DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_00140_AAD_S_000002_PKG

Source


1 PACKAGE BODY XLA_00140_AAD_S_000002_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_00140_AAD_S_000002_PKG                                        |
10 |                                                                       |
11 | DESCRIPTION                                                           |
12 |     Package generated From Product Accounting Definition              |
13 |      Name    : Assets Standard Accounting                             |
14 |      Code    : FA_STANDARD_ACCOUNTING                                 |
15 |      Owner   : PRODUCT                                                |
16 |      Version :                                                        |
17 |      AMB Context Code: DEFAULT                                        |
18 | HISTORY                                                               |
19 |     Generated at 30-03-2009 at 05:03:11 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_00140_AAD_S_000002_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_00140_AAD_S_000002_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_00140_AAD_S_000002_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_00140_AAD_S_000002_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 --Period Close Date
241  , p_source_1            IN DATE
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        := 'FA_ADDITION';
268 l_component_type_code   := 'S';
269 l_component_appl_id     :=  140;
270 l_amb_context_code      := 'DEFAULT';
271 l_source                := NULL;
272 l_description           := NULL;
273 
274 
275  
276  IF 
277 l_ledger_language = 'US' THEN
278     l_description :=  SUBSTR(CONCAT(l_description,'Addition'),1,2000);
279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
280  END IF;  
281  IF 
282 l_ledger_language = 'US' THEN
283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
285  END IF;   
286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
288   IF l_source IS NOT NULL THEN
289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
291   END IF; 
292  l_description := SUBSTR(l_description,1,1996);
293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
294         trace
295            (p_msg      => 'END of Description_1'
296            ,p_level    => C_LEVEL_PROCEDURE
297            ,p_module   => l_log_module);
298 
299   END IF;
300   RETURN l_description;
301 
302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
303       trace
304          (p_msg      => 'END of Description_1'
305          ,p_level    => C_LEVEL_PROCEDURE
306          ,p_module   => l_log_module);
307 END IF;
308 RETURN NULL;
309 EXCEPTION
310   WHEN VALUE_ERROR THEN
311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
312             trace
313                (p_msg      => 'ERROR: '||sqlerrm
314                ,p_level    => C_LEVEL_EXCEPTION
315                ,p_module   => l_log_module);
316      END IF;
317      RAISE;
318  WHEN xla_exceptions_pkg.application_exception THEN
319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
320       trace
321          (p_msg      => 'ERROR: '||sqlerrm
322          ,p_level    => C_LEVEL_EXCEPTION
323          ,p_module   => l_log_module);
324       END IF;
325       RAISE;
326  WHEN OTHERS THEN
327        xla_exceptions_pkg.raise_message
328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_1');
329 END Description_1;
330 
331 ---------------------------------------
332 --
333 -- PRIVATE FUNCTION
334 --         Description_2
338   p_application_id      IN NUMBER
335 --
336 ---------------------------------------
337 FUNCTION Description_2 (
339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
340 --Period Close Date
341  , p_source_1            IN DATE
342 )
343 RETURN VARCHAR2
344 IS
345 l_component_type        VARCHAR2(80)   ;
346 l_component_code        VARCHAR2(30)   ;
347 l_component_type_code   VARCHAR2(1)    ;
348 l_component_appl_id     INTEGER        ;
349 l_amb_context_code      VARCHAR2(30)   ;
350 l_ledger_language       VARCHAR2(30)   ;
351 l_source                VARCHAR2(1996) ;
352 l_description           VARCHAR2(2000) ;
353 l_log_module            VARCHAR2(240)  ;
354 BEGIN
355 IF g_log_enabled THEN
356       l_log_module := C_DEFAULT_MODULE||'.Description_2';
357 END IF;
358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
359       trace
360          (p_msg      => 'BEGIN of Description_2'
361          ,p_level    => C_LEVEL_PROCEDURE
362          ,p_module   => l_log_module);
363 END IF;
364 
365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
366 l_component_type        := 'AMB_DESCRIPTION';
367 l_component_code        := 'FA_ADDITION_BONUS_EXP';
368 l_component_type_code   := 'S';
369 l_component_appl_id     :=  140;
370 l_amb_context_code      := 'DEFAULT';
371 l_source                := NULL;
372 l_description           := NULL;
373 
374 
375  
376  IF 
377 l_ledger_language = 'US' THEN
378     l_description :=  SUBSTR(CONCAT(l_description,'Addition Bonus Depreciation Expense'),1,2000);
379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
380  END IF;  
381  IF 
382 l_ledger_language = 'US' THEN
383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
385  END IF;   
386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
388   IF l_source IS NOT NULL THEN
389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
391   END IF; 
392  l_description := SUBSTR(l_description,1,1996);
393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
394         trace
395            (p_msg      => 'END of Description_2'
396            ,p_level    => C_LEVEL_PROCEDURE
397            ,p_module   => l_log_module);
398 
399   END IF;
400   RETURN l_description;
401 
402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
403       trace
404          (p_msg      => 'END of Description_2'
405          ,p_level    => C_LEVEL_PROCEDURE
406          ,p_module   => l_log_module);
407 END IF;
408 RETURN NULL;
409 EXCEPTION
410   WHEN VALUE_ERROR THEN
411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
412             trace
413                (p_msg      => 'ERROR: '||sqlerrm
414                ,p_level    => C_LEVEL_EXCEPTION
415                ,p_module   => l_log_module);
416      END IF;
417      RAISE;
418  WHEN xla_exceptions_pkg.application_exception THEN
419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
420       trace
421          (p_msg      => 'ERROR: '||sqlerrm
422          ,p_level    => C_LEVEL_EXCEPTION
423          ,p_module   => l_log_module);
424       END IF;
425       RAISE;
426  WHEN OTHERS THEN
427        xla_exceptions_pkg.raise_message
428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_2');
429 END Description_2;
430 
431 ---------------------------------------
432 --
433 -- PRIVATE FUNCTION
434 --         Description_3
435 --
436 ---------------------------------------
437 FUNCTION Description_3 (
438   p_application_id      IN NUMBER
439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
440 --Period Close Date
441  , p_source_1            IN DATE
442 )
443 RETURN VARCHAR2
444 IS
445 l_component_type        VARCHAR2(80)   ;
446 l_component_code        VARCHAR2(30)   ;
447 l_component_type_code   VARCHAR2(1)    ;
448 l_component_appl_id     INTEGER        ;
449 l_amb_context_code      VARCHAR2(30)   ;
450 l_ledger_language       VARCHAR2(30)   ;
451 l_source                VARCHAR2(1996) ;
452 l_description           VARCHAR2(2000) ;
453 l_log_module            VARCHAR2(240)  ;
454 BEGIN
455 IF g_log_enabled THEN
456       l_log_module := C_DEFAULT_MODULE||'.Description_3';
457 END IF;
458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
459       trace
460          (p_msg      => 'BEGIN of Description_3'
461          ,p_level    => C_LEVEL_PROCEDURE
462          ,p_module   => l_log_module);
463 END IF;
464 
465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
466 l_component_type        := 'AMB_DESCRIPTION';
467 l_component_code        := 'FA_ADDITION_BONUS_RESERVE';
468 l_component_type_code   := 'S';
469 l_component_appl_id     :=  140;
470 l_amb_context_code      := 'DEFAULT';
471 l_source                := NULL;
472 l_description           := NULL;
473 
474 
475  
476  IF 
477 l_ledger_language = 'US' THEN
478     l_description :=  SUBSTR(CONCAT(l_description,'Addition Bonus Depreciation Reserve'),1,2000);
479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
480  END IF;  
481  IF 
482 l_ledger_language = 'US' THEN
483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
485  END IF;   
486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
488   IF l_source IS NOT NULL THEN
489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
491   END IF; 
492  l_description := SUBSTR(l_description,1,1996);
493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
494         trace
495            (p_msg      => 'END of Description_3'
496            ,p_level    => C_LEVEL_PROCEDURE
497            ,p_module   => l_log_module);
498 
499   END IF;
500   RETURN l_description;
501 
502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
503       trace
504          (p_msg      => 'END of Description_3'
505          ,p_level    => C_LEVEL_PROCEDURE
506          ,p_module   => l_log_module);
507 END IF;
508 RETURN NULL;
509 EXCEPTION
510   WHEN VALUE_ERROR THEN
511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
512             trace
513                (p_msg      => 'ERROR: '||sqlerrm
514                ,p_level    => C_LEVEL_EXCEPTION
515                ,p_module   => l_log_module);
516      END IF;
517      RAISE;
518  WHEN xla_exceptions_pkg.application_exception THEN
519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
520       trace
521          (p_msg      => 'ERROR: '||sqlerrm
522          ,p_level    => C_LEVEL_EXCEPTION
523          ,p_module   => l_log_module);
524       END IF;
525       RAISE;
526  WHEN OTHERS THEN
527        xla_exceptions_pkg.raise_message
528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_3');
529 END Description_3;
530 
531 ---------------------------------------
532 --
533 -- PRIVATE FUNCTION
534 --         Description_4
535 --
536 ---------------------------------------
537 FUNCTION Description_4 (
538   p_application_id      IN NUMBER
539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
540 --Period Close Date
541  , p_source_1            IN DATE
542 )
543 RETURN VARCHAR2
544 IS
545 l_component_type        VARCHAR2(80)   ;
546 l_component_code        VARCHAR2(30)   ;
547 l_component_type_code   VARCHAR2(1)    ;
548 l_component_appl_id     INTEGER        ;
549 l_amb_context_code      VARCHAR2(30)   ;
550 l_ledger_language       VARCHAR2(30)   ;
551 l_source                VARCHAR2(1996) ;
552 l_description           VARCHAR2(2000) ;
553 l_log_module            VARCHAR2(240)  ;
554 BEGIN
555 IF g_log_enabled THEN
556       l_log_module := C_DEFAULT_MODULE||'.Description_4';
557 END IF;
558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
559       trace
560          (p_msg      => 'BEGIN of Description_4'
561          ,p_level    => C_LEVEL_PROCEDURE
562          ,p_module   => l_log_module);
563 END IF;
564 
565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
566 l_component_type        := 'AMB_DESCRIPTION';
567 l_component_code        := 'FA_ADDITION_COST';
568 l_component_type_code   := 'S';
569 l_component_appl_id     :=  140;
570 l_amb_context_code      := 'DEFAULT';
571 l_source                := NULL;
572 l_description           := NULL;
573 
574 
575  
576  IF 
577 l_ledger_language = 'US' THEN
578     l_description :=  SUBSTR(CONCAT(l_description,'Addition Cost'),1,2000);
579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
580  END IF;  
581  IF 
582 l_ledger_language = 'US' THEN
583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
585  END IF;   
586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
588   IF l_source IS NOT NULL THEN
589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
591   END IF; 
592  l_description := SUBSTR(l_description,1,1996);
593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
594         trace
595            (p_msg      => 'END of Description_4'
596            ,p_level    => C_LEVEL_PROCEDURE
597            ,p_module   => l_log_module);
598 
599   END IF;
600   RETURN l_description;
601 
602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
603       trace
604          (p_msg      => 'END of Description_4'
605          ,p_level    => C_LEVEL_PROCEDURE
606          ,p_module   => l_log_module);
607 END IF;
608 RETURN NULL;
609 EXCEPTION
610   WHEN VALUE_ERROR THEN
611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
612             trace
613                (p_msg      => 'ERROR: '||sqlerrm
614                ,p_level    => C_LEVEL_EXCEPTION
615                ,p_module   => l_log_module);
616      END IF;
617      RAISE;
618  WHEN xla_exceptions_pkg.application_exception THEN
619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
620       trace
621          (p_msg      => 'ERROR: '||sqlerrm
622          ,p_level    => C_LEVEL_EXCEPTION
623          ,p_module   => l_log_module);
624       END IF;
625       RAISE;
626  WHEN OTHERS THEN
627        xla_exceptions_pkg.raise_message
628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_4');
629 END Description_4;
630 
631 ---------------------------------------
632 --
633 -- PRIVATE FUNCTION
634 --         Description_5
635 --
636 ---------------------------------------
637 FUNCTION Description_5 (
638   p_application_id      IN NUMBER
639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
640 --Period Close Date
641  , p_source_1            IN DATE
642 )
643 RETURN VARCHAR2
647 l_component_type_code   VARCHAR2(1)    ;
644 IS
645 l_component_type        VARCHAR2(80)   ;
646 l_component_code        VARCHAR2(30)   ;
648 l_component_appl_id     INTEGER        ;
649 l_amb_context_code      VARCHAR2(30)   ;
650 l_ledger_language       VARCHAR2(30)   ;
651 l_source                VARCHAR2(1996) ;
652 l_description           VARCHAR2(2000) ;
653 l_log_module            VARCHAR2(240)  ;
654 BEGIN
655 IF g_log_enabled THEN
656       l_log_module := C_DEFAULT_MODULE||'.Description_5';
657 END IF;
658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
659       trace
660          (p_msg      => 'BEGIN of Description_5'
661          ,p_level    => C_LEVEL_PROCEDURE
662          ,p_module   => l_log_module);
663 END IF;
664 
665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
666 l_component_type        := 'AMB_DESCRIPTION';
667 l_component_code        := 'FA_ADDITION_COST_CLEARING';
668 l_component_type_code   := 'S';
669 l_component_appl_id     :=  140;
670 l_amb_context_code      := 'DEFAULT';
671 l_source                := NULL;
672 l_description           := NULL;
673 
674 
675  
676  IF 
677 l_ledger_language = 'US' THEN
678     l_description :=  SUBSTR(CONCAT(l_description,'Addition Cost Clearing'),1,2000);
679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
680  END IF;  
681  IF 
682 l_ledger_language = 'US' THEN
683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
685  END IF;   
686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
688   IF l_source IS NOT NULL THEN
689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
691   END IF; 
692  l_description := SUBSTR(l_description,1,1996);
693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
694         trace
695            (p_msg      => 'END of Description_5'
696            ,p_level    => C_LEVEL_PROCEDURE
697            ,p_module   => l_log_module);
698 
699   END IF;
700   RETURN l_description;
701 
702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
703       trace
704          (p_msg      => 'END of Description_5'
705          ,p_level    => C_LEVEL_PROCEDURE
706          ,p_module   => l_log_module);
707 END IF;
708 RETURN NULL;
709 EXCEPTION
710   WHEN VALUE_ERROR THEN
711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
712             trace
713                (p_msg      => 'ERROR: '||sqlerrm
714                ,p_level    => C_LEVEL_EXCEPTION
715                ,p_module   => l_log_module);
716      END IF;
717      RAISE;
718  WHEN xla_exceptions_pkg.application_exception THEN
719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
720       trace
721          (p_msg      => 'ERROR: '||sqlerrm
722          ,p_level    => C_LEVEL_EXCEPTION
723          ,p_module   => l_log_module);
724       END IF;
725       RAISE;
726  WHEN OTHERS THEN
727        xla_exceptions_pkg.raise_message
728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_5');
729 END Description_5;
730 
731 ---------------------------------------
732 --
733 -- PRIVATE FUNCTION
734 --         Description_6
735 --
736 ---------------------------------------
737 FUNCTION Description_6 (
738   p_application_id      IN NUMBER
739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
740 --Period Close Date
741  , p_source_1            IN DATE
742 )
743 RETURN VARCHAR2
744 IS
745 l_component_type        VARCHAR2(80)   ;
746 l_component_code        VARCHAR2(30)   ;
747 l_component_type_code   VARCHAR2(1)    ;
748 l_component_appl_id     INTEGER        ;
749 l_amb_context_code      VARCHAR2(30)   ;
750 l_ledger_language       VARCHAR2(30)   ;
751 l_source                VARCHAR2(1996) ;
752 l_description           VARCHAR2(2000) ;
753 l_log_module            VARCHAR2(240)  ;
754 BEGIN
755 IF g_log_enabled THEN
756       l_log_module := C_DEFAULT_MODULE||'.Description_6';
757 END IF;
758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
759       trace
760          (p_msg      => 'BEGIN of Description_6'
761          ,p_level    => C_LEVEL_PROCEDURE
762          ,p_module   => l_log_module);
763 END IF;
764 
765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
766 l_component_type        := 'AMB_DESCRIPTION';
767 l_component_code        := 'FA_ADDITION_EXPENSE';
768 l_component_type_code   := 'S';
769 l_component_appl_id     :=  140;
770 l_amb_context_code      := 'DEFAULT';
771 l_source                := NULL;
772 l_description           := NULL;
773 
774 
775  
776  IF 
777 l_ledger_language = 'US' THEN
778     l_description :=  SUBSTR(CONCAT(l_description,'Addition Depreciation Expense'),1,2000);
779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
780  END IF;  
781  IF 
782 l_ledger_language = 'US' THEN
783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
785  END IF;   
786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
788   IF l_source IS NOT NULL THEN
789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
791   END IF; 
792  l_description := SUBSTR(l_description,1,1996);
793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
797            ,p_module   => l_log_module);
794         trace
795            (p_msg      => 'END of Description_6'
796            ,p_level    => C_LEVEL_PROCEDURE
798 
799   END IF;
800   RETURN l_description;
801 
802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
803       trace
804          (p_msg      => 'END of Description_6'
805          ,p_level    => C_LEVEL_PROCEDURE
806          ,p_module   => l_log_module);
807 END IF;
808 RETURN NULL;
809 EXCEPTION
810   WHEN VALUE_ERROR THEN
811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
812             trace
813                (p_msg      => 'ERROR: '||sqlerrm
814                ,p_level    => C_LEVEL_EXCEPTION
815                ,p_module   => l_log_module);
816      END IF;
817      RAISE;
818  WHEN xla_exceptions_pkg.application_exception THEN
819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
820       trace
821          (p_msg      => 'ERROR: '||sqlerrm
822          ,p_level    => C_LEVEL_EXCEPTION
823          ,p_module   => l_log_module);
824       END IF;
825       RAISE;
826  WHEN OTHERS THEN
827        xla_exceptions_pkg.raise_message
828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_6');
829 END Description_6;
830 
831 ---------------------------------------
832 --
833 -- PRIVATE FUNCTION
834 --         Description_7
835 --
836 ---------------------------------------
837 FUNCTION Description_7 (
838   p_application_id      IN NUMBER
839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
840 --Period Close Date
841  , p_source_1            IN DATE
842 )
843 RETURN VARCHAR2
844 IS
845 l_component_type        VARCHAR2(80)   ;
846 l_component_code        VARCHAR2(30)   ;
847 l_component_type_code   VARCHAR2(1)    ;
848 l_component_appl_id     INTEGER        ;
849 l_amb_context_code      VARCHAR2(30)   ;
850 l_ledger_language       VARCHAR2(30)   ;
851 l_source                VARCHAR2(1996) ;
852 l_description           VARCHAR2(2000) ;
853 l_log_module            VARCHAR2(240)  ;
854 BEGIN
855 IF g_log_enabled THEN
856       l_log_module := C_DEFAULT_MODULE||'.Description_7';
857 END IF;
858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
859       trace
860          (p_msg      => 'BEGIN of Description_7'
861          ,p_level    => C_LEVEL_PROCEDURE
862          ,p_module   => l_log_module);
863 END IF;
864 
865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
866 l_component_type        := 'AMB_DESCRIPTION';
867 l_component_code        := 'FA_ADDITION_RESERVE';
868 l_component_type_code   := 'S';
869 l_component_appl_id     :=  140;
870 l_amb_context_code      := 'DEFAULT';
871 l_source                := NULL;
872 l_description           := NULL;
873 
874 
875  
876  IF 
877 l_ledger_language = 'US' THEN
878     l_description :=  SUBSTR(CONCAT(l_description,'Addition Depreciation Reserve'),1,2000);
879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
880  END IF;  
881  IF 
882 l_ledger_language = 'US' THEN
883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
885  END IF;   
886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
888   IF l_source IS NOT NULL THEN
889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
891   END IF; 
892  l_description := SUBSTR(l_description,1,1996);
893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
894         trace
895            (p_msg      => 'END of Description_7'
896            ,p_level    => C_LEVEL_PROCEDURE
897            ,p_module   => l_log_module);
898 
899   END IF;
900   RETURN l_description;
901 
902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
903       trace
904          (p_msg      => 'END of Description_7'
905          ,p_level    => C_LEVEL_PROCEDURE
906          ,p_module   => l_log_module);
907 END IF;
908 RETURN NULL;
909 EXCEPTION
910   WHEN VALUE_ERROR THEN
911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
912             trace
913                (p_msg      => 'ERROR: '||sqlerrm
914                ,p_level    => C_LEVEL_EXCEPTION
915                ,p_module   => l_log_module);
916      END IF;
917      RAISE;
918  WHEN xla_exceptions_pkg.application_exception THEN
919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
920       trace
921          (p_msg      => 'ERROR: '||sqlerrm
922          ,p_level    => C_LEVEL_EXCEPTION
923          ,p_module   => l_log_module);
924       END IF;
925       RAISE;
926  WHEN OTHERS THEN
927        xla_exceptions_pkg.raise_message
928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_7');
929 END Description_7;
930 
931 ---------------------------------------
932 --
933 -- PRIVATE FUNCTION
934 --         Description_8
935 --
936 ---------------------------------------
937 FUNCTION Description_8 (
938   p_application_id      IN NUMBER
939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
940 --Period Close Date
941  , p_source_1            IN DATE
942 )
943 RETURN VARCHAR2
944 IS
945 l_component_type        VARCHAR2(80)   ;
946 l_component_code        VARCHAR2(30)   ;
947 l_component_type_code   VARCHAR2(1)    ;
948 l_component_appl_id     INTEGER        ;
949 l_amb_context_code      VARCHAR2(30)   ;
950 l_ledger_language       VARCHAR2(30)   ;
951 l_source                VARCHAR2(1996) ;
955 IF g_log_enabled THEN
952 l_description           VARCHAR2(2000) ;
953 l_log_module            VARCHAR2(240)  ;
954 BEGIN
956       l_log_module := C_DEFAULT_MODULE||'.Description_8';
957 END IF;
958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
959       trace
960          (p_msg      => 'BEGIN of Description_8'
961          ,p_level    => C_LEVEL_PROCEDURE
962          ,p_module   => l_log_module);
963 END IF;
964 
965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
966 l_component_type        := 'AMB_DESCRIPTION';
967 l_component_code        := 'FA_ADJUSTMENT_BONUS_EXP';
968 l_component_type_code   := 'S';
969 l_component_appl_id     :=  140;
970 l_amb_context_code      := 'DEFAULT';
971 l_source                := NULL;
972 l_description           := NULL;
973 
974 
975  
976  IF 
977 l_ledger_language = 'US' THEN
978     l_description :=  SUBSTR(CONCAT(l_description,'Adjustment Bonus Depreciation Expense'),1,2000);
979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
980  END IF;  
981  IF 
982 l_ledger_language = 'US' THEN
983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
985  END IF;   
986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
988   IF l_source IS NOT NULL THEN
989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
991   END IF; 
992  l_description := SUBSTR(l_description,1,1996);
993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
994         trace
995            (p_msg      => 'END of Description_8'
996            ,p_level    => C_LEVEL_PROCEDURE
997            ,p_module   => l_log_module);
998 
999   END IF;
1000   RETURN l_description;
1001 
1002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1003       trace
1004          (p_msg      => 'END of Description_8'
1005          ,p_level    => C_LEVEL_PROCEDURE
1006          ,p_module   => l_log_module);
1007 END IF;
1008 RETURN NULL;
1009 EXCEPTION
1010   WHEN VALUE_ERROR THEN
1011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1012             trace
1013                (p_msg      => 'ERROR: '||sqlerrm
1014                ,p_level    => C_LEVEL_EXCEPTION
1015                ,p_module   => l_log_module);
1016      END IF;
1017      RAISE;
1018  WHEN xla_exceptions_pkg.application_exception THEN
1019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1020       trace
1021          (p_msg      => 'ERROR: '||sqlerrm
1022          ,p_level    => C_LEVEL_EXCEPTION
1023          ,p_module   => l_log_module);
1024       END IF;
1025       RAISE;
1026  WHEN OTHERS THEN
1027        xla_exceptions_pkg.raise_message
1028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_8');
1029 END Description_8;
1030 
1031 ---------------------------------------
1032 --
1033 -- PRIVATE FUNCTION
1034 --         Description_9
1035 --
1036 ---------------------------------------
1037 FUNCTION Description_9 (
1038   p_application_id      IN NUMBER
1039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1040 --Period Close Date
1041  , p_source_1            IN DATE
1042 )
1043 RETURN VARCHAR2
1044 IS
1045 l_component_type        VARCHAR2(80)   ;
1046 l_component_code        VARCHAR2(30)   ;
1047 l_component_type_code   VARCHAR2(1)    ;
1048 l_component_appl_id     INTEGER        ;
1049 l_amb_context_code      VARCHAR2(30)   ;
1050 l_ledger_language       VARCHAR2(30)   ;
1051 l_source                VARCHAR2(1996) ;
1052 l_description           VARCHAR2(2000) ;
1053 l_log_module            VARCHAR2(240)  ;
1054 BEGIN
1055 IF g_log_enabled THEN
1056       l_log_module := C_DEFAULT_MODULE||'.Description_9';
1057 END IF;
1058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1059       trace
1060          (p_msg      => 'BEGIN of Description_9'
1061          ,p_level    => C_LEVEL_PROCEDURE
1062          ,p_module   => l_log_module);
1063 END IF;
1064 
1065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1066 l_component_type        := 'AMB_DESCRIPTION';
1067 l_component_code        := 'FA_ADJUSTMENT_BONUS_RESERVE';
1068 l_component_type_code   := 'S';
1069 l_component_appl_id     :=  140;
1070 l_amb_context_code      := 'DEFAULT';
1071 l_source                := NULL;
1072 l_description           := NULL;
1073 
1074 
1075  
1076  IF 
1077 l_ledger_language = 'US' THEN
1078     l_description :=  SUBSTR(CONCAT(l_description,'Adjustment Bonus Depreciation Reserve'),1,2000);
1079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1080  END IF;  
1081  IF 
1082 l_ledger_language = 'US' THEN
1083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1085  END IF;   
1086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1088   IF l_source IS NOT NULL THEN
1089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1091   END IF; 
1092  l_description := SUBSTR(l_description,1,1996);
1093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1094         trace
1095            (p_msg      => 'END of Description_9'
1096            ,p_level    => C_LEVEL_PROCEDURE
1097            ,p_module   => l_log_module);
1098 
1099   END IF;
1100   RETURN l_description;
1101 
1102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1106          ,p_module   => l_log_module);
1103       trace
1104          (p_msg      => 'END of Description_9'
1105          ,p_level    => C_LEVEL_PROCEDURE
1107 END IF;
1108 RETURN NULL;
1109 EXCEPTION
1110   WHEN VALUE_ERROR THEN
1111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1112             trace
1113                (p_msg      => 'ERROR: '||sqlerrm
1114                ,p_level    => C_LEVEL_EXCEPTION
1115                ,p_module   => l_log_module);
1116      END IF;
1117      RAISE;
1118  WHEN xla_exceptions_pkg.application_exception THEN
1119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1120       trace
1121          (p_msg      => 'ERROR: '||sqlerrm
1122          ,p_level    => C_LEVEL_EXCEPTION
1123          ,p_module   => l_log_module);
1124       END IF;
1125       RAISE;
1126  WHEN OTHERS THEN
1127        xla_exceptions_pkg.raise_message
1128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_9');
1129 END Description_9;
1130 
1131 ---------------------------------------
1132 --
1133 -- PRIVATE FUNCTION
1134 --         Description_10
1135 --
1136 ---------------------------------------
1137 FUNCTION Description_10 (
1138   p_application_id      IN NUMBER
1139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1140 --Period Close Date
1141  , p_source_1            IN DATE
1142 )
1143 RETURN VARCHAR2
1144 IS
1145 l_component_type        VARCHAR2(80)   ;
1146 l_component_code        VARCHAR2(30)   ;
1147 l_component_type_code   VARCHAR2(1)    ;
1148 l_component_appl_id     INTEGER        ;
1149 l_amb_context_code      VARCHAR2(30)   ;
1150 l_ledger_language       VARCHAR2(30)   ;
1151 l_source                VARCHAR2(1996) ;
1152 l_description           VARCHAR2(2000) ;
1153 l_log_module            VARCHAR2(240)  ;
1154 BEGIN
1155 IF g_log_enabled THEN
1156       l_log_module := C_DEFAULT_MODULE||'.Description_10';
1157 END IF;
1158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1159       trace
1160          (p_msg      => 'BEGIN of Description_10'
1161          ,p_level    => C_LEVEL_PROCEDURE
1162          ,p_module   => l_log_module);
1163 END IF;
1164 
1165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1166 l_component_type        := 'AMB_DESCRIPTION';
1167 l_component_code        := 'FA_ADJUSTMENT_COST';
1168 l_component_type_code   := 'S';
1169 l_component_appl_id     :=  140;
1170 l_amb_context_code      := 'DEFAULT';
1171 l_source                := NULL;
1172 l_description           := NULL;
1173 
1174 
1175  
1176  IF 
1177 l_ledger_language = 'US' THEN
1178     l_description :=  SUBSTR(CONCAT(l_description,'Adjustment Cost'),1,2000);
1179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1180  END IF;  
1181  IF 
1182 l_ledger_language = 'US' THEN
1183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1185  END IF;   
1186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1188   IF l_source IS NOT NULL THEN
1189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1191   END IF; 
1192  l_description := SUBSTR(l_description,1,1996);
1193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1194         trace
1195            (p_msg      => 'END of Description_10'
1196            ,p_level    => C_LEVEL_PROCEDURE
1197            ,p_module   => l_log_module);
1198 
1199   END IF;
1200   RETURN l_description;
1201 
1202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1203       trace
1204          (p_msg      => 'END of Description_10'
1205          ,p_level    => C_LEVEL_PROCEDURE
1206          ,p_module   => l_log_module);
1207 END IF;
1208 RETURN NULL;
1209 EXCEPTION
1210   WHEN VALUE_ERROR THEN
1211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1212             trace
1213                (p_msg      => 'ERROR: '||sqlerrm
1214                ,p_level    => C_LEVEL_EXCEPTION
1215                ,p_module   => l_log_module);
1216      END IF;
1217      RAISE;
1218  WHEN xla_exceptions_pkg.application_exception THEN
1219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1220       trace
1221          (p_msg      => 'ERROR: '||sqlerrm
1222          ,p_level    => C_LEVEL_EXCEPTION
1223          ,p_module   => l_log_module);
1224       END IF;
1225       RAISE;
1226  WHEN OTHERS THEN
1227        xla_exceptions_pkg.raise_message
1228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_10');
1229 END Description_10;
1230 
1231 ---------------------------------------
1232 --
1233 -- PRIVATE FUNCTION
1234 --         Description_11
1235 --
1236 ---------------------------------------
1237 FUNCTION Description_11 (
1238   p_application_id      IN NUMBER
1239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1240 --Period Close Date
1241  , p_source_1            IN DATE
1242 )
1243 RETURN VARCHAR2
1244 IS
1245 l_component_type        VARCHAR2(80)   ;
1246 l_component_code        VARCHAR2(30)   ;
1247 l_component_type_code   VARCHAR2(1)    ;
1248 l_component_appl_id     INTEGER        ;
1249 l_amb_context_code      VARCHAR2(30)   ;
1250 l_ledger_language       VARCHAR2(30)   ;
1251 l_source                VARCHAR2(1996) ;
1252 l_description           VARCHAR2(2000) ;
1253 l_log_module            VARCHAR2(240)  ;
1254 BEGIN
1255 IF g_log_enabled THEN
1256       l_log_module := C_DEFAULT_MODULE||'.Description_11';
1257 END IF;
1258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1259       trace
1263 END IF;
1260          (p_msg      => 'BEGIN of Description_11'
1261          ,p_level    => C_LEVEL_PROCEDURE
1262          ,p_module   => l_log_module);
1264 
1265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1266 l_component_type        := 'AMB_DESCRIPTION';
1267 l_component_code        := 'FA_ADJUSTMENT_COST_CLEARING';
1268 l_component_type_code   := 'S';
1269 l_component_appl_id     :=  140;
1270 l_amb_context_code      := 'DEFAULT';
1271 l_source                := NULL;
1272 l_description           := NULL;
1273 
1274 
1275  
1276  IF 
1277 l_ledger_language = 'US' THEN
1278     l_description :=  SUBSTR(CONCAT(l_description,'Adjustment Cost Clearing'),1,2000);
1279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1280  END IF;  
1281  IF 
1282 l_ledger_language = 'US' THEN
1283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1285  END IF;   
1286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1288   IF l_source IS NOT NULL THEN
1289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1291   END IF; 
1292  l_description := SUBSTR(l_description,1,1996);
1293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1294         trace
1295            (p_msg      => 'END of Description_11'
1296            ,p_level    => C_LEVEL_PROCEDURE
1297            ,p_module   => l_log_module);
1298 
1299   END IF;
1300   RETURN l_description;
1301 
1302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1303       trace
1304          (p_msg      => 'END of Description_11'
1305          ,p_level    => C_LEVEL_PROCEDURE
1306          ,p_module   => l_log_module);
1307 END IF;
1308 RETURN NULL;
1309 EXCEPTION
1310   WHEN VALUE_ERROR THEN
1311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1312             trace
1313                (p_msg      => 'ERROR: '||sqlerrm
1314                ,p_level    => C_LEVEL_EXCEPTION
1315                ,p_module   => l_log_module);
1316      END IF;
1317      RAISE;
1318  WHEN xla_exceptions_pkg.application_exception THEN
1319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1320       trace
1321          (p_msg      => 'ERROR: '||sqlerrm
1322          ,p_level    => C_LEVEL_EXCEPTION
1323          ,p_module   => l_log_module);
1324       END IF;
1325       RAISE;
1326  WHEN OTHERS THEN
1327        xla_exceptions_pkg.raise_message
1328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_11');
1329 END Description_11;
1330 
1331 ---------------------------------------
1332 --
1333 -- PRIVATE FUNCTION
1334 --         Description_12
1335 --
1336 ---------------------------------------
1337 FUNCTION Description_12 (
1338   p_application_id      IN NUMBER
1339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1340 --Period Close Date
1341  , p_source_1            IN DATE
1342 )
1343 RETURN VARCHAR2
1344 IS
1345 l_component_type        VARCHAR2(80)   ;
1346 l_component_code        VARCHAR2(30)   ;
1347 l_component_type_code   VARCHAR2(1)    ;
1348 l_component_appl_id     INTEGER        ;
1349 l_amb_context_code      VARCHAR2(30)   ;
1350 l_ledger_language       VARCHAR2(30)   ;
1351 l_source                VARCHAR2(1996) ;
1352 l_description           VARCHAR2(2000) ;
1353 l_log_module            VARCHAR2(240)  ;
1354 BEGIN
1355 IF g_log_enabled THEN
1356       l_log_module := C_DEFAULT_MODULE||'.Description_12';
1357 END IF;
1358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1359       trace
1360          (p_msg      => 'BEGIN of Description_12'
1361          ,p_level    => C_LEVEL_PROCEDURE
1362          ,p_module   => l_log_module);
1363 END IF;
1364 
1365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1366 l_component_type        := 'AMB_DESCRIPTION';
1367 l_component_code        := 'FA_ADJUSTMENT_EXP';
1368 l_component_type_code   := 'S';
1369 l_component_appl_id     :=  140;
1370 l_amb_context_code      := 'DEFAULT';
1371 l_source                := NULL;
1372 l_description           := NULL;
1373 
1374 
1375  
1376  IF 
1377 l_ledger_language = 'US' THEN
1378     l_description :=  SUBSTR(CONCAT(l_description,'Adjustment Depreciation Expense'),1,2000);
1379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1380  END IF;  
1381  IF 
1382 l_ledger_language = 'US' THEN
1383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1385  END IF;   
1386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1388   IF l_source IS NOT NULL THEN
1389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1391   END IF; 
1392  l_description := SUBSTR(l_description,1,1996);
1393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1394         trace
1395            (p_msg      => 'END of Description_12'
1396            ,p_level    => C_LEVEL_PROCEDURE
1397            ,p_module   => l_log_module);
1398 
1399   END IF;
1400   RETURN l_description;
1401 
1402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1403       trace
1404          (p_msg      => 'END of Description_12'
1405          ,p_level    => C_LEVEL_PROCEDURE
1406          ,p_module   => l_log_module);
1407 END IF;
1408 RETURN NULL;
1409 EXCEPTION
1410   WHEN VALUE_ERROR THEN
1411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1415                ,p_module   => l_log_module);
1412             trace
1413                (p_msg      => 'ERROR: '||sqlerrm
1414                ,p_level    => C_LEVEL_EXCEPTION
1416      END IF;
1417      RAISE;
1418  WHEN xla_exceptions_pkg.application_exception THEN
1419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1420       trace
1421          (p_msg      => 'ERROR: '||sqlerrm
1422          ,p_level    => C_LEVEL_EXCEPTION
1423          ,p_module   => l_log_module);
1424       END IF;
1425       RAISE;
1426  WHEN OTHERS THEN
1427        xla_exceptions_pkg.raise_message
1428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_12');
1429 END Description_12;
1430 
1431 ---------------------------------------
1432 --
1433 -- PRIVATE FUNCTION
1434 --         Description_13
1435 --
1436 ---------------------------------------
1437 FUNCTION Description_13 (
1438   p_application_id      IN NUMBER
1439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1440 --Period Close Date
1441  , p_source_1            IN DATE
1442 )
1443 RETURN VARCHAR2
1444 IS
1445 l_component_type        VARCHAR2(80)   ;
1446 l_component_code        VARCHAR2(30)   ;
1447 l_component_type_code   VARCHAR2(1)    ;
1448 l_component_appl_id     INTEGER        ;
1449 l_amb_context_code      VARCHAR2(30)   ;
1450 l_ledger_language       VARCHAR2(30)   ;
1451 l_source                VARCHAR2(1996) ;
1452 l_description           VARCHAR2(2000) ;
1453 l_log_module            VARCHAR2(240)  ;
1454 BEGIN
1455 IF g_log_enabled THEN
1456       l_log_module := C_DEFAULT_MODULE||'.Description_13';
1457 END IF;
1458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1459       trace
1460          (p_msg      => 'BEGIN of Description_13'
1461          ,p_level    => C_LEVEL_PROCEDURE
1462          ,p_module   => l_log_module);
1463 END IF;
1464 
1465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1466 l_component_type        := 'AMB_DESCRIPTION';
1467 l_component_code        := 'FA_ADJUSTMENT_IC_PAY';
1468 l_component_type_code   := 'S';
1469 l_component_appl_id     :=  140;
1470 l_amb_context_code      := 'DEFAULT';
1471 l_source                := NULL;
1472 l_description           := NULL;
1473 
1474 
1475  
1476  IF 
1477 l_ledger_language = 'US' THEN
1478     l_description :=  SUBSTR(CONCAT(l_description,'Adjustment Intercompany Payable'),1,2000);
1479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1480  END IF;  
1481  IF 
1482 l_ledger_language = 'US' THEN
1483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1485  END IF;   
1486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1488   IF l_source IS NOT NULL THEN
1489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1491   END IF; 
1492  l_description := SUBSTR(l_description,1,1996);
1493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1494         trace
1495            (p_msg      => 'END of Description_13'
1496            ,p_level    => C_LEVEL_PROCEDURE
1497            ,p_module   => l_log_module);
1498 
1499   END IF;
1500   RETURN l_description;
1501 
1502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1503       trace
1504          (p_msg      => 'END of Description_13'
1505          ,p_level    => C_LEVEL_PROCEDURE
1506          ,p_module   => l_log_module);
1507 END IF;
1508 RETURN NULL;
1509 EXCEPTION
1510   WHEN VALUE_ERROR THEN
1511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1512             trace
1513                (p_msg      => 'ERROR: '||sqlerrm
1514                ,p_level    => C_LEVEL_EXCEPTION
1515                ,p_module   => l_log_module);
1516      END IF;
1517      RAISE;
1518  WHEN xla_exceptions_pkg.application_exception THEN
1519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1520       trace
1521          (p_msg      => 'ERROR: '||sqlerrm
1522          ,p_level    => C_LEVEL_EXCEPTION
1523          ,p_module   => l_log_module);
1524       END IF;
1525       RAISE;
1526  WHEN OTHERS THEN
1527        xla_exceptions_pkg.raise_message
1528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_13');
1529 END Description_13;
1530 
1531 ---------------------------------------
1532 --
1533 -- PRIVATE FUNCTION
1534 --         Description_14
1535 --
1536 ---------------------------------------
1537 FUNCTION Description_14 (
1538   p_application_id      IN NUMBER
1539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1540 --Period Close Date
1541  , p_source_1            IN DATE
1542 )
1543 RETURN VARCHAR2
1544 IS
1545 l_component_type        VARCHAR2(80)   ;
1546 l_component_code        VARCHAR2(30)   ;
1547 l_component_type_code   VARCHAR2(1)    ;
1548 l_component_appl_id     INTEGER        ;
1549 l_amb_context_code      VARCHAR2(30)   ;
1550 l_ledger_language       VARCHAR2(30)   ;
1551 l_source                VARCHAR2(1996) ;
1552 l_description           VARCHAR2(2000) ;
1553 l_log_module            VARCHAR2(240)  ;
1554 BEGIN
1555 IF g_log_enabled THEN
1556       l_log_module := C_DEFAULT_MODULE||'.Description_14';
1557 END IF;
1558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1559       trace
1560          (p_msg      => 'BEGIN of Description_14'
1561          ,p_level    => C_LEVEL_PROCEDURE
1562          ,p_module   => l_log_module);
1563 END IF;
1564 
1565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1566 l_component_type        := 'AMB_DESCRIPTION';
1570 l_amb_context_code      := 'DEFAULT';
1567 l_component_code        := 'FA_ADJUSTMENT_IC_REC';
1568 l_component_type_code   := 'S';
1569 l_component_appl_id     :=  140;
1571 l_source                := NULL;
1572 l_description           := NULL;
1573 
1574 
1575  
1576  IF 
1577 l_ledger_language = 'US' THEN
1578     l_description :=  SUBSTR(CONCAT(l_description,'Adjustment Intercompany Receivable'),1,2000);
1579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1580  END IF;  
1581  IF 
1582 l_ledger_language = 'US' THEN
1583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1585  END IF;   
1586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1588   IF l_source IS NOT NULL THEN
1589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1591   END IF; 
1592  l_description := SUBSTR(l_description,1,1996);
1593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1594         trace
1595            (p_msg      => 'END of Description_14'
1596            ,p_level    => C_LEVEL_PROCEDURE
1597            ,p_module   => l_log_module);
1598 
1599   END IF;
1600   RETURN l_description;
1601 
1602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1603       trace
1604          (p_msg      => 'END of Description_14'
1605          ,p_level    => C_LEVEL_PROCEDURE
1606          ,p_module   => l_log_module);
1607 END IF;
1608 RETURN NULL;
1609 EXCEPTION
1610   WHEN VALUE_ERROR THEN
1611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1612             trace
1613                (p_msg      => 'ERROR: '||sqlerrm
1614                ,p_level    => C_LEVEL_EXCEPTION
1615                ,p_module   => l_log_module);
1616      END IF;
1617      RAISE;
1618  WHEN xla_exceptions_pkg.application_exception THEN
1619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1620       trace
1621          (p_msg      => 'ERROR: '||sqlerrm
1622          ,p_level    => C_LEVEL_EXCEPTION
1623          ,p_module   => l_log_module);
1624       END IF;
1625       RAISE;
1626  WHEN OTHERS THEN
1627        xla_exceptions_pkg.raise_message
1628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_14');
1629 END Description_14;
1630 
1631 ---------------------------------------
1632 --
1633 -- PRIVATE FUNCTION
1634 --         Description_15
1635 --
1636 ---------------------------------------
1637 FUNCTION Description_15 (
1638   p_application_id      IN NUMBER
1639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1640 --Period Close Date
1641  , p_source_1            IN DATE
1642 )
1643 RETURN VARCHAR2
1644 IS
1645 l_component_type        VARCHAR2(80)   ;
1646 l_component_code        VARCHAR2(30)   ;
1647 l_component_type_code   VARCHAR2(1)    ;
1648 l_component_appl_id     INTEGER        ;
1649 l_amb_context_code      VARCHAR2(30)   ;
1650 l_ledger_language       VARCHAR2(30)   ;
1651 l_source                VARCHAR2(1996) ;
1652 l_description           VARCHAR2(2000) ;
1653 l_log_module            VARCHAR2(240)  ;
1654 BEGIN
1655 IF g_log_enabled THEN
1656       l_log_module := C_DEFAULT_MODULE||'.Description_15';
1657 END IF;
1658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1659       trace
1660          (p_msg      => 'BEGIN of Description_15'
1661          ,p_level    => C_LEVEL_PROCEDURE
1662          ,p_module   => l_log_module);
1663 END IF;
1664 
1665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1666 l_component_type        := 'AMB_DESCRIPTION';
1667 l_component_code        := 'FA_ADJUSTMENT_RESERVE';
1668 l_component_type_code   := 'S';
1669 l_component_appl_id     :=  140;
1670 l_amb_context_code      := 'DEFAULT';
1671 l_source                := NULL;
1672 l_description           := NULL;
1673 
1674 
1675  
1676  IF 
1677 l_ledger_language = 'US' THEN
1678     l_description :=  SUBSTR(CONCAT(l_description,'Adjustment Depreciation Reserve'),1,2000);
1679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1680  END IF;  
1681  IF 
1682 l_ledger_language = 'US' THEN
1683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1685  END IF;   
1686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1688   IF l_source IS NOT NULL THEN
1689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1691   END IF; 
1692  l_description := SUBSTR(l_description,1,1996);
1693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1694         trace
1695            (p_msg      => 'END of Description_15'
1696            ,p_level    => C_LEVEL_PROCEDURE
1697            ,p_module   => l_log_module);
1698 
1699   END IF;
1700   RETURN l_description;
1701 
1702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1703       trace
1704          (p_msg      => 'END of Description_15'
1705          ,p_level    => C_LEVEL_PROCEDURE
1706          ,p_module   => l_log_module);
1707 END IF;
1708 RETURN NULL;
1709 EXCEPTION
1710   WHEN VALUE_ERROR THEN
1711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1712             trace
1713                (p_msg      => 'ERROR: '||sqlerrm
1714                ,p_level    => C_LEVEL_EXCEPTION
1715                ,p_module   => l_log_module);
1716      END IF;
1717      RAISE;
1718  WHEN xla_exceptions_pkg.application_exception THEN
1722          ,p_level    => C_LEVEL_EXCEPTION
1719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1720       trace
1721          (p_msg      => 'ERROR: '||sqlerrm
1723          ,p_module   => l_log_module);
1724       END IF;
1725       RAISE;
1726  WHEN OTHERS THEN
1727        xla_exceptions_pkg.raise_message
1728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_15');
1729 END Description_15;
1730 
1731 ---------------------------------------
1732 --
1733 -- PRIVATE FUNCTION
1734 --         Description_16
1735 --
1736 ---------------------------------------
1737 FUNCTION Description_16 (
1738   p_application_id      IN NUMBER
1739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1740 --Period Close Date
1741  , p_source_1            IN DATE
1742 )
1743 RETURN VARCHAR2
1744 IS
1745 l_component_type        VARCHAR2(80)   ;
1746 l_component_code        VARCHAR2(30)   ;
1747 l_component_type_code   VARCHAR2(1)    ;
1748 l_component_appl_id     INTEGER        ;
1749 l_amb_context_code      VARCHAR2(30)   ;
1750 l_ledger_language       VARCHAR2(30)   ;
1751 l_source                VARCHAR2(1996) ;
1752 l_description           VARCHAR2(2000) ;
1753 l_log_module            VARCHAR2(240)  ;
1754 BEGIN
1755 IF g_log_enabled THEN
1756       l_log_module := C_DEFAULT_MODULE||'.Description_16';
1757 END IF;
1758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1759       trace
1760          (p_msg      => 'BEGIN of Description_16'
1761          ,p_level    => C_LEVEL_PROCEDURE
1762          ,p_module   => l_log_module);
1763 END IF;
1764 
1765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1766 l_component_type        := 'AMB_DESCRIPTION';
1767 l_component_code        := 'FA_CAPITALIZATION';
1768 l_component_type_code   := 'S';
1769 l_component_appl_id     :=  140;
1770 l_amb_context_code      := 'DEFAULT';
1771 l_source                := NULL;
1772 l_description           := NULL;
1773 
1774 
1775  
1776  IF 
1777 l_ledger_language = 'US' THEN
1778     l_description :=  SUBSTR(CONCAT(l_description,'Assets Capitalization'),1,2000);
1779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1780  END IF;  
1781  IF 
1782 l_ledger_language = 'US' THEN
1783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1785  END IF;   
1786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1788   IF l_source IS NOT NULL THEN
1789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1791   END IF; 
1792  l_description := SUBSTR(l_description,1,1996);
1793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1794         trace
1795            (p_msg      => 'END of Description_16'
1796            ,p_level    => C_LEVEL_PROCEDURE
1797            ,p_module   => l_log_module);
1798 
1799   END IF;
1800   RETURN l_description;
1801 
1802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1803       trace
1804          (p_msg      => 'END of Description_16'
1805          ,p_level    => C_LEVEL_PROCEDURE
1806          ,p_module   => l_log_module);
1807 END IF;
1808 RETURN NULL;
1809 EXCEPTION
1810   WHEN VALUE_ERROR THEN
1811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1812             trace
1813                (p_msg      => 'ERROR: '||sqlerrm
1814                ,p_level    => C_LEVEL_EXCEPTION
1815                ,p_module   => l_log_module);
1816      END IF;
1817      RAISE;
1818  WHEN xla_exceptions_pkg.application_exception THEN
1819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1820       trace
1821          (p_msg      => 'ERROR: '||sqlerrm
1822          ,p_level    => C_LEVEL_EXCEPTION
1823          ,p_module   => l_log_module);
1824       END IF;
1825       RAISE;
1826  WHEN OTHERS THEN
1827        xla_exceptions_pkg.raise_message
1828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_16');
1829 END Description_16;
1830 
1831 ---------------------------------------
1832 --
1833 -- PRIVATE FUNCTION
1834 --         Description_17
1835 --
1836 ---------------------------------------
1837 FUNCTION Description_17 (
1838   p_application_id      IN NUMBER
1839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1840 --Period Close Date
1841  , p_source_1            IN DATE
1842 )
1843 RETURN VARCHAR2
1844 IS
1845 l_component_type        VARCHAR2(80)   ;
1846 l_component_code        VARCHAR2(30)   ;
1847 l_component_type_code   VARCHAR2(1)    ;
1848 l_component_appl_id     INTEGER        ;
1849 l_amb_context_code      VARCHAR2(30)   ;
1850 l_ledger_language       VARCHAR2(30)   ;
1851 l_source                VARCHAR2(1996) ;
1852 l_description           VARCHAR2(2000) ;
1853 l_log_module            VARCHAR2(240)  ;
1854 BEGIN
1855 IF g_log_enabled THEN
1856       l_log_module := C_DEFAULT_MODULE||'.Description_17';
1857 END IF;
1858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1859       trace
1860          (p_msg      => 'BEGIN of Description_17'
1861          ,p_level    => C_LEVEL_PROCEDURE
1862          ,p_module   => l_log_module);
1863 END IF;
1864 
1865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1866 l_component_type        := 'AMB_DESCRIPTION';
1867 l_component_code        := 'FA_CAP_ASSET_BONUS_EXPENSE';
1868 l_component_type_code   := 'S';
1869 l_component_appl_id     :=  140;
1870 l_amb_context_code      := 'DEFAULT';
1871 l_source                := NULL;
1872 l_description           := NULL;
1873 
1874 
1875  
1876  IF 
1880  END IF;  
1877 l_ledger_language = 'US' THEN
1878     l_description :=  SUBSTR(CONCAT(l_description,'Assets Capitalization Bonus Expense'),1,2000);
1879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1881  IF 
1882 l_ledger_language = 'US' THEN
1883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1885  END IF;   
1886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1888   IF l_source IS NOT NULL THEN
1889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1891   END IF; 
1892  l_description := SUBSTR(l_description,1,1996);
1893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1894         trace
1895            (p_msg      => 'END of Description_17'
1896            ,p_level    => C_LEVEL_PROCEDURE
1897            ,p_module   => l_log_module);
1898 
1899   END IF;
1900   RETURN l_description;
1901 
1902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1903       trace
1904          (p_msg      => 'END of Description_17'
1905          ,p_level    => C_LEVEL_PROCEDURE
1906          ,p_module   => l_log_module);
1907 END IF;
1908 RETURN NULL;
1909 EXCEPTION
1910   WHEN VALUE_ERROR THEN
1911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1912             trace
1913                (p_msg      => 'ERROR: '||sqlerrm
1914                ,p_level    => C_LEVEL_EXCEPTION
1915                ,p_module   => l_log_module);
1916      END IF;
1917      RAISE;
1918  WHEN xla_exceptions_pkg.application_exception THEN
1919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1920       trace
1921          (p_msg      => 'ERROR: '||sqlerrm
1922          ,p_level    => C_LEVEL_EXCEPTION
1923          ,p_module   => l_log_module);
1924       END IF;
1925       RAISE;
1926  WHEN OTHERS THEN
1927        xla_exceptions_pkg.raise_message
1928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_17');
1929 END Description_17;
1930 
1931 ---------------------------------------
1932 --
1933 -- PRIVATE FUNCTION
1934 --         Description_18
1935 --
1936 ---------------------------------------
1937 FUNCTION Description_18 (
1938   p_application_id      IN NUMBER
1939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
1940 --Period Close Date
1941  , p_source_1            IN DATE
1942 )
1943 RETURN VARCHAR2
1944 IS
1945 l_component_type        VARCHAR2(80)   ;
1946 l_component_code        VARCHAR2(30)   ;
1947 l_component_type_code   VARCHAR2(1)    ;
1948 l_component_appl_id     INTEGER        ;
1949 l_amb_context_code      VARCHAR2(30)   ;
1950 l_ledger_language       VARCHAR2(30)   ;
1951 l_source                VARCHAR2(1996) ;
1952 l_description           VARCHAR2(2000) ;
1953 l_log_module            VARCHAR2(240)  ;
1954 BEGIN
1955 IF g_log_enabled THEN
1956       l_log_module := C_DEFAULT_MODULE||'.Description_18';
1957 END IF;
1958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1959       trace
1960          (p_msg      => 'BEGIN of Description_18'
1961          ,p_level    => C_LEVEL_PROCEDURE
1962          ,p_module   => l_log_module);
1963 END IF;
1964 
1965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
1966 l_component_type        := 'AMB_DESCRIPTION';
1967 l_component_code        := 'FA_CAP_ASSET_BONUS_RESERVE';
1968 l_component_type_code   := 'S';
1969 l_component_appl_id     :=  140;
1970 l_amb_context_code      := 'DEFAULT';
1971 l_source                := NULL;
1972 l_description           := NULL;
1973 
1974 
1975  
1976  IF 
1977 l_ledger_language = 'US' THEN
1978     l_description :=  SUBSTR(CONCAT(l_description,'Assets Capitalization Bonus Reserve'),1,2000);
1979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1980  END IF;  
1981  IF 
1982 l_ledger_language = 'US' THEN
1983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
1984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
1985  END IF;   
1986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
1987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
1988   IF l_source IS NOT NULL THEN
1989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
1990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
1991   END IF; 
1992  l_description := SUBSTR(l_description,1,1996);
1993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1994         trace
1995            (p_msg      => 'END of Description_18'
1996            ,p_level    => C_LEVEL_PROCEDURE
1997            ,p_module   => l_log_module);
1998 
1999   END IF;
2000   RETURN l_description;
2001 
2002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2003       trace
2004          (p_msg      => 'END of Description_18'
2005          ,p_level    => C_LEVEL_PROCEDURE
2006          ,p_module   => l_log_module);
2007 END IF;
2008 RETURN NULL;
2009 EXCEPTION
2010   WHEN VALUE_ERROR THEN
2011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2012             trace
2013                (p_msg      => 'ERROR: '||sqlerrm
2014                ,p_level    => C_LEVEL_EXCEPTION
2015                ,p_module   => l_log_module);
2016      END IF;
2017      RAISE;
2018  WHEN xla_exceptions_pkg.application_exception THEN
2019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2020       trace
2021          (p_msg      => 'ERROR: '||sqlerrm
2022          ,p_level    => C_LEVEL_EXCEPTION
2023          ,p_module   => l_log_module);
2024       END IF;
2025       RAISE;
2026  WHEN OTHERS THEN
2027        xla_exceptions_pkg.raise_message
2031 ---------------------------------------
2028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_18');
2029 END Description_18;
2030 
2032 --
2033 -- PRIVATE FUNCTION
2034 --         Description_19
2035 --
2036 ---------------------------------------
2037 FUNCTION Description_19 (
2038   p_application_id      IN NUMBER
2039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2040 --Period Close Date
2041  , p_source_1            IN DATE
2042 )
2043 RETURN VARCHAR2
2044 IS
2045 l_component_type        VARCHAR2(80)   ;
2046 l_component_code        VARCHAR2(30)   ;
2047 l_component_type_code   VARCHAR2(1)    ;
2048 l_component_appl_id     INTEGER        ;
2049 l_amb_context_code      VARCHAR2(30)   ;
2050 l_ledger_language       VARCHAR2(30)   ;
2051 l_source                VARCHAR2(1996) ;
2052 l_description           VARCHAR2(2000) ;
2053 l_log_module            VARCHAR2(240)  ;
2054 BEGIN
2055 IF g_log_enabled THEN
2056       l_log_module := C_DEFAULT_MODULE||'.Description_19';
2057 END IF;
2058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2059       trace
2060          (p_msg      => 'BEGIN of Description_19'
2061          ,p_level    => C_LEVEL_PROCEDURE
2062          ,p_module   => l_log_module);
2063 END IF;
2064 
2065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2066 l_component_type        := 'AMB_DESCRIPTION';
2067 l_component_code        := 'FA_CAP_ASSET_CIP_COST';
2068 l_component_type_code   := 'S';
2069 l_component_appl_id     :=  140;
2070 l_amb_context_code      := 'DEFAULT';
2071 l_source                := NULL;
2072 l_description           := NULL;
2073 
2074 
2075  
2076  IF 
2077 l_ledger_language = 'US' THEN
2078     l_description :=  SUBSTR(CONCAT(l_description,'Assets Capitalization CIP Cost'),1,2000);
2079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2080  END IF;  
2081  IF 
2082 l_ledger_language = 'US' THEN
2083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2085  END IF;   
2086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2088   IF l_source IS NOT NULL THEN
2089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2091   END IF; 
2092  l_description := SUBSTR(l_description,1,1996);
2093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2094         trace
2095            (p_msg      => 'END of Description_19'
2096            ,p_level    => C_LEVEL_PROCEDURE
2097            ,p_module   => l_log_module);
2098 
2099   END IF;
2100   RETURN l_description;
2101 
2102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2103       trace
2104          (p_msg      => 'END of Description_19'
2105          ,p_level    => C_LEVEL_PROCEDURE
2106          ,p_module   => l_log_module);
2107 END IF;
2108 RETURN NULL;
2109 EXCEPTION
2110   WHEN VALUE_ERROR THEN
2111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2112             trace
2113                (p_msg      => 'ERROR: '||sqlerrm
2114                ,p_level    => C_LEVEL_EXCEPTION
2115                ,p_module   => l_log_module);
2116      END IF;
2117      RAISE;
2118  WHEN xla_exceptions_pkg.application_exception THEN
2119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2120       trace
2121          (p_msg      => 'ERROR: '||sqlerrm
2122          ,p_level    => C_LEVEL_EXCEPTION
2123          ,p_module   => l_log_module);
2124       END IF;
2125       RAISE;
2126  WHEN OTHERS THEN
2127        xla_exceptions_pkg.raise_message
2128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_19');
2129 END Description_19;
2130 
2131 ---------------------------------------
2132 --
2133 -- PRIVATE FUNCTION
2134 --         Description_20
2135 --
2136 ---------------------------------------
2137 FUNCTION Description_20 (
2138   p_application_id      IN NUMBER
2139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2140 --Period Close Date
2141  , p_source_1            IN DATE
2142 )
2143 RETURN VARCHAR2
2144 IS
2145 l_component_type        VARCHAR2(80)   ;
2146 l_component_code        VARCHAR2(30)   ;
2147 l_component_type_code   VARCHAR2(1)    ;
2148 l_component_appl_id     INTEGER        ;
2149 l_amb_context_code      VARCHAR2(30)   ;
2150 l_ledger_language       VARCHAR2(30)   ;
2151 l_source                VARCHAR2(1996) ;
2152 l_description           VARCHAR2(2000) ;
2153 l_log_module            VARCHAR2(240)  ;
2154 BEGIN
2155 IF g_log_enabled THEN
2156       l_log_module := C_DEFAULT_MODULE||'.Description_20';
2157 END IF;
2158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2159       trace
2160          (p_msg      => 'BEGIN of Description_20'
2161          ,p_level    => C_LEVEL_PROCEDURE
2162          ,p_module   => l_log_module);
2163 END IF;
2164 
2165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2166 l_component_type        := 'AMB_DESCRIPTION';
2167 l_component_code        := 'FA_CAP_ASSET_COST';
2168 l_component_type_code   := 'S';
2169 l_component_appl_id     :=  140;
2170 l_amb_context_code      := 'DEFAULT';
2171 l_source                := NULL;
2172 l_description           := NULL;
2173 
2174 
2175  
2176  IF 
2177 l_ledger_language = 'US' THEN
2178     l_description :=  SUBSTR(CONCAT(l_description,'Assets Capitalization Cost'),1,2000);
2179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2180  END IF;  
2181  IF 
2182 l_ledger_language = 'US' THEN
2183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2185  END IF;   
2186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2188   IF l_source IS NOT NULL THEN
2189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2191   END IF; 
2192  l_description := SUBSTR(l_description,1,1996);
2193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2194         trace
2195            (p_msg      => 'END of Description_20'
2196            ,p_level    => C_LEVEL_PROCEDURE
2197            ,p_module   => l_log_module);
2198 
2199   END IF;
2200   RETURN l_description;
2201 
2202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2203       trace
2204          (p_msg      => 'END of Description_20'
2205          ,p_level    => C_LEVEL_PROCEDURE
2206          ,p_module   => l_log_module);
2207 END IF;
2208 RETURN NULL;
2209 EXCEPTION
2210   WHEN VALUE_ERROR THEN
2211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2212             trace
2213                (p_msg      => 'ERROR: '||sqlerrm
2214                ,p_level    => C_LEVEL_EXCEPTION
2215                ,p_module   => l_log_module);
2216      END IF;
2217      RAISE;
2218  WHEN xla_exceptions_pkg.application_exception THEN
2219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2220       trace
2221          (p_msg      => 'ERROR: '||sqlerrm
2222          ,p_level    => C_LEVEL_EXCEPTION
2223          ,p_module   => l_log_module);
2224       END IF;
2225       RAISE;
2226  WHEN OTHERS THEN
2227        xla_exceptions_pkg.raise_message
2228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_20');
2229 END Description_20;
2230 
2231 ---------------------------------------
2232 --
2233 -- PRIVATE FUNCTION
2234 --         Description_21
2235 --
2236 ---------------------------------------
2237 FUNCTION Description_21 (
2238   p_application_id      IN NUMBER
2239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2240 --Period Close Date
2241  , p_source_1            IN DATE
2242 )
2243 RETURN VARCHAR2
2244 IS
2245 l_component_type        VARCHAR2(80)   ;
2246 l_component_code        VARCHAR2(30)   ;
2247 l_component_type_code   VARCHAR2(1)    ;
2248 l_component_appl_id     INTEGER        ;
2249 l_amb_context_code      VARCHAR2(30)   ;
2250 l_ledger_language       VARCHAR2(30)   ;
2251 l_source                VARCHAR2(1996) ;
2252 l_description           VARCHAR2(2000) ;
2253 l_log_module            VARCHAR2(240)  ;
2254 BEGIN
2255 IF g_log_enabled THEN
2256       l_log_module := C_DEFAULT_MODULE||'.Description_21';
2257 END IF;
2258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2259       trace
2260          (p_msg      => 'BEGIN of Description_21'
2261          ,p_level    => C_LEVEL_PROCEDURE
2262          ,p_module   => l_log_module);
2263 END IF;
2264 
2265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2266 l_component_type        := 'AMB_DESCRIPTION';
2267 l_component_code        := 'FA_CAP_ASSET_EXPENSE';
2268 l_component_type_code   := 'S';
2269 l_component_appl_id     :=  140;
2270 l_amb_context_code      := 'DEFAULT';
2271 l_source                := NULL;
2272 l_description           := NULL;
2273 
2274 
2275  
2276  IF 
2277 l_ledger_language = 'US' THEN
2278     l_description :=  SUBSTR(CONCAT(l_description,'Assets Capitalization Expense'),1,2000);
2279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2280  END IF;  
2281  IF 
2282 l_ledger_language = 'US' THEN
2283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2285  END IF;   
2286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2288   IF l_source IS NOT NULL THEN
2289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2291   END IF; 
2292  l_description := SUBSTR(l_description,1,1996);
2293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2294         trace
2295            (p_msg      => 'END of Description_21'
2296            ,p_level    => C_LEVEL_PROCEDURE
2297            ,p_module   => l_log_module);
2298 
2299   END IF;
2300   RETURN l_description;
2301 
2302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2303       trace
2304          (p_msg      => 'END of Description_21'
2305          ,p_level    => C_LEVEL_PROCEDURE
2306          ,p_module   => l_log_module);
2307 END IF;
2308 RETURN NULL;
2309 EXCEPTION
2310   WHEN VALUE_ERROR THEN
2311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2312             trace
2313                (p_msg      => 'ERROR: '||sqlerrm
2314                ,p_level    => C_LEVEL_EXCEPTION
2315                ,p_module   => l_log_module);
2316      END IF;
2317      RAISE;
2318  WHEN xla_exceptions_pkg.application_exception THEN
2319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2320       trace
2321          (p_msg      => 'ERROR: '||sqlerrm
2322          ,p_level    => C_LEVEL_EXCEPTION
2323          ,p_module   => l_log_module);
2324       END IF;
2325       RAISE;
2326  WHEN OTHERS THEN
2327        xla_exceptions_pkg.raise_message
2328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_21');
2329 END Description_21;
2330 
2331 ---------------------------------------
2332 --
2333 -- PRIVATE FUNCTION
2334 --         Description_22
2335 --
2336 ---------------------------------------
2337 FUNCTION Description_22 (
2341  , p_source_1            IN DATE
2338   p_application_id      IN NUMBER
2339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2340 --Period Close Date
2342 )
2343 RETURN VARCHAR2
2344 IS
2345 l_component_type        VARCHAR2(80)   ;
2346 l_component_code        VARCHAR2(30)   ;
2347 l_component_type_code   VARCHAR2(1)    ;
2348 l_component_appl_id     INTEGER        ;
2349 l_amb_context_code      VARCHAR2(30)   ;
2350 l_ledger_language       VARCHAR2(30)   ;
2351 l_source                VARCHAR2(1996) ;
2352 l_description           VARCHAR2(2000) ;
2353 l_log_module            VARCHAR2(240)  ;
2354 BEGIN
2355 IF g_log_enabled THEN
2356       l_log_module := C_DEFAULT_MODULE||'.Description_22';
2357 END IF;
2358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2359       trace
2360          (p_msg      => 'BEGIN of Description_22'
2361          ,p_level    => C_LEVEL_PROCEDURE
2362          ,p_module   => l_log_module);
2363 END IF;
2364 
2365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2366 l_component_type        := 'AMB_DESCRIPTION';
2367 l_component_code        := 'FA_CAP_ASSET_RESERVE';
2368 l_component_type_code   := 'S';
2369 l_component_appl_id     :=  140;
2370 l_amb_context_code      := 'DEFAULT';
2371 l_source                := NULL;
2372 l_description           := NULL;
2373 
2374 
2375  
2376  IF 
2377 l_ledger_language = 'US' THEN
2378     l_description :=  SUBSTR(CONCAT(l_description,'Assets Capitalization Reserve'),1,2000);
2379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2380  END IF;  
2381  IF 
2382 l_ledger_language = 'US' THEN
2383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2385  END IF;   
2386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2388   IF l_source IS NOT NULL THEN
2389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2391   END IF; 
2392  l_description := SUBSTR(l_description,1,1996);
2393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2394         trace
2395            (p_msg      => 'END of Description_22'
2396            ,p_level    => C_LEVEL_PROCEDURE
2397            ,p_module   => l_log_module);
2398 
2399   END IF;
2400   RETURN l_description;
2401 
2402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2403       trace
2404          (p_msg      => 'END of Description_22'
2405          ,p_level    => C_LEVEL_PROCEDURE
2406          ,p_module   => l_log_module);
2407 END IF;
2408 RETURN NULL;
2409 EXCEPTION
2410   WHEN VALUE_ERROR THEN
2411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2412             trace
2413                (p_msg      => 'ERROR: '||sqlerrm
2414                ,p_level    => C_LEVEL_EXCEPTION
2415                ,p_module   => l_log_module);
2416      END IF;
2417      RAISE;
2418  WHEN xla_exceptions_pkg.application_exception THEN
2419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2420       trace
2421          (p_msg      => 'ERROR: '||sqlerrm
2422          ,p_level    => C_LEVEL_EXCEPTION
2423          ,p_module   => l_log_module);
2424       END IF;
2425       RAISE;
2426  WHEN OTHERS THEN
2427        xla_exceptions_pkg.raise_message
2428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_22');
2429 END Description_22;
2430 
2431 ---------------------------------------
2432 --
2433 -- PRIVATE FUNCTION
2434 --         Description_23
2435 --
2436 ---------------------------------------
2437 FUNCTION Description_23 (
2438   p_application_id      IN NUMBER
2439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2440 --Period Close Date
2441  , p_source_1            IN DATE
2442 )
2443 RETURN VARCHAR2
2444 IS
2445 l_component_type        VARCHAR2(80)   ;
2446 l_component_code        VARCHAR2(30)   ;
2447 l_component_type_code   VARCHAR2(1)    ;
2448 l_component_appl_id     INTEGER        ;
2449 l_amb_context_code      VARCHAR2(30)   ;
2450 l_ledger_language       VARCHAR2(30)   ;
2451 l_source                VARCHAR2(1996) ;
2452 l_description           VARCHAR2(2000) ;
2453 l_log_module            VARCHAR2(240)  ;
2454 BEGIN
2455 IF g_log_enabled THEN
2456       l_log_module := C_DEFAULT_MODULE||'.Description_23';
2457 END IF;
2458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2459       trace
2460          (p_msg      => 'BEGIN of Description_23'
2461          ,p_level    => C_LEVEL_PROCEDURE
2462          ,p_module   => l_log_module);
2463 END IF;
2464 
2465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2466 l_component_type        := 'AMB_DESCRIPTION';
2467 l_component_code        := 'FA_CIP_ADDITION';
2468 l_component_type_code   := 'S';
2469 l_component_appl_id     :=  140;
2470 l_amb_context_code      := 'DEFAULT';
2471 l_source                := NULL;
2472 l_description           := NULL;
2473 
2474 
2475  
2476  IF 
2477 l_ledger_language = 'US' THEN
2478     l_description :=  SUBSTR(CONCAT(l_description,'CIP Addition'),1,2000);
2479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2480  END IF;  
2481  IF 
2482 l_ledger_language = 'US' THEN
2483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2485  END IF;   
2486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2488   IF l_source IS NOT NULL THEN
2492  l_description := SUBSTR(l_description,1,1996);
2489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2491   END IF; 
2493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2494         trace
2495            (p_msg      => 'END of Description_23'
2496            ,p_level    => C_LEVEL_PROCEDURE
2497            ,p_module   => l_log_module);
2498 
2499   END IF;
2500   RETURN l_description;
2501 
2502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2503       trace
2504          (p_msg      => 'END of Description_23'
2505          ,p_level    => C_LEVEL_PROCEDURE
2506          ,p_module   => l_log_module);
2507 END IF;
2508 RETURN NULL;
2509 EXCEPTION
2510   WHEN VALUE_ERROR THEN
2511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2512             trace
2513                (p_msg      => 'ERROR: '||sqlerrm
2514                ,p_level    => C_LEVEL_EXCEPTION
2515                ,p_module   => l_log_module);
2516      END IF;
2517      RAISE;
2518  WHEN xla_exceptions_pkg.application_exception THEN
2519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2520       trace
2521          (p_msg      => 'ERROR: '||sqlerrm
2522          ,p_level    => C_LEVEL_EXCEPTION
2523          ,p_module   => l_log_module);
2524       END IF;
2525       RAISE;
2526  WHEN OTHERS THEN
2527        xla_exceptions_pkg.raise_message
2528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_23');
2529 END Description_23;
2530 
2531 ---------------------------------------
2532 --
2533 -- PRIVATE FUNCTION
2534 --         Description_24
2535 --
2536 ---------------------------------------
2537 FUNCTION Description_24 (
2538   p_application_id      IN NUMBER
2539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2540 --Period Close Date
2541  , p_source_1            IN DATE
2542 )
2543 RETURN VARCHAR2
2544 IS
2545 l_component_type        VARCHAR2(80)   ;
2546 l_component_code        VARCHAR2(30)   ;
2547 l_component_type_code   VARCHAR2(1)    ;
2548 l_component_appl_id     INTEGER        ;
2549 l_amb_context_code      VARCHAR2(30)   ;
2550 l_ledger_language       VARCHAR2(30)   ;
2551 l_source                VARCHAR2(1996) ;
2552 l_description           VARCHAR2(2000) ;
2553 l_log_module            VARCHAR2(240)  ;
2554 BEGIN
2555 IF g_log_enabled THEN
2556       l_log_module := C_DEFAULT_MODULE||'.Description_24';
2557 END IF;
2558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2559       trace
2560          (p_msg      => 'BEGIN of Description_24'
2561          ,p_level    => C_LEVEL_PROCEDURE
2562          ,p_module   => l_log_module);
2563 END IF;
2564 
2565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2566 l_component_type        := 'AMB_DESCRIPTION';
2567 l_component_code        := 'FA_CIP_ADDITION_COST';
2568 l_component_type_code   := 'S';
2569 l_component_appl_id     :=  140;
2570 l_amb_context_code      := 'DEFAULT';
2571 l_source                := NULL;
2572 l_description           := NULL;
2573 
2574 
2575  
2576  IF 
2577 l_ledger_language = 'US' THEN
2578     l_description :=  SUBSTR(CONCAT(l_description,'CIP Addition Cost'),1,2000);
2579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2580  END IF;  
2581  IF 
2582 l_ledger_language = 'US' THEN
2583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2585  END IF;   
2586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2588   IF l_source IS NOT NULL THEN
2589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2591   END IF; 
2592  l_description := SUBSTR(l_description,1,1996);
2593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2594         trace
2595            (p_msg      => 'END of Description_24'
2596            ,p_level    => C_LEVEL_PROCEDURE
2597            ,p_module   => l_log_module);
2598 
2599   END IF;
2600   RETURN l_description;
2601 
2602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2603       trace
2604          (p_msg      => 'END of Description_24'
2605          ,p_level    => C_LEVEL_PROCEDURE
2606          ,p_module   => l_log_module);
2607 END IF;
2608 RETURN NULL;
2609 EXCEPTION
2610   WHEN VALUE_ERROR THEN
2611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2612             trace
2613                (p_msg      => 'ERROR: '||sqlerrm
2614                ,p_level    => C_LEVEL_EXCEPTION
2615                ,p_module   => l_log_module);
2616      END IF;
2617      RAISE;
2618  WHEN xla_exceptions_pkg.application_exception THEN
2619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2620       trace
2621          (p_msg      => 'ERROR: '||sqlerrm
2622          ,p_level    => C_LEVEL_EXCEPTION
2623          ,p_module   => l_log_module);
2624       END IF;
2625       RAISE;
2626  WHEN OTHERS THEN
2627        xla_exceptions_pkg.raise_message
2628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_24');
2629 END Description_24;
2630 
2631 ---------------------------------------
2632 --
2633 -- PRIVATE FUNCTION
2634 --         Description_25
2635 --
2636 ---------------------------------------
2637 FUNCTION Description_25 (
2638   p_application_id      IN NUMBER
2639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2640 --Period Close Date
2641  , p_source_1            IN DATE
2642 )
2643 RETURN VARCHAR2
2644 IS
2645 l_component_type        VARCHAR2(80)   ;
2646 l_component_code        VARCHAR2(30)   ;
2650 l_ledger_language       VARCHAR2(30)   ;
2647 l_component_type_code   VARCHAR2(1)    ;
2648 l_component_appl_id     INTEGER        ;
2649 l_amb_context_code      VARCHAR2(30)   ;
2651 l_source                VARCHAR2(1996) ;
2652 l_description           VARCHAR2(2000) ;
2653 l_log_module            VARCHAR2(240)  ;
2654 BEGIN
2655 IF g_log_enabled THEN
2656       l_log_module := C_DEFAULT_MODULE||'.Description_25';
2657 END IF;
2658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2659       trace
2660          (p_msg      => 'BEGIN of Description_25'
2661          ,p_level    => C_LEVEL_PROCEDURE
2662          ,p_module   => l_log_module);
2663 END IF;
2664 
2665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2666 l_component_type        := 'AMB_DESCRIPTION';
2667 l_component_code        := 'FA_CIP_ADDITION_COST_CLEARING';
2668 l_component_type_code   := 'S';
2669 l_component_appl_id     :=  140;
2670 l_amb_context_code      := 'DEFAULT';
2671 l_source                := NULL;
2672 l_description           := NULL;
2673 
2674 
2675  
2676  IF 
2677 l_ledger_language = 'US' THEN
2678     l_description :=  SUBSTR(CONCAT(l_description,'Addition CIP Cost Clearing'),1,2000);
2679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2680  END IF;  
2681  IF 
2682 l_ledger_language = 'US' THEN
2683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2685  END IF;   
2686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2688   IF l_source IS NOT NULL THEN
2689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2691   END IF; 
2692  l_description := SUBSTR(l_description,1,1996);
2693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2694         trace
2695            (p_msg      => 'END of Description_25'
2696            ,p_level    => C_LEVEL_PROCEDURE
2697            ,p_module   => l_log_module);
2698 
2699   END IF;
2700   RETURN l_description;
2701 
2702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2703       trace
2704          (p_msg      => 'END of Description_25'
2705          ,p_level    => C_LEVEL_PROCEDURE
2706          ,p_module   => l_log_module);
2707 END IF;
2708 RETURN NULL;
2709 EXCEPTION
2710   WHEN VALUE_ERROR THEN
2711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2712             trace
2713                (p_msg      => 'ERROR: '||sqlerrm
2714                ,p_level    => C_LEVEL_EXCEPTION
2715                ,p_module   => l_log_module);
2716      END IF;
2717      RAISE;
2718  WHEN xla_exceptions_pkg.application_exception THEN
2719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2720       trace
2721          (p_msg      => 'ERROR: '||sqlerrm
2722          ,p_level    => C_LEVEL_EXCEPTION
2723          ,p_module   => l_log_module);
2724       END IF;
2725       RAISE;
2726  WHEN OTHERS THEN
2727        xla_exceptions_pkg.raise_message
2728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_25');
2729 END Description_25;
2730 
2731 ---------------------------------------
2732 --
2733 -- PRIVATE FUNCTION
2734 --         Description_26
2735 --
2736 ---------------------------------------
2737 FUNCTION Description_26 (
2738   p_application_id      IN NUMBER
2739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2740 --Period Close Date
2741  , p_source_1            IN DATE
2742 )
2743 RETURN VARCHAR2
2744 IS
2745 l_component_type        VARCHAR2(80)   ;
2746 l_component_code        VARCHAR2(30)   ;
2747 l_component_type_code   VARCHAR2(1)    ;
2748 l_component_appl_id     INTEGER        ;
2749 l_amb_context_code      VARCHAR2(30)   ;
2750 l_ledger_language       VARCHAR2(30)   ;
2751 l_source                VARCHAR2(1996) ;
2752 l_description           VARCHAR2(2000) ;
2753 l_log_module            VARCHAR2(240)  ;
2754 BEGIN
2755 IF g_log_enabled THEN
2756       l_log_module := C_DEFAULT_MODULE||'.Description_26';
2757 END IF;
2758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2759       trace
2760          (p_msg      => 'BEGIN of Description_26'
2761          ,p_level    => C_LEVEL_PROCEDURE
2762          ,p_module   => l_log_module);
2763 END IF;
2764 
2765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2766 l_component_type        := 'AMB_DESCRIPTION';
2767 l_component_code        := 'FA_CIP_ADJUSTMENT';
2768 l_component_type_code   := 'S';
2769 l_component_appl_id     :=  140;
2770 l_amb_context_code      := 'DEFAULT';
2771 l_source                := NULL;
2772 l_description           := NULL;
2773 
2774 
2775  
2776  IF 
2777 l_ledger_language = 'US' THEN
2778     l_description :=  SUBSTR(CONCAT(l_description,'CIP Adjustment'),1,2000);
2779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2780  END IF;  
2781  IF 
2782 l_ledger_language = 'US' THEN
2783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2785  END IF;   
2786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2788   IF l_source IS NOT NULL THEN
2789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2791   END IF; 
2792  l_description := SUBSTR(l_description,1,1996);
2793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2794         trace
2795            (p_msg      => 'END of Description_26'
2799   END IF;
2796            ,p_level    => C_LEVEL_PROCEDURE
2797            ,p_module   => l_log_module);
2798 
2800   RETURN l_description;
2801 
2802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2803       trace
2804          (p_msg      => 'END of Description_26'
2805          ,p_level    => C_LEVEL_PROCEDURE
2806          ,p_module   => l_log_module);
2807 END IF;
2808 RETURN NULL;
2809 EXCEPTION
2810   WHEN VALUE_ERROR THEN
2811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2812             trace
2813                (p_msg      => 'ERROR: '||sqlerrm
2814                ,p_level    => C_LEVEL_EXCEPTION
2815                ,p_module   => l_log_module);
2816      END IF;
2817      RAISE;
2818  WHEN xla_exceptions_pkg.application_exception THEN
2819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2820       trace
2821          (p_msg      => 'ERROR: '||sqlerrm
2822          ,p_level    => C_LEVEL_EXCEPTION
2823          ,p_module   => l_log_module);
2824       END IF;
2825       RAISE;
2826  WHEN OTHERS THEN
2827        xla_exceptions_pkg.raise_message
2828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_26');
2829 END Description_26;
2830 
2831 ---------------------------------------
2832 --
2833 -- PRIVATE FUNCTION
2834 --         Description_27
2835 --
2836 ---------------------------------------
2837 FUNCTION Description_27 (
2838   p_application_id      IN NUMBER
2839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2840 --Period Close Date
2841  , p_source_1            IN DATE
2842 )
2843 RETURN VARCHAR2
2844 IS
2845 l_component_type        VARCHAR2(80)   ;
2846 l_component_code        VARCHAR2(30)   ;
2847 l_component_type_code   VARCHAR2(1)    ;
2848 l_component_appl_id     INTEGER        ;
2849 l_amb_context_code      VARCHAR2(30)   ;
2850 l_ledger_language       VARCHAR2(30)   ;
2851 l_source                VARCHAR2(1996) ;
2852 l_description           VARCHAR2(2000) ;
2853 l_log_module            VARCHAR2(240)  ;
2854 BEGIN
2855 IF g_log_enabled THEN
2856       l_log_module := C_DEFAULT_MODULE||'.Description_27';
2857 END IF;
2858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2859       trace
2860          (p_msg      => 'BEGIN of Description_27'
2861          ,p_level    => C_LEVEL_PROCEDURE
2862          ,p_module   => l_log_module);
2863 END IF;
2864 
2865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2866 l_component_type        := 'AMB_DESCRIPTION';
2867 l_component_code        := 'FA_CIP_ADJUSTMENT_COST';
2868 l_component_type_code   := 'S';
2869 l_component_appl_id     :=  140;
2870 l_amb_context_code      := 'DEFAULT';
2871 l_source                := NULL;
2872 l_description           := NULL;
2873 
2874 
2875  
2876  IF 
2877 l_ledger_language = 'US' THEN
2878     l_description :=  SUBSTR(CONCAT(l_description,'CIP Adjustment Cost'),1,2000);
2879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2880  END IF;  
2881  IF 
2882 l_ledger_language = 'US' THEN
2883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2885  END IF;   
2886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2888   IF l_source IS NOT NULL THEN
2889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2891   END IF; 
2892  l_description := SUBSTR(l_description,1,1996);
2893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2894         trace
2895            (p_msg      => 'END of Description_27'
2896            ,p_level    => C_LEVEL_PROCEDURE
2897            ,p_module   => l_log_module);
2898 
2899   END IF;
2900   RETURN l_description;
2901 
2902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2903       trace
2904          (p_msg      => 'END of Description_27'
2905          ,p_level    => C_LEVEL_PROCEDURE
2906          ,p_module   => l_log_module);
2907 END IF;
2908 RETURN NULL;
2909 EXCEPTION
2910   WHEN VALUE_ERROR THEN
2911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2912             trace
2913                (p_msg      => 'ERROR: '||sqlerrm
2914                ,p_level    => C_LEVEL_EXCEPTION
2915                ,p_module   => l_log_module);
2916      END IF;
2917      RAISE;
2918  WHEN xla_exceptions_pkg.application_exception THEN
2919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2920       trace
2921          (p_msg      => 'ERROR: '||sqlerrm
2922          ,p_level    => C_LEVEL_EXCEPTION
2923          ,p_module   => l_log_module);
2924       END IF;
2925       RAISE;
2926  WHEN OTHERS THEN
2927        xla_exceptions_pkg.raise_message
2928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_27');
2929 END Description_27;
2930 
2931 ---------------------------------------
2932 --
2933 -- PRIVATE FUNCTION
2934 --         Description_28
2935 --
2936 ---------------------------------------
2937 FUNCTION Description_28 (
2938   p_application_id      IN NUMBER
2939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
2940 --Period Close Date
2941  , p_source_1            IN DATE
2942 )
2943 RETURN VARCHAR2
2944 IS
2945 l_component_type        VARCHAR2(80)   ;
2946 l_component_code        VARCHAR2(30)   ;
2947 l_component_type_code   VARCHAR2(1)    ;
2948 l_component_appl_id     INTEGER        ;
2949 l_amb_context_code      VARCHAR2(30)   ;
2950 l_ledger_language       VARCHAR2(30)   ;
2951 l_source                VARCHAR2(1996) ;
2952 l_description           VARCHAR2(2000) ;
2953 l_log_module            VARCHAR2(240)  ;
2954 BEGIN
2958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2955 IF g_log_enabled THEN
2956       l_log_module := C_DEFAULT_MODULE||'.Description_28';
2957 END IF;
2959       trace
2960          (p_msg      => 'BEGIN of Description_28'
2961          ,p_level    => C_LEVEL_PROCEDURE
2962          ,p_module   => l_log_module);
2963 END IF;
2964 
2965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2966 l_component_type        := 'AMB_DESCRIPTION';
2967 l_component_code        := 'FA_CIP_RECLASS';
2968 l_component_type_code   := 'S';
2969 l_component_appl_id     :=  140;
2970 l_amb_context_code      := 'DEFAULT';
2971 l_source                := NULL;
2972 l_description           := NULL;
2973 
2974 
2975  
2976  IF 
2977 l_ledger_language = 'US' THEN
2978     l_description :=  SUBSTR(CONCAT(l_description,'CIP Category Reclass'),1,2000);
2979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2980  END IF;  
2981  IF 
2982 l_ledger_language = 'US' THEN
2983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
2984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
2985  END IF;   
2986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
2987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
2988   IF l_source IS NOT NULL THEN
2989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
2990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
2991   END IF; 
2992  l_description := SUBSTR(l_description,1,1996);
2993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2994         trace
2995            (p_msg      => 'END of Description_28'
2996            ,p_level    => C_LEVEL_PROCEDURE
2997            ,p_module   => l_log_module);
2998 
2999   END IF;
3000   RETURN l_description;
3001 
3002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3003       trace
3004          (p_msg      => 'END of Description_28'
3005          ,p_level    => C_LEVEL_PROCEDURE
3006          ,p_module   => l_log_module);
3007 END IF;
3008 RETURN NULL;
3009 EXCEPTION
3010   WHEN VALUE_ERROR THEN
3011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3012             trace
3013                (p_msg      => 'ERROR: '||sqlerrm
3014                ,p_level    => C_LEVEL_EXCEPTION
3015                ,p_module   => l_log_module);
3016      END IF;
3017      RAISE;
3018  WHEN xla_exceptions_pkg.application_exception THEN
3019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3020       trace
3021          (p_msg      => 'ERROR: '||sqlerrm
3022          ,p_level    => C_LEVEL_EXCEPTION
3023          ,p_module   => l_log_module);
3024       END IF;
3025       RAISE;
3026  WHEN OTHERS THEN
3027        xla_exceptions_pkg.raise_message
3028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_28');
3029 END Description_28;
3030 
3031 ---------------------------------------
3032 --
3033 -- PRIVATE FUNCTION
3034 --         Description_29
3035 --
3036 ---------------------------------------
3037 FUNCTION Description_29 (
3038   p_application_id      IN NUMBER
3039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3040 --Period Close Date
3041  , p_source_1            IN DATE
3042 )
3043 RETURN VARCHAR2
3044 IS
3045 l_component_type        VARCHAR2(80)   ;
3046 l_component_code        VARCHAR2(30)   ;
3047 l_component_type_code   VARCHAR2(1)    ;
3048 l_component_appl_id     INTEGER        ;
3049 l_amb_context_code      VARCHAR2(30)   ;
3050 l_ledger_language       VARCHAR2(30)   ;
3051 l_source                VARCHAR2(1996) ;
3052 l_description           VARCHAR2(2000) ;
3053 l_log_module            VARCHAR2(240)  ;
3054 BEGIN
3055 IF g_log_enabled THEN
3056       l_log_module := C_DEFAULT_MODULE||'.Description_29';
3057 END IF;
3058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3059       trace
3060          (p_msg      => 'BEGIN of Description_29'
3061          ,p_level    => C_LEVEL_PROCEDURE
3062          ,p_module   => l_log_module);
3063 END IF;
3064 
3065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3066 l_component_type        := 'AMB_DESCRIPTION';
3067 l_component_code        := 'FA_CIP_RECLASS_COST';
3068 l_component_type_code   := 'S';
3069 l_component_appl_id     :=  140;
3070 l_amb_context_code      := 'DEFAULT';
3071 l_source                := NULL;
3072 l_description           := NULL;
3073 
3074 
3075  
3076  IF 
3077 l_ledger_language = 'US' THEN
3078     l_description :=  SUBSTR(CONCAT(l_description,'CIP Category Reclass Cost'),1,2000);
3079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3080  END IF;  
3081  IF 
3082 l_ledger_language = 'US' THEN
3083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3085  END IF;   
3086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3088   IF l_source IS NOT NULL THEN
3089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3091   END IF; 
3092  l_description := SUBSTR(l_description,1,1996);
3093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3094         trace
3095            (p_msg      => 'END of Description_29'
3096            ,p_level    => C_LEVEL_PROCEDURE
3097            ,p_module   => l_log_module);
3098 
3099   END IF;
3100   RETURN l_description;
3101 
3102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3103       trace
3104          (p_msg      => 'END of Description_29'
3105          ,p_level    => C_LEVEL_PROCEDURE
3109 EXCEPTION
3106          ,p_module   => l_log_module);
3107 END IF;
3108 RETURN NULL;
3110   WHEN VALUE_ERROR THEN
3111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3112             trace
3113                (p_msg      => 'ERROR: '||sqlerrm
3114                ,p_level    => C_LEVEL_EXCEPTION
3115                ,p_module   => l_log_module);
3116      END IF;
3117      RAISE;
3118  WHEN xla_exceptions_pkg.application_exception THEN
3119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3120       trace
3121          (p_msg      => 'ERROR: '||sqlerrm
3122          ,p_level    => C_LEVEL_EXCEPTION
3123          ,p_module   => l_log_module);
3124       END IF;
3125       RAISE;
3126  WHEN OTHERS THEN
3127        xla_exceptions_pkg.raise_message
3128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_29');
3129 END Description_29;
3130 
3131 ---------------------------------------
3132 --
3133 -- PRIVATE FUNCTION
3134 --         Description_30
3135 --
3136 ---------------------------------------
3137 FUNCTION Description_30 (
3138   p_application_id      IN NUMBER
3139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3140 --Period Close Date
3141  , p_source_1            IN DATE
3142 )
3143 RETURN VARCHAR2
3144 IS
3145 l_component_type        VARCHAR2(80)   ;
3146 l_component_code        VARCHAR2(30)   ;
3147 l_component_type_code   VARCHAR2(1)    ;
3148 l_component_appl_id     INTEGER        ;
3149 l_amb_context_code      VARCHAR2(30)   ;
3150 l_ledger_language       VARCHAR2(30)   ;
3151 l_source                VARCHAR2(1996) ;
3152 l_description           VARCHAR2(2000) ;
3153 l_log_module            VARCHAR2(240)  ;
3154 BEGIN
3155 IF g_log_enabled THEN
3156       l_log_module := C_DEFAULT_MODULE||'.Description_30';
3157 END IF;
3158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3159       trace
3160          (p_msg      => 'BEGIN of Description_30'
3161          ,p_level    => C_LEVEL_PROCEDURE
3162          ,p_module   => l_log_module);
3163 END IF;
3164 
3165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3166 l_component_type        := 'AMB_DESCRIPTION';
3167 l_component_code        := 'FA_CIP_RECLASS_REVAL_RESERVE';
3168 l_component_type_code   := 'S';
3169 l_component_appl_id     :=  140;
3170 l_amb_context_code      := 'DEFAULT';
3171 l_source                := NULL;
3172 l_description           := NULL;
3173 
3174 
3175  
3176  IF 
3177 l_ledger_language = 'US' THEN
3178     l_description :=  SUBSTR(CONCAT(l_description,'CIP Category Reclass Revaluation Reserve'),1,2000);
3179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3180  END IF;  
3181  IF 
3182 l_ledger_language = 'US' THEN
3183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3185  END IF;   
3186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3188   IF l_source IS NOT NULL THEN
3189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3191   END IF; 
3192  l_description := SUBSTR(l_description,1,1996);
3193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3194         trace
3195            (p_msg      => 'END of Description_30'
3196            ,p_level    => C_LEVEL_PROCEDURE
3197            ,p_module   => l_log_module);
3198 
3199   END IF;
3200   RETURN l_description;
3201 
3202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3203       trace
3204          (p_msg      => 'END of Description_30'
3205          ,p_level    => C_LEVEL_PROCEDURE
3206          ,p_module   => l_log_module);
3207 END IF;
3208 RETURN NULL;
3209 EXCEPTION
3210   WHEN VALUE_ERROR THEN
3211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3212             trace
3213                (p_msg      => 'ERROR: '||sqlerrm
3214                ,p_level    => C_LEVEL_EXCEPTION
3215                ,p_module   => l_log_module);
3216      END IF;
3217      RAISE;
3218  WHEN xla_exceptions_pkg.application_exception THEN
3219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3220       trace
3221          (p_msg      => 'ERROR: '||sqlerrm
3222          ,p_level    => C_LEVEL_EXCEPTION
3223          ,p_module   => l_log_module);
3224       END IF;
3225       RAISE;
3226  WHEN OTHERS THEN
3227        xla_exceptions_pkg.raise_message
3228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_30');
3229 END Description_30;
3230 
3231 ---------------------------------------
3232 --
3233 -- PRIVATE FUNCTION
3234 --         Description_31
3235 --
3236 ---------------------------------------
3237 FUNCTION Description_31 (
3238   p_application_id      IN NUMBER
3239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3240 --Period Close Date
3241  , p_source_1            IN DATE
3242 )
3243 RETURN VARCHAR2
3244 IS
3245 l_component_type        VARCHAR2(80)   ;
3246 l_component_code        VARCHAR2(30)   ;
3247 l_component_type_code   VARCHAR2(1)    ;
3248 l_component_appl_id     INTEGER        ;
3249 l_amb_context_code      VARCHAR2(30)   ;
3250 l_ledger_language       VARCHAR2(30)   ;
3251 l_source                VARCHAR2(1996) ;
3252 l_description           VARCHAR2(2000) ;
3253 l_log_module            VARCHAR2(240)  ;
3254 BEGIN
3255 IF g_log_enabled THEN
3256       l_log_module := C_DEFAULT_MODULE||'.Description_31';
3257 END IF;
3258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3259       trace
3260          (p_msg      => 'BEGIN of Description_31'
3261          ,p_level    => C_LEVEL_PROCEDURE
3265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3262          ,p_module   => l_log_module);
3263 END IF;
3264 
3266 l_component_type        := 'AMB_DESCRIPTION';
3267 l_component_code        := 'FA_CIP_REINSTATEMENT';
3268 l_component_type_code   := 'S';
3269 l_component_appl_id     :=  140;
3270 l_amb_context_code      := 'DEFAULT';
3271 l_source                := NULL;
3272 l_description           := NULL;
3273 
3274 
3275  
3276  IF 
3277 l_ledger_language = 'US' THEN
3278     l_description :=  SUBSTR(CONCAT(l_description,'CIP Reinstatement'),1,2000);
3279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3280  END IF;  
3281  IF 
3282 l_ledger_language = 'US' THEN
3283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3285  END IF;   
3286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3288   IF l_source IS NOT NULL THEN
3289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3291   END IF; 
3292  l_description := SUBSTR(l_description,1,1996);
3293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3294         trace
3295            (p_msg      => 'END of Description_31'
3296            ,p_level    => C_LEVEL_PROCEDURE
3297            ,p_module   => l_log_module);
3298 
3299   END IF;
3300   RETURN l_description;
3301 
3302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3303       trace
3304          (p_msg      => 'END of Description_31'
3305          ,p_level    => C_LEVEL_PROCEDURE
3306          ,p_module   => l_log_module);
3307 END IF;
3308 RETURN NULL;
3309 EXCEPTION
3310   WHEN VALUE_ERROR THEN
3311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3312             trace
3313                (p_msg      => 'ERROR: '||sqlerrm
3314                ,p_level    => C_LEVEL_EXCEPTION
3315                ,p_module   => l_log_module);
3316      END IF;
3317      RAISE;
3318  WHEN xla_exceptions_pkg.application_exception THEN
3319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3320       trace
3321          (p_msg      => 'ERROR: '||sqlerrm
3322          ,p_level    => C_LEVEL_EXCEPTION
3323          ,p_module   => l_log_module);
3324       END IF;
3325       RAISE;
3326  WHEN OTHERS THEN
3327        xla_exceptions_pkg.raise_message
3328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_31');
3329 END Description_31;
3330 
3331 ---------------------------------------
3332 --
3333 -- PRIVATE FUNCTION
3334 --         Description_32
3335 --
3336 ---------------------------------------
3337 FUNCTION Description_32 (
3338   p_application_id      IN NUMBER
3339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3340 --Period Close Date
3341  , p_source_1            IN DATE
3342 )
3343 RETURN VARCHAR2
3344 IS
3345 l_component_type        VARCHAR2(80)   ;
3346 l_component_code        VARCHAR2(30)   ;
3347 l_component_type_code   VARCHAR2(1)    ;
3348 l_component_appl_id     INTEGER        ;
3349 l_amb_context_code      VARCHAR2(30)   ;
3350 l_ledger_language       VARCHAR2(30)   ;
3351 l_source                VARCHAR2(1996) ;
3352 l_description           VARCHAR2(2000) ;
3353 l_log_module            VARCHAR2(240)  ;
3354 BEGIN
3355 IF g_log_enabled THEN
3356       l_log_module := C_DEFAULT_MODULE||'.Description_32';
3357 END IF;
3358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3359       trace
3360          (p_msg      => 'BEGIN of Description_32'
3361          ,p_level    => C_LEVEL_PROCEDURE
3362          ,p_module   => l_log_module);
3363 END IF;
3364 
3365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3366 l_component_type        := 'AMB_DESCRIPTION';
3367 l_component_code        := 'FA_CIP_RETIREMENT';
3368 l_component_type_code   := 'S';
3369 l_component_appl_id     :=  140;
3370 l_amb_context_code      := 'DEFAULT';
3371 l_source                := NULL;
3372 l_description           := NULL;
3373 
3374 
3375  
3376  IF 
3377 l_ledger_language = 'US' THEN
3378     l_description :=  SUBSTR(CONCAT(l_description,'CIP Retirement'),1,2000);
3379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3380  END IF;  
3381  IF 
3382 l_ledger_language = 'US' THEN
3383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3385  END IF;   
3386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3388   IF l_source IS NOT NULL THEN
3389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3391   END IF; 
3392  l_description := SUBSTR(l_description,1,1996);
3393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3394         trace
3395            (p_msg      => 'END of Description_32'
3396            ,p_level    => C_LEVEL_PROCEDURE
3397            ,p_module   => l_log_module);
3398 
3399   END IF;
3400   RETURN l_description;
3401 
3402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3403       trace
3404          (p_msg      => 'END of Description_32'
3405          ,p_level    => C_LEVEL_PROCEDURE
3406          ,p_module   => l_log_module);
3407 END IF;
3408 RETURN NULL;
3409 EXCEPTION
3410   WHEN VALUE_ERROR THEN
3411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3412             trace
3413                (p_msg      => 'ERROR: '||sqlerrm
3414                ,p_level    => C_LEVEL_EXCEPTION
3418  WHEN xla_exceptions_pkg.application_exception THEN
3415                ,p_module   => l_log_module);
3416      END IF;
3417      RAISE;
3419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3420       trace
3421          (p_msg      => 'ERROR: '||sqlerrm
3422          ,p_level    => C_LEVEL_EXCEPTION
3423          ,p_module   => l_log_module);
3424       END IF;
3425       RAISE;
3426  WHEN OTHERS THEN
3427        xla_exceptions_pkg.raise_message
3428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_32');
3429 END Description_32;
3430 
3431 ---------------------------------------
3432 --
3433 -- PRIVATE FUNCTION
3434 --         Description_33
3435 --
3436 ---------------------------------------
3437 FUNCTION Description_33 (
3438   p_application_id      IN NUMBER
3439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3440 --Period Close Date
3441  , p_source_1            IN DATE
3442 )
3443 RETURN VARCHAR2
3444 IS
3445 l_component_type        VARCHAR2(80)   ;
3446 l_component_code        VARCHAR2(30)   ;
3447 l_component_type_code   VARCHAR2(1)    ;
3448 l_component_appl_id     INTEGER        ;
3449 l_amb_context_code      VARCHAR2(30)   ;
3450 l_ledger_language       VARCHAR2(30)   ;
3451 l_source                VARCHAR2(1996) ;
3452 l_description           VARCHAR2(2000) ;
3453 l_log_module            VARCHAR2(240)  ;
3454 BEGIN
3455 IF g_log_enabled THEN
3456       l_log_module := C_DEFAULT_MODULE||'.Description_33';
3457 END IF;
3458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3459       trace
3460          (p_msg      => 'BEGIN of Description_33'
3461          ,p_level    => C_LEVEL_PROCEDURE
3462          ,p_module   => l_log_module);
3463 END IF;
3464 
3465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3466 l_component_type        := 'AMB_DESCRIPTION';
3467 l_component_code        := 'FA_CIP_RETIREMENT_COST';
3468 l_component_type_code   := 'S';
3469 l_component_appl_id     :=  140;
3470 l_amb_context_code      := 'DEFAULT';
3471 l_source                := NULL;
3472 l_description           := NULL;
3473 
3474 
3475  
3476  IF 
3477 l_ledger_language = 'US' THEN
3478     l_description :=  SUBSTR(CONCAT(l_description,'CIP Retirement Cost'),1,2000);
3479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3480  END IF;  
3481  IF 
3482 l_ledger_language = 'US' THEN
3483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3485  END IF;   
3486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3488   IF l_source IS NOT NULL THEN
3489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3491   END IF; 
3492  l_description := SUBSTR(l_description,1,1996);
3493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3494         trace
3495            (p_msg      => 'END of Description_33'
3496            ,p_level    => C_LEVEL_PROCEDURE
3497            ,p_module   => l_log_module);
3498 
3499   END IF;
3500   RETURN l_description;
3501 
3502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3503       trace
3504          (p_msg      => 'END of Description_33'
3505          ,p_level    => C_LEVEL_PROCEDURE
3506          ,p_module   => l_log_module);
3507 END IF;
3508 RETURN NULL;
3509 EXCEPTION
3510   WHEN VALUE_ERROR THEN
3511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3512             trace
3513                (p_msg      => 'ERROR: '||sqlerrm
3514                ,p_level    => C_LEVEL_EXCEPTION
3515                ,p_module   => l_log_module);
3516      END IF;
3517      RAISE;
3518  WHEN xla_exceptions_pkg.application_exception THEN
3519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3520       trace
3521          (p_msg      => 'ERROR: '||sqlerrm
3522          ,p_level    => C_LEVEL_EXCEPTION
3523          ,p_module   => l_log_module);
3524       END IF;
3525       RAISE;
3526  WHEN OTHERS THEN
3527        xla_exceptions_pkg.raise_message
3528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_33');
3529 END Description_33;
3530 
3531 ---------------------------------------
3532 --
3533 -- PRIVATE FUNCTION
3534 --         Description_34
3535 --
3536 ---------------------------------------
3537 FUNCTION Description_34 (
3538   p_application_id      IN NUMBER
3539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3540 --Period Close Date
3541  , p_source_1            IN DATE
3542 )
3543 RETURN VARCHAR2
3544 IS
3545 l_component_type        VARCHAR2(80)   ;
3546 l_component_code        VARCHAR2(30)   ;
3547 l_component_type_code   VARCHAR2(1)    ;
3548 l_component_appl_id     INTEGER        ;
3549 l_amb_context_code      VARCHAR2(30)   ;
3550 l_ledger_language       VARCHAR2(30)   ;
3551 l_source                VARCHAR2(1996) ;
3552 l_description           VARCHAR2(2000) ;
3553 l_log_module            VARCHAR2(240)  ;
3554 BEGIN
3555 IF g_log_enabled THEN
3556       l_log_module := C_DEFAULT_MODULE||'.Description_34';
3557 END IF;
3558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3559       trace
3560          (p_msg      => 'BEGIN of Description_34'
3561          ,p_level    => C_LEVEL_PROCEDURE
3562          ,p_module   => l_log_module);
3563 END IF;
3564 
3565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3566 l_component_type        := 'AMB_DESCRIPTION';
3567 l_component_code        := 'FA_CIP_RETIREMENT_NBV_RETIRED';
3568 l_component_type_code   := 'S';
3569 l_component_appl_id     :=  140;
3573 
3570 l_amb_context_code      := 'DEFAULT';
3571 l_source                := NULL;
3572 l_description           := NULL;
3574 
3575  
3576  IF 
3577 l_ledger_language = 'US' THEN
3578     l_description :=  SUBSTR(CONCAT(l_description,'CIP Retirement NBV Retired'),1,2000);
3579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3580  END IF;  
3581  IF 
3582 l_ledger_language = 'US' THEN
3583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3585  END IF;   
3586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3588   IF l_source IS NOT NULL THEN
3589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3591   END IF; 
3592  l_description := SUBSTR(l_description,1,1996);
3593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3594         trace
3595            (p_msg      => 'END of Description_34'
3596            ,p_level    => C_LEVEL_PROCEDURE
3597            ,p_module   => l_log_module);
3598 
3599   END IF;
3600   RETURN l_description;
3601 
3602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3603       trace
3604          (p_msg      => 'END of Description_34'
3605          ,p_level    => C_LEVEL_PROCEDURE
3606          ,p_module   => l_log_module);
3607 END IF;
3608 RETURN NULL;
3609 EXCEPTION
3610   WHEN VALUE_ERROR THEN
3611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3612             trace
3613                (p_msg      => 'ERROR: '||sqlerrm
3614                ,p_level    => C_LEVEL_EXCEPTION
3615                ,p_module   => l_log_module);
3616      END IF;
3617      RAISE;
3618  WHEN xla_exceptions_pkg.application_exception THEN
3619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3620       trace
3621          (p_msg      => 'ERROR: '||sqlerrm
3622          ,p_level    => C_LEVEL_EXCEPTION
3623          ,p_module   => l_log_module);
3624       END IF;
3625       RAISE;
3626  WHEN OTHERS THEN
3627        xla_exceptions_pkg.raise_message
3628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_34');
3629 END Description_34;
3630 
3631 ---------------------------------------
3632 --
3633 -- PRIVATE FUNCTION
3634 --         Description_35
3635 --
3636 ---------------------------------------
3637 FUNCTION Description_35 (
3638   p_application_id      IN NUMBER
3639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3640 --Period Close Date
3641  , p_source_1            IN DATE
3642 )
3643 RETURN VARCHAR2
3644 IS
3645 l_component_type        VARCHAR2(80)   ;
3646 l_component_code        VARCHAR2(30)   ;
3647 l_component_type_code   VARCHAR2(1)    ;
3648 l_component_appl_id     INTEGER        ;
3649 l_amb_context_code      VARCHAR2(30)   ;
3650 l_ledger_language       VARCHAR2(30)   ;
3651 l_source                VARCHAR2(1996) ;
3652 l_description           VARCHAR2(2000) ;
3653 l_log_module            VARCHAR2(240)  ;
3654 BEGIN
3655 IF g_log_enabled THEN
3656       l_log_module := C_DEFAULT_MODULE||'.Description_35';
3657 END IF;
3658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3659       trace
3660          (p_msg      => 'BEGIN of Description_35'
3661          ,p_level    => C_LEVEL_PROCEDURE
3662          ,p_module   => l_log_module);
3663 END IF;
3664 
3665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3666 l_component_type        := 'AMB_DESCRIPTION';
3667 l_component_code        := 'FA_CIP_RETIREMENT_PROC_OF_SALE';
3668 l_component_type_code   := 'S';
3669 l_component_appl_id     :=  140;
3670 l_amb_context_code      := 'DEFAULT';
3671 l_source                := NULL;
3672 l_description           := NULL;
3673 
3674 
3675  
3676  IF 
3677 l_ledger_language = 'US' THEN
3678     l_description :=  SUBSTR(CONCAT(l_description,'CIP Retirement Proceeds of Sale'),1,2000);
3679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3680  END IF;  
3681  IF 
3682 l_ledger_language = 'US' THEN
3683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3685  END IF;   
3686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3688   IF l_source IS NOT NULL THEN
3689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3691   END IF; 
3692  l_description := SUBSTR(l_description,1,1996);
3693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3694         trace
3695            (p_msg      => 'END of Description_35'
3696            ,p_level    => C_LEVEL_PROCEDURE
3697            ,p_module   => l_log_module);
3698 
3699   END IF;
3700   RETURN l_description;
3701 
3702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3703       trace
3704          (p_msg      => 'END of Description_35'
3705          ,p_level    => C_LEVEL_PROCEDURE
3706          ,p_module   => l_log_module);
3707 END IF;
3708 RETURN NULL;
3709 EXCEPTION
3710   WHEN VALUE_ERROR THEN
3711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3712             trace
3713                (p_msg      => 'ERROR: '||sqlerrm
3714                ,p_level    => C_LEVEL_EXCEPTION
3715                ,p_module   => l_log_module);
3716      END IF;
3717      RAISE;
3718  WHEN xla_exceptions_pkg.application_exception THEN
3719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3720       trace
3721          (p_msg      => 'ERROR: '||sqlerrm
3722          ,p_level    => C_LEVEL_EXCEPTION
3726  WHEN OTHERS THEN
3723          ,p_module   => l_log_module);
3724       END IF;
3725       RAISE;
3727        xla_exceptions_pkg.raise_message
3728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_35');
3729 END Description_35;
3730 
3731 ---------------------------------------
3732 --
3733 -- PRIVATE FUNCTION
3734 --         Description_36
3735 --
3736 ---------------------------------------
3737 FUNCTION Description_36 (
3738   p_application_id      IN NUMBER
3739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3740 --Period Close Date
3741  , p_source_1            IN DATE
3742 )
3743 RETURN VARCHAR2
3744 IS
3745 l_component_type        VARCHAR2(80)   ;
3746 l_component_code        VARCHAR2(30)   ;
3747 l_component_type_code   VARCHAR2(1)    ;
3748 l_component_appl_id     INTEGER        ;
3749 l_amb_context_code      VARCHAR2(30)   ;
3750 l_ledger_language       VARCHAR2(30)   ;
3751 l_source                VARCHAR2(1996) ;
3752 l_description           VARCHAR2(2000) ;
3753 l_log_module            VARCHAR2(240)  ;
3754 BEGIN
3755 IF g_log_enabled THEN
3756       l_log_module := C_DEFAULT_MODULE||'.Description_36';
3757 END IF;
3758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3759       trace
3760          (p_msg      => 'BEGIN of Description_36'
3761          ,p_level    => C_LEVEL_PROCEDURE
3762          ,p_module   => l_log_module);
3763 END IF;
3764 
3765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3766 l_component_type        := 'AMB_DESCRIPTION';
3767 l_component_code        := 'FA_CIP_RET_COST_OF_REMOVAL';
3768 l_component_type_code   := 'S';
3769 l_component_appl_id     :=  140;
3770 l_amb_context_code      := 'DEFAULT';
3771 l_source                := NULL;
3772 l_description           := NULL;
3773 
3774 
3775  
3776  IF 
3777 l_ledger_language = 'US' THEN
3778     l_description :=  SUBSTR(CONCAT(l_description,'CIP Retirement Cost of Removal'),1,2000);
3779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3780  END IF;  
3781  IF 
3782 l_ledger_language = 'US' THEN
3783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3785  END IF;   
3786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3788   IF l_source IS NOT NULL THEN
3789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3791   END IF; 
3792  l_description := SUBSTR(l_description,1,1996);
3793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3794         trace
3795            (p_msg      => 'END of Description_36'
3796            ,p_level    => C_LEVEL_PROCEDURE
3797            ,p_module   => l_log_module);
3798 
3799   END IF;
3800   RETURN l_description;
3801 
3802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3803       trace
3804          (p_msg      => 'END of Description_36'
3805          ,p_level    => C_LEVEL_PROCEDURE
3806          ,p_module   => l_log_module);
3807 END IF;
3808 RETURN NULL;
3809 EXCEPTION
3810   WHEN VALUE_ERROR THEN
3811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3812             trace
3813                (p_msg      => 'ERROR: '||sqlerrm
3814                ,p_level    => C_LEVEL_EXCEPTION
3815                ,p_module   => l_log_module);
3816      END IF;
3817      RAISE;
3818  WHEN xla_exceptions_pkg.application_exception THEN
3819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3820       trace
3821          (p_msg      => 'ERROR: '||sqlerrm
3822          ,p_level    => C_LEVEL_EXCEPTION
3823          ,p_module   => l_log_module);
3824       END IF;
3825       RAISE;
3826  WHEN OTHERS THEN
3827        xla_exceptions_pkg.raise_message
3828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_36');
3829 END Description_36;
3830 
3831 ---------------------------------------
3832 --
3833 -- PRIVATE FUNCTION
3834 --         Description_37
3835 --
3836 ---------------------------------------
3837 FUNCTION Description_37 (
3838   p_application_id      IN NUMBER
3839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3840 --Period Close Date
3841  , p_source_1            IN DATE
3842 )
3843 RETURN VARCHAR2
3844 IS
3845 l_component_type        VARCHAR2(80)   ;
3846 l_component_code        VARCHAR2(30)   ;
3847 l_component_type_code   VARCHAR2(1)    ;
3848 l_component_appl_id     INTEGER        ;
3849 l_amb_context_code      VARCHAR2(30)   ;
3850 l_ledger_language       VARCHAR2(30)   ;
3851 l_source                VARCHAR2(1996) ;
3852 l_description           VARCHAR2(2000) ;
3853 l_log_module            VARCHAR2(240)  ;
3854 BEGIN
3855 IF g_log_enabled THEN
3856       l_log_module := C_DEFAULT_MODULE||'.Description_37';
3857 END IF;
3858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3859       trace
3860          (p_msg      => 'BEGIN of Description_37'
3861          ,p_level    => C_LEVEL_PROCEDURE
3862          ,p_module   => l_log_module);
3863 END IF;
3864 
3865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3866 l_component_type        := 'AMB_DESCRIPTION';
3867 l_component_code        := 'FA_CIP_RET_COST_OF_REMOVAL_CLR';
3868 l_component_type_code   := 'S';
3869 l_component_appl_id     :=  140;
3870 l_amb_context_code      := 'DEFAULT';
3871 l_source                := NULL;
3872 l_description           := NULL;
3873 
3874 
3875  
3876  IF 
3877 l_ledger_language = 'US' THEN
3878     l_description :=  SUBSTR(CONCAT(l_description,'CIP Retirement Cost of Removal Clearing'),1,2000);
3882 l_ledger_language = 'US' THEN
3879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3880  END IF;  
3881  IF 
3883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3885  END IF;   
3886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3888   IF l_source IS NOT NULL THEN
3889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3891   END IF; 
3892  l_description := SUBSTR(l_description,1,1996);
3893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3894         trace
3895            (p_msg      => 'END of Description_37'
3896            ,p_level    => C_LEVEL_PROCEDURE
3897            ,p_module   => l_log_module);
3898 
3899   END IF;
3900   RETURN l_description;
3901 
3902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3903       trace
3904          (p_msg      => 'END of Description_37'
3905          ,p_level    => C_LEVEL_PROCEDURE
3906          ,p_module   => l_log_module);
3907 END IF;
3908 RETURN NULL;
3909 EXCEPTION
3910   WHEN VALUE_ERROR THEN
3911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3912             trace
3913                (p_msg      => 'ERROR: '||sqlerrm
3914                ,p_level    => C_LEVEL_EXCEPTION
3915                ,p_module   => l_log_module);
3916      END IF;
3917      RAISE;
3918  WHEN xla_exceptions_pkg.application_exception THEN
3919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3920       trace
3921          (p_msg      => 'ERROR: '||sqlerrm
3922          ,p_level    => C_LEVEL_EXCEPTION
3923          ,p_module   => l_log_module);
3924       END IF;
3925       RAISE;
3926  WHEN OTHERS THEN
3927        xla_exceptions_pkg.raise_message
3928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_37');
3929 END Description_37;
3930 
3931 ---------------------------------------
3932 --
3933 -- PRIVATE FUNCTION
3934 --         Description_38
3935 --
3936 ---------------------------------------
3937 FUNCTION Description_38 (
3938   p_application_id      IN NUMBER
3939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
3940 --Period Close Date
3941  , p_source_1            IN DATE
3942 )
3943 RETURN VARCHAR2
3944 IS
3945 l_component_type        VARCHAR2(80)   ;
3946 l_component_code        VARCHAR2(30)   ;
3947 l_component_type_code   VARCHAR2(1)    ;
3948 l_component_appl_id     INTEGER        ;
3949 l_amb_context_code      VARCHAR2(30)   ;
3950 l_ledger_language       VARCHAR2(30)   ;
3951 l_source                VARCHAR2(1996) ;
3952 l_description           VARCHAR2(2000) ;
3953 l_log_module            VARCHAR2(240)  ;
3954 BEGIN
3955 IF g_log_enabled THEN
3956       l_log_module := C_DEFAULT_MODULE||'.Description_38';
3957 END IF;
3958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3959       trace
3960          (p_msg      => 'BEGIN of Description_38'
3961          ,p_level    => C_LEVEL_PROCEDURE
3962          ,p_module   => l_log_module);
3963 END IF;
3964 
3965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
3966 l_component_type        := 'AMB_DESCRIPTION';
3967 l_component_code        := 'FA_CIP_RET_PROC_OF_SALE_CLEAR';
3968 l_component_type_code   := 'S';
3969 l_component_appl_id     :=  140;
3970 l_amb_context_code      := 'DEFAULT';
3971 l_source                := NULL;
3972 l_description           := NULL;
3973 
3974 
3975  
3976  IF 
3977 l_ledger_language = 'US' THEN
3978     l_description :=  SUBSTR(CONCAT(l_description,'CIP Retirement Proceeds of Sale Clearing'),1,2000);
3979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3980  END IF;  
3981  IF 
3982 l_ledger_language = 'US' THEN
3983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
3984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
3985  END IF;   
3986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
3987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
3988   IF l_source IS NOT NULL THEN
3989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
3990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
3991   END IF; 
3992  l_description := SUBSTR(l_description,1,1996);
3993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3994         trace
3995            (p_msg      => 'END of Description_38'
3996            ,p_level    => C_LEVEL_PROCEDURE
3997            ,p_module   => l_log_module);
3998 
3999   END IF;
4000   RETURN l_description;
4001 
4002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4003       trace
4004          (p_msg      => 'END of Description_38'
4005          ,p_level    => C_LEVEL_PROCEDURE
4006          ,p_module   => l_log_module);
4007 END IF;
4008 RETURN NULL;
4009 EXCEPTION
4010   WHEN VALUE_ERROR THEN
4011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4012             trace
4013                (p_msg      => 'ERROR: '||sqlerrm
4014                ,p_level    => C_LEVEL_EXCEPTION
4015                ,p_module   => l_log_module);
4016      END IF;
4017      RAISE;
4018  WHEN xla_exceptions_pkg.application_exception THEN
4019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4020       trace
4021          (p_msg      => 'ERROR: '||sqlerrm
4022          ,p_level    => C_LEVEL_EXCEPTION
4023          ,p_module   => l_log_module);
4024       END IF;
4025       RAISE;
4026  WHEN OTHERS THEN
4027        xla_exceptions_pkg.raise_message
4028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_38');
4029 END Description_38;
4030 
4034 --         Description_39
4031 ---------------------------------------
4032 --
4033 -- PRIVATE FUNCTION
4035 --
4036 ---------------------------------------
4037 FUNCTION Description_39 (
4038   p_application_id      IN NUMBER
4039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4040 --Period Close Date
4041  , p_source_1            IN DATE
4042 )
4043 RETURN VARCHAR2
4044 IS
4045 l_component_type        VARCHAR2(80)   ;
4046 l_component_code        VARCHAR2(30)   ;
4047 l_component_type_code   VARCHAR2(1)    ;
4048 l_component_appl_id     INTEGER        ;
4049 l_amb_context_code      VARCHAR2(30)   ;
4050 l_ledger_language       VARCHAR2(30)   ;
4051 l_source                VARCHAR2(1996) ;
4052 l_description           VARCHAR2(2000) ;
4053 l_log_module            VARCHAR2(240)  ;
4054 BEGIN
4055 IF g_log_enabled THEN
4056       l_log_module := C_DEFAULT_MODULE||'.Description_39';
4057 END IF;
4058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4059       trace
4060          (p_msg      => 'BEGIN of Description_39'
4061          ,p_level    => C_LEVEL_PROCEDURE
4062          ,p_module   => l_log_module);
4063 END IF;
4064 
4065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4066 l_component_type        := 'AMB_DESCRIPTION';
4067 l_component_code        := 'FA_CIP_RET_REVAL_RESERVE';
4068 l_component_type_code   := 'S';
4069 l_component_appl_id     :=  140;
4070 l_amb_context_code      := 'DEFAULT';
4071 l_source                := NULL;
4072 l_description           := NULL;
4073 
4074 
4075  
4076  IF 
4077 l_ledger_language = 'US' THEN
4078     l_description :=  SUBSTR(CONCAT(l_description,'CIP Retirement Revaluation Reserve'),1,2000);
4079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4080  END IF;  
4081  IF 
4082 l_ledger_language = 'US' THEN
4083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4085  END IF;   
4086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4088   IF l_source IS NOT NULL THEN
4089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4091   END IF; 
4092  l_description := SUBSTR(l_description,1,1996);
4093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4094         trace
4095            (p_msg      => 'END of Description_39'
4096            ,p_level    => C_LEVEL_PROCEDURE
4097            ,p_module   => l_log_module);
4098 
4099   END IF;
4100   RETURN l_description;
4101 
4102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4103       trace
4104          (p_msg      => 'END of Description_39'
4105          ,p_level    => C_LEVEL_PROCEDURE
4106          ,p_module   => l_log_module);
4107 END IF;
4108 RETURN NULL;
4109 EXCEPTION
4110   WHEN VALUE_ERROR THEN
4111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4112             trace
4113                (p_msg      => 'ERROR: '||sqlerrm
4114                ,p_level    => C_LEVEL_EXCEPTION
4115                ,p_module   => l_log_module);
4116      END IF;
4117      RAISE;
4118  WHEN xla_exceptions_pkg.application_exception THEN
4119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4120       trace
4121          (p_msg      => 'ERROR: '||sqlerrm
4122          ,p_level    => C_LEVEL_EXCEPTION
4123          ,p_module   => l_log_module);
4124       END IF;
4125       RAISE;
4126  WHEN OTHERS THEN
4127        xla_exceptions_pkg.raise_message
4128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_39');
4129 END Description_39;
4130 
4131 ---------------------------------------
4132 --
4133 -- PRIVATE FUNCTION
4134 --         Description_40
4135 --
4136 ---------------------------------------
4137 FUNCTION Description_40 (
4138   p_application_id      IN NUMBER
4139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4140 --Period Close Date
4141  , p_source_1            IN DATE
4142 )
4143 RETURN VARCHAR2
4144 IS
4145 l_component_type        VARCHAR2(80)   ;
4146 l_component_code        VARCHAR2(30)   ;
4147 l_component_type_code   VARCHAR2(1)    ;
4148 l_component_appl_id     INTEGER        ;
4149 l_amb_context_code      VARCHAR2(30)   ;
4150 l_ledger_language       VARCHAR2(30)   ;
4151 l_source                VARCHAR2(1996) ;
4152 l_description           VARCHAR2(2000) ;
4153 l_log_module            VARCHAR2(240)  ;
4154 BEGIN
4155 IF g_log_enabled THEN
4156       l_log_module := C_DEFAULT_MODULE||'.Description_40';
4157 END IF;
4158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4159       trace
4160          (p_msg      => 'BEGIN of Description_40'
4161          ,p_level    => C_LEVEL_PROCEDURE
4162          ,p_module   => l_log_module);
4163 END IF;
4164 
4165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4166 l_component_type        := 'AMB_DESCRIPTION';
4167 l_component_code        := 'FA_CIP_RET_REVAL_RES_RETIRED';
4168 l_component_type_code   := 'S';
4169 l_component_appl_id     :=  140;
4170 l_amb_context_code      := 'DEFAULT';
4171 l_source                := NULL;
4172 l_description           := NULL;
4173 
4174 
4175  
4176  IF 
4177 l_ledger_language = 'US' THEN
4178     l_description :=  SUBSTR(CONCAT(l_description,'CIP Retirement Revaluation Reserve Retired'),1,2000);
4179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4180  END IF;  
4181  IF 
4182 l_ledger_language = 'US' THEN
4183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4185  END IF;   
4189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4188   IF l_source IS NOT NULL THEN
4190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4191   END IF; 
4192  l_description := SUBSTR(l_description,1,1996);
4193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4194         trace
4195            (p_msg      => 'END of Description_40'
4196            ,p_level    => C_LEVEL_PROCEDURE
4197            ,p_module   => l_log_module);
4198 
4199   END IF;
4200   RETURN l_description;
4201 
4202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4203       trace
4204          (p_msg      => 'END of Description_40'
4205          ,p_level    => C_LEVEL_PROCEDURE
4206          ,p_module   => l_log_module);
4207 END IF;
4208 RETURN NULL;
4209 EXCEPTION
4210   WHEN VALUE_ERROR THEN
4211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4212             trace
4213                (p_msg      => 'ERROR: '||sqlerrm
4214                ,p_level    => C_LEVEL_EXCEPTION
4215                ,p_module   => l_log_module);
4216      END IF;
4217      RAISE;
4218  WHEN xla_exceptions_pkg.application_exception THEN
4219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4220       trace
4221          (p_msg      => 'ERROR: '||sqlerrm
4222          ,p_level    => C_LEVEL_EXCEPTION
4223          ,p_module   => l_log_module);
4224       END IF;
4225       RAISE;
4226  WHEN OTHERS THEN
4227        xla_exceptions_pkg.raise_message
4228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_40');
4229 END Description_40;
4230 
4231 ---------------------------------------
4232 --
4233 -- PRIVATE FUNCTION
4234 --         Description_41
4235 --
4236 ---------------------------------------
4237 FUNCTION Description_41 (
4238   p_application_id      IN NUMBER
4239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4240 --Period Close Date
4241  , p_source_1            IN DATE
4242 )
4243 RETURN VARCHAR2
4244 IS
4245 l_component_type        VARCHAR2(80)   ;
4246 l_component_code        VARCHAR2(30)   ;
4247 l_component_type_code   VARCHAR2(1)    ;
4248 l_component_appl_id     INTEGER        ;
4249 l_amb_context_code      VARCHAR2(30)   ;
4250 l_ledger_language       VARCHAR2(30)   ;
4251 l_source                VARCHAR2(1996) ;
4252 l_description           VARCHAR2(2000) ;
4253 l_log_module            VARCHAR2(240)  ;
4254 BEGIN
4255 IF g_log_enabled THEN
4256       l_log_module := C_DEFAULT_MODULE||'.Description_41';
4257 END IF;
4258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4259       trace
4260          (p_msg      => 'BEGIN of Description_41'
4261          ,p_level    => C_LEVEL_PROCEDURE
4262          ,p_module   => l_log_module);
4263 END IF;
4264 
4265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4266 l_component_type        := 'AMB_DESCRIPTION';
4267 l_component_code        := 'FA_CIP_REVALUATION';
4268 l_component_type_code   := 'S';
4269 l_component_appl_id     :=  140;
4270 l_amb_context_code      := 'DEFAULT';
4271 l_source                := NULL;
4272 l_description           := NULL;
4273 
4274 
4275  
4276  IF 
4277 l_ledger_language = 'US' THEN
4278     l_description :=  SUBSTR(CONCAT(l_description,'CIP Revaluation'),1,2000);
4279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4280  END IF;  
4281  IF 
4282 l_ledger_language = 'US' THEN
4283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4285  END IF;   
4286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4288   IF l_source IS NOT NULL THEN
4289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4291   END IF; 
4292  l_description := SUBSTR(l_description,1,1996);
4293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4294         trace
4295            (p_msg      => 'END of Description_41'
4296            ,p_level    => C_LEVEL_PROCEDURE
4297            ,p_module   => l_log_module);
4298 
4299   END IF;
4300   RETURN l_description;
4301 
4302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4303       trace
4304          (p_msg      => 'END of Description_41'
4305          ,p_level    => C_LEVEL_PROCEDURE
4306          ,p_module   => l_log_module);
4307 END IF;
4308 RETURN NULL;
4309 EXCEPTION
4310   WHEN VALUE_ERROR THEN
4311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4312             trace
4313                (p_msg      => 'ERROR: '||sqlerrm
4314                ,p_level    => C_LEVEL_EXCEPTION
4315                ,p_module   => l_log_module);
4316      END IF;
4317      RAISE;
4318  WHEN xla_exceptions_pkg.application_exception THEN
4319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4320       trace
4321          (p_msg      => 'ERROR: '||sqlerrm
4322          ,p_level    => C_LEVEL_EXCEPTION
4323          ,p_module   => l_log_module);
4324       END IF;
4325       RAISE;
4326  WHEN OTHERS THEN
4327        xla_exceptions_pkg.raise_message
4328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_41');
4329 END Description_41;
4330 
4331 ---------------------------------------
4332 --
4333 -- PRIVATE FUNCTION
4334 --         Description_42
4335 --
4336 ---------------------------------------
4337 FUNCTION Description_42 (
4338   p_application_id      IN NUMBER
4339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4340 --Period Close Date
4344 IS
4341  , p_source_1            IN DATE
4342 )
4343 RETURN VARCHAR2
4345 l_component_type        VARCHAR2(80)   ;
4346 l_component_code        VARCHAR2(30)   ;
4347 l_component_type_code   VARCHAR2(1)    ;
4348 l_component_appl_id     INTEGER        ;
4349 l_amb_context_code      VARCHAR2(30)   ;
4350 l_ledger_language       VARCHAR2(30)   ;
4351 l_source                VARCHAR2(1996) ;
4352 l_description           VARCHAR2(2000) ;
4353 l_log_module            VARCHAR2(240)  ;
4354 BEGIN
4355 IF g_log_enabled THEN
4356       l_log_module := C_DEFAULT_MODULE||'.Description_42';
4357 END IF;
4358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4359       trace
4360          (p_msg      => 'BEGIN of Description_42'
4361          ,p_level    => C_LEVEL_PROCEDURE
4362          ,p_module   => l_log_module);
4363 END IF;
4364 
4365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4366 l_component_type        := 'AMB_DESCRIPTION';
4367 l_component_code        := 'FA_CIP_REVAL_COST';
4368 l_component_type_code   := 'S';
4369 l_component_appl_id     :=  140;
4370 l_amb_context_code      := 'DEFAULT';
4371 l_source                := NULL;
4372 l_description           := NULL;
4373 
4374 
4375  
4376  IF 
4377 l_ledger_language = 'US' THEN
4378     l_description :=  SUBSTR(CONCAT(l_description,'CIP Revaluation Cost'),1,2000);
4379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4380  END IF;  
4381  IF 
4382 l_ledger_language = 'US' THEN
4383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4385  END IF;   
4386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4388   IF l_source IS NOT NULL THEN
4389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4391   END IF; 
4392  l_description := SUBSTR(l_description,1,1996);
4393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4394         trace
4395            (p_msg      => 'END of Description_42'
4396            ,p_level    => C_LEVEL_PROCEDURE
4397            ,p_module   => l_log_module);
4398 
4399   END IF;
4400   RETURN l_description;
4401 
4402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4403       trace
4404          (p_msg      => 'END of Description_42'
4405          ,p_level    => C_LEVEL_PROCEDURE
4406          ,p_module   => l_log_module);
4407 END IF;
4408 RETURN NULL;
4409 EXCEPTION
4410   WHEN VALUE_ERROR THEN
4411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4412             trace
4413                (p_msg      => 'ERROR: '||sqlerrm
4414                ,p_level    => C_LEVEL_EXCEPTION
4415                ,p_module   => l_log_module);
4416      END IF;
4417      RAISE;
4418  WHEN xla_exceptions_pkg.application_exception THEN
4419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4420       trace
4421          (p_msg      => 'ERROR: '||sqlerrm
4422          ,p_level    => C_LEVEL_EXCEPTION
4423          ,p_module   => l_log_module);
4424       END IF;
4425       RAISE;
4426  WHEN OTHERS THEN
4427        xla_exceptions_pkg.raise_message
4428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_42');
4429 END Description_42;
4430 
4431 ---------------------------------------
4432 --
4433 -- PRIVATE FUNCTION
4434 --         Description_43
4435 --
4436 ---------------------------------------
4437 FUNCTION Description_43 (
4438   p_application_id      IN NUMBER
4439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4440 --Period Close Date
4441  , p_source_1            IN DATE
4442 )
4443 RETURN VARCHAR2
4444 IS
4445 l_component_type        VARCHAR2(80)   ;
4446 l_component_code        VARCHAR2(30)   ;
4447 l_component_type_code   VARCHAR2(1)    ;
4448 l_component_appl_id     INTEGER        ;
4449 l_amb_context_code      VARCHAR2(30)   ;
4450 l_ledger_language       VARCHAR2(30)   ;
4451 l_source                VARCHAR2(1996) ;
4452 l_description           VARCHAR2(2000) ;
4453 l_log_module            VARCHAR2(240)  ;
4454 BEGIN
4455 IF g_log_enabled THEN
4456       l_log_module := C_DEFAULT_MODULE||'.Description_43';
4457 END IF;
4458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4459       trace
4460          (p_msg      => 'BEGIN of Description_43'
4461          ,p_level    => C_LEVEL_PROCEDURE
4462          ,p_module   => l_log_module);
4463 END IF;
4464 
4465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4466 l_component_type        := 'AMB_DESCRIPTION';
4467 l_component_code        := 'FA_CIP_REVAL_RESERVE';
4468 l_component_type_code   := 'S';
4469 l_component_appl_id     :=  140;
4470 l_amb_context_code      := 'DEFAULT';
4471 l_source                := NULL;
4472 l_description           := NULL;
4473 
4474 
4475  
4476  IF 
4477 l_ledger_language = 'US' THEN
4478     l_description :=  SUBSTR(CONCAT(l_description,'CIP Revaluation Reserve'),1,2000);
4479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4480  END IF;  
4481  IF 
4482 l_ledger_language = 'US' THEN
4483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4485  END IF;   
4486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4488   IF l_source IS NOT NULL THEN
4489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4491   END IF; 
4495            (p_msg      => 'END of Description_43'
4492  l_description := SUBSTR(l_description,1,1996);
4493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4494         trace
4496            ,p_level    => C_LEVEL_PROCEDURE
4497            ,p_module   => l_log_module);
4498 
4499   END IF;
4500   RETURN l_description;
4501 
4502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4503       trace
4504          (p_msg      => 'END of Description_43'
4505          ,p_level    => C_LEVEL_PROCEDURE
4506          ,p_module   => l_log_module);
4507 END IF;
4508 RETURN NULL;
4509 EXCEPTION
4510   WHEN VALUE_ERROR THEN
4511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4512             trace
4513                (p_msg      => 'ERROR: '||sqlerrm
4514                ,p_level    => C_LEVEL_EXCEPTION
4515                ,p_module   => l_log_module);
4516      END IF;
4517      RAISE;
4518  WHEN xla_exceptions_pkg.application_exception THEN
4519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4520       trace
4521          (p_msg      => 'ERROR: '||sqlerrm
4522          ,p_level    => C_LEVEL_EXCEPTION
4523          ,p_module   => l_log_module);
4524       END IF;
4525       RAISE;
4526  WHEN OTHERS THEN
4527        xla_exceptions_pkg.raise_message
4528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_43');
4529 END Description_43;
4530 
4531 ---------------------------------------
4532 --
4533 -- PRIVATE FUNCTION
4534 --         Description_44
4535 --
4536 ---------------------------------------
4537 FUNCTION Description_44 (
4538   p_application_id      IN NUMBER
4539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4540 --Period Close Date
4541  , p_source_1            IN DATE
4542 )
4543 RETURN VARCHAR2
4544 IS
4545 l_component_type        VARCHAR2(80)   ;
4546 l_component_code        VARCHAR2(30)   ;
4547 l_component_type_code   VARCHAR2(1)    ;
4548 l_component_appl_id     INTEGER        ;
4549 l_amb_context_code      VARCHAR2(30)   ;
4550 l_ledger_language       VARCHAR2(30)   ;
4551 l_source                VARCHAR2(1996) ;
4552 l_description           VARCHAR2(2000) ;
4553 l_log_module            VARCHAR2(240)  ;
4554 BEGIN
4555 IF g_log_enabled THEN
4556       l_log_module := C_DEFAULT_MODULE||'.Description_44';
4557 END IF;
4558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4559       trace
4560          (p_msg      => 'BEGIN of Description_44'
4561          ,p_level    => C_LEVEL_PROCEDURE
4562          ,p_module   => l_log_module);
4563 END IF;
4564 
4565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4566 l_component_type        := 'AMB_DESCRIPTION';
4567 l_component_code        := 'FA_CIP_SOURCE_LINE_TRANSFER';
4568 l_component_type_code   := 'S';
4569 l_component_appl_id     :=  140;
4570 l_amb_context_code      := 'DEFAULT';
4571 l_source                := NULL;
4572 l_description           := NULL;
4573 
4574 
4575  
4576  IF 
4577 l_ledger_language = 'US' THEN
4578     l_description :=  SUBSTR(CONCAT(l_description,'CIP Source Line Transfer'),1,2000);
4579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4580  END IF;  
4581  IF 
4582 l_ledger_language = 'US' THEN
4583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4585  END IF;   
4586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4588   IF l_source IS NOT NULL THEN
4589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4591   END IF; 
4592  l_description := SUBSTR(l_description,1,1996);
4593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4594         trace
4595            (p_msg      => 'END of Description_44'
4596            ,p_level    => C_LEVEL_PROCEDURE
4597            ,p_module   => l_log_module);
4598 
4599   END IF;
4600   RETURN l_description;
4601 
4602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4603       trace
4604          (p_msg      => 'END of Description_44'
4605          ,p_level    => C_LEVEL_PROCEDURE
4606          ,p_module   => l_log_module);
4607 END IF;
4608 RETURN NULL;
4609 EXCEPTION
4610   WHEN VALUE_ERROR THEN
4611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4612             trace
4613                (p_msg      => 'ERROR: '||sqlerrm
4614                ,p_level    => C_LEVEL_EXCEPTION
4615                ,p_module   => l_log_module);
4616      END IF;
4617      RAISE;
4618  WHEN xla_exceptions_pkg.application_exception THEN
4619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4620       trace
4621          (p_msg      => 'ERROR: '||sqlerrm
4622          ,p_level    => C_LEVEL_EXCEPTION
4623          ,p_module   => l_log_module);
4624       END IF;
4625       RAISE;
4626  WHEN OTHERS THEN
4627        xla_exceptions_pkg.raise_message
4628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_44');
4629 END Description_44;
4630 
4631 ---------------------------------------
4632 --
4633 -- PRIVATE FUNCTION
4634 --         Description_45
4635 --
4636 ---------------------------------------
4637 FUNCTION Description_45 (
4638   p_application_id      IN NUMBER
4639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4640 --Period Close Date
4641  , p_source_1            IN DATE
4642 )
4643 RETURN VARCHAR2
4644 IS
4645 l_component_type        VARCHAR2(80)   ;
4646 l_component_code        VARCHAR2(30)   ;
4647 l_component_type_code   VARCHAR2(1)    ;
4648 l_component_appl_id     INTEGER        ;
4649 l_amb_context_code      VARCHAR2(30)   ;
4653 l_log_module            VARCHAR2(240)  ;
4650 l_ledger_language       VARCHAR2(30)   ;
4651 l_source                VARCHAR2(1996) ;
4652 l_description           VARCHAR2(2000) ;
4654 BEGIN
4655 IF g_log_enabled THEN
4656       l_log_module := C_DEFAULT_MODULE||'.Description_45';
4657 END IF;
4658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4659       trace
4660          (p_msg      => 'BEGIN of Description_45'
4661          ,p_level    => C_LEVEL_PROCEDURE
4662          ,p_module   => l_log_module);
4663 END IF;
4664 
4665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4666 l_component_type        := 'AMB_DESCRIPTION';
4667 l_component_code        := 'FA_CIP_TRANSFER_COST';
4668 l_component_type_code   := 'S';
4669 l_component_appl_id     :=  140;
4670 l_amb_context_code      := 'DEFAULT';
4671 l_source                := NULL;
4672 l_description           := NULL;
4673 
4674 
4675  
4676  IF 
4677 l_ledger_language = 'US' THEN
4678     l_description :=  SUBSTR(CONCAT(l_description,'CIP Transfer Cost'),1,2000);
4679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4680  END IF;  
4681  IF 
4682 l_ledger_language = 'US' THEN
4683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4685  END IF;   
4686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4688   IF l_source IS NOT NULL THEN
4689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4691   END IF; 
4692  l_description := SUBSTR(l_description,1,1996);
4693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4694         trace
4695            (p_msg      => 'END of Description_45'
4696            ,p_level    => C_LEVEL_PROCEDURE
4697            ,p_module   => l_log_module);
4698 
4699   END IF;
4700   RETURN l_description;
4701 
4702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4703       trace
4704          (p_msg      => 'END of Description_45'
4705          ,p_level    => C_LEVEL_PROCEDURE
4706          ,p_module   => l_log_module);
4707 END IF;
4708 RETURN NULL;
4709 EXCEPTION
4710   WHEN VALUE_ERROR THEN
4711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4712             trace
4713                (p_msg      => 'ERROR: '||sqlerrm
4714                ,p_level    => C_LEVEL_EXCEPTION
4715                ,p_module   => l_log_module);
4716      END IF;
4717      RAISE;
4718  WHEN xla_exceptions_pkg.application_exception THEN
4719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4720       trace
4721          (p_msg      => 'ERROR: '||sqlerrm
4722          ,p_level    => C_LEVEL_EXCEPTION
4723          ,p_module   => l_log_module);
4724       END IF;
4725       RAISE;
4726  WHEN OTHERS THEN
4727        xla_exceptions_pkg.raise_message
4728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_45');
4729 END Description_45;
4730 
4731 ---------------------------------------
4732 --
4733 -- PRIVATE FUNCTION
4734 --         Description_46
4735 --
4736 ---------------------------------------
4737 FUNCTION Description_46 (
4738   p_application_id      IN NUMBER
4739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4740 --Period Close Date
4741  , p_source_1            IN DATE
4742 )
4743 RETURN VARCHAR2
4744 IS
4745 l_component_type        VARCHAR2(80)   ;
4746 l_component_code        VARCHAR2(30)   ;
4747 l_component_type_code   VARCHAR2(1)    ;
4748 l_component_appl_id     INTEGER        ;
4749 l_amb_context_code      VARCHAR2(30)   ;
4750 l_ledger_language       VARCHAR2(30)   ;
4751 l_source                VARCHAR2(1996) ;
4752 l_description           VARCHAR2(2000) ;
4753 l_log_module            VARCHAR2(240)  ;
4754 BEGIN
4755 IF g_log_enabled THEN
4756       l_log_module := C_DEFAULT_MODULE||'.Description_46';
4757 END IF;
4758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4759       trace
4760          (p_msg      => 'BEGIN of Description_46'
4761          ,p_level    => C_LEVEL_PROCEDURE
4762          ,p_module   => l_log_module);
4763 END IF;
4764 
4765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4766 l_component_type        := 'AMB_DESCRIPTION';
4767 l_component_code        := 'FA_CIP_TRANSFER_IC_PAYABLE';
4768 l_component_type_code   := 'S';
4769 l_component_appl_id     :=  140;
4770 l_amb_context_code      := 'DEFAULT';
4771 l_source                := NULL;
4772 l_description           := NULL;
4773 
4774 
4775  
4776  IF 
4777 l_ledger_language = 'US' THEN
4778     l_description :=  SUBSTR(CONCAT(l_description,'CIP Transfer Intercompany AP'),1,2000);
4779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4780  END IF;  
4781  IF 
4782 l_ledger_language = 'US' THEN
4783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4785  END IF;   
4786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4788   IF l_source IS NOT NULL THEN
4789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4791   END IF; 
4792  l_description := SUBSTR(l_description,1,1996);
4793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4794         trace
4795            (p_msg      => 'END of Description_46'
4796            ,p_level    => C_LEVEL_PROCEDURE
4797            ,p_module   => l_log_module);
4798 
4799   END IF;
4800   RETURN l_description;
4804          (p_msg      => 'END of Description_46'
4801 
4802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4803       trace
4805          ,p_level    => C_LEVEL_PROCEDURE
4806          ,p_module   => l_log_module);
4807 END IF;
4808 RETURN NULL;
4809 EXCEPTION
4810   WHEN VALUE_ERROR THEN
4811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4812             trace
4813                (p_msg      => 'ERROR: '||sqlerrm
4814                ,p_level    => C_LEVEL_EXCEPTION
4815                ,p_module   => l_log_module);
4816      END IF;
4817      RAISE;
4818  WHEN xla_exceptions_pkg.application_exception THEN
4819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4820       trace
4821          (p_msg      => 'ERROR: '||sqlerrm
4822          ,p_level    => C_LEVEL_EXCEPTION
4823          ,p_module   => l_log_module);
4824       END IF;
4825       RAISE;
4826  WHEN OTHERS THEN
4827        xla_exceptions_pkg.raise_message
4828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_46');
4829 END Description_46;
4830 
4831 ---------------------------------------
4832 --
4833 -- PRIVATE FUNCTION
4834 --         Description_47
4835 --
4836 ---------------------------------------
4837 FUNCTION Description_47 (
4838   p_application_id      IN NUMBER
4839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4840 --Period Close Date
4841  , p_source_1            IN DATE
4842 )
4843 RETURN VARCHAR2
4844 IS
4845 l_component_type        VARCHAR2(80)   ;
4846 l_component_code        VARCHAR2(30)   ;
4847 l_component_type_code   VARCHAR2(1)    ;
4848 l_component_appl_id     INTEGER        ;
4849 l_amb_context_code      VARCHAR2(30)   ;
4850 l_ledger_language       VARCHAR2(30)   ;
4851 l_source                VARCHAR2(1996) ;
4852 l_description           VARCHAR2(2000) ;
4853 l_log_module            VARCHAR2(240)  ;
4854 BEGIN
4855 IF g_log_enabled THEN
4856       l_log_module := C_DEFAULT_MODULE||'.Description_47';
4857 END IF;
4858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4859       trace
4860          (p_msg      => 'BEGIN of Description_47'
4861          ,p_level    => C_LEVEL_PROCEDURE
4862          ,p_module   => l_log_module);
4863 END IF;
4864 
4865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4866 l_component_type        := 'AMB_DESCRIPTION';
4867 l_component_code        := 'FA_CIP_TRANSFER_IC_RECEIVABLE';
4868 l_component_type_code   := 'S';
4869 l_component_appl_id     :=  140;
4870 l_amb_context_code      := 'DEFAULT';
4871 l_source                := NULL;
4872 l_description           := NULL;
4873 
4874 
4875  
4876  IF 
4877 l_ledger_language = 'US' THEN
4878     l_description :=  SUBSTR(CONCAT(l_description,'CIP Transfer Intercompany AR'),1,2000);
4879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4880  END IF;  
4881  IF 
4882 l_ledger_language = 'US' THEN
4883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4885  END IF;   
4886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4888   IF l_source IS NOT NULL THEN
4889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4891   END IF; 
4892  l_description := SUBSTR(l_description,1,1996);
4893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4894         trace
4895            (p_msg      => 'END of Description_47'
4896            ,p_level    => C_LEVEL_PROCEDURE
4897            ,p_module   => l_log_module);
4898 
4899   END IF;
4900   RETURN l_description;
4901 
4902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4903       trace
4904          (p_msg      => 'END of Description_47'
4905          ,p_level    => C_LEVEL_PROCEDURE
4906          ,p_module   => l_log_module);
4907 END IF;
4908 RETURN NULL;
4909 EXCEPTION
4910   WHEN VALUE_ERROR THEN
4911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4912             trace
4913                (p_msg      => 'ERROR: '||sqlerrm
4914                ,p_level    => C_LEVEL_EXCEPTION
4915                ,p_module   => l_log_module);
4916      END IF;
4917      RAISE;
4918  WHEN xla_exceptions_pkg.application_exception THEN
4919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4920       trace
4921          (p_msg      => 'ERROR: '||sqlerrm
4922          ,p_level    => C_LEVEL_EXCEPTION
4923          ,p_module   => l_log_module);
4924       END IF;
4925       RAISE;
4926  WHEN OTHERS THEN
4927        xla_exceptions_pkg.raise_message
4928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_47');
4929 END Description_47;
4930 
4931 ---------------------------------------
4932 --
4933 -- PRIVATE FUNCTION
4934 --         Description_48
4935 --
4936 ---------------------------------------
4937 FUNCTION Description_48 (
4938   p_application_id      IN NUMBER
4939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
4940 --Period Close Date
4941  , p_source_1            IN DATE
4942 )
4943 RETURN VARCHAR2
4944 IS
4945 l_component_type        VARCHAR2(80)   ;
4946 l_component_code        VARCHAR2(30)   ;
4947 l_component_type_code   VARCHAR2(1)    ;
4948 l_component_appl_id     INTEGER        ;
4949 l_amb_context_code      VARCHAR2(30)   ;
4950 l_ledger_language       VARCHAR2(30)   ;
4951 l_source                VARCHAR2(1996) ;
4952 l_description           VARCHAR2(2000) ;
4953 l_log_module            VARCHAR2(240)  ;
4954 BEGIN
4955 IF g_log_enabled THEN
4956       l_log_module := C_DEFAULT_MODULE||'.Description_48';
4957 END IF;
4961          ,p_level    => C_LEVEL_PROCEDURE
4958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4959       trace
4960          (p_msg      => 'BEGIN of Description_48'
4962          ,p_module   => l_log_module);
4963 END IF;
4964 
4965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
4966 l_component_type        := 'AMB_DESCRIPTION';
4967 l_component_code        := 'FA_CIP_TRANSFER_REVAL_RESERVE';
4968 l_component_type_code   := 'S';
4969 l_component_appl_id     :=  140;
4970 l_amb_context_code      := 'DEFAULT';
4971 l_source                := NULL;
4972 l_description           := NULL;
4973 
4974 
4975  
4976  IF 
4977 l_ledger_language = 'US' THEN
4978     l_description :=  SUBSTR(CONCAT(l_description,'CIP Transfer revaluation Reserve'),1,2000);
4979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4980  END IF;  
4981  IF 
4982 l_ledger_language = 'US' THEN
4983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
4984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
4985  END IF;   
4986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
4987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
4988   IF l_source IS NOT NULL THEN
4989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
4990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
4991   END IF; 
4992  l_description := SUBSTR(l_description,1,1996);
4993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4994         trace
4995            (p_msg      => 'END of Description_48'
4996            ,p_level    => C_LEVEL_PROCEDURE
4997            ,p_module   => l_log_module);
4998 
4999   END IF;
5000   RETURN l_description;
5001 
5002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5003       trace
5004          (p_msg      => 'END of Description_48'
5005          ,p_level    => C_LEVEL_PROCEDURE
5006          ,p_module   => l_log_module);
5007 END IF;
5008 RETURN NULL;
5009 EXCEPTION
5010   WHEN VALUE_ERROR THEN
5011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5012             trace
5013                (p_msg      => 'ERROR: '||sqlerrm
5014                ,p_level    => C_LEVEL_EXCEPTION
5015                ,p_module   => l_log_module);
5016      END IF;
5017      RAISE;
5018  WHEN xla_exceptions_pkg.application_exception THEN
5019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5020       trace
5021          (p_msg      => 'ERROR: '||sqlerrm
5022          ,p_level    => C_LEVEL_EXCEPTION
5023          ,p_module   => l_log_module);
5024       END IF;
5025       RAISE;
5026  WHEN OTHERS THEN
5027        xla_exceptions_pkg.raise_message
5028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_48');
5029 END Description_48;
5030 
5031 ---------------------------------------
5032 --
5033 -- PRIVATE FUNCTION
5034 --         Description_49
5035 --
5036 ---------------------------------------
5037 FUNCTION Description_49 (
5038   p_application_id      IN NUMBER
5039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5040 --Period Close Date
5041  , p_source_1            IN DATE
5042 )
5043 RETURN VARCHAR2
5044 IS
5045 l_component_type        VARCHAR2(80)   ;
5046 l_component_code        VARCHAR2(30)   ;
5047 l_component_type_code   VARCHAR2(1)    ;
5048 l_component_appl_id     INTEGER        ;
5049 l_amb_context_code      VARCHAR2(30)   ;
5050 l_ledger_language       VARCHAR2(30)   ;
5051 l_source                VARCHAR2(1996) ;
5052 l_description           VARCHAR2(2000) ;
5053 l_log_module            VARCHAR2(240)  ;
5054 BEGIN
5055 IF g_log_enabled THEN
5056       l_log_module := C_DEFAULT_MODULE||'.Description_49';
5057 END IF;
5058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5059       trace
5060          (p_msg      => 'BEGIN of Description_49'
5061          ,p_level    => C_LEVEL_PROCEDURE
5062          ,p_module   => l_log_module);
5063 END IF;
5064 
5065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5066 l_component_type        := 'AMB_DESCRIPTION';
5067 l_component_code        := 'FA_CIP_UNITADJ_COST';
5068 l_component_type_code   := 'S';
5069 l_component_appl_id     :=  140;
5070 l_amb_context_code      := 'DEFAULT';
5071 l_source                := NULL;
5072 l_description           := NULL;
5073 
5074 
5075  
5076  IF 
5077 l_ledger_language = 'US' THEN
5078     l_description :=  SUBSTR(CONCAT(l_description,'CIP Unit Adjustment Cost'),1,2000);
5079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5080  END IF;  
5081  IF 
5082 l_ledger_language = 'US' THEN
5083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5085  END IF;   
5086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5088   IF l_source IS NOT NULL THEN
5089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5091   END IF; 
5092  l_description := SUBSTR(l_description,1,1996);
5093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5094         trace
5095            (p_msg      => 'END of Description_49'
5096            ,p_level    => C_LEVEL_PROCEDURE
5097            ,p_module   => l_log_module);
5098 
5099   END IF;
5100   RETURN l_description;
5101 
5102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5103       trace
5104          (p_msg      => 'END of Description_49'
5105          ,p_level    => C_LEVEL_PROCEDURE
5106          ,p_module   => l_log_module);
5107 END IF;
5108 RETURN NULL;
5109 EXCEPTION
5113                (p_msg      => 'ERROR: '||sqlerrm
5110   WHEN VALUE_ERROR THEN
5111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5112             trace
5114                ,p_level    => C_LEVEL_EXCEPTION
5115                ,p_module   => l_log_module);
5116      END IF;
5117      RAISE;
5118  WHEN xla_exceptions_pkg.application_exception THEN
5119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5120       trace
5121          (p_msg      => 'ERROR: '||sqlerrm
5122          ,p_level    => C_LEVEL_EXCEPTION
5123          ,p_module   => l_log_module);
5124       END IF;
5125       RAISE;
5126  WHEN OTHERS THEN
5127        xla_exceptions_pkg.raise_message
5128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_49');
5129 END Description_49;
5130 
5131 ---------------------------------------
5132 --
5133 -- PRIVATE FUNCTION
5134 --         Description_50
5135 --
5136 ---------------------------------------
5137 FUNCTION Description_50 (
5138   p_application_id      IN NUMBER
5139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5140 --Period Close Date
5141  , p_source_1            IN DATE
5142 )
5143 RETURN VARCHAR2
5144 IS
5145 l_component_type        VARCHAR2(80)   ;
5146 l_component_code        VARCHAR2(30)   ;
5147 l_component_type_code   VARCHAR2(1)    ;
5148 l_component_appl_id     INTEGER        ;
5149 l_amb_context_code      VARCHAR2(30)   ;
5150 l_ledger_language       VARCHAR2(30)   ;
5151 l_source                VARCHAR2(1996) ;
5152 l_description           VARCHAR2(2000) ;
5153 l_log_module            VARCHAR2(240)  ;
5154 BEGIN
5155 IF g_log_enabled THEN
5156       l_log_module := C_DEFAULT_MODULE||'.Description_50';
5157 END IF;
5158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5159       trace
5160          (p_msg      => 'BEGIN of Description_50'
5161          ,p_level    => C_LEVEL_PROCEDURE
5162          ,p_module   => l_log_module);
5163 END IF;
5164 
5165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5166 l_component_type        := 'AMB_DESCRIPTION';
5167 l_component_code        := 'FA_CIP_UNITADJ_IC_PAYABLE';
5168 l_component_type_code   := 'S';
5169 l_component_appl_id     :=  140;
5170 l_amb_context_code      := 'DEFAULT';
5171 l_source                := NULL;
5172 l_description           := NULL;
5173 
5174 
5175  
5176  IF 
5177 l_ledger_language = 'US' THEN
5178     l_description :=  SUBSTR(CONCAT(l_description,'CIP Unit Adjustment Intercompany AP'),1,2000);
5179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5180  END IF;  
5181  IF 
5182 l_ledger_language = 'US' THEN
5183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5185  END IF;   
5186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5188   IF l_source IS NOT NULL THEN
5189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5191   END IF; 
5192  l_description := SUBSTR(l_description,1,1996);
5193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5194         trace
5195            (p_msg      => 'END of Description_50'
5196            ,p_level    => C_LEVEL_PROCEDURE
5197            ,p_module   => l_log_module);
5198 
5199   END IF;
5200   RETURN l_description;
5201 
5202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5203       trace
5204          (p_msg      => 'END of Description_50'
5205          ,p_level    => C_LEVEL_PROCEDURE
5206          ,p_module   => l_log_module);
5207 END IF;
5208 RETURN NULL;
5209 EXCEPTION
5210   WHEN VALUE_ERROR THEN
5211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5212             trace
5213                (p_msg      => 'ERROR: '||sqlerrm
5214                ,p_level    => C_LEVEL_EXCEPTION
5215                ,p_module   => l_log_module);
5216      END IF;
5217      RAISE;
5218  WHEN xla_exceptions_pkg.application_exception THEN
5219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5220       trace
5221          (p_msg      => 'ERROR: '||sqlerrm
5222          ,p_level    => C_LEVEL_EXCEPTION
5223          ,p_module   => l_log_module);
5224       END IF;
5225       RAISE;
5226  WHEN OTHERS THEN
5227        xla_exceptions_pkg.raise_message
5228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_50');
5229 END Description_50;
5230 
5231 ---------------------------------------
5232 --
5233 -- PRIVATE FUNCTION
5234 --         Description_51
5235 --
5236 ---------------------------------------
5237 FUNCTION Description_51 (
5238   p_application_id      IN NUMBER
5239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5240 --Period Close Date
5241  , p_source_1            IN DATE
5242 )
5243 RETURN VARCHAR2
5244 IS
5245 l_component_type        VARCHAR2(80)   ;
5246 l_component_code        VARCHAR2(30)   ;
5247 l_component_type_code   VARCHAR2(1)    ;
5248 l_component_appl_id     INTEGER        ;
5249 l_amb_context_code      VARCHAR2(30)   ;
5250 l_ledger_language       VARCHAR2(30)   ;
5251 l_source                VARCHAR2(1996) ;
5252 l_description           VARCHAR2(2000) ;
5253 l_log_module            VARCHAR2(240)  ;
5254 BEGIN
5255 IF g_log_enabled THEN
5256       l_log_module := C_DEFAULT_MODULE||'.Description_51';
5257 END IF;
5258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5259       trace
5260          (p_msg      => 'BEGIN of Description_51'
5261          ,p_level    => C_LEVEL_PROCEDURE
5262          ,p_module   => l_log_module);
5263 END IF;
5264 
5268 l_component_type_code   := 'S';
5265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5266 l_component_type        := 'AMB_DESCRIPTION';
5267 l_component_code        := 'FA_CIP_UNITADJ_IC_RECEIVABLE';
5269 l_component_appl_id     :=  140;
5270 l_amb_context_code      := 'DEFAULT';
5271 l_source                := NULL;
5272 l_description           := NULL;
5273 
5274 
5275  
5276  IF 
5277 l_ledger_language = 'US' THEN
5278     l_description :=  SUBSTR(CONCAT(l_description,'CIP Unit Adjustment Intercompany AR'),1,2000);
5279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5280  END IF;  
5281  IF 
5282 l_ledger_language = 'US' THEN
5283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5285  END IF;   
5286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5288   IF l_source IS NOT NULL THEN
5289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5291   END IF; 
5292  l_description := SUBSTR(l_description,1,1996);
5293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5294         trace
5295            (p_msg      => 'END of Description_51'
5296            ,p_level    => C_LEVEL_PROCEDURE
5297            ,p_module   => l_log_module);
5298 
5299   END IF;
5300   RETURN l_description;
5301 
5302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5303       trace
5304          (p_msg      => 'END of Description_51'
5305          ,p_level    => C_LEVEL_PROCEDURE
5306          ,p_module   => l_log_module);
5307 END IF;
5308 RETURN NULL;
5309 EXCEPTION
5310   WHEN VALUE_ERROR THEN
5311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5312             trace
5313                (p_msg      => 'ERROR: '||sqlerrm
5314                ,p_level    => C_LEVEL_EXCEPTION
5315                ,p_module   => l_log_module);
5316      END IF;
5317      RAISE;
5318  WHEN xla_exceptions_pkg.application_exception THEN
5319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5320       trace
5321          (p_msg      => 'ERROR: '||sqlerrm
5322          ,p_level    => C_LEVEL_EXCEPTION
5323          ,p_module   => l_log_module);
5324       END IF;
5325       RAISE;
5326  WHEN OTHERS THEN
5327        xla_exceptions_pkg.raise_message
5328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_51');
5329 END Description_51;
5330 
5331 ---------------------------------------
5332 --
5333 -- PRIVATE FUNCTION
5334 --         Description_52
5335 --
5336 ---------------------------------------
5337 FUNCTION Description_52 (
5338   p_application_id      IN NUMBER
5339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5340 --Period Close Date
5341  , p_source_1            IN DATE
5342 )
5343 RETURN VARCHAR2
5344 IS
5345 l_component_type        VARCHAR2(80)   ;
5346 l_component_code        VARCHAR2(30)   ;
5347 l_component_type_code   VARCHAR2(1)    ;
5348 l_component_appl_id     INTEGER        ;
5349 l_amb_context_code      VARCHAR2(30)   ;
5350 l_ledger_language       VARCHAR2(30)   ;
5351 l_source                VARCHAR2(1996) ;
5352 l_description           VARCHAR2(2000) ;
5353 l_log_module            VARCHAR2(240)  ;
5354 BEGIN
5355 IF g_log_enabled THEN
5356       l_log_module := C_DEFAULT_MODULE||'.Description_52';
5357 END IF;
5358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5359       trace
5360          (p_msg      => 'BEGIN of Description_52'
5361          ,p_level    => C_LEVEL_PROCEDURE
5362          ,p_module   => l_log_module);
5363 END IF;
5364 
5365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5366 l_component_type        := 'AMB_DESCRIPTION';
5367 l_component_code        := 'FA_CIP_UNITADJ_REVAL_RESERVE';
5368 l_component_type_code   := 'S';
5369 l_component_appl_id     :=  140;
5370 l_amb_context_code      := 'DEFAULT';
5371 l_source                := NULL;
5372 l_description           := NULL;
5373 
5374 
5375  
5376  IF 
5377 l_ledger_language = 'US' THEN
5378     l_description :=  SUBSTR(CONCAT(l_description,'CIP Unit Adjustment revaluation Reserve'),1,2000);
5379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5380  END IF;  
5381  IF 
5382 l_ledger_language = 'US' THEN
5383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5385  END IF;   
5386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5388   IF l_source IS NOT NULL THEN
5389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5391   END IF; 
5392  l_description := SUBSTR(l_description,1,1996);
5393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5394         trace
5395            (p_msg      => 'END of Description_52'
5396            ,p_level    => C_LEVEL_PROCEDURE
5397            ,p_module   => l_log_module);
5398 
5399   END IF;
5400   RETURN l_description;
5401 
5402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5403       trace
5404          (p_msg      => 'END of Description_52'
5405          ,p_level    => C_LEVEL_PROCEDURE
5406          ,p_module   => l_log_module);
5407 END IF;
5408 RETURN NULL;
5409 EXCEPTION
5410   WHEN VALUE_ERROR THEN
5411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5412             trace
5413                (p_msg      => 'ERROR: '||sqlerrm
5414                ,p_level    => C_LEVEL_EXCEPTION
5418  WHEN xla_exceptions_pkg.application_exception THEN
5415                ,p_module   => l_log_module);
5416      END IF;
5417      RAISE;
5419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5420       trace
5421          (p_msg      => 'ERROR: '||sqlerrm
5422          ,p_level    => C_LEVEL_EXCEPTION
5423          ,p_module   => l_log_module);
5424       END IF;
5425       RAISE;
5426  WHEN OTHERS THEN
5427        xla_exceptions_pkg.raise_message
5428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_52');
5429 END Description_52;
5430 
5431 ---------------------------------------
5432 --
5433 -- PRIVATE FUNCTION
5434 --         Description_53
5435 --
5436 ---------------------------------------
5437 FUNCTION Description_53 (
5438   p_application_id      IN NUMBER
5439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5440 --Period Close Date
5441  , p_source_1            IN DATE
5442 )
5443 RETURN VARCHAR2
5444 IS
5445 l_component_type        VARCHAR2(80)   ;
5446 l_component_code        VARCHAR2(30)   ;
5447 l_component_type_code   VARCHAR2(1)    ;
5448 l_component_appl_id     INTEGER        ;
5449 l_amb_context_code      VARCHAR2(30)   ;
5450 l_ledger_language       VARCHAR2(30)   ;
5451 l_source                VARCHAR2(1996) ;
5452 l_description           VARCHAR2(2000) ;
5453 l_log_module            VARCHAR2(240)  ;
5454 BEGIN
5455 IF g_log_enabled THEN
5456       l_log_module := C_DEFAULT_MODULE||'.Description_53';
5457 END IF;
5458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5459       trace
5460          (p_msg      => 'BEGIN of Description_53'
5461          ,p_level    => C_LEVEL_PROCEDURE
5462          ,p_module   => l_log_module);
5463 END IF;
5464 
5465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5466 l_component_type        := 'AMB_DESCRIPTION';
5467 l_component_code        := 'FA_CIP_UNIT_ADJ';
5468 l_component_type_code   := 'S';
5469 l_component_appl_id     :=  140;
5470 l_amb_context_code      := 'DEFAULT';
5471 l_source                := NULL;
5472 l_description           := NULL;
5473 
5474 
5475  
5476  IF 
5477 l_ledger_language = 'US' THEN
5478     l_description :=  SUBSTR(CONCAT(l_description,'CIP Unit Adjustment'),1,2000);
5479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5480  END IF;  
5481  IF 
5482 l_ledger_language = 'US' THEN
5483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5485  END IF;   
5486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5488   IF l_source IS NOT NULL THEN
5489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5491   END IF; 
5492  l_description := SUBSTR(l_description,1,1996);
5493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5494         trace
5495            (p_msg      => 'END of Description_53'
5496            ,p_level    => C_LEVEL_PROCEDURE
5497            ,p_module   => l_log_module);
5498 
5499   END IF;
5500   RETURN l_description;
5501 
5502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5503       trace
5504          (p_msg      => 'END of Description_53'
5505          ,p_level    => C_LEVEL_PROCEDURE
5506          ,p_module   => l_log_module);
5507 END IF;
5508 RETURN NULL;
5509 EXCEPTION
5510   WHEN VALUE_ERROR THEN
5511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5512             trace
5513                (p_msg      => 'ERROR: '||sqlerrm
5514                ,p_level    => C_LEVEL_EXCEPTION
5515                ,p_module   => l_log_module);
5516      END IF;
5517      RAISE;
5518  WHEN xla_exceptions_pkg.application_exception THEN
5519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5520       trace
5521          (p_msg      => 'ERROR: '||sqlerrm
5522          ,p_level    => C_LEVEL_EXCEPTION
5523          ,p_module   => l_log_module);
5524       END IF;
5525       RAISE;
5526  WHEN OTHERS THEN
5527        xla_exceptions_pkg.raise_message
5528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_53');
5529 END Description_53;
5530 
5531 ---------------------------------------
5532 --
5533 -- PRIVATE FUNCTION
5534 --         Description_54
5535 --
5536 ---------------------------------------
5537 FUNCTION Description_54 (
5538   p_application_id      IN NUMBER
5539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5540 --Period Close Date
5541  , p_source_1            IN DATE
5542 )
5543 RETURN VARCHAR2
5544 IS
5545 l_component_type        VARCHAR2(80)   ;
5546 l_component_code        VARCHAR2(30)   ;
5547 l_component_type_code   VARCHAR2(1)    ;
5548 l_component_appl_id     INTEGER        ;
5549 l_amb_context_code      VARCHAR2(30)   ;
5550 l_ledger_language       VARCHAR2(30)   ;
5551 l_source                VARCHAR2(1996) ;
5552 l_description           VARCHAR2(2000) ;
5553 l_log_module            VARCHAR2(240)  ;
5554 BEGIN
5555 IF g_log_enabled THEN
5556       l_log_module := C_DEFAULT_MODULE||'.Description_54';
5557 END IF;
5558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5559       trace
5560          (p_msg      => 'BEGIN of Description_54'
5561          ,p_level    => C_LEVEL_PROCEDURE
5562          ,p_module   => l_log_module);
5563 END IF;
5564 
5565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5566 l_component_type        := 'AMB_DESCRIPTION';
5567 l_component_code        := 'FA_DEFERRED_DEPRN';
5568 l_component_type_code   := 'S';
5569 l_component_appl_id     :=  140;
5570 l_amb_context_code      := 'DEFAULT';
5574 
5571 l_source                := NULL;
5572 l_description           := NULL;
5573 
5575  
5576  IF 
5577 l_ledger_language = 'US' THEN
5578     l_description :=  SUBSTR(CONCAT(l_description,'Deferred Depreciation'),1,2000);
5579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5580  END IF;  
5581  IF 
5582 l_ledger_language = 'US' THEN
5583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5585  END IF;   
5586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5588   IF l_source IS NOT NULL THEN
5589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5591   END IF; 
5592  l_description := SUBSTR(l_description,1,1996);
5593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5594         trace
5595            (p_msg      => 'END of Description_54'
5596            ,p_level    => C_LEVEL_PROCEDURE
5597            ,p_module   => l_log_module);
5598 
5599   END IF;
5600   RETURN l_description;
5601 
5602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5603       trace
5604          (p_msg      => 'END of Description_54'
5605          ,p_level    => C_LEVEL_PROCEDURE
5606          ,p_module   => l_log_module);
5607 END IF;
5608 RETURN NULL;
5609 EXCEPTION
5610   WHEN VALUE_ERROR THEN
5611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5612             trace
5613                (p_msg      => 'ERROR: '||sqlerrm
5614                ,p_level    => C_LEVEL_EXCEPTION
5615                ,p_module   => l_log_module);
5616      END IF;
5617      RAISE;
5618  WHEN xla_exceptions_pkg.application_exception THEN
5619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5620       trace
5621          (p_msg      => 'ERROR: '||sqlerrm
5622          ,p_level    => C_LEVEL_EXCEPTION
5623          ,p_module   => l_log_module);
5624       END IF;
5625       RAISE;
5626  WHEN OTHERS THEN
5627        xla_exceptions_pkg.raise_message
5628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_54');
5629 END Description_54;
5630 
5631 ---------------------------------------
5632 --
5633 -- PRIVATE FUNCTION
5634 --         Description_55
5635 --
5636 ---------------------------------------
5637 FUNCTION Description_55 (
5638   p_application_id      IN NUMBER
5639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5640 --Period Close Date
5641  , p_source_1            IN DATE
5642 )
5643 RETURN VARCHAR2
5644 IS
5645 l_component_type        VARCHAR2(80)   ;
5646 l_component_code        VARCHAR2(30)   ;
5647 l_component_type_code   VARCHAR2(1)    ;
5648 l_component_appl_id     INTEGER        ;
5649 l_amb_context_code      VARCHAR2(30)   ;
5650 l_ledger_language       VARCHAR2(30)   ;
5651 l_source                VARCHAR2(1996) ;
5652 l_description           VARCHAR2(2000) ;
5653 l_log_module            VARCHAR2(240)  ;
5654 BEGIN
5655 IF g_log_enabled THEN
5656       l_log_module := C_DEFAULT_MODULE||'.Description_55';
5657 END IF;
5658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5659       trace
5660          (p_msg      => 'BEGIN of Description_55'
5661          ,p_level    => C_LEVEL_PROCEDURE
5662          ,p_module   => l_log_module);
5663 END IF;
5664 
5665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5666 l_component_type        := 'AMB_DESCRIPTION';
5667 l_component_code        := 'FA_DEFERRED_DEPRN_EXPENSE';
5668 l_component_type_code   := 'S';
5669 l_component_appl_id     :=  140;
5670 l_amb_context_code      := 'DEFAULT';
5671 l_source                := NULL;
5672 l_description           := NULL;
5673 
5674 
5675  
5676  IF 
5677 l_ledger_language = 'US' THEN
5678     l_description :=  SUBSTR(CONCAT(l_description,'Deferred Depreciation Expense'),1,2000);
5679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5680  END IF;  
5681  IF 
5682 l_ledger_language = 'US' THEN
5683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5685  END IF;   
5686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5688   IF l_source IS NOT NULL THEN
5689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5691   END IF; 
5692  l_description := SUBSTR(l_description,1,1996);
5693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5694         trace
5695            (p_msg      => 'END of Description_55'
5696            ,p_level    => C_LEVEL_PROCEDURE
5697            ,p_module   => l_log_module);
5698 
5699   END IF;
5700   RETURN l_description;
5701 
5702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5703       trace
5704          (p_msg      => 'END of Description_55'
5705          ,p_level    => C_LEVEL_PROCEDURE
5706          ,p_module   => l_log_module);
5707 END IF;
5708 RETURN NULL;
5709 EXCEPTION
5710   WHEN VALUE_ERROR THEN
5711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5712             trace
5713                (p_msg      => 'ERROR: '||sqlerrm
5714                ,p_level    => C_LEVEL_EXCEPTION
5715                ,p_module   => l_log_module);
5716      END IF;
5717      RAISE;
5718  WHEN xla_exceptions_pkg.application_exception THEN
5719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5720       trace
5721          (p_msg      => 'ERROR: '||sqlerrm
5722          ,p_level    => C_LEVEL_EXCEPTION
5723          ,p_module   => l_log_module);
5727        xla_exceptions_pkg.raise_message
5724       END IF;
5725       RAISE;
5726  WHEN OTHERS THEN
5728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_55');
5729 END Description_55;
5730 
5731 ---------------------------------------
5732 --
5733 -- PRIVATE FUNCTION
5734 --         Description_56
5735 --
5736 ---------------------------------------
5737 FUNCTION Description_56 (
5738   p_application_id      IN NUMBER
5739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5740 --Period Close Date
5741  , p_source_1            IN DATE
5742 )
5743 RETURN VARCHAR2
5744 IS
5745 l_component_type        VARCHAR2(80)   ;
5746 l_component_code        VARCHAR2(30)   ;
5747 l_component_type_code   VARCHAR2(1)    ;
5748 l_component_appl_id     INTEGER        ;
5749 l_amb_context_code      VARCHAR2(30)   ;
5750 l_ledger_language       VARCHAR2(30)   ;
5751 l_source                VARCHAR2(1996) ;
5752 l_description           VARCHAR2(2000) ;
5753 l_log_module            VARCHAR2(240)  ;
5754 BEGIN
5755 IF g_log_enabled THEN
5756       l_log_module := C_DEFAULT_MODULE||'.Description_56';
5757 END IF;
5758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5759       trace
5760          (p_msg      => 'BEGIN of Description_56'
5761          ,p_level    => C_LEVEL_PROCEDURE
5762          ,p_module   => l_log_module);
5763 END IF;
5764 
5765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5766 l_component_type        := 'AMB_DESCRIPTION';
5767 l_component_code        := 'FA_DEFERRED_DEPRN_RESERVE';
5768 l_component_type_code   := 'S';
5769 l_component_appl_id     :=  140;
5770 l_amb_context_code      := 'DEFAULT';
5771 l_source                := NULL;
5772 l_description           := NULL;
5773 
5774 
5775  
5776  IF 
5777 l_ledger_language = 'US' THEN
5778     l_description :=  SUBSTR(CONCAT(l_description,'Deferred Depreciation Reserve'),1,2000);
5779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5780  END IF;  
5781  IF 
5782 l_ledger_language = 'US' THEN
5783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5785  END IF;   
5786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5788   IF l_source IS NOT NULL THEN
5789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5791   END IF; 
5792  l_description := SUBSTR(l_description,1,1996);
5793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5794         trace
5795            (p_msg      => 'END of Description_56'
5796            ,p_level    => C_LEVEL_PROCEDURE
5797            ,p_module   => l_log_module);
5798 
5799   END IF;
5800   RETURN l_description;
5801 
5802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5803       trace
5804          (p_msg      => 'END of Description_56'
5805          ,p_level    => C_LEVEL_PROCEDURE
5806          ,p_module   => l_log_module);
5807 END IF;
5808 RETURN NULL;
5809 EXCEPTION
5810   WHEN VALUE_ERROR THEN
5811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5812             trace
5813                (p_msg      => 'ERROR: '||sqlerrm
5814                ,p_level    => C_LEVEL_EXCEPTION
5815                ,p_module   => l_log_module);
5816      END IF;
5817      RAISE;
5818  WHEN xla_exceptions_pkg.application_exception THEN
5819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5820       trace
5821          (p_msg      => 'ERROR: '||sqlerrm
5822          ,p_level    => C_LEVEL_EXCEPTION
5823          ,p_module   => l_log_module);
5824       END IF;
5825       RAISE;
5826  WHEN OTHERS THEN
5827        xla_exceptions_pkg.raise_message
5828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_56');
5829 END Description_56;
5830 
5831 ---------------------------------------
5832 --
5833 -- PRIVATE FUNCTION
5834 --         Description_57
5835 --
5836 ---------------------------------------
5837 FUNCTION Description_57 (
5838   p_application_id      IN NUMBER
5839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5840 --Period Close Date
5841  , p_source_1            IN DATE
5842 )
5843 RETURN VARCHAR2
5844 IS
5845 l_component_type        VARCHAR2(80)   ;
5846 l_component_code        VARCHAR2(30)   ;
5847 l_component_type_code   VARCHAR2(1)    ;
5848 l_component_appl_id     INTEGER        ;
5849 l_amb_context_code      VARCHAR2(30)   ;
5850 l_ledger_language       VARCHAR2(30)   ;
5851 l_source                VARCHAR2(1996) ;
5852 l_description           VARCHAR2(2000) ;
5853 l_log_module            VARCHAR2(240)  ;
5854 BEGIN
5855 IF g_log_enabled THEN
5856       l_log_module := C_DEFAULT_MODULE||'.Description_57';
5857 END IF;
5858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5859       trace
5860          (p_msg      => 'BEGIN of Description_57'
5861          ,p_level    => C_LEVEL_PROCEDURE
5862          ,p_module   => l_log_module);
5863 END IF;
5864 
5865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5866 l_component_type        := 'AMB_DESCRIPTION';
5867 l_component_code        := 'FA_DEPRECIATION';
5868 l_component_type_code   := 'S';
5869 l_component_appl_id     :=  140;
5870 l_amb_context_code      := 'DEFAULT';
5871 l_source                := NULL;
5872 l_description           := NULL;
5873 
5874 
5875  
5876  IF 
5877 l_ledger_language = 'US' THEN
5878     l_description :=  SUBSTR(CONCAT(l_description,'Depreciation'),1,2000);
5879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5880  END IF;  
5884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5881  IF 
5882 l_ledger_language = 'US' THEN
5883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5885  END IF;   
5886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5888   IF l_source IS NOT NULL THEN
5889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5891   END IF; 
5892  l_description := SUBSTR(l_description,1,1996);
5893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5894         trace
5895            (p_msg      => 'END of Description_57'
5896            ,p_level    => C_LEVEL_PROCEDURE
5897            ,p_module   => l_log_module);
5898 
5899   END IF;
5900   RETURN l_description;
5901 
5902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5903       trace
5904          (p_msg      => 'END of Description_57'
5905          ,p_level    => C_LEVEL_PROCEDURE
5906          ,p_module   => l_log_module);
5907 END IF;
5908 RETURN NULL;
5909 EXCEPTION
5910   WHEN VALUE_ERROR THEN
5911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5912             trace
5913                (p_msg      => 'ERROR: '||sqlerrm
5914                ,p_level    => C_LEVEL_EXCEPTION
5915                ,p_module   => l_log_module);
5916      END IF;
5917      RAISE;
5918  WHEN xla_exceptions_pkg.application_exception THEN
5919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5920       trace
5921          (p_msg      => 'ERROR: '||sqlerrm
5922          ,p_level    => C_LEVEL_EXCEPTION
5923          ,p_module   => l_log_module);
5924       END IF;
5925       RAISE;
5926  WHEN OTHERS THEN
5927        xla_exceptions_pkg.raise_message
5928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_57');
5929 END Description_57;
5930 
5931 ---------------------------------------
5932 --
5933 -- PRIVATE FUNCTION
5934 --         Description_58
5935 --
5936 ---------------------------------------
5937 FUNCTION Description_58 (
5938   p_application_id      IN NUMBER
5939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
5940 --Period Close Date
5941  , p_source_1            IN DATE
5942 )
5943 RETURN VARCHAR2
5944 IS
5945 l_component_type        VARCHAR2(80)   ;
5946 l_component_code        VARCHAR2(30)   ;
5947 l_component_type_code   VARCHAR2(1)    ;
5948 l_component_appl_id     INTEGER        ;
5949 l_amb_context_code      VARCHAR2(30)   ;
5950 l_ledger_language       VARCHAR2(30)   ;
5951 l_source                VARCHAR2(1996) ;
5952 l_description           VARCHAR2(2000) ;
5953 l_log_module            VARCHAR2(240)  ;
5954 BEGIN
5955 IF g_log_enabled THEN
5956       l_log_module := C_DEFAULT_MODULE||'.Description_58';
5957 END IF;
5958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5959       trace
5960          (p_msg      => 'BEGIN of Description_58'
5961          ,p_level    => C_LEVEL_PROCEDURE
5962          ,p_module   => l_log_module);
5963 END IF;
5964 
5965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
5966 l_component_type        := 'AMB_DESCRIPTION';
5967 l_component_code        := 'FA_DEPRECIATION_ADJUSTMENT';
5968 l_component_type_code   := 'S';
5969 l_component_appl_id     :=  140;
5970 l_amb_context_code      := 'DEFAULT';
5971 l_source                := NULL;
5972 l_description           := NULL;
5973 
5974 
5975  
5976  IF 
5977 l_ledger_language = 'US' THEN
5978     l_description :=  SUBSTR(CONCAT(l_description,'Depreciation Adjustment'),1,2000);
5979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5980  END IF;  
5981  IF 
5982 l_ledger_language = 'US' THEN
5983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
5984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
5985  END IF;   
5986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
5987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
5988   IF l_source IS NOT NULL THEN
5989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
5990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
5991   END IF; 
5992  l_description := SUBSTR(l_description,1,1996);
5993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5994         trace
5995            (p_msg      => 'END of Description_58'
5996            ,p_level    => C_LEVEL_PROCEDURE
5997            ,p_module   => l_log_module);
5998 
5999   END IF;
6000   RETURN l_description;
6001 
6002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6003       trace
6004          (p_msg      => 'END of Description_58'
6005          ,p_level    => C_LEVEL_PROCEDURE
6006          ,p_module   => l_log_module);
6007 END IF;
6008 RETURN NULL;
6009 EXCEPTION
6010   WHEN VALUE_ERROR THEN
6011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6012             trace
6013                (p_msg      => 'ERROR: '||sqlerrm
6014                ,p_level    => C_LEVEL_EXCEPTION
6015                ,p_module   => l_log_module);
6016      END IF;
6017      RAISE;
6018  WHEN xla_exceptions_pkg.application_exception THEN
6019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6020       trace
6021          (p_msg      => 'ERROR: '||sqlerrm
6022          ,p_level    => C_LEVEL_EXCEPTION
6023          ,p_module   => l_log_module);
6024       END IF;
6025       RAISE;
6026  WHEN OTHERS THEN
6027        xla_exceptions_pkg.raise_message
6028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_58');
6029 END Description_58;
6030 
6031 ---------------------------------------
6032 --
6033 -- PRIVATE FUNCTION
6034 --         Description_59
6038   p_application_id      IN NUMBER
6035 --
6036 ---------------------------------------
6037 FUNCTION Description_59 (
6039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6040 --Period Close Date
6041  , p_source_1            IN DATE
6042 )
6043 RETURN VARCHAR2
6044 IS
6045 l_component_type        VARCHAR2(80)   ;
6046 l_component_code        VARCHAR2(30)   ;
6047 l_component_type_code   VARCHAR2(1)    ;
6048 l_component_appl_id     INTEGER        ;
6049 l_amb_context_code      VARCHAR2(30)   ;
6050 l_ledger_language       VARCHAR2(30)   ;
6051 l_source                VARCHAR2(1996) ;
6052 l_description           VARCHAR2(2000) ;
6053 l_log_module            VARCHAR2(240)  ;
6054 BEGIN
6055 IF g_log_enabled THEN
6056       l_log_module := C_DEFAULT_MODULE||'.Description_59';
6057 END IF;
6058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6059       trace
6060          (p_msg      => 'BEGIN of Description_59'
6061          ,p_level    => C_LEVEL_PROCEDURE
6062          ,p_module   => l_log_module);
6063 END IF;
6064 
6065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6066 l_component_type        := 'AMB_DESCRIPTION';
6067 l_component_code        := 'FA_DEPRN_RESERVE';
6068 l_component_type_code   := 'S';
6069 l_component_appl_id     :=  140;
6070 l_amb_context_code      := 'DEFAULT';
6071 l_source                := NULL;
6072 l_description           := NULL;
6073 
6074 
6075  
6076  IF 
6077 l_ledger_language = 'US' THEN
6078     l_description :=  SUBSTR(CONCAT(l_description,'Depreciation Reserve'),1,2000);
6079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6080  END IF;  
6081  IF 
6082 l_ledger_language = 'US' THEN
6083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6085  END IF;   
6086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6088   IF l_source IS NOT NULL THEN
6089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6091   END IF; 
6092  l_description := SUBSTR(l_description,1,1996);
6093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6094         trace
6095            (p_msg      => 'END of Description_59'
6096            ,p_level    => C_LEVEL_PROCEDURE
6097            ,p_module   => l_log_module);
6098 
6099   END IF;
6100   RETURN l_description;
6101 
6102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6103       trace
6104          (p_msg      => 'END of Description_59'
6105          ,p_level    => C_LEVEL_PROCEDURE
6106          ,p_module   => l_log_module);
6107 END IF;
6108 RETURN NULL;
6109 EXCEPTION
6110   WHEN VALUE_ERROR THEN
6111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6112             trace
6113                (p_msg      => 'ERROR: '||sqlerrm
6114                ,p_level    => C_LEVEL_EXCEPTION
6115                ,p_module   => l_log_module);
6116      END IF;
6117      RAISE;
6118  WHEN xla_exceptions_pkg.application_exception THEN
6119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6120       trace
6121          (p_msg      => 'ERROR: '||sqlerrm
6122          ,p_level    => C_LEVEL_EXCEPTION
6123          ,p_module   => l_log_module);
6124       END IF;
6125       RAISE;
6126  WHEN OTHERS THEN
6127        xla_exceptions_pkg.raise_message
6128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_59');
6129 END Description_59;
6130 
6131 ---------------------------------------
6132 --
6133 -- PRIVATE FUNCTION
6134 --         Description_60
6135 --
6136 ---------------------------------------
6137 FUNCTION Description_60 (
6138   p_application_id      IN NUMBER
6139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6140 --Period Close Date
6141  , p_source_1            IN DATE
6142 )
6143 RETURN VARCHAR2
6144 IS
6145 l_component_type        VARCHAR2(80)   ;
6146 l_component_code        VARCHAR2(30)   ;
6147 l_component_type_code   VARCHAR2(1)    ;
6148 l_component_appl_id     INTEGER        ;
6149 l_amb_context_code      VARCHAR2(30)   ;
6150 l_ledger_language       VARCHAR2(30)   ;
6151 l_source                VARCHAR2(1996) ;
6152 l_description           VARCHAR2(2000) ;
6153 l_log_module            VARCHAR2(240)  ;
6154 BEGIN
6155 IF g_log_enabled THEN
6156       l_log_module := C_DEFAULT_MODULE||'.Description_60';
6157 END IF;
6158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6159       trace
6160          (p_msg      => 'BEGIN of Description_60'
6161          ,p_level    => C_LEVEL_PROCEDURE
6162          ,p_module   => l_log_module);
6163 END IF;
6164 
6165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6166 l_component_type        := 'AMB_DESCRIPTION';
6167 l_component_code        := 'FA_DEPRN_REVAL_AMORT';
6168 l_component_type_code   := 'S';
6169 l_component_appl_id     :=  140;
6170 l_amb_context_code      := 'DEFAULT';
6171 l_source                := NULL;
6172 l_description           := NULL;
6173 
6174 
6175  
6176  IF 
6177 l_ledger_language = 'US' THEN
6178     l_description :=  SUBSTR(CONCAT(l_description,'Depreciation Revaluation Amortization'),1,2000);
6179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6180  END IF;  
6181  IF 
6182 l_ledger_language = 'US' THEN
6183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6185  END IF;   
6186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6188   IF l_source IS NOT NULL THEN
6189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6191   END IF; 
6192  l_description := SUBSTR(l_description,1,1996);
6193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6194         trace
6195            (p_msg      => 'END of Description_60'
6196            ,p_level    => C_LEVEL_PROCEDURE
6197            ,p_module   => l_log_module);
6198 
6199   END IF;
6200   RETURN l_description;
6201 
6202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6203       trace
6204          (p_msg      => 'END of Description_60'
6205          ,p_level    => C_LEVEL_PROCEDURE
6206          ,p_module   => l_log_module);
6207 END IF;
6208 RETURN NULL;
6209 EXCEPTION
6210   WHEN VALUE_ERROR THEN
6211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6212             trace
6213                (p_msg      => 'ERROR: '||sqlerrm
6214                ,p_level    => C_LEVEL_EXCEPTION
6215                ,p_module   => l_log_module);
6216      END IF;
6217      RAISE;
6218  WHEN xla_exceptions_pkg.application_exception THEN
6219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6220       trace
6221          (p_msg      => 'ERROR: '||sqlerrm
6222          ,p_level    => C_LEVEL_EXCEPTION
6223          ,p_module   => l_log_module);
6224       END IF;
6225       RAISE;
6226  WHEN OTHERS THEN
6227        xla_exceptions_pkg.raise_message
6228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_60');
6229 END Description_60;
6230 
6231 ---------------------------------------
6232 --
6233 -- PRIVATE FUNCTION
6234 --         Description_61
6235 --
6236 ---------------------------------------
6237 FUNCTION Description_61 (
6238   p_application_id      IN NUMBER
6239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6240 --Period Close Date
6241  , p_source_1            IN DATE
6242 )
6243 RETURN VARCHAR2
6244 IS
6245 l_component_type        VARCHAR2(80)   ;
6246 l_component_code        VARCHAR2(30)   ;
6247 l_component_type_code   VARCHAR2(1)    ;
6248 l_component_appl_id     INTEGER        ;
6249 l_amb_context_code      VARCHAR2(30)   ;
6250 l_ledger_language       VARCHAR2(30)   ;
6251 l_source                VARCHAR2(1996) ;
6252 l_description           VARCHAR2(2000) ;
6253 l_log_module            VARCHAR2(240)  ;
6254 BEGIN
6255 IF g_log_enabled THEN
6256       l_log_module := C_DEFAULT_MODULE||'.Description_61';
6257 END IF;
6258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6259       trace
6260          (p_msg      => 'BEGIN of Description_61'
6261          ,p_level    => C_LEVEL_PROCEDURE
6262          ,p_module   => l_log_module);
6263 END IF;
6264 
6265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6266 l_component_type        := 'AMB_DESCRIPTION';
6267 l_component_code        := 'FA_DEPRN_REVAL_RESERVE';
6268 l_component_type_code   := 'S';
6269 l_component_appl_id     :=  140;
6270 l_amb_context_code      := 'DEFAULT';
6271 l_source                := NULL;
6272 l_description           := NULL;
6273 
6274 
6275  
6276  IF 
6277 l_ledger_language = 'US' THEN
6278     l_description :=  SUBSTR(CONCAT(l_description,'Depreciation Revaluation Reserve'),1,2000);
6279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6280  END IF;  
6281  IF 
6282 l_ledger_language = 'US' THEN
6283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6285  END IF;   
6286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6288   IF l_source IS NOT NULL THEN
6289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6291   END IF; 
6292  l_description := SUBSTR(l_description,1,1996);
6293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6294         trace
6295            (p_msg      => 'END of Description_61'
6296            ,p_level    => C_LEVEL_PROCEDURE
6297            ,p_module   => l_log_module);
6298 
6299   END IF;
6300   RETURN l_description;
6301 
6302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6303       trace
6304          (p_msg      => 'END of Description_61'
6305          ,p_level    => C_LEVEL_PROCEDURE
6306          ,p_module   => l_log_module);
6307 END IF;
6308 RETURN NULL;
6309 EXCEPTION
6310   WHEN VALUE_ERROR THEN
6311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6312             trace
6313                (p_msg      => 'ERROR: '||sqlerrm
6314                ,p_level    => C_LEVEL_EXCEPTION
6315                ,p_module   => l_log_module);
6316      END IF;
6317      RAISE;
6318  WHEN xla_exceptions_pkg.application_exception THEN
6319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6320       trace
6321          (p_msg      => 'ERROR: '||sqlerrm
6322          ,p_level    => C_LEVEL_EXCEPTION
6323          ,p_module   => l_log_module);
6324       END IF;
6325       RAISE;
6326  WHEN OTHERS THEN
6327        xla_exceptions_pkg.raise_message
6328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_61');
6329 END Description_61;
6330 
6331 ---------------------------------------
6332 --
6333 -- PRIVATE FUNCTION
6334 --         Description_62
6335 --
6336 ---------------------------------------
6337 FUNCTION Description_62 (
6338   p_application_id      IN NUMBER
6339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6340 --Period Close Date
6341  , p_source_1            IN DATE
6342 )
6346 l_component_code        VARCHAR2(30)   ;
6343 RETURN VARCHAR2
6344 IS
6345 l_component_type        VARCHAR2(80)   ;
6347 l_component_type_code   VARCHAR2(1)    ;
6348 l_component_appl_id     INTEGER        ;
6349 l_amb_context_code      VARCHAR2(30)   ;
6350 l_ledger_language       VARCHAR2(30)   ;
6351 l_source                VARCHAR2(1996) ;
6352 l_description           VARCHAR2(2000) ;
6353 l_log_module            VARCHAR2(240)  ;
6354 BEGIN
6355 IF g_log_enabled THEN
6356       l_log_module := C_DEFAULT_MODULE||'.Description_62';
6357 END IF;
6358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6359       trace
6360          (p_msg      => 'BEGIN of Description_62'
6361          ,p_level    => C_LEVEL_PROCEDURE
6362          ,p_module   => l_log_module);
6363 END IF;
6364 
6365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6366 l_component_type        := 'AMB_DESCRIPTION';
6367 l_component_code        := 'FA_RECLASS';
6368 l_component_type_code   := 'S';
6369 l_component_appl_id     :=  140;
6370 l_amb_context_code      := 'DEFAULT';
6371 l_source                := NULL;
6372 l_description           := NULL;
6373 
6374 
6375  
6376  IF 
6377 l_ledger_language = 'US' THEN
6378     l_description :=  SUBSTR(CONCAT(l_description,'Category Reclass'),1,2000);
6379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6380  END IF;  
6381  IF 
6382 l_ledger_language = 'US' THEN
6383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6385  END IF;   
6386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6388   IF l_source IS NOT NULL THEN
6389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6391   END IF; 
6392  l_description := SUBSTR(l_description,1,1996);
6393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6394         trace
6395            (p_msg      => 'END of Description_62'
6396            ,p_level    => C_LEVEL_PROCEDURE
6397            ,p_module   => l_log_module);
6398 
6399   END IF;
6400   RETURN l_description;
6401 
6402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6403       trace
6404          (p_msg      => 'END of Description_62'
6405          ,p_level    => C_LEVEL_PROCEDURE
6406          ,p_module   => l_log_module);
6407 END IF;
6408 RETURN NULL;
6409 EXCEPTION
6410   WHEN VALUE_ERROR THEN
6411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6412             trace
6413                (p_msg      => 'ERROR: '||sqlerrm
6414                ,p_level    => C_LEVEL_EXCEPTION
6415                ,p_module   => l_log_module);
6416      END IF;
6417      RAISE;
6418  WHEN xla_exceptions_pkg.application_exception THEN
6419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6420       trace
6421          (p_msg      => 'ERROR: '||sqlerrm
6422          ,p_level    => C_LEVEL_EXCEPTION
6423          ,p_module   => l_log_module);
6424       END IF;
6425       RAISE;
6426  WHEN OTHERS THEN
6427        xla_exceptions_pkg.raise_message
6428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_62');
6429 END Description_62;
6430 
6431 ---------------------------------------
6432 --
6433 -- PRIVATE FUNCTION
6434 --         Description_63
6435 --
6436 ---------------------------------------
6437 FUNCTION Description_63 (
6438   p_application_id      IN NUMBER
6439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6440 --Period Close Date
6441  , p_source_1            IN DATE
6442 )
6443 RETURN VARCHAR2
6444 IS
6445 l_component_type        VARCHAR2(80)   ;
6446 l_component_code        VARCHAR2(30)   ;
6447 l_component_type_code   VARCHAR2(1)    ;
6448 l_component_appl_id     INTEGER        ;
6449 l_amb_context_code      VARCHAR2(30)   ;
6450 l_ledger_language       VARCHAR2(30)   ;
6451 l_source                VARCHAR2(1996) ;
6452 l_description           VARCHAR2(2000) ;
6453 l_log_module            VARCHAR2(240)  ;
6454 BEGIN
6455 IF g_log_enabled THEN
6456       l_log_module := C_DEFAULT_MODULE||'.Description_63';
6457 END IF;
6458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6459       trace
6460          (p_msg      => 'BEGIN of Description_63'
6461          ,p_level    => C_LEVEL_PROCEDURE
6462          ,p_module   => l_log_module);
6463 END IF;
6464 
6465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6466 l_component_type        := 'AMB_DESCRIPTION';
6467 l_component_code        := 'FA_RECLASS_BONUS_EXPENSE';
6468 l_component_type_code   := 'S';
6469 l_component_appl_id     :=  140;
6470 l_amb_context_code      := 'DEFAULT';
6471 l_source                := NULL;
6472 l_description           := NULL;
6473 
6474 
6475  
6476  IF 
6477 l_ledger_language = 'US' THEN
6478     l_description :=  SUBSTR(CONCAT(l_description,'Category Reclass Bonus Expense'),1,2000);
6479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6480  END IF;  
6481  IF 
6482 l_ledger_language = 'US' THEN
6483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6485  END IF;   
6486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6488   IF l_source IS NOT NULL THEN
6489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6491   END IF; 
6492  l_description := SUBSTR(l_description,1,1996);
6496            ,p_level    => C_LEVEL_PROCEDURE
6493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6494         trace
6495            (p_msg      => 'END of Description_63'
6497            ,p_module   => l_log_module);
6498 
6499   END IF;
6500   RETURN l_description;
6501 
6502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6503       trace
6504          (p_msg      => 'END of Description_63'
6505          ,p_level    => C_LEVEL_PROCEDURE
6506          ,p_module   => l_log_module);
6507 END IF;
6508 RETURN NULL;
6509 EXCEPTION
6510   WHEN VALUE_ERROR THEN
6511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6512             trace
6513                (p_msg      => 'ERROR: '||sqlerrm
6514                ,p_level    => C_LEVEL_EXCEPTION
6515                ,p_module   => l_log_module);
6516      END IF;
6517      RAISE;
6518  WHEN xla_exceptions_pkg.application_exception THEN
6519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6520       trace
6521          (p_msg      => 'ERROR: '||sqlerrm
6522          ,p_level    => C_LEVEL_EXCEPTION
6523          ,p_module   => l_log_module);
6524       END IF;
6525       RAISE;
6526  WHEN OTHERS THEN
6527        xla_exceptions_pkg.raise_message
6528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_63');
6529 END Description_63;
6530 
6531 ---------------------------------------
6532 --
6533 -- PRIVATE FUNCTION
6534 --         Description_64
6535 --
6536 ---------------------------------------
6537 FUNCTION Description_64 (
6538   p_application_id      IN NUMBER
6539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6540 --Period Close Date
6541  , p_source_1            IN DATE
6542 )
6543 RETURN VARCHAR2
6544 IS
6545 l_component_type        VARCHAR2(80)   ;
6546 l_component_code        VARCHAR2(30)   ;
6547 l_component_type_code   VARCHAR2(1)    ;
6548 l_component_appl_id     INTEGER        ;
6549 l_amb_context_code      VARCHAR2(30)   ;
6550 l_ledger_language       VARCHAR2(30)   ;
6551 l_source                VARCHAR2(1996) ;
6552 l_description           VARCHAR2(2000) ;
6553 l_log_module            VARCHAR2(240)  ;
6554 BEGIN
6555 IF g_log_enabled THEN
6556       l_log_module := C_DEFAULT_MODULE||'.Description_64';
6557 END IF;
6558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6559       trace
6560          (p_msg      => 'BEGIN of Description_64'
6561          ,p_level    => C_LEVEL_PROCEDURE
6562          ,p_module   => l_log_module);
6563 END IF;
6564 
6565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6566 l_component_type        := 'AMB_DESCRIPTION';
6567 l_component_code        := 'FA_RECLASS_BONUS_RESERVE';
6568 l_component_type_code   := 'S';
6569 l_component_appl_id     :=  140;
6570 l_amb_context_code      := 'DEFAULT';
6571 l_source                := NULL;
6572 l_description           := NULL;
6573 
6574 
6575  
6576  IF 
6577 l_ledger_language = 'US' THEN
6578     l_description :=  SUBSTR(CONCAT(l_description,'Category Reclass Bonus Reserve'),1,2000);
6579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6580  END IF;  
6581  IF 
6582 l_ledger_language = 'US' THEN
6583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6585  END IF;   
6586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6588   IF l_source IS NOT NULL THEN
6589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6591   END IF; 
6592  l_description := SUBSTR(l_description,1,1996);
6593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6594         trace
6595            (p_msg      => 'END of Description_64'
6596            ,p_level    => C_LEVEL_PROCEDURE
6597            ,p_module   => l_log_module);
6598 
6599   END IF;
6600   RETURN l_description;
6601 
6602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6603       trace
6604          (p_msg      => 'END of Description_64'
6605          ,p_level    => C_LEVEL_PROCEDURE
6606          ,p_module   => l_log_module);
6607 END IF;
6608 RETURN NULL;
6609 EXCEPTION
6610   WHEN VALUE_ERROR THEN
6611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6612             trace
6613                (p_msg      => 'ERROR: '||sqlerrm
6614                ,p_level    => C_LEVEL_EXCEPTION
6615                ,p_module   => l_log_module);
6616      END IF;
6617      RAISE;
6618  WHEN xla_exceptions_pkg.application_exception THEN
6619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6620       trace
6621          (p_msg      => 'ERROR: '||sqlerrm
6622          ,p_level    => C_LEVEL_EXCEPTION
6623          ,p_module   => l_log_module);
6624       END IF;
6625       RAISE;
6626  WHEN OTHERS THEN
6627        xla_exceptions_pkg.raise_message
6628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_64');
6629 END Description_64;
6630 
6631 ---------------------------------------
6632 --
6633 -- PRIVATE FUNCTION
6634 --         Description_65
6635 --
6636 ---------------------------------------
6637 FUNCTION Description_65 (
6638   p_application_id      IN NUMBER
6639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6640 --Period Close Date
6641  , p_source_1            IN DATE
6642 )
6643 RETURN VARCHAR2
6644 IS
6645 l_component_type        VARCHAR2(80)   ;
6646 l_component_code        VARCHAR2(30)   ;
6647 l_component_type_code   VARCHAR2(1)    ;
6648 l_component_appl_id     INTEGER        ;
6649 l_amb_context_code      VARCHAR2(30)   ;
6650 l_ledger_language       VARCHAR2(30)   ;
6654 BEGIN
6651 l_source                VARCHAR2(1996) ;
6652 l_description           VARCHAR2(2000) ;
6653 l_log_module            VARCHAR2(240)  ;
6655 IF g_log_enabled THEN
6656       l_log_module := C_DEFAULT_MODULE||'.Description_65';
6657 END IF;
6658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6659       trace
6660          (p_msg      => 'BEGIN of Description_65'
6661          ,p_level    => C_LEVEL_PROCEDURE
6662          ,p_module   => l_log_module);
6663 END IF;
6664 
6665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6666 l_component_type        := 'AMB_DESCRIPTION';
6667 l_component_code        := 'FA_RECLASS_COST';
6668 l_component_type_code   := 'S';
6669 l_component_appl_id     :=  140;
6670 l_amb_context_code      := 'DEFAULT';
6671 l_source                := NULL;
6672 l_description           := NULL;
6673 
6674 
6675  
6676  IF 
6677 l_ledger_language = 'US' THEN
6678     l_description :=  SUBSTR(CONCAT(l_description,'Category Reclass Cost'),1,2000);
6679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6680  END IF;  
6681  IF 
6682 l_ledger_language = 'US' THEN
6683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6685  END IF;   
6686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6688   IF l_source IS NOT NULL THEN
6689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6691   END IF; 
6692  l_description := SUBSTR(l_description,1,1996);
6693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6694         trace
6695            (p_msg      => 'END of Description_65'
6696            ,p_level    => C_LEVEL_PROCEDURE
6697            ,p_module   => l_log_module);
6698 
6699   END IF;
6700   RETURN l_description;
6701 
6702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6703       trace
6704          (p_msg      => 'END of Description_65'
6705          ,p_level    => C_LEVEL_PROCEDURE
6706          ,p_module   => l_log_module);
6707 END IF;
6708 RETURN NULL;
6709 EXCEPTION
6710   WHEN VALUE_ERROR THEN
6711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6712             trace
6713                (p_msg      => 'ERROR: '||sqlerrm
6714                ,p_level    => C_LEVEL_EXCEPTION
6715                ,p_module   => l_log_module);
6716      END IF;
6717      RAISE;
6718  WHEN xla_exceptions_pkg.application_exception THEN
6719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6720       trace
6721          (p_msg      => 'ERROR: '||sqlerrm
6722          ,p_level    => C_LEVEL_EXCEPTION
6723          ,p_module   => l_log_module);
6724       END IF;
6725       RAISE;
6726  WHEN OTHERS THEN
6727        xla_exceptions_pkg.raise_message
6728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_65');
6729 END Description_65;
6730 
6731 ---------------------------------------
6732 --
6733 -- PRIVATE FUNCTION
6734 --         Description_66
6735 --
6736 ---------------------------------------
6737 FUNCTION Description_66 (
6738   p_application_id      IN NUMBER
6739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6740 --Period Close Date
6741  , p_source_1            IN DATE
6742 )
6743 RETURN VARCHAR2
6744 IS
6745 l_component_type        VARCHAR2(80)   ;
6746 l_component_code        VARCHAR2(30)   ;
6747 l_component_type_code   VARCHAR2(1)    ;
6748 l_component_appl_id     INTEGER        ;
6749 l_amb_context_code      VARCHAR2(30)   ;
6750 l_ledger_language       VARCHAR2(30)   ;
6751 l_source                VARCHAR2(1996) ;
6752 l_description           VARCHAR2(2000) ;
6753 l_log_module            VARCHAR2(240)  ;
6754 BEGIN
6755 IF g_log_enabled THEN
6756       l_log_module := C_DEFAULT_MODULE||'.Description_66';
6757 END IF;
6758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6759       trace
6760          (p_msg      => 'BEGIN of Description_66'
6761          ,p_level    => C_LEVEL_PROCEDURE
6762          ,p_module   => l_log_module);
6763 END IF;
6764 
6765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6766 l_component_type        := 'AMB_DESCRIPTION';
6767 l_component_code        := 'FA_RECLASS_DEPRN_EXPENSE';
6768 l_component_type_code   := 'S';
6769 l_component_appl_id     :=  140;
6770 l_amb_context_code      := 'DEFAULT';
6771 l_source                := NULL;
6772 l_description           := NULL;
6773 
6774 
6775  
6776  IF 
6777 l_ledger_language = 'US' THEN
6778     l_description :=  SUBSTR(CONCAT(l_description,'Category Reclass Depreciation Expense'),1,2000);
6779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6780  END IF;  
6781  IF 
6782 l_ledger_language = 'US' THEN
6783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6785  END IF;   
6786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6788   IF l_source IS NOT NULL THEN
6789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6791   END IF; 
6792  l_description := SUBSTR(l_description,1,1996);
6793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6794         trace
6795            (p_msg      => 'END of Description_66'
6796            ,p_level    => C_LEVEL_PROCEDURE
6797            ,p_module   => l_log_module);
6798 
6799   END IF;
6800   RETURN l_description;
6801 
6805          ,p_level    => C_LEVEL_PROCEDURE
6802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6803       trace
6804          (p_msg      => 'END of Description_66'
6806          ,p_module   => l_log_module);
6807 END IF;
6808 RETURN NULL;
6809 EXCEPTION
6810   WHEN VALUE_ERROR THEN
6811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6812             trace
6813                (p_msg      => 'ERROR: '||sqlerrm
6814                ,p_level    => C_LEVEL_EXCEPTION
6815                ,p_module   => l_log_module);
6816      END IF;
6817      RAISE;
6818  WHEN xla_exceptions_pkg.application_exception THEN
6819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6820       trace
6821          (p_msg      => 'ERROR: '||sqlerrm
6822          ,p_level    => C_LEVEL_EXCEPTION
6823          ,p_module   => l_log_module);
6824       END IF;
6825       RAISE;
6826  WHEN OTHERS THEN
6827        xla_exceptions_pkg.raise_message
6828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_66');
6829 END Description_66;
6830 
6831 ---------------------------------------
6832 --
6833 -- PRIVATE FUNCTION
6834 --         Description_67
6835 --
6836 ---------------------------------------
6837 FUNCTION Description_67 (
6838   p_application_id      IN NUMBER
6839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6840 --Period Close Date
6841  , p_source_1            IN DATE
6842 )
6843 RETURN VARCHAR2
6844 IS
6845 l_component_type        VARCHAR2(80)   ;
6846 l_component_code        VARCHAR2(30)   ;
6847 l_component_type_code   VARCHAR2(1)    ;
6848 l_component_appl_id     INTEGER        ;
6849 l_amb_context_code      VARCHAR2(30)   ;
6850 l_ledger_language       VARCHAR2(30)   ;
6851 l_source                VARCHAR2(1996) ;
6852 l_description           VARCHAR2(2000) ;
6853 l_log_module            VARCHAR2(240)  ;
6854 BEGIN
6855 IF g_log_enabled THEN
6856       l_log_module := C_DEFAULT_MODULE||'.Description_67';
6857 END IF;
6858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6859       trace
6860          (p_msg      => 'BEGIN of Description_67'
6861          ,p_level    => C_LEVEL_PROCEDURE
6862          ,p_module   => l_log_module);
6863 END IF;
6864 
6865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6866 l_component_type        := 'AMB_DESCRIPTION';
6867 l_component_code        := 'FA_RECLASS_RESERVE';
6868 l_component_type_code   := 'S';
6869 l_component_appl_id     :=  140;
6870 l_amb_context_code      := 'DEFAULT';
6871 l_source                := NULL;
6872 l_description           := NULL;
6873 
6874 
6875  
6876  IF 
6877 l_ledger_language = 'US' THEN
6878     l_description :=  SUBSTR(CONCAT(l_description,'Category Reclass Depreciation Reserve'),1,2000);
6879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6880  END IF;  
6881  IF 
6882 l_ledger_language = 'US' THEN
6883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6885  END IF;   
6886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6888   IF l_source IS NOT NULL THEN
6889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6891   END IF; 
6892  l_description := SUBSTR(l_description,1,1996);
6893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6894         trace
6895            (p_msg      => 'END of Description_67'
6896            ,p_level    => C_LEVEL_PROCEDURE
6897            ,p_module   => l_log_module);
6898 
6899   END IF;
6900   RETURN l_description;
6901 
6902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6903       trace
6904          (p_msg      => 'END of Description_67'
6905          ,p_level    => C_LEVEL_PROCEDURE
6906          ,p_module   => l_log_module);
6907 END IF;
6908 RETURN NULL;
6909 EXCEPTION
6910   WHEN VALUE_ERROR THEN
6911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6912             trace
6913                (p_msg      => 'ERROR: '||sqlerrm
6914                ,p_level    => C_LEVEL_EXCEPTION
6915                ,p_module   => l_log_module);
6916      END IF;
6917      RAISE;
6918  WHEN xla_exceptions_pkg.application_exception THEN
6919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6920       trace
6921          (p_msg      => 'ERROR: '||sqlerrm
6922          ,p_level    => C_LEVEL_EXCEPTION
6923          ,p_module   => l_log_module);
6924       END IF;
6925       RAISE;
6926  WHEN OTHERS THEN
6927        xla_exceptions_pkg.raise_message
6928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_67');
6929 END Description_67;
6930 
6931 ---------------------------------------
6932 --
6933 -- PRIVATE FUNCTION
6934 --         Description_68
6935 --
6936 ---------------------------------------
6937 FUNCTION Description_68 (
6938   p_application_id      IN NUMBER
6939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
6940 --Period Close Date
6941  , p_source_1            IN DATE
6942 )
6943 RETURN VARCHAR2
6944 IS
6945 l_component_type        VARCHAR2(80)   ;
6946 l_component_code        VARCHAR2(30)   ;
6947 l_component_type_code   VARCHAR2(1)    ;
6948 l_component_appl_id     INTEGER        ;
6949 l_amb_context_code      VARCHAR2(30)   ;
6950 l_ledger_language       VARCHAR2(30)   ;
6951 l_source                VARCHAR2(1996) ;
6952 l_description           VARCHAR2(2000) ;
6953 l_log_module            VARCHAR2(240)  ;
6954 BEGIN
6955 IF g_log_enabled THEN
6956       l_log_module := C_DEFAULT_MODULE||'.Description_68';
6957 END IF;
6958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6962          ,p_module   => l_log_module);
6959       trace
6960          (p_msg      => 'BEGIN of Description_68'
6961          ,p_level    => C_LEVEL_PROCEDURE
6963 END IF;
6964 
6965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6966 l_component_type        := 'AMB_DESCRIPTION';
6967 l_component_code        := 'FA_RECLASS_REVAL_RESERVE';
6968 l_component_type_code   := 'S';
6969 l_component_appl_id     :=  140;
6970 l_amb_context_code      := 'DEFAULT';
6971 l_source                := NULL;
6972 l_description           := NULL;
6973 
6974 
6975  
6976  IF 
6977 l_ledger_language = 'US' THEN
6978     l_description :=  SUBSTR(CONCAT(l_description,'Category Reclass Revaluation Reserve'),1,2000);
6979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6980  END IF;  
6981  IF 
6982 l_ledger_language = 'US' THEN
6983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
6984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
6985  END IF;   
6986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
6987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
6988   IF l_source IS NOT NULL THEN
6989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
6990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
6991   END IF; 
6992  l_description := SUBSTR(l_description,1,1996);
6993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6994         trace
6995            (p_msg      => 'END of Description_68'
6996            ,p_level    => C_LEVEL_PROCEDURE
6997            ,p_module   => l_log_module);
6998 
6999   END IF;
7000   RETURN l_description;
7001 
7002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7003       trace
7004          (p_msg      => 'END of Description_68'
7005          ,p_level    => C_LEVEL_PROCEDURE
7006          ,p_module   => l_log_module);
7007 END IF;
7008 RETURN NULL;
7009 EXCEPTION
7010   WHEN VALUE_ERROR THEN
7011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7012             trace
7013                (p_msg      => 'ERROR: '||sqlerrm
7014                ,p_level    => C_LEVEL_EXCEPTION
7015                ,p_module   => l_log_module);
7016      END IF;
7017      RAISE;
7018  WHEN xla_exceptions_pkg.application_exception THEN
7019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7020       trace
7021          (p_msg      => 'ERROR: '||sqlerrm
7022          ,p_level    => C_LEVEL_EXCEPTION
7023          ,p_module   => l_log_module);
7024       END IF;
7025       RAISE;
7026  WHEN OTHERS THEN
7027        xla_exceptions_pkg.raise_message
7028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_68');
7029 END Description_68;
7030 
7031 ---------------------------------------
7032 --
7033 -- PRIVATE FUNCTION
7034 --         Description_69
7035 --
7036 ---------------------------------------
7037 FUNCTION Description_69 (
7038   p_application_id      IN NUMBER
7039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7040 --Period Close Date
7041  , p_source_1            IN DATE
7042 )
7043 RETURN VARCHAR2
7044 IS
7045 l_component_type        VARCHAR2(80)   ;
7046 l_component_code        VARCHAR2(30)   ;
7047 l_component_type_code   VARCHAR2(1)    ;
7048 l_component_appl_id     INTEGER        ;
7049 l_amb_context_code      VARCHAR2(30)   ;
7050 l_ledger_language       VARCHAR2(30)   ;
7051 l_source                VARCHAR2(1996) ;
7052 l_description           VARCHAR2(2000) ;
7053 l_log_module            VARCHAR2(240)  ;
7054 BEGIN
7055 IF g_log_enabled THEN
7056       l_log_module := C_DEFAULT_MODULE||'.Description_69';
7057 END IF;
7058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7059       trace
7060          (p_msg      => 'BEGIN of Description_69'
7061          ,p_level    => C_LEVEL_PROCEDURE
7062          ,p_module   => l_log_module);
7063 END IF;
7064 
7065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7066 l_component_type        := 'AMB_DESCRIPTION';
7067 l_component_code        := 'FA_REINSTATEMENT';
7068 l_component_type_code   := 'S';
7069 l_component_appl_id     :=  140;
7070 l_amb_context_code      := 'DEFAULT';
7071 l_source                := NULL;
7072 l_description           := NULL;
7073 
7074 
7075  
7076  IF 
7077 l_ledger_language = 'US' THEN
7078     l_description :=  SUBSTR(CONCAT(l_description,'Reinstatement'),1,2000);
7079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7080  END IF;  
7081  IF 
7082 l_ledger_language = 'US' THEN
7083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7085  END IF;   
7086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7088   IF l_source IS NOT NULL THEN
7089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7091   END IF; 
7092  l_description := SUBSTR(l_description,1,1996);
7093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7094         trace
7095            (p_msg      => 'END of Description_69'
7096            ,p_level    => C_LEVEL_PROCEDURE
7097            ,p_module   => l_log_module);
7098 
7099   END IF;
7100   RETURN l_description;
7101 
7102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7103       trace
7104          (p_msg      => 'END of Description_69'
7105          ,p_level    => C_LEVEL_PROCEDURE
7106          ,p_module   => l_log_module);
7107 END IF;
7108 RETURN NULL;
7109 EXCEPTION
7110   WHEN VALUE_ERROR THEN
7114                ,p_level    => C_LEVEL_EXCEPTION
7111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7112             trace
7113                (p_msg      => 'ERROR: '||sqlerrm
7115                ,p_module   => l_log_module);
7116      END IF;
7117      RAISE;
7118  WHEN xla_exceptions_pkg.application_exception THEN
7119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7120       trace
7121          (p_msg      => 'ERROR: '||sqlerrm
7122          ,p_level    => C_LEVEL_EXCEPTION
7123          ,p_module   => l_log_module);
7124       END IF;
7125       RAISE;
7126  WHEN OTHERS THEN
7127        xla_exceptions_pkg.raise_message
7128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_69');
7129 END Description_69;
7130 
7131 ---------------------------------------
7132 --
7133 -- PRIVATE FUNCTION
7134 --         Description_70
7135 --
7136 ---------------------------------------
7137 FUNCTION Description_70 (
7138   p_application_id      IN NUMBER
7139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7140 --Period Close Date
7141  , p_source_1            IN DATE
7142 )
7143 RETURN VARCHAR2
7144 IS
7145 l_component_type        VARCHAR2(80)   ;
7146 l_component_code        VARCHAR2(30)   ;
7147 l_component_type_code   VARCHAR2(1)    ;
7148 l_component_appl_id     INTEGER        ;
7149 l_amb_context_code      VARCHAR2(30)   ;
7150 l_ledger_language       VARCHAR2(30)   ;
7151 l_source                VARCHAR2(1996) ;
7152 l_description           VARCHAR2(2000) ;
7153 l_log_module            VARCHAR2(240)  ;
7154 BEGIN
7155 IF g_log_enabled THEN
7156       l_log_module := C_DEFAULT_MODULE||'.Description_70';
7157 END IF;
7158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7159       trace
7160          (p_msg      => 'BEGIN of Description_70'
7161          ,p_level    => C_LEVEL_PROCEDURE
7162          ,p_module   => l_log_module);
7163 END IF;
7164 
7165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7166 l_component_type        := 'AMB_DESCRIPTION';
7167 l_component_code        := 'FA_RESERVE_TRANSFER';
7168 l_component_type_code   := 'S';
7169 l_component_appl_id     :=  140;
7170 l_amb_context_code      := 'DEFAULT';
7171 l_source                := NULL;
7172 l_description           := NULL;
7173 
7174 
7175  
7176  IF 
7177 l_ledger_language = 'US' THEN
7178     l_description :=  SUBSTR(CONCAT(l_description,'Reserve Transfer'),1,2000);
7179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7180  END IF;  
7181  IF 
7182 l_ledger_language = 'US' THEN
7183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7185  END IF;   
7186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7188   IF l_source IS NOT NULL THEN
7189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7191   END IF; 
7192  l_description := SUBSTR(l_description,1,1996);
7193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7194         trace
7195            (p_msg      => 'END of Description_70'
7196            ,p_level    => C_LEVEL_PROCEDURE
7197            ,p_module   => l_log_module);
7198 
7199   END IF;
7200   RETURN l_description;
7201 
7202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7203       trace
7204          (p_msg      => 'END of Description_70'
7205          ,p_level    => C_LEVEL_PROCEDURE
7206          ,p_module   => l_log_module);
7207 END IF;
7208 RETURN NULL;
7209 EXCEPTION
7210   WHEN VALUE_ERROR THEN
7211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7212             trace
7213                (p_msg      => 'ERROR: '||sqlerrm
7214                ,p_level    => C_LEVEL_EXCEPTION
7215                ,p_module   => l_log_module);
7216      END IF;
7217      RAISE;
7218  WHEN xla_exceptions_pkg.application_exception THEN
7219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7220       trace
7221          (p_msg      => 'ERROR: '||sqlerrm
7222          ,p_level    => C_LEVEL_EXCEPTION
7223          ,p_module   => l_log_module);
7224       END IF;
7225       RAISE;
7226  WHEN OTHERS THEN
7227        xla_exceptions_pkg.raise_message
7228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_70');
7229 END Description_70;
7230 
7231 ---------------------------------------
7232 --
7233 -- PRIVATE FUNCTION
7234 --         Description_71
7235 --
7236 ---------------------------------------
7237 FUNCTION Description_71 (
7238   p_application_id      IN NUMBER
7239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7240 --Period Close Date
7241  , p_source_1            IN DATE
7242 )
7243 RETURN VARCHAR2
7244 IS
7245 l_component_type        VARCHAR2(80)   ;
7246 l_component_code        VARCHAR2(30)   ;
7247 l_component_type_code   VARCHAR2(1)    ;
7248 l_component_appl_id     INTEGER        ;
7249 l_amb_context_code      VARCHAR2(30)   ;
7250 l_ledger_language       VARCHAR2(30)   ;
7251 l_source                VARCHAR2(1996) ;
7252 l_description           VARCHAR2(2000) ;
7253 l_log_module            VARCHAR2(240)  ;
7254 BEGIN
7255 IF g_log_enabled THEN
7256       l_log_module := C_DEFAULT_MODULE||'.Description_71';
7257 END IF;
7258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7259       trace
7260          (p_msg      => 'BEGIN of Description_71'
7261          ,p_level    => C_LEVEL_PROCEDURE
7262          ,p_module   => l_log_module);
7263 END IF;
7264 
7265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7269 l_component_appl_id     :=  140;
7266 l_component_type        := 'AMB_DESCRIPTION';
7267 l_component_code        := 'FA_RES_IC_PAY';
7268 l_component_type_code   := 'S';
7270 l_amb_context_code      := 'DEFAULT';
7271 l_source                := NULL;
7272 l_description           := NULL;
7273 
7274 
7275  
7276  IF 
7277 l_ledger_language = 'US' THEN
7278     l_description :=  SUBSTR(CONCAT(l_description,'Reserve Transfer Intercompany Payables'),1,2000);
7279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7280  END IF;  
7281  IF 
7282 l_ledger_language = 'US' THEN
7283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7285  END IF;   
7286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7288   IF l_source IS NOT NULL THEN
7289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7291   END IF; 
7292  l_description := SUBSTR(l_description,1,1996);
7293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7294         trace
7295            (p_msg      => 'END of Description_71'
7296            ,p_level    => C_LEVEL_PROCEDURE
7297            ,p_module   => l_log_module);
7298 
7299   END IF;
7300   RETURN l_description;
7301 
7302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7303       trace
7304          (p_msg      => 'END of Description_71'
7305          ,p_level    => C_LEVEL_PROCEDURE
7306          ,p_module   => l_log_module);
7307 END IF;
7308 RETURN NULL;
7309 EXCEPTION
7310   WHEN VALUE_ERROR THEN
7311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7312             trace
7313                (p_msg      => 'ERROR: '||sqlerrm
7314                ,p_level    => C_LEVEL_EXCEPTION
7315                ,p_module   => l_log_module);
7316      END IF;
7317      RAISE;
7318  WHEN xla_exceptions_pkg.application_exception THEN
7319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7320       trace
7321          (p_msg      => 'ERROR: '||sqlerrm
7322          ,p_level    => C_LEVEL_EXCEPTION
7323          ,p_module   => l_log_module);
7324       END IF;
7325       RAISE;
7326  WHEN OTHERS THEN
7327        xla_exceptions_pkg.raise_message
7328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_71');
7329 END Description_71;
7330 
7331 ---------------------------------------
7332 --
7333 -- PRIVATE FUNCTION
7334 --         Description_72
7335 --
7336 ---------------------------------------
7337 FUNCTION Description_72 (
7338   p_application_id      IN NUMBER
7339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7340 --Period Close Date
7341  , p_source_1            IN DATE
7342 )
7343 RETURN VARCHAR2
7344 IS
7345 l_component_type        VARCHAR2(80)   ;
7346 l_component_code        VARCHAR2(30)   ;
7347 l_component_type_code   VARCHAR2(1)    ;
7348 l_component_appl_id     INTEGER        ;
7349 l_amb_context_code      VARCHAR2(30)   ;
7350 l_ledger_language       VARCHAR2(30)   ;
7351 l_source                VARCHAR2(1996) ;
7352 l_description           VARCHAR2(2000) ;
7353 l_log_module            VARCHAR2(240)  ;
7354 BEGIN
7355 IF g_log_enabled THEN
7356       l_log_module := C_DEFAULT_MODULE||'.Description_72';
7357 END IF;
7358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7359       trace
7360          (p_msg      => 'BEGIN of Description_72'
7361          ,p_level    => C_LEVEL_PROCEDURE
7362          ,p_module   => l_log_module);
7363 END IF;
7364 
7365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7366 l_component_type        := 'AMB_DESCRIPTION';
7367 l_component_code        := 'FA_RES_IC_REC';
7368 l_component_type_code   := 'S';
7369 l_component_appl_id     :=  140;
7370 l_amb_context_code      := 'DEFAULT';
7371 l_source                := NULL;
7372 l_description           := NULL;
7373 
7374 
7375  
7376  IF 
7377 l_ledger_language = 'US' THEN
7378     l_description :=  SUBSTR(CONCAT(l_description,'Reserve Transfer Intercompany Receivable'),1,2000);
7379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7380  END IF;  
7381  IF 
7382 l_ledger_language = 'US' THEN
7383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7385  END IF;   
7386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7388   IF l_source IS NOT NULL THEN
7389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7391   END IF; 
7392  l_description := SUBSTR(l_description,1,1996);
7393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7394         trace
7395            (p_msg      => 'END of Description_72'
7396            ,p_level    => C_LEVEL_PROCEDURE
7397            ,p_module   => l_log_module);
7398 
7399   END IF;
7400   RETURN l_description;
7401 
7402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7403       trace
7404          (p_msg      => 'END of Description_72'
7405          ,p_level    => C_LEVEL_PROCEDURE
7406          ,p_module   => l_log_module);
7407 END IF;
7408 RETURN NULL;
7409 EXCEPTION
7410   WHEN VALUE_ERROR THEN
7411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7412             trace
7413                (p_msg      => 'ERROR: '||sqlerrm
7414                ,p_level    => C_LEVEL_EXCEPTION
7415                ,p_module   => l_log_module);
7416      END IF;
7417      RAISE;
7421          (p_msg      => 'ERROR: '||sqlerrm
7418  WHEN xla_exceptions_pkg.application_exception THEN
7419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7420       trace
7422          ,p_level    => C_LEVEL_EXCEPTION
7423          ,p_module   => l_log_module);
7424       END IF;
7425       RAISE;
7426  WHEN OTHERS THEN
7427        xla_exceptions_pkg.raise_message
7428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_72');
7429 END Description_72;
7430 
7431 ---------------------------------------
7432 --
7433 -- PRIVATE FUNCTION
7434 --         Description_73
7435 --
7436 ---------------------------------------
7437 FUNCTION Description_73 (
7438   p_application_id      IN NUMBER
7439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7440 --Period Close Date
7441  , p_source_1            IN DATE
7442 )
7443 RETURN VARCHAR2
7444 IS
7445 l_component_type        VARCHAR2(80)   ;
7446 l_component_code        VARCHAR2(30)   ;
7447 l_component_type_code   VARCHAR2(1)    ;
7448 l_component_appl_id     INTEGER        ;
7449 l_amb_context_code      VARCHAR2(30)   ;
7450 l_ledger_language       VARCHAR2(30)   ;
7451 l_source                VARCHAR2(1996) ;
7452 l_description           VARCHAR2(2000) ;
7453 l_log_module            VARCHAR2(240)  ;
7454 BEGIN
7455 IF g_log_enabled THEN
7456       l_log_module := C_DEFAULT_MODULE||'.Description_73';
7457 END IF;
7458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7459       trace
7460          (p_msg      => 'BEGIN of Description_73'
7461          ,p_level    => C_LEVEL_PROCEDURE
7462          ,p_module   => l_log_module);
7463 END IF;
7464 
7465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7466 l_component_type        := 'AMB_DESCRIPTION';
7467 l_component_code        := 'FA_RES_TRF_RES';
7468 l_component_type_code   := 'S';
7469 l_component_appl_id     :=  140;
7470 l_amb_context_code      := 'DEFAULT';
7471 l_source                := NULL;
7472 l_description           := NULL;
7473 
7474 
7475  
7476  IF 
7477 l_ledger_language = 'US' THEN
7478     l_description :=  SUBSTR(CONCAT(l_description,'Reserve Transfer Reserve'),1,2000);
7479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7480  END IF;  
7481  IF 
7482 l_ledger_language = 'US' THEN
7483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7485  END IF;   
7486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7488   IF l_source IS NOT NULL THEN
7489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7491   END IF; 
7492  l_description := SUBSTR(l_description,1,1996);
7493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7494         trace
7495            (p_msg      => 'END of Description_73'
7496            ,p_level    => C_LEVEL_PROCEDURE
7497            ,p_module   => l_log_module);
7498 
7499   END IF;
7500   RETURN l_description;
7501 
7502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7503       trace
7504          (p_msg      => 'END of Description_73'
7505          ,p_level    => C_LEVEL_PROCEDURE
7506          ,p_module   => l_log_module);
7507 END IF;
7508 RETURN NULL;
7509 EXCEPTION
7510   WHEN VALUE_ERROR THEN
7511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7512             trace
7513                (p_msg      => 'ERROR: '||sqlerrm
7514                ,p_level    => C_LEVEL_EXCEPTION
7515                ,p_module   => l_log_module);
7516      END IF;
7517      RAISE;
7518  WHEN xla_exceptions_pkg.application_exception THEN
7519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7520       trace
7521          (p_msg      => 'ERROR: '||sqlerrm
7522          ,p_level    => C_LEVEL_EXCEPTION
7523          ,p_module   => l_log_module);
7524       END IF;
7525       RAISE;
7526  WHEN OTHERS THEN
7527        xla_exceptions_pkg.raise_message
7528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_73');
7529 END Description_73;
7530 
7531 ---------------------------------------
7532 --
7533 -- PRIVATE FUNCTION
7534 --         Description_74
7535 --
7536 ---------------------------------------
7537 FUNCTION Description_74 (
7538   p_application_id      IN NUMBER
7539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7540 --Period Close Date
7541  , p_source_1            IN DATE
7542 )
7543 RETURN VARCHAR2
7544 IS
7545 l_component_type        VARCHAR2(80)   ;
7546 l_component_code        VARCHAR2(30)   ;
7547 l_component_type_code   VARCHAR2(1)    ;
7548 l_component_appl_id     INTEGER        ;
7549 l_amb_context_code      VARCHAR2(30)   ;
7550 l_ledger_language       VARCHAR2(30)   ;
7551 l_source                VARCHAR2(1996) ;
7552 l_description           VARCHAR2(2000) ;
7553 l_log_module            VARCHAR2(240)  ;
7554 BEGIN
7555 IF g_log_enabled THEN
7556       l_log_module := C_DEFAULT_MODULE||'.Description_74';
7557 END IF;
7558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7559       trace
7560          (p_msg      => 'BEGIN of Description_74'
7561          ,p_level    => C_LEVEL_PROCEDURE
7562          ,p_module   => l_log_module);
7563 END IF;
7564 
7565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7566 l_component_type        := 'AMB_DESCRIPTION';
7567 l_component_code        := 'FA_RETIREMENT';
7568 l_component_type_code   := 'S';
7569 l_component_appl_id     :=  140;
7570 l_amb_context_code      := 'DEFAULT';
7571 l_source                := NULL;
7572 l_description           := NULL;
7573 
7577 l_ledger_language = 'US' THEN
7574 
7575  
7576  IF 
7578     l_description :=  SUBSTR(CONCAT(l_description,'Retirement'),1,2000);
7579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7580  END IF;  
7581  IF 
7582 l_ledger_language = 'US' THEN
7583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7585  END IF;   
7586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7588   IF l_source IS NOT NULL THEN
7589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7591   END IF; 
7592  l_description := SUBSTR(l_description,1,1996);
7593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7594         trace
7595            (p_msg      => 'END of Description_74'
7596            ,p_level    => C_LEVEL_PROCEDURE
7597            ,p_module   => l_log_module);
7598 
7599   END IF;
7600   RETURN l_description;
7601 
7602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7603       trace
7604          (p_msg      => 'END of Description_74'
7605          ,p_level    => C_LEVEL_PROCEDURE
7606          ,p_module   => l_log_module);
7607 END IF;
7608 RETURN NULL;
7609 EXCEPTION
7610   WHEN VALUE_ERROR THEN
7611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7612             trace
7613                (p_msg      => 'ERROR: '||sqlerrm
7614                ,p_level    => C_LEVEL_EXCEPTION
7615                ,p_module   => l_log_module);
7616      END IF;
7617      RAISE;
7618  WHEN xla_exceptions_pkg.application_exception THEN
7619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7620       trace
7621          (p_msg      => 'ERROR: '||sqlerrm
7622          ,p_level    => C_LEVEL_EXCEPTION
7623          ,p_module   => l_log_module);
7624       END IF;
7625       RAISE;
7626  WHEN OTHERS THEN
7627        xla_exceptions_pkg.raise_message
7628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_74');
7629 END Description_74;
7630 
7631 ---------------------------------------
7632 --
7633 -- PRIVATE FUNCTION
7634 --         Description_75
7635 --
7636 ---------------------------------------
7637 FUNCTION Description_75 (
7638   p_application_id      IN NUMBER
7639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7640 --Period Close Date
7641  , p_source_1            IN DATE
7642 )
7643 RETURN VARCHAR2
7644 IS
7645 l_component_type        VARCHAR2(80)   ;
7646 l_component_code        VARCHAR2(30)   ;
7647 l_component_type_code   VARCHAR2(1)    ;
7648 l_component_appl_id     INTEGER        ;
7649 l_amb_context_code      VARCHAR2(30)   ;
7650 l_ledger_language       VARCHAR2(30)   ;
7651 l_source                VARCHAR2(1996) ;
7652 l_description           VARCHAR2(2000) ;
7653 l_log_module            VARCHAR2(240)  ;
7654 BEGIN
7655 IF g_log_enabled THEN
7656       l_log_module := C_DEFAULT_MODULE||'.Description_75';
7657 END IF;
7658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7659       trace
7660          (p_msg      => 'BEGIN of Description_75'
7661          ,p_level    => C_LEVEL_PROCEDURE
7662          ,p_module   => l_log_module);
7663 END IF;
7664 
7665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7666 l_component_type        := 'AMB_DESCRIPTION';
7667 l_component_code        := 'FA_RETIREMENT_BONUS_EXP';
7668 l_component_type_code   := 'S';
7669 l_component_appl_id     :=  140;
7670 l_amb_context_code      := 'DEFAULT';
7671 l_source                := NULL;
7672 l_description           := NULL;
7673 
7674 
7675  
7676  IF 
7677 l_ledger_language = 'US' THEN
7678     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Bonus Depreciation Expense'),1,2000);
7679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7680  END IF;  
7681  IF 
7682 l_ledger_language = 'US' THEN
7683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7685  END IF;   
7686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7688   IF l_source IS NOT NULL THEN
7689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7691   END IF; 
7692  l_description := SUBSTR(l_description,1,1996);
7693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7694         trace
7695            (p_msg      => 'END of Description_75'
7696            ,p_level    => C_LEVEL_PROCEDURE
7697            ,p_module   => l_log_module);
7698 
7699   END IF;
7700   RETURN l_description;
7701 
7702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7703       trace
7704          (p_msg      => 'END of Description_75'
7705          ,p_level    => C_LEVEL_PROCEDURE
7706          ,p_module   => l_log_module);
7707 END IF;
7708 RETURN NULL;
7709 EXCEPTION
7710   WHEN VALUE_ERROR THEN
7711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7712             trace
7713                (p_msg      => 'ERROR: '||sqlerrm
7714                ,p_level    => C_LEVEL_EXCEPTION
7715                ,p_module   => l_log_module);
7716      END IF;
7717      RAISE;
7718  WHEN xla_exceptions_pkg.application_exception THEN
7719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7720       trace
7721          (p_msg      => 'ERROR: '||sqlerrm
7722          ,p_level    => C_LEVEL_EXCEPTION
7723          ,p_module   => l_log_module);
7724       END IF;
7725       RAISE;
7726  WHEN OTHERS THEN
7730 
7727        xla_exceptions_pkg.raise_message
7728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_75');
7729 END Description_75;
7731 ---------------------------------------
7732 --
7733 -- PRIVATE FUNCTION
7734 --         Description_76
7735 --
7736 ---------------------------------------
7737 FUNCTION Description_76 (
7738   p_application_id      IN NUMBER
7739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7740 --Period Close Date
7741  , p_source_1            IN DATE
7742 )
7743 RETURN VARCHAR2
7744 IS
7745 l_component_type        VARCHAR2(80)   ;
7746 l_component_code        VARCHAR2(30)   ;
7747 l_component_type_code   VARCHAR2(1)    ;
7748 l_component_appl_id     INTEGER        ;
7749 l_amb_context_code      VARCHAR2(30)   ;
7750 l_ledger_language       VARCHAR2(30)   ;
7751 l_source                VARCHAR2(1996) ;
7752 l_description           VARCHAR2(2000) ;
7753 l_log_module            VARCHAR2(240)  ;
7754 BEGIN
7755 IF g_log_enabled THEN
7756       l_log_module := C_DEFAULT_MODULE||'.Description_76';
7757 END IF;
7758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7759       trace
7760          (p_msg      => 'BEGIN of Description_76'
7761          ,p_level    => C_LEVEL_PROCEDURE
7762          ,p_module   => l_log_module);
7763 END IF;
7764 
7765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7766 l_component_type        := 'AMB_DESCRIPTION';
7767 l_component_code        := 'FA_RETIREMENT_BONUS_RESERVE';
7768 l_component_type_code   := 'S';
7769 l_component_appl_id     :=  140;
7770 l_amb_context_code      := 'DEFAULT';
7771 l_source                := NULL;
7772 l_description           := NULL;
7773 
7774 
7775  
7776  IF 
7777 l_ledger_language = 'US' THEN
7778     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Bonus Depreciation Reserve'),1,2000);
7779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7780  END IF;  
7781  IF 
7782 l_ledger_language = 'US' THEN
7783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7785  END IF;   
7786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7788   IF l_source IS NOT NULL THEN
7789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7791   END IF; 
7792  l_description := SUBSTR(l_description,1,1996);
7793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7794         trace
7795            (p_msg      => 'END of Description_76'
7796            ,p_level    => C_LEVEL_PROCEDURE
7797            ,p_module   => l_log_module);
7798 
7799   END IF;
7800   RETURN l_description;
7801 
7802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7803       trace
7804          (p_msg      => 'END of Description_76'
7805          ,p_level    => C_LEVEL_PROCEDURE
7806          ,p_module   => l_log_module);
7807 END IF;
7808 RETURN NULL;
7809 EXCEPTION
7810   WHEN VALUE_ERROR THEN
7811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7812             trace
7813                (p_msg      => 'ERROR: '||sqlerrm
7814                ,p_level    => C_LEVEL_EXCEPTION
7815                ,p_module   => l_log_module);
7816      END IF;
7817      RAISE;
7818  WHEN xla_exceptions_pkg.application_exception THEN
7819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7820       trace
7821          (p_msg      => 'ERROR: '||sqlerrm
7822          ,p_level    => C_LEVEL_EXCEPTION
7823          ,p_module   => l_log_module);
7824       END IF;
7825       RAISE;
7826  WHEN OTHERS THEN
7827        xla_exceptions_pkg.raise_message
7828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_76');
7829 END Description_76;
7830 
7831 ---------------------------------------
7832 --
7833 -- PRIVATE FUNCTION
7834 --         Description_77
7835 --
7836 ---------------------------------------
7837 FUNCTION Description_77 (
7838   p_application_id      IN NUMBER
7839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7840 --Period Close Date
7841  , p_source_1            IN DATE
7842 )
7843 RETURN VARCHAR2
7844 IS
7845 l_component_type        VARCHAR2(80)   ;
7846 l_component_code        VARCHAR2(30)   ;
7847 l_component_type_code   VARCHAR2(1)    ;
7848 l_component_appl_id     INTEGER        ;
7849 l_amb_context_code      VARCHAR2(30)   ;
7850 l_ledger_language       VARCHAR2(30)   ;
7851 l_source                VARCHAR2(1996) ;
7852 l_description           VARCHAR2(2000) ;
7853 l_log_module            VARCHAR2(240)  ;
7854 BEGIN
7855 IF g_log_enabled THEN
7856       l_log_module := C_DEFAULT_MODULE||'.Description_77';
7857 END IF;
7858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7859       trace
7860          (p_msg      => 'BEGIN of Description_77'
7861          ,p_level    => C_LEVEL_PROCEDURE
7862          ,p_module   => l_log_module);
7863 END IF;
7864 
7865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7866 l_component_type        := 'AMB_DESCRIPTION';
7867 l_component_code        := 'FA_RETIREMENT_COST';
7868 l_component_type_code   := 'S';
7869 l_component_appl_id     :=  140;
7870 l_amb_context_code      := 'DEFAULT';
7871 l_source                := NULL;
7872 l_description           := NULL;
7873 
7874 
7875  
7876  IF 
7877 l_ledger_language = 'US' THEN
7878     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Cost'),1,2000);
7879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7880  END IF;  
7881  IF 
7882 l_ledger_language = 'US' THEN
7886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7885  END IF;   
7887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7888   IF l_source IS NOT NULL THEN
7889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7891   END IF; 
7892  l_description := SUBSTR(l_description,1,1996);
7893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7894         trace
7895            (p_msg      => 'END of Description_77'
7896            ,p_level    => C_LEVEL_PROCEDURE
7897            ,p_module   => l_log_module);
7898 
7899   END IF;
7900   RETURN l_description;
7901 
7902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7903       trace
7904          (p_msg      => 'END of Description_77'
7905          ,p_level    => C_LEVEL_PROCEDURE
7906          ,p_module   => l_log_module);
7907 END IF;
7908 RETURN NULL;
7909 EXCEPTION
7910   WHEN VALUE_ERROR THEN
7911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7912             trace
7913                (p_msg      => 'ERROR: '||sqlerrm
7914                ,p_level    => C_LEVEL_EXCEPTION
7915                ,p_module   => l_log_module);
7916      END IF;
7917      RAISE;
7918  WHEN xla_exceptions_pkg.application_exception THEN
7919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7920       trace
7921          (p_msg      => 'ERROR: '||sqlerrm
7922          ,p_level    => C_LEVEL_EXCEPTION
7923          ,p_module   => l_log_module);
7924       END IF;
7925       RAISE;
7926  WHEN OTHERS THEN
7927        xla_exceptions_pkg.raise_message
7928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_77');
7929 END Description_77;
7930 
7931 ---------------------------------------
7932 --
7933 -- PRIVATE FUNCTION
7934 --         Description_78
7935 --
7936 ---------------------------------------
7937 FUNCTION Description_78 (
7938   p_application_id      IN NUMBER
7939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
7940 --Period Close Date
7941  , p_source_1            IN DATE
7942 )
7943 RETURN VARCHAR2
7944 IS
7945 l_component_type        VARCHAR2(80)   ;
7946 l_component_code        VARCHAR2(30)   ;
7947 l_component_type_code   VARCHAR2(1)    ;
7948 l_component_appl_id     INTEGER        ;
7949 l_amb_context_code      VARCHAR2(30)   ;
7950 l_ledger_language       VARCHAR2(30)   ;
7951 l_source                VARCHAR2(1996) ;
7952 l_description           VARCHAR2(2000) ;
7953 l_log_module            VARCHAR2(240)  ;
7954 BEGIN
7955 IF g_log_enabled THEN
7956       l_log_module := C_DEFAULT_MODULE||'.Description_78';
7957 END IF;
7958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7959       trace
7960          (p_msg      => 'BEGIN of Description_78'
7961          ,p_level    => C_LEVEL_PROCEDURE
7962          ,p_module   => l_log_module);
7963 END IF;
7964 
7965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
7966 l_component_type        := 'AMB_DESCRIPTION';
7967 l_component_code        := 'FA_RETIREMENT_COST_OF_REMOVAL';
7968 l_component_type_code   := 'S';
7969 l_component_appl_id     :=  140;
7970 l_amb_context_code      := 'DEFAULT';
7971 l_source                := NULL;
7972 l_description           := NULL;
7973 
7974 
7975  
7976  IF 
7977 l_ledger_language = 'US' THEN
7978     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Cost of Removal'),1,2000);
7979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7980  END IF;  
7981  IF 
7982 l_ledger_language = 'US' THEN
7983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
7984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
7985  END IF;   
7986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
7987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
7988   IF l_source IS NOT NULL THEN
7989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
7990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
7991   END IF; 
7992  l_description := SUBSTR(l_description,1,1996);
7993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7994         trace
7995            (p_msg      => 'END of Description_78'
7996            ,p_level    => C_LEVEL_PROCEDURE
7997            ,p_module   => l_log_module);
7998 
7999   END IF;
8000   RETURN l_description;
8001 
8002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8003       trace
8004          (p_msg      => 'END of Description_78'
8005          ,p_level    => C_LEVEL_PROCEDURE
8006          ,p_module   => l_log_module);
8007 END IF;
8008 RETURN NULL;
8009 EXCEPTION
8010   WHEN VALUE_ERROR THEN
8011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8012             trace
8013                (p_msg      => 'ERROR: '||sqlerrm
8014                ,p_level    => C_LEVEL_EXCEPTION
8015                ,p_module   => l_log_module);
8016      END IF;
8017      RAISE;
8018  WHEN xla_exceptions_pkg.application_exception THEN
8019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8020       trace
8021          (p_msg      => 'ERROR: '||sqlerrm
8022          ,p_level    => C_LEVEL_EXCEPTION
8023          ,p_module   => l_log_module);
8024       END IF;
8025       RAISE;
8026  WHEN OTHERS THEN
8027        xla_exceptions_pkg.raise_message
8028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_78');
8029 END Description_78;
8030 
8031 ---------------------------------------
8032 --
8033 -- PRIVATE FUNCTION
8034 --         Description_79
8035 --
8039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8036 ---------------------------------------
8037 FUNCTION Description_79 (
8038   p_application_id      IN NUMBER
8040 --Period Close Date
8041  , p_source_1            IN DATE
8042 )
8043 RETURN VARCHAR2
8044 IS
8045 l_component_type        VARCHAR2(80)   ;
8046 l_component_code        VARCHAR2(30)   ;
8047 l_component_type_code   VARCHAR2(1)    ;
8048 l_component_appl_id     INTEGER        ;
8049 l_amb_context_code      VARCHAR2(30)   ;
8050 l_ledger_language       VARCHAR2(30)   ;
8051 l_source                VARCHAR2(1996) ;
8052 l_description           VARCHAR2(2000) ;
8053 l_log_module            VARCHAR2(240)  ;
8054 BEGIN
8055 IF g_log_enabled THEN
8056       l_log_module := C_DEFAULT_MODULE||'.Description_79';
8057 END IF;
8058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8059       trace
8060          (p_msg      => 'BEGIN of Description_79'
8061          ,p_level    => C_LEVEL_PROCEDURE
8062          ,p_module   => l_log_module);
8063 END IF;
8064 
8065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8066 l_component_type        := 'AMB_DESCRIPTION';
8067 l_component_code        := 'FA_RETIREMENT_EXP';
8068 l_component_type_code   := 'S';
8069 l_component_appl_id     :=  140;
8070 l_amb_context_code      := 'DEFAULT';
8071 l_source                := NULL;
8072 l_description           := NULL;
8073 
8074 
8075  
8076  IF 
8077 l_ledger_language = 'US' THEN
8078     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Depreciation Expense'),1,2000);
8079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8080  END IF;  
8081  IF 
8082 l_ledger_language = 'US' THEN
8083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8085  END IF;   
8086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8088   IF l_source IS NOT NULL THEN
8089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8091   END IF; 
8092  l_description := SUBSTR(l_description,1,1996);
8093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8094         trace
8095            (p_msg      => 'END of Description_79'
8096            ,p_level    => C_LEVEL_PROCEDURE
8097            ,p_module   => l_log_module);
8098 
8099   END IF;
8100   RETURN l_description;
8101 
8102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8103       trace
8104          (p_msg      => 'END of Description_79'
8105          ,p_level    => C_LEVEL_PROCEDURE
8106          ,p_module   => l_log_module);
8107 END IF;
8108 RETURN NULL;
8109 EXCEPTION
8110   WHEN VALUE_ERROR THEN
8111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8112             trace
8113                (p_msg      => 'ERROR: '||sqlerrm
8114                ,p_level    => C_LEVEL_EXCEPTION
8115                ,p_module   => l_log_module);
8116      END IF;
8117      RAISE;
8118  WHEN xla_exceptions_pkg.application_exception THEN
8119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8120       trace
8121          (p_msg      => 'ERROR: '||sqlerrm
8122          ,p_level    => C_LEVEL_EXCEPTION
8123          ,p_module   => l_log_module);
8124       END IF;
8125       RAISE;
8126  WHEN OTHERS THEN
8127        xla_exceptions_pkg.raise_message
8128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_79');
8129 END Description_79;
8130 
8131 ---------------------------------------
8132 --
8133 -- PRIVATE FUNCTION
8134 --         Description_80
8135 --
8136 ---------------------------------------
8137 FUNCTION Description_80 (
8138   p_application_id      IN NUMBER
8139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8140 --Period Close Date
8141  , p_source_1            IN DATE
8142 )
8143 RETURN VARCHAR2
8144 IS
8145 l_component_type        VARCHAR2(80)   ;
8146 l_component_code        VARCHAR2(30)   ;
8147 l_component_type_code   VARCHAR2(1)    ;
8148 l_component_appl_id     INTEGER        ;
8149 l_amb_context_code      VARCHAR2(30)   ;
8150 l_ledger_language       VARCHAR2(30)   ;
8151 l_source                VARCHAR2(1996) ;
8152 l_description           VARCHAR2(2000) ;
8153 l_log_module            VARCHAR2(240)  ;
8154 BEGIN
8155 IF g_log_enabled THEN
8156       l_log_module := C_DEFAULT_MODULE||'.Description_80';
8157 END IF;
8158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8159       trace
8160          (p_msg      => 'BEGIN of Description_80'
8161          ,p_level    => C_LEVEL_PROCEDURE
8162          ,p_module   => l_log_module);
8163 END IF;
8164 
8165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8166 l_component_type        := 'AMB_DESCRIPTION';
8167 l_component_code        := 'FA_RETIREMENT_NBV_RETIRED';
8168 l_component_type_code   := 'S';
8169 l_component_appl_id     :=  140;
8170 l_amb_context_code      := 'DEFAULT';
8171 l_source                := NULL;
8172 l_description           := NULL;
8173 
8174 
8175  
8176  IF 
8177 l_ledger_language = 'US' THEN
8178     l_description :=  SUBSTR(CONCAT(l_description,'Retirement NBV Retired'),1,2000);
8179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8180  END IF;  
8181  IF 
8182 l_ledger_language = 'US' THEN
8183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8185  END IF;   
8186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8191   END IF; 
8188   IF l_source IS NOT NULL THEN
8189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8192  l_description := SUBSTR(l_description,1,1996);
8193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8194         trace
8195            (p_msg      => 'END of Description_80'
8196            ,p_level    => C_LEVEL_PROCEDURE
8197            ,p_module   => l_log_module);
8198 
8199   END IF;
8200   RETURN l_description;
8201 
8202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8203       trace
8204          (p_msg      => 'END of Description_80'
8205          ,p_level    => C_LEVEL_PROCEDURE
8206          ,p_module   => l_log_module);
8207 END IF;
8208 RETURN NULL;
8209 EXCEPTION
8210   WHEN VALUE_ERROR THEN
8211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8212             trace
8213                (p_msg      => 'ERROR: '||sqlerrm
8214                ,p_level    => C_LEVEL_EXCEPTION
8215                ,p_module   => l_log_module);
8216      END IF;
8217      RAISE;
8218  WHEN xla_exceptions_pkg.application_exception THEN
8219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8220       trace
8221          (p_msg      => 'ERROR: '||sqlerrm
8222          ,p_level    => C_LEVEL_EXCEPTION
8223          ,p_module   => l_log_module);
8224       END IF;
8225       RAISE;
8226  WHEN OTHERS THEN
8227        xla_exceptions_pkg.raise_message
8228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_80');
8229 END Description_80;
8230 
8231 ---------------------------------------
8232 --
8233 -- PRIVATE FUNCTION
8234 --         Description_81
8235 --
8236 ---------------------------------------
8237 FUNCTION Description_81 (
8238   p_application_id      IN NUMBER
8239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8240 --Period Close Date
8241  , p_source_1            IN DATE
8242 )
8243 RETURN VARCHAR2
8244 IS
8245 l_component_type        VARCHAR2(80)   ;
8246 l_component_code        VARCHAR2(30)   ;
8247 l_component_type_code   VARCHAR2(1)    ;
8248 l_component_appl_id     INTEGER        ;
8249 l_amb_context_code      VARCHAR2(30)   ;
8250 l_ledger_language       VARCHAR2(30)   ;
8251 l_source                VARCHAR2(1996) ;
8252 l_description           VARCHAR2(2000) ;
8253 l_log_module            VARCHAR2(240)  ;
8254 BEGIN
8255 IF g_log_enabled THEN
8256       l_log_module := C_DEFAULT_MODULE||'.Description_81';
8257 END IF;
8258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8259       trace
8260          (p_msg      => 'BEGIN of Description_81'
8261          ,p_level    => C_LEVEL_PROCEDURE
8262          ,p_module   => l_log_module);
8263 END IF;
8264 
8265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8266 l_component_type        := 'AMB_DESCRIPTION';
8267 l_component_code        := 'FA_RETIREMENT_PROC_OF_SALE';
8268 l_component_type_code   := 'S';
8269 l_component_appl_id     :=  140;
8270 l_amb_context_code      := 'DEFAULT';
8271 l_source                := NULL;
8272 l_description           := NULL;
8273 
8274 
8275  
8276  IF 
8277 l_ledger_language = 'US' THEN
8278     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Proceeds of Sale'),1,2000);
8279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8280  END IF;  
8281  IF 
8282 l_ledger_language = 'US' THEN
8283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8285  END IF;   
8286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8288   IF l_source IS NOT NULL THEN
8289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8291   END IF; 
8292  l_description := SUBSTR(l_description,1,1996);
8293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8294         trace
8295            (p_msg      => 'END of Description_81'
8296            ,p_level    => C_LEVEL_PROCEDURE
8297            ,p_module   => l_log_module);
8298 
8299   END IF;
8300   RETURN l_description;
8301 
8302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8303       trace
8304          (p_msg      => 'END of Description_81'
8305          ,p_level    => C_LEVEL_PROCEDURE
8306          ,p_module   => l_log_module);
8307 END IF;
8308 RETURN NULL;
8309 EXCEPTION
8310   WHEN VALUE_ERROR THEN
8311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8312             trace
8313                (p_msg      => 'ERROR: '||sqlerrm
8314                ,p_level    => C_LEVEL_EXCEPTION
8315                ,p_module   => l_log_module);
8316      END IF;
8317      RAISE;
8318  WHEN xla_exceptions_pkg.application_exception THEN
8319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8320       trace
8321          (p_msg      => 'ERROR: '||sqlerrm
8322          ,p_level    => C_LEVEL_EXCEPTION
8323          ,p_module   => l_log_module);
8324       END IF;
8325       RAISE;
8326  WHEN OTHERS THEN
8327        xla_exceptions_pkg.raise_message
8328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_81');
8329 END Description_81;
8330 
8331 ---------------------------------------
8332 --
8333 -- PRIVATE FUNCTION
8334 --         Description_82
8335 --
8336 ---------------------------------------
8337 FUNCTION Description_82 (
8338   p_application_id      IN NUMBER
8339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8340 --Period Close Date
8341  , p_source_1            IN DATE
8342 )
8343 RETURN VARCHAR2
8344 IS
8345 l_component_type        VARCHAR2(80)   ;
8349 l_amb_context_code      VARCHAR2(30)   ;
8346 l_component_code        VARCHAR2(30)   ;
8347 l_component_type_code   VARCHAR2(1)    ;
8348 l_component_appl_id     INTEGER        ;
8350 l_ledger_language       VARCHAR2(30)   ;
8351 l_source                VARCHAR2(1996) ;
8352 l_description           VARCHAR2(2000) ;
8353 l_log_module            VARCHAR2(240)  ;
8354 BEGIN
8355 IF g_log_enabled THEN
8356       l_log_module := C_DEFAULT_MODULE||'.Description_82';
8357 END IF;
8358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8359       trace
8360          (p_msg      => 'BEGIN of Description_82'
8361          ,p_level    => C_LEVEL_PROCEDURE
8362          ,p_module   => l_log_module);
8363 END IF;
8364 
8365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8366 l_component_type        := 'AMB_DESCRIPTION';
8367 l_component_code        := 'FA_RETIREMENT_RESERVE';
8368 l_component_type_code   := 'S';
8369 l_component_appl_id     :=  140;
8370 l_amb_context_code      := 'DEFAULT';
8371 l_source                := NULL;
8372 l_description           := NULL;
8373 
8374 
8375  
8376  IF 
8377 l_ledger_language = 'US' THEN
8378     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Depreciation Reserve'),1,2000);
8379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8380  END IF;  
8381  IF 
8382 l_ledger_language = 'US' THEN
8383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8385  END IF;   
8386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8388   IF l_source IS NOT NULL THEN
8389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8391   END IF; 
8392  l_description := SUBSTR(l_description,1,1996);
8393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8394         trace
8395            (p_msg      => 'END of Description_82'
8396            ,p_level    => C_LEVEL_PROCEDURE
8397            ,p_module   => l_log_module);
8398 
8399   END IF;
8400   RETURN l_description;
8401 
8402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8403       trace
8404          (p_msg      => 'END of Description_82'
8405          ,p_level    => C_LEVEL_PROCEDURE
8406          ,p_module   => l_log_module);
8407 END IF;
8408 RETURN NULL;
8409 EXCEPTION
8410   WHEN VALUE_ERROR THEN
8411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8412             trace
8413                (p_msg      => 'ERROR: '||sqlerrm
8414                ,p_level    => C_LEVEL_EXCEPTION
8415                ,p_module   => l_log_module);
8416      END IF;
8417      RAISE;
8418  WHEN xla_exceptions_pkg.application_exception THEN
8419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8420       trace
8421          (p_msg      => 'ERROR: '||sqlerrm
8422          ,p_level    => C_LEVEL_EXCEPTION
8423          ,p_module   => l_log_module);
8424       END IF;
8425       RAISE;
8426  WHEN OTHERS THEN
8427        xla_exceptions_pkg.raise_message
8428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_82');
8429 END Description_82;
8430 
8431 ---------------------------------------
8432 --
8433 -- PRIVATE FUNCTION
8434 --         Description_83
8435 --
8436 ---------------------------------------
8437 FUNCTION Description_83 (
8438   p_application_id      IN NUMBER
8439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8440 --Period Close Date
8441  , p_source_1            IN DATE
8442 )
8443 RETURN VARCHAR2
8444 IS
8445 l_component_type        VARCHAR2(80)   ;
8446 l_component_code        VARCHAR2(30)   ;
8447 l_component_type_code   VARCHAR2(1)    ;
8448 l_component_appl_id     INTEGER        ;
8449 l_amb_context_code      VARCHAR2(30)   ;
8450 l_ledger_language       VARCHAR2(30)   ;
8451 l_source                VARCHAR2(1996) ;
8452 l_description           VARCHAR2(2000) ;
8453 l_log_module            VARCHAR2(240)  ;
8454 BEGIN
8455 IF g_log_enabled THEN
8456       l_log_module := C_DEFAULT_MODULE||'.Description_83';
8457 END IF;
8458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8459       trace
8460          (p_msg      => 'BEGIN of Description_83'
8461          ,p_level    => C_LEVEL_PROCEDURE
8462          ,p_module   => l_log_module);
8463 END IF;
8464 
8465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8466 l_component_type        := 'AMB_DESCRIPTION';
8467 l_component_code        := 'FA_RETIREMENT_REVAL_RESERVE';
8468 l_component_type_code   := 'S';
8469 l_component_appl_id     :=  140;
8470 l_amb_context_code      := 'DEFAULT';
8471 l_source                := NULL;
8472 l_description           := NULL;
8473 
8474 
8475  
8476  IF 
8477 l_ledger_language = 'US' THEN
8478     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Revaluation Reserve'),1,2000);
8479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8480  END IF;  
8481  IF 
8482 l_ledger_language = 'US' THEN
8483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8485  END IF;   
8486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8488   IF l_source IS NOT NULL THEN
8489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8491   END IF; 
8492  l_description := SUBSTR(l_description,1,1996);
8493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8494         trace
8498 
8495            (p_msg      => 'END of Description_83'
8496            ,p_level    => C_LEVEL_PROCEDURE
8497            ,p_module   => l_log_module);
8499   END IF;
8500   RETURN l_description;
8501 
8502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8503       trace
8504          (p_msg      => 'END of Description_83'
8505          ,p_level    => C_LEVEL_PROCEDURE
8506          ,p_module   => l_log_module);
8507 END IF;
8508 RETURN NULL;
8509 EXCEPTION
8510   WHEN VALUE_ERROR THEN
8511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8512             trace
8513                (p_msg      => 'ERROR: '||sqlerrm
8514                ,p_level    => C_LEVEL_EXCEPTION
8515                ,p_module   => l_log_module);
8516      END IF;
8517      RAISE;
8518  WHEN xla_exceptions_pkg.application_exception THEN
8519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8520       trace
8521          (p_msg      => 'ERROR: '||sqlerrm
8522          ,p_level    => C_LEVEL_EXCEPTION
8523          ,p_module   => l_log_module);
8524       END IF;
8525       RAISE;
8526  WHEN OTHERS THEN
8527        xla_exceptions_pkg.raise_message
8528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_83');
8529 END Description_83;
8530 
8531 ---------------------------------------
8532 --
8533 -- PRIVATE FUNCTION
8534 --         Description_84
8535 --
8536 ---------------------------------------
8537 FUNCTION Description_84 (
8538   p_application_id      IN NUMBER
8539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8540 --Period Close Date
8541  , p_source_1            IN DATE
8542 )
8543 RETURN VARCHAR2
8544 IS
8545 l_component_type        VARCHAR2(80)   ;
8546 l_component_code        VARCHAR2(30)   ;
8547 l_component_type_code   VARCHAR2(1)    ;
8548 l_component_appl_id     INTEGER        ;
8549 l_amb_context_code      VARCHAR2(30)   ;
8550 l_ledger_language       VARCHAR2(30)   ;
8551 l_source                VARCHAR2(1996) ;
8552 l_description           VARCHAR2(2000) ;
8553 l_log_module            VARCHAR2(240)  ;
8554 BEGIN
8555 IF g_log_enabled THEN
8556       l_log_module := C_DEFAULT_MODULE||'.Description_84';
8557 END IF;
8558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8559       trace
8560          (p_msg      => 'BEGIN of Description_84'
8561          ,p_level    => C_LEVEL_PROCEDURE
8562          ,p_module   => l_log_module);
8563 END IF;
8564 
8565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8566 l_component_type        := 'AMB_DESCRIPTION';
8567 l_component_code        := 'FA_RET_ADJ';
8568 l_component_type_code   := 'S';
8569 l_component_appl_id     :=  140;
8570 l_amb_context_code      := 'DEFAULT';
8571 l_source                := NULL;
8572 l_description           := NULL;
8573 
8574 
8575  
8576  IF 
8577 l_ledger_language = 'US' THEN
8578     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Adjustment'),1,2000);
8579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8580  END IF;  
8581  IF 
8582 l_ledger_language = 'US' THEN
8583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8585  END IF;   
8586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8588   IF l_source IS NOT NULL THEN
8589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8591   END IF; 
8592  l_description := SUBSTR(l_description,1,1996);
8593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8594         trace
8595            (p_msg      => 'END of Description_84'
8596            ,p_level    => C_LEVEL_PROCEDURE
8597            ,p_module   => l_log_module);
8598 
8599   END IF;
8600   RETURN l_description;
8601 
8602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8603       trace
8604          (p_msg      => 'END of Description_84'
8605          ,p_level    => C_LEVEL_PROCEDURE
8606          ,p_module   => l_log_module);
8607 END IF;
8608 RETURN NULL;
8609 EXCEPTION
8610   WHEN VALUE_ERROR THEN
8611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8612             trace
8613                (p_msg      => 'ERROR: '||sqlerrm
8614                ,p_level    => C_LEVEL_EXCEPTION
8615                ,p_module   => l_log_module);
8616      END IF;
8617      RAISE;
8618  WHEN xla_exceptions_pkg.application_exception THEN
8619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8620       trace
8621          (p_msg      => 'ERROR: '||sqlerrm
8622          ,p_level    => C_LEVEL_EXCEPTION
8623          ,p_module   => l_log_module);
8624       END IF;
8625       RAISE;
8626  WHEN OTHERS THEN
8627        xla_exceptions_pkg.raise_message
8628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_84');
8629 END Description_84;
8630 
8631 ---------------------------------------
8632 --
8633 -- PRIVATE FUNCTION
8634 --         Description_85
8635 --
8636 ---------------------------------------
8637 FUNCTION Description_85 (
8638   p_application_id      IN NUMBER
8639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8640 --Period Close Date
8641  , p_source_1            IN DATE
8642 )
8643 RETURN VARCHAR2
8644 IS
8645 l_component_type        VARCHAR2(80)   ;
8646 l_component_code        VARCHAR2(30)   ;
8647 l_component_type_code   VARCHAR2(1)    ;
8648 l_component_appl_id     INTEGER        ;
8649 l_amb_context_code      VARCHAR2(30)   ;
8650 l_ledger_language       VARCHAR2(30)   ;
8651 l_source                VARCHAR2(1996) ;
8652 l_description           VARCHAR2(2000) ;
8656       l_log_module := C_DEFAULT_MODULE||'.Description_85';
8653 l_log_module            VARCHAR2(240)  ;
8654 BEGIN
8655 IF g_log_enabled THEN
8657 END IF;
8658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8659       trace
8660          (p_msg      => 'BEGIN of Description_85'
8661          ,p_level    => C_LEVEL_PROCEDURE
8662          ,p_module   => l_log_module);
8663 END IF;
8664 
8665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8666 l_component_type        := 'AMB_DESCRIPTION';
8667 l_component_code        := 'FA_RET_ADJ_COST_OF_REM_CLR';
8668 l_component_type_code   := 'S';
8669 l_component_appl_id     :=  140;
8670 l_amb_context_code      := 'DEFAULT';
8671 l_source                := NULL;
8672 l_description           := NULL;
8673 
8674 
8675  
8676  IF 
8677 l_ledger_language = 'US' THEN
8678     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Adjustment Cost of Removal Clearing'),1,2000);
8679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8680  END IF;  
8681  IF 
8682 l_ledger_language = 'US' THEN
8683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8685  END IF;   
8686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8688   IF l_source IS NOT NULL THEN
8689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8691   END IF; 
8692  l_description := SUBSTR(l_description,1,1996);
8693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8694         trace
8695            (p_msg      => 'END of Description_85'
8696            ,p_level    => C_LEVEL_PROCEDURE
8697            ,p_module   => l_log_module);
8698 
8699   END IF;
8700   RETURN l_description;
8701 
8702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8703       trace
8704          (p_msg      => 'END of Description_85'
8705          ,p_level    => C_LEVEL_PROCEDURE
8706          ,p_module   => l_log_module);
8707 END IF;
8708 RETURN NULL;
8709 EXCEPTION
8710   WHEN VALUE_ERROR THEN
8711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8712             trace
8713                (p_msg      => 'ERROR: '||sqlerrm
8714                ,p_level    => C_LEVEL_EXCEPTION
8715                ,p_module   => l_log_module);
8716      END IF;
8717      RAISE;
8718  WHEN xla_exceptions_pkg.application_exception THEN
8719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8720       trace
8721          (p_msg      => 'ERROR: '||sqlerrm
8722          ,p_level    => C_LEVEL_EXCEPTION
8723          ,p_module   => l_log_module);
8724       END IF;
8725       RAISE;
8726  WHEN OTHERS THEN
8727        xla_exceptions_pkg.raise_message
8728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_85');
8729 END Description_85;
8730 
8731 ---------------------------------------
8732 --
8733 -- PRIVATE FUNCTION
8734 --         Description_86
8735 --
8736 ---------------------------------------
8737 FUNCTION Description_86 (
8738   p_application_id      IN NUMBER
8739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8740 --Period Close Date
8741  , p_source_1            IN DATE
8742 )
8743 RETURN VARCHAR2
8744 IS
8745 l_component_type        VARCHAR2(80)   ;
8746 l_component_code        VARCHAR2(30)   ;
8747 l_component_type_code   VARCHAR2(1)    ;
8748 l_component_appl_id     INTEGER        ;
8749 l_amb_context_code      VARCHAR2(30)   ;
8750 l_ledger_language       VARCHAR2(30)   ;
8751 l_source                VARCHAR2(1996) ;
8752 l_description           VARCHAR2(2000) ;
8753 l_log_module            VARCHAR2(240)  ;
8754 BEGIN
8755 IF g_log_enabled THEN
8756       l_log_module := C_DEFAULT_MODULE||'.Description_86';
8757 END IF;
8758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8759       trace
8760          (p_msg      => 'BEGIN of Description_86'
8761          ,p_level    => C_LEVEL_PROCEDURE
8762          ,p_module   => l_log_module);
8763 END IF;
8764 
8765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8766 l_component_type        := 'AMB_DESCRIPTION';
8767 l_component_code        := 'FA_RET_ADJ_RES';
8768 l_component_type_code   := 'S';
8769 l_component_appl_id     :=  140;
8770 l_amb_context_code      := 'DEFAULT';
8771 l_source                := NULL;
8772 l_description           := NULL;
8773 
8774 
8775  
8776  IF 
8777 l_ledger_language = 'US' THEN
8778     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Adjustment Reserve'),1,2000);
8779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8780  END IF;  
8781  IF 
8782 l_ledger_language = 'US' THEN
8783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8785  END IF;   
8786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8788   IF l_source IS NOT NULL THEN
8789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8791   END IF; 
8792  l_description := SUBSTR(l_description,1,1996);
8793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8794         trace
8795            (p_msg      => 'END of Description_86'
8796            ,p_level    => C_LEVEL_PROCEDURE
8797            ,p_module   => l_log_module);
8798 
8799   END IF;
8800   RETURN l_description;
8801 
8802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8803       trace
8807 END IF;
8804          (p_msg      => 'END of Description_86'
8805          ,p_level    => C_LEVEL_PROCEDURE
8806          ,p_module   => l_log_module);
8808 RETURN NULL;
8809 EXCEPTION
8810   WHEN VALUE_ERROR THEN
8811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8812             trace
8813                (p_msg      => 'ERROR: '||sqlerrm
8814                ,p_level    => C_LEVEL_EXCEPTION
8815                ,p_module   => l_log_module);
8816      END IF;
8817      RAISE;
8818  WHEN xla_exceptions_pkg.application_exception THEN
8819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8820       trace
8821          (p_msg      => 'ERROR: '||sqlerrm
8822          ,p_level    => C_LEVEL_EXCEPTION
8823          ,p_module   => l_log_module);
8824       END IF;
8825       RAISE;
8826  WHEN OTHERS THEN
8827        xla_exceptions_pkg.raise_message
8828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_86');
8829 END Description_86;
8830 
8831 ---------------------------------------
8832 --
8833 -- PRIVATE FUNCTION
8834 --         Description_87
8835 --
8836 ---------------------------------------
8837 FUNCTION Description_87 (
8838   p_application_id      IN NUMBER
8839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8840 --Period Close Date
8841  , p_source_1            IN DATE
8842 )
8843 RETURN VARCHAR2
8844 IS
8845 l_component_type        VARCHAR2(80)   ;
8846 l_component_code        VARCHAR2(30)   ;
8847 l_component_type_code   VARCHAR2(1)    ;
8848 l_component_appl_id     INTEGER        ;
8849 l_amb_context_code      VARCHAR2(30)   ;
8850 l_ledger_language       VARCHAR2(30)   ;
8851 l_source                VARCHAR2(1996) ;
8852 l_description           VARCHAR2(2000) ;
8853 l_log_module            VARCHAR2(240)  ;
8854 BEGIN
8855 IF g_log_enabled THEN
8856       l_log_module := C_DEFAULT_MODULE||'.Description_87';
8857 END IF;
8858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8859       trace
8860          (p_msg      => 'BEGIN of Description_87'
8861          ,p_level    => C_LEVEL_PROCEDURE
8862          ,p_module   => l_log_module);
8863 END IF;
8864 
8865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8866 l_component_type        := 'AMB_DESCRIPTION';
8867 l_component_code        := 'FA_RET_COST_OF_REMOVAL_CLR';
8868 l_component_type_code   := 'S';
8869 l_component_appl_id     :=  140;
8870 l_amb_context_code      := 'DEFAULT';
8871 l_source                := NULL;
8872 l_description           := NULL;
8873 
8874 
8875  
8876  IF 
8877 l_ledger_language = 'US' THEN
8878     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Cost of Removal Clearing'),1,2000);
8879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8880  END IF;  
8881  IF 
8882 l_ledger_language = 'US' THEN
8883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8885  END IF;   
8886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8888   IF l_source IS NOT NULL THEN
8889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8891   END IF; 
8892  l_description := SUBSTR(l_description,1,1996);
8893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8894         trace
8895            (p_msg      => 'END of Description_87'
8896            ,p_level    => C_LEVEL_PROCEDURE
8897            ,p_module   => l_log_module);
8898 
8899   END IF;
8900   RETURN l_description;
8901 
8902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8903       trace
8904          (p_msg      => 'END of Description_87'
8905          ,p_level    => C_LEVEL_PROCEDURE
8906          ,p_module   => l_log_module);
8907 END IF;
8908 RETURN NULL;
8909 EXCEPTION
8910   WHEN VALUE_ERROR THEN
8911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8912             trace
8913                (p_msg      => 'ERROR: '||sqlerrm
8914                ,p_level    => C_LEVEL_EXCEPTION
8915                ,p_module   => l_log_module);
8916      END IF;
8917      RAISE;
8918  WHEN xla_exceptions_pkg.application_exception THEN
8919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8920       trace
8921          (p_msg      => 'ERROR: '||sqlerrm
8922          ,p_level    => C_LEVEL_EXCEPTION
8923          ,p_module   => l_log_module);
8924       END IF;
8925       RAISE;
8926  WHEN OTHERS THEN
8927        xla_exceptions_pkg.raise_message
8928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_87');
8929 END Description_87;
8930 
8931 ---------------------------------------
8932 --
8933 -- PRIVATE FUNCTION
8934 --         Description_88
8935 --
8936 ---------------------------------------
8937 FUNCTION Description_88 (
8938   p_application_id      IN NUMBER
8939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
8940 --Period Close Date
8941  , p_source_1            IN DATE
8942 )
8943 RETURN VARCHAR2
8944 IS
8945 l_component_type        VARCHAR2(80)   ;
8946 l_component_code        VARCHAR2(30)   ;
8947 l_component_type_code   VARCHAR2(1)    ;
8948 l_component_appl_id     INTEGER        ;
8949 l_amb_context_code      VARCHAR2(30)   ;
8950 l_ledger_language       VARCHAR2(30)   ;
8951 l_source                VARCHAR2(1996) ;
8952 l_description           VARCHAR2(2000) ;
8953 l_log_module            VARCHAR2(240)  ;
8954 BEGIN
8955 IF g_log_enabled THEN
8956       l_log_module := C_DEFAULT_MODULE||'.Description_88';
8957 END IF;
8958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8959       trace
8963 END IF;
8960          (p_msg      => 'BEGIN of Description_88'
8961          ,p_level    => C_LEVEL_PROCEDURE
8962          ,p_module   => l_log_module);
8964 
8965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
8966 l_component_type        := 'AMB_DESCRIPTION';
8967 l_component_code        := 'FA_RET_PROC_OF_SALE_CLEAR';
8968 l_component_type_code   := 'S';
8969 l_component_appl_id     :=  140;
8970 l_amb_context_code      := 'DEFAULT';
8971 l_source                := NULL;
8972 l_description           := NULL;
8973 
8974 
8975  
8976  IF 
8977 l_ledger_language = 'US' THEN
8978     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Proceeds of Sale Clearing'),1,2000);
8979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8980  END IF;  
8981  IF 
8982 l_ledger_language = 'US' THEN
8983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
8984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
8985  END IF;   
8986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
8987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
8988   IF l_source IS NOT NULL THEN
8989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
8990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
8991   END IF; 
8992  l_description := SUBSTR(l_description,1,1996);
8993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8994         trace
8995            (p_msg      => 'END of Description_88'
8996            ,p_level    => C_LEVEL_PROCEDURE
8997            ,p_module   => l_log_module);
8998 
8999   END IF;
9000   RETURN l_description;
9001 
9002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9003       trace
9004          (p_msg      => 'END of Description_88'
9005          ,p_level    => C_LEVEL_PROCEDURE
9006          ,p_module   => l_log_module);
9007 END IF;
9008 RETURN NULL;
9009 EXCEPTION
9010   WHEN VALUE_ERROR THEN
9011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9012             trace
9013                (p_msg      => 'ERROR: '||sqlerrm
9014                ,p_level    => C_LEVEL_EXCEPTION
9015                ,p_module   => l_log_module);
9016      END IF;
9017      RAISE;
9018  WHEN xla_exceptions_pkg.application_exception THEN
9019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9020       trace
9021          (p_msg      => 'ERROR: '||sqlerrm
9022          ,p_level    => C_LEVEL_EXCEPTION
9023          ,p_module   => l_log_module);
9024       END IF;
9025       RAISE;
9026  WHEN OTHERS THEN
9027        xla_exceptions_pkg.raise_message
9028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_88');
9029 END Description_88;
9030 
9031 ---------------------------------------
9032 --
9033 -- PRIVATE FUNCTION
9034 --         Description_89
9035 --
9036 ---------------------------------------
9037 FUNCTION Description_89 (
9038   p_application_id      IN NUMBER
9039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9040 --Period Close Date
9041  , p_source_1            IN DATE
9042 )
9043 RETURN VARCHAR2
9044 IS
9045 l_component_type        VARCHAR2(80)   ;
9046 l_component_code        VARCHAR2(30)   ;
9047 l_component_type_code   VARCHAR2(1)    ;
9048 l_component_appl_id     INTEGER        ;
9049 l_amb_context_code      VARCHAR2(30)   ;
9050 l_ledger_language       VARCHAR2(30)   ;
9051 l_source                VARCHAR2(1996) ;
9052 l_description           VARCHAR2(2000) ;
9053 l_log_module            VARCHAR2(240)  ;
9054 BEGIN
9055 IF g_log_enabled THEN
9056       l_log_module := C_DEFAULT_MODULE||'.Description_89';
9057 END IF;
9058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9059       trace
9060          (p_msg      => 'BEGIN of Description_89'
9061          ,p_level    => C_LEVEL_PROCEDURE
9062          ,p_module   => l_log_module);
9063 END IF;
9064 
9065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9066 l_component_type        := 'AMB_DESCRIPTION';
9067 l_component_code        := 'FA_RET_REVAL_RESERVE_RETIRED';
9068 l_component_type_code   := 'S';
9069 l_component_appl_id     :=  140;
9070 l_amb_context_code      := 'DEFAULT';
9071 l_source                := NULL;
9072 l_description           := NULL;
9073 
9074 
9075  
9076  IF 
9077 l_ledger_language = 'US' THEN
9078     l_description :=  SUBSTR(CONCAT(l_description,'Retirement Revaluation Reserve Retired'),1,2000);
9079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9080  END IF;  
9081  IF 
9082 l_ledger_language = 'US' THEN
9083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9085  END IF;   
9086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9088   IF l_source IS NOT NULL THEN
9089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9091   END IF; 
9092  l_description := SUBSTR(l_description,1,1996);
9093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9094         trace
9095            (p_msg      => 'END of Description_89'
9096            ,p_level    => C_LEVEL_PROCEDURE
9097            ,p_module   => l_log_module);
9098 
9099   END IF;
9100   RETURN l_description;
9101 
9102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9103       trace
9104          (p_msg      => 'END of Description_89'
9105          ,p_level    => C_LEVEL_PROCEDURE
9106          ,p_module   => l_log_module);
9107 END IF;
9108 RETURN NULL;
9109 EXCEPTION
9110   WHEN VALUE_ERROR THEN
9114                ,p_level    => C_LEVEL_EXCEPTION
9111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9112             trace
9113                (p_msg      => 'ERROR: '||sqlerrm
9115                ,p_module   => l_log_module);
9116      END IF;
9117      RAISE;
9118  WHEN xla_exceptions_pkg.application_exception THEN
9119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9120       trace
9121          (p_msg      => 'ERROR: '||sqlerrm
9122          ,p_level    => C_LEVEL_EXCEPTION
9123          ,p_module   => l_log_module);
9124       END IF;
9125       RAISE;
9126  WHEN OTHERS THEN
9127        xla_exceptions_pkg.raise_message
9128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_89');
9129 END Description_89;
9130 
9131 ---------------------------------------
9132 --
9133 -- PRIVATE FUNCTION
9134 --         Description_90
9135 --
9136 ---------------------------------------
9137 FUNCTION Description_90 (
9138   p_application_id      IN NUMBER
9139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9140 --Period Close Date
9141  , p_source_1            IN DATE
9142 )
9143 RETURN VARCHAR2
9144 IS
9145 l_component_type        VARCHAR2(80)   ;
9146 l_component_code        VARCHAR2(30)   ;
9147 l_component_type_code   VARCHAR2(1)    ;
9148 l_component_appl_id     INTEGER        ;
9149 l_amb_context_code      VARCHAR2(30)   ;
9150 l_ledger_language       VARCHAR2(30)   ;
9151 l_source                VARCHAR2(1996) ;
9152 l_description           VARCHAR2(2000) ;
9153 l_log_module            VARCHAR2(240)  ;
9154 BEGIN
9155 IF g_log_enabled THEN
9156       l_log_module := C_DEFAULT_MODULE||'.Description_90';
9157 END IF;
9158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9159       trace
9160          (p_msg      => 'BEGIN of Description_90'
9161          ,p_level    => C_LEVEL_PROCEDURE
9162          ,p_module   => l_log_module);
9163 END IF;
9164 
9165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9166 l_component_type        := 'AMB_DESCRIPTION';
9167 l_component_code        := 'FA_REVALUATION';
9168 l_component_type_code   := 'S';
9169 l_component_appl_id     :=  140;
9170 l_amb_context_code      := 'DEFAULT';
9171 l_source                := NULL;
9172 l_description           := NULL;
9173 
9174 
9175  
9176  IF 
9177 l_ledger_language = 'US' THEN
9178     l_description :=  SUBSTR(CONCAT(l_description,'Revaluation'),1,2000);
9179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9180  END IF;  
9181  IF 
9182 l_ledger_language = 'US' THEN
9183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9185  END IF;   
9186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9188   IF l_source IS NOT NULL THEN
9189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9191   END IF; 
9192  l_description := SUBSTR(l_description,1,1996);
9193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9194         trace
9195            (p_msg      => 'END of Description_90'
9196            ,p_level    => C_LEVEL_PROCEDURE
9197            ,p_module   => l_log_module);
9198 
9199   END IF;
9200   RETURN l_description;
9201 
9202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9203       trace
9204          (p_msg      => 'END of Description_90'
9205          ,p_level    => C_LEVEL_PROCEDURE
9206          ,p_module   => l_log_module);
9207 END IF;
9208 RETURN NULL;
9209 EXCEPTION
9210   WHEN VALUE_ERROR THEN
9211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9212             trace
9213                (p_msg      => 'ERROR: '||sqlerrm
9214                ,p_level    => C_LEVEL_EXCEPTION
9215                ,p_module   => l_log_module);
9216      END IF;
9217      RAISE;
9218  WHEN xla_exceptions_pkg.application_exception THEN
9219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9220       trace
9221          (p_msg      => 'ERROR: '||sqlerrm
9222          ,p_level    => C_LEVEL_EXCEPTION
9223          ,p_module   => l_log_module);
9224       END IF;
9225       RAISE;
9226  WHEN OTHERS THEN
9227        xla_exceptions_pkg.raise_message
9228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_90');
9229 END Description_90;
9230 
9231 ---------------------------------------
9232 --
9233 -- PRIVATE FUNCTION
9234 --         Description_91
9235 --
9236 ---------------------------------------
9237 FUNCTION Description_91 (
9238   p_application_id      IN NUMBER
9239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9240 --Period Close Date
9241  , p_source_1            IN DATE
9242 )
9243 RETURN VARCHAR2
9244 IS
9245 l_component_type        VARCHAR2(80)   ;
9246 l_component_code        VARCHAR2(30)   ;
9247 l_component_type_code   VARCHAR2(1)    ;
9248 l_component_appl_id     INTEGER        ;
9249 l_amb_context_code      VARCHAR2(30)   ;
9250 l_ledger_language       VARCHAR2(30)   ;
9251 l_source                VARCHAR2(1996) ;
9252 l_description           VARCHAR2(2000) ;
9253 l_log_module            VARCHAR2(240)  ;
9254 BEGIN
9255 IF g_log_enabled THEN
9256       l_log_module := C_DEFAULT_MODULE||'.Description_91';
9257 END IF;
9258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9259       trace
9260          (p_msg      => 'BEGIN of Description_91'
9261          ,p_level    => C_LEVEL_PROCEDURE
9262          ,p_module   => l_log_module);
9263 END IF;
9264 
9265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9269 l_component_appl_id     :=  140;
9266 l_component_type        := 'AMB_DESCRIPTION';
9267 l_component_code        := 'FA_REVAL_BONUS_EXPENSE';
9268 l_component_type_code   := 'S';
9270 l_amb_context_code      := 'DEFAULT';
9271 l_source                := NULL;
9272 l_description           := NULL;
9273 
9274 
9275  
9276  IF 
9277 l_ledger_language = 'US' THEN
9278     l_description :=  SUBSTR(CONCAT(l_description,'Description for Revaluation Bonus Expense'),1,2000);
9279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9280  END IF;  
9281  IF 
9282 l_ledger_language = 'US' THEN
9283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9285  END IF;   
9286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9288   IF l_source IS NOT NULL THEN
9289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9291   END IF; 
9292  l_description := SUBSTR(l_description,1,1996);
9293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9294         trace
9295            (p_msg      => 'END of Description_91'
9296            ,p_level    => C_LEVEL_PROCEDURE
9297            ,p_module   => l_log_module);
9298 
9299   END IF;
9300   RETURN l_description;
9301 
9302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9303       trace
9304          (p_msg      => 'END of Description_91'
9305          ,p_level    => C_LEVEL_PROCEDURE
9306          ,p_module   => l_log_module);
9307 END IF;
9308 RETURN NULL;
9309 EXCEPTION
9310   WHEN VALUE_ERROR THEN
9311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9312             trace
9313                (p_msg      => 'ERROR: '||sqlerrm
9314                ,p_level    => C_LEVEL_EXCEPTION
9315                ,p_module   => l_log_module);
9316      END IF;
9317      RAISE;
9318  WHEN xla_exceptions_pkg.application_exception THEN
9319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9320       trace
9321          (p_msg      => 'ERROR: '||sqlerrm
9322          ,p_level    => C_LEVEL_EXCEPTION
9323          ,p_module   => l_log_module);
9324       END IF;
9325       RAISE;
9326  WHEN OTHERS THEN
9327        xla_exceptions_pkg.raise_message
9328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_91');
9329 END Description_91;
9330 
9331 ---------------------------------------
9332 --
9333 -- PRIVATE FUNCTION
9334 --         Description_92
9335 --
9336 ---------------------------------------
9337 FUNCTION Description_92 (
9338   p_application_id      IN NUMBER
9339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9340 --Period Close Date
9341  , p_source_1            IN DATE
9342 )
9343 RETURN VARCHAR2
9344 IS
9345 l_component_type        VARCHAR2(80)   ;
9346 l_component_code        VARCHAR2(30)   ;
9347 l_component_type_code   VARCHAR2(1)    ;
9348 l_component_appl_id     INTEGER        ;
9349 l_amb_context_code      VARCHAR2(30)   ;
9350 l_ledger_language       VARCHAR2(30)   ;
9351 l_source                VARCHAR2(1996) ;
9352 l_description           VARCHAR2(2000) ;
9353 l_log_module            VARCHAR2(240)  ;
9354 BEGIN
9355 IF g_log_enabled THEN
9356       l_log_module := C_DEFAULT_MODULE||'.Description_92';
9357 END IF;
9358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9359       trace
9360          (p_msg      => 'BEGIN of Description_92'
9361          ,p_level    => C_LEVEL_PROCEDURE
9362          ,p_module   => l_log_module);
9363 END IF;
9364 
9365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9366 l_component_type        := 'AMB_DESCRIPTION';
9367 l_component_code        := 'FA_REVAL_BONUS_RESERVE';
9368 l_component_type_code   := 'S';
9369 l_component_appl_id     :=  140;
9370 l_amb_context_code      := 'DEFAULT';
9371 l_source                := NULL;
9372 l_description           := NULL;
9373 
9374 
9375  
9376  IF 
9377 l_ledger_language = 'US' THEN
9378     l_description :=  SUBSTR(CONCAT(l_description,'Revaluation  Bonus Reserve'),1,2000);
9379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9380  END IF;  
9381  IF 
9382 l_ledger_language = 'US' THEN
9383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9385  END IF;   
9386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9388   IF l_source IS NOT NULL THEN
9389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9391   END IF; 
9392  l_description := SUBSTR(l_description,1,1996);
9393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9394         trace
9395            (p_msg      => 'END of Description_92'
9396            ,p_level    => C_LEVEL_PROCEDURE
9397            ,p_module   => l_log_module);
9398 
9399   END IF;
9400   RETURN l_description;
9401 
9402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9403       trace
9404          (p_msg      => 'END of Description_92'
9405          ,p_level    => C_LEVEL_PROCEDURE
9406          ,p_module   => l_log_module);
9407 END IF;
9408 RETURN NULL;
9409 EXCEPTION
9410   WHEN VALUE_ERROR THEN
9411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9412             trace
9413                (p_msg      => 'ERROR: '||sqlerrm
9414                ,p_level    => C_LEVEL_EXCEPTION
9415                ,p_module   => l_log_module);
9416      END IF;
9417      RAISE;
9421          (p_msg      => 'ERROR: '||sqlerrm
9418  WHEN xla_exceptions_pkg.application_exception THEN
9419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9420       trace
9422          ,p_level    => C_LEVEL_EXCEPTION
9423          ,p_module   => l_log_module);
9424       END IF;
9425       RAISE;
9426  WHEN OTHERS THEN
9427        xla_exceptions_pkg.raise_message
9428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_92');
9429 END Description_92;
9430 
9431 ---------------------------------------
9432 --
9433 -- PRIVATE FUNCTION
9434 --         Description_93
9435 --
9436 ---------------------------------------
9437 FUNCTION Description_93 (
9438   p_application_id      IN NUMBER
9439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9440 --Period Close Date
9441  , p_source_1            IN DATE
9442 )
9443 RETURN VARCHAR2
9444 IS
9445 l_component_type        VARCHAR2(80)   ;
9446 l_component_code        VARCHAR2(30)   ;
9447 l_component_type_code   VARCHAR2(1)    ;
9448 l_component_appl_id     INTEGER        ;
9449 l_amb_context_code      VARCHAR2(30)   ;
9450 l_ledger_language       VARCHAR2(30)   ;
9451 l_source                VARCHAR2(1996) ;
9452 l_description           VARCHAR2(2000) ;
9453 l_log_module            VARCHAR2(240)  ;
9454 BEGIN
9455 IF g_log_enabled THEN
9456       l_log_module := C_DEFAULT_MODULE||'.Description_93';
9457 END IF;
9458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9459       trace
9460          (p_msg      => 'BEGIN of Description_93'
9461          ,p_level    => C_LEVEL_PROCEDURE
9462          ,p_module   => l_log_module);
9463 END IF;
9464 
9465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9466 l_component_type        := 'AMB_DESCRIPTION';
9467 l_component_code        := 'FA_REVAL_COST';
9468 l_component_type_code   := 'S';
9469 l_component_appl_id     :=  140;
9470 l_amb_context_code      := 'DEFAULT';
9471 l_source                := NULL;
9472 l_description           := NULL;
9473 
9474 
9475  
9476  IF 
9477 l_ledger_language = 'US' THEN
9478     l_description :=  SUBSTR(CONCAT(l_description,'Revaluation Cost'),1,2000);
9479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9480  END IF;  
9481  IF 
9482 l_ledger_language = 'US' THEN
9483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9485  END IF;   
9486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9488   IF l_source IS NOT NULL THEN
9489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9491   END IF; 
9492  l_description := SUBSTR(l_description,1,1996);
9493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9494         trace
9495            (p_msg      => 'END of Description_93'
9496            ,p_level    => C_LEVEL_PROCEDURE
9497            ,p_module   => l_log_module);
9498 
9499   END IF;
9500   RETURN l_description;
9501 
9502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9503       trace
9504          (p_msg      => 'END of Description_93'
9505          ,p_level    => C_LEVEL_PROCEDURE
9506          ,p_module   => l_log_module);
9507 END IF;
9508 RETURN NULL;
9509 EXCEPTION
9510   WHEN VALUE_ERROR THEN
9511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9512             trace
9513                (p_msg      => 'ERROR: '||sqlerrm
9514                ,p_level    => C_LEVEL_EXCEPTION
9515                ,p_module   => l_log_module);
9516      END IF;
9517      RAISE;
9518  WHEN xla_exceptions_pkg.application_exception THEN
9519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9520       trace
9521          (p_msg      => 'ERROR: '||sqlerrm
9522          ,p_level    => C_LEVEL_EXCEPTION
9523          ,p_module   => l_log_module);
9524       END IF;
9525       RAISE;
9526  WHEN OTHERS THEN
9527        xla_exceptions_pkg.raise_message
9528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_93');
9529 END Description_93;
9530 
9531 ---------------------------------------
9532 --
9533 -- PRIVATE FUNCTION
9534 --         Description_94
9535 --
9536 ---------------------------------------
9537 FUNCTION Description_94 (
9538   p_application_id      IN NUMBER
9539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9540 --Period Close Date
9541  , p_source_1            IN DATE
9542 )
9543 RETURN VARCHAR2
9544 IS
9545 l_component_type        VARCHAR2(80)   ;
9546 l_component_code        VARCHAR2(30)   ;
9547 l_component_type_code   VARCHAR2(1)    ;
9548 l_component_appl_id     INTEGER        ;
9549 l_amb_context_code      VARCHAR2(30)   ;
9550 l_ledger_language       VARCHAR2(30)   ;
9551 l_source                VARCHAR2(1996) ;
9552 l_description           VARCHAR2(2000) ;
9553 l_log_module            VARCHAR2(240)  ;
9554 BEGIN
9555 IF g_log_enabled THEN
9556       l_log_module := C_DEFAULT_MODULE||'.Description_94';
9557 END IF;
9558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9559       trace
9560          (p_msg      => 'BEGIN of Description_94'
9561          ,p_level    => C_LEVEL_PROCEDURE
9562          ,p_module   => l_log_module);
9563 END IF;
9564 
9565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9566 l_component_type        := 'AMB_DESCRIPTION';
9567 l_component_code        := 'FA_REVAL_DEPRN_RESERVE';
9568 l_component_type_code   := 'S';
9569 l_component_appl_id     :=  140;
9570 l_amb_context_code      := 'DEFAULT';
9571 l_source                := NULL;
9572 l_description           := NULL;
9573 
9577 l_ledger_language = 'US' THEN
9574 
9575  
9576  IF 
9578     l_description :=  SUBSTR(CONCAT(l_description,'Revaluation Depreciation Reserve'),1,2000);
9579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9580  END IF;  
9581  IF 
9582 l_ledger_language = 'US' THEN
9583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9585  END IF;   
9586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9588   IF l_source IS NOT NULL THEN
9589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9591   END IF; 
9592  l_description := SUBSTR(l_description,1,1996);
9593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9594         trace
9595            (p_msg      => 'END of Description_94'
9596            ,p_level    => C_LEVEL_PROCEDURE
9597            ,p_module   => l_log_module);
9598 
9599   END IF;
9600   RETURN l_description;
9601 
9602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9603       trace
9604          (p_msg      => 'END of Description_94'
9605          ,p_level    => C_LEVEL_PROCEDURE
9606          ,p_module   => l_log_module);
9607 END IF;
9608 RETURN NULL;
9609 EXCEPTION
9610   WHEN VALUE_ERROR THEN
9611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9612             trace
9613                (p_msg      => 'ERROR: '||sqlerrm
9614                ,p_level    => C_LEVEL_EXCEPTION
9615                ,p_module   => l_log_module);
9616      END IF;
9617      RAISE;
9618  WHEN xla_exceptions_pkg.application_exception THEN
9619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9620       trace
9621          (p_msg      => 'ERROR: '||sqlerrm
9622          ,p_level    => C_LEVEL_EXCEPTION
9623          ,p_module   => l_log_module);
9624       END IF;
9625       RAISE;
9626  WHEN OTHERS THEN
9627        xla_exceptions_pkg.raise_message
9628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_94');
9629 END Description_94;
9630 
9631 ---------------------------------------
9632 --
9633 -- PRIVATE FUNCTION
9634 --         Description_95
9635 --
9636 ---------------------------------------
9637 FUNCTION Description_95 (
9638   p_application_id      IN NUMBER
9639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9640 --Period Close Date
9641  , p_source_1            IN DATE
9642 )
9643 RETURN VARCHAR2
9644 IS
9645 l_component_type        VARCHAR2(80)   ;
9646 l_component_code        VARCHAR2(30)   ;
9647 l_component_type_code   VARCHAR2(1)    ;
9648 l_component_appl_id     INTEGER        ;
9649 l_amb_context_code      VARCHAR2(30)   ;
9650 l_ledger_language       VARCHAR2(30)   ;
9651 l_source                VARCHAR2(1996) ;
9652 l_description           VARCHAR2(2000) ;
9653 l_log_module            VARCHAR2(240)  ;
9654 BEGIN
9655 IF g_log_enabled THEN
9656       l_log_module := C_DEFAULT_MODULE||'.Description_95';
9657 END IF;
9658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9659       trace
9660          (p_msg      => 'BEGIN of Description_95'
9661          ,p_level    => C_LEVEL_PROCEDURE
9662          ,p_module   => l_log_module);
9663 END IF;
9664 
9665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9666 l_component_type        := 'AMB_DESCRIPTION';
9667 l_component_code        := 'FA_REVAL_EXPENSE';
9668 l_component_type_code   := 'S';
9669 l_component_appl_id     :=  140;
9670 l_amb_context_code      := 'DEFAULT';
9671 l_source                := NULL;
9672 l_description           := NULL;
9673 
9674 
9675  
9676  IF 
9677 l_ledger_language = 'US' THEN
9678     l_description :=  SUBSTR(CONCAT(l_description,'Revaluation Expense'),1,2000);
9679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9680  END IF;  
9681  IF 
9682 l_ledger_language = 'US' THEN
9683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9685  END IF;   
9686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9688   IF l_source IS NOT NULL THEN
9689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9691   END IF; 
9692  l_description := SUBSTR(l_description,1,1996);
9693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9694         trace
9695            (p_msg      => 'END of Description_95'
9696            ,p_level    => C_LEVEL_PROCEDURE
9697            ,p_module   => l_log_module);
9698 
9699   END IF;
9700   RETURN l_description;
9701 
9702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9703       trace
9704          (p_msg      => 'END of Description_95'
9705          ,p_level    => C_LEVEL_PROCEDURE
9706          ,p_module   => l_log_module);
9707 END IF;
9708 RETURN NULL;
9709 EXCEPTION
9710   WHEN VALUE_ERROR THEN
9711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9712             trace
9713                (p_msg      => 'ERROR: '||sqlerrm
9714                ,p_level    => C_LEVEL_EXCEPTION
9715                ,p_module   => l_log_module);
9716      END IF;
9717      RAISE;
9718  WHEN xla_exceptions_pkg.application_exception THEN
9719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9720       trace
9721          (p_msg      => 'ERROR: '||sqlerrm
9722          ,p_level    => C_LEVEL_EXCEPTION
9723          ,p_module   => l_log_module);
9724       END IF;
9725       RAISE;
9726  WHEN OTHERS THEN
9730 
9727        xla_exceptions_pkg.raise_message
9728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_95');
9729 END Description_95;
9731 ---------------------------------------
9732 --
9733 -- PRIVATE FUNCTION
9734 --         Description_96
9735 --
9736 ---------------------------------------
9737 FUNCTION Description_96 (
9738   p_application_id      IN NUMBER
9739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9740 --Period Close Date
9741  , p_source_1            IN DATE
9742 )
9743 RETURN VARCHAR2
9744 IS
9745 l_component_type        VARCHAR2(80)   ;
9746 l_component_code        VARCHAR2(30)   ;
9747 l_component_type_code   VARCHAR2(1)    ;
9748 l_component_appl_id     INTEGER        ;
9749 l_amb_context_code      VARCHAR2(30)   ;
9750 l_ledger_language       VARCHAR2(30)   ;
9751 l_source                VARCHAR2(1996) ;
9752 l_description           VARCHAR2(2000) ;
9753 l_log_module            VARCHAR2(240)  ;
9754 BEGIN
9755 IF g_log_enabled THEN
9756       l_log_module := C_DEFAULT_MODULE||'.Description_96';
9757 END IF;
9758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9759       trace
9760          (p_msg      => 'BEGIN of Description_96'
9761          ,p_level    => C_LEVEL_PROCEDURE
9762          ,p_module   => l_log_module);
9763 END IF;
9764 
9765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9766 l_component_type        := 'AMB_DESCRIPTION';
9767 l_component_code        := 'FA_REVAL_RESERVE';
9768 l_component_type_code   := 'S';
9769 l_component_appl_id     :=  140;
9770 l_amb_context_code      := 'DEFAULT';
9771 l_source                := NULL;
9772 l_description           := NULL;
9773 
9774 
9775  
9776  IF 
9777 l_ledger_language = 'US' THEN
9778     l_description :=  SUBSTR(CONCAT(l_description,'Revaluation Reserve'),1,2000);
9779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9780  END IF;  
9781  IF 
9782 l_ledger_language = 'US' THEN
9783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9785  END IF;   
9786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9788   IF l_source IS NOT NULL THEN
9789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9791   END IF; 
9792  l_description := SUBSTR(l_description,1,1996);
9793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9794         trace
9795            (p_msg      => 'END of Description_96'
9796            ,p_level    => C_LEVEL_PROCEDURE
9797            ,p_module   => l_log_module);
9798 
9799   END IF;
9800   RETURN l_description;
9801 
9802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9803       trace
9804          (p_msg      => 'END of Description_96'
9805          ,p_level    => C_LEVEL_PROCEDURE
9806          ,p_module   => l_log_module);
9807 END IF;
9808 RETURN NULL;
9809 EXCEPTION
9810   WHEN VALUE_ERROR THEN
9811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9812             trace
9813                (p_msg      => 'ERROR: '||sqlerrm
9814                ,p_level    => C_LEVEL_EXCEPTION
9815                ,p_module   => l_log_module);
9816      END IF;
9817      RAISE;
9818  WHEN xla_exceptions_pkg.application_exception THEN
9819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9820       trace
9821          (p_msg      => 'ERROR: '||sqlerrm
9822          ,p_level    => C_LEVEL_EXCEPTION
9823          ,p_module   => l_log_module);
9824       END IF;
9825       RAISE;
9826  WHEN OTHERS THEN
9827        xla_exceptions_pkg.raise_message
9828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_96');
9829 END Description_96;
9830 
9831 ---------------------------------------
9832 --
9833 -- PRIVATE FUNCTION
9834 --         Description_97
9835 --
9836 ---------------------------------------
9837 FUNCTION Description_97 (
9838   p_application_id      IN NUMBER
9839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9840 --Period Close Date
9841  , p_source_1            IN DATE
9842 )
9843 RETURN VARCHAR2
9844 IS
9845 l_component_type        VARCHAR2(80)   ;
9846 l_component_code        VARCHAR2(30)   ;
9847 l_component_type_code   VARCHAR2(1)    ;
9848 l_component_appl_id     INTEGER        ;
9849 l_amb_context_code      VARCHAR2(30)   ;
9850 l_ledger_language       VARCHAR2(30)   ;
9851 l_source                VARCHAR2(1996) ;
9852 l_description           VARCHAR2(2000) ;
9853 l_log_module            VARCHAR2(240)  ;
9854 BEGIN
9855 IF g_log_enabled THEN
9856       l_log_module := C_DEFAULT_MODULE||'.Description_97';
9857 END IF;
9858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9859       trace
9860          (p_msg      => 'BEGIN of Description_97'
9861          ,p_level    => C_LEVEL_PROCEDURE
9862          ,p_module   => l_log_module);
9863 END IF;
9864 
9865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9866 l_component_type        := 'AMB_DESCRIPTION';
9867 l_component_code        := 'FA_REV_ASSET_BONUS_EXPENSE';
9868 l_component_type_code   := 'S';
9869 l_component_appl_id     :=  140;
9870 l_amb_context_code      := 'DEFAULT';
9871 l_source                := NULL;
9872 l_description           := NULL;
9873 
9874 
9875  
9876  IF 
9877 l_ledger_language = 'US' THEN
9878     l_description :=  SUBSTR(CONCAT(l_description,'Assets Reverse Capitalization Bonus Expense'),1,2000);
9879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9880  END IF;  
9881  IF 
9882 l_ledger_language = 'US' THEN
9886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9885  END IF;   
9887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9888   IF l_source IS NOT NULL THEN
9889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9891   END IF; 
9892  l_description := SUBSTR(l_description,1,1996);
9893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9894         trace
9895            (p_msg      => 'END of Description_97'
9896            ,p_level    => C_LEVEL_PROCEDURE
9897            ,p_module   => l_log_module);
9898 
9899   END IF;
9900   RETURN l_description;
9901 
9902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9903       trace
9904          (p_msg      => 'END of Description_97'
9905          ,p_level    => C_LEVEL_PROCEDURE
9906          ,p_module   => l_log_module);
9907 END IF;
9908 RETURN NULL;
9909 EXCEPTION
9910   WHEN VALUE_ERROR THEN
9911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9912             trace
9913                (p_msg      => 'ERROR: '||sqlerrm
9914                ,p_level    => C_LEVEL_EXCEPTION
9915                ,p_module   => l_log_module);
9916      END IF;
9917      RAISE;
9918  WHEN xla_exceptions_pkg.application_exception THEN
9919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9920       trace
9921          (p_msg      => 'ERROR: '||sqlerrm
9922          ,p_level    => C_LEVEL_EXCEPTION
9923          ,p_module   => l_log_module);
9924       END IF;
9925       RAISE;
9926  WHEN OTHERS THEN
9927        xla_exceptions_pkg.raise_message
9928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_97');
9929 END Description_97;
9930 
9931 ---------------------------------------
9932 --
9933 -- PRIVATE FUNCTION
9934 --         Description_98
9935 --
9936 ---------------------------------------
9937 FUNCTION Description_98 (
9938   p_application_id      IN NUMBER
9939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
9940 --Period Close Date
9941  , p_source_1            IN DATE
9942 )
9943 RETURN VARCHAR2
9944 IS
9945 l_component_type        VARCHAR2(80)   ;
9946 l_component_code        VARCHAR2(30)   ;
9947 l_component_type_code   VARCHAR2(1)    ;
9948 l_component_appl_id     INTEGER        ;
9949 l_amb_context_code      VARCHAR2(30)   ;
9950 l_ledger_language       VARCHAR2(30)   ;
9951 l_source                VARCHAR2(1996) ;
9952 l_description           VARCHAR2(2000) ;
9953 l_log_module            VARCHAR2(240)  ;
9954 BEGIN
9955 IF g_log_enabled THEN
9956       l_log_module := C_DEFAULT_MODULE||'.Description_98';
9957 END IF;
9958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9959       trace
9960          (p_msg      => 'BEGIN of Description_98'
9961          ,p_level    => C_LEVEL_PROCEDURE
9962          ,p_module   => l_log_module);
9963 END IF;
9964 
9965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
9966 l_component_type        := 'AMB_DESCRIPTION';
9967 l_component_code        := 'FA_REV_ASSET_BONUS_RESERVE';
9968 l_component_type_code   := 'S';
9969 l_component_appl_id     :=  140;
9970 l_amb_context_code      := 'DEFAULT';
9971 l_source                := NULL;
9972 l_description           := NULL;
9973 
9974 
9975  
9976  IF 
9977 l_ledger_language = 'US' THEN
9978     l_description :=  SUBSTR(CONCAT(l_description,'Assets Reverse Capitalization Bonus Reserve'),1,2000);
9979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9980  END IF;  
9981  IF 
9982 l_ledger_language = 'US' THEN
9983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
9984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
9985  END IF;   
9986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
9987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
9988   IF l_source IS NOT NULL THEN
9989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
9990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
9991   END IF; 
9992  l_description := SUBSTR(l_description,1,1996);
9993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9994         trace
9995            (p_msg      => 'END of Description_98'
9996            ,p_level    => C_LEVEL_PROCEDURE
9997            ,p_module   => l_log_module);
9998 
9999   END IF;
10000   RETURN l_description;
10001 
10002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10003       trace
10004          (p_msg      => 'END of Description_98'
10005          ,p_level    => C_LEVEL_PROCEDURE
10006          ,p_module   => l_log_module);
10007 END IF;
10008 RETURN NULL;
10009 EXCEPTION
10010   WHEN VALUE_ERROR THEN
10011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10012             trace
10013                (p_msg      => 'ERROR: '||sqlerrm
10014                ,p_level    => C_LEVEL_EXCEPTION
10015                ,p_module   => l_log_module);
10016      END IF;
10017      RAISE;
10018  WHEN xla_exceptions_pkg.application_exception THEN
10019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10020       trace
10021          (p_msg      => 'ERROR: '||sqlerrm
10022          ,p_level    => C_LEVEL_EXCEPTION
10023          ,p_module   => l_log_module);
10024       END IF;
10025       RAISE;
10026  WHEN OTHERS THEN
10027        xla_exceptions_pkg.raise_message
10028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_98');
10029 END Description_98;
10030 
10031 ---------------------------------------
10032 --
10033 -- PRIVATE FUNCTION
10034 --         Description_99
10038   p_application_id      IN NUMBER
10035 --
10036 ---------------------------------------
10037 FUNCTION Description_99 (
10039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10040 --Period Close Date
10041  , p_source_1            IN DATE
10042 )
10043 RETURN VARCHAR2
10044 IS
10045 l_component_type        VARCHAR2(80)   ;
10046 l_component_code        VARCHAR2(30)   ;
10047 l_component_type_code   VARCHAR2(1)    ;
10048 l_component_appl_id     INTEGER        ;
10049 l_amb_context_code      VARCHAR2(30)   ;
10050 l_ledger_language       VARCHAR2(30)   ;
10051 l_source                VARCHAR2(1996) ;
10052 l_description           VARCHAR2(2000) ;
10053 l_log_module            VARCHAR2(240)  ;
10054 BEGIN
10055 IF g_log_enabled THEN
10056       l_log_module := C_DEFAULT_MODULE||'.Description_99';
10057 END IF;
10058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10059       trace
10060          (p_msg      => 'BEGIN of Description_99'
10061          ,p_level    => C_LEVEL_PROCEDURE
10062          ,p_module   => l_log_module);
10063 END IF;
10064 
10065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10066 l_component_type        := 'AMB_DESCRIPTION';
10067 l_component_code        := 'FA_REV_ASSET_CIP_COST';
10068 l_component_type_code   := 'S';
10069 l_component_appl_id     :=  140;
10070 l_amb_context_code      := 'DEFAULT';
10071 l_source                := NULL;
10072 l_description           := NULL;
10073 
10074 
10075  
10076  IF 
10077 l_ledger_language = 'US' THEN
10078     l_description :=  SUBSTR(CONCAT(l_description,'Assets Reverse Capitalization CIP Cost'),1,2000);
10079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10080  END IF;  
10081  IF 
10082 l_ledger_language = 'US' THEN
10083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10085  END IF;   
10086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10088   IF l_source IS NOT NULL THEN
10089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10091   END IF; 
10092  l_description := SUBSTR(l_description,1,1996);
10093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10094         trace
10095            (p_msg      => 'END of Description_99'
10096            ,p_level    => C_LEVEL_PROCEDURE
10097            ,p_module   => l_log_module);
10098 
10099   END IF;
10100   RETURN l_description;
10101 
10102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10103       trace
10104          (p_msg      => 'END of Description_99'
10105          ,p_level    => C_LEVEL_PROCEDURE
10106          ,p_module   => l_log_module);
10107 END IF;
10108 RETURN NULL;
10109 EXCEPTION
10110   WHEN VALUE_ERROR THEN
10111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10112             trace
10113                (p_msg      => 'ERROR: '||sqlerrm
10114                ,p_level    => C_LEVEL_EXCEPTION
10115                ,p_module   => l_log_module);
10116      END IF;
10117      RAISE;
10118  WHEN xla_exceptions_pkg.application_exception THEN
10119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10120       trace
10121          (p_msg      => 'ERROR: '||sqlerrm
10122          ,p_level    => C_LEVEL_EXCEPTION
10123          ,p_module   => l_log_module);
10124       END IF;
10125       RAISE;
10126  WHEN OTHERS THEN
10127        xla_exceptions_pkg.raise_message
10128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_99');
10129 END Description_99;
10130 
10131 ---------------------------------------
10132 --
10133 -- PRIVATE FUNCTION
10134 --         Description_100
10135 --
10136 ---------------------------------------
10137 FUNCTION Description_100 (
10138   p_application_id      IN NUMBER
10139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10140 --Period Close Date
10141  , p_source_1            IN DATE
10142 )
10143 RETURN VARCHAR2
10144 IS
10145 l_component_type        VARCHAR2(80)   ;
10146 l_component_code        VARCHAR2(30)   ;
10147 l_component_type_code   VARCHAR2(1)    ;
10148 l_component_appl_id     INTEGER        ;
10149 l_amb_context_code      VARCHAR2(30)   ;
10150 l_ledger_language       VARCHAR2(30)   ;
10151 l_source                VARCHAR2(1996) ;
10152 l_description           VARCHAR2(2000) ;
10153 l_log_module            VARCHAR2(240)  ;
10154 BEGIN
10155 IF g_log_enabled THEN
10156       l_log_module := C_DEFAULT_MODULE||'.Description_100';
10157 END IF;
10158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10159       trace
10160          (p_msg      => 'BEGIN of Description_100'
10161          ,p_level    => C_LEVEL_PROCEDURE
10162          ,p_module   => l_log_module);
10163 END IF;
10164 
10165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10166 l_component_type        := 'AMB_DESCRIPTION';
10167 l_component_code        := 'FA_REV_ASSET_COST';
10168 l_component_type_code   := 'S';
10169 l_component_appl_id     :=  140;
10170 l_amb_context_code      := 'DEFAULT';
10171 l_source                := NULL;
10172 l_description           := NULL;
10173 
10174 
10175  
10176  IF 
10177 l_ledger_language = 'US' THEN
10178     l_description :=  SUBSTR(CONCAT(l_description,'Assets Reverse Capitalization Cost'),1,2000);
10179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10180  END IF;  
10181  IF 
10182 l_ledger_language = 'US' THEN
10183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10185  END IF;   
10189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10188   IF l_source IS NOT NULL THEN
10190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10191   END IF; 
10192  l_description := SUBSTR(l_description,1,1996);
10193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10194         trace
10195            (p_msg      => 'END of Description_100'
10196            ,p_level    => C_LEVEL_PROCEDURE
10197            ,p_module   => l_log_module);
10198 
10199   END IF;
10200   RETURN l_description;
10201 
10202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10203       trace
10204          (p_msg      => 'END of Description_100'
10205          ,p_level    => C_LEVEL_PROCEDURE
10209 EXCEPTION
10206          ,p_module   => l_log_module);
10207 END IF;
10208 RETURN NULL;
10210   WHEN VALUE_ERROR THEN
10211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10212             trace
10213                (p_msg      => 'ERROR: '||sqlerrm
10214                ,p_level    => C_LEVEL_EXCEPTION
10215                ,p_module   => l_log_module);
10216      END IF;
10217      RAISE;
10218  WHEN xla_exceptions_pkg.application_exception THEN
10219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10220       trace
10221          (p_msg      => 'ERROR: '||sqlerrm
10222          ,p_level    => C_LEVEL_EXCEPTION
10223          ,p_module   => l_log_module);
10224       END IF;
10225       RAISE;
10226  WHEN OTHERS THEN
10227        xla_exceptions_pkg.raise_message
10228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_100');
10229 END Description_100;
10230 
10231 ---------------------------------------
10232 --
10233 -- PRIVATE FUNCTION
10234 --         Description_101
10235 --
10236 ---------------------------------------
10237 FUNCTION Description_101 (
10238   p_application_id      IN NUMBER
10239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10240 --Period Close Date
10241  , p_source_1            IN DATE
10242 )
10243 RETURN VARCHAR2
10244 IS
10245 l_component_type        VARCHAR2(80)   ;
10246 l_component_code        VARCHAR2(30)   ;
10247 l_component_type_code   VARCHAR2(1)    ;
10248 l_component_appl_id     INTEGER        ;
10249 l_amb_context_code      VARCHAR2(30)   ;
10250 l_ledger_language       VARCHAR2(30)   ;
10251 l_source                VARCHAR2(1996) ;
10252 l_description           VARCHAR2(2000) ;
10253 l_log_module            VARCHAR2(240)  ;
10254 BEGIN
10255 IF g_log_enabled THEN
10256       l_log_module := C_DEFAULT_MODULE||'.Description_101';
10257 END IF;
10258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10259       trace
10260          (p_msg      => 'BEGIN of Description_101'
10261          ,p_level    => C_LEVEL_PROCEDURE
10262          ,p_module   => l_log_module);
10263 END IF;
10264 
10265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10266 l_component_type        := 'AMB_DESCRIPTION';
10267 l_component_code        := 'FA_REV_ASSET_EXPENSE';
10268 l_component_type_code   := 'S';
10269 l_component_appl_id     :=  140;
10270 l_amb_context_code      := 'DEFAULT';
10271 l_source                := NULL;
10272 l_description           := NULL;
10273 
10274 
10275  
10276  IF 
10277 l_ledger_language = 'US' THEN
10278     l_description :=  SUBSTR(CONCAT(l_description,'Assets Reverse Capitalization Expense'),1,2000);
10279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10280  END IF;  
10281  IF 
10282 l_ledger_language = 'US' THEN
10283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10285  END IF;   
10286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10288   IF l_source IS NOT NULL THEN
10289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10291   END IF; 
10292  l_description := SUBSTR(l_description,1,1996);
10293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10294         trace
10295            (p_msg      => 'END of Description_101'
10296            ,p_level    => C_LEVEL_PROCEDURE
10297            ,p_module   => l_log_module);
10298 
10299   END IF;
10300   RETURN l_description;
10301 
10302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10303       trace
10304          (p_msg      => 'END of Description_101'
10305          ,p_level    => C_LEVEL_PROCEDURE
10306          ,p_module   => l_log_module);
10307 END IF;
10308 RETURN NULL;
10309 EXCEPTION
10313                (p_msg      => 'ERROR: '||sqlerrm
10310   WHEN VALUE_ERROR THEN
10311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10312             trace
10314                ,p_level    => C_LEVEL_EXCEPTION
10315                ,p_module   => l_log_module);
10316      END IF;
10317      RAISE;
10318  WHEN xla_exceptions_pkg.application_exception THEN
10319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10320       trace
10321          (p_msg      => 'ERROR: '||sqlerrm
10322          ,p_level    => C_LEVEL_EXCEPTION
10323          ,p_module   => l_log_module);
10324       END IF;
10325       RAISE;
10326  WHEN OTHERS THEN
10327        xla_exceptions_pkg.raise_message
10328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_101');
10329 END Description_101;
10330 
10331 ---------------------------------------
10332 --
10333 -- PRIVATE FUNCTION
10334 --         Description_102
10335 --
10336 ---------------------------------------
10337 FUNCTION Description_102 (
10338   p_application_id      IN NUMBER
10339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10340 --Period Close Date
10341  , p_source_1            IN DATE
10342 )
10343 RETURN VARCHAR2
10344 IS
10345 l_component_type        VARCHAR2(80)   ;
10346 l_component_code        VARCHAR2(30)   ;
10347 l_component_type_code   VARCHAR2(1)    ;
10348 l_component_appl_id     INTEGER        ;
10349 l_amb_context_code      VARCHAR2(30)   ;
10350 l_ledger_language       VARCHAR2(30)   ;
10351 l_source                VARCHAR2(1996) ;
10352 l_description           VARCHAR2(2000) ;
10353 l_log_module            VARCHAR2(240)  ;
10354 BEGIN
10355 IF g_log_enabled THEN
10356       l_log_module := C_DEFAULT_MODULE||'.Description_102';
10357 END IF;
10358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10359       trace
10360          (p_msg      => 'BEGIN of Description_102'
10361          ,p_level    => C_LEVEL_PROCEDURE
10362          ,p_module   => l_log_module);
10363 END IF;
10364 
10365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10366 l_component_type        := 'AMB_DESCRIPTION';
10367 l_component_code        := 'FA_REV_ASSET_RESERVE';
10368 l_component_type_code   := 'S';
10369 l_component_appl_id     :=  140;
10370 l_amb_context_code      := 'DEFAULT';
10371 l_source                := NULL;
10372 l_description           := NULL;
10373 
10374 
10375  
10376  IF 
10377 l_ledger_language = 'US' THEN
10378     l_description :=  SUBSTR(CONCAT(l_description,'Assets Reverse Capitalization Reserve'),1,2000);
10379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10380  END IF;  
10381  IF 
10382 l_ledger_language = 'US' THEN
10383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10385  END IF;   
10386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10388   IF l_source IS NOT NULL THEN
10389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10391   END IF; 
10392  l_description := SUBSTR(l_description,1,1996);
10393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10394         trace
10395            (p_msg      => 'END of Description_102'
10396            ,p_level    => C_LEVEL_PROCEDURE
10397            ,p_module   => l_log_module);
10398 
10399   END IF;
10400   RETURN l_description;
10401 
10402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10403       trace
10404          (p_msg      => 'END of Description_102'
10405          ,p_level    => C_LEVEL_PROCEDURE
10406          ,p_module   => l_log_module);
10407 END IF;
10408 RETURN NULL;
10409 EXCEPTION
10410   WHEN VALUE_ERROR THEN
10411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10412             trace
10413                (p_msg      => 'ERROR: '||sqlerrm
10414                ,p_level    => C_LEVEL_EXCEPTION
10415                ,p_module   => l_log_module);
10416      END IF;
10417      RAISE;
10418  WHEN xla_exceptions_pkg.application_exception THEN
10419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10420       trace
10421          (p_msg      => 'ERROR: '||sqlerrm
10422          ,p_level    => C_LEVEL_EXCEPTION
10423          ,p_module   => l_log_module);
10424       END IF;
10425       RAISE;
10426  WHEN OTHERS THEN
10427        xla_exceptions_pkg.raise_message
10428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_102');
10429 END Description_102;
10430 
10431 ---------------------------------------
10432 --
10433 -- PRIVATE FUNCTION
10434 --         Description_103
10435 --
10436 ---------------------------------------
10440 --Period Close Date
10437 FUNCTION Description_103 (
10438   p_application_id      IN NUMBER
10439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10441  , p_source_1            IN DATE
10442 )
10443 RETURN VARCHAR2
10444 IS
10445 l_component_type        VARCHAR2(80)   ;
10446 l_component_code        VARCHAR2(30)   ;
10447 l_component_type_code   VARCHAR2(1)    ;
10448 l_component_appl_id     INTEGER        ;
10449 l_amb_context_code      VARCHAR2(30)   ;
10450 l_ledger_language       VARCHAR2(30)   ;
10451 l_source                VARCHAR2(1996) ;
10452 l_description           VARCHAR2(2000) ;
10453 l_log_module            VARCHAR2(240)  ;
10454 BEGIN
10455 IF g_log_enabled THEN
10456       l_log_module := C_DEFAULT_MODULE||'.Description_103';
10457 END IF;
10458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10459       trace
10460          (p_msg      => 'BEGIN of Description_103'
10461          ,p_level    => C_LEVEL_PROCEDURE
10462          ,p_module   => l_log_module);
10463 END IF;
10464 
10465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10466 l_component_type        := 'AMB_DESCRIPTION';
10467 l_component_code        := 'FA_SLT_BONUS_EXP';
10468 l_component_type_code   := 'S';
10469 l_component_appl_id     :=  140;
10470 l_amb_context_code      := 'DEFAULT';
10471 l_source                := NULL;
10472 l_description           := NULL;
10473 
10474 
10475  
10476  IF 
10477 l_ledger_language = 'US' THEN
10478     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer Bonus Expense'),1,2000);
10479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10480  END IF;  
10481  IF 
10482 l_ledger_language = 'US' THEN
10483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10485  END IF;   
10486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10488   IF l_source IS NOT NULL THEN
10489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10491   END IF; 
10492  l_description := SUBSTR(l_description,1,1996);
10493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10494         trace
10495            (p_msg      => 'END of Description_103'
10496            ,p_level    => C_LEVEL_PROCEDURE
10497            ,p_module   => l_log_module);
10498 
10499   END IF;
10500   RETURN l_description;
10501 
10502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10503       trace
10504          (p_msg      => 'END of Description_103'
10505          ,p_level    => C_LEVEL_PROCEDURE
10506          ,p_module   => l_log_module);
10507 END IF;
10508 RETURN NULL;
10509 EXCEPTION
10510   WHEN VALUE_ERROR THEN
10511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10512             trace
10513                (p_msg      => 'ERROR: '||sqlerrm
10514                ,p_level    => C_LEVEL_EXCEPTION
10515                ,p_module   => l_log_module);
10516      END IF;
10517      RAISE;
10518  WHEN xla_exceptions_pkg.application_exception THEN
10519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10520       trace
10521          (p_msg      => 'ERROR: '||sqlerrm
10522          ,p_level    => C_LEVEL_EXCEPTION
10523          ,p_module   => l_log_module);
10524       END IF;
10525       RAISE;
10526  WHEN OTHERS THEN
10527        xla_exceptions_pkg.raise_message
10528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_103');
10529 END Description_103;
10530 
10531 ---------------------------------------
10532 --
10533 -- PRIVATE FUNCTION
10534 --         Description_104
10535 --
10536 ---------------------------------------
10537 FUNCTION Description_104 (
10538   p_application_id      IN NUMBER
10539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10540 --Period Close Date
10541  , p_source_1            IN DATE
10542 )
10543 RETURN VARCHAR2
10544 IS
10545 l_component_type        VARCHAR2(80)   ;
10546 l_component_code        VARCHAR2(30)   ;
10547 l_component_type_code   VARCHAR2(1)    ;
10548 l_component_appl_id     INTEGER        ;
10549 l_amb_context_code      VARCHAR2(30)   ;
10550 l_ledger_language       VARCHAR2(30)   ;
10551 l_source                VARCHAR2(1996) ;
10552 l_description           VARCHAR2(2000) ;
10553 l_log_module            VARCHAR2(240)  ;
10554 BEGIN
10555 IF g_log_enabled THEN
10556       l_log_module := C_DEFAULT_MODULE||'.Description_104';
10557 END IF;
10558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10559       trace
10563 END IF;
10560          (p_msg      => 'BEGIN of Description_104'
10561          ,p_level    => C_LEVEL_PROCEDURE
10562          ,p_module   => l_log_module);
10564 
10565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10566 l_component_type        := 'AMB_DESCRIPTION';
10567 l_component_code        := 'FA_SLT_BONUS_RESERVE';
10568 l_component_type_code   := 'S';
10572 l_description           := NULL;
10569 l_component_appl_id     :=  140;
10570 l_amb_context_code      := 'DEFAULT';
10571 l_source                := NULL;
10573 
10574 
10575  
10576  IF 
10577 l_ledger_language = 'US' THEN
10578     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer Bonus Reserve'),1,2000);
10579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10580  END IF;  
10581  IF 
10582 l_ledger_language = 'US' THEN
10583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10585  END IF;   
10586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10588   IF l_source IS NOT NULL THEN
10589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10591   END IF; 
10592  l_description := SUBSTR(l_description,1,1996);
10593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10594         trace
10595            (p_msg      => 'END of Description_104'
10596            ,p_level    => C_LEVEL_PROCEDURE
10597            ,p_module   => l_log_module);
10598 
10599   END IF;
10600   RETURN l_description;
10601 
10602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10603       trace
10604          (p_msg      => 'END of Description_104'
10605          ,p_level    => C_LEVEL_PROCEDURE
10606          ,p_module   => l_log_module);
10607 END IF;
10608 RETURN NULL;
10609 EXCEPTION
10610   WHEN VALUE_ERROR THEN
10611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10612             trace
10613                (p_msg      => 'ERROR: '||sqlerrm
10614                ,p_level    => C_LEVEL_EXCEPTION
10615                ,p_module   => l_log_module);
10616      END IF;
10617      RAISE;
10618  WHEN xla_exceptions_pkg.application_exception THEN
10619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10620       trace
10621          (p_msg      => 'ERROR: '||sqlerrm
10622          ,p_level    => C_LEVEL_EXCEPTION
10623          ,p_module   => l_log_module);
10624       END IF;
10625       RAISE;
10626  WHEN OTHERS THEN
10627        xla_exceptions_pkg.raise_message
10628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_104');
10629 END Description_104;
10630 
10631 ---------------------------------------
10632 --
10633 -- PRIVATE FUNCTION
10634 --         Description_105
10635 --
10636 ---------------------------------------
10637 FUNCTION Description_105 (
10638   p_application_id      IN NUMBER
10639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10640 --Period Close Date
10641  , p_source_1            IN DATE
10642 )
10643 RETURN VARCHAR2
10644 IS
10645 l_component_type        VARCHAR2(80)   ;
10646 l_component_code        VARCHAR2(30)   ;
10647 l_component_type_code   VARCHAR2(1)    ;
10648 l_component_appl_id     INTEGER        ;
10649 l_amb_context_code      VARCHAR2(30)   ;
10650 l_ledger_language       VARCHAR2(30)   ;
10651 l_source                VARCHAR2(1996) ;
10652 l_description           VARCHAR2(2000) ;
10653 l_log_module            VARCHAR2(240)  ;
10654 BEGIN
10655 IF g_log_enabled THEN
10656       l_log_module := C_DEFAULT_MODULE||'.Description_105';
10657 END IF;
10658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10659       trace
10660          (p_msg      => 'BEGIN of Description_105'
10661          ,p_level    => C_LEVEL_PROCEDURE
10662          ,p_module   => l_log_module);
10663 END IF;
10664 
10665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10666 l_component_type        := 'AMB_DESCRIPTION';
10667 l_component_code        := 'FA_SLT_CIP_COST';
10668 l_component_type_code   := 'S';
10669 l_component_appl_id     :=  140;
10670 l_amb_context_code      := 'DEFAULT';
10671 l_source                := NULL;
10672 l_description           := NULL;
10673 
10674 
10675  
10676  IF 
10677 l_ledger_language = 'US' THEN
10678     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer CIP Cost'),1,2000);
10679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10680  END IF;  
10681  IF 
10682 l_ledger_language = 'US' THEN
10683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10685  END IF;   
10686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10688   IF l_source IS NOT NULL THEN
10689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10691   END IF; 
10692  l_description := SUBSTR(l_description,1,1996);
10693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10694         trace
10695            (p_msg      => 'END of Description_105'
10696            ,p_level    => C_LEVEL_PROCEDURE
10697            ,p_module   => l_log_module);
10698 
10699   END IF;
10700   RETURN l_description;
10701 
10702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10703       trace
10704          (p_msg      => 'END of Description_105'
10705          ,p_level    => C_LEVEL_PROCEDURE
10706          ,p_module   => l_log_module);
10707 END IF;
10708 RETURN NULL;
10709 EXCEPTION
10710   WHEN VALUE_ERROR THEN
10711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10712             trace
10713                (p_msg      => 'ERROR: '||sqlerrm
10714                ,p_level    => C_LEVEL_EXCEPTION
10715                ,p_module   => l_log_module);
10716      END IF;
10717      RAISE;
10718  WHEN xla_exceptions_pkg.application_exception THEN
10722          ,p_level    => C_LEVEL_EXCEPTION
10719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10720       trace
10721          (p_msg      => 'ERROR: '||sqlerrm
10723          ,p_module   => l_log_module);
10724       END IF;
10725       RAISE;
10726  WHEN OTHERS THEN
10727        xla_exceptions_pkg.raise_message
10728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_105');
10729 END Description_105;
10730 
10731 ---------------------------------------
10732 --
10733 -- PRIVATE FUNCTION
10734 --         Description_106
10735 --
10739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10736 ---------------------------------------
10737 FUNCTION Description_106 (
10738   p_application_id      IN NUMBER
10740 --Period Close Date
10741  , p_source_1            IN DATE
10742 )
10743 RETURN VARCHAR2
10744 IS
10745 l_component_type        VARCHAR2(80)   ;
10746 l_component_code        VARCHAR2(30)   ;
10747 l_component_type_code   VARCHAR2(1)    ;
10748 l_component_appl_id     INTEGER        ;
10749 l_amb_context_code      VARCHAR2(30)   ;
10750 l_ledger_language       VARCHAR2(30)   ;
10754 BEGIN
10751 l_source                VARCHAR2(1996) ;
10752 l_description           VARCHAR2(2000) ;
10753 l_log_module            VARCHAR2(240)  ;
10755 IF g_log_enabled THEN
10756       l_log_module := C_DEFAULT_MODULE||'.Description_106';
10757 END IF;
10758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10759       trace
10760          (p_msg      => 'BEGIN of Description_106'
10761          ,p_level    => C_LEVEL_PROCEDURE
10762          ,p_module   => l_log_module);
10763 END IF;
10764 
10765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10766 l_component_type        := 'AMB_DESCRIPTION';
10767 l_component_code        := 'FA_SLT_CIP_COST_CLR';
10768 l_component_type_code   := 'S';
10769 l_component_appl_id     :=  140;
10770 l_amb_context_code      := 'DEFAULT';
10771 l_source                := NULL;
10772 l_description           := NULL;
10773 
10774 
10775  
10776  IF 
10777 l_ledger_language = 'US' THEN
10778     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer CIP Cost Clearing'),1,2000);
10779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10780  END IF;  
10781  IF 
10782 l_ledger_language = 'US' THEN
10783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10785  END IF;   
10786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10788   IF l_source IS NOT NULL THEN
10789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10791   END IF; 
10792  l_description := SUBSTR(l_description,1,1996);
10793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10794         trace
10795            (p_msg      => 'END of Description_106'
10796            ,p_level    => C_LEVEL_PROCEDURE
10797            ,p_module   => l_log_module);
10798 
10799   END IF;
10800   RETURN l_description;
10801 
10802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10803       trace
10804          (p_msg      => 'END of Description_106'
10805          ,p_level    => C_LEVEL_PROCEDURE
10806          ,p_module   => l_log_module);
10807 END IF;
10808 RETURN NULL;
10809 EXCEPTION
10810   WHEN VALUE_ERROR THEN
10811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10812             trace
10813                (p_msg      => 'ERROR: '||sqlerrm
10814                ,p_level    => C_LEVEL_EXCEPTION
10815                ,p_module   => l_log_module);
10816      END IF;
10817      RAISE;
10818  WHEN xla_exceptions_pkg.application_exception THEN
10819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10820       trace
10821          (p_msg      => 'ERROR: '||sqlerrm
10822          ,p_level    => C_LEVEL_EXCEPTION
10823          ,p_module   => l_log_module);
10824       END IF;
10825       RAISE;
10826  WHEN OTHERS THEN
10827        xla_exceptions_pkg.raise_message
10828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_106');
10829 END Description_106;
10830 
10831 ---------------------------------------
10832 --
10833 -- PRIVATE FUNCTION
10834 --         Description_107
10835 --
10836 ---------------------------------------
10837 FUNCTION Description_107 (
10838   p_application_id      IN NUMBER
10839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10840 --Period Close Date
10841  , p_source_1            IN DATE
10842 )
10843 RETURN VARCHAR2
10844 IS
10845 l_component_type        VARCHAR2(80)   ;
10846 l_component_code        VARCHAR2(30)   ;
10847 l_component_type_code   VARCHAR2(1)    ;
10848 l_component_appl_id     INTEGER        ;
10849 l_amb_context_code      VARCHAR2(30)   ;
10850 l_ledger_language       VARCHAR2(30)   ;
10851 l_source                VARCHAR2(1996) ;
10852 l_description           VARCHAR2(2000) ;
10853 l_log_module            VARCHAR2(240)  ;
10854 BEGIN
10855 IF g_log_enabled THEN
10856       l_log_module := C_DEFAULT_MODULE||'.Description_107';
10857 END IF;
10858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10859       trace
10860          (p_msg      => 'BEGIN of Description_107'
10861          ,p_level    => C_LEVEL_PROCEDURE
10862          ,p_module   => l_log_module);
10863 END IF;
10864 
10865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10866 l_component_type        := 'AMB_DESCRIPTION';
10867 l_component_code        := 'FA_SLT_CIP_IC_PAY';
10868 l_component_type_code   := 'S';
10869 l_component_appl_id     :=  140;
10870 l_amb_context_code      := 'DEFAULT';
10871 l_source                := NULL;
10872 l_description           := NULL;
10873 
10874 
10875  
10876  IF 
10877 l_ledger_language = 'US' THEN
10878     l_description :=  SUBSTR(CONCAT(l_description,'CIP Source Line Transfer Intercompany Payable'),1,2000);
10879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10880  END IF;  
10881  IF 
10882 l_ledger_language = 'US' THEN
10883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10885  END IF;   
10886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10888   IF l_source IS NOT NULL THEN
10889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10891   END IF; 
10892  l_description := SUBSTR(l_description,1,1996);
10893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10894         trace
10895            (p_msg      => 'END of Description_107'
10896            ,p_level    => C_LEVEL_PROCEDURE
10900   RETURN l_description;
10897            ,p_module   => l_log_module);
10898 
10899   END IF;
10901 
10902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10903       trace
10904          (p_msg      => 'END of Description_107'
10905          ,p_level    => C_LEVEL_PROCEDURE
10906          ,p_module   => l_log_module);
10907 END IF;
10908 RETURN NULL;
10909 EXCEPTION
10913                (p_msg      => 'ERROR: '||sqlerrm
10910   WHEN VALUE_ERROR THEN
10911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10912             trace
10914                ,p_level    => C_LEVEL_EXCEPTION
10915                ,p_module   => l_log_module);
10916      END IF;
10917      RAISE;
10918  WHEN xla_exceptions_pkg.application_exception THEN
10919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10920       trace
10921          (p_msg      => 'ERROR: '||sqlerrm
10922          ,p_level    => C_LEVEL_EXCEPTION
10923          ,p_module   => l_log_module);
10924       END IF;
10925       RAISE;
10926  WHEN OTHERS THEN
10927        xla_exceptions_pkg.raise_message
10928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_107');
10929 END Description_107;
10930 
10931 ---------------------------------------
10932 --
10933 -- PRIVATE FUNCTION
10934 --         Description_108
10935 --
10936 ---------------------------------------
10937 FUNCTION Description_108 (
10938   p_application_id      IN NUMBER
10939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
10940 --Period Close Date
10941  , p_source_1            IN DATE
10942 )
10943 RETURN VARCHAR2
10944 IS
10945 l_component_type        VARCHAR2(80)   ;
10946 l_component_code        VARCHAR2(30)   ;
10947 l_component_type_code   VARCHAR2(1)    ;
10948 l_component_appl_id     INTEGER        ;
10949 l_amb_context_code      VARCHAR2(30)   ;
10950 l_ledger_language       VARCHAR2(30)   ;
10951 l_source                VARCHAR2(1996) ;
10952 l_description           VARCHAR2(2000) ;
10953 l_log_module            VARCHAR2(240)  ;
10954 BEGIN
10955 IF g_log_enabled THEN
10956       l_log_module := C_DEFAULT_MODULE||'.Description_108';
10957 END IF;
10958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10959       trace
10960          (p_msg      => 'BEGIN of Description_108'
10961          ,p_level    => C_LEVEL_PROCEDURE
10962          ,p_module   => l_log_module);
10963 END IF;
10964 
10965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
10966 l_component_type        := 'AMB_DESCRIPTION';
10967 l_component_code        := 'FA_SLT_CIP_IC_REC';
10968 l_component_type_code   := 'S';
10969 l_component_appl_id     :=  140;
10970 l_amb_context_code      := 'DEFAULT';
10971 l_source                := NULL;
10972 l_description           := NULL;
10973 
10974 
10975  
10976  IF 
10977 l_ledger_language = 'US' THEN
10978     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer CIP Intercompany Receivable'),1,2000);
10979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
10980  END IF;  
10981  IF 
10982 l_ledger_language = 'US' THEN
10984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
10985  END IF;   
10986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
10987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
10988   IF l_source IS NOT NULL THEN
10989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
10990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
10991   END IF; 
10992  l_description := SUBSTR(l_description,1,1996);
10993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10994         trace
10995            (p_msg      => 'END of Description_108'
10996            ,p_level    => C_LEVEL_PROCEDURE
10997            ,p_module   => l_log_module);
10998 
10999   END IF;
11000   RETURN l_description;
11001 
11002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11003       trace
11004          (p_msg      => 'END of Description_108'
11005          ,p_level    => C_LEVEL_PROCEDURE
11006          ,p_module   => l_log_module);
11007 END IF;
11008 RETURN NULL;
11009 EXCEPTION
11010   WHEN VALUE_ERROR THEN
11011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11012             trace
11013                (p_msg      => 'ERROR: '||sqlerrm
11014                ,p_level    => C_LEVEL_EXCEPTION
11015                ,p_module   => l_log_module);
11016      END IF;
11017      RAISE;
11018  WHEN xla_exceptions_pkg.application_exception THEN
11019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11020       trace
11021          (p_msg      => 'ERROR: '||sqlerrm
11022          ,p_level    => C_LEVEL_EXCEPTION
11023          ,p_module   => l_log_module);
11024       END IF;
11025       RAISE;
11026  WHEN OTHERS THEN
11027        xla_exceptions_pkg.raise_message
11028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_108');
11029 END Description_108;
11030 
11031 ---------------------------------------
11032 --
11033 -- PRIVATE FUNCTION
11034 --         Description_109
11035 --
11036 ---------------------------------------
11037 FUNCTION Description_109 (
11038   p_application_id      IN NUMBER
11039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11040 --Period Close Date
11041  , p_source_1            IN DATE
11042 )
11043 RETURN VARCHAR2
11044 IS
11045 l_component_type        VARCHAR2(80)   ;
11046 l_component_code        VARCHAR2(30)   ;
11047 l_component_type_code   VARCHAR2(1)    ;
11048 l_component_appl_id     INTEGER        ;
11049 l_amb_context_code      VARCHAR2(30)   ;
11050 l_ledger_language       VARCHAR2(30)   ;
11051 l_source                VARCHAR2(1996) ;
11052 l_description           VARCHAR2(2000) ;
11053 l_log_module            VARCHAR2(240)  ;
11054 BEGIN
11055 IF g_log_enabled THEN
11056       l_log_module := C_DEFAULT_MODULE||'.Description_109';
11057 END IF;
11058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11059       trace
11060          (p_msg      => 'BEGIN of Description_109'
11061          ,p_level    => C_LEVEL_PROCEDURE
11062          ,p_module   => l_log_module);
11063 END IF;
11064 
11065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11066 l_component_type        := 'AMB_DESCRIPTION';
11067 l_component_code        := 'FA_SLT_CIP_REVAL_RESERVE';
11068 l_component_type_code   := 'S';
11069 l_component_appl_id     :=  140;
11070 l_amb_context_code      := 'DEFAULT';
11071 l_source                := NULL;
11072 l_description           := NULL;
11073 
11074 
11075  
11076  IF 
11077 l_ledger_language = 'US' THEN
11078     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer CIP Revaluation Reserve'),1,2000);
11079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11080  END IF;  
11081  IF 
11082 l_ledger_language = 'US' THEN
11083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11085  END IF;   
11089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11088   IF l_source IS NOT NULL THEN
11090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11091   END IF; 
11092  l_description := SUBSTR(l_description,1,1996);
11093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11094         trace
11095            (p_msg      => 'END of Description_109'
11096            ,p_level    => C_LEVEL_PROCEDURE
11097            ,p_module   => l_log_module);
11098 
11099   END IF;
11100   RETURN l_description;
11101 
11102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11103       trace
11107 END IF;
11104          (p_msg      => 'END of Description_109'
11105          ,p_level    => C_LEVEL_PROCEDURE
11106          ,p_module   => l_log_module);
11108 RETURN NULL;
11109 EXCEPTION
11110   WHEN VALUE_ERROR THEN
11111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11112             trace
11113                (p_msg      => 'ERROR: '||sqlerrm
11114                ,p_level    => C_LEVEL_EXCEPTION
11115                ,p_module   => l_log_module);
11116      END IF;
11117      RAISE;
11118  WHEN xla_exceptions_pkg.application_exception THEN
11119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11120       trace
11121          (p_msg      => 'ERROR: '||sqlerrm
11122          ,p_level    => C_LEVEL_EXCEPTION
11123          ,p_module   => l_log_module);
11124       END IF;
11125       RAISE;
11126  WHEN OTHERS THEN
11127        xla_exceptions_pkg.raise_message
11128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_109');
11129 END Description_109;
11130 
11131 ---------------------------------------
11132 --
11133 -- PRIVATE FUNCTION
11134 --         Description_110
11135 --
11136 ---------------------------------------
11137 FUNCTION Description_110 (
11138   p_application_id      IN NUMBER
11139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11140 --Period Close Date
11141  , p_source_1            IN DATE
11142 )
11143 RETURN VARCHAR2
11144 IS
11145 l_component_type        VARCHAR2(80)   ;
11146 l_component_code        VARCHAR2(30)   ;
11147 l_component_type_code   VARCHAR2(1)    ;
11148 l_component_appl_id     INTEGER        ;
11149 l_amb_context_code      VARCHAR2(30)   ;
11150 l_ledger_language       VARCHAR2(30)   ;
11151 l_source                VARCHAR2(1996) ;
11152 l_description           VARCHAR2(2000) ;
11153 l_log_module            VARCHAR2(240)  ;
11154 BEGIN
11155 IF g_log_enabled THEN
11156       l_log_module := C_DEFAULT_MODULE||'.Description_110';
11157 END IF;
11158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11159       trace
11160          (p_msg      => 'BEGIN of Description_110'
11161          ,p_level    => C_LEVEL_PROCEDURE
11162          ,p_module   => l_log_module);
11163 END IF;
11164 
11165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11166 l_component_type        := 'AMB_DESCRIPTION';
11167 l_component_code        := 'FA_SLT_COST';
11168 l_component_type_code   := 'S';
11169 l_component_appl_id     :=  140;
11170 l_amb_context_code      := 'DEFAULT';
11171 l_source                := NULL;
11172 l_description           := NULL;
11173 
11174 
11175  
11176  IF 
11177 l_ledger_language = 'US' THEN
11178     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer Cost'),1,2000);
11179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11180  END IF;  
11181  IF 
11182 l_ledger_language = 'US' THEN
11183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11185  END IF;   
11186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11188   IF l_source IS NOT NULL THEN
11189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11191   END IF; 
11192  l_description := SUBSTR(l_description,1,1996);
11193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11194         trace
11195            (p_msg      => 'END of Description_110'
11196            ,p_level    => C_LEVEL_PROCEDURE
11197            ,p_module   => l_log_module);
11198 
11199   END IF;
11200   RETURN l_description;
11201 
11202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11203       trace
11204          (p_msg      => 'END of Description_110'
11205          ,p_level    => C_LEVEL_PROCEDURE
11206          ,p_module   => l_log_module);
11207 END IF;
11208 RETURN NULL;
11209 EXCEPTION
11210   WHEN VALUE_ERROR THEN
11211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11212             trace
11213                (p_msg      => 'ERROR: '||sqlerrm
11214                ,p_level    => C_LEVEL_EXCEPTION
11215                ,p_module   => l_log_module);
11216      END IF;
11217      RAISE;
11218  WHEN xla_exceptions_pkg.application_exception THEN
11219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11220       trace
11221          (p_msg      => 'ERROR: '||sqlerrm
11222          ,p_level    => C_LEVEL_EXCEPTION
11223          ,p_module   => l_log_module);
11224       END IF;
11225       RAISE;
11226  WHEN OTHERS THEN
11227        xla_exceptions_pkg.raise_message
11228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_110');
11229 END Description_110;
11230 
11231 ---------------------------------------
11232 --
11233 -- PRIVATE FUNCTION
11234 --         Description_111
11235 --
11236 ---------------------------------------
11237 FUNCTION Description_111 (
11238   p_application_id      IN NUMBER
11239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11240 --Period Close Date
11241  , p_source_1            IN DATE
11242 )
11243 RETURN VARCHAR2
11244 IS
11245 l_component_type        VARCHAR2(80)   ;
11246 l_component_code        VARCHAR2(30)   ;
11247 l_component_type_code   VARCHAR2(1)    ;
11248 l_component_appl_id     INTEGER        ;
11249 l_amb_context_code      VARCHAR2(30)   ;
11250 l_ledger_language       VARCHAR2(30)   ;
11251 l_source                VARCHAR2(1996) ;
11252 l_description           VARCHAR2(2000) ;
11253 l_log_module            VARCHAR2(240)  ;
11254 BEGIN
11255 IF g_log_enabled THEN
11256       l_log_module := C_DEFAULT_MODULE||'.Description_111';
11257 END IF;
11261          ,p_level    => C_LEVEL_PROCEDURE
11258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11259       trace
11260          (p_msg      => 'BEGIN of Description_111'
11262          ,p_module   => l_log_module);
11263 END IF;
11267 l_component_code        := 'FA_SLT_COST_CLR';
11264 
11265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11266 l_component_type        := 'AMB_DESCRIPTION';
11268 l_component_type_code   := 'S';
11269 l_component_appl_id     :=  140;
11270 l_amb_context_code      := 'DEFAULT';
11271 l_source                := NULL;
11272 l_description           := NULL;
11273 
11274 
11275  
11276  IF 
11277 l_ledger_language = 'US' THEN
11278     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer Cost Clearing'),1,2000);
11279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11280  END IF;  
11281  IF 
11282 l_ledger_language = 'US' THEN
11283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11285  END IF;   
11286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11288   IF l_source IS NOT NULL THEN
11289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11291   END IF; 
11292  l_description := SUBSTR(l_description,1,1996);
11293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11294         trace
11295            (p_msg      => 'END of Description_111'
11296            ,p_level    => C_LEVEL_PROCEDURE
11297            ,p_module   => l_log_module);
11298 
11299   END IF;
11300   RETURN l_description;
11301 
11302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11303       trace
11304          (p_msg      => 'END of Description_111'
11305          ,p_level    => C_LEVEL_PROCEDURE
11306          ,p_module   => l_log_module);
11307 END IF;
11308 RETURN NULL;
11309 EXCEPTION
11310   WHEN VALUE_ERROR THEN
11311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11312             trace
11313                (p_msg      => 'ERROR: '||sqlerrm
11314                ,p_level    => C_LEVEL_EXCEPTION
11315                ,p_module   => l_log_module);
11316      END IF;
11317      RAISE;
11318  WHEN xla_exceptions_pkg.application_exception THEN
11319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11320       trace
11321          (p_msg      => 'ERROR: '||sqlerrm
11322          ,p_level    => C_LEVEL_EXCEPTION
11323          ,p_module   => l_log_module);
11324       END IF;
11325       RAISE;
11326  WHEN OTHERS THEN
11327        xla_exceptions_pkg.raise_message
11328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_111');
11329 END Description_111;
11330 
11331 ---------------------------------------
11332 --
11333 -- PRIVATE FUNCTION
11334 --         Description_112
11335 --
11336 ---------------------------------------
11337 FUNCTION Description_112 (
11338   p_application_id      IN NUMBER
11339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11340 --Period Close Date
11341  , p_source_1            IN DATE
11342 )
11343 RETURN VARCHAR2
11344 IS
11345 l_component_type        VARCHAR2(80)   ;
11346 l_component_code        VARCHAR2(30)   ;
11347 l_component_type_code   VARCHAR2(1)    ;
11348 l_component_appl_id     INTEGER        ;
11349 l_amb_context_code      VARCHAR2(30)   ;
11350 l_ledger_language       VARCHAR2(30)   ;
11351 l_source                VARCHAR2(1996) ;
11352 l_description           VARCHAR2(2000) ;
11353 l_log_module            VARCHAR2(240)  ;
11354 BEGIN
11355 IF g_log_enabled THEN
11356       l_log_module := C_DEFAULT_MODULE||'.Description_112';
11357 END IF;
11358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11359       trace
11360          (p_msg      => 'BEGIN of Description_112'
11361          ,p_level    => C_LEVEL_PROCEDURE
11362          ,p_module   => l_log_module);
11363 END IF;
11364 
11365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11366 l_component_type        := 'AMB_DESCRIPTION';
11367 l_component_code        := 'FA_SLT_DEPRN_EXP';
11368 l_component_type_code   := 'S';
11369 l_component_appl_id     :=  140;
11370 l_amb_context_code      := 'DEFAULT';
11371 l_source                := NULL;
11372 l_description           := NULL;
11373 
11374 
11375  
11376  IF 
11377 l_ledger_language = 'US' THEN
11378     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer Depreciation Expense'),1,2000);
11379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11380  END IF;  
11381  IF 
11385  END IF;   
11382 l_ledger_language = 'US' THEN
11383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11388   IF l_source IS NOT NULL THEN
11389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11391   END IF; 
11392  l_description := SUBSTR(l_description,1,1996);
11393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11394         trace
11395            (p_msg      => 'END of Description_112'
11396            ,p_level    => C_LEVEL_PROCEDURE
11397            ,p_module   => l_log_module);
11398 
11399   END IF;
11400   RETURN l_description;
11401 
11402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11403       trace
11404          (p_msg      => 'END of Description_112'
11405          ,p_level    => C_LEVEL_PROCEDURE
11406          ,p_module   => l_log_module);
11407 END IF;
11408 RETURN NULL;
11409 EXCEPTION
11410   WHEN VALUE_ERROR THEN
11411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11412             trace
11413                (p_msg      => 'ERROR: '||sqlerrm
11414                ,p_level    => C_LEVEL_EXCEPTION
11415                ,p_module   => l_log_module);
11416      END IF;
11417      RAISE;
11418  WHEN xla_exceptions_pkg.application_exception THEN
11419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11420       trace
11421          (p_msg      => 'ERROR: '||sqlerrm
11422          ,p_level    => C_LEVEL_EXCEPTION
11423          ,p_module   => l_log_module);
11424       END IF;
11425       RAISE;
11426  WHEN OTHERS THEN
11427        xla_exceptions_pkg.raise_message
11428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_112');
11429 END Description_112;
11430 
11431 ---------------------------------------
11432 --
11433 -- PRIVATE FUNCTION
11434 --         Description_113
11435 --
11436 ---------------------------------------
11437 FUNCTION Description_113 (
11438   p_application_id      IN NUMBER
11439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11440 --Period Close Date
11441  , p_source_1            IN DATE
11442 )
11443 RETURN VARCHAR2
11444 IS
11445 l_component_type        VARCHAR2(80)   ;
11446 l_component_code        VARCHAR2(30)   ;
11447 l_component_type_code   VARCHAR2(1)    ;
11448 l_component_appl_id     INTEGER        ;
11449 l_amb_context_code      VARCHAR2(30)   ;
11450 l_ledger_language       VARCHAR2(30)   ;
11451 l_source                VARCHAR2(1996) ;
11452 l_description           VARCHAR2(2000) ;
11453 l_log_module            VARCHAR2(240)  ;
11454 BEGIN
11455 IF g_log_enabled THEN
11456       l_log_module := C_DEFAULT_MODULE||'.Description_113';
11457 END IF;
11458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11459       trace
11460          (p_msg      => 'BEGIN of Description_113'
11461          ,p_level    => C_LEVEL_PROCEDURE
11462          ,p_module   => l_log_module);
11463 END IF;
11464 
11465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11466 l_component_type        := 'AMB_DESCRIPTION';
11467 l_component_code        := 'FA_SLT_DEPRN_RESERVE';
11468 l_component_type_code   := 'S';
11469 l_component_appl_id     :=  140;
11470 l_amb_context_code      := 'DEFAULT';
11471 l_source                := NULL;
11472 l_description           := NULL;
11473 
11474 
11475  
11476  IF 
11477 l_ledger_language = 'US' THEN
11478     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer Depreciation Reserve'),1,2000);
11479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11480  END IF;  
11481  IF 
11482 l_ledger_language = 'US' THEN
11483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11485  END IF;   
11486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11488   IF l_source IS NOT NULL THEN
11489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11491   END IF; 
11492  l_description := SUBSTR(l_description,1,1996);
11493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11494         trace
11495            (p_msg      => 'END of Description_113'
11496            ,p_level    => C_LEVEL_PROCEDURE
11497            ,p_module   => l_log_module);
11498 
11499   END IF;
11500   RETURN l_description;
11501 
11502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11503       trace
11504          (p_msg      => 'END of Description_113'
11505          ,p_level    => C_LEVEL_PROCEDURE
11506          ,p_module   => l_log_module);
11507 END IF;
11508 RETURN NULL;
11509 EXCEPTION
11510   WHEN VALUE_ERROR THEN
11511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11512             trace
11513                (p_msg      => 'ERROR: '||sqlerrm
11514                ,p_level    => C_LEVEL_EXCEPTION
11515                ,p_module   => l_log_module);
11516      END IF;
11517      RAISE;
11518  WHEN xla_exceptions_pkg.application_exception THEN
11519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11520       trace
11521          (p_msg      => 'ERROR: '||sqlerrm
11522          ,p_level    => C_LEVEL_EXCEPTION
11523          ,p_module   => l_log_module);
11524       END IF;
11525       RAISE;
11526  WHEN OTHERS THEN
11527        xla_exceptions_pkg.raise_message
11528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_113');
11529 END Description_113;
11533 -- PRIVATE FUNCTION
11530 
11531 ---------------------------------------
11532 --
11534 --         Description_114
11535 --
11536 ---------------------------------------
11537 FUNCTION Description_114 (
11538   p_application_id      IN NUMBER
11539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11540 --Period Close Date
11541  , p_source_1            IN DATE
11542 )
11543 RETURN VARCHAR2
11544 IS
11545 l_component_type        VARCHAR2(80)   ;
11546 l_component_code        VARCHAR2(30)   ;
11547 l_component_type_code   VARCHAR2(1)    ;
11548 l_component_appl_id     INTEGER        ;
11549 l_amb_context_code      VARCHAR2(30)   ;
11550 l_ledger_language       VARCHAR2(30)   ;
11551 l_source                VARCHAR2(1996) ;
11552 l_description           VARCHAR2(2000) ;
11553 l_log_module            VARCHAR2(240)  ;
11554 BEGIN
11555 IF g_log_enabled THEN
11556       l_log_module := C_DEFAULT_MODULE||'.Description_114';
11557 END IF;
11558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11559       trace
11560          (p_msg      => 'BEGIN of Description_114'
11561          ,p_level    => C_LEVEL_PROCEDURE
11562          ,p_module   => l_log_module);
11563 END IF;
11564 
11565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11566 l_component_type        := 'AMB_DESCRIPTION';
11567 l_component_code        := 'FA_SLT_IC_PAY';
11568 l_component_type_code   := 'S';
11569 l_component_appl_id     :=  140;
11570 l_amb_context_code      := 'DEFAULT';
11571 l_source                := NULL;
11572 l_description           := NULL;
11573 
11574 
11575  
11576  IF 
11577 l_ledger_language = 'US' THEN
11578     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer Intercompany Payable'),1,2000);
11579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11580  END IF;  
11581  IF 
11582 l_ledger_language = 'US' THEN
11583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11585  END IF;   
11586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11588   IF l_source IS NOT NULL THEN
11589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11591   END IF; 
11592  l_description := SUBSTR(l_description,1,1996);
11593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11594         trace
11595            (p_msg      => 'END of Description_114'
11596            ,p_level    => C_LEVEL_PROCEDURE
11597            ,p_module   => l_log_module);
11598 
11599   END IF;
11600   RETURN l_description;
11601 
11602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11603       trace
11604          (p_msg      => 'END of Description_114'
11605          ,p_level    => C_LEVEL_PROCEDURE
11606          ,p_module   => l_log_module);
11607 END IF;
11608 RETURN NULL;
11609 EXCEPTION
11610   WHEN VALUE_ERROR THEN
11611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11612             trace
11613                (p_msg      => 'ERROR: '||sqlerrm
11614                ,p_level    => C_LEVEL_EXCEPTION
11615                ,p_module   => l_log_module);
11616      END IF;
11617      RAISE;
11618  WHEN xla_exceptions_pkg.application_exception THEN
11619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11620       trace
11621          (p_msg      => 'ERROR: '||sqlerrm
11622          ,p_level    => C_LEVEL_EXCEPTION
11623          ,p_module   => l_log_module);
11624       END IF;
11625       RAISE;
11626  WHEN OTHERS THEN
11627        xla_exceptions_pkg.raise_message
11628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_114');
11629 END Description_114;
11630 
11631 ---------------------------------------
11632 --
11633 -- PRIVATE FUNCTION
11634 --         Description_115
11635 --
11636 ---------------------------------------
11637 FUNCTION Description_115 (
11638   p_application_id      IN NUMBER
11639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11640 --Period Close Date
11641  , p_source_1            IN DATE
11642 )
11643 RETURN VARCHAR2
11644 IS
11645 l_component_type        VARCHAR2(80)   ;
11646 l_component_code        VARCHAR2(30)   ;
11647 l_component_type_code   VARCHAR2(1)    ;
11648 l_component_appl_id     INTEGER        ;
11649 l_amb_context_code      VARCHAR2(30)   ;
11650 l_ledger_language       VARCHAR2(30)   ;
11651 l_source                VARCHAR2(1996) ;
11652 l_description           VARCHAR2(2000) ;
11653 l_log_module            VARCHAR2(240)  ;
11654 BEGIN
11655 IF g_log_enabled THEN
11656       l_log_module := C_DEFAULT_MODULE||'.Description_115';
11657 END IF;
11658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11659       trace
11660          (p_msg      => 'BEGIN of Description_115'
11661          ,p_level    => C_LEVEL_PROCEDURE
11662          ,p_module   => l_log_module);
11663 END IF;
11664 
11665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11666 l_component_type        := 'AMB_DESCRIPTION';
11667 l_component_code        := 'FA_SLT_IC_REC';
11668 l_component_type_code   := 'S';
11669 l_component_appl_id     :=  140;
11670 l_amb_context_code      := 'DEFAULT';
11671 l_source                := NULL;
11672 l_description           := NULL;
11673 
11674 
11675  
11676  IF 
11677 l_ledger_language = 'US' THEN
11678     l_description :=  SUBSTR(CONCAT(l_description,'Source LineTransfer Intercompany Receivable'),1,2000);
11679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11680  END IF;  
11681  IF 
11682 l_ledger_language = 'US' THEN
11686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11685  END IF;   
11687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11688   IF l_source IS NOT NULL THEN
11689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11691   END IF; 
11692  l_description := SUBSTR(l_description,1,1996);
11693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11694         trace
11695            (p_msg      => 'END of Description_115'
11696            ,p_level    => C_LEVEL_PROCEDURE
11697            ,p_module   => l_log_module);
11698 
11699   END IF;
11700   RETURN l_description;
11701 
11702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11703       trace
11704          (p_msg      => 'END of Description_115'
11705          ,p_level    => C_LEVEL_PROCEDURE
11706          ,p_module   => l_log_module);
11707 END IF;
11708 RETURN NULL;
11709 EXCEPTION
11710   WHEN VALUE_ERROR THEN
11711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11712             trace
11713                (p_msg      => 'ERROR: '||sqlerrm
11714                ,p_level    => C_LEVEL_EXCEPTION
11715                ,p_module   => l_log_module);
11716      END IF;
11717      RAISE;
11718  WHEN xla_exceptions_pkg.application_exception THEN
11719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11720       trace
11721          (p_msg      => 'ERROR: '||sqlerrm
11722          ,p_level    => C_LEVEL_EXCEPTION
11723          ,p_module   => l_log_module);
11724       END IF;
11725       RAISE;
11726  WHEN OTHERS THEN
11727        xla_exceptions_pkg.raise_message
11728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_115');
11729 END Description_115;
11730 
11731 ---------------------------------------
11732 --
11733 -- PRIVATE FUNCTION
11734 --         Description_116
11735 --
11736 ---------------------------------------
11737 FUNCTION Description_116 (
11738   p_application_id      IN NUMBER
11739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11740 --Period Close Date
11741  , p_source_1            IN DATE
11742 )
11743 RETURN VARCHAR2
11744 IS
11745 l_component_type        VARCHAR2(80)   ;
11746 l_component_code        VARCHAR2(30)   ;
11747 l_component_type_code   VARCHAR2(1)    ;
11748 l_component_appl_id     INTEGER        ;
11749 l_amb_context_code      VARCHAR2(30)   ;
11750 l_ledger_language       VARCHAR2(30)   ;
11751 l_source                VARCHAR2(1996) ;
11752 l_description           VARCHAR2(2000) ;
11753 l_log_module            VARCHAR2(240)  ;
11754 BEGIN
11755 IF g_log_enabled THEN
11756       l_log_module := C_DEFAULT_MODULE||'.Description_116';
11757 END IF;
11758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11759       trace
11760          (p_msg      => 'BEGIN of Description_116'
11761          ,p_level    => C_LEVEL_PROCEDURE
11762          ,p_module   => l_log_module);
11763 END IF;
11764 
11765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11766 l_component_type        := 'AMB_DESCRIPTION';
11767 l_component_code        := 'FA_SLT_REVAL_RESERVE';
11768 l_component_type_code   := 'S';
11769 l_component_appl_id     :=  140;
11770 l_amb_context_code      := 'DEFAULT';
11771 l_source                := NULL;
11772 l_description           := NULL;
11773 
11774 
11775  
11776  IF 
11777 l_ledger_language = 'US' THEN
11778     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer Revaluation Reserve'),1,2000);
11779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11780  END IF;  
11781  IF 
11782 l_ledger_language = 'US' THEN
11783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11785  END IF;   
11786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11788   IF l_source IS NOT NULL THEN
11789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11791   END IF; 
11792  l_description := SUBSTR(l_description,1,1996);
11793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11794         trace
11795            (p_msg      => 'END of Description_116'
11796            ,p_level    => C_LEVEL_PROCEDURE
11797            ,p_module   => l_log_module);
11798 
11799   END IF;
11800   RETURN l_description;
11801 
11802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11803       trace
11804          (p_msg      => 'END of Description_116'
11805          ,p_level    => C_LEVEL_PROCEDURE
11806          ,p_module   => l_log_module);
11807 END IF;
11808 RETURN NULL;
11809 EXCEPTION
11810   WHEN VALUE_ERROR THEN
11811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11812             trace
11813                (p_msg      => 'ERROR: '||sqlerrm
11814                ,p_level    => C_LEVEL_EXCEPTION
11815                ,p_module   => l_log_module);
11816      END IF;
11817      RAISE;
11818  WHEN xla_exceptions_pkg.application_exception THEN
11819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11820       trace
11821          (p_msg      => 'ERROR: '||sqlerrm
11822          ,p_level    => C_LEVEL_EXCEPTION
11823          ,p_module   => l_log_module);
11824       END IF;
11825       RAISE;
11826  WHEN OTHERS THEN
11827        xla_exceptions_pkg.raise_message
11828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_116');
11829 END Description_116;
11830 
11834 --         Description_117
11831 ---------------------------------------
11832 --
11833 -- PRIVATE FUNCTION
11835 --
11836 ---------------------------------------
11837 FUNCTION Description_117 (
11838   p_application_id      IN NUMBER
11839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11840 --Period Close Date
11841  , p_source_1            IN DATE
11842 )
11843 RETURN VARCHAR2
11844 IS
11845 l_component_type        VARCHAR2(80)   ;
11846 l_component_code        VARCHAR2(30)   ;
11847 l_component_type_code   VARCHAR2(1)    ;
11848 l_component_appl_id     INTEGER        ;
11849 l_amb_context_code      VARCHAR2(30)   ;
11850 l_ledger_language       VARCHAR2(30)   ;
11851 l_source                VARCHAR2(1996) ;
11852 l_description           VARCHAR2(2000) ;
11853 l_log_module            VARCHAR2(240)  ;
11854 BEGIN
11855 IF g_log_enabled THEN
11856       l_log_module := C_DEFAULT_MODULE||'.Description_117';
11857 END IF;
11858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11859       trace
11860          (p_msg      => 'BEGIN of Description_117'
11861          ,p_level    => C_LEVEL_PROCEDURE
11862          ,p_module   => l_log_module);
11863 END IF;
11864 
11865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11866 l_component_type        := 'AMB_DESCRIPTION';
11867 l_component_code        := 'FA_SOURCE_LINE_TRANSFER';
11868 l_component_type_code   := 'S';
11869 l_component_appl_id     :=  140;
11870 l_amb_context_code      := 'DEFAULT';
11871 l_source                := NULL;
11872 l_description           := NULL;
11873 
11874 
11875  
11876  IF 
11877 l_ledger_language = 'US' THEN
11878     l_description :=  SUBSTR(CONCAT(l_description,'Source Line Transfer'),1,2000);
11879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11880  END IF;  
11881  IF 
11882 l_ledger_language = 'US' THEN
11883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11885  END IF;   
11886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11888   IF l_source IS NOT NULL THEN
11889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11891   END IF; 
11892  l_description := SUBSTR(l_description,1,1996);
11893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11894         trace
11895            (p_msg      => 'END of Description_117'
11896            ,p_level    => C_LEVEL_PROCEDURE
11897            ,p_module   => l_log_module);
11898 
11899   END IF;
11900   RETURN l_description;
11901 
11902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11903       trace
11904          (p_msg      => 'END of Description_117'
11905          ,p_level    => C_LEVEL_PROCEDURE
11906          ,p_module   => l_log_module);
11907 END IF;
11908 RETURN NULL;
11909 EXCEPTION
11910   WHEN VALUE_ERROR THEN
11911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11912             trace
11913                (p_msg      => 'ERROR: '||sqlerrm
11914                ,p_level    => C_LEVEL_EXCEPTION
11915                ,p_module   => l_log_module);
11916      END IF;
11917      RAISE;
11918  WHEN xla_exceptions_pkg.application_exception THEN
11919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11920       trace
11921          (p_msg      => 'ERROR: '||sqlerrm
11922          ,p_level    => C_LEVEL_EXCEPTION
11923          ,p_module   => l_log_module);
11924       END IF;
11925       RAISE;
11926  WHEN OTHERS THEN
11927        xla_exceptions_pkg.raise_message
11928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_117');
11929 END Description_117;
11930 
11931 ---------------------------------------
11932 --
11933 -- PRIVATE FUNCTION
11934 --         Description_118
11935 --
11936 ---------------------------------------
11937 FUNCTION Description_118 (
11938   p_application_id      IN NUMBER
11939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
11940 --Period Close Date
11941  , p_source_1            IN DATE
11942 )
11943 RETURN VARCHAR2
11944 IS
11945 l_component_type        VARCHAR2(80)   ;
11946 l_component_code        VARCHAR2(30)   ;
11947 l_component_type_code   VARCHAR2(1)    ;
11948 l_component_appl_id     INTEGER        ;
11949 l_amb_context_code      VARCHAR2(30)   ;
11950 l_ledger_language       VARCHAR2(30)   ;
11951 l_source                VARCHAR2(1996) ;
11952 l_description           VARCHAR2(2000) ;
11953 l_log_module            VARCHAR2(240)  ;
11954 BEGIN
11955 IF g_log_enabled THEN
11956       l_log_module := C_DEFAULT_MODULE||'.Description_118';
11957 END IF;
11958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11959       trace
11960          (p_msg      => 'BEGIN of Description_118'
11961          ,p_level    => C_LEVEL_PROCEDURE
11962          ,p_module   => l_log_module);
11963 END IF;
11964 
11965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
11966 l_component_type        := 'AMB_DESCRIPTION';
11967 l_component_code        := 'FA_TAX_DEPRN_RESERVE';
11968 l_component_type_code   := 'S';
11969 l_component_appl_id     :=  140;
11970 l_amb_context_code      := 'DEFAULT';
11971 l_source                := NULL;
11972 l_description           := NULL;
11973 
11974 
11975  
11976  IF 
11977 l_ledger_language = 'US' THEN
11978     l_description :=  SUBSTR(CONCAT(l_description,'Tax Depreciation Reserve'),1,2000);
11979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11980  END IF;  
11981  IF 
11982 l_ledger_language = 'US' THEN
11986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
11983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
11984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
11985  END IF;   
11987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
11988   IF l_source IS NOT NULL THEN
11989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
11990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
11991   END IF; 
11992  l_description := SUBSTR(l_description,1,1996);
11993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11994         trace
11995            (p_msg      => 'END of Description_118'
11996            ,p_level    => C_LEVEL_PROCEDURE
11997            ,p_module   => l_log_module);
11998 
11999   END IF;
12000   RETURN l_description;
12001 
12002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12003       trace
12004          (p_msg      => 'END of Description_118'
12005          ,p_level    => C_LEVEL_PROCEDURE
12006          ,p_module   => l_log_module);
12007 END IF;
12008 RETURN NULL;
12009 EXCEPTION
12010   WHEN VALUE_ERROR THEN
12011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12012             trace
12013                (p_msg      => 'ERROR: '||sqlerrm
12014                ,p_level    => C_LEVEL_EXCEPTION
12015                ,p_module   => l_log_module);
12016      END IF;
12017      RAISE;
12018  WHEN xla_exceptions_pkg.application_exception THEN
12019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12020       trace
12021          (p_msg      => 'ERROR: '||sqlerrm
12022          ,p_level    => C_LEVEL_EXCEPTION
12023          ,p_module   => l_log_module);
12024       END IF;
12025       RAISE;
12026  WHEN OTHERS THEN
12027        xla_exceptions_pkg.raise_message
12028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_118');
12029 END Description_118;
12030 
12031 ---------------------------------------
12032 --
12033 -- PRIVATE FUNCTION
12034 --         Description_119
12035 --
12036 ---------------------------------------
12037 FUNCTION Description_119 (
12038   p_application_id      IN NUMBER
12039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12040 --Period Close Date
12041  , p_source_1            IN DATE
12042 )
12043 RETURN VARCHAR2
12044 IS
12045 l_component_type        VARCHAR2(80)   ;
12046 l_component_code        VARCHAR2(30)   ;
12047 l_component_type_code   VARCHAR2(1)    ;
12048 l_component_appl_id     INTEGER        ;
12049 l_amb_context_code      VARCHAR2(30)   ;
12050 l_ledger_language       VARCHAR2(30)   ;
12051 l_source                VARCHAR2(1996) ;
12052 l_description           VARCHAR2(2000) ;
12053 l_log_module            VARCHAR2(240)  ;
12054 BEGIN
12055 IF g_log_enabled THEN
12056       l_log_module := C_DEFAULT_MODULE||'.Description_119';
12057 END IF;
12058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12059       trace
12060          (p_msg      => 'BEGIN of Description_119'
12061          ,p_level    => C_LEVEL_PROCEDURE
12062          ,p_module   => l_log_module);
12063 END IF;
12064 
12065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12066 l_component_type        := 'AMB_DESCRIPTION';
12067 l_component_code        := 'FA_TERM_GAIN_LOSS';
12068 l_component_type_code   := 'S';
12069 l_component_appl_id     :=  140;
12070 l_amb_context_code      := 'DEFAULT';
12071 l_source                := NULL;
12072 l_description           := NULL;
12073 
12074 
12075  
12076  IF 
12077 l_ledger_language = 'US' THEN
12078     l_description :=  SUBSTR(CONCAT(l_description,'Terminal Gain and Loss'),1,2000);
12079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12080  END IF;  
12081  IF 
12082 l_ledger_language = 'US' THEN
12083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12085  END IF;   
12086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12088   IF l_source IS NOT NULL THEN
12089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12091   END IF; 
12092  l_description := SUBSTR(l_description,1,1996);
12093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12094         trace
12095            (p_msg      => 'END of Description_119'
12096            ,p_level    => C_LEVEL_PROCEDURE
12097            ,p_module   => l_log_module);
12098 
12099   END IF;
12100   RETURN l_description;
12101 
12102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12103       trace
12104          (p_msg      => 'END of Description_119'
12105          ,p_level    => C_LEVEL_PROCEDURE
12106          ,p_module   => l_log_module);
12107 END IF;
12108 RETURN NULL;
12109 EXCEPTION
12110   WHEN VALUE_ERROR THEN
12111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12112             trace
12113                (p_msg      => 'ERROR: '||sqlerrm
12114                ,p_level    => C_LEVEL_EXCEPTION
12115                ,p_module   => l_log_module);
12116      END IF;
12117      RAISE;
12118  WHEN xla_exceptions_pkg.application_exception THEN
12119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12120       trace
12121          (p_msg      => 'ERROR: '||sqlerrm
12122          ,p_level    => C_LEVEL_EXCEPTION
12123          ,p_module   => l_log_module);
12124       END IF;
12125       RAISE;
12126  WHEN OTHERS THEN
12127        xla_exceptions_pkg.raise_message
12128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_119');
12129 END Description_119;
12130 
12131 ---------------------------------------
12135 --
12132 --
12133 -- PRIVATE FUNCTION
12134 --         Description_120
12136 ---------------------------------------
12137 FUNCTION Description_120 (
12138   p_application_id      IN NUMBER
12139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12140 --Period Close Date
12141  , p_source_1            IN DATE
12142 )
12143 RETURN VARCHAR2
12144 IS
12145 l_component_type        VARCHAR2(80)   ;
12146 l_component_code        VARCHAR2(30)   ;
12147 l_component_type_code   VARCHAR2(1)    ;
12148 l_component_appl_id     INTEGER        ;
12149 l_amb_context_code      VARCHAR2(30)   ;
12150 l_ledger_language       VARCHAR2(30)   ;
12151 l_source                VARCHAR2(1996) ;
12152 l_description           VARCHAR2(2000) ;
12153 l_log_module            VARCHAR2(240)  ;
12154 BEGIN
12155 IF g_log_enabled THEN
12156       l_log_module := C_DEFAULT_MODULE||'.Description_120';
12157 END IF;
12158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12159       trace
12160          (p_msg      => 'BEGIN of Description_120'
12161          ,p_level    => C_LEVEL_PROCEDURE
12162          ,p_module   => l_log_module);
12163 END IF;
12164 
12165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12166 l_component_type        := 'AMB_DESCRIPTION';
12167 l_component_code        := 'FA_TGL_NBV_RETIRED_GAIN';
12168 l_component_type_code   := 'S';
12169 l_component_appl_id     :=  140;
12170 l_amb_context_code      := 'DEFAULT';
12171 l_source                := NULL;
12172 l_description           := NULL;
12173 
12174 
12175  
12176  IF 
12177 l_ledger_language = 'US' THEN
12178     l_description :=  SUBSTR(CONCAT(l_description,'Net Book Value Retired Gain'),1,2000);
12179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12180  END IF;  
12181  IF 
12182 l_ledger_language = 'US' THEN
12183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12185  END IF;   
12186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12188   IF l_source IS NOT NULL THEN
12189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12191   END IF; 
12192  l_description := SUBSTR(l_description,1,1996);
12193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12194         trace
12195            (p_msg      => 'END of Description_120'
12196            ,p_level    => C_LEVEL_PROCEDURE
12197            ,p_module   => l_log_module);
12198 
12199   END IF;
12200   RETURN l_description;
12201 
12202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12203       trace
12204          (p_msg      => 'END of Description_120'
12205          ,p_level    => C_LEVEL_PROCEDURE
12206          ,p_module   => l_log_module);
12207 END IF;
12208 RETURN NULL;
12209 EXCEPTION
12210   WHEN VALUE_ERROR THEN
12211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12212             trace
12213                (p_msg      => 'ERROR: '||sqlerrm
12214                ,p_level    => C_LEVEL_EXCEPTION
12215                ,p_module   => l_log_module);
12216      END IF;
12217      RAISE;
12218  WHEN xla_exceptions_pkg.application_exception THEN
12219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12220       trace
12221          (p_msg      => 'ERROR: '||sqlerrm
12222          ,p_level    => C_LEVEL_EXCEPTION
12223          ,p_module   => l_log_module);
12224       END IF;
12225       RAISE;
12226  WHEN OTHERS THEN
12227        xla_exceptions_pkg.raise_message
12228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_120');
12229 END Description_120;
12230 
12231 ---------------------------------------
12232 --
12233 -- PRIVATE FUNCTION
12234 --         Description_121
12235 --
12236 ---------------------------------------
12237 FUNCTION Description_121 (
12238   p_application_id      IN NUMBER
12239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12240 --Period Close Date
12241  , p_source_1            IN DATE
12242 )
12243 RETURN VARCHAR2
12244 IS
12245 l_component_type        VARCHAR2(80)   ;
12246 l_component_code        VARCHAR2(30)   ;
12247 l_component_type_code   VARCHAR2(1)    ;
12248 l_component_appl_id     INTEGER        ;
12249 l_amb_context_code      VARCHAR2(30)   ;
12250 l_ledger_language       VARCHAR2(30)   ;
12251 l_source                VARCHAR2(1996) ;
12252 l_description           VARCHAR2(2000) ;
12253 l_log_module            VARCHAR2(240)  ;
12254 BEGIN
12255 IF g_log_enabled THEN
12256       l_log_module := C_DEFAULT_MODULE||'.Description_121';
12257 END IF;
12258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12259       trace
12260          (p_msg      => 'BEGIN of Description_121'
12261          ,p_level    => C_LEVEL_PROCEDURE
12262          ,p_module   => l_log_module);
12263 END IF;
12264 
12265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12266 l_component_type        := 'AMB_DESCRIPTION';
12267 l_component_code        := 'FA_TGL_NBV_RETIRED_LOSS';
12268 l_component_type_code   := 'S';
12269 l_component_appl_id     :=  140;
12270 l_amb_context_code      := 'DEFAULT';
12271 l_source                := NULL;
12272 l_description           := NULL;
12273 
12274 
12275  
12276  IF 
12277 l_ledger_language = 'US' THEN
12278     l_description :=  SUBSTR(CONCAT(l_description,'Net Book Value Retired Loss'),1,2000);
12279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12280  END IF;  
12281  IF 
12282 l_ledger_language = 'US' THEN
12283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12285  END IF;   
12286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12288   IF l_source IS NOT NULL THEN
12289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12291   END IF; 
12292  l_description := SUBSTR(l_description,1,1996);
12293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12294         trace
12295            (p_msg      => 'END of Description_121'
12296            ,p_level    => C_LEVEL_PROCEDURE
12297            ,p_module   => l_log_module);
12298 
12299   END IF;
12300   RETURN l_description;
12301 
12302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12303       trace
12304          (p_msg      => 'END of Description_121'
12305          ,p_level    => C_LEVEL_PROCEDURE
12306          ,p_module   => l_log_module);
12307 END IF;
12308 RETURN NULL;
12309 EXCEPTION
12310   WHEN VALUE_ERROR THEN
12311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12312             trace
12313                (p_msg      => 'ERROR: '||sqlerrm
12314                ,p_level    => C_LEVEL_EXCEPTION
12315                ,p_module   => l_log_module);
12316      END IF;
12317      RAISE;
12318  WHEN xla_exceptions_pkg.application_exception THEN
12319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12320       trace
12321          (p_msg      => 'ERROR: '||sqlerrm
12322          ,p_level    => C_LEVEL_EXCEPTION
12323          ,p_module   => l_log_module);
12324       END IF;
12325       RAISE;
12326  WHEN OTHERS THEN
12327        xla_exceptions_pkg.raise_message
12328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_121');
12329 END Description_121;
12330 
12331 ---------------------------------------
12332 --
12333 -- PRIVATE FUNCTION
12334 --         Description_122
12335 --
12336 ---------------------------------------
12337 FUNCTION Description_122 (
12338   p_application_id      IN NUMBER
12339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12340 --Period Close Date
12341  , p_source_1            IN DATE
12342 )
12343 RETURN VARCHAR2
12344 IS
12345 l_component_type        VARCHAR2(80)   ;
12346 l_component_code        VARCHAR2(30)   ;
12347 l_component_type_code   VARCHAR2(1)    ;
12348 l_component_appl_id     INTEGER        ;
12349 l_amb_context_code      VARCHAR2(30)   ;
12350 l_ledger_language       VARCHAR2(30)   ;
12351 l_source                VARCHAR2(1996) ;
12352 l_description           VARCHAR2(2000) ;
12353 l_log_module            VARCHAR2(240)  ;
12354 BEGIN
12355 IF g_log_enabled THEN
12356       l_log_module := C_DEFAULT_MODULE||'.Description_122';
12357 END IF;
12358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12359       trace
12360          (p_msg      => 'BEGIN of Description_122'
12361          ,p_level    => C_LEVEL_PROCEDURE
12362          ,p_module   => l_log_module);
12363 END IF;
12364 
12365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12366 l_component_type        := 'AMB_DESCRIPTION';
12367 l_component_code        := 'FA_TGL_RES';
12368 l_component_type_code   := 'S';
12369 l_component_appl_id     :=  140;
12370 l_amb_context_code      := 'DEFAULT';
12371 l_source                := NULL;
12372 l_description           := NULL;
12373 
12374 
12375  
12376  IF 
12377 l_ledger_language = 'US' THEN
12378     l_description :=  SUBSTR(CONCAT(l_description,'Terminal Gain Loss Reserve'),1,2000);
12379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12380  END IF;  
12381  IF 
12382 l_ledger_language = 'US' THEN
12383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12385  END IF;   
12386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12388   IF l_source IS NOT NULL THEN
12389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12391   END IF; 
12392  l_description := SUBSTR(l_description,1,1996);
12393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12394         trace
12395            (p_msg      => 'END of Description_122'
12396            ,p_level    => C_LEVEL_PROCEDURE
12397            ,p_module   => l_log_module);
12398 
12399   END IF;
12400   RETURN l_description;
12401 
12402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12403       trace
12404          (p_msg      => 'END of Description_122'
12405          ,p_level    => C_LEVEL_PROCEDURE
12406          ,p_module   => l_log_module);
12407 END IF;
12408 RETURN NULL;
12409 EXCEPTION
12410   WHEN VALUE_ERROR THEN
12411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12412             trace
12413                (p_msg      => 'ERROR: '||sqlerrm
12414                ,p_level    => C_LEVEL_EXCEPTION
12415                ,p_module   => l_log_module);
12416      END IF;
12417      RAISE;
12418  WHEN xla_exceptions_pkg.application_exception THEN
12419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12420       trace
12421          (p_msg      => 'ERROR: '||sqlerrm
12422          ,p_level    => C_LEVEL_EXCEPTION
12423          ,p_module   => l_log_module);
12424       END IF;
12425       RAISE;
12426  WHEN OTHERS THEN
12427        xla_exceptions_pkg.raise_message
12428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_122');
12429 END Description_122;
12430 
12431 ---------------------------------------
12432 --
12433 -- PRIVATE FUNCTION
12437 FUNCTION Description_123 (
12434 --         Description_123
12435 --
12436 ---------------------------------------
12438   p_application_id      IN NUMBER
12439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12440 --Period Close Date
12441  , p_source_1            IN DATE
12442 )
12443 RETURN VARCHAR2
12444 IS
12445 l_component_type        VARCHAR2(80)   ;
12446 l_component_code        VARCHAR2(30)   ;
12447 l_component_type_code   VARCHAR2(1)    ;
12448 l_component_appl_id     INTEGER        ;
12449 l_amb_context_code      VARCHAR2(30)   ;
12450 l_ledger_language       VARCHAR2(30)   ;
12451 l_source                VARCHAR2(1996) ;
12452 l_description           VARCHAR2(2000) ;
12453 l_log_module            VARCHAR2(240)  ;
12454 BEGIN
12455 IF g_log_enabled THEN
12456       l_log_module := C_DEFAULT_MODULE||'.Description_123';
12457 END IF;
12458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12459       trace
12460          (p_msg      => 'BEGIN of Description_123'
12461          ,p_level    => C_LEVEL_PROCEDURE
12462          ,p_module   => l_log_module);
12463 END IF;
12464 
12465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12466 l_component_type        := 'AMB_DESCRIPTION';
12467 l_component_code        := 'FA_TRANSFER';
12468 l_component_type_code   := 'S';
12469 l_component_appl_id     :=  140;
12470 l_amb_context_code      := 'DEFAULT';
12471 l_source                := NULL;
12472 l_description           := NULL;
12473 
12474 
12475  
12476  IF 
12477 l_ledger_language = 'US' THEN
12478     l_description :=  SUBSTR(CONCAT(l_description,'Transfer'),1,2000);
12479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12480  END IF;  
12481  IF 
12482 l_ledger_language = 'US' THEN
12483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12485  END IF;   
12486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12488   IF l_source IS NOT NULL THEN
12489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12491   END IF; 
12492  l_description := SUBSTR(l_description,1,1996);
12493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12494         trace
12495            (p_msg      => 'END of Description_123'
12496            ,p_level    => C_LEVEL_PROCEDURE
12497            ,p_module   => l_log_module);
12498 
12499   END IF;
12500   RETURN l_description;
12501 
12502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12503       trace
12504          (p_msg      => 'END of Description_123'
12505          ,p_level    => C_LEVEL_PROCEDURE
12506          ,p_module   => l_log_module);
12507 END IF;
12508 RETURN NULL;
12509 EXCEPTION
12510   WHEN VALUE_ERROR THEN
12511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12512             trace
12513                (p_msg      => 'ERROR: '||sqlerrm
12514                ,p_level    => C_LEVEL_EXCEPTION
12515                ,p_module   => l_log_module);
12516      END IF;
12517      RAISE;
12518  WHEN xla_exceptions_pkg.application_exception THEN
12519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12520       trace
12521          (p_msg      => 'ERROR: '||sqlerrm
12522          ,p_level    => C_LEVEL_EXCEPTION
12523          ,p_module   => l_log_module);
12524       END IF;
12525       RAISE;
12526  WHEN OTHERS THEN
12527        xla_exceptions_pkg.raise_message
12528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_123');
12529 END Description_123;
12530 
12531 ---------------------------------------
12532 --
12533 -- PRIVATE FUNCTION
12534 --         Description_124
12535 --
12536 ---------------------------------------
12537 FUNCTION Description_124 (
12538   p_application_id      IN NUMBER
12539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12540 --Period Close Date
12541  , p_source_1            IN DATE
12542 )
12543 RETURN VARCHAR2
12544 IS
12545 l_component_type        VARCHAR2(80)   ;
12546 l_component_code        VARCHAR2(30)   ;
12547 l_component_type_code   VARCHAR2(1)    ;
12548 l_component_appl_id     INTEGER        ;
12549 l_amb_context_code      VARCHAR2(30)   ;
12550 l_ledger_language       VARCHAR2(30)   ;
12551 l_source                VARCHAR2(1996) ;
12552 l_description           VARCHAR2(2000) ;
12553 l_log_module            VARCHAR2(240)  ;
12554 BEGIN
12555 IF g_log_enabled THEN
12556       l_log_module := C_DEFAULT_MODULE||'.Description_124';
12557 END IF;
12558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12559       trace
12560          (p_msg      => 'BEGIN of Description_124'
12561          ,p_level    => C_LEVEL_PROCEDURE
12562          ,p_module   => l_log_module);
12563 END IF;
12564 
12565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12566 l_component_type        := 'AMB_DESCRIPTION';
12567 l_component_code        := 'FA_TRANSFER_BONUS_EXP';
12568 l_component_type_code   := 'S';
12569 l_component_appl_id     :=  140;
12570 l_amb_context_code      := 'DEFAULT';
12571 l_source                := NULL;
12572 l_description           := NULL;
12573 
12574 
12575  
12576  IF 
12577 l_ledger_language = 'US' THEN
12578     l_description :=  SUBSTR(CONCAT(l_description,'Transfer Bonus Depreciation Expense'),1,2000);
12579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12580  END IF;  
12581  IF 
12582 l_ledger_language = 'US' THEN
12583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12585  END IF;   
12589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12588   IF l_source IS NOT NULL THEN
12590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12591   END IF; 
12592  l_description := SUBSTR(l_description,1,1996);
12593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12594         trace
12595            (p_msg      => 'END of Description_124'
12596            ,p_level    => C_LEVEL_PROCEDURE
12597            ,p_module   => l_log_module);
12598 
12599   END IF;
12600   RETURN l_description;
12601 
12602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12603       trace
12604          (p_msg      => 'END of Description_124'
12605          ,p_level    => C_LEVEL_PROCEDURE
12606          ,p_module   => l_log_module);
12607 END IF;
12608 RETURN NULL;
12609 EXCEPTION
12610   WHEN VALUE_ERROR THEN
12611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12612             trace
12613                (p_msg      => 'ERROR: '||sqlerrm
12614                ,p_level    => C_LEVEL_EXCEPTION
12615                ,p_module   => l_log_module);
12616      END IF;
12617      RAISE;
12618  WHEN xla_exceptions_pkg.application_exception THEN
12619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12620       trace
12621          (p_msg      => 'ERROR: '||sqlerrm
12622          ,p_level    => C_LEVEL_EXCEPTION
12623          ,p_module   => l_log_module);
12624       END IF;
12625       RAISE;
12626  WHEN OTHERS THEN
12627        xla_exceptions_pkg.raise_message
12628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_124');
12629 END Description_124;
12630 
12631 ---------------------------------------
12632 --
12633 -- PRIVATE FUNCTION
12634 --         Description_125
12635 --
12636 ---------------------------------------
12637 FUNCTION Description_125 (
12638   p_application_id      IN NUMBER
12639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12640 --Period Close Date
12641  , p_source_1            IN DATE
12642 )
12643 RETURN VARCHAR2
12644 IS
12645 l_component_type        VARCHAR2(80)   ;
12646 l_component_code        VARCHAR2(30)   ;
12647 l_component_type_code   VARCHAR2(1)    ;
12648 l_component_appl_id     INTEGER        ;
12649 l_amb_context_code      VARCHAR2(30)   ;
12650 l_ledger_language       VARCHAR2(30)   ;
12651 l_source                VARCHAR2(1996) ;
12652 l_description           VARCHAR2(2000) ;
12653 l_log_module            VARCHAR2(240)  ;
12654 BEGIN
12655 IF g_log_enabled THEN
12656       l_log_module := C_DEFAULT_MODULE||'.Description_125';
12657 END IF;
12658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12659       trace
12660          (p_msg      => 'BEGIN of Description_125'
12661          ,p_level    => C_LEVEL_PROCEDURE
12662          ,p_module   => l_log_module);
12663 END IF;
12664 
12665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12666 l_component_type        := 'AMB_DESCRIPTION';
12667 l_component_code        := 'FA_TRANSFER_BONUS_RESERVE';
12668 l_component_type_code   := 'S';
12669 l_component_appl_id     :=  140;
12670 l_amb_context_code      := 'DEFAULT';
12671 l_source                := NULL;
12672 l_description           := NULL;
12673 
12674 
12675  
12676  IF 
12677 l_ledger_language = 'US' THEN
12678     l_description :=  SUBSTR(CONCAT(l_description,'Transfer Bonus Reserve'),1,2000);
12679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12680  END IF;  
12681  IF 
12682 l_ledger_language = 'US' THEN
12683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12685  END IF;   
12686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12688   IF l_source IS NOT NULL THEN
12689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12691   END IF; 
12692  l_description := SUBSTR(l_description,1,1996);
12693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12694         trace
12695            (p_msg      => 'END of Description_125'
12696            ,p_level    => C_LEVEL_PROCEDURE
12697            ,p_module   => l_log_module);
12698 
12699   END IF;
12700   RETURN l_description;
12701 
12702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12703       trace
12704          (p_msg      => 'END of Description_125'
12705          ,p_level    => C_LEVEL_PROCEDURE
12706          ,p_module   => l_log_module);
12707 END IF;
12708 RETURN NULL;
12709 EXCEPTION
12710   WHEN VALUE_ERROR THEN
12711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12712             trace
12713                (p_msg      => 'ERROR: '||sqlerrm
12714                ,p_level    => C_LEVEL_EXCEPTION
12715                ,p_module   => l_log_module);
12716      END IF;
12717      RAISE;
12718  WHEN xla_exceptions_pkg.application_exception THEN
12719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12720       trace
12721          (p_msg      => 'ERROR: '||sqlerrm
12722          ,p_level    => C_LEVEL_EXCEPTION
12723          ,p_module   => l_log_module);
12724       END IF;
12725       RAISE;
12726  WHEN OTHERS THEN
12727        xla_exceptions_pkg.raise_message
12728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_125');
12729 END Description_125;
12730 
12731 ---------------------------------------
12732 --
12733 -- PRIVATE FUNCTION
12734 --         Description_126
12735 --
12736 ---------------------------------------
12740 --Period Close Date
12737 FUNCTION Description_126 (
12738   p_application_id      IN NUMBER
12739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12741  , p_source_1            IN DATE
12742 )
12743 RETURN VARCHAR2
12744 IS
12745 l_component_type        VARCHAR2(80)   ;
12746 l_component_code        VARCHAR2(30)   ;
12747 l_component_type_code   VARCHAR2(1)    ;
12748 l_component_appl_id     INTEGER        ;
12749 l_amb_context_code      VARCHAR2(30)   ;
12750 l_ledger_language       VARCHAR2(30)   ;
12751 l_source                VARCHAR2(1996) ;
12752 l_description           VARCHAR2(2000) ;
12753 l_log_module            VARCHAR2(240)  ;
12754 BEGIN
12755 IF g_log_enabled THEN
12756       l_log_module := C_DEFAULT_MODULE||'.Description_126';
12757 END IF;
12758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12759       trace
12760          (p_msg      => 'BEGIN of Description_126'
12761          ,p_level    => C_LEVEL_PROCEDURE
12762          ,p_module   => l_log_module);
12763 END IF;
12764 
12765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12766 l_component_type        := 'AMB_DESCRIPTION';
12767 l_component_code        := 'FA_TRANSFER_COST';
12768 l_component_type_code   := 'S';
12769 l_component_appl_id     :=  140;
12770 l_amb_context_code      := 'DEFAULT';
12771 l_source                := NULL;
12772 l_description           := NULL;
12773 
12774 
12775  
12776  IF 
12777 l_ledger_language = 'US' THEN
12778     l_description :=  SUBSTR(CONCAT(l_description,'Transfer Cost'),1,2000);
12779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12780  END IF;  
12781  IF 
12782 l_ledger_language = 'US' THEN
12783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12785  END IF;   
12786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12788   IF l_source IS NOT NULL THEN
12789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12791   END IF; 
12792  l_description := SUBSTR(l_description,1,1996);
12793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12794         trace
12795            (p_msg      => 'END of Description_126'
12796            ,p_level    => C_LEVEL_PROCEDURE
12797            ,p_module   => l_log_module);
12798 
12799   END IF;
12800   RETURN l_description;
12801 
12802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12803       trace
12804          (p_msg      => 'END of Description_126'
12805          ,p_level    => C_LEVEL_PROCEDURE
12806          ,p_module   => l_log_module);
12807 END IF;
12808 RETURN NULL;
12809 EXCEPTION
12810   WHEN VALUE_ERROR THEN
12811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12812             trace
12813                (p_msg      => 'ERROR: '||sqlerrm
12814                ,p_level    => C_LEVEL_EXCEPTION
12815                ,p_module   => l_log_module);
12816      END IF;
12817      RAISE;
12818  WHEN xla_exceptions_pkg.application_exception THEN
12819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12820       trace
12821          (p_msg      => 'ERROR: '||sqlerrm
12822          ,p_level    => C_LEVEL_EXCEPTION
12823          ,p_module   => l_log_module);
12824       END IF;
12825       RAISE;
12826  WHEN OTHERS THEN
12827        xla_exceptions_pkg.raise_message
12828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_126');
12829 END Description_126;
12830 
12831 ---------------------------------------
12832 --
12833 -- PRIVATE FUNCTION
12834 --         Description_127
12835 --
12836 ---------------------------------------
12837 FUNCTION Description_127 (
12838   p_application_id      IN NUMBER
12839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12840 --Period Close Date
12841  , p_source_1            IN DATE
12842 )
12843 RETURN VARCHAR2
12844 IS
12845 l_component_type        VARCHAR2(80)   ;
12846 l_component_code        VARCHAR2(30)   ;
12847 l_component_type_code   VARCHAR2(1)    ;
12848 l_component_appl_id     INTEGER        ;
12849 l_amb_context_code      VARCHAR2(30)   ;
12850 l_ledger_language       VARCHAR2(30)   ;
12851 l_source                VARCHAR2(1996) ;
12852 l_description           VARCHAR2(2000) ;
12853 l_log_module            VARCHAR2(240)  ;
12854 BEGIN
12855 IF g_log_enabled THEN
12856       l_log_module := C_DEFAULT_MODULE||'.Description_127';
12857 END IF;
12858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12859       trace
12860          (p_msg      => 'BEGIN of Description_127'
12861          ,p_level    => C_LEVEL_PROCEDURE
12862          ,p_module   => l_log_module);
12863 END IF;
12864 
12865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12866 l_component_type        := 'AMB_DESCRIPTION';
12867 l_component_code        := 'FA_TRANSFER_EXP';
12868 l_component_type_code   := 'S';
12869 l_component_appl_id     :=  140;
12870 l_amb_context_code      := 'DEFAULT';
12871 l_source                := NULL;
12872 l_description           := NULL;
12873 
12874 
12875  
12876  IF 
12877 l_ledger_language = 'US' THEN
12878     l_description :=  SUBSTR(CONCAT(l_description,'Transfer Depreciation Expense'),1,2000);
12879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12880  END IF;  
12881  IF 
12882 l_ledger_language = 'US' THEN
12883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12885  END IF;   
12886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12888   IF l_source IS NOT NULL THEN
12889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12891   END IF; 
12892  l_description := SUBSTR(l_description,1,1996);
12893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12894         trace
12895            (p_msg      => 'END of Description_127'
12896            ,p_level    => C_LEVEL_PROCEDURE
12897            ,p_module   => l_log_module);
12898 
12899   END IF;
12900   RETURN l_description;
12901 
12902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12903       trace
12904          (p_msg      => 'END of Description_127'
12905          ,p_level    => C_LEVEL_PROCEDURE
12906          ,p_module   => l_log_module);
12907 END IF;
12908 RETURN NULL;
12909 EXCEPTION
12910   WHEN VALUE_ERROR THEN
12911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12912             trace
12913                (p_msg      => 'ERROR: '||sqlerrm
12914                ,p_level    => C_LEVEL_EXCEPTION
12915                ,p_module   => l_log_module);
12916      END IF;
12917      RAISE;
12918  WHEN xla_exceptions_pkg.application_exception THEN
12919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12920       trace
12921          (p_msg      => 'ERROR: '||sqlerrm
12922          ,p_level    => C_LEVEL_EXCEPTION
12923          ,p_module   => l_log_module);
12924       END IF;
12925       RAISE;
12926  WHEN OTHERS THEN
12927        xla_exceptions_pkg.raise_message
12928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_127');
12929 END Description_127;
12930 
12931 ---------------------------------------
12932 --
12933 -- PRIVATE FUNCTION
12934 --         Description_128
12935 --
12936 ---------------------------------------
12937 FUNCTION Description_128 (
12938   p_application_id      IN NUMBER
12939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
12940 --Period Close Date
12941  , p_source_1            IN DATE
12942 )
12943 RETURN VARCHAR2
12944 IS
12945 l_component_type        VARCHAR2(80)   ;
12946 l_component_code        VARCHAR2(30)   ;
12947 l_component_type_code   VARCHAR2(1)    ;
12948 l_component_appl_id     INTEGER        ;
12949 l_amb_context_code      VARCHAR2(30)   ;
12950 l_ledger_language       VARCHAR2(30)   ;
12951 l_source                VARCHAR2(1996) ;
12952 l_description           VARCHAR2(2000) ;
12953 l_log_module            VARCHAR2(240)  ;
12954 BEGIN
12955 IF g_log_enabled THEN
12956       l_log_module := C_DEFAULT_MODULE||'.Description_128';
12957 END IF;
12958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12959       trace
12960          (p_msg      => 'BEGIN of Description_128'
12961          ,p_level    => C_LEVEL_PROCEDURE
12962          ,p_module   => l_log_module);
12963 END IF;
12964 
12965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12966 l_component_type        := 'AMB_DESCRIPTION';
12967 l_component_code        := 'FA_TRANSFER_IC_PAYABLE';
12968 l_component_type_code   := 'S';
12969 l_component_appl_id     :=  140;
12970 l_amb_context_code      := 'DEFAULT';
12971 l_source                := NULL;
12972 l_description           := NULL;
12973 
12974 
12975  
12976  IF 
12977 l_ledger_language = 'US' THEN
12978     l_description :=  SUBSTR(CONCAT(l_description,'Transfer Intercompany AP'),1,2000);
12979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12980  END IF;  
12981  IF 
12982 l_ledger_language = 'US' THEN
12983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
12984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
12985  END IF;   
12986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
12987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
12988   IF l_source IS NOT NULL THEN
12989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
12990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
12991   END IF; 
12992  l_description := SUBSTR(l_description,1,1996);
12993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12994         trace
12995            (p_msg      => 'END of Description_128'
12996            ,p_level    => C_LEVEL_PROCEDURE
12997            ,p_module   => l_log_module);
12998 
12999   END IF;
13000   RETURN l_description;
13001 
13002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13003       trace
13004          (p_msg      => 'END of Description_128'
13005          ,p_level    => C_LEVEL_PROCEDURE
13006          ,p_module   => l_log_module);
13007 END IF;
13008 RETURN NULL;
13009 EXCEPTION
13010   WHEN VALUE_ERROR THEN
13011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13012             trace
13013                (p_msg      => 'ERROR: '||sqlerrm
13014                ,p_level    => C_LEVEL_EXCEPTION
13015                ,p_module   => l_log_module);
13016      END IF;
13017      RAISE;
13018  WHEN xla_exceptions_pkg.application_exception THEN
13019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13020       trace
13021          (p_msg      => 'ERROR: '||sqlerrm
13022          ,p_level    => C_LEVEL_EXCEPTION
13023          ,p_module   => l_log_module);
13024       END IF;
13025       RAISE;
13026  WHEN OTHERS THEN
13027        xla_exceptions_pkg.raise_message
13028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_128');
13029 END Description_128;
13030 
13031 ---------------------------------------
13032 --
13033 -- PRIVATE FUNCTION
13034 --         Description_129
13035 --
13036 ---------------------------------------
13037 FUNCTION Description_129 (
13038   p_application_id      IN NUMBER
13042 )
13039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13040 --Period Close Date
13041  , p_source_1            IN DATE
13043 RETURN VARCHAR2
13044 IS
13045 l_component_type        VARCHAR2(80)   ;
13046 l_component_code        VARCHAR2(30)   ;
13047 l_component_type_code   VARCHAR2(1)    ;
13048 l_component_appl_id     INTEGER        ;
13049 l_amb_context_code      VARCHAR2(30)   ;
13050 l_ledger_language       VARCHAR2(30)   ;
13051 l_source                VARCHAR2(1996) ;
13052 l_description           VARCHAR2(2000) ;
13053 l_log_module            VARCHAR2(240)  ;
13054 BEGIN
13055 IF g_log_enabled THEN
13056       l_log_module := C_DEFAULT_MODULE||'.Description_129';
13057 END IF;
13058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13059       trace
13060          (p_msg      => 'BEGIN of Description_129'
13061          ,p_level    => C_LEVEL_PROCEDURE
13062          ,p_module   => l_log_module);
13063 END IF;
13064 
13065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13066 l_component_type        := 'AMB_DESCRIPTION';
13067 l_component_code        := 'FA_TRANSFER_IC_RECEIVABLE';
13068 l_component_type_code   := 'S';
13069 l_component_appl_id     :=  140;
13070 l_amb_context_code      := 'DEFAULT';
13071 l_source                := NULL;
13072 l_description           := NULL;
13073 
13074 
13075  
13076  IF 
13077 l_ledger_language = 'US' THEN
13078     l_description :=  SUBSTR(CONCAT(l_description,'Transfer Intercompany AR'),1,2000);
13079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13080  END IF;  
13081  IF 
13082 l_ledger_language = 'US' THEN
13083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13085  END IF;   
13086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13088   IF l_source IS NOT NULL THEN
13089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13091   END IF; 
13092  l_description := SUBSTR(l_description,1,1996);
13093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13094         trace
13095            (p_msg      => 'END of Description_129'
13096            ,p_level    => C_LEVEL_PROCEDURE
13097            ,p_module   => l_log_module);
13098 
13099   END IF;
13100   RETURN l_description;
13101 
13102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13103       trace
13104          (p_msg      => 'END of Description_129'
13105          ,p_level    => C_LEVEL_PROCEDURE
13106          ,p_module   => l_log_module);
13107 END IF;
13108 RETURN NULL;
13109 EXCEPTION
13110   WHEN VALUE_ERROR THEN
13111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13112             trace
13113                (p_msg      => 'ERROR: '||sqlerrm
13114                ,p_level    => C_LEVEL_EXCEPTION
13115                ,p_module   => l_log_module);
13116      END IF;
13117      RAISE;
13118  WHEN xla_exceptions_pkg.application_exception THEN
13119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13120       trace
13121          (p_msg      => 'ERROR: '||sqlerrm
13122          ,p_level    => C_LEVEL_EXCEPTION
13123          ,p_module   => l_log_module);
13124       END IF;
13125       RAISE;
13126  WHEN OTHERS THEN
13127        xla_exceptions_pkg.raise_message
13128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_129');
13129 END Description_129;
13130 
13131 ---------------------------------------
13132 --
13133 -- PRIVATE FUNCTION
13134 --         Description_130
13135 --
13136 ---------------------------------------
13137 FUNCTION Description_130 (
13138   p_application_id      IN NUMBER
13139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13140 --Period Close Date
13141  , p_source_1            IN DATE
13142 )
13143 RETURN VARCHAR2
13144 IS
13145 l_component_type        VARCHAR2(80)   ;
13146 l_component_code        VARCHAR2(30)   ;
13147 l_component_type_code   VARCHAR2(1)    ;
13148 l_component_appl_id     INTEGER        ;
13149 l_amb_context_code      VARCHAR2(30)   ;
13150 l_ledger_language       VARCHAR2(30)   ;
13151 l_source                VARCHAR2(1996) ;
13152 l_description           VARCHAR2(2000) ;
13153 l_log_module            VARCHAR2(240)  ;
13154 BEGIN
13155 IF g_log_enabled THEN
13156       l_log_module := C_DEFAULT_MODULE||'.Description_130';
13157 END IF;
13158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13159       trace
13160          (p_msg      => 'BEGIN of Description_130'
13161          ,p_level    => C_LEVEL_PROCEDURE
13162          ,p_module   => l_log_module);
13163 END IF;
13164 
13165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13166 l_component_type        := 'AMB_DESCRIPTION';
13167 l_component_code        := 'FA_TRANSFER_RESERVE';
13168 l_component_type_code   := 'S';
13169 l_component_appl_id     :=  140;
13170 l_amb_context_code      := 'DEFAULT';
13171 l_source                := NULL;
13172 l_description           := NULL;
13173 
13174 
13175  
13176  IF 
13177 l_ledger_language = 'US' THEN
13178     l_description :=  SUBSTR(CONCAT(l_description,'Transfer Reserve'),1,2000);
13179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13180  END IF;  
13181  IF 
13182 l_ledger_language = 'US' THEN
13183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13185  END IF;   
13186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13191   END IF; 
13188   IF l_source IS NOT NULL THEN
13189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13192  l_description := SUBSTR(l_description,1,1996);
13193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13194         trace
13195            (p_msg      => 'END of Description_130'
13196            ,p_level    => C_LEVEL_PROCEDURE
13197            ,p_module   => l_log_module);
13198 
13199   END IF;
13200   RETURN l_description;
13201 
13202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13203       trace
13204          (p_msg      => 'END of Description_130'
13205          ,p_level    => C_LEVEL_PROCEDURE
13206          ,p_module   => l_log_module);
13207 END IF;
13208 RETURN NULL;
13209 EXCEPTION
13210   WHEN VALUE_ERROR THEN
13211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13212             trace
13213                (p_msg      => 'ERROR: '||sqlerrm
13214                ,p_level    => C_LEVEL_EXCEPTION
13215                ,p_module   => l_log_module);
13216      END IF;
13217      RAISE;
13218  WHEN xla_exceptions_pkg.application_exception THEN
13219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13220       trace
13221          (p_msg      => 'ERROR: '||sqlerrm
13222          ,p_level    => C_LEVEL_EXCEPTION
13223          ,p_module   => l_log_module);
13224       END IF;
13225       RAISE;
13226  WHEN OTHERS THEN
13227        xla_exceptions_pkg.raise_message
13228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_130');
13229 END Description_130;
13230 
13231 ---------------------------------------
13232 --
13233 -- PRIVATE FUNCTION
13234 --         Description_131
13235 --
13236 ---------------------------------------
13237 FUNCTION Description_131 (
13238   p_application_id      IN NUMBER
13239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13240 --Period Close Date
13241  , p_source_1            IN DATE
13242 )
13243 RETURN VARCHAR2
13244 IS
13245 l_component_type        VARCHAR2(80)   ;
13246 l_component_code        VARCHAR2(30)   ;
13247 l_component_type_code   VARCHAR2(1)    ;
13248 l_component_appl_id     INTEGER        ;
13249 l_amb_context_code      VARCHAR2(30)   ;
13250 l_ledger_language       VARCHAR2(30)   ;
13251 l_source                VARCHAR2(1996) ;
13252 l_description           VARCHAR2(2000) ;
13253 l_log_module            VARCHAR2(240)  ;
13254 BEGIN
13255 IF g_log_enabled THEN
13256       l_log_module := C_DEFAULT_MODULE||'.Description_131';
13257 END IF;
13258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13259       trace
13260          (p_msg      => 'BEGIN of Description_131'
13261          ,p_level    => C_LEVEL_PROCEDURE
13262          ,p_module   => l_log_module);
13263 END IF;
13264 
13265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13266 l_component_type        := 'AMB_DESCRIPTION';
13267 l_component_code        := 'FA_TRANSFER_REVAL_RESERVE';
13268 l_component_type_code   := 'S';
13269 l_component_appl_id     :=  140;
13270 l_amb_context_code      := 'DEFAULT';
13271 l_source                := NULL;
13272 l_description           := NULL;
13273 
13274 
13275  
13276  IF 
13277 l_ledger_language = 'US' THEN
13278     l_description :=  SUBSTR(CONCAT(l_description,'Transfer Revaluation Reserve'),1,2000);
13279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13280  END IF;  
13281  IF 
13282 l_ledger_language = 'US' THEN
13283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13285  END IF;   
13286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13288   IF l_source IS NOT NULL THEN
13289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13291   END IF; 
13292  l_description := SUBSTR(l_description,1,1996);
13293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13294         trace
13295            (p_msg      => 'END of Description_131'
13296            ,p_level    => C_LEVEL_PROCEDURE
13297            ,p_module   => l_log_module);
13298 
13299   END IF;
13300   RETURN l_description;
13301 
13302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13303       trace
13304          (p_msg      => 'END of Description_131'
13305          ,p_level    => C_LEVEL_PROCEDURE
13306          ,p_module   => l_log_module);
13307 END IF;
13308 RETURN NULL;
13309 EXCEPTION
13310   WHEN VALUE_ERROR THEN
13311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13312             trace
13313                (p_msg      => 'ERROR: '||sqlerrm
13314                ,p_level    => C_LEVEL_EXCEPTION
13315                ,p_module   => l_log_module);
13316      END IF;
13317      RAISE;
13318  WHEN xla_exceptions_pkg.application_exception THEN
13319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13320       trace
13321          (p_msg      => 'ERROR: '||sqlerrm
13322          ,p_level    => C_LEVEL_EXCEPTION
13323          ,p_module   => l_log_module);
13324       END IF;
13325       RAISE;
13326  WHEN OTHERS THEN
13327        xla_exceptions_pkg.raise_message
13328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_131');
13329 END Description_131;
13330 
13331 ---------------------------------------
13332 --
13333 -- PRIVATE FUNCTION
13334 --         Description_132
13335 --
13336 ---------------------------------------
13337 FUNCTION Description_132 (
13338   p_application_id      IN NUMBER
13339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13340 --Period Close Date
13344 IS
13341  , p_source_1            IN DATE
13342 )
13343 RETURN VARCHAR2
13345 l_component_type        VARCHAR2(80)   ;
13346 l_component_code        VARCHAR2(30)   ;
13347 l_component_type_code   VARCHAR2(1)    ;
13348 l_component_appl_id     INTEGER        ;
13349 l_amb_context_code      VARCHAR2(30)   ;
13350 l_ledger_language       VARCHAR2(30)   ;
13351 l_source                VARCHAR2(1996) ;
13352 l_description           VARCHAR2(2000) ;
13353 l_log_module            VARCHAR2(240)  ;
13354 BEGIN
13355 IF g_log_enabled THEN
13356       l_log_module := C_DEFAULT_MODULE||'.Description_132';
13357 END IF;
13358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13359       trace
13360          (p_msg      => 'BEGIN of Description_132'
13361          ,p_level    => C_LEVEL_PROCEDURE
13362          ,p_module   => l_log_module);
13363 END IF;
13364 
13365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13366 l_component_type        := 'AMB_DESCRIPTION';
13367 l_component_code        := 'FA_UNITADJ_BONUS_RESERVE';
13368 l_component_type_code   := 'S';
13369 l_component_appl_id     :=  140;
13370 l_amb_context_code      := 'DEFAULT';
13371 l_source                := NULL;
13372 l_description           := NULL;
13373 
13374 
13375  
13376  IF 
13377 l_ledger_language = 'US' THEN
13378     l_description :=  SUBSTR(CONCAT(l_description,'Unit Adjustment Bonus Reserve'),1,2000);
13379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13380  END IF;  
13381  IF 
13382 l_ledger_language = 'US' THEN
13383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13385  END IF;   
13386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13388   IF l_source IS NOT NULL THEN
13389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13391   END IF; 
13392  l_description := SUBSTR(l_description,1,1996);
13393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13394         trace
13395            (p_msg      => 'END of Description_132'
13396            ,p_level    => C_LEVEL_PROCEDURE
13397            ,p_module   => l_log_module);
13398 
13399   END IF;
13400   RETURN l_description;
13401 
13402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13403       trace
13404          (p_msg      => 'END of Description_132'
13405          ,p_level    => C_LEVEL_PROCEDURE
13406          ,p_module   => l_log_module);
13407 END IF;
13408 RETURN NULL;
13409 EXCEPTION
13410   WHEN VALUE_ERROR THEN
13411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13412             trace
13413                (p_msg      => 'ERROR: '||sqlerrm
13414                ,p_level    => C_LEVEL_EXCEPTION
13415                ,p_module   => l_log_module);
13416      END IF;
13417      RAISE;
13418  WHEN xla_exceptions_pkg.application_exception THEN
13419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13420       trace
13421          (p_msg      => 'ERROR: '||sqlerrm
13422          ,p_level    => C_LEVEL_EXCEPTION
13423          ,p_module   => l_log_module);
13424       END IF;
13425       RAISE;
13426  WHEN OTHERS THEN
13427        xla_exceptions_pkg.raise_message
13428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_132');
13429 END Description_132;
13430 
13431 ---------------------------------------
13432 --
13433 -- PRIVATE FUNCTION
13434 --         Description_133
13435 --
13436 ---------------------------------------
13437 FUNCTION Description_133 (
13438   p_application_id      IN NUMBER
13439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13440 --Period Close Date
13441  , p_source_1            IN DATE
13442 )
13443 RETURN VARCHAR2
13444 IS
13445 l_component_type        VARCHAR2(80)   ;
13446 l_component_code        VARCHAR2(30)   ;
13447 l_component_type_code   VARCHAR2(1)    ;
13448 l_component_appl_id     INTEGER        ;
13449 l_amb_context_code      VARCHAR2(30)   ;
13450 l_ledger_language       VARCHAR2(30)   ;
13451 l_source                VARCHAR2(1996) ;
13452 l_description           VARCHAR2(2000) ;
13453 l_log_module            VARCHAR2(240)  ;
13454 BEGIN
13455 IF g_log_enabled THEN
13456       l_log_module := C_DEFAULT_MODULE||'.Description_133';
13457 END IF;
13458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13459       trace
13460          (p_msg      => 'BEGIN of Description_133'
13461          ,p_level    => C_LEVEL_PROCEDURE
13462          ,p_module   => l_log_module);
13463 END IF;
13464 
13465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13466 l_component_type        := 'AMB_DESCRIPTION';
13467 l_component_code        := 'FA_UNITADJ_COST';
13468 l_component_type_code   := 'S';
13469 l_component_appl_id     :=  140;
13470 l_amb_context_code      := 'DEFAULT';
13471 l_source                := NULL;
13472 l_description           := NULL;
13473 
13474 
13475  
13476  IF 
13477 l_ledger_language = 'US' THEN
13478     l_description :=  SUBSTR(CONCAT(l_description,'Unit Adjustment Cost'),1,2000);
13479     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13480  END IF;  
13481  IF 
13482 l_ledger_language = 'US' THEN
13483     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13484     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13485  END IF;   
13486   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13487                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13488   IF l_source IS NOT NULL THEN
13492  l_description := SUBSTR(l_description,1,1996);
13489     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13490     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13491   END IF; 
13493   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13494         trace
13495            (p_msg      => 'END of Description_133'
13496            ,p_level    => C_LEVEL_PROCEDURE
13497            ,p_module   => l_log_module);
13498 
13499   END IF;
13500   RETURN l_description;
13501 
13502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13503       trace
13504          (p_msg      => 'END of Description_133'
13505          ,p_level    => C_LEVEL_PROCEDURE
13506          ,p_module   => l_log_module);
13507 END IF;
13508 RETURN NULL;
13509 EXCEPTION
13510   WHEN VALUE_ERROR THEN
13511      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13512             trace
13513                (p_msg      => 'ERROR: '||sqlerrm
13514                ,p_level    => C_LEVEL_EXCEPTION
13515                ,p_module   => l_log_module);
13516      END IF;
13517      RAISE;
13518  WHEN xla_exceptions_pkg.application_exception THEN
13519       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13520       trace
13521          (p_msg      => 'ERROR: '||sqlerrm
13522          ,p_level    => C_LEVEL_EXCEPTION
13523          ,p_module   => l_log_module);
13524       END IF;
13525       RAISE;
13526  WHEN OTHERS THEN
13527        xla_exceptions_pkg.raise_message
13528            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_133');
13529 END Description_133;
13530 
13531 ---------------------------------------
13532 --
13533 -- PRIVATE FUNCTION
13534 --         Description_134
13535 --
13536 ---------------------------------------
13537 FUNCTION Description_134 (
13538   p_application_id      IN NUMBER
13539 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13540 --Period Close Date
13541  , p_source_1            IN DATE
13542 )
13543 RETURN VARCHAR2
13544 IS
13545 l_component_type        VARCHAR2(80)   ;
13546 l_component_code        VARCHAR2(30)   ;
13547 l_component_type_code   VARCHAR2(1)    ;
13548 l_component_appl_id     INTEGER        ;
13549 l_amb_context_code      VARCHAR2(30)   ;
13550 l_ledger_language       VARCHAR2(30)   ;
13551 l_source                VARCHAR2(1996) ;
13552 l_description           VARCHAR2(2000) ;
13553 l_log_module            VARCHAR2(240)  ;
13554 BEGIN
13555 IF g_log_enabled THEN
13556       l_log_module := C_DEFAULT_MODULE||'.Description_134';
13557 END IF;
13558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13559       trace
13560          (p_msg      => 'BEGIN of Description_134'
13561          ,p_level    => C_LEVEL_PROCEDURE
13562          ,p_module   => l_log_module);
13563 END IF;
13564 
13565 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13566 l_component_type        := 'AMB_DESCRIPTION';
13567 l_component_code        := 'FA_UNITADJ_EXP';
13568 l_component_type_code   := 'S';
13569 l_component_appl_id     :=  140;
13570 l_amb_context_code      := 'DEFAULT';
13571 l_source                := NULL;
13572 l_description           := NULL;
13573 
13574 
13575  
13576  IF 
13577 l_ledger_language = 'US' THEN
13578     l_description :=  SUBSTR(CONCAT(l_description,'Unit Adjustment Depreciation Expense'),1,2000);
13579     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13580  END IF;  
13581  IF 
13582 l_ledger_language = 'US' THEN
13583     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13584     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13585  END IF;   
13586   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13587                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13588   IF l_source IS NOT NULL THEN
13589     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13590     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13591   END IF; 
13592  l_description := SUBSTR(l_description,1,1996);
13593   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13594         trace
13595            (p_msg      => 'END of Description_134'
13596            ,p_level    => C_LEVEL_PROCEDURE
13597            ,p_module   => l_log_module);
13598 
13599   END IF;
13600   RETURN l_description;
13601 
13602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13603       trace
13604          (p_msg      => 'END of Description_134'
13605          ,p_level    => C_LEVEL_PROCEDURE
13606          ,p_module   => l_log_module);
13607 END IF;
13608 RETURN NULL;
13609 EXCEPTION
13610   WHEN VALUE_ERROR THEN
13611      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13612             trace
13613                (p_msg      => 'ERROR: '||sqlerrm
13614                ,p_level    => C_LEVEL_EXCEPTION
13615                ,p_module   => l_log_module);
13616      END IF;
13617      RAISE;
13618  WHEN xla_exceptions_pkg.application_exception THEN
13619       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13620       trace
13621          (p_msg      => 'ERROR: '||sqlerrm
13622          ,p_level    => C_LEVEL_EXCEPTION
13623          ,p_module   => l_log_module);
13624       END IF;
13625       RAISE;
13626  WHEN OTHERS THEN
13627        xla_exceptions_pkg.raise_message
13628            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_134');
13629 END Description_134;
13630 
13631 ---------------------------------------
13632 --
13633 -- PRIVATE FUNCTION
13634 --         Description_135
13635 --
13636 ---------------------------------------
13637 FUNCTION Description_135 (
13638   p_application_id      IN NUMBER
13639 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13640 --Period Close Date
13641  , p_source_1            IN DATE
13645 l_component_type        VARCHAR2(80)   ;
13642 )
13643 RETURN VARCHAR2
13644 IS
13646 l_component_code        VARCHAR2(30)   ;
13647 l_component_type_code   VARCHAR2(1)    ;
13648 l_component_appl_id     INTEGER        ;
13649 l_amb_context_code      VARCHAR2(30)   ;
13650 l_ledger_language       VARCHAR2(30)   ;
13651 l_source                VARCHAR2(1996) ;
13652 l_description           VARCHAR2(2000) ;
13653 l_log_module            VARCHAR2(240)  ;
13654 BEGIN
13655 IF g_log_enabled THEN
13656       l_log_module := C_DEFAULT_MODULE||'.Description_135';
13657 END IF;
13658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13659       trace
13660          (p_msg      => 'BEGIN of Description_135'
13661          ,p_level    => C_LEVEL_PROCEDURE
13662          ,p_module   => l_log_module);
13663 END IF;
13664 
13665 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13666 l_component_type        := 'AMB_DESCRIPTION';
13667 l_component_code        := 'FA_UNITADJ_IC_PAYABLE';
13668 l_component_type_code   := 'S';
13669 l_component_appl_id     :=  140;
13670 l_amb_context_code      := 'DEFAULT';
13671 l_source                := NULL;
13672 l_description           := NULL;
13673 
13674 
13675  
13676  IF 
13677 l_ledger_language = 'US' THEN
13678     l_description :=  SUBSTR(CONCAT(l_description,'Unit Adjustment Intercompany AP'),1,2000);
13679     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13680  END IF;  
13681  IF 
13682 l_ledger_language = 'US' THEN
13683     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13684     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13685  END IF;   
13686   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13687                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13688   IF l_source IS NOT NULL THEN
13689     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13690     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13691   END IF; 
13692  l_description := SUBSTR(l_description,1,1996);
13693   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13694         trace
13695            (p_msg      => 'END of Description_135'
13696            ,p_level    => C_LEVEL_PROCEDURE
13697            ,p_module   => l_log_module);
13698 
13699   END IF;
13700   RETURN l_description;
13701 
13702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13703       trace
13704          (p_msg      => 'END of Description_135'
13705          ,p_level    => C_LEVEL_PROCEDURE
13706          ,p_module   => l_log_module);
13707 END IF;
13708 RETURN NULL;
13709 EXCEPTION
13710   WHEN VALUE_ERROR THEN
13711      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13712             trace
13713                (p_msg      => 'ERROR: '||sqlerrm
13714                ,p_level    => C_LEVEL_EXCEPTION
13715                ,p_module   => l_log_module);
13716      END IF;
13717      RAISE;
13718  WHEN xla_exceptions_pkg.application_exception THEN
13719       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13720       trace
13721          (p_msg      => 'ERROR: '||sqlerrm
13722          ,p_level    => C_LEVEL_EXCEPTION
13723          ,p_module   => l_log_module);
13724       END IF;
13725       RAISE;
13726  WHEN OTHERS THEN
13727        xla_exceptions_pkg.raise_message
13728            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_135');
13729 END Description_135;
13730 
13731 ---------------------------------------
13732 --
13733 -- PRIVATE FUNCTION
13734 --         Description_136
13735 --
13736 ---------------------------------------
13737 FUNCTION Description_136 (
13738   p_application_id      IN NUMBER
13739 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13740 --Period Close Date
13741  , p_source_1            IN DATE
13742 )
13743 RETURN VARCHAR2
13744 IS
13745 l_component_type        VARCHAR2(80)   ;
13746 l_component_code        VARCHAR2(30)   ;
13747 l_component_type_code   VARCHAR2(1)    ;
13748 l_component_appl_id     INTEGER        ;
13749 l_amb_context_code      VARCHAR2(30)   ;
13750 l_ledger_language       VARCHAR2(30)   ;
13751 l_source                VARCHAR2(1996) ;
13752 l_description           VARCHAR2(2000) ;
13753 l_log_module            VARCHAR2(240)  ;
13754 BEGIN
13755 IF g_log_enabled THEN
13756       l_log_module := C_DEFAULT_MODULE||'.Description_136';
13757 END IF;
13758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13759       trace
13760          (p_msg      => 'BEGIN of Description_136'
13761          ,p_level    => C_LEVEL_PROCEDURE
13762          ,p_module   => l_log_module);
13763 END IF;
13764 
13765 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13766 l_component_type        := 'AMB_DESCRIPTION';
13767 l_component_code        := 'FA_UNITADJ_IC_RECEIVABLE';
13768 l_component_type_code   := 'S';
13769 l_component_appl_id     :=  140;
13770 l_amb_context_code      := 'DEFAULT';
13771 l_source                := NULL;
13772 l_description           := NULL;
13773 
13774 
13775  
13776  IF 
13777 l_ledger_language = 'US' THEN
13778     l_description :=  SUBSTR(CONCAT(l_description,'Unit Adjustment Intercompany AR'),1,2000);
13779     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13780  END IF;  
13781  IF 
13782 l_ledger_language = 'US' THEN
13783     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13784     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13785  END IF;   
13786   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13787                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13788   IF l_source IS NOT NULL THEN
13789     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13793   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13790     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13791   END IF; 
13792  l_description := SUBSTR(l_description,1,1996);
13794         trace
13795            (p_msg      => 'END of Description_136'
13796            ,p_level    => C_LEVEL_PROCEDURE
13797            ,p_module   => l_log_module);
13798 
13799   END IF;
13800   RETURN l_description;
13801 
13802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13803       trace
13804          (p_msg      => 'END of Description_136'
13805          ,p_level    => C_LEVEL_PROCEDURE
13806          ,p_module   => l_log_module);
13807 END IF;
13808 RETURN NULL;
13809 EXCEPTION
13810   WHEN VALUE_ERROR THEN
13811      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13812             trace
13813                (p_msg      => 'ERROR: '||sqlerrm
13814                ,p_level    => C_LEVEL_EXCEPTION
13815                ,p_module   => l_log_module);
13816      END IF;
13817      RAISE;
13818  WHEN xla_exceptions_pkg.application_exception THEN
13819       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13820       trace
13821          (p_msg      => 'ERROR: '||sqlerrm
13822          ,p_level    => C_LEVEL_EXCEPTION
13823          ,p_module   => l_log_module);
13824       END IF;
13825       RAISE;
13826  WHEN OTHERS THEN
13827        xla_exceptions_pkg.raise_message
13828            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_136');
13829 END Description_136;
13830 
13831 ---------------------------------------
13832 --
13833 -- PRIVATE FUNCTION
13834 --         Description_137
13835 --
13836 ---------------------------------------
13837 FUNCTION Description_137 (
13838   p_application_id      IN NUMBER
13839 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13840 --Period Close Date
13841  , p_source_1            IN DATE
13842 )
13843 RETURN VARCHAR2
13844 IS
13845 l_component_type        VARCHAR2(80)   ;
13846 l_component_code        VARCHAR2(30)   ;
13847 l_component_type_code   VARCHAR2(1)    ;
13848 l_component_appl_id     INTEGER        ;
13849 l_amb_context_code      VARCHAR2(30)   ;
13850 l_ledger_language       VARCHAR2(30)   ;
13851 l_source                VARCHAR2(1996) ;
13852 l_description           VARCHAR2(2000) ;
13853 l_log_module            VARCHAR2(240)  ;
13854 BEGIN
13855 IF g_log_enabled THEN
13856       l_log_module := C_DEFAULT_MODULE||'.Description_137';
13857 END IF;
13858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13859       trace
13860          (p_msg      => 'BEGIN of Description_137'
13861          ,p_level    => C_LEVEL_PROCEDURE
13862          ,p_module   => l_log_module);
13863 END IF;
13864 
13865 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13866 l_component_type        := 'AMB_DESCRIPTION';
13867 l_component_code        := 'FA_UNITADJ_RESERVE';
13868 l_component_type_code   := 'S';
13869 l_component_appl_id     :=  140;
13870 l_amb_context_code      := 'DEFAULT';
13871 l_source                := NULL;
13872 l_description           := NULL;
13873 
13874 
13875  
13876  IF 
13877 l_ledger_language = 'US' THEN
13878     l_description :=  SUBSTR(CONCAT(l_description,'Unit Adjustment Reserve'),1,2000);
13879     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13880  END IF;  
13881  IF 
13882 l_ledger_language = 'US' THEN
13883     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13884     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13885  END IF;   
13886   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13887                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13888   IF l_source IS NOT NULL THEN
13889     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13890     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13891   END IF; 
13892  l_description := SUBSTR(l_description,1,1996);
13893   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13894         trace
13895            (p_msg      => 'END of Description_137'
13896            ,p_level    => C_LEVEL_PROCEDURE
13897            ,p_module   => l_log_module);
13898 
13899   END IF;
13900   RETURN l_description;
13901 
13902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13903       trace
13904          (p_msg      => 'END of Description_137'
13905          ,p_level    => C_LEVEL_PROCEDURE
13906          ,p_module   => l_log_module);
13907 END IF;
13908 RETURN NULL;
13909 EXCEPTION
13910   WHEN VALUE_ERROR THEN
13911      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13912             trace
13913                (p_msg      => 'ERROR: '||sqlerrm
13914                ,p_level    => C_LEVEL_EXCEPTION
13915                ,p_module   => l_log_module);
13916      END IF;
13917      RAISE;
13918  WHEN xla_exceptions_pkg.application_exception THEN
13919       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
13920       trace
13921          (p_msg      => 'ERROR: '||sqlerrm
13922          ,p_level    => C_LEVEL_EXCEPTION
13923          ,p_module   => l_log_module);
13924       END IF;
13925       RAISE;
13926  WHEN OTHERS THEN
13927        xla_exceptions_pkg.raise_message
13928            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_137');
13929 END Description_137;
13930 
13931 ---------------------------------------
13932 --
13933 -- PRIVATE FUNCTION
13934 --         Description_138
13935 --
13936 ---------------------------------------
13937 FUNCTION Description_138 (
13938   p_application_id      IN NUMBER
13939 , p_ae_header_id        IN NUMBER DEFAULT NULL 
13940 --Period Close Date
13941  , p_source_1            IN DATE
13942 )
13943 RETURN VARCHAR2
13944 IS
13948 l_component_appl_id     INTEGER        ;
13945 l_component_type        VARCHAR2(80)   ;
13946 l_component_code        VARCHAR2(30)   ;
13947 l_component_type_code   VARCHAR2(1)    ;
13949 l_amb_context_code      VARCHAR2(30)   ;
13950 l_ledger_language       VARCHAR2(30)   ;
13951 l_source                VARCHAR2(1996) ;
13952 l_description           VARCHAR2(2000) ;
13953 l_log_module            VARCHAR2(240)  ;
13954 BEGIN
13955 IF g_log_enabled THEN
13956       l_log_module := C_DEFAULT_MODULE||'.Description_138';
13957 END IF;
13958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13959       trace
13960          (p_msg      => 'BEGIN of Description_138'
13961          ,p_level    => C_LEVEL_PROCEDURE
13962          ,p_module   => l_log_module);
13963 END IF;
13964 
13965 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13966 l_component_type        := 'AMB_DESCRIPTION';
13967 l_component_code        := 'FA_UNITADJ_REVAL_RESERVE';
13968 l_component_type_code   := 'S';
13969 l_component_appl_id     :=  140;
13970 l_amb_context_code      := 'DEFAULT';
13971 l_source                := NULL;
13972 l_description           := NULL;
13973 
13974 
13975  
13976  IF 
13977 l_ledger_language = 'US' THEN
13978     l_description :=  SUBSTR(CONCAT(l_description,'Unit Adjustment Revaluation Reserve'),1,2000);
13979     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13980  END IF;  
13981  IF 
13982 l_ledger_language = 'US' THEN
13983     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
13984     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
13985  END IF;   
13986   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
13987                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
13988   IF l_source IS NOT NULL THEN
13989     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
13990     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
13991   END IF; 
13992  l_description := SUBSTR(l_description,1,1996);
13993   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13994         trace
13995            (p_msg      => 'END of Description_138'
13996            ,p_level    => C_LEVEL_PROCEDURE
13997            ,p_module   => l_log_module);
13998 
13999   END IF;
14000   RETURN l_description;
14001 
14002 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14003       trace
14004          (p_msg      => 'END of Description_138'
14005          ,p_level    => C_LEVEL_PROCEDURE
14006          ,p_module   => l_log_module);
14007 END IF;
14008 RETURN NULL;
14009 EXCEPTION
14010   WHEN VALUE_ERROR THEN
14011      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14012             trace
14013                (p_msg      => 'ERROR: '||sqlerrm
14014                ,p_level    => C_LEVEL_EXCEPTION
14015                ,p_module   => l_log_module);
14016      END IF;
14017      RAISE;
14018  WHEN xla_exceptions_pkg.application_exception THEN
14019       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14020       trace
14021          (p_msg      => 'ERROR: '||sqlerrm
14022          ,p_level    => C_LEVEL_EXCEPTION
14023          ,p_module   => l_log_module);
14024       END IF;
14025       RAISE;
14026  WHEN OTHERS THEN
14027        xla_exceptions_pkg.raise_message
14028            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_138');
14029 END Description_138;
14030 
14031 ---------------------------------------
14032 --
14033 -- PRIVATE FUNCTION
14034 --         Description_139
14035 --
14036 ---------------------------------------
14037 FUNCTION Description_139 (
14038   p_application_id      IN NUMBER
14039 , p_ae_header_id        IN NUMBER DEFAULT NULL 
14040 --Period Close Date
14041  , p_source_1            IN DATE
14042 )
14043 RETURN VARCHAR2
14044 IS
14045 l_component_type        VARCHAR2(80)   ;
14046 l_component_code        VARCHAR2(30)   ;
14047 l_component_type_code   VARCHAR2(1)    ;
14048 l_component_appl_id     INTEGER        ;
14049 l_amb_context_code      VARCHAR2(30)   ;
14050 l_ledger_language       VARCHAR2(30)   ;
14051 l_source                VARCHAR2(1996) ;
14052 l_description           VARCHAR2(2000) ;
14053 l_log_module            VARCHAR2(240)  ;
14054 BEGIN
14055 IF g_log_enabled THEN
14056       l_log_module := C_DEFAULT_MODULE||'.Description_139';
14057 END IF;
14058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14059       trace
14060          (p_msg      => 'BEGIN of Description_139'
14061          ,p_level    => C_LEVEL_PROCEDURE
14062          ,p_module   => l_log_module);
14063 END IF;
14064 
14065 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
14066 l_component_type        := 'AMB_DESCRIPTION';
14067 l_component_code        := 'FA_UNIT_ADJ';
14068 l_component_type_code   := 'S';
14069 l_component_appl_id     :=  140;
14070 l_amb_context_code      := 'DEFAULT';
14071 l_source                := NULL;
14072 l_description           := NULL;
14073 
14074 
14075  
14076  IF 
14077 l_ledger_language = 'US' THEN
14078     l_description :=  SUBSTR(CONCAT(l_description,'Unit Adjustment'),1,2000);
14079     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
14080  END IF;  
14081  IF 
14082 l_ledger_language = 'US' THEN
14083     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
14084     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
14085  END IF;   
14086   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
14087                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
14088   IF l_source IS NOT NULL THEN
14089     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
14090     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
14094         trace
14091   END IF; 
14092  l_description := SUBSTR(l_description,1,1996);
14093   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14095            (p_msg      => 'END of Description_139'
14096            ,p_level    => C_LEVEL_PROCEDURE
14097            ,p_module   => l_log_module);
14098 
14099   END IF;
14100   RETURN l_description;
14101 
14102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14103       trace
14104          (p_msg      => 'END of Description_139'
14105          ,p_level    => C_LEVEL_PROCEDURE
14106          ,p_module   => l_log_module);
14107 END IF;
14108 RETURN NULL;
14109 EXCEPTION
14110   WHEN VALUE_ERROR THEN
14111      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14112             trace
14113                (p_msg      => 'ERROR: '||sqlerrm
14114                ,p_level    => C_LEVEL_EXCEPTION
14115                ,p_module   => l_log_module);
14116      END IF;
14117      RAISE;
14118  WHEN xla_exceptions_pkg.application_exception THEN
14119       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14120       trace
14121          (p_msg      => 'ERROR: '||sqlerrm
14122          ,p_level    => C_LEVEL_EXCEPTION
14123          ,p_module   => l_log_module);
14124       END IF;
14125       RAISE;
14126  WHEN OTHERS THEN
14127        xla_exceptions_pkg.raise_message
14128            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_139');
14129 END Description_139;
14130 
14131 ---------------------------------------
14132 --
14133 -- PRIVATE FUNCTION
14134 --         Description_140
14135 --
14136 ---------------------------------------
14137 FUNCTION Description_140 (
14138   p_application_id      IN NUMBER
14139 , p_ae_header_id        IN NUMBER DEFAULT NULL 
14140 --Period Close Date
14141  , p_source_1            IN DATE
14142 )
14143 RETURN VARCHAR2
14144 IS
14145 l_component_type        VARCHAR2(80)   ;
14146 l_component_code        VARCHAR2(30)   ;
14147 l_component_type_code   VARCHAR2(1)    ;
14148 l_component_appl_id     INTEGER        ;
14149 l_amb_context_code      VARCHAR2(30)   ;
14150 l_ledger_language       VARCHAR2(30)   ;
14151 l_source                VARCHAR2(1996) ;
14152 l_description           VARCHAR2(2000) ;
14153 l_log_module            VARCHAR2(240)  ;
14154 BEGIN
14155 IF g_log_enabled THEN
14156       l_log_module := C_DEFAULT_MODULE||'.Description_140';
14157 END IF;
14158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14159       trace
14160          (p_msg      => 'BEGIN of Description_140'
14161          ,p_level    => C_LEVEL_PROCEDURE
14162          ,p_module   => l_log_module);
14163 END IF;
14164 
14165 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
14166 l_component_type        := 'AMB_DESCRIPTION';
14167 l_component_code        := 'FA_UNPL_DEP';
14168 l_component_type_code   := 'S';
14169 l_component_appl_id     :=  140;
14170 l_amb_context_code      := 'DEFAULT';
14171 l_source                := NULL;
14172 l_description           := NULL;
14173 
14174 
14175  
14176  IF 
14177 l_ledger_language = 'US' THEN
14178     l_description :=  SUBSTR(CONCAT(l_description,'Unplanned Depreciation'),1,2000);
14179     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
14180  END IF;  
14181  IF 
14182 l_ledger_language = 'US' THEN
14183     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
14184     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
14185  END IF;   
14186   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
14187                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
14188   IF l_source IS NOT NULL THEN
14189     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
14190     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
14191   END IF; 
14192  l_description := SUBSTR(l_description,1,1996);
14193   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14194         trace
14195            (p_msg      => 'END of Description_140'
14196            ,p_level    => C_LEVEL_PROCEDURE
14197            ,p_module   => l_log_module);
14198 
14199   END IF;
14200   RETURN l_description;
14201 
14202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14203       trace
14204          (p_msg      => 'END of Description_140'
14205          ,p_level    => C_LEVEL_PROCEDURE
14206          ,p_module   => l_log_module);
14207 END IF;
14208 RETURN NULL;
14209 EXCEPTION
14210   WHEN VALUE_ERROR THEN
14211      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14212             trace
14213                (p_msg      => 'ERROR: '||sqlerrm
14214                ,p_level    => C_LEVEL_EXCEPTION
14215                ,p_module   => l_log_module);
14216      END IF;
14217      RAISE;
14218  WHEN xla_exceptions_pkg.application_exception THEN
14219       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14220       trace
14221          (p_msg      => 'ERROR: '||sqlerrm
14222          ,p_level    => C_LEVEL_EXCEPTION
14223          ,p_module   => l_log_module);
14224       END IF;
14225       RAISE;
14226  WHEN OTHERS THEN
14227        xla_exceptions_pkg.raise_message
14228            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_140');
14229 END Description_140;
14230 
14231 ---------------------------------------
14232 --
14233 -- PRIVATE FUNCTION
14234 --         Description_141
14235 --
14236 ---------------------------------------
14237 FUNCTION Description_141 (
14238   p_application_id      IN NUMBER
14239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
14240 --Period Close Date
14241  , p_source_1            IN DATE
14242 )
14243 RETURN VARCHAR2
14244 IS
14245 l_component_type        VARCHAR2(80)   ;
14246 l_component_code        VARCHAR2(30)   ;
14250 l_ledger_language       VARCHAR2(30)   ;
14247 l_component_type_code   VARCHAR2(1)    ;
14248 l_component_appl_id     INTEGER        ;
14249 l_amb_context_code      VARCHAR2(30)   ;
14251 l_source                VARCHAR2(1996) ;
14252 l_description           VARCHAR2(2000) ;
14253 l_log_module            VARCHAR2(240)  ;
14254 BEGIN
14255 IF g_log_enabled THEN
14256       l_log_module := C_DEFAULT_MODULE||'.Description_141';
14257 END IF;
14258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14259       trace
14260          (p_msg      => 'BEGIN of Description_141'
14261          ,p_level    => C_LEVEL_PROCEDURE
14262          ,p_module   => l_log_module);
14263 END IF;
14264 
14265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
14266 l_component_type        := 'AMB_DESCRIPTION';
14267 l_component_code        := 'FA_UNPL_EXP';
14268 l_component_type_code   := 'S';
14269 l_component_appl_id     :=  140;
14270 l_amb_context_code      := 'DEFAULT';
14271 l_source                := NULL;
14272 l_description           := NULL;
14273 
14274 
14275  
14276  IF 
14277 l_ledger_language = 'US' THEN
14278     l_description :=  SUBSTR(CONCAT(l_description,'Unplanned Depreciation Expense'),1,2000);
14279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
14280  END IF;  
14281  IF 
14282 l_ledger_language = 'US' THEN
14283     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
14284     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
14285  END IF;   
14286   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
14287                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
14288   IF l_source IS NOT NULL THEN
14289     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
14290     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
14291   END IF; 
14292  l_description := SUBSTR(l_description,1,1996);
14293   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14294         trace
14295            (p_msg      => 'END of Description_141'
14296            ,p_level    => C_LEVEL_PROCEDURE
14297            ,p_module   => l_log_module);
14298 
14299   END IF;
14300   RETURN l_description;
14301 
14302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14303       trace
14304          (p_msg      => 'END of Description_141'
14305          ,p_level    => C_LEVEL_PROCEDURE
14306          ,p_module   => l_log_module);
14307 END IF;
14308 RETURN NULL;
14309 EXCEPTION
14310   WHEN VALUE_ERROR THEN
14311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14312             trace
14313                (p_msg      => 'ERROR: '||sqlerrm
14314                ,p_level    => C_LEVEL_EXCEPTION
14315                ,p_module   => l_log_module);
14316      END IF;
14317      RAISE;
14318  WHEN xla_exceptions_pkg.application_exception THEN
14319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14320       trace
14321          (p_msg      => 'ERROR: '||sqlerrm
14322          ,p_level    => C_LEVEL_EXCEPTION
14323          ,p_module   => l_log_module);
14324       END IF;
14325       RAISE;
14326  WHEN OTHERS THEN
14327        xla_exceptions_pkg.raise_message
14328            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_141');
14329 END Description_141;
14330 
14331 ---------------------------------------
14332 --
14333 -- PRIVATE FUNCTION
14334 --         Description_142
14335 --
14336 ---------------------------------------
14337 FUNCTION Description_142 (
14338   p_application_id      IN NUMBER
14339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
14340 --Period Close Date
14341  , p_source_1            IN DATE
14342 )
14343 RETURN VARCHAR2
14344 IS
14345 l_component_type        VARCHAR2(80)   ;
14346 l_component_code        VARCHAR2(30)   ;
14347 l_component_type_code   VARCHAR2(1)    ;
14348 l_component_appl_id     INTEGER        ;
14349 l_amb_context_code      VARCHAR2(30)   ;
14350 l_ledger_language       VARCHAR2(30)   ;
14351 l_source                VARCHAR2(1996) ;
14352 l_description           VARCHAR2(2000) ;
14353 l_log_module            VARCHAR2(240)  ;
14354 BEGIN
14355 IF g_log_enabled THEN
14356       l_log_module := C_DEFAULT_MODULE||'.Description_142';
14357 END IF;
14358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14359       trace
14360          (p_msg      => 'BEGIN of Description_142'
14361          ,p_level    => C_LEVEL_PROCEDURE
14362          ,p_module   => l_log_module);
14363 END IF;
14364 
14365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
14366 l_component_type        := 'AMB_DESCRIPTION';
14367 l_component_code        := 'FA_UNPL_RES';
14368 l_component_type_code   := 'S';
14369 l_component_appl_id     :=  140;
14370 l_amb_context_code      := 'DEFAULT';
14371 l_source                := NULL;
14372 l_description           := NULL;
14373 
14374 
14375  
14376  IF 
14377 l_ledger_language = 'US' THEN
14378     l_description :=  SUBSTR(CONCAT(l_description,'Unplanned Depreciation Reserve'),1,2000);
14379     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
14380  END IF;  
14381  IF 
14382 l_ledger_language = 'US' THEN
14383     l_description :=  SUBSTR(CONCAT(l_description,'-'),1,2000);
14384     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
14385  END IF;   
14386   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(p_source_1,
14387                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
14388   IF l_source IS NOT NULL THEN
14389     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
14390     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
14391   END IF; 
14392  l_description := SUBSTR(l_description,1,1996);
14396            ,p_level    => C_LEVEL_PROCEDURE
14393   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14394         trace
14395            (p_msg      => 'END of Description_142'
14397            ,p_module   => l_log_module);
14398 
14399   END IF;
14400   RETURN l_description;
14401 
14402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14403       trace
14404          (p_msg      => 'END of Description_142'
14405          ,p_level    => C_LEVEL_PROCEDURE
14406          ,p_module   => l_log_module);
14407 END IF;
14408 RETURN NULL;
14409 EXCEPTION
14410   WHEN VALUE_ERROR THEN
14411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14412             trace
14413                (p_msg      => 'ERROR: '||sqlerrm
14414                ,p_level    => C_LEVEL_EXCEPTION
14415                ,p_module   => l_log_module);
14416      END IF;
14417      RAISE;
14418  WHEN xla_exceptions_pkg.application_exception THEN
14419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
14420       trace
14421          (p_msg      => 'ERROR: '||sqlerrm
14422          ,p_level    => C_LEVEL_EXCEPTION
14423          ,p_module   => l_log_module);
14424       END IF;
14425       RAISE;
14426  WHEN OTHERS THEN
14427        xla_exceptions_pkg.raise_message
14428            (p_location => 'XLA_00140_AAD_S_000002_PKG.Description_142');
14429 END Description_142;
14430 
14431 ---------------------------------------
14432 --
14433 -- PRIVATE FUNCTION
14434 --         AcctDerRule_143
14435 --
14436 ---------------------------------------
14437 FUNCTION AcctDerRule_143 (
14438   p_application_id             IN NUMBER
14439 , p_ae_header_id               IN NUMBER
14440 , p_side                       IN VARCHAR2
14441 , p_override_seg_flag          IN VARCHAR2 
14442 --Bonus Depreciation Expense Account
14443  , p_source_2            IN VARCHAR2
14444 --Generated Code Combination Identifier
14445  , p_source_3            IN NUMBER
14446 , x_transaction_coa_id         OUT NOCOPY NUMBER
14447 , x_accounting_coa_id          OUT NOCOPY NUMBER
14448 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
14449 , x_flex_value_set_id          OUT NOCOPY NUMBER
14450 , x_value_type_code            OUT NOCOPY VARCHAR2
14451 , x_value_combination_id       OUT NOCOPY NUMBER
14452 , x_value_segment_code         OUT NOCOPY VARCHAR2
14453 )
14454 RETURN VARCHAR2
14455 IS
14456 l_component_type       VARCHAR2(80)  ;
14457 l_component_code       VARCHAR2(30)  ;
14458 l_component_type_code  VARCHAR2(1)   ;
14459 l_component_appl_id    INTEGER       ;
14460 l_amb_context_code     VARCHAR2(30)  ;
14461 l_log_module           VARCHAR2(240) ;
14462 l_output_value         VARCHAR2(30)  ;
14463 BEGIN
14464 IF g_log_enabled THEN
14465       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_143';
14466 END IF;
14467 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14468 
14469       trace
14470          (p_msg      => 'BEGIN of AcctDerRule_143'
14471          ,p_level    => C_LEVEL_PROCEDURE
14472          ,p_module   => l_log_module);
14473 
14474 END IF;
14475 
14476 l_component_type         := 'AMB_ADR';
14477 l_component_code         := 'FA_BONUS_DEPRN_EXPENSE_SEGMENT';
14478 l_component_type_code    := 'S';
14479 l_component_appl_id      :=  140;
14480 l_amb_context_code       := 'DEFAULT';
14481 x_transaction_coa_id     :=  null;
14482 x_accounting_coa_id      :=  null;
14483 x_flexfield_segment_code := 'GL_ACCOUNT';
14484 x_flex_value_set_id      :=  null ;
14485 
14486 
14487  IF TO_NUMBER(p_source_3) IS NULL 
14488  THEN 
14489 --
14490   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14491 
14492       trace
14493          (p_msg      => 'END of AcctDerRule_143'
14494          ,p_level    => C_LEVEL_PROCEDURE
14495          ,p_module   => l_log_module);
14496 
14497   END IF;
14498   x_value_combination_id  :=  null ;
14499   x_value_segment_code    :=  null ;
14500   x_value_type_code       := 'S';
14501   l_output_value          := TO_CHAR(p_source_2);
14502   RETURN l_output_value;
14503 
14504  ELSE 
14505     IF p_override_seg_flag = 'Y' THEN 
14506        RETURN '#$NO_OVERRIDE#$';
14507     END IF;
14508  END IF;
14509 
14510 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14511 
14512       trace
14513          (p_msg      => 'END of AcctDerRule_143(invalid)'
14514          ,p_level    => C_LEVEL_PROCEDURE
14515          ,p_module   => l_log_module);
14516 
14517 END IF;
14518 
14519 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
14520 x_value_combination_id  := null;
14521 x_value_segment_code    := null;
14522 x_value_type_code       := null;
14523 l_output_value          := null;
14524 xla_accounting_err_pkg.build_message
14525                  (p_appli_s_name            => 'XLA'
14526                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
14527                  ,p_token_1                 => 'COMPONENT_NAME'
14528                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
14529                                                             l_component_type
14530                                                           , l_component_code
14531                                                           , l_component_type_code
14532                                                           , l_component_appl_id
14533                                                           , l_amb_context_code
14534                                                           )
14535                  ,p_token_2                 => 'OWNER'
14536                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
14537                                                         'XLA_OWNER_TYPE'
14538                                                         ,l_component_type_code
14542                  ,p_token_4                 => 'PAD_OWNER'
14539                                                         )
14540                  ,p_token_3                 => 'PAD_NAME'
14541                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
14543                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
14544                                                         'XLA_OWNER_TYPE'
14545                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
14546                                                         )
14547                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
14548                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
14549                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
14550                  ,p_ae_header_id            => NULL
14551 );
14552 RETURN l_output_value;
14553 EXCEPTION
14554   WHEN xla_exceptions_pkg.application_exception THEN
14555       RAISE;
14556   WHEN OTHERS THEN
14557        xla_exceptions_pkg.raise_message
14558            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_143');
14559 END AcctDerRule_143;
14560 --
14561 
14562 ---------------------------------------
14563 --
14564 -- PRIVATE FUNCTION
14565 --         AcctDerRule_144
14566 --
14567 ---------------------------------------
14568 FUNCTION AcctDerRule_144 (
14569   p_application_id             IN NUMBER
14570 , p_ae_header_id               IN NUMBER
14571 , p_side                       IN VARCHAR2
14572 , p_override_seg_flag          IN VARCHAR2 
14573 --Generated Code Combination Identifier
14574  , p_source_3            IN NUMBER
14575 --Bonus Reserve Account
14576  , p_source_4            IN VARCHAR2
14577 , x_transaction_coa_id         OUT NOCOPY NUMBER
14578 , x_accounting_coa_id          OUT NOCOPY NUMBER
14579 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
14580 , x_flex_value_set_id          OUT NOCOPY NUMBER
14581 , x_value_type_code            OUT NOCOPY VARCHAR2
14582 , x_value_combination_id       OUT NOCOPY NUMBER
14583 , x_value_segment_code         OUT NOCOPY VARCHAR2
14584 )
14585 RETURN VARCHAR2
14586 IS
14587 l_component_type       VARCHAR2(80)  ;
14588 l_component_code       VARCHAR2(30)  ;
14589 l_component_type_code  VARCHAR2(1)   ;
14590 l_component_appl_id    INTEGER       ;
14591 l_amb_context_code     VARCHAR2(30)  ;
14592 l_log_module           VARCHAR2(240) ;
14593 l_output_value         VARCHAR2(30)  ;
14594 BEGIN
14595 IF g_log_enabled THEN
14596       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_144';
14597 END IF;
14598 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14599 
14600       trace
14601          (p_msg      => 'BEGIN of AcctDerRule_144'
14602          ,p_level    => C_LEVEL_PROCEDURE
14603          ,p_module   => l_log_module);
14604 
14605 END IF;
14606 
14607 l_component_type         := 'AMB_ADR';
14608 l_component_code         := 'FA_BONUS_RES_ACCOUNT_SEGMENT';
14609 l_component_type_code    := 'S';
14610 l_component_appl_id      :=  140;
14611 l_amb_context_code       := 'DEFAULT';
14612 x_transaction_coa_id     :=  null;
14613 x_accounting_coa_id      :=  null;
14614 x_flexfield_segment_code := 'GL_ACCOUNT';
14615 x_flex_value_set_id      :=  null ;
14616 
14617 
14618  IF TO_NUMBER(p_source_3) IS NULL 
14619  THEN 
14620 --
14621   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14622 
14623       trace
14624          (p_msg      => 'END of AcctDerRule_144'
14625          ,p_level    => C_LEVEL_PROCEDURE
14626          ,p_module   => l_log_module);
14627 
14628   END IF;
14629   x_value_combination_id  :=  null ;
14630   x_value_segment_code    :=  null ;
14631   x_value_type_code       := 'S';
14632   l_output_value          := TO_CHAR(p_source_4);
14633   RETURN l_output_value;
14634 
14635  ELSE 
14636     IF p_override_seg_flag = 'Y' THEN 
14637        RETURN '#$NO_OVERRIDE#$';
14638     END IF;
14639  END IF;
14640 
14641 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14642 
14643       trace
14644          (p_msg      => 'END of AcctDerRule_144(invalid)'
14645          ,p_level    => C_LEVEL_PROCEDURE
14646          ,p_module   => l_log_module);
14647 
14648 END IF;
14649 
14650 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
14651 x_value_combination_id  := null;
14652 x_value_segment_code    := null;
14653 x_value_type_code       := null;
14654 l_output_value          := null;
14655 xla_accounting_err_pkg.build_message
14656                  (p_appli_s_name            => 'XLA'
14657                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
14658                  ,p_token_1                 => 'COMPONENT_NAME'
14659                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
14660                                                             l_component_type
14661                                                           , l_component_code
14662                                                           , l_component_type_code
14663                                                           , l_component_appl_id
14664                                                           , l_amb_context_code
14665                                                           )
14666                  ,p_token_2                 => 'OWNER'
14667                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
14668                                                         'XLA_OWNER_TYPE'
14669                                                         ,l_component_type_code
14670                                                         )
14671                  ,p_token_3                 => 'PAD_NAME'
14675                                                         'XLA_OWNER_TYPE'
14672                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
14673                  ,p_token_4                 => 'PAD_OWNER'
14674                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
14676                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
14677                                                         )
14678                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
14679                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
14680                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
14681                  ,p_ae_header_id            => NULL
14682 );
14683 RETURN l_output_value;
14684 EXCEPTION
14685   WHEN xla_exceptions_pkg.application_exception THEN
14686       RAISE;
14687   WHEN OTHERS THEN
14688        xla_exceptions_pkg.raise_message
14689            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_144');
14690 END AcctDerRule_144;
14691 --
14692 
14693 ---------------------------------------
14694 --
14695 -- PRIVATE FUNCTION
14696 --         AcctDerRule_145
14697 --
14698 ---------------------------------------
14699 FUNCTION AcctDerRule_145 (
14700   p_application_id             IN NUMBER
14701 , p_ae_header_id               IN NUMBER
14702 , p_side                       IN VARCHAR2
14703 , p_override_seg_flag          IN VARCHAR2 
14704 --Generated Code Combination Identifier
14705  , p_source_3            IN NUMBER
14706 --CIP Clearing Account
14707  , p_source_5            IN VARCHAR2
14708 --Payables Code Combination Identifier
14709  , p_source_6            IN NUMBER
14710 , x_transaction_coa_id         OUT NOCOPY NUMBER
14711 , x_accounting_coa_id          OUT NOCOPY NUMBER
14712 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
14713 , x_flex_value_set_id          OUT NOCOPY NUMBER
14714 , x_value_type_code            OUT NOCOPY VARCHAR2
14715 , x_value_combination_id       OUT NOCOPY NUMBER
14716 , x_value_segment_code         OUT NOCOPY VARCHAR2
14717 )
14718 RETURN VARCHAR2
14719 IS
14720 l_component_type       VARCHAR2(80)  ;
14721 l_component_code       VARCHAR2(30)  ;
14722 l_component_type_code  VARCHAR2(1)   ;
14723 l_component_appl_id    INTEGER       ;
14724 l_amb_context_code     VARCHAR2(30)  ;
14725 l_log_module           VARCHAR2(240) ;
14726 l_output_value         VARCHAR2(30)  ;
14727 BEGIN
14728 IF g_log_enabled THEN
14729       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_145';
14730 END IF;
14731 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14732 
14733       trace
14734          (p_msg      => 'BEGIN of AcctDerRule_145'
14735          ,p_level    => C_LEVEL_PROCEDURE
14736          ,p_module   => l_log_module);
14737 
14738 END IF;
14739 
14740 l_component_type         := 'AMB_ADR';
14741 l_component_code         := 'FA_CAT_CIP_CLR_SEGMENT';
14742 l_component_type_code    := 'S';
14743 l_component_appl_id      :=  140;
14744 l_amb_context_code       := 'DEFAULT';
14745 x_transaction_coa_id     :=  null;
14746 x_accounting_coa_id      :=  null;
14747 x_flexfield_segment_code := 'GL_ACCOUNT';
14748 x_flex_value_set_id      :=  null ;
14749 
14750 
14751  IF (TO_NUMBER(p_source_6) IS NULL AND 
14752 TO_NUMBER(p_source_3) IS NULL )
14753  THEN 
14754 --
14755   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14756 
14757       trace
14758          (p_msg      => 'END of AcctDerRule_145'
14759          ,p_level    => C_LEVEL_PROCEDURE
14760          ,p_module   => l_log_module);
14761 
14762   END IF;
14763   x_value_combination_id  :=  null ;
14764   x_value_segment_code    :=  null ;
14765   x_value_type_code       := 'S';
14766   l_output_value          := TO_CHAR(p_source_5);
14767   RETURN l_output_value;
14768 
14769  ELSE 
14770     IF p_override_seg_flag = 'Y' THEN 
14771        RETURN '#$NO_OVERRIDE#$';
14772     END IF;
14773  END IF;
14774 
14775 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14776 
14777       trace
14778          (p_msg      => 'END of AcctDerRule_145(invalid)'
14779          ,p_level    => C_LEVEL_PROCEDURE
14780          ,p_module   => l_log_module);
14781 
14782 END IF;
14783 
14784 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
14785 x_value_combination_id  := null;
14786 x_value_segment_code    := null;
14787 x_value_type_code       := null;
14788 l_output_value          := null;
14789 xla_accounting_err_pkg.build_message
14790                  (p_appli_s_name            => 'XLA'
14791                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
14792                  ,p_token_1                 => 'COMPONENT_NAME'
14793                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
14794                                                             l_component_type
14795                                                           , l_component_code
14796                                                           , l_component_type_code
14797                                                           , l_component_appl_id
14798                                                           , l_amb_context_code
14799                                                           )
14800                  ,p_token_2                 => 'OWNER'
14801                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
14802                                                         'XLA_OWNER_TYPE'
14803                                                         ,l_component_type_code
14804                                                         )
14805                  ,p_token_3                 => 'PAD_NAME'
14809                                                         'XLA_OWNER_TYPE'
14806                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
14807                  ,p_token_4                 => 'PAD_OWNER'
14808                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
14810                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
14811                                                         )
14812                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
14813                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
14814                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
14815                  ,p_ae_header_id            => NULL
14816 );
14817 RETURN l_output_value;
14818 EXCEPTION
14819   WHEN xla_exceptions_pkg.application_exception THEN
14820       RAISE;
14821   WHEN OTHERS THEN
14822        xla_exceptions_pkg.raise_message
14823            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_145');
14824 END AcctDerRule_145;
14825 --
14826 
14827 ---------------------------------------
14828 --
14829 -- PRIVATE FUNCTION
14830 --         AcctDerRule_146
14831 --
14832 ---------------------------------------
14833 FUNCTION AcctDerRule_146 (
14834   p_application_id             IN NUMBER
14835 , p_ae_header_id               IN NUMBER
14836 , p_side                       IN VARCHAR2
14837 , p_override_seg_flag          IN VARCHAR2 
14838 --Generated Code Combination Identifier
14839  , p_source_3            IN NUMBER
14840 --CIP Cost Account
14841  , p_source_7            IN VARCHAR2
14842 , x_transaction_coa_id         OUT NOCOPY NUMBER
14843 , x_accounting_coa_id          OUT NOCOPY NUMBER
14844 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
14845 , x_flex_value_set_id          OUT NOCOPY NUMBER
14846 , x_value_type_code            OUT NOCOPY VARCHAR2
14847 , x_value_combination_id       OUT NOCOPY NUMBER
14848 , x_value_segment_code         OUT NOCOPY VARCHAR2
14849 )
14850 RETURN VARCHAR2
14851 IS
14852 l_component_type       VARCHAR2(80)  ;
14853 l_component_code       VARCHAR2(30)  ;
14854 l_component_type_code  VARCHAR2(1)   ;
14855 l_component_appl_id    INTEGER       ;
14856 l_amb_context_code     VARCHAR2(30)  ;
14857 l_log_module           VARCHAR2(240) ;
14858 l_output_value         VARCHAR2(30)  ;
14859 BEGIN
14860 IF g_log_enabled THEN
14861       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_146';
14862 END IF;
14863 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14864 
14865       trace
14866          (p_msg      => 'BEGIN of AcctDerRule_146'
14867          ,p_level    => C_LEVEL_PROCEDURE
14868          ,p_module   => l_log_module);
14869 
14870 END IF;
14871 
14872 l_component_type         := 'AMB_ADR';
14873 l_component_code         := 'FA_CAT_CIP_COST_SEGMENT';
14874 l_component_type_code    := 'S';
14875 l_component_appl_id      :=  140;
14876 l_amb_context_code       := 'DEFAULT';
14877 x_transaction_coa_id     :=  null;
14878 x_accounting_coa_id      :=  null;
14879 x_flexfield_segment_code := 'GL_ACCOUNT';
14880 x_flex_value_set_id      :=  null ;
14881 
14882 
14883  IF TO_NUMBER(p_source_3) IS NULL 
14884  THEN 
14885 --
14886   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14887 
14888       trace
14889          (p_msg      => 'END of AcctDerRule_146'
14890          ,p_level    => C_LEVEL_PROCEDURE
14891          ,p_module   => l_log_module);
14892 
14893   END IF;
14894   x_value_combination_id  :=  null ;
14895   x_value_segment_code    :=  null ;
14896   x_value_type_code       := 'S';
14897   l_output_value          := TO_CHAR(p_source_7);
14898   RETURN l_output_value;
14899 
14900  ELSE 
14901     IF p_override_seg_flag = 'Y' THEN 
14902        RETURN '#$NO_OVERRIDE#$';
14903     END IF;
14904  END IF;
14905 
14906 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14907 
14908       trace
14909          (p_msg      => 'END of AcctDerRule_146(invalid)'
14910          ,p_level    => C_LEVEL_PROCEDURE
14911          ,p_module   => l_log_module);
14912 
14913 END IF;
14914 
14915 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
14916 x_value_combination_id  := null;
14917 x_value_segment_code    := null;
14918 x_value_type_code       := null;
14919 l_output_value          := null;
14920 xla_accounting_err_pkg.build_message
14921                  (p_appli_s_name            => 'XLA'
14922                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
14923                  ,p_token_1                 => 'COMPONENT_NAME'
14924                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
14925                                                             l_component_type
14926                                                           , l_component_code
14927                                                           , l_component_type_code
14928                                                           , l_component_appl_id
14929                                                           , l_amb_context_code
14930                                                           )
14931                  ,p_token_2                 => 'OWNER'
14932                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
14933                                                         'XLA_OWNER_TYPE'
14934                                                         ,l_component_type_code
14935                                                         )
14936                  ,p_token_3                 => 'PAD_NAME'
14937                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
14938                  ,p_token_4                 => 'PAD_OWNER'
14942                                                         )
14939                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
14940                                                         'XLA_OWNER_TYPE'
14941                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
14943                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
14944                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
14945                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
14946                  ,p_ae_header_id            => NULL
14947 );
14948 RETURN l_output_value;
14949 EXCEPTION
14950   WHEN xla_exceptions_pkg.application_exception THEN
14951       RAISE;
14952   WHEN OTHERS THEN
14953        xla_exceptions_pkg.raise_message
14954            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_146');
14955 END AcctDerRule_146;
14956 --
14957 
14958 ---------------------------------------
14959 --
14960 -- PRIVATE FUNCTION
14961 --         AcctDerRule_147
14962 --
14963 ---------------------------------------
14964 FUNCTION AcctDerRule_147 (
14965   p_application_id             IN NUMBER
14966 , p_ae_header_id               IN NUMBER
14967 , p_side                       IN VARCHAR2
14968 , p_override_seg_flag          IN VARCHAR2 
14969 --Generated Code Combination Identifier
14970  , p_source_3            IN NUMBER
14971 --Payables Code Combination Identifier
14972  , p_source_6            IN NUMBER
14973 --Asset Clearing Account
14974  , p_source_8            IN VARCHAR2
14975 , x_transaction_coa_id         OUT NOCOPY NUMBER
14976 , x_accounting_coa_id          OUT NOCOPY NUMBER
14977 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
14978 , x_flex_value_set_id          OUT NOCOPY NUMBER
14979 , x_value_type_code            OUT NOCOPY VARCHAR2
14980 , x_value_combination_id       OUT NOCOPY NUMBER
14981 , x_value_segment_code         OUT NOCOPY VARCHAR2
14982 )
14983 RETURN VARCHAR2
14984 IS
14985 l_component_type       VARCHAR2(80)  ;
14986 l_component_code       VARCHAR2(30)  ;
14987 l_component_type_code  VARCHAR2(1)   ;
14988 l_component_appl_id    INTEGER       ;
14989 l_amb_context_code     VARCHAR2(30)  ;
14990 l_log_module           VARCHAR2(240) ;
14991 l_output_value         VARCHAR2(30)  ;
14992 BEGIN
14993 IF g_log_enabled THEN
14994       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_147';
14995 END IF;
14996 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14997 
14998       trace
14999          (p_msg      => 'BEGIN of AcctDerRule_147'
15000          ,p_level    => C_LEVEL_PROCEDURE
15001          ,p_module   => l_log_module);
15002 
15003 END IF;
15004 
15005 l_component_type         := 'AMB_ADR';
15006 l_component_code         := 'FA_CAT_CLR_ACCOUNT_SEGMENT';
15007 l_component_type_code    := 'S';
15008 l_component_appl_id      :=  140;
15009 l_amb_context_code       := 'DEFAULT';
15010 x_transaction_coa_id     :=  null;
15011 x_accounting_coa_id      :=  null;
15012 x_flexfield_segment_code := 'GL_ACCOUNT';
15013 x_flex_value_set_id      :=  null ;
15014 
15015 
15016  IF TO_NUMBER(p_source_3) IS NULL AND 
15017 TO_NUMBER(p_source_6) IS NULL 
15018  THEN 
15019 --
15020   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15021 
15022       trace
15023          (p_msg      => 'END of AcctDerRule_147'
15024          ,p_level    => C_LEVEL_PROCEDURE
15025          ,p_module   => l_log_module);
15026 
15027   END IF;
15028   x_value_combination_id  :=  null ;
15029   x_value_segment_code    :=  null ;
15030   x_value_type_code       := 'S';
15031   l_output_value          := TO_CHAR(p_source_8);
15032   RETURN l_output_value;
15033 
15034  ELSE 
15035     IF p_override_seg_flag = 'Y' THEN 
15036        RETURN '#$NO_OVERRIDE#$';
15037     END IF;
15038  END IF;
15039 
15040 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15041 
15042       trace
15043          (p_msg      => 'END of AcctDerRule_147(invalid)'
15044          ,p_level    => C_LEVEL_PROCEDURE
15045          ,p_module   => l_log_module);
15046 
15047 END IF;
15048 
15049 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
15050 x_value_combination_id  := null;
15051 x_value_segment_code    := null;
15052 x_value_type_code       := null;
15053 l_output_value          := null;
15054 xla_accounting_err_pkg.build_message
15055                  (p_appli_s_name            => 'XLA'
15056                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
15057                  ,p_token_1                 => 'COMPONENT_NAME'
15058                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
15059                                                             l_component_type
15060                                                           , l_component_code
15061                                                           , l_component_type_code
15062                                                           , l_component_appl_id
15063                                                           , l_amb_context_code
15064                                                           )
15065                  ,p_token_2                 => 'OWNER'
15066                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
15067                                                         'XLA_OWNER_TYPE'
15068                                                         ,l_component_type_code
15069                                                         )
15070                  ,p_token_3                 => 'PAD_NAME'
15071                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
15072                  ,p_token_4                 => 'PAD_OWNER'
15076                                                         )
15073                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
15074                                                         'XLA_OWNER_TYPE'
15075                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
15077                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
15078                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
15079                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
15080                  ,p_ae_header_id            => NULL
15081 );
15082 RETURN l_output_value;
15083 EXCEPTION
15084   WHEN xla_exceptions_pkg.application_exception THEN
15085       RAISE;
15086   WHEN OTHERS THEN
15087        xla_exceptions_pkg.raise_message
15088            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_147');
15089 END AcctDerRule_147;
15090 --
15091 
15092 ---------------------------------------
15093 --
15094 -- PRIVATE FUNCTION
15095 --         AcctDerRule_148
15096 --
15097 ---------------------------------------
15098 FUNCTION AcctDerRule_148 (
15099   p_application_id             IN NUMBER
15100 , p_ae_header_id               IN NUMBER
15101 , p_side                       IN VARCHAR2
15102 , p_override_seg_flag          IN VARCHAR2 
15103 --Generated Code Combination Identifier
15104  , p_source_3            IN NUMBER
15105 --Asset Cost Account
15106  , p_source_9            IN VARCHAR2
15107 , x_transaction_coa_id         OUT NOCOPY NUMBER
15108 , x_accounting_coa_id          OUT NOCOPY NUMBER
15109 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
15110 , x_flex_value_set_id          OUT NOCOPY NUMBER
15111 , x_value_type_code            OUT NOCOPY VARCHAR2
15112 , x_value_combination_id       OUT NOCOPY NUMBER
15113 , x_value_segment_code         OUT NOCOPY VARCHAR2
15114 )
15115 RETURN VARCHAR2
15116 IS
15117 l_component_type       VARCHAR2(80)  ;
15118 l_component_code       VARCHAR2(30)  ;
15119 l_component_type_code  VARCHAR2(1)   ;
15120 l_component_appl_id    INTEGER       ;
15121 l_amb_context_code     VARCHAR2(30)  ;
15122 l_log_module           VARCHAR2(240) ;
15123 l_output_value         VARCHAR2(30)  ;
15124 BEGIN
15125 IF g_log_enabled THEN
15126       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_148';
15127 END IF;
15128 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15129 
15130       trace
15131          (p_msg      => 'BEGIN of AcctDerRule_148'
15132          ,p_level    => C_LEVEL_PROCEDURE
15133          ,p_module   => l_log_module);
15134 
15135 END IF;
15136 
15137 l_component_type         := 'AMB_ADR';
15138 l_component_code         := 'FA_CAT_COST_ACCOUNT_SEGMENT';
15139 l_component_type_code    := 'S';
15140 l_component_appl_id      :=  140;
15141 l_amb_context_code       := 'DEFAULT';
15142 x_transaction_coa_id     :=  null;
15143 x_accounting_coa_id      :=  null;
15144 x_flexfield_segment_code := 'GL_ACCOUNT';
15145 x_flex_value_set_id      :=  null ;
15146 
15147 
15148  IF TO_NUMBER(p_source_3) IS NULL 
15149  THEN 
15150 --
15151   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15152 
15153       trace
15154          (p_msg      => 'END of AcctDerRule_148'
15155          ,p_level    => C_LEVEL_PROCEDURE
15156          ,p_module   => l_log_module);
15157 
15158   END IF;
15159   x_value_combination_id  :=  null ;
15160   x_value_segment_code    :=  null ;
15161   x_value_type_code       := 'S';
15162   l_output_value          := TO_CHAR(p_source_9);
15163   RETURN l_output_value;
15164 
15165  ELSE 
15166     IF p_override_seg_flag = 'Y' THEN 
15167        RETURN '#$NO_OVERRIDE#$';
15168     END IF;
15169  END IF;
15170 
15171 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15172 
15173       trace
15174          (p_msg      => 'END of AcctDerRule_148(invalid)'
15175          ,p_level    => C_LEVEL_PROCEDURE
15176          ,p_module   => l_log_module);
15177 
15178 END IF;
15179 
15180 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
15181 x_value_combination_id  := null;
15182 x_value_segment_code    := null;
15183 x_value_type_code       := null;
15184 l_output_value          := null;
15185 xla_accounting_err_pkg.build_message
15186                  (p_appli_s_name            => 'XLA'
15187                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
15188                  ,p_token_1                 => 'COMPONENT_NAME'
15189                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
15190                                                             l_component_type
15191                                                           , l_component_code
15192                                                           , l_component_type_code
15193                                                           , l_component_appl_id
15194                                                           , l_amb_context_code
15195                                                           )
15196                  ,p_token_2                 => 'OWNER'
15197                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
15198                                                         'XLA_OWNER_TYPE'
15199                                                         ,l_component_type_code
15200                                                         )
15201                  ,p_token_3                 => 'PAD_NAME'
15202                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
15203                  ,p_token_4                 => 'PAD_OWNER'
15204                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
15205                                                         'XLA_OWNER_TYPE'
15209                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
15206                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
15207                                                         )
15208                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
15210                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
15211                  ,p_ae_header_id            => NULL
15212 );
15213 RETURN l_output_value;
15214 EXCEPTION
15215   WHEN xla_exceptions_pkg.application_exception THEN
15216       RAISE;
15217   WHEN OTHERS THEN
15218        xla_exceptions_pkg.raise_message
15219            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_148');
15220 END AcctDerRule_148;
15221 --
15222 
15223 ---------------------------------------
15224 --
15225 -- PRIVATE FUNCTION
15226 --         AcctDerRule_149
15227 --
15228 ---------------------------------------
15229 FUNCTION AcctDerRule_149 (
15230   p_application_id             IN NUMBER
15231 , p_ae_header_id               IN NUMBER
15232 , p_side                       IN VARCHAR2
15233 , p_override_seg_flag          IN VARCHAR2 
15234 --Generated Code Combination Identifier
15235  , p_source_3            IN NUMBER
15236 --Depreciation Reserve Account
15237  , p_source_10            IN VARCHAR2
15238 , x_transaction_coa_id         OUT NOCOPY NUMBER
15239 , x_accounting_coa_id          OUT NOCOPY NUMBER
15240 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
15241 , x_flex_value_set_id          OUT NOCOPY NUMBER
15242 , x_value_type_code            OUT NOCOPY VARCHAR2
15243 , x_value_combination_id       OUT NOCOPY NUMBER
15244 , x_value_segment_code         OUT NOCOPY VARCHAR2
15245 )
15246 RETURN VARCHAR2
15247 IS
15248 l_component_type       VARCHAR2(80)  ;
15249 l_component_code       VARCHAR2(30)  ;
15250 l_component_type_code  VARCHAR2(1)   ;
15251 l_component_appl_id    INTEGER       ;
15252 l_amb_context_code     VARCHAR2(30)  ;
15253 l_log_module           VARCHAR2(240) ;
15254 l_output_value         VARCHAR2(30)  ;
15255 BEGIN
15256 IF g_log_enabled THEN
15257       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_149';
15258 END IF;
15259 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15260 
15261       trace
15262          (p_msg      => 'BEGIN of AcctDerRule_149'
15263          ,p_level    => C_LEVEL_PROCEDURE
15264          ,p_module   => l_log_module);
15265 
15266 END IF;
15267 
15268 l_component_type         := 'AMB_ADR';
15269 l_component_code         := 'FA_CAT_RES_ACCOUNT_SEGMENT';
15270 l_component_type_code    := 'S';
15271 l_component_appl_id      :=  140;
15272 l_amb_context_code       := 'DEFAULT';
15273 x_transaction_coa_id     :=  null;
15274 x_accounting_coa_id      :=  null;
15275 x_flexfield_segment_code := 'GL_ACCOUNT';
15276 x_flex_value_set_id      :=  null ;
15277 
15278 
15279  IF TO_NUMBER(p_source_3) IS NULL 
15280  THEN 
15281 --
15282   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15283 
15284       trace
15285          (p_msg      => 'END of AcctDerRule_149'
15286          ,p_level    => C_LEVEL_PROCEDURE
15287          ,p_module   => l_log_module);
15288 
15289   END IF;
15290   x_value_combination_id  :=  null ;
15291   x_value_segment_code    :=  null ;
15292   x_value_type_code       := 'S';
15293   l_output_value          := TO_CHAR(p_source_10);
15294   RETURN l_output_value;
15295 
15296  ELSE 
15297     IF p_override_seg_flag = 'Y' THEN 
15298        RETURN '#$NO_OVERRIDE#$';
15299     END IF;
15300  END IF;
15301 
15302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15303 
15304       trace
15305          (p_msg      => 'END of AcctDerRule_149(invalid)'
15306          ,p_level    => C_LEVEL_PROCEDURE
15307          ,p_module   => l_log_module);
15308 
15309 END IF;
15310 
15311 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
15312 x_value_combination_id  := null;
15313 x_value_segment_code    := null;
15314 x_value_type_code       := null;
15315 l_output_value          := null;
15316 xla_accounting_err_pkg.build_message
15317                  (p_appli_s_name            => 'XLA'
15318                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
15319                  ,p_token_1                 => 'COMPONENT_NAME'
15320                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
15321                                                             l_component_type
15322                                                           , l_component_code
15323                                                           , l_component_type_code
15324                                                           , l_component_appl_id
15325                                                           , l_amb_context_code
15326                                                           )
15327                  ,p_token_2                 => 'OWNER'
15328                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
15329                                                         'XLA_OWNER_TYPE'
15330                                                         ,l_component_type_code
15331                                                         )
15332                  ,p_token_3                 => 'PAD_NAME'
15333                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
15334                  ,p_token_4                 => 'PAD_OWNER'
15335                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
15336                                                         'XLA_OWNER_TYPE'
15337                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
15338                                                         )
15342                  ,p_ae_header_id            => NULL
15339                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
15340                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
15341                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
15343 );
15344 RETURN l_output_value;
15345 EXCEPTION
15346   WHEN xla_exceptions_pkg.application_exception THEN
15347       RAISE;
15348   WHEN OTHERS THEN
15349        xla_exceptions_pkg.raise_message
15350            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_149');
15351 END AcctDerRule_149;
15352 --
15353 
15354 ---------------------------------------
15355 --
15356 -- PRIVATE FUNCTION
15357 --         AcctDerRule_150
15358 --
15359 ---------------------------------------
15360 FUNCTION AcctDerRule_150 (
15361   p_application_id             IN NUMBER
15362 , p_ae_header_id               IN NUMBER
15363 , p_side                       IN VARCHAR2
15364 , p_override_seg_flag          IN VARCHAR2 
15365 --Generated Code Combination Identifier
15366  , p_source_3            IN NUMBER
15367 --Revaluation Reserve Account
15368  , p_source_11            IN VARCHAR2
15369 , x_transaction_coa_id         OUT NOCOPY NUMBER
15370 , x_accounting_coa_id          OUT NOCOPY NUMBER
15371 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
15372 , x_flex_value_set_id          OUT NOCOPY NUMBER
15373 , x_value_type_code            OUT NOCOPY VARCHAR2
15374 , x_value_combination_id       OUT NOCOPY NUMBER
15375 , x_value_segment_code         OUT NOCOPY VARCHAR2
15376 )
15377 RETURN VARCHAR2
15378 IS
15379 l_component_type       VARCHAR2(80)  ;
15380 l_component_code       VARCHAR2(30)  ;
15381 l_component_type_code  VARCHAR2(1)   ;
15382 l_component_appl_id    INTEGER       ;
15383 l_amb_context_code     VARCHAR2(30)  ;
15384 l_log_module           VARCHAR2(240) ;
15385 l_output_value         VARCHAR2(30)  ;
15386 BEGIN
15387 IF g_log_enabled THEN
15388       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_150';
15389 END IF;
15390 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15391 
15392       trace
15393          (p_msg      => 'BEGIN of AcctDerRule_150'
15394          ,p_level    => C_LEVEL_PROCEDURE
15395          ,p_module   => l_log_module);
15396 
15397 END IF;
15398 
15399 l_component_type         := 'AMB_ADR';
15400 l_component_code         := 'FA_CAT_REVAL_RES_SEGMENT';
15401 l_component_type_code    := 'S';
15402 l_component_appl_id      :=  140;
15403 l_amb_context_code       := 'DEFAULT';
15404 x_transaction_coa_id     :=  null;
15405 x_accounting_coa_id      :=  null;
15406 x_flexfield_segment_code := 'GL_ACCOUNT';
15407 x_flex_value_set_id      :=  null ;
15408 
15409 
15410  IF TO_NUMBER(p_source_3) IS NULL 
15411  THEN 
15412 --
15413   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15414 
15415       trace
15416          (p_msg      => 'END of AcctDerRule_150'
15417          ,p_level    => C_LEVEL_PROCEDURE
15418          ,p_module   => l_log_module);
15419 
15420   END IF;
15421   x_value_combination_id  :=  null ;
15422   x_value_segment_code    :=  null ;
15423   x_value_type_code       := 'S';
15424   l_output_value          := TO_CHAR(p_source_11);
15425   RETURN l_output_value;
15426 
15427  ELSE 
15428     IF p_override_seg_flag = 'Y' THEN 
15429        RETURN '#$NO_OVERRIDE#$';
15430     END IF;
15431  END IF;
15432 
15433 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15434 
15435       trace
15436          (p_msg      => 'END of AcctDerRule_150(invalid)'
15437          ,p_level    => C_LEVEL_PROCEDURE
15438          ,p_module   => l_log_module);
15439 
15440 END IF;
15441 
15442 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
15443 x_value_combination_id  := null;
15444 x_value_segment_code    := null;
15445 x_value_type_code       := null;
15446 l_output_value          := null;
15447 xla_accounting_err_pkg.build_message
15448                  (p_appli_s_name            => 'XLA'
15449                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
15450                  ,p_token_1                 => 'COMPONENT_NAME'
15451                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
15452                                                             l_component_type
15453                                                           , l_component_code
15454                                                           , l_component_type_code
15455                                                           , l_component_appl_id
15456                                                           , l_amb_context_code
15457                                                           )
15458                  ,p_token_2                 => 'OWNER'
15459                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
15460                                                         'XLA_OWNER_TYPE'
15461                                                         ,l_component_type_code
15462                                                         )
15463                  ,p_token_3                 => 'PAD_NAME'
15464                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
15465                  ,p_token_4                 => 'PAD_OWNER'
15466                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
15467                                                         'XLA_OWNER_TYPE'
15468                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
15469                                                         )
15470                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
15471                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
15475 RETURN l_output_value;
15472                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
15473                  ,p_ae_header_id            => NULL
15474 );
15476 EXCEPTION
15477   WHEN xla_exceptions_pkg.application_exception THEN
15478       RAISE;
15479   WHEN OTHERS THEN
15480        xla_exceptions_pkg.raise_message
15481            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_150');
15482 END AcctDerRule_150;
15483 --
15484 
15485 ---------------------------------------
15486 --
15487 -- PRIVATE FUNCTION
15488 --         AcctDerRule_151
15489 --
15490 ---------------------------------------
15491 FUNCTION AcctDerRule_151 (
15492   p_application_id             IN NUMBER
15493 , p_ae_header_id               IN NUMBER
15494 , p_side                       IN VARCHAR2
15495 , p_override_seg_flag          IN VARCHAR2 
15496 --Generated Code Combination Identifier
15497  , p_source_3            IN NUMBER
15498 --Cost Of Removal Clearing Account
15499  , p_source_12            IN VARCHAR2
15500 , x_transaction_coa_id         OUT NOCOPY NUMBER
15501 , x_accounting_coa_id          OUT NOCOPY NUMBER
15502 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
15503 , x_flex_value_set_id          OUT NOCOPY NUMBER
15504 , x_value_type_code            OUT NOCOPY VARCHAR2
15505 , x_value_combination_id       OUT NOCOPY NUMBER
15506 , x_value_segment_code         OUT NOCOPY VARCHAR2
15507 )
15508 RETURN VARCHAR2
15509 IS
15510 l_component_type       VARCHAR2(80)  ;
15511 l_component_code       VARCHAR2(30)  ;
15512 l_component_type_code  VARCHAR2(1)   ;
15513 l_component_appl_id    INTEGER       ;
15514 l_amb_context_code     VARCHAR2(30)  ;
15515 l_log_module           VARCHAR2(240) ;
15516 l_output_value         VARCHAR2(30)  ;
15517 BEGIN
15518 IF g_log_enabled THEN
15519       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_151';
15520 END IF;
15521 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15522 
15523       trace
15524          (p_msg      => 'BEGIN of AcctDerRule_151'
15525          ,p_level    => C_LEVEL_PROCEDURE
15526          ,p_module   => l_log_module);
15527 
15528 END IF;
15529 
15530 l_component_type         := 'AMB_ADR';
15531 l_component_code         := 'FA_COST_OF_REMOVAL_CLR_SEGMENT';
15532 l_component_type_code    := 'S';
15533 l_component_appl_id      :=  140;
15534 l_amb_context_code       := 'DEFAULT';
15535 x_transaction_coa_id     :=  null;
15536 x_accounting_coa_id      :=  null;
15537 x_flexfield_segment_code := 'GL_ACCOUNT';
15538 x_flex_value_set_id      :=  null ;
15539 
15540 
15541  IF TO_NUMBER(p_source_3) IS NULL 
15542  THEN 
15543 --
15544   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15545 
15546       trace
15547          (p_msg      => 'END of AcctDerRule_151'
15548          ,p_level    => C_LEVEL_PROCEDURE
15549          ,p_module   => l_log_module);
15550 
15551   END IF;
15552   x_value_combination_id  :=  null ;
15553   x_value_segment_code    :=  null ;
15554   x_value_type_code       := 'S';
15555   l_output_value          := TO_CHAR(p_source_12);
15556   RETURN l_output_value;
15557 
15558  ELSE 
15559     IF p_override_seg_flag = 'Y' THEN 
15560        RETURN '#$NO_OVERRIDE#$';
15561     END IF;
15562  END IF;
15563 
15564 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15565 
15566       trace
15567          (p_msg      => 'END of AcctDerRule_151(invalid)'
15568          ,p_level    => C_LEVEL_PROCEDURE
15569          ,p_module   => l_log_module);
15570 
15571 END IF;
15572 
15573 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
15574 x_value_combination_id  := null;
15575 x_value_segment_code    := null;
15576 x_value_type_code       := null;
15577 l_output_value          := null;
15578 xla_accounting_err_pkg.build_message
15579                  (p_appli_s_name            => 'XLA'
15580                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
15581                  ,p_token_1                 => 'COMPONENT_NAME'
15582                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
15583                                                             l_component_type
15584                                                           , l_component_code
15585                                                           , l_component_type_code
15586                                                           , l_component_appl_id
15587                                                           , l_amb_context_code
15588                                                           )
15589                  ,p_token_2                 => 'OWNER'
15590                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
15591                                                         'XLA_OWNER_TYPE'
15592                                                         ,l_component_type_code
15593                                                         )
15594                  ,p_token_3                 => 'PAD_NAME'
15595                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
15596                  ,p_token_4                 => 'PAD_OWNER'
15597                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
15598                                                         'XLA_OWNER_TYPE'
15599                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
15600                                                         )
15601                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
15602                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
15603                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
15604                  ,p_ae_header_id            => NULL
15605 );
15609       RAISE;
15606 RETURN l_output_value;
15607 EXCEPTION
15608   WHEN xla_exceptions_pkg.application_exception THEN
15610   WHEN OTHERS THEN
15611        xla_exceptions_pkg.raise_message
15612            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_151');
15613 END AcctDerRule_151;
15614 --
15615 
15616 ---------------------------------------
15617 --
15618 -- PRIVATE FUNCTION
15619 --         AcctDerRule_152
15620 --
15621 ---------------------------------------
15622 FUNCTION AcctDerRule_152 (
15623   p_application_id             IN NUMBER
15624 , p_ae_header_id               IN NUMBER
15625 , p_side                       IN VARCHAR2
15626 , p_override_seg_flag          IN VARCHAR2 
15627 --Generated Code Combination Identifier
15628  , p_source_3            IN NUMBER
15629 --Cost Of Removal Gain Account
15630  , p_source_13            IN VARCHAR2
15631 , x_transaction_coa_id         OUT NOCOPY NUMBER
15632 , x_accounting_coa_id          OUT NOCOPY NUMBER
15633 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
15634 , x_flex_value_set_id          OUT NOCOPY NUMBER
15635 , x_value_type_code            OUT NOCOPY VARCHAR2
15636 , x_value_combination_id       OUT NOCOPY NUMBER
15637 , x_value_segment_code         OUT NOCOPY VARCHAR2
15638 )
15639 RETURN VARCHAR2
15640 IS
15641 l_component_type       VARCHAR2(80)  ;
15642 l_component_code       VARCHAR2(30)  ;
15643 l_component_type_code  VARCHAR2(1)   ;
15644 l_component_appl_id    INTEGER       ;
15645 l_amb_context_code     VARCHAR2(30)  ;
15646 l_log_module           VARCHAR2(240) ;
15647 l_output_value         VARCHAR2(30)  ;
15648 BEGIN
15649 IF g_log_enabled THEN
15650       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_152';
15651 END IF;
15652 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15653 
15654       trace
15655          (p_msg      => 'BEGIN of AcctDerRule_152'
15656          ,p_level    => C_LEVEL_PROCEDURE
15657          ,p_module   => l_log_module);
15658 
15659 END IF;
15660 
15661 l_component_type         := 'AMB_ADR';
15662 l_component_code         := 'FA_COST_OF_REM_GAIN_SEGMENT';
15663 l_component_type_code    := 'S';
15664 l_component_appl_id      :=  140;
15665 l_amb_context_code       := 'DEFAULT';
15666 x_transaction_coa_id     :=  null;
15667 x_accounting_coa_id      :=  null;
15668 x_flexfield_segment_code := 'GL_ACCOUNT';
15669 x_flex_value_set_id      :=  null ;
15670 
15671 
15672  IF TO_NUMBER(p_source_3) IS NULL 
15673  THEN 
15674 --
15675   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15676 
15677       trace
15678          (p_msg      => 'END of AcctDerRule_152'
15679          ,p_level    => C_LEVEL_PROCEDURE
15680          ,p_module   => l_log_module);
15681 
15682   END IF;
15683   x_value_combination_id  :=  null ;
15684   x_value_segment_code    :=  null ;
15685   x_value_type_code       := 'S';
15686   l_output_value          := TO_CHAR(p_source_13);
15687   RETURN l_output_value;
15688 
15689  ELSE 
15690     IF p_override_seg_flag = 'Y' THEN 
15691        RETURN '#$NO_OVERRIDE#$';
15692     END IF;
15693  END IF;
15694 
15695 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15696 
15697       trace
15698          (p_msg      => 'END of AcctDerRule_152(invalid)'
15699          ,p_level    => C_LEVEL_PROCEDURE
15700          ,p_module   => l_log_module);
15701 
15702 END IF;
15703 
15704 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
15705 x_value_combination_id  := null;
15706 x_value_segment_code    := null;
15707 x_value_type_code       := null;
15708 l_output_value          := null;
15709 xla_accounting_err_pkg.build_message
15710                  (p_appli_s_name            => 'XLA'
15711                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
15712                  ,p_token_1                 => 'COMPONENT_NAME'
15713                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
15714                                                             l_component_type
15715                                                           , l_component_code
15716                                                           , l_component_type_code
15717                                                           , l_component_appl_id
15718                                                           , l_amb_context_code
15719                                                           )
15720                  ,p_token_2                 => 'OWNER'
15721                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
15722                                                         'XLA_OWNER_TYPE'
15723                                                         ,l_component_type_code
15724                                                         )
15725                  ,p_token_3                 => 'PAD_NAME'
15726                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
15727                  ,p_token_4                 => 'PAD_OWNER'
15728                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
15729                                                         'XLA_OWNER_TYPE'
15730                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
15731                                                         )
15732                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
15733                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
15734                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
15735                  ,p_ae_header_id            => NULL
15736 );
15737 RETURN l_output_value;
15738 EXCEPTION
15739   WHEN xla_exceptions_pkg.application_exception THEN
15740       RAISE;
15741   WHEN OTHERS THEN
15745 --
15742        xla_exceptions_pkg.raise_message
15743            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_152');
15744 END AcctDerRule_152;
15746 
15747 ---------------------------------------
15748 --
15749 -- PRIVATE FUNCTION
15750 --         AcctDerRule_153
15751 --
15752 ---------------------------------------
15753 FUNCTION AcctDerRule_153 (
15754   p_application_id             IN NUMBER
15755 , p_ae_header_id               IN NUMBER
15756 , p_side                       IN VARCHAR2
15757 , p_override_seg_flag          IN VARCHAR2 
15758 --Generated Code Combination Identifier
15759  , p_source_3            IN NUMBER
15760 --Cost Of Removal Loss Account
15761  , p_source_14            IN VARCHAR2
15762 , x_transaction_coa_id         OUT NOCOPY NUMBER
15763 , x_accounting_coa_id          OUT NOCOPY NUMBER
15764 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
15765 , x_flex_value_set_id          OUT NOCOPY NUMBER
15766 , x_value_type_code            OUT NOCOPY VARCHAR2
15767 , x_value_combination_id       OUT NOCOPY NUMBER
15768 , x_value_segment_code         OUT NOCOPY VARCHAR2
15769 )
15770 RETURN VARCHAR2
15771 IS
15772 l_component_type       VARCHAR2(80)  ;
15773 l_component_code       VARCHAR2(30)  ;
15774 l_component_type_code  VARCHAR2(1)   ;
15775 l_component_appl_id    INTEGER       ;
15776 l_amb_context_code     VARCHAR2(30)  ;
15777 l_log_module           VARCHAR2(240) ;
15778 l_output_value         VARCHAR2(30)  ;
15779 BEGIN
15780 IF g_log_enabled THEN
15781       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_153';
15782 END IF;
15783 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15784 
15785       trace
15786          (p_msg      => 'BEGIN of AcctDerRule_153'
15787          ,p_level    => C_LEVEL_PROCEDURE
15788          ,p_module   => l_log_module);
15789 
15790 END IF;
15791 
15792 l_component_type         := 'AMB_ADR';
15793 l_component_code         := 'FA_COST_OF_REM_LOSS_SEGMENT';
15794 l_component_type_code    := 'S';
15795 l_component_appl_id      :=  140;
15796 l_amb_context_code       := 'DEFAULT';
15797 x_transaction_coa_id     :=  null;
15798 x_accounting_coa_id      :=  null;
15799 x_flexfield_segment_code := 'GL_ACCOUNT';
15800 x_flex_value_set_id      :=  null ;
15801 
15802 
15803  IF TO_NUMBER(p_source_3) IS NULL 
15804  THEN 
15805 --
15806   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15807 
15808       trace
15809          (p_msg      => 'END of AcctDerRule_153'
15810          ,p_level    => C_LEVEL_PROCEDURE
15811          ,p_module   => l_log_module);
15812 
15813   END IF;
15814   x_value_combination_id  :=  null ;
15815   x_value_segment_code    :=  null ;
15816   x_value_type_code       := 'S';
15817   l_output_value          := TO_CHAR(p_source_14);
15818   RETURN l_output_value;
15819 
15820  ELSE 
15821     IF p_override_seg_flag = 'Y' THEN 
15822        RETURN '#$NO_OVERRIDE#$';
15823     END IF;
15824  END IF;
15825 
15826 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15827 
15828       trace
15829          (p_msg      => 'END of AcctDerRule_153(invalid)'
15830          ,p_level    => C_LEVEL_PROCEDURE
15831          ,p_module   => l_log_module);
15832 
15833 END IF;
15834 
15835 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
15836 x_value_combination_id  := null;
15837 x_value_segment_code    := null;
15838 x_value_type_code       := null;
15839 l_output_value          := null;
15840 xla_accounting_err_pkg.build_message
15841                  (p_appli_s_name            => 'XLA'
15842                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
15843                  ,p_token_1                 => 'COMPONENT_NAME'
15844                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
15845                                                             l_component_type
15846                                                           , l_component_code
15847                                                           , l_component_type_code
15848                                                           , l_component_appl_id
15849                                                           , l_amb_context_code
15850                                                           )
15851                  ,p_token_2                 => 'OWNER'
15852                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
15853                                                         'XLA_OWNER_TYPE'
15854                                                         ,l_component_type_code
15855                                                         )
15856                  ,p_token_3                 => 'PAD_NAME'
15857                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
15858                  ,p_token_4                 => 'PAD_OWNER'
15859                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
15860                                                         'XLA_OWNER_TYPE'
15861                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
15862                                                         )
15863                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
15864                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
15865                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
15866                  ,p_ae_header_id            => NULL
15867 );
15868 RETURN l_output_value;
15869 EXCEPTION
15870   WHEN xla_exceptions_pkg.application_exception THEN
15871       RAISE;
15872   WHEN OTHERS THEN
15873        xla_exceptions_pkg.raise_message
15874            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_153');
15875 END AcctDerRule_153;
15876 --
15877 
15881 --         AcctDerRule_154
15878 ---------------------------------------
15879 --
15880 -- PRIVATE FUNCTION
15882 --
15883 ---------------------------------------
15884 FUNCTION AcctDerRule_154 (
15885   p_application_id             IN NUMBER
15886 , p_ae_header_id               IN NUMBER
15887 , p_side                       IN VARCHAR2
15888 , p_override_seg_flag          IN VARCHAR2 
15889 --Generated Code Combination Identifier
15890  , p_source_3            IN NUMBER
15891 --Deferred Depreciation Expense Account
15892  , p_source_15            IN VARCHAR2
15893 , x_transaction_coa_id         OUT NOCOPY NUMBER
15894 , x_accounting_coa_id          OUT NOCOPY NUMBER
15895 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
15896 , x_flex_value_set_id          OUT NOCOPY NUMBER
15897 , x_value_type_code            OUT NOCOPY VARCHAR2
15898 , x_value_combination_id       OUT NOCOPY NUMBER
15899 , x_value_segment_code         OUT NOCOPY VARCHAR2
15900 )
15901 RETURN VARCHAR2
15902 IS
15903 l_component_type       VARCHAR2(80)  ;
15904 l_component_code       VARCHAR2(30)  ;
15905 l_component_type_code  VARCHAR2(1)   ;
15906 l_component_appl_id    INTEGER       ;
15907 l_amb_context_code     VARCHAR2(30)  ;
15908 l_log_module           VARCHAR2(240) ;
15909 l_output_value         VARCHAR2(30)  ;
15910 BEGIN
15911 IF g_log_enabled THEN
15912       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_154';
15913 END IF;
15914 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15915 
15916       trace
15917          (p_msg      => 'BEGIN of AcctDerRule_154'
15918          ,p_level    => C_LEVEL_PROCEDURE
15919          ,p_module   => l_log_module);
15920 
15921 END IF;
15922 
15923 l_component_type         := 'AMB_ADR';
15924 l_component_code         := 'FA_DEF_DEPRN_EXPENSE_SEGMENT';
15925 l_component_type_code    := 'S';
15926 l_component_appl_id      :=  140;
15927 l_amb_context_code       := 'DEFAULT';
15928 x_transaction_coa_id     :=  null;
15929 x_accounting_coa_id      :=  null;
15930 x_flexfield_segment_code := 'GL_ACCOUNT';
15931 x_flex_value_set_id      :=  null ;
15932 
15933 
15934  IF TO_NUMBER(p_source_3) IS NULL 
15935  THEN 
15936 --
15937   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15938 
15939       trace
15940          (p_msg      => 'END of AcctDerRule_154'
15941          ,p_level    => C_LEVEL_PROCEDURE
15942          ,p_module   => l_log_module);
15943 
15944   END IF;
15945   x_value_combination_id  :=  null ;
15946   x_value_segment_code    :=  null ;
15947   x_value_type_code       := 'S';
15948   l_output_value          := TO_CHAR(p_source_15);
15949   RETURN l_output_value;
15950 
15951  ELSE 
15952     IF p_override_seg_flag = 'Y' THEN 
15953        RETURN '#$NO_OVERRIDE#$';
15954     END IF;
15955  END IF;
15956 
15957 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15958 
15959       trace
15960          (p_msg      => 'END of AcctDerRule_154(invalid)'
15961          ,p_level    => C_LEVEL_PROCEDURE
15962          ,p_module   => l_log_module);
15963 
15964 END IF;
15965 
15966 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
15967 x_value_combination_id  := null;
15968 x_value_segment_code    := null;
15969 x_value_type_code       := null;
15970 l_output_value          := null;
15971 xla_accounting_err_pkg.build_message
15972                  (p_appli_s_name            => 'XLA'
15973                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
15974                  ,p_token_1                 => 'COMPONENT_NAME'
15975                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
15976                                                             l_component_type
15977                                                           , l_component_code
15978                                                           , l_component_type_code
15979                                                           , l_component_appl_id
15980                                                           , l_amb_context_code
15981                                                           )
15982                  ,p_token_2                 => 'OWNER'
15983                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
15984                                                         'XLA_OWNER_TYPE'
15985                                                         ,l_component_type_code
15986                                                         )
15987                  ,p_token_3                 => 'PAD_NAME'
15988                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
15989                  ,p_token_4                 => 'PAD_OWNER'
15990                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
15991                                                         'XLA_OWNER_TYPE'
15992                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
15993                                                         )
15994                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
15995                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
15996                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
15997                  ,p_ae_header_id            => NULL
15998 );
15999 RETURN l_output_value;
16000 EXCEPTION
16001   WHEN xla_exceptions_pkg.application_exception THEN
16002       RAISE;
16003   WHEN OTHERS THEN
16004        xla_exceptions_pkg.raise_message
16005            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_154');
16006 END AcctDerRule_154;
16007 --
16008 
16009 ---------------------------------------
16010 --
16011 -- PRIVATE FUNCTION
16012 --         AcctDerRule_155
16013 --
16017 , p_ae_header_id               IN NUMBER
16014 ---------------------------------------
16015 FUNCTION AcctDerRule_155 (
16016   p_application_id             IN NUMBER
16018 , p_side                       IN VARCHAR2
16019 , p_override_seg_flag          IN VARCHAR2 
16020 --Deferred Depreciation Reserve Account
16021  , p_source_16            IN VARCHAR2
16022 --Generated Offset Code Combination Identifier
16023  , p_source_17            IN NUMBER
16024 , x_transaction_coa_id         OUT NOCOPY NUMBER
16025 , x_accounting_coa_id          OUT NOCOPY NUMBER
16026 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
16027 , x_flex_value_set_id          OUT NOCOPY NUMBER
16028 , x_value_type_code            OUT NOCOPY VARCHAR2
16029 , x_value_combination_id       OUT NOCOPY NUMBER
16030 , x_value_segment_code         OUT NOCOPY VARCHAR2
16031 )
16032 RETURN VARCHAR2
16033 IS
16034 l_component_type       VARCHAR2(80)  ;
16035 l_component_code       VARCHAR2(30)  ;
16036 l_component_type_code  VARCHAR2(1)   ;
16037 l_component_appl_id    INTEGER       ;
16038 l_amb_context_code     VARCHAR2(30)  ;
16039 l_log_module           VARCHAR2(240) ;
16040 l_output_value         VARCHAR2(30)  ;
16041 BEGIN
16042 IF g_log_enabled THEN
16043       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_155';
16044 END IF;
16045 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16046 
16047       trace
16048          (p_msg      => 'BEGIN of AcctDerRule_155'
16049          ,p_level    => C_LEVEL_PROCEDURE
16050          ,p_module   => l_log_module);
16051 
16052 END IF;
16053 
16054 l_component_type         := 'AMB_ADR';
16055 l_component_code         := 'FA_DEF_DEPRN_RESERVE_SEGMENT';
16056 l_component_type_code    := 'S';
16057 l_component_appl_id      :=  140;
16058 l_amb_context_code       := 'DEFAULT';
16059 x_transaction_coa_id     :=  null;
16060 x_accounting_coa_id      :=  null;
16061 x_flexfield_segment_code := 'GL_ACCOUNT';
16062 x_flex_value_set_id      :=  null ;
16063 
16064 
16065  IF TO_NUMBER(p_source_17) IS NULL 
16066  THEN 
16067 --
16068   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16069 
16070       trace
16071          (p_msg      => 'END of AcctDerRule_155'
16072          ,p_level    => C_LEVEL_PROCEDURE
16073          ,p_module   => l_log_module);
16074 
16075   END IF;
16076   x_value_combination_id  :=  null ;
16077   x_value_segment_code    :=  null ;
16078   x_value_type_code       := 'S';
16079   l_output_value          := TO_CHAR(p_source_16);
16080   RETURN l_output_value;
16081 
16082  ELSE 
16083     IF p_override_seg_flag = 'Y' THEN 
16084        RETURN '#$NO_OVERRIDE#$';
16085     END IF;
16086  END IF;
16087 
16088 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16089 
16090       trace
16091          (p_msg      => 'END of AcctDerRule_155(invalid)'
16092          ,p_level    => C_LEVEL_PROCEDURE
16093          ,p_module   => l_log_module);
16094 
16095 END IF;
16096 
16097 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
16098 x_value_combination_id  := null;
16099 x_value_segment_code    := null;
16100 x_value_type_code       := null;
16101 l_output_value          := null;
16102 xla_accounting_err_pkg.build_message
16103                  (p_appli_s_name            => 'XLA'
16104                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
16105                  ,p_token_1                 => 'COMPONENT_NAME'
16106                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
16107                                                             l_component_type
16108                                                           , l_component_code
16109                                                           , l_component_type_code
16110                                                           , l_component_appl_id
16111                                                           , l_amb_context_code
16112                                                           )
16113                  ,p_token_2                 => 'OWNER'
16114                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
16115                                                         'XLA_OWNER_TYPE'
16116                                                         ,l_component_type_code
16117                                                         )
16118                  ,p_token_3                 => 'PAD_NAME'
16119                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
16120                  ,p_token_4                 => 'PAD_OWNER'
16121                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
16122                                                         'XLA_OWNER_TYPE'
16123                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
16124                                                         )
16125                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
16126                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
16127                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
16128                  ,p_ae_header_id            => NULL
16129 );
16130 RETURN l_output_value;
16131 EXCEPTION
16132   WHEN xla_exceptions_pkg.application_exception THEN
16133       RAISE;
16134   WHEN OTHERS THEN
16135        xla_exceptions_pkg.raise_message
16136            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_155');
16137 END AcctDerRule_155;
16138 --
16139 
16140 ---------------------------------------
16141 --
16142 -- PRIVATE FUNCTION
16143 --         AcctDerRule_156
16144 --
16145 ---------------------------------------
16146 FUNCTION AcctDerRule_156 (
16147   p_application_id             IN NUMBER
16151 --Generated Code Combination Identifier
16148 , p_ae_header_id               IN NUMBER
16149 , p_side                       IN VARCHAR2
16150 , p_override_seg_flag          IN VARCHAR2 
16152  , p_source_3            IN NUMBER
16153 --Depreciation Adjustment Account
16154  , p_source_18            IN VARCHAR2
16155 , x_transaction_coa_id         OUT NOCOPY NUMBER
16156 , x_accounting_coa_id          OUT NOCOPY NUMBER
16157 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
16158 , x_flex_value_set_id          OUT NOCOPY NUMBER
16159 , x_value_type_code            OUT NOCOPY VARCHAR2
16160 , x_value_combination_id       OUT NOCOPY NUMBER
16161 , x_value_segment_code         OUT NOCOPY VARCHAR2
16162 )
16163 RETURN VARCHAR2
16164 IS
16165 l_component_type       VARCHAR2(80)  ;
16166 l_component_code       VARCHAR2(30)  ;
16167 l_component_type_code  VARCHAR2(1)   ;
16168 l_component_appl_id    INTEGER       ;
16169 l_amb_context_code     VARCHAR2(30)  ;
16170 l_log_module           VARCHAR2(240) ;
16171 l_output_value         VARCHAR2(30)  ;
16172 BEGIN
16173 IF g_log_enabled THEN
16174       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_156';
16175 END IF;
16176 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16177 
16178       trace
16179          (p_msg      => 'BEGIN of AcctDerRule_156'
16180          ,p_level    => C_LEVEL_PROCEDURE
16181          ,p_module   => l_log_module);
16182 
16183 END IF;
16184 
16185 l_component_type         := 'AMB_ADR';
16186 l_component_code         := 'FA_DEPRN_ADJUSTMENT_SEGMENT';
16187 l_component_type_code    := 'S';
16188 l_component_appl_id      :=  140;
16189 l_amb_context_code       := 'DEFAULT';
16190 x_transaction_coa_id     :=  null;
16191 x_accounting_coa_id      :=  null;
16192 x_flexfield_segment_code := 'GL_ACCOUNT';
16193 x_flex_value_set_id      :=  null ;
16194 
16195 
16196  IF TO_NUMBER(p_source_3) IS NULL 
16197  THEN 
16198 --
16199   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16200 
16201       trace
16202          (p_msg      => 'END of AcctDerRule_156'
16203          ,p_level    => C_LEVEL_PROCEDURE
16204          ,p_module   => l_log_module);
16205 
16206   END IF;
16207   x_value_combination_id  :=  null ;
16208   x_value_segment_code    :=  null ;
16209   x_value_type_code       := 'S';
16210   l_output_value          := TO_CHAR(p_source_18);
16211   RETURN l_output_value;
16212 
16213  ELSE 
16214     IF p_override_seg_flag = 'Y' THEN 
16215        RETURN '#$NO_OVERRIDE#$';
16216     END IF;
16217  END IF;
16218 
16219 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16220 
16221       trace
16222          (p_msg      => 'END of AcctDerRule_156(invalid)'
16223          ,p_level    => C_LEVEL_PROCEDURE
16224          ,p_module   => l_log_module);
16225 
16226 END IF;
16227 
16228 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
16229 x_value_combination_id  := null;
16230 x_value_segment_code    := null;
16231 x_value_type_code       := null;
16232 l_output_value          := null;
16233 xla_accounting_err_pkg.build_message
16234                  (p_appli_s_name            => 'XLA'
16235                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
16236                  ,p_token_1                 => 'COMPONENT_NAME'
16237                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
16238                                                             l_component_type
16239                                                           , l_component_code
16240                                                           , l_component_type_code
16241                                                           , l_component_appl_id
16242                                                           , l_amb_context_code
16243                                                           )
16244                  ,p_token_2                 => 'OWNER'
16245                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
16246                                                         'XLA_OWNER_TYPE'
16247                                                         ,l_component_type_code
16248                                                         )
16249                  ,p_token_3                 => 'PAD_NAME'
16250                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
16251                  ,p_token_4                 => 'PAD_OWNER'
16252                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
16253                                                         'XLA_OWNER_TYPE'
16254                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
16255                                                         )
16256                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
16257                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
16258                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
16259                  ,p_ae_header_id            => NULL
16260 );
16261 RETURN l_output_value;
16262 EXCEPTION
16263   WHEN xla_exceptions_pkg.application_exception THEN
16264       RAISE;
16265   WHEN OTHERS THEN
16266        xla_exceptions_pkg.raise_message
16267            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_156');
16268 END AcctDerRule_156;
16269 --
16270 
16271 ---------------------------------------
16272 --
16273 -- PRIVATE FUNCTION
16274 --         AcctDerRule_157
16275 --
16276 ---------------------------------------
16277 FUNCTION AcctDerRule_157 (
16278   p_application_id             IN NUMBER
16279 , p_ae_header_id               IN NUMBER
16280 , p_side                       IN VARCHAR2
16281 , p_override_seg_flag          IN VARCHAR2 
16285  , p_source_19            IN VARCHAR2
16282 --Generated Code Combination Identifier
16283  , p_source_3            IN NUMBER
16284 --Intercompany Payables Account
16286 , x_transaction_coa_id         OUT NOCOPY NUMBER
16287 , x_accounting_coa_id          OUT NOCOPY NUMBER
16288 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
16289 , x_flex_value_set_id          OUT NOCOPY NUMBER
16290 , x_value_type_code            OUT NOCOPY VARCHAR2
16291 , x_value_combination_id       OUT NOCOPY NUMBER
16292 , x_value_segment_code         OUT NOCOPY VARCHAR2
16293 )
16294 RETURN VARCHAR2
16295 IS
16296 l_component_type       VARCHAR2(80)  ;
16297 l_component_code       VARCHAR2(30)  ;
16298 l_component_type_code  VARCHAR2(1)   ;
16299 l_component_appl_id    INTEGER       ;
16300 l_amb_context_code     VARCHAR2(30)  ;
16301 l_log_module           VARCHAR2(240) ;
16302 l_output_value         VARCHAR2(30)  ;
16303 BEGIN
16304 IF g_log_enabled THEN
16305       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_157';
16306 END IF;
16307 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16308 
16309       trace
16310          (p_msg      => 'BEGIN of AcctDerRule_157'
16311          ,p_level    => C_LEVEL_PROCEDURE
16312          ,p_module   => l_log_module);
16313 
16314 END IF;
16315 
16316 l_component_type         := 'AMB_ADR';
16317 l_component_code         := 'FA_IC_PAYABLE_ACCOUNT';
16318 l_component_type_code    := 'S';
16319 l_component_appl_id      :=  140;
16320 l_amb_context_code       := 'DEFAULT';
16321 x_transaction_coa_id     :=  null;
16322 x_accounting_coa_id      :=  null;
16323 x_flexfield_segment_code := 'GL_ACCOUNT';
16324 x_flex_value_set_id      :=  null ;
16325 
16326 
16327  IF TO_NUMBER(p_source_3) IS NULL 
16328  THEN 
16329 --
16330   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16331 
16332       trace
16333          (p_msg      => 'END of AcctDerRule_157'
16334          ,p_level    => C_LEVEL_PROCEDURE
16335          ,p_module   => l_log_module);
16336 
16337   END IF;
16338   x_value_combination_id  :=  null ;
16339   x_value_segment_code    :=  null ;
16340   x_value_type_code       := 'S';
16341   l_output_value          := TO_CHAR(p_source_19);
16342   RETURN l_output_value;
16343 
16344  ELSE 
16345     IF p_override_seg_flag = 'Y' THEN 
16346        RETURN '#$NO_OVERRIDE#$';
16347     END IF;
16348  END IF;
16349 
16350 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16351 
16352       trace
16353          (p_msg      => 'END of AcctDerRule_157(invalid)'
16354          ,p_level    => C_LEVEL_PROCEDURE
16355          ,p_module   => l_log_module);
16356 
16357 END IF;
16358 
16359 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
16360 x_value_combination_id  := null;
16361 x_value_segment_code    := null;
16362 x_value_type_code       := null;
16363 l_output_value          := null;
16364 xla_accounting_err_pkg.build_message
16365                  (p_appli_s_name            => 'XLA'
16366                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
16367                  ,p_token_1                 => 'COMPONENT_NAME'
16368                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
16369                                                             l_component_type
16370                                                           , l_component_code
16371                                                           , l_component_type_code
16372                                                           , l_component_appl_id
16373                                                           , l_amb_context_code
16374                                                           )
16375                  ,p_token_2                 => 'OWNER'
16376                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
16377                                                         'XLA_OWNER_TYPE'
16378                                                         ,l_component_type_code
16379                                                         )
16380                  ,p_token_3                 => 'PAD_NAME'
16381                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
16382                  ,p_token_4                 => 'PAD_OWNER'
16383                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
16384                                                         'XLA_OWNER_TYPE'
16385                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
16386                                                         )
16387                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
16388                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
16389                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
16390                  ,p_ae_header_id            => NULL
16391 );
16392 RETURN l_output_value;
16393 EXCEPTION
16394   WHEN xla_exceptions_pkg.application_exception THEN
16395       RAISE;
16396   WHEN OTHERS THEN
16397        xla_exceptions_pkg.raise_message
16398            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_157');
16399 END AcctDerRule_157;
16400 --
16401 
16402 ---------------------------------------
16403 --
16404 -- PRIVATE FUNCTION
16405 --         AcctDerRule_158
16406 --
16407 ---------------------------------------
16408 FUNCTION AcctDerRule_158 (
16409   p_application_id             IN NUMBER
16410 , p_ae_header_id               IN NUMBER
16411 , p_side                       IN VARCHAR2
16412 , p_override_seg_flag          IN VARCHAR2 
16413 --Generated Code Combination Identifier
16414  , p_source_3            IN NUMBER
16415 --Intercompany Receivables Account
16416  , p_source_20            IN VARCHAR2
16420 , x_flex_value_set_id          OUT NOCOPY NUMBER
16417 , x_transaction_coa_id         OUT NOCOPY NUMBER
16418 , x_accounting_coa_id          OUT NOCOPY NUMBER
16419 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
16421 , x_value_type_code            OUT NOCOPY VARCHAR2
16422 , x_value_combination_id       OUT NOCOPY NUMBER
16423 , x_value_segment_code         OUT NOCOPY VARCHAR2
16424 )
16425 RETURN VARCHAR2
16426 IS
16427 l_component_type       VARCHAR2(80)  ;
16428 l_component_code       VARCHAR2(30)  ;
16429 l_component_type_code  VARCHAR2(1)   ;
16430 l_component_appl_id    INTEGER       ;
16431 l_amb_context_code     VARCHAR2(30)  ;
16432 l_log_module           VARCHAR2(240) ;
16433 l_output_value         VARCHAR2(30)  ;
16434 BEGIN
16435 IF g_log_enabled THEN
16436       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_158';
16437 END IF;
16438 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16439 
16440       trace
16441          (p_msg      => 'BEGIN of AcctDerRule_158'
16442          ,p_level    => C_LEVEL_PROCEDURE
16443          ,p_module   => l_log_module);
16444 
16445 END IF;
16446 
16447 l_component_type         := 'AMB_ADR';
16448 l_component_code         := 'FA_IC_RECEIVABLE_ACCOUNT';
16449 l_component_type_code    := 'S';
16450 l_component_appl_id      :=  140;
16451 l_amb_context_code       := 'DEFAULT';
16452 x_transaction_coa_id     :=  null;
16453 x_accounting_coa_id      :=  null;
16454 x_flexfield_segment_code := 'GL_ACCOUNT';
16455 x_flex_value_set_id      :=  null ;
16456 
16457 
16458  IF TO_NUMBER(p_source_3) IS NULL 
16459  THEN 
16460 --
16461   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16462 
16463       trace
16464          (p_msg      => 'END of AcctDerRule_158'
16465          ,p_level    => C_LEVEL_PROCEDURE
16466          ,p_module   => l_log_module);
16467 
16468   END IF;
16469   x_value_combination_id  :=  null ;
16470   x_value_segment_code    :=  null ;
16471   x_value_type_code       := 'S';
16472   l_output_value          := TO_CHAR(p_source_20);
16473   RETURN l_output_value;
16474 
16475  ELSE 
16476     IF p_override_seg_flag = 'Y' THEN 
16477        RETURN '#$NO_OVERRIDE#$';
16478     END IF;
16479  END IF;
16480 
16481 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16482 
16483       trace
16484          (p_msg      => 'END of AcctDerRule_158(invalid)'
16485          ,p_level    => C_LEVEL_PROCEDURE
16486          ,p_module   => l_log_module);
16487 
16488 END IF;
16489 
16490 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
16491 x_value_combination_id  := null;
16492 x_value_segment_code    := null;
16493 x_value_type_code       := null;
16494 l_output_value          := null;
16495 xla_accounting_err_pkg.build_message
16496                  (p_appli_s_name            => 'XLA'
16497                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
16498                  ,p_token_1                 => 'COMPONENT_NAME'
16499                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
16500                                                             l_component_type
16501                                                           , l_component_code
16502                                                           , l_component_type_code
16503                                                           , l_component_appl_id
16504                                                           , l_amb_context_code
16505                                                           )
16506                  ,p_token_2                 => 'OWNER'
16507                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
16508                                                         'XLA_OWNER_TYPE'
16509                                                         ,l_component_type_code
16510                                                         )
16511                  ,p_token_3                 => 'PAD_NAME'
16512                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
16513                  ,p_token_4                 => 'PAD_OWNER'
16514                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
16515                                                         'XLA_OWNER_TYPE'
16516                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
16517                                                         )
16518                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
16519                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
16520                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
16521                  ,p_ae_header_id            => NULL
16522 );
16523 RETURN l_output_value;
16524 EXCEPTION
16525   WHEN xla_exceptions_pkg.application_exception THEN
16526       RAISE;
16527   WHEN OTHERS THEN
16528        xla_exceptions_pkg.raise_message
16529            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_158');
16530 END AcctDerRule_158;
16531 --
16532 
16533 ---------------------------------------
16534 --
16535 -- PRIVATE FUNCTION
16536 --         AcctDerRule_159
16537 --
16538 ---------------------------------------
16539 FUNCTION AcctDerRule_159 (
16540   p_application_id             IN NUMBER
16541 , p_ae_header_id               IN NUMBER
16542 , p_side                       IN VARCHAR2
16543 , p_override_seg_flag          IN VARCHAR2 
16544 --Generated Code Combination Identifier
16545  , p_source_3            IN NUMBER
16546 --Net Book Value Retired Gain Account
16547  , p_source_21            IN VARCHAR2
16548 , x_transaction_coa_id         OUT NOCOPY NUMBER
16549 , x_accounting_coa_id          OUT NOCOPY NUMBER
16550 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
16554 , x_value_segment_code         OUT NOCOPY VARCHAR2
16551 , x_flex_value_set_id          OUT NOCOPY NUMBER
16552 , x_value_type_code            OUT NOCOPY VARCHAR2
16553 , x_value_combination_id       OUT NOCOPY NUMBER
16555 )
16556 RETURN VARCHAR2
16557 IS
16558 l_component_type       VARCHAR2(80)  ;
16559 l_component_code       VARCHAR2(30)  ;
16560 l_component_type_code  VARCHAR2(1)   ;
16561 l_component_appl_id    INTEGER       ;
16562 l_amb_context_code     VARCHAR2(30)  ;
16563 l_log_module           VARCHAR2(240) ;
16564 l_output_value         VARCHAR2(30)  ;
16565 BEGIN
16566 IF g_log_enabled THEN
16567       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_159';
16568 END IF;
16569 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16570 
16571       trace
16572          (p_msg      => 'BEGIN of AcctDerRule_159'
16573          ,p_level    => C_LEVEL_PROCEDURE
16574          ,p_module   => l_log_module);
16575 
16576 END IF;
16577 
16578 l_component_type         := 'AMB_ADR';
16579 l_component_code         := 'FA_NBV_RETIRED_GAIN_SEGMENT';
16580 l_component_type_code    := 'S';
16581 l_component_appl_id      :=  140;
16582 l_amb_context_code       := 'DEFAULT';
16583 x_transaction_coa_id     :=  null;
16584 x_accounting_coa_id      :=  null;
16585 x_flexfield_segment_code := 'GL_ACCOUNT';
16586 x_flex_value_set_id      :=  null ;
16587 
16588 
16589  IF TO_NUMBER(p_source_3) IS NULL 
16590  THEN 
16591 --
16592   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16593 
16594       trace
16595          (p_msg      => 'END of AcctDerRule_159'
16596          ,p_level    => C_LEVEL_PROCEDURE
16597          ,p_module   => l_log_module);
16598 
16599   END IF;
16600   x_value_combination_id  :=  null ;
16601   x_value_segment_code    :=  null ;
16602   x_value_type_code       := 'S';
16603   l_output_value          := TO_CHAR(p_source_21);
16604   RETURN l_output_value;
16605 
16606  ELSE 
16607     IF p_override_seg_flag = 'Y' THEN 
16608        RETURN '#$NO_OVERRIDE#$';
16609     END IF;
16610  END IF;
16611 
16612 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16613 
16614       trace
16615          (p_msg      => 'END of AcctDerRule_159(invalid)'
16616          ,p_level    => C_LEVEL_PROCEDURE
16617          ,p_module   => l_log_module);
16618 
16619 END IF;
16620 
16621 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
16622 x_value_combination_id  := null;
16623 x_value_segment_code    := null;
16624 x_value_type_code       := null;
16625 l_output_value          := null;
16626 xla_accounting_err_pkg.build_message
16627                  (p_appli_s_name            => 'XLA'
16628                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
16629                  ,p_token_1                 => 'COMPONENT_NAME'
16630                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
16631                                                             l_component_type
16632                                                           , l_component_code
16633                                                           , l_component_type_code
16634                                                           , l_component_appl_id
16635                                                           , l_amb_context_code
16636                                                           )
16637                  ,p_token_2                 => 'OWNER'
16638                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
16639                                                         'XLA_OWNER_TYPE'
16640                                                         ,l_component_type_code
16641                                                         )
16642                  ,p_token_3                 => 'PAD_NAME'
16643                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
16644                  ,p_token_4                 => 'PAD_OWNER'
16645                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
16646                                                         'XLA_OWNER_TYPE'
16647                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
16648                                                         )
16649                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
16650                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
16651                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
16652                  ,p_ae_header_id            => NULL
16653 );
16654 RETURN l_output_value;
16655 EXCEPTION
16656   WHEN xla_exceptions_pkg.application_exception THEN
16657       RAISE;
16658   WHEN OTHERS THEN
16659        xla_exceptions_pkg.raise_message
16660            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_159');
16661 END AcctDerRule_159;
16662 --
16663 
16664 ---------------------------------------
16665 --
16666 -- PRIVATE FUNCTION
16667 --         AcctDerRule_160
16668 --
16669 ---------------------------------------
16670 FUNCTION AcctDerRule_160 (
16671   p_application_id             IN NUMBER
16672 , p_ae_header_id               IN NUMBER
16673 , p_side                       IN VARCHAR2
16674 , p_override_seg_flag          IN VARCHAR2 
16675 --Generated Code Combination Identifier
16676  , p_source_3            IN NUMBER
16677 --Net Book Value Retired Loss Account
16678  , p_source_22            IN VARCHAR2
16679 , x_transaction_coa_id         OUT NOCOPY NUMBER
16680 , x_accounting_coa_id          OUT NOCOPY NUMBER
16681 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
16682 , x_flex_value_set_id          OUT NOCOPY NUMBER
16683 , x_value_type_code            OUT NOCOPY VARCHAR2
16684 , x_value_combination_id       OUT NOCOPY NUMBER
16688 IS
16685 , x_value_segment_code         OUT NOCOPY VARCHAR2
16686 )
16687 RETURN VARCHAR2
16689 l_component_type       VARCHAR2(80)  ;
16690 l_component_code       VARCHAR2(30)  ;
16691 l_component_type_code  VARCHAR2(1)   ;
16692 l_component_appl_id    INTEGER       ;
16693 l_amb_context_code     VARCHAR2(30)  ;
16694 l_log_module           VARCHAR2(240) ;
16695 l_output_value         VARCHAR2(30)  ;
16696 BEGIN
16697 IF g_log_enabled THEN
16698       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_160';
16699 END IF;
16700 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16701 
16702       trace
16703          (p_msg      => 'BEGIN of AcctDerRule_160'
16704          ,p_level    => C_LEVEL_PROCEDURE
16705          ,p_module   => l_log_module);
16706 
16707 END IF;
16708 
16709 l_component_type         := 'AMB_ADR';
16710 l_component_code         := 'FA_NBV_RETIRED_LOSS_SEGMENT';
16711 l_component_type_code    := 'S';
16712 l_component_appl_id      :=  140;
16713 l_amb_context_code       := 'DEFAULT';
16714 x_transaction_coa_id     :=  null;
16715 x_accounting_coa_id      :=  null;
16716 x_flexfield_segment_code := 'GL_ACCOUNT';
16717 x_flex_value_set_id      :=  null ;
16718 
16719 
16720  IF TO_NUMBER(p_source_3) IS NULL 
16721  THEN 
16722 --
16723   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16724 
16725       trace
16726          (p_msg      => 'END of AcctDerRule_160'
16727          ,p_level    => C_LEVEL_PROCEDURE
16728          ,p_module   => l_log_module);
16729 
16730   END IF;
16731   x_value_combination_id  :=  null ;
16732   x_value_segment_code    :=  null ;
16733   x_value_type_code       := 'S';
16734   l_output_value          := TO_CHAR(p_source_22);
16735   RETURN l_output_value;
16736 
16737  ELSE 
16738     IF p_override_seg_flag = 'Y' THEN 
16739        RETURN '#$NO_OVERRIDE#$';
16740     END IF;
16741  END IF;
16742 
16743 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16744 
16745       trace
16746          (p_msg      => 'END of AcctDerRule_160(invalid)'
16747          ,p_level    => C_LEVEL_PROCEDURE
16748          ,p_module   => l_log_module);
16749 
16750 END IF;
16751 
16752 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
16753 x_value_combination_id  := null;
16754 x_value_segment_code    := null;
16755 x_value_type_code       := null;
16756 l_output_value          := null;
16757 xla_accounting_err_pkg.build_message
16758                  (p_appli_s_name            => 'XLA'
16759                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
16760                  ,p_token_1                 => 'COMPONENT_NAME'
16761                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
16762                                                             l_component_type
16763                                                           , l_component_code
16764                                                           , l_component_type_code
16765                                                           , l_component_appl_id
16766                                                           , l_amb_context_code
16767                                                           )
16768                  ,p_token_2                 => 'OWNER'
16769                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
16770                                                         'XLA_OWNER_TYPE'
16771                                                         ,l_component_type_code
16772                                                         )
16773                  ,p_token_3                 => 'PAD_NAME'
16774                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
16775                  ,p_token_4                 => 'PAD_OWNER'
16776                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
16777                                                         'XLA_OWNER_TYPE'
16778                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
16779                                                         )
16780                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
16781                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
16782                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
16783                  ,p_ae_header_id            => NULL
16784 );
16785 RETURN l_output_value;
16786 EXCEPTION
16787   WHEN xla_exceptions_pkg.application_exception THEN
16788       RAISE;
16789   WHEN OTHERS THEN
16790        xla_exceptions_pkg.raise_message
16791            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_160');
16792 END AcctDerRule_160;
16793 --
16794 
16795 ---------------------------------------
16796 --
16797 -- PRIVATE FUNCTION
16798 --         AcctDerRule_161
16799 --
16800 ---------------------------------------
16801 FUNCTION AcctDerRule_161 (
16802   p_application_id             IN NUMBER
16803 , p_ae_header_id               IN NUMBER
16804 , p_side                       IN VARCHAR2
16805 , p_override_seg_flag          IN VARCHAR2 
16806 --Generated Code Combination Identifier
16807  , p_source_3            IN NUMBER
16808 --Proceeds Of Sale Clearing Account
16809  , p_source_23            IN VARCHAR2
16810 , x_transaction_coa_id         OUT NOCOPY NUMBER
16811 , x_accounting_coa_id          OUT NOCOPY NUMBER
16812 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
16813 , x_flex_value_set_id          OUT NOCOPY NUMBER
16814 , x_value_type_code            OUT NOCOPY VARCHAR2
16815 , x_value_combination_id       OUT NOCOPY NUMBER
16816 , x_value_segment_code         OUT NOCOPY VARCHAR2
16817 )
16818 RETURN VARCHAR2
16819 IS
16820 l_component_type       VARCHAR2(80)  ;
16824 l_amb_context_code     VARCHAR2(30)  ;
16821 l_component_code       VARCHAR2(30)  ;
16822 l_component_type_code  VARCHAR2(1)   ;
16823 l_component_appl_id    INTEGER       ;
16825 l_log_module           VARCHAR2(240) ;
16826 l_output_value         VARCHAR2(30)  ;
16827 BEGIN
16828 IF g_log_enabled THEN
16829       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_161';
16830 END IF;
16831 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16832 
16833       trace
16834          (p_msg      => 'BEGIN of AcctDerRule_161'
16835          ,p_level    => C_LEVEL_PROCEDURE
16836          ,p_module   => l_log_module);
16837 
16838 END IF;
16839 
16840 l_component_type         := 'AMB_ADR';
16841 l_component_code         := 'FA_PROC_OF_SALE_CLR_SEGMENT';
16842 l_component_type_code    := 'S';
16843 l_component_appl_id      :=  140;
16844 l_amb_context_code       := 'DEFAULT';
16845 x_transaction_coa_id     :=  null;
16846 x_accounting_coa_id      :=  null;
16847 x_flexfield_segment_code := 'GL_ACCOUNT';
16848 x_flex_value_set_id      :=  null ;
16849 
16850 
16851  IF TO_NUMBER(p_source_3) IS NULL 
16852  THEN 
16853 --
16854   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16855 
16856       trace
16857          (p_msg      => 'END of AcctDerRule_161'
16858          ,p_level    => C_LEVEL_PROCEDURE
16859          ,p_module   => l_log_module);
16860 
16861   END IF;
16862   x_value_combination_id  :=  null ;
16863   x_value_segment_code    :=  null ;
16864   x_value_type_code       := 'S';
16865   l_output_value          := TO_CHAR(p_source_23);
16866   RETURN l_output_value;
16867 
16868  ELSE 
16869     IF p_override_seg_flag = 'Y' THEN 
16870        RETURN '#$NO_OVERRIDE#$';
16871     END IF;
16872  END IF;
16873 
16874 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16875 
16876       trace
16877          (p_msg      => 'END of AcctDerRule_161(invalid)'
16878          ,p_level    => C_LEVEL_PROCEDURE
16879          ,p_module   => l_log_module);
16880 
16881 END IF;
16882 
16883 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
16884 x_value_combination_id  := null;
16885 x_value_segment_code    := null;
16886 x_value_type_code       := null;
16887 l_output_value          := null;
16888 xla_accounting_err_pkg.build_message
16889                  (p_appli_s_name            => 'XLA'
16890                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
16891                  ,p_token_1                 => 'COMPONENT_NAME'
16892                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
16893                                                             l_component_type
16894                                                           , l_component_code
16895                                                           , l_component_type_code
16896                                                           , l_component_appl_id
16897                                                           , l_amb_context_code
16898                                                           )
16899                  ,p_token_2                 => 'OWNER'
16900                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
16901                                                         'XLA_OWNER_TYPE'
16902                                                         ,l_component_type_code
16903                                                         )
16904                  ,p_token_3                 => 'PAD_NAME'
16905                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
16906                  ,p_token_4                 => 'PAD_OWNER'
16907                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
16908                                                         'XLA_OWNER_TYPE'
16909                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
16910                                                         )
16911                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
16912                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
16913                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
16914                  ,p_ae_header_id            => NULL
16915 );
16916 RETURN l_output_value;
16917 EXCEPTION
16918   WHEN xla_exceptions_pkg.application_exception THEN
16919       RAISE;
16920   WHEN OTHERS THEN
16921        xla_exceptions_pkg.raise_message
16922            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_161');
16923 END AcctDerRule_161;
16924 --
16925 
16926 ---------------------------------------
16927 --
16928 -- PRIVATE FUNCTION
16929 --         AcctDerRule_162
16930 --
16931 ---------------------------------------
16932 FUNCTION AcctDerRule_162 (
16933   p_application_id             IN NUMBER
16934 , p_ae_header_id               IN NUMBER
16935 , p_side                       IN VARCHAR2
16936 , p_override_seg_flag          IN VARCHAR2 
16937 --Generated Code Combination Identifier
16938  , p_source_3            IN NUMBER
16939 --Proceeds Of Sale Gain Account
16940  , p_source_24            IN VARCHAR2
16941 , x_transaction_coa_id         OUT NOCOPY NUMBER
16942 , x_accounting_coa_id          OUT NOCOPY NUMBER
16943 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
16944 , x_flex_value_set_id          OUT NOCOPY NUMBER
16945 , x_value_type_code            OUT NOCOPY VARCHAR2
16946 , x_value_combination_id       OUT NOCOPY NUMBER
16947 , x_value_segment_code         OUT NOCOPY VARCHAR2
16948 )
16949 RETURN VARCHAR2
16950 IS
16951 l_component_type       VARCHAR2(80)  ;
16952 l_component_code       VARCHAR2(30)  ;
16953 l_component_type_code  VARCHAR2(1)   ;
16954 l_component_appl_id    INTEGER       ;
16955 l_amb_context_code     VARCHAR2(30)  ;
16959 IF g_log_enabled THEN
16956 l_log_module           VARCHAR2(240) ;
16957 l_output_value         VARCHAR2(30)  ;
16958 BEGIN
16960       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_162';
16961 END IF;
16962 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16963 
16964       trace
16965          (p_msg      => 'BEGIN of AcctDerRule_162'
16966          ,p_level    => C_LEVEL_PROCEDURE
16967          ,p_module   => l_log_module);
16968 
16969 END IF;
16970 
16971 l_component_type         := 'AMB_ADR';
16972 l_component_code         := 'FA_PROC_OF_SALE_GAIN_SEGMENT';
16973 l_component_type_code    := 'S';
16974 l_component_appl_id      :=  140;
16975 l_amb_context_code       := 'DEFAULT';
16976 x_transaction_coa_id     :=  null;
16977 x_accounting_coa_id      :=  null;
16978 x_flexfield_segment_code := 'GL_ACCOUNT';
16979 x_flex_value_set_id      :=  null ;
16980 
16981 
16982  IF TO_NUMBER(p_source_3) IS NULL 
16983  THEN 
16984 --
16985   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16986 
16987       trace
16988          (p_msg      => 'END of AcctDerRule_162'
16989          ,p_level    => C_LEVEL_PROCEDURE
16990          ,p_module   => l_log_module);
16991 
16992   END IF;
16993   x_value_combination_id  :=  null ;
16994   x_value_segment_code    :=  null ;
16995   x_value_type_code       := 'S';
16996   l_output_value          := TO_CHAR(p_source_24);
16997   RETURN l_output_value;
16998 
16999  ELSE 
17000     IF p_override_seg_flag = 'Y' THEN 
17001        RETURN '#$NO_OVERRIDE#$';
17002     END IF;
17003  END IF;
17004 
17005 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17006 
17007       trace
17008          (p_msg      => 'END of AcctDerRule_162(invalid)'
17009          ,p_level    => C_LEVEL_PROCEDURE
17010          ,p_module   => l_log_module);
17011 
17012 END IF;
17013 
17014 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
17015 x_value_combination_id  := null;
17016 x_value_segment_code    := null;
17017 x_value_type_code       := null;
17018 l_output_value          := null;
17019 xla_accounting_err_pkg.build_message
17020                  (p_appli_s_name            => 'XLA'
17021                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
17022                  ,p_token_1                 => 'COMPONENT_NAME'
17023                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
17024                                                             l_component_type
17025                                                           , l_component_code
17026                                                           , l_component_type_code
17027                                                           , l_component_appl_id
17028                                                           , l_amb_context_code
17029                                                           )
17030                  ,p_token_2                 => 'OWNER'
17031                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
17032                                                         'XLA_OWNER_TYPE'
17033                                                         ,l_component_type_code
17034                                                         )
17035                  ,p_token_3                 => 'PAD_NAME'
17036                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
17037                  ,p_token_4                 => 'PAD_OWNER'
17038                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
17039                                                         'XLA_OWNER_TYPE'
17040                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
17041                                                         )
17042                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
17043                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
17044                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
17045                  ,p_ae_header_id            => NULL
17046 );
17047 RETURN l_output_value;
17048 EXCEPTION
17049   WHEN xla_exceptions_pkg.application_exception THEN
17050       RAISE;
17051   WHEN OTHERS THEN
17052        xla_exceptions_pkg.raise_message
17053            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_162');
17054 END AcctDerRule_162;
17055 --
17056 
17057 ---------------------------------------
17058 --
17059 -- PRIVATE FUNCTION
17060 --         AcctDerRule_163
17061 --
17062 ---------------------------------------
17063 FUNCTION AcctDerRule_163 (
17064   p_application_id             IN NUMBER
17065 , p_ae_header_id               IN NUMBER
17066 , p_side                       IN VARCHAR2
17067 , p_override_seg_flag          IN VARCHAR2 
17068 --Generated Code Combination Identifier
17069  , p_source_3            IN NUMBER
17070 --Proceeds Of Sale Loss Account
17071  , p_source_25            IN VARCHAR2
17072 , x_transaction_coa_id         OUT NOCOPY NUMBER
17073 , x_accounting_coa_id          OUT NOCOPY NUMBER
17074 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
17075 , x_flex_value_set_id          OUT NOCOPY NUMBER
17076 , x_value_type_code            OUT NOCOPY VARCHAR2
17077 , x_value_combination_id       OUT NOCOPY NUMBER
17078 , x_value_segment_code         OUT NOCOPY VARCHAR2
17079 )
17080 RETURN VARCHAR2
17081 IS
17082 l_component_type       VARCHAR2(80)  ;
17083 l_component_code       VARCHAR2(30)  ;
17084 l_component_type_code  VARCHAR2(1)   ;
17085 l_component_appl_id    INTEGER       ;
17086 l_amb_context_code     VARCHAR2(30)  ;
17087 l_log_module           VARCHAR2(240) ;
17088 l_output_value         VARCHAR2(30)  ;
17089 BEGIN
17090 IF g_log_enabled THEN
17094 
17091       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_163';
17092 END IF;
17093 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17095       trace
17096          (p_msg      => 'BEGIN of AcctDerRule_163'
17097          ,p_level    => C_LEVEL_PROCEDURE
17098          ,p_module   => l_log_module);
17099 
17100 END IF;
17101 
17102 l_component_type         := 'AMB_ADR';
17103 l_component_code         := 'FA_PROC_OF_SALE_LOSS_SEGMENT';
17104 l_component_type_code    := 'S';
17105 l_component_appl_id      :=  140;
17106 l_amb_context_code       := 'DEFAULT';
17107 x_transaction_coa_id     :=  null;
17108 x_accounting_coa_id      :=  null;
17109 x_flexfield_segment_code := 'GL_ACCOUNT';
17110 x_flex_value_set_id      :=  null ;
17111 
17112 
17113  IF TO_NUMBER(p_source_3) IS NULL 
17114  THEN 
17115 --
17116   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17117 
17118       trace
17119          (p_msg      => 'END of AcctDerRule_163'
17120          ,p_level    => C_LEVEL_PROCEDURE
17121          ,p_module   => l_log_module);
17122 
17123   END IF;
17124   x_value_combination_id  :=  null ;
17125   x_value_segment_code    :=  null ;
17126   x_value_type_code       := 'S';
17127   l_output_value          := TO_CHAR(p_source_25);
17128   RETURN l_output_value;
17129 
17130  ELSE 
17131     IF p_override_seg_flag = 'Y' THEN 
17132        RETURN '#$NO_OVERRIDE#$';
17133     END IF;
17134  END IF;
17135 
17136 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17137 
17138       trace
17139          (p_msg      => 'END of AcctDerRule_163(invalid)'
17140          ,p_level    => C_LEVEL_PROCEDURE
17141          ,p_module   => l_log_module);
17142 
17143 END IF;
17144 
17145 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
17146 x_value_combination_id  := null;
17147 x_value_segment_code    := null;
17148 x_value_type_code       := null;
17149 l_output_value          := null;
17150 xla_accounting_err_pkg.build_message
17151                  (p_appli_s_name            => 'XLA'
17152                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
17153                  ,p_token_1                 => 'COMPONENT_NAME'
17154                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
17155                                                             l_component_type
17156                                                           , l_component_code
17157                                                           , l_component_type_code
17158                                                           , l_component_appl_id
17159                                                           , l_amb_context_code
17160                                                           )
17161                  ,p_token_2                 => 'OWNER'
17162                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
17163                                                         'XLA_OWNER_TYPE'
17164                                                         ,l_component_type_code
17165                                                         )
17166                  ,p_token_3                 => 'PAD_NAME'
17167                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
17168                  ,p_token_4                 => 'PAD_OWNER'
17169                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
17170                                                         'XLA_OWNER_TYPE'
17171                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
17172                                                         )
17173                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
17174                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
17175                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
17176                  ,p_ae_header_id            => NULL
17177 );
17178 RETURN l_output_value;
17179 EXCEPTION
17180   WHEN xla_exceptions_pkg.application_exception THEN
17181       RAISE;
17182   WHEN OTHERS THEN
17183        xla_exceptions_pkg.raise_message
17184            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_163');
17185 END AcctDerRule_163;
17186 --
17187 
17188 ---------------------------------------
17189 --
17190 -- PRIVATE FUNCTION
17191 --         AcctDerRule_164
17192 --
17193 ---------------------------------------
17194 FUNCTION AcctDerRule_164 (
17195   p_application_id             IN NUMBER
17196 , p_ae_header_id               IN NUMBER
17197 , p_side                       IN VARCHAR2
17198 , p_override_seg_flag          IN VARCHAR2 
17199 --Generated Code Combination Identifier
17200  , p_source_3            IN NUMBER
17201 --Revaluation Amortization Account
17202  , p_source_26            IN VARCHAR2
17203 , x_transaction_coa_id         OUT NOCOPY NUMBER
17204 , x_accounting_coa_id          OUT NOCOPY NUMBER
17205 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
17206 , x_flex_value_set_id          OUT NOCOPY NUMBER
17207 , x_value_type_code            OUT NOCOPY VARCHAR2
17208 , x_value_combination_id       OUT NOCOPY NUMBER
17209 , x_value_segment_code         OUT NOCOPY VARCHAR2
17210 )
17211 RETURN VARCHAR2
17212 IS
17213 l_component_type       VARCHAR2(80)  ;
17214 l_component_code       VARCHAR2(30)  ;
17215 l_component_type_code  VARCHAR2(1)   ;
17216 l_component_appl_id    INTEGER       ;
17217 l_amb_context_code     VARCHAR2(30)  ;
17218 l_log_module           VARCHAR2(240) ;
17219 l_output_value         VARCHAR2(30)  ;
17220 BEGIN
17221 IF g_log_enabled THEN
17222       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_164';
17223 END IF;
17224 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17225 
17226       trace
17230 
17227          (p_msg      => 'BEGIN of AcctDerRule_164'
17228          ,p_level    => C_LEVEL_PROCEDURE
17229          ,p_module   => l_log_module);
17231 END IF;
17232 
17233 l_component_type         := 'AMB_ADR';
17234 l_component_code         := 'FA_REVAL_AMORT_SEGMENT';
17235 l_component_type_code    := 'S';
17236 l_component_appl_id      :=  140;
17237 l_amb_context_code       := 'DEFAULT';
17238 x_transaction_coa_id     :=  null;
17239 x_accounting_coa_id      :=  null;
17240 x_flexfield_segment_code := 'GL_ACCOUNT';
17241 x_flex_value_set_id      :=  null ;
17242 
17243 
17244  IF TO_NUMBER(p_source_3) IS NULL 
17245  THEN 
17246 --
17247   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17248 
17249       trace
17250          (p_msg      => 'END of AcctDerRule_164'
17251          ,p_level    => C_LEVEL_PROCEDURE
17252          ,p_module   => l_log_module);
17253 
17254   END IF;
17255   x_value_combination_id  :=  null ;
17256   x_value_segment_code    :=  null ;
17257   x_value_type_code       := 'S';
17258   l_output_value          := TO_CHAR(p_source_26);
17259   RETURN l_output_value;
17260 
17261  ELSE 
17262     IF p_override_seg_flag = 'Y' THEN 
17263        RETURN '#$NO_OVERRIDE#$';
17264     END IF;
17265  END IF;
17266 
17267 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17268 
17269       trace
17270          (p_msg      => 'END of AcctDerRule_164(invalid)'
17271          ,p_level    => C_LEVEL_PROCEDURE
17272          ,p_module   => l_log_module);
17273 
17274 END IF;
17275 
17276 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
17277 x_value_combination_id  := null;
17278 x_value_segment_code    := null;
17279 x_value_type_code       := null;
17280 l_output_value          := null;
17281 xla_accounting_err_pkg.build_message
17282                  (p_appli_s_name            => 'XLA'
17283                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
17284                  ,p_token_1                 => 'COMPONENT_NAME'
17285                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
17286                                                             l_component_type
17287                                                           , l_component_code
17288                                                           , l_component_type_code
17289                                                           , l_component_appl_id
17290                                                           , l_amb_context_code
17291                                                           )
17292                  ,p_token_2                 => 'OWNER'
17293                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
17294                                                         'XLA_OWNER_TYPE'
17295                                                         ,l_component_type_code
17296                                                         )
17297                  ,p_token_3                 => 'PAD_NAME'
17298                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
17299                  ,p_token_4                 => 'PAD_OWNER'
17300                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
17301                                                         'XLA_OWNER_TYPE'
17302                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
17303                                                         )
17304                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
17305                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
17306                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
17307                  ,p_ae_header_id            => NULL
17308 );
17309 RETURN l_output_value;
17310 EXCEPTION
17311   WHEN xla_exceptions_pkg.application_exception THEN
17312       RAISE;
17313   WHEN OTHERS THEN
17314        xla_exceptions_pkg.raise_message
17315            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_164');
17316 END AcctDerRule_164;
17317 --
17318 
17319 ---------------------------------------
17320 --
17321 -- PRIVATE FUNCTION
17322 --         AcctDerRule_165
17323 --
17324 ---------------------------------------
17325 FUNCTION AcctDerRule_165 (
17326   p_application_id             IN NUMBER
17327 , p_ae_header_id               IN NUMBER
17328 , p_side                       IN VARCHAR2
17329 , p_override_seg_flag          IN VARCHAR2 
17330 --Generated Code Combination Identifier
17331  , p_source_3            IN NUMBER
17332 --Revaluation Reserve Retired Gain Account
17333  , p_source_27            IN VARCHAR2
17334 , x_transaction_coa_id         OUT NOCOPY NUMBER
17335 , x_accounting_coa_id          OUT NOCOPY NUMBER
17336 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
17337 , x_flex_value_set_id          OUT NOCOPY NUMBER
17338 , x_value_type_code            OUT NOCOPY VARCHAR2
17339 , x_value_combination_id       OUT NOCOPY NUMBER
17340 , x_value_segment_code         OUT NOCOPY VARCHAR2
17341 )
17342 RETURN VARCHAR2
17343 IS
17344 l_component_type       VARCHAR2(80)  ;
17345 l_component_code       VARCHAR2(30)  ;
17346 l_component_type_code  VARCHAR2(1)   ;
17347 l_component_appl_id    INTEGER       ;
17348 l_amb_context_code     VARCHAR2(30)  ;
17349 l_log_module           VARCHAR2(240) ;
17350 l_output_value         VARCHAR2(30)  ;
17351 BEGIN
17352 IF g_log_enabled THEN
17353       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_165';
17354 END IF;
17355 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17356 
17357       trace
17358          (p_msg      => 'BEGIN of AcctDerRule_165'
17359          ,p_level    => C_LEVEL_PROCEDURE
17360          ,p_module   => l_log_module);
17361 
17362 END IF;
17366 l_component_type_code    := 'S';
17363 
17364 l_component_type         := 'AMB_ADR';
17365 l_component_code         := 'FA_REVAL_RES_RET_GAIN_SEGMENT';
17367 l_component_appl_id      :=  140;
17368 l_amb_context_code       := 'DEFAULT';
17369 x_transaction_coa_id     :=  null;
17370 x_accounting_coa_id      :=  null;
17371 x_flexfield_segment_code := 'GL_ACCOUNT';
17372 x_flex_value_set_id      :=  null ;
17373 
17374 
17375  IF TO_NUMBER(p_source_3) IS NULL 
17376  THEN 
17377 --
17378   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17379 
17380       trace
17381          (p_msg      => 'END of AcctDerRule_165'
17382          ,p_level    => C_LEVEL_PROCEDURE
17383          ,p_module   => l_log_module);
17384 
17385   END IF;
17386   x_value_combination_id  :=  null ;
17387   x_value_segment_code    :=  null ;
17388   x_value_type_code       := 'S';
17389   l_output_value          := TO_CHAR(p_source_27);
17390   RETURN l_output_value;
17391 
17392  ELSE 
17393     IF p_override_seg_flag = 'Y' THEN 
17394        RETURN '#$NO_OVERRIDE#$';
17395     END IF;
17396  END IF;
17397 
17398 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17399 
17400       trace
17401          (p_msg      => 'END of AcctDerRule_165(invalid)'
17402          ,p_level    => C_LEVEL_PROCEDURE
17403          ,p_module   => l_log_module);
17404 
17405 END IF;
17406 
17407 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
17408 x_value_combination_id  := null;
17409 x_value_segment_code    := null;
17410 x_value_type_code       := null;
17411 l_output_value          := null;
17412 xla_accounting_err_pkg.build_message
17413                  (p_appli_s_name            => 'XLA'
17414                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
17415                  ,p_token_1                 => 'COMPONENT_NAME'
17416                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
17417                                                             l_component_type
17418                                                           , l_component_code
17419                                                           , l_component_type_code
17420                                                           , l_component_appl_id
17421                                                           , l_amb_context_code
17422                                                           )
17423                  ,p_token_2                 => 'OWNER'
17424                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
17425                                                         'XLA_OWNER_TYPE'
17426                                                         ,l_component_type_code
17427                                                         )
17428                  ,p_token_3                 => 'PAD_NAME'
17429                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
17430                  ,p_token_4                 => 'PAD_OWNER'
17431                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
17432                                                         'XLA_OWNER_TYPE'
17433                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
17434                                                         )
17435                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
17436                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
17437                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
17438                  ,p_ae_header_id            => NULL
17439 );
17440 RETURN l_output_value;
17441 EXCEPTION
17442   WHEN xla_exceptions_pkg.application_exception THEN
17443       RAISE;
17444   WHEN OTHERS THEN
17445        xla_exceptions_pkg.raise_message
17446            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_165');
17447 END AcctDerRule_165;
17448 --
17449 
17450 ---------------------------------------
17451 --
17452 -- PRIVATE FUNCTION
17453 --         AcctDerRule_166
17454 --
17455 ---------------------------------------
17456 FUNCTION AcctDerRule_166 (
17457   p_application_id             IN NUMBER
17458 , p_ae_header_id               IN NUMBER
17459 , p_side                       IN VARCHAR2
17460 , p_override_seg_flag          IN VARCHAR2 
17461 --Generated Code Combination Identifier
17462  , p_source_3            IN NUMBER
17463 --Revaluation Reserve Retired Loss Account
17464  , p_source_28            IN VARCHAR2
17465 , x_transaction_coa_id         OUT NOCOPY NUMBER
17466 , x_accounting_coa_id          OUT NOCOPY NUMBER
17467 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
17468 , x_flex_value_set_id          OUT NOCOPY NUMBER
17469 , x_value_type_code            OUT NOCOPY VARCHAR2
17470 , x_value_combination_id       OUT NOCOPY NUMBER
17471 , x_value_segment_code         OUT NOCOPY VARCHAR2
17472 )
17473 RETURN VARCHAR2
17474 IS
17475 l_component_type       VARCHAR2(80)  ;
17476 l_component_code       VARCHAR2(30)  ;
17477 l_component_type_code  VARCHAR2(1)   ;
17478 l_component_appl_id    INTEGER       ;
17479 l_amb_context_code     VARCHAR2(30)  ;
17480 l_log_module           VARCHAR2(240) ;
17481 l_output_value         VARCHAR2(30)  ;
17482 BEGIN
17483 IF g_log_enabled THEN
17484       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_166';
17485 END IF;
17486 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17487 
17488       trace
17489          (p_msg      => 'BEGIN of AcctDerRule_166'
17490          ,p_level    => C_LEVEL_PROCEDURE
17491          ,p_module   => l_log_module);
17492 
17493 END IF;
17494 
17495 l_component_type         := 'AMB_ADR';
17496 l_component_code         := 'FA_REVAL_RES_RET_LOSS_SEGMENT';
17497 l_component_type_code    := 'S';
17501 x_accounting_coa_id      :=  null;
17498 l_component_appl_id      :=  140;
17499 l_amb_context_code       := 'DEFAULT';
17500 x_transaction_coa_id     :=  null;
17502 x_flexfield_segment_code := 'GL_ACCOUNT';
17503 x_flex_value_set_id      :=  null ;
17504 
17505 
17506  IF TO_NUMBER(p_source_3) IS NULL 
17507  THEN 
17508 --
17509   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17510 
17511       trace
17512          (p_msg      => 'END of AcctDerRule_166'
17513          ,p_level    => C_LEVEL_PROCEDURE
17514          ,p_module   => l_log_module);
17515 
17516   END IF;
17517   x_value_combination_id  :=  null ;
17518   x_value_segment_code    :=  null ;
17519   x_value_type_code       := 'S';
17520   l_output_value          := TO_CHAR(p_source_28);
17521   RETURN l_output_value;
17522 
17523  ELSE 
17524     IF p_override_seg_flag = 'Y' THEN 
17525        RETURN '#$NO_OVERRIDE#$';
17526     END IF;
17527  END IF;
17528 
17529 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17530 
17531       trace
17532          (p_msg      => 'END of AcctDerRule_166(invalid)'
17533          ,p_level    => C_LEVEL_PROCEDURE
17534          ,p_module   => l_log_module);
17535 
17536 END IF;
17537 
17538 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
17539 x_value_combination_id  := null;
17540 x_value_segment_code    := null;
17541 x_value_type_code       := null;
17542 l_output_value          := null;
17543 xla_accounting_err_pkg.build_message
17544                  (p_appli_s_name            => 'XLA'
17545                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
17546                  ,p_token_1                 => 'COMPONENT_NAME'
17547                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
17548                                                             l_component_type
17549                                                           , l_component_code
17550                                                           , l_component_type_code
17551                                                           , l_component_appl_id
17552                                                           , l_amb_context_code
17553                                                           )
17554                  ,p_token_2                 => 'OWNER'
17555                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
17556                                                         'XLA_OWNER_TYPE'
17557                                                         ,l_component_type_code
17558                                                         )
17559                  ,p_token_3                 => 'PAD_NAME'
17560                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
17561                  ,p_token_4                 => 'PAD_OWNER'
17562                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
17563                                                         'XLA_OWNER_TYPE'
17564                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
17565                                                         )
17566                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
17567                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
17568                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
17569                  ,p_ae_header_id            => NULL
17570 );
17571 RETURN l_output_value;
17572 EXCEPTION
17573   WHEN xla_exceptions_pkg.application_exception THEN
17574       RAISE;
17575   WHEN OTHERS THEN
17576        xla_exceptions_pkg.raise_message
17577            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_166');
17578 END AcctDerRule_166;
17579 --
17580 
17581 ---------------------------------------
17582 --
17583 -- PRIVATE FUNCTION
17584 --         AcctDerRule_167
17585 --
17586 ---------------------------------------
17587 FUNCTION AcctDerRule_167 (
17588   p_application_id             IN NUMBER
17589 , p_ae_header_id               IN NUMBER
17590 , p_side                       IN VARCHAR2
17591 , p_override_seg_flag          IN VARCHAR2 
17592 --Depreciation Reserve Account
17593  , p_source_10            IN VARCHAR2
17594 --Generated Offset Code Combination Identifier
17595  , p_source_17            IN NUMBER
17596 , x_transaction_coa_id         OUT NOCOPY NUMBER
17597 , x_accounting_coa_id          OUT NOCOPY NUMBER
17598 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
17599 , x_flex_value_set_id          OUT NOCOPY NUMBER
17600 , x_value_type_code            OUT NOCOPY VARCHAR2
17601 , x_value_combination_id       OUT NOCOPY NUMBER
17602 , x_value_segment_code         OUT NOCOPY VARCHAR2
17603 )
17604 RETURN VARCHAR2
17605 IS
17606 l_component_type       VARCHAR2(80)  ;
17607 l_component_code       VARCHAR2(30)  ;
17608 l_component_type_code  VARCHAR2(1)   ;
17609 l_component_appl_id    INTEGER       ;
17610 l_amb_context_code     VARCHAR2(30)  ;
17611 l_log_module           VARCHAR2(240) ;
17612 l_output_value         VARCHAR2(30)  ;
17613 BEGIN
17614 IF g_log_enabled THEN
17615       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_167';
17616 END IF;
17617 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17618 
17619       trace
17620          (p_msg      => 'BEGIN of AcctDerRule_167'
17621          ,p_level    => C_LEVEL_PROCEDURE
17622          ,p_module   => l_log_module);
17623 
17624 END IF;
17625 
17626 l_component_type         := 'AMB_ADR';
17627 l_component_code         := 'FA_UPL_CAT_RES_ACCOUNT_SEGMENT';
17628 l_component_type_code    := 'S';
17629 l_component_appl_id      :=  140;
17630 l_amb_context_code       := 'DEFAULT';
17631 x_transaction_coa_id     :=  null;
17632 x_accounting_coa_id      :=  null;
17636 
17633 x_flexfield_segment_code := 'GL_ACCOUNT';
17634 x_flex_value_set_id      :=  null ;
17635 
17637  IF TO_NUMBER(p_source_17) IS NULL 
17638  THEN 
17639 --
17640   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17641 
17642       trace
17643          (p_msg      => 'END of AcctDerRule_167'
17644          ,p_level    => C_LEVEL_PROCEDURE
17645          ,p_module   => l_log_module);
17646 
17647   END IF;
17648   x_value_combination_id  :=  null ;
17649   x_value_segment_code    :=  null ;
17650   x_value_type_code       := 'S';
17651   l_output_value          := TO_CHAR(p_source_10);
17652   RETURN l_output_value;
17653 
17654  ELSE 
17655     IF p_override_seg_flag = 'Y' THEN 
17656        RETURN '#$NO_OVERRIDE#$';
17657     END IF;
17658  END IF;
17659 
17660 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17661 
17662       trace
17663          (p_msg      => 'END of AcctDerRule_167(invalid)'
17664          ,p_level    => C_LEVEL_PROCEDURE
17665          ,p_module   => l_log_module);
17666 
17667 END IF;
17668 
17669 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
17670 x_value_combination_id  := null;
17671 x_value_segment_code    := null;
17672 x_value_type_code       := null;
17673 l_output_value          := null;
17674 xla_accounting_err_pkg.build_message
17675                  (p_appli_s_name            => 'XLA'
17676                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
17677                  ,p_token_1                 => 'COMPONENT_NAME'
17678                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
17679                                                             l_component_type
17680                                                           , l_component_code
17681                                                           , l_component_type_code
17682                                                           , l_component_appl_id
17683                                                           , l_amb_context_code
17684                                                           )
17685                  ,p_token_2                 => 'OWNER'
17686                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
17687                                                         'XLA_OWNER_TYPE'
17688                                                         ,l_component_type_code
17689                                                         )
17690                  ,p_token_3                 => 'PAD_NAME'
17691                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
17692                  ,p_token_4                 => 'PAD_OWNER'
17693                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
17694                                                         'XLA_OWNER_TYPE'
17695                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
17696                                                         )
17697                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
17698                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
17699                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
17700                  ,p_ae_header_id            => NULL
17701 );
17702 RETURN l_output_value;
17703 EXCEPTION
17704   WHEN xla_exceptions_pkg.application_exception THEN
17705       RAISE;
17706   WHEN OTHERS THEN
17707        xla_exceptions_pkg.raise_message
17708            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_167');
17709 END AcctDerRule_167;
17710 --
17711 
17712 ---------------------------------------
17713 --
17714 -- PRIVATE FUNCTION
17715 --         AcctDerRule_168
17716 --
17717 ---------------------------------------
17718 FUNCTION AcctDerRule_168 (
17719   p_application_id             IN NUMBER
17720 , p_ae_header_id               IN NUMBER
17721 , p_side                       IN VARCHAR2
17722 , p_override_seg_flag          IN VARCHAR2 
17723 --Generated Code Combination Identifier
17724  , p_source_3            IN NUMBER
17725 --Expense Account Code Combination Identifier
17726  , p_source_29            IN NUMBER
17727 , x_transaction_coa_id         OUT NOCOPY NUMBER
17728 , x_accounting_coa_id          OUT NOCOPY NUMBER
17729 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
17730 , x_flex_value_set_id          OUT NOCOPY NUMBER
17731 , x_value_type_code            OUT NOCOPY VARCHAR2
17732 , x_value_combination_id       OUT NOCOPY NUMBER
17733 , x_value_segment_code         OUT NOCOPY VARCHAR2
17734 )
17735 RETURN VARCHAR2
17736 IS
17737 l_component_type       VARCHAR2(80)  ;
17738 l_component_code       VARCHAR2(30)  ;
17739 l_component_type_code  VARCHAR2(1)   ;
17740 l_component_appl_id    INTEGER       ;
17741 l_amb_context_code     VARCHAR2(30)  ;
17742 l_log_module           VARCHAR2(240) ;
17743 l_output_value         VARCHAR2(30)  ;
17744 BEGIN
17745 IF g_log_enabled THEN
17746       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_168';
17747 END IF;
17748 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17749 
17750       trace
17751          (p_msg      => 'BEGIN of AcctDerRule_168'
17752          ,p_level    => C_LEVEL_PROCEDURE
17753          ,p_module   => l_log_module);
17754 
17755 END IF;
17756 
17757 l_component_type         := 'AMB_ADR';
17758 l_component_code         := 'FA_EXPENSE_ACCT';
17759 l_component_type_code    := 'S';
17760 l_component_appl_id      :=  140;
17761 l_amb_context_code       := 'DEFAULT';
17762 x_transaction_coa_id     :=  null;
17763 x_accounting_coa_id      :=  null;
17764 x_flexfield_segment_code := 'GL_BALANCING';
17765 x_flex_value_set_id      :=  null ;
17766 
17767 
17768  IF TO_NUMBER(p_source_3) IS NULL 
17769  THEN 
17773       trace
17770 --
17771   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17772 
17774          (p_msg      => 'END of AcctDerRule_168'
17775          ,p_level    => C_LEVEL_PROCEDURE
17776          ,p_module   => l_log_module);
17777 
17778   END IF;
17779   x_value_combination_id  := TO_NUMBER(p_source_29) ;
17780   x_value_segment_code    := 'GL_BALANCING' ;
17781   x_value_type_code       := 'S';
17782   l_output_value          :=  null;
17783   RETURN l_output_value;
17784 
17785  ELSE 
17786     IF p_override_seg_flag = 'Y' THEN 
17787        RETURN '#$NO_OVERRIDE#$';
17788     END IF;
17789  END IF;
17790 
17791 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17792 
17793       trace
17794          (p_msg      => 'END of AcctDerRule_168(invalid)'
17795          ,p_level    => C_LEVEL_PROCEDURE
17796          ,p_module   => l_log_module);
17797 
17798 END IF;
17799 
17800 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
17801 x_value_combination_id  := null;
17802 x_value_segment_code    := null;
17803 x_value_type_code       := null;
17804 l_output_value          := null;
17805 xla_accounting_err_pkg.build_message
17806                  (p_appli_s_name            => 'XLA'
17807                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
17808                  ,p_token_1                 => 'COMPONENT_NAME'
17809                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
17810                                                             l_component_type
17811                                                           , l_component_code
17812                                                           , l_component_type_code
17813                                                           , l_component_appl_id
17814                                                           , l_amb_context_code
17815                                                           )
17816                  ,p_token_2                 => 'OWNER'
17817                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
17818                                                         'XLA_OWNER_TYPE'
17819                                                         ,l_component_type_code
17820                                                         )
17821                  ,p_token_3                 => 'PAD_NAME'
17822                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
17823                  ,p_token_4                 => 'PAD_OWNER'
17824                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
17825                                                         'XLA_OWNER_TYPE'
17826                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
17827                                                         )
17828                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
17829                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
17830                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
17831                  ,p_ae_header_id            => NULL
17832 );
17833 RETURN l_output_value;
17834 EXCEPTION
17835   WHEN xla_exceptions_pkg.application_exception THEN
17836       RAISE;
17837   WHEN OTHERS THEN
17838        xla_exceptions_pkg.raise_message
17839            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_168');
17840 END AcctDerRule_168;
17841 --
17842 
17843 ---------------------------------------
17844 --
17845 -- PRIVATE FUNCTION
17846 --         AcctDerRule_169
17847 --
17848 ---------------------------------------
17849 FUNCTION AcctDerRule_169 (
17850   p_application_id             IN NUMBER
17851 , p_ae_header_id               IN NUMBER
17852 , p_side                       IN VARCHAR2
17853 , p_override_seg_flag          IN VARCHAR2 
17854 --Generated Code Combination Identifier
17855  , p_source_3            IN NUMBER
17856 --Payables Code Combination Identifier
17857  , p_source_6            IN NUMBER
17858 --Expense Account Code Combination Identifier
17859  , p_source_29            IN NUMBER
17860 , x_transaction_coa_id         OUT NOCOPY NUMBER
17861 , x_accounting_coa_id          OUT NOCOPY NUMBER
17862 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
17863 , x_flex_value_set_id          OUT NOCOPY NUMBER
17864 , x_value_type_code            OUT NOCOPY VARCHAR2
17865 , x_value_combination_id       OUT NOCOPY NUMBER
17866 , x_value_segment_code         OUT NOCOPY VARCHAR2
17867 )
17868 RETURN VARCHAR2
17869 IS
17870 l_component_type       VARCHAR2(80)  ;
17871 l_component_code       VARCHAR2(30)  ;
17872 l_component_type_code  VARCHAR2(1)   ;
17873 l_component_appl_id    INTEGER       ;
17874 l_amb_context_code     VARCHAR2(30)  ;
17875 l_log_module           VARCHAR2(240) ;
17876 l_output_value         VARCHAR2(30)  ;
17877 BEGIN
17878 IF g_log_enabled THEN
17879       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_169';
17880 END IF;
17881 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17882 
17883       trace
17884          (p_msg      => 'BEGIN of AcctDerRule_169'
17885          ,p_level    => C_LEVEL_PROCEDURE
17886          ,p_module   => l_log_module);
17887 
17888 END IF;
17889 
17890 l_component_type         := 'AMB_ADR';
17891 l_component_code         := 'FA_EXPENSE_ACCT_PAY';
17892 l_component_type_code    := 'S';
17893 l_component_appl_id      :=  140;
17894 l_amb_context_code       := 'DEFAULT';
17895 x_transaction_coa_id     :=  null;
17896 x_accounting_coa_id      :=  null;
17897 x_flexfield_segment_code := 'GL_BALANCING';
17898 x_flex_value_set_id      :=  null ;
17899 
17900 
17901  IF TO_NUMBER(p_source_3) IS NULL AND 
17902 TO_NUMBER(p_source_6) IS NULL 
17903  THEN 
17904 --
17908          (p_msg      => 'END of AcctDerRule_169'
17905   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17906 
17907       trace
17909          ,p_level    => C_LEVEL_PROCEDURE
17910          ,p_module   => l_log_module);
17911 
17912   END IF;
17913   x_value_combination_id  := TO_NUMBER(p_source_29) ;
17914   x_value_segment_code    := 'GL_BALANCING' ;
17915   x_value_type_code       := 'S';
17916   l_output_value          :=  null;
17917   RETURN l_output_value;
17918 
17919  ELSE 
17920     IF p_override_seg_flag = 'Y' THEN 
17921        RETURN '#$NO_OVERRIDE#$';
17922     END IF;
17923  END IF;
17924 
17925 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17926 
17927       trace
17928          (p_msg      => 'END of AcctDerRule_169(invalid)'
17929          ,p_level    => C_LEVEL_PROCEDURE
17930          ,p_module   => l_log_module);
17931 
17932 END IF;
17933 
17934 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
17935 x_value_combination_id  := null;
17936 x_value_segment_code    := null;
17937 x_value_type_code       := null;
17938 l_output_value          := null;
17939 xla_accounting_err_pkg.build_message
17940                  (p_appli_s_name            => 'XLA'
17941                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
17942                  ,p_token_1                 => 'COMPONENT_NAME'
17943                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
17944                                                             l_component_type
17945                                                           , l_component_code
17946                                                           , l_component_type_code
17947                                                           , l_component_appl_id
17948                                                           , l_amb_context_code
17949                                                           )
17950                  ,p_token_2                 => 'OWNER'
17951                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
17952                                                         'XLA_OWNER_TYPE'
17953                                                         ,l_component_type_code
17954                                                         )
17955                  ,p_token_3                 => 'PAD_NAME'
17956                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
17957                  ,p_token_4                 => 'PAD_OWNER'
17958                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
17959                                                         'XLA_OWNER_TYPE'
17960                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
17961                                                         )
17962                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
17963                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
17964                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
17965                  ,p_ae_header_id            => NULL
17966 );
17967 RETURN l_output_value;
17968 EXCEPTION
17969   WHEN xla_exceptions_pkg.application_exception THEN
17970       RAISE;
17971   WHEN OTHERS THEN
17972        xla_exceptions_pkg.raise_message
17973            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_169');
17974 END AcctDerRule_169;
17975 --
17976 
17977 ---------------------------------------
17978 --
17979 -- PRIVATE FUNCTION
17980 --         AcctDerRule_170
17981 --
17982 ---------------------------------------
17983 FUNCTION AcctDerRule_170 (
17984   p_application_id             IN NUMBER
17985 , p_ae_header_id               IN NUMBER
17986 , p_side                       IN VARCHAR2
17987 , p_override_seg_flag          IN VARCHAR2 
17988 --Generated Offset Code Combination Identifier
17989  , p_source_17            IN NUMBER
17990 --Expense Account Code Combination Identifier
17991  , p_source_29            IN NUMBER
17992 , x_transaction_coa_id         OUT NOCOPY NUMBER
17993 , x_accounting_coa_id          OUT NOCOPY NUMBER
17994 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
17995 , x_flex_value_set_id          OUT NOCOPY NUMBER
17996 , x_value_type_code            OUT NOCOPY VARCHAR2
17997 , x_value_combination_id       OUT NOCOPY NUMBER
17998 , x_value_segment_code         OUT NOCOPY VARCHAR2
17999 )
18000 RETURN VARCHAR2
18001 IS
18002 l_component_type       VARCHAR2(80)  ;
18003 l_component_code       VARCHAR2(30)  ;
18004 l_component_type_code  VARCHAR2(1)   ;
18005 l_component_appl_id    INTEGER       ;
18006 l_amb_context_code     VARCHAR2(30)  ;
18007 l_log_module           VARCHAR2(240) ;
18008 l_output_value         VARCHAR2(30)  ;
18009 BEGIN
18010 IF g_log_enabled THEN
18011       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_170';
18012 END IF;
18013 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18014 
18015       trace
18016          (p_msg      => 'BEGIN of AcctDerRule_170'
18017          ,p_level    => C_LEVEL_PROCEDURE
18018          ,p_module   => l_log_module);
18019 
18020 END IF;
18021 
18022 l_component_type         := 'AMB_ADR';
18023 l_component_code         := 'FA_UPL_EXP_ACCOUNT';
18024 l_component_type_code    := 'S';
18025 l_component_appl_id      :=  140;
18026 l_amb_context_code       := 'DEFAULT';
18027 x_transaction_coa_id     :=  null;
18028 x_accounting_coa_id      :=  null;
18029 x_flexfield_segment_code := 'GL_BALANCING';
18030 x_flex_value_set_id      :=  null ;
18031 
18032 
18033  IF TO_NUMBER(p_source_17) IS NULL 
18034  THEN 
18035 --
18036   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18037 
18038       trace
18039          (p_msg      => 'END of AcctDerRule_170'
18043   END IF;
18040          ,p_level    => C_LEVEL_PROCEDURE
18041          ,p_module   => l_log_module);
18042 
18044   x_value_combination_id  := TO_NUMBER(p_source_29) ;
18045   x_value_segment_code    := 'GL_BALANCING' ;
18046   x_value_type_code       := 'S';
18047   l_output_value          :=  null;
18048   RETURN l_output_value;
18049 
18050  ELSE 
18051     IF p_override_seg_flag = 'Y' THEN 
18052        RETURN '#$NO_OVERRIDE#$';
18053     END IF;
18054  END IF;
18055 
18056 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18057 
18058       trace
18059          (p_msg      => 'END of AcctDerRule_170(invalid)'
18060          ,p_level    => C_LEVEL_PROCEDURE
18061          ,p_module   => l_log_module);
18062 
18063 END IF;
18064 
18065 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
18066 x_value_combination_id  := null;
18067 x_value_segment_code    := null;
18068 x_value_type_code       := null;
18069 l_output_value          := null;
18070 xla_accounting_err_pkg.build_message
18071                  (p_appli_s_name            => 'XLA'
18072                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
18073                  ,p_token_1                 => 'COMPONENT_NAME'
18074                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
18075                                                             l_component_type
18076                                                           , l_component_code
18077                                                           , l_component_type_code
18078                                                           , l_component_appl_id
18079                                                           , l_amb_context_code
18080                                                           )
18081                  ,p_token_2                 => 'OWNER'
18082                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
18083                                                         'XLA_OWNER_TYPE'
18084                                                         ,l_component_type_code
18085                                                         )
18086                  ,p_token_3                 => 'PAD_NAME'
18087                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
18088                  ,p_token_4                 => 'PAD_OWNER'
18089                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
18090                                                         'XLA_OWNER_TYPE'
18091                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
18092                                                         )
18093                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
18094                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
18095                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
18096                  ,p_ae_header_id            => NULL
18097 );
18098 RETURN l_output_value;
18099 EXCEPTION
18100   WHEN xla_exceptions_pkg.application_exception THEN
18101       RAISE;
18102   WHEN OTHERS THEN
18103        xla_exceptions_pkg.raise_message
18104            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_170');
18105 END AcctDerRule_170;
18106 --
18107 
18108 ---------------------------------------
18109 --
18110 -- PRIVATE FUNCTION
18111 --         AcctDerRule_171
18112 --
18113 ---------------------------------------
18114 FUNCTION AcctDerRule_171 (
18115   p_application_id              IN NUMBER
18116 , p_ae_header_id                IN NUMBER
18117 , p_side                        IN VARCHAR2 
18118 --Generated Code Combination Identifier
18119  , p_source_3            IN NUMBER
18120 --Payables Code Combination Identifier
18121  , p_source_6            IN NUMBER
18122 --Default Code Combination Identifier
18123  , p_source_30            IN NUMBER
18124 , x_transaction_coa_id         OUT NOCOPY NUMBER
18125 , x_accounting_coa_id          OUT NOCOPY NUMBER
18126 , x_value_type_code            OUT NOCOPY VARCHAR2
18127 )
18128 RETURN NUMBER
18129 IS
18130 l_component_type       VARCHAR2(80)  ;
18131 l_component_code       VARCHAR2(30)  ;
18132 l_component_type_code  VARCHAR2(1)   ;
18133 l_component_appl_id    INTEGER       ;
18134 l_amb_context_code     VARCHAR2(30)  ;
18135 l_log_module           VARCHAR2(240) ;
18136 l_output_value         NUMBER        ;
18137 BEGIN
18138 IF g_log_enabled THEN
18139       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_171';
18140 END IF;
18141 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18142       trace
18143          (p_msg      => 'BEGIN of AcctDerRule_171'
18144          ,p_level    => C_LEVEL_PROCEDURE
18145          ,p_module   => l_log_module);
18146 END IF;
18147 --
18148 l_component_type         := 'AMB_ADR';
18149 l_component_code         := 'FA_CAT_CIP_COST_CLEARING';
18150 l_component_type_code    := 'S';
18151 l_component_appl_id      :=  140;
18152 l_amb_context_code       := 'DEFAULT';
18153 x_transaction_coa_id     :=  null;
18154 x_accounting_coa_id      :=  null;
18155 --
18156 
18157  IF TO_NUMBER(p_source_6) IS NOT NULL 
18158  THEN 
18159  --
18160   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18161       trace
18162          (p_msg      => 'END of AcctDerRule_171'
18163          ,p_level    => C_LEVEL_PROCEDURE
18164          ,p_module   => l_log_module);
18165   END IF;
18166   x_value_type_code := 'S';
18167   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_6));
18168   RETURN l_output_value;
18169 
18170  ELSIF TO_NUMBER(p_source_3) IS NOT NULL AND 
18171 TO_NUMBER(p_source_6) IS NULL 
18172  THEN 
18173  --
18174   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18175       trace
18179   END IF;
18176          (p_msg      => 'END of AcctDerRule_171'
18177          ,p_level    => C_LEVEL_PROCEDURE
18178          ,p_module   => l_log_module);
18180   x_value_type_code := 'S';
18181   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_3));
18182   RETURN l_output_value;
18183 
18184  ELSIF TO_NUMBER(p_source_3) IS NULL AND 
18185 TO_NUMBER(p_source_6) IS NULL 
18186  THEN 
18187  --
18188   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18189       trace
18190          (p_msg      => 'END of AcctDerRule_171'
18191          ,p_level    => C_LEVEL_PROCEDURE
18192          ,p_module   => l_log_module);
18193   END IF;
18194   x_value_type_code := 'S';
18195   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_30));
18196   RETURN l_output_value;
18197 
18198  END IF;
18199 --
18200 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18201       trace
18202          (p_msg      => 'END of AcctDerRule_171(invalid)'
18203          ,p_level    => C_LEVEL_PROCEDURE
18204          ,p_module   => l_log_module);
18205 END IF;
18206 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
18207 x_value_type_code := null;
18208 l_output_value    := null;
18209 xla_accounting_err_pkg.build_message
18210                  (p_appli_s_name            => 'XLA'
18211                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
18212                  ,p_token_1                 => 'COMPONENT_NAME'
18213                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
18214                                                             l_component_type
18215                                                           , l_component_code
18216                                                           , l_component_type_code
18217                                                           , l_component_appl_id
18218                                                           , l_amb_context_code
18219                                                           )
18220                  ,p_token_2                 => 'OWNER'
18221                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
18222                                                         'XLA_OWNER_TYPE'
18223                                                         ,l_component_type_code
18224                                                         )
18225                  ,p_token_3                 => 'PAD_NAME'
18226                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
18227                  ,p_token_4                 => 'PAD_OWNER'
18228                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
18229                                                         'XLA_OWNER_TYPE'
18230                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
18231                                                         )
18232                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
18233                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
18234                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
18235                  ,p_ae_header_id            => NULL
18236 );
18237 RETURN l_output_value;
18238 EXCEPTION
18239   WHEN xla_exceptions_pkg.application_exception THEN
18240       RAISE;
18241   WHEN OTHERS THEN
18242        xla_exceptions_pkg.raise_message
18243            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_171');
18244 END AcctDerRule_171;
18245 --
18246 
18247 ---------------------------------------
18248 --
18249 -- PRIVATE FUNCTION
18250 --         AcctDerRule_172
18251 --
18252 ---------------------------------------
18253 FUNCTION AcctDerRule_172 (
18254   p_application_id              IN NUMBER
18255 , p_ae_header_id                IN NUMBER
18256 , p_side                        IN VARCHAR2 
18257 --Generated Code Combination Identifier
18258  , p_source_3            IN NUMBER
18259 --Payables Code Combination Identifier
18260  , p_source_6            IN NUMBER
18261 --Default Code Combination Identifier
18262  , p_source_30            IN NUMBER
18263 , x_transaction_coa_id         OUT NOCOPY NUMBER
18264 , x_accounting_coa_id          OUT NOCOPY NUMBER
18265 , x_value_type_code            OUT NOCOPY VARCHAR2
18266 )
18267 RETURN NUMBER
18268 IS
18269 l_component_type       VARCHAR2(80)  ;
18270 l_component_code       VARCHAR2(30)  ;
18271 l_component_type_code  VARCHAR2(1)   ;
18272 l_component_appl_id    INTEGER       ;
18273 l_amb_context_code     VARCHAR2(30)  ;
18274 l_log_module           VARCHAR2(240) ;
18275 l_output_value         NUMBER        ;
18276 BEGIN
18277 IF g_log_enabled THEN
18278       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_172';
18279 END IF;
18280 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18281       trace
18282          (p_msg      => 'BEGIN of AcctDerRule_172'
18283          ,p_level    => C_LEVEL_PROCEDURE
18284          ,p_module   => l_log_module);
18285 END IF;
18286 --
18287 l_component_type         := 'AMB_ADR';
18288 l_component_code         := 'FA_CAT_COST_CLEARING';
18289 l_component_type_code    := 'S';
18290 l_component_appl_id      :=  140;
18291 l_amb_context_code       := 'DEFAULT';
18292 x_transaction_coa_id     :=  null;
18293 x_accounting_coa_id      :=  null;
18294 --
18295 
18296  IF TO_NUMBER(p_source_6) IS NOT NULL 
18297  THEN 
18298  --
18299   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18300       trace
18301          (p_msg      => 'END of AcctDerRule_172'
18302          ,p_level    => C_LEVEL_PROCEDURE
18303          ,p_module   => l_log_module);
18304   END IF;
18305   x_value_type_code := 'S';
18306   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_6));
18307   RETURN l_output_value;
18308 
18312  --
18309  ELSIF TO_NUMBER(p_source_3) IS NOT NULL AND 
18310 TO_NUMBER(p_source_6) IS NULL 
18311  THEN 
18313   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18314       trace
18315          (p_msg      => 'END of AcctDerRule_172'
18316          ,p_level    => C_LEVEL_PROCEDURE
18317          ,p_module   => l_log_module);
18318   END IF;
18319   x_value_type_code := 'S';
18320   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_3));
18321   RETURN l_output_value;
18322 
18323  ELSIF TO_NUMBER(p_source_6) IS NULL AND 
18324 TO_NUMBER(p_source_3) IS NULL 
18325  THEN 
18326  --
18327   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18328       trace
18329          (p_msg      => 'END of AcctDerRule_172'
18330          ,p_level    => C_LEVEL_PROCEDURE
18331          ,p_module   => l_log_module);
18332   END IF;
18333   x_value_type_code := 'S';
18334   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_30));
18335   RETURN l_output_value;
18336 
18337  END IF;
18338 --
18339 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18340       trace
18341          (p_msg      => 'END of AcctDerRule_172(invalid)'
18342          ,p_level    => C_LEVEL_PROCEDURE
18343          ,p_module   => l_log_module);
18344 END IF;
18345 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
18346 x_value_type_code := null;
18347 l_output_value    := null;
18348 xla_accounting_err_pkg.build_message
18349                  (p_appli_s_name            => 'XLA'
18350                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
18351                  ,p_token_1                 => 'COMPONENT_NAME'
18352                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
18353                                                             l_component_type
18354                                                           , l_component_code
18355                                                           , l_component_type_code
18356                                                           , l_component_appl_id
18357                                                           , l_amb_context_code
18358                                                           )
18359                  ,p_token_2                 => 'OWNER'
18360                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
18361                                                         'XLA_OWNER_TYPE'
18362                                                         ,l_component_type_code
18363                                                         )
18364                  ,p_token_3                 => 'PAD_NAME'
18365                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
18366                  ,p_token_4                 => 'PAD_OWNER'
18367                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
18368                                                         'XLA_OWNER_TYPE'
18369                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
18370                                                         )
18371                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
18372                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
18373                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
18374                  ,p_ae_header_id            => NULL
18375 );
18376 RETURN l_output_value;
18377 EXCEPTION
18378   WHEN xla_exceptions_pkg.application_exception THEN
18379       RAISE;
18380   WHEN OTHERS THEN
18381        xla_exceptions_pkg.raise_message
18382            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_172');
18383 END AcctDerRule_172;
18384 --
18385 
18386 ---------------------------------------
18387 --
18388 -- PRIVATE FUNCTION
18389 --         AcctDerRule_173
18390 --
18391 ---------------------------------------
18392 FUNCTION AcctDerRule_173 (
18393   p_application_id              IN NUMBER
18394 , p_ae_header_id                IN NUMBER
18395 , p_side                        IN VARCHAR2 
18396 --Generated Code Combination Identifier
18397  , p_source_3            IN NUMBER
18398 --Default Code Combination Identifier
18399  , p_source_30            IN NUMBER
18400 , x_transaction_coa_id         OUT NOCOPY NUMBER
18401 , x_accounting_coa_id          OUT NOCOPY NUMBER
18402 , x_value_type_code            OUT NOCOPY VARCHAR2
18403 )
18404 RETURN NUMBER
18405 IS
18406 l_component_type       VARCHAR2(80)  ;
18407 l_component_code       VARCHAR2(30)  ;
18408 l_component_type_code  VARCHAR2(1)   ;
18409 l_component_appl_id    INTEGER       ;
18410 l_amb_context_code     VARCHAR2(30)  ;
18411 l_log_module           VARCHAR2(240) ;
18412 l_output_value         NUMBER        ;
18413 BEGIN
18414 IF g_log_enabled THEN
18415       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_173';
18416 END IF;
18417 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18418       trace
18419          (p_msg      => 'BEGIN of AcctDerRule_173'
18420          ,p_level    => C_LEVEL_PROCEDURE
18421          ,p_module   => l_log_module);
18422 END IF;
18423 --
18424 l_component_type         := 'AMB_ADR';
18425 l_component_code         := 'FA_DEFAULT_ACCOUNT';
18426 l_component_type_code    := 'S';
18427 l_component_appl_id      :=  140;
18428 l_amb_context_code       := 'DEFAULT';
18429 x_transaction_coa_id     :=  null;
18430 x_accounting_coa_id      :=  null;
18431 --
18432 
18433  IF TO_NUMBER(p_source_3) IS NOT NULL 
18434  THEN 
18435  --
18436   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18437       trace
18438          (p_msg      => 'END of AcctDerRule_173'
18439          ,p_level    => C_LEVEL_PROCEDURE
18440          ,p_module   => l_log_module);
18441   END IF;
18442   x_value_type_code := 'S';
18446  ELSIF TO_NUMBER(p_source_3) IS NULL 
18443   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_3));
18444   RETURN l_output_value;
18445 
18447  THEN 
18448  --
18449   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18450       trace
18451          (p_msg      => 'END of AcctDerRule_173'
18452          ,p_level    => C_LEVEL_PROCEDURE
18453          ,p_module   => l_log_module);
18454   END IF;
18455   x_value_type_code := 'S';
18456   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_30));
18457   RETURN l_output_value;
18458 
18459  END IF;
18460 --
18461 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18462       trace
18463          (p_msg      => 'END of AcctDerRule_173(invalid)'
18464          ,p_level    => C_LEVEL_PROCEDURE
18465          ,p_module   => l_log_module);
18466 END IF;
18467 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
18468 x_value_type_code := null;
18469 l_output_value    := null;
18470 xla_accounting_err_pkg.build_message
18471                  (p_appli_s_name            => 'XLA'
18472                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
18473                  ,p_token_1                 => 'COMPONENT_NAME'
18474                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
18475                                                             l_component_type
18476                                                           , l_component_code
18477                                                           , l_component_type_code
18478                                                           , l_component_appl_id
18479                                                           , l_amb_context_code
18480                                                           )
18481                  ,p_token_2                 => 'OWNER'
18482                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
18483                                                         'XLA_OWNER_TYPE'
18484                                                         ,l_component_type_code
18485                                                         )
18486                  ,p_token_3                 => 'PAD_NAME'
18487                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
18488                  ,p_token_4                 => 'PAD_OWNER'
18489                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
18490                                                         'XLA_OWNER_TYPE'
18491                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
18492                                                         )
18493                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
18494                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
18495                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
18496                  ,p_ae_header_id            => NULL
18497 );
18498 RETURN l_output_value;
18499 EXCEPTION
18500   WHEN xla_exceptions_pkg.application_exception THEN
18501       RAISE;
18502   WHEN OTHERS THEN
18503        xla_exceptions_pkg.raise_message
18504            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_173');
18505 END AcctDerRule_173;
18506 --
18507 
18508 ---------------------------------------
18509 --
18510 -- PRIVATE FUNCTION
18511 --         AcctDerRule_174
18512 --
18513 ---------------------------------------
18514 FUNCTION AcctDerRule_174 (
18515   p_application_id              IN NUMBER
18516 , p_ae_header_id                IN NUMBER
18517 , p_side                        IN VARCHAR2 
18518 --Generated Code Combination Identifier
18519  , p_source_3            IN NUMBER
18520 --Generated Offset Code Combination Identifier
18521  , p_source_17            IN NUMBER
18522 --Default Code Combination Identifier
18523  , p_source_30            IN NUMBER
18524 , x_transaction_coa_id         OUT NOCOPY NUMBER
18525 , x_accounting_coa_id          OUT NOCOPY NUMBER
18526 , x_value_type_code            OUT NOCOPY VARCHAR2
18527 )
18528 RETURN NUMBER
18529 IS
18530 l_component_type       VARCHAR2(80)  ;
18531 l_component_code       VARCHAR2(30)  ;
18532 l_component_type_code  VARCHAR2(1)   ;
18533 l_component_appl_id    INTEGER       ;
18534 l_amb_context_code     VARCHAR2(30)  ;
18535 l_log_module           VARCHAR2(240) ;
18536 l_output_value         NUMBER        ;
18537 BEGIN
18538 IF g_log_enabled THEN
18539       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_174';
18540 END IF;
18541 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18542       trace
18543          (p_msg      => 'BEGIN of AcctDerRule_174'
18544          ,p_level    => C_LEVEL_PROCEDURE
18545          ,p_module   => l_log_module);
18546 END IF;
18547 --
18548 l_component_type         := 'AMB_ADR';
18549 l_component_code         := 'FA_DEFAULT_OFFSET_ACCOUNT';
18550 l_component_type_code    := 'S';
18551 l_component_appl_id      :=  140;
18552 l_amb_context_code       := 'DEFAULT';
18553 x_transaction_coa_id     :=  null;
18554 x_accounting_coa_id      :=  null;
18555 --
18556 
18557  IF TO_NUMBER(p_source_17) IS NOT NULL 
18558  THEN 
18559  --
18560   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18561       trace
18562          (p_msg      => 'END of AcctDerRule_174'
18563          ,p_level    => C_LEVEL_PROCEDURE
18564          ,p_module   => l_log_module);
18565   END IF;
18566   x_value_type_code := 'S';
18567   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_17));
18568   RETURN l_output_value;
18569 
18570  ELSIF (TO_NUMBER(p_source_3) IS NOT NULL AND 
18571 TO_NUMBER(p_source_17) IS NULL )
18572  THEN 
18573  --
18574   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18575       trace
18576          (p_msg      => 'END of AcctDerRule_174'
18580   x_value_type_code := 'S';
18577          ,p_level    => C_LEVEL_PROCEDURE
18578          ,p_module   => l_log_module);
18579   END IF;
18581   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_3));
18582   RETURN l_output_value;
18583 
18584  ELSIF TO_NUMBER(p_source_3) IS NULL 
18585  THEN 
18586  --
18587   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18588       trace
18589          (p_msg      => 'END of AcctDerRule_174'
18590          ,p_level    => C_LEVEL_PROCEDURE
18591          ,p_module   => l_log_module);
18592   END IF;
18593   x_value_type_code := 'S';
18594   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_30));
18595   RETURN l_output_value;
18596 
18597  END IF;
18598 --
18599 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18600       trace
18601          (p_msg      => 'END of AcctDerRule_174(invalid)'
18602          ,p_level    => C_LEVEL_PROCEDURE
18603          ,p_module   => l_log_module);
18604 END IF;
18605 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
18606 x_value_type_code := null;
18607 l_output_value    := null;
18608 xla_accounting_err_pkg.build_message
18609                  (p_appli_s_name            => 'XLA'
18610                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
18611                  ,p_token_1                 => 'COMPONENT_NAME'
18612                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
18613                                                             l_component_type
18614                                                           , l_component_code
18615                                                           , l_component_type_code
18616                                                           , l_component_appl_id
18617                                                           , l_amb_context_code
18618                                                           )
18619                  ,p_token_2                 => 'OWNER'
18620                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
18621                                                         'XLA_OWNER_TYPE'
18622                                                         ,l_component_type_code
18623                                                         )
18624                  ,p_token_3                 => 'PAD_NAME'
18625                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
18626                  ,p_token_4                 => 'PAD_OWNER'
18627                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
18628                                                         'XLA_OWNER_TYPE'
18629                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
18630                                                         )
18631                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
18632                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
18633                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
18634                  ,p_ae_header_id            => NULL
18635 );
18636 RETURN l_output_value;
18637 EXCEPTION
18638   WHEN xla_exceptions_pkg.application_exception THEN
18639       RAISE;
18640   WHEN OTHERS THEN
18641        xla_exceptions_pkg.raise_message
18642            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_174');
18643 END AcctDerRule_174;
18644 --
18645 
18646 ---------------------------------------
18647 --
18648 -- PRIVATE FUNCTION
18649 --         AcctDerRule_175
18650 --
18651 ---------------------------------------
18652 FUNCTION AcctDerRule_175 (
18653   p_application_id              IN NUMBER
18654 , p_ae_header_id                IN NUMBER
18655 , p_side                        IN VARCHAR2 
18656 --Generated Code Combination Identifier
18657  , p_source_3            IN NUMBER
18658 --Expense Account Code Combination Identifier
18659  , p_source_29            IN NUMBER
18660 , x_transaction_coa_id         OUT NOCOPY NUMBER
18661 , x_accounting_coa_id          OUT NOCOPY NUMBER
18662 , x_value_type_code            OUT NOCOPY VARCHAR2
18663 )
18664 RETURN NUMBER
18665 IS
18666 l_component_type       VARCHAR2(80)  ;
18667 l_component_code       VARCHAR2(30)  ;
18668 l_component_type_code  VARCHAR2(1)   ;
18669 l_component_appl_id    INTEGER       ;
18670 l_amb_context_code     VARCHAR2(30)  ;
18671 l_log_module           VARCHAR2(240) ;
18672 l_output_value         NUMBER        ;
18673 BEGIN
18674 IF g_log_enabled THEN
18675       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_175';
18676 END IF;
18677 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18678       trace
18679          (p_msg      => 'BEGIN of AcctDerRule_175'
18680          ,p_level    => C_LEVEL_PROCEDURE
18681          ,p_module   => l_log_module);
18682 END IF;
18683 --
18684 l_component_type         := 'AMB_ADR';
18685 l_component_code         := 'FA_EXPENSE_ACCOUNT';
18686 l_component_type_code    := 'S';
18687 l_component_appl_id      :=  140;
18688 l_amb_context_code       := 'DEFAULT';
18689 x_transaction_coa_id     :=  null;
18690 x_accounting_coa_id      :=  null;
18691 --
18692 
18693  IF TO_NUMBER(p_source_3) IS NOT NULL 
18694  THEN 
18695  --
18696   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18697       trace
18698          (p_msg      => 'END of AcctDerRule_175'
18699          ,p_level    => C_LEVEL_PROCEDURE
18700          ,p_module   => l_log_module);
18701   END IF;
18702   x_value_type_code := 'S';
18703   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_3));
18704   RETURN l_output_value;
18705 
18706  ELSIF TO_NUMBER(p_source_3) IS NULL 
18707  THEN 
18708  --
18709   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18710       trace
18711          (p_msg      => 'END of AcctDerRule_175'
18715   x_value_type_code := 'S';
18712          ,p_level    => C_LEVEL_PROCEDURE
18713          ,p_module   => l_log_module);
18714   END IF;
18716   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_29));
18717   RETURN l_output_value;
18718 
18719  END IF;
18720 --
18721 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18722       trace
18723          (p_msg      => 'END of AcctDerRule_175(invalid)'
18724          ,p_level    => C_LEVEL_PROCEDURE
18725          ,p_module   => l_log_module);
18726 END IF;
18727 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
18728 x_value_type_code := null;
18729 l_output_value    := null;
18730 xla_accounting_err_pkg.build_message
18731                  (p_appli_s_name            => 'XLA'
18732                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
18733                  ,p_token_1                 => 'COMPONENT_NAME'
18734                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
18735                                                             l_component_type
18736                                                           , l_component_code
18737                                                           , l_component_type_code
18738                                                           , l_component_appl_id
18739                                                           , l_amb_context_code
18740                                                           )
18741                  ,p_token_2                 => 'OWNER'
18742                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
18743                                                         'XLA_OWNER_TYPE'
18744                                                         ,l_component_type_code
18745                                                         )
18746                  ,p_token_3                 => 'PAD_NAME'
18747                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
18748                  ,p_token_4                 => 'PAD_OWNER'
18749                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
18750                                                         'XLA_OWNER_TYPE'
18751                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
18752                                                         )
18753                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
18754                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
18755                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
18756                  ,p_ae_header_id            => NULL
18757 );
18758 RETURN l_output_value;
18759 EXCEPTION
18760   WHEN xla_exceptions_pkg.application_exception THEN
18761       RAISE;
18762   WHEN OTHERS THEN
18763        xla_exceptions_pkg.raise_message
18764            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_175');
18765 END AcctDerRule_175;
18766 --
18767 
18768 ---------------------------------------
18769 --
18770 -- PRIVATE FUNCTION
18771 --         AcctDerRule_176
18772 --
18773 ---------------------------------------
18774 FUNCTION AcctDerRule_176 (
18775   p_application_id              IN NUMBER
18776 , p_ae_header_id                IN NUMBER
18777 , p_side                        IN VARCHAR2 
18778 --Expense Account Code Combination Identifier
18779  , p_source_29            IN NUMBER
18780 --Bonus Generated Code Combination Identifier
18781  , p_source_31            IN NUMBER
18782 , x_transaction_coa_id         OUT NOCOPY NUMBER
18783 , x_accounting_coa_id          OUT NOCOPY NUMBER
18784 , x_value_type_code            OUT NOCOPY VARCHAR2
18785 )
18786 RETURN NUMBER
18787 IS
18788 l_component_type       VARCHAR2(80)  ;
18789 l_component_code       VARCHAR2(30)  ;
18790 l_component_type_code  VARCHAR2(1)   ;
18791 l_component_appl_id    INTEGER       ;
18792 l_amb_context_code     VARCHAR2(30)  ;
18793 l_log_module           VARCHAR2(240) ;
18794 l_output_value         NUMBER        ;
18795 BEGIN
18796 IF g_log_enabled THEN
18797       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_176';
18798 END IF;
18799 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18800       trace
18801          (p_msg      => 'BEGIN of AcctDerRule_176'
18802          ,p_level    => C_LEVEL_PROCEDURE
18803          ,p_module   => l_log_module);
18804 END IF;
18805 --
18806 l_component_type         := 'AMB_ADR';
18807 l_component_code         := 'FA_PER_BONUS_DEPRN_EXPENSE';
18808 l_component_type_code    := 'S';
18809 l_component_appl_id      :=  140;
18810 l_amb_context_code       := 'DEFAULT';
18811 x_transaction_coa_id     :=  null;
18812 x_accounting_coa_id      :=  null;
18813 --
18814 
18815  IF TO_NUMBER(p_source_31) IS NOT NULL 
18816  THEN 
18817  --
18818   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18819       trace
18820          (p_msg      => 'END of AcctDerRule_176'
18821          ,p_level    => C_LEVEL_PROCEDURE
18822          ,p_module   => l_log_module);
18823   END IF;
18824   x_value_type_code := 'S';
18825   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_31));
18826   RETURN l_output_value;
18827 
18828  ELSIF TO_NUMBER(p_source_31) IS NULL 
18829  THEN 
18830  --
18831   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18832       trace
18833          (p_msg      => 'END of AcctDerRule_176'
18834          ,p_level    => C_LEVEL_PROCEDURE
18835          ,p_module   => l_log_module);
18836   END IF;
18837   x_value_type_code := 'S';
18838   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_29));
18839   RETURN l_output_value;
18840 
18841  END IF;
18842 --
18843 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18844       trace
18845          (p_msg      => 'END of AcctDerRule_176(invalid)'
18849 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
18846          ,p_level    => C_LEVEL_PROCEDURE
18847          ,p_module   => l_log_module);
18848 END IF;
18850 x_value_type_code := null;
18851 l_output_value    := null;
18852 xla_accounting_err_pkg.build_message
18853                  (p_appli_s_name            => 'XLA'
18854                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
18855                  ,p_token_1                 => 'COMPONENT_NAME'
18856                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
18857                                                             l_component_type
18858                                                           , l_component_code
18859                                                           , l_component_type_code
18860                                                           , l_component_appl_id
18861                                                           , l_amb_context_code
18862                                                           )
18863                  ,p_token_2                 => 'OWNER'
18864                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
18865                                                         'XLA_OWNER_TYPE'
18866                                                         ,l_component_type_code
18867                                                         )
18868                  ,p_token_3                 => 'PAD_NAME'
18869                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
18870                  ,p_token_4                 => 'PAD_OWNER'
18871                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
18872                                                         'XLA_OWNER_TYPE'
18873                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
18874                                                         )
18875                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
18876                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
18877                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
18878                  ,p_ae_header_id            => NULL
18879 );
18880 RETURN l_output_value;
18881 EXCEPTION
18882   WHEN xla_exceptions_pkg.application_exception THEN
18883       RAISE;
18884   WHEN OTHERS THEN
18885        xla_exceptions_pkg.raise_message
18886            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_176');
18887 END AcctDerRule_176;
18888 --
18889 
18890 ---------------------------------------
18891 --
18892 -- PRIVATE FUNCTION
18893 --         AcctDerRule_177
18894 --
18895 ---------------------------------------
18896 FUNCTION AcctDerRule_177 (
18897   p_application_id              IN NUMBER
18898 , p_ae_header_id                IN NUMBER
18899 , p_side                        IN VARCHAR2 
18900 --Default Code Combination Identifier
18901  , p_source_30            IN NUMBER
18902 --Bonus Generated Offset Code Combination Identifier
18903  , p_source_32            IN NUMBER
18904 , x_transaction_coa_id         OUT NOCOPY NUMBER
18905 , x_accounting_coa_id          OUT NOCOPY NUMBER
18906 , x_value_type_code            OUT NOCOPY VARCHAR2
18907 )
18908 RETURN NUMBER
18909 IS
18910 l_component_type       VARCHAR2(80)  ;
18911 l_component_code       VARCHAR2(30)  ;
18912 l_component_type_code  VARCHAR2(1)   ;
18913 l_component_appl_id    INTEGER       ;
18914 l_amb_context_code     VARCHAR2(30)  ;
18915 l_log_module           VARCHAR2(240) ;
18916 l_output_value         NUMBER        ;
18917 BEGIN
18918 IF g_log_enabled THEN
18919       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_177';
18920 END IF;
18921 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18922       trace
18923          (p_msg      => 'BEGIN of AcctDerRule_177'
18924          ,p_level    => C_LEVEL_PROCEDURE
18925          ,p_module   => l_log_module);
18926 END IF;
18927 --
18928 l_component_type         := 'AMB_ADR';
18929 l_component_code         := 'FA_PER_BONUS_DEPRN_RESERVE';
18930 l_component_type_code    := 'S';
18931 l_component_appl_id      :=  140;
18932 l_amb_context_code       := 'DEFAULT';
18933 x_transaction_coa_id     :=  null;
18934 x_accounting_coa_id      :=  null;
18935 --
18936 
18937  IF TO_NUMBER(p_source_32) IS NOT NULL 
18938  THEN 
18939  --
18940   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18941       trace
18942          (p_msg      => 'END of AcctDerRule_177'
18943          ,p_level    => C_LEVEL_PROCEDURE
18944          ,p_module   => l_log_module);
18945   END IF;
18946   x_value_type_code := 'S';
18947   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_32));
18948   RETURN l_output_value;
18949 
18950  ELSIF TO_NUMBER(p_source_32) IS NULL 
18951  THEN 
18952  --
18953   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18954       trace
18955          (p_msg      => 'END of AcctDerRule_177'
18956          ,p_level    => C_LEVEL_PROCEDURE
18957          ,p_module   => l_log_module);
18958   END IF;
18959   x_value_type_code := 'S';
18960   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_30));
18961   RETURN l_output_value;
18962 
18963  END IF;
18964 --
18965 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18966       trace
18967          (p_msg      => 'END of AcctDerRule_177(invalid)'
18968          ,p_level    => C_LEVEL_PROCEDURE
18969          ,p_module   => l_log_module);
18970 END IF;
18971 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
18972 x_value_type_code := null;
18973 l_output_value    := null;
18974 xla_accounting_err_pkg.build_message
18975                  (p_appli_s_name            => 'XLA'
18976                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
18980                                                           , l_component_code
18977                  ,p_token_1                 => 'COMPONENT_NAME'
18978                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
18979                                                             l_component_type
18981                                                           , l_component_type_code
18982                                                           , l_component_appl_id
18983                                                           , l_amb_context_code
18984                                                           )
18985                  ,p_token_2                 => 'OWNER'
18986                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
18987                                                         'XLA_OWNER_TYPE'
18988                                                         ,l_component_type_code
18989                                                         )
18990                  ,p_token_3                 => 'PAD_NAME'
18991                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
18992                  ,p_token_4                 => 'PAD_OWNER'
18993                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
18994                                                         'XLA_OWNER_TYPE'
18995                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
18996                                                         )
18997                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
18998                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
18999                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
19000                  ,p_ae_header_id            => NULL
19001 );
19002 RETURN l_output_value;
19003 EXCEPTION
19004   WHEN xla_exceptions_pkg.application_exception THEN
19005       RAISE;
19006   WHEN OTHERS THEN
19007        xla_exceptions_pkg.raise_message
19008            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_177');
19009 END AcctDerRule_177;
19010 --
19011 
19012 ---------------------------------------
19013 --
19014 -- PRIVATE FUNCTION
19015 --         AcctDerRule_178
19016 --
19017 ---------------------------------------
19018 FUNCTION AcctDerRule_178 (
19019   p_application_id              IN NUMBER
19020 , p_ae_header_id                IN NUMBER
19021 , p_side                        IN VARCHAR2 
19022 --Default Code Combination Identifier
19023  , p_source_30            IN NUMBER
19024 --Revaluation Generated Code Combination Identifier
19025  , p_source_33            IN NUMBER
19026 , x_transaction_coa_id         OUT NOCOPY NUMBER
19027 , x_accounting_coa_id          OUT NOCOPY NUMBER
19028 , x_value_type_code            OUT NOCOPY VARCHAR2
19029 )
19030 RETURN NUMBER
19031 IS
19032 l_component_type       VARCHAR2(80)  ;
19033 l_component_code       VARCHAR2(30)  ;
19034 l_component_type_code  VARCHAR2(1)   ;
19035 l_component_appl_id    INTEGER       ;
19036 l_amb_context_code     VARCHAR2(30)  ;
19037 l_log_module           VARCHAR2(240) ;
19038 l_output_value         NUMBER        ;
19039 BEGIN
19040 IF g_log_enabled THEN
19041       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_178';
19042 END IF;
19043 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19044       trace
19045          (p_msg      => 'BEGIN of AcctDerRule_178'
19046          ,p_level    => C_LEVEL_PROCEDURE
19047          ,p_module   => l_log_module);
19048 END IF;
19049 --
19050 l_component_type         := 'AMB_ADR';
19051 l_component_code         := 'FA_PER_REVAL_AMORTIZATION';
19052 l_component_type_code    := 'S';
19053 l_component_appl_id      :=  140;
19054 l_amb_context_code       := 'DEFAULT';
19055 x_transaction_coa_id     :=  null;
19056 x_accounting_coa_id      :=  null;
19057 --
19058 
19059  IF TO_NUMBER(p_source_33) IS NOT NULL 
19060  THEN 
19061  --
19062   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19063       trace
19064          (p_msg      => 'END of AcctDerRule_178'
19065          ,p_level    => C_LEVEL_PROCEDURE
19066          ,p_module   => l_log_module);
19067   END IF;
19068   x_value_type_code := 'S';
19069   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_33));
19070   RETURN l_output_value;
19071 
19072  ELSIF TO_NUMBER(p_source_33) IS NULL 
19073  THEN 
19074  --
19075   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19076       trace
19077          (p_msg      => 'END of AcctDerRule_178'
19078          ,p_level    => C_LEVEL_PROCEDURE
19079          ,p_module   => l_log_module);
19080   END IF;
19081   x_value_type_code := 'S';
19082   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_30));
19083   RETURN l_output_value;
19084 
19085  END IF;
19086 --
19087 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19088       trace
19089          (p_msg      => 'END of AcctDerRule_178(invalid)'
19090          ,p_level    => C_LEVEL_PROCEDURE
19091          ,p_module   => l_log_module);
19092 END IF;
19093 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
19094 x_value_type_code := null;
19095 l_output_value    := null;
19096 xla_accounting_err_pkg.build_message
19097                  (p_appli_s_name            => 'XLA'
19098                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
19099                  ,p_token_1                 => 'COMPONENT_NAME'
19100                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
19101                                                             l_component_type
19102                                                           , l_component_code
19103                                                           , l_component_type_code
19107                  ,p_token_2                 => 'OWNER'
19104                                                           , l_component_appl_id
19105                                                           , l_amb_context_code
19106                                                           )
19108                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
19109                                                         'XLA_OWNER_TYPE'
19110                                                         ,l_component_type_code
19111                                                         )
19112                  ,p_token_3                 => 'PAD_NAME'
19113                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
19114                  ,p_token_4                 => 'PAD_OWNER'
19115                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
19116                                                         'XLA_OWNER_TYPE'
19117                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
19118                                                         )
19119                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
19120                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
19121                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
19122                  ,p_ae_header_id            => NULL
19123 );
19124 RETURN l_output_value;
19125 EXCEPTION
19126   WHEN xla_exceptions_pkg.application_exception THEN
19127       RAISE;
19128   WHEN OTHERS THEN
19129        xla_exceptions_pkg.raise_message
19130            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_178');
19131 END AcctDerRule_178;
19132 --
19133 
19134 ---------------------------------------
19135 --
19136 -- PRIVATE FUNCTION
19137 --         AcctDerRule_179
19138 --
19139 ---------------------------------------
19140 FUNCTION AcctDerRule_179 (
19141   p_application_id              IN NUMBER
19142 , p_ae_header_id                IN NUMBER
19143 , p_side                        IN VARCHAR2 
19144 --Default Code Combination Identifier
19145  , p_source_30            IN NUMBER
19146 --Revaluation Generated Offset Code Combination Identifier
19147  , p_source_34            IN NUMBER
19148 , x_transaction_coa_id         OUT NOCOPY NUMBER
19149 , x_accounting_coa_id          OUT NOCOPY NUMBER
19150 , x_value_type_code            OUT NOCOPY VARCHAR2
19151 )
19152 RETURN NUMBER
19153 IS
19154 l_component_type       VARCHAR2(80)  ;
19155 l_component_code       VARCHAR2(30)  ;
19156 l_component_type_code  VARCHAR2(1)   ;
19157 l_component_appl_id    INTEGER       ;
19158 l_amb_context_code     VARCHAR2(30)  ;
19159 l_log_module           VARCHAR2(240) ;
19160 l_output_value         NUMBER        ;
19161 BEGIN
19162 IF g_log_enabled THEN
19163       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_179';
19164 END IF;
19165 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19166       trace
19167          (p_msg      => 'BEGIN of AcctDerRule_179'
19168          ,p_level    => C_LEVEL_PROCEDURE
19169          ,p_module   => l_log_module);
19170 END IF;
19171 --
19172 l_component_type         := 'AMB_ADR';
19173 l_component_code         := 'FA_PER_REVAL_RESERVE';
19174 l_component_type_code    := 'S';
19175 l_component_appl_id      :=  140;
19176 l_amb_context_code       := 'DEFAULT';
19177 x_transaction_coa_id     :=  null;
19178 x_accounting_coa_id      :=  null;
19179 --
19180 
19181  IF TO_NUMBER(p_source_34) IS NOT NULL 
19182  THEN 
19183  --
19184   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19185       trace
19186          (p_msg      => 'END of AcctDerRule_179'
19187          ,p_level    => C_LEVEL_PROCEDURE
19188          ,p_module   => l_log_module);
19189   END IF;
19190   x_value_type_code := 'S';
19191   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_34));
19192   RETURN l_output_value;
19193 
19194  ELSIF TO_NUMBER(p_source_34) IS NULL 
19195  THEN 
19196  --
19197   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19198       trace
19199          (p_msg      => 'END of AcctDerRule_179'
19200          ,p_level    => C_LEVEL_PROCEDURE
19201          ,p_module   => l_log_module);
19202   END IF;
19203   x_value_type_code := 'S';
19204   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_30));
19205   RETURN l_output_value;
19206 
19207  END IF;
19208 --
19209 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19210       trace
19211          (p_msg      => 'END of AcctDerRule_179(invalid)'
19212          ,p_level    => C_LEVEL_PROCEDURE
19213          ,p_module   => l_log_module);
19214 END IF;
19215 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
19216 x_value_type_code := null;
19217 l_output_value    := null;
19218 xla_accounting_err_pkg.build_message
19219                  (p_appli_s_name            => 'XLA'
19220                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
19221                  ,p_token_1                 => 'COMPONENT_NAME'
19222                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
19223                                                             l_component_type
19224                                                           , l_component_code
19225                                                           , l_component_type_code
19226                                                           , l_component_appl_id
19227                                                           , l_amb_context_code
19228                                                           )
19229                  ,p_token_2                 => 'OWNER'
19230                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
19231                                                         'XLA_OWNER_TYPE'
19235                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
19232                                                         ,l_component_type_code
19233                                                         )
19234                  ,p_token_3                 => 'PAD_NAME'
19236                  ,p_token_4                 => 'PAD_OWNER'
19237                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
19238                                                         'XLA_OWNER_TYPE'
19239                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
19240                                                         )
19241                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
19242                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
19243                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
19244                  ,p_ae_header_id            => NULL
19245 );
19246 RETURN l_output_value;
19247 EXCEPTION
19248   WHEN xla_exceptions_pkg.application_exception THEN
19249       RAISE;
19250   WHEN OTHERS THEN
19251        xla_exceptions_pkg.raise_message
19252            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_179');
19253 END AcctDerRule_179;
19254 --
19255 
19256 ---------------------------------------
19257 --
19258 -- PRIVATE FUNCTION
19259 --         AcctDerRule_180
19260 --
19261 ---------------------------------------
19262 FUNCTION AcctDerRule_180 (
19263   p_application_id              IN NUMBER
19264 , p_ae_header_id                IN NUMBER
19265 , p_side                        IN VARCHAR2 
19266 --Generated Offset Code Combination Identifier
19267  , p_source_17            IN NUMBER
19268 --Default Code Combination Identifier
19269  , p_source_30            IN NUMBER
19270 , x_transaction_coa_id         OUT NOCOPY NUMBER
19271 , x_accounting_coa_id          OUT NOCOPY NUMBER
19272 , x_value_type_code            OUT NOCOPY VARCHAR2
19273 )
19274 RETURN NUMBER
19275 IS
19276 l_component_type       VARCHAR2(80)  ;
19277 l_component_code       VARCHAR2(30)  ;
19278 l_component_type_code  VARCHAR2(1)   ;
19279 l_component_appl_id    INTEGER       ;
19280 l_amb_context_code     VARCHAR2(30)  ;
19281 l_log_module           VARCHAR2(240) ;
19282 l_output_value         NUMBER        ;
19283 BEGIN
19284 IF g_log_enabled THEN
19285       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_180';
19286 END IF;
19287 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19288       trace
19289          (p_msg      => 'BEGIN of AcctDerRule_180'
19290          ,p_level    => C_LEVEL_PROCEDURE
19291          ,p_module   => l_log_module);
19292 END IF;
19293 --
19294 l_component_type         := 'AMB_ADR';
19295 l_component_code         := 'FA_UPL_RESERVE';
19296 l_component_type_code    := 'S';
19297 l_component_appl_id      :=  140;
19298 l_amb_context_code       := 'DEFAULT';
19299 x_transaction_coa_id     :=  null;
19300 x_accounting_coa_id      :=  null;
19301 --
19302 
19303  IF TO_NUMBER(p_source_17) IS NOT NULL 
19304  THEN 
19305  --
19306   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19307       trace
19308          (p_msg      => 'END of AcctDerRule_180'
19309          ,p_level    => C_LEVEL_PROCEDURE
19310          ,p_module   => l_log_module);
19311   END IF;
19312   x_value_type_code := 'S';
19313   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_17));
19314   RETURN l_output_value;
19315 
19316  ELSIF TO_NUMBER(p_source_17) IS NULL 
19317  THEN 
19318  --
19319   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19320       trace
19321          (p_msg      => 'END of AcctDerRule_180'
19322          ,p_level    => C_LEVEL_PROCEDURE
19323          ,p_module   => l_log_module);
19324   END IF;
19325   x_value_type_code := 'S';
19326   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_30));
19327   RETURN l_output_value;
19328 
19329  END IF;
19330 --
19331 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19332       trace
19333          (p_msg      => 'END of AcctDerRule_180(invalid)'
19334          ,p_level    => C_LEVEL_PROCEDURE
19335          ,p_module   => l_log_module);
19336 END IF;
19337 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
19338 x_value_type_code := null;
19339 l_output_value    := null;
19340 xla_accounting_err_pkg.build_message
19341                  (p_appli_s_name            => 'XLA'
19342                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
19343                  ,p_token_1                 => 'COMPONENT_NAME'
19344                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
19345                                                             l_component_type
19346                                                           , l_component_code
19347                                                           , l_component_type_code
19348                                                           , l_component_appl_id
19349                                                           , l_amb_context_code
19350                                                           )
19351                  ,p_token_2                 => 'OWNER'
19352                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
19353                                                         'XLA_OWNER_TYPE'
19354                                                         ,l_component_type_code
19355                                                         )
19356                  ,p_token_3                 => 'PAD_NAME'
19357                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
19358                  ,p_token_4                 => 'PAD_OWNER'
19359                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
19363                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
19360                                                         'XLA_OWNER_TYPE'
19361                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
19362                                                         )
19364                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
19365                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
19366                  ,p_ae_header_id            => NULL
19367 );
19368 RETURN l_output_value;
19369 EXCEPTION
19370   WHEN xla_exceptions_pkg.application_exception THEN
19371       RAISE;
19372   WHEN OTHERS THEN
19373        xla_exceptions_pkg.raise_message
19374            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctDerRule_180');
19375 END AcctDerRule_180;
19376 --
19377 
19378 ---------------------------------------
19379 --
19380 -- PRIVATE FUNCTION
19381 --         AcctLineType_181
19382 --
19383 ---------------------------------------
19384 PROCEDURE AcctLineType_181 (
19385   p_application_id        IN NUMBER
19386  ,p_event_id              IN NUMBER
19387  ,p_calculate_acctd_flag  IN VARCHAR2
19388  ,p_calculate_g_l_flag    IN VARCHAR2
19389  ,p_actual_flag           IN OUT VARCHAR2
19390  ,p_balance_type_code     OUT VARCHAR2
19391  ,p_gain_or_loss_ref      OUT VARCHAR2
19392  
19393 --Period Close Date
19394  , p_source_1            IN DATE
19395 --Bonus Depreciation Expense Account
19396  , p_source_2            IN VARCHAR2
19397 --Generated Code Combination Identifier
19398  , p_source_3            IN NUMBER
19399 --Expense Account Code Combination Identifier
19400  , p_source_29            IN NUMBER
19401 --Adjustment Type
19402  , p_source_35            IN VARCHAR2
19403 --Transaction Header Identifier
19404  , p_source_36            IN NUMBER
19405 --Adjustment Line Identifier
19406  , p_source_37            IN NUMBER
19407 --Distribution Type Code
19408  , p_source_38            IN VARCHAR2
19409 --Entered Amount
19410  , p_source_39            IN NUMBER
19411 --Currency Code
19412  , p_source_40            IN VARCHAR2
19413 )
19414 IS
19415 
19416 l_component_type              VARCHAR2(80);
19417 l_component_code              VARCHAR2(30);
19418 l_component_type_code         VARCHAR2(1);
19419 l_component_appl_id           INTEGER;
19420 l_amb_context_code            VARCHAR2(30);
19421 l_entity_code                 VARCHAR2(30);
19422 l_event_class_code            VARCHAR2(30);
19423 l_ae_header_id                NUMBER;
19424 l_event_type_code             VARCHAR2(30);
19425 l_line_definition_code        VARCHAR2(30);
19426 l_line_definition_owner_code  VARCHAR2(1);
19427 --
19428 -- adr variables
19429 l_segment                     VARCHAR2(30);
19430 l_ccid                        NUMBER;
19431 l_adr_transaction_coa_id      NUMBER;
19432 l_adr_accounting_coa_id       NUMBER;
19433 l_adr_flexfield_segment_code  VARCHAR2(30);
19434 l_adr_flex_value_set_id       NUMBER;
19435 l_adr_value_type_code         VARCHAR2(30);
19436 l_adr_value_combination_id    NUMBER;
19437 l_adr_value_segment_code      VARCHAR2(30);
19438 
19439 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
19440 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
19441 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
19442 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
19443 
19444 -- 4262811 Variables ------------------------------------------------------------------------------------------
19445 l_entered_amt_idx             NUMBER;
19446 l_accted_amt_idx              NUMBER;
19447 l_acc_rev_flag                VARCHAR2(1);
19448 l_accrual_line_num            NUMBER;
19449 l_tmp_amt                     NUMBER;
19450 l_acc_rev_natural_side_code   VARCHAR2(1);
19451 
19452 l_num_entries                 NUMBER;
19453 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
19454 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
19455 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
19456 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
19457 l_recog_line_1                NUMBER;
19458 l_recog_line_2                NUMBER;
19459 
19460 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
19461 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
19462 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
19463 
19464 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
19465 
19466 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
19467 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
19468 
19469 ---------------------------------------------------------------------------------------------------------------
19470 
19471 
19472 --
19473 -- bulk performance
19474 --
19475 l_balance_type_code           VARCHAR2(1);
19476 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
19477 l_log_module                  VARCHAR2(240);
19478 
19479 --
19480 -- Upgrade strategy
19481 --
19482 l_actual_upg_option           VARCHAR2(1);
19483 l_enc_upg_option           VARCHAR2(1);
19484 
19485 --
19486 BEGIN
19487 --
19488 IF g_log_enabled THEN
19489       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_181';
19490 END IF;
19491 --
19492 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19493 
19494       trace
19495          (p_msg      => 'BEGIN of AcctLineType_181'
19496          ,p_level    => C_LEVEL_PROCEDURE
19497          ,p_module   => l_log_module);
19498 
19499 END IF;
19503 l_component_type_code        := 'S';
19500 --
19501 l_component_type             := 'AMB_JLT';
19502 l_component_code             := 'FA_ADD_BONUS_EXP';
19504 l_component_appl_id          :=  140;
19505 l_amb_context_code           := 'DEFAULT';
19506 l_entity_code                := 'TRANSACTIONS';
19507 l_event_class_code           := 'ADDITIONS';
19508 l_event_type_code            := 'ADDITIONS_ALL';
19509 l_line_definition_owner_code := 'S';
19510 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADDITI1';
19511 --
19512 l_balance_type_code          := 'A';
19513 l_segment                     := NULL;
19514 l_ccid                        := NULL;
19515 l_adr_transaction_coa_id      := NULL;
19516 l_adr_accounting_coa_id       := NULL;
19517 l_adr_flexfield_segment_code  := NULL;
19518 l_adr_flex_value_set_id       := NULL;
19519 l_adr_value_type_code         := NULL;
19520 l_adr_value_combination_id    := NULL;
19521 l_adr_value_segment_code      := NULL;
19522 
19523 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
19524 l_bflow_class_code           := '';    -- 4219869 Business Flow
19525 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
19526 l_budgetary_control_flag     := 'N';
19527 
19528 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
19529 l_bflow_applied_to_amt       := NULL; -- 5132302
19530 l_entered_amt_idx            := NULL;          -- 4262811
19531 l_accted_amt_idx             := NULL;          -- 4262811
19532 l_acc_rev_flag               := NULL;          -- 4262811
19533 l_accrual_line_num           := NULL;          -- 4262811
19534 l_tmp_amt                    := NULL;          -- 4262811
19535 --
19536  
19537 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
19538     l_balance_type_code <> 'B' THEN
19539 IF NVL(p_source_35,'
19540 ') =  'BONUS EXPENSE'
19541  THEN 
19542 
19543    --
19544    XLA_AE_LINES_PKG.SetNewLine;
19545 
19546    p_balance_type_code          := l_balance_type_code;
19547    -- set the flag so later we will know whether the gain loss line needs to be created
19548    
19549    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
19550      p_actual_flag :='A';
19551    END IF;
19552 
19553    --
19554    -- bulk performance
19555    --
19556    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
19557                                       p_header_num   => 0); -- 4262811
19558    --
19559    -- set accounting line options
19560    --
19561    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
19562            p_natural_side_code          => 'D'
19563          , p_gain_or_loss_flag          => 'N'
19564          , p_gl_transfer_mode_code      => 'S'
19565          , p_acct_entry_type_code       => 'A'
19566          , p_switch_side_flag           => 'Y'
19567          , p_merge_duplicate_code       => 'N'
19568          );
19569    --
19570    l_acc_rev_natural_side_code := 'C';  -- 4262811
19571    -- 
19572    --
19573    -- set accounting line type info
19574    --
19575    xla_ae_lines_pkg.SetAcctLineType
19576       (p_component_type             => l_component_type
19577       ,p_event_type_code            => l_event_type_code
19578       ,p_line_definition_owner_code => l_line_definition_owner_code
19579       ,p_line_definition_code       => l_line_definition_code
19580       ,p_accounting_line_code       => l_component_code
19581       ,p_accounting_line_type_code  => l_component_type_code
19582       ,p_accounting_line_appl_id    => l_component_appl_id
19583       ,p_amb_context_code           => l_amb_context_code
19584       ,p_entity_code                => l_entity_code
19585       ,p_event_class_code           => l_event_class_code);
19586    --
19587    -- set accounting class
19588    --
19589    xla_ae_lines_pkg.SetAcctClass(
19590            p_accounting_class_code  => 'EXPENSE'
19591          , p_ae_header_id           => l_ae_header_id
19592          );
19593 
19594    --
19595    -- set rounding class
19596    --
19597    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
19598                       'EXPENSE';
19599 
19600    --
19601    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
19602    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
19603    --
19604    -- bulk performance
19605    --
19606    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
19607 
19608    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
19609       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
19610 
19611    -- 4955764
19612    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19613       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
19614 
19615    -- 4458381 Public Sector Enh
19616    
19617    --
19618    -- set accounting attributes for the line type
19619    --
19620    l_entered_amt_idx := 4;
19621    l_accted_amt_idx  := 6;
19622    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
19623    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
19624    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
19625    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
19626    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
19627    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
19628    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
19629    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
19630    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
19631    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
19635 
19632    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
19633    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
19634    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
19636    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
19637    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
19638 
19639    ---------------------------------------------------------------------------------------------------------------
19640    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
19641    ---------------------------------------------------------------------------------------------------------------
19642    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
19643 
19644    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19645    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19646 
19647    IF xla_accounting_cache_pkg.GetValueChar
19648          (p_source_code         => 'LEDGER_CATEGORY_CODE'
19649          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
19650    AND l_bflow_method_code = 'PRIOR_ENTRY'
19651 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
19652    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
19653          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
19654        )
19655    THEN
19656          xla_ae_lines_pkg.BflowUpgEntry
19657            (p_business_method_code    => l_bflow_method_code
19658            ,p_business_class_code     => l_bflow_class_code
19659            ,p_balance_type            => l_balance_type_code);
19660    ELSE
19661       NULL;
19662 -- No business flow processing for business flow method of NONE.
19663    END IF;
19664 
19665    --
19666    -- call analytical criteria
19667    --
19668    
19669    --
19670    -- call description
19671    --
19672    
19673 xla_ae_lines_pkg.SetLineDescription(
19674    p_ae_header_id => l_ae_header_id
19675   ,p_description  => Description_2 (
19676      p_application_id         => p_application_id
19677    , p_ae_header_id           => l_ae_header_id 
19678 , p_source_1 => p_source_1
19679    )
19680 );
19681 
19682 
19683    --
19684    -- call ADRs
19685    -- Bug 4922099
19686    --
19687    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19688         (NVL(l_actual_upg_option, 'N') = 'O') OR
19689         (NVL(l_enc_upg_option, 'N') = 'O')
19690       )
19691    THEN
19692    NULL;
19693    --
19694    --
19695    
19696   l_ccid := AcctDerRule_175(
19697            p_application_id           => p_application_id
19698          , p_ae_header_id             => l_ae_header_id 
19699 , p_source_3 => p_source_3
19700 , p_source_29 => p_source_29
19701          , x_transaction_coa_id       => l_adr_transaction_coa_id
19702          , x_accounting_coa_id        => l_adr_accounting_coa_id
19703          , x_value_type_code          => l_adr_value_type_code
19704          , p_side                     => 'NA'
19705    );
19706 
19707    xla_ae_lines_pkg.set_ccid(
19708     p_code_combination_id          => l_ccid
19709   , p_value_type_code              => l_adr_value_type_code
19710   , p_transaction_coa_id           => l_adr_transaction_coa_id
19711   , p_accounting_coa_id            => l_adr_accounting_coa_id
19712   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
19713   , p_adr_type_code                => 'S'
19714   , p_component_type               => l_component_type
19715   , p_component_code               => l_component_code
19716   , p_component_type_code          => l_component_type_code
19717   , p_component_appl_id            => l_component_appl_id
19718   , p_amb_context_code             => l_amb_context_code
19719   , p_side                         => 'NA'
19720   );
19721 
19722 
19723    l_segment := AcctDerRule_143(
19724            p_application_id           => p_application_id
19725          , p_ae_header_id             => l_ae_header_id 
19726 , p_source_2 => p_source_2
19727 , p_source_3 => p_source_3
19728          , x_transaction_coa_id       => l_adr_transaction_coa_id
19729          , x_accounting_coa_id        => l_adr_accounting_coa_id
19730          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
19731          , x_flex_value_set_id        => l_adr_flex_value_set_id
19732          , x_value_type_code          => l_adr_value_type_code
19733          , x_value_combination_id     => l_adr_value_combination_id
19734          , x_value_segment_code       => l_adr_value_segment_code
19735          , p_side                     => 'NA'
19736          , p_override_seg_flag        => 'Y'
19737    );
19738 
19739    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
19740 
19741       xla_ae_lines_pkg.set_segment(
19742           p_to_segment_code         => 'GL_ACCOUNT'
19743         , p_segment_value           => l_segment
19744         , p_from_segment_code       => l_adr_value_segment_code
19745         , p_from_combination_id     => l_adr_value_combination_id
19746         , p_value_type_code         => l_adr_value_type_code
19747         , p_transaction_coa_id      => l_adr_transaction_coa_id
19748         , p_accounting_coa_id       => l_adr_accounting_coa_id
19749         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
19750         , p_flex_value_set_id       => l_adr_flex_value_set_id
19751         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
19752         , p_adr_type_code           => 'S'
19753         , p_component_type          => l_component_type
19754         , p_component_code          => l_component_code
19755         , p_component_type_code     => l_component_type_code
19756         , p_component_appl_id       => l_component_appl_id
19760         , p_side                    => 'NA'
19757         , p_amb_context_code        => l_amb_context_code
19758         , p_entity_code             => 'TRANSACTIONS'
19759         , p_event_class_code        => 'ADDITIONS'
19761         );
19762 
19763   END IF;
19764 
19765    --
19766    --
19767    END IF;
19768    --
19769    -- Bug 4922099
19770    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
19771           (NVL(l_enc_upg_option, 'N') = 'O')
19772         ) AND
19773         (l_bflow_method_code = 'PRIOR_ENTRY')
19774       )
19775    THEN
19776       IF
19777       --
19778       1 = 2
19779       --
19780       THEN
19781       xla_accounting_err_pkg.build_message
19782                                     (p_appli_s_name            => 'XLA'
19783                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19784                                     ,p_token_1                 => 'LINE_NUMBER'
19785                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
19786                                     ,p_token_2                 => 'LINE_TYPE_NAME'
19787                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
19788                                                                              l_component_type
19789                                                                             ,l_component_code
19790                                                                             ,l_component_type_code
19791                                                                             ,l_component_appl_id
19792                                                                             ,l_amb_context_code
19793                                                                             ,l_entity_code
19794                                                                             ,l_event_class_code
19795                                                                            )
19796                                     ,p_token_3                 => 'OWNER'
19797                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
19798                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
19799                                                                           ,p_lookup_code    => l_component_type_code
19800                                                                          )
19801                                     ,p_token_4                 => 'PRODUCT_NAME'
19802                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
19803                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
19804                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
19805                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
19806                                     ,p_ae_header_id            =>  NULL
19807                                        );
19808 
19809         IF (C_LEVEL_ERROR>= g_log_level) THEN
19810                  trace
19811                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19812                       ,p_level    => C_LEVEL_ERROR
19813                       ,p_module   => l_log_module);
19814         END IF;
19815       END IF;
19816    END IF;
19817    --
19818    --
19819    ------------------------------------------------------------------------------------------------
19820    -- 4219869 Business Flow
19821    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
19822    -- Prior Entry.  Currently, the following code is always generated.
19823    ------------------------------------------------------------------------------------------------
19824    XLA_AE_LINES_PKG.ValidateCurrentLine;
19825 
19826    ------------------------------------------------------------------------------------
19827    -- 4219869 Business Flow
19828    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
19829    ------------------------------------------------------------------------------------
19830    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19831 
19832    ----------------------------------------------------------------------------------
19833    -- 4219869 Business Flow
19834    -- Update journal entry status -- Need to generate this within IF <condition>
19835    ----------------------------------------------------------------------------------
19836    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19837          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
19838          ,p_balance_type_code => l_balance_type_code
19839          );
19840 
19841    -------------------------------------------------------------------------------------------
19842    -- 4262811 - Generate the Accrual Reversal lines
19843    -------------------------------------------------------------------------------------------
19844    BEGIN
19845       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
19846                               (g_array_event(p_event_id).array_value_num('header_index'));
19847       IF l_acc_rev_flag IS NULL THEN
19848          l_acc_rev_flag := 'N';
19849       END IF;
19850    EXCEPTION
19851       WHEN OTHERS THEN
19852          l_acc_rev_flag := 'N';
19853    END;
19854    --
19855    IF (l_acc_rev_flag = 'Y') THEN
19856 
19857        -- 4645092  ------------------------------------------------------------------------------
19858        -- To allow MPA report to determine if it should generate report process
19859        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
19860        ------------------------------------------------------------------------------------------
19861 
19862        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
19866    -- Bug 4922099
19863        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
19864    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
19865    -- call ADRs
19867    --
19868    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19869         (NVL(l_actual_upg_option, 'N') = 'O') OR
19870         (NVL(l_enc_upg_option, 'N') = 'O')
19871       )
19872    THEN
19873    NULL;
19874    --
19875    --
19876    
19877   l_ccid := AcctDerRule_175(
19878            p_application_id           => p_application_id
19879          , p_ae_header_id             => l_ae_header_id 
19880 , p_source_3 => p_source_3
19881 , p_source_29 => p_source_29
19882          , x_transaction_coa_id       => l_adr_transaction_coa_id
19883          , x_accounting_coa_id        => l_adr_accounting_coa_id
19884          , x_value_type_code          => l_adr_value_type_code
19885          , p_side                     => 'NA'
19886    );
19887 
19888    xla_ae_lines_pkg.set_ccid(
19889     p_code_combination_id          => l_ccid
19890   , p_value_type_code              => l_adr_value_type_code
19891   , p_transaction_coa_id           => l_adr_transaction_coa_id
19892   , p_accounting_coa_id            => l_adr_accounting_coa_id
19893   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
19894   , p_adr_type_code                => 'S'
19895   , p_component_type               => l_component_type
19896   , p_component_code               => l_component_code
19897   , p_component_type_code          => l_component_type_code
19898   , p_component_appl_id            => l_component_appl_id
19899   , p_amb_context_code             => l_amb_context_code
19900   , p_side                         => 'NA'
19901   );
19902 
19903 
19904    l_segment := AcctDerRule_143(
19905            p_application_id           => p_application_id
19906          , p_ae_header_id             => l_ae_header_id 
19907 , p_source_2 => p_source_2
19908 , p_source_3 => p_source_3
19909          , x_transaction_coa_id       => l_adr_transaction_coa_id
19910          , x_accounting_coa_id        => l_adr_accounting_coa_id
19911          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
19912          , x_flex_value_set_id        => l_adr_flex_value_set_id
19913          , x_value_type_code          => l_adr_value_type_code
19914          , x_value_combination_id     => l_adr_value_combination_id
19915          , x_value_segment_code       => l_adr_value_segment_code
19916          , p_side                     => 'NA'
19917          , p_override_seg_flag        => 'Y'
19918    );
19919 
19920    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
19921 
19922       xla_ae_lines_pkg.set_segment(
19923           p_to_segment_code         => 'GL_ACCOUNT'
19924         , p_segment_value           => l_segment
19925         , p_from_segment_code       => l_adr_value_segment_code
19926         , p_from_combination_id     => l_adr_value_combination_id
19927         , p_value_type_code         => l_adr_value_type_code
19928         , p_transaction_coa_id      => l_adr_transaction_coa_id
19929         , p_accounting_coa_id       => l_adr_accounting_coa_id
19930         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
19931         , p_flex_value_set_id       => l_adr_flex_value_set_id
19932         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
19933         , p_adr_type_code           => 'S'
19934         , p_component_type          => l_component_type
19935         , p_component_code          => l_component_code
19936         , p_component_type_code     => l_component_type_code
19937         , p_component_appl_id       => l_component_appl_id
19938         , p_amb_context_code        => l_amb_context_code
19939         , p_entity_code             => 'TRANSACTIONS'
19940         , p_event_class_code        => 'ADDITIONS'
19941         , p_side                    => 'NA'
19942         );
19943 
19944   END IF;
19945 
19946    --
19947    --
19948    END IF;
19949 
19950        --
19951        -- Update the line information that should be overwritten
19952        --
19953        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
19954                                          p_header_num   => 1);
19955        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
19956 
19957        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
19958 
19959        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
19960           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
19961        END IF;
19962 
19963       --
19964       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
19965       --
19966       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
19967           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
19968       ELSE
19969           ---------------------------------------------------------------------------------------------------
19970           -- 4262811a Switch Sign
19971           ---------------------------------------------------------------------------------------------------
19972           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
19973           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19974                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19975           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19976                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19977           -- 5132302
19978           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
19982 
19979                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19980 
19981       END IF;
19983       -- 4955764
19984       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19985       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
19986 
19987 
19988       XLA_AE_LINES_PKG.ValidateCurrentLine;
19989       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19990 
19991       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19992                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
19993                ,p_balance_type_code => l_balance_type_code);
19994 
19995    END IF;
19996 
19997    -----------------------------------------------------------------------------------------
19998    -- 4262811 Multiperiod Accounting
19999    -----------------------------------------------------------------------------------------
20000      -- No MPA option is assigned.
20001 
20002 
20003 END IF;
20004 END IF;
20005 --
20006 
20007 --
20008 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20009    trace
20010       (p_msg      => 'END of AcctLineType_181'
20011       ,p_level    => C_LEVEL_PROCEDURE
20012       ,p_module   => l_log_module);
20013 END IF;
20014 --
20015 EXCEPTION
20016   WHEN xla_exceptions_pkg.application_exception THEN
20017       RAISE;
20018   WHEN OTHERS THEN
20019        xla_exceptions_pkg.raise_message
20020            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_181');
20021 END AcctLineType_181;
20022 --
20023 
20024 ---------------------------------------
20025 --
20026 -- PRIVATE FUNCTION
20027 --         AcctLineType_182
20028 --
20029 ---------------------------------------
20030 PROCEDURE AcctLineType_182 (
20031   p_application_id        IN NUMBER
20032  ,p_event_id              IN NUMBER
20033  ,p_calculate_acctd_flag  IN VARCHAR2
20034  ,p_calculate_g_l_flag    IN VARCHAR2
20035  ,p_actual_flag           IN OUT VARCHAR2
20036  ,p_balance_type_code     OUT VARCHAR2
20037  ,p_gain_or_loss_ref      OUT VARCHAR2
20038  
20039 --Period Close Date
20040  , p_source_1            IN DATE
20041 --Generated Code Combination Identifier
20042  , p_source_3            IN NUMBER
20043 --Bonus Reserve Account
20044  , p_source_4            IN VARCHAR2
20045 --Generated Offset Code Combination Identifier
20046  , p_source_17            IN NUMBER
20047 --Expense Account Code Combination Identifier
20048  , p_source_29            IN NUMBER
20049 --Default Code Combination Identifier
20050  , p_source_30            IN NUMBER
20051 --Adjustment Type
20052  , p_source_35            IN VARCHAR2
20053 --Transaction Header Identifier
20054  , p_source_36            IN NUMBER
20055 --Adjustment Line Identifier
20056  , p_source_37            IN NUMBER
20057 --Distribution Type Code
20058  , p_source_38            IN VARCHAR2
20059 --Entered Amount
20060  , p_source_39            IN NUMBER
20061 --Currency Code
20062  , p_source_40            IN VARCHAR2
20063 )
20064 IS
20065 
20066 l_component_type              VARCHAR2(80);
20067 l_component_code              VARCHAR2(30);
20068 l_component_type_code         VARCHAR2(1);
20069 l_component_appl_id           INTEGER;
20070 l_amb_context_code            VARCHAR2(30);
20071 l_entity_code                 VARCHAR2(30);
20072 l_event_class_code            VARCHAR2(30);
20073 l_ae_header_id                NUMBER;
20074 l_event_type_code             VARCHAR2(30);
20075 l_line_definition_code        VARCHAR2(30);
20076 l_line_definition_owner_code  VARCHAR2(1);
20077 --
20078 -- adr variables
20079 l_segment                     VARCHAR2(30);
20080 l_ccid                        NUMBER;
20081 l_adr_transaction_coa_id      NUMBER;
20082 l_adr_accounting_coa_id       NUMBER;
20083 l_adr_flexfield_segment_code  VARCHAR2(30);
20084 l_adr_flex_value_set_id       NUMBER;
20085 l_adr_value_type_code         VARCHAR2(30);
20086 l_adr_value_combination_id    NUMBER;
20087 l_adr_value_segment_code      VARCHAR2(30);
20088 
20089 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
20090 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
20091 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
20092 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
20093 
20094 -- 4262811 Variables ------------------------------------------------------------------------------------------
20095 l_entered_amt_idx             NUMBER;
20096 l_accted_amt_idx              NUMBER;
20097 l_acc_rev_flag                VARCHAR2(1);
20098 l_accrual_line_num            NUMBER;
20099 l_tmp_amt                     NUMBER;
20100 l_acc_rev_natural_side_code   VARCHAR2(1);
20101 
20102 l_num_entries                 NUMBER;
20103 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
20104 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
20105 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
20106 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
20107 l_recog_line_1                NUMBER;
20108 l_recog_line_2                NUMBER;
20109 
20110 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
20111 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
20112 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
20113 
20114 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
20115 
20116 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
20117 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
20118 
20122 --
20119 ---------------------------------------------------------------------------------------------------------------
20120 
20121 
20123 -- bulk performance
20124 --
20125 l_balance_type_code           VARCHAR2(1);
20126 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
20127 l_log_module                  VARCHAR2(240);
20128 
20129 --
20130 -- Upgrade strategy
20131 --
20132 l_actual_upg_option           VARCHAR2(1);
20133 l_enc_upg_option           VARCHAR2(1);
20134 
20135 --
20136 BEGIN
20137 --
20138 IF g_log_enabled THEN
20139       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_182';
20140 END IF;
20141 --
20142 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20143 
20144       trace
20145          (p_msg      => 'BEGIN of AcctLineType_182'
20146          ,p_level    => C_LEVEL_PROCEDURE
20147          ,p_module   => l_log_module);
20148 
20149 END IF;
20150 --
20151 l_component_type             := 'AMB_JLT';
20152 l_component_code             := 'FA_ADD_BONUS_RESERVE';
20153 l_component_type_code        := 'S';
20154 l_component_appl_id          :=  140;
20155 l_amb_context_code           := 'DEFAULT';
20156 l_entity_code                := 'TRANSACTIONS';
20157 l_event_class_code           := 'ADDITIONS';
20158 l_event_type_code            := 'ADDITIONS_ALL';
20159 l_line_definition_owner_code := 'S';
20160 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADDITI1';
20161 --
20162 l_balance_type_code          := 'A';
20163 l_segment                     := NULL;
20164 l_ccid                        := NULL;
20165 l_adr_transaction_coa_id      := NULL;
20166 l_adr_accounting_coa_id       := NULL;
20167 l_adr_flexfield_segment_code  := NULL;
20168 l_adr_flex_value_set_id       := NULL;
20169 l_adr_value_type_code         := NULL;
20170 l_adr_value_combination_id    := NULL;
20171 l_adr_value_segment_code      := NULL;
20172 
20173 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
20174 l_bflow_class_code           := '';    -- 4219869 Business Flow
20175 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
20176 l_budgetary_control_flag     := 'N';
20177 
20178 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
20179 l_bflow_applied_to_amt       := NULL; -- 5132302
20180 l_entered_amt_idx            := NULL;          -- 4262811
20181 l_accted_amt_idx             := NULL;          -- 4262811
20182 l_acc_rev_flag               := NULL;          -- 4262811
20183 l_accrual_line_num           := NULL;          -- 4262811
20184 l_tmp_amt                    := NULL;          -- 4262811
20185 --
20186  
20187 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
20188     l_balance_type_code <> 'B' THEN
20189 IF NVL(p_source_35,'
20190 ') =  'BONUS EXPENSE'
20191  THEN 
20192 
20193    --
20194    XLA_AE_LINES_PKG.SetNewLine;
20195 
20196    p_balance_type_code          := l_balance_type_code;
20197    -- set the flag so later we will know whether the gain loss line needs to be created
20198    
20199    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
20200      p_actual_flag :='A';
20201    END IF;
20202 
20203    --
20204    -- bulk performance
20205    --
20206    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
20207                                       p_header_num   => 0); -- 4262811
20208    --
20209    -- set accounting line options
20210    --
20211    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
20212            p_natural_side_code          => 'C'
20213          , p_gain_or_loss_flag          => 'N'
20214          , p_gl_transfer_mode_code      => 'S'
20215          , p_acct_entry_type_code       => 'A'
20216          , p_switch_side_flag           => 'Y'
20217          , p_merge_duplicate_code       => 'N'
20218          );
20219    --
20220    l_acc_rev_natural_side_code := 'D';  -- 4262811
20221    -- 
20222    --
20223    -- set accounting line type info
20224    --
20225    xla_ae_lines_pkg.SetAcctLineType
20226       (p_component_type             => l_component_type
20227       ,p_event_type_code            => l_event_type_code
20228       ,p_line_definition_owner_code => l_line_definition_owner_code
20229       ,p_line_definition_code       => l_line_definition_code
20230       ,p_accounting_line_code       => l_component_code
20231       ,p_accounting_line_type_code  => l_component_type_code
20232       ,p_accounting_line_appl_id    => l_component_appl_id
20233       ,p_amb_context_code           => l_amb_context_code
20234       ,p_entity_code                => l_entity_code
20235       ,p_event_class_code           => l_event_class_code);
20236    --
20237    -- set accounting class
20238    --
20239    xla_ae_lines_pkg.SetAcctClass(
20240            p_accounting_class_code  => 'ASSET'
20241          , p_ae_header_id           => l_ae_header_id
20242          );
20243 
20244    --
20245    -- set rounding class
20246    --
20247    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
20248                       'ASSET';
20249 
20250    --
20251    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
20252    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
20253    --
20254    -- bulk performance
20255    --
20256    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
20257 
20258    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
20259       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
20260 
20261    -- 4955764
20262    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20266    
20263       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
20264 
20265    -- 4458381 Public Sector Enh
20267    --
20268    -- set accounting attributes for the line type
20269    --
20270    l_entered_amt_idx := 4;
20271    l_accted_amt_idx  := 6;
20272    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
20273    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
20274    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
20275    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
20276    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
20277    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
20278    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
20279    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
20280    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
20281    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
20282    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
20283    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
20284    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
20285 
20286    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
20287    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
20288 
20289    ---------------------------------------------------------------------------------------------------------------
20290    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
20291    ---------------------------------------------------------------------------------------------------------------
20292    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
20293 
20294    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
20295    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
20296 
20297    IF xla_accounting_cache_pkg.GetValueChar
20298          (p_source_code         => 'LEDGER_CATEGORY_CODE'
20299          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
20300    AND l_bflow_method_code = 'PRIOR_ENTRY'
20301 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
20302    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
20303          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
20304        )
20305    THEN
20306          xla_ae_lines_pkg.BflowUpgEntry
20307            (p_business_method_code    => l_bflow_method_code
20308            ,p_business_class_code     => l_bflow_class_code
20309            ,p_balance_type            => l_balance_type_code);
20310    ELSE
20311       NULL;
20312 -- No business flow processing for business flow method of NONE.
20313    END IF;
20314 
20315    --
20316    -- call analytical criteria
20317    --
20318    
20319    --
20320    -- call description
20321    --
20322    
20323 xla_ae_lines_pkg.SetLineDescription(
20324    p_ae_header_id => l_ae_header_id
20325   ,p_description  => Description_3 (
20326      p_application_id         => p_application_id
20327    , p_ae_header_id           => l_ae_header_id 
20328 , p_source_1 => p_source_1
20329    )
20330 );
20331 
20332 
20333    --
20334    -- call ADRs
20335    -- Bug 4922099
20336    --
20337    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20338         (NVL(l_actual_upg_option, 'N') = 'O') OR
20339         (NVL(l_enc_upg_option, 'N') = 'O')
20340       )
20341    THEN
20342    NULL;
20343    --
20344    --
20345    
20346   l_ccid := AcctDerRule_174(
20347            p_application_id           => p_application_id
20348          , p_ae_header_id             => l_ae_header_id 
20349 , p_source_3 => p_source_3
20350 , p_source_17 => p_source_17
20351 , p_source_30 => p_source_30
20352          , x_transaction_coa_id       => l_adr_transaction_coa_id
20353          , x_accounting_coa_id        => l_adr_accounting_coa_id
20354          , x_value_type_code          => l_adr_value_type_code
20355          , p_side                     => 'NA'
20356    );
20357 
20358    xla_ae_lines_pkg.set_ccid(
20359     p_code_combination_id          => l_ccid
20360   , p_value_type_code              => l_adr_value_type_code
20361   , p_transaction_coa_id           => l_adr_transaction_coa_id
20362   , p_accounting_coa_id            => l_adr_accounting_coa_id
20363   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
20364   , p_adr_type_code                => 'S'
20365   , p_component_type               => l_component_type
20366   , p_component_code               => l_component_code
20367   , p_component_type_code          => l_component_type_code
20368   , p_component_appl_id            => l_component_appl_id
20369   , p_amb_context_code             => l_amb_context_code
20370   , p_side                         => 'NA'
20371   );
20372 
20373 
20374    l_segment := AcctDerRule_144(
20375            p_application_id           => p_application_id
20376          , p_ae_header_id             => l_ae_header_id 
20377 , p_source_3 => p_source_3
20378 , p_source_4 => p_source_4
20379          , x_transaction_coa_id       => l_adr_transaction_coa_id
20380          , x_accounting_coa_id        => l_adr_accounting_coa_id
20381          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
20382          , x_flex_value_set_id        => l_adr_flex_value_set_id
20383          , x_value_type_code          => l_adr_value_type_code
20384          , x_value_combination_id     => l_adr_value_combination_id
20385          , x_value_segment_code       => l_adr_value_segment_code
20386          , p_side                     => 'NA'
20387          , p_override_seg_flag        => 'Y'
20388    );
20389 
20393           p_to_segment_code         => 'GL_ACCOUNT'
20390    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
20391 
20392       xla_ae_lines_pkg.set_segment(
20394         , p_segment_value           => l_segment
20395         , p_from_segment_code       => l_adr_value_segment_code
20396         , p_from_combination_id     => l_adr_value_combination_id
20397         , p_value_type_code         => l_adr_value_type_code
20398         , p_transaction_coa_id      => l_adr_transaction_coa_id
20399         , p_accounting_coa_id       => l_adr_accounting_coa_id
20400         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
20401         , p_flex_value_set_id       => l_adr_flex_value_set_id
20402         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
20403         , p_adr_type_code           => 'S'
20404         , p_component_type          => l_component_type
20405         , p_component_code          => l_component_code
20406         , p_component_type_code     => l_component_type_code
20407         , p_component_appl_id       => l_component_appl_id
20408         , p_amb_context_code        => l_amb_context_code
20409         , p_entity_code             => 'TRANSACTIONS'
20410         , p_event_class_code        => 'ADDITIONS'
20411         , p_side                    => 'NA'
20412         );
20413 
20414   END IF;
20415 
20416    l_segment := AcctDerRule_168(
20417            p_application_id           => p_application_id
20418          , p_ae_header_id             => l_ae_header_id 
20419 , p_source_3 => p_source_3
20420 , p_source_29 => p_source_29
20421          , x_transaction_coa_id       => l_adr_transaction_coa_id
20422          , x_accounting_coa_id        => l_adr_accounting_coa_id
20423          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
20424          , x_flex_value_set_id        => l_adr_flex_value_set_id
20425          , x_value_type_code          => l_adr_value_type_code
20426          , x_value_combination_id     => l_adr_value_combination_id
20427          , x_value_segment_code       => l_adr_value_segment_code
20428          , p_side                     => 'NA'
20429          , p_override_seg_flag        => 'Y'
20430    );
20431 
20432    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
20433 
20434       xla_ae_lines_pkg.set_segment(
20435           p_to_segment_code         => 'GL_BALANCING'
20436         , p_segment_value           => l_segment
20437         , p_from_segment_code       => l_adr_value_segment_code
20438         , p_from_combination_id     => l_adr_value_combination_id
20439         , p_value_type_code         => l_adr_value_type_code
20440         , p_transaction_coa_id      => l_adr_transaction_coa_id
20441         , p_accounting_coa_id       => l_adr_accounting_coa_id
20442         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
20443         , p_flex_value_set_id       => l_adr_flex_value_set_id
20444         , p_adr_code                => 'FA_EXPENSE_ACCT'
20445         , p_adr_type_code           => 'S'
20446         , p_component_type          => l_component_type
20447         , p_component_code          => l_component_code
20448         , p_component_type_code     => l_component_type_code
20449         , p_component_appl_id       => l_component_appl_id
20450         , p_amb_context_code        => l_amb_context_code
20451         , p_entity_code             => 'TRANSACTIONS'
20452         , p_event_class_code        => 'ADDITIONS'
20453         , p_side                    => 'NA'
20454         );
20455 
20456   END IF;
20457 
20458    --
20459    --
20460    END IF;
20461    --
20462    -- Bug 4922099
20463    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
20464           (NVL(l_enc_upg_option, 'N') = 'O')
20465         ) AND
20466         (l_bflow_method_code = 'PRIOR_ENTRY')
20467       )
20468    THEN
20469       IF
20470       --
20471       1 = 2
20472       --
20473       THEN
20474       xla_accounting_err_pkg.build_message
20475                                     (p_appli_s_name            => 'XLA'
20476                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20477                                     ,p_token_1                 => 'LINE_NUMBER'
20478                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
20479                                     ,p_token_2                 => 'LINE_TYPE_NAME'
20480                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
20481                                                                              l_component_type
20482                                                                             ,l_component_code
20483                                                                             ,l_component_type_code
20484                                                                             ,l_component_appl_id
20485                                                                             ,l_amb_context_code
20486                                                                             ,l_entity_code
20487                                                                             ,l_event_class_code
20488                                                                            )
20489                                     ,p_token_3                 => 'OWNER'
20490                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
20491                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
20492                                                                           ,p_lookup_code    => l_component_type_code
20493                                                                          )
20494                                     ,p_token_4                 => 'PRODUCT_NAME'
20495                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
20499                                     ,p_ae_header_id            =>  NULL
20496                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
20497                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
20498                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
20500                                        );
20501 
20502         IF (C_LEVEL_ERROR>= g_log_level) THEN
20503                  trace
20504                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20505                       ,p_level    => C_LEVEL_ERROR
20506                       ,p_module   => l_log_module);
20507         END IF;
20508       END IF;
20509    END IF;
20510    --
20511    --
20512    ------------------------------------------------------------------------------------------------
20513    -- 4219869 Business Flow
20514    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
20515    -- Prior Entry.  Currently, the following code is always generated.
20516    ------------------------------------------------------------------------------------------------
20517    XLA_AE_LINES_PKG.ValidateCurrentLine;
20518 
20519    ------------------------------------------------------------------------------------
20520    -- 4219869 Business Flow
20521    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
20522    ------------------------------------------------------------------------------------
20523    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20524 
20525    ----------------------------------------------------------------------------------
20526    -- 4219869 Business Flow
20527    -- Update journal entry status -- Need to generate this within IF <condition>
20528    ----------------------------------------------------------------------------------
20529    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20530          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
20531          ,p_balance_type_code => l_balance_type_code
20532          );
20533 
20534    -------------------------------------------------------------------------------------------
20535    -- 4262811 - Generate the Accrual Reversal lines
20536    -------------------------------------------------------------------------------------------
20537    BEGIN
20538       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
20539                               (g_array_event(p_event_id).array_value_num('header_index'));
20540       IF l_acc_rev_flag IS NULL THEN
20541          l_acc_rev_flag := 'N';
20542       END IF;
20543    EXCEPTION
20544       WHEN OTHERS THEN
20545          l_acc_rev_flag := 'N';
20546    END;
20547    --
20548    IF (l_acc_rev_flag = 'Y') THEN
20549 
20550        -- 4645092  ------------------------------------------------------------------------------
20551        -- To allow MPA report to determine if it should generate report process
20552        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
20553        ------------------------------------------------------------------------------------------
20554 
20555        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
20556        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
20557    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
20558    -- call ADRs
20559    -- Bug 4922099
20560    --
20561    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20562         (NVL(l_actual_upg_option, 'N') = 'O') OR
20563         (NVL(l_enc_upg_option, 'N') = 'O')
20564       )
20565    THEN
20566    NULL;
20567    --
20568    --
20569    
20570   l_ccid := AcctDerRule_174(
20571            p_application_id           => p_application_id
20572          , p_ae_header_id             => l_ae_header_id 
20573 , p_source_3 => p_source_3
20574 , p_source_17 => p_source_17
20575 , p_source_30 => p_source_30
20576          , x_transaction_coa_id       => l_adr_transaction_coa_id
20577          , x_accounting_coa_id        => l_adr_accounting_coa_id
20578          , x_value_type_code          => l_adr_value_type_code
20579          , p_side                     => 'NA'
20580    );
20581 
20582    xla_ae_lines_pkg.set_ccid(
20583     p_code_combination_id          => l_ccid
20584   , p_value_type_code              => l_adr_value_type_code
20585   , p_transaction_coa_id           => l_adr_transaction_coa_id
20586   , p_accounting_coa_id            => l_adr_accounting_coa_id
20587   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
20588   , p_adr_type_code                => 'S'
20589   , p_component_type               => l_component_type
20590   , p_component_code               => l_component_code
20591   , p_component_type_code          => l_component_type_code
20592   , p_component_appl_id            => l_component_appl_id
20593   , p_amb_context_code             => l_amb_context_code
20594   , p_side                         => 'NA'
20595   );
20596 
20597 
20598    l_segment := AcctDerRule_144(
20599            p_application_id           => p_application_id
20600          , p_ae_header_id             => l_ae_header_id 
20601 , p_source_3 => p_source_3
20602 , p_source_4 => p_source_4
20603          , x_transaction_coa_id       => l_adr_transaction_coa_id
20604          , x_accounting_coa_id        => l_adr_accounting_coa_id
20605          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
20606          , x_flex_value_set_id        => l_adr_flex_value_set_id
20607          , x_value_type_code          => l_adr_value_type_code
20608          , x_value_combination_id     => l_adr_value_combination_id
20609          , x_value_segment_code       => l_adr_value_segment_code
20610          , p_side                     => 'NA'
20611          , p_override_seg_flag        => 'Y'
20612    );
20613 
20617           p_to_segment_code         => 'GL_ACCOUNT'
20614    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
20615 
20616       xla_ae_lines_pkg.set_segment(
20618         , p_segment_value           => l_segment
20619         , p_from_segment_code       => l_adr_value_segment_code
20620         , p_from_combination_id     => l_adr_value_combination_id
20621         , p_value_type_code         => l_adr_value_type_code
20622         , p_transaction_coa_id      => l_adr_transaction_coa_id
20623         , p_accounting_coa_id       => l_adr_accounting_coa_id
20624         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
20625         , p_flex_value_set_id       => l_adr_flex_value_set_id
20626         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
20627         , p_adr_type_code           => 'S'
20628         , p_component_type          => l_component_type
20629         , p_component_code          => l_component_code
20630         , p_component_type_code     => l_component_type_code
20631         , p_component_appl_id       => l_component_appl_id
20632         , p_amb_context_code        => l_amb_context_code
20633         , p_entity_code             => 'TRANSACTIONS'
20634         , p_event_class_code        => 'ADDITIONS'
20635         , p_side                    => 'NA'
20636         );
20637 
20638   END IF;
20639 
20640    l_segment := AcctDerRule_168(
20641            p_application_id           => p_application_id
20642          , p_ae_header_id             => l_ae_header_id 
20643 , p_source_3 => p_source_3
20644 , p_source_29 => p_source_29
20645          , x_transaction_coa_id       => l_adr_transaction_coa_id
20646          , x_accounting_coa_id        => l_adr_accounting_coa_id
20647          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
20648          , x_flex_value_set_id        => l_adr_flex_value_set_id
20649          , x_value_type_code          => l_adr_value_type_code
20650          , x_value_combination_id     => l_adr_value_combination_id
20651          , x_value_segment_code       => l_adr_value_segment_code
20652          , p_side                     => 'NA'
20653          , p_override_seg_flag        => 'Y'
20654    );
20655 
20656    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
20657 
20658       xla_ae_lines_pkg.set_segment(
20659           p_to_segment_code         => 'GL_BALANCING'
20660         , p_segment_value           => l_segment
20661         , p_from_segment_code       => l_adr_value_segment_code
20662         , p_from_combination_id     => l_adr_value_combination_id
20663         , p_value_type_code         => l_adr_value_type_code
20664         , p_transaction_coa_id      => l_adr_transaction_coa_id
20665         , p_accounting_coa_id       => l_adr_accounting_coa_id
20666         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
20667         , p_flex_value_set_id       => l_adr_flex_value_set_id
20668         , p_adr_code                => 'FA_EXPENSE_ACCT'
20669         , p_adr_type_code           => 'S'
20670         , p_component_type          => l_component_type
20671         , p_component_code          => l_component_code
20672         , p_component_type_code     => l_component_type_code
20673         , p_component_appl_id       => l_component_appl_id
20674         , p_amb_context_code        => l_amb_context_code
20675         , p_entity_code             => 'TRANSACTIONS'
20676         , p_event_class_code        => 'ADDITIONS'
20677         , p_side                    => 'NA'
20678         );
20679 
20680   END IF;
20681 
20682    --
20683    --
20684    END IF;
20685 
20686        --
20687        -- Update the line information that should be overwritten
20688        --
20689        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
20690                                          p_header_num   => 1);
20691        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
20692 
20693        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
20694 
20695        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
20696           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
20697        END IF;
20698 
20699       --
20700       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
20701       --
20702       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
20703           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
20704       ELSE
20705           ---------------------------------------------------------------------------------------------------
20706           -- 4262811a Switch Sign
20707           ---------------------------------------------------------------------------------------------------
20708           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
20709           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20710                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20711           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20712                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20713           -- 5132302
20714           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
20715                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20716 
20717       END IF;
20718 
20719       -- 4955764
20720       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20721       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
20722 
20723 
20724       XLA_AE_LINES_PKG.ValidateCurrentLine;
20728                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
20725       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20726 
20727       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20729                ,p_balance_type_code => l_balance_type_code);
20730 
20731    END IF;
20732 
20733    -----------------------------------------------------------------------------------------
20734    -- 4262811 Multiperiod Accounting
20735    -----------------------------------------------------------------------------------------
20736      -- No MPA option is assigned.
20737 
20738 
20739 END IF;
20740 END IF;
20741 --
20742 
20743 --
20744 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20745    trace
20746       (p_msg      => 'END of AcctLineType_182'
20747       ,p_level    => C_LEVEL_PROCEDURE
20748       ,p_module   => l_log_module);
20749 END IF;
20750 --
20751 EXCEPTION
20752   WHEN xla_exceptions_pkg.application_exception THEN
20753       RAISE;
20754   WHEN OTHERS THEN
20755        xla_exceptions_pkg.raise_message
20756            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_182');
20757 END AcctLineType_182;
20758 --
20759 
20760 ---------------------------------------
20761 --
20762 -- PRIVATE FUNCTION
20763 --         AcctLineType_183
20764 --
20765 ---------------------------------------
20766 PROCEDURE AcctLineType_183 (
20767   p_application_id        IN NUMBER
20768  ,p_event_id              IN NUMBER
20769  ,p_calculate_acctd_flag  IN VARCHAR2
20770  ,p_calculate_g_l_flag    IN VARCHAR2
20771  ,p_actual_flag           IN OUT VARCHAR2
20772  ,p_balance_type_code     OUT VARCHAR2
20773  ,p_gain_or_loss_ref      OUT VARCHAR2
20774  
20775 --Period Close Date
20776  , p_source_1            IN DATE
20777 --Generated Code Combination Identifier
20778  , p_source_3            IN NUMBER
20779 --Asset Cost Account
20780  , p_source_9            IN VARCHAR2
20781 --Expense Account Code Combination Identifier
20782  , p_source_29            IN NUMBER
20783 --Default Code Combination Identifier
20784  , p_source_30            IN NUMBER
20785 --Adjustment Type
20786  , p_source_35            IN VARCHAR2
20787 --Transaction Header Identifier
20788  , p_source_36            IN NUMBER
20789 --Adjustment Line Identifier
20790  , p_source_37            IN NUMBER
20791 --Distribution Type Code
20792  , p_source_38            IN VARCHAR2
20793 --Entered Amount
20794  , p_source_39            IN NUMBER
20795 --Currency Code
20796  , p_source_40            IN VARCHAR2
20797 )
20798 IS
20799 
20800 l_component_type              VARCHAR2(80);
20801 l_component_code              VARCHAR2(30);
20802 l_component_type_code         VARCHAR2(1);
20803 l_component_appl_id           INTEGER;
20804 l_amb_context_code            VARCHAR2(30);
20805 l_entity_code                 VARCHAR2(30);
20806 l_event_class_code            VARCHAR2(30);
20807 l_ae_header_id                NUMBER;
20808 l_event_type_code             VARCHAR2(30);
20809 l_line_definition_code        VARCHAR2(30);
20810 l_line_definition_owner_code  VARCHAR2(1);
20811 --
20812 -- adr variables
20813 l_segment                     VARCHAR2(30);
20814 l_ccid                        NUMBER;
20815 l_adr_transaction_coa_id      NUMBER;
20816 l_adr_accounting_coa_id       NUMBER;
20817 l_adr_flexfield_segment_code  VARCHAR2(30);
20818 l_adr_flex_value_set_id       NUMBER;
20819 l_adr_value_type_code         VARCHAR2(30);
20820 l_adr_value_combination_id    NUMBER;
20821 l_adr_value_segment_code      VARCHAR2(30);
20822 
20823 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
20824 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
20825 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
20826 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
20827 
20828 -- 4262811 Variables ------------------------------------------------------------------------------------------
20829 l_entered_amt_idx             NUMBER;
20830 l_accted_amt_idx              NUMBER;
20831 l_acc_rev_flag                VARCHAR2(1);
20832 l_accrual_line_num            NUMBER;
20833 l_tmp_amt                     NUMBER;
20834 l_acc_rev_natural_side_code   VARCHAR2(1);
20835 
20836 l_num_entries                 NUMBER;
20837 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
20838 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
20839 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
20840 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
20841 l_recog_line_1                NUMBER;
20842 l_recog_line_2                NUMBER;
20843 
20844 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
20845 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
20846 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
20847 
20848 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
20849 
20850 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
20851 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
20852 
20853 ---------------------------------------------------------------------------------------------------------------
20854 
20855 
20856 --
20857 -- bulk performance
20858 --
20859 l_balance_type_code           VARCHAR2(1);
20860 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
20861 l_log_module                  VARCHAR2(240);
20862 
20863 --
20864 -- Upgrade strategy
20865 --
20866 l_actual_upg_option           VARCHAR2(1);
20867 l_enc_upg_option           VARCHAR2(1);
20868 
20869 --
20870 BEGIN
20874 END IF;
20871 --
20872 IF g_log_enabled THEN
20873       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_183';
20875 --
20876 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20877 
20878       trace
20879          (p_msg      => 'BEGIN of AcctLineType_183'
20880          ,p_level    => C_LEVEL_PROCEDURE
20881          ,p_module   => l_log_module);
20882 
20883 END IF;
20884 --
20885 l_component_type             := 'AMB_JLT';
20886 l_component_code             := 'FA_ADD_COST';
20887 l_component_type_code        := 'S';
20888 l_component_appl_id          :=  140;
20889 l_amb_context_code           := 'DEFAULT';
20890 l_entity_code                := 'TRANSACTIONS';
20891 l_event_class_code           := 'ADDITIONS';
20892 l_event_type_code            := 'ADDITIONS_ALL';
20893 l_line_definition_owner_code := 'S';
20894 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADDITI1';
20895 --
20896 l_balance_type_code          := 'A';
20897 l_segment                     := NULL;
20898 l_ccid                        := NULL;
20899 l_adr_transaction_coa_id      := NULL;
20900 l_adr_accounting_coa_id       := NULL;
20901 l_adr_flexfield_segment_code  := NULL;
20902 l_adr_flex_value_set_id       := NULL;
20903 l_adr_value_type_code         := NULL;
20904 l_adr_value_combination_id    := NULL;
20905 l_adr_value_segment_code      := NULL;
20906 
20907 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
20908 l_bflow_class_code           := '';    -- 4219869 Business Flow
20909 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
20910 l_budgetary_control_flag     := 'N';
20911 
20912 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
20913 l_bflow_applied_to_amt       := NULL; -- 5132302
20914 l_entered_amt_idx            := NULL;          -- 4262811
20915 l_accted_amt_idx             := NULL;          -- 4262811
20916 l_acc_rev_flag               := NULL;          -- 4262811
20917 l_accrual_line_num           := NULL;          -- 4262811
20918 l_tmp_amt                    := NULL;          -- 4262811
20919 --
20920  
20921 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
20922     l_balance_type_code <> 'B' THEN
20923 IF NVL(p_source_35,'
20924 ') =  'COST'
20925  THEN 
20926 
20927    --
20928    XLA_AE_LINES_PKG.SetNewLine;
20929 
20930    p_balance_type_code          := l_balance_type_code;
20931    -- set the flag so later we will know whether the gain loss line needs to be created
20932    
20933    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
20934      p_actual_flag :='A';
20935    END IF;
20936 
20937    --
20938    -- bulk performance
20939    --
20940    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
20941                                       p_header_num   => 0); -- 4262811
20942    --
20943    -- set accounting line options
20944    --
20945    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
20946            p_natural_side_code          => 'D'
20947          , p_gain_or_loss_flag          => 'N'
20948          , p_gl_transfer_mode_code      => 'S'
20949          , p_acct_entry_type_code       => 'A'
20950          , p_switch_side_flag           => 'Y'
20951          , p_merge_duplicate_code       => 'N'
20952          );
20953    --
20954    l_acc_rev_natural_side_code := 'C';  -- 4262811
20955    -- 
20956    --
20957    -- set accounting line type info
20958    --
20959    xla_ae_lines_pkg.SetAcctLineType
20960       (p_component_type             => l_component_type
20961       ,p_event_type_code            => l_event_type_code
20962       ,p_line_definition_owner_code => l_line_definition_owner_code
20963       ,p_line_definition_code       => l_line_definition_code
20964       ,p_accounting_line_code       => l_component_code
20965       ,p_accounting_line_type_code  => l_component_type_code
20966       ,p_accounting_line_appl_id    => l_component_appl_id
20967       ,p_amb_context_code           => l_amb_context_code
20968       ,p_entity_code                => l_entity_code
20969       ,p_event_class_code           => l_event_class_code);
20970    --
20971    -- set accounting class
20972    --
20973    xla_ae_lines_pkg.SetAcctClass(
20974            p_accounting_class_code  => 'ASSET'
20975          , p_ae_header_id           => l_ae_header_id
20976          );
20977 
20978    --
20979    -- set rounding class
20980    --
20981    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
20982                       'ASSET';
20983 
20984    --
20985    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
20986    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
20987    --
20988    -- bulk performance
20989    --
20990    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
20991 
20992    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
20993       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
20994 
20995    -- 4955764
20996    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20997       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
20998 
20999    -- 4458381 Public Sector Enh
21000    
21001    --
21002    -- set accounting attributes for the line type
21003    --
21004    l_entered_amt_idx := 4;
21005    l_accted_amt_idx  := 6;
21006    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
21007    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
21008    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
21009    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
21013    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
21010    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
21011    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
21012    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
21014    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
21015    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
21016    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
21017    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
21018    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
21019 
21020    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
21021    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
21022 
21023    ---------------------------------------------------------------------------------------------------------------
21024    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
21025    ---------------------------------------------------------------------------------------------------------------
21026    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
21027 
21028    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21029    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21030 
21031    IF xla_accounting_cache_pkg.GetValueChar
21032          (p_source_code         => 'LEDGER_CATEGORY_CODE'
21033          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
21034    AND l_bflow_method_code = 'PRIOR_ENTRY'
21035 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
21036    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
21037          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
21038        )
21039    THEN
21040          xla_ae_lines_pkg.BflowUpgEntry
21041            (p_business_method_code    => l_bflow_method_code
21042            ,p_business_class_code     => l_bflow_class_code
21043            ,p_balance_type            => l_balance_type_code);
21044    ELSE
21045       NULL;
21046 -- No business flow processing for business flow method of NONE.
21047    END IF;
21048 
21049    --
21050    -- call analytical criteria
21051    --
21052    
21053    --
21054    -- call description
21055    --
21056    
21057 xla_ae_lines_pkg.SetLineDescription(
21058    p_ae_header_id => l_ae_header_id
21059   ,p_description  => Description_4 (
21060      p_application_id         => p_application_id
21061    , p_ae_header_id           => l_ae_header_id 
21062 , p_source_1 => p_source_1
21063    )
21064 );
21065 
21066 
21067    --
21068    -- call ADRs
21069    -- Bug 4922099
21070    --
21071    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21072         (NVL(l_actual_upg_option, 'N') = 'O') OR
21073         (NVL(l_enc_upg_option, 'N') = 'O')
21074       )
21075    THEN
21076    NULL;
21077    --
21078    --
21079    
21080   l_ccid := AcctDerRule_173(
21081            p_application_id           => p_application_id
21082          , p_ae_header_id             => l_ae_header_id 
21083 , p_source_3 => p_source_3
21084 , p_source_30 => p_source_30
21085          , x_transaction_coa_id       => l_adr_transaction_coa_id
21086          , x_accounting_coa_id        => l_adr_accounting_coa_id
21087          , x_value_type_code          => l_adr_value_type_code
21088          , p_side                     => 'NA'
21089    );
21090 
21091    xla_ae_lines_pkg.set_ccid(
21092     p_code_combination_id          => l_ccid
21093   , p_value_type_code              => l_adr_value_type_code
21094   , p_transaction_coa_id           => l_adr_transaction_coa_id
21095   , p_accounting_coa_id            => l_adr_accounting_coa_id
21096   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
21097   , p_adr_type_code                => 'S'
21098   , p_component_type               => l_component_type
21099   , p_component_code               => l_component_code
21100   , p_component_type_code          => l_component_type_code
21101   , p_component_appl_id            => l_component_appl_id
21102   , p_amb_context_code             => l_amb_context_code
21103   , p_side                         => 'NA'
21104   );
21105 
21106 
21107    l_segment := AcctDerRule_148(
21108            p_application_id           => p_application_id
21109          , p_ae_header_id             => l_ae_header_id 
21110 , p_source_3 => p_source_3
21111 , p_source_9 => p_source_9
21112          , x_transaction_coa_id       => l_adr_transaction_coa_id
21113          , x_accounting_coa_id        => l_adr_accounting_coa_id
21114          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21115          , x_flex_value_set_id        => l_adr_flex_value_set_id
21116          , x_value_type_code          => l_adr_value_type_code
21117          , x_value_combination_id     => l_adr_value_combination_id
21118          , x_value_segment_code       => l_adr_value_segment_code
21119          , p_side                     => 'NA'
21120          , p_override_seg_flag        => 'Y'
21121    );
21122 
21123    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21124 
21125       xla_ae_lines_pkg.set_segment(
21126           p_to_segment_code         => 'GL_ACCOUNT'
21127         , p_segment_value           => l_segment
21128         , p_from_segment_code       => l_adr_value_segment_code
21129         , p_from_combination_id     => l_adr_value_combination_id
21130         , p_value_type_code         => l_adr_value_type_code
21131         , p_transaction_coa_id      => l_adr_transaction_coa_id
21132         , p_accounting_coa_id       => l_adr_accounting_coa_id
21133         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21137         , p_component_type          => l_component_type
21134         , p_flex_value_set_id       => l_adr_flex_value_set_id
21135         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
21136         , p_adr_type_code           => 'S'
21138         , p_component_code          => l_component_code
21139         , p_component_type_code     => l_component_type_code
21140         , p_component_appl_id       => l_component_appl_id
21141         , p_amb_context_code        => l_amb_context_code
21142         , p_entity_code             => 'TRANSACTIONS'
21143         , p_event_class_code        => 'ADDITIONS'
21144         , p_side                    => 'NA'
21145         );
21146 
21147   END IF;
21148 
21149    l_segment := AcctDerRule_168(
21150            p_application_id           => p_application_id
21151          , p_ae_header_id             => l_ae_header_id 
21152 , p_source_3 => p_source_3
21153 , p_source_29 => p_source_29
21154          , x_transaction_coa_id       => l_adr_transaction_coa_id
21155          , x_accounting_coa_id        => l_adr_accounting_coa_id
21156          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21157          , x_flex_value_set_id        => l_adr_flex_value_set_id
21158          , x_value_type_code          => l_adr_value_type_code
21159          , x_value_combination_id     => l_adr_value_combination_id
21160          , x_value_segment_code       => l_adr_value_segment_code
21161          , p_side                     => 'NA'
21162          , p_override_seg_flag        => 'Y'
21163    );
21164 
21165    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21166 
21167       xla_ae_lines_pkg.set_segment(
21168           p_to_segment_code         => 'GL_BALANCING'
21169         , p_segment_value           => l_segment
21170         , p_from_segment_code       => l_adr_value_segment_code
21171         , p_from_combination_id     => l_adr_value_combination_id
21172         , p_value_type_code         => l_adr_value_type_code
21173         , p_transaction_coa_id      => l_adr_transaction_coa_id
21174         , p_accounting_coa_id       => l_adr_accounting_coa_id
21175         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21176         , p_flex_value_set_id       => l_adr_flex_value_set_id
21177         , p_adr_code                => 'FA_EXPENSE_ACCT'
21178         , p_adr_type_code           => 'S'
21179         , p_component_type          => l_component_type
21180         , p_component_code          => l_component_code
21181         , p_component_type_code     => l_component_type_code
21182         , p_component_appl_id       => l_component_appl_id
21183         , p_amb_context_code        => l_amb_context_code
21184         , p_entity_code             => 'TRANSACTIONS'
21185         , p_event_class_code        => 'ADDITIONS'
21186         , p_side                    => 'NA'
21187         );
21188 
21189   END IF;
21190 
21191    --
21192    --
21193    END IF;
21194    --
21195    -- Bug 4922099
21196    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
21197           (NVL(l_enc_upg_option, 'N') = 'O')
21198         ) AND
21199         (l_bflow_method_code = 'PRIOR_ENTRY')
21200       )
21201    THEN
21202       IF
21203       --
21204       1 = 2
21205       --
21206       THEN
21207       xla_accounting_err_pkg.build_message
21208                                     (p_appli_s_name            => 'XLA'
21209                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21210                                     ,p_token_1                 => 'LINE_NUMBER'
21211                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
21212                                     ,p_token_2                 => 'LINE_TYPE_NAME'
21213                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
21214                                                                              l_component_type
21215                                                                             ,l_component_code
21216                                                                             ,l_component_type_code
21217                                                                             ,l_component_appl_id
21218                                                                             ,l_amb_context_code
21219                                                                             ,l_entity_code
21220                                                                             ,l_event_class_code
21221                                                                            )
21222                                     ,p_token_3                 => 'OWNER'
21223                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
21224                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
21225                                                                           ,p_lookup_code    => l_component_type_code
21226                                                                          )
21227                                     ,p_token_4                 => 'PRODUCT_NAME'
21228                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
21229                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
21230                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
21231                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
21232                                     ,p_ae_header_id            =>  NULL
21233                                        );
21234 
21235         IF (C_LEVEL_ERROR>= g_log_level) THEN
21236                  trace
21237                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21238                       ,p_level    => C_LEVEL_ERROR
21242    END IF;
21239                       ,p_module   => l_log_module);
21240         END IF;
21241       END IF;
21243    --
21244    --
21245    ------------------------------------------------------------------------------------------------
21246    -- 4219869 Business Flow
21247    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
21248    -- Prior Entry.  Currently, the following code is always generated.
21249    ------------------------------------------------------------------------------------------------
21250    XLA_AE_LINES_PKG.ValidateCurrentLine;
21251 
21252    ------------------------------------------------------------------------------------
21253    -- 4219869 Business Flow
21254    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
21255    ------------------------------------------------------------------------------------
21256    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21257 
21258    ----------------------------------------------------------------------------------
21259    -- 4219869 Business Flow
21260    -- Update journal entry status -- Need to generate this within IF <condition>
21261    ----------------------------------------------------------------------------------
21262    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
21263          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
21264          ,p_balance_type_code => l_balance_type_code
21265          );
21266 
21267    -------------------------------------------------------------------------------------------
21268    -- 4262811 - Generate the Accrual Reversal lines
21269    -------------------------------------------------------------------------------------------
21270    BEGIN
21271       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
21272                               (g_array_event(p_event_id).array_value_num('header_index'));
21273       IF l_acc_rev_flag IS NULL THEN
21274          l_acc_rev_flag := 'N';
21275       END IF;
21276    EXCEPTION
21277       WHEN OTHERS THEN
21278          l_acc_rev_flag := 'N';
21279    END;
21280    --
21281    IF (l_acc_rev_flag = 'Y') THEN
21282 
21283        -- 4645092  ------------------------------------------------------------------------------
21284        -- To allow MPA report to determine if it should generate report process
21285        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
21286        ------------------------------------------------------------------------------------------
21287 
21288        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
21289        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
21290    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
21291    -- call ADRs
21292    -- Bug 4922099
21293    --
21294    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21295         (NVL(l_actual_upg_option, 'N') = 'O') OR
21296         (NVL(l_enc_upg_option, 'N') = 'O')
21297       )
21298    THEN
21299    NULL;
21300    --
21301    --
21302    
21303   l_ccid := AcctDerRule_173(
21304            p_application_id           => p_application_id
21305          , p_ae_header_id             => l_ae_header_id 
21306 , p_source_3 => p_source_3
21307 , p_source_30 => p_source_30
21308          , x_transaction_coa_id       => l_adr_transaction_coa_id
21309          , x_accounting_coa_id        => l_adr_accounting_coa_id
21310          , x_value_type_code          => l_adr_value_type_code
21311          , p_side                     => 'NA'
21312    );
21313 
21314    xla_ae_lines_pkg.set_ccid(
21315     p_code_combination_id          => l_ccid
21316   , p_value_type_code              => l_adr_value_type_code
21317   , p_transaction_coa_id           => l_adr_transaction_coa_id
21318   , p_accounting_coa_id            => l_adr_accounting_coa_id
21319   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
21320   , p_adr_type_code                => 'S'
21321   , p_component_type               => l_component_type
21322   , p_component_code               => l_component_code
21323   , p_component_type_code          => l_component_type_code
21324   , p_component_appl_id            => l_component_appl_id
21325   , p_amb_context_code             => l_amb_context_code
21326   , p_side                         => 'NA'
21327   );
21328 
21329 
21330    l_segment := AcctDerRule_148(
21331            p_application_id           => p_application_id
21332          , p_ae_header_id             => l_ae_header_id 
21333 , p_source_3 => p_source_3
21334 , p_source_9 => p_source_9
21335          , x_transaction_coa_id       => l_adr_transaction_coa_id
21336          , x_accounting_coa_id        => l_adr_accounting_coa_id
21337          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21338          , x_flex_value_set_id        => l_adr_flex_value_set_id
21339          , x_value_type_code          => l_adr_value_type_code
21340          , x_value_combination_id     => l_adr_value_combination_id
21341          , x_value_segment_code       => l_adr_value_segment_code
21342          , p_side                     => 'NA'
21343          , p_override_seg_flag        => 'Y'
21344    );
21345 
21346    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21347 
21348       xla_ae_lines_pkg.set_segment(
21349           p_to_segment_code         => 'GL_ACCOUNT'
21350         , p_segment_value           => l_segment
21351         , p_from_segment_code       => l_adr_value_segment_code
21352         , p_from_combination_id     => l_adr_value_combination_id
21353         , p_value_type_code         => l_adr_value_type_code
21354         , p_transaction_coa_id      => l_adr_transaction_coa_id
21355         , p_accounting_coa_id       => l_adr_accounting_coa_id
21356         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21357         , p_flex_value_set_id       => l_adr_flex_value_set_id
21361         , p_component_code          => l_component_code
21358         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
21359         , p_adr_type_code           => 'S'
21360         , p_component_type          => l_component_type
21362         , p_component_type_code     => l_component_type_code
21363         , p_component_appl_id       => l_component_appl_id
21364         , p_amb_context_code        => l_amb_context_code
21365         , p_entity_code             => 'TRANSACTIONS'
21366         , p_event_class_code        => 'ADDITIONS'
21367         , p_side                    => 'NA'
21368         );
21369 
21370   END IF;
21371 
21372    l_segment := AcctDerRule_168(
21373            p_application_id           => p_application_id
21374          , p_ae_header_id             => l_ae_header_id 
21375 , p_source_3 => p_source_3
21376 , p_source_29 => p_source_29
21377          , x_transaction_coa_id       => l_adr_transaction_coa_id
21378          , x_accounting_coa_id        => l_adr_accounting_coa_id
21379          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21380          , x_flex_value_set_id        => l_adr_flex_value_set_id
21381          , x_value_type_code          => l_adr_value_type_code
21382          , x_value_combination_id     => l_adr_value_combination_id
21383          , x_value_segment_code       => l_adr_value_segment_code
21384          , p_side                     => 'NA'
21385          , p_override_seg_flag        => 'Y'
21386    );
21387 
21388    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21389 
21390       xla_ae_lines_pkg.set_segment(
21391           p_to_segment_code         => 'GL_BALANCING'
21392         , p_segment_value           => l_segment
21393         , p_from_segment_code       => l_adr_value_segment_code
21394         , p_from_combination_id     => l_adr_value_combination_id
21395         , p_value_type_code         => l_adr_value_type_code
21396         , p_transaction_coa_id      => l_adr_transaction_coa_id
21397         , p_accounting_coa_id       => l_adr_accounting_coa_id
21398         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21399         , p_flex_value_set_id       => l_adr_flex_value_set_id
21400         , p_adr_code                => 'FA_EXPENSE_ACCT'
21401         , p_adr_type_code           => 'S'
21402         , p_component_type          => l_component_type
21403         , p_component_code          => l_component_code
21404         , p_component_type_code     => l_component_type_code
21405         , p_component_appl_id       => l_component_appl_id
21406         , p_amb_context_code        => l_amb_context_code
21407         , p_entity_code             => 'TRANSACTIONS'
21408         , p_event_class_code        => 'ADDITIONS'
21409         , p_side                    => 'NA'
21410         );
21411 
21412   END IF;
21413 
21414    --
21415    --
21416    END IF;
21417 
21418        --
21419        -- Update the line information that should be overwritten
21420        --
21421        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
21422                                          p_header_num   => 1);
21423        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
21424 
21425        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
21426 
21427        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
21428           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
21429        END IF;
21430 
21431       --
21432       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
21433       --
21434       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
21435           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
21436       ELSE
21437           ---------------------------------------------------------------------------------------------------
21438           -- 4262811a Switch Sign
21439           ---------------------------------------------------------------------------------------------------
21440           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
21441           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
21442                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21443           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
21444                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21445           -- 5132302
21446           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
21447                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21448 
21449       END IF;
21450 
21451       -- 4955764
21452       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
21453       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
21454 
21455 
21456       XLA_AE_LINES_PKG.ValidateCurrentLine;
21457       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21458 
21459       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
21460                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
21461                ,p_balance_type_code => l_balance_type_code);
21462 
21463    END IF;
21464 
21465    -----------------------------------------------------------------------------------------
21466    -- 4262811 Multiperiod Accounting
21467    -----------------------------------------------------------------------------------------
21468      -- No MPA option is assigned.
21469 
21470 
21471 END IF;
21472 END IF;
21473 --
21474 
21478       (p_msg      => 'END of AcctLineType_183'
21475 --
21476 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
21477    trace
21479       ,p_level    => C_LEVEL_PROCEDURE
21480       ,p_module   => l_log_module);
21481 END IF;
21482 --
21483 EXCEPTION
21484   WHEN xla_exceptions_pkg.application_exception THEN
21485       RAISE;
21486   WHEN OTHERS THEN
21487        xla_exceptions_pkg.raise_message
21488            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_183');
21489 END AcctLineType_183;
21490 --
21491 
21492 ---------------------------------------
21493 --
21494 -- PRIVATE FUNCTION
21495 --         AcctLineType_184
21496 --
21497 ---------------------------------------
21498 PROCEDURE AcctLineType_184 (
21499   p_application_id        IN NUMBER
21500  ,p_event_id              IN NUMBER
21501  ,p_calculate_acctd_flag  IN VARCHAR2
21502  ,p_calculate_g_l_flag    IN VARCHAR2
21503  ,p_actual_flag           IN OUT VARCHAR2
21504  ,p_balance_type_code     OUT VARCHAR2
21505  ,p_gain_or_loss_ref      OUT VARCHAR2
21506  
21507 --Period Close Date
21508  , p_source_1            IN DATE
21509 --Generated Code Combination Identifier
21510  , p_source_3            IN NUMBER
21511 --Payables Code Combination Identifier
21512  , p_source_6            IN NUMBER
21513 --Asset Clearing Account
21514  , p_source_8            IN VARCHAR2
21515 --Expense Account Code Combination Identifier
21516  , p_source_29            IN NUMBER
21517 --Default Code Combination Identifier
21518  , p_source_30            IN NUMBER
21519 --Adjustment Type
21520  , p_source_35            IN VARCHAR2
21521 --Transaction Header Identifier
21522  , p_source_36            IN NUMBER
21523 --Adjustment Line Identifier
21524  , p_source_37            IN NUMBER
21525 --Distribution Type Code
21526  , p_source_38            IN VARCHAR2
21527 --Entered Amount
21528  , p_source_39            IN NUMBER
21529 --Currency Code
21530  , p_source_40            IN VARCHAR2
21531 )
21532 IS
21533 
21534 l_component_type              VARCHAR2(80);
21535 l_component_code              VARCHAR2(30);
21536 l_component_type_code         VARCHAR2(1);
21537 l_component_appl_id           INTEGER;
21538 l_amb_context_code            VARCHAR2(30);
21539 l_entity_code                 VARCHAR2(30);
21540 l_event_class_code            VARCHAR2(30);
21541 l_ae_header_id                NUMBER;
21542 l_event_type_code             VARCHAR2(30);
21543 l_line_definition_code        VARCHAR2(30);
21544 l_line_definition_owner_code  VARCHAR2(1);
21545 --
21546 -- adr variables
21547 l_segment                     VARCHAR2(30);
21548 l_ccid                        NUMBER;
21549 l_adr_transaction_coa_id      NUMBER;
21550 l_adr_accounting_coa_id       NUMBER;
21551 l_adr_flexfield_segment_code  VARCHAR2(30);
21552 l_adr_flex_value_set_id       NUMBER;
21553 l_adr_value_type_code         VARCHAR2(30);
21554 l_adr_value_combination_id    NUMBER;
21555 l_adr_value_segment_code      VARCHAR2(30);
21556 
21557 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
21558 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
21559 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
21560 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
21561 
21562 -- 4262811 Variables ------------------------------------------------------------------------------------------
21563 l_entered_amt_idx             NUMBER;
21564 l_accted_amt_idx              NUMBER;
21565 l_acc_rev_flag                VARCHAR2(1);
21566 l_accrual_line_num            NUMBER;
21567 l_tmp_amt                     NUMBER;
21568 l_acc_rev_natural_side_code   VARCHAR2(1);
21569 
21570 l_num_entries                 NUMBER;
21571 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
21572 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
21573 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
21574 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
21575 l_recog_line_1                NUMBER;
21576 l_recog_line_2                NUMBER;
21577 
21578 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
21579 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
21580 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
21581 
21582 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
21583 
21584 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
21585 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
21586 
21587 ---------------------------------------------------------------------------------------------------------------
21588 
21589 
21590 --
21591 -- bulk performance
21592 --
21593 l_balance_type_code           VARCHAR2(1);
21594 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
21595 l_log_module                  VARCHAR2(240);
21596 
21597 --
21598 -- Upgrade strategy
21599 --
21600 l_actual_upg_option           VARCHAR2(1);
21601 l_enc_upg_option           VARCHAR2(1);
21602 
21603 --
21604 BEGIN
21605 --
21606 IF g_log_enabled THEN
21607       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_184';
21608 END IF;
21609 --
21610 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
21611 
21612       trace
21613          (p_msg      => 'BEGIN of AcctLineType_184'
21614          ,p_level    => C_LEVEL_PROCEDURE
21615          ,p_module   => l_log_module);
21616 
21617 END IF;
21618 --
21619 l_component_type             := 'AMB_JLT';
21620 l_component_code             := 'FA_ADD_COST_CLEARING';
21621 l_component_type_code        := 'S';
21625 l_event_class_code           := 'ADDITIONS';
21622 l_component_appl_id          :=  140;
21623 l_amb_context_code           := 'DEFAULT';
21624 l_entity_code                := 'TRANSACTIONS';
21626 l_event_type_code            := 'ADDITIONS_ALL';
21627 l_line_definition_owner_code := 'S';
21628 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADDITI1';
21629 --
21630 l_balance_type_code          := 'A';
21631 l_segment                     := NULL;
21632 l_ccid                        := NULL;
21633 l_adr_transaction_coa_id      := NULL;
21634 l_adr_accounting_coa_id       := NULL;
21635 l_adr_flexfield_segment_code  := NULL;
21636 l_adr_flex_value_set_id       := NULL;
21637 l_adr_value_type_code         := NULL;
21638 l_adr_value_combination_id    := NULL;
21639 l_adr_value_segment_code      := NULL;
21640 
21641 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
21642 l_bflow_class_code           := '';    -- 4219869 Business Flow
21643 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
21644 l_budgetary_control_flag     := 'N';
21645 
21646 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
21647 l_bflow_applied_to_amt       := NULL; -- 5132302
21648 l_entered_amt_idx            := NULL;          -- 4262811
21649 l_accted_amt_idx             := NULL;          -- 4262811
21650 l_acc_rev_flag               := NULL;          -- 4262811
21651 l_accrual_line_num           := NULL;          -- 4262811
21652 l_tmp_amt                    := NULL;          -- 4262811
21653 --
21654  
21655 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
21656     l_balance_type_code <> 'B' THEN
21657 IF NVL(p_source_35,'
21658 ') =  'COST CLEARING'
21659  THEN 
21660 
21661    --
21662    XLA_AE_LINES_PKG.SetNewLine;
21663 
21664    p_balance_type_code          := l_balance_type_code;
21665    -- set the flag so later we will know whether the gain loss line needs to be created
21666    
21667    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
21668      p_actual_flag :='A';
21669    END IF;
21670 
21671    --
21672    -- bulk performance
21673    --
21674    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
21675                                       p_header_num   => 0); -- 4262811
21676    --
21677    -- set accounting line options
21678    --
21679    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
21680            p_natural_side_code          => 'C'
21681          , p_gain_or_loss_flag          => 'N'
21682          , p_gl_transfer_mode_code      => 'S'
21683          , p_acct_entry_type_code       => 'A'
21684          , p_switch_side_flag           => 'Y'
21685          , p_merge_duplicate_code       => 'N'
21686          );
21687    --
21688    l_acc_rev_natural_side_code := 'D';  -- 4262811
21689    -- 
21690    --
21691    -- set accounting line type info
21692    --
21693    xla_ae_lines_pkg.SetAcctLineType
21694       (p_component_type             => l_component_type
21695       ,p_event_type_code            => l_event_type_code
21696       ,p_line_definition_owner_code => l_line_definition_owner_code
21697       ,p_line_definition_code       => l_line_definition_code
21698       ,p_accounting_line_code       => l_component_code
21699       ,p_accounting_line_type_code  => l_component_type_code
21700       ,p_accounting_line_appl_id    => l_component_appl_id
21701       ,p_amb_context_code           => l_amb_context_code
21702       ,p_entity_code                => l_entity_code
21703       ,p_event_class_code           => l_event_class_code);
21704    --
21705    -- set accounting class
21706    --
21707    xla_ae_lines_pkg.SetAcctClass(
21708            p_accounting_class_code  => 'ASSET'
21709          , p_ae_header_id           => l_ae_header_id
21710          );
21711 
21712    --
21713    -- set rounding class
21714    --
21715    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
21716                       'ASSET';
21717 
21718    --
21719    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
21720    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
21721    --
21722    -- bulk performance
21723    --
21724    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
21725 
21726    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
21727       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
21728 
21729    -- 4955764
21730    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
21731       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
21732 
21733    -- 4458381 Public Sector Enh
21734    
21735    --
21736    -- set accounting attributes for the line type
21737    --
21738    l_entered_amt_idx := 4;
21739    l_accted_amt_idx  := 6;
21740    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
21741    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
21742    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
21743    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
21744    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
21745    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
21746    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
21747    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
21748    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
21749    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
21750    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
21751    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
21755    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
21752    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
21753 
21754    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
21756 
21757    ---------------------------------------------------------------------------------------------------------------
21758    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
21759    ---------------------------------------------------------------------------------------------------------------
21760    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
21761 
21762    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21763    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21764 
21765    IF xla_accounting_cache_pkg.GetValueChar
21766          (p_source_code         => 'LEDGER_CATEGORY_CODE'
21767          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
21768    AND l_bflow_method_code = 'PRIOR_ENTRY'
21769 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
21770    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
21771          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
21772        )
21773    THEN
21774          xla_ae_lines_pkg.BflowUpgEntry
21775            (p_business_method_code    => l_bflow_method_code
21776            ,p_business_class_code     => l_bflow_class_code
21777            ,p_balance_type            => l_balance_type_code);
21778    ELSE
21779       NULL;
21780 -- No business flow processing for business flow method of NONE.
21781    END IF;
21782 
21783    --
21784    -- call analytical criteria
21785    --
21786    
21787    --
21788    -- call description
21789    --
21790    
21791 xla_ae_lines_pkg.SetLineDescription(
21792    p_ae_header_id => l_ae_header_id
21793   ,p_description  => Description_5 (
21794      p_application_id         => p_application_id
21795    , p_ae_header_id           => l_ae_header_id 
21796 , p_source_1 => p_source_1
21797    )
21798 );
21799 
21800 
21801    --
21802    -- call ADRs
21803    -- Bug 4922099
21804    --
21805    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21806         (NVL(l_actual_upg_option, 'N') = 'O') OR
21807         (NVL(l_enc_upg_option, 'N') = 'O')
21808       )
21809    THEN
21810    NULL;
21811    --
21812    --
21813    
21814   l_ccid := AcctDerRule_172(
21815            p_application_id           => p_application_id
21816          , p_ae_header_id             => l_ae_header_id 
21817 , p_source_3 => p_source_3
21818 , p_source_6 => p_source_6
21819 , p_source_30 => p_source_30
21820          , x_transaction_coa_id       => l_adr_transaction_coa_id
21821          , x_accounting_coa_id        => l_adr_accounting_coa_id
21822          , x_value_type_code          => l_adr_value_type_code
21823          , p_side                     => 'NA'
21824    );
21825 
21826    xla_ae_lines_pkg.set_ccid(
21827     p_code_combination_id          => l_ccid
21828   , p_value_type_code              => l_adr_value_type_code
21829   , p_transaction_coa_id           => l_adr_transaction_coa_id
21830   , p_accounting_coa_id            => l_adr_accounting_coa_id
21831   , p_adr_code                     => 'FA_CAT_COST_CLEARING'
21832   , p_adr_type_code                => 'S'
21833   , p_component_type               => l_component_type
21834   , p_component_code               => l_component_code
21835   , p_component_type_code          => l_component_type_code
21836   , p_component_appl_id            => l_component_appl_id
21837   , p_amb_context_code             => l_amb_context_code
21838   , p_side                         => 'NA'
21839   );
21840 
21841 
21842    l_segment := AcctDerRule_147(
21843            p_application_id           => p_application_id
21844          , p_ae_header_id             => l_ae_header_id 
21845 , p_source_3 => p_source_3
21846 , p_source_6 => p_source_6
21847 , p_source_8 => p_source_8
21848          , x_transaction_coa_id       => l_adr_transaction_coa_id
21849          , x_accounting_coa_id        => l_adr_accounting_coa_id
21850          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21851          , x_flex_value_set_id        => l_adr_flex_value_set_id
21852          , x_value_type_code          => l_adr_value_type_code
21853          , x_value_combination_id     => l_adr_value_combination_id
21854          , x_value_segment_code       => l_adr_value_segment_code
21855          , p_side                     => 'NA'
21856          , p_override_seg_flag        => 'Y'
21857    );
21858 
21859    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21860 
21861       xla_ae_lines_pkg.set_segment(
21862           p_to_segment_code         => 'GL_ACCOUNT'
21863         , p_segment_value           => l_segment
21864         , p_from_segment_code       => l_adr_value_segment_code
21865         , p_from_combination_id     => l_adr_value_combination_id
21866         , p_value_type_code         => l_adr_value_type_code
21867         , p_transaction_coa_id      => l_adr_transaction_coa_id
21868         , p_accounting_coa_id       => l_adr_accounting_coa_id
21869         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21870         , p_flex_value_set_id       => l_adr_flex_value_set_id
21871         , p_adr_code                => 'FA_CAT_CLR_ACCOUNT_SEGMENT'
21872         , p_adr_type_code           => 'S'
21873         , p_component_type          => l_component_type
21874         , p_component_code          => l_component_code
21875         , p_component_type_code     => l_component_type_code
21876         , p_component_appl_id       => l_component_appl_id
21877         , p_amb_context_code        => l_amb_context_code
21881         );
21878         , p_entity_code             => 'TRANSACTIONS'
21879         , p_event_class_code        => 'ADDITIONS'
21880         , p_side                    => 'NA'
21882 
21883   END IF;
21884 
21885    l_segment := AcctDerRule_169(
21886            p_application_id           => p_application_id
21887          , p_ae_header_id             => l_ae_header_id 
21888 , p_source_3 => p_source_3
21889 , p_source_6 => p_source_6
21890 , p_source_29 => p_source_29
21891          , x_transaction_coa_id       => l_adr_transaction_coa_id
21892          , x_accounting_coa_id        => l_adr_accounting_coa_id
21893          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21894          , x_flex_value_set_id        => l_adr_flex_value_set_id
21895          , x_value_type_code          => l_adr_value_type_code
21896          , x_value_combination_id     => l_adr_value_combination_id
21897          , x_value_segment_code       => l_adr_value_segment_code
21898          , p_side                     => 'NA'
21899          , p_override_seg_flag        => 'Y'
21900    );
21901 
21902    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21903 
21904       xla_ae_lines_pkg.set_segment(
21905           p_to_segment_code         => 'GL_BALANCING'
21906         , p_segment_value           => l_segment
21907         , p_from_segment_code       => l_adr_value_segment_code
21908         , p_from_combination_id     => l_adr_value_combination_id
21909         , p_value_type_code         => l_adr_value_type_code
21910         , p_transaction_coa_id      => l_adr_transaction_coa_id
21911         , p_accounting_coa_id       => l_adr_accounting_coa_id
21912         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21913         , p_flex_value_set_id       => l_adr_flex_value_set_id
21914         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
21915         , p_adr_type_code           => 'S'
21916         , p_component_type          => l_component_type
21917         , p_component_code          => l_component_code
21918         , p_component_type_code     => l_component_type_code
21919         , p_component_appl_id       => l_component_appl_id
21920         , p_amb_context_code        => l_amb_context_code
21921         , p_entity_code             => 'TRANSACTIONS'
21922         , p_event_class_code        => 'ADDITIONS'
21923         , p_side                    => 'NA'
21924         );
21925 
21926   END IF;
21927 
21928    --
21929    --
21930    END IF;
21931    --
21932    -- Bug 4922099
21933    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
21934           (NVL(l_enc_upg_option, 'N') = 'O')
21935         ) AND
21936         (l_bflow_method_code = 'PRIOR_ENTRY')
21937       )
21938    THEN
21939       IF
21940       --
21941       1 = 2
21942       --
21943       THEN
21944       xla_accounting_err_pkg.build_message
21945                                     (p_appli_s_name            => 'XLA'
21946                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21947                                     ,p_token_1                 => 'LINE_NUMBER'
21948                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
21949                                     ,p_token_2                 => 'LINE_TYPE_NAME'
21950                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
21951                                                                              l_component_type
21952                                                                             ,l_component_code
21953                                                                             ,l_component_type_code
21954                                                                             ,l_component_appl_id
21955                                                                             ,l_amb_context_code
21956                                                                             ,l_entity_code
21957                                                                             ,l_event_class_code
21958                                                                            )
21959                                     ,p_token_3                 => 'OWNER'
21960                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
21961                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
21962                                                                           ,p_lookup_code    => l_component_type_code
21963                                                                          )
21964                                     ,p_token_4                 => 'PRODUCT_NAME'
21965                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
21966                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
21967                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
21968                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
21969                                     ,p_ae_header_id            =>  NULL
21970                                        );
21971 
21972         IF (C_LEVEL_ERROR>= g_log_level) THEN
21973                  trace
21974                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21975                       ,p_level    => C_LEVEL_ERROR
21976                       ,p_module   => l_log_module);
21977         END IF;
21978       END IF;
21979    END IF;
21980    --
21981    --
21982    ------------------------------------------------------------------------------------------------
21983    -- 4219869 Business Flow
21984    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
21985    -- Prior Entry.  Currently, the following code is always generated.
21989    ------------------------------------------------------------------------------------
21986    ------------------------------------------------------------------------------------------------
21987    XLA_AE_LINES_PKG.ValidateCurrentLine;
21988 
21990    -- 4219869 Business Flow
21991    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
21992    ------------------------------------------------------------------------------------
21993    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21994 
21995    ----------------------------------------------------------------------------------
21996    -- 4219869 Business Flow
21997    -- Update journal entry status -- Need to generate this within IF <condition>
21998    ----------------------------------------------------------------------------------
21999    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22000          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
22001          ,p_balance_type_code => l_balance_type_code
22002          );
22003 
22004    -------------------------------------------------------------------------------------------
22005    -- 4262811 - Generate the Accrual Reversal lines
22006    -------------------------------------------------------------------------------------------
22007    BEGIN
22008       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
22009                               (g_array_event(p_event_id).array_value_num('header_index'));
22010       IF l_acc_rev_flag IS NULL THEN
22011          l_acc_rev_flag := 'N';
22012       END IF;
22013    EXCEPTION
22014       WHEN OTHERS THEN
22015          l_acc_rev_flag := 'N';
22016    END;
22017    --
22018    IF (l_acc_rev_flag = 'Y') THEN
22019 
22020        -- 4645092  ------------------------------------------------------------------------------
22021        -- To allow MPA report to determine if it should generate report process
22022        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
22023        ------------------------------------------------------------------------------------------
22024 
22025        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
22026        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
22027    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
22028    -- call ADRs
22029    -- Bug 4922099
22030    --
22031    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
22032         (NVL(l_actual_upg_option, 'N') = 'O') OR
22033         (NVL(l_enc_upg_option, 'N') = 'O')
22034       )
22035    THEN
22036    NULL;
22037    --
22038    --
22039    
22040   l_ccid := AcctDerRule_172(
22041            p_application_id           => p_application_id
22042          , p_ae_header_id             => l_ae_header_id 
22043 , p_source_3 => p_source_3
22044 , p_source_6 => p_source_6
22045 , p_source_30 => p_source_30
22046          , x_transaction_coa_id       => l_adr_transaction_coa_id
22047          , x_accounting_coa_id        => l_adr_accounting_coa_id
22048          , x_value_type_code          => l_adr_value_type_code
22049          , p_side                     => 'NA'
22050    );
22051 
22052    xla_ae_lines_pkg.set_ccid(
22053     p_code_combination_id          => l_ccid
22054   , p_value_type_code              => l_adr_value_type_code
22055   , p_transaction_coa_id           => l_adr_transaction_coa_id
22056   , p_accounting_coa_id            => l_adr_accounting_coa_id
22057   , p_adr_code                     => 'FA_CAT_COST_CLEARING'
22058   , p_adr_type_code                => 'S'
22059   , p_component_type               => l_component_type
22060   , p_component_code               => l_component_code
22061   , p_component_type_code          => l_component_type_code
22062   , p_component_appl_id            => l_component_appl_id
22063   , p_amb_context_code             => l_amb_context_code
22064   , p_side                         => 'NA'
22065   );
22066 
22067 
22068    l_segment := AcctDerRule_147(
22069            p_application_id           => p_application_id
22070          , p_ae_header_id             => l_ae_header_id 
22071 , p_source_3 => p_source_3
22072 , p_source_6 => p_source_6
22073 , p_source_8 => p_source_8
22074          , x_transaction_coa_id       => l_adr_transaction_coa_id
22075          , x_accounting_coa_id        => l_adr_accounting_coa_id
22076          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22077          , x_flex_value_set_id        => l_adr_flex_value_set_id
22078          , x_value_type_code          => l_adr_value_type_code
22079          , x_value_combination_id     => l_adr_value_combination_id
22080          , x_value_segment_code       => l_adr_value_segment_code
22081          , p_side                     => 'NA'
22082          , p_override_seg_flag        => 'Y'
22083    );
22084 
22085    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22086 
22087       xla_ae_lines_pkg.set_segment(
22088           p_to_segment_code         => 'GL_ACCOUNT'
22089         , p_segment_value           => l_segment
22090         , p_from_segment_code       => l_adr_value_segment_code
22091         , p_from_combination_id     => l_adr_value_combination_id
22092         , p_value_type_code         => l_adr_value_type_code
22093         , p_transaction_coa_id      => l_adr_transaction_coa_id
22094         , p_accounting_coa_id       => l_adr_accounting_coa_id
22095         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22096         , p_flex_value_set_id       => l_adr_flex_value_set_id
22097         , p_adr_code                => 'FA_CAT_CLR_ACCOUNT_SEGMENT'
22098         , p_adr_type_code           => 'S'
22099         , p_component_type          => l_component_type
22100         , p_component_code          => l_component_code
22101         , p_component_type_code     => l_component_type_code
22102         , p_component_appl_id       => l_component_appl_id
22103         , p_amb_context_code        => l_amb_context_code
22107         );
22104         , p_entity_code             => 'TRANSACTIONS'
22105         , p_event_class_code        => 'ADDITIONS'
22106         , p_side                    => 'NA'
22108 
22109   END IF;
22110 
22111    l_segment := AcctDerRule_169(
22112            p_application_id           => p_application_id
22113          , p_ae_header_id             => l_ae_header_id 
22114 , p_source_3 => p_source_3
22115 , p_source_6 => p_source_6
22116 , p_source_29 => p_source_29
22117          , x_transaction_coa_id       => l_adr_transaction_coa_id
22118          , x_accounting_coa_id        => l_adr_accounting_coa_id
22119          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22120          , x_flex_value_set_id        => l_adr_flex_value_set_id
22121          , x_value_type_code          => l_adr_value_type_code
22122          , x_value_combination_id     => l_adr_value_combination_id
22123          , x_value_segment_code       => l_adr_value_segment_code
22124          , p_side                     => 'NA'
22125          , p_override_seg_flag        => 'Y'
22126    );
22127 
22128    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22129 
22130       xla_ae_lines_pkg.set_segment(
22131           p_to_segment_code         => 'GL_BALANCING'
22132         , p_segment_value           => l_segment
22133         , p_from_segment_code       => l_adr_value_segment_code
22134         , p_from_combination_id     => l_adr_value_combination_id
22135         , p_value_type_code         => l_adr_value_type_code
22136         , p_transaction_coa_id      => l_adr_transaction_coa_id
22137         , p_accounting_coa_id       => l_adr_accounting_coa_id
22138         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22139         , p_flex_value_set_id       => l_adr_flex_value_set_id
22140         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
22141         , p_adr_type_code           => 'S'
22142         , p_component_type          => l_component_type
22143         , p_component_code          => l_component_code
22144         , p_component_type_code     => l_component_type_code
22145         , p_component_appl_id       => l_component_appl_id
22146         , p_amb_context_code        => l_amb_context_code
22147         , p_entity_code             => 'TRANSACTIONS'
22148         , p_event_class_code        => 'ADDITIONS'
22149         , p_side                    => 'NA'
22150         );
22151 
22152   END IF;
22153 
22154    --
22155    --
22156    END IF;
22157 
22158        --
22159        -- Update the line information that should be overwritten
22160        --
22161        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
22162                                          p_header_num   => 1);
22163        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
22164 
22165        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
22166 
22167        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
22168           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
22169        END IF;
22170 
22171       --
22172       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
22173       --
22174       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
22175           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
22176       ELSE
22177           ---------------------------------------------------------------------------------------------------
22178           -- 4262811a Switch Sign
22179           ---------------------------------------------------------------------------------------------------
22180           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
22181           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22182                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22183           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22184                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22185           -- 5132302
22186           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
22187                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22188 
22189       END IF;
22190 
22191       -- 4955764
22192       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
22193       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
22194 
22195 
22196       XLA_AE_LINES_PKG.ValidateCurrentLine;
22197       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
22198 
22199       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22200                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
22201                ,p_balance_type_code => l_balance_type_code);
22202 
22203    END IF;
22204 
22205    -----------------------------------------------------------------------------------------
22206    -- 4262811 Multiperiod Accounting
22207    -----------------------------------------------------------------------------------------
22208      -- No MPA option is assigned.
22209 
22210 
22211 END IF;
22212 END IF;
22213 --
22214 
22215 --
22216 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22217    trace
22218       (p_msg      => 'END of AcctLineType_184'
22219       ,p_level    => C_LEVEL_PROCEDURE
22220       ,p_module   => l_log_module);
22221 END IF;
22222 --
22223 EXCEPTION
22224   WHEN xla_exceptions_pkg.application_exception THEN
22225       RAISE;
22226   WHEN OTHERS THEN
22230 --
22227        xla_exceptions_pkg.raise_message
22228            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_184');
22229 END AcctLineType_184;
22231 
22232 ---------------------------------------
22233 --
22234 -- PRIVATE FUNCTION
22235 --         AcctLineType_185
22236 --
22237 ---------------------------------------
22238 PROCEDURE AcctLineType_185 (
22239   p_application_id        IN NUMBER
22240  ,p_event_id              IN NUMBER
22241  ,p_calculate_acctd_flag  IN VARCHAR2
22242  ,p_calculate_g_l_flag    IN VARCHAR2
22243  ,p_actual_flag           IN OUT VARCHAR2
22244  ,p_balance_type_code     OUT VARCHAR2
22245  ,p_gain_or_loss_ref      OUT VARCHAR2
22246  
22247 --Period Close Date
22248  , p_source_1            IN DATE
22249 --Generated Code Combination Identifier
22250  , p_source_3            IN NUMBER
22251 --Expense Account Code Combination Identifier
22252  , p_source_29            IN NUMBER
22253 --Adjustment Type
22254  , p_source_35            IN VARCHAR2
22255 --Transaction Header Identifier
22256  , p_source_36            IN NUMBER
22257 --Adjustment Line Identifier
22258  , p_source_37            IN NUMBER
22259 --Distribution Type Code
22260  , p_source_38            IN VARCHAR2
22261 --Entered Amount
22262  , p_source_39            IN NUMBER
22263 --Currency Code
22264  , p_source_40            IN VARCHAR2
22265 )
22266 IS
22267 
22268 l_component_type              VARCHAR2(80);
22269 l_component_code              VARCHAR2(30);
22270 l_component_type_code         VARCHAR2(1);
22271 l_component_appl_id           INTEGER;
22272 l_amb_context_code            VARCHAR2(30);
22273 l_entity_code                 VARCHAR2(30);
22274 l_event_class_code            VARCHAR2(30);
22275 l_ae_header_id                NUMBER;
22276 l_event_type_code             VARCHAR2(30);
22277 l_line_definition_code        VARCHAR2(30);
22278 l_line_definition_owner_code  VARCHAR2(1);
22279 --
22280 -- adr variables
22281 l_segment                     VARCHAR2(30);
22282 l_ccid                        NUMBER;
22283 l_adr_transaction_coa_id      NUMBER;
22284 l_adr_accounting_coa_id       NUMBER;
22285 l_adr_flexfield_segment_code  VARCHAR2(30);
22286 l_adr_flex_value_set_id       NUMBER;
22287 l_adr_value_type_code         VARCHAR2(30);
22288 l_adr_value_combination_id    NUMBER;
22289 l_adr_value_segment_code      VARCHAR2(30);
22290 
22291 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
22292 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
22293 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
22294 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
22295 
22296 -- 4262811 Variables ------------------------------------------------------------------------------------------
22297 l_entered_amt_idx             NUMBER;
22298 l_accted_amt_idx              NUMBER;
22299 l_acc_rev_flag                VARCHAR2(1);
22300 l_accrual_line_num            NUMBER;
22301 l_tmp_amt                     NUMBER;
22302 l_acc_rev_natural_side_code   VARCHAR2(1);
22303 
22304 l_num_entries                 NUMBER;
22305 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
22306 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
22307 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
22308 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
22309 l_recog_line_1                NUMBER;
22310 l_recog_line_2                NUMBER;
22311 
22312 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
22313 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
22314 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
22315 
22316 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
22317 
22318 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
22319 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
22320 
22321 ---------------------------------------------------------------------------------------------------------------
22322 
22323 
22324 --
22325 -- bulk performance
22326 --
22327 l_balance_type_code           VARCHAR2(1);
22328 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
22329 l_log_module                  VARCHAR2(240);
22330 
22331 --
22332 -- Upgrade strategy
22333 --
22334 l_actual_upg_option           VARCHAR2(1);
22335 l_enc_upg_option           VARCHAR2(1);
22336 
22337 --
22338 BEGIN
22339 --
22340 IF g_log_enabled THEN
22341       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_185';
22342 END IF;
22343 --
22344 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22345 
22346       trace
22347          (p_msg      => 'BEGIN of AcctLineType_185'
22348          ,p_level    => C_LEVEL_PROCEDURE
22349          ,p_module   => l_log_module);
22350 
22351 END IF;
22352 --
22353 l_component_type             := 'AMB_JLT';
22354 l_component_code             := 'FA_ADD_EXP';
22355 l_component_type_code        := 'S';
22356 l_component_appl_id          :=  140;
22357 l_amb_context_code           := 'DEFAULT';
22358 l_entity_code                := 'TRANSACTIONS';
22359 l_event_class_code           := 'ADDITIONS';
22360 l_event_type_code            := 'ADDITIONS_ALL';
22361 l_line_definition_owner_code := 'S';
22362 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADDITI1';
22363 --
22364 l_balance_type_code          := 'A';
22365 l_segment                     := NULL;
22366 l_ccid                        := NULL;
22367 l_adr_transaction_coa_id      := NULL;
22368 l_adr_accounting_coa_id       := NULL;
22369 l_adr_flexfield_segment_code  := NULL;
22370 l_adr_flex_value_set_id       := NULL;
22374 
22371 l_adr_value_type_code         := NULL;
22372 l_adr_value_combination_id    := NULL;
22373 l_adr_value_segment_code      := NULL;
22375 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
22376 l_bflow_class_code           := '';    -- 4219869 Business Flow
22377 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
22378 l_budgetary_control_flag     := 'N';
22379 
22380 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
22381 l_bflow_applied_to_amt       := NULL; -- 5132302
22382 l_entered_amt_idx            := NULL;          -- 4262811
22383 l_accted_amt_idx             := NULL;          -- 4262811
22384 l_acc_rev_flag               := NULL;          -- 4262811
22385 l_accrual_line_num           := NULL;          -- 4262811
22386 l_tmp_amt                    := NULL;          -- 4262811
22387 --
22388  
22389 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
22390     l_balance_type_code <> 'B' THEN
22391 IF NVL(p_source_35,'
22392 ') =  'EXPENSE'
22393  THEN 
22394 
22395    --
22396    XLA_AE_LINES_PKG.SetNewLine;
22397 
22398    p_balance_type_code          := l_balance_type_code;
22399    -- set the flag so later we will know whether the gain loss line needs to be created
22400    
22401    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
22402      p_actual_flag :='A';
22403    END IF;
22404 
22405    --
22406    -- bulk performance
22407    --
22408    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
22409                                       p_header_num   => 0); -- 4262811
22410    --
22411    -- set accounting line options
22412    --
22413    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
22414            p_natural_side_code          => 'D'
22415          , p_gain_or_loss_flag          => 'N'
22416          , p_gl_transfer_mode_code      => 'S'
22417          , p_acct_entry_type_code       => 'A'
22418          , p_switch_side_flag           => 'Y'
22419          , p_merge_duplicate_code       => 'N'
22420          );
22421    --
22422    l_acc_rev_natural_side_code := 'C';  -- 4262811
22423    -- 
22424    --
22425    -- set accounting line type info
22426    --
22427    xla_ae_lines_pkg.SetAcctLineType
22428       (p_component_type             => l_component_type
22429       ,p_event_type_code            => l_event_type_code
22430       ,p_line_definition_owner_code => l_line_definition_owner_code
22431       ,p_line_definition_code       => l_line_definition_code
22432       ,p_accounting_line_code       => l_component_code
22433       ,p_accounting_line_type_code  => l_component_type_code
22434       ,p_accounting_line_appl_id    => l_component_appl_id
22435       ,p_amb_context_code           => l_amb_context_code
22436       ,p_entity_code                => l_entity_code
22437       ,p_event_class_code           => l_event_class_code);
22438    --
22439    -- set accounting class
22440    --
22441    xla_ae_lines_pkg.SetAcctClass(
22442            p_accounting_class_code  => 'EXPENSE'
22443          , p_ae_header_id           => l_ae_header_id
22444          );
22445 
22446    --
22447    -- set rounding class
22448    --
22449    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
22450                       'EXPENSE';
22451 
22452    --
22453    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
22454    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
22455    --
22456    -- bulk performance
22457    --
22458    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
22459 
22460    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
22461       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
22462 
22463    -- 4955764
22464    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
22465       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
22466 
22467    -- 4458381 Public Sector Enh
22468    
22469    --
22470    -- set accounting attributes for the line type
22471    --
22472    l_entered_amt_idx := 4;
22473    l_accted_amt_idx  := 6;
22474    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
22475    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
22476    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
22477    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
22478    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
22479    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
22480    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
22481    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
22482    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
22483    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
22484    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
22485    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
22486    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
22487 
22488    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
22489    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
22490 
22491    ---------------------------------------------------------------------------------------------------------------
22492    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
22493    ---------------------------------------------------------------------------------------------------------------
22494    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
22495 
22499    IF xla_accounting_cache_pkg.GetValueChar
22496    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
22497    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
22498 
22500          (p_source_code         => 'LEDGER_CATEGORY_CODE'
22501          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
22502    AND l_bflow_method_code = 'PRIOR_ENTRY'
22503 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
22504    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
22505          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
22506        )
22507    THEN
22508          xla_ae_lines_pkg.BflowUpgEntry
22509            (p_business_method_code    => l_bflow_method_code
22510            ,p_business_class_code     => l_bflow_class_code
22511            ,p_balance_type            => l_balance_type_code);
22512    ELSE
22513       NULL;
22514 -- No business flow processing for business flow method of NONE.
22515    END IF;
22516 
22517    --
22518    -- call analytical criteria
22519    --
22520    
22521    --
22522    -- call description
22523    --
22524    
22525 xla_ae_lines_pkg.SetLineDescription(
22526    p_ae_header_id => l_ae_header_id
22527   ,p_description  => Description_6 (
22528      p_application_id         => p_application_id
22529    , p_ae_header_id           => l_ae_header_id 
22530 , p_source_1 => p_source_1
22531    )
22532 );
22533 
22534 
22535    --
22536    -- call ADRs
22537    -- Bug 4922099
22538    --
22539    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
22540         (NVL(l_actual_upg_option, 'N') = 'O') OR
22541         (NVL(l_enc_upg_option, 'N') = 'O')
22542       )
22543    THEN
22544    NULL;
22545    --
22546    --
22547    
22548   l_ccid := AcctDerRule_175(
22549            p_application_id           => p_application_id
22550          , p_ae_header_id             => l_ae_header_id 
22551 , p_source_3 => p_source_3
22552 , p_source_29 => p_source_29
22553          , x_transaction_coa_id       => l_adr_transaction_coa_id
22554          , x_accounting_coa_id        => l_adr_accounting_coa_id
22555          , x_value_type_code          => l_adr_value_type_code
22556          , p_side                     => 'NA'
22557    );
22558 
22559    xla_ae_lines_pkg.set_ccid(
22560     p_code_combination_id          => l_ccid
22561   , p_value_type_code              => l_adr_value_type_code
22562   , p_transaction_coa_id           => l_adr_transaction_coa_id
22563   , p_accounting_coa_id            => l_adr_accounting_coa_id
22564   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
22565   , p_adr_type_code                => 'S'
22566   , p_component_type               => l_component_type
22567   , p_component_code               => l_component_code
22568   , p_component_type_code          => l_component_type_code
22569   , p_component_appl_id            => l_component_appl_id
22570   , p_amb_context_code             => l_amb_context_code
22571   , p_side                         => 'NA'
22572   );
22573 
22574 
22575    --
22576    --
22577    END IF;
22578    --
22579    -- Bug 4922099
22580    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
22581           (NVL(l_enc_upg_option, 'N') = 'O')
22582         ) AND
22583         (l_bflow_method_code = 'PRIOR_ENTRY')
22584       )
22585    THEN
22586       IF
22587       --
22588       1 = 2
22589       --
22590       THEN
22591       xla_accounting_err_pkg.build_message
22592                                     (p_appli_s_name            => 'XLA'
22593                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
22594                                     ,p_token_1                 => 'LINE_NUMBER'
22595                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
22596                                     ,p_token_2                 => 'LINE_TYPE_NAME'
22597                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
22598                                                                              l_component_type
22599                                                                             ,l_component_code
22600                                                                             ,l_component_type_code
22601                                                                             ,l_component_appl_id
22602                                                                             ,l_amb_context_code
22603                                                                             ,l_entity_code
22604                                                                             ,l_event_class_code
22605                                                                            )
22606                                     ,p_token_3                 => 'OWNER'
22607                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
22608                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
22609                                                                           ,p_lookup_code    => l_component_type_code
22610                                                                          )
22611                                     ,p_token_4                 => 'PRODUCT_NAME'
22612                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
22613                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
22614                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
22615                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
22619         IF (C_LEVEL_ERROR>= g_log_level) THEN
22616                                     ,p_ae_header_id            =>  NULL
22617                                        );
22618 
22620                  trace
22621                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
22622                       ,p_level    => C_LEVEL_ERROR
22623                       ,p_module   => l_log_module);
22624         END IF;
22625       END IF;
22626    END IF;
22627    --
22628    --
22629    ------------------------------------------------------------------------------------------------
22630    -- 4219869 Business Flow
22631    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
22632    -- Prior Entry.  Currently, the following code is always generated.
22633    ------------------------------------------------------------------------------------------------
22634    XLA_AE_LINES_PKG.ValidateCurrentLine;
22635 
22636    ------------------------------------------------------------------------------------
22637    -- 4219869 Business Flow
22638    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
22639    ------------------------------------------------------------------------------------
22640    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
22641 
22642    ----------------------------------------------------------------------------------
22643    -- 4219869 Business Flow
22644    -- Update journal entry status -- Need to generate this within IF <condition>
22645    ----------------------------------------------------------------------------------
22646    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22647          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
22648          ,p_balance_type_code => l_balance_type_code
22649          );
22650 
22651    -------------------------------------------------------------------------------------------
22652    -- 4262811 - Generate the Accrual Reversal lines
22653    -------------------------------------------------------------------------------------------
22654    BEGIN
22655       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
22656                               (g_array_event(p_event_id).array_value_num('header_index'));
22657       IF l_acc_rev_flag IS NULL THEN
22658          l_acc_rev_flag := 'N';
22659       END IF;
22660    EXCEPTION
22661       WHEN OTHERS THEN
22662          l_acc_rev_flag := 'N';
22663    END;
22664    --
22665    IF (l_acc_rev_flag = 'Y') THEN
22666 
22667        -- 4645092  ------------------------------------------------------------------------------
22668        -- To allow MPA report to determine if it should generate report process
22669        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
22670        ------------------------------------------------------------------------------------------
22671 
22672        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
22673        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
22674    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
22675    -- call ADRs
22676    -- Bug 4922099
22677    --
22678    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
22679         (NVL(l_actual_upg_option, 'N') = 'O') OR
22680         (NVL(l_enc_upg_option, 'N') = 'O')
22681       )
22682    THEN
22683    NULL;
22684    --
22685    --
22686    
22687   l_ccid := AcctDerRule_175(
22688            p_application_id           => p_application_id
22689          , p_ae_header_id             => l_ae_header_id 
22690 , p_source_3 => p_source_3
22691 , p_source_29 => p_source_29
22692          , x_transaction_coa_id       => l_adr_transaction_coa_id
22693          , x_accounting_coa_id        => l_adr_accounting_coa_id
22694          , x_value_type_code          => l_adr_value_type_code
22695          , p_side                     => 'NA'
22696    );
22697 
22698    xla_ae_lines_pkg.set_ccid(
22699     p_code_combination_id          => l_ccid
22700   , p_value_type_code              => l_adr_value_type_code
22701   , p_transaction_coa_id           => l_adr_transaction_coa_id
22702   , p_accounting_coa_id            => l_adr_accounting_coa_id
22703   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
22704   , p_adr_type_code                => 'S'
22705   , p_component_type               => l_component_type
22706   , p_component_code               => l_component_code
22707   , p_component_type_code          => l_component_type_code
22708   , p_component_appl_id            => l_component_appl_id
22709   , p_amb_context_code             => l_amb_context_code
22710   , p_side                         => 'NA'
22711   );
22712 
22713 
22714    --
22715    --
22716    END IF;
22717 
22718        --
22719        -- Update the line information that should be overwritten
22720        --
22721        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
22722                                          p_header_num   => 1);
22723        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
22724 
22725        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
22726 
22727        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
22728           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
22729        END IF;
22730 
22731       --
22732       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
22733       --
22734       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
22735           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
22736       ELSE
22737           ---------------------------------------------------------------------------------------------------
22741           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22738           -- 4262811a Switch Sign
22739           ---------------------------------------------------------------------------------------------------
22740           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
22742                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22743           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22744                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22745           -- 5132302
22746           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
22747                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22748 
22749       END IF;
22750 
22751       -- 4955764
22752       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
22753       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
22754 
22755 
22756       XLA_AE_LINES_PKG.ValidateCurrentLine;
22757       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
22758 
22759       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22760                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
22761                ,p_balance_type_code => l_balance_type_code);
22762 
22763    END IF;
22764 
22765    -----------------------------------------------------------------------------------------
22766    -- 4262811 Multiperiod Accounting
22767    -----------------------------------------------------------------------------------------
22768      -- No MPA option is assigned.
22769 
22770 
22771 END IF;
22772 END IF;
22773 --
22774 
22775 --
22776 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22777    trace
22778       (p_msg      => 'END of AcctLineType_185'
22779       ,p_level    => C_LEVEL_PROCEDURE
22780       ,p_module   => l_log_module);
22781 END IF;
22782 --
22783 EXCEPTION
22784   WHEN xla_exceptions_pkg.application_exception THEN
22785       RAISE;
22786   WHEN OTHERS THEN
22787        xla_exceptions_pkg.raise_message
22788            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_185');
22789 END AcctLineType_185;
22790 --
22791 
22792 ---------------------------------------
22793 --
22794 -- PRIVATE FUNCTION
22795 --         AcctLineType_186
22796 --
22797 ---------------------------------------
22798 PROCEDURE AcctLineType_186 (
22799   p_application_id        IN NUMBER
22800  ,p_event_id              IN NUMBER
22801  ,p_calculate_acctd_flag  IN VARCHAR2
22802  ,p_calculate_g_l_flag    IN VARCHAR2
22803  ,p_actual_flag           IN OUT VARCHAR2
22804  ,p_balance_type_code     OUT VARCHAR2
22805  ,p_gain_or_loss_ref      OUT VARCHAR2
22806  
22807 --Period Close Date
22808  , p_source_1            IN DATE
22809 --Generated Code Combination Identifier
22810  , p_source_3            IN NUMBER
22811 --Expense Account Code Combination Identifier
22812  , p_source_29            IN NUMBER
22813 --Adjustment Type
22814  , p_source_35            IN VARCHAR2
22815 --Transaction Header Identifier
22816  , p_source_36            IN NUMBER
22817 --Adjustment Line Identifier
22818  , p_source_37            IN NUMBER
22819 --Distribution Type Code
22820  , p_source_38            IN VARCHAR2
22821 --Entered Amount
22822  , p_source_39            IN NUMBER
22823 --Currency Code
22824  , p_source_40            IN VARCHAR2
22825 )
22826 IS
22827 
22828 l_component_type              VARCHAR2(80);
22829 l_component_code              VARCHAR2(30);
22830 l_component_type_code         VARCHAR2(1);
22831 l_component_appl_id           INTEGER;
22832 l_amb_context_code            VARCHAR2(30);
22833 l_entity_code                 VARCHAR2(30);
22834 l_event_class_code            VARCHAR2(30);
22835 l_ae_header_id                NUMBER;
22836 l_event_type_code             VARCHAR2(30);
22837 l_line_definition_code        VARCHAR2(30);
22838 l_line_definition_owner_code  VARCHAR2(1);
22839 --
22840 -- adr variables
22841 l_segment                     VARCHAR2(30);
22842 l_ccid                        NUMBER;
22843 l_adr_transaction_coa_id      NUMBER;
22844 l_adr_accounting_coa_id       NUMBER;
22845 l_adr_flexfield_segment_code  VARCHAR2(30);
22846 l_adr_flex_value_set_id       NUMBER;
22847 l_adr_value_type_code         VARCHAR2(30);
22848 l_adr_value_combination_id    NUMBER;
22849 l_adr_value_segment_code      VARCHAR2(30);
22850 
22851 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
22852 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
22853 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
22854 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
22855 
22856 -- 4262811 Variables ------------------------------------------------------------------------------------------
22857 l_entered_amt_idx             NUMBER;
22858 l_accted_amt_idx              NUMBER;
22859 l_acc_rev_flag                VARCHAR2(1);
22860 l_accrual_line_num            NUMBER;
22861 l_tmp_amt                     NUMBER;
22862 l_acc_rev_natural_side_code   VARCHAR2(1);
22863 
22864 l_num_entries                 NUMBER;
22865 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
22866 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
22867 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
22868 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
22869 l_recog_line_1                NUMBER;
22870 l_recog_line_2                NUMBER;
22871 
22875 
22872 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
22873 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
22874 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
22876 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
22877 
22878 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
22879 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
22880 
22881 ---------------------------------------------------------------------------------------------------------------
22882 
22883 
22884 --
22885 -- bulk performance
22886 --
22887 l_balance_type_code           VARCHAR2(1);
22888 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
22889 l_log_module                  VARCHAR2(240);
22890 
22891 --
22892 -- Upgrade strategy
22893 --
22894 l_actual_upg_option           VARCHAR2(1);
22895 l_enc_upg_option           VARCHAR2(1);
22896 
22897 --
22898 BEGIN
22899 --
22900 IF g_log_enabled THEN
22901       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_186';
22902 END IF;
22903 --
22904 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22905 
22906       trace
22907          (p_msg      => 'BEGIN of AcctLineType_186'
22908          ,p_level    => C_LEVEL_PROCEDURE
22909          ,p_module   => l_log_module);
22910 
22911 END IF;
22912 --
22913 l_component_type             := 'AMB_JLT';
22914 l_component_code             := 'FA_ADD_EXP_BAL';
22915 l_component_type_code        := 'S';
22916 l_component_appl_id          :=  140;
22917 l_amb_context_code           := 'DEFAULT';
22918 l_entity_code                := 'TRANSACTIONS';
22919 l_event_class_code           := 'ADDITIONS';
22920 l_event_type_code            := 'ADDITIONS_ALL';
22921 l_line_definition_owner_code := 'S';
22922 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADDITI1';
22923 --
22924 l_balance_type_code          := 'A';
22925 l_segment                     := NULL;
22926 l_ccid                        := NULL;
22927 l_adr_transaction_coa_id      := NULL;
22928 l_adr_accounting_coa_id       := NULL;
22929 l_adr_flexfield_segment_code  := NULL;
22930 l_adr_flex_value_set_id       := NULL;
22931 l_adr_value_type_code         := NULL;
22932 l_adr_value_combination_id    := NULL;
22933 l_adr_value_segment_code      := NULL;
22934 
22935 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
22936 l_bflow_class_code           := '';    -- 4219869 Business Flow
22937 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
22938 l_budgetary_control_flag     := 'N';
22939 
22940 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
22941 l_bflow_applied_to_amt       := NULL; -- 5132302
22942 l_entered_amt_idx            := NULL;          -- 4262811
22943 l_accted_amt_idx             := NULL;          -- 4262811
22944 l_acc_rev_flag               := NULL;          -- 4262811
22945 l_accrual_line_num           := NULL;          -- 4262811
22946 l_tmp_amt                    := NULL;          -- 4262811
22947 --
22948  
22949 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
22950     l_balance_type_code <> 'B' THEN
22951 IF NVL(p_source_35,'
22952 ') =  'BONUS EXPENSE'
22953  THEN 
22954 
22955    --
22956    XLA_AE_LINES_PKG.SetNewLine;
22957 
22958    p_balance_type_code          := l_balance_type_code;
22959    -- set the flag so later we will know whether the gain loss line needs to be created
22960    
22961    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
22962      p_actual_flag :='A';
22963    END IF;
22964 
22965    --
22966    -- bulk performance
22967    --
22968    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
22969                                       p_header_num   => 0); -- 4262811
22970    --
22971    -- set accounting line options
22972    --
22973    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
22974            p_natural_side_code          => 'C'
22975          , p_gain_or_loss_flag          => 'N'
22976          , p_gl_transfer_mode_code      => 'S'
22977          , p_acct_entry_type_code       => 'A'
22978          , p_switch_side_flag           => 'Y'
22979          , p_merge_duplicate_code       => 'N'
22980          );
22981    --
22982    l_acc_rev_natural_side_code := 'D';  -- 4262811
22983    -- 
22984    --
22985    -- set accounting line type info
22986    --
22987    xla_ae_lines_pkg.SetAcctLineType
22988       (p_component_type             => l_component_type
22989       ,p_event_type_code            => l_event_type_code
22990       ,p_line_definition_owner_code => l_line_definition_owner_code
22991       ,p_line_definition_code       => l_line_definition_code
22992       ,p_accounting_line_code       => l_component_code
22993       ,p_accounting_line_type_code  => l_component_type_code
22994       ,p_accounting_line_appl_id    => l_component_appl_id
22995       ,p_amb_context_code           => l_amb_context_code
22996       ,p_entity_code                => l_entity_code
22997       ,p_event_class_code           => l_event_class_code);
22998    --
22999    -- set accounting class
23000    --
23001    xla_ae_lines_pkg.SetAcctClass(
23002            p_accounting_class_code  => 'EXPENSE'
23003          , p_ae_header_id           => l_ae_header_id
23004          );
23005 
23006    --
23007    -- set rounding class
23008    --
23009    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
23010                       'EXPENSE';
23011 
23012    --
23013    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
23017    --
23014    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
23015    --
23016    -- bulk performance
23018    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
23019 
23020    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
23021       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
23022 
23023    -- 4955764
23024    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
23025       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
23026 
23027    -- 4458381 Public Sector Enh
23028    
23029    --
23030    -- set accounting attributes for the line type
23031    --
23032    l_entered_amt_idx := 4;
23033    l_accted_amt_idx  := 6;
23034    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
23035    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
23036    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
23037    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
23038    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
23039    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
23040    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
23041    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
23042    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
23043    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
23044    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
23045    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
23046    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
23047 
23048    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
23049    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
23050 
23051    ---------------------------------------------------------------------------------------------------------------
23052    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
23053    ---------------------------------------------------------------------------------------------------------------
23054    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
23055 
23056    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
23057    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
23058 
23059    IF xla_accounting_cache_pkg.GetValueChar
23060          (p_source_code         => 'LEDGER_CATEGORY_CODE'
23061          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
23062    AND l_bflow_method_code = 'PRIOR_ENTRY'
23063 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
23064    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
23065          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
23066        )
23067    THEN
23068          xla_ae_lines_pkg.BflowUpgEntry
23069            (p_business_method_code    => l_bflow_method_code
23070            ,p_business_class_code     => l_bflow_class_code
23071            ,p_balance_type            => l_balance_type_code);
23072    ELSE
23073       NULL;
23074 -- No business flow processing for business flow method of NONE.
23075    END IF;
23076 
23077    --
23078    -- call analytical criteria
23079    --
23080    
23081    --
23082    -- call description
23083    --
23084    
23085 xla_ae_lines_pkg.SetLineDescription(
23086    p_ae_header_id => l_ae_header_id
23087   ,p_description  => Description_6 (
23088      p_application_id         => p_application_id
23089    , p_ae_header_id           => l_ae_header_id 
23090 , p_source_1 => p_source_1
23091    )
23092 );
23093 
23094 
23095    --
23096    -- call ADRs
23097    -- Bug 4922099
23098    --
23099    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
23100         (NVL(l_actual_upg_option, 'N') = 'O') OR
23101         (NVL(l_enc_upg_option, 'N') = 'O')
23102       )
23103    THEN
23104    NULL;
23105    --
23106    --
23107    
23108   l_ccid := AcctDerRule_175(
23109            p_application_id           => p_application_id
23110          , p_ae_header_id             => l_ae_header_id 
23111 , p_source_3 => p_source_3
23112 , p_source_29 => p_source_29
23113          , x_transaction_coa_id       => l_adr_transaction_coa_id
23114          , x_accounting_coa_id        => l_adr_accounting_coa_id
23115          , x_value_type_code          => l_adr_value_type_code
23116          , p_side                     => 'NA'
23117    );
23118 
23119    xla_ae_lines_pkg.set_ccid(
23120     p_code_combination_id          => l_ccid
23121   , p_value_type_code              => l_adr_value_type_code
23122   , p_transaction_coa_id           => l_adr_transaction_coa_id
23123   , p_accounting_coa_id            => l_adr_accounting_coa_id
23124   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
23125   , p_adr_type_code                => 'S'
23126   , p_component_type               => l_component_type
23127   , p_component_code               => l_component_code
23128   , p_component_type_code          => l_component_type_code
23129   , p_component_appl_id            => l_component_appl_id
23130   , p_amb_context_code             => l_amb_context_code
23131   , p_side                         => 'NA'
23132   );
23133 
23134 
23135    --
23136    --
23137    END IF;
23138    --
23139    -- Bug 4922099
23140    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
23141           (NVL(l_enc_upg_option, 'N') = 'O')
23142         ) AND
23143         (l_bflow_method_code = 'PRIOR_ENTRY')
23144       )
23145    THEN
23146       IF
23150       THEN
23147       --
23148       1 = 2
23149       --
23151       xla_accounting_err_pkg.build_message
23152                                     (p_appli_s_name            => 'XLA'
23153                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23154                                     ,p_token_1                 => 'LINE_NUMBER'
23155                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
23156                                     ,p_token_2                 => 'LINE_TYPE_NAME'
23157                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
23158                                                                              l_component_type
23159                                                                             ,l_component_code
23160                                                                             ,l_component_type_code
23161                                                                             ,l_component_appl_id
23162                                                                             ,l_amb_context_code
23163                                                                             ,l_entity_code
23164                                                                             ,l_event_class_code
23165                                                                            )
23166                                     ,p_token_3                 => 'OWNER'
23167                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
23168                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
23169                                                                           ,p_lookup_code    => l_component_type_code
23170                                                                          )
23171                                     ,p_token_4                 => 'PRODUCT_NAME'
23172                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
23173                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
23174                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
23175                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
23176                                     ,p_ae_header_id            =>  NULL
23177                                        );
23178 
23179         IF (C_LEVEL_ERROR>= g_log_level) THEN
23180                  trace
23181                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23182                       ,p_level    => C_LEVEL_ERROR
23183                       ,p_module   => l_log_module);
23184         END IF;
23185       END IF;
23186    END IF;
23187    --
23188    --
23189    ------------------------------------------------------------------------------------------------
23190    -- 4219869 Business Flow
23191    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
23192    -- Prior Entry.  Currently, the following code is always generated.
23193    ------------------------------------------------------------------------------------------------
23194    XLA_AE_LINES_PKG.ValidateCurrentLine;
23195 
23196    ------------------------------------------------------------------------------------
23197    -- 4219869 Business Flow
23198    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
23199    ------------------------------------------------------------------------------------
23200    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
23201 
23202    ----------------------------------------------------------------------------------
23203    -- 4219869 Business Flow
23204    -- Update journal entry status -- Need to generate this within IF <condition>
23205    ----------------------------------------------------------------------------------
23206    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
23207          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
23208          ,p_balance_type_code => l_balance_type_code
23209          );
23210 
23211    -------------------------------------------------------------------------------------------
23212    -- 4262811 - Generate the Accrual Reversal lines
23213    -------------------------------------------------------------------------------------------
23214    BEGIN
23215       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
23216                               (g_array_event(p_event_id).array_value_num('header_index'));
23217       IF l_acc_rev_flag IS NULL THEN
23218          l_acc_rev_flag := 'N';
23219       END IF;
23220    EXCEPTION
23221       WHEN OTHERS THEN
23222          l_acc_rev_flag := 'N';
23223    END;
23224    --
23225    IF (l_acc_rev_flag = 'Y') THEN
23226 
23227        -- 4645092  ------------------------------------------------------------------------------
23228        -- To allow MPA report to determine if it should generate report process
23229        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
23230        ------------------------------------------------------------------------------------------
23231 
23232        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
23233        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
23234    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
23235    -- call ADRs
23236    -- Bug 4922099
23237    --
23238    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
23239         (NVL(l_actual_upg_option, 'N') = 'O') OR
23240         (NVL(l_enc_upg_option, 'N') = 'O')
23241       )
23242    THEN
23243    NULL;
23244    --
23245    --
23246    
23247   l_ccid := AcctDerRule_175(
23248            p_application_id           => p_application_id
23249          , p_ae_header_id             => l_ae_header_id 
23253          , x_accounting_coa_id        => l_adr_accounting_coa_id
23250 , p_source_3 => p_source_3
23251 , p_source_29 => p_source_29
23252          , x_transaction_coa_id       => l_adr_transaction_coa_id
23254          , x_value_type_code          => l_adr_value_type_code
23255          , p_side                     => 'NA'
23256    );
23257 
23258    xla_ae_lines_pkg.set_ccid(
23259     p_code_combination_id          => l_ccid
23260   , p_value_type_code              => l_adr_value_type_code
23261   , p_transaction_coa_id           => l_adr_transaction_coa_id
23262   , p_accounting_coa_id            => l_adr_accounting_coa_id
23263   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
23264   , p_adr_type_code                => 'S'
23265   , p_component_type               => l_component_type
23266   , p_component_code               => l_component_code
23267   , p_component_type_code          => l_component_type_code
23268   , p_component_appl_id            => l_component_appl_id
23269   , p_amb_context_code             => l_amb_context_code
23270   , p_side                         => 'NA'
23271   );
23272 
23273 
23274    --
23275    --
23276    END IF;
23277 
23278        --
23279        -- Update the line information that should be overwritten
23280        --
23281        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
23282                                          p_header_num   => 1);
23283        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
23284 
23285        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
23286 
23287        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
23288           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
23289        END IF;
23290 
23291       --
23292       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
23293       --
23294       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
23295           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
23296       ELSE
23297           ---------------------------------------------------------------------------------------------------
23298           -- 4262811a Switch Sign
23299           ---------------------------------------------------------------------------------------------------
23300           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
23301           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
23302                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23303           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
23304                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23305           -- 5132302
23306           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
23307                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23308 
23309       END IF;
23310 
23311       -- 4955764
23312       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
23313       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
23314 
23315 
23316       XLA_AE_LINES_PKG.ValidateCurrentLine;
23317       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
23318 
23319       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
23320                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
23321                ,p_balance_type_code => l_balance_type_code);
23322 
23323    END IF;
23324 
23325    -----------------------------------------------------------------------------------------
23326    -- 4262811 Multiperiod Accounting
23327    -----------------------------------------------------------------------------------------
23328      -- No MPA option is assigned.
23329 
23330 
23331 END IF;
23332 END IF;
23333 --
23334 
23335 --
23336 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
23337    trace
23338       (p_msg      => 'END of AcctLineType_186'
23339       ,p_level    => C_LEVEL_PROCEDURE
23340       ,p_module   => l_log_module);
23341 END IF;
23342 --
23343 EXCEPTION
23344   WHEN xla_exceptions_pkg.application_exception THEN
23345       RAISE;
23346   WHEN OTHERS THEN
23347        xla_exceptions_pkg.raise_message
23348            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_186');
23349 END AcctLineType_186;
23350 --
23351 
23352 ---------------------------------------
23353 --
23354 -- PRIVATE FUNCTION
23355 --         AcctLineType_187
23356 --
23357 ---------------------------------------
23358 PROCEDURE AcctLineType_187 (
23359   p_application_id        IN NUMBER
23360  ,p_event_id              IN NUMBER
23361  ,p_calculate_acctd_flag  IN VARCHAR2
23362  ,p_calculate_g_l_flag    IN VARCHAR2
23366  
23363  ,p_actual_flag           IN OUT VARCHAR2
23364  ,p_balance_type_code     OUT VARCHAR2
23365  ,p_gain_or_loss_ref      OUT VARCHAR2
23367 --Period Close Date
23368  , p_source_1            IN DATE
23369 --Generated Code Combination Identifier
23370  , p_source_3            IN NUMBER
23371 --Depreciation Reserve Account
23372  , p_source_10            IN VARCHAR2
23373 --Generated Offset Code Combination Identifier
23374  , p_source_17            IN NUMBER
23375 --Expense Account Code Combination Identifier
23376  , p_source_29            IN NUMBER
23377 --Default Code Combination Identifier
23378  , p_source_30            IN NUMBER
23379 --Adjustment Type
23380  , p_source_35            IN VARCHAR2
23381 --Transaction Header Identifier
23382  , p_source_36            IN NUMBER
23383 --Adjustment Line Identifier
23384  , p_source_37            IN NUMBER
23385 --Distribution Type Code
23386  , p_source_38            IN VARCHAR2
23387 --Entered Amount
23388  , p_source_39            IN NUMBER
23389 --Currency Code
23390  , p_source_40            IN VARCHAR2
23391 )
23392 IS
23393 
23394 l_component_type              VARCHAR2(80);
23395 l_component_code              VARCHAR2(30);
23396 l_component_type_code         VARCHAR2(1);
23397 l_component_appl_id           INTEGER;
23398 l_amb_context_code            VARCHAR2(30);
23399 l_entity_code                 VARCHAR2(30);
23400 l_event_class_code            VARCHAR2(30);
23401 l_ae_header_id                NUMBER;
23402 l_event_type_code             VARCHAR2(30);
23403 l_line_definition_code        VARCHAR2(30);
23404 l_line_definition_owner_code  VARCHAR2(1);
23405 --
23406 -- adr variables
23407 l_segment                     VARCHAR2(30);
23408 l_ccid                        NUMBER;
23409 l_adr_transaction_coa_id      NUMBER;
23410 l_adr_accounting_coa_id       NUMBER;
23411 l_adr_flexfield_segment_code  VARCHAR2(30);
23412 l_adr_flex_value_set_id       NUMBER;
23413 l_adr_value_type_code         VARCHAR2(30);
23414 l_adr_value_combination_id    NUMBER;
23415 l_adr_value_segment_code      VARCHAR2(30);
23416 
23417 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
23418 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
23419 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
23420 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
23421 
23422 -- 4262811 Variables ------------------------------------------------------------------------------------------
23423 l_entered_amt_idx             NUMBER;
23424 l_accted_amt_idx              NUMBER;
23425 l_acc_rev_flag                VARCHAR2(1);
23426 l_accrual_line_num            NUMBER;
23427 l_tmp_amt                     NUMBER;
23428 l_acc_rev_natural_side_code   VARCHAR2(1);
23429 
23430 l_num_entries                 NUMBER;
23431 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
23432 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
23433 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
23434 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
23435 l_recog_line_1                NUMBER;
23436 l_recog_line_2                NUMBER;
23437 
23438 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
23439 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
23440 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
23441 
23442 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
23443 
23444 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
23445 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
23446 
23447 ---------------------------------------------------------------------------------------------------------------
23448 
23449 
23450 --
23451 -- bulk performance
23452 --
23453 l_balance_type_code           VARCHAR2(1);
23454 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
23455 l_log_module                  VARCHAR2(240);
23456 
23457 --
23458 -- Upgrade strategy
23459 --
23460 l_actual_upg_option           VARCHAR2(1);
23461 l_enc_upg_option           VARCHAR2(1);
23462 
23463 --
23464 BEGIN
23465 --
23466 IF g_log_enabled THEN
23467       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_187';
23471 
23468 END IF;
23469 --
23470 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
23472       trace
23473          (p_msg      => 'BEGIN of AcctLineType_187'
23474          ,p_level    => C_LEVEL_PROCEDURE
23475          ,p_module   => l_log_module);
23476 
23477 END IF;
23478 --
23479 l_component_type             := 'AMB_JLT';
23480 l_component_code             := 'FA_ADD_RESERVE';
23481 l_component_type_code        := 'S';
23482 l_component_appl_id          :=  140;
23483 l_amb_context_code           := 'DEFAULT';
23484 l_entity_code                := 'TRANSACTIONS';
23485 l_event_class_code           := 'ADDITIONS';
23486 l_event_type_code            := 'ADDITIONS_ALL';
23487 l_line_definition_owner_code := 'S';
23488 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADDITI1';
23489 --
23490 l_balance_type_code          := 'A';
23491 l_segment                     := NULL;
23492 l_ccid                        := NULL;
23493 l_adr_transaction_coa_id      := NULL;
23494 l_adr_accounting_coa_id       := NULL;
23495 l_adr_flexfield_segment_code  := NULL;
23496 l_adr_flex_value_set_id       := NULL;
23497 l_adr_value_type_code         := NULL;
23498 l_adr_value_combination_id    := NULL;
23499 l_adr_value_segment_code      := NULL;
23500 
23501 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
23502 l_bflow_class_code           := '';    -- 4219869 Business Flow
23503 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
23504 l_budgetary_control_flag     := 'N';
23505 
23506 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
23507 l_bflow_applied_to_amt       := NULL; -- 5132302
23508 l_entered_amt_idx            := NULL;          -- 4262811
23509 l_accted_amt_idx             := NULL;          -- 4262811
23510 l_acc_rev_flag               := NULL;          -- 4262811
23511 l_accrual_line_num           := NULL;          -- 4262811
23512 l_tmp_amt                    := NULL;          -- 4262811
23513 --
23514  
23515 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
23516     l_balance_type_code <> 'B' THEN
23517 IF NVL(p_source_35,'
23518 ') =  'EXPENSE'
23519  THEN 
23520 
23521    --
23522    XLA_AE_LINES_PKG.SetNewLine;
23523 
23524    p_balance_type_code          := l_balance_type_code;
23525    -- set the flag so later we will know whether the gain loss line needs to be created
23526    
23527    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
23528      p_actual_flag :='A';
23529    END IF;
23530 
23531    --
23532    -- bulk performance
23533    --
23534    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
23535                                       p_header_num   => 0); -- 4262811
23536    --
23537    -- set accounting line options
23538    --
23539    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
23540            p_natural_side_code          => 'C'
23541          , p_gain_or_loss_flag          => 'N'
23542          , p_gl_transfer_mode_code      => 'S'
23543          , p_acct_entry_type_code       => 'A'
23544          , p_switch_side_flag           => 'Y'
23545          , p_merge_duplicate_code       => 'N'
23546          );
23547    --
23548    l_acc_rev_natural_side_code := 'D';  -- 4262811
23549    -- 
23550    --
23551    -- set accounting line type info
23552    --
23553    xla_ae_lines_pkg.SetAcctLineType
23554       (p_component_type             => l_component_type
23555       ,p_event_type_code            => l_event_type_code
23556       ,p_line_definition_owner_code => l_line_definition_owner_code
23557       ,p_line_definition_code       => l_line_definition_code
23558       ,p_accounting_line_code       => l_component_code
23559       ,p_accounting_line_type_code  => l_component_type_code
23560       ,p_accounting_line_appl_id    => l_component_appl_id
23561       ,p_amb_context_code           => l_amb_context_code
23562       ,p_entity_code                => l_entity_code
23563       ,p_event_class_code           => l_event_class_code);
23564    --
23565    -- set accounting class
23566    --
23567    xla_ae_lines_pkg.SetAcctClass(
23568            p_accounting_class_code  => 'ASSET'
23569          , p_ae_header_id           => l_ae_header_id
23570          );
23571 
23572    --
23573    -- set rounding class
23574    --
23575    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
23576                       'ASSET';
23577 
23578    --
23579    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
23580    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
23581    --
23582    -- bulk performance
23583    --
23584    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
23585 
23586    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
23587       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
23588 
23589    -- 4955764
23590    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
23591       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
23592 
23593    -- 4458381 Public Sector Enh
23594    
23595    --
23596    -- set accounting attributes for the line type
23597    --
23598    l_entered_amt_idx := 4;
23599    l_accted_amt_idx  := 6;
23600    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
23601    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
23602    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
23603    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
23604    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
23608    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
23605    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
23606    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
23607    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
23609    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
23610    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
23611    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
23612    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
23613 
23614    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
23615    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
23616 
23617    ---------------------------------------------------------------------------------------------------------------
23618    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
23619    ---------------------------------------------------------------------------------------------------------------
23620    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
23621 
23622    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
23623    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
23624 
23625    IF xla_accounting_cache_pkg.GetValueChar
23626          (p_source_code         => 'LEDGER_CATEGORY_CODE'
23627          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
23628    AND l_bflow_method_code = 'PRIOR_ENTRY'
23629 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
23630    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
23631          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
23632        )
23633    THEN
23634          xla_ae_lines_pkg.BflowUpgEntry
23635            (p_business_method_code    => l_bflow_method_code
23636            ,p_business_class_code     => l_bflow_class_code
23637            ,p_balance_type            => l_balance_type_code);
23638    ELSE
23639       NULL;
23640 -- No business flow processing for business flow method of NONE.
23641    END IF;
23642 
23643    --
23644    -- call analytical criteria
23645    --
23646    
23647    --
23648    -- call description
23649    --
23650    
23651 xla_ae_lines_pkg.SetLineDescription(
23652    p_ae_header_id => l_ae_header_id
23653   ,p_description  => Description_7 (
23654      p_application_id         => p_application_id
23655    , p_ae_header_id           => l_ae_header_id 
23656 , p_source_1 => p_source_1
23657    )
23658 );
23659 
23660 
23661    --
23662    -- call ADRs
23663    -- Bug 4922099
23664    --
23665    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
23666         (NVL(l_actual_upg_option, 'N') = 'O') OR
23667         (NVL(l_enc_upg_option, 'N') = 'O')
23668       )
23669    THEN
23670    NULL;
23671    --
23672    --
23673    
23674   l_ccid := AcctDerRule_174(
23675            p_application_id           => p_application_id
23676          , p_ae_header_id             => l_ae_header_id 
23677 , p_source_3 => p_source_3
23678 , p_source_17 => p_source_17
23679 , p_source_30 => p_source_30
23680          , x_transaction_coa_id       => l_adr_transaction_coa_id
23681          , x_accounting_coa_id        => l_adr_accounting_coa_id
23682          , x_value_type_code          => l_adr_value_type_code
23683          , p_side                     => 'NA'
23684    );
23685 
23686    xla_ae_lines_pkg.set_ccid(
23687     p_code_combination_id          => l_ccid
23688   , p_value_type_code              => l_adr_value_type_code
23689   , p_transaction_coa_id           => l_adr_transaction_coa_id
23690   , p_accounting_coa_id            => l_adr_accounting_coa_id
23691   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
23692   , p_adr_type_code                => 'S'
23693   , p_component_type               => l_component_type
23694   , p_component_code               => l_component_code
23695   , p_component_type_code          => l_component_type_code
23696   , p_component_appl_id            => l_component_appl_id
23697   , p_amb_context_code             => l_amb_context_code
23698   , p_side                         => 'NA'
23699   );
23700 
23701 
23702    l_segment := AcctDerRule_149(
23703            p_application_id           => p_application_id
23704          , p_ae_header_id             => l_ae_header_id 
23705 , p_source_3 => p_source_3
23706 , p_source_10 => p_source_10
23707          , x_transaction_coa_id       => l_adr_transaction_coa_id
23708          , x_accounting_coa_id        => l_adr_accounting_coa_id
23709          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23710          , x_flex_value_set_id        => l_adr_flex_value_set_id
23711          , x_value_type_code          => l_adr_value_type_code
23712          , x_value_combination_id     => l_adr_value_combination_id
23713          , x_value_segment_code       => l_adr_value_segment_code
23714          , p_side                     => 'NA'
23715          , p_override_seg_flag        => 'Y'
23716    );
23717 
23718    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23719 
23720       xla_ae_lines_pkg.set_segment(
23721           p_to_segment_code         => 'GL_ACCOUNT'
23722         , p_segment_value           => l_segment
23723         , p_from_segment_code       => l_adr_value_segment_code
23724         , p_from_combination_id     => l_adr_value_combination_id
23725         , p_value_type_code         => l_adr_value_type_code
23726         , p_transaction_coa_id      => l_adr_transaction_coa_id
23727         , p_accounting_coa_id       => l_adr_accounting_coa_id
23728         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23729         , p_flex_value_set_id       => l_adr_flex_value_set_id
23733         , p_component_code          => l_component_code
23730         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
23731         , p_adr_type_code           => 'S'
23732         , p_component_type          => l_component_type
23734         , p_component_type_code     => l_component_type_code
23735         , p_component_appl_id       => l_component_appl_id
23736         , p_amb_context_code        => l_amb_context_code
23737         , p_entity_code             => 'TRANSACTIONS'
23738         , p_event_class_code        => 'ADDITIONS'
23739         , p_side                    => 'NA'
23740         );
23741 
23742   END IF;
23743 
23744    l_segment := AcctDerRule_168(
23745            p_application_id           => p_application_id
23746          , p_ae_header_id             => l_ae_header_id 
23747 , p_source_3 => p_source_3
23748 , p_source_29 => p_source_29
23749          , x_transaction_coa_id       => l_adr_transaction_coa_id
23750          , x_accounting_coa_id        => l_adr_accounting_coa_id
23751          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23752          , x_flex_value_set_id        => l_adr_flex_value_set_id
23753          , x_value_type_code          => l_adr_value_type_code
23754          , x_value_combination_id     => l_adr_value_combination_id
23755          , x_value_segment_code       => l_adr_value_segment_code
23756          , p_side                     => 'NA'
23757          , p_override_seg_flag        => 'Y'
23758    );
23759 
23760    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23761 
23762       xla_ae_lines_pkg.set_segment(
23763           p_to_segment_code         => 'GL_BALANCING'
23764         , p_segment_value           => l_segment
23765         , p_from_segment_code       => l_adr_value_segment_code
23766         , p_from_combination_id     => l_adr_value_combination_id
23767         , p_value_type_code         => l_adr_value_type_code
23768         , p_transaction_coa_id      => l_adr_transaction_coa_id
23769         , p_accounting_coa_id       => l_adr_accounting_coa_id
23770         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23771         , p_flex_value_set_id       => l_adr_flex_value_set_id
23772         , p_adr_code                => 'FA_EXPENSE_ACCT'
23773         , p_adr_type_code           => 'S'
23774         , p_component_type          => l_component_type
23775         , p_component_code          => l_component_code
23776         , p_component_type_code     => l_component_type_code
23777         , p_component_appl_id       => l_component_appl_id
23778         , p_amb_context_code        => l_amb_context_code
23779         , p_entity_code             => 'TRANSACTIONS'
23780         , p_event_class_code        => 'ADDITIONS'
23781         , p_side                    => 'NA'
23782         );
23783 
23784   END IF;
23785 
23786    --
23787    --
23788    END IF;
23789    --
23790    -- Bug 4922099
23791    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
23792           (NVL(l_enc_upg_option, 'N') = 'O')
23793         ) AND
23794         (l_bflow_method_code = 'PRIOR_ENTRY')
23795       )
23796    THEN
23797       IF
23798       --
23799       1 = 2
23800       --
23801       THEN
23802       xla_accounting_err_pkg.build_message
23803                                     (p_appli_s_name            => 'XLA'
23804                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23805                                     ,p_token_1                 => 'LINE_NUMBER'
23806                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
23807                                     ,p_token_2                 => 'LINE_TYPE_NAME'
23808                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
23809                                                                              l_component_type
23810                                                                             ,l_component_code
23811                                                                             ,l_component_type_code
23812                                                                             ,l_component_appl_id
23813                                                                             ,l_amb_context_code
23814                                                                             ,l_entity_code
23815                                                                             ,l_event_class_code
23816                                                                            )
23817                                     ,p_token_3                 => 'OWNER'
23818                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
23819                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
23820                                                                           ,p_lookup_code    => l_component_type_code
23821                                                                          )
23822                                     ,p_token_4                 => 'PRODUCT_NAME'
23823                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
23824                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
23825                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
23826                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
23827                                     ,p_ae_header_id            =>  NULL
23828                                        );
23829 
23830         IF (C_LEVEL_ERROR>= g_log_level) THEN
23831                  trace
23832                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23833                       ,p_level    => C_LEVEL_ERROR
23834                       ,p_module   => l_log_module);
23835         END IF;
23836       END IF;
23840    ------------------------------------------------------------------------------------------------
23837    END IF;
23838    --
23839    --
23841    -- 4219869 Business Flow
23842    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
23843    -- Prior Entry.  Currently, the following code is always generated.
23844    ------------------------------------------------------------------------------------------------
23845    XLA_AE_LINES_PKG.ValidateCurrentLine;
23846 
23847    ------------------------------------------------------------------------------------
23848    -- 4219869 Business Flow
23849    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
23850    ------------------------------------------------------------------------------------
23851    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
23852 
23853    ----------------------------------------------------------------------------------
23854    -- 4219869 Business Flow
23855    -- Update journal entry status -- Need to generate this within IF <condition>
23856    ----------------------------------------------------------------------------------
23857    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
23858          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
23859          ,p_balance_type_code => l_balance_type_code
23860          );
23861 
23862    -------------------------------------------------------------------------------------------
23863    -- 4262811 - Generate the Accrual Reversal lines
23864    -------------------------------------------------------------------------------------------
23865    BEGIN
23866       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
23867                               (g_array_event(p_event_id).array_value_num('header_index'));
23868       IF l_acc_rev_flag IS NULL THEN
23869          l_acc_rev_flag := 'N';
23870       END IF;
23871    EXCEPTION
23872       WHEN OTHERS THEN
23873          l_acc_rev_flag := 'N';
23874    END;
23875    --
23876    IF (l_acc_rev_flag = 'Y') THEN
23877 
23878        -- 4645092  ------------------------------------------------------------------------------
23879        -- To allow MPA report to determine if it should generate report process
23880        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
23881        ------------------------------------------------------------------------------------------
23882 
23883        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
23884        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
23885    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
23886    -- call ADRs
23887    -- Bug 4922099
23888    --
23889    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
23890         (NVL(l_actual_upg_option, 'N') = 'O') OR
23891         (NVL(l_enc_upg_option, 'N') = 'O')
23892       )
23893    THEN
23894    NULL;
23895    --
23896    --
23897    
23898   l_ccid := AcctDerRule_174(
23899            p_application_id           => p_application_id
23900          , p_ae_header_id             => l_ae_header_id 
23901 , p_source_3 => p_source_3
23902 , p_source_17 => p_source_17
23903 , p_source_30 => p_source_30
23904          , x_transaction_coa_id       => l_adr_transaction_coa_id
23905          , x_accounting_coa_id        => l_adr_accounting_coa_id
23906          , x_value_type_code          => l_adr_value_type_code
23907          , p_side                     => 'NA'
23908    );
23909 
23910    xla_ae_lines_pkg.set_ccid(
23911     p_code_combination_id          => l_ccid
23912   , p_value_type_code              => l_adr_value_type_code
23913   , p_transaction_coa_id           => l_adr_transaction_coa_id
23914   , p_accounting_coa_id            => l_adr_accounting_coa_id
23915   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
23916   , p_adr_type_code                => 'S'
23917   , p_component_type               => l_component_type
23918   , p_component_code               => l_component_code
23919   , p_component_type_code          => l_component_type_code
23920   , p_component_appl_id            => l_component_appl_id
23921   , p_amb_context_code             => l_amb_context_code
23922   , p_side                         => 'NA'
23923   );
23924 
23925 
23926    l_segment := AcctDerRule_149(
23927            p_application_id           => p_application_id
23928          , p_ae_header_id             => l_ae_header_id 
23929 , p_source_3 => p_source_3
23930 , p_source_10 => p_source_10
23931          , x_transaction_coa_id       => l_adr_transaction_coa_id
23932          , x_accounting_coa_id        => l_adr_accounting_coa_id
23933          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23934          , x_flex_value_set_id        => l_adr_flex_value_set_id
23935          , x_value_type_code          => l_adr_value_type_code
23936          , x_value_combination_id     => l_adr_value_combination_id
23937          , x_value_segment_code       => l_adr_value_segment_code
23938          , p_side                     => 'NA'
23939          , p_override_seg_flag        => 'Y'
23940    );
23941 
23942    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23943 
23944       xla_ae_lines_pkg.set_segment(
23945           p_to_segment_code         => 'GL_ACCOUNT'
23946         , p_segment_value           => l_segment
23947         , p_from_segment_code       => l_adr_value_segment_code
23948         , p_from_combination_id     => l_adr_value_combination_id
23949         , p_value_type_code         => l_adr_value_type_code
23950         , p_transaction_coa_id      => l_adr_transaction_coa_id
23951         , p_accounting_coa_id       => l_adr_accounting_coa_id
23952         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23953         , p_flex_value_set_id       => l_adr_flex_value_set_id
23954         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
23958         , p_component_type_code     => l_component_type_code
23955         , p_adr_type_code           => 'S'
23956         , p_component_type          => l_component_type
23957         , p_component_code          => l_component_code
23959         , p_component_appl_id       => l_component_appl_id
23960         , p_amb_context_code        => l_amb_context_code
23961         , p_entity_code             => 'TRANSACTIONS'
23962         , p_event_class_code        => 'ADDITIONS'
23963         , p_side                    => 'NA'
23964         );
23965 
23966   END IF;
23967 
23968    l_segment := AcctDerRule_168(
23969            p_application_id           => p_application_id
23970          , p_ae_header_id             => l_ae_header_id 
23971 , p_source_3 => p_source_3
23972 , p_source_29 => p_source_29
23973          , x_transaction_coa_id       => l_adr_transaction_coa_id
23974          , x_accounting_coa_id        => l_adr_accounting_coa_id
23975          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23976          , x_flex_value_set_id        => l_adr_flex_value_set_id
23977          , x_value_type_code          => l_adr_value_type_code
23978          , x_value_combination_id     => l_adr_value_combination_id
23979          , x_value_segment_code       => l_adr_value_segment_code
23980          , p_side                     => 'NA'
23981          , p_override_seg_flag        => 'Y'
23982    );
23983 
23984    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23985 
23986       xla_ae_lines_pkg.set_segment(
23987           p_to_segment_code         => 'GL_BALANCING'
23988         , p_segment_value           => l_segment
23989         , p_from_segment_code       => l_adr_value_segment_code
23990         , p_from_combination_id     => l_adr_value_combination_id
23991         , p_value_type_code         => l_adr_value_type_code
23992         , p_transaction_coa_id      => l_adr_transaction_coa_id
23993         , p_accounting_coa_id       => l_adr_accounting_coa_id
23994         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23995         , p_flex_value_set_id       => l_adr_flex_value_set_id
23996         , p_adr_code                => 'FA_EXPENSE_ACCT'
23997         , p_adr_type_code           => 'S'
23998         , p_component_type          => l_component_type
23999         , p_component_code          => l_component_code
24000         , p_component_type_code     => l_component_type_code
24001         , p_component_appl_id       => l_component_appl_id
24002         , p_amb_context_code        => l_amb_context_code
24003         , p_entity_code             => 'TRANSACTIONS'
24004         , p_event_class_code        => 'ADDITIONS'
24005         , p_side                    => 'NA'
24006         );
24007 
24008   END IF;
24009 
24010    --
24011    --
24012    END IF;
24013 
24014        --
24015        -- Update the line information that should be overwritten
24016        --
24017        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
24018                                          p_header_num   => 1);
24019        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
24020 
24021        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
24022 
24023        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
24024           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
24025        END IF;
24026 
24027       --
24028       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
24029       --
24030       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
24031           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
24032       ELSE
24033           ---------------------------------------------------------------------------------------------------
24034           -- 4262811a Switch Sign
24035           ---------------------------------------------------------------------------------------------------
24036           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
24037           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
24038                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24039           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
24040                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24041           -- 5132302
24042           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
24043                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24044 
24045       END IF;
24046 
24047       -- 4955764
24048       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
24049       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
24050 
24051 
24052       XLA_AE_LINES_PKG.ValidateCurrentLine;
24053       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
24054 
24055       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
24056                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
24057                ,p_balance_type_code => l_balance_type_code);
24058 
24059    END IF;
24060 
24061    -----------------------------------------------------------------------------------------
24062    -- 4262811 Multiperiod Accounting
24063    -----------------------------------------------------------------------------------------
24064      -- No MPA option is assigned.
24065 
24066 
24067 END IF;
24068 END IF;
24069 --
24070 
24071 --
24072 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24076       ,p_module   => l_log_module);
24073    trace
24074       (p_msg      => 'END of AcctLineType_187'
24075       ,p_level    => C_LEVEL_PROCEDURE
24077 END IF;
24078 --
24079 EXCEPTION
24080   WHEN xla_exceptions_pkg.application_exception THEN
24081       RAISE;
24082   WHEN OTHERS THEN
24083        xla_exceptions_pkg.raise_message
24084            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_187');
24085 END AcctLineType_187;
24086 --
24087 
24088 ---------------------------------------
24089 --
24090 -- PRIVATE FUNCTION
24091 --         AcctLineType_188
24092 --
24093 ---------------------------------------
24094 PROCEDURE AcctLineType_188 (
24095   p_application_id        IN NUMBER
24096  ,p_event_id              IN NUMBER
24097  ,p_calculate_acctd_flag  IN VARCHAR2
24098  ,p_calculate_g_l_flag    IN VARCHAR2
24099  ,p_actual_flag           IN OUT VARCHAR2
24100  ,p_balance_type_code     OUT VARCHAR2
24101  ,p_gain_or_loss_ref      OUT VARCHAR2
24102  
24103 --Period Close Date
24104  , p_source_1            IN DATE
24105 --Generated Code Combination Identifier
24106  , p_source_3            IN NUMBER
24107 --Depreciation Reserve Account
24108  , p_source_10            IN VARCHAR2
24109 --Generated Offset Code Combination Identifier
24110  , p_source_17            IN NUMBER
24111 --Expense Account Code Combination Identifier
24112  , p_source_29            IN NUMBER
24113 --Default Code Combination Identifier
24114  , p_source_30            IN NUMBER
24115 --Adjustment Type
24116  , p_source_35            IN VARCHAR2
24117 --Transaction Header Identifier
24118  , p_source_36            IN NUMBER
24119 --Adjustment Line Identifier
24120  , p_source_37            IN NUMBER
24121 --Distribution Type Code
24122  , p_source_38            IN VARCHAR2
24123 --Entered Amount
24124  , p_source_39            IN NUMBER
24125 --Currency Code
24126  , p_source_40            IN VARCHAR2
24127 )
24128 IS
24129 
24130 l_component_type              VARCHAR2(80);
24131 l_component_code              VARCHAR2(30);
24132 l_component_type_code         VARCHAR2(1);
24133 l_component_appl_id           INTEGER;
24134 l_amb_context_code            VARCHAR2(30);
24135 l_entity_code                 VARCHAR2(30);
24136 l_event_class_code            VARCHAR2(30);
24137 l_ae_header_id                NUMBER;
24138 l_event_type_code             VARCHAR2(30);
24139 l_line_definition_code        VARCHAR2(30);
24140 l_line_definition_owner_code  VARCHAR2(1);
24141 --
24142 -- adr variables
24143 l_segment                     VARCHAR2(30);
24144 l_ccid                        NUMBER;
24145 l_adr_transaction_coa_id      NUMBER;
24146 l_adr_accounting_coa_id       NUMBER;
24147 l_adr_flexfield_segment_code  VARCHAR2(30);
24148 l_adr_flex_value_set_id       NUMBER;
24149 l_adr_value_type_code         VARCHAR2(30);
24150 l_adr_value_combination_id    NUMBER;
24151 l_adr_value_segment_code      VARCHAR2(30);
24152 
24153 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
24154 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
24155 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
24156 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
24157 
24158 -- 4262811 Variables ------------------------------------------------------------------------------------------
24159 l_entered_amt_idx             NUMBER;
24160 l_accted_amt_idx              NUMBER;
24161 l_acc_rev_flag                VARCHAR2(1);
24162 l_accrual_line_num            NUMBER;
24163 l_tmp_amt                     NUMBER;
24164 l_acc_rev_natural_side_code   VARCHAR2(1);
24165 
24166 l_num_entries                 NUMBER;
24167 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
24168 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
24169 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
24170 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
24171 l_recog_line_1                NUMBER;
24172 l_recog_line_2                NUMBER;
24173 
24174 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
24175 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
24176 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
24177 
24178 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
24179 
24180 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
24181 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
24182 
24183 ---------------------------------------------------------------------------------------------------------------
24184 
24185 
24186 --
24187 -- bulk performance
24188 --
24189 l_balance_type_code           VARCHAR2(1);
24190 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
24191 l_log_module                  VARCHAR2(240);
24192 
24193 --
24194 -- Upgrade strategy
24195 --
24196 l_actual_upg_option           VARCHAR2(1);
24197 l_enc_upg_option           VARCHAR2(1);
24198 
24199 --
24200 BEGIN
24201 --
24202 IF g_log_enabled THEN
24203       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_188';
24204 END IF;
24205 --
24206 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24207 
24208       trace
24209          (p_msg      => 'BEGIN of AcctLineType_188'
24210          ,p_level    => C_LEVEL_PROCEDURE
24211          ,p_module   => l_log_module);
24212 
24213 END IF;
24214 --
24215 l_component_type             := 'AMB_JLT';
24216 l_component_code             := 'FA_ADD_RESERVE_BAL';
24217 l_component_type_code        := 'S';
24218 l_component_appl_id          :=  140;
24219 l_amb_context_code           := 'DEFAULT';
24223 l_line_definition_owner_code := 'S';
24220 l_entity_code                := 'TRANSACTIONS';
24221 l_event_class_code           := 'ADDITIONS';
24222 l_event_type_code            := 'ADDITIONS_ALL';
24224 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADDITI1';
24225 --
24226 l_balance_type_code          := 'A';
24227 l_segment                     := NULL;
24228 l_ccid                        := NULL;
24229 l_adr_transaction_coa_id      := NULL;
24230 l_adr_accounting_coa_id       := NULL;
24231 l_adr_flexfield_segment_code  := NULL;
24232 l_adr_flex_value_set_id       := NULL;
24233 l_adr_value_type_code         := NULL;
24234 l_adr_value_combination_id    := NULL;
24235 l_adr_value_segment_code      := NULL;
24236 
24237 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
24238 l_bflow_class_code           := '';    -- 4219869 Business Flow
24239 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
24240 l_budgetary_control_flag     := 'N';
24241 
24242 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
24243 l_bflow_applied_to_amt       := NULL; -- 5132302
24244 l_entered_amt_idx            := NULL;          -- 4262811
24245 l_accted_amt_idx             := NULL;          -- 4262811
24246 l_acc_rev_flag               := NULL;          -- 4262811
24247 l_accrual_line_num           := NULL;          -- 4262811
24248 l_tmp_amt                    := NULL;          -- 4262811
24249 --
24250  
24251 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
24252     l_balance_type_code <> 'B' THEN
24253 IF NVL(p_source_35,'
24254 ') =  'BONUS EXPENSE'
24255  THEN 
24256 
24257    --
24258    XLA_AE_LINES_PKG.SetNewLine;
24259 
24260    p_balance_type_code          := l_balance_type_code;
24261    -- set the flag so later we will know whether the gain loss line needs to be created
24262    
24263    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
24264      p_actual_flag :='A';
24265    END IF;
24266 
24267    --
24268    -- bulk performance
24269    --
24270    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
24271                                       p_header_num   => 0); -- 4262811
24272    --
24273    -- set accounting line options
24274    --
24275    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
24276            p_natural_side_code          => 'D'
24277          , p_gain_or_loss_flag          => 'N'
24278          , p_gl_transfer_mode_code      => 'S'
24279          , p_acct_entry_type_code       => 'A'
24280          , p_switch_side_flag           => 'Y'
24281          , p_merge_duplicate_code       => 'N'
24282          );
24283    --
24284    l_acc_rev_natural_side_code := 'C';  -- 4262811
24285    -- 
24286    --
24287    -- set accounting line type info
24288    --
24289    xla_ae_lines_pkg.SetAcctLineType
24290       (p_component_type             => l_component_type
24291       ,p_event_type_code            => l_event_type_code
24292       ,p_line_definition_owner_code => l_line_definition_owner_code
24293       ,p_line_definition_code       => l_line_definition_code
24294       ,p_accounting_line_code       => l_component_code
24295       ,p_accounting_line_type_code  => l_component_type_code
24296       ,p_accounting_line_appl_id    => l_component_appl_id
24297       ,p_amb_context_code           => l_amb_context_code
24298       ,p_entity_code                => l_entity_code
24299       ,p_event_class_code           => l_event_class_code);
24300    --
24301    -- set accounting class
24302    --
24303    xla_ae_lines_pkg.SetAcctClass(
24304            p_accounting_class_code  => 'ASSET'
24305          , p_ae_header_id           => l_ae_header_id
24306          );
24307 
24308    --
24309    -- set rounding class
24310    --
24311    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
24312                       'ASSET';
24313 
24314    --
24315    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
24316    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
24317    --
24318    -- bulk performance
24319    --
24320    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
24321 
24322    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
24323       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
24324 
24325    -- 4955764
24326    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
24327       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
24328 
24329    -- 4458381 Public Sector Enh
24330    
24331    --
24332    -- set accounting attributes for the line type
24333    --
24334    l_entered_amt_idx := 4;
24335    l_accted_amt_idx  := 6;
24336    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
24337    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
24338    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
24339    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
24340    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
24341    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
24342    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
24343    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
24344    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
24345    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
24346    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
24347    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
24348    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
24349 
24350    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
24354    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
24351    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
24352 
24353    ---------------------------------------------------------------------------------------------------------------
24355    ---------------------------------------------------------------------------------------------------------------
24356    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
24357 
24358    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24359    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24360 
24361    IF xla_accounting_cache_pkg.GetValueChar
24362          (p_source_code         => 'LEDGER_CATEGORY_CODE'
24363          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
24364    AND l_bflow_method_code = 'PRIOR_ENTRY'
24365 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
24366    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
24367          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
24368        )
24369    THEN
24370          xla_ae_lines_pkg.BflowUpgEntry
24371            (p_business_method_code    => l_bflow_method_code
24372            ,p_business_class_code     => l_bflow_class_code
24373            ,p_balance_type            => l_balance_type_code);
24374    ELSE
24375       NULL;
24376 -- No business flow processing for business flow method of NONE.
24377    END IF;
24378 
24379    --
24380    -- call analytical criteria
24381    --
24382    
24383    --
24384    -- call description
24385    --
24386    
24387 xla_ae_lines_pkg.SetLineDescription(
24388    p_ae_header_id => l_ae_header_id
24389   ,p_description  => Description_7 (
24390      p_application_id         => p_application_id
24391    , p_ae_header_id           => l_ae_header_id 
24392 , p_source_1 => p_source_1
24393    )
24394 );
24395 
24396 
24397    --
24398    -- call ADRs
24399    -- Bug 4922099
24400    --
24401    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
24402         (NVL(l_actual_upg_option, 'N') = 'O') OR
24403         (NVL(l_enc_upg_option, 'N') = 'O')
24404       )
24405    THEN
24406    NULL;
24407    --
24408    --
24409    
24410   l_ccid := AcctDerRule_174(
24411            p_application_id           => p_application_id
24412          , p_ae_header_id             => l_ae_header_id 
24413 , p_source_3 => p_source_3
24414 , p_source_17 => p_source_17
24415 , p_source_30 => p_source_30
24416          , x_transaction_coa_id       => l_adr_transaction_coa_id
24417          , x_accounting_coa_id        => l_adr_accounting_coa_id
24418          , x_value_type_code          => l_adr_value_type_code
24419          , p_side                     => 'NA'
24420    );
24421 
24422    xla_ae_lines_pkg.set_ccid(
24423     p_code_combination_id          => l_ccid
24424   , p_value_type_code              => l_adr_value_type_code
24425   , p_transaction_coa_id           => l_adr_transaction_coa_id
24426   , p_accounting_coa_id            => l_adr_accounting_coa_id
24427   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
24428   , p_adr_type_code                => 'S'
24429   , p_component_type               => l_component_type
24430   , p_component_code               => l_component_code
24431   , p_component_type_code          => l_component_type_code
24432   , p_component_appl_id            => l_component_appl_id
24433   , p_amb_context_code             => l_amb_context_code
24434   , p_side                         => 'NA'
24435   );
24436 
24437 
24438    l_segment := AcctDerRule_149(
24439            p_application_id           => p_application_id
24440          , p_ae_header_id             => l_ae_header_id 
24441 , p_source_3 => p_source_3
24442 , p_source_10 => p_source_10
24443          , x_transaction_coa_id       => l_adr_transaction_coa_id
24444          , x_accounting_coa_id        => l_adr_accounting_coa_id
24445          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24446          , x_flex_value_set_id        => l_adr_flex_value_set_id
24447          , x_value_type_code          => l_adr_value_type_code
24448          , x_value_combination_id     => l_adr_value_combination_id
24449          , x_value_segment_code       => l_adr_value_segment_code
24450          , p_side                     => 'NA'
24451          , p_override_seg_flag        => 'Y'
24452    );
24453 
24454    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24455 
24456       xla_ae_lines_pkg.set_segment(
24457           p_to_segment_code         => 'GL_ACCOUNT'
24458         , p_segment_value           => l_segment
24459         , p_from_segment_code       => l_adr_value_segment_code
24460         , p_from_combination_id     => l_adr_value_combination_id
24461         , p_value_type_code         => l_adr_value_type_code
24462         , p_transaction_coa_id      => l_adr_transaction_coa_id
24463         , p_accounting_coa_id       => l_adr_accounting_coa_id
24464         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24465         , p_flex_value_set_id       => l_adr_flex_value_set_id
24466         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
24467         , p_adr_type_code           => 'S'
24468         , p_component_type          => l_component_type
24469         , p_component_code          => l_component_code
24470         , p_component_type_code     => l_component_type_code
24471         , p_component_appl_id       => l_component_appl_id
24472         , p_amb_context_code        => l_amb_context_code
24473         , p_entity_code             => 'TRANSACTIONS'
24474         , p_event_class_code        => 'ADDITIONS'
24475         , p_side                    => 'NA'
24479 
24476         );
24477 
24478   END IF;
24480    l_segment := AcctDerRule_168(
24481            p_application_id           => p_application_id
24482          , p_ae_header_id             => l_ae_header_id 
24483 , p_source_3 => p_source_3
24484 , p_source_29 => p_source_29
24485          , x_transaction_coa_id       => l_adr_transaction_coa_id
24486          , x_accounting_coa_id        => l_adr_accounting_coa_id
24487          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24488          , x_flex_value_set_id        => l_adr_flex_value_set_id
24489          , x_value_type_code          => l_adr_value_type_code
24490          , x_value_combination_id     => l_adr_value_combination_id
24491          , x_value_segment_code       => l_adr_value_segment_code
24492          , p_side                     => 'NA'
24493          , p_override_seg_flag        => 'Y'
24494    );
24495 
24496    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24497 
24498       xla_ae_lines_pkg.set_segment(
24499           p_to_segment_code         => 'GL_BALANCING'
24500         , p_segment_value           => l_segment
24501         , p_from_segment_code       => l_adr_value_segment_code
24502         , p_from_combination_id     => l_adr_value_combination_id
24503         , p_value_type_code         => l_adr_value_type_code
24504         , p_transaction_coa_id      => l_adr_transaction_coa_id
24505         , p_accounting_coa_id       => l_adr_accounting_coa_id
24506         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24507         , p_flex_value_set_id       => l_adr_flex_value_set_id
24508         , p_adr_code                => 'FA_EXPENSE_ACCT'
24509         , p_adr_type_code           => 'S'
24510         , p_component_type          => l_component_type
24511         , p_component_code          => l_component_code
24512         , p_component_type_code     => l_component_type_code
24513         , p_component_appl_id       => l_component_appl_id
24514         , p_amb_context_code        => l_amb_context_code
24515         , p_entity_code             => 'TRANSACTIONS'
24516         , p_event_class_code        => 'ADDITIONS'
24517         , p_side                    => 'NA'
24518         );
24519 
24520   END IF;
24521 
24522    --
24523    --
24524    END IF;
24525    --
24526    -- Bug 4922099
24527    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
24528           (NVL(l_enc_upg_option, 'N') = 'O')
24529         ) AND
24530         (l_bflow_method_code = 'PRIOR_ENTRY')
24531       )
24532    THEN
24533       IF
24534       --
24535       1 = 2
24536       --
24537       THEN
24538       xla_accounting_err_pkg.build_message
24539                                     (p_appli_s_name            => 'XLA'
24540                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
24541                                     ,p_token_1                 => 'LINE_NUMBER'
24542                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
24543                                     ,p_token_2                 => 'LINE_TYPE_NAME'
24544                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
24545                                                                              l_component_type
24546                                                                             ,l_component_code
24547                                                                             ,l_component_type_code
24548                                                                             ,l_component_appl_id
24549                                                                             ,l_amb_context_code
24550                                                                             ,l_entity_code
24551                                                                             ,l_event_class_code
24552                                                                            )
24553                                     ,p_token_3                 => 'OWNER'
24554                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
24555                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
24556                                                                           ,p_lookup_code    => l_component_type_code
24557                                                                          )
24558                                     ,p_token_4                 => 'PRODUCT_NAME'
24559                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
24560                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
24561                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
24562                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
24563                                     ,p_ae_header_id            =>  NULL
24564                                        );
24565 
24566         IF (C_LEVEL_ERROR>= g_log_level) THEN
24567                  trace
24568                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
24569                       ,p_level    => C_LEVEL_ERROR
24570                       ,p_module   => l_log_module);
24571         END IF;
24572       END IF;
24573    END IF;
24574    --
24575    --
24576    ------------------------------------------------------------------------------------------------
24577    -- 4219869 Business Flow
24578    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
24579    -- Prior Entry.  Currently, the following code is always generated.
24580    ------------------------------------------------------------------------------------------------
24581    XLA_AE_LINES_PKG.ValidateCurrentLine;
24582 
24586    ------------------------------------------------------------------------------------
24583    ------------------------------------------------------------------------------------
24584    -- 4219869 Business Flow
24585    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
24587    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
24588 
24589    ----------------------------------------------------------------------------------
24590    -- 4219869 Business Flow
24591    -- Update journal entry status -- Need to generate this within IF <condition>
24592    ----------------------------------------------------------------------------------
24593    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
24594          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
24595          ,p_balance_type_code => l_balance_type_code
24596          );
24597 
24598    -------------------------------------------------------------------------------------------
24599    -- 4262811 - Generate the Accrual Reversal lines
24600    -------------------------------------------------------------------------------------------
24601    BEGIN
24602       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
24603                               (g_array_event(p_event_id).array_value_num('header_index'));
24604       IF l_acc_rev_flag IS NULL THEN
24605          l_acc_rev_flag := 'N';
24606       END IF;
24607    EXCEPTION
24608       WHEN OTHERS THEN
24609          l_acc_rev_flag := 'N';
24610    END;
24611    --
24612    IF (l_acc_rev_flag = 'Y') THEN
24613 
24614        -- 4645092  ------------------------------------------------------------------------------
24615        -- To allow MPA report to determine if it should generate report process
24616        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
24617        ------------------------------------------------------------------------------------------
24618 
24619        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
24620        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
24621    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
24622    -- call ADRs
24623    -- Bug 4922099
24624    --
24625    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
24626         (NVL(l_actual_upg_option, 'N') = 'O') OR
24627         (NVL(l_enc_upg_option, 'N') = 'O')
24628       )
24629    THEN
24630    NULL;
24631    --
24632    --
24633    
24634   l_ccid := AcctDerRule_174(
24635            p_application_id           => p_application_id
24636          , p_ae_header_id             => l_ae_header_id 
24637 , p_source_3 => p_source_3
24638 , p_source_17 => p_source_17
24639 , p_source_30 => p_source_30
24640          , x_transaction_coa_id       => l_adr_transaction_coa_id
24641          , x_accounting_coa_id        => l_adr_accounting_coa_id
24642          , x_value_type_code          => l_adr_value_type_code
24643          , p_side                     => 'NA'
24644    );
24645 
24646    xla_ae_lines_pkg.set_ccid(
24647     p_code_combination_id          => l_ccid
24648   , p_value_type_code              => l_adr_value_type_code
24649   , p_transaction_coa_id           => l_adr_transaction_coa_id
24650   , p_accounting_coa_id            => l_adr_accounting_coa_id
24651   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
24652   , p_adr_type_code                => 'S'
24653   , p_component_type               => l_component_type
24654   , p_component_code               => l_component_code
24655   , p_component_type_code          => l_component_type_code
24656   , p_component_appl_id            => l_component_appl_id
24657   , p_amb_context_code             => l_amb_context_code
24658   , p_side                         => 'NA'
24659   );
24660 
24661 
24662    l_segment := AcctDerRule_149(
24663            p_application_id           => p_application_id
24664          , p_ae_header_id             => l_ae_header_id 
24665 , p_source_3 => p_source_3
24666 , p_source_10 => p_source_10
24667          , x_transaction_coa_id       => l_adr_transaction_coa_id
24668          , x_accounting_coa_id        => l_adr_accounting_coa_id
24669          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24670          , x_flex_value_set_id        => l_adr_flex_value_set_id
24671          , x_value_type_code          => l_adr_value_type_code
24672          , x_value_combination_id     => l_adr_value_combination_id
24673          , x_value_segment_code       => l_adr_value_segment_code
24674          , p_side                     => 'NA'
24675          , p_override_seg_flag        => 'Y'
24676    );
24677 
24678    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24679 
24680       xla_ae_lines_pkg.set_segment(
24681           p_to_segment_code         => 'GL_ACCOUNT'
24682         , p_segment_value           => l_segment
24683         , p_from_segment_code       => l_adr_value_segment_code
24684         , p_from_combination_id     => l_adr_value_combination_id
24685         , p_value_type_code         => l_adr_value_type_code
24686         , p_transaction_coa_id      => l_adr_transaction_coa_id
24687         , p_accounting_coa_id       => l_adr_accounting_coa_id
24688         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24689         , p_flex_value_set_id       => l_adr_flex_value_set_id
24690         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
24691         , p_adr_type_code           => 'S'
24692         , p_component_type          => l_component_type
24693         , p_component_code          => l_component_code
24694         , p_component_type_code     => l_component_type_code
24695         , p_component_appl_id       => l_component_appl_id
24696         , p_amb_context_code        => l_amb_context_code
24697         , p_entity_code             => 'TRANSACTIONS'
24698         , p_event_class_code        => 'ADDITIONS'
24699         , p_side                    => 'NA'
24700         );
24701 
24705            p_application_id           => p_application_id
24702   END IF;
24703 
24704    l_segment := AcctDerRule_168(
24706          , p_ae_header_id             => l_ae_header_id 
24707 , p_source_3 => p_source_3
24708 , p_source_29 => p_source_29
24709          , x_transaction_coa_id       => l_adr_transaction_coa_id
24710          , x_accounting_coa_id        => l_adr_accounting_coa_id
24711          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24712          , x_flex_value_set_id        => l_adr_flex_value_set_id
24713          , x_value_type_code          => l_adr_value_type_code
24714          , x_value_combination_id     => l_adr_value_combination_id
24715          , x_value_segment_code       => l_adr_value_segment_code
24716          , p_side                     => 'NA'
24717          , p_override_seg_flag        => 'Y'
24718    );
24719 
24720    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24721 
24722       xla_ae_lines_pkg.set_segment(
24723           p_to_segment_code         => 'GL_BALANCING'
24724         , p_segment_value           => l_segment
24725         , p_from_segment_code       => l_adr_value_segment_code
24726         , p_from_combination_id     => l_adr_value_combination_id
24727         , p_value_type_code         => l_adr_value_type_code
24728         , p_transaction_coa_id      => l_adr_transaction_coa_id
24729         , p_accounting_coa_id       => l_adr_accounting_coa_id
24730         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24731         , p_flex_value_set_id       => l_adr_flex_value_set_id
24732         , p_adr_code                => 'FA_EXPENSE_ACCT'
24733         , p_adr_type_code           => 'S'
24734         , p_component_type          => l_component_type
24735         , p_component_code          => l_component_code
24736         , p_component_type_code     => l_component_type_code
24737         , p_component_appl_id       => l_component_appl_id
24738         , p_amb_context_code        => l_amb_context_code
24739         , p_entity_code             => 'TRANSACTIONS'
24740         , p_event_class_code        => 'ADDITIONS'
24741         , p_side                    => 'NA'
24742         );
24743 
24744   END IF;
24745 
24746    --
24747    --
24748    END IF;
24749 
24750        --
24751        -- Update the line information that should be overwritten
24752        --
24753        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
24754                                          p_header_num   => 1);
24755        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
24756 
24757        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
24758 
24759        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
24760           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
24761        END IF;
24762 
24763       --
24764       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
24765       --
24766       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
24767           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
24768       ELSE
24769           ---------------------------------------------------------------------------------------------------
24770           -- 4262811a Switch Sign
24771           ---------------------------------------------------------------------------------------------------
24772           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
24773           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
24774                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24775           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
24776                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24777           -- 5132302
24778           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
24779                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24780 
24781       END IF;
24782 
24783       -- 4955764
24784       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
24785       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
24786 
24787 
24788       XLA_AE_LINES_PKG.ValidateCurrentLine;
24789       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
24790 
24791       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
24792                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
24793                ,p_balance_type_code => l_balance_type_code);
24794 
24795    END IF;
24796 
24797    -----------------------------------------------------------------------------------------
24798    -- 4262811 Multiperiod Accounting
24799    -----------------------------------------------------------------------------------------
24800      -- No MPA option is assigned.
24801 
24802 
24803 END IF;
24804 END IF;
24805 --
24806 
24807 --
24808 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24809    trace
24810       (p_msg      => 'END of AcctLineType_188'
24811       ,p_level    => C_LEVEL_PROCEDURE
24812       ,p_module   => l_log_module);
24813 END IF;
24814 --
24815 EXCEPTION
24816   WHEN xla_exceptions_pkg.application_exception THEN
24817       RAISE;
24818   WHEN OTHERS THEN
24819        xla_exceptions_pkg.raise_message
24820            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_188');
24821 END AcctLineType_188;
24822 --
24823 
24824 ---------------------------------------
24828 --
24825 --
24826 -- PRIVATE FUNCTION
24827 --         AcctLineType_189
24829 ---------------------------------------
24830 PROCEDURE AcctLineType_189 (
24831   p_application_id        IN NUMBER
24832  ,p_event_id              IN NUMBER
24833  ,p_calculate_acctd_flag  IN VARCHAR2
24834  ,p_calculate_g_l_flag    IN VARCHAR2
24835  ,p_actual_flag           IN OUT VARCHAR2
24836  ,p_balance_type_code     OUT VARCHAR2
24837  ,p_gain_or_loss_ref      OUT VARCHAR2
24838  
24839 --Period Close Date
24840  , p_source_1            IN DATE
24841 --Bonus Depreciation Expense Account
24842  , p_source_2            IN VARCHAR2
24843 --Generated Code Combination Identifier
24844  , p_source_3            IN NUMBER
24845 --Expense Account Code Combination Identifier
24846  , p_source_29            IN NUMBER
24847 --Adjustment Type
24848  , p_source_35            IN VARCHAR2
24849 --Transaction Header Identifier
24850  , p_source_36            IN NUMBER
24851 --Adjustment Line Identifier
24852  , p_source_37            IN NUMBER
24853 --Distribution Type Code
24854  , p_source_38            IN VARCHAR2
24855 --Entered Amount
24856  , p_source_39            IN NUMBER
24857 --Currency Code
24858  , p_source_40            IN VARCHAR2
24859 )
24860 IS
24861 
24862 l_component_type              VARCHAR2(80);
24863 l_component_code              VARCHAR2(30);
24864 l_component_type_code         VARCHAR2(1);
24865 l_component_appl_id           INTEGER;
24866 l_amb_context_code            VARCHAR2(30);
24867 l_entity_code                 VARCHAR2(30);
24868 l_event_class_code            VARCHAR2(30);
24869 l_ae_header_id                NUMBER;
24870 l_event_type_code             VARCHAR2(30);
24871 l_line_definition_code        VARCHAR2(30);
24872 l_line_definition_owner_code  VARCHAR2(1);
24873 --
24874 -- adr variables
24875 l_segment                     VARCHAR2(30);
24876 l_ccid                        NUMBER;
24877 l_adr_transaction_coa_id      NUMBER;
24878 l_adr_accounting_coa_id       NUMBER;
24879 l_adr_flexfield_segment_code  VARCHAR2(30);
24880 l_adr_flex_value_set_id       NUMBER;
24881 l_adr_value_type_code         VARCHAR2(30);
24882 l_adr_value_combination_id    NUMBER;
24883 l_adr_value_segment_code      VARCHAR2(30);
24884 
24885 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
24886 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
24887 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
24888 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
24889 
24890 -- 4262811 Variables ------------------------------------------------------------------------------------------
24891 l_entered_amt_idx             NUMBER;
24892 l_accted_amt_idx              NUMBER;
24893 l_acc_rev_flag                VARCHAR2(1);
24894 l_accrual_line_num            NUMBER;
24895 l_tmp_amt                     NUMBER;
24896 l_acc_rev_natural_side_code   VARCHAR2(1);
24897 
24898 l_num_entries                 NUMBER;
24899 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
24900 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
24901 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
24902 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
24903 l_recog_line_1                NUMBER;
24904 l_recog_line_2                NUMBER;
24905 
24906 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
24907 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
24908 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
24909 
24910 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
24911 
24912 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
24913 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
24914 
24915 ---------------------------------------------------------------------------------------------------------------
24916 
24917 
24918 --
24919 -- bulk performance
24920 --
24921 l_balance_type_code           VARCHAR2(1);
24922 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
24923 l_log_module                  VARCHAR2(240);
24924 
24925 --
24926 -- Upgrade strategy
24927 --
24928 l_actual_upg_option           VARCHAR2(1);
24929 l_enc_upg_option           VARCHAR2(1);
24930 
24931 --
24932 BEGIN
24933 --
24934 IF g_log_enabled THEN
24935       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_189';
24936 END IF;
24937 --
24938 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24939 
24940       trace
24941          (p_msg      => 'BEGIN of AcctLineType_189'
24942          ,p_level    => C_LEVEL_PROCEDURE
24943          ,p_module   => l_log_module);
24944 
24945 END IF;
24946 --
24947 l_component_type             := 'AMB_JLT';
24948 l_component_code             := 'FA_ADJ_BONUS_EXP';
24949 l_component_type_code        := 'S';
24950 l_component_appl_id          :=  140;
24951 l_amb_context_code           := 'DEFAULT';
24952 l_entity_code                := 'TRANSACTIONS';
24953 l_event_class_code           := 'ADJUSTMENTS';
24954 l_event_type_code            := 'ADJUSTMENTS_ALL';
24955 l_line_definition_owner_code := 'S';
24956 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
24957 --
24958 l_balance_type_code          := 'A';
24959 l_segment                     := NULL;
24960 l_ccid                        := NULL;
24961 l_adr_transaction_coa_id      := NULL;
24962 l_adr_accounting_coa_id       := NULL;
24963 l_adr_flexfield_segment_code  := NULL;
24964 l_adr_flex_value_set_id       := NULL;
24965 l_adr_value_type_code         := NULL;
24966 l_adr_value_combination_id    := NULL;
24970 l_bflow_class_code           := '';    -- 4219869 Business Flow
24967 l_adr_value_segment_code      := NULL;
24968 
24969 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
24971 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
24972 l_budgetary_control_flag     := 'N';
24973 
24974 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
24975 l_bflow_applied_to_amt       := NULL; -- 5132302
24976 l_entered_amt_idx            := NULL;          -- 4262811
24977 l_accted_amt_idx             := NULL;          -- 4262811
24978 l_acc_rev_flag               := NULL;          -- 4262811
24979 l_accrual_line_num           := NULL;          -- 4262811
24980 l_tmp_amt                    := NULL;          -- 4262811
24981 --
24982  
24983 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
24984     l_balance_type_code <> 'B' THEN
24985 IF NVL(p_source_35,'
24986 ') =  'BONUS EXPENSE'
24987  THEN 
24988 
24989    --
24990    XLA_AE_LINES_PKG.SetNewLine;
24991 
24992    p_balance_type_code          := l_balance_type_code;
24993    -- set the flag so later we will know whether the gain loss line needs to be created
24994    
24995    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
24996      p_actual_flag :='A';
24997    END IF;
24998 
24999    --
25000    -- bulk performance
25001    --
25002    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
25003                                       p_header_num   => 0); -- 4262811
25004    --
25005    -- set accounting line options
25006    --
25007    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
25008            p_natural_side_code          => 'D'
25009          , p_gain_or_loss_flag          => 'N'
25010          , p_gl_transfer_mode_code      => 'S'
25011          , p_acct_entry_type_code       => 'A'
25012          , p_switch_side_flag           => 'Y'
25013          , p_merge_duplicate_code       => 'N'
25014          );
25015    --
25016    l_acc_rev_natural_side_code := 'C';  -- 4262811
25017    -- 
25018    --
25019    -- set accounting line type info
25020    --
25021    xla_ae_lines_pkg.SetAcctLineType
25022       (p_component_type             => l_component_type
25023       ,p_event_type_code            => l_event_type_code
25024       ,p_line_definition_owner_code => l_line_definition_owner_code
25025       ,p_line_definition_code       => l_line_definition_code
25026       ,p_accounting_line_code       => l_component_code
25027       ,p_accounting_line_type_code  => l_component_type_code
25028       ,p_accounting_line_appl_id    => l_component_appl_id
25029       ,p_amb_context_code           => l_amb_context_code
25030       ,p_entity_code                => l_entity_code
25031       ,p_event_class_code           => l_event_class_code);
25032    --
25033    -- set accounting class
25034    --
25035    xla_ae_lines_pkg.SetAcctClass(
25036            p_accounting_class_code  => 'EXPENSE'
25037          , p_ae_header_id           => l_ae_header_id
25038          );
25039 
25040    --
25041    -- set rounding class
25042    --
25043    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
25044                       'EXPENSE';
25045 
25046    --
25047    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
25048    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
25049    --
25050    -- bulk performance
25051    --
25052    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
25053 
25054    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
25055       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
25056 
25057    -- 4955764
25058    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
25059       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
25060 
25061    -- 4458381 Public Sector Enh
25062    
25063    --
25064    -- set accounting attributes for the line type
25065    --
25066    l_entered_amt_idx := 4;
25067    l_accted_amt_idx  := 6;
25068    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
25069    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
25070    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
25071    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
25072    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
25073    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
25074    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
25075    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
25076    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
25077    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
25078    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
25079    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
25080    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
25081 
25082    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
25083    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
25084 
25085    ---------------------------------------------------------------------------------------------------------------
25086    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
25087    ---------------------------------------------------------------------------------------------------------------
25088    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
25089 
25090    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
25094          (p_source_code         => 'LEDGER_CATEGORY_CODE'
25091    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
25092 
25093    IF xla_accounting_cache_pkg.GetValueChar
25095          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
25096    AND l_bflow_method_code = 'PRIOR_ENTRY'
25097 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
25098    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
25099          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
25100        )
25101    THEN
25102          xla_ae_lines_pkg.BflowUpgEntry
25103            (p_business_method_code    => l_bflow_method_code
25104            ,p_business_class_code     => l_bflow_class_code
25105            ,p_balance_type            => l_balance_type_code);
25106    ELSE
25107       NULL;
25108 -- No business flow processing for business flow method of NONE.
25109    END IF;
25110 
25111    --
25112    -- call analytical criteria
25113    --
25114    
25115    --
25116    -- call description
25117    --
25118    
25119 xla_ae_lines_pkg.SetLineDescription(
25120    p_ae_header_id => l_ae_header_id
25121   ,p_description  => Description_8 (
25122      p_application_id         => p_application_id
25123    , p_ae_header_id           => l_ae_header_id 
25124 , p_source_1 => p_source_1
25125    )
25126 );
25127 
25128 
25129    --
25130    -- call ADRs
25131    -- Bug 4922099
25132    --
25133    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
25134         (NVL(l_actual_upg_option, 'N') = 'O') OR
25135         (NVL(l_enc_upg_option, 'N') = 'O')
25136       )
25137    THEN
25138    NULL;
25139    --
25140    --
25141    
25142   l_ccid := AcctDerRule_175(
25143            p_application_id           => p_application_id
25144          , p_ae_header_id             => l_ae_header_id 
25145 , p_source_3 => p_source_3
25146 , p_source_29 => p_source_29
25147          , x_transaction_coa_id       => l_adr_transaction_coa_id
25148          , x_accounting_coa_id        => l_adr_accounting_coa_id
25149          , x_value_type_code          => l_adr_value_type_code
25150          , p_side                     => 'NA'
25151    );
25152 
25153    xla_ae_lines_pkg.set_ccid(
25154     p_code_combination_id          => l_ccid
25155   , p_value_type_code              => l_adr_value_type_code
25156   , p_transaction_coa_id           => l_adr_transaction_coa_id
25157   , p_accounting_coa_id            => l_adr_accounting_coa_id
25158   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
25159   , p_adr_type_code                => 'S'
25160   , p_component_type               => l_component_type
25161   , p_component_code               => l_component_code
25162   , p_component_type_code          => l_component_type_code
25163   , p_component_appl_id            => l_component_appl_id
25164   , p_amb_context_code             => l_amb_context_code
25165   , p_side                         => 'NA'
25166   );
25167 
25168 
25169    l_segment := AcctDerRule_143(
25170            p_application_id           => p_application_id
25171          , p_ae_header_id             => l_ae_header_id 
25172 , p_source_2 => p_source_2
25173 , p_source_3 => p_source_3
25174          , x_transaction_coa_id       => l_adr_transaction_coa_id
25175          , x_accounting_coa_id        => l_adr_accounting_coa_id
25176          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25177          , x_flex_value_set_id        => l_adr_flex_value_set_id
25178          , x_value_type_code          => l_adr_value_type_code
25179          , x_value_combination_id     => l_adr_value_combination_id
25180          , x_value_segment_code       => l_adr_value_segment_code
25181          , p_side                     => 'NA'
25182          , p_override_seg_flag        => 'Y'
25183    );
25184 
25185    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25186 
25187       xla_ae_lines_pkg.set_segment(
25188           p_to_segment_code         => 'GL_ACCOUNT'
25189         , p_segment_value           => l_segment
25190         , p_from_segment_code       => l_adr_value_segment_code
25191         , p_from_combination_id     => l_adr_value_combination_id
25192         , p_value_type_code         => l_adr_value_type_code
25193         , p_transaction_coa_id      => l_adr_transaction_coa_id
25194         , p_accounting_coa_id       => l_adr_accounting_coa_id
25195         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25196         , p_flex_value_set_id       => l_adr_flex_value_set_id
25197         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
25198         , p_adr_type_code           => 'S'
25199         , p_component_type          => l_component_type
25200         , p_component_code          => l_component_code
25201         , p_component_type_code     => l_component_type_code
25202         , p_component_appl_id       => l_component_appl_id
25203         , p_amb_context_code        => l_amb_context_code
25204         , p_entity_code             => 'TRANSACTIONS'
25205         , p_event_class_code        => 'ADJUSTMENTS'
25206         , p_side                    => 'NA'
25207         );
25208 
25209   END IF;
25210 
25211    --
25212    --
25213    END IF;
25214    --
25215    -- Bug 4922099
25216    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
25217           (NVL(l_enc_upg_option, 'N') = 'O')
25218         ) AND
25219         (l_bflow_method_code = 'PRIOR_ENTRY')
25220       )
25221    THEN
25222       IF
25223       --
25224       1 = 2
25225       --
25226       THEN
25227       xla_accounting_err_pkg.build_message
25228                                     (p_appli_s_name            => 'XLA'
25232                                     ,p_token_2                 => 'LINE_TYPE_NAME'
25229                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25230                                     ,p_token_1                 => 'LINE_NUMBER'
25231                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
25233                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
25234                                                                              l_component_type
25235                                                                             ,l_component_code
25236                                                                             ,l_component_type_code
25237                                                                             ,l_component_appl_id
25238                                                                             ,l_amb_context_code
25239                                                                             ,l_entity_code
25240                                                                             ,l_event_class_code
25241                                                                            )
25242                                     ,p_token_3                 => 'OWNER'
25243                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
25244                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
25245                                                                           ,p_lookup_code    => l_component_type_code
25246                                                                          )
25247                                     ,p_token_4                 => 'PRODUCT_NAME'
25248                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
25249                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
25250                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
25251                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
25252                                     ,p_ae_header_id            =>  NULL
25253                                        );
25254 
25255         IF (C_LEVEL_ERROR>= g_log_level) THEN
25256                  trace
25257                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25258                       ,p_level    => C_LEVEL_ERROR
25259                       ,p_module   => l_log_module);
25260         END IF;
25261       END IF;
25262    END IF;
25263    --
25264    --
25265    ------------------------------------------------------------------------------------------------
25266    -- 4219869 Business Flow
25267    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
25268    -- Prior Entry.  Currently, the following code is always generated.
25269    ------------------------------------------------------------------------------------------------
25270    XLA_AE_LINES_PKG.ValidateCurrentLine;
25271 
25272    ------------------------------------------------------------------------------------
25273    -- 4219869 Business Flow
25274    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
25275    ------------------------------------------------------------------------------------
25276    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25277 
25278    ----------------------------------------------------------------------------------
25279    -- 4219869 Business Flow
25280    -- Update journal entry status -- Need to generate this within IF <condition>
25281    ----------------------------------------------------------------------------------
25282    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25283          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
25284          ,p_balance_type_code => l_balance_type_code
25285          );
25286 
25287    -------------------------------------------------------------------------------------------
25288    -- 4262811 - Generate the Accrual Reversal lines
25289    -------------------------------------------------------------------------------------------
25290    BEGIN
25291       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
25292                               (g_array_event(p_event_id).array_value_num('header_index'));
25293       IF l_acc_rev_flag IS NULL THEN
25294          l_acc_rev_flag := 'N';
25295       END IF;
25296    EXCEPTION
25297       WHEN OTHERS THEN
25298          l_acc_rev_flag := 'N';
25299    END;
25300    --
25301    IF (l_acc_rev_flag = 'Y') THEN
25302 
25303        -- 4645092  ------------------------------------------------------------------------------
25304        -- To allow MPA report to determine if it should generate report process
25305        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
25306        ------------------------------------------------------------------------------------------
25307 
25308        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
25309        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
25310    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
25311    -- call ADRs
25312    -- Bug 4922099
25313    --
25314    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
25315         (NVL(l_actual_upg_option, 'N') = 'O') OR
25316         (NVL(l_enc_upg_option, 'N') = 'O')
25317       )
25318    THEN
25319    NULL;
25320    --
25321    --
25322    
25323   l_ccid := AcctDerRule_175(
25324            p_application_id           => p_application_id
25325          , p_ae_header_id             => l_ae_header_id 
25326 , p_source_3 => p_source_3
25327 , p_source_29 => p_source_29
25328          , x_transaction_coa_id       => l_adr_transaction_coa_id
25329          , x_accounting_coa_id        => l_adr_accounting_coa_id
25333 
25330          , x_value_type_code          => l_adr_value_type_code
25331          , p_side                     => 'NA'
25332    );
25334    xla_ae_lines_pkg.set_ccid(
25335     p_code_combination_id          => l_ccid
25336   , p_value_type_code              => l_adr_value_type_code
25337   , p_transaction_coa_id           => l_adr_transaction_coa_id
25338   , p_accounting_coa_id            => l_adr_accounting_coa_id
25339   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
25340   , p_adr_type_code                => 'S'
25341   , p_component_type               => l_component_type
25342   , p_component_code               => l_component_code
25343   , p_component_type_code          => l_component_type_code
25344   , p_component_appl_id            => l_component_appl_id
25345   , p_amb_context_code             => l_amb_context_code
25346   , p_side                         => 'NA'
25347   );
25348 
25349 
25350    l_segment := AcctDerRule_143(
25351            p_application_id           => p_application_id
25352          , p_ae_header_id             => l_ae_header_id 
25353 , p_source_2 => p_source_2
25354 , p_source_3 => p_source_3
25355          , x_transaction_coa_id       => l_adr_transaction_coa_id
25356          , x_accounting_coa_id        => l_adr_accounting_coa_id
25357          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25358          , x_flex_value_set_id        => l_adr_flex_value_set_id
25359          , x_value_type_code          => l_adr_value_type_code
25360          , x_value_combination_id     => l_adr_value_combination_id
25361          , x_value_segment_code       => l_adr_value_segment_code
25362          , p_side                     => 'NA'
25363          , p_override_seg_flag        => 'Y'
25364    );
25365 
25366    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25367 
25368       xla_ae_lines_pkg.set_segment(
25369           p_to_segment_code         => 'GL_ACCOUNT'
25370         , p_segment_value           => l_segment
25371         , p_from_segment_code       => l_adr_value_segment_code
25372         , p_from_combination_id     => l_adr_value_combination_id
25373         , p_value_type_code         => l_adr_value_type_code
25374         , p_transaction_coa_id      => l_adr_transaction_coa_id
25375         , p_accounting_coa_id       => l_adr_accounting_coa_id
25376         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25377         , p_flex_value_set_id       => l_adr_flex_value_set_id
25378         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
25379         , p_adr_type_code           => 'S'
25380         , p_component_type          => l_component_type
25381         , p_component_code          => l_component_code
25382         , p_component_type_code     => l_component_type_code
25383         , p_component_appl_id       => l_component_appl_id
25384         , p_amb_context_code        => l_amb_context_code
25385         , p_entity_code             => 'TRANSACTIONS'
25386         , p_event_class_code        => 'ADJUSTMENTS'
25387         , p_side                    => 'NA'
25388         );
25389 
25390   END IF;
25391 
25392    --
25393    --
25394    END IF;
25395 
25396        --
25397        -- Update the line information that should be overwritten
25398        --
25399        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
25400                                          p_header_num   => 1);
25401        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
25402 
25403        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
25404 
25405        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
25406           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
25407        END IF;
25408 
25409       --
25410       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
25411       --
25412       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
25413           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
25414       ELSE
25415           ---------------------------------------------------------------------------------------------------
25416           -- 4262811a Switch Sign
25417           ---------------------------------------------------------------------------------------------------
25418           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
25419           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25420                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25421           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25422                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25423           -- 5132302
25424           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
25425                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25426 
25427       END IF;
25428 
25429       -- 4955764
25430       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
25431       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
25432 
25433 
25434       XLA_AE_LINES_PKG.ValidateCurrentLine;
25435       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25436 
25437       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25438                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
25439                ,p_balance_type_code => l_balance_type_code);
25440 
25441    END IF;
25442 
25446      -- No MPA option is assigned.
25443    -----------------------------------------------------------------------------------------
25444    -- 4262811 Multiperiod Accounting
25445    -----------------------------------------------------------------------------------------
25447 
25448 
25449 END IF;
25450 END IF;
25451 --
25452 
25453 --
25454 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
25455    trace
25456       (p_msg      => 'END of AcctLineType_189'
25457       ,p_level    => C_LEVEL_PROCEDURE
25458       ,p_module   => l_log_module);
25459 END IF;
25460 --
25461 EXCEPTION
25462   WHEN xla_exceptions_pkg.application_exception THEN
25463       RAISE;
25464   WHEN OTHERS THEN
25465        xla_exceptions_pkg.raise_message
25466            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_189');
25467 END AcctLineType_189;
25468 --
25469 
25470 ---------------------------------------
25471 --
25472 -- PRIVATE FUNCTION
25473 --         AcctLineType_190
25474 --
25475 ---------------------------------------
25476 PROCEDURE AcctLineType_190 (
25477   p_application_id        IN NUMBER
25478  ,p_event_id              IN NUMBER
25479  ,p_calculate_acctd_flag  IN VARCHAR2
25480  ,p_calculate_g_l_flag    IN VARCHAR2
25481  ,p_actual_flag           IN OUT VARCHAR2
25482  ,p_balance_type_code     OUT VARCHAR2
25483  ,p_gain_or_loss_ref      OUT VARCHAR2
25484  
25485 --Period Close Date
25486  , p_source_1            IN DATE
25487 --Generated Code Combination Identifier
25488  , p_source_3            IN NUMBER
25489 --Bonus Reserve Account
25490  , p_source_4            IN VARCHAR2
25491 --Generated Offset Code Combination Identifier
25492  , p_source_17            IN NUMBER
25493 --Expense Account Code Combination Identifier
25494  , p_source_29            IN NUMBER
25495 --Default Code Combination Identifier
25496  , p_source_30            IN NUMBER
25497 --Adjustment Type
25498  , p_source_35            IN VARCHAR2
25499 --Transaction Header Identifier
25500  , p_source_36            IN NUMBER
25501 --Adjustment Line Identifier
25502  , p_source_37            IN NUMBER
25503 --Distribution Type Code
25504  , p_source_38            IN VARCHAR2
25505 --Entered Amount
25506  , p_source_39            IN NUMBER
25507 --Currency Code
25508  , p_source_40            IN VARCHAR2
25509 )
25510 IS
25511 
25512 l_component_type              VARCHAR2(80);
25513 l_component_code              VARCHAR2(30);
25514 l_component_type_code         VARCHAR2(1);
25515 l_component_appl_id           INTEGER;
25516 l_amb_context_code            VARCHAR2(30);
25517 l_entity_code                 VARCHAR2(30);
25518 l_event_class_code            VARCHAR2(30);
25519 l_ae_header_id                NUMBER;
25520 l_event_type_code             VARCHAR2(30);
25521 l_line_definition_code        VARCHAR2(30);
25522 l_line_definition_owner_code  VARCHAR2(1);
25523 --
25524 -- adr variables
25525 l_segment                     VARCHAR2(30);
25526 l_ccid                        NUMBER;
25527 l_adr_transaction_coa_id      NUMBER;
25528 l_adr_accounting_coa_id       NUMBER;
25529 l_adr_flexfield_segment_code  VARCHAR2(30);
25530 l_adr_flex_value_set_id       NUMBER;
25531 l_adr_value_type_code         VARCHAR2(30);
25532 l_adr_value_combination_id    NUMBER;
25533 l_adr_value_segment_code      VARCHAR2(30);
25534 
25535 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
25536 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
25537 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
25538 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
25539 
25540 -- 4262811 Variables ------------------------------------------------------------------------------------------
25541 l_entered_amt_idx             NUMBER;
25542 l_accted_amt_idx              NUMBER;
25543 l_acc_rev_flag                VARCHAR2(1);
25544 l_accrual_line_num            NUMBER;
25545 l_tmp_amt                     NUMBER;
25546 l_acc_rev_natural_side_code   VARCHAR2(1);
25547 
25548 l_num_entries                 NUMBER;
25549 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
25550 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
25551 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
25552 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
25553 l_recog_line_1                NUMBER;
25554 l_recog_line_2                NUMBER;
25555 
25556 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
25557 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
25558 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
25559 
25560 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
25561 
25562 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
25563 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
25564 
25565 ---------------------------------------------------------------------------------------------------------------
25566 
25567 
25568 --
25569 -- bulk performance
25570 --
25571 l_balance_type_code           VARCHAR2(1);
25572 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
25573 l_log_module                  VARCHAR2(240);
25574 
25575 --
25576 -- Upgrade strategy
25577 --
25578 l_actual_upg_option           VARCHAR2(1);
25579 l_enc_upg_option           VARCHAR2(1);
25580 
25581 --
25582 BEGIN
25583 --
25584 IF g_log_enabled THEN
25585       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_190';
25586 END IF;
25587 --
25588 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
25589 
25590       trace
25594 
25591          (p_msg      => 'BEGIN of AcctLineType_190'
25592          ,p_level    => C_LEVEL_PROCEDURE
25593          ,p_module   => l_log_module);
25595 END IF;
25596 --
25597 l_component_type             := 'AMB_JLT';
25598 l_component_code             := 'FA_ADJ_BONUS_RESERVE';
25599 l_component_type_code        := 'S';
25600 l_component_appl_id          :=  140;
25601 l_amb_context_code           := 'DEFAULT';
25602 l_entity_code                := 'TRANSACTIONS';
25603 l_event_class_code           := 'ADJUSTMENTS';
25604 l_event_type_code            := 'ADJUSTMENTS_ALL';
25605 l_line_definition_owner_code := 'S';
25606 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
25607 --
25608 l_balance_type_code          := 'A';
25609 l_segment                     := NULL;
25610 l_ccid                        := NULL;
25611 l_adr_transaction_coa_id      := NULL;
25612 l_adr_accounting_coa_id       := NULL;
25613 l_adr_flexfield_segment_code  := NULL;
25614 l_adr_flex_value_set_id       := NULL;
25615 l_adr_value_type_code         := NULL;
25616 l_adr_value_combination_id    := NULL;
25617 l_adr_value_segment_code      := NULL;
25618 
25619 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
25620 l_bflow_class_code           := '';    -- 4219869 Business Flow
25621 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
25622 l_budgetary_control_flag     := 'N';
25623 
25624 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
25625 l_bflow_applied_to_amt       := NULL; -- 5132302
25626 l_entered_amt_idx            := NULL;          -- 4262811
25627 l_accted_amt_idx             := NULL;          -- 4262811
25628 l_acc_rev_flag               := NULL;          -- 4262811
25629 l_accrual_line_num           := NULL;          -- 4262811
25630 l_tmp_amt                    := NULL;          -- 4262811
25631 --
25632  
25633 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
25634     l_balance_type_code <> 'B' THEN
25635 IF (NVL(p_source_35,'
25636 ') =  'BONUS EXPENSE' OR 
25637 NVL(p_source_35,'
25638 ') =  'BONUS RESERVE')
25639  THEN 
25640 
25641    --
25642    XLA_AE_LINES_PKG.SetNewLine;
25643 
25644    p_balance_type_code          := l_balance_type_code;
25645    -- set the flag so later we will know whether the gain loss line needs to be created
25646    
25647    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
25648      p_actual_flag :='A';
25649    END IF;
25650 
25651    --
25652    -- bulk performance
25653    --
25654    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
25655                                       p_header_num   => 0); -- 4262811
25656    --
25657    -- set accounting line options
25658    --
25659    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
25660            p_natural_side_code          => 'C'
25661          , p_gain_or_loss_flag          => 'N'
25662          , p_gl_transfer_mode_code      => 'S'
25663          , p_acct_entry_type_code       => 'A'
25664          , p_switch_side_flag           => 'Y'
25665          , p_merge_duplicate_code       => 'N'
25666          );
25667    --
25668    l_acc_rev_natural_side_code := 'D';  -- 4262811
25669    -- 
25670    --
25671    -- set accounting line type info
25672    --
25673    xla_ae_lines_pkg.SetAcctLineType
25674       (p_component_type             => l_component_type
25675       ,p_event_type_code            => l_event_type_code
25676       ,p_line_definition_owner_code => l_line_definition_owner_code
25677       ,p_line_definition_code       => l_line_definition_code
25678       ,p_accounting_line_code       => l_component_code
25679       ,p_accounting_line_type_code  => l_component_type_code
25680       ,p_accounting_line_appl_id    => l_component_appl_id
25681       ,p_amb_context_code           => l_amb_context_code
25682       ,p_entity_code                => l_entity_code
25683       ,p_event_class_code           => l_event_class_code);
25684    --
25685    -- set accounting class
25686    --
25687    xla_ae_lines_pkg.SetAcctClass(
25688            p_accounting_class_code  => 'ASSET'
25689          , p_ae_header_id           => l_ae_header_id
25690          );
25691 
25692    --
25693    -- set rounding class
25694    --
25695    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
25696                       'ASSET';
25697 
25698    --
25699    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
25700    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
25701    --
25702    -- bulk performance
25703    --
25704    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
25705 
25706    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
25707       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
25708 
25709    -- 4955764
25710    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
25711       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
25712 
25713    -- 4458381 Public Sector Enh
25714    
25715    --
25716    -- set accounting attributes for the line type
25717    --
25718    l_entered_amt_idx := 4;
25719    l_accted_amt_idx  := 6;
25720    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
25721    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
25722    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
25723    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
25724    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
25725    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
25729    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
25726    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
25727    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
25728    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
25730    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
25731    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
25732    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
25733 
25734    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
25735    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
25736 
25737    ---------------------------------------------------------------------------------------------------------------
25738    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
25739    ---------------------------------------------------------------------------------------------------------------
25740    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
25741 
25742    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
25743    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
25744 
25745    IF xla_accounting_cache_pkg.GetValueChar
25746          (p_source_code         => 'LEDGER_CATEGORY_CODE'
25747          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
25748    AND l_bflow_method_code = 'PRIOR_ENTRY'
25749 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
25750    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
25751          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
25752        )
25753    THEN
25754          xla_ae_lines_pkg.BflowUpgEntry
25755            (p_business_method_code    => l_bflow_method_code
25756            ,p_business_class_code     => l_bflow_class_code
25757            ,p_balance_type            => l_balance_type_code);
25758    ELSE
25759       NULL;
25760 -- No business flow processing for business flow method of NONE.
25761    END IF;
25762 
25763    --
25764    -- call analytical criteria
25765    --
25766    
25767    --
25768    -- call description
25769    --
25770    
25771 xla_ae_lines_pkg.SetLineDescription(
25772    p_ae_header_id => l_ae_header_id
25773   ,p_description  => Description_9 (
25774      p_application_id         => p_application_id
25775    , p_ae_header_id           => l_ae_header_id 
25776 , p_source_1 => p_source_1
25777    )
25778 );
25779 
25780 
25781    --
25782    -- call ADRs
25783    -- Bug 4922099
25784    --
25785    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
25786         (NVL(l_actual_upg_option, 'N') = 'O') OR
25787         (NVL(l_enc_upg_option, 'N') = 'O')
25788       )
25789    THEN
25790    NULL;
25791    --
25792    --
25793    
25794   l_ccid := AcctDerRule_174(
25795            p_application_id           => p_application_id
25796          , p_ae_header_id             => l_ae_header_id 
25797 , p_source_3 => p_source_3
25798 , p_source_17 => p_source_17
25799 , p_source_30 => p_source_30
25800          , x_transaction_coa_id       => l_adr_transaction_coa_id
25801          , x_accounting_coa_id        => l_adr_accounting_coa_id
25802          , x_value_type_code          => l_adr_value_type_code
25803          , p_side                     => 'NA'
25804    );
25805 
25806    xla_ae_lines_pkg.set_ccid(
25807     p_code_combination_id          => l_ccid
25808   , p_value_type_code              => l_adr_value_type_code
25809   , p_transaction_coa_id           => l_adr_transaction_coa_id
25810   , p_accounting_coa_id            => l_adr_accounting_coa_id
25811   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
25812   , p_adr_type_code                => 'S'
25813   , p_component_type               => l_component_type
25814   , p_component_code               => l_component_code
25815   , p_component_type_code          => l_component_type_code
25816   , p_component_appl_id            => l_component_appl_id
25817   , p_amb_context_code             => l_amb_context_code
25818   , p_side                         => 'NA'
25819   );
25820 
25821 
25822    l_segment := AcctDerRule_144(
25823            p_application_id           => p_application_id
25824          , p_ae_header_id             => l_ae_header_id 
25825 , p_source_3 => p_source_3
25826 , p_source_4 => p_source_4
25827          , x_transaction_coa_id       => l_adr_transaction_coa_id
25828          , x_accounting_coa_id        => l_adr_accounting_coa_id
25829          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25830          , x_flex_value_set_id        => l_adr_flex_value_set_id
25831          , x_value_type_code          => l_adr_value_type_code
25832          , x_value_combination_id     => l_adr_value_combination_id
25833          , x_value_segment_code       => l_adr_value_segment_code
25834          , p_side                     => 'NA'
25835          , p_override_seg_flag        => 'Y'
25836    );
25837 
25838    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25839 
25840       xla_ae_lines_pkg.set_segment(
25841           p_to_segment_code         => 'GL_ACCOUNT'
25842         , p_segment_value           => l_segment
25843         , p_from_segment_code       => l_adr_value_segment_code
25844         , p_from_combination_id     => l_adr_value_combination_id
25845         , p_value_type_code         => l_adr_value_type_code
25846         , p_transaction_coa_id      => l_adr_transaction_coa_id
25847         , p_accounting_coa_id       => l_adr_accounting_coa_id
25848         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25849         , p_flex_value_set_id       => l_adr_flex_value_set_id
25850         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
25854         , p_component_type_code     => l_component_type_code
25851         , p_adr_type_code           => 'S'
25852         , p_component_type          => l_component_type
25853         , p_component_code          => l_component_code
25855         , p_component_appl_id       => l_component_appl_id
25856         , p_amb_context_code        => l_amb_context_code
25857         , p_entity_code             => 'TRANSACTIONS'
25858         , p_event_class_code        => 'ADJUSTMENTS'
25859         , p_side                    => 'NA'
25860         );
25861 
25862   END IF;
25863 
25864    l_segment := AcctDerRule_168(
25865            p_application_id           => p_application_id
25866          , p_ae_header_id             => l_ae_header_id 
25867 , p_source_3 => p_source_3
25868 , p_source_29 => p_source_29
25869          , x_transaction_coa_id       => l_adr_transaction_coa_id
25870          , x_accounting_coa_id        => l_adr_accounting_coa_id
25871          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25872          , x_flex_value_set_id        => l_adr_flex_value_set_id
25873          , x_value_type_code          => l_adr_value_type_code
25874          , x_value_combination_id     => l_adr_value_combination_id
25875          , x_value_segment_code       => l_adr_value_segment_code
25876          , p_side                     => 'NA'
25877          , p_override_seg_flag        => 'Y'
25878    );
25879 
25880    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25881 
25882       xla_ae_lines_pkg.set_segment(
25883           p_to_segment_code         => 'GL_BALANCING'
25884         , p_segment_value           => l_segment
25885         , p_from_segment_code       => l_adr_value_segment_code
25886         , p_from_combination_id     => l_adr_value_combination_id
25887         , p_value_type_code         => l_adr_value_type_code
25888         , p_transaction_coa_id      => l_adr_transaction_coa_id
25889         , p_accounting_coa_id       => l_adr_accounting_coa_id
25890         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25891         , p_flex_value_set_id       => l_adr_flex_value_set_id
25892         , p_adr_code                => 'FA_EXPENSE_ACCT'
25893         , p_adr_type_code           => 'S'
25894         , p_component_type          => l_component_type
25895         , p_component_code          => l_component_code
25896         , p_component_type_code     => l_component_type_code
25897         , p_component_appl_id       => l_component_appl_id
25898         , p_amb_context_code        => l_amb_context_code
25899         , p_entity_code             => 'TRANSACTIONS'
25900         , p_event_class_code        => 'ADJUSTMENTS'
25901         , p_side                    => 'NA'
25902         );
25903 
25904   END IF;
25905 
25906    --
25907    --
25908    END IF;
25909    --
25910    -- Bug 4922099
25911    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
25912           (NVL(l_enc_upg_option, 'N') = 'O')
25913         ) AND
25914         (l_bflow_method_code = 'PRIOR_ENTRY')
25915       )
25916    THEN
25917       IF
25918       --
25919       1 = 2
25920       --
25921       THEN
25922       xla_accounting_err_pkg.build_message
25923                                     (p_appli_s_name            => 'XLA'
25924                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25925                                     ,p_token_1                 => 'LINE_NUMBER'
25926                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
25927                                     ,p_token_2                 => 'LINE_TYPE_NAME'
25928                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
25929                                                                              l_component_type
25930                                                                             ,l_component_code
25931                                                                             ,l_component_type_code
25932                                                                             ,l_component_appl_id
25933                                                                             ,l_amb_context_code
25934                                                                             ,l_entity_code
25935                                                                             ,l_event_class_code
25936                                                                            )
25937                                     ,p_token_3                 => 'OWNER'
25938                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
25939                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
25940                                                                           ,p_lookup_code    => l_component_type_code
25941                                                                          )
25942                                     ,p_token_4                 => 'PRODUCT_NAME'
25943                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
25944                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
25945                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
25946                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
25947                                     ,p_ae_header_id            =>  NULL
25948                                        );
25949 
25950         IF (C_LEVEL_ERROR>= g_log_level) THEN
25951                  trace
25952                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25953                       ,p_level    => C_LEVEL_ERROR
25954                       ,p_module   => l_log_module);
25955         END IF;
25956       END IF;
25957    END IF;
25958    --
25959    --
25963    -- Prior Entry.  Currently, the following code is always generated.
25960    ------------------------------------------------------------------------------------------------
25961    -- 4219869 Business Flow
25962    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
25964    ------------------------------------------------------------------------------------------------
25965    XLA_AE_LINES_PKG.ValidateCurrentLine;
25966 
25967    ------------------------------------------------------------------------------------
25968    -- 4219869 Business Flow
25969    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
25970    ------------------------------------------------------------------------------------
25971    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25972 
25973    ----------------------------------------------------------------------------------
25974    -- 4219869 Business Flow
25975    -- Update journal entry status -- Need to generate this within IF <condition>
25976    ----------------------------------------------------------------------------------
25977    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25978          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
25979          ,p_balance_type_code => l_balance_type_code
25980          );
25981 
25982    -------------------------------------------------------------------------------------------
25983    -- 4262811 - Generate the Accrual Reversal lines
25984    -------------------------------------------------------------------------------------------
25985    BEGIN
25986       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
25987                               (g_array_event(p_event_id).array_value_num('header_index'));
25988       IF l_acc_rev_flag IS NULL THEN
25989          l_acc_rev_flag := 'N';
25990       END IF;
25991    EXCEPTION
25992       WHEN OTHERS THEN
25993          l_acc_rev_flag := 'N';
25994    END;
25995    --
25996    IF (l_acc_rev_flag = 'Y') THEN
25997 
25998        -- 4645092  ------------------------------------------------------------------------------
25999        -- To allow MPA report to determine if it should generate report process
26000        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
26001        ------------------------------------------------------------------------------------------
26002 
26003        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
26004        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
26005    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
26006    -- call ADRs
26007    -- Bug 4922099
26008    --
26009    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
26010         (NVL(l_actual_upg_option, 'N') = 'O') OR
26011         (NVL(l_enc_upg_option, 'N') = 'O')
26012       )
26013    THEN
26014    NULL;
26015    --
26016    --
26017    
26018   l_ccid := AcctDerRule_174(
26019            p_application_id           => p_application_id
26020          , p_ae_header_id             => l_ae_header_id 
26021 , p_source_3 => p_source_3
26022 , p_source_17 => p_source_17
26023 , p_source_30 => p_source_30
26024          , x_transaction_coa_id       => l_adr_transaction_coa_id
26025          , x_accounting_coa_id        => l_adr_accounting_coa_id
26026          , x_value_type_code          => l_adr_value_type_code
26027          , p_side                     => 'NA'
26028    );
26029 
26030    xla_ae_lines_pkg.set_ccid(
26031     p_code_combination_id          => l_ccid
26032   , p_value_type_code              => l_adr_value_type_code
26033   , p_transaction_coa_id           => l_adr_transaction_coa_id
26034   , p_accounting_coa_id            => l_adr_accounting_coa_id
26035   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
26036   , p_adr_type_code                => 'S'
26037   , p_component_type               => l_component_type
26038   , p_component_code               => l_component_code
26039   , p_component_type_code          => l_component_type_code
26040   , p_component_appl_id            => l_component_appl_id
26041   , p_amb_context_code             => l_amb_context_code
26042   , p_side                         => 'NA'
26043   );
26044 
26045 
26046    l_segment := AcctDerRule_144(
26047            p_application_id           => p_application_id
26048          , p_ae_header_id             => l_ae_header_id 
26049 , p_source_3 => p_source_3
26050 , p_source_4 => p_source_4
26051          , x_transaction_coa_id       => l_adr_transaction_coa_id
26052          , x_accounting_coa_id        => l_adr_accounting_coa_id
26053          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26054          , x_flex_value_set_id        => l_adr_flex_value_set_id
26055          , x_value_type_code          => l_adr_value_type_code
26056          , x_value_combination_id     => l_adr_value_combination_id
26057          , x_value_segment_code       => l_adr_value_segment_code
26058          , p_side                     => 'NA'
26059          , p_override_seg_flag        => 'Y'
26060    );
26061 
26062    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26063 
26064       xla_ae_lines_pkg.set_segment(
26065           p_to_segment_code         => 'GL_ACCOUNT'
26066         , p_segment_value           => l_segment
26067         , p_from_segment_code       => l_adr_value_segment_code
26068         , p_from_combination_id     => l_adr_value_combination_id
26069         , p_value_type_code         => l_adr_value_type_code
26070         , p_transaction_coa_id      => l_adr_transaction_coa_id
26071         , p_accounting_coa_id       => l_adr_accounting_coa_id
26072         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26073         , p_flex_value_set_id       => l_adr_flex_value_set_id
26074         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
26075         , p_adr_type_code           => 'S'
26079         , p_component_appl_id       => l_component_appl_id
26076         , p_component_type          => l_component_type
26077         , p_component_code          => l_component_code
26078         , p_component_type_code     => l_component_type_code
26080         , p_amb_context_code        => l_amb_context_code
26081         , p_entity_code             => 'TRANSACTIONS'
26082         , p_event_class_code        => 'ADJUSTMENTS'
26083         , p_side                    => 'NA'
26084         );
26085 
26086   END IF;
26087 
26088    l_segment := AcctDerRule_168(
26089            p_application_id           => p_application_id
26090          , p_ae_header_id             => l_ae_header_id 
26091 , p_source_3 => p_source_3
26092 , p_source_29 => p_source_29
26093          , x_transaction_coa_id       => l_adr_transaction_coa_id
26094          , x_accounting_coa_id        => l_adr_accounting_coa_id
26095          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26096          , x_flex_value_set_id        => l_adr_flex_value_set_id
26097          , x_value_type_code          => l_adr_value_type_code
26098          , x_value_combination_id     => l_adr_value_combination_id
26099          , x_value_segment_code       => l_adr_value_segment_code
26100          , p_side                     => 'NA'
26101          , p_override_seg_flag        => 'Y'
26102    );
26103 
26104    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26105 
26106       xla_ae_lines_pkg.set_segment(
26107           p_to_segment_code         => 'GL_BALANCING'
26108         , p_segment_value           => l_segment
26109         , p_from_segment_code       => l_adr_value_segment_code
26110         , p_from_combination_id     => l_adr_value_combination_id
26111         , p_value_type_code         => l_adr_value_type_code
26112         , p_transaction_coa_id      => l_adr_transaction_coa_id
26113         , p_accounting_coa_id       => l_adr_accounting_coa_id
26114         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26115         , p_flex_value_set_id       => l_adr_flex_value_set_id
26116         , p_adr_code                => 'FA_EXPENSE_ACCT'
26117         , p_adr_type_code           => 'S'
26118         , p_component_type          => l_component_type
26119         , p_component_code          => l_component_code
26120         , p_component_type_code     => l_component_type_code
26121         , p_component_appl_id       => l_component_appl_id
26122         , p_amb_context_code        => l_amb_context_code
26123         , p_entity_code             => 'TRANSACTIONS'
26124         , p_event_class_code        => 'ADJUSTMENTS'
26125         , p_side                    => 'NA'
26126         );
26127 
26128   END IF;
26129 
26130    --
26131    --
26132    END IF;
26133 
26134        --
26135        -- Update the line information that should be overwritten
26136        --
26137        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
26138                                          p_header_num   => 1);
26139        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
26140 
26141        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
26142 
26143        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
26144           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
26145        END IF;
26146 
26147       --
26148       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
26149       --
26150       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
26151           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
26152       ELSE
26153           ---------------------------------------------------------------------------------------------------
26154           -- 4262811a Switch Sign
26155           ---------------------------------------------------------------------------------------------------
26156           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
26157           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
26158                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26159           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
26160                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26161           -- 5132302
26162           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
26163                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26164 
26165       END IF;
26166 
26167       -- 4955764
26168       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
26169       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
26170 
26171 
26172       XLA_AE_LINES_PKG.ValidateCurrentLine;
26173       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
26174 
26175       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
26176                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
26177                ,p_balance_type_code => l_balance_type_code);
26178 
26179    END IF;
26180 
26181    -----------------------------------------------------------------------------------------
26182    -- 4262811 Multiperiod Accounting
26183    -----------------------------------------------------------------------------------------
26184      -- No MPA option is assigned.
26185 
26186 
26187 END IF;
26188 END IF;
26189 --
26190 
26191 --
26192 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
26193    trace
26197 END IF;
26194       (p_msg      => 'END of AcctLineType_190'
26195       ,p_level    => C_LEVEL_PROCEDURE
26196       ,p_module   => l_log_module);
26198 --
26199 EXCEPTION
26200   WHEN xla_exceptions_pkg.application_exception THEN
26201       RAISE;
26202   WHEN OTHERS THEN
26203        xla_exceptions_pkg.raise_message
26204            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_190');
26205 END AcctLineType_190;
26206 --
26207 
26208 ---------------------------------------
26209 --
26210 -- PRIVATE FUNCTION
26211 --         AcctLineType_191
26212 --
26213 ---------------------------------------
26214 PROCEDURE AcctLineType_191 (
26215   p_application_id        IN NUMBER
26216  ,p_event_id              IN NUMBER
26217  ,p_calculate_acctd_flag  IN VARCHAR2
26218  ,p_calculate_g_l_flag    IN VARCHAR2
26219  ,p_actual_flag           IN OUT VARCHAR2
26220  ,p_balance_type_code     OUT VARCHAR2
26221  ,p_gain_or_loss_ref      OUT VARCHAR2
26222  
26223 --Period Close Date
26224  , p_source_1            IN DATE
26225 --Generated Code Combination Identifier
26226  , p_source_3            IN NUMBER
26227 --Asset Cost Account
26228  , p_source_9            IN VARCHAR2
26229 --Expense Account Code Combination Identifier
26230  , p_source_29            IN NUMBER
26231 --Default Code Combination Identifier
26232  , p_source_30            IN NUMBER
26233 --Adjustment Type
26234  , p_source_35            IN VARCHAR2
26235 --Transaction Header Identifier
26236  , p_source_36            IN NUMBER
26237 --Adjustment Line Identifier
26238  , p_source_37            IN NUMBER
26239 --Distribution Type Code
26240  , p_source_38            IN VARCHAR2
26241 --Entered Amount
26242  , p_source_39            IN NUMBER
26243 --Currency Code
26244  , p_source_40            IN VARCHAR2
26245 )
26246 IS
26247 
26248 l_component_type              VARCHAR2(80);
26249 l_component_code              VARCHAR2(30);
26250 l_component_type_code         VARCHAR2(1);
26251 l_component_appl_id           INTEGER;
26252 l_amb_context_code            VARCHAR2(30);
26253 l_entity_code                 VARCHAR2(30);
26254 l_event_class_code            VARCHAR2(30);
26255 l_ae_header_id                NUMBER;
26256 l_event_type_code             VARCHAR2(30);
26257 l_line_definition_code        VARCHAR2(30);
26258 l_line_definition_owner_code  VARCHAR2(1);
26259 --
26260 -- adr variables
26261 l_segment                     VARCHAR2(30);
26262 l_ccid                        NUMBER;
26263 l_adr_transaction_coa_id      NUMBER;
26264 l_adr_accounting_coa_id       NUMBER;
26265 l_adr_flexfield_segment_code  VARCHAR2(30);
26266 l_adr_flex_value_set_id       NUMBER;
26267 l_adr_value_type_code         VARCHAR2(30);
26268 l_adr_value_combination_id    NUMBER;
26269 l_adr_value_segment_code      VARCHAR2(30);
26270 
26271 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
26272 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
26273 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
26274 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
26275 
26276 -- 4262811 Variables ------------------------------------------------------------------------------------------
26277 l_entered_amt_idx             NUMBER;
26278 l_accted_amt_idx              NUMBER;
26279 l_acc_rev_flag                VARCHAR2(1);
26280 l_accrual_line_num            NUMBER;
26281 l_tmp_amt                     NUMBER;
26282 l_acc_rev_natural_side_code   VARCHAR2(1);
26283 
26284 l_num_entries                 NUMBER;
26285 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
26286 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
26287 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
26288 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
26289 l_recog_line_1                NUMBER;
26290 l_recog_line_2                NUMBER;
26291 
26292 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
26293 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
26294 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
26295 
26296 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
26297 
26298 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
26299 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
26300 
26301 ---------------------------------------------------------------------------------------------------------------
26302 
26303 
26304 --
26305 -- bulk performance
26306 --
26307 l_balance_type_code           VARCHAR2(1);
26308 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
26309 l_log_module                  VARCHAR2(240);
26310 
26311 --
26312 -- Upgrade strategy
26313 --
26314 l_actual_upg_option           VARCHAR2(1);
26315 l_enc_upg_option           VARCHAR2(1);
26316 
26317 --
26318 BEGIN
26319 --
26320 IF g_log_enabled THEN
26321       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_191';
26322 END IF;
26323 --
26324 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
26325 
26326       trace
26327          (p_msg      => 'BEGIN of AcctLineType_191'
26328          ,p_level    => C_LEVEL_PROCEDURE
26329          ,p_module   => l_log_module);
26330 
26331 END IF;
26332 --
26333 l_component_type             := 'AMB_JLT';
26334 l_component_code             := 'FA_ADJ_COST';
26335 l_component_type_code        := 'S';
26336 l_component_appl_id          :=  140;
26337 l_amb_context_code           := 'DEFAULT';
26338 l_entity_code                := 'TRANSACTIONS';
26339 l_event_class_code           := 'ADJUSTMENTS';
26343 --
26340 l_event_type_code            := 'ADJUSTMENTS_ALL';
26341 l_line_definition_owner_code := 'S';
26342 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
26344 l_balance_type_code          := 'A';
26345 l_segment                     := NULL;
26346 l_ccid                        := NULL;
26347 l_adr_transaction_coa_id      := NULL;
26348 l_adr_accounting_coa_id       := NULL;
26349 l_adr_flexfield_segment_code  := NULL;
26350 l_adr_flex_value_set_id       := NULL;
26351 l_adr_value_type_code         := NULL;
26352 l_adr_value_combination_id    := NULL;
26353 l_adr_value_segment_code      := NULL;
26354 
26355 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
26356 l_bflow_class_code           := '';    -- 4219869 Business Flow
26357 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
26358 l_budgetary_control_flag     := 'N';
26359 
26360 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
26361 l_bflow_applied_to_amt       := NULL; -- 5132302
26362 l_entered_amt_idx            := NULL;          -- 4262811
26363 l_accted_amt_idx             := NULL;          -- 4262811
26364 l_acc_rev_flag               := NULL;          -- 4262811
26365 l_accrual_line_num           := NULL;          -- 4262811
26366 l_tmp_amt                    := NULL;          -- 4262811
26367 --
26368  
26369 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
26370     l_balance_type_code <> 'B' THEN
26371 IF NVL(p_source_35,'
26372 ') =  'COST'
26373  THEN 
26374 
26375    --
26376    XLA_AE_LINES_PKG.SetNewLine;
26377 
26378    p_balance_type_code          := l_balance_type_code;
26379    -- set the flag so later we will know whether the gain loss line needs to be created
26380    
26381    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
26382      p_actual_flag :='A';
26383    END IF;
26384 
26385    --
26386    -- bulk performance
26387    --
26388    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
26389                                       p_header_num   => 0); -- 4262811
26390    --
26391    -- set accounting line options
26392    --
26393    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
26394            p_natural_side_code          => 'D'
26395          , p_gain_or_loss_flag          => 'N'
26396          , p_gl_transfer_mode_code      => 'S'
26397          , p_acct_entry_type_code       => 'A'
26398          , p_switch_side_flag           => 'Y'
26399          , p_merge_duplicate_code       => 'N'
26400          );
26401    --
26402    l_acc_rev_natural_side_code := 'C';  -- 4262811
26403    -- 
26404    --
26405    -- set accounting line type info
26406    --
26407    xla_ae_lines_pkg.SetAcctLineType
26408       (p_component_type             => l_component_type
26409       ,p_event_type_code            => l_event_type_code
26410       ,p_line_definition_owner_code => l_line_definition_owner_code
26411       ,p_line_definition_code       => l_line_definition_code
26412       ,p_accounting_line_code       => l_component_code
26413       ,p_accounting_line_type_code  => l_component_type_code
26414       ,p_accounting_line_appl_id    => l_component_appl_id
26415       ,p_amb_context_code           => l_amb_context_code
26416       ,p_entity_code                => l_entity_code
26417       ,p_event_class_code           => l_event_class_code);
26418    --
26419    -- set accounting class
26420    --
26421    xla_ae_lines_pkg.SetAcctClass(
26422            p_accounting_class_code  => 'ASSET'
26423          , p_ae_header_id           => l_ae_header_id
26424          );
26425 
26426    --
26427    -- set rounding class
26428    --
26429    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
26430                       'ASSET';
26431 
26432    --
26433    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
26434    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
26435    --
26436    -- bulk performance
26437    --
26438    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
26439 
26440    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
26441       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
26442 
26443    -- 4955764
26444    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
26445       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
26446 
26447    -- 4458381 Public Sector Enh
26448    
26449    --
26450    -- set accounting attributes for the line type
26451    --
26452    l_entered_amt_idx := 4;
26453    l_accted_amt_idx  := 6;
26454    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
26455    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
26456    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
26457    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
26458    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
26459    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
26460    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
26461    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
26462    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
26463    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
26464    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
26465    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
26466    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
26467 
26468    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
26469    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
26473    ---------------------------------------------------------------------------------------------------------------
26470 
26471    ---------------------------------------------------------------------------------------------------------------
26472    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
26474    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
26475 
26476    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
26477    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
26478 
26479    IF xla_accounting_cache_pkg.GetValueChar
26480          (p_source_code         => 'LEDGER_CATEGORY_CODE'
26481          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
26482    AND l_bflow_method_code = 'PRIOR_ENTRY'
26483 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
26484    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
26485          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
26486        )
26487    THEN
26488          xla_ae_lines_pkg.BflowUpgEntry
26489            (p_business_method_code    => l_bflow_method_code
26490            ,p_business_class_code     => l_bflow_class_code
26491            ,p_balance_type            => l_balance_type_code);
26492    ELSE
26493       NULL;
26494 -- No business flow processing for business flow method of NONE.
26495    END IF;
26496 
26497    --
26498    -- call analytical criteria
26499    --
26500    
26501    --
26502    -- call description
26503    --
26504    
26505 xla_ae_lines_pkg.SetLineDescription(
26506    p_ae_header_id => l_ae_header_id
26507   ,p_description  => Description_10 (
26508      p_application_id         => p_application_id
26509    , p_ae_header_id           => l_ae_header_id 
26510 , p_source_1 => p_source_1
26511    )
26512 );
26513 
26514 
26515    --
26516    -- call ADRs
26517    -- Bug 4922099
26518    --
26519    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
26520         (NVL(l_actual_upg_option, 'N') = 'O') OR
26521         (NVL(l_enc_upg_option, 'N') = 'O')
26522       )
26523    THEN
26524    NULL;
26525    --
26526    --
26527    
26528   l_ccid := AcctDerRule_173(
26529            p_application_id           => p_application_id
26530          , p_ae_header_id             => l_ae_header_id 
26531 , p_source_3 => p_source_3
26532 , p_source_30 => p_source_30
26533          , x_transaction_coa_id       => l_adr_transaction_coa_id
26534          , x_accounting_coa_id        => l_adr_accounting_coa_id
26535          , x_value_type_code          => l_adr_value_type_code
26536          , p_side                     => 'NA'
26537    );
26538 
26539    xla_ae_lines_pkg.set_ccid(
26540     p_code_combination_id          => l_ccid
26541   , p_value_type_code              => l_adr_value_type_code
26542   , p_transaction_coa_id           => l_adr_transaction_coa_id
26543   , p_accounting_coa_id            => l_adr_accounting_coa_id
26544   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
26545   , p_adr_type_code                => 'S'
26546   , p_component_type               => l_component_type
26547   , p_component_code               => l_component_code
26548   , p_component_type_code          => l_component_type_code
26549   , p_component_appl_id            => l_component_appl_id
26550   , p_amb_context_code             => l_amb_context_code
26551   , p_side                         => 'NA'
26552   );
26553 
26554 
26555    l_segment := AcctDerRule_148(
26556            p_application_id           => p_application_id
26557          , p_ae_header_id             => l_ae_header_id 
26558 , p_source_3 => p_source_3
26559 , p_source_9 => p_source_9
26560          , x_transaction_coa_id       => l_adr_transaction_coa_id
26561          , x_accounting_coa_id        => l_adr_accounting_coa_id
26562          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26563          , x_flex_value_set_id        => l_adr_flex_value_set_id
26564          , x_value_type_code          => l_adr_value_type_code
26565          , x_value_combination_id     => l_adr_value_combination_id
26566          , x_value_segment_code       => l_adr_value_segment_code
26567          , p_side                     => 'NA'
26568          , p_override_seg_flag        => 'Y'
26569    );
26570 
26571    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26572 
26573       xla_ae_lines_pkg.set_segment(
26574           p_to_segment_code         => 'GL_ACCOUNT'
26575         , p_segment_value           => l_segment
26576         , p_from_segment_code       => l_adr_value_segment_code
26577         , p_from_combination_id     => l_adr_value_combination_id
26578         , p_value_type_code         => l_adr_value_type_code
26579         , p_transaction_coa_id      => l_adr_transaction_coa_id
26580         , p_accounting_coa_id       => l_adr_accounting_coa_id
26581         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26582         , p_flex_value_set_id       => l_adr_flex_value_set_id
26583         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
26584         , p_adr_type_code           => 'S'
26585         , p_component_type          => l_component_type
26586         , p_component_code          => l_component_code
26587         , p_component_type_code     => l_component_type_code
26588         , p_component_appl_id       => l_component_appl_id
26589         , p_amb_context_code        => l_amb_context_code
26590         , p_entity_code             => 'TRANSACTIONS'
26591         , p_event_class_code        => 'ADJUSTMENTS'
26592         , p_side                    => 'NA'
26593         );
26594 
26595   END IF;
26596 
26597    l_segment := AcctDerRule_168(
26601 , p_source_29 => p_source_29
26598            p_application_id           => p_application_id
26599          , p_ae_header_id             => l_ae_header_id 
26600 , p_source_3 => p_source_3
26602          , x_transaction_coa_id       => l_adr_transaction_coa_id
26603          , x_accounting_coa_id        => l_adr_accounting_coa_id
26604          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26605          , x_flex_value_set_id        => l_adr_flex_value_set_id
26606          , x_value_type_code          => l_adr_value_type_code
26607          , x_value_combination_id     => l_adr_value_combination_id
26608          , x_value_segment_code       => l_adr_value_segment_code
26609          , p_side                     => 'NA'
26610          , p_override_seg_flag        => 'Y'
26611    );
26612 
26613    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26614 
26615       xla_ae_lines_pkg.set_segment(
26616           p_to_segment_code         => 'GL_BALANCING'
26617         , p_segment_value           => l_segment
26618         , p_from_segment_code       => l_adr_value_segment_code
26619         , p_from_combination_id     => l_adr_value_combination_id
26620         , p_value_type_code         => l_adr_value_type_code
26621         , p_transaction_coa_id      => l_adr_transaction_coa_id
26622         , p_accounting_coa_id       => l_adr_accounting_coa_id
26623         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26624         , p_flex_value_set_id       => l_adr_flex_value_set_id
26625         , p_adr_code                => 'FA_EXPENSE_ACCT'
26626         , p_adr_type_code           => 'S'
26627         , p_component_type          => l_component_type
26628         , p_component_code          => l_component_code
26629         , p_component_type_code     => l_component_type_code
26630         , p_component_appl_id       => l_component_appl_id
26631         , p_amb_context_code        => l_amb_context_code
26632         , p_entity_code             => 'TRANSACTIONS'
26633         , p_event_class_code        => 'ADJUSTMENTS'
26634         , p_side                    => 'NA'
26635         );
26636 
26637   END IF;
26638 
26639    --
26640    --
26641    END IF;
26642    --
26643    -- Bug 4922099
26644    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
26645           (NVL(l_enc_upg_option, 'N') = 'O')
26646         ) AND
26647         (l_bflow_method_code = 'PRIOR_ENTRY')
26648       )
26649    THEN
26650       IF
26651       --
26652       1 = 2
26653       --
26654       THEN
26655       xla_accounting_err_pkg.build_message
26656                                     (p_appli_s_name            => 'XLA'
26657                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
26658                                     ,p_token_1                 => 'LINE_NUMBER'
26659                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
26660                                     ,p_token_2                 => 'LINE_TYPE_NAME'
26661                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
26662                                                                              l_component_type
26663                                                                             ,l_component_code
26664                                                                             ,l_component_type_code
26665                                                                             ,l_component_appl_id
26666                                                                             ,l_amb_context_code
26667                                                                             ,l_entity_code
26668                                                                             ,l_event_class_code
26669                                                                            )
26670                                     ,p_token_3                 => 'OWNER'
26671                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
26672                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
26673                                                                           ,p_lookup_code    => l_component_type_code
26674                                                                          )
26675                                     ,p_token_4                 => 'PRODUCT_NAME'
26676                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
26677                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
26678                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
26679                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
26680                                     ,p_ae_header_id            =>  NULL
26681                                        );
26682 
26683         IF (C_LEVEL_ERROR>= g_log_level) THEN
26684                  trace
26685                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
26686                       ,p_level    => C_LEVEL_ERROR
26687                       ,p_module   => l_log_module);
26688         END IF;
26689       END IF;
26690    END IF;
26691    --
26692    --
26693    ------------------------------------------------------------------------------------------------
26694    -- 4219869 Business Flow
26695    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
26696    -- Prior Entry.  Currently, the following code is always generated.
26697    ------------------------------------------------------------------------------------------------
26698    XLA_AE_LINES_PKG.ValidateCurrentLine;
26699 
26700    ------------------------------------------------------------------------------------
26701    -- 4219869 Business Flow
26705 
26702    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
26703    ------------------------------------------------------------------------------------
26704    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
26706    ----------------------------------------------------------------------------------
26707    -- 4219869 Business Flow
26708    -- Update journal entry status -- Need to generate this within IF <condition>
26709    ----------------------------------------------------------------------------------
26710    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
26711          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
26712          ,p_balance_type_code => l_balance_type_code
26713          );
26714 
26715    -------------------------------------------------------------------------------------------
26716    -- 4262811 - Generate the Accrual Reversal lines
26717    -------------------------------------------------------------------------------------------
26718    BEGIN
26719       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
26720                               (g_array_event(p_event_id).array_value_num('header_index'));
26721       IF l_acc_rev_flag IS NULL THEN
26722          l_acc_rev_flag := 'N';
26723       END IF;
26724    EXCEPTION
26725       WHEN OTHERS THEN
26726          l_acc_rev_flag := 'N';
26727    END;
26728    --
26729    IF (l_acc_rev_flag = 'Y') THEN
26730 
26731        -- 4645092  ------------------------------------------------------------------------------
26732        -- To allow MPA report to determine if it should generate report process
26733        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
26734        ------------------------------------------------------------------------------------------
26735 
26736        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
26737        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
26738    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
26739    -- call ADRs
26740    -- Bug 4922099
26741    --
26742    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
26743         (NVL(l_actual_upg_option, 'N') = 'O') OR
26744         (NVL(l_enc_upg_option, 'N') = 'O')
26745       )
26746    THEN
26747    NULL;
26748    --
26749    --
26750    
26751   l_ccid := AcctDerRule_173(
26752            p_application_id           => p_application_id
26753          , p_ae_header_id             => l_ae_header_id 
26754 , p_source_3 => p_source_3
26755 , p_source_30 => p_source_30
26756          , x_transaction_coa_id       => l_adr_transaction_coa_id
26757          , x_accounting_coa_id        => l_adr_accounting_coa_id
26758          , x_value_type_code          => l_adr_value_type_code
26759          , p_side                     => 'NA'
26760    );
26761 
26762    xla_ae_lines_pkg.set_ccid(
26763     p_code_combination_id          => l_ccid
26764   , p_value_type_code              => l_adr_value_type_code
26765   , p_transaction_coa_id           => l_adr_transaction_coa_id
26766   , p_accounting_coa_id            => l_adr_accounting_coa_id
26767   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
26768   , p_adr_type_code                => 'S'
26769   , p_component_type               => l_component_type
26770   , p_component_code               => l_component_code
26771   , p_component_type_code          => l_component_type_code
26772   , p_component_appl_id            => l_component_appl_id
26773   , p_amb_context_code             => l_amb_context_code
26774   , p_side                         => 'NA'
26775   );
26776 
26777 
26778    l_segment := AcctDerRule_148(
26779            p_application_id           => p_application_id
26780          , p_ae_header_id             => l_ae_header_id 
26781 , p_source_3 => p_source_3
26782 , p_source_9 => p_source_9
26783          , x_transaction_coa_id       => l_adr_transaction_coa_id
26784          , x_accounting_coa_id        => l_adr_accounting_coa_id
26785          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26786          , x_flex_value_set_id        => l_adr_flex_value_set_id
26787          , x_value_type_code          => l_adr_value_type_code
26788          , x_value_combination_id     => l_adr_value_combination_id
26789          , x_value_segment_code       => l_adr_value_segment_code
26790          , p_side                     => 'NA'
26791          , p_override_seg_flag        => 'Y'
26792    );
26793 
26794    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26795 
26796       xla_ae_lines_pkg.set_segment(
26797           p_to_segment_code         => 'GL_ACCOUNT'
26798         , p_segment_value           => l_segment
26799         , p_from_segment_code       => l_adr_value_segment_code
26800         , p_from_combination_id     => l_adr_value_combination_id
26801         , p_value_type_code         => l_adr_value_type_code
26802         , p_transaction_coa_id      => l_adr_transaction_coa_id
26803         , p_accounting_coa_id       => l_adr_accounting_coa_id
26804         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26805         , p_flex_value_set_id       => l_adr_flex_value_set_id
26806         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
26807         , p_adr_type_code           => 'S'
26808         , p_component_type          => l_component_type
26809         , p_component_code          => l_component_code
26810         , p_component_type_code     => l_component_type_code
26811         , p_component_appl_id       => l_component_appl_id
26812         , p_amb_context_code        => l_amb_context_code
26813         , p_entity_code             => 'TRANSACTIONS'
26814         , p_event_class_code        => 'ADJUSTMENTS'
26815         , p_side                    => 'NA'
26816         );
26817 
26818   END IF;
26819 
26820    l_segment := AcctDerRule_168(
26821            p_application_id           => p_application_id
26825          , x_transaction_coa_id       => l_adr_transaction_coa_id
26822          , p_ae_header_id             => l_ae_header_id 
26823 , p_source_3 => p_source_3
26824 , p_source_29 => p_source_29
26826          , x_accounting_coa_id        => l_adr_accounting_coa_id
26827          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26828          , x_flex_value_set_id        => l_adr_flex_value_set_id
26829          , x_value_type_code          => l_adr_value_type_code
26830          , x_value_combination_id     => l_adr_value_combination_id
26831          , x_value_segment_code       => l_adr_value_segment_code
26832          , p_side                     => 'NA'
26833          , p_override_seg_flag        => 'Y'
26834    );
26835 
26836    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26837 
26838       xla_ae_lines_pkg.set_segment(
26839           p_to_segment_code         => 'GL_BALANCING'
26840         , p_segment_value           => l_segment
26841         , p_from_segment_code       => l_adr_value_segment_code
26842         , p_from_combination_id     => l_adr_value_combination_id
26843         , p_value_type_code         => l_adr_value_type_code
26844         , p_transaction_coa_id      => l_adr_transaction_coa_id
26845         , p_accounting_coa_id       => l_adr_accounting_coa_id
26846         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26847         , p_flex_value_set_id       => l_adr_flex_value_set_id
26848         , p_adr_code                => 'FA_EXPENSE_ACCT'
26849         , p_adr_type_code           => 'S'
26850         , p_component_type          => l_component_type
26851         , p_component_code          => l_component_code
26852         , p_component_type_code     => l_component_type_code
26853         , p_component_appl_id       => l_component_appl_id
26854         , p_amb_context_code        => l_amb_context_code
26855         , p_entity_code             => 'TRANSACTIONS'
26856         , p_event_class_code        => 'ADJUSTMENTS'
26857         , p_side                    => 'NA'
26858         );
26859 
26860   END IF;
26861 
26862    --
26863    --
26864    END IF;
26865 
26866        --
26867        -- Update the line information that should be overwritten
26868        --
26869        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
26870                                          p_header_num   => 1);
26871        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
26872 
26873        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
26874 
26875        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
26876           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
26877        END IF;
26878 
26879       --
26880       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
26881       --
26882       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
26883           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
26884       ELSE
26885           ---------------------------------------------------------------------------------------------------
26886           -- 4262811a Switch Sign
26887           ---------------------------------------------------------------------------------------------------
26888           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
26889           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
26890                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26891           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
26892                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26893           -- 5132302
26894           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
26895                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26896 
26897       END IF;
26898 
26899       -- 4955764
26900       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
26901       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
26902 
26903 
26904       XLA_AE_LINES_PKG.ValidateCurrentLine;
26905       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
26906 
26907       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
26908                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
26909                ,p_balance_type_code => l_balance_type_code);
26910 
26911    END IF;
26912 
26913    -----------------------------------------------------------------------------------------
26914    -- 4262811 Multiperiod Accounting
26915    -----------------------------------------------------------------------------------------
26916      -- No MPA option is assigned.
26917 
26918 
26919 END IF;
26920 END IF;
26921 --
26922 
26923 --
26924 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
26925    trace
26926       (p_msg      => 'END of AcctLineType_191'
26927       ,p_level    => C_LEVEL_PROCEDURE
26928       ,p_module   => l_log_module);
26929 END IF;
26930 --
26931 EXCEPTION
26932   WHEN xla_exceptions_pkg.application_exception THEN
26933       RAISE;
26934   WHEN OTHERS THEN
26935        xla_exceptions_pkg.raise_message
26936            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_191');
26937 END AcctLineType_191;
26938 --
26939 
26940 ---------------------------------------
26941 --
26942 -- PRIVATE FUNCTION
26943 --         AcctLineType_192
26944 --
26945 ---------------------------------------
26949  ,p_calculate_acctd_flag  IN VARCHAR2
26946 PROCEDURE AcctLineType_192 (
26947   p_application_id        IN NUMBER
26948  ,p_event_id              IN NUMBER
26950  ,p_calculate_g_l_flag    IN VARCHAR2
26951  ,p_actual_flag           IN OUT VARCHAR2
26952  ,p_balance_type_code     OUT VARCHAR2
26953  ,p_gain_or_loss_ref      OUT VARCHAR2
26954  
26955 --Period Close Date
26956  , p_source_1            IN DATE
26957 --Generated Code Combination Identifier
26958  , p_source_3            IN NUMBER
26959 --Payables Code Combination Identifier
26960  , p_source_6            IN NUMBER
26961 --Asset Clearing Account
26962  , p_source_8            IN VARCHAR2
26963 --Expense Account Code Combination Identifier
26964  , p_source_29            IN NUMBER
26965 --Default Code Combination Identifier
26966  , p_source_30            IN NUMBER
26967 --Adjustment Type
26968  , p_source_35            IN VARCHAR2
26969 --Transaction Header Identifier
26970  , p_source_36            IN NUMBER
26971 --Adjustment Line Identifier
26972  , p_source_37            IN NUMBER
26973 --Distribution Type Code
26974  , p_source_38            IN VARCHAR2
26975 --Entered Amount
26976  , p_source_39            IN NUMBER
26977 --Currency Code
26978  , p_source_40            IN VARCHAR2
26979 )
26980 IS
26981 
26982 l_component_type              VARCHAR2(80);
26983 l_component_code              VARCHAR2(30);
26984 l_component_type_code         VARCHAR2(1);
26985 l_component_appl_id           INTEGER;
26986 l_amb_context_code            VARCHAR2(30);
26987 l_entity_code                 VARCHAR2(30);
26988 l_event_class_code            VARCHAR2(30);
26989 l_ae_header_id                NUMBER;
26990 l_event_type_code             VARCHAR2(30);
26991 l_line_definition_code        VARCHAR2(30);
26992 l_line_definition_owner_code  VARCHAR2(1);
26993 --
26994 -- adr variables
26995 l_segment                     VARCHAR2(30);
26996 l_ccid                        NUMBER;
26997 l_adr_transaction_coa_id      NUMBER;
26998 l_adr_accounting_coa_id       NUMBER;
26999 l_adr_flexfield_segment_code  VARCHAR2(30);
27000 l_adr_flex_value_set_id       NUMBER;
27001 l_adr_value_type_code         VARCHAR2(30);
27002 l_adr_value_combination_id    NUMBER;
27003 l_adr_value_segment_code      VARCHAR2(30);
27004 
27005 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
27006 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
27007 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
27008 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
27009 
27010 -- 4262811 Variables ------------------------------------------------------------------------------------------
27011 l_entered_amt_idx             NUMBER;
27012 l_accted_amt_idx              NUMBER;
27013 l_acc_rev_flag                VARCHAR2(1);
27014 l_accrual_line_num            NUMBER;
27015 l_tmp_amt                     NUMBER;
27016 l_acc_rev_natural_side_code   VARCHAR2(1);
27017 
27018 l_num_entries                 NUMBER;
27019 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
27020 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
27021 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
27022 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
27023 l_recog_line_1                NUMBER;
27024 l_recog_line_2                NUMBER;
27025 
27026 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
27027 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
27028 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
27029 
27030 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
27031 
27032 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
27033 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
27034 
27035 ---------------------------------------------------------------------------------------------------------------
27036 
27037 
27038 --
27039 -- bulk performance
27040 --
27041 l_balance_type_code           VARCHAR2(1);
27042 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
27043 l_log_module                  VARCHAR2(240);
27044 
27045 --
27046 -- Upgrade strategy
27047 --
27048 l_actual_upg_option           VARCHAR2(1);
27049 l_enc_upg_option           VARCHAR2(1);
27050 
27051 --
27052 BEGIN
27053 --
27054 IF g_log_enabled THEN
27055       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_192';
27056 END IF;
27057 --
27058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
27059 
27060       trace
27061          (p_msg      => 'BEGIN of AcctLineType_192'
27062          ,p_level    => C_LEVEL_PROCEDURE
27063          ,p_module   => l_log_module);
27064 
27065 END IF;
27066 --
27067 l_component_type             := 'AMB_JLT';
27068 l_component_code             := 'FA_ADJ_COST_CLEARING';
27069 l_component_type_code        := 'S';
27070 l_component_appl_id          :=  140;
27071 l_amb_context_code           := 'DEFAULT';
27072 l_entity_code                := 'TRANSACTIONS';
27073 l_event_class_code           := 'ADJUSTMENTS';
27074 l_event_type_code            := 'ADJUSTMENTS_ALL';
27075 l_line_definition_owner_code := 'S';
27076 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
27077 --
27078 l_balance_type_code          := 'A';
27079 l_segment                     := NULL;
27080 l_ccid                        := NULL;
27081 l_adr_transaction_coa_id      := NULL;
27082 l_adr_accounting_coa_id       := NULL;
27083 l_adr_flexfield_segment_code  := NULL;
27084 l_adr_flex_value_set_id       := NULL;
27085 l_adr_value_type_code         := NULL;
27086 l_adr_value_combination_id    := NULL;
27090 l_bflow_class_code           := '';    -- 4219869 Business Flow
27087 l_adr_value_segment_code      := NULL;
27088 
27089 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
27091 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
27092 l_budgetary_control_flag     := 'N';
27093 
27094 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
27095 l_bflow_applied_to_amt       := NULL; -- 5132302
27096 l_entered_amt_idx            := NULL;          -- 4262811
27097 l_accted_amt_idx             := NULL;          -- 4262811
27098 l_acc_rev_flag               := NULL;          -- 4262811
27099 l_accrual_line_num           := NULL;          -- 4262811
27100 l_tmp_amt                    := NULL;          -- 4262811
27101 --
27102  
27103 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
27104     l_balance_type_code <> 'B' THEN
27105 IF NVL(p_source_35,'
27106 ') =  'COST CLEARING'
27107  THEN 
27108 
27109    --
27110    XLA_AE_LINES_PKG.SetNewLine;
27111 
27112    p_balance_type_code          := l_balance_type_code;
27113    -- set the flag so later we will know whether the gain loss line needs to be created
27114    
27115    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
27116      p_actual_flag :='A';
27117    END IF;
27118 
27119    --
27120    -- bulk performance
27121    --
27122    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
27123                                       p_header_num   => 0); -- 4262811
27124    --
27125    -- set accounting line options
27126    --
27127    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
27128            p_natural_side_code          => 'C'
27129          , p_gain_or_loss_flag          => 'N'
27130          , p_gl_transfer_mode_code      => 'S'
27131          , p_acct_entry_type_code       => 'A'
27132          , p_switch_side_flag           => 'Y'
27133          , p_merge_duplicate_code       => 'N'
27134          );
27135    --
27136    l_acc_rev_natural_side_code := 'D';  -- 4262811
27137    -- 
27138    --
27139    -- set accounting line type info
27140    --
27141    xla_ae_lines_pkg.SetAcctLineType
27142       (p_component_type             => l_component_type
27143       ,p_event_type_code            => l_event_type_code
27144       ,p_line_definition_owner_code => l_line_definition_owner_code
27145       ,p_line_definition_code       => l_line_definition_code
27146       ,p_accounting_line_code       => l_component_code
27147       ,p_accounting_line_type_code  => l_component_type_code
27148       ,p_accounting_line_appl_id    => l_component_appl_id
27149       ,p_amb_context_code           => l_amb_context_code
27150       ,p_entity_code                => l_entity_code
27151       ,p_event_class_code           => l_event_class_code);
27152    --
27153    -- set accounting class
27154    --
27155    xla_ae_lines_pkg.SetAcctClass(
27156            p_accounting_class_code  => 'ASSET'
27157          , p_ae_header_id           => l_ae_header_id
27158          );
27159 
27160    --
27161    -- set rounding class
27162    --
27163    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
27164                       'ASSET';
27165 
27166    --
27167    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
27168    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
27169    --
27170    -- bulk performance
27171    --
27172    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
27173 
27174    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
27175       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
27176 
27177    -- 4955764
27178    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
27179       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
27180 
27181    -- 4458381 Public Sector Enh
27182    
27183    --
27184    -- set accounting attributes for the line type
27185    --
27186    l_entered_amt_idx := 4;
27187    l_accted_amt_idx  := 6;
27188    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
27189    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
27190    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
27191    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
27192    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
27193    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
27194    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
27195    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
27196    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
27197    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
27198    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
27199    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
27200    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
27201 
27202    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
27203    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
27204 
27205    ---------------------------------------------------------------------------------------------------------------
27206    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
27207    ---------------------------------------------------------------------------------------------------------------
27208    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
27209 
27210    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27214          (p_source_code         => 'LEDGER_CATEGORY_CODE'
27211    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27212 
27213    IF xla_accounting_cache_pkg.GetValueChar
27215          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
27216    AND l_bflow_method_code = 'PRIOR_ENTRY'
27217 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
27218    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
27219          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
27220        )
27221    THEN
27222          xla_ae_lines_pkg.BflowUpgEntry
27223            (p_business_method_code    => l_bflow_method_code
27224            ,p_business_class_code     => l_bflow_class_code
27225            ,p_balance_type            => l_balance_type_code);
27226    ELSE
27227       NULL;
27228 -- No business flow processing for business flow method of NONE.
27229    END IF;
27230 
27231    --
27232    -- call analytical criteria
27233    --
27234    
27235    --
27236    -- call description
27237    --
27238    
27239 xla_ae_lines_pkg.SetLineDescription(
27240    p_ae_header_id => l_ae_header_id
27241   ,p_description  => Description_11 (
27242      p_application_id         => p_application_id
27243    , p_ae_header_id           => l_ae_header_id 
27244 , p_source_1 => p_source_1
27245    )
27246 );
27247 
27248 
27249    --
27250    -- call ADRs
27251    -- Bug 4922099
27252    --
27253    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
27254         (NVL(l_actual_upg_option, 'N') = 'O') OR
27255         (NVL(l_enc_upg_option, 'N') = 'O')
27256       )
27257    THEN
27258    NULL;
27259    --
27260    --
27261    
27262   l_ccid := AcctDerRule_172(
27263            p_application_id           => p_application_id
27264          , p_ae_header_id             => l_ae_header_id 
27265 , p_source_3 => p_source_3
27266 , p_source_6 => p_source_6
27267 , p_source_30 => p_source_30
27268          , x_transaction_coa_id       => l_adr_transaction_coa_id
27269          , x_accounting_coa_id        => l_adr_accounting_coa_id
27270          , x_value_type_code          => l_adr_value_type_code
27271          , p_side                     => 'NA'
27272    );
27273 
27274    xla_ae_lines_pkg.set_ccid(
27275     p_code_combination_id          => l_ccid
27276   , p_value_type_code              => l_adr_value_type_code
27277   , p_transaction_coa_id           => l_adr_transaction_coa_id
27278   , p_accounting_coa_id            => l_adr_accounting_coa_id
27279   , p_adr_code                     => 'FA_CAT_COST_CLEARING'
27280   , p_adr_type_code                => 'S'
27281   , p_component_type               => l_component_type
27282   , p_component_code               => l_component_code
27283   , p_component_type_code          => l_component_type_code
27284   , p_component_appl_id            => l_component_appl_id
27285   , p_amb_context_code             => l_amb_context_code
27286   , p_side                         => 'NA'
27287   );
27288 
27289 
27290    l_segment := AcctDerRule_147(
27291            p_application_id           => p_application_id
27292          , p_ae_header_id             => l_ae_header_id 
27293 , p_source_3 => p_source_3
27294 , p_source_6 => p_source_6
27295 , p_source_8 => p_source_8
27296          , x_transaction_coa_id       => l_adr_transaction_coa_id
27297          , x_accounting_coa_id        => l_adr_accounting_coa_id
27298          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27299          , x_flex_value_set_id        => l_adr_flex_value_set_id
27300          , x_value_type_code          => l_adr_value_type_code
27301          , x_value_combination_id     => l_adr_value_combination_id
27302          , x_value_segment_code       => l_adr_value_segment_code
27303          , p_side                     => 'NA'
27304          , p_override_seg_flag        => 'Y'
27305    );
27306 
27307    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27308 
27309       xla_ae_lines_pkg.set_segment(
27310           p_to_segment_code         => 'GL_ACCOUNT'
27311         , p_segment_value           => l_segment
27312         , p_from_segment_code       => l_adr_value_segment_code
27313         , p_from_combination_id     => l_adr_value_combination_id
27314         , p_value_type_code         => l_adr_value_type_code
27315         , p_transaction_coa_id      => l_adr_transaction_coa_id
27316         , p_accounting_coa_id       => l_adr_accounting_coa_id
27317         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27318         , p_flex_value_set_id       => l_adr_flex_value_set_id
27319         , p_adr_code                => 'FA_CAT_CLR_ACCOUNT_SEGMENT'
27320         , p_adr_type_code           => 'S'
27321         , p_component_type          => l_component_type
27322         , p_component_code          => l_component_code
27323         , p_component_type_code     => l_component_type_code
27324         , p_component_appl_id       => l_component_appl_id
27325         , p_amb_context_code        => l_amb_context_code
27326         , p_entity_code             => 'TRANSACTIONS'
27327         , p_event_class_code        => 'ADJUSTMENTS'
27328         , p_side                    => 'NA'
27329         );
27330 
27331   END IF;
27332 
27333    l_segment := AcctDerRule_169(
27334            p_application_id           => p_application_id
27335          , p_ae_header_id             => l_ae_header_id 
27336 , p_source_3 => p_source_3
27337 , p_source_6 => p_source_6
27338 , p_source_29 => p_source_29
27339          , x_transaction_coa_id       => l_adr_transaction_coa_id
27340          , x_accounting_coa_id        => l_adr_accounting_coa_id
27341          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27342          , x_flex_value_set_id        => l_adr_flex_value_set_id
27346          , p_side                     => 'NA'
27343          , x_value_type_code          => l_adr_value_type_code
27344          , x_value_combination_id     => l_adr_value_combination_id
27345          , x_value_segment_code       => l_adr_value_segment_code
27347          , p_override_seg_flag        => 'Y'
27348    );
27349 
27350    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27351 
27352       xla_ae_lines_pkg.set_segment(
27353           p_to_segment_code         => 'GL_BALANCING'
27354         , p_segment_value           => l_segment
27355         , p_from_segment_code       => l_adr_value_segment_code
27356         , p_from_combination_id     => l_adr_value_combination_id
27357         , p_value_type_code         => l_adr_value_type_code
27358         , p_transaction_coa_id      => l_adr_transaction_coa_id
27359         , p_accounting_coa_id       => l_adr_accounting_coa_id
27360         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27361         , p_flex_value_set_id       => l_adr_flex_value_set_id
27362         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
27363         , p_adr_type_code           => 'S'
27364         , p_component_type          => l_component_type
27365         , p_component_code          => l_component_code
27366         , p_component_type_code     => l_component_type_code
27367         , p_component_appl_id       => l_component_appl_id
27368         , p_amb_context_code        => l_amb_context_code
27369         , p_entity_code             => 'TRANSACTIONS'
27370         , p_event_class_code        => 'ADJUSTMENTS'
27371         , p_side                    => 'NA'
27372         );
27373 
27374   END IF;
27375 
27376    --
27377    --
27378    END IF;
27379    --
27380    -- Bug 4922099
27381    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
27382           (NVL(l_enc_upg_option, 'N') = 'O')
27383         ) AND
27384         (l_bflow_method_code = 'PRIOR_ENTRY')
27385       )
27386    THEN
27387       IF
27388       --
27389       1 = 2
27390       --
27391       THEN
27392       xla_accounting_err_pkg.build_message
27393                                     (p_appli_s_name            => 'XLA'
27394                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27395                                     ,p_token_1                 => 'LINE_NUMBER'
27396                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
27397                                     ,p_token_2                 => 'LINE_TYPE_NAME'
27398                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
27399                                                                              l_component_type
27400                                                                             ,l_component_code
27401                                                                             ,l_component_type_code
27402                                                                             ,l_component_appl_id
27403                                                                             ,l_amb_context_code
27404                                                                             ,l_entity_code
27405                                                                             ,l_event_class_code
27406                                                                            )
27407                                     ,p_token_3                 => 'OWNER'
27408                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
27409                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
27410                                                                           ,p_lookup_code    => l_component_type_code
27411                                                                          )
27412                                     ,p_token_4                 => 'PRODUCT_NAME'
27413                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
27414                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
27415                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
27416                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
27417                                     ,p_ae_header_id            =>  NULL
27418                                        );
27419 
27420         IF (C_LEVEL_ERROR>= g_log_level) THEN
27421                  trace
27422                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27423                       ,p_level    => C_LEVEL_ERROR
27424                       ,p_module   => l_log_module);
27425         END IF;
27426       END IF;
27427    END IF;
27428    --
27429    --
27430    ------------------------------------------------------------------------------------------------
27431    -- 4219869 Business Flow
27432    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
27433    -- Prior Entry.  Currently, the following code is always generated.
27434    ------------------------------------------------------------------------------------------------
27435    XLA_AE_LINES_PKG.ValidateCurrentLine;
27436 
27437    ------------------------------------------------------------------------------------
27438    -- 4219869 Business Flow
27439    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
27440    ------------------------------------------------------------------------------------
27441    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
27442 
27443    ----------------------------------------------------------------------------------
27444    -- 4219869 Business Flow
27445    -- Update journal entry status -- Need to generate this within IF <condition>
27446    ----------------------------------------------------------------------------------
27450          );
27447    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
27448          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
27449          ,p_balance_type_code => l_balance_type_code
27451 
27452    -------------------------------------------------------------------------------------------
27453    -- 4262811 - Generate the Accrual Reversal lines
27454    -------------------------------------------------------------------------------------------
27455    BEGIN
27456       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
27457                               (g_array_event(p_event_id).array_value_num('header_index'));
27458       IF l_acc_rev_flag IS NULL THEN
27459          l_acc_rev_flag := 'N';
27460       END IF;
27461    EXCEPTION
27462       WHEN OTHERS THEN
27463          l_acc_rev_flag := 'N';
27464    END;
27465    --
27466    IF (l_acc_rev_flag = 'Y') THEN
27467 
27468        -- 4645092  ------------------------------------------------------------------------------
27469        -- To allow MPA report to determine if it should generate report process
27470        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
27471        ------------------------------------------------------------------------------------------
27472 
27473        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
27474        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
27475    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
27476    -- call ADRs
27477    -- Bug 4922099
27478    --
27479    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
27480         (NVL(l_actual_upg_option, 'N') = 'O') OR
27481         (NVL(l_enc_upg_option, 'N') = 'O')
27482       )
27483    THEN
27484    NULL;
27485    --
27486    --
27487    
27488   l_ccid := AcctDerRule_172(
27489            p_application_id           => p_application_id
27490          , p_ae_header_id             => l_ae_header_id 
27491 , p_source_3 => p_source_3
27492 , p_source_6 => p_source_6
27493 , p_source_30 => p_source_30
27494          , x_transaction_coa_id       => l_adr_transaction_coa_id
27495          , x_accounting_coa_id        => l_adr_accounting_coa_id
27496          , x_value_type_code          => l_adr_value_type_code
27497          , p_side                     => 'NA'
27498    );
27499 
27500    xla_ae_lines_pkg.set_ccid(
27501     p_code_combination_id          => l_ccid
27502   , p_value_type_code              => l_adr_value_type_code
27503   , p_transaction_coa_id           => l_adr_transaction_coa_id
27504   , p_accounting_coa_id            => l_adr_accounting_coa_id
27505   , p_adr_code                     => 'FA_CAT_COST_CLEARING'
27506   , p_adr_type_code                => 'S'
27507   , p_component_type               => l_component_type
27508   , p_component_code               => l_component_code
27509   , p_component_type_code          => l_component_type_code
27510   , p_component_appl_id            => l_component_appl_id
27511   , p_amb_context_code             => l_amb_context_code
27512   , p_side                         => 'NA'
27513   );
27514 
27515 
27516    l_segment := AcctDerRule_147(
27517            p_application_id           => p_application_id
27518          , p_ae_header_id             => l_ae_header_id 
27519 , p_source_3 => p_source_3
27520 , p_source_6 => p_source_6
27521 , p_source_8 => p_source_8
27522          , x_transaction_coa_id       => l_adr_transaction_coa_id
27523          , x_accounting_coa_id        => l_adr_accounting_coa_id
27524          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27525          , x_flex_value_set_id        => l_adr_flex_value_set_id
27526          , x_value_type_code          => l_adr_value_type_code
27527          , x_value_combination_id     => l_adr_value_combination_id
27528          , x_value_segment_code       => l_adr_value_segment_code
27529          , p_side                     => 'NA'
27530          , p_override_seg_flag        => 'Y'
27531    );
27532 
27533    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27534 
27535       xla_ae_lines_pkg.set_segment(
27536           p_to_segment_code         => 'GL_ACCOUNT'
27537         , p_segment_value           => l_segment
27538         , p_from_segment_code       => l_adr_value_segment_code
27539         , p_from_combination_id     => l_adr_value_combination_id
27540         , p_value_type_code         => l_adr_value_type_code
27541         , p_transaction_coa_id      => l_adr_transaction_coa_id
27542         , p_accounting_coa_id       => l_adr_accounting_coa_id
27543         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27544         , p_flex_value_set_id       => l_adr_flex_value_set_id
27545         , p_adr_code                => 'FA_CAT_CLR_ACCOUNT_SEGMENT'
27546         , p_adr_type_code           => 'S'
27547         , p_component_type          => l_component_type
27548         , p_component_code          => l_component_code
27549         , p_component_type_code     => l_component_type_code
27550         , p_component_appl_id       => l_component_appl_id
27551         , p_amb_context_code        => l_amb_context_code
27552         , p_entity_code             => 'TRANSACTIONS'
27553         , p_event_class_code        => 'ADJUSTMENTS'
27554         , p_side                    => 'NA'
27555         );
27556 
27557   END IF;
27558 
27559    l_segment := AcctDerRule_169(
27560            p_application_id           => p_application_id
27561          , p_ae_header_id             => l_ae_header_id 
27562 , p_source_3 => p_source_3
27563 , p_source_6 => p_source_6
27564 , p_source_29 => p_source_29
27565          , x_transaction_coa_id       => l_adr_transaction_coa_id
27566          , x_accounting_coa_id        => l_adr_accounting_coa_id
27567          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27568          , x_flex_value_set_id        => l_adr_flex_value_set_id
27572          , p_side                     => 'NA'
27569          , x_value_type_code          => l_adr_value_type_code
27570          , x_value_combination_id     => l_adr_value_combination_id
27571          , x_value_segment_code       => l_adr_value_segment_code
27573          , p_override_seg_flag        => 'Y'
27574    );
27575 
27576    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27577 
27578       xla_ae_lines_pkg.set_segment(
27579           p_to_segment_code         => 'GL_BALANCING'
27580         , p_segment_value           => l_segment
27581         , p_from_segment_code       => l_adr_value_segment_code
27582         , p_from_combination_id     => l_adr_value_combination_id
27583         , p_value_type_code         => l_adr_value_type_code
27584         , p_transaction_coa_id      => l_adr_transaction_coa_id
27585         , p_accounting_coa_id       => l_adr_accounting_coa_id
27586         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27587         , p_flex_value_set_id       => l_adr_flex_value_set_id
27588         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
27589         , p_adr_type_code           => 'S'
27590         , p_component_type          => l_component_type
27591         , p_component_code          => l_component_code
27592         , p_component_type_code     => l_component_type_code
27593         , p_component_appl_id       => l_component_appl_id
27594         , p_amb_context_code        => l_amb_context_code
27595         , p_entity_code             => 'TRANSACTIONS'
27596         , p_event_class_code        => 'ADJUSTMENTS'
27597         , p_side                    => 'NA'
27598         );
27599 
27600   END IF;
27601 
27602    --
27603    --
27604    END IF;
27605 
27606        --
27607        -- Update the line information that should be overwritten
27608        --
27609        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
27610                                          p_header_num   => 1);
27611        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
27612 
27613        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
27614 
27615        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
27616           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
27617        END IF;
27618 
27619       --
27620       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
27621       --
27622       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
27623           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
27624       ELSE
27625           ---------------------------------------------------------------------------------------------------
27626           -- 4262811a Switch Sign
27627           ---------------------------------------------------------------------------------------------------
27628           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
27629           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
27630                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27631           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
27632                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27633           -- 5132302
27634           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
27635                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27636 
27637       END IF;
27638 
27639       -- 4955764
27640       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
27641       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
27642 
27643 
27644       XLA_AE_LINES_PKG.ValidateCurrentLine;
27645       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
27646 
27647       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
27648                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
27649                ,p_balance_type_code => l_balance_type_code);
27650 
27651    END IF;
27652 
27653    -----------------------------------------------------------------------------------------
27654    -- 4262811 Multiperiod Accounting
27655    -----------------------------------------------------------------------------------------
27656      -- No MPA option is assigned.
27657 
27658 
27659 END IF;
27660 END IF;
27661 --
27662 
27663 --
27664 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
27665    trace
27666       (p_msg      => 'END of AcctLineType_192'
27667       ,p_level    => C_LEVEL_PROCEDURE
27668       ,p_module   => l_log_module);
27669 END IF;
27670 --
27671 EXCEPTION
27672   WHEN xla_exceptions_pkg.application_exception THEN
27673       RAISE;
27674   WHEN OTHERS THEN
27675        xla_exceptions_pkg.raise_message
27676            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_192');
27677 END AcctLineType_192;
27678 --
27679 
27680 ---------------------------------------
27681 --
27682 -- PRIVATE FUNCTION
27683 --         AcctLineType_193
27684 --
27685 ---------------------------------------
27686 PROCEDURE AcctLineType_193 (
27687   p_application_id        IN NUMBER
27688  ,p_event_id              IN NUMBER
27689  ,p_calculate_acctd_flag  IN VARCHAR2
27690  ,p_calculate_g_l_flag    IN VARCHAR2
27691  ,p_actual_flag           IN OUT VARCHAR2
27692  ,p_balance_type_code     OUT VARCHAR2
27693  ,p_gain_or_loss_ref      OUT VARCHAR2
27694  
27695 --Period Close Date
27699 --Expense Account Code Combination Identifier
27696  , p_source_1            IN DATE
27697 --Generated Code Combination Identifier
27698  , p_source_3            IN NUMBER
27700  , p_source_29            IN NUMBER
27701 --Adjustment Type
27702  , p_source_35            IN VARCHAR2
27703 --Transaction Header Identifier
27704  , p_source_36            IN NUMBER
27705 --Adjustment Line Identifier
27706  , p_source_37            IN NUMBER
27707 --Distribution Type Code
27708  , p_source_38            IN VARCHAR2
27709 --Entered Amount
27710  , p_source_39            IN NUMBER
27711 --Currency Code
27712  , p_source_40            IN VARCHAR2
27713 )
27714 IS
27715 
27716 l_component_type              VARCHAR2(80);
27717 l_component_code              VARCHAR2(30);
27718 l_component_type_code         VARCHAR2(1);
27719 l_component_appl_id           INTEGER;
27720 l_amb_context_code            VARCHAR2(30);
27721 l_entity_code                 VARCHAR2(30);
27722 l_event_class_code            VARCHAR2(30);
27723 l_ae_header_id                NUMBER;
27724 l_event_type_code             VARCHAR2(30);
27725 l_line_definition_code        VARCHAR2(30);
27726 l_line_definition_owner_code  VARCHAR2(1);
27727 --
27728 -- adr variables
27729 l_segment                     VARCHAR2(30);
27730 l_ccid                        NUMBER;
27731 l_adr_transaction_coa_id      NUMBER;
27732 l_adr_accounting_coa_id       NUMBER;
27733 l_adr_flexfield_segment_code  VARCHAR2(30);
27734 l_adr_flex_value_set_id       NUMBER;
27735 l_adr_value_type_code         VARCHAR2(30);
27736 l_adr_value_combination_id    NUMBER;
27737 l_adr_value_segment_code      VARCHAR2(30);
27738 
27739 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
27740 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
27741 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
27742 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
27743 
27744 -- 4262811 Variables ------------------------------------------------------------------------------------------
27745 l_entered_amt_idx             NUMBER;
27746 l_accted_amt_idx              NUMBER;
27747 l_acc_rev_flag                VARCHAR2(1);
27748 l_accrual_line_num            NUMBER;
27749 l_tmp_amt                     NUMBER;
27750 l_acc_rev_natural_side_code   VARCHAR2(1);
27751 
27752 l_num_entries                 NUMBER;
27753 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
27754 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
27755 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
27756 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
27757 l_recog_line_1                NUMBER;
27758 l_recog_line_2                NUMBER;
27759 
27760 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
27761 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
27762 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
27763 
27764 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
27765 
27766 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
27767 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
27768 
27769 ---------------------------------------------------------------------------------------------------------------
27770 
27771 
27772 --
27773 -- bulk performance
27774 --
27775 l_balance_type_code           VARCHAR2(1);
27776 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
27777 l_log_module                  VARCHAR2(240);
27778 
27779 --
27780 -- Upgrade strategy
27781 --
27782 l_actual_upg_option           VARCHAR2(1);
27783 l_enc_upg_option           VARCHAR2(1);
27784 
27785 --
27786 BEGIN
27787 --
27788 IF g_log_enabled THEN
27789       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_193';
27790 END IF;
27791 --
27792 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
27793 
27794       trace
27795          (p_msg      => 'BEGIN of AcctLineType_193'
27796          ,p_level    => C_LEVEL_PROCEDURE
27797          ,p_module   => l_log_module);
27798 
27799 END IF;
27800 --
27801 l_component_type             := 'AMB_JLT';
27802 l_component_code             := 'FA_ADJ_EXP';
27803 l_component_type_code        := 'S';
27804 l_component_appl_id          :=  140;
27805 l_amb_context_code           := 'DEFAULT';
27806 l_entity_code                := 'TRANSACTIONS';
27807 l_event_class_code           := 'ADJUSTMENTS';
27808 l_event_type_code            := 'ADJUSTMENTS_ALL';
27809 l_line_definition_owner_code := 'S';
27810 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
27811 --
27812 l_balance_type_code          := 'A';
27813 l_segment                     := NULL;
27814 l_ccid                        := NULL;
27815 l_adr_transaction_coa_id      := NULL;
27816 l_adr_accounting_coa_id       := NULL;
27817 l_adr_flexfield_segment_code  := NULL;
27818 l_adr_flex_value_set_id       := NULL;
27819 l_adr_value_type_code         := NULL;
27820 l_adr_value_combination_id    := NULL;
27821 l_adr_value_segment_code      := NULL;
27822 
27823 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
27824 l_bflow_class_code           := '';    -- 4219869 Business Flow
27825 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
27826 l_budgetary_control_flag     := 'N';
27827 
27828 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
27829 l_bflow_applied_to_amt       := NULL; -- 5132302
27830 l_entered_amt_idx            := NULL;          -- 4262811
27831 l_accted_amt_idx             := NULL;          -- 4262811
27832 l_acc_rev_flag               := NULL;          -- 4262811
27833 l_accrual_line_num           := NULL;          -- 4262811
27837 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
27834 l_tmp_amt                    := NULL;          -- 4262811
27835 --
27836  
27838     l_balance_type_code <> 'B' THEN
27839 IF NVL(p_source_35,'
27840 ') =  'EXPENSE'
27841  THEN 
27842 
27843    --
27844    XLA_AE_LINES_PKG.SetNewLine;
27845 
27846    p_balance_type_code          := l_balance_type_code;
27847    -- set the flag so later we will know whether the gain loss line needs to be created
27848    
27849    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
27850      p_actual_flag :='A';
27851    END IF;
27852 
27853    --
27854    -- bulk performance
27855    --
27856    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
27857                                       p_header_num   => 0); -- 4262811
27858    --
27859    -- set accounting line options
27860    --
27861    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
27862            p_natural_side_code          => 'D'
27863          , p_gain_or_loss_flag          => 'N'
27864          , p_gl_transfer_mode_code      => 'S'
27865          , p_acct_entry_type_code       => 'A'
27866          , p_switch_side_flag           => 'Y'
27867          , p_merge_duplicate_code       => 'N'
27868          );
27869    --
27870    l_acc_rev_natural_side_code := 'C';  -- 4262811
27871    -- 
27872    --
27873    -- set accounting line type info
27874    --
27875    xla_ae_lines_pkg.SetAcctLineType
27876       (p_component_type             => l_component_type
27877       ,p_event_type_code            => l_event_type_code
27878       ,p_line_definition_owner_code => l_line_definition_owner_code
27879       ,p_line_definition_code       => l_line_definition_code
27880       ,p_accounting_line_code       => l_component_code
27881       ,p_accounting_line_type_code  => l_component_type_code
27882       ,p_accounting_line_appl_id    => l_component_appl_id
27883       ,p_amb_context_code           => l_amb_context_code
27884       ,p_entity_code                => l_entity_code
27885       ,p_event_class_code           => l_event_class_code);
27886    --
27887    -- set accounting class
27888    --
27889    xla_ae_lines_pkg.SetAcctClass(
27890            p_accounting_class_code  => 'EXPENSE'
27891          , p_ae_header_id           => l_ae_header_id
27892          );
27893 
27894    --
27895    -- set rounding class
27896    --
27897    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
27898                       'EXPENSE';
27899 
27900    --
27901    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
27902    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
27903    --
27904    -- bulk performance
27905    --
27906    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
27907 
27908    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
27909       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
27910 
27911    -- 4955764
27912    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
27913       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
27914 
27915    -- 4458381 Public Sector Enh
27916    
27917    --
27918    -- set accounting attributes for the line type
27919    --
27920    l_entered_amt_idx := 4;
27921    l_accted_amt_idx  := 6;
27922    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
27923    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
27924    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
27925    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
27926    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
27927    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
27928    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
27929    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
27930    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
27931    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
27932    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
27933    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
27934    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
27935 
27936    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
27937    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
27938 
27939    ---------------------------------------------------------------------------------------------------------------
27940    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
27941    ---------------------------------------------------------------------------------------------------------------
27942    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
27943 
27944    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27945    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27946 
27947    IF xla_accounting_cache_pkg.GetValueChar
27948          (p_source_code         => 'LEDGER_CATEGORY_CODE'
27949          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
27950    AND l_bflow_method_code = 'PRIOR_ENTRY'
27951 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
27952    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
27953          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
27954        )
27955    THEN
27956          xla_ae_lines_pkg.BflowUpgEntry
27960    ELSE
27957            (p_business_method_code    => l_bflow_method_code
27958            ,p_business_class_code     => l_bflow_class_code
27959            ,p_balance_type            => l_balance_type_code);
27961       NULL;
27962 -- No business flow processing for business flow method of NONE.
27963    END IF;
27964 
27965    --
27966    -- call analytical criteria
27967    --
27968    
27969    --
27970    -- call description
27971    --
27972    
27973 xla_ae_lines_pkg.SetLineDescription(
27974    p_ae_header_id => l_ae_header_id
27975   ,p_description  => Description_12 (
27976      p_application_id         => p_application_id
27977    , p_ae_header_id           => l_ae_header_id 
27978 , p_source_1 => p_source_1
27979    )
27980 );
27981 
27982 
27983    --
27984    -- call ADRs
27985    -- Bug 4922099
27986    --
27987    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
27988         (NVL(l_actual_upg_option, 'N') = 'O') OR
27989         (NVL(l_enc_upg_option, 'N') = 'O')
27990       )
27991    THEN
27992    NULL;
27993    --
27994    --
27995    
27996   l_ccid := AcctDerRule_175(
27997            p_application_id           => p_application_id
27998          , p_ae_header_id             => l_ae_header_id 
27999 , p_source_3 => p_source_3
28000 , p_source_29 => p_source_29
28001          , x_transaction_coa_id       => l_adr_transaction_coa_id
28002          , x_accounting_coa_id        => l_adr_accounting_coa_id
28003          , x_value_type_code          => l_adr_value_type_code
28004          , p_side                     => 'NA'
28005    );
28006 
28007    xla_ae_lines_pkg.set_ccid(
28008     p_code_combination_id          => l_ccid
28009   , p_value_type_code              => l_adr_value_type_code
28010   , p_transaction_coa_id           => l_adr_transaction_coa_id
28011   , p_accounting_coa_id            => l_adr_accounting_coa_id
28012   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
28013   , p_adr_type_code                => 'S'
28014   , p_component_type               => l_component_type
28015   , p_component_code               => l_component_code
28016   , p_component_type_code          => l_component_type_code
28017   , p_component_appl_id            => l_component_appl_id
28018   , p_amb_context_code             => l_amb_context_code
28019   , p_side                         => 'NA'
28020   );
28021 
28022 
28023    --
28024    --
28025    END IF;
28026    --
28027    -- Bug 4922099
28028    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
28029           (NVL(l_enc_upg_option, 'N') = 'O')
28030         ) AND
28031         (l_bflow_method_code = 'PRIOR_ENTRY')
28032       )
28033    THEN
28034       IF
28035       --
28036       1 = 2
28037       --
28038       THEN
28039       xla_accounting_err_pkg.build_message
28040                                     (p_appli_s_name            => 'XLA'
28041                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
28042                                     ,p_token_1                 => 'LINE_NUMBER'
28043                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
28044                                     ,p_token_2                 => 'LINE_TYPE_NAME'
28045                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
28046                                                                              l_component_type
28047                                                                             ,l_component_code
28048                                                                             ,l_component_type_code
28049                                                                             ,l_component_appl_id
28050                                                                             ,l_amb_context_code
28051                                                                             ,l_entity_code
28052                                                                             ,l_event_class_code
28053                                                                            )
28054                                     ,p_token_3                 => 'OWNER'
28055                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
28056                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
28057                                                                           ,p_lookup_code    => l_component_type_code
28058                                                                          )
28059                                     ,p_token_4                 => 'PRODUCT_NAME'
28060                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
28061                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
28062                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
28063                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
28064                                     ,p_ae_header_id            =>  NULL
28065                                        );
28066 
28067         IF (C_LEVEL_ERROR>= g_log_level) THEN
28068                  trace
28069                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
28070                       ,p_level    => C_LEVEL_ERROR
28071                       ,p_module   => l_log_module);
28072         END IF;
28073       END IF;
28074    END IF;
28075    --
28076    --
28077    ------------------------------------------------------------------------------------------------
28078    -- 4219869 Business Flow
28079    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
28083 
28080    -- Prior Entry.  Currently, the following code is always generated.
28081    ------------------------------------------------------------------------------------------------
28082    XLA_AE_LINES_PKG.ValidateCurrentLine;
28084    ------------------------------------------------------------------------------------
28085    -- 4219869 Business Flow
28086    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
28087    ------------------------------------------------------------------------------------
28088    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
28089 
28090    ----------------------------------------------------------------------------------
28091    -- 4219869 Business Flow
28092    -- Update journal entry status -- Need to generate this within IF <condition>
28093    ----------------------------------------------------------------------------------
28094    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
28095          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
28096          ,p_balance_type_code => l_balance_type_code
28097          );
28098 
28099    -------------------------------------------------------------------------------------------
28100    -- 4262811 - Generate the Accrual Reversal lines
28101    -------------------------------------------------------------------------------------------
28102    BEGIN
28103       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
28104                               (g_array_event(p_event_id).array_value_num('header_index'));
28105       IF l_acc_rev_flag IS NULL THEN
28106          l_acc_rev_flag := 'N';
28107       END IF;
28108    EXCEPTION
28109       WHEN OTHERS THEN
28110          l_acc_rev_flag := 'N';
28111    END;
28112    --
28113    IF (l_acc_rev_flag = 'Y') THEN
28114 
28115        -- 4645092  ------------------------------------------------------------------------------
28116        -- To allow MPA report to determine if it should generate report process
28117        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
28118        ------------------------------------------------------------------------------------------
28119 
28120        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
28121        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
28122    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
28123    -- call ADRs
28124    -- Bug 4922099
28125    --
28126    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
28127         (NVL(l_actual_upg_option, 'N') = 'O') OR
28128         (NVL(l_enc_upg_option, 'N') = 'O')
28129       )
28130    THEN
28131    NULL;
28132    --
28133    --
28134    
28135   l_ccid := AcctDerRule_175(
28136            p_application_id           => p_application_id
28137          , p_ae_header_id             => l_ae_header_id 
28138 , p_source_3 => p_source_3
28139 , p_source_29 => p_source_29
28140          , x_transaction_coa_id       => l_adr_transaction_coa_id
28141          , x_accounting_coa_id        => l_adr_accounting_coa_id
28142          , x_value_type_code          => l_adr_value_type_code
28143          , p_side                     => 'NA'
28144    );
28145 
28146    xla_ae_lines_pkg.set_ccid(
28147     p_code_combination_id          => l_ccid
28148   , p_value_type_code              => l_adr_value_type_code
28149   , p_transaction_coa_id           => l_adr_transaction_coa_id
28150   , p_accounting_coa_id            => l_adr_accounting_coa_id
28151   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
28152   , p_adr_type_code                => 'S'
28153   , p_component_type               => l_component_type
28154   , p_component_code               => l_component_code
28155   , p_component_type_code          => l_component_type_code
28156   , p_component_appl_id            => l_component_appl_id
28157   , p_amb_context_code             => l_amb_context_code
28158   , p_side                         => 'NA'
28159   );
28160 
28161 
28162    --
28163    --
28164    END IF;
28165 
28166        --
28167        -- Update the line information that should be overwritten
28168        --
28169        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
28170                                          p_header_num   => 1);
28171        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
28172 
28173        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
28174 
28175        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
28176           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
28177        END IF;
28178 
28179       --
28180       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
28181       --
28182       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
28183           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
28184       ELSE
28185           ---------------------------------------------------------------------------------------------------
28186           -- 4262811a Switch Sign
28187           ---------------------------------------------------------------------------------------------------
28188           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
28189           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
28190                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28191           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
28192                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28193           -- 5132302
28197       END IF;
28194           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
28195                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28196 
28198 
28199       -- 4955764
28200       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
28201       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
28202 
28203 
28204       XLA_AE_LINES_PKG.ValidateCurrentLine;
28205       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
28206 
28207       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
28208                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
28209                ,p_balance_type_code => l_balance_type_code);
28210 
28211    END IF;
28212 
28213    -----------------------------------------------------------------------------------------
28214    -- 4262811 Multiperiod Accounting
28215    -----------------------------------------------------------------------------------------
28216      -- No MPA option is assigned.
28217 
28218 
28219 END IF;
28220 END IF;
28221 --
28222 
28223 --
28224 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
28225    trace
28226       (p_msg      => 'END of AcctLineType_193'
28227       ,p_level    => C_LEVEL_PROCEDURE
28228       ,p_module   => l_log_module);
28229 END IF;
28230 --
28231 EXCEPTION
28232   WHEN xla_exceptions_pkg.application_exception THEN
28233       RAISE;
28234   WHEN OTHERS THEN
28235        xla_exceptions_pkg.raise_message
28236            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_193');
28237 END AcctLineType_193;
28238 --
28239 
28240 ---------------------------------------
28241 --
28242 -- PRIVATE FUNCTION
28243 --         AcctLineType_194
28244 --
28245 ---------------------------------------
28246 PROCEDURE AcctLineType_194 (
28247   p_application_id        IN NUMBER
28248  ,p_event_id              IN NUMBER
28249  ,p_calculate_acctd_flag  IN VARCHAR2
28250  ,p_calculate_g_l_flag    IN VARCHAR2
28251  ,p_actual_flag           IN OUT VARCHAR2
28252  ,p_balance_type_code     OUT VARCHAR2
28253  ,p_gain_or_loss_ref      OUT VARCHAR2
28254  
28255 --Period Close Date
28256  , p_source_1            IN DATE
28257 --Generated Code Combination Identifier
28258  , p_source_3            IN NUMBER
28259 --Expense Account Code Combination Identifier
28260  , p_source_29            IN NUMBER
28261 --Adjustment Type
28262  , p_source_35            IN VARCHAR2
28263 --Transaction Header Identifier
28264  , p_source_36            IN NUMBER
28265 --Adjustment Line Identifier
28266  , p_source_37            IN NUMBER
28267 --Distribution Type Code
28268  , p_source_38            IN VARCHAR2
28269 --Entered Amount
28270  , p_source_39            IN NUMBER
28271 --Currency Code
28272  , p_source_40            IN VARCHAR2
28273 )
28274 IS
28275 
28276 l_component_type              VARCHAR2(80);
28277 l_component_code              VARCHAR2(30);
28278 l_component_type_code         VARCHAR2(1);
28279 l_component_appl_id           INTEGER;
28280 l_amb_context_code            VARCHAR2(30);
28281 l_entity_code                 VARCHAR2(30);
28282 l_event_class_code            VARCHAR2(30);
28283 l_ae_header_id                NUMBER;
28284 l_event_type_code             VARCHAR2(30);
28285 l_line_definition_code        VARCHAR2(30);
28286 l_line_definition_owner_code  VARCHAR2(1);
28287 --
28288 -- adr variables
28289 l_segment                     VARCHAR2(30);
28290 l_ccid                        NUMBER;
28291 l_adr_transaction_coa_id      NUMBER;
28292 l_adr_accounting_coa_id       NUMBER;
28293 l_adr_flexfield_segment_code  VARCHAR2(30);
28294 l_adr_flex_value_set_id       NUMBER;
28295 l_adr_value_type_code         VARCHAR2(30);
28296 l_adr_value_combination_id    NUMBER;
28297 l_adr_value_segment_code      VARCHAR2(30);
28298 
28299 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
28300 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
28301 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
28302 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
28303 
28304 -- 4262811 Variables ------------------------------------------------------------------------------------------
28305 l_entered_amt_idx             NUMBER;
28306 l_accted_amt_idx              NUMBER;
28307 l_acc_rev_flag                VARCHAR2(1);
28308 l_accrual_line_num            NUMBER;
28309 l_tmp_amt                     NUMBER;
28310 l_acc_rev_natural_side_code   VARCHAR2(1);
28311 
28312 l_num_entries                 NUMBER;
28313 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
28314 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
28315 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
28316 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
28317 l_recog_line_1                NUMBER;
28318 l_recog_line_2                NUMBER;
28319 
28320 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
28321 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
28322 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
28323 
28324 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
28325 
28326 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
28327 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
28328 
28329 ---------------------------------------------------------------------------------------------------------------
28330 
28331 
28332 --
28333 -- bulk performance
28334 --
28338 
28335 l_balance_type_code           VARCHAR2(1);
28336 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
28337 l_log_module                  VARCHAR2(240);
28339 --
28340 -- Upgrade strategy
28341 --
28342 l_actual_upg_option           VARCHAR2(1);
28343 l_enc_upg_option           VARCHAR2(1);
28344 
28345 --
28346 BEGIN
28347 --
28348 IF g_log_enabled THEN
28349       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_194';
28350 END IF;
28351 --
28352 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
28353 
28354       trace
28355          (p_msg      => 'BEGIN of AcctLineType_194'
28356          ,p_level    => C_LEVEL_PROCEDURE
28357          ,p_module   => l_log_module);
28358 
28359 END IF;
28360 --
28361 l_component_type             := 'AMB_JLT';
28362 l_component_code             := 'FA_ADJ_EXP_BAL';
28363 l_component_type_code        := 'S';
28364 l_component_appl_id          :=  140;
28365 l_amb_context_code           := 'DEFAULT';
28366 l_entity_code                := 'TRANSACTIONS';
28367 l_event_class_code           := 'ADJUSTMENTS';
28368 l_event_type_code            := 'ADJUSTMENTS_ALL';
28369 l_line_definition_owner_code := 'S';
28370 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
28371 --
28372 l_balance_type_code          := 'A';
28373 l_segment                     := NULL;
28374 l_ccid                        := NULL;
28375 l_adr_transaction_coa_id      := NULL;
28376 l_adr_accounting_coa_id       := NULL;
28377 l_adr_flexfield_segment_code  := NULL;
28378 l_adr_flex_value_set_id       := NULL;
28379 l_adr_value_type_code         := NULL;
28380 l_adr_value_combination_id    := NULL;
28381 l_adr_value_segment_code      := NULL;
28382 
28383 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
28384 l_bflow_class_code           := '';    -- 4219869 Business Flow
28385 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
28386 l_budgetary_control_flag     := 'N';
28387 
28388 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
28389 l_bflow_applied_to_amt       := NULL; -- 5132302
28390 l_entered_amt_idx            := NULL;          -- 4262811
28391 l_accted_amt_idx             := NULL;          -- 4262811
28392 l_acc_rev_flag               := NULL;          -- 4262811
28393 l_accrual_line_num           := NULL;          -- 4262811
28394 l_tmp_amt                    := NULL;          -- 4262811
28395 --
28396  
28397 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
28398     l_balance_type_code <> 'B' THEN
28399 IF NVL(p_source_35,'
28400 ') =  'BONUS EXPENSE'
28401  THEN 
28402 
28403    --
28404    XLA_AE_LINES_PKG.SetNewLine;
28405 
28406    p_balance_type_code          := l_balance_type_code;
28407    -- set the flag so later we will know whether the gain loss line needs to be created
28408    
28409    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
28410      p_actual_flag :='A';
28411    END IF;
28412 
28413    --
28414    -- bulk performance
28415    --
28416    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
28417                                       p_header_num   => 0); -- 4262811
28418    --
28419    -- set accounting line options
28420    --
28421    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
28422            p_natural_side_code          => 'C'
28423          , p_gain_or_loss_flag          => 'N'
28424          , p_gl_transfer_mode_code      => 'S'
28425          , p_acct_entry_type_code       => 'A'
28426          , p_switch_side_flag           => 'Y'
28427          , p_merge_duplicate_code       => 'N'
28428          );
28429    --
28430    l_acc_rev_natural_side_code := 'D';  -- 4262811
28431    -- 
28432    --
28433    -- set accounting line type info
28434    --
28435    xla_ae_lines_pkg.SetAcctLineType
28436       (p_component_type             => l_component_type
28437       ,p_event_type_code            => l_event_type_code
28438       ,p_line_definition_owner_code => l_line_definition_owner_code
28439       ,p_line_definition_code       => l_line_definition_code
28440       ,p_accounting_line_code       => l_component_code
28441       ,p_accounting_line_type_code  => l_component_type_code
28442       ,p_accounting_line_appl_id    => l_component_appl_id
28443       ,p_amb_context_code           => l_amb_context_code
28444       ,p_entity_code                => l_entity_code
28445       ,p_event_class_code           => l_event_class_code);
28446    --
28447    -- set accounting class
28448    --
28449    xla_ae_lines_pkg.SetAcctClass(
28450            p_accounting_class_code  => 'EXPENSE'
28451          , p_ae_header_id           => l_ae_header_id
28452          );
28453 
28454    --
28455    -- set rounding class
28456    --
28457    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
28458                       'EXPENSE';
28459 
28460    --
28461    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
28462    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
28463    --
28464    -- bulk performance
28465    --
28466    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
28467 
28468    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
28469       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
28470 
28471    -- 4955764
28472    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
28473       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
28474 
28475    -- 4458381 Public Sector Enh
28476    
28477    --
28481    l_accted_amt_idx  := 6;
28478    -- set accounting attributes for the line type
28479    --
28480    l_entered_amt_idx := 4;
28482    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
28483    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
28484    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
28485    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
28486    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
28487    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
28488    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
28489    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
28490    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
28491    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
28492    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
28493    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
28494    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
28495 
28496    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
28497    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
28498 
28499    ---------------------------------------------------------------------------------------------------------------
28500    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
28501    ---------------------------------------------------------------------------------------------------------------
28502    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
28503 
28504    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
28505    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
28506 
28507    IF xla_accounting_cache_pkg.GetValueChar
28508          (p_source_code         => 'LEDGER_CATEGORY_CODE'
28509          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
28510    AND l_bflow_method_code = 'PRIOR_ENTRY'
28511 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
28512    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
28513          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
28514        )
28515    THEN
28516          xla_ae_lines_pkg.BflowUpgEntry
28517            (p_business_method_code    => l_bflow_method_code
28518            ,p_business_class_code     => l_bflow_class_code
28519            ,p_balance_type            => l_balance_type_code);
28520    ELSE
28521       NULL;
28522 -- No business flow processing for business flow method of NONE.
28523    END IF;
28524 
28525    --
28526    -- call analytical criteria
28527    --
28528    
28529    --
28530    -- call description
28531    --
28532    
28533 xla_ae_lines_pkg.SetLineDescription(
28534    p_ae_header_id => l_ae_header_id
28535   ,p_description  => Description_12 (
28536      p_application_id         => p_application_id
28537    , p_ae_header_id           => l_ae_header_id 
28538 , p_source_1 => p_source_1
28539    )
28540 );
28541 
28542 
28543    --
28544    -- call ADRs
28545    -- Bug 4922099
28546    --
28547    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
28548         (NVL(l_actual_upg_option, 'N') = 'O') OR
28549         (NVL(l_enc_upg_option, 'N') = 'O')
28550       )
28551    THEN
28552    NULL;
28553    --
28554    --
28555    
28556   l_ccid := AcctDerRule_175(
28557            p_application_id           => p_application_id
28558          , p_ae_header_id             => l_ae_header_id 
28559 , p_source_3 => p_source_3
28560 , p_source_29 => p_source_29
28561          , x_transaction_coa_id       => l_adr_transaction_coa_id
28562          , x_accounting_coa_id        => l_adr_accounting_coa_id
28563          , x_value_type_code          => l_adr_value_type_code
28564          , p_side                     => 'NA'
28565    );
28566 
28567    xla_ae_lines_pkg.set_ccid(
28568     p_code_combination_id          => l_ccid
28569   , p_value_type_code              => l_adr_value_type_code
28570   , p_transaction_coa_id           => l_adr_transaction_coa_id
28571   , p_accounting_coa_id            => l_adr_accounting_coa_id
28572   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
28573   , p_adr_type_code                => 'S'
28574   , p_component_type               => l_component_type
28575   , p_component_code               => l_component_code
28576   , p_component_type_code          => l_component_type_code
28577   , p_component_appl_id            => l_component_appl_id
28578   , p_amb_context_code             => l_amb_context_code
28579   , p_side                         => 'NA'
28580   );
28581 
28582 
28583    --
28584    --
28585    END IF;
28586    --
28587    -- Bug 4922099
28588    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
28589           (NVL(l_enc_upg_option, 'N') = 'O')
28590         ) AND
28591         (l_bflow_method_code = 'PRIOR_ENTRY')
28592       )
28593    THEN
28594       IF
28595       --
28596       1 = 2
28597       --
28598       THEN
28599       xla_accounting_err_pkg.build_message
28600                                     (p_appli_s_name            => 'XLA'
28601                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
28602                                     ,p_token_1                 => 'LINE_NUMBER'
28603                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
28604                                     ,p_token_2                 => 'LINE_TYPE_NAME'
28605                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
28606                                                                              l_component_type
28610                                                                             ,l_amb_context_code
28607                                                                             ,l_component_code
28608                                                                             ,l_component_type_code
28609                                                                             ,l_component_appl_id
28611                                                                             ,l_entity_code
28612                                                                             ,l_event_class_code
28613                                                                            )
28614                                     ,p_token_3                 => 'OWNER'
28615                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
28616                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
28617                                                                           ,p_lookup_code    => l_component_type_code
28618                                                                          )
28619                                     ,p_token_4                 => 'PRODUCT_NAME'
28620                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
28621                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
28622                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
28623                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
28624                                     ,p_ae_header_id            =>  NULL
28625                                        );
28626 
28627         IF (C_LEVEL_ERROR>= g_log_level) THEN
28628                  trace
28629                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
28630                       ,p_level    => C_LEVEL_ERROR
28631                       ,p_module   => l_log_module);
28632         END IF;
28633       END IF;
28634    END IF;
28635    --
28636    --
28637    ------------------------------------------------------------------------------------------------
28638    -- 4219869 Business Flow
28639    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
28640    -- Prior Entry.  Currently, the following code is always generated.
28641    ------------------------------------------------------------------------------------------------
28642    XLA_AE_LINES_PKG.ValidateCurrentLine;
28643 
28644    ------------------------------------------------------------------------------------
28645    -- 4219869 Business Flow
28646    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
28647    ------------------------------------------------------------------------------------
28648    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
28649 
28650    ----------------------------------------------------------------------------------
28651    -- 4219869 Business Flow
28652    -- Update journal entry status -- Need to generate this within IF <condition>
28653    ----------------------------------------------------------------------------------
28654    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
28655          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
28656          ,p_balance_type_code => l_balance_type_code
28657          );
28658 
28659    -------------------------------------------------------------------------------------------
28660    -- 4262811 - Generate the Accrual Reversal lines
28661    -------------------------------------------------------------------------------------------
28662    BEGIN
28663       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
28664                               (g_array_event(p_event_id).array_value_num('header_index'));
28665       IF l_acc_rev_flag IS NULL THEN
28666          l_acc_rev_flag := 'N';
28667       END IF;
28668    EXCEPTION
28669       WHEN OTHERS THEN
28670          l_acc_rev_flag := 'N';
28671    END;
28672    --
28673    IF (l_acc_rev_flag = 'Y') THEN
28674 
28675        -- 4645092  ------------------------------------------------------------------------------
28676        -- To allow MPA report to determine if it should generate report process
28677        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
28678        ------------------------------------------------------------------------------------------
28679 
28680        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
28681        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
28682    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
28683    -- call ADRs
28684    -- Bug 4922099
28685    --
28686    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
28687         (NVL(l_actual_upg_option, 'N') = 'O') OR
28688         (NVL(l_enc_upg_option, 'N') = 'O')
28689       )
28690    THEN
28691    NULL;
28692    --
28693    --
28694    
28695   l_ccid := AcctDerRule_175(
28696            p_application_id           => p_application_id
28697          , p_ae_header_id             => l_ae_header_id 
28698 , p_source_3 => p_source_3
28699 , p_source_29 => p_source_29
28700          , x_transaction_coa_id       => l_adr_transaction_coa_id
28701          , x_accounting_coa_id        => l_adr_accounting_coa_id
28702          , x_value_type_code          => l_adr_value_type_code
28703          , p_side                     => 'NA'
28704    );
28705 
28706    xla_ae_lines_pkg.set_ccid(
28707     p_code_combination_id          => l_ccid
28708   , p_value_type_code              => l_adr_value_type_code
28709   , p_transaction_coa_id           => l_adr_transaction_coa_id
28710   , p_accounting_coa_id            => l_adr_accounting_coa_id
28711   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
28712   , p_adr_type_code                => 'S'
28716   , p_component_appl_id            => l_component_appl_id
28713   , p_component_type               => l_component_type
28714   , p_component_code               => l_component_code
28715   , p_component_type_code          => l_component_type_code
28717   , p_amb_context_code             => l_amb_context_code
28718   , p_side                         => 'NA'
28719   );
28720 
28721 
28722    --
28723    --
28724    END IF;
28725 
28726        --
28727        -- Update the line information that should be overwritten
28728        --
28729        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
28730                                          p_header_num   => 1);
28731        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
28732 
28733        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
28734 
28735        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
28736           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
28737        END IF;
28738 
28739       --
28740       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
28741       --
28742       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
28743           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
28744       ELSE
28745           ---------------------------------------------------------------------------------------------------
28746           -- 4262811a Switch Sign
28747           ---------------------------------------------------------------------------------------------------
28748           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
28749           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
28750                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28751           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
28752                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28753           -- 5132302
28754           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
28755                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28756 
28757       END IF;
28758 
28759       -- 4955764
28760       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
28761       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
28762 
28763 
28764       XLA_AE_LINES_PKG.ValidateCurrentLine;
28765       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
28766 
28767       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
28768                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
28769                ,p_balance_type_code => l_balance_type_code);
28770 
28771    END IF;
28772 
28773    -----------------------------------------------------------------------------------------
28774    -- 4262811 Multiperiod Accounting
28775    -----------------------------------------------------------------------------------------
28776      -- No MPA option is assigned.
28777 
28778 
28779 END IF;
28780 END IF;
28781 --
28782 
28783 --
28784 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
28785    trace
28786       (p_msg      => 'END of AcctLineType_194'
28787       ,p_level    => C_LEVEL_PROCEDURE
28788       ,p_module   => l_log_module);
28789 END IF;
28790 --
28791 EXCEPTION
28792   WHEN xla_exceptions_pkg.application_exception THEN
28793       RAISE;
28794   WHEN OTHERS THEN
28795        xla_exceptions_pkg.raise_message
28796            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_194');
28797 END AcctLineType_194;
28798 --
28799 
28800 ---------------------------------------
28801 --
28802 -- PRIVATE FUNCTION
28803 --         AcctLineType_195
28804 --
28805 ---------------------------------------
28806 PROCEDURE AcctLineType_195 (
28807   p_application_id        IN NUMBER
28808  ,p_event_id              IN NUMBER
28809  ,p_calculate_acctd_flag  IN VARCHAR2
28810  ,p_calculate_g_l_flag    IN VARCHAR2
28811  ,p_actual_flag           IN OUT VARCHAR2
28812  ,p_balance_type_code     OUT VARCHAR2
28813  ,p_gain_or_loss_ref      OUT VARCHAR2
28814  
28815 --Period Close Date
28816  , p_source_1            IN DATE
28817 --Generated Code Combination Identifier
28818  , p_source_3            IN NUMBER
28819 --Intercompany Payables Account
28820  , p_source_19            IN VARCHAR2
28821 --Expense Account Code Combination Identifier
28822  , p_source_29            IN NUMBER
28823 --Default Code Combination Identifier
28824  , p_source_30            IN NUMBER
28825 --Adjustment Type
28826  , p_source_35            IN VARCHAR2
28827 --Transaction Header Identifier
28828  , p_source_36            IN NUMBER
28829 --Adjustment Line Identifier
28830  , p_source_37            IN NUMBER
28831 --Distribution Type Code
28832  , p_source_38            IN VARCHAR2
28833 --Entered Amount
28834  , p_source_39            IN NUMBER
28835 --Currency Code
28836  , p_source_40            IN VARCHAR2
28837 )
28838 IS
28839 
28840 l_component_type              VARCHAR2(80);
28841 l_component_code              VARCHAR2(30);
28842 l_component_type_code         VARCHAR2(1);
28843 l_component_appl_id           INTEGER;
28844 l_amb_context_code            VARCHAR2(30);
28845 l_entity_code                 VARCHAR2(30);
28846 l_event_class_code            VARCHAR2(30);
28847 l_ae_header_id                NUMBER;
28851 --
28848 l_event_type_code             VARCHAR2(30);
28849 l_line_definition_code        VARCHAR2(30);
28850 l_line_definition_owner_code  VARCHAR2(1);
28852 -- adr variables
28853 l_segment                     VARCHAR2(30);
28854 l_ccid                        NUMBER;
28855 l_adr_transaction_coa_id      NUMBER;
28856 l_adr_accounting_coa_id       NUMBER;
28857 l_adr_flexfield_segment_code  VARCHAR2(30);
28858 l_adr_flex_value_set_id       NUMBER;
28859 l_adr_value_type_code         VARCHAR2(30);
28860 l_adr_value_combination_id    NUMBER;
28861 l_adr_value_segment_code      VARCHAR2(30);
28862 
28863 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
28864 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
28865 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
28866 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
28867 
28868 -- 4262811 Variables ------------------------------------------------------------------------------------------
28869 l_entered_amt_idx             NUMBER;
28870 l_accted_amt_idx              NUMBER;
28871 l_acc_rev_flag                VARCHAR2(1);
28872 l_accrual_line_num            NUMBER;
28873 l_tmp_amt                     NUMBER;
28874 l_acc_rev_natural_side_code   VARCHAR2(1);
28875 
28876 l_num_entries                 NUMBER;
28877 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
28878 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
28879 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
28880 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
28881 l_recog_line_1                NUMBER;
28882 l_recog_line_2                NUMBER;
28883 
28884 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
28885 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
28886 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
28887 
28888 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
28889 
28890 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
28891 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
28892 
28893 ---------------------------------------------------------------------------------------------------------------
28894 
28895 
28896 --
28897 -- bulk performance
28898 --
28899 l_balance_type_code           VARCHAR2(1);
28900 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
28901 l_log_module                  VARCHAR2(240);
28902 
28903 --
28904 -- Upgrade strategy
28905 --
28906 l_actual_upg_option           VARCHAR2(1);
28907 l_enc_upg_option           VARCHAR2(1);
28908 
28909 --
28910 BEGIN
28911 --
28912 IF g_log_enabled THEN
28913       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_195';
28914 END IF;
28915 --
28916 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
28917 
28918       trace
28919          (p_msg      => 'BEGIN of AcctLineType_195'
28920          ,p_level    => C_LEVEL_PROCEDURE
28921          ,p_module   => l_log_module);
28922 
28923 END IF;
28924 --
28925 l_component_type             := 'AMB_JLT';
28926 l_component_code             := 'FA_ADJ_IC_PAY';
28927 l_component_type_code        := 'S';
28928 l_component_appl_id          :=  140;
28929 l_amb_context_code           := 'DEFAULT';
28930 l_entity_code                := 'TRANSACTIONS';
28931 l_event_class_code           := 'ADJUSTMENTS';
28932 l_event_type_code            := 'ADJUSTMENTS_ALL';
28933 l_line_definition_owner_code := 'S';
28934 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
28935 --
28936 l_balance_type_code          := 'A';
28937 l_segment                     := NULL;
28938 l_ccid                        := NULL;
28939 l_adr_transaction_coa_id      := NULL;
28940 l_adr_accounting_coa_id       := NULL;
28941 l_adr_flexfield_segment_code  := NULL;
28942 l_adr_flex_value_set_id       := NULL;
28943 l_adr_value_type_code         := NULL;
28944 l_adr_value_combination_id    := NULL;
28945 l_adr_value_segment_code      := NULL;
28946 
28947 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
28948 l_bflow_class_code           := '';    -- 4219869 Business Flow
28949 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
28950 l_budgetary_control_flag     := 'N';
28951 
28952 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
28953 l_bflow_applied_to_amt       := NULL; -- 5132302
28954 l_entered_amt_idx            := NULL;          -- 4262811
28955 l_accted_amt_idx             := NULL;          -- 4262811
28956 l_acc_rev_flag               := NULL;          -- 4262811
28957 l_accrual_line_num           := NULL;          -- 4262811
28958 l_tmp_amt                    := NULL;          -- 4262811
28959 --
28960  
28961 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
28962     l_balance_type_code <> 'B' THEN
28963 IF NVL(p_source_35,'
28964 ') =  'INTERCO AP'
28965  THEN 
28966 
28967    --
28968    XLA_AE_LINES_PKG.SetNewLine;
28969 
28970    p_balance_type_code          := l_balance_type_code;
28971    -- set the flag so later we will know whether the gain loss line needs to be created
28972    
28973    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
28974      p_actual_flag :='A';
28975    END IF;
28976 
28977    --
28978    -- bulk performance
28979    --
28980    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
28981                                       p_header_num   => 0); -- 4262811
28982    --
28983    -- set accounting line options
28984    --
28985    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
28986            p_natural_side_code          => 'C'
28990          , p_switch_side_flag           => 'Y'
28987          , p_gain_or_loss_flag          => 'N'
28988          , p_gl_transfer_mode_code      => 'S'
28989          , p_acct_entry_type_code       => 'A'
28991          , p_merge_duplicate_code       => 'N'
28992          );
28993    --
28994    l_acc_rev_natural_side_code := 'D';  -- 4262811
28995    -- 
28996    --
28997    -- set accounting line type info
28998    --
28999    xla_ae_lines_pkg.SetAcctLineType
29000       (p_component_type             => l_component_type
29001       ,p_event_type_code            => l_event_type_code
29002       ,p_line_definition_owner_code => l_line_definition_owner_code
29003       ,p_line_definition_code       => l_line_definition_code
29004       ,p_accounting_line_code       => l_component_code
29005       ,p_accounting_line_type_code  => l_component_type_code
29006       ,p_accounting_line_appl_id    => l_component_appl_id
29007       ,p_amb_context_code           => l_amb_context_code
29008       ,p_entity_code                => l_entity_code
29009       ,p_event_class_code           => l_event_class_code);
29010    --
29011    -- set accounting class
29012    --
29013    xla_ae_lines_pkg.SetAcctClass(
29014            p_accounting_class_code  => 'LIABILITY'
29015          , p_ae_header_id           => l_ae_header_id
29016          );
29017 
29018    --
29019    -- set rounding class
29020    --
29021    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
29022                       'LIABILITY';
29023 
29024    --
29025    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
29026    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
29027    --
29028    -- bulk performance
29029    --
29030    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
29031 
29032    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
29033       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
29034 
29035    -- 4955764
29036    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
29037       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
29038 
29039    -- 4458381 Public Sector Enh
29040    
29041    --
29042    -- set accounting attributes for the line type
29043    --
29044    l_entered_amt_idx := 4;
29045    l_accted_amt_idx  := 6;
29046    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
29047    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
29048    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
29049    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
29050    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
29051    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
29052    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
29053    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
29054    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
29055    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
29056    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
29057    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
29058    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
29059 
29060    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
29061    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
29062 
29063    ---------------------------------------------------------------------------------------------------------------
29064    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
29065    ---------------------------------------------------------------------------------------------------------------
29066    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
29067 
29068    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
29069    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
29070 
29071    IF xla_accounting_cache_pkg.GetValueChar
29072          (p_source_code         => 'LEDGER_CATEGORY_CODE'
29073          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
29074    AND l_bflow_method_code = 'PRIOR_ENTRY'
29075 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
29076    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
29077          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
29078        )
29079    THEN
29080          xla_ae_lines_pkg.BflowUpgEntry
29081            (p_business_method_code    => l_bflow_method_code
29082            ,p_business_class_code     => l_bflow_class_code
29083            ,p_balance_type            => l_balance_type_code);
29084    ELSE
29085       NULL;
29086 -- No business flow processing for business flow method of NONE.
29087    END IF;
29088 
29089    --
29090    -- call analytical criteria
29091    --
29092    
29093    --
29094    -- call description
29095    --
29096    
29097 xla_ae_lines_pkg.SetLineDescription(
29098    p_ae_header_id => l_ae_header_id
29099   ,p_description  => Description_13 (
29100      p_application_id         => p_application_id
29101    , p_ae_header_id           => l_ae_header_id 
29102 , p_source_1 => p_source_1
29103    )
29104 );
29105 
29106 
29107    --
29108    -- call ADRs
29109    -- Bug 4922099
29110    --
29111    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
29112         (NVL(l_actual_upg_option, 'N') = 'O') OR
29113         (NVL(l_enc_upg_option, 'N') = 'O')
29114       )
29115    THEN
29119    
29116    NULL;
29117    --
29118    --
29120   l_ccid := AcctDerRule_173(
29121            p_application_id           => p_application_id
29122          , p_ae_header_id             => l_ae_header_id 
29123 , p_source_3 => p_source_3
29124 , p_source_30 => p_source_30
29125          , x_transaction_coa_id       => l_adr_transaction_coa_id
29126          , x_accounting_coa_id        => l_adr_accounting_coa_id
29127          , x_value_type_code          => l_adr_value_type_code
29128          , p_side                     => 'NA'
29129    );
29130 
29131    xla_ae_lines_pkg.set_ccid(
29132     p_code_combination_id          => l_ccid
29133   , p_value_type_code              => l_adr_value_type_code
29134   , p_transaction_coa_id           => l_adr_transaction_coa_id
29135   , p_accounting_coa_id            => l_adr_accounting_coa_id
29136   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
29137   , p_adr_type_code                => 'S'
29138   , p_component_type               => l_component_type
29139   , p_component_code               => l_component_code
29140   , p_component_type_code          => l_component_type_code
29141   , p_component_appl_id            => l_component_appl_id
29142   , p_amb_context_code             => l_amb_context_code
29143   , p_side                         => 'NA'
29144   );
29145 
29146 
29147    l_segment := AcctDerRule_168(
29148            p_application_id           => p_application_id
29149          , p_ae_header_id             => l_ae_header_id 
29150 , p_source_3 => p_source_3
29151 , p_source_29 => p_source_29
29152          , x_transaction_coa_id       => l_adr_transaction_coa_id
29153          , x_accounting_coa_id        => l_adr_accounting_coa_id
29154          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29155          , x_flex_value_set_id        => l_adr_flex_value_set_id
29156          , x_value_type_code          => l_adr_value_type_code
29157          , x_value_combination_id     => l_adr_value_combination_id
29158          , x_value_segment_code       => l_adr_value_segment_code
29159          , p_side                     => 'NA'
29160          , p_override_seg_flag        => 'Y'
29161    );
29162 
29163    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29164 
29165       xla_ae_lines_pkg.set_segment(
29166           p_to_segment_code         => 'GL_BALANCING'
29167         , p_segment_value           => l_segment
29168         , p_from_segment_code       => l_adr_value_segment_code
29169         , p_from_combination_id     => l_adr_value_combination_id
29170         , p_value_type_code         => l_adr_value_type_code
29171         , p_transaction_coa_id      => l_adr_transaction_coa_id
29172         , p_accounting_coa_id       => l_adr_accounting_coa_id
29173         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29174         , p_flex_value_set_id       => l_adr_flex_value_set_id
29175         , p_adr_code                => 'FA_EXPENSE_ACCT'
29176         , p_adr_type_code           => 'S'
29177         , p_component_type          => l_component_type
29178         , p_component_code          => l_component_code
29179         , p_component_type_code     => l_component_type_code
29180         , p_component_appl_id       => l_component_appl_id
29181         , p_amb_context_code        => l_amb_context_code
29182         , p_entity_code             => 'TRANSACTIONS'
29183         , p_event_class_code        => 'ADJUSTMENTS'
29184         , p_side                    => 'NA'
29185         );
29186 
29187   END IF;
29188 
29189    l_segment := AcctDerRule_157(
29190            p_application_id           => p_application_id
29191          , p_ae_header_id             => l_ae_header_id 
29192 , p_source_3 => p_source_3
29193 , p_source_19 => p_source_19
29194          , x_transaction_coa_id       => l_adr_transaction_coa_id
29195          , x_accounting_coa_id        => l_adr_accounting_coa_id
29196          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29197          , x_flex_value_set_id        => l_adr_flex_value_set_id
29198          , x_value_type_code          => l_adr_value_type_code
29199          , x_value_combination_id     => l_adr_value_combination_id
29200          , x_value_segment_code       => l_adr_value_segment_code
29201          , p_side                     => 'NA'
29202          , p_override_seg_flag        => 'Y'
29203    );
29204 
29205    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29206 
29207       xla_ae_lines_pkg.set_segment(
29208           p_to_segment_code         => 'GL_ACCOUNT'
29209         , p_segment_value           => l_segment
29210         , p_from_segment_code       => l_adr_value_segment_code
29211         , p_from_combination_id     => l_adr_value_combination_id
29212         , p_value_type_code         => l_adr_value_type_code
29213         , p_transaction_coa_id      => l_adr_transaction_coa_id
29214         , p_accounting_coa_id       => l_adr_accounting_coa_id
29215         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29216         , p_flex_value_set_id       => l_adr_flex_value_set_id
29217         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
29218         , p_adr_type_code           => 'S'
29219         , p_component_type          => l_component_type
29220         , p_component_code          => l_component_code
29221         , p_component_type_code     => l_component_type_code
29222         , p_component_appl_id       => l_component_appl_id
29223         , p_amb_context_code        => l_amb_context_code
29224         , p_entity_code             => 'TRANSACTIONS'
29225         , p_event_class_code        => 'ADJUSTMENTS'
29226         , p_side                    => 'NA'
29227         );
29228 
29229   END IF;
29230 
29231    --
29232    --
29233    END IF;
29234    --
29235    -- Bug 4922099
29236    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
29237           (NVL(l_enc_upg_option, 'N') = 'O')
29238         ) AND
29242       IF
29239         (l_bflow_method_code = 'PRIOR_ENTRY')
29240       )
29241    THEN
29243       --
29244       1 = 2
29245       --
29246       THEN
29247       xla_accounting_err_pkg.build_message
29248                                     (p_appli_s_name            => 'XLA'
29249                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
29250                                     ,p_token_1                 => 'LINE_NUMBER'
29251                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
29252                                     ,p_token_2                 => 'LINE_TYPE_NAME'
29253                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
29254                                                                              l_component_type
29255                                                                             ,l_component_code
29256                                                                             ,l_component_type_code
29257                                                                             ,l_component_appl_id
29258                                                                             ,l_amb_context_code
29259                                                                             ,l_entity_code
29260                                                                             ,l_event_class_code
29261                                                                            )
29262                                     ,p_token_3                 => 'OWNER'
29263                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
29264                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
29265                                                                           ,p_lookup_code    => l_component_type_code
29266                                                                          )
29267                                     ,p_token_4                 => 'PRODUCT_NAME'
29268                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
29269                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
29270                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
29271                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
29272                                     ,p_ae_header_id            =>  NULL
29273                                        );
29274 
29275         IF (C_LEVEL_ERROR>= g_log_level) THEN
29276                  trace
29277                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
29278                       ,p_level    => C_LEVEL_ERROR
29279                       ,p_module   => l_log_module);
29280         END IF;
29281       END IF;
29282    END IF;
29283    --
29284    --
29285    ------------------------------------------------------------------------------------------------
29286    -- 4219869 Business Flow
29287    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
29288    -- Prior Entry.  Currently, the following code is always generated.
29289    ------------------------------------------------------------------------------------------------
29290    XLA_AE_LINES_PKG.ValidateCurrentLine;
29291 
29292    ------------------------------------------------------------------------------------
29293    -- 4219869 Business Flow
29294    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
29295    ------------------------------------------------------------------------------------
29296    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
29297 
29298    ----------------------------------------------------------------------------------
29299    -- 4219869 Business Flow
29300    -- Update journal entry status -- Need to generate this within IF <condition>
29301    ----------------------------------------------------------------------------------
29302    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
29303          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
29304          ,p_balance_type_code => l_balance_type_code
29305          );
29306 
29307    -------------------------------------------------------------------------------------------
29308    -- 4262811 - Generate the Accrual Reversal lines
29309    -------------------------------------------------------------------------------------------
29310    BEGIN
29311       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
29312                               (g_array_event(p_event_id).array_value_num('header_index'));
29313       IF l_acc_rev_flag IS NULL THEN
29314          l_acc_rev_flag := 'N';
29315       END IF;
29316    EXCEPTION
29317       WHEN OTHERS THEN
29318          l_acc_rev_flag := 'N';
29319    END;
29320    --
29321    IF (l_acc_rev_flag = 'Y') THEN
29322 
29323        -- 4645092  ------------------------------------------------------------------------------
29324        -- To allow MPA report to determine if it should generate report process
29325        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
29326        ------------------------------------------------------------------------------------------
29327 
29328        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
29329        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
29330    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
29331    -- call ADRs
29332    -- Bug 4922099
29333    --
29334    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
29335         (NVL(l_actual_upg_option, 'N') = 'O') OR
29336         (NVL(l_enc_upg_option, 'N') = 'O')
29337       )
29338    THEN
29339    NULL;
29340    --
29341    --
29342    
29343   l_ccid := AcctDerRule_173(
29347 , p_source_30 => p_source_30
29344            p_application_id           => p_application_id
29345          , p_ae_header_id             => l_ae_header_id 
29346 , p_source_3 => p_source_3
29348          , x_transaction_coa_id       => l_adr_transaction_coa_id
29349          , x_accounting_coa_id        => l_adr_accounting_coa_id
29350          , x_value_type_code          => l_adr_value_type_code
29351          , p_side                     => 'NA'
29352    );
29353 
29354    xla_ae_lines_pkg.set_ccid(
29355     p_code_combination_id          => l_ccid
29356   , p_value_type_code              => l_adr_value_type_code
29357   , p_transaction_coa_id           => l_adr_transaction_coa_id
29358   , p_accounting_coa_id            => l_adr_accounting_coa_id
29359   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
29360   , p_adr_type_code                => 'S'
29361   , p_component_type               => l_component_type
29362   , p_component_code               => l_component_code
29363   , p_component_type_code          => l_component_type_code
29364   , p_component_appl_id            => l_component_appl_id
29365   , p_amb_context_code             => l_amb_context_code
29366   , p_side                         => 'NA'
29367   );
29368 
29369 
29370    l_segment := AcctDerRule_168(
29371            p_application_id           => p_application_id
29372          , p_ae_header_id             => l_ae_header_id 
29373 , p_source_3 => p_source_3
29374 , p_source_29 => p_source_29
29375          , x_transaction_coa_id       => l_adr_transaction_coa_id
29376          , x_accounting_coa_id        => l_adr_accounting_coa_id
29377          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29378          , x_flex_value_set_id        => l_adr_flex_value_set_id
29379          , x_value_type_code          => l_adr_value_type_code
29380          , x_value_combination_id     => l_adr_value_combination_id
29381          , x_value_segment_code       => l_adr_value_segment_code
29382          , p_side                     => 'NA'
29383          , p_override_seg_flag        => 'Y'
29384    );
29385 
29386    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29387 
29388       xla_ae_lines_pkg.set_segment(
29389           p_to_segment_code         => 'GL_BALANCING'
29390         , p_segment_value           => l_segment
29391         , p_from_segment_code       => l_adr_value_segment_code
29392         , p_from_combination_id     => l_adr_value_combination_id
29393         , p_value_type_code         => l_adr_value_type_code
29394         , p_transaction_coa_id      => l_adr_transaction_coa_id
29395         , p_accounting_coa_id       => l_adr_accounting_coa_id
29396         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29397         , p_flex_value_set_id       => l_adr_flex_value_set_id
29398         , p_adr_code                => 'FA_EXPENSE_ACCT'
29399         , p_adr_type_code           => 'S'
29400         , p_component_type          => l_component_type
29401         , p_component_code          => l_component_code
29402         , p_component_type_code     => l_component_type_code
29403         , p_component_appl_id       => l_component_appl_id
29404         , p_amb_context_code        => l_amb_context_code
29405         , p_entity_code             => 'TRANSACTIONS'
29406         , p_event_class_code        => 'ADJUSTMENTS'
29407         , p_side                    => 'NA'
29408         );
29409 
29410   END IF;
29411 
29412    l_segment := AcctDerRule_157(
29413            p_application_id           => p_application_id
29414          , p_ae_header_id             => l_ae_header_id 
29415 , p_source_3 => p_source_3
29416 , p_source_19 => p_source_19
29417          , x_transaction_coa_id       => l_adr_transaction_coa_id
29418          , x_accounting_coa_id        => l_adr_accounting_coa_id
29419          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29420          , x_flex_value_set_id        => l_adr_flex_value_set_id
29421          , x_value_type_code          => l_adr_value_type_code
29422          , x_value_combination_id     => l_adr_value_combination_id
29423          , x_value_segment_code       => l_adr_value_segment_code
29424          , p_side                     => 'NA'
29425          , p_override_seg_flag        => 'Y'
29426    );
29427 
29428    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29429 
29430       xla_ae_lines_pkg.set_segment(
29431           p_to_segment_code         => 'GL_ACCOUNT'
29432         , p_segment_value           => l_segment
29433         , p_from_segment_code       => l_adr_value_segment_code
29434         , p_from_combination_id     => l_adr_value_combination_id
29435         , p_value_type_code         => l_adr_value_type_code
29436         , p_transaction_coa_id      => l_adr_transaction_coa_id
29437         , p_accounting_coa_id       => l_adr_accounting_coa_id
29438         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29439         , p_flex_value_set_id       => l_adr_flex_value_set_id
29440         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
29441         , p_adr_type_code           => 'S'
29442         , p_component_type          => l_component_type
29443         , p_component_code          => l_component_code
29444         , p_component_type_code     => l_component_type_code
29445         , p_component_appl_id       => l_component_appl_id
29446         , p_amb_context_code        => l_amb_context_code
29447         , p_entity_code             => 'TRANSACTIONS'
29448         , p_event_class_code        => 'ADJUSTMENTS'
29449         , p_side                    => 'NA'
29450         );
29451 
29452   END IF;
29453 
29454    --
29455    --
29456    END IF;
29457 
29458        --
29459        -- Update the line information that should be overwritten
29460        --
29461        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
29462                                          p_header_num   => 1);
29466 
29463        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
29464 
29465        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
29467        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
29468           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
29469        END IF;
29470 
29471       --
29472       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
29473       --
29474       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
29475           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
29476       ELSE
29477           ---------------------------------------------------------------------------------------------------
29478           -- 4262811a Switch Sign
29479           ---------------------------------------------------------------------------------------------------
29480           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
29481           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
29482                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29483           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
29484                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29485           -- 5132302
29486           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
29487                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29488 
29489       END IF;
29490 
29491       -- 4955764
29492       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
29493       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
29494 
29495 
29496       XLA_AE_LINES_PKG.ValidateCurrentLine;
29497       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
29498 
29499       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
29500                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
29501                ,p_balance_type_code => l_balance_type_code);
29502 
29503    END IF;
29504 
29505    -----------------------------------------------------------------------------------------
29506    -- 4262811 Multiperiod Accounting
29507    -----------------------------------------------------------------------------------------
29508      -- No MPA option is assigned.
29509 
29510 
29511 END IF;
29512 END IF;
29513 --
29514 
29515 --
29516 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29517    trace
29518       (p_msg      => 'END of AcctLineType_195'
29519       ,p_level    => C_LEVEL_PROCEDURE
29520       ,p_module   => l_log_module);
29521 END IF;
29522 --
29523 EXCEPTION
29524   WHEN xla_exceptions_pkg.application_exception THEN
29525       RAISE;
29526   WHEN OTHERS THEN
29527        xla_exceptions_pkg.raise_message
29528            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_195');
29529 END AcctLineType_195;
29530 --
29531 
29532 ---------------------------------------
29533 --
29534 -- PRIVATE FUNCTION
29535 --         AcctLineType_196
29536 --
29537 ---------------------------------------
29538 PROCEDURE AcctLineType_196 (
29539   p_application_id        IN NUMBER
29540  ,p_event_id              IN NUMBER
29541  ,p_calculate_acctd_flag  IN VARCHAR2
29542  ,p_calculate_g_l_flag    IN VARCHAR2
29543  ,p_actual_flag           IN OUT VARCHAR2
29544  ,p_balance_type_code     OUT VARCHAR2
29545  ,p_gain_or_loss_ref      OUT VARCHAR2
29546  
29547 --Period Close Date
29548  , p_source_1            IN DATE
29549 --Generated Code Combination Identifier
29550  , p_source_3            IN NUMBER
29551 --Intercompany Receivables Account
29552  , p_source_20            IN VARCHAR2
29553 --Expense Account Code Combination Identifier
29554  , p_source_29            IN NUMBER
29555 --Default Code Combination Identifier
29556  , p_source_30            IN NUMBER
29557 --Adjustment Type
29558  , p_source_35            IN VARCHAR2
29559 --Transaction Header Identifier
29560  , p_source_36            IN NUMBER
29561 --Adjustment Line Identifier
29562  , p_source_37            IN NUMBER
29563 --Distribution Type Code
29564  , p_source_38            IN VARCHAR2
29565 --Entered Amount
29566  , p_source_39            IN NUMBER
29567 --Currency Code
29568  , p_source_40            IN VARCHAR2
29569 )
29570 IS
29571 
29572 l_component_type              VARCHAR2(80);
29573 l_component_code              VARCHAR2(30);
29574 l_component_type_code         VARCHAR2(1);
29575 l_component_appl_id           INTEGER;
29576 l_amb_context_code            VARCHAR2(30);
29577 l_entity_code                 VARCHAR2(30);
29578 l_event_class_code            VARCHAR2(30);
29579 l_ae_header_id                NUMBER;
29580 l_event_type_code             VARCHAR2(30);
29581 l_line_definition_code        VARCHAR2(30);
29582 l_line_definition_owner_code  VARCHAR2(1);
29583 --
29584 -- adr variables
29585 l_segment                     VARCHAR2(30);
29586 l_ccid                        NUMBER;
29587 l_adr_transaction_coa_id      NUMBER;
29588 l_adr_accounting_coa_id       NUMBER;
29589 l_adr_flexfield_segment_code  VARCHAR2(30);
29590 l_adr_flex_value_set_id       NUMBER;
29591 l_adr_value_type_code         VARCHAR2(30);
29592 l_adr_value_combination_id    NUMBER;
29593 l_adr_value_segment_code      VARCHAR2(30);
29594 
29595 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
29599 
29596 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
29597 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
29598 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
29600 -- 4262811 Variables ------------------------------------------------------------------------------------------
29601 l_entered_amt_idx             NUMBER;
29602 l_accted_amt_idx              NUMBER;
29603 l_acc_rev_flag                VARCHAR2(1);
29604 l_accrual_line_num            NUMBER;
29605 l_tmp_amt                     NUMBER;
29606 l_acc_rev_natural_side_code   VARCHAR2(1);
29607 
29608 l_num_entries                 NUMBER;
29609 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
29610 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
29611 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
29612 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
29613 l_recog_line_1                NUMBER;
29614 l_recog_line_2                NUMBER;
29615 
29616 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
29617 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
29618 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
29619 
29620 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
29621 
29622 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
29623 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
29624 
29625 ---------------------------------------------------------------------------------------------------------------
29626 
29627 
29628 --
29629 -- bulk performance
29630 --
29631 l_balance_type_code           VARCHAR2(1);
29632 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
29633 l_log_module                  VARCHAR2(240);
29634 
29635 --
29636 -- Upgrade strategy
29637 --
29638 l_actual_upg_option           VARCHAR2(1);
29639 l_enc_upg_option           VARCHAR2(1);
29640 
29641 --
29642 BEGIN
29643 --
29644 IF g_log_enabled THEN
29645       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_196';
29646 END IF;
29647 --
29648 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29649 
29650       trace
29651          (p_msg      => 'BEGIN of AcctLineType_196'
29652          ,p_level    => C_LEVEL_PROCEDURE
29653          ,p_module   => l_log_module);
29654 
29655 END IF;
29656 --
29657 l_component_type             := 'AMB_JLT';
29658 l_component_code             := 'FA_ADJ_IC_REC';
29659 l_component_type_code        := 'S';
29660 l_component_appl_id          :=  140;
29661 l_amb_context_code           := 'DEFAULT';
29662 l_entity_code                := 'TRANSACTIONS';
29663 l_event_class_code           := 'ADJUSTMENTS';
29664 l_event_type_code            := 'ADJUSTMENTS_ALL';
29665 l_line_definition_owner_code := 'S';
29666 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
29667 --
29668 l_balance_type_code          := 'A';
29669 l_segment                     := NULL;
29670 l_ccid                        := NULL;
29671 l_adr_transaction_coa_id      := NULL;
29672 l_adr_accounting_coa_id       := NULL;
29673 l_adr_flexfield_segment_code  := NULL;
29674 l_adr_flex_value_set_id       := NULL;
29675 l_adr_value_type_code         := NULL;
29676 l_adr_value_combination_id    := NULL;
29677 l_adr_value_segment_code      := NULL;
29678 
29679 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
29680 l_bflow_class_code           := '';    -- 4219869 Business Flow
29681 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
29682 l_budgetary_control_flag     := 'N';
29683 
29684 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
29685 l_bflow_applied_to_amt       := NULL; -- 5132302
29686 l_entered_amt_idx            := NULL;          -- 4262811
29687 l_accted_amt_idx             := NULL;          -- 4262811
29688 l_acc_rev_flag               := NULL;          -- 4262811
29689 l_accrual_line_num           := NULL;          -- 4262811
29690 l_tmp_amt                    := NULL;          -- 4262811
29691 --
29692  
29693 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
29694     l_balance_type_code <> 'B' THEN
29695 IF NVL(p_source_35,'
29696 ') =  'INTERCO AR'
29697  THEN 
29698 
29699    --
29700    XLA_AE_LINES_PKG.SetNewLine;
29701 
29702    p_balance_type_code          := l_balance_type_code;
29703    -- set the flag so later we will know whether the gain loss line needs to be created
29704    
29705    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
29706      p_actual_flag :='A';
29707    END IF;
29708 
29709    --
29710    -- bulk performance
29711    --
29712    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
29713                                       p_header_num   => 0); -- 4262811
29714    --
29715    -- set accounting line options
29716    --
29717    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
29718            p_natural_side_code          => 'D'
29719          , p_gain_or_loss_flag          => 'N'
29720          , p_gl_transfer_mode_code      => 'S'
29721          , p_acct_entry_type_code       => 'A'
29722          , p_switch_side_flag           => 'Y'
29723          , p_merge_duplicate_code       => 'N'
29724          );
29725    --
29726    l_acc_rev_natural_side_code := 'C';  -- 4262811
29727    -- 
29728    --
29729    -- set accounting line type info
29730    --
29731    xla_ae_lines_pkg.SetAcctLineType
29732       (p_component_type             => l_component_type
29733       ,p_event_type_code            => l_event_type_code
29734       ,p_line_definition_owner_code => l_line_definition_owner_code
29738       ,p_accounting_line_appl_id    => l_component_appl_id
29735       ,p_line_definition_code       => l_line_definition_code
29736       ,p_accounting_line_code       => l_component_code
29737       ,p_accounting_line_type_code  => l_component_type_code
29739       ,p_amb_context_code           => l_amb_context_code
29740       ,p_entity_code                => l_entity_code
29741       ,p_event_class_code           => l_event_class_code);
29742    --
29743    -- set accounting class
29744    --
29745    xla_ae_lines_pkg.SetAcctClass(
29746            p_accounting_class_code  => 'ASSET'
29747          , p_ae_header_id           => l_ae_header_id
29748          );
29749 
29750    --
29751    -- set rounding class
29752    --
29753    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
29754                       'ASSET';
29755 
29756    --
29757    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
29758    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
29759    --
29760    -- bulk performance
29761    --
29762    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
29763 
29764    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
29765       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
29766 
29767    -- 4955764
29768    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
29769       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
29770 
29771    -- 4458381 Public Sector Enh
29772    
29773    --
29774    -- set accounting attributes for the line type
29775    --
29776    l_entered_amt_idx := 4;
29777    l_accted_amt_idx  := 6;
29778    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
29779    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
29780    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
29781    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
29782    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
29783    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
29784    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
29785    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
29786    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
29787    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
29788    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
29789    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
29790    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
29791 
29792    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
29793    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
29794 
29795    ---------------------------------------------------------------------------------------------------------------
29796    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
29797    ---------------------------------------------------------------------------------------------------------------
29798    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
29799 
29800    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
29801    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
29802 
29803    IF xla_accounting_cache_pkg.GetValueChar
29804          (p_source_code         => 'LEDGER_CATEGORY_CODE'
29805          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
29806    AND l_bflow_method_code = 'PRIOR_ENTRY'
29807 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
29808    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
29809          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
29810        )
29811    THEN
29812          xla_ae_lines_pkg.BflowUpgEntry
29813            (p_business_method_code    => l_bflow_method_code
29814            ,p_business_class_code     => l_bflow_class_code
29815            ,p_balance_type            => l_balance_type_code);
29816    ELSE
29817       NULL;
29818 -- No business flow processing for business flow method of NONE.
29819    END IF;
29820 
29821    --
29822    -- call analytical criteria
29823    --
29824    
29825    --
29826    -- call description
29827    --
29828    
29829 xla_ae_lines_pkg.SetLineDescription(
29830    p_ae_header_id => l_ae_header_id
29831   ,p_description  => Description_14 (
29832      p_application_id         => p_application_id
29833    , p_ae_header_id           => l_ae_header_id 
29834 , p_source_1 => p_source_1
29835    )
29836 );
29837 
29838 
29839    --
29840    -- call ADRs
29841    -- Bug 4922099
29842    --
29843    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
29844         (NVL(l_actual_upg_option, 'N') = 'O') OR
29845         (NVL(l_enc_upg_option, 'N') = 'O')
29846       )
29847    THEN
29848    NULL;
29849    --
29850    --
29851    
29852   l_ccid := AcctDerRule_173(
29853            p_application_id           => p_application_id
29854          , p_ae_header_id             => l_ae_header_id 
29855 , p_source_3 => p_source_3
29856 , p_source_30 => p_source_30
29857          , x_transaction_coa_id       => l_adr_transaction_coa_id
29858          , x_accounting_coa_id        => l_adr_accounting_coa_id
29859          , x_value_type_code          => l_adr_value_type_code
29860          , p_side                     => 'NA'
29861    );
29862 
29863    xla_ae_lines_pkg.set_ccid(
29864     p_code_combination_id          => l_ccid
29868   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
29865   , p_value_type_code              => l_adr_value_type_code
29866   , p_transaction_coa_id           => l_adr_transaction_coa_id
29867   , p_accounting_coa_id            => l_adr_accounting_coa_id
29869   , p_adr_type_code                => 'S'
29870   , p_component_type               => l_component_type
29871   , p_component_code               => l_component_code
29872   , p_component_type_code          => l_component_type_code
29873   , p_component_appl_id            => l_component_appl_id
29874   , p_amb_context_code             => l_amb_context_code
29875   , p_side                         => 'NA'
29876   );
29877 
29878 
29879    l_segment := AcctDerRule_168(
29880            p_application_id           => p_application_id
29881          , p_ae_header_id             => l_ae_header_id 
29882 , p_source_3 => p_source_3
29883 , p_source_29 => p_source_29
29884          , x_transaction_coa_id       => l_adr_transaction_coa_id
29885          , x_accounting_coa_id        => l_adr_accounting_coa_id
29886          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29887          , x_flex_value_set_id        => l_adr_flex_value_set_id
29888          , x_value_type_code          => l_adr_value_type_code
29889          , x_value_combination_id     => l_adr_value_combination_id
29890          , x_value_segment_code       => l_adr_value_segment_code
29891          , p_side                     => 'NA'
29892          , p_override_seg_flag        => 'Y'
29893    );
29894 
29895    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29896 
29897       xla_ae_lines_pkg.set_segment(
29898           p_to_segment_code         => 'GL_BALANCING'
29899         , p_segment_value           => l_segment
29900         , p_from_segment_code       => l_adr_value_segment_code
29901         , p_from_combination_id     => l_adr_value_combination_id
29902         , p_value_type_code         => l_adr_value_type_code
29903         , p_transaction_coa_id      => l_adr_transaction_coa_id
29904         , p_accounting_coa_id       => l_adr_accounting_coa_id
29905         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29906         , p_flex_value_set_id       => l_adr_flex_value_set_id
29907         , p_adr_code                => 'FA_EXPENSE_ACCT'
29908         , p_adr_type_code           => 'S'
29909         , p_component_type          => l_component_type
29910         , p_component_code          => l_component_code
29911         , p_component_type_code     => l_component_type_code
29912         , p_component_appl_id       => l_component_appl_id
29913         , p_amb_context_code        => l_amb_context_code
29914         , p_entity_code             => 'TRANSACTIONS'
29915         , p_event_class_code        => 'ADJUSTMENTS'
29916         , p_side                    => 'NA'
29917         );
29918 
29919   END IF;
29920 
29921    l_segment := AcctDerRule_158(
29922            p_application_id           => p_application_id
29923          , p_ae_header_id             => l_ae_header_id 
29924 , p_source_3 => p_source_3
29925 , p_source_20 => p_source_20
29926          , x_transaction_coa_id       => l_adr_transaction_coa_id
29927          , x_accounting_coa_id        => l_adr_accounting_coa_id
29928          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29929          , x_flex_value_set_id        => l_adr_flex_value_set_id
29930          , x_value_type_code          => l_adr_value_type_code
29931          , x_value_combination_id     => l_adr_value_combination_id
29932          , x_value_segment_code       => l_adr_value_segment_code
29933          , p_side                     => 'NA'
29934          , p_override_seg_flag        => 'Y'
29935    );
29936 
29937    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29938 
29939       xla_ae_lines_pkg.set_segment(
29940           p_to_segment_code         => 'GL_ACCOUNT'
29941         , p_segment_value           => l_segment
29942         , p_from_segment_code       => l_adr_value_segment_code
29943         , p_from_combination_id     => l_adr_value_combination_id
29944         , p_value_type_code         => l_adr_value_type_code
29945         , p_transaction_coa_id      => l_adr_transaction_coa_id
29946         , p_accounting_coa_id       => l_adr_accounting_coa_id
29947         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29948         , p_flex_value_set_id       => l_adr_flex_value_set_id
29949         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
29950         , p_adr_type_code           => 'S'
29951         , p_component_type          => l_component_type
29952         , p_component_code          => l_component_code
29953         , p_component_type_code     => l_component_type_code
29954         , p_component_appl_id       => l_component_appl_id
29955         , p_amb_context_code        => l_amb_context_code
29956         , p_entity_code             => 'TRANSACTIONS'
29957         , p_event_class_code        => 'ADJUSTMENTS'
29958         , p_side                    => 'NA'
29959         );
29960 
29961   END IF;
29962 
29963    --
29964    --
29965    END IF;
29966    --
29967    -- Bug 4922099
29968    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
29969           (NVL(l_enc_upg_option, 'N') = 'O')
29970         ) AND
29971         (l_bflow_method_code = 'PRIOR_ENTRY')
29972       )
29973    THEN
29974       IF
29975       --
29976       1 = 2
29977       --
29978       THEN
29979       xla_accounting_err_pkg.build_message
29980                                     (p_appli_s_name            => 'XLA'
29981                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
29982                                     ,p_token_1                 => 'LINE_NUMBER'
29983                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
29984                                     ,p_token_2                 => 'LINE_TYPE_NAME'
29988                                                                             ,l_component_type_code
29985                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
29986                                                                              l_component_type
29987                                                                             ,l_component_code
29989                                                                             ,l_component_appl_id
29990                                                                             ,l_amb_context_code
29991                                                                             ,l_entity_code
29992                                                                             ,l_event_class_code
29993                                                                            )
29994                                     ,p_token_3                 => 'OWNER'
29995                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
29996                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
29997                                                                           ,p_lookup_code    => l_component_type_code
29998                                                                          )
29999                                     ,p_token_4                 => 'PRODUCT_NAME'
30000                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
30001                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
30002                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
30003                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
30004                                     ,p_ae_header_id            =>  NULL
30005                                        );
30006 
30007         IF (C_LEVEL_ERROR>= g_log_level) THEN
30008                  trace
30009                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
30010                       ,p_level    => C_LEVEL_ERROR
30011                       ,p_module   => l_log_module);
30012         END IF;
30013       END IF;
30014    END IF;
30015    --
30016    --
30017    ------------------------------------------------------------------------------------------------
30018    -- 4219869 Business Flow
30019    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
30020    -- Prior Entry.  Currently, the following code is always generated.
30021    ------------------------------------------------------------------------------------------------
30022    XLA_AE_LINES_PKG.ValidateCurrentLine;
30023 
30024    ------------------------------------------------------------------------------------
30025    -- 4219869 Business Flow
30026    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
30027    ------------------------------------------------------------------------------------
30028    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30029 
30030    ----------------------------------------------------------------------------------
30031    -- 4219869 Business Flow
30032    -- Update journal entry status -- Need to generate this within IF <condition>
30033    ----------------------------------------------------------------------------------
30034    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30035          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
30036          ,p_balance_type_code => l_balance_type_code
30037          );
30038 
30039    -------------------------------------------------------------------------------------------
30040    -- 4262811 - Generate the Accrual Reversal lines
30041    -------------------------------------------------------------------------------------------
30042    BEGIN
30043       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
30044                               (g_array_event(p_event_id).array_value_num('header_index'));
30045       IF l_acc_rev_flag IS NULL THEN
30046          l_acc_rev_flag := 'N';
30047       END IF;
30048    EXCEPTION
30049       WHEN OTHERS THEN
30050          l_acc_rev_flag := 'N';
30051    END;
30052    --
30053    IF (l_acc_rev_flag = 'Y') THEN
30054 
30055        -- 4645092  ------------------------------------------------------------------------------
30056        -- To allow MPA report to determine if it should generate report process
30057        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
30058        ------------------------------------------------------------------------------------------
30059 
30060        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
30061        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
30062    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
30063    -- call ADRs
30064    -- Bug 4922099
30065    --
30066    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30067         (NVL(l_actual_upg_option, 'N') = 'O') OR
30068         (NVL(l_enc_upg_option, 'N') = 'O')
30069       )
30070    THEN
30071    NULL;
30072    --
30073    --
30074    
30075   l_ccid := AcctDerRule_173(
30076            p_application_id           => p_application_id
30077          , p_ae_header_id             => l_ae_header_id 
30078 , p_source_3 => p_source_3
30079 , p_source_30 => p_source_30
30080          , x_transaction_coa_id       => l_adr_transaction_coa_id
30081          , x_accounting_coa_id        => l_adr_accounting_coa_id
30082          , x_value_type_code          => l_adr_value_type_code
30083          , p_side                     => 'NA'
30084    );
30085 
30086    xla_ae_lines_pkg.set_ccid(
30087     p_code_combination_id          => l_ccid
30088   , p_value_type_code              => l_adr_value_type_code
30089   , p_transaction_coa_id           => l_adr_transaction_coa_id
30093   , p_component_type               => l_component_type
30090   , p_accounting_coa_id            => l_adr_accounting_coa_id
30091   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
30092   , p_adr_type_code                => 'S'
30094   , p_component_code               => l_component_code
30095   , p_component_type_code          => l_component_type_code
30096   , p_component_appl_id            => l_component_appl_id
30097   , p_amb_context_code             => l_amb_context_code
30098   , p_side                         => 'NA'
30099   );
30100 
30101 
30102    l_segment := AcctDerRule_168(
30103            p_application_id           => p_application_id
30104          , p_ae_header_id             => l_ae_header_id 
30105 , p_source_3 => p_source_3
30106 , p_source_29 => p_source_29
30107          , x_transaction_coa_id       => l_adr_transaction_coa_id
30108          , x_accounting_coa_id        => l_adr_accounting_coa_id
30109          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30110          , x_flex_value_set_id        => l_adr_flex_value_set_id
30111          , x_value_type_code          => l_adr_value_type_code
30112          , x_value_combination_id     => l_adr_value_combination_id
30113          , x_value_segment_code       => l_adr_value_segment_code
30114          , p_side                     => 'NA'
30115          , p_override_seg_flag        => 'Y'
30116    );
30117 
30118    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30119 
30120       xla_ae_lines_pkg.set_segment(
30121           p_to_segment_code         => 'GL_BALANCING'
30122         , p_segment_value           => l_segment
30123         , p_from_segment_code       => l_adr_value_segment_code
30124         , p_from_combination_id     => l_adr_value_combination_id
30125         , p_value_type_code         => l_adr_value_type_code
30126         , p_transaction_coa_id      => l_adr_transaction_coa_id
30127         , p_accounting_coa_id       => l_adr_accounting_coa_id
30128         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30129         , p_flex_value_set_id       => l_adr_flex_value_set_id
30130         , p_adr_code                => 'FA_EXPENSE_ACCT'
30131         , p_adr_type_code           => 'S'
30132         , p_component_type          => l_component_type
30133         , p_component_code          => l_component_code
30134         , p_component_type_code     => l_component_type_code
30135         , p_component_appl_id       => l_component_appl_id
30136         , p_amb_context_code        => l_amb_context_code
30137         , p_entity_code             => 'TRANSACTIONS'
30138         , p_event_class_code        => 'ADJUSTMENTS'
30139         , p_side                    => 'NA'
30140         );
30141 
30142   END IF;
30143 
30144    l_segment := AcctDerRule_158(
30145            p_application_id           => p_application_id
30146          , p_ae_header_id             => l_ae_header_id 
30147 , p_source_3 => p_source_3
30148 , p_source_20 => p_source_20
30149          , x_transaction_coa_id       => l_adr_transaction_coa_id
30150          , x_accounting_coa_id        => l_adr_accounting_coa_id
30151          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30152          , x_flex_value_set_id        => l_adr_flex_value_set_id
30153          , x_value_type_code          => l_adr_value_type_code
30154          , x_value_combination_id     => l_adr_value_combination_id
30155          , x_value_segment_code       => l_adr_value_segment_code
30156          , p_side                     => 'NA'
30157          , p_override_seg_flag        => 'Y'
30158    );
30159 
30160    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30161 
30162       xla_ae_lines_pkg.set_segment(
30163           p_to_segment_code         => 'GL_ACCOUNT'
30164         , p_segment_value           => l_segment
30165         , p_from_segment_code       => l_adr_value_segment_code
30166         , p_from_combination_id     => l_adr_value_combination_id
30167         , p_value_type_code         => l_adr_value_type_code
30168         , p_transaction_coa_id      => l_adr_transaction_coa_id
30169         , p_accounting_coa_id       => l_adr_accounting_coa_id
30170         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30171         , p_flex_value_set_id       => l_adr_flex_value_set_id
30172         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
30173         , p_adr_type_code           => 'S'
30174         , p_component_type          => l_component_type
30175         , p_component_code          => l_component_code
30176         , p_component_type_code     => l_component_type_code
30177         , p_component_appl_id       => l_component_appl_id
30178         , p_amb_context_code        => l_amb_context_code
30179         , p_entity_code             => 'TRANSACTIONS'
30180         , p_event_class_code        => 'ADJUSTMENTS'
30181         , p_side                    => 'NA'
30182         );
30183 
30184   END IF;
30185 
30186    --
30187    --
30188    END IF;
30189 
30190        --
30191        -- Update the line information that should be overwritten
30192        --
30193        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
30194                                          p_header_num   => 1);
30195        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
30196 
30197        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
30198 
30199        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
30200           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
30201        END IF;
30202 
30203       --
30204       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
30205       --
30206       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
30210           -- 4262811a Switch Sign
30207           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
30208       ELSE
30209           ---------------------------------------------------------------------------------------------------
30211           ---------------------------------------------------------------------------------------------------
30212           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
30213           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30214                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30215           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30216                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30217           -- 5132302
30218           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
30219                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30220 
30221       END IF;
30222 
30223       -- 4955764
30224       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30225       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
30226 
30227 
30228       XLA_AE_LINES_PKG.ValidateCurrentLine;
30229       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30230 
30231       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30232                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
30233                ,p_balance_type_code => l_balance_type_code);
30234 
30235    END IF;
30236 
30237    -----------------------------------------------------------------------------------------
30238    -- 4262811 Multiperiod Accounting
30239    -----------------------------------------------------------------------------------------
30240      -- No MPA option is assigned.
30241 
30242 
30243 END IF;
30244 END IF;
30245 --
30246 
30247 --
30248 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
30249    trace
30250       (p_msg      => 'END of AcctLineType_196'
30251       ,p_level    => C_LEVEL_PROCEDURE
30252       ,p_module   => l_log_module);
30253 END IF;
30254 --
30255 EXCEPTION
30256   WHEN xla_exceptions_pkg.application_exception THEN
30257       RAISE;
30258   WHEN OTHERS THEN
30259        xla_exceptions_pkg.raise_message
30260            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_196');
30261 END AcctLineType_196;
30262 --
30263 
30264 ---------------------------------------
30265 --
30266 -- PRIVATE FUNCTION
30267 --         AcctLineType_197
30268 --
30269 ---------------------------------------
30270 PROCEDURE AcctLineType_197 (
30271   p_application_id        IN NUMBER
30272  ,p_event_id              IN NUMBER
30273  ,p_calculate_acctd_flag  IN VARCHAR2
30274  ,p_calculate_g_l_flag    IN VARCHAR2
30275  ,p_actual_flag           IN OUT VARCHAR2
30276  ,p_balance_type_code     OUT VARCHAR2
30277  ,p_gain_or_loss_ref      OUT VARCHAR2
30278  
30279 --Period Close Date
30280  , p_source_1            IN DATE
30281 --Generated Code Combination Identifier
30282  , p_source_3            IN NUMBER
30283 --Depreciation Reserve Account
30284  , p_source_10            IN VARCHAR2
30285 --Generated Offset Code Combination Identifier
30286  , p_source_17            IN NUMBER
30287 --Expense Account Code Combination Identifier
30288  , p_source_29            IN NUMBER
30289 --Default Code Combination Identifier
30290  , p_source_30            IN NUMBER
30291 --Adjustment Type
30292  , p_source_35            IN VARCHAR2
30293 --Transaction Header Identifier
30294  , p_source_36            IN NUMBER
30295 --Adjustment Line Identifier
30296  , p_source_37            IN NUMBER
30297 --Distribution Type Code
30298  , p_source_38            IN VARCHAR2
30299 --Entered Amount
30300  , p_source_39            IN NUMBER
30301 --Currency Code
30302  , p_source_40            IN VARCHAR2
30303 )
30304 IS
30305 
30306 l_component_type              VARCHAR2(80);
30307 l_component_code              VARCHAR2(30);
30308 l_component_type_code         VARCHAR2(1);
30309 l_component_appl_id           INTEGER;
30310 l_amb_context_code            VARCHAR2(30);
30311 l_entity_code                 VARCHAR2(30);
30312 l_event_class_code            VARCHAR2(30);
30313 l_ae_header_id                NUMBER;
30314 l_event_type_code             VARCHAR2(30);
30315 l_line_definition_code        VARCHAR2(30);
30316 l_line_definition_owner_code  VARCHAR2(1);
30317 --
30318 -- adr variables
30319 l_segment                     VARCHAR2(30);
30320 l_ccid                        NUMBER;
30321 l_adr_transaction_coa_id      NUMBER;
30322 l_adr_accounting_coa_id       NUMBER;
30323 l_adr_flexfield_segment_code  VARCHAR2(30);
30324 l_adr_flex_value_set_id       NUMBER;
30325 l_adr_value_type_code         VARCHAR2(30);
30326 l_adr_value_combination_id    NUMBER;
30327 l_adr_value_segment_code      VARCHAR2(30);
30328 
30329 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
30330 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
30331 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
30332 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
30333 
30334 -- 4262811 Variables ------------------------------------------------------------------------------------------
30335 l_entered_amt_idx             NUMBER;
30336 l_accted_amt_idx              NUMBER;
30337 l_acc_rev_flag                VARCHAR2(1);
30338 l_accrual_line_num            NUMBER;
30339 l_tmp_amt                     NUMBER;
30340 l_acc_rev_natural_side_code   VARCHAR2(1);
30344 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
30341 
30342 l_num_entries                 NUMBER;
30343 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
30345 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
30346 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
30347 l_recog_line_1                NUMBER;
30348 l_recog_line_2                NUMBER;
30349 
30350 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
30351 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
30352 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
30353 
30354 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
30355 
30356 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
30357 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
30358 
30359 ---------------------------------------------------------------------------------------------------------------
30360 
30361 
30362 --
30363 -- bulk performance
30364 --
30365 l_balance_type_code           VARCHAR2(1);
30366 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
30367 l_log_module                  VARCHAR2(240);
30368 
30369 --
30370 -- Upgrade strategy
30371 --
30372 l_actual_upg_option           VARCHAR2(1);
30373 l_enc_upg_option           VARCHAR2(1);
30374 
30375 --
30376 BEGIN
30377 --
30378 IF g_log_enabled THEN
30379       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_197';
30380 END IF;
30381 --
30382 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
30383 
30384       trace
30385          (p_msg      => 'BEGIN of AcctLineType_197'
30386          ,p_level    => C_LEVEL_PROCEDURE
30387          ,p_module   => l_log_module);
30388 
30389 END IF;
30390 --
30391 l_component_type             := 'AMB_JLT';
30392 l_component_code             := 'FA_ADJ_RESERVE';
30393 l_component_type_code        := 'S';
30394 l_component_appl_id          :=  140;
30395 l_amb_context_code           := 'DEFAULT';
30396 l_entity_code                := 'TRANSACTIONS';
30397 l_event_class_code           := 'ADJUSTMENTS';
30398 l_event_type_code            := 'ADJUSTMENTS_ALL';
30399 l_line_definition_owner_code := 'S';
30400 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
30401 --
30402 l_balance_type_code          := 'A';
30403 l_segment                     := NULL;
30404 l_ccid                        := NULL;
30405 l_adr_transaction_coa_id      := NULL;
30406 l_adr_accounting_coa_id       := NULL;
30407 l_adr_flexfield_segment_code  := NULL;
30408 l_adr_flex_value_set_id       := NULL;
30409 l_adr_value_type_code         := NULL;
30410 l_adr_value_combination_id    := NULL;
30411 l_adr_value_segment_code      := NULL;
30412 
30413 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
30414 l_bflow_class_code           := '';    -- 4219869 Business Flow
30415 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
30416 l_budgetary_control_flag     := 'N';
30417 
30418 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
30419 l_bflow_applied_to_amt       := NULL; -- 5132302
30420 l_entered_amt_idx            := NULL;          -- 4262811
30421 l_accted_amt_idx             := NULL;          -- 4262811
30422 l_acc_rev_flag               := NULL;          -- 4262811
30423 l_accrual_line_num           := NULL;          -- 4262811
30424 l_tmp_amt                    := NULL;          -- 4262811
30425 --
30426  
30427 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
30428     l_balance_type_code <> 'B' THEN
30429 IF (NVL(p_source_35,'
30430 ') =  'EXPENSE' OR 
30431 NVL(p_source_35,'
30432 ') =  'RESERVE')
30433  THEN 
30434 
30435    --
30436    XLA_AE_LINES_PKG.SetNewLine;
30437 
30438    p_balance_type_code          := l_balance_type_code;
30439    -- set the flag so later we will know whether the gain loss line needs to be created
30440    
30441    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
30442      p_actual_flag :='A';
30443    END IF;
30444 
30445    --
30446    -- bulk performance
30447    --
30448    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
30449                                       p_header_num   => 0); -- 4262811
30450    --
30451    -- set accounting line options
30452    --
30453    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
30454            p_natural_side_code          => 'C'
30455          , p_gain_or_loss_flag          => 'N'
30456          , p_gl_transfer_mode_code      => 'S'
30457          , p_acct_entry_type_code       => 'A'
30458          , p_switch_side_flag           => 'Y'
30459          , p_merge_duplicate_code       => 'N'
30460          );
30461    --
30462    l_acc_rev_natural_side_code := 'D';  -- 4262811
30463    -- 
30464    --
30465    -- set accounting line type info
30466    --
30467    xla_ae_lines_pkg.SetAcctLineType
30468       (p_component_type             => l_component_type
30469       ,p_event_type_code            => l_event_type_code
30470       ,p_line_definition_owner_code => l_line_definition_owner_code
30471       ,p_line_definition_code       => l_line_definition_code
30472       ,p_accounting_line_code       => l_component_code
30473       ,p_accounting_line_type_code  => l_component_type_code
30474       ,p_accounting_line_appl_id    => l_component_appl_id
30475       ,p_amb_context_code           => l_amb_context_code
30476       ,p_entity_code                => l_entity_code
30477       ,p_event_class_code           => l_event_class_code);
30478    --
30479    -- set accounting class
30480    --
30481    xla_ae_lines_pkg.SetAcctClass(
30485 
30482            p_accounting_class_code  => 'ASSET'
30483          , p_ae_header_id           => l_ae_header_id
30484          );
30486    --
30487    -- set rounding class
30488    --
30489    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
30490                       'ASSET';
30491 
30492    --
30493    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
30494    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
30495    --
30496    -- bulk performance
30497    --
30498    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
30499 
30500    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
30501       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
30502 
30503    -- 4955764
30504    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30505       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
30506 
30507    -- 4458381 Public Sector Enh
30508    
30509    --
30510    -- set accounting attributes for the line type
30511    --
30512    l_entered_amt_idx := 4;
30513    l_accted_amt_idx  := 6;
30514    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
30515    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
30516    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
30517    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
30518    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
30519    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
30520    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
30521    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
30522    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
30523    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
30524    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
30525    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
30526    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
30527 
30528    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
30529    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
30530 
30531    ---------------------------------------------------------------------------------------------------------------
30532    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
30533    ---------------------------------------------------------------------------------------------------------------
30534    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
30535 
30536    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30537    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30538 
30539    IF xla_accounting_cache_pkg.GetValueChar
30540          (p_source_code         => 'LEDGER_CATEGORY_CODE'
30541          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
30542    AND l_bflow_method_code = 'PRIOR_ENTRY'
30543 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
30544    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
30545          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
30546        )
30547    THEN
30548          xla_ae_lines_pkg.BflowUpgEntry
30549            (p_business_method_code    => l_bflow_method_code
30550            ,p_business_class_code     => l_bflow_class_code
30551            ,p_balance_type            => l_balance_type_code);
30552    ELSE
30553       NULL;
30554 -- No business flow processing for business flow method of NONE.
30555    END IF;
30556 
30557    --
30558    -- call analytical criteria
30559    --
30560    
30561    --
30562    -- call description
30563    --
30564    
30565 xla_ae_lines_pkg.SetLineDescription(
30566    p_ae_header_id => l_ae_header_id
30567   ,p_description  => Description_15 (
30568      p_application_id         => p_application_id
30569    , p_ae_header_id           => l_ae_header_id 
30570 , p_source_1 => p_source_1
30571    )
30572 );
30573 
30574 
30575    --
30576    -- call ADRs
30577    -- Bug 4922099
30578    --
30579    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30580         (NVL(l_actual_upg_option, 'N') = 'O') OR
30581         (NVL(l_enc_upg_option, 'N') = 'O')
30582       )
30583    THEN
30584    NULL;
30585    --
30586    --
30587    
30588   l_ccid := AcctDerRule_174(
30589            p_application_id           => p_application_id
30590          , p_ae_header_id             => l_ae_header_id 
30591 , p_source_3 => p_source_3
30592 , p_source_17 => p_source_17
30593 , p_source_30 => p_source_30
30594          , x_transaction_coa_id       => l_adr_transaction_coa_id
30595          , x_accounting_coa_id        => l_adr_accounting_coa_id
30596          , x_value_type_code          => l_adr_value_type_code
30597          , p_side                     => 'NA'
30598    );
30599 
30600    xla_ae_lines_pkg.set_ccid(
30601     p_code_combination_id          => l_ccid
30602   , p_value_type_code              => l_adr_value_type_code
30603   , p_transaction_coa_id           => l_adr_transaction_coa_id
30604   , p_accounting_coa_id            => l_adr_accounting_coa_id
30605   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
30606   , p_adr_type_code                => 'S'
30607   , p_component_type               => l_component_type
30608   , p_component_code               => l_component_code
30609   , p_component_type_code          => l_component_type_code
30613   );
30610   , p_component_appl_id            => l_component_appl_id
30611   , p_amb_context_code             => l_amb_context_code
30612   , p_side                         => 'NA'
30614 
30615 
30616    l_segment := AcctDerRule_149(
30617            p_application_id           => p_application_id
30618          , p_ae_header_id             => l_ae_header_id 
30619 , p_source_3 => p_source_3
30620 , p_source_10 => p_source_10
30621          , x_transaction_coa_id       => l_adr_transaction_coa_id
30622          , x_accounting_coa_id        => l_adr_accounting_coa_id
30623          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30624          , x_flex_value_set_id        => l_adr_flex_value_set_id
30625          , x_value_type_code          => l_adr_value_type_code
30626          , x_value_combination_id     => l_adr_value_combination_id
30627          , x_value_segment_code       => l_adr_value_segment_code
30628          , p_side                     => 'NA'
30629          , p_override_seg_flag        => 'Y'
30630    );
30631 
30632    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30633 
30634       xla_ae_lines_pkg.set_segment(
30635           p_to_segment_code         => 'GL_ACCOUNT'
30636         , p_segment_value           => l_segment
30637         , p_from_segment_code       => l_adr_value_segment_code
30638         , p_from_combination_id     => l_adr_value_combination_id
30639         , p_value_type_code         => l_adr_value_type_code
30640         , p_transaction_coa_id      => l_adr_transaction_coa_id
30641         , p_accounting_coa_id       => l_adr_accounting_coa_id
30642         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30643         , p_flex_value_set_id       => l_adr_flex_value_set_id
30644         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
30645         , p_adr_type_code           => 'S'
30646         , p_component_type          => l_component_type
30647         , p_component_code          => l_component_code
30648         , p_component_type_code     => l_component_type_code
30649         , p_component_appl_id       => l_component_appl_id
30650         , p_amb_context_code        => l_amb_context_code
30651         , p_entity_code             => 'TRANSACTIONS'
30652         , p_event_class_code        => 'ADJUSTMENTS'
30653         , p_side                    => 'NA'
30654         );
30655 
30656   END IF;
30657 
30658    l_segment := AcctDerRule_168(
30659            p_application_id           => p_application_id
30660          , p_ae_header_id             => l_ae_header_id 
30661 , p_source_3 => p_source_3
30662 , p_source_29 => p_source_29
30663          , x_transaction_coa_id       => l_adr_transaction_coa_id
30664          , x_accounting_coa_id        => l_adr_accounting_coa_id
30665          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30666          , x_flex_value_set_id        => l_adr_flex_value_set_id
30667          , x_value_type_code          => l_adr_value_type_code
30668          , x_value_combination_id     => l_adr_value_combination_id
30669          , x_value_segment_code       => l_adr_value_segment_code
30670          , p_side                     => 'NA'
30671          , p_override_seg_flag        => 'Y'
30672    );
30673 
30674    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30675 
30676       xla_ae_lines_pkg.set_segment(
30677           p_to_segment_code         => 'GL_BALANCING'
30678         , p_segment_value           => l_segment
30679         , p_from_segment_code       => l_adr_value_segment_code
30680         , p_from_combination_id     => l_adr_value_combination_id
30681         , p_value_type_code         => l_adr_value_type_code
30682         , p_transaction_coa_id      => l_adr_transaction_coa_id
30683         , p_accounting_coa_id       => l_adr_accounting_coa_id
30684         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30685         , p_flex_value_set_id       => l_adr_flex_value_set_id
30686         , p_adr_code                => 'FA_EXPENSE_ACCT'
30687         , p_adr_type_code           => 'S'
30688         , p_component_type          => l_component_type
30689         , p_component_code          => l_component_code
30690         , p_component_type_code     => l_component_type_code
30691         , p_component_appl_id       => l_component_appl_id
30692         , p_amb_context_code        => l_amb_context_code
30693         , p_entity_code             => 'TRANSACTIONS'
30694         , p_event_class_code        => 'ADJUSTMENTS'
30695         , p_side                    => 'NA'
30696         );
30697 
30698   END IF;
30699 
30700    --
30701    --
30702    END IF;
30703    --
30704    -- Bug 4922099
30705    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
30706           (NVL(l_enc_upg_option, 'N') = 'O')
30707         ) AND
30708         (l_bflow_method_code = 'PRIOR_ENTRY')
30709       )
30710    THEN
30711       IF
30712       --
30713       1 = 2
30714       --
30715       THEN
30716       xla_accounting_err_pkg.build_message
30717                                     (p_appli_s_name            => 'XLA'
30718                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
30719                                     ,p_token_1                 => 'LINE_NUMBER'
30720                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
30721                                     ,p_token_2                 => 'LINE_TYPE_NAME'
30722                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
30723                                                                              l_component_type
30724                                                                             ,l_component_code
30725                                                                             ,l_component_type_code
30726                                                                             ,l_component_appl_id
30730                                                                            )
30727                                                                             ,l_amb_context_code
30728                                                                             ,l_entity_code
30729                                                                             ,l_event_class_code
30731                                     ,p_token_3                 => 'OWNER'
30732                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
30733                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
30734                                                                           ,p_lookup_code    => l_component_type_code
30735                                                                          )
30736                                     ,p_token_4                 => 'PRODUCT_NAME'
30737                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
30738                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
30739                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
30740                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
30741                                     ,p_ae_header_id            =>  NULL
30742                                        );
30743 
30744         IF (C_LEVEL_ERROR>= g_log_level) THEN
30745                  trace
30746                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
30747                       ,p_level    => C_LEVEL_ERROR
30748                       ,p_module   => l_log_module);
30749         END IF;
30750       END IF;
30751    END IF;
30752    --
30753    --
30754    ------------------------------------------------------------------------------------------------
30755    -- 4219869 Business Flow
30756    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
30757    -- Prior Entry.  Currently, the following code is always generated.
30758    ------------------------------------------------------------------------------------------------
30759    XLA_AE_LINES_PKG.ValidateCurrentLine;
30760 
30761    ------------------------------------------------------------------------------------
30762    -- 4219869 Business Flow
30763    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
30764    ------------------------------------------------------------------------------------
30765    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30766 
30767    ----------------------------------------------------------------------------------
30768    -- 4219869 Business Flow
30769    -- Update journal entry status -- Need to generate this within IF <condition>
30770    ----------------------------------------------------------------------------------
30771    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30772          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
30773          ,p_balance_type_code => l_balance_type_code
30774          );
30775 
30776    -------------------------------------------------------------------------------------------
30777    -- 4262811 - Generate the Accrual Reversal lines
30778    -------------------------------------------------------------------------------------------
30779    BEGIN
30780       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
30781                               (g_array_event(p_event_id).array_value_num('header_index'));
30782       IF l_acc_rev_flag IS NULL THEN
30783          l_acc_rev_flag := 'N';
30784       END IF;
30785    EXCEPTION
30786       WHEN OTHERS THEN
30787          l_acc_rev_flag := 'N';
30788    END;
30789    --
30790    IF (l_acc_rev_flag = 'Y') THEN
30791 
30792        -- 4645092  ------------------------------------------------------------------------------
30793        -- To allow MPA report to determine if it should generate report process
30794        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
30795        ------------------------------------------------------------------------------------------
30796 
30797        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
30798        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
30799    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
30800    -- call ADRs
30801    -- Bug 4922099
30802    --
30803    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30804         (NVL(l_actual_upg_option, 'N') = 'O') OR
30805         (NVL(l_enc_upg_option, 'N') = 'O')
30806       )
30807    THEN
30808    NULL;
30809    --
30810    --
30811    
30812   l_ccid := AcctDerRule_174(
30813            p_application_id           => p_application_id
30814          , p_ae_header_id             => l_ae_header_id 
30815 , p_source_3 => p_source_3
30816 , p_source_17 => p_source_17
30817 , p_source_30 => p_source_30
30818          , x_transaction_coa_id       => l_adr_transaction_coa_id
30819          , x_accounting_coa_id        => l_adr_accounting_coa_id
30820          , x_value_type_code          => l_adr_value_type_code
30821          , p_side                     => 'NA'
30822    );
30823 
30824    xla_ae_lines_pkg.set_ccid(
30825     p_code_combination_id          => l_ccid
30826   , p_value_type_code              => l_adr_value_type_code
30827   , p_transaction_coa_id           => l_adr_transaction_coa_id
30828   , p_accounting_coa_id            => l_adr_accounting_coa_id
30829   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
30830   , p_adr_type_code                => 'S'
30831   , p_component_type               => l_component_type
30832   , p_component_code               => l_component_code
30833   , p_component_type_code          => l_component_type_code
30834   , p_component_appl_id            => l_component_appl_id
30838 
30835   , p_amb_context_code             => l_amb_context_code
30836   , p_side                         => 'NA'
30837   );
30839 
30840    l_segment := AcctDerRule_149(
30841            p_application_id           => p_application_id
30842          , p_ae_header_id             => l_ae_header_id 
30843 , p_source_3 => p_source_3
30844 , p_source_10 => p_source_10
30845          , x_transaction_coa_id       => l_adr_transaction_coa_id
30846          , x_accounting_coa_id        => l_adr_accounting_coa_id
30847          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30848          , x_flex_value_set_id        => l_adr_flex_value_set_id
30849          , x_value_type_code          => l_adr_value_type_code
30850          , x_value_combination_id     => l_adr_value_combination_id
30851          , x_value_segment_code       => l_adr_value_segment_code
30852          , p_side                     => 'NA'
30853          , p_override_seg_flag        => 'Y'
30854    );
30855 
30856    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30857 
30858       xla_ae_lines_pkg.set_segment(
30859           p_to_segment_code         => 'GL_ACCOUNT'
30860         , p_segment_value           => l_segment
30861         , p_from_segment_code       => l_adr_value_segment_code
30862         , p_from_combination_id     => l_adr_value_combination_id
30863         , p_value_type_code         => l_adr_value_type_code
30864         , p_transaction_coa_id      => l_adr_transaction_coa_id
30865         , p_accounting_coa_id       => l_adr_accounting_coa_id
30866         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30867         , p_flex_value_set_id       => l_adr_flex_value_set_id
30868         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
30869         , p_adr_type_code           => 'S'
30870         , p_component_type          => l_component_type
30871         , p_component_code          => l_component_code
30872         , p_component_type_code     => l_component_type_code
30873         , p_component_appl_id       => l_component_appl_id
30874         , p_amb_context_code        => l_amb_context_code
30875         , p_entity_code             => 'TRANSACTIONS'
30876         , p_event_class_code        => 'ADJUSTMENTS'
30877         , p_side                    => 'NA'
30878         );
30879 
30880   END IF;
30881 
30882    l_segment := AcctDerRule_168(
30883            p_application_id           => p_application_id
30884          , p_ae_header_id             => l_ae_header_id 
30885 , p_source_3 => p_source_3
30886 , p_source_29 => p_source_29
30887          , x_transaction_coa_id       => l_adr_transaction_coa_id
30888          , x_accounting_coa_id        => l_adr_accounting_coa_id
30889          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30890          , x_flex_value_set_id        => l_adr_flex_value_set_id
30891          , x_value_type_code          => l_adr_value_type_code
30892          , x_value_combination_id     => l_adr_value_combination_id
30893          , x_value_segment_code       => l_adr_value_segment_code
30894          , p_side                     => 'NA'
30895          , p_override_seg_flag        => 'Y'
30896    );
30897 
30898    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30899 
30900       xla_ae_lines_pkg.set_segment(
30901           p_to_segment_code         => 'GL_BALANCING'
30902         , p_segment_value           => l_segment
30903         , p_from_segment_code       => l_adr_value_segment_code
30904         , p_from_combination_id     => l_adr_value_combination_id
30905         , p_value_type_code         => l_adr_value_type_code
30906         , p_transaction_coa_id      => l_adr_transaction_coa_id
30907         , p_accounting_coa_id       => l_adr_accounting_coa_id
30908         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30909         , p_flex_value_set_id       => l_adr_flex_value_set_id
30910         , p_adr_code                => 'FA_EXPENSE_ACCT'
30911         , p_adr_type_code           => 'S'
30912         , p_component_type          => l_component_type
30913         , p_component_code          => l_component_code
30914         , p_component_type_code     => l_component_type_code
30915         , p_component_appl_id       => l_component_appl_id
30916         , p_amb_context_code        => l_amb_context_code
30917         , p_entity_code             => 'TRANSACTIONS'
30918         , p_event_class_code        => 'ADJUSTMENTS'
30919         , p_side                    => 'NA'
30920         );
30921 
30922   END IF;
30923 
30924    --
30925    --
30926    END IF;
30927 
30928        --
30929        -- Update the line information that should be overwritten
30930        --
30931        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
30932                                          p_header_num   => 1);
30933        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
30934 
30935        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
30936 
30937        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
30938           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
30939        END IF;
30940 
30941       --
30942       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
30943       --
30944       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
30945           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
30946       ELSE
30947           ---------------------------------------------------------------------------------------------------
30948           -- 4262811a Switch Sign
30949           ---------------------------------------------------------------------------------------------------
30953           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30950           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
30951           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30952                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30954                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30955           -- 5132302
30956           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
30957                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30958 
30959       END IF;
30960 
30961       -- 4955764
30962       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30963       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
30964 
30965 
30966       XLA_AE_LINES_PKG.ValidateCurrentLine;
30967       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30968 
30969       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30970                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
30971                ,p_balance_type_code => l_balance_type_code);
30972 
30973    END IF;
30974 
30975    -----------------------------------------------------------------------------------------
30976    -- 4262811 Multiperiod Accounting
30977    -----------------------------------------------------------------------------------------
30978      -- No MPA option is assigned.
30979 
30980 
30981 END IF;
30982 END IF;
30983 --
30984 
30985 --
30986 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
30987    trace
30988       (p_msg      => 'END of AcctLineType_197'
30989       ,p_level    => C_LEVEL_PROCEDURE
30990       ,p_module   => l_log_module);
30991 END IF;
30992 --
30993 EXCEPTION
30994   WHEN xla_exceptions_pkg.application_exception THEN
30995       RAISE;
30996   WHEN OTHERS THEN
30997        xla_exceptions_pkg.raise_message
30998            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_197');
30999 END AcctLineType_197;
31000 --
31001 
31002 ---------------------------------------
31003 --
31004 -- PRIVATE FUNCTION
31005 --         AcctLineType_198
31006 --
31007 ---------------------------------------
31008 PROCEDURE AcctLineType_198 (
31009   p_application_id        IN NUMBER
31010  ,p_event_id              IN NUMBER
31011  ,p_calculate_acctd_flag  IN VARCHAR2
31012  ,p_calculate_g_l_flag    IN VARCHAR2
31013  ,p_actual_flag           IN OUT VARCHAR2
31014  ,p_balance_type_code     OUT VARCHAR2
31015  ,p_gain_or_loss_ref      OUT VARCHAR2
31016  
31017 --Period Close Date
31018  , p_source_1            IN DATE
31019 --Generated Code Combination Identifier
31020  , p_source_3            IN NUMBER
31021 --Depreciation Reserve Account
31022  , p_source_10            IN VARCHAR2
31023 --Generated Offset Code Combination Identifier
31024  , p_source_17            IN NUMBER
31025 --Expense Account Code Combination Identifier
31026  , p_source_29            IN NUMBER
31027 --Default Code Combination Identifier
31028  , p_source_30            IN NUMBER
31029 --Adjustment Type
31030  , p_source_35            IN VARCHAR2
31031 --Transaction Header Identifier
31032  , p_source_36            IN NUMBER
31033 --Adjustment Line Identifier
31034  , p_source_37            IN NUMBER
31035 --Distribution Type Code
31036  , p_source_38            IN VARCHAR2
31037 --Entered Amount
31038  , p_source_39            IN NUMBER
31039 --Currency Code
31040  , p_source_40            IN VARCHAR2
31041 )
31042 IS
31043 
31044 l_component_type              VARCHAR2(80);
31045 l_component_code              VARCHAR2(30);
31046 l_component_type_code         VARCHAR2(1);
31047 l_component_appl_id           INTEGER;
31048 l_amb_context_code            VARCHAR2(30);
31049 l_entity_code                 VARCHAR2(30);
31050 l_event_class_code            VARCHAR2(30);
31051 l_ae_header_id                NUMBER;
31052 l_event_type_code             VARCHAR2(30);
31053 l_line_definition_code        VARCHAR2(30);
31054 l_line_definition_owner_code  VARCHAR2(1);
31055 --
31056 -- adr variables
31057 l_segment                     VARCHAR2(30);
31058 l_ccid                        NUMBER;
31059 l_adr_transaction_coa_id      NUMBER;
31060 l_adr_accounting_coa_id       NUMBER;
31061 l_adr_flexfield_segment_code  VARCHAR2(30);
31062 l_adr_flex_value_set_id       NUMBER;
31063 l_adr_value_type_code         VARCHAR2(30);
31064 l_adr_value_combination_id    NUMBER;
31065 l_adr_value_segment_code      VARCHAR2(30);
31066 
31067 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
31068 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
31069 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
31070 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
31071 
31072 -- 4262811 Variables ------------------------------------------------------------------------------------------
31073 l_entered_amt_idx             NUMBER;
31074 l_accted_amt_idx              NUMBER;
31075 l_acc_rev_flag                VARCHAR2(1);
31076 l_accrual_line_num            NUMBER;
31077 l_tmp_amt                     NUMBER;
31078 l_acc_rev_natural_side_code   VARCHAR2(1);
31079 
31080 l_num_entries                 NUMBER;
31081 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
31082 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
31083 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
31084 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
31085 l_recog_line_1                NUMBER;
31089 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
31086 l_recog_line_2                NUMBER;
31087 
31088 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
31090 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
31091 
31092 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
31093 
31094 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
31095 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
31096 
31097 ---------------------------------------------------------------------------------------------------------------
31098 
31099 
31100 --
31101 -- bulk performance
31102 --
31103 l_balance_type_code           VARCHAR2(1);
31104 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
31105 l_log_module                  VARCHAR2(240);
31106 
31107 --
31108 -- Upgrade strategy
31109 --
31110 l_actual_upg_option           VARCHAR2(1);
31111 l_enc_upg_option           VARCHAR2(1);
31112 
31113 --
31114 BEGIN
31115 --
31116 IF g_log_enabled THEN
31117       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_198';
31118 END IF;
31119 --
31120 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
31121 
31122       trace
31123          (p_msg      => 'BEGIN of AcctLineType_198'
31124          ,p_level    => C_LEVEL_PROCEDURE
31125          ,p_module   => l_log_module);
31126 
31127 END IF;
31128 --
31129 l_component_type             := 'AMB_JLT';
31130 l_component_code             := 'FA_ADJ_RESERVE_BAL';
31131 l_component_type_code        := 'S';
31132 l_component_appl_id          :=  140;
31133 l_amb_context_code           := 'DEFAULT';
31134 l_entity_code                := 'TRANSACTIONS';
31135 l_event_class_code           := 'ADJUSTMENTS';
31136 l_event_type_code            := 'ADJUSTMENTS_ALL';
31137 l_line_definition_owner_code := 'S';
31138 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_ADJUST2';
31139 --
31140 l_balance_type_code          := 'A';
31141 l_segment                     := NULL;
31142 l_ccid                        := NULL;
31143 l_adr_transaction_coa_id      := NULL;
31144 l_adr_accounting_coa_id       := NULL;
31145 l_adr_flexfield_segment_code  := NULL;
31146 l_adr_flex_value_set_id       := NULL;
31147 l_adr_value_type_code         := NULL;
31148 l_adr_value_combination_id    := NULL;
31149 l_adr_value_segment_code      := NULL;
31150 
31151 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
31152 l_bflow_class_code           := '';    -- 4219869 Business Flow
31153 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
31154 l_budgetary_control_flag     := 'N';
31155 
31156 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
31157 l_bflow_applied_to_amt       := NULL; -- 5132302
31158 l_entered_amt_idx            := NULL;          -- 4262811
31159 l_accted_amt_idx             := NULL;          -- 4262811
31160 l_acc_rev_flag               := NULL;          -- 4262811
31161 l_accrual_line_num           := NULL;          -- 4262811
31162 l_tmp_amt                    := NULL;          -- 4262811
31163 --
31164  
31165 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
31166     l_balance_type_code <> 'B' THEN
31167 IF NVL(p_source_35,'
31168 ') =  'BONUS EXPENSE'
31169  THEN 
31170 
31171    --
31172    XLA_AE_LINES_PKG.SetNewLine;
31173 
31174    p_balance_type_code          := l_balance_type_code;
31175    -- set the flag so later we will know whether the gain loss line needs to be created
31176    
31177    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
31178      p_actual_flag :='A';
31179    END IF;
31180 
31181    --
31182    -- bulk performance
31183    --
31184    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
31185                                       p_header_num   => 0); -- 4262811
31186    --
31187    -- set accounting line options
31188    --
31189    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
31190            p_natural_side_code          => 'D'
31191          , p_gain_or_loss_flag          => 'N'
31192          , p_gl_transfer_mode_code      => 'S'
31193          , p_acct_entry_type_code       => 'A'
31194          , p_switch_side_flag           => 'Y'
31195          , p_merge_duplicate_code       => 'N'
31196          );
31197    --
31198    l_acc_rev_natural_side_code := 'C';  -- 4262811
31199    -- 
31200    --
31201    -- set accounting line type info
31202    --
31203    xla_ae_lines_pkg.SetAcctLineType
31204       (p_component_type             => l_component_type
31205       ,p_event_type_code            => l_event_type_code
31206       ,p_line_definition_owner_code => l_line_definition_owner_code
31207       ,p_line_definition_code       => l_line_definition_code
31208       ,p_accounting_line_code       => l_component_code
31209       ,p_accounting_line_type_code  => l_component_type_code
31210       ,p_accounting_line_appl_id    => l_component_appl_id
31211       ,p_amb_context_code           => l_amb_context_code
31212       ,p_entity_code                => l_entity_code
31213       ,p_event_class_code           => l_event_class_code);
31214    --
31215    -- set accounting class
31216    --
31217    xla_ae_lines_pkg.SetAcctClass(
31218            p_accounting_class_code  => 'ASSET'
31219          , p_ae_header_id           => l_ae_header_id
31220          );
31221 
31222    --
31223    -- set rounding class
31224    --
31225    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
31226                       'ASSET';
31227 
31228    --
31232    -- bulk performance
31229    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
31230    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
31231    --
31233    --
31234    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
31235 
31236    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
31237       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
31238 
31239    -- 4955764
31240    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
31241       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
31242 
31243    -- 4458381 Public Sector Enh
31244    
31245    --
31246    -- set accounting attributes for the line type
31247    --
31248    l_entered_amt_idx := 4;
31249    l_accted_amt_idx  := 6;
31250    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
31251    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
31252    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
31253    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
31254    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
31255    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
31256    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
31257    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
31258    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
31259    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
31260    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
31261    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
31262    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
31263 
31264    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
31265    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
31266 
31267    ---------------------------------------------------------------------------------------------------------------
31268    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
31269    ---------------------------------------------------------------------------------------------------------------
31270    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
31271 
31272    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
31273    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
31274 
31275    IF xla_accounting_cache_pkg.GetValueChar
31276          (p_source_code         => 'LEDGER_CATEGORY_CODE'
31277          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
31278    AND l_bflow_method_code = 'PRIOR_ENTRY'
31279 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
31280    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
31281          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
31282        )
31283    THEN
31284          xla_ae_lines_pkg.BflowUpgEntry
31285            (p_business_method_code    => l_bflow_method_code
31286            ,p_business_class_code     => l_bflow_class_code
31287            ,p_balance_type            => l_balance_type_code);
31288    ELSE
31289       NULL;
31290 -- No business flow processing for business flow method of NONE.
31291    END IF;
31292 
31293    --
31294    -- call analytical criteria
31295    --
31296    
31297    --
31298    -- call description
31299    --
31300    
31301 xla_ae_lines_pkg.SetLineDescription(
31302    p_ae_header_id => l_ae_header_id
31303   ,p_description  => Description_15 (
31304      p_application_id         => p_application_id
31305    , p_ae_header_id           => l_ae_header_id 
31306 , p_source_1 => p_source_1
31307    )
31308 );
31309 
31310 
31311    --
31312    -- call ADRs
31313    -- Bug 4922099
31314    --
31315    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
31316         (NVL(l_actual_upg_option, 'N') = 'O') OR
31317         (NVL(l_enc_upg_option, 'N') = 'O')
31318       )
31319    THEN
31320    NULL;
31321    --
31322    --
31323    
31324   l_ccid := AcctDerRule_174(
31325            p_application_id           => p_application_id
31326          , p_ae_header_id             => l_ae_header_id 
31327 , p_source_3 => p_source_3
31328 , p_source_17 => p_source_17
31329 , p_source_30 => p_source_30
31330          , x_transaction_coa_id       => l_adr_transaction_coa_id
31331          , x_accounting_coa_id        => l_adr_accounting_coa_id
31332          , x_value_type_code          => l_adr_value_type_code
31333          , p_side                     => 'NA'
31334    );
31335 
31336    xla_ae_lines_pkg.set_ccid(
31337     p_code_combination_id          => l_ccid
31338   , p_value_type_code              => l_adr_value_type_code
31339   , p_transaction_coa_id           => l_adr_transaction_coa_id
31340   , p_accounting_coa_id            => l_adr_accounting_coa_id
31341   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
31342   , p_adr_type_code                => 'S'
31343   , p_component_type               => l_component_type
31344   , p_component_code               => l_component_code
31345   , p_component_type_code          => l_component_type_code
31346   , p_component_appl_id            => l_component_appl_id
31347   , p_amb_context_code             => l_amb_context_code
31348   , p_side                         => 'NA'
31349   );
31350 
31351 
31352    l_segment := AcctDerRule_149(
31353            p_application_id           => p_application_id
31354          , p_ae_header_id             => l_ae_header_id 
31355 , p_source_3 => p_source_3
31359          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31356 , p_source_10 => p_source_10
31357          , x_transaction_coa_id       => l_adr_transaction_coa_id
31358          , x_accounting_coa_id        => l_adr_accounting_coa_id
31360          , x_flex_value_set_id        => l_adr_flex_value_set_id
31361          , x_value_type_code          => l_adr_value_type_code
31362          , x_value_combination_id     => l_adr_value_combination_id
31363          , x_value_segment_code       => l_adr_value_segment_code
31364          , p_side                     => 'NA'
31365          , p_override_seg_flag        => 'Y'
31366    );
31367 
31368    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31369 
31370       xla_ae_lines_pkg.set_segment(
31371           p_to_segment_code         => 'GL_ACCOUNT'
31372         , p_segment_value           => l_segment
31373         , p_from_segment_code       => l_adr_value_segment_code
31374         , p_from_combination_id     => l_adr_value_combination_id
31375         , p_value_type_code         => l_adr_value_type_code
31376         , p_transaction_coa_id      => l_adr_transaction_coa_id
31377         , p_accounting_coa_id       => l_adr_accounting_coa_id
31378         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31379         , p_flex_value_set_id       => l_adr_flex_value_set_id
31380         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
31381         , p_adr_type_code           => 'S'
31382         , p_component_type          => l_component_type
31383         , p_component_code          => l_component_code
31384         , p_component_type_code     => l_component_type_code
31385         , p_component_appl_id       => l_component_appl_id
31386         , p_amb_context_code        => l_amb_context_code
31387         , p_entity_code             => 'TRANSACTIONS'
31388         , p_event_class_code        => 'ADJUSTMENTS'
31389         , p_side                    => 'NA'
31390         );
31391 
31392   END IF;
31393 
31394    l_segment := AcctDerRule_168(
31395            p_application_id           => p_application_id
31396          , p_ae_header_id             => l_ae_header_id 
31397 , p_source_3 => p_source_3
31398 , p_source_29 => p_source_29
31399          , x_transaction_coa_id       => l_adr_transaction_coa_id
31400          , x_accounting_coa_id        => l_adr_accounting_coa_id
31401          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31402          , x_flex_value_set_id        => l_adr_flex_value_set_id
31403          , x_value_type_code          => l_adr_value_type_code
31404          , x_value_combination_id     => l_adr_value_combination_id
31405          , x_value_segment_code       => l_adr_value_segment_code
31406          , p_side                     => 'NA'
31407          , p_override_seg_flag        => 'Y'
31408    );
31409 
31410    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31411 
31412       xla_ae_lines_pkg.set_segment(
31413           p_to_segment_code         => 'GL_BALANCING'
31414         , p_segment_value           => l_segment
31415         , p_from_segment_code       => l_adr_value_segment_code
31416         , p_from_combination_id     => l_adr_value_combination_id
31417         , p_value_type_code         => l_adr_value_type_code
31418         , p_transaction_coa_id      => l_adr_transaction_coa_id
31419         , p_accounting_coa_id       => l_adr_accounting_coa_id
31420         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31421         , p_flex_value_set_id       => l_adr_flex_value_set_id
31422         , p_adr_code                => 'FA_EXPENSE_ACCT'
31423         , p_adr_type_code           => 'S'
31424         , p_component_type          => l_component_type
31425         , p_component_code          => l_component_code
31426         , p_component_type_code     => l_component_type_code
31427         , p_component_appl_id       => l_component_appl_id
31428         , p_amb_context_code        => l_amb_context_code
31429         , p_entity_code             => 'TRANSACTIONS'
31430         , p_event_class_code        => 'ADJUSTMENTS'
31431         , p_side                    => 'NA'
31432         );
31433 
31434   END IF;
31435 
31436    --
31437    --
31438    END IF;
31439    --
31440    -- Bug 4922099
31441    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
31442           (NVL(l_enc_upg_option, 'N') = 'O')
31443         ) AND
31444         (l_bflow_method_code = 'PRIOR_ENTRY')
31445       )
31446    THEN
31447       IF
31448       --
31449       1 = 2
31450       --
31451       THEN
31452       xla_accounting_err_pkg.build_message
31453                                     (p_appli_s_name            => 'XLA'
31454                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31455                                     ,p_token_1                 => 'LINE_NUMBER'
31456                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
31457                                     ,p_token_2                 => 'LINE_TYPE_NAME'
31458                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
31459                                                                              l_component_type
31460                                                                             ,l_component_code
31461                                                                             ,l_component_type_code
31462                                                                             ,l_component_appl_id
31463                                                                             ,l_amb_context_code
31464                                                                             ,l_entity_code
31465                                                                             ,l_event_class_code
31466                                                                            )
31467                                     ,p_token_3                 => 'OWNER'
31471                                                                          )
31468                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
31469                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
31470                                                                           ,p_lookup_code    => l_component_type_code
31472                                     ,p_token_4                 => 'PRODUCT_NAME'
31473                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
31474                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
31475                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
31476                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
31477                                     ,p_ae_header_id            =>  NULL
31478                                        );
31479 
31480         IF (C_LEVEL_ERROR>= g_log_level) THEN
31481                  trace
31482                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31483                       ,p_level    => C_LEVEL_ERROR
31484                       ,p_module   => l_log_module);
31485         END IF;
31486       END IF;
31487    END IF;
31488    --
31489    --
31490    ------------------------------------------------------------------------------------------------
31491    -- 4219869 Business Flow
31492    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
31493    -- Prior Entry.  Currently, the following code is always generated.
31494    ------------------------------------------------------------------------------------------------
31495    XLA_AE_LINES_PKG.ValidateCurrentLine;
31496 
31497    ------------------------------------------------------------------------------------
31498    -- 4219869 Business Flow
31499    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
31500    ------------------------------------------------------------------------------------
31501    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
31502 
31503    ----------------------------------------------------------------------------------
31504    -- 4219869 Business Flow
31505    -- Update journal entry status -- Need to generate this within IF <condition>
31506    ----------------------------------------------------------------------------------
31507    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
31508          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
31509          ,p_balance_type_code => l_balance_type_code
31510          );
31511 
31512    -------------------------------------------------------------------------------------------
31513    -- 4262811 - Generate the Accrual Reversal lines
31514    -------------------------------------------------------------------------------------------
31515    BEGIN
31516       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
31517                               (g_array_event(p_event_id).array_value_num('header_index'));
31518       IF l_acc_rev_flag IS NULL THEN
31519          l_acc_rev_flag := 'N';
31520       END IF;
31521    EXCEPTION
31522       WHEN OTHERS THEN
31523          l_acc_rev_flag := 'N';
31524    END;
31525    --
31526    IF (l_acc_rev_flag = 'Y') THEN
31527 
31528        -- 4645092  ------------------------------------------------------------------------------
31529        -- To allow MPA report to determine if it should generate report process
31530        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
31531        ------------------------------------------------------------------------------------------
31532 
31533        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
31534        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
31535    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
31536    -- call ADRs
31537    -- Bug 4922099
31538    --
31539    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
31540         (NVL(l_actual_upg_option, 'N') = 'O') OR
31541         (NVL(l_enc_upg_option, 'N') = 'O')
31542       )
31543    THEN
31544    NULL;
31545    --
31546    --
31547    
31548   l_ccid := AcctDerRule_174(
31549            p_application_id           => p_application_id
31550          , p_ae_header_id             => l_ae_header_id 
31551 , p_source_3 => p_source_3
31552 , p_source_17 => p_source_17
31553 , p_source_30 => p_source_30
31554          , x_transaction_coa_id       => l_adr_transaction_coa_id
31555          , x_accounting_coa_id        => l_adr_accounting_coa_id
31556          , x_value_type_code          => l_adr_value_type_code
31557          , p_side                     => 'NA'
31558    );
31559 
31560    xla_ae_lines_pkg.set_ccid(
31561     p_code_combination_id          => l_ccid
31562   , p_value_type_code              => l_adr_value_type_code
31563   , p_transaction_coa_id           => l_adr_transaction_coa_id
31564   , p_accounting_coa_id            => l_adr_accounting_coa_id
31565   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
31566   , p_adr_type_code                => 'S'
31567   , p_component_type               => l_component_type
31568   , p_component_code               => l_component_code
31569   , p_component_type_code          => l_component_type_code
31570   , p_component_appl_id            => l_component_appl_id
31571   , p_amb_context_code             => l_amb_context_code
31572   , p_side                         => 'NA'
31573   );
31574 
31575 
31576    l_segment := AcctDerRule_149(
31577            p_application_id           => p_application_id
31578          , p_ae_header_id             => l_ae_header_id 
31579 , p_source_3 => p_source_3
31580 , p_source_10 => p_source_10
31584          , x_flex_value_set_id        => l_adr_flex_value_set_id
31581          , x_transaction_coa_id       => l_adr_transaction_coa_id
31582          , x_accounting_coa_id        => l_adr_accounting_coa_id
31583          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31585          , x_value_type_code          => l_adr_value_type_code
31586          , x_value_combination_id     => l_adr_value_combination_id
31587          , x_value_segment_code       => l_adr_value_segment_code
31588          , p_side                     => 'NA'
31589          , p_override_seg_flag        => 'Y'
31590    );
31591 
31592    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31593 
31594       xla_ae_lines_pkg.set_segment(
31595           p_to_segment_code         => 'GL_ACCOUNT'
31596         , p_segment_value           => l_segment
31597         , p_from_segment_code       => l_adr_value_segment_code
31598         , p_from_combination_id     => l_adr_value_combination_id
31599         , p_value_type_code         => l_adr_value_type_code
31600         , p_transaction_coa_id      => l_adr_transaction_coa_id
31601         , p_accounting_coa_id       => l_adr_accounting_coa_id
31602         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31603         , p_flex_value_set_id       => l_adr_flex_value_set_id
31604         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
31605         , p_adr_type_code           => 'S'
31606         , p_component_type          => l_component_type
31607         , p_component_code          => l_component_code
31608         , p_component_type_code     => l_component_type_code
31609         , p_component_appl_id       => l_component_appl_id
31610         , p_amb_context_code        => l_amb_context_code
31611         , p_entity_code             => 'TRANSACTIONS'
31612         , p_event_class_code        => 'ADJUSTMENTS'
31613         , p_side                    => 'NA'
31614         );
31615 
31616   END IF;
31617 
31618    l_segment := AcctDerRule_168(
31619            p_application_id           => p_application_id
31620          , p_ae_header_id             => l_ae_header_id 
31621 , p_source_3 => p_source_3
31622 , p_source_29 => p_source_29
31623          , x_transaction_coa_id       => l_adr_transaction_coa_id
31624          , x_accounting_coa_id        => l_adr_accounting_coa_id
31625          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31626          , x_flex_value_set_id        => l_adr_flex_value_set_id
31627          , x_value_type_code          => l_adr_value_type_code
31628          , x_value_combination_id     => l_adr_value_combination_id
31629          , x_value_segment_code       => l_adr_value_segment_code
31630          , p_side                     => 'NA'
31631          , p_override_seg_flag        => 'Y'
31632    );
31633 
31634    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31635 
31636       xla_ae_lines_pkg.set_segment(
31637           p_to_segment_code         => 'GL_BALANCING'
31638         , p_segment_value           => l_segment
31639         , p_from_segment_code       => l_adr_value_segment_code
31640         , p_from_combination_id     => l_adr_value_combination_id
31641         , p_value_type_code         => l_adr_value_type_code
31642         , p_transaction_coa_id      => l_adr_transaction_coa_id
31643         , p_accounting_coa_id       => l_adr_accounting_coa_id
31644         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31645         , p_flex_value_set_id       => l_adr_flex_value_set_id
31646         , p_adr_code                => 'FA_EXPENSE_ACCT'
31647         , p_adr_type_code           => 'S'
31648         , p_component_type          => l_component_type
31649         , p_component_code          => l_component_code
31650         , p_component_type_code     => l_component_type_code
31651         , p_component_appl_id       => l_component_appl_id
31652         , p_amb_context_code        => l_amb_context_code
31653         , p_entity_code             => 'TRANSACTIONS'
31654         , p_event_class_code        => 'ADJUSTMENTS'
31655         , p_side                    => 'NA'
31656         );
31657 
31658   END IF;
31659 
31660    --
31661    --
31662    END IF;
31663 
31664        --
31665        -- Update the line information that should be overwritten
31666        --
31667        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
31668                                          p_header_num   => 1);
31669        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
31670 
31671        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
31672 
31673        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
31674           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
31675        END IF;
31676 
31677       --
31678       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
31679       --
31680       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
31681           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
31682       ELSE
31683           ---------------------------------------------------------------------------------------------------
31684           -- 4262811a Switch Sign
31685           ---------------------------------------------------------------------------------------------------
31686           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
31687           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
31688                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
31689           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
31693                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
31690                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
31691           -- 5132302
31692           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
31694 
31695       END IF;
31696 
31697       -- 4955764
31698       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
31699       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
31700 
31701 
31702       XLA_AE_LINES_PKG.ValidateCurrentLine;
31703       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
31704 
31705       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
31706                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
31707                ,p_balance_type_code => l_balance_type_code);
31708 
31709    END IF;
31710 
31711    -----------------------------------------------------------------------------------------
31712    -- 4262811 Multiperiod Accounting
31713    -----------------------------------------------------------------------------------------
31714      -- No MPA option is assigned.
31715 
31716 
31717 END IF;
31718 END IF;
31719 --
31720 
31721 --
31722 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
31723    trace
31724       (p_msg      => 'END of AcctLineType_198'
31725       ,p_level    => C_LEVEL_PROCEDURE
31726       ,p_module   => l_log_module);
31727 END IF;
31728 --
31729 EXCEPTION
31730   WHEN xla_exceptions_pkg.application_exception THEN
31731       RAISE;
31732   WHEN OTHERS THEN
31733        xla_exceptions_pkg.raise_message
31734            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_198');
31735 END AcctLineType_198;
31736 --
31737 
31738 ---------------------------------------
31739 --
31740 -- PRIVATE FUNCTION
31741 --         AcctLineType_199
31742 --
31743 ---------------------------------------
31744 PROCEDURE AcctLineType_199 (
31745   p_application_id        IN NUMBER
31746  ,p_event_id              IN NUMBER
31747  ,p_calculate_acctd_flag  IN VARCHAR2
31748  ,p_calculate_g_l_flag    IN VARCHAR2
31749  ,p_actual_flag           IN OUT VARCHAR2
31750  ,p_balance_type_code     OUT VARCHAR2
31751  ,p_gain_or_loss_ref      OUT VARCHAR2
31752  
31753 --Period Close Date
31754  , p_source_1            IN DATE
31755 --Generated Code Combination Identifier
31756  , p_source_3            IN NUMBER
31757 --CIP Cost Account
31758  , p_source_7            IN VARCHAR2
31759 --Expense Account Code Combination Identifier
31760  , p_source_29            IN NUMBER
31761 --Default Code Combination Identifier
31762  , p_source_30            IN NUMBER
31763 --Adjustment Type
31764  , p_source_35            IN VARCHAR2
31765 --Transaction Header Identifier
31766  , p_source_36            IN NUMBER
31767 --Adjustment Line Identifier
31768  , p_source_37            IN NUMBER
31769 --Distribution Type Code
31770  , p_source_38            IN VARCHAR2
31771 --Entered Amount
31772  , p_source_39            IN NUMBER
31773 --Currency Code
31774  , p_source_40            IN VARCHAR2
31775 )
31776 IS
31777 
31778 l_component_type              VARCHAR2(80);
31779 l_component_code              VARCHAR2(30);
31780 l_component_type_code         VARCHAR2(1);
31781 l_component_appl_id           INTEGER;
31782 l_amb_context_code            VARCHAR2(30);
31783 l_entity_code                 VARCHAR2(30);
31784 l_event_class_code            VARCHAR2(30);
31785 l_ae_header_id                NUMBER;
31786 l_event_type_code             VARCHAR2(30);
31787 l_line_definition_code        VARCHAR2(30);
31788 l_line_definition_owner_code  VARCHAR2(1);
31789 --
31790 -- adr variables
31791 l_segment                     VARCHAR2(30);
31792 l_ccid                        NUMBER;
31793 l_adr_transaction_coa_id      NUMBER;
31794 l_adr_accounting_coa_id       NUMBER;
31795 l_adr_flexfield_segment_code  VARCHAR2(30);
31796 l_adr_flex_value_set_id       NUMBER;
31797 l_adr_value_type_code         VARCHAR2(30);
31798 l_adr_value_combination_id    NUMBER;
31799 l_adr_value_segment_code      VARCHAR2(30);
31800 
31801 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
31802 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
31803 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
31804 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
31805 
31806 -- 4262811 Variables ------------------------------------------------------------------------------------------
31807 l_entered_amt_idx             NUMBER;
31808 l_accted_amt_idx              NUMBER;
31809 l_acc_rev_flag                VARCHAR2(1);
31810 l_accrual_line_num            NUMBER;
31811 l_tmp_amt                     NUMBER;
31812 l_acc_rev_natural_side_code   VARCHAR2(1);
31813 
31814 l_num_entries                 NUMBER;
31815 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
31816 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
31817 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
31818 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
31819 l_recog_line_1                NUMBER;
31820 l_recog_line_2                NUMBER;
31821 
31822 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
31823 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
31824 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
31825 
31826 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
31827 
31831 ---------------------------------------------------------------------------------------------------------------
31828 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
31829 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
31830 
31832 
31833 
31834 --
31835 -- bulk performance
31836 --
31837 l_balance_type_code           VARCHAR2(1);
31838 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
31839 l_log_module                  VARCHAR2(240);
31840 
31841 --
31842 -- Upgrade strategy
31843 --
31844 l_actual_upg_option           VARCHAR2(1);
31845 l_enc_upg_option           VARCHAR2(1);
31846 
31847 --
31848 BEGIN
31849 --
31850 IF g_log_enabled THEN
31851       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_199';
31852 END IF;
31853 --
31854 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
31855 
31856       trace
31857          (p_msg      => 'BEGIN of AcctLineType_199'
31858          ,p_level    => C_LEVEL_PROCEDURE
31859          ,p_module   => l_log_module);
31860 
31861 END IF;
31862 --
31863 l_component_type             := 'AMB_JLT';
31864 l_component_code             := 'FA_CAP_ASSET_CIP_COST';
31865 l_component_type_code        := 'S';
31866 l_component_appl_id          :=  140;
31867 l_amb_context_code           := 'DEFAULT';
31868 l_entity_code                := 'TRANSACTIONS';
31869 l_event_class_code           := 'CAPITALIZATION';
31870 l_event_type_code            := 'CAPITALIZATION';
31871 l_line_definition_owner_code := 'S';
31872 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CAPITA3';
31873 --
31874 l_balance_type_code          := 'A';
31875 l_segment                     := NULL;
31876 l_ccid                        := NULL;
31877 l_adr_transaction_coa_id      := NULL;
31878 l_adr_accounting_coa_id       := NULL;
31879 l_adr_flexfield_segment_code  := NULL;
31880 l_adr_flex_value_set_id       := NULL;
31881 l_adr_value_type_code         := NULL;
31882 l_adr_value_combination_id    := NULL;
31883 l_adr_value_segment_code      := NULL;
31884 
31885 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
31886 l_bflow_class_code           := '';    -- 4219869 Business Flow
31887 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
31888 l_budgetary_control_flag     := 'N';
31889 
31890 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
31891 l_bflow_applied_to_amt       := NULL; -- 5132302
31892 l_entered_amt_idx            := NULL;          -- 4262811
31893 l_accted_amt_idx             := NULL;          -- 4262811
31894 l_acc_rev_flag               := NULL;          -- 4262811
31895 l_accrual_line_num           := NULL;          -- 4262811
31896 l_tmp_amt                    := NULL;          -- 4262811
31897 --
31898  
31899 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
31900     l_balance_type_code <> 'B' THEN
31901 IF NVL(p_source_35,'
31902 ') =  'CIP COST'
31903  THEN 
31904 
31905    --
31906    XLA_AE_LINES_PKG.SetNewLine;
31907 
31908    p_balance_type_code          := l_balance_type_code;
31909    -- set the flag so later we will know whether the gain loss line needs to be created
31910    
31911    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
31912      p_actual_flag :='A';
31913    END IF;
31914 
31915    --
31916    -- bulk performance
31917    --
31918    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
31919                                       p_header_num   => 0); -- 4262811
31920    --
31921    -- set accounting line options
31922    --
31923    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
31924            p_natural_side_code          => 'C'
31925          , p_gain_or_loss_flag          => 'N'
31926          , p_gl_transfer_mode_code      => 'S'
31927          , p_acct_entry_type_code       => 'A'
31928          , p_switch_side_flag           => 'Y'
31929          , p_merge_duplicate_code       => 'N'
31930          );
31931    --
31932    l_acc_rev_natural_side_code := 'D';  -- 4262811
31933    -- 
31934    --
31935    -- set accounting line type info
31936    --
31937    xla_ae_lines_pkg.SetAcctLineType
31938       (p_component_type             => l_component_type
31939       ,p_event_type_code            => l_event_type_code
31940       ,p_line_definition_owner_code => l_line_definition_owner_code
31941       ,p_line_definition_code       => l_line_definition_code
31942       ,p_accounting_line_code       => l_component_code
31943       ,p_accounting_line_type_code  => l_component_type_code
31944       ,p_accounting_line_appl_id    => l_component_appl_id
31945       ,p_amb_context_code           => l_amb_context_code
31946       ,p_entity_code                => l_entity_code
31947       ,p_event_class_code           => l_event_class_code);
31948    --
31949    -- set accounting class
31950    --
31951    xla_ae_lines_pkg.SetAcctClass(
31952            p_accounting_class_code  => 'ASSET'
31953          , p_ae_header_id           => l_ae_header_id
31954          );
31955 
31956    --
31957    -- set rounding class
31958    --
31959    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
31960                       'ASSET';
31961 
31962    --
31963    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
31964    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
31965    --
31966    -- bulk performance
31967    --
31968    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
31969 
31970    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
31974    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
31971       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
31972 
31973    -- 4955764
31975       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
31976 
31977    -- 4458381 Public Sector Enh
31978    
31979    --
31980    -- set accounting attributes for the line type
31981    --
31982    l_entered_amt_idx := 4;
31983    l_accted_amt_idx  := 6;
31984    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
31985    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
31986    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
31987    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
31988    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
31989    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
31990    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
31991    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
31992    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
31993    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
31994    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
31995    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
31996    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
31997 
31998    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
31999    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
32000 
32001    ---------------------------------------------------------------------------------------------------------------
32002    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
32003    ---------------------------------------------------------------------------------------------------------------
32004    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
32005 
32006    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32007    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32008 
32009    IF xla_accounting_cache_pkg.GetValueChar
32010          (p_source_code         => 'LEDGER_CATEGORY_CODE'
32011          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
32012    AND l_bflow_method_code = 'PRIOR_ENTRY'
32013 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
32014    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
32015          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
32016        )
32017    THEN
32018          xla_ae_lines_pkg.BflowUpgEntry
32019            (p_business_method_code    => l_bflow_method_code
32020            ,p_business_class_code     => l_bflow_class_code
32021            ,p_balance_type            => l_balance_type_code);
32022    ELSE
32023       NULL;
32024 -- No business flow processing for business flow method of NONE.
32025    END IF;
32026 
32027    --
32028    -- call analytical criteria
32029    --
32030    
32031    --
32032    -- call description
32033    --
32034    
32035 xla_ae_lines_pkg.SetLineDescription(
32036    p_ae_header_id => l_ae_header_id
32037   ,p_description  => Description_19 (
32038      p_application_id         => p_application_id
32039    , p_ae_header_id           => l_ae_header_id 
32040 , p_source_1 => p_source_1
32041    )
32042 );
32043 
32044 
32045    --
32046    -- call ADRs
32047    -- Bug 4922099
32048    --
32049    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
32050         (NVL(l_actual_upg_option, 'N') = 'O') OR
32051         (NVL(l_enc_upg_option, 'N') = 'O')
32052       )
32053    THEN
32054    NULL;
32055    --
32056    --
32057    
32058   l_ccid := AcctDerRule_173(
32059            p_application_id           => p_application_id
32060          , p_ae_header_id             => l_ae_header_id 
32061 , p_source_3 => p_source_3
32062 , p_source_30 => p_source_30
32063          , x_transaction_coa_id       => l_adr_transaction_coa_id
32064          , x_accounting_coa_id        => l_adr_accounting_coa_id
32065          , x_value_type_code          => l_adr_value_type_code
32066          , p_side                     => 'NA'
32067    );
32068 
32069    xla_ae_lines_pkg.set_ccid(
32070     p_code_combination_id          => l_ccid
32071   , p_value_type_code              => l_adr_value_type_code
32072   , p_transaction_coa_id           => l_adr_transaction_coa_id
32073   , p_accounting_coa_id            => l_adr_accounting_coa_id
32074   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
32075   , p_adr_type_code                => 'S'
32076   , p_component_type               => l_component_type
32077   , p_component_code               => l_component_code
32078   , p_component_type_code          => l_component_type_code
32079   , p_component_appl_id            => l_component_appl_id
32080   , p_amb_context_code             => l_amb_context_code
32081   , p_side                         => 'NA'
32082   );
32083 
32084 
32085    l_segment := AcctDerRule_146(
32086            p_application_id           => p_application_id
32087          , p_ae_header_id             => l_ae_header_id 
32088 , p_source_3 => p_source_3
32089 , p_source_7 => p_source_7
32090          , x_transaction_coa_id       => l_adr_transaction_coa_id
32091          , x_accounting_coa_id        => l_adr_accounting_coa_id
32092          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32093          , x_flex_value_set_id        => l_adr_flex_value_set_id
32094          , x_value_type_code          => l_adr_value_type_code
32095          , x_value_combination_id     => l_adr_value_combination_id
32096          , x_value_segment_code       => l_adr_value_segment_code
32100 
32097          , p_side                     => 'NA'
32098          , p_override_seg_flag        => 'Y'
32099    );
32101    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32102 
32103       xla_ae_lines_pkg.set_segment(
32104           p_to_segment_code         => 'GL_ACCOUNT'
32105         , p_segment_value           => l_segment
32106         , p_from_segment_code       => l_adr_value_segment_code
32107         , p_from_combination_id     => l_adr_value_combination_id
32108         , p_value_type_code         => l_adr_value_type_code
32109         , p_transaction_coa_id      => l_adr_transaction_coa_id
32110         , p_accounting_coa_id       => l_adr_accounting_coa_id
32111         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32112         , p_flex_value_set_id       => l_adr_flex_value_set_id
32113         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
32114         , p_adr_type_code           => 'S'
32115         , p_component_type          => l_component_type
32116         , p_component_code          => l_component_code
32117         , p_component_type_code     => l_component_type_code
32118         , p_component_appl_id       => l_component_appl_id
32119         , p_amb_context_code        => l_amb_context_code
32120         , p_entity_code             => 'TRANSACTIONS'
32121         , p_event_class_code        => 'CAPITALIZATION'
32122         , p_side                    => 'NA'
32123         );
32124 
32125   END IF;
32126 
32127    l_segment := AcctDerRule_168(
32128            p_application_id           => p_application_id
32129          , p_ae_header_id             => l_ae_header_id 
32130 , p_source_3 => p_source_3
32131 , p_source_29 => p_source_29
32132          , x_transaction_coa_id       => l_adr_transaction_coa_id
32133          , x_accounting_coa_id        => l_adr_accounting_coa_id
32134          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32135          , x_flex_value_set_id        => l_adr_flex_value_set_id
32136          , x_value_type_code          => l_adr_value_type_code
32137          , x_value_combination_id     => l_adr_value_combination_id
32138          , x_value_segment_code       => l_adr_value_segment_code
32139          , p_side                     => 'NA'
32140          , p_override_seg_flag        => 'Y'
32141    );
32142 
32143    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32144 
32145       xla_ae_lines_pkg.set_segment(
32146           p_to_segment_code         => 'GL_BALANCING'
32147         , p_segment_value           => l_segment
32148         , p_from_segment_code       => l_adr_value_segment_code
32149         , p_from_combination_id     => l_adr_value_combination_id
32150         , p_value_type_code         => l_adr_value_type_code
32151         , p_transaction_coa_id      => l_adr_transaction_coa_id
32152         , p_accounting_coa_id       => l_adr_accounting_coa_id
32153         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32154         , p_flex_value_set_id       => l_adr_flex_value_set_id
32155         , p_adr_code                => 'FA_EXPENSE_ACCT'
32156         , p_adr_type_code           => 'S'
32157         , p_component_type          => l_component_type
32158         , p_component_code          => l_component_code
32159         , p_component_type_code     => l_component_type_code
32160         , p_component_appl_id       => l_component_appl_id
32161         , p_amb_context_code        => l_amb_context_code
32162         , p_entity_code             => 'TRANSACTIONS'
32163         , p_event_class_code        => 'CAPITALIZATION'
32164         , p_side                    => 'NA'
32165         );
32166 
32167   END IF;
32168 
32169    --
32170    --
32171    END IF;
32172    --
32173    -- Bug 4922099
32174    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
32175           (NVL(l_enc_upg_option, 'N') = 'O')
32176         ) AND
32177         (l_bflow_method_code = 'PRIOR_ENTRY')
32178       )
32179    THEN
32180       IF
32181       --
32182       1 = 2
32183       --
32184       THEN
32185       xla_accounting_err_pkg.build_message
32186                                     (p_appli_s_name            => 'XLA'
32187                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
32188                                     ,p_token_1                 => 'LINE_NUMBER'
32189                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
32190                                     ,p_token_2                 => 'LINE_TYPE_NAME'
32191                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
32192                                                                              l_component_type
32193                                                                             ,l_component_code
32194                                                                             ,l_component_type_code
32195                                                                             ,l_component_appl_id
32196                                                                             ,l_amb_context_code
32197                                                                             ,l_entity_code
32198                                                                             ,l_event_class_code
32199                                                                            )
32200                                     ,p_token_3                 => 'OWNER'
32201                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
32202                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
32203                                                                           ,p_lookup_code    => l_component_type_code
32204                                                                          )
32205                                     ,p_token_4                 => 'PRODUCT_NAME'
32209                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
32206                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
32207                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
32208                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
32210                                     ,p_ae_header_id            =>  NULL
32211                                        );
32212 
32213         IF (C_LEVEL_ERROR>= g_log_level) THEN
32214                  trace
32215                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
32216                       ,p_level    => C_LEVEL_ERROR
32217                       ,p_module   => l_log_module);
32218         END IF;
32219       END IF;
32220    END IF;
32221    --
32222    --
32223    ------------------------------------------------------------------------------------------------
32224    -- 4219869 Business Flow
32225    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
32226    -- Prior Entry.  Currently, the following code is always generated.
32227    ------------------------------------------------------------------------------------------------
32228    XLA_AE_LINES_PKG.ValidateCurrentLine;
32229 
32230    ------------------------------------------------------------------------------------
32231    -- 4219869 Business Flow
32232    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
32233    ------------------------------------------------------------------------------------
32234    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
32235 
32236    ----------------------------------------------------------------------------------
32237    -- 4219869 Business Flow
32238    -- Update journal entry status -- Need to generate this within IF <condition>
32239    ----------------------------------------------------------------------------------
32240    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
32241          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
32242          ,p_balance_type_code => l_balance_type_code
32243          );
32244 
32245    -------------------------------------------------------------------------------------------
32246    -- 4262811 - Generate the Accrual Reversal lines
32247    -------------------------------------------------------------------------------------------
32248    BEGIN
32249       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
32250                               (g_array_event(p_event_id).array_value_num('header_index'));
32251       IF l_acc_rev_flag IS NULL THEN
32252          l_acc_rev_flag := 'N';
32253       END IF;
32254    EXCEPTION
32255       WHEN OTHERS THEN
32256          l_acc_rev_flag := 'N';
32257    END;
32258    --
32259    IF (l_acc_rev_flag = 'Y') THEN
32260 
32261        -- 4645092  ------------------------------------------------------------------------------
32262        -- To allow MPA report to determine if it should generate report process
32263        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
32264        ------------------------------------------------------------------------------------------
32265 
32266        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
32267        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
32268    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
32269    -- call ADRs
32270    -- Bug 4922099
32271    --
32272    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
32273         (NVL(l_actual_upg_option, 'N') = 'O') OR
32274         (NVL(l_enc_upg_option, 'N') = 'O')
32275       )
32276    THEN
32277    NULL;
32278    --
32279    --
32280    
32281   l_ccid := AcctDerRule_173(
32282            p_application_id           => p_application_id
32283          , p_ae_header_id             => l_ae_header_id 
32284 , p_source_3 => p_source_3
32285 , p_source_30 => p_source_30
32286          , x_transaction_coa_id       => l_adr_transaction_coa_id
32287          , x_accounting_coa_id        => l_adr_accounting_coa_id
32288          , x_value_type_code          => l_adr_value_type_code
32289          , p_side                     => 'NA'
32290    );
32291 
32292    xla_ae_lines_pkg.set_ccid(
32293     p_code_combination_id          => l_ccid
32294   , p_value_type_code              => l_adr_value_type_code
32295   , p_transaction_coa_id           => l_adr_transaction_coa_id
32296   , p_accounting_coa_id            => l_adr_accounting_coa_id
32297   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
32298   , p_adr_type_code                => 'S'
32299   , p_component_type               => l_component_type
32300   , p_component_code               => l_component_code
32301   , p_component_type_code          => l_component_type_code
32302   , p_component_appl_id            => l_component_appl_id
32303   , p_amb_context_code             => l_amb_context_code
32304   , p_side                         => 'NA'
32305   );
32306 
32307 
32308    l_segment := AcctDerRule_146(
32309            p_application_id           => p_application_id
32310          , p_ae_header_id             => l_ae_header_id 
32311 , p_source_3 => p_source_3
32312 , p_source_7 => p_source_7
32313          , x_transaction_coa_id       => l_adr_transaction_coa_id
32314          , x_accounting_coa_id        => l_adr_accounting_coa_id
32315          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32316          , x_flex_value_set_id        => l_adr_flex_value_set_id
32317          , x_value_type_code          => l_adr_value_type_code
32318          , x_value_combination_id     => l_adr_value_combination_id
32319          , x_value_segment_code       => l_adr_value_segment_code
32320          , p_side                     => 'NA'
32324    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32321          , p_override_seg_flag        => 'Y'
32322    );
32323 
32325 
32326       xla_ae_lines_pkg.set_segment(
32327           p_to_segment_code         => 'GL_ACCOUNT'
32328         , p_segment_value           => l_segment
32329         , p_from_segment_code       => l_adr_value_segment_code
32330         , p_from_combination_id     => l_adr_value_combination_id
32331         , p_value_type_code         => l_adr_value_type_code
32332         , p_transaction_coa_id      => l_adr_transaction_coa_id
32333         , p_accounting_coa_id       => l_adr_accounting_coa_id
32334         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32335         , p_flex_value_set_id       => l_adr_flex_value_set_id
32336         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
32337         , p_adr_type_code           => 'S'
32338         , p_component_type          => l_component_type
32339         , p_component_code          => l_component_code
32340         , p_component_type_code     => l_component_type_code
32341         , p_component_appl_id       => l_component_appl_id
32342         , p_amb_context_code        => l_amb_context_code
32343         , p_entity_code             => 'TRANSACTIONS'
32344         , p_event_class_code        => 'CAPITALIZATION'
32345         , p_side                    => 'NA'
32346         );
32347 
32348   END IF;
32349 
32350    l_segment := AcctDerRule_168(
32351            p_application_id           => p_application_id
32352          , p_ae_header_id             => l_ae_header_id 
32353 , p_source_3 => p_source_3
32354 , p_source_29 => p_source_29
32355          , x_transaction_coa_id       => l_adr_transaction_coa_id
32356          , x_accounting_coa_id        => l_adr_accounting_coa_id
32357          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32358          , x_flex_value_set_id        => l_adr_flex_value_set_id
32359          , x_value_type_code          => l_adr_value_type_code
32360          , x_value_combination_id     => l_adr_value_combination_id
32361          , x_value_segment_code       => l_adr_value_segment_code
32362          , p_side                     => 'NA'
32363          , p_override_seg_flag        => 'Y'
32364    );
32365 
32366    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32367 
32368       xla_ae_lines_pkg.set_segment(
32369           p_to_segment_code         => 'GL_BALANCING'
32370         , p_segment_value           => l_segment
32371         , p_from_segment_code       => l_adr_value_segment_code
32372         , p_from_combination_id     => l_adr_value_combination_id
32373         , p_value_type_code         => l_adr_value_type_code
32374         , p_transaction_coa_id      => l_adr_transaction_coa_id
32375         , p_accounting_coa_id       => l_adr_accounting_coa_id
32376         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32377         , p_flex_value_set_id       => l_adr_flex_value_set_id
32378         , p_adr_code                => 'FA_EXPENSE_ACCT'
32379         , p_adr_type_code           => 'S'
32380         , p_component_type          => l_component_type
32381         , p_component_code          => l_component_code
32382         , p_component_type_code     => l_component_type_code
32383         , p_component_appl_id       => l_component_appl_id
32384         , p_amb_context_code        => l_amb_context_code
32385         , p_entity_code             => 'TRANSACTIONS'
32386         , p_event_class_code        => 'CAPITALIZATION'
32387         , p_side                    => 'NA'
32388         );
32389 
32390   END IF;
32391 
32392    --
32393    --
32394    END IF;
32395 
32396        --
32397        -- Update the line information that should be overwritten
32398        --
32399        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
32400                                          p_header_num   => 1);
32401        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
32402 
32403        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
32404 
32405        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
32406           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
32407        END IF;
32408 
32409       --
32410       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
32411       --
32412       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
32413           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
32414       ELSE
32415           ---------------------------------------------------------------------------------------------------
32416           -- 4262811a Switch Sign
32417           ---------------------------------------------------------------------------------------------------
32418           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
32419           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32420                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32421           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32422                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32423           -- 5132302
32424           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
32425                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32426 
32427       END IF;
32428 
32429       -- 4955764
32430       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
32431       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
32435       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
32432 
32433 
32434       XLA_AE_LINES_PKG.ValidateCurrentLine;
32436 
32437       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
32438                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
32439                ,p_balance_type_code => l_balance_type_code);
32440 
32441    END IF;
32442 
32443    -----------------------------------------------------------------------------------------
32444    -- 4262811 Multiperiod Accounting
32445    -----------------------------------------------------------------------------------------
32446      -- No MPA option is assigned.
32447 
32448 
32449 END IF;
32450 END IF;
32451 --
32452 
32453 --
32454 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
32455    trace
32456       (p_msg      => 'END of AcctLineType_199'
32457       ,p_level    => C_LEVEL_PROCEDURE
32458       ,p_module   => l_log_module);
32459 END IF;
32460 --
32461 EXCEPTION
32462   WHEN xla_exceptions_pkg.application_exception THEN
32463       RAISE;
32464   WHEN OTHERS THEN
32465        xla_exceptions_pkg.raise_message
32466            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_199');
32467 END AcctLineType_199;
32468 --
32469 
32470 ---------------------------------------
32471 --
32472 -- PRIVATE FUNCTION
32473 --         AcctLineType_200
32474 --
32475 ---------------------------------------
32476 PROCEDURE AcctLineType_200 (
32477   p_application_id        IN NUMBER
32478  ,p_event_id              IN NUMBER
32479  ,p_calculate_acctd_flag  IN VARCHAR2
32480  ,p_calculate_g_l_flag    IN VARCHAR2
32481  ,p_actual_flag           IN OUT VARCHAR2
32482  ,p_balance_type_code     OUT VARCHAR2
32483  ,p_gain_or_loss_ref      OUT VARCHAR2
32484  
32485 --Period Close Date
32486  , p_source_1            IN DATE
32487 --Generated Code Combination Identifier
32488  , p_source_3            IN NUMBER
32489 --Asset Cost Account
32490  , p_source_9            IN VARCHAR2
32491 --Expense Account Code Combination Identifier
32492  , p_source_29            IN NUMBER
32493 --Default Code Combination Identifier
32494  , p_source_30            IN NUMBER
32495 --Adjustment Type
32496  , p_source_35            IN VARCHAR2
32497 --Transaction Header Identifier
32498  , p_source_36            IN NUMBER
32499 --Adjustment Line Identifier
32500  , p_source_37            IN NUMBER
32501 --Distribution Type Code
32502  , p_source_38            IN VARCHAR2
32503 --Entered Amount
32504  , p_source_39            IN NUMBER
32505 --Currency Code
32506  , p_source_40            IN VARCHAR2
32507 )
32508 IS
32509 
32510 l_component_type              VARCHAR2(80);
32511 l_component_code              VARCHAR2(30);
32512 l_component_type_code         VARCHAR2(1);
32513 l_component_appl_id           INTEGER;
32514 l_amb_context_code            VARCHAR2(30);
32515 l_entity_code                 VARCHAR2(30);
32516 l_event_class_code            VARCHAR2(30);
32517 l_ae_header_id                NUMBER;
32518 l_event_type_code             VARCHAR2(30);
32519 l_line_definition_code        VARCHAR2(30);
32520 l_line_definition_owner_code  VARCHAR2(1);
32521 --
32522 -- adr variables
32523 l_segment                     VARCHAR2(30);
32524 l_ccid                        NUMBER;
32525 l_adr_transaction_coa_id      NUMBER;
32526 l_adr_accounting_coa_id       NUMBER;
32527 l_adr_flexfield_segment_code  VARCHAR2(30);
32528 l_adr_flex_value_set_id       NUMBER;
32529 l_adr_value_type_code         VARCHAR2(30);
32530 l_adr_value_combination_id    NUMBER;
32531 l_adr_value_segment_code      VARCHAR2(30);
32532 
32533 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
32534 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
32535 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
32536 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
32537 
32538 -- 4262811 Variables ------------------------------------------------------------------------------------------
32539 l_entered_amt_idx             NUMBER;
32540 l_accted_amt_idx              NUMBER;
32541 l_acc_rev_flag                VARCHAR2(1);
32542 l_accrual_line_num            NUMBER;
32543 l_tmp_amt                     NUMBER;
32544 l_acc_rev_natural_side_code   VARCHAR2(1);
32545 
32546 l_num_entries                 NUMBER;
32547 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
32548 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
32549 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
32550 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
32551 l_recog_line_1                NUMBER;
32552 l_recog_line_2                NUMBER;
32553 
32554 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
32555 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
32556 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
32557 
32558 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
32559 
32560 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
32561 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
32562 
32563 ---------------------------------------------------------------------------------------------------------------
32564 
32565 
32566 --
32567 -- bulk performance
32568 --
32569 l_balance_type_code           VARCHAR2(1);
32570 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
32571 l_log_module                  VARCHAR2(240);
32572 
32573 --
32574 -- Upgrade strategy
32575 --
32576 l_actual_upg_option           VARCHAR2(1);
32580 BEGIN
32577 l_enc_upg_option           VARCHAR2(1);
32578 
32579 --
32581 --
32582 IF g_log_enabled THEN
32583       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_200';
32584 END IF;
32585 --
32586 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
32587 
32588       trace
32589          (p_msg      => 'BEGIN of AcctLineType_200'
32590          ,p_level    => C_LEVEL_PROCEDURE
32591          ,p_module   => l_log_module);
32592 
32593 END IF;
32594 --
32595 l_component_type             := 'AMB_JLT';
32596 l_component_code             := 'FA_CAP_ASSET_COST';
32597 l_component_type_code        := 'S';
32598 l_component_appl_id          :=  140;
32599 l_amb_context_code           := 'DEFAULT';
32600 l_entity_code                := 'TRANSACTIONS';
32601 l_event_class_code           := 'CAPITALIZATION';
32602 l_event_type_code            := 'CAPITALIZATION';
32603 l_line_definition_owner_code := 'S';
32604 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CAPITA3';
32605 --
32606 l_balance_type_code          := 'A';
32607 l_segment                     := NULL;
32608 l_ccid                        := NULL;
32609 l_adr_transaction_coa_id      := NULL;
32610 l_adr_accounting_coa_id       := NULL;
32611 l_adr_flexfield_segment_code  := NULL;
32612 l_adr_flex_value_set_id       := NULL;
32613 l_adr_value_type_code         := NULL;
32614 l_adr_value_combination_id    := NULL;
32615 l_adr_value_segment_code      := NULL;
32616 
32617 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
32618 l_bflow_class_code           := '';    -- 4219869 Business Flow
32619 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
32620 l_budgetary_control_flag     := 'N';
32621 
32622 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
32623 l_bflow_applied_to_amt       := NULL; -- 5132302
32624 l_entered_amt_idx            := NULL;          -- 4262811
32625 l_accted_amt_idx             := NULL;          -- 4262811
32626 l_acc_rev_flag               := NULL;          -- 4262811
32627 l_accrual_line_num           := NULL;          -- 4262811
32628 l_tmp_amt                    := NULL;          -- 4262811
32629 --
32630  
32631 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
32632     l_balance_type_code <> 'B' THEN
32633 IF NVL(p_source_35,'
32634 ') =  'COST'
32635  THEN 
32636 
32637    --
32638    XLA_AE_LINES_PKG.SetNewLine;
32639 
32640    p_balance_type_code          := l_balance_type_code;
32641    -- set the flag so later we will know whether the gain loss line needs to be created
32642    
32643    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
32644      p_actual_flag :='A';
32645    END IF;
32646 
32647    --
32648    -- bulk performance
32649    --
32650    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
32651                                       p_header_num   => 0); -- 4262811
32652    --
32653    -- set accounting line options
32654    --
32655    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
32656            p_natural_side_code          => 'D'
32657          , p_gain_or_loss_flag          => 'N'
32658          , p_gl_transfer_mode_code      => 'S'
32659          , p_acct_entry_type_code       => 'A'
32660          , p_switch_side_flag           => 'Y'
32661          , p_merge_duplicate_code       => 'N'
32662          );
32663    --
32664    l_acc_rev_natural_side_code := 'C';  -- 4262811
32665    -- 
32666    --
32667    -- set accounting line type info
32668    --
32669    xla_ae_lines_pkg.SetAcctLineType
32670       (p_component_type             => l_component_type
32671       ,p_event_type_code            => l_event_type_code
32672       ,p_line_definition_owner_code => l_line_definition_owner_code
32673       ,p_line_definition_code       => l_line_definition_code
32674       ,p_accounting_line_code       => l_component_code
32675       ,p_accounting_line_type_code  => l_component_type_code
32676       ,p_accounting_line_appl_id    => l_component_appl_id
32677       ,p_amb_context_code           => l_amb_context_code
32678       ,p_entity_code                => l_entity_code
32679       ,p_event_class_code           => l_event_class_code);
32680    --
32681    -- set accounting class
32682    --
32683    xla_ae_lines_pkg.SetAcctClass(
32684            p_accounting_class_code  => 'ASSET'
32685          , p_ae_header_id           => l_ae_header_id
32686          );
32687 
32688    --
32689    -- set rounding class
32690    --
32691    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
32692                       'ASSET';
32693 
32694    --
32695    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
32696    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
32697    --
32698    -- bulk performance
32699    --
32700    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
32701 
32702    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
32703       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
32704 
32705    -- 4955764
32706    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
32707       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
32708 
32709    -- 4458381 Public Sector Enh
32710    
32711    --
32712    -- set accounting attributes for the line type
32713    --
32714    l_entered_amt_idx := 4;
32715    l_accted_amt_idx  := 6;
32716    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
32717    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
32721    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
32718    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
32719    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
32720    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
32722    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
32723    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
32724    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
32725    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
32726    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
32727    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
32728    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
32729 
32730    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
32731    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
32732 
32733    ---------------------------------------------------------------------------------------------------------------
32734    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
32735    ---------------------------------------------------------------------------------------------------------------
32736    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
32737 
32738    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32739    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32740 
32741    IF xla_accounting_cache_pkg.GetValueChar
32742          (p_source_code         => 'LEDGER_CATEGORY_CODE'
32743          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
32744    AND l_bflow_method_code = 'PRIOR_ENTRY'
32745 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
32746    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
32747          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
32748        )
32749    THEN
32750          xla_ae_lines_pkg.BflowUpgEntry
32751            (p_business_method_code    => l_bflow_method_code
32752            ,p_business_class_code     => l_bflow_class_code
32753            ,p_balance_type            => l_balance_type_code);
32754    ELSE
32755       NULL;
32756 -- No business flow processing for business flow method of NONE.
32757    END IF;
32758 
32759    --
32760    -- call analytical criteria
32761    --
32762    
32763    --
32764    -- call description
32765    --
32766    
32767 xla_ae_lines_pkg.SetLineDescription(
32768    p_ae_header_id => l_ae_header_id
32769   ,p_description  => Description_20 (
32770      p_application_id         => p_application_id
32771    , p_ae_header_id           => l_ae_header_id 
32772 , p_source_1 => p_source_1
32773    )
32774 );
32775 
32776 
32777    --
32778    -- call ADRs
32779    -- Bug 4922099
32780    --
32781    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
32782         (NVL(l_actual_upg_option, 'N') = 'O') OR
32783         (NVL(l_enc_upg_option, 'N') = 'O')
32784       )
32785    THEN
32786    NULL;
32787    --
32788    --
32789    
32790   l_ccid := AcctDerRule_173(
32791            p_application_id           => p_application_id
32792          , p_ae_header_id             => l_ae_header_id 
32793 , p_source_3 => p_source_3
32794 , p_source_30 => p_source_30
32795          , x_transaction_coa_id       => l_adr_transaction_coa_id
32796          , x_accounting_coa_id        => l_adr_accounting_coa_id
32797          , x_value_type_code          => l_adr_value_type_code
32798          , p_side                     => 'NA'
32799    );
32800 
32801    xla_ae_lines_pkg.set_ccid(
32802     p_code_combination_id          => l_ccid
32803   , p_value_type_code              => l_adr_value_type_code
32804   , p_transaction_coa_id           => l_adr_transaction_coa_id
32805   , p_accounting_coa_id            => l_adr_accounting_coa_id
32806   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
32807   , p_adr_type_code                => 'S'
32808   , p_component_type               => l_component_type
32809   , p_component_code               => l_component_code
32810   , p_component_type_code          => l_component_type_code
32811   , p_component_appl_id            => l_component_appl_id
32812   , p_amb_context_code             => l_amb_context_code
32813   , p_side                         => 'NA'
32814   );
32815 
32816 
32817    l_segment := AcctDerRule_148(
32818            p_application_id           => p_application_id
32819          , p_ae_header_id             => l_ae_header_id 
32820 , p_source_3 => p_source_3
32821 , p_source_9 => p_source_9
32822          , x_transaction_coa_id       => l_adr_transaction_coa_id
32823          , x_accounting_coa_id        => l_adr_accounting_coa_id
32824          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32825          , x_flex_value_set_id        => l_adr_flex_value_set_id
32826          , x_value_type_code          => l_adr_value_type_code
32827          , x_value_combination_id     => l_adr_value_combination_id
32828          , x_value_segment_code       => l_adr_value_segment_code
32829          , p_side                     => 'NA'
32830          , p_override_seg_flag        => 'Y'
32831    );
32832 
32833    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32834 
32835       xla_ae_lines_pkg.set_segment(
32836           p_to_segment_code         => 'GL_ACCOUNT'
32837         , p_segment_value           => l_segment
32838         , p_from_segment_code       => l_adr_value_segment_code
32839         , p_from_combination_id     => l_adr_value_combination_id
32840         , p_value_type_code         => l_adr_value_type_code
32841         , p_transaction_coa_id      => l_adr_transaction_coa_id
32845         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
32842         , p_accounting_coa_id       => l_adr_accounting_coa_id
32843         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32844         , p_flex_value_set_id       => l_adr_flex_value_set_id
32846         , p_adr_type_code           => 'S'
32847         , p_component_type          => l_component_type
32848         , p_component_code          => l_component_code
32849         , p_component_type_code     => l_component_type_code
32850         , p_component_appl_id       => l_component_appl_id
32851         , p_amb_context_code        => l_amb_context_code
32852         , p_entity_code             => 'TRANSACTIONS'
32853         , p_event_class_code        => 'CAPITALIZATION'
32854         , p_side                    => 'NA'
32855         );
32856 
32857   END IF;
32858 
32859    l_segment := AcctDerRule_168(
32860            p_application_id           => p_application_id
32861          , p_ae_header_id             => l_ae_header_id 
32862 , p_source_3 => p_source_3
32863 , p_source_29 => p_source_29
32864          , x_transaction_coa_id       => l_adr_transaction_coa_id
32865          , x_accounting_coa_id        => l_adr_accounting_coa_id
32866          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32867          , x_flex_value_set_id        => l_adr_flex_value_set_id
32868          , x_value_type_code          => l_adr_value_type_code
32869          , x_value_combination_id     => l_adr_value_combination_id
32870          , x_value_segment_code       => l_adr_value_segment_code
32871          , p_side                     => 'NA'
32872          , p_override_seg_flag        => 'Y'
32873    );
32874 
32875    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32876 
32877       xla_ae_lines_pkg.set_segment(
32878           p_to_segment_code         => 'GL_BALANCING'
32879         , p_segment_value           => l_segment
32880         , p_from_segment_code       => l_adr_value_segment_code
32881         , p_from_combination_id     => l_adr_value_combination_id
32882         , p_value_type_code         => l_adr_value_type_code
32883         , p_transaction_coa_id      => l_adr_transaction_coa_id
32884         , p_accounting_coa_id       => l_adr_accounting_coa_id
32885         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32886         , p_flex_value_set_id       => l_adr_flex_value_set_id
32887         , p_adr_code                => 'FA_EXPENSE_ACCT'
32888         , p_adr_type_code           => 'S'
32889         , p_component_type          => l_component_type
32890         , p_component_code          => l_component_code
32891         , p_component_type_code     => l_component_type_code
32892         , p_component_appl_id       => l_component_appl_id
32893         , p_amb_context_code        => l_amb_context_code
32894         , p_entity_code             => 'TRANSACTIONS'
32895         , p_event_class_code        => 'CAPITALIZATION'
32896         , p_side                    => 'NA'
32897         );
32898 
32899   END IF;
32900 
32901    --
32902    --
32903    END IF;
32904    --
32905    -- Bug 4922099
32906    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
32907           (NVL(l_enc_upg_option, 'N') = 'O')
32908         ) AND
32909         (l_bflow_method_code = 'PRIOR_ENTRY')
32910       )
32911    THEN
32912       IF
32913       --
32914       1 = 2
32915       --
32916       THEN
32917       xla_accounting_err_pkg.build_message
32918                                     (p_appli_s_name            => 'XLA'
32919                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
32920                                     ,p_token_1                 => 'LINE_NUMBER'
32921                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
32922                                     ,p_token_2                 => 'LINE_TYPE_NAME'
32923                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
32924                                                                              l_component_type
32925                                                                             ,l_component_code
32926                                                                             ,l_component_type_code
32927                                                                             ,l_component_appl_id
32928                                                                             ,l_amb_context_code
32929                                                                             ,l_entity_code
32930                                                                             ,l_event_class_code
32931                                                                            )
32932                                     ,p_token_3                 => 'OWNER'
32933                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
32934                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
32935                                                                           ,p_lookup_code    => l_component_type_code
32936                                                                          )
32937                                     ,p_token_4                 => 'PRODUCT_NAME'
32938                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
32939                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
32940                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
32941                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
32942                                     ,p_ae_header_id            =>  NULL
32943                                        );
32944 
32945         IF (C_LEVEL_ERROR>= g_log_level) THEN
32946                  trace
32950         END IF;
32947                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
32948                       ,p_level    => C_LEVEL_ERROR
32949                       ,p_module   => l_log_module);
32951       END IF;
32952    END IF;
32953    --
32954    --
32955    ------------------------------------------------------------------------------------------------
32956    -- 4219869 Business Flow
32957    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
32958    -- Prior Entry.  Currently, the following code is always generated.
32959    ------------------------------------------------------------------------------------------------
32960    XLA_AE_LINES_PKG.ValidateCurrentLine;
32961 
32962    ------------------------------------------------------------------------------------
32963    -- 4219869 Business Flow
32964    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
32965    ------------------------------------------------------------------------------------
32966    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
32967 
32968    ----------------------------------------------------------------------------------
32969    -- 4219869 Business Flow
32970    -- Update journal entry status -- Need to generate this within IF <condition>
32971    ----------------------------------------------------------------------------------
32972    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
32973          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
32974          ,p_balance_type_code => l_balance_type_code
32975          );
32976 
32977    -------------------------------------------------------------------------------------------
32978    -- 4262811 - Generate the Accrual Reversal lines
32979    -------------------------------------------------------------------------------------------
32980    BEGIN
32981       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
32982                               (g_array_event(p_event_id).array_value_num('header_index'));
32983       IF l_acc_rev_flag IS NULL THEN
32984          l_acc_rev_flag := 'N';
32985       END IF;
32986    EXCEPTION
32987       WHEN OTHERS THEN
32988          l_acc_rev_flag := 'N';
32989    END;
32990    --
32991    IF (l_acc_rev_flag = 'Y') THEN
32992 
32993        -- 4645092  ------------------------------------------------------------------------------
32994        -- To allow MPA report to determine if it should generate report process
32995        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
32996        ------------------------------------------------------------------------------------------
32997 
32998        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
32999        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
33000    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
33001    -- call ADRs
33002    -- Bug 4922099
33003    --
33004    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33005         (NVL(l_actual_upg_option, 'N') = 'O') OR
33006         (NVL(l_enc_upg_option, 'N') = 'O')
33007       )
33008    THEN
33009    NULL;
33010    --
33011    --
33012    
33013   l_ccid := AcctDerRule_173(
33014            p_application_id           => p_application_id
33015          , p_ae_header_id             => l_ae_header_id 
33016 , p_source_3 => p_source_3
33017 , p_source_30 => p_source_30
33018          , x_transaction_coa_id       => l_adr_transaction_coa_id
33019          , x_accounting_coa_id        => l_adr_accounting_coa_id
33020          , x_value_type_code          => l_adr_value_type_code
33021          , p_side                     => 'NA'
33022    );
33023 
33024    xla_ae_lines_pkg.set_ccid(
33025     p_code_combination_id          => l_ccid
33026   , p_value_type_code              => l_adr_value_type_code
33027   , p_transaction_coa_id           => l_adr_transaction_coa_id
33028   , p_accounting_coa_id            => l_adr_accounting_coa_id
33029   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
33030   , p_adr_type_code                => 'S'
33031   , p_component_type               => l_component_type
33032   , p_component_code               => l_component_code
33033   , p_component_type_code          => l_component_type_code
33034   , p_component_appl_id            => l_component_appl_id
33035   , p_amb_context_code             => l_amb_context_code
33036   , p_side                         => 'NA'
33037   );
33038 
33039 
33040    l_segment := AcctDerRule_148(
33041            p_application_id           => p_application_id
33042          , p_ae_header_id             => l_ae_header_id 
33043 , p_source_3 => p_source_3
33044 , p_source_9 => p_source_9
33045          , x_transaction_coa_id       => l_adr_transaction_coa_id
33046          , x_accounting_coa_id        => l_adr_accounting_coa_id
33047          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
33048          , x_flex_value_set_id        => l_adr_flex_value_set_id
33049          , x_value_type_code          => l_adr_value_type_code
33050          , x_value_combination_id     => l_adr_value_combination_id
33051          , x_value_segment_code       => l_adr_value_segment_code
33052          , p_side                     => 'NA'
33053          , p_override_seg_flag        => 'Y'
33054    );
33055 
33056    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
33057 
33058       xla_ae_lines_pkg.set_segment(
33059           p_to_segment_code         => 'GL_ACCOUNT'
33060         , p_segment_value           => l_segment
33061         , p_from_segment_code       => l_adr_value_segment_code
33062         , p_from_combination_id     => l_adr_value_combination_id
33063         , p_value_type_code         => l_adr_value_type_code
33064         , p_transaction_coa_id      => l_adr_transaction_coa_id
33065         , p_accounting_coa_id       => l_adr_accounting_coa_id
33069         , p_adr_type_code           => 'S'
33066         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
33067         , p_flex_value_set_id       => l_adr_flex_value_set_id
33068         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
33070         , p_component_type          => l_component_type
33071         , p_component_code          => l_component_code
33072         , p_component_type_code     => l_component_type_code
33073         , p_component_appl_id       => l_component_appl_id
33074         , p_amb_context_code        => l_amb_context_code
33075         , p_entity_code             => 'TRANSACTIONS'
33076         , p_event_class_code        => 'CAPITALIZATION'
33077         , p_side                    => 'NA'
33078         );
33079 
33080   END IF;
33081 
33082    l_segment := AcctDerRule_168(
33083            p_application_id           => p_application_id
33084          , p_ae_header_id             => l_ae_header_id 
33085 , p_source_3 => p_source_3
33086 , p_source_29 => p_source_29
33087          , x_transaction_coa_id       => l_adr_transaction_coa_id
33088          , x_accounting_coa_id        => l_adr_accounting_coa_id
33089          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
33090          , x_flex_value_set_id        => l_adr_flex_value_set_id
33091          , x_value_type_code          => l_adr_value_type_code
33092          , x_value_combination_id     => l_adr_value_combination_id
33093          , x_value_segment_code       => l_adr_value_segment_code
33094          , p_side                     => 'NA'
33095          , p_override_seg_flag        => 'Y'
33096    );
33097 
33098    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
33099 
33100       xla_ae_lines_pkg.set_segment(
33101           p_to_segment_code         => 'GL_BALANCING'
33102         , p_segment_value           => l_segment
33103         , p_from_segment_code       => l_adr_value_segment_code
33104         , p_from_combination_id     => l_adr_value_combination_id
33105         , p_value_type_code         => l_adr_value_type_code
33106         , p_transaction_coa_id      => l_adr_transaction_coa_id
33107         , p_accounting_coa_id       => l_adr_accounting_coa_id
33108         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
33109         , p_flex_value_set_id       => l_adr_flex_value_set_id
33110         , p_adr_code                => 'FA_EXPENSE_ACCT'
33111         , p_adr_type_code           => 'S'
33112         , p_component_type          => l_component_type
33113         , p_component_code          => l_component_code
33114         , p_component_type_code     => l_component_type_code
33115         , p_component_appl_id       => l_component_appl_id
33116         , p_amb_context_code        => l_amb_context_code
33117         , p_entity_code             => 'TRANSACTIONS'
33118         , p_event_class_code        => 'CAPITALIZATION'
33119         , p_side                    => 'NA'
33120         );
33121 
33122   END IF;
33123 
33124    --
33125    --
33126    END IF;
33127 
33128        --
33129        -- Update the line information that should be overwritten
33130        --
33131        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
33132                                          p_header_num   => 1);
33133        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
33134 
33135        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
33136 
33137        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
33138           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
33139        END IF;
33140 
33141       --
33142       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
33143       --
33144       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
33145           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
33146       ELSE
33147           ---------------------------------------------------------------------------------------------------
33148           -- 4262811a Switch Sign
33149           ---------------------------------------------------------------------------------------------------
33150           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
33151           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33152                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33153           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33154                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33155           -- 5132302
33156           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
33157                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33158 
33159       END IF;
33160 
33161       -- 4955764
33162       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33163       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
33164 
33165 
33166       XLA_AE_LINES_PKG.ValidateCurrentLine;
33167       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33168 
33169       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33170                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
33171                ,p_balance_type_code => l_balance_type_code);
33172 
33173    END IF;
33174 
33175    -----------------------------------------------------------------------------------------
33176    -- 4262811 Multiperiod Accounting
33177    -----------------------------------------------------------------------------------------
33181 END IF;
33178      -- No MPA option is assigned.
33179 
33180 
33182 END IF;
33183 --
33184 
33185 --
33186 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33187    trace
33188       (p_msg      => 'END of AcctLineType_200'
33189       ,p_level    => C_LEVEL_PROCEDURE
33190       ,p_module   => l_log_module);
33191 END IF;
33192 --
33193 EXCEPTION
33194   WHEN xla_exceptions_pkg.application_exception THEN
33195       RAISE;
33196   WHEN OTHERS THEN
33197        xla_exceptions_pkg.raise_message
33198            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_200');
33199 END AcctLineType_200;
33200 --
33201 
33202 ---------------------------------------
33203 --
33204 -- PRIVATE FUNCTION
33205 --         AcctLineType_201
33206 --
33207 ---------------------------------------
33208 PROCEDURE AcctLineType_201 (
33209   p_application_id        IN NUMBER
33210  ,p_event_id              IN NUMBER
33211  ,p_calculate_acctd_flag  IN VARCHAR2
33212  ,p_calculate_g_l_flag    IN VARCHAR2
33213  ,p_actual_flag           IN OUT VARCHAR2
33214  ,p_balance_type_code     OUT VARCHAR2
33215  ,p_gain_or_loss_ref      OUT VARCHAR2
33216  
33217 --Period Close Date
33218  , p_source_1            IN DATE
33219 --Generated Code Combination Identifier
33220  , p_source_3            IN NUMBER
33221 --Expense Account Code Combination Identifier
33222  , p_source_29            IN NUMBER
33223 --Adjustment Type
33224  , p_source_35            IN VARCHAR2
33225 --Transaction Header Identifier
33226  , p_source_36            IN NUMBER
33227 --Adjustment Line Identifier
33228  , p_source_37            IN NUMBER
33229 --Distribution Type Code
33230  , p_source_38            IN VARCHAR2
33231 --Entered Amount
33232  , p_source_39            IN NUMBER
33233 --Currency Code
33234  , p_source_40            IN VARCHAR2
33235 )
33236 IS
33237 
33238 l_component_type              VARCHAR2(80);
33239 l_component_code              VARCHAR2(30);
33240 l_component_type_code         VARCHAR2(1);
33241 l_component_appl_id           INTEGER;
33242 l_amb_context_code            VARCHAR2(30);
33243 l_entity_code                 VARCHAR2(30);
33244 l_event_class_code            VARCHAR2(30);
33245 l_ae_header_id                NUMBER;
33246 l_event_type_code             VARCHAR2(30);
33247 l_line_definition_code        VARCHAR2(30);
33248 l_line_definition_owner_code  VARCHAR2(1);
33249 --
33250 -- adr variables
33251 l_segment                     VARCHAR2(30);
33252 l_ccid                        NUMBER;
33253 l_adr_transaction_coa_id      NUMBER;
33254 l_adr_accounting_coa_id       NUMBER;
33255 l_adr_flexfield_segment_code  VARCHAR2(30);
33256 l_adr_flex_value_set_id       NUMBER;
33257 l_adr_value_type_code         VARCHAR2(30);
33258 l_adr_value_combination_id    NUMBER;
33259 l_adr_value_segment_code      VARCHAR2(30);
33260 
33261 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
33262 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
33263 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
33264 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
33265 
33266 -- 4262811 Variables ------------------------------------------------------------------------------------------
33267 l_entered_amt_idx             NUMBER;
33268 l_accted_amt_idx              NUMBER;
33269 l_acc_rev_flag                VARCHAR2(1);
33270 l_accrual_line_num            NUMBER;
33271 l_tmp_amt                     NUMBER;
33272 l_acc_rev_natural_side_code   VARCHAR2(1);
33273 
33274 l_num_entries                 NUMBER;
33275 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
33276 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
33277 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
33278 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
33279 l_recog_line_1                NUMBER;
33280 l_recog_line_2                NUMBER;
33281 
33282 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
33283 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
33284 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
33285 
33286 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
33287 
33288 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
33289 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
33290 
33291 ---------------------------------------------------------------------------------------------------------------
33292 
33293 
33294 --
33295 -- bulk performance
33296 --
33297 l_balance_type_code           VARCHAR2(1);
33298 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
33299 l_log_module                  VARCHAR2(240);
33300 
33301 --
33302 -- Upgrade strategy
33303 --
33304 l_actual_upg_option           VARCHAR2(1);
33305 l_enc_upg_option           VARCHAR2(1);
33306 
33307 --
33308 BEGIN
33309 --
33310 IF g_log_enabled THEN
33311       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_201';
33312 END IF;
33313 --
33314 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33315 
33316       trace
33317          (p_msg      => 'BEGIN of AcctLineType_201'
33318          ,p_level    => C_LEVEL_PROCEDURE
33319          ,p_module   => l_log_module);
33320 
33321 END IF;
33322 --
33323 l_component_type             := 'AMB_JLT';
33324 l_component_code             := 'FA_CAP_ASSET_EXP';
33325 l_component_type_code        := 'S';
33326 l_component_appl_id          :=  140;
33327 l_amb_context_code           := 'DEFAULT';
33328 l_entity_code                := 'TRANSACTIONS';
33332 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CAPITA3';
33329 l_event_class_code           := 'CAPITALIZATION';
33330 l_event_type_code            := 'CAPITALIZATION';
33331 l_line_definition_owner_code := 'S';
33333 --
33334 l_balance_type_code          := 'A';
33335 l_segment                     := NULL;
33336 l_ccid                        := NULL;
33337 l_adr_transaction_coa_id      := NULL;
33338 l_adr_accounting_coa_id       := NULL;
33339 l_adr_flexfield_segment_code  := NULL;
33340 l_adr_flex_value_set_id       := NULL;
33341 l_adr_value_type_code         := NULL;
33342 l_adr_value_combination_id    := NULL;
33343 l_adr_value_segment_code      := NULL;
33344 
33345 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
33346 l_bflow_class_code           := '';    -- 4219869 Business Flow
33347 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
33348 l_budgetary_control_flag     := 'N';
33349 
33350 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
33351 l_bflow_applied_to_amt       := NULL; -- 5132302
33352 l_entered_amt_idx            := NULL;          -- 4262811
33353 l_accted_amt_idx             := NULL;          -- 4262811
33354 l_acc_rev_flag               := NULL;          -- 4262811
33355 l_accrual_line_num           := NULL;          -- 4262811
33356 l_tmp_amt                    := NULL;          -- 4262811
33357 --
33358  
33359 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
33360     l_balance_type_code <> 'B' THEN
33361 IF NVL(p_source_35,'
33362 ') =  'EXPENSE'
33363  THEN 
33364 
33365    --
33366    XLA_AE_LINES_PKG.SetNewLine;
33367 
33368    p_balance_type_code          := l_balance_type_code;
33369    -- set the flag so later we will know whether the gain loss line needs to be created
33370    
33371    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
33372      p_actual_flag :='A';
33373    END IF;
33374 
33375    --
33376    -- bulk performance
33377    --
33378    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
33379                                       p_header_num   => 0); -- 4262811
33380    --
33381    -- set accounting line options
33382    --
33383    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
33384            p_natural_side_code          => 'D'
33385          , p_gain_or_loss_flag          => 'N'
33386          , p_gl_transfer_mode_code      => 'S'
33387          , p_acct_entry_type_code       => 'A'
33388          , p_switch_side_flag           => 'Y'
33389          , p_merge_duplicate_code       => 'N'
33390          );
33391    --
33392    l_acc_rev_natural_side_code := 'C';  -- 4262811
33393    -- 
33394    --
33395    -- set accounting line type info
33396    --
33397    xla_ae_lines_pkg.SetAcctLineType
33398       (p_component_type             => l_component_type
33399       ,p_event_type_code            => l_event_type_code
33400       ,p_line_definition_owner_code => l_line_definition_owner_code
33401       ,p_line_definition_code       => l_line_definition_code
33402       ,p_accounting_line_code       => l_component_code
33403       ,p_accounting_line_type_code  => l_component_type_code
33404       ,p_accounting_line_appl_id    => l_component_appl_id
33405       ,p_amb_context_code           => l_amb_context_code
33406       ,p_entity_code                => l_entity_code
33407       ,p_event_class_code           => l_event_class_code);
33408    --
33409    -- set accounting class
33410    --
33411    xla_ae_lines_pkg.SetAcctClass(
33412            p_accounting_class_code  => 'EXPENSE'
33413          , p_ae_header_id           => l_ae_header_id
33414          );
33415 
33416    --
33417    -- set rounding class
33418    --
33419    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
33420                       'EXPENSE';
33421 
33422    --
33423    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
33424    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
33425    --
33426    -- bulk performance
33427    --
33428    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
33429 
33430    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
33431       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
33432 
33433    -- 4955764
33434    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33435       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
33436 
33437    -- 4458381 Public Sector Enh
33438    
33439    --
33440    -- set accounting attributes for the line type
33441    --
33442    l_entered_amt_idx := 4;
33443    l_accted_amt_idx  := 6;
33444    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
33445    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
33446    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
33447    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
33448    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
33449    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
33450    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
33451    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
33452    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
33453    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
33454    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
33455    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
33456    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
33457 
33458    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
33462    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
33459    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
33460 
33461    ---------------------------------------------------------------------------------------------------------------
33463    ---------------------------------------------------------------------------------------------------------------
33464    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
33465 
33466    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
33467    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
33468 
33469    IF xla_accounting_cache_pkg.GetValueChar
33470          (p_source_code         => 'LEDGER_CATEGORY_CODE'
33471          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
33472    AND l_bflow_method_code = 'PRIOR_ENTRY'
33473 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
33474    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
33475          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
33476        )
33477    THEN
33478          xla_ae_lines_pkg.BflowUpgEntry
33479            (p_business_method_code    => l_bflow_method_code
33480            ,p_business_class_code     => l_bflow_class_code
33481            ,p_balance_type            => l_balance_type_code);
33482    ELSE
33483       NULL;
33484 -- No business flow processing for business flow method of NONE.
33485    END IF;
33486 
33487    --
33488    -- call analytical criteria
33489    --
33490    
33491    --
33492    -- call description
33493    --
33494    
33495 xla_ae_lines_pkg.SetLineDescription(
33496    p_ae_header_id => l_ae_header_id
33497   ,p_description  => Description_21 (
33498      p_application_id         => p_application_id
33499    , p_ae_header_id           => l_ae_header_id 
33500 , p_source_1 => p_source_1
33501    )
33502 );
33503 
33504 
33505    --
33506    -- call ADRs
33507    -- Bug 4922099
33508    --
33509    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33510         (NVL(l_actual_upg_option, 'N') = 'O') OR
33511         (NVL(l_enc_upg_option, 'N') = 'O')
33512       )
33513    THEN
33514    NULL;
33515    --
33516    --
33517    
33518   l_ccid := AcctDerRule_175(
33519            p_application_id           => p_application_id
33520          , p_ae_header_id             => l_ae_header_id 
33521 , p_source_3 => p_source_3
33522 , p_source_29 => p_source_29
33523          , x_transaction_coa_id       => l_adr_transaction_coa_id
33524          , x_accounting_coa_id        => l_adr_accounting_coa_id
33525          , x_value_type_code          => l_adr_value_type_code
33526          , p_side                     => 'NA'
33527    );
33528 
33529    xla_ae_lines_pkg.set_ccid(
33530     p_code_combination_id          => l_ccid
33531   , p_value_type_code              => l_adr_value_type_code
33532   , p_transaction_coa_id           => l_adr_transaction_coa_id
33533   , p_accounting_coa_id            => l_adr_accounting_coa_id
33534   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
33535   , p_adr_type_code                => 'S'
33536   , p_component_type               => l_component_type
33537   , p_component_code               => l_component_code
33538   , p_component_type_code          => l_component_type_code
33539   , p_component_appl_id            => l_component_appl_id
33540   , p_amb_context_code             => l_amb_context_code
33541   , p_side                         => 'NA'
33542   );
33543 
33544 
33545    --
33546    --
33547    END IF;
33548    --
33549    -- Bug 4922099
33550    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
33551           (NVL(l_enc_upg_option, 'N') = 'O')
33552         ) AND
33553         (l_bflow_method_code = 'PRIOR_ENTRY')
33554       )
33555    THEN
33556       IF
33557       --
33558       1 = 2
33559       --
33560       THEN
33561       xla_accounting_err_pkg.build_message
33562                                     (p_appli_s_name            => 'XLA'
33563                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33564                                     ,p_token_1                 => 'LINE_NUMBER'
33565                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
33566                                     ,p_token_2                 => 'LINE_TYPE_NAME'
33567                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
33568                                                                              l_component_type
33569                                                                             ,l_component_code
33570                                                                             ,l_component_type_code
33571                                                                             ,l_component_appl_id
33572                                                                             ,l_amb_context_code
33573                                                                             ,l_entity_code
33574                                                                             ,l_event_class_code
33575                                                                            )
33576                                     ,p_token_3                 => 'OWNER'
33577                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
33578                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
33579                                                                           ,p_lookup_code    => l_component_type_code
33580                                                                          )
33584                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
33581                                     ,p_token_4                 => 'PRODUCT_NAME'
33582                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
33583                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
33585                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
33586                                     ,p_ae_header_id            =>  NULL
33587                                        );
33588 
33589         IF (C_LEVEL_ERROR>= g_log_level) THEN
33590                  trace
33591                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33592                       ,p_level    => C_LEVEL_ERROR
33593                       ,p_module   => l_log_module);
33594         END IF;
33595       END IF;
33596    END IF;
33597    --
33598    --
33599    ------------------------------------------------------------------------------------------------
33600    -- 4219869 Business Flow
33601    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
33602    -- Prior Entry.  Currently, the following code is always generated.
33603    ------------------------------------------------------------------------------------------------
33604    XLA_AE_LINES_PKG.ValidateCurrentLine;
33605 
33606    ------------------------------------------------------------------------------------
33607    -- 4219869 Business Flow
33608    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
33609    ------------------------------------------------------------------------------------
33610    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33611 
33612    ----------------------------------------------------------------------------------
33613    -- 4219869 Business Flow
33614    -- Update journal entry status -- Need to generate this within IF <condition>
33615    ----------------------------------------------------------------------------------
33616    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33617          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
33618          ,p_balance_type_code => l_balance_type_code
33619          );
33620 
33621    -------------------------------------------------------------------------------------------
33622    -- 4262811 - Generate the Accrual Reversal lines
33623    -------------------------------------------------------------------------------------------
33624    BEGIN
33625       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
33626                               (g_array_event(p_event_id).array_value_num('header_index'));
33627       IF l_acc_rev_flag IS NULL THEN
33628          l_acc_rev_flag := 'N';
33629       END IF;
33630    EXCEPTION
33631       WHEN OTHERS THEN
33632          l_acc_rev_flag := 'N';
33633    END;
33634    --
33635    IF (l_acc_rev_flag = 'Y') THEN
33636 
33637        -- 4645092  ------------------------------------------------------------------------------
33638        -- To allow MPA report to determine if it should generate report process
33639        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
33640        ------------------------------------------------------------------------------------------
33641 
33642        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
33643        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
33644    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
33645    -- call ADRs
33646    -- Bug 4922099
33647    --
33648    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33649         (NVL(l_actual_upg_option, 'N') = 'O') OR
33650         (NVL(l_enc_upg_option, 'N') = 'O')
33651       )
33652    THEN
33653    NULL;
33654    --
33655    --
33656    
33657   l_ccid := AcctDerRule_175(
33658            p_application_id           => p_application_id
33659          , p_ae_header_id             => l_ae_header_id 
33660 , p_source_3 => p_source_3
33661 , p_source_29 => p_source_29
33662          , x_transaction_coa_id       => l_adr_transaction_coa_id
33663          , x_accounting_coa_id        => l_adr_accounting_coa_id
33664          , x_value_type_code          => l_adr_value_type_code
33665          , p_side                     => 'NA'
33666    );
33667 
33668    xla_ae_lines_pkg.set_ccid(
33669     p_code_combination_id          => l_ccid
33670   , p_value_type_code              => l_adr_value_type_code
33671   , p_transaction_coa_id           => l_adr_transaction_coa_id
33672   , p_accounting_coa_id            => l_adr_accounting_coa_id
33673   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
33674   , p_adr_type_code                => 'S'
33675   , p_component_type               => l_component_type
33676   , p_component_code               => l_component_code
33677   , p_component_type_code          => l_component_type_code
33678   , p_component_appl_id            => l_component_appl_id
33679   , p_amb_context_code             => l_amb_context_code
33680   , p_side                         => 'NA'
33681   );
33682 
33683 
33684    --
33685    --
33686    END IF;
33687 
33688        --
33689        -- Update the line information that should be overwritten
33690        --
33691        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
33692                                          p_header_num   => 1);
33693        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
33694 
33695        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
33696 
33697        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
33701       --
33698           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
33699        END IF;
33700 
33702       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
33703       --
33704       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
33705           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
33706       ELSE
33707           ---------------------------------------------------------------------------------------------------
33708           -- 4262811a Switch Sign
33709           ---------------------------------------------------------------------------------------------------
33710           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
33711           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33712                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33713           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33714                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33715           -- 5132302
33716           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
33717                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33718 
33719       END IF;
33720 
33721       -- 4955764
33722       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33723       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
33724 
33725 
33726       XLA_AE_LINES_PKG.ValidateCurrentLine;
33727       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33728 
33729       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33730                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
33731                ,p_balance_type_code => l_balance_type_code);
33732 
33733    END IF;
33734 
33735    -----------------------------------------------------------------------------------------
33736    -- 4262811 Multiperiod Accounting
33737    -----------------------------------------------------------------------------------------
33738      -- No MPA option is assigned.
33739 
33740 
33741 END IF;
33742 END IF;
33743 --
33744 
33745 --
33746 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33747    trace
33748       (p_msg      => 'END of AcctLineType_201'
33749       ,p_level    => C_LEVEL_PROCEDURE
33750       ,p_module   => l_log_module);
33751 END IF;
33752 --
33753 EXCEPTION
33754   WHEN xla_exceptions_pkg.application_exception THEN
33755       RAISE;
33756   WHEN OTHERS THEN
33757        xla_exceptions_pkg.raise_message
33758            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_201');
33759 END AcctLineType_201;
33760 --
33761 
33762 ---------------------------------------
33763 --
33764 -- PRIVATE FUNCTION
33765 --         AcctLineType_202
33766 --
33767 ---------------------------------------
33768 PROCEDURE AcctLineType_202 (
33769   p_application_id        IN NUMBER
33770  ,p_event_id              IN NUMBER
33771  ,p_calculate_acctd_flag  IN VARCHAR2
33772  ,p_calculate_g_l_flag    IN VARCHAR2
33773  ,p_actual_flag           IN OUT VARCHAR2
33774  ,p_balance_type_code     OUT VARCHAR2
33775  ,p_gain_or_loss_ref      OUT VARCHAR2
33776  
33777 --Period Close Date
33778  , p_source_1            IN DATE
33779 --Bonus Depreciation Expense Account
33780  , p_source_2            IN VARCHAR2
33781 --Generated Code Combination Identifier
33782  , p_source_3            IN NUMBER
33783 --Expense Account Code Combination Identifier
33784  , p_source_29            IN NUMBER
33785 --Adjustment Type
33786  , p_source_35            IN VARCHAR2
33787 --Transaction Header Identifier
33788  , p_source_36            IN NUMBER
33789 --Adjustment Line Identifier
33790  , p_source_37            IN NUMBER
33791 --Distribution Type Code
33792  , p_source_38            IN VARCHAR2
33793 --Entered Amount
33794  , p_source_39            IN NUMBER
33795 --Currency Code
33796  , p_source_40            IN VARCHAR2
33797 )
33798 IS
33799 
33800 l_component_type              VARCHAR2(80);
33801 l_component_code              VARCHAR2(30);
33802 l_component_type_code         VARCHAR2(1);
33803 l_component_appl_id           INTEGER;
33804 l_amb_context_code            VARCHAR2(30);
33805 l_entity_code                 VARCHAR2(30);
33806 l_event_class_code            VARCHAR2(30);
33807 l_ae_header_id                NUMBER;
33808 l_event_type_code             VARCHAR2(30);
33809 l_line_definition_code        VARCHAR2(30);
33810 l_line_definition_owner_code  VARCHAR2(1);
33811 --
33812 -- adr variables
33813 l_segment                     VARCHAR2(30);
33814 l_ccid                        NUMBER;
33815 l_adr_transaction_coa_id      NUMBER;
33816 l_adr_accounting_coa_id       NUMBER;
33817 l_adr_flexfield_segment_code  VARCHAR2(30);
33818 l_adr_flex_value_set_id       NUMBER;
33819 l_adr_value_type_code         VARCHAR2(30);
33820 l_adr_value_combination_id    NUMBER;
33821 l_adr_value_segment_code      VARCHAR2(30);
33822 
33823 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
33824 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
33825 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
33826 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
33827 
33828 -- 4262811 Variables ------------------------------------------------------------------------------------------
33829 l_entered_amt_idx             NUMBER;
33833 l_tmp_amt                     NUMBER;
33830 l_accted_amt_idx              NUMBER;
33831 l_acc_rev_flag                VARCHAR2(1);
33832 l_accrual_line_num            NUMBER;
33834 l_acc_rev_natural_side_code   VARCHAR2(1);
33835 
33836 l_num_entries                 NUMBER;
33837 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
33838 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
33839 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
33840 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
33841 l_recog_line_1                NUMBER;
33842 l_recog_line_2                NUMBER;
33843 
33844 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
33845 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
33846 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
33847 
33848 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
33849 
33850 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
33851 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
33852 
33853 ---------------------------------------------------------------------------------------------------------------
33854 
33855 
33856 --
33857 -- bulk performance
33858 --
33859 l_balance_type_code           VARCHAR2(1);
33860 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
33861 l_log_module                  VARCHAR2(240);
33862 
33863 --
33864 -- Upgrade strategy
33865 --
33866 l_actual_upg_option           VARCHAR2(1);
33867 l_enc_upg_option           VARCHAR2(1);
33868 
33869 --
33870 BEGIN
33871 --
33872 IF g_log_enabled THEN
33873       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_202';
33874 END IF;
33875 --
33876 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33877 
33878       trace
33879          (p_msg      => 'BEGIN of AcctLineType_202'
33880          ,p_level    => C_LEVEL_PROCEDURE
33881          ,p_module   => l_log_module);
33882 
33883 END IF;
33884 --
33885 l_component_type             := 'AMB_JLT';
33886 l_component_code             := 'FA_CAP_BONUS_EXP';
33887 l_component_type_code        := 'S';
33888 l_component_appl_id          :=  140;
33889 l_amb_context_code           := 'DEFAULT';
33890 l_entity_code                := 'TRANSACTIONS';
33891 l_event_class_code           := 'CAPITALIZATION';
33892 l_event_type_code            := 'CAPITALIZATION';
33893 l_line_definition_owner_code := 'S';
33894 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CAPITA3';
33895 --
33896 l_balance_type_code          := 'A';
33897 l_segment                     := NULL;
33898 l_ccid                        := NULL;
33899 l_adr_transaction_coa_id      := NULL;
33900 l_adr_accounting_coa_id       := NULL;
33901 l_adr_flexfield_segment_code  := NULL;
33902 l_adr_flex_value_set_id       := NULL;
33903 l_adr_value_type_code         := NULL;
33904 l_adr_value_combination_id    := NULL;
33905 l_adr_value_segment_code      := NULL;
33906 
33907 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
33908 l_bflow_class_code           := '';    -- 4219869 Business Flow
33909 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
33910 l_budgetary_control_flag     := 'N';
33911 
33912 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
33913 l_bflow_applied_to_amt       := NULL; -- 5132302
33914 l_entered_amt_idx            := NULL;          -- 4262811
33915 l_accted_amt_idx             := NULL;          -- 4262811
33916 l_acc_rev_flag               := NULL;          -- 4262811
33917 l_accrual_line_num           := NULL;          -- 4262811
33918 l_tmp_amt                    := NULL;          -- 4262811
33919 --
33920  
33921 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
33922     l_balance_type_code <> 'B' THEN
33923 IF NVL(p_source_35,'
33924 ') =  'BONUS EXPENSE'
33925  THEN 
33926 
33927    --
33928    XLA_AE_LINES_PKG.SetNewLine;
33929 
33930    p_balance_type_code          := l_balance_type_code;
33931    -- set the flag so later we will know whether the gain loss line needs to be created
33932    
33933    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
33934      p_actual_flag :='A';
33935    END IF;
33936 
33937    --
33938    -- bulk performance
33939    --
33940    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
33941                                       p_header_num   => 0); -- 4262811
33942    --
33943    -- set accounting line options
33944    --
33945    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
33946            p_natural_side_code          => 'D'
33947          , p_gain_or_loss_flag          => 'N'
33948          , p_gl_transfer_mode_code      => 'S'
33949          , p_acct_entry_type_code       => 'A'
33950          , p_switch_side_flag           => 'Y'
33951          , p_merge_duplicate_code       => 'N'
33952          );
33953    --
33954    l_acc_rev_natural_side_code := 'C';  -- 4262811
33955    -- 
33956    --
33957    -- set accounting line type info
33958    --
33959    xla_ae_lines_pkg.SetAcctLineType
33960       (p_component_type             => l_component_type
33961       ,p_event_type_code            => l_event_type_code
33962       ,p_line_definition_owner_code => l_line_definition_owner_code
33963       ,p_line_definition_code       => l_line_definition_code
33964       ,p_accounting_line_code       => l_component_code
33965       ,p_accounting_line_type_code  => l_component_type_code
33966       ,p_accounting_line_appl_id    => l_component_appl_id
33967       ,p_amb_context_code           => l_amb_context_code
33968       ,p_entity_code                => l_entity_code
33972    --
33969       ,p_event_class_code           => l_event_class_code);
33970    --
33971    -- set accounting class
33973    xla_ae_lines_pkg.SetAcctClass(
33974            p_accounting_class_code  => 'EXPENSE'
33975          , p_ae_header_id           => l_ae_header_id
33976          );
33977 
33978    --
33979    -- set rounding class
33980    --
33981    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
33982                       'EXPENSE';
33983 
33984    --
33985    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
33986    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
33987    --
33988    -- bulk performance
33989    --
33990    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
33991 
33992    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
33993       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
33994 
33995    -- 4955764
33996    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33997       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
33998 
33999    -- 4458381 Public Sector Enh
34000    
34001    --
34002    -- set accounting attributes for the line type
34003    --
34004    l_entered_amt_idx := 4;
34005    l_accted_amt_idx  := 6;
34006    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
34007    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
34008    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
34009    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
34010    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
34011    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
34012    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
34013    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
34014    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
34015    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
34016    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
34017    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
34018    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
34019 
34020    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
34021    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
34022 
34023    ---------------------------------------------------------------------------------------------------------------
34024    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
34025    ---------------------------------------------------------------------------------------------------------------
34026    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
34027 
34028    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34029    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34030 
34031    IF xla_accounting_cache_pkg.GetValueChar
34032          (p_source_code         => 'LEDGER_CATEGORY_CODE'
34033          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
34034    AND l_bflow_method_code = 'PRIOR_ENTRY'
34035 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
34036    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
34037          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
34038        )
34039    THEN
34040          xla_ae_lines_pkg.BflowUpgEntry
34041            (p_business_method_code    => l_bflow_method_code
34042            ,p_business_class_code     => l_bflow_class_code
34043            ,p_balance_type            => l_balance_type_code);
34044    ELSE
34045       NULL;
34046 -- No business flow processing for business flow method of NONE.
34047    END IF;
34048 
34049    --
34050    -- call analytical criteria
34051    --
34052    
34053    --
34054    -- call description
34055    --
34056    
34057 xla_ae_lines_pkg.SetLineDescription(
34058    p_ae_header_id => l_ae_header_id
34059   ,p_description  => Description_17 (
34060      p_application_id         => p_application_id
34061    , p_ae_header_id           => l_ae_header_id 
34062 , p_source_1 => p_source_1
34063    )
34064 );
34065 
34066 
34067    --
34068    -- call ADRs
34069    -- Bug 4922099
34070    --
34071    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34072         (NVL(l_actual_upg_option, 'N') = 'O') OR
34073         (NVL(l_enc_upg_option, 'N') = 'O')
34074       )
34075    THEN
34076    NULL;
34077    --
34078    --
34079    
34080   l_ccid := AcctDerRule_175(
34081            p_application_id           => p_application_id
34082          , p_ae_header_id             => l_ae_header_id 
34083 , p_source_3 => p_source_3
34084 , p_source_29 => p_source_29
34085          , x_transaction_coa_id       => l_adr_transaction_coa_id
34086          , x_accounting_coa_id        => l_adr_accounting_coa_id
34087          , x_value_type_code          => l_adr_value_type_code
34088          , p_side                     => 'NA'
34089    );
34090 
34091    xla_ae_lines_pkg.set_ccid(
34092     p_code_combination_id          => l_ccid
34093   , p_value_type_code              => l_adr_value_type_code
34094   , p_transaction_coa_id           => l_adr_transaction_coa_id
34095   , p_accounting_coa_id            => l_adr_accounting_coa_id
34096   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
34097   , p_adr_type_code                => 'S'
34098   , p_component_type               => l_component_type
34102   , p_amb_context_code             => l_amb_context_code
34099   , p_component_code               => l_component_code
34100   , p_component_type_code          => l_component_type_code
34101   , p_component_appl_id            => l_component_appl_id
34103   , p_side                         => 'NA'
34104   );
34105 
34106 
34107    l_segment := AcctDerRule_143(
34108            p_application_id           => p_application_id
34109          , p_ae_header_id             => l_ae_header_id 
34110 , p_source_2 => p_source_2
34111 , p_source_3 => p_source_3
34112          , x_transaction_coa_id       => l_adr_transaction_coa_id
34113          , x_accounting_coa_id        => l_adr_accounting_coa_id
34114          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
34115          , x_flex_value_set_id        => l_adr_flex_value_set_id
34116          , x_value_type_code          => l_adr_value_type_code
34117          , x_value_combination_id     => l_adr_value_combination_id
34118          , x_value_segment_code       => l_adr_value_segment_code
34119          , p_side                     => 'NA'
34120          , p_override_seg_flag        => 'Y'
34121    );
34122 
34123    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
34124 
34125       xla_ae_lines_pkg.set_segment(
34126           p_to_segment_code         => 'GL_ACCOUNT'
34127         , p_segment_value           => l_segment
34128         , p_from_segment_code       => l_adr_value_segment_code
34129         , p_from_combination_id     => l_adr_value_combination_id
34130         , p_value_type_code         => l_adr_value_type_code
34131         , p_transaction_coa_id      => l_adr_transaction_coa_id
34132         , p_accounting_coa_id       => l_adr_accounting_coa_id
34133         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
34134         , p_flex_value_set_id       => l_adr_flex_value_set_id
34135         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
34136         , p_adr_type_code           => 'S'
34137         , p_component_type          => l_component_type
34138         , p_component_code          => l_component_code
34139         , p_component_type_code     => l_component_type_code
34140         , p_component_appl_id       => l_component_appl_id
34141         , p_amb_context_code        => l_amb_context_code
34142         , p_entity_code             => 'TRANSACTIONS'
34143         , p_event_class_code        => 'CAPITALIZATION'
34144         , p_side                    => 'NA'
34145         );
34146 
34147   END IF;
34148 
34149    --
34150    --
34151    END IF;
34152    --
34153    -- Bug 4922099
34154    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
34155           (NVL(l_enc_upg_option, 'N') = 'O')
34156         ) AND
34157         (l_bflow_method_code = 'PRIOR_ENTRY')
34158       )
34159    THEN
34160       IF
34161       --
34162       1 = 2
34163       --
34164       THEN
34165       xla_accounting_err_pkg.build_message
34166                                     (p_appli_s_name            => 'XLA'
34167                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34168                                     ,p_token_1                 => 'LINE_NUMBER'
34169                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
34170                                     ,p_token_2                 => 'LINE_TYPE_NAME'
34171                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
34172                                                                              l_component_type
34173                                                                             ,l_component_code
34174                                                                             ,l_component_type_code
34175                                                                             ,l_component_appl_id
34176                                                                             ,l_amb_context_code
34177                                                                             ,l_entity_code
34178                                                                             ,l_event_class_code
34179                                                                            )
34180                                     ,p_token_3                 => 'OWNER'
34181                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
34182                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
34183                                                                           ,p_lookup_code    => l_component_type_code
34184                                                                          )
34185                                     ,p_token_4                 => 'PRODUCT_NAME'
34186                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
34187                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
34188                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
34189                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
34190                                     ,p_ae_header_id            =>  NULL
34191                                        );
34192 
34193         IF (C_LEVEL_ERROR>= g_log_level) THEN
34194                  trace
34195                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34196                       ,p_level    => C_LEVEL_ERROR
34197                       ,p_module   => l_log_module);
34198         END IF;
34199       END IF;
34200    END IF;
34201    --
34202    --
34203    ------------------------------------------------------------------------------------------------
34204    -- 4219869 Business Flow
34205    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
34209 
34206    -- Prior Entry.  Currently, the following code is always generated.
34207    ------------------------------------------------------------------------------------------------
34208    XLA_AE_LINES_PKG.ValidateCurrentLine;
34210    ------------------------------------------------------------------------------------
34211    -- 4219869 Business Flow
34212    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
34213    ------------------------------------------------------------------------------------
34214    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34215 
34216    ----------------------------------------------------------------------------------
34217    -- 4219869 Business Flow
34218    -- Update journal entry status -- Need to generate this within IF <condition>
34219    ----------------------------------------------------------------------------------
34220    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34221          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
34222          ,p_balance_type_code => l_balance_type_code
34223          );
34224 
34225    -------------------------------------------------------------------------------------------
34226    -- 4262811 - Generate the Accrual Reversal lines
34227    -------------------------------------------------------------------------------------------
34228    BEGIN
34229       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
34230                               (g_array_event(p_event_id).array_value_num('header_index'));
34231       IF l_acc_rev_flag IS NULL THEN
34232          l_acc_rev_flag := 'N';
34233       END IF;
34234    EXCEPTION
34235       WHEN OTHERS THEN
34236          l_acc_rev_flag := 'N';
34237    END;
34238    --
34239    IF (l_acc_rev_flag = 'Y') THEN
34240 
34241        -- 4645092  ------------------------------------------------------------------------------
34242        -- To allow MPA report to determine if it should generate report process
34243        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
34244        ------------------------------------------------------------------------------------------
34245 
34246        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
34247        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
34248    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
34249    -- call ADRs
34250    -- Bug 4922099
34251    --
34252    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34253         (NVL(l_actual_upg_option, 'N') = 'O') OR
34254         (NVL(l_enc_upg_option, 'N') = 'O')
34255       )
34256    THEN
34257    NULL;
34258    --
34259    --
34260    
34261   l_ccid := AcctDerRule_175(
34262            p_application_id           => p_application_id
34263          , p_ae_header_id             => l_ae_header_id 
34264 , p_source_3 => p_source_3
34265 , p_source_29 => p_source_29
34266          , x_transaction_coa_id       => l_adr_transaction_coa_id
34267          , x_accounting_coa_id        => l_adr_accounting_coa_id
34268          , x_value_type_code          => l_adr_value_type_code
34269          , p_side                     => 'NA'
34270    );
34271 
34272    xla_ae_lines_pkg.set_ccid(
34273     p_code_combination_id          => l_ccid
34274   , p_value_type_code              => l_adr_value_type_code
34275   , p_transaction_coa_id           => l_adr_transaction_coa_id
34276   , p_accounting_coa_id            => l_adr_accounting_coa_id
34277   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
34278   , p_adr_type_code                => 'S'
34279   , p_component_type               => l_component_type
34280   , p_component_code               => l_component_code
34281   , p_component_type_code          => l_component_type_code
34282   , p_component_appl_id            => l_component_appl_id
34283   , p_amb_context_code             => l_amb_context_code
34284   , p_side                         => 'NA'
34285   );
34286 
34287 
34288    l_segment := AcctDerRule_143(
34289            p_application_id           => p_application_id
34290          , p_ae_header_id             => l_ae_header_id 
34291 , p_source_2 => p_source_2
34292 , p_source_3 => p_source_3
34293          , x_transaction_coa_id       => l_adr_transaction_coa_id
34294          , x_accounting_coa_id        => l_adr_accounting_coa_id
34295          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
34296          , x_flex_value_set_id        => l_adr_flex_value_set_id
34297          , x_value_type_code          => l_adr_value_type_code
34298          , x_value_combination_id     => l_adr_value_combination_id
34299          , x_value_segment_code       => l_adr_value_segment_code
34300          , p_side                     => 'NA'
34301          , p_override_seg_flag        => 'Y'
34302    );
34303 
34304    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
34305 
34306       xla_ae_lines_pkg.set_segment(
34307           p_to_segment_code         => 'GL_ACCOUNT'
34308         , p_segment_value           => l_segment
34309         , p_from_segment_code       => l_adr_value_segment_code
34310         , p_from_combination_id     => l_adr_value_combination_id
34311         , p_value_type_code         => l_adr_value_type_code
34312         , p_transaction_coa_id      => l_adr_transaction_coa_id
34313         , p_accounting_coa_id       => l_adr_accounting_coa_id
34314         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
34315         , p_flex_value_set_id       => l_adr_flex_value_set_id
34316         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
34317         , p_adr_type_code           => 'S'
34318         , p_component_type          => l_component_type
34319         , p_component_code          => l_component_code
34320         , p_component_type_code     => l_component_type_code
34321         , p_component_appl_id       => l_component_appl_id
34322         , p_amb_context_code        => l_amb_context_code
34326         );
34323         , p_entity_code             => 'TRANSACTIONS'
34324         , p_event_class_code        => 'CAPITALIZATION'
34325         , p_side                    => 'NA'
34327 
34328   END IF;
34329 
34330    --
34331    --
34332    END IF;
34333 
34334        --
34335        -- Update the line information that should be overwritten
34336        --
34337        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
34338                                          p_header_num   => 1);
34339        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
34340 
34341        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
34342 
34343        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
34344           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
34345        END IF;
34346 
34347       --
34348       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
34349       --
34350       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
34351           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
34352       ELSE
34353           ---------------------------------------------------------------------------------------------------
34354           -- 4262811a Switch Sign
34355           ---------------------------------------------------------------------------------------------------
34356           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
34357           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34358                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34359           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34360                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34361           -- 5132302
34362           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
34363                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34364 
34365       END IF;
34366 
34367       -- 4955764
34368       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
34369       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
34370 
34371 
34372       XLA_AE_LINES_PKG.ValidateCurrentLine;
34373       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34374 
34375       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34376                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
34377                ,p_balance_type_code => l_balance_type_code);
34378 
34379    END IF;
34380 
34381    -----------------------------------------------------------------------------------------
34382    -- 4262811 Multiperiod Accounting
34383    -----------------------------------------------------------------------------------------
34384      -- No MPA option is assigned.
34385 
34386 
34387 END IF;
34388 END IF;
34389 --
34390 
34391 --
34392 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
34393    trace
34394       (p_msg      => 'END of AcctLineType_202'
34395       ,p_level    => C_LEVEL_PROCEDURE
34396       ,p_module   => l_log_module);
34397 END IF;
34398 --
34399 EXCEPTION
34400   WHEN xla_exceptions_pkg.application_exception THEN
34401       RAISE;
34402   WHEN OTHERS THEN
34403        xla_exceptions_pkg.raise_message
34404            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_202');
34405 END AcctLineType_202;
34406 --
34407 
34408 ---------------------------------------
34409 --
34410 -- PRIVATE FUNCTION
34411 --         AcctLineType_203
34412 --
34413 ---------------------------------------
34414 PROCEDURE AcctLineType_203 (
34415   p_application_id        IN NUMBER
34416  ,p_event_id              IN NUMBER
34417  ,p_calculate_acctd_flag  IN VARCHAR2
34418  ,p_calculate_g_l_flag    IN VARCHAR2
34419  ,p_actual_flag           IN OUT VARCHAR2
34420  ,p_balance_type_code     OUT VARCHAR2
34421  ,p_gain_or_loss_ref      OUT VARCHAR2
34422  
34423 --Period Close Date
34424  , p_source_1            IN DATE
34425 --Generated Code Combination Identifier
34426  , p_source_3            IN NUMBER
34427 --Bonus Reserve Account
34428  , p_source_4            IN VARCHAR2
34429 --Generated Offset Code Combination Identifier
34430  , p_source_17            IN NUMBER
34431 --Expense Account Code Combination Identifier
34432  , p_source_29            IN NUMBER
34433 --Default Code Combination Identifier
34434  , p_source_30            IN NUMBER
34435 --Adjustment Type
34436  , p_source_35            IN VARCHAR2
34437 --Transaction Header Identifier
34438  , p_source_36            IN NUMBER
34439 --Adjustment Line Identifier
34440  , p_source_37            IN NUMBER
34441 --Distribution Type Code
34442  , p_source_38            IN VARCHAR2
34443 --Entered Amount
34444  , p_source_39            IN NUMBER
34445 --Currency Code
34446  , p_source_40            IN VARCHAR2
34447 )
34448 IS
34449 
34450 l_component_type              VARCHAR2(80);
34451 l_component_code              VARCHAR2(30);
34452 l_component_type_code         VARCHAR2(1);
34453 l_component_appl_id           INTEGER;
34454 l_amb_context_code            VARCHAR2(30);
34455 l_entity_code                 VARCHAR2(30);
34456 l_event_class_code            VARCHAR2(30);
34457 l_ae_header_id                NUMBER;
34458 l_event_type_code             VARCHAR2(30);
34462 -- adr variables
34459 l_line_definition_code        VARCHAR2(30);
34460 l_line_definition_owner_code  VARCHAR2(1);
34461 --
34463 l_segment                     VARCHAR2(30);
34464 l_ccid                        NUMBER;
34465 l_adr_transaction_coa_id      NUMBER;
34466 l_adr_accounting_coa_id       NUMBER;
34467 l_adr_flexfield_segment_code  VARCHAR2(30);
34468 l_adr_flex_value_set_id       NUMBER;
34469 l_adr_value_type_code         VARCHAR2(30);
34470 l_adr_value_combination_id    NUMBER;
34471 l_adr_value_segment_code      VARCHAR2(30);
34472 
34473 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
34474 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
34475 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
34476 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
34477 
34478 -- 4262811 Variables ------------------------------------------------------------------------------------------
34479 l_entered_amt_idx             NUMBER;
34480 l_accted_amt_idx              NUMBER;
34481 l_acc_rev_flag                VARCHAR2(1);
34482 l_accrual_line_num            NUMBER;
34483 l_tmp_amt                     NUMBER;
34484 l_acc_rev_natural_side_code   VARCHAR2(1);
34485 
34486 l_num_entries                 NUMBER;
34487 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
34488 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
34489 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
34490 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
34491 l_recog_line_1                NUMBER;
34492 l_recog_line_2                NUMBER;
34493 
34494 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
34495 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
34496 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
34497 
34498 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
34499 
34500 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
34501 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
34502 
34503 ---------------------------------------------------------------------------------------------------------------
34504 
34505 
34506 --
34507 -- bulk performance
34508 --
34509 l_balance_type_code           VARCHAR2(1);
34510 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
34511 l_log_module                  VARCHAR2(240);
34512 
34513 --
34514 -- Upgrade strategy
34515 --
34516 l_actual_upg_option           VARCHAR2(1);
34517 l_enc_upg_option           VARCHAR2(1);
34518 
34519 --
34520 BEGIN
34521 --
34522 IF g_log_enabled THEN
34523       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_203';
34524 END IF;
34525 --
34526 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
34527 
34528       trace
34529          (p_msg      => 'BEGIN of AcctLineType_203'
34530          ,p_level    => C_LEVEL_PROCEDURE
34531          ,p_module   => l_log_module);
34532 
34533 END IF;
34534 --
34535 l_component_type             := 'AMB_JLT';
34536 l_component_code             := 'FA_CAP_BONUS_RESERVE';
34537 l_component_type_code        := 'S';
34538 l_component_appl_id          :=  140;
34539 l_amb_context_code           := 'DEFAULT';
34540 l_entity_code                := 'TRANSACTIONS';
34541 l_event_class_code           := 'CAPITALIZATION';
34542 l_event_type_code            := 'CAPITALIZATION';
34543 l_line_definition_owner_code := 'S';
34544 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CAPITA3';
34545 --
34546 l_balance_type_code          := 'A';
34547 l_segment                     := NULL;
34548 l_ccid                        := NULL;
34549 l_adr_transaction_coa_id      := NULL;
34550 l_adr_accounting_coa_id       := NULL;
34551 l_adr_flexfield_segment_code  := NULL;
34552 l_adr_flex_value_set_id       := NULL;
34553 l_adr_value_type_code         := NULL;
34554 l_adr_value_combination_id    := NULL;
34555 l_adr_value_segment_code      := NULL;
34556 
34557 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
34558 l_bflow_class_code           := '';    -- 4219869 Business Flow
34559 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
34560 l_budgetary_control_flag     := 'N';
34561 
34562 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
34563 l_bflow_applied_to_amt       := NULL; -- 5132302
34564 l_entered_amt_idx            := NULL;          -- 4262811
34565 l_accted_amt_idx             := NULL;          -- 4262811
34566 l_acc_rev_flag               := NULL;          -- 4262811
34567 l_accrual_line_num           := NULL;          -- 4262811
34568 l_tmp_amt                    := NULL;          -- 4262811
34569 --
34570  
34571 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
34572     l_balance_type_code <> 'B' THEN
34573 IF NVL(p_source_35,'
34574 ') =  'BONUS EXPENSE'
34575  THEN 
34576 
34577    --
34578    XLA_AE_LINES_PKG.SetNewLine;
34579 
34580    p_balance_type_code          := l_balance_type_code;
34581    -- set the flag so later we will know whether the gain loss line needs to be created
34582    
34583    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
34584      p_actual_flag :='A';
34585    END IF;
34586 
34587    --
34588    -- bulk performance
34589    --
34590    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
34591                                       p_header_num   => 0); -- 4262811
34592    --
34593    -- set accounting line options
34594    --
34595    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
34596            p_natural_side_code          => 'C'
34600          , p_switch_side_flag           => 'Y'
34597          , p_gain_or_loss_flag          => 'N'
34598          , p_gl_transfer_mode_code      => 'S'
34599          , p_acct_entry_type_code       => 'A'
34601          , p_merge_duplicate_code       => 'N'
34602          );
34603    --
34604    l_acc_rev_natural_side_code := 'D';  -- 4262811
34605    -- 
34606    --
34607    -- set accounting line type info
34608    --
34609    xla_ae_lines_pkg.SetAcctLineType
34610       (p_component_type             => l_component_type
34611       ,p_event_type_code            => l_event_type_code
34612       ,p_line_definition_owner_code => l_line_definition_owner_code
34613       ,p_line_definition_code       => l_line_definition_code
34614       ,p_accounting_line_code       => l_component_code
34615       ,p_accounting_line_type_code  => l_component_type_code
34616       ,p_accounting_line_appl_id    => l_component_appl_id
34617       ,p_amb_context_code           => l_amb_context_code
34618       ,p_entity_code                => l_entity_code
34619       ,p_event_class_code           => l_event_class_code);
34620    --
34621    -- set accounting class
34622    --
34623    xla_ae_lines_pkg.SetAcctClass(
34624            p_accounting_class_code  => 'ASSET'
34625          , p_ae_header_id           => l_ae_header_id
34626          );
34627 
34628    --
34629    -- set rounding class
34630    --
34631    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
34632                       'ASSET';
34633 
34634    --
34635    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
34636    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
34637    --
34638    -- bulk performance
34639    --
34640    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
34641 
34642    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
34643       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
34644 
34645    -- 4955764
34646    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
34647       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
34648 
34649    -- 4458381 Public Sector Enh
34650    
34651    --
34652    -- set accounting attributes for the line type
34653    --
34654    l_entered_amt_idx := 4;
34655    l_accted_amt_idx  := 6;
34656    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
34657    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
34658    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
34659    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
34660    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
34661    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
34662    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
34663    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
34664    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
34665    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
34666    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
34667    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
34668    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
34669 
34670    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
34671    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
34672 
34673    ---------------------------------------------------------------------------------------------------------------
34674    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
34675    ---------------------------------------------------------------------------------------------------------------
34676    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
34677 
34678    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34679    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34680 
34681    IF xla_accounting_cache_pkg.GetValueChar
34682          (p_source_code         => 'LEDGER_CATEGORY_CODE'
34683          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
34684    AND l_bflow_method_code = 'PRIOR_ENTRY'
34685 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
34686    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
34687          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
34688        )
34689    THEN
34690          xla_ae_lines_pkg.BflowUpgEntry
34691            (p_business_method_code    => l_bflow_method_code
34692            ,p_business_class_code     => l_bflow_class_code
34693            ,p_balance_type            => l_balance_type_code);
34694    ELSE
34695       NULL;
34696 -- No business flow processing for business flow method of NONE.
34697    END IF;
34698 
34699    --
34700    -- call analytical criteria
34701    --
34702    
34703    --
34704    -- call description
34705    --
34706    
34707 xla_ae_lines_pkg.SetLineDescription(
34708    p_ae_header_id => l_ae_header_id
34709   ,p_description  => Description_18 (
34710      p_application_id         => p_application_id
34711    , p_ae_header_id           => l_ae_header_id 
34712 , p_source_1 => p_source_1
34713    )
34714 );
34715 
34716 
34717    --
34718    -- call ADRs
34719    -- Bug 4922099
34720    --
34721    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34722         (NVL(l_actual_upg_option, 'N') = 'O') OR
34723         (NVL(l_enc_upg_option, 'N') = 'O')
34724       )
34725    THEN
34729    
34726    NULL;
34727    --
34728    --
34730   l_ccid := AcctDerRule_174(
34731            p_application_id           => p_application_id
34732          , p_ae_header_id             => l_ae_header_id 
34733 , p_source_3 => p_source_3
34734 , p_source_17 => p_source_17
34735 , p_source_30 => p_source_30
34736          , x_transaction_coa_id       => l_adr_transaction_coa_id
34737          , x_accounting_coa_id        => l_adr_accounting_coa_id
34738          , x_value_type_code          => l_adr_value_type_code
34739          , p_side                     => 'NA'
34740    );
34741 
34742    xla_ae_lines_pkg.set_ccid(
34743     p_code_combination_id          => l_ccid
34744   , p_value_type_code              => l_adr_value_type_code
34745   , p_transaction_coa_id           => l_adr_transaction_coa_id
34746   , p_accounting_coa_id            => l_adr_accounting_coa_id
34747   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
34748   , p_adr_type_code                => 'S'
34749   , p_component_type               => l_component_type
34750   , p_component_code               => l_component_code
34751   , p_component_type_code          => l_component_type_code
34752   , p_component_appl_id            => l_component_appl_id
34753   , p_amb_context_code             => l_amb_context_code
34754   , p_side                         => 'NA'
34755   );
34756 
34757 
34758    l_segment := AcctDerRule_144(
34759            p_application_id           => p_application_id
34760          , p_ae_header_id             => l_ae_header_id 
34761 , p_source_3 => p_source_3
34762 , p_source_4 => p_source_4
34763          , x_transaction_coa_id       => l_adr_transaction_coa_id
34764          , x_accounting_coa_id        => l_adr_accounting_coa_id
34765          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
34766          , x_flex_value_set_id        => l_adr_flex_value_set_id
34767          , x_value_type_code          => l_adr_value_type_code
34768          , x_value_combination_id     => l_adr_value_combination_id
34769          , x_value_segment_code       => l_adr_value_segment_code
34770          , p_side                     => 'NA'
34771          , p_override_seg_flag        => 'Y'
34772    );
34773 
34774    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
34775 
34776       xla_ae_lines_pkg.set_segment(
34777           p_to_segment_code         => 'GL_ACCOUNT'
34778         , p_segment_value           => l_segment
34779         , p_from_segment_code       => l_adr_value_segment_code
34780         , p_from_combination_id     => l_adr_value_combination_id
34781         , p_value_type_code         => l_adr_value_type_code
34782         , p_transaction_coa_id      => l_adr_transaction_coa_id
34783         , p_accounting_coa_id       => l_adr_accounting_coa_id
34784         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
34785         , p_flex_value_set_id       => l_adr_flex_value_set_id
34786         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
34787         , p_adr_type_code           => 'S'
34788         , p_component_type          => l_component_type
34789         , p_component_code          => l_component_code
34790         , p_component_type_code     => l_component_type_code
34791         , p_component_appl_id       => l_component_appl_id
34792         , p_amb_context_code        => l_amb_context_code
34793         , p_entity_code             => 'TRANSACTIONS'
34794         , p_event_class_code        => 'CAPITALIZATION'
34795         , p_side                    => 'NA'
34796         );
34797 
34798   END IF;
34799 
34800    l_segment := AcctDerRule_168(
34801            p_application_id           => p_application_id
34802          , p_ae_header_id             => l_ae_header_id 
34803 , p_source_3 => p_source_3
34804 , p_source_29 => p_source_29
34805          , x_transaction_coa_id       => l_adr_transaction_coa_id
34806          , x_accounting_coa_id        => l_adr_accounting_coa_id
34807          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
34808          , x_flex_value_set_id        => l_adr_flex_value_set_id
34809          , x_value_type_code          => l_adr_value_type_code
34810          , x_value_combination_id     => l_adr_value_combination_id
34811          , x_value_segment_code       => l_adr_value_segment_code
34812          , p_side                     => 'NA'
34813          , p_override_seg_flag        => 'Y'
34814    );
34815 
34816    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
34817 
34818       xla_ae_lines_pkg.set_segment(
34819           p_to_segment_code         => 'GL_BALANCING'
34820         , p_segment_value           => l_segment
34821         , p_from_segment_code       => l_adr_value_segment_code
34822         , p_from_combination_id     => l_adr_value_combination_id
34823         , p_value_type_code         => l_adr_value_type_code
34824         , p_transaction_coa_id      => l_adr_transaction_coa_id
34825         , p_accounting_coa_id       => l_adr_accounting_coa_id
34826         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
34827         , p_flex_value_set_id       => l_adr_flex_value_set_id
34828         , p_adr_code                => 'FA_EXPENSE_ACCT'
34829         , p_adr_type_code           => 'S'
34830         , p_component_type          => l_component_type
34831         , p_component_code          => l_component_code
34832         , p_component_type_code     => l_component_type_code
34833         , p_component_appl_id       => l_component_appl_id
34834         , p_amb_context_code        => l_amb_context_code
34835         , p_entity_code             => 'TRANSACTIONS'
34836         , p_event_class_code        => 'CAPITALIZATION'
34837         , p_side                    => 'NA'
34838         );
34839 
34840   END IF;
34841 
34842    --
34843    --
34844    END IF;
34845    --
34846    -- Bug 4922099
34847    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
34851       )
34848           (NVL(l_enc_upg_option, 'N') = 'O')
34849         ) AND
34850         (l_bflow_method_code = 'PRIOR_ENTRY')
34852    THEN
34853       IF
34854       --
34855       1 = 2
34856       --
34857       THEN
34858       xla_accounting_err_pkg.build_message
34859                                     (p_appli_s_name            => 'XLA'
34860                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34861                                     ,p_token_1                 => 'LINE_NUMBER'
34862                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
34863                                     ,p_token_2                 => 'LINE_TYPE_NAME'
34864                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
34865                                                                              l_component_type
34866                                                                             ,l_component_code
34867                                                                             ,l_component_type_code
34868                                                                             ,l_component_appl_id
34869                                                                             ,l_amb_context_code
34870                                                                             ,l_entity_code
34871                                                                             ,l_event_class_code
34872                                                                            )
34873                                     ,p_token_3                 => 'OWNER'
34874                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
34875                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
34876                                                                           ,p_lookup_code    => l_component_type_code
34877                                                                          )
34878                                     ,p_token_4                 => 'PRODUCT_NAME'
34879                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
34880                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
34881                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
34882                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
34883                                     ,p_ae_header_id            =>  NULL
34884                                        );
34885 
34886         IF (C_LEVEL_ERROR>= g_log_level) THEN
34887                  trace
34888                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34889                       ,p_level    => C_LEVEL_ERROR
34890                       ,p_module   => l_log_module);
34891         END IF;
34892       END IF;
34893    END IF;
34894    --
34895    --
34896    ------------------------------------------------------------------------------------------------
34897    -- 4219869 Business Flow
34898    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
34899    -- Prior Entry.  Currently, the following code is always generated.
34900    ------------------------------------------------------------------------------------------------
34901    XLA_AE_LINES_PKG.ValidateCurrentLine;
34902 
34903    ------------------------------------------------------------------------------------
34904    -- 4219869 Business Flow
34905    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
34906    ------------------------------------------------------------------------------------
34907    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34908 
34909    ----------------------------------------------------------------------------------
34910    -- 4219869 Business Flow
34911    -- Update journal entry status -- Need to generate this within IF <condition>
34912    ----------------------------------------------------------------------------------
34913    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34914          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
34915          ,p_balance_type_code => l_balance_type_code
34916          );
34917 
34918    -------------------------------------------------------------------------------------------
34919    -- 4262811 - Generate the Accrual Reversal lines
34920    -------------------------------------------------------------------------------------------
34921    BEGIN
34922       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
34923                               (g_array_event(p_event_id).array_value_num('header_index'));
34924       IF l_acc_rev_flag IS NULL THEN
34925          l_acc_rev_flag := 'N';
34926       END IF;
34927    EXCEPTION
34928       WHEN OTHERS THEN
34929          l_acc_rev_flag := 'N';
34930    END;
34931    --
34932    IF (l_acc_rev_flag = 'Y') THEN
34933 
34934        -- 4645092  ------------------------------------------------------------------------------
34935        -- To allow MPA report to determine if it should generate report process
34936        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
34937        ------------------------------------------------------------------------------------------
34938 
34939        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
34940        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
34941    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
34942    -- call ADRs
34943    -- Bug 4922099
34944    --
34945    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34946         (NVL(l_actual_upg_option, 'N') = 'O') OR
34947         (NVL(l_enc_upg_option, 'N') = 'O')
34948       )
34949    THEN
34950    NULL;
34951    --
34952    --
34953    
34957 , p_source_3 => p_source_3
34954   l_ccid := AcctDerRule_174(
34955            p_application_id           => p_application_id
34956          , p_ae_header_id             => l_ae_header_id 
34958 , p_source_17 => p_source_17
34959 , p_source_30 => p_source_30
34960          , x_transaction_coa_id       => l_adr_transaction_coa_id
34961          , x_accounting_coa_id        => l_adr_accounting_coa_id
34962          , x_value_type_code          => l_adr_value_type_code
34963          , p_side                     => 'NA'
34964    );
34965 
34966    xla_ae_lines_pkg.set_ccid(
34967     p_code_combination_id          => l_ccid
34968   , p_value_type_code              => l_adr_value_type_code
34969   , p_transaction_coa_id           => l_adr_transaction_coa_id
34970   , p_accounting_coa_id            => l_adr_accounting_coa_id
34971   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
34972   , p_adr_type_code                => 'S'
34973   , p_component_type               => l_component_type
34974   , p_component_code               => l_component_code
34975   , p_component_type_code          => l_component_type_code
34976   , p_component_appl_id            => l_component_appl_id
34977   , p_amb_context_code             => l_amb_context_code
34978   , p_side                         => 'NA'
34979   );
34980 
34981 
34982    l_segment := AcctDerRule_144(
34983            p_application_id           => p_application_id
34984          , p_ae_header_id             => l_ae_header_id 
34985 , p_source_3 => p_source_3
34986 , p_source_4 => p_source_4
34987          , x_transaction_coa_id       => l_adr_transaction_coa_id
34988          , x_accounting_coa_id        => l_adr_accounting_coa_id
34989          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
34990          , x_flex_value_set_id        => l_adr_flex_value_set_id
34991          , x_value_type_code          => l_adr_value_type_code
34992          , x_value_combination_id     => l_adr_value_combination_id
34993          , x_value_segment_code       => l_adr_value_segment_code
34994          , p_side                     => 'NA'
34995          , p_override_seg_flag        => 'Y'
34996    );
34997 
34998    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
34999 
35000       xla_ae_lines_pkg.set_segment(
35001           p_to_segment_code         => 'GL_ACCOUNT'
35002         , p_segment_value           => l_segment
35003         , p_from_segment_code       => l_adr_value_segment_code
35004         , p_from_combination_id     => l_adr_value_combination_id
35005         , p_value_type_code         => l_adr_value_type_code
35006         , p_transaction_coa_id      => l_adr_transaction_coa_id
35007         , p_accounting_coa_id       => l_adr_accounting_coa_id
35008         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
35009         , p_flex_value_set_id       => l_adr_flex_value_set_id
35010         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
35011         , p_adr_type_code           => 'S'
35012         , p_component_type          => l_component_type
35013         , p_component_code          => l_component_code
35014         , p_component_type_code     => l_component_type_code
35015         , p_component_appl_id       => l_component_appl_id
35016         , p_amb_context_code        => l_amb_context_code
35017         , p_entity_code             => 'TRANSACTIONS'
35018         , p_event_class_code        => 'CAPITALIZATION'
35019         , p_side                    => 'NA'
35020         );
35021 
35022   END IF;
35023 
35024    l_segment := AcctDerRule_168(
35025            p_application_id           => p_application_id
35026          , p_ae_header_id             => l_ae_header_id 
35027 , p_source_3 => p_source_3
35028 , p_source_29 => p_source_29
35029          , x_transaction_coa_id       => l_adr_transaction_coa_id
35030          , x_accounting_coa_id        => l_adr_accounting_coa_id
35031          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
35032          , x_flex_value_set_id        => l_adr_flex_value_set_id
35033          , x_value_type_code          => l_adr_value_type_code
35034          , x_value_combination_id     => l_adr_value_combination_id
35035          , x_value_segment_code       => l_adr_value_segment_code
35036          , p_side                     => 'NA'
35037          , p_override_seg_flag        => 'Y'
35038    );
35039 
35040    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
35041 
35042       xla_ae_lines_pkg.set_segment(
35043           p_to_segment_code         => 'GL_BALANCING'
35044         , p_segment_value           => l_segment
35045         , p_from_segment_code       => l_adr_value_segment_code
35046         , p_from_combination_id     => l_adr_value_combination_id
35047         , p_value_type_code         => l_adr_value_type_code
35048         , p_transaction_coa_id      => l_adr_transaction_coa_id
35049         , p_accounting_coa_id       => l_adr_accounting_coa_id
35050         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
35051         , p_flex_value_set_id       => l_adr_flex_value_set_id
35052         , p_adr_code                => 'FA_EXPENSE_ACCT'
35053         , p_adr_type_code           => 'S'
35054         , p_component_type          => l_component_type
35055         , p_component_code          => l_component_code
35056         , p_component_type_code     => l_component_type_code
35057         , p_component_appl_id       => l_component_appl_id
35058         , p_amb_context_code        => l_amb_context_code
35059         , p_entity_code             => 'TRANSACTIONS'
35060         , p_event_class_code        => 'CAPITALIZATION'
35061         , p_side                    => 'NA'
35062         );
35063 
35064   END IF;
35065 
35066    --
35067    --
35068    END IF;
35069 
35070        --
35071        -- Update the line information that should be overwritten
35072        --
35073        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
35077        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
35074                                          p_header_num   => 1);
35075        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
35076 
35078 
35079        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
35080           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
35081        END IF;
35082 
35083       --
35084       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
35085       --
35086       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
35087           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
35088       ELSE
35089           ---------------------------------------------------------------------------------------------------
35090           -- 4262811a Switch Sign
35091           ---------------------------------------------------------------------------------------------------
35092           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
35093           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35094                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35095           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35096                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35097           -- 5132302
35098           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
35099                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35100 
35101       END IF;
35102 
35103       -- 4955764
35104       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35105       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
35106 
35107 
35108       XLA_AE_LINES_PKG.ValidateCurrentLine;
35109       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35110 
35111       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35112                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
35113                ,p_balance_type_code => l_balance_type_code);
35114 
35115    END IF;
35116 
35117    -----------------------------------------------------------------------------------------
35118    -- 4262811 Multiperiod Accounting
35119    -----------------------------------------------------------------------------------------
35120      -- No MPA option is assigned.
35121 
35122 
35123 END IF;
35124 END IF;
35125 --
35126 
35127 --
35128 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35129    trace
35130       (p_msg      => 'END of AcctLineType_203'
35131       ,p_level    => C_LEVEL_PROCEDURE
35132       ,p_module   => l_log_module);
35133 END IF;
35134 --
35135 EXCEPTION
35136   WHEN xla_exceptions_pkg.application_exception THEN
35137       RAISE;
35138   WHEN OTHERS THEN
35139        xla_exceptions_pkg.raise_message
35140            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_203');
35141 END AcctLineType_203;
35142 --
35143 
35144 ---------------------------------------
35145 --
35146 -- PRIVATE FUNCTION
35147 --         AcctLineType_204
35148 --
35149 ---------------------------------------
35150 PROCEDURE AcctLineType_204 (
35151   p_application_id        IN NUMBER
35152  ,p_event_id              IN NUMBER
35153  ,p_calculate_acctd_flag  IN VARCHAR2
35154  ,p_calculate_g_l_flag    IN VARCHAR2
35155  ,p_actual_flag           IN OUT VARCHAR2
35156  ,p_balance_type_code     OUT VARCHAR2
35157  ,p_gain_or_loss_ref      OUT VARCHAR2
35158  
35159 --Period Close Date
35160  , p_source_1            IN DATE
35161 --Generated Code Combination Identifier
35162  , p_source_3            IN NUMBER
35163 --Expense Account Code Combination Identifier
35164  , p_source_29            IN NUMBER
35165 --Adjustment Type
35166  , p_source_35            IN VARCHAR2
35167 --Transaction Header Identifier
35168  , p_source_36            IN NUMBER
35169 --Adjustment Line Identifier
35170  , p_source_37            IN NUMBER
35171 --Distribution Type Code
35172  , p_source_38            IN VARCHAR2
35173 --Entered Amount
35174  , p_source_39            IN NUMBER
35175 --Currency Code
35176  , p_source_40            IN VARCHAR2
35177 )
35178 IS
35179 
35180 l_component_type              VARCHAR2(80);
35181 l_component_code              VARCHAR2(30);
35182 l_component_type_code         VARCHAR2(1);
35183 l_component_appl_id           INTEGER;
35184 l_amb_context_code            VARCHAR2(30);
35185 l_entity_code                 VARCHAR2(30);
35186 l_event_class_code            VARCHAR2(30);
35187 l_ae_header_id                NUMBER;
35188 l_event_type_code             VARCHAR2(30);
35189 l_line_definition_code        VARCHAR2(30);
35190 l_line_definition_owner_code  VARCHAR2(1);
35191 --
35192 -- adr variables
35193 l_segment                     VARCHAR2(30);
35194 l_ccid                        NUMBER;
35195 l_adr_transaction_coa_id      NUMBER;
35196 l_adr_accounting_coa_id       NUMBER;
35197 l_adr_flexfield_segment_code  VARCHAR2(30);
35198 l_adr_flex_value_set_id       NUMBER;
35199 l_adr_value_type_code         VARCHAR2(30);
35200 l_adr_value_combination_id    NUMBER;
35201 l_adr_value_segment_code      VARCHAR2(30);
35202 
35203 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
35204 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
35205 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
35209 l_entered_amt_idx             NUMBER;
35206 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
35207 
35208 -- 4262811 Variables ------------------------------------------------------------------------------------------
35210 l_accted_amt_idx              NUMBER;
35211 l_acc_rev_flag                VARCHAR2(1);
35212 l_accrual_line_num            NUMBER;
35213 l_tmp_amt                     NUMBER;
35214 l_acc_rev_natural_side_code   VARCHAR2(1);
35215 
35216 l_num_entries                 NUMBER;
35217 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
35218 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
35219 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
35220 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
35221 l_recog_line_1                NUMBER;
35222 l_recog_line_2                NUMBER;
35223 
35224 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
35225 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
35226 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
35227 
35228 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
35229 
35230 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
35231 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
35232 
35233 ---------------------------------------------------------------------------------------------------------------
35234 
35235 
35236 --
35237 -- bulk performance
35238 --
35239 l_balance_type_code           VARCHAR2(1);
35240 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
35241 l_log_module                  VARCHAR2(240);
35242 
35243 --
35244 -- Upgrade strategy
35245 --
35246 l_actual_upg_option           VARCHAR2(1);
35247 l_enc_upg_option           VARCHAR2(1);
35248 
35249 --
35250 BEGIN
35251 --
35252 IF g_log_enabled THEN
35253       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_204';
35254 END IF;
35255 --
35256 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35257 
35258       trace
35259          (p_msg      => 'BEGIN of AcctLineType_204'
35260          ,p_level    => C_LEVEL_PROCEDURE
35261          ,p_module   => l_log_module);
35262 
35263 END IF;
35264 --
35265 l_component_type             := 'AMB_JLT';
35266 l_component_code             := 'FA_CAP_EXP_BAL';
35267 l_component_type_code        := 'S';
35268 l_component_appl_id          :=  140;
35269 l_amb_context_code           := 'DEFAULT';
35270 l_entity_code                := 'TRANSACTIONS';
35271 l_event_class_code           := 'CAPITALIZATION';
35272 l_event_type_code            := 'CAPITALIZATION';
35273 l_line_definition_owner_code := 'S';
35277 l_segment                     := NULL;
35274 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CAPITA3';
35275 --
35276 l_balance_type_code          := 'A';
35278 l_ccid                        := NULL;
35282 l_adr_flex_value_set_id       := NULL;
35279 l_adr_transaction_coa_id      := NULL;
35280 l_adr_accounting_coa_id       := NULL;
35281 l_adr_flexfield_segment_code  := NULL;
35283 l_adr_value_type_code         := NULL;
35284 l_adr_value_combination_id    := NULL;
35285 l_adr_value_segment_code      := NULL;
35286 
35287 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
35288 l_bflow_class_code           := '';    -- 4219869 Business Flow
35289 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
35290 l_budgetary_control_flag     := 'N';
35291 
35292 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
35293 l_bflow_applied_to_amt       := NULL; -- 5132302
35294 l_entered_amt_idx            := NULL;          -- 4262811
35295 l_accted_amt_idx             := NULL;          -- 4262811
35296 l_acc_rev_flag               := NULL;          -- 4262811
35297 l_accrual_line_num           := NULL;          -- 4262811
35298 l_tmp_amt                    := NULL;          -- 4262811
35299 --
35300  
35301 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
35302     l_balance_type_code <> 'B' THEN
35303 IF NVL(p_source_35,'
35304 ') =  'BONUS EXPENSE'
35305  THEN 
35306 
35307    --
35308    XLA_AE_LINES_PKG.SetNewLine;
35309 
35310    p_balance_type_code          := l_balance_type_code;
35311    -- set the flag so later we will know whether the gain loss line needs to be created
35312    
35313    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
35314      p_actual_flag :='A';
35315    END IF;
35316 
35317    --
35318    -- bulk performance
35319    --
35320    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
35321                                       p_header_num   => 0); -- 4262811
35322    --
35323    -- set accounting line options
35324    --
35325    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
35326            p_natural_side_code          => 'C'
35327          , p_gain_or_loss_flag          => 'N'
35328          , p_gl_transfer_mode_code      => 'S'
35329          , p_acct_entry_type_code       => 'A'
35330          , p_switch_side_flag           => 'Y'
35331          , p_merge_duplicate_code       => 'N'
35332          );
35333    --
35334    l_acc_rev_natural_side_code := 'D';  -- 4262811
35335    -- 
35336    --
35337    -- set accounting line type info
35338    --
35339    xla_ae_lines_pkg.SetAcctLineType
35340       (p_component_type             => l_component_type
35341       ,p_event_type_code            => l_event_type_code
35342       ,p_line_definition_owner_code => l_line_definition_owner_code
35343       ,p_line_definition_code       => l_line_definition_code
35344       ,p_accounting_line_code       => l_component_code
35345       ,p_accounting_line_type_code  => l_component_type_code
35346       ,p_accounting_line_appl_id    => l_component_appl_id
35347       ,p_amb_context_code           => l_amb_context_code
35348       ,p_entity_code                => l_entity_code
35349       ,p_event_class_code           => l_event_class_code);
35350    --
35351    -- set accounting class
35352    --
35353    xla_ae_lines_pkg.SetAcctClass(
35354            p_accounting_class_code  => 'EXPENSE'
35355          , p_ae_header_id           => l_ae_header_id
35356          );
35357 
35358    --
35359    -- set rounding class
35360    --
35361    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
35362                       'EXPENSE';
35363 
35364    --
35365    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
35366    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
35367    --
35368    -- bulk performance
35369    --
35370    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
35371 
35372    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
35373       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
35374 
35375    -- 4955764
35376    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35377       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
35378 
35379    -- 4458381 Public Sector Enh
35380    
35381    --
35382    -- set accounting attributes for the line type
35383    --
35384    l_entered_amt_idx := 4;
35385    l_accted_amt_idx  := 6;
35386    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
35387    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
35388    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
35389    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
35390    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
35391    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
35392    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
35393    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
35394    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
35395    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
35396    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
35397    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
35398    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
35399 
35400    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
35401    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
35402 
35403    ---------------------------------------------------------------------------------------------------------------
35404    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
35408    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35405    ---------------------------------------------------------------------------------------------------------------
35406    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
35407 
35409    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35410 
35411    IF xla_accounting_cache_pkg.GetValueChar
35412          (p_source_code         => 'LEDGER_CATEGORY_CODE'
35413          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
35414    AND l_bflow_method_code = 'PRIOR_ENTRY'
35415 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
35416    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
35417          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
35418        )
35419    THEN
35420          xla_ae_lines_pkg.BflowUpgEntry
35421            (p_business_method_code    => l_bflow_method_code
35422            ,p_business_class_code     => l_bflow_class_code
35423            ,p_balance_type            => l_balance_type_code);
35424    ELSE
35425       NULL;
35426 -- No business flow processing for business flow method of NONE.
35427    END IF;
35428 
35429    --
35430    -- call analytical criteria
35431    --
35432    
35433    --
35434    -- call description
35435    --
35436    
35437 xla_ae_lines_pkg.SetLineDescription(
35438    p_ae_header_id => l_ae_header_id
35439   ,p_description  => Description_21 (
35440      p_application_id         => p_application_id
35441    , p_ae_header_id           => l_ae_header_id 
35442 , p_source_1 => p_source_1
35443    )
35444 );
35445 
35446 
35447    --
35448    -- call ADRs
35449    -- Bug 4922099
35450    --
35451    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
35452         (NVL(l_actual_upg_option, 'N') = 'O') OR
35453         (NVL(l_enc_upg_option, 'N') = 'O')
35454       )
35455    THEN
35456    NULL;
35457    --
35458    --
35459    
35460   l_ccid := AcctDerRule_175(
35461            p_application_id           => p_application_id
35462          , p_ae_header_id             => l_ae_header_id 
35463 , p_source_3 => p_source_3
35464 , p_source_29 => p_source_29
35465          , x_transaction_coa_id       => l_adr_transaction_coa_id
35466          , x_accounting_coa_id        => l_adr_accounting_coa_id
35467          , x_value_type_code          => l_adr_value_type_code
35468          , p_side                     => 'NA'
35469    );
35470 
35471    xla_ae_lines_pkg.set_ccid(
35472     p_code_combination_id          => l_ccid
35473   , p_value_type_code              => l_adr_value_type_code
35474   , p_transaction_coa_id           => l_adr_transaction_coa_id
35475   , p_accounting_coa_id            => l_adr_accounting_coa_id
35476   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
35477   , p_adr_type_code                => 'S'
35478   , p_component_type               => l_component_type
35479   , p_component_code               => l_component_code
35480   , p_component_type_code          => l_component_type_code
35481   , p_component_appl_id            => l_component_appl_id
35482   , p_amb_context_code             => l_amb_context_code
35483   , p_side                         => 'NA'
35484   );
35485 
35486 
35487    --
35488    --
35489    END IF;
35490    --
35491    -- Bug 4922099
35492    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
35493           (NVL(l_enc_upg_option, 'N') = 'O')
35494         ) AND
35495         (l_bflow_method_code = 'PRIOR_ENTRY')
35496       )
35497    THEN
35498       IF
35499       --
35500       1 = 2
35501       --
35502       THEN
35503       xla_accounting_err_pkg.build_message
35504                                     (p_appli_s_name            => 'XLA'
35505                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35506                                     ,p_token_1                 => 'LINE_NUMBER'
35507                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
35508                                     ,p_token_2                 => 'LINE_TYPE_NAME'
35509                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
35510                                                                              l_component_type
35511                                                                             ,l_component_code
35512                                                                             ,l_component_type_code
35513                                                                             ,l_component_appl_id
35514                                                                             ,l_amb_context_code
35518                                     ,p_token_3                 => 'OWNER'
35515                                                                             ,l_entity_code
35516                                                                             ,l_event_class_code
35517                                                                            )
35519                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
35520                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
35521                                                                           ,p_lookup_code    => l_component_type_code
35522                                                                          )
35523                                     ,p_token_4                 => 'PRODUCT_NAME'
35524                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
35525                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
35526                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
35527                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
35528                                     ,p_ae_header_id            =>  NULL
35529                                        );
35530 
35531         IF (C_LEVEL_ERROR>= g_log_level) THEN
35532                  trace
35533                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35534                       ,p_level    => C_LEVEL_ERROR
35535                       ,p_module   => l_log_module);
35536         END IF;
35537       END IF;
35538    END IF;
35539    --
35540    --
35541    ------------------------------------------------------------------------------------------------
35542    -- 4219869 Business Flow
35543    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
35544    -- Prior Entry.  Currently, the following code is always generated.
35545    ------------------------------------------------------------------------------------------------
35546    XLA_AE_LINES_PKG.ValidateCurrentLine;
35547 
35548    ------------------------------------------------------------------------------------
35549    -- 4219869 Business Flow
35550    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
35551    ------------------------------------------------------------------------------------
35552    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35553 
35554    ----------------------------------------------------------------------------------
35555    -- 4219869 Business Flow
35556    -- Update journal entry status -- Need to generate this within IF <condition>
35560          ,p_balance_type_code => l_balance_type_code
35557    ----------------------------------------------------------------------------------
35558    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35559          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
35561          );
35562 
35563    -------------------------------------------------------------------------------------------
35564    -- 4262811 - Generate the Accrual Reversal lines
35565    -------------------------------------------------------------------------------------------
35566    BEGIN
35567       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
35568                               (g_array_event(p_event_id).array_value_num('header_index'));
35569       IF l_acc_rev_flag IS NULL THEN
35570          l_acc_rev_flag := 'N';
35571       END IF;
35572    EXCEPTION
35573       WHEN OTHERS THEN
35574          l_acc_rev_flag := 'N';
35575    END;
35576    --
35577    IF (l_acc_rev_flag = 'Y') THEN
35578 
35579        -- 4645092  ------------------------------------------------------------------------------
35580        -- To allow MPA report to determine if it should generate report process
35581        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
35582        ------------------------------------------------------------------------------------------
35583 
35584        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
35585        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
35586    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
35587    -- call ADRs
35588    -- Bug 4922099
35589    --
35590    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
35591         (NVL(l_actual_upg_option, 'N') = 'O') OR
35592         (NVL(l_enc_upg_option, 'N') = 'O')
35593       )
35594    THEN
35595    NULL;
35596    --
35597    --
35598    
35599   l_ccid := AcctDerRule_175(
35600            p_application_id           => p_application_id
35601          , p_ae_header_id             => l_ae_header_id 
35602 , p_source_3 => p_source_3
35603 , p_source_29 => p_source_29
35604          , x_transaction_coa_id       => l_adr_transaction_coa_id
35605          , x_accounting_coa_id        => l_adr_accounting_coa_id
35606          , x_value_type_code          => l_adr_value_type_code
35607          , p_side                     => 'NA'
35608    );
35609 
35610    xla_ae_lines_pkg.set_ccid(
35611     p_code_combination_id          => l_ccid
35612   , p_value_type_code              => l_adr_value_type_code
35613   , p_transaction_coa_id           => l_adr_transaction_coa_id
35614   , p_accounting_coa_id            => l_adr_accounting_coa_id
35615   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
35616   , p_adr_type_code                => 'S'
35617   , p_component_type               => l_component_type
35618   , p_component_code               => l_component_code
35619   , p_component_type_code          => l_component_type_code
35620   , p_component_appl_id            => l_component_appl_id
35621   , p_amb_context_code             => l_amb_context_code
35622   , p_side                         => 'NA'
35623   );
35624 
35625 
35626    --
35627    --
35628    END IF;
35629 
35630        --
35631        -- Update the line information that should be overwritten
35632        --
35633        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
35634                                          p_header_num   => 1);
35635        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
35636 
35637        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
35638 
35639        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
35640           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
35641        END IF;
35642 
35643       --
35644       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
35645       --
35646       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
35647           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
35648       ELSE
35649           ---------------------------------------------------------------------------------------------------
35650           -- 4262811a Switch Sign
35651           ---------------------------------------------------------------------------------------------------
35652           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
35653           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35654                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35655           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35656                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35657           -- 5132302
35658           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
35662 
35659                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35660 
35661       END IF;
35663       -- 4955764
35664       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35665       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
35666 
35667 
35668       XLA_AE_LINES_PKG.ValidateCurrentLine;
35669       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35670 
35671       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35672                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
35673                ,p_balance_type_code => l_balance_type_code);
35674 
35675    END IF;
35676 
35677    -----------------------------------------------------------------------------------------
35678    -- 4262811 Multiperiod Accounting
35679    -----------------------------------------------------------------------------------------
35680      -- No MPA option is assigned.
35681 
35682 
35683 END IF;
35684 END IF;
35685 --
35686 
35687 --
35688 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35689    trace
35690       (p_msg      => 'END of AcctLineType_204'
35691       ,p_level    => C_LEVEL_PROCEDURE
35692       ,p_module   => l_log_module);
35693 END IF;
35694 --
35695 EXCEPTION
35696   WHEN xla_exceptions_pkg.application_exception THEN
35697       RAISE;
35698   WHEN OTHERS THEN
35699        xla_exceptions_pkg.raise_message
35700            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_204');
35701 END AcctLineType_204;
35702 --
35703 
35704 ---------------------------------------
35705 --
35706 -- PRIVATE FUNCTION
35707 --         AcctLineType_205
35708 --
35709 ---------------------------------------
35710 PROCEDURE AcctLineType_205 (
35711   p_application_id        IN NUMBER
35712  ,p_event_id              IN NUMBER
35713  ,p_calculate_acctd_flag  IN VARCHAR2
35714  ,p_calculate_g_l_flag    IN VARCHAR2
35715  ,p_actual_flag           IN OUT VARCHAR2
35716  ,p_balance_type_code     OUT VARCHAR2
35717  ,p_gain_or_loss_ref      OUT VARCHAR2
35718  
35719 --Period Close Date
35720  , p_source_1            IN DATE
35721 --Generated Code Combination Identifier
35722  , p_source_3            IN NUMBER
35723 --Depreciation Reserve Account
35724  , p_source_10            IN VARCHAR2
35725 --Generated Offset Code Combination Identifier
35726  , p_source_17            IN NUMBER
35727 --Expense Account Code Combination Identifier
35728  , p_source_29            IN NUMBER
35729 --Default Code Combination Identifier
35730  , p_source_30            IN NUMBER
35731 --Adjustment Type
35732  , p_source_35            IN VARCHAR2
35733 --Transaction Header Identifier
35734  , p_source_36            IN NUMBER
35735 --Adjustment Line Identifier
35736  , p_source_37            IN NUMBER
35737 --Distribution Type Code
35738  , p_source_38            IN VARCHAR2
35739 --Entered Amount
35740  , p_source_39            IN NUMBER
35741 --Currency Code
35742  , p_source_40            IN VARCHAR2
35743 )
35744 IS
35745 
35746 l_component_type              VARCHAR2(80);
35747 l_component_code              VARCHAR2(30);
35748 l_component_type_code         VARCHAR2(1);
35749 l_component_appl_id           INTEGER;
35750 l_amb_context_code            VARCHAR2(30);
35751 l_entity_code                 VARCHAR2(30);
35752 l_event_class_code            VARCHAR2(30);
35753 l_ae_header_id                NUMBER;
35754 l_event_type_code             VARCHAR2(30);
35755 l_line_definition_code        VARCHAR2(30);
35756 l_line_definition_owner_code  VARCHAR2(1);
35757 --
35758 -- adr variables
35759 l_segment                     VARCHAR2(30);
35760 l_ccid                        NUMBER;
35761 l_adr_transaction_coa_id      NUMBER;
35762 l_adr_accounting_coa_id       NUMBER;
35763 l_adr_flexfield_segment_code  VARCHAR2(30);
35764 l_adr_flex_value_set_id       NUMBER;
35765 l_adr_value_type_code         VARCHAR2(30);
35766 l_adr_value_combination_id    NUMBER;
35767 l_adr_value_segment_code      VARCHAR2(30);
35768 
35769 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
35770 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
35771 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
35772 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
35773 
35774 -- 4262811 Variables ------------------------------------------------------------------------------------------
35775 l_entered_amt_idx             NUMBER;
35776 l_accted_amt_idx              NUMBER;
35777 l_acc_rev_flag                VARCHAR2(1);
35778 l_accrual_line_num            NUMBER;
35779 l_tmp_amt                     NUMBER;
35780 l_acc_rev_natural_side_code   VARCHAR2(1);
35781 
35782 l_num_entries                 NUMBER;
35783 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
35784 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
35785 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
35786 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
35787 l_recog_line_1                NUMBER;
35788 l_recog_line_2                NUMBER;
35789 
35793 
35790 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
35791 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
35792 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
35794 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
35795 
35796 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
35797 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
35798 
35799 ---------------------------------------------------------------------------------------------------------------
35800 
35801 
35802 --
35803 -- bulk performance
35804 --
35805 l_balance_type_code           VARCHAR2(1);
35806 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
35807 l_log_module                  VARCHAR2(240);
35808 
35809 --
35810 -- Upgrade strategy
35811 --
35812 l_actual_upg_option           VARCHAR2(1);
35813 l_enc_upg_option           VARCHAR2(1);
35814 
35815 --
35816 BEGIN
35817 --
35818 IF g_log_enabled THEN
35819       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_205';
35820 END IF;
35821 --
35822 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35823 
35824       trace
35825          (p_msg      => 'BEGIN of AcctLineType_205'
35826          ,p_level    => C_LEVEL_PROCEDURE
35827          ,p_module   => l_log_module);
35828 
35829 END IF;
35830 --
35831 l_component_type             := 'AMB_JLT';
35832 l_component_code             := 'FA_CAP_RESERVE';
35833 l_component_type_code        := 'S';
35834 l_component_appl_id          :=  140;
35835 l_amb_context_code           := 'DEFAULT';
35836 l_entity_code                := 'TRANSACTIONS';
35837 l_event_class_code           := 'CAPITALIZATION';
35838 l_event_type_code            := 'CAPITALIZATION';
35839 l_line_definition_owner_code := 'S';
35840 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CAPITA3';
35841 --
35842 l_balance_type_code          := 'A';
35843 l_segment                     := NULL;
35844 l_ccid                        := NULL;
35845 l_adr_transaction_coa_id      := NULL;
35846 l_adr_accounting_coa_id       := NULL;
35847 l_adr_flexfield_segment_code  := NULL;
35848 l_adr_flex_value_set_id       := NULL;
35849 l_adr_value_type_code         := NULL;
35850 l_adr_value_combination_id    := NULL;
35851 l_adr_value_segment_code      := NULL;
35852 
35853 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
35854 l_bflow_class_code           := '';    -- 4219869 Business Flow
35855 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
35856 l_budgetary_control_flag     := 'N';
35857 
35858 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
35859 l_bflow_applied_to_amt       := NULL; -- 5132302
35860 l_entered_amt_idx            := NULL;          -- 4262811
35861 l_accted_amt_idx             := NULL;          -- 4262811
35862 l_acc_rev_flag               := NULL;          -- 4262811
35863 l_accrual_line_num           := NULL;          -- 4262811
35864 l_tmp_amt                    := NULL;          -- 4262811
35865 --
35866  
35867 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
35868     l_balance_type_code <> 'B' THEN
35869 IF NVL(p_source_35,'
35870 ') =  'EXPENSE'
35871  THEN 
35872 
35873    --
35874    XLA_AE_LINES_PKG.SetNewLine;
35875 
35876    p_balance_type_code          := l_balance_type_code;
35877    -- set the flag so later we will know whether the gain loss line needs to be created
35878    
35879    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
35880      p_actual_flag :='A';
35881    END IF;
35882 
35883    --
35884    -- bulk performance
35885    --
35886    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
35887                                       p_header_num   => 0); -- 4262811
35888    --
35889    -- set accounting line options
35890    --
35891    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
35892            p_natural_side_code          => 'C'
35893          , p_gain_or_loss_flag          => 'N'
35894          , p_gl_transfer_mode_code      => 'S'
35895          , p_acct_entry_type_code       => 'A'
35896          , p_switch_side_flag           => 'Y'
35897          , p_merge_duplicate_code       => 'N'
35898          );
35899    --
35900    l_acc_rev_natural_side_code := 'D';  -- 4262811
35901    -- 
35902    --
35903    -- set accounting line type info
35904    --
35905    xla_ae_lines_pkg.SetAcctLineType
35906       (p_component_type             => l_component_type
35907       ,p_event_type_code            => l_event_type_code
35908       ,p_line_definition_owner_code => l_line_definition_owner_code
35909       ,p_line_definition_code       => l_line_definition_code
35910       ,p_accounting_line_code       => l_component_code
35911       ,p_accounting_line_type_code  => l_component_type_code
35912       ,p_accounting_line_appl_id    => l_component_appl_id
35913       ,p_amb_context_code           => l_amb_context_code
35914       ,p_entity_code                => l_entity_code
35915       ,p_event_class_code           => l_event_class_code);
35916    --
35917    -- set accounting class
35918    --
35919    xla_ae_lines_pkg.SetAcctClass(
35920            p_accounting_class_code  => 'ASSET'
35921          , p_ae_header_id           => l_ae_header_id
35922          );
35923 
35924    --
35925    -- set rounding class
35926    --
35927    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
35928                       'ASSET';
35929 
35930    --
35931    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
35935    --
35932    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
35933    --
35934    -- bulk performance
35936    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
35937 
35938    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
35939       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
35940 
35941    -- 4955764
35942    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35943       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
35944 
35945    -- 4458381 Public Sector Enh
35946    
35947    --
35948    -- set accounting attributes for the line type
35949    --
35950    l_entered_amt_idx := 4;
35951    l_accted_amt_idx  := 6;
35952    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
35953    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
35954    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
35955    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
35956    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
35957    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
35958    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
35959    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
35960    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
35961    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
35962    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
35963    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
35964    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
35965 
35966    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
35967    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
35968 
35969    ---------------------------------------------------------------------------------------------------------------
35970    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
35971    ---------------------------------------------------------------------------------------------------------------
35972    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
35973 
35974    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35975    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35976 
35977    IF xla_accounting_cache_pkg.GetValueChar
35978          (p_source_code         => 'LEDGER_CATEGORY_CODE'
35979          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
35980    AND l_bflow_method_code = 'PRIOR_ENTRY'
35981 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
35982    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
35983          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
35984        )
35985    THEN
35986          xla_ae_lines_pkg.BflowUpgEntry
35987            (p_business_method_code    => l_bflow_method_code
35988            ,p_business_class_code     => l_bflow_class_code
35989            ,p_balance_type            => l_balance_type_code);
35990    ELSE
35991       NULL;
35992 -- No business flow processing for business flow method of NONE.
35993    END IF;
35994 
35995    --
35996    -- call analytical criteria
35997    --
35998    
35999    --
36000    -- call description
36001    --
36002    
36003 xla_ae_lines_pkg.SetLineDescription(
36004    p_ae_header_id => l_ae_header_id
36005   ,p_description  => Description_22 (
36006      p_application_id         => p_application_id
36007    , p_ae_header_id           => l_ae_header_id 
36008 , p_source_1 => p_source_1
36009    )
36010 );
36011 
36012 
36013    --
36014    -- call ADRs
36015    -- Bug 4922099
36016    --
36017    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36018         (NVL(l_actual_upg_option, 'N') = 'O') OR
36019         (NVL(l_enc_upg_option, 'N') = 'O')
36020       )
36021    THEN
36022    NULL;
36023    --
36024    --
36025    
36026   l_ccid := AcctDerRule_174(
36027            p_application_id           => p_application_id
36028          , p_ae_header_id             => l_ae_header_id 
36029 , p_source_3 => p_source_3
36030 , p_source_17 => p_source_17
36031 , p_source_30 => p_source_30
36032          , x_transaction_coa_id       => l_adr_transaction_coa_id
36033          , x_accounting_coa_id        => l_adr_accounting_coa_id
36034          , x_value_type_code          => l_adr_value_type_code
36035          , p_side                     => 'NA'
36036    );
36037 
36038    xla_ae_lines_pkg.set_ccid(
36039     p_code_combination_id          => l_ccid
36040   , p_value_type_code              => l_adr_value_type_code
36041   , p_transaction_coa_id           => l_adr_transaction_coa_id
36042   , p_accounting_coa_id            => l_adr_accounting_coa_id
36043   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
36044   , p_adr_type_code                => 'S'
36045   , p_component_type               => l_component_type
36046   , p_component_code               => l_component_code
36047   , p_component_type_code          => l_component_type_code
36048   , p_component_appl_id            => l_component_appl_id
36049   , p_amb_context_code             => l_amb_context_code
36050   , p_side                         => 'NA'
36051   );
36052 
36053 
36054    l_segment := AcctDerRule_149(
36055            p_application_id           => p_application_id
36056          , p_ae_header_id             => l_ae_header_id 
36057 , p_source_3 => p_source_3
36058 , p_source_10 => p_source_10
36059          , x_transaction_coa_id       => l_adr_transaction_coa_id
36063          , x_value_type_code          => l_adr_value_type_code
36060          , x_accounting_coa_id        => l_adr_accounting_coa_id
36061          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
36062          , x_flex_value_set_id        => l_adr_flex_value_set_id
36064          , x_value_combination_id     => l_adr_value_combination_id
36065          , x_value_segment_code       => l_adr_value_segment_code
36066          , p_side                     => 'NA'
36067          , p_override_seg_flag        => 'Y'
36068    );
36069 
36070    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
36071 
36072       xla_ae_lines_pkg.set_segment(
36073           p_to_segment_code         => 'GL_ACCOUNT'
36074         , p_segment_value           => l_segment
36075         , p_from_segment_code       => l_adr_value_segment_code
36076         , p_from_combination_id     => l_adr_value_combination_id
36077         , p_value_type_code         => l_adr_value_type_code
36078         , p_transaction_coa_id      => l_adr_transaction_coa_id
36079         , p_accounting_coa_id       => l_adr_accounting_coa_id
36080         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
36081         , p_flex_value_set_id       => l_adr_flex_value_set_id
36082         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
36083         , p_adr_type_code           => 'S'
36084         , p_component_type          => l_component_type
36085         , p_component_code          => l_component_code
36086         , p_component_type_code     => l_component_type_code
36087         , p_component_appl_id       => l_component_appl_id
36088         , p_amb_context_code        => l_amb_context_code
36089         , p_entity_code             => 'TRANSACTIONS'
36090         , p_event_class_code        => 'CAPITALIZATION'
36091         , p_side                    => 'NA'
36092         );
36093 
36094   END IF;
36095 
36096    l_segment := AcctDerRule_168(
36097            p_application_id           => p_application_id
36098          , p_ae_header_id             => l_ae_header_id 
36099 , p_source_3 => p_source_3
36100 , p_source_29 => p_source_29
36101          , x_transaction_coa_id       => l_adr_transaction_coa_id
36102          , x_accounting_coa_id        => l_adr_accounting_coa_id
36103          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
36104          , x_flex_value_set_id        => l_adr_flex_value_set_id
36105          , x_value_type_code          => l_adr_value_type_code
36106          , x_value_combination_id     => l_adr_value_combination_id
36107          , x_value_segment_code       => l_adr_value_segment_code
36108          , p_side                     => 'NA'
36109          , p_override_seg_flag        => 'Y'
36110    );
36111 
36112    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
36113 
36114       xla_ae_lines_pkg.set_segment(
36115           p_to_segment_code         => 'GL_BALANCING'
36116         , p_segment_value           => l_segment
36117         , p_from_segment_code       => l_adr_value_segment_code
36118         , p_from_combination_id     => l_adr_value_combination_id
36119         , p_value_type_code         => l_adr_value_type_code
36120         , p_transaction_coa_id      => l_adr_transaction_coa_id
36121         , p_accounting_coa_id       => l_adr_accounting_coa_id
36122         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
36123         , p_flex_value_set_id       => l_adr_flex_value_set_id
36124         , p_adr_code                => 'FA_EXPENSE_ACCT'
36125         , p_adr_type_code           => 'S'
36126         , p_component_type          => l_component_type
36127         , p_component_code          => l_component_code
36128         , p_component_type_code     => l_component_type_code
36129         , p_component_appl_id       => l_component_appl_id
36130         , p_amb_context_code        => l_amb_context_code
36131         , p_entity_code             => 'TRANSACTIONS'
36132         , p_event_class_code        => 'CAPITALIZATION'
36133         , p_side                    => 'NA'
36134         );
36135 
36136   END IF;
36137 
36138    --
36139    --
36140    END IF;
36141    --
36142    -- Bug 4922099
36143    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
36144           (NVL(l_enc_upg_option, 'N') = 'O')
36145         ) AND
36146         (l_bflow_method_code = 'PRIOR_ENTRY')
36147       )
36148    THEN
36149       IF
36150       --
36151       1 = 2
36152       --
36153       THEN
36154       xla_accounting_err_pkg.build_message
36155                                     (p_appli_s_name            => 'XLA'
36156                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36157                                     ,p_token_1                 => 'LINE_NUMBER'
36158                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
36159                                     ,p_token_2                 => 'LINE_TYPE_NAME'
36160                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
36161                                                                              l_component_type
36162                                                                             ,l_component_code
36163                                                                             ,l_component_type_code
36164                                                                             ,l_component_appl_id
36165                                                                             ,l_amb_context_code
36166                                                                             ,l_entity_code
36167                                                                             ,l_event_class_code
36168                                                                            )
36169                                     ,p_token_3                 => 'OWNER'
36170                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
36174                                     ,p_token_4                 => 'PRODUCT_NAME'
36171                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
36172                                                                           ,p_lookup_code    => l_component_type_code
36173                                                                          )
36175                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
36176                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
36177                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
36178                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
36179                                     ,p_ae_header_id            =>  NULL
36180                                        );
36181 
36182         IF (C_LEVEL_ERROR>= g_log_level) THEN
36183                  trace
36184                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36185                       ,p_level    => C_LEVEL_ERROR
36186                       ,p_module   => l_log_module);
36187         END IF;
36188       END IF;
36189    END IF;
36190    --
36191    --
36192    ------------------------------------------------------------------------------------------------
36193    -- 4219869 Business Flow
36194    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
36195    -- Prior Entry.  Currently, the following code is always generated.
36196    ------------------------------------------------------------------------------------------------
36197    XLA_AE_LINES_PKG.ValidateCurrentLine;
36198 
36199    ------------------------------------------------------------------------------------
36200    -- 4219869 Business Flow
36201    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
36202    ------------------------------------------------------------------------------------
36203    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36204 
36205    ----------------------------------------------------------------------------------
36206    -- 4219869 Business Flow
36207    -- Update journal entry status -- Need to generate this within IF <condition>
36208    ----------------------------------------------------------------------------------
36209    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36210          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
36211          ,p_balance_type_code => l_balance_type_code
36212          );
36213 
36214    -------------------------------------------------------------------------------------------
36215    -- 4262811 - Generate the Accrual Reversal lines
36216    -------------------------------------------------------------------------------------------
36217    BEGIN
36218       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
36219                               (g_array_event(p_event_id).array_value_num('header_index'));
36220       IF l_acc_rev_flag IS NULL THEN
36221          l_acc_rev_flag := 'N';
36222       END IF;
36223    EXCEPTION
36224       WHEN OTHERS THEN
36225          l_acc_rev_flag := 'N';
36226    END;
36227    --
36228    IF (l_acc_rev_flag = 'Y') THEN
36229 
36230        -- 4645092  ------------------------------------------------------------------------------
36231        -- To allow MPA report to determine if it should generate report process
36232        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
36233        ------------------------------------------------------------------------------------------
36234 
36235        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
36236        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
36237    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
36238    -- call ADRs
36239    -- Bug 4922099
36240    --
36241    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36242         (NVL(l_actual_upg_option, 'N') = 'O') OR
36243         (NVL(l_enc_upg_option, 'N') = 'O')
36244       )
36245    THEN
36246    NULL;
36247    --
36248    --
36249    
36250   l_ccid := AcctDerRule_174(
36251            p_application_id           => p_application_id
36252          , p_ae_header_id             => l_ae_header_id 
36253 , p_source_3 => p_source_3
36254 , p_source_17 => p_source_17
36255 , p_source_30 => p_source_30
36256          , x_transaction_coa_id       => l_adr_transaction_coa_id
36257          , x_accounting_coa_id        => l_adr_accounting_coa_id
36258          , x_value_type_code          => l_adr_value_type_code
36259          , p_side                     => 'NA'
36260    );
36261 
36262    xla_ae_lines_pkg.set_ccid(
36263     p_code_combination_id          => l_ccid
36264   , p_value_type_code              => l_adr_value_type_code
36265   , p_transaction_coa_id           => l_adr_transaction_coa_id
36266   , p_accounting_coa_id            => l_adr_accounting_coa_id
36267   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
36268   , p_adr_type_code                => 'S'
36269   , p_component_type               => l_component_type
36270   , p_component_code               => l_component_code
36271   , p_component_type_code          => l_component_type_code
36272   , p_component_appl_id            => l_component_appl_id
36273   , p_amb_context_code             => l_amb_context_code
36274   , p_side                         => 'NA'
36275   );
36276 
36277 
36278    l_segment := AcctDerRule_149(
36279            p_application_id           => p_application_id
36280          , p_ae_header_id             => l_ae_header_id 
36281 , p_source_3 => p_source_3
36282 , p_source_10 => p_source_10
36283          , x_transaction_coa_id       => l_adr_transaction_coa_id
36284          , x_accounting_coa_id        => l_adr_accounting_coa_id
36288          , x_value_combination_id     => l_adr_value_combination_id
36285          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
36286          , x_flex_value_set_id        => l_adr_flex_value_set_id
36287          , x_value_type_code          => l_adr_value_type_code
36289          , x_value_segment_code       => l_adr_value_segment_code
36290          , p_side                     => 'NA'
36291          , p_override_seg_flag        => 'Y'
36292    );
36293 
36294    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
36295 
36296       xla_ae_lines_pkg.set_segment(
36297           p_to_segment_code         => 'GL_ACCOUNT'
36298         , p_segment_value           => l_segment
36299         , p_from_segment_code       => l_adr_value_segment_code
36300         , p_from_combination_id     => l_adr_value_combination_id
36301         , p_value_type_code         => l_adr_value_type_code
36302         , p_transaction_coa_id      => l_adr_transaction_coa_id
36303         , p_accounting_coa_id       => l_adr_accounting_coa_id
36304         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
36305         , p_flex_value_set_id       => l_adr_flex_value_set_id
36306         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
36307         , p_adr_type_code           => 'S'
36308         , p_component_type          => l_component_type
36309         , p_component_code          => l_component_code
36310         , p_component_type_code     => l_component_type_code
36311         , p_component_appl_id       => l_component_appl_id
36312         , p_amb_context_code        => l_amb_context_code
36313         , p_entity_code             => 'TRANSACTIONS'
36314         , p_event_class_code        => 'CAPITALIZATION'
36315         , p_side                    => 'NA'
36316         );
36317 
36318   END IF;
36319 
36320    l_segment := AcctDerRule_168(
36321            p_application_id           => p_application_id
36322          , p_ae_header_id             => l_ae_header_id 
36323 , p_source_3 => p_source_3
36324 , p_source_29 => p_source_29
36325          , x_transaction_coa_id       => l_adr_transaction_coa_id
36326          , x_accounting_coa_id        => l_adr_accounting_coa_id
36327          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
36328          , x_flex_value_set_id        => l_adr_flex_value_set_id
36329          , x_value_type_code          => l_adr_value_type_code
36330          , x_value_combination_id     => l_adr_value_combination_id
36331          , x_value_segment_code       => l_adr_value_segment_code
36332          , p_side                     => 'NA'
36333          , p_override_seg_flag        => 'Y'
36334    );
36335 
36336    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
36337 
36338       xla_ae_lines_pkg.set_segment(
36339           p_to_segment_code         => 'GL_BALANCING'
36340         , p_segment_value           => l_segment
36341         , p_from_segment_code       => l_adr_value_segment_code
36342         , p_from_combination_id     => l_adr_value_combination_id
36343         , p_value_type_code         => l_adr_value_type_code
36344         , p_transaction_coa_id      => l_adr_transaction_coa_id
36345         , p_accounting_coa_id       => l_adr_accounting_coa_id
36346         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
36347         , p_flex_value_set_id       => l_adr_flex_value_set_id
36348         , p_adr_code                => 'FA_EXPENSE_ACCT'
36349         , p_adr_type_code           => 'S'
36350         , p_component_type          => l_component_type
36351         , p_component_code          => l_component_code
36352         , p_component_type_code     => l_component_type_code
36353         , p_component_appl_id       => l_component_appl_id
36354         , p_amb_context_code        => l_amb_context_code
36355         , p_entity_code             => 'TRANSACTIONS'
36356         , p_event_class_code        => 'CAPITALIZATION'
36357         , p_side                    => 'NA'
36358         );
36359 
36360   END IF;
36361 
36362    --
36363    --
36364    END IF;
36365 
36366        --
36367        -- Update the line information that should be overwritten
36368        --
36369        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
36370                                          p_header_num   => 1);
36371        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
36372 
36373        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
36374 
36375        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
36376           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
36377        END IF;
36378 
36379       --
36380       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
36381       --
36382       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
36383           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
36384       ELSE
36385           ---------------------------------------------------------------------------------------------------
36386           -- 4262811a Switch Sign
36387           ---------------------------------------------------------------------------------------------------
36388           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
36389           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36390                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36391           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36392                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36393           -- 5132302
36397       END IF;
36394           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
36395                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36396 
36398 
36399       -- 4955764
36400       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
36401       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
36402 
36403 
36404       XLA_AE_LINES_PKG.ValidateCurrentLine;
36405       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36406 
36407       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36408                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
36409                ,p_balance_type_code => l_balance_type_code);
36410 
36411    END IF;
36412 
36413    -----------------------------------------------------------------------------------------
36414    -- 4262811 Multiperiod Accounting
36415    -----------------------------------------------------------------------------------------
36416      -- No MPA option is assigned.
36417 
36418 
36419 END IF;
36420 END IF;
36421 --
36422 
36423 --
36424 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
36425    trace
36426       (p_msg      => 'END of AcctLineType_205'
36427       ,p_level    => C_LEVEL_PROCEDURE
36428       ,p_module   => l_log_module);
36429 END IF;
36430 --
36431 EXCEPTION
36432   WHEN xla_exceptions_pkg.application_exception THEN
36433       RAISE;
36434   WHEN OTHERS THEN
36435        xla_exceptions_pkg.raise_message
36436            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_205');
36437 END AcctLineType_205;
36438 --
36439 
36440 ---------------------------------------
36441 --
36442 -- PRIVATE FUNCTION
36443 --         AcctLineType_206
36444 --
36445 ---------------------------------------
36446 PROCEDURE AcctLineType_206 (
36447   p_application_id        IN NUMBER
36448  ,p_event_id              IN NUMBER
36449  ,p_calculate_acctd_flag  IN VARCHAR2
36450  ,p_calculate_g_l_flag    IN VARCHAR2
36451  ,p_actual_flag           IN OUT VARCHAR2
36452  ,p_balance_type_code     OUT VARCHAR2
36453  ,p_gain_or_loss_ref      OUT VARCHAR2
36454  
36455 --Period Close Date
36456  , p_source_1            IN DATE
36457 --Generated Code Combination Identifier
36458  , p_source_3            IN NUMBER
36459 --Depreciation Reserve Account
36460  , p_source_10            IN VARCHAR2
36461 --Generated Offset Code Combination Identifier
36462  , p_source_17            IN NUMBER
36463 --Expense Account Code Combination Identifier
36464  , p_source_29            IN NUMBER
36465 --Default Code Combination Identifier
36466  , p_source_30            IN NUMBER
36467 --Adjustment Type
36468  , p_source_35            IN VARCHAR2
36469 --Transaction Header Identifier
36470  , p_source_36            IN NUMBER
36471 --Adjustment Line Identifier
36472  , p_source_37            IN NUMBER
36473 --Distribution Type Code
36474  , p_source_38            IN VARCHAR2
36475 --Entered Amount
36476  , p_source_39            IN NUMBER
36477 --Currency Code
36478  , p_source_40            IN VARCHAR2
36479 )
36480 IS
36481 
36482 l_component_type              VARCHAR2(80);
36483 l_component_code              VARCHAR2(30);
36484 l_component_type_code         VARCHAR2(1);
36485 l_component_appl_id           INTEGER;
36486 l_amb_context_code            VARCHAR2(30);
36487 l_entity_code                 VARCHAR2(30);
36488 l_event_class_code            VARCHAR2(30);
36489 l_ae_header_id                NUMBER;
36490 l_event_type_code             VARCHAR2(30);
36491 l_line_definition_code        VARCHAR2(30);
36492 l_line_definition_owner_code  VARCHAR2(1);
36493 --
36494 -- adr variables
36495 l_segment                     VARCHAR2(30);
36496 l_ccid                        NUMBER;
36497 l_adr_transaction_coa_id      NUMBER;
36498 l_adr_accounting_coa_id       NUMBER;
36499 l_adr_flexfield_segment_code  VARCHAR2(30);
36500 l_adr_flex_value_set_id       NUMBER;
36501 l_adr_value_type_code         VARCHAR2(30);
36502 l_adr_value_combination_id    NUMBER;
36503 l_adr_value_segment_code      VARCHAR2(30);
36504 
36505 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
36506 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
36507 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
36508 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
36509 
36510 -- 4262811 Variables ------------------------------------------------------------------------------------------
36511 l_entered_amt_idx             NUMBER;
36512 l_accted_amt_idx              NUMBER;
36513 l_acc_rev_flag                VARCHAR2(1);
36514 l_accrual_line_num            NUMBER;
36515 l_tmp_amt                     NUMBER;
36516 l_acc_rev_natural_side_code   VARCHAR2(1);
36517 
36518 l_num_entries                 NUMBER;
36519 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
36520 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
36521 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
36522 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
36523 l_recog_line_1                NUMBER;
36524 l_recog_line_2                NUMBER;
36525 
36526 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
36527 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
36528 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
36529 
36530 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
36531 
36532 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
36536 
36533 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
36534 
36535 ---------------------------------------------------------------------------------------------------------------
36537 
36538 --
36539 -- bulk performance
36540 --
36541 l_balance_type_code           VARCHAR2(1);
36542 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
36543 l_log_module                  VARCHAR2(240);
36544 
36545 --
36546 -- Upgrade strategy
36547 --
36548 l_actual_upg_option           VARCHAR2(1);
36549 l_enc_upg_option           VARCHAR2(1);
36550 
36551 --
36552 BEGIN
36553 --
36554 IF g_log_enabled THEN
36555       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_206';
36556 END IF;
36557 --
36558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
36559 
36560       trace
36561          (p_msg      => 'BEGIN of AcctLineType_206'
36562          ,p_level    => C_LEVEL_PROCEDURE
36563          ,p_module   => l_log_module);
36564 
36565 END IF;
36566 --
36567 l_component_type             := 'AMB_JLT';
36568 l_component_code             := 'FA_CAP_RESERVE_BAL';
36569 l_component_type_code        := 'S';
36570 l_component_appl_id          :=  140;
36571 l_amb_context_code           := 'DEFAULT';
36572 l_entity_code                := 'TRANSACTIONS';
36573 l_event_class_code           := 'CAPITALIZATION';
36574 l_event_type_code            := 'CAPITALIZATION';
36575 l_line_definition_owner_code := 'S';
36576 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CAPITA3';
36577 --
36578 l_balance_type_code          := 'A';
36579 l_segment                     := NULL;
36580 l_ccid                        := NULL;
36581 l_adr_transaction_coa_id      := NULL;
36582 l_adr_accounting_coa_id       := NULL;
36583 l_adr_flexfield_segment_code  := NULL;
36584 l_adr_flex_value_set_id       := NULL;
36585 l_adr_value_type_code         := NULL;
36586 l_adr_value_combination_id    := NULL;
36587 l_adr_value_segment_code      := NULL;
36588 
36589 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
36590 l_bflow_class_code           := '';    -- 4219869 Business Flow
36591 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
36592 l_budgetary_control_flag     := 'N';
36593 
36594 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
36595 l_bflow_applied_to_amt       := NULL; -- 5132302
36596 l_entered_amt_idx            := NULL;          -- 4262811
36597 l_accted_amt_idx             := NULL;          -- 4262811
36598 l_acc_rev_flag               := NULL;          -- 4262811
36599 l_accrual_line_num           := NULL;          -- 4262811
36600 l_tmp_amt                    := NULL;          -- 4262811
36601 --
36602  
36603 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
36604     l_balance_type_code <> 'B' THEN
36605 IF NVL(p_source_35,'
36606 ') =  'BONUS EXPENSE'
36607  THEN 
36608 
36609    --
36610    XLA_AE_LINES_PKG.SetNewLine;
36611 
36612    p_balance_type_code          := l_balance_type_code;
36613    -- set the flag so later we will know whether the gain loss line needs to be created
36614    
36615    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
36616      p_actual_flag :='A';
36617    END IF;
36618 
36619    --
36620    -- bulk performance
36621    --
36622    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
36623                                       p_header_num   => 0); -- 4262811
36624    --
36625    -- set accounting line options
36626    --
36627    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
36628            p_natural_side_code          => 'D'
36629          , p_gain_or_loss_flag          => 'N'
36630          , p_gl_transfer_mode_code      => 'S'
36631          , p_acct_entry_type_code       => 'A'
36632          , p_switch_side_flag           => 'Y'
36633          , p_merge_duplicate_code       => 'N'
36634          );
36635    --
36636    l_acc_rev_natural_side_code := 'C';  -- 4262811
36637    -- 
36638    --
36639    -- set accounting line type info
36640    --
36641    xla_ae_lines_pkg.SetAcctLineType
36642       (p_component_type             => l_component_type
36643       ,p_event_type_code            => l_event_type_code
36644       ,p_line_definition_owner_code => l_line_definition_owner_code
36645       ,p_line_definition_code       => l_line_definition_code
36646       ,p_accounting_line_code       => l_component_code
36647       ,p_accounting_line_type_code  => l_component_type_code
36648       ,p_accounting_line_appl_id    => l_component_appl_id
36649       ,p_amb_context_code           => l_amb_context_code
36650       ,p_entity_code                => l_entity_code
36651       ,p_event_class_code           => l_event_class_code);
36652    --
36653    -- set accounting class
36654    --
36655    xla_ae_lines_pkg.SetAcctClass(
36656            p_accounting_class_code  => 'ASSET'
36657          , p_ae_header_id           => l_ae_header_id
36658          );
36659 
36660    --
36661    -- set rounding class
36662    --
36663    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
36664                       'ASSET';
36665 
36666    --
36667    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
36668    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
36669    --
36670    -- bulk performance
36671    --
36672    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
36673 
36674    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
36675       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
36676 
36677    -- 4955764
36681    -- 4458381 Public Sector Enh
36678    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
36679       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
36680 
36682    
36683    --
36684    -- set accounting attributes for the line type
36685    --
36686    l_entered_amt_idx := 4;
36687    l_accted_amt_idx  := 6;
36688    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
36689    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
36690    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
36691    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
36692    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
36693    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
36694    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
36695    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
36696    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
36697    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
36698    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
36699    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
36700    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
36701 
36702    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
36703    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
36704 
36705    ---------------------------------------------------------------------------------------------------------------
36706    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
36707    ---------------------------------------------------------------------------------------------------------------
36708    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
36709 
36710    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
36711    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
36712 
36713    IF xla_accounting_cache_pkg.GetValueChar
36714          (p_source_code         => 'LEDGER_CATEGORY_CODE'
36715          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
36716    AND l_bflow_method_code = 'PRIOR_ENTRY'
36717 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
36718    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
36719          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
36720        )
36721    THEN
36722          xla_ae_lines_pkg.BflowUpgEntry
36723            (p_business_method_code    => l_bflow_method_code
36724            ,p_business_class_code     => l_bflow_class_code
36725            ,p_balance_type            => l_balance_type_code);
36726    ELSE
36727       NULL;
36728 -- No business flow processing for business flow method of NONE.
36729    END IF;
36730 
36731    --
36732    -- call analytical criteria
36733    --
36734    
36735    --
36736    -- call description
36737    --
36738    
36739 xla_ae_lines_pkg.SetLineDescription(
36740    p_ae_header_id => l_ae_header_id
36741   ,p_description  => Description_22 (
36742      p_application_id         => p_application_id
36743    , p_ae_header_id           => l_ae_header_id 
36744 , p_source_1 => p_source_1
36745    )
36746 );
36747 
36748 
36749    --
36750    -- call ADRs
36751    -- Bug 4922099
36752    --
36753    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36754         (NVL(l_actual_upg_option, 'N') = 'O') OR
36755         (NVL(l_enc_upg_option, 'N') = 'O')
36756       )
36757    THEN
36758    NULL;
36759    --
36760    --
36761    
36762   l_ccid := AcctDerRule_174(
36763            p_application_id           => p_application_id
36764          , p_ae_header_id             => l_ae_header_id 
36765 , p_source_3 => p_source_3
36766 , p_source_17 => p_source_17
36767 , p_source_30 => p_source_30
36768          , x_transaction_coa_id       => l_adr_transaction_coa_id
36769          , x_accounting_coa_id        => l_adr_accounting_coa_id
36770          , x_value_type_code          => l_adr_value_type_code
36771          , p_side                     => 'NA'
36772    );
36773 
36774    xla_ae_lines_pkg.set_ccid(
36775     p_code_combination_id          => l_ccid
36776   , p_value_type_code              => l_adr_value_type_code
36777   , p_transaction_coa_id           => l_adr_transaction_coa_id
36778   , p_accounting_coa_id            => l_adr_accounting_coa_id
36779   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
36780   , p_adr_type_code                => 'S'
36781   , p_component_type               => l_component_type
36782   , p_component_code               => l_component_code
36783   , p_component_type_code          => l_component_type_code
36784   , p_component_appl_id            => l_component_appl_id
36785   , p_amb_context_code             => l_amb_context_code
36786   , p_side                         => 'NA'
36787   );
36788 
36789 
36790    l_segment := AcctDerRule_149(
36791            p_application_id           => p_application_id
36792          , p_ae_header_id             => l_ae_header_id 
36793 , p_source_3 => p_source_3
36794 , p_source_10 => p_source_10
36795          , x_transaction_coa_id       => l_adr_transaction_coa_id
36796          , x_accounting_coa_id        => l_adr_accounting_coa_id
36797          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
36798          , x_flex_value_set_id        => l_adr_flex_value_set_id
36799          , x_value_type_code          => l_adr_value_type_code
36800          , x_value_combination_id     => l_adr_value_combination_id
36801          , x_value_segment_code       => l_adr_value_segment_code
36802          , p_side                     => 'NA'
36806    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
36803          , p_override_seg_flag        => 'Y'
36804    );
36805 
36807 
36808       xla_ae_lines_pkg.set_segment(
36809           p_to_segment_code         => 'GL_ACCOUNT'
36810         , p_segment_value           => l_segment
36811         , p_from_segment_code       => l_adr_value_segment_code
36812         , p_from_combination_id     => l_adr_value_combination_id
36813         , p_value_type_code         => l_adr_value_type_code
36814         , p_transaction_coa_id      => l_adr_transaction_coa_id
36815         , p_accounting_coa_id       => l_adr_accounting_coa_id
36816         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
36817         , p_flex_value_set_id       => l_adr_flex_value_set_id
36818         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
36819         , p_adr_type_code           => 'S'
36820         , p_component_type          => l_component_type
36821         , p_component_code          => l_component_code
36822         , p_component_type_code     => l_component_type_code
36823         , p_component_appl_id       => l_component_appl_id
36824         , p_amb_context_code        => l_amb_context_code
36825         , p_entity_code             => 'TRANSACTIONS'
36826         , p_event_class_code        => 'CAPITALIZATION'
36827         , p_side                    => 'NA'
36828         );
36829 
36830   END IF;
36831 
36832    l_segment := AcctDerRule_168(
36833            p_application_id           => p_application_id
36834          , p_ae_header_id             => l_ae_header_id 
36835 , p_source_3 => p_source_3
36836 , p_source_29 => p_source_29
36837          , x_transaction_coa_id       => l_adr_transaction_coa_id
36838          , x_accounting_coa_id        => l_adr_accounting_coa_id
36839          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
36840          , x_flex_value_set_id        => l_adr_flex_value_set_id
36841          , x_value_type_code          => l_adr_value_type_code
36842          , x_value_combination_id     => l_adr_value_combination_id
36843          , x_value_segment_code       => l_adr_value_segment_code
36844          , p_side                     => 'NA'
36845          , p_override_seg_flag        => 'Y'
36846    );
36847 
36848    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
36849 
36850       xla_ae_lines_pkg.set_segment(
36851           p_to_segment_code         => 'GL_BALANCING'
36852         , p_segment_value           => l_segment
36853         , p_from_segment_code       => l_adr_value_segment_code
36854         , p_from_combination_id     => l_adr_value_combination_id
36855         , p_value_type_code         => l_adr_value_type_code
36856         , p_transaction_coa_id      => l_adr_transaction_coa_id
36857         , p_accounting_coa_id       => l_adr_accounting_coa_id
36858         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
36859         , p_flex_value_set_id       => l_adr_flex_value_set_id
36860         , p_adr_code                => 'FA_EXPENSE_ACCT'
36861         , p_adr_type_code           => 'S'
36862         , p_component_type          => l_component_type
36863         , p_component_code          => l_component_code
36864         , p_component_type_code     => l_component_type_code
36865         , p_component_appl_id       => l_component_appl_id
36866         , p_amb_context_code        => l_amb_context_code
36867         , p_entity_code             => 'TRANSACTIONS'
36868         , p_event_class_code        => 'CAPITALIZATION'
36869         , p_side                    => 'NA'
36870         );
36871 
36872   END IF;
36873 
36874    --
36875    --
36876    END IF;
36877    --
36878    -- Bug 4922099
36879    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
36880           (NVL(l_enc_upg_option, 'N') = 'O')
36881         ) AND
36882         (l_bflow_method_code = 'PRIOR_ENTRY')
36883       )
36884    THEN
36885       IF
36886       --
36887       1 = 2
36888       --
36889       THEN
36890       xla_accounting_err_pkg.build_message
36891                                     (p_appli_s_name            => 'XLA'
36892                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36893                                     ,p_token_1                 => 'LINE_NUMBER'
36894                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
36895                                     ,p_token_2                 => 'LINE_TYPE_NAME'
36896                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
36897                                                                              l_component_type
36898                                                                             ,l_component_code
36899                                                                             ,l_component_type_code
36900                                                                             ,l_component_appl_id
36901                                                                             ,l_amb_context_code
36902                                                                             ,l_entity_code
36903                                                                             ,l_event_class_code
36904                                                                            )
36905                                     ,p_token_3                 => 'OWNER'
36906                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
36907                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
36908                                                                           ,p_lookup_code    => l_component_type_code
36909                                                                          )
36910                                     ,p_token_4                 => 'PRODUCT_NAME'
36911                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
36915                                     ,p_ae_header_id            =>  NULL
36912                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
36913                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
36914                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
36916                                        );
36917 
36918         IF (C_LEVEL_ERROR>= g_log_level) THEN
36919                  trace
36920                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36921                       ,p_level    => C_LEVEL_ERROR
36922                       ,p_module   => l_log_module);
36923         END IF;
36924       END IF;
36925    END IF;
36926    --
36927    --
36928    ------------------------------------------------------------------------------------------------
36929    -- 4219869 Business Flow
36930    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
36931    -- Prior Entry.  Currently, the following code is always generated.
36932    ------------------------------------------------------------------------------------------------
36933    XLA_AE_LINES_PKG.ValidateCurrentLine;
36934 
36935    ------------------------------------------------------------------------------------
36936    -- 4219869 Business Flow
36937    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
36938    ------------------------------------------------------------------------------------
36939    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36940 
36941    ----------------------------------------------------------------------------------
36942    -- 4219869 Business Flow
36943    -- Update journal entry status -- Need to generate this within IF <condition>
36944    ----------------------------------------------------------------------------------
36945    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36946          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
36947          ,p_balance_type_code => l_balance_type_code
36948          );
36949 
36950    -------------------------------------------------------------------------------------------
36951    -- 4262811 - Generate the Accrual Reversal lines
36952    -------------------------------------------------------------------------------------------
36953    BEGIN
36954       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
36955                               (g_array_event(p_event_id).array_value_num('header_index'));
36956       IF l_acc_rev_flag IS NULL THEN
36957          l_acc_rev_flag := 'N';
36958       END IF;
36959    EXCEPTION
36960       WHEN OTHERS THEN
36961          l_acc_rev_flag := 'N';
36962    END;
36963    --
36964    IF (l_acc_rev_flag = 'Y') THEN
36965 
36966        -- 4645092  ------------------------------------------------------------------------------
36967        -- To allow MPA report to determine if it should generate report process
36968        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
36969        ------------------------------------------------------------------------------------------
36970 
36971        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
36972        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
36973    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
36974    -- call ADRs
36975    -- Bug 4922099
36976    --
36977    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36978         (NVL(l_actual_upg_option, 'N') = 'O') OR
36979         (NVL(l_enc_upg_option, 'N') = 'O')
36980       )
36981    THEN
36982    NULL;
36983    --
36984    --
36985    
36986   l_ccid := AcctDerRule_174(
36987            p_application_id           => p_application_id
36988          , p_ae_header_id             => l_ae_header_id 
36989 , p_source_3 => p_source_3
36990 , p_source_17 => p_source_17
36991 , p_source_30 => p_source_30
36992          , x_transaction_coa_id       => l_adr_transaction_coa_id
36993          , x_accounting_coa_id        => l_adr_accounting_coa_id
36994          , x_value_type_code          => l_adr_value_type_code
36995          , p_side                     => 'NA'
36996    );
36997 
36998    xla_ae_lines_pkg.set_ccid(
36999     p_code_combination_id          => l_ccid
37000   , p_value_type_code              => l_adr_value_type_code
37001   , p_transaction_coa_id           => l_adr_transaction_coa_id
37002   , p_accounting_coa_id            => l_adr_accounting_coa_id
37003   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
37004   , p_adr_type_code                => 'S'
37005   , p_component_type               => l_component_type
37006   , p_component_code               => l_component_code
37007   , p_component_type_code          => l_component_type_code
37008   , p_component_appl_id            => l_component_appl_id
37009   , p_amb_context_code             => l_amb_context_code
37010   , p_side                         => 'NA'
37011   );
37012 
37013 
37014    l_segment := AcctDerRule_149(
37015            p_application_id           => p_application_id
37016          , p_ae_header_id             => l_ae_header_id 
37017 , p_source_3 => p_source_3
37018 , p_source_10 => p_source_10
37019          , x_transaction_coa_id       => l_adr_transaction_coa_id
37020          , x_accounting_coa_id        => l_adr_accounting_coa_id
37021          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
37022          , x_flex_value_set_id        => l_adr_flex_value_set_id
37023          , x_value_type_code          => l_adr_value_type_code
37024          , x_value_combination_id     => l_adr_value_combination_id
37025          , x_value_segment_code       => l_adr_value_segment_code
37026          , p_side                     => 'NA'
37027          , p_override_seg_flag        => 'Y'
37028    );
37029 
37033           p_to_segment_code         => 'GL_ACCOUNT'
37030    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
37031 
37032       xla_ae_lines_pkg.set_segment(
37034         , p_segment_value           => l_segment
37035         , p_from_segment_code       => l_adr_value_segment_code
37036         , p_from_combination_id     => l_adr_value_combination_id
37037         , p_value_type_code         => l_adr_value_type_code
37038         , p_transaction_coa_id      => l_adr_transaction_coa_id
37039         , p_accounting_coa_id       => l_adr_accounting_coa_id
37040         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
37041         , p_flex_value_set_id       => l_adr_flex_value_set_id
37042         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
37043         , p_adr_type_code           => 'S'
37044         , p_component_type          => l_component_type
37045         , p_component_code          => l_component_code
37046         , p_component_type_code     => l_component_type_code
37047         , p_component_appl_id       => l_component_appl_id
37048         , p_amb_context_code        => l_amb_context_code
37049         , p_entity_code             => 'TRANSACTIONS'
37050         , p_event_class_code        => 'CAPITALIZATION'
37051         , p_side                    => 'NA'
37052         );
37053 
37054   END IF;
37055 
37056    l_segment := AcctDerRule_168(
37057            p_application_id           => p_application_id
37058          , p_ae_header_id             => l_ae_header_id 
37059 , p_source_3 => p_source_3
37060 , p_source_29 => p_source_29
37061          , x_transaction_coa_id       => l_adr_transaction_coa_id
37062          , x_accounting_coa_id        => l_adr_accounting_coa_id
37063          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
37064          , x_flex_value_set_id        => l_adr_flex_value_set_id
37065          , x_value_type_code          => l_adr_value_type_code
37066          , x_value_combination_id     => l_adr_value_combination_id
37067          , x_value_segment_code       => l_adr_value_segment_code
37068          , p_side                     => 'NA'
37069          , p_override_seg_flag        => 'Y'
37070    );
37071 
37072    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
37073 
37074       xla_ae_lines_pkg.set_segment(
37075           p_to_segment_code         => 'GL_BALANCING'
37076         , p_segment_value           => l_segment
37077         , p_from_segment_code       => l_adr_value_segment_code
37078         , p_from_combination_id     => l_adr_value_combination_id
37079         , p_value_type_code         => l_adr_value_type_code
37080         , p_transaction_coa_id      => l_adr_transaction_coa_id
37081         , p_accounting_coa_id       => l_adr_accounting_coa_id
37082         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
37083         , p_flex_value_set_id       => l_adr_flex_value_set_id
37084         , p_adr_code                => 'FA_EXPENSE_ACCT'
37085         , p_adr_type_code           => 'S'
37086         , p_component_type          => l_component_type
37087         , p_component_code          => l_component_code
37088         , p_component_type_code     => l_component_type_code
37089         , p_component_appl_id       => l_component_appl_id
37090         , p_amb_context_code        => l_amb_context_code
37091         , p_entity_code             => 'TRANSACTIONS'
37092         , p_event_class_code        => 'CAPITALIZATION'
37093         , p_side                    => 'NA'
37094         );
37095 
37096   END IF;
37097 
37098    --
37099    --
37100    END IF;
37101 
37102        --
37103        -- Update the line information that should be overwritten
37104        --
37105        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
37106                                          p_header_num   => 1);
37107        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
37108 
37109        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
37110 
37111        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
37112           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
37113        END IF;
37114 
37115       --
37116       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
37117       --
37118       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
37119           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
37120       ELSE
37121           ---------------------------------------------------------------------------------------------------
37122           -- 4262811a Switch Sign
37123           ---------------------------------------------------------------------------------------------------
37124           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
37125           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
37126                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37127           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
37128                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37129           -- 5132302
37130           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
37131                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37132 
37133       END IF;
37134 
37135       -- 4955764
37136       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
37137       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
37138 
37139 
37140       XLA_AE_LINES_PKG.ValidateCurrentLine;
37144                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
37141       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
37142 
37143       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
37145                ,p_balance_type_code => l_balance_type_code);
37146 
37147    END IF;
37148 
37149    -----------------------------------------------------------------------------------------
37150    -- 4262811 Multiperiod Accounting
37151    -----------------------------------------------------------------------------------------
37152      -- No MPA option is assigned.
37153 
37154 
37155 END IF;
37156 END IF;
37157 --
37158 
37159 --
37160 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
37161    trace
37162       (p_msg      => 'END of AcctLineType_206'
37163       ,p_level    => C_LEVEL_PROCEDURE
37164       ,p_module   => l_log_module);
37165 END IF;
37166 --
37167 EXCEPTION
37168   WHEN xla_exceptions_pkg.application_exception THEN
37169       RAISE;
37170   WHEN OTHERS THEN
37171        xla_exceptions_pkg.raise_message
37172            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_206');
37173 END AcctLineType_206;
37174 --
37175 
37176 ---------------------------------------
37177 --
37178 -- PRIVATE FUNCTION
37179 --         AcctLineType_207
37180 --
37181 ---------------------------------------
37182 PROCEDURE AcctLineType_207 (
37183   p_application_id        IN NUMBER
37184  ,p_event_id              IN NUMBER
37185  ,p_calculate_acctd_flag  IN VARCHAR2
37186  ,p_calculate_g_l_flag    IN VARCHAR2
37187  ,p_actual_flag           IN OUT VARCHAR2
37188  ,p_balance_type_code     OUT VARCHAR2
37189  ,p_gain_or_loss_ref      OUT VARCHAR2
37190  
37191 --Period Close Date
37192  , p_source_1            IN DATE
37193 --Generated Code Combination Identifier
37194  , p_source_3            IN NUMBER
37195 --CIP Cost Account
37196  , p_source_7            IN VARCHAR2
37197 --Expense Account Code Combination Identifier
37198  , p_source_29            IN NUMBER
37199 --Default Code Combination Identifier
37200  , p_source_30            IN NUMBER
37201 --Adjustment Type
37202  , p_source_35            IN VARCHAR2
37203 --Transaction Header Identifier
37204  , p_source_36            IN NUMBER
37205 --Adjustment Line Identifier
37206  , p_source_37            IN NUMBER
37207 --Distribution Type Code
37208  , p_source_38            IN VARCHAR2
37209 --Entered Amount
37210  , p_source_39            IN NUMBER
37211 --Currency Code
37212  , p_source_40            IN VARCHAR2
37213 )
37214 IS
37215 
37216 l_component_type              VARCHAR2(80);
37217 l_component_code              VARCHAR2(30);
37218 l_component_type_code         VARCHAR2(1);
37219 l_component_appl_id           INTEGER;
37220 l_amb_context_code            VARCHAR2(30);
37221 l_entity_code                 VARCHAR2(30);
37222 l_event_class_code            VARCHAR2(30);
37223 l_ae_header_id                NUMBER;
37224 l_event_type_code             VARCHAR2(30);
37225 l_line_definition_code        VARCHAR2(30);
37226 l_line_definition_owner_code  VARCHAR2(1);
37227 --
37228 -- adr variables
37229 l_segment                     VARCHAR2(30);
37230 l_ccid                        NUMBER;
37231 l_adr_transaction_coa_id      NUMBER;
37232 l_adr_accounting_coa_id       NUMBER;
37233 l_adr_flexfield_segment_code  VARCHAR2(30);
37234 l_adr_flex_value_set_id       NUMBER;
37235 l_adr_value_type_code         VARCHAR2(30);
37236 l_adr_value_combination_id    NUMBER;
37237 l_adr_value_segment_code      VARCHAR2(30);
37238 
37239 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
37240 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
37241 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
37242 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
37243 
37244 -- 4262811 Variables ------------------------------------------------------------------------------------------
37245 l_entered_amt_idx             NUMBER;
37246 l_accted_amt_idx              NUMBER;
37247 l_acc_rev_flag                VARCHAR2(1);
37248 l_accrual_line_num            NUMBER;
37249 l_tmp_amt                     NUMBER;
37250 l_acc_rev_natural_side_code   VARCHAR2(1);
37251 
37252 l_num_entries                 NUMBER;
37253 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
37254 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
37255 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
37256 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
37257 l_recog_line_1                NUMBER;
37258 l_recog_line_2                NUMBER;
37259 
37260 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
37261 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
37262 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
37263 
37264 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
37265 
37266 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
37267 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
37268 
37269 ---------------------------------------------------------------------------------------------------------------
37270 
37271 
37272 --
37273 -- bulk performance
37274 --
37275 l_balance_type_code           VARCHAR2(1);
37276 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
37277 l_log_module                  VARCHAR2(240);
37278 
37279 --
37280 -- Upgrade strategy
37281 --
37282 l_actual_upg_option           VARCHAR2(1);
37283 l_enc_upg_option           VARCHAR2(1);
37284 
37285 --
37286 BEGIN
37287 --
37291 --
37288 IF g_log_enabled THEN
37289       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_207';
37290 END IF;
37292 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
37293 
37294       trace
37295          (p_msg      => 'BEGIN of AcctLineType_207'
37296          ,p_level    => C_LEVEL_PROCEDURE
37297          ,p_module   => l_log_module);
37298 
37299 END IF;
37300 --
37301 l_component_type             := 'AMB_JLT';
37302 l_component_code             := 'FA_CIP_ADD_COST';
37303 l_component_type_code        := 'S';
37304 l_component_appl_id          :=  140;
37305 l_amb_context_code           := 'DEFAULT';
37306 l_entity_code                := 'TRANSACTIONS';
37307 l_event_class_code           := 'CIP_ADDITIONS';
37308 l_event_type_code            := 'CIP_ADDITIONS_ALL';
37309 l_line_definition_owner_code := 'S';
37310 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_AD5';
37311 --
37312 l_balance_type_code          := 'A';
37313 l_segment                     := NULL;
37314 l_ccid                        := NULL;
37315 l_adr_transaction_coa_id      := NULL;
37316 l_adr_accounting_coa_id       := NULL;
37317 l_adr_flexfield_segment_code  := NULL;
37318 l_adr_flex_value_set_id       := NULL;
37319 l_adr_value_type_code         := NULL;
37320 l_adr_value_combination_id    := NULL;
37321 l_adr_value_segment_code      := NULL;
37322 
37323 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
37324 l_bflow_class_code           := '';    -- 4219869 Business Flow
37325 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
37326 l_budgetary_control_flag     := 'N';
37327 
37328 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
37329 l_bflow_applied_to_amt       := NULL; -- 5132302
37330 l_entered_amt_idx            := NULL;          -- 4262811
37331 l_accted_amt_idx             := NULL;          -- 4262811
37332 l_acc_rev_flag               := NULL;          -- 4262811
37333 l_accrual_line_num           := NULL;          -- 4262811
37334 l_tmp_amt                    := NULL;          -- 4262811
37335 --
37336  
37337 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
37338     l_balance_type_code <> 'B' THEN
37339 IF NVL(p_source_35,'
37340 ') =  'CIP COST'
37341  THEN 
37342 
37343    --
37344    XLA_AE_LINES_PKG.SetNewLine;
37345 
37346    p_balance_type_code          := l_balance_type_code;
37347    -- set the flag so later we will know whether the gain loss line needs to be created
37348    
37349    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
37350      p_actual_flag :='A';
37351    END IF;
37352 
37353    --
37354    -- bulk performance
37355    --
37356    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
37357                                       p_header_num   => 0); -- 4262811
37358    --
37359    -- set accounting line options
37360    --
37361    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
37362            p_natural_side_code          => 'D'
37363          , p_gain_or_loss_flag          => 'N'
37364          , p_gl_transfer_mode_code      => 'S'
37365          , p_acct_entry_type_code       => 'A'
37366          , p_switch_side_flag           => 'Y'
37367          , p_merge_duplicate_code       => 'N'
37368          );
37369    --
37370    l_acc_rev_natural_side_code := 'C';  -- 4262811
37371    -- 
37372    --
37373    -- set accounting line type info
37374    --
37375    xla_ae_lines_pkg.SetAcctLineType
37376       (p_component_type             => l_component_type
37377       ,p_event_type_code            => l_event_type_code
37378       ,p_line_definition_owner_code => l_line_definition_owner_code
37379       ,p_line_definition_code       => l_line_definition_code
37380       ,p_accounting_line_code       => l_component_code
37381       ,p_accounting_line_type_code  => l_component_type_code
37382       ,p_accounting_line_appl_id    => l_component_appl_id
37383       ,p_amb_context_code           => l_amb_context_code
37384       ,p_entity_code                => l_entity_code
37385       ,p_event_class_code           => l_event_class_code);
37386    --
37387    -- set accounting class
37388    --
37389    xla_ae_lines_pkg.SetAcctClass(
37390            p_accounting_class_code  => 'ASSET'
37391          , p_ae_header_id           => l_ae_header_id
37392          );
37393 
37394    --
37395    -- set rounding class
37396    --
37397    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
37398                       'ASSET';
37399 
37400    --
37401    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
37402    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
37403    --
37404    -- bulk performance
37405    --
37406    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
37407 
37408    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
37409       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
37410 
37411    -- 4955764
37412    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
37413       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
37414 
37415    -- 4458381 Public Sector Enh
37416    
37417    --
37418    -- set accounting attributes for the line type
37419    --
37420    l_entered_amt_idx := 4;
37421    l_accted_amt_idx  := 6;
37422    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
37423    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
37424    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
37425    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
37429    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
37426    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
37427    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
37428    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
37430    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
37431    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
37432    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
37433    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
37434    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
37435 
37436    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
37437    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
37438 
37439    ---------------------------------------------------------------------------------------------------------------
37440    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
37441    ---------------------------------------------------------------------------------------------------------------
37442    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
37443 
37444    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37445    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37446 
37447    IF xla_accounting_cache_pkg.GetValueChar
37448          (p_source_code         => 'LEDGER_CATEGORY_CODE'
37449          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
37450    AND l_bflow_method_code = 'PRIOR_ENTRY'
37451 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
37452    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
37453          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
37454        )
37455    THEN
37456          xla_ae_lines_pkg.BflowUpgEntry
37457            (p_business_method_code    => l_bflow_method_code
37458            ,p_business_class_code     => l_bflow_class_code
37459            ,p_balance_type            => l_balance_type_code);
37460    ELSE
37461       NULL;
37462 -- No business flow processing for business flow method of NONE.
37463    END IF;
37464 
37465    --
37466    -- call analytical criteria
37467    --
37468    
37469    --
37470    -- call description
37471    --
37472    
37473 xla_ae_lines_pkg.SetLineDescription(
37474    p_ae_header_id => l_ae_header_id
37475   ,p_description  => Description_24 (
37476      p_application_id         => p_application_id
37477    , p_ae_header_id           => l_ae_header_id 
37478 , p_source_1 => p_source_1
37479    )
37480 );
37481 
37482 
37483    --
37484    -- call ADRs
37485    -- Bug 4922099
37486    --
37487    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37488         (NVL(l_actual_upg_option, 'N') = 'O') OR
37489         (NVL(l_enc_upg_option, 'N') = 'O')
37490       )
37491    THEN
37492    NULL;
37493    --
37494    --
37495    
37496   l_ccid := AcctDerRule_173(
37497            p_application_id           => p_application_id
37498          , p_ae_header_id             => l_ae_header_id 
37499 , p_source_3 => p_source_3
37500 , p_source_30 => p_source_30
37501          , x_transaction_coa_id       => l_adr_transaction_coa_id
37502          , x_accounting_coa_id        => l_adr_accounting_coa_id
37503          , x_value_type_code          => l_adr_value_type_code
37504          , p_side                     => 'NA'
37505    );
37506 
37507    xla_ae_lines_pkg.set_ccid(
37508     p_code_combination_id          => l_ccid
37509   , p_value_type_code              => l_adr_value_type_code
37510   , p_transaction_coa_id           => l_adr_transaction_coa_id
37511   , p_accounting_coa_id            => l_adr_accounting_coa_id
37512   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
37513   , p_adr_type_code                => 'S'
37514   , p_component_type               => l_component_type
37515   , p_component_code               => l_component_code
37516   , p_component_type_code          => l_component_type_code
37517   , p_component_appl_id            => l_component_appl_id
37518   , p_amb_context_code             => l_amb_context_code
37519   , p_side                         => 'NA'
37520   );
37521 
37522 
37523    l_segment := AcctDerRule_146(
37524            p_application_id           => p_application_id
37525          , p_ae_header_id             => l_ae_header_id 
37526 , p_source_3 => p_source_3
37527 , p_source_7 => p_source_7
37528          , x_transaction_coa_id       => l_adr_transaction_coa_id
37529          , x_accounting_coa_id        => l_adr_accounting_coa_id
37530          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
37531          , x_flex_value_set_id        => l_adr_flex_value_set_id
37532          , x_value_type_code          => l_adr_value_type_code
37533          , x_value_combination_id     => l_adr_value_combination_id
37534          , x_value_segment_code       => l_adr_value_segment_code
37535          , p_side                     => 'NA'
37536          , p_override_seg_flag        => 'Y'
37537    );
37538 
37539    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
37540 
37541       xla_ae_lines_pkg.set_segment(
37542           p_to_segment_code         => 'GL_ACCOUNT'
37543         , p_segment_value           => l_segment
37544         , p_from_segment_code       => l_adr_value_segment_code
37545         , p_from_combination_id     => l_adr_value_combination_id
37546         , p_value_type_code         => l_adr_value_type_code
37547         , p_transaction_coa_id      => l_adr_transaction_coa_id
37548         , p_accounting_coa_id       => l_adr_accounting_coa_id
37549         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
37553         , p_component_type          => l_component_type
37550         , p_flex_value_set_id       => l_adr_flex_value_set_id
37551         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
37552         , p_adr_type_code           => 'S'
37554         , p_component_code          => l_component_code
37555         , p_component_type_code     => l_component_type_code
37556         , p_component_appl_id       => l_component_appl_id
37557         , p_amb_context_code        => l_amb_context_code
37558         , p_entity_code             => 'TRANSACTIONS'
37559         , p_event_class_code        => 'CIP_ADDITIONS'
37560         , p_side                    => 'NA'
37561         );
37562 
37563   END IF;
37564 
37565    l_segment := AcctDerRule_168(
37566            p_application_id           => p_application_id
37567          , p_ae_header_id             => l_ae_header_id 
37568 , p_source_3 => p_source_3
37569 , p_source_29 => p_source_29
37570          , x_transaction_coa_id       => l_adr_transaction_coa_id
37571          , x_accounting_coa_id        => l_adr_accounting_coa_id
37572          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
37573          , x_flex_value_set_id        => l_adr_flex_value_set_id
37574          , x_value_type_code          => l_adr_value_type_code
37575          , x_value_combination_id     => l_adr_value_combination_id
37576          , x_value_segment_code       => l_adr_value_segment_code
37577          , p_side                     => 'NA'
37578          , p_override_seg_flag        => 'Y'
37579    );
37580 
37581    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
37582 
37583       xla_ae_lines_pkg.set_segment(
37584           p_to_segment_code         => 'GL_BALANCING'
37585         , p_segment_value           => l_segment
37586         , p_from_segment_code       => l_adr_value_segment_code
37587         , p_from_combination_id     => l_adr_value_combination_id
37588         , p_value_type_code         => l_adr_value_type_code
37589         , p_transaction_coa_id      => l_adr_transaction_coa_id
37590         , p_accounting_coa_id       => l_adr_accounting_coa_id
37591         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
37592         , p_flex_value_set_id       => l_adr_flex_value_set_id
37593         , p_adr_code                => 'FA_EXPENSE_ACCT'
37594         , p_adr_type_code           => 'S'
37595         , p_component_type          => l_component_type
37596         , p_component_code          => l_component_code
37597         , p_component_type_code     => l_component_type_code
37598         , p_component_appl_id       => l_component_appl_id
37599         , p_amb_context_code        => l_amb_context_code
37600         , p_entity_code             => 'TRANSACTIONS'
37601         , p_event_class_code        => 'CIP_ADDITIONS'
37602         , p_side                    => 'NA'
37603         );
37604 
37605   END IF;
37606 
37607    --
37608    --
37609    END IF;
37610    --
37611    -- Bug 4922099
37612    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
37613           (NVL(l_enc_upg_option, 'N') = 'O')
37614         ) AND
37615         (l_bflow_method_code = 'PRIOR_ENTRY')
37616       )
37617    THEN
37618       IF
37619       --
37620       1 = 2
37621       --
37622       THEN
37623       xla_accounting_err_pkg.build_message
37624                                     (p_appli_s_name            => 'XLA'
37625                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37626                                     ,p_token_1                 => 'LINE_NUMBER'
37627                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
37628                                     ,p_token_2                 => 'LINE_TYPE_NAME'
37629                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
37630                                                                              l_component_type
37631                                                                             ,l_component_code
37632                                                                             ,l_component_type_code
37633                                                                             ,l_component_appl_id
37634                                                                             ,l_amb_context_code
37635                                                                             ,l_entity_code
37636                                                                             ,l_event_class_code
37637                                                                            )
37638                                     ,p_token_3                 => 'OWNER'
37639                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
37640                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
37641                                                                           ,p_lookup_code    => l_component_type_code
37642                                                                          )
37643                                     ,p_token_4                 => 'PRODUCT_NAME'
37644                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
37645                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
37646                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
37647                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
37648                                     ,p_ae_header_id            =>  NULL
37649                                        );
37650 
37651         IF (C_LEVEL_ERROR>= g_log_level) THEN
37652                  trace
37653                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37654                       ,p_level    => C_LEVEL_ERROR
37658    END IF;
37655                       ,p_module   => l_log_module);
37656         END IF;
37657       END IF;
37659    --
37660    --
37661    ------------------------------------------------------------------------------------------------
37662    -- 4219869 Business Flow
37663    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
37664    -- Prior Entry.  Currently, the following code is always generated.
37665    ------------------------------------------------------------------------------------------------
37666    XLA_AE_LINES_PKG.ValidateCurrentLine;
37667 
37668    ------------------------------------------------------------------------------------
37669    -- 4219869 Business Flow
37670    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
37671    ------------------------------------------------------------------------------------
37672    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
37673 
37674    ----------------------------------------------------------------------------------
37675    -- 4219869 Business Flow
37676    -- Update journal entry status -- Need to generate this within IF <condition>
37677    ----------------------------------------------------------------------------------
37678    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
37679          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
37680          ,p_balance_type_code => l_balance_type_code
37681          );
37682 
37683    -------------------------------------------------------------------------------------------
37684    -- 4262811 - Generate the Accrual Reversal lines
37685    -------------------------------------------------------------------------------------------
37686    BEGIN
37687       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
37688                               (g_array_event(p_event_id).array_value_num('header_index'));
37689       IF l_acc_rev_flag IS NULL THEN
37690          l_acc_rev_flag := 'N';
37691       END IF;
37692    EXCEPTION
37693       WHEN OTHERS THEN
37694          l_acc_rev_flag := 'N';
37695    END;
37696    --
37697    IF (l_acc_rev_flag = 'Y') THEN
37698 
37699        -- 4645092  ------------------------------------------------------------------------------
37700        -- To allow MPA report to determine if it should generate report process
37701        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
37702        ------------------------------------------------------------------------------------------
37703 
37704        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
37705        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
37706    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
37707    -- call ADRs
37708    -- Bug 4922099
37709    --
37710    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37711         (NVL(l_actual_upg_option, 'N') = 'O') OR
37712         (NVL(l_enc_upg_option, 'N') = 'O')
37713       )
37714    THEN
37715    NULL;
37716    --
37717    --
37718    
37719   l_ccid := AcctDerRule_173(
37720            p_application_id           => p_application_id
37721          , p_ae_header_id             => l_ae_header_id 
37722 , p_source_3 => p_source_3
37723 , p_source_30 => p_source_30
37724          , x_transaction_coa_id       => l_adr_transaction_coa_id
37725          , x_accounting_coa_id        => l_adr_accounting_coa_id
37726          , x_value_type_code          => l_adr_value_type_code
37727          , p_side                     => 'NA'
37728    );
37729 
37730    xla_ae_lines_pkg.set_ccid(
37731     p_code_combination_id          => l_ccid
37732   , p_value_type_code              => l_adr_value_type_code
37733   , p_transaction_coa_id           => l_adr_transaction_coa_id
37734   , p_accounting_coa_id            => l_adr_accounting_coa_id
37735   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
37736   , p_adr_type_code                => 'S'
37737   , p_component_type               => l_component_type
37738   , p_component_code               => l_component_code
37739   , p_component_type_code          => l_component_type_code
37740   , p_component_appl_id            => l_component_appl_id
37741   , p_amb_context_code             => l_amb_context_code
37742   , p_side                         => 'NA'
37743   );
37744 
37745 
37746    l_segment := AcctDerRule_146(
37747            p_application_id           => p_application_id
37748          , p_ae_header_id             => l_ae_header_id 
37749 , p_source_3 => p_source_3
37750 , p_source_7 => p_source_7
37751          , x_transaction_coa_id       => l_adr_transaction_coa_id
37752          , x_accounting_coa_id        => l_adr_accounting_coa_id
37753          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
37754          , x_flex_value_set_id        => l_adr_flex_value_set_id
37755          , x_value_type_code          => l_adr_value_type_code
37756          , x_value_combination_id     => l_adr_value_combination_id
37757          , x_value_segment_code       => l_adr_value_segment_code
37758          , p_side                     => 'NA'
37759          , p_override_seg_flag        => 'Y'
37760    );
37761 
37762    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
37763 
37764       xla_ae_lines_pkg.set_segment(
37765           p_to_segment_code         => 'GL_ACCOUNT'
37766         , p_segment_value           => l_segment
37767         , p_from_segment_code       => l_adr_value_segment_code
37768         , p_from_combination_id     => l_adr_value_combination_id
37769         , p_value_type_code         => l_adr_value_type_code
37770         , p_transaction_coa_id      => l_adr_transaction_coa_id
37771         , p_accounting_coa_id       => l_adr_accounting_coa_id
37772         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
37773         , p_flex_value_set_id       => l_adr_flex_value_set_id
37777         , p_component_code          => l_component_code
37774         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
37775         , p_adr_type_code           => 'S'
37776         , p_component_type          => l_component_type
37778         , p_component_type_code     => l_component_type_code
37779         , p_component_appl_id       => l_component_appl_id
37780         , p_amb_context_code        => l_amb_context_code
37781         , p_entity_code             => 'TRANSACTIONS'
37782         , p_event_class_code        => 'CIP_ADDITIONS'
37783         , p_side                    => 'NA'
37784         );
37785 
37786   END IF;
37787 
37788    l_segment := AcctDerRule_168(
37789            p_application_id           => p_application_id
37790          , p_ae_header_id             => l_ae_header_id 
37791 , p_source_3 => p_source_3
37792 , p_source_29 => p_source_29
37793          , x_transaction_coa_id       => l_adr_transaction_coa_id
37794          , x_accounting_coa_id        => l_adr_accounting_coa_id
37795          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
37796          , x_flex_value_set_id        => l_adr_flex_value_set_id
37797          , x_value_type_code          => l_adr_value_type_code
37798          , x_value_combination_id     => l_adr_value_combination_id
37799          , x_value_segment_code       => l_adr_value_segment_code
37800          , p_side                     => 'NA'
37801          , p_override_seg_flag        => 'Y'
37802    );
37803 
37804    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
37805 
37806       xla_ae_lines_pkg.set_segment(
37807           p_to_segment_code         => 'GL_BALANCING'
37808         , p_segment_value           => l_segment
37809         , p_from_segment_code       => l_adr_value_segment_code
37810         , p_from_combination_id     => l_adr_value_combination_id
37811         , p_value_type_code         => l_adr_value_type_code
37812         , p_transaction_coa_id      => l_adr_transaction_coa_id
37813         , p_accounting_coa_id       => l_adr_accounting_coa_id
37814         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
37815         , p_flex_value_set_id       => l_adr_flex_value_set_id
37816         , p_adr_code                => 'FA_EXPENSE_ACCT'
37817         , p_adr_type_code           => 'S'
37818         , p_component_type          => l_component_type
37819         , p_component_code          => l_component_code
37820         , p_component_type_code     => l_component_type_code
37821         , p_component_appl_id       => l_component_appl_id
37822         , p_amb_context_code        => l_amb_context_code
37823         , p_entity_code             => 'TRANSACTIONS'
37824         , p_event_class_code        => 'CIP_ADDITIONS'
37825         , p_side                    => 'NA'
37826         );
37827 
37828   END IF;
37829 
37830    --
37831    --
37832    END IF;
37833 
37834        --
37835        -- Update the line information that should be overwritten
37836        --
37837        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
37838                                          p_header_num   => 1);
37839        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
37840 
37841        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
37842 
37843        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
37844           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
37845        END IF;
37846 
37847       --
37848       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
37849       --
37850       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
37851           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
37852       ELSE
37853           ---------------------------------------------------------------------------------------------------
37854           -- 4262811a Switch Sign
37855           ---------------------------------------------------------------------------------------------------
37856           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
37857           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
37858                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37859           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
37860                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37861           -- 5132302
37862           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
37863                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37864 
37865       END IF;
37866 
37867       -- 4955764
37868       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
37869       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
37870 
37871 
37872       XLA_AE_LINES_PKG.ValidateCurrentLine;
37873       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
37874 
37875       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
37876                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
37877                ,p_balance_type_code => l_balance_type_code);
37878 
37879    END IF;
37880 
37881    -----------------------------------------------------------------------------------------
37882    -- 4262811 Multiperiod Accounting
37883    -----------------------------------------------------------------------------------------
37884      -- No MPA option is assigned.
37885 
37886 
37887 END IF;
37888 END IF;
37889 --
37890 
37894       (p_msg      => 'END of AcctLineType_207'
37891 --
37892 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
37893    trace
37895       ,p_level    => C_LEVEL_PROCEDURE
37896       ,p_module   => l_log_module);
37897 END IF;
37898 --
37899 EXCEPTION
37900   WHEN xla_exceptions_pkg.application_exception THEN
37901       RAISE;
37902   WHEN OTHERS THEN
37903        xla_exceptions_pkg.raise_message
37904            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_207');
37905 END AcctLineType_207;
37906 --
37907 
37908 ---------------------------------------
37909 --
37910 -- PRIVATE FUNCTION
37911 --         AcctLineType_208
37912 --
37913 ---------------------------------------
37914 PROCEDURE AcctLineType_208 (
37915   p_application_id        IN NUMBER
37916  ,p_event_id              IN NUMBER
37917  ,p_calculate_acctd_flag  IN VARCHAR2
37918  ,p_calculate_g_l_flag    IN VARCHAR2
37919  ,p_actual_flag           IN OUT VARCHAR2
37920  ,p_balance_type_code     OUT VARCHAR2
37921  ,p_gain_or_loss_ref      OUT VARCHAR2
37922  
37923 --Period Close Date
37924  , p_source_1            IN DATE
37925 --Generated Code Combination Identifier
37926  , p_source_3            IN NUMBER
37927 --CIP Clearing Account
37928  , p_source_5            IN VARCHAR2
37929 --Payables Code Combination Identifier
37930  , p_source_6            IN NUMBER
37931 --Expense Account Code Combination Identifier
37932  , p_source_29            IN NUMBER
37933 --Default Code Combination Identifier
37934  , p_source_30            IN NUMBER
37935 --Adjustment Type
37936  , p_source_35            IN VARCHAR2
37937 --Transaction Header Identifier
37938  , p_source_36            IN NUMBER
37939 --Adjustment Line Identifier
37940  , p_source_37            IN NUMBER
37941 --Distribution Type Code
37942  , p_source_38            IN VARCHAR2
37943 --Entered Amount
37944  , p_source_39            IN NUMBER
37945 --Currency Code
37946  , p_source_40            IN VARCHAR2
37947 )
37948 IS
37949 
37950 l_component_type              VARCHAR2(80);
37951 l_component_code              VARCHAR2(30);
37952 l_component_type_code         VARCHAR2(1);
37953 l_component_appl_id           INTEGER;
37954 l_amb_context_code            VARCHAR2(30);
37955 l_entity_code                 VARCHAR2(30);
37956 l_event_class_code            VARCHAR2(30);
37957 l_ae_header_id                NUMBER;
37958 l_event_type_code             VARCHAR2(30);
37959 l_line_definition_code        VARCHAR2(30);
37960 l_line_definition_owner_code  VARCHAR2(1);
37961 --
37962 -- adr variables
37963 l_segment                     VARCHAR2(30);
37964 l_ccid                        NUMBER;
37965 l_adr_transaction_coa_id      NUMBER;
37966 l_adr_accounting_coa_id       NUMBER;
37967 l_adr_flexfield_segment_code  VARCHAR2(30);
37968 l_adr_flex_value_set_id       NUMBER;
37969 l_adr_value_type_code         VARCHAR2(30);
37970 l_adr_value_combination_id    NUMBER;
37971 l_adr_value_segment_code      VARCHAR2(30);
37972 
37973 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
37974 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
37975 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
37976 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
37977 
37978 -- 4262811 Variables ------------------------------------------------------------------------------------------
37979 l_entered_amt_idx             NUMBER;
37980 l_accted_amt_idx              NUMBER;
37981 l_acc_rev_flag                VARCHAR2(1);
37982 l_accrual_line_num            NUMBER;
37983 l_tmp_amt                     NUMBER;
37984 l_acc_rev_natural_side_code   VARCHAR2(1);
37985 
37986 l_num_entries                 NUMBER;
37987 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
37988 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
37989 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
37990 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
37991 l_recog_line_1                NUMBER;
37992 l_recog_line_2                NUMBER;
37993 
37994 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
37995 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
37996 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
37997 
37998 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
37999 
38000 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
38001 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
38002 
38003 ---------------------------------------------------------------------------------------------------------------
38004 
38005 
38006 --
38007 -- bulk performance
38008 --
38009 l_balance_type_code           VARCHAR2(1);
38010 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
38011 l_log_module                  VARCHAR2(240);
38012 
38013 --
38014 -- Upgrade strategy
38015 --
38016 l_actual_upg_option           VARCHAR2(1);
38017 l_enc_upg_option           VARCHAR2(1);
38018 
38019 --
38020 BEGIN
38021 --
38022 IF g_log_enabled THEN
38023       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_208';
38024 END IF;
38025 --
38026 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38027 
38028       trace
38029          (p_msg      => 'BEGIN of AcctLineType_208'
38030          ,p_level    => C_LEVEL_PROCEDURE
38031          ,p_module   => l_log_module);
38032 
38033 END IF;
38034 --
38035 l_component_type             := 'AMB_JLT';
38036 l_component_code             := 'FA_CIP_ADD_COST_CLEARING';
38037 l_component_type_code        := 'S';
38041 l_event_class_code           := 'CIP_ADDITIONS';
38038 l_component_appl_id          :=  140;
38039 l_amb_context_code           := 'DEFAULT';
38040 l_entity_code                := 'TRANSACTIONS';
38042 l_event_type_code            := 'CIP_ADDITIONS_ALL';
38043 l_line_definition_owner_code := 'S';
38044 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_AD5';
38045 --
38046 l_balance_type_code          := 'A';
38047 l_segment                     := NULL;
38048 l_ccid                        := NULL;
38049 l_adr_transaction_coa_id      := NULL;
38050 l_adr_accounting_coa_id       := NULL;
38051 l_adr_flexfield_segment_code  := NULL;
38052 l_adr_flex_value_set_id       := NULL;
38053 l_adr_value_type_code         := NULL;
38054 l_adr_value_combination_id    := NULL;
38055 l_adr_value_segment_code      := NULL;
38056 
38057 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
38058 l_bflow_class_code           := '';    -- 4219869 Business Flow
38059 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
38060 l_budgetary_control_flag     := 'N';
38061 
38062 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
38063 l_bflow_applied_to_amt       := NULL; -- 5132302
38064 l_entered_amt_idx            := NULL;          -- 4262811
38065 l_accted_amt_idx             := NULL;          -- 4262811
38066 l_acc_rev_flag               := NULL;          -- 4262811
38067 l_accrual_line_num           := NULL;          -- 4262811
38068 l_tmp_amt                    := NULL;          -- 4262811
38069 --
38070  
38071 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
38072     l_balance_type_code <> 'B' THEN
38073 IF NVL(p_source_35,'
38074 ') =  'COST CLEARING'
38075  THEN 
38076 
38077    --
38078    XLA_AE_LINES_PKG.SetNewLine;
38079 
38080    p_balance_type_code          := l_balance_type_code;
38081    -- set the flag so later we will know whether the gain loss line needs to be created
38082    
38083    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
38084      p_actual_flag :='A';
38085    END IF;
38086 
38087    --
38088    -- bulk performance
38089    --
38090    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
38091                                       p_header_num   => 0); -- 4262811
38092    --
38093    -- set accounting line options
38094    --
38095    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
38096            p_natural_side_code          => 'C'
38097          , p_gain_or_loss_flag          => 'N'
38098          , p_gl_transfer_mode_code      => 'S'
38099          , p_acct_entry_type_code       => 'A'
38100          , p_switch_side_flag           => 'Y'
38101          , p_merge_duplicate_code       => 'N'
38102          );
38103    --
38104    l_acc_rev_natural_side_code := 'D';  -- 4262811
38105    -- 
38106    --
38107    -- set accounting line type info
38108    --
38109    xla_ae_lines_pkg.SetAcctLineType
38110       (p_component_type             => l_component_type
38111       ,p_event_type_code            => l_event_type_code
38112       ,p_line_definition_owner_code => l_line_definition_owner_code
38113       ,p_line_definition_code       => l_line_definition_code
38114       ,p_accounting_line_code       => l_component_code
38115       ,p_accounting_line_type_code  => l_component_type_code
38116       ,p_accounting_line_appl_id    => l_component_appl_id
38117       ,p_amb_context_code           => l_amb_context_code
38118       ,p_entity_code                => l_entity_code
38119       ,p_event_class_code           => l_event_class_code);
38120    --
38121    -- set accounting class
38122    --
38123    xla_ae_lines_pkg.SetAcctClass(
38124            p_accounting_class_code  => 'ASSET'
38125          , p_ae_header_id           => l_ae_header_id
38126          );
38127 
38128    --
38129    -- set rounding class
38130    --
38131    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
38132                       'ASSET';
38133 
38134    --
38135    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
38136    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
38137    --
38138    -- bulk performance
38139    --
38140    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
38141 
38142    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
38143       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
38144 
38145    -- 4955764
38146    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
38147       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
38148 
38149    -- 4458381 Public Sector Enh
38150    
38151    --
38152    -- set accounting attributes for the line type
38153    --
38154    l_entered_amt_idx := 4;
38155    l_accted_amt_idx  := 6;
38156    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
38157    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
38158    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
38159    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
38160    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
38161    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
38162    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
38163    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
38164    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
38165    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
38166    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
38167    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
38171    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
38168    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
38169 
38170    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
38172 
38173    ---------------------------------------------------------------------------------------------------------------
38174    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
38175    ---------------------------------------------------------------------------------------------------------------
38176    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
38177 
38178    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
38179    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
38180 
38181    IF xla_accounting_cache_pkg.GetValueChar
38182          (p_source_code         => 'LEDGER_CATEGORY_CODE'
38183          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
38184    AND l_bflow_method_code = 'PRIOR_ENTRY'
38185 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
38186    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
38187          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
38188        )
38189    THEN
38190          xla_ae_lines_pkg.BflowUpgEntry
38191            (p_business_method_code    => l_bflow_method_code
38192            ,p_business_class_code     => l_bflow_class_code
38193            ,p_balance_type            => l_balance_type_code);
38194    ELSE
38195       NULL;
38196 -- No business flow processing for business flow method of NONE.
38197    END IF;
38198 
38199    --
38200    -- call analytical criteria
38201    --
38202    
38203    --
38204    -- call description
38205    --
38206    
38207 xla_ae_lines_pkg.SetLineDescription(
38208    p_ae_header_id => l_ae_header_id
38209   ,p_description  => Description_25 (
38210      p_application_id         => p_application_id
38211    , p_ae_header_id           => l_ae_header_id 
38212 , p_source_1 => p_source_1
38213    )
38214 );
38215 
38216 
38217    --
38218    -- call ADRs
38219    -- Bug 4922099
38220    --
38221    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
38222         (NVL(l_actual_upg_option, 'N') = 'O') OR
38223         (NVL(l_enc_upg_option, 'N') = 'O')
38224       )
38225    THEN
38226    NULL;
38227    --
38228    --
38229    
38230   l_ccid := AcctDerRule_171(
38231            p_application_id           => p_application_id
38232          , p_ae_header_id             => l_ae_header_id 
38233 , p_source_3 => p_source_3
38234 , p_source_6 => p_source_6
38235 , p_source_30 => p_source_30
38236          , x_transaction_coa_id       => l_adr_transaction_coa_id
38237          , x_accounting_coa_id        => l_adr_accounting_coa_id
38238          , x_value_type_code          => l_adr_value_type_code
38239          , p_side                     => 'NA'
38240    );
38241 
38242    xla_ae_lines_pkg.set_ccid(
38243     p_code_combination_id          => l_ccid
38244   , p_value_type_code              => l_adr_value_type_code
38245   , p_transaction_coa_id           => l_adr_transaction_coa_id
38246   , p_accounting_coa_id            => l_adr_accounting_coa_id
38247   , p_adr_code                     => 'FA_CAT_CIP_COST_CLEARING'
38248   , p_adr_type_code                => 'S'
38249   , p_component_type               => l_component_type
38250   , p_component_code               => l_component_code
38251   , p_component_type_code          => l_component_type_code
38252   , p_component_appl_id            => l_component_appl_id
38253   , p_amb_context_code             => l_amb_context_code
38254   , p_side                         => 'NA'
38255   );
38256 
38257 
38258    l_segment := AcctDerRule_145(
38259            p_application_id           => p_application_id
38260          , p_ae_header_id             => l_ae_header_id 
38261 , p_source_3 => p_source_3
38262 , p_source_5 => p_source_5
38263 , p_source_6 => p_source_6
38264          , x_transaction_coa_id       => l_adr_transaction_coa_id
38265          , x_accounting_coa_id        => l_adr_accounting_coa_id
38266          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
38267          , x_flex_value_set_id        => l_adr_flex_value_set_id
38268          , x_value_type_code          => l_adr_value_type_code
38269          , x_value_combination_id     => l_adr_value_combination_id
38270          , x_value_segment_code       => l_adr_value_segment_code
38271          , p_side                     => 'NA'
38272          , p_override_seg_flag        => 'Y'
38273    );
38274 
38275    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
38276 
38277       xla_ae_lines_pkg.set_segment(
38278           p_to_segment_code         => 'GL_ACCOUNT'
38279         , p_segment_value           => l_segment
38280         , p_from_segment_code       => l_adr_value_segment_code
38281         , p_from_combination_id     => l_adr_value_combination_id
38282         , p_value_type_code         => l_adr_value_type_code
38283         , p_transaction_coa_id      => l_adr_transaction_coa_id
38284         , p_accounting_coa_id       => l_adr_accounting_coa_id
38285         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
38286         , p_flex_value_set_id       => l_adr_flex_value_set_id
38287         , p_adr_code                => 'FA_CAT_CIP_CLR_SEGMENT'
38288         , p_adr_type_code           => 'S'
38289         , p_component_type          => l_component_type
38290         , p_component_code          => l_component_code
38291         , p_component_type_code     => l_component_type_code
38292         , p_component_appl_id       => l_component_appl_id
38293         , p_amb_context_code        => l_amb_context_code
38297         );
38294         , p_entity_code             => 'TRANSACTIONS'
38295         , p_event_class_code        => 'CIP_ADDITIONS'
38296         , p_side                    => 'NA'
38298 
38299   END IF;
38300 
38301    l_segment := AcctDerRule_169(
38302            p_application_id           => p_application_id
38303          , p_ae_header_id             => l_ae_header_id 
38304 , p_source_3 => p_source_3
38305 , p_source_6 => p_source_6
38306 , p_source_29 => p_source_29
38307          , x_transaction_coa_id       => l_adr_transaction_coa_id
38308          , x_accounting_coa_id        => l_adr_accounting_coa_id
38309          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
38310          , x_flex_value_set_id        => l_adr_flex_value_set_id
38311          , x_value_type_code          => l_adr_value_type_code
38312          , x_value_combination_id     => l_adr_value_combination_id
38313          , x_value_segment_code       => l_adr_value_segment_code
38314          , p_side                     => 'NA'
38315          , p_override_seg_flag        => 'Y'
38316    );
38317 
38318    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
38319 
38320       xla_ae_lines_pkg.set_segment(
38321           p_to_segment_code         => 'GL_BALANCING'
38322         , p_segment_value           => l_segment
38323         , p_from_segment_code       => l_adr_value_segment_code
38324         , p_from_combination_id     => l_adr_value_combination_id
38325         , p_value_type_code         => l_adr_value_type_code
38326         , p_transaction_coa_id      => l_adr_transaction_coa_id
38327         , p_accounting_coa_id       => l_adr_accounting_coa_id
38328         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
38329         , p_flex_value_set_id       => l_adr_flex_value_set_id
38330         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
38331         , p_adr_type_code           => 'S'
38332         , p_component_type          => l_component_type
38333         , p_component_code          => l_component_code
38334         , p_component_type_code     => l_component_type_code
38335         , p_component_appl_id       => l_component_appl_id
38336         , p_amb_context_code        => l_amb_context_code
38337         , p_entity_code             => 'TRANSACTIONS'
38338         , p_event_class_code        => 'CIP_ADDITIONS'
38339         , p_side                    => 'NA'
38340         );
38341 
38342   END IF;
38343 
38344    --
38345    --
38346    END IF;
38347    --
38348    -- Bug 4922099
38349    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
38350           (NVL(l_enc_upg_option, 'N') = 'O')
38351         ) AND
38352         (l_bflow_method_code = 'PRIOR_ENTRY')
38353       )
38354    THEN
38355       IF
38356       --
38357       1 = 2
38358       --
38359       THEN
38360       xla_accounting_err_pkg.build_message
38361                                     (p_appli_s_name            => 'XLA'
38362                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
38363                                     ,p_token_1                 => 'LINE_NUMBER'
38364                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
38365                                     ,p_token_2                 => 'LINE_TYPE_NAME'
38366                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
38367                                                                              l_component_type
38368                                                                             ,l_component_code
38369                                                                             ,l_component_type_code
38370                                                                             ,l_component_appl_id
38371                                                                             ,l_amb_context_code
38372                                                                             ,l_entity_code
38373                                                                             ,l_event_class_code
38374                                                                            )
38375                                     ,p_token_3                 => 'OWNER'
38376                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
38377                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
38378                                                                           ,p_lookup_code    => l_component_type_code
38379                                                                          )
38380                                     ,p_token_4                 => 'PRODUCT_NAME'
38381                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
38382                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
38383                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
38384                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
38385                                     ,p_ae_header_id            =>  NULL
38386                                        );
38387 
38388         IF (C_LEVEL_ERROR>= g_log_level) THEN
38389                  trace
38390                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
38391                       ,p_level    => C_LEVEL_ERROR
38392                       ,p_module   => l_log_module);
38393         END IF;
38394       END IF;
38395    END IF;
38396    --
38397    --
38398    ------------------------------------------------------------------------------------------------
38399    -- 4219869 Business Flow
38400    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
38401    -- Prior Entry.  Currently, the following code is always generated.
38405    ------------------------------------------------------------------------------------
38402    ------------------------------------------------------------------------------------------------
38403    XLA_AE_LINES_PKG.ValidateCurrentLine;
38404 
38406    -- 4219869 Business Flow
38407    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
38408    ------------------------------------------------------------------------------------
38409    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
38410 
38411    ----------------------------------------------------------------------------------
38412    -- 4219869 Business Flow
38413    -- Update journal entry status -- Need to generate this within IF <condition>
38414    ----------------------------------------------------------------------------------
38415    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
38416          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
38417          ,p_balance_type_code => l_balance_type_code
38418          );
38419 
38420    -------------------------------------------------------------------------------------------
38421    -- 4262811 - Generate the Accrual Reversal lines
38422    -------------------------------------------------------------------------------------------
38423    BEGIN
38424       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
38425                               (g_array_event(p_event_id).array_value_num('header_index'));
38426       IF l_acc_rev_flag IS NULL THEN
38427          l_acc_rev_flag := 'N';
38428       END IF;
38429    EXCEPTION
38430       WHEN OTHERS THEN
38431          l_acc_rev_flag := 'N';
38432    END;
38433    --
38434    IF (l_acc_rev_flag = 'Y') THEN
38435 
38436        -- 4645092  ------------------------------------------------------------------------------
38437        -- To allow MPA report to determine if it should generate report process
38438        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
38439        ------------------------------------------------------------------------------------------
38440 
38441        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
38442        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
38443    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
38444    -- call ADRs
38445    -- Bug 4922099
38446    --
38447    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
38448         (NVL(l_actual_upg_option, 'N') = 'O') OR
38449         (NVL(l_enc_upg_option, 'N') = 'O')
38450       )
38451    THEN
38452    NULL;
38453    --
38454    --
38455    
38456   l_ccid := AcctDerRule_171(
38457            p_application_id           => p_application_id
38458          , p_ae_header_id             => l_ae_header_id 
38459 , p_source_3 => p_source_3
38460 , p_source_6 => p_source_6
38461 , p_source_30 => p_source_30
38462          , x_transaction_coa_id       => l_adr_transaction_coa_id
38463          , x_accounting_coa_id        => l_adr_accounting_coa_id
38464          , x_value_type_code          => l_adr_value_type_code
38465          , p_side                     => 'NA'
38466    );
38467 
38468    xla_ae_lines_pkg.set_ccid(
38469     p_code_combination_id          => l_ccid
38470   , p_value_type_code              => l_adr_value_type_code
38471   , p_transaction_coa_id           => l_adr_transaction_coa_id
38472   , p_accounting_coa_id            => l_adr_accounting_coa_id
38473   , p_adr_code                     => 'FA_CAT_CIP_COST_CLEARING'
38474   , p_adr_type_code                => 'S'
38475   , p_component_type               => l_component_type
38476   , p_component_code               => l_component_code
38477   , p_component_type_code          => l_component_type_code
38478   , p_component_appl_id            => l_component_appl_id
38479   , p_amb_context_code             => l_amb_context_code
38480   , p_side                         => 'NA'
38481   );
38482 
38483 
38484    l_segment := AcctDerRule_145(
38485            p_application_id           => p_application_id
38486          , p_ae_header_id             => l_ae_header_id 
38487 , p_source_3 => p_source_3
38488 , p_source_5 => p_source_5
38489 , p_source_6 => p_source_6
38490          , x_transaction_coa_id       => l_adr_transaction_coa_id
38491          , x_accounting_coa_id        => l_adr_accounting_coa_id
38492          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
38493          , x_flex_value_set_id        => l_adr_flex_value_set_id
38494          , x_value_type_code          => l_adr_value_type_code
38495          , x_value_combination_id     => l_adr_value_combination_id
38496          , x_value_segment_code       => l_adr_value_segment_code
38497          , p_side                     => 'NA'
38498          , p_override_seg_flag        => 'Y'
38499    );
38500 
38501    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
38502 
38503       xla_ae_lines_pkg.set_segment(
38504           p_to_segment_code         => 'GL_ACCOUNT'
38505         , p_segment_value           => l_segment
38506         , p_from_segment_code       => l_adr_value_segment_code
38507         , p_from_combination_id     => l_adr_value_combination_id
38508         , p_value_type_code         => l_adr_value_type_code
38509         , p_transaction_coa_id      => l_adr_transaction_coa_id
38510         , p_accounting_coa_id       => l_adr_accounting_coa_id
38511         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
38512         , p_flex_value_set_id       => l_adr_flex_value_set_id
38513         , p_adr_code                => 'FA_CAT_CIP_CLR_SEGMENT'
38514         , p_adr_type_code           => 'S'
38515         , p_component_type          => l_component_type
38516         , p_component_code          => l_component_code
38517         , p_component_type_code     => l_component_type_code
38518         , p_component_appl_id       => l_component_appl_id
38519         , p_amb_context_code        => l_amb_context_code
38523         );
38520         , p_entity_code             => 'TRANSACTIONS'
38521         , p_event_class_code        => 'CIP_ADDITIONS'
38522         , p_side                    => 'NA'
38524 
38525   END IF;
38526 
38527    l_segment := AcctDerRule_169(
38528            p_application_id           => p_application_id
38529          , p_ae_header_id             => l_ae_header_id 
38530 , p_source_3 => p_source_3
38531 , p_source_6 => p_source_6
38532 , p_source_29 => p_source_29
38533          , x_transaction_coa_id       => l_adr_transaction_coa_id
38534          , x_accounting_coa_id        => l_adr_accounting_coa_id
38535          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
38536          , x_flex_value_set_id        => l_adr_flex_value_set_id
38537          , x_value_type_code          => l_adr_value_type_code
38538          , x_value_combination_id     => l_adr_value_combination_id
38539          , x_value_segment_code       => l_adr_value_segment_code
38540          , p_side                     => 'NA'
38541          , p_override_seg_flag        => 'Y'
38542    );
38543 
38544    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
38545 
38546       xla_ae_lines_pkg.set_segment(
38547           p_to_segment_code         => 'GL_BALANCING'
38548         , p_segment_value           => l_segment
38549         , p_from_segment_code       => l_adr_value_segment_code
38550         , p_from_combination_id     => l_adr_value_combination_id
38551         , p_value_type_code         => l_adr_value_type_code
38552         , p_transaction_coa_id      => l_adr_transaction_coa_id
38553         , p_accounting_coa_id       => l_adr_accounting_coa_id
38554         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
38555         , p_flex_value_set_id       => l_adr_flex_value_set_id
38556         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
38557         , p_adr_type_code           => 'S'
38558         , p_component_type          => l_component_type
38559         , p_component_code          => l_component_code
38560         , p_component_type_code     => l_component_type_code
38561         , p_component_appl_id       => l_component_appl_id
38562         , p_amb_context_code        => l_amb_context_code
38563         , p_entity_code             => 'TRANSACTIONS'
38564         , p_event_class_code        => 'CIP_ADDITIONS'
38565         , p_side                    => 'NA'
38566         );
38567 
38568   END IF;
38569 
38570    --
38571    --
38572    END IF;
38573 
38574        --
38575        -- Update the line information that should be overwritten
38576        --
38577        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
38578                                          p_header_num   => 1);
38579        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
38580 
38581        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
38582 
38583        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
38584           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
38585        END IF;
38586 
38587       --
38588       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
38589       --
38590       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
38591           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
38592       ELSE
38593           ---------------------------------------------------------------------------------------------------
38594           -- 4262811a Switch Sign
38595           ---------------------------------------------------------------------------------------------------
38596           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
38597           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38598                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38599           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38600                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38601           -- 5132302
38602           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
38603                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38604 
38605       END IF;
38606 
38607       -- 4955764
38608       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
38609       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
38610 
38611 
38612       XLA_AE_LINES_PKG.ValidateCurrentLine;
38613       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
38614 
38615       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
38616                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
38617                ,p_balance_type_code => l_balance_type_code);
38618 
38619    END IF;
38620 
38621    -----------------------------------------------------------------------------------------
38622    -- 4262811 Multiperiod Accounting
38623    -----------------------------------------------------------------------------------------
38624      -- No MPA option is assigned.
38625 
38626 
38627 END IF;
38628 END IF;
38629 --
38630 
38631 --
38632 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38633    trace
38634       (p_msg      => 'END of AcctLineType_208'
38635       ,p_level    => C_LEVEL_PROCEDURE
38636       ,p_module   => l_log_module);
38637 END IF;
38638 --
38639 EXCEPTION
38640   WHEN xla_exceptions_pkg.application_exception THEN
38641       RAISE;
38645 END AcctLineType_208;
38642   WHEN OTHERS THEN
38643        xla_exceptions_pkg.raise_message
38644            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_208');
38646 --
38647 
38648 ---------------------------------------
38649 --
38650 -- PRIVATE FUNCTION
38651 --         AcctLineType_209
38652 --
38653 ---------------------------------------
38654 PROCEDURE AcctLineType_209 (
38655   p_application_id        IN NUMBER
38656  ,p_event_id              IN NUMBER
38657  ,p_calculate_acctd_flag  IN VARCHAR2
38658  ,p_calculate_g_l_flag    IN VARCHAR2
38659  ,p_actual_flag           IN OUT VARCHAR2
38660  ,p_balance_type_code     OUT VARCHAR2
38661  ,p_gain_or_loss_ref      OUT VARCHAR2
38662  
38663 --Period Close Date
38664  , p_source_1            IN DATE
38665 --Generated Code Combination Identifier
38666  , p_source_3            IN NUMBER
38667 --CIP Cost Account
38668  , p_source_7            IN VARCHAR2
38669 --Expense Account Code Combination Identifier
38670  , p_source_29            IN NUMBER
38671 --Default Code Combination Identifier
38672  , p_source_30            IN NUMBER
38673 --Adjustment Type
38674  , p_source_35            IN VARCHAR2
38675 --Transaction Header Identifier
38676  , p_source_36            IN NUMBER
38677 --Adjustment Line Identifier
38678  , p_source_37            IN NUMBER
38679 --Distribution Type Code
38680  , p_source_38            IN VARCHAR2
38681 --Entered Amount
38682  , p_source_39            IN NUMBER
38683 --Currency Code
38684  , p_source_40            IN VARCHAR2
38685 )
38686 IS
38687 
38688 l_component_type              VARCHAR2(80);
38689 l_component_code              VARCHAR2(30);
38690 l_component_type_code         VARCHAR2(1);
38691 l_component_appl_id           INTEGER;
38692 l_amb_context_code            VARCHAR2(30);
38693 l_entity_code                 VARCHAR2(30);
38694 l_event_class_code            VARCHAR2(30);
38695 l_ae_header_id                NUMBER;
38696 l_event_type_code             VARCHAR2(30);
38697 l_line_definition_code        VARCHAR2(30);
38698 l_line_definition_owner_code  VARCHAR2(1);
38699 --
38700 -- adr variables
38701 l_segment                     VARCHAR2(30);
38702 l_ccid                        NUMBER;
38703 l_adr_transaction_coa_id      NUMBER;
38704 l_adr_accounting_coa_id       NUMBER;
38705 l_adr_flexfield_segment_code  VARCHAR2(30);
38706 l_adr_flex_value_set_id       NUMBER;
38707 l_adr_value_type_code         VARCHAR2(30);
38708 l_adr_value_combination_id    NUMBER;
38709 l_adr_value_segment_code      VARCHAR2(30);
38710 
38711 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
38712 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
38713 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
38714 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
38715 
38716 -- 4262811 Variables ------------------------------------------------------------------------------------------
38717 l_entered_amt_idx             NUMBER;
38718 l_accted_amt_idx              NUMBER;
38719 l_acc_rev_flag                VARCHAR2(1);
38720 l_accrual_line_num            NUMBER;
38721 l_tmp_amt                     NUMBER;
38722 l_acc_rev_natural_side_code   VARCHAR2(1);
38723 
38724 l_num_entries                 NUMBER;
38725 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
38726 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
38727 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
38728 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
38729 l_recog_line_1                NUMBER;
38730 l_recog_line_2                NUMBER;
38731 
38732 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
38733 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
38734 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
38735 
38736 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
38737 
38738 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
38739 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
38740 
38741 ---------------------------------------------------------------------------------------------------------------
38742 
38743 
38744 --
38745 -- bulk performance
38746 --
38747 l_balance_type_code           VARCHAR2(1);
38748 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
38749 l_log_module                  VARCHAR2(240);
38750 
38751 --
38752 -- Upgrade strategy
38753 --
38754 l_actual_upg_option           VARCHAR2(1);
38755 l_enc_upg_option           VARCHAR2(1);
38756 
38757 --
38758 BEGIN
38759 --
38760 IF g_log_enabled THEN
38761       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_209';
38762 END IF;
38763 --
38764 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38765 
38766       trace
38767          (p_msg      => 'BEGIN of AcctLineType_209'
38768          ,p_level    => C_LEVEL_PROCEDURE
38769          ,p_module   => l_log_module);
38770 
38771 END IF;
38772 --
38773 l_component_type             := 'AMB_JLT';
38774 l_component_code             := 'FA_CIP_ADJ_COST';
38775 l_component_type_code        := 'S';
38776 l_component_appl_id          :=  140;
38777 l_amb_context_code           := 'DEFAULT';
38778 l_entity_code                := 'TRANSACTIONS';
38779 l_event_class_code           := 'CIP_ADJUSTMENTS';
38780 l_event_type_code            := 'CIP_ADJUSTMENTS_ALL';
38781 l_line_definition_owner_code := 'S';
38782 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_AD6';
38783 --
38784 l_balance_type_code          := 'A';
38785 l_segment                     := NULL;
38789 l_adr_flexfield_segment_code  := NULL;
38786 l_ccid                        := NULL;
38787 l_adr_transaction_coa_id      := NULL;
38788 l_adr_accounting_coa_id       := NULL;
38790 l_adr_flex_value_set_id       := NULL;
38791 l_adr_value_type_code         := NULL;
38792 l_adr_value_combination_id    := NULL;
38793 l_adr_value_segment_code      := NULL;
38794 
38795 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
38796 l_bflow_class_code           := '';    -- 4219869 Business Flow
38797 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
38798 l_budgetary_control_flag     := 'N';
38799 
38800 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
38801 l_bflow_applied_to_amt       := NULL; -- 5132302
38802 l_entered_amt_idx            := NULL;          -- 4262811
38803 l_accted_amt_idx             := NULL;          -- 4262811
38804 l_acc_rev_flag               := NULL;          -- 4262811
38805 l_accrual_line_num           := NULL;          -- 4262811
38806 l_tmp_amt                    := NULL;          -- 4262811
38807 --
38808  
38809 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
38810     l_balance_type_code <> 'B' THEN
38811 IF NVL(p_source_35,'
38812 ') =  'CIP COST'
38813  THEN 
38814 
38815    --
38816    XLA_AE_LINES_PKG.SetNewLine;
38817 
38818    p_balance_type_code          := l_balance_type_code;
38819    -- set the flag so later we will know whether the gain loss line needs to be created
38820    
38821    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
38822      p_actual_flag :='A';
38823    END IF;
38824 
38825    --
38826    -- bulk performance
38827    --
38828    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
38829                                       p_header_num   => 0); -- 4262811
38830    --
38831    -- set accounting line options
38832    --
38833    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
38834            p_natural_side_code          => 'D'
38835          , p_gain_or_loss_flag          => 'N'
38836          , p_gl_transfer_mode_code      => 'S'
38837          , p_acct_entry_type_code       => 'A'
38838          , p_switch_side_flag           => 'Y'
38839          , p_merge_duplicate_code       => 'N'
38840          );
38841    --
38842    l_acc_rev_natural_side_code := 'C';  -- 4262811
38843    -- 
38844    --
38845    -- set accounting line type info
38846    --
38847    xla_ae_lines_pkg.SetAcctLineType
38848       (p_component_type             => l_component_type
38849       ,p_event_type_code            => l_event_type_code
38850       ,p_line_definition_owner_code => l_line_definition_owner_code
38851       ,p_line_definition_code       => l_line_definition_code
38852       ,p_accounting_line_code       => l_component_code
38853       ,p_accounting_line_type_code  => l_component_type_code
38854       ,p_accounting_line_appl_id    => l_component_appl_id
38855       ,p_amb_context_code           => l_amb_context_code
38856       ,p_entity_code                => l_entity_code
38857       ,p_event_class_code           => l_event_class_code);
38858    --
38859    -- set accounting class
38860    --
38861    xla_ae_lines_pkg.SetAcctClass(
38862            p_accounting_class_code  => 'ASSET'
38863          , p_ae_header_id           => l_ae_header_id
38864          );
38865 
38866    --
38867    -- set rounding class
38868    --
38869    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
38870                       'ASSET';
38871 
38872    --
38873    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
38874    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
38875    --
38876    -- bulk performance
38877    --
38878    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
38879 
38880    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
38881       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
38882 
38883    -- 4955764
38884    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
38885       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
38886 
38887    -- 4458381 Public Sector Enh
38888    
38889    --
38890    -- set accounting attributes for the line type
38891    --
38892    l_entered_amt_idx := 4;
38893    l_accted_amt_idx  := 6;
38894    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
38895    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
38896    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
38897    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
38898    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
38899    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
38900    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
38901    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
38902    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
38903    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
38904    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
38905    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
38906    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
38907 
38908    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
38909    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
38910 
38911    ---------------------------------------------------------------------------------------------------------------
38912    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
38916    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
38913    ---------------------------------------------------------------------------------------------------------------
38914    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
38915 
38917    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
38918 
38919    IF xla_accounting_cache_pkg.GetValueChar
38920          (p_source_code         => 'LEDGER_CATEGORY_CODE'
38921          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
38922    AND l_bflow_method_code = 'PRIOR_ENTRY'
38923 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
38924    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
38925          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
38926        )
38927    THEN
38928          xla_ae_lines_pkg.BflowUpgEntry
38929            (p_business_method_code    => l_bflow_method_code
38930            ,p_business_class_code     => l_bflow_class_code
38931            ,p_balance_type            => l_balance_type_code);
38932    ELSE
38933       NULL;
38934 -- No business flow processing for business flow method of NONE.
38935    END IF;
38936 
38937    --
38938    -- call analytical criteria
38939    --
38940    
38941    --
38942    -- call description
38943    --
38944    
38945 xla_ae_lines_pkg.SetLineDescription(
38946    p_ae_header_id => l_ae_header_id
38947   ,p_description  => Description_27 (
38948      p_application_id         => p_application_id
38949    , p_ae_header_id           => l_ae_header_id 
38950 , p_source_1 => p_source_1
38951    )
38952 );
38953 
38954 
38955    --
38956    -- call ADRs
38957    -- Bug 4922099
38958    --
38959    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
38960         (NVL(l_actual_upg_option, 'N') = 'O') OR
38961         (NVL(l_enc_upg_option, 'N') = 'O')
38962       )
38963    THEN
38964    NULL;
38965    --
38966    --
38967    
38968   l_ccid := AcctDerRule_173(
38969            p_application_id           => p_application_id
38970          , p_ae_header_id             => l_ae_header_id 
38971 , p_source_3 => p_source_3
38972 , p_source_30 => p_source_30
38973          , x_transaction_coa_id       => l_adr_transaction_coa_id
38974          , x_accounting_coa_id        => l_adr_accounting_coa_id
38975          , x_value_type_code          => l_adr_value_type_code
38976          , p_side                     => 'NA'
38977    );
38978 
38979    xla_ae_lines_pkg.set_ccid(
38980     p_code_combination_id          => l_ccid
38981   , p_value_type_code              => l_adr_value_type_code
38982   , p_transaction_coa_id           => l_adr_transaction_coa_id
38983   , p_accounting_coa_id            => l_adr_accounting_coa_id
38984   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
38985   , p_adr_type_code                => 'S'
38986   , p_component_type               => l_component_type
38987   , p_component_code               => l_component_code
38988   , p_component_type_code          => l_component_type_code
38989   , p_component_appl_id            => l_component_appl_id
38990   , p_amb_context_code             => l_amb_context_code
38991   , p_side                         => 'NA'
38992   );
38993 
38994 
38995    l_segment := AcctDerRule_146(
38996            p_application_id           => p_application_id
38997          , p_ae_header_id             => l_ae_header_id 
38998 , p_source_3 => p_source_3
38999 , p_source_7 => p_source_7
39000          , x_transaction_coa_id       => l_adr_transaction_coa_id
39001          , x_accounting_coa_id        => l_adr_accounting_coa_id
39002          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39003          , x_flex_value_set_id        => l_adr_flex_value_set_id
39004          , x_value_type_code          => l_adr_value_type_code
39005          , x_value_combination_id     => l_adr_value_combination_id
39006          , x_value_segment_code       => l_adr_value_segment_code
39007          , p_side                     => 'NA'
39008          , p_override_seg_flag        => 'Y'
39009    );
39010 
39011    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39012 
39013       xla_ae_lines_pkg.set_segment(
39014           p_to_segment_code         => 'GL_ACCOUNT'
39015         , p_segment_value           => l_segment
39016         , p_from_segment_code       => l_adr_value_segment_code
39017         , p_from_combination_id     => l_adr_value_combination_id
39018         , p_value_type_code         => l_adr_value_type_code
39019         , p_transaction_coa_id      => l_adr_transaction_coa_id
39020         , p_accounting_coa_id       => l_adr_accounting_coa_id
39021         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39022         , p_flex_value_set_id       => l_adr_flex_value_set_id
39023         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
39024         , p_adr_type_code           => 'S'
39025         , p_component_type          => l_component_type
39026         , p_component_code          => l_component_code
39027         , p_component_type_code     => l_component_type_code
39028         , p_component_appl_id       => l_component_appl_id
39029         , p_amb_context_code        => l_amb_context_code
39030         , p_entity_code             => 'TRANSACTIONS'
39031         , p_event_class_code        => 'CIP_ADJUSTMENTS'
39032         , p_side                    => 'NA'
39033         );
39034 
39035   END IF;
39036 
39037    l_segment := AcctDerRule_168(
39038            p_application_id           => p_application_id
39039          , p_ae_header_id             => l_ae_header_id 
39040 , p_source_3 => p_source_3
39041 , p_source_29 => p_source_29
39042          , x_transaction_coa_id       => l_adr_transaction_coa_id
39046          , x_value_type_code          => l_adr_value_type_code
39043          , x_accounting_coa_id        => l_adr_accounting_coa_id
39044          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39045          , x_flex_value_set_id        => l_adr_flex_value_set_id
39047          , x_value_combination_id     => l_adr_value_combination_id
39048          , x_value_segment_code       => l_adr_value_segment_code
39049          , p_side                     => 'NA'
39050          , p_override_seg_flag        => 'Y'
39051    );
39052 
39053    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39054 
39055       xla_ae_lines_pkg.set_segment(
39056           p_to_segment_code         => 'GL_BALANCING'
39057         , p_segment_value           => l_segment
39058         , p_from_segment_code       => l_adr_value_segment_code
39059         , p_from_combination_id     => l_adr_value_combination_id
39060         , p_value_type_code         => l_adr_value_type_code
39061         , p_transaction_coa_id      => l_adr_transaction_coa_id
39062         , p_accounting_coa_id       => l_adr_accounting_coa_id
39063         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39064         , p_flex_value_set_id       => l_adr_flex_value_set_id
39065         , p_adr_code                => 'FA_EXPENSE_ACCT'
39066         , p_adr_type_code           => 'S'
39067         , p_component_type          => l_component_type
39068         , p_component_code          => l_component_code
39069         , p_component_type_code     => l_component_type_code
39070         , p_component_appl_id       => l_component_appl_id
39071         , p_amb_context_code        => l_amb_context_code
39072         , p_entity_code             => 'TRANSACTIONS'
39073         , p_event_class_code        => 'CIP_ADJUSTMENTS'
39074         , p_side                    => 'NA'
39075         );
39076 
39077   END IF;
39078 
39079    --
39080    --
39081    END IF;
39082    --
39083    -- Bug 4922099
39084    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
39085           (NVL(l_enc_upg_option, 'N') = 'O')
39086         ) AND
39087         (l_bflow_method_code = 'PRIOR_ENTRY')
39088       )
39089    THEN
39090       IF
39091       --
39092       1 = 2
39093       --
39094       THEN
39095       xla_accounting_err_pkg.build_message
39096                                     (p_appli_s_name            => 'XLA'
39097                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39098                                     ,p_token_1                 => 'LINE_NUMBER'
39099                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
39100                                     ,p_token_2                 => 'LINE_TYPE_NAME'
39101                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
39102                                                                              l_component_type
39103                                                                             ,l_component_code
39104                                                                             ,l_component_type_code
39105                                                                             ,l_component_appl_id
39106                                                                             ,l_amb_context_code
39107                                                                             ,l_entity_code
39108                                                                             ,l_event_class_code
39109                                                                            )
39110                                     ,p_token_3                 => 'OWNER'
39111                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
39112                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
39113                                                                           ,p_lookup_code    => l_component_type_code
39114                                                                          )
39115                                     ,p_token_4                 => 'PRODUCT_NAME'
39116                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
39117                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
39118                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
39119                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
39120                                     ,p_ae_header_id            =>  NULL
39121                                        );
39122 
39123         IF (C_LEVEL_ERROR>= g_log_level) THEN
39124                  trace
39125                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39126                       ,p_level    => C_LEVEL_ERROR
39127                       ,p_module   => l_log_module);
39128         END IF;
39129       END IF;
39130    END IF;
39131    --
39132    --
39133    ------------------------------------------------------------------------------------------------
39134    -- 4219869 Business Flow
39135    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
39136    -- Prior Entry.  Currently, the following code is always generated.
39137    ------------------------------------------------------------------------------------------------
39138    XLA_AE_LINES_PKG.ValidateCurrentLine;
39139 
39140    ------------------------------------------------------------------------------------
39141    -- 4219869 Business Flow
39142    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
39143    ------------------------------------------------------------------------------------
39144    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39145 
39146    ----------------------------------------------------------------------------------
39150    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39147    -- 4219869 Business Flow
39148    -- Update journal entry status -- Need to generate this within IF <condition>
39149    ----------------------------------------------------------------------------------
39151          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
39152          ,p_balance_type_code => l_balance_type_code
39153          );
39154 
39155    -------------------------------------------------------------------------------------------
39156    -- 4262811 - Generate the Accrual Reversal lines
39157    -------------------------------------------------------------------------------------------
39158    BEGIN
39159       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
39160                               (g_array_event(p_event_id).array_value_num('header_index'));
39161       IF l_acc_rev_flag IS NULL THEN
39162          l_acc_rev_flag := 'N';
39163       END IF;
39164    EXCEPTION
39165       WHEN OTHERS THEN
39166          l_acc_rev_flag := 'N';
39167    END;
39168    --
39169    IF (l_acc_rev_flag = 'Y') THEN
39170 
39171        -- 4645092  ------------------------------------------------------------------------------
39172        -- To allow MPA report to determine if it should generate report process
39173        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
39174        ------------------------------------------------------------------------------------------
39175 
39176        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
39177        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
39178    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
39179    -- call ADRs
39180    -- Bug 4922099
39181    --
39182    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39183         (NVL(l_actual_upg_option, 'N') = 'O') OR
39184         (NVL(l_enc_upg_option, 'N') = 'O')
39185       )
39186    THEN
39187    NULL;
39188    --
39189    --
39190    
39191   l_ccid := AcctDerRule_173(
39192            p_application_id           => p_application_id
39193          , p_ae_header_id             => l_ae_header_id 
39194 , p_source_3 => p_source_3
39195 , p_source_30 => p_source_30
39196          , x_transaction_coa_id       => l_adr_transaction_coa_id
39197          , x_accounting_coa_id        => l_adr_accounting_coa_id
39198          , x_value_type_code          => l_adr_value_type_code
39199          , p_side                     => 'NA'
39200    );
39201 
39202    xla_ae_lines_pkg.set_ccid(
39203     p_code_combination_id          => l_ccid
39204   , p_value_type_code              => l_adr_value_type_code
39205   , p_transaction_coa_id           => l_adr_transaction_coa_id
39206   , p_accounting_coa_id            => l_adr_accounting_coa_id
39207   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
39208   , p_adr_type_code                => 'S'
39209   , p_component_type               => l_component_type
39210   , p_component_code               => l_component_code
39211   , p_component_type_code          => l_component_type_code
39212   , p_component_appl_id            => l_component_appl_id
39213   , p_amb_context_code             => l_amb_context_code
39214   , p_side                         => 'NA'
39215   );
39216 
39217 
39218    l_segment := AcctDerRule_146(
39219            p_application_id           => p_application_id
39220          , p_ae_header_id             => l_ae_header_id 
39221 , p_source_3 => p_source_3
39222 , p_source_7 => p_source_7
39223          , x_transaction_coa_id       => l_adr_transaction_coa_id
39224          , x_accounting_coa_id        => l_adr_accounting_coa_id
39225          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39226          , x_flex_value_set_id        => l_adr_flex_value_set_id
39227          , x_value_type_code          => l_adr_value_type_code
39228          , x_value_combination_id     => l_adr_value_combination_id
39229          , x_value_segment_code       => l_adr_value_segment_code
39230          , p_side                     => 'NA'
39231          , p_override_seg_flag        => 'Y'
39232    );
39233 
39234    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39235 
39236       xla_ae_lines_pkg.set_segment(
39237           p_to_segment_code         => 'GL_ACCOUNT'
39238         , p_segment_value           => l_segment
39239         , p_from_segment_code       => l_adr_value_segment_code
39240         , p_from_combination_id     => l_adr_value_combination_id
39241         , p_value_type_code         => l_adr_value_type_code
39242         , p_transaction_coa_id      => l_adr_transaction_coa_id
39243         , p_accounting_coa_id       => l_adr_accounting_coa_id
39244         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39245         , p_flex_value_set_id       => l_adr_flex_value_set_id
39246         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
39247         , p_adr_type_code           => 'S'
39248         , p_component_type          => l_component_type
39249         , p_component_code          => l_component_code
39250         , p_component_type_code     => l_component_type_code
39251         , p_component_appl_id       => l_component_appl_id
39252         , p_amb_context_code        => l_amb_context_code
39253         , p_entity_code             => 'TRANSACTIONS'
39254         , p_event_class_code        => 'CIP_ADJUSTMENTS'
39255         , p_side                    => 'NA'
39256         );
39257 
39258   END IF;
39259 
39260    l_segment := AcctDerRule_168(
39261            p_application_id           => p_application_id
39262          , p_ae_header_id             => l_ae_header_id 
39263 , p_source_3 => p_source_3
39264 , p_source_29 => p_source_29
39265          , x_transaction_coa_id       => l_adr_transaction_coa_id
39266          , x_accounting_coa_id        => l_adr_accounting_coa_id
39267          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39271          , x_value_segment_code       => l_adr_value_segment_code
39268          , x_flex_value_set_id        => l_adr_flex_value_set_id
39269          , x_value_type_code          => l_adr_value_type_code
39270          , x_value_combination_id     => l_adr_value_combination_id
39272          , p_side                     => 'NA'
39273          , p_override_seg_flag        => 'Y'
39274    );
39275 
39276    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39277 
39278       xla_ae_lines_pkg.set_segment(
39279           p_to_segment_code         => 'GL_BALANCING'
39280         , p_segment_value           => l_segment
39281         , p_from_segment_code       => l_adr_value_segment_code
39282         , p_from_combination_id     => l_adr_value_combination_id
39283         , p_value_type_code         => l_adr_value_type_code
39284         , p_transaction_coa_id      => l_adr_transaction_coa_id
39285         , p_accounting_coa_id       => l_adr_accounting_coa_id
39286         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39287         , p_flex_value_set_id       => l_adr_flex_value_set_id
39288         , p_adr_code                => 'FA_EXPENSE_ACCT'
39289         , p_adr_type_code           => 'S'
39290         , p_component_type          => l_component_type
39291         , p_component_code          => l_component_code
39292         , p_component_type_code     => l_component_type_code
39293         , p_component_appl_id       => l_component_appl_id
39294         , p_amb_context_code        => l_amb_context_code
39295         , p_entity_code             => 'TRANSACTIONS'
39296         , p_event_class_code        => 'CIP_ADJUSTMENTS'
39297         , p_side                    => 'NA'
39298         );
39299 
39300   END IF;
39301 
39302    --
39303    --
39304    END IF;
39305 
39306        --
39307        -- Update the line information that should be overwritten
39308        --
39309        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
39310                                          p_header_num   => 1);
39311        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
39312 
39313        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
39314 
39315        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
39316           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
39317        END IF;
39318 
39319       --
39320       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
39321       --
39322       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
39323           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
39324       ELSE
39325           ---------------------------------------------------------------------------------------------------
39326           -- 4262811a Switch Sign
39327           ---------------------------------------------------------------------------------------------------
39328           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
39329           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
39330                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39331           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
39332                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39333           -- 5132302
39334           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
39335                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39336 
39337       END IF;
39338 
39339       -- 4955764
39340       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
39341       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
39342 
39343 
39344       XLA_AE_LINES_PKG.ValidateCurrentLine;
39345       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39346 
39347       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39348                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
39349                ,p_balance_type_code => l_balance_type_code);
39350 
39351    END IF;
39352 
39353    -----------------------------------------------------------------------------------------
39354    -- 4262811 Multiperiod Accounting
39355    -----------------------------------------------------------------------------------------
39356      -- No MPA option is assigned.
39357 
39358 
39359 END IF;
39360 END IF;
39361 --
39362 
39363 --
39364 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
39365    trace
39366       (p_msg      => 'END of AcctLineType_209'
39367       ,p_level    => C_LEVEL_PROCEDURE
39368       ,p_module   => l_log_module);
39369 END IF;
39370 --
39371 EXCEPTION
39372   WHEN xla_exceptions_pkg.application_exception THEN
39373       RAISE;
39374   WHEN OTHERS THEN
39375        xla_exceptions_pkg.raise_message
39376            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_209');
39377 END AcctLineType_209;
39378 --
39379 
39380 ---------------------------------------
39381 --
39382 -- PRIVATE FUNCTION
39383 --         AcctLineType_210
39384 --
39385 ---------------------------------------
39386 PROCEDURE AcctLineType_210 (
39387   p_application_id        IN NUMBER
39388  ,p_event_id              IN NUMBER
39389  ,p_calculate_acctd_flag  IN VARCHAR2
39390  ,p_calculate_g_l_flag    IN VARCHAR2
39391  ,p_actual_flag           IN OUT VARCHAR2
39392  ,p_balance_type_code     OUT VARCHAR2
39396  , p_source_1            IN DATE
39393  ,p_gain_or_loss_ref      OUT VARCHAR2
39394  
39395 --Period Close Date
39397 --Generated Code Combination Identifier
39398  , p_source_3            IN NUMBER
39399 --CIP Clearing Account
39400  , p_source_5            IN VARCHAR2
39401 --Payables Code Combination Identifier
39402  , p_source_6            IN NUMBER
39403 --Expense Account Code Combination Identifier
39404  , p_source_29            IN NUMBER
39405 --Default Code Combination Identifier
39406  , p_source_30            IN NUMBER
39407 --Adjustment Type
39408  , p_source_35            IN VARCHAR2
39409 --Transaction Header Identifier
39410  , p_source_36            IN NUMBER
39411 --Adjustment Line Identifier
39412  , p_source_37            IN NUMBER
39413 --Distribution Type Code
39414  , p_source_38            IN VARCHAR2
39415 --Entered Amount
39416  , p_source_39            IN NUMBER
39417 --Currency Code
39418  , p_source_40            IN VARCHAR2
39419 )
39420 IS
39421 
39422 l_component_type              VARCHAR2(80);
39423 l_component_code              VARCHAR2(30);
39424 l_component_type_code         VARCHAR2(1);
39425 l_component_appl_id           INTEGER;
39426 l_amb_context_code            VARCHAR2(30);
39427 l_entity_code                 VARCHAR2(30);
39428 l_event_class_code            VARCHAR2(30);
39429 l_ae_header_id                NUMBER;
39430 l_event_type_code             VARCHAR2(30);
39431 l_line_definition_code        VARCHAR2(30);
39432 l_line_definition_owner_code  VARCHAR2(1);
39433 --
39434 -- adr variables
39435 l_segment                     VARCHAR2(30);
39436 l_ccid                        NUMBER;
39437 l_adr_transaction_coa_id      NUMBER;
39438 l_adr_accounting_coa_id       NUMBER;
39439 l_adr_flexfield_segment_code  VARCHAR2(30);
39440 l_adr_flex_value_set_id       NUMBER;
39441 l_adr_value_type_code         VARCHAR2(30);
39442 l_adr_value_combination_id    NUMBER;
39443 l_adr_value_segment_code      VARCHAR2(30);
39444 
39445 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
39446 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
39447 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
39448 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
39449 
39450 -- 4262811 Variables ------------------------------------------------------------------------------------------
39451 l_entered_amt_idx             NUMBER;
39452 l_accted_amt_idx              NUMBER;
39453 l_acc_rev_flag                VARCHAR2(1);
39454 l_accrual_line_num            NUMBER;
39455 l_tmp_amt                     NUMBER;
39456 l_acc_rev_natural_side_code   VARCHAR2(1);
39457 
39458 l_num_entries                 NUMBER;
39459 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
39460 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
39461 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
39462 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
39463 l_recog_line_1                NUMBER;
39464 l_recog_line_2                NUMBER;
39465 
39466 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
39467 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
39468 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
39469 
39470 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
39471 
39472 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
39473 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
39474 
39475 ---------------------------------------------------------------------------------------------------------------
39476 
39477 
39478 --
39479 -- bulk performance
39480 --
39481 l_balance_type_code           VARCHAR2(1);
39482 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
39483 l_log_module                  VARCHAR2(240);
39484 
39485 --
39486 -- Upgrade strategy
39487 --
39488 l_actual_upg_option           VARCHAR2(1);
39489 l_enc_upg_option           VARCHAR2(1);
39490 
39491 --
39492 BEGIN
39493 --
39494 IF g_log_enabled THEN
39495       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_210';
39496 END IF;
39497 --
39498 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
39499 
39500       trace
39501          (p_msg      => 'BEGIN of AcctLineType_210'
39502          ,p_level    => C_LEVEL_PROCEDURE
39503          ,p_module   => l_log_module);
39504 
39505 END IF;
39506 --
39507 l_component_type             := 'AMB_JLT';
39508 l_component_code             := 'FA_CIP_ADJ_COST_CLEARING';
39509 l_component_type_code        := 'S';
39510 l_component_appl_id          :=  140;
39511 l_amb_context_code           := 'DEFAULT';
39512 l_entity_code                := 'TRANSACTIONS';
39513 l_event_class_code           := 'CIP_ADJUSTMENTS';
39514 l_event_type_code            := 'CIP_ADJUSTMENTS_ALL';
39515 l_line_definition_owner_code := 'S';
39516 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_AD6';
39517 --
39518 l_balance_type_code          := 'A';
39519 l_segment                     := NULL;
39520 l_ccid                        := NULL;
39521 l_adr_transaction_coa_id      := NULL;
39522 l_adr_accounting_coa_id       := NULL;
39523 l_adr_flexfield_segment_code  := NULL;
39524 l_adr_flex_value_set_id       := NULL;
39525 l_adr_value_type_code         := NULL;
39526 l_adr_value_combination_id    := NULL;
39527 l_adr_value_segment_code      := NULL;
39528 
39529 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
39530 l_bflow_class_code           := '';    -- 4219869 Business Flow
39531 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
39532 l_budgetary_control_flag     := 'N';
39536 l_entered_amt_idx            := NULL;          -- 4262811
39533 
39534 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
39535 l_bflow_applied_to_amt       := NULL; -- 5132302
39537 l_accted_amt_idx             := NULL;          -- 4262811
39538 l_acc_rev_flag               := NULL;          -- 4262811
39539 l_accrual_line_num           := NULL;          -- 4262811
39540 l_tmp_amt                    := NULL;          -- 4262811
39541 --
39542  
39543 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
39544     l_balance_type_code <> 'B' THEN
39545 IF NVL(p_source_35,'
39546 ') =  'COST CLEARING'
39547  THEN 
39548 
39549    --
39550    XLA_AE_LINES_PKG.SetNewLine;
39551 
39552    p_balance_type_code          := l_balance_type_code;
39553    -- set the flag so later we will know whether the gain loss line needs to be created
39554    
39555    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
39556      p_actual_flag :='A';
39557    END IF;
39558 
39559    --
39560    -- bulk performance
39561    --
39562    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
39563                                       p_header_num   => 0); -- 4262811
39564    --
39565    -- set accounting line options
39566    --
39567    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
39568            p_natural_side_code          => 'C'
39569          , p_gain_or_loss_flag          => 'N'
39570          , p_gl_transfer_mode_code      => 'S'
39571          , p_acct_entry_type_code       => 'A'
39572          , p_switch_side_flag           => 'Y'
39573          , p_merge_duplicate_code       => 'N'
39574          );
39575    --
39576    l_acc_rev_natural_side_code := 'D';  -- 4262811
39577    -- 
39578    --
39579    -- set accounting line type info
39580    --
39581    xla_ae_lines_pkg.SetAcctLineType
39582       (p_component_type             => l_component_type
39583       ,p_event_type_code            => l_event_type_code
39584       ,p_line_definition_owner_code => l_line_definition_owner_code
39585       ,p_line_definition_code       => l_line_definition_code
39586       ,p_accounting_line_code       => l_component_code
39587       ,p_accounting_line_type_code  => l_component_type_code
39588       ,p_accounting_line_appl_id    => l_component_appl_id
39589       ,p_amb_context_code           => l_amb_context_code
39590       ,p_entity_code                => l_entity_code
39591       ,p_event_class_code           => l_event_class_code);
39592    --
39593    -- set accounting class
39594    --
39595    xla_ae_lines_pkg.SetAcctClass(
39596            p_accounting_class_code  => 'ASSET'
39597          , p_ae_header_id           => l_ae_header_id
39598          );
39599 
39600    --
39601    -- set rounding class
39602    --
39603    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
39604                       'ASSET';
39605 
39606    --
39607    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
39608    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
39609    --
39610    -- bulk performance
39611    --
39612    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
39613 
39614    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
39615       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
39616 
39617    -- 4955764
39618    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
39619       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
39620 
39621    -- 4458381 Public Sector Enh
39622    
39623    --
39624    -- set accounting attributes for the line type
39625    --
39626    l_entered_amt_idx := 4;
39627    l_accted_amt_idx  := 6;
39628    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
39629    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
39630    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
39631    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
39632    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
39633    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
39634    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
39635    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
39636    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
39637    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
39638    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
39639    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
39640    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
39641 
39642    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
39643    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
39644 
39645    ---------------------------------------------------------------------------------------------------------------
39646    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
39647    ---------------------------------------------------------------------------------------------------------------
39648    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
39649 
39650    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39651    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39652 
39653    IF xla_accounting_cache_pkg.GetValueChar
39654          (p_source_code         => 'LEDGER_CATEGORY_CODE'
39655          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
39659          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
39656    AND l_bflow_method_code = 'PRIOR_ENTRY'
39657 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
39658    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
39660        )
39661    THEN
39662          xla_ae_lines_pkg.BflowUpgEntry
39663            (p_business_method_code    => l_bflow_method_code
39664            ,p_business_class_code     => l_bflow_class_code
39665            ,p_balance_type            => l_balance_type_code);
39666    ELSE
39667       NULL;
39668 -- No business flow processing for business flow method of NONE.
39669    END IF;
39670 
39671    --
39672    -- call analytical criteria
39673    --
39674    
39675    --
39676    -- call description
39677    --
39678    
39679 xla_ae_lines_pkg.SetLineDescription(
39680    p_ae_header_id => l_ae_header_id
39681   ,p_description  => Description_27 (
39682      p_application_id         => p_application_id
39683    , p_ae_header_id           => l_ae_header_id 
39684 , p_source_1 => p_source_1
39685    )
39686 );
39687 
39688 
39689    --
39690    -- call ADRs
39691    -- Bug 4922099
39692    --
39693    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39694         (NVL(l_actual_upg_option, 'N') = 'O') OR
39695         (NVL(l_enc_upg_option, 'N') = 'O')
39696       )
39697    THEN
39698    NULL;
39699    --
39700    --
39701    
39702   l_ccid := AcctDerRule_171(
39703            p_application_id           => p_application_id
39704          , p_ae_header_id             => l_ae_header_id 
39705 , p_source_3 => p_source_3
39706 , p_source_6 => p_source_6
39707 , p_source_30 => p_source_30
39708          , x_transaction_coa_id       => l_adr_transaction_coa_id
39709          , x_accounting_coa_id        => l_adr_accounting_coa_id
39710          , x_value_type_code          => l_adr_value_type_code
39711          , p_side                     => 'NA'
39712    );
39713 
39714    xla_ae_lines_pkg.set_ccid(
39715     p_code_combination_id          => l_ccid
39716   , p_value_type_code              => l_adr_value_type_code
39717   , p_transaction_coa_id           => l_adr_transaction_coa_id
39718   , p_accounting_coa_id            => l_adr_accounting_coa_id
39719   , p_adr_code                     => 'FA_CAT_CIP_COST_CLEARING'
39720   , p_adr_type_code                => 'S'
39721   , p_component_type               => l_component_type
39722   , p_component_code               => l_component_code
39723   , p_component_type_code          => l_component_type_code
39724   , p_component_appl_id            => l_component_appl_id
39725   , p_amb_context_code             => l_amb_context_code
39726   , p_side                         => 'NA'
39727   );
39728 
39729 
39730    l_segment := AcctDerRule_145(
39731            p_application_id           => p_application_id
39732          , p_ae_header_id             => l_ae_header_id 
39733 , p_source_3 => p_source_3
39734 , p_source_5 => p_source_5
39735 , p_source_6 => p_source_6
39736          , x_transaction_coa_id       => l_adr_transaction_coa_id
39737          , x_accounting_coa_id        => l_adr_accounting_coa_id
39738          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39739          , x_flex_value_set_id        => l_adr_flex_value_set_id
39740          , x_value_type_code          => l_adr_value_type_code
39741          , x_value_combination_id     => l_adr_value_combination_id
39742          , x_value_segment_code       => l_adr_value_segment_code
39743          , p_side                     => 'NA'
39744          , p_override_seg_flag        => 'Y'
39745    );
39746 
39747    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39748 
39749       xla_ae_lines_pkg.set_segment(
39750           p_to_segment_code         => 'GL_ACCOUNT'
39751         , p_segment_value           => l_segment
39752         , p_from_segment_code       => l_adr_value_segment_code
39753         , p_from_combination_id     => l_adr_value_combination_id
39754         , p_value_type_code         => l_adr_value_type_code
39755         , p_transaction_coa_id      => l_adr_transaction_coa_id
39756         , p_accounting_coa_id       => l_adr_accounting_coa_id
39757         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39758         , p_flex_value_set_id       => l_adr_flex_value_set_id
39759         , p_adr_code                => 'FA_CAT_CIP_CLR_SEGMENT'
39760         , p_adr_type_code           => 'S'
39761         , p_component_type          => l_component_type
39762         , p_component_code          => l_component_code
39763         , p_component_type_code     => l_component_type_code
39764         , p_component_appl_id       => l_component_appl_id
39765         , p_amb_context_code        => l_amb_context_code
39766         , p_entity_code             => 'TRANSACTIONS'
39767         , p_event_class_code        => 'CIP_ADJUSTMENTS'
39768         , p_side                    => 'NA'
39769         );
39770 
39771   END IF;
39772 
39773    l_segment := AcctDerRule_169(
39774            p_application_id           => p_application_id
39775          , p_ae_header_id             => l_ae_header_id 
39776 , p_source_3 => p_source_3
39777 , p_source_6 => p_source_6
39778 , p_source_29 => p_source_29
39779          , x_transaction_coa_id       => l_adr_transaction_coa_id
39780          , x_accounting_coa_id        => l_adr_accounting_coa_id
39781          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39782          , x_flex_value_set_id        => l_adr_flex_value_set_id
39783          , x_value_type_code          => l_adr_value_type_code
39784          , x_value_combination_id     => l_adr_value_combination_id
39785          , x_value_segment_code       => l_adr_value_segment_code
39786          , p_side                     => 'NA'
39787          , p_override_seg_flag        => 'Y'
39788    );
39789 
39793           p_to_segment_code         => 'GL_BALANCING'
39790    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39791 
39792       xla_ae_lines_pkg.set_segment(
39794         , p_segment_value           => l_segment
39795         , p_from_segment_code       => l_adr_value_segment_code
39796         , p_from_combination_id     => l_adr_value_combination_id
39797         , p_value_type_code         => l_adr_value_type_code
39798         , p_transaction_coa_id      => l_adr_transaction_coa_id
39799         , p_accounting_coa_id       => l_adr_accounting_coa_id
39800         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39801         , p_flex_value_set_id       => l_adr_flex_value_set_id
39802         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
39803         , p_adr_type_code           => 'S'
39804         , p_component_type          => l_component_type
39805         , p_component_code          => l_component_code
39806         , p_component_type_code     => l_component_type_code
39807         , p_component_appl_id       => l_component_appl_id
39808         , p_amb_context_code        => l_amb_context_code
39809         , p_entity_code             => 'TRANSACTIONS'
39810         , p_event_class_code        => 'CIP_ADJUSTMENTS'
39811         , p_side                    => 'NA'
39812         );
39813 
39814   END IF;
39815 
39816    --
39817    --
39818    END IF;
39819    --
39820    -- Bug 4922099
39821    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
39822           (NVL(l_enc_upg_option, 'N') = 'O')
39823         ) AND
39824         (l_bflow_method_code = 'PRIOR_ENTRY')
39825       )
39826    THEN
39827       IF
39828       --
39829       1 = 2
39830       --
39831       THEN
39832       xla_accounting_err_pkg.build_message
39833                                     (p_appli_s_name            => 'XLA'
39834                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39835                                     ,p_token_1                 => 'LINE_NUMBER'
39836                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
39837                                     ,p_token_2                 => 'LINE_TYPE_NAME'
39838                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
39839                                                                              l_component_type
39840                                                                             ,l_component_code
39841                                                                             ,l_component_type_code
39842                                                                             ,l_component_appl_id
39843                                                                             ,l_amb_context_code
39844                                                                             ,l_entity_code
39845                                                                             ,l_event_class_code
39846                                                                            )
39847                                     ,p_token_3                 => 'OWNER'
39848                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
39849                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
39850                                                                           ,p_lookup_code    => l_component_type_code
39851                                                                          )
39852                                     ,p_token_4                 => 'PRODUCT_NAME'
39853                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
39854                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
39855                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
39856                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
39857                                     ,p_ae_header_id            =>  NULL
39858                                        );
39859 
39860         IF (C_LEVEL_ERROR>= g_log_level) THEN
39861                  trace
39862                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39863                       ,p_level    => C_LEVEL_ERROR
39864                       ,p_module   => l_log_module);
39865         END IF;
39866       END IF;
39867    END IF;
39868    --
39869    --
39870    ------------------------------------------------------------------------------------------------
39871    -- 4219869 Business Flow
39872    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
39873    -- Prior Entry.  Currently, the following code is always generated.
39874    ------------------------------------------------------------------------------------------------
39875    XLA_AE_LINES_PKG.ValidateCurrentLine;
39876 
39877    ------------------------------------------------------------------------------------
39878    -- 4219869 Business Flow
39879    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
39880    ------------------------------------------------------------------------------------
39881    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39882 
39883    ----------------------------------------------------------------------------------
39884    -- 4219869 Business Flow
39885    -- Update journal entry status -- Need to generate this within IF <condition>
39886    ----------------------------------------------------------------------------------
39887    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39888          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
39889          ,p_balance_type_code => l_balance_type_code
39890          );
39891 
39892    -------------------------------------------------------------------------------------------
39896       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
39893    -- 4262811 - Generate the Accrual Reversal lines
39894    -------------------------------------------------------------------------------------------
39895    BEGIN
39897                               (g_array_event(p_event_id).array_value_num('header_index'));
39898       IF l_acc_rev_flag IS NULL THEN
39899          l_acc_rev_flag := 'N';
39900       END IF;
39901    EXCEPTION
39902       WHEN OTHERS THEN
39903          l_acc_rev_flag := 'N';
39904    END;
39905    --
39906    IF (l_acc_rev_flag = 'Y') THEN
39907 
39908        -- 4645092  ------------------------------------------------------------------------------
39909        -- To allow MPA report to determine if it should generate report process
39910        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
39911        ------------------------------------------------------------------------------------------
39912 
39913        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
39914        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
39915    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
39916    -- call ADRs
39917    -- Bug 4922099
39918    --
39919    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39920         (NVL(l_actual_upg_option, 'N') = 'O') OR
39921         (NVL(l_enc_upg_option, 'N') = 'O')
39922       )
39923    THEN
39924    NULL;
39925    --
39926    --
39927    
39928   l_ccid := AcctDerRule_171(
39929            p_application_id           => p_application_id
39930          , p_ae_header_id             => l_ae_header_id 
39931 , p_source_3 => p_source_3
39932 , p_source_6 => p_source_6
39933 , p_source_30 => p_source_30
39934          , x_transaction_coa_id       => l_adr_transaction_coa_id
39935          , x_accounting_coa_id        => l_adr_accounting_coa_id
39936          , x_value_type_code          => l_adr_value_type_code
39937          , p_side                     => 'NA'
39938    );
39939 
39940    xla_ae_lines_pkg.set_ccid(
39941     p_code_combination_id          => l_ccid
39942   , p_value_type_code              => l_adr_value_type_code
39943   , p_transaction_coa_id           => l_adr_transaction_coa_id
39944   , p_accounting_coa_id            => l_adr_accounting_coa_id
39945   , p_adr_code                     => 'FA_CAT_CIP_COST_CLEARING'
39946   , p_adr_type_code                => 'S'
39947   , p_component_type               => l_component_type
39948   , p_component_code               => l_component_code
39949   , p_component_type_code          => l_component_type_code
39950   , p_component_appl_id            => l_component_appl_id
39951   , p_amb_context_code             => l_amb_context_code
39952   , p_side                         => 'NA'
39953   );
39954 
39955 
39956    l_segment := AcctDerRule_145(
39957            p_application_id           => p_application_id
39958          , p_ae_header_id             => l_ae_header_id 
39959 , p_source_3 => p_source_3
39960 , p_source_5 => p_source_5
39961 , p_source_6 => p_source_6
39962          , x_transaction_coa_id       => l_adr_transaction_coa_id
39963          , x_accounting_coa_id        => l_adr_accounting_coa_id
39964          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39965          , x_flex_value_set_id        => l_adr_flex_value_set_id
39966          , x_value_type_code          => l_adr_value_type_code
39967          , x_value_combination_id     => l_adr_value_combination_id
39968          , x_value_segment_code       => l_adr_value_segment_code
39969          , p_side                     => 'NA'
39970          , p_override_seg_flag        => 'Y'
39971    );
39972 
39973    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39974 
39975       xla_ae_lines_pkg.set_segment(
39976           p_to_segment_code         => 'GL_ACCOUNT'
39977         , p_segment_value           => l_segment
39978         , p_from_segment_code       => l_adr_value_segment_code
39979         , p_from_combination_id     => l_adr_value_combination_id
39980         , p_value_type_code         => l_adr_value_type_code
39981         , p_transaction_coa_id      => l_adr_transaction_coa_id
39982         , p_accounting_coa_id       => l_adr_accounting_coa_id
39983         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39984         , p_flex_value_set_id       => l_adr_flex_value_set_id
39985         , p_adr_code                => 'FA_CAT_CIP_CLR_SEGMENT'
39986         , p_adr_type_code           => 'S'
39987         , p_component_type          => l_component_type
39988         , p_component_code          => l_component_code
39989         , p_component_type_code     => l_component_type_code
39990         , p_component_appl_id       => l_component_appl_id
39991         , p_amb_context_code        => l_amb_context_code
39992         , p_entity_code             => 'TRANSACTIONS'
39993         , p_event_class_code        => 'CIP_ADJUSTMENTS'
39994         , p_side                    => 'NA'
39995         );
39996 
39997   END IF;
39998 
39999    l_segment := AcctDerRule_169(
40000            p_application_id           => p_application_id
40001          , p_ae_header_id             => l_ae_header_id 
40002 , p_source_3 => p_source_3
40003 , p_source_6 => p_source_6
40004 , p_source_29 => p_source_29
40005          , x_transaction_coa_id       => l_adr_transaction_coa_id
40006          , x_accounting_coa_id        => l_adr_accounting_coa_id
40007          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
40008          , x_flex_value_set_id        => l_adr_flex_value_set_id
40009          , x_value_type_code          => l_adr_value_type_code
40010          , x_value_combination_id     => l_adr_value_combination_id
40011          , x_value_segment_code       => l_adr_value_segment_code
40012          , p_side                     => 'NA'
40013          , p_override_seg_flag        => 'Y'
40014    );
40015 
40019           p_to_segment_code         => 'GL_BALANCING'
40016    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
40017 
40018       xla_ae_lines_pkg.set_segment(
40020         , p_segment_value           => l_segment
40021         , p_from_segment_code       => l_adr_value_segment_code
40022         , p_from_combination_id     => l_adr_value_combination_id
40023         , p_value_type_code         => l_adr_value_type_code
40024         , p_transaction_coa_id      => l_adr_transaction_coa_id
40025         , p_accounting_coa_id       => l_adr_accounting_coa_id
40026         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
40027         , p_flex_value_set_id       => l_adr_flex_value_set_id
40028         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
40029         , p_adr_type_code           => 'S'
40030         , p_component_type          => l_component_type
40031         , p_component_code          => l_component_code
40032         , p_component_type_code     => l_component_type_code
40033         , p_component_appl_id       => l_component_appl_id
40034         , p_amb_context_code        => l_amb_context_code
40035         , p_entity_code             => 'TRANSACTIONS'
40036         , p_event_class_code        => 'CIP_ADJUSTMENTS'
40037         , p_side                    => 'NA'
40038         );
40039 
40040   END IF;
40041 
40042    --
40043    --
40044    END IF;
40045 
40046        --
40047        -- Update the line information that should be overwritten
40048        --
40049        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
40050                                          p_header_num   => 1);
40051        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
40052 
40053        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
40054 
40055        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
40056           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
40057        END IF;
40058 
40059       --
40060       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
40061       --
40062       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
40063           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
40064       ELSE
40065           ---------------------------------------------------------------------------------------------------
40066           -- 4262811a Switch Sign
40067           ---------------------------------------------------------------------------------------------------
40068           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
40069           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40070                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40071           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40072                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40073           -- 5132302
40074           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
40075                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40076 
40077       END IF;
40078 
40079       -- 4955764
40080       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
40081       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
40082 
40083 
40084       XLA_AE_LINES_PKG.ValidateCurrentLine;
40085       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
40086 
40087       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
40088                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
40089                ,p_balance_type_code => l_balance_type_code);
40090 
40091    END IF;
40092 
40093    -----------------------------------------------------------------------------------------
40094    -- 4262811 Multiperiod Accounting
40095    -----------------------------------------------------------------------------------------
40096      -- No MPA option is assigned.
40097 
40098 
40099 END IF;
40100 END IF;
40101 --
40102 
40103 --
40104 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40105    trace
40106       (p_msg      => 'END of AcctLineType_210'
40107       ,p_level    => C_LEVEL_PROCEDURE
40108       ,p_module   => l_log_module);
40109 END IF;
40110 --
40111 EXCEPTION
40112   WHEN xla_exceptions_pkg.application_exception THEN
40113       RAISE;
40114   WHEN OTHERS THEN
40115        xla_exceptions_pkg.raise_message
40116            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_210');
40117 END AcctLineType_210;
40118 --
40119 
40120 ---------------------------------------
40121 --
40122 -- PRIVATE FUNCTION
40123 --         AcctLineType_211
40124 --
40125 ---------------------------------------
40126 PROCEDURE AcctLineType_211 (
40127   p_application_id        IN NUMBER
40128  ,p_event_id              IN NUMBER
40129  ,p_calculate_acctd_flag  IN VARCHAR2
40130  ,p_calculate_g_l_flag    IN VARCHAR2
40131  ,p_actual_flag           IN OUT VARCHAR2
40132  ,p_balance_type_code     OUT VARCHAR2
40133  ,p_gain_or_loss_ref      OUT VARCHAR2
40134  
40135 --Period Close Date
40136  , p_source_1            IN DATE
40137 --Generated Code Combination Identifier
40138  , p_source_3            IN NUMBER
40139 --Cost Of Removal Clearing Account
40140  , p_source_12            IN VARCHAR2
40141 --Expense Account Code Combination Identifier
40142  , p_source_29            IN NUMBER
40146  , p_source_35            IN VARCHAR2
40143 --Default Code Combination Identifier
40144  , p_source_30            IN NUMBER
40145 --Adjustment Type
40147 --Transaction Header Identifier
40148  , p_source_36            IN NUMBER
40149 --Adjustment Line Identifier
40150  , p_source_37            IN NUMBER
40151 --Distribution Type Code
40152  , p_source_38            IN VARCHAR2
40153 --Entered Amount
40154  , p_source_39            IN NUMBER
40155 --Currency Code
40156  , p_source_40            IN VARCHAR2
40157 )
40158 IS
40159 
40160 l_component_type              VARCHAR2(80);
40161 l_component_code              VARCHAR2(30);
40162 l_component_type_code         VARCHAR2(1);
40163 l_component_appl_id           INTEGER;
40164 l_amb_context_code            VARCHAR2(30);
40165 l_entity_code                 VARCHAR2(30);
40166 l_event_class_code            VARCHAR2(30);
40167 l_ae_header_id                NUMBER;
40168 l_event_type_code             VARCHAR2(30);
40169 l_line_definition_code        VARCHAR2(30);
40170 l_line_definition_owner_code  VARCHAR2(1);
40171 --
40172 -- adr variables
40173 l_segment                     VARCHAR2(30);
40174 l_ccid                        NUMBER;
40175 l_adr_transaction_coa_id      NUMBER;
40176 l_adr_accounting_coa_id       NUMBER;
40177 l_adr_flexfield_segment_code  VARCHAR2(30);
40178 l_adr_flex_value_set_id       NUMBER;
40179 l_adr_value_type_code         VARCHAR2(30);
40180 l_adr_value_combination_id    NUMBER;
40181 l_adr_value_segment_code      VARCHAR2(30);
40182 
40183 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
40184 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
40185 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
40186 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
40187 
40188 -- 4262811 Variables ------------------------------------------------------------------------------------------
40189 l_entered_amt_idx             NUMBER;
40190 l_accted_amt_idx              NUMBER;
40191 l_acc_rev_flag                VARCHAR2(1);
40192 l_accrual_line_num            NUMBER;
40193 l_tmp_amt                     NUMBER;
40194 l_acc_rev_natural_side_code   VARCHAR2(1);
40195 
40196 l_num_entries                 NUMBER;
40197 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
40198 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
40199 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
40200 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
40201 l_recog_line_1                NUMBER;
40202 l_recog_line_2                NUMBER;
40203 
40204 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
40205 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
40206 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
40207 
40208 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
40209 
40210 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
40211 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
40212 
40213 ---------------------------------------------------------------------------------------------------------------
40214 
40215 
40216 --
40217 -- bulk performance
40218 --
40219 l_balance_type_code           VARCHAR2(1);
40220 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
40221 l_log_module                  VARCHAR2(240);
40222 
40223 --
40224 -- Upgrade strategy
40225 --
40226 l_actual_upg_option           VARCHAR2(1);
40227 l_enc_upg_option           VARCHAR2(1);
40228 
40229 --
40230 BEGIN
40231 --
40232 IF g_log_enabled THEN
40233       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_211';
40234 END IF;
40235 --
40236 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40237 
40238       trace
40239          (p_msg      => 'BEGIN of AcctLineType_211'
40240          ,p_level    => C_LEVEL_PROCEDURE
40241          ,p_module   => l_log_module);
40242 
40243 END IF;
40244 --
40245 l_component_type             := 'AMB_JLT';
40246 l_component_code             := 'FA_CIP_COST_OF_REMOVAL_CLR';
40247 l_component_type_code        := 'S';
40248 l_component_appl_id          :=  140;
40249 l_amb_context_code           := 'DEFAULT';
40250 l_entity_code                := 'TRANSACTIONS';
40251 l_event_class_code           := 'CIP_RETIREMENTS';
40252 l_event_type_code            := 'CIP_REINSTATEMENTS';
40253 l_line_definition_owner_code := 'S';
40254 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
40255 --
40256 l_balance_type_code          := 'A';
40257 l_segment                     := NULL;
40258 l_ccid                        := NULL;
40259 l_adr_transaction_coa_id      := NULL;
40260 l_adr_accounting_coa_id       := NULL;
40261 l_adr_flexfield_segment_code  := NULL;
40262 l_adr_flex_value_set_id       := NULL;
40263 l_adr_value_type_code         := NULL;
40264 l_adr_value_combination_id    := NULL;
40265 l_adr_value_segment_code      := NULL;
40266 
40267 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
40268 l_bflow_class_code           := '';    -- 4219869 Business Flow
40269 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
40270 l_budgetary_control_flag     := 'N';
40271 
40272 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
40273 l_bflow_applied_to_amt       := NULL; -- 5132302
40274 l_entered_amt_idx            := NULL;          -- 4262811
40275 l_accted_amt_idx             := NULL;          -- 4262811
40276 l_acc_rev_flag               := NULL;          -- 4262811
40277 l_accrual_line_num           := NULL;          -- 4262811
40278 l_tmp_amt                    := NULL;          -- 4262811
40279 --
40280  
40284 ') =  'REMOVALCOST CLR'
40281 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
40282     l_balance_type_code <> 'B' THEN
40283 IF NVL(p_source_35,'
40285  THEN 
40286 
40287    --
40288    XLA_AE_LINES_PKG.SetNewLine;
40289 
40290    p_balance_type_code          := l_balance_type_code;
40291    -- set the flag so later we will know whether the gain loss line needs to be created
40292    
40293    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
40294      p_actual_flag :='A';
40295    END IF;
40296 
40297    --
40298    -- bulk performance
40299    --
40300    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
40301                                       p_header_num   => 0); -- 4262811
40302    --
40303    -- set accounting line options
40304    --
40305    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
40306            p_natural_side_code          => 'C'
40307          , p_gain_or_loss_flag          => 'N'
40308          , p_gl_transfer_mode_code      => 'S'
40309          , p_acct_entry_type_code       => 'A'
40310          , p_switch_side_flag           => 'Y'
40311          , p_merge_duplicate_code       => 'N'
40312          );
40313    --
40314    l_acc_rev_natural_side_code := 'D';  -- 4262811
40315    -- 
40316    --
40317    -- set accounting line type info
40318    --
40319    xla_ae_lines_pkg.SetAcctLineType
40320       (p_component_type             => l_component_type
40321       ,p_event_type_code            => l_event_type_code
40322       ,p_line_definition_owner_code => l_line_definition_owner_code
40323       ,p_line_definition_code       => l_line_definition_code
40324       ,p_accounting_line_code       => l_component_code
40325       ,p_accounting_line_type_code  => l_component_type_code
40326       ,p_accounting_line_appl_id    => l_component_appl_id
40327       ,p_amb_context_code           => l_amb_context_code
40328       ,p_entity_code                => l_entity_code
40329       ,p_event_class_code           => l_event_class_code);
40330    --
40331    -- set accounting class
40332    --
40333    xla_ae_lines_pkg.SetAcctClass(
40334            p_accounting_class_code  => 'ASSET'
40335          , p_ae_header_id           => l_ae_header_id
40336          );
40337 
40338    --
40339    -- set rounding class
40340    --
40341    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
40342                       'ASSET';
40343 
40344    --
40345    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
40346    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
40347    --
40348    -- bulk performance
40349    --
40350    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
40351 
40352    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
40353       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
40354 
40355    -- 4955764
40356    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
40357       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
40358 
40359    -- 4458381 Public Sector Enh
40360    
40361    --
40362    -- set accounting attributes for the line type
40363    --
40364    l_entered_amt_idx := 4;
40365    l_accted_amt_idx  := 6;
40366    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
40367    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
40368    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
40369    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
40370    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
40371    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
40372    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
40373    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
40374    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
40375    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
40376    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
40377    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
40378    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
40379 
40380    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
40381    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
40382 
40383    ---------------------------------------------------------------------------------------------------------------
40384    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
40385    ---------------------------------------------------------------------------------------------------------------
40386    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
40387 
40388    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
40389    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
40390 
40391    IF xla_accounting_cache_pkg.GetValueChar
40392          (p_source_code         => 'LEDGER_CATEGORY_CODE'
40393          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
40394    AND l_bflow_method_code = 'PRIOR_ENTRY'
40395 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
40396    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
40397          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
40398        )
40399    THEN
40400          xla_ae_lines_pkg.BflowUpgEntry
40401            (p_business_method_code    => l_bflow_method_code
40402            ,p_business_class_code     => l_bflow_class_code
40406 -- No business flow processing for business flow method of NONE.
40403            ,p_balance_type            => l_balance_type_code);
40404    ELSE
40405       NULL;
40407    END IF;
40408 
40409    --
40410    -- call analytical criteria
40411    --
40412    
40413    --
40414    -- call description
40415    --
40416    
40417 xla_ae_lines_pkg.SetLineDescription(
40418    p_ae_header_id => l_ae_header_id
40419   ,p_description  => Description_37 (
40420      p_application_id         => p_application_id
40421    , p_ae_header_id           => l_ae_header_id 
40422 , p_source_1 => p_source_1
40423    )
40424 );
40425 
40426 
40427    --
40428    -- call ADRs
40429    -- Bug 4922099
40430    --
40431    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
40432         (NVL(l_actual_upg_option, 'N') = 'O') OR
40433         (NVL(l_enc_upg_option, 'N') = 'O')
40434       )
40435    THEN
40436    NULL;
40437    --
40438    --
40439    
40440   l_ccid := AcctDerRule_173(
40441            p_application_id           => p_application_id
40442          , p_ae_header_id             => l_ae_header_id 
40443 , p_source_3 => p_source_3
40444 , p_source_30 => p_source_30
40445          , x_transaction_coa_id       => l_adr_transaction_coa_id
40446          , x_accounting_coa_id        => l_adr_accounting_coa_id
40447          , x_value_type_code          => l_adr_value_type_code
40448          , p_side                     => 'NA'
40449    );
40450 
40451    xla_ae_lines_pkg.set_ccid(
40452     p_code_combination_id          => l_ccid
40453   , p_value_type_code              => l_adr_value_type_code
40454   , p_transaction_coa_id           => l_adr_transaction_coa_id
40455   , p_accounting_coa_id            => l_adr_accounting_coa_id
40456   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
40457   , p_adr_type_code                => 'S'
40458   , p_component_type               => l_component_type
40459   , p_component_code               => l_component_code
40460   , p_component_type_code          => l_component_type_code
40461   , p_component_appl_id            => l_component_appl_id
40462   , p_amb_context_code             => l_amb_context_code
40463   , p_side                         => 'NA'
40464   );
40465 
40466 
40467    l_segment := AcctDerRule_151(
40468            p_application_id           => p_application_id
40469          , p_ae_header_id             => l_ae_header_id 
40470 , p_source_3 => p_source_3
40471 , p_source_12 => p_source_12
40472          , x_transaction_coa_id       => l_adr_transaction_coa_id
40473          , x_accounting_coa_id        => l_adr_accounting_coa_id
40474          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
40475          , x_flex_value_set_id        => l_adr_flex_value_set_id
40476          , x_value_type_code          => l_adr_value_type_code
40477          , x_value_combination_id     => l_adr_value_combination_id
40478          , x_value_segment_code       => l_adr_value_segment_code
40479          , p_side                     => 'NA'
40480          , p_override_seg_flag        => 'Y'
40481    );
40482 
40483    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
40484 
40485       xla_ae_lines_pkg.set_segment(
40486           p_to_segment_code         => 'GL_ACCOUNT'
40487         , p_segment_value           => l_segment
40488         , p_from_segment_code       => l_adr_value_segment_code
40489         , p_from_combination_id     => l_adr_value_combination_id
40490         , p_value_type_code         => l_adr_value_type_code
40491         , p_transaction_coa_id      => l_adr_transaction_coa_id
40492         , p_accounting_coa_id       => l_adr_accounting_coa_id
40493         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
40494         , p_flex_value_set_id       => l_adr_flex_value_set_id
40495         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
40496         , p_adr_type_code           => 'S'
40497         , p_component_type          => l_component_type
40498         , p_component_code          => l_component_code
40499         , p_component_type_code     => l_component_type_code
40500         , p_component_appl_id       => l_component_appl_id
40501         , p_amb_context_code        => l_amb_context_code
40502         , p_entity_code             => 'TRANSACTIONS'
40503         , p_event_class_code        => 'CIP_RETIREMENTS'
40504         , p_side                    => 'NA'
40505         );
40506 
40507   END IF;
40508 
40509    l_segment := AcctDerRule_168(
40510            p_application_id           => p_application_id
40511          , p_ae_header_id             => l_ae_header_id 
40512 , p_source_3 => p_source_3
40513 , p_source_29 => p_source_29
40514          , x_transaction_coa_id       => l_adr_transaction_coa_id
40515          , x_accounting_coa_id        => l_adr_accounting_coa_id
40516          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
40517          , x_flex_value_set_id        => l_adr_flex_value_set_id
40518          , x_value_type_code          => l_adr_value_type_code
40519          , x_value_combination_id     => l_adr_value_combination_id
40520          , x_value_segment_code       => l_adr_value_segment_code
40521          , p_side                     => 'NA'
40522          , p_override_seg_flag        => 'Y'
40523    );
40524 
40525    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
40526 
40527       xla_ae_lines_pkg.set_segment(
40528           p_to_segment_code         => 'GL_BALANCING'
40529         , p_segment_value           => l_segment
40530         , p_from_segment_code       => l_adr_value_segment_code
40531         , p_from_combination_id     => l_adr_value_combination_id
40532         , p_value_type_code         => l_adr_value_type_code
40533         , p_transaction_coa_id      => l_adr_transaction_coa_id
40534         , p_accounting_coa_id       => l_adr_accounting_coa_id
40538         , p_adr_type_code           => 'S'
40535         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
40536         , p_flex_value_set_id       => l_adr_flex_value_set_id
40537         , p_adr_code                => 'FA_EXPENSE_ACCT'
40539         , p_component_type          => l_component_type
40540         , p_component_code          => l_component_code
40541         , p_component_type_code     => l_component_type_code
40542         , p_component_appl_id       => l_component_appl_id
40543         , p_amb_context_code        => l_amb_context_code
40544         , p_entity_code             => 'TRANSACTIONS'
40545         , p_event_class_code        => 'CIP_RETIREMENTS'
40546         , p_side                    => 'NA'
40547         );
40548 
40549   END IF;
40550 
40551    --
40552    --
40553    END IF;
40554    --
40555    -- Bug 4922099
40556    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
40557           (NVL(l_enc_upg_option, 'N') = 'O')
40558         ) AND
40559         (l_bflow_method_code = 'PRIOR_ENTRY')
40560       )
40561    THEN
40562       IF
40563       --
40564       1 = 2
40565       --
40566       THEN
40567       xla_accounting_err_pkg.build_message
40568                                     (p_appli_s_name            => 'XLA'
40569                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
40570                                     ,p_token_1                 => 'LINE_NUMBER'
40571                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
40572                                     ,p_token_2                 => 'LINE_TYPE_NAME'
40573                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
40574                                                                              l_component_type
40575                                                                             ,l_component_code
40576                                                                             ,l_component_type_code
40577                                                                             ,l_component_appl_id
40578                                                                             ,l_amb_context_code
40579                                                                             ,l_entity_code
40580                                                                             ,l_event_class_code
40581                                                                            )
40582                                     ,p_token_3                 => 'OWNER'
40583                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
40584                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
40585                                                                           ,p_lookup_code    => l_component_type_code
40586                                                                          )
40587                                     ,p_token_4                 => 'PRODUCT_NAME'
40588                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
40589                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
40590                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
40591                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
40592                                     ,p_ae_header_id            =>  NULL
40593                                        );
40594 
40595         IF (C_LEVEL_ERROR>= g_log_level) THEN
40596                  trace
40597                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
40598                       ,p_level    => C_LEVEL_ERROR
40599                       ,p_module   => l_log_module);
40600         END IF;
40601       END IF;
40602    END IF;
40603    --
40604    --
40605    ------------------------------------------------------------------------------------------------
40606    -- 4219869 Business Flow
40607    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
40608    -- Prior Entry.  Currently, the following code is always generated.
40609    ------------------------------------------------------------------------------------------------
40610    XLA_AE_LINES_PKG.ValidateCurrentLine;
40611 
40612    ------------------------------------------------------------------------------------
40613    -- 4219869 Business Flow
40614    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
40615    ------------------------------------------------------------------------------------
40616    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
40617 
40618    ----------------------------------------------------------------------------------
40619    -- 4219869 Business Flow
40620    -- Update journal entry status -- Need to generate this within IF <condition>
40621    ----------------------------------------------------------------------------------
40622    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
40623          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
40624          ,p_balance_type_code => l_balance_type_code
40625          );
40626 
40627    -------------------------------------------------------------------------------------------
40628    -- 4262811 - Generate the Accrual Reversal lines
40629    -------------------------------------------------------------------------------------------
40630    BEGIN
40631       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
40632                               (g_array_event(p_event_id).array_value_num('header_index'));
40633       IF l_acc_rev_flag IS NULL THEN
40634          l_acc_rev_flag := 'N';
40635       END IF;
40636    EXCEPTION
40637       WHEN OTHERS THEN
40638          l_acc_rev_flag := 'N';
40639    END;
40640    --
40644        -- To allow MPA report to determine if it should generate report process
40641    IF (l_acc_rev_flag = 'Y') THEN
40642 
40643        -- 4645092  ------------------------------------------------------------------------------
40645        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
40646        ------------------------------------------------------------------------------------------
40647 
40648        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
40649        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
40650    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
40651    -- call ADRs
40652    -- Bug 4922099
40653    --
40654    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
40655         (NVL(l_actual_upg_option, 'N') = 'O') OR
40656         (NVL(l_enc_upg_option, 'N') = 'O')
40657       )
40658    THEN
40659    NULL;
40660    --
40661    --
40662    
40663   l_ccid := AcctDerRule_173(
40664            p_application_id           => p_application_id
40665          , p_ae_header_id             => l_ae_header_id 
40666 , p_source_3 => p_source_3
40667 , p_source_30 => p_source_30
40668          , x_transaction_coa_id       => l_adr_transaction_coa_id
40669          , x_accounting_coa_id        => l_adr_accounting_coa_id
40670          , x_value_type_code          => l_adr_value_type_code
40671          , p_side                     => 'NA'
40672    );
40673 
40674    xla_ae_lines_pkg.set_ccid(
40675     p_code_combination_id          => l_ccid
40676   , p_value_type_code              => l_adr_value_type_code
40677   , p_transaction_coa_id           => l_adr_transaction_coa_id
40678   , p_accounting_coa_id            => l_adr_accounting_coa_id
40679   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
40680   , p_adr_type_code                => 'S'
40681   , p_component_type               => l_component_type
40682   , p_component_code               => l_component_code
40683   , p_component_type_code          => l_component_type_code
40684   , p_component_appl_id            => l_component_appl_id
40685   , p_amb_context_code             => l_amb_context_code
40686   , p_side                         => 'NA'
40687   );
40688 
40689 
40690    l_segment := AcctDerRule_151(
40691            p_application_id           => p_application_id
40692          , p_ae_header_id             => l_ae_header_id 
40693 , p_source_3 => p_source_3
40694 , p_source_12 => p_source_12
40695          , x_transaction_coa_id       => l_adr_transaction_coa_id
40696          , x_accounting_coa_id        => l_adr_accounting_coa_id
40697          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
40698          , x_flex_value_set_id        => l_adr_flex_value_set_id
40699          , x_value_type_code          => l_adr_value_type_code
40700          , x_value_combination_id     => l_adr_value_combination_id
40701          , x_value_segment_code       => l_adr_value_segment_code
40702          , p_side                     => 'NA'
40703          , p_override_seg_flag        => 'Y'
40704    );
40705 
40706    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
40707 
40708       xla_ae_lines_pkg.set_segment(
40709           p_to_segment_code         => 'GL_ACCOUNT'
40710         , p_segment_value           => l_segment
40711         , p_from_segment_code       => l_adr_value_segment_code
40712         , p_from_combination_id     => l_adr_value_combination_id
40713         , p_value_type_code         => l_adr_value_type_code
40714         , p_transaction_coa_id      => l_adr_transaction_coa_id
40715         , p_accounting_coa_id       => l_adr_accounting_coa_id
40716         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
40717         , p_flex_value_set_id       => l_adr_flex_value_set_id
40718         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
40719         , p_adr_type_code           => 'S'
40720         , p_component_type          => l_component_type
40721         , p_component_code          => l_component_code
40722         , p_component_type_code     => l_component_type_code
40723         , p_component_appl_id       => l_component_appl_id
40724         , p_amb_context_code        => l_amb_context_code
40725         , p_entity_code             => 'TRANSACTIONS'
40726         , p_event_class_code        => 'CIP_RETIREMENTS'
40727         , p_side                    => 'NA'
40728         );
40729 
40730   END IF;
40731 
40732    l_segment := AcctDerRule_168(
40733            p_application_id           => p_application_id
40734          , p_ae_header_id             => l_ae_header_id 
40735 , p_source_3 => p_source_3
40736 , p_source_29 => p_source_29
40737          , x_transaction_coa_id       => l_adr_transaction_coa_id
40738          , x_accounting_coa_id        => l_adr_accounting_coa_id
40739          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
40740          , x_flex_value_set_id        => l_adr_flex_value_set_id
40741          , x_value_type_code          => l_adr_value_type_code
40742          , x_value_combination_id     => l_adr_value_combination_id
40743          , x_value_segment_code       => l_adr_value_segment_code
40744          , p_side                     => 'NA'
40745          , p_override_seg_flag        => 'Y'
40746    );
40747 
40748    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
40749 
40750       xla_ae_lines_pkg.set_segment(
40751           p_to_segment_code         => 'GL_BALANCING'
40752         , p_segment_value           => l_segment
40753         , p_from_segment_code       => l_adr_value_segment_code
40754         , p_from_combination_id     => l_adr_value_combination_id
40755         , p_value_type_code         => l_adr_value_type_code
40756         , p_transaction_coa_id      => l_adr_transaction_coa_id
40757         , p_accounting_coa_id       => l_adr_accounting_coa_id
40758         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
40759         , p_flex_value_set_id       => l_adr_flex_value_set_id
40763         , p_component_code          => l_component_code
40760         , p_adr_code                => 'FA_EXPENSE_ACCT'
40761         , p_adr_type_code           => 'S'
40762         , p_component_type          => l_component_type
40764         , p_component_type_code     => l_component_type_code
40765         , p_component_appl_id       => l_component_appl_id
40766         , p_amb_context_code        => l_amb_context_code
40767         , p_entity_code             => 'TRANSACTIONS'
40768         , p_event_class_code        => 'CIP_RETIREMENTS'
40769         , p_side                    => 'NA'
40770         );
40771 
40772   END IF;
40773 
40774    --
40775    --
40776    END IF;
40777 
40778        --
40779        -- Update the line information that should be overwritten
40780        --
40781        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
40782                                          p_header_num   => 1);
40783        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
40784 
40785        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
40786 
40787        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
40788           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
40789        END IF;
40790 
40791       --
40792       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
40793       --
40794       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
40795           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
40796       ELSE
40797           ---------------------------------------------------------------------------------------------------
40798           -- 4262811a Switch Sign
40799           ---------------------------------------------------------------------------------------------------
40800           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
40801           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40802                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40803           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40804                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40805           -- 5132302
40806           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
40807                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40808 
40809       END IF;
40810 
40811       -- 4955764
40812       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
40813       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
40814 
40815 
40816       XLA_AE_LINES_PKG.ValidateCurrentLine;
40817       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
40818 
40819       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
40820                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
40821                ,p_balance_type_code => l_balance_type_code);
40822 
40823    END IF;
40824 
40825    -----------------------------------------------------------------------------------------
40826    -- 4262811 Multiperiod Accounting
40827    -----------------------------------------------------------------------------------------
40828      -- No MPA option is assigned.
40829 
40830 
40831 END IF;
40832 END IF;
40833 --
40834 
40835 --
40836 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40837    trace
40838       (p_msg      => 'END of AcctLineType_211'
40839       ,p_level    => C_LEVEL_PROCEDURE
40840       ,p_module   => l_log_module);
40841 END IF;
40842 --
40843 EXCEPTION
40844   WHEN xla_exceptions_pkg.application_exception THEN
40845       RAISE;
40846   WHEN OTHERS THEN
40847        xla_exceptions_pkg.raise_message
40848            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_211');
40849 END AcctLineType_211;
40850 --
40851 
40852 ---------------------------------------
40853 --
40854 -- PRIVATE FUNCTION
40855 --         AcctLineType_212
40856 --
40857 ---------------------------------------
40858 PROCEDURE AcctLineType_212 (
40859   p_application_id        IN NUMBER
40860  ,p_event_id              IN NUMBER
40861  ,p_calculate_acctd_flag  IN VARCHAR2
40862  ,p_calculate_g_l_flag    IN VARCHAR2
40863  ,p_actual_flag           IN OUT VARCHAR2
40864  ,p_balance_type_code     OUT VARCHAR2
40865  ,p_gain_or_loss_ref      OUT VARCHAR2
40866  
40867 --Period Close Date
40868  , p_source_1            IN DATE
40869 --Generated Code Combination Identifier
40870  , p_source_3            IN NUMBER
40871 --Cost Of Removal Clearing Account
40872  , p_source_12            IN VARCHAR2
40873 --Expense Account Code Combination Identifier
40874  , p_source_29            IN NUMBER
40875 --Default Code Combination Identifier
40876  , p_source_30            IN NUMBER
40877 --Adjustment Type
40878  , p_source_35            IN VARCHAR2
40879 --Transaction Header Identifier
40880  , p_source_36            IN NUMBER
40881 --Adjustment Line Identifier
40882  , p_source_37            IN NUMBER
40883 --Distribution Type Code
40884  , p_source_38            IN VARCHAR2
40885 --Entered Amount
40886  , p_source_39            IN NUMBER
40887 --Currency Code
40888  , p_source_40            IN VARCHAR2
40889 )
40890 IS
40891 
40892 l_component_type              VARCHAR2(80);
40893 l_component_code              VARCHAR2(30);
40894 l_component_type_code         VARCHAR2(1);
40898 l_event_class_code            VARCHAR2(30);
40895 l_component_appl_id           INTEGER;
40896 l_amb_context_code            VARCHAR2(30);
40897 l_entity_code                 VARCHAR2(30);
40899 l_ae_header_id                NUMBER;
40900 l_event_type_code             VARCHAR2(30);
40901 l_line_definition_code        VARCHAR2(30);
40902 l_line_definition_owner_code  VARCHAR2(1);
40903 --
40904 -- adr variables
40905 l_segment                     VARCHAR2(30);
40906 l_ccid                        NUMBER;
40907 l_adr_transaction_coa_id      NUMBER;
40908 l_adr_accounting_coa_id       NUMBER;
40909 l_adr_flexfield_segment_code  VARCHAR2(30);
40910 l_adr_flex_value_set_id       NUMBER;
40911 l_adr_value_type_code         VARCHAR2(30);
40912 l_adr_value_combination_id    NUMBER;
40913 l_adr_value_segment_code      VARCHAR2(30);
40914 
40915 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
40916 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
40917 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
40918 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
40919 
40920 -- 4262811 Variables ------------------------------------------------------------------------------------------
40921 l_entered_amt_idx             NUMBER;
40922 l_accted_amt_idx              NUMBER;
40923 l_acc_rev_flag                VARCHAR2(1);
40924 l_accrual_line_num            NUMBER;
40925 l_tmp_amt                     NUMBER;
40926 l_acc_rev_natural_side_code   VARCHAR2(1);
40927 
40928 l_num_entries                 NUMBER;
40929 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
40930 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
40931 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
40932 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
40933 l_recog_line_1                NUMBER;
40934 l_recog_line_2                NUMBER;
40935 
40936 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
40937 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
40938 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
40939 
40940 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
40941 
40942 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
40943 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
40944 
40945 ---------------------------------------------------------------------------------------------------------------
40946 
40947 
40948 --
40949 -- bulk performance
40950 --
40951 l_balance_type_code           VARCHAR2(1);
40952 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
40953 l_log_module                  VARCHAR2(240);
40954 
40955 --
40956 -- Upgrade strategy
40957 --
40958 l_actual_upg_option           VARCHAR2(1);
40959 l_enc_upg_option           VARCHAR2(1);
40960 
40961 --
40962 BEGIN
40963 --
40964 IF g_log_enabled THEN
40965       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_212';
40966 END IF;
40967 --
40968 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40969 
40970       trace
40971          (p_msg      => 'BEGIN of AcctLineType_212'
40972          ,p_level    => C_LEVEL_PROCEDURE
40973          ,p_module   => l_log_module);
40974 
40975 END IF;
40976 --
40977 l_component_type             := 'AMB_JLT';
40978 l_component_code             := 'FA_CIP_COST_OF_REMOVAL_CLR';
40979 l_component_type_code        := 'S';
40980 l_component_appl_id          :=  140;
40981 l_amb_context_code           := 'DEFAULT';
40982 l_entity_code                := 'TRANSACTIONS';
40983 l_event_class_code           := 'CIP_RETIREMENTS';
40984 l_event_type_code            := 'CIP_RETIREMENTS';
40985 l_line_definition_owner_code := 'S';
40986 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
40987 --
40988 l_balance_type_code          := 'A';
40989 l_segment                     := NULL;
40990 l_ccid                        := NULL;
40991 l_adr_transaction_coa_id      := NULL;
40992 l_adr_accounting_coa_id       := NULL;
40993 l_adr_flexfield_segment_code  := NULL;
40994 l_adr_flex_value_set_id       := NULL;
40995 l_adr_value_type_code         := NULL;
40996 l_adr_value_combination_id    := NULL;
40997 l_adr_value_segment_code      := NULL;
40998 
40999 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
41000 l_bflow_class_code           := '';    -- 4219869 Business Flow
41001 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
41002 l_budgetary_control_flag     := 'N';
41003 
41004 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
41005 l_bflow_applied_to_amt       := NULL; -- 5132302
41006 l_entered_amt_idx            := NULL;          -- 4262811
41007 l_accted_amt_idx             := NULL;          -- 4262811
41008 l_acc_rev_flag               := NULL;          -- 4262811
41009 l_accrual_line_num           := NULL;          -- 4262811
41010 l_tmp_amt                    := NULL;          -- 4262811
41011 --
41012  
41013 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
41014     l_balance_type_code <> 'B' THEN
41015 IF NVL(p_source_35,'
41016 ') =  'REMOVALCOST CLR'
41017  THEN 
41018 
41019    --
41020    XLA_AE_LINES_PKG.SetNewLine;
41021 
41022    p_balance_type_code          := l_balance_type_code;
41023    -- set the flag so later we will know whether the gain loss line needs to be created
41024    
41025    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
41026      p_actual_flag :='A';
41027    END IF;
41028 
41029    --
41030    -- bulk performance
41031    --
41032    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
41036    --
41033                                       p_header_num   => 0); -- 4262811
41034    --
41035    -- set accounting line options
41037    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
41038            p_natural_side_code          => 'C'
41039          , p_gain_or_loss_flag          => 'N'
41040          , p_gl_transfer_mode_code      => 'S'
41041          , p_acct_entry_type_code       => 'A'
41042          , p_switch_side_flag           => 'Y'
41043          , p_merge_duplicate_code       => 'N'
41044          );
41045    --
41046    l_acc_rev_natural_side_code := 'D';  -- 4262811
41047    -- 
41048    --
41049    -- set accounting line type info
41050    --
41051    xla_ae_lines_pkg.SetAcctLineType
41052       (p_component_type             => l_component_type
41053       ,p_event_type_code            => l_event_type_code
41054       ,p_line_definition_owner_code => l_line_definition_owner_code
41055       ,p_line_definition_code       => l_line_definition_code
41056       ,p_accounting_line_code       => l_component_code
41057       ,p_accounting_line_type_code  => l_component_type_code
41058       ,p_accounting_line_appl_id    => l_component_appl_id
41059       ,p_amb_context_code           => l_amb_context_code
41060       ,p_entity_code                => l_entity_code
41061       ,p_event_class_code           => l_event_class_code);
41062    --
41063    -- set accounting class
41064    --
41065    xla_ae_lines_pkg.SetAcctClass(
41066            p_accounting_class_code  => 'ASSET'
41067          , p_ae_header_id           => l_ae_header_id
41068          );
41069 
41070    --
41071    -- set rounding class
41072    --
41073    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
41074                       'ASSET';
41075 
41076    --
41077    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
41078    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
41079    --
41080    -- bulk performance
41081    --
41082    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
41083 
41084    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
41085       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
41086 
41087    -- 4955764
41088    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41089       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
41090 
41091    -- 4458381 Public Sector Enh
41092    
41093    --
41094    -- set accounting attributes for the line type
41095    --
41096    l_entered_amt_idx := 4;
41097    l_accted_amt_idx  := 6;
41098    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
41099    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
41100    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
41101    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
41102    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
41103    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
41104    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
41105    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
41106    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
41107    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
41108    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
41109    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
41110    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
41111 
41112    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
41113    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
41114 
41115    ---------------------------------------------------------------------------------------------------------------
41116    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
41117    ---------------------------------------------------------------------------------------------------------------
41118    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
41119 
41120    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41121    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41122 
41123    IF xla_accounting_cache_pkg.GetValueChar
41124          (p_source_code         => 'LEDGER_CATEGORY_CODE'
41125          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
41126    AND l_bflow_method_code = 'PRIOR_ENTRY'
41127 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
41128    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
41129          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
41130        )
41131    THEN
41132          xla_ae_lines_pkg.BflowUpgEntry
41133            (p_business_method_code    => l_bflow_method_code
41134            ,p_business_class_code     => l_bflow_class_code
41135            ,p_balance_type            => l_balance_type_code);
41136    ELSE
41137       NULL;
41138 -- No business flow processing for business flow method of NONE.
41139    END IF;
41140 
41141    --
41142    -- call analytical criteria
41143    --
41144    
41145    --
41146    -- call description
41147    --
41148    
41149 xla_ae_lines_pkg.SetLineDescription(
41150    p_ae_header_id => l_ae_header_id
41151   ,p_description  => Description_37 (
41152      p_application_id         => p_application_id
41153    , p_ae_header_id           => l_ae_header_id 
41154 , p_source_1 => p_source_1
41155    )
41156 );
41157 
41158 
41159    --
41163    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41160    -- call ADRs
41161    -- Bug 4922099
41162    --
41164         (NVL(l_actual_upg_option, 'N') = 'O') OR
41165         (NVL(l_enc_upg_option, 'N') = 'O')
41166       )
41167    THEN
41168    NULL;
41169    --
41170    --
41171    
41172   l_ccid := AcctDerRule_173(
41173            p_application_id           => p_application_id
41174          , p_ae_header_id             => l_ae_header_id 
41175 , p_source_3 => p_source_3
41176 , p_source_30 => p_source_30
41177          , x_transaction_coa_id       => l_adr_transaction_coa_id
41178          , x_accounting_coa_id        => l_adr_accounting_coa_id
41179          , x_value_type_code          => l_adr_value_type_code
41180          , p_side                     => 'NA'
41181    );
41182 
41183    xla_ae_lines_pkg.set_ccid(
41184     p_code_combination_id          => l_ccid
41185   , p_value_type_code              => l_adr_value_type_code
41186   , p_transaction_coa_id           => l_adr_transaction_coa_id
41187   , p_accounting_coa_id            => l_adr_accounting_coa_id
41188   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
41189   , p_adr_type_code                => 'S'
41190   , p_component_type               => l_component_type
41191   , p_component_code               => l_component_code
41192   , p_component_type_code          => l_component_type_code
41193   , p_component_appl_id            => l_component_appl_id
41194   , p_amb_context_code             => l_amb_context_code
41195   , p_side                         => 'NA'
41196   );
41197 
41198 
41199    l_segment := AcctDerRule_151(
41200            p_application_id           => p_application_id
41201          , p_ae_header_id             => l_ae_header_id 
41202 , p_source_3 => p_source_3
41203 , p_source_12 => p_source_12
41204          , x_transaction_coa_id       => l_adr_transaction_coa_id
41205          , x_accounting_coa_id        => l_adr_accounting_coa_id
41206          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41207          , x_flex_value_set_id        => l_adr_flex_value_set_id
41208          , x_value_type_code          => l_adr_value_type_code
41209          , x_value_combination_id     => l_adr_value_combination_id
41210          , x_value_segment_code       => l_adr_value_segment_code
41211          , p_side                     => 'NA'
41212          , p_override_seg_flag        => 'Y'
41213    );
41214 
41215    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41216 
41217       xla_ae_lines_pkg.set_segment(
41218           p_to_segment_code         => 'GL_ACCOUNT'
41219         , p_segment_value           => l_segment
41220         , p_from_segment_code       => l_adr_value_segment_code
41221         , p_from_combination_id     => l_adr_value_combination_id
41222         , p_value_type_code         => l_adr_value_type_code
41223         , p_transaction_coa_id      => l_adr_transaction_coa_id
41224         , p_accounting_coa_id       => l_adr_accounting_coa_id
41225         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
41226         , p_flex_value_set_id       => l_adr_flex_value_set_id
41227         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
41228         , p_adr_type_code           => 'S'
41229         , p_component_type          => l_component_type
41230         , p_component_code          => l_component_code
41231         , p_component_type_code     => l_component_type_code
41232         , p_component_appl_id       => l_component_appl_id
41233         , p_amb_context_code        => l_amb_context_code
41234         , p_entity_code             => 'TRANSACTIONS'
41235         , p_event_class_code        => 'CIP_RETIREMENTS'
41236         , p_side                    => 'NA'
41237         );
41238 
41239   END IF;
41240 
41241    l_segment := AcctDerRule_168(
41242            p_application_id           => p_application_id
41243          , p_ae_header_id             => l_ae_header_id 
41244 , p_source_3 => p_source_3
41245 , p_source_29 => p_source_29
41246          , x_transaction_coa_id       => l_adr_transaction_coa_id
41247          , x_accounting_coa_id        => l_adr_accounting_coa_id
41248          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41249          , x_flex_value_set_id        => l_adr_flex_value_set_id
41250          , x_value_type_code          => l_adr_value_type_code
41251          , x_value_combination_id     => l_adr_value_combination_id
41252          , x_value_segment_code       => l_adr_value_segment_code
41253          , p_side                     => 'NA'
41254          , p_override_seg_flag        => 'Y'
41255    );
41256 
41257    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41258 
41259       xla_ae_lines_pkg.set_segment(
41260           p_to_segment_code         => 'GL_BALANCING'
41261         , p_segment_value           => l_segment
41262         , p_from_segment_code       => l_adr_value_segment_code
41263         , p_from_combination_id     => l_adr_value_combination_id
41264         , p_value_type_code         => l_adr_value_type_code
41265         , p_transaction_coa_id      => l_adr_transaction_coa_id
41266         , p_accounting_coa_id       => l_adr_accounting_coa_id
41267         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
41268         , p_flex_value_set_id       => l_adr_flex_value_set_id
41269         , p_adr_code                => 'FA_EXPENSE_ACCT'
41270         , p_adr_type_code           => 'S'
41271         , p_component_type          => l_component_type
41272         , p_component_code          => l_component_code
41273         , p_component_type_code     => l_component_type_code
41274         , p_component_appl_id       => l_component_appl_id
41275         , p_amb_context_code        => l_amb_context_code
41276         , p_entity_code             => 'TRANSACTIONS'
41277         , p_event_class_code        => 'CIP_RETIREMENTS'
41278         , p_side                    => 'NA'
41279         );
41280 
41284    --
41281   END IF;
41282 
41283    --
41285    END IF;
41286    --
41287    -- Bug 4922099
41288    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
41289           (NVL(l_enc_upg_option, 'N') = 'O')
41290         ) AND
41291         (l_bflow_method_code = 'PRIOR_ENTRY')
41292       )
41293    THEN
41294       IF
41295       --
41296       1 = 2
41297       --
41298       THEN
41299       xla_accounting_err_pkg.build_message
41300                                     (p_appli_s_name            => 'XLA'
41301                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
41302                                     ,p_token_1                 => 'LINE_NUMBER'
41303                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
41304                                     ,p_token_2                 => 'LINE_TYPE_NAME'
41305                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
41306                                                                              l_component_type
41307                                                                             ,l_component_code
41308                                                                             ,l_component_type_code
41309                                                                             ,l_component_appl_id
41310                                                                             ,l_amb_context_code
41311                                                                             ,l_entity_code
41312                                                                             ,l_event_class_code
41313                                                                            )
41314                                     ,p_token_3                 => 'OWNER'
41315                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
41316                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
41317                                                                           ,p_lookup_code    => l_component_type_code
41318                                                                          )
41319                                     ,p_token_4                 => 'PRODUCT_NAME'
41320                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
41321                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
41322                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
41323                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
41324                                     ,p_ae_header_id            =>  NULL
41325                                        );
41326 
41327         IF (C_LEVEL_ERROR>= g_log_level) THEN
41328                  trace
41329                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
41330                       ,p_level    => C_LEVEL_ERROR
41331                       ,p_module   => l_log_module);
41332         END IF;
41333       END IF;
41334    END IF;
41335    --
41336    --
41337    ------------------------------------------------------------------------------------------------
41338    -- 4219869 Business Flow
41339    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
41340    -- Prior Entry.  Currently, the following code is always generated.
41341    ------------------------------------------------------------------------------------------------
41342    XLA_AE_LINES_PKG.ValidateCurrentLine;
41343 
41344    ------------------------------------------------------------------------------------
41345    -- 4219869 Business Flow
41346    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
41347    ------------------------------------------------------------------------------------
41348    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
41349 
41350    ----------------------------------------------------------------------------------
41351    -- 4219869 Business Flow
41352    -- Update journal entry status -- Need to generate this within IF <condition>
41353    ----------------------------------------------------------------------------------
41354    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
41355          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
41356          ,p_balance_type_code => l_balance_type_code
41357          );
41358 
41359    -------------------------------------------------------------------------------------------
41360    -- 4262811 - Generate the Accrual Reversal lines
41361    -------------------------------------------------------------------------------------------
41362    BEGIN
41363       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
41364                               (g_array_event(p_event_id).array_value_num('header_index'));
41365       IF l_acc_rev_flag IS NULL THEN
41366          l_acc_rev_flag := 'N';
41367       END IF;
41368    EXCEPTION
41369       WHEN OTHERS THEN
41370          l_acc_rev_flag := 'N';
41371    END;
41372    --
41373    IF (l_acc_rev_flag = 'Y') THEN
41374 
41375        -- 4645092  ------------------------------------------------------------------------------
41376        -- To allow MPA report to determine if it should generate report process
41377        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
41378        ------------------------------------------------------------------------------------------
41379 
41380        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
41381        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
41382    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
41383    -- call ADRs
41384    -- Bug 4922099
41385    --
41386    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41390    THEN
41387         (NVL(l_actual_upg_option, 'N') = 'O') OR
41388         (NVL(l_enc_upg_option, 'N') = 'O')
41389       )
41391    NULL;
41392    --
41393    --
41394    
41395   l_ccid := AcctDerRule_173(
41396            p_application_id           => p_application_id
41397          , p_ae_header_id             => l_ae_header_id 
41398 , p_source_3 => p_source_3
41399 , p_source_30 => p_source_30
41400          , x_transaction_coa_id       => l_adr_transaction_coa_id
41401          , x_accounting_coa_id        => l_adr_accounting_coa_id
41402          , x_value_type_code          => l_adr_value_type_code
41403          , p_side                     => 'NA'
41404    );
41405 
41406    xla_ae_lines_pkg.set_ccid(
41407     p_code_combination_id          => l_ccid
41408   , p_value_type_code              => l_adr_value_type_code
41409   , p_transaction_coa_id           => l_adr_transaction_coa_id
41410   , p_accounting_coa_id            => l_adr_accounting_coa_id
41411   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
41412   , p_adr_type_code                => 'S'
41413   , p_component_type               => l_component_type
41414   , p_component_code               => l_component_code
41415   , p_component_type_code          => l_component_type_code
41416   , p_component_appl_id            => l_component_appl_id
41417   , p_amb_context_code             => l_amb_context_code
41418   , p_side                         => 'NA'
41419   );
41420 
41421 
41422    l_segment := AcctDerRule_151(
41423            p_application_id           => p_application_id
41424          , p_ae_header_id             => l_ae_header_id 
41425 , p_source_3 => p_source_3
41426 , p_source_12 => p_source_12
41427          , x_transaction_coa_id       => l_adr_transaction_coa_id
41428          , x_accounting_coa_id        => l_adr_accounting_coa_id
41429          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41430          , x_flex_value_set_id        => l_adr_flex_value_set_id
41431          , x_value_type_code          => l_adr_value_type_code
41432          , x_value_combination_id     => l_adr_value_combination_id
41433          , x_value_segment_code       => l_adr_value_segment_code
41434          , p_side                     => 'NA'
41435          , p_override_seg_flag        => 'Y'
41436    );
41437 
41438    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41439 
41440       xla_ae_lines_pkg.set_segment(
41441           p_to_segment_code         => 'GL_ACCOUNT'
41442         , p_segment_value           => l_segment
41443         , p_from_segment_code       => l_adr_value_segment_code
41444         , p_from_combination_id     => l_adr_value_combination_id
41445         , p_value_type_code         => l_adr_value_type_code
41446         , p_transaction_coa_id      => l_adr_transaction_coa_id
41447         , p_accounting_coa_id       => l_adr_accounting_coa_id
41448         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
41449         , p_flex_value_set_id       => l_adr_flex_value_set_id
41450         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
41451         , p_adr_type_code           => 'S'
41452         , p_component_type          => l_component_type
41453         , p_component_code          => l_component_code
41454         , p_component_type_code     => l_component_type_code
41455         , p_component_appl_id       => l_component_appl_id
41456         , p_amb_context_code        => l_amb_context_code
41457         , p_entity_code             => 'TRANSACTIONS'
41458         , p_event_class_code        => 'CIP_RETIREMENTS'
41459         , p_side                    => 'NA'
41460         );
41461 
41462   END IF;
41463 
41464    l_segment := AcctDerRule_168(
41465            p_application_id           => p_application_id
41466          , p_ae_header_id             => l_ae_header_id 
41467 , p_source_3 => p_source_3
41468 , p_source_29 => p_source_29
41469          , x_transaction_coa_id       => l_adr_transaction_coa_id
41470          , x_accounting_coa_id        => l_adr_accounting_coa_id
41471          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41472          , x_flex_value_set_id        => l_adr_flex_value_set_id
41473          , x_value_type_code          => l_adr_value_type_code
41474          , x_value_combination_id     => l_adr_value_combination_id
41475          , x_value_segment_code       => l_adr_value_segment_code
41476          , p_side                     => 'NA'
41477          , p_override_seg_flag        => 'Y'
41478    );
41479 
41480    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41481 
41482       xla_ae_lines_pkg.set_segment(
41483           p_to_segment_code         => 'GL_BALANCING'
41484         , p_segment_value           => l_segment
41485         , p_from_segment_code       => l_adr_value_segment_code
41486         , p_from_combination_id     => l_adr_value_combination_id
41487         , p_value_type_code         => l_adr_value_type_code
41488         , p_transaction_coa_id      => l_adr_transaction_coa_id
41489         , p_accounting_coa_id       => l_adr_accounting_coa_id
41490         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
41491         , p_flex_value_set_id       => l_adr_flex_value_set_id
41492         , p_adr_code                => 'FA_EXPENSE_ACCT'
41493         , p_adr_type_code           => 'S'
41494         , p_component_type          => l_component_type
41495         , p_component_code          => l_component_code
41496         , p_component_type_code     => l_component_type_code
41497         , p_component_appl_id       => l_component_appl_id
41498         , p_amb_context_code        => l_amb_context_code
41499         , p_entity_code             => 'TRANSACTIONS'
41500         , p_event_class_code        => 'CIP_RETIREMENTS'
41501         , p_side                    => 'NA'
41502         );
41503 
41504   END IF;
41505 
41506    --
41507    --
41508    END IF;
41509 
41510        --
41514                                          p_header_num   => 1);
41511        -- Update the line information that should be overwritten
41512        --
41513        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
41515        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
41516 
41517        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
41518 
41519        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
41520           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
41521        END IF;
41522 
41523       --
41524       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
41525       --
41526       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
41527           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
41528       ELSE
41529           ---------------------------------------------------------------------------------------------------
41530           -- 4262811a Switch Sign
41531           ---------------------------------------------------------------------------------------------------
41532           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
41533           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
41534                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41535           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
41536                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41537           -- 5132302
41538           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
41539                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41540 
41541       END IF;
41542 
41543       -- 4955764
41544       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41545       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
41546 
41547 
41548       XLA_AE_LINES_PKG.ValidateCurrentLine;
41549       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
41550 
41551       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
41552                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
41553                ,p_balance_type_code => l_balance_type_code);
41554 
41555    END IF;
41556 
41557    -----------------------------------------------------------------------------------------
41558    -- 4262811 Multiperiod Accounting
41559    -----------------------------------------------------------------------------------------
41560      -- No MPA option is assigned.
41561 
41562 
41563 END IF;
41564 END IF;
41565 --
41566 
41567 --
41568 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
41569    trace
41570       (p_msg      => 'END of AcctLineType_212'
41571       ,p_level    => C_LEVEL_PROCEDURE
41572       ,p_module   => l_log_module);
41573 END IF;
41574 --
41575 EXCEPTION
41576   WHEN xla_exceptions_pkg.application_exception THEN
41577       RAISE;
41578   WHEN OTHERS THEN
41579        xla_exceptions_pkg.raise_message
41580            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_212');
41581 END AcctLineType_212;
41582 --
41583 
41584 ---------------------------------------
41585 --
41586 -- PRIVATE FUNCTION
41587 --         AcctLineType_213
41588 --
41589 ---------------------------------------
41590 PROCEDURE AcctLineType_213 (
41591   p_application_id        IN NUMBER
41592  ,p_event_id              IN NUMBER
41593  ,p_calculate_acctd_flag  IN VARCHAR2
41594  ,p_calculate_g_l_flag    IN VARCHAR2
41595  ,p_actual_flag           IN OUT VARCHAR2
41596  ,p_balance_type_code     OUT VARCHAR2
41597  ,p_gain_or_loss_ref      OUT VARCHAR2
41598  
41599 --Period Close Date
41600  , p_source_1            IN DATE
41601 --Generated Code Combination Identifier
41602  , p_source_3            IN NUMBER
41603 --Cost Of Removal Gain Account
41604  , p_source_13            IN VARCHAR2
41605 --Expense Account Code Combination Identifier
41606  , p_source_29            IN NUMBER
41607 --Default Code Combination Identifier
41608  , p_source_30            IN NUMBER
41609 --Adjustment Type
41610  , p_source_35            IN VARCHAR2
41611 --Transaction Header Identifier
41612  , p_source_36            IN NUMBER
41613 --Adjustment Line Identifier
41614  , p_source_37            IN NUMBER
41615 --Distribution Type Code
41616  , p_source_38            IN VARCHAR2
41617 --Entered Amount
41618  , p_source_39            IN NUMBER
41619 --Currency Code
41620  , p_source_40            IN VARCHAR2
41621 --Gain Loss Amount
41622  , p_source_41            IN NUMBER
41623 )
41624 IS
41625 
41626 l_component_type              VARCHAR2(80);
41627 l_component_code              VARCHAR2(30);
41628 l_component_type_code         VARCHAR2(1);
41629 l_component_appl_id           INTEGER;
41630 l_amb_context_code            VARCHAR2(30);
41631 l_entity_code                 VARCHAR2(30);
41632 l_event_class_code            VARCHAR2(30);
41633 l_ae_header_id                NUMBER;
41634 l_event_type_code             VARCHAR2(30);
41635 l_line_definition_code        VARCHAR2(30);
41636 l_line_definition_owner_code  VARCHAR2(1);
41637 --
41638 -- adr variables
41639 l_segment                     VARCHAR2(30);
41640 l_ccid                        NUMBER;
41641 l_adr_transaction_coa_id      NUMBER;
41642 l_adr_accounting_coa_id       NUMBER;
41643 l_adr_flexfield_segment_code  VARCHAR2(30);
41647 l_adr_value_segment_code      VARCHAR2(30);
41644 l_adr_flex_value_set_id       NUMBER;
41645 l_adr_value_type_code         VARCHAR2(30);
41646 l_adr_value_combination_id    NUMBER;
41648 
41649 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
41650 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
41651 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
41652 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
41653 
41654 -- 4262811 Variables ------------------------------------------------------------------------------------------
41655 l_entered_amt_idx             NUMBER;
41656 l_accted_amt_idx              NUMBER;
41657 l_acc_rev_flag                VARCHAR2(1);
41658 l_accrual_line_num            NUMBER;
41659 l_tmp_amt                     NUMBER;
41660 l_acc_rev_natural_side_code   VARCHAR2(1);
41661 
41662 l_num_entries                 NUMBER;
41663 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
41664 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
41665 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
41666 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
41667 l_recog_line_1                NUMBER;
41668 l_recog_line_2                NUMBER;
41669 
41670 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
41671 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
41672 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
41673 
41674 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
41675 
41676 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
41677 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
41678 
41679 ---------------------------------------------------------------------------------------------------------------
41680 
41681 
41682 --
41683 -- bulk performance
41684 --
41685 l_balance_type_code           VARCHAR2(1);
41686 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
41687 l_log_module                  VARCHAR2(240);
41688 
41689 --
41690 -- Upgrade strategy
41691 --
41692 l_actual_upg_option           VARCHAR2(1);
41693 l_enc_upg_option           VARCHAR2(1);
41694 
41695 --
41696 BEGIN
41697 --
41698 IF g_log_enabled THEN
41699       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_213';
41700 END IF;
41701 --
41702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
41703 
41704       trace
41705          (p_msg      => 'BEGIN of AcctLineType_213'
41706          ,p_level    => C_LEVEL_PROCEDURE
41707          ,p_module   => l_log_module);
41708 
41709 END IF;
41710 --
41711 l_component_type             := 'AMB_JLT';
41712 l_component_code             := 'FA_CIP_COST_OF_REMOVAL_GAIN';
41713 l_component_type_code        := 'S';
41714 l_component_appl_id          :=  140;
41715 l_amb_context_code           := 'DEFAULT';
41716 l_entity_code                := 'TRANSACTIONS';
41717 l_event_class_code           := 'CIP_RETIREMENTS';
41718 l_event_type_code            := 'CIP_RETIREMENTS';
41719 l_line_definition_owner_code := 'S';
41720 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
41721 --
41722 l_balance_type_code          := 'A';
41723 l_segment                     := NULL;
41724 l_ccid                        := NULL;
41725 l_adr_transaction_coa_id      := NULL;
41726 l_adr_accounting_coa_id       := NULL;
41727 l_adr_flexfield_segment_code  := NULL;
41728 l_adr_flex_value_set_id       := NULL;
41729 l_adr_value_type_code         := NULL;
41730 l_adr_value_combination_id    := NULL;
41731 l_adr_value_segment_code      := NULL;
41732 
41733 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
41734 l_bflow_class_code           := '';    -- 4219869 Business Flow
41735 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
41736 l_budgetary_control_flag     := 'N';
41737 
41738 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
41739 l_bflow_applied_to_amt       := NULL; -- 5132302
41740 l_entered_amt_idx            := NULL;          -- 4262811
41741 l_accted_amt_idx             := NULL;          -- 4262811
41742 l_acc_rev_flag               := NULL;          -- 4262811
41743 l_accrual_line_num           := NULL;          -- 4262811
41744 l_tmp_amt                    := NULL;          -- 4262811
41745 --
41746  
41747 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
41748     l_balance_type_code <> 'B' THEN
41749 IF NVL(p_source_35,'
41750 ') =  'REMOVALCOST' AND 
41751 p_source_41 >=  0
41752  THEN 
41753 
41754    --
41755    XLA_AE_LINES_PKG.SetNewLine;
41756 
41757    p_balance_type_code          := l_balance_type_code;
41758    -- set the flag so later we will know whether the gain loss line needs to be created
41759    
41760    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
41761      p_actual_flag :='A';
41762    END IF;
41763 
41764    --
41765    -- bulk performance
41766    --
41767    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
41768                                       p_header_num   => 0); -- 4262811
41769    --
41770    -- set accounting line options
41771    --
41772    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
41773            p_natural_side_code          => 'D'
41774          , p_gain_or_loss_flag          => 'N'
41775          , p_gl_transfer_mode_code      => 'S'
41776          , p_acct_entry_type_code       => 'A'
41777          , p_switch_side_flag           => 'Y'
41778          , p_merge_duplicate_code       => 'N'
41779          );
41780    --
41781    l_acc_rev_natural_side_code := 'C';  -- 4262811
41782    -- 
41786    xla_ae_lines_pkg.SetAcctLineType
41783    --
41784    -- set accounting line type info
41785    --
41787       (p_component_type             => l_component_type
41788       ,p_event_type_code            => l_event_type_code
41789       ,p_line_definition_owner_code => l_line_definition_owner_code
41790       ,p_line_definition_code       => l_line_definition_code
41791       ,p_accounting_line_code       => l_component_code
41792       ,p_accounting_line_type_code  => l_component_type_code
41793       ,p_accounting_line_appl_id    => l_component_appl_id
41794       ,p_amb_context_code           => l_amb_context_code
41795       ,p_entity_code                => l_entity_code
41796       ,p_event_class_code           => l_event_class_code);
41797    --
41798    -- set accounting class
41799    --
41800    xla_ae_lines_pkg.SetAcctClass(
41801            p_accounting_class_code  => 'ASSET'
41802          , p_ae_header_id           => l_ae_header_id
41803          );
41804 
41805    --
41806    -- set rounding class
41807    --
41808    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
41809                       'ASSET';
41810 
41811    --
41812    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
41813    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
41814    --
41815    -- bulk performance
41816    --
41817    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
41818 
41819    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
41820       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
41821 
41822    -- 4955764
41823    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41824       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
41825 
41826    -- 4458381 Public Sector Enh
41827    
41828    --
41829    -- set accounting attributes for the line type
41830    --
41831    l_entered_amt_idx := 4;
41832    l_accted_amt_idx  := 6;
41833    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
41834    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
41835    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
41836    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
41837    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
41838    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
41839    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
41840    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
41841    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
41842    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
41843    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
41844    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
41845    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
41846 
41847    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
41848    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
41849 
41850    ---------------------------------------------------------------------------------------------------------------
41851    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
41852    ---------------------------------------------------------------------------------------------------------------
41853    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
41854 
41855    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41856    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41857 
41858    IF xla_accounting_cache_pkg.GetValueChar
41859          (p_source_code         => 'LEDGER_CATEGORY_CODE'
41860          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
41861    AND l_bflow_method_code = 'PRIOR_ENTRY'
41862 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
41863    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
41864          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
41865        )
41866    THEN
41867          xla_ae_lines_pkg.BflowUpgEntry
41868            (p_business_method_code    => l_bflow_method_code
41869            ,p_business_class_code     => l_bflow_class_code
41870            ,p_balance_type            => l_balance_type_code);
41871    ELSE
41872       NULL;
41873 -- No business flow processing for business flow method of NONE.
41874    END IF;
41875 
41876    --
41877    -- call analytical criteria
41878    --
41879    
41880    --
41881    -- call description
41882    --
41883    
41884 xla_ae_lines_pkg.SetLineDescription(
41885    p_ae_header_id => l_ae_header_id
41886   ,p_description  => Description_36 (
41887      p_application_id         => p_application_id
41888    , p_ae_header_id           => l_ae_header_id 
41889 , p_source_1 => p_source_1
41890    )
41891 );
41892 
41893 
41894    --
41895    -- call ADRs
41896    -- Bug 4922099
41897    --
41898    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41899         (NVL(l_actual_upg_option, 'N') = 'O') OR
41900         (NVL(l_enc_upg_option, 'N') = 'O')
41901       )
41902    THEN
41903    NULL;
41904    --
41905    --
41906    
41907   l_ccid := AcctDerRule_173(
41908            p_application_id           => p_application_id
41909          , p_ae_header_id             => l_ae_header_id 
41910 , p_source_3 => p_source_3
41911 , p_source_30 => p_source_30
41912          , x_transaction_coa_id       => l_adr_transaction_coa_id
41916    );
41913          , x_accounting_coa_id        => l_adr_accounting_coa_id
41914          , x_value_type_code          => l_adr_value_type_code
41915          , p_side                     => 'NA'
41917 
41918    xla_ae_lines_pkg.set_ccid(
41919     p_code_combination_id          => l_ccid
41920   , p_value_type_code              => l_adr_value_type_code
41921   , p_transaction_coa_id           => l_adr_transaction_coa_id
41922   , p_accounting_coa_id            => l_adr_accounting_coa_id
41923   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
41924   , p_adr_type_code                => 'S'
41925   , p_component_type               => l_component_type
41926   , p_component_code               => l_component_code
41927   , p_component_type_code          => l_component_type_code
41928   , p_component_appl_id            => l_component_appl_id
41929   , p_amb_context_code             => l_amb_context_code
41930   , p_side                         => 'NA'
41931   );
41932 
41933 
41934    l_segment := AcctDerRule_152(
41935            p_application_id           => p_application_id
41936          , p_ae_header_id             => l_ae_header_id 
41937 , p_source_3 => p_source_3
41938 , p_source_13 => p_source_13
41939          , x_transaction_coa_id       => l_adr_transaction_coa_id
41940          , x_accounting_coa_id        => l_adr_accounting_coa_id
41941          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41942          , x_flex_value_set_id        => l_adr_flex_value_set_id
41943          , x_value_type_code          => l_adr_value_type_code
41944          , x_value_combination_id     => l_adr_value_combination_id
41945          , x_value_segment_code       => l_adr_value_segment_code
41946          , p_side                     => 'NA'
41947          , p_override_seg_flag        => 'Y'
41948    );
41949 
41950    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41951 
41952       xla_ae_lines_pkg.set_segment(
41953           p_to_segment_code         => 'GL_ACCOUNT'
41954         , p_segment_value           => l_segment
41955         , p_from_segment_code       => l_adr_value_segment_code
41956         , p_from_combination_id     => l_adr_value_combination_id
41957         , p_value_type_code         => l_adr_value_type_code
41958         , p_transaction_coa_id      => l_adr_transaction_coa_id
41959         , p_accounting_coa_id       => l_adr_accounting_coa_id
41960         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
41961         , p_flex_value_set_id       => l_adr_flex_value_set_id
41962         , p_adr_code                => 'FA_COST_OF_REM_GAIN_SEGMENT'
41963         , p_adr_type_code           => 'S'
41964         , p_component_type          => l_component_type
41965         , p_component_code          => l_component_code
41966         , p_component_type_code     => l_component_type_code
41967         , p_component_appl_id       => l_component_appl_id
41968         , p_amb_context_code        => l_amb_context_code
41969         , p_entity_code             => 'TRANSACTIONS'
41970         , p_event_class_code        => 'CIP_RETIREMENTS'
41971         , p_side                    => 'NA'
41972         );
41973 
41974   END IF;
41975 
41976    l_segment := AcctDerRule_168(
41977            p_application_id           => p_application_id
41978          , p_ae_header_id             => l_ae_header_id 
41979 , p_source_3 => p_source_3
41980 , p_source_29 => p_source_29
41981          , x_transaction_coa_id       => l_adr_transaction_coa_id
41982          , x_accounting_coa_id        => l_adr_accounting_coa_id
41983          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41984          , x_flex_value_set_id        => l_adr_flex_value_set_id
41985          , x_value_type_code          => l_adr_value_type_code
41986          , x_value_combination_id     => l_adr_value_combination_id
41987          , x_value_segment_code       => l_adr_value_segment_code
41988          , p_side                     => 'NA'
41989          , p_override_seg_flag        => 'Y'
41990    );
41991 
41992    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41993 
41994       xla_ae_lines_pkg.set_segment(
41995           p_to_segment_code         => 'GL_BALANCING'
41996         , p_segment_value           => l_segment
41997         , p_from_segment_code       => l_adr_value_segment_code
41998         , p_from_combination_id     => l_adr_value_combination_id
41999         , p_value_type_code         => l_adr_value_type_code
42000         , p_transaction_coa_id      => l_adr_transaction_coa_id
42001         , p_accounting_coa_id       => l_adr_accounting_coa_id
42002         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42003         , p_flex_value_set_id       => l_adr_flex_value_set_id
42004         , p_adr_code                => 'FA_EXPENSE_ACCT'
42005         , p_adr_type_code           => 'S'
42006         , p_component_type          => l_component_type
42007         , p_component_code          => l_component_code
42008         , p_component_type_code     => l_component_type_code
42009         , p_component_appl_id       => l_component_appl_id
42010         , p_amb_context_code        => l_amb_context_code
42011         , p_entity_code             => 'TRANSACTIONS'
42012         , p_event_class_code        => 'CIP_RETIREMENTS'
42013         , p_side                    => 'NA'
42014         );
42015 
42016   END IF;
42017 
42018    --
42019    --
42020    END IF;
42021    --
42022    -- Bug 4922099
42023    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
42024           (NVL(l_enc_upg_option, 'N') = 'O')
42025         ) AND
42026         (l_bflow_method_code = 'PRIOR_ENTRY')
42027       )
42028    THEN
42029       IF
42030       --
42031       1 = 2
42032       --
42033       THEN
42034       xla_accounting_err_pkg.build_message
42035                                     (p_appli_s_name            => 'XLA'
42039                                     ,p_token_2                 => 'LINE_TYPE_NAME'
42036                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42037                                     ,p_token_1                 => 'LINE_NUMBER'
42038                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
42040                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
42041                                                                              l_component_type
42042                                                                             ,l_component_code
42043                                                                             ,l_component_type_code
42044                                                                             ,l_component_appl_id
42045                                                                             ,l_amb_context_code
42046                                                                             ,l_entity_code
42047                                                                             ,l_event_class_code
42048                                                                            )
42049                                     ,p_token_3                 => 'OWNER'
42050                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
42051                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
42052                                                                           ,p_lookup_code    => l_component_type_code
42053                                                                          )
42054                                     ,p_token_4                 => 'PRODUCT_NAME'
42055                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
42056                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
42057                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
42058                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
42059                                     ,p_ae_header_id            =>  NULL
42060                                        );
42061 
42062         IF (C_LEVEL_ERROR>= g_log_level) THEN
42063                  trace
42064                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42065                       ,p_level    => C_LEVEL_ERROR
42066                       ,p_module   => l_log_module);
42067         END IF;
42068       END IF;
42069    END IF;
42070    --
42071    --
42072    ------------------------------------------------------------------------------------------------
42073    -- 4219869 Business Flow
42074    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
42075    -- Prior Entry.  Currently, the following code is always generated.
42076    ------------------------------------------------------------------------------------------------
42077    XLA_AE_LINES_PKG.ValidateCurrentLine;
42078 
42079    ------------------------------------------------------------------------------------
42080    -- 4219869 Business Flow
42081    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
42082    ------------------------------------------------------------------------------------
42083    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42084 
42085    ----------------------------------------------------------------------------------
42086    -- 4219869 Business Flow
42087    -- Update journal entry status -- Need to generate this within IF <condition>
42088    ----------------------------------------------------------------------------------
42089    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42090          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
42091          ,p_balance_type_code => l_balance_type_code
42092          );
42093 
42094    -------------------------------------------------------------------------------------------
42095    -- 4262811 - Generate the Accrual Reversal lines
42096    -------------------------------------------------------------------------------------------
42097    BEGIN
42098       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
42099                               (g_array_event(p_event_id).array_value_num('header_index'));
42100       IF l_acc_rev_flag IS NULL THEN
42101          l_acc_rev_flag := 'N';
42102       END IF;
42103    EXCEPTION
42104       WHEN OTHERS THEN
42105          l_acc_rev_flag := 'N';
42106    END;
42107    --
42108    IF (l_acc_rev_flag = 'Y') THEN
42109 
42110        -- 4645092  ------------------------------------------------------------------------------
42111        -- To allow MPA report to determine if it should generate report process
42112        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
42113        ------------------------------------------------------------------------------------------
42114 
42115        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
42116        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
42117    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
42118    -- call ADRs
42119    -- Bug 4922099
42120    --
42121    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
42122         (NVL(l_actual_upg_option, 'N') = 'O') OR
42123         (NVL(l_enc_upg_option, 'N') = 'O')
42124       )
42125    THEN
42126    NULL;
42127    --
42128    --
42129    
42130   l_ccid := AcctDerRule_173(
42131            p_application_id           => p_application_id
42132          , p_ae_header_id             => l_ae_header_id 
42133 , p_source_3 => p_source_3
42134 , p_source_30 => p_source_30
42135          , x_transaction_coa_id       => l_adr_transaction_coa_id
42136          , x_accounting_coa_id        => l_adr_accounting_coa_id
42140 
42137          , x_value_type_code          => l_adr_value_type_code
42138          , p_side                     => 'NA'
42139    );
42141    xla_ae_lines_pkg.set_ccid(
42142     p_code_combination_id          => l_ccid
42143   , p_value_type_code              => l_adr_value_type_code
42144   , p_transaction_coa_id           => l_adr_transaction_coa_id
42145   , p_accounting_coa_id            => l_adr_accounting_coa_id
42146   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
42147   , p_adr_type_code                => 'S'
42148   , p_component_type               => l_component_type
42149   , p_component_code               => l_component_code
42150   , p_component_type_code          => l_component_type_code
42151   , p_component_appl_id            => l_component_appl_id
42152   , p_amb_context_code             => l_amb_context_code
42153   , p_side                         => 'NA'
42154   );
42155 
42156 
42157    l_segment := AcctDerRule_152(
42158            p_application_id           => p_application_id
42159          , p_ae_header_id             => l_ae_header_id 
42160 , p_source_3 => p_source_3
42161 , p_source_13 => p_source_13
42162          , x_transaction_coa_id       => l_adr_transaction_coa_id
42163          , x_accounting_coa_id        => l_adr_accounting_coa_id
42164          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
42165          , x_flex_value_set_id        => l_adr_flex_value_set_id
42166          , x_value_type_code          => l_adr_value_type_code
42167          , x_value_combination_id     => l_adr_value_combination_id
42168          , x_value_segment_code       => l_adr_value_segment_code
42169          , p_side                     => 'NA'
42170          , p_override_seg_flag        => 'Y'
42171    );
42172 
42173    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
42174 
42175       xla_ae_lines_pkg.set_segment(
42176           p_to_segment_code         => 'GL_ACCOUNT'
42177         , p_segment_value           => l_segment
42178         , p_from_segment_code       => l_adr_value_segment_code
42179         , p_from_combination_id     => l_adr_value_combination_id
42180         , p_value_type_code         => l_adr_value_type_code
42181         , p_transaction_coa_id      => l_adr_transaction_coa_id
42182         , p_accounting_coa_id       => l_adr_accounting_coa_id
42183         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42184         , p_flex_value_set_id       => l_adr_flex_value_set_id
42185         , p_adr_code                => 'FA_COST_OF_REM_GAIN_SEGMENT'
42186         , p_adr_type_code           => 'S'
42187         , p_component_type          => l_component_type
42188         , p_component_code          => l_component_code
42189         , p_component_type_code     => l_component_type_code
42190         , p_component_appl_id       => l_component_appl_id
42191         , p_amb_context_code        => l_amb_context_code
42192         , p_entity_code             => 'TRANSACTIONS'
42193         , p_event_class_code        => 'CIP_RETIREMENTS'
42194         , p_side                    => 'NA'
42195         );
42196 
42197   END IF;
42198 
42199    l_segment := AcctDerRule_168(
42200            p_application_id           => p_application_id
42201          , p_ae_header_id             => l_ae_header_id 
42202 , p_source_3 => p_source_3
42203 , p_source_29 => p_source_29
42204          , x_transaction_coa_id       => l_adr_transaction_coa_id
42205          , x_accounting_coa_id        => l_adr_accounting_coa_id
42206          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
42207          , x_flex_value_set_id        => l_adr_flex_value_set_id
42208          , x_value_type_code          => l_adr_value_type_code
42209          , x_value_combination_id     => l_adr_value_combination_id
42210          , x_value_segment_code       => l_adr_value_segment_code
42211          , p_side                     => 'NA'
42212          , p_override_seg_flag        => 'Y'
42213    );
42214 
42215    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
42216 
42217       xla_ae_lines_pkg.set_segment(
42218           p_to_segment_code         => 'GL_BALANCING'
42219         , p_segment_value           => l_segment
42220         , p_from_segment_code       => l_adr_value_segment_code
42221         , p_from_combination_id     => l_adr_value_combination_id
42222         , p_value_type_code         => l_adr_value_type_code
42223         , p_transaction_coa_id      => l_adr_transaction_coa_id
42224         , p_accounting_coa_id       => l_adr_accounting_coa_id
42225         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42226         , p_flex_value_set_id       => l_adr_flex_value_set_id
42227         , p_adr_code                => 'FA_EXPENSE_ACCT'
42228         , p_adr_type_code           => 'S'
42229         , p_component_type          => l_component_type
42230         , p_component_code          => l_component_code
42231         , p_component_type_code     => l_component_type_code
42232         , p_component_appl_id       => l_component_appl_id
42233         , p_amb_context_code        => l_amb_context_code
42234         , p_entity_code             => 'TRANSACTIONS'
42235         , p_event_class_code        => 'CIP_RETIREMENTS'
42236         , p_side                    => 'NA'
42237         );
42238 
42239   END IF;
42240 
42241    --
42242    --
42243    END IF;
42244 
42245        --
42246        -- Update the line information that should be overwritten
42247        --
42248        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
42249                                          p_header_num   => 1);
42250        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
42251 
42252        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
42253 
42254        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
42258       --
42255           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
42256        END IF;
42257 
42259       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
42260       --
42261       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
42262           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
42263       ELSE
42264           ---------------------------------------------------------------------------------------------------
42265           -- 4262811a Switch Sign
42266           ---------------------------------------------------------------------------------------------------
42267           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
42268           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42269                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42270           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42271                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42272           -- 5132302
42273           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
42274                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42275 
42276       END IF;
42277 
42278       -- 4955764
42279       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
42280       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
42281 
42282 
42283       XLA_AE_LINES_PKG.ValidateCurrentLine;
42284       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42285 
42286       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42287                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
42288                ,p_balance_type_code => l_balance_type_code);
42289 
42290    END IF;
42291 
42292    -----------------------------------------------------------------------------------------
42293    -- 4262811 Multiperiod Accounting
42294    -----------------------------------------------------------------------------------------
42295      -- No MPA option is assigned.
42296 
42297 
42298 END IF;
42299 END IF;
42300 --
42301 
42302 --
42303 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
42304    trace
42305       (p_msg      => 'END of AcctLineType_213'
42306       ,p_level    => C_LEVEL_PROCEDURE
42307       ,p_module   => l_log_module);
42308 END IF;
42309 --
42310 EXCEPTION
42311   WHEN xla_exceptions_pkg.application_exception THEN
42312       RAISE;
42313   WHEN OTHERS THEN
42314        xla_exceptions_pkg.raise_message
42315            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_213');
42316 END AcctLineType_213;
42317 --
42318 
42319 ---------------------------------------
42320 --
42321 -- PRIVATE FUNCTION
42322 --         AcctLineType_214
42323 --
42324 ---------------------------------------
42325 PROCEDURE AcctLineType_214 (
42326   p_application_id        IN NUMBER
42327  ,p_event_id              IN NUMBER
42328  ,p_calculate_acctd_flag  IN VARCHAR2
42329  ,p_calculate_g_l_flag    IN VARCHAR2
42330  ,p_actual_flag           IN OUT VARCHAR2
42331  ,p_balance_type_code     OUT VARCHAR2
42332  ,p_gain_or_loss_ref      OUT VARCHAR2
42333  
42334 --Period Close Date
42335  , p_source_1            IN DATE
42336 --Generated Code Combination Identifier
42337  , p_source_3            IN NUMBER
42338 --Cost Of Removal Gain Account
42339  , p_source_13            IN VARCHAR2
42340 --Expense Account Code Combination Identifier
42341  , p_source_29            IN NUMBER
42342 --Default Code Combination Identifier
42343  , p_source_30            IN NUMBER
42344 --Adjustment Type
42345  , p_source_35            IN VARCHAR2
42346 --Transaction Header Identifier
42347  , p_source_36            IN NUMBER
42348 --Adjustment Line Identifier
42349  , p_source_37            IN NUMBER
42350 --Distribution Type Code
42351  , p_source_38            IN VARCHAR2
42352 --Entered Amount
42353  , p_source_39            IN NUMBER
42354 --Currency Code
42355  , p_source_40            IN VARCHAR2
42356 --Gain Loss Amount
42357  , p_source_41            IN NUMBER
42358 )
42359 IS
42360 
42361 l_component_type              VARCHAR2(80);
42362 l_component_code              VARCHAR2(30);
42363 l_component_type_code         VARCHAR2(1);
42364 l_component_appl_id           INTEGER;
42365 l_amb_context_code            VARCHAR2(30);
42366 l_entity_code                 VARCHAR2(30);
42367 l_event_class_code            VARCHAR2(30);
42368 l_ae_header_id                NUMBER;
42369 l_event_type_code             VARCHAR2(30);
42370 l_line_definition_code        VARCHAR2(30);
42371 l_line_definition_owner_code  VARCHAR2(1);
42372 --
42373 -- adr variables
42374 l_segment                     VARCHAR2(30);
42375 l_ccid                        NUMBER;
42376 l_adr_transaction_coa_id      NUMBER;
42377 l_adr_accounting_coa_id       NUMBER;
42378 l_adr_flexfield_segment_code  VARCHAR2(30);
42379 l_adr_flex_value_set_id       NUMBER;
42380 l_adr_value_type_code         VARCHAR2(30);
42381 l_adr_value_combination_id    NUMBER;
42382 l_adr_value_segment_code      VARCHAR2(30);
42383 
42384 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
42385 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
42386 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
42387 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
42388 
42392 l_acc_rev_flag                VARCHAR2(1);
42389 -- 4262811 Variables ------------------------------------------------------------------------------------------
42390 l_entered_amt_idx             NUMBER;
42391 l_accted_amt_idx              NUMBER;
42393 l_accrual_line_num            NUMBER;
42394 l_tmp_amt                     NUMBER;
42395 l_acc_rev_natural_side_code   VARCHAR2(1);
42396 
42397 l_num_entries                 NUMBER;
42398 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
42399 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
42400 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
42401 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
42402 l_recog_line_1                NUMBER;
42403 l_recog_line_2                NUMBER;
42404 
42405 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
42406 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
42407 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
42408 
42409 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
42410 
42411 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
42412 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
42413 
42414 ---------------------------------------------------------------------------------------------------------------
42415 
42416 
42417 --
42418 -- bulk performance
42419 --
42420 l_balance_type_code           VARCHAR2(1);
42421 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
42422 l_log_module                  VARCHAR2(240);
42423 
42424 --
42425 -- Upgrade strategy
42426 --
42427 l_actual_upg_option           VARCHAR2(1);
42428 l_enc_upg_option           VARCHAR2(1);
42429 
42430 --
42431 BEGIN
42432 --
42433 IF g_log_enabled THEN
42434       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_214';
42435 END IF;
42436 --
42437 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
42438 
42439       trace
42440          (p_msg      => 'BEGIN of AcctLineType_214'
42441          ,p_level    => C_LEVEL_PROCEDURE
42442          ,p_module   => l_log_module);
42443 
42444 END IF;
42445 --
42446 l_component_type             := 'AMB_JLT';
42447 l_component_code             := 'FA_CIP_COST_OF_REMOVAL_GAIN';
42448 l_component_type_code        := 'S';
42449 l_component_appl_id          :=  140;
42450 l_amb_context_code           := 'DEFAULT';
42451 l_entity_code                := 'TRANSACTIONS';
42452 l_event_class_code           := 'CIP_RETIREMENTS';
42453 l_event_type_code            := 'CIP_REINSTATEMENTS';
42454 l_line_definition_owner_code := 'S';
42455 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
42456 --
42457 l_balance_type_code          := 'A';
42458 l_segment                     := NULL;
42459 l_ccid                        := NULL;
42460 l_adr_transaction_coa_id      := NULL;
42461 l_adr_accounting_coa_id       := NULL;
42462 l_adr_flexfield_segment_code  := NULL;
42463 l_adr_flex_value_set_id       := NULL;
42464 l_adr_value_type_code         := NULL;
42465 l_adr_value_combination_id    := NULL;
42466 l_adr_value_segment_code      := NULL;
42467 
42468 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
42469 l_bflow_class_code           := '';    -- 4219869 Business Flow
42470 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
42471 l_budgetary_control_flag     := 'N';
42472 
42473 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
42474 l_bflow_applied_to_amt       := NULL; -- 5132302
42475 l_entered_amt_idx            := NULL;          -- 4262811
42476 l_accted_amt_idx             := NULL;          -- 4262811
42477 l_acc_rev_flag               := NULL;          -- 4262811
42478 l_accrual_line_num           := NULL;          -- 4262811
42479 l_tmp_amt                    := NULL;          -- 4262811
42480 --
42481  
42482 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
42483     l_balance_type_code <> 'B' THEN
42484 IF NVL(p_source_35,'
42485 ') =  'REMOVALCOST' AND 
42486 p_source_41 >=  0
42487  THEN 
42488 
42489    --
42490    XLA_AE_LINES_PKG.SetNewLine;
42491 
42492    p_balance_type_code          := l_balance_type_code;
42493    -- set the flag so later we will know whether the gain loss line needs to be created
42494    
42495    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
42496      p_actual_flag :='A';
42497    END IF;
42498 
42499    --
42500    -- bulk performance
42501    --
42502    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
42503                                       p_header_num   => 0); -- 4262811
42504    --
42505    -- set accounting line options
42506    --
42507    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
42508            p_natural_side_code          => 'D'
42509          , p_gain_or_loss_flag          => 'N'
42510          , p_gl_transfer_mode_code      => 'S'
42511          , p_acct_entry_type_code       => 'A'
42512          , p_switch_side_flag           => 'Y'
42513          , p_merge_duplicate_code       => 'N'
42514          );
42515    --
42516    l_acc_rev_natural_side_code := 'C';  -- 4262811
42517    -- 
42518    --
42519    -- set accounting line type info
42520    --
42521    xla_ae_lines_pkg.SetAcctLineType
42522       (p_component_type             => l_component_type
42523       ,p_event_type_code            => l_event_type_code
42524       ,p_line_definition_owner_code => l_line_definition_owner_code
42525       ,p_line_definition_code       => l_line_definition_code
42526       ,p_accounting_line_code       => l_component_code
42527       ,p_accounting_line_type_code  => l_component_type_code
42531       ,p_event_class_code           => l_event_class_code);
42528       ,p_accounting_line_appl_id    => l_component_appl_id
42529       ,p_amb_context_code           => l_amb_context_code
42530       ,p_entity_code                => l_entity_code
42532    --
42533    -- set accounting class
42534    --
42535    xla_ae_lines_pkg.SetAcctClass(
42536            p_accounting_class_code  => 'ASSET'
42537          , p_ae_header_id           => l_ae_header_id
42538          );
42539 
42540    --
42541    -- set rounding class
42542    --
42543    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
42544                       'ASSET';
42545 
42546    --
42547    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
42548    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
42549    --
42550    -- bulk performance
42551    --
42552    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
42553 
42554    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
42555       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
42556 
42557    -- 4955764
42558    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
42559       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
42560 
42561    -- 4458381 Public Sector Enh
42562    
42563    --
42564    -- set accounting attributes for the line type
42565    --
42566    l_entered_amt_idx := 4;
42567    l_accted_amt_idx  := 6;
42568    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
42569    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
42570    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
42571    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
42572    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
42573    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
42574    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
42575    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
42576    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
42577    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
42578    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
42579    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
42580    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
42581 
42582    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
42583    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
42584 
42585    ---------------------------------------------------------------------------------------------------------------
42586    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
42587    ---------------------------------------------------------------------------------------------------------------
42588    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
42589 
42590    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
42591    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
42592 
42593    IF xla_accounting_cache_pkg.GetValueChar
42594          (p_source_code         => 'LEDGER_CATEGORY_CODE'
42595          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
42596    AND l_bflow_method_code = 'PRIOR_ENTRY'
42597 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
42598    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
42599          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
42600        )
42601    THEN
42602          xla_ae_lines_pkg.BflowUpgEntry
42603            (p_business_method_code    => l_bflow_method_code
42604            ,p_business_class_code     => l_bflow_class_code
42605            ,p_balance_type            => l_balance_type_code);
42606    ELSE
42607       NULL;
42608 -- No business flow processing for business flow method of NONE.
42609    END IF;
42610 
42611    --
42612    -- call analytical criteria
42613    --
42614    
42615    --
42616    -- call description
42617    --
42618    
42619 xla_ae_lines_pkg.SetLineDescription(
42620    p_ae_header_id => l_ae_header_id
42621   ,p_description  => Description_36 (
42622      p_application_id         => p_application_id
42623    , p_ae_header_id           => l_ae_header_id 
42624 , p_source_1 => p_source_1
42625    )
42626 );
42627 
42628 
42629    --
42630    -- call ADRs
42631    -- Bug 4922099
42632    --
42633    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
42634         (NVL(l_actual_upg_option, 'N') = 'O') OR
42635         (NVL(l_enc_upg_option, 'N') = 'O')
42636       )
42637    THEN
42638    NULL;
42639    --
42640    --
42641    
42642   l_ccid := AcctDerRule_173(
42643            p_application_id           => p_application_id
42644          , p_ae_header_id             => l_ae_header_id 
42645 , p_source_3 => p_source_3
42646 , p_source_30 => p_source_30
42647          , x_transaction_coa_id       => l_adr_transaction_coa_id
42648          , x_accounting_coa_id        => l_adr_accounting_coa_id
42649          , x_value_type_code          => l_adr_value_type_code
42650          , p_side                     => 'NA'
42651    );
42652 
42653    xla_ae_lines_pkg.set_ccid(
42654     p_code_combination_id          => l_ccid
42655   , p_value_type_code              => l_adr_value_type_code
42656   , p_transaction_coa_id           => l_adr_transaction_coa_id
42657   , p_accounting_coa_id            => l_adr_accounting_coa_id
42661   , p_component_code               => l_component_code
42658   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
42659   , p_adr_type_code                => 'S'
42660   , p_component_type               => l_component_type
42662   , p_component_type_code          => l_component_type_code
42663   , p_component_appl_id            => l_component_appl_id
42664   , p_amb_context_code             => l_amb_context_code
42665   , p_side                         => 'NA'
42666   );
42667 
42668 
42669    l_segment := AcctDerRule_152(
42670            p_application_id           => p_application_id
42671          , p_ae_header_id             => l_ae_header_id 
42672 , p_source_3 => p_source_3
42673 , p_source_13 => p_source_13
42674          , x_transaction_coa_id       => l_adr_transaction_coa_id
42675          , x_accounting_coa_id        => l_adr_accounting_coa_id
42676          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
42677          , x_flex_value_set_id        => l_adr_flex_value_set_id
42678          , x_value_type_code          => l_adr_value_type_code
42679          , x_value_combination_id     => l_adr_value_combination_id
42680          , x_value_segment_code       => l_adr_value_segment_code
42681          , p_side                     => 'NA'
42682          , p_override_seg_flag        => 'Y'
42683    );
42684 
42685    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
42686 
42687       xla_ae_lines_pkg.set_segment(
42688           p_to_segment_code         => 'GL_ACCOUNT'
42689         , p_segment_value           => l_segment
42690         , p_from_segment_code       => l_adr_value_segment_code
42691         , p_from_combination_id     => l_adr_value_combination_id
42692         , p_value_type_code         => l_adr_value_type_code
42693         , p_transaction_coa_id      => l_adr_transaction_coa_id
42694         , p_accounting_coa_id       => l_adr_accounting_coa_id
42695         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42696         , p_flex_value_set_id       => l_adr_flex_value_set_id
42697         , p_adr_code                => 'FA_COST_OF_REM_GAIN_SEGMENT'
42698         , p_adr_type_code           => 'S'
42699         , p_component_type          => l_component_type
42700         , p_component_code          => l_component_code
42701         , p_component_type_code     => l_component_type_code
42702         , p_component_appl_id       => l_component_appl_id
42703         , p_amb_context_code        => l_amb_context_code
42704         , p_entity_code             => 'TRANSACTIONS'
42705         , p_event_class_code        => 'CIP_RETIREMENTS'
42706         , p_side                    => 'NA'
42707         );
42708 
42709   END IF;
42710 
42711    l_segment := AcctDerRule_168(
42712            p_application_id           => p_application_id
42713          , p_ae_header_id             => l_ae_header_id 
42714 , p_source_3 => p_source_3
42715 , p_source_29 => p_source_29
42716          , x_transaction_coa_id       => l_adr_transaction_coa_id
42717          , x_accounting_coa_id        => l_adr_accounting_coa_id
42718          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
42719          , x_flex_value_set_id        => l_adr_flex_value_set_id
42720          , x_value_type_code          => l_adr_value_type_code
42721          , x_value_combination_id     => l_adr_value_combination_id
42722          , x_value_segment_code       => l_adr_value_segment_code
42723          , p_side                     => 'NA'
42724          , p_override_seg_flag        => 'Y'
42725    );
42726 
42727    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
42728 
42729       xla_ae_lines_pkg.set_segment(
42730           p_to_segment_code         => 'GL_BALANCING'
42731         , p_segment_value           => l_segment
42732         , p_from_segment_code       => l_adr_value_segment_code
42733         , p_from_combination_id     => l_adr_value_combination_id
42734         , p_value_type_code         => l_adr_value_type_code
42735         , p_transaction_coa_id      => l_adr_transaction_coa_id
42736         , p_accounting_coa_id       => l_adr_accounting_coa_id
42737         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42738         , p_flex_value_set_id       => l_adr_flex_value_set_id
42739         , p_adr_code                => 'FA_EXPENSE_ACCT'
42740         , p_adr_type_code           => 'S'
42741         , p_component_type          => l_component_type
42742         , p_component_code          => l_component_code
42743         , p_component_type_code     => l_component_type_code
42744         , p_component_appl_id       => l_component_appl_id
42745         , p_amb_context_code        => l_amb_context_code
42746         , p_entity_code             => 'TRANSACTIONS'
42747         , p_event_class_code        => 'CIP_RETIREMENTS'
42748         , p_side                    => 'NA'
42749         );
42750 
42751   END IF;
42752 
42753    --
42754    --
42755    END IF;
42756    --
42757    -- Bug 4922099
42758    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
42759           (NVL(l_enc_upg_option, 'N') = 'O')
42760         ) AND
42761         (l_bflow_method_code = 'PRIOR_ENTRY')
42762       )
42763    THEN
42764       IF
42765       --
42766       1 = 2
42767       --
42768       THEN
42769       xla_accounting_err_pkg.build_message
42770                                     (p_appli_s_name            => 'XLA'
42771                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42772                                     ,p_token_1                 => 'LINE_NUMBER'
42773                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
42774                                     ,p_token_2                 => 'LINE_TYPE_NAME'
42775                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
42776                                                                              l_component_type
42780                                                                             ,l_amb_context_code
42777                                                                             ,l_component_code
42778                                                                             ,l_component_type_code
42779                                                                             ,l_component_appl_id
42781                                                                             ,l_entity_code
42782                                                                             ,l_event_class_code
42783                                                                            )
42784                                     ,p_token_3                 => 'OWNER'
42785                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
42786                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
42787                                                                           ,p_lookup_code    => l_component_type_code
42788                                                                          )
42789                                     ,p_token_4                 => 'PRODUCT_NAME'
42790                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
42791                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
42792                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
42793                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
42794                                     ,p_ae_header_id            =>  NULL
42795                                        );
42796 
42797         IF (C_LEVEL_ERROR>= g_log_level) THEN
42798                  trace
42799                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42800                       ,p_level    => C_LEVEL_ERROR
42801                       ,p_module   => l_log_module);
42802         END IF;
42803       END IF;
42804    END IF;
42805    --
42806    --
42807    ------------------------------------------------------------------------------------------------
42808    -- 4219869 Business Flow
42809    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
42810    -- Prior Entry.  Currently, the following code is always generated.
42811    ------------------------------------------------------------------------------------------------
42812    XLA_AE_LINES_PKG.ValidateCurrentLine;
42813 
42814    ------------------------------------------------------------------------------------
42815    -- 4219869 Business Flow
42816    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
42817    ------------------------------------------------------------------------------------
42818    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42819 
42820    ----------------------------------------------------------------------------------
42821    -- 4219869 Business Flow
42822    -- Update journal entry status -- Need to generate this within IF <condition>
42823    ----------------------------------------------------------------------------------
42824    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42825          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
42826          ,p_balance_type_code => l_balance_type_code
42827          );
42828 
42829    -------------------------------------------------------------------------------------------
42830    -- 4262811 - Generate the Accrual Reversal lines
42831    -------------------------------------------------------------------------------------------
42832    BEGIN
42833       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
42834                               (g_array_event(p_event_id).array_value_num('header_index'));
42835       IF l_acc_rev_flag IS NULL THEN
42836          l_acc_rev_flag := 'N';
42837       END IF;
42838    EXCEPTION
42839       WHEN OTHERS THEN
42840          l_acc_rev_flag := 'N';
42841    END;
42842    --
42843    IF (l_acc_rev_flag = 'Y') THEN
42844 
42845        -- 4645092  ------------------------------------------------------------------------------
42846        -- To allow MPA report to determine if it should generate report process
42847        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
42848        ------------------------------------------------------------------------------------------
42849 
42850        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
42851        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
42852    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
42853    -- call ADRs
42854    -- Bug 4922099
42855    --
42856    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
42857         (NVL(l_actual_upg_option, 'N') = 'O') OR
42858         (NVL(l_enc_upg_option, 'N') = 'O')
42859       )
42860    THEN
42861    NULL;
42862    --
42863    --
42864    
42865   l_ccid := AcctDerRule_173(
42866            p_application_id           => p_application_id
42867          , p_ae_header_id             => l_ae_header_id 
42868 , p_source_3 => p_source_3
42869 , p_source_30 => p_source_30
42870          , x_transaction_coa_id       => l_adr_transaction_coa_id
42871          , x_accounting_coa_id        => l_adr_accounting_coa_id
42872          , x_value_type_code          => l_adr_value_type_code
42873          , p_side                     => 'NA'
42874    );
42875 
42876    xla_ae_lines_pkg.set_ccid(
42877     p_code_combination_id          => l_ccid
42878   , p_value_type_code              => l_adr_value_type_code
42879   , p_transaction_coa_id           => l_adr_transaction_coa_id
42880   , p_accounting_coa_id            => l_adr_accounting_coa_id
42881   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
42882   , p_adr_type_code                => 'S'
42886   , p_component_appl_id            => l_component_appl_id
42883   , p_component_type               => l_component_type
42884   , p_component_code               => l_component_code
42885   , p_component_type_code          => l_component_type_code
42887   , p_amb_context_code             => l_amb_context_code
42888   , p_side                         => 'NA'
42889   );
42890 
42891 
42892    l_segment := AcctDerRule_152(
42893            p_application_id           => p_application_id
42894          , p_ae_header_id             => l_ae_header_id 
42895 , p_source_3 => p_source_3
42896 , p_source_13 => p_source_13
42897          , x_transaction_coa_id       => l_adr_transaction_coa_id
42898          , x_accounting_coa_id        => l_adr_accounting_coa_id
42899          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
42900          , x_flex_value_set_id        => l_adr_flex_value_set_id
42901          , x_value_type_code          => l_adr_value_type_code
42902          , x_value_combination_id     => l_adr_value_combination_id
42903          , x_value_segment_code       => l_adr_value_segment_code
42904          , p_side                     => 'NA'
42905          , p_override_seg_flag        => 'Y'
42906    );
42907 
42908    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
42909 
42910       xla_ae_lines_pkg.set_segment(
42911           p_to_segment_code         => 'GL_ACCOUNT'
42912         , p_segment_value           => l_segment
42913         , p_from_segment_code       => l_adr_value_segment_code
42914         , p_from_combination_id     => l_adr_value_combination_id
42915         , p_value_type_code         => l_adr_value_type_code
42916         , p_transaction_coa_id      => l_adr_transaction_coa_id
42917         , p_accounting_coa_id       => l_adr_accounting_coa_id
42918         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42919         , p_flex_value_set_id       => l_adr_flex_value_set_id
42920         , p_adr_code                => 'FA_COST_OF_REM_GAIN_SEGMENT'
42921         , p_adr_type_code           => 'S'
42922         , p_component_type          => l_component_type
42923         , p_component_code          => l_component_code
42924         , p_component_type_code     => l_component_type_code
42925         , p_component_appl_id       => l_component_appl_id
42926         , p_amb_context_code        => l_amb_context_code
42927         , p_entity_code             => 'TRANSACTIONS'
42928         , p_event_class_code        => 'CIP_RETIREMENTS'
42929         , p_side                    => 'NA'
42930         );
42931 
42932   END IF;
42933 
42934    l_segment := AcctDerRule_168(
42935            p_application_id           => p_application_id
42936          , p_ae_header_id             => l_ae_header_id 
42937 , p_source_3 => p_source_3
42938 , p_source_29 => p_source_29
42939          , x_transaction_coa_id       => l_adr_transaction_coa_id
42940          , x_accounting_coa_id        => l_adr_accounting_coa_id
42941          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
42942          , x_flex_value_set_id        => l_adr_flex_value_set_id
42943          , x_value_type_code          => l_adr_value_type_code
42944          , x_value_combination_id     => l_adr_value_combination_id
42945          , x_value_segment_code       => l_adr_value_segment_code
42946          , p_side                     => 'NA'
42947          , p_override_seg_flag        => 'Y'
42948    );
42949 
42950    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
42951 
42952       xla_ae_lines_pkg.set_segment(
42953           p_to_segment_code         => 'GL_BALANCING'
42954         , p_segment_value           => l_segment
42955         , p_from_segment_code       => l_adr_value_segment_code
42956         , p_from_combination_id     => l_adr_value_combination_id
42957         , p_value_type_code         => l_adr_value_type_code
42958         , p_transaction_coa_id      => l_adr_transaction_coa_id
42959         , p_accounting_coa_id       => l_adr_accounting_coa_id
42960         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42961         , p_flex_value_set_id       => l_adr_flex_value_set_id
42962         , p_adr_code                => 'FA_EXPENSE_ACCT'
42963         , p_adr_type_code           => 'S'
42964         , p_component_type          => l_component_type
42965         , p_component_code          => l_component_code
42966         , p_component_type_code     => l_component_type_code
42967         , p_component_appl_id       => l_component_appl_id
42968         , p_amb_context_code        => l_amb_context_code
42969         , p_entity_code             => 'TRANSACTIONS'
42970         , p_event_class_code        => 'CIP_RETIREMENTS'
42971         , p_side                    => 'NA'
42972         );
42973 
42974   END IF;
42975 
42976    --
42977    --
42978    END IF;
42979 
42980        --
42981        -- Update the line information that should be overwritten
42982        --
42983        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
42984                                          p_header_num   => 1);
42985        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
42986 
42987        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
42988 
42989        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
42990           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
42991        END IF;
42992 
42993       --
42994       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
42995       --
42996       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
42997           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
42998       ELSE
43002           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
42999           ---------------------------------------------------------------------------------------------------
43000           -- 4262811a Switch Sign
43001           ---------------------------------------------------------------------------------------------------
43003           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
43004                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43005           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
43006                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43007           -- 5132302
43008           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
43009                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43010 
43011       END IF;
43012 
43013       -- 4955764
43014       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
43015       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
43016 
43017 
43018       XLA_AE_LINES_PKG.ValidateCurrentLine;
43019       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
43020 
43021       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
43022                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
43023                ,p_balance_type_code => l_balance_type_code);
43024 
43025    END IF;
43026 
43027    -----------------------------------------------------------------------------------------
43028    -- 4262811 Multiperiod Accounting
43029    -----------------------------------------------------------------------------------------
43030      -- No MPA option is assigned.
43031 
43032 
43033 END IF;
43034 END IF;
43035 --
43036 
43037 --
43038 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
43039    trace
43040       (p_msg      => 'END of AcctLineType_214'
43041       ,p_level    => C_LEVEL_PROCEDURE
43042       ,p_module   => l_log_module);
43043 END IF;
43044 --
43045 EXCEPTION
43046   WHEN xla_exceptions_pkg.application_exception THEN
43047       RAISE;
43048   WHEN OTHERS THEN
43049        xla_exceptions_pkg.raise_message
43050            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_214');
43051 END AcctLineType_214;
43052 --
43053 
43054 ---------------------------------------
43055 --
43056 -- PRIVATE FUNCTION
43057 --         AcctLineType_215
43058 --
43059 ---------------------------------------
43060 PROCEDURE AcctLineType_215 (
43061   p_application_id        IN NUMBER
43062  ,p_event_id              IN NUMBER
43063  ,p_calculate_acctd_flag  IN VARCHAR2
43064  ,p_calculate_g_l_flag    IN VARCHAR2
43065  ,p_actual_flag           IN OUT VARCHAR2
43066  ,p_balance_type_code     OUT VARCHAR2
43067  ,p_gain_or_loss_ref      OUT VARCHAR2
43068  
43069 --Period Close Date
43070  , p_source_1            IN DATE
43071 --Generated Code Combination Identifier
43072  , p_source_3            IN NUMBER
43073 --Cost Of Removal Loss Account
43074  , p_source_14            IN VARCHAR2
43075 --Expense Account Code Combination Identifier
43076  , p_source_29            IN NUMBER
43077 --Default Code Combination Identifier
43078  , p_source_30            IN NUMBER
43079 --Adjustment Type
43080  , p_source_35            IN VARCHAR2
43081 --Transaction Header Identifier
43082  , p_source_36            IN NUMBER
43083 --Adjustment Line Identifier
43084  , p_source_37            IN NUMBER
43085 --Distribution Type Code
43086  , p_source_38            IN VARCHAR2
43087 --Entered Amount
43088  , p_source_39            IN NUMBER
43089 --Currency Code
43090  , p_source_40            IN VARCHAR2
43091 --Gain Loss Amount
43092  , p_source_41            IN NUMBER
43093 )
43094 IS
43095 
43096 l_component_type              VARCHAR2(80);
43097 l_component_code              VARCHAR2(30);
43098 l_component_type_code         VARCHAR2(1);
43099 l_component_appl_id           INTEGER;
43100 l_amb_context_code            VARCHAR2(30);
43101 l_entity_code                 VARCHAR2(30);
43102 l_event_class_code            VARCHAR2(30);
43103 l_ae_header_id                NUMBER;
43104 l_event_type_code             VARCHAR2(30);
43105 l_line_definition_code        VARCHAR2(30);
43106 l_line_definition_owner_code  VARCHAR2(1);
43107 --
43108 -- adr variables
43109 l_segment                     VARCHAR2(30);
43110 l_ccid                        NUMBER;
43111 l_adr_transaction_coa_id      NUMBER;
43112 l_adr_accounting_coa_id       NUMBER;
43113 l_adr_flexfield_segment_code  VARCHAR2(30);
43114 l_adr_flex_value_set_id       NUMBER;
43115 l_adr_value_type_code         VARCHAR2(30);
43116 l_adr_value_combination_id    NUMBER;
43117 l_adr_value_segment_code      VARCHAR2(30);
43118 
43119 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
43120 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
43121 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
43122 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
43123 
43124 -- 4262811 Variables ------------------------------------------------------------------------------------------
43125 l_entered_amt_idx             NUMBER;
43126 l_accted_amt_idx              NUMBER;
43127 l_acc_rev_flag                VARCHAR2(1);
43128 l_accrual_line_num            NUMBER;
43129 l_tmp_amt                     NUMBER;
43130 l_acc_rev_natural_side_code   VARCHAR2(1);
43131 
43132 l_num_entries                 NUMBER;
43133 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
43137 l_recog_line_1                NUMBER;
43134 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
43135 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
43136 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
43138 l_recog_line_2                NUMBER;
43139 
43140 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
43141 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
43142 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
43143 
43144 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
43145 
43146 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
43147 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
43148 
43149 ---------------------------------------------------------------------------------------------------------------
43150 
43151 
43152 --
43153 -- bulk performance
43154 --
43155 l_balance_type_code           VARCHAR2(1);
43156 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
43157 l_log_module                  VARCHAR2(240);
43158 
43159 --
43160 -- Upgrade strategy
43161 --
43162 l_actual_upg_option           VARCHAR2(1);
43163 l_enc_upg_option           VARCHAR2(1);
43164 
43165 --
43166 BEGIN
43167 --
43168 IF g_log_enabled THEN
43169       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_215';
43170 END IF;
43171 --
43172 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
43173 
43174       trace
43175          (p_msg      => 'BEGIN of AcctLineType_215'
43176          ,p_level    => C_LEVEL_PROCEDURE
43177          ,p_module   => l_log_module);
43178 
43179 END IF;
43180 --
43181 l_component_type             := 'AMB_JLT';
43182 l_component_code             := 'FA_CIP_COST_OF_REMOVAL_LOSS';
43183 l_component_type_code        := 'S';
43184 l_component_appl_id          :=  140;
43185 l_amb_context_code           := 'DEFAULT';
43186 l_entity_code                := 'TRANSACTIONS';
43187 l_event_class_code           := 'CIP_RETIREMENTS';
43188 l_event_type_code            := 'CIP_RETIREMENTS';
43189 l_line_definition_owner_code := 'S';
43190 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
43191 --
43192 l_balance_type_code          := 'A';
43193 l_segment                     := NULL;
43194 l_ccid                        := NULL;
43195 l_adr_transaction_coa_id      := NULL;
43196 l_adr_accounting_coa_id       := NULL;
43197 l_adr_flexfield_segment_code  := NULL;
43198 l_adr_flex_value_set_id       := NULL;
43199 l_adr_value_type_code         := NULL;
43200 l_adr_value_combination_id    := NULL;
43201 l_adr_value_segment_code      := NULL;
43202 
43203 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
43204 l_bflow_class_code           := '';    -- 4219869 Business Flow
43205 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
43206 l_budgetary_control_flag     := 'N';
43207 
43208 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
43209 l_bflow_applied_to_amt       := NULL; -- 5132302
43210 l_entered_amt_idx            := NULL;          -- 4262811
43211 l_accted_amt_idx             := NULL;          -- 4262811
43212 l_acc_rev_flag               := NULL;          -- 4262811
43213 l_accrual_line_num           := NULL;          -- 4262811
43214 l_tmp_amt                    := NULL;          -- 4262811
43215 --
43216  
43217 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
43218     l_balance_type_code <> 'B' THEN
43219 IF NVL(p_source_35,'
43220 ') =  'REMOVALCOST' AND 
43221 p_source_41 <  0
43222  THEN 
43223 
43224    --
43225    XLA_AE_LINES_PKG.SetNewLine;
43226 
43227    p_balance_type_code          := l_balance_type_code;
43228    -- set the flag so later we will know whether the gain loss line needs to be created
43229    
43230    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
43231      p_actual_flag :='A';
43232    END IF;
43233 
43234    --
43235    -- bulk performance
43236    --
43237    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
43238                                       p_header_num   => 0); -- 4262811
43239    --
43240    -- set accounting line options
43241    --
43242    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
43243            p_natural_side_code          => 'D'
43244          , p_gain_or_loss_flag          => 'N'
43245          , p_gl_transfer_mode_code      => 'S'
43246          , p_acct_entry_type_code       => 'A'
43247          , p_switch_side_flag           => 'Y'
43248          , p_merge_duplicate_code       => 'N'
43249          );
43250    --
43251    l_acc_rev_natural_side_code := 'C';  -- 4262811
43252    -- 
43253    --
43254    -- set accounting line type info
43255    --
43256    xla_ae_lines_pkg.SetAcctLineType
43257       (p_component_type             => l_component_type
43258       ,p_event_type_code            => l_event_type_code
43259       ,p_line_definition_owner_code => l_line_definition_owner_code
43260       ,p_line_definition_code       => l_line_definition_code
43261       ,p_accounting_line_code       => l_component_code
43262       ,p_accounting_line_type_code  => l_component_type_code
43263       ,p_accounting_line_appl_id    => l_component_appl_id
43264       ,p_amb_context_code           => l_amb_context_code
43265       ,p_entity_code                => l_entity_code
43266       ,p_event_class_code           => l_event_class_code);
43267    --
43268    -- set accounting class
43269    --
43270    xla_ae_lines_pkg.SetAcctClass(
43271            p_accounting_class_code  => 'ASSET'
43272          , p_ae_header_id           => l_ae_header_id
43273          );
43274 
43275    --
43279                       'ASSET';
43276    -- set rounding class
43277    --
43278    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
43280 
43281    --
43282    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
43283    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
43284    --
43285    -- bulk performance
43286    --
43287    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
43288 
43289    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
43290       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
43291 
43292    -- 4955764
43293    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
43294       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
43295 
43296    -- 4458381 Public Sector Enh
43297    
43298    --
43299    -- set accounting attributes for the line type
43300    --
43301    l_entered_amt_idx := 4;
43302    l_accted_amt_idx  := 6;
43303    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
43304    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
43305    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
43306    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
43307    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
43308    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
43309    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
43310    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
43311    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
43312    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
43313    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
43314    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
43315    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
43316 
43317    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
43318    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
43319 
43320    ---------------------------------------------------------------------------------------------------------------
43321    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
43322    ---------------------------------------------------------------------------------------------------------------
43323    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
43324 
43325    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43326    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43327 
43328    IF xla_accounting_cache_pkg.GetValueChar
43329          (p_source_code         => 'LEDGER_CATEGORY_CODE'
43330          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
43331    AND l_bflow_method_code = 'PRIOR_ENTRY'
43332 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
43333    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
43334          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
43335        )
43336    THEN
43337          xla_ae_lines_pkg.BflowUpgEntry
43338            (p_business_method_code    => l_bflow_method_code
43339            ,p_business_class_code     => l_bflow_class_code
43340            ,p_balance_type            => l_balance_type_code);
43341    ELSE
43342       NULL;
43343 -- No business flow processing for business flow method of NONE.
43344    END IF;
43345 
43346    --
43347    -- call analytical criteria
43348    --
43349    
43350    --
43351    -- call description
43352    --
43353    
43354 xla_ae_lines_pkg.SetLineDescription(
43355    p_ae_header_id => l_ae_header_id
43356   ,p_description  => Description_36 (
43357      p_application_id         => p_application_id
43358    , p_ae_header_id           => l_ae_header_id 
43359 , p_source_1 => p_source_1
43360    )
43361 );
43362 
43363 
43364    --
43365    -- call ADRs
43366    -- Bug 4922099
43367    --
43368    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
43369         (NVL(l_actual_upg_option, 'N') = 'O') OR
43370         (NVL(l_enc_upg_option, 'N') = 'O')
43371       )
43372    THEN
43373    NULL;
43374    --
43375    --
43376    
43377   l_ccid := AcctDerRule_173(
43378            p_application_id           => p_application_id
43379          , p_ae_header_id             => l_ae_header_id 
43380 , p_source_3 => p_source_3
43381 , p_source_30 => p_source_30
43382          , x_transaction_coa_id       => l_adr_transaction_coa_id
43383          , x_accounting_coa_id        => l_adr_accounting_coa_id
43384          , x_value_type_code          => l_adr_value_type_code
43385          , p_side                     => 'NA'
43386    );
43387 
43388    xla_ae_lines_pkg.set_ccid(
43389     p_code_combination_id          => l_ccid
43390   , p_value_type_code              => l_adr_value_type_code
43391   , p_transaction_coa_id           => l_adr_transaction_coa_id
43392   , p_accounting_coa_id            => l_adr_accounting_coa_id
43393   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
43394   , p_adr_type_code                => 'S'
43395   , p_component_type               => l_component_type
43396   , p_component_code               => l_component_code
43397   , p_component_type_code          => l_component_type_code
43398   , p_component_appl_id            => l_component_appl_id
43399   , p_amb_context_code             => l_amb_context_code
43400   , p_side                         => 'NA'
43401   );
43402 
43403 
43407 , p_source_3 => p_source_3
43404    l_segment := AcctDerRule_153(
43405            p_application_id           => p_application_id
43406          , p_ae_header_id             => l_ae_header_id 
43408 , p_source_14 => p_source_14
43409          , x_transaction_coa_id       => l_adr_transaction_coa_id
43410          , x_accounting_coa_id        => l_adr_accounting_coa_id
43411          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43412          , x_flex_value_set_id        => l_adr_flex_value_set_id
43413          , x_value_type_code          => l_adr_value_type_code
43414          , x_value_combination_id     => l_adr_value_combination_id
43415          , x_value_segment_code       => l_adr_value_segment_code
43416          , p_side                     => 'NA'
43417          , p_override_seg_flag        => 'Y'
43418    );
43419 
43420    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43421 
43422       xla_ae_lines_pkg.set_segment(
43423           p_to_segment_code         => 'GL_ACCOUNT'
43424         , p_segment_value           => l_segment
43425         , p_from_segment_code       => l_adr_value_segment_code
43426         , p_from_combination_id     => l_adr_value_combination_id
43427         , p_value_type_code         => l_adr_value_type_code
43428         , p_transaction_coa_id      => l_adr_transaction_coa_id
43429         , p_accounting_coa_id       => l_adr_accounting_coa_id
43430         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43431         , p_flex_value_set_id       => l_adr_flex_value_set_id
43432         , p_adr_code                => 'FA_COST_OF_REM_LOSS_SEGMENT'
43433         , p_adr_type_code           => 'S'
43434         , p_component_type          => l_component_type
43435         , p_component_code          => l_component_code
43436         , p_component_type_code     => l_component_type_code
43437         , p_component_appl_id       => l_component_appl_id
43438         , p_amb_context_code        => l_amb_context_code
43439         , p_entity_code             => 'TRANSACTIONS'
43440         , p_event_class_code        => 'CIP_RETIREMENTS'
43441         , p_side                    => 'NA'
43442         );
43443 
43444   END IF;
43445 
43446    l_segment := AcctDerRule_168(
43447            p_application_id           => p_application_id
43448          , p_ae_header_id             => l_ae_header_id 
43449 , p_source_3 => p_source_3
43450 , p_source_29 => p_source_29
43451          , x_transaction_coa_id       => l_adr_transaction_coa_id
43452          , x_accounting_coa_id        => l_adr_accounting_coa_id
43453          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43454          , x_flex_value_set_id        => l_adr_flex_value_set_id
43455          , x_value_type_code          => l_adr_value_type_code
43456          , x_value_combination_id     => l_adr_value_combination_id
43457          , x_value_segment_code       => l_adr_value_segment_code
43458          , p_side                     => 'NA'
43459          , p_override_seg_flag        => 'Y'
43460    );
43461 
43462    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43463 
43464       xla_ae_lines_pkg.set_segment(
43465           p_to_segment_code         => 'GL_BALANCING'
43466         , p_segment_value           => l_segment
43467         , p_from_segment_code       => l_adr_value_segment_code
43468         , p_from_combination_id     => l_adr_value_combination_id
43469         , p_value_type_code         => l_adr_value_type_code
43470         , p_transaction_coa_id      => l_adr_transaction_coa_id
43471         , p_accounting_coa_id       => l_adr_accounting_coa_id
43472         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43473         , p_flex_value_set_id       => l_adr_flex_value_set_id
43474         , p_adr_code                => 'FA_EXPENSE_ACCT'
43475         , p_adr_type_code           => 'S'
43476         , p_component_type          => l_component_type
43477         , p_component_code          => l_component_code
43478         , p_component_type_code     => l_component_type_code
43479         , p_component_appl_id       => l_component_appl_id
43480         , p_amb_context_code        => l_amb_context_code
43481         , p_entity_code             => 'TRANSACTIONS'
43482         , p_event_class_code        => 'CIP_RETIREMENTS'
43483         , p_side                    => 'NA'
43484         );
43485 
43486   END IF;
43487 
43488    --
43489    --
43490    END IF;
43491    --
43492    -- Bug 4922099
43493    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
43494           (NVL(l_enc_upg_option, 'N') = 'O')
43495         ) AND
43496         (l_bflow_method_code = 'PRIOR_ENTRY')
43497       )
43498    THEN
43499       IF
43500       --
43501       1 = 2
43502       --
43503       THEN
43504       xla_accounting_err_pkg.build_message
43505                                     (p_appli_s_name            => 'XLA'
43506                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43507                                     ,p_token_1                 => 'LINE_NUMBER'
43508                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
43509                                     ,p_token_2                 => 'LINE_TYPE_NAME'
43510                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
43511                                                                              l_component_type
43512                                                                             ,l_component_code
43513                                                                             ,l_component_type_code
43514                                                                             ,l_component_appl_id
43515                                                                             ,l_amb_context_code
43516                                                                             ,l_entity_code
43520                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
43517                                                                             ,l_event_class_code
43518                                                                            )
43519                                     ,p_token_3                 => 'OWNER'
43521                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
43522                                                                           ,p_lookup_code    => l_component_type_code
43523                                                                          )
43524                                     ,p_token_4                 => 'PRODUCT_NAME'
43525                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
43526                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
43527                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
43528                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
43529                                     ,p_ae_header_id            =>  NULL
43530                                        );
43531 
43532         IF (C_LEVEL_ERROR>= g_log_level) THEN
43533                  trace
43534                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43535                       ,p_level    => C_LEVEL_ERROR
43536                       ,p_module   => l_log_module);
43537         END IF;
43538       END IF;
43539    END IF;
43540    --
43541    --
43542    ------------------------------------------------------------------------------------------------
43543    -- 4219869 Business Flow
43544    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
43545    -- Prior Entry.  Currently, the following code is always generated.
43546    ------------------------------------------------------------------------------------------------
43547    XLA_AE_LINES_PKG.ValidateCurrentLine;
43548 
43549    ------------------------------------------------------------------------------------
43550    -- 4219869 Business Flow
43551    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
43552    ------------------------------------------------------------------------------------
43553    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
43554 
43555    ----------------------------------------------------------------------------------
43556    -- 4219869 Business Flow
43557    -- Update journal entry status -- Need to generate this within IF <condition>
43558    ----------------------------------------------------------------------------------
43559    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
43560          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
43561          ,p_balance_type_code => l_balance_type_code
43562          );
43563 
43564    -------------------------------------------------------------------------------------------
43565    -- 4262811 - Generate the Accrual Reversal lines
43566    -------------------------------------------------------------------------------------------
43567    BEGIN
43568       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
43569                               (g_array_event(p_event_id).array_value_num('header_index'));
43570       IF l_acc_rev_flag IS NULL THEN
43571          l_acc_rev_flag := 'N';
43572       END IF;
43573    EXCEPTION
43574       WHEN OTHERS THEN
43575          l_acc_rev_flag := 'N';
43576    END;
43577    --
43578    IF (l_acc_rev_flag = 'Y') THEN
43579 
43580        -- 4645092  ------------------------------------------------------------------------------
43581        -- To allow MPA report to determine if it should generate report process
43582        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
43583        ------------------------------------------------------------------------------------------
43584 
43585        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
43586        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
43587    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
43588    -- call ADRs
43589    -- Bug 4922099
43590    --
43591    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
43592         (NVL(l_actual_upg_option, 'N') = 'O') OR
43593         (NVL(l_enc_upg_option, 'N') = 'O')
43594       )
43595    THEN
43596    NULL;
43597    --
43598    --
43599    
43600   l_ccid := AcctDerRule_173(
43601            p_application_id           => p_application_id
43602          , p_ae_header_id             => l_ae_header_id 
43603 , p_source_3 => p_source_3
43604 , p_source_30 => p_source_30
43605          , x_transaction_coa_id       => l_adr_transaction_coa_id
43606          , x_accounting_coa_id        => l_adr_accounting_coa_id
43607          , x_value_type_code          => l_adr_value_type_code
43608          , p_side                     => 'NA'
43609    );
43610 
43611    xla_ae_lines_pkg.set_ccid(
43612     p_code_combination_id          => l_ccid
43613   , p_value_type_code              => l_adr_value_type_code
43614   , p_transaction_coa_id           => l_adr_transaction_coa_id
43615   , p_accounting_coa_id            => l_adr_accounting_coa_id
43616   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
43617   , p_adr_type_code                => 'S'
43618   , p_component_type               => l_component_type
43619   , p_component_code               => l_component_code
43620   , p_component_type_code          => l_component_type_code
43621   , p_component_appl_id            => l_component_appl_id
43622   , p_amb_context_code             => l_amb_context_code
43623   , p_side                         => 'NA'
43624   );
43625 
43626 
43627    l_segment := AcctDerRule_153(
43631 , p_source_14 => p_source_14
43628            p_application_id           => p_application_id
43629          , p_ae_header_id             => l_ae_header_id 
43630 , p_source_3 => p_source_3
43632          , x_transaction_coa_id       => l_adr_transaction_coa_id
43633          , x_accounting_coa_id        => l_adr_accounting_coa_id
43634          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43635          , x_flex_value_set_id        => l_adr_flex_value_set_id
43636          , x_value_type_code          => l_adr_value_type_code
43637          , x_value_combination_id     => l_adr_value_combination_id
43638          , x_value_segment_code       => l_adr_value_segment_code
43639          , p_side                     => 'NA'
43640          , p_override_seg_flag        => 'Y'
43641    );
43642 
43643    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43644 
43645       xla_ae_lines_pkg.set_segment(
43646           p_to_segment_code         => 'GL_ACCOUNT'
43647         , p_segment_value           => l_segment
43648         , p_from_segment_code       => l_adr_value_segment_code
43649         , p_from_combination_id     => l_adr_value_combination_id
43650         , p_value_type_code         => l_adr_value_type_code
43651         , p_transaction_coa_id      => l_adr_transaction_coa_id
43652         , p_accounting_coa_id       => l_adr_accounting_coa_id
43653         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43654         , p_flex_value_set_id       => l_adr_flex_value_set_id
43655         , p_adr_code                => 'FA_COST_OF_REM_LOSS_SEGMENT'
43656         , p_adr_type_code           => 'S'
43657         , p_component_type          => l_component_type
43658         , p_component_code          => l_component_code
43659         , p_component_type_code     => l_component_type_code
43660         , p_component_appl_id       => l_component_appl_id
43661         , p_amb_context_code        => l_amb_context_code
43662         , p_entity_code             => 'TRANSACTIONS'
43663         , p_event_class_code        => 'CIP_RETIREMENTS'
43664         , p_side                    => 'NA'
43665         );
43666 
43667   END IF;
43668 
43669    l_segment := AcctDerRule_168(
43670            p_application_id           => p_application_id
43671          , p_ae_header_id             => l_ae_header_id 
43672 , p_source_3 => p_source_3
43673 , p_source_29 => p_source_29
43674          , x_transaction_coa_id       => l_adr_transaction_coa_id
43675          , x_accounting_coa_id        => l_adr_accounting_coa_id
43676          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43677          , x_flex_value_set_id        => l_adr_flex_value_set_id
43678          , x_value_type_code          => l_adr_value_type_code
43679          , x_value_combination_id     => l_adr_value_combination_id
43680          , x_value_segment_code       => l_adr_value_segment_code
43681          , p_side                     => 'NA'
43682          , p_override_seg_flag        => 'Y'
43683    );
43684 
43685    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43686 
43687       xla_ae_lines_pkg.set_segment(
43688           p_to_segment_code         => 'GL_BALANCING'
43689         , p_segment_value           => l_segment
43690         , p_from_segment_code       => l_adr_value_segment_code
43691         , p_from_combination_id     => l_adr_value_combination_id
43692         , p_value_type_code         => l_adr_value_type_code
43693         , p_transaction_coa_id      => l_adr_transaction_coa_id
43694         , p_accounting_coa_id       => l_adr_accounting_coa_id
43695         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43696         , p_flex_value_set_id       => l_adr_flex_value_set_id
43697         , p_adr_code                => 'FA_EXPENSE_ACCT'
43698         , p_adr_type_code           => 'S'
43699         , p_component_type          => l_component_type
43700         , p_component_code          => l_component_code
43701         , p_component_type_code     => l_component_type_code
43702         , p_component_appl_id       => l_component_appl_id
43703         , p_amb_context_code        => l_amb_context_code
43704         , p_entity_code             => 'TRANSACTIONS'
43705         , p_event_class_code        => 'CIP_RETIREMENTS'
43706         , p_side                    => 'NA'
43707         );
43708 
43709   END IF;
43710 
43711    --
43712    --
43713    END IF;
43714 
43715        --
43716        -- Update the line information that should be overwritten
43717        --
43718        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
43719                                          p_header_num   => 1);
43720        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
43721 
43722        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
43723 
43724        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
43725           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
43726        END IF;
43727 
43728       --
43729       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
43730       --
43731       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
43732           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
43733       ELSE
43734           ---------------------------------------------------------------------------------------------------
43735           -- 4262811a Switch Sign
43736           ---------------------------------------------------------------------------------------------------
43737           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
43738           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
43742           -- 5132302
43739                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43740           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
43741                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43743           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
43744                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43745 
43746       END IF;
43747 
43748       -- 4955764
43749       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
43750       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
43751 
43752 
43753       XLA_AE_LINES_PKG.ValidateCurrentLine;
43754       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
43755 
43756       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
43757                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
43758                ,p_balance_type_code => l_balance_type_code);
43759 
43760    END IF;
43761 
43762    -----------------------------------------------------------------------------------------
43763    -- 4262811 Multiperiod Accounting
43764    -----------------------------------------------------------------------------------------
43765      -- No MPA option is assigned.
43766 
43767 
43768 END IF;
43769 END IF;
43770 --
43771 
43772 --
43773 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
43774    trace
43775       (p_msg      => 'END of AcctLineType_215'
43776       ,p_level    => C_LEVEL_PROCEDURE
43777       ,p_module   => l_log_module);
43778 END IF;
43779 --
43780 EXCEPTION
43781   WHEN xla_exceptions_pkg.application_exception THEN
43782       RAISE;
43783   WHEN OTHERS THEN
43784        xla_exceptions_pkg.raise_message
43785            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_215');
43786 END AcctLineType_215;
43787 --
43788 
43789 ---------------------------------------
43790 --
43791 -- PRIVATE FUNCTION
43792 --         AcctLineType_216
43793 --
43794 ---------------------------------------
43795 PROCEDURE AcctLineType_216 (
43796   p_application_id        IN NUMBER
43797  ,p_event_id              IN NUMBER
43798  ,p_calculate_acctd_flag  IN VARCHAR2
43799  ,p_calculate_g_l_flag    IN VARCHAR2
43800  ,p_actual_flag           IN OUT VARCHAR2
43801  ,p_balance_type_code     OUT VARCHAR2
43802  ,p_gain_or_loss_ref      OUT VARCHAR2
43803  
43804 --Period Close Date
43805  , p_source_1            IN DATE
43806 --Generated Code Combination Identifier
43807  , p_source_3            IN NUMBER
43808 --Cost Of Removal Loss Account
43809  , p_source_14            IN VARCHAR2
43810 --Expense Account Code Combination Identifier
43811  , p_source_29            IN NUMBER
43812 --Default Code Combination Identifier
43813  , p_source_30            IN NUMBER
43814 --Adjustment Type
43815  , p_source_35            IN VARCHAR2
43816 --Transaction Header Identifier
43817  , p_source_36            IN NUMBER
43818 --Adjustment Line Identifier
43819  , p_source_37            IN NUMBER
43820 --Distribution Type Code
43821  , p_source_38            IN VARCHAR2
43822 --Entered Amount
43823  , p_source_39            IN NUMBER
43824 --Currency Code
43825  , p_source_40            IN VARCHAR2
43826 --Gain Loss Amount
43827  , p_source_41            IN NUMBER
43828 )
43829 IS
43830 
43831 l_component_type              VARCHAR2(80);
43832 l_component_code              VARCHAR2(30);
43833 l_component_type_code         VARCHAR2(1);
43834 l_component_appl_id           INTEGER;
43835 l_amb_context_code            VARCHAR2(30);
43836 l_entity_code                 VARCHAR2(30);
43837 l_event_class_code            VARCHAR2(30);
43838 l_ae_header_id                NUMBER;
43839 l_event_type_code             VARCHAR2(30);
43840 l_line_definition_code        VARCHAR2(30);
43841 l_line_definition_owner_code  VARCHAR2(1);
43842 --
43843 -- adr variables
43844 l_segment                     VARCHAR2(30);
43845 l_ccid                        NUMBER;
43846 l_adr_transaction_coa_id      NUMBER;
43847 l_adr_accounting_coa_id       NUMBER;
43848 l_adr_flexfield_segment_code  VARCHAR2(30);
43849 l_adr_flex_value_set_id       NUMBER;
43850 l_adr_value_type_code         VARCHAR2(30);
43851 l_adr_value_combination_id    NUMBER;
43852 l_adr_value_segment_code      VARCHAR2(30);
43853 
43854 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
43855 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
43856 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
43857 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
43858 
43859 -- 4262811 Variables ------------------------------------------------------------------------------------------
43860 l_entered_amt_idx             NUMBER;
43861 l_accted_amt_idx              NUMBER;
43862 l_acc_rev_flag                VARCHAR2(1);
43863 l_accrual_line_num            NUMBER;
43864 l_tmp_amt                     NUMBER;
43865 l_acc_rev_natural_side_code   VARCHAR2(1);
43866 
43867 l_num_entries                 NUMBER;
43868 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
43869 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
43870 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
43871 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
43872 l_recog_line_1                NUMBER;
43873 l_recog_line_2                NUMBER;
43874 
43875 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
43876 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
43880 
43877 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
43878 
43879 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
43881 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
43882 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
43883 
43884 ---------------------------------------------------------------------------------------------------------------
43885 
43886 
43887 --
43888 -- bulk performance
43889 --
43890 l_balance_type_code           VARCHAR2(1);
43891 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
43892 l_log_module                  VARCHAR2(240);
43893 
43894 --
43895 -- Upgrade strategy
43896 --
43897 l_actual_upg_option           VARCHAR2(1);
43898 l_enc_upg_option           VARCHAR2(1);
43899 
43900 --
43901 BEGIN
43902 --
43903 IF g_log_enabled THEN
43904       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_216';
43905 END IF;
43906 --
43907 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
43908 
43909       trace
43910          (p_msg      => 'BEGIN of AcctLineType_216'
43911          ,p_level    => C_LEVEL_PROCEDURE
43912          ,p_module   => l_log_module);
43913 
43914 END IF;
43915 --
43916 l_component_type             := 'AMB_JLT';
43917 l_component_code             := 'FA_CIP_COST_OF_REMOVAL_LOSS';
43918 l_component_type_code        := 'S';
43919 l_component_appl_id          :=  140;
43920 l_amb_context_code           := 'DEFAULT';
43921 l_entity_code                := 'TRANSACTIONS';
43922 l_event_class_code           := 'CIP_RETIREMENTS';
43923 l_event_type_code            := 'CIP_REINSTATEMENTS';
43924 l_line_definition_owner_code := 'S';
43925 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
43926 --
43927 l_balance_type_code          := 'A';
43928 l_segment                     := NULL;
43929 l_ccid                        := NULL;
43930 l_adr_transaction_coa_id      := NULL;
43931 l_adr_accounting_coa_id       := NULL;
43932 l_adr_flexfield_segment_code  := NULL;
43933 l_adr_flex_value_set_id       := NULL;
43934 l_adr_value_type_code         := NULL;
43935 l_adr_value_combination_id    := NULL;
43936 l_adr_value_segment_code      := NULL;
43937 
43938 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
43939 l_bflow_class_code           := '';    -- 4219869 Business Flow
43940 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
43941 l_budgetary_control_flag     := 'N';
43942 
43943 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
43944 l_bflow_applied_to_amt       := NULL; -- 5132302
43945 l_entered_amt_idx            := NULL;          -- 4262811
43946 l_accted_amt_idx             := NULL;          -- 4262811
43947 l_acc_rev_flag               := NULL;          -- 4262811
43948 l_accrual_line_num           := NULL;          -- 4262811
43949 l_tmp_amt                    := NULL;          -- 4262811
43950 --
43951  
43952 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
43953     l_balance_type_code <> 'B' THEN
43954 IF NVL(p_source_35,'
43955 ') =  'REMOVALCOST' AND 
43956 p_source_41 <  0
43957  THEN 
43958 
43959    --
43960    XLA_AE_LINES_PKG.SetNewLine;
43961 
43962    p_balance_type_code          := l_balance_type_code;
43963    -- set the flag so later we will know whether the gain loss line needs to be created
43964    
43965    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
43966      p_actual_flag :='A';
43967    END IF;
43968 
43969    --
43970    -- bulk performance
43971    --
43972    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
43973                                       p_header_num   => 0); -- 4262811
43974    --
43975    -- set accounting line options
43976    --
43977    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
43978            p_natural_side_code          => 'D'
43979          , p_gain_or_loss_flag          => 'N'
43980          , p_gl_transfer_mode_code      => 'S'
43981          , p_acct_entry_type_code       => 'A'
43982          , p_switch_side_flag           => 'Y'
43983          , p_merge_duplicate_code       => 'N'
43984          );
43985    --
43986    l_acc_rev_natural_side_code := 'C';  -- 4262811
43987    -- 
43988    --
43989    -- set accounting line type info
43990    --
43991    xla_ae_lines_pkg.SetAcctLineType
43992       (p_component_type             => l_component_type
43993       ,p_event_type_code            => l_event_type_code
43994       ,p_line_definition_owner_code => l_line_definition_owner_code
43995       ,p_line_definition_code       => l_line_definition_code
43996       ,p_accounting_line_code       => l_component_code
43997       ,p_accounting_line_type_code  => l_component_type_code
43998       ,p_accounting_line_appl_id    => l_component_appl_id
43999       ,p_amb_context_code           => l_amb_context_code
44000       ,p_entity_code                => l_entity_code
44001       ,p_event_class_code           => l_event_class_code);
44002    --
44003    -- set accounting class
44004    --
44005    xla_ae_lines_pkg.SetAcctClass(
44006            p_accounting_class_code  => 'ASSET'
44007          , p_ae_header_id           => l_ae_header_id
44008          );
44009 
44010    --
44011    -- set rounding class
44012    --
44013    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
44014                       'ASSET';
44015 
44016    --
44017    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
44018    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
44019    --
44023 
44020    -- bulk performance
44021    --
44022    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
44024    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
44025       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
44026 
44027    -- 4955764
44028    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
44029       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
44030 
44031    -- 4458381 Public Sector Enh
44032    
44033    --
44034    -- set accounting attributes for the line type
44035    --
44036    l_entered_amt_idx := 4;
44037    l_accted_amt_idx  := 6;
44038    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
44039    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
44040    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
44041    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
44042    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
44043    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
44044    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
44045    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
44046    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
44047    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
44048    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
44049    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
44050    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
44051 
44052    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
44053    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
44054 
44055    ---------------------------------------------------------------------------------------------------------------
44056    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
44057    ---------------------------------------------------------------------------------------------------------------
44058    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
44059 
44060    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
44061    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
44062 
44063    IF xla_accounting_cache_pkg.GetValueChar
44064          (p_source_code         => 'LEDGER_CATEGORY_CODE'
44065          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
44066    AND l_bflow_method_code = 'PRIOR_ENTRY'
44067 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
44068    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
44069          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
44070        )
44071    THEN
44072          xla_ae_lines_pkg.BflowUpgEntry
44073            (p_business_method_code    => l_bflow_method_code
44074            ,p_business_class_code     => l_bflow_class_code
44075            ,p_balance_type            => l_balance_type_code);
44076    ELSE
44077       NULL;
44078 -- No business flow processing for business flow method of NONE.
44079    END IF;
44080 
44081    --
44082    -- call analytical criteria
44083    --
44084    
44085    --
44086    -- call description
44087    --
44088    
44089 xla_ae_lines_pkg.SetLineDescription(
44090    p_ae_header_id => l_ae_header_id
44091   ,p_description  => Description_36 (
44092      p_application_id         => p_application_id
44093    , p_ae_header_id           => l_ae_header_id 
44094 , p_source_1 => p_source_1
44095    )
44096 );
44097 
44098 
44099    --
44100    -- call ADRs
44101    -- Bug 4922099
44102    --
44103    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
44104         (NVL(l_actual_upg_option, 'N') = 'O') OR
44105         (NVL(l_enc_upg_option, 'N') = 'O')
44106       )
44107    THEN
44108    NULL;
44109    --
44110    --
44111    
44112   l_ccid := AcctDerRule_173(
44113            p_application_id           => p_application_id
44114          , p_ae_header_id             => l_ae_header_id 
44115 , p_source_3 => p_source_3
44116 , p_source_30 => p_source_30
44117          , x_transaction_coa_id       => l_adr_transaction_coa_id
44118          , x_accounting_coa_id        => l_adr_accounting_coa_id
44119          , x_value_type_code          => l_adr_value_type_code
44120          , p_side                     => 'NA'
44121    );
44122 
44123    xla_ae_lines_pkg.set_ccid(
44124     p_code_combination_id          => l_ccid
44125   , p_value_type_code              => l_adr_value_type_code
44126   , p_transaction_coa_id           => l_adr_transaction_coa_id
44127   , p_accounting_coa_id            => l_adr_accounting_coa_id
44128   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
44129   , p_adr_type_code                => 'S'
44130   , p_component_type               => l_component_type
44131   , p_component_code               => l_component_code
44132   , p_component_type_code          => l_component_type_code
44133   , p_component_appl_id            => l_component_appl_id
44134   , p_amb_context_code             => l_amb_context_code
44135   , p_side                         => 'NA'
44136   );
44137 
44138 
44139    l_segment := AcctDerRule_153(
44140            p_application_id           => p_application_id
44141          , p_ae_header_id             => l_ae_header_id 
44142 , p_source_3 => p_source_3
44143 , p_source_14 => p_source_14
44144          , x_transaction_coa_id       => l_adr_transaction_coa_id
44145          , x_accounting_coa_id        => l_adr_accounting_coa_id
44146          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
44150          , x_value_segment_code       => l_adr_value_segment_code
44147          , x_flex_value_set_id        => l_adr_flex_value_set_id
44148          , x_value_type_code          => l_adr_value_type_code
44149          , x_value_combination_id     => l_adr_value_combination_id
44151          , p_side                     => 'NA'
44152          , p_override_seg_flag        => 'Y'
44153    );
44154 
44155    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
44156 
44157       xla_ae_lines_pkg.set_segment(
44158           p_to_segment_code         => 'GL_ACCOUNT'
44159         , p_segment_value           => l_segment
44160         , p_from_segment_code       => l_adr_value_segment_code
44161         , p_from_combination_id     => l_adr_value_combination_id
44162         , p_value_type_code         => l_adr_value_type_code
44163         , p_transaction_coa_id      => l_adr_transaction_coa_id
44164         , p_accounting_coa_id       => l_adr_accounting_coa_id
44165         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
44166         , p_flex_value_set_id       => l_adr_flex_value_set_id
44167         , p_adr_code                => 'FA_COST_OF_REM_LOSS_SEGMENT'
44168         , p_adr_type_code           => 'S'
44169         , p_component_type          => l_component_type
44170         , p_component_code          => l_component_code
44171         , p_component_type_code     => l_component_type_code
44172         , p_component_appl_id       => l_component_appl_id
44173         , p_amb_context_code        => l_amb_context_code
44174         , p_entity_code             => 'TRANSACTIONS'
44175         , p_event_class_code        => 'CIP_RETIREMENTS'
44176         , p_side                    => 'NA'
44177         );
44178 
44179   END IF;
44180 
44181    l_segment := AcctDerRule_168(
44182            p_application_id           => p_application_id
44183          , p_ae_header_id             => l_ae_header_id 
44184 , p_source_3 => p_source_3
44185 , p_source_29 => p_source_29
44186          , x_transaction_coa_id       => l_adr_transaction_coa_id
44187          , x_accounting_coa_id        => l_adr_accounting_coa_id
44188          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
44189          , x_flex_value_set_id        => l_adr_flex_value_set_id
44190          , x_value_type_code          => l_adr_value_type_code
44191          , x_value_combination_id     => l_adr_value_combination_id
44192          , x_value_segment_code       => l_adr_value_segment_code
44193          , p_side                     => 'NA'
44194          , p_override_seg_flag        => 'Y'
44195    );
44196 
44197    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
44198 
44199       xla_ae_lines_pkg.set_segment(
44200           p_to_segment_code         => 'GL_BALANCING'
44201         , p_segment_value           => l_segment
44202         , p_from_segment_code       => l_adr_value_segment_code
44203         , p_from_combination_id     => l_adr_value_combination_id
44204         , p_value_type_code         => l_adr_value_type_code
44205         , p_transaction_coa_id      => l_adr_transaction_coa_id
44206         , p_accounting_coa_id       => l_adr_accounting_coa_id
44207         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
44208         , p_flex_value_set_id       => l_adr_flex_value_set_id
44209         , p_adr_code                => 'FA_EXPENSE_ACCT'
44210         , p_adr_type_code           => 'S'
44211         , p_component_type          => l_component_type
44212         , p_component_code          => l_component_code
44213         , p_component_type_code     => l_component_type_code
44214         , p_component_appl_id       => l_component_appl_id
44215         , p_amb_context_code        => l_amb_context_code
44216         , p_entity_code             => 'TRANSACTIONS'
44217         , p_event_class_code        => 'CIP_RETIREMENTS'
44218         , p_side                    => 'NA'
44219         );
44220 
44221   END IF;
44222 
44223    --
44224    --
44225    END IF;
44226    --
44227    -- Bug 4922099
44228    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
44229           (NVL(l_enc_upg_option, 'N') = 'O')
44230         ) AND
44231         (l_bflow_method_code = 'PRIOR_ENTRY')
44232       )
44233    THEN
44234       IF
44235       --
44236       1 = 2
44237       --
44238       THEN
44239       xla_accounting_err_pkg.build_message
44240                                     (p_appli_s_name            => 'XLA'
44241                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
44242                                     ,p_token_1                 => 'LINE_NUMBER'
44243                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
44244                                     ,p_token_2                 => 'LINE_TYPE_NAME'
44245                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
44246                                                                              l_component_type
44247                                                                             ,l_component_code
44248                                                                             ,l_component_type_code
44249                                                                             ,l_component_appl_id
44250                                                                             ,l_amb_context_code
44251                                                                             ,l_entity_code
44252                                                                             ,l_event_class_code
44253                                                                            )
44254                                     ,p_token_3                 => 'OWNER'
44255                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
44256                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
44260                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
44257                                                                           ,p_lookup_code    => l_component_type_code
44258                                                                          )
44259                                     ,p_token_4                 => 'PRODUCT_NAME'
44261                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
44262                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
44263                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
44264                                     ,p_ae_header_id            =>  NULL
44265                                        );
44266 
44267         IF (C_LEVEL_ERROR>= g_log_level) THEN
44268                  trace
44269                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
44270                       ,p_level    => C_LEVEL_ERROR
44271                       ,p_module   => l_log_module);
44272         END IF;
44273       END IF;
44274    END IF;
44275    --
44276    --
44277    ------------------------------------------------------------------------------------------------
44278    -- 4219869 Business Flow
44279    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
44280    -- Prior Entry.  Currently, the following code is always generated.
44281    ------------------------------------------------------------------------------------------------
44282    XLA_AE_LINES_PKG.ValidateCurrentLine;
44283 
44284    ------------------------------------------------------------------------------------
44285    -- 4219869 Business Flow
44286    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
44287    ------------------------------------------------------------------------------------
44288    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
44289 
44290    ----------------------------------------------------------------------------------
44291    -- 4219869 Business Flow
44292    -- Update journal entry status -- Need to generate this within IF <condition>
44293    ----------------------------------------------------------------------------------
44294    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
44295          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
44296          ,p_balance_type_code => l_balance_type_code
44297          );
44298 
44299    -------------------------------------------------------------------------------------------
44300    -- 4262811 - Generate the Accrual Reversal lines
44301    -------------------------------------------------------------------------------------------
44302    BEGIN
44303       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
44304                               (g_array_event(p_event_id).array_value_num('header_index'));
44305       IF l_acc_rev_flag IS NULL THEN
44306          l_acc_rev_flag := 'N';
44307       END IF;
44308    EXCEPTION
44309       WHEN OTHERS THEN
44310          l_acc_rev_flag := 'N';
44311    END;
44312    --
44313    IF (l_acc_rev_flag = 'Y') THEN
44314 
44315        -- 4645092  ------------------------------------------------------------------------------
44316        -- To allow MPA report to determine if it should generate report process
44317        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
44318        ------------------------------------------------------------------------------------------
44319 
44320        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
44321        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
44322    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
44323    -- call ADRs
44324    -- Bug 4922099
44325    --
44326    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
44327         (NVL(l_actual_upg_option, 'N') = 'O') OR
44328         (NVL(l_enc_upg_option, 'N') = 'O')
44329       )
44330    THEN
44331    NULL;
44332    --
44333    --
44334    
44335   l_ccid := AcctDerRule_173(
44336            p_application_id           => p_application_id
44337          , p_ae_header_id             => l_ae_header_id 
44338 , p_source_3 => p_source_3
44339 , p_source_30 => p_source_30
44340          , x_transaction_coa_id       => l_adr_transaction_coa_id
44341          , x_accounting_coa_id        => l_adr_accounting_coa_id
44342          , x_value_type_code          => l_adr_value_type_code
44343          , p_side                     => 'NA'
44344    );
44345 
44346    xla_ae_lines_pkg.set_ccid(
44347     p_code_combination_id          => l_ccid
44348   , p_value_type_code              => l_adr_value_type_code
44349   , p_transaction_coa_id           => l_adr_transaction_coa_id
44350   , p_accounting_coa_id            => l_adr_accounting_coa_id
44351   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
44352   , p_adr_type_code                => 'S'
44353   , p_component_type               => l_component_type
44354   , p_component_code               => l_component_code
44355   , p_component_type_code          => l_component_type_code
44356   , p_component_appl_id            => l_component_appl_id
44357   , p_amb_context_code             => l_amb_context_code
44358   , p_side                         => 'NA'
44359   );
44360 
44361 
44362    l_segment := AcctDerRule_153(
44363            p_application_id           => p_application_id
44364          , p_ae_header_id             => l_ae_header_id 
44365 , p_source_3 => p_source_3
44366 , p_source_14 => p_source_14
44367          , x_transaction_coa_id       => l_adr_transaction_coa_id
44368          , x_accounting_coa_id        => l_adr_accounting_coa_id
44369          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
44370          , x_flex_value_set_id        => l_adr_flex_value_set_id
44374          , p_side                     => 'NA'
44371          , x_value_type_code          => l_adr_value_type_code
44372          , x_value_combination_id     => l_adr_value_combination_id
44373          , x_value_segment_code       => l_adr_value_segment_code
44375          , p_override_seg_flag        => 'Y'
44376    );
44377 
44378    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
44379 
44380       xla_ae_lines_pkg.set_segment(
44381           p_to_segment_code         => 'GL_ACCOUNT'
44382         , p_segment_value           => l_segment
44383         , p_from_segment_code       => l_adr_value_segment_code
44384         , p_from_combination_id     => l_adr_value_combination_id
44385         , p_value_type_code         => l_adr_value_type_code
44386         , p_transaction_coa_id      => l_adr_transaction_coa_id
44387         , p_accounting_coa_id       => l_adr_accounting_coa_id
44388         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
44389         , p_flex_value_set_id       => l_adr_flex_value_set_id
44390         , p_adr_code                => 'FA_COST_OF_REM_LOSS_SEGMENT'
44391         , p_adr_type_code           => 'S'
44392         , p_component_type          => l_component_type
44393         , p_component_code          => l_component_code
44394         , p_component_type_code     => l_component_type_code
44395         , p_component_appl_id       => l_component_appl_id
44396         , p_amb_context_code        => l_amb_context_code
44397         , p_entity_code             => 'TRANSACTIONS'
44398         , p_event_class_code        => 'CIP_RETIREMENTS'
44399         , p_side                    => 'NA'
44400         );
44401 
44402   END IF;
44403 
44404    l_segment := AcctDerRule_168(
44405            p_application_id           => p_application_id
44406          , p_ae_header_id             => l_ae_header_id 
44407 , p_source_3 => p_source_3
44408 , p_source_29 => p_source_29
44409          , x_transaction_coa_id       => l_adr_transaction_coa_id
44410          , x_accounting_coa_id        => l_adr_accounting_coa_id
44411          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
44412          , x_flex_value_set_id        => l_adr_flex_value_set_id
44413          , x_value_type_code          => l_adr_value_type_code
44414          , x_value_combination_id     => l_adr_value_combination_id
44415          , x_value_segment_code       => l_adr_value_segment_code
44416          , p_side                     => 'NA'
44417          , p_override_seg_flag        => 'Y'
44418    );
44419 
44420    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
44421 
44422       xla_ae_lines_pkg.set_segment(
44423           p_to_segment_code         => 'GL_BALANCING'
44424         , p_segment_value           => l_segment
44425         , p_from_segment_code       => l_adr_value_segment_code
44426         , p_from_combination_id     => l_adr_value_combination_id
44427         , p_value_type_code         => l_adr_value_type_code
44428         , p_transaction_coa_id      => l_adr_transaction_coa_id
44429         , p_accounting_coa_id       => l_adr_accounting_coa_id
44430         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
44431         , p_flex_value_set_id       => l_adr_flex_value_set_id
44432         , p_adr_code                => 'FA_EXPENSE_ACCT'
44433         , p_adr_type_code           => 'S'
44434         , p_component_type          => l_component_type
44435         , p_component_code          => l_component_code
44436         , p_component_type_code     => l_component_type_code
44437         , p_component_appl_id       => l_component_appl_id
44438         , p_amb_context_code        => l_amb_context_code
44439         , p_entity_code             => 'TRANSACTIONS'
44440         , p_event_class_code        => 'CIP_RETIREMENTS'
44441         , p_side                    => 'NA'
44442         );
44443 
44444   END IF;
44445 
44446    --
44447    --
44448    END IF;
44449 
44450        --
44451        -- Update the line information that should be overwritten
44452        --
44453        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
44454                                          p_header_num   => 1);
44455        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
44456 
44457        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
44458 
44459        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
44460           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
44461        END IF;
44462 
44463       --
44464       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
44465       --
44466       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
44467           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
44468       ELSE
44469           ---------------------------------------------------------------------------------------------------
44470           -- 4262811a Switch Sign
44471           ---------------------------------------------------------------------------------------------------
44472           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
44473           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44474                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44475           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44476                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44477           -- 5132302
44478           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
44479                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44480 
44484       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
44481       END IF;
44482 
44483       -- 4955764
44485       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
44486 
44487 
44488       XLA_AE_LINES_PKG.ValidateCurrentLine;
44489       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
44490 
44491       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
44492                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
44493                ,p_balance_type_code => l_balance_type_code);
44494 
44495    END IF;
44496 
44497    -----------------------------------------------------------------------------------------
44498    -- 4262811 Multiperiod Accounting
44499    -----------------------------------------------------------------------------------------
44500      -- No MPA option is assigned.
44501 
44502 
44503 END IF;
44504 END IF;
44505 --
44506 
44507 --
44508 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44509    trace
44510       (p_msg      => 'END of AcctLineType_216'
44511       ,p_level    => C_LEVEL_PROCEDURE
44512       ,p_module   => l_log_module);
44513 END IF;
44514 --
44515 EXCEPTION
44516   WHEN xla_exceptions_pkg.application_exception THEN
44517       RAISE;
44518   WHEN OTHERS THEN
44519        xla_exceptions_pkg.raise_message
44520            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_216');
44521 END AcctLineType_216;
44522 --
44523 
44524 ---------------------------------------
44525 --
44526 -- PRIVATE FUNCTION
44527 --         AcctLineType_217
44528 --
44529 ---------------------------------------
44530 PROCEDURE AcctLineType_217 (
44531   p_application_id        IN NUMBER
44532  ,p_event_id              IN NUMBER
44533  ,p_calculate_acctd_flag  IN VARCHAR2
44534  ,p_calculate_g_l_flag    IN VARCHAR2
44535  ,p_actual_flag           IN OUT VARCHAR2
44536  ,p_balance_type_code     OUT VARCHAR2
44537  ,p_gain_or_loss_ref      OUT VARCHAR2
44538  
44539 --Period Close Date
44540  , p_source_1            IN DATE
44541 --Generated Code Combination Identifier
44542  , p_source_3            IN NUMBER
44543 --Net Book Value Retired Gain Account
44544  , p_source_21            IN VARCHAR2
44545 --Expense Account Code Combination Identifier
44546  , p_source_29            IN NUMBER
44547 --Default Code Combination Identifier
44548  , p_source_30            IN NUMBER
44549 --Adjustment Type
44550  , p_source_35            IN VARCHAR2
44551 --Transaction Header Identifier
44552  , p_source_36            IN NUMBER
44553 --Adjustment Line Identifier
44554  , p_source_37            IN NUMBER
44555 --Distribution Type Code
44556  , p_source_38            IN VARCHAR2
44557 --Entered Amount
44558  , p_source_39            IN NUMBER
44559 --Currency Code
44560  , p_source_40            IN VARCHAR2
44561 --Gain Loss Amount
44562  , p_source_41            IN NUMBER
44563 )
44564 IS
44565 
44566 l_component_type              VARCHAR2(80);
44567 l_component_code              VARCHAR2(30);
44568 l_component_type_code         VARCHAR2(1);
44569 l_component_appl_id           INTEGER;
44570 l_amb_context_code            VARCHAR2(30);
44571 l_entity_code                 VARCHAR2(30);
44572 l_event_class_code            VARCHAR2(30);
44573 l_ae_header_id                NUMBER;
44574 l_event_type_code             VARCHAR2(30);
44575 l_line_definition_code        VARCHAR2(30);
44576 l_line_definition_owner_code  VARCHAR2(1);
44577 --
44578 -- adr variables
44579 l_segment                     VARCHAR2(30);
44580 l_ccid                        NUMBER;
44581 l_adr_transaction_coa_id      NUMBER;
44582 l_adr_accounting_coa_id       NUMBER;
44583 l_adr_flexfield_segment_code  VARCHAR2(30);
44584 l_adr_flex_value_set_id       NUMBER;
44585 l_adr_value_type_code         VARCHAR2(30);
44586 l_adr_value_combination_id    NUMBER;
44587 l_adr_value_segment_code      VARCHAR2(30);
44588 
44589 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
44590 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
44591 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
44592 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
44593 
44594 -- 4262811 Variables ------------------------------------------------------------------------------------------
44595 l_entered_amt_idx             NUMBER;
44596 l_accted_amt_idx              NUMBER;
44597 l_acc_rev_flag                VARCHAR2(1);
44598 l_accrual_line_num            NUMBER;
44599 l_tmp_amt                     NUMBER;
44600 l_acc_rev_natural_side_code   VARCHAR2(1);
44601 
44602 l_num_entries                 NUMBER;
44603 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
44604 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
44605 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
44606 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
44607 l_recog_line_1                NUMBER;
44608 l_recog_line_2                NUMBER;
44609 
44610 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
44611 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
44612 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
44613 
44614 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
44615 
44616 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
44617 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
44618 
44619 ---------------------------------------------------------------------------------------------------------------
44620 
44621 
44622 --
44626 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
44623 -- bulk performance
44624 --
44625 l_balance_type_code           VARCHAR2(1);
44627 l_log_module                  VARCHAR2(240);
44628 
44629 --
44630 -- Upgrade strategy
44631 --
44632 l_actual_upg_option           VARCHAR2(1);
44633 l_enc_upg_option           VARCHAR2(1);
44634 
44635 --
44636 BEGIN
44637 --
44638 IF g_log_enabled THEN
44639       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_217';
44640 END IF;
44641 --
44642 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44643 
44644       trace
44645          (p_msg      => 'BEGIN of AcctLineType_217'
44646          ,p_level    => C_LEVEL_PROCEDURE
44647          ,p_module   => l_log_module);
44648 
44649 END IF;
44650 --
44651 l_component_type             := 'AMB_JLT';
44652 l_component_code             := 'FA_CIP_NBV_RETIRED_GAIN';
44653 l_component_type_code        := 'S';
44654 l_component_appl_id          :=  140;
44655 l_amb_context_code           := 'DEFAULT';
44656 l_entity_code                := 'TRANSACTIONS';
44657 l_event_class_code           := 'CIP_RETIREMENTS';
44658 l_event_type_code            := 'CIP_RETIREMENTS';
44659 l_line_definition_owner_code := 'S';
44660 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
44661 --
44662 l_balance_type_code          := 'A';
44663 l_segment                     := NULL;
44664 l_ccid                        := NULL;
44665 l_adr_transaction_coa_id      := NULL;
44666 l_adr_accounting_coa_id       := NULL;
44667 l_adr_flexfield_segment_code  := NULL;
44668 l_adr_flex_value_set_id       := NULL;
44669 l_adr_value_type_code         := NULL;
44670 l_adr_value_combination_id    := NULL;
44671 l_adr_value_segment_code      := NULL;
44672 
44673 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
44674 l_bflow_class_code           := '';    -- 4219869 Business Flow
44675 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
44676 l_budgetary_control_flag     := 'N';
44677 
44678 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
44679 l_bflow_applied_to_amt       := NULL; -- 5132302
44680 l_entered_amt_idx            := NULL;          -- 4262811
44681 l_accted_amt_idx             := NULL;          -- 4262811
44682 l_acc_rev_flag               := NULL;          -- 4262811
44683 l_accrual_line_num           := NULL;          -- 4262811
44684 l_tmp_amt                    := NULL;          -- 4262811
44685 --
44686  
44687 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
44688     l_balance_type_code <> 'B' THEN
44689 IF NVL(p_source_35,'
44690 ') =  'NBV RETIRED' AND 
44691 p_source_41 >=  0
44692  THEN 
44693 
44694    --
44695    XLA_AE_LINES_PKG.SetNewLine;
44696 
44697    p_balance_type_code          := l_balance_type_code;
44698    -- set the flag so later we will know whether the gain loss line needs to be created
44699    
44700    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
44701      p_actual_flag :='A';
44702    END IF;
44703 
44704    --
44705    -- bulk performance
44706    --
44707    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
44708                                       p_header_num   => 0); -- 4262811
44709    --
44710    -- set accounting line options
44711    --
44712    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
44713            p_natural_side_code          => 'D'
44714          , p_gain_or_loss_flag          => 'N'
44715          , p_gl_transfer_mode_code      => 'S'
44716          , p_acct_entry_type_code       => 'A'
44717          , p_switch_side_flag           => 'Y'
44718          , p_merge_duplicate_code       => 'N'
44719          );
44720    --
44721    l_acc_rev_natural_side_code := 'C';  -- 4262811
44722    -- 
44723    --
44724    -- set accounting line type info
44725    --
44726    xla_ae_lines_pkg.SetAcctLineType
44727       (p_component_type             => l_component_type
44728       ,p_event_type_code            => l_event_type_code
44729       ,p_line_definition_owner_code => l_line_definition_owner_code
44730       ,p_line_definition_code       => l_line_definition_code
44731       ,p_accounting_line_code       => l_component_code
44732       ,p_accounting_line_type_code  => l_component_type_code
44733       ,p_accounting_line_appl_id    => l_component_appl_id
44734       ,p_amb_context_code           => l_amb_context_code
44735       ,p_entity_code                => l_entity_code
44736       ,p_event_class_code           => l_event_class_code);
44737    --
44738    -- set accounting class
44739    --
44740    xla_ae_lines_pkg.SetAcctClass(
44741            p_accounting_class_code  => 'ASSET'
44742          , p_ae_header_id           => l_ae_header_id
44743          );
44744 
44745    --
44746    -- set rounding class
44747    --
44748    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
44749                       'ASSET';
44750 
44751    --
44752    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
44753    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
44754    --
44755    -- bulk performance
44756    --
44757    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
44758 
44759    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
44760       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
44761 
44762    -- 4955764
44763    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
44764       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
44765 
44769    -- set accounting attributes for the line type
44766    -- 4458381 Public Sector Enh
44767    
44768    --
44770    --
44771    l_entered_amt_idx := 4;
44772    l_accted_amt_idx  := 6;
44773    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
44774    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
44775    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
44776    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
44777    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
44778    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
44779    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
44780    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
44781    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
44782    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
44783    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
44784    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
44785    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
44786 
44787    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
44788    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
44789 
44790    ---------------------------------------------------------------------------------------------------------------
44791    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
44792    ---------------------------------------------------------------------------------------------------------------
44793    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
44794 
44795    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
44796    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
44797 
44798    IF xla_accounting_cache_pkg.GetValueChar
44799          (p_source_code         => 'LEDGER_CATEGORY_CODE'
44800          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
44801    AND l_bflow_method_code = 'PRIOR_ENTRY'
44802 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
44803    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
44804          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
44805        )
44806    THEN
44807          xla_ae_lines_pkg.BflowUpgEntry
44808            (p_business_method_code    => l_bflow_method_code
44809            ,p_business_class_code     => l_bflow_class_code
44810            ,p_balance_type            => l_balance_type_code);
44811    ELSE
44812       NULL;
44813 -- No business flow processing for business flow method of NONE.
44814    END IF;
44815 
44816    --
44817    -- call analytical criteria
44818    --
44819    
44820    --
44821    -- call description
44822    --
44823    
44824 xla_ae_lines_pkg.SetLineDescription(
44825    p_ae_header_id => l_ae_header_id
44826   ,p_description  => Description_34 (
44827      p_application_id         => p_application_id
44828    , p_ae_header_id           => l_ae_header_id 
44829 , p_source_1 => p_source_1
44830    )
44831 );
44832 
44833 
44834    --
44835    -- call ADRs
44836    -- Bug 4922099
44837    --
44838    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
44839         (NVL(l_actual_upg_option, 'N') = 'O') OR
44840         (NVL(l_enc_upg_option, 'N') = 'O')
44841       )
44842    THEN
44843    NULL;
44844    --
44845    --
44846    
44847   l_ccid := AcctDerRule_173(
44848            p_application_id           => p_application_id
44849          , p_ae_header_id             => l_ae_header_id 
44850 , p_source_3 => p_source_3
44851 , p_source_30 => p_source_30
44852          , x_transaction_coa_id       => l_adr_transaction_coa_id
44853          , x_accounting_coa_id        => l_adr_accounting_coa_id
44854          , x_value_type_code          => l_adr_value_type_code
44855          , p_side                     => 'NA'
44856    );
44857 
44858    xla_ae_lines_pkg.set_ccid(
44859     p_code_combination_id          => l_ccid
44860   , p_value_type_code              => l_adr_value_type_code
44861   , p_transaction_coa_id           => l_adr_transaction_coa_id
44862   , p_accounting_coa_id            => l_adr_accounting_coa_id
44863   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
44864   , p_adr_type_code                => 'S'
44865   , p_component_type               => l_component_type
44866   , p_component_code               => l_component_code
44867   , p_component_type_code          => l_component_type_code
44868   , p_component_appl_id            => l_component_appl_id
44869   , p_amb_context_code             => l_amb_context_code
44870   , p_side                         => 'NA'
44871   );
44872 
44873 
44874    l_segment := AcctDerRule_168(
44875            p_application_id           => p_application_id
44876          , p_ae_header_id             => l_ae_header_id 
44877 , p_source_3 => p_source_3
44878 , p_source_29 => p_source_29
44879          , x_transaction_coa_id       => l_adr_transaction_coa_id
44880          , x_accounting_coa_id        => l_adr_accounting_coa_id
44881          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
44882          , x_flex_value_set_id        => l_adr_flex_value_set_id
44883          , x_value_type_code          => l_adr_value_type_code
44884          , x_value_combination_id     => l_adr_value_combination_id
44885          , x_value_segment_code       => l_adr_value_segment_code
44886          , p_side                     => 'NA'
44887          , p_override_seg_flag        => 'Y'
44888    );
44889 
44890    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
44891 
44892       xla_ae_lines_pkg.set_segment(
44893           p_to_segment_code         => 'GL_BALANCING'
44897         , p_value_type_code         => l_adr_value_type_code
44894         , p_segment_value           => l_segment
44895         , p_from_segment_code       => l_adr_value_segment_code
44896         , p_from_combination_id     => l_adr_value_combination_id
44898         , p_transaction_coa_id      => l_adr_transaction_coa_id
44899         , p_accounting_coa_id       => l_adr_accounting_coa_id
44900         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
44901         , p_flex_value_set_id       => l_adr_flex_value_set_id
44902         , p_adr_code                => 'FA_EXPENSE_ACCT'
44903         , p_adr_type_code           => 'S'
44904         , p_component_type          => l_component_type
44905         , p_component_code          => l_component_code
44906         , p_component_type_code     => l_component_type_code
44907         , p_component_appl_id       => l_component_appl_id
44908         , p_amb_context_code        => l_amb_context_code
44909         , p_entity_code             => 'TRANSACTIONS'
44910         , p_event_class_code        => 'CIP_RETIREMENTS'
44911         , p_side                    => 'NA'
44912         );
44913 
44914   END IF;
44915 
44916    l_segment := AcctDerRule_159(
44917            p_application_id           => p_application_id
44918          , p_ae_header_id             => l_ae_header_id 
44919 , p_source_3 => p_source_3
44920 , p_source_21 => p_source_21
44921          , x_transaction_coa_id       => l_adr_transaction_coa_id
44922          , x_accounting_coa_id        => l_adr_accounting_coa_id
44923          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
44924          , x_flex_value_set_id        => l_adr_flex_value_set_id
44925          , x_value_type_code          => l_adr_value_type_code
44926          , x_value_combination_id     => l_adr_value_combination_id
44927          , x_value_segment_code       => l_adr_value_segment_code
44928          , p_side                     => 'NA'
44929          , p_override_seg_flag        => 'Y'
44930    );
44931 
44932    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
44933 
44934       xla_ae_lines_pkg.set_segment(
44935           p_to_segment_code         => 'GL_ACCOUNT'
44936         , p_segment_value           => l_segment
44937         , p_from_segment_code       => l_adr_value_segment_code
44938         , p_from_combination_id     => l_adr_value_combination_id
44939         , p_value_type_code         => l_adr_value_type_code
44940         , p_transaction_coa_id      => l_adr_transaction_coa_id
44941         , p_accounting_coa_id       => l_adr_accounting_coa_id
44942         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
44943         , p_flex_value_set_id       => l_adr_flex_value_set_id
44944         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
44945         , p_adr_type_code           => 'S'
44946         , p_component_type          => l_component_type
44947         , p_component_code          => l_component_code
44948         , p_component_type_code     => l_component_type_code
44949         , p_component_appl_id       => l_component_appl_id
44950         , p_amb_context_code        => l_amb_context_code
44951         , p_entity_code             => 'TRANSACTIONS'
44952         , p_event_class_code        => 'CIP_RETIREMENTS'
44953         , p_side                    => 'NA'
44954         );
44955 
44956   END IF;
44957 
44958    --
44959    --
44960    END IF;
44961    --
44962    -- Bug 4922099
44963    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
44964           (NVL(l_enc_upg_option, 'N') = 'O')
44965         ) AND
44966         (l_bflow_method_code = 'PRIOR_ENTRY')
44967       )
44968    THEN
44969       IF
44970       --
44971       1 = 2
44972       --
44973       THEN
44974       xla_accounting_err_pkg.build_message
44975                                     (p_appli_s_name            => 'XLA'
44976                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
44977                                     ,p_token_1                 => 'LINE_NUMBER'
44978                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
44979                                     ,p_token_2                 => 'LINE_TYPE_NAME'
44980                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
44981                                                                              l_component_type
44982                                                                             ,l_component_code
44983                                                                             ,l_component_type_code
44984                                                                             ,l_component_appl_id
44985                                                                             ,l_amb_context_code
44986                                                                             ,l_entity_code
44987                                                                             ,l_event_class_code
44988                                                                            )
44989                                     ,p_token_3                 => 'OWNER'
44990                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
44991                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
44992                                                                           ,p_lookup_code    => l_component_type_code
44993                                                                          )
44994                                     ,p_token_4                 => 'PRODUCT_NAME'
44995                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
44996                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
44997                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
45001 
44998                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
44999                                     ,p_ae_header_id            =>  NULL
45000                                        );
45002         IF (C_LEVEL_ERROR>= g_log_level) THEN
45003                  trace
45004                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45005                       ,p_level    => C_LEVEL_ERROR
45006                       ,p_module   => l_log_module);
45007         END IF;
45008       END IF;
45009    END IF;
45010    --
45011    --
45012    ------------------------------------------------------------------------------------------------
45013    -- 4219869 Business Flow
45014    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
45015    -- Prior Entry.  Currently, the following code is always generated.
45016    ------------------------------------------------------------------------------------------------
45017    XLA_AE_LINES_PKG.ValidateCurrentLine;
45018 
45019    ------------------------------------------------------------------------------------
45020    -- 4219869 Business Flow
45021    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
45022    ------------------------------------------------------------------------------------
45023    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45024 
45025    ----------------------------------------------------------------------------------
45026    -- 4219869 Business Flow
45027    -- Update journal entry status -- Need to generate this within IF <condition>
45028    ----------------------------------------------------------------------------------
45029    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45030          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
45031          ,p_balance_type_code => l_balance_type_code
45032          );
45033 
45034    -------------------------------------------------------------------------------------------
45035    -- 4262811 - Generate the Accrual Reversal lines
45036    -------------------------------------------------------------------------------------------
45037    BEGIN
45038       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
45039                               (g_array_event(p_event_id).array_value_num('header_index'));
45040       IF l_acc_rev_flag IS NULL THEN
45041          l_acc_rev_flag := 'N';
45042       END IF;
45043    EXCEPTION
45044       WHEN OTHERS THEN
45045          l_acc_rev_flag := 'N';
45046    END;
45047    --
45048    IF (l_acc_rev_flag = 'Y') THEN
45049 
45050        -- 4645092  ------------------------------------------------------------------------------
45051        -- To allow MPA report to determine if it should generate report process
45052        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
45053        ------------------------------------------------------------------------------------------
45054 
45055        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
45056        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
45057    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
45058    -- call ADRs
45059    -- Bug 4922099
45060    --
45061    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45062         (NVL(l_actual_upg_option, 'N') = 'O') OR
45063         (NVL(l_enc_upg_option, 'N') = 'O')
45064       )
45065    THEN
45066    NULL;
45067    --
45068    --
45069    
45070   l_ccid := AcctDerRule_173(
45071            p_application_id           => p_application_id
45072          , p_ae_header_id             => l_ae_header_id 
45073 , p_source_3 => p_source_3
45074 , p_source_30 => p_source_30
45075          , x_transaction_coa_id       => l_adr_transaction_coa_id
45076          , x_accounting_coa_id        => l_adr_accounting_coa_id
45077          , x_value_type_code          => l_adr_value_type_code
45078          , p_side                     => 'NA'
45079    );
45080 
45081    xla_ae_lines_pkg.set_ccid(
45082     p_code_combination_id          => l_ccid
45083   , p_value_type_code              => l_adr_value_type_code
45084   , p_transaction_coa_id           => l_adr_transaction_coa_id
45085   , p_accounting_coa_id            => l_adr_accounting_coa_id
45086   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
45087   , p_adr_type_code                => 'S'
45088   , p_component_type               => l_component_type
45089   , p_component_code               => l_component_code
45090   , p_component_type_code          => l_component_type_code
45091   , p_component_appl_id            => l_component_appl_id
45092   , p_amb_context_code             => l_amb_context_code
45093   , p_side                         => 'NA'
45094   );
45095 
45096 
45097    l_segment := AcctDerRule_168(
45098            p_application_id           => p_application_id
45099          , p_ae_header_id             => l_ae_header_id 
45100 , p_source_3 => p_source_3
45101 , p_source_29 => p_source_29
45102          , x_transaction_coa_id       => l_adr_transaction_coa_id
45103          , x_accounting_coa_id        => l_adr_accounting_coa_id
45104          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
45105          , x_flex_value_set_id        => l_adr_flex_value_set_id
45106          , x_value_type_code          => l_adr_value_type_code
45107          , x_value_combination_id     => l_adr_value_combination_id
45108          , x_value_segment_code       => l_adr_value_segment_code
45109          , p_side                     => 'NA'
45110          , p_override_seg_flag        => 'Y'
45111    );
45112 
45113    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
45114 
45115       xla_ae_lines_pkg.set_segment(
45116           p_to_segment_code         => 'GL_BALANCING'
45117         , p_segment_value           => l_segment
45121         , p_transaction_coa_id      => l_adr_transaction_coa_id
45118         , p_from_segment_code       => l_adr_value_segment_code
45119         , p_from_combination_id     => l_adr_value_combination_id
45120         , p_value_type_code         => l_adr_value_type_code
45122         , p_accounting_coa_id       => l_adr_accounting_coa_id
45123         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
45124         , p_flex_value_set_id       => l_adr_flex_value_set_id
45125         , p_adr_code                => 'FA_EXPENSE_ACCT'
45126         , p_adr_type_code           => 'S'
45127         , p_component_type          => l_component_type
45128         , p_component_code          => l_component_code
45129         , p_component_type_code     => l_component_type_code
45130         , p_component_appl_id       => l_component_appl_id
45131         , p_amb_context_code        => l_amb_context_code
45132         , p_entity_code             => 'TRANSACTIONS'
45133         , p_event_class_code        => 'CIP_RETIREMENTS'
45134         , p_side                    => 'NA'
45135         );
45136 
45137   END IF;
45138 
45139    l_segment := AcctDerRule_159(
45140            p_application_id           => p_application_id
45141          , p_ae_header_id             => l_ae_header_id 
45142 , p_source_3 => p_source_3
45143 , p_source_21 => p_source_21
45144          , x_transaction_coa_id       => l_adr_transaction_coa_id
45145          , x_accounting_coa_id        => l_adr_accounting_coa_id
45146          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
45147          , x_flex_value_set_id        => l_adr_flex_value_set_id
45148          , x_value_type_code          => l_adr_value_type_code
45149          , x_value_combination_id     => l_adr_value_combination_id
45150          , x_value_segment_code       => l_adr_value_segment_code
45151          , p_side                     => 'NA'
45152          , p_override_seg_flag        => 'Y'
45153    );
45154 
45155    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
45156 
45157       xla_ae_lines_pkg.set_segment(
45158           p_to_segment_code         => 'GL_ACCOUNT'
45159         , p_segment_value           => l_segment
45160         , p_from_segment_code       => l_adr_value_segment_code
45161         , p_from_combination_id     => l_adr_value_combination_id
45162         , p_value_type_code         => l_adr_value_type_code
45163         , p_transaction_coa_id      => l_adr_transaction_coa_id
45164         , p_accounting_coa_id       => l_adr_accounting_coa_id
45165         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
45166         , p_flex_value_set_id       => l_adr_flex_value_set_id
45167         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
45168         , p_adr_type_code           => 'S'
45169         , p_component_type          => l_component_type
45170         , p_component_code          => l_component_code
45171         , p_component_type_code     => l_component_type_code
45172         , p_component_appl_id       => l_component_appl_id
45173         , p_amb_context_code        => l_amb_context_code
45174         , p_entity_code             => 'TRANSACTIONS'
45175         , p_event_class_code        => 'CIP_RETIREMENTS'
45176         , p_side                    => 'NA'
45177         );
45178 
45179   END IF;
45180 
45181    --
45182    --
45183    END IF;
45184 
45185        --
45186        -- Update the line information that should be overwritten
45187        --
45188        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
45189                                          p_header_num   => 1);
45190        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
45191 
45192        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
45193 
45194        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
45195           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
45196        END IF;
45197 
45198       --
45199       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
45200       --
45201       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
45202           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
45203       ELSE
45204           ---------------------------------------------------------------------------------------------------
45205           -- 4262811a Switch Sign
45206           ---------------------------------------------------------------------------------------------------
45207           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
45208           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45209                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45210           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45211                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45212           -- 5132302
45213           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
45214                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45215 
45216       END IF;
45217 
45218       -- 4955764
45219       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45220       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
45221 
45222 
45223       XLA_AE_LINES_PKG.ValidateCurrentLine;
45224       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45225 
45226       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45227                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
45231 
45228                ,p_balance_type_code => l_balance_type_code);
45229 
45230    END IF;
45232    -----------------------------------------------------------------------------------------
45233    -- 4262811 Multiperiod Accounting
45234    -----------------------------------------------------------------------------------------
45235      -- No MPA option is assigned.
45236 
45237 
45238 END IF;
45239 END IF;
45240 --
45241 
45242 --
45243 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
45244    trace
45245       (p_msg      => 'END of AcctLineType_217'
45246       ,p_level    => C_LEVEL_PROCEDURE
45247       ,p_module   => l_log_module);
45248 END IF;
45249 --
45250 EXCEPTION
45251   WHEN xla_exceptions_pkg.application_exception THEN
45252       RAISE;
45253   WHEN OTHERS THEN
45254        xla_exceptions_pkg.raise_message
45255            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_217');
45256 END AcctLineType_217;
45257 --
45258 
45259 ---------------------------------------
45260 --
45261 -- PRIVATE FUNCTION
45262 --         AcctLineType_218
45263 --
45264 ---------------------------------------
45265 PROCEDURE AcctLineType_218 (
45266   p_application_id        IN NUMBER
45267  ,p_event_id              IN NUMBER
45268  ,p_calculate_acctd_flag  IN VARCHAR2
45269  ,p_calculate_g_l_flag    IN VARCHAR2
45270  ,p_actual_flag           IN OUT VARCHAR2
45271  ,p_balance_type_code     OUT VARCHAR2
45272  ,p_gain_or_loss_ref      OUT VARCHAR2
45273  
45274 --Period Close Date
45275  , p_source_1            IN DATE
45276 --Generated Code Combination Identifier
45277  , p_source_3            IN NUMBER
45278 --Net Book Value Retired Gain Account
45279  , p_source_21            IN VARCHAR2
45280 --Expense Account Code Combination Identifier
45281  , p_source_29            IN NUMBER
45282 --Default Code Combination Identifier
45283  , p_source_30            IN NUMBER
45284 --Adjustment Type
45285  , p_source_35            IN VARCHAR2
45286 --Transaction Header Identifier
45287  , p_source_36            IN NUMBER
45288 --Adjustment Line Identifier
45289  , p_source_37            IN NUMBER
45290 --Distribution Type Code
45291  , p_source_38            IN VARCHAR2
45292 --Entered Amount
45293  , p_source_39            IN NUMBER
45294 --Currency Code
45295  , p_source_40            IN VARCHAR2
45296 --Gain Loss Amount
45297  , p_source_41            IN NUMBER
45298 )
45299 IS
45300 
45301 l_component_type              VARCHAR2(80);
45302 l_component_code              VARCHAR2(30);
45303 l_component_type_code         VARCHAR2(1);
45304 l_component_appl_id           INTEGER;
45305 l_amb_context_code            VARCHAR2(30);
45306 l_entity_code                 VARCHAR2(30);
45307 l_event_class_code            VARCHAR2(30);
45308 l_ae_header_id                NUMBER;
45309 l_event_type_code             VARCHAR2(30);
45310 l_line_definition_code        VARCHAR2(30);
45311 l_line_definition_owner_code  VARCHAR2(1);
45312 --
45313 -- adr variables
45314 l_segment                     VARCHAR2(30);
45315 l_ccid                        NUMBER;
45316 l_adr_transaction_coa_id      NUMBER;
45317 l_adr_accounting_coa_id       NUMBER;
45318 l_adr_flexfield_segment_code  VARCHAR2(30);
45319 l_adr_flex_value_set_id       NUMBER;
45320 l_adr_value_type_code         VARCHAR2(30);
45321 l_adr_value_combination_id    NUMBER;
45322 l_adr_value_segment_code      VARCHAR2(30);
45323 
45324 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
45325 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
45326 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
45327 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
45328 
45329 -- 4262811 Variables ------------------------------------------------------------------------------------------
45330 l_entered_amt_idx             NUMBER;
45331 l_accted_amt_idx              NUMBER;
45332 l_acc_rev_flag                VARCHAR2(1);
45333 l_accrual_line_num            NUMBER;
45334 l_tmp_amt                     NUMBER;
45335 l_acc_rev_natural_side_code   VARCHAR2(1);
45336 
45337 l_num_entries                 NUMBER;
45338 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
45339 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
45340 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
45341 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
45342 l_recog_line_1                NUMBER;
45343 l_recog_line_2                NUMBER;
45344 
45345 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
45346 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
45347 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
45348 
45349 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
45350 
45351 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
45352 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
45353 
45354 ---------------------------------------------------------------------------------------------------------------
45355 
45356 
45357 --
45358 -- bulk performance
45359 --
45360 l_balance_type_code           VARCHAR2(1);
45361 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
45362 l_log_module                  VARCHAR2(240);
45363 
45364 --
45365 -- Upgrade strategy
45366 --
45367 l_actual_upg_option           VARCHAR2(1);
45368 l_enc_upg_option           VARCHAR2(1);
45369 
45370 --
45371 BEGIN
45372 --
45373 IF g_log_enabled THEN
45374       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_218';
45375 END IF;
45376 --
45380          (p_msg      => 'BEGIN of AcctLineType_218'
45377 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
45378 
45379       trace
45381          ,p_level    => C_LEVEL_PROCEDURE
45382          ,p_module   => l_log_module);
45383 
45384 END IF;
45385 --
45386 l_component_type             := 'AMB_JLT';
45387 l_component_code             := 'FA_CIP_NBV_RETIRED_GAIN';
45388 l_component_type_code        := 'S';
45389 l_component_appl_id          :=  140;
45390 l_amb_context_code           := 'DEFAULT';
45391 l_entity_code                := 'TRANSACTIONS';
45392 l_event_class_code           := 'CIP_RETIREMENTS';
45393 l_event_type_code            := 'CIP_REINSTATEMENTS';
45394 l_line_definition_owner_code := 'S';
45395 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
45396 --
45397 l_balance_type_code          := 'A';
45398 l_segment                     := NULL;
45399 l_ccid                        := NULL;
45400 l_adr_transaction_coa_id      := NULL;
45401 l_adr_accounting_coa_id       := NULL;
45402 l_adr_flexfield_segment_code  := NULL;
45403 l_adr_flex_value_set_id       := NULL;
45404 l_adr_value_type_code         := NULL;
45405 l_adr_value_combination_id    := NULL;
45406 l_adr_value_segment_code      := NULL;
45407 
45408 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
45409 l_bflow_class_code           := '';    -- 4219869 Business Flow
45410 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
45411 l_budgetary_control_flag     := 'N';
45412 
45413 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
45414 l_bflow_applied_to_amt       := NULL; -- 5132302
45415 l_entered_amt_idx            := NULL;          -- 4262811
45416 l_accted_amt_idx             := NULL;          -- 4262811
45417 l_acc_rev_flag               := NULL;          -- 4262811
45418 l_accrual_line_num           := NULL;          -- 4262811
45419 l_tmp_amt                    := NULL;          -- 4262811
45420 --
45421  
45422 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
45423     l_balance_type_code <> 'B' THEN
45424 IF NVL(p_source_35,'
45425 ') =  'NBV RETIRED' AND 
45426 p_source_41 >=  0
45427  THEN 
45428 
45429    --
45430    XLA_AE_LINES_PKG.SetNewLine;
45431 
45432    p_balance_type_code          := l_balance_type_code;
45433    -- set the flag so later we will know whether the gain loss line needs to be created
45434    
45435    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
45436      p_actual_flag :='A';
45437    END IF;
45438 
45439    --
45440    -- bulk performance
45441    --
45442    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
45443                                       p_header_num   => 0); -- 4262811
45444    --
45445    -- set accounting line options
45446    --
45447    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
45448            p_natural_side_code          => 'D'
45449          , p_gain_or_loss_flag          => 'N'
45450          , p_gl_transfer_mode_code      => 'S'
45451          , p_acct_entry_type_code       => 'A'
45452          , p_switch_side_flag           => 'Y'
45453          , p_merge_duplicate_code       => 'N'
45454          );
45455    --
45456    l_acc_rev_natural_side_code := 'C';  -- 4262811
45457    -- 
45458    --
45459    -- set accounting line type info
45460    --
45461    xla_ae_lines_pkg.SetAcctLineType
45462       (p_component_type             => l_component_type
45463       ,p_event_type_code            => l_event_type_code
45464       ,p_line_definition_owner_code => l_line_definition_owner_code
45465       ,p_line_definition_code       => l_line_definition_code
45466       ,p_accounting_line_code       => l_component_code
45467       ,p_accounting_line_type_code  => l_component_type_code
45468       ,p_accounting_line_appl_id    => l_component_appl_id
45469       ,p_amb_context_code           => l_amb_context_code
45470       ,p_entity_code                => l_entity_code
45471       ,p_event_class_code           => l_event_class_code);
45472    --
45473    -- set accounting class
45474    --
45475    xla_ae_lines_pkg.SetAcctClass(
45476            p_accounting_class_code  => 'ASSET'
45477          , p_ae_header_id           => l_ae_header_id
45478          );
45479 
45480    --
45481    -- set rounding class
45482    --
45483    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
45484                       'ASSET';
45485 
45486    --
45487    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
45488    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
45489    --
45490    -- bulk performance
45491    --
45492    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
45493 
45494    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
45495       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
45496 
45497    -- 4955764
45498    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45499       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
45500 
45501    -- 4458381 Public Sector Enh
45502    
45503    --
45504    -- set accounting attributes for the line type
45505    --
45506    l_entered_amt_idx := 4;
45507    l_accted_amt_idx  := 6;
45508    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
45509    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
45510    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
45511    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
45512    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
45516    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
45513    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
45514    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
45515    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
45517    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
45518    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
45519    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
45520    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
45521 
45522    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
45523    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
45524 
45525    ---------------------------------------------------------------------------------------------------------------
45526    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
45527    ---------------------------------------------------------------------------------------------------------------
45528    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
45529 
45530    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45531    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45532 
45533    IF xla_accounting_cache_pkg.GetValueChar
45534          (p_source_code         => 'LEDGER_CATEGORY_CODE'
45535          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
45536    AND l_bflow_method_code = 'PRIOR_ENTRY'
45537 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
45538    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
45539          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
45540        )
45541    THEN
45542          xla_ae_lines_pkg.BflowUpgEntry
45543            (p_business_method_code    => l_bflow_method_code
45544            ,p_business_class_code     => l_bflow_class_code
45545            ,p_balance_type            => l_balance_type_code);
45546    ELSE
45547       NULL;
45548 -- No business flow processing for business flow method of NONE.
45549    END IF;
45550 
45551    --
45552    -- call analytical criteria
45553    --
45554    
45555    --
45556    -- call description
45557    --
45558    
45559 xla_ae_lines_pkg.SetLineDescription(
45560    p_ae_header_id => l_ae_header_id
45561   ,p_description  => Description_34 (
45562      p_application_id         => p_application_id
45563    , p_ae_header_id           => l_ae_header_id 
45564 , p_source_1 => p_source_1
45565    )
45566 );
45567 
45568 
45569    --
45570    -- call ADRs
45571    -- Bug 4922099
45572    --
45573    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45574         (NVL(l_actual_upg_option, 'N') = 'O') OR
45575         (NVL(l_enc_upg_option, 'N') = 'O')
45576       )
45577    THEN
45578    NULL;
45579    --
45580    --
45581    
45582   l_ccid := AcctDerRule_173(
45583            p_application_id           => p_application_id
45584          , p_ae_header_id             => l_ae_header_id 
45585 , p_source_3 => p_source_3
45586 , p_source_30 => p_source_30
45587          , x_transaction_coa_id       => l_adr_transaction_coa_id
45588          , x_accounting_coa_id        => l_adr_accounting_coa_id
45589          , x_value_type_code          => l_adr_value_type_code
45590          , p_side                     => 'NA'
45591    );
45592 
45593    xla_ae_lines_pkg.set_ccid(
45594     p_code_combination_id          => l_ccid
45595   , p_value_type_code              => l_adr_value_type_code
45596   , p_transaction_coa_id           => l_adr_transaction_coa_id
45597   , p_accounting_coa_id            => l_adr_accounting_coa_id
45598   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
45599   , p_adr_type_code                => 'S'
45600   , p_component_type               => l_component_type
45601   , p_component_code               => l_component_code
45602   , p_component_type_code          => l_component_type_code
45603   , p_component_appl_id            => l_component_appl_id
45604   , p_amb_context_code             => l_amb_context_code
45605   , p_side                         => 'NA'
45606   );
45607 
45608 
45609    l_segment := AcctDerRule_168(
45610            p_application_id           => p_application_id
45611          , p_ae_header_id             => l_ae_header_id 
45612 , p_source_3 => p_source_3
45613 , p_source_29 => p_source_29
45614          , x_transaction_coa_id       => l_adr_transaction_coa_id
45615          , x_accounting_coa_id        => l_adr_accounting_coa_id
45616          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
45617          , x_flex_value_set_id        => l_adr_flex_value_set_id
45618          , x_value_type_code          => l_adr_value_type_code
45619          , x_value_combination_id     => l_adr_value_combination_id
45620          , x_value_segment_code       => l_adr_value_segment_code
45621          , p_side                     => 'NA'
45622          , p_override_seg_flag        => 'Y'
45623    );
45624 
45625    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
45626 
45627       xla_ae_lines_pkg.set_segment(
45628           p_to_segment_code         => 'GL_BALANCING'
45629         , p_segment_value           => l_segment
45630         , p_from_segment_code       => l_adr_value_segment_code
45631         , p_from_combination_id     => l_adr_value_combination_id
45632         , p_value_type_code         => l_adr_value_type_code
45633         , p_transaction_coa_id      => l_adr_transaction_coa_id
45634         , p_accounting_coa_id       => l_adr_accounting_coa_id
45635         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
45636         , p_flex_value_set_id       => l_adr_flex_value_set_id
45640         , p_component_code          => l_component_code
45637         , p_adr_code                => 'FA_EXPENSE_ACCT'
45638         , p_adr_type_code           => 'S'
45639         , p_component_type          => l_component_type
45641         , p_component_type_code     => l_component_type_code
45642         , p_component_appl_id       => l_component_appl_id
45643         , p_amb_context_code        => l_amb_context_code
45644         , p_entity_code             => 'TRANSACTIONS'
45645         , p_event_class_code        => 'CIP_RETIREMENTS'
45646         , p_side                    => 'NA'
45647         );
45648 
45649   END IF;
45650 
45651    l_segment := AcctDerRule_159(
45652            p_application_id           => p_application_id
45653          , p_ae_header_id             => l_ae_header_id 
45654 , p_source_3 => p_source_3
45655 , p_source_21 => p_source_21
45656          , x_transaction_coa_id       => l_adr_transaction_coa_id
45657          , x_accounting_coa_id        => l_adr_accounting_coa_id
45658          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
45659          , x_flex_value_set_id        => l_adr_flex_value_set_id
45660          , x_value_type_code          => l_adr_value_type_code
45661          , x_value_combination_id     => l_adr_value_combination_id
45662          , x_value_segment_code       => l_adr_value_segment_code
45663          , p_side                     => 'NA'
45664          , p_override_seg_flag        => 'Y'
45665    );
45666 
45667    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
45668 
45669       xla_ae_lines_pkg.set_segment(
45670           p_to_segment_code         => 'GL_ACCOUNT'
45671         , p_segment_value           => l_segment
45672         , p_from_segment_code       => l_adr_value_segment_code
45673         , p_from_combination_id     => l_adr_value_combination_id
45674         , p_value_type_code         => l_adr_value_type_code
45675         , p_transaction_coa_id      => l_adr_transaction_coa_id
45676         , p_accounting_coa_id       => l_adr_accounting_coa_id
45677         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
45678         , p_flex_value_set_id       => l_adr_flex_value_set_id
45679         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
45680         , p_adr_type_code           => 'S'
45681         , p_component_type          => l_component_type
45682         , p_component_code          => l_component_code
45683         , p_component_type_code     => l_component_type_code
45684         , p_component_appl_id       => l_component_appl_id
45685         , p_amb_context_code        => l_amb_context_code
45686         , p_entity_code             => 'TRANSACTIONS'
45687         , p_event_class_code        => 'CIP_RETIREMENTS'
45688         , p_side                    => 'NA'
45689         );
45690 
45691   END IF;
45692 
45693    --
45694    --
45695    END IF;
45696    --
45697    -- Bug 4922099
45698    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
45699           (NVL(l_enc_upg_option, 'N') = 'O')
45700         ) AND
45701         (l_bflow_method_code = 'PRIOR_ENTRY')
45702       )
45703    THEN
45704       IF
45705       --
45706       1 = 2
45707       --
45708       THEN
45709       xla_accounting_err_pkg.build_message
45710                                     (p_appli_s_name            => 'XLA'
45711                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45712                                     ,p_token_1                 => 'LINE_NUMBER'
45713                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
45714                                     ,p_token_2                 => 'LINE_TYPE_NAME'
45715                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
45716                                                                              l_component_type
45717                                                                             ,l_component_code
45718                                                                             ,l_component_type_code
45719                                                                             ,l_component_appl_id
45720                                                                             ,l_amb_context_code
45721                                                                             ,l_entity_code
45722                                                                             ,l_event_class_code
45723                                                                            )
45724                                     ,p_token_3                 => 'OWNER'
45725                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
45726                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
45727                                                                           ,p_lookup_code    => l_component_type_code
45728                                                                          )
45729                                     ,p_token_4                 => 'PRODUCT_NAME'
45730                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
45731                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
45732                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
45733                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
45734                                     ,p_ae_header_id            =>  NULL
45735                                        );
45736 
45737         IF (C_LEVEL_ERROR>= g_log_level) THEN
45738                  trace
45739                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45740                       ,p_level    => C_LEVEL_ERROR
45741                       ,p_module   => l_log_module);
45742         END IF;
45743       END IF;
45747    ------------------------------------------------------------------------------------------------
45744    END IF;
45745    --
45746    --
45748    -- 4219869 Business Flow
45749    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
45750    -- Prior Entry.  Currently, the following code is always generated.
45751    ------------------------------------------------------------------------------------------------
45752    XLA_AE_LINES_PKG.ValidateCurrentLine;
45753 
45754    ------------------------------------------------------------------------------------
45755    -- 4219869 Business Flow
45756    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
45757    ------------------------------------------------------------------------------------
45758    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45759 
45760    ----------------------------------------------------------------------------------
45761    -- 4219869 Business Flow
45762    -- Update journal entry status -- Need to generate this within IF <condition>
45763    ----------------------------------------------------------------------------------
45764    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45765          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
45766          ,p_balance_type_code => l_balance_type_code
45767          );
45768 
45769    -------------------------------------------------------------------------------------------
45770    -- 4262811 - Generate the Accrual Reversal lines
45771    -------------------------------------------------------------------------------------------
45772    BEGIN
45773       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
45774                               (g_array_event(p_event_id).array_value_num('header_index'));
45775       IF l_acc_rev_flag IS NULL THEN
45776          l_acc_rev_flag := 'N';
45777       END IF;
45778    EXCEPTION
45779       WHEN OTHERS THEN
45780          l_acc_rev_flag := 'N';
45781    END;
45782    --
45783    IF (l_acc_rev_flag = 'Y') THEN
45784 
45785        -- 4645092  ------------------------------------------------------------------------------
45786        -- To allow MPA report to determine if it should generate report process
45787        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
45788        ------------------------------------------------------------------------------------------
45789 
45790        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
45791        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
45792    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
45793    -- call ADRs
45794    -- Bug 4922099
45795    --
45796    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45797         (NVL(l_actual_upg_option, 'N') = 'O') OR
45798         (NVL(l_enc_upg_option, 'N') = 'O')
45799       )
45800    THEN
45801    NULL;
45802    --
45803    --
45804    
45805   l_ccid := AcctDerRule_173(
45806            p_application_id           => p_application_id
45807          , p_ae_header_id             => l_ae_header_id 
45808 , p_source_3 => p_source_3
45809 , p_source_30 => p_source_30
45810          , x_transaction_coa_id       => l_adr_transaction_coa_id
45811          , x_accounting_coa_id        => l_adr_accounting_coa_id
45812          , x_value_type_code          => l_adr_value_type_code
45813          , p_side                     => 'NA'
45814    );
45815 
45816    xla_ae_lines_pkg.set_ccid(
45817     p_code_combination_id          => l_ccid
45818   , p_value_type_code              => l_adr_value_type_code
45819   , p_transaction_coa_id           => l_adr_transaction_coa_id
45820   , p_accounting_coa_id            => l_adr_accounting_coa_id
45821   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
45822   , p_adr_type_code                => 'S'
45823   , p_component_type               => l_component_type
45824   , p_component_code               => l_component_code
45825   , p_component_type_code          => l_component_type_code
45826   , p_component_appl_id            => l_component_appl_id
45827   , p_amb_context_code             => l_amb_context_code
45828   , p_side                         => 'NA'
45829   );
45830 
45831 
45832    l_segment := AcctDerRule_168(
45833            p_application_id           => p_application_id
45834          , p_ae_header_id             => l_ae_header_id 
45835 , p_source_3 => p_source_3
45836 , p_source_29 => p_source_29
45837          , x_transaction_coa_id       => l_adr_transaction_coa_id
45838          , x_accounting_coa_id        => l_adr_accounting_coa_id
45839          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
45840          , x_flex_value_set_id        => l_adr_flex_value_set_id
45841          , x_value_type_code          => l_adr_value_type_code
45842          , x_value_combination_id     => l_adr_value_combination_id
45843          , x_value_segment_code       => l_adr_value_segment_code
45844          , p_side                     => 'NA'
45845          , p_override_seg_flag        => 'Y'
45846    );
45847 
45848    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
45849 
45850       xla_ae_lines_pkg.set_segment(
45851           p_to_segment_code         => 'GL_BALANCING'
45852         , p_segment_value           => l_segment
45853         , p_from_segment_code       => l_adr_value_segment_code
45854         , p_from_combination_id     => l_adr_value_combination_id
45855         , p_value_type_code         => l_adr_value_type_code
45856         , p_transaction_coa_id      => l_adr_transaction_coa_id
45857         , p_accounting_coa_id       => l_adr_accounting_coa_id
45858         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
45859         , p_flex_value_set_id       => l_adr_flex_value_set_id
45860         , p_adr_code                => 'FA_EXPENSE_ACCT'
45861         , p_adr_type_code           => 'S'
45865         , p_component_appl_id       => l_component_appl_id
45862         , p_component_type          => l_component_type
45863         , p_component_code          => l_component_code
45864         , p_component_type_code     => l_component_type_code
45866         , p_amb_context_code        => l_amb_context_code
45867         , p_entity_code             => 'TRANSACTIONS'
45868         , p_event_class_code        => 'CIP_RETIREMENTS'
45869         , p_side                    => 'NA'
45870         );
45871 
45872   END IF;
45873 
45874    l_segment := AcctDerRule_159(
45875            p_application_id           => p_application_id
45876          , p_ae_header_id             => l_ae_header_id 
45877 , p_source_3 => p_source_3
45878 , p_source_21 => p_source_21
45879          , x_transaction_coa_id       => l_adr_transaction_coa_id
45880          , x_accounting_coa_id        => l_adr_accounting_coa_id
45881          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
45882          , x_flex_value_set_id        => l_adr_flex_value_set_id
45883          , x_value_type_code          => l_adr_value_type_code
45884          , x_value_combination_id     => l_adr_value_combination_id
45885          , x_value_segment_code       => l_adr_value_segment_code
45886          , p_side                     => 'NA'
45887          , p_override_seg_flag        => 'Y'
45888    );
45889 
45890    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
45891 
45892       xla_ae_lines_pkg.set_segment(
45893           p_to_segment_code         => 'GL_ACCOUNT'
45894         , p_segment_value           => l_segment
45895         , p_from_segment_code       => l_adr_value_segment_code
45896         , p_from_combination_id     => l_adr_value_combination_id
45897         , p_value_type_code         => l_adr_value_type_code
45898         , p_transaction_coa_id      => l_adr_transaction_coa_id
45899         , p_accounting_coa_id       => l_adr_accounting_coa_id
45900         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
45901         , p_flex_value_set_id       => l_adr_flex_value_set_id
45902         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
45903         , p_adr_type_code           => 'S'
45904         , p_component_type          => l_component_type
45905         , p_component_code          => l_component_code
45906         , p_component_type_code     => l_component_type_code
45907         , p_component_appl_id       => l_component_appl_id
45908         , p_amb_context_code        => l_amb_context_code
45909         , p_entity_code             => 'TRANSACTIONS'
45910         , p_event_class_code        => 'CIP_RETIREMENTS'
45911         , p_side                    => 'NA'
45912         );
45913 
45914   END IF;
45915 
45916    --
45917    --
45918    END IF;
45919 
45920        --
45921        -- Update the line information that should be overwritten
45922        --
45923        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
45924                                          p_header_num   => 1);
45925        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
45926 
45927        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
45928 
45929        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
45930           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
45931        END IF;
45932 
45933       --
45934       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
45935       --
45936       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
45937           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
45938       ELSE
45939           ---------------------------------------------------------------------------------------------------
45940           -- 4262811a Switch Sign
45941           ---------------------------------------------------------------------------------------------------
45942           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
45943           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45944                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45945           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45946                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45947           -- 5132302
45948           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
45949                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45950 
45951       END IF;
45952 
45953       -- 4955764
45954       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45955       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
45956 
45957 
45958       XLA_AE_LINES_PKG.ValidateCurrentLine;
45959       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45960 
45961       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45962                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
45963                ,p_balance_type_code => l_balance_type_code);
45964 
45965    END IF;
45966 
45967    -----------------------------------------------------------------------------------------
45968    -- 4262811 Multiperiod Accounting
45969    -----------------------------------------------------------------------------------------
45970      -- No MPA option is assigned.
45971 
45972 
45973 END IF;
45974 END IF;
45975 --
45976 
45977 --
45978 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
45979    trace
45983 END IF;
45980       (p_msg      => 'END of AcctLineType_218'
45981       ,p_level    => C_LEVEL_PROCEDURE
45982       ,p_module   => l_log_module);
45984 --
45985 EXCEPTION
45986   WHEN xla_exceptions_pkg.application_exception THEN
45987       RAISE;
45988   WHEN OTHERS THEN
45989        xla_exceptions_pkg.raise_message
45990            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_218');
45991 END AcctLineType_218;
45992 --
45993 
45994 ---------------------------------------
45995 --
45996 -- PRIVATE FUNCTION
45997 --         AcctLineType_219
45998 --
45999 ---------------------------------------
46000 PROCEDURE AcctLineType_219 (
46001   p_application_id        IN NUMBER
46002  ,p_event_id              IN NUMBER
46003  ,p_calculate_acctd_flag  IN VARCHAR2
46004  ,p_calculate_g_l_flag    IN VARCHAR2
46005  ,p_actual_flag           IN OUT VARCHAR2
46006  ,p_balance_type_code     OUT VARCHAR2
46007  ,p_gain_or_loss_ref      OUT VARCHAR2
46008  
46009 --Period Close Date
46010  , p_source_1            IN DATE
46011 --Generated Code Combination Identifier
46012  , p_source_3            IN NUMBER
46013 --Net Book Value Retired Loss Account
46014  , p_source_22            IN VARCHAR2
46015 --Expense Account Code Combination Identifier
46016  , p_source_29            IN NUMBER
46017 --Default Code Combination Identifier
46018  , p_source_30            IN NUMBER
46019 --Adjustment Type
46020  , p_source_35            IN VARCHAR2
46021 --Transaction Header Identifier
46022  , p_source_36            IN NUMBER
46023 --Adjustment Line Identifier
46024  , p_source_37            IN NUMBER
46025 --Distribution Type Code
46026  , p_source_38            IN VARCHAR2
46027 --Entered Amount
46028  , p_source_39            IN NUMBER
46029 --Currency Code
46030  , p_source_40            IN VARCHAR2
46031 --Gain Loss Amount
46032  , p_source_41            IN NUMBER
46033 )
46034 IS
46035 
46036 l_component_type              VARCHAR2(80);
46037 l_component_code              VARCHAR2(30);
46038 l_component_type_code         VARCHAR2(1);
46039 l_component_appl_id           INTEGER;
46040 l_amb_context_code            VARCHAR2(30);
46041 l_entity_code                 VARCHAR2(30);
46042 l_event_class_code            VARCHAR2(30);
46043 l_ae_header_id                NUMBER;
46044 l_event_type_code             VARCHAR2(30);
46045 l_line_definition_code        VARCHAR2(30);
46046 l_line_definition_owner_code  VARCHAR2(1);
46047 --
46048 -- adr variables
46049 l_segment                     VARCHAR2(30);
46050 l_ccid                        NUMBER;
46051 l_adr_transaction_coa_id      NUMBER;
46052 l_adr_accounting_coa_id       NUMBER;
46053 l_adr_flexfield_segment_code  VARCHAR2(30);
46054 l_adr_flex_value_set_id       NUMBER;
46055 l_adr_value_type_code         VARCHAR2(30);
46056 l_adr_value_combination_id    NUMBER;
46057 l_adr_value_segment_code      VARCHAR2(30);
46058 
46059 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
46060 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
46061 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
46062 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
46063 
46064 -- 4262811 Variables ------------------------------------------------------------------------------------------
46065 l_entered_amt_idx             NUMBER;
46066 l_accted_amt_idx              NUMBER;
46067 l_acc_rev_flag                VARCHAR2(1);
46068 l_accrual_line_num            NUMBER;
46069 l_tmp_amt                     NUMBER;
46070 l_acc_rev_natural_side_code   VARCHAR2(1);
46071 
46072 l_num_entries                 NUMBER;
46073 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
46074 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
46075 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
46076 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
46077 l_recog_line_1                NUMBER;
46078 l_recog_line_2                NUMBER;
46079 
46080 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
46081 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
46082 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
46083 
46084 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
46085 
46086 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
46087 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
46088 
46089 ---------------------------------------------------------------------------------------------------------------
46090 
46091 
46092 --
46093 -- bulk performance
46094 --
46095 l_balance_type_code           VARCHAR2(1);
46096 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
46097 l_log_module                  VARCHAR2(240);
46098 
46099 --
46100 -- Upgrade strategy
46101 --
46102 l_actual_upg_option           VARCHAR2(1);
46103 l_enc_upg_option           VARCHAR2(1);
46104 
46105 --
46106 BEGIN
46107 --
46108 IF g_log_enabled THEN
46109       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_219';
46110 END IF;
46111 --
46112 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
46113 
46114       trace
46115          (p_msg      => 'BEGIN of AcctLineType_219'
46116          ,p_level    => C_LEVEL_PROCEDURE
46117          ,p_module   => l_log_module);
46118 
46119 END IF;
46120 --
46121 l_component_type             := 'AMB_JLT';
46122 l_component_code             := 'FA_CIP_NBV_RETIRED_LOSS';
46123 l_component_type_code        := 'S';
46124 l_component_appl_id          :=  140;
46125 l_amb_context_code           := 'DEFAULT';
46129 l_line_definition_owner_code := 'S';
46126 l_entity_code                := 'TRANSACTIONS';
46127 l_event_class_code           := 'CIP_RETIREMENTS';
46128 l_event_type_code            := 'CIP_REINSTATEMENTS';
46130 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
46131 --
46132 l_balance_type_code          := 'A';
46133 l_segment                     := NULL;
46134 l_ccid                        := NULL;
46135 l_adr_transaction_coa_id      := NULL;
46136 l_adr_accounting_coa_id       := NULL;
46137 l_adr_flexfield_segment_code  := NULL;
46138 l_adr_flex_value_set_id       := NULL;
46139 l_adr_value_type_code         := NULL;
46140 l_adr_value_combination_id    := NULL;
46141 l_adr_value_segment_code      := NULL;
46142 
46143 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
46144 l_bflow_class_code           := '';    -- 4219869 Business Flow
46145 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
46146 l_budgetary_control_flag     := 'N';
46147 
46148 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
46149 l_bflow_applied_to_amt       := NULL; -- 5132302
46150 l_entered_amt_idx            := NULL;          -- 4262811
46151 l_accted_amt_idx             := NULL;          -- 4262811
46152 l_acc_rev_flag               := NULL;          -- 4262811
46153 l_accrual_line_num           := NULL;          -- 4262811
46154 l_tmp_amt                    := NULL;          -- 4262811
46155 --
46156  
46157 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
46158     l_balance_type_code <> 'B' THEN
46159 IF NVL(p_source_35,'
46160 ') =  'NBV RETIRED' AND 
46161 p_source_41 <  0
46162  THEN 
46163 
46164    --
46165    XLA_AE_LINES_PKG.SetNewLine;
46166 
46167    p_balance_type_code          := l_balance_type_code;
46168    -- set the flag so later we will know whether the gain loss line needs to be created
46169    
46170    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
46171      p_actual_flag :='A';
46172    END IF;
46173 
46174    --
46175    -- bulk performance
46176    --
46177    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
46178                                       p_header_num   => 0); -- 4262811
46179    --
46180    -- set accounting line options
46181    --
46182    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
46183            p_natural_side_code          => 'D'
46184          , p_gain_or_loss_flag          => 'N'
46185          , p_gl_transfer_mode_code      => 'S'
46186          , p_acct_entry_type_code       => 'A'
46187          , p_switch_side_flag           => 'Y'
46188          , p_merge_duplicate_code       => 'N'
46189          );
46190    --
46191    l_acc_rev_natural_side_code := 'C';  -- 4262811
46192    -- 
46193    --
46194    -- set accounting line type info
46195    --
46196    xla_ae_lines_pkg.SetAcctLineType
46197       (p_component_type             => l_component_type
46198       ,p_event_type_code            => l_event_type_code
46199       ,p_line_definition_owner_code => l_line_definition_owner_code
46200       ,p_line_definition_code       => l_line_definition_code
46201       ,p_accounting_line_code       => l_component_code
46202       ,p_accounting_line_type_code  => l_component_type_code
46203       ,p_accounting_line_appl_id    => l_component_appl_id
46204       ,p_amb_context_code           => l_amb_context_code
46205       ,p_entity_code                => l_entity_code
46206       ,p_event_class_code           => l_event_class_code);
46207    --
46208    -- set accounting class
46209    --
46210    xla_ae_lines_pkg.SetAcctClass(
46211            p_accounting_class_code  => 'ASSET'
46212          , p_ae_header_id           => l_ae_header_id
46213          );
46214 
46215    --
46216    -- set rounding class
46217    --
46218    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
46219                       'ASSET';
46220 
46221    --
46222    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
46223    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
46224    --
46225    -- bulk performance
46226    --
46227    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
46228 
46229    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
46230       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
46231 
46232    -- 4955764
46233    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
46234       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
46235 
46236    -- 4458381 Public Sector Enh
46237    
46238    --
46239    -- set accounting attributes for the line type
46240    --
46241    l_entered_amt_idx := 4;
46242    l_accted_amt_idx  := 6;
46243    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
46244    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
46245    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
46246    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
46247    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
46248    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
46249    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
46250    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
46251    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
46252    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
46253    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
46254    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
46255    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
46256 
46260    ---------------------------------------------------------------------------------------------------------------
46257    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
46258    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
46259 
46261    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
46262    ---------------------------------------------------------------------------------------------------------------
46263    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
46264 
46265    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46266    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46267 
46268    IF xla_accounting_cache_pkg.GetValueChar
46269          (p_source_code         => 'LEDGER_CATEGORY_CODE'
46270          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
46271    AND l_bflow_method_code = 'PRIOR_ENTRY'
46272 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
46273    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
46274          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
46275        )
46276    THEN
46277          xla_ae_lines_pkg.BflowUpgEntry
46278            (p_business_method_code    => l_bflow_method_code
46279            ,p_business_class_code     => l_bflow_class_code
46280            ,p_balance_type            => l_balance_type_code);
46281    ELSE
46282       NULL;
46283 -- No business flow processing for business flow method of NONE.
46284    END IF;
46285 
46286    --
46287    -- call analytical criteria
46288    --
46289    
46290    --
46291    -- call description
46292    --
46293    
46294 xla_ae_lines_pkg.SetLineDescription(
46295    p_ae_header_id => l_ae_header_id
46296   ,p_description  => Description_34 (
46297      p_application_id         => p_application_id
46298    , p_ae_header_id           => l_ae_header_id 
46299 , p_source_1 => p_source_1
46300    )
46301 );
46302 
46303 
46304    --
46305    -- call ADRs
46306    -- Bug 4922099
46307    --
46308    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
46309         (NVL(l_actual_upg_option, 'N') = 'O') OR
46310         (NVL(l_enc_upg_option, 'N') = 'O')
46311       )
46312    THEN
46313    NULL;
46314    --
46315    --
46316    
46317   l_ccid := AcctDerRule_173(
46318            p_application_id           => p_application_id
46319          , p_ae_header_id             => l_ae_header_id 
46320 , p_source_3 => p_source_3
46321 , p_source_30 => p_source_30
46322          , x_transaction_coa_id       => l_adr_transaction_coa_id
46323          , x_accounting_coa_id        => l_adr_accounting_coa_id
46324          , x_value_type_code          => l_adr_value_type_code
46325          , p_side                     => 'NA'
46326    );
46327 
46328    xla_ae_lines_pkg.set_ccid(
46329     p_code_combination_id          => l_ccid
46330   , p_value_type_code              => l_adr_value_type_code
46331   , p_transaction_coa_id           => l_adr_transaction_coa_id
46332   , p_accounting_coa_id            => l_adr_accounting_coa_id
46333   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
46334   , p_adr_type_code                => 'S'
46335   , p_component_type               => l_component_type
46336   , p_component_code               => l_component_code
46337   , p_component_type_code          => l_component_type_code
46338   , p_component_appl_id            => l_component_appl_id
46339   , p_amb_context_code             => l_amb_context_code
46340   , p_side                         => 'NA'
46341   );
46342 
46343 
46344    l_segment := AcctDerRule_168(
46345            p_application_id           => p_application_id
46346          , p_ae_header_id             => l_ae_header_id 
46347 , p_source_3 => p_source_3
46348 , p_source_29 => p_source_29
46349          , x_transaction_coa_id       => l_adr_transaction_coa_id
46350          , x_accounting_coa_id        => l_adr_accounting_coa_id
46351          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
46352          , x_flex_value_set_id        => l_adr_flex_value_set_id
46353          , x_value_type_code          => l_adr_value_type_code
46354          , x_value_combination_id     => l_adr_value_combination_id
46355          , x_value_segment_code       => l_adr_value_segment_code
46356          , p_side                     => 'NA'
46357          , p_override_seg_flag        => 'Y'
46358    );
46359 
46360    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
46361 
46362       xla_ae_lines_pkg.set_segment(
46363           p_to_segment_code         => 'GL_BALANCING'
46364         , p_segment_value           => l_segment
46365         , p_from_segment_code       => l_adr_value_segment_code
46366         , p_from_combination_id     => l_adr_value_combination_id
46367         , p_value_type_code         => l_adr_value_type_code
46368         , p_transaction_coa_id      => l_adr_transaction_coa_id
46369         , p_accounting_coa_id       => l_adr_accounting_coa_id
46370         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
46371         , p_flex_value_set_id       => l_adr_flex_value_set_id
46372         , p_adr_code                => 'FA_EXPENSE_ACCT'
46373         , p_adr_type_code           => 'S'
46374         , p_component_type          => l_component_type
46375         , p_component_code          => l_component_code
46376         , p_component_type_code     => l_component_type_code
46377         , p_component_appl_id       => l_component_appl_id
46378         , p_amb_context_code        => l_amb_context_code
46379         , p_entity_code             => 'TRANSACTIONS'
46380         , p_event_class_code        => 'CIP_RETIREMENTS'
46381         , p_side                    => 'NA'
46385 
46382         );
46383 
46384   END IF;
46386    l_segment := AcctDerRule_160(
46387            p_application_id           => p_application_id
46388          , p_ae_header_id             => l_ae_header_id 
46389 , p_source_3 => p_source_3
46390 , p_source_22 => p_source_22
46391          , x_transaction_coa_id       => l_adr_transaction_coa_id
46392          , x_accounting_coa_id        => l_adr_accounting_coa_id
46393          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
46394          , x_flex_value_set_id        => l_adr_flex_value_set_id
46395          , x_value_type_code          => l_adr_value_type_code
46396          , x_value_combination_id     => l_adr_value_combination_id
46397          , x_value_segment_code       => l_adr_value_segment_code
46398          , p_side                     => 'NA'
46399          , p_override_seg_flag        => 'Y'
46400    );
46401 
46402    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
46403 
46404       xla_ae_lines_pkg.set_segment(
46405           p_to_segment_code         => 'GL_ACCOUNT'
46406         , p_segment_value           => l_segment
46407         , p_from_segment_code       => l_adr_value_segment_code
46408         , p_from_combination_id     => l_adr_value_combination_id
46409         , p_value_type_code         => l_adr_value_type_code
46410         , p_transaction_coa_id      => l_adr_transaction_coa_id
46411         , p_accounting_coa_id       => l_adr_accounting_coa_id
46412         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
46413         , p_flex_value_set_id       => l_adr_flex_value_set_id
46414         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
46415         , p_adr_type_code           => 'S'
46416         , p_component_type          => l_component_type
46417         , p_component_code          => l_component_code
46418         , p_component_type_code     => l_component_type_code
46419         , p_component_appl_id       => l_component_appl_id
46420         , p_amb_context_code        => l_amb_context_code
46421         , p_entity_code             => 'TRANSACTIONS'
46422         , p_event_class_code        => 'CIP_RETIREMENTS'
46423         , p_side                    => 'NA'
46424         );
46425 
46426   END IF;
46427 
46428    --
46429    --
46430    END IF;
46431    --
46432    -- Bug 4922099
46433    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
46434           (NVL(l_enc_upg_option, 'N') = 'O')
46435         ) AND
46436         (l_bflow_method_code = 'PRIOR_ENTRY')
46437       )
46438    THEN
46439       IF
46440       --
46441       1 = 2
46442       --
46443       THEN
46444       xla_accounting_err_pkg.build_message
46445                                     (p_appli_s_name            => 'XLA'
46446                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46447                                     ,p_token_1                 => 'LINE_NUMBER'
46448                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
46449                                     ,p_token_2                 => 'LINE_TYPE_NAME'
46450                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
46451                                                                              l_component_type
46452                                                                             ,l_component_code
46453                                                                             ,l_component_type_code
46454                                                                             ,l_component_appl_id
46455                                                                             ,l_amb_context_code
46456                                                                             ,l_entity_code
46457                                                                             ,l_event_class_code
46458                                                                            )
46459                                     ,p_token_3                 => 'OWNER'
46460                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
46461                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
46462                                                                           ,p_lookup_code    => l_component_type_code
46463                                                                          )
46464                                     ,p_token_4                 => 'PRODUCT_NAME'
46465                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
46466                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
46467                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
46468                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
46469                                     ,p_ae_header_id            =>  NULL
46470                                        );
46471 
46472         IF (C_LEVEL_ERROR>= g_log_level) THEN
46473                  trace
46474                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46475                       ,p_level    => C_LEVEL_ERROR
46476                       ,p_module   => l_log_module);
46477         END IF;
46478       END IF;
46479    END IF;
46480    --
46481    --
46482    ------------------------------------------------------------------------------------------------
46483    -- 4219869 Business Flow
46484    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
46485    -- Prior Entry.  Currently, the following code is always generated.
46486    ------------------------------------------------------------------------------------------------
46487    XLA_AE_LINES_PKG.ValidateCurrentLine;
46488 
46492    ------------------------------------------------------------------------------------
46489    ------------------------------------------------------------------------------------
46490    -- 4219869 Business Flow
46491    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
46493    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
46494 
46495    ----------------------------------------------------------------------------------
46496    -- 4219869 Business Flow
46497    -- Update journal entry status -- Need to generate this within IF <condition>
46498    ----------------------------------------------------------------------------------
46499    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
46500          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
46501          ,p_balance_type_code => l_balance_type_code
46502          );
46503 
46504    -------------------------------------------------------------------------------------------
46505    -- 4262811 - Generate the Accrual Reversal lines
46506    -------------------------------------------------------------------------------------------
46507    BEGIN
46508       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
46509                               (g_array_event(p_event_id).array_value_num('header_index'));
46510       IF l_acc_rev_flag IS NULL THEN
46511          l_acc_rev_flag := 'N';
46512       END IF;
46513    EXCEPTION
46514       WHEN OTHERS THEN
46515          l_acc_rev_flag := 'N';
46516    END;
46517    --
46518    IF (l_acc_rev_flag = 'Y') THEN
46519 
46520        -- 4645092  ------------------------------------------------------------------------------
46521        -- To allow MPA report to determine if it should generate report process
46522        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
46523        ------------------------------------------------------------------------------------------
46524 
46525        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
46526        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
46527    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
46528    -- call ADRs
46529    -- Bug 4922099
46530    --
46531    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
46532         (NVL(l_actual_upg_option, 'N') = 'O') OR
46533         (NVL(l_enc_upg_option, 'N') = 'O')
46534       )
46535    THEN
46536    NULL;
46537    --
46538    --
46539    
46540   l_ccid := AcctDerRule_173(
46541            p_application_id           => p_application_id
46542          , p_ae_header_id             => l_ae_header_id 
46543 , p_source_3 => p_source_3
46544 , p_source_30 => p_source_30
46545          , x_transaction_coa_id       => l_adr_transaction_coa_id
46546          , x_accounting_coa_id        => l_adr_accounting_coa_id
46547          , x_value_type_code          => l_adr_value_type_code
46548          , p_side                     => 'NA'
46549    );
46550 
46551    xla_ae_lines_pkg.set_ccid(
46552     p_code_combination_id          => l_ccid
46553   , p_value_type_code              => l_adr_value_type_code
46554   , p_transaction_coa_id           => l_adr_transaction_coa_id
46555   , p_accounting_coa_id            => l_adr_accounting_coa_id
46556   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
46557   , p_adr_type_code                => 'S'
46558   , p_component_type               => l_component_type
46559   , p_component_code               => l_component_code
46560   , p_component_type_code          => l_component_type_code
46561   , p_component_appl_id            => l_component_appl_id
46562   , p_amb_context_code             => l_amb_context_code
46563   , p_side                         => 'NA'
46564   );
46565 
46566 
46567    l_segment := AcctDerRule_168(
46568            p_application_id           => p_application_id
46569          , p_ae_header_id             => l_ae_header_id 
46570 , p_source_3 => p_source_3
46571 , p_source_29 => p_source_29
46572          , x_transaction_coa_id       => l_adr_transaction_coa_id
46573          , x_accounting_coa_id        => l_adr_accounting_coa_id
46574          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
46575          , x_flex_value_set_id        => l_adr_flex_value_set_id
46576          , x_value_type_code          => l_adr_value_type_code
46577          , x_value_combination_id     => l_adr_value_combination_id
46578          , x_value_segment_code       => l_adr_value_segment_code
46579          , p_side                     => 'NA'
46580          , p_override_seg_flag        => 'Y'
46581    );
46582 
46583    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
46584 
46585       xla_ae_lines_pkg.set_segment(
46586           p_to_segment_code         => 'GL_BALANCING'
46587         , p_segment_value           => l_segment
46588         , p_from_segment_code       => l_adr_value_segment_code
46589         , p_from_combination_id     => l_adr_value_combination_id
46590         , p_value_type_code         => l_adr_value_type_code
46591         , p_transaction_coa_id      => l_adr_transaction_coa_id
46592         , p_accounting_coa_id       => l_adr_accounting_coa_id
46593         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
46594         , p_flex_value_set_id       => l_adr_flex_value_set_id
46595         , p_adr_code                => 'FA_EXPENSE_ACCT'
46596         , p_adr_type_code           => 'S'
46597         , p_component_type          => l_component_type
46598         , p_component_code          => l_component_code
46599         , p_component_type_code     => l_component_type_code
46600         , p_component_appl_id       => l_component_appl_id
46601         , p_amb_context_code        => l_amb_context_code
46602         , p_entity_code             => 'TRANSACTIONS'
46603         , p_event_class_code        => 'CIP_RETIREMENTS'
46604         , p_side                    => 'NA'
46605         );
46606 
46607   END IF;
46608 
46612 , p_source_3 => p_source_3
46609    l_segment := AcctDerRule_160(
46610            p_application_id           => p_application_id
46611          , p_ae_header_id             => l_ae_header_id 
46613 , p_source_22 => p_source_22
46614          , x_transaction_coa_id       => l_adr_transaction_coa_id
46615          , x_accounting_coa_id        => l_adr_accounting_coa_id
46616          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
46617          , x_flex_value_set_id        => l_adr_flex_value_set_id
46618          , x_value_type_code          => l_adr_value_type_code
46619          , x_value_combination_id     => l_adr_value_combination_id
46620          , x_value_segment_code       => l_adr_value_segment_code
46621          , p_side                     => 'NA'
46622          , p_override_seg_flag        => 'Y'
46623    );
46624 
46625    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
46626 
46627       xla_ae_lines_pkg.set_segment(
46628           p_to_segment_code         => 'GL_ACCOUNT'
46629         , p_segment_value           => l_segment
46630         , p_from_segment_code       => l_adr_value_segment_code
46631         , p_from_combination_id     => l_adr_value_combination_id
46632         , p_value_type_code         => l_adr_value_type_code
46633         , p_transaction_coa_id      => l_adr_transaction_coa_id
46634         , p_accounting_coa_id       => l_adr_accounting_coa_id
46635         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
46636         , p_flex_value_set_id       => l_adr_flex_value_set_id
46637         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
46638         , p_adr_type_code           => 'S'
46639         , p_component_type          => l_component_type
46640         , p_component_code          => l_component_code
46641         , p_component_type_code     => l_component_type_code
46642         , p_component_appl_id       => l_component_appl_id
46643         , p_amb_context_code        => l_amb_context_code
46644         , p_entity_code             => 'TRANSACTIONS'
46645         , p_event_class_code        => 'CIP_RETIREMENTS'
46646         , p_side                    => 'NA'
46647         );
46648 
46649   END IF;
46650 
46651    --
46652    --
46653    END IF;
46654 
46655        --
46656        -- Update the line information that should be overwritten
46657        --
46658        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
46659                                          p_header_num   => 1);
46660        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
46661 
46662        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
46663 
46664        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
46665           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
46666        END IF;
46667 
46668       --
46669       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
46670       --
46671       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
46672           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
46673       ELSE
46674           ---------------------------------------------------------------------------------------------------
46675           -- 4262811a Switch Sign
46676           ---------------------------------------------------------------------------------------------------
46677           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
46678           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
46679                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
46680           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
46681                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
46682           -- 5132302
46683           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
46684                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
46685 
46686       END IF;
46687 
46688       -- 4955764
46689       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
46690       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
46691 
46692 
46693       XLA_AE_LINES_PKG.ValidateCurrentLine;
46694       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
46695 
46696       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
46697                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
46698                ,p_balance_type_code => l_balance_type_code);
46699 
46700    END IF;
46701 
46702    -----------------------------------------------------------------------------------------
46703    -- 4262811 Multiperiod Accounting
46704    -----------------------------------------------------------------------------------------
46705      -- No MPA option is assigned.
46706 
46707 
46708 END IF;
46709 END IF;
46710 --
46711 
46712 --
46713 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
46714    trace
46715       (p_msg      => 'END of AcctLineType_219'
46716       ,p_level    => C_LEVEL_PROCEDURE
46717       ,p_module   => l_log_module);
46718 END IF;
46719 --
46720 EXCEPTION
46721   WHEN xla_exceptions_pkg.application_exception THEN
46722       RAISE;
46723   WHEN OTHERS THEN
46724        xla_exceptions_pkg.raise_message
46725            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_219');
46726 END AcctLineType_219;
46727 --
46728 
46729 ---------------------------------------
46730 --
46734 ---------------------------------------
46731 -- PRIVATE FUNCTION
46732 --         AcctLineType_220
46733 --
46735 PROCEDURE AcctLineType_220 (
46736   p_application_id        IN NUMBER
46737  ,p_event_id              IN NUMBER
46738  ,p_calculate_acctd_flag  IN VARCHAR2
46739  ,p_calculate_g_l_flag    IN VARCHAR2
46740  ,p_actual_flag           IN OUT VARCHAR2
46741  ,p_balance_type_code     OUT VARCHAR2
46742  ,p_gain_or_loss_ref      OUT VARCHAR2
46743  
46744 --Period Close Date
46745  , p_source_1            IN DATE
46746 --Generated Code Combination Identifier
46747  , p_source_3            IN NUMBER
46748 --Net Book Value Retired Loss Account
46749  , p_source_22            IN VARCHAR2
46750 --Expense Account Code Combination Identifier
46751  , p_source_29            IN NUMBER
46752 --Default Code Combination Identifier
46753  , p_source_30            IN NUMBER
46754 --Adjustment Type
46755  , p_source_35            IN VARCHAR2
46756 --Transaction Header Identifier
46757  , p_source_36            IN NUMBER
46758 --Adjustment Line Identifier
46759  , p_source_37            IN NUMBER
46760 --Distribution Type Code
46761  , p_source_38            IN VARCHAR2
46762 --Entered Amount
46763  , p_source_39            IN NUMBER
46764 --Currency Code
46765  , p_source_40            IN VARCHAR2
46766 --Gain Loss Amount
46767  , p_source_41            IN NUMBER
46768 )
46769 IS
46770 
46771 l_component_type              VARCHAR2(80);
46772 l_component_code              VARCHAR2(30);
46773 l_component_type_code         VARCHAR2(1);
46774 l_component_appl_id           INTEGER;
46775 l_amb_context_code            VARCHAR2(30);
46776 l_entity_code                 VARCHAR2(30);
46777 l_event_class_code            VARCHAR2(30);
46778 l_ae_header_id                NUMBER;
46779 l_event_type_code             VARCHAR2(30);
46780 l_line_definition_code        VARCHAR2(30);
46781 l_line_definition_owner_code  VARCHAR2(1);
46782 --
46783 -- adr variables
46784 l_segment                     VARCHAR2(30);
46785 l_ccid                        NUMBER;
46786 l_adr_transaction_coa_id      NUMBER;
46787 l_adr_accounting_coa_id       NUMBER;
46788 l_adr_flexfield_segment_code  VARCHAR2(30);
46789 l_adr_flex_value_set_id       NUMBER;
46790 l_adr_value_type_code         VARCHAR2(30);
46791 l_adr_value_combination_id    NUMBER;
46792 l_adr_value_segment_code      VARCHAR2(30);
46793 
46794 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
46795 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
46796 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
46797 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
46798 
46799 -- 4262811 Variables ------------------------------------------------------------------------------------------
46800 l_entered_amt_idx             NUMBER;
46801 l_accted_amt_idx              NUMBER;
46802 l_acc_rev_flag                VARCHAR2(1);
46803 l_accrual_line_num            NUMBER;
46804 l_tmp_amt                     NUMBER;
46805 l_acc_rev_natural_side_code   VARCHAR2(1);
46806 
46807 l_num_entries                 NUMBER;
46808 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
46809 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
46810 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
46811 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
46812 l_recog_line_1                NUMBER;
46813 l_recog_line_2                NUMBER;
46814 
46815 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
46816 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
46817 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
46818 
46819 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
46820 
46821 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
46822 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
46823 
46824 ---------------------------------------------------------------------------------------------------------------
46825 
46826 
46827 --
46828 -- bulk performance
46829 --
46830 l_balance_type_code           VARCHAR2(1);
46831 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
46832 l_log_module                  VARCHAR2(240);
46833 
46834 --
46835 -- Upgrade strategy
46836 --
46837 l_actual_upg_option           VARCHAR2(1);
46838 l_enc_upg_option           VARCHAR2(1);
46839 
46840 --
46841 BEGIN
46842 --
46843 IF g_log_enabled THEN
46844       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_220';
46845 END IF;
46846 --
46847 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
46848 
46849       trace
46850          (p_msg      => 'BEGIN of AcctLineType_220'
46851          ,p_level    => C_LEVEL_PROCEDURE
46852          ,p_module   => l_log_module);
46853 
46854 END IF;
46855 --
46856 l_component_type             := 'AMB_JLT';
46857 l_component_code             := 'FA_CIP_NBV_RETIRED_LOSS';
46858 l_component_type_code        := 'S';
46859 l_component_appl_id          :=  140;
46860 l_amb_context_code           := 'DEFAULT';
46861 l_entity_code                := 'TRANSACTIONS';
46862 l_event_class_code           := 'CIP_RETIREMENTS';
46863 l_event_type_code            := 'CIP_RETIREMENTS';
46864 l_line_definition_owner_code := 'S';
46865 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
46866 --
46867 l_balance_type_code          := 'A';
46868 l_segment                     := NULL;
46869 l_ccid                        := NULL;
46870 l_adr_transaction_coa_id      := NULL;
46871 l_adr_accounting_coa_id       := NULL;
46872 l_adr_flexfield_segment_code  := NULL;
46876 l_adr_value_segment_code      := NULL;
46873 l_adr_flex_value_set_id       := NULL;
46874 l_adr_value_type_code         := NULL;
46875 l_adr_value_combination_id    := NULL;
46877 
46878 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
46879 l_bflow_class_code           := '';    -- 4219869 Business Flow
46880 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
46881 l_budgetary_control_flag     := 'N';
46882 
46883 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
46884 l_bflow_applied_to_amt       := NULL; -- 5132302
46885 l_entered_amt_idx            := NULL;          -- 4262811
46886 l_accted_amt_idx             := NULL;          -- 4262811
46887 l_acc_rev_flag               := NULL;          -- 4262811
46888 l_accrual_line_num           := NULL;          -- 4262811
46889 l_tmp_amt                    := NULL;          -- 4262811
46890 --
46891  
46892 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
46893     l_balance_type_code <> 'B' THEN
46894 IF NVL(p_source_35,'
46895 ') =  'NBV RETIRED' AND 
46896 p_source_41 <  0
46897  THEN 
46898 
46899    --
46900    XLA_AE_LINES_PKG.SetNewLine;
46901 
46902    p_balance_type_code          := l_balance_type_code;
46903    -- set the flag so later we will know whether the gain loss line needs to be created
46904    
46905    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
46906      p_actual_flag :='A';
46907    END IF;
46908 
46909    --
46910    -- bulk performance
46911    --
46912    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
46913                                       p_header_num   => 0); -- 4262811
46914    --
46915    -- set accounting line options
46916    --
46917    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
46918            p_natural_side_code          => 'D'
46919          , p_gain_or_loss_flag          => 'N'
46920          , p_gl_transfer_mode_code      => 'S'
46921          , p_acct_entry_type_code       => 'A'
46922          , p_switch_side_flag           => 'Y'
46923          , p_merge_duplicate_code       => 'N'
46924          );
46925    --
46926    l_acc_rev_natural_side_code := 'C';  -- 4262811
46927    -- 
46928    --
46929    -- set accounting line type info
46930    --
46931    xla_ae_lines_pkg.SetAcctLineType
46932       (p_component_type             => l_component_type
46933       ,p_event_type_code            => l_event_type_code
46934       ,p_line_definition_owner_code => l_line_definition_owner_code
46935       ,p_line_definition_code       => l_line_definition_code
46936       ,p_accounting_line_code       => l_component_code
46937       ,p_accounting_line_type_code  => l_component_type_code
46938       ,p_accounting_line_appl_id    => l_component_appl_id
46939       ,p_amb_context_code           => l_amb_context_code
46940       ,p_entity_code                => l_entity_code
46941       ,p_event_class_code           => l_event_class_code);
46942    --
46943    -- set accounting class
46944    --
46945    xla_ae_lines_pkg.SetAcctClass(
46946            p_accounting_class_code  => 'ASSET'
46947          , p_ae_header_id           => l_ae_header_id
46948          );
46949 
46950    --
46951    -- set rounding class
46952    --
46953    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
46954                       'ASSET';
46955 
46956    --
46957    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
46958    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
46959    --
46960    -- bulk performance
46961    --
46962    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
46963 
46964    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
46965       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
46966 
46967    -- 4955764
46968    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
46969       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
46970 
46971    -- 4458381 Public Sector Enh
46972    
46973    --
46974    -- set accounting attributes for the line type
46975    --
46976    l_entered_amt_idx := 4;
46977    l_accted_amt_idx  := 6;
46978    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
46979    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
46980    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
46981    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
46982    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
46983    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
46984    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
46985    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
46986    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
46987    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
46988    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
46989    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
46990    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
46991 
46992    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
46993    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
46994 
46995    ---------------------------------------------------------------------------------------------------------------
46996    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
46997    ---------------------------------------------------------------------------------------------------------------
47001    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46998    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
46999 
47000    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
47002 
47003    IF xla_accounting_cache_pkg.GetValueChar
47004          (p_source_code         => 'LEDGER_CATEGORY_CODE'
47005          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
47006    AND l_bflow_method_code = 'PRIOR_ENTRY'
47007 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
47008    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
47009          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
47010        )
47011    THEN
47012          xla_ae_lines_pkg.BflowUpgEntry
47013            (p_business_method_code    => l_bflow_method_code
47014            ,p_business_class_code     => l_bflow_class_code
47015            ,p_balance_type            => l_balance_type_code);
47016    ELSE
47017       NULL;
47018 -- No business flow processing for business flow method of NONE.
47019    END IF;
47020 
47021    --
47022    -- call analytical criteria
47023    --
47024    
47025    --
47026    -- call description
47027    --
47028    
47029 xla_ae_lines_pkg.SetLineDescription(
47030    p_ae_header_id => l_ae_header_id
47031   ,p_description  => Description_34 (
47032      p_application_id         => p_application_id
47033    , p_ae_header_id           => l_ae_header_id 
47034 , p_source_1 => p_source_1
47035    )
47036 );
47037 
47038 
47039    --
47040    -- call ADRs
47041    -- Bug 4922099
47042    --
47043    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
47044         (NVL(l_actual_upg_option, 'N') = 'O') OR
47045         (NVL(l_enc_upg_option, 'N') = 'O')
47046       )
47047    THEN
47048    NULL;
47049    --
47050    --
47051    
47052   l_ccid := AcctDerRule_173(
47053            p_application_id           => p_application_id
47054          , p_ae_header_id             => l_ae_header_id 
47055 , p_source_3 => p_source_3
47056 , p_source_30 => p_source_30
47057          , x_transaction_coa_id       => l_adr_transaction_coa_id
47058          , x_accounting_coa_id        => l_adr_accounting_coa_id
47059          , x_value_type_code          => l_adr_value_type_code
47060          , p_side                     => 'NA'
47061    );
47062 
47063    xla_ae_lines_pkg.set_ccid(
47064     p_code_combination_id          => l_ccid
47065   , p_value_type_code              => l_adr_value_type_code
47066   , p_transaction_coa_id           => l_adr_transaction_coa_id
47067   , p_accounting_coa_id            => l_adr_accounting_coa_id
47068   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
47069   , p_adr_type_code                => 'S'
47070   , p_component_type               => l_component_type
47071   , p_component_code               => l_component_code
47072   , p_component_type_code          => l_component_type_code
47073   , p_component_appl_id            => l_component_appl_id
47074   , p_amb_context_code             => l_amb_context_code
47075   , p_side                         => 'NA'
47076   );
47077 
47078 
47079    l_segment := AcctDerRule_168(
47080            p_application_id           => p_application_id
47081          , p_ae_header_id             => l_ae_header_id 
47082 , p_source_3 => p_source_3
47083 , p_source_29 => p_source_29
47084          , x_transaction_coa_id       => l_adr_transaction_coa_id
47085          , x_accounting_coa_id        => l_adr_accounting_coa_id
47086          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
47087          , x_flex_value_set_id        => l_adr_flex_value_set_id
47088          , x_value_type_code          => l_adr_value_type_code
47089          , x_value_combination_id     => l_adr_value_combination_id
47090          , x_value_segment_code       => l_adr_value_segment_code
47091          , p_side                     => 'NA'
47092          , p_override_seg_flag        => 'Y'
47093    );
47094 
47095    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
47096 
47097       xla_ae_lines_pkg.set_segment(
47098           p_to_segment_code         => 'GL_BALANCING'
47099         , p_segment_value           => l_segment
47100         , p_from_segment_code       => l_adr_value_segment_code
47101         , p_from_combination_id     => l_adr_value_combination_id
47102         , p_value_type_code         => l_adr_value_type_code
47103         , p_transaction_coa_id      => l_adr_transaction_coa_id
47104         , p_accounting_coa_id       => l_adr_accounting_coa_id
47105         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
47106         , p_flex_value_set_id       => l_adr_flex_value_set_id
47107         , p_adr_code                => 'FA_EXPENSE_ACCT'
47108         , p_adr_type_code           => 'S'
47109         , p_component_type          => l_component_type
47110         , p_component_code          => l_component_code
47111         , p_component_type_code     => l_component_type_code
47112         , p_component_appl_id       => l_component_appl_id
47113         , p_amb_context_code        => l_amb_context_code
47114         , p_entity_code             => 'TRANSACTIONS'
47115         , p_event_class_code        => 'CIP_RETIREMENTS'
47116         , p_side                    => 'NA'
47117         );
47118 
47119   END IF;
47120 
47121    l_segment := AcctDerRule_160(
47122            p_application_id           => p_application_id
47123          , p_ae_header_id             => l_ae_header_id 
47124 , p_source_3 => p_source_3
47125 , p_source_22 => p_source_22
47126          , x_transaction_coa_id       => l_adr_transaction_coa_id
47127          , x_accounting_coa_id        => l_adr_accounting_coa_id
47131          , x_value_combination_id     => l_adr_value_combination_id
47128          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
47129          , x_flex_value_set_id        => l_adr_flex_value_set_id
47130          , x_value_type_code          => l_adr_value_type_code
47132          , x_value_segment_code       => l_adr_value_segment_code
47133          , p_side                     => 'NA'
47134          , p_override_seg_flag        => 'Y'
47135    );
47136 
47137    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
47138 
47139       xla_ae_lines_pkg.set_segment(
47140           p_to_segment_code         => 'GL_ACCOUNT'
47141         , p_segment_value           => l_segment
47142         , p_from_segment_code       => l_adr_value_segment_code
47143         , p_from_combination_id     => l_adr_value_combination_id
47144         , p_value_type_code         => l_adr_value_type_code
47145         , p_transaction_coa_id      => l_adr_transaction_coa_id
47146         , p_accounting_coa_id       => l_adr_accounting_coa_id
47147         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
47148         , p_flex_value_set_id       => l_adr_flex_value_set_id
47149         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
47150         , p_adr_type_code           => 'S'
47151         , p_component_type          => l_component_type
47152         , p_component_code          => l_component_code
47153         , p_component_type_code     => l_component_type_code
47154         , p_component_appl_id       => l_component_appl_id
47155         , p_amb_context_code        => l_amb_context_code
47156         , p_entity_code             => 'TRANSACTIONS'
47157         , p_event_class_code        => 'CIP_RETIREMENTS'
47158         , p_side                    => 'NA'
47159         );
47160 
47161   END IF;
47162 
47163    --
47164    --
47165    END IF;
47166    --
47167    -- Bug 4922099
47168    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
47169           (NVL(l_enc_upg_option, 'N') = 'O')
47170         ) AND
47171         (l_bflow_method_code = 'PRIOR_ENTRY')
47172       )
47173    THEN
47174       IF
47175       --
47176       1 = 2
47177       --
47178       THEN
47179       xla_accounting_err_pkg.build_message
47180                                     (p_appli_s_name            => 'XLA'
47181                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
47182                                     ,p_token_1                 => 'LINE_NUMBER'
47183                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
47184                                     ,p_token_2                 => 'LINE_TYPE_NAME'
47185                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
47186                                                                              l_component_type
47187                                                                             ,l_component_code
47188                                                                             ,l_component_type_code
47189                                                                             ,l_component_appl_id
47190                                                                             ,l_amb_context_code
47191                                                                             ,l_entity_code
47192                                                                             ,l_event_class_code
47193                                                                            )
47194                                     ,p_token_3                 => 'OWNER'
47195                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
47196                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
47197                                                                           ,p_lookup_code    => l_component_type_code
47198                                                                          )
47199                                     ,p_token_4                 => 'PRODUCT_NAME'
47200                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
47201                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
47202                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
47203                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
47204                                     ,p_ae_header_id            =>  NULL
47205                                        );
47206 
47207         IF (C_LEVEL_ERROR>= g_log_level) THEN
47208                  trace
47209                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
47210                       ,p_level    => C_LEVEL_ERROR
47211                       ,p_module   => l_log_module);
47212         END IF;
47213       END IF;
47214    END IF;
47215    --
47216    --
47217    ------------------------------------------------------------------------------------------------
47218    -- 4219869 Business Flow
47219    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
47220    -- Prior Entry.  Currently, the following code is always generated.
47221    ------------------------------------------------------------------------------------------------
47222    XLA_AE_LINES_PKG.ValidateCurrentLine;
47223 
47224    ------------------------------------------------------------------------------------
47225    -- 4219869 Business Flow
47226    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
47227    ------------------------------------------------------------------------------------
47228    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
47229 
47230    ----------------------------------------------------------------------------------
47231    -- 4219869 Business Flow
47235          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
47232    -- Update journal entry status -- Need to generate this within IF <condition>
47233    ----------------------------------------------------------------------------------
47234    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
47236          ,p_balance_type_code => l_balance_type_code
47237          );
47238 
47239    -------------------------------------------------------------------------------------------
47240    -- 4262811 - Generate the Accrual Reversal lines
47241    -------------------------------------------------------------------------------------------
47242    BEGIN
47243       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
47244                               (g_array_event(p_event_id).array_value_num('header_index'));
47245       IF l_acc_rev_flag IS NULL THEN
47246          l_acc_rev_flag := 'N';
47247       END IF;
47248    EXCEPTION
47249       WHEN OTHERS THEN
47250          l_acc_rev_flag := 'N';
47251    END;
47252    --
47253    IF (l_acc_rev_flag = 'Y') THEN
47254 
47255        -- 4645092  ------------------------------------------------------------------------------
47256        -- To allow MPA report to determine if it should generate report process
47257        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
47258        ------------------------------------------------------------------------------------------
47259 
47260        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
47261        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
47262    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
47263    -- call ADRs
47264    -- Bug 4922099
47265    --
47266    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
47267         (NVL(l_actual_upg_option, 'N') = 'O') OR
47268         (NVL(l_enc_upg_option, 'N') = 'O')
47269       )
47270    THEN
47271    NULL;
47272    --
47273    --
47274    
47275   l_ccid := AcctDerRule_173(
47276            p_application_id           => p_application_id
47277          , p_ae_header_id             => l_ae_header_id 
47278 , p_source_3 => p_source_3
47279 , p_source_30 => p_source_30
47280          , x_transaction_coa_id       => l_adr_transaction_coa_id
47281          , x_accounting_coa_id        => l_adr_accounting_coa_id
47282          , x_value_type_code          => l_adr_value_type_code
47283          , p_side                     => 'NA'
47284    );
47285 
47286    xla_ae_lines_pkg.set_ccid(
47287     p_code_combination_id          => l_ccid
47288   , p_value_type_code              => l_adr_value_type_code
47289   , p_transaction_coa_id           => l_adr_transaction_coa_id
47290   , p_accounting_coa_id            => l_adr_accounting_coa_id
47291   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
47292   , p_adr_type_code                => 'S'
47293   , p_component_type               => l_component_type
47294   , p_component_code               => l_component_code
47295   , p_component_type_code          => l_component_type_code
47296   , p_component_appl_id            => l_component_appl_id
47297   , p_amb_context_code             => l_amb_context_code
47298   , p_side                         => 'NA'
47299   );
47300 
47301 
47302    l_segment := AcctDerRule_168(
47303            p_application_id           => p_application_id
47304          , p_ae_header_id             => l_ae_header_id 
47305 , p_source_3 => p_source_3
47306 , p_source_29 => p_source_29
47307          , x_transaction_coa_id       => l_adr_transaction_coa_id
47308          , x_accounting_coa_id        => l_adr_accounting_coa_id
47309          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
47310          , x_flex_value_set_id        => l_adr_flex_value_set_id
47311          , x_value_type_code          => l_adr_value_type_code
47312          , x_value_combination_id     => l_adr_value_combination_id
47313          , x_value_segment_code       => l_adr_value_segment_code
47314          , p_side                     => 'NA'
47315          , p_override_seg_flag        => 'Y'
47316    );
47317 
47318    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
47319 
47320       xla_ae_lines_pkg.set_segment(
47321           p_to_segment_code         => 'GL_BALANCING'
47322         , p_segment_value           => l_segment
47323         , p_from_segment_code       => l_adr_value_segment_code
47324         , p_from_combination_id     => l_adr_value_combination_id
47325         , p_value_type_code         => l_adr_value_type_code
47326         , p_transaction_coa_id      => l_adr_transaction_coa_id
47327         , p_accounting_coa_id       => l_adr_accounting_coa_id
47328         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
47329         , p_flex_value_set_id       => l_adr_flex_value_set_id
47330         , p_adr_code                => 'FA_EXPENSE_ACCT'
47331         , p_adr_type_code           => 'S'
47332         , p_component_type          => l_component_type
47333         , p_component_code          => l_component_code
47334         , p_component_type_code     => l_component_type_code
47335         , p_component_appl_id       => l_component_appl_id
47336         , p_amb_context_code        => l_amb_context_code
47337         , p_entity_code             => 'TRANSACTIONS'
47338         , p_event_class_code        => 'CIP_RETIREMENTS'
47339         , p_side                    => 'NA'
47340         );
47341 
47342   END IF;
47343 
47344    l_segment := AcctDerRule_160(
47345            p_application_id           => p_application_id
47346          , p_ae_header_id             => l_ae_header_id 
47347 , p_source_3 => p_source_3
47348 , p_source_22 => p_source_22
47349          , x_transaction_coa_id       => l_adr_transaction_coa_id
47350          , x_accounting_coa_id        => l_adr_accounting_coa_id
47351          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
47355          , x_value_segment_code       => l_adr_value_segment_code
47352          , x_flex_value_set_id        => l_adr_flex_value_set_id
47353          , x_value_type_code          => l_adr_value_type_code
47354          , x_value_combination_id     => l_adr_value_combination_id
47356          , p_side                     => 'NA'
47357          , p_override_seg_flag        => 'Y'
47358    );
47359 
47360    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
47361 
47362       xla_ae_lines_pkg.set_segment(
47363           p_to_segment_code         => 'GL_ACCOUNT'
47364         , p_segment_value           => l_segment
47365         , p_from_segment_code       => l_adr_value_segment_code
47366         , p_from_combination_id     => l_adr_value_combination_id
47367         , p_value_type_code         => l_adr_value_type_code
47368         , p_transaction_coa_id      => l_adr_transaction_coa_id
47369         , p_accounting_coa_id       => l_adr_accounting_coa_id
47370         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
47371         , p_flex_value_set_id       => l_adr_flex_value_set_id
47372         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
47373         , p_adr_type_code           => 'S'
47374         , p_component_type          => l_component_type
47375         , p_component_code          => l_component_code
47376         , p_component_type_code     => l_component_type_code
47377         , p_component_appl_id       => l_component_appl_id
47378         , p_amb_context_code        => l_amb_context_code
47379         , p_entity_code             => 'TRANSACTIONS'
47380         , p_event_class_code        => 'CIP_RETIREMENTS'
47381         , p_side                    => 'NA'
47382         );
47383 
47384   END IF;
47385 
47386    --
47387    --
47388    END IF;
47389 
47390        --
47391        -- Update the line information that should be overwritten
47392        --
47393        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
47394                                          p_header_num   => 1);
47395        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
47396 
47397        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
47398 
47399        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
47400           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
47401        END IF;
47402 
47403       --
47404       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
47405       --
47406       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
47407           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
47408       ELSE
47409           ---------------------------------------------------------------------------------------------------
47410           -- 4262811a Switch Sign
47411           ---------------------------------------------------------------------------------------------------
47412           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
47413           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47414                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47415           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47416                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47417           -- 5132302
47418           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
47419                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47420 
47421       END IF;
47422 
47423       -- 4955764
47424       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47425       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
47426 
47427 
47428       XLA_AE_LINES_PKG.ValidateCurrentLine;
47429       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
47430 
47431       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
47432                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
47433                ,p_balance_type_code => l_balance_type_code);
47434 
47435    END IF;
47436 
47437    -----------------------------------------------------------------------------------------
47438    -- 4262811 Multiperiod Accounting
47439    -----------------------------------------------------------------------------------------
47440      -- No MPA option is assigned.
47441 
47442 
47443 END IF;
47444 END IF;
47445 --
47446 
47447 --
47448 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47449    trace
47450       (p_msg      => 'END of AcctLineType_220'
47451       ,p_level    => C_LEVEL_PROCEDURE
47452       ,p_module   => l_log_module);
47453 END IF;
47454 --
47455 EXCEPTION
47456   WHEN xla_exceptions_pkg.application_exception THEN
47457       RAISE;
47458   WHEN OTHERS THEN
47459        xla_exceptions_pkg.raise_message
47460            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_220');
47461 END AcctLineType_220;
47462 --
47463 
47464 ---------------------------------------
47465 --
47466 -- PRIVATE FUNCTION
47467 --         AcctLineType_221
47468 --
47469 ---------------------------------------
47470 PROCEDURE AcctLineType_221 (
47471   p_application_id        IN NUMBER
47472  ,p_event_id              IN NUMBER
47473  ,p_calculate_acctd_flag  IN VARCHAR2
47474  ,p_calculate_g_l_flag    IN VARCHAR2
47475  ,p_actual_flag           IN OUT VARCHAR2
47476  ,p_balance_type_code     OUT VARCHAR2
47480  , p_source_1            IN DATE
47477  ,p_gain_or_loss_ref      OUT VARCHAR2
47478  
47479 --Period Close Date
47481 --Generated Code Combination Identifier
47482  , p_source_3            IN NUMBER
47483 --Proceeds Of Sale Clearing Account
47484  , p_source_23            IN VARCHAR2
47485 --Expense Account Code Combination Identifier
47486  , p_source_29            IN NUMBER
47487 --Default Code Combination Identifier
47488  , p_source_30            IN NUMBER
47489 --Adjustment Type
47490  , p_source_35            IN VARCHAR2
47491 --Transaction Header Identifier
47492  , p_source_36            IN NUMBER
47493 --Adjustment Line Identifier
47494  , p_source_37            IN NUMBER
47495 --Distribution Type Code
47496  , p_source_38            IN VARCHAR2
47497 --Entered Amount
47498  , p_source_39            IN NUMBER
47499 --Currency Code
47500  , p_source_40            IN VARCHAR2
47501 )
47502 IS
47503 
47504 l_component_type              VARCHAR2(80);
47505 l_component_code              VARCHAR2(30);
47506 l_component_type_code         VARCHAR2(1);
47507 l_component_appl_id           INTEGER;
47508 l_amb_context_code            VARCHAR2(30);
47509 l_entity_code                 VARCHAR2(30);
47510 l_event_class_code            VARCHAR2(30);
47511 l_ae_header_id                NUMBER;
47512 l_event_type_code             VARCHAR2(30);
47513 l_line_definition_code        VARCHAR2(30);
47514 l_line_definition_owner_code  VARCHAR2(1);
47515 --
47516 -- adr variables
47517 l_segment                     VARCHAR2(30);
47518 l_ccid                        NUMBER;
47519 l_adr_transaction_coa_id      NUMBER;
47520 l_adr_accounting_coa_id       NUMBER;
47521 l_adr_flexfield_segment_code  VARCHAR2(30);
47522 l_adr_flex_value_set_id       NUMBER;
47523 l_adr_value_type_code         VARCHAR2(30);
47524 l_adr_value_combination_id    NUMBER;
47525 l_adr_value_segment_code      VARCHAR2(30);
47526 
47527 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
47528 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
47529 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
47530 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
47531 
47532 -- 4262811 Variables ------------------------------------------------------------------------------------------
47533 l_entered_amt_idx             NUMBER;
47534 l_accted_amt_idx              NUMBER;
47535 l_acc_rev_flag                VARCHAR2(1);
47536 l_accrual_line_num            NUMBER;
47537 l_tmp_amt                     NUMBER;
47538 l_acc_rev_natural_side_code   VARCHAR2(1);
47539 
47540 l_num_entries                 NUMBER;
47541 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
47542 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
47543 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
47544 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
47545 l_recog_line_1                NUMBER;
47546 l_recog_line_2                NUMBER;
47547 
47548 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
47549 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
47550 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
47551 
47552 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
47553 
47554 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
47555 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
47556 
47557 ---------------------------------------------------------------------------------------------------------------
47558 
47559 
47560 --
47561 -- bulk performance
47562 --
47563 l_balance_type_code           VARCHAR2(1);
47564 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
47565 l_log_module                  VARCHAR2(240);
47566 
47567 --
47568 -- Upgrade strategy
47569 --
47570 l_actual_upg_option           VARCHAR2(1);
47571 l_enc_upg_option           VARCHAR2(1);
47572 
47573 --
47574 BEGIN
47575 --
47576 IF g_log_enabled THEN
47577       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_221';
47578 END IF;
47579 --
47580 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47581 
47582       trace
47583          (p_msg      => 'BEGIN of AcctLineType_221'
47584          ,p_level    => C_LEVEL_PROCEDURE
47585          ,p_module   => l_log_module);
47586 
47587 END IF;
47588 --
47589 l_component_type             := 'AMB_JLT';
47590 l_component_code             := 'FA_CIP_PROC_OF_SALE_CLR';
47591 l_component_type_code        := 'S';
47592 l_component_appl_id          :=  140;
47593 l_amb_context_code           := 'DEFAULT';
47594 l_entity_code                := 'TRANSACTIONS';
47595 l_event_class_code           := 'CIP_RETIREMENTS';
47596 l_event_type_code            := 'CIP_REINSTATEMENTS';
47597 l_line_definition_owner_code := 'S';
47598 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
47599 --
47600 l_balance_type_code          := 'A';
47601 l_segment                     := NULL;
47602 l_ccid                        := NULL;
47603 l_adr_transaction_coa_id      := NULL;
47604 l_adr_accounting_coa_id       := NULL;
47605 l_adr_flexfield_segment_code  := NULL;
47606 l_adr_flex_value_set_id       := NULL;
47607 l_adr_value_type_code         := NULL;
47608 l_adr_value_combination_id    := NULL;
47609 l_adr_value_segment_code      := NULL;
47610 
47611 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
47612 l_bflow_class_code           := '';    -- 4219869 Business Flow
47613 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
47614 l_budgetary_control_flag     := 'N';
47615 
47616 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
47620 l_acc_rev_flag               := NULL;          -- 4262811
47617 l_bflow_applied_to_amt       := NULL; -- 5132302
47618 l_entered_amt_idx            := NULL;          -- 4262811
47619 l_accted_amt_idx             := NULL;          -- 4262811
47621 l_accrual_line_num           := NULL;          -- 4262811
47622 l_tmp_amt                    := NULL;          -- 4262811
47623 --
47624  
47625 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
47626     l_balance_type_code <> 'B' THEN
47627 IF NVL(p_source_35,'
47628 ') =  'PROCEEDS CLR'
47629  THEN 
47630 
47631    --
47632    XLA_AE_LINES_PKG.SetNewLine;
47633 
47634    p_balance_type_code          := l_balance_type_code;
47635    -- set the flag so later we will know whether the gain loss line needs to be created
47636    
47637    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
47638      p_actual_flag :='A';
47639    END IF;
47640 
47641    --
47642    -- bulk performance
47643    --
47644    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
47645                                       p_header_num   => 0); -- 4262811
47646    --
47647    -- set accounting line options
47648    --
47649    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
47650            p_natural_side_code          => 'D'
47651          , p_gain_or_loss_flag          => 'N'
47652          , p_gl_transfer_mode_code      => 'S'
47653          , p_acct_entry_type_code       => 'A'
47654          , p_switch_side_flag           => 'Y'
47655          , p_merge_duplicate_code       => 'N'
47656          );
47657    --
47658    l_acc_rev_natural_side_code := 'C';  -- 4262811
47659    -- 
47660    --
47661    -- set accounting line type info
47662    --
47663    xla_ae_lines_pkg.SetAcctLineType
47664       (p_component_type             => l_component_type
47665       ,p_event_type_code            => l_event_type_code
47666       ,p_line_definition_owner_code => l_line_definition_owner_code
47667       ,p_line_definition_code       => l_line_definition_code
47668       ,p_accounting_line_code       => l_component_code
47669       ,p_accounting_line_type_code  => l_component_type_code
47670       ,p_accounting_line_appl_id    => l_component_appl_id
47671       ,p_amb_context_code           => l_amb_context_code
47672       ,p_entity_code                => l_entity_code
47673       ,p_event_class_code           => l_event_class_code);
47674    --
47675    -- set accounting class
47676    --
47677    xla_ae_lines_pkg.SetAcctClass(
47678            p_accounting_class_code  => 'ASSET'
47679          , p_ae_header_id           => l_ae_header_id
47680          );
47681 
47682    --
47683    -- set rounding class
47684    --
47685    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
47686                       'ASSET';
47687 
47688    --
47689    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
47690    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
47691    --
47692    -- bulk performance
47693    --
47694    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
47695 
47696    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
47697       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
47698 
47699    -- 4955764
47700    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47701       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
47702 
47703    -- 4458381 Public Sector Enh
47704    
47705    --
47706    -- set accounting attributes for the line type
47707    --
47708    l_entered_amt_idx := 4;
47709    l_accted_amt_idx  := 6;
47710    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
47711    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
47712    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
47713    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
47714    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
47715    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
47716    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
47717    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
47718    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
47719    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
47720    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
47721    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
47722    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
47723 
47724    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
47725    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
47726 
47727    ---------------------------------------------------------------------------------------------------------------
47728    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
47729    ---------------------------------------------------------------------------------------------------------------
47730    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
47731 
47732    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
47733    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
47734 
47735    IF xla_accounting_cache_pkg.GetValueChar
47736          (p_source_code         => 'LEDGER_CATEGORY_CODE'
47737          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
47738    AND l_bflow_method_code = 'PRIOR_ENTRY'
47742        )
47739 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
47740    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
47741          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
47743    THEN
47744          xla_ae_lines_pkg.BflowUpgEntry
47745            (p_business_method_code    => l_bflow_method_code
47746            ,p_business_class_code     => l_bflow_class_code
47747            ,p_balance_type            => l_balance_type_code);
47748    ELSE
47749       NULL;
47750 -- No business flow processing for business flow method of NONE.
47751    END IF;
47752 
47753    --
47754    -- call analytical criteria
47755    --
47756    
47757    --
47758    -- call description
47759    --
47760    
47761 xla_ae_lines_pkg.SetLineDescription(
47762    p_ae_header_id => l_ae_header_id
47763   ,p_description  => Description_38 (
47764      p_application_id         => p_application_id
47765    , p_ae_header_id           => l_ae_header_id 
47766 , p_source_1 => p_source_1
47767    )
47768 );
47769 
47770 
47771    --
47772    -- call ADRs
47773    -- Bug 4922099
47774    --
47775    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
47776         (NVL(l_actual_upg_option, 'N') = 'O') OR
47777         (NVL(l_enc_upg_option, 'N') = 'O')
47778       )
47779    THEN
47780    NULL;
47781    --
47782    --
47783    
47784   l_ccid := AcctDerRule_173(
47785            p_application_id           => p_application_id
47786          , p_ae_header_id             => l_ae_header_id 
47787 , p_source_3 => p_source_3
47788 , p_source_30 => p_source_30
47789          , x_transaction_coa_id       => l_adr_transaction_coa_id
47790          , x_accounting_coa_id        => l_adr_accounting_coa_id
47791          , x_value_type_code          => l_adr_value_type_code
47792          , p_side                     => 'NA'
47793    );
47794 
47795    xla_ae_lines_pkg.set_ccid(
47796     p_code_combination_id          => l_ccid
47797   , p_value_type_code              => l_adr_value_type_code
47798   , p_transaction_coa_id           => l_adr_transaction_coa_id
47799   , p_accounting_coa_id            => l_adr_accounting_coa_id
47800   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
47801   , p_adr_type_code                => 'S'
47802   , p_component_type               => l_component_type
47803   , p_component_code               => l_component_code
47804   , p_component_type_code          => l_component_type_code
47805   , p_component_appl_id            => l_component_appl_id
47806   , p_amb_context_code             => l_amb_context_code
47807   , p_side                         => 'NA'
47808   );
47809 
47810 
47811    l_segment := AcctDerRule_168(
47812            p_application_id           => p_application_id
47813          , p_ae_header_id             => l_ae_header_id 
47814 , p_source_3 => p_source_3
47815 , p_source_29 => p_source_29
47816          , x_transaction_coa_id       => l_adr_transaction_coa_id
47817          , x_accounting_coa_id        => l_adr_accounting_coa_id
47818          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
47819          , x_flex_value_set_id        => l_adr_flex_value_set_id
47820          , x_value_type_code          => l_adr_value_type_code
47821          , x_value_combination_id     => l_adr_value_combination_id
47822          , x_value_segment_code       => l_adr_value_segment_code
47823          , p_side                     => 'NA'
47824          , p_override_seg_flag        => 'Y'
47825    );
47826 
47827    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
47828 
47829       xla_ae_lines_pkg.set_segment(
47830           p_to_segment_code         => 'GL_BALANCING'
47831         , p_segment_value           => l_segment
47832         , p_from_segment_code       => l_adr_value_segment_code
47833         , p_from_combination_id     => l_adr_value_combination_id
47834         , p_value_type_code         => l_adr_value_type_code
47835         , p_transaction_coa_id      => l_adr_transaction_coa_id
47836         , p_accounting_coa_id       => l_adr_accounting_coa_id
47837         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
47838         , p_flex_value_set_id       => l_adr_flex_value_set_id
47839         , p_adr_code                => 'FA_EXPENSE_ACCT'
47840         , p_adr_type_code           => 'S'
47841         , p_component_type          => l_component_type
47842         , p_component_code          => l_component_code
47843         , p_component_type_code     => l_component_type_code
47844         , p_component_appl_id       => l_component_appl_id
47845         , p_amb_context_code        => l_amb_context_code
47846         , p_entity_code             => 'TRANSACTIONS'
47847         , p_event_class_code        => 'CIP_RETIREMENTS'
47848         , p_side                    => 'NA'
47849         );
47850 
47851   END IF;
47852 
47853    l_segment := AcctDerRule_161(
47854            p_application_id           => p_application_id
47855          , p_ae_header_id             => l_ae_header_id 
47856 , p_source_3 => p_source_3
47857 , p_source_23 => p_source_23
47858          , x_transaction_coa_id       => l_adr_transaction_coa_id
47859          , x_accounting_coa_id        => l_adr_accounting_coa_id
47860          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
47861          , x_flex_value_set_id        => l_adr_flex_value_set_id
47862          , x_value_type_code          => l_adr_value_type_code
47863          , x_value_combination_id     => l_adr_value_combination_id
47864          , x_value_segment_code       => l_adr_value_segment_code
47865          , p_side                     => 'NA'
47866          , p_override_seg_flag        => 'Y'
47867    );
47868 
47869    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
47870 
47871       xla_ae_lines_pkg.set_segment(
47872           p_to_segment_code         => 'GL_ACCOUNT'
47876         , p_value_type_code         => l_adr_value_type_code
47873         , p_segment_value           => l_segment
47874         , p_from_segment_code       => l_adr_value_segment_code
47875         , p_from_combination_id     => l_adr_value_combination_id
47877         , p_transaction_coa_id      => l_adr_transaction_coa_id
47878         , p_accounting_coa_id       => l_adr_accounting_coa_id
47879         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
47880         , p_flex_value_set_id       => l_adr_flex_value_set_id
47881         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
47882         , p_adr_type_code           => 'S'
47883         , p_component_type          => l_component_type
47884         , p_component_code          => l_component_code
47885         , p_component_type_code     => l_component_type_code
47886         , p_component_appl_id       => l_component_appl_id
47887         , p_amb_context_code        => l_amb_context_code
47888         , p_entity_code             => 'TRANSACTIONS'
47889         , p_event_class_code        => 'CIP_RETIREMENTS'
47890         , p_side                    => 'NA'
47891         );
47892 
47893   END IF;
47894 
47895    --
47896    --
47897    END IF;
47898    --
47899    -- Bug 4922099
47900    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
47901           (NVL(l_enc_upg_option, 'N') = 'O')
47902         ) AND
47903         (l_bflow_method_code = 'PRIOR_ENTRY')
47904       )
47905    THEN
47906       IF
47907       --
47908       1 = 2
47909       --
47910       THEN
47911       xla_accounting_err_pkg.build_message
47912                                     (p_appli_s_name            => 'XLA'
47913                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
47914                                     ,p_token_1                 => 'LINE_NUMBER'
47915                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
47916                                     ,p_token_2                 => 'LINE_TYPE_NAME'
47917                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
47918                                                                              l_component_type
47919                                                                             ,l_component_code
47920                                                                             ,l_component_type_code
47921                                                                             ,l_component_appl_id
47922                                                                             ,l_amb_context_code
47923                                                                             ,l_entity_code
47924                                                                             ,l_event_class_code
47925                                                                            )
47926                                     ,p_token_3                 => 'OWNER'
47927                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
47928                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
47929                                                                           ,p_lookup_code    => l_component_type_code
47930                                                                          )
47931                                     ,p_token_4                 => 'PRODUCT_NAME'
47932                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
47933                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
47934                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
47935                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
47936                                     ,p_ae_header_id            =>  NULL
47937                                        );
47938 
47939         IF (C_LEVEL_ERROR>= g_log_level) THEN
47940                  trace
47941                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
47942                       ,p_level    => C_LEVEL_ERROR
47943                       ,p_module   => l_log_module);
47944         END IF;
47945       END IF;
47946    END IF;
47947    --
47948    --
47949    ------------------------------------------------------------------------------------------------
47950    -- 4219869 Business Flow
47951    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
47952    -- Prior Entry.  Currently, the following code is always generated.
47953    ------------------------------------------------------------------------------------------------
47954    XLA_AE_LINES_PKG.ValidateCurrentLine;
47955 
47956    ------------------------------------------------------------------------------------
47957    -- 4219869 Business Flow
47958    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
47959    ------------------------------------------------------------------------------------
47960    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
47961 
47962    ----------------------------------------------------------------------------------
47963    -- 4219869 Business Flow
47964    -- Update journal entry status -- Need to generate this within IF <condition>
47965    ----------------------------------------------------------------------------------
47966    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
47967          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
47968          ,p_balance_type_code => l_balance_type_code
47969          );
47970 
47971    -------------------------------------------------------------------------------------------
47972    -- 4262811 - Generate the Accrual Reversal lines
47973    -------------------------------------------------------------------------------------------
47974    BEGIN
47978          l_acc_rev_flag := 'N';
47975       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
47976                               (g_array_event(p_event_id).array_value_num('header_index'));
47977       IF l_acc_rev_flag IS NULL THEN
47979       END IF;
47980    EXCEPTION
47981       WHEN OTHERS THEN
47982          l_acc_rev_flag := 'N';
47983    END;
47984    --
47985    IF (l_acc_rev_flag = 'Y') THEN
47986 
47987        -- 4645092  ------------------------------------------------------------------------------
47988        -- To allow MPA report to determine if it should generate report process
47989        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
47990        ------------------------------------------------------------------------------------------
47991 
47992        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
47993        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
47994    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
47995    -- call ADRs
47996    -- Bug 4922099
47997    --
47998    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
47999         (NVL(l_actual_upg_option, 'N') = 'O') OR
48000         (NVL(l_enc_upg_option, 'N') = 'O')
48001       )
48002    THEN
48003    NULL;
48004    --
48005    --
48006    
48007   l_ccid := AcctDerRule_173(
48008            p_application_id           => p_application_id
48009          , p_ae_header_id             => l_ae_header_id 
48010 , p_source_3 => p_source_3
48011 , p_source_30 => p_source_30
48012          , x_transaction_coa_id       => l_adr_transaction_coa_id
48013          , x_accounting_coa_id        => l_adr_accounting_coa_id
48014          , x_value_type_code          => l_adr_value_type_code
48015          , p_side                     => 'NA'
48016    );
48017 
48018    xla_ae_lines_pkg.set_ccid(
48019     p_code_combination_id          => l_ccid
48020   , p_value_type_code              => l_adr_value_type_code
48021   , p_transaction_coa_id           => l_adr_transaction_coa_id
48022   , p_accounting_coa_id            => l_adr_accounting_coa_id
48023   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
48024   , p_adr_type_code                => 'S'
48025   , p_component_type               => l_component_type
48026   , p_component_code               => l_component_code
48027   , p_component_type_code          => l_component_type_code
48028   , p_component_appl_id            => l_component_appl_id
48029   , p_amb_context_code             => l_amb_context_code
48030   , p_side                         => 'NA'
48031   );
48032 
48033 
48034    l_segment := AcctDerRule_168(
48035            p_application_id           => p_application_id
48036          , p_ae_header_id             => l_ae_header_id 
48037 , p_source_3 => p_source_3
48038 , p_source_29 => p_source_29
48039          , x_transaction_coa_id       => l_adr_transaction_coa_id
48040          , x_accounting_coa_id        => l_adr_accounting_coa_id
48041          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
48042          , x_flex_value_set_id        => l_adr_flex_value_set_id
48043          , x_value_type_code          => l_adr_value_type_code
48044          , x_value_combination_id     => l_adr_value_combination_id
48045          , x_value_segment_code       => l_adr_value_segment_code
48046          , p_side                     => 'NA'
48047          , p_override_seg_flag        => 'Y'
48048    );
48049 
48050    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
48051 
48052       xla_ae_lines_pkg.set_segment(
48053           p_to_segment_code         => 'GL_BALANCING'
48054         , p_segment_value           => l_segment
48055         , p_from_segment_code       => l_adr_value_segment_code
48056         , p_from_combination_id     => l_adr_value_combination_id
48057         , p_value_type_code         => l_adr_value_type_code
48058         , p_transaction_coa_id      => l_adr_transaction_coa_id
48059         , p_accounting_coa_id       => l_adr_accounting_coa_id
48060         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
48061         , p_flex_value_set_id       => l_adr_flex_value_set_id
48062         , p_adr_code                => 'FA_EXPENSE_ACCT'
48063         , p_adr_type_code           => 'S'
48064         , p_component_type          => l_component_type
48065         , p_component_code          => l_component_code
48066         , p_component_type_code     => l_component_type_code
48067         , p_component_appl_id       => l_component_appl_id
48068         , p_amb_context_code        => l_amb_context_code
48069         , p_entity_code             => 'TRANSACTIONS'
48070         , p_event_class_code        => 'CIP_RETIREMENTS'
48071         , p_side                    => 'NA'
48072         );
48073 
48074   END IF;
48075 
48076    l_segment := AcctDerRule_161(
48077            p_application_id           => p_application_id
48078          , p_ae_header_id             => l_ae_header_id 
48079 , p_source_3 => p_source_3
48080 , p_source_23 => p_source_23
48081          , x_transaction_coa_id       => l_adr_transaction_coa_id
48082          , x_accounting_coa_id        => l_adr_accounting_coa_id
48083          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
48084          , x_flex_value_set_id        => l_adr_flex_value_set_id
48085          , x_value_type_code          => l_adr_value_type_code
48086          , x_value_combination_id     => l_adr_value_combination_id
48087          , x_value_segment_code       => l_adr_value_segment_code
48088          , p_side                     => 'NA'
48089          , p_override_seg_flag        => 'Y'
48090    );
48091 
48092    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
48093 
48094       xla_ae_lines_pkg.set_segment(
48095           p_to_segment_code         => 'GL_ACCOUNT'
48096         , p_segment_value           => l_segment
48097         , p_from_segment_code       => l_adr_value_segment_code
48101         , p_accounting_coa_id       => l_adr_accounting_coa_id
48098         , p_from_combination_id     => l_adr_value_combination_id
48099         , p_value_type_code         => l_adr_value_type_code
48100         , p_transaction_coa_id      => l_adr_transaction_coa_id
48102         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
48103         , p_flex_value_set_id       => l_adr_flex_value_set_id
48104         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
48105         , p_adr_type_code           => 'S'
48106         , p_component_type          => l_component_type
48107         , p_component_code          => l_component_code
48108         , p_component_type_code     => l_component_type_code
48109         , p_component_appl_id       => l_component_appl_id
48110         , p_amb_context_code        => l_amb_context_code
48111         , p_entity_code             => 'TRANSACTIONS'
48112         , p_event_class_code        => 'CIP_RETIREMENTS'
48113         , p_side                    => 'NA'
48114         );
48115 
48116   END IF;
48117 
48118    --
48119    --
48120    END IF;
48121 
48122        --
48123        -- Update the line information that should be overwritten
48124        --
48125        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
48126                                          p_header_num   => 1);
48127        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
48128 
48129        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
48130 
48131        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
48132           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
48133        END IF;
48134 
48135       --
48136       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
48137       --
48138       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
48139           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
48140       ELSE
48141           ---------------------------------------------------------------------------------------------------
48142           -- 4262811a Switch Sign
48143           ---------------------------------------------------------------------------------------------------
48144           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
48145           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48146                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48147           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48148                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48149           -- 5132302
48150           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
48151                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48152 
48153       END IF;
48154 
48155       -- 4955764
48156       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
48157       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
48158 
48159 
48160       XLA_AE_LINES_PKG.ValidateCurrentLine;
48161       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48162 
48163       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48164                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
48165                ,p_balance_type_code => l_balance_type_code);
48166 
48167    END IF;
48168 
48169    -----------------------------------------------------------------------------------------
48170    -- 4262811 Multiperiod Accounting
48171    -----------------------------------------------------------------------------------------
48172      -- No MPA option is assigned.
48173 
48174 
48175 END IF;
48176 END IF;
48177 --
48178 
48179 --
48180 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48181    trace
48182       (p_msg      => 'END of AcctLineType_221'
48183       ,p_level    => C_LEVEL_PROCEDURE
48184       ,p_module   => l_log_module);
48185 END IF;
48186 --
48187 EXCEPTION
48188   WHEN xla_exceptions_pkg.application_exception THEN
48189       RAISE;
48190   WHEN OTHERS THEN
48191        xla_exceptions_pkg.raise_message
48192            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_221');
48193 END AcctLineType_221;
48194 --
48195 
48196 ---------------------------------------
48197 --
48198 -- PRIVATE FUNCTION
48199 --         AcctLineType_222
48200 --
48201 ---------------------------------------
48202 PROCEDURE AcctLineType_222 (
48203   p_application_id        IN NUMBER
48204  ,p_event_id              IN NUMBER
48205  ,p_calculate_acctd_flag  IN VARCHAR2
48206  ,p_calculate_g_l_flag    IN VARCHAR2
48207  ,p_actual_flag           IN OUT VARCHAR2
48208  ,p_balance_type_code     OUT VARCHAR2
48209  ,p_gain_or_loss_ref      OUT VARCHAR2
48210  
48211 --Period Close Date
48212  , p_source_1            IN DATE
48213 --Generated Code Combination Identifier
48214  , p_source_3            IN NUMBER
48215 --Proceeds Of Sale Clearing Account
48216  , p_source_23            IN VARCHAR2
48217 --Expense Account Code Combination Identifier
48218  , p_source_29            IN NUMBER
48219 --Default Code Combination Identifier
48220  , p_source_30            IN NUMBER
48221 --Adjustment Type
48222  , p_source_35            IN VARCHAR2
48223 --Transaction Header Identifier
48224  , p_source_36            IN NUMBER
48225 --Adjustment Line Identifier
48226  , p_source_37            IN NUMBER
48230  , p_source_39            IN NUMBER
48227 --Distribution Type Code
48228  , p_source_38            IN VARCHAR2
48229 --Entered Amount
48231 --Currency Code
48232  , p_source_40            IN VARCHAR2
48233 )
48234 IS
48235 
48236 l_component_type              VARCHAR2(80);
48237 l_component_code              VARCHAR2(30);
48238 l_component_type_code         VARCHAR2(1);
48239 l_component_appl_id           INTEGER;
48240 l_amb_context_code            VARCHAR2(30);
48241 l_entity_code                 VARCHAR2(30);
48242 l_event_class_code            VARCHAR2(30);
48243 l_ae_header_id                NUMBER;
48244 l_event_type_code             VARCHAR2(30);
48245 l_line_definition_code        VARCHAR2(30);
48246 l_line_definition_owner_code  VARCHAR2(1);
48247 --
48248 -- adr variables
48249 l_segment                     VARCHAR2(30);
48250 l_ccid                        NUMBER;
48251 l_adr_transaction_coa_id      NUMBER;
48252 l_adr_accounting_coa_id       NUMBER;
48253 l_adr_flexfield_segment_code  VARCHAR2(30);
48254 l_adr_flex_value_set_id       NUMBER;
48255 l_adr_value_type_code         VARCHAR2(30);
48256 l_adr_value_combination_id    NUMBER;
48257 l_adr_value_segment_code      VARCHAR2(30);
48258 
48259 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
48260 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
48261 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
48262 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
48263 
48264 -- 4262811 Variables ------------------------------------------------------------------------------------------
48265 l_entered_amt_idx             NUMBER;
48266 l_accted_amt_idx              NUMBER;
48270 l_acc_rev_natural_side_code   VARCHAR2(1);
48267 l_acc_rev_flag                VARCHAR2(1);
48268 l_accrual_line_num            NUMBER;
48269 l_tmp_amt                     NUMBER;
48271 
48272 l_num_entries                 NUMBER;
48273 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
48274 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
48275 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
48276 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
48277 l_recog_line_1                NUMBER;
48278 l_recog_line_2                NUMBER;
48279 
48280 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
48281 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
48282 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
48283 
48284 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
48285 
48286 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
48287 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
48288 
48292 --
48289 ---------------------------------------------------------------------------------------------------------------
48290 
48291 
48293 -- bulk performance
48294 --
48295 l_balance_type_code           VARCHAR2(1);
48296 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
48297 l_log_module                  VARCHAR2(240);
48298 
48299 --
48300 -- Upgrade strategy
48301 --
48302 l_actual_upg_option           VARCHAR2(1);
48303 l_enc_upg_option           VARCHAR2(1);
48304 
48305 --
48306 BEGIN
48307 --
48308 IF g_log_enabled THEN
48309       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_222';
48310 END IF;
48311 --
48312 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48313 
48314       trace
48315          (p_msg      => 'BEGIN of AcctLineType_222'
48316          ,p_level    => C_LEVEL_PROCEDURE
48317          ,p_module   => l_log_module);
48318 
48319 END IF;
48320 --
48321 l_component_type             := 'AMB_JLT';
48322 l_component_code             := 'FA_CIP_PROC_OF_SALE_CLR';
48323 l_component_type_code        := 'S';
48324 l_component_appl_id          :=  140;
48325 l_amb_context_code           := 'DEFAULT';
48326 l_entity_code                := 'TRANSACTIONS';
48327 l_event_class_code           := 'CIP_RETIREMENTS';
48328 l_event_type_code            := 'CIP_RETIREMENTS';
48329 l_line_definition_owner_code := 'S';
48330 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
48331 --
48332 l_balance_type_code          := 'A';
48333 l_segment                     := NULL;
48334 l_ccid                        := NULL;
48335 l_adr_transaction_coa_id      := NULL;
48336 l_adr_accounting_coa_id       := NULL;
48337 l_adr_flexfield_segment_code  := NULL;
48338 l_adr_flex_value_set_id       := NULL;
48339 l_adr_value_type_code         := NULL;
48340 l_adr_value_combination_id    := NULL;
48341 l_adr_value_segment_code      := NULL;
48342 
48343 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
48344 l_bflow_class_code           := '';    -- 4219869 Business Flow
48345 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
48346 l_budgetary_control_flag     := 'N';
48347 
48348 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
48349 l_bflow_applied_to_amt       := NULL; -- 5132302
48350 l_entered_amt_idx            := NULL;          -- 4262811
48351 l_accted_amt_idx             := NULL;          -- 4262811
48352 l_acc_rev_flag               := NULL;          -- 4262811
48353 l_accrual_line_num           := NULL;          -- 4262811
48354 l_tmp_amt                    := NULL;          -- 4262811
48355 --
48356  
48357 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
48358     l_balance_type_code <> 'B' THEN
48359 IF NVL(p_source_35,'
48360 ') =  'PROCEEDS CLR'
48361  THEN 
48362 
48363    --
48364    XLA_AE_LINES_PKG.SetNewLine;
48365 
48366    p_balance_type_code          := l_balance_type_code;
48367    -- set the flag so later we will know whether the gain loss line needs to be created
48368    
48369    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
48370      p_actual_flag :='A';
48371    END IF;
48372 
48373    --
48374    -- bulk performance
48375    --
48376    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
48377                                       p_header_num   => 0); -- 4262811
48378    --
48379    -- set accounting line options
48380    --
48381    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
48382            p_natural_side_code          => 'D'
48383          , p_gain_or_loss_flag          => 'N'
48384          , p_gl_transfer_mode_code      => 'S'
48385          , p_acct_entry_type_code       => 'A'
48386          , p_switch_side_flag           => 'Y'
48387          , p_merge_duplicate_code       => 'N'
48388          );
48389    --
48390    l_acc_rev_natural_side_code := 'C';  -- 4262811
48391    -- 
48392    --
48393    -- set accounting line type info
48394    --
48395    xla_ae_lines_pkg.SetAcctLineType
48396       (p_component_type             => l_component_type
48397       ,p_event_type_code            => l_event_type_code
48398       ,p_line_definition_owner_code => l_line_definition_owner_code
48399       ,p_line_definition_code       => l_line_definition_code
48400       ,p_accounting_line_code       => l_component_code
48401       ,p_accounting_line_type_code  => l_component_type_code
48402       ,p_accounting_line_appl_id    => l_component_appl_id
48403       ,p_amb_context_code           => l_amb_context_code
48404       ,p_entity_code                => l_entity_code
48405       ,p_event_class_code           => l_event_class_code);
48406    --
48407    -- set accounting class
48408    --
48409    xla_ae_lines_pkg.SetAcctClass(
48410            p_accounting_class_code  => 'ASSET'
48411          , p_ae_header_id           => l_ae_header_id
48412          );
48413 
48414    --
48415    -- set rounding class
48416    --
48417    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
48418                       'ASSET';
48419 
48420    --
48421    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
48422    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
48423    --
48424    -- bulk performance
48425    --
48426    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
48427 
48428    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
48432    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
48429       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
48430 
48431    -- 4955764
48433       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
48434 
48435    -- 4458381 Public Sector Enh
48436    
48437    --
48438    -- set accounting attributes for the line type
48439    --
48440    l_entered_amt_idx := 4;
48441    l_accted_amt_idx  := 6;
48442    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
48443    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
48444    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
48445    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
48446    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
48447    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
48448    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
48449    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
48450    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
48451    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
48452    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
48453    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
48454    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
48455 
48456    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
48457    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
48458 
48459    ---------------------------------------------------------------------------------------------------------------
48460    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
48461    ---------------------------------------------------------------------------------------------------------------
48462    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
48463 
48464    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
48465    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
48466 
48467    IF xla_accounting_cache_pkg.GetValueChar
48468          (p_source_code         => 'LEDGER_CATEGORY_CODE'
48469          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
48470    AND l_bflow_method_code = 'PRIOR_ENTRY'
48471 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
48472    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
48473          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
48474        )
48475    THEN
48476          xla_ae_lines_pkg.BflowUpgEntry
48477            (p_business_method_code    => l_bflow_method_code
48478            ,p_business_class_code     => l_bflow_class_code
48479            ,p_balance_type            => l_balance_type_code);
48480    ELSE
48481       NULL;
48482 -- No business flow processing for business flow method of NONE.
48483    END IF;
48484 
48485    --
48486    -- call analytical criteria
48487    --
48488    
48489    --
48490    -- call description
48491    --
48492    
48493 xla_ae_lines_pkg.SetLineDescription(
48494    p_ae_header_id => l_ae_header_id
48495   ,p_description  => Description_38 (
48496      p_application_id         => p_application_id
48497    , p_ae_header_id           => l_ae_header_id 
48498 , p_source_1 => p_source_1
48499    )
48500 );
48501 
48502 
48503    --
48504    -- call ADRs
48505    -- Bug 4922099
48506    --
48507    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48508         (NVL(l_actual_upg_option, 'N') = 'O') OR
48509         (NVL(l_enc_upg_option, 'N') = 'O')
48510       )
48511    THEN
48512    NULL;
48513    --
48514    --
48515    
48516   l_ccid := AcctDerRule_173(
48517            p_application_id           => p_application_id
48518          , p_ae_header_id             => l_ae_header_id 
48519 , p_source_3 => p_source_3
48520 , p_source_30 => p_source_30
48521          , x_transaction_coa_id       => l_adr_transaction_coa_id
48522          , x_accounting_coa_id        => l_adr_accounting_coa_id
48523          , x_value_type_code          => l_adr_value_type_code
48524          , p_side                     => 'NA'
48525    );
48526 
48527    xla_ae_lines_pkg.set_ccid(
48528     p_code_combination_id          => l_ccid
48529   , p_value_type_code              => l_adr_value_type_code
48530   , p_transaction_coa_id           => l_adr_transaction_coa_id
48531   , p_accounting_coa_id            => l_adr_accounting_coa_id
48532   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
48533   , p_adr_type_code                => 'S'
48534   , p_component_type               => l_component_type
48535   , p_component_code               => l_component_code
48536   , p_component_type_code          => l_component_type_code
48537   , p_component_appl_id            => l_component_appl_id
48538   , p_amb_context_code             => l_amb_context_code
48542 
48539   , p_side                         => 'NA'
48540   );
48541 
48543    l_segment := AcctDerRule_168(
48544            p_application_id           => p_application_id
48545          , p_ae_header_id             => l_ae_header_id 
48546 , p_source_3 => p_source_3
48547 , p_source_29 => p_source_29
48548          , x_transaction_coa_id       => l_adr_transaction_coa_id
48549          , x_accounting_coa_id        => l_adr_accounting_coa_id
48550          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
48551          , x_flex_value_set_id        => l_adr_flex_value_set_id
48552          , x_value_type_code          => l_adr_value_type_code
48553          , x_value_combination_id     => l_adr_value_combination_id
48554          , x_value_segment_code       => l_adr_value_segment_code
48555          , p_side                     => 'NA'
48556          , p_override_seg_flag        => 'Y'
48557    );
48558 
48559    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
48560 
48561       xla_ae_lines_pkg.set_segment(
48562           p_to_segment_code         => 'GL_BALANCING'
48563         , p_segment_value           => l_segment
48564         , p_from_segment_code       => l_adr_value_segment_code
48565         , p_from_combination_id     => l_adr_value_combination_id
48566         , p_value_type_code         => l_adr_value_type_code
48567         , p_transaction_coa_id      => l_adr_transaction_coa_id
48568         , p_accounting_coa_id       => l_adr_accounting_coa_id
48569         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
48570         , p_flex_value_set_id       => l_adr_flex_value_set_id
48571         , p_adr_code                => 'FA_EXPENSE_ACCT'
48572         , p_adr_type_code           => 'S'
48573         , p_component_type          => l_component_type
48574         , p_component_code          => l_component_code
48575         , p_component_type_code     => l_component_type_code
48576         , p_component_appl_id       => l_component_appl_id
48577         , p_amb_context_code        => l_amb_context_code
48578         , p_entity_code             => 'TRANSACTIONS'
48579         , p_event_class_code        => 'CIP_RETIREMENTS'
48580         , p_side                    => 'NA'
48581         );
48582 
48583   END IF;
48584 
48585    l_segment := AcctDerRule_161(
48586            p_application_id           => p_application_id
48587          , p_ae_header_id             => l_ae_header_id 
48588 , p_source_3 => p_source_3
48589 , p_source_23 => p_source_23
48590          , x_transaction_coa_id       => l_adr_transaction_coa_id
48591          , x_accounting_coa_id        => l_adr_accounting_coa_id
48592          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
48593          , x_flex_value_set_id        => l_adr_flex_value_set_id
48594          , x_value_type_code          => l_adr_value_type_code
48595          , x_value_combination_id     => l_adr_value_combination_id
48596          , x_value_segment_code       => l_adr_value_segment_code
48597          , p_side                     => 'NA'
48598          , p_override_seg_flag        => 'Y'
48599    );
48600 
48601    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
48602 
48603       xla_ae_lines_pkg.set_segment(
48604           p_to_segment_code         => 'GL_ACCOUNT'
48605         , p_segment_value           => l_segment
48606         , p_from_segment_code       => l_adr_value_segment_code
48607         , p_from_combination_id     => l_adr_value_combination_id
48608         , p_value_type_code         => l_adr_value_type_code
48609         , p_transaction_coa_id      => l_adr_transaction_coa_id
48610         , p_accounting_coa_id       => l_adr_accounting_coa_id
48611         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
48612         , p_flex_value_set_id       => l_adr_flex_value_set_id
48613         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
48614         , p_adr_type_code           => 'S'
48615         , p_component_type          => l_component_type
48616         , p_component_code          => l_component_code
48617         , p_component_type_code     => l_component_type_code
48618         , p_component_appl_id       => l_component_appl_id
48619         , p_amb_context_code        => l_amb_context_code
48620         , p_entity_code             => 'TRANSACTIONS'
48621         , p_event_class_code        => 'CIP_RETIREMENTS'
48622         , p_side                    => 'NA'
48623         );
48624 
48625   END IF;
48626 
48627    --
48628    --
48629    END IF;
48630    --
48631    -- Bug 4922099
48632    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
48633           (NVL(l_enc_upg_option, 'N') = 'O')
48634         ) AND
48635         (l_bflow_method_code = 'PRIOR_ENTRY')
48636       )
48637    THEN
48638       IF
48639       --
48640       1 = 2
48641       --
48642       THEN
48643       xla_accounting_err_pkg.build_message
48644                                     (p_appli_s_name            => 'XLA'
48645                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48646                                     ,p_token_1                 => 'LINE_NUMBER'
48647                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
48648                                     ,p_token_2                 => 'LINE_TYPE_NAME'
48649                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
48650                                                                              l_component_type
48651                                                                             ,l_component_code
48652                                                                             ,l_component_type_code
48653                                                                             ,l_component_appl_id
48654                                                                             ,l_amb_context_code
48658                                     ,p_token_3                 => 'OWNER'
48655                                                                             ,l_entity_code
48656                                                                             ,l_event_class_code
48657                                                                            )
48659                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
48660                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
48661                                                                           ,p_lookup_code    => l_component_type_code
48662                                                                          )
48663                                     ,p_token_4                 => 'PRODUCT_NAME'
48664                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
48665                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
48666                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
48667                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
48668                                     ,p_ae_header_id            =>  NULL
48669                                        );
48670 
48671         IF (C_LEVEL_ERROR>= g_log_level) THEN
48672                  trace
48673                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48674                       ,p_level    => C_LEVEL_ERROR
48675                       ,p_module   => l_log_module);
48676         END IF;
48677       END IF;
48678    END IF;
48679    --
48680    --
48681    ------------------------------------------------------------------------------------------------
48682    -- 4219869 Business Flow
48683    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
48684    -- Prior Entry.  Currently, the following code is always generated.
48685    ------------------------------------------------------------------------------------------------
48686    XLA_AE_LINES_PKG.ValidateCurrentLine;
48687 
48688    ------------------------------------------------------------------------------------
48689    -- 4219869 Business Flow
48690    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
48691    ------------------------------------------------------------------------------------
48692    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48693 
48694    ----------------------------------------------------------------------------------
48695    -- 4219869 Business Flow
48699          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
48696    -- Update journal entry status -- Need to generate this within IF <condition>
48697    ----------------------------------------------------------------------------------
48698    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48700          ,p_balance_type_code => l_balance_type_code
48701          );
48702 
48703    -------------------------------------------------------------------------------------------
48704    -- 4262811 - Generate the Accrual Reversal lines
48705    -------------------------------------------------------------------------------------------
48706    BEGIN
48707       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
48708                               (g_array_event(p_event_id).array_value_num('header_index'));
48709       IF l_acc_rev_flag IS NULL THEN
48710          l_acc_rev_flag := 'N';
48711       END IF;
48712    EXCEPTION
48713       WHEN OTHERS THEN
48714          l_acc_rev_flag := 'N';
48715    END;
48716    --
48717    IF (l_acc_rev_flag = 'Y') THEN
48718 
48719        -- 4645092  ------------------------------------------------------------------------------
48720        -- To allow MPA report to determine if it should generate report process
48721        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
48722        ------------------------------------------------------------------------------------------
48723 
48724        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
48725        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
48726    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
48727    -- call ADRs
48728    -- Bug 4922099
48729    --
48730    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48731         (NVL(l_actual_upg_option, 'N') = 'O') OR
48732         (NVL(l_enc_upg_option, 'N') = 'O')
48733       )
48734    THEN
48735    NULL;
48736    --
48737    --
48738    
48739   l_ccid := AcctDerRule_173(
48740            p_application_id           => p_application_id
48741          , p_ae_header_id             => l_ae_header_id 
48742 , p_source_3 => p_source_3
48743 , p_source_30 => p_source_30
48744          , x_transaction_coa_id       => l_adr_transaction_coa_id
48748    );
48745          , x_accounting_coa_id        => l_adr_accounting_coa_id
48746          , x_value_type_code          => l_adr_value_type_code
48747          , p_side                     => 'NA'
48749 
48750    xla_ae_lines_pkg.set_ccid(
48751     p_code_combination_id          => l_ccid
48752   , p_value_type_code              => l_adr_value_type_code
48753   , p_transaction_coa_id           => l_adr_transaction_coa_id
48754   , p_accounting_coa_id            => l_adr_accounting_coa_id
48755   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
48756   , p_adr_type_code                => 'S'
48757   , p_component_type               => l_component_type
48758   , p_component_code               => l_component_code
48759   , p_component_type_code          => l_component_type_code
48760   , p_component_appl_id            => l_component_appl_id
48761   , p_amb_context_code             => l_amb_context_code
48762   , p_side                         => 'NA'
48763   );
48764 
48765 
48766    l_segment := AcctDerRule_168(
48767            p_application_id           => p_application_id
48768          , p_ae_header_id             => l_ae_header_id 
48769 , p_source_3 => p_source_3
48770 , p_source_29 => p_source_29
48771          , x_transaction_coa_id       => l_adr_transaction_coa_id
48772          , x_accounting_coa_id        => l_adr_accounting_coa_id
48773          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
48774          , x_flex_value_set_id        => l_adr_flex_value_set_id
48775          , x_value_type_code          => l_adr_value_type_code
48776          , x_value_combination_id     => l_adr_value_combination_id
48777          , x_value_segment_code       => l_adr_value_segment_code
48778          , p_side                     => 'NA'
48779          , p_override_seg_flag        => 'Y'
48780    );
48781 
48782    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
48783 
48784       xla_ae_lines_pkg.set_segment(
48785           p_to_segment_code         => 'GL_BALANCING'
48786         , p_segment_value           => l_segment
48787         , p_from_segment_code       => l_adr_value_segment_code
48788         , p_from_combination_id     => l_adr_value_combination_id
48789         , p_value_type_code         => l_adr_value_type_code
48790         , p_transaction_coa_id      => l_adr_transaction_coa_id
48791         , p_accounting_coa_id       => l_adr_accounting_coa_id
48792         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
48793         , p_flex_value_set_id       => l_adr_flex_value_set_id
48794         , p_adr_code                => 'FA_EXPENSE_ACCT'
48795         , p_adr_type_code           => 'S'
48796         , p_component_type          => l_component_type
48797         , p_component_code          => l_component_code
48798         , p_component_type_code     => l_component_type_code
48799         , p_component_appl_id       => l_component_appl_id
48800         , p_amb_context_code        => l_amb_context_code
48801         , p_entity_code             => 'TRANSACTIONS'
48802         , p_event_class_code        => 'CIP_RETIREMENTS'
48803         , p_side                    => 'NA'
48804         );
48805 
48806   END IF;
48807 
48808    l_segment := AcctDerRule_161(
48809            p_application_id           => p_application_id
48810          , p_ae_header_id             => l_ae_header_id 
48811 , p_source_3 => p_source_3
48812 , p_source_23 => p_source_23
48813          , x_transaction_coa_id       => l_adr_transaction_coa_id
48814          , x_accounting_coa_id        => l_adr_accounting_coa_id
48815          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
48816          , x_flex_value_set_id        => l_adr_flex_value_set_id
48817          , x_value_type_code          => l_adr_value_type_code
48818          , x_value_combination_id     => l_adr_value_combination_id
48819          , x_value_segment_code       => l_adr_value_segment_code
48820          , p_side                     => 'NA'
48821          , p_override_seg_flag        => 'Y'
48822    );
48823 
48824    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
48825 
48826       xla_ae_lines_pkg.set_segment(
48827           p_to_segment_code         => 'GL_ACCOUNT'
48828         , p_segment_value           => l_segment
48829         , p_from_segment_code       => l_adr_value_segment_code
48830         , p_from_combination_id     => l_adr_value_combination_id
48831         , p_value_type_code         => l_adr_value_type_code
48832         , p_transaction_coa_id      => l_adr_transaction_coa_id
48833         , p_accounting_coa_id       => l_adr_accounting_coa_id
48834         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
48835         , p_flex_value_set_id       => l_adr_flex_value_set_id
48836         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
48837         , p_adr_type_code           => 'S'
48838         , p_component_type          => l_component_type
48839         , p_component_code          => l_component_code
48840         , p_component_type_code     => l_component_type_code
48841         , p_component_appl_id       => l_component_appl_id
48842         , p_amb_context_code        => l_amb_context_code
48843         , p_entity_code             => 'TRANSACTIONS'
48844         , p_event_class_code        => 'CIP_RETIREMENTS'
48845         , p_side                    => 'NA'
48846         );
48847 
48848   END IF;
48849 
48850    --
48851    --
48852    END IF;
48853 
48854        --
48855        -- Update the line information that should be overwritten
48856        --
48857        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
48858                                          p_header_num   => 1);
48859        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
48860 
48861        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
48862 
48863        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
48867       --
48864           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
48865        END IF;
48866 
48868       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
48869       --
48870       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
48871           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
48872       ELSE
48873           ---------------------------------------------------------------------------------------------------
48874           -- 4262811a Switch Sign
48875           ---------------------------------------------------------------------------------------------------
48876           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
48877           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48878                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48879           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48880                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48881           -- 5132302
48882           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
48883                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48884 
48885       END IF;
48886 
48887       -- 4955764
48888       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
48889       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
48890 
48891 
48892       XLA_AE_LINES_PKG.ValidateCurrentLine;
48893       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48894 
48895       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48896                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
48897                ,p_balance_type_code => l_balance_type_code);
48898 
48899    END IF;
48900 
48901    -----------------------------------------------------------------------------------------
48902    -- 4262811 Multiperiod Accounting
48903    -----------------------------------------------------------------------------------------
48904      -- No MPA option is assigned.
48905 
48906 
48907 END IF;
48908 END IF;
48909 --
48910 
48911 --
48912 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48913    trace
48914       (p_msg      => 'END of AcctLineType_222'
48915       ,p_level    => C_LEVEL_PROCEDURE
48916       ,p_module   => l_log_module);
48917 END IF;
48918 --
48919 EXCEPTION
48920   WHEN xla_exceptions_pkg.application_exception THEN
48921       RAISE;
48922   WHEN OTHERS THEN
48923        xla_exceptions_pkg.raise_message
48924            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_222');
48925 END AcctLineType_222;
48926 --
48927 
48928 ---------------------------------------
48929 --
48930 -- PRIVATE FUNCTION
48931 --         AcctLineType_223
48932 --
48933 ---------------------------------------
48934 PROCEDURE AcctLineType_223 (
48935   p_application_id        IN NUMBER
48936  ,p_event_id              IN NUMBER
48937  ,p_calculate_acctd_flag  IN VARCHAR2
48938  ,p_calculate_g_l_flag    IN VARCHAR2
48939  ,p_actual_flag           IN OUT VARCHAR2
48940  ,p_balance_type_code     OUT VARCHAR2
48941  ,p_gain_or_loss_ref      OUT VARCHAR2
48942  
48943 --Period Close Date
48944  , p_source_1            IN DATE
48945 --Generated Code Combination Identifier
48946  , p_source_3            IN NUMBER
48947 --Proceeds Of Sale Gain Account
48948  , p_source_24            IN VARCHAR2
48949 --Expense Account Code Combination Identifier
48950  , p_source_29            IN NUMBER
48951 --Default Code Combination Identifier
48952  , p_source_30            IN NUMBER
48953 --Adjustment Type
48954  , p_source_35            IN VARCHAR2
48955 --Transaction Header Identifier
48956  , p_source_36            IN NUMBER
48957 --Adjustment Line Identifier
48958  , p_source_37            IN NUMBER
48959 --Distribution Type Code
48960  , p_source_38            IN VARCHAR2
48961 --Entered Amount
48962  , p_source_39            IN NUMBER
48963 --Currency Code
48964  , p_source_40            IN VARCHAR2
48965 --Gain Loss Amount
48966  , p_source_41            IN NUMBER
48967 )
48968 IS
48969 
48970 l_component_type              VARCHAR2(80);
48971 l_component_code              VARCHAR2(30);
48972 l_component_type_code         VARCHAR2(1);
48973 l_component_appl_id           INTEGER;
48974 l_amb_context_code            VARCHAR2(30);
48975 l_entity_code                 VARCHAR2(30);
48976 l_event_class_code            VARCHAR2(30);
48977 l_ae_header_id                NUMBER;
48978 l_event_type_code             VARCHAR2(30);
48979 l_line_definition_code        VARCHAR2(30);
48980 l_line_definition_owner_code  VARCHAR2(1);
48981 --
48982 -- adr variables
48983 l_segment                     VARCHAR2(30);
48984 l_ccid                        NUMBER;
48985 l_adr_transaction_coa_id      NUMBER;
48986 l_adr_accounting_coa_id       NUMBER;
48987 l_adr_flexfield_segment_code  VARCHAR2(30);
48988 l_adr_flex_value_set_id       NUMBER;
48989 l_adr_value_type_code         VARCHAR2(30);
48993 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
48990 l_adr_value_combination_id    NUMBER;
48991 l_adr_value_segment_code      VARCHAR2(30);
48992 
48994 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
48995 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
48996 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
48997 
48998 -- 4262811 Variables ------------------------------------------------------------------------------------------
48999 l_entered_amt_idx             NUMBER;
49000 l_accted_amt_idx              NUMBER;
49001 l_acc_rev_flag                VARCHAR2(1);
49002 l_accrual_line_num            NUMBER;
49003 l_tmp_amt                     NUMBER;
49004 l_acc_rev_natural_side_code   VARCHAR2(1);
49005 
49006 l_num_entries                 NUMBER;
49007 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
49008 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
49009 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
49010 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
49011 l_recog_line_1                NUMBER;
49012 l_recog_line_2                NUMBER;
49013 
49014 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
49015 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
49016 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
49017 
49018 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
49019 
49020 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
49021 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
49022 
49023 ---------------------------------------------------------------------------------------------------------------
49024 
49025 
49026 --
49027 -- bulk performance
49028 --
49029 l_balance_type_code           VARCHAR2(1);
49030 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
49031 l_log_module                  VARCHAR2(240);
49032 
49033 --
49034 -- Upgrade strategy
49035 --
49036 l_actual_upg_option           VARCHAR2(1);
49037 l_enc_upg_option           VARCHAR2(1);
49038 
49039 --
49040 BEGIN
49041 --
49042 IF g_log_enabled THEN
49043       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_223';
49044 END IF;
49045 --
49046 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
49047 
49048       trace
49049          (p_msg      => 'BEGIN of AcctLineType_223'
49050          ,p_level    => C_LEVEL_PROCEDURE
49051          ,p_module   => l_log_module);
49052 
49053 END IF;
49054 --
49055 l_component_type             := 'AMB_JLT';
49056 l_component_code             := 'FA_CIP_PROC_OF_SALE_GAIN';
49057 l_component_type_code        := 'S';
49058 l_component_appl_id          :=  140;
49059 l_amb_context_code           := 'DEFAULT';
49060 l_entity_code                := 'TRANSACTIONS';
49061 l_event_class_code           := 'CIP_RETIREMENTS';
49062 l_event_type_code            := 'CIP_RETIREMENTS';
49063 l_line_definition_owner_code := 'S';
49064 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
49065 --
49066 l_balance_type_code          := 'A';
49067 l_segment                     := NULL;
49068 l_ccid                        := NULL;
49069 l_adr_transaction_coa_id      := NULL;
49070 l_adr_accounting_coa_id       := NULL;
49071 l_adr_flexfield_segment_code  := NULL;
49072 l_adr_flex_value_set_id       := NULL;
49073 l_adr_value_type_code         := NULL;
49074 l_adr_value_combination_id    := NULL;
49075 l_adr_value_segment_code      := NULL;
49076 
49077 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
49078 l_bflow_class_code           := '';    -- 4219869 Business Flow
49079 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
49080 l_budgetary_control_flag     := 'N';
49081 
49082 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
49083 l_bflow_applied_to_amt       := NULL; -- 5132302
49084 l_entered_amt_idx            := NULL;          -- 4262811
49085 l_accted_amt_idx             := NULL;          -- 4262811
49086 l_acc_rev_flag               := NULL;          -- 4262811
49087 l_accrual_line_num           := NULL;          -- 4262811
49088 l_tmp_amt                    := NULL;          -- 4262811
49089 --
49090  
49091 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
49092     l_balance_type_code <> 'B' THEN
49093 IF NVL(p_source_35,'
49094 ') =  'PROCEEDS' AND 
49095 p_source_41 >=  0
49096  THEN 
49097 
49098    --
49099    XLA_AE_LINES_PKG.SetNewLine;
49100 
49101    p_balance_type_code          := l_balance_type_code;
49102    -- set the flag so later we will know whether the gain loss line needs to be created
49103    
49104    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
49105      p_actual_flag :='A';
49106    END IF;
49107 
49108    --
49109    -- bulk performance
49110    --
49111    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
49112                                       p_header_num   => 0); -- 4262811
49113    --
49114    -- set accounting line options
49115    --
49119          , p_gl_transfer_mode_code      => 'S'
49116    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
49117            p_natural_side_code          => 'C'
49118          , p_gain_or_loss_flag          => 'N'
49120          , p_acct_entry_type_code       => 'A'
49121          , p_switch_side_flag           => 'Y'
49122          , p_merge_duplicate_code       => 'N'
49123          );
49124    --
49125    l_acc_rev_natural_side_code := 'D';  -- 4262811
49126    -- 
49127    --
49128    -- set accounting line type info
49129    --
49130    xla_ae_lines_pkg.SetAcctLineType
49131       (p_component_type             => l_component_type
49132       ,p_event_type_code            => l_event_type_code
49133       ,p_line_definition_owner_code => l_line_definition_owner_code
49134       ,p_line_definition_code       => l_line_definition_code
49135       ,p_accounting_line_code       => l_component_code
49136       ,p_accounting_line_type_code  => l_component_type_code
49137       ,p_accounting_line_appl_id    => l_component_appl_id
49138       ,p_amb_context_code           => l_amb_context_code
49139       ,p_entity_code                => l_entity_code
49140       ,p_event_class_code           => l_event_class_code);
49141    --
49142    -- set accounting class
49143    --
49144    xla_ae_lines_pkg.SetAcctClass(
49145            p_accounting_class_code  => 'ASSET'
49146          , p_ae_header_id           => l_ae_header_id
49147          );
49148 
49149    --
49150    -- set rounding class
49151    --
49155    --
49152    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
49153                       'ASSET';
49154 
49156    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
49157    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
49158    --
49159    -- bulk performance
49160    --
49161    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
49162 
49163    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
49164       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
49165 
49166    -- 4955764
49167    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49168       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
49169 
49170    -- 4458381 Public Sector Enh
49171    
49172    --
49173    -- set accounting attributes for the line type
49174    --
49175    l_entered_amt_idx := 4;
49176    l_accted_amt_idx  := 6;
49177    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
49178    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
49179    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
49180    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
49181    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
49182    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
49186    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
49183    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
49184    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
49185    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
49187    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
49188    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
49189    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
49190 
49191    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
49192    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
49193 
49194    ---------------------------------------------------------------------------------------------------------------
49195    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
49196    ---------------------------------------------------------------------------------------------------------------
49197    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
49198 
49199    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49200    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49201 
49202    IF xla_accounting_cache_pkg.GetValueChar
49203          (p_source_code         => 'LEDGER_CATEGORY_CODE'
49204          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
49205    AND l_bflow_method_code = 'PRIOR_ENTRY'
49206 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
49207    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
49208          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
49209        )
49210    THEN
49211          xla_ae_lines_pkg.BflowUpgEntry
49212            (p_business_method_code    => l_bflow_method_code
49213            ,p_business_class_code     => l_bflow_class_code
49214            ,p_balance_type            => l_balance_type_code);
49215    ELSE
49216       NULL;
49217 -- No business flow processing for business flow method of NONE.
49218    END IF;
49219 
49220    --
49221    -- call analytical criteria
49222    --
49223    
49224    --
49225    -- call description
49226    --
49227    
49228 xla_ae_lines_pkg.SetLineDescription(
49229    p_ae_header_id => l_ae_header_id
49230   ,p_description  => Description_35 (
49231      p_application_id         => p_application_id
49232    , p_ae_header_id           => l_ae_header_id 
49233 , p_source_1 => p_source_1
49234    )
49235 );
49236 
49237 
49238    --
49239    -- call ADRs
49240    -- Bug 4922099
49241    --
49242    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49243         (NVL(l_actual_upg_option, 'N') = 'O') OR
49244         (NVL(l_enc_upg_option, 'N') = 'O')
49245       )
49246    THEN
49247    NULL;
49248    --
49249    --
49250    
49251   l_ccid := AcctDerRule_173(
49252            p_application_id           => p_application_id
49253          , p_ae_header_id             => l_ae_header_id 
49254 , p_source_3 => p_source_3
49255 , p_source_30 => p_source_30
49256          , x_transaction_coa_id       => l_adr_transaction_coa_id
49257          , x_accounting_coa_id        => l_adr_accounting_coa_id
49258          , x_value_type_code          => l_adr_value_type_code
49259          , p_side                     => 'NA'
49260    );
49261 
49262    xla_ae_lines_pkg.set_ccid(
49263     p_code_combination_id          => l_ccid
49264   , p_value_type_code              => l_adr_value_type_code
49265   , p_transaction_coa_id           => l_adr_transaction_coa_id
49266   , p_accounting_coa_id            => l_adr_accounting_coa_id
49267   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
49268   , p_adr_type_code                => 'S'
49269   , p_component_type               => l_component_type
49270   , p_component_code               => l_component_code
49271   , p_component_type_code          => l_component_type_code
49272   , p_component_appl_id            => l_component_appl_id
49273   , p_amb_context_code             => l_amb_context_code
49274   , p_side                         => 'NA'
49275   );
49276 
49277 
49278    l_segment := AcctDerRule_168(
49279            p_application_id           => p_application_id
49280          , p_ae_header_id             => l_ae_header_id 
49281 , p_source_3 => p_source_3
49282 , p_source_29 => p_source_29
49283          , x_transaction_coa_id       => l_adr_transaction_coa_id
49284          , x_accounting_coa_id        => l_adr_accounting_coa_id
49285          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
49286          , x_flex_value_set_id        => l_adr_flex_value_set_id
49287          , x_value_type_code          => l_adr_value_type_code
49288          , x_value_combination_id     => l_adr_value_combination_id
49289          , x_value_segment_code       => l_adr_value_segment_code
49290          , p_side                     => 'NA'
49291          , p_override_seg_flag        => 'Y'
49292    );
49293 
49294    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
49295 
49296       xla_ae_lines_pkg.set_segment(
49297           p_to_segment_code         => 'GL_BALANCING'
49298         , p_segment_value           => l_segment
49302         , p_transaction_coa_id      => l_adr_transaction_coa_id
49299         , p_from_segment_code       => l_adr_value_segment_code
49300         , p_from_combination_id     => l_adr_value_combination_id
49301         , p_value_type_code         => l_adr_value_type_code
49303         , p_accounting_coa_id       => l_adr_accounting_coa_id
49304         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
49305         , p_flex_value_set_id       => l_adr_flex_value_set_id
49306         , p_adr_code                => 'FA_EXPENSE_ACCT'
49307         , p_adr_type_code           => 'S'
49308         , p_component_type          => l_component_type
49309         , p_component_code          => l_component_code
49310         , p_component_type_code     => l_component_type_code
49311         , p_component_appl_id       => l_component_appl_id
49312         , p_amb_context_code        => l_amb_context_code
49313         , p_entity_code             => 'TRANSACTIONS'
49314         , p_event_class_code        => 'CIP_RETIREMENTS'
49315         , p_side                    => 'NA'
49316         );
49317 
49318   END IF;
49319 
49320    l_segment := AcctDerRule_162(
49321            p_application_id           => p_application_id
49322          , p_ae_header_id             => l_ae_header_id 
49323 , p_source_3 => p_source_3
49324 , p_source_24 => p_source_24
49325          , x_transaction_coa_id       => l_adr_transaction_coa_id
49326          , x_accounting_coa_id        => l_adr_accounting_coa_id
49327          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
49328          , x_flex_value_set_id        => l_adr_flex_value_set_id
49329          , x_value_type_code          => l_adr_value_type_code
49330          , x_value_combination_id     => l_adr_value_combination_id
49331          , x_value_segment_code       => l_adr_value_segment_code
49332          , p_side                     => 'NA'
49333          , p_override_seg_flag        => 'Y'
49334    );
49335 
49336    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
49337 
49338       xla_ae_lines_pkg.set_segment(
49339           p_to_segment_code         => 'GL_ACCOUNT'
49340         , p_segment_value           => l_segment
49341         , p_from_segment_code       => l_adr_value_segment_code
49342         , p_from_combination_id     => l_adr_value_combination_id
49343         , p_value_type_code         => l_adr_value_type_code
49344         , p_transaction_coa_id      => l_adr_transaction_coa_id
49345         , p_accounting_coa_id       => l_adr_accounting_coa_id
49346         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
49347         , p_flex_value_set_id       => l_adr_flex_value_set_id
49348         , p_adr_code                => 'FA_PROC_OF_SALE_GAIN_SEGMENT'
49349         , p_adr_type_code           => 'S'
49350         , p_component_type          => l_component_type
49351         , p_component_code          => l_component_code
49352         , p_component_type_code     => l_component_type_code
49353         , p_component_appl_id       => l_component_appl_id
49354         , p_amb_context_code        => l_amb_context_code
49355         , p_entity_code             => 'TRANSACTIONS'
49356         , p_event_class_code        => 'CIP_RETIREMENTS'
49357         , p_side                    => 'NA'
49358         );
49359 
49360   END IF;
49361 
49362    --
49363    --
49364    END IF;
49365    --
49366    -- Bug 4922099
49367    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
49368           (NVL(l_enc_upg_option, 'N') = 'O')
49369         ) AND
49370         (l_bflow_method_code = 'PRIOR_ENTRY')
49371       )
49372    THEN
49373       IF
49374       --
49375       1 = 2
49376       --
49377       THEN
49378       xla_accounting_err_pkg.build_message
49379                                     (p_appli_s_name            => 'XLA'
49380                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49381                                     ,p_token_1                 => 'LINE_NUMBER'
49382                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
49383                                     ,p_token_2                 => 'LINE_TYPE_NAME'
49384                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
49385                                                                              l_component_type
49386                                                                             ,l_component_code
49387                                                                             ,l_component_type_code
49391                                                                             ,l_event_class_code
49388                                                                             ,l_component_appl_id
49389                                                                             ,l_amb_context_code
49390                                                                             ,l_entity_code
49392                                                                            )
49393                                     ,p_token_3                 => 'OWNER'
49394                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
49395                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
49396                                                                           ,p_lookup_code    => l_component_type_code
49397                                                                          )
49398                                     ,p_token_4                 => 'PRODUCT_NAME'
49399                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
49400                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
49401                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
49402                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
49403                                     ,p_ae_header_id            =>  NULL
49404                                        );
49405 
49406         IF (C_LEVEL_ERROR>= g_log_level) THEN
49407                  trace
49408                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49409                       ,p_level    => C_LEVEL_ERROR
49410                       ,p_module   => l_log_module);
49411         END IF;
49412       END IF;
49413    END IF;
49414    --
49415    --
49416    ------------------------------------------------------------------------------------------------
49417    -- 4219869 Business Flow
49418    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
49419    -- Prior Entry.  Currently, the following code is always generated.
49423    ------------------------------------------------------------------------------------
49420    ------------------------------------------------------------------------------------------------
49421    XLA_AE_LINES_PKG.ValidateCurrentLine;
49422 
49424    -- 4219869 Business Flow
49425    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
49426    ------------------------------------------------------------------------------------
49427    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
49428 
49429    ----------------------------------------------------------------------------------
49430    -- 4219869 Business Flow
49431    -- Update journal entry status -- Need to generate this within IF <condition>
49432    ----------------------------------------------------------------------------------
49433    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
49434          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
49435          ,p_balance_type_code => l_balance_type_code
49436          );
49437 
49438    -------------------------------------------------------------------------------------------
49439    -- 4262811 - Generate the Accrual Reversal lines
49440    -------------------------------------------------------------------------------------------
49441    BEGIN
49442       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
49443                               (g_array_event(p_event_id).array_value_num('header_index'));
49444       IF l_acc_rev_flag IS NULL THEN
49445          l_acc_rev_flag := 'N';
49446       END IF;
49447    EXCEPTION
49448       WHEN OTHERS THEN
49449          l_acc_rev_flag := 'N';
49450    END;
49451    --
49452    IF (l_acc_rev_flag = 'Y') THEN
49453 
49454        -- 4645092  ------------------------------------------------------------------------------
49455        -- To allow MPA report to determine if it should generate report process
49456        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
49457        ------------------------------------------------------------------------------------------
49458 
49459        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
49460        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
49461    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
49462    -- call ADRs
49463    -- Bug 4922099
49464    --
49465    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49466         (NVL(l_actual_upg_option, 'N') = 'O') OR
49467         (NVL(l_enc_upg_option, 'N') = 'O')
49468       )
49469    THEN
49470    NULL;
49471    --
49472    --
49473    
49474   l_ccid := AcctDerRule_173(
49475            p_application_id           => p_application_id
49479          , x_transaction_coa_id       => l_adr_transaction_coa_id
49476          , p_ae_header_id             => l_ae_header_id 
49477 , p_source_3 => p_source_3
49478 , p_source_30 => p_source_30
49480          , x_accounting_coa_id        => l_adr_accounting_coa_id
49481          , x_value_type_code          => l_adr_value_type_code
49482          , p_side                     => 'NA'
49483    );
49484 
49485    xla_ae_lines_pkg.set_ccid(
49486     p_code_combination_id          => l_ccid
49487   , p_value_type_code              => l_adr_value_type_code
49488   , p_transaction_coa_id           => l_adr_transaction_coa_id
49489   , p_accounting_coa_id            => l_adr_accounting_coa_id
49490   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
49491   , p_adr_type_code                => 'S'
49492   , p_component_type               => l_component_type
49493   , p_component_code               => l_component_code
49494   , p_component_type_code          => l_component_type_code
49495   , p_component_appl_id            => l_component_appl_id
49496   , p_amb_context_code             => l_amb_context_code
49497   , p_side                         => 'NA'
49498   );
49499 
49500 
49501    l_segment := AcctDerRule_168(
49502            p_application_id           => p_application_id
49503          , p_ae_header_id             => l_ae_header_id 
49504 , p_source_3 => p_source_3
49505 , p_source_29 => p_source_29
49506          , x_transaction_coa_id       => l_adr_transaction_coa_id
49507          , x_accounting_coa_id        => l_adr_accounting_coa_id
49508          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
49509          , x_flex_value_set_id        => l_adr_flex_value_set_id
49510          , x_value_type_code          => l_adr_value_type_code
49511          , x_value_combination_id     => l_adr_value_combination_id
49512          , x_value_segment_code       => l_adr_value_segment_code
49513          , p_side                     => 'NA'
49514          , p_override_seg_flag        => 'Y'
49515    );
49516 
49517    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
49518 
49519       xla_ae_lines_pkg.set_segment(
49520           p_to_segment_code         => 'GL_BALANCING'
49521         , p_segment_value           => l_segment
49522         , p_from_segment_code       => l_adr_value_segment_code
49523         , p_from_combination_id     => l_adr_value_combination_id
49524         , p_value_type_code         => l_adr_value_type_code
49525         , p_transaction_coa_id      => l_adr_transaction_coa_id
49526         , p_accounting_coa_id       => l_adr_accounting_coa_id
49527         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
49528         , p_flex_value_set_id       => l_adr_flex_value_set_id
49529         , p_adr_code                => 'FA_EXPENSE_ACCT'
49530         , p_adr_type_code           => 'S'
49531         , p_component_type          => l_component_type
49532         , p_component_code          => l_component_code
49533         , p_component_type_code     => l_component_type_code
49534         , p_component_appl_id       => l_component_appl_id
49535         , p_amb_context_code        => l_amb_context_code
49536         , p_entity_code             => 'TRANSACTIONS'
49537         , p_event_class_code        => 'CIP_RETIREMENTS'
49538         , p_side                    => 'NA'
49539         );
49540 
49541   END IF;
49542 
49543    l_segment := AcctDerRule_162(
49544            p_application_id           => p_application_id
49545          , p_ae_header_id             => l_ae_header_id 
49546 , p_source_3 => p_source_3
49547 , p_source_24 => p_source_24
49548          , x_transaction_coa_id       => l_adr_transaction_coa_id
49549          , x_accounting_coa_id        => l_adr_accounting_coa_id
49550          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
49551          , x_flex_value_set_id        => l_adr_flex_value_set_id
49552          , x_value_type_code          => l_adr_value_type_code
49553          , x_value_combination_id     => l_adr_value_combination_id
49554          , x_value_segment_code       => l_adr_value_segment_code
49555          , p_side                     => 'NA'
49556          , p_override_seg_flag        => 'Y'
49557    );
49561       xla_ae_lines_pkg.set_segment(
49558 
49559    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
49560 
49562           p_to_segment_code         => 'GL_ACCOUNT'
49563         , p_segment_value           => l_segment
49564         , p_from_segment_code       => l_adr_value_segment_code
49565         , p_from_combination_id     => l_adr_value_combination_id
49566         , p_value_type_code         => l_adr_value_type_code
49567         , p_transaction_coa_id      => l_adr_transaction_coa_id
49568         , p_accounting_coa_id       => l_adr_accounting_coa_id
49569         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
49570         , p_flex_value_set_id       => l_adr_flex_value_set_id
49571         , p_adr_code                => 'FA_PROC_OF_SALE_GAIN_SEGMENT'
49572         , p_adr_type_code           => 'S'
49576         , p_component_appl_id       => l_component_appl_id
49573         , p_component_type          => l_component_type
49574         , p_component_code          => l_component_code
49575         , p_component_type_code     => l_component_type_code
49577         , p_amb_context_code        => l_amb_context_code
49578         , p_entity_code             => 'TRANSACTIONS'
49579         , p_event_class_code        => 'CIP_RETIREMENTS'
49580         , p_side                    => 'NA'
49581         );
49582 
49583   END IF;
49584 
49585    --
49586    --
49587    END IF;
49588 
49589        --
49590        -- Update the line information that should be overwritten
49591        --
49592        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
49593                                          p_header_num   => 1);
49594        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
49595 
49596        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
49597 
49598        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
49599           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
49600        END IF;
49601 
49602       --
49603       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
49604       --
49605       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
49606           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
49607       ELSE
49608           ---------------------------------------------------------------------------------------------------
49609           -- 4262811a Switch Sign
49610           ---------------------------------------------------------------------------------------------------
49611           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
49612           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
49613                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49614           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
49615                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49616           -- 5132302
49617           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
49618                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49619 
49620       END IF;
49621 
49622       -- 4955764
49623       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49624       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
49625 
49626 
49627       XLA_AE_LINES_PKG.ValidateCurrentLine;
49628       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
49629 
49630       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
49631                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
49632                ,p_balance_type_code => l_balance_type_code);
49633 
49634    END IF;
49635 
49636    -----------------------------------------------------------------------------------------
49637    -- 4262811 Multiperiod Accounting
49638    -----------------------------------------------------------------------------------------
49639      -- No MPA option is assigned.
49640 
49641 
49642 END IF;
49643 END IF;
49644 --
49645 
49646 --
49647 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
49648    trace
49649       (p_msg      => 'END of AcctLineType_223'
49650       ,p_level    => C_LEVEL_PROCEDURE
49651       ,p_module   => l_log_module);
49652 END IF;
49653 --
49654 EXCEPTION
49655   WHEN xla_exceptions_pkg.application_exception THEN
49656       RAISE;
49657   WHEN OTHERS THEN
49658        xla_exceptions_pkg.raise_message
49659            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_223');
49660 END AcctLineType_223;
49661 --
49662 
49663 ---------------------------------------
49664 --
49665 -- PRIVATE FUNCTION
49666 --         AcctLineType_224
49667 --
49668 ---------------------------------------
49669 PROCEDURE AcctLineType_224 (
49670   p_application_id        IN NUMBER
49671  ,p_event_id              IN NUMBER
49672  ,p_calculate_acctd_flag  IN VARCHAR2
49673  ,p_calculate_g_l_flag    IN VARCHAR2
49674  ,p_actual_flag           IN OUT VARCHAR2
49675  ,p_balance_type_code     OUT VARCHAR2
49676  ,p_gain_or_loss_ref      OUT VARCHAR2
49677  
49678 --Period Close Date
49679  , p_source_1            IN DATE
49680 --Generated Code Combination Identifier
49681  , p_source_3            IN NUMBER
49682 --Proceeds Of Sale Gain Account
49683  , p_source_24            IN VARCHAR2
49684 --Expense Account Code Combination Identifier
49685  , p_source_29            IN NUMBER
49686 --Default Code Combination Identifier
49687  , p_source_30            IN NUMBER
49688 --Adjustment Type
49689  , p_source_35            IN VARCHAR2
49690 --Transaction Header Identifier
49691  , p_source_36            IN NUMBER
49692 --Adjustment Line Identifier
49693  , p_source_37            IN NUMBER
49694 --Distribution Type Code
49695  , p_source_38            IN VARCHAR2
49696 --Entered Amount
49697  , p_source_39            IN NUMBER
49698 --Currency Code
49699  , p_source_40            IN VARCHAR2
49700 --Gain Loss Amount
49701  , p_source_41            IN NUMBER
49702 )
49703 IS
49704 
49705 l_component_type              VARCHAR2(80);
49706 l_component_code              VARCHAR2(30);
49707 l_component_type_code         VARCHAR2(1);
49711 l_event_class_code            VARCHAR2(30);
49708 l_component_appl_id           INTEGER;
49709 l_amb_context_code            VARCHAR2(30);
49710 l_entity_code                 VARCHAR2(30);
49712 l_ae_header_id                NUMBER;
49713 l_event_type_code             VARCHAR2(30);
49714 l_line_definition_code        VARCHAR2(30);
49715 l_line_definition_owner_code  VARCHAR2(1);
49716 --
49717 -- adr variables
49718 l_segment                     VARCHAR2(30);
49719 l_ccid                        NUMBER;
49720 l_adr_transaction_coa_id      NUMBER;
49721 l_adr_accounting_coa_id       NUMBER;
49722 l_adr_flexfield_segment_code  VARCHAR2(30);
49723 l_adr_flex_value_set_id       NUMBER;
49724 l_adr_value_type_code         VARCHAR2(30);
49725 l_adr_value_combination_id    NUMBER;
49726 l_adr_value_segment_code      VARCHAR2(30);
49727 
49728 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
49729 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
49730 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
49731 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
49732 
49733 -- 4262811 Variables ------------------------------------------------------------------------------------------
49734 l_entered_amt_idx             NUMBER;
49735 l_accted_amt_idx              NUMBER;
49736 l_acc_rev_flag                VARCHAR2(1);
49737 l_accrual_line_num            NUMBER;
49738 l_tmp_amt                     NUMBER;
49739 l_acc_rev_natural_side_code   VARCHAR2(1);
49740 
49741 l_num_entries                 NUMBER;
49742 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
49743 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
49744 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
49745 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
49746 l_recog_line_1                NUMBER;
49747 l_recog_line_2                NUMBER;
49748 
49749 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
49750 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
49751 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
49752 
49753 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
49754 
49755 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
49756 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
49757 
49758 ---------------------------------------------------------------------------------------------------------------
49759 
49760 
49761 --
49762 -- bulk performance
49763 --
49764 l_balance_type_code           VARCHAR2(1);
49765 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
49766 l_log_module                  VARCHAR2(240);
49767 
49768 --
49769 -- Upgrade strategy
49770 --
49771 l_actual_upg_option           VARCHAR2(1);
49772 l_enc_upg_option           VARCHAR2(1);
49773 
49774 --
49775 BEGIN
49776 --
49777 IF g_log_enabled THEN
49778       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_224';
49779 END IF;
49780 --
49781 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
49782 
49783       trace
49784          (p_msg      => 'BEGIN of AcctLineType_224'
49785          ,p_level    => C_LEVEL_PROCEDURE
49786          ,p_module   => l_log_module);
49787 
49788 END IF;
49789 --
49790 l_component_type             := 'AMB_JLT';
49791 l_component_code             := 'FA_CIP_PROC_OF_SALE_GAIN';
49792 l_component_type_code        := 'S';
49793 l_component_appl_id          :=  140;
49794 l_amb_context_code           := 'DEFAULT';
49795 l_entity_code                := 'TRANSACTIONS';
49796 l_event_class_code           := 'CIP_RETIREMENTS';
49797 l_event_type_code            := 'CIP_REINSTATEMENTS';
49798 l_line_definition_owner_code := 'S';
49799 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
49800 --
49801 l_balance_type_code          := 'A';
49802 l_segment                     := NULL;
49803 l_ccid                        := NULL;
49804 l_adr_transaction_coa_id      := NULL;
49805 l_adr_accounting_coa_id       := NULL;
49806 l_adr_flexfield_segment_code  := NULL;
49807 l_adr_flex_value_set_id       := NULL;
49808 l_adr_value_type_code         := NULL;
49809 l_adr_value_combination_id    := NULL;
49810 l_adr_value_segment_code      := NULL;
49811 
49812 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
49813 l_bflow_class_code           := '';    -- 4219869 Business Flow
49814 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
49815 l_budgetary_control_flag     := 'N';
49816 
49817 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
49818 l_bflow_applied_to_amt       := NULL; -- 5132302
49819 l_entered_amt_idx            := NULL;          -- 4262811
49820 l_accted_amt_idx             := NULL;          -- 4262811
49821 l_acc_rev_flag               := NULL;          -- 4262811
49822 l_accrual_line_num           := NULL;          -- 4262811
49823 l_tmp_amt                    := NULL;          -- 4262811
49824 --
49825  
49826 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
49827     l_balance_type_code <> 'B' THEN
49828 IF NVL(p_source_35,'
49829 ') =  'PROCEEDS' AND 
49830 p_source_41 >=  0
49831  THEN 
49832 
49833    --
49834    XLA_AE_LINES_PKG.SetNewLine;
49835 
49836    p_balance_type_code          := l_balance_type_code;
49837    -- set the flag so later we will know whether the gain loss line needs to be created
49838    
49839    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
49840      p_actual_flag :='A';
49841    END IF;
49842 
49843    --
49844    -- bulk performance
49845    --
49849    -- set accounting line options
49846    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
49847                                       p_header_num   => 0); -- 4262811
49848    --
49850    --
49851    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
49852            p_natural_side_code          => 'C'
49853          , p_gain_or_loss_flag          => 'N'
49854          , p_gl_transfer_mode_code      => 'S'
49855          , p_acct_entry_type_code       => 'A'
49856          , p_switch_side_flag           => 'Y'
49857          , p_merge_duplicate_code       => 'N'
49858          );
49859    --
49860    l_acc_rev_natural_side_code := 'D';  -- 4262811
49861    -- 
49862    --
49863    -- set accounting line type info
49864    --
49865    xla_ae_lines_pkg.SetAcctLineType
49866       (p_component_type             => l_component_type
49867       ,p_event_type_code            => l_event_type_code
49868       ,p_line_definition_owner_code => l_line_definition_owner_code
49869       ,p_line_definition_code       => l_line_definition_code
49870       ,p_accounting_line_code       => l_component_code
49874       ,p_entity_code                => l_entity_code
49871       ,p_accounting_line_type_code  => l_component_type_code
49872       ,p_accounting_line_appl_id    => l_component_appl_id
49873       ,p_amb_context_code           => l_amb_context_code
49875       ,p_event_class_code           => l_event_class_code);
49876    --
49877    -- set accounting class
49878    --
49879    xla_ae_lines_pkg.SetAcctClass(
49880            p_accounting_class_code  => 'ASSET'
49881          , p_ae_header_id           => l_ae_header_id
49882          );
49883 
49884    --
49885    -- set rounding class
49886    --
49887    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
49888                       'ASSET';
49889 
49890    --
49891    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
49892    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
49893    --
49894    -- bulk performance
49895    --
49896    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
49897 
49898    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
49899       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
49900 
49901    -- 4955764
49902    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49903       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
49904 
49905    -- 4458381 Public Sector Enh
49906    
49907    --
49908    -- set accounting attributes for the line type
49909    --
49910    l_entered_amt_idx := 4;
49911    l_accted_amt_idx  := 6;
49912    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
49913    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
49914    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
49915    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
49916    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
49917    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
49918    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
49919    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
49920    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
49921    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
49922    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
49923    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
49924    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
49925 
49926    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
49927    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
49928 
49929    ---------------------------------------------------------------------------------------------------------------
49933 
49930    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
49931    ---------------------------------------------------------------------------------------------------------------
49932    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
49934    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49935    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49936 
49937    IF xla_accounting_cache_pkg.GetValueChar
49938          (p_source_code         => 'LEDGER_CATEGORY_CODE'
49939          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
49940    AND l_bflow_method_code = 'PRIOR_ENTRY'
49941 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
49942    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
49943          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
49944        )
49945    THEN
49946          xla_ae_lines_pkg.BflowUpgEntry
49947            (p_business_method_code    => l_bflow_method_code
49948            ,p_business_class_code     => l_bflow_class_code
49949            ,p_balance_type            => l_balance_type_code);
49950    ELSE
49951       NULL;
49952 -- No business flow processing for business flow method of NONE.
49953    END IF;
49954 
49955    --
49956    -- call analytical criteria
49957    --
49958    
49959    --
49960    -- call description
49961    --
49962    
49963 xla_ae_lines_pkg.SetLineDescription(
49964    p_ae_header_id => l_ae_header_id
49965   ,p_description  => Description_35 (
49966      p_application_id         => p_application_id
49967    , p_ae_header_id           => l_ae_header_id 
49968 , p_source_1 => p_source_1
49969    )
49970 );
49971 
49972 
49973    --
49974    -- call ADRs
49975    -- Bug 4922099
49976    --
49977    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49978         (NVL(l_actual_upg_option, 'N') = 'O') OR
49979         (NVL(l_enc_upg_option, 'N') = 'O')
49980       )
49981    THEN
49982    NULL;
49983    --
49984    --
49985    
49986   l_ccid := AcctDerRule_173(
49987            p_application_id           => p_application_id
49988          , p_ae_header_id             => l_ae_header_id 
49989 , p_source_3 => p_source_3
49990 , p_source_30 => p_source_30
49991          , x_transaction_coa_id       => l_adr_transaction_coa_id
49992          , x_accounting_coa_id        => l_adr_accounting_coa_id
49993          , x_value_type_code          => l_adr_value_type_code
49994          , p_side                     => 'NA'
49995    );
49996 
49997    xla_ae_lines_pkg.set_ccid(
49998     p_code_combination_id          => l_ccid
49999   , p_value_type_code              => l_adr_value_type_code
50000   , p_transaction_coa_id           => l_adr_transaction_coa_id
50001   , p_accounting_coa_id            => l_adr_accounting_coa_id
50002   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
50003   , p_adr_type_code                => 'S'
50004   , p_component_type               => l_component_type
50005   , p_component_code               => l_component_code
50006   , p_component_type_code          => l_component_type_code
50007   , p_component_appl_id            => l_component_appl_id
50008   , p_amb_context_code             => l_amb_context_code
50009   , p_side                         => 'NA'
50010   );
50011 
50012 
50013    l_segment := AcctDerRule_168(
50014            p_application_id           => p_application_id
50015          , p_ae_header_id             => l_ae_header_id 
50016 , p_source_3 => p_source_3
50017 , p_source_29 => p_source_29
50018          , x_transaction_coa_id       => l_adr_transaction_coa_id
50019          , x_accounting_coa_id        => l_adr_accounting_coa_id
50023          , x_value_combination_id     => l_adr_value_combination_id
50020          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
50021          , x_flex_value_set_id        => l_adr_flex_value_set_id
50022          , x_value_type_code          => l_adr_value_type_code
50024          , x_value_segment_code       => l_adr_value_segment_code
50025          , p_side                     => 'NA'
50026          , p_override_seg_flag        => 'Y'
50027    );
50028 
50029    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
50030 
50031       xla_ae_lines_pkg.set_segment(
50032           p_to_segment_code         => 'GL_BALANCING'
50033         , p_segment_value           => l_segment
50034         , p_from_segment_code       => l_adr_value_segment_code
50035         , p_from_combination_id     => l_adr_value_combination_id
50036         , p_value_type_code         => l_adr_value_type_code
50037         , p_transaction_coa_id      => l_adr_transaction_coa_id
50041         , p_adr_code                => 'FA_EXPENSE_ACCT'
50038         , p_accounting_coa_id       => l_adr_accounting_coa_id
50039         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
50040         , p_flex_value_set_id       => l_adr_flex_value_set_id
50042         , p_adr_type_code           => 'S'
50043         , p_component_type          => l_component_type
50044         , p_component_code          => l_component_code
50045         , p_component_type_code     => l_component_type_code
50046         , p_component_appl_id       => l_component_appl_id
50047         , p_amb_context_code        => l_amb_context_code
50048         , p_entity_code             => 'TRANSACTIONS'
50049         , p_event_class_code        => 'CIP_RETIREMENTS'
50050         , p_side                    => 'NA'
50051         );
50052 
50053   END IF;
50054 
50055    l_segment := AcctDerRule_162(
50056            p_application_id           => p_application_id
50057          , p_ae_header_id             => l_ae_header_id 
50058 , p_source_3 => p_source_3
50059 , p_source_24 => p_source_24
50060          , x_transaction_coa_id       => l_adr_transaction_coa_id
50061          , x_accounting_coa_id        => l_adr_accounting_coa_id
50062          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
50063          , x_flex_value_set_id        => l_adr_flex_value_set_id
50064          , x_value_type_code          => l_adr_value_type_code
50065          , x_value_combination_id     => l_adr_value_combination_id
50066          , x_value_segment_code       => l_adr_value_segment_code
50067          , p_side                     => 'NA'
50068          , p_override_seg_flag        => 'Y'
50069    );
50070 
50071    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
50072 
50073       xla_ae_lines_pkg.set_segment(
50074           p_to_segment_code         => 'GL_ACCOUNT'
50075         , p_segment_value           => l_segment
50076         , p_from_segment_code       => l_adr_value_segment_code
50077         , p_from_combination_id     => l_adr_value_combination_id
50078         , p_value_type_code         => l_adr_value_type_code
50079         , p_transaction_coa_id      => l_adr_transaction_coa_id
50080         , p_accounting_coa_id       => l_adr_accounting_coa_id
50081         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
50082         , p_flex_value_set_id       => l_adr_flex_value_set_id
50083         , p_adr_code                => 'FA_PROC_OF_SALE_GAIN_SEGMENT'
50084         , p_adr_type_code           => 'S'
50085         , p_component_type          => l_component_type
50086         , p_component_code          => l_component_code
50087         , p_component_type_code     => l_component_type_code
50088         , p_component_appl_id       => l_component_appl_id
50089         , p_amb_context_code        => l_amb_context_code
50090         , p_entity_code             => 'TRANSACTIONS'
50091         , p_event_class_code        => 'CIP_RETIREMENTS'
50092         , p_side                    => 'NA'
50093         );
50094 
50095   END IF;
50096 
50097    --
50098    --
50099    END IF;
50100    --
50101    -- Bug 4922099
50102    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
50103           (NVL(l_enc_upg_option, 'N') = 'O')
50104         ) AND
50105         (l_bflow_method_code = 'PRIOR_ENTRY')
50106       )
50107    THEN
50108       IF
50109       --
50110       1 = 2
50111       --
50112       THEN
50113       xla_accounting_err_pkg.build_message
50114                                     (p_appli_s_name            => 'XLA'
50115                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50116                                     ,p_token_1                 => 'LINE_NUMBER'
50117                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
50118                                     ,p_token_2                 => 'LINE_TYPE_NAME'
50119                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
50120                                                                              l_component_type
50121                                                                             ,l_component_code
50122                                                                             ,l_component_type_code
50123                                                                             ,l_component_appl_id
50124                                                                             ,l_amb_context_code
50125                                                                             ,l_entity_code
50126                                                                             ,l_event_class_code
50127                                                                            )
50128                                     ,p_token_3                 => 'OWNER'
50129                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
50130                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
50131                                                                           ,p_lookup_code    => l_component_type_code
50132                                                                          )
50133                                     ,p_token_4                 => 'PRODUCT_NAME'
50134                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
50135                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
50136                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
50137                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
50138                                     ,p_ae_header_id            =>  NULL
50139                                        );
50140 
50141         IF (C_LEVEL_ERROR>= g_log_level) THEN
50145                       ,p_module   => l_log_module);
50142                  trace
50143                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50144                       ,p_level    => C_LEVEL_ERROR
50146         END IF;
50147       END IF;
50148    END IF;
50149    --
50150    --
50151    ------------------------------------------------------------------------------------------------
50152    -- 4219869 Business Flow
50153    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
50154    -- Prior Entry.  Currently, the following code is always generated.
50155    ------------------------------------------------------------------------------------------------
50156    XLA_AE_LINES_PKG.ValidateCurrentLine;
50157 
50158    ------------------------------------------------------------------------------------
50159    -- 4219869 Business Flow
50160    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
50161    ------------------------------------------------------------------------------------
50162    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50163 
50164    ----------------------------------------------------------------------------------
50165    -- 4219869 Business Flow
50166    -- Update journal entry status -- Need to generate this within IF <condition>
50167    ----------------------------------------------------------------------------------
50168    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50169          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
50170          ,p_balance_type_code => l_balance_type_code
50171          );
50172 
50173    -------------------------------------------------------------------------------------------
50174    -- 4262811 - Generate the Accrual Reversal lines
50175    -------------------------------------------------------------------------------------------
50176    BEGIN
50177       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
50178                               (g_array_event(p_event_id).array_value_num('header_index'));
50179       IF l_acc_rev_flag IS NULL THEN
50180          l_acc_rev_flag := 'N';
50181       END IF;
50182    EXCEPTION
50183       WHEN OTHERS THEN
50184          l_acc_rev_flag := 'N';
50185    END;
50186    --
50187    IF (l_acc_rev_flag = 'Y') THEN
50188 
50189        -- 4645092  ------------------------------------------------------------------------------
50190        -- To allow MPA report to determine if it should generate report process
50191        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
50192        ------------------------------------------------------------------------------------------
50193 
50194        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
50195        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
50196    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
50197    -- call ADRs
50198    -- Bug 4922099
50199    --
50200    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50204    THEN
50201         (NVL(l_actual_upg_option, 'N') = 'O') OR
50202         (NVL(l_enc_upg_option, 'N') = 'O')
50203       )
50205    NULL;
50206    --
50207    --
50208    
50209   l_ccid := AcctDerRule_173(
50210            p_application_id           => p_application_id
50211          , p_ae_header_id             => l_ae_header_id 
50212 , p_source_3 => p_source_3
50213 , p_source_30 => p_source_30
50214          , x_transaction_coa_id       => l_adr_transaction_coa_id
50215          , x_accounting_coa_id        => l_adr_accounting_coa_id
50216          , x_value_type_code          => l_adr_value_type_code
50217          , p_side                     => 'NA'
50218    );
50219 
50220    xla_ae_lines_pkg.set_ccid(
50221     p_code_combination_id          => l_ccid
50222   , p_value_type_code              => l_adr_value_type_code
50223   , p_transaction_coa_id           => l_adr_transaction_coa_id
50224   , p_accounting_coa_id            => l_adr_accounting_coa_id
50225   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
50226   , p_adr_type_code                => 'S'
50227   , p_component_type               => l_component_type
50228   , p_component_code               => l_component_code
50229   , p_component_type_code          => l_component_type_code
50230   , p_component_appl_id            => l_component_appl_id
50231   , p_amb_context_code             => l_amb_context_code
50232   , p_side                         => 'NA'
50233   );
50234 
50235 
50236    l_segment := AcctDerRule_168(
50237            p_application_id           => p_application_id
50238          , p_ae_header_id             => l_ae_header_id 
50239 , p_source_3 => p_source_3
50240 , p_source_29 => p_source_29
50241          , x_transaction_coa_id       => l_adr_transaction_coa_id
50242          , x_accounting_coa_id        => l_adr_accounting_coa_id
50243          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
50244          , x_flex_value_set_id        => l_adr_flex_value_set_id
50245          , x_value_type_code          => l_adr_value_type_code
50246          , x_value_combination_id     => l_adr_value_combination_id
50247          , x_value_segment_code       => l_adr_value_segment_code
50248          , p_side                     => 'NA'
50249          , p_override_seg_flag        => 'Y'
50250    );
50251 
50252    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
50253 
50254       xla_ae_lines_pkg.set_segment(
50255           p_to_segment_code         => 'GL_BALANCING'
50256         , p_segment_value           => l_segment
50257         , p_from_segment_code       => l_adr_value_segment_code
50258         , p_from_combination_id     => l_adr_value_combination_id
50259         , p_value_type_code         => l_adr_value_type_code
50260         , p_transaction_coa_id      => l_adr_transaction_coa_id
50261         , p_accounting_coa_id       => l_adr_accounting_coa_id
50262         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
50263         , p_flex_value_set_id       => l_adr_flex_value_set_id
50264         , p_adr_code                => 'FA_EXPENSE_ACCT'
50265         , p_adr_type_code           => 'S'
50266         , p_component_type          => l_component_type
50267         , p_component_code          => l_component_code
50268         , p_component_type_code     => l_component_type_code
50269         , p_component_appl_id       => l_component_appl_id
50270         , p_amb_context_code        => l_amb_context_code
50271         , p_entity_code             => 'TRANSACTIONS'
50272         , p_event_class_code        => 'CIP_RETIREMENTS'
50273         , p_side                    => 'NA'
50274         );
50275 
50276   END IF;
50277 
50278    l_segment := AcctDerRule_162(
50279            p_application_id           => p_application_id
50280          , p_ae_header_id             => l_ae_header_id 
50284          , x_accounting_coa_id        => l_adr_accounting_coa_id
50281 , p_source_3 => p_source_3
50282 , p_source_24 => p_source_24
50283          , x_transaction_coa_id       => l_adr_transaction_coa_id
50285          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
50286          , x_flex_value_set_id        => l_adr_flex_value_set_id
50287          , x_value_type_code          => l_adr_value_type_code
50288          , x_value_combination_id     => l_adr_value_combination_id
50289          , x_value_segment_code       => l_adr_value_segment_code
50290          , p_side                     => 'NA'
50291          , p_override_seg_flag        => 'Y'
50292    );
50293 
50294    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
50295 
50296       xla_ae_lines_pkg.set_segment(
50297           p_to_segment_code         => 'GL_ACCOUNT'
50298         , p_segment_value           => l_segment
50299         , p_from_segment_code       => l_adr_value_segment_code
50300         , p_from_combination_id     => l_adr_value_combination_id
50301         , p_value_type_code         => l_adr_value_type_code
50305         , p_flex_value_set_id       => l_adr_flex_value_set_id
50302         , p_transaction_coa_id      => l_adr_transaction_coa_id
50303         , p_accounting_coa_id       => l_adr_accounting_coa_id
50304         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
50306         , p_adr_code                => 'FA_PROC_OF_SALE_GAIN_SEGMENT'
50307         , p_adr_type_code           => 'S'
50308         , p_component_type          => l_component_type
50309         , p_component_code          => l_component_code
50310         , p_component_type_code     => l_component_type_code
50311         , p_component_appl_id       => l_component_appl_id
50312         , p_amb_context_code        => l_amb_context_code
50313         , p_entity_code             => 'TRANSACTIONS'
50314         , p_event_class_code        => 'CIP_RETIREMENTS'
50315         , p_side                    => 'NA'
50316         );
50317 
50318   END IF;
50319 
50320    --
50321    --
50322    END IF;
50323 
50324        --
50325        -- Update the line information that should be overwritten
50326        --
50327        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
50328                                          p_header_num   => 1);
50329        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
50330 
50331        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
50332 
50333        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
50334           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
50335        END IF;
50336 
50337       --
50338       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
50339       --
50340       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
50341           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
50342       ELSE
50343           ---------------------------------------------------------------------------------------------------
50344           -- 4262811a Switch Sign
50345           ---------------------------------------------------------------------------------------------------
50346           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
50347           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50348                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50349           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50350                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50351           -- 5132302
50352           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
50353                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50354 
50355       END IF;
50356 
50357       -- 4955764
50358       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
50359       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
50360 
50361 
50362       XLA_AE_LINES_PKG.ValidateCurrentLine;
50363       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50364 
50365       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50366                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
50367                ,p_balance_type_code => l_balance_type_code);
50368 
50369    END IF;
50370 
50371    -----------------------------------------------------------------------------------------
50372    -- 4262811 Multiperiod Accounting
50373    -----------------------------------------------------------------------------------------
50374      -- No MPA option is assigned.
50375 
50376 
50377 END IF;
50378 END IF;
50379 --
50380 
50381 --
50382 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50383    trace
50384       (p_msg      => 'END of AcctLineType_224'
50385       ,p_level    => C_LEVEL_PROCEDURE
50386       ,p_module   => l_log_module);
50387 END IF;
50388 --
50389 EXCEPTION
50390   WHEN xla_exceptions_pkg.application_exception THEN
50391       RAISE;
50392   WHEN OTHERS THEN
50393        xla_exceptions_pkg.raise_message
50394            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_224');
50395 END AcctLineType_224;
50396 --
50397 
50398 ---------------------------------------
50399 --
50400 -- PRIVATE FUNCTION
50401 --         AcctLineType_225
50402 --
50403 ---------------------------------------
50404 PROCEDURE AcctLineType_225 (
50405   p_application_id        IN NUMBER
50406  ,p_event_id              IN NUMBER
50407  ,p_calculate_acctd_flag  IN VARCHAR2
50408  ,p_calculate_g_l_flag    IN VARCHAR2
50409  ,p_actual_flag           IN OUT VARCHAR2
50410  ,p_balance_type_code     OUT VARCHAR2
50411  ,p_gain_or_loss_ref      OUT VARCHAR2
50412  
50413 --Period Close Date
50414  , p_source_1            IN DATE
50415 --Generated Code Combination Identifier
50416  , p_source_3            IN NUMBER
50417 --Proceeds Of Sale Loss Account
50418  , p_source_25            IN VARCHAR2
50419 --Expense Account Code Combination Identifier
50420  , p_source_29            IN NUMBER
50421 --Default Code Combination Identifier
50422  , p_source_30            IN NUMBER
50423 --Adjustment Type
50424  , p_source_35            IN VARCHAR2
50425 --Transaction Header Identifier
50426  , p_source_36            IN NUMBER
50427 --Adjustment Line Identifier
50428  , p_source_37            IN NUMBER
50432  , p_source_39            IN NUMBER
50429 --Distribution Type Code
50430  , p_source_38            IN VARCHAR2
50431 --Entered Amount
50433 --Currency Code
50434  , p_source_40            IN VARCHAR2
50435 --Gain Loss Amount
50436  , p_source_41            IN NUMBER
50437 )
50438 IS
50439 
50440 l_component_type              VARCHAR2(80);
50441 l_component_code              VARCHAR2(30);
50442 l_component_type_code         VARCHAR2(1);
50443 l_component_appl_id           INTEGER;
50444 l_amb_context_code            VARCHAR2(30);
50445 l_entity_code                 VARCHAR2(30);
50446 l_event_class_code            VARCHAR2(30);
50447 l_ae_header_id                NUMBER;
50448 l_event_type_code             VARCHAR2(30);
50449 l_line_definition_code        VARCHAR2(30);
50450 l_line_definition_owner_code  VARCHAR2(1);
50451 --
50452 -- adr variables
50453 l_segment                     VARCHAR2(30);
50454 l_ccid                        NUMBER;
50455 l_adr_transaction_coa_id      NUMBER;
50456 l_adr_accounting_coa_id       NUMBER;
50457 l_adr_flexfield_segment_code  VARCHAR2(30);
50458 l_adr_flex_value_set_id       NUMBER;
50459 l_adr_value_type_code         VARCHAR2(30);
50460 l_adr_value_combination_id    NUMBER;
50461 l_adr_value_segment_code      VARCHAR2(30);
50462 
50463 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
50464 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
50465 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
50466 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
50467 
50468 -- 4262811 Variables ------------------------------------------------------------------------------------------
50469 l_entered_amt_idx             NUMBER;
50470 l_accted_amt_idx              NUMBER;
50471 l_acc_rev_flag                VARCHAR2(1);
50472 l_accrual_line_num            NUMBER;
50473 l_tmp_amt                     NUMBER;
50474 l_acc_rev_natural_side_code   VARCHAR2(1);
50475 
50476 l_num_entries                 NUMBER;
50477 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
50478 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
50479 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
50480 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
50481 l_recog_line_1                NUMBER;
50482 l_recog_line_2                NUMBER;
50483 
50484 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
50485 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
50486 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
50487 
50488 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
50489 
50490 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
50491 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
50492 
50493 ---------------------------------------------------------------------------------------------------------------
50494 
50495 
50496 --
50497 -- bulk performance
50498 --
50499 l_balance_type_code           VARCHAR2(1);
50500 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
50501 l_log_module                  VARCHAR2(240);
50502 
50503 --
50504 -- Upgrade strategy
50505 --
50506 l_actual_upg_option           VARCHAR2(1);
50507 l_enc_upg_option           VARCHAR2(1);
50508 
50509 --
50510 BEGIN
50511 --
50512 IF g_log_enabled THEN
50513       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_225';
50514 END IF;
50515 --
50516 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50517 
50518       trace
50519          (p_msg      => 'BEGIN of AcctLineType_225'
50520          ,p_level    => C_LEVEL_PROCEDURE
50521          ,p_module   => l_log_module);
50522 
50523 END IF;
50524 --
50525 l_component_type             := 'AMB_JLT';
50526 l_component_code             := 'FA_CIP_PROC_OF_SALE_LOSS';
50530 l_entity_code                := 'TRANSACTIONS';
50527 l_component_type_code        := 'S';
50528 l_component_appl_id          :=  140;
50529 l_amb_context_code           := 'DEFAULT';
50531 l_event_class_code           := 'CIP_RETIREMENTS';
50532 l_event_type_code            := 'CIP_RETIREMENTS';
50533 l_line_definition_owner_code := 'S';
50534 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
50535 --
50536 l_balance_type_code          := 'A';
50537 l_segment                     := NULL;
50538 l_ccid                        := NULL;
50539 l_adr_transaction_coa_id      := NULL;
50540 l_adr_accounting_coa_id       := NULL;
50541 l_adr_flexfield_segment_code  := NULL;
50542 l_adr_flex_value_set_id       := NULL;
50543 l_adr_value_type_code         := NULL;
50544 l_adr_value_combination_id    := NULL;
50545 l_adr_value_segment_code      := NULL;
50546 
50547 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
50548 l_bflow_class_code           := '';    -- 4219869 Business Flow
50549 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
50550 l_budgetary_control_flag     := 'N';
50551 
50552 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
50553 l_bflow_applied_to_amt       := NULL; -- 5132302
50554 l_entered_amt_idx            := NULL;          -- 4262811
50555 l_accted_amt_idx             := NULL;          -- 4262811
50556 l_acc_rev_flag               := NULL;          -- 4262811
50557 l_accrual_line_num           := NULL;          -- 4262811
50558 l_tmp_amt                    := NULL;          -- 4262811
50559 --
50560  
50561 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
50562     l_balance_type_code <> 'B' THEN
50563 IF NVL(p_source_35,'
50564 ') =  'PROCEEDS' AND 
50565 p_source_41 <  0
50566  THEN 
50567 
50568    --
50569    XLA_AE_LINES_PKG.SetNewLine;
50570 
50571    p_balance_type_code          := l_balance_type_code;
50572    -- set the flag so later we will know whether the gain loss line needs to be created
50573    
50574    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
50575      p_actual_flag :='A';
50576    END IF;
50577 
50578    --
50579    -- bulk performance
50580    --
50581    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
50582                                       p_header_num   => 0); -- 4262811
50583    --
50584    -- set accounting line options
50585    --
50586    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
50587            p_natural_side_code          => 'C'
50588          , p_gain_or_loss_flag          => 'N'
50589          , p_gl_transfer_mode_code      => 'S'
50590          , p_acct_entry_type_code       => 'A'
50594    --
50591          , p_switch_side_flag           => 'Y'
50592          , p_merge_duplicate_code       => 'N'
50593          );
50595    l_acc_rev_natural_side_code := 'D';  -- 4262811
50596    -- 
50597    --
50598    -- set accounting line type info
50599    --
50600    xla_ae_lines_pkg.SetAcctLineType
50601       (p_component_type             => l_component_type
50602       ,p_event_type_code            => l_event_type_code
50603       ,p_line_definition_owner_code => l_line_definition_owner_code
50604       ,p_line_definition_code       => l_line_definition_code
50605       ,p_accounting_line_code       => l_component_code
50606       ,p_accounting_line_type_code  => l_component_type_code
50607       ,p_accounting_line_appl_id    => l_component_appl_id
50608       ,p_amb_context_code           => l_amb_context_code
50609       ,p_entity_code                => l_entity_code
50610       ,p_event_class_code           => l_event_class_code);
50611    --
50612    -- set accounting class
50613    --
50614    xla_ae_lines_pkg.SetAcctClass(
50615            p_accounting_class_code  => 'ASSET'
50616          , p_ae_header_id           => l_ae_header_id
50617          );
50618 
50619    --
50620    -- set rounding class
50621    --
50622    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
50623                       'ASSET';
50624 
50625    --
50626    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
50627    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
50628    --
50629    -- bulk performance
50630    --
50631    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
50632 
50633    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
50634       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
50635 
50636    -- 4955764
50637    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
50638       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
50639 
50640    -- 4458381 Public Sector Enh
50644    --
50641    
50642    --
50643    -- set accounting attributes for the line type
50645    l_entered_amt_idx := 4;
50646    l_accted_amt_idx  := 6;
50647    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
50648    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
50649    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
50650    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
50651    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
50652    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
50653    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
50654    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
50655    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
50656    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
50657    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
50658    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
50659    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
50660 
50661    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
50662    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
50663 
50664    ---------------------------------------------------------------------------------------------------------------
50665    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
50666    ---------------------------------------------------------------------------------------------------------------
50667    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
50668 
50669    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
50670    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
50671 
50672    IF xla_accounting_cache_pkg.GetValueChar
50673          (p_source_code         => 'LEDGER_CATEGORY_CODE'
50674          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
50675    AND l_bflow_method_code = 'PRIOR_ENTRY'
50676 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
50677    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
50678          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
50679        )
50680    THEN
50681          xla_ae_lines_pkg.BflowUpgEntry
50682            (p_business_method_code    => l_bflow_method_code
50683            ,p_business_class_code     => l_bflow_class_code
50684            ,p_balance_type            => l_balance_type_code);
50685    ELSE
50686       NULL;
50687 -- No business flow processing for business flow method of NONE.
50688    END IF;
50689 
50690    --
50691    -- call analytical criteria
50692    --
50693    
50694    --
50695    -- call description
50696    --
50697    
50698 xla_ae_lines_pkg.SetLineDescription(
50699    p_ae_header_id => l_ae_header_id
50700   ,p_description  => Description_35 (
50701      p_application_id         => p_application_id
50702    , p_ae_header_id           => l_ae_header_id 
50703 , p_source_1 => p_source_1
50704    )
50705 );
50706 
50707 
50708    --
50709    -- call ADRs
50710    -- Bug 4922099
50711    --
50712    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50713         (NVL(l_actual_upg_option, 'N') = 'O') OR
50714         (NVL(l_enc_upg_option, 'N') = 'O')
50715       )
50716    THEN
50717    NULL;
50718    --
50719    --
50720    
50721   l_ccid := AcctDerRule_173(
50722            p_application_id           => p_application_id
50723          , p_ae_header_id             => l_ae_header_id 
50724 , p_source_3 => p_source_3
50725 , p_source_30 => p_source_30
50726          , x_transaction_coa_id       => l_adr_transaction_coa_id
50727          , x_accounting_coa_id        => l_adr_accounting_coa_id
50728          , x_value_type_code          => l_adr_value_type_code
50729          , p_side                     => 'NA'
50730    );
50731 
50732    xla_ae_lines_pkg.set_ccid(
50733     p_code_combination_id          => l_ccid
50734   , p_value_type_code              => l_adr_value_type_code
50735   , p_transaction_coa_id           => l_adr_transaction_coa_id
50736   , p_accounting_coa_id            => l_adr_accounting_coa_id
50737   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
50738   , p_adr_type_code                => 'S'
50739   , p_component_type               => l_component_type
50740   , p_component_code               => l_component_code
50744   , p_side                         => 'NA'
50741   , p_component_type_code          => l_component_type_code
50742   , p_component_appl_id            => l_component_appl_id
50743   , p_amb_context_code             => l_amb_context_code
50745   );
50746 
50747 
50748    l_segment := AcctDerRule_168(
50749            p_application_id           => p_application_id
50750          , p_ae_header_id             => l_ae_header_id 
50751 , p_source_3 => p_source_3
50752 , p_source_29 => p_source_29
50753          , x_transaction_coa_id       => l_adr_transaction_coa_id
50754          , x_accounting_coa_id        => l_adr_accounting_coa_id
50755          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
50756          , x_flex_value_set_id        => l_adr_flex_value_set_id
50757          , x_value_type_code          => l_adr_value_type_code
50758          , x_value_combination_id     => l_adr_value_combination_id
50759          , x_value_segment_code       => l_adr_value_segment_code
50760          , p_side                     => 'NA'
50761          , p_override_seg_flag        => 'Y'
50762    );
50763 
50764    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
50765 
50766       xla_ae_lines_pkg.set_segment(
50767           p_to_segment_code         => 'GL_BALANCING'
50768         , p_segment_value           => l_segment
50769         , p_from_segment_code       => l_adr_value_segment_code
50770         , p_from_combination_id     => l_adr_value_combination_id
50771         , p_value_type_code         => l_adr_value_type_code
50772         , p_transaction_coa_id      => l_adr_transaction_coa_id
50773         , p_accounting_coa_id       => l_adr_accounting_coa_id
50774         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
50775         , p_flex_value_set_id       => l_adr_flex_value_set_id
50776         , p_adr_code                => 'FA_EXPENSE_ACCT'
50777         , p_adr_type_code           => 'S'
50778         , p_component_type          => l_component_type
50779         , p_component_code          => l_component_code
50780         , p_component_type_code     => l_component_type_code
50781         , p_component_appl_id       => l_component_appl_id
50782         , p_amb_context_code        => l_amb_context_code
50783         , p_entity_code             => 'TRANSACTIONS'
50784         , p_event_class_code        => 'CIP_RETIREMENTS'
50785         , p_side                    => 'NA'
50786         );
50787 
50788   END IF;
50789 
50790    l_segment := AcctDerRule_163(
50791            p_application_id           => p_application_id
50792          , p_ae_header_id             => l_ae_header_id 
50793 , p_source_3 => p_source_3
50794 , p_source_25 => p_source_25
50795          , x_transaction_coa_id       => l_adr_transaction_coa_id
50796          , x_accounting_coa_id        => l_adr_accounting_coa_id
50797          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
50798          , x_flex_value_set_id        => l_adr_flex_value_set_id
50799          , x_value_type_code          => l_adr_value_type_code
50800          , x_value_combination_id     => l_adr_value_combination_id
50801          , x_value_segment_code       => l_adr_value_segment_code
50802          , p_side                     => 'NA'
50803          , p_override_seg_flag        => 'Y'
50804    );
50805 
50806    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
50807 
50808       xla_ae_lines_pkg.set_segment(
50809           p_to_segment_code         => 'GL_ACCOUNT'
50810         , p_segment_value           => l_segment
50811         , p_from_segment_code       => l_adr_value_segment_code
50812         , p_from_combination_id     => l_adr_value_combination_id
50813         , p_value_type_code         => l_adr_value_type_code
50814         , p_transaction_coa_id      => l_adr_transaction_coa_id
50815         , p_accounting_coa_id       => l_adr_accounting_coa_id
50816         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
50817         , p_flex_value_set_id       => l_adr_flex_value_set_id
50818         , p_adr_code                => 'FA_PROC_OF_SALE_LOSS_SEGMENT'
50819         , p_adr_type_code           => 'S'
50820         , p_component_type          => l_component_type
50821         , p_component_code          => l_component_code
50822         , p_component_type_code     => l_component_type_code
50823         , p_component_appl_id       => l_component_appl_id
50827         , p_side                    => 'NA'
50824         , p_amb_context_code        => l_amb_context_code
50825         , p_entity_code             => 'TRANSACTIONS'
50826         , p_event_class_code        => 'CIP_RETIREMENTS'
50828         );
50829 
50830   END IF;
50831 
50832    --
50833    --
50834    END IF;
50835    --
50836    -- Bug 4922099
50837    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
50838           (NVL(l_enc_upg_option, 'N') = 'O')
50839         ) AND
50840         (l_bflow_method_code = 'PRIOR_ENTRY')
50841       )
50842    THEN
50843       IF
50844       --
50845       1 = 2
50846       --
50847       THEN
50848       xla_accounting_err_pkg.build_message
50849                                     (p_appli_s_name            => 'XLA'
50850                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50851                                     ,p_token_1                 => 'LINE_NUMBER'
50852                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
50853                                     ,p_token_2                 => 'LINE_TYPE_NAME'
50854                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
50855                                                                              l_component_type
50856                                                                             ,l_component_code
50857                                                                             ,l_component_type_code
50858                                                                             ,l_component_appl_id
50859                                                                             ,l_amb_context_code
50860                                                                             ,l_entity_code
50861                                                                             ,l_event_class_code
50862                                                                            )
50863                                     ,p_token_3                 => 'OWNER'
50864                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
50865                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
50866                                                                           ,p_lookup_code    => l_component_type_code
50867                                                                          )
50868                                     ,p_token_4                 => 'PRODUCT_NAME'
50872                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
50869                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
50870                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
50871                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
50873                                     ,p_ae_header_id            =>  NULL
50874                                        );
50875 
50876         IF (C_LEVEL_ERROR>= g_log_level) THEN
50877                  trace
50878                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50879                       ,p_level    => C_LEVEL_ERROR
50880                       ,p_module   => l_log_module);
50881         END IF;
50882       END IF;
50883    END IF;
50884    --
50885    --
50886    ------------------------------------------------------------------------------------------------
50887    -- 4219869 Business Flow
50888    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
50889    -- Prior Entry.  Currently, the following code is always generated.
50890    ------------------------------------------------------------------------------------------------
50891    XLA_AE_LINES_PKG.ValidateCurrentLine;
50892 
50893    ------------------------------------------------------------------------------------
50894    -- 4219869 Business Flow
50895    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
50896    ------------------------------------------------------------------------------------
50897    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50898 
50899    ----------------------------------------------------------------------------------
50900    -- 4219869 Business Flow
50901    -- Update journal entry status -- Need to generate this within IF <condition>
50902    ----------------------------------------------------------------------------------
50903    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50904          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
50905          ,p_balance_type_code => l_balance_type_code
50906          );
50907 
50908    -------------------------------------------------------------------------------------------
50909    -- 4262811 - Generate the Accrual Reversal lines
50913                               (g_array_event(p_event_id).array_value_num('header_index'));
50910    -------------------------------------------------------------------------------------------
50911    BEGIN
50912       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
50914       IF l_acc_rev_flag IS NULL THEN
50915          l_acc_rev_flag := 'N';
50916       END IF;
50917    EXCEPTION
50918       WHEN OTHERS THEN
50919          l_acc_rev_flag := 'N';
50920    END;
50921    --
50922    IF (l_acc_rev_flag = 'Y') THEN
50923 
50924        -- 4645092  ------------------------------------------------------------------------------
50925        -- To allow MPA report to determine if it should generate report process
50926        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
50927        ------------------------------------------------------------------------------------------
50928 
50929        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
50930        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
50931    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
50932    -- call ADRs
50933    -- Bug 4922099
50934    --
50935    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50936         (NVL(l_actual_upg_option, 'N') = 'O') OR
50937         (NVL(l_enc_upg_option, 'N') = 'O')
50938       )
50939    THEN
50940    NULL;
50941    --
50942    --
50943    
50944   l_ccid := AcctDerRule_173(
50945            p_application_id           => p_application_id
50946          , p_ae_header_id             => l_ae_header_id 
50947 , p_source_3 => p_source_3
50948 , p_source_30 => p_source_30
50949          , x_transaction_coa_id       => l_adr_transaction_coa_id
50950          , x_accounting_coa_id        => l_adr_accounting_coa_id
50951          , x_value_type_code          => l_adr_value_type_code
50952          , p_side                     => 'NA'
50953    );
50954 
50955    xla_ae_lines_pkg.set_ccid(
50956     p_code_combination_id          => l_ccid
50957   , p_value_type_code              => l_adr_value_type_code
50958   , p_transaction_coa_id           => l_adr_transaction_coa_id
50959   , p_accounting_coa_id            => l_adr_accounting_coa_id
50960   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
50961   , p_adr_type_code                => 'S'
50962   , p_component_type               => l_component_type
50963   , p_component_code               => l_component_code
50964   , p_component_type_code          => l_component_type_code
50965   , p_component_appl_id            => l_component_appl_id
50966   , p_amb_context_code             => l_amb_context_code
50967   , p_side                         => 'NA'
50968   );
50969 
50970 
50971    l_segment := AcctDerRule_168(
50972            p_application_id           => p_application_id
50973          , p_ae_header_id             => l_ae_header_id 
50974 , p_source_3 => p_source_3
50975 , p_source_29 => p_source_29
50976          , x_transaction_coa_id       => l_adr_transaction_coa_id
50977          , x_accounting_coa_id        => l_adr_accounting_coa_id
50978          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
50979          , x_flex_value_set_id        => l_adr_flex_value_set_id
50980          , x_value_type_code          => l_adr_value_type_code
50981          , x_value_combination_id     => l_adr_value_combination_id
50982          , x_value_segment_code       => l_adr_value_segment_code
50983          , p_side                     => 'NA'
50984          , p_override_seg_flag        => 'Y'
50985    );
50986 
50987    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
50988 
50989       xla_ae_lines_pkg.set_segment(
50990           p_to_segment_code         => 'GL_BALANCING'
50991         , p_segment_value           => l_segment
50992         , p_from_segment_code       => l_adr_value_segment_code
50993         , p_from_combination_id     => l_adr_value_combination_id
50994         , p_value_type_code         => l_adr_value_type_code
50995         , p_transaction_coa_id      => l_adr_transaction_coa_id
50996         , p_accounting_coa_id       => l_adr_accounting_coa_id
50997         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
50998         , p_flex_value_set_id       => l_adr_flex_value_set_id
50999         , p_adr_code                => 'FA_EXPENSE_ACCT'
51000         , p_adr_type_code           => 'S'
51001         , p_component_type          => l_component_type
51005         , p_amb_context_code        => l_amb_context_code
51002         , p_component_code          => l_component_code
51003         , p_component_type_code     => l_component_type_code
51004         , p_component_appl_id       => l_component_appl_id
51006         , p_entity_code             => 'TRANSACTIONS'
51007         , p_event_class_code        => 'CIP_RETIREMENTS'
51008         , p_side                    => 'NA'
51009         );
51010 
51011   END IF;
51012 
51013    l_segment := AcctDerRule_163(
51014            p_application_id           => p_application_id
51018          , x_transaction_coa_id       => l_adr_transaction_coa_id
51015          , p_ae_header_id             => l_ae_header_id 
51016 , p_source_3 => p_source_3
51017 , p_source_25 => p_source_25
51019          , x_accounting_coa_id        => l_adr_accounting_coa_id
51020          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
51021          , x_flex_value_set_id        => l_adr_flex_value_set_id
51022          , x_value_type_code          => l_adr_value_type_code
51023          , x_value_combination_id     => l_adr_value_combination_id
51024          , x_value_segment_code       => l_adr_value_segment_code
51025          , p_side                     => 'NA'
51026          , p_override_seg_flag        => 'Y'
51027    );
51028 
51029    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
51030 
51031       xla_ae_lines_pkg.set_segment(
51032           p_to_segment_code         => 'GL_ACCOUNT'
51033         , p_segment_value           => l_segment
51034         , p_from_segment_code       => l_adr_value_segment_code
51035         , p_from_combination_id     => l_adr_value_combination_id
51036         , p_value_type_code         => l_adr_value_type_code
51037         , p_transaction_coa_id      => l_adr_transaction_coa_id
51038         , p_accounting_coa_id       => l_adr_accounting_coa_id
51039         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
51040         , p_flex_value_set_id       => l_adr_flex_value_set_id
51041         , p_adr_code                => 'FA_PROC_OF_SALE_LOSS_SEGMENT'
51042         , p_adr_type_code           => 'S'
51043         , p_component_type          => l_component_type
51044         , p_component_code          => l_component_code
51045         , p_component_type_code     => l_component_type_code
51046         , p_component_appl_id       => l_component_appl_id
51047         , p_amb_context_code        => l_amb_context_code
51048         , p_entity_code             => 'TRANSACTIONS'
51049         , p_event_class_code        => 'CIP_RETIREMENTS'
51050         , p_side                    => 'NA'
51051         );
51052 
51053   END IF;
51054 
51055    --
51056    --
51057    END IF;
51058 
51059        --
51060        -- Update the line information that should be overwritten
51061        --
51062        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
51063                                          p_header_num   => 1);
51064        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
51065 
51066        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
51067 
51068        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
51069           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
51070        END IF;
51071 
51072       --
51073       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
51074       --
51075       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
51076           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
51077       ELSE
51078           ---------------------------------------------------------------------------------------------------
51079           -- 4262811a Switch Sign
51080           ---------------------------------------------------------------------------------------------------
51081           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
51082           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
51083                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51084           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
51085                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51086           -- 5132302
51087           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
51088                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51089 
51090       END IF;
51091 
51092       -- 4955764
51093       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
51094       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
51095 
51096 
51097       XLA_AE_LINES_PKG.ValidateCurrentLine;
51098       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
51099 
51100       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
51101                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
51102                ,p_balance_type_code => l_balance_type_code);
51103 
51104    END IF;
51105 
51106    -----------------------------------------------------------------------------------------
51107    -- 4262811 Multiperiod Accounting
51108    -----------------------------------------------------------------------------------------
51109      -- No MPA option is assigned.
51110 
51111 
51112 END IF;
51113 END IF;
51114 --
51115 
51116 --
51117 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
51118    trace
51119       (p_msg      => 'END of AcctLineType_225'
51120       ,p_level    => C_LEVEL_PROCEDURE
51121       ,p_module   => l_log_module);
51122 END IF;
51123 --
51124 EXCEPTION
51125   WHEN xla_exceptions_pkg.application_exception THEN
51126       RAISE;
51127   WHEN OTHERS THEN
51128        xla_exceptions_pkg.raise_message
51129            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_225');
51130 END AcctLineType_225;
51131 --
51132 
51133 ---------------------------------------
51134 --
51135 -- PRIVATE FUNCTION
51136 --         AcctLineType_226
51137 --
51141  ,p_event_id              IN NUMBER
51138 ---------------------------------------
51139 PROCEDURE AcctLineType_226 (
51140   p_application_id        IN NUMBER
51142  ,p_calculate_acctd_flag  IN VARCHAR2
51143  ,p_calculate_g_l_flag    IN VARCHAR2
51144  ,p_actual_flag           IN OUT VARCHAR2
51145  ,p_balance_type_code     OUT VARCHAR2
51146  ,p_gain_or_loss_ref      OUT VARCHAR2
51147  
51151  , p_source_3            IN NUMBER
51148 --Period Close Date
51149  , p_source_1            IN DATE
51150 --Generated Code Combination Identifier
51152 --Proceeds Of Sale Loss Account
51153  , p_source_25            IN VARCHAR2
51154 --Expense Account Code Combination Identifier
51155  , p_source_29            IN NUMBER
51156 --Default Code Combination Identifier
51157  , p_source_30            IN NUMBER
51158 --Adjustment Type
51159  , p_source_35            IN VARCHAR2
51160 --Transaction Header Identifier
51161  , p_source_36            IN NUMBER
51162 --Adjustment Line Identifier
51163  , p_source_37            IN NUMBER
51164 --Distribution Type Code
51165  , p_source_38            IN VARCHAR2
51166 --Entered Amount
51167  , p_source_39            IN NUMBER
51168 --Currency Code
51169  , p_source_40            IN VARCHAR2
51170 --Gain Loss Amount
51171  , p_source_41            IN NUMBER
51172 )
51173 IS
51174 
51175 l_component_type              VARCHAR2(80);
51176 l_component_code              VARCHAR2(30);
51177 l_component_type_code         VARCHAR2(1);
51178 l_component_appl_id           INTEGER;
51179 l_amb_context_code            VARCHAR2(30);
51183 l_event_type_code             VARCHAR2(30);
51180 l_entity_code                 VARCHAR2(30);
51181 l_event_class_code            VARCHAR2(30);
51182 l_ae_header_id                NUMBER;
51184 l_line_definition_code        VARCHAR2(30);
51185 l_line_definition_owner_code  VARCHAR2(1);
51186 --
51187 -- adr variables
51188 l_segment                     VARCHAR2(30);
51189 l_ccid                        NUMBER;
51190 l_adr_transaction_coa_id      NUMBER;
51191 l_adr_accounting_coa_id       NUMBER;
51192 l_adr_flexfield_segment_code  VARCHAR2(30);
51193 l_adr_flex_value_set_id       NUMBER;
51194 l_adr_value_type_code         VARCHAR2(30);
51195 l_adr_value_combination_id    NUMBER;
51196 l_adr_value_segment_code      VARCHAR2(30);
51197 
51198 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
51199 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
51200 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
51201 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
51202 
51203 -- 4262811 Variables ------------------------------------------------------------------------------------------
51204 l_entered_amt_idx             NUMBER;
51205 l_accted_amt_idx              NUMBER;
51206 l_acc_rev_flag                VARCHAR2(1);
51207 l_accrual_line_num            NUMBER;
51208 l_tmp_amt                     NUMBER;
51209 l_acc_rev_natural_side_code   VARCHAR2(1);
51210 
51211 l_num_entries                 NUMBER;
51212 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
51213 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
51214 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
51215 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
51216 l_recog_line_1                NUMBER;
51217 l_recog_line_2                NUMBER;
51218 
51219 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
51220 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
51221 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
51222 
51223 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
51224 
51225 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
51226 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
51227 
51228 ---------------------------------------------------------------------------------------------------------------
51229 
51230 
51231 --
51232 -- bulk performance
51233 --
51234 l_balance_type_code           VARCHAR2(1);
51235 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
51236 l_log_module                  VARCHAR2(240);
51237 
51238 --
51239 -- Upgrade strategy
51240 --
51241 l_actual_upg_option           VARCHAR2(1);
51242 l_enc_upg_option           VARCHAR2(1);
51243 
51244 --
51245 BEGIN
51246 --
51247 IF g_log_enabled THEN
51248       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_226';
51249 END IF;
51250 --
51251 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
51252 
51253       trace
51254          (p_msg      => 'BEGIN of AcctLineType_226'
51255          ,p_level    => C_LEVEL_PROCEDURE
51256          ,p_module   => l_log_module);
51257 
51258 END IF;
51259 --
51260 l_component_type             := 'AMB_JLT';
51261 l_component_code             := 'FA_CIP_PROC_OF_SALE_LOSS';
51262 l_component_type_code        := 'S';
51263 l_component_appl_id          :=  140;
51264 l_amb_context_code           := 'DEFAULT';
51265 l_entity_code                := 'TRANSACTIONS';
51266 l_event_class_code           := 'CIP_RETIREMENTS';
51267 l_event_type_code            := 'CIP_REINSTATEMENTS';
51268 l_line_definition_owner_code := 'S';
51269 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
51270 --
51271 l_balance_type_code          := 'A';
51272 l_segment                     := NULL;
51273 l_ccid                        := NULL;
51274 l_adr_transaction_coa_id      := NULL;
51275 l_adr_accounting_coa_id       := NULL;
51276 l_adr_flexfield_segment_code  := NULL;
51277 l_adr_flex_value_set_id       := NULL;
51278 l_adr_value_type_code         := NULL;
51279 l_adr_value_combination_id    := NULL;
51280 l_adr_value_segment_code      := NULL;
51281 
51282 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
51283 l_bflow_class_code           := '';    -- 4219869 Business Flow
51284 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
51285 l_budgetary_control_flag     := 'N';
51286 
51287 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
51288 l_bflow_applied_to_amt       := NULL; -- 5132302
51289 l_entered_amt_idx            := NULL;          -- 4262811
51290 l_accted_amt_idx             := NULL;          -- 4262811
51291 l_acc_rev_flag               := NULL;          -- 4262811
51292 l_accrual_line_num           := NULL;          -- 4262811
51293 l_tmp_amt                    := NULL;          -- 4262811
51294 --
51295  
51296 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
51297     l_balance_type_code <> 'B' THEN
51298 IF NVL(p_source_35,'
51299 ') =  'PROCEEDS' AND 
51300 p_source_41 <  0
51301  THEN 
51302 
51303    --
51304    XLA_AE_LINES_PKG.SetNewLine;
51305 
51306    p_balance_type_code          := l_balance_type_code;
51307    -- set the flag so later we will know whether the gain loss line needs to be created
51308    
51309    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
51310      p_actual_flag :='A';
51311    END IF;
51312 
51316    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
51313    --
51314    -- bulk performance
51315    --
51317                                       p_header_num   => 0); -- 4262811
51318    --
51319    -- set accounting line options
51320    --
51321    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
51322            p_natural_side_code          => 'C'
51323          , p_gain_or_loss_flag          => 'N'
51324          , p_gl_transfer_mode_code      => 'S'
51325          , p_acct_entry_type_code       => 'A'
51326          , p_switch_side_flag           => 'Y'
51327          , p_merge_duplicate_code       => 'N'
51328          );
51329    --
51330    l_acc_rev_natural_side_code := 'D';  -- 4262811
51331    -- 
51332    --
51333    -- set accounting line type info
51334    --
51335    xla_ae_lines_pkg.SetAcctLineType
51336       (p_component_type             => l_component_type
51337       ,p_event_type_code            => l_event_type_code
51338       ,p_line_definition_owner_code => l_line_definition_owner_code
51339       ,p_line_definition_code       => l_line_definition_code
51340       ,p_accounting_line_code       => l_component_code
51341       ,p_accounting_line_type_code  => l_component_type_code
51342       ,p_accounting_line_appl_id    => l_component_appl_id
51343       ,p_amb_context_code           => l_amb_context_code
51344       ,p_entity_code                => l_entity_code
51345       ,p_event_class_code           => l_event_class_code);
51346    --
51347    -- set accounting class
51348    --
51349    xla_ae_lines_pkg.SetAcctClass(
51350            p_accounting_class_code  => 'ASSET'
51351          , p_ae_header_id           => l_ae_header_id
51352          );
51353 
51354    --
51355    -- set rounding class
51356    --
51357    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
51358                       'ASSET';
51359 
51360    --
51361    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
51362    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
51363    --
51364    -- bulk performance
51365    --
51366    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
51367 
51368    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
51369       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
51370 
51371    -- 4955764
51372    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
51373       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
51374 
51375    -- 4458381 Public Sector Enh
51376    
51377    --
51378    -- set accounting attributes for the line type
51379    --
51380    l_entered_amt_idx := 4;
51381    l_accted_amt_idx  := 6;
51382    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
51383    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
51384    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
51385    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
51386    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
51387    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
51388    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
51389    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
51390    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
51391    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
51392    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
51393    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
51394    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
51395 
51396    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
51397    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
51398 
51399    ---------------------------------------------------------------------------------------------------------------
51403 
51400    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
51401    ---------------------------------------------------------------------------------------------------------------
51402    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
51404    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51405    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51406 
51407    IF xla_accounting_cache_pkg.GetValueChar
51408          (p_source_code         => 'LEDGER_CATEGORY_CODE'
51409          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
51410    AND l_bflow_method_code = 'PRIOR_ENTRY'
51411 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
51412    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
51413          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
51414        )
51415    THEN
51416          xla_ae_lines_pkg.BflowUpgEntry
51417            (p_business_method_code    => l_bflow_method_code
51418            ,p_business_class_code     => l_bflow_class_code
51419            ,p_balance_type            => l_balance_type_code);
51420    ELSE
51421       NULL;
51422 -- No business flow processing for business flow method of NONE.
51423    END IF;
51424 
51425    --
51426    -- call analytical criteria
51427    --
51428    
51429    --
51430    -- call description
51431    --
51432    
51433 xla_ae_lines_pkg.SetLineDescription(
51434    p_ae_header_id => l_ae_header_id
51435   ,p_description  => Description_35 (
51436      p_application_id         => p_application_id
51437    , p_ae_header_id           => l_ae_header_id 
51438 , p_source_1 => p_source_1
51439    )
51440 );
51441 
51442 
51443    --
51444    -- call ADRs
51445    -- Bug 4922099
51446    --
51447    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
51448         (NVL(l_actual_upg_option, 'N') = 'O') OR
51449         (NVL(l_enc_upg_option, 'N') = 'O')
51450       )
51451    THEN
51452    NULL;
51453    --
51454    --
51455    
51456   l_ccid := AcctDerRule_173(
51457            p_application_id           => p_application_id
51458          , p_ae_header_id             => l_ae_header_id 
51459 , p_source_3 => p_source_3
51460 , p_source_30 => p_source_30
51461          , x_transaction_coa_id       => l_adr_transaction_coa_id
51462          , x_accounting_coa_id        => l_adr_accounting_coa_id
51463          , x_value_type_code          => l_adr_value_type_code
51467    xla_ae_lines_pkg.set_ccid(
51464          , p_side                     => 'NA'
51465    );
51466 
51468     p_code_combination_id          => l_ccid
51469   , p_value_type_code              => l_adr_value_type_code
51470   , p_transaction_coa_id           => l_adr_transaction_coa_id
51471   , p_accounting_coa_id            => l_adr_accounting_coa_id
51472   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
51473   , p_adr_type_code                => 'S'
51474   , p_component_type               => l_component_type
51475   , p_component_code               => l_component_code
51476   , p_component_type_code          => l_component_type_code
51477   , p_component_appl_id            => l_component_appl_id
51478   , p_amb_context_code             => l_amb_context_code
51479   , p_side                         => 'NA'
51480   );
51481 
51482 
51483    l_segment := AcctDerRule_168(
51484            p_application_id           => p_application_id
51485          , p_ae_header_id             => l_ae_header_id 
51486 , p_source_3 => p_source_3
51487 , p_source_29 => p_source_29
51488          , x_transaction_coa_id       => l_adr_transaction_coa_id
51489          , x_accounting_coa_id        => l_adr_accounting_coa_id
51490          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
51491          , x_flex_value_set_id        => l_adr_flex_value_set_id
51492          , x_value_type_code          => l_adr_value_type_code
51493          , x_value_combination_id     => l_adr_value_combination_id
51494          , x_value_segment_code       => l_adr_value_segment_code
51495          , p_side                     => 'NA'
51496          , p_override_seg_flag        => 'Y'
51497    );
51498 
51499    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
51500 
51501       xla_ae_lines_pkg.set_segment(
51502           p_to_segment_code         => 'GL_BALANCING'
51503         , p_segment_value           => l_segment
51504         , p_from_segment_code       => l_adr_value_segment_code
51505         , p_from_combination_id     => l_adr_value_combination_id
51506         , p_value_type_code         => l_adr_value_type_code
51507         , p_transaction_coa_id      => l_adr_transaction_coa_id
51508         , p_accounting_coa_id       => l_adr_accounting_coa_id
51509         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
51513         , p_component_type          => l_component_type
51510         , p_flex_value_set_id       => l_adr_flex_value_set_id
51511         , p_adr_code                => 'FA_EXPENSE_ACCT'
51512         , p_adr_type_code           => 'S'
51514         , p_component_code          => l_component_code
51515         , p_component_type_code     => l_component_type_code
51516         , p_component_appl_id       => l_component_appl_id
51517         , p_amb_context_code        => l_amb_context_code
51518         , p_entity_code             => 'TRANSACTIONS'
51519         , p_event_class_code        => 'CIP_RETIREMENTS'
51520         , p_side                    => 'NA'
51521         );
51522 
51523   END IF;
51524 
51525    l_segment := AcctDerRule_163(
51526            p_application_id           => p_application_id
51527          , p_ae_header_id             => l_ae_header_id 
51528 , p_source_3 => p_source_3
51529 , p_source_25 => p_source_25
51530          , x_transaction_coa_id       => l_adr_transaction_coa_id
51531          , x_accounting_coa_id        => l_adr_accounting_coa_id
51532          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
51533          , x_flex_value_set_id        => l_adr_flex_value_set_id
51534          , x_value_type_code          => l_adr_value_type_code
51535          , x_value_combination_id     => l_adr_value_combination_id
51536          , x_value_segment_code       => l_adr_value_segment_code
51537          , p_side                     => 'NA'
51538          , p_override_seg_flag        => 'Y'
51539    );
51540 
51541    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
51542 
51543       xla_ae_lines_pkg.set_segment(
51544           p_to_segment_code         => 'GL_ACCOUNT'
51545         , p_segment_value           => l_segment
51546         , p_from_segment_code       => l_adr_value_segment_code
51547         , p_from_combination_id     => l_adr_value_combination_id
51548         , p_value_type_code         => l_adr_value_type_code
51549         , p_transaction_coa_id      => l_adr_transaction_coa_id
51550         , p_accounting_coa_id       => l_adr_accounting_coa_id
51551         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
51552         , p_flex_value_set_id       => l_adr_flex_value_set_id
51553         , p_adr_code                => 'FA_PROC_OF_SALE_LOSS_SEGMENT'
51554         , p_adr_type_code           => 'S'
51555         , p_component_type          => l_component_type
51556         , p_component_code          => l_component_code
51557         , p_component_type_code     => l_component_type_code
51558         , p_component_appl_id       => l_component_appl_id
51559         , p_amb_context_code        => l_amb_context_code
51560         , p_entity_code             => 'TRANSACTIONS'
51561         , p_event_class_code        => 'CIP_RETIREMENTS'
51562         , p_side                    => 'NA'
51563         );
51564 
51565   END IF;
51566 
51567    --
51568    --
51569    END IF;
51570    --
51571    -- Bug 4922099
51572    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
51573           (NVL(l_enc_upg_option, 'N') = 'O')
51574         ) AND
51575         (l_bflow_method_code = 'PRIOR_ENTRY')
51576       )
51577    THEN
51578       IF
51579       --
51580       1 = 2
51581       --
51582       THEN
51583       xla_accounting_err_pkg.build_message
51584                                     (p_appli_s_name            => 'XLA'
51585                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
51586                                     ,p_token_1                 => 'LINE_NUMBER'
51587                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
51588                                     ,p_token_2                 => 'LINE_TYPE_NAME'
51589                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
51590                                                                              l_component_type
51591                                                                             ,l_component_code
51592                                                                             ,l_component_type_code
51593                                                                             ,l_component_appl_id
51594                                                                             ,l_amb_context_code
51595                                                                             ,l_entity_code
51596                                                                             ,l_event_class_code
51597                                                                            )
51598                                     ,p_token_3                 => 'OWNER'
51599                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
51600                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
51601                                                                           ,p_lookup_code    => l_component_type_code
51602                                                                          )
51603                                     ,p_token_4                 => 'PRODUCT_NAME'
51604                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
51605                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
51609                                        );
51606                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
51607                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
51608                                     ,p_ae_header_id            =>  NULL
51610 
51611         IF (C_LEVEL_ERROR>= g_log_level) THEN
51612                  trace
51613                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
51614                       ,p_level    => C_LEVEL_ERROR
51615                       ,p_module   => l_log_module);
51616         END IF;
51617       END IF;
51618    END IF;
51619    --
51620    --
51621    ------------------------------------------------------------------------------------------------
51622    -- 4219869 Business Flow
51623    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
51624    -- Prior Entry.  Currently, the following code is always generated.
51625    ------------------------------------------------------------------------------------------------
51626    XLA_AE_LINES_PKG.ValidateCurrentLine;
51627 
51628    ------------------------------------------------------------------------------------
51629    -- 4219869 Business Flow
51630    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
51631    ------------------------------------------------------------------------------------
51632    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
51633 
51634    ----------------------------------------------------------------------------------
51635    -- 4219869 Business Flow
51636    -- Update journal entry status -- Need to generate this within IF <condition>
51637    ----------------------------------------------------------------------------------
51638    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
51639          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
51640          ,p_balance_type_code => l_balance_type_code
51641          );
51642 
51643    -------------------------------------------------------------------------------------------
51644    -- 4262811 - Generate the Accrual Reversal lines
51645    -------------------------------------------------------------------------------------------
51646    BEGIN
51647       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
51648                               (g_array_event(p_event_id).array_value_num('header_index'));
51649       IF l_acc_rev_flag IS NULL THEN
51650          l_acc_rev_flag := 'N';
51651       END IF;
51652    EXCEPTION
51653       WHEN OTHERS THEN
51654          l_acc_rev_flag := 'N';
51655    END;
51656    --
51657    IF (l_acc_rev_flag = 'Y') THEN
51658 
51659        -- 4645092  ------------------------------------------------------------------------------
51660        -- To allow MPA report to determine if it should generate report process
51661        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
51662        ------------------------------------------------------------------------------------------
51663 
51664        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
51665        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
51666    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
51667    -- call ADRs
51668    -- Bug 4922099
51669    --
51670    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
51671         (NVL(l_actual_upg_option, 'N') = 'O') OR
51672         (NVL(l_enc_upg_option, 'N') = 'O')
51673       )
51674    THEN
51675    NULL;
51676    --
51677    --
51678    
51679   l_ccid := AcctDerRule_173(
51680            p_application_id           => p_application_id
51681          , p_ae_header_id             => l_ae_header_id 
51682 , p_source_3 => p_source_3
51683 , p_source_30 => p_source_30
51684          , x_transaction_coa_id       => l_adr_transaction_coa_id
51685          , x_accounting_coa_id        => l_adr_accounting_coa_id
51686          , x_value_type_code          => l_adr_value_type_code
51687          , p_side                     => 'NA'
51688    );
51689 
51690    xla_ae_lines_pkg.set_ccid(
51691     p_code_combination_id          => l_ccid
51692   , p_value_type_code              => l_adr_value_type_code
51693   , p_transaction_coa_id           => l_adr_transaction_coa_id
51694   , p_accounting_coa_id            => l_adr_accounting_coa_id
51695   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
51696   , p_adr_type_code                => 'S'
51697   , p_component_type               => l_component_type
51698   , p_component_code               => l_component_code
51699   , p_component_type_code          => l_component_type_code
51700   , p_component_appl_id            => l_component_appl_id
51701   , p_amb_context_code             => l_amb_context_code
51702   , p_side                         => 'NA'
51703   );
51704 
51705 
51706    l_segment := AcctDerRule_168(
51707            p_application_id           => p_application_id
51708          , p_ae_header_id             => l_ae_header_id 
51709 , p_source_3 => p_source_3
51710 , p_source_29 => p_source_29
51711          , x_transaction_coa_id       => l_adr_transaction_coa_id
51712          , x_accounting_coa_id        => l_adr_accounting_coa_id
51713          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
51714          , x_flex_value_set_id        => l_adr_flex_value_set_id
51715          , x_value_type_code          => l_adr_value_type_code
51716          , x_value_combination_id     => l_adr_value_combination_id
51717          , x_value_segment_code       => l_adr_value_segment_code
51718          , p_side                     => 'NA'
51719          , p_override_seg_flag        => 'Y'
51720    );
51721 
51722    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
51723 
51724       xla_ae_lines_pkg.set_segment(
51728         , p_from_combination_id     => l_adr_value_combination_id
51725           p_to_segment_code         => 'GL_BALANCING'
51726         , p_segment_value           => l_segment
51727         , p_from_segment_code       => l_adr_value_segment_code
51729         , p_value_type_code         => l_adr_value_type_code
51730         , p_transaction_coa_id      => l_adr_transaction_coa_id
51731         , p_accounting_coa_id       => l_adr_accounting_coa_id
51732         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
51733         , p_flex_value_set_id       => l_adr_flex_value_set_id
51734         , p_adr_code                => 'FA_EXPENSE_ACCT'
51735         , p_adr_type_code           => 'S'
51736         , p_component_type          => l_component_type
51737         , p_component_code          => l_component_code
51738         , p_component_type_code     => l_component_type_code
51739         , p_component_appl_id       => l_component_appl_id
51740         , p_amb_context_code        => l_amb_context_code
51741         , p_entity_code             => 'TRANSACTIONS'
51742         , p_event_class_code        => 'CIP_RETIREMENTS'
51743         , p_side                    => 'NA'
51744         );
51745 
51746   END IF;
51747 
51748    l_segment := AcctDerRule_163(
51749            p_application_id           => p_application_id
51750          , p_ae_header_id             => l_ae_header_id 
51751 , p_source_3 => p_source_3
51752 , p_source_25 => p_source_25
51753          , x_transaction_coa_id       => l_adr_transaction_coa_id
51754          , x_accounting_coa_id        => l_adr_accounting_coa_id
51755          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
51756          , x_flex_value_set_id        => l_adr_flex_value_set_id
51757          , x_value_type_code          => l_adr_value_type_code
51758          , x_value_combination_id     => l_adr_value_combination_id
51759          , x_value_segment_code       => l_adr_value_segment_code
51760          , p_side                     => 'NA'
51761          , p_override_seg_flag        => 'Y'
51762    );
51763 
51764    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
51765 
51766       xla_ae_lines_pkg.set_segment(
51767           p_to_segment_code         => 'GL_ACCOUNT'
51768         , p_segment_value           => l_segment
51769         , p_from_segment_code       => l_adr_value_segment_code
51770         , p_from_combination_id     => l_adr_value_combination_id
51771         , p_value_type_code         => l_adr_value_type_code
51772         , p_transaction_coa_id      => l_adr_transaction_coa_id
51773         , p_accounting_coa_id       => l_adr_accounting_coa_id
51774         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
51775         , p_flex_value_set_id       => l_adr_flex_value_set_id
51776         , p_adr_code                => 'FA_PROC_OF_SALE_LOSS_SEGMENT'
51777         , p_adr_type_code           => 'S'
51778         , p_component_type          => l_component_type
51779         , p_component_code          => l_component_code
51780         , p_component_type_code     => l_component_type_code
51781         , p_component_appl_id       => l_component_appl_id
51782         , p_amb_context_code        => l_amb_context_code
51783         , p_entity_code             => 'TRANSACTIONS'
51784         , p_event_class_code        => 'CIP_RETIREMENTS'
51785         , p_side                    => 'NA'
51786         );
51787 
51788   END IF;
51789 
51790    --
51791    --
51792    END IF;
51793 
51794        --
51795        -- Update the line information that should be overwritten
51796        --
51797        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
51798                                          p_header_num   => 1);
51799        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
51800 
51801        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
51802 
51803        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
51804           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
51805        END IF;
51806 
51807       --
51808       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
51809       --
51810       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
51811           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
51812       ELSE
51813           ---------------------------------------------------------------------------------------------------
51814           -- 4262811a Switch Sign
51815           ---------------------------------------------------------------------------------------------------
51816           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
51817           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
51818                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51819           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
51820                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51821           -- 5132302
51822           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
51823                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51824 
51825       END IF;
51826 
51827       -- 4955764
51828       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
51829       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
51830 
51831 
51832       XLA_AE_LINES_PKG.ValidateCurrentLine;
51833       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
51834 
51835       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
51839    END IF;
51836                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
51837                ,p_balance_type_code => l_balance_type_code);
51838 
51840 
51841    -----------------------------------------------------------------------------------------
51842    -- 4262811 Multiperiod Accounting
51843    -----------------------------------------------------------------------------------------
51844      -- No MPA option is assigned.
51845 
51846 
51847 END IF;
51848 END IF;
51849 --
51850 
51851 --
51852 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
51853    trace
51854       (p_msg      => 'END of AcctLineType_226'
51855       ,p_level    => C_LEVEL_PROCEDURE
51856       ,p_module   => l_log_module);
51857 END IF;
51858 --
51859 EXCEPTION
51860   WHEN xla_exceptions_pkg.application_exception THEN
51861       RAISE;
51862   WHEN OTHERS THEN
51863        xla_exceptions_pkg.raise_message
51864            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_226');
51865 END AcctLineType_226;
51866 --
51867 
51868 ---------------------------------------
51869 --
51870 -- PRIVATE FUNCTION
51871 --         AcctLineType_227
51872 --
51873 ---------------------------------------
51874 PROCEDURE AcctLineType_227 (
51875   p_application_id        IN NUMBER
51876  ,p_event_id              IN NUMBER
51877  ,p_calculate_acctd_flag  IN VARCHAR2
51878  ,p_calculate_g_l_flag    IN VARCHAR2
51879  ,p_actual_flag           IN OUT VARCHAR2
51880  ,p_balance_type_code     OUT VARCHAR2
51881  ,p_gain_or_loss_ref      OUT VARCHAR2
51882  
51883 --Period Close Date
51884  , p_source_1            IN DATE
51885 --Generated Code Combination Identifier
51886  , p_source_3            IN NUMBER
51887 --CIP Cost Account
51888  , p_source_7            IN VARCHAR2
51889 --Expense Account Code Combination Identifier
51890  , p_source_29            IN NUMBER
51891 --Default Code Combination Identifier
51892  , p_source_30            IN NUMBER
51893 --Adjustment Type
51894  , p_source_35            IN VARCHAR2
51895 --Transaction Header Identifier
51896  , p_source_36            IN NUMBER
51897 --Adjustment Line Identifier
51898  , p_source_37            IN NUMBER
51899 --Distribution Type Code
51900  , p_source_38            IN VARCHAR2
51901 --Entered Amount
51902  , p_source_39            IN NUMBER
51903 --Currency Code
51904  , p_source_40            IN VARCHAR2
51905 --Source Destination Code
51906  , p_source_42            IN VARCHAR2
51907 )
51908 IS
51909 
51910 l_component_type              VARCHAR2(80);
51911 l_component_code              VARCHAR2(30);
51912 l_component_type_code         VARCHAR2(1);
51913 l_component_appl_id           INTEGER;
51914 l_amb_context_code            VARCHAR2(30);
51915 l_entity_code                 VARCHAR2(30);
51916 l_event_class_code            VARCHAR2(30);
51917 l_ae_header_id                NUMBER;
51918 l_event_type_code             VARCHAR2(30);
51919 l_line_definition_code        VARCHAR2(30);
51920 l_line_definition_owner_code  VARCHAR2(1);
51921 --
51922 -- adr variables
51923 l_segment                     VARCHAR2(30);
51924 l_ccid                        NUMBER;
51925 l_adr_transaction_coa_id      NUMBER;
51926 l_adr_accounting_coa_id       NUMBER;
51927 l_adr_flexfield_segment_code  VARCHAR2(30);
51928 l_adr_flex_value_set_id       NUMBER;
51929 l_adr_value_type_code         VARCHAR2(30);
51930 l_adr_value_combination_id    NUMBER;
51931 l_adr_value_segment_code      VARCHAR2(30);
51932 
51933 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
51934 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
51935 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
51936 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
51937 
51938 -- 4262811 Variables ------------------------------------------------------------------------------------------
51939 l_entered_amt_idx             NUMBER;
51940 l_accted_amt_idx              NUMBER;
51941 l_acc_rev_flag                VARCHAR2(1);
51942 l_accrual_line_num            NUMBER;
51943 l_tmp_amt                     NUMBER;
51944 l_acc_rev_natural_side_code   VARCHAR2(1);
51945 
51946 l_num_entries                 NUMBER;
51947 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
51948 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
51949 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
51950 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
51951 l_recog_line_1                NUMBER;
51952 l_recog_line_2                NUMBER;
51953 
51954 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
51955 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
51956 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
51957 
51958 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
51959 
51960 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
51961 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
51962 
51963 ---------------------------------------------------------------------------------------------------------------
51964 
51965 
51966 --
51967 -- bulk performance
51968 --
51969 l_balance_type_code           VARCHAR2(1);
51970 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
51971 l_log_module                  VARCHAR2(240);
51972 
51973 --
51974 -- Upgrade strategy
51975 --
51976 l_actual_upg_option           VARCHAR2(1);
51977 l_enc_upg_option           VARCHAR2(1);
51978 
51979 --
51980 BEGIN
51981 --
51982 IF g_log_enabled THEN
51986 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
51983       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_227';
51984 END IF;
51985 --
51987 
51988       trace
51989          (p_msg      => 'BEGIN of AcctLineType_227'
51990          ,p_level    => C_LEVEL_PROCEDURE
51991          ,p_module   => l_log_module);
51992 
51993 END IF;
51994 --
51995 l_component_type             := 'AMB_JLT';
51996 l_component_code             := 'FA_CIP_RECLASS_DEST_COST';
51997 l_component_type_code        := 'S';
51998 l_component_appl_id          :=  140;
51999 l_amb_context_code           := 'DEFAULT';
52000 l_entity_code                := 'TRANSACTIONS';
52001 l_event_class_code           := 'CIP_CATEGORY_RECLASS';
52002 l_event_type_code            := 'CIP_CATEGORY_RECLASS_ALL';
52003 l_line_definition_owner_code := 'S';
52004 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_CA7';
52005 --
52006 l_balance_type_code          := 'A';
52007 l_segment                     := NULL;
52008 l_ccid                        := NULL;
52009 l_adr_transaction_coa_id      := NULL;
52010 l_adr_accounting_coa_id       := NULL;
52011 l_adr_flexfield_segment_code  := NULL;
52012 l_adr_flex_value_set_id       := NULL;
52013 l_adr_value_type_code         := NULL;
52014 l_adr_value_combination_id    := NULL;
52015 l_adr_value_segment_code      := NULL;
52016 
52017 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
52018 l_bflow_class_code           := '';    -- 4219869 Business Flow
52019 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
52020 l_budgetary_control_flag     := 'N';
52021 
52022 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
52023 l_bflow_applied_to_amt       := NULL; -- 5132302
52024 l_entered_amt_idx            := NULL;          -- 4262811
52025 l_accted_amt_idx             := NULL;          -- 4262811
52026 l_acc_rev_flag               := NULL;          -- 4262811
52027 l_accrual_line_num           := NULL;          -- 4262811
52028 l_tmp_amt                    := NULL;          -- 4262811
52029 --
52030  
52031 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
52032     l_balance_type_code <> 'B' THEN
52033 IF NVL(p_source_35,'
52034 ') =  'CIP COST' AND 
52035 NVL(p_source_42,'
52036 ') =  'DEST'
52037  THEN 
52038 
52039    --
52040    XLA_AE_LINES_PKG.SetNewLine;
52041 
52042    p_balance_type_code          := l_balance_type_code;
52043    -- set the flag so later we will know whether the gain loss line needs to be created
52044    
52045    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
52046      p_actual_flag :='A';
52047    END IF;
52048 
52049    --
52050    -- bulk performance
52051    --
52052    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
52053                                       p_header_num   => 0); -- 4262811
52054    --
52055    -- set accounting line options
52056    --
52057    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
52058            p_natural_side_code          => 'D'
52059          , p_gain_or_loss_flag          => 'N'
52060          , p_gl_transfer_mode_code      => 'S'
52061          , p_acct_entry_type_code       => 'A'
52062          , p_switch_side_flag           => 'Y'
52063          , p_merge_duplicate_code       => 'N'
52064          );
52065    --
52066    l_acc_rev_natural_side_code := 'C';  -- 4262811
52067    -- 
52068    --
52069    -- set accounting line type info
52070    --
52071    xla_ae_lines_pkg.SetAcctLineType
52072       (p_component_type             => l_component_type
52073       ,p_event_type_code            => l_event_type_code
52074       ,p_line_definition_owner_code => l_line_definition_owner_code
52075       ,p_line_definition_code       => l_line_definition_code
52076       ,p_accounting_line_code       => l_component_code
52077       ,p_accounting_line_type_code  => l_component_type_code
52078       ,p_accounting_line_appl_id    => l_component_appl_id
52079       ,p_amb_context_code           => l_amb_context_code
52080       ,p_entity_code                => l_entity_code
52081       ,p_event_class_code           => l_event_class_code);
52082    --
52083    -- set accounting class
52084    --
52085    xla_ae_lines_pkg.SetAcctClass(
52086            p_accounting_class_code  => 'ASSET'
52087          , p_ae_header_id           => l_ae_header_id
52088          );
52089 
52090    --
52091    -- set rounding class
52092    --
52093    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
52094                       'ASSET';
52095 
52096    --
52097    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
52098    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
52099    --
52100    -- bulk performance
52101    --
52102    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
52103 
52104    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
52105       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
52106 
52107    -- 4955764
52108    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
52109       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
52110 
52111    -- 4458381 Public Sector Enh
52112    
52113    --
52114    -- set accounting attributes for the line type
52115    --
52116    l_entered_amt_idx := 4;
52117    l_accted_amt_idx  := 6;
52118    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
52119    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
52120    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
52124    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
52121    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
52122    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
52123    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
52125    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
52126    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
52127    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
52128    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
52129    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
52130    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
52131 
52132    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
52133    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
52134 
52135    ---------------------------------------------------------------------------------------------------------------
52136    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
52137    ---------------------------------------------------------------------------------------------------------------
52138    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
52139 
52140    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
52141    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
52142 
52143    IF xla_accounting_cache_pkg.GetValueChar
52144          (p_source_code         => 'LEDGER_CATEGORY_CODE'
52145          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
52146    AND l_bflow_method_code = 'PRIOR_ENTRY'
52147 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
52148    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
52149          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
52150        )
52151    THEN
52152          xla_ae_lines_pkg.BflowUpgEntry
52153            (p_business_method_code    => l_bflow_method_code
52154            ,p_business_class_code     => l_bflow_class_code
52155            ,p_balance_type            => l_balance_type_code);
52156    ELSE
52157       NULL;
52158 -- No business flow processing for business flow method of NONE.
52159    END IF;
52160 
52161    --
52162    -- call analytical criteria
52163    --
52164    
52165    --
52166    -- call description
52167    --
52168    
52169 xla_ae_lines_pkg.SetLineDescription(
52170    p_ae_header_id => l_ae_header_id
52171   ,p_description  => Description_29 (
52172      p_application_id         => p_application_id
52173    , p_ae_header_id           => l_ae_header_id 
52174 , p_source_1 => p_source_1
52175    )
52176 );
52177 
52178 
52179    --
52180    -- call ADRs
52181    -- Bug 4922099
52182    --
52183    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
52184         (NVL(l_actual_upg_option, 'N') = 'O') OR
52185         (NVL(l_enc_upg_option, 'N') = 'O')
52186       )
52187    THEN
52188    NULL;
52189    --
52190    --
52191    
52192   l_ccid := AcctDerRule_173(
52193            p_application_id           => p_application_id
52194          , p_ae_header_id             => l_ae_header_id 
52195 , p_source_3 => p_source_3
52196 , p_source_30 => p_source_30
52197          , x_transaction_coa_id       => l_adr_transaction_coa_id
52198          , x_accounting_coa_id        => l_adr_accounting_coa_id
52199          , x_value_type_code          => l_adr_value_type_code
52200          , p_side                     => 'NA'
52201    );
52202 
52203    xla_ae_lines_pkg.set_ccid(
52204     p_code_combination_id          => l_ccid
52205   , p_value_type_code              => l_adr_value_type_code
52206   , p_transaction_coa_id           => l_adr_transaction_coa_id
52207   , p_accounting_coa_id            => l_adr_accounting_coa_id
52208   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
52209   , p_adr_type_code                => 'S'
52210   , p_component_type               => l_component_type
52211   , p_component_code               => l_component_code
52212   , p_component_type_code          => l_component_type_code
52213   , p_component_appl_id            => l_component_appl_id
52214   , p_amb_context_code             => l_amb_context_code
52215   , p_side                         => 'NA'
52216   );
52217 
52218 
52219    l_segment := AcctDerRule_146(
52220            p_application_id           => p_application_id
52221          , p_ae_header_id             => l_ae_header_id 
52222 , p_source_3 => p_source_3
52223 , p_source_7 => p_source_7
52224          , x_transaction_coa_id       => l_adr_transaction_coa_id
52225          , x_accounting_coa_id        => l_adr_accounting_coa_id
52226          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
52227          , x_flex_value_set_id        => l_adr_flex_value_set_id
52228          , x_value_type_code          => l_adr_value_type_code
52229          , x_value_combination_id     => l_adr_value_combination_id
52230          , x_value_segment_code       => l_adr_value_segment_code
52231          , p_side                     => 'NA'
52232          , p_override_seg_flag        => 'Y'
52233    );
52234 
52235    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
52236 
52237       xla_ae_lines_pkg.set_segment(
52238           p_to_segment_code         => 'GL_ACCOUNT'
52239         , p_segment_value           => l_segment
52240         , p_from_segment_code       => l_adr_value_segment_code
52241         , p_from_combination_id     => l_adr_value_combination_id
52242         , p_value_type_code         => l_adr_value_type_code
52243         , p_transaction_coa_id      => l_adr_transaction_coa_id
52244         , p_accounting_coa_id       => l_adr_accounting_coa_id
52248         , p_adr_type_code           => 'S'
52245         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
52246         , p_flex_value_set_id       => l_adr_flex_value_set_id
52247         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
52249         , p_component_type          => l_component_type
52250         , p_component_code          => l_component_code
52251         , p_component_type_code     => l_component_type_code
52252         , p_component_appl_id       => l_component_appl_id
52253         , p_amb_context_code        => l_amb_context_code
52254         , p_entity_code             => 'TRANSACTIONS'
52255         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
52256         , p_side                    => 'NA'
52257         );
52258 
52259   END IF;
52260 
52261    l_segment := AcctDerRule_168(
52262            p_application_id           => p_application_id
52263          , p_ae_header_id             => l_ae_header_id 
52264 , p_source_3 => p_source_3
52265 , p_source_29 => p_source_29
52266          , x_transaction_coa_id       => l_adr_transaction_coa_id
52267          , x_accounting_coa_id        => l_adr_accounting_coa_id
52268          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
52269          , x_flex_value_set_id        => l_adr_flex_value_set_id
52270          , x_value_type_code          => l_adr_value_type_code
52271          , x_value_combination_id     => l_adr_value_combination_id
52272          , x_value_segment_code       => l_adr_value_segment_code
52273          , p_side                     => 'NA'
52274          , p_override_seg_flag        => 'Y'
52275    );
52276 
52277    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
52278 
52279       xla_ae_lines_pkg.set_segment(
52280           p_to_segment_code         => 'GL_BALANCING'
52281         , p_segment_value           => l_segment
52282         , p_from_segment_code       => l_adr_value_segment_code
52283         , p_from_combination_id     => l_adr_value_combination_id
52284         , p_value_type_code         => l_adr_value_type_code
52285         , p_transaction_coa_id      => l_adr_transaction_coa_id
52286         , p_accounting_coa_id       => l_adr_accounting_coa_id
52287         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
52288         , p_flex_value_set_id       => l_adr_flex_value_set_id
52289         , p_adr_code                => 'FA_EXPENSE_ACCT'
52290         , p_adr_type_code           => 'S'
52291         , p_component_type          => l_component_type
52292         , p_component_code          => l_component_code
52293         , p_component_type_code     => l_component_type_code
52294         , p_component_appl_id       => l_component_appl_id
52295         , p_amb_context_code        => l_amb_context_code
52296         , p_entity_code             => 'TRANSACTIONS'
52297         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
52298         , p_side                    => 'NA'
52299         );
52300 
52301   END IF;
52302 
52303    --
52304    --
52305    END IF;
52306    --
52307    -- Bug 4922099
52308    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
52309           (NVL(l_enc_upg_option, 'N') = 'O')
52310         ) AND
52311         (l_bflow_method_code = 'PRIOR_ENTRY')
52312       )
52313    THEN
52314       IF
52315       --
52316       1 = 2
52317       --
52318       THEN
52319       xla_accounting_err_pkg.build_message
52320                                     (p_appli_s_name            => 'XLA'
52321                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
52322                                     ,p_token_1                 => 'LINE_NUMBER'
52323                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
52324                                     ,p_token_2                 => 'LINE_TYPE_NAME'
52325                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
52326                                                                              l_component_type
52327                                                                             ,l_component_code
52328                                                                             ,l_component_type_code
52329                                                                             ,l_component_appl_id
52330                                                                             ,l_amb_context_code
52331                                                                             ,l_entity_code
52332                                                                             ,l_event_class_code
52333                                                                            )
52334                                     ,p_token_3                 => 'OWNER'
52335                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
52336                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
52337                                                                           ,p_lookup_code    => l_component_type_code
52338                                                                          )
52339                                     ,p_token_4                 => 'PRODUCT_NAME'
52340                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
52341                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
52342                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
52343                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
52344                                     ,p_ae_header_id            =>  NULL
52345                                        );
52346 
52347         IF (C_LEVEL_ERROR>= g_log_level) THEN
52348                  trace
52349                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
52353       END IF;
52350                       ,p_level    => C_LEVEL_ERROR
52351                       ,p_module   => l_log_module);
52352         END IF;
52354    END IF;
52355    --
52356    --
52357    ------------------------------------------------------------------------------------------------
52358    -- 4219869 Business Flow
52359    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
52360    -- Prior Entry.  Currently, the following code is always generated.
52361    ------------------------------------------------------------------------------------------------
52362    XLA_AE_LINES_PKG.ValidateCurrentLine;
52363 
52364    ------------------------------------------------------------------------------------
52365    -- 4219869 Business Flow
52366    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
52367    ------------------------------------------------------------------------------------
52368    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
52369 
52370    ----------------------------------------------------------------------------------
52371    -- 4219869 Business Flow
52372    -- Update journal entry status -- Need to generate this within IF <condition>
52373    ----------------------------------------------------------------------------------
52374    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
52375          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
52376          ,p_balance_type_code => l_balance_type_code
52377          );
52378 
52379    -------------------------------------------------------------------------------------------
52380    -- 4262811 - Generate the Accrual Reversal lines
52381    -------------------------------------------------------------------------------------------
52382    BEGIN
52383       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
52384                               (g_array_event(p_event_id).array_value_num('header_index'));
52385       IF l_acc_rev_flag IS NULL THEN
52386          l_acc_rev_flag := 'N';
52387       END IF;
52388    EXCEPTION
52389       WHEN OTHERS THEN
52390          l_acc_rev_flag := 'N';
52391    END;
52392    --
52393    IF (l_acc_rev_flag = 'Y') THEN
52394 
52395        -- 4645092  ------------------------------------------------------------------------------
52396        -- To allow MPA report to determine if it should generate report process
52397        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
52398        ------------------------------------------------------------------------------------------
52399 
52400        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
52401        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
52402    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
52403    -- call ADRs
52404    -- Bug 4922099
52405    --
52406    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
52407         (NVL(l_actual_upg_option, 'N') = 'O') OR
52408         (NVL(l_enc_upg_option, 'N') = 'O')
52409       )
52410    THEN
52411    NULL;
52412    --
52413    --
52414    
52415   l_ccid := AcctDerRule_173(
52416            p_application_id           => p_application_id
52417          , p_ae_header_id             => l_ae_header_id 
52418 , p_source_3 => p_source_3
52419 , p_source_30 => p_source_30
52420          , x_transaction_coa_id       => l_adr_transaction_coa_id
52421          , x_accounting_coa_id        => l_adr_accounting_coa_id
52422          , x_value_type_code          => l_adr_value_type_code
52423          , p_side                     => 'NA'
52424    );
52425 
52426    xla_ae_lines_pkg.set_ccid(
52427     p_code_combination_id          => l_ccid
52428   , p_value_type_code              => l_adr_value_type_code
52429   , p_transaction_coa_id           => l_adr_transaction_coa_id
52430   , p_accounting_coa_id            => l_adr_accounting_coa_id
52431   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
52432   , p_adr_type_code                => 'S'
52433   , p_component_type               => l_component_type
52434   , p_component_code               => l_component_code
52435   , p_component_type_code          => l_component_type_code
52436   , p_component_appl_id            => l_component_appl_id
52437   , p_amb_context_code             => l_amb_context_code
52438   , p_side                         => 'NA'
52439   );
52440 
52441 
52442    l_segment := AcctDerRule_146(
52443            p_application_id           => p_application_id
52444          , p_ae_header_id             => l_ae_header_id 
52445 , p_source_3 => p_source_3
52446 , p_source_7 => p_source_7
52447          , x_transaction_coa_id       => l_adr_transaction_coa_id
52448          , x_accounting_coa_id        => l_adr_accounting_coa_id
52449          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
52450          , x_flex_value_set_id        => l_adr_flex_value_set_id
52451          , x_value_type_code          => l_adr_value_type_code
52452          , x_value_combination_id     => l_adr_value_combination_id
52453          , x_value_segment_code       => l_adr_value_segment_code
52454          , p_side                     => 'NA'
52455          , p_override_seg_flag        => 'Y'
52456    );
52457 
52458    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
52459 
52460       xla_ae_lines_pkg.set_segment(
52461           p_to_segment_code         => 'GL_ACCOUNT'
52462         , p_segment_value           => l_segment
52463         , p_from_segment_code       => l_adr_value_segment_code
52464         , p_from_combination_id     => l_adr_value_combination_id
52465         , p_value_type_code         => l_adr_value_type_code
52466         , p_transaction_coa_id      => l_adr_transaction_coa_id
52467         , p_accounting_coa_id       => l_adr_accounting_coa_id
52468         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
52472         , p_component_type          => l_component_type
52469         , p_flex_value_set_id       => l_adr_flex_value_set_id
52470         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
52471         , p_adr_type_code           => 'S'
52473         , p_component_code          => l_component_code
52474         , p_component_type_code     => l_component_type_code
52475         , p_component_appl_id       => l_component_appl_id
52476         , p_amb_context_code        => l_amb_context_code
52477         , p_entity_code             => 'TRANSACTIONS'
52478         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
52479         , p_side                    => 'NA'
52480         );
52481 
52482   END IF;
52483 
52484    l_segment := AcctDerRule_168(
52485            p_application_id           => p_application_id
52486          , p_ae_header_id             => l_ae_header_id 
52487 , p_source_3 => p_source_3
52488 , p_source_29 => p_source_29
52489          , x_transaction_coa_id       => l_adr_transaction_coa_id
52490          , x_accounting_coa_id        => l_adr_accounting_coa_id
52491          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
52492          , x_flex_value_set_id        => l_adr_flex_value_set_id
52493          , x_value_type_code          => l_adr_value_type_code
52494          , x_value_combination_id     => l_adr_value_combination_id
52495          , x_value_segment_code       => l_adr_value_segment_code
52496          , p_side                     => 'NA'
52497          , p_override_seg_flag        => 'Y'
52498    );
52499 
52500    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
52501 
52502       xla_ae_lines_pkg.set_segment(
52503           p_to_segment_code         => 'GL_BALANCING'
52504         , p_segment_value           => l_segment
52505         , p_from_segment_code       => l_adr_value_segment_code
52506         , p_from_combination_id     => l_adr_value_combination_id
52507         , p_value_type_code         => l_adr_value_type_code
52508         , p_transaction_coa_id      => l_adr_transaction_coa_id
52509         , p_accounting_coa_id       => l_adr_accounting_coa_id
52510         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
52511         , p_flex_value_set_id       => l_adr_flex_value_set_id
52512         , p_adr_code                => 'FA_EXPENSE_ACCT'
52513         , p_adr_type_code           => 'S'
52514         , p_component_type          => l_component_type
52515         , p_component_code          => l_component_code
52516         , p_component_type_code     => l_component_type_code
52517         , p_component_appl_id       => l_component_appl_id
52518         , p_amb_context_code        => l_amb_context_code
52519         , p_entity_code             => 'TRANSACTIONS'
52520         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
52521         , p_side                    => 'NA'
52522         );
52523 
52524   END IF;
52525 
52526    --
52527    --
52528    END IF;
52529 
52530        --
52531        -- Update the line information that should be overwritten
52532        --
52533        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
52534                                          p_header_num   => 1);
52535        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
52536 
52537        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
52538 
52539        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
52540           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
52541        END IF;
52542 
52543       --
52544       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
52545       --
52546       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
52547           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
52548       ELSE
52549           ---------------------------------------------------------------------------------------------------
52550           -- 4262811a Switch Sign
52551           ---------------------------------------------------------------------------------------------------
52552           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
52553           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52554                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52555           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52556                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52557           -- 5132302
52558           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
52559                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52560 
52561       END IF;
52562 
52563       -- 4955764
52564       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
52565       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
52566 
52567 
52568       XLA_AE_LINES_PKG.ValidateCurrentLine;
52569       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
52570 
52571       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
52572                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
52573                ,p_balance_type_code => l_balance_type_code);
52574 
52575    END IF;
52576 
52577    -----------------------------------------------------------------------------------------
52578    -- 4262811 Multiperiod Accounting
52579    -----------------------------------------------------------------------------------------
52580      -- No MPA option is assigned.
52581 
52585 --
52582 
52583 END IF;
52584 END IF;
52586 
52587 --
52588 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
52589    trace
52590       (p_msg      => 'END of AcctLineType_227'
52591       ,p_level    => C_LEVEL_PROCEDURE
52592       ,p_module   => l_log_module);
52593 END IF;
52594 --
52595 EXCEPTION
52596   WHEN xla_exceptions_pkg.application_exception THEN
52597       RAISE;
52598   WHEN OTHERS THEN
52599        xla_exceptions_pkg.raise_message
52600            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_227');
52601 END AcctLineType_227;
52602 --
52603 
52604 ---------------------------------------
52605 --
52606 -- PRIVATE FUNCTION
52607 --         AcctLineType_228
52608 --
52609 ---------------------------------------
52610 PROCEDURE AcctLineType_228 (
52611   p_application_id        IN NUMBER
52612  ,p_event_id              IN NUMBER
52613  ,p_calculate_acctd_flag  IN VARCHAR2
52614  ,p_calculate_g_l_flag    IN VARCHAR2
52615  ,p_actual_flag           IN OUT VARCHAR2
52616  ,p_balance_type_code     OUT VARCHAR2
52617  ,p_gain_or_loss_ref      OUT VARCHAR2
52618  
52619 --Period Close Date
52620  , p_source_1            IN DATE
52621 --Generated Code Combination Identifier
52622  , p_source_3            IN NUMBER
52623 --Revaluation Reserve Account
52624  , p_source_11            IN VARCHAR2
52625 --Expense Account Code Combination Identifier
52626  , p_source_29            IN NUMBER
52627 --Default Code Combination Identifier
52628  , p_source_30            IN NUMBER
52629 --Adjustment Type
52630  , p_source_35            IN VARCHAR2
52631 --Transaction Header Identifier
52632  , p_source_36            IN NUMBER
52633 --Adjustment Line Identifier
52634  , p_source_37            IN NUMBER
52635 --Distribution Type Code
52636  , p_source_38            IN VARCHAR2
52637 --Entered Amount
52638  , p_source_39            IN NUMBER
52639 --Currency Code
52640  , p_source_40            IN VARCHAR2
52641 --Source Destination Code
52642  , p_source_42            IN VARCHAR2
52643 )
52644 IS
52645 
52646 l_component_type              VARCHAR2(80);
52647 l_component_code              VARCHAR2(30);
52648 l_component_type_code         VARCHAR2(1);
52649 l_component_appl_id           INTEGER;
52650 l_amb_context_code            VARCHAR2(30);
52651 l_entity_code                 VARCHAR2(30);
52652 l_event_class_code            VARCHAR2(30);
52653 l_ae_header_id                NUMBER;
52654 l_event_type_code             VARCHAR2(30);
52655 l_line_definition_code        VARCHAR2(30);
52656 l_line_definition_owner_code  VARCHAR2(1);
52657 --
52658 -- adr variables
52659 l_segment                     VARCHAR2(30);
52660 l_ccid                        NUMBER;
52661 l_adr_transaction_coa_id      NUMBER;
52662 l_adr_accounting_coa_id       NUMBER;
52663 l_adr_flexfield_segment_code  VARCHAR2(30);
52664 l_adr_flex_value_set_id       NUMBER;
52665 l_adr_value_type_code         VARCHAR2(30);
52666 l_adr_value_combination_id    NUMBER;
52667 l_adr_value_segment_code      VARCHAR2(30);
52668 
52669 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
52670 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
52671 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
52672 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
52673 
52674 -- 4262811 Variables ------------------------------------------------------------------------------------------
52675 l_entered_amt_idx             NUMBER;
52676 l_accted_amt_idx              NUMBER;
52677 l_acc_rev_flag                VARCHAR2(1);
52678 l_accrual_line_num            NUMBER;
52679 l_tmp_amt                     NUMBER;
52680 l_acc_rev_natural_side_code   VARCHAR2(1);
52681 
52682 l_num_entries                 NUMBER;
52683 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
52684 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
52685 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
52686 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
52687 l_recog_line_1                NUMBER;
52688 l_recog_line_2                NUMBER;
52689 
52690 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
52691 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
52692 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
52693 
52694 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
52695 
52696 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
52697 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
52698 
52699 ---------------------------------------------------------------------------------------------------------------
52700 
52701 
52702 --
52703 -- bulk performance
52704 --
52705 l_balance_type_code           VARCHAR2(1);
52706 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
52707 l_log_module                  VARCHAR2(240);
52708 
52709 --
52710 -- Upgrade strategy
52711 --
52712 l_actual_upg_option           VARCHAR2(1);
52713 l_enc_upg_option           VARCHAR2(1);
52714 
52715 --
52716 BEGIN
52717 --
52718 IF g_log_enabled THEN
52719       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_228';
52720 END IF;
52721 --
52722 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
52723 
52724       trace
52725          (p_msg      => 'BEGIN of AcctLineType_228'
52726          ,p_level    => C_LEVEL_PROCEDURE
52727          ,p_module   => l_log_module);
52728 
52729 END IF;
52730 --
52731 l_component_type             := 'AMB_JLT';
52735 l_amb_context_code           := 'DEFAULT';
52732 l_component_code             := 'FA_CIP_RECLASS_DEST_REVAL_RES';
52733 l_component_type_code        := 'S';
52734 l_component_appl_id          :=  140;
52736 l_entity_code                := 'TRANSACTIONS';
52737 l_event_class_code           := 'CIP_CATEGORY_RECLASS';
52738 l_event_type_code            := 'CIP_CATEGORY_RECLASS_ALL';
52739 l_line_definition_owner_code := 'S';
52740 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_CA7';
52741 --
52742 l_balance_type_code          := 'A';
52743 l_segment                     := NULL;
52744 l_ccid                        := NULL;
52745 l_adr_transaction_coa_id      := NULL;
52746 l_adr_accounting_coa_id       := NULL;
52747 l_adr_flexfield_segment_code  := NULL;
52748 l_adr_flex_value_set_id       := NULL;
52749 l_adr_value_type_code         := NULL;
52750 l_adr_value_combination_id    := NULL;
52751 l_adr_value_segment_code      := NULL;
52752 
52753 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
52754 l_bflow_class_code           := '';    -- 4219869 Business Flow
52755 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
52756 l_budgetary_control_flag     := 'N';
52757 
52758 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
52759 l_bflow_applied_to_amt       := NULL; -- 5132302
52760 l_entered_amt_idx            := NULL;          -- 4262811
52761 l_accted_amt_idx             := NULL;          -- 4262811
52762 l_acc_rev_flag               := NULL;          -- 4262811
52763 l_accrual_line_num           := NULL;          -- 4262811
52764 l_tmp_amt                    := NULL;          -- 4262811
52765 --
52766  
52767 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
52768     l_balance_type_code <> 'B' THEN
52769 IF NVL(p_source_35,'
52770 ') =  'REVAL RESERVE' AND 
52771 NVL(p_source_42,'
52772 ') =  'DEST'
52773  THEN 
52774 
52775    --
52776    XLA_AE_LINES_PKG.SetNewLine;
52777 
52778    p_balance_type_code          := l_balance_type_code;
52779    -- set the flag so later we will know whether the gain loss line needs to be created
52780    
52781    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
52782      p_actual_flag :='A';
52783    END IF;
52784 
52785    --
52786    -- bulk performance
52787    --
52788    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
52789                                       p_header_num   => 0); -- 4262811
52790    --
52791    -- set accounting line options
52792    --
52793    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
52794            p_natural_side_code          => 'C'
52795          , p_gain_or_loss_flag          => 'N'
52796          , p_gl_transfer_mode_code      => 'S'
52797          , p_acct_entry_type_code       => 'A'
52798          , p_switch_side_flag           => 'Y'
52799          , p_merge_duplicate_code       => 'N'
52800          );
52801    --
52802    l_acc_rev_natural_side_code := 'D';  -- 4262811
52803    -- 
52804    --
52805    -- set accounting line type info
52806    --
52807    xla_ae_lines_pkg.SetAcctLineType
52808       (p_component_type             => l_component_type
52809       ,p_event_type_code            => l_event_type_code
52810       ,p_line_definition_owner_code => l_line_definition_owner_code
52811       ,p_line_definition_code       => l_line_definition_code
52812       ,p_accounting_line_code       => l_component_code
52813       ,p_accounting_line_type_code  => l_component_type_code
52814       ,p_accounting_line_appl_id    => l_component_appl_id
52815       ,p_amb_context_code           => l_amb_context_code
52816       ,p_entity_code                => l_entity_code
52817       ,p_event_class_code           => l_event_class_code);
52818    --
52819    -- set accounting class
52820    --
52821    xla_ae_lines_pkg.SetAcctClass(
52822            p_accounting_class_code  => 'ASSET'
52823          , p_ae_header_id           => l_ae_header_id
52824          );
52825 
52826    --
52827    -- set rounding class
52828    --
52829    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
52830                       'ASSET';
52831 
52832    --
52833    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
52834    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
52835    --
52836    -- bulk performance
52837    --
52838    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
52839 
52840    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
52841       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
52842 
52843    -- 4955764
52844    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
52845       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
52846 
52847    -- 4458381 Public Sector Enh
52848    
52849    --
52850    -- set accounting attributes for the line type
52851    --
52852    l_entered_amt_idx := 4;
52853    l_accted_amt_idx  := 6;
52854    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
52855    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
52856    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
52857    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
52858    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
52859    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
52860    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
52861    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
52862    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
52866    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
52863    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
52864    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
52865    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
52867 
52868    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
52869    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
52870 
52871    ---------------------------------------------------------------------------------------------------------------
52872    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
52873    ---------------------------------------------------------------------------------------------------------------
52874    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
52875 
52876    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
52877    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
52878 
52879    IF xla_accounting_cache_pkg.GetValueChar
52880          (p_source_code         => 'LEDGER_CATEGORY_CODE'
52881          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
52882    AND l_bflow_method_code = 'PRIOR_ENTRY'
52883 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
52884    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
52885          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
52886        )
52887    THEN
52888          xla_ae_lines_pkg.BflowUpgEntry
52889            (p_business_method_code    => l_bflow_method_code
52890            ,p_business_class_code     => l_bflow_class_code
52891            ,p_balance_type            => l_balance_type_code);
52892    ELSE
52893       NULL;
52894 -- No business flow processing for business flow method of NONE.
52895    END IF;
52896 
52897    --
52898    -- call analytical criteria
52899    --
52900    
52901    --
52902    -- call description
52903    --
52904    
52905 xla_ae_lines_pkg.SetLineDescription(
52906    p_ae_header_id => l_ae_header_id
52907   ,p_description  => Description_30 (
52908      p_application_id         => p_application_id
52909    , p_ae_header_id           => l_ae_header_id 
52910 , p_source_1 => p_source_1
52911    )
52912 );
52913 
52914 
52915    --
52916    -- call ADRs
52917    -- Bug 4922099
52918    --
52919    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
52920         (NVL(l_actual_upg_option, 'N') = 'O') OR
52921         (NVL(l_enc_upg_option, 'N') = 'O')
52922       )
52923    THEN
52924    NULL;
52925    --
52926    --
52927    
52928   l_ccid := AcctDerRule_173(
52929            p_application_id           => p_application_id
52930          , p_ae_header_id             => l_ae_header_id 
52931 , p_source_3 => p_source_3
52932 , p_source_30 => p_source_30
52933          , x_transaction_coa_id       => l_adr_transaction_coa_id
52934          , x_accounting_coa_id        => l_adr_accounting_coa_id
52935          , x_value_type_code          => l_adr_value_type_code
52936          , p_side                     => 'NA'
52937    );
52938 
52939    xla_ae_lines_pkg.set_ccid(
52940     p_code_combination_id          => l_ccid
52941   , p_value_type_code              => l_adr_value_type_code
52942   , p_transaction_coa_id           => l_adr_transaction_coa_id
52943   , p_accounting_coa_id            => l_adr_accounting_coa_id
52944   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
52945   , p_adr_type_code                => 'S'
52946   , p_component_type               => l_component_type
52947   , p_component_code               => l_component_code
52948   , p_component_type_code          => l_component_type_code
52949   , p_component_appl_id            => l_component_appl_id
52950   , p_amb_context_code             => l_amb_context_code
52951   , p_side                         => 'NA'
52952   );
52953 
52954 
52955    l_segment := AcctDerRule_150(
52956            p_application_id           => p_application_id
52957          , p_ae_header_id             => l_ae_header_id 
52958 , p_source_3 => p_source_3
52959 , p_source_11 => p_source_11
52960          , x_transaction_coa_id       => l_adr_transaction_coa_id
52961          , x_accounting_coa_id        => l_adr_accounting_coa_id
52962          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
52963          , x_flex_value_set_id        => l_adr_flex_value_set_id
52964          , x_value_type_code          => l_adr_value_type_code
52965          , x_value_combination_id     => l_adr_value_combination_id
52966          , x_value_segment_code       => l_adr_value_segment_code
52967          , p_side                     => 'NA'
52968          , p_override_seg_flag        => 'Y'
52969    );
52970 
52971    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
52972 
52973       xla_ae_lines_pkg.set_segment(
52974           p_to_segment_code         => 'GL_ACCOUNT'
52975         , p_segment_value           => l_segment
52976         , p_from_segment_code       => l_adr_value_segment_code
52977         , p_from_combination_id     => l_adr_value_combination_id
52978         , p_value_type_code         => l_adr_value_type_code
52979         , p_transaction_coa_id      => l_adr_transaction_coa_id
52980         , p_accounting_coa_id       => l_adr_accounting_coa_id
52981         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
52982         , p_flex_value_set_id       => l_adr_flex_value_set_id
52983         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
52984         , p_adr_type_code           => 'S'
52985         , p_component_type          => l_component_type
52986         , p_component_code          => l_component_code
52987         , p_component_type_code     => l_component_type_code
52991         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
52988         , p_component_appl_id       => l_component_appl_id
52989         , p_amb_context_code        => l_amb_context_code
52990         , p_entity_code             => 'TRANSACTIONS'
52992         , p_side                    => 'NA'
52993         );
52994 
52995   END IF;
52996 
52997    l_segment := AcctDerRule_168(
52998            p_application_id           => p_application_id
52999          , p_ae_header_id             => l_ae_header_id 
53000 , p_source_3 => p_source_3
53001 , p_source_29 => p_source_29
53002          , x_transaction_coa_id       => l_adr_transaction_coa_id
53003          , x_accounting_coa_id        => l_adr_accounting_coa_id
53004          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
53005          , x_flex_value_set_id        => l_adr_flex_value_set_id
53006          , x_value_type_code          => l_adr_value_type_code
53007          , x_value_combination_id     => l_adr_value_combination_id
53008          , x_value_segment_code       => l_adr_value_segment_code
53009          , p_side                     => 'NA'
53010          , p_override_seg_flag        => 'Y'
53011    );
53012 
53013    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
53014 
53015       xla_ae_lines_pkg.set_segment(
53016           p_to_segment_code         => 'GL_BALANCING'
53017         , p_segment_value           => l_segment
53018         , p_from_segment_code       => l_adr_value_segment_code
53019         , p_from_combination_id     => l_adr_value_combination_id
53020         , p_value_type_code         => l_adr_value_type_code
53021         , p_transaction_coa_id      => l_adr_transaction_coa_id
53022         , p_accounting_coa_id       => l_adr_accounting_coa_id
53023         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
53024         , p_flex_value_set_id       => l_adr_flex_value_set_id
53025         , p_adr_code                => 'FA_EXPENSE_ACCT'
53026         , p_adr_type_code           => 'S'
53027         , p_component_type          => l_component_type
53028         , p_component_code          => l_component_code
53029         , p_component_type_code     => l_component_type_code
53030         , p_component_appl_id       => l_component_appl_id
53031         , p_amb_context_code        => l_amb_context_code
53032         , p_entity_code             => 'TRANSACTIONS'
53033         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
53034         , p_side                    => 'NA'
53035         );
53036 
53037   END IF;
53038 
53039    --
53040    --
53041    END IF;
53042    --
53043    -- Bug 4922099
53044    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
53045           (NVL(l_enc_upg_option, 'N') = 'O')
53046         ) AND
53047         (l_bflow_method_code = 'PRIOR_ENTRY')
53048       )
53049    THEN
53050       IF
53051       --
53052       1 = 2
53053       --
53054       THEN
53055       xla_accounting_err_pkg.build_message
53056                                     (p_appli_s_name            => 'XLA'
53057                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
53058                                     ,p_token_1                 => 'LINE_NUMBER'
53059                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
53060                                     ,p_token_2                 => 'LINE_TYPE_NAME'
53061                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
53062                                                                              l_component_type
53063                                                                             ,l_component_code
53064                                                                             ,l_component_type_code
53065                                                                             ,l_component_appl_id
53066                                                                             ,l_amb_context_code
53067                                                                             ,l_entity_code
53068                                                                             ,l_event_class_code
53069                                                                            )
53070                                     ,p_token_3                 => 'OWNER'
53071                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
53072                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
53073                                                                           ,p_lookup_code    => l_component_type_code
53074                                                                          )
53075                                     ,p_token_4                 => 'PRODUCT_NAME'
53076                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
53077                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
53078                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
53079                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
53080                                     ,p_ae_header_id            =>  NULL
53081                                        );
53082 
53083         IF (C_LEVEL_ERROR>= g_log_level) THEN
53084                  trace
53085                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
53086                       ,p_level    => C_LEVEL_ERROR
53087                       ,p_module   => l_log_module);
53088         END IF;
53089       END IF;
53090    END IF;
53091    --
53092    --
53093    ------------------------------------------------------------------------------------------------
53094    -- 4219869 Business Flow
53095    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
53099 
53096    -- Prior Entry.  Currently, the following code is always generated.
53097    ------------------------------------------------------------------------------------------------
53098    XLA_AE_LINES_PKG.ValidateCurrentLine;
53100    ------------------------------------------------------------------------------------
53101    -- 4219869 Business Flow
53102    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
53103    ------------------------------------------------------------------------------------
53104    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
53105 
53106    ----------------------------------------------------------------------------------
53107    -- 4219869 Business Flow
53108    -- Update journal entry status -- Need to generate this within IF <condition>
53109    ----------------------------------------------------------------------------------
53110    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
53111          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
53112          ,p_balance_type_code => l_balance_type_code
53113          );
53114 
53115    -------------------------------------------------------------------------------------------
53116    -- 4262811 - Generate the Accrual Reversal lines
53117    -------------------------------------------------------------------------------------------
53118    BEGIN
53119       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
53120                               (g_array_event(p_event_id).array_value_num('header_index'));
53121       IF l_acc_rev_flag IS NULL THEN
53122          l_acc_rev_flag := 'N';
53123       END IF;
53124    EXCEPTION
53125       WHEN OTHERS THEN
53126          l_acc_rev_flag := 'N';
53127    END;
53128    --
53129    IF (l_acc_rev_flag = 'Y') THEN
53130 
53131        -- 4645092  ------------------------------------------------------------------------------
53132        -- To allow MPA report to determine if it should generate report process
53133        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
53134        ------------------------------------------------------------------------------------------
53135 
53136        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
53137        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
53138    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
53139    -- call ADRs
53140    -- Bug 4922099
53141    --
53142    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
53143         (NVL(l_actual_upg_option, 'N') = 'O') OR
53144         (NVL(l_enc_upg_option, 'N') = 'O')
53145       )
53146    THEN
53147    NULL;
53148    --
53149    --
53150    
53151   l_ccid := AcctDerRule_173(
53152            p_application_id           => p_application_id
53153          , p_ae_header_id             => l_ae_header_id 
53154 , p_source_3 => p_source_3
53155 , p_source_30 => p_source_30
53156          , x_transaction_coa_id       => l_adr_transaction_coa_id
53157          , x_accounting_coa_id        => l_adr_accounting_coa_id
53158          , x_value_type_code          => l_adr_value_type_code
53159          , p_side                     => 'NA'
53160    );
53161 
53162    xla_ae_lines_pkg.set_ccid(
53163     p_code_combination_id          => l_ccid
53164   , p_value_type_code              => l_adr_value_type_code
53165   , p_transaction_coa_id           => l_adr_transaction_coa_id
53166   , p_accounting_coa_id            => l_adr_accounting_coa_id
53167   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
53168   , p_adr_type_code                => 'S'
53169   , p_component_type               => l_component_type
53170   , p_component_code               => l_component_code
53171   , p_component_type_code          => l_component_type_code
53172   , p_component_appl_id            => l_component_appl_id
53173   , p_amb_context_code             => l_amb_context_code
53174   , p_side                         => 'NA'
53175   );
53176 
53177 
53178    l_segment := AcctDerRule_150(
53179            p_application_id           => p_application_id
53180          , p_ae_header_id             => l_ae_header_id 
53181 , p_source_3 => p_source_3
53182 , p_source_11 => p_source_11
53183          , x_transaction_coa_id       => l_adr_transaction_coa_id
53184          , x_accounting_coa_id        => l_adr_accounting_coa_id
53185          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
53186          , x_flex_value_set_id        => l_adr_flex_value_set_id
53187          , x_value_type_code          => l_adr_value_type_code
53188          , x_value_combination_id     => l_adr_value_combination_id
53189          , x_value_segment_code       => l_adr_value_segment_code
53190          , p_side                     => 'NA'
53191          , p_override_seg_flag        => 'Y'
53192    );
53193 
53194    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
53195 
53196       xla_ae_lines_pkg.set_segment(
53197           p_to_segment_code         => 'GL_ACCOUNT'
53198         , p_segment_value           => l_segment
53199         , p_from_segment_code       => l_adr_value_segment_code
53200         , p_from_combination_id     => l_adr_value_combination_id
53201         , p_value_type_code         => l_adr_value_type_code
53202         , p_transaction_coa_id      => l_adr_transaction_coa_id
53203         , p_accounting_coa_id       => l_adr_accounting_coa_id
53204         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
53205         , p_flex_value_set_id       => l_adr_flex_value_set_id
53206         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
53207         , p_adr_type_code           => 'S'
53208         , p_component_type          => l_component_type
53209         , p_component_code          => l_component_code
53210         , p_component_type_code     => l_component_type_code
53211         , p_component_appl_id       => l_component_appl_id
53212         , p_amb_context_code        => l_amb_context_code
53216         );
53213         , p_entity_code             => 'TRANSACTIONS'
53214         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
53215         , p_side                    => 'NA'
53217 
53218   END IF;
53219 
53220    l_segment := AcctDerRule_168(
53221            p_application_id           => p_application_id
53222          , p_ae_header_id             => l_ae_header_id 
53223 , p_source_3 => p_source_3
53224 , p_source_29 => p_source_29
53225          , x_transaction_coa_id       => l_adr_transaction_coa_id
53226          , x_accounting_coa_id        => l_adr_accounting_coa_id
53227          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
53228          , x_flex_value_set_id        => l_adr_flex_value_set_id
53229          , x_value_type_code          => l_adr_value_type_code
53230          , x_value_combination_id     => l_adr_value_combination_id
53231          , x_value_segment_code       => l_adr_value_segment_code
53232          , p_side                     => 'NA'
53233          , p_override_seg_flag        => 'Y'
53234    );
53235 
53236    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
53237 
53238       xla_ae_lines_pkg.set_segment(
53239           p_to_segment_code         => 'GL_BALANCING'
53240         , p_segment_value           => l_segment
53241         , p_from_segment_code       => l_adr_value_segment_code
53242         , p_from_combination_id     => l_adr_value_combination_id
53243         , p_value_type_code         => l_adr_value_type_code
53244         , p_transaction_coa_id      => l_adr_transaction_coa_id
53245         , p_accounting_coa_id       => l_adr_accounting_coa_id
53246         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
53247         , p_flex_value_set_id       => l_adr_flex_value_set_id
53248         , p_adr_code                => 'FA_EXPENSE_ACCT'
53249         , p_adr_type_code           => 'S'
53250         , p_component_type          => l_component_type
53251         , p_component_code          => l_component_code
53252         , p_component_type_code     => l_component_type_code
53253         , p_component_appl_id       => l_component_appl_id
53254         , p_amb_context_code        => l_amb_context_code
53255         , p_entity_code             => 'TRANSACTIONS'
53256         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
53257         , p_side                    => 'NA'
53258         );
53259 
53260   END IF;
53261 
53262    --
53263    --
53264    END IF;
53265 
53266        --
53267        -- Update the line information that should be overwritten
53268        --
53269        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
53270                                          p_header_num   => 1);
53271        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
53272 
53273        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
53274 
53275        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
53276           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
53277        END IF;
53278 
53279       --
53280       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
53281       --
53282       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
53283           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
53284       ELSE
53285           ---------------------------------------------------------------------------------------------------
53286           -- 4262811a Switch Sign
53287           ---------------------------------------------------------------------------------------------------
53288           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
53289           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
53290                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
53291           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
53292                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
53293           -- 5132302
53294           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
53295                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
53296 
53297       END IF;
53298 
53299       -- 4955764
53300       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
53301       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
53302 
53303 
53304       XLA_AE_LINES_PKG.ValidateCurrentLine;
53305       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
53306 
53307       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
53308                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
53309                ,p_balance_type_code => l_balance_type_code);
53310 
53311    END IF;
53312 
53313    -----------------------------------------------------------------------------------------
53314    -- 4262811 Multiperiod Accounting
53315    -----------------------------------------------------------------------------------------
53316      -- No MPA option is assigned.
53317 
53318 
53319 END IF;
53320 END IF;
53321 --
53322 
53323 --
53324 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
53325    trace
53326       (p_msg      => 'END of AcctLineType_228'
53327       ,p_level    => C_LEVEL_PROCEDURE
53328       ,p_module   => l_log_module);
53329 END IF;
53330 --
53331 EXCEPTION
53332   WHEN xla_exceptions_pkg.application_exception THEN
53333       RAISE;
53334   WHEN OTHERS THEN
53338 --
53335        xla_exceptions_pkg.raise_message
53336            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_228');
53337 END AcctLineType_228;
53339 
53340 ---------------------------------------
53341 --
53342 -- PRIVATE FUNCTION
53343 --         AcctLineType_229
53344 --
53345 ---------------------------------------
53346 PROCEDURE AcctLineType_229 (
53347   p_application_id        IN NUMBER
53348  ,p_event_id              IN NUMBER
53349  ,p_calculate_acctd_flag  IN VARCHAR2
53350  ,p_calculate_g_l_flag    IN VARCHAR2
53351  ,p_actual_flag           IN OUT VARCHAR2
53352  ,p_balance_type_code     OUT VARCHAR2
53353  ,p_gain_or_loss_ref      OUT VARCHAR2
53354  
53355 --Period Close Date
53356  , p_source_1            IN DATE
53357 --Generated Code Combination Identifier
53358  , p_source_3            IN NUMBER
53359 --CIP Cost Account
53360  , p_source_7            IN VARCHAR2
53361 --Expense Account Code Combination Identifier
53362  , p_source_29            IN NUMBER
53363 --Default Code Combination Identifier
53364  , p_source_30            IN NUMBER
53365 --Adjustment Type
53366  , p_source_35            IN VARCHAR2
53367 --Transaction Header Identifier
53368  , p_source_36            IN NUMBER
53369 --Adjustment Line Identifier
53370  , p_source_37            IN NUMBER
53371 --Distribution Type Code
53372  , p_source_38            IN VARCHAR2
53373 --Entered Amount
53374  , p_source_39            IN NUMBER
53375 --Currency Code
53376  , p_source_40            IN VARCHAR2
53377 --Source Destination Code
53378  , p_source_42            IN VARCHAR2
53379 )
53380 IS
53381 
53382 l_component_type              VARCHAR2(80);
53383 l_component_code              VARCHAR2(30);
53384 l_component_type_code         VARCHAR2(1);
53385 l_component_appl_id           INTEGER;
53386 l_amb_context_code            VARCHAR2(30);
53387 l_entity_code                 VARCHAR2(30);
53388 l_event_class_code            VARCHAR2(30);
53389 l_ae_header_id                NUMBER;
53390 l_event_type_code             VARCHAR2(30);
53391 l_line_definition_code        VARCHAR2(30);
53392 l_line_definition_owner_code  VARCHAR2(1);
53393 --
53394 -- adr variables
53395 l_segment                     VARCHAR2(30);
53396 l_ccid                        NUMBER;
53397 l_adr_transaction_coa_id      NUMBER;
53398 l_adr_accounting_coa_id       NUMBER;
53399 l_adr_flexfield_segment_code  VARCHAR2(30);
53400 l_adr_flex_value_set_id       NUMBER;
53401 l_adr_value_type_code         VARCHAR2(30);
53402 l_adr_value_combination_id    NUMBER;
53403 l_adr_value_segment_code      VARCHAR2(30);
53404 
53405 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
53406 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
53407 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
53408 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
53409 
53410 -- 4262811 Variables ------------------------------------------------------------------------------------------
53411 l_entered_amt_idx             NUMBER;
53412 l_accted_amt_idx              NUMBER;
53413 l_acc_rev_flag                VARCHAR2(1);
53414 l_accrual_line_num            NUMBER;
53415 l_tmp_amt                     NUMBER;
53416 l_acc_rev_natural_side_code   VARCHAR2(1);
53417 
53418 l_num_entries                 NUMBER;
53419 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
53420 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
53421 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
53422 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
53423 l_recog_line_1                NUMBER;
53424 l_recog_line_2                NUMBER;
53425 
53426 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
53427 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
53428 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
53429 
53430 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
53431 
53432 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
53433 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
53434 
53435 ---------------------------------------------------------------------------------------------------------------
53436 
53437 
53438 --
53439 -- bulk performance
53440 --
53441 l_balance_type_code           VARCHAR2(1);
53442 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
53443 l_log_module                  VARCHAR2(240);
53444 
53445 --
53446 -- Upgrade strategy
53447 --
53448 l_actual_upg_option           VARCHAR2(1);
53449 l_enc_upg_option           VARCHAR2(1);
53450 
53451 --
53452 BEGIN
53453 --
53454 IF g_log_enabled THEN
53455       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_229';
53456 END IF;
53457 --
53458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
53459 
53460       trace
53461          (p_msg      => 'BEGIN of AcctLineType_229'
53462          ,p_level    => C_LEVEL_PROCEDURE
53463          ,p_module   => l_log_module);
53464 
53465 END IF;
53466 --
53467 l_component_type             := 'AMB_JLT';
53468 l_component_code             := 'FA_CIP_RECLASS_SOURCE_COST';
53469 l_component_type_code        := 'S';
53470 l_component_appl_id          :=  140;
53471 l_amb_context_code           := 'DEFAULT';
53472 l_entity_code                := 'TRANSACTIONS';
53473 l_event_class_code           := 'CIP_CATEGORY_RECLASS';
53474 l_event_type_code            := 'CIP_CATEGORY_RECLASS_ALL';
53475 l_line_definition_owner_code := 'S';
53476 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_CA7';
53477 --
53478 l_balance_type_code          := 'A';
53482 l_adr_accounting_coa_id       := NULL;
53479 l_segment                     := NULL;
53480 l_ccid                        := NULL;
53481 l_adr_transaction_coa_id      := NULL;
53483 l_adr_flexfield_segment_code  := NULL;
53484 l_adr_flex_value_set_id       := NULL;
53485 l_adr_value_type_code         := NULL;
53486 l_adr_value_combination_id    := NULL;
53487 l_adr_value_segment_code      := NULL;
53488 
53489 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
53490 l_bflow_class_code           := '';    -- 4219869 Business Flow
53491 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
53492 l_budgetary_control_flag     := 'N';
53493 
53494 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
53495 l_bflow_applied_to_amt       := NULL; -- 5132302
53496 l_entered_amt_idx            := NULL;          -- 4262811
53497 l_accted_amt_idx             := NULL;          -- 4262811
53498 l_acc_rev_flag               := NULL;          -- 4262811
53499 l_accrual_line_num           := NULL;          -- 4262811
53500 l_tmp_amt                    := NULL;          -- 4262811
53501 --
53502  
53503 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
53504     l_balance_type_code <> 'B' THEN
53505 IF NVL(p_source_35,'
53506 ') =  'CIP COST' AND 
53507 NVL(p_source_42,'
53508 ') =  'SOURCE'
53509  THEN 
53510 
53511    --
53512    XLA_AE_LINES_PKG.SetNewLine;
53513 
53514    p_balance_type_code          := l_balance_type_code;
53515    -- set the flag so later we will know whether the gain loss line needs to be created
53516    
53517    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
53518      p_actual_flag :='A';
53519    END IF;
53520 
53521    --
53522    -- bulk performance
53523    --
53524    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
53525                                       p_header_num   => 0); -- 4262811
53526    --
53527    -- set accounting line options
53528    --
53529    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
53530            p_natural_side_code          => 'C'
53531          , p_gain_or_loss_flag          => 'N'
53532          , p_gl_transfer_mode_code      => 'S'
53533          , p_acct_entry_type_code       => 'A'
53534          , p_switch_side_flag           => 'Y'
53535          , p_merge_duplicate_code       => 'N'
53536          );
53537    --
53538    l_acc_rev_natural_side_code := 'D';  -- 4262811
53539    -- 
53540    --
53541    -- set accounting line type info
53542    --
53543    xla_ae_lines_pkg.SetAcctLineType
53544       (p_component_type             => l_component_type
53545       ,p_event_type_code            => l_event_type_code
53546       ,p_line_definition_owner_code => l_line_definition_owner_code
53547       ,p_line_definition_code       => l_line_definition_code
53548       ,p_accounting_line_code       => l_component_code
53549       ,p_accounting_line_type_code  => l_component_type_code
53550       ,p_accounting_line_appl_id    => l_component_appl_id
53551       ,p_amb_context_code           => l_amb_context_code
53552       ,p_entity_code                => l_entity_code
53553       ,p_event_class_code           => l_event_class_code);
53554    --
53555    -- set accounting class
53556    --
53557    xla_ae_lines_pkg.SetAcctClass(
53558            p_accounting_class_code  => 'ASSET'
53559          , p_ae_header_id           => l_ae_header_id
53560          );
53561 
53562    --
53563    -- set rounding class
53564    --
53565    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
53566                       'ASSET';
53567 
53568    --
53569    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
53570    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
53571    --
53572    -- bulk performance
53573    --
53574    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
53575 
53576    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
53577       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
53578 
53579    -- 4955764
53580    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
53581       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
53582 
53583    -- 4458381 Public Sector Enh
53584    
53585    --
53586    -- set accounting attributes for the line type
53587    --
53588    l_entered_amt_idx := 4;
53589    l_accted_amt_idx  := 6;
53590    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
53591    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
53592    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
53593    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
53594    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
53595    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
53596    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
53597    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
53598    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
53599    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
53600    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
53601    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
53602    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
53603 
53604    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
53605    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
53606 
53607    ---------------------------------------------------------------------------------------------------------------
53611 
53608    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
53609    ---------------------------------------------------------------------------------------------------------------
53610    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
53612    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
53613    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
53614 
53615    IF xla_accounting_cache_pkg.GetValueChar
53616          (p_source_code         => 'LEDGER_CATEGORY_CODE'
53617          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
53618    AND l_bflow_method_code = 'PRIOR_ENTRY'
53619 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
53620    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
53621          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
53622        )
53623    THEN
53624          xla_ae_lines_pkg.BflowUpgEntry
53625            (p_business_method_code    => l_bflow_method_code
53626            ,p_business_class_code     => l_bflow_class_code
53627            ,p_balance_type            => l_balance_type_code);
53628    ELSE
53629       NULL;
53630 -- No business flow processing for business flow method of NONE.
53631    END IF;
53632 
53633    --
53634    -- call analytical criteria
53635    --
53636    
53637    --
53638    -- call description
53639    --
53640    
53641 xla_ae_lines_pkg.SetLineDescription(
53642    p_ae_header_id => l_ae_header_id
53643   ,p_description  => Description_65 (
53644      p_application_id         => p_application_id
53645    , p_ae_header_id           => l_ae_header_id 
53646 , p_source_1 => p_source_1
53647    )
53648 );
53649 
53650 
53651    --
53652    -- call ADRs
53653    -- Bug 4922099
53654    --
53655    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
53656         (NVL(l_actual_upg_option, 'N') = 'O') OR
53657         (NVL(l_enc_upg_option, 'N') = 'O')
53658       )
53659    THEN
53660    NULL;
53661    --
53662    --
53663    
53664   l_ccid := AcctDerRule_173(
53665            p_application_id           => p_application_id
53666          , p_ae_header_id             => l_ae_header_id 
53667 , p_source_3 => p_source_3
53668 , p_source_30 => p_source_30
53669          , x_transaction_coa_id       => l_adr_transaction_coa_id
53670          , x_accounting_coa_id        => l_adr_accounting_coa_id
53671          , x_value_type_code          => l_adr_value_type_code
53672          , p_side                     => 'NA'
53673    );
53674 
53675    xla_ae_lines_pkg.set_ccid(
53676     p_code_combination_id          => l_ccid
53677   , p_value_type_code              => l_adr_value_type_code
53678   , p_transaction_coa_id           => l_adr_transaction_coa_id
53679   , p_accounting_coa_id            => l_adr_accounting_coa_id
53680   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
53681   , p_adr_type_code                => 'S'
53682   , p_component_type               => l_component_type
53683   , p_component_code               => l_component_code
53684   , p_component_type_code          => l_component_type_code
53685   , p_component_appl_id            => l_component_appl_id
53686   , p_amb_context_code             => l_amb_context_code
53687   , p_side                         => 'NA'
53688   );
53689 
53690 
53691    l_segment := AcctDerRule_146(
53692            p_application_id           => p_application_id
53693          , p_ae_header_id             => l_ae_header_id 
53694 , p_source_3 => p_source_3
53695 , p_source_7 => p_source_7
53696          , x_transaction_coa_id       => l_adr_transaction_coa_id
53697          , x_accounting_coa_id        => l_adr_accounting_coa_id
53698          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
53699          , x_flex_value_set_id        => l_adr_flex_value_set_id
53700          , x_value_type_code          => l_adr_value_type_code
53701          , x_value_combination_id     => l_adr_value_combination_id
53702          , x_value_segment_code       => l_adr_value_segment_code
53703          , p_side                     => 'NA'
53704          , p_override_seg_flag        => 'Y'
53705    );
53706 
53707    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
53708 
53709       xla_ae_lines_pkg.set_segment(
53710           p_to_segment_code         => 'GL_ACCOUNT'
53711         , p_segment_value           => l_segment
53712         , p_from_segment_code       => l_adr_value_segment_code
53713         , p_from_combination_id     => l_adr_value_combination_id
53714         , p_value_type_code         => l_adr_value_type_code
53715         , p_transaction_coa_id      => l_adr_transaction_coa_id
53716         , p_accounting_coa_id       => l_adr_accounting_coa_id
53717         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
53718         , p_flex_value_set_id       => l_adr_flex_value_set_id
53719         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
53720         , p_adr_type_code           => 'S'
53721         , p_component_type          => l_component_type
53722         , p_component_code          => l_component_code
53723         , p_component_type_code     => l_component_type_code
53724         , p_component_appl_id       => l_component_appl_id
53725         , p_amb_context_code        => l_amb_context_code
53726         , p_entity_code             => 'TRANSACTIONS'
53727         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
53728         , p_side                    => 'NA'
53729         );
53730 
53731   END IF;
53732 
53733    l_segment := AcctDerRule_168(
53734            p_application_id           => p_application_id
53735          , p_ae_header_id             => l_ae_header_id 
53736 , p_source_3 => p_source_3
53740          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
53737 , p_source_29 => p_source_29
53738          , x_transaction_coa_id       => l_adr_transaction_coa_id
53739          , x_accounting_coa_id        => l_adr_accounting_coa_id
53741          , x_flex_value_set_id        => l_adr_flex_value_set_id
53742          , x_value_type_code          => l_adr_value_type_code
53743          , x_value_combination_id     => l_adr_value_combination_id
53744          , x_value_segment_code       => l_adr_value_segment_code
53745          , p_side                     => 'NA'
53746          , p_override_seg_flag        => 'Y'
53747    );
53748 
53749    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
53750 
53751       xla_ae_lines_pkg.set_segment(
53752           p_to_segment_code         => 'GL_BALANCING'
53753         , p_segment_value           => l_segment
53754         , p_from_segment_code       => l_adr_value_segment_code
53755         , p_from_combination_id     => l_adr_value_combination_id
53756         , p_value_type_code         => l_adr_value_type_code
53757         , p_transaction_coa_id      => l_adr_transaction_coa_id
53758         , p_accounting_coa_id       => l_adr_accounting_coa_id
53759         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
53760         , p_flex_value_set_id       => l_adr_flex_value_set_id
53761         , p_adr_code                => 'FA_EXPENSE_ACCT'
53762         , p_adr_type_code           => 'S'
53763         , p_component_type          => l_component_type
53764         , p_component_code          => l_component_code
53765         , p_component_type_code     => l_component_type_code
53766         , p_component_appl_id       => l_component_appl_id
53767         , p_amb_context_code        => l_amb_context_code
53768         , p_entity_code             => 'TRANSACTIONS'
53769         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
53770         , p_side                    => 'NA'
53771         );
53772 
53773   END IF;
53774 
53775    --
53776    --
53777    END IF;
53778    --
53779    -- Bug 4922099
53780    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
53781           (NVL(l_enc_upg_option, 'N') = 'O')
53782         ) AND
53783         (l_bflow_method_code = 'PRIOR_ENTRY')
53784       )
53785    THEN
53786       IF
53787       --
53788       1 = 2
53789       --
53790       THEN
53791       xla_accounting_err_pkg.build_message
53792                                     (p_appli_s_name            => 'XLA'
53793                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
53794                                     ,p_token_1                 => 'LINE_NUMBER'
53795                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
53796                                     ,p_token_2                 => 'LINE_TYPE_NAME'
53797                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
53798                                                                              l_component_type
53799                                                                             ,l_component_code
53800                                                                             ,l_component_type_code
53801                                                                             ,l_component_appl_id
53802                                                                             ,l_amb_context_code
53803                                                                             ,l_entity_code
53804                                                                             ,l_event_class_code
53805                                                                            )
53806                                     ,p_token_3                 => 'OWNER'
53807                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
53808                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
53809                                                                           ,p_lookup_code    => l_component_type_code
53810                                                                          )
53811                                     ,p_token_4                 => 'PRODUCT_NAME'
53812                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
53813                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
53814                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
53815                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
53816                                     ,p_ae_header_id            =>  NULL
53817                                        );
53818 
53819         IF (C_LEVEL_ERROR>= g_log_level) THEN
53820                  trace
53821                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
53822                       ,p_level    => C_LEVEL_ERROR
53823                       ,p_module   => l_log_module);
53824         END IF;
53825       END IF;
53826    END IF;
53827    --
53828    --
53829    ------------------------------------------------------------------------------------------------
53830    -- 4219869 Business Flow
53831    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
53832    -- Prior Entry.  Currently, the following code is always generated.
53833    ------------------------------------------------------------------------------------------------
53834    XLA_AE_LINES_PKG.ValidateCurrentLine;
53835 
53836    ------------------------------------------------------------------------------------
53837    -- 4219869 Business Flow
53838    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
53839    ------------------------------------------------------------------------------------
53840    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
53844    -- Update journal entry status -- Need to generate this within IF <condition>
53841 
53842    ----------------------------------------------------------------------------------
53843    -- 4219869 Business Flow
53845    ----------------------------------------------------------------------------------
53846    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
53847          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
53848          ,p_balance_type_code => l_balance_type_code
53849          );
53850 
53851    -------------------------------------------------------------------------------------------
53852    -- 4262811 - Generate the Accrual Reversal lines
53853    -------------------------------------------------------------------------------------------
53854    BEGIN
53855       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
53856                               (g_array_event(p_event_id).array_value_num('header_index'));
53857       IF l_acc_rev_flag IS NULL THEN
53858          l_acc_rev_flag := 'N';
53859       END IF;
53860    EXCEPTION
53861       WHEN OTHERS THEN
53862          l_acc_rev_flag := 'N';
53863    END;
53864    --
53865    IF (l_acc_rev_flag = 'Y') THEN
53866 
53867        -- 4645092  ------------------------------------------------------------------------------
53868        -- To allow MPA report to determine if it should generate report process
53869        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
53870        ------------------------------------------------------------------------------------------
53871 
53872        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
53873        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
53874    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
53875    -- call ADRs
53876    -- Bug 4922099
53877    --
53878    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
53879         (NVL(l_actual_upg_option, 'N') = 'O') OR
53880         (NVL(l_enc_upg_option, 'N') = 'O')
53881       )
53882    THEN
53883    NULL;
53884    --
53885    --
53886    
53887   l_ccid := AcctDerRule_173(
53888            p_application_id           => p_application_id
53889          , p_ae_header_id             => l_ae_header_id 
53890 , p_source_3 => p_source_3
53891 , p_source_30 => p_source_30
53892          , x_transaction_coa_id       => l_adr_transaction_coa_id
53893          , x_accounting_coa_id        => l_adr_accounting_coa_id
53894          , x_value_type_code          => l_adr_value_type_code
53895          , p_side                     => 'NA'
53896    );
53897 
53898    xla_ae_lines_pkg.set_ccid(
53899     p_code_combination_id          => l_ccid
53900   , p_value_type_code              => l_adr_value_type_code
53901   , p_transaction_coa_id           => l_adr_transaction_coa_id
53902   , p_accounting_coa_id            => l_adr_accounting_coa_id
53903   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
53904   , p_adr_type_code                => 'S'
53905   , p_component_type               => l_component_type
53906   , p_component_code               => l_component_code
53907   , p_component_type_code          => l_component_type_code
53908   , p_component_appl_id            => l_component_appl_id
53909   , p_amb_context_code             => l_amb_context_code
53910   , p_side                         => 'NA'
53911   );
53912 
53913 
53914    l_segment := AcctDerRule_146(
53915            p_application_id           => p_application_id
53916          , p_ae_header_id             => l_ae_header_id 
53917 , p_source_3 => p_source_3
53918 , p_source_7 => p_source_7
53919          , x_transaction_coa_id       => l_adr_transaction_coa_id
53920          , x_accounting_coa_id        => l_adr_accounting_coa_id
53921          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
53922          , x_flex_value_set_id        => l_adr_flex_value_set_id
53923          , x_value_type_code          => l_adr_value_type_code
53924          , x_value_combination_id     => l_adr_value_combination_id
53925          , x_value_segment_code       => l_adr_value_segment_code
53926          , p_side                     => 'NA'
53927          , p_override_seg_flag        => 'Y'
53928    );
53929 
53930    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
53931 
53932       xla_ae_lines_pkg.set_segment(
53933           p_to_segment_code         => 'GL_ACCOUNT'
53934         , p_segment_value           => l_segment
53935         , p_from_segment_code       => l_adr_value_segment_code
53936         , p_from_combination_id     => l_adr_value_combination_id
53937         , p_value_type_code         => l_adr_value_type_code
53938         , p_transaction_coa_id      => l_adr_transaction_coa_id
53939         , p_accounting_coa_id       => l_adr_accounting_coa_id
53940         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
53941         , p_flex_value_set_id       => l_adr_flex_value_set_id
53942         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
53943         , p_adr_type_code           => 'S'
53944         , p_component_type          => l_component_type
53945         , p_component_code          => l_component_code
53946         , p_component_type_code     => l_component_type_code
53947         , p_component_appl_id       => l_component_appl_id
53948         , p_amb_context_code        => l_amb_context_code
53949         , p_entity_code             => 'TRANSACTIONS'
53950         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
53951         , p_side                    => 'NA'
53952         );
53953 
53954   END IF;
53955 
53956    l_segment := AcctDerRule_168(
53957            p_application_id           => p_application_id
53958          , p_ae_header_id             => l_ae_header_id 
53959 , p_source_3 => p_source_3
53960 , p_source_29 => p_source_29
53961          , x_transaction_coa_id       => l_adr_transaction_coa_id
53965          , x_value_type_code          => l_adr_value_type_code
53962          , x_accounting_coa_id        => l_adr_accounting_coa_id
53963          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
53964          , x_flex_value_set_id        => l_adr_flex_value_set_id
53966          , x_value_combination_id     => l_adr_value_combination_id
53967          , x_value_segment_code       => l_adr_value_segment_code
53968          , p_side                     => 'NA'
53969          , p_override_seg_flag        => 'Y'
53970    );
53971 
53972    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
53973 
53974       xla_ae_lines_pkg.set_segment(
53975           p_to_segment_code         => 'GL_BALANCING'
53976         , p_segment_value           => l_segment
53977         , p_from_segment_code       => l_adr_value_segment_code
53978         , p_from_combination_id     => l_adr_value_combination_id
53979         , p_value_type_code         => l_adr_value_type_code
53980         , p_transaction_coa_id      => l_adr_transaction_coa_id
53981         , p_accounting_coa_id       => l_adr_accounting_coa_id
53982         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
53983         , p_flex_value_set_id       => l_adr_flex_value_set_id
53984         , p_adr_code                => 'FA_EXPENSE_ACCT'
53985         , p_adr_type_code           => 'S'
53986         , p_component_type          => l_component_type
53987         , p_component_code          => l_component_code
53988         , p_component_type_code     => l_component_type_code
53989         , p_component_appl_id       => l_component_appl_id
53990         , p_amb_context_code        => l_amb_context_code
53991         , p_entity_code             => 'TRANSACTIONS'
53992         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
53993         , p_side                    => 'NA'
53994         );
53995 
53996   END IF;
53997 
53998    --
53999    --
54000    END IF;
54001 
54002        --
54003        -- Update the line information that should be overwritten
54004        --
54005        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
54006                                          p_header_num   => 1);
54007        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
54008 
54009        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
54010 
54011        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
54012           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
54013        END IF;
54014 
54015       --
54016       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
54017       --
54018       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
54019           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
54020       ELSE
54021           ---------------------------------------------------------------------------------------------------
54022           -- 4262811a Switch Sign
54023           ---------------------------------------------------------------------------------------------------
54024           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
54025           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
54026                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54027           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
54028                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54029           -- 5132302
54030           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
54031                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54032 
54033       END IF;
54034 
54035       -- 4955764
54036       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
54037       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
54038 
54039 
54040       XLA_AE_LINES_PKG.ValidateCurrentLine;
54041       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
54042 
54043       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
54044                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
54045                ,p_balance_type_code => l_balance_type_code);
54046 
54047    END IF;
54048 
54049    -----------------------------------------------------------------------------------------
54050    -- 4262811 Multiperiod Accounting
54051    -----------------------------------------------------------------------------------------
54052      -- No MPA option is assigned.
54053 
54054 
54055 END IF;
54056 END IF;
54057 --
54058 
54059 --
54060 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54061    trace
54062       (p_msg      => 'END of AcctLineType_229'
54063       ,p_level    => C_LEVEL_PROCEDURE
54064       ,p_module   => l_log_module);
54065 END IF;
54066 --
54067 EXCEPTION
54068   WHEN xla_exceptions_pkg.application_exception THEN
54069       RAISE;
54070   WHEN OTHERS THEN
54071        xla_exceptions_pkg.raise_message
54072            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_229');
54073 END AcctLineType_229;
54074 --
54075 
54076 ---------------------------------------
54077 --
54078 -- PRIVATE FUNCTION
54079 --         AcctLineType_230
54080 --
54081 ---------------------------------------
54082 PROCEDURE AcctLineType_230 (
54083   p_application_id        IN NUMBER
54084  ,p_event_id              IN NUMBER
54085  ,p_calculate_acctd_flag  IN VARCHAR2
54089  ,p_gain_or_loss_ref      OUT VARCHAR2
54086  ,p_calculate_g_l_flag    IN VARCHAR2
54087  ,p_actual_flag           IN OUT VARCHAR2
54088  ,p_balance_type_code     OUT VARCHAR2
54090  
54091 --Period Close Date
54092  , p_source_1            IN DATE
54093 --Generated Code Combination Identifier
54094  , p_source_3            IN NUMBER
54095 --Revaluation Reserve Account
54096  , p_source_11            IN VARCHAR2
54097 --Expense Account Code Combination Identifier
54098  , p_source_29            IN NUMBER
54099 --Default Code Combination Identifier
54100  , p_source_30            IN NUMBER
54101 --Adjustment Type
54102  , p_source_35            IN VARCHAR2
54103 --Transaction Header Identifier
54104  , p_source_36            IN NUMBER
54105 --Adjustment Line Identifier
54106  , p_source_37            IN NUMBER
54107 --Distribution Type Code
54108  , p_source_38            IN VARCHAR2
54109 --Entered Amount
54110  , p_source_39            IN NUMBER
54111 --Currency Code
54112  , p_source_40            IN VARCHAR2
54113 --Source Destination Code
54114  , p_source_42            IN VARCHAR2
54115 )
54116 IS
54117 
54118 l_component_type              VARCHAR2(80);
54119 l_component_code              VARCHAR2(30);
54120 l_component_type_code         VARCHAR2(1);
54121 l_component_appl_id           INTEGER;
54122 l_amb_context_code            VARCHAR2(30);
54123 l_entity_code                 VARCHAR2(30);
54124 l_event_class_code            VARCHAR2(30);
54125 l_ae_header_id                NUMBER;
54126 l_event_type_code             VARCHAR2(30);
54127 l_line_definition_code        VARCHAR2(30);
54128 l_line_definition_owner_code  VARCHAR2(1);
54129 --
54130 -- adr variables
54131 l_segment                     VARCHAR2(30);
54132 l_ccid                        NUMBER;
54133 l_adr_transaction_coa_id      NUMBER;
54134 l_adr_accounting_coa_id       NUMBER;
54135 l_adr_flexfield_segment_code  VARCHAR2(30);
54136 l_adr_flex_value_set_id       NUMBER;
54137 l_adr_value_type_code         VARCHAR2(30);
54138 l_adr_value_combination_id    NUMBER;
54139 l_adr_value_segment_code      VARCHAR2(30);
54140 
54141 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
54142 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
54143 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
54144 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
54145 
54146 -- 4262811 Variables ------------------------------------------------------------------------------------------
54147 l_entered_amt_idx             NUMBER;
54148 l_accted_amt_idx              NUMBER;
54149 l_acc_rev_flag                VARCHAR2(1);
54150 l_accrual_line_num            NUMBER;
54151 l_tmp_amt                     NUMBER;
54152 l_acc_rev_natural_side_code   VARCHAR2(1);
54153 
54154 l_num_entries                 NUMBER;
54155 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
54156 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
54157 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
54158 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
54159 l_recog_line_1                NUMBER;
54160 l_recog_line_2                NUMBER;
54161 
54162 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
54163 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
54164 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
54165 
54166 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
54167 
54168 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
54169 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
54170 
54171 ---------------------------------------------------------------------------------------------------------------
54172 
54173 
54174 --
54175 -- bulk performance
54176 --
54177 l_balance_type_code           VARCHAR2(1);
54178 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
54179 l_log_module                  VARCHAR2(240);
54180 
54181 --
54182 -- Upgrade strategy
54183 --
54184 l_actual_upg_option           VARCHAR2(1);
54185 l_enc_upg_option           VARCHAR2(1);
54186 
54187 --
54188 BEGIN
54189 --
54190 IF g_log_enabled THEN
54191       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_230';
54192 END IF;
54193 --
54194 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54195 
54196       trace
54197          (p_msg      => 'BEGIN of AcctLineType_230'
54198          ,p_level    => C_LEVEL_PROCEDURE
54199          ,p_module   => l_log_module);
54200 
54201 END IF;
54202 --
54203 l_component_type             := 'AMB_JLT';
54204 l_component_code             := 'FA_CIP_RECLASS_SRC_REVAL_RES';
54205 l_component_type_code        := 'S';
54206 l_component_appl_id          :=  140;
54207 l_amb_context_code           := 'DEFAULT';
54208 l_entity_code                := 'TRANSACTIONS';
54209 l_event_class_code           := 'CIP_CATEGORY_RECLASS';
54210 l_event_type_code            := 'CIP_CATEGORY_RECLASS_ALL';
54211 l_line_definition_owner_code := 'S';
54212 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_CA7';
54213 --
54214 l_balance_type_code          := 'A';
54215 l_segment                     := NULL;
54216 l_ccid                        := NULL;
54217 l_adr_transaction_coa_id      := NULL;
54218 l_adr_accounting_coa_id       := NULL;
54219 l_adr_flexfield_segment_code  := NULL;
54220 l_adr_flex_value_set_id       := NULL;
54221 l_adr_value_type_code         := NULL;
54222 l_adr_value_combination_id    := NULL;
54223 l_adr_value_segment_code      := NULL;
54224 
54225 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
54229 
54226 l_bflow_class_code           := '';    -- 4219869 Business Flow
54227 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
54228 l_budgetary_control_flag     := 'N';
54230 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
54231 l_bflow_applied_to_amt       := NULL; -- 5132302
54232 l_entered_amt_idx            := NULL;          -- 4262811
54233 l_accted_amt_idx             := NULL;          -- 4262811
54234 l_acc_rev_flag               := NULL;          -- 4262811
54235 l_accrual_line_num           := NULL;          -- 4262811
54236 l_tmp_amt                    := NULL;          -- 4262811
54237 --
54238  
54239 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
54240     l_balance_type_code <> 'B' THEN
54241 IF NVL(p_source_35,'
54242 ') =  'REVAL RESERVE' AND 
54243 NVL(p_source_42,'
54244 ') =  'SOURCE'
54245  THEN 
54246 
54247    --
54248    XLA_AE_LINES_PKG.SetNewLine;
54249 
54250    p_balance_type_code          := l_balance_type_code;
54251    -- set the flag so later we will know whether the gain loss line needs to be created
54252    
54253    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
54254      p_actual_flag :='A';
54255    END IF;
54256 
54257    --
54258    -- bulk performance
54259    --
54260    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
54261                                       p_header_num   => 0); -- 4262811
54262    --
54263    -- set accounting line options
54264    --
54265    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
54266            p_natural_side_code          => 'D'
54267          , p_gain_or_loss_flag          => 'N'
54268          , p_gl_transfer_mode_code      => 'S'
54269          , p_acct_entry_type_code       => 'A'
54270          , p_switch_side_flag           => 'Y'
54271          , p_merge_duplicate_code       => 'N'
54272          );
54273    --
54274    l_acc_rev_natural_side_code := 'C';  -- 4262811
54275    -- 
54276    --
54277    -- set accounting line type info
54278    --
54279    xla_ae_lines_pkg.SetAcctLineType
54280       (p_component_type             => l_component_type
54281       ,p_event_type_code            => l_event_type_code
54282       ,p_line_definition_owner_code => l_line_definition_owner_code
54283       ,p_line_definition_code       => l_line_definition_code
54284       ,p_accounting_line_code       => l_component_code
54285       ,p_accounting_line_type_code  => l_component_type_code
54286       ,p_accounting_line_appl_id    => l_component_appl_id
54287       ,p_amb_context_code           => l_amb_context_code
54288       ,p_entity_code                => l_entity_code
54289       ,p_event_class_code           => l_event_class_code);
54290    --
54291    -- set accounting class
54292    --
54293    xla_ae_lines_pkg.SetAcctClass(
54294            p_accounting_class_code  => 'ASSET'
54295          , p_ae_header_id           => l_ae_header_id
54296          );
54297 
54298    --
54299    -- set rounding class
54300    --
54301    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
54302                       'ASSET';
54303 
54304    --
54305    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
54306    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
54307    --
54308    -- bulk performance
54309    --
54310    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
54311 
54312    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
54313       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
54314 
54315    -- 4955764
54316    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
54317       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
54318 
54319    -- 4458381 Public Sector Enh
54320    
54321    --
54322    -- set accounting attributes for the line type
54323    --
54324    l_entered_amt_idx := 4;
54325    l_accted_amt_idx  := 6;
54326    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
54327    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
54328    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
54329    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
54330    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
54331    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
54332    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
54333    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
54334    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
54335    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
54336    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
54337    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
54338    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
54339 
54340    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
54341    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
54342 
54343    ---------------------------------------------------------------------------------------------------------------
54344    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
54345    ---------------------------------------------------------------------------------------------------------------
54346    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
54347 
54348    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
54349    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
54353          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
54350 
54351    IF xla_accounting_cache_pkg.GetValueChar
54352          (p_source_code         => 'LEDGER_CATEGORY_CODE'
54354    AND l_bflow_method_code = 'PRIOR_ENTRY'
54355 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
54356    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
54357          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
54358        )
54359    THEN
54360          xla_ae_lines_pkg.BflowUpgEntry
54361            (p_business_method_code    => l_bflow_method_code
54362            ,p_business_class_code     => l_bflow_class_code
54363            ,p_balance_type            => l_balance_type_code);
54364    ELSE
54365       NULL;
54366 -- No business flow processing for business flow method of NONE.
54367    END IF;
54368 
54369    --
54370    -- call analytical criteria
54371    --
54372    
54373    --
54374    -- call description
54375    --
54376    
54377 xla_ae_lines_pkg.SetLineDescription(
54378    p_ae_header_id => l_ae_header_id
54379   ,p_description  => Description_30 (
54380      p_application_id         => p_application_id
54381    , p_ae_header_id           => l_ae_header_id 
54382 , p_source_1 => p_source_1
54383    )
54384 );
54385 
54386 
54387    --
54388    -- call ADRs
54389    -- Bug 4922099
54390    --
54391    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
54392         (NVL(l_actual_upg_option, 'N') = 'O') OR
54393         (NVL(l_enc_upg_option, 'N') = 'O')
54394       )
54395    THEN
54396    NULL;
54397    --
54398    --
54399    
54400   l_ccid := AcctDerRule_173(
54401            p_application_id           => p_application_id
54402          , p_ae_header_id             => l_ae_header_id 
54403 , p_source_3 => p_source_3
54404 , p_source_30 => p_source_30
54405          , x_transaction_coa_id       => l_adr_transaction_coa_id
54406          , x_accounting_coa_id        => l_adr_accounting_coa_id
54407          , x_value_type_code          => l_adr_value_type_code
54408          , p_side                     => 'NA'
54409    );
54410 
54411    xla_ae_lines_pkg.set_ccid(
54412     p_code_combination_id          => l_ccid
54413   , p_value_type_code              => l_adr_value_type_code
54414   , p_transaction_coa_id           => l_adr_transaction_coa_id
54415   , p_accounting_coa_id            => l_adr_accounting_coa_id
54416   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
54417   , p_adr_type_code                => 'S'
54418   , p_component_type               => l_component_type
54419   , p_component_code               => l_component_code
54420   , p_component_type_code          => l_component_type_code
54421   , p_component_appl_id            => l_component_appl_id
54422   , p_amb_context_code             => l_amb_context_code
54423   , p_side                         => 'NA'
54424   );
54425 
54426 
54427    l_segment := AcctDerRule_150(
54428            p_application_id           => p_application_id
54429          , p_ae_header_id             => l_ae_header_id 
54430 , p_source_3 => p_source_3
54431 , p_source_11 => p_source_11
54432          , x_transaction_coa_id       => l_adr_transaction_coa_id
54433          , x_accounting_coa_id        => l_adr_accounting_coa_id
54434          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
54435          , x_flex_value_set_id        => l_adr_flex_value_set_id
54436          , x_value_type_code          => l_adr_value_type_code
54437          , x_value_combination_id     => l_adr_value_combination_id
54438          , x_value_segment_code       => l_adr_value_segment_code
54439          , p_side                     => 'NA'
54440          , p_override_seg_flag        => 'Y'
54441    );
54442 
54443    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
54444 
54445       xla_ae_lines_pkg.set_segment(
54446           p_to_segment_code         => 'GL_ACCOUNT'
54447         , p_segment_value           => l_segment
54448         , p_from_segment_code       => l_adr_value_segment_code
54449         , p_from_combination_id     => l_adr_value_combination_id
54450         , p_value_type_code         => l_adr_value_type_code
54451         , p_transaction_coa_id      => l_adr_transaction_coa_id
54452         , p_accounting_coa_id       => l_adr_accounting_coa_id
54453         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
54454         , p_flex_value_set_id       => l_adr_flex_value_set_id
54455         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
54456         , p_adr_type_code           => 'S'
54457         , p_component_type          => l_component_type
54458         , p_component_code          => l_component_code
54459         , p_component_type_code     => l_component_type_code
54460         , p_component_appl_id       => l_component_appl_id
54461         , p_amb_context_code        => l_amb_context_code
54462         , p_entity_code             => 'TRANSACTIONS'
54463         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
54464         , p_side                    => 'NA'
54465         );
54466 
54467   END IF;
54468 
54469    l_segment := AcctDerRule_168(
54470            p_application_id           => p_application_id
54471          , p_ae_header_id             => l_ae_header_id 
54472 , p_source_3 => p_source_3
54473 , p_source_29 => p_source_29
54474          , x_transaction_coa_id       => l_adr_transaction_coa_id
54475          , x_accounting_coa_id        => l_adr_accounting_coa_id
54476          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
54477          , x_flex_value_set_id        => l_adr_flex_value_set_id
54478          , x_value_type_code          => l_adr_value_type_code
54479          , x_value_combination_id     => l_adr_value_combination_id
54480          , x_value_segment_code       => l_adr_value_segment_code
54484 
54481          , p_side                     => 'NA'
54482          , p_override_seg_flag        => 'Y'
54483    );
54485    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
54486 
54487       xla_ae_lines_pkg.set_segment(
54488           p_to_segment_code         => 'GL_BALANCING'
54489         , p_segment_value           => l_segment
54490         , p_from_segment_code       => l_adr_value_segment_code
54491         , p_from_combination_id     => l_adr_value_combination_id
54492         , p_value_type_code         => l_adr_value_type_code
54493         , p_transaction_coa_id      => l_adr_transaction_coa_id
54494         , p_accounting_coa_id       => l_adr_accounting_coa_id
54495         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
54496         , p_flex_value_set_id       => l_adr_flex_value_set_id
54497         , p_adr_code                => 'FA_EXPENSE_ACCT'
54498         , p_adr_type_code           => 'S'
54499         , p_component_type          => l_component_type
54500         , p_component_code          => l_component_code
54501         , p_component_type_code     => l_component_type_code
54502         , p_component_appl_id       => l_component_appl_id
54503         , p_amb_context_code        => l_amb_context_code
54504         , p_entity_code             => 'TRANSACTIONS'
54505         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
54506         , p_side                    => 'NA'
54507         );
54508 
54509   END IF;
54510 
54511    --
54512    --
54513    END IF;
54514    --
54515    -- Bug 4922099
54516    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
54517           (NVL(l_enc_upg_option, 'N') = 'O')
54518         ) AND
54519         (l_bflow_method_code = 'PRIOR_ENTRY')
54520       )
54521    THEN
54522       IF
54523       --
54524       1 = 2
54525       --
54526       THEN
54527       xla_accounting_err_pkg.build_message
54528                                     (p_appli_s_name            => 'XLA'
54529                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
54530                                     ,p_token_1                 => 'LINE_NUMBER'
54531                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
54532                                     ,p_token_2                 => 'LINE_TYPE_NAME'
54533                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
54534                                                                              l_component_type
54535                                                                             ,l_component_code
54536                                                                             ,l_component_type_code
54537                                                                             ,l_component_appl_id
54538                                                                             ,l_amb_context_code
54539                                                                             ,l_entity_code
54540                                                                             ,l_event_class_code
54541                                                                            )
54542                                     ,p_token_3                 => 'OWNER'
54543                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
54544                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
54545                                                                           ,p_lookup_code    => l_component_type_code
54546                                                                          )
54547                                     ,p_token_4                 => 'PRODUCT_NAME'
54548                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
54549                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
54550                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
54551                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
54552                                     ,p_ae_header_id            =>  NULL
54553                                        );
54554 
54555         IF (C_LEVEL_ERROR>= g_log_level) THEN
54556                  trace
54557                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
54558                       ,p_level    => C_LEVEL_ERROR
54559                       ,p_module   => l_log_module);
54560         END IF;
54561       END IF;
54562    END IF;
54563    --
54564    --
54565    ------------------------------------------------------------------------------------------------
54566    -- 4219869 Business Flow
54567    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
54568    -- Prior Entry.  Currently, the following code is always generated.
54569    ------------------------------------------------------------------------------------------------
54570    XLA_AE_LINES_PKG.ValidateCurrentLine;
54571 
54572    ------------------------------------------------------------------------------------
54573    -- 4219869 Business Flow
54574    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
54575    ------------------------------------------------------------------------------------
54576    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
54577 
54578    ----------------------------------------------------------------------------------
54579    -- 4219869 Business Flow
54580    -- Update journal entry status -- Need to generate this within IF <condition>
54581    ----------------------------------------------------------------------------------
54582    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
54583          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
54584          ,p_balance_type_code => l_balance_type_code
54588    -- 4262811 - Generate the Accrual Reversal lines
54585          );
54586 
54587    -------------------------------------------------------------------------------------------
54589    -------------------------------------------------------------------------------------------
54590    BEGIN
54591       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
54592                               (g_array_event(p_event_id).array_value_num('header_index'));
54593       IF l_acc_rev_flag IS NULL THEN
54594          l_acc_rev_flag := 'N';
54595       END IF;
54596    EXCEPTION
54597       WHEN OTHERS THEN
54598          l_acc_rev_flag := 'N';
54599    END;
54600    --
54601    IF (l_acc_rev_flag = 'Y') THEN
54602 
54603        -- 4645092  ------------------------------------------------------------------------------
54604        -- To allow MPA report to determine if it should generate report process
54605        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
54606        ------------------------------------------------------------------------------------------
54607 
54608        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
54609        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
54610    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
54611    -- call ADRs
54612    -- Bug 4922099
54613    --
54614    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
54615         (NVL(l_actual_upg_option, 'N') = 'O') OR
54616         (NVL(l_enc_upg_option, 'N') = 'O')
54617       )
54618    THEN
54619    NULL;
54620    --
54621    --
54622    
54623   l_ccid := AcctDerRule_173(
54624            p_application_id           => p_application_id
54625          , p_ae_header_id             => l_ae_header_id 
54626 , p_source_3 => p_source_3
54627 , p_source_30 => p_source_30
54628          , x_transaction_coa_id       => l_adr_transaction_coa_id
54629          , x_accounting_coa_id        => l_adr_accounting_coa_id
54630          , x_value_type_code          => l_adr_value_type_code
54631          , p_side                     => 'NA'
54632    );
54633 
54634    xla_ae_lines_pkg.set_ccid(
54635     p_code_combination_id          => l_ccid
54636   , p_value_type_code              => l_adr_value_type_code
54637   , p_transaction_coa_id           => l_adr_transaction_coa_id
54638   , p_accounting_coa_id            => l_adr_accounting_coa_id
54639   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
54640   , p_adr_type_code                => 'S'
54641   , p_component_type               => l_component_type
54642   , p_component_code               => l_component_code
54643   , p_component_type_code          => l_component_type_code
54644   , p_component_appl_id            => l_component_appl_id
54645   , p_amb_context_code             => l_amb_context_code
54646   , p_side                         => 'NA'
54647   );
54648 
54649 
54650    l_segment := AcctDerRule_150(
54651            p_application_id           => p_application_id
54652          , p_ae_header_id             => l_ae_header_id 
54653 , p_source_3 => p_source_3
54654 , p_source_11 => p_source_11
54655          , x_transaction_coa_id       => l_adr_transaction_coa_id
54656          , x_accounting_coa_id        => l_adr_accounting_coa_id
54657          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
54658          , x_flex_value_set_id        => l_adr_flex_value_set_id
54659          , x_value_type_code          => l_adr_value_type_code
54660          , x_value_combination_id     => l_adr_value_combination_id
54661          , x_value_segment_code       => l_adr_value_segment_code
54662          , p_side                     => 'NA'
54663          , p_override_seg_flag        => 'Y'
54664    );
54665 
54666    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
54667 
54668       xla_ae_lines_pkg.set_segment(
54669           p_to_segment_code         => 'GL_ACCOUNT'
54670         , p_segment_value           => l_segment
54671         , p_from_segment_code       => l_adr_value_segment_code
54672         , p_from_combination_id     => l_adr_value_combination_id
54673         , p_value_type_code         => l_adr_value_type_code
54674         , p_transaction_coa_id      => l_adr_transaction_coa_id
54675         , p_accounting_coa_id       => l_adr_accounting_coa_id
54676         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
54677         , p_flex_value_set_id       => l_adr_flex_value_set_id
54678         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
54679         , p_adr_type_code           => 'S'
54680         , p_component_type          => l_component_type
54681         , p_component_code          => l_component_code
54682         , p_component_type_code     => l_component_type_code
54683         , p_component_appl_id       => l_component_appl_id
54684         , p_amb_context_code        => l_amb_context_code
54685         , p_entity_code             => 'TRANSACTIONS'
54686         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
54687         , p_side                    => 'NA'
54688         );
54689 
54690   END IF;
54691 
54692    l_segment := AcctDerRule_168(
54693            p_application_id           => p_application_id
54694          , p_ae_header_id             => l_ae_header_id 
54695 , p_source_3 => p_source_3
54696 , p_source_29 => p_source_29
54697          , x_transaction_coa_id       => l_adr_transaction_coa_id
54698          , x_accounting_coa_id        => l_adr_accounting_coa_id
54699          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
54700          , x_flex_value_set_id        => l_adr_flex_value_set_id
54701          , x_value_type_code          => l_adr_value_type_code
54702          , x_value_combination_id     => l_adr_value_combination_id
54703          , x_value_segment_code       => l_adr_value_segment_code
54704          , p_side                     => 'NA'
54705          , p_override_seg_flag        => 'Y'
54706    );
54707 
54711           p_to_segment_code         => 'GL_BALANCING'
54708    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
54709 
54710       xla_ae_lines_pkg.set_segment(
54712         , p_segment_value           => l_segment
54713         , p_from_segment_code       => l_adr_value_segment_code
54714         , p_from_combination_id     => l_adr_value_combination_id
54715         , p_value_type_code         => l_adr_value_type_code
54716         , p_transaction_coa_id      => l_adr_transaction_coa_id
54717         , p_accounting_coa_id       => l_adr_accounting_coa_id
54718         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
54719         , p_flex_value_set_id       => l_adr_flex_value_set_id
54720         , p_adr_code                => 'FA_EXPENSE_ACCT'
54721         , p_adr_type_code           => 'S'
54722         , p_component_type          => l_component_type
54723         , p_component_code          => l_component_code
54724         , p_component_type_code     => l_component_type_code
54725         , p_component_appl_id       => l_component_appl_id
54726         , p_amb_context_code        => l_amb_context_code
54727         , p_entity_code             => 'TRANSACTIONS'
54728         , p_event_class_code        => 'CIP_CATEGORY_RECLASS'
54729         , p_side                    => 'NA'
54730         );
54731 
54732   END IF;
54733 
54734    --
54735    --
54736    END IF;
54737 
54738        --
54739        -- Update the line information that should be overwritten
54740        --
54741        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
54742                                          p_header_num   => 1);
54743        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
54744 
54745        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
54746 
54747        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
54748           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
54749        END IF;
54750 
54751       --
54752       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
54753       --
54754       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
54755           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
54756       ELSE
54757           ---------------------------------------------------------------------------------------------------
54758           -- 4262811a Switch Sign
54759           ---------------------------------------------------------------------------------------------------
54760           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
54761           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
54762                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54763           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
54764                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54765           -- 5132302
54766           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
54767                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54768 
54769       END IF;
54770 
54771       -- 4955764
54772       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
54773       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
54774 
54775 
54776       XLA_AE_LINES_PKG.ValidateCurrentLine;
54777       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
54778 
54779       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
54780                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
54781                ,p_balance_type_code => l_balance_type_code);
54782 
54783    END IF;
54784 
54785    -----------------------------------------------------------------------------------------
54786    -- 4262811 Multiperiod Accounting
54787    -----------------------------------------------------------------------------------------
54788      -- No MPA option is assigned.
54789 
54790 
54791 END IF;
54792 END IF;
54793 --
54794 
54795 --
54796 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54797    trace
54798       (p_msg      => 'END of AcctLineType_230'
54799       ,p_level    => C_LEVEL_PROCEDURE
54800       ,p_module   => l_log_module);
54801 END IF;
54802 --
54803 EXCEPTION
54804   WHEN xla_exceptions_pkg.application_exception THEN
54805       RAISE;
54806   WHEN OTHERS THEN
54807        xla_exceptions_pkg.raise_message
54808            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_230');
54809 END AcctLineType_230;
54810 --
54811 
54812 ---------------------------------------
54813 --
54814 -- PRIVATE FUNCTION
54815 --         AcctLineType_231
54816 --
54817 ---------------------------------------
54818 PROCEDURE AcctLineType_231 (
54819   p_application_id        IN NUMBER
54820  ,p_event_id              IN NUMBER
54821  ,p_calculate_acctd_flag  IN VARCHAR2
54822  ,p_calculate_g_l_flag    IN VARCHAR2
54823  ,p_actual_flag           IN OUT VARCHAR2
54824  ,p_balance_type_code     OUT VARCHAR2
54825  ,p_gain_or_loss_ref      OUT VARCHAR2
54826  
54827 --Period Close Date
54828  , p_source_1            IN DATE
54829 --Generated Code Combination Identifier
54830  , p_source_3            IN NUMBER
54831 --CIP Cost Account
54832  , p_source_7            IN VARCHAR2
54833 --Expense Account Code Combination Identifier
54834  , p_source_29            IN NUMBER
54835 --Default Code Combination Identifier
54839 --Transaction Header Identifier
54836  , p_source_30            IN NUMBER
54837 --Adjustment Type
54838  , p_source_35            IN VARCHAR2
54840  , p_source_36            IN NUMBER
54841 --Adjustment Line Identifier
54842  , p_source_37            IN NUMBER
54843 --Distribution Type Code
54844  , p_source_38            IN VARCHAR2
54845 --Entered Amount
54846  , p_source_39            IN NUMBER
54847 --Currency Code
54848  , p_source_40            IN VARCHAR2
54849 )
54850 IS
54851 
54852 l_component_type              VARCHAR2(80);
54853 l_component_code              VARCHAR2(30);
54854 l_component_type_code         VARCHAR2(1);
54855 l_component_appl_id           INTEGER;
54856 l_amb_context_code            VARCHAR2(30);
54857 l_entity_code                 VARCHAR2(30);
54858 l_event_class_code            VARCHAR2(30);
54859 l_ae_header_id                NUMBER;
54860 l_event_type_code             VARCHAR2(30);
54861 l_line_definition_code        VARCHAR2(30);
54862 l_line_definition_owner_code  VARCHAR2(1);
54863 --
54864 -- adr variables
54865 l_segment                     VARCHAR2(30);
54866 l_ccid                        NUMBER;
54867 l_adr_transaction_coa_id      NUMBER;
54868 l_adr_accounting_coa_id       NUMBER;
54869 l_adr_flexfield_segment_code  VARCHAR2(30);
54870 l_adr_flex_value_set_id       NUMBER;
54871 l_adr_value_type_code         VARCHAR2(30);
54872 l_adr_value_combination_id    NUMBER;
54873 l_adr_value_segment_code      VARCHAR2(30);
54874 
54875 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
54876 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
54877 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
54878 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
54879 
54880 -- 4262811 Variables ------------------------------------------------------------------------------------------
54881 l_entered_amt_idx             NUMBER;
54882 l_accted_amt_idx              NUMBER;
54883 l_acc_rev_flag                VARCHAR2(1);
54884 l_accrual_line_num            NUMBER;
54885 l_tmp_amt                     NUMBER;
54886 l_acc_rev_natural_side_code   VARCHAR2(1);
54887 
54888 l_num_entries                 NUMBER;
54889 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
54890 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
54891 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
54892 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
54893 l_recog_line_1                NUMBER;
54894 l_recog_line_2                NUMBER;
54895 
54896 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
54897 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
54898 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
54899 
54900 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
54901 
54902 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
54903 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
54904 
54905 ---------------------------------------------------------------------------------------------------------------
54906 
54907 
54908 --
54909 -- bulk performance
54910 --
54911 l_balance_type_code           VARCHAR2(1);
54912 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
54913 l_log_module                  VARCHAR2(240);
54914 
54915 --
54916 -- Upgrade strategy
54917 --
54918 l_actual_upg_option           VARCHAR2(1);
54919 l_enc_upg_option           VARCHAR2(1);
54920 
54921 --
54922 BEGIN
54923 --
54924 IF g_log_enabled THEN
54925       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_231';
54926 END IF;
54927 --
54928 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54929 
54930       trace
54931          (p_msg      => 'BEGIN of AcctLineType_231'
54932          ,p_level    => C_LEVEL_PROCEDURE
54933          ,p_module   => l_log_module);
54934 
54935 END IF;
54936 --
54937 l_component_type             := 'AMB_JLT';
54938 l_component_code             := 'FA_CIP_RETIREMENT_COST';
54939 l_component_type_code        := 'S';
54940 l_component_appl_id          :=  140;
54941 l_amb_context_code           := 'DEFAULT';
54942 l_entity_code                := 'TRANSACTIONS';
54943 l_event_class_code           := 'CIP_RETIREMENTS';
54944 l_event_type_code            := 'CIP_REINSTATEMENTS';
54945 l_line_definition_owner_code := 'S';
54946 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
54947 --
54948 l_balance_type_code          := 'A';
54949 l_segment                     := NULL;
54950 l_ccid                        := NULL;
54951 l_adr_transaction_coa_id      := NULL;
54952 l_adr_accounting_coa_id       := NULL;
54953 l_adr_flexfield_segment_code  := NULL;
54954 l_adr_flex_value_set_id       := NULL;
54955 l_adr_value_type_code         := NULL;
54956 l_adr_value_combination_id    := NULL;
54957 l_adr_value_segment_code      := NULL;
54958 
54959 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
54960 l_bflow_class_code           := '';    -- 4219869 Business Flow
54961 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
54962 l_budgetary_control_flag     := 'N';
54963 
54964 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
54965 l_bflow_applied_to_amt       := NULL; -- 5132302
54966 l_entered_amt_idx            := NULL;          -- 4262811
54967 l_accted_amt_idx             := NULL;          -- 4262811
54968 l_acc_rev_flag               := NULL;          -- 4262811
54969 l_accrual_line_num           := NULL;          -- 4262811
54970 l_tmp_amt                    := NULL;          -- 4262811
54971 --
54972  
54976 ') =  'CIP COST'
54973 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
54974     l_balance_type_code <> 'B' THEN
54975 IF NVL(p_source_35,'
54977  THEN 
54978 
54979    --
54980    XLA_AE_LINES_PKG.SetNewLine;
54981 
54982    p_balance_type_code          := l_balance_type_code;
54983    -- set the flag so later we will know whether the gain loss line needs to be created
54984    
54985    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
54986      p_actual_flag :='A';
54987    END IF;
54988 
54989    --
54990    -- bulk performance
54991    --
54992    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
54993                                       p_header_num   => 0); -- 4262811
54994    --
54995    -- set accounting line options
54996    --
54997    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
54998            p_natural_side_code          => 'C'
54999          , p_gain_or_loss_flag          => 'N'
55000          , p_gl_transfer_mode_code      => 'S'
55001          , p_acct_entry_type_code       => 'A'
55002          , p_switch_side_flag           => 'Y'
55003          , p_merge_duplicate_code       => 'N'
55004          );
55005    --
55006    l_acc_rev_natural_side_code := 'D';  -- 4262811
55007    -- 
55008    --
55009    -- set accounting line type info
55010    --
55011    xla_ae_lines_pkg.SetAcctLineType
55012       (p_component_type             => l_component_type
55013       ,p_event_type_code            => l_event_type_code
55014       ,p_line_definition_owner_code => l_line_definition_owner_code
55015       ,p_line_definition_code       => l_line_definition_code
55016       ,p_accounting_line_code       => l_component_code
55017       ,p_accounting_line_type_code  => l_component_type_code
55018       ,p_accounting_line_appl_id    => l_component_appl_id
55019       ,p_amb_context_code           => l_amb_context_code
55020       ,p_entity_code                => l_entity_code
55021       ,p_event_class_code           => l_event_class_code);
55022    --
55023    -- set accounting class
55024    --
55025    xla_ae_lines_pkg.SetAcctClass(
55026            p_accounting_class_code  => 'ASSET'
55027          , p_ae_header_id           => l_ae_header_id
55028          );
55029 
55030    --
55031    -- set rounding class
55032    --
55033    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
55034                       'ASSET';
55035 
55036    --
55037    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
55038    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
55039    --
55040    -- bulk performance
55041    --
55042    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
55043 
55044    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
55045       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
55046 
55047    -- 4955764
55048    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
55049       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
55050 
55051    -- 4458381 Public Sector Enh
55052    
55053    --
55054    -- set accounting attributes for the line type
55055    --
55056    l_entered_amt_idx := 4;
55057    l_accted_amt_idx  := 6;
55058    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
55059    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
55060    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
55061    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
55062    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
55063    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
55064    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
55065    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
55066    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
55067    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
55068    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
55069    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
55070    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
55071 
55072    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
55073    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
55074 
55075    ---------------------------------------------------------------------------------------------------------------
55076    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
55077    ---------------------------------------------------------------------------------------------------------------
55078    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
55079 
55080    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
55081    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
55082 
55083    IF xla_accounting_cache_pkg.GetValueChar
55084          (p_source_code         => 'LEDGER_CATEGORY_CODE'
55085          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
55086    AND l_bflow_method_code = 'PRIOR_ENTRY'
55087 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
55088    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
55089          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
55090        )
55091    THEN
55092          xla_ae_lines_pkg.BflowUpgEntry
55093            (p_business_method_code    => l_bflow_method_code
55094            ,p_business_class_code     => l_bflow_class_code
55098 -- No business flow processing for business flow method of NONE.
55095            ,p_balance_type            => l_balance_type_code);
55096    ELSE
55097       NULL;
55099    END IF;
55100 
55101    --
55102    -- call analytical criteria
55103    --
55104    
55105    --
55106    -- call description
55107    --
55108    
55109 xla_ae_lines_pkg.SetLineDescription(
55110    p_ae_header_id => l_ae_header_id
55111   ,p_description  => Description_33 (
55112      p_application_id         => p_application_id
55113    , p_ae_header_id           => l_ae_header_id 
55114 , p_source_1 => p_source_1
55115    )
55116 );
55117 
55118 
55119    --
55120    -- call ADRs
55121    -- Bug 4922099
55122    --
55123    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
55124         (NVL(l_actual_upg_option, 'N') = 'O') OR
55125         (NVL(l_enc_upg_option, 'N') = 'O')
55126       )
55127    THEN
55128    NULL;
55129    --
55130    --
55131    
55132   l_ccid := AcctDerRule_173(
55133            p_application_id           => p_application_id
55134          , p_ae_header_id             => l_ae_header_id 
55135 , p_source_3 => p_source_3
55136 , p_source_30 => p_source_30
55137          , x_transaction_coa_id       => l_adr_transaction_coa_id
55138          , x_accounting_coa_id        => l_adr_accounting_coa_id
55139          , x_value_type_code          => l_adr_value_type_code
55140          , p_side                     => 'NA'
55141    );
55142 
55143    xla_ae_lines_pkg.set_ccid(
55144     p_code_combination_id          => l_ccid
55145   , p_value_type_code              => l_adr_value_type_code
55146   , p_transaction_coa_id           => l_adr_transaction_coa_id
55147   , p_accounting_coa_id            => l_adr_accounting_coa_id
55148   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
55149   , p_adr_type_code                => 'S'
55150   , p_component_type               => l_component_type
55151   , p_component_code               => l_component_code
55152   , p_component_type_code          => l_component_type_code
55153   , p_component_appl_id            => l_component_appl_id
55154   , p_amb_context_code             => l_amb_context_code
55155   , p_side                         => 'NA'
55156   );
55157 
55158 
55159    l_segment := AcctDerRule_146(
55160            p_application_id           => p_application_id
55161          , p_ae_header_id             => l_ae_header_id 
55162 , p_source_3 => p_source_3
55163 , p_source_7 => p_source_7
55164          , x_transaction_coa_id       => l_adr_transaction_coa_id
55165          , x_accounting_coa_id        => l_adr_accounting_coa_id
55166          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
55167          , x_flex_value_set_id        => l_adr_flex_value_set_id
55168          , x_value_type_code          => l_adr_value_type_code
55169          , x_value_combination_id     => l_adr_value_combination_id
55170          , x_value_segment_code       => l_adr_value_segment_code
55171          , p_side                     => 'NA'
55172          , p_override_seg_flag        => 'Y'
55173    );
55174 
55175    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
55176 
55177       xla_ae_lines_pkg.set_segment(
55178           p_to_segment_code         => 'GL_ACCOUNT'
55179         , p_segment_value           => l_segment
55180         , p_from_segment_code       => l_adr_value_segment_code
55181         , p_from_combination_id     => l_adr_value_combination_id
55182         , p_value_type_code         => l_adr_value_type_code
55183         , p_transaction_coa_id      => l_adr_transaction_coa_id
55184         , p_accounting_coa_id       => l_adr_accounting_coa_id
55185         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
55186         , p_flex_value_set_id       => l_adr_flex_value_set_id
55187         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
55188         , p_adr_type_code           => 'S'
55189         , p_component_type          => l_component_type
55190         , p_component_code          => l_component_code
55191         , p_component_type_code     => l_component_type_code
55192         , p_component_appl_id       => l_component_appl_id
55193         , p_amb_context_code        => l_amb_context_code
55194         , p_entity_code             => 'TRANSACTIONS'
55195         , p_event_class_code        => 'CIP_RETIREMENTS'
55196         , p_side                    => 'NA'
55197         );
55198 
55199   END IF;
55200 
55201    l_segment := AcctDerRule_168(
55202            p_application_id           => p_application_id
55203          , p_ae_header_id             => l_ae_header_id 
55204 , p_source_3 => p_source_3
55205 , p_source_29 => p_source_29
55206          , x_transaction_coa_id       => l_adr_transaction_coa_id
55207          , x_accounting_coa_id        => l_adr_accounting_coa_id
55208          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
55209          , x_flex_value_set_id        => l_adr_flex_value_set_id
55210          , x_value_type_code          => l_adr_value_type_code
55211          , x_value_combination_id     => l_adr_value_combination_id
55212          , x_value_segment_code       => l_adr_value_segment_code
55213          , p_side                     => 'NA'
55214          , p_override_seg_flag        => 'Y'
55215    );
55216 
55217    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
55218 
55219       xla_ae_lines_pkg.set_segment(
55220           p_to_segment_code         => 'GL_BALANCING'
55221         , p_segment_value           => l_segment
55222         , p_from_segment_code       => l_adr_value_segment_code
55223         , p_from_combination_id     => l_adr_value_combination_id
55224         , p_value_type_code         => l_adr_value_type_code
55225         , p_transaction_coa_id      => l_adr_transaction_coa_id
55226         , p_accounting_coa_id       => l_adr_accounting_coa_id
55230         , p_adr_type_code           => 'S'
55227         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
55228         , p_flex_value_set_id       => l_adr_flex_value_set_id
55229         , p_adr_code                => 'FA_EXPENSE_ACCT'
55231         , p_component_type          => l_component_type
55232         , p_component_code          => l_component_code
55233         , p_component_type_code     => l_component_type_code
55234         , p_component_appl_id       => l_component_appl_id
55235         , p_amb_context_code        => l_amb_context_code
55236         , p_entity_code             => 'TRANSACTIONS'
55237         , p_event_class_code        => 'CIP_RETIREMENTS'
55238         , p_side                    => 'NA'
55239         );
55240 
55241   END IF;
55242 
55243    --
55244    --
55245    END IF;
55246    --
55247    -- Bug 4922099
55248    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
55249           (NVL(l_enc_upg_option, 'N') = 'O')
55250         ) AND
55251         (l_bflow_method_code = 'PRIOR_ENTRY')
55252       )
55253    THEN
55254       IF
55255       --
55256       1 = 2
55257       --
55258       THEN
55259       xla_accounting_err_pkg.build_message
55260                                     (p_appli_s_name            => 'XLA'
55261                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
55262                                     ,p_token_1                 => 'LINE_NUMBER'
55263                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
55264                                     ,p_token_2                 => 'LINE_TYPE_NAME'
55265                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
55266                                                                              l_component_type
55267                                                                             ,l_component_code
55268                                                                             ,l_component_type_code
55269                                                                             ,l_component_appl_id
55270                                                                             ,l_amb_context_code
55271                                                                             ,l_entity_code
55272                                                                             ,l_event_class_code
55273                                                                            )
55274                                     ,p_token_3                 => 'OWNER'
55275                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
55276                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
55277                                                                           ,p_lookup_code    => l_component_type_code
55278                                                                          )
55279                                     ,p_token_4                 => 'PRODUCT_NAME'
55280                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
55281                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
55282                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
55283                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
55284                                     ,p_ae_header_id            =>  NULL
55285                                        );
55286 
55287         IF (C_LEVEL_ERROR>= g_log_level) THEN
55288                  trace
55289                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
55290                       ,p_level    => C_LEVEL_ERROR
55291                       ,p_module   => l_log_module);
55292         END IF;
55293       END IF;
55294    END IF;
55295    --
55296    --
55297    ------------------------------------------------------------------------------------------------
55298    -- 4219869 Business Flow
55299    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
55300    -- Prior Entry.  Currently, the following code is always generated.
55301    ------------------------------------------------------------------------------------------------
55302    XLA_AE_LINES_PKG.ValidateCurrentLine;
55303 
55304    ------------------------------------------------------------------------------------
55305    -- 4219869 Business Flow
55306    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
55307    ------------------------------------------------------------------------------------
55308    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
55309 
55310    ----------------------------------------------------------------------------------
55311    -- 4219869 Business Flow
55312    -- Update journal entry status -- Need to generate this within IF <condition>
55313    ----------------------------------------------------------------------------------
55314    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
55315          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
55316          ,p_balance_type_code => l_balance_type_code
55317          );
55318 
55319    -------------------------------------------------------------------------------------------
55320    -- 4262811 - Generate the Accrual Reversal lines
55321    -------------------------------------------------------------------------------------------
55322    BEGIN
55323       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
55324                               (g_array_event(p_event_id).array_value_num('header_index'));
55325       IF l_acc_rev_flag IS NULL THEN
55326          l_acc_rev_flag := 'N';
55327       END IF;
55328    EXCEPTION
55329       WHEN OTHERS THEN
55330          l_acc_rev_flag := 'N';
55331    END;
55332    --
55336        -- To allow MPA report to determine if it should generate report process
55333    IF (l_acc_rev_flag = 'Y') THEN
55334 
55335        -- 4645092  ------------------------------------------------------------------------------
55337        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
55338        ------------------------------------------------------------------------------------------
55339 
55340        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
55341        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
55342    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
55343    -- call ADRs
55344    -- Bug 4922099
55345    --
55346    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
55347         (NVL(l_actual_upg_option, 'N') = 'O') OR
55348         (NVL(l_enc_upg_option, 'N') = 'O')
55349       )
55350    THEN
55351    NULL;
55352    --
55353    --
55354    
55355   l_ccid := AcctDerRule_173(
55356            p_application_id           => p_application_id
55357          , p_ae_header_id             => l_ae_header_id 
55358 , p_source_3 => p_source_3
55359 , p_source_30 => p_source_30
55360          , x_transaction_coa_id       => l_adr_transaction_coa_id
55361          , x_accounting_coa_id        => l_adr_accounting_coa_id
55362          , x_value_type_code          => l_adr_value_type_code
55363          , p_side                     => 'NA'
55364    );
55365 
55366    xla_ae_lines_pkg.set_ccid(
55367     p_code_combination_id          => l_ccid
55368   , p_value_type_code              => l_adr_value_type_code
55369   , p_transaction_coa_id           => l_adr_transaction_coa_id
55370   , p_accounting_coa_id            => l_adr_accounting_coa_id
55371   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
55372   , p_adr_type_code                => 'S'
55373   , p_component_type               => l_component_type
55374   , p_component_code               => l_component_code
55375   , p_component_type_code          => l_component_type_code
55376   , p_component_appl_id            => l_component_appl_id
55377   , p_amb_context_code             => l_amb_context_code
55378   , p_side                         => 'NA'
55379   );
55380 
55381 
55382    l_segment := AcctDerRule_146(
55383            p_application_id           => p_application_id
55384          , p_ae_header_id             => l_ae_header_id 
55385 , p_source_3 => p_source_3
55386 , p_source_7 => p_source_7
55387          , x_transaction_coa_id       => l_adr_transaction_coa_id
55388          , x_accounting_coa_id        => l_adr_accounting_coa_id
55389          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
55390          , x_flex_value_set_id        => l_adr_flex_value_set_id
55391          , x_value_type_code          => l_adr_value_type_code
55392          , x_value_combination_id     => l_adr_value_combination_id
55393          , x_value_segment_code       => l_adr_value_segment_code
55394          , p_side                     => 'NA'
55395          , p_override_seg_flag        => 'Y'
55396    );
55397 
55398    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
55399 
55400       xla_ae_lines_pkg.set_segment(
55401           p_to_segment_code         => 'GL_ACCOUNT'
55402         , p_segment_value           => l_segment
55403         , p_from_segment_code       => l_adr_value_segment_code
55404         , p_from_combination_id     => l_adr_value_combination_id
55405         , p_value_type_code         => l_adr_value_type_code
55406         , p_transaction_coa_id      => l_adr_transaction_coa_id
55407         , p_accounting_coa_id       => l_adr_accounting_coa_id
55408         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
55409         , p_flex_value_set_id       => l_adr_flex_value_set_id
55410         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
55411         , p_adr_type_code           => 'S'
55412         , p_component_type          => l_component_type
55413         , p_component_code          => l_component_code
55414         , p_component_type_code     => l_component_type_code
55415         , p_component_appl_id       => l_component_appl_id
55416         , p_amb_context_code        => l_amb_context_code
55417         , p_entity_code             => 'TRANSACTIONS'
55418         , p_event_class_code        => 'CIP_RETIREMENTS'
55419         , p_side                    => 'NA'
55420         );
55421 
55422   END IF;
55423 
55424    l_segment := AcctDerRule_168(
55425            p_application_id           => p_application_id
55426          , p_ae_header_id             => l_ae_header_id 
55427 , p_source_3 => p_source_3
55428 , p_source_29 => p_source_29
55429          , x_transaction_coa_id       => l_adr_transaction_coa_id
55430          , x_accounting_coa_id        => l_adr_accounting_coa_id
55431          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
55432          , x_flex_value_set_id        => l_adr_flex_value_set_id
55433          , x_value_type_code          => l_adr_value_type_code
55434          , x_value_combination_id     => l_adr_value_combination_id
55435          , x_value_segment_code       => l_adr_value_segment_code
55436          , p_side                     => 'NA'
55437          , p_override_seg_flag        => 'Y'
55438    );
55439 
55440    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
55441 
55442       xla_ae_lines_pkg.set_segment(
55443           p_to_segment_code         => 'GL_BALANCING'
55444         , p_segment_value           => l_segment
55445         , p_from_segment_code       => l_adr_value_segment_code
55446         , p_from_combination_id     => l_adr_value_combination_id
55447         , p_value_type_code         => l_adr_value_type_code
55448         , p_transaction_coa_id      => l_adr_transaction_coa_id
55449         , p_accounting_coa_id       => l_adr_accounting_coa_id
55450         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
55451         , p_flex_value_set_id       => l_adr_flex_value_set_id
55455         , p_component_code          => l_component_code
55452         , p_adr_code                => 'FA_EXPENSE_ACCT'
55453         , p_adr_type_code           => 'S'
55454         , p_component_type          => l_component_type
55456         , p_component_type_code     => l_component_type_code
55457         , p_component_appl_id       => l_component_appl_id
55458         , p_amb_context_code        => l_amb_context_code
55459         , p_entity_code             => 'TRANSACTIONS'
55460         , p_event_class_code        => 'CIP_RETIREMENTS'
55461         , p_side                    => 'NA'
55462         );
55463 
55464   END IF;
55465 
55466    --
55467    --
55468    END IF;
55469 
55470        --
55471        -- Update the line information that should be overwritten
55472        --
55473        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
55474                                          p_header_num   => 1);
55475        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
55476 
55477        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
55478 
55479        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
55480           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
55481        END IF;
55482 
55483       --
55484       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
55485       --
55486       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
55487           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
55488       ELSE
55489           ---------------------------------------------------------------------------------------------------
55490           -- 4262811a Switch Sign
55491           ---------------------------------------------------------------------------------------------------
55492           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
55493           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
55494                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
55495           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
55496                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
55497           -- 5132302
55498           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
55499                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
55500 
55501       END IF;
55502 
55503       -- 4955764
55504       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
55505       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
55506 
55507 
55508       XLA_AE_LINES_PKG.ValidateCurrentLine;
55509       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
55510 
55511       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
55512                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
55513                ,p_balance_type_code => l_balance_type_code);
55514 
55515    END IF;
55516 
55517    -----------------------------------------------------------------------------------------
55518    -- 4262811 Multiperiod Accounting
55519    -----------------------------------------------------------------------------------------
55520      -- No MPA option is assigned.
55521 
55522 
55523 END IF;
55524 END IF;
55525 --
55526 
55527 --
55528 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
55529    trace
55530       (p_msg      => 'END of AcctLineType_231'
55531       ,p_level    => C_LEVEL_PROCEDURE
55532       ,p_module   => l_log_module);
55533 END IF;
55534 --
55535 EXCEPTION
55536   WHEN xla_exceptions_pkg.application_exception THEN
55537       RAISE;
55538   WHEN OTHERS THEN
55539        xla_exceptions_pkg.raise_message
55540            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_231');
55541 END AcctLineType_231;
55542 --
55543 
55544 ---------------------------------------
55545 --
55546 -- PRIVATE FUNCTION
55547 --         AcctLineType_232
55548 --
55549 ---------------------------------------
55550 PROCEDURE AcctLineType_232 (
55551   p_application_id        IN NUMBER
55552  ,p_event_id              IN NUMBER
55553  ,p_calculate_acctd_flag  IN VARCHAR2
55554  ,p_calculate_g_l_flag    IN VARCHAR2
55555  ,p_actual_flag           IN OUT VARCHAR2
55556  ,p_balance_type_code     OUT VARCHAR2
55557  ,p_gain_or_loss_ref      OUT VARCHAR2
55558  
55559 --Period Close Date
55560  , p_source_1            IN DATE
55561 --Generated Code Combination Identifier
55562  , p_source_3            IN NUMBER
55563 --CIP Cost Account
55564  , p_source_7            IN VARCHAR2
55565 --Expense Account Code Combination Identifier
55566  , p_source_29            IN NUMBER
55567 --Default Code Combination Identifier
55568  , p_source_30            IN NUMBER
55569 --Adjustment Type
55570  , p_source_35            IN VARCHAR2
55571 --Transaction Header Identifier
55572  , p_source_36            IN NUMBER
55573 --Adjustment Line Identifier
55574  , p_source_37            IN NUMBER
55575 --Distribution Type Code
55576  , p_source_38            IN VARCHAR2
55577 --Entered Amount
55578  , p_source_39            IN NUMBER
55579 --Currency Code
55580  , p_source_40            IN VARCHAR2
55581 )
55582 IS
55583 
55584 l_component_type              VARCHAR2(80);
55585 l_component_code              VARCHAR2(30);
55586 l_component_type_code         VARCHAR2(1);
55590 l_event_class_code            VARCHAR2(30);
55587 l_component_appl_id           INTEGER;
55588 l_amb_context_code            VARCHAR2(30);
55589 l_entity_code                 VARCHAR2(30);
55591 l_ae_header_id                NUMBER;
55592 l_event_type_code             VARCHAR2(30);
55593 l_line_definition_code        VARCHAR2(30);
55594 l_line_definition_owner_code  VARCHAR2(1);
55595 --
55596 -- adr variables
55597 l_segment                     VARCHAR2(30);
55598 l_ccid                        NUMBER;
55599 l_adr_transaction_coa_id      NUMBER;
55600 l_adr_accounting_coa_id       NUMBER;
55601 l_adr_flexfield_segment_code  VARCHAR2(30);
55602 l_adr_flex_value_set_id       NUMBER;
55603 l_adr_value_type_code         VARCHAR2(30);
55604 l_adr_value_combination_id    NUMBER;
55605 l_adr_value_segment_code      VARCHAR2(30);
55606 
55607 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
55608 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
55609 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
55610 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
55611 
55612 -- 4262811 Variables ------------------------------------------------------------------------------------------
55613 l_entered_amt_idx             NUMBER;
55614 l_accted_amt_idx              NUMBER;
55615 l_acc_rev_flag                VARCHAR2(1);
55616 l_accrual_line_num            NUMBER;
55617 l_tmp_amt                     NUMBER;
55618 l_acc_rev_natural_side_code   VARCHAR2(1);
55619 
55620 l_num_entries                 NUMBER;
55621 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
55622 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
55623 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
55624 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
55625 l_recog_line_1                NUMBER;
55626 l_recog_line_2                NUMBER;
55627 
55628 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
55629 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
55630 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
55631 
55632 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
55633 
55634 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
55635 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
55636 
55637 ---------------------------------------------------------------------------------------------------------------
55638 
55639 
55640 --
55641 -- bulk performance
55642 --
55643 l_balance_type_code           VARCHAR2(1);
55644 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
55645 l_log_module                  VARCHAR2(240);
55646 
55647 --
55648 -- Upgrade strategy
55649 --
55650 l_actual_upg_option           VARCHAR2(1);
55651 l_enc_upg_option           VARCHAR2(1);
55652 
55653 --
55654 BEGIN
55655 --
55656 IF g_log_enabled THEN
55657       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_232';
55658 END IF;
55659 --
55660 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
55661 
55662       trace
55663          (p_msg      => 'BEGIN of AcctLineType_232'
55664          ,p_level    => C_LEVEL_PROCEDURE
55665          ,p_module   => l_log_module);
55666 
55667 END IF;
55668 --
55669 l_component_type             := 'AMB_JLT';
55670 l_component_code             := 'FA_CIP_RETIREMENT_COST';
55671 l_component_type_code        := 'S';
55672 l_component_appl_id          :=  140;
55673 l_amb_context_code           := 'DEFAULT';
55674 l_entity_code                := 'TRANSACTIONS';
55675 l_event_class_code           := 'CIP_RETIREMENTS';
55676 l_event_type_code            := 'CIP_RETIREMENTS';
55677 l_line_definition_owner_code := 'S';
55678 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
55679 --
55680 l_balance_type_code          := 'A';
55681 l_segment                     := NULL;
55682 l_ccid                        := NULL;
55683 l_adr_transaction_coa_id      := NULL;
55684 l_adr_accounting_coa_id       := NULL;
55685 l_adr_flexfield_segment_code  := NULL;
55686 l_adr_flex_value_set_id       := NULL;
55687 l_adr_value_type_code         := NULL;
55688 l_adr_value_combination_id    := NULL;
55689 l_adr_value_segment_code      := NULL;
55690 
55691 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
55692 l_bflow_class_code           := '';    -- 4219869 Business Flow
55693 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
55694 l_budgetary_control_flag     := 'N';
55695 
55696 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
55697 l_bflow_applied_to_amt       := NULL; -- 5132302
55698 l_entered_amt_idx            := NULL;          -- 4262811
55699 l_accted_amt_idx             := NULL;          -- 4262811
55700 l_acc_rev_flag               := NULL;          -- 4262811
55701 l_accrual_line_num           := NULL;          -- 4262811
55702 l_tmp_amt                    := NULL;          -- 4262811
55703 --
55704  
55705 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
55706     l_balance_type_code <> 'B' THEN
55707 IF NVL(p_source_35,'
55708 ') =  'CIP COST'
55709  THEN 
55710 
55711    --
55712    XLA_AE_LINES_PKG.SetNewLine;
55713 
55714    p_balance_type_code          := l_balance_type_code;
55715    -- set the flag so later we will know whether the gain loss line needs to be created
55716    
55717    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
55718      p_actual_flag :='A';
55719    END IF;
55720 
55721    --
55722    -- bulk performance
55723    --
55724    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
55728    --
55725                                       p_header_num   => 0); -- 4262811
55726    --
55727    -- set accounting line options
55729    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
55730            p_natural_side_code          => 'C'
55731          , p_gain_or_loss_flag          => 'N'
55732          , p_gl_transfer_mode_code      => 'S'
55733          , p_acct_entry_type_code       => 'A'
55734          , p_switch_side_flag           => 'Y'
55735          , p_merge_duplicate_code       => 'N'
55736          );
55737    --
55738    l_acc_rev_natural_side_code := 'D';  -- 4262811
55739    -- 
55740    --
55741    -- set accounting line type info
55742    --
55743    xla_ae_lines_pkg.SetAcctLineType
55744       (p_component_type             => l_component_type
55745       ,p_event_type_code            => l_event_type_code
55746       ,p_line_definition_owner_code => l_line_definition_owner_code
55747       ,p_line_definition_code       => l_line_definition_code
55748       ,p_accounting_line_code       => l_component_code
55749       ,p_accounting_line_type_code  => l_component_type_code
55750       ,p_accounting_line_appl_id    => l_component_appl_id
55751       ,p_amb_context_code           => l_amb_context_code
55752       ,p_entity_code                => l_entity_code
55753       ,p_event_class_code           => l_event_class_code);
55754    --
55755    -- set accounting class
55756    --
55757    xla_ae_lines_pkg.SetAcctClass(
55758            p_accounting_class_code  => 'ASSET'
55759          , p_ae_header_id           => l_ae_header_id
55760          );
55761 
55762    --
55763    -- set rounding class
55764    --
55765    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
55766                       'ASSET';
55767 
55768    --
55769    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
55770    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
55771    --
55772    -- bulk performance
55773    --
55774    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
55775 
55776    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
55777       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
55778 
55779    -- 4955764
55780    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
55781       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
55782 
55783    -- 4458381 Public Sector Enh
55784    
55785    --
55786    -- set accounting attributes for the line type
55787    --
55788    l_entered_amt_idx := 4;
55789    l_accted_amt_idx  := 6;
55790    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
55791    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
55792    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
55793    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
55794    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
55795    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
55796    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
55797    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
55798    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
55799    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
55800    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
55801    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
55802    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
55803 
55804    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
55805    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
55806 
55807    ---------------------------------------------------------------------------------------------------------------
55808    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
55809    ---------------------------------------------------------------------------------------------------------------
55810    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
55811 
55812    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
55813    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
55814 
55815    IF xla_accounting_cache_pkg.GetValueChar
55816          (p_source_code         => 'LEDGER_CATEGORY_CODE'
55817          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
55818    AND l_bflow_method_code = 'PRIOR_ENTRY'
55819 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
55820    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
55821          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
55822        )
55823    THEN
55824          xla_ae_lines_pkg.BflowUpgEntry
55825            (p_business_method_code    => l_bflow_method_code
55826            ,p_business_class_code     => l_bflow_class_code
55827            ,p_balance_type            => l_balance_type_code);
55828    ELSE
55829       NULL;
55830 -- No business flow processing for business flow method of NONE.
55831    END IF;
55832 
55833    --
55834    -- call analytical criteria
55835    --
55836    
55837    --
55838    -- call description
55839    --
55840    
55841 xla_ae_lines_pkg.SetLineDescription(
55842    p_ae_header_id => l_ae_header_id
55843   ,p_description  => Description_31 (
55844      p_application_id         => p_application_id
55845    , p_ae_header_id           => l_ae_header_id 
55846 , p_source_1 => p_source_1
55847    )
55848 );
55849 
55850 
55851    --
55855    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
55852    -- call ADRs
55853    -- Bug 4922099
55854    --
55856         (NVL(l_actual_upg_option, 'N') = 'O') OR
55857         (NVL(l_enc_upg_option, 'N') = 'O')
55858       )
55859    THEN
55860    NULL;
55861    --
55862    --
55863    
55864   l_ccid := AcctDerRule_173(
55865            p_application_id           => p_application_id
55866          , p_ae_header_id             => l_ae_header_id 
55867 , p_source_3 => p_source_3
55868 , p_source_30 => p_source_30
55869          , x_transaction_coa_id       => l_adr_transaction_coa_id
55870          , x_accounting_coa_id        => l_adr_accounting_coa_id
55871          , x_value_type_code          => l_adr_value_type_code
55872          , p_side                     => 'NA'
55873    );
55874 
55875    xla_ae_lines_pkg.set_ccid(
55876     p_code_combination_id          => l_ccid
55877   , p_value_type_code              => l_adr_value_type_code
55878   , p_transaction_coa_id           => l_adr_transaction_coa_id
55879   , p_accounting_coa_id            => l_adr_accounting_coa_id
55880   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
55881   , p_adr_type_code                => 'S'
55882   , p_component_type               => l_component_type
55883   , p_component_code               => l_component_code
55884   , p_component_type_code          => l_component_type_code
55885   , p_component_appl_id            => l_component_appl_id
55886   , p_amb_context_code             => l_amb_context_code
55887   , p_side                         => 'NA'
55888   );
55889 
55890 
55891    l_segment := AcctDerRule_146(
55892            p_application_id           => p_application_id
55893          , p_ae_header_id             => l_ae_header_id 
55894 , p_source_3 => p_source_3
55895 , p_source_7 => p_source_7
55896          , x_transaction_coa_id       => l_adr_transaction_coa_id
55897          , x_accounting_coa_id        => l_adr_accounting_coa_id
55898          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
55899          , x_flex_value_set_id        => l_adr_flex_value_set_id
55900          , x_value_type_code          => l_adr_value_type_code
55901          , x_value_combination_id     => l_adr_value_combination_id
55902          , x_value_segment_code       => l_adr_value_segment_code
55903          , p_side                     => 'NA'
55904          , p_override_seg_flag        => 'Y'
55905    );
55906 
55907    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
55908 
55909       xla_ae_lines_pkg.set_segment(
55910           p_to_segment_code         => 'GL_ACCOUNT'
55911         , p_segment_value           => l_segment
55912         , p_from_segment_code       => l_adr_value_segment_code
55913         , p_from_combination_id     => l_adr_value_combination_id
55914         , p_value_type_code         => l_adr_value_type_code
55915         , p_transaction_coa_id      => l_adr_transaction_coa_id
55916         , p_accounting_coa_id       => l_adr_accounting_coa_id
55917         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
55918         , p_flex_value_set_id       => l_adr_flex_value_set_id
55919         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
55920         , p_adr_type_code           => 'S'
55921         , p_component_type          => l_component_type
55922         , p_component_code          => l_component_code
55923         , p_component_type_code     => l_component_type_code
55924         , p_component_appl_id       => l_component_appl_id
55925         , p_amb_context_code        => l_amb_context_code
55926         , p_entity_code             => 'TRANSACTIONS'
55927         , p_event_class_code        => 'CIP_RETIREMENTS'
55928         , p_side                    => 'NA'
55929         );
55930 
55931   END IF;
55932 
55933    l_segment := AcctDerRule_168(
55934            p_application_id           => p_application_id
55935          , p_ae_header_id             => l_ae_header_id 
55936 , p_source_3 => p_source_3
55937 , p_source_29 => p_source_29
55938          , x_transaction_coa_id       => l_adr_transaction_coa_id
55939          , x_accounting_coa_id        => l_adr_accounting_coa_id
55940          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
55941          , x_flex_value_set_id        => l_adr_flex_value_set_id
55942          , x_value_type_code          => l_adr_value_type_code
55943          , x_value_combination_id     => l_adr_value_combination_id
55944          , x_value_segment_code       => l_adr_value_segment_code
55945          , p_side                     => 'NA'
55946          , p_override_seg_flag        => 'Y'
55947    );
55948 
55949    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
55950 
55951       xla_ae_lines_pkg.set_segment(
55952           p_to_segment_code         => 'GL_BALANCING'
55953         , p_segment_value           => l_segment
55954         , p_from_segment_code       => l_adr_value_segment_code
55955         , p_from_combination_id     => l_adr_value_combination_id
55956         , p_value_type_code         => l_adr_value_type_code
55957         , p_transaction_coa_id      => l_adr_transaction_coa_id
55958         , p_accounting_coa_id       => l_adr_accounting_coa_id
55959         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
55960         , p_flex_value_set_id       => l_adr_flex_value_set_id
55961         , p_adr_code                => 'FA_EXPENSE_ACCT'
55962         , p_adr_type_code           => 'S'
55963         , p_component_type          => l_component_type
55964         , p_component_code          => l_component_code
55965         , p_component_type_code     => l_component_type_code
55966         , p_component_appl_id       => l_component_appl_id
55967         , p_amb_context_code        => l_amb_context_code
55968         , p_entity_code             => 'TRANSACTIONS'
55969         , p_event_class_code        => 'CIP_RETIREMENTS'
55970         , p_side                    => 'NA'
55971         );
55972 
55976    --
55973   END IF;
55974 
55975    --
55977    END IF;
55978    --
55979    -- Bug 4922099
55980    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
55981           (NVL(l_enc_upg_option, 'N') = 'O')
55982         ) AND
55983         (l_bflow_method_code = 'PRIOR_ENTRY')
55984       )
55985    THEN
55986       IF
55987       --
55988       1 = 2
55989       --
55990       THEN
55991       xla_accounting_err_pkg.build_message
55992                                     (p_appli_s_name            => 'XLA'
55993                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
55994                                     ,p_token_1                 => 'LINE_NUMBER'
55995                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
55996                                     ,p_token_2                 => 'LINE_TYPE_NAME'
55997                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
55998                                                                              l_component_type
55999                                                                             ,l_component_code
56000                                                                             ,l_component_type_code
56001                                                                             ,l_component_appl_id
56002                                                                             ,l_amb_context_code
56003                                                                             ,l_entity_code
56004                                                                             ,l_event_class_code
56005                                                                            )
56006                                     ,p_token_3                 => 'OWNER'
56007                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
56008                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
56009                                                                           ,p_lookup_code    => l_component_type_code
56010                                                                          )
56011                                     ,p_token_4                 => 'PRODUCT_NAME'
56012                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
56013                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
56014                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
56015                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
56016                                     ,p_ae_header_id            =>  NULL
56017                                        );
56018 
56019         IF (C_LEVEL_ERROR>= g_log_level) THEN
56020                  trace
56021                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
56022                       ,p_level    => C_LEVEL_ERROR
56023                       ,p_module   => l_log_module);
56024         END IF;
56025       END IF;
56026    END IF;
56027    --
56028    --
56029    ------------------------------------------------------------------------------------------------
56030    -- 4219869 Business Flow
56031    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
56032    -- Prior Entry.  Currently, the following code is always generated.
56033    ------------------------------------------------------------------------------------------------
56034    XLA_AE_LINES_PKG.ValidateCurrentLine;
56035 
56036    ------------------------------------------------------------------------------------
56037    -- 4219869 Business Flow
56038    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
56039    ------------------------------------------------------------------------------------
56040    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
56041 
56042    ----------------------------------------------------------------------------------
56043    -- 4219869 Business Flow
56044    -- Update journal entry status -- Need to generate this within IF <condition>
56045    ----------------------------------------------------------------------------------
56046    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
56047          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
56048          ,p_balance_type_code => l_balance_type_code
56049          );
56050 
56051    -------------------------------------------------------------------------------------------
56052    -- 4262811 - Generate the Accrual Reversal lines
56053    -------------------------------------------------------------------------------------------
56054    BEGIN
56055       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
56056                               (g_array_event(p_event_id).array_value_num('header_index'));
56057       IF l_acc_rev_flag IS NULL THEN
56058          l_acc_rev_flag := 'N';
56059       END IF;
56060    EXCEPTION
56061       WHEN OTHERS THEN
56062          l_acc_rev_flag := 'N';
56063    END;
56064    --
56065    IF (l_acc_rev_flag = 'Y') THEN
56066 
56067        -- 4645092  ------------------------------------------------------------------------------
56068        -- To allow MPA report to determine if it should generate report process
56069        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
56070        ------------------------------------------------------------------------------------------
56071 
56072        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
56073        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
56074    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
56075    -- call ADRs
56076    -- Bug 4922099
56077    --
56078    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
56082    THEN
56079         (NVL(l_actual_upg_option, 'N') = 'O') OR
56080         (NVL(l_enc_upg_option, 'N') = 'O')
56081       )
56083    NULL;
56084    --
56085    --
56086    
56087   l_ccid := AcctDerRule_173(
56088            p_application_id           => p_application_id
56089          , p_ae_header_id             => l_ae_header_id 
56090 , p_source_3 => p_source_3
56091 , p_source_30 => p_source_30
56092          , x_transaction_coa_id       => l_adr_transaction_coa_id
56093          , x_accounting_coa_id        => l_adr_accounting_coa_id
56094          , x_value_type_code          => l_adr_value_type_code
56095          , p_side                     => 'NA'
56096    );
56097 
56098    xla_ae_lines_pkg.set_ccid(
56099     p_code_combination_id          => l_ccid
56100   , p_value_type_code              => l_adr_value_type_code
56101   , p_transaction_coa_id           => l_adr_transaction_coa_id
56102   , p_accounting_coa_id            => l_adr_accounting_coa_id
56103   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
56104   , p_adr_type_code                => 'S'
56105   , p_component_type               => l_component_type
56106   , p_component_code               => l_component_code
56107   , p_component_type_code          => l_component_type_code
56108   , p_component_appl_id            => l_component_appl_id
56109   , p_amb_context_code             => l_amb_context_code
56110   , p_side                         => 'NA'
56111   );
56112 
56113 
56114    l_segment := AcctDerRule_146(
56115            p_application_id           => p_application_id
56116          , p_ae_header_id             => l_ae_header_id 
56117 , p_source_3 => p_source_3
56118 , p_source_7 => p_source_7
56119          , x_transaction_coa_id       => l_adr_transaction_coa_id
56120          , x_accounting_coa_id        => l_adr_accounting_coa_id
56121          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
56122          , x_flex_value_set_id        => l_adr_flex_value_set_id
56123          , x_value_type_code          => l_adr_value_type_code
56124          , x_value_combination_id     => l_adr_value_combination_id
56125          , x_value_segment_code       => l_adr_value_segment_code
56126          , p_side                     => 'NA'
56127          , p_override_seg_flag        => 'Y'
56128    );
56129 
56130    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
56131 
56132       xla_ae_lines_pkg.set_segment(
56133           p_to_segment_code         => 'GL_ACCOUNT'
56134         , p_segment_value           => l_segment
56135         , p_from_segment_code       => l_adr_value_segment_code
56136         , p_from_combination_id     => l_adr_value_combination_id
56137         , p_value_type_code         => l_adr_value_type_code
56138         , p_transaction_coa_id      => l_adr_transaction_coa_id
56139         , p_accounting_coa_id       => l_adr_accounting_coa_id
56140         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
56141         , p_flex_value_set_id       => l_adr_flex_value_set_id
56142         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
56143         , p_adr_type_code           => 'S'
56144         , p_component_type          => l_component_type
56145         , p_component_code          => l_component_code
56146         , p_component_type_code     => l_component_type_code
56147         , p_component_appl_id       => l_component_appl_id
56148         , p_amb_context_code        => l_amb_context_code
56149         , p_entity_code             => 'TRANSACTIONS'
56150         , p_event_class_code        => 'CIP_RETIREMENTS'
56151         , p_side                    => 'NA'
56152         );
56153 
56154   END IF;
56155 
56156    l_segment := AcctDerRule_168(
56157            p_application_id           => p_application_id
56158          , p_ae_header_id             => l_ae_header_id 
56159 , p_source_3 => p_source_3
56160 , p_source_29 => p_source_29
56161          , x_transaction_coa_id       => l_adr_transaction_coa_id
56162          , x_accounting_coa_id        => l_adr_accounting_coa_id
56163          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
56164          , x_flex_value_set_id        => l_adr_flex_value_set_id
56165          , x_value_type_code          => l_adr_value_type_code
56166          , x_value_combination_id     => l_adr_value_combination_id
56167          , x_value_segment_code       => l_adr_value_segment_code
56168          , p_side                     => 'NA'
56169          , p_override_seg_flag        => 'Y'
56170    );
56171 
56172    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
56173 
56174       xla_ae_lines_pkg.set_segment(
56175           p_to_segment_code         => 'GL_BALANCING'
56176         , p_segment_value           => l_segment
56177         , p_from_segment_code       => l_adr_value_segment_code
56178         , p_from_combination_id     => l_adr_value_combination_id
56179         , p_value_type_code         => l_adr_value_type_code
56180         , p_transaction_coa_id      => l_adr_transaction_coa_id
56181         , p_accounting_coa_id       => l_adr_accounting_coa_id
56182         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
56183         , p_flex_value_set_id       => l_adr_flex_value_set_id
56184         , p_adr_code                => 'FA_EXPENSE_ACCT'
56185         , p_adr_type_code           => 'S'
56186         , p_component_type          => l_component_type
56187         , p_component_code          => l_component_code
56188         , p_component_type_code     => l_component_type_code
56189         , p_component_appl_id       => l_component_appl_id
56190         , p_amb_context_code        => l_amb_context_code
56191         , p_entity_code             => 'TRANSACTIONS'
56192         , p_event_class_code        => 'CIP_RETIREMENTS'
56193         , p_side                    => 'NA'
56194         );
56195 
56196   END IF;
56197 
56198    --
56199    --
56200    END IF;
56201 
56202        --
56206                                          p_header_num   => 1);
56203        -- Update the line information that should be overwritten
56204        --
56205        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
56207        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
56208 
56209        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
56210 
56211        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
56212           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
56213        END IF;
56214 
56215       --
56216       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
56217       --
56218       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
56219           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
56220       ELSE
56221           ---------------------------------------------------------------------------------------------------
56222           -- 4262811a Switch Sign
56223           ---------------------------------------------------------------------------------------------------
56224           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
56225           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
56226                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56227           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
56228                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56229           -- 5132302
56230           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
56231                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56232 
56233       END IF;
56234 
56235       -- 4955764
56236       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
56237       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
56238 
56239 
56240       XLA_AE_LINES_PKG.ValidateCurrentLine;
56241       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
56242 
56243       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
56244                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
56245                ,p_balance_type_code => l_balance_type_code);
56246 
56247    END IF;
56248 
56249    -----------------------------------------------------------------------------------------
56250    -- 4262811 Multiperiod Accounting
56251    -----------------------------------------------------------------------------------------
56252      -- No MPA option is assigned.
56253 
56254 
56255 END IF;
56256 END IF;
56257 --
56258 
56259 --
56260 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
56261    trace
56262       (p_msg      => 'END of AcctLineType_232'
56263       ,p_level    => C_LEVEL_PROCEDURE
56264       ,p_module   => l_log_module);
56265 END IF;
56266 --
56267 EXCEPTION
56268   WHEN xla_exceptions_pkg.application_exception THEN
56269       RAISE;
56270   WHEN OTHERS THEN
56271        xla_exceptions_pkg.raise_message
56272            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_232');
56273 END AcctLineType_232;
56274 --
56275 
56276 ---------------------------------------
56277 --
56278 -- PRIVATE FUNCTION
56279 --         AcctLineType_233
56280 --
56281 ---------------------------------------
56282 PROCEDURE AcctLineType_233 (
56283   p_application_id        IN NUMBER
56284  ,p_event_id              IN NUMBER
56285  ,p_calculate_acctd_flag  IN VARCHAR2
56286  ,p_calculate_g_l_flag    IN VARCHAR2
56287  ,p_actual_flag           IN OUT VARCHAR2
56288  ,p_balance_type_code     OUT VARCHAR2
56289  ,p_gain_or_loss_ref      OUT VARCHAR2
56290  
56291 --Period Close Date
56292  , p_source_1            IN DATE
56293 --Generated Code Combination Identifier
56294  , p_source_3            IN NUMBER
56295 --Revaluation Reserve Account
56296  , p_source_11            IN VARCHAR2
56297 --Generated Offset Code Combination Identifier
56298  , p_source_17            IN NUMBER
56299 --Expense Account Code Combination Identifier
56300  , p_source_29            IN NUMBER
56301 --Default Code Combination Identifier
56302  , p_source_30            IN NUMBER
56303 --Adjustment Type
56304  , p_source_35            IN VARCHAR2
56305 --Transaction Header Identifier
56306  , p_source_36            IN NUMBER
56307 --Adjustment Line Identifier
56308  , p_source_37            IN NUMBER
56309 --Distribution Type Code
56310  , p_source_38            IN VARCHAR2
56311 --Entered Amount
56312  , p_source_39            IN NUMBER
56313 --Currency Code
56314  , p_source_40            IN VARCHAR2
56315 )
56316 IS
56317 
56318 l_component_type              VARCHAR2(80);
56319 l_component_code              VARCHAR2(30);
56320 l_component_type_code         VARCHAR2(1);
56321 l_component_appl_id           INTEGER;
56322 l_amb_context_code            VARCHAR2(30);
56323 l_entity_code                 VARCHAR2(30);
56324 l_event_class_code            VARCHAR2(30);
56325 l_ae_header_id                NUMBER;
56326 l_event_type_code             VARCHAR2(30);
56327 l_line_definition_code        VARCHAR2(30);
56328 l_line_definition_owner_code  VARCHAR2(1);
56329 --
56330 -- adr variables
56331 l_segment                     VARCHAR2(30);
56332 l_ccid                        NUMBER;
56333 l_adr_transaction_coa_id      NUMBER;
56334 l_adr_accounting_coa_id       NUMBER;
56338 l_adr_value_combination_id    NUMBER;
56335 l_adr_flexfield_segment_code  VARCHAR2(30);
56336 l_adr_flex_value_set_id       NUMBER;
56337 l_adr_value_type_code         VARCHAR2(30);
56339 l_adr_value_segment_code      VARCHAR2(30);
56340 
56341 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
56342 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
56343 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
56344 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
56345 
56346 -- 4262811 Variables ------------------------------------------------------------------------------------------
56347 l_entered_amt_idx             NUMBER;
56348 l_accted_amt_idx              NUMBER;
56349 l_acc_rev_flag                VARCHAR2(1);
56350 l_accrual_line_num            NUMBER;
56351 l_tmp_amt                     NUMBER;
56352 l_acc_rev_natural_side_code   VARCHAR2(1);
56353 
56354 l_num_entries                 NUMBER;
56355 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
56356 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
56357 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
56358 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
56359 l_recog_line_1                NUMBER;
56360 l_recog_line_2                NUMBER;
56361 
56362 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
56363 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
56364 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
56365 
56366 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
56367 
56368 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
56369 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
56370 
56371 ---------------------------------------------------------------------------------------------------------------
56372 
56373 
56374 --
56375 -- bulk performance
56376 --
56377 l_balance_type_code           VARCHAR2(1);
56378 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
56379 l_log_module                  VARCHAR2(240);
56380 
56381 --
56382 -- Upgrade strategy
56383 --
56384 l_actual_upg_option           VARCHAR2(1);
56385 l_enc_upg_option           VARCHAR2(1);
56386 
56387 --
56388 BEGIN
56389 --
56390 IF g_log_enabled THEN
56391       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_233';
56392 END IF;
56393 --
56394 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
56395 
56396       trace
56397          (p_msg      => 'BEGIN of AcctLineType_233'
56398          ,p_level    => C_LEVEL_PROCEDURE
56399          ,p_module   => l_log_module);
56400 
56401 END IF;
56402 --
56403 l_component_type             := 'AMB_JLT';
56404 l_component_code             := 'FA_CIP_RET_REVAL_RESERVE';
56405 l_component_type_code        := 'S';
56406 l_component_appl_id          :=  140;
56407 l_amb_context_code           := 'DEFAULT';
56408 l_entity_code                := 'TRANSACTIONS';
56409 l_event_class_code           := 'CIP_RETIREMENTS';
56410 l_event_type_code            := 'CIP_RETIREMENTS';
56411 l_line_definition_owner_code := 'S';
56412 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
56413 --
56414 l_balance_type_code          := 'A';
56415 l_segment                     := NULL;
56416 l_ccid                        := NULL;
56417 l_adr_transaction_coa_id      := NULL;
56418 l_adr_accounting_coa_id       := NULL;
56419 l_adr_flexfield_segment_code  := NULL;
56420 l_adr_flex_value_set_id       := NULL;
56421 l_adr_value_type_code         := NULL;
56422 l_adr_value_combination_id    := NULL;
56423 l_adr_value_segment_code      := NULL;
56424 
56425 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
56426 l_bflow_class_code           := '';    -- 4219869 Business Flow
56427 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
56428 l_budgetary_control_flag     := 'N';
56429 
56430 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
56431 l_bflow_applied_to_amt       := NULL; -- 5132302
56432 l_entered_amt_idx            := NULL;          -- 4262811
56433 l_accted_amt_idx             := NULL;          -- 4262811
56434 l_acc_rev_flag               := NULL;          -- 4262811
56435 l_accrual_line_num           := NULL;          -- 4262811
56436 l_tmp_amt                    := NULL;          -- 4262811
56437 --
56438  
56439 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
56440     l_balance_type_code <> 'B' THEN
56441 IF NVL(p_source_35,'
56442 ') =  'REVAL RESERVE'
56443  THEN 
56444 
56445    --
56446    XLA_AE_LINES_PKG.SetNewLine;
56447 
56448    p_balance_type_code          := l_balance_type_code;
56449    -- set the flag so later we will know whether the gain loss line needs to be created
56450    
56451    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
56452      p_actual_flag :='A';
56453    END IF;
56454 
56455    --
56456    -- bulk performance
56457    --
56458    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
56459                                       p_header_num   => 0); -- 4262811
56460    --
56461    -- set accounting line options
56462    --
56463    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
56464            p_natural_side_code          => 'D'
56465          , p_gain_or_loss_flag          => 'N'
56466          , p_gl_transfer_mode_code      => 'S'
56467          , p_acct_entry_type_code       => 'A'
56468          , p_switch_side_flag           => 'Y'
56469          , p_merge_duplicate_code       => 'N'
56470          );
56471    --
56472    l_acc_rev_natural_side_code := 'C';  -- 4262811
56476    --
56473    -- 
56474    --
56475    -- set accounting line type info
56477    xla_ae_lines_pkg.SetAcctLineType
56478       (p_component_type             => l_component_type
56479       ,p_event_type_code            => l_event_type_code
56480       ,p_line_definition_owner_code => l_line_definition_owner_code
56481       ,p_line_definition_code       => l_line_definition_code
56482       ,p_accounting_line_code       => l_component_code
56483       ,p_accounting_line_type_code  => l_component_type_code
56484       ,p_accounting_line_appl_id    => l_component_appl_id
56485       ,p_amb_context_code           => l_amb_context_code
56486       ,p_entity_code                => l_entity_code
56487       ,p_event_class_code           => l_event_class_code);
56488    --
56489    -- set accounting class
56490    --
56491    xla_ae_lines_pkg.SetAcctClass(
56492            p_accounting_class_code  => 'ASSET'
56493          , p_ae_header_id           => l_ae_header_id
56494          );
56495 
56496    --
56497    -- set rounding class
56498    --
56499    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
56500                       'ASSET';
56501 
56502    --
56503    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
56504    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
56505    --
56506    -- bulk performance
56507    --
56508    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
56509 
56510    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
56511       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
56512 
56513    -- 4955764
56514    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
56515       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
56516 
56517    -- 4458381 Public Sector Enh
56518    
56519    --
56520    -- set accounting attributes for the line type
56521    --
56522    l_entered_amt_idx := 4;
56523    l_accted_amt_idx  := 6;
56524    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
56525    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
56526    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
56527    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
56528    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
56529    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
56530    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
56531    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
56532    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
56533    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
56534    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
56535    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
56536    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
56537 
56538    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
56539    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
56540 
56541    ---------------------------------------------------------------------------------------------------------------
56542    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
56543    ---------------------------------------------------------------------------------------------------------------
56544    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
56545 
56546    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
56547    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
56548 
56549    IF xla_accounting_cache_pkg.GetValueChar
56550          (p_source_code         => 'LEDGER_CATEGORY_CODE'
56551          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
56552    AND l_bflow_method_code = 'PRIOR_ENTRY'
56553 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
56554    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
56555          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
56556        )
56557    THEN
56558          xla_ae_lines_pkg.BflowUpgEntry
56559            (p_business_method_code    => l_bflow_method_code
56560            ,p_business_class_code     => l_bflow_class_code
56561            ,p_balance_type            => l_balance_type_code);
56562    ELSE
56563       NULL;
56564 -- No business flow processing for business flow method of NONE.
56565    END IF;
56566 
56567    --
56568    -- call analytical criteria
56569    --
56570    
56571    --
56572    -- call description
56573    --
56574    
56575 xla_ae_lines_pkg.SetLineDescription(
56576    p_ae_header_id => l_ae_header_id
56577   ,p_description  => Description_39 (
56578      p_application_id         => p_application_id
56579    , p_ae_header_id           => l_ae_header_id 
56580 , p_source_1 => p_source_1
56581    )
56582 );
56583 
56584 
56585    --
56586    -- call ADRs
56587    -- Bug 4922099
56588    --
56589    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
56590         (NVL(l_actual_upg_option, 'N') = 'O') OR
56591         (NVL(l_enc_upg_option, 'N') = 'O')
56592       )
56593    THEN
56594    NULL;
56595    --
56596    --
56597    
56598   l_ccid := AcctDerRule_174(
56599            p_application_id           => p_application_id
56600          , p_ae_header_id             => l_ae_header_id 
56601 , p_source_3 => p_source_3
56602 , p_source_17 => p_source_17
56603 , p_source_30 => p_source_30
56607          , p_side                     => 'NA'
56604          , x_transaction_coa_id       => l_adr_transaction_coa_id
56605          , x_accounting_coa_id        => l_adr_accounting_coa_id
56606          , x_value_type_code          => l_adr_value_type_code
56608    );
56609 
56610    xla_ae_lines_pkg.set_ccid(
56611     p_code_combination_id          => l_ccid
56612   , p_value_type_code              => l_adr_value_type_code
56613   , p_transaction_coa_id           => l_adr_transaction_coa_id
56614   , p_accounting_coa_id            => l_adr_accounting_coa_id
56615   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
56616   , p_adr_type_code                => 'S'
56617   , p_component_type               => l_component_type
56618   , p_component_code               => l_component_code
56619   , p_component_type_code          => l_component_type_code
56620   , p_component_appl_id            => l_component_appl_id
56621   , p_amb_context_code             => l_amb_context_code
56622   , p_side                         => 'NA'
56623   );
56624 
56625 
56626    l_segment := AcctDerRule_150(
56627            p_application_id           => p_application_id
56628          , p_ae_header_id             => l_ae_header_id 
56629 , p_source_3 => p_source_3
56630 , p_source_11 => p_source_11
56631          , x_transaction_coa_id       => l_adr_transaction_coa_id
56632          , x_accounting_coa_id        => l_adr_accounting_coa_id
56633          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
56634          , x_flex_value_set_id        => l_adr_flex_value_set_id
56635          , x_value_type_code          => l_adr_value_type_code
56636          , x_value_combination_id     => l_adr_value_combination_id
56637          , x_value_segment_code       => l_adr_value_segment_code
56638          , p_side                     => 'NA'
56639          , p_override_seg_flag        => 'Y'
56640    );
56641 
56642    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
56643 
56644       xla_ae_lines_pkg.set_segment(
56645           p_to_segment_code         => 'GL_ACCOUNT'
56646         , p_segment_value           => l_segment
56647         , p_from_segment_code       => l_adr_value_segment_code
56648         , p_from_combination_id     => l_adr_value_combination_id
56649         , p_value_type_code         => l_adr_value_type_code
56650         , p_transaction_coa_id      => l_adr_transaction_coa_id
56651         , p_accounting_coa_id       => l_adr_accounting_coa_id
56652         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
56653         , p_flex_value_set_id       => l_adr_flex_value_set_id
56654         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
56655         , p_adr_type_code           => 'S'
56656         , p_component_type          => l_component_type
56657         , p_component_code          => l_component_code
56658         , p_component_type_code     => l_component_type_code
56659         , p_component_appl_id       => l_component_appl_id
56660         , p_amb_context_code        => l_amb_context_code
56661         , p_entity_code             => 'TRANSACTIONS'
56662         , p_event_class_code        => 'CIP_RETIREMENTS'
56663         , p_side                    => 'NA'
56664         );
56665 
56666   END IF;
56667 
56668    l_segment := AcctDerRule_168(
56669            p_application_id           => p_application_id
56670          , p_ae_header_id             => l_ae_header_id 
56671 , p_source_3 => p_source_3
56672 , p_source_29 => p_source_29
56673          , x_transaction_coa_id       => l_adr_transaction_coa_id
56674          , x_accounting_coa_id        => l_adr_accounting_coa_id
56675          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
56676          , x_flex_value_set_id        => l_adr_flex_value_set_id
56677          , x_value_type_code          => l_adr_value_type_code
56678          , x_value_combination_id     => l_adr_value_combination_id
56679          , x_value_segment_code       => l_adr_value_segment_code
56680          , p_side                     => 'NA'
56681          , p_override_seg_flag        => 'Y'
56682    );
56683 
56684    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
56685 
56686       xla_ae_lines_pkg.set_segment(
56687           p_to_segment_code         => 'GL_BALANCING'
56688         , p_segment_value           => l_segment
56689         , p_from_segment_code       => l_adr_value_segment_code
56690         , p_from_combination_id     => l_adr_value_combination_id
56691         , p_value_type_code         => l_adr_value_type_code
56692         , p_transaction_coa_id      => l_adr_transaction_coa_id
56693         , p_accounting_coa_id       => l_adr_accounting_coa_id
56694         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
56695         , p_flex_value_set_id       => l_adr_flex_value_set_id
56696         , p_adr_code                => 'FA_EXPENSE_ACCT'
56697         , p_adr_type_code           => 'S'
56698         , p_component_type          => l_component_type
56699         , p_component_code          => l_component_code
56700         , p_component_type_code     => l_component_type_code
56701         , p_component_appl_id       => l_component_appl_id
56702         , p_amb_context_code        => l_amb_context_code
56703         , p_entity_code             => 'TRANSACTIONS'
56704         , p_event_class_code        => 'CIP_RETIREMENTS'
56705         , p_side                    => 'NA'
56706         );
56707 
56708   END IF;
56709 
56710    --
56711    --
56712    END IF;
56713    --
56714    -- Bug 4922099
56715    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
56716           (NVL(l_enc_upg_option, 'N') = 'O')
56717         ) AND
56718         (l_bflow_method_code = 'PRIOR_ENTRY')
56719       )
56720    THEN
56721       IF
56722       --
56723       1 = 2
56724       --
56725       THEN
56726       xla_accounting_err_pkg.build_message
56730                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
56727                                     (p_appli_s_name            => 'XLA'
56728                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
56729                                     ,p_token_1                 => 'LINE_NUMBER'
56731                                     ,p_token_2                 => 'LINE_TYPE_NAME'
56732                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
56733                                                                              l_component_type
56734                                                                             ,l_component_code
56735                                                                             ,l_component_type_code
56736                                                                             ,l_component_appl_id
56737                                                                             ,l_amb_context_code
56738                                                                             ,l_entity_code
56739                                                                             ,l_event_class_code
56740                                                                            )
56741                                     ,p_token_3                 => 'OWNER'
56742                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
56743                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
56744                                                                           ,p_lookup_code    => l_component_type_code
56745                                                                          )
56746                                     ,p_token_4                 => 'PRODUCT_NAME'
56747                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
56748                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
56749                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
56750                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
56751                                     ,p_ae_header_id            =>  NULL
56752                                        );
56753 
56754         IF (C_LEVEL_ERROR>= g_log_level) THEN
56755                  trace
56756                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
56757                       ,p_level    => C_LEVEL_ERROR
56758                       ,p_module   => l_log_module);
56759         END IF;
56760       END IF;
56761    END IF;
56762    --
56763    --
56764    ------------------------------------------------------------------------------------------------
56765    -- 4219869 Business Flow
56766    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
56767    -- Prior Entry.  Currently, the following code is always generated.
56768    ------------------------------------------------------------------------------------------------
56769    XLA_AE_LINES_PKG.ValidateCurrentLine;
56770 
56771    ------------------------------------------------------------------------------------
56772    -- 4219869 Business Flow
56773    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
56774    ------------------------------------------------------------------------------------
56775    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
56776 
56777    ----------------------------------------------------------------------------------
56778    -- 4219869 Business Flow
56779    -- Update journal entry status -- Need to generate this within IF <condition>
56780    ----------------------------------------------------------------------------------
56781    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
56782          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
56783          ,p_balance_type_code => l_balance_type_code
56784          );
56785 
56786    -------------------------------------------------------------------------------------------
56787    -- 4262811 - Generate the Accrual Reversal lines
56788    -------------------------------------------------------------------------------------------
56789    BEGIN
56790       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
56791                               (g_array_event(p_event_id).array_value_num('header_index'));
56792       IF l_acc_rev_flag IS NULL THEN
56793          l_acc_rev_flag := 'N';
56794       END IF;
56795    EXCEPTION
56796       WHEN OTHERS THEN
56797          l_acc_rev_flag := 'N';
56798    END;
56799    --
56800    IF (l_acc_rev_flag = 'Y') THEN
56801 
56802        -- 4645092  ------------------------------------------------------------------------------
56803        -- To allow MPA report to determine if it should generate report process
56804        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
56805        ------------------------------------------------------------------------------------------
56806 
56807        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
56808        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
56809    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
56810    -- call ADRs
56811    -- Bug 4922099
56812    --
56813    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
56814         (NVL(l_actual_upg_option, 'N') = 'O') OR
56815         (NVL(l_enc_upg_option, 'N') = 'O')
56816       )
56817    THEN
56818    NULL;
56819    --
56820    --
56821    
56822   l_ccid := AcctDerRule_174(
56823            p_application_id           => p_application_id
56824          , p_ae_header_id             => l_ae_header_id 
56825 , p_source_3 => p_source_3
56826 , p_source_17 => p_source_17
56827 , p_source_30 => p_source_30
56831          , p_side                     => 'NA'
56828          , x_transaction_coa_id       => l_adr_transaction_coa_id
56829          , x_accounting_coa_id        => l_adr_accounting_coa_id
56830          , x_value_type_code          => l_adr_value_type_code
56832    );
56833 
56834    xla_ae_lines_pkg.set_ccid(
56835     p_code_combination_id          => l_ccid
56836   , p_value_type_code              => l_adr_value_type_code
56837   , p_transaction_coa_id           => l_adr_transaction_coa_id
56838   , p_accounting_coa_id            => l_adr_accounting_coa_id
56839   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
56840   , p_adr_type_code                => 'S'
56841   , p_component_type               => l_component_type
56842   , p_component_code               => l_component_code
56843   , p_component_type_code          => l_component_type_code
56844   , p_component_appl_id            => l_component_appl_id
56845   , p_amb_context_code             => l_amb_context_code
56846   , p_side                         => 'NA'
56847   );
56848 
56849 
56850    l_segment := AcctDerRule_150(
56851            p_application_id           => p_application_id
56852          , p_ae_header_id             => l_ae_header_id 
56853 , p_source_3 => p_source_3
56854 , p_source_11 => p_source_11
56855          , x_transaction_coa_id       => l_adr_transaction_coa_id
56856          , x_accounting_coa_id        => l_adr_accounting_coa_id
56857          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
56858          , x_flex_value_set_id        => l_adr_flex_value_set_id
56859          , x_value_type_code          => l_adr_value_type_code
56860          , x_value_combination_id     => l_adr_value_combination_id
56861          , x_value_segment_code       => l_adr_value_segment_code
56862          , p_side                     => 'NA'
56863          , p_override_seg_flag        => 'Y'
56864    );
56865 
56866    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
56867 
56868       xla_ae_lines_pkg.set_segment(
56869           p_to_segment_code         => 'GL_ACCOUNT'
56870         , p_segment_value           => l_segment
56871         , p_from_segment_code       => l_adr_value_segment_code
56872         , p_from_combination_id     => l_adr_value_combination_id
56873         , p_value_type_code         => l_adr_value_type_code
56874         , p_transaction_coa_id      => l_adr_transaction_coa_id
56875         , p_accounting_coa_id       => l_adr_accounting_coa_id
56876         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
56877         , p_flex_value_set_id       => l_adr_flex_value_set_id
56878         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
56879         , p_adr_type_code           => 'S'
56880         , p_component_type          => l_component_type
56881         , p_component_code          => l_component_code
56882         , p_component_type_code     => l_component_type_code
56883         , p_component_appl_id       => l_component_appl_id
56884         , p_amb_context_code        => l_amb_context_code
56885         , p_entity_code             => 'TRANSACTIONS'
56886         , p_event_class_code        => 'CIP_RETIREMENTS'
56887         , p_side                    => 'NA'
56888         );
56889 
56890   END IF;
56891 
56892    l_segment := AcctDerRule_168(
56893            p_application_id           => p_application_id
56894          , p_ae_header_id             => l_ae_header_id 
56895 , p_source_3 => p_source_3
56896 , p_source_29 => p_source_29
56897          , x_transaction_coa_id       => l_adr_transaction_coa_id
56898          , x_accounting_coa_id        => l_adr_accounting_coa_id
56899          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
56900          , x_flex_value_set_id        => l_adr_flex_value_set_id
56901          , x_value_type_code          => l_adr_value_type_code
56902          , x_value_combination_id     => l_adr_value_combination_id
56903          , x_value_segment_code       => l_adr_value_segment_code
56904          , p_side                     => 'NA'
56905          , p_override_seg_flag        => 'Y'
56906    );
56907 
56908    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
56909 
56910       xla_ae_lines_pkg.set_segment(
56911           p_to_segment_code         => 'GL_BALANCING'
56912         , p_segment_value           => l_segment
56913         , p_from_segment_code       => l_adr_value_segment_code
56914         , p_from_combination_id     => l_adr_value_combination_id
56915         , p_value_type_code         => l_adr_value_type_code
56916         , p_transaction_coa_id      => l_adr_transaction_coa_id
56917         , p_accounting_coa_id       => l_adr_accounting_coa_id
56918         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
56919         , p_flex_value_set_id       => l_adr_flex_value_set_id
56920         , p_adr_code                => 'FA_EXPENSE_ACCT'
56921         , p_adr_type_code           => 'S'
56922         , p_component_type          => l_component_type
56923         , p_component_code          => l_component_code
56924         , p_component_type_code     => l_component_type_code
56925         , p_component_appl_id       => l_component_appl_id
56926         , p_amb_context_code        => l_amb_context_code
56927         , p_entity_code             => 'TRANSACTIONS'
56928         , p_event_class_code        => 'CIP_RETIREMENTS'
56929         , p_side                    => 'NA'
56930         );
56931 
56932   END IF;
56933 
56934    --
56935    --
56936    END IF;
56937 
56938        --
56939        -- Update the line information that should be overwritten
56940        --
56941        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
56942                                          p_header_num   => 1);
56943        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
56944 
56945        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
56946 
56950 
56947        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
56948           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
56949        END IF;
56951       --
56952       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
56953       --
56954       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
56955           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
56956       ELSE
56957           ---------------------------------------------------------------------------------------------------
56958           -- 4262811a Switch Sign
56959           ---------------------------------------------------------------------------------------------------
56960           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
56961           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
56962                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56963           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
56964                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56965           -- 5132302
56966           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
56967                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56968 
56969       END IF;
56970 
56971       -- 4955764
56972       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
56973       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
56974 
56975 
56976       XLA_AE_LINES_PKG.ValidateCurrentLine;
56977       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
56978 
56979       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
56980                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
56981                ,p_balance_type_code => l_balance_type_code);
56982 
56983    END IF;
56984 
56985    -----------------------------------------------------------------------------------------
56986    -- 4262811 Multiperiod Accounting
56987    -----------------------------------------------------------------------------------------
56988      -- No MPA option is assigned.
56989 
56990 
56991 END IF;
56992 END IF;
56993 --
56994 
56995 --
56996 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
56997    trace
56998       (p_msg      => 'END of AcctLineType_233'
56999       ,p_level    => C_LEVEL_PROCEDURE
57000       ,p_module   => l_log_module);
57001 END IF;
57002 --
57003 EXCEPTION
57004   WHEN xla_exceptions_pkg.application_exception THEN
57005       RAISE;
57006   WHEN OTHERS THEN
57007        xla_exceptions_pkg.raise_message
57008            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_233');
57009 END AcctLineType_233;
57010 --
57011 
57012 ---------------------------------------
57013 --
57014 -- PRIVATE FUNCTION
57015 --         AcctLineType_234
57016 --
57017 ---------------------------------------
57018 PROCEDURE AcctLineType_234 (
57019   p_application_id        IN NUMBER
57020  ,p_event_id              IN NUMBER
57021  ,p_calculate_acctd_flag  IN VARCHAR2
57022  ,p_calculate_g_l_flag    IN VARCHAR2
57023  ,p_actual_flag           IN OUT VARCHAR2
57024  ,p_balance_type_code     OUT VARCHAR2
57025  ,p_gain_or_loss_ref      OUT VARCHAR2
57026  
57027 --Period Close Date
57028  , p_source_1            IN DATE
57029 --Generated Code Combination Identifier
57030  , p_source_3            IN NUMBER
57031 --Revaluation Reserve Account
57032  , p_source_11            IN VARCHAR2
57033 --Generated Offset Code Combination Identifier
57034  , p_source_17            IN NUMBER
57035 --Expense Account Code Combination Identifier
57036  , p_source_29            IN NUMBER
57037 --Default Code Combination Identifier
57038  , p_source_30            IN NUMBER
57039 --Adjustment Type
57040  , p_source_35            IN VARCHAR2
57041 --Transaction Header Identifier
57042  , p_source_36            IN NUMBER
57043 --Adjustment Line Identifier
57044  , p_source_37            IN NUMBER
57045 --Distribution Type Code
57046  , p_source_38            IN VARCHAR2
57047 --Entered Amount
57048  , p_source_39            IN NUMBER
57049 --Currency Code
57050  , p_source_40            IN VARCHAR2
57051 )
57052 IS
57053 
57054 l_component_type              VARCHAR2(80);
57055 l_component_code              VARCHAR2(30);
57056 l_component_type_code         VARCHAR2(1);
57057 l_component_appl_id           INTEGER;
57058 l_amb_context_code            VARCHAR2(30);
57059 l_entity_code                 VARCHAR2(30);
57060 l_event_class_code            VARCHAR2(30);
57061 l_ae_header_id                NUMBER;
57062 l_event_type_code             VARCHAR2(30);
57063 l_line_definition_code        VARCHAR2(30);
57064 l_line_definition_owner_code  VARCHAR2(1);
57065 --
57066 -- adr variables
57067 l_segment                     VARCHAR2(30);
57068 l_ccid                        NUMBER;
57069 l_adr_transaction_coa_id      NUMBER;
57070 l_adr_accounting_coa_id       NUMBER;
57071 l_adr_flexfield_segment_code  VARCHAR2(30);
57072 l_adr_flex_value_set_id       NUMBER;
57073 l_adr_value_type_code         VARCHAR2(30);
57074 l_adr_value_combination_id    NUMBER;
57075 l_adr_value_segment_code      VARCHAR2(30);
57076 
57077 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
57078 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
57079 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
57083 l_entered_amt_idx             NUMBER;
57080 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
57081 
57082 -- 4262811 Variables ------------------------------------------------------------------------------------------
57084 l_accted_amt_idx              NUMBER;
57085 l_acc_rev_flag                VARCHAR2(1);
57086 l_accrual_line_num            NUMBER;
57087 l_tmp_amt                     NUMBER;
57088 l_acc_rev_natural_side_code   VARCHAR2(1);
57089 
57090 l_num_entries                 NUMBER;
57091 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
57092 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
57093 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
57094 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
57095 l_recog_line_1                NUMBER;
57096 l_recog_line_2                NUMBER;
57097 
57098 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
57099 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
57100 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
57101 
57102 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
57103 
57104 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
57105 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
57106 
57107 ---------------------------------------------------------------------------------------------------------------
57108 
57109 
57110 --
57111 -- bulk performance
57112 --
57113 l_balance_type_code           VARCHAR2(1);
57114 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
57115 l_log_module                  VARCHAR2(240);
57116 
57117 --
57118 -- Upgrade strategy
57119 --
57120 l_actual_upg_option           VARCHAR2(1);
57121 l_enc_upg_option           VARCHAR2(1);
57122 
57123 --
57124 BEGIN
57125 --
57126 IF g_log_enabled THEN
57127       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_234';
57128 END IF;
57129 --
57130 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
57131 
57132       trace
57133          (p_msg      => 'BEGIN of AcctLineType_234'
57134          ,p_level    => C_LEVEL_PROCEDURE
57135          ,p_module   => l_log_module);
57136 
57137 END IF;
57138 --
57139 l_component_type             := 'AMB_JLT';
57140 l_component_code             := 'FA_CIP_RET_REVAL_RESERVE';
57141 l_component_type_code        := 'S';
57142 l_component_appl_id          :=  140;
57143 l_amb_context_code           := 'DEFAULT';
57144 l_entity_code                := 'TRANSACTIONS';
57145 l_event_class_code           := 'CIP_RETIREMENTS';
57146 l_event_type_code            := 'CIP_REINSTATEMENTS';
57147 l_line_definition_owner_code := 'S';
57148 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
57149 --
57150 l_balance_type_code          := 'A';
57151 l_segment                     := NULL;
57152 l_ccid                        := NULL;
57153 l_adr_transaction_coa_id      := NULL;
57154 l_adr_accounting_coa_id       := NULL;
57155 l_adr_flexfield_segment_code  := NULL;
57156 l_adr_flex_value_set_id       := NULL;
57157 l_adr_value_type_code         := NULL;
57158 l_adr_value_combination_id    := NULL;
57159 l_adr_value_segment_code      := NULL;
57160 
57161 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
57162 l_bflow_class_code           := '';    -- 4219869 Business Flow
57163 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
57164 l_budgetary_control_flag     := 'N';
57165 
57166 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
57167 l_bflow_applied_to_amt       := NULL; -- 5132302
57168 l_entered_amt_idx            := NULL;          -- 4262811
57169 l_accted_amt_idx             := NULL;          -- 4262811
57170 l_acc_rev_flag               := NULL;          -- 4262811
57171 l_accrual_line_num           := NULL;          -- 4262811
57172 l_tmp_amt                    := NULL;          -- 4262811
57173 --
57174  
57175 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
57176     l_balance_type_code <> 'B' THEN
57177 IF NVL(p_source_35,'
57178 ') =  'REVAL RESERVE'
57179  THEN 
57180 
57181    --
57182    XLA_AE_LINES_PKG.SetNewLine;
57183 
57184    p_balance_type_code          := l_balance_type_code;
57185    -- set the flag so later we will know whether the gain loss line needs to be created
57186    
57187    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
57188      p_actual_flag :='A';
57189    END IF;
57190 
57191    --
57192    -- bulk performance
57193    --
57194    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
57195                                       p_header_num   => 0); -- 4262811
57196    --
57197    -- set accounting line options
57198    --
57199    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
57200            p_natural_side_code          => 'D'
57201          , p_gain_or_loss_flag          => 'N'
57202          , p_gl_transfer_mode_code      => 'S'
57203          , p_acct_entry_type_code       => 'A'
57204          , p_switch_side_flag           => 'Y'
57205          , p_merge_duplicate_code       => 'N'
57206          );
57207    --
57208    l_acc_rev_natural_side_code := 'C';  -- 4262811
57209    -- 
57210    --
57211    -- set accounting line type info
57212    --
57213    xla_ae_lines_pkg.SetAcctLineType
57214       (p_component_type             => l_component_type
57215       ,p_event_type_code            => l_event_type_code
57216       ,p_line_definition_owner_code => l_line_definition_owner_code
57217       ,p_line_definition_code       => l_line_definition_code
57218       ,p_accounting_line_code       => l_component_code
57222       ,p_entity_code                => l_entity_code
57219       ,p_accounting_line_type_code  => l_component_type_code
57220       ,p_accounting_line_appl_id    => l_component_appl_id
57221       ,p_amb_context_code           => l_amb_context_code
57223       ,p_event_class_code           => l_event_class_code);
57224    --
57225    -- set accounting class
57226    --
57227    xla_ae_lines_pkg.SetAcctClass(
57228            p_accounting_class_code  => 'ASSET'
57229          , p_ae_header_id           => l_ae_header_id
57230          );
57231 
57232    --
57233    -- set rounding class
57234    --
57235    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
57236                       'ASSET';
57237 
57238    --
57239    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
57240    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
57241    --
57242    -- bulk performance
57243    --
57244    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
57245 
57246    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
57247       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
57248 
57249    -- 4955764
57250    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
57251       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
57252 
57253    -- 4458381 Public Sector Enh
57254    
57255    --
57256    -- set accounting attributes for the line type
57257    --
57258    l_entered_amt_idx := 4;
57259    l_accted_amt_idx  := 6;
57260    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
57261    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
57262    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
57263    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
57264    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
57265    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
57266    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
57267    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
57268    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
57269    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
57270    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
57271    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
57272    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
57273 
57274    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
57275    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
57276 
57277    ---------------------------------------------------------------------------------------------------------------
57278    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
57279    ---------------------------------------------------------------------------------------------------------------
57280    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
57281 
57282    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
57283    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
57284 
57285    IF xla_accounting_cache_pkg.GetValueChar
57286          (p_source_code         => 'LEDGER_CATEGORY_CODE'
57287          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
57288    AND l_bflow_method_code = 'PRIOR_ENTRY'
57289 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
57290    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
57291          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
57292        )
57293    THEN
57294          xla_ae_lines_pkg.BflowUpgEntry
57295            (p_business_method_code    => l_bflow_method_code
57296            ,p_business_class_code     => l_bflow_class_code
57297            ,p_balance_type            => l_balance_type_code);
57298    ELSE
57299       NULL;
57300 -- No business flow processing for business flow method of NONE.
57301    END IF;
57302 
57303    --
57304    -- call analytical criteria
57305    --
57306    
57307    --
57308    -- call description
57309    --
57310    
57311 xla_ae_lines_pkg.SetLineDescription(
57312    p_ae_header_id => l_ae_header_id
57313   ,p_description  => Description_43 (
57314      p_application_id         => p_application_id
57315    , p_ae_header_id           => l_ae_header_id 
57316 , p_source_1 => p_source_1
57317    )
57318 );
57319 
57320 
57321    --
57322    -- call ADRs
57323    -- Bug 4922099
57324    --
57325    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
57326         (NVL(l_actual_upg_option, 'N') = 'O') OR
57327         (NVL(l_enc_upg_option, 'N') = 'O')
57328       )
57329    THEN
57330    NULL;
57331    --
57332    --
57333    
57334   l_ccid := AcctDerRule_174(
57335            p_application_id           => p_application_id
57336          , p_ae_header_id             => l_ae_header_id 
57337 , p_source_3 => p_source_3
57338 , p_source_17 => p_source_17
57339 , p_source_30 => p_source_30
57340          , x_transaction_coa_id       => l_adr_transaction_coa_id
57341          , x_accounting_coa_id        => l_adr_accounting_coa_id
57342          , x_value_type_code          => l_adr_value_type_code
57343          , p_side                     => 'NA'
57344    );
57345 
57346    xla_ae_lines_pkg.set_ccid(
57347     p_code_combination_id          => l_ccid
57348   , p_value_type_code              => l_adr_value_type_code
57352   , p_adr_type_code                => 'S'
57349   , p_transaction_coa_id           => l_adr_transaction_coa_id
57350   , p_accounting_coa_id            => l_adr_accounting_coa_id
57351   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
57353   , p_component_type               => l_component_type
57354   , p_component_code               => l_component_code
57355   , p_component_type_code          => l_component_type_code
57356   , p_component_appl_id            => l_component_appl_id
57357   , p_amb_context_code             => l_amb_context_code
57358   , p_side                         => 'NA'
57359   );
57360 
57361 
57362    l_segment := AcctDerRule_150(
57363            p_application_id           => p_application_id
57364          , p_ae_header_id             => l_ae_header_id 
57365 , p_source_3 => p_source_3
57366 , p_source_11 => p_source_11
57367          , x_transaction_coa_id       => l_adr_transaction_coa_id
57368          , x_accounting_coa_id        => l_adr_accounting_coa_id
57369          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
57370          , x_flex_value_set_id        => l_adr_flex_value_set_id
57371          , x_value_type_code          => l_adr_value_type_code
57372          , x_value_combination_id     => l_adr_value_combination_id
57373          , x_value_segment_code       => l_adr_value_segment_code
57374          , p_side                     => 'NA'
57375          , p_override_seg_flag        => 'Y'
57376    );
57377 
57378    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
57379 
57380       xla_ae_lines_pkg.set_segment(
57381           p_to_segment_code         => 'GL_ACCOUNT'
57382         , p_segment_value           => l_segment
57383         , p_from_segment_code       => l_adr_value_segment_code
57384         , p_from_combination_id     => l_adr_value_combination_id
57385         , p_value_type_code         => l_adr_value_type_code
57386         , p_transaction_coa_id      => l_adr_transaction_coa_id
57387         , p_accounting_coa_id       => l_adr_accounting_coa_id
57388         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
57389         , p_flex_value_set_id       => l_adr_flex_value_set_id
57390         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
57391         , p_adr_type_code           => 'S'
57392         , p_component_type          => l_component_type
57393         , p_component_code          => l_component_code
57394         , p_component_type_code     => l_component_type_code
57395         , p_component_appl_id       => l_component_appl_id
57396         , p_amb_context_code        => l_amb_context_code
57397         , p_entity_code             => 'TRANSACTIONS'
57398         , p_event_class_code        => 'CIP_RETIREMENTS'
57399         , p_side                    => 'NA'
57400         );
57401 
57402   END IF;
57403 
57404    l_segment := AcctDerRule_168(
57405            p_application_id           => p_application_id
57406          , p_ae_header_id             => l_ae_header_id 
57407 , p_source_3 => p_source_3
57408 , p_source_29 => p_source_29
57409          , x_transaction_coa_id       => l_adr_transaction_coa_id
57410          , x_accounting_coa_id        => l_adr_accounting_coa_id
57411          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
57412          , x_flex_value_set_id        => l_adr_flex_value_set_id
57413          , x_value_type_code          => l_adr_value_type_code
57414          , x_value_combination_id     => l_adr_value_combination_id
57415          , x_value_segment_code       => l_adr_value_segment_code
57416          , p_side                     => 'NA'
57417          , p_override_seg_flag        => 'Y'
57418    );
57419 
57420    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
57421 
57422       xla_ae_lines_pkg.set_segment(
57423           p_to_segment_code         => 'GL_BALANCING'
57424         , p_segment_value           => l_segment
57425         , p_from_segment_code       => l_adr_value_segment_code
57426         , p_from_combination_id     => l_adr_value_combination_id
57427         , p_value_type_code         => l_adr_value_type_code
57428         , p_transaction_coa_id      => l_adr_transaction_coa_id
57429         , p_accounting_coa_id       => l_adr_accounting_coa_id
57430         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
57431         , p_flex_value_set_id       => l_adr_flex_value_set_id
57432         , p_adr_code                => 'FA_EXPENSE_ACCT'
57433         , p_adr_type_code           => 'S'
57434         , p_component_type          => l_component_type
57435         , p_component_code          => l_component_code
57436         , p_component_type_code     => l_component_type_code
57437         , p_component_appl_id       => l_component_appl_id
57438         , p_amb_context_code        => l_amb_context_code
57439         , p_entity_code             => 'TRANSACTIONS'
57440         , p_event_class_code        => 'CIP_RETIREMENTS'
57441         , p_side                    => 'NA'
57442         );
57443 
57444   END IF;
57445 
57446    --
57447    --
57448    END IF;
57449    --
57450    -- Bug 4922099
57451    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
57452           (NVL(l_enc_upg_option, 'N') = 'O')
57453         ) AND
57454         (l_bflow_method_code = 'PRIOR_ENTRY')
57455       )
57456    THEN
57457       IF
57458       --
57459       1 = 2
57460       --
57461       THEN
57462       xla_accounting_err_pkg.build_message
57463                                     (p_appli_s_name            => 'XLA'
57464                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
57465                                     ,p_token_1                 => 'LINE_NUMBER'
57466                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
57467                                     ,p_token_2                 => 'LINE_TYPE_NAME'
57471                                                                             ,l_component_type_code
57468                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
57469                                                                              l_component_type
57470                                                                             ,l_component_code
57472                                                                             ,l_component_appl_id
57473                                                                             ,l_amb_context_code
57474                                                                             ,l_entity_code
57475                                                                             ,l_event_class_code
57476                                                                            )
57477                                     ,p_token_3                 => 'OWNER'
57478                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
57479                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
57480                                                                           ,p_lookup_code    => l_component_type_code
57481                                                                          )
57482                                     ,p_token_4                 => 'PRODUCT_NAME'
57483                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
57484                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
57485                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
57486                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
57487                                     ,p_ae_header_id            =>  NULL
57488                                        );
57489 
57490         IF (C_LEVEL_ERROR>= g_log_level) THEN
57491                  trace
57492                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
57493                       ,p_level    => C_LEVEL_ERROR
57494                       ,p_module   => l_log_module);
57495         END IF;
57496       END IF;
57497    END IF;
57498    --
57499    --
57500    ------------------------------------------------------------------------------------------------
57501    -- 4219869 Business Flow
57502    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
57503    -- Prior Entry.  Currently, the following code is always generated.
57504    ------------------------------------------------------------------------------------------------
57505    XLA_AE_LINES_PKG.ValidateCurrentLine;
57506 
57507    ------------------------------------------------------------------------------------
57508    -- 4219869 Business Flow
57509    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
57510    ------------------------------------------------------------------------------------
57511    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
57512 
57513    ----------------------------------------------------------------------------------
57514    -- 4219869 Business Flow
57515    -- Update journal entry status -- Need to generate this within IF <condition>
57516    ----------------------------------------------------------------------------------
57517    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
57518          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
57519          ,p_balance_type_code => l_balance_type_code
57520          );
57521 
57522    -------------------------------------------------------------------------------------------
57523    -- 4262811 - Generate the Accrual Reversal lines
57524    -------------------------------------------------------------------------------------------
57525    BEGIN
57526       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
57527                               (g_array_event(p_event_id).array_value_num('header_index'));
57528       IF l_acc_rev_flag IS NULL THEN
57529          l_acc_rev_flag := 'N';
57530       END IF;
57531    EXCEPTION
57532       WHEN OTHERS THEN
57533          l_acc_rev_flag := 'N';
57534    END;
57535    --
57536    IF (l_acc_rev_flag = 'Y') THEN
57537 
57538        -- 4645092  ------------------------------------------------------------------------------
57539        -- To allow MPA report to determine if it should generate report process
57540        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
57541        ------------------------------------------------------------------------------------------
57542 
57543        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
57544        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
57545    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
57546    -- call ADRs
57547    -- Bug 4922099
57548    --
57549    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
57550         (NVL(l_actual_upg_option, 'N') = 'O') OR
57551         (NVL(l_enc_upg_option, 'N') = 'O')
57552       )
57553    THEN
57554    NULL;
57555    --
57556    --
57557    
57558   l_ccid := AcctDerRule_174(
57559            p_application_id           => p_application_id
57560          , p_ae_header_id             => l_ae_header_id 
57561 , p_source_3 => p_source_3
57562 , p_source_17 => p_source_17
57563 , p_source_30 => p_source_30
57564          , x_transaction_coa_id       => l_adr_transaction_coa_id
57565          , x_accounting_coa_id        => l_adr_accounting_coa_id
57566          , x_value_type_code          => l_adr_value_type_code
57567          , p_side                     => 'NA'
57568    );
57569 
57570    xla_ae_lines_pkg.set_ccid(
57571     p_code_combination_id          => l_ccid
57572   , p_value_type_code              => l_adr_value_type_code
57576   , p_adr_type_code                => 'S'
57573   , p_transaction_coa_id           => l_adr_transaction_coa_id
57574   , p_accounting_coa_id            => l_adr_accounting_coa_id
57575   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
57577   , p_component_type               => l_component_type
57578   , p_component_code               => l_component_code
57579   , p_component_type_code          => l_component_type_code
57580   , p_component_appl_id            => l_component_appl_id
57581   , p_amb_context_code             => l_amb_context_code
57582   , p_side                         => 'NA'
57583   );
57584 
57585 
57586    l_segment := AcctDerRule_150(
57587            p_application_id           => p_application_id
57588          , p_ae_header_id             => l_ae_header_id 
57589 , p_source_3 => p_source_3
57590 , p_source_11 => p_source_11
57591          , x_transaction_coa_id       => l_adr_transaction_coa_id
57592          , x_accounting_coa_id        => l_adr_accounting_coa_id
57593          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
57594          , x_flex_value_set_id        => l_adr_flex_value_set_id
57595          , x_value_type_code          => l_adr_value_type_code
57596          , x_value_combination_id     => l_adr_value_combination_id
57597          , x_value_segment_code       => l_adr_value_segment_code
57598          , p_side                     => 'NA'
57599          , p_override_seg_flag        => 'Y'
57600    );
57601 
57602    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
57603 
57604       xla_ae_lines_pkg.set_segment(
57605           p_to_segment_code         => 'GL_ACCOUNT'
57606         , p_segment_value           => l_segment
57607         , p_from_segment_code       => l_adr_value_segment_code
57608         , p_from_combination_id     => l_adr_value_combination_id
57609         , p_value_type_code         => l_adr_value_type_code
57610         , p_transaction_coa_id      => l_adr_transaction_coa_id
57611         , p_accounting_coa_id       => l_adr_accounting_coa_id
57612         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
57613         , p_flex_value_set_id       => l_adr_flex_value_set_id
57614         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
57615         , p_adr_type_code           => 'S'
57616         , p_component_type          => l_component_type
57617         , p_component_code          => l_component_code
57618         , p_component_type_code     => l_component_type_code
57619         , p_component_appl_id       => l_component_appl_id
57620         , p_amb_context_code        => l_amb_context_code
57621         , p_entity_code             => 'TRANSACTIONS'
57622         , p_event_class_code        => 'CIP_RETIREMENTS'
57623         , p_side                    => 'NA'
57624         );
57625 
57626   END IF;
57627 
57628    l_segment := AcctDerRule_168(
57629            p_application_id           => p_application_id
57630          , p_ae_header_id             => l_ae_header_id 
57631 , p_source_3 => p_source_3
57632 , p_source_29 => p_source_29
57633          , x_transaction_coa_id       => l_adr_transaction_coa_id
57634          , x_accounting_coa_id        => l_adr_accounting_coa_id
57635          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
57636          , x_flex_value_set_id        => l_adr_flex_value_set_id
57637          , x_value_type_code          => l_adr_value_type_code
57638          , x_value_combination_id     => l_adr_value_combination_id
57639          , x_value_segment_code       => l_adr_value_segment_code
57640          , p_side                     => 'NA'
57641          , p_override_seg_flag        => 'Y'
57642    );
57643 
57644    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
57645 
57646       xla_ae_lines_pkg.set_segment(
57647           p_to_segment_code         => 'GL_BALANCING'
57648         , p_segment_value           => l_segment
57649         , p_from_segment_code       => l_adr_value_segment_code
57650         , p_from_combination_id     => l_adr_value_combination_id
57651         , p_value_type_code         => l_adr_value_type_code
57652         , p_transaction_coa_id      => l_adr_transaction_coa_id
57653         , p_accounting_coa_id       => l_adr_accounting_coa_id
57654         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
57655         , p_flex_value_set_id       => l_adr_flex_value_set_id
57656         , p_adr_code                => 'FA_EXPENSE_ACCT'
57657         , p_adr_type_code           => 'S'
57658         , p_component_type          => l_component_type
57659         , p_component_code          => l_component_code
57660         , p_component_type_code     => l_component_type_code
57661         , p_component_appl_id       => l_component_appl_id
57662         , p_amb_context_code        => l_amb_context_code
57663         , p_entity_code             => 'TRANSACTIONS'
57664         , p_event_class_code        => 'CIP_RETIREMENTS'
57665         , p_side                    => 'NA'
57666         );
57667 
57668   END IF;
57669 
57670    --
57671    --
57672    END IF;
57673 
57674        --
57675        -- Update the line information that should be overwritten
57676        --
57677        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
57678                                          p_header_num   => 1);
57679        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
57680 
57681        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
57682 
57683        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
57684           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
57685        END IF;
57686 
57687       --
57688       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
57689       --
57693           ---------------------------------------------------------------------------------------------------
57690       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
57691           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
57692       ELSE
57694           -- 4262811a Switch Sign
57695           ---------------------------------------------------------------------------------------------------
57696           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
57697           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
57698                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
57699           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
57700                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
57701           -- 5132302
57702           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
57703                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
57704 
57705       END IF;
57706 
57707       -- 4955764
57708       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
57709       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
57710 
57711 
57712       XLA_AE_LINES_PKG.ValidateCurrentLine;
57713       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
57714 
57715       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
57716                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
57717                ,p_balance_type_code => l_balance_type_code);
57718 
57719    END IF;
57720 
57721    -----------------------------------------------------------------------------------------
57722    -- 4262811 Multiperiod Accounting
57723    -----------------------------------------------------------------------------------------
57724      -- No MPA option is assigned.
57725 
57726 
57727 END IF;
57728 END IF;
57729 --
57730 
57731 --
57732 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
57733    trace
57734       (p_msg      => 'END of AcctLineType_234'
57735       ,p_level    => C_LEVEL_PROCEDURE
57736       ,p_module   => l_log_module);
57737 END IF;
57738 --
57739 EXCEPTION
57740   WHEN xla_exceptions_pkg.application_exception THEN
57741       RAISE;
57742   WHEN OTHERS THEN
57743        xla_exceptions_pkg.raise_message
57744            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_234');
57745 END AcctLineType_234;
57746 --
57747 
57748 ---------------------------------------
57749 --
57750 -- PRIVATE FUNCTION
57751 --         AcctLineType_235
57752 --
57753 ---------------------------------------
57754 PROCEDURE AcctLineType_235 (
57755   p_application_id        IN NUMBER
57756  ,p_event_id              IN NUMBER
57757  ,p_calculate_acctd_flag  IN VARCHAR2
57758  ,p_calculate_g_l_flag    IN VARCHAR2
57759  ,p_actual_flag           IN OUT VARCHAR2
57760  ,p_balance_type_code     OUT VARCHAR2
57761  ,p_gain_or_loss_ref      OUT VARCHAR2
57762  
57763 --Period Close Date
57764  , p_source_1            IN DATE
57765 --Generated Code Combination Identifier
57766  , p_source_3            IN NUMBER
57767 --Revaluation Reserve Retired Gain Account
57768  , p_source_27            IN VARCHAR2
57769 --Expense Account Code Combination Identifier
57770  , p_source_29            IN NUMBER
57771 --Default Code Combination Identifier
57772  , p_source_30            IN NUMBER
57773 --Adjustment Type
57774  , p_source_35            IN VARCHAR2
57775 --Transaction Header Identifier
57776  , p_source_36            IN NUMBER
57777 --Adjustment Line Identifier
57778  , p_source_37            IN NUMBER
57779 --Distribution Type Code
57780  , p_source_38            IN VARCHAR2
57781 --Entered Amount
57782  , p_source_39            IN NUMBER
57783 --Currency Code
57784  , p_source_40            IN VARCHAR2
57785 --Gain Loss Amount
57786  , p_source_41            IN NUMBER
57787 )
57788 IS
57789 
57790 l_component_type              VARCHAR2(80);
57791 l_component_code              VARCHAR2(30);
57792 l_component_type_code         VARCHAR2(1);
57793 l_component_appl_id           INTEGER;
57794 l_amb_context_code            VARCHAR2(30);
57795 l_entity_code                 VARCHAR2(30);
57796 l_event_class_code            VARCHAR2(30);
57797 l_ae_header_id                NUMBER;
57798 l_event_type_code             VARCHAR2(30);
57799 l_line_definition_code        VARCHAR2(30);
57800 l_line_definition_owner_code  VARCHAR2(1);
57801 --
57802 -- adr variables
57803 l_segment                     VARCHAR2(30);
57804 l_ccid                        NUMBER;
57805 l_adr_transaction_coa_id      NUMBER;
57806 l_adr_accounting_coa_id       NUMBER;
57807 l_adr_flexfield_segment_code  VARCHAR2(30);
57808 l_adr_flex_value_set_id       NUMBER;
57809 l_adr_value_type_code         VARCHAR2(30);
57810 l_adr_value_combination_id    NUMBER;
57811 l_adr_value_segment_code      VARCHAR2(30);
57812 
57813 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
57814 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
57815 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
57816 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
57817 
57818 -- 4262811 Variables ------------------------------------------------------------------------------------------
57819 l_entered_amt_idx             NUMBER;
57820 l_accted_amt_idx              NUMBER;
57821 l_acc_rev_flag                VARCHAR2(1);
57822 l_accrual_line_num            NUMBER;
57826 l_num_entries                 NUMBER;
57823 l_tmp_amt                     NUMBER;
57824 l_acc_rev_natural_side_code   VARCHAR2(1);
57825 
57827 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
57828 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
57829 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
57830 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
57831 l_recog_line_1                NUMBER;
57832 l_recog_line_2                NUMBER;
57833 
57834 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
57835 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
57836 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
57837 
57838 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
57839 
57840 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
57841 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
57842 
57843 ---------------------------------------------------------------------------------------------------------------
57844 
57845 
57846 --
57847 -- bulk performance
57848 --
57849 l_balance_type_code           VARCHAR2(1);
57850 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
57851 l_log_module                  VARCHAR2(240);
57852 
57853 --
57854 -- Upgrade strategy
57855 --
57856 l_actual_upg_option           VARCHAR2(1);
57857 l_enc_upg_option           VARCHAR2(1);
57858 
57859 --
57860 BEGIN
57861 --
57862 IF g_log_enabled THEN
57863       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_235';
57864 END IF;
57865 --
57866 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
57867 
57868       trace
57869          (p_msg      => 'BEGIN of AcctLineType_235'
57870          ,p_level    => C_LEVEL_PROCEDURE
57871          ,p_module   => l_log_module);
57872 
57873 END IF;
57874 --
57875 l_component_type             := 'AMB_JLT';
57876 l_component_code             := 'FA_CIP_RET_REVAL_RESERVE_GAIN';
57877 l_component_type_code        := 'S';
57878 l_component_appl_id          :=  140;
57879 l_amb_context_code           := 'DEFAULT';
57880 l_entity_code                := 'TRANSACTIONS';
57881 l_event_class_code           := 'CIP_RETIREMENTS';
57882 l_event_type_code            := 'CIP_RETIREMENTS';
57883 l_line_definition_owner_code := 'S';
57884 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
57885 --
57886 l_balance_type_code          := 'A';
57887 l_segment                     := NULL;
57888 l_ccid                        := NULL;
57889 l_adr_transaction_coa_id      := NULL;
57890 l_adr_accounting_coa_id       := NULL;
57891 l_adr_flexfield_segment_code  := NULL;
57892 l_adr_flex_value_set_id       := NULL;
57893 l_adr_value_type_code         := NULL;
57894 l_adr_value_combination_id    := NULL;
57895 l_adr_value_segment_code      := NULL;
57896 
57897 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
57898 l_bflow_class_code           := '';    -- 4219869 Business Flow
57899 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
57900 l_budgetary_control_flag     := 'N';
57901 
57902 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
57903 l_bflow_applied_to_amt       := NULL; -- 5132302
57904 l_entered_amt_idx            := NULL;          -- 4262811
57905 l_accted_amt_idx             := NULL;          -- 4262811
57906 l_acc_rev_flag               := NULL;          -- 4262811
57907 l_accrual_line_num           := NULL;          -- 4262811
57908 l_tmp_amt                    := NULL;          -- 4262811
57909 --
57910  
57911 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
57912     l_balance_type_code <> 'B' THEN
57913 IF NVL(p_source_35,'
57914 ') =  'REVAL RSV RET' AND 
57915 p_source_41 >=  0
57916  THEN 
57917 
57918    --
57919    XLA_AE_LINES_PKG.SetNewLine;
57920 
57921    p_balance_type_code          := l_balance_type_code;
57922    -- set the flag so later we will know whether the gain loss line needs to be created
57923    
57924    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
57925      p_actual_flag :='A';
57926    END IF;
57927 
57928    --
57929    -- bulk performance
57930    --
57931    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
57932                                       p_header_num   => 0); -- 4262811
57933    --
57934    -- set accounting line options
57935    --
57936    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
57937            p_natural_side_code          => 'C'
57938          , p_gain_or_loss_flag          => 'N'
57939          , p_gl_transfer_mode_code      => 'S'
57940          , p_acct_entry_type_code       => 'A'
57941          , p_switch_side_flag           => 'Y'
57942          , p_merge_duplicate_code       => 'N'
57943          );
57944    --
57945    l_acc_rev_natural_side_code := 'D';  -- 4262811
57946    -- 
57947    --
57948    -- set accounting line type info
57949    --
57950    xla_ae_lines_pkg.SetAcctLineType
57951       (p_component_type             => l_component_type
57952       ,p_event_type_code            => l_event_type_code
57953       ,p_line_definition_owner_code => l_line_definition_owner_code
57954       ,p_line_definition_code       => l_line_definition_code
57955       ,p_accounting_line_code       => l_component_code
57956       ,p_accounting_line_type_code  => l_component_type_code
57957       ,p_accounting_line_appl_id    => l_component_appl_id
57958       ,p_amb_context_code           => l_amb_context_code
57959       ,p_entity_code                => l_entity_code
57960       ,p_event_class_code           => l_event_class_code);
57961    --
57962    -- set accounting class
57966          , p_ae_header_id           => l_ae_header_id
57963    --
57964    xla_ae_lines_pkg.SetAcctClass(
57965            p_accounting_class_code  => 'ASSET'
57967          );
57968 
57969    --
57970    -- set rounding class
57971    --
57972    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
57973                       'ASSET';
57974 
57975    --
57976    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
57977    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
57978    --
57979    -- bulk performance
57980    --
57981    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
57982 
57983    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
57984       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
57985 
57986    -- 4955764
57987    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
57988       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
57989 
57990    -- 4458381 Public Sector Enh
57991    
57992    --
57993    -- set accounting attributes for the line type
57994    --
57995    l_entered_amt_idx := 4;
57996    l_accted_amt_idx  := 6;
57997    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
57998    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
57999    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
58000    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
58001    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
58002    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
58003    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
58004    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
58005    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
58006    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
58007    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
58008    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
58009    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
58010 
58011    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
58012    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
58013 
58014    ---------------------------------------------------------------------------------------------------------------
58015    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
58016    ---------------------------------------------------------------------------------------------------------------
58017    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
58018 
58019    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
58020    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
58021 
58022    IF xla_accounting_cache_pkg.GetValueChar
58023          (p_source_code         => 'LEDGER_CATEGORY_CODE'
58024          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
58025    AND l_bflow_method_code = 'PRIOR_ENTRY'
58026 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
58027    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
58028          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
58029        )
58030    THEN
58031          xla_ae_lines_pkg.BflowUpgEntry
58032            (p_business_method_code    => l_bflow_method_code
58033            ,p_business_class_code     => l_bflow_class_code
58034            ,p_balance_type            => l_balance_type_code);
58035    ELSE
58036       NULL;
58037 -- No business flow processing for business flow method of NONE.
58038    END IF;
58039 
58040    --
58041    -- call analytical criteria
58042    --
58043    
58044    --
58045    -- call description
58046    --
58047    
58048 xla_ae_lines_pkg.SetLineDescription(
58049    p_ae_header_id => l_ae_header_id
58050   ,p_description  => Description_40 (
58051      p_application_id         => p_application_id
58052    , p_ae_header_id           => l_ae_header_id 
58053 , p_source_1 => p_source_1
58054    )
58055 );
58056 
58057 
58058    --
58059    -- call ADRs
58060    -- Bug 4922099
58061    --
58062    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
58063         (NVL(l_actual_upg_option, 'N') = 'O') OR
58064         (NVL(l_enc_upg_option, 'N') = 'O')
58065       )
58066    THEN
58067    NULL;
58068    --
58069    --
58070    
58071   l_ccid := AcctDerRule_173(
58072            p_application_id           => p_application_id
58073          , p_ae_header_id             => l_ae_header_id 
58074 , p_source_3 => p_source_3
58075 , p_source_30 => p_source_30
58076          , x_transaction_coa_id       => l_adr_transaction_coa_id
58077          , x_accounting_coa_id        => l_adr_accounting_coa_id
58078          , x_value_type_code          => l_adr_value_type_code
58079          , p_side                     => 'NA'
58080    );
58081 
58082    xla_ae_lines_pkg.set_ccid(
58083     p_code_combination_id          => l_ccid
58084   , p_value_type_code              => l_adr_value_type_code
58085   , p_transaction_coa_id           => l_adr_transaction_coa_id
58086   , p_accounting_coa_id            => l_adr_accounting_coa_id
58087   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
58088   , p_adr_type_code                => 'S'
58089   , p_component_type               => l_component_type
58090   , p_component_code               => l_component_code
58091   , p_component_type_code          => l_component_type_code
58095   );
58092   , p_component_appl_id            => l_component_appl_id
58093   , p_amb_context_code             => l_amb_context_code
58094   , p_side                         => 'NA'
58096 
58097 
58098    l_segment := AcctDerRule_168(
58099            p_application_id           => p_application_id
58100          , p_ae_header_id             => l_ae_header_id 
58101 , p_source_3 => p_source_3
58102 , p_source_29 => p_source_29
58103          , x_transaction_coa_id       => l_adr_transaction_coa_id
58104          , x_accounting_coa_id        => l_adr_accounting_coa_id
58105          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
58106          , x_flex_value_set_id        => l_adr_flex_value_set_id
58107          , x_value_type_code          => l_adr_value_type_code
58108          , x_value_combination_id     => l_adr_value_combination_id
58109          , x_value_segment_code       => l_adr_value_segment_code
58110          , p_side                     => 'NA'
58111          , p_override_seg_flag        => 'Y'
58112    );
58113 
58114    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
58115 
58116       xla_ae_lines_pkg.set_segment(
58117           p_to_segment_code         => 'GL_BALANCING'
58118         , p_segment_value           => l_segment
58119         , p_from_segment_code       => l_adr_value_segment_code
58120         , p_from_combination_id     => l_adr_value_combination_id
58121         , p_value_type_code         => l_adr_value_type_code
58122         , p_transaction_coa_id      => l_adr_transaction_coa_id
58123         , p_accounting_coa_id       => l_adr_accounting_coa_id
58124         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
58125         , p_flex_value_set_id       => l_adr_flex_value_set_id
58126         , p_adr_code                => 'FA_EXPENSE_ACCT'
58127         , p_adr_type_code           => 'S'
58128         , p_component_type          => l_component_type
58129         , p_component_code          => l_component_code
58130         , p_component_type_code     => l_component_type_code
58131         , p_component_appl_id       => l_component_appl_id
58132         , p_amb_context_code        => l_amb_context_code
58133         , p_entity_code             => 'TRANSACTIONS'
58134         , p_event_class_code        => 'CIP_RETIREMENTS'
58135         , p_side                    => 'NA'
58136         );
58137 
58138   END IF;
58139 
58140    l_segment := AcctDerRule_165(
58141            p_application_id           => p_application_id
58142          , p_ae_header_id             => l_ae_header_id 
58143 , p_source_3 => p_source_3
58144 , p_source_27 => p_source_27
58145          , x_transaction_coa_id       => l_adr_transaction_coa_id
58146          , x_accounting_coa_id        => l_adr_accounting_coa_id
58147          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
58148          , x_flex_value_set_id        => l_adr_flex_value_set_id
58149          , x_value_type_code          => l_adr_value_type_code
58150          , x_value_combination_id     => l_adr_value_combination_id
58151          , x_value_segment_code       => l_adr_value_segment_code
58152          , p_side                     => 'NA'
58153          , p_override_seg_flag        => 'Y'
58154    );
58155 
58156    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
58157 
58158       xla_ae_lines_pkg.set_segment(
58159           p_to_segment_code         => 'GL_ACCOUNT'
58160         , p_segment_value           => l_segment
58161         , p_from_segment_code       => l_adr_value_segment_code
58162         , p_from_combination_id     => l_adr_value_combination_id
58163         , p_value_type_code         => l_adr_value_type_code
58164         , p_transaction_coa_id      => l_adr_transaction_coa_id
58165         , p_accounting_coa_id       => l_adr_accounting_coa_id
58166         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
58167         , p_flex_value_set_id       => l_adr_flex_value_set_id
58168         , p_adr_code                => 'FA_REVAL_RES_RET_GAIN_SEGMENT'
58169         , p_adr_type_code           => 'S'
58170         , p_component_type          => l_component_type
58171         , p_component_code          => l_component_code
58172         , p_component_type_code     => l_component_type_code
58173         , p_component_appl_id       => l_component_appl_id
58174         , p_amb_context_code        => l_amb_context_code
58175         , p_entity_code             => 'TRANSACTIONS'
58176         , p_event_class_code        => 'CIP_RETIREMENTS'
58177         , p_side                    => 'NA'
58178         );
58179 
58180   END IF;
58181 
58182    --
58183    --
58184    END IF;
58185    --
58186    -- Bug 4922099
58187    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
58188           (NVL(l_enc_upg_option, 'N') = 'O')
58189         ) AND
58190         (l_bflow_method_code = 'PRIOR_ENTRY')
58191       )
58192    THEN
58193       IF
58194       --
58195       1 = 2
58196       --
58197       THEN
58198       xla_accounting_err_pkg.build_message
58199                                     (p_appli_s_name            => 'XLA'
58200                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
58201                                     ,p_token_1                 => 'LINE_NUMBER'
58202                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
58203                                     ,p_token_2                 => 'LINE_TYPE_NAME'
58204                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
58205                                                                              l_component_type
58206                                                                             ,l_component_code
58207                                                                             ,l_component_type_code
58208                                                                             ,l_component_appl_id
58212                                                                            )
58209                                                                             ,l_amb_context_code
58210                                                                             ,l_entity_code
58211                                                                             ,l_event_class_code
58213                                     ,p_token_3                 => 'OWNER'
58214                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
58215                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
58216                                                                           ,p_lookup_code    => l_component_type_code
58217                                                                          )
58218                                     ,p_token_4                 => 'PRODUCT_NAME'
58219                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
58220                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
58221                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
58222                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
58223                                     ,p_ae_header_id            =>  NULL
58224                                        );
58225 
58226         IF (C_LEVEL_ERROR>= g_log_level) THEN
58227                  trace
58228                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
58229                       ,p_level    => C_LEVEL_ERROR
58230                       ,p_module   => l_log_module);
58231         END IF;
58232       END IF;
58233    END IF;
58234    --
58235    --
58236    ------------------------------------------------------------------------------------------------
58237    -- 4219869 Business Flow
58238    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
58239    -- Prior Entry.  Currently, the following code is always generated.
58240    ------------------------------------------------------------------------------------------------
58241    XLA_AE_LINES_PKG.ValidateCurrentLine;
58242 
58243    ------------------------------------------------------------------------------------
58244    -- 4219869 Business Flow
58245    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
58246    ------------------------------------------------------------------------------------
58247    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
58248 
58249    ----------------------------------------------------------------------------------
58250    -- 4219869 Business Flow
58251    -- Update journal entry status -- Need to generate this within IF <condition>
58252    ----------------------------------------------------------------------------------
58253    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
58254          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
58255          ,p_balance_type_code => l_balance_type_code
58256          );
58257 
58258    -------------------------------------------------------------------------------------------
58259    -- 4262811 - Generate the Accrual Reversal lines
58260    -------------------------------------------------------------------------------------------
58261    BEGIN
58262       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
58263                               (g_array_event(p_event_id).array_value_num('header_index'));
58264       IF l_acc_rev_flag IS NULL THEN
58265          l_acc_rev_flag := 'N';
58266       END IF;
58267    EXCEPTION
58268       WHEN OTHERS THEN
58269          l_acc_rev_flag := 'N';
58270    END;
58271    --
58272    IF (l_acc_rev_flag = 'Y') THEN
58273 
58274        -- 4645092  ------------------------------------------------------------------------------
58275        -- To allow MPA report to determine if it should generate report process
58276        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
58277        ------------------------------------------------------------------------------------------
58278 
58279        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
58280        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
58281    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
58282    -- call ADRs
58283    -- Bug 4922099
58284    --
58285    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
58286         (NVL(l_actual_upg_option, 'N') = 'O') OR
58287         (NVL(l_enc_upg_option, 'N') = 'O')
58288       )
58289    THEN
58290    NULL;
58291    --
58292    --
58293    
58294   l_ccid := AcctDerRule_173(
58295            p_application_id           => p_application_id
58296          , p_ae_header_id             => l_ae_header_id 
58297 , p_source_3 => p_source_3
58298 , p_source_30 => p_source_30
58299          , x_transaction_coa_id       => l_adr_transaction_coa_id
58300          , x_accounting_coa_id        => l_adr_accounting_coa_id
58301          , x_value_type_code          => l_adr_value_type_code
58302          , p_side                     => 'NA'
58303    );
58304 
58305    xla_ae_lines_pkg.set_ccid(
58306     p_code_combination_id          => l_ccid
58307   , p_value_type_code              => l_adr_value_type_code
58308   , p_transaction_coa_id           => l_adr_transaction_coa_id
58309   , p_accounting_coa_id            => l_adr_accounting_coa_id
58310   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
58311   , p_adr_type_code                => 'S'
58312   , p_component_type               => l_component_type
58313   , p_component_code               => l_component_code
58314   , p_component_type_code          => l_component_type_code
58315   , p_component_appl_id            => l_component_appl_id
58316   , p_amb_context_code             => l_amb_context_code
58320 
58317   , p_side                         => 'NA'
58318   );
58319 
58321    l_segment := AcctDerRule_168(
58322            p_application_id           => p_application_id
58323          , p_ae_header_id             => l_ae_header_id 
58324 , p_source_3 => p_source_3
58325 , p_source_29 => p_source_29
58326          , x_transaction_coa_id       => l_adr_transaction_coa_id
58327          , x_accounting_coa_id        => l_adr_accounting_coa_id
58328          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
58329          , x_flex_value_set_id        => l_adr_flex_value_set_id
58330          , x_value_type_code          => l_adr_value_type_code
58331          , x_value_combination_id     => l_adr_value_combination_id
58332          , x_value_segment_code       => l_adr_value_segment_code
58333          , p_side                     => 'NA'
58334          , p_override_seg_flag        => 'Y'
58335    );
58336 
58337    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
58338 
58339       xla_ae_lines_pkg.set_segment(
58340           p_to_segment_code         => 'GL_BALANCING'
58341         , p_segment_value           => l_segment
58342         , p_from_segment_code       => l_adr_value_segment_code
58343         , p_from_combination_id     => l_adr_value_combination_id
58344         , p_value_type_code         => l_adr_value_type_code
58345         , p_transaction_coa_id      => l_adr_transaction_coa_id
58346         , p_accounting_coa_id       => l_adr_accounting_coa_id
58347         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
58348         , p_flex_value_set_id       => l_adr_flex_value_set_id
58349         , p_adr_code                => 'FA_EXPENSE_ACCT'
58350         , p_adr_type_code           => 'S'
58351         , p_component_type          => l_component_type
58352         , p_component_code          => l_component_code
58353         , p_component_type_code     => l_component_type_code
58354         , p_component_appl_id       => l_component_appl_id
58355         , p_amb_context_code        => l_amb_context_code
58356         , p_entity_code             => 'TRANSACTIONS'
58357         , p_event_class_code        => 'CIP_RETIREMENTS'
58358         , p_side                    => 'NA'
58359         );
58360 
58361   END IF;
58362 
58363    l_segment := AcctDerRule_165(
58364            p_application_id           => p_application_id
58365          , p_ae_header_id             => l_ae_header_id 
58366 , p_source_3 => p_source_3
58367 , p_source_27 => p_source_27
58368          , x_transaction_coa_id       => l_adr_transaction_coa_id
58369          , x_accounting_coa_id        => l_adr_accounting_coa_id
58370          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
58371          , x_flex_value_set_id        => l_adr_flex_value_set_id
58372          , x_value_type_code          => l_adr_value_type_code
58373          , x_value_combination_id     => l_adr_value_combination_id
58374          , x_value_segment_code       => l_adr_value_segment_code
58375          , p_side                     => 'NA'
58376          , p_override_seg_flag        => 'Y'
58377    );
58378 
58379    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
58380 
58381       xla_ae_lines_pkg.set_segment(
58382           p_to_segment_code         => 'GL_ACCOUNT'
58383         , p_segment_value           => l_segment
58384         , p_from_segment_code       => l_adr_value_segment_code
58385         , p_from_combination_id     => l_adr_value_combination_id
58386         , p_value_type_code         => l_adr_value_type_code
58387         , p_transaction_coa_id      => l_adr_transaction_coa_id
58388         , p_accounting_coa_id       => l_adr_accounting_coa_id
58389         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
58390         , p_flex_value_set_id       => l_adr_flex_value_set_id
58391         , p_adr_code                => 'FA_REVAL_RES_RET_GAIN_SEGMENT'
58392         , p_adr_type_code           => 'S'
58393         , p_component_type          => l_component_type
58394         , p_component_code          => l_component_code
58395         , p_component_type_code     => l_component_type_code
58396         , p_component_appl_id       => l_component_appl_id
58397         , p_amb_context_code        => l_amb_context_code
58398         , p_entity_code             => 'TRANSACTIONS'
58399         , p_event_class_code        => 'CIP_RETIREMENTS'
58400         , p_side                    => 'NA'
58401         );
58402 
58403   END IF;
58404 
58405    --
58406    --
58407    END IF;
58408 
58409        --
58410        -- Update the line information that should be overwritten
58411        --
58412        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
58413                                          p_header_num   => 1);
58414        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
58415 
58416        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
58417 
58418        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
58419           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
58420        END IF;
58421 
58422       --
58423       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
58424       --
58425       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
58426           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
58427       ELSE
58428           ---------------------------------------------------------------------------------------------------
58429           -- 4262811a Switch Sign
58430           ---------------------------------------------------------------------------------------------------
58431           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
58435                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
58432           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
58433                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
58434           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
58436           -- 5132302
58437           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
58438                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
58439 
58440       END IF;
58441 
58442       -- 4955764
58443       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
58444       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
58445 
58446 
58447       XLA_AE_LINES_PKG.ValidateCurrentLine;
58448       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
58449 
58450       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
58451                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
58452                ,p_balance_type_code => l_balance_type_code);
58453 
58454    END IF;
58455 
58456    -----------------------------------------------------------------------------------------
58457    -- 4262811 Multiperiod Accounting
58458    -----------------------------------------------------------------------------------------
58459      -- No MPA option is assigned.
58460 
58461 
58462 END IF;
58463 END IF;
58464 --
58465 
58466 --
58467 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
58468    trace
58469       (p_msg      => 'END of AcctLineType_235'
58470       ,p_level    => C_LEVEL_PROCEDURE
58471       ,p_module   => l_log_module);
58472 END IF;
58473 --
58474 EXCEPTION
58475   WHEN xla_exceptions_pkg.application_exception THEN
58476       RAISE;
58477   WHEN OTHERS THEN
58478        xla_exceptions_pkg.raise_message
58479            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_235');
58480 END AcctLineType_235;
58481 --
58482 
58483 ---------------------------------------
58484 --
58485 -- PRIVATE FUNCTION
58486 --         AcctLineType_236
58487 --
58488 ---------------------------------------
58489 PROCEDURE AcctLineType_236 (
58490   p_application_id        IN NUMBER
58491  ,p_event_id              IN NUMBER
58492  ,p_calculate_acctd_flag  IN VARCHAR2
58493  ,p_calculate_g_l_flag    IN VARCHAR2
58494  ,p_actual_flag           IN OUT VARCHAR2
58495  ,p_balance_type_code     OUT VARCHAR2
58496  ,p_gain_or_loss_ref      OUT VARCHAR2
58497  
58498 --Period Close Date
58499  , p_source_1            IN DATE
58500 --Generated Code Combination Identifier
58501  , p_source_3            IN NUMBER
58502 --Revaluation Reserve Retired Loss Account
58503  , p_source_28            IN VARCHAR2
58504 --Expense Account Code Combination Identifier
58505  , p_source_29            IN NUMBER
58506 --Default Code Combination Identifier
58507  , p_source_30            IN NUMBER
58508 --Adjustment Type
58509  , p_source_35            IN VARCHAR2
58510 --Transaction Header Identifier
58511  , p_source_36            IN NUMBER
58512 --Adjustment Line Identifier
58513  , p_source_37            IN NUMBER
58514 --Distribution Type Code
58515  , p_source_38            IN VARCHAR2
58516 --Entered Amount
58517  , p_source_39            IN NUMBER
58518 --Currency Code
58519  , p_source_40            IN VARCHAR2
58520 --Gain Loss Amount
58521  , p_source_41            IN NUMBER
58522 )
58523 IS
58524 
58525 l_component_type              VARCHAR2(80);
58526 l_component_code              VARCHAR2(30);
58527 l_component_type_code         VARCHAR2(1);
58528 l_component_appl_id           INTEGER;
58529 l_amb_context_code            VARCHAR2(30);
58530 l_entity_code                 VARCHAR2(30);
58531 l_event_class_code            VARCHAR2(30);
58532 l_ae_header_id                NUMBER;
58533 l_event_type_code             VARCHAR2(30);
58534 l_line_definition_code        VARCHAR2(30);
58535 l_line_definition_owner_code  VARCHAR2(1);
58536 --
58537 -- adr variables
58538 l_segment                     VARCHAR2(30);
58539 l_ccid                        NUMBER;
58540 l_adr_transaction_coa_id      NUMBER;
58541 l_adr_accounting_coa_id       NUMBER;
58542 l_adr_flexfield_segment_code  VARCHAR2(30);
58543 l_adr_flex_value_set_id       NUMBER;
58544 l_adr_value_type_code         VARCHAR2(30);
58545 l_adr_value_combination_id    NUMBER;
58546 l_adr_value_segment_code      VARCHAR2(30);
58547 
58548 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
58549 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
58550 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
58551 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
58552 
58553 -- 4262811 Variables ------------------------------------------------------------------------------------------
58554 l_entered_amt_idx             NUMBER;
58555 l_accted_amt_idx              NUMBER;
58556 l_acc_rev_flag                VARCHAR2(1);
58557 l_accrual_line_num            NUMBER;
58558 l_tmp_amt                     NUMBER;
58559 l_acc_rev_natural_side_code   VARCHAR2(1);
58560 
58561 l_num_entries                 NUMBER;
58562 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
58563 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
58564 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
58565 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
58566 l_recog_line_1                NUMBER;
58567 l_recog_line_2                NUMBER;
58568 
58572 
58569 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
58570 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
58571 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
58573 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
58574 
58575 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
58576 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
58577 
58578 ---------------------------------------------------------------------------------------------------------------
58579 
58580 
58581 --
58582 -- bulk performance
58583 --
58584 l_balance_type_code           VARCHAR2(1);
58585 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
58586 l_log_module                  VARCHAR2(240);
58587 
58588 --
58589 -- Upgrade strategy
58590 --
58591 l_actual_upg_option           VARCHAR2(1);
58592 l_enc_upg_option           VARCHAR2(1);
58593 
58594 --
58595 BEGIN
58596 --
58597 IF g_log_enabled THEN
58598       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_236';
58599 END IF;
58600 --
58601 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
58602 
58603       trace
58604          (p_msg      => 'BEGIN of AcctLineType_236'
58605          ,p_level    => C_LEVEL_PROCEDURE
58606          ,p_module   => l_log_module);
58607 
58608 END IF;
58609 --
58610 l_component_type             := 'AMB_JLT';
58611 l_component_code             := 'FA_CIP_RET_REVAL_RESERVE_GAIN';
58612 l_component_type_code        := 'S';
58613 l_component_appl_id          :=  140;
58614 l_amb_context_code           := 'DEFAULT';
58615 l_entity_code                := 'TRANSACTIONS';
58616 l_event_class_code           := 'CIP_RETIREMENTS';
58617 l_event_type_code            := 'CIP_REINSTATEMENTS';
58618 l_line_definition_owner_code := 'S';
58619 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
58620 --
58621 l_balance_type_code          := 'A';
58622 l_segment                     := NULL;
58623 l_ccid                        := NULL;
58624 l_adr_transaction_coa_id      := NULL;
58625 l_adr_accounting_coa_id       := NULL;
58626 l_adr_flexfield_segment_code  := NULL;
58627 l_adr_flex_value_set_id       := NULL;
58628 l_adr_value_type_code         := NULL;
58629 l_adr_value_combination_id    := NULL;
58630 l_adr_value_segment_code      := NULL;
58631 
58632 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
58633 l_bflow_class_code           := '';    -- 4219869 Business Flow
58634 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
58635 l_budgetary_control_flag     := 'N';
58636 
58637 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
58638 l_bflow_applied_to_amt       := NULL; -- 5132302
58639 l_entered_amt_idx            := NULL;          -- 4262811
58640 l_accted_amt_idx             := NULL;          -- 4262811
58641 l_acc_rev_flag               := NULL;          -- 4262811
58642 l_accrual_line_num           := NULL;          -- 4262811
58643 l_tmp_amt                    := NULL;          -- 4262811
58644 --
58645  
58646 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
58647     l_balance_type_code <> 'B' THEN
58648 IF NVL(p_source_35,'
58649 ') =  'REVAL RSV RET' AND 
58650 p_source_41 >=  0
58651  THEN 
58652 
58653    --
58654    XLA_AE_LINES_PKG.SetNewLine;
58655 
58656    p_balance_type_code          := l_balance_type_code;
58657    -- set the flag so later we will know whether the gain loss line needs to be created
58658    
58659    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
58660      p_actual_flag :='A';
58661    END IF;
58662 
58663    --
58664    -- bulk performance
58665    --
58666    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
58667                                       p_header_num   => 0); -- 4262811
58668    --
58669    -- set accounting line options
58670    --
58671    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
58672            p_natural_side_code          => 'C'
58673          , p_gain_or_loss_flag          => 'N'
58674          , p_gl_transfer_mode_code      => 'S'
58675          , p_acct_entry_type_code       => 'A'
58676          , p_switch_side_flag           => 'Y'
58677          , p_merge_duplicate_code       => 'N'
58678          );
58679    --
58680    l_acc_rev_natural_side_code := 'D';  -- 4262811
58681    -- 
58682    --
58683    -- set accounting line type info
58684    --
58685    xla_ae_lines_pkg.SetAcctLineType
58686       (p_component_type             => l_component_type
58687       ,p_event_type_code            => l_event_type_code
58688       ,p_line_definition_owner_code => l_line_definition_owner_code
58689       ,p_line_definition_code       => l_line_definition_code
58690       ,p_accounting_line_code       => l_component_code
58691       ,p_accounting_line_type_code  => l_component_type_code
58692       ,p_accounting_line_appl_id    => l_component_appl_id
58693       ,p_amb_context_code           => l_amb_context_code
58694       ,p_entity_code                => l_entity_code
58695       ,p_event_class_code           => l_event_class_code);
58696    --
58697    -- set accounting class
58698    --
58699    xla_ae_lines_pkg.SetAcctClass(
58700            p_accounting_class_code  => 'ASSET'
58701          , p_ae_header_id           => l_ae_header_id
58702          );
58703 
58704    --
58705    -- set rounding class
58706    --
58707    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
58708                       'ASSET';
58709 
58710    --
58714    -- bulk performance
58711    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
58712    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
58713    --
58715    --
58716    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
58717 
58718    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
58719       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
58720 
58721    -- 4955764
58722    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
58723       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
58724 
58725    -- 4458381 Public Sector Enh
58726    
58727    --
58728    -- set accounting attributes for the line type
58729    --
58730    l_entered_amt_idx := 4;
58731    l_accted_amt_idx  := 6;
58732    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
58733    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
58734    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
58735    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
58736    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
58737    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
58738    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
58739    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
58740    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
58741    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
58742    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
58743    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
58744    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
58745 
58746    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
58747    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
58748 
58749    ---------------------------------------------------------------------------------------------------------------
58750    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
58751    ---------------------------------------------------------------------------------------------------------------
58752    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
58753 
58754    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
58755    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
58756 
58757    IF xla_accounting_cache_pkg.GetValueChar
58758          (p_source_code         => 'LEDGER_CATEGORY_CODE'
58759          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
58760    AND l_bflow_method_code = 'PRIOR_ENTRY'
58761 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
58762    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
58763          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
58764        )
58765    THEN
58766          xla_ae_lines_pkg.BflowUpgEntry
58767            (p_business_method_code    => l_bflow_method_code
58768            ,p_business_class_code     => l_bflow_class_code
58769            ,p_balance_type            => l_balance_type_code);
58770    ELSE
58771       NULL;
58772 -- No business flow processing for business flow method of NONE.
58773    END IF;
58774 
58775    --
58776    -- call analytical criteria
58777    --
58778    
58779    --
58780    -- call description
58781    --
58782    
58783 xla_ae_lines_pkg.SetLineDescription(
58784    p_ae_header_id => l_ae_header_id
58785   ,p_description  => Description_40 (
58786      p_application_id         => p_application_id
58787    , p_ae_header_id           => l_ae_header_id 
58788 , p_source_1 => p_source_1
58789    )
58790 );
58791 
58792 
58793    --
58794    -- call ADRs
58795    -- Bug 4922099
58796    --
58797    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
58798         (NVL(l_actual_upg_option, 'N') = 'O') OR
58799         (NVL(l_enc_upg_option, 'N') = 'O')
58800       )
58801    THEN
58802    NULL;
58803    --
58804    --
58805    
58806   l_ccid := AcctDerRule_173(
58807            p_application_id           => p_application_id
58808          , p_ae_header_id             => l_ae_header_id 
58809 , p_source_3 => p_source_3
58810 , p_source_30 => p_source_30
58811          , x_transaction_coa_id       => l_adr_transaction_coa_id
58812          , x_accounting_coa_id        => l_adr_accounting_coa_id
58813          , x_value_type_code          => l_adr_value_type_code
58814          , p_side                     => 'NA'
58815    );
58816 
58817    xla_ae_lines_pkg.set_ccid(
58818     p_code_combination_id          => l_ccid
58819   , p_value_type_code              => l_adr_value_type_code
58820   , p_transaction_coa_id           => l_adr_transaction_coa_id
58821   , p_accounting_coa_id            => l_adr_accounting_coa_id
58822   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
58823   , p_adr_type_code                => 'S'
58824   , p_component_type               => l_component_type
58825   , p_component_code               => l_component_code
58826   , p_component_type_code          => l_component_type_code
58827   , p_component_appl_id            => l_component_appl_id
58828   , p_amb_context_code             => l_amb_context_code
58829   , p_side                         => 'NA'
58830   );
58831 
58832 
58833    l_segment := AcctDerRule_168(
58834            p_application_id           => p_application_id
58835          , p_ae_header_id             => l_ae_header_id 
58836 , p_source_3 => p_source_3
58837 , p_source_29 => p_source_29
58841          , x_flex_value_set_id        => l_adr_flex_value_set_id
58838          , x_transaction_coa_id       => l_adr_transaction_coa_id
58839          , x_accounting_coa_id        => l_adr_accounting_coa_id
58840          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
58842          , x_value_type_code          => l_adr_value_type_code
58843          , x_value_combination_id     => l_adr_value_combination_id
58844          , x_value_segment_code       => l_adr_value_segment_code
58845          , p_side                     => 'NA'
58846          , p_override_seg_flag        => 'Y'
58847    );
58848 
58849    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
58850 
58851       xla_ae_lines_pkg.set_segment(
58852           p_to_segment_code         => 'GL_BALANCING'
58853         , p_segment_value           => l_segment
58854         , p_from_segment_code       => l_adr_value_segment_code
58855         , p_from_combination_id     => l_adr_value_combination_id
58856         , p_value_type_code         => l_adr_value_type_code
58857         , p_transaction_coa_id      => l_adr_transaction_coa_id
58858         , p_accounting_coa_id       => l_adr_accounting_coa_id
58859         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
58860         , p_flex_value_set_id       => l_adr_flex_value_set_id
58861         , p_adr_code                => 'FA_EXPENSE_ACCT'
58862         , p_adr_type_code           => 'S'
58863         , p_component_type          => l_component_type
58864         , p_component_code          => l_component_code
58865         , p_component_type_code     => l_component_type_code
58866         , p_component_appl_id       => l_component_appl_id
58867         , p_amb_context_code        => l_amb_context_code
58868         , p_entity_code             => 'TRANSACTIONS'
58869         , p_event_class_code        => 'CIP_RETIREMENTS'
58870         , p_side                    => 'NA'
58871         );
58872 
58873   END IF;
58874 
58875    l_segment := AcctDerRule_166(
58876            p_application_id           => p_application_id
58877          , p_ae_header_id             => l_ae_header_id 
58878 , p_source_3 => p_source_3
58879 , p_source_28 => p_source_28
58880          , x_transaction_coa_id       => l_adr_transaction_coa_id
58881          , x_accounting_coa_id        => l_adr_accounting_coa_id
58882          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
58883          , x_flex_value_set_id        => l_adr_flex_value_set_id
58884          , x_value_type_code          => l_adr_value_type_code
58885          , x_value_combination_id     => l_adr_value_combination_id
58886          , x_value_segment_code       => l_adr_value_segment_code
58887          , p_side                     => 'NA'
58888          , p_override_seg_flag        => 'Y'
58889    );
58890 
58891    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
58892 
58893       xla_ae_lines_pkg.set_segment(
58894           p_to_segment_code         => 'GL_ACCOUNT'
58895         , p_segment_value           => l_segment
58896         , p_from_segment_code       => l_adr_value_segment_code
58897         , p_from_combination_id     => l_adr_value_combination_id
58898         , p_value_type_code         => l_adr_value_type_code
58899         , p_transaction_coa_id      => l_adr_transaction_coa_id
58900         , p_accounting_coa_id       => l_adr_accounting_coa_id
58901         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
58902         , p_flex_value_set_id       => l_adr_flex_value_set_id
58903         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
58904         , p_adr_type_code           => 'S'
58905         , p_component_type          => l_component_type
58906         , p_component_code          => l_component_code
58907         , p_component_type_code     => l_component_type_code
58908         , p_component_appl_id       => l_component_appl_id
58909         , p_amb_context_code        => l_amb_context_code
58910         , p_entity_code             => 'TRANSACTIONS'
58911         , p_event_class_code        => 'CIP_RETIREMENTS'
58912         , p_side                    => 'NA'
58913         );
58914 
58915   END IF;
58916 
58917    --
58918    --
58919    END IF;
58920    --
58921    -- Bug 4922099
58922    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
58923           (NVL(l_enc_upg_option, 'N') = 'O')
58924         ) AND
58925         (l_bflow_method_code = 'PRIOR_ENTRY')
58926       )
58927    THEN
58928       IF
58929       --
58930       1 = 2
58931       --
58932       THEN
58933       xla_accounting_err_pkg.build_message
58934                                     (p_appli_s_name            => 'XLA'
58935                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
58936                                     ,p_token_1                 => 'LINE_NUMBER'
58937                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
58938                                     ,p_token_2                 => 'LINE_TYPE_NAME'
58939                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
58940                                                                              l_component_type
58941                                                                             ,l_component_code
58942                                                                             ,l_component_type_code
58943                                                                             ,l_component_appl_id
58944                                                                             ,l_amb_context_code
58945                                                                             ,l_entity_code
58946                                                                             ,l_event_class_code
58947                                                                            )
58948                                     ,p_token_3                 => 'OWNER'
58952                                                                          )
58949                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
58950                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
58951                                                                           ,p_lookup_code    => l_component_type_code
58953                                     ,p_token_4                 => 'PRODUCT_NAME'
58954                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
58955                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
58956                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
58957                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
58958                                     ,p_ae_header_id            =>  NULL
58959                                        );
58960 
58961         IF (C_LEVEL_ERROR>= g_log_level) THEN
58962                  trace
58963                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
58964                       ,p_level    => C_LEVEL_ERROR
58965                       ,p_module   => l_log_module);
58966         END IF;
58967       END IF;
58968    END IF;
58969    --
58970    --
58971    ------------------------------------------------------------------------------------------------
58972    -- 4219869 Business Flow
58973    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
58974    -- Prior Entry.  Currently, the following code is always generated.
58975    ------------------------------------------------------------------------------------------------
58976    XLA_AE_LINES_PKG.ValidateCurrentLine;
58977 
58978    ------------------------------------------------------------------------------------
58979    -- 4219869 Business Flow
58980    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
58981    ------------------------------------------------------------------------------------
58982    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
58983 
58984    ----------------------------------------------------------------------------------
58985    -- 4219869 Business Flow
58986    -- Update journal entry status -- Need to generate this within IF <condition>
58987    ----------------------------------------------------------------------------------
58988    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
58989          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
58990          ,p_balance_type_code => l_balance_type_code
58991          );
58992 
58993    -------------------------------------------------------------------------------------------
58994    -- 4262811 - Generate the Accrual Reversal lines
58995    -------------------------------------------------------------------------------------------
58996    BEGIN
58997       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
58998                               (g_array_event(p_event_id).array_value_num('header_index'));
58999       IF l_acc_rev_flag IS NULL THEN
59000          l_acc_rev_flag := 'N';
59001       END IF;
59002    EXCEPTION
59003       WHEN OTHERS THEN
59004          l_acc_rev_flag := 'N';
59005    END;
59006    --
59007    IF (l_acc_rev_flag = 'Y') THEN
59008 
59009        -- 4645092  ------------------------------------------------------------------------------
59010        -- To allow MPA report to determine if it should generate report process
59011        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
59012        ------------------------------------------------------------------------------------------
59013 
59014        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
59015        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
59016    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
59017    -- call ADRs
59018    -- Bug 4922099
59019    --
59020    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
59021         (NVL(l_actual_upg_option, 'N') = 'O') OR
59022         (NVL(l_enc_upg_option, 'N') = 'O')
59023       )
59024    THEN
59025    NULL;
59026    --
59027    --
59028    
59029   l_ccid := AcctDerRule_173(
59030            p_application_id           => p_application_id
59031          , p_ae_header_id             => l_ae_header_id 
59032 , p_source_3 => p_source_3
59033 , p_source_30 => p_source_30
59034          , x_transaction_coa_id       => l_adr_transaction_coa_id
59035          , x_accounting_coa_id        => l_adr_accounting_coa_id
59036          , x_value_type_code          => l_adr_value_type_code
59037          , p_side                     => 'NA'
59038    );
59039 
59040    xla_ae_lines_pkg.set_ccid(
59041     p_code_combination_id          => l_ccid
59042   , p_value_type_code              => l_adr_value_type_code
59043   , p_transaction_coa_id           => l_adr_transaction_coa_id
59044   , p_accounting_coa_id            => l_adr_accounting_coa_id
59045   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
59046   , p_adr_type_code                => 'S'
59047   , p_component_type               => l_component_type
59048   , p_component_code               => l_component_code
59049   , p_component_type_code          => l_component_type_code
59050   , p_component_appl_id            => l_component_appl_id
59051   , p_amb_context_code             => l_amb_context_code
59052   , p_side                         => 'NA'
59053   );
59054 
59055 
59056    l_segment := AcctDerRule_168(
59057            p_application_id           => p_application_id
59058          , p_ae_header_id             => l_ae_header_id 
59059 , p_source_3 => p_source_3
59060 , p_source_29 => p_source_29
59061          , x_transaction_coa_id       => l_adr_transaction_coa_id
59065          , x_value_type_code          => l_adr_value_type_code
59062          , x_accounting_coa_id        => l_adr_accounting_coa_id
59063          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
59064          , x_flex_value_set_id        => l_adr_flex_value_set_id
59066          , x_value_combination_id     => l_adr_value_combination_id
59067          , x_value_segment_code       => l_adr_value_segment_code
59068          , p_side                     => 'NA'
59069          , p_override_seg_flag        => 'Y'
59070    );
59071 
59072    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
59073 
59074       xla_ae_lines_pkg.set_segment(
59075           p_to_segment_code         => 'GL_BALANCING'
59076         , p_segment_value           => l_segment
59077         , p_from_segment_code       => l_adr_value_segment_code
59078         , p_from_combination_id     => l_adr_value_combination_id
59079         , p_value_type_code         => l_adr_value_type_code
59080         , p_transaction_coa_id      => l_adr_transaction_coa_id
59081         , p_accounting_coa_id       => l_adr_accounting_coa_id
59082         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
59083         , p_flex_value_set_id       => l_adr_flex_value_set_id
59084         , p_adr_code                => 'FA_EXPENSE_ACCT'
59085         , p_adr_type_code           => 'S'
59086         , p_component_type          => l_component_type
59087         , p_component_code          => l_component_code
59088         , p_component_type_code     => l_component_type_code
59089         , p_component_appl_id       => l_component_appl_id
59090         , p_amb_context_code        => l_amb_context_code
59091         , p_entity_code             => 'TRANSACTIONS'
59092         , p_event_class_code        => 'CIP_RETIREMENTS'
59093         , p_side                    => 'NA'
59094         );
59095 
59096   END IF;
59097 
59098    l_segment := AcctDerRule_166(
59099            p_application_id           => p_application_id
59100          , p_ae_header_id             => l_ae_header_id 
59101 , p_source_3 => p_source_3
59102 , p_source_28 => p_source_28
59103          , x_transaction_coa_id       => l_adr_transaction_coa_id
59104          , x_accounting_coa_id        => l_adr_accounting_coa_id
59105          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
59106          , x_flex_value_set_id        => l_adr_flex_value_set_id
59107          , x_value_type_code          => l_adr_value_type_code
59108          , x_value_combination_id     => l_adr_value_combination_id
59109          , x_value_segment_code       => l_adr_value_segment_code
59110          , p_side                     => 'NA'
59111          , p_override_seg_flag        => 'Y'
59112    );
59113 
59114    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
59115 
59116       xla_ae_lines_pkg.set_segment(
59117           p_to_segment_code         => 'GL_ACCOUNT'
59118         , p_segment_value           => l_segment
59119         , p_from_segment_code       => l_adr_value_segment_code
59120         , p_from_combination_id     => l_adr_value_combination_id
59121         , p_value_type_code         => l_adr_value_type_code
59122         , p_transaction_coa_id      => l_adr_transaction_coa_id
59123         , p_accounting_coa_id       => l_adr_accounting_coa_id
59124         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
59125         , p_flex_value_set_id       => l_adr_flex_value_set_id
59126         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
59127         , p_adr_type_code           => 'S'
59128         , p_component_type          => l_component_type
59129         , p_component_code          => l_component_code
59130         , p_component_type_code     => l_component_type_code
59131         , p_component_appl_id       => l_component_appl_id
59132         , p_amb_context_code        => l_amb_context_code
59133         , p_entity_code             => 'TRANSACTIONS'
59134         , p_event_class_code        => 'CIP_RETIREMENTS'
59135         , p_side                    => 'NA'
59136         );
59137 
59138   END IF;
59139 
59140    --
59141    --
59142    END IF;
59143 
59144        --
59145        -- Update the line information that should be overwritten
59146        --
59147        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
59148                                          p_header_num   => 1);
59149        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
59150 
59151        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
59152 
59153        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
59154           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
59155        END IF;
59156 
59157       --
59158       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
59159       --
59160       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
59161           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
59162       ELSE
59163           ---------------------------------------------------------------------------------------------------
59164           -- 4262811a Switch Sign
59165           ---------------------------------------------------------------------------------------------------
59166           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
59167           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
59168                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
59169           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
59170                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
59171           -- 5132302
59175       END IF;
59172           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
59173                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
59174 
59176 
59177       -- 4955764
59178       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
59179       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
59180 
59181 
59182       XLA_AE_LINES_PKG.ValidateCurrentLine;
59183       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
59184 
59185       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
59186                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
59187                ,p_balance_type_code => l_balance_type_code);
59188 
59189    END IF;
59190 
59191    -----------------------------------------------------------------------------------------
59192    -- 4262811 Multiperiod Accounting
59193    -----------------------------------------------------------------------------------------
59194      -- No MPA option is assigned.
59195 
59196 
59197 END IF;
59198 END IF;
59199 --
59200 
59201 --
59202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59203    trace
59204       (p_msg      => 'END of AcctLineType_236'
59205       ,p_level    => C_LEVEL_PROCEDURE
59206       ,p_module   => l_log_module);
59207 END IF;
59208 --
59209 EXCEPTION
59210   WHEN xla_exceptions_pkg.application_exception THEN
59211       RAISE;
59212   WHEN OTHERS THEN
59213        xla_exceptions_pkg.raise_message
59214            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_236');
59215 END AcctLineType_236;
59216 --
59217 
59218 ---------------------------------------
59219 --
59220 -- PRIVATE FUNCTION
59221 --         AcctLineType_237
59222 --
59223 ---------------------------------------
59224 PROCEDURE AcctLineType_237 (
59225   p_application_id        IN NUMBER
59226  ,p_event_id              IN NUMBER
59227  ,p_calculate_acctd_flag  IN VARCHAR2
59228  ,p_calculate_g_l_flag    IN VARCHAR2
59229  ,p_actual_flag           IN OUT VARCHAR2
59230  ,p_balance_type_code     OUT VARCHAR2
59231  ,p_gain_or_loss_ref      OUT VARCHAR2
59232  
59233 --Period Close Date
59234  , p_source_1            IN DATE
59235 --Generated Code Combination Identifier
59236  , p_source_3            IN NUMBER
59237 --Revaluation Reserve Retired Loss Account
59238  , p_source_28            IN VARCHAR2
59239 --Expense Account Code Combination Identifier
59240  , p_source_29            IN NUMBER
59241 --Default Code Combination Identifier
59242  , p_source_30            IN NUMBER
59243 --Adjustment Type
59244  , p_source_35            IN VARCHAR2
59245 --Transaction Header Identifier
59246  , p_source_36            IN NUMBER
59247 --Adjustment Line Identifier
59248  , p_source_37            IN NUMBER
59249 --Distribution Type Code
59250  , p_source_38            IN VARCHAR2
59251 --Entered Amount
59252  , p_source_39            IN NUMBER
59253 --Currency Code
59254  , p_source_40            IN VARCHAR2
59255 --Gain Loss Amount
59256  , p_source_41            IN NUMBER
59257 )
59258 IS
59259 
59260 l_component_type              VARCHAR2(80);
59261 l_component_code              VARCHAR2(30);
59262 l_component_type_code         VARCHAR2(1);
59263 l_component_appl_id           INTEGER;
59264 l_amb_context_code            VARCHAR2(30);
59265 l_entity_code                 VARCHAR2(30);
59266 l_event_class_code            VARCHAR2(30);
59267 l_ae_header_id                NUMBER;
59268 l_event_type_code             VARCHAR2(30);
59269 l_line_definition_code        VARCHAR2(30);
59270 l_line_definition_owner_code  VARCHAR2(1);
59271 --
59272 -- adr variables
59273 l_segment                     VARCHAR2(30);
59274 l_ccid                        NUMBER;
59275 l_adr_transaction_coa_id      NUMBER;
59276 l_adr_accounting_coa_id       NUMBER;
59277 l_adr_flexfield_segment_code  VARCHAR2(30);
59278 l_adr_flex_value_set_id       NUMBER;
59279 l_adr_value_type_code         VARCHAR2(30);
59280 l_adr_value_combination_id    NUMBER;
59281 l_adr_value_segment_code      VARCHAR2(30);
59282 
59283 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
59284 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
59285 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
59286 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
59287 
59288 -- 4262811 Variables ------------------------------------------------------------------------------------------
59289 l_entered_amt_idx             NUMBER;
59290 l_accted_amt_idx              NUMBER;
59291 l_acc_rev_flag                VARCHAR2(1);
59292 l_accrual_line_num            NUMBER;
59293 l_tmp_amt                     NUMBER;
59294 l_acc_rev_natural_side_code   VARCHAR2(1);
59295 
59296 l_num_entries                 NUMBER;
59297 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
59298 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
59299 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
59300 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
59301 l_recog_line_1                NUMBER;
59302 l_recog_line_2                NUMBER;
59303 
59304 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
59305 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
59306 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
59307 
59308 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
59309 
59310 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
59314 
59311 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
59312 
59313 ---------------------------------------------------------------------------------------------------------------
59315 
59316 --
59317 -- bulk performance
59318 --
59319 l_balance_type_code           VARCHAR2(1);
59320 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
59321 l_log_module                  VARCHAR2(240);
59322 
59323 --
59324 -- Upgrade strategy
59325 --
59326 l_actual_upg_option           VARCHAR2(1);
59327 l_enc_upg_option           VARCHAR2(1);
59328 
59329 --
59330 BEGIN
59331 --
59332 IF g_log_enabled THEN
59333       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_237';
59334 END IF;
59335 --
59336 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59337 
59338       trace
59339          (p_msg      => 'BEGIN of AcctLineType_237'
59340          ,p_level    => C_LEVEL_PROCEDURE
59341          ,p_module   => l_log_module);
59342 
59343 END IF;
59344 --
59345 l_component_type             := 'AMB_JLT';
59346 l_component_code             := 'FA_CIP_RET_REVAL_RESERVE_LOSS';
59347 l_component_type_code        := 'S';
59348 l_component_appl_id          :=  140;
59349 l_amb_context_code           := 'DEFAULT';
59350 l_entity_code                := 'TRANSACTIONS';
59351 l_event_class_code           := 'CIP_RETIREMENTS';
59352 l_event_type_code            := 'CIP_REINSTATEMENTS';
59353 l_line_definition_owner_code := 'S';
59354 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE8';
59355 --
59356 l_balance_type_code          := 'A';
59357 l_segment                     := NULL;
59358 l_ccid                        := NULL;
59359 l_adr_transaction_coa_id      := NULL;
59360 l_adr_accounting_coa_id       := NULL;
59361 l_adr_flexfield_segment_code  := NULL;
59362 l_adr_flex_value_set_id       := NULL;
59363 l_adr_value_type_code         := NULL;
59364 l_adr_value_combination_id    := NULL;
59365 l_adr_value_segment_code      := NULL;
59366 
59367 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
59368 l_bflow_class_code           := '';    -- 4219869 Business Flow
59369 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
59370 l_budgetary_control_flag     := 'N';
59371 
59372 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
59373 l_bflow_applied_to_amt       := NULL; -- 5132302
59374 l_entered_amt_idx            := NULL;          -- 4262811
59375 l_accted_amt_idx             := NULL;          -- 4262811
59376 l_acc_rev_flag               := NULL;          -- 4262811
59377 l_accrual_line_num           := NULL;          -- 4262811
59378 l_tmp_amt                    := NULL;          -- 4262811
59379 --
59380  
59381 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
59382     l_balance_type_code <> 'B' THEN
59383 IF NVL(p_source_35,'
59384 ') =  'REVAL RSV RET' AND 
59385 p_source_41 <  0
59386  THEN 
59387 
59388    --
59389    XLA_AE_LINES_PKG.SetNewLine;
59390 
59391    p_balance_type_code          := l_balance_type_code;
59392    -- set the flag so later we will know whether the gain loss line needs to be created
59393    
59394    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
59395      p_actual_flag :='A';
59396    END IF;
59397 
59398    --
59399    -- bulk performance
59400    --
59401    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
59402                                       p_header_num   => 0); -- 4262811
59403    --
59404    -- set accounting line options
59405    --
59406    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
59407            p_natural_side_code          => 'D'
59408          , p_gain_or_loss_flag          => 'N'
59409          , p_gl_transfer_mode_code      => 'S'
59410          , p_acct_entry_type_code       => 'A'
59411          , p_switch_side_flag           => 'Y'
59412          , p_merge_duplicate_code       => 'N'
59413          );
59414    --
59415    l_acc_rev_natural_side_code := 'C';  -- 4262811
59416    -- 
59417    --
59418    -- set accounting line type info
59419    --
59420    xla_ae_lines_pkg.SetAcctLineType
59421       (p_component_type             => l_component_type
59422       ,p_event_type_code            => l_event_type_code
59423       ,p_line_definition_owner_code => l_line_definition_owner_code
59424       ,p_line_definition_code       => l_line_definition_code
59425       ,p_accounting_line_code       => l_component_code
59426       ,p_accounting_line_type_code  => l_component_type_code
59427       ,p_accounting_line_appl_id    => l_component_appl_id
59428       ,p_amb_context_code           => l_amb_context_code
59429       ,p_entity_code                => l_entity_code
59430       ,p_event_class_code           => l_event_class_code);
59431    --
59432    -- set accounting class
59433    --
59434    xla_ae_lines_pkg.SetAcctClass(
59435            p_accounting_class_code  => 'ASSET'
59436          , p_ae_header_id           => l_ae_header_id
59437          );
59438 
59439    --
59440    -- set rounding class
59441    --
59442    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
59443                       'ASSET';
59444 
59445    --
59446    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
59447    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
59448    --
59449    -- bulk performance
59450    --
59451    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
59452 
59453    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
59454       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
59458       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
59455 
59456    -- 4955764
59457    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
59459 
59460    -- 4458381 Public Sector Enh
59461    
59462    --
59463    -- set accounting attributes for the line type
59464    --
59465    l_entered_amt_idx := 4;
59466    l_accted_amt_idx  := 6;
59467    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
59468    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
59469    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
59470    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
59471    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
59472    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
59473    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
59474    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
59475    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
59476    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
59477    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
59478    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
59479    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
59480 
59481    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
59482    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
59483 
59484    ---------------------------------------------------------------------------------------------------------------
59485    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
59486    ---------------------------------------------------------------------------------------------------------------
59487    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
59488 
59489    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
59490    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
59491 
59492    IF xla_accounting_cache_pkg.GetValueChar
59493          (p_source_code         => 'LEDGER_CATEGORY_CODE'
59494          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
59495    AND l_bflow_method_code = 'PRIOR_ENTRY'
59496 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
59497    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
59498          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
59499        )
59500    THEN
59501          xla_ae_lines_pkg.BflowUpgEntry
59502            (p_business_method_code    => l_bflow_method_code
59503            ,p_business_class_code     => l_bflow_class_code
59504            ,p_balance_type            => l_balance_type_code);
59505    ELSE
59506       NULL;
59507 -- No business flow processing for business flow method of NONE.
59508    END IF;
59509 
59510    --
59511    -- call analytical criteria
59512    --
59513    
59514    --
59515    -- call description
59516    --
59517    
59518 xla_ae_lines_pkg.SetLineDescription(
59519    p_ae_header_id => l_ae_header_id
59520   ,p_description  => Description_39 (
59521      p_application_id         => p_application_id
59522    , p_ae_header_id           => l_ae_header_id 
59523 , p_source_1 => p_source_1
59524    )
59525 );
59526 
59527 
59528    --
59529    -- call ADRs
59530    -- Bug 4922099
59531    --
59532    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
59533         (NVL(l_actual_upg_option, 'N') = 'O') OR
59534         (NVL(l_enc_upg_option, 'N') = 'O')
59535       )
59536    THEN
59537    NULL;
59538    --
59539    --
59540    
59541   l_ccid := AcctDerRule_173(
59542            p_application_id           => p_application_id
59543          , p_ae_header_id             => l_ae_header_id 
59544 , p_source_3 => p_source_3
59545 , p_source_30 => p_source_30
59546          , x_transaction_coa_id       => l_adr_transaction_coa_id
59547          , x_accounting_coa_id        => l_adr_accounting_coa_id
59548          , x_value_type_code          => l_adr_value_type_code
59549          , p_side                     => 'NA'
59550    );
59551 
59552    xla_ae_lines_pkg.set_ccid(
59553     p_code_combination_id          => l_ccid
59554   , p_value_type_code              => l_adr_value_type_code
59555   , p_transaction_coa_id           => l_adr_transaction_coa_id
59556   , p_accounting_coa_id            => l_adr_accounting_coa_id
59557   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
59558   , p_adr_type_code                => 'S'
59559   , p_component_type               => l_component_type
59560   , p_component_code               => l_component_code
59561   , p_component_type_code          => l_component_type_code
59562   , p_component_appl_id            => l_component_appl_id
59563   , p_amb_context_code             => l_amb_context_code
59564   , p_side                         => 'NA'
59565   );
59566 
59567 
59568    l_segment := AcctDerRule_168(
59569            p_application_id           => p_application_id
59570          , p_ae_header_id             => l_ae_header_id 
59571 , p_source_3 => p_source_3
59572 , p_source_29 => p_source_29
59573          , x_transaction_coa_id       => l_adr_transaction_coa_id
59574          , x_accounting_coa_id        => l_adr_accounting_coa_id
59575          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
59576          , x_flex_value_set_id        => l_adr_flex_value_set_id
59577          , x_value_type_code          => l_adr_value_type_code
59578          , x_value_combination_id     => l_adr_value_combination_id
59579          , x_value_segment_code       => l_adr_value_segment_code
59580          , p_side                     => 'NA'
59584    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
59581          , p_override_seg_flag        => 'Y'
59582    );
59583 
59585 
59586       xla_ae_lines_pkg.set_segment(
59587           p_to_segment_code         => 'GL_BALANCING'
59588         , p_segment_value           => l_segment
59589         , p_from_segment_code       => l_adr_value_segment_code
59590         , p_from_combination_id     => l_adr_value_combination_id
59591         , p_value_type_code         => l_adr_value_type_code
59592         , p_transaction_coa_id      => l_adr_transaction_coa_id
59593         , p_accounting_coa_id       => l_adr_accounting_coa_id
59594         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
59595         , p_flex_value_set_id       => l_adr_flex_value_set_id
59596         , p_adr_code                => 'FA_EXPENSE_ACCT'
59597         , p_adr_type_code           => 'S'
59598         , p_component_type          => l_component_type
59599         , p_component_code          => l_component_code
59600         , p_component_type_code     => l_component_type_code
59601         , p_component_appl_id       => l_component_appl_id
59602         , p_amb_context_code        => l_amb_context_code
59603         , p_entity_code             => 'TRANSACTIONS'
59604         , p_event_class_code        => 'CIP_RETIREMENTS'
59605         , p_side                    => 'NA'
59606         );
59607 
59608   END IF;
59609 
59610    l_segment := AcctDerRule_166(
59611            p_application_id           => p_application_id
59612          , p_ae_header_id             => l_ae_header_id 
59613 , p_source_3 => p_source_3
59614 , p_source_28 => p_source_28
59615          , x_transaction_coa_id       => l_adr_transaction_coa_id
59616          , x_accounting_coa_id        => l_adr_accounting_coa_id
59617          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
59618          , x_flex_value_set_id        => l_adr_flex_value_set_id
59619          , x_value_type_code          => l_adr_value_type_code
59620          , x_value_combination_id     => l_adr_value_combination_id
59621          , x_value_segment_code       => l_adr_value_segment_code
59622          , p_side                     => 'NA'
59623          , p_override_seg_flag        => 'Y'
59624    );
59625 
59626    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
59627 
59628       xla_ae_lines_pkg.set_segment(
59629           p_to_segment_code         => 'GL_ACCOUNT'
59630         , p_segment_value           => l_segment
59631         , p_from_segment_code       => l_adr_value_segment_code
59632         , p_from_combination_id     => l_adr_value_combination_id
59633         , p_value_type_code         => l_adr_value_type_code
59634         , p_transaction_coa_id      => l_adr_transaction_coa_id
59635         , p_accounting_coa_id       => l_adr_accounting_coa_id
59636         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
59637         , p_flex_value_set_id       => l_adr_flex_value_set_id
59638         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
59639         , p_adr_type_code           => 'S'
59640         , p_component_type          => l_component_type
59641         , p_component_code          => l_component_code
59642         , p_component_type_code     => l_component_type_code
59643         , p_component_appl_id       => l_component_appl_id
59644         , p_amb_context_code        => l_amb_context_code
59645         , p_entity_code             => 'TRANSACTIONS'
59646         , p_event_class_code        => 'CIP_RETIREMENTS'
59647         , p_side                    => 'NA'
59648         );
59649 
59650   END IF;
59651 
59652    --
59653    --
59654    END IF;
59655    --
59656    -- Bug 4922099
59657    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
59658           (NVL(l_enc_upg_option, 'N') = 'O')
59659         ) AND
59660         (l_bflow_method_code = 'PRIOR_ENTRY')
59661       )
59662    THEN
59663       IF
59664       --
59665       1 = 2
59666       --
59667       THEN
59668       xla_accounting_err_pkg.build_message
59669                                     (p_appli_s_name            => 'XLA'
59670                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
59671                                     ,p_token_1                 => 'LINE_NUMBER'
59672                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
59673                                     ,p_token_2                 => 'LINE_TYPE_NAME'
59674                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
59675                                                                              l_component_type
59676                                                                             ,l_component_code
59677                                                                             ,l_component_type_code
59678                                                                             ,l_component_appl_id
59679                                                                             ,l_amb_context_code
59680                                                                             ,l_entity_code
59681                                                                             ,l_event_class_code
59682                                                                            )
59683                                     ,p_token_3                 => 'OWNER'
59684                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
59685                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
59686                                                                           ,p_lookup_code    => l_component_type_code
59687                                                                          )
59688                                     ,p_token_4                 => 'PRODUCT_NAME'
59689                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
59693                                     ,p_ae_header_id            =>  NULL
59690                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
59691                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
59692                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
59694                                        );
59695 
59696         IF (C_LEVEL_ERROR>= g_log_level) THEN
59697                  trace
59698                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
59699                       ,p_level    => C_LEVEL_ERROR
59700                       ,p_module   => l_log_module);
59701         END IF;
59702       END IF;
59703    END IF;
59704    --
59705    --
59706    ------------------------------------------------------------------------------------------------
59707    -- 4219869 Business Flow
59708    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
59709    -- Prior Entry.  Currently, the following code is always generated.
59710    ------------------------------------------------------------------------------------------------
59711    XLA_AE_LINES_PKG.ValidateCurrentLine;
59712 
59713    ------------------------------------------------------------------------------------
59714    -- 4219869 Business Flow
59715    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
59716    ------------------------------------------------------------------------------------
59717    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
59718 
59719    ----------------------------------------------------------------------------------
59720    -- 4219869 Business Flow
59721    -- Update journal entry status -- Need to generate this within IF <condition>
59722    ----------------------------------------------------------------------------------
59723    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
59724          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
59725          ,p_balance_type_code => l_balance_type_code
59726          );
59727 
59728    -------------------------------------------------------------------------------------------
59729    -- 4262811 - Generate the Accrual Reversal lines
59730    -------------------------------------------------------------------------------------------
59731    BEGIN
59732       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
59733                               (g_array_event(p_event_id).array_value_num('header_index'));
59734       IF l_acc_rev_flag IS NULL THEN
59735          l_acc_rev_flag := 'N';
59736       END IF;
59737    EXCEPTION
59738       WHEN OTHERS THEN
59739          l_acc_rev_flag := 'N';
59740    END;
59741    --
59742    IF (l_acc_rev_flag = 'Y') THEN
59743 
59744        -- 4645092  ------------------------------------------------------------------------------
59745        -- To allow MPA report to determine if it should generate report process
59746        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
59747        ------------------------------------------------------------------------------------------
59748 
59749        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
59750        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
59751    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
59752    -- call ADRs
59753    -- Bug 4922099
59754    --
59755    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
59756         (NVL(l_actual_upg_option, 'N') = 'O') OR
59757         (NVL(l_enc_upg_option, 'N') = 'O')
59758       )
59759    THEN
59760    NULL;
59761    --
59762    --
59763    
59764   l_ccid := AcctDerRule_173(
59765            p_application_id           => p_application_id
59766          , p_ae_header_id             => l_ae_header_id 
59767 , p_source_3 => p_source_3
59768 , p_source_30 => p_source_30
59769          , x_transaction_coa_id       => l_adr_transaction_coa_id
59770          , x_accounting_coa_id        => l_adr_accounting_coa_id
59771          , x_value_type_code          => l_adr_value_type_code
59772          , p_side                     => 'NA'
59773    );
59774 
59775    xla_ae_lines_pkg.set_ccid(
59776     p_code_combination_id          => l_ccid
59777   , p_value_type_code              => l_adr_value_type_code
59778   , p_transaction_coa_id           => l_adr_transaction_coa_id
59779   , p_accounting_coa_id            => l_adr_accounting_coa_id
59780   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
59781   , p_adr_type_code                => 'S'
59782   , p_component_type               => l_component_type
59783   , p_component_code               => l_component_code
59784   , p_component_type_code          => l_component_type_code
59785   , p_component_appl_id            => l_component_appl_id
59786   , p_amb_context_code             => l_amb_context_code
59787   , p_side                         => 'NA'
59788   );
59789 
59790 
59791    l_segment := AcctDerRule_168(
59792            p_application_id           => p_application_id
59793          , p_ae_header_id             => l_ae_header_id 
59794 , p_source_3 => p_source_3
59795 , p_source_29 => p_source_29
59796          , x_transaction_coa_id       => l_adr_transaction_coa_id
59797          , x_accounting_coa_id        => l_adr_accounting_coa_id
59798          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
59799          , x_flex_value_set_id        => l_adr_flex_value_set_id
59800          , x_value_type_code          => l_adr_value_type_code
59801          , x_value_combination_id     => l_adr_value_combination_id
59802          , x_value_segment_code       => l_adr_value_segment_code
59803          , p_side                     => 'NA'
59804          , p_override_seg_flag        => 'Y'
59805    );
59806 
59807    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
59811         , p_segment_value           => l_segment
59808 
59809       xla_ae_lines_pkg.set_segment(
59810           p_to_segment_code         => 'GL_BALANCING'
59812         , p_from_segment_code       => l_adr_value_segment_code
59813         , p_from_combination_id     => l_adr_value_combination_id
59814         , p_value_type_code         => l_adr_value_type_code
59815         , p_transaction_coa_id      => l_adr_transaction_coa_id
59816         , p_accounting_coa_id       => l_adr_accounting_coa_id
59817         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
59818         , p_flex_value_set_id       => l_adr_flex_value_set_id
59819         , p_adr_code                => 'FA_EXPENSE_ACCT'
59820         , p_adr_type_code           => 'S'
59821         , p_component_type          => l_component_type
59822         , p_component_code          => l_component_code
59823         , p_component_type_code     => l_component_type_code
59824         , p_component_appl_id       => l_component_appl_id
59825         , p_amb_context_code        => l_amb_context_code
59826         , p_entity_code             => 'TRANSACTIONS'
59827         , p_event_class_code        => 'CIP_RETIREMENTS'
59828         , p_side                    => 'NA'
59829         );
59830 
59831   END IF;
59832 
59833    l_segment := AcctDerRule_166(
59834            p_application_id           => p_application_id
59835          , p_ae_header_id             => l_ae_header_id 
59836 , p_source_3 => p_source_3
59837 , p_source_28 => p_source_28
59838          , x_transaction_coa_id       => l_adr_transaction_coa_id
59839          , x_accounting_coa_id        => l_adr_accounting_coa_id
59840          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
59841          , x_flex_value_set_id        => l_adr_flex_value_set_id
59842          , x_value_type_code          => l_adr_value_type_code
59843          , x_value_combination_id     => l_adr_value_combination_id
59844          , x_value_segment_code       => l_adr_value_segment_code
59845          , p_side                     => 'NA'
59846          , p_override_seg_flag        => 'Y'
59847    );
59848 
59849    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
59850 
59851       xla_ae_lines_pkg.set_segment(
59852           p_to_segment_code         => 'GL_ACCOUNT'
59853         , p_segment_value           => l_segment
59854         , p_from_segment_code       => l_adr_value_segment_code
59855         , p_from_combination_id     => l_adr_value_combination_id
59856         , p_value_type_code         => l_adr_value_type_code
59857         , p_transaction_coa_id      => l_adr_transaction_coa_id
59858         , p_accounting_coa_id       => l_adr_accounting_coa_id
59859         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
59860         , p_flex_value_set_id       => l_adr_flex_value_set_id
59861         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
59862         , p_adr_type_code           => 'S'
59863         , p_component_type          => l_component_type
59864         , p_component_code          => l_component_code
59865         , p_component_type_code     => l_component_type_code
59866         , p_component_appl_id       => l_component_appl_id
59867         , p_amb_context_code        => l_amb_context_code
59868         , p_entity_code             => 'TRANSACTIONS'
59869         , p_event_class_code        => 'CIP_RETIREMENTS'
59870         , p_side                    => 'NA'
59871         );
59872 
59873   END IF;
59874 
59875    --
59876    --
59877    END IF;
59878 
59879        --
59880        -- Update the line information that should be overwritten
59881        --
59882        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
59883                                          p_header_num   => 1);
59884        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
59885 
59886        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
59887 
59888        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
59889           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
59890        END IF;
59891 
59892       --
59893       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
59894       --
59895       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
59896           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
59897       ELSE
59898           ---------------------------------------------------------------------------------------------------
59899           -- 4262811a Switch Sign
59900           ---------------------------------------------------------------------------------------------------
59901           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
59902           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
59903                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
59904           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
59905                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
59906           -- 5132302
59907           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
59908                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
59909 
59910       END IF;
59911 
59912       -- 4955764
59913       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
59914       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
59915 
59916 
59917       XLA_AE_LINES_PKG.ValidateCurrentLine;
59918       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
59919 
59923 
59920       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
59921                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
59922                ,p_balance_type_code => l_balance_type_code);
59924    END IF;
59925 
59926    -----------------------------------------------------------------------------------------
59927    -- 4262811 Multiperiod Accounting
59928    -----------------------------------------------------------------------------------------
59929      -- No MPA option is assigned.
59930 
59931 
59932 END IF;
59933 END IF;
59934 --
59935 
59936 --
59937 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59938    trace
59939       (p_msg      => 'END of AcctLineType_237'
59940       ,p_level    => C_LEVEL_PROCEDURE
59941       ,p_module   => l_log_module);
59942 END IF;
59943 --
59944 EXCEPTION
59945   WHEN xla_exceptions_pkg.application_exception THEN
59946       RAISE;
59947   WHEN OTHERS THEN
59948        xla_exceptions_pkg.raise_message
59949            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_237');
59950 END AcctLineType_237;
59951 --
59952 
59953 ---------------------------------------
59954 --
59955 -- PRIVATE FUNCTION
59956 --         AcctLineType_238
59957 --
59958 ---------------------------------------
59959 PROCEDURE AcctLineType_238 (
59960   p_application_id        IN NUMBER
59961  ,p_event_id              IN NUMBER
59962  ,p_calculate_acctd_flag  IN VARCHAR2
59963  ,p_calculate_g_l_flag    IN VARCHAR2
59964  ,p_actual_flag           IN OUT VARCHAR2
59965  ,p_balance_type_code     OUT VARCHAR2
59966  ,p_gain_or_loss_ref      OUT VARCHAR2
59967  
59968 --Period Close Date
59969  , p_source_1            IN DATE
59970 --Generated Code Combination Identifier
59971  , p_source_3            IN NUMBER
59972 --Revaluation Reserve Retired Loss Account
59973  , p_source_28            IN VARCHAR2
59974 --Expense Account Code Combination Identifier
59975  , p_source_29            IN NUMBER
59976 --Default Code Combination Identifier
59977  , p_source_30            IN NUMBER
59978 --Adjustment Type
59979  , p_source_35            IN VARCHAR2
59980 --Transaction Header Identifier
59981  , p_source_36            IN NUMBER
59982 --Adjustment Line Identifier
59983  , p_source_37            IN NUMBER
59984 --Distribution Type Code
59985  , p_source_38            IN VARCHAR2
59986 --Entered Amount
59987  , p_source_39            IN NUMBER
59988 --Currency Code
59989  , p_source_40            IN VARCHAR2
59990 --Gain Loss Amount
59991  , p_source_41            IN NUMBER
59992 )
59993 IS
59994 
59995 l_component_type              VARCHAR2(80);
59996 l_component_code              VARCHAR2(30);
59997 l_component_type_code         VARCHAR2(1);
59998 l_component_appl_id           INTEGER;
59999 l_amb_context_code            VARCHAR2(30);
60000 l_entity_code                 VARCHAR2(30);
60001 l_event_class_code            VARCHAR2(30);
60002 l_ae_header_id                NUMBER;
60003 l_event_type_code             VARCHAR2(30);
60004 l_line_definition_code        VARCHAR2(30);
60005 l_line_definition_owner_code  VARCHAR2(1);
60006 --
60007 -- adr variables
60008 l_segment                     VARCHAR2(30);
60009 l_ccid                        NUMBER;
60010 l_adr_transaction_coa_id      NUMBER;
60011 l_adr_accounting_coa_id       NUMBER;
60012 l_adr_flexfield_segment_code  VARCHAR2(30);
60013 l_adr_flex_value_set_id       NUMBER;
60014 l_adr_value_type_code         VARCHAR2(30);
60015 l_adr_value_combination_id    NUMBER;
60016 l_adr_value_segment_code      VARCHAR2(30);
60017 
60018 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
60019 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
60020 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
60021 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
60022 
60023 -- 4262811 Variables ------------------------------------------------------------------------------------------
60024 l_entered_amt_idx             NUMBER;
60025 l_accted_amt_idx              NUMBER;
60026 l_acc_rev_flag                VARCHAR2(1);
60027 l_accrual_line_num            NUMBER;
60028 l_tmp_amt                     NUMBER;
60029 l_acc_rev_natural_side_code   VARCHAR2(1);
60030 
60031 l_num_entries                 NUMBER;
60032 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
60033 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
60034 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
60035 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
60036 l_recog_line_1                NUMBER;
60037 l_recog_line_2                NUMBER;
60038 
60039 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
60040 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
60041 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
60042 
60043 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
60044 
60045 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
60046 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
60047 
60048 ---------------------------------------------------------------------------------------------------------------
60049 
60050 
60051 --
60052 -- bulk performance
60053 --
60054 l_balance_type_code           VARCHAR2(1);
60055 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
60056 l_log_module                  VARCHAR2(240);
60057 
60058 --
60059 -- Upgrade strategy
60060 --
60061 l_actual_upg_option           VARCHAR2(1);
60062 l_enc_upg_option           VARCHAR2(1);
60063 
60064 --
60068       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_238';
60065 BEGIN
60066 --
60067 IF g_log_enabled THEN
60069 END IF;
60070 --
60071 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
60072 
60073       trace
60074          (p_msg      => 'BEGIN of AcctLineType_238'
60075          ,p_level    => C_LEVEL_PROCEDURE
60076          ,p_module   => l_log_module);
60077 
60078 END IF;
60079 --
60080 l_component_type             := 'AMB_JLT';
60081 l_component_code             := 'FA_CIP_RET_REVAL_RESERVE_LOSS';
60082 l_component_type_code        := 'S';
60083 l_component_appl_id          :=  140;
60084 l_amb_context_code           := 'DEFAULT';
60085 l_entity_code                := 'TRANSACTIONS';
60086 l_event_class_code           := 'CIP_RETIREMENTS';
60087 l_event_type_code            := 'CIP_RETIREMENTS';
60088 l_line_definition_owner_code := 'S';
60089 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_RE9';
60090 --
60091 l_balance_type_code          := 'A';
60092 l_segment                     := NULL;
60093 l_ccid                        := NULL;
60094 l_adr_transaction_coa_id      := NULL;
60095 l_adr_accounting_coa_id       := NULL;
60096 l_adr_flexfield_segment_code  := NULL;
60097 l_adr_flex_value_set_id       := NULL;
60098 l_adr_value_type_code         := NULL;
60099 l_adr_value_combination_id    := NULL;
60100 l_adr_value_segment_code      := NULL;
60101 
60102 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
60103 l_bflow_class_code           := '';    -- 4219869 Business Flow
60104 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
60105 l_budgetary_control_flag     := 'N';
60106 
60107 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
60108 l_bflow_applied_to_amt       := NULL; -- 5132302
60109 l_entered_amt_idx            := NULL;          -- 4262811
60110 l_accted_amt_idx             := NULL;          -- 4262811
60111 l_acc_rev_flag               := NULL;          -- 4262811
60112 l_accrual_line_num           := NULL;          -- 4262811
60113 l_tmp_amt                    := NULL;          -- 4262811
60114 --
60115  
60116 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
60117     l_balance_type_code <> 'B' THEN
60118 IF NVL(p_source_35,'
60119 ') =  'REVAL RSV RET' AND 
60120 p_source_41 <  0
60121  THEN 
60122 
60123    --
60124    XLA_AE_LINES_PKG.SetNewLine;
60125 
60126    p_balance_type_code          := l_balance_type_code;
60127    -- set the flag so later we will know whether the gain loss line needs to be created
60128    
60129    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
60130      p_actual_flag :='A';
60131    END IF;
60132 
60133    --
60134    -- bulk performance
60135    --
60136    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
60137                                       p_header_num   => 0); -- 4262811
60138    --
60139    -- set accounting line options
60140    --
60141    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
60142            p_natural_side_code          => 'D'
60143          , p_gain_or_loss_flag          => 'N'
60144          , p_gl_transfer_mode_code      => 'S'
60145          , p_acct_entry_type_code       => 'A'
60146          , p_switch_side_flag           => 'Y'
60147          , p_merge_duplicate_code       => 'N'
60148          );
60149    --
60150    l_acc_rev_natural_side_code := 'C';  -- 4262811
60151    -- 
60152    --
60153    -- set accounting line type info
60154    --
60155    xla_ae_lines_pkg.SetAcctLineType
60156       (p_component_type             => l_component_type
60157       ,p_event_type_code            => l_event_type_code
60158       ,p_line_definition_owner_code => l_line_definition_owner_code
60159       ,p_line_definition_code       => l_line_definition_code
60160       ,p_accounting_line_code       => l_component_code
60161       ,p_accounting_line_type_code  => l_component_type_code
60162       ,p_accounting_line_appl_id    => l_component_appl_id
60163       ,p_amb_context_code           => l_amb_context_code
60164       ,p_entity_code                => l_entity_code
60165       ,p_event_class_code           => l_event_class_code);
60166    --
60167    -- set accounting class
60168    --
60169    xla_ae_lines_pkg.SetAcctClass(
60170            p_accounting_class_code  => 'ASSET'
60171          , p_ae_header_id           => l_ae_header_id
60172          );
60173 
60174    --
60175    -- set rounding class
60176    --
60177    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
60178                       'ASSET';
60179 
60180    --
60181    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
60182    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
60183    --
60184    -- bulk performance
60185    --
60186    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
60187 
60188    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
60189       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
60190 
60191    -- 4955764
60192    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
60193       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
60194 
60195    -- 4458381 Public Sector Enh
60196    
60197    --
60198    -- set accounting attributes for the line type
60199    --
60200    l_entered_amt_idx := 4;
60201    l_accted_amt_idx  := 6;
60202    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
60203    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
60204    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
60208    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
60205    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
60206    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
60207    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
60209    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
60210    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
60211    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
60212    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
60213    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
60214    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
60215 
60216    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
60217    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
60218 
60219    ---------------------------------------------------------------------------------------------------------------
60220    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
60221    ---------------------------------------------------------------------------------------------------------------
60222    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
60223 
60224    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
60225    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
60226 
60227    IF xla_accounting_cache_pkg.GetValueChar
60228          (p_source_code         => 'LEDGER_CATEGORY_CODE'
60229          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
60230    AND l_bflow_method_code = 'PRIOR_ENTRY'
60231 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
60232    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
60233          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
60234        )
60235    THEN
60236          xla_ae_lines_pkg.BflowUpgEntry
60237            (p_business_method_code    => l_bflow_method_code
60238            ,p_business_class_code     => l_bflow_class_code
60239            ,p_balance_type            => l_balance_type_code);
60240    ELSE
60241       NULL;
60242 -- No business flow processing for business flow method of NONE.
60243    END IF;
60244 
60245    --
60246    -- call analytical criteria
60247    --
60248    
60249    --
60250    -- call description
60251    --
60252    
60253 xla_ae_lines_pkg.SetLineDescription(
60254    p_ae_header_id => l_ae_header_id
60255   ,p_description  => Description_40 (
60256      p_application_id         => p_application_id
60257    , p_ae_header_id           => l_ae_header_id 
60258 , p_source_1 => p_source_1
60259    )
60260 );
60261 
60262 
60263    --
60264    -- call ADRs
60265    -- Bug 4922099
60266    --
60270       )
60267    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
60268         (NVL(l_actual_upg_option, 'N') = 'O') OR
60269         (NVL(l_enc_upg_option, 'N') = 'O')
60271    THEN
60272    NULL;
60273    --
60274    --
60275    
60276   l_ccid := AcctDerRule_173(
60277            p_application_id           => p_application_id
60278          , p_ae_header_id             => l_ae_header_id 
60279 , p_source_3 => p_source_3
60280 , p_source_30 => p_source_30
60281          , x_transaction_coa_id       => l_adr_transaction_coa_id
60282          , x_accounting_coa_id        => l_adr_accounting_coa_id
60283          , x_value_type_code          => l_adr_value_type_code
60284          , p_side                     => 'NA'
60285    );
60286 
60287    xla_ae_lines_pkg.set_ccid(
60288     p_code_combination_id          => l_ccid
60289   , p_value_type_code              => l_adr_value_type_code
60290   , p_transaction_coa_id           => l_adr_transaction_coa_id
60291   , p_accounting_coa_id            => l_adr_accounting_coa_id
60292   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
60293   , p_adr_type_code                => 'S'
60294   , p_component_type               => l_component_type
60295   , p_component_code               => l_component_code
60296   , p_component_type_code          => l_component_type_code
60297   , p_component_appl_id            => l_component_appl_id
60298   , p_amb_context_code             => l_amb_context_code
60299   , p_side                         => 'NA'
60300   );
60301 
60302 
60303    l_segment := AcctDerRule_168(
60304            p_application_id           => p_application_id
60305          , p_ae_header_id             => l_ae_header_id 
60306 , p_source_3 => p_source_3
60307 , p_source_29 => p_source_29
60308          , x_transaction_coa_id       => l_adr_transaction_coa_id
60309          , x_accounting_coa_id        => l_adr_accounting_coa_id
60310          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
60311          , x_flex_value_set_id        => l_adr_flex_value_set_id
60312          , x_value_type_code          => l_adr_value_type_code
60313          , x_value_combination_id     => l_adr_value_combination_id
60314          , x_value_segment_code       => l_adr_value_segment_code
60315          , p_side                     => 'NA'
60316          , p_override_seg_flag        => 'Y'
60317    );
60318 
60319    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
60320 
60321       xla_ae_lines_pkg.set_segment(
60322           p_to_segment_code         => 'GL_BALANCING'
60323         , p_segment_value           => l_segment
60324         , p_from_segment_code       => l_adr_value_segment_code
60325         , p_from_combination_id     => l_adr_value_combination_id
60326         , p_value_type_code         => l_adr_value_type_code
60327         , p_transaction_coa_id      => l_adr_transaction_coa_id
60328         , p_accounting_coa_id       => l_adr_accounting_coa_id
60329         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
60330         , p_flex_value_set_id       => l_adr_flex_value_set_id
60331         , p_adr_code                => 'FA_EXPENSE_ACCT'
60332         , p_adr_type_code           => 'S'
60333         , p_component_type          => l_component_type
60334         , p_component_code          => l_component_code
60335         , p_component_type_code     => l_component_type_code
60336         , p_component_appl_id       => l_component_appl_id
60337         , p_amb_context_code        => l_amb_context_code
60338         , p_entity_code             => 'TRANSACTIONS'
60339         , p_event_class_code        => 'CIP_RETIREMENTS'
60340         , p_side                    => 'NA'
60341         );
60342 
60343   END IF;
60344 
60345    l_segment := AcctDerRule_166(
60346            p_application_id           => p_application_id
60347          , p_ae_header_id             => l_ae_header_id 
60348 , p_source_3 => p_source_3
60349 , p_source_28 => p_source_28
60350          , x_transaction_coa_id       => l_adr_transaction_coa_id
60351          , x_accounting_coa_id        => l_adr_accounting_coa_id
60352          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
60353          , x_flex_value_set_id        => l_adr_flex_value_set_id
60354          , x_value_type_code          => l_adr_value_type_code
60355          , x_value_combination_id     => l_adr_value_combination_id
60356          , x_value_segment_code       => l_adr_value_segment_code
60357          , p_side                     => 'NA'
60358          , p_override_seg_flag        => 'Y'
60359    );
60360 
60361    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
60362 
60363       xla_ae_lines_pkg.set_segment(
60364           p_to_segment_code         => 'GL_ACCOUNT'
60365         , p_segment_value           => l_segment
60366         , p_from_segment_code       => l_adr_value_segment_code
60367         , p_from_combination_id     => l_adr_value_combination_id
60368         , p_value_type_code         => l_adr_value_type_code
60369         , p_transaction_coa_id      => l_adr_transaction_coa_id
60370         , p_accounting_coa_id       => l_adr_accounting_coa_id
60371         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
60372         , p_flex_value_set_id       => l_adr_flex_value_set_id
60373         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
60374         , p_adr_type_code           => 'S'
60378         , p_component_appl_id       => l_component_appl_id
60375         , p_component_type          => l_component_type
60376         , p_component_code          => l_component_code
60377         , p_component_type_code     => l_component_type_code
60379         , p_amb_context_code        => l_amb_context_code
60380         , p_entity_code             => 'TRANSACTIONS'
60381         , p_event_class_code        => 'CIP_RETIREMENTS'
60382         , p_side                    => 'NA'
60383         );
60384 
60385   END IF;
60386 
60387    --
60388    --
60389    END IF;
60390    --
60391    -- Bug 4922099
60392    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
60393           (NVL(l_enc_upg_option, 'N') = 'O')
60394         ) AND
60395         (l_bflow_method_code = 'PRIOR_ENTRY')
60396       )
60397    THEN
60398       IF
60399       --
60400       1 = 2
60401       --
60402       THEN
60403       xla_accounting_err_pkg.build_message
60404                                     (p_appli_s_name            => 'XLA'
60405                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
60406                                     ,p_token_1                 => 'LINE_NUMBER'
60407                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
60408                                     ,p_token_2                 => 'LINE_TYPE_NAME'
60409                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
60410                                                                              l_component_type
60411                                                                             ,l_component_code
60412                                                                             ,l_component_type_code
60413                                                                             ,l_component_appl_id
60414                                                                             ,l_amb_context_code
60415                                                                             ,l_entity_code
60416                                                                             ,l_event_class_code
60417                                                                            )
60418                                     ,p_token_3                 => 'OWNER'
60419                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
60420                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
60421                                                                           ,p_lookup_code    => l_component_type_code
60422                                                                          )
60423                                     ,p_token_4                 => 'PRODUCT_NAME'
60424                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
60425                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
60426                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
60427                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
60428                                     ,p_ae_header_id            =>  NULL
60429                                        );
60430 
60431         IF (C_LEVEL_ERROR>= g_log_level) THEN
60432                  trace
60433                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
60434                       ,p_level    => C_LEVEL_ERROR
60435                       ,p_module   => l_log_module);
60436         END IF;
60437       END IF;
60438    END IF;
60439    --
60440    --
60441    ------------------------------------------------------------------------------------------------
60442    -- 4219869 Business Flow
60443    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
60444    -- Prior Entry.  Currently, the following code is always generated.
60445    ------------------------------------------------------------------------------------------------
60446    XLA_AE_LINES_PKG.ValidateCurrentLine;
60447 
60448    ------------------------------------------------------------------------------------
60449    -- 4219869 Business Flow
60450    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
60451    ------------------------------------------------------------------------------------
60452    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
60453 
60454    ----------------------------------------------------------------------------------
60455    -- 4219869 Business Flow
60456    -- Update journal entry status -- Need to generate this within IF <condition>
60457    ----------------------------------------------------------------------------------
60458    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
60459          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
60460          ,p_balance_type_code => l_balance_type_code
60461          );
60462 
60463    -------------------------------------------------------------------------------------------
60464    -- 4262811 - Generate the Accrual Reversal lines
60465    -------------------------------------------------------------------------------------------
60466    BEGIN
60467       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
60468                               (g_array_event(p_event_id).array_value_num('header_index'));
60469       IF l_acc_rev_flag IS NULL THEN
60470          l_acc_rev_flag := 'N';
60471       END IF;
60472    EXCEPTION
60473       WHEN OTHERS THEN
60474          l_acc_rev_flag := 'N';
60475    END;
60476    --
60477    IF (l_acc_rev_flag = 'Y') THEN
60478 
60479        -- 4645092  ------------------------------------------------------------------------------
60480        -- To allow MPA report to determine if it should generate report process
60484        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
60481        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
60482        ------------------------------------------------------------------------------------------
60483 
60485        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
60486    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
60487    -- call ADRs
60488    -- Bug 4922099
60489    --
60490    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
60491         (NVL(l_actual_upg_option, 'N') = 'O') OR
60492         (NVL(l_enc_upg_option, 'N') = 'O')
60493       )
60494    THEN
60495    NULL;
60496    --
60497    --
60498    
60499   l_ccid := AcctDerRule_173(
60500            p_application_id           => p_application_id
60501          , p_ae_header_id             => l_ae_header_id 
60502 , p_source_3 => p_source_3
60503 , p_source_30 => p_source_30
60504          , x_transaction_coa_id       => l_adr_transaction_coa_id
60505          , x_accounting_coa_id        => l_adr_accounting_coa_id
60506          , x_value_type_code          => l_adr_value_type_code
60507          , p_side                     => 'NA'
60508    );
60509 
60510    xla_ae_lines_pkg.set_ccid(
60511     p_code_combination_id          => l_ccid
60512   , p_value_type_code              => l_adr_value_type_code
60513   , p_transaction_coa_id           => l_adr_transaction_coa_id
60514   , p_accounting_coa_id            => l_adr_accounting_coa_id
60515   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
60516   , p_adr_type_code                => 'S'
60517   , p_component_type               => l_component_type
60518   , p_component_code               => l_component_code
60519   , p_component_type_code          => l_component_type_code
60520   , p_component_appl_id            => l_component_appl_id
60521   , p_amb_context_code             => l_amb_context_code
60522   , p_side                         => 'NA'
60523   );
60524 
60525 
60526    l_segment := AcctDerRule_168(
60527            p_application_id           => p_application_id
60528          , p_ae_header_id             => l_ae_header_id 
60529 , p_source_3 => p_source_3
60530 , p_source_29 => p_source_29
60531          , x_transaction_coa_id       => l_adr_transaction_coa_id
60532          , x_accounting_coa_id        => l_adr_accounting_coa_id
60533          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
60534          , x_flex_value_set_id        => l_adr_flex_value_set_id
60535          , x_value_type_code          => l_adr_value_type_code
60536          , x_value_combination_id     => l_adr_value_combination_id
60537          , x_value_segment_code       => l_adr_value_segment_code
60538          , p_side                     => 'NA'
60539          , p_override_seg_flag        => 'Y'
60540    );
60541 
60542    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
60543 
60544       xla_ae_lines_pkg.set_segment(
60545           p_to_segment_code         => 'GL_BALANCING'
60546         , p_segment_value           => l_segment
60547         , p_from_segment_code       => l_adr_value_segment_code
60548         , p_from_combination_id     => l_adr_value_combination_id
60549         , p_value_type_code         => l_adr_value_type_code
60550         , p_transaction_coa_id      => l_adr_transaction_coa_id
60551         , p_accounting_coa_id       => l_adr_accounting_coa_id
60552         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
60553         , p_flex_value_set_id       => l_adr_flex_value_set_id
60554         , p_adr_code                => 'FA_EXPENSE_ACCT'
60555         , p_adr_type_code           => 'S'
60556         , p_component_type          => l_component_type
60557         , p_component_code          => l_component_code
60558         , p_component_type_code     => l_component_type_code
60559         , p_component_appl_id       => l_component_appl_id
60560         , p_amb_context_code        => l_amb_context_code
60561         , p_entity_code             => 'TRANSACTIONS'
60562         , p_event_class_code        => 'CIP_RETIREMENTS'
60563         , p_side                    => 'NA'
60564         );
60565 
60566   END IF;
60567 
60568    l_segment := AcctDerRule_166(
60569            p_application_id           => p_application_id
60570          , p_ae_header_id             => l_ae_header_id 
60571 , p_source_3 => p_source_3
60572 , p_source_28 => p_source_28
60573          , x_transaction_coa_id       => l_adr_transaction_coa_id
60574          , x_accounting_coa_id        => l_adr_accounting_coa_id
60575          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
60576          , x_flex_value_set_id        => l_adr_flex_value_set_id
60577          , x_value_type_code          => l_adr_value_type_code
60578          , x_value_combination_id     => l_adr_value_combination_id
60579          , x_value_segment_code       => l_adr_value_segment_code
60580          , p_side                     => 'NA'
60581          , p_override_seg_flag        => 'Y'
60582    );
60583 
60584    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
60585 
60586       xla_ae_lines_pkg.set_segment(
60587           p_to_segment_code         => 'GL_ACCOUNT'
60588         , p_segment_value           => l_segment
60589         , p_from_segment_code       => l_adr_value_segment_code
60590         , p_from_combination_id     => l_adr_value_combination_id
60591         , p_value_type_code         => l_adr_value_type_code
60592         , p_transaction_coa_id      => l_adr_transaction_coa_id
60593         , p_accounting_coa_id       => l_adr_accounting_coa_id
60594         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
60595         , p_flex_value_set_id       => l_adr_flex_value_set_id
60596         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
60597         , p_adr_type_code           => 'S'
60598         , p_component_type          => l_component_type
60599         , p_component_code          => l_component_code
60603         , p_entity_code             => 'TRANSACTIONS'
60600         , p_component_type_code     => l_component_type_code
60601         , p_component_appl_id       => l_component_appl_id
60602         , p_amb_context_code        => l_amb_context_code
60604         , p_event_class_code        => 'CIP_RETIREMENTS'
60605         , p_side                    => 'NA'
60606         );
60607 
60608   END IF;
60609 
60610    --
60611    --
60612    END IF;
60613 
60614        --
60615        -- Update the line information that should be overwritten
60616        --
60617        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
60618                                          p_header_num   => 1);
60619        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
60620 
60621        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
60622 
60623        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
60624           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
60625        END IF;
60626 
60627       --
60628       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
60629       --
60630       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
60631           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
60632       ELSE
60633           ---------------------------------------------------------------------------------------------------
60634           -- 4262811a Switch Sign
60635           ---------------------------------------------------------------------------------------------------
60636           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
60637           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
60638                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
60639           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
60640                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
60641           -- 5132302
60642           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
60643                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
60644 
60645       END IF;
60646 
60647       -- 4955764
60648       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
60649       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
60650 
60651 
60652       XLA_AE_LINES_PKG.ValidateCurrentLine;
60653       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
60654 
60655       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
60656                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
60657                ,p_balance_type_code => l_balance_type_code);
60658 
60659    END IF;
60660 
60661    -----------------------------------------------------------------------------------------
60662    -- 4262811 Multiperiod Accounting
60663    -----------------------------------------------------------------------------------------
60664      -- No MPA option is assigned.
60665 
60666 
60667 END IF;
60668 END IF;
60669 --
60670 
60671 --
60672 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
60673    trace
60674       (p_msg      => 'END of AcctLineType_238'
60675       ,p_level    => C_LEVEL_PROCEDURE
60676       ,p_module   => l_log_module);
60677 END IF;
60678 --
60679 EXCEPTION
60680   WHEN xla_exceptions_pkg.application_exception THEN
60681       RAISE;
60682   WHEN OTHERS THEN
60683        xla_exceptions_pkg.raise_message
60684            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_238');
60685 END AcctLineType_238;
60686 --
60687 
60688 ---------------------------------------
60689 --
60690 -- PRIVATE FUNCTION
60691 --         AcctLineType_239
60692 --
60693 ---------------------------------------
60694 PROCEDURE AcctLineType_239 (
60695   p_application_id        IN NUMBER
60696  ,p_event_id              IN NUMBER
60697  ,p_calculate_acctd_flag  IN VARCHAR2
60698  ,p_calculate_g_l_flag    IN VARCHAR2
60699  ,p_actual_flag           IN OUT VARCHAR2
60700  ,p_balance_type_code     OUT VARCHAR2
60701  ,p_gain_or_loss_ref      OUT VARCHAR2
60702  
60703 --Period Close Date
60704  , p_source_1            IN DATE
60705 --Generated Code Combination Identifier
60706  , p_source_3            IN NUMBER
60707 --CIP Cost Account
60708  , p_source_7            IN VARCHAR2
60709 --Expense Account Code Combination Identifier
60710  , p_source_29            IN NUMBER
60711 --Default Code Combination Identifier
60712  , p_source_30            IN NUMBER
60713 --Adjustment Type
60714  , p_source_35            IN VARCHAR2
60715 --Transaction Header Identifier
60716  , p_source_36            IN NUMBER
60717 --Adjustment Line Identifier
60718  , p_source_37            IN NUMBER
60719 --Distribution Type Code
60720  , p_source_38            IN VARCHAR2
60721 --Entered Amount
60722  , p_source_39            IN NUMBER
60723 --Currency Code
60724  , p_source_40            IN VARCHAR2
60725 )
60726 IS
60727 
60728 l_component_type              VARCHAR2(80);
60729 l_component_code              VARCHAR2(30);
60730 l_component_type_code         VARCHAR2(1);
60731 l_component_appl_id           INTEGER;
60732 l_amb_context_code            VARCHAR2(30);
60733 l_entity_code                 VARCHAR2(30);
60734 l_event_class_code            VARCHAR2(30);
60735 l_ae_header_id                NUMBER;
60739 --
60736 l_event_type_code             VARCHAR2(30);
60737 l_line_definition_code        VARCHAR2(30);
60738 l_line_definition_owner_code  VARCHAR2(1);
60740 -- adr variables
60741 l_segment                     VARCHAR2(30);
60742 l_ccid                        NUMBER;
60743 l_adr_transaction_coa_id      NUMBER;
60744 l_adr_accounting_coa_id       NUMBER;
60745 l_adr_flexfield_segment_code  VARCHAR2(30);
60746 l_adr_flex_value_set_id       NUMBER;
60747 l_adr_value_type_code         VARCHAR2(30);
60748 l_adr_value_combination_id    NUMBER;
60749 l_adr_value_segment_code      VARCHAR2(30);
60750 
60751 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
60752 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
60753 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
60754 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
60755 
60756 -- 4262811 Variables ------------------------------------------------------------------------------------------
60757 l_entered_amt_idx             NUMBER;
60758 l_accted_amt_idx              NUMBER;
60759 l_acc_rev_flag                VARCHAR2(1);
60760 l_accrual_line_num            NUMBER;
60761 l_tmp_amt                     NUMBER;
60762 l_acc_rev_natural_side_code   VARCHAR2(1);
60763 
60764 l_num_entries                 NUMBER;
60765 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
60766 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
60767 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
60768 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
60769 l_recog_line_1                NUMBER;
60770 l_recog_line_2                NUMBER;
60771 
60772 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
60773 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
60774 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
60775 
60776 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
60777 
60778 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
60779 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
60780 
60781 ---------------------------------------------------------------------------------------------------------------
60782 
60783 
60784 --
60785 -- bulk performance
60786 --
60787 l_balance_type_code           VARCHAR2(1);
60788 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
60789 l_log_module                  VARCHAR2(240);
60790 
60791 --
60792 -- Upgrade strategy
60793 --
60794 l_actual_upg_option           VARCHAR2(1);
60795 l_enc_upg_option           VARCHAR2(1);
60796 
60797 --
60798 BEGIN
60799 --
60800 IF g_log_enabled THEN
60801       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_239';
60802 END IF;
60803 --
60804 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
60805 
60806       trace
60807          (p_msg      => 'BEGIN of AcctLineType_239'
60808          ,p_level    => C_LEVEL_PROCEDURE
60809          ,p_module   => l_log_module);
60810 
60811 END IF;
60812 --
60813 l_component_type             := 'AMB_JLT';
60814 l_component_code             := 'FA_CIP_REVAL_COST';
60815 l_component_type_code        := 'S';
60816 l_component_appl_id          :=  140;
60817 l_amb_context_code           := 'DEFAULT';
60818 l_entity_code                := 'TRANSACTIONS';
60819 l_event_class_code           := 'CIP_REVALUATION';
60820 l_event_type_code            := 'CIP_REVALUATION_ALL';
60821 l_line_definition_owner_code := 'S';
60822 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_R10';
60823 --
60824 l_balance_type_code          := 'A';
60825 l_segment                     := NULL;
60826 l_ccid                        := NULL;
60827 l_adr_transaction_coa_id      := NULL;
60828 l_adr_accounting_coa_id       := NULL;
60829 l_adr_flexfield_segment_code  := NULL;
60830 l_adr_flex_value_set_id       := NULL;
60831 l_adr_value_type_code         := NULL;
60832 l_adr_value_combination_id    := NULL;
60833 l_adr_value_segment_code      := NULL;
60834 
60835 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
60836 l_bflow_class_code           := '';    -- 4219869 Business Flow
60837 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
60838 l_budgetary_control_flag     := 'N';
60839 
60840 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
60841 l_bflow_applied_to_amt       := NULL; -- 5132302
60842 l_entered_amt_idx            := NULL;          -- 4262811
60843 l_accted_amt_idx             := NULL;          -- 4262811
60844 l_acc_rev_flag               := NULL;          -- 4262811
60845 l_accrual_line_num           := NULL;          -- 4262811
60846 l_tmp_amt                    := NULL;          -- 4262811
60847 --
60848  
60849 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
60850     l_balance_type_code <> 'B' THEN
60851 IF NVL(p_source_35,'
60852 ') =  'CIP COST'
60853  THEN 
60854 
60855    --
60856    XLA_AE_LINES_PKG.SetNewLine;
60857 
60858    p_balance_type_code          := l_balance_type_code;
60859    -- set the flag so later we will know whether the gain loss line needs to be created
60860    
60861    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
60862      p_actual_flag :='A';
60863    END IF;
60864 
60865    --
60866    -- bulk performance
60867    --
60868    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
60869                                       p_header_num   => 0); -- 4262811
60870    --
60871    -- set accounting line options
60872    --
60873    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
60877          , p_acct_entry_type_code       => 'A'
60874            p_natural_side_code          => 'D'
60875          , p_gain_or_loss_flag          => 'N'
60876          , p_gl_transfer_mode_code      => 'S'
60878          , p_switch_side_flag           => 'Y'
60879          , p_merge_duplicate_code       => 'N'
60880          );
60881    --
60882    l_acc_rev_natural_side_code := 'C';  -- 4262811
60883    -- 
60884    --
60885    -- set accounting line type info
60886    --
60887    xla_ae_lines_pkg.SetAcctLineType
60888       (p_component_type             => l_component_type
60889       ,p_event_type_code            => l_event_type_code
60890       ,p_line_definition_owner_code => l_line_definition_owner_code
60891       ,p_line_definition_code       => l_line_definition_code
60892       ,p_accounting_line_code       => l_component_code
60893       ,p_accounting_line_type_code  => l_component_type_code
60894       ,p_accounting_line_appl_id    => l_component_appl_id
60895       ,p_amb_context_code           => l_amb_context_code
60896       ,p_entity_code                => l_entity_code
60897       ,p_event_class_code           => l_event_class_code);
60898    --
60899    -- set accounting class
60900    --
60901    xla_ae_lines_pkg.SetAcctClass(
60902            p_accounting_class_code  => 'ASSET'
60903          , p_ae_header_id           => l_ae_header_id
60904          );
60905 
60906    --
60907    -- set rounding class
60908    --
60909    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
60910                       'ASSET';
60911 
60912    --
60913    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
60914    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
60915    --
60916    -- bulk performance
60917    --
60918    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
60919 
60920    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
60921       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
60922 
60923    -- 4955764
60924    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
60925       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
60926 
60927    -- 4458381 Public Sector Enh
60928    
60929    --
60930    -- set accounting attributes for the line type
60931    --
60932    l_entered_amt_idx := 4;
60933    l_accted_amt_idx  := 6;
60934    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
60935    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
60936    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
60937    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
60938    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
60939    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
60940    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
60941    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
60942    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
60943    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
60944    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
60945    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
60946    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
60947 
60948    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
60949    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
60950 
60951    ---------------------------------------------------------------------------------------------------------------
60952    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
60953    ---------------------------------------------------------------------------------------------------------------
60954    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
60955 
60956    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
60957    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
60958 
60959    IF xla_accounting_cache_pkg.GetValueChar
60960          (p_source_code         => 'LEDGER_CATEGORY_CODE'
60961          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
60962    AND l_bflow_method_code = 'PRIOR_ENTRY'
60963 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
60964    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
60965          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
60966        )
60967    THEN
60968          xla_ae_lines_pkg.BflowUpgEntry
60969            (p_business_method_code    => l_bflow_method_code
60970            ,p_business_class_code     => l_bflow_class_code
60971            ,p_balance_type            => l_balance_type_code);
60972    ELSE
60973       NULL;
60974 -- No business flow processing for business flow method of NONE.
60975    END IF;
60976 
60977    --
60978    -- call analytical criteria
60979    --
60980    
60981    --
60982    -- call description
60983    --
60984    
60985 xla_ae_lines_pkg.SetLineDescription(
60986    p_ae_header_id => l_ae_header_id
60987   ,p_description  => Description_42 (
60988      p_application_id         => p_application_id
60989    , p_ae_header_id           => l_ae_header_id 
60990 , p_source_1 => p_source_1
60991    )
60992 );
60993 
60994 
60995    --
60996    -- call ADRs
60997    -- Bug 4922099
60998    --
60999    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
61000         (NVL(l_actual_upg_option, 'N') = 'O') OR
61001         (NVL(l_enc_upg_option, 'N') = 'O')
61005    --
61002       )
61003    THEN
61004    NULL;
61006    --
61007    
61008   l_ccid := AcctDerRule_173(
61009            p_application_id           => p_application_id
61010          , p_ae_header_id             => l_ae_header_id 
61011 , p_source_3 => p_source_3
61012 , p_source_30 => p_source_30
61013          , x_transaction_coa_id       => l_adr_transaction_coa_id
61014          , x_accounting_coa_id        => l_adr_accounting_coa_id
61015          , x_value_type_code          => l_adr_value_type_code
61016          , p_side                     => 'NA'
61017    );
61018 
61019    xla_ae_lines_pkg.set_ccid(
61020     p_code_combination_id          => l_ccid
61021   , p_value_type_code              => l_adr_value_type_code
61022   , p_transaction_coa_id           => l_adr_transaction_coa_id
61023   , p_accounting_coa_id            => l_adr_accounting_coa_id
61024   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
61025   , p_adr_type_code                => 'S'
61026   , p_component_type               => l_component_type
61027   , p_component_code               => l_component_code
61028   , p_component_type_code          => l_component_type_code
61029   , p_component_appl_id            => l_component_appl_id
61030   , p_amb_context_code             => l_amb_context_code
61031   , p_side                         => 'NA'
61032   );
61033 
61034 
61035    l_segment := AcctDerRule_146(
61036            p_application_id           => p_application_id
61037          , p_ae_header_id             => l_ae_header_id 
61038 , p_source_3 => p_source_3
61039 , p_source_7 => p_source_7
61040          , x_transaction_coa_id       => l_adr_transaction_coa_id
61041          , x_accounting_coa_id        => l_adr_accounting_coa_id
61042          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
61043          , x_flex_value_set_id        => l_adr_flex_value_set_id
61044          , x_value_type_code          => l_adr_value_type_code
61045          , x_value_combination_id     => l_adr_value_combination_id
61046          , x_value_segment_code       => l_adr_value_segment_code
61047          , p_side                     => 'NA'
61048          , p_override_seg_flag        => 'Y'
61049    );
61050 
61051    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
61052 
61053       xla_ae_lines_pkg.set_segment(
61054           p_to_segment_code         => 'GL_ACCOUNT'
61055         , p_segment_value           => l_segment
61056         , p_from_segment_code       => l_adr_value_segment_code
61057         , p_from_combination_id     => l_adr_value_combination_id
61058         , p_value_type_code         => l_adr_value_type_code
61059         , p_transaction_coa_id      => l_adr_transaction_coa_id
61060         , p_accounting_coa_id       => l_adr_accounting_coa_id
61061         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
61062         , p_flex_value_set_id       => l_adr_flex_value_set_id
61063         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
61064         , p_adr_type_code           => 'S'
61065         , p_component_type          => l_component_type
61066         , p_component_code          => l_component_code
61067         , p_component_type_code     => l_component_type_code
61068         , p_component_appl_id       => l_component_appl_id
61069         , p_amb_context_code        => l_amb_context_code
61070         , p_entity_code             => 'TRANSACTIONS'
61071         , p_event_class_code        => 'CIP_REVALUATION'
61072         , p_side                    => 'NA'
61073         );
61074 
61075   END IF;
61076 
61077    l_segment := AcctDerRule_168(
61078            p_application_id           => p_application_id
61079          , p_ae_header_id             => l_ae_header_id 
61080 , p_source_3 => p_source_3
61081 , p_source_29 => p_source_29
61082          , x_transaction_coa_id       => l_adr_transaction_coa_id
61083          , x_accounting_coa_id        => l_adr_accounting_coa_id
61084          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
61085          , x_flex_value_set_id        => l_adr_flex_value_set_id
61086          , x_value_type_code          => l_adr_value_type_code
61087          , x_value_combination_id     => l_adr_value_combination_id
61088          , x_value_segment_code       => l_adr_value_segment_code
61089          , p_side                     => 'NA'
61090          , p_override_seg_flag        => 'Y'
61091    );
61092 
61093    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
61094 
61095       xla_ae_lines_pkg.set_segment(
61096           p_to_segment_code         => 'GL_BALANCING'
61097         , p_segment_value           => l_segment
61098         , p_from_segment_code       => l_adr_value_segment_code
61099         , p_from_combination_id     => l_adr_value_combination_id
61100         , p_value_type_code         => l_adr_value_type_code
61101         , p_transaction_coa_id      => l_adr_transaction_coa_id
61102         , p_accounting_coa_id       => l_adr_accounting_coa_id
61103         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
61104         , p_flex_value_set_id       => l_adr_flex_value_set_id
61105         , p_adr_code                => 'FA_EXPENSE_ACCT'
61106         , p_adr_type_code           => 'S'
61107         , p_component_type          => l_component_type
61108         , p_component_code          => l_component_code
61109         , p_component_type_code     => l_component_type_code
61110         , p_component_appl_id       => l_component_appl_id
61111         , p_amb_context_code        => l_amb_context_code
61112         , p_entity_code             => 'TRANSACTIONS'
61113         , p_event_class_code        => 'CIP_REVALUATION'
61114         , p_side                    => 'NA'
61115         );
61116 
61117   END IF;
61118 
61119    --
61120    --
61121    END IF;
61122    --
61123    -- Bug 4922099
61124    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
61125           (NVL(l_enc_upg_option, 'N') = 'O')
61129    THEN
61126         ) AND
61127         (l_bflow_method_code = 'PRIOR_ENTRY')
61128       )
61130       IF
61131       --
61132       1 = 2
61133       --
61134       THEN
61135       xla_accounting_err_pkg.build_message
61136                                     (p_appli_s_name            => 'XLA'
61137                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
61138                                     ,p_token_1                 => 'LINE_NUMBER'
61139                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
61140                                     ,p_token_2                 => 'LINE_TYPE_NAME'
61141                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
61142                                                                              l_component_type
61143                                                                             ,l_component_code
61144                                                                             ,l_component_type_code
61145                                                                             ,l_component_appl_id
61146                                                                             ,l_amb_context_code
61147                                                                             ,l_entity_code
61148                                                                             ,l_event_class_code
61149                                                                            )
61150                                     ,p_token_3                 => 'OWNER'
61151                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
61152                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
61153                                                                           ,p_lookup_code    => l_component_type_code
61154                                                                          )
61155                                     ,p_token_4                 => 'PRODUCT_NAME'
61156                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
61157                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
61158                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
61159                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
61160                                     ,p_ae_header_id            =>  NULL
61161                                        );
61162 
61163         IF (C_LEVEL_ERROR>= g_log_level) THEN
61164                  trace
61165                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
61166                       ,p_level    => C_LEVEL_ERROR
61167                       ,p_module   => l_log_module);
61168         END IF;
61169       END IF;
61170    END IF;
61171    --
61172    --
61173    ------------------------------------------------------------------------------------------------
61174    -- 4219869 Business Flow
61175    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
61176    -- Prior Entry.  Currently, the following code is always generated.
61177    ------------------------------------------------------------------------------------------------
61178    XLA_AE_LINES_PKG.ValidateCurrentLine;
61179 
61180    ------------------------------------------------------------------------------------
61181    -- 4219869 Business Flow
61182    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
61183    ------------------------------------------------------------------------------------
61184    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
61185 
61186    ----------------------------------------------------------------------------------
61187    -- 4219869 Business Flow
61188    -- Update journal entry status -- Need to generate this within IF <condition>
61189    ----------------------------------------------------------------------------------
61190    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
61191          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
61192          ,p_balance_type_code => l_balance_type_code
61193          );
61194 
61195    -------------------------------------------------------------------------------------------
61196    -- 4262811 - Generate the Accrual Reversal lines
61197    -------------------------------------------------------------------------------------------
61198    BEGIN
61199       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
61200                               (g_array_event(p_event_id).array_value_num('header_index'));
61201       IF l_acc_rev_flag IS NULL THEN
61202          l_acc_rev_flag := 'N';
61203       END IF;
61204    EXCEPTION
61205       WHEN OTHERS THEN
61206          l_acc_rev_flag := 'N';
61207    END;
61208    --
61209    IF (l_acc_rev_flag = 'Y') THEN
61210 
61211        -- 4645092  ------------------------------------------------------------------------------
61212        -- To allow MPA report to determine if it should generate report process
61213        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
61214        ------------------------------------------------------------------------------------------
61215 
61216        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
61217        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
61218    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
61219    -- call ADRs
61220    -- Bug 4922099
61221    --
61222    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
61223         (NVL(l_actual_upg_option, 'N') = 'O') OR
61224         (NVL(l_enc_upg_option, 'N') = 'O')
61225       )
61226    THEN
61227    NULL;
61228    --
61229    --
61230    
61231   l_ccid := AcctDerRule_173(
61235 , p_source_30 => p_source_30
61232            p_application_id           => p_application_id
61233          , p_ae_header_id             => l_ae_header_id 
61234 , p_source_3 => p_source_3
61236          , x_transaction_coa_id       => l_adr_transaction_coa_id
61237          , x_accounting_coa_id        => l_adr_accounting_coa_id
61238          , x_value_type_code          => l_adr_value_type_code
61239          , p_side                     => 'NA'
61240    );
61241 
61242    xla_ae_lines_pkg.set_ccid(
61243     p_code_combination_id          => l_ccid
61244   , p_value_type_code              => l_adr_value_type_code
61245   , p_transaction_coa_id           => l_adr_transaction_coa_id
61246   , p_accounting_coa_id            => l_adr_accounting_coa_id
61247   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
61248   , p_adr_type_code                => 'S'
61249   , p_component_type               => l_component_type
61250   , p_component_code               => l_component_code
61251   , p_component_type_code          => l_component_type_code
61252   , p_component_appl_id            => l_component_appl_id
61253   , p_amb_context_code             => l_amb_context_code
61254   , p_side                         => 'NA'
61255   );
61256 
61257 
61258    l_segment := AcctDerRule_146(
61259            p_application_id           => p_application_id
61260          , p_ae_header_id             => l_ae_header_id 
61261 , p_source_3 => p_source_3
61262 , p_source_7 => p_source_7
61263          , x_transaction_coa_id       => l_adr_transaction_coa_id
61264          , x_accounting_coa_id        => l_adr_accounting_coa_id
61265          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
61266          , x_flex_value_set_id        => l_adr_flex_value_set_id
61267          , x_value_type_code          => l_adr_value_type_code
61268          , x_value_combination_id     => l_adr_value_combination_id
61269          , x_value_segment_code       => l_adr_value_segment_code
61270          , p_side                     => 'NA'
61271          , p_override_seg_flag        => 'Y'
61272    );
61273 
61274    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
61275 
61276       xla_ae_lines_pkg.set_segment(
61277           p_to_segment_code         => 'GL_ACCOUNT'
61278         , p_segment_value           => l_segment
61279         , p_from_segment_code       => l_adr_value_segment_code
61280         , p_from_combination_id     => l_adr_value_combination_id
61281         , p_value_type_code         => l_adr_value_type_code
61282         , p_transaction_coa_id      => l_adr_transaction_coa_id
61283         , p_accounting_coa_id       => l_adr_accounting_coa_id
61284         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
61285         , p_flex_value_set_id       => l_adr_flex_value_set_id
61286         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
61287         , p_adr_type_code           => 'S'
61288         , p_component_type          => l_component_type
61289         , p_component_code          => l_component_code
61290         , p_component_type_code     => l_component_type_code
61291         , p_component_appl_id       => l_component_appl_id
61292         , p_amb_context_code        => l_amb_context_code
61293         , p_entity_code             => 'TRANSACTIONS'
61294         , p_event_class_code        => 'CIP_REVALUATION'
61295         , p_side                    => 'NA'
61296         );
61297 
61298   END IF;
61299 
61300    l_segment := AcctDerRule_168(
61301            p_application_id           => p_application_id
61302          , p_ae_header_id             => l_ae_header_id 
61303 , p_source_3 => p_source_3
61304 , p_source_29 => p_source_29
61305          , x_transaction_coa_id       => l_adr_transaction_coa_id
61306          , x_accounting_coa_id        => l_adr_accounting_coa_id
61307          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
61308          , x_flex_value_set_id        => l_adr_flex_value_set_id
61309          , x_value_type_code          => l_adr_value_type_code
61310          , x_value_combination_id     => l_adr_value_combination_id
61311          , x_value_segment_code       => l_adr_value_segment_code
61312          , p_side                     => 'NA'
61313          , p_override_seg_flag        => 'Y'
61314    );
61315 
61316    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
61317 
61318       xla_ae_lines_pkg.set_segment(
61319           p_to_segment_code         => 'GL_BALANCING'
61320         , p_segment_value           => l_segment
61321         , p_from_segment_code       => l_adr_value_segment_code
61322         , p_from_combination_id     => l_adr_value_combination_id
61323         , p_value_type_code         => l_adr_value_type_code
61324         , p_transaction_coa_id      => l_adr_transaction_coa_id
61325         , p_accounting_coa_id       => l_adr_accounting_coa_id
61326         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
61327         , p_flex_value_set_id       => l_adr_flex_value_set_id
61328         , p_adr_code                => 'FA_EXPENSE_ACCT'
61329         , p_adr_type_code           => 'S'
61330         , p_component_type          => l_component_type
61331         , p_component_code          => l_component_code
61332         , p_component_type_code     => l_component_type_code
61333         , p_component_appl_id       => l_component_appl_id
61334         , p_amb_context_code        => l_amb_context_code
61335         , p_entity_code             => 'TRANSACTIONS'
61336         , p_event_class_code        => 'CIP_REVALUATION'
61337         , p_side                    => 'NA'
61338         );
61339 
61340   END IF;
61341 
61342    --
61343    --
61344    END IF;
61345 
61346        --
61347        -- Update the line information that should be overwritten
61348        --
61349        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
61350                                          p_header_num   => 1);
61354 
61351        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
61352 
61353        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
61355        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
61356           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
61357        END IF;
61358 
61359       --
61360       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
61361       --
61362       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
61363           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
61364       ELSE
61365           ---------------------------------------------------------------------------------------------------
61366           -- 4262811a Switch Sign
61367           ---------------------------------------------------------------------------------------------------
61368           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
61369           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
61370                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
61371           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
61372                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
61373           -- 5132302
61374           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
61375                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
61376 
61377       END IF;
61378 
61379       -- 4955764
61380       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
61381       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
61382 
61383 
61384       XLA_AE_LINES_PKG.ValidateCurrentLine;
61385       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
61386 
61387       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
61388                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
61389                ,p_balance_type_code => l_balance_type_code);
61390 
61391    END IF;
61392 
61393    -----------------------------------------------------------------------------------------
61394    -- 4262811 Multiperiod Accounting
61395    -----------------------------------------------------------------------------------------
61396      -- No MPA option is assigned.
61397 
61398 
61399 END IF;
61400 END IF;
61401 --
61402 
61403 --
61404 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
61405    trace
61406       (p_msg      => 'END of AcctLineType_239'
61407       ,p_level    => C_LEVEL_PROCEDURE
61408       ,p_module   => l_log_module);
61409 END IF;
61410 --
61411 EXCEPTION
61412   WHEN xla_exceptions_pkg.application_exception THEN
61413       RAISE;
61414   WHEN OTHERS THEN
61415        xla_exceptions_pkg.raise_message
61416            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_239');
61417 END AcctLineType_239;
61418 --
61419 
61420 ---------------------------------------
61421 --
61422 -- PRIVATE FUNCTION
61423 --         AcctLineType_240
61424 --
61425 ---------------------------------------
61426 PROCEDURE AcctLineType_240 (
61427   p_application_id        IN NUMBER
61428  ,p_event_id              IN NUMBER
61429  ,p_calculate_acctd_flag  IN VARCHAR2
61430  ,p_calculate_g_l_flag    IN VARCHAR2
61431  ,p_actual_flag           IN OUT VARCHAR2
61432  ,p_balance_type_code     OUT VARCHAR2
61433  ,p_gain_or_loss_ref      OUT VARCHAR2
61434  
61435 --Period Close Date
61436  , p_source_1            IN DATE
61437 --Generated Code Combination Identifier
61438  , p_source_3            IN NUMBER
61439 --Revaluation Reserve Account
61440  , p_source_11            IN VARCHAR2
61441 --Generated Offset Code Combination Identifier
61442  , p_source_17            IN NUMBER
61443 --Expense Account Code Combination Identifier
61444  , p_source_29            IN NUMBER
61445 --Default Code Combination Identifier
61446  , p_source_30            IN NUMBER
61447 --Adjustment Type
61448  , p_source_35            IN VARCHAR2
61449 --Transaction Header Identifier
61450  , p_source_36            IN NUMBER
61451 --Adjustment Line Identifier
61452  , p_source_37            IN NUMBER
61453 --Distribution Type Code
61454  , p_source_38            IN VARCHAR2
61455 --Entered Amount
61456  , p_source_39            IN NUMBER
61457 --Currency Code
61458  , p_source_40            IN VARCHAR2
61459 )
61460 IS
61461 
61462 l_component_type              VARCHAR2(80);
61463 l_component_code              VARCHAR2(30);
61464 l_component_type_code         VARCHAR2(1);
61465 l_component_appl_id           INTEGER;
61466 l_amb_context_code            VARCHAR2(30);
61467 l_entity_code                 VARCHAR2(30);
61468 l_event_class_code            VARCHAR2(30);
61469 l_ae_header_id                NUMBER;
61470 l_event_type_code             VARCHAR2(30);
61471 l_line_definition_code        VARCHAR2(30);
61472 l_line_definition_owner_code  VARCHAR2(1);
61473 --
61474 -- adr variables
61475 l_segment                     VARCHAR2(30);
61476 l_ccid                        NUMBER;
61477 l_adr_transaction_coa_id      NUMBER;
61478 l_adr_accounting_coa_id       NUMBER;
61479 l_adr_flexfield_segment_code  VARCHAR2(30);
61480 l_adr_flex_value_set_id       NUMBER;
61481 l_adr_value_type_code         VARCHAR2(30);
61482 l_adr_value_combination_id    NUMBER;
61483 l_adr_value_segment_code      VARCHAR2(30);
61484 
61488 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
61485 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
61486 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
61487 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
61489 
61490 -- 4262811 Variables ------------------------------------------------------------------------------------------
61491 l_entered_amt_idx             NUMBER;
61492 l_accted_amt_idx              NUMBER;
61493 l_acc_rev_flag                VARCHAR2(1);
61494 l_accrual_line_num            NUMBER;
61495 l_tmp_amt                     NUMBER;
61496 l_acc_rev_natural_side_code   VARCHAR2(1);
61497 
61498 l_num_entries                 NUMBER;
61499 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
61500 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
61501 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
61502 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
61503 l_recog_line_1                NUMBER;
61504 l_recog_line_2                NUMBER;
61505 
61506 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
61507 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
61508 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
61509 
61510 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
61511 
61512 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
61513 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
61514 
61515 ---------------------------------------------------------------------------------------------------------------
61516 
61517 
61518 --
61519 -- bulk performance
61520 --
61521 l_balance_type_code           VARCHAR2(1);
61522 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
61523 l_log_module                  VARCHAR2(240);
61524 
61525 --
61526 -- Upgrade strategy
61527 --
61528 l_actual_upg_option           VARCHAR2(1);
61529 l_enc_upg_option           VARCHAR2(1);
61530 
61531 --
61532 BEGIN
61533 --
61534 IF g_log_enabled THEN
61535       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_240';
61536 END IF;
61537 --
61538 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
61539 
61540       trace
61541          (p_msg      => 'BEGIN of AcctLineType_240'
61542          ,p_level    => C_LEVEL_PROCEDURE
61543          ,p_module   => l_log_module);
61544 
61545 END IF;
61546 --
61547 l_component_type             := 'AMB_JLT';
61548 l_component_code             := 'FA_CIP_REVAL_RESERVE';
61549 l_component_type_code        := 'S';
61550 l_component_appl_id          :=  140;
61551 l_amb_context_code           := 'DEFAULT';
61552 l_entity_code                := 'TRANSACTIONS';
61553 l_event_class_code           := 'CIP_REVALUATION';
61554 l_event_type_code            := 'CIP_REVALUATION_ALL';
61555 l_line_definition_owner_code := 'S';
61556 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_R10';
61557 --
61558 l_balance_type_code          := 'A';
61559 l_segment                     := NULL;
61560 l_ccid                        := NULL;
61561 l_adr_transaction_coa_id      := NULL;
61562 l_adr_accounting_coa_id       := NULL;
61563 l_adr_flexfield_segment_code  := NULL;
61564 l_adr_flex_value_set_id       := NULL;
61565 l_adr_value_type_code         := NULL;
61566 l_adr_value_combination_id    := NULL;
61567 l_adr_value_segment_code      := NULL;
61568 
61569 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
61570 l_bflow_class_code           := '';    -- 4219869 Business Flow
61571 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
61572 l_budgetary_control_flag     := 'N';
61573 
61574 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
61575 l_bflow_applied_to_amt       := NULL; -- 5132302
61576 l_entered_amt_idx            := NULL;          -- 4262811
61577 l_accted_amt_idx             := NULL;          -- 4262811
61578 l_acc_rev_flag               := NULL;          -- 4262811
61579 l_accrual_line_num           := NULL;          -- 4262811
61580 l_tmp_amt                    := NULL;          -- 4262811
61581 --
61582  
61583 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
61584     l_balance_type_code <> 'B' THEN
61585 IF NVL(p_source_35,'
61586 ') =  'REVAL RESERVE'
61587  THEN 
61588 
61589    --
61590    XLA_AE_LINES_PKG.SetNewLine;
61591 
61592    p_balance_type_code          := l_balance_type_code;
61593    -- set the flag so later we will know whether the gain loss line needs to be created
61594    
61595    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
61596      p_actual_flag :='A';
61597    END IF;
61598 
61599    --
61600    -- bulk performance
61601    --
61602    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
61603                                       p_header_num   => 0); -- 4262811
61604    --
61605    -- set accounting line options
61606    --
61607    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
61608            p_natural_side_code          => 'C'
61609          , p_gain_or_loss_flag          => 'N'
61610          , p_gl_transfer_mode_code      => 'S'
61611          , p_acct_entry_type_code       => 'A'
61612          , p_switch_side_flag           => 'Y'
61613          , p_merge_duplicate_code       => 'N'
61614          );
61615    --
61616    l_acc_rev_natural_side_code := 'D';  -- 4262811
61617    -- 
61618    --
61619    -- set accounting line type info
61620    --
61621    xla_ae_lines_pkg.SetAcctLineType
61622       (p_component_type             => l_component_type
61623       ,p_event_type_code            => l_event_type_code
61627       ,p_accounting_line_type_code  => l_component_type_code
61624       ,p_line_definition_owner_code => l_line_definition_owner_code
61625       ,p_line_definition_code       => l_line_definition_code
61626       ,p_accounting_line_code       => l_component_code
61628       ,p_accounting_line_appl_id    => l_component_appl_id
61629       ,p_amb_context_code           => l_amb_context_code
61630       ,p_entity_code                => l_entity_code
61631       ,p_event_class_code           => l_event_class_code);
61632    --
61633    -- set accounting class
61634    --
61635    xla_ae_lines_pkg.SetAcctClass(
61636            p_accounting_class_code  => 'ASSET'
61637          , p_ae_header_id           => l_ae_header_id
61638          );
61639 
61640    --
61641    -- set rounding class
61642    --
61643    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
61644                       'ASSET';
61645 
61646    --
61647    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
61648    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
61649    --
61650    -- bulk performance
61651    --
61652    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
61653 
61654    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
61655       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
61656 
61657    -- 4955764
61658    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
61659       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
61660 
61661    -- 4458381 Public Sector Enh
61662    
61663    --
61664    -- set accounting attributes for the line type
61665    --
61666    l_entered_amt_idx := 4;
61667    l_accted_amt_idx  := 6;
61668    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
61669    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
61670    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
61671    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
61672    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
61673    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
61674    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
61675    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
61676    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
61677    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
61678    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
61679    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
61680    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
61681 
61682    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
61683    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
61684 
61685    ---------------------------------------------------------------------------------------------------------------
61686    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
61687    ---------------------------------------------------------------------------------------------------------------
61688    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
61689 
61690    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
61691    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
61692 
61693    IF xla_accounting_cache_pkg.GetValueChar
61694          (p_source_code         => 'LEDGER_CATEGORY_CODE'
61695          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
61696    AND l_bflow_method_code = 'PRIOR_ENTRY'
61697 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
61698    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
61699          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
61700        )
61701    THEN
61702          xla_ae_lines_pkg.BflowUpgEntry
61703            (p_business_method_code    => l_bflow_method_code
61704            ,p_business_class_code     => l_bflow_class_code
61705            ,p_balance_type            => l_balance_type_code);
61706    ELSE
61707       NULL;
61708 -- No business flow processing for business flow method of NONE.
61709    END IF;
61710 
61711    --
61712    -- call analytical criteria
61713    --
61714    
61715    --
61716    -- call description
61717    --
61718    
61719 xla_ae_lines_pkg.SetLineDescription(
61720    p_ae_header_id => l_ae_header_id
61721   ,p_description  => Description_43 (
61722      p_application_id         => p_application_id
61723    , p_ae_header_id           => l_ae_header_id 
61724 , p_source_1 => p_source_1
61725    )
61726 );
61727 
61728 
61729    --
61730    -- call ADRs
61731    -- Bug 4922099
61732    --
61733    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
61734         (NVL(l_actual_upg_option, 'N') = 'O') OR
61735         (NVL(l_enc_upg_option, 'N') = 'O')
61736       )
61737    THEN
61738    NULL;
61739    --
61740    --
61741    
61742   l_ccid := AcctDerRule_174(
61743            p_application_id           => p_application_id
61744          , p_ae_header_id             => l_ae_header_id 
61745 , p_source_3 => p_source_3
61746 , p_source_17 => p_source_17
61747 , p_source_30 => p_source_30
61748          , x_transaction_coa_id       => l_adr_transaction_coa_id
61749          , x_accounting_coa_id        => l_adr_accounting_coa_id
61750          , x_value_type_code          => l_adr_value_type_code
61751          , p_side                     => 'NA'
61752    );
61753 
61757   , p_transaction_coa_id           => l_adr_transaction_coa_id
61754    xla_ae_lines_pkg.set_ccid(
61755     p_code_combination_id          => l_ccid
61756   , p_value_type_code              => l_adr_value_type_code
61758   , p_accounting_coa_id            => l_adr_accounting_coa_id
61759   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
61760   , p_adr_type_code                => 'S'
61761   , p_component_type               => l_component_type
61762   , p_component_code               => l_component_code
61763   , p_component_type_code          => l_component_type_code
61764   , p_component_appl_id            => l_component_appl_id
61765   , p_amb_context_code             => l_amb_context_code
61766   , p_side                         => 'NA'
61767   );
61768 
61769 
61770    l_segment := AcctDerRule_150(
61771            p_application_id           => p_application_id
61772          , p_ae_header_id             => l_ae_header_id 
61773 , p_source_3 => p_source_3
61774 , p_source_11 => p_source_11
61775          , x_transaction_coa_id       => l_adr_transaction_coa_id
61776          , x_accounting_coa_id        => l_adr_accounting_coa_id
61777          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
61778          , x_flex_value_set_id        => l_adr_flex_value_set_id
61779          , x_value_type_code          => l_adr_value_type_code
61780          , x_value_combination_id     => l_adr_value_combination_id
61781          , x_value_segment_code       => l_adr_value_segment_code
61782          , p_side                     => 'NA'
61783          , p_override_seg_flag        => 'Y'
61784    );
61785 
61786    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
61787 
61788       xla_ae_lines_pkg.set_segment(
61789           p_to_segment_code         => 'GL_ACCOUNT'
61790         , p_segment_value           => l_segment
61791         , p_from_segment_code       => l_adr_value_segment_code
61792         , p_from_combination_id     => l_adr_value_combination_id
61793         , p_value_type_code         => l_adr_value_type_code
61794         , p_transaction_coa_id      => l_adr_transaction_coa_id
61795         , p_accounting_coa_id       => l_adr_accounting_coa_id
61796         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
61797         , p_flex_value_set_id       => l_adr_flex_value_set_id
61798         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
61799         , p_adr_type_code           => 'S'
61800         , p_component_type          => l_component_type
61801         , p_component_code          => l_component_code
61802         , p_component_type_code     => l_component_type_code
61803         , p_component_appl_id       => l_component_appl_id
61804         , p_amb_context_code        => l_amb_context_code
61805         , p_entity_code             => 'TRANSACTIONS'
61806         , p_event_class_code        => 'CIP_REVALUATION'
61807         , p_side                    => 'NA'
61808         );
61809 
61810   END IF;
61811 
61812    l_segment := AcctDerRule_168(
61813            p_application_id           => p_application_id
61814          , p_ae_header_id             => l_ae_header_id 
61815 , p_source_3 => p_source_3
61816 , p_source_29 => p_source_29
61817          , x_transaction_coa_id       => l_adr_transaction_coa_id
61818          , x_accounting_coa_id        => l_adr_accounting_coa_id
61819          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
61820          , x_flex_value_set_id        => l_adr_flex_value_set_id
61821          , x_value_type_code          => l_adr_value_type_code
61822          , x_value_combination_id     => l_adr_value_combination_id
61823          , x_value_segment_code       => l_adr_value_segment_code
61824          , p_side                     => 'NA'
61825          , p_override_seg_flag        => 'Y'
61826    );
61827 
61828    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
61829 
61830       xla_ae_lines_pkg.set_segment(
61831           p_to_segment_code         => 'GL_BALANCING'
61832         , p_segment_value           => l_segment
61833         , p_from_segment_code       => l_adr_value_segment_code
61834         , p_from_combination_id     => l_adr_value_combination_id
61835         , p_value_type_code         => l_adr_value_type_code
61836         , p_transaction_coa_id      => l_adr_transaction_coa_id
61837         , p_accounting_coa_id       => l_adr_accounting_coa_id
61838         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
61839         , p_flex_value_set_id       => l_adr_flex_value_set_id
61840         , p_adr_code                => 'FA_EXPENSE_ACCT'
61841         , p_adr_type_code           => 'S'
61842         , p_component_type          => l_component_type
61843         , p_component_code          => l_component_code
61844         , p_component_type_code     => l_component_type_code
61845         , p_component_appl_id       => l_component_appl_id
61846         , p_amb_context_code        => l_amb_context_code
61847         , p_entity_code             => 'TRANSACTIONS'
61848         , p_event_class_code        => 'CIP_REVALUATION'
61849         , p_side                    => 'NA'
61850         );
61851 
61852   END IF;
61853 
61854    --
61855    --
61856    END IF;
61857    --
61858    -- Bug 4922099
61859    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
61860           (NVL(l_enc_upg_option, 'N') = 'O')
61861         ) AND
61862         (l_bflow_method_code = 'PRIOR_ENTRY')
61863       )
61864    THEN
61865       IF
61866       --
61867       1 = 2
61868       --
61869       THEN
61870       xla_accounting_err_pkg.build_message
61871                                     (p_appli_s_name            => 'XLA'
61872                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
61873                                     ,p_token_1                 => 'LINE_NUMBER'
61874                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
61878                                                                             ,l_component_code
61875                                     ,p_token_2                 => 'LINE_TYPE_NAME'
61876                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
61877                                                                              l_component_type
61879                                                                             ,l_component_type_code
61880                                                                             ,l_component_appl_id
61881                                                                             ,l_amb_context_code
61882                                                                             ,l_entity_code
61883                                                                             ,l_event_class_code
61884                                                                            )
61885                                     ,p_token_3                 => 'OWNER'
61886                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
61887                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
61888                                                                           ,p_lookup_code    => l_component_type_code
61889                                                                          )
61890                                     ,p_token_4                 => 'PRODUCT_NAME'
61891                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
61892                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
61893                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
61894                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
61895                                     ,p_ae_header_id            =>  NULL
61896                                        );
61897 
61898         IF (C_LEVEL_ERROR>= g_log_level) THEN
61899                  trace
61900                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
61901                       ,p_level    => C_LEVEL_ERROR
61902                       ,p_module   => l_log_module);
61903         END IF;
61904       END IF;
61905    END IF;
61906    --
61907    --
61908    ------------------------------------------------------------------------------------------------
61909    -- 4219869 Business Flow
61910    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
61911    -- Prior Entry.  Currently, the following code is always generated.
61912    ------------------------------------------------------------------------------------------------
61913    XLA_AE_LINES_PKG.ValidateCurrentLine;
61914 
61915    ------------------------------------------------------------------------------------
61916    -- 4219869 Business Flow
61917    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
61918    ------------------------------------------------------------------------------------
61919    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
61920 
61921    ----------------------------------------------------------------------------------
61922    -- 4219869 Business Flow
61923    -- Update journal entry status -- Need to generate this within IF <condition>
61924    ----------------------------------------------------------------------------------
61925    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
61926          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
61927          ,p_balance_type_code => l_balance_type_code
61928          );
61929 
61930    -------------------------------------------------------------------------------------------
61931    -- 4262811 - Generate the Accrual Reversal lines
61932    -------------------------------------------------------------------------------------------
61933    BEGIN
61934       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
61935                               (g_array_event(p_event_id).array_value_num('header_index'));
61936       IF l_acc_rev_flag IS NULL THEN
61937          l_acc_rev_flag := 'N';
61938       END IF;
61939    EXCEPTION
61940       WHEN OTHERS THEN
61941          l_acc_rev_flag := 'N';
61942    END;
61943    --
61944    IF (l_acc_rev_flag = 'Y') THEN
61945 
61946        -- 4645092  ------------------------------------------------------------------------------
61947        -- To allow MPA report to determine if it should generate report process
61948        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
61949        ------------------------------------------------------------------------------------------
61950 
61951        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
61952        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
61953    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
61954    -- call ADRs
61955    -- Bug 4922099
61956    --
61957    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
61958         (NVL(l_actual_upg_option, 'N') = 'O') OR
61959         (NVL(l_enc_upg_option, 'N') = 'O')
61960       )
61961    THEN
61962    NULL;
61963    --
61964    --
61965    
61966   l_ccid := AcctDerRule_174(
61967            p_application_id           => p_application_id
61968          , p_ae_header_id             => l_ae_header_id 
61969 , p_source_3 => p_source_3
61970 , p_source_17 => p_source_17
61971 , p_source_30 => p_source_30
61972          , x_transaction_coa_id       => l_adr_transaction_coa_id
61973          , x_accounting_coa_id        => l_adr_accounting_coa_id
61974          , x_value_type_code          => l_adr_value_type_code
61975          , p_side                     => 'NA'
61976    );
61977 
61978    xla_ae_lines_pkg.set_ccid(
61979     p_code_combination_id          => l_ccid
61983   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
61980   , p_value_type_code              => l_adr_value_type_code
61981   , p_transaction_coa_id           => l_adr_transaction_coa_id
61982   , p_accounting_coa_id            => l_adr_accounting_coa_id
61984   , p_adr_type_code                => 'S'
61985   , p_component_type               => l_component_type
61986   , p_component_code               => l_component_code
61987   , p_component_type_code          => l_component_type_code
61988   , p_component_appl_id            => l_component_appl_id
61989   , p_amb_context_code             => l_amb_context_code
61990   , p_side                         => 'NA'
61991   );
61992 
61993 
61994    l_segment := AcctDerRule_150(
61995            p_application_id           => p_application_id
61996          , p_ae_header_id             => l_ae_header_id 
61997 , p_source_3 => p_source_3
61998 , p_source_11 => p_source_11
61999          , x_transaction_coa_id       => l_adr_transaction_coa_id
62000          , x_accounting_coa_id        => l_adr_accounting_coa_id
62001          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
62002          , x_flex_value_set_id        => l_adr_flex_value_set_id
62003          , x_value_type_code          => l_adr_value_type_code
62004          , x_value_combination_id     => l_adr_value_combination_id
62005          , x_value_segment_code       => l_adr_value_segment_code
62006          , p_side                     => 'NA'
62007          , p_override_seg_flag        => 'Y'
62008    );
62009 
62010    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
62011 
62012       xla_ae_lines_pkg.set_segment(
62013           p_to_segment_code         => 'GL_ACCOUNT'
62014         , p_segment_value           => l_segment
62015         , p_from_segment_code       => l_adr_value_segment_code
62016         , p_from_combination_id     => l_adr_value_combination_id
62017         , p_value_type_code         => l_adr_value_type_code
62018         , p_transaction_coa_id      => l_adr_transaction_coa_id
62019         , p_accounting_coa_id       => l_adr_accounting_coa_id
62020         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
62021         , p_flex_value_set_id       => l_adr_flex_value_set_id
62022         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
62023         , p_adr_type_code           => 'S'
62024         , p_component_type          => l_component_type
62025         , p_component_code          => l_component_code
62026         , p_component_type_code     => l_component_type_code
62027         , p_component_appl_id       => l_component_appl_id
62028         , p_amb_context_code        => l_amb_context_code
62029         , p_entity_code             => 'TRANSACTIONS'
62030         , p_event_class_code        => 'CIP_REVALUATION'
62031         , p_side                    => 'NA'
62032         );
62033 
62034   END IF;
62035 
62036    l_segment := AcctDerRule_168(
62037            p_application_id           => p_application_id
62038          , p_ae_header_id             => l_ae_header_id 
62039 , p_source_3 => p_source_3
62040 , p_source_29 => p_source_29
62041          , x_transaction_coa_id       => l_adr_transaction_coa_id
62042          , x_accounting_coa_id        => l_adr_accounting_coa_id
62043          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
62044          , x_flex_value_set_id        => l_adr_flex_value_set_id
62045          , x_value_type_code          => l_adr_value_type_code
62046          , x_value_combination_id     => l_adr_value_combination_id
62047          , x_value_segment_code       => l_adr_value_segment_code
62048          , p_side                     => 'NA'
62049          , p_override_seg_flag        => 'Y'
62050    );
62051 
62052    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
62053 
62054       xla_ae_lines_pkg.set_segment(
62055           p_to_segment_code         => 'GL_BALANCING'
62056         , p_segment_value           => l_segment
62057         , p_from_segment_code       => l_adr_value_segment_code
62058         , p_from_combination_id     => l_adr_value_combination_id
62059         , p_value_type_code         => l_adr_value_type_code
62060         , p_transaction_coa_id      => l_adr_transaction_coa_id
62061         , p_accounting_coa_id       => l_adr_accounting_coa_id
62062         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
62063         , p_flex_value_set_id       => l_adr_flex_value_set_id
62064         , p_adr_code                => 'FA_EXPENSE_ACCT'
62065         , p_adr_type_code           => 'S'
62066         , p_component_type          => l_component_type
62067         , p_component_code          => l_component_code
62068         , p_component_type_code     => l_component_type_code
62069         , p_component_appl_id       => l_component_appl_id
62070         , p_amb_context_code        => l_amb_context_code
62071         , p_entity_code             => 'TRANSACTIONS'
62072         , p_event_class_code        => 'CIP_REVALUATION'
62073         , p_side                    => 'NA'
62074         );
62075 
62076   END IF;
62077 
62078    --
62079    --
62080    END IF;
62081 
62082        --
62083        -- Update the line information that should be overwritten
62084        --
62085        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
62086                                          p_header_num   => 1);
62087        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
62088 
62089        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
62090 
62091        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
62092           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
62093        END IF;
62094 
62095       --
62096       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
62097       --
62101           ---------------------------------------------------------------------------------------------------
62098       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
62099           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
62100       ELSE
62102           -- 4262811a Switch Sign
62103           ---------------------------------------------------------------------------------------------------
62104           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
62105           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
62106                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62107           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
62108                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62109           -- 5132302
62110           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
62111                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62112 
62113       END IF;
62114 
62115       -- 4955764
62116       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
62117       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
62118 
62119 
62120       XLA_AE_LINES_PKG.ValidateCurrentLine;
62121       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
62122 
62123       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
62124                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
62125                ,p_balance_type_code => l_balance_type_code);
62126 
62127    END IF;
62128 
62129    -----------------------------------------------------------------------------------------
62130    -- 4262811 Multiperiod Accounting
62131    -----------------------------------------------------------------------------------------
62132      -- No MPA option is assigned.
62133 
62134 
62135 END IF;
62136 END IF;
62137 --
62138 
62139 --
62140 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62141    trace
62142       (p_msg      => 'END of AcctLineType_240'
62143       ,p_level    => C_LEVEL_PROCEDURE
62144       ,p_module   => l_log_module);
62145 END IF;
62146 --
62147 EXCEPTION
62148   WHEN xla_exceptions_pkg.application_exception THEN
62149       RAISE;
62150   WHEN OTHERS THEN
62151        xla_exceptions_pkg.raise_message
62152            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_240');
62153 END AcctLineType_240;
62154 --
62155 
62156 ---------------------------------------
62157 --
62158 -- PRIVATE FUNCTION
62159 --         AcctLineType_241
62160 --
62161 ---------------------------------------
62162 PROCEDURE AcctLineType_241 (
62163   p_application_id        IN NUMBER
62164  ,p_event_id              IN NUMBER
62165  ,p_calculate_acctd_flag  IN VARCHAR2
62166  ,p_calculate_g_l_flag    IN VARCHAR2
62167  ,p_actual_flag           IN OUT VARCHAR2
62168  ,p_balance_type_code     OUT VARCHAR2
62169  ,p_gain_or_loss_ref      OUT VARCHAR2
62170  
62171 --Period Close Date
62172  , p_source_1            IN DATE
62173 --Generated Code Combination Identifier
62174  , p_source_3            IN NUMBER
62175 --CIP Cost Account
62176  , p_source_7            IN VARCHAR2
62177 --Expense Account Code Combination Identifier
62178  , p_source_29            IN NUMBER
62179 --Default Code Combination Identifier
62180  , p_source_30            IN NUMBER
62181 --Adjustment Type
62182  , p_source_35            IN VARCHAR2
62183 --Transaction Header Identifier
62184  , p_source_36            IN NUMBER
62185 --Adjustment Line Identifier
62186  , p_source_37            IN NUMBER
62187 --Distribution Type Code
62188  , p_source_38            IN VARCHAR2
62189 --Entered Amount
62190  , p_source_39            IN NUMBER
62191 --Currency Code
62192  , p_source_40            IN VARCHAR2
62193 --Source Destination Code
62194  , p_source_42            IN VARCHAR2
62195 )
62196 IS
62197 
62198 l_component_type              VARCHAR2(80);
62199 l_component_code              VARCHAR2(30);
62200 l_component_type_code         VARCHAR2(1);
62201 l_component_appl_id           INTEGER;
62202 l_amb_context_code            VARCHAR2(30);
62203 l_entity_code                 VARCHAR2(30);
62204 l_event_class_code            VARCHAR2(30);
62205 l_ae_header_id                NUMBER;
62206 l_event_type_code             VARCHAR2(30);
62207 l_line_definition_code        VARCHAR2(30);
62208 l_line_definition_owner_code  VARCHAR2(1);
62209 --
62210 -- adr variables
62211 l_segment                     VARCHAR2(30);
62212 l_ccid                        NUMBER;
62213 l_adr_transaction_coa_id      NUMBER;
62214 l_adr_accounting_coa_id       NUMBER;
62215 l_adr_flexfield_segment_code  VARCHAR2(30);
62216 l_adr_flex_value_set_id       NUMBER;
62217 l_adr_value_type_code         VARCHAR2(30);
62218 l_adr_value_combination_id    NUMBER;
62219 l_adr_value_segment_code      VARCHAR2(30);
62220 
62221 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
62222 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
62223 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
62224 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
62225 
62226 -- 4262811 Variables ------------------------------------------------------------------------------------------
62227 l_entered_amt_idx             NUMBER;
62228 l_accted_amt_idx              NUMBER;
62229 l_acc_rev_flag                VARCHAR2(1);
62230 l_accrual_line_num            NUMBER;
62234 l_num_entries                 NUMBER;
62231 l_tmp_amt                     NUMBER;
62232 l_acc_rev_natural_side_code   VARCHAR2(1);
62233 
62235 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
62236 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
62237 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
62238 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
62239 l_recog_line_1                NUMBER;
62240 l_recog_line_2                NUMBER;
62241 
62242 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
62243 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
62244 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
62245 
62246 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
62247 
62248 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
62249 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
62250 
62251 ---------------------------------------------------------------------------------------------------------------
62252 
62253 
62254 --
62255 -- bulk performance
62256 --
62257 l_balance_type_code           VARCHAR2(1);
62258 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
62259 l_log_module                  VARCHAR2(240);
62260 
62261 --
62262 -- Upgrade strategy
62263 --
62264 l_actual_upg_option           VARCHAR2(1);
62265 l_enc_upg_option           VARCHAR2(1);
62266 
62267 --
62268 BEGIN
62269 --
62270 IF g_log_enabled THEN
62271       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_241';
62272 END IF;
62273 --
62274 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62275 
62276       trace
62277          (p_msg      => 'BEGIN of AcctLineType_241'
62278          ,p_level    => C_LEVEL_PROCEDURE
62279          ,p_module   => l_log_module);
62280 
62281 END IF;
62282 --
62283 l_component_type             := 'AMB_JLT';
62284 l_component_code             := 'FA_CIP_TRANSFER_DEST_COST';
62285 l_component_type_code        := 'S';
62286 l_component_appl_id          :=  140;
62287 l_amb_context_code           := 'DEFAULT';
62288 l_entity_code                := 'TRANSACTIONS';
62289 l_event_class_code           := 'CIP_TRANSFERS';
62290 l_event_type_code            := 'CIP_TRANSFERS_ALL';
62291 l_line_definition_owner_code := 'S';
62292 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_T12';
62293 --
62294 l_balance_type_code          := 'A';
62295 l_segment                     := NULL;
62296 l_ccid                        := NULL;
62297 l_adr_transaction_coa_id      := NULL;
62298 l_adr_accounting_coa_id       := NULL;
62299 l_adr_flexfield_segment_code  := NULL;
62300 l_adr_flex_value_set_id       := NULL;
62301 l_adr_value_type_code         := NULL;
62302 l_adr_value_combination_id    := NULL;
62303 l_adr_value_segment_code      := NULL;
62304 
62305 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
62306 l_bflow_class_code           := '';    -- 4219869 Business Flow
62307 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
62308 l_budgetary_control_flag     := 'N';
62309 
62310 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
62311 l_bflow_applied_to_amt       := NULL; -- 5132302
62312 l_entered_amt_idx            := NULL;          -- 4262811
62313 l_accted_amt_idx             := NULL;          -- 4262811
62314 l_acc_rev_flag               := NULL;          -- 4262811
62315 l_accrual_line_num           := NULL;          -- 4262811
62316 l_tmp_amt                    := NULL;          -- 4262811
62317 --
62318  
62319 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
62320     l_balance_type_code <> 'B' THEN
62321 IF NVL(p_source_35,'
62322 ') =  'CIP COST' AND 
62323 NVL(p_source_42,'
62324 ') =  'DEST'
62325  THEN 
62326 
62327    --
62328    XLA_AE_LINES_PKG.SetNewLine;
62329 
62330    p_balance_type_code          := l_balance_type_code;
62331    -- set the flag so later we will know whether the gain loss line needs to be created
62332    
62333    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
62334      p_actual_flag :='A';
62335    END IF;
62336 
62337    --
62338    -- bulk performance
62339    --
62340    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
62341                                       p_header_num   => 0); -- 4262811
62342    --
62343    -- set accounting line options
62344    --
62345    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
62346            p_natural_side_code          => 'D'
62347          , p_gain_or_loss_flag          => 'N'
62348          , p_gl_transfer_mode_code      => 'S'
62349          , p_acct_entry_type_code       => 'A'
62350          , p_switch_side_flag           => 'Y'
62351          , p_merge_duplicate_code       => 'N'
62352          );
62353    --
62354    l_acc_rev_natural_side_code := 'C';  -- 4262811
62355    -- 
62356    --
62357    -- set accounting line type info
62358    --
62359    xla_ae_lines_pkg.SetAcctLineType
62360       (p_component_type             => l_component_type
62361       ,p_event_type_code            => l_event_type_code
62362       ,p_line_definition_owner_code => l_line_definition_owner_code
62363       ,p_line_definition_code       => l_line_definition_code
62364       ,p_accounting_line_code       => l_component_code
62365       ,p_accounting_line_type_code  => l_component_type_code
62366       ,p_accounting_line_appl_id    => l_component_appl_id
62367       ,p_amb_context_code           => l_amb_context_code
62368       ,p_entity_code                => l_entity_code
62369       ,p_event_class_code           => l_event_class_code);
62370    --
62374            p_accounting_class_code  => 'ASSET'
62371    -- set accounting class
62372    --
62373    xla_ae_lines_pkg.SetAcctClass(
62375          , p_ae_header_id           => l_ae_header_id
62376          );
62377 
62378    --
62379    -- set rounding class
62380    --
62381    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
62382                       'ASSET';
62383 
62384    --
62385    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
62386    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
62387    --
62388    -- bulk performance
62389    --
62390    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
62391 
62392    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
62393       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
62394 
62395    -- 4955764
62396    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
62397       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
62398 
62399    -- 4458381 Public Sector Enh
62400    
62401    --
62402    -- set accounting attributes for the line type
62403    --
62404    l_entered_amt_idx := 4;
62405    l_accted_amt_idx  := 6;
62406    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
62407    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
62408    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
62409    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
62410    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
62411    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
62412    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
62413    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
62414    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
62415    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
62416    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
62417    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
62418    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
62419 
62420    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
62421    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
62422 
62423    ---------------------------------------------------------------------------------------------------------------
62424    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
62425    ---------------------------------------------------------------------------------------------------------------
62426    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
62427 
62428    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
62429    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
62430 
62431    IF xla_accounting_cache_pkg.GetValueChar
62432          (p_source_code         => 'LEDGER_CATEGORY_CODE'
62433          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
62434    AND l_bflow_method_code = 'PRIOR_ENTRY'
62435 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
62436    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
62437          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
62438        )
62439    THEN
62440          xla_ae_lines_pkg.BflowUpgEntry
62441            (p_business_method_code    => l_bflow_method_code
62442            ,p_business_class_code     => l_bflow_class_code
62443            ,p_balance_type            => l_balance_type_code);
62444    ELSE
62445       NULL;
62446 -- No business flow processing for business flow method of NONE.
62447    END IF;
62448 
62449    --
62450    -- call analytical criteria
62451    --
62452    
62453    --
62454    -- call description
62455    --
62456    
62457 xla_ae_lines_pkg.SetLineDescription(
62458    p_ae_header_id => l_ae_header_id
62459   ,p_description  => Description_45 (
62460      p_application_id         => p_application_id
62461    , p_ae_header_id           => l_ae_header_id 
62462 , p_source_1 => p_source_1
62463    )
62464 );
62465 
62466 
62467    --
62468    -- call ADRs
62469    -- Bug 4922099
62470    --
62471    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
62472         (NVL(l_actual_upg_option, 'N') = 'O') OR
62473         (NVL(l_enc_upg_option, 'N') = 'O')
62474       )
62475    THEN
62476    NULL;
62477    --
62478    --
62479    
62480   l_ccid := AcctDerRule_173(
62481            p_application_id           => p_application_id
62482          , p_ae_header_id             => l_ae_header_id 
62483 , p_source_3 => p_source_3
62484 , p_source_30 => p_source_30
62485          , x_transaction_coa_id       => l_adr_transaction_coa_id
62486          , x_accounting_coa_id        => l_adr_accounting_coa_id
62487          , x_value_type_code          => l_adr_value_type_code
62488          , p_side                     => 'NA'
62489    );
62490 
62491    xla_ae_lines_pkg.set_ccid(
62492     p_code_combination_id          => l_ccid
62493   , p_value_type_code              => l_adr_value_type_code
62494   , p_transaction_coa_id           => l_adr_transaction_coa_id
62495   , p_accounting_coa_id            => l_adr_accounting_coa_id
62496   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
62497   , p_adr_type_code                => 'S'
62498   , p_component_type               => l_component_type
62499   , p_component_code               => l_component_code
62503   , p_side                         => 'NA'
62500   , p_component_type_code          => l_component_type_code
62501   , p_component_appl_id            => l_component_appl_id
62502   , p_amb_context_code             => l_amb_context_code
62504   );
62505 
62506 
62507    l_segment := AcctDerRule_146(
62508            p_application_id           => p_application_id
62509          , p_ae_header_id             => l_ae_header_id 
62510 , p_source_3 => p_source_3
62511 , p_source_7 => p_source_7
62512          , x_transaction_coa_id       => l_adr_transaction_coa_id
62513          , x_accounting_coa_id        => l_adr_accounting_coa_id
62514          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
62515          , x_flex_value_set_id        => l_adr_flex_value_set_id
62516          , x_value_type_code          => l_adr_value_type_code
62517          , x_value_combination_id     => l_adr_value_combination_id
62518          , x_value_segment_code       => l_adr_value_segment_code
62519          , p_side                     => 'NA'
62520          , p_override_seg_flag        => 'Y'
62521    );
62522 
62523    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
62524 
62525       xla_ae_lines_pkg.set_segment(
62526           p_to_segment_code         => 'GL_ACCOUNT'
62527         , p_segment_value           => l_segment
62528         , p_from_segment_code       => l_adr_value_segment_code
62529         , p_from_combination_id     => l_adr_value_combination_id
62530         , p_value_type_code         => l_adr_value_type_code
62531         , p_transaction_coa_id      => l_adr_transaction_coa_id
62532         , p_accounting_coa_id       => l_adr_accounting_coa_id
62533         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
62534         , p_flex_value_set_id       => l_adr_flex_value_set_id
62535         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
62536         , p_adr_type_code           => 'S'
62537         , p_component_type          => l_component_type
62538         , p_component_code          => l_component_code
62539         , p_component_type_code     => l_component_type_code
62540         , p_component_appl_id       => l_component_appl_id
62541         , p_amb_context_code        => l_amb_context_code
62542         , p_entity_code             => 'TRANSACTIONS'
62543         , p_event_class_code        => 'CIP_TRANSFERS'
62544         , p_side                    => 'NA'
62545         );
62546 
62547   END IF;
62548 
62549    l_segment := AcctDerRule_168(
62550            p_application_id           => p_application_id
62551          , p_ae_header_id             => l_ae_header_id 
62552 , p_source_3 => p_source_3
62553 , p_source_29 => p_source_29
62554          , x_transaction_coa_id       => l_adr_transaction_coa_id
62555          , x_accounting_coa_id        => l_adr_accounting_coa_id
62556          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
62557          , x_flex_value_set_id        => l_adr_flex_value_set_id
62558          , x_value_type_code          => l_adr_value_type_code
62559          , x_value_combination_id     => l_adr_value_combination_id
62560          , x_value_segment_code       => l_adr_value_segment_code
62561          , p_side                     => 'NA'
62562          , p_override_seg_flag        => 'Y'
62563    );
62564 
62565    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
62566 
62567       xla_ae_lines_pkg.set_segment(
62568           p_to_segment_code         => 'GL_BALANCING'
62569         , p_segment_value           => l_segment
62570         , p_from_segment_code       => l_adr_value_segment_code
62571         , p_from_combination_id     => l_adr_value_combination_id
62572         , p_value_type_code         => l_adr_value_type_code
62573         , p_transaction_coa_id      => l_adr_transaction_coa_id
62574         , p_accounting_coa_id       => l_adr_accounting_coa_id
62575         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
62576         , p_flex_value_set_id       => l_adr_flex_value_set_id
62577         , p_adr_code                => 'FA_EXPENSE_ACCT'
62578         , p_adr_type_code           => 'S'
62579         , p_component_type          => l_component_type
62580         , p_component_code          => l_component_code
62581         , p_component_type_code     => l_component_type_code
62582         , p_component_appl_id       => l_component_appl_id
62583         , p_amb_context_code        => l_amb_context_code
62584         , p_entity_code             => 'TRANSACTIONS'
62585         , p_event_class_code        => 'CIP_TRANSFERS'
62586         , p_side                    => 'NA'
62587         );
62588 
62589   END IF;
62590 
62591    --
62592    --
62593    END IF;
62594    --
62595    -- Bug 4922099
62596    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
62597           (NVL(l_enc_upg_option, 'N') = 'O')
62598         ) AND
62599         (l_bflow_method_code = 'PRIOR_ENTRY')
62600       )
62601    THEN
62602       IF
62603       --
62604       1 = 2
62605       --
62606       THEN
62607       xla_accounting_err_pkg.build_message
62608                                     (p_appli_s_name            => 'XLA'
62609                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
62610                                     ,p_token_1                 => 'LINE_NUMBER'
62611                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
62612                                     ,p_token_2                 => 'LINE_TYPE_NAME'
62613                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
62614                                                                              l_component_type
62615                                                                             ,l_component_code
62616                                                                             ,l_component_type_code
62620                                                                             ,l_event_class_code
62617                                                                             ,l_component_appl_id
62618                                                                             ,l_amb_context_code
62619                                                                             ,l_entity_code
62621                                                                            )
62622                                     ,p_token_3                 => 'OWNER'
62623                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
62624                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
62625                                                                           ,p_lookup_code    => l_component_type_code
62626                                                                          )
62627                                     ,p_token_4                 => 'PRODUCT_NAME'
62628                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
62629                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
62630                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
62631                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
62632                                     ,p_ae_header_id            =>  NULL
62633                                        );
62634 
62635         IF (C_LEVEL_ERROR>= g_log_level) THEN
62636                  trace
62637                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
62638                       ,p_level    => C_LEVEL_ERROR
62639                       ,p_module   => l_log_module);
62640         END IF;
62641       END IF;
62642    END IF;
62643    --
62644    --
62645    ------------------------------------------------------------------------------------------------
62646    -- 4219869 Business Flow
62647    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
62648    -- Prior Entry.  Currently, the following code is always generated.
62649    ------------------------------------------------------------------------------------------------
62650    XLA_AE_LINES_PKG.ValidateCurrentLine;
62651 
62652    ------------------------------------------------------------------------------------
62653    -- 4219869 Business Flow
62654    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
62655    ------------------------------------------------------------------------------------
62656    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
62657 
62658    ----------------------------------------------------------------------------------
62659    -- 4219869 Business Flow
62660    -- Update journal entry status -- Need to generate this within IF <condition>
62661    ----------------------------------------------------------------------------------
62662    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
62663          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
62664          ,p_balance_type_code => l_balance_type_code
62665          );
62666 
62667    -------------------------------------------------------------------------------------------
62668    -- 4262811 - Generate the Accrual Reversal lines
62669    -------------------------------------------------------------------------------------------
62670    BEGIN
62671       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
62672                               (g_array_event(p_event_id).array_value_num('header_index'));
62673       IF l_acc_rev_flag IS NULL THEN
62674          l_acc_rev_flag := 'N';
62675       END IF;
62676    EXCEPTION
62677       WHEN OTHERS THEN
62678          l_acc_rev_flag := 'N';
62679    END;
62680    --
62681    IF (l_acc_rev_flag = 'Y') THEN
62682 
62683        -- 4645092  ------------------------------------------------------------------------------
62684        -- To allow MPA report to determine if it should generate report process
62685        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
62686        ------------------------------------------------------------------------------------------
62687 
62688        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
62689        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
62690    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
62691    -- call ADRs
62692    -- Bug 4922099
62693    --
62694    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
62695         (NVL(l_actual_upg_option, 'N') = 'O') OR
62696         (NVL(l_enc_upg_option, 'N') = 'O')
62697       )
62698    THEN
62699    NULL;
62700    --
62701    --
62702    
62703   l_ccid := AcctDerRule_173(
62704            p_application_id           => p_application_id
62705          , p_ae_header_id             => l_ae_header_id 
62706 , p_source_3 => p_source_3
62707 , p_source_30 => p_source_30
62708          , x_transaction_coa_id       => l_adr_transaction_coa_id
62709          , x_accounting_coa_id        => l_adr_accounting_coa_id
62710          , x_value_type_code          => l_adr_value_type_code
62711          , p_side                     => 'NA'
62712    );
62713 
62714    xla_ae_lines_pkg.set_ccid(
62715     p_code_combination_id          => l_ccid
62716   , p_value_type_code              => l_adr_value_type_code
62717   , p_transaction_coa_id           => l_adr_transaction_coa_id
62718   , p_accounting_coa_id            => l_adr_accounting_coa_id
62719   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
62720   , p_adr_type_code                => 'S'
62721   , p_component_type               => l_component_type
62722   , p_component_code               => l_component_code
62723   , p_component_type_code          => l_component_type_code
62727   );
62724   , p_component_appl_id            => l_component_appl_id
62725   , p_amb_context_code             => l_amb_context_code
62726   , p_side                         => 'NA'
62728 
62729 
62730    l_segment := AcctDerRule_146(
62731            p_application_id           => p_application_id
62732          , p_ae_header_id             => l_ae_header_id 
62733 , p_source_3 => p_source_3
62734 , p_source_7 => p_source_7
62735          , x_transaction_coa_id       => l_adr_transaction_coa_id
62736          , x_accounting_coa_id        => l_adr_accounting_coa_id
62737          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
62738          , x_flex_value_set_id        => l_adr_flex_value_set_id
62739          , x_value_type_code          => l_adr_value_type_code
62740          , x_value_combination_id     => l_adr_value_combination_id
62741          , x_value_segment_code       => l_adr_value_segment_code
62742          , p_side                     => 'NA'
62743          , p_override_seg_flag        => 'Y'
62744    );
62745 
62746    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
62747 
62748       xla_ae_lines_pkg.set_segment(
62749           p_to_segment_code         => 'GL_ACCOUNT'
62750         , p_segment_value           => l_segment
62751         , p_from_segment_code       => l_adr_value_segment_code
62752         , p_from_combination_id     => l_adr_value_combination_id
62753         , p_value_type_code         => l_adr_value_type_code
62754         , p_transaction_coa_id      => l_adr_transaction_coa_id
62755         , p_accounting_coa_id       => l_adr_accounting_coa_id
62756         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
62757         , p_flex_value_set_id       => l_adr_flex_value_set_id
62758         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
62759         , p_adr_type_code           => 'S'
62760         , p_component_type          => l_component_type
62761         , p_component_code          => l_component_code
62762         , p_component_type_code     => l_component_type_code
62763         , p_component_appl_id       => l_component_appl_id
62764         , p_amb_context_code        => l_amb_context_code
62765         , p_entity_code             => 'TRANSACTIONS'
62766         , p_event_class_code        => 'CIP_TRANSFERS'
62767         , p_side                    => 'NA'
62768         );
62769 
62770   END IF;
62771 
62772    l_segment := AcctDerRule_168(
62773            p_application_id           => p_application_id
62774          , p_ae_header_id             => l_ae_header_id 
62775 , p_source_3 => p_source_3
62776 , p_source_29 => p_source_29
62777          , x_transaction_coa_id       => l_adr_transaction_coa_id
62778          , x_accounting_coa_id        => l_adr_accounting_coa_id
62779          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
62780          , x_flex_value_set_id        => l_adr_flex_value_set_id
62781          , x_value_type_code          => l_adr_value_type_code
62782          , x_value_combination_id     => l_adr_value_combination_id
62783          , x_value_segment_code       => l_adr_value_segment_code
62784          , p_side                     => 'NA'
62785          , p_override_seg_flag        => 'Y'
62786    );
62787 
62788    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
62789 
62790       xla_ae_lines_pkg.set_segment(
62791           p_to_segment_code         => 'GL_BALANCING'
62792         , p_segment_value           => l_segment
62793         , p_from_segment_code       => l_adr_value_segment_code
62794         , p_from_combination_id     => l_adr_value_combination_id
62795         , p_value_type_code         => l_adr_value_type_code
62796         , p_transaction_coa_id      => l_adr_transaction_coa_id
62797         , p_accounting_coa_id       => l_adr_accounting_coa_id
62798         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
62799         , p_flex_value_set_id       => l_adr_flex_value_set_id
62800         , p_adr_code                => 'FA_EXPENSE_ACCT'
62801         , p_adr_type_code           => 'S'
62802         , p_component_type          => l_component_type
62803         , p_component_code          => l_component_code
62804         , p_component_type_code     => l_component_type_code
62805         , p_component_appl_id       => l_component_appl_id
62806         , p_amb_context_code        => l_amb_context_code
62807         , p_entity_code             => 'TRANSACTIONS'
62808         , p_event_class_code        => 'CIP_TRANSFERS'
62809         , p_side                    => 'NA'
62810         );
62811 
62812   END IF;
62813 
62814    --
62815    --
62816    END IF;
62817 
62818        --
62819        -- Update the line information that should be overwritten
62820        --
62821        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
62822                                          p_header_num   => 1);
62823        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
62824 
62825        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
62826 
62827        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
62828           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
62829        END IF;
62830 
62831       --
62832       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
62833       --
62834       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
62835           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
62836       ELSE
62837           ---------------------------------------------------------------------------------------------------
62838           -- 4262811a Switch Sign
62839           ---------------------------------------------------------------------------------------------------
62843           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
62840           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
62841           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
62842                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62844                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62845           -- 5132302
62846           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
62847                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62848 
62849       END IF;
62850 
62851       -- 4955764
62852       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
62853       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
62854 
62855 
62856       XLA_AE_LINES_PKG.ValidateCurrentLine;
62857       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
62858 
62859       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
62860                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
62861                ,p_balance_type_code => l_balance_type_code);
62862 
62863    END IF;
62864 
62865    -----------------------------------------------------------------------------------------
62866    -- 4262811 Multiperiod Accounting
62867    -----------------------------------------------------------------------------------------
62868      -- No MPA option is assigned.
62869 
62870 
62871 END IF;
62872 END IF;
62873 --
62874 
62875 --
62876 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62877    trace
62878       (p_msg      => 'END of AcctLineType_241'
62879       ,p_level    => C_LEVEL_PROCEDURE
62880       ,p_module   => l_log_module);
62881 END IF;
62882 --
62883 EXCEPTION
62884   WHEN xla_exceptions_pkg.application_exception THEN
62885       RAISE;
62886   WHEN OTHERS THEN
62887        xla_exceptions_pkg.raise_message
62888            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_241');
62889 END AcctLineType_241;
62890 --
62891 
62892 ---------------------------------------
62893 --
62894 -- PRIVATE FUNCTION
62895 --         AcctLineType_242
62896 --
62897 ---------------------------------------
62898 PROCEDURE AcctLineType_242 (
62899   p_application_id        IN NUMBER
62900  ,p_event_id              IN NUMBER
62901  ,p_calculate_acctd_flag  IN VARCHAR2
62902  ,p_calculate_g_l_flag    IN VARCHAR2
62903  ,p_actual_flag           IN OUT VARCHAR2
62904  ,p_balance_type_code     OUT VARCHAR2
62905  ,p_gain_or_loss_ref      OUT VARCHAR2
62906  
62907 --Period Close Date
62908  , p_source_1            IN DATE
62909 --Generated Code Combination Identifier
62910  , p_source_3            IN NUMBER
62911 --Revaluation Reserve Account
62912  , p_source_11            IN VARCHAR2
62913 --Generated Offset Code Combination Identifier
62914  , p_source_17            IN NUMBER
62915 --Expense Account Code Combination Identifier
62916  , p_source_29            IN NUMBER
62917 --Default Code Combination Identifier
62918  , p_source_30            IN NUMBER
62919 --Adjustment Type
62920  , p_source_35            IN VARCHAR2
62921 --Transaction Header Identifier
62922  , p_source_36            IN NUMBER
62923 --Adjustment Line Identifier
62924  , p_source_37            IN NUMBER
62925 --Distribution Type Code
62926  , p_source_38            IN VARCHAR2
62927 --Entered Amount
62928  , p_source_39            IN NUMBER
62929 --Currency Code
62930  , p_source_40            IN VARCHAR2
62931 --Source Destination Code
62932  , p_source_42            IN VARCHAR2
62933 )
62934 IS
62935 
62936 l_component_type              VARCHAR2(80);
62937 l_component_code              VARCHAR2(30);
62938 l_component_type_code         VARCHAR2(1);
62939 l_component_appl_id           INTEGER;
62940 l_amb_context_code            VARCHAR2(30);
62941 l_entity_code                 VARCHAR2(30);
62942 l_event_class_code            VARCHAR2(30);
62943 l_ae_header_id                NUMBER;
62944 l_event_type_code             VARCHAR2(30);
62945 l_line_definition_code        VARCHAR2(30);
62946 l_line_definition_owner_code  VARCHAR2(1);
62947 --
62948 -- adr variables
62949 l_segment                     VARCHAR2(30);
62950 l_ccid                        NUMBER;
62951 l_adr_transaction_coa_id      NUMBER;
62952 l_adr_accounting_coa_id       NUMBER;
62953 l_adr_flexfield_segment_code  VARCHAR2(30);
62954 l_adr_flex_value_set_id       NUMBER;
62955 l_adr_value_type_code         VARCHAR2(30);
62956 l_adr_value_combination_id    NUMBER;
62957 l_adr_value_segment_code      VARCHAR2(30);
62958 
62959 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
62960 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
62961 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
62962 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
62963 
62964 -- 4262811 Variables ------------------------------------------------------------------------------------------
62965 l_entered_amt_idx             NUMBER;
62966 l_accted_amt_idx              NUMBER;
62967 l_acc_rev_flag                VARCHAR2(1);
62968 l_accrual_line_num            NUMBER;
62969 l_tmp_amt                     NUMBER;
62970 l_acc_rev_natural_side_code   VARCHAR2(1);
62971 
62972 l_num_entries                 NUMBER;
62973 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
62974 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
62975 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
62979 
62976 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
62977 l_recog_line_1                NUMBER;
62978 l_recog_line_2                NUMBER;
62980 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
62981 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
62982 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
62983 
62984 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
62985 
62986 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
62987 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
62988 
62989 ---------------------------------------------------------------------------------------------------------------
62990 
62991 
62992 --
62993 -- bulk performance
62994 --
62995 l_balance_type_code           VARCHAR2(1);
62996 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
62997 l_log_module                  VARCHAR2(240);
62998 
62999 --
63000 -- Upgrade strategy
63001 --
63002 l_actual_upg_option           VARCHAR2(1);
63003 l_enc_upg_option           VARCHAR2(1);
63004 
63005 --
63006 BEGIN
63007 --
63008 IF g_log_enabled THEN
63009       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_242';
63010 END IF;
63011 --
63012 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63013 
63014       trace
63015          (p_msg      => 'BEGIN of AcctLineType_242'
63016          ,p_level    => C_LEVEL_PROCEDURE
63017          ,p_module   => l_log_module);
63018 
63019 END IF;
63020 --
63021 l_component_type             := 'AMB_JLT';
63022 l_component_code             := 'FA_CIP_TRANSFER_DEST_REVAL_RES';
63023 l_component_type_code        := 'S';
63024 l_component_appl_id          :=  140;
63025 l_amb_context_code           := 'DEFAULT';
63026 l_entity_code                := 'TRANSACTIONS';
63027 l_event_class_code           := 'CIP_TRANSFERS';
63028 l_event_type_code            := 'CIP_TRANSFERS_ALL';
63029 l_line_definition_owner_code := 'S';
63030 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_T12';
63031 --
63032 l_balance_type_code          := 'A';
63033 l_segment                     := NULL;
63034 l_ccid                        := NULL;
63035 l_adr_transaction_coa_id      := NULL;
63036 l_adr_accounting_coa_id       := NULL;
63037 l_adr_flexfield_segment_code  := NULL;
63038 l_adr_flex_value_set_id       := NULL;
63039 l_adr_value_type_code         := NULL;
63040 l_adr_value_combination_id    := NULL;
63041 l_adr_value_segment_code      := NULL;
63042 
63043 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
63044 l_bflow_class_code           := '';    -- 4219869 Business Flow
63045 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
63046 l_budgetary_control_flag     := 'N';
63047 
63048 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
63049 l_bflow_applied_to_amt       := NULL; -- 5132302
63050 l_entered_amt_idx            := NULL;          -- 4262811
63051 l_accted_amt_idx             := NULL;          -- 4262811
63052 l_acc_rev_flag               := NULL;          -- 4262811
63053 l_accrual_line_num           := NULL;          -- 4262811
63054 l_tmp_amt                    := NULL;          -- 4262811
63055 --
63056  
63057 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
63058     l_balance_type_code <> 'B' THEN
63059 IF NVL(p_source_35,'
63060 ') =  'REVAL RESERVE' AND 
63061 NVL(p_source_42,'
63062 ') =  'DEST'
63063  THEN 
63064 
63065    --
63066    XLA_AE_LINES_PKG.SetNewLine;
63067 
63068    p_balance_type_code          := l_balance_type_code;
63069    -- set the flag so later we will know whether the gain loss line needs to be created
63070    
63071    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
63072      p_actual_flag :='A';
63073    END IF;
63074 
63075    --
63076    -- bulk performance
63077    --
63078    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
63079                                       p_header_num   => 0); -- 4262811
63080    --
63081    -- set accounting line options
63082    --
63083    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
63084            p_natural_side_code          => 'C'
63085          , p_gain_or_loss_flag          => 'N'
63086          , p_gl_transfer_mode_code      => 'S'
63087          , p_acct_entry_type_code       => 'A'
63088          , p_switch_side_flag           => 'Y'
63089          , p_merge_duplicate_code       => 'N'
63090          );
63091    --
63092    l_acc_rev_natural_side_code := 'D';  -- 4262811
63093    -- 
63094    --
63095    -- set accounting line type info
63096    --
63097    xla_ae_lines_pkg.SetAcctLineType
63098       (p_component_type             => l_component_type
63099       ,p_event_type_code            => l_event_type_code
63100       ,p_line_definition_owner_code => l_line_definition_owner_code
63101       ,p_line_definition_code       => l_line_definition_code
63102       ,p_accounting_line_code       => l_component_code
63103       ,p_accounting_line_type_code  => l_component_type_code
63104       ,p_accounting_line_appl_id    => l_component_appl_id
63105       ,p_amb_context_code           => l_amb_context_code
63106       ,p_entity_code                => l_entity_code
63107       ,p_event_class_code           => l_event_class_code);
63108    --
63109    -- set accounting class
63110    --
63111    xla_ae_lines_pkg.SetAcctClass(
63112            p_accounting_class_code  => 'ASSET'
63113          , p_ae_header_id           => l_ae_header_id
63114          );
63115 
63116    --
63117    -- set rounding class
63118    --
63122    --
63119    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
63120                       'ASSET';
63121 
63123    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
63124    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
63125    --
63126    -- bulk performance
63127    --
63128    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
63129 
63130    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
63131       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
63132 
63133    -- 4955764
63134    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
63135       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
63136 
63137    -- 4458381 Public Sector Enh
63138    
63139    --
63140    -- set accounting attributes for the line type
63141    --
63142    l_entered_amt_idx := 4;
63143    l_accted_amt_idx  := 6;
63144    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
63145    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
63146    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
63147    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
63148    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
63149    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
63150    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
63151    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
63152    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
63153    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
63154    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
63155    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
63156    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
63157 
63158    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
63159    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
63160 
63161    ---------------------------------------------------------------------------------------------------------------
63162    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
63163    ---------------------------------------------------------------------------------------------------------------
63164    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
63165 
63166    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
63167    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
63168 
63169    IF xla_accounting_cache_pkg.GetValueChar
63170          (p_source_code         => 'LEDGER_CATEGORY_CODE'
63171          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
63172    AND l_bflow_method_code = 'PRIOR_ENTRY'
63173 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
63174    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
63175          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
63176        )
63177    THEN
63178          xla_ae_lines_pkg.BflowUpgEntry
63179            (p_business_method_code    => l_bflow_method_code
63180            ,p_business_class_code     => l_bflow_class_code
63181            ,p_balance_type            => l_balance_type_code);
63182    ELSE
63183       NULL;
63184 -- No business flow processing for business flow method of NONE.
63185    END IF;
63186 
63187    --
63188    -- call analytical criteria
63189    --
63190    
63191    --
63192    -- call description
63193    --
63194    
63195 xla_ae_lines_pkg.SetLineDescription(
63196    p_ae_header_id => l_ae_header_id
63197   ,p_description  => Description_48 (
63198      p_application_id         => p_application_id
63199    , p_ae_header_id           => l_ae_header_id 
63200 , p_source_1 => p_source_1
63201    )
63202 );
63203 
63204 
63205    --
63206    -- call ADRs
63207    -- Bug 4922099
63208    --
63209    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
63210         (NVL(l_actual_upg_option, 'N') = 'O') OR
63211         (NVL(l_enc_upg_option, 'N') = 'O')
63212       )
63213    THEN
63214    NULL;
63215    --
63216    --
63217    
63218   l_ccid := AcctDerRule_174(
63219            p_application_id           => p_application_id
63220          , p_ae_header_id             => l_ae_header_id 
63221 , p_source_3 => p_source_3
63222 , p_source_17 => p_source_17
63223 , p_source_30 => p_source_30
63224          , x_transaction_coa_id       => l_adr_transaction_coa_id
63225          , x_accounting_coa_id        => l_adr_accounting_coa_id
63226          , x_value_type_code          => l_adr_value_type_code
63227          , p_side                     => 'NA'
63228    );
63229 
63230    xla_ae_lines_pkg.set_ccid(
63231     p_code_combination_id          => l_ccid
63232   , p_value_type_code              => l_adr_value_type_code
63233   , p_transaction_coa_id           => l_adr_transaction_coa_id
63234   , p_accounting_coa_id            => l_adr_accounting_coa_id
63235   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
63236   , p_adr_type_code                => 'S'
63237   , p_component_type               => l_component_type
63238   , p_component_code               => l_component_code
63239   , p_component_type_code          => l_component_type_code
63240   , p_component_appl_id            => l_component_appl_id
63241   , p_amb_context_code             => l_amb_context_code
63242   , p_side                         => 'NA'
63243   );
63244 
63245 
63246    l_segment := AcctDerRule_150(
63250 , p_source_11 => p_source_11
63247            p_application_id           => p_application_id
63248          , p_ae_header_id             => l_ae_header_id 
63249 , p_source_3 => p_source_3
63251          , x_transaction_coa_id       => l_adr_transaction_coa_id
63252          , x_accounting_coa_id        => l_adr_accounting_coa_id
63253          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
63254          , x_flex_value_set_id        => l_adr_flex_value_set_id
63255          , x_value_type_code          => l_adr_value_type_code
63256          , x_value_combination_id     => l_adr_value_combination_id
63257          , x_value_segment_code       => l_adr_value_segment_code
63258          , p_side                     => 'NA'
63259          , p_override_seg_flag        => 'Y'
63260    );
63261 
63262    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
63263 
63264       xla_ae_lines_pkg.set_segment(
63265           p_to_segment_code         => 'GL_ACCOUNT'
63266         , p_segment_value           => l_segment
63267         , p_from_segment_code       => l_adr_value_segment_code
63268         , p_from_combination_id     => l_adr_value_combination_id
63269         , p_value_type_code         => l_adr_value_type_code
63270         , p_transaction_coa_id      => l_adr_transaction_coa_id
63271         , p_accounting_coa_id       => l_adr_accounting_coa_id
63272         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
63273         , p_flex_value_set_id       => l_adr_flex_value_set_id
63274         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
63275         , p_adr_type_code           => 'S'
63276         , p_component_type          => l_component_type
63277         , p_component_code          => l_component_code
63278         , p_component_type_code     => l_component_type_code
63279         , p_component_appl_id       => l_component_appl_id
63280         , p_amb_context_code        => l_amb_context_code
63281         , p_entity_code             => 'TRANSACTIONS'
63282         , p_event_class_code        => 'CIP_TRANSFERS'
63283         , p_side                    => 'NA'
63284         );
63285 
63286   END IF;
63287 
63288    l_segment := AcctDerRule_168(
63289            p_application_id           => p_application_id
63290          , p_ae_header_id             => l_ae_header_id 
63291 , p_source_3 => p_source_3
63292 , p_source_29 => p_source_29
63293          , x_transaction_coa_id       => l_adr_transaction_coa_id
63294          , x_accounting_coa_id        => l_adr_accounting_coa_id
63295          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
63296          , x_flex_value_set_id        => l_adr_flex_value_set_id
63297          , x_value_type_code          => l_adr_value_type_code
63298          , x_value_combination_id     => l_adr_value_combination_id
63299          , x_value_segment_code       => l_adr_value_segment_code
63300          , p_side                     => 'NA'
63301          , p_override_seg_flag        => 'Y'
63302    );
63303 
63304    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
63305 
63306       xla_ae_lines_pkg.set_segment(
63307           p_to_segment_code         => 'GL_BALANCING'
63308         , p_segment_value           => l_segment
63309         , p_from_segment_code       => l_adr_value_segment_code
63310         , p_from_combination_id     => l_adr_value_combination_id
63311         , p_value_type_code         => l_adr_value_type_code
63312         , p_transaction_coa_id      => l_adr_transaction_coa_id
63313         , p_accounting_coa_id       => l_adr_accounting_coa_id
63314         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
63315         , p_flex_value_set_id       => l_adr_flex_value_set_id
63316         , p_adr_code                => 'FA_EXPENSE_ACCT'
63317         , p_adr_type_code           => 'S'
63318         , p_component_type          => l_component_type
63319         , p_component_code          => l_component_code
63320         , p_component_type_code     => l_component_type_code
63321         , p_component_appl_id       => l_component_appl_id
63322         , p_amb_context_code        => l_amb_context_code
63323         , p_entity_code             => 'TRANSACTIONS'
63324         , p_event_class_code        => 'CIP_TRANSFERS'
63325         , p_side                    => 'NA'
63326         );
63327 
63328   END IF;
63329 
63330    --
63331    --
63332    END IF;
63333    --
63334    -- Bug 4922099
63335    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
63336           (NVL(l_enc_upg_option, 'N') = 'O')
63337         ) AND
63338         (l_bflow_method_code = 'PRIOR_ENTRY')
63339       )
63340    THEN
63341       IF
63342       --
63343       1 = 2
63344       --
63345       THEN
63346       xla_accounting_err_pkg.build_message
63347                                     (p_appli_s_name            => 'XLA'
63348                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
63349                                     ,p_token_1                 => 'LINE_NUMBER'
63350                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
63351                                     ,p_token_2                 => 'LINE_TYPE_NAME'
63352                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
63353                                                                              l_component_type
63354                                                                             ,l_component_code
63355                                                                             ,l_component_type_code
63356                                                                             ,l_component_appl_id
63357                                                                             ,l_amb_context_code
63358                                                                             ,l_entity_code
63359                                                                             ,l_event_class_code
63363                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
63360                                                                            )
63361                                     ,p_token_3                 => 'OWNER'
63362                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
63364                                                                           ,p_lookup_code    => l_component_type_code
63365                                                                          )
63366                                     ,p_token_4                 => 'PRODUCT_NAME'
63367                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
63368                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
63369                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
63370                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
63371                                     ,p_ae_header_id            =>  NULL
63372                                        );
63373 
63374         IF (C_LEVEL_ERROR>= g_log_level) THEN
63375                  trace
63376                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
63377                       ,p_level    => C_LEVEL_ERROR
63378                       ,p_module   => l_log_module);
63379         END IF;
63380       END IF;
63381    END IF;
63382    --
63383    --
63384    ------------------------------------------------------------------------------------------------
63385    -- 4219869 Business Flow
63386    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
63387    -- Prior Entry.  Currently, the following code is always generated.
63388    ------------------------------------------------------------------------------------------------
63389    XLA_AE_LINES_PKG.ValidateCurrentLine;
63390 
63391    ------------------------------------------------------------------------------------
63392    -- 4219869 Business Flow
63393    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
63394    ------------------------------------------------------------------------------------
63395    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
63396 
63397    ----------------------------------------------------------------------------------
63398    -- 4219869 Business Flow
63399    -- Update journal entry status -- Need to generate this within IF <condition>
63400    ----------------------------------------------------------------------------------
63401    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
63402          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
63403          ,p_balance_type_code => l_balance_type_code
63404          );
63405 
63406    -------------------------------------------------------------------------------------------
63407    -- 4262811 - Generate the Accrual Reversal lines
63408    -------------------------------------------------------------------------------------------
63409    BEGIN
63410       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
63411                               (g_array_event(p_event_id).array_value_num('header_index'));
63412       IF l_acc_rev_flag IS NULL THEN
63413          l_acc_rev_flag := 'N';
63414       END IF;
63415    EXCEPTION
63416       WHEN OTHERS THEN
63417          l_acc_rev_flag := 'N';
63418    END;
63419    --
63420    IF (l_acc_rev_flag = 'Y') THEN
63421 
63422        -- 4645092  ------------------------------------------------------------------------------
63423        -- To allow MPA report to determine if it should generate report process
63424        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
63425        ------------------------------------------------------------------------------------------
63426 
63427        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
63428        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
63429    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
63430    -- call ADRs
63431    -- Bug 4922099
63432    --
63433    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
63434         (NVL(l_actual_upg_option, 'N') = 'O') OR
63435         (NVL(l_enc_upg_option, 'N') = 'O')
63436       )
63437    THEN
63438    NULL;
63439    --
63440    --
63441    
63442   l_ccid := AcctDerRule_174(
63443            p_application_id           => p_application_id
63444          , p_ae_header_id             => l_ae_header_id 
63445 , p_source_3 => p_source_3
63446 , p_source_17 => p_source_17
63447 , p_source_30 => p_source_30
63448          , x_transaction_coa_id       => l_adr_transaction_coa_id
63449          , x_accounting_coa_id        => l_adr_accounting_coa_id
63450          , x_value_type_code          => l_adr_value_type_code
63451          , p_side                     => 'NA'
63452    );
63453 
63454    xla_ae_lines_pkg.set_ccid(
63455     p_code_combination_id          => l_ccid
63456   , p_value_type_code              => l_adr_value_type_code
63457   , p_transaction_coa_id           => l_adr_transaction_coa_id
63458   , p_accounting_coa_id            => l_adr_accounting_coa_id
63459   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
63460   , p_adr_type_code                => 'S'
63461   , p_component_type               => l_component_type
63462   , p_component_code               => l_component_code
63463   , p_component_type_code          => l_component_type_code
63464   , p_component_appl_id            => l_component_appl_id
63465   , p_amb_context_code             => l_amb_context_code
63466   , p_side                         => 'NA'
63467   );
63468 
63469 
63470    l_segment := AcctDerRule_150(
63471            p_application_id           => p_application_id
63475          , x_transaction_coa_id       => l_adr_transaction_coa_id
63472          , p_ae_header_id             => l_ae_header_id 
63473 , p_source_3 => p_source_3
63474 , p_source_11 => p_source_11
63476          , x_accounting_coa_id        => l_adr_accounting_coa_id
63477          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
63478          , x_flex_value_set_id        => l_adr_flex_value_set_id
63479          , x_value_type_code          => l_adr_value_type_code
63480          , x_value_combination_id     => l_adr_value_combination_id
63481          , x_value_segment_code       => l_adr_value_segment_code
63482          , p_side                     => 'NA'
63483          , p_override_seg_flag        => 'Y'
63484    );
63485 
63486    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
63487 
63488       xla_ae_lines_pkg.set_segment(
63489           p_to_segment_code         => 'GL_ACCOUNT'
63490         , p_segment_value           => l_segment
63491         , p_from_segment_code       => l_adr_value_segment_code
63492         , p_from_combination_id     => l_adr_value_combination_id
63493         , p_value_type_code         => l_adr_value_type_code
63494         , p_transaction_coa_id      => l_adr_transaction_coa_id
63495         , p_accounting_coa_id       => l_adr_accounting_coa_id
63496         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
63497         , p_flex_value_set_id       => l_adr_flex_value_set_id
63498         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
63499         , p_adr_type_code           => 'S'
63500         , p_component_type          => l_component_type
63501         , p_component_code          => l_component_code
63502         , p_component_type_code     => l_component_type_code
63503         , p_component_appl_id       => l_component_appl_id
63504         , p_amb_context_code        => l_amb_context_code
63505         , p_entity_code             => 'TRANSACTIONS'
63506         , p_event_class_code        => 'CIP_TRANSFERS'
63507         , p_side                    => 'NA'
63508         );
63509 
63510   END IF;
63511 
63512    l_segment := AcctDerRule_168(
63513            p_application_id           => p_application_id
63514          , p_ae_header_id             => l_ae_header_id 
63515 , p_source_3 => p_source_3
63516 , p_source_29 => p_source_29
63517          , x_transaction_coa_id       => l_adr_transaction_coa_id
63518          , x_accounting_coa_id        => l_adr_accounting_coa_id
63519          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
63520          , x_flex_value_set_id        => l_adr_flex_value_set_id
63521          , x_value_type_code          => l_adr_value_type_code
63522          , x_value_combination_id     => l_adr_value_combination_id
63523          , x_value_segment_code       => l_adr_value_segment_code
63524          , p_side                     => 'NA'
63525          , p_override_seg_flag        => 'Y'
63526    );
63527 
63528    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
63529 
63530       xla_ae_lines_pkg.set_segment(
63531           p_to_segment_code         => 'GL_BALANCING'
63532         , p_segment_value           => l_segment
63533         , p_from_segment_code       => l_adr_value_segment_code
63534         , p_from_combination_id     => l_adr_value_combination_id
63535         , p_value_type_code         => l_adr_value_type_code
63536         , p_transaction_coa_id      => l_adr_transaction_coa_id
63537         , p_accounting_coa_id       => l_adr_accounting_coa_id
63538         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
63539         , p_flex_value_set_id       => l_adr_flex_value_set_id
63540         , p_adr_code                => 'FA_EXPENSE_ACCT'
63541         , p_adr_type_code           => 'S'
63542         , p_component_type          => l_component_type
63543         , p_component_code          => l_component_code
63544         , p_component_type_code     => l_component_type_code
63545         , p_component_appl_id       => l_component_appl_id
63546         , p_amb_context_code        => l_amb_context_code
63547         , p_entity_code             => 'TRANSACTIONS'
63548         , p_event_class_code        => 'CIP_TRANSFERS'
63549         , p_side                    => 'NA'
63550         );
63551 
63552   END IF;
63553 
63554    --
63555    --
63556    END IF;
63557 
63558        --
63559        -- Update the line information that should be overwritten
63560        --
63561        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
63562                                          p_header_num   => 1);
63563        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
63564 
63565        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
63566 
63567        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
63568           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
63569        END IF;
63570 
63571       --
63572       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
63573       --
63574       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
63575           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
63576       ELSE
63577           ---------------------------------------------------------------------------------------------------
63578           -- 4262811a Switch Sign
63579           ---------------------------------------------------------------------------------------------------
63580           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
63581           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
63582                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
63586           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
63583           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
63584                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
63585           -- 5132302
63587                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
63588 
63589       END IF;
63590 
63591       -- 4955764
63592       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
63593       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
63594 
63595 
63596       XLA_AE_LINES_PKG.ValidateCurrentLine;
63597       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
63598 
63599       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
63600                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
63601                ,p_balance_type_code => l_balance_type_code);
63602 
63603    END IF;
63604 
63605    -----------------------------------------------------------------------------------------
63606    -- 4262811 Multiperiod Accounting
63607    -----------------------------------------------------------------------------------------
63608      -- No MPA option is assigned.
63609 
63610 
63611 END IF;
63612 END IF;
63613 --
63614 
63615 --
63616 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63617    trace
63618       (p_msg      => 'END of AcctLineType_242'
63619       ,p_level    => C_LEVEL_PROCEDURE
63620       ,p_module   => l_log_module);
63621 END IF;
63622 --
63623 EXCEPTION
63624   WHEN xla_exceptions_pkg.application_exception THEN
63625       RAISE;
63626   WHEN OTHERS THEN
63627        xla_exceptions_pkg.raise_message
63628            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_242');
63629 END AcctLineType_242;
63630 --
63631 
63632 ---------------------------------------
63633 --
63634 -- PRIVATE FUNCTION
63635 --         AcctLineType_243
63636 --
63637 ---------------------------------------
63638 PROCEDURE AcctLineType_243 (
63639   p_application_id        IN NUMBER
63640  ,p_event_id              IN NUMBER
63641  ,p_calculate_acctd_flag  IN VARCHAR2
63642  ,p_calculate_g_l_flag    IN VARCHAR2
63643  ,p_actual_flag           IN OUT VARCHAR2
63644  ,p_balance_type_code     OUT VARCHAR2
63645  ,p_gain_or_loss_ref      OUT VARCHAR2
63646  
63647 --Period Close Date
63648  , p_source_1            IN DATE
63649 --Generated Code Combination Identifier
63650  , p_source_3            IN NUMBER
63651 --Intercompany Payables Account
63652  , p_source_19            IN VARCHAR2
63653 --Expense Account Code Combination Identifier
63654  , p_source_29            IN NUMBER
63655 --Default Code Combination Identifier
63656  , p_source_30            IN NUMBER
63657 --Adjustment Type
63658  , p_source_35            IN VARCHAR2
63659 --Transaction Header Identifier
63660  , p_source_36            IN NUMBER
63661 --Adjustment Line Identifier
63662  , p_source_37            IN NUMBER
63663 --Distribution Type Code
63664  , p_source_38            IN VARCHAR2
63665 --Entered Amount
63666  , p_source_39            IN NUMBER
63667 --Currency Code
63668  , p_source_40            IN VARCHAR2
63669 )
63670 IS
63671 
63672 l_component_type              VARCHAR2(80);
63673 l_component_code              VARCHAR2(30);
63674 l_component_type_code         VARCHAR2(1);
63675 l_component_appl_id           INTEGER;
63676 l_amb_context_code            VARCHAR2(30);
63677 l_entity_code                 VARCHAR2(30);
63678 l_event_class_code            VARCHAR2(30);
63679 l_ae_header_id                NUMBER;
63680 l_event_type_code             VARCHAR2(30);
63681 l_line_definition_code        VARCHAR2(30);
63682 l_line_definition_owner_code  VARCHAR2(1);
63683 --
63684 -- adr variables
63685 l_segment                     VARCHAR2(30);
63686 l_ccid                        NUMBER;
63687 l_adr_transaction_coa_id      NUMBER;
63688 l_adr_accounting_coa_id       NUMBER;
63689 l_adr_flexfield_segment_code  VARCHAR2(30);
63690 l_adr_flex_value_set_id       NUMBER;
63691 l_adr_value_type_code         VARCHAR2(30);
63692 l_adr_value_combination_id    NUMBER;
63693 l_adr_value_segment_code      VARCHAR2(30);
63694 
63695 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
63696 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
63697 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
63698 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
63699 
63700 -- 4262811 Variables ------------------------------------------------------------------------------------------
63701 l_entered_amt_idx             NUMBER;
63702 l_accted_amt_idx              NUMBER;
63703 l_acc_rev_flag                VARCHAR2(1);
63704 l_accrual_line_num            NUMBER;
63705 l_tmp_amt                     NUMBER;
63706 l_acc_rev_natural_side_code   VARCHAR2(1);
63707 
63708 l_num_entries                 NUMBER;
63709 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
63710 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
63711 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
63712 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
63713 l_recog_line_1                NUMBER;
63714 l_recog_line_2                NUMBER;
63715 
63716 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
63717 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
63718 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
63719 
63723 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
63720 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
63721 
63722 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
63724 
63725 ---------------------------------------------------------------------------------------------------------------
63726 
63727 
63728 --
63729 -- bulk performance
63730 --
63731 l_balance_type_code           VARCHAR2(1);
63732 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
63733 l_log_module                  VARCHAR2(240);
63734 
63735 --
63736 -- Upgrade strategy
63737 --
63738 l_actual_upg_option           VARCHAR2(1);
63739 l_enc_upg_option           VARCHAR2(1);
63740 
63741 --
63742 BEGIN
63743 --
63744 IF g_log_enabled THEN
63745       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_243';
63746 END IF;
63747 --
63748 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63749 
63750       trace
63751          (p_msg      => 'BEGIN of AcctLineType_243'
63752          ,p_level    => C_LEVEL_PROCEDURE
63753          ,p_module   => l_log_module);
63754 
63755 END IF;
63756 --
63757 l_component_type             := 'AMB_JLT';
63758 l_component_code             := 'FA_CIP_TRANSFER_IC_PAY';
63759 l_component_type_code        := 'S';
63760 l_component_appl_id          :=  140;
63761 l_amb_context_code           := 'DEFAULT';
63762 l_entity_code                := 'TRANSACTIONS';
63763 l_event_class_code           := 'CIP_TRANSFERS';
63764 l_event_type_code            := 'CIP_TRANSFERS_ALL';
63765 l_line_definition_owner_code := 'S';
63766 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_T12';
63767 --
63768 l_balance_type_code          := 'A';
63769 l_segment                     := NULL;
63770 l_ccid                        := NULL;
63771 l_adr_transaction_coa_id      := NULL;
63772 l_adr_accounting_coa_id       := NULL;
63773 l_adr_flexfield_segment_code  := NULL;
63774 l_adr_flex_value_set_id       := NULL;
63775 l_adr_value_type_code         := NULL;
63776 l_adr_value_combination_id    := NULL;
63777 l_adr_value_segment_code      := NULL;
63778 
63779 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
63780 l_bflow_class_code           := '';    -- 4219869 Business Flow
63781 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
63782 l_budgetary_control_flag     := 'N';
63783 
63784 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
63785 l_bflow_applied_to_amt       := NULL; -- 5132302
63786 l_entered_amt_idx            := NULL;          -- 4262811
63787 l_accted_amt_idx             := NULL;          -- 4262811
63788 l_acc_rev_flag               := NULL;          -- 4262811
63789 l_accrual_line_num           := NULL;          -- 4262811
63790 l_tmp_amt                    := NULL;          -- 4262811
63791 --
63792  
63793 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
63794     l_balance_type_code <> 'B' THEN
63795 IF NVL(p_source_35,'
63796 ') =  'INTERCO AP'
63797  THEN 
63798 
63799    --
63800    XLA_AE_LINES_PKG.SetNewLine;
63801 
63802    p_balance_type_code          := l_balance_type_code;
63803    -- set the flag so later we will know whether the gain loss line needs to be created
63804    
63805    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
63806      p_actual_flag :='A';
63807    END IF;
63808 
63809    --
63810    -- bulk performance
63811    --
63812    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
63813                                       p_header_num   => 0); -- 4262811
63814    --
63815    -- set accounting line options
63816    --
63817    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
63818            p_natural_side_code          => 'C'
63819          , p_gain_or_loss_flag          => 'N'
63820          , p_gl_transfer_mode_code      => 'S'
63821          , p_acct_entry_type_code       => 'A'
63822          , p_switch_side_flag           => 'Y'
63823          , p_merge_duplicate_code       => 'N'
63824          );
63825    --
63826    l_acc_rev_natural_side_code := 'D';  -- 4262811
63827    -- 
63828    --
63829    -- set accounting line type info
63830    --
63831    xla_ae_lines_pkg.SetAcctLineType
63832       (p_component_type             => l_component_type
63833       ,p_event_type_code            => l_event_type_code
63834       ,p_line_definition_owner_code => l_line_definition_owner_code
63835       ,p_line_definition_code       => l_line_definition_code
63836       ,p_accounting_line_code       => l_component_code
63837       ,p_accounting_line_type_code  => l_component_type_code
63838       ,p_accounting_line_appl_id    => l_component_appl_id
63839       ,p_amb_context_code           => l_amb_context_code
63840       ,p_entity_code                => l_entity_code
63841       ,p_event_class_code           => l_event_class_code);
63842    --
63843    -- set accounting class
63844    --
63845    xla_ae_lines_pkg.SetAcctClass(
63846            p_accounting_class_code  => 'LIABILITY'
63847          , p_ae_header_id           => l_ae_header_id
63848          );
63849 
63850    --
63851    -- set rounding class
63852    --
63853    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
63854                       'LIABILITY';
63855 
63856    --
63857    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
63858    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
63859    --
63860    -- bulk performance
63861    --
63865       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
63862    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
63863 
63864    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
63866 
63867    -- 4955764
63868    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
63869       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
63870 
63871    -- 4458381 Public Sector Enh
63872    
63873    --
63874    -- set accounting attributes for the line type
63875    --
63876    l_entered_amt_idx := 4;
63877    l_accted_amt_idx  := 6;
63878    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
63879    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
63880    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
63881    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
63882    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
63883    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
63884    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
63885    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
63886    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
63887    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
63888    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
63889    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
63890    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
63891 
63892    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
63893    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
63894 
63895    ---------------------------------------------------------------------------------------------------------------
63896    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
63897    ---------------------------------------------------------------------------------------------------------------
63898    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
63899 
63900    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
63901    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
63902 
63903    IF xla_accounting_cache_pkg.GetValueChar
63904          (p_source_code         => 'LEDGER_CATEGORY_CODE'
63905          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
63906    AND l_bflow_method_code = 'PRIOR_ENTRY'
63907 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
63908    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
63909          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
63910        )
63911    THEN
63912          xla_ae_lines_pkg.BflowUpgEntry
63913            (p_business_method_code    => l_bflow_method_code
63914            ,p_business_class_code     => l_bflow_class_code
63915            ,p_balance_type            => l_balance_type_code);
63916    ELSE
63917       NULL;
63918 -- No business flow processing for business flow method of NONE.
63919    END IF;
63920 
63921    --
63922    -- call analytical criteria
63923    --
63924    
63925    --
63926    -- call description
63927    --
63928    
63929 xla_ae_lines_pkg.SetLineDescription(
63930    p_ae_header_id => l_ae_header_id
63931   ,p_description  => Description_46 (
63932      p_application_id         => p_application_id
63933    , p_ae_header_id           => l_ae_header_id 
63934 , p_source_1 => p_source_1
63935    )
63936 );
63937 
63938 
63939    --
63940    -- call ADRs
63941    -- Bug 4922099
63942    --
63943    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
63944         (NVL(l_actual_upg_option, 'N') = 'O') OR
63945         (NVL(l_enc_upg_option, 'N') = 'O')
63946       )
63947    THEN
63948    NULL;
63949    --
63950    --
63951    
63952   l_ccid := AcctDerRule_173(
63953            p_application_id           => p_application_id
63954          , p_ae_header_id             => l_ae_header_id 
63955 , p_source_3 => p_source_3
63956 , p_source_30 => p_source_30
63957          , x_transaction_coa_id       => l_adr_transaction_coa_id
63958          , x_accounting_coa_id        => l_adr_accounting_coa_id
63959          , x_value_type_code          => l_adr_value_type_code
63960          , p_side                     => 'NA'
63961    );
63962 
63963    xla_ae_lines_pkg.set_ccid(
63964     p_code_combination_id          => l_ccid
63965   , p_value_type_code              => l_adr_value_type_code
63966   , p_transaction_coa_id           => l_adr_transaction_coa_id
63967   , p_accounting_coa_id            => l_adr_accounting_coa_id
63968   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
63969   , p_adr_type_code                => 'S'
63970   , p_component_type               => l_component_type
63971   , p_component_code               => l_component_code
63972   , p_component_type_code          => l_component_type_code
63973   , p_component_appl_id            => l_component_appl_id
63974   , p_amb_context_code             => l_amb_context_code
63975   , p_side                         => 'NA'
63976   );
63977 
63978 
63979    l_segment := AcctDerRule_168(
63980            p_application_id           => p_application_id
63981          , p_ae_header_id             => l_ae_header_id 
63982 , p_source_3 => p_source_3
63983 , p_source_29 => p_source_29
63984          , x_transaction_coa_id       => l_adr_transaction_coa_id
63985          , x_accounting_coa_id        => l_adr_accounting_coa_id
63986          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
63987          , x_flex_value_set_id        => l_adr_flex_value_set_id
63991          , p_side                     => 'NA'
63988          , x_value_type_code          => l_adr_value_type_code
63989          , x_value_combination_id     => l_adr_value_combination_id
63990          , x_value_segment_code       => l_adr_value_segment_code
63992          , p_override_seg_flag        => 'Y'
63993    );
63994 
63995    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
63996 
63997       xla_ae_lines_pkg.set_segment(
63998           p_to_segment_code         => 'GL_BALANCING'
63999         , p_segment_value           => l_segment
64000         , p_from_segment_code       => l_adr_value_segment_code
64001         , p_from_combination_id     => l_adr_value_combination_id
64002         , p_value_type_code         => l_adr_value_type_code
64003         , p_transaction_coa_id      => l_adr_transaction_coa_id
64004         , p_accounting_coa_id       => l_adr_accounting_coa_id
64005         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
64006         , p_flex_value_set_id       => l_adr_flex_value_set_id
64007         , p_adr_code                => 'FA_EXPENSE_ACCT'
64008         , p_adr_type_code           => 'S'
64009         , p_component_type          => l_component_type
64010         , p_component_code          => l_component_code
64011         , p_component_type_code     => l_component_type_code
64012         , p_component_appl_id       => l_component_appl_id
64013         , p_amb_context_code        => l_amb_context_code
64014         , p_entity_code             => 'TRANSACTIONS'
64015         , p_event_class_code        => 'CIP_TRANSFERS'
64016         , p_side                    => 'NA'
64017         );
64018 
64019   END IF;
64020 
64021    l_segment := AcctDerRule_157(
64022            p_application_id           => p_application_id
64023          , p_ae_header_id             => l_ae_header_id 
64024 , p_source_3 => p_source_3
64025 , p_source_19 => p_source_19
64026          , x_transaction_coa_id       => l_adr_transaction_coa_id
64027          , x_accounting_coa_id        => l_adr_accounting_coa_id
64028          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
64029          , x_flex_value_set_id        => l_adr_flex_value_set_id
64030          , x_value_type_code          => l_adr_value_type_code
64031          , x_value_combination_id     => l_adr_value_combination_id
64032          , x_value_segment_code       => l_adr_value_segment_code
64033          , p_side                     => 'NA'
64034          , p_override_seg_flag        => 'Y'
64035    );
64036 
64037    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
64038 
64039       xla_ae_lines_pkg.set_segment(
64040           p_to_segment_code         => 'GL_ACCOUNT'
64041         , p_segment_value           => l_segment
64042         , p_from_segment_code       => l_adr_value_segment_code
64043         , p_from_combination_id     => l_adr_value_combination_id
64044         , p_value_type_code         => l_adr_value_type_code
64045         , p_transaction_coa_id      => l_adr_transaction_coa_id
64046         , p_accounting_coa_id       => l_adr_accounting_coa_id
64047         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
64048         , p_flex_value_set_id       => l_adr_flex_value_set_id
64049         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
64050         , p_adr_type_code           => 'S'
64051         , p_component_type          => l_component_type
64052         , p_component_code          => l_component_code
64053         , p_component_type_code     => l_component_type_code
64054         , p_component_appl_id       => l_component_appl_id
64055         , p_amb_context_code        => l_amb_context_code
64056         , p_entity_code             => 'TRANSACTIONS'
64057         , p_event_class_code        => 'CIP_TRANSFERS'
64058         , p_side                    => 'NA'
64059         );
64060 
64061   END IF;
64062 
64063    --
64064    --
64065    END IF;
64066    --
64067    -- Bug 4922099
64068    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
64069           (NVL(l_enc_upg_option, 'N') = 'O')
64070         ) AND
64071         (l_bflow_method_code = 'PRIOR_ENTRY')
64072       )
64073    THEN
64074       IF
64075       --
64076       1 = 2
64077       --
64078       THEN
64079       xla_accounting_err_pkg.build_message
64080                                     (p_appli_s_name            => 'XLA'
64081                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
64082                                     ,p_token_1                 => 'LINE_NUMBER'
64083                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
64084                                     ,p_token_2                 => 'LINE_TYPE_NAME'
64085                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
64086                                                                              l_component_type
64087                                                                             ,l_component_code
64088                                                                             ,l_component_type_code
64089                                                                             ,l_component_appl_id
64090                                                                             ,l_amb_context_code
64091                                                                             ,l_entity_code
64092                                                                             ,l_event_class_code
64093                                                                            )
64094                                     ,p_token_3                 => 'OWNER'
64095                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
64096                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
64097                                                                           ,p_lookup_code    => l_component_type_code
64101                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
64098                                                                          )
64099                                     ,p_token_4                 => 'PRODUCT_NAME'
64100                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
64102                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
64103                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
64104                                     ,p_ae_header_id            =>  NULL
64105                                        );
64106 
64107         IF (C_LEVEL_ERROR>= g_log_level) THEN
64108                  trace
64109                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
64110                       ,p_level    => C_LEVEL_ERROR
64111                       ,p_module   => l_log_module);
64112         END IF;
64113       END IF;
64114    END IF;
64115    --
64116    --
64117    ------------------------------------------------------------------------------------------------
64118    -- 4219869 Business Flow
64119    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
64120    -- Prior Entry.  Currently, the following code is always generated.
64121    ------------------------------------------------------------------------------------------------
64122    XLA_AE_LINES_PKG.ValidateCurrentLine;
64123 
64124    ------------------------------------------------------------------------------------
64125    -- 4219869 Business Flow
64126    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
64127    ------------------------------------------------------------------------------------
64128    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
64129 
64130    ----------------------------------------------------------------------------------
64131    -- 4219869 Business Flow
64132    -- Update journal entry status -- Need to generate this within IF <condition>
64133    ----------------------------------------------------------------------------------
64134    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
64135          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
64136          ,p_balance_type_code => l_balance_type_code
64137          );
64138 
64139    -------------------------------------------------------------------------------------------
64140    -- 4262811 - Generate the Accrual Reversal lines
64141    -------------------------------------------------------------------------------------------
64142    BEGIN
64143       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
64144                               (g_array_event(p_event_id).array_value_num('header_index'));
64145       IF l_acc_rev_flag IS NULL THEN
64146          l_acc_rev_flag := 'N';
64147       END IF;
64148    EXCEPTION
64149       WHEN OTHERS THEN
64150          l_acc_rev_flag := 'N';
64151    END;
64152    --
64153    IF (l_acc_rev_flag = 'Y') THEN
64154 
64155        -- 4645092  ------------------------------------------------------------------------------
64156        -- To allow MPA report to determine if it should generate report process
64157        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
64158        ------------------------------------------------------------------------------------------
64159 
64160        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
64161        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
64162    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
64163    -- call ADRs
64164    -- Bug 4922099
64165    --
64166    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
64167         (NVL(l_actual_upg_option, 'N') = 'O') OR
64168         (NVL(l_enc_upg_option, 'N') = 'O')
64169       )
64170    THEN
64171    NULL;
64172    --
64173    --
64174    
64175   l_ccid := AcctDerRule_173(
64176            p_application_id           => p_application_id
64177          , p_ae_header_id             => l_ae_header_id 
64178 , p_source_3 => p_source_3
64179 , p_source_30 => p_source_30
64180          , x_transaction_coa_id       => l_adr_transaction_coa_id
64181          , x_accounting_coa_id        => l_adr_accounting_coa_id
64182          , x_value_type_code          => l_adr_value_type_code
64183          , p_side                     => 'NA'
64184    );
64185 
64186    xla_ae_lines_pkg.set_ccid(
64187     p_code_combination_id          => l_ccid
64188   , p_value_type_code              => l_adr_value_type_code
64189   , p_transaction_coa_id           => l_adr_transaction_coa_id
64190   , p_accounting_coa_id            => l_adr_accounting_coa_id
64191   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
64192   , p_adr_type_code                => 'S'
64193   , p_component_type               => l_component_type
64194   , p_component_code               => l_component_code
64195   , p_component_type_code          => l_component_type_code
64196   , p_component_appl_id            => l_component_appl_id
64197   , p_amb_context_code             => l_amb_context_code
64198   , p_side                         => 'NA'
64199   );
64200 
64201 
64202    l_segment := AcctDerRule_168(
64203            p_application_id           => p_application_id
64204          , p_ae_header_id             => l_ae_header_id 
64205 , p_source_3 => p_source_3
64206 , p_source_29 => p_source_29
64207          , x_transaction_coa_id       => l_adr_transaction_coa_id
64208          , x_accounting_coa_id        => l_adr_accounting_coa_id
64209          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
64210          , x_flex_value_set_id        => l_adr_flex_value_set_id
64211          , x_value_type_code          => l_adr_value_type_code
64212          , x_value_combination_id     => l_adr_value_combination_id
64216    );
64213          , x_value_segment_code       => l_adr_value_segment_code
64214          , p_side                     => 'NA'
64215          , p_override_seg_flag        => 'Y'
64217 
64218    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
64219 
64220       xla_ae_lines_pkg.set_segment(
64221           p_to_segment_code         => 'GL_BALANCING'
64222         , p_segment_value           => l_segment
64223         , p_from_segment_code       => l_adr_value_segment_code
64224         , p_from_combination_id     => l_adr_value_combination_id
64225         , p_value_type_code         => l_adr_value_type_code
64226         , p_transaction_coa_id      => l_adr_transaction_coa_id
64227         , p_accounting_coa_id       => l_adr_accounting_coa_id
64228         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
64229         , p_flex_value_set_id       => l_adr_flex_value_set_id
64230         , p_adr_code                => 'FA_EXPENSE_ACCT'
64231         , p_adr_type_code           => 'S'
64232         , p_component_type          => l_component_type
64233         , p_component_code          => l_component_code
64234         , p_component_type_code     => l_component_type_code
64235         , p_component_appl_id       => l_component_appl_id
64236         , p_amb_context_code        => l_amb_context_code
64237         , p_entity_code             => 'TRANSACTIONS'
64238         , p_event_class_code        => 'CIP_TRANSFERS'
64239         , p_side                    => 'NA'
64240         );
64241 
64242   END IF;
64243 
64244    l_segment := AcctDerRule_157(
64245            p_application_id           => p_application_id
64246          , p_ae_header_id             => l_ae_header_id 
64247 , p_source_3 => p_source_3
64248 , p_source_19 => p_source_19
64249          , x_transaction_coa_id       => l_adr_transaction_coa_id
64250          , x_accounting_coa_id        => l_adr_accounting_coa_id
64251          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
64252          , x_flex_value_set_id        => l_adr_flex_value_set_id
64253          , x_value_type_code          => l_adr_value_type_code
64254          , x_value_combination_id     => l_adr_value_combination_id
64255          , x_value_segment_code       => l_adr_value_segment_code
64256          , p_side                     => 'NA'
64257          , p_override_seg_flag        => 'Y'
64258    );
64259 
64260    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
64261 
64262       xla_ae_lines_pkg.set_segment(
64263           p_to_segment_code         => 'GL_ACCOUNT'
64264         , p_segment_value           => l_segment
64265         , p_from_segment_code       => l_adr_value_segment_code
64266         , p_from_combination_id     => l_adr_value_combination_id
64267         , p_value_type_code         => l_adr_value_type_code
64268         , p_transaction_coa_id      => l_adr_transaction_coa_id
64269         , p_accounting_coa_id       => l_adr_accounting_coa_id
64270         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
64271         , p_flex_value_set_id       => l_adr_flex_value_set_id
64272         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
64273         , p_adr_type_code           => 'S'
64274         , p_component_type          => l_component_type
64275         , p_component_code          => l_component_code
64276         , p_component_type_code     => l_component_type_code
64277         , p_component_appl_id       => l_component_appl_id
64278         , p_amb_context_code        => l_amb_context_code
64279         , p_entity_code             => 'TRANSACTIONS'
64280         , p_event_class_code        => 'CIP_TRANSFERS'
64281         , p_side                    => 'NA'
64282         );
64283 
64284   END IF;
64285 
64286    --
64287    --
64288    END IF;
64289 
64290        --
64291        -- Update the line information that should be overwritten
64292        --
64293        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
64294                                          p_header_num   => 1);
64295        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
64296 
64297        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
64298 
64299        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
64300           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
64301        END IF;
64302 
64303       --
64304       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
64305       --
64306       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
64307           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
64308       ELSE
64309           ---------------------------------------------------------------------------------------------------
64310           -- 4262811a Switch Sign
64311           ---------------------------------------------------------------------------------------------------
64312           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
64313           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
64314                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
64315           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
64316                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
64317           -- 5132302
64318           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
64319                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
64320 
64321       END IF;
64322 
64323       -- 4955764
64324       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
64328       XLA_AE_LINES_PKG.ValidateCurrentLine;
64325       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
64326 
64327 
64329       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
64330 
64331       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
64332                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
64333                ,p_balance_type_code => l_balance_type_code);
64334 
64335    END IF;
64336 
64337    -----------------------------------------------------------------------------------------
64338    -- 4262811 Multiperiod Accounting
64339    -----------------------------------------------------------------------------------------
64340      -- No MPA option is assigned.
64341 
64342 
64343 END IF;
64344 END IF;
64345 --
64346 
64347 --
64348 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
64349    trace
64350       (p_msg      => 'END of AcctLineType_243'
64351       ,p_level    => C_LEVEL_PROCEDURE
64352       ,p_module   => l_log_module);
64353 END IF;
64354 --
64355 EXCEPTION
64356   WHEN xla_exceptions_pkg.application_exception THEN
64357       RAISE;
64358   WHEN OTHERS THEN
64359        xla_exceptions_pkg.raise_message
64360            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_243');
64361 END AcctLineType_243;
64362 --
64363 
64364 ---------------------------------------
64365 --
64366 -- PRIVATE FUNCTION
64367 --         AcctLineType_244
64368 --
64369 ---------------------------------------
64370 PROCEDURE AcctLineType_244 (
64371   p_application_id        IN NUMBER
64372  ,p_event_id              IN NUMBER
64373  ,p_calculate_acctd_flag  IN VARCHAR2
64374  ,p_calculate_g_l_flag    IN VARCHAR2
64375  ,p_actual_flag           IN OUT VARCHAR2
64376  ,p_balance_type_code     OUT VARCHAR2
64377  ,p_gain_or_loss_ref      OUT VARCHAR2
64378  
64379 --Period Close Date
64380  , p_source_1            IN DATE
64381 --Generated Code Combination Identifier
64382  , p_source_3            IN NUMBER
64383 --Intercompany Receivables Account
64384  , p_source_20            IN VARCHAR2
64385 --Expense Account Code Combination Identifier
64386  , p_source_29            IN NUMBER
64387 --Default Code Combination Identifier
64388  , p_source_30            IN NUMBER
64389 --Adjustment Type
64390  , p_source_35            IN VARCHAR2
64391 --Transaction Header Identifier
64392  , p_source_36            IN NUMBER
64393 --Adjustment Line Identifier
64394  , p_source_37            IN NUMBER
64395 --Distribution Type Code
64396  , p_source_38            IN VARCHAR2
64397 --Entered Amount
64398  , p_source_39            IN NUMBER
64399 --Currency Code
64400  , p_source_40            IN VARCHAR2
64401 )
64402 IS
64403 
64404 l_component_type              VARCHAR2(80);
64405 l_component_code              VARCHAR2(30);
64406 l_component_type_code         VARCHAR2(1);
64407 l_component_appl_id           INTEGER;
64408 l_amb_context_code            VARCHAR2(30);
64409 l_entity_code                 VARCHAR2(30);
64410 l_event_class_code            VARCHAR2(30);
64411 l_ae_header_id                NUMBER;
64412 l_event_type_code             VARCHAR2(30);
64413 l_line_definition_code        VARCHAR2(30);
64414 l_line_definition_owner_code  VARCHAR2(1);
64415 --
64416 -- adr variables
64417 l_segment                     VARCHAR2(30);
64418 l_ccid                        NUMBER;
64419 l_adr_transaction_coa_id      NUMBER;
64420 l_adr_accounting_coa_id       NUMBER;
64421 l_adr_flexfield_segment_code  VARCHAR2(30);
64422 l_adr_flex_value_set_id       NUMBER;
64423 l_adr_value_type_code         VARCHAR2(30);
64424 l_adr_value_combination_id    NUMBER;
64425 l_adr_value_segment_code      VARCHAR2(30);
64426 
64427 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
64428 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
64429 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
64430 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
64431 
64432 -- 4262811 Variables ------------------------------------------------------------------------------------------
64433 l_entered_amt_idx             NUMBER;
64434 l_accted_amt_idx              NUMBER;
64435 l_acc_rev_flag                VARCHAR2(1);
64436 l_accrual_line_num            NUMBER;
64437 l_tmp_amt                     NUMBER;
64438 l_acc_rev_natural_side_code   VARCHAR2(1);
64439 
64440 l_num_entries                 NUMBER;
64441 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
64442 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
64443 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
64444 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
64445 l_recog_line_1                NUMBER;
64446 l_recog_line_2                NUMBER;
64447 
64448 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
64449 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
64450 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
64451 
64452 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
64453 
64454 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
64455 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
64456 
64457 ---------------------------------------------------------------------------------------------------------------
64458 
64459 
64460 --
64461 -- bulk performance
64462 --
64463 l_balance_type_code           VARCHAR2(1);
64464 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
64465 l_log_module                  VARCHAR2(240);
64466 
64470 l_actual_upg_option           VARCHAR2(1);
64467 --
64468 -- Upgrade strategy
64469 --
64471 l_enc_upg_option           VARCHAR2(1);
64472 
64473 --
64474 BEGIN
64475 --
64476 IF g_log_enabled THEN
64477       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_244';
64478 END IF;
64479 --
64480 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
64481 
64482       trace
64483          (p_msg      => 'BEGIN of AcctLineType_244'
64484          ,p_level    => C_LEVEL_PROCEDURE
64485          ,p_module   => l_log_module);
64486 
64487 END IF;
64488 --
64489 l_component_type             := 'AMB_JLT';
64490 l_component_code             := 'FA_CIP_TRANSFER_IC_REC';
64491 l_component_type_code        := 'S';
64492 l_component_appl_id          :=  140;
64493 l_amb_context_code           := 'DEFAULT';
64494 l_entity_code                := 'TRANSACTIONS';
64495 l_event_class_code           := 'CIP_TRANSFERS';
64496 l_event_type_code            := 'CIP_TRANSFERS_ALL';
64497 l_line_definition_owner_code := 'S';
64498 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_T12';
64499 --
64500 l_balance_type_code          := 'A';
64501 l_segment                     := NULL;
64502 l_ccid                        := NULL;
64503 l_adr_transaction_coa_id      := NULL;
64504 l_adr_accounting_coa_id       := NULL;
64505 l_adr_flexfield_segment_code  := NULL;
64506 l_adr_flex_value_set_id       := NULL;
64507 l_adr_value_type_code         := NULL;
64508 l_adr_value_combination_id    := NULL;
64509 l_adr_value_segment_code      := NULL;
64510 
64511 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
64512 l_bflow_class_code           := '';    -- 4219869 Business Flow
64513 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
64514 l_budgetary_control_flag     := 'N';
64515 
64516 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
64517 l_bflow_applied_to_amt       := NULL; -- 5132302
64518 l_entered_amt_idx            := NULL;          -- 4262811
64519 l_accted_amt_idx             := NULL;          -- 4262811
64520 l_acc_rev_flag               := NULL;          -- 4262811
64521 l_accrual_line_num           := NULL;          -- 4262811
64522 l_tmp_amt                    := NULL;          -- 4262811
64523 --
64524  
64525 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
64526     l_balance_type_code <> 'B' THEN
64527 IF NVL(p_source_35,'
64528 ') =  'INTERCO AR'
64529  THEN 
64530 
64531    --
64532    XLA_AE_LINES_PKG.SetNewLine;
64533 
64534    p_balance_type_code          := l_balance_type_code;
64535    -- set the flag so later we will know whether the gain loss line needs to be created
64536    
64537    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
64538      p_actual_flag :='A';
64539    END IF;
64540 
64541    --
64542    -- bulk performance
64543    --
64544    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
64545                                       p_header_num   => 0); -- 4262811
64546    --
64547    -- set accounting line options
64548    --
64549    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
64550            p_natural_side_code          => 'D'
64551          , p_gain_or_loss_flag          => 'N'
64552          , p_gl_transfer_mode_code      => 'S'
64553          , p_acct_entry_type_code       => 'A'
64554          , p_switch_side_flag           => 'Y'
64555          , p_merge_duplicate_code       => 'N'
64556          );
64557    --
64558    l_acc_rev_natural_side_code := 'C';  -- 4262811
64559    -- 
64560    --
64561    -- set accounting line type info
64562    --
64563    xla_ae_lines_pkg.SetAcctLineType
64564       (p_component_type             => l_component_type
64565       ,p_event_type_code            => l_event_type_code
64566       ,p_line_definition_owner_code => l_line_definition_owner_code
64567       ,p_line_definition_code       => l_line_definition_code
64568       ,p_accounting_line_code       => l_component_code
64569       ,p_accounting_line_type_code  => l_component_type_code
64570       ,p_accounting_line_appl_id    => l_component_appl_id
64571       ,p_amb_context_code           => l_amb_context_code
64572       ,p_entity_code                => l_entity_code
64573       ,p_event_class_code           => l_event_class_code);
64574    --
64575    -- set accounting class
64576    --
64577    xla_ae_lines_pkg.SetAcctClass(
64578            p_accounting_class_code  => 'ASSET'
64579          , p_ae_header_id           => l_ae_header_id
64580          );
64581 
64582    --
64583    -- set rounding class
64584    --
64585    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
64586                       'ASSET';
64587 
64588    --
64589    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
64590    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
64591    --
64592    -- bulk performance
64593    --
64594    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
64595 
64596    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
64597       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
64598 
64599    -- 4955764
64600    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
64601       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
64602 
64603    -- 4458381 Public Sector Enh
64604    
64605    --
64606    -- set accounting attributes for the line type
64607    --
64608    l_entered_amt_idx := 4;
64609    l_accted_amt_idx  := 6;
64610    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
64614    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
64611    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
64612    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
64613    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
64615    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
64616    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
64617    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
64618    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
64619    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
64620    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
64621    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
64622    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
64623 
64624    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
64625    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
64626 
64627    ---------------------------------------------------------------------------------------------------------------
64628    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
64629    ---------------------------------------------------------------------------------------------------------------
64630    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
64631 
64632    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
64633    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
64634 
64635    IF xla_accounting_cache_pkg.GetValueChar
64636          (p_source_code         => 'LEDGER_CATEGORY_CODE'
64637          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
64638    AND l_bflow_method_code = 'PRIOR_ENTRY'
64639 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
64640    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
64641          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
64642        )
64643    THEN
64644          xla_ae_lines_pkg.BflowUpgEntry
64645            (p_business_method_code    => l_bflow_method_code
64646            ,p_business_class_code     => l_bflow_class_code
64647            ,p_balance_type            => l_balance_type_code);
64648    ELSE
64649       NULL;
64650 -- No business flow processing for business flow method of NONE.
64651    END IF;
64652 
64653    --
64654    -- call analytical criteria
64655    --
64656    
64657    --
64658    -- call description
64659    --
64660    
64661 xla_ae_lines_pkg.SetLineDescription(
64662    p_ae_header_id => l_ae_header_id
64663   ,p_description  => Description_47 (
64664      p_application_id         => p_application_id
64665    , p_ae_header_id           => l_ae_header_id 
64666 , p_source_1 => p_source_1
64667    )
64668 );
64669 
64670 
64671    --
64672    -- call ADRs
64673    -- Bug 4922099
64674    --
64675    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
64676         (NVL(l_actual_upg_option, 'N') = 'O') OR
64677         (NVL(l_enc_upg_option, 'N') = 'O')
64678       )
64679    THEN
64680    NULL;
64681    --
64682    --
64683    
64684   l_ccid := AcctDerRule_173(
64685            p_application_id           => p_application_id
64686          , p_ae_header_id             => l_ae_header_id 
64687 , p_source_3 => p_source_3
64688 , p_source_30 => p_source_30
64689          , x_transaction_coa_id       => l_adr_transaction_coa_id
64690          , x_accounting_coa_id        => l_adr_accounting_coa_id
64691          , x_value_type_code          => l_adr_value_type_code
64692          , p_side                     => 'NA'
64693    );
64694 
64695    xla_ae_lines_pkg.set_ccid(
64696     p_code_combination_id          => l_ccid
64697   , p_value_type_code              => l_adr_value_type_code
64698   , p_transaction_coa_id           => l_adr_transaction_coa_id
64699   , p_accounting_coa_id            => l_adr_accounting_coa_id
64700   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
64701   , p_adr_type_code                => 'S'
64702   , p_component_type               => l_component_type
64703   , p_component_code               => l_component_code
64704   , p_component_type_code          => l_component_type_code
64705   , p_component_appl_id            => l_component_appl_id
64706   , p_amb_context_code             => l_amb_context_code
64707   , p_side                         => 'NA'
64708   );
64709 
64710 
64711    l_segment := AcctDerRule_168(
64712            p_application_id           => p_application_id
64713          , p_ae_header_id             => l_ae_header_id 
64714 , p_source_3 => p_source_3
64715 , p_source_29 => p_source_29
64716          , x_transaction_coa_id       => l_adr_transaction_coa_id
64717          , x_accounting_coa_id        => l_adr_accounting_coa_id
64718          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
64719          , x_flex_value_set_id        => l_adr_flex_value_set_id
64720          , x_value_type_code          => l_adr_value_type_code
64721          , x_value_combination_id     => l_adr_value_combination_id
64722          , x_value_segment_code       => l_adr_value_segment_code
64723          , p_side                     => 'NA'
64724          , p_override_seg_flag        => 'Y'
64725    );
64726 
64727    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
64728 
64729       xla_ae_lines_pkg.set_segment(
64730           p_to_segment_code         => 'GL_BALANCING'
64731         , p_segment_value           => l_segment
64732         , p_from_segment_code       => l_adr_value_segment_code
64733         , p_from_combination_id     => l_adr_value_combination_id
64734         , p_value_type_code         => l_adr_value_type_code
64738         , p_flex_value_set_id       => l_adr_flex_value_set_id
64735         , p_transaction_coa_id      => l_adr_transaction_coa_id
64736         , p_accounting_coa_id       => l_adr_accounting_coa_id
64737         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
64739         , p_adr_code                => 'FA_EXPENSE_ACCT'
64740         , p_adr_type_code           => 'S'
64741         , p_component_type          => l_component_type
64742         , p_component_code          => l_component_code
64743         , p_component_type_code     => l_component_type_code
64744         , p_component_appl_id       => l_component_appl_id
64745         , p_amb_context_code        => l_amb_context_code
64746         , p_entity_code             => 'TRANSACTIONS'
64747         , p_event_class_code        => 'CIP_TRANSFERS'
64748         , p_side                    => 'NA'
64749         );
64750 
64751   END IF;
64752 
64753    l_segment := AcctDerRule_158(
64754            p_application_id           => p_application_id
64755          , p_ae_header_id             => l_ae_header_id 
64756 , p_source_3 => p_source_3
64757 , p_source_20 => p_source_20
64758          , x_transaction_coa_id       => l_adr_transaction_coa_id
64759          , x_accounting_coa_id        => l_adr_accounting_coa_id
64760          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
64761          , x_flex_value_set_id        => l_adr_flex_value_set_id
64762          , x_value_type_code          => l_adr_value_type_code
64763          , x_value_combination_id     => l_adr_value_combination_id
64764          , x_value_segment_code       => l_adr_value_segment_code
64765          , p_side                     => 'NA'
64766          , p_override_seg_flag        => 'Y'
64767    );
64768 
64769    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
64770 
64771       xla_ae_lines_pkg.set_segment(
64772           p_to_segment_code         => 'GL_ACCOUNT'
64773         , p_segment_value           => l_segment
64774         , p_from_segment_code       => l_adr_value_segment_code
64775         , p_from_combination_id     => l_adr_value_combination_id
64776         , p_value_type_code         => l_adr_value_type_code
64777         , p_transaction_coa_id      => l_adr_transaction_coa_id
64778         , p_accounting_coa_id       => l_adr_accounting_coa_id
64779         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
64780         , p_flex_value_set_id       => l_adr_flex_value_set_id
64781         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
64782         , p_adr_type_code           => 'S'
64783         , p_component_type          => l_component_type
64784         , p_component_code          => l_component_code
64785         , p_component_type_code     => l_component_type_code
64786         , p_component_appl_id       => l_component_appl_id
64787         , p_amb_context_code        => l_amb_context_code
64788         , p_entity_code             => 'TRANSACTIONS'
64789         , p_event_class_code        => 'CIP_TRANSFERS'
64790         , p_side                    => 'NA'
64791         );
64792 
64793   END IF;
64794 
64795    --
64796    --
64797    END IF;
64798    --
64799    -- Bug 4922099
64800    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
64801           (NVL(l_enc_upg_option, 'N') = 'O')
64802         ) AND
64803         (l_bflow_method_code = 'PRIOR_ENTRY')
64804       )
64805    THEN
64806       IF
64807       --
64808       1 = 2
64809       --
64810       THEN
64811       xla_accounting_err_pkg.build_message
64812                                     (p_appli_s_name            => 'XLA'
64813                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
64814                                     ,p_token_1                 => 'LINE_NUMBER'
64815                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
64816                                     ,p_token_2                 => 'LINE_TYPE_NAME'
64817                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
64818                                                                              l_component_type
64819                                                                             ,l_component_code
64820                                                                             ,l_component_type_code
64821                                                                             ,l_component_appl_id
64822                                                                             ,l_amb_context_code
64823                                                                             ,l_entity_code
64824                                                                             ,l_event_class_code
64825                                                                            )
64826                                     ,p_token_3                 => 'OWNER'
64827                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
64828                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
64829                                                                           ,p_lookup_code    => l_component_type_code
64830                                                                          )
64831                                     ,p_token_4                 => 'PRODUCT_NAME'
64832                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
64833                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
64834                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
64835                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
64836                                     ,p_ae_header_id            =>  NULL
64837                                        );
64838 
64839         IF (C_LEVEL_ERROR>= g_log_level) THEN
64843                       ,p_module   => l_log_module);
64840                  trace
64841                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
64842                       ,p_level    => C_LEVEL_ERROR
64844         END IF;
64845       END IF;
64846    END IF;
64847    --
64848    --
64849    ------------------------------------------------------------------------------------------------
64850    -- 4219869 Business Flow
64851    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
64852    -- Prior Entry.  Currently, the following code is always generated.
64853    ------------------------------------------------------------------------------------------------
64854    XLA_AE_LINES_PKG.ValidateCurrentLine;
64855 
64856    ------------------------------------------------------------------------------------
64857    -- 4219869 Business Flow
64858    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
64859    ------------------------------------------------------------------------------------
64860    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
64861 
64862    ----------------------------------------------------------------------------------
64863    -- 4219869 Business Flow
64864    -- Update journal entry status -- Need to generate this within IF <condition>
64865    ----------------------------------------------------------------------------------
64866    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
64867          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
64868          ,p_balance_type_code => l_balance_type_code
64869          );
64870 
64871    -------------------------------------------------------------------------------------------
64872    -- 4262811 - Generate the Accrual Reversal lines
64873    -------------------------------------------------------------------------------------------
64874    BEGIN
64875       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
64876                               (g_array_event(p_event_id).array_value_num('header_index'));
64877       IF l_acc_rev_flag IS NULL THEN
64878          l_acc_rev_flag := 'N';
64879       END IF;
64880    EXCEPTION
64881       WHEN OTHERS THEN
64882          l_acc_rev_flag := 'N';
64883    END;
64884    --
64885    IF (l_acc_rev_flag = 'Y') THEN
64886 
64887        -- 4645092  ------------------------------------------------------------------------------
64888        -- To allow MPA report to determine if it should generate report process
64889        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
64890        ------------------------------------------------------------------------------------------
64891 
64892        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
64893        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
64894    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
64895    -- call ADRs
64896    -- Bug 4922099
64897    --
64898    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
64899         (NVL(l_actual_upg_option, 'N') = 'O') OR
64900         (NVL(l_enc_upg_option, 'N') = 'O')
64901       )
64902    THEN
64903    NULL;
64904    --
64905    --
64906    
64907   l_ccid := AcctDerRule_173(
64908            p_application_id           => p_application_id
64909          , p_ae_header_id             => l_ae_header_id 
64910 , p_source_3 => p_source_3
64911 , p_source_30 => p_source_30
64912          , x_transaction_coa_id       => l_adr_transaction_coa_id
64913          , x_accounting_coa_id        => l_adr_accounting_coa_id
64914          , x_value_type_code          => l_adr_value_type_code
64915          , p_side                     => 'NA'
64916    );
64917 
64918    xla_ae_lines_pkg.set_ccid(
64919     p_code_combination_id          => l_ccid
64920   , p_value_type_code              => l_adr_value_type_code
64921   , p_transaction_coa_id           => l_adr_transaction_coa_id
64922   , p_accounting_coa_id            => l_adr_accounting_coa_id
64923   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
64924   , p_adr_type_code                => 'S'
64925   , p_component_type               => l_component_type
64926   , p_component_code               => l_component_code
64927   , p_component_type_code          => l_component_type_code
64928   , p_component_appl_id            => l_component_appl_id
64929   , p_amb_context_code             => l_amb_context_code
64930   , p_side                         => 'NA'
64931   );
64932 
64933 
64934    l_segment := AcctDerRule_168(
64935            p_application_id           => p_application_id
64936          , p_ae_header_id             => l_ae_header_id 
64937 , p_source_3 => p_source_3
64938 , p_source_29 => p_source_29
64939          , x_transaction_coa_id       => l_adr_transaction_coa_id
64940          , x_accounting_coa_id        => l_adr_accounting_coa_id
64941          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
64942          , x_flex_value_set_id        => l_adr_flex_value_set_id
64943          , x_value_type_code          => l_adr_value_type_code
64944          , x_value_combination_id     => l_adr_value_combination_id
64945          , x_value_segment_code       => l_adr_value_segment_code
64946          , p_side                     => 'NA'
64947          , p_override_seg_flag        => 'Y'
64948    );
64949 
64950    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
64951 
64952       xla_ae_lines_pkg.set_segment(
64953           p_to_segment_code         => 'GL_BALANCING'
64954         , p_segment_value           => l_segment
64955         , p_from_segment_code       => l_adr_value_segment_code
64956         , p_from_combination_id     => l_adr_value_combination_id
64957         , p_value_type_code         => l_adr_value_type_code
64958         , p_transaction_coa_id      => l_adr_transaction_coa_id
64959         , p_accounting_coa_id       => l_adr_accounting_coa_id
64963         , p_adr_type_code           => 'S'
64960         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
64961         , p_flex_value_set_id       => l_adr_flex_value_set_id
64962         , p_adr_code                => 'FA_EXPENSE_ACCT'
64964         , p_component_type          => l_component_type
64965         , p_component_code          => l_component_code
64966         , p_component_type_code     => l_component_type_code
64967         , p_component_appl_id       => l_component_appl_id
64968         , p_amb_context_code        => l_amb_context_code
64969         , p_entity_code             => 'TRANSACTIONS'
64970         , p_event_class_code        => 'CIP_TRANSFERS'
64971         , p_side                    => 'NA'
64972         );
64973 
64974   END IF;
64975 
64976    l_segment := AcctDerRule_158(
64977            p_application_id           => p_application_id
64978          , p_ae_header_id             => l_ae_header_id 
64979 , p_source_3 => p_source_3
64980 , p_source_20 => p_source_20
64981          , x_transaction_coa_id       => l_adr_transaction_coa_id
64982          , x_accounting_coa_id        => l_adr_accounting_coa_id
64983          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
64984          , x_flex_value_set_id        => l_adr_flex_value_set_id
64985          , x_value_type_code          => l_adr_value_type_code
64986          , x_value_combination_id     => l_adr_value_combination_id
64987          , x_value_segment_code       => l_adr_value_segment_code
64988          , p_side                     => 'NA'
64989          , p_override_seg_flag        => 'Y'
64990    );
64991 
64992    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
64993 
64994       xla_ae_lines_pkg.set_segment(
64995           p_to_segment_code         => 'GL_ACCOUNT'
64996         , p_segment_value           => l_segment
64997         , p_from_segment_code       => l_adr_value_segment_code
64998         , p_from_combination_id     => l_adr_value_combination_id
64999         , p_value_type_code         => l_adr_value_type_code
65000         , p_transaction_coa_id      => l_adr_transaction_coa_id
65001         , p_accounting_coa_id       => l_adr_accounting_coa_id
65002         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
65003         , p_flex_value_set_id       => l_adr_flex_value_set_id
65004         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
65005         , p_adr_type_code           => 'S'
65006         , p_component_type          => l_component_type
65007         , p_component_code          => l_component_code
65008         , p_component_type_code     => l_component_type_code
65009         , p_component_appl_id       => l_component_appl_id
65010         , p_amb_context_code        => l_amb_context_code
65011         , p_entity_code             => 'TRANSACTIONS'
65012         , p_event_class_code        => 'CIP_TRANSFERS'
65013         , p_side                    => 'NA'
65014         );
65015 
65016   END IF;
65017 
65018    --
65019    --
65020    END IF;
65021 
65022        --
65023        -- Update the line information that should be overwritten
65024        --
65025        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
65026                                          p_header_num   => 1);
65027        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
65028 
65029        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
65030 
65031        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
65032           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
65033        END IF;
65034 
65035       --
65036       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
65037       --
65038       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
65039           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
65040       ELSE
65041           ---------------------------------------------------------------------------------------------------
65042           -- 4262811a Switch Sign
65043           ---------------------------------------------------------------------------------------------------
65044           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
65045           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
65046                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
65047           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
65048                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
65049           -- 5132302
65050           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
65051                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
65052 
65053       END IF;
65054 
65055       -- 4955764
65056       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
65057       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
65058 
65059 
65060       XLA_AE_LINES_PKG.ValidateCurrentLine;
65061       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
65062 
65063       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
65064                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
65065                ,p_balance_type_code => l_balance_type_code);
65066 
65067    END IF;
65068 
65069    -----------------------------------------------------------------------------------------
65070    -- 4262811 Multiperiod Accounting
65071    -----------------------------------------------------------------------------------------
65075 END IF;
65072      -- No MPA option is assigned.
65073 
65074 
65076 END IF;
65077 --
65078 
65079 --
65080 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
65081    trace
65082       (p_msg      => 'END of AcctLineType_244'
65083       ,p_level    => C_LEVEL_PROCEDURE
65084       ,p_module   => l_log_module);
65085 END IF;
65086 --
65087 EXCEPTION
65088   WHEN xla_exceptions_pkg.application_exception THEN
65089       RAISE;
65090   WHEN OTHERS THEN
65091        xla_exceptions_pkg.raise_message
65092            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_244');
65093 END AcctLineType_244;
65094 --
65095 
65096 ---------------------------------------
65097 --
65098 -- PRIVATE FUNCTION
65099 --         AcctLineType_245
65100 --
65101 ---------------------------------------
65102 PROCEDURE AcctLineType_245 (
65103   p_application_id        IN NUMBER
65104  ,p_event_id              IN NUMBER
65105  ,p_calculate_acctd_flag  IN VARCHAR2
65106  ,p_calculate_g_l_flag    IN VARCHAR2
65107  ,p_actual_flag           IN OUT VARCHAR2
65108  ,p_balance_type_code     OUT VARCHAR2
65109  ,p_gain_or_loss_ref      OUT VARCHAR2
65110  
65111 --Period Close Date
65112  , p_source_1            IN DATE
65113 --Generated Code Combination Identifier
65114  , p_source_3            IN NUMBER
65115 --CIP Cost Account
65116  , p_source_7            IN VARCHAR2
65117 --Expense Account Code Combination Identifier
65118  , p_source_29            IN NUMBER
65119 --Default Code Combination Identifier
65120  , p_source_30            IN NUMBER
65121 --Adjustment Type
65122  , p_source_35            IN VARCHAR2
65123 --Transaction Header Identifier
65124  , p_source_36            IN NUMBER
65125 --Adjustment Line Identifier
65126  , p_source_37            IN NUMBER
65127 --Distribution Type Code
65128  , p_source_38            IN VARCHAR2
65129 --Entered Amount
65130  , p_source_39            IN NUMBER
65131 --Currency Code
65132  , p_source_40            IN VARCHAR2
65133 --Source Destination Code
65134  , p_source_42            IN VARCHAR2
65135 )
65136 IS
65137 
65138 l_component_type              VARCHAR2(80);
65139 l_component_code              VARCHAR2(30);
65140 l_component_type_code         VARCHAR2(1);
65141 l_component_appl_id           INTEGER;
65142 l_amb_context_code            VARCHAR2(30);
65143 l_entity_code                 VARCHAR2(30);
65144 l_event_class_code            VARCHAR2(30);
65145 l_ae_header_id                NUMBER;
65146 l_event_type_code             VARCHAR2(30);
65147 l_line_definition_code        VARCHAR2(30);
65148 l_line_definition_owner_code  VARCHAR2(1);
65149 --
65150 -- adr variables
65151 l_segment                     VARCHAR2(30);
65152 l_ccid                        NUMBER;
65153 l_adr_transaction_coa_id      NUMBER;
65154 l_adr_accounting_coa_id       NUMBER;
65155 l_adr_flexfield_segment_code  VARCHAR2(30);
65156 l_adr_flex_value_set_id       NUMBER;
65157 l_adr_value_type_code         VARCHAR2(30);
65158 l_adr_value_combination_id    NUMBER;
65159 l_adr_value_segment_code      VARCHAR2(30);
65160 
65161 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
65162 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
65163 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
65164 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
65165 
65166 -- 4262811 Variables ------------------------------------------------------------------------------------------
65167 l_entered_amt_idx             NUMBER;
65168 l_accted_amt_idx              NUMBER;
65169 l_acc_rev_flag                VARCHAR2(1);
65170 l_accrual_line_num            NUMBER;
65171 l_tmp_amt                     NUMBER;
65172 l_acc_rev_natural_side_code   VARCHAR2(1);
65173 
65174 l_num_entries                 NUMBER;
65175 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
65176 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
65177 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
65178 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
65179 l_recog_line_1                NUMBER;
65180 l_recog_line_2                NUMBER;
65181 
65182 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
65183 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
65184 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
65185 
65186 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
65187 
65188 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
65189 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
65190 
65194 --
65191 ---------------------------------------------------------------------------------------------------------------
65192 
65193 
65195 -- bulk performance
65196 --
65197 l_balance_type_code           VARCHAR2(1);
65198 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
65199 l_log_module                  VARCHAR2(240);
65200 
65201 --
65202 -- Upgrade strategy
65203 --
65204 l_actual_upg_option           VARCHAR2(1);
65205 l_enc_upg_option           VARCHAR2(1);
65206 
65207 --
65208 BEGIN
65209 --
65210 IF g_log_enabled THEN
65211       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_245';
65212 END IF;
65213 --
65214 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
65215 
65216       trace
65217          (p_msg      => 'BEGIN of AcctLineType_245'
65218          ,p_level    => C_LEVEL_PROCEDURE
65219          ,p_module   => l_log_module);
65220 
65221 END IF;
65222 --
65223 l_component_type             := 'AMB_JLT';
65224 l_component_code             := 'FA_CIP_TRANSFER_SOURCE_COST';
65225 l_component_type_code        := 'S';
65226 l_component_appl_id          :=  140;
65227 l_amb_context_code           := 'DEFAULT';
65228 l_entity_code                := 'TRANSACTIONS';
65229 l_event_class_code           := 'CIP_TRANSFERS';
65230 l_event_type_code            := 'CIP_TRANSFERS_ALL';
65231 l_line_definition_owner_code := 'S';
65232 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_T12';
65233 --
65234 l_balance_type_code          := 'A';
65235 l_segment                     := NULL;
65236 l_ccid                        := NULL;
65237 l_adr_transaction_coa_id      := NULL;
65238 l_adr_accounting_coa_id       := NULL;
65239 l_adr_flexfield_segment_code  := NULL;
65240 l_adr_flex_value_set_id       := NULL;
65241 l_adr_value_type_code         := NULL;
65242 l_adr_value_combination_id    := NULL;
65243 l_adr_value_segment_code      := NULL;
65244 
65245 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
65246 l_bflow_class_code           := '';    -- 4219869 Business Flow
65247 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
65248 l_budgetary_control_flag     := 'N';
65249 
65250 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
65251 l_bflow_applied_to_amt       := NULL; -- 5132302
65252 l_entered_amt_idx            := NULL;          -- 4262811
65253 l_accted_amt_idx             := NULL;          -- 4262811
65254 l_acc_rev_flag               := NULL;          -- 4262811
65255 l_accrual_line_num           := NULL;          -- 4262811
65256 l_tmp_amt                    := NULL;          -- 4262811
65257 --
65258  
65259 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
65260     l_balance_type_code <> 'B' THEN
65261 IF NVL(p_source_35,'
65262 ') =  'CIP COST' AND 
65263 NVL(p_source_42,'
65264 ') =  'SOURCE'
65265  THEN 
65266 
65267    --
65268    XLA_AE_LINES_PKG.SetNewLine;
65269 
65270    p_balance_type_code          := l_balance_type_code;
65271    -- set the flag so later we will know whether the gain loss line needs to be created
65272    
65273    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
65274      p_actual_flag :='A';
65275    END IF;
65276 
65277    --
65278    -- bulk performance
65279    --
65280    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
65281                                       p_header_num   => 0); -- 4262811
65282    --
65283    -- set accounting line options
65284    --
65285    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
65286            p_natural_side_code          => 'C'
65287          , p_gain_or_loss_flag          => 'N'
65288          , p_gl_transfer_mode_code      => 'S'
65289          , p_acct_entry_type_code       => 'A'
65290          , p_switch_side_flag           => 'Y'
65291          , p_merge_duplicate_code       => 'N'
65292          );
65293    --
65294    l_acc_rev_natural_side_code := 'D';  -- 4262811
65295    -- 
65296    --
65297    -- set accounting line type info
65298    --
65299    xla_ae_lines_pkg.SetAcctLineType
65300       (p_component_type             => l_component_type
65301       ,p_event_type_code            => l_event_type_code
65302       ,p_line_definition_owner_code => l_line_definition_owner_code
65303       ,p_line_definition_code       => l_line_definition_code
65304       ,p_accounting_line_code       => l_component_code
65305       ,p_accounting_line_type_code  => l_component_type_code
65306       ,p_accounting_line_appl_id    => l_component_appl_id
65307       ,p_amb_context_code           => l_amb_context_code
65308       ,p_entity_code                => l_entity_code
65309       ,p_event_class_code           => l_event_class_code);
65310    --
65311    -- set accounting class
65312    --
65313    xla_ae_lines_pkg.SetAcctClass(
65314            p_accounting_class_code  => 'ASSET'
65315          , p_ae_header_id           => l_ae_header_id
65316          );
65317 
65318    --
65319    -- set rounding class
65320    --
65321    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
65322                       'ASSET';
65323 
65324    --
65325    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
65326    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
65327    --
65328    -- bulk performance
65329    --
65330    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
65331 
65332    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
65333       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
65334 
65335    -- 4955764
65339    -- 4458381 Public Sector Enh
65336    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
65337       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
65338 
65340    
65341    --
65342    -- set accounting attributes for the line type
65343    --
65344    l_entered_amt_idx := 4;
65345    l_accted_amt_idx  := 6;
65346    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
65347    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
65348    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
65349    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
65350    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
65351    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
65352    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
65353    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
65354    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
65355    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
65356    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
65357    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
65358    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
65359 
65360    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
65361    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
65362 
65363    ---------------------------------------------------------------------------------------------------------------
65364    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
65365    ---------------------------------------------------------------------------------------------------------------
65366    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
65367 
65368    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
65369    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
65370 
65371    IF xla_accounting_cache_pkg.GetValueChar
65372          (p_source_code         => 'LEDGER_CATEGORY_CODE'
65373          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
65374    AND l_bflow_method_code = 'PRIOR_ENTRY'
65375 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
65376    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
65377          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
65378        )
65379    THEN
65380          xla_ae_lines_pkg.BflowUpgEntry
65381            (p_business_method_code    => l_bflow_method_code
65382            ,p_business_class_code     => l_bflow_class_code
65383            ,p_balance_type            => l_balance_type_code);
65384    ELSE
65385       NULL;
65386 -- No business flow processing for business flow method of NONE.
65387    END IF;
65388 
65389    --
65390    -- call analytical criteria
65391    --
65392    
65393    --
65394    -- call description
65395    --
65396    
65397 xla_ae_lines_pkg.SetLineDescription(
65398    p_ae_header_id => l_ae_header_id
65399   ,p_description  => Description_45 (
65400      p_application_id         => p_application_id
65401    , p_ae_header_id           => l_ae_header_id 
65402 , p_source_1 => p_source_1
65403    )
65404 );
65405 
65406 
65407    --
65408    -- call ADRs
65409    -- Bug 4922099
65410    --
65411    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
65412         (NVL(l_actual_upg_option, 'N') = 'O') OR
65413         (NVL(l_enc_upg_option, 'N') = 'O')
65414       )
65415    THEN
65416    NULL;
65417    --
65418    --
65419    
65420   l_ccid := AcctDerRule_173(
65421            p_application_id           => p_application_id
65422          , p_ae_header_id             => l_ae_header_id 
65423 , p_source_3 => p_source_3
65424 , p_source_30 => p_source_30
65425          , x_transaction_coa_id       => l_adr_transaction_coa_id
65426          , x_accounting_coa_id        => l_adr_accounting_coa_id
65427          , x_value_type_code          => l_adr_value_type_code
65428          , p_side                     => 'NA'
65429    );
65430 
65431    xla_ae_lines_pkg.set_ccid(
65432     p_code_combination_id          => l_ccid
65433   , p_value_type_code              => l_adr_value_type_code
65434   , p_transaction_coa_id           => l_adr_transaction_coa_id
65435   , p_accounting_coa_id            => l_adr_accounting_coa_id
65436   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
65437   , p_adr_type_code                => 'S'
65438   , p_component_type               => l_component_type
65439   , p_component_code               => l_component_code
65440   , p_component_type_code          => l_component_type_code
65441   , p_component_appl_id            => l_component_appl_id
65442   , p_amb_context_code             => l_amb_context_code
65443   , p_side                         => 'NA'
65444   );
65445 
65446 
65447    l_segment := AcctDerRule_146(
65448            p_application_id           => p_application_id
65449          , p_ae_header_id             => l_ae_header_id 
65450 , p_source_3 => p_source_3
65451 , p_source_7 => p_source_7
65452          , x_transaction_coa_id       => l_adr_transaction_coa_id
65453          , x_accounting_coa_id        => l_adr_accounting_coa_id
65454          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
65455          , x_flex_value_set_id        => l_adr_flex_value_set_id
65456          , x_value_type_code          => l_adr_value_type_code
65457          , x_value_combination_id     => l_adr_value_combination_id
65458          , x_value_segment_code       => l_adr_value_segment_code
65459          , p_side                     => 'NA'
65460          , p_override_seg_flag        => 'Y'
65461    );
65465       xla_ae_lines_pkg.set_segment(
65462 
65463    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
65464 
65466           p_to_segment_code         => 'GL_ACCOUNT'
65467         , p_segment_value           => l_segment
65468         , p_from_segment_code       => l_adr_value_segment_code
65469         , p_from_combination_id     => l_adr_value_combination_id
65470         , p_value_type_code         => l_adr_value_type_code
65471         , p_transaction_coa_id      => l_adr_transaction_coa_id
65472         , p_accounting_coa_id       => l_adr_accounting_coa_id
65473         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
65474         , p_flex_value_set_id       => l_adr_flex_value_set_id
65475         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
65476         , p_adr_type_code           => 'S'
65477         , p_component_type          => l_component_type
65478         , p_component_code          => l_component_code
65479         , p_component_type_code     => l_component_type_code
65480         , p_component_appl_id       => l_component_appl_id
65481         , p_amb_context_code        => l_amb_context_code
65482         , p_entity_code             => 'TRANSACTIONS'
65483         , p_event_class_code        => 'CIP_TRANSFERS'
65484         , p_side                    => 'NA'
65485         );
65486 
65487   END IF;
65488 
65489    l_segment := AcctDerRule_168(
65490            p_application_id           => p_application_id
65491          , p_ae_header_id             => l_ae_header_id 
65492 , p_source_3 => p_source_3
65493 , p_source_29 => p_source_29
65494          , x_transaction_coa_id       => l_adr_transaction_coa_id
65495          , x_accounting_coa_id        => l_adr_accounting_coa_id
65496          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
65497          , x_flex_value_set_id        => l_adr_flex_value_set_id
65498          , x_value_type_code          => l_adr_value_type_code
65499          , x_value_combination_id     => l_adr_value_combination_id
65500          , x_value_segment_code       => l_adr_value_segment_code
65501          , p_side                     => 'NA'
65502          , p_override_seg_flag        => 'Y'
65503    );
65504 
65505    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
65506 
65507       xla_ae_lines_pkg.set_segment(
65508           p_to_segment_code         => 'GL_BALANCING'
65509         , p_segment_value           => l_segment
65510         , p_from_segment_code       => l_adr_value_segment_code
65511         , p_from_combination_id     => l_adr_value_combination_id
65512         , p_value_type_code         => l_adr_value_type_code
65513         , p_transaction_coa_id      => l_adr_transaction_coa_id
65514         , p_accounting_coa_id       => l_adr_accounting_coa_id
65515         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
65516         , p_flex_value_set_id       => l_adr_flex_value_set_id
65517         , p_adr_code                => 'FA_EXPENSE_ACCT'
65518         , p_adr_type_code           => 'S'
65519         , p_component_type          => l_component_type
65520         , p_component_code          => l_component_code
65521         , p_component_type_code     => l_component_type_code
65522         , p_component_appl_id       => l_component_appl_id
65523         , p_amb_context_code        => l_amb_context_code
65524         , p_entity_code             => 'TRANSACTIONS'
65525         , p_event_class_code        => 'CIP_TRANSFERS'
65526         , p_side                    => 'NA'
65527         );
65528 
65529   END IF;
65530 
65531    --
65532    --
65533    END IF;
65534    --
65535    -- Bug 4922099
65536    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
65537           (NVL(l_enc_upg_option, 'N') = 'O')
65538         ) AND
65539         (l_bflow_method_code = 'PRIOR_ENTRY')
65540       )
65541    THEN
65542       IF
65543       --
65544       1 = 2
65545       --
65546       THEN
65547       xla_accounting_err_pkg.build_message
65548                                     (p_appli_s_name            => 'XLA'
65549                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
65550                                     ,p_token_1                 => 'LINE_NUMBER'
65551                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
65552                                     ,p_token_2                 => 'LINE_TYPE_NAME'
65553                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
65554                                                                              l_component_type
65555                                                                             ,l_component_code
65556                                                                             ,l_component_type_code
65557                                                                             ,l_component_appl_id
65558                                                                             ,l_amb_context_code
65559                                                                             ,l_entity_code
65560                                                                             ,l_event_class_code
65561                                                                            )
65562                                     ,p_token_3                 => 'OWNER'
65563                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
65564                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
65565                                                                           ,p_lookup_code    => l_component_type_code
65566                                                                          )
65567                                     ,p_token_4                 => 'PRODUCT_NAME'
65568                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
65572                                     ,p_ae_header_id            =>  NULL
65569                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
65570                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
65571                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
65573                                        );
65574 
65575         IF (C_LEVEL_ERROR>= g_log_level) THEN
65576                  trace
65577                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
65578                       ,p_level    => C_LEVEL_ERROR
65579                       ,p_module   => l_log_module);
65580         END IF;
65581       END IF;
65582    END IF;
65583    --
65584    --
65585    ------------------------------------------------------------------------------------------------
65586    -- 4219869 Business Flow
65587    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
65588    -- Prior Entry.  Currently, the following code is always generated.
65589    ------------------------------------------------------------------------------------------------
65590    XLA_AE_LINES_PKG.ValidateCurrentLine;
65591 
65592    ------------------------------------------------------------------------------------
65593    -- 4219869 Business Flow
65594    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
65595    ------------------------------------------------------------------------------------
65596    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
65597 
65598    ----------------------------------------------------------------------------------
65599    -- 4219869 Business Flow
65600    -- Update journal entry status -- Need to generate this within IF <condition>
65601    ----------------------------------------------------------------------------------
65602    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
65603          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
65604          ,p_balance_type_code => l_balance_type_code
65605          );
65606 
65607    -------------------------------------------------------------------------------------------
65608    -- 4262811 - Generate the Accrual Reversal lines
65609    -------------------------------------------------------------------------------------------
65610    BEGIN
65611       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
65612                               (g_array_event(p_event_id).array_value_num('header_index'));
65613       IF l_acc_rev_flag IS NULL THEN
65614          l_acc_rev_flag := 'N';
65615       END IF;
65616    EXCEPTION
65617       WHEN OTHERS THEN
65618          l_acc_rev_flag := 'N';
65619    END;
65620    --
65621    IF (l_acc_rev_flag = 'Y') THEN
65622 
65623        -- 4645092  ------------------------------------------------------------------------------
65624        -- To allow MPA report to determine if it should generate report process
65625        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
65626        ------------------------------------------------------------------------------------------
65627 
65628        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
65629        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
65630    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
65631    -- call ADRs
65632    -- Bug 4922099
65633    --
65634    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
65635         (NVL(l_actual_upg_option, 'N') = 'O') OR
65636         (NVL(l_enc_upg_option, 'N') = 'O')
65637       )
65638    THEN
65639    NULL;
65640    --
65641    --
65642    
65643   l_ccid := AcctDerRule_173(
65644            p_application_id           => p_application_id
65645          , p_ae_header_id             => l_ae_header_id 
65646 , p_source_3 => p_source_3
65647 , p_source_30 => p_source_30
65648          , x_transaction_coa_id       => l_adr_transaction_coa_id
65649          , x_accounting_coa_id        => l_adr_accounting_coa_id
65650          , x_value_type_code          => l_adr_value_type_code
65651          , p_side                     => 'NA'
65652    );
65653 
65654    xla_ae_lines_pkg.set_ccid(
65655     p_code_combination_id          => l_ccid
65656   , p_value_type_code              => l_adr_value_type_code
65657   , p_transaction_coa_id           => l_adr_transaction_coa_id
65658   , p_accounting_coa_id            => l_adr_accounting_coa_id
65659   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
65660   , p_adr_type_code                => 'S'
65661   , p_component_type               => l_component_type
65662   , p_component_code               => l_component_code
65663   , p_component_type_code          => l_component_type_code
65664   , p_component_appl_id            => l_component_appl_id
65665   , p_amb_context_code             => l_amb_context_code
65666   , p_side                         => 'NA'
65667   );
65668 
65669 
65670    l_segment := AcctDerRule_146(
65671            p_application_id           => p_application_id
65672          , p_ae_header_id             => l_ae_header_id 
65673 , p_source_3 => p_source_3
65674 , p_source_7 => p_source_7
65675          , x_transaction_coa_id       => l_adr_transaction_coa_id
65676          , x_accounting_coa_id        => l_adr_accounting_coa_id
65677          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
65678          , x_flex_value_set_id        => l_adr_flex_value_set_id
65679          , x_value_type_code          => l_adr_value_type_code
65680          , x_value_combination_id     => l_adr_value_combination_id
65681          , x_value_segment_code       => l_adr_value_segment_code
65682          , p_side                     => 'NA'
65683          , p_override_seg_flag        => 'Y'
65684    );
65685 
65686    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
65690         , p_segment_value           => l_segment
65687 
65688       xla_ae_lines_pkg.set_segment(
65689           p_to_segment_code         => 'GL_ACCOUNT'
65691         , p_from_segment_code       => l_adr_value_segment_code
65692         , p_from_combination_id     => l_adr_value_combination_id
65693         , p_value_type_code         => l_adr_value_type_code
65694         , p_transaction_coa_id      => l_adr_transaction_coa_id
65695         , p_accounting_coa_id       => l_adr_accounting_coa_id
65696         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
65697         , p_flex_value_set_id       => l_adr_flex_value_set_id
65698         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
65699         , p_adr_type_code           => 'S'
65700         , p_component_type          => l_component_type
65701         , p_component_code          => l_component_code
65702         , p_component_type_code     => l_component_type_code
65703         , p_component_appl_id       => l_component_appl_id
65704         , p_amb_context_code        => l_amb_context_code
65705         , p_entity_code             => 'TRANSACTIONS'
65706         , p_event_class_code        => 'CIP_TRANSFERS'
65707         , p_side                    => 'NA'
65708         );
65709 
65710   END IF;
65711 
65712    l_segment := AcctDerRule_168(
65713            p_application_id           => p_application_id
65714          , p_ae_header_id             => l_ae_header_id 
65715 , p_source_3 => p_source_3
65716 , p_source_29 => p_source_29
65717          , x_transaction_coa_id       => l_adr_transaction_coa_id
65718          , x_accounting_coa_id        => l_adr_accounting_coa_id
65719          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
65720          , x_flex_value_set_id        => l_adr_flex_value_set_id
65721          , x_value_type_code          => l_adr_value_type_code
65722          , x_value_combination_id     => l_adr_value_combination_id
65723          , x_value_segment_code       => l_adr_value_segment_code
65724          , p_side                     => 'NA'
65725          , p_override_seg_flag        => 'Y'
65726    );
65727 
65728    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
65729 
65730       xla_ae_lines_pkg.set_segment(
65731           p_to_segment_code         => 'GL_BALANCING'
65732         , p_segment_value           => l_segment
65733         , p_from_segment_code       => l_adr_value_segment_code
65734         , p_from_combination_id     => l_adr_value_combination_id
65735         , p_value_type_code         => l_adr_value_type_code
65736         , p_transaction_coa_id      => l_adr_transaction_coa_id
65737         , p_accounting_coa_id       => l_adr_accounting_coa_id
65738         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
65739         , p_flex_value_set_id       => l_adr_flex_value_set_id
65740         , p_adr_code                => 'FA_EXPENSE_ACCT'
65741         , p_adr_type_code           => 'S'
65742         , p_component_type          => l_component_type
65743         , p_component_code          => l_component_code
65744         , p_component_type_code     => l_component_type_code
65745         , p_component_appl_id       => l_component_appl_id
65746         , p_amb_context_code        => l_amb_context_code
65747         , p_entity_code             => 'TRANSACTIONS'
65748         , p_event_class_code        => 'CIP_TRANSFERS'
65749         , p_side                    => 'NA'
65750         );
65751 
65752   END IF;
65753 
65754    --
65755    --
65756    END IF;
65757 
65758        --
65759        -- Update the line information that should be overwritten
65760        --
65761        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
65762                                          p_header_num   => 1);
65763        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
65764 
65765        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
65766 
65767        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
65768           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
65769        END IF;
65770 
65771       --
65772       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
65773       --
65774       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
65775           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
65776       ELSE
65777           ---------------------------------------------------------------------------------------------------
65778           -- 4262811a Switch Sign
65779           ---------------------------------------------------------------------------------------------------
65780           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
65781           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
65782                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
65783           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
65784                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
65785           -- 5132302
65786           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
65787                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
65788 
65789       END IF;
65790 
65791       -- 4955764
65792       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
65793       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
65794 
65795 
65796       XLA_AE_LINES_PKG.ValidateCurrentLine;
65797       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
65798 
65802 
65799       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
65800                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
65801                ,p_balance_type_code => l_balance_type_code);
65803    END IF;
65804 
65805    -----------------------------------------------------------------------------------------
65806    -- 4262811 Multiperiod Accounting
65807    -----------------------------------------------------------------------------------------
65808      -- No MPA option is assigned.
65809 
65810 
65811 END IF;
65812 END IF;
65813 --
65814 
65815 --
65816 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
65817    trace
65818       (p_msg      => 'END of AcctLineType_245'
65819       ,p_level    => C_LEVEL_PROCEDURE
65820       ,p_module   => l_log_module);
65821 END IF;
65822 --
65823 EXCEPTION
65824   WHEN xla_exceptions_pkg.application_exception THEN
65825       RAISE;
65826   WHEN OTHERS THEN
65827        xla_exceptions_pkg.raise_message
65828            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_245');
65829 END AcctLineType_245;
65830 --
65831 
65832 ---------------------------------------
65833 --
65834 -- PRIVATE FUNCTION
65835 --         AcctLineType_246
65836 --
65837 ---------------------------------------
65838 PROCEDURE AcctLineType_246 (
65839   p_application_id        IN NUMBER
65840  ,p_event_id              IN NUMBER
65841  ,p_calculate_acctd_flag  IN VARCHAR2
65842  ,p_calculate_g_l_flag    IN VARCHAR2
65843  ,p_actual_flag           IN OUT VARCHAR2
65844  ,p_balance_type_code     OUT VARCHAR2
65845  ,p_gain_or_loss_ref      OUT VARCHAR2
65846  
65847 --Period Close Date
65848  , p_source_1            IN DATE
65849 --Generated Code Combination Identifier
65850  , p_source_3            IN NUMBER
65851 --Revaluation Reserve Account
65852  , p_source_11            IN VARCHAR2
65853 --Generated Offset Code Combination Identifier
65854  , p_source_17            IN NUMBER
65855 --Default Code Combination Identifier
65856  , p_source_30            IN NUMBER
65857 --Adjustment Type
65858  , p_source_35            IN VARCHAR2
65859 --Transaction Header Identifier
65860  , p_source_36            IN NUMBER
65861 --Adjustment Line Identifier
65862  , p_source_37            IN NUMBER
65863 --Distribution Type Code
65864  , p_source_38            IN VARCHAR2
65865 --Entered Amount
65866  , p_source_39            IN NUMBER
65867 --Currency Code
65868  , p_source_40            IN VARCHAR2
65869 --Source Destination Code
65870  , p_source_42            IN VARCHAR2
65871 )
65872 IS
65873 
65874 l_component_type              VARCHAR2(80);
65875 l_component_code              VARCHAR2(30);
65876 l_component_type_code         VARCHAR2(1);
65877 l_component_appl_id           INTEGER;
65878 l_amb_context_code            VARCHAR2(30);
65879 l_entity_code                 VARCHAR2(30);
65880 l_event_class_code            VARCHAR2(30);
65881 l_ae_header_id                NUMBER;
65882 l_event_type_code             VARCHAR2(30);
65883 l_line_definition_code        VARCHAR2(30);
65884 l_line_definition_owner_code  VARCHAR2(1);
65885 --
65886 -- adr variables
65887 l_segment                     VARCHAR2(30);
65888 l_ccid                        NUMBER;
65889 l_adr_transaction_coa_id      NUMBER;
65890 l_adr_accounting_coa_id       NUMBER;
65891 l_adr_flexfield_segment_code  VARCHAR2(30);
65892 l_adr_flex_value_set_id       NUMBER;
65893 l_adr_value_type_code         VARCHAR2(30);
65894 l_adr_value_combination_id    NUMBER;
65895 l_adr_value_segment_code      VARCHAR2(30);
65896 
65897 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
65898 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
65899 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
65900 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
65901 
65902 -- 4262811 Variables ------------------------------------------------------------------------------------------
65903 l_entered_amt_idx             NUMBER;
65904 l_accted_amt_idx              NUMBER;
65905 l_acc_rev_flag                VARCHAR2(1);
65906 l_accrual_line_num            NUMBER;
65907 l_tmp_amt                     NUMBER;
65908 l_acc_rev_natural_side_code   VARCHAR2(1);
65909 
65910 l_num_entries                 NUMBER;
65911 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
65912 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
65913 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
65914 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
65915 l_recog_line_1                NUMBER;
65916 l_recog_line_2                NUMBER;
65917 
65918 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
65919 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
65920 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
65921 
65922 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
65923 
65924 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
65925 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
65926 
65927 ---------------------------------------------------------------------------------------------------------------
65928 
65929 
65930 --
65931 -- bulk performance
65932 --
65933 l_balance_type_code           VARCHAR2(1);
65934 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
65935 l_log_module                  VARCHAR2(240);
65936 
65937 --
65938 -- Upgrade strategy
65939 --
65940 l_actual_upg_option           VARCHAR2(1);
65941 l_enc_upg_option           VARCHAR2(1);
65942 
65943 --
65947       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_246';
65944 BEGIN
65945 --
65946 IF g_log_enabled THEN
65948 END IF;
65949 --
65950 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
65951 
65952       trace
65953          (p_msg      => 'BEGIN of AcctLineType_246'
65954          ,p_level    => C_LEVEL_PROCEDURE
65955          ,p_module   => l_log_module);
65956 
65957 END IF;
65958 --
65959 l_component_type             := 'AMB_JLT';
65960 l_component_code             := 'FA_CIP_TRANSFER_SRC_REVAL_RES';
65961 l_component_type_code        := 'S';
65962 l_component_appl_id          :=  140;
65963 l_amb_context_code           := 'DEFAULT';
65964 l_entity_code                := 'TRANSACTIONS';
65965 l_event_class_code           := 'CIP_TRANSFERS';
65966 l_event_type_code            := 'CIP_TRANSFERS_ALL';
65967 l_line_definition_owner_code := 'S';
65968 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_T12';
65969 --
65970 l_balance_type_code          := 'A';
65971 l_segment                     := NULL;
65972 l_ccid                        := NULL;
65973 l_adr_transaction_coa_id      := NULL;
65974 l_adr_accounting_coa_id       := NULL;
65975 l_adr_flexfield_segment_code  := NULL;
65976 l_adr_flex_value_set_id       := NULL;
65977 l_adr_value_type_code         := NULL;
65978 l_adr_value_combination_id    := NULL;
65979 l_adr_value_segment_code      := NULL;
65980 
65981 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
65982 l_bflow_class_code           := '';    -- 4219869 Business Flow
65983 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
65984 l_budgetary_control_flag     := 'N';
65985 
65986 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
65987 l_bflow_applied_to_amt       := NULL; -- 5132302
65988 l_entered_amt_idx            := NULL;          -- 4262811
65989 l_accted_amt_idx             := NULL;          -- 4262811
65990 l_acc_rev_flag               := NULL;          -- 4262811
65991 l_accrual_line_num           := NULL;          -- 4262811
65992 l_tmp_amt                    := NULL;          -- 4262811
65993 --
65994  
65995 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
65996     l_balance_type_code <> 'B' THEN
65997 IF NVL(p_source_35,'
65998 ') =  'REVAL RESERVE' AND 
65999 NVL(p_source_42,'
66000 ') =  'SOURCE'
66001  THEN 
66002 
66003    --
66004    XLA_AE_LINES_PKG.SetNewLine;
66005 
66006    p_balance_type_code          := l_balance_type_code;
66007    -- set the flag so later we will know whether the gain loss line needs to be created
66008    
66009    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
66010      p_actual_flag :='A';
66011    END IF;
66012 
66013    --
66014    -- bulk performance
66015    --
66016    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
66017                                       p_header_num   => 0); -- 4262811
66018    --
66019    -- set accounting line options
66020    --
66021    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
66022            p_natural_side_code          => 'D'
66023          , p_gain_or_loss_flag          => 'N'
66024          , p_gl_transfer_mode_code      => 'S'
66025          , p_acct_entry_type_code       => 'A'
66026          , p_switch_side_flag           => 'Y'
66027          , p_merge_duplicate_code       => 'N'
66028          );
66029    --
66030    l_acc_rev_natural_side_code := 'C';  -- 4262811
66031    -- 
66032    --
66033    -- set accounting line type info
66034    --
66035    xla_ae_lines_pkg.SetAcctLineType
66036       (p_component_type             => l_component_type
66037       ,p_event_type_code            => l_event_type_code
66038       ,p_line_definition_owner_code => l_line_definition_owner_code
66039       ,p_line_definition_code       => l_line_definition_code
66040       ,p_accounting_line_code       => l_component_code
66041       ,p_accounting_line_type_code  => l_component_type_code
66042       ,p_accounting_line_appl_id    => l_component_appl_id
66043       ,p_amb_context_code           => l_amb_context_code
66044       ,p_entity_code                => l_entity_code
66045       ,p_event_class_code           => l_event_class_code);
66046    --
66047    -- set accounting class
66048    --
66049    xla_ae_lines_pkg.SetAcctClass(
66050            p_accounting_class_code  => 'ASSET'
66051          , p_ae_header_id           => l_ae_header_id
66052          );
66053 
66054    --
66055    -- set rounding class
66056    --
66057    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
66058                       'ASSET';
66059 
66060    --
66061    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
66062    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
66063    --
66064    -- bulk performance
66065    --
66066    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
66067 
66068    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
66069       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
66070 
66071    -- 4955764
66072    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
66073       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
66074 
66075    -- 4458381 Public Sector Enh
66076    
66077    --
66078    -- set accounting attributes for the line type
66079    --
66080    l_entered_amt_idx := 4;
66081    l_accted_amt_idx  := 6;
66082    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
66083    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
66087    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
66084    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
66085    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
66086    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
66088    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
66089    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
66090    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
66091    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
66092    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
66093    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
66094    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
66095 
66096    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
66097    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
66098 
66099    ---------------------------------------------------------------------------------------------------------------
66100    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
66101    ---------------------------------------------------------------------------------------------------------------
66102    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
66103 
66104    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
66105    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
66106 
66107    IF xla_accounting_cache_pkg.GetValueChar
66108          (p_source_code         => 'LEDGER_CATEGORY_CODE'
66109          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
66110    AND l_bflow_method_code = 'PRIOR_ENTRY'
66111 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
66112    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
66113          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
66114        )
66115    THEN
66116          xla_ae_lines_pkg.BflowUpgEntry
66117            (p_business_method_code    => l_bflow_method_code
66118            ,p_business_class_code     => l_bflow_class_code
66119            ,p_balance_type            => l_balance_type_code);
66120    ELSE
66121       NULL;
66122 -- No business flow processing for business flow method of NONE.
66123    END IF;
66124 
66125    --
66126    -- call analytical criteria
66127    --
66128    
66129    --
66130    -- call description
66131    --
66132    
66133 xla_ae_lines_pkg.SetLineDescription(
66134    p_ae_header_id => l_ae_header_id
66135   ,p_description  => Description_48 (
66136      p_application_id         => p_application_id
66137    , p_ae_header_id           => l_ae_header_id 
66138 , p_source_1 => p_source_1
66139    )
66140 );
66141 
66142 
66143    --
66144    -- call ADRs
66145    -- Bug 4922099
66146    --
66147    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
66148         (NVL(l_actual_upg_option, 'N') = 'O') OR
66149         (NVL(l_enc_upg_option, 'N') = 'O')
66150       )
66151    THEN
66152    NULL;
66153    --
66154    --
66155    
66156   l_ccid := AcctDerRule_174(
66157            p_application_id           => p_application_id
66158          , p_ae_header_id             => l_ae_header_id 
66159 , p_source_3 => p_source_3
66160 , p_source_17 => p_source_17
66161 , p_source_30 => p_source_30
66162          , x_transaction_coa_id       => l_adr_transaction_coa_id
66163          , x_accounting_coa_id        => l_adr_accounting_coa_id
66164          , x_value_type_code          => l_adr_value_type_code
66165          , p_side                     => 'NA'
66166    );
66167 
66168    xla_ae_lines_pkg.set_ccid(
66169     p_code_combination_id          => l_ccid
66170   , p_value_type_code              => l_adr_value_type_code
66171   , p_transaction_coa_id           => l_adr_transaction_coa_id
66172   , p_accounting_coa_id            => l_adr_accounting_coa_id
66173   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
66174   , p_adr_type_code                => 'S'
66175   , p_component_type               => l_component_type
66176   , p_component_code               => l_component_code
66177   , p_component_type_code          => l_component_type_code
66178   , p_component_appl_id            => l_component_appl_id
66179   , p_amb_context_code             => l_amb_context_code
66180   , p_side                         => 'NA'
66181   );
66182 
66183 
66184    l_segment := AcctDerRule_150(
66185            p_application_id           => p_application_id
66186          , p_ae_header_id             => l_ae_header_id 
66187 , p_source_3 => p_source_3
66188 , p_source_11 => p_source_11
66189          , x_transaction_coa_id       => l_adr_transaction_coa_id
66190          , x_accounting_coa_id        => l_adr_accounting_coa_id
66191          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
66192          , x_flex_value_set_id        => l_adr_flex_value_set_id
66193          , x_value_type_code          => l_adr_value_type_code
66194          , x_value_combination_id     => l_adr_value_combination_id
66195          , x_value_segment_code       => l_adr_value_segment_code
66196          , p_side                     => 'NA'
66197          , p_override_seg_flag        => 'Y'
66198    );
66199 
66200    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
66201 
66202       xla_ae_lines_pkg.set_segment(
66203           p_to_segment_code         => 'GL_ACCOUNT'
66204         , p_segment_value           => l_segment
66205         , p_from_segment_code       => l_adr_value_segment_code
66206         , p_from_combination_id     => l_adr_value_combination_id
66207         , p_value_type_code         => l_adr_value_type_code
66211         , p_flex_value_set_id       => l_adr_flex_value_set_id
66208         , p_transaction_coa_id      => l_adr_transaction_coa_id
66209         , p_accounting_coa_id       => l_adr_accounting_coa_id
66210         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
66212         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
66213         , p_adr_type_code           => 'S'
66214         , p_component_type          => l_component_type
66215         , p_component_code          => l_component_code
66216         , p_component_type_code     => l_component_type_code
66217         , p_component_appl_id       => l_component_appl_id
66218         , p_amb_context_code        => l_amb_context_code
66219         , p_entity_code             => 'TRANSACTIONS'
66220         , p_event_class_code        => 'CIP_TRANSFERS'
66221         , p_side                    => 'NA'
66222         );
66223 
66224   END IF;
66225 
66226    --
66227    --
66228    END IF;
66229    --
66230    -- Bug 4922099
66231    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
66232           (NVL(l_enc_upg_option, 'N') = 'O')
66233         ) AND
66234         (l_bflow_method_code = 'PRIOR_ENTRY')
66235       )
66236    THEN
66237       IF
66238       --
66239       1 = 2
66240       --
66241       THEN
66242       xla_accounting_err_pkg.build_message
66243                                     (p_appli_s_name            => 'XLA'
66244                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
66245                                     ,p_token_1                 => 'LINE_NUMBER'
66246                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
66247                                     ,p_token_2                 => 'LINE_TYPE_NAME'
66248                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
66249                                                                              l_component_type
66250                                                                             ,l_component_code
66251                                                                             ,l_component_type_code
66252                                                                             ,l_component_appl_id
66253                                                                             ,l_amb_context_code
66254                                                                             ,l_entity_code
66255                                                                             ,l_event_class_code
66256                                                                            )
66257                                     ,p_token_3                 => 'OWNER'
66258                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
66259                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
66260                                                                           ,p_lookup_code    => l_component_type_code
66261                                                                          )
66262                                     ,p_token_4                 => 'PRODUCT_NAME'
66263                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
66264                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
66265                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
66266                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
66267                                     ,p_ae_header_id            =>  NULL
66268                                        );
66269 
66270         IF (C_LEVEL_ERROR>= g_log_level) THEN
66271                  trace
66272                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
66273                       ,p_level    => C_LEVEL_ERROR
66274                       ,p_module   => l_log_module);
66275         END IF;
66276       END IF;
66277    END IF;
66278    --
66279    --
66280    ------------------------------------------------------------------------------------------------
66281    -- 4219869 Business Flow
66282    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
66283    -- Prior Entry.  Currently, the following code is always generated.
66284    ------------------------------------------------------------------------------------------------
66285    XLA_AE_LINES_PKG.ValidateCurrentLine;
66286 
66287    ------------------------------------------------------------------------------------
66288    -- 4219869 Business Flow
66289    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
66290    ------------------------------------------------------------------------------------
66291    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
66292 
66293    ----------------------------------------------------------------------------------
66294    -- 4219869 Business Flow
66295    -- Update journal entry status -- Need to generate this within IF <condition>
66296    ----------------------------------------------------------------------------------
66297    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
66298          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
66299          ,p_balance_type_code => l_balance_type_code
66300          );
66301 
66302    -------------------------------------------------------------------------------------------
66303    -- 4262811 - Generate the Accrual Reversal lines
66304    -------------------------------------------------------------------------------------------
66305    BEGIN
66306       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
66307                               (g_array_event(p_event_id).array_value_num('header_index'));
66308       IF l_acc_rev_flag IS NULL THEN
66309          l_acc_rev_flag := 'N';
66310       END IF;
66314    END;
66311    EXCEPTION
66312       WHEN OTHERS THEN
66313          l_acc_rev_flag := 'N';
66315    --
66316    IF (l_acc_rev_flag = 'Y') THEN
66317 
66318        -- 4645092  ------------------------------------------------------------------------------
66319        -- To allow MPA report to determine if it should generate report process
66320        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
66321        ------------------------------------------------------------------------------------------
66322 
66323        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
66324        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
66325    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
66326    -- call ADRs
66327    -- Bug 4922099
66328    --
66329    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
66330         (NVL(l_actual_upg_option, 'N') = 'O') OR
66331         (NVL(l_enc_upg_option, 'N') = 'O')
66332       )
66333    THEN
66334    NULL;
66335    --
66336    --
66337    
66338   l_ccid := AcctDerRule_174(
66339            p_application_id           => p_application_id
66340          , p_ae_header_id             => l_ae_header_id 
66341 , p_source_3 => p_source_3
66342 , p_source_17 => p_source_17
66343 , p_source_30 => p_source_30
66344          , x_transaction_coa_id       => l_adr_transaction_coa_id
66345          , x_accounting_coa_id        => l_adr_accounting_coa_id
66346          , x_value_type_code          => l_adr_value_type_code
66347          , p_side                     => 'NA'
66348    );
66349 
66350    xla_ae_lines_pkg.set_ccid(
66351     p_code_combination_id          => l_ccid
66352   , p_value_type_code              => l_adr_value_type_code
66353   , p_transaction_coa_id           => l_adr_transaction_coa_id
66354   , p_accounting_coa_id            => l_adr_accounting_coa_id
66355   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
66356   , p_adr_type_code                => 'S'
66357   , p_component_type               => l_component_type
66358   , p_component_code               => l_component_code
66359   , p_component_type_code          => l_component_type_code
66360   , p_component_appl_id            => l_component_appl_id
66361   , p_amb_context_code             => l_amb_context_code
66362   , p_side                         => 'NA'
66363   );
66364 
66365 
66366    l_segment := AcctDerRule_150(
66367            p_application_id           => p_application_id
66368          , p_ae_header_id             => l_ae_header_id 
66369 , p_source_3 => p_source_3
66370 , p_source_11 => p_source_11
66371          , x_transaction_coa_id       => l_adr_transaction_coa_id
66372          , x_accounting_coa_id        => l_adr_accounting_coa_id
66373          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
66374          , x_flex_value_set_id        => l_adr_flex_value_set_id
66375          , x_value_type_code          => l_adr_value_type_code
66376          , x_value_combination_id     => l_adr_value_combination_id
66377          , x_value_segment_code       => l_adr_value_segment_code
66378          , p_side                     => 'NA'
66379          , p_override_seg_flag        => 'Y'
66380    );
66381 
66382    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
66383 
66384       xla_ae_lines_pkg.set_segment(
66385           p_to_segment_code         => 'GL_ACCOUNT'
66386         , p_segment_value           => l_segment
66387         , p_from_segment_code       => l_adr_value_segment_code
66388         , p_from_combination_id     => l_adr_value_combination_id
66389         , p_value_type_code         => l_adr_value_type_code
66390         , p_transaction_coa_id      => l_adr_transaction_coa_id
66391         , p_accounting_coa_id       => l_adr_accounting_coa_id
66392         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
66393         , p_flex_value_set_id       => l_adr_flex_value_set_id
66394         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
66395         , p_adr_type_code           => 'S'
66396         , p_component_type          => l_component_type
66397         , p_component_code          => l_component_code
66398         , p_component_type_code     => l_component_type_code
66399         , p_component_appl_id       => l_component_appl_id
66400         , p_amb_context_code        => l_amb_context_code
66401         , p_entity_code             => 'TRANSACTIONS'
66402         , p_event_class_code        => 'CIP_TRANSFERS'
66403         , p_side                    => 'NA'
66404         );
66405 
66406   END IF;
66407 
66408    --
66409    --
66410    END IF;
66411 
66412        --
66413        -- Update the line information that should be overwritten
66414        --
66415        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
66416                                          p_header_num   => 1);
66417        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
66418 
66419        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
66420 
66421        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
66422           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
66423        END IF;
66424 
66425       --
66426       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
66427       --
66428       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
66429           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
66430       ELSE
66431           ---------------------------------------------------------------------------------------------------
66432           -- 4262811a Switch Sign
66433           ---------------------------------------------------------------------------------------------------
66437           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
66434           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
66435           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
66436                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
66438                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
66439           -- 5132302
66440           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
66441                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
66442 
66443       END IF;
66444 
66445       -- 4955764
66446       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
66447       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
66448 
66449 
66450       XLA_AE_LINES_PKG.ValidateCurrentLine;
66451       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
66452 
66453       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
66454                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
66455                ,p_balance_type_code => l_balance_type_code);
66456 
66457    END IF;
66458 
66459    -----------------------------------------------------------------------------------------
66460    -- 4262811 Multiperiod Accounting
66461    -----------------------------------------------------------------------------------------
66462      -- No MPA option is assigned.
66463 
66464 
66465 END IF;
66466 END IF;
66467 --
66468 
66469 --
66470 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
66471    trace
66472       (p_msg      => 'END of AcctLineType_246'
66473       ,p_level    => C_LEVEL_PROCEDURE
66474       ,p_module   => l_log_module);
66475 END IF;
66476 --
66477 EXCEPTION
66478   WHEN xla_exceptions_pkg.application_exception THEN
66479       RAISE;
66480   WHEN OTHERS THEN
66481        xla_exceptions_pkg.raise_message
66482            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_246');
66483 END AcctLineType_246;
66484 --
66485 
66486 ---------------------------------------
66487 --
66488 -- PRIVATE FUNCTION
66489 --         AcctLineType_247
66490 --
66491 ---------------------------------------
66492 PROCEDURE AcctLineType_247 (
66493   p_application_id        IN NUMBER
66494  ,p_event_id              IN NUMBER
66495  ,p_calculate_acctd_flag  IN VARCHAR2
66496  ,p_calculate_g_l_flag    IN VARCHAR2
66497  ,p_actual_flag           IN OUT VARCHAR2
66498  ,p_balance_type_code     OUT VARCHAR2
66499  ,p_gain_or_loss_ref      OUT VARCHAR2
66500  
66501 --Period Close Date
66502  , p_source_1            IN DATE
66503 --Generated Code Combination Identifier
66504  , p_source_3            IN NUMBER
66505 --CIP Cost Account
66506  , p_source_7            IN VARCHAR2
66507 --Expense Account Code Combination Identifier
66508  , p_source_29            IN NUMBER
66509 --Default Code Combination Identifier
66510  , p_source_30            IN NUMBER
66511 --Adjustment Type
66512  , p_source_35            IN VARCHAR2
66513 --Transaction Header Identifier
66514  , p_source_36            IN NUMBER
66515 --Adjustment Line Identifier
66516  , p_source_37            IN NUMBER
66517 --Distribution Type Code
66518  , p_source_38            IN VARCHAR2
66519 --Entered Amount
66520  , p_source_39            IN NUMBER
66521 --Currency Code
66522  , p_source_40            IN VARCHAR2
66523 --Source Destination Code
66524  , p_source_42            IN VARCHAR2
66525 )
66526 IS
66527 
66528 l_component_type              VARCHAR2(80);
66529 l_component_code              VARCHAR2(30);
66530 l_component_type_code         VARCHAR2(1);
66531 l_component_appl_id           INTEGER;
66532 l_amb_context_code            VARCHAR2(30);
66533 l_entity_code                 VARCHAR2(30);
66534 l_event_class_code            VARCHAR2(30);
66535 l_ae_header_id                NUMBER;
66536 l_event_type_code             VARCHAR2(30);
66537 l_line_definition_code        VARCHAR2(30);
66538 l_line_definition_owner_code  VARCHAR2(1);
66539 --
66540 -- adr variables
66541 l_segment                     VARCHAR2(30);
66542 l_ccid                        NUMBER;
66543 l_adr_transaction_coa_id      NUMBER;
66544 l_adr_accounting_coa_id       NUMBER;
66545 l_adr_flexfield_segment_code  VARCHAR2(30);
66546 l_adr_flex_value_set_id       NUMBER;
66547 l_adr_value_type_code         VARCHAR2(30);
66548 l_adr_value_combination_id    NUMBER;
66549 l_adr_value_segment_code      VARCHAR2(30);
66550 
66551 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
66552 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
66553 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
66554 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
66555 
66556 -- 4262811 Variables ------------------------------------------------------------------------------------------
66557 l_entered_amt_idx             NUMBER;
66558 l_accted_amt_idx              NUMBER;
66559 l_acc_rev_flag                VARCHAR2(1);
66560 l_accrual_line_num            NUMBER;
66561 l_tmp_amt                     NUMBER;
66562 l_acc_rev_natural_side_code   VARCHAR2(1);
66563 
66564 l_num_entries                 NUMBER;
66565 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
66566 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
66567 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
66568 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
66569 l_recog_line_1                NUMBER;
66573 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
66570 l_recog_line_2                NUMBER;
66571 
66572 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
66574 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
66575 
66576 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
66577 
66578 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
66579 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
66580 
66581 ---------------------------------------------------------------------------------------------------------------
66582 
66583 
66584 --
66585 -- bulk performance
66586 --
66587 l_balance_type_code           VARCHAR2(1);
66588 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
66589 l_log_module                  VARCHAR2(240);
66590 
66591 --
66592 -- Upgrade strategy
66593 --
66594 l_actual_upg_option           VARCHAR2(1);
66595 l_enc_upg_option           VARCHAR2(1);
66596 
66597 --
66598 BEGIN
66599 --
66600 IF g_log_enabled THEN
66601       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_247';
66602 END IF;
66603 --
66604 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
66605 
66606       trace
66607          (p_msg      => 'BEGIN of AcctLineType_247'
66608          ,p_level    => C_LEVEL_PROCEDURE
66609          ,p_module   => l_log_module);
66610 
66611 END IF;
66612 --
66613 l_component_type             := 'AMB_JLT';
66614 l_component_code             := 'FA_CIP_UNITADJ_DEST_COST';
66615 l_component_type_code        := 'S';
66616 l_component_appl_id          :=  140;
66617 l_amb_context_code           := 'DEFAULT';
66618 l_entity_code                := 'TRANSACTIONS';
66619 l_event_class_code           := 'CIP_UNIT_ADJUSTMENTS';
66620 l_event_type_code            := 'CIP_UNIT_ADJUSTMENTS_ALL';
66621 l_line_definition_owner_code := 'S';
66622 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_U13';
66623 --
66624 l_balance_type_code          := 'A';
66625 l_segment                     := NULL;
66626 l_ccid                        := NULL;
66627 l_adr_transaction_coa_id      := NULL;
66628 l_adr_accounting_coa_id       := NULL;
66629 l_adr_flexfield_segment_code  := NULL;
66630 l_adr_flex_value_set_id       := NULL;
66631 l_adr_value_type_code         := NULL;
66632 l_adr_value_combination_id    := NULL;
66633 l_adr_value_segment_code      := NULL;
66634 
66635 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
66636 l_bflow_class_code           := '';    -- 4219869 Business Flow
66637 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
66638 l_budgetary_control_flag     := 'N';
66639 
66640 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
66641 l_bflow_applied_to_amt       := NULL; -- 5132302
66642 l_entered_amt_idx            := NULL;          -- 4262811
66643 l_accted_amt_idx             := NULL;          -- 4262811
66644 l_acc_rev_flag               := NULL;          -- 4262811
66645 l_accrual_line_num           := NULL;          -- 4262811
66646 l_tmp_amt                    := NULL;          -- 4262811
66647 --
66648  
66649 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
66650     l_balance_type_code <> 'B' THEN
66651 IF NVL(p_source_35,'
66652 ') =  'CIP COST' AND 
66653 NVL(p_source_42,'
66654 ') =  'DEST'
66655  THEN 
66656 
66657    --
66658    XLA_AE_LINES_PKG.SetNewLine;
66659 
66660    p_balance_type_code          := l_balance_type_code;
66661    -- set the flag so later we will know whether the gain loss line needs to be created
66662    
66663    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
66664      p_actual_flag :='A';
66665    END IF;
66666 
66667    --
66668    -- bulk performance
66669    --
66670    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
66671                                       p_header_num   => 0); -- 4262811
66672    --
66673    -- set accounting line options
66674    --
66675    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
66676            p_natural_side_code          => 'D'
66677          , p_gain_or_loss_flag          => 'N'
66678          , p_gl_transfer_mode_code      => 'S'
66679          , p_acct_entry_type_code       => 'A'
66680          , p_switch_side_flag           => 'Y'
66681          , p_merge_duplicate_code       => 'N'
66682          );
66683    --
66684    l_acc_rev_natural_side_code := 'C';  -- 4262811
66685    -- 
66686    --
66687    -- set accounting line type info
66688    --
66689    xla_ae_lines_pkg.SetAcctLineType
66690       (p_component_type             => l_component_type
66691       ,p_event_type_code            => l_event_type_code
66692       ,p_line_definition_owner_code => l_line_definition_owner_code
66693       ,p_line_definition_code       => l_line_definition_code
66694       ,p_accounting_line_code       => l_component_code
66695       ,p_accounting_line_type_code  => l_component_type_code
66696       ,p_accounting_line_appl_id    => l_component_appl_id
66697       ,p_amb_context_code           => l_amb_context_code
66698       ,p_entity_code                => l_entity_code
66699       ,p_event_class_code           => l_event_class_code);
66700    --
66701    -- set accounting class
66702    --
66703    xla_ae_lines_pkg.SetAcctClass(
66704            p_accounting_class_code  => 'ASSET'
66705          , p_ae_header_id           => l_ae_header_id
66706          );
66707 
66708    --
66709    -- set rounding class
66710    --
66711    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
66712                       'ASSET';
66713 
66714    --
66718    -- bulk performance
66715    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
66716    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
66717    --
66719    --
66720    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
66721 
66722    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
66723       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
66724 
66725    -- 4955764
66726    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
66727       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
66728 
66729    -- 4458381 Public Sector Enh
66730    
66731    --
66732    -- set accounting attributes for the line type
66733    --
66734    l_entered_amt_idx := 4;
66735    l_accted_amt_idx  := 6;
66736    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
66737    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
66738    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
66739    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
66740    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
66741    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
66742    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
66743    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
66744    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
66745    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
66746    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
66747    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
66748    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
66749 
66750    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
66751    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
66752 
66753    ---------------------------------------------------------------------------------------------------------------
66754    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
66755    ---------------------------------------------------------------------------------------------------------------
66756    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
66757 
66758    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
66759    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
66760 
66761    IF xla_accounting_cache_pkg.GetValueChar
66762          (p_source_code         => 'LEDGER_CATEGORY_CODE'
66763          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
66764    AND l_bflow_method_code = 'PRIOR_ENTRY'
66765 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
66766    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
66767          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
66768        )
66769    THEN
66770          xla_ae_lines_pkg.BflowUpgEntry
66771            (p_business_method_code    => l_bflow_method_code
66772            ,p_business_class_code     => l_bflow_class_code
66773            ,p_balance_type            => l_balance_type_code);
66774    ELSE
66775       NULL;
66776 -- No business flow processing for business flow method of NONE.
66777    END IF;
66778 
66779    --
66780    -- call analytical criteria
66781    --
66782    
66783    --
66784    -- call description
66785    --
66786    
66787 xla_ae_lines_pkg.SetLineDescription(
66788    p_ae_header_id => l_ae_header_id
66789   ,p_description  => Description_49 (
66790      p_application_id         => p_application_id
66791    , p_ae_header_id           => l_ae_header_id 
66792 , p_source_1 => p_source_1
66793    )
66794 );
66795 
66796 
66797    --
66798    -- call ADRs
66799    -- Bug 4922099
66800    --
66801    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
66802         (NVL(l_actual_upg_option, 'N') = 'O') OR
66803         (NVL(l_enc_upg_option, 'N') = 'O')
66804       )
66805    THEN
66806    NULL;
66807    --
66808    --
66809    
66810   l_ccid := AcctDerRule_173(
66811            p_application_id           => p_application_id
66812          , p_ae_header_id             => l_ae_header_id 
66813 , p_source_3 => p_source_3
66814 , p_source_30 => p_source_30
66815          , x_transaction_coa_id       => l_adr_transaction_coa_id
66816          , x_accounting_coa_id        => l_adr_accounting_coa_id
66817          , x_value_type_code          => l_adr_value_type_code
66818          , p_side                     => 'NA'
66819    );
66820 
66821    xla_ae_lines_pkg.set_ccid(
66822     p_code_combination_id          => l_ccid
66823   , p_value_type_code              => l_adr_value_type_code
66824   , p_transaction_coa_id           => l_adr_transaction_coa_id
66825   , p_accounting_coa_id            => l_adr_accounting_coa_id
66826   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
66827   , p_adr_type_code                => 'S'
66828   , p_component_type               => l_component_type
66829   , p_component_code               => l_component_code
66830   , p_component_type_code          => l_component_type_code
66831   , p_component_appl_id            => l_component_appl_id
66832   , p_amb_context_code             => l_amb_context_code
66833   , p_side                         => 'NA'
66834   );
66835 
66836 
66837    l_segment := AcctDerRule_146(
66838            p_application_id           => p_application_id
66839          , p_ae_header_id             => l_ae_header_id 
66840 , p_source_3 => p_source_3
66841 , p_source_7 => p_source_7
66845          , x_flex_value_set_id        => l_adr_flex_value_set_id
66842          , x_transaction_coa_id       => l_adr_transaction_coa_id
66843          , x_accounting_coa_id        => l_adr_accounting_coa_id
66844          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
66846          , x_value_type_code          => l_adr_value_type_code
66847          , x_value_combination_id     => l_adr_value_combination_id
66848          , x_value_segment_code       => l_adr_value_segment_code
66849          , p_side                     => 'NA'
66850          , p_override_seg_flag        => 'Y'
66851    );
66852 
66853    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
66854 
66855       xla_ae_lines_pkg.set_segment(
66856           p_to_segment_code         => 'GL_ACCOUNT'
66857         , p_segment_value           => l_segment
66858         , p_from_segment_code       => l_adr_value_segment_code
66859         , p_from_combination_id     => l_adr_value_combination_id
66860         , p_value_type_code         => l_adr_value_type_code
66861         , p_transaction_coa_id      => l_adr_transaction_coa_id
66862         , p_accounting_coa_id       => l_adr_accounting_coa_id
66863         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
66864         , p_flex_value_set_id       => l_adr_flex_value_set_id
66865         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
66866         , p_adr_type_code           => 'S'
66867         , p_component_type          => l_component_type
66868         , p_component_code          => l_component_code
66869         , p_component_type_code     => l_component_type_code
66870         , p_component_appl_id       => l_component_appl_id
66871         , p_amb_context_code        => l_amb_context_code
66872         , p_entity_code             => 'TRANSACTIONS'
66873         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
66874         , p_side                    => 'NA'
66875         );
66876 
66877   END IF;
66878 
66879    l_segment := AcctDerRule_168(
66880            p_application_id           => p_application_id
66881          , p_ae_header_id             => l_ae_header_id 
66882 , p_source_3 => p_source_3
66883 , p_source_29 => p_source_29
66884          , x_transaction_coa_id       => l_adr_transaction_coa_id
66885          , x_accounting_coa_id        => l_adr_accounting_coa_id
66886          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
66887          , x_flex_value_set_id        => l_adr_flex_value_set_id
66888          , x_value_type_code          => l_adr_value_type_code
66889          , x_value_combination_id     => l_adr_value_combination_id
66890          , x_value_segment_code       => l_adr_value_segment_code
66891          , p_side                     => 'NA'
66892          , p_override_seg_flag        => 'Y'
66893    );
66894 
66895    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
66896 
66897       xla_ae_lines_pkg.set_segment(
66898           p_to_segment_code         => 'GL_BALANCING'
66899         , p_segment_value           => l_segment
66900         , p_from_segment_code       => l_adr_value_segment_code
66901         , p_from_combination_id     => l_adr_value_combination_id
66902         , p_value_type_code         => l_adr_value_type_code
66903         , p_transaction_coa_id      => l_adr_transaction_coa_id
66904         , p_accounting_coa_id       => l_adr_accounting_coa_id
66905         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
66906         , p_flex_value_set_id       => l_adr_flex_value_set_id
66907         , p_adr_code                => 'FA_EXPENSE_ACCT'
66908         , p_adr_type_code           => 'S'
66909         , p_component_type          => l_component_type
66910         , p_component_code          => l_component_code
66911         , p_component_type_code     => l_component_type_code
66912         , p_component_appl_id       => l_component_appl_id
66913         , p_amb_context_code        => l_amb_context_code
66914         , p_entity_code             => 'TRANSACTIONS'
66915         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
66916         , p_side                    => 'NA'
66917         );
66918 
66919   END IF;
66920 
66921    --
66922    --
66923    END IF;
66924    --
66925    -- Bug 4922099
66926    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
66927           (NVL(l_enc_upg_option, 'N') = 'O')
66928         ) AND
66929         (l_bflow_method_code = 'PRIOR_ENTRY')
66930       )
66931    THEN
66932       IF
66933       --
66934       1 = 2
66935       --
66936       THEN
66937       xla_accounting_err_pkg.build_message
66938                                     (p_appli_s_name            => 'XLA'
66939                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
66940                                     ,p_token_1                 => 'LINE_NUMBER'
66941                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
66942                                     ,p_token_2                 => 'LINE_TYPE_NAME'
66943                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
66944                                                                              l_component_type
66945                                                                             ,l_component_code
66946                                                                             ,l_component_type_code
66947                                                                             ,l_component_appl_id
66948                                                                             ,l_amb_context_code
66949                                                                             ,l_entity_code
66950                                                                             ,l_event_class_code
66951                                                                            )
66952                                     ,p_token_3                 => 'OWNER'
66956                                                                          )
66953                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
66954                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
66955                                                                           ,p_lookup_code    => l_component_type_code
66957                                     ,p_token_4                 => 'PRODUCT_NAME'
66958                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
66959                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
66960                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
66961                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
66962                                     ,p_ae_header_id            =>  NULL
66963                                        );
66964 
66965         IF (C_LEVEL_ERROR>= g_log_level) THEN
66966                  trace
66967                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
66968                       ,p_level    => C_LEVEL_ERROR
66969                       ,p_module   => l_log_module);
66970         END IF;
66971       END IF;
66972    END IF;
66973    --
66974    --
66975    ------------------------------------------------------------------------------------------------
66976    -- 4219869 Business Flow
66977    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
66978    -- Prior Entry.  Currently, the following code is always generated.
66979    ------------------------------------------------------------------------------------------------
66980    XLA_AE_LINES_PKG.ValidateCurrentLine;
66981 
66982    ------------------------------------------------------------------------------------
66983    -- 4219869 Business Flow
66984    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
66985    ------------------------------------------------------------------------------------
66986    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
66987 
66988    ----------------------------------------------------------------------------------
66989    -- 4219869 Business Flow
66990    -- Update journal entry status -- Need to generate this within IF <condition>
66991    ----------------------------------------------------------------------------------
66992    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
66993          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
66994          ,p_balance_type_code => l_balance_type_code
66995          );
66996 
66997    -------------------------------------------------------------------------------------------
66998    -- 4262811 - Generate the Accrual Reversal lines
66999    -------------------------------------------------------------------------------------------
67000    BEGIN
67001       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
67002                               (g_array_event(p_event_id).array_value_num('header_index'));
67003       IF l_acc_rev_flag IS NULL THEN
67004          l_acc_rev_flag := 'N';
67005       END IF;
67006    EXCEPTION
67007       WHEN OTHERS THEN
67008          l_acc_rev_flag := 'N';
67009    END;
67010    --
67011    IF (l_acc_rev_flag = 'Y') THEN
67012 
67013        -- 4645092  ------------------------------------------------------------------------------
67014        -- To allow MPA report to determine if it should generate report process
67015        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
67016        ------------------------------------------------------------------------------------------
67017 
67018        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
67019        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
67020    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
67021    -- call ADRs
67022    -- Bug 4922099
67023    --
67024    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
67025         (NVL(l_actual_upg_option, 'N') = 'O') OR
67026         (NVL(l_enc_upg_option, 'N') = 'O')
67027       )
67028    THEN
67029    NULL;
67030    --
67031    --
67032    
67033   l_ccid := AcctDerRule_173(
67034            p_application_id           => p_application_id
67035          , p_ae_header_id             => l_ae_header_id 
67036 , p_source_3 => p_source_3
67037 , p_source_30 => p_source_30
67038          , x_transaction_coa_id       => l_adr_transaction_coa_id
67039          , x_accounting_coa_id        => l_adr_accounting_coa_id
67040          , x_value_type_code          => l_adr_value_type_code
67041          , p_side                     => 'NA'
67042    );
67043 
67044    xla_ae_lines_pkg.set_ccid(
67045     p_code_combination_id          => l_ccid
67046   , p_value_type_code              => l_adr_value_type_code
67047   , p_transaction_coa_id           => l_adr_transaction_coa_id
67048   , p_accounting_coa_id            => l_adr_accounting_coa_id
67049   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
67050   , p_adr_type_code                => 'S'
67051   , p_component_type               => l_component_type
67052   , p_component_code               => l_component_code
67053   , p_component_type_code          => l_component_type_code
67054   , p_component_appl_id            => l_component_appl_id
67055   , p_amb_context_code             => l_amb_context_code
67056   , p_side                         => 'NA'
67057   );
67058 
67059 
67060    l_segment := AcctDerRule_146(
67061            p_application_id           => p_application_id
67062          , p_ae_header_id             => l_ae_header_id 
67063 , p_source_3 => p_source_3
67064 , p_source_7 => p_source_7
67065          , x_transaction_coa_id       => l_adr_transaction_coa_id
67069          , x_value_type_code          => l_adr_value_type_code
67066          , x_accounting_coa_id        => l_adr_accounting_coa_id
67067          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
67068          , x_flex_value_set_id        => l_adr_flex_value_set_id
67070          , x_value_combination_id     => l_adr_value_combination_id
67071          , x_value_segment_code       => l_adr_value_segment_code
67072          , p_side                     => 'NA'
67073          , p_override_seg_flag        => 'Y'
67074    );
67075 
67076    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
67077 
67078       xla_ae_lines_pkg.set_segment(
67079           p_to_segment_code         => 'GL_ACCOUNT'
67080         , p_segment_value           => l_segment
67081         , p_from_segment_code       => l_adr_value_segment_code
67082         , p_from_combination_id     => l_adr_value_combination_id
67083         , p_value_type_code         => l_adr_value_type_code
67084         , p_transaction_coa_id      => l_adr_transaction_coa_id
67085         , p_accounting_coa_id       => l_adr_accounting_coa_id
67086         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
67087         , p_flex_value_set_id       => l_adr_flex_value_set_id
67088         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
67089         , p_adr_type_code           => 'S'
67090         , p_component_type          => l_component_type
67091         , p_component_code          => l_component_code
67092         , p_component_type_code     => l_component_type_code
67093         , p_component_appl_id       => l_component_appl_id
67094         , p_amb_context_code        => l_amb_context_code
67095         , p_entity_code             => 'TRANSACTIONS'
67096         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
67097         , p_side                    => 'NA'
67098         );
67099 
67100   END IF;
67101 
67102    l_segment := AcctDerRule_168(
67103            p_application_id           => p_application_id
67104          , p_ae_header_id             => l_ae_header_id 
67105 , p_source_3 => p_source_3
67106 , p_source_29 => p_source_29
67107          , x_transaction_coa_id       => l_adr_transaction_coa_id
67108          , x_accounting_coa_id        => l_adr_accounting_coa_id
67109          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
67110          , x_flex_value_set_id        => l_adr_flex_value_set_id
67111          , x_value_type_code          => l_adr_value_type_code
67112          , x_value_combination_id     => l_adr_value_combination_id
67113          , x_value_segment_code       => l_adr_value_segment_code
67114          , p_side                     => 'NA'
67115          , p_override_seg_flag        => 'Y'
67116    );
67117 
67118    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
67119 
67120       xla_ae_lines_pkg.set_segment(
67121           p_to_segment_code         => 'GL_BALANCING'
67122         , p_segment_value           => l_segment
67123         , p_from_segment_code       => l_adr_value_segment_code
67124         , p_from_combination_id     => l_adr_value_combination_id
67125         , p_value_type_code         => l_adr_value_type_code
67126         , p_transaction_coa_id      => l_adr_transaction_coa_id
67127         , p_accounting_coa_id       => l_adr_accounting_coa_id
67128         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
67129         , p_flex_value_set_id       => l_adr_flex_value_set_id
67130         , p_adr_code                => 'FA_EXPENSE_ACCT'
67131         , p_adr_type_code           => 'S'
67132         , p_component_type          => l_component_type
67133         , p_component_code          => l_component_code
67134         , p_component_type_code     => l_component_type_code
67135         , p_component_appl_id       => l_component_appl_id
67136         , p_amb_context_code        => l_amb_context_code
67137         , p_entity_code             => 'TRANSACTIONS'
67138         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
67139         , p_side                    => 'NA'
67140         );
67141 
67142   END IF;
67143 
67144    --
67145    --
67146    END IF;
67147 
67148        --
67149        -- Update the line information that should be overwritten
67150        --
67151        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
67152                                          p_header_num   => 1);
67153        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
67154 
67155        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
67156 
67157        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
67158           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
67159        END IF;
67160 
67161       --
67162       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
67163       --
67164       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
67165           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
67166       ELSE
67167           ---------------------------------------------------------------------------------------------------
67168           -- 4262811a Switch Sign
67169           ---------------------------------------------------------------------------------------------------
67170           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
67171           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
67172                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
67173           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
67174                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
67175           -- 5132302
67179       END IF;
67176           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
67177                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
67178 
67180 
67181       -- 4955764
67182       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
67183       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
67184 
67185 
67186       XLA_AE_LINES_PKG.ValidateCurrentLine;
67187       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
67188 
67189       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
67190                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
67191                ,p_balance_type_code => l_balance_type_code);
67192 
67193    END IF;
67194 
67195    -----------------------------------------------------------------------------------------
67196    -- 4262811 Multiperiod Accounting
67197    -----------------------------------------------------------------------------------------
67198      -- No MPA option is assigned.
67199 
67200 
67201 END IF;
67202 END IF;
67203 --
67204 
67205 --
67206 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67207    trace
67208       (p_msg      => 'END of AcctLineType_247'
67209       ,p_level    => C_LEVEL_PROCEDURE
67210       ,p_module   => l_log_module);
67211 END IF;
67212 --
67213 EXCEPTION
67214   WHEN xla_exceptions_pkg.application_exception THEN
67215       RAISE;
67216   WHEN OTHERS THEN
67217        xla_exceptions_pkg.raise_message
67218            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_247');
67219 END AcctLineType_247;
67220 --
67221 
67222 ---------------------------------------
67223 --
67224 -- PRIVATE FUNCTION
67225 --         AcctLineType_248
67226 --
67227 ---------------------------------------
67228 PROCEDURE AcctLineType_248 (
67229   p_application_id        IN NUMBER
67230  ,p_event_id              IN NUMBER
67231  ,p_calculate_acctd_flag  IN VARCHAR2
67232  ,p_calculate_g_l_flag    IN VARCHAR2
67233  ,p_actual_flag           IN OUT VARCHAR2
67234  ,p_balance_type_code     OUT VARCHAR2
67235  ,p_gain_or_loss_ref      OUT VARCHAR2
67236  
67237 --Period Close Date
67238  , p_source_1            IN DATE
67239 --Generated Code Combination Identifier
67240  , p_source_3            IN NUMBER
67241 --Revaluation Reserve Account
67242  , p_source_11            IN VARCHAR2
67243 --Generated Offset Code Combination Identifier
67244  , p_source_17            IN NUMBER
67245 --Expense Account Code Combination Identifier
67246  , p_source_29            IN NUMBER
67247 --Default Code Combination Identifier
67248  , p_source_30            IN NUMBER
67249 --Adjustment Type
67250  , p_source_35            IN VARCHAR2
67251 --Transaction Header Identifier
67252  , p_source_36            IN NUMBER
67253 --Adjustment Line Identifier
67254  , p_source_37            IN NUMBER
67255 --Distribution Type Code
67256  , p_source_38            IN VARCHAR2
67257 --Entered Amount
67258  , p_source_39            IN NUMBER
67259 --Currency Code
67260  , p_source_40            IN VARCHAR2
67261 --Source Destination Code
67262  , p_source_42            IN VARCHAR2
67263 )
67264 IS
67265 
67266 l_component_type              VARCHAR2(80);
67267 l_component_code              VARCHAR2(30);
67268 l_component_type_code         VARCHAR2(1);
67269 l_component_appl_id           INTEGER;
67270 l_amb_context_code            VARCHAR2(30);
67271 l_entity_code                 VARCHAR2(30);
67272 l_event_class_code            VARCHAR2(30);
67273 l_ae_header_id                NUMBER;
67274 l_event_type_code             VARCHAR2(30);
67275 l_line_definition_code        VARCHAR2(30);
67276 l_line_definition_owner_code  VARCHAR2(1);
67277 --
67278 -- adr variables
67279 l_segment                     VARCHAR2(30);
67280 l_ccid                        NUMBER;
67281 l_adr_transaction_coa_id      NUMBER;
67282 l_adr_accounting_coa_id       NUMBER;
67283 l_adr_flexfield_segment_code  VARCHAR2(30);
67284 l_adr_flex_value_set_id       NUMBER;
67285 l_adr_value_type_code         VARCHAR2(30);
67286 l_adr_value_combination_id    NUMBER;
67287 l_adr_value_segment_code      VARCHAR2(30);
67288 
67289 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
67290 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
67291 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
67292 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
67293 
67294 -- 4262811 Variables ------------------------------------------------------------------------------------------
67295 l_entered_amt_idx             NUMBER;
67296 l_accted_amt_idx              NUMBER;
67297 l_acc_rev_flag                VARCHAR2(1);
67298 l_accrual_line_num            NUMBER;
67299 l_tmp_amt                     NUMBER;
67300 l_acc_rev_natural_side_code   VARCHAR2(1);
67301 
67302 l_num_entries                 NUMBER;
67303 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
67304 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
67305 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
67306 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
67307 l_recog_line_1                NUMBER;
67308 l_recog_line_2                NUMBER;
67309 
67310 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
67311 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
67312 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
67313 
67314 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
67315 
67319 ---------------------------------------------------------------------------------------------------------------
67316 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
67317 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
67318 
67320 
67321 
67322 --
67323 -- bulk performance
67324 --
67325 l_balance_type_code           VARCHAR2(1);
67326 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
67327 l_log_module                  VARCHAR2(240);
67328 
67329 --
67330 -- Upgrade strategy
67331 --
67332 l_actual_upg_option           VARCHAR2(1);
67333 l_enc_upg_option           VARCHAR2(1);
67334 
67335 --
67336 BEGIN
67337 --
67338 IF g_log_enabled THEN
67339       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_248';
67340 END IF;
67341 --
67342 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67343 
67344       trace
67345          (p_msg      => 'BEGIN of AcctLineType_248'
67346          ,p_level    => C_LEVEL_PROCEDURE
67347          ,p_module   => l_log_module);
67348 
67349 END IF;
67350 --
67351 l_component_type             := 'AMB_JLT';
67352 l_component_code             := 'FA_CIP_UNITADJ_DEST_REVAL_RES';
67353 l_component_type_code        := 'S';
67354 l_component_appl_id          :=  140;
67355 l_amb_context_code           := 'DEFAULT';
67356 l_entity_code                := 'TRANSACTIONS';
67357 l_event_class_code           := 'CIP_UNIT_ADJUSTMENTS';
67358 l_event_type_code            := 'CIP_UNIT_ADJUSTMENTS_ALL';
67359 l_line_definition_owner_code := 'S';
67360 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_U13';
67361 --
67362 l_balance_type_code          := 'A';
67363 l_segment                     := NULL;
67364 l_ccid                        := NULL;
67365 l_adr_transaction_coa_id      := NULL;
67366 l_adr_accounting_coa_id       := NULL;
67367 l_adr_flexfield_segment_code  := NULL;
67368 l_adr_flex_value_set_id       := NULL;
67369 l_adr_value_type_code         := NULL;
67370 l_adr_value_combination_id    := NULL;
67371 l_adr_value_segment_code      := NULL;
67372 
67373 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
67374 l_bflow_class_code           := '';    -- 4219869 Business Flow
67375 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
67376 l_budgetary_control_flag     := 'N';
67377 
67378 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
67379 l_bflow_applied_to_amt       := NULL; -- 5132302
67380 l_entered_amt_idx            := NULL;          -- 4262811
67381 l_accted_amt_idx             := NULL;          -- 4262811
67382 l_acc_rev_flag               := NULL;          -- 4262811
67383 l_accrual_line_num           := NULL;          -- 4262811
67384 l_tmp_amt                    := NULL;          -- 4262811
67385 --
67386  
67387 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
67388     l_balance_type_code <> 'B' THEN
67389 IF NVL(p_source_35,'
67390 ') =  'REVAL RESERVE' AND 
67391 NVL(p_source_42,'
67392 ') =  'DEST'
67393  THEN 
67394 
67395    --
67396    XLA_AE_LINES_PKG.SetNewLine;
67397 
67398    p_balance_type_code          := l_balance_type_code;
67399    -- set the flag so later we will know whether the gain loss line needs to be created
67400    
67401    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
67402      p_actual_flag :='A';
67403    END IF;
67404 
67405    --
67406    -- bulk performance
67407    --
67408    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
67409                                       p_header_num   => 0); -- 4262811
67410    --
67411    -- set accounting line options
67412    --
67413    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
67414            p_natural_side_code          => 'C'
67415          , p_gain_or_loss_flag          => 'N'
67416          , p_gl_transfer_mode_code      => 'S'
67417          , p_acct_entry_type_code       => 'A'
67418          , p_switch_side_flag           => 'Y'
67419          , p_merge_duplicate_code       => 'N'
67420          );
67421    --
67422    l_acc_rev_natural_side_code := 'D';  -- 4262811
67423    -- 
67424    --
67425    -- set accounting line type info
67426    --
67427    xla_ae_lines_pkg.SetAcctLineType
67428       (p_component_type             => l_component_type
67429       ,p_event_type_code            => l_event_type_code
67430       ,p_line_definition_owner_code => l_line_definition_owner_code
67431       ,p_line_definition_code       => l_line_definition_code
67432       ,p_accounting_line_code       => l_component_code
67433       ,p_accounting_line_type_code  => l_component_type_code
67434       ,p_accounting_line_appl_id    => l_component_appl_id
67435       ,p_amb_context_code           => l_amb_context_code
67436       ,p_entity_code                => l_entity_code
67437       ,p_event_class_code           => l_event_class_code);
67438    --
67439    -- set accounting class
67440    --
67441    xla_ae_lines_pkg.SetAcctClass(
67442            p_accounting_class_code  => 'ASSET'
67443          , p_ae_header_id           => l_ae_header_id
67444          );
67445 
67446    --
67447    -- set rounding class
67448    --
67449    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
67450                       'ASSET';
67451 
67452    --
67453    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
67454    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
67455    --
67456    -- bulk performance
67457    --
67458    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
67459 
67463    -- 4955764
67460    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
67461       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
67462 
67464    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
67465       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
67466 
67467    -- 4458381 Public Sector Enh
67468    
67469    --
67470    -- set accounting attributes for the line type
67471    --
67472    l_entered_amt_idx := 4;
67473    l_accted_amt_idx  := 6;
67474    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
67475    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
67476    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
67477    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
67478    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
67479    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
67480    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
67481    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
67482    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
67483    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
67484    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
67485    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
67486    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
67487 
67488    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
67489    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
67490 
67491    ---------------------------------------------------------------------------------------------------------------
67492    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
67493    ---------------------------------------------------------------------------------------------------------------
67494    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
67495 
67496    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
67497    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
67498 
67499    IF xla_accounting_cache_pkg.GetValueChar
67500          (p_source_code         => 'LEDGER_CATEGORY_CODE'
67501          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
67502    AND l_bflow_method_code = 'PRIOR_ENTRY'
67503 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
67504    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
67505          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
67506        )
67507    THEN
67508          xla_ae_lines_pkg.BflowUpgEntry
67509            (p_business_method_code    => l_bflow_method_code
67510            ,p_business_class_code     => l_bflow_class_code
67511            ,p_balance_type            => l_balance_type_code);
67512    ELSE
67513       NULL;
67514 -- No business flow processing for business flow method of NONE.
67515    END IF;
67516 
67517    --
67518    -- call analytical criteria
67519    --
67520    
67521    --
67522    -- call description
67523    --
67524    
67525 xla_ae_lines_pkg.SetLineDescription(
67526    p_ae_header_id => l_ae_header_id
67527   ,p_description  => Description_52 (
67528      p_application_id         => p_application_id
67529    , p_ae_header_id           => l_ae_header_id 
67530 , p_source_1 => p_source_1
67531    )
67532 );
67533 
67534 
67535    --
67536    -- call ADRs
67537    -- Bug 4922099
67538    --
67539    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
67540         (NVL(l_actual_upg_option, 'N') = 'O') OR
67541         (NVL(l_enc_upg_option, 'N') = 'O')
67542       )
67543    THEN
67544    NULL;
67545    --
67546    --
67547    
67548   l_ccid := AcctDerRule_174(
67549            p_application_id           => p_application_id
67550          , p_ae_header_id             => l_ae_header_id 
67551 , p_source_3 => p_source_3
67552 , p_source_17 => p_source_17
67553 , p_source_30 => p_source_30
67554          , x_transaction_coa_id       => l_adr_transaction_coa_id
67555          , x_accounting_coa_id        => l_adr_accounting_coa_id
67556          , x_value_type_code          => l_adr_value_type_code
67557          , p_side                     => 'NA'
67558    );
67559 
67560    xla_ae_lines_pkg.set_ccid(
67561     p_code_combination_id          => l_ccid
67562   , p_value_type_code              => l_adr_value_type_code
67563   , p_transaction_coa_id           => l_adr_transaction_coa_id
67564   , p_accounting_coa_id            => l_adr_accounting_coa_id
67565   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
67566   , p_adr_type_code                => 'S'
67567   , p_component_type               => l_component_type
67568   , p_component_code               => l_component_code
67569   , p_component_type_code          => l_component_type_code
67570   , p_component_appl_id            => l_component_appl_id
67571   , p_amb_context_code             => l_amb_context_code
67572   , p_side                         => 'NA'
67573   );
67574 
67575 
67576    l_segment := AcctDerRule_150(
67577            p_application_id           => p_application_id
67578          , p_ae_header_id             => l_ae_header_id 
67579 , p_source_3 => p_source_3
67580 , p_source_11 => p_source_11
67581          , x_transaction_coa_id       => l_adr_transaction_coa_id
67582          , x_accounting_coa_id        => l_adr_accounting_coa_id
67583          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
67584          , x_flex_value_set_id        => l_adr_flex_value_set_id
67585          , x_value_type_code          => l_adr_value_type_code
67589          , p_override_seg_flag        => 'Y'
67586          , x_value_combination_id     => l_adr_value_combination_id
67587          , x_value_segment_code       => l_adr_value_segment_code
67588          , p_side                     => 'NA'
67590    );
67591 
67592    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
67593 
67594       xla_ae_lines_pkg.set_segment(
67595           p_to_segment_code         => 'GL_ACCOUNT'
67596         , p_segment_value           => l_segment
67597         , p_from_segment_code       => l_adr_value_segment_code
67598         , p_from_combination_id     => l_adr_value_combination_id
67599         , p_value_type_code         => l_adr_value_type_code
67600         , p_transaction_coa_id      => l_adr_transaction_coa_id
67601         , p_accounting_coa_id       => l_adr_accounting_coa_id
67602         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
67603         , p_flex_value_set_id       => l_adr_flex_value_set_id
67604         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
67605         , p_adr_type_code           => 'S'
67606         , p_component_type          => l_component_type
67607         , p_component_code          => l_component_code
67608         , p_component_type_code     => l_component_type_code
67609         , p_component_appl_id       => l_component_appl_id
67610         , p_amb_context_code        => l_amb_context_code
67611         , p_entity_code             => 'TRANSACTIONS'
67612         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
67613         , p_side                    => 'NA'
67614         );
67615 
67616   END IF;
67617 
67618    l_segment := AcctDerRule_168(
67619            p_application_id           => p_application_id
67620          , p_ae_header_id             => l_ae_header_id 
67621 , p_source_3 => p_source_3
67622 , p_source_29 => p_source_29
67623          , x_transaction_coa_id       => l_adr_transaction_coa_id
67624          , x_accounting_coa_id        => l_adr_accounting_coa_id
67625          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
67626          , x_flex_value_set_id        => l_adr_flex_value_set_id
67627          , x_value_type_code          => l_adr_value_type_code
67628          , x_value_combination_id     => l_adr_value_combination_id
67629          , x_value_segment_code       => l_adr_value_segment_code
67630          , p_side                     => 'NA'
67631          , p_override_seg_flag        => 'Y'
67632    );
67633 
67634    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
67635 
67636       xla_ae_lines_pkg.set_segment(
67637           p_to_segment_code         => 'GL_BALANCING'
67638         , p_segment_value           => l_segment
67639         , p_from_segment_code       => l_adr_value_segment_code
67640         , p_from_combination_id     => l_adr_value_combination_id
67641         , p_value_type_code         => l_adr_value_type_code
67642         , p_transaction_coa_id      => l_adr_transaction_coa_id
67643         , p_accounting_coa_id       => l_adr_accounting_coa_id
67644         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
67645         , p_flex_value_set_id       => l_adr_flex_value_set_id
67646         , p_adr_code                => 'FA_EXPENSE_ACCT'
67647         , p_adr_type_code           => 'S'
67648         , p_component_type          => l_component_type
67649         , p_component_code          => l_component_code
67650         , p_component_type_code     => l_component_type_code
67651         , p_component_appl_id       => l_component_appl_id
67652         , p_amb_context_code        => l_amb_context_code
67653         , p_entity_code             => 'TRANSACTIONS'
67654         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
67655         , p_side                    => 'NA'
67656         );
67657 
67658   END IF;
67659 
67660    --
67661    --
67662    END IF;
67663    --
67664    -- Bug 4922099
67665    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
67666           (NVL(l_enc_upg_option, 'N') = 'O')
67667         ) AND
67668         (l_bflow_method_code = 'PRIOR_ENTRY')
67669       )
67670    THEN
67671       IF
67672       --
67673       1 = 2
67674       --
67675       THEN
67676       xla_accounting_err_pkg.build_message
67677                                     (p_appli_s_name            => 'XLA'
67678                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
67679                                     ,p_token_1                 => 'LINE_NUMBER'
67680                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
67681                                     ,p_token_2                 => 'LINE_TYPE_NAME'
67682                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
67683                                                                              l_component_type
67684                                                                             ,l_component_code
67685                                                                             ,l_component_type_code
67686                                                                             ,l_component_appl_id
67687                                                                             ,l_amb_context_code
67688                                                                             ,l_entity_code
67689                                                                             ,l_event_class_code
67690                                                                            )
67691                                     ,p_token_3                 => 'OWNER'
67692                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
67693                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
67694                                                                           ,p_lookup_code    => l_component_type_code
67695                                                                          )
67699                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
67696                                     ,p_token_4                 => 'PRODUCT_NAME'
67697                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
67698                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
67700                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
67701                                     ,p_ae_header_id            =>  NULL
67702                                        );
67703 
67704         IF (C_LEVEL_ERROR>= g_log_level) THEN
67705                  trace
67706                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
67707                       ,p_level    => C_LEVEL_ERROR
67708                       ,p_module   => l_log_module);
67709         END IF;
67710       END IF;
67711    END IF;
67712    --
67713    --
67714    ------------------------------------------------------------------------------------------------
67715    -- 4219869 Business Flow
67716    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
67717    -- Prior Entry.  Currently, the following code is always generated.
67718    ------------------------------------------------------------------------------------------------
67719    XLA_AE_LINES_PKG.ValidateCurrentLine;
67720 
67721    ------------------------------------------------------------------------------------
67722    -- 4219869 Business Flow
67723    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
67724    ------------------------------------------------------------------------------------
67725    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
67726 
67727    ----------------------------------------------------------------------------------
67728    -- 4219869 Business Flow
67729    -- Update journal entry status -- Need to generate this within IF <condition>
67730    ----------------------------------------------------------------------------------
67731    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
67732          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
67733          ,p_balance_type_code => l_balance_type_code
67734          );
67735 
67736    -------------------------------------------------------------------------------------------
67737    -- 4262811 - Generate the Accrual Reversal lines
67738    -------------------------------------------------------------------------------------------
67739    BEGIN
67740       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
67741                               (g_array_event(p_event_id).array_value_num('header_index'));
67742       IF l_acc_rev_flag IS NULL THEN
67743          l_acc_rev_flag := 'N';
67744       END IF;
67745    EXCEPTION
67746       WHEN OTHERS THEN
67747          l_acc_rev_flag := 'N';
67748    END;
67749    --
67750    IF (l_acc_rev_flag = 'Y') THEN
67751 
67752        -- 4645092  ------------------------------------------------------------------------------
67753        -- To allow MPA report to determine if it should generate report process
67754        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
67755        ------------------------------------------------------------------------------------------
67756 
67757        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
67758        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
67759    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
67760    -- call ADRs
67761    -- Bug 4922099
67762    --
67763    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
67764         (NVL(l_actual_upg_option, 'N') = 'O') OR
67765         (NVL(l_enc_upg_option, 'N') = 'O')
67766       )
67767    THEN
67768    NULL;
67769    --
67770    --
67771    
67772   l_ccid := AcctDerRule_174(
67773            p_application_id           => p_application_id
67774          , p_ae_header_id             => l_ae_header_id 
67775 , p_source_3 => p_source_3
67776 , p_source_17 => p_source_17
67777 , p_source_30 => p_source_30
67778          , x_transaction_coa_id       => l_adr_transaction_coa_id
67779          , x_accounting_coa_id        => l_adr_accounting_coa_id
67780          , x_value_type_code          => l_adr_value_type_code
67781          , p_side                     => 'NA'
67782    );
67783 
67784    xla_ae_lines_pkg.set_ccid(
67785     p_code_combination_id          => l_ccid
67786   , p_value_type_code              => l_adr_value_type_code
67787   , p_transaction_coa_id           => l_adr_transaction_coa_id
67788   , p_accounting_coa_id            => l_adr_accounting_coa_id
67789   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
67790   , p_adr_type_code                => 'S'
67791   , p_component_type               => l_component_type
67792   , p_component_code               => l_component_code
67793   , p_component_type_code          => l_component_type_code
67794   , p_component_appl_id            => l_component_appl_id
67795   , p_amb_context_code             => l_amb_context_code
67796   , p_side                         => 'NA'
67797   );
67798 
67799 
67800    l_segment := AcctDerRule_150(
67801            p_application_id           => p_application_id
67802          , p_ae_header_id             => l_ae_header_id 
67803 , p_source_3 => p_source_3
67804 , p_source_11 => p_source_11
67805          , x_transaction_coa_id       => l_adr_transaction_coa_id
67806          , x_accounting_coa_id        => l_adr_accounting_coa_id
67807          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
67808          , x_flex_value_set_id        => l_adr_flex_value_set_id
67809          , x_value_type_code          => l_adr_value_type_code
67810          , x_value_combination_id     => l_adr_value_combination_id
67814    );
67811          , x_value_segment_code       => l_adr_value_segment_code
67812          , p_side                     => 'NA'
67813          , p_override_seg_flag        => 'Y'
67815 
67816    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
67817 
67818       xla_ae_lines_pkg.set_segment(
67819           p_to_segment_code         => 'GL_ACCOUNT'
67820         , p_segment_value           => l_segment
67821         , p_from_segment_code       => l_adr_value_segment_code
67822         , p_from_combination_id     => l_adr_value_combination_id
67823         , p_value_type_code         => l_adr_value_type_code
67824         , p_transaction_coa_id      => l_adr_transaction_coa_id
67825         , p_accounting_coa_id       => l_adr_accounting_coa_id
67826         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
67827         , p_flex_value_set_id       => l_adr_flex_value_set_id
67828         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
67829         , p_adr_type_code           => 'S'
67830         , p_component_type          => l_component_type
67831         , p_component_code          => l_component_code
67832         , p_component_type_code     => l_component_type_code
67833         , p_component_appl_id       => l_component_appl_id
67834         , p_amb_context_code        => l_amb_context_code
67835         , p_entity_code             => 'TRANSACTIONS'
67836         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
67837         , p_side                    => 'NA'
67838         );
67839 
67840   END IF;
67841 
67842    l_segment := AcctDerRule_168(
67843            p_application_id           => p_application_id
67844          , p_ae_header_id             => l_ae_header_id 
67845 , p_source_3 => p_source_3
67846 , p_source_29 => p_source_29
67847          , x_transaction_coa_id       => l_adr_transaction_coa_id
67848          , x_accounting_coa_id        => l_adr_accounting_coa_id
67849          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
67850          , x_flex_value_set_id        => l_adr_flex_value_set_id
67851          , x_value_type_code          => l_adr_value_type_code
67852          , x_value_combination_id     => l_adr_value_combination_id
67853          , x_value_segment_code       => l_adr_value_segment_code
67854          , p_side                     => 'NA'
67855          , p_override_seg_flag        => 'Y'
67856    );
67857 
67858    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
67859 
67860       xla_ae_lines_pkg.set_segment(
67861           p_to_segment_code         => 'GL_BALANCING'
67862         , p_segment_value           => l_segment
67863         , p_from_segment_code       => l_adr_value_segment_code
67864         , p_from_combination_id     => l_adr_value_combination_id
67865         , p_value_type_code         => l_adr_value_type_code
67866         , p_transaction_coa_id      => l_adr_transaction_coa_id
67867         , p_accounting_coa_id       => l_adr_accounting_coa_id
67868         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
67869         , p_flex_value_set_id       => l_adr_flex_value_set_id
67870         , p_adr_code                => 'FA_EXPENSE_ACCT'
67871         , p_adr_type_code           => 'S'
67872         , p_component_type          => l_component_type
67873         , p_component_code          => l_component_code
67874         , p_component_type_code     => l_component_type_code
67875         , p_component_appl_id       => l_component_appl_id
67876         , p_amb_context_code        => l_amb_context_code
67877         , p_entity_code             => 'TRANSACTIONS'
67878         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
67879         , p_side                    => 'NA'
67880         );
67881 
67882   END IF;
67883 
67884    --
67885    --
67886    END IF;
67887 
67888        --
67889        -- Update the line information that should be overwritten
67890        --
67891        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
67892                                          p_header_num   => 1);
67893        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
67894 
67895        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
67896 
67897        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
67898           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
67899        END IF;
67900 
67901       --
67902       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
67903       --
67904       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
67905           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
67906       ELSE
67907           ---------------------------------------------------------------------------------------------------
67908           -- 4262811a Switch Sign
67909           ---------------------------------------------------------------------------------------------------
67910           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
67911           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
67912                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
67913           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
67914                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
67915           -- 5132302
67916           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
67917                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
67918 
67919       END IF;
67920 
67921       -- 4955764
67925 
67922       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
67923       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
67924 
67926       XLA_AE_LINES_PKG.ValidateCurrentLine;
67927       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
67928 
67929       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
67930                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
67931                ,p_balance_type_code => l_balance_type_code);
67932 
67933    END IF;
67934 
67935    -----------------------------------------------------------------------------------------
67936    -- 4262811 Multiperiod Accounting
67937    -----------------------------------------------------------------------------------------
67938      -- No MPA option is assigned.
67939 
67940 
67941 END IF;
67942 END IF;
67943 --
67944 
67945 --
67946 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67947    trace
67948       (p_msg      => 'END of AcctLineType_248'
67949       ,p_level    => C_LEVEL_PROCEDURE
67950       ,p_module   => l_log_module);
67951 END IF;
67952 --
67953 EXCEPTION
67954   WHEN xla_exceptions_pkg.application_exception THEN
67955       RAISE;
67956   WHEN OTHERS THEN
67957        xla_exceptions_pkg.raise_message
67958            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_248');
67959 END AcctLineType_248;
67960 --
67961 
67962 ---------------------------------------
67963 --
67964 -- PRIVATE FUNCTION
67965 --         AcctLineType_249
67966 --
67967 ---------------------------------------
67968 PROCEDURE AcctLineType_249 (
67969   p_application_id        IN NUMBER
67970  ,p_event_id              IN NUMBER
67971  ,p_calculate_acctd_flag  IN VARCHAR2
67972  ,p_calculate_g_l_flag    IN VARCHAR2
67973  ,p_actual_flag           IN OUT VARCHAR2
67974  ,p_balance_type_code     OUT VARCHAR2
67975  ,p_gain_or_loss_ref      OUT VARCHAR2
67976  
67977 --Period Close Date
67978  , p_source_1            IN DATE
67979 --Generated Code Combination Identifier
67980  , p_source_3            IN NUMBER
67981 --Intercompany Payables Account
67982  , p_source_19            IN VARCHAR2
67983 --Expense Account Code Combination Identifier
67984  , p_source_29            IN NUMBER
67985 --Default Code Combination Identifier
67986  , p_source_30            IN NUMBER
67987 --Adjustment Type
67988  , p_source_35            IN VARCHAR2
67989 --Transaction Header Identifier
67990  , p_source_36            IN NUMBER
67991 --Adjustment Line Identifier
67992  , p_source_37            IN NUMBER
67993 --Distribution Type Code
67994  , p_source_38            IN VARCHAR2
67995 --Entered Amount
67996  , p_source_39            IN NUMBER
67997 --Currency Code
67998  , p_source_40            IN VARCHAR2
67999 )
68000 IS
68001 
68002 l_component_type              VARCHAR2(80);
68003 l_component_code              VARCHAR2(30);
68004 l_component_type_code         VARCHAR2(1);
68005 l_component_appl_id           INTEGER;
68006 l_amb_context_code            VARCHAR2(30);
68007 l_entity_code                 VARCHAR2(30);
68008 l_event_class_code            VARCHAR2(30);
68009 l_ae_header_id                NUMBER;
68010 l_event_type_code             VARCHAR2(30);
68011 l_line_definition_code        VARCHAR2(30);
68012 l_line_definition_owner_code  VARCHAR2(1);
68013 --
68014 -- adr variables
68015 l_segment                     VARCHAR2(30);
68016 l_ccid                        NUMBER;
68017 l_adr_transaction_coa_id      NUMBER;
68018 l_adr_accounting_coa_id       NUMBER;
68019 l_adr_flexfield_segment_code  VARCHAR2(30);
68020 l_adr_flex_value_set_id       NUMBER;
68021 l_adr_value_type_code         VARCHAR2(30);
68022 l_adr_value_combination_id    NUMBER;
68023 l_adr_value_segment_code      VARCHAR2(30);
68024 
68025 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
68026 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
68027 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
68028 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
68029 
68030 -- 4262811 Variables ------------------------------------------------------------------------------------------
68031 l_entered_amt_idx             NUMBER;
68032 l_accted_amt_idx              NUMBER;
68033 l_acc_rev_flag                VARCHAR2(1);
68034 l_accrual_line_num            NUMBER;
68035 l_tmp_amt                     NUMBER;
68036 l_acc_rev_natural_side_code   VARCHAR2(1);
68037 
68038 l_num_entries                 NUMBER;
68039 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
68040 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
68041 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
68042 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
68043 l_recog_line_1                NUMBER;
68044 l_recog_line_2                NUMBER;
68045 
68046 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
68047 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
68048 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
68049 
68050 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
68051 
68052 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
68053 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
68054 
68055 ---------------------------------------------------------------------------------------------------------------
68056 
68057 
68058 --
68059 -- bulk performance
68060 --
68061 l_balance_type_code           VARCHAR2(1);
68065 --
68062 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
68063 l_log_module                  VARCHAR2(240);
68064 
68066 -- Upgrade strategy
68067 --
68068 l_actual_upg_option           VARCHAR2(1);
68069 l_enc_upg_option           VARCHAR2(1);
68070 
68071 --
68072 BEGIN
68073 --
68074 IF g_log_enabled THEN
68075       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_249';
68076 END IF;
68077 --
68078 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
68079 
68080       trace
68081          (p_msg      => 'BEGIN of AcctLineType_249'
68082          ,p_level    => C_LEVEL_PROCEDURE
68083          ,p_module   => l_log_module);
68084 
68085 END IF;
68086 --
68087 l_component_type             := 'AMB_JLT';
68088 l_component_code             := 'FA_CIP_UNITADJ_IC_PAY';
68089 l_component_type_code        := 'S';
68090 l_component_appl_id          :=  140;
68091 l_amb_context_code           := 'DEFAULT';
68092 l_entity_code                := 'TRANSACTIONS';
68093 l_event_class_code           := 'CIP_UNIT_ADJUSTMENTS';
68094 l_event_type_code            := 'CIP_UNIT_ADJUSTMENTS_ALL';
68095 l_line_definition_owner_code := 'S';
68096 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_U13';
68097 --
68098 l_balance_type_code          := 'A';
68099 l_segment                     := NULL;
68100 l_ccid                        := NULL;
68101 l_adr_transaction_coa_id      := NULL;
68102 l_adr_accounting_coa_id       := NULL;
68103 l_adr_flexfield_segment_code  := NULL;
68104 l_adr_flex_value_set_id       := NULL;
68105 l_adr_value_type_code         := NULL;
68106 l_adr_value_combination_id    := NULL;
68107 l_adr_value_segment_code      := NULL;
68108 
68109 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
68110 l_bflow_class_code           := '';    -- 4219869 Business Flow
68111 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
68112 l_budgetary_control_flag     := 'N';
68113 
68114 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
68115 l_bflow_applied_to_amt       := NULL; -- 5132302
68116 l_entered_amt_idx            := NULL;          -- 4262811
68117 l_accted_amt_idx             := NULL;          -- 4262811
68118 l_acc_rev_flag               := NULL;          -- 4262811
68119 l_accrual_line_num           := NULL;          -- 4262811
68120 l_tmp_amt                    := NULL;          -- 4262811
68121 --
68122  
68123 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
68124     l_balance_type_code <> 'B' THEN
68125 IF NVL(p_source_35,'
68126 ') =  'INTERCO AP'
68127  THEN 
68128 
68129    --
68130    XLA_AE_LINES_PKG.SetNewLine;
68131 
68132    p_balance_type_code          := l_balance_type_code;
68133    -- set the flag so later we will know whether the gain loss line needs to be created
68134    
68135    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
68136      p_actual_flag :='A';
68137    END IF;
68138 
68139    --
68140    -- bulk performance
68141    --
68142    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
68143                                       p_header_num   => 0); -- 4262811
68144    --
68145    -- set accounting line options
68146    --
68147    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
68148            p_natural_side_code          => 'C'
68149          , p_gain_or_loss_flag          => 'N'
68150          , p_gl_transfer_mode_code      => 'S'
68151          , p_acct_entry_type_code       => 'A'
68152          , p_switch_side_flag           => 'Y'
68153          , p_merge_duplicate_code       => 'N'
68154          );
68155    --
68156    l_acc_rev_natural_side_code := 'D';  -- 4262811
68157    -- 
68158    --
68159    -- set accounting line type info
68160    --
68161    xla_ae_lines_pkg.SetAcctLineType
68162       (p_component_type             => l_component_type
68163       ,p_event_type_code            => l_event_type_code
68164       ,p_line_definition_owner_code => l_line_definition_owner_code
68165       ,p_line_definition_code       => l_line_definition_code
68166       ,p_accounting_line_code       => l_component_code
68167       ,p_accounting_line_type_code  => l_component_type_code
68168       ,p_accounting_line_appl_id    => l_component_appl_id
68169       ,p_amb_context_code           => l_amb_context_code
68170       ,p_entity_code                => l_entity_code
68171       ,p_event_class_code           => l_event_class_code);
68172    --
68173    -- set accounting class
68174    --
68175    xla_ae_lines_pkg.SetAcctClass(
68176            p_accounting_class_code  => 'LIABILITY'
68177          , p_ae_header_id           => l_ae_header_id
68178          );
68179 
68180    --
68181    -- set rounding class
68182    --
68183    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
68184                       'LIABILITY';
68185 
68186    --
68187    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
68188    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
68189    --
68190    -- bulk performance
68191    --
68192    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
68193 
68194    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
68195       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
68196 
68197    -- 4955764
68198    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
68199       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
68200 
68201    -- 4458381 Public Sector Enh
68202    
68203    --
68207    l_accted_amt_idx  := 6;
68204    -- set accounting attributes for the line type
68205    --
68206    l_entered_amt_idx := 4;
68208    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
68209    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
68210    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
68211    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
68212    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
68213    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
68214    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
68215    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
68216    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
68217    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
68218    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
68219    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
68220    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
68221 
68222    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
68223    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
68224 
68225    ---------------------------------------------------------------------------------------------------------------
68226    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
68227    ---------------------------------------------------------------------------------------------------------------
68228    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
68229 
68230    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
68231    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
68232 
68233    IF xla_accounting_cache_pkg.GetValueChar
68234          (p_source_code         => 'LEDGER_CATEGORY_CODE'
68235          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
68236    AND l_bflow_method_code = 'PRIOR_ENTRY'
68237 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
68238    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
68239          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
68240        )
68241    THEN
68242          xla_ae_lines_pkg.BflowUpgEntry
68243            (p_business_method_code    => l_bflow_method_code
68244            ,p_business_class_code     => l_bflow_class_code
68245            ,p_balance_type            => l_balance_type_code);
68246    ELSE
68247       NULL;
68248 -- No business flow processing for business flow method of NONE.
68249    END IF;
68250 
68251    --
68252    -- call analytical criteria
68253    --
68254    
68255    --
68256    -- call description
68257    --
68258    
68259 xla_ae_lines_pkg.SetLineDescription(
68260    p_ae_header_id => l_ae_header_id
68261   ,p_description  => Description_50 (
68262      p_application_id         => p_application_id
68263    , p_ae_header_id           => l_ae_header_id 
68264 , p_source_1 => p_source_1
68265    )
68266 );
68267 
68268 
68269    --
68270    -- call ADRs
68271    -- Bug 4922099
68272    --
68273    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
68274         (NVL(l_actual_upg_option, 'N') = 'O') OR
68275         (NVL(l_enc_upg_option, 'N') = 'O')
68276       )
68277    THEN
68278    NULL;
68279    --
68280    --
68281    
68282   l_ccid := AcctDerRule_173(
68283            p_application_id           => p_application_id
68284          , p_ae_header_id             => l_ae_header_id 
68285 , p_source_3 => p_source_3
68286 , p_source_30 => p_source_30
68287          , x_transaction_coa_id       => l_adr_transaction_coa_id
68288          , x_accounting_coa_id        => l_adr_accounting_coa_id
68289          , x_value_type_code          => l_adr_value_type_code
68290          , p_side                     => 'NA'
68291    );
68292 
68293    xla_ae_lines_pkg.set_ccid(
68294     p_code_combination_id          => l_ccid
68295   , p_value_type_code              => l_adr_value_type_code
68296   , p_transaction_coa_id           => l_adr_transaction_coa_id
68297   , p_accounting_coa_id            => l_adr_accounting_coa_id
68298   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
68299   , p_adr_type_code                => 'S'
68300   , p_component_type               => l_component_type
68301   , p_component_code               => l_component_code
68302   , p_component_type_code          => l_component_type_code
68303   , p_component_appl_id            => l_component_appl_id
68304   , p_amb_context_code             => l_amb_context_code
68305   , p_side                         => 'NA'
68306   );
68307 
68308 
68309    l_segment := AcctDerRule_168(
68310            p_application_id           => p_application_id
68311          , p_ae_header_id             => l_ae_header_id 
68312 , p_source_3 => p_source_3
68313 , p_source_29 => p_source_29
68314          , x_transaction_coa_id       => l_adr_transaction_coa_id
68315          , x_accounting_coa_id        => l_adr_accounting_coa_id
68316          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
68317          , x_flex_value_set_id        => l_adr_flex_value_set_id
68318          , x_value_type_code          => l_adr_value_type_code
68319          , x_value_combination_id     => l_adr_value_combination_id
68320          , x_value_segment_code       => l_adr_value_segment_code
68321          , p_side                     => 'NA'
68322          , p_override_seg_flag        => 'Y'
68323    );
68324 
68325    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
68326 
68327       xla_ae_lines_pkg.set_segment(
68328           p_to_segment_code         => 'GL_BALANCING'
68329         , p_segment_value           => l_segment
68333         , p_transaction_coa_id      => l_adr_transaction_coa_id
68330         , p_from_segment_code       => l_adr_value_segment_code
68331         , p_from_combination_id     => l_adr_value_combination_id
68332         , p_value_type_code         => l_adr_value_type_code
68334         , p_accounting_coa_id       => l_adr_accounting_coa_id
68335         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
68336         , p_flex_value_set_id       => l_adr_flex_value_set_id
68337         , p_adr_code                => 'FA_EXPENSE_ACCT'
68338         , p_adr_type_code           => 'S'
68339         , p_component_type          => l_component_type
68340         , p_component_code          => l_component_code
68341         , p_component_type_code     => l_component_type_code
68342         , p_component_appl_id       => l_component_appl_id
68343         , p_amb_context_code        => l_amb_context_code
68344         , p_entity_code             => 'TRANSACTIONS'
68345         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
68346         , p_side                    => 'NA'
68347         );
68348 
68349   END IF;
68350 
68351    l_segment := AcctDerRule_157(
68352            p_application_id           => p_application_id
68353          , p_ae_header_id             => l_ae_header_id 
68354 , p_source_3 => p_source_3
68355 , p_source_19 => p_source_19
68356          , x_transaction_coa_id       => l_adr_transaction_coa_id
68357          , x_accounting_coa_id        => l_adr_accounting_coa_id
68358          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
68359          , x_flex_value_set_id        => l_adr_flex_value_set_id
68360          , x_value_type_code          => l_adr_value_type_code
68361          , x_value_combination_id     => l_adr_value_combination_id
68362          , x_value_segment_code       => l_adr_value_segment_code
68363          , p_side                     => 'NA'
68364          , p_override_seg_flag        => 'Y'
68365    );
68366 
68367    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
68368 
68369       xla_ae_lines_pkg.set_segment(
68370           p_to_segment_code         => 'GL_ACCOUNT'
68371         , p_segment_value           => l_segment
68372         , p_from_segment_code       => l_adr_value_segment_code
68373         , p_from_combination_id     => l_adr_value_combination_id
68374         , p_value_type_code         => l_adr_value_type_code
68375         , p_transaction_coa_id      => l_adr_transaction_coa_id
68376         , p_accounting_coa_id       => l_adr_accounting_coa_id
68377         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
68378         , p_flex_value_set_id       => l_adr_flex_value_set_id
68379         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
68380         , p_adr_type_code           => 'S'
68381         , p_component_type          => l_component_type
68382         , p_component_code          => l_component_code
68383         , p_component_type_code     => l_component_type_code
68384         , p_component_appl_id       => l_component_appl_id
68385         , p_amb_context_code        => l_amb_context_code
68386         , p_entity_code             => 'TRANSACTIONS'
68387         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
68388         , p_side                    => 'NA'
68389         );
68390 
68391   END IF;
68392 
68393    --
68394    --
68395    END IF;
68396    --
68397    -- Bug 4922099
68398    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
68399           (NVL(l_enc_upg_option, 'N') = 'O')
68400         ) AND
68401         (l_bflow_method_code = 'PRIOR_ENTRY')
68402       )
68403    THEN
68404       IF
68405       --
68406       1 = 2
68407       --
68408       THEN
68409       xla_accounting_err_pkg.build_message
68410                                     (p_appli_s_name            => 'XLA'
68411                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
68412                                     ,p_token_1                 => 'LINE_NUMBER'
68413                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
68414                                     ,p_token_2                 => 'LINE_TYPE_NAME'
68415                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
68416                                                                              l_component_type
68417                                                                             ,l_component_code
68418                                                                             ,l_component_type_code
68419                                                                             ,l_component_appl_id
68420                                                                             ,l_amb_context_code
68421                                                                             ,l_entity_code
68422                                                                             ,l_event_class_code
68423                                                                            )
68424                                     ,p_token_3                 => 'OWNER'
68425                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
68426                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
68427                                                                           ,p_lookup_code    => l_component_type_code
68428                                                                          )
68429                                     ,p_token_4                 => 'PRODUCT_NAME'
68430                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
68431                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
68432                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
68436 
68433                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
68434                                     ,p_ae_header_id            =>  NULL
68435                                        );
68437         IF (C_LEVEL_ERROR>= g_log_level) THEN
68438                  trace
68439                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
68440                       ,p_level    => C_LEVEL_ERROR
68441                       ,p_module   => l_log_module);
68442         END IF;
68443       END IF;
68444    END IF;
68445    --
68446    --
68447    ------------------------------------------------------------------------------------------------
68448    -- 4219869 Business Flow
68449    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
68450    -- Prior Entry.  Currently, the following code is always generated.
68451    ------------------------------------------------------------------------------------------------
68452    XLA_AE_LINES_PKG.ValidateCurrentLine;
68453 
68454    ------------------------------------------------------------------------------------
68455    -- 4219869 Business Flow
68456    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
68457    ------------------------------------------------------------------------------------
68458    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
68459 
68460    ----------------------------------------------------------------------------------
68461    -- 4219869 Business Flow
68462    -- Update journal entry status -- Need to generate this within IF <condition>
68463    ----------------------------------------------------------------------------------
68464    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
68465          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
68466          ,p_balance_type_code => l_balance_type_code
68467          );
68468 
68469    -------------------------------------------------------------------------------------------
68470    -- 4262811 - Generate the Accrual Reversal lines
68471    -------------------------------------------------------------------------------------------
68472    BEGIN
68473       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
68474                               (g_array_event(p_event_id).array_value_num('header_index'));
68475       IF l_acc_rev_flag IS NULL THEN
68476          l_acc_rev_flag := 'N';
68477       END IF;
68478    EXCEPTION
68479       WHEN OTHERS THEN
68480          l_acc_rev_flag := 'N';
68481    END;
68482    --
68483    IF (l_acc_rev_flag = 'Y') THEN
68484 
68485        -- 4645092  ------------------------------------------------------------------------------
68486        -- To allow MPA report to determine if it should generate report process
68487        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
68488        ------------------------------------------------------------------------------------------
68489 
68490        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
68491        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
68492    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
68493    -- call ADRs
68494    -- Bug 4922099
68495    --
68496    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
68497         (NVL(l_actual_upg_option, 'N') = 'O') OR
68498         (NVL(l_enc_upg_option, 'N') = 'O')
68499       )
68500    THEN
68501    NULL;
68502    --
68503    --
68504    
68505   l_ccid := AcctDerRule_173(
68506            p_application_id           => p_application_id
68507          , p_ae_header_id             => l_ae_header_id 
68508 , p_source_3 => p_source_3
68509 , p_source_30 => p_source_30
68510          , x_transaction_coa_id       => l_adr_transaction_coa_id
68511          , x_accounting_coa_id        => l_adr_accounting_coa_id
68512          , x_value_type_code          => l_adr_value_type_code
68513          , p_side                     => 'NA'
68514    );
68515 
68516    xla_ae_lines_pkg.set_ccid(
68517     p_code_combination_id          => l_ccid
68518   , p_value_type_code              => l_adr_value_type_code
68519   , p_transaction_coa_id           => l_adr_transaction_coa_id
68520   , p_accounting_coa_id            => l_adr_accounting_coa_id
68521   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
68522   , p_adr_type_code                => 'S'
68523   , p_component_type               => l_component_type
68524   , p_component_code               => l_component_code
68525   , p_component_type_code          => l_component_type_code
68526   , p_component_appl_id            => l_component_appl_id
68527   , p_amb_context_code             => l_amb_context_code
68528   , p_side                         => 'NA'
68529   );
68530 
68531 
68532    l_segment := AcctDerRule_168(
68533            p_application_id           => p_application_id
68534          , p_ae_header_id             => l_ae_header_id 
68535 , p_source_3 => p_source_3
68536 , p_source_29 => p_source_29
68537          , x_transaction_coa_id       => l_adr_transaction_coa_id
68538          , x_accounting_coa_id        => l_adr_accounting_coa_id
68539          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
68540          , x_flex_value_set_id        => l_adr_flex_value_set_id
68541          , x_value_type_code          => l_adr_value_type_code
68542          , x_value_combination_id     => l_adr_value_combination_id
68543          , x_value_segment_code       => l_adr_value_segment_code
68544          , p_side                     => 'NA'
68545          , p_override_seg_flag        => 'Y'
68546    );
68547 
68548    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
68549 
68550       xla_ae_lines_pkg.set_segment(
68551           p_to_segment_code         => 'GL_BALANCING'
68552         , p_segment_value           => l_segment
68556         , p_transaction_coa_id      => l_adr_transaction_coa_id
68553         , p_from_segment_code       => l_adr_value_segment_code
68554         , p_from_combination_id     => l_adr_value_combination_id
68555         , p_value_type_code         => l_adr_value_type_code
68557         , p_accounting_coa_id       => l_adr_accounting_coa_id
68558         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
68559         , p_flex_value_set_id       => l_adr_flex_value_set_id
68560         , p_adr_code                => 'FA_EXPENSE_ACCT'
68561         , p_adr_type_code           => 'S'
68562         , p_component_type          => l_component_type
68563         , p_component_code          => l_component_code
68564         , p_component_type_code     => l_component_type_code
68565         , p_component_appl_id       => l_component_appl_id
68566         , p_amb_context_code        => l_amb_context_code
68567         , p_entity_code             => 'TRANSACTIONS'
68568         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
68569         , p_side                    => 'NA'
68570         );
68571 
68572   END IF;
68573 
68574    l_segment := AcctDerRule_157(
68575            p_application_id           => p_application_id
68576          , p_ae_header_id             => l_ae_header_id 
68577 , p_source_3 => p_source_3
68578 , p_source_19 => p_source_19
68579          , x_transaction_coa_id       => l_adr_transaction_coa_id
68580          , x_accounting_coa_id        => l_adr_accounting_coa_id
68581          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
68582          , x_flex_value_set_id        => l_adr_flex_value_set_id
68583          , x_value_type_code          => l_adr_value_type_code
68584          , x_value_combination_id     => l_adr_value_combination_id
68585          , x_value_segment_code       => l_adr_value_segment_code
68586          , p_side                     => 'NA'
68587          , p_override_seg_flag        => 'Y'
68588    );
68589 
68590    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
68591 
68592       xla_ae_lines_pkg.set_segment(
68593           p_to_segment_code         => 'GL_ACCOUNT'
68594         , p_segment_value           => l_segment
68595         , p_from_segment_code       => l_adr_value_segment_code
68596         , p_from_combination_id     => l_adr_value_combination_id
68597         , p_value_type_code         => l_adr_value_type_code
68598         , p_transaction_coa_id      => l_adr_transaction_coa_id
68599         , p_accounting_coa_id       => l_adr_accounting_coa_id
68600         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
68601         , p_flex_value_set_id       => l_adr_flex_value_set_id
68602         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
68603         , p_adr_type_code           => 'S'
68604         , p_component_type          => l_component_type
68605         , p_component_code          => l_component_code
68606         , p_component_type_code     => l_component_type_code
68607         , p_component_appl_id       => l_component_appl_id
68608         , p_amb_context_code        => l_amb_context_code
68609         , p_entity_code             => 'TRANSACTIONS'
68610         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
68611         , p_side                    => 'NA'
68612         );
68613 
68614   END IF;
68615 
68616    --
68617    --
68618    END IF;
68619 
68620        --
68621        -- Update the line information that should be overwritten
68622        --
68623        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
68624                                          p_header_num   => 1);
68625        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
68626 
68627        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
68628 
68629        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
68630           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
68631        END IF;
68632 
68633       --
68634       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
68635       --
68636       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
68637           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
68638       ELSE
68639           ---------------------------------------------------------------------------------------------------
68640           -- 4262811a Switch Sign
68641           ---------------------------------------------------------------------------------------------------
68642           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
68643           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
68644                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
68645           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
68646                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
68647           -- 5132302
68648           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
68649                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
68650 
68651       END IF;
68652 
68653       -- 4955764
68654       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
68655       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
68656 
68657 
68658       XLA_AE_LINES_PKG.ValidateCurrentLine;
68659       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
68660 
68661       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
68662                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
68666 
68663                ,p_balance_type_code => l_balance_type_code);
68664 
68665    END IF;
68667    -----------------------------------------------------------------------------------------
68668    -- 4262811 Multiperiod Accounting
68669    -----------------------------------------------------------------------------------------
68670      -- No MPA option is assigned.
68671 
68672 
68673 END IF;
68674 END IF;
68675 --
68676 
68677 --
68678 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
68679    trace
68680       (p_msg      => 'END of AcctLineType_249'
68681       ,p_level    => C_LEVEL_PROCEDURE
68682       ,p_module   => l_log_module);
68683 END IF;
68684 --
68685 EXCEPTION
68686   WHEN xla_exceptions_pkg.application_exception THEN
68687       RAISE;
68688   WHEN OTHERS THEN
68689        xla_exceptions_pkg.raise_message
68690            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_249');
68691 END AcctLineType_249;
68692 --
68693 
68694 ---------------------------------------
68695 --
68696 -- PRIVATE FUNCTION
68697 --         AcctLineType_250
68698 --
68699 ---------------------------------------
68700 PROCEDURE AcctLineType_250 (
68701   p_application_id        IN NUMBER
68702  ,p_event_id              IN NUMBER
68703  ,p_calculate_acctd_flag  IN VARCHAR2
68704  ,p_calculate_g_l_flag    IN VARCHAR2
68705  ,p_actual_flag           IN OUT VARCHAR2
68706  ,p_balance_type_code     OUT VARCHAR2
68707  ,p_gain_or_loss_ref      OUT VARCHAR2
68708  
68709 --Period Close Date
68710  , p_source_1            IN DATE
68711 --Generated Code Combination Identifier
68712  , p_source_3            IN NUMBER
68713 --Intercompany Receivables Account
68714  , p_source_20            IN VARCHAR2
68715 --Expense Account Code Combination Identifier
68716  , p_source_29            IN NUMBER
68717 --Default Code Combination Identifier
68718  , p_source_30            IN NUMBER
68719 --Adjustment Type
68720  , p_source_35            IN VARCHAR2
68721 --Transaction Header Identifier
68722  , p_source_36            IN NUMBER
68723 --Adjustment Line Identifier
68724  , p_source_37            IN NUMBER
68725 --Distribution Type Code
68726  , p_source_38            IN VARCHAR2
68727 --Entered Amount
68728  , p_source_39            IN NUMBER
68729 --Currency Code
68730  , p_source_40            IN VARCHAR2
68731 )
68732 IS
68733 
68734 l_component_type              VARCHAR2(80);
68735 l_component_code              VARCHAR2(30);
68736 l_component_type_code         VARCHAR2(1);
68737 l_component_appl_id           INTEGER;
68738 l_amb_context_code            VARCHAR2(30);
68739 l_entity_code                 VARCHAR2(30);
68740 l_event_class_code            VARCHAR2(30);
68741 l_ae_header_id                NUMBER;
68742 l_event_type_code             VARCHAR2(30);
68743 l_line_definition_code        VARCHAR2(30);
68744 l_line_definition_owner_code  VARCHAR2(1);
68745 --
68746 -- adr variables
68747 l_segment                     VARCHAR2(30);
68748 l_ccid                        NUMBER;
68749 l_adr_transaction_coa_id      NUMBER;
68750 l_adr_accounting_coa_id       NUMBER;
68751 l_adr_flexfield_segment_code  VARCHAR2(30);
68752 l_adr_flex_value_set_id       NUMBER;
68753 l_adr_value_type_code         VARCHAR2(30);
68754 l_adr_value_combination_id    NUMBER;
68755 l_adr_value_segment_code      VARCHAR2(30);
68756 
68757 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
68758 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
68759 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
68760 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
68761 
68762 -- 4262811 Variables ------------------------------------------------------------------------------------------
68763 l_entered_amt_idx             NUMBER;
68764 l_accted_amt_idx              NUMBER;
68765 l_acc_rev_flag                VARCHAR2(1);
68766 l_accrual_line_num            NUMBER;
68767 l_tmp_amt                     NUMBER;
68768 l_acc_rev_natural_side_code   VARCHAR2(1);
68769 
68770 l_num_entries                 NUMBER;
68771 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
68772 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
68773 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
68774 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
68775 l_recog_line_1                NUMBER;
68776 l_recog_line_2                NUMBER;
68777 
68778 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
68779 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
68780 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
68781 
68782 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
68783 
68784 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
68785 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
68786 
68787 ---------------------------------------------------------------------------------------------------------------
68788 
68789 
68790 --
68791 -- bulk performance
68792 --
68793 l_balance_type_code           VARCHAR2(1);
68794 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
68795 l_log_module                  VARCHAR2(240);
68796 
68797 --
68798 -- Upgrade strategy
68799 --
68800 l_actual_upg_option           VARCHAR2(1);
68801 l_enc_upg_option           VARCHAR2(1);
68802 
68803 --
68804 BEGIN
68805 --
68806 IF g_log_enabled THEN
68807       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_250';
68808 END IF;
68809 --
68810 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
68811 
68815          ,p_module   => l_log_module);
68812       trace
68813          (p_msg      => 'BEGIN of AcctLineType_250'
68814          ,p_level    => C_LEVEL_PROCEDURE
68816 
68817 END IF;
68818 --
68819 l_component_type             := 'AMB_JLT';
68820 l_component_code             := 'FA_CIP_UNITADJ_IC_REC';
68821 l_component_type_code        := 'S';
68822 l_component_appl_id          :=  140;
68823 l_amb_context_code           := 'DEFAULT';
68824 l_entity_code                := 'TRANSACTIONS';
68825 l_event_class_code           := 'CIP_UNIT_ADJUSTMENTS';
68826 l_event_type_code            := 'CIP_UNIT_ADJUSTMENTS_ALL';
68827 l_line_definition_owner_code := 'S';
68828 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_U13';
68829 --
68830 l_balance_type_code          := 'A';
68831 l_segment                     := NULL;
68832 l_ccid                        := NULL;
68833 l_adr_transaction_coa_id      := NULL;
68834 l_adr_accounting_coa_id       := NULL;
68835 l_adr_flexfield_segment_code  := NULL;
68836 l_adr_flex_value_set_id       := NULL;
68837 l_adr_value_type_code         := NULL;
68838 l_adr_value_combination_id    := NULL;
68839 l_adr_value_segment_code      := NULL;
68840 
68841 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
68842 l_bflow_class_code           := '';    -- 4219869 Business Flow
68843 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
68844 l_budgetary_control_flag     := 'N';
68845 
68846 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
68847 l_bflow_applied_to_amt       := NULL; -- 5132302
68848 l_entered_amt_idx            := NULL;          -- 4262811
68849 l_accted_amt_idx             := NULL;          -- 4262811
68850 l_acc_rev_flag               := NULL;          -- 4262811
68851 l_accrual_line_num           := NULL;          -- 4262811
68852 l_tmp_amt                    := NULL;          -- 4262811
68853 --
68854  
68855 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
68856     l_balance_type_code <> 'B' THEN
68857 IF NVL(p_source_35,'
68858 ') =  'INTERCO AR'
68859  THEN 
68860 
68861    --
68862    XLA_AE_LINES_PKG.SetNewLine;
68863 
68864    p_balance_type_code          := l_balance_type_code;
68865    -- set the flag so later we will know whether the gain loss line needs to be created
68866    
68867    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
68868      p_actual_flag :='A';
68869    END IF;
68870 
68871    --
68872    -- bulk performance
68873    --
68874    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
68875                                       p_header_num   => 0); -- 4262811
68876    --
68877    -- set accounting line options
68878    --
68879    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
68880            p_natural_side_code          => 'D'
68881          , p_gain_or_loss_flag          => 'N'
68882          , p_gl_transfer_mode_code      => 'S'
68883          , p_acct_entry_type_code       => 'A'
68884          , p_switch_side_flag           => 'Y'
68885          , p_merge_duplicate_code       => 'N'
68886          );
68887    --
68888    l_acc_rev_natural_side_code := 'C';  -- 4262811
68889    -- 
68890    --
68891    -- set accounting line type info
68892    --
68893    xla_ae_lines_pkg.SetAcctLineType
68894       (p_component_type             => l_component_type
68895       ,p_event_type_code            => l_event_type_code
68896       ,p_line_definition_owner_code => l_line_definition_owner_code
68897       ,p_line_definition_code       => l_line_definition_code
68898       ,p_accounting_line_code       => l_component_code
68899       ,p_accounting_line_type_code  => l_component_type_code
68900       ,p_accounting_line_appl_id    => l_component_appl_id
68901       ,p_amb_context_code           => l_amb_context_code
68902       ,p_entity_code                => l_entity_code
68903       ,p_event_class_code           => l_event_class_code);
68904    --
68905    -- set accounting class
68906    --
68907    xla_ae_lines_pkg.SetAcctClass(
68908            p_accounting_class_code  => 'ASSET'
68909          , p_ae_header_id           => l_ae_header_id
68910          );
68911 
68912    --
68913    -- set rounding class
68914    --
68915    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
68916                       'ASSET';
68917 
68918    --
68919    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
68920    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
68921    --
68922    -- bulk performance
68923    --
68924    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
68925 
68926    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
68927       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
68928 
68929    -- 4955764
68930    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
68931       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
68932 
68933    -- 4458381 Public Sector Enh
68934    
68935    --
68936    -- set accounting attributes for the line type
68937    --
68938    l_entered_amt_idx := 4;
68939    l_accted_amt_idx  := 6;
68940    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
68941    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
68942    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
68943    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
68944    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
68945    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
68949    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
68946    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
68947    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
68948    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
68950    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
68951    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
68952    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
68953 
68954    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
68955    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
68956 
68957    ---------------------------------------------------------------------------------------------------------------
68958    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
68959    ---------------------------------------------------------------------------------------------------------------
68960    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
68961 
68962    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
68963    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
68964 
68965    IF xla_accounting_cache_pkg.GetValueChar
68966          (p_source_code         => 'LEDGER_CATEGORY_CODE'
68967          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
68968    AND l_bflow_method_code = 'PRIOR_ENTRY'
68969 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
68970    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
68971          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
68972        )
68973    THEN
68974          xla_ae_lines_pkg.BflowUpgEntry
68975            (p_business_method_code    => l_bflow_method_code
68976            ,p_business_class_code     => l_bflow_class_code
68977            ,p_balance_type            => l_balance_type_code);
68978    ELSE
68979       NULL;
68980 -- No business flow processing for business flow method of NONE.
68981    END IF;
68982 
68983    --
68984    -- call analytical criteria
68985    --
68986    
68987    --
68988    -- call description
68989    --
68990    
68991 xla_ae_lines_pkg.SetLineDescription(
68992    p_ae_header_id => l_ae_header_id
68993   ,p_description  => Description_51 (
68994      p_application_id         => p_application_id
68995    , p_ae_header_id           => l_ae_header_id 
68996 , p_source_1 => p_source_1
68997    )
68998 );
68999 
69000 
69001    --
69002    -- call ADRs
69003    -- Bug 4922099
69004    --
69005    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
69006         (NVL(l_actual_upg_option, 'N') = 'O') OR
69007         (NVL(l_enc_upg_option, 'N') = 'O')
69008       )
69009    THEN
69010    NULL;
69011    --
69012    --
69013    
69014   l_ccid := AcctDerRule_173(
69015            p_application_id           => p_application_id
69016          , p_ae_header_id             => l_ae_header_id 
69017 , p_source_3 => p_source_3
69018 , p_source_30 => p_source_30
69019          , x_transaction_coa_id       => l_adr_transaction_coa_id
69020          , x_accounting_coa_id        => l_adr_accounting_coa_id
69021          , x_value_type_code          => l_adr_value_type_code
69022          , p_side                     => 'NA'
69023    );
69024 
69025    xla_ae_lines_pkg.set_ccid(
69026     p_code_combination_id          => l_ccid
69027   , p_value_type_code              => l_adr_value_type_code
69028   , p_transaction_coa_id           => l_adr_transaction_coa_id
69029   , p_accounting_coa_id            => l_adr_accounting_coa_id
69030   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
69031   , p_adr_type_code                => 'S'
69032   , p_component_type               => l_component_type
69033   , p_component_code               => l_component_code
69034   , p_component_type_code          => l_component_type_code
69035   , p_component_appl_id            => l_component_appl_id
69036   , p_amb_context_code             => l_amb_context_code
69037   , p_side                         => 'NA'
69038   );
69039 
69040 
69041    l_segment := AcctDerRule_168(
69042            p_application_id           => p_application_id
69043          , p_ae_header_id             => l_ae_header_id 
69044 , p_source_3 => p_source_3
69045 , p_source_29 => p_source_29
69046          , x_transaction_coa_id       => l_adr_transaction_coa_id
69047          , x_accounting_coa_id        => l_adr_accounting_coa_id
69048          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
69049          , x_flex_value_set_id        => l_adr_flex_value_set_id
69050          , x_value_type_code          => l_adr_value_type_code
69051          , x_value_combination_id     => l_adr_value_combination_id
69052          , x_value_segment_code       => l_adr_value_segment_code
69053          , p_side                     => 'NA'
69054          , p_override_seg_flag        => 'Y'
69055    );
69056 
69057    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
69058 
69059       xla_ae_lines_pkg.set_segment(
69060           p_to_segment_code         => 'GL_BALANCING'
69061         , p_segment_value           => l_segment
69062         , p_from_segment_code       => l_adr_value_segment_code
69063         , p_from_combination_id     => l_adr_value_combination_id
69064         , p_value_type_code         => l_adr_value_type_code
69065         , p_transaction_coa_id      => l_adr_transaction_coa_id
69066         , p_accounting_coa_id       => l_adr_accounting_coa_id
69067         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
69068         , p_flex_value_set_id       => l_adr_flex_value_set_id
69069         , p_adr_code                => 'FA_EXPENSE_ACCT'
69070         , p_adr_type_code           => 'S'
69074         , p_component_appl_id       => l_component_appl_id
69071         , p_component_type          => l_component_type
69072         , p_component_code          => l_component_code
69073         , p_component_type_code     => l_component_type_code
69075         , p_amb_context_code        => l_amb_context_code
69076         , p_entity_code             => 'TRANSACTIONS'
69077         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
69078         , p_side                    => 'NA'
69079         );
69080 
69081   END IF;
69082 
69083    l_segment := AcctDerRule_158(
69084            p_application_id           => p_application_id
69085          , p_ae_header_id             => l_ae_header_id 
69086 , p_source_3 => p_source_3
69087 , p_source_20 => p_source_20
69088          , x_transaction_coa_id       => l_adr_transaction_coa_id
69089          , x_accounting_coa_id        => l_adr_accounting_coa_id
69090          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
69091          , x_flex_value_set_id        => l_adr_flex_value_set_id
69092          , x_value_type_code          => l_adr_value_type_code
69093          , x_value_combination_id     => l_adr_value_combination_id
69094          , x_value_segment_code       => l_adr_value_segment_code
69095          , p_side                     => 'NA'
69096          , p_override_seg_flag        => 'Y'
69097    );
69098 
69099    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
69100 
69101       xla_ae_lines_pkg.set_segment(
69102           p_to_segment_code         => 'GL_ACCOUNT'
69103         , p_segment_value           => l_segment
69104         , p_from_segment_code       => l_adr_value_segment_code
69105         , p_from_combination_id     => l_adr_value_combination_id
69106         , p_value_type_code         => l_adr_value_type_code
69107         , p_transaction_coa_id      => l_adr_transaction_coa_id
69108         , p_accounting_coa_id       => l_adr_accounting_coa_id
69109         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
69110         , p_flex_value_set_id       => l_adr_flex_value_set_id
69111         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
69112         , p_adr_type_code           => 'S'
69113         , p_component_type          => l_component_type
69114         , p_component_code          => l_component_code
69115         , p_component_type_code     => l_component_type_code
69116         , p_component_appl_id       => l_component_appl_id
69117         , p_amb_context_code        => l_amb_context_code
69118         , p_entity_code             => 'TRANSACTIONS'
69119         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
69120         , p_side                    => 'NA'
69121         );
69122 
69123   END IF;
69124 
69125    --
69126    --
69127    END IF;
69128    --
69129    -- Bug 4922099
69130    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
69131           (NVL(l_enc_upg_option, 'N') = 'O')
69132         ) AND
69133         (l_bflow_method_code = 'PRIOR_ENTRY')
69134       )
69135    THEN
69136       IF
69137       --
69138       1 = 2
69139       --
69140       THEN
69141       xla_accounting_err_pkg.build_message
69142                                     (p_appli_s_name            => 'XLA'
69143                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
69144                                     ,p_token_1                 => 'LINE_NUMBER'
69145                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
69146                                     ,p_token_2                 => 'LINE_TYPE_NAME'
69147                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
69148                                                                              l_component_type
69149                                                                             ,l_component_code
69150                                                                             ,l_component_type_code
69151                                                                             ,l_component_appl_id
69152                                                                             ,l_amb_context_code
69153                                                                             ,l_entity_code
69154                                                                             ,l_event_class_code
69155                                                                            )
69156                                     ,p_token_3                 => 'OWNER'
69157                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
69158                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
69159                                                                           ,p_lookup_code    => l_component_type_code
69160                                                                          )
69161                                     ,p_token_4                 => 'PRODUCT_NAME'
69162                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
69163                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
69164                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
69165                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
69166                                     ,p_ae_header_id            =>  NULL
69167                                        );
69168 
69169         IF (C_LEVEL_ERROR>= g_log_level) THEN
69170                  trace
69171                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
69172                       ,p_level    => C_LEVEL_ERROR
69173                       ,p_module   => l_log_module);
69174         END IF;
69175       END IF;
69176    END IF;
69177    --
69178    --
69182    -- Prior Entry.  Currently, the following code is always generated.
69179    ------------------------------------------------------------------------------------------------
69180    -- 4219869 Business Flow
69181    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
69183    ------------------------------------------------------------------------------------------------
69184    XLA_AE_LINES_PKG.ValidateCurrentLine;
69185 
69186    ------------------------------------------------------------------------------------
69187    -- 4219869 Business Flow
69188    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
69189    ------------------------------------------------------------------------------------
69190    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
69191 
69192    ----------------------------------------------------------------------------------
69193    -- 4219869 Business Flow
69194    -- Update journal entry status -- Need to generate this within IF <condition>
69195    ----------------------------------------------------------------------------------
69196    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
69197          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
69198          ,p_balance_type_code => l_balance_type_code
69199          );
69200 
69201    -------------------------------------------------------------------------------------------
69202    -- 4262811 - Generate the Accrual Reversal lines
69203    -------------------------------------------------------------------------------------------
69204    BEGIN
69205       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
69206                               (g_array_event(p_event_id).array_value_num('header_index'));
69207       IF l_acc_rev_flag IS NULL THEN
69208          l_acc_rev_flag := 'N';
69209       END IF;
69210    EXCEPTION
69211       WHEN OTHERS THEN
69212          l_acc_rev_flag := 'N';
69213    END;
69214    --
69215    IF (l_acc_rev_flag = 'Y') THEN
69216 
69217        -- 4645092  ------------------------------------------------------------------------------
69218        -- To allow MPA report to determine if it should generate report process
69219        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
69220        ------------------------------------------------------------------------------------------
69221 
69222        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
69223        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
69224    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
69225    -- call ADRs
69226    -- Bug 4922099
69227    --
69228    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
69229         (NVL(l_actual_upg_option, 'N') = 'O') OR
69230         (NVL(l_enc_upg_option, 'N') = 'O')
69231       )
69232    THEN
69233    NULL;
69234    --
69235    --
69236    
69237   l_ccid := AcctDerRule_173(
69238            p_application_id           => p_application_id
69239          , p_ae_header_id             => l_ae_header_id 
69240 , p_source_3 => p_source_3
69241 , p_source_30 => p_source_30
69242          , x_transaction_coa_id       => l_adr_transaction_coa_id
69243          , x_accounting_coa_id        => l_adr_accounting_coa_id
69244          , x_value_type_code          => l_adr_value_type_code
69245          , p_side                     => 'NA'
69246    );
69247 
69248    xla_ae_lines_pkg.set_ccid(
69249     p_code_combination_id          => l_ccid
69250   , p_value_type_code              => l_adr_value_type_code
69251   , p_transaction_coa_id           => l_adr_transaction_coa_id
69252   , p_accounting_coa_id            => l_adr_accounting_coa_id
69253   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
69254   , p_adr_type_code                => 'S'
69255   , p_component_type               => l_component_type
69256   , p_component_code               => l_component_code
69257   , p_component_type_code          => l_component_type_code
69258   , p_component_appl_id            => l_component_appl_id
69259   , p_amb_context_code             => l_amb_context_code
69260   , p_side                         => 'NA'
69261   );
69262 
69263 
69264    l_segment := AcctDerRule_168(
69265            p_application_id           => p_application_id
69266          , p_ae_header_id             => l_ae_header_id 
69267 , p_source_3 => p_source_3
69268 , p_source_29 => p_source_29
69269          , x_transaction_coa_id       => l_adr_transaction_coa_id
69270          , x_accounting_coa_id        => l_adr_accounting_coa_id
69271          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
69272          , x_flex_value_set_id        => l_adr_flex_value_set_id
69273          , x_value_type_code          => l_adr_value_type_code
69274          , x_value_combination_id     => l_adr_value_combination_id
69275          , x_value_segment_code       => l_adr_value_segment_code
69276          , p_side                     => 'NA'
69277          , p_override_seg_flag        => 'Y'
69278    );
69279 
69280    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
69281 
69282       xla_ae_lines_pkg.set_segment(
69283           p_to_segment_code         => 'GL_BALANCING'
69284         , p_segment_value           => l_segment
69285         , p_from_segment_code       => l_adr_value_segment_code
69286         , p_from_combination_id     => l_adr_value_combination_id
69287         , p_value_type_code         => l_adr_value_type_code
69288         , p_transaction_coa_id      => l_adr_transaction_coa_id
69289         , p_accounting_coa_id       => l_adr_accounting_coa_id
69290         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
69291         , p_flex_value_set_id       => l_adr_flex_value_set_id
69292         , p_adr_code                => 'FA_EXPENSE_ACCT'
69293         , p_adr_type_code           => 'S'
69294         , p_component_type          => l_component_type
69298         , p_amb_context_code        => l_amb_context_code
69295         , p_component_code          => l_component_code
69296         , p_component_type_code     => l_component_type_code
69297         , p_component_appl_id       => l_component_appl_id
69299         , p_entity_code             => 'TRANSACTIONS'
69300         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
69301         , p_side                    => 'NA'
69302         );
69303 
69304   END IF;
69305 
69306    l_segment := AcctDerRule_158(
69307            p_application_id           => p_application_id
69308          , p_ae_header_id             => l_ae_header_id 
69309 , p_source_3 => p_source_3
69310 , p_source_20 => p_source_20
69311          , x_transaction_coa_id       => l_adr_transaction_coa_id
69312          , x_accounting_coa_id        => l_adr_accounting_coa_id
69313          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
69314          , x_flex_value_set_id        => l_adr_flex_value_set_id
69315          , x_value_type_code          => l_adr_value_type_code
69316          , x_value_combination_id     => l_adr_value_combination_id
69317          , x_value_segment_code       => l_adr_value_segment_code
69318          , p_side                     => 'NA'
69319          , p_override_seg_flag        => 'Y'
69320    );
69321 
69322    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
69323 
69324       xla_ae_lines_pkg.set_segment(
69325           p_to_segment_code         => 'GL_ACCOUNT'
69326         , p_segment_value           => l_segment
69327         , p_from_segment_code       => l_adr_value_segment_code
69328         , p_from_combination_id     => l_adr_value_combination_id
69329         , p_value_type_code         => l_adr_value_type_code
69330         , p_transaction_coa_id      => l_adr_transaction_coa_id
69331         , p_accounting_coa_id       => l_adr_accounting_coa_id
69332         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
69333         , p_flex_value_set_id       => l_adr_flex_value_set_id
69334         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
69335         , p_adr_type_code           => 'S'
69336         , p_component_type          => l_component_type
69337         , p_component_code          => l_component_code
69338         , p_component_type_code     => l_component_type_code
69339         , p_component_appl_id       => l_component_appl_id
69340         , p_amb_context_code        => l_amb_context_code
69341         , p_entity_code             => 'TRANSACTIONS'
69342         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
69343         , p_side                    => 'NA'
69344         );
69345 
69346   END IF;
69347 
69348    --
69349    --
69350    END IF;
69351 
69352        --
69353        -- Update the line information that should be overwritten
69354        --
69355        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
69356                                          p_header_num   => 1);
69357        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
69358 
69359        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
69360 
69361        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
69362           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
69363        END IF;
69364 
69365       --
69366       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
69367       --
69368       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
69369           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
69370       ELSE
69371           ---------------------------------------------------------------------------------------------------
69372           -- 4262811a Switch Sign
69373           ---------------------------------------------------------------------------------------------------
69374           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
69375           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
69376                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
69377           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
69378                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
69379           -- 5132302
69380           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
69381                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
69382 
69383       END IF;
69384 
69385       -- 4955764
69386       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
69387       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
69388 
69389 
69390       XLA_AE_LINES_PKG.ValidateCurrentLine;
69391       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
69392 
69393       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
69394                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
69395                ,p_balance_type_code => l_balance_type_code);
69396 
69397    END IF;
69398 
69399    -----------------------------------------------------------------------------------------
69400    -- 4262811 Multiperiod Accounting
69401    -----------------------------------------------------------------------------------------
69402      -- No MPA option is assigned.
69403 
69404 
69405 END IF;
69406 END IF;
69407 --
69408 
69409 --
69410 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
69411    trace
69412       (p_msg      => 'END of AcctLineType_250'
69416 --
69413       ,p_level    => C_LEVEL_PROCEDURE
69414       ,p_module   => l_log_module);
69415 END IF;
69417 EXCEPTION
69418   WHEN xla_exceptions_pkg.application_exception THEN
69419       RAISE;
69420   WHEN OTHERS THEN
69421        xla_exceptions_pkg.raise_message
69422            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_250');
69423 END AcctLineType_250;
69424 --
69425 
69426 ---------------------------------------
69427 --
69428 -- PRIVATE FUNCTION
69429 --         AcctLineType_251
69430 --
69431 ---------------------------------------
69432 PROCEDURE AcctLineType_251 (
69433   p_application_id        IN NUMBER
69434  ,p_event_id              IN NUMBER
69435  ,p_calculate_acctd_flag  IN VARCHAR2
69436  ,p_calculate_g_l_flag    IN VARCHAR2
69437  ,p_actual_flag           IN OUT VARCHAR2
69438  ,p_balance_type_code     OUT VARCHAR2
69439  ,p_gain_or_loss_ref      OUT VARCHAR2
69440  
69441 --Period Close Date
69442  , p_source_1            IN DATE
69443 --Generated Code Combination Identifier
69444  , p_source_3            IN NUMBER
69445 --CIP Cost Account
69446  , p_source_7            IN VARCHAR2
69447 --Expense Account Code Combination Identifier
69448  , p_source_29            IN NUMBER
69449 --Default Code Combination Identifier
69450  , p_source_30            IN NUMBER
69451 --Adjustment Type
69452  , p_source_35            IN VARCHAR2
69453 --Transaction Header Identifier
69454  , p_source_36            IN NUMBER
69455 --Adjustment Line Identifier
69456  , p_source_37            IN NUMBER
69457 --Distribution Type Code
69458  , p_source_38            IN VARCHAR2
69459 --Entered Amount
69460  , p_source_39            IN NUMBER
69461 --Currency Code
69462  , p_source_40            IN VARCHAR2
69463 --Source Destination Code
69464  , p_source_42            IN VARCHAR2
69465 )
69466 IS
69467 
69468 l_component_type              VARCHAR2(80);
69469 l_component_code              VARCHAR2(30);
69470 l_component_type_code         VARCHAR2(1);
69471 l_component_appl_id           INTEGER;
69472 l_amb_context_code            VARCHAR2(30);
69473 l_entity_code                 VARCHAR2(30);
69474 l_event_class_code            VARCHAR2(30);
69475 l_ae_header_id                NUMBER;
69476 l_event_type_code             VARCHAR2(30);
69477 l_line_definition_code        VARCHAR2(30);
69478 l_line_definition_owner_code  VARCHAR2(1);
69479 --
69480 -- adr variables
69481 l_segment                     VARCHAR2(30);
69482 l_ccid                        NUMBER;
69483 l_adr_transaction_coa_id      NUMBER;
69484 l_adr_accounting_coa_id       NUMBER;
69485 l_adr_flexfield_segment_code  VARCHAR2(30);
69486 l_adr_flex_value_set_id       NUMBER;
69487 l_adr_value_type_code         VARCHAR2(30);
69488 l_adr_value_combination_id    NUMBER;
69489 l_adr_value_segment_code      VARCHAR2(30);
69490 
69491 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
69492 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
69493 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
69494 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
69495 
69496 -- 4262811 Variables ------------------------------------------------------------------------------------------
69497 l_entered_amt_idx             NUMBER;
69498 l_accted_amt_idx              NUMBER;
69499 l_acc_rev_flag                VARCHAR2(1);
69500 l_accrual_line_num            NUMBER;
69501 l_tmp_amt                     NUMBER;
69502 l_acc_rev_natural_side_code   VARCHAR2(1);
69503 
69504 l_num_entries                 NUMBER;
69505 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
69506 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
69507 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
69508 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
69509 l_recog_line_1                NUMBER;
69510 l_recog_line_2                NUMBER;
69511 
69512 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
69513 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
69514 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
69515 
69516 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
69517 
69518 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
69519 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
69520 
69521 ---------------------------------------------------------------------------------------------------------------
69522 
69523 
69524 --
69525 -- bulk performance
69526 --
69527 l_balance_type_code           VARCHAR2(1);
69528 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
69529 l_log_module                  VARCHAR2(240);
69530 
69531 --
69532 -- Upgrade strategy
69533 --
69534 l_actual_upg_option           VARCHAR2(1);
69535 l_enc_upg_option           VARCHAR2(1);
69536 
69537 --
69538 BEGIN
69539 --
69540 IF g_log_enabled THEN
69541       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_251';
69542 END IF;
69543 --
69544 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
69545 
69546       trace
69547          (p_msg      => 'BEGIN of AcctLineType_251'
69548          ,p_level    => C_LEVEL_PROCEDURE
69549          ,p_module   => l_log_module);
69550 
69551 END IF;
69552 --
69553 l_component_type             := 'AMB_JLT';
69554 l_component_code             := 'FA_CIP_UNITADJ_SOURCE_COST';
69555 l_component_type_code        := 'S';
69556 l_component_appl_id          :=  140;
69557 l_amb_context_code           := 'DEFAULT';
69558 l_entity_code                := 'TRANSACTIONS';
69562 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_U13';
69559 l_event_class_code           := 'CIP_UNIT_ADJUSTMENTS';
69560 l_event_type_code            := 'CIP_UNIT_ADJUSTMENTS_ALL';
69561 l_line_definition_owner_code := 'S';
69563 --
69564 l_balance_type_code          := 'A';
69565 l_segment                     := NULL;
69566 l_ccid                        := NULL;
69567 l_adr_transaction_coa_id      := NULL;
69568 l_adr_accounting_coa_id       := NULL;
69569 l_adr_flexfield_segment_code  := NULL;
69570 l_adr_flex_value_set_id       := NULL;
69571 l_adr_value_type_code         := NULL;
69572 l_adr_value_combination_id    := NULL;
69573 l_adr_value_segment_code      := NULL;
69574 
69575 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
69576 l_bflow_class_code           := '';    -- 4219869 Business Flow
69577 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
69578 l_budgetary_control_flag     := 'N';
69579 
69580 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
69581 l_bflow_applied_to_amt       := NULL; -- 5132302
69582 l_entered_amt_idx            := NULL;          -- 4262811
69583 l_accted_amt_idx             := NULL;          -- 4262811
69584 l_acc_rev_flag               := NULL;          -- 4262811
69585 l_accrual_line_num           := NULL;          -- 4262811
69586 l_tmp_amt                    := NULL;          -- 4262811
69587 --
69588  
69589 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
69590     l_balance_type_code <> 'B' THEN
69591 IF NVL(p_source_35,'
69592 ') =  'CIP COST' AND 
69593 NVL(p_source_42,'
69594 ') =  'SOURCE'
69595  THEN 
69596 
69597    --
69598    XLA_AE_LINES_PKG.SetNewLine;
69599 
69600    p_balance_type_code          := l_balance_type_code;
69601    -- set the flag so later we will know whether the gain loss line needs to be created
69602    
69603    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
69604      p_actual_flag :='A';
69605    END IF;
69606 
69607    --
69608    -- bulk performance
69609    --
69610    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
69611                                       p_header_num   => 0); -- 4262811
69612    --
69613    -- set accounting line options
69614    --
69615    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
69616            p_natural_side_code          => 'C'
69617          , p_gain_or_loss_flag          => 'N'
69618          , p_gl_transfer_mode_code      => 'S'
69619          , p_acct_entry_type_code       => 'A'
69620          , p_switch_side_flag           => 'Y'
69621          , p_merge_duplicate_code       => 'N'
69622          );
69623    --
69624    l_acc_rev_natural_side_code := 'D';  -- 4262811
69625    -- 
69626    --
69627    -- set accounting line type info
69628    --
69629    xla_ae_lines_pkg.SetAcctLineType
69630       (p_component_type             => l_component_type
69631       ,p_event_type_code            => l_event_type_code
69632       ,p_line_definition_owner_code => l_line_definition_owner_code
69633       ,p_line_definition_code       => l_line_definition_code
69634       ,p_accounting_line_code       => l_component_code
69635       ,p_accounting_line_type_code  => l_component_type_code
69636       ,p_accounting_line_appl_id    => l_component_appl_id
69637       ,p_amb_context_code           => l_amb_context_code
69638       ,p_entity_code                => l_entity_code
69639       ,p_event_class_code           => l_event_class_code);
69640    --
69641    -- set accounting class
69642    --
69643    xla_ae_lines_pkg.SetAcctClass(
69644            p_accounting_class_code  => 'ASSET'
69645          , p_ae_header_id           => l_ae_header_id
69646          );
69647 
69648    --
69649    -- set rounding class
69650    --
69651    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
69652                       'ASSET';
69653 
69654    --
69655    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
69656    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
69657    --
69658    -- bulk performance
69659    --
69660    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
69661 
69662    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
69663       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
69664 
69665    -- 4955764
69666    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
69667       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
69668 
69669    -- 4458381 Public Sector Enh
69670    
69671    --
69672    -- set accounting attributes for the line type
69673    --
69674    l_entered_amt_idx := 4;
69675    l_accted_amt_idx  := 6;
69676    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
69677    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
69678    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
69679    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
69680    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
69681    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
69682    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
69683    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
69684    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
69685    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
69686    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
69687    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
69688    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
69689 
69693    ---------------------------------------------------------------------------------------------------------------
69690    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
69691    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
69692 
69694    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
69695    ---------------------------------------------------------------------------------------------------------------
69696    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
69697 
69698    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
69699    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
69700 
69701    IF xla_accounting_cache_pkg.GetValueChar
69702          (p_source_code         => 'LEDGER_CATEGORY_CODE'
69703          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
69704    AND l_bflow_method_code = 'PRIOR_ENTRY'
69705 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
69706    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
69707          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
69708        )
69709    THEN
69710          xla_ae_lines_pkg.BflowUpgEntry
69711            (p_business_method_code    => l_bflow_method_code
69712            ,p_business_class_code     => l_bflow_class_code
69713            ,p_balance_type            => l_balance_type_code);
69714    ELSE
69715       NULL;
69716 -- No business flow processing for business flow method of NONE.
69717    END IF;
69718 
69719    --
69720    -- call analytical criteria
69721    --
69722    
69723    --
69724    -- call description
69725    --
69726    
69727 xla_ae_lines_pkg.SetLineDescription(
69728    p_ae_header_id => l_ae_header_id
69729   ,p_description  => Description_49 (
69730      p_application_id         => p_application_id
69731    , p_ae_header_id           => l_ae_header_id 
69732 , p_source_1 => p_source_1
69733    )
69734 );
69735 
69736 
69737    --
69738    -- call ADRs
69739    -- Bug 4922099
69740    --
69741    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
69742         (NVL(l_actual_upg_option, 'N') = 'O') OR
69743         (NVL(l_enc_upg_option, 'N') = 'O')
69744       )
69745    THEN
69746    NULL;
69747    --
69748    --
69749    
69750   l_ccid := AcctDerRule_173(
69751            p_application_id           => p_application_id
69752          , p_ae_header_id             => l_ae_header_id 
69753 , p_source_3 => p_source_3
69754 , p_source_30 => p_source_30
69755          , x_transaction_coa_id       => l_adr_transaction_coa_id
69756          , x_accounting_coa_id        => l_adr_accounting_coa_id
69757          , x_value_type_code          => l_adr_value_type_code
69758          , p_side                     => 'NA'
69759    );
69760 
69761    xla_ae_lines_pkg.set_ccid(
69762     p_code_combination_id          => l_ccid
69763   , p_value_type_code              => l_adr_value_type_code
69764   , p_transaction_coa_id           => l_adr_transaction_coa_id
69765   , p_accounting_coa_id            => l_adr_accounting_coa_id
69766   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
69767   , p_adr_type_code                => 'S'
69768   , p_component_type               => l_component_type
69769   , p_component_code               => l_component_code
69770   , p_component_type_code          => l_component_type_code
69771   , p_component_appl_id            => l_component_appl_id
69772   , p_amb_context_code             => l_amb_context_code
69773   , p_side                         => 'NA'
69774   );
69775 
69776 
69777    l_segment := AcctDerRule_146(
69778            p_application_id           => p_application_id
69779          , p_ae_header_id             => l_ae_header_id 
69780 , p_source_3 => p_source_3
69781 , p_source_7 => p_source_7
69782          , x_transaction_coa_id       => l_adr_transaction_coa_id
69783          , x_accounting_coa_id        => l_adr_accounting_coa_id
69784          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
69785          , x_flex_value_set_id        => l_adr_flex_value_set_id
69786          , x_value_type_code          => l_adr_value_type_code
69787          , x_value_combination_id     => l_adr_value_combination_id
69788          , x_value_segment_code       => l_adr_value_segment_code
69789          , p_side                     => 'NA'
69790          , p_override_seg_flag        => 'Y'
69791    );
69792 
69793    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
69794 
69795       xla_ae_lines_pkg.set_segment(
69796           p_to_segment_code         => 'GL_ACCOUNT'
69797         , p_segment_value           => l_segment
69798         , p_from_segment_code       => l_adr_value_segment_code
69799         , p_from_combination_id     => l_adr_value_combination_id
69800         , p_value_type_code         => l_adr_value_type_code
69801         , p_transaction_coa_id      => l_adr_transaction_coa_id
69802         , p_accounting_coa_id       => l_adr_accounting_coa_id
69803         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
69804         , p_flex_value_set_id       => l_adr_flex_value_set_id
69805         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
69806         , p_adr_type_code           => 'S'
69807         , p_component_type          => l_component_type
69808         , p_component_code          => l_component_code
69809         , p_component_type_code     => l_component_type_code
69810         , p_component_appl_id       => l_component_appl_id
69811         , p_amb_context_code        => l_amb_context_code
69812         , p_entity_code             => 'TRANSACTIONS'
69813         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
69817   END IF;
69814         , p_side                    => 'NA'
69815         );
69816 
69818 
69819    l_segment := AcctDerRule_168(
69820            p_application_id           => p_application_id
69821          , p_ae_header_id             => l_ae_header_id 
69822 , p_source_3 => p_source_3
69823 , p_source_29 => p_source_29
69824          , x_transaction_coa_id       => l_adr_transaction_coa_id
69825          , x_accounting_coa_id        => l_adr_accounting_coa_id
69826          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
69827          , x_flex_value_set_id        => l_adr_flex_value_set_id
69828          , x_value_type_code          => l_adr_value_type_code
69829          , x_value_combination_id     => l_adr_value_combination_id
69830          , x_value_segment_code       => l_adr_value_segment_code
69831          , p_side                     => 'NA'
69832          , p_override_seg_flag        => 'Y'
69833    );
69834 
69835    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
69836 
69837       xla_ae_lines_pkg.set_segment(
69838           p_to_segment_code         => 'GL_BALANCING'
69839         , p_segment_value           => l_segment
69840         , p_from_segment_code       => l_adr_value_segment_code
69841         , p_from_combination_id     => l_adr_value_combination_id
69842         , p_value_type_code         => l_adr_value_type_code
69843         , p_transaction_coa_id      => l_adr_transaction_coa_id
69844         , p_accounting_coa_id       => l_adr_accounting_coa_id
69845         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
69846         , p_flex_value_set_id       => l_adr_flex_value_set_id
69847         , p_adr_code                => 'FA_EXPENSE_ACCT'
69848         , p_adr_type_code           => 'S'
69849         , p_component_type          => l_component_type
69850         , p_component_code          => l_component_code
69851         , p_component_type_code     => l_component_type_code
69852         , p_component_appl_id       => l_component_appl_id
69853         , p_amb_context_code        => l_amb_context_code
69854         , p_entity_code             => 'TRANSACTIONS'
69855         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
69856         , p_side                    => 'NA'
69857         );
69858 
69859   END IF;
69860 
69861    --
69862    --
69863    END IF;
69864    --
69865    -- Bug 4922099
69866    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
69867           (NVL(l_enc_upg_option, 'N') = 'O')
69868         ) AND
69869         (l_bflow_method_code = 'PRIOR_ENTRY')
69870       )
69871    THEN
69872       IF
69873       --
69874       1 = 2
69875       --
69876       THEN
69877       xla_accounting_err_pkg.build_message
69878                                     (p_appli_s_name            => 'XLA'
69879                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
69880                                     ,p_token_1                 => 'LINE_NUMBER'
69881                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
69882                                     ,p_token_2                 => 'LINE_TYPE_NAME'
69883                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
69884                                                                              l_component_type
69885                                                                             ,l_component_code
69886                                                                             ,l_component_type_code
69887                                                                             ,l_component_appl_id
69888                                                                             ,l_amb_context_code
69889                                                                             ,l_entity_code
69890                                                                             ,l_event_class_code
69891                                                                            )
69892                                     ,p_token_3                 => 'OWNER'
69893                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
69894                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
69895                                                                           ,p_lookup_code    => l_component_type_code
69896                                                                          )
69897                                     ,p_token_4                 => 'PRODUCT_NAME'
69898                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
69899                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
69900                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
69901                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
69902                                     ,p_ae_header_id            =>  NULL
69903                                        );
69904 
69905         IF (C_LEVEL_ERROR>= g_log_level) THEN
69906                  trace
69907                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
69908                       ,p_level    => C_LEVEL_ERROR
69909                       ,p_module   => l_log_module);
69910         END IF;
69911       END IF;
69912    END IF;
69913    --
69914    --
69915    ------------------------------------------------------------------------------------------------
69916    -- 4219869 Business Flow
69917    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
69918    -- Prior Entry.  Currently, the following code is always generated.
69919    ------------------------------------------------------------------------------------------------
69920    XLA_AE_LINES_PKG.ValidateCurrentLine;
69921 
69925    ------------------------------------------------------------------------------------
69922    ------------------------------------------------------------------------------------
69923    -- 4219869 Business Flow
69924    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
69926    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
69927 
69928    ----------------------------------------------------------------------------------
69929    -- 4219869 Business Flow
69930    -- Update journal entry status -- Need to generate this within IF <condition>
69931    ----------------------------------------------------------------------------------
69932    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
69933          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
69934          ,p_balance_type_code => l_balance_type_code
69935          );
69936 
69937    -------------------------------------------------------------------------------------------
69938    -- 4262811 - Generate the Accrual Reversal lines
69939    -------------------------------------------------------------------------------------------
69940    BEGIN
69941       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
69942                               (g_array_event(p_event_id).array_value_num('header_index'));
69943       IF l_acc_rev_flag IS NULL THEN
69944          l_acc_rev_flag := 'N';
69945       END IF;
69946    EXCEPTION
69947       WHEN OTHERS THEN
69948          l_acc_rev_flag := 'N';
69949    END;
69950    --
69951    IF (l_acc_rev_flag = 'Y') THEN
69952 
69953        -- 4645092  ------------------------------------------------------------------------------
69954        -- To allow MPA report to determine if it should generate report process
69955        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
69956        ------------------------------------------------------------------------------------------
69957 
69958        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
69959        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
69960    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
69961    -- call ADRs
69962    -- Bug 4922099
69963    --
69964    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
69965         (NVL(l_actual_upg_option, 'N') = 'O') OR
69966         (NVL(l_enc_upg_option, 'N') = 'O')
69967       )
69968    THEN
69969    NULL;
69970    --
69971    --
69972    
69973   l_ccid := AcctDerRule_173(
69974            p_application_id           => p_application_id
69975          , p_ae_header_id             => l_ae_header_id 
69976 , p_source_3 => p_source_3
69977 , p_source_30 => p_source_30
69978          , x_transaction_coa_id       => l_adr_transaction_coa_id
69979          , x_accounting_coa_id        => l_adr_accounting_coa_id
69980          , x_value_type_code          => l_adr_value_type_code
69981          , p_side                     => 'NA'
69982    );
69983 
69984    xla_ae_lines_pkg.set_ccid(
69985     p_code_combination_id          => l_ccid
69986   , p_value_type_code              => l_adr_value_type_code
69987   , p_transaction_coa_id           => l_adr_transaction_coa_id
69988   , p_accounting_coa_id            => l_adr_accounting_coa_id
69989   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
69990   , p_adr_type_code                => 'S'
69991   , p_component_type               => l_component_type
69992   , p_component_code               => l_component_code
69993   , p_component_type_code          => l_component_type_code
69994   , p_component_appl_id            => l_component_appl_id
69995   , p_amb_context_code             => l_amb_context_code
69996   , p_side                         => 'NA'
69997   );
69998 
69999 
70000    l_segment := AcctDerRule_146(
70001            p_application_id           => p_application_id
70002          , p_ae_header_id             => l_ae_header_id 
70003 , p_source_3 => p_source_3
70004 , p_source_7 => p_source_7
70005          , x_transaction_coa_id       => l_adr_transaction_coa_id
70006          , x_accounting_coa_id        => l_adr_accounting_coa_id
70007          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
70008          , x_flex_value_set_id        => l_adr_flex_value_set_id
70009          , x_value_type_code          => l_adr_value_type_code
70010          , x_value_combination_id     => l_adr_value_combination_id
70011          , x_value_segment_code       => l_adr_value_segment_code
70012          , p_side                     => 'NA'
70013          , p_override_seg_flag        => 'Y'
70014    );
70015 
70016    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
70017 
70018       xla_ae_lines_pkg.set_segment(
70019           p_to_segment_code         => 'GL_ACCOUNT'
70020         , p_segment_value           => l_segment
70021         , p_from_segment_code       => l_adr_value_segment_code
70022         , p_from_combination_id     => l_adr_value_combination_id
70023         , p_value_type_code         => l_adr_value_type_code
70024         , p_transaction_coa_id      => l_adr_transaction_coa_id
70025         , p_accounting_coa_id       => l_adr_accounting_coa_id
70026         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
70027         , p_flex_value_set_id       => l_adr_flex_value_set_id
70028         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
70029         , p_adr_type_code           => 'S'
70030         , p_component_type          => l_component_type
70031         , p_component_code          => l_component_code
70032         , p_component_type_code     => l_component_type_code
70033         , p_component_appl_id       => l_component_appl_id
70034         , p_amb_context_code        => l_amb_context_code
70035         , p_entity_code             => 'TRANSACTIONS'
70036         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
70037         , p_side                    => 'NA'
70038         );
70039 
70040   END IF;
70041 
70045 , p_source_3 => p_source_3
70042    l_segment := AcctDerRule_168(
70043            p_application_id           => p_application_id
70044          , p_ae_header_id             => l_ae_header_id 
70046 , p_source_29 => p_source_29
70047          , x_transaction_coa_id       => l_adr_transaction_coa_id
70048          , x_accounting_coa_id        => l_adr_accounting_coa_id
70049          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
70050          , x_flex_value_set_id        => l_adr_flex_value_set_id
70051          , x_value_type_code          => l_adr_value_type_code
70052          , x_value_combination_id     => l_adr_value_combination_id
70053          , x_value_segment_code       => l_adr_value_segment_code
70054          , p_side                     => 'NA'
70055          , p_override_seg_flag        => 'Y'
70056    );
70057 
70058    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
70059 
70060       xla_ae_lines_pkg.set_segment(
70061           p_to_segment_code         => 'GL_BALANCING'
70062         , p_segment_value           => l_segment
70063         , p_from_segment_code       => l_adr_value_segment_code
70064         , p_from_combination_id     => l_adr_value_combination_id
70065         , p_value_type_code         => l_adr_value_type_code
70066         , p_transaction_coa_id      => l_adr_transaction_coa_id
70067         , p_accounting_coa_id       => l_adr_accounting_coa_id
70068         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
70069         , p_flex_value_set_id       => l_adr_flex_value_set_id
70070         , p_adr_code                => 'FA_EXPENSE_ACCT'
70071         , p_adr_type_code           => 'S'
70072         , p_component_type          => l_component_type
70073         , p_component_code          => l_component_code
70074         , p_component_type_code     => l_component_type_code
70075         , p_component_appl_id       => l_component_appl_id
70076         , p_amb_context_code        => l_amb_context_code
70077         , p_entity_code             => 'TRANSACTIONS'
70078         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
70079         , p_side                    => 'NA'
70080         );
70081 
70082   END IF;
70083 
70084    --
70085    --
70086    END IF;
70087 
70088        --
70089        -- Update the line information that should be overwritten
70090        --
70091        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
70092                                          p_header_num   => 1);
70093        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
70094 
70095        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
70096 
70097        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
70098           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
70099        END IF;
70100 
70101       --
70102       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
70103       --
70104       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
70105           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
70106       ELSE
70107           ---------------------------------------------------------------------------------------------------
70108           -- 4262811a Switch Sign
70109           ---------------------------------------------------------------------------------------------------
70110           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
70111           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
70112                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
70113           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
70114                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
70115           -- 5132302
70116           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
70117                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
70118 
70119       END IF;
70120 
70121       -- 4955764
70122       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
70123       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
70124 
70125 
70126       XLA_AE_LINES_PKG.ValidateCurrentLine;
70127       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
70128 
70129       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
70130                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
70131                ,p_balance_type_code => l_balance_type_code);
70132 
70133    END IF;
70134 
70135    -----------------------------------------------------------------------------------------
70136    -- 4262811 Multiperiod Accounting
70137    -----------------------------------------------------------------------------------------
70138      -- No MPA option is assigned.
70139 
70140 
70141 END IF;
70142 END IF;
70143 --
70144 
70145 --
70146 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
70147    trace
70148       (p_msg      => 'END of AcctLineType_251'
70149       ,p_level    => C_LEVEL_PROCEDURE
70150       ,p_module   => l_log_module);
70151 END IF;
70152 --
70153 EXCEPTION
70154   WHEN xla_exceptions_pkg.application_exception THEN
70155       RAISE;
70156   WHEN OTHERS THEN
70157        xla_exceptions_pkg.raise_message
70158            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_251');
70159 END AcctLineType_251;
70160 --
70161 
70162 ---------------------------------------
70163 --
70167 ---------------------------------------
70164 -- PRIVATE FUNCTION
70165 --         AcctLineType_252
70166 --
70168 PROCEDURE AcctLineType_252 (
70169   p_application_id        IN NUMBER
70170  ,p_event_id              IN NUMBER
70171  ,p_calculate_acctd_flag  IN VARCHAR2
70172  ,p_calculate_g_l_flag    IN VARCHAR2
70173  ,p_actual_flag           IN OUT VARCHAR2
70174  ,p_balance_type_code     OUT VARCHAR2
70175  ,p_gain_or_loss_ref      OUT VARCHAR2
70176  
70177 --Period Close Date
70178  , p_source_1            IN DATE
70179 --Generated Code Combination Identifier
70180  , p_source_3            IN NUMBER
70181 --Revaluation Reserve Account
70182  , p_source_11            IN VARCHAR2
70183 --Generated Offset Code Combination Identifier
70184  , p_source_17            IN NUMBER
70185 --Expense Account Code Combination Identifier
70186  , p_source_29            IN NUMBER
70187 --Default Code Combination Identifier
70188  , p_source_30            IN NUMBER
70189 --Adjustment Type
70190  , p_source_35            IN VARCHAR2
70191 --Transaction Header Identifier
70192  , p_source_36            IN NUMBER
70193 --Adjustment Line Identifier
70194  , p_source_37            IN NUMBER
70195 --Distribution Type Code
70196  , p_source_38            IN VARCHAR2
70197 --Entered Amount
70198  , p_source_39            IN NUMBER
70199 --Currency Code
70200  , p_source_40            IN VARCHAR2
70201 --Source Destination Code
70202  , p_source_42            IN VARCHAR2
70203 )
70204 IS
70205 
70206 l_component_type              VARCHAR2(80);
70207 l_component_code              VARCHAR2(30);
70208 l_component_type_code         VARCHAR2(1);
70209 l_component_appl_id           INTEGER;
70210 l_amb_context_code            VARCHAR2(30);
70211 l_entity_code                 VARCHAR2(30);
70212 l_event_class_code            VARCHAR2(30);
70213 l_ae_header_id                NUMBER;
70214 l_event_type_code             VARCHAR2(30);
70215 l_line_definition_code        VARCHAR2(30);
70216 l_line_definition_owner_code  VARCHAR2(1);
70217 --
70218 -- adr variables
70219 l_segment                     VARCHAR2(30);
70220 l_ccid                        NUMBER;
70221 l_adr_transaction_coa_id      NUMBER;
70222 l_adr_accounting_coa_id       NUMBER;
70223 l_adr_flexfield_segment_code  VARCHAR2(30);
70224 l_adr_flex_value_set_id       NUMBER;
70225 l_adr_value_type_code         VARCHAR2(30);
70226 l_adr_value_combination_id    NUMBER;
70227 l_adr_value_segment_code      VARCHAR2(30);
70228 
70229 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
70230 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
70231 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
70232 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
70233 
70234 -- 4262811 Variables ------------------------------------------------------------------------------------------
70235 l_entered_amt_idx             NUMBER;
70236 l_accted_amt_idx              NUMBER;
70237 l_acc_rev_flag                VARCHAR2(1);
70238 l_accrual_line_num            NUMBER;
70239 l_tmp_amt                     NUMBER;
70240 l_acc_rev_natural_side_code   VARCHAR2(1);
70241 
70242 l_num_entries                 NUMBER;
70243 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
70244 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
70245 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
70246 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
70247 l_recog_line_1                NUMBER;
70248 l_recog_line_2                NUMBER;
70249 
70250 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
70251 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
70252 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
70253 
70254 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
70255 
70256 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
70257 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
70258 
70259 ---------------------------------------------------------------------------------------------------------------
70260 
70261 
70262 --
70263 -- bulk performance
70264 --
70265 l_balance_type_code           VARCHAR2(1);
70266 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
70267 l_log_module                  VARCHAR2(240);
70268 
70269 --
70270 -- Upgrade strategy
70271 --
70272 l_actual_upg_option           VARCHAR2(1);
70273 l_enc_upg_option           VARCHAR2(1);
70274 
70275 --
70276 BEGIN
70277 --
70278 IF g_log_enabled THEN
70279       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_252';
70280 END IF;
70281 --
70282 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
70283 
70284       trace
70285          (p_msg      => 'BEGIN of AcctLineType_252'
70286          ,p_level    => C_LEVEL_PROCEDURE
70287          ,p_module   => l_log_module);
70288 
70289 END IF;
70290 --
70291 l_component_type             := 'AMB_JLT';
70292 l_component_code             := 'FA_CIP_UNITADJ_SRC_REVAL_RES';
70293 l_component_type_code        := 'S';
70294 l_component_appl_id          :=  140;
70295 l_amb_context_code           := 'DEFAULT';
70296 l_entity_code                := 'TRANSACTIONS';
70297 l_event_class_code           := 'CIP_UNIT_ADJUSTMENTS';
70298 l_event_type_code            := 'CIP_UNIT_ADJUSTMENTS_ALL';
70299 l_line_definition_owner_code := 'S';
70300 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_U13';
70301 --
70302 l_balance_type_code          := 'A';
70303 l_segment                     := NULL;
70304 l_ccid                        := NULL;
70305 l_adr_transaction_coa_id      := NULL;
70309 l_adr_value_type_code         := NULL;
70306 l_adr_accounting_coa_id       := NULL;
70307 l_adr_flexfield_segment_code  := NULL;
70308 l_adr_flex_value_set_id       := NULL;
70310 l_adr_value_combination_id    := NULL;
70311 l_adr_value_segment_code      := NULL;
70312 
70313 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
70314 l_bflow_class_code           := '';    -- 4219869 Business Flow
70315 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
70316 l_budgetary_control_flag     := 'N';
70317 
70318 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
70319 l_bflow_applied_to_amt       := NULL; -- 5132302
70320 l_entered_amt_idx            := NULL;          -- 4262811
70321 l_accted_amt_idx             := NULL;          -- 4262811
70322 l_acc_rev_flag               := NULL;          -- 4262811
70323 l_accrual_line_num           := NULL;          -- 4262811
70324 l_tmp_amt                    := NULL;          -- 4262811
70325 --
70326  
70327 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
70328     l_balance_type_code <> 'B' THEN
70329 IF NVL(p_source_35,'
70330 ') =  'REVAL RESERVE' AND 
70331 NVL(p_source_42,'
70332 ') =  'SOURCE'
70333  THEN 
70334 
70335    --
70336    XLA_AE_LINES_PKG.SetNewLine;
70337 
70338    p_balance_type_code          := l_balance_type_code;
70339    -- set the flag so later we will know whether the gain loss line needs to be created
70340    
70341    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
70342      p_actual_flag :='A';
70343    END IF;
70344 
70345    --
70346    -- bulk performance
70347    --
70348    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
70349                                       p_header_num   => 0); -- 4262811
70350    --
70351    -- set accounting line options
70352    --
70353    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
70354            p_natural_side_code          => 'D'
70355          , p_gain_or_loss_flag          => 'N'
70356          , p_gl_transfer_mode_code      => 'S'
70357          , p_acct_entry_type_code       => 'A'
70358          , p_switch_side_flag           => 'Y'
70359          , p_merge_duplicate_code       => 'N'
70360          );
70361    --
70362    l_acc_rev_natural_side_code := 'C';  -- 4262811
70363    -- 
70364    --
70365    -- set accounting line type info
70366    --
70367    xla_ae_lines_pkg.SetAcctLineType
70368       (p_component_type             => l_component_type
70369       ,p_event_type_code            => l_event_type_code
70370       ,p_line_definition_owner_code => l_line_definition_owner_code
70371       ,p_line_definition_code       => l_line_definition_code
70372       ,p_accounting_line_code       => l_component_code
70373       ,p_accounting_line_type_code  => l_component_type_code
70374       ,p_accounting_line_appl_id    => l_component_appl_id
70375       ,p_amb_context_code           => l_amb_context_code
70376       ,p_entity_code                => l_entity_code
70377       ,p_event_class_code           => l_event_class_code);
70378    --
70379    -- set accounting class
70380    --
70381    xla_ae_lines_pkg.SetAcctClass(
70382            p_accounting_class_code  => 'ASSET'
70383          , p_ae_header_id           => l_ae_header_id
70384          );
70385 
70386    --
70387    -- set rounding class
70388    --
70389    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
70390                       'ASSET';
70391 
70392    --
70393    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
70394    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
70395    --
70396    -- bulk performance
70397    --
70398    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
70399 
70400    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
70401       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
70402 
70403    -- 4955764
70404    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
70405       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
70406 
70407    -- 4458381 Public Sector Enh
70408    
70409    --
70410    -- set accounting attributes for the line type
70411    --
70412    l_entered_amt_idx := 4;
70413    l_accted_amt_idx  := 6;
70414    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
70415    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
70416    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
70417    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
70418    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
70419    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
70420    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
70421    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
70422    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
70423    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
70424    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
70425    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
70426    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
70427 
70428    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
70429    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
70430 
70431    ---------------------------------------------------------------------------------------------------------------
70432    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
70436    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
70433    ---------------------------------------------------------------------------------------------------------------
70434    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
70435 
70437    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
70438 
70439    IF xla_accounting_cache_pkg.GetValueChar
70440          (p_source_code         => 'LEDGER_CATEGORY_CODE'
70441          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
70442    AND l_bflow_method_code = 'PRIOR_ENTRY'
70443 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
70444    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
70445          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
70446        )
70447    THEN
70448          xla_ae_lines_pkg.BflowUpgEntry
70449            (p_business_method_code    => l_bflow_method_code
70450            ,p_business_class_code     => l_bflow_class_code
70451            ,p_balance_type            => l_balance_type_code);
70452    ELSE
70453       NULL;
70454 -- No business flow processing for business flow method of NONE.
70455    END IF;
70456 
70457    --
70458    -- call analytical criteria
70459    --
70460    
70461    --
70462    -- call description
70463    --
70464    
70465 xla_ae_lines_pkg.SetLineDescription(
70466    p_ae_header_id => l_ae_header_id
70467   ,p_description  => Description_52 (
70468      p_application_id         => p_application_id
70469    , p_ae_header_id           => l_ae_header_id 
70470 , p_source_1 => p_source_1
70471    )
70472 );
70473 
70474 
70475    --
70476    -- call ADRs
70477    -- Bug 4922099
70478    --
70479    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
70480         (NVL(l_actual_upg_option, 'N') = 'O') OR
70481         (NVL(l_enc_upg_option, 'N') = 'O')
70482       )
70483    THEN
70484    NULL;
70485    --
70486    --
70487    
70488   l_ccid := AcctDerRule_174(
70489            p_application_id           => p_application_id
70490          , p_ae_header_id             => l_ae_header_id 
70491 , p_source_3 => p_source_3
70492 , p_source_17 => p_source_17
70493 , p_source_30 => p_source_30
70494          , x_transaction_coa_id       => l_adr_transaction_coa_id
70495          , x_accounting_coa_id        => l_adr_accounting_coa_id
70496          , x_value_type_code          => l_adr_value_type_code
70497          , p_side                     => 'NA'
70498    );
70499 
70500    xla_ae_lines_pkg.set_ccid(
70501     p_code_combination_id          => l_ccid
70502   , p_value_type_code              => l_adr_value_type_code
70503   , p_transaction_coa_id           => l_adr_transaction_coa_id
70504   , p_accounting_coa_id            => l_adr_accounting_coa_id
70505   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
70506   , p_adr_type_code                => 'S'
70507   , p_component_type               => l_component_type
70508   , p_component_code               => l_component_code
70509   , p_component_type_code          => l_component_type_code
70510   , p_component_appl_id            => l_component_appl_id
70511   , p_amb_context_code             => l_amb_context_code
70512   , p_side                         => 'NA'
70513   );
70514 
70515 
70516    l_segment := AcctDerRule_150(
70517            p_application_id           => p_application_id
70518          , p_ae_header_id             => l_ae_header_id 
70519 , p_source_3 => p_source_3
70520 , p_source_11 => p_source_11
70521          , x_transaction_coa_id       => l_adr_transaction_coa_id
70522          , x_accounting_coa_id        => l_adr_accounting_coa_id
70523          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
70524          , x_flex_value_set_id        => l_adr_flex_value_set_id
70525          , x_value_type_code          => l_adr_value_type_code
70526          , x_value_combination_id     => l_adr_value_combination_id
70527          , x_value_segment_code       => l_adr_value_segment_code
70528          , p_side                     => 'NA'
70529          , p_override_seg_flag        => 'Y'
70530    );
70531 
70532    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
70533 
70534       xla_ae_lines_pkg.set_segment(
70535           p_to_segment_code         => 'GL_ACCOUNT'
70536         , p_segment_value           => l_segment
70537         , p_from_segment_code       => l_adr_value_segment_code
70538         , p_from_combination_id     => l_adr_value_combination_id
70539         , p_value_type_code         => l_adr_value_type_code
70540         , p_transaction_coa_id      => l_adr_transaction_coa_id
70541         , p_accounting_coa_id       => l_adr_accounting_coa_id
70542         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
70543         , p_flex_value_set_id       => l_adr_flex_value_set_id
70544         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
70545         , p_adr_type_code           => 'S'
70546         , p_component_type          => l_component_type
70547         , p_component_code          => l_component_code
70548         , p_component_type_code     => l_component_type_code
70549         , p_component_appl_id       => l_component_appl_id
70550         , p_amb_context_code        => l_amb_context_code
70551         , p_entity_code             => 'TRANSACTIONS'
70552         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
70553         , p_side                    => 'NA'
70554         );
70555 
70556   END IF;
70557 
70558    l_segment := AcctDerRule_168(
70559            p_application_id           => p_application_id
70560          , p_ae_header_id             => l_ae_header_id 
70561 , p_source_3 => p_source_3
70562 , p_source_29 => p_source_29
70566          , x_flex_value_set_id        => l_adr_flex_value_set_id
70563          , x_transaction_coa_id       => l_adr_transaction_coa_id
70564          , x_accounting_coa_id        => l_adr_accounting_coa_id
70565          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
70567          , x_value_type_code          => l_adr_value_type_code
70568          , x_value_combination_id     => l_adr_value_combination_id
70569          , x_value_segment_code       => l_adr_value_segment_code
70570          , p_side                     => 'NA'
70571          , p_override_seg_flag        => 'Y'
70572    );
70573 
70574    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
70575 
70576       xla_ae_lines_pkg.set_segment(
70577           p_to_segment_code         => 'GL_BALANCING'
70578         , p_segment_value           => l_segment
70579         , p_from_segment_code       => l_adr_value_segment_code
70580         , p_from_combination_id     => l_adr_value_combination_id
70581         , p_value_type_code         => l_adr_value_type_code
70582         , p_transaction_coa_id      => l_adr_transaction_coa_id
70583         , p_accounting_coa_id       => l_adr_accounting_coa_id
70584         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
70585         , p_flex_value_set_id       => l_adr_flex_value_set_id
70586         , p_adr_code                => 'FA_EXPENSE_ACCT'
70587         , p_adr_type_code           => 'S'
70588         , p_component_type          => l_component_type
70589         , p_component_code          => l_component_code
70590         , p_component_type_code     => l_component_type_code
70591         , p_component_appl_id       => l_component_appl_id
70592         , p_amb_context_code        => l_amb_context_code
70593         , p_entity_code             => 'TRANSACTIONS'
70594         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
70595         , p_side                    => 'NA'
70596         );
70597 
70598   END IF;
70599 
70600    --
70601    --
70602    END IF;
70603    --
70604    -- Bug 4922099
70605    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
70606           (NVL(l_enc_upg_option, 'N') = 'O')
70607         ) AND
70608         (l_bflow_method_code = 'PRIOR_ENTRY')
70609       )
70610    THEN
70611       IF
70612       --
70613       1 = 2
70614       --
70615       THEN
70616       xla_accounting_err_pkg.build_message
70617                                     (p_appli_s_name            => 'XLA'
70618                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
70619                                     ,p_token_1                 => 'LINE_NUMBER'
70620                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
70621                                     ,p_token_2                 => 'LINE_TYPE_NAME'
70622                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
70623                                                                              l_component_type
70624                                                                             ,l_component_code
70625                                                                             ,l_component_type_code
70626                                                                             ,l_component_appl_id
70627                                                                             ,l_amb_context_code
70628                                                                             ,l_entity_code
70629                                                                             ,l_event_class_code
70630                                                                            )
70631                                     ,p_token_3                 => 'OWNER'
70632                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
70633                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
70634                                                                           ,p_lookup_code    => l_component_type_code
70635                                                                          )
70636                                     ,p_token_4                 => 'PRODUCT_NAME'
70637                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
70638                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
70639                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
70640                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
70641                                     ,p_ae_header_id            =>  NULL
70642                                        );
70643 
70644         IF (C_LEVEL_ERROR>= g_log_level) THEN
70645                  trace
70646                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
70647                       ,p_level    => C_LEVEL_ERROR
70648                       ,p_module   => l_log_module);
70649         END IF;
70650       END IF;
70651    END IF;
70652    --
70653    --
70654    ------------------------------------------------------------------------------------------------
70655    -- 4219869 Business Flow
70656    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
70657    -- Prior Entry.  Currently, the following code is always generated.
70658    ------------------------------------------------------------------------------------------------
70659    XLA_AE_LINES_PKG.ValidateCurrentLine;
70660 
70661    ------------------------------------------------------------------------------------
70662    -- 4219869 Business Flow
70663    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
70664    ------------------------------------------------------------------------------------
70665    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
70666 
70670    ----------------------------------------------------------------------------------
70667    ----------------------------------------------------------------------------------
70668    -- 4219869 Business Flow
70669    -- Update journal entry status -- Need to generate this within IF <condition>
70671    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
70672          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
70673          ,p_balance_type_code => l_balance_type_code
70674          );
70675 
70676    -------------------------------------------------------------------------------------------
70677    -- 4262811 - Generate the Accrual Reversal lines
70678    -------------------------------------------------------------------------------------------
70679    BEGIN
70680       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
70681                               (g_array_event(p_event_id).array_value_num('header_index'));
70682       IF l_acc_rev_flag IS NULL THEN
70683          l_acc_rev_flag := 'N';
70684       END IF;
70685    EXCEPTION
70686       WHEN OTHERS THEN
70687          l_acc_rev_flag := 'N';
70688    END;
70689    --
70690    IF (l_acc_rev_flag = 'Y') THEN
70691 
70692        -- 4645092  ------------------------------------------------------------------------------
70693        -- To allow MPA report to determine if it should generate report process
70694        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
70695        ------------------------------------------------------------------------------------------
70696 
70697        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
70698        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
70699    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
70700    -- call ADRs
70701    -- Bug 4922099
70702    --
70703    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
70704         (NVL(l_actual_upg_option, 'N') = 'O') OR
70705         (NVL(l_enc_upg_option, 'N') = 'O')
70706       )
70707    THEN
70708    NULL;
70709    --
70710    --
70711    
70712   l_ccid := AcctDerRule_174(
70713            p_application_id           => p_application_id
70714          , p_ae_header_id             => l_ae_header_id 
70715 , p_source_3 => p_source_3
70716 , p_source_17 => p_source_17
70717 , p_source_30 => p_source_30
70718          , x_transaction_coa_id       => l_adr_transaction_coa_id
70719          , x_accounting_coa_id        => l_adr_accounting_coa_id
70720          , x_value_type_code          => l_adr_value_type_code
70721          , p_side                     => 'NA'
70722    );
70723 
70724    xla_ae_lines_pkg.set_ccid(
70725     p_code_combination_id          => l_ccid
70726   , p_value_type_code              => l_adr_value_type_code
70727   , p_transaction_coa_id           => l_adr_transaction_coa_id
70728   , p_accounting_coa_id            => l_adr_accounting_coa_id
70729   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
70730   , p_adr_type_code                => 'S'
70731   , p_component_type               => l_component_type
70732   , p_component_code               => l_component_code
70733   , p_component_type_code          => l_component_type_code
70734   , p_component_appl_id            => l_component_appl_id
70735   , p_amb_context_code             => l_amb_context_code
70736   , p_side                         => 'NA'
70737   );
70738 
70739 
70740    l_segment := AcctDerRule_150(
70741            p_application_id           => p_application_id
70742          , p_ae_header_id             => l_ae_header_id 
70743 , p_source_3 => p_source_3
70744 , p_source_11 => p_source_11
70745          , x_transaction_coa_id       => l_adr_transaction_coa_id
70746          , x_accounting_coa_id        => l_adr_accounting_coa_id
70747          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
70748          , x_flex_value_set_id        => l_adr_flex_value_set_id
70749          , x_value_type_code          => l_adr_value_type_code
70750          , x_value_combination_id     => l_adr_value_combination_id
70751          , x_value_segment_code       => l_adr_value_segment_code
70752          , p_side                     => 'NA'
70753          , p_override_seg_flag        => 'Y'
70754    );
70755 
70756    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
70757 
70758       xla_ae_lines_pkg.set_segment(
70759           p_to_segment_code         => 'GL_ACCOUNT'
70760         , p_segment_value           => l_segment
70761         , p_from_segment_code       => l_adr_value_segment_code
70762         , p_from_combination_id     => l_adr_value_combination_id
70763         , p_value_type_code         => l_adr_value_type_code
70764         , p_transaction_coa_id      => l_adr_transaction_coa_id
70765         , p_accounting_coa_id       => l_adr_accounting_coa_id
70766         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
70767         , p_flex_value_set_id       => l_adr_flex_value_set_id
70768         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
70769         , p_adr_type_code           => 'S'
70770         , p_component_type          => l_component_type
70771         , p_component_code          => l_component_code
70772         , p_component_type_code     => l_component_type_code
70773         , p_component_appl_id       => l_component_appl_id
70774         , p_amb_context_code        => l_amb_context_code
70775         , p_entity_code             => 'TRANSACTIONS'
70776         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
70777         , p_side                    => 'NA'
70778         );
70779 
70780   END IF;
70781 
70782    l_segment := AcctDerRule_168(
70783            p_application_id           => p_application_id
70784          , p_ae_header_id             => l_ae_header_id 
70785 , p_source_3 => p_source_3
70786 , p_source_29 => p_source_29
70787          , x_transaction_coa_id       => l_adr_transaction_coa_id
70791          , x_value_type_code          => l_adr_value_type_code
70788          , x_accounting_coa_id        => l_adr_accounting_coa_id
70789          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
70790          , x_flex_value_set_id        => l_adr_flex_value_set_id
70792          , x_value_combination_id     => l_adr_value_combination_id
70793          , x_value_segment_code       => l_adr_value_segment_code
70794          , p_side                     => 'NA'
70795          , p_override_seg_flag        => 'Y'
70796    );
70797 
70798    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
70799 
70800       xla_ae_lines_pkg.set_segment(
70801           p_to_segment_code         => 'GL_BALANCING'
70802         , p_segment_value           => l_segment
70803         , p_from_segment_code       => l_adr_value_segment_code
70804         , p_from_combination_id     => l_adr_value_combination_id
70805         , p_value_type_code         => l_adr_value_type_code
70806         , p_transaction_coa_id      => l_adr_transaction_coa_id
70807         , p_accounting_coa_id       => l_adr_accounting_coa_id
70808         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
70809         , p_flex_value_set_id       => l_adr_flex_value_set_id
70810         , p_adr_code                => 'FA_EXPENSE_ACCT'
70811         , p_adr_type_code           => 'S'
70812         , p_component_type          => l_component_type
70813         , p_component_code          => l_component_code
70814         , p_component_type_code     => l_component_type_code
70815         , p_component_appl_id       => l_component_appl_id
70816         , p_amb_context_code        => l_amb_context_code
70817         , p_entity_code             => 'TRANSACTIONS'
70818         , p_event_class_code        => 'CIP_UNIT_ADJUSTMENTS'
70819         , p_side                    => 'NA'
70820         );
70821 
70822   END IF;
70823 
70824    --
70825    --
70826    END IF;
70827 
70828        --
70829        -- Update the line information that should be overwritten
70830        --
70831        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
70832                                          p_header_num   => 1);
70833        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
70834 
70835        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
70836 
70837        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
70838           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
70839        END IF;
70840 
70841       --
70842       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
70843       --
70844       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
70845           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
70846       ELSE
70847           ---------------------------------------------------------------------------------------------------
70848           -- 4262811a Switch Sign
70849           ---------------------------------------------------------------------------------------------------
70850           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
70851           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
70852                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
70853           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
70854                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
70855           -- 5132302
70856           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
70857                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
70858 
70859       END IF;
70860 
70861       -- 4955764
70862       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
70863       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
70864 
70865 
70866       XLA_AE_LINES_PKG.ValidateCurrentLine;
70867       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
70868 
70869       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
70870                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
70871                ,p_balance_type_code => l_balance_type_code);
70872 
70873    END IF;
70874 
70875    -----------------------------------------------------------------------------------------
70876    -- 4262811 Multiperiod Accounting
70877    -----------------------------------------------------------------------------------------
70878      -- No MPA option is assigned.
70879 
70880 
70881 END IF;
70882 END IF;
70883 --
70884 
70885 --
70886 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
70887    trace
70888       (p_msg      => 'END of AcctLineType_252'
70889       ,p_level    => C_LEVEL_PROCEDURE
70890       ,p_module   => l_log_module);
70891 END IF;
70892 --
70893 EXCEPTION
70894   WHEN xla_exceptions_pkg.application_exception THEN
70895       RAISE;
70896   WHEN OTHERS THEN
70897        xla_exceptions_pkg.raise_message
70898            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_252');
70899 END AcctLineType_252;
70900 --
70901 
70902 ---------------------------------------
70903 --
70904 -- PRIVATE FUNCTION
70905 --         AcctLineType_253
70906 --
70907 ---------------------------------------
70908 PROCEDURE AcctLineType_253 (
70909   p_application_id        IN NUMBER
70910  ,p_event_id              IN NUMBER
70911  ,p_calculate_acctd_flag  IN VARCHAR2
70915  ,p_gain_or_loss_ref      OUT VARCHAR2
70912  ,p_calculate_g_l_flag    IN VARCHAR2
70913  ,p_actual_flag           IN OUT VARCHAR2
70914  ,p_balance_type_code     OUT VARCHAR2
70916  
70917 --Period Close Date
70918  , p_source_1            IN DATE
70919 --Generated Code Combination Identifier
70920  , p_source_3            IN NUMBER
70921 --Cost Of Removal Clearing Account
70922  , p_source_12            IN VARCHAR2
70923 --Expense Account Code Combination Identifier
70924  , p_source_29            IN NUMBER
70925 --Default Code Combination Identifier
70926  , p_source_30            IN NUMBER
70927 --Adjustment Type
70928  , p_source_35            IN VARCHAR2
70929 --Transaction Header Identifier
70930  , p_source_36            IN NUMBER
70931 --Adjustment Line Identifier
70932  , p_source_37            IN NUMBER
70933 --Distribution Type Code
70934  , p_source_38            IN VARCHAR2
70935 --Entered Amount
70936  , p_source_39            IN NUMBER
70937 --Currency Code
70938  , p_source_40            IN VARCHAR2
70939 )
70940 IS
70941 
70942 l_component_type              VARCHAR2(80);
70943 l_component_code              VARCHAR2(30);
70944 l_component_type_code         VARCHAR2(1);
70945 l_component_appl_id           INTEGER;
70946 l_amb_context_code            VARCHAR2(30);
70947 l_entity_code                 VARCHAR2(30);
70948 l_event_class_code            VARCHAR2(30);
70949 l_ae_header_id                NUMBER;
70950 l_event_type_code             VARCHAR2(30);
70951 l_line_definition_code        VARCHAR2(30);
70952 l_line_definition_owner_code  VARCHAR2(1);
70953 --
70954 -- adr variables
70955 l_segment                     VARCHAR2(30);
70956 l_ccid                        NUMBER;
70957 l_adr_transaction_coa_id      NUMBER;
70958 l_adr_accounting_coa_id       NUMBER;
70959 l_adr_flexfield_segment_code  VARCHAR2(30);
70960 l_adr_flex_value_set_id       NUMBER;
70961 l_adr_value_type_code         VARCHAR2(30);
70962 l_adr_value_combination_id    NUMBER;
70963 l_adr_value_segment_code      VARCHAR2(30);
70964 
70965 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
70966 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
70967 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
70968 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
70969 
70970 -- 4262811 Variables ------------------------------------------------------------------------------------------
70971 l_entered_amt_idx             NUMBER;
70972 l_accted_amt_idx              NUMBER;
70973 l_acc_rev_flag                VARCHAR2(1);
70974 l_accrual_line_num            NUMBER;
70975 l_tmp_amt                     NUMBER;
70976 l_acc_rev_natural_side_code   VARCHAR2(1);
70977 
70978 l_num_entries                 NUMBER;
70979 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
70980 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
70981 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
70982 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
70983 l_recog_line_1                NUMBER;
70984 l_recog_line_2                NUMBER;
70985 
70986 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
70987 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
70988 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
70989 
70990 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
70991 
70992 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
70993 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
70994 
70995 ---------------------------------------------------------------------------------------------------------------
70996 
70997 
70998 --
70999 -- bulk performance
71000 --
71001 l_balance_type_code           VARCHAR2(1);
71002 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
71003 l_log_module                  VARCHAR2(240);
71004 
71005 --
71006 -- Upgrade strategy
71007 --
71008 l_actual_upg_option           VARCHAR2(1);
71009 l_enc_upg_option           VARCHAR2(1);
71010 
71011 --
71012 BEGIN
71013 --
71014 IF g_log_enabled THEN
71015       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_253';
71016 END IF;
71017 --
71018 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
71019 
71020       trace
71021          (p_msg      => 'BEGIN of AcctLineType_253'
71022          ,p_level    => C_LEVEL_PROCEDURE
71023          ,p_module   => l_log_module);
71024 
71025 END IF;
71026 --
71027 l_component_type             := 'AMB_JLT';
71028 l_component_code             := 'FA_COST_OF_REMOVAL_CLR';
71029 l_component_type_code        := 'S';
71030 l_component_appl_id          :=  140;
71031 l_amb_context_code           := 'DEFAULT';
71032 l_entity_code                := 'TRANSACTIONS';
71033 l_event_class_code           := 'RETIREMENTS';
71034 l_event_type_code            := 'RETIREMENTS';
71035 l_line_definition_owner_code := 'S';
71036 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
71037 --
71038 l_balance_type_code          := 'A';
71039 l_segment                     := NULL;
71040 l_ccid                        := NULL;
71041 l_adr_transaction_coa_id      := NULL;
71042 l_adr_accounting_coa_id       := NULL;
71043 l_adr_flexfield_segment_code  := NULL;
71044 l_adr_flex_value_set_id       := NULL;
71045 l_adr_value_type_code         := NULL;
71046 l_adr_value_combination_id    := NULL;
71047 l_adr_value_segment_code      := NULL;
71048 
71049 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
71050 l_bflow_class_code           := '';    -- 4219869 Business Flow
71051 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
71055 l_bflow_applied_to_amt       := NULL; -- 5132302
71052 l_budgetary_control_flag     := 'N';
71053 
71054 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
71056 l_entered_amt_idx            := NULL;          -- 4262811
71057 l_accted_amt_idx             := NULL;          -- 4262811
71058 l_acc_rev_flag               := NULL;          -- 4262811
71059 l_accrual_line_num           := NULL;          -- 4262811
71060 l_tmp_amt                    := NULL;          -- 4262811
71061 --
71062  
71063 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
71064     l_balance_type_code <> 'B' THEN
71065 IF NVL(p_source_35,'
71066 ') =  'REMOVALCOST CLR'
71067  THEN 
71068 
71069    --
71070    XLA_AE_LINES_PKG.SetNewLine;
71071 
71072    p_balance_type_code          := l_balance_type_code;
71073    -- set the flag so later we will know whether the gain loss line needs to be created
71074    
71075    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
71076      p_actual_flag :='A';
71077    END IF;
71078 
71079    --
71080    -- bulk performance
71081    --
71082    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
71083                                       p_header_num   => 0); -- 4262811
71084    --
71085    -- set accounting line options
71086    --
71087    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
71088            p_natural_side_code          => 'C'
71089          , p_gain_or_loss_flag          => 'N'
71090          , p_gl_transfer_mode_code      => 'S'
71091          , p_acct_entry_type_code       => 'A'
71092          , p_switch_side_flag           => 'Y'
71093          , p_merge_duplicate_code       => 'N'
71094          );
71095    --
71096    l_acc_rev_natural_side_code := 'D';  -- 4262811
71097    -- 
71098    --
71099    -- set accounting line type info
71100    --
71101    xla_ae_lines_pkg.SetAcctLineType
71102       (p_component_type             => l_component_type
71103       ,p_event_type_code            => l_event_type_code
71104       ,p_line_definition_owner_code => l_line_definition_owner_code
71105       ,p_line_definition_code       => l_line_definition_code
71106       ,p_accounting_line_code       => l_component_code
71107       ,p_accounting_line_type_code  => l_component_type_code
71108       ,p_accounting_line_appl_id    => l_component_appl_id
71109       ,p_amb_context_code           => l_amb_context_code
71110       ,p_entity_code                => l_entity_code
71111       ,p_event_class_code           => l_event_class_code);
71112    --
71113    -- set accounting class
71114    --
71115    xla_ae_lines_pkg.SetAcctClass(
71116            p_accounting_class_code  => 'ASSET'
71117          , p_ae_header_id           => l_ae_header_id
71118          );
71119 
71120    --
71121    -- set rounding class
71122    --
71123    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
71124                       'ASSET';
71125 
71126    --
71127    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
71128    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
71129    --
71130    -- bulk performance
71131    --
71132    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
71133 
71134    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
71135       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
71136 
71137    -- 4955764
71138    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
71139       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
71140 
71141    -- 4458381 Public Sector Enh
71142    
71143    --
71144    -- set accounting attributes for the line type
71145    --
71146    l_entered_amt_idx := 4;
71147    l_accted_amt_idx  := 6;
71148    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
71149    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
71150    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
71151    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
71152    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
71153    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
71154    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
71155    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
71156    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
71157    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
71158    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
71159    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
71160    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
71161 
71162    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
71163    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
71164 
71165    ---------------------------------------------------------------------------------------------------------------
71166    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
71167    ---------------------------------------------------------------------------------------------------------------
71168    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
71169 
71170    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
71171    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
71172 
71173    IF xla_accounting_cache_pkg.GetValueChar
71174          (p_source_code         => 'LEDGER_CATEGORY_CODE'
71178    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
71175          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
71176    AND l_bflow_method_code = 'PRIOR_ENTRY'
71177 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
71179          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
71180        )
71181    THEN
71182          xla_ae_lines_pkg.BflowUpgEntry
71183            (p_business_method_code    => l_bflow_method_code
71184            ,p_business_class_code     => l_bflow_class_code
71185            ,p_balance_type            => l_balance_type_code);
71186    ELSE
71187       NULL;
71188 -- No business flow processing for business flow method of NONE.
71189    END IF;
71190 
71191    --
71192    -- call analytical criteria
71193    --
71194    
71195    --
71196    -- call description
71197    --
71198    
71199 xla_ae_lines_pkg.SetLineDescription(
71200    p_ae_header_id => l_ae_header_id
71201   ,p_description  => Description_87 (
71202      p_application_id         => p_application_id
71203    , p_ae_header_id           => l_ae_header_id 
71204 , p_source_1 => p_source_1
71205    )
71206 );
71207 
71208 
71209    --
71210    -- call ADRs
71211    -- Bug 4922099
71212    --
71213    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
71214         (NVL(l_actual_upg_option, 'N') = 'O') OR
71215         (NVL(l_enc_upg_option, 'N') = 'O')
71216       )
71217    THEN
71218    NULL;
71219    --
71220    --
71221    
71222   l_ccid := AcctDerRule_173(
71223            p_application_id           => p_application_id
71224          , p_ae_header_id             => l_ae_header_id 
71225 , p_source_3 => p_source_3
71226 , p_source_30 => p_source_30
71227          , x_transaction_coa_id       => l_adr_transaction_coa_id
71228          , x_accounting_coa_id        => l_adr_accounting_coa_id
71229          , x_value_type_code          => l_adr_value_type_code
71230          , p_side                     => 'NA'
71231    );
71232 
71233    xla_ae_lines_pkg.set_ccid(
71234     p_code_combination_id          => l_ccid
71235   , p_value_type_code              => l_adr_value_type_code
71236   , p_transaction_coa_id           => l_adr_transaction_coa_id
71237   , p_accounting_coa_id            => l_adr_accounting_coa_id
71238   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
71239   , p_adr_type_code                => 'S'
71240   , p_component_type               => l_component_type
71241   , p_component_code               => l_component_code
71242   , p_component_type_code          => l_component_type_code
71243   , p_component_appl_id            => l_component_appl_id
71244   , p_amb_context_code             => l_amb_context_code
71245   , p_side                         => 'NA'
71246   );
71247 
71248 
71249    l_segment := AcctDerRule_151(
71250            p_application_id           => p_application_id
71251          , p_ae_header_id             => l_ae_header_id 
71252 , p_source_3 => p_source_3
71253 , p_source_12 => p_source_12
71254          , x_transaction_coa_id       => l_adr_transaction_coa_id
71255          , x_accounting_coa_id        => l_adr_accounting_coa_id
71256          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
71257          , x_flex_value_set_id        => l_adr_flex_value_set_id
71258          , x_value_type_code          => l_adr_value_type_code
71259          , x_value_combination_id     => l_adr_value_combination_id
71260          , x_value_segment_code       => l_adr_value_segment_code
71261          , p_side                     => 'NA'
71262          , p_override_seg_flag        => 'Y'
71263    );
71264 
71265    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
71266 
71267       xla_ae_lines_pkg.set_segment(
71268           p_to_segment_code         => 'GL_ACCOUNT'
71269         , p_segment_value           => l_segment
71270         , p_from_segment_code       => l_adr_value_segment_code
71271         , p_from_combination_id     => l_adr_value_combination_id
71272         , p_value_type_code         => l_adr_value_type_code
71273         , p_transaction_coa_id      => l_adr_transaction_coa_id
71274         , p_accounting_coa_id       => l_adr_accounting_coa_id
71275         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
71276         , p_flex_value_set_id       => l_adr_flex_value_set_id
71277         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
71278         , p_adr_type_code           => 'S'
71279         , p_component_type          => l_component_type
71280         , p_component_code          => l_component_code
71281         , p_component_type_code     => l_component_type_code
71282         , p_component_appl_id       => l_component_appl_id
71283         , p_amb_context_code        => l_amb_context_code
71284         , p_entity_code             => 'TRANSACTIONS'
71285         , p_event_class_code        => 'RETIREMENTS'
71286         , p_side                    => 'NA'
71287         );
71288 
71289   END IF;
71290 
71291    l_segment := AcctDerRule_168(
71292            p_application_id           => p_application_id
71293          , p_ae_header_id             => l_ae_header_id 
71294 , p_source_3 => p_source_3
71295 , p_source_29 => p_source_29
71296          , x_transaction_coa_id       => l_adr_transaction_coa_id
71297          , x_accounting_coa_id        => l_adr_accounting_coa_id
71298          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
71299          , x_flex_value_set_id        => l_adr_flex_value_set_id
71300          , x_value_type_code          => l_adr_value_type_code
71301          , x_value_combination_id     => l_adr_value_combination_id
71302          , x_value_segment_code       => l_adr_value_segment_code
71303          , p_side                     => 'NA'
71304          , p_override_seg_flag        => 'Y'
71305    );
71306 
71310           p_to_segment_code         => 'GL_BALANCING'
71307    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
71308 
71309       xla_ae_lines_pkg.set_segment(
71311         , p_segment_value           => l_segment
71312         , p_from_segment_code       => l_adr_value_segment_code
71313         , p_from_combination_id     => l_adr_value_combination_id
71314         , p_value_type_code         => l_adr_value_type_code
71315         , p_transaction_coa_id      => l_adr_transaction_coa_id
71316         , p_accounting_coa_id       => l_adr_accounting_coa_id
71317         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
71318         , p_flex_value_set_id       => l_adr_flex_value_set_id
71319         , p_adr_code                => 'FA_EXPENSE_ACCT'
71320         , p_adr_type_code           => 'S'
71321         , p_component_type          => l_component_type
71322         , p_component_code          => l_component_code
71323         , p_component_type_code     => l_component_type_code
71324         , p_component_appl_id       => l_component_appl_id
71325         , p_amb_context_code        => l_amb_context_code
71326         , p_entity_code             => 'TRANSACTIONS'
71327         , p_event_class_code        => 'RETIREMENTS'
71328         , p_side                    => 'NA'
71329         );
71330 
71331   END IF;
71332 
71333    --
71334    --
71335    END IF;
71336    --
71337    -- Bug 4922099
71338    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
71339           (NVL(l_enc_upg_option, 'N') = 'O')
71340         ) AND
71341         (l_bflow_method_code = 'PRIOR_ENTRY')
71342       )
71343    THEN
71344       IF
71345       --
71346       1 = 2
71347       --
71348       THEN
71349       xla_accounting_err_pkg.build_message
71350                                     (p_appli_s_name            => 'XLA'
71351                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
71352                                     ,p_token_1                 => 'LINE_NUMBER'
71353                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
71354                                     ,p_token_2                 => 'LINE_TYPE_NAME'
71355                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
71356                                                                              l_component_type
71357                                                                             ,l_component_code
71358                                                                             ,l_component_type_code
71359                                                                             ,l_component_appl_id
71360                                                                             ,l_amb_context_code
71361                                                                             ,l_entity_code
71362                                                                             ,l_event_class_code
71363                                                                            )
71364                                     ,p_token_3                 => 'OWNER'
71365                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
71366                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
71367                                                                           ,p_lookup_code    => l_component_type_code
71368                                                                          )
71369                                     ,p_token_4                 => 'PRODUCT_NAME'
71370                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
71371                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
71372                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
71373                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
71374                                     ,p_ae_header_id            =>  NULL
71375                                        );
71376 
71377         IF (C_LEVEL_ERROR>= g_log_level) THEN
71378                  trace
71379                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
71380                       ,p_level    => C_LEVEL_ERROR
71381                       ,p_module   => l_log_module);
71382         END IF;
71383       END IF;
71384    END IF;
71385    --
71386    --
71387    ------------------------------------------------------------------------------------------------
71388    -- 4219869 Business Flow
71389    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
71390    -- Prior Entry.  Currently, the following code is always generated.
71391    ------------------------------------------------------------------------------------------------
71392    XLA_AE_LINES_PKG.ValidateCurrentLine;
71393 
71394    ------------------------------------------------------------------------------------
71395    -- 4219869 Business Flow
71396    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
71397    ------------------------------------------------------------------------------------
71398    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
71399 
71400    ----------------------------------------------------------------------------------
71401    -- 4219869 Business Flow
71402    -- Update journal entry status -- Need to generate this within IF <condition>
71403    ----------------------------------------------------------------------------------
71404    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
71405          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
71406          ,p_balance_type_code => l_balance_type_code
71407          );
71408 
71409    -------------------------------------------------------------------------------------------
71413       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
71410    -- 4262811 - Generate the Accrual Reversal lines
71411    -------------------------------------------------------------------------------------------
71412    BEGIN
71414                               (g_array_event(p_event_id).array_value_num('header_index'));
71415       IF l_acc_rev_flag IS NULL THEN
71416          l_acc_rev_flag := 'N';
71417       END IF;
71418    EXCEPTION
71419       WHEN OTHERS THEN
71420          l_acc_rev_flag := 'N';
71421    END;
71422    --
71423    IF (l_acc_rev_flag = 'Y') THEN
71424 
71425        -- 4645092  ------------------------------------------------------------------------------
71426        -- To allow MPA report to determine if it should generate report process
71427        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
71428        ------------------------------------------------------------------------------------------
71429 
71430        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
71431        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
71432    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
71433    -- call ADRs
71434    -- Bug 4922099
71435    --
71436    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
71437         (NVL(l_actual_upg_option, 'N') = 'O') OR
71438         (NVL(l_enc_upg_option, 'N') = 'O')
71439       )
71440    THEN
71441    NULL;
71442    --
71443    --
71444    
71445   l_ccid := AcctDerRule_173(
71446            p_application_id           => p_application_id
71447          , p_ae_header_id             => l_ae_header_id 
71448 , p_source_3 => p_source_3
71449 , p_source_30 => p_source_30
71450          , x_transaction_coa_id       => l_adr_transaction_coa_id
71451          , x_accounting_coa_id        => l_adr_accounting_coa_id
71452          , x_value_type_code          => l_adr_value_type_code
71453          , p_side                     => 'NA'
71454    );
71455 
71456    xla_ae_lines_pkg.set_ccid(
71457     p_code_combination_id          => l_ccid
71458   , p_value_type_code              => l_adr_value_type_code
71459   , p_transaction_coa_id           => l_adr_transaction_coa_id
71460   , p_accounting_coa_id            => l_adr_accounting_coa_id
71461   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
71462   , p_adr_type_code                => 'S'
71463   , p_component_type               => l_component_type
71464   , p_component_code               => l_component_code
71465   , p_component_type_code          => l_component_type_code
71466   , p_component_appl_id            => l_component_appl_id
71467   , p_amb_context_code             => l_amb_context_code
71468   , p_side                         => 'NA'
71469   );
71470 
71471 
71472    l_segment := AcctDerRule_151(
71473            p_application_id           => p_application_id
71474          , p_ae_header_id             => l_ae_header_id 
71475 , p_source_3 => p_source_3
71476 , p_source_12 => p_source_12
71477          , x_transaction_coa_id       => l_adr_transaction_coa_id
71478          , x_accounting_coa_id        => l_adr_accounting_coa_id
71479          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
71480          , x_flex_value_set_id        => l_adr_flex_value_set_id
71481          , x_value_type_code          => l_adr_value_type_code
71482          , x_value_combination_id     => l_adr_value_combination_id
71483          , x_value_segment_code       => l_adr_value_segment_code
71484          , p_side                     => 'NA'
71485          , p_override_seg_flag        => 'Y'
71486    );
71487 
71488    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
71489 
71490       xla_ae_lines_pkg.set_segment(
71491           p_to_segment_code         => 'GL_ACCOUNT'
71492         , p_segment_value           => l_segment
71493         , p_from_segment_code       => l_adr_value_segment_code
71494         , p_from_combination_id     => l_adr_value_combination_id
71495         , p_value_type_code         => l_adr_value_type_code
71496         , p_transaction_coa_id      => l_adr_transaction_coa_id
71497         , p_accounting_coa_id       => l_adr_accounting_coa_id
71498         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
71499         , p_flex_value_set_id       => l_adr_flex_value_set_id
71500         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
71501         , p_adr_type_code           => 'S'
71502         , p_component_type          => l_component_type
71503         , p_component_code          => l_component_code
71504         , p_component_type_code     => l_component_type_code
71505         , p_component_appl_id       => l_component_appl_id
71506         , p_amb_context_code        => l_amb_context_code
71507         , p_entity_code             => 'TRANSACTIONS'
71508         , p_event_class_code        => 'RETIREMENTS'
71509         , p_side                    => 'NA'
71510         );
71511 
71512   END IF;
71513 
71514    l_segment := AcctDerRule_168(
71515            p_application_id           => p_application_id
71516          , p_ae_header_id             => l_ae_header_id 
71517 , p_source_3 => p_source_3
71518 , p_source_29 => p_source_29
71519          , x_transaction_coa_id       => l_adr_transaction_coa_id
71520          , x_accounting_coa_id        => l_adr_accounting_coa_id
71521          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
71522          , x_flex_value_set_id        => l_adr_flex_value_set_id
71523          , x_value_type_code          => l_adr_value_type_code
71524          , x_value_combination_id     => l_adr_value_combination_id
71525          , x_value_segment_code       => l_adr_value_segment_code
71526          , p_side                     => 'NA'
71527          , p_override_seg_flag        => 'Y'
71528    );
71529 
71530    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
71531 
71532       xla_ae_lines_pkg.set_segment(
71536         , p_from_combination_id     => l_adr_value_combination_id
71533           p_to_segment_code         => 'GL_BALANCING'
71534         , p_segment_value           => l_segment
71535         , p_from_segment_code       => l_adr_value_segment_code
71537         , p_value_type_code         => l_adr_value_type_code
71538         , p_transaction_coa_id      => l_adr_transaction_coa_id
71539         , p_accounting_coa_id       => l_adr_accounting_coa_id
71540         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
71541         , p_flex_value_set_id       => l_adr_flex_value_set_id
71542         , p_adr_code                => 'FA_EXPENSE_ACCT'
71543         , p_adr_type_code           => 'S'
71544         , p_component_type          => l_component_type
71545         , p_component_code          => l_component_code
71546         , p_component_type_code     => l_component_type_code
71547         , p_component_appl_id       => l_component_appl_id
71548         , p_amb_context_code        => l_amb_context_code
71549         , p_entity_code             => 'TRANSACTIONS'
71550         , p_event_class_code        => 'RETIREMENTS'
71551         , p_side                    => 'NA'
71552         );
71553 
71554   END IF;
71555 
71556    --
71557    --
71558    END IF;
71559 
71560        --
71561        -- Update the line information that should be overwritten
71562        --
71563        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
71564                                          p_header_num   => 1);
71565        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
71566 
71567        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
71568 
71569        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
71570           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
71571        END IF;
71572 
71573       --
71574       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
71575       --
71576       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
71577           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
71578       ELSE
71579           ---------------------------------------------------------------------------------------------------
71580           -- 4262811a Switch Sign
71581           ---------------------------------------------------------------------------------------------------
71582           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
71583           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
71584                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
71585           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
71586                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
71587           -- 5132302
71588           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
71589                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
71590 
71591       END IF;
71592 
71593       -- 4955764
71594       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
71595       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
71596 
71597 
71598       XLA_AE_LINES_PKG.ValidateCurrentLine;
71599       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
71600 
71601       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
71602                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
71603                ,p_balance_type_code => l_balance_type_code);
71604 
71605    END IF;
71606 
71607    -----------------------------------------------------------------------------------------
71608    -- 4262811 Multiperiod Accounting
71609    -----------------------------------------------------------------------------------------
71610      -- No MPA option is assigned.
71611 
71612 
71613 END IF;
71614 END IF;
71615 --
71616 
71617 --
71618 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
71619    trace
71620       (p_msg      => 'END of AcctLineType_253'
71621       ,p_level    => C_LEVEL_PROCEDURE
71622       ,p_module   => l_log_module);
71623 END IF;
71624 --
71625 EXCEPTION
71626   WHEN xla_exceptions_pkg.application_exception THEN
71627       RAISE;
71628   WHEN OTHERS THEN
71629        xla_exceptions_pkg.raise_message
71630            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_253');
71631 END AcctLineType_253;
71632 --
71633 
71634 ---------------------------------------
71635 --
71636 -- PRIVATE FUNCTION
71637 --         AcctLineType_254
71638 --
71639 ---------------------------------------
71640 PROCEDURE AcctLineType_254 (
71641   p_application_id        IN NUMBER
71642  ,p_event_id              IN NUMBER
71643  ,p_calculate_acctd_flag  IN VARCHAR2
71644  ,p_calculate_g_l_flag    IN VARCHAR2
71645  ,p_actual_flag           IN OUT VARCHAR2
71646  ,p_balance_type_code     OUT VARCHAR2
71647  ,p_gain_or_loss_ref      OUT VARCHAR2
71648  
71649 --Period Close Date
71650  , p_source_1            IN DATE
71651 --Generated Code Combination Identifier
71652  , p_source_3            IN NUMBER
71653 --Cost Of Removal Clearing Account
71654  , p_source_12            IN VARCHAR2
71655 --Expense Account Code Combination Identifier
71656  , p_source_29            IN NUMBER
71657 --Default Code Combination Identifier
71658  , p_source_30            IN NUMBER
71659 --Adjustment Type
71660  , p_source_35            IN VARCHAR2
71664  , p_source_37            IN NUMBER
71661 --Transaction Header Identifier
71662  , p_source_36            IN NUMBER
71663 --Adjustment Line Identifier
71665 --Distribution Type Code
71666  , p_source_38            IN VARCHAR2
71667 --Entered Amount
71668  , p_source_39            IN NUMBER
71669 --Currency Code
71670  , p_source_40            IN VARCHAR2
71671 )
71672 IS
71673 
71674 l_component_type              VARCHAR2(80);
71675 l_component_code              VARCHAR2(30);
71676 l_component_type_code         VARCHAR2(1);
71677 l_component_appl_id           INTEGER;
71678 l_amb_context_code            VARCHAR2(30);
71679 l_entity_code                 VARCHAR2(30);
71680 l_event_class_code            VARCHAR2(30);
71681 l_ae_header_id                NUMBER;
71682 l_event_type_code             VARCHAR2(30);
71683 l_line_definition_code        VARCHAR2(30);
71684 l_line_definition_owner_code  VARCHAR2(1);
71685 --
71686 -- adr variables
71687 l_segment                     VARCHAR2(30);
71688 l_ccid                        NUMBER;
71689 l_adr_transaction_coa_id      NUMBER;
71690 l_adr_accounting_coa_id       NUMBER;
71691 l_adr_flexfield_segment_code  VARCHAR2(30);
71692 l_adr_flex_value_set_id       NUMBER;
71693 l_adr_value_type_code         VARCHAR2(30);
71694 l_adr_value_combination_id    NUMBER;
71695 l_adr_value_segment_code      VARCHAR2(30);
71696 
71697 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
71698 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
71699 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
71700 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
71701 
71702 -- 4262811 Variables ------------------------------------------------------------------------------------------
71703 l_entered_amt_idx             NUMBER;
71704 l_accted_amt_idx              NUMBER;
71705 l_acc_rev_flag                VARCHAR2(1);
71706 l_accrual_line_num            NUMBER;
71707 l_tmp_amt                     NUMBER;
71708 l_acc_rev_natural_side_code   VARCHAR2(1);
71709 
71710 l_num_entries                 NUMBER;
71711 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
71712 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
71713 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
71714 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
71715 l_recog_line_1                NUMBER;
71716 l_recog_line_2                NUMBER;
71717 
71718 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
71719 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
71720 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
71721 
71722 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
71723 
71724 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
71725 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
71726 
71727 ---------------------------------------------------------------------------------------------------------------
71728 
71729 
71730 --
71731 -- bulk performance
71732 --
71733 l_balance_type_code           VARCHAR2(1);
71734 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
71735 l_log_module                  VARCHAR2(240);
71736 
71737 --
71738 -- Upgrade strategy
71739 --
71740 l_actual_upg_option           VARCHAR2(1);
71741 l_enc_upg_option           VARCHAR2(1);
71742 
71743 --
71744 BEGIN
71745 --
71746 IF g_log_enabled THEN
71747       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_254';
71748 END IF;
71749 --
71750 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
71751 
71752       trace
71753          (p_msg      => 'BEGIN of AcctLineType_254'
71754          ,p_level    => C_LEVEL_PROCEDURE
71755          ,p_module   => l_log_module);
71756 
71757 END IF;
71758 --
71759 l_component_type             := 'AMB_JLT';
71760 l_component_code             := 'FA_COST_OF_REMOVAL_CLR';
71761 l_component_type_code        := 'S';
71762 l_component_appl_id          :=  140;
71763 l_amb_context_code           := 'DEFAULT';
71764 l_entity_code                := 'TRANSACTIONS';
71765 l_event_class_code           := 'RETIREMENTS';
71766 l_event_type_code            := 'REINSTATEMENTS';
71767 l_line_definition_owner_code := 'S';
71768 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
71769 --
71770 l_balance_type_code          := 'A';
71771 l_segment                     := NULL;
71772 l_ccid                        := NULL;
71773 l_adr_transaction_coa_id      := NULL;
71774 l_adr_accounting_coa_id       := NULL;
71775 l_adr_flexfield_segment_code  := NULL;
71776 l_adr_flex_value_set_id       := NULL;
71777 l_adr_value_type_code         := NULL;
71778 l_adr_value_combination_id    := NULL;
71779 l_adr_value_segment_code      := NULL;
71780 
71781 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
71782 l_bflow_class_code           := '';    -- 4219869 Business Flow
71783 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
71784 l_budgetary_control_flag     := 'N';
71785 
71786 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
71787 l_bflow_applied_to_amt       := NULL; -- 5132302
71788 l_entered_amt_idx            := NULL;          -- 4262811
71789 l_accted_amt_idx             := NULL;          -- 4262811
71790 l_acc_rev_flag               := NULL;          -- 4262811
71791 l_accrual_line_num           := NULL;          -- 4262811
71792 l_tmp_amt                    := NULL;          -- 4262811
71793 --
71794  
71795 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
71796     l_balance_type_code <> 'B' THEN
71797 IF NVL(p_source_35,'
71801    --
71798 ') =  'REMOVALCOST CLR'
71799  THEN 
71800 
71802    XLA_AE_LINES_PKG.SetNewLine;
71803 
71804    p_balance_type_code          := l_balance_type_code;
71805    -- set the flag so later we will know whether the gain loss line needs to be created
71806    
71807    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
71808      p_actual_flag :='A';
71809    END IF;
71810 
71811    --
71812    -- bulk performance
71813    --
71814    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
71815                                       p_header_num   => 0); -- 4262811
71816    --
71817    -- set accounting line options
71818    --
71819    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
71820            p_natural_side_code          => 'C'
71821          , p_gain_or_loss_flag          => 'N'
71822          , p_gl_transfer_mode_code      => 'S'
71823          , p_acct_entry_type_code       => 'A'
71824          , p_switch_side_flag           => 'Y'
71825          , p_merge_duplicate_code       => 'N'
71826          );
71827    --
71828    l_acc_rev_natural_side_code := 'D';  -- 4262811
71829    -- 
71830    --
71831    -- set accounting line type info
71832    --
71833    xla_ae_lines_pkg.SetAcctLineType
71834       (p_component_type             => l_component_type
71835       ,p_event_type_code            => l_event_type_code
71836       ,p_line_definition_owner_code => l_line_definition_owner_code
71837       ,p_line_definition_code       => l_line_definition_code
71838       ,p_accounting_line_code       => l_component_code
71839       ,p_accounting_line_type_code  => l_component_type_code
71840       ,p_accounting_line_appl_id    => l_component_appl_id
71841       ,p_amb_context_code           => l_amb_context_code
71842       ,p_entity_code                => l_entity_code
71843       ,p_event_class_code           => l_event_class_code);
71844    --
71845    -- set accounting class
71846    --
71847    xla_ae_lines_pkg.SetAcctClass(
71848            p_accounting_class_code  => 'ASSET'
71849          , p_ae_header_id           => l_ae_header_id
71850          );
71851 
71852    --
71853    -- set rounding class
71854    --
71855    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
71856                       'ASSET';
71857 
71858    --
71859    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
71860    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
71861    --
71862    -- bulk performance
71863    --
71864    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
71865 
71866    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
71867       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
71868 
71869    -- 4955764
71870    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
71871       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
71872 
71873    -- 4458381 Public Sector Enh
71874    
71875    --
71876    -- set accounting attributes for the line type
71877    --
71878    l_entered_amt_idx := 4;
71879    l_accted_amt_idx  := 6;
71880    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
71881    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
71882    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
71883    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
71884    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
71885    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
71886    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
71887    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
71888    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
71889    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
71890    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
71891    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
71892    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
71893 
71894    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
71895    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
71896 
71897    ---------------------------------------------------------------------------------------------------------------
71898    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
71899    ---------------------------------------------------------------------------------------------------------------
71900    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
71901 
71902    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
71903    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
71904 
71905    IF xla_accounting_cache_pkg.GetValueChar
71906          (p_source_code         => 'LEDGER_CATEGORY_CODE'
71907          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
71908    AND l_bflow_method_code = 'PRIOR_ENTRY'
71909 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
71910    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
71911          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
71912        )
71913    THEN
71914          xla_ae_lines_pkg.BflowUpgEntry
71915            (p_business_method_code    => l_bflow_method_code
71916            ,p_business_class_code     => l_bflow_class_code
71917            ,p_balance_type            => l_balance_type_code);
71918    ELSE
71919       NULL;
71920 -- No business flow processing for business flow method of NONE.
71924    -- call analytical criteria
71921    END IF;
71922 
71923    --
71925    --
71926    
71927    --
71928    -- call description
71929    --
71930    
71931 xla_ae_lines_pkg.SetLineDescription(
71932    p_ae_header_id => l_ae_header_id
71933   ,p_description  => Description_87 (
71934      p_application_id         => p_application_id
71935    , p_ae_header_id           => l_ae_header_id 
71936 , p_source_1 => p_source_1
71937    )
71938 );
71939 
71940 
71941    --
71942    -- call ADRs
71943    -- Bug 4922099
71944    --
71945    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
71946         (NVL(l_actual_upg_option, 'N') = 'O') OR
71947         (NVL(l_enc_upg_option, 'N') = 'O')
71948       )
71949    THEN
71950    NULL;
71951    --
71952    --
71953    
71954   l_ccid := AcctDerRule_173(
71955            p_application_id           => p_application_id
71956          , p_ae_header_id             => l_ae_header_id 
71957 , p_source_3 => p_source_3
71958 , p_source_30 => p_source_30
71959          , x_transaction_coa_id       => l_adr_transaction_coa_id
71960          , x_accounting_coa_id        => l_adr_accounting_coa_id
71961          , x_value_type_code          => l_adr_value_type_code
71962          , p_side                     => 'NA'
71963    );
71964 
71965    xla_ae_lines_pkg.set_ccid(
71966     p_code_combination_id          => l_ccid
71967   , p_value_type_code              => l_adr_value_type_code
71968   , p_transaction_coa_id           => l_adr_transaction_coa_id
71969   , p_accounting_coa_id            => l_adr_accounting_coa_id
71970   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
71971   , p_adr_type_code                => 'S'
71972   , p_component_type               => l_component_type
71973   , p_component_code               => l_component_code
71974   , p_component_type_code          => l_component_type_code
71975   , p_component_appl_id            => l_component_appl_id
71976   , p_amb_context_code             => l_amb_context_code
71977   , p_side                         => 'NA'
71978   );
71979 
71980 
71981    l_segment := AcctDerRule_151(
71982            p_application_id           => p_application_id
71983          , p_ae_header_id             => l_ae_header_id 
71984 , p_source_3 => p_source_3
71985 , p_source_12 => p_source_12
71986          , x_transaction_coa_id       => l_adr_transaction_coa_id
71987          , x_accounting_coa_id        => l_adr_accounting_coa_id
71988          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
71989          , x_flex_value_set_id        => l_adr_flex_value_set_id
71990          , x_value_type_code          => l_adr_value_type_code
71991          , x_value_combination_id     => l_adr_value_combination_id
71992          , x_value_segment_code       => l_adr_value_segment_code
71993          , p_side                     => 'NA'
71994          , p_override_seg_flag        => 'Y'
71995    );
71996 
71997    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
71998 
71999       xla_ae_lines_pkg.set_segment(
72000           p_to_segment_code         => 'GL_ACCOUNT'
72001         , p_segment_value           => l_segment
72002         , p_from_segment_code       => l_adr_value_segment_code
72003         , p_from_combination_id     => l_adr_value_combination_id
72004         , p_value_type_code         => l_adr_value_type_code
72005         , p_transaction_coa_id      => l_adr_transaction_coa_id
72006         , p_accounting_coa_id       => l_adr_accounting_coa_id
72007         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
72008         , p_flex_value_set_id       => l_adr_flex_value_set_id
72009         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
72010         , p_adr_type_code           => 'S'
72011         , p_component_type          => l_component_type
72012         , p_component_code          => l_component_code
72013         , p_component_type_code     => l_component_type_code
72014         , p_component_appl_id       => l_component_appl_id
72015         , p_amb_context_code        => l_amb_context_code
72016         , p_entity_code             => 'TRANSACTIONS'
72017         , p_event_class_code        => 'RETIREMENTS'
72018         , p_side                    => 'NA'
72019         );
72020 
72021   END IF;
72022 
72023    l_segment := AcctDerRule_168(
72024            p_application_id           => p_application_id
72025          , p_ae_header_id             => l_ae_header_id 
72026 , p_source_3 => p_source_3
72027 , p_source_29 => p_source_29
72028          , x_transaction_coa_id       => l_adr_transaction_coa_id
72029          , x_accounting_coa_id        => l_adr_accounting_coa_id
72030          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
72031          , x_flex_value_set_id        => l_adr_flex_value_set_id
72032          , x_value_type_code          => l_adr_value_type_code
72033          , x_value_combination_id     => l_adr_value_combination_id
72034          , x_value_segment_code       => l_adr_value_segment_code
72035          , p_side                     => 'NA'
72036          , p_override_seg_flag        => 'Y'
72037    );
72038 
72039    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
72040 
72041       xla_ae_lines_pkg.set_segment(
72042           p_to_segment_code         => 'GL_BALANCING'
72043         , p_segment_value           => l_segment
72044         , p_from_segment_code       => l_adr_value_segment_code
72045         , p_from_combination_id     => l_adr_value_combination_id
72046         , p_value_type_code         => l_adr_value_type_code
72047         , p_transaction_coa_id      => l_adr_transaction_coa_id
72048         , p_accounting_coa_id       => l_adr_accounting_coa_id
72049         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
72050         , p_flex_value_set_id       => l_adr_flex_value_set_id
72051         , p_adr_code                => 'FA_EXPENSE_ACCT'
72055         , p_component_type_code     => l_component_type_code
72052         , p_adr_type_code           => 'S'
72053         , p_component_type          => l_component_type
72054         , p_component_code          => l_component_code
72056         , p_component_appl_id       => l_component_appl_id
72057         , p_amb_context_code        => l_amb_context_code
72058         , p_entity_code             => 'TRANSACTIONS'
72059         , p_event_class_code        => 'RETIREMENTS'
72060         , p_side                    => 'NA'
72061         );
72062 
72063   END IF;
72064 
72065    --
72066    --
72067    END IF;
72068    --
72069    -- Bug 4922099
72070    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
72071           (NVL(l_enc_upg_option, 'N') = 'O')
72072         ) AND
72073         (l_bflow_method_code = 'PRIOR_ENTRY')
72074       )
72075    THEN
72076       IF
72077       --
72078       1 = 2
72079       --
72080       THEN
72081       xla_accounting_err_pkg.build_message
72082                                     (p_appli_s_name            => 'XLA'
72083                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
72084                                     ,p_token_1                 => 'LINE_NUMBER'
72085                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
72086                                     ,p_token_2                 => 'LINE_TYPE_NAME'
72087                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
72088                                                                              l_component_type
72089                                                                             ,l_component_code
72090                                                                             ,l_component_type_code
72091                                                                             ,l_component_appl_id
72092                                                                             ,l_amb_context_code
72093                                                                             ,l_entity_code
72094                                                                             ,l_event_class_code
72095                                                                            )
72096                                     ,p_token_3                 => 'OWNER'
72097                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
72098                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
72099                                                                           ,p_lookup_code    => l_component_type_code
72100                                                                          )
72101                                     ,p_token_4                 => 'PRODUCT_NAME'
72102                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
72103                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
72104                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
72105                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
72106                                     ,p_ae_header_id            =>  NULL
72107                                        );
72108 
72109         IF (C_LEVEL_ERROR>= g_log_level) THEN
72110                  trace
72111                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
72112                       ,p_level    => C_LEVEL_ERROR
72113                       ,p_module   => l_log_module);
72114         END IF;
72115       END IF;
72116    END IF;
72117    --
72118    --
72119    ------------------------------------------------------------------------------------------------
72120    -- 4219869 Business Flow
72121    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
72122    -- Prior Entry.  Currently, the following code is always generated.
72123    ------------------------------------------------------------------------------------------------
72124    XLA_AE_LINES_PKG.ValidateCurrentLine;
72125 
72126    ------------------------------------------------------------------------------------
72127    -- 4219869 Business Flow
72128    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
72129    ------------------------------------------------------------------------------------
72130    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
72131 
72132    ----------------------------------------------------------------------------------
72133    -- 4219869 Business Flow
72134    -- Update journal entry status -- Need to generate this within IF <condition>
72135    ----------------------------------------------------------------------------------
72136    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
72137          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
72138          ,p_balance_type_code => l_balance_type_code
72139          );
72140 
72141    -------------------------------------------------------------------------------------------
72142    -- 4262811 - Generate the Accrual Reversal lines
72143    -------------------------------------------------------------------------------------------
72144    BEGIN
72145       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
72146                               (g_array_event(p_event_id).array_value_num('header_index'));
72147       IF l_acc_rev_flag IS NULL THEN
72148          l_acc_rev_flag := 'N';
72149       END IF;
72150    EXCEPTION
72151       WHEN OTHERS THEN
72152          l_acc_rev_flag := 'N';
72153    END;
72154    --
72155    IF (l_acc_rev_flag = 'Y') THEN
72156 
72157        -- 4645092  ------------------------------------------------------------------------------
72161 
72158        -- To allow MPA report to determine if it should generate report process
72159        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
72160        ------------------------------------------------------------------------------------------
72162        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
72163        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
72164    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
72165    -- call ADRs
72166    -- Bug 4922099
72167    --
72168    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
72169         (NVL(l_actual_upg_option, 'N') = 'O') OR
72170         (NVL(l_enc_upg_option, 'N') = 'O')
72171       )
72172    THEN
72173    NULL;
72174    --
72175    --
72176    
72177   l_ccid := AcctDerRule_173(
72178            p_application_id           => p_application_id
72179          , p_ae_header_id             => l_ae_header_id 
72180 , p_source_3 => p_source_3
72181 , p_source_30 => p_source_30
72182          , x_transaction_coa_id       => l_adr_transaction_coa_id
72183          , x_accounting_coa_id        => l_adr_accounting_coa_id
72184          , x_value_type_code          => l_adr_value_type_code
72185          , p_side                     => 'NA'
72186    );
72187 
72188    xla_ae_lines_pkg.set_ccid(
72189     p_code_combination_id          => l_ccid
72190   , p_value_type_code              => l_adr_value_type_code
72191   , p_transaction_coa_id           => l_adr_transaction_coa_id
72192   , p_accounting_coa_id            => l_adr_accounting_coa_id
72193   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
72194   , p_adr_type_code                => 'S'
72195   , p_component_type               => l_component_type
72196   , p_component_code               => l_component_code
72197   , p_component_type_code          => l_component_type_code
72198   , p_component_appl_id            => l_component_appl_id
72199   , p_amb_context_code             => l_amb_context_code
72200   , p_side                         => 'NA'
72201   );
72202 
72203 
72204    l_segment := AcctDerRule_151(
72205            p_application_id           => p_application_id
72206          , p_ae_header_id             => l_ae_header_id 
72207 , p_source_3 => p_source_3
72208 , p_source_12 => p_source_12
72209          , x_transaction_coa_id       => l_adr_transaction_coa_id
72210          , x_accounting_coa_id        => l_adr_accounting_coa_id
72211          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
72212          , x_flex_value_set_id        => l_adr_flex_value_set_id
72213          , x_value_type_code          => l_adr_value_type_code
72214          , x_value_combination_id     => l_adr_value_combination_id
72215          , x_value_segment_code       => l_adr_value_segment_code
72216          , p_side                     => 'NA'
72217          , p_override_seg_flag        => 'Y'
72218    );
72219 
72220    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
72221 
72222       xla_ae_lines_pkg.set_segment(
72223           p_to_segment_code         => 'GL_ACCOUNT'
72224         , p_segment_value           => l_segment
72225         , p_from_segment_code       => l_adr_value_segment_code
72226         , p_from_combination_id     => l_adr_value_combination_id
72227         , p_value_type_code         => l_adr_value_type_code
72228         , p_transaction_coa_id      => l_adr_transaction_coa_id
72229         , p_accounting_coa_id       => l_adr_accounting_coa_id
72230         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
72231         , p_flex_value_set_id       => l_adr_flex_value_set_id
72232         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
72233         , p_adr_type_code           => 'S'
72234         , p_component_type          => l_component_type
72235         , p_component_code          => l_component_code
72236         , p_component_type_code     => l_component_type_code
72237         , p_component_appl_id       => l_component_appl_id
72238         , p_amb_context_code        => l_amb_context_code
72239         , p_entity_code             => 'TRANSACTIONS'
72240         , p_event_class_code        => 'RETIREMENTS'
72241         , p_side                    => 'NA'
72242         );
72243 
72244   END IF;
72245 
72246    l_segment := AcctDerRule_168(
72247            p_application_id           => p_application_id
72248          , p_ae_header_id             => l_ae_header_id 
72249 , p_source_3 => p_source_3
72250 , p_source_29 => p_source_29
72251          , x_transaction_coa_id       => l_adr_transaction_coa_id
72252          , x_accounting_coa_id        => l_adr_accounting_coa_id
72253          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
72254          , x_flex_value_set_id        => l_adr_flex_value_set_id
72255          , x_value_type_code          => l_adr_value_type_code
72256          , x_value_combination_id     => l_adr_value_combination_id
72257          , x_value_segment_code       => l_adr_value_segment_code
72258          , p_side                     => 'NA'
72259          , p_override_seg_flag        => 'Y'
72260    );
72261 
72262    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
72263 
72264       xla_ae_lines_pkg.set_segment(
72265           p_to_segment_code         => 'GL_BALANCING'
72266         , p_segment_value           => l_segment
72267         , p_from_segment_code       => l_adr_value_segment_code
72268         , p_from_combination_id     => l_adr_value_combination_id
72269         , p_value_type_code         => l_adr_value_type_code
72270         , p_transaction_coa_id      => l_adr_transaction_coa_id
72271         , p_accounting_coa_id       => l_adr_accounting_coa_id
72272         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
72273         , p_flex_value_set_id       => l_adr_flex_value_set_id
72274         , p_adr_code                => 'FA_EXPENSE_ACCT'
72275         , p_adr_type_code           => 'S'
72279         , p_component_appl_id       => l_component_appl_id
72276         , p_component_type          => l_component_type
72277         , p_component_code          => l_component_code
72278         , p_component_type_code     => l_component_type_code
72280         , p_amb_context_code        => l_amb_context_code
72281         , p_entity_code             => 'TRANSACTIONS'
72282         , p_event_class_code        => 'RETIREMENTS'
72283         , p_side                    => 'NA'
72284         );
72285 
72286   END IF;
72287 
72288    --
72289    --
72290    END IF;
72291 
72292        --
72293        -- Update the line information that should be overwritten
72294        --
72295        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
72296                                          p_header_num   => 1);
72297        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
72298 
72299        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
72300 
72301        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
72302           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
72303        END IF;
72304 
72305       --
72306       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
72307       --
72308       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
72309           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
72310       ELSE
72311           ---------------------------------------------------------------------------------------------------
72312           -- 4262811a Switch Sign
72313           ---------------------------------------------------------------------------------------------------
72314           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
72315           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
72316                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
72317           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
72318                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
72319           -- 5132302
72320           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
72321                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
72322 
72323       END IF;
72324 
72325       -- 4955764
72326       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
72327       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
72328 
72329 
72330       XLA_AE_LINES_PKG.ValidateCurrentLine;
72331       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
72332 
72333       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
72334                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
72335                ,p_balance_type_code => l_balance_type_code);
72336 
72337    END IF;
72338 
72339    -----------------------------------------------------------------------------------------
72340    -- 4262811 Multiperiod Accounting
72341    -----------------------------------------------------------------------------------------
72342      -- No MPA option is assigned.
72343 
72344 
72345 END IF;
72346 END IF;
72347 --
72348 
72349 --
72350 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
72351    trace
72352       (p_msg      => 'END of AcctLineType_254'
72353       ,p_level    => C_LEVEL_PROCEDURE
72354       ,p_module   => l_log_module);
72355 END IF;
72356 --
72357 EXCEPTION
72358   WHEN xla_exceptions_pkg.application_exception THEN
72359       RAISE;
72360   WHEN OTHERS THEN
72361        xla_exceptions_pkg.raise_message
72362            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_254');
72363 END AcctLineType_254;
72364 --
72365 
72366 ---------------------------------------
72367 --
72368 -- PRIVATE FUNCTION
72369 --         AcctLineType_255
72370 --
72371 ---------------------------------------
72372 PROCEDURE AcctLineType_255 (
72373   p_application_id        IN NUMBER
72374  ,p_event_id              IN NUMBER
72375  ,p_calculate_acctd_flag  IN VARCHAR2
72376  ,p_calculate_g_l_flag    IN VARCHAR2
72377  ,p_actual_flag           IN OUT VARCHAR2
72378  ,p_balance_type_code     OUT VARCHAR2
72379  ,p_gain_or_loss_ref      OUT VARCHAR2
72380  
72381 --Period Close Date
72382  , p_source_1            IN DATE
72383 --Generated Code Combination Identifier
72384  , p_source_3            IN NUMBER
72385 --Cost Of Removal Gain Account
72386  , p_source_13            IN VARCHAR2
72387 --Expense Account Code Combination Identifier
72388  , p_source_29            IN NUMBER
72389 --Default Code Combination Identifier
72390  , p_source_30            IN NUMBER
72391 --Adjustment Type
72392  , p_source_35            IN VARCHAR2
72393 --Transaction Header Identifier
72394  , p_source_36            IN NUMBER
72395 --Adjustment Line Identifier
72396  , p_source_37            IN NUMBER
72397 --Distribution Type Code
72398  , p_source_38            IN VARCHAR2
72399 --Entered Amount
72400  , p_source_39            IN NUMBER
72401 --Currency Code
72402  , p_source_40            IN VARCHAR2
72403 --Gain Loss Amount
72404  , p_source_41            IN NUMBER
72405 )
72406 IS
72407 
72408 l_component_type              VARCHAR2(80);
72409 l_component_code              VARCHAR2(30);
72410 l_component_type_code         VARCHAR2(1);
72411 l_component_appl_id           INTEGER;
72415 l_ae_header_id                NUMBER;
72412 l_amb_context_code            VARCHAR2(30);
72413 l_entity_code                 VARCHAR2(30);
72414 l_event_class_code            VARCHAR2(30);
72416 l_event_type_code             VARCHAR2(30);
72417 l_line_definition_code        VARCHAR2(30);
72418 l_line_definition_owner_code  VARCHAR2(1);
72419 --
72420 -- adr variables
72421 l_segment                     VARCHAR2(30);
72422 l_ccid                        NUMBER;
72423 l_adr_transaction_coa_id      NUMBER;
72424 l_adr_accounting_coa_id       NUMBER;
72425 l_adr_flexfield_segment_code  VARCHAR2(30);
72426 l_adr_flex_value_set_id       NUMBER;
72427 l_adr_value_type_code         VARCHAR2(30);
72428 l_adr_value_combination_id    NUMBER;
72429 l_adr_value_segment_code      VARCHAR2(30);
72430 
72431 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
72432 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
72433 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
72434 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
72435 
72436 -- 4262811 Variables ------------------------------------------------------------------------------------------
72437 l_entered_amt_idx             NUMBER;
72438 l_accted_amt_idx              NUMBER;
72439 l_acc_rev_flag                VARCHAR2(1);
72440 l_accrual_line_num            NUMBER;
72441 l_tmp_amt                     NUMBER;
72442 l_acc_rev_natural_side_code   VARCHAR2(1);
72443 
72444 l_num_entries                 NUMBER;
72445 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
72446 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
72447 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
72448 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
72449 l_recog_line_1                NUMBER;
72450 l_recog_line_2                NUMBER;
72451 
72452 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
72453 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
72454 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
72455 
72456 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
72457 
72458 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
72459 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
72460 
72461 ---------------------------------------------------------------------------------------------------------------
72462 
72463 
72464 --
72465 -- bulk performance
72466 --
72467 l_balance_type_code           VARCHAR2(1);
72468 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
72469 l_log_module                  VARCHAR2(240);
72470 
72471 --
72472 -- Upgrade strategy
72473 --
72474 l_actual_upg_option           VARCHAR2(1);
72475 l_enc_upg_option           VARCHAR2(1);
72476 
72477 --
72478 BEGIN
72479 --
72480 IF g_log_enabled THEN
72481       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_255';
72482 END IF;
72483 --
72484 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
72485 
72486       trace
72487          (p_msg      => 'BEGIN of AcctLineType_255'
72488          ,p_level    => C_LEVEL_PROCEDURE
72489          ,p_module   => l_log_module);
72490 
72491 END IF;
72492 --
72493 l_component_type             := 'AMB_JLT';
72494 l_component_code             := 'FA_COST_OF_REMOVAL_GAIN';
72495 l_component_type_code        := 'S';
72496 l_component_appl_id          :=  140;
72497 l_amb_context_code           := 'DEFAULT';
72498 l_entity_code                := 'TRANSACTIONS';
72499 l_event_class_code           := 'RETIREMENTS';
72500 l_event_type_code            := 'RETIREMENTS';
72501 l_line_definition_owner_code := 'S';
72502 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
72503 --
72504 l_balance_type_code          := 'A';
72505 l_segment                     := NULL;
72506 l_ccid                        := NULL;
72507 l_adr_transaction_coa_id      := NULL;
72508 l_adr_accounting_coa_id       := NULL;
72509 l_adr_flexfield_segment_code  := NULL;
72510 l_adr_flex_value_set_id       := NULL;
72511 l_adr_value_type_code         := NULL;
72512 l_adr_value_combination_id    := NULL;
72513 l_adr_value_segment_code      := NULL;
72514 
72515 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
72516 l_bflow_class_code           := '';    -- 4219869 Business Flow
72517 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
72518 l_budgetary_control_flag     := 'N';
72519 
72520 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
72521 l_bflow_applied_to_amt       := NULL; -- 5132302
72522 l_entered_amt_idx            := NULL;          -- 4262811
72523 l_accted_amt_idx             := NULL;          -- 4262811
72524 l_acc_rev_flag               := NULL;          -- 4262811
72525 l_accrual_line_num           := NULL;          -- 4262811
72526 l_tmp_amt                    := NULL;          -- 4262811
72527 --
72528  
72529 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
72530     l_balance_type_code <> 'B' THEN
72531 IF NVL(p_source_35,'
72532 ') =  'REMOVALCOST' AND 
72533 p_source_41 >=  0
72534  THEN 
72535 
72536    --
72537    XLA_AE_LINES_PKG.SetNewLine;
72538 
72539    p_balance_type_code          := l_balance_type_code;
72540    -- set the flag so later we will know whether the gain loss line needs to be created
72541    
72542    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
72543      p_actual_flag :='A';
72544    END IF;
72545 
72546    --
72547    -- bulk performance
72548    --
72549    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
72553    --
72550                                       p_header_num   => 0); -- 4262811
72551    --
72552    -- set accounting line options
72554    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
72555            p_natural_side_code          => 'D'
72556          , p_gain_or_loss_flag          => 'N'
72557          , p_gl_transfer_mode_code      => 'S'
72558          , p_acct_entry_type_code       => 'A'
72559          , p_switch_side_flag           => 'Y'
72560          , p_merge_duplicate_code       => 'N'
72561          );
72562    --
72563    l_acc_rev_natural_side_code := 'C';  -- 4262811
72564    -- 
72565    --
72566    -- set accounting line type info
72567    --
72568    xla_ae_lines_pkg.SetAcctLineType
72569       (p_component_type             => l_component_type
72570       ,p_event_type_code            => l_event_type_code
72571       ,p_line_definition_owner_code => l_line_definition_owner_code
72572       ,p_line_definition_code       => l_line_definition_code
72573       ,p_accounting_line_code       => l_component_code
72574       ,p_accounting_line_type_code  => l_component_type_code
72575       ,p_accounting_line_appl_id    => l_component_appl_id
72576       ,p_amb_context_code           => l_amb_context_code
72577       ,p_entity_code                => l_entity_code
72578       ,p_event_class_code           => l_event_class_code);
72579    --
72580    -- set accounting class
72581    --
72582    xla_ae_lines_pkg.SetAcctClass(
72583            p_accounting_class_code  => 'ASSET'
72584          , p_ae_header_id           => l_ae_header_id
72585          );
72586 
72587    --
72588    -- set rounding class
72589    --
72590    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
72591                       'ASSET';
72592 
72593    --
72594    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
72595    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
72596    --
72597    -- bulk performance
72598    --
72599    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
72600 
72601    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
72602       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
72603 
72604    -- 4955764
72605    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
72606       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
72607 
72608    -- 4458381 Public Sector Enh
72609    
72610    --
72611    -- set accounting attributes for the line type
72612    --
72613    l_entered_amt_idx := 4;
72614    l_accted_amt_idx  := 6;
72615    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
72616    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
72617    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
72618    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
72619    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
72620    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
72621    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
72622    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
72623    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
72624    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
72625    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
72626    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
72627    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
72628 
72629    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
72630    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
72631 
72632    ---------------------------------------------------------------------------------------------------------------
72633    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
72634    ---------------------------------------------------------------------------------------------------------------
72635    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
72636 
72637    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
72638    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
72639 
72640    IF xla_accounting_cache_pkg.GetValueChar
72641          (p_source_code         => 'LEDGER_CATEGORY_CODE'
72642          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
72643    AND l_bflow_method_code = 'PRIOR_ENTRY'
72644 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
72645    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
72646          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
72647        )
72648    THEN
72649          xla_ae_lines_pkg.BflowUpgEntry
72650            (p_business_method_code    => l_bflow_method_code
72651            ,p_business_class_code     => l_bflow_class_code
72652            ,p_balance_type            => l_balance_type_code);
72653    ELSE
72654       NULL;
72655 -- No business flow processing for business flow method of NONE.
72656    END IF;
72657 
72658    --
72659    -- call analytical criteria
72660    --
72661    
72662    --
72663    -- call description
72664    --
72665    
72666 xla_ae_lines_pkg.SetLineDescription(
72667    p_ae_header_id => l_ae_header_id
72668   ,p_description  => Description_78 (
72669      p_application_id         => p_application_id
72670    , p_ae_header_id           => l_ae_header_id 
72671 , p_source_1 => p_source_1
72672    )
72673 );
72674 
72675 
72676    --
72680    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
72677    -- call ADRs
72678    -- Bug 4922099
72679    --
72681         (NVL(l_actual_upg_option, 'N') = 'O') OR
72682         (NVL(l_enc_upg_option, 'N') = 'O')
72683       )
72684    THEN
72685    NULL;
72686    --
72687    --
72688    
72689   l_ccid := AcctDerRule_173(
72690            p_application_id           => p_application_id
72691          , p_ae_header_id             => l_ae_header_id 
72692 , p_source_3 => p_source_3
72693 , p_source_30 => p_source_30
72694          , x_transaction_coa_id       => l_adr_transaction_coa_id
72695          , x_accounting_coa_id        => l_adr_accounting_coa_id
72696          , x_value_type_code          => l_adr_value_type_code
72697          , p_side                     => 'NA'
72698    );
72699 
72700    xla_ae_lines_pkg.set_ccid(
72701     p_code_combination_id          => l_ccid
72702   , p_value_type_code              => l_adr_value_type_code
72703   , p_transaction_coa_id           => l_adr_transaction_coa_id
72704   , p_accounting_coa_id            => l_adr_accounting_coa_id
72705   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
72706   , p_adr_type_code                => 'S'
72707   , p_component_type               => l_component_type
72708   , p_component_code               => l_component_code
72709   , p_component_type_code          => l_component_type_code
72710   , p_component_appl_id            => l_component_appl_id
72711   , p_amb_context_code             => l_amb_context_code
72712   , p_side                         => 'NA'
72713   );
72714 
72715 
72716    l_segment := AcctDerRule_152(
72717            p_application_id           => p_application_id
72718          , p_ae_header_id             => l_ae_header_id 
72719 , p_source_3 => p_source_3
72720 , p_source_13 => p_source_13
72721          , x_transaction_coa_id       => l_adr_transaction_coa_id
72722          , x_accounting_coa_id        => l_adr_accounting_coa_id
72723          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
72724          , x_flex_value_set_id        => l_adr_flex_value_set_id
72725          , x_value_type_code          => l_adr_value_type_code
72726          , x_value_combination_id     => l_adr_value_combination_id
72727          , x_value_segment_code       => l_adr_value_segment_code
72728          , p_side                     => 'NA'
72729          , p_override_seg_flag        => 'Y'
72730    );
72731 
72732    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
72733 
72734       xla_ae_lines_pkg.set_segment(
72735           p_to_segment_code         => 'GL_ACCOUNT'
72736         , p_segment_value           => l_segment
72737         , p_from_segment_code       => l_adr_value_segment_code
72738         , p_from_combination_id     => l_adr_value_combination_id
72739         , p_value_type_code         => l_adr_value_type_code
72740         , p_transaction_coa_id      => l_adr_transaction_coa_id
72741         , p_accounting_coa_id       => l_adr_accounting_coa_id
72742         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
72743         , p_flex_value_set_id       => l_adr_flex_value_set_id
72744         , p_adr_code                => 'FA_COST_OF_REM_GAIN_SEGMENT'
72745         , p_adr_type_code           => 'S'
72746         , p_component_type          => l_component_type
72747         , p_component_code          => l_component_code
72748         , p_component_type_code     => l_component_type_code
72749         , p_component_appl_id       => l_component_appl_id
72750         , p_amb_context_code        => l_amb_context_code
72751         , p_entity_code             => 'TRANSACTIONS'
72752         , p_event_class_code        => 'RETIREMENTS'
72753         , p_side                    => 'NA'
72754         );
72755 
72756   END IF;
72757 
72758    l_segment := AcctDerRule_168(
72759            p_application_id           => p_application_id
72760          , p_ae_header_id             => l_ae_header_id 
72761 , p_source_3 => p_source_3
72762 , p_source_29 => p_source_29
72763          , x_transaction_coa_id       => l_adr_transaction_coa_id
72764          , x_accounting_coa_id        => l_adr_accounting_coa_id
72765          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
72766          , x_flex_value_set_id        => l_adr_flex_value_set_id
72767          , x_value_type_code          => l_adr_value_type_code
72768          , x_value_combination_id     => l_adr_value_combination_id
72769          , x_value_segment_code       => l_adr_value_segment_code
72770          , p_side                     => 'NA'
72771          , p_override_seg_flag        => 'Y'
72772    );
72773 
72774    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
72775 
72776       xla_ae_lines_pkg.set_segment(
72777           p_to_segment_code         => 'GL_BALANCING'
72778         , p_segment_value           => l_segment
72779         , p_from_segment_code       => l_adr_value_segment_code
72780         , p_from_combination_id     => l_adr_value_combination_id
72781         , p_value_type_code         => l_adr_value_type_code
72782         , p_transaction_coa_id      => l_adr_transaction_coa_id
72783         , p_accounting_coa_id       => l_adr_accounting_coa_id
72784         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
72785         , p_flex_value_set_id       => l_adr_flex_value_set_id
72786         , p_adr_code                => 'FA_EXPENSE_ACCT'
72787         , p_adr_type_code           => 'S'
72788         , p_component_type          => l_component_type
72789         , p_component_code          => l_component_code
72790         , p_component_type_code     => l_component_type_code
72791         , p_component_appl_id       => l_component_appl_id
72792         , p_amb_context_code        => l_amb_context_code
72793         , p_entity_code             => 'TRANSACTIONS'
72794         , p_event_class_code        => 'RETIREMENTS'
72795         , p_side                    => 'NA'
72796         );
72797 
72801    --
72798   END IF;
72799 
72800    --
72802    END IF;
72803    --
72804    -- Bug 4922099
72805    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
72806           (NVL(l_enc_upg_option, 'N') = 'O')
72807         ) AND
72808         (l_bflow_method_code = 'PRIOR_ENTRY')
72809       )
72810    THEN
72811       IF
72812       --
72813       1 = 2
72814       --
72815       THEN
72816       xla_accounting_err_pkg.build_message
72817                                     (p_appli_s_name            => 'XLA'
72818                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
72819                                     ,p_token_1                 => 'LINE_NUMBER'
72820                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
72821                                     ,p_token_2                 => 'LINE_TYPE_NAME'
72822                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
72823                                                                              l_component_type
72824                                                                             ,l_component_code
72825                                                                             ,l_component_type_code
72826                                                                             ,l_component_appl_id
72827                                                                             ,l_amb_context_code
72828                                                                             ,l_entity_code
72829                                                                             ,l_event_class_code
72830                                                                            )
72831                                     ,p_token_3                 => 'OWNER'
72832                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
72833                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
72834                                                                           ,p_lookup_code    => l_component_type_code
72835                                                                          )
72836                                     ,p_token_4                 => 'PRODUCT_NAME'
72837                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
72838                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
72839                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
72840                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
72841                                     ,p_ae_header_id            =>  NULL
72842                                        );
72843 
72844         IF (C_LEVEL_ERROR>= g_log_level) THEN
72845                  trace
72846                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
72847                       ,p_level    => C_LEVEL_ERROR
72848                       ,p_module   => l_log_module);
72849         END IF;
72850       END IF;
72851    END IF;
72852    --
72853    --
72854    ------------------------------------------------------------------------------------------------
72855    -- 4219869 Business Flow
72856    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
72857    -- Prior Entry.  Currently, the following code is always generated.
72858    ------------------------------------------------------------------------------------------------
72859    XLA_AE_LINES_PKG.ValidateCurrentLine;
72860 
72861    ------------------------------------------------------------------------------------
72862    -- 4219869 Business Flow
72863    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
72864    ------------------------------------------------------------------------------------
72865    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
72866 
72867    ----------------------------------------------------------------------------------
72868    -- 4219869 Business Flow
72869    -- Update journal entry status -- Need to generate this within IF <condition>
72870    ----------------------------------------------------------------------------------
72871    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
72872          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
72873          ,p_balance_type_code => l_balance_type_code
72874          );
72875 
72876    -------------------------------------------------------------------------------------------
72877    -- 4262811 - Generate the Accrual Reversal lines
72878    -------------------------------------------------------------------------------------------
72879    BEGIN
72880       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
72881                               (g_array_event(p_event_id).array_value_num('header_index'));
72882       IF l_acc_rev_flag IS NULL THEN
72883          l_acc_rev_flag := 'N';
72884       END IF;
72885    EXCEPTION
72886       WHEN OTHERS THEN
72887          l_acc_rev_flag := 'N';
72888    END;
72889    --
72890    IF (l_acc_rev_flag = 'Y') THEN
72891 
72892        -- 4645092  ------------------------------------------------------------------------------
72893        -- To allow MPA report to determine if it should generate report process
72894        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
72895        ------------------------------------------------------------------------------------------
72896 
72897        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
72898        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
72899    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
72900    -- call ADRs
72901    -- Bug 4922099
72902    --
72903    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
72907    THEN
72904         (NVL(l_actual_upg_option, 'N') = 'O') OR
72905         (NVL(l_enc_upg_option, 'N') = 'O')
72906       )
72908    NULL;
72909    --
72910    --
72911    
72912   l_ccid := AcctDerRule_173(
72913            p_application_id           => p_application_id
72914          , p_ae_header_id             => l_ae_header_id 
72915 , p_source_3 => p_source_3
72916 , p_source_30 => p_source_30
72917          , x_transaction_coa_id       => l_adr_transaction_coa_id
72918          , x_accounting_coa_id        => l_adr_accounting_coa_id
72919          , x_value_type_code          => l_adr_value_type_code
72920          , p_side                     => 'NA'
72921    );
72922 
72923    xla_ae_lines_pkg.set_ccid(
72924     p_code_combination_id          => l_ccid
72925   , p_value_type_code              => l_adr_value_type_code
72926   , p_transaction_coa_id           => l_adr_transaction_coa_id
72927   , p_accounting_coa_id            => l_adr_accounting_coa_id
72928   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
72929   , p_adr_type_code                => 'S'
72930   , p_component_type               => l_component_type
72931   , p_component_code               => l_component_code
72932   , p_component_type_code          => l_component_type_code
72933   , p_component_appl_id            => l_component_appl_id
72934   , p_amb_context_code             => l_amb_context_code
72935   , p_side                         => 'NA'
72936   );
72937 
72938 
72939    l_segment := AcctDerRule_152(
72940            p_application_id           => p_application_id
72941          , p_ae_header_id             => l_ae_header_id 
72942 , p_source_3 => p_source_3
72943 , p_source_13 => p_source_13
72944          , x_transaction_coa_id       => l_adr_transaction_coa_id
72945          , x_accounting_coa_id        => l_adr_accounting_coa_id
72946          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
72947          , x_flex_value_set_id        => l_adr_flex_value_set_id
72948          , x_value_type_code          => l_adr_value_type_code
72949          , x_value_combination_id     => l_adr_value_combination_id
72950          , x_value_segment_code       => l_adr_value_segment_code
72951          , p_side                     => 'NA'
72952          , p_override_seg_flag        => 'Y'
72953    );
72954 
72955    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
72956 
72957       xla_ae_lines_pkg.set_segment(
72958           p_to_segment_code         => 'GL_ACCOUNT'
72959         , p_segment_value           => l_segment
72960         , p_from_segment_code       => l_adr_value_segment_code
72961         , p_from_combination_id     => l_adr_value_combination_id
72962         , p_value_type_code         => l_adr_value_type_code
72963         , p_transaction_coa_id      => l_adr_transaction_coa_id
72964         , p_accounting_coa_id       => l_adr_accounting_coa_id
72965         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
72966         , p_flex_value_set_id       => l_adr_flex_value_set_id
72967         , p_adr_code                => 'FA_COST_OF_REM_GAIN_SEGMENT'
72968         , p_adr_type_code           => 'S'
72969         , p_component_type          => l_component_type
72970         , p_component_code          => l_component_code
72971         , p_component_type_code     => l_component_type_code
72972         , p_component_appl_id       => l_component_appl_id
72973         , p_amb_context_code        => l_amb_context_code
72974         , p_entity_code             => 'TRANSACTIONS'
72975         , p_event_class_code        => 'RETIREMENTS'
72976         , p_side                    => 'NA'
72977         );
72978 
72979   END IF;
72980 
72981    l_segment := AcctDerRule_168(
72982            p_application_id           => p_application_id
72983          , p_ae_header_id             => l_ae_header_id 
72984 , p_source_3 => p_source_3
72985 , p_source_29 => p_source_29
72986          , x_transaction_coa_id       => l_adr_transaction_coa_id
72987          , x_accounting_coa_id        => l_adr_accounting_coa_id
72988          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
72989          , x_flex_value_set_id        => l_adr_flex_value_set_id
72990          , x_value_type_code          => l_adr_value_type_code
72991          , x_value_combination_id     => l_adr_value_combination_id
72992          , x_value_segment_code       => l_adr_value_segment_code
72993          , p_side                     => 'NA'
72994          , p_override_seg_flag        => 'Y'
72995    );
72996 
72997    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
72998 
72999       xla_ae_lines_pkg.set_segment(
73000           p_to_segment_code         => 'GL_BALANCING'
73001         , p_segment_value           => l_segment
73002         , p_from_segment_code       => l_adr_value_segment_code
73003         , p_from_combination_id     => l_adr_value_combination_id
73004         , p_value_type_code         => l_adr_value_type_code
73005         , p_transaction_coa_id      => l_adr_transaction_coa_id
73006         , p_accounting_coa_id       => l_adr_accounting_coa_id
73007         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
73008         , p_flex_value_set_id       => l_adr_flex_value_set_id
73009         , p_adr_code                => 'FA_EXPENSE_ACCT'
73010         , p_adr_type_code           => 'S'
73011         , p_component_type          => l_component_type
73012         , p_component_code          => l_component_code
73013         , p_component_type_code     => l_component_type_code
73014         , p_component_appl_id       => l_component_appl_id
73015         , p_amb_context_code        => l_amb_context_code
73016         , p_entity_code             => 'TRANSACTIONS'
73017         , p_event_class_code        => 'RETIREMENTS'
73018         , p_side                    => 'NA'
73019         );
73020 
73021   END IF;
73022 
73023    --
73024    --
73025    END IF;
73026 
73027        --
73031                                          p_header_num   => 1);
73028        -- Update the line information that should be overwritten
73029        --
73030        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
73032        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
73033 
73034        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
73035 
73036        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
73037           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
73038        END IF;
73039 
73040       --
73041       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
73042       --
73043       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
73044           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
73045       ELSE
73046           ---------------------------------------------------------------------------------------------------
73047           -- 4262811a Switch Sign
73048           ---------------------------------------------------------------------------------------------------
73049           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
73050           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
73051                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
73052           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
73053                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
73054           -- 5132302
73055           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
73056                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
73057 
73058       END IF;
73059 
73060       -- 4955764
73061       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
73062       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
73063 
73064 
73065       XLA_AE_LINES_PKG.ValidateCurrentLine;
73066       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
73067 
73068       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
73069                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
73070                ,p_balance_type_code => l_balance_type_code);
73071 
73072    END IF;
73073 
73074    -----------------------------------------------------------------------------------------
73075    -- 4262811 Multiperiod Accounting
73076    -----------------------------------------------------------------------------------------
73077      -- No MPA option is assigned.
73078 
73079 
73080 END IF;
73081 END IF;
73082 --
73083 
73084 --
73085 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
73086    trace
73087       (p_msg      => 'END of AcctLineType_255'
73088       ,p_level    => C_LEVEL_PROCEDURE
73089       ,p_module   => l_log_module);
73090 END IF;
73091 --
73092 EXCEPTION
73093   WHEN xla_exceptions_pkg.application_exception THEN
73094       RAISE;
73095   WHEN OTHERS THEN
73096        xla_exceptions_pkg.raise_message
73097            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_255');
73098 END AcctLineType_255;
73099 --
73100 
73101 ---------------------------------------
73102 --
73103 -- PRIVATE FUNCTION
73104 --         AcctLineType_256
73105 --
73106 ---------------------------------------
73107 PROCEDURE AcctLineType_256 (
73108   p_application_id        IN NUMBER
73109  ,p_event_id              IN NUMBER
73110  ,p_calculate_acctd_flag  IN VARCHAR2
73111  ,p_calculate_g_l_flag    IN VARCHAR2
73112  ,p_actual_flag           IN OUT VARCHAR2
73113  ,p_balance_type_code     OUT VARCHAR2
73114  ,p_gain_or_loss_ref      OUT VARCHAR2
73115  
73116 --Period Close Date
73117  , p_source_1            IN DATE
73118 --Generated Code Combination Identifier
73119  , p_source_3            IN NUMBER
73120 --Cost Of Removal Gain Account
73121  , p_source_13            IN VARCHAR2
73122 --Expense Account Code Combination Identifier
73123  , p_source_29            IN NUMBER
73124 --Default Code Combination Identifier
73125  , p_source_30            IN NUMBER
73126 --Adjustment Type
73127  , p_source_35            IN VARCHAR2
73128 --Transaction Header Identifier
73129  , p_source_36            IN NUMBER
73130 --Adjustment Line Identifier
73131  , p_source_37            IN NUMBER
73132 --Distribution Type Code
73133  , p_source_38            IN VARCHAR2
73134 --Entered Amount
73135  , p_source_39            IN NUMBER
73136 --Currency Code
73137  , p_source_40            IN VARCHAR2
73138 --Gain Loss Amount
73139  , p_source_41            IN NUMBER
73140 )
73141 IS
73142 
73143 l_component_type              VARCHAR2(80);
73144 l_component_code              VARCHAR2(30);
73145 l_component_type_code         VARCHAR2(1);
73146 l_component_appl_id           INTEGER;
73147 l_amb_context_code            VARCHAR2(30);
73148 l_entity_code                 VARCHAR2(30);
73149 l_event_class_code            VARCHAR2(30);
73150 l_ae_header_id                NUMBER;
73151 l_event_type_code             VARCHAR2(30);
73152 l_line_definition_code        VARCHAR2(30);
73153 l_line_definition_owner_code  VARCHAR2(1);
73154 --
73155 -- adr variables
73156 l_segment                     VARCHAR2(30);
73157 l_ccid                        NUMBER;
73158 l_adr_transaction_coa_id      NUMBER;
73159 l_adr_accounting_coa_id       NUMBER;
73160 l_adr_flexfield_segment_code  VARCHAR2(30);
73164 l_adr_value_segment_code      VARCHAR2(30);
73161 l_adr_flex_value_set_id       NUMBER;
73162 l_adr_value_type_code         VARCHAR2(30);
73163 l_adr_value_combination_id    NUMBER;
73165 
73166 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
73167 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
73168 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
73169 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
73170 
73171 -- 4262811 Variables ------------------------------------------------------------------------------------------
73172 l_entered_amt_idx             NUMBER;
73173 l_accted_amt_idx              NUMBER;
73174 l_acc_rev_flag                VARCHAR2(1);
73175 l_accrual_line_num            NUMBER;
73176 l_tmp_amt                     NUMBER;
73177 l_acc_rev_natural_side_code   VARCHAR2(1);
73178 
73179 l_num_entries                 NUMBER;
73180 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
73181 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
73182 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
73183 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
73184 l_recog_line_1                NUMBER;
73185 l_recog_line_2                NUMBER;
73186 
73187 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
73188 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
73189 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
73190 
73191 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
73192 
73193 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
73194 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
73195 
73196 ---------------------------------------------------------------------------------------------------------------
73197 
73198 
73199 --
73200 -- bulk performance
73201 --
73202 l_balance_type_code           VARCHAR2(1);
73203 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
73204 l_log_module                  VARCHAR2(240);
73205 
73206 --
73207 -- Upgrade strategy
73208 --
73209 l_actual_upg_option           VARCHAR2(1);
73210 l_enc_upg_option           VARCHAR2(1);
73211 
73212 --
73213 BEGIN
73214 --
73215 IF g_log_enabled THEN
73216       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_256';
73217 END IF;
73218 --
73219 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
73220 
73221       trace
73222          (p_msg      => 'BEGIN of AcctLineType_256'
73223          ,p_level    => C_LEVEL_PROCEDURE
73224          ,p_module   => l_log_module);
73225 
73226 END IF;
73227 --
73228 l_component_type             := 'AMB_JLT';
73229 l_component_code             := 'FA_COST_OF_REMOVAL_GAIN';
73230 l_component_type_code        := 'S';
73231 l_component_appl_id          :=  140;
73232 l_amb_context_code           := 'DEFAULT';
73233 l_entity_code                := 'TRANSACTIONS';
73234 l_event_class_code           := 'RETIREMENTS';
73235 l_event_type_code            := 'REINSTATEMENTS';
73236 l_line_definition_owner_code := 'S';
73237 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
73238 --
73239 l_balance_type_code          := 'A';
73240 l_segment                     := NULL;
73241 l_ccid                        := NULL;
73242 l_adr_transaction_coa_id      := NULL;
73243 l_adr_accounting_coa_id       := NULL;
73244 l_adr_flexfield_segment_code  := NULL;
73245 l_adr_flex_value_set_id       := NULL;
73246 l_adr_value_type_code         := NULL;
73247 l_adr_value_combination_id    := NULL;
73248 l_adr_value_segment_code      := NULL;
73249 
73250 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
73251 l_bflow_class_code           := '';    -- 4219869 Business Flow
73252 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
73253 l_budgetary_control_flag     := 'N';
73254 
73255 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
73256 l_bflow_applied_to_amt       := NULL; -- 5132302
73257 l_entered_amt_idx            := NULL;          -- 4262811
73258 l_accted_amt_idx             := NULL;          -- 4262811
73259 l_acc_rev_flag               := NULL;          -- 4262811
73260 l_accrual_line_num           := NULL;          -- 4262811
73261 l_tmp_amt                    := NULL;          -- 4262811
73262 --
73263  
73264 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
73265     l_balance_type_code <> 'B' THEN
73266 IF NVL(p_source_35,'
73267 ') =  'REMOVALCOST' AND 
73268 p_source_41 >=  0
73269  THEN 
73270 
73271    --
73272    XLA_AE_LINES_PKG.SetNewLine;
73273 
73274    p_balance_type_code          := l_balance_type_code;
73275    -- set the flag so later we will know whether the gain loss line needs to be created
73276    
73277    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
73278      p_actual_flag :='A';
73279    END IF;
73280 
73281    --
73282    -- bulk performance
73283    --
73284    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
73285                                       p_header_num   => 0); -- 4262811
73286    --
73287    -- set accounting line options
73288    --
73289    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
73290            p_natural_side_code          => 'D'
73291          , p_gain_or_loss_flag          => 'N'
73292          , p_gl_transfer_mode_code      => 'S'
73293          , p_acct_entry_type_code       => 'A'
73294          , p_switch_side_flag           => 'Y'
73295          , p_merge_duplicate_code       => 'N'
73296          );
73297    --
73298    l_acc_rev_natural_side_code := 'C';  -- 4262811
73299    -- 
73303    xla_ae_lines_pkg.SetAcctLineType
73300    --
73301    -- set accounting line type info
73302    --
73304       (p_component_type             => l_component_type
73305       ,p_event_type_code            => l_event_type_code
73306       ,p_line_definition_owner_code => l_line_definition_owner_code
73307       ,p_line_definition_code       => l_line_definition_code
73308       ,p_accounting_line_code       => l_component_code
73309       ,p_accounting_line_type_code  => l_component_type_code
73310       ,p_accounting_line_appl_id    => l_component_appl_id
73311       ,p_amb_context_code           => l_amb_context_code
73312       ,p_entity_code                => l_entity_code
73313       ,p_event_class_code           => l_event_class_code);
73314    --
73315    -- set accounting class
73316    --
73317    xla_ae_lines_pkg.SetAcctClass(
73318            p_accounting_class_code  => 'ASSET'
73319          , p_ae_header_id           => l_ae_header_id
73320          );
73321 
73322    --
73323    -- set rounding class
73324    --
73325    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
73326                       'ASSET';
73327 
73328    --
73329    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
73330    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
73331    --
73332    -- bulk performance
73333    --
73334    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
73335 
73336    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
73337       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
73338 
73339    -- 4955764
73340    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
73341       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
73342 
73343    -- 4458381 Public Sector Enh
73344    
73345    --
73346    -- set accounting attributes for the line type
73347    --
73348    l_entered_amt_idx := 4;
73349    l_accted_amt_idx  := 6;
73350    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
73351    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
73352    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
73353    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
73354    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
73355    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
73356    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
73357    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
73358    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
73359    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
73360    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
73361    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
73362    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
73363 
73364    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
73365    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
73366 
73367    ---------------------------------------------------------------------------------------------------------------
73368    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
73369    ---------------------------------------------------------------------------------------------------------------
73370    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
73371 
73372    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
73373    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
73374 
73375    IF xla_accounting_cache_pkg.GetValueChar
73376          (p_source_code         => 'LEDGER_CATEGORY_CODE'
73377          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
73378    AND l_bflow_method_code = 'PRIOR_ENTRY'
73379 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
73380    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
73381          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
73382        )
73383    THEN
73384          xla_ae_lines_pkg.BflowUpgEntry
73385            (p_business_method_code    => l_bflow_method_code
73386            ,p_business_class_code     => l_bflow_class_code
73387            ,p_balance_type            => l_balance_type_code);
73388    ELSE
73389       NULL;
73390 -- No business flow processing for business flow method of NONE.
73391    END IF;
73392 
73393    --
73394    -- call analytical criteria
73395    --
73396    
73397    --
73398    -- call description
73399    --
73400    
73401 xla_ae_lines_pkg.SetLineDescription(
73402    p_ae_header_id => l_ae_header_id
73403   ,p_description  => Description_78 (
73404      p_application_id         => p_application_id
73405    , p_ae_header_id           => l_ae_header_id 
73406 , p_source_1 => p_source_1
73407    )
73408 );
73409 
73410 
73411    --
73412    -- call ADRs
73413    -- Bug 4922099
73414    --
73415    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
73416         (NVL(l_actual_upg_option, 'N') = 'O') OR
73417         (NVL(l_enc_upg_option, 'N') = 'O')
73418       )
73419    THEN
73420    NULL;
73421    --
73422    --
73423    
73424   l_ccid := AcctDerRule_173(
73425            p_application_id           => p_application_id
73426          , p_ae_header_id             => l_ae_header_id 
73427 , p_source_3 => p_source_3
73428 , p_source_30 => p_source_30
73429          , x_transaction_coa_id       => l_adr_transaction_coa_id
73433    );
73430          , x_accounting_coa_id        => l_adr_accounting_coa_id
73431          , x_value_type_code          => l_adr_value_type_code
73432          , p_side                     => 'NA'
73434 
73435    xla_ae_lines_pkg.set_ccid(
73436     p_code_combination_id          => l_ccid
73437   , p_value_type_code              => l_adr_value_type_code
73438   , p_transaction_coa_id           => l_adr_transaction_coa_id
73439   , p_accounting_coa_id            => l_adr_accounting_coa_id
73440   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
73441   , p_adr_type_code                => 'S'
73442   , p_component_type               => l_component_type
73443   , p_component_code               => l_component_code
73444   , p_component_type_code          => l_component_type_code
73445   , p_component_appl_id            => l_component_appl_id
73446   , p_amb_context_code             => l_amb_context_code
73447   , p_side                         => 'NA'
73448   );
73449 
73450 
73451    l_segment := AcctDerRule_152(
73452            p_application_id           => p_application_id
73453          , p_ae_header_id             => l_ae_header_id 
73454 , p_source_3 => p_source_3
73455 , p_source_13 => p_source_13
73456          , x_transaction_coa_id       => l_adr_transaction_coa_id
73457          , x_accounting_coa_id        => l_adr_accounting_coa_id
73458          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
73459          , x_flex_value_set_id        => l_adr_flex_value_set_id
73460          , x_value_type_code          => l_adr_value_type_code
73461          , x_value_combination_id     => l_adr_value_combination_id
73462          , x_value_segment_code       => l_adr_value_segment_code
73463          , p_side                     => 'NA'
73464          , p_override_seg_flag        => 'Y'
73465    );
73466 
73467    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
73468 
73469       xla_ae_lines_pkg.set_segment(
73470           p_to_segment_code         => 'GL_ACCOUNT'
73471         , p_segment_value           => l_segment
73472         , p_from_segment_code       => l_adr_value_segment_code
73473         , p_from_combination_id     => l_adr_value_combination_id
73474         , p_value_type_code         => l_adr_value_type_code
73475         , p_transaction_coa_id      => l_adr_transaction_coa_id
73476         , p_accounting_coa_id       => l_adr_accounting_coa_id
73477         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
73478         , p_flex_value_set_id       => l_adr_flex_value_set_id
73479         , p_adr_code                => 'FA_COST_OF_REM_GAIN_SEGMENT'
73480         , p_adr_type_code           => 'S'
73481         , p_component_type          => l_component_type
73482         , p_component_code          => l_component_code
73483         , p_component_type_code     => l_component_type_code
73484         , p_component_appl_id       => l_component_appl_id
73485         , p_amb_context_code        => l_amb_context_code
73486         , p_entity_code             => 'TRANSACTIONS'
73487         , p_event_class_code        => 'RETIREMENTS'
73488         , p_side                    => 'NA'
73489         );
73490 
73491   END IF;
73492 
73493    l_segment := AcctDerRule_168(
73494            p_application_id           => p_application_id
73495          , p_ae_header_id             => l_ae_header_id 
73496 , p_source_3 => p_source_3
73497 , p_source_29 => p_source_29
73498          , x_transaction_coa_id       => l_adr_transaction_coa_id
73499          , x_accounting_coa_id        => l_adr_accounting_coa_id
73500          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
73501          , x_flex_value_set_id        => l_adr_flex_value_set_id
73502          , x_value_type_code          => l_adr_value_type_code
73503          , x_value_combination_id     => l_adr_value_combination_id
73504          , x_value_segment_code       => l_adr_value_segment_code
73505          , p_side                     => 'NA'
73506          , p_override_seg_flag        => 'Y'
73507    );
73508 
73509    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
73510 
73511       xla_ae_lines_pkg.set_segment(
73512           p_to_segment_code         => 'GL_BALANCING'
73513         , p_segment_value           => l_segment
73514         , p_from_segment_code       => l_adr_value_segment_code
73515         , p_from_combination_id     => l_adr_value_combination_id
73516         , p_value_type_code         => l_adr_value_type_code
73517         , p_transaction_coa_id      => l_adr_transaction_coa_id
73518         , p_accounting_coa_id       => l_adr_accounting_coa_id
73519         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
73520         , p_flex_value_set_id       => l_adr_flex_value_set_id
73521         , p_adr_code                => 'FA_EXPENSE_ACCT'
73522         , p_adr_type_code           => 'S'
73523         , p_component_type          => l_component_type
73524         , p_component_code          => l_component_code
73525         , p_component_type_code     => l_component_type_code
73526         , p_component_appl_id       => l_component_appl_id
73527         , p_amb_context_code        => l_amb_context_code
73528         , p_entity_code             => 'TRANSACTIONS'
73529         , p_event_class_code        => 'RETIREMENTS'
73530         , p_side                    => 'NA'
73531         );
73532 
73533   END IF;
73534 
73535    --
73536    --
73537    END IF;
73538    --
73539    -- Bug 4922099
73540    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
73541           (NVL(l_enc_upg_option, 'N') = 'O')
73542         ) AND
73543         (l_bflow_method_code = 'PRIOR_ENTRY')
73544       )
73545    THEN
73546       IF
73547       --
73548       1 = 2
73549       --
73550       THEN
73551       xla_accounting_err_pkg.build_message
73552                                     (p_appli_s_name            => 'XLA'
73556                                     ,p_token_2                 => 'LINE_TYPE_NAME'
73553                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
73554                                     ,p_token_1                 => 'LINE_NUMBER'
73555                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
73557                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
73558                                                                              l_component_type
73559                                                                             ,l_component_code
73560                                                                             ,l_component_type_code
73561                                                                             ,l_component_appl_id
73562                                                                             ,l_amb_context_code
73563                                                                             ,l_entity_code
73564                                                                             ,l_event_class_code
73565                                                                            )
73566                                     ,p_token_3                 => 'OWNER'
73567                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
73568                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
73569                                                                           ,p_lookup_code    => l_component_type_code
73570                                                                          )
73571                                     ,p_token_4                 => 'PRODUCT_NAME'
73572                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
73573                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
73574                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
73575                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
73576                                     ,p_ae_header_id            =>  NULL
73577                                        );
73578 
73579         IF (C_LEVEL_ERROR>= g_log_level) THEN
73580                  trace
73581                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
73582                       ,p_level    => C_LEVEL_ERROR
73583                       ,p_module   => l_log_module);
73584         END IF;
73585       END IF;
73586    END IF;
73587    --
73588    --
73589    ------------------------------------------------------------------------------------------------
73590    -- 4219869 Business Flow
73591    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
73592    -- Prior Entry.  Currently, the following code is always generated.
73593    ------------------------------------------------------------------------------------------------
73594    XLA_AE_LINES_PKG.ValidateCurrentLine;
73595 
73596    ------------------------------------------------------------------------------------
73597    -- 4219869 Business Flow
73598    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
73599    ------------------------------------------------------------------------------------
73600    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
73601 
73602    ----------------------------------------------------------------------------------
73603    -- 4219869 Business Flow
73604    -- Update journal entry status -- Need to generate this within IF <condition>
73605    ----------------------------------------------------------------------------------
73606    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
73607          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
73608          ,p_balance_type_code => l_balance_type_code
73609          );
73610 
73611    -------------------------------------------------------------------------------------------
73612    -- 4262811 - Generate the Accrual Reversal lines
73613    -------------------------------------------------------------------------------------------
73614    BEGIN
73615       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
73616                               (g_array_event(p_event_id).array_value_num('header_index'));
73617       IF l_acc_rev_flag IS NULL THEN
73618          l_acc_rev_flag := 'N';
73619       END IF;
73620    EXCEPTION
73621       WHEN OTHERS THEN
73622          l_acc_rev_flag := 'N';
73623    END;
73624    --
73625    IF (l_acc_rev_flag = 'Y') THEN
73626 
73627        -- 4645092  ------------------------------------------------------------------------------
73628        -- To allow MPA report to determine if it should generate report process
73629        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
73630        ------------------------------------------------------------------------------------------
73631 
73632        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
73633        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
73634    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
73635    -- call ADRs
73636    -- Bug 4922099
73637    --
73638    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
73639         (NVL(l_actual_upg_option, 'N') = 'O') OR
73640         (NVL(l_enc_upg_option, 'N') = 'O')
73641       )
73642    THEN
73643    NULL;
73644    --
73645    --
73646    
73647   l_ccid := AcctDerRule_173(
73648            p_application_id           => p_application_id
73649          , p_ae_header_id             => l_ae_header_id 
73650 , p_source_3 => p_source_3
73651 , p_source_30 => p_source_30
73652          , x_transaction_coa_id       => l_adr_transaction_coa_id
73653          , x_accounting_coa_id        => l_adr_accounting_coa_id
73657 
73654          , x_value_type_code          => l_adr_value_type_code
73655          , p_side                     => 'NA'
73656    );
73658    xla_ae_lines_pkg.set_ccid(
73659     p_code_combination_id          => l_ccid
73660   , p_value_type_code              => l_adr_value_type_code
73661   , p_transaction_coa_id           => l_adr_transaction_coa_id
73662   , p_accounting_coa_id            => l_adr_accounting_coa_id
73663   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
73664   , p_adr_type_code                => 'S'
73665   , p_component_type               => l_component_type
73666   , p_component_code               => l_component_code
73667   , p_component_type_code          => l_component_type_code
73668   , p_component_appl_id            => l_component_appl_id
73669   , p_amb_context_code             => l_amb_context_code
73670   , p_side                         => 'NA'
73671   );
73672 
73673 
73674    l_segment := AcctDerRule_152(
73675            p_application_id           => p_application_id
73676          , p_ae_header_id             => l_ae_header_id 
73677 , p_source_3 => p_source_3
73678 , p_source_13 => p_source_13
73679          , x_transaction_coa_id       => l_adr_transaction_coa_id
73680          , x_accounting_coa_id        => l_adr_accounting_coa_id
73681          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
73682          , x_flex_value_set_id        => l_adr_flex_value_set_id
73683          , x_value_type_code          => l_adr_value_type_code
73684          , x_value_combination_id     => l_adr_value_combination_id
73685          , x_value_segment_code       => l_adr_value_segment_code
73686          , p_side                     => 'NA'
73687          , p_override_seg_flag        => 'Y'
73688    );
73689 
73690    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
73691 
73692       xla_ae_lines_pkg.set_segment(
73693           p_to_segment_code         => 'GL_ACCOUNT'
73694         , p_segment_value           => l_segment
73695         , p_from_segment_code       => l_adr_value_segment_code
73696         , p_from_combination_id     => l_adr_value_combination_id
73697         , p_value_type_code         => l_adr_value_type_code
73698         , p_transaction_coa_id      => l_adr_transaction_coa_id
73699         , p_accounting_coa_id       => l_adr_accounting_coa_id
73700         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
73701         , p_flex_value_set_id       => l_adr_flex_value_set_id
73702         , p_adr_code                => 'FA_COST_OF_REM_GAIN_SEGMENT'
73703         , p_adr_type_code           => 'S'
73704         , p_component_type          => l_component_type
73705         , p_component_code          => l_component_code
73706         , p_component_type_code     => l_component_type_code
73707         , p_component_appl_id       => l_component_appl_id
73708         , p_amb_context_code        => l_amb_context_code
73709         , p_entity_code             => 'TRANSACTIONS'
73710         , p_event_class_code        => 'RETIREMENTS'
73711         , p_side                    => 'NA'
73712         );
73713 
73714   END IF;
73715 
73716    l_segment := AcctDerRule_168(
73717            p_application_id           => p_application_id
73718          , p_ae_header_id             => l_ae_header_id 
73719 , p_source_3 => p_source_3
73720 , p_source_29 => p_source_29
73721          , x_transaction_coa_id       => l_adr_transaction_coa_id
73722          , x_accounting_coa_id        => l_adr_accounting_coa_id
73723          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
73724          , x_flex_value_set_id        => l_adr_flex_value_set_id
73725          , x_value_type_code          => l_adr_value_type_code
73726          , x_value_combination_id     => l_adr_value_combination_id
73727          , x_value_segment_code       => l_adr_value_segment_code
73728          , p_side                     => 'NA'
73729          , p_override_seg_flag        => 'Y'
73730    );
73731 
73732    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
73733 
73734       xla_ae_lines_pkg.set_segment(
73735           p_to_segment_code         => 'GL_BALANCING'
73736         , p_segment_value           => l_segment
73737         , p_from_segment_code       => l_adr_value_segment_code
73738         , p_from_combination_id     => l_adr_value_combination_id
73739         , p_value_type_code         => l_adr_value_type_code
73740         , p_transaction_coa_id      => l_adr_transaction_coa_id
73741         , p_accounting_coa_id       => l_adr_accounting_coa_id
73742         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
73743         , p_flex_value_set_id       => l_adr_flex_value_set_id
73744         , p_adr_code                => 'FA_EXPENSE_ACCT'
73745         , p_adr_type_code           => 'S'
73746         , p_component_type          => l_component_type
73747         , p_component_code          => l_component_code
73748         , p_component_type_code     => l_component_type_code
73749         , p_component_appl_id       => l_component_appl_id
73750         , p_amb_context_code        => l_amb_context_code
73751         , p_entity_code             => 'TRANSACTIONS'
73752         , p_event_class_code        => 'RETIREMENTS'
73753         , p_side                    => 'NA'
73754         );
73755 
73756   END IF;
73757 
73758    --
73759    --
73760    END IF;
73761 
73762        --
73763        -- Update the line information that should be overwritten
73764        --
73765        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
73766                                          p_header_num   => 1);
73767        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
73768 
73769        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
73770 
73771        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
73775       --
73772           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
73773        END IF;
73774 
73776       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
73777       --
73778       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
73779           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
73780       ELSE
73781           ---------------------------------------------------------------------------------------------------
73782           -- 4262811a Switch Sign
73783           ---------------------------------------------------------------------------------------------------
73784           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
73785           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
73786                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
73787           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
73788                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
73789           -- 5132302
73790           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
73791                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
73792 
73793       END IF;
73794 
73795       -- 4955764
73796       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
73797       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
73798 
73799 
73800       XLA_AE_LINES_PKG.ValidateCurrentLine;
73801       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
73802 
73803       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
73804                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
73805                ,p_balance_type_code => l_balance_type_code);
73806 
73807    END IF;
73808 
73809    -----------------------------------------------------------------------------------------
73810    -- 4262811 Multiperiod Accounting
73811    -----------------------------------------------------------------------------------------
73812      -- No MPA option is assigned.
73813 
73814 
73815 END IF;
73816 END IF;
73817 --
73818 
73819 --
73820 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
73821    trace
73822       (p_msg      => 'END of AcctLineType_256'
73823       ,p_level    => C_LEVEL_PROCEDURE
73824       ,p_module   => l_log_module);
73825 END IF;
73826 --
73827 EXCEPTION
73828   WHEN xla_exceptions_pkg.application_exception THEN
73829       RAISE;
73830   WHEN OTHERS THEN
73831        xla_exceptions_pkg.raise_message
73832            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_256');
73833 END AcctLineType_256;
73834 --
73835 
73836 ---------------------------------------
73837 --
73838 -- PRIVATE FUNCTION
73839 --         AcctLineType_257
73840 --
73841 ---------------------------------------
73842 PROCEDURE AcctLineType_257 (
73843   p_application_id        IN NUMBER
73844  ,p_event_id              IN NUMBER
73845  ,p_calculate_acctd_flag  IN VARCHAR2
73846  ,p_calculate_g_l_flag    IN VARCHAR2
73847  ,p_actual_flag           IN OUT VARCHAR2
73848  ,p_balance_type_code     OUT VARCHAR2
73849  ,p_gain_or_loss_ref      OUT VARCHAR2
73850  
73851 --Period Close Date
73852  , p_source_1            IN DATE
73853 --Generated Code Combination Identifier
73854  , p_source_3            IN NUMBER
73855 --Cost Of Removal Loss Account
73856  , p_source_14            IN VARCHAR2
73857 --Expense Account Code Combination Identifier
73858  , p_source_29            IN NUMBER
73859 --Default Code Combination Identifier
73860  , p_source_30            IN NUMBER
73861 --Adjustment Type
73862  , p_source_35            IN VARCHAR2
73863 --Transaction Header Identifier
73864  , p_source_36            IN NUMBER
73865 --Adjustment Line Identifier
73866  , p_source_37            IN NUMBER
73867 --Distribution Type Code
73868  , p_source_38            IN VARCHAR2
73869 --Entered Amount
73870  , p_source_39            IN NUMBER
73871 --Currency Code
73872  , p_source_40            IN VARCHAR2
73873 --Gain Loss Amount
73874  , p_source_41            IN NUMBER
73875 )
73876 IS
73877 
73878 l_component_type              VARCHAR2(80);
73879 l_component_code              VARCHAR2(30);
73880 l_component_type_code         VARCHAR2(1);
73881 l_component_appl_id           INTEGER;
73882 l_amb_context_code            VARCHAR2(30);
73883 l_entity_code                 VARCHAR2(30);
73884 l_event_class_code            VARCHAR2(30);
73885 l_ae_header_id                NUMBER;
73886 l_event_type_code             VARCHAR2(30);
73887 l_line_definition_code        VARCHAR2(30);
73888 l_line_definition_owner_code  VARCHAR2(1);
73889 --
73890 -- adr variables
73891 l_segment                     VARCHAR2(30);
73892 l_ccid                        NUMBER;
73893 l_adr_transaction_coa_id      NUMBER;
73894 l_adr_accounting_coa_id       NUMBER;
73895 l_adr_flexfield_segment_code  VARCHAR2(30);
73896 l_adr_flex_value_set_id       NUMBER;
73897 l_adr_value_type_code         VARCHAR2(30);
73898 l_adr_value_combination_id    NUMBER;
73899 l_adr_value_segment_code      VARCHAR2(30);
73900 
73901 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
73902 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
73903 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
73904 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
73905 
73909 l_acc_rev_flag                VARCHAR2(1);
73906 -- 4262811 Variables ------------------------------------------------------------------------------------------
73907 l_entered_amt_idx             NUMBER;
73908 l_accted_amt_idx              NUMBER;
73910 l_accrual_line_num            NUMBER;
73911 l_tmp_amt                     NUMBER;
73912 l_acc_rev_natural_side_code   VARCHAR2(1);
73913 
73914 l_num_entries                 NUMBER;
73915 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
73916 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
73917 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
73918 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
73919 l_recog_line_1                NUMBER;
73920 l_recog_line_2                NUMBER;
73921 
73922 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
73923 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
73924 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
73925 
73926 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
73927 
73928 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
73929 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
73930 
73931 ---------------------------------------------------------------------------------------------------------------
73932 
73933 
73934 --
73935 -- bulk performance
73936 --
73937 l_balance_type_code           VARCHAR2(1);
73938 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
73939 l_log_module                  VARCHAR2(240);
73940 
73941 --
73942 -- Upgrade strategy
73943 --
73944 l_actual_upg_option           VARCHAR2(1);
73945 l_enc_upg_option           VARCHAR2(1);
73946 
73947 --
73948 BEGIN
73949 --
73950 IF g_log_enabled THEN
73951       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_257';
73952 END IF;
73953 --
73954 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
73955 
73956       trace
73957          (p_msg      => 'BEGIN of AcctLineType_257'
73958          ,p_level    => C_LEVEL_PROCEDURE
73959          ,p_module   => l_log_module);
73960 
73961 END IF;
73962 --
73963 l_component_type             := 'AMB_JLT';
73964 l_component_code             := 'FA_COST_OF_REMOVAL_LOSS';
73965 l_component_type_code        := 'S';
73966 l_component_appl_id          :=  140;
73967 l_amb_context_code           := 'DEFAULT';
73968 l_entity_code                := 'TRANSACTIONS';
73969 l_event_class_code           := 'RETIREMENTS';
73970 l_event_type_code            := 'REINSTATEMENTS';
73971 l_line_definition_owner_code := 'S';
73972 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
73973 --
73974 l_balance_type_code          := 'A';
73975 l_segment                     := NULL;
73976 l_ccid                        := NULL;
73977 l_adr_transaction_coa_id      := NULL;
73978 l_adr_accounting_coa_id       := NULL;
73979 l_adr_flexfield_segment_code  := NULL;
73980 l_adr_flex_value_set_id       := NULL;
73981 l_adr_value_type_code         := NULL;
73982 l_adr_value_combination_id    := NULL;
73983 l_adr_value_segment_code      := NULL;
73984 
73985 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
73986 l_bflow_class_code           := '';    -- 4219869 Business Flow
73987 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
73988 l_budgetary_control_flag     := 'N';
73989 
73990 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
73991 l_bflow_applied_to_amt       := NULL; -- 5132302
73992 l_entered_amt_idx            := NULL;          -- 4262811
73993 l_accted_amt_idx             := NULL;          -- 4262811
73994 l_acc_rev_flag               := NULL;          -- 4262811
73995 l_accrual_line_num           := NULL;          -- 4262811
73996 l_tmp_amt                    := NULL;          -- 4262811
73997 --
73998  
73999 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
74000     l_balance_type_code <> 'B' THEN
74001 IF NVL(p_source_35,'
74002 ') =  'REMOVALCOST' AND 
74003 p_source_41 <  0
74004  THEN 
74005 
74006    --
74007    XLA_AE_LINES_PKG.SetNewLine;
74008 
74009    p_balance_type_code          := l_balance_type_code;
74010    -- set the flag so later we will know whether the gain loss line needs to be created
74011    
74012    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
74013      p_actual_flag :='A';
74014    END IF;
74015 
74016    --
74017    -- bulk performance
74018    --
74019    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
74020                                       p_header_num   => 0); -- 4262811
74021    --
74022    -- set accounting line options
74023    --
74024    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
74025            p_natural_side_code          => 'D'
74026          , p_gain_or_loss_flag          => 'N'
74027          , p_gl_transfer_mode_code      => 'S'
74028          , p_acct_entry_type_code       => 'A'
74029          , p_switch_side_flag           => 'Y'
74030          , p_merge_duplicate_code       => 'N'
74031          );
74032    --
74033    l_acc_rev_natural_side_code := 'C';  -- 4262811
74034    -- 
74035    --
74036    -- set accounting line type info
74037    --
74038    xla_ae_lines_pkg.SetAcctLineType
74039       (p_component_type             => l_component_type
74040       ,p_event_type_code            => l_event_type_code
74041       ,p_line_definition_owner_code => l_line_definition_owner_code
74042       ,p_line_definition_code       => l_line_definition_code
74043       ,p_accounting_line_code       => l_component_code
74044       ,p_accounting_line_type_code  => l_component_type_code
74048       ,p_event_class_code           => l_event_class_code);
74045       ,p_accounting_line_appl_id    => l_component_appl_id
74046       ,p_amb_context_code           => l_amb_context_code
74047       ,p_entity_code                => l_entity_code
74049    --
74050    -- set accounting class
74051    --
74052    xla_ae_lines_pkg.SetAcctClass(
74053            p_accounting_class_code  => 'ASSET'
74054          , p_ae_header_id           => l_ae_header_id
74055          );
74056 
74057    --
74058    -- set rounding class
74059    --
74060    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
74061                       'ASSET';
74062 
74063    --
74064    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
74065    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
74066    --
74067    -- bulk performance
74068    --
74069    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
74070 
74071    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
74072       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
74073 
74074    -- 4955764
74075    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
74076       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
74077 
74078    -- 4458381 Public Sector Enh
74079    
74080    --
74081    -- set accounting attributes for the line type
74082    --
74083    l_entered_amt_idx := 4;
74084    l_accted_amt_idx  := 6;
74085    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
74086    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
74087    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
74088    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
74089    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
74090    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
74091    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
74092    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
74093    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
74094    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
74095    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
74096    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
74097    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
74098 
74099    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
74100    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
74101 
74102    ---------------------------------------------------------------------------------------------------------------
74103    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
74104    ---------------------------------------------------------------------------------------------------------------
74105    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
74106 
74107    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
74108    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
74109 
74110    IF xla_accounting_cache_pkg.GetValueChar
74111          (p_source_code         => 'LEDGER_CATEGORY_CODE'
74112          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
74113    AND l_bflow_method_code = 'PRIOR_ENTRY'
74114 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
74115    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
74116          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
74117        )
74118    THEN
74119          xla_ae_lines_pkg.BflowUpgEntry
74120            (p_business_method_code    => l_bflow_method_code
74121            ,p_business_class_code     => l_bflow_class_code
74122            ,p_balance_type            => l_balance_type_code);
74123    ELSE
74124       NULL;
74125 -- No business flow processing for business flow method of NONE.
74126    END IF;
74127 
74128    --
74129    -- call analytical criteria
74130    --
74131    
74132    --
74133    -- call description
74134    --
74135    
74136 xla_ae_lines_pkg.SetLineDescription(
74137    p_ae_header_id => l_ae_header_id
74138   ,p_description  => Description_78 (
74139      p_application_id         => p_application_id
74140    , p_ae_header_id           => l_ae_header_id 
74141 , p_source_1 => p_source_1
74142    )
74143 );
74144 
74145 
74146    --
74147    -- call ADRs
74148    -- Bug 4922099
74149    --
74150    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
74151         (NVL(l_actual_upg_option, 'N') = 'O') OR
74152         (NVL(l_enc_upg_option, 'N') = 'O')
74153       )
74154    THEN
74155    NULL;
74156    --
74157    --
74158    
74159   l_ccid := AcctDerRule_173(
74160            p_application_id           => p_application_id
74161          , p_ae_header_id             => l_ae_header_id 
74162 , p_source_3 => p_source_3
74163 , p_source_30 => p_source_30
74164          , x_transaction_coa_id       => l_adr_transaction_coa_id
74165          , x_accounting_coa_id        => l_adr_accounting_coa_id
74166          , x_value_type_code          => l_adr_value_type_code
74167          , p_side                     => 'NA'
74168    );
74169 
74170    xla_ae_lines_pkg.set_ccid(
74171     p_code_combination_id          => l_ccid
74172   , p_value_type_code              => l_adr_value_type_code
74173   , p_transaction_coa_id           => l_adr_transaction_coa_id
74174   , p_accounting_coa_id            => l_adr_accounting_coa_id
74178   , p_component_code               => l_component_code
74175   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
74176   , p_adr_type_code                => 'S'
74177   , p_component_type               => l_component_type
74179   , p_component_type_code          => l_component_type_code
74180   , p_component_appl_id            => l_component_appl_id
74181   , p_amb_context_code             => l_amb_context_code
74182   , p_side                         => 'NA'
74183   );
74184 
74185 
74186    l_segment := AcctDerRule_153(
74187            p_application_id           => p_application_id
74188          , p_ae_header_id             => l_ae_header_id 
74189 , p_source_3 => p_source_3
74190 , p_source_14 => p_source_14
74191          , x_transaction_coa_id       => l_adr_transaction_coa_id
74192          , x_accounting_coa_id        => l_adr_accounting_coa_id
74193          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
74194          , x_flex_value_set_id        => l_adr_flex_value_set_id
74195          , x_value_type_code          => l_adr_value_type_code
74196          , x_value_combination_id     => l_adr_value_combination_id
74197          , x_value_segment_code       => l_adr_value_segment_code
74198          , p_side                     => 'NA'
74199          , p_override_seg_flag        => 'Y'
74200    );
74201 
74202    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
74203 
74204       xla_ae_lines_pkg.set_segment(
74205           p_to_segment_code         => 'GL_ACCOUNT'
74206         , p_segment_value           => l_segment
74207         , p_from_segment_code       => l_adr_value_segment_code
74208         , p_from_combination_id     => l_adr_value_combination_id
74209         , p_value_type_code         => l_adr_value_type_code
74210         , p_transaction_coa_id      => l_adr_transaction_coa_id
74211         , p_accounting_coa_id       => l_adr_accounting_coa_id
74212         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
74213         , p_flex_value_set_id       => l_adr_flex_value_set_id
74214         , p_adr_code                => 'FA_COST_OF_REM_LOSS_SEGMENT'
74215         , p_adr_type_code           => 'S'
74216         , p_component_type          => l_component_type
74217         , p_component_code          => l_component_code
74218         , p_component_type_code     => l_component_type_code
74219         , p_component_appl_id       => l_component_appl_id
74220         , p_amb_context_code        => l_amb_context_code
74221         , p_entity_code             => 'TRANSACTIONS'
74222         , p_event_class_code        => 'RETIREMENTS'
74223         , p_side                    => 'NA'
74224         );
74225 
74226   END IF;
74227 
74228    l_segment := AcctDerRule_168(
74229            p_application_id           => p_application_id
74230          , p_ae_header_id             => l_ae_header_id 
74231 , p_source_3 => p_source_3
74232 , p_source_29 => p_source_29
74233          , x_transaction_coa_id       => l_adr_transaction_coa_id
74234          , x_accounting_coa_id        => l_adr_accounting_coa_id
74235          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
74236          , x_flex_value_set_id        => l_adr_flex_value_set_id
74237          , x_value_type_code          => l_adr_value_type_code
74238          , x_value_combination_id     => l_adr_value_combination_id
74239          , x_value_segment_code       => l_adr_value_segment_code
74240          , p_side                     => 'NA'
74241          , p_override_seg_flag        => 'Y'
74242    );
74243 
74244    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
74245 
74246       xla_ae_lines_pkg.set_segment(
74247           p_to_segment_code         => 'GL_BALANCING'
74248         , p_segment_value           => l_segment
74249         , p_from_segment_code       => l_adr_value_segment_code
74250         , p_from_combination_id     => l_adr_value_combination_id
74251         , p_value_type_code         => l_adr_value_type_code
74252         , p_transaction_coa_id      => l_adr_transaction_coa_id
74253         , p_accounting_coa_id       => l_adr_accounting_coa_id
74254         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
74255         , p_flex_value_set_id       => l_adr_flex_value_set_id
74256         , p_adr_code                => 'FA_EXPENSE_ACCT'
74257         , p_adr_type_code           => 'S'
74258         , p_component_type          => l_component_type
74259         , p_component_code          => l_component_code
74260         , p_component_type_code     => l_component_type_code
74261         , p_component_appl_id       => l_component_appl_id
74262         , p_amb_context_code        => l_amb_context_code
74263         , p_entity_code             => 'TRANSACTIONS'
74264         , p_event_class_code        => 'RETIREMENTS'
74265         , p_side                    => 'NA'
74266         );
74267 
74268   END IF;
74269 
74270    --
74271    --
74272    END IF;
74273    --
74274    -- Bug 4922099
74275    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
74276           (NVL(l_enc_upg_option, 'N') = 'O')
74277         ) AND
74278         (l_bflow_method_code = 'PRIOR_ENTRY')
74279       )
74280    THEN
74281       IF
74282       --
74283       1 = 2
74284       --
74285       THEN
74286       xla_accounting_err_pkg.build_message
74287                                     (p_appli_s_name            => 'XLA'
74288                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
74289                                     ,p_token_1                 => 'LINE_NUMBER'
74290                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
74291                                     ,p_token_2                 => 'LINE_TYPE_NAME'
74292                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
74293                                                                              l_component_type
74297                                                                             ,l_amb_context_code
74294                                                                             ,l_component_code
74295                                                                             ,l_component_type_code
74296                                                                             ,l_component_appl_id
74298                                                                             ,l_entity_code
74299                                                                             ,l_event_class_code
74300                                                                            )
74301                                     ,p_token_3                 => 'OWNER'
74302                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
74303                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
74304                                                                           ,p_lookup_code    => l_component_type_code
74305                                                                          )
74306                                     ,p_token_4                 => 'PRODUCT_NAME'
74307                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
74308                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
74309                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
74310                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
74311                                     ,p_ae_header_id            =>  NULL
74312                                        );
74313 
74314         IF (C_LEVEL_ERROR>= g_log_level) THEN
74315                  trace
74316                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
74317                       ,p_level    => C_LEVEL_ERROR
74318                       ,p_module   => l_log_module);
74319         END IF;
74320       END IF;
74321    END IF;
74322    --
74323    --
74324    ------------------------------------------------------------------------------------------------
74325    -- 4219869 Business Flow
74326    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
74327    -- Prior Entry.  Currently, the following code is always generated.
74328    ------------------------------------------------------------------------------------------------
74329    XLA_AE_LINES_PKG.ValidateCurrentLine;
74330 
74331    ------------------------------------------------------------------------------------
74332    -- 4219869 Business Flow
74333    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
74334    ------------------------------------------------------------------------------------
74335    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
74336 
74337    ----------------------------------------------------------------------------------
74338    -- 4219869 Business Flow
74339    -- Update journal entry status -- Need to generate this within IF <condition>
74340    ----------------------------------------------------------------------------------
74341    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
74342          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
74343          ,p_balance_type_code => l_balance_type_code
74344          );
74345 
74346    -------------------------------------------------------------------------------------------
74347    -- 4262811 - Generate the Accrual Reversal lines
74348    -------------------------------------------------------------------------------------------
74349    BEGIN
74350       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
74351                               (g_array_event(p_event_id).array_value_num('header_index'));
74352       IF l_acc_rev_flag IS NULL THEN
74353          l_acc_rev_flag := 'N';
74354       END IF;
74355    EXCEPTION
74356       WHEN OTHERS THEN
74357          l_acc_rev_flag := 'N';
74358    END;
74359    --
74360    IF (l_acc_rev_flag = 'Y') THEN
74361 
74362        -- 4645092  ------------------------------------------------------------------------------
74363        -- To allow MPA report to determine if it should generate report process
74364        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
74365        ------------------------------------------------------------------------------------------
74366 
74367        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
74368        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
74369    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
74370    -- call ADRs
74371    -- Bug 4922099
74372    --
74373    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
74374         (NVL(l_actual_upg_option, 'N') = 'O') OR
74375         (NVL(l_enc_upg_option, 'N') = 'O')
74376       )
74377    THEN
74378    NULL;
74379    --
74380    --
74381    
74382   l_ccid := AcctDerRule_173(
74383            p_application_id           => p_application_id
74384          , p_ae_header_id             => l_ae_header_id 
74385 , p_source_3 => p_source_3
74386 , p_source_30 => p_source_30
74387          , x_transaction_coa_id       => l_adr_transaction_coa_id
74388          , x_accounting_coa_id        => l_adr_accounting_coa_id
74389          , x_value_type_code          => l_adr_value_type_code
74390          , p_side                     => 'NA'
74391    );
74392 
74393    xla_ae_lines_pkg.set_ccid(
74394     p_code_combination_id          => l_ccid
74395   , p_value_type_code              => l_adr_value_type_code
74396   , p_transaction_coa_id           => l_adr_transaction_coa_id
74397   , p_accounting_coa_id            => l_adr_accounting_coa_id
74398   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
74399   , p_adr_type_code                => 'S'
74403   , p_component_appl_id            => l_component_appl_id
74400   , p_component_type               => l_component_type
74401   , p_component_code               => l_component_code
74402   , p_component_type_code          => l_component_type_code
74404   , p_amb_context_code             => l_amb_context_code
74405   , p_side                         => 'NA'
74406   );
74407 
74408 
74409    l_segment := AcctDerRule_153(
74410            p_application_id           => p_application_id
74411          , p_ae_header_id             => l_ae_header_id 
74412 , p_source_3 => p_source_3
74413 , p_source_14 => p_source_14
74414          , x_transaction_coa_id       => l_adr_transaction_coa_id
74415          , x_accounting_coa_id        => l_adr_accounting_coa_id
74416          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
74417          , x_flex_value_set_id        => l_adr_flex_value_set_id
74418          , x_value_type_code          => l_adr_value_type_code
74419          , x_value_combination_id     => l_adr_value_combination_id
74420          , x_value_segment_code       => l_adr_value_segment_code
74421          , p_side                     => 'NA'
74422          , p_override_seg_flag        => 'Y'
74423    );
74424 
74425    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
74426 
74427       xla_ae_lines_pkg.set_segment(
74428           p_to_segment_code         => 'GL_ACCOUNT'
74429         , p_segment_value           => l_segment
74430         , p_from_segment_code       => l_adr_value_segment_code
74431         , p_from_combination_id     => l_adr_value_combination_id
74432         , p_value_type_code         => l_adr_value_type_code
74433         , p_transaction_coa_id      => l_adr_transaction_coa_id
74434         , p_accounting_coa_id       => l_adr_accounting_coa_id
74435         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
74436         , p_flex_value_set_id       => l_adr_flex_value_set_id
74437         , p_adr_code                => 'FA_COST_OF_REM_LOSS_SEGMENT'
74438         , p_adr_type_code           => 'S'
74439         , p_component_type          => l_component_type
74440         , p_component_code          => l_component_code
74441         , p_component_type_code     => l_component_type_code
74442         , p_component_appl_id       => l_component_appl_id
74443         , p_amb_context_code        => l_amb_context_code
74444         , p_entity_code             => 'TRANSACTIONS'
74445         , p_event_class_code        => 'RETIREMENTS'
74446         , p_side                    => 'NA'
74447         );
74448 
74449   END IF;
74450 
74451    l_segment := AcctDerRule_168(
74452            p_application_id           => p_application_id
74453          , p_ae_header_id             => l_ae_header_id 
74454 , p_source_3 => p_source_3
74455 , p_source_29 => p_source_29
74456          , x_transaction_coa_id       => l_adr_transaction_coa_id
74457          , x_accounting_coa_id        => l_adr_accounting_coa_id
74458          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
74459          , x_flex_value_set_id        => l_adr_flex_value_set_id
74460          , x_value_type_code          => l_adr_value_type_code
74461          , x_value_combination_id     => l_adr_value_combination_id
74462          , x_value_segment_code       => l_adr_value_segment_code
74463          , p_side                     => 'NA'
74464          , p_override_seg_flag        => 'Y'
74465    );
74466 
74467    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
74468 
74469       xla_ae_lines_pkg.set_segment(
74470           p_to_segment_code         => 'GL_BALANCING'
74471         , p_segment_value           => l_segment
74472         , p_from_segment_code       => l_adr_value_segment_code
74473         , p_from_combination_id     => l_adr_value_combination_id
74474         , p_value_type_code         => l_adr_value_type_code
74475         , p_transaction_coa_id      => l_adr_transaction_coa_id
74476         , p_accounting_coa_id       => l_adr_accounting_coa_id
74477         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
74478         , p_flex_value_set_id       => l_adr_flex_value_set_id
74479         , p_adr_code                => 'FA_EXPENSE_ACCT'
74480         , p_adr_type_code           => 'S'
74481         , p_component_type          => l_component_type
74482         , p_component_code          => l_component_code
74483         , p_component_type_code     => l_component_type_code
74484         , p_component_appl_id       => l_component_appl_id
74485         , p_amb_context_code        => l_amb_context_code
74486         , p_entity_code             => 'TRANSACTIONS'
74487         , p_event_class_code        => 'RETIREMENTS'
74488         , p_side                    => 'NA'
74489         );
74490 
74491   END IF;
74492 
74493    --
74494    --
74495    END IF;
74496 
74497        --
74498        -- Update the line information that should be overwritten
74499        --
74500        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
74501                                          p_header_num   => 1);
74502        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
74503 
74504        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
74505 
74506        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
74507           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
74508        END IF;
74509 
74510       --
74511       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
74512       --
74513       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
74514           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
74515       ELSE
74519           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
74516           ---------------------------------------------------------------------------------------------------
74517           -- 4262811a Switch Sign
74518           ---------------------------------------------------------------------------------------------------
74520           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
74521                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
74522           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
74523                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
74524           -- 5132302
74525           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
74526                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
74527 
74528       END IF;
74529 
74530       -- 4955764
74531       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
74532       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
74533 
74534 
74535       XLA_AE_LINES_PKG.ValidateCurrentLine;
74536       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
74537 
74538       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
74539                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
74540                ,p_balance_type_code => l_balance_type_code);
74541 
74542    END IF;
74543 
74544    -----------------------------------------------------------------------------------------
74545    -- 4262811 Multiperiod Accounting
74546    -----------------------------------------------------------------------------------------
74547      -- No MPA option is assigned.
74548 
74549 
74550 END IF;
74551 END IF;
74552 --
74553 
74554 --
74555 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
74556    trace
74557       (p_msg      => 'END of AcctLineType_257'
74558       ,p_level    => C_LEVEL_PROCEDURE
74559       ,p_module   => l_log_module);
74560 END IF;
74561 --
74562 EXCEPTION
74563   WHEN xla_exceptions_pkg.application_exception THEN
74564       RAISE;
74565   WHEN OTHERS THEN
74566        xla_exceptions_pkg.raise_message
74567            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_257');
74568 END AcctLineType_257;
74569 --
74570 
74571 ---------------------------------------
74572 --
74573 -- PRIVATE FUNCTION
74574 --         AcctLineType_258
74575 --
74576 ---------------------------------------
74577 PROCEDURE AcctLineType_258 (
74578   p_application_id        IN NUMBER
74579  ,p_event_id              IN NUMBER
74580  ,p_calculate_acctd_flag  IN VARCHAR2
74581  ,p_calculate_g_l_flag    IN VARCHAR2
74582  ,p_actual_flag           IN OUT VARCHAR2
74583  ,p_balance_type_code     OUT VARCHAR2
74584  ,p_gain_or_loss_ref      OUT VARCHAR2
74585  
74586 --Period Close Date
74587  , p_source_1            IN DATE
74588 --Generated Code Combination Identifier
74589  , p_source_3            IN NUMBER
74590 --Cost Of Removal Loss Account
74591  , p_source_14            IN VARCHAR2
74592 --Expense Account Code Combination Identifier
74593  , p_source_29            IN NUMBER
74594 --Default Code Combination Identifier
74595  , p_source_30            IN NUMBER
74596 --Adjustment Type
74597  , p_source_35            IN VARCHAR2
74598 --Transaction Header Identifier
74599  , p_source_36            IN NUMBER
74600 --Adjustment Line Identifier
74601  , p_source_37            IN NUMBER
74602 --Distribution Type Code
74603  , p_source_38            IN VARCHAR2
74604 --Entered Amount
74605  , p_source_39            IN NUMBER
74606 --Currency Code
74607  , p_source_40            IN VARCHAR2
74608 --Gain Loss Amount
74609  , p_source_41            IN NUMBER
74610 )
74611 IS
74612 
74613 l_component_type              VARCHAR2(80);
74614 l_component_code              VARCHAR2(30);
74615 l_component_type_code         VARCHAR2(1);
74616 l_component_appl_id           INTEGER;
74617 l_amb_context_code            VARCHAR2(30);
74618 l_entity_code                 VARCHAR2(30);
74619 l_event_class_code            VARCHAR2(30);
74620 l_ae_header_id                NUMBER;
74621 l_event_type_code             VARCHAR2(30);
74622 l_line_definition_code        VARCHAR2(30);
74623 l_line_definition_owner_code  VARCHAR2(1);
74624 --
74625 -- adr variables
74626 l_segment                     VARCHAR2(30);
74627 l_ccid                        NUMBER;
74628 l_adr_transaction_coa_id      NUMBER;
74629 l_adr_accounting_coa_id       NUMBER;
74630 l_adr_flexfield_segment_code  VARCHAR2(30);
74631 l_adr_flex_value_set_id       NUMBER;
74632 l_adr_value_type_code         VARCHAR2(30);
74633 l_adr_value_combination_id    NUMBER;
74634 l_adr_value_segment_code      VARCHAR2(30);
74635 
74636 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
74637 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
74638 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
74639 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
74640 
74641 -- 4262811 Variables ------------------------------------------------------------------------------------------
74642 l_entered_amt_idx             NUMBER;
74643 l_accted_amt_idx              NUMBER;
74644 l_acc_rev_flag                VARCHAR2(1);
74645 l_accrual_line_num            NUMBER;
74646 l_tmp_amt                     NUMBER;
74647 l_acc_rev_natural_side_code   VARCHAR2(1);
74648 
74649 l_num_entries                 NUMBER;
74650 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
74654 l_recog_line_1                NUMBER;
74651 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
74652 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
74653 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
74655 l_recog_line_2                NUMBER;
74656 
74657 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
74658 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
74659 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
74660 
74661 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
74662 
74663 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
74664 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
74665 
74666 ---------------------------------------------------------------------------------------------------------------
74667 
74668 
74669 --
74670 -- bulk performance
74671 --
74672 l_balance_type_code           VARCHAR2(1);
74673 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
74674 l_log_module                  VARCHAR2(240);
74675 
74676 --
74677 -- Upgrade strategy
74678 --
74679 l_actual_upg_option           VARCHAR2(1);
74680 l_enc_upg_option           VARCHAR2(1);
74681 
74682 --
74683 BEGIN
74684 --
74685 IF g_log_enabled THEN
74686       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_258';
74687 END IF;
74688 --
74689 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
74690 
74691       trace
74692          (p_msg      => 'BEGIN of AcctLineType_258'
74693          ,p_level    => C_LEVEL_PROCEDURE
74694          ,p_module   => l_log_module);
74695 
74696 END IF;
74697 --
74698 l_component_type             := 'AMB_JLT';
74699 l_component_code             := 'FA_COST_OF_REMOVAL_LOSS';
74700 l_component_type_code        := 'S';
74701 l_component_appl_id          :=  140;
74702 l_amb_context_code           := 'DEFAULT';
74703 l_entity_code                := 'TRANSACTIONS';
74704 l_event_class_code           := 'RETIREMENTS';
74705 l_event_type_code            := 'RETIREMENTS';
74706 l_line_definition_owner_code := 'S';
74707 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
74708 --
74709 l_balance_type_code          := 'A';
74710 l_segment                     := NULL;
74711 l_ccid                        := NULL;
74712 l_adr_transaction_coa_id      := NULL;
74713 l_adr_accounting_coa_id       := NULL;
74714 l_adr_flexfield_segment_code  := NULL;
74715 l_adr_flex_value_set_id       := NULL;
74716 l_adr_value_type_code         := NULL;
74717 l_adr_value_combination_id    := NULL;
74718 l_adr_value_segment_code      := NULL;
74719 
74720 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
74721 l_bflow_class_code           := '';    -- 4219869 Business Flow
74722 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
74723 l_budgetary_control_flag     := 'N';
74724 
74725 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
74726 l_bflow_applied_to_amt       := NULL; -- 5132302
74727 l_entered_amt_idx            := NULL;          -- 4262811
74728 l_accted_amt_idx             := NULL;          -- 4262811
74729 l_acc_rev_flag               := NULL;          -- 4262811
74730 l_accrual_line_num           := NULL;          -- 4262811
74731 l_tmp_amt                    := NULL;          -- 4262811
74732 --
74733  
74734 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
74735     l_balance_type_code <> 'B' THEN
74736 IF NVL(p_source_35,'
74737 ') =  'REMOVALCOST' AND 
74738 p_source_41 <  0
74739  THEN 
74740 
74741    --
74742    XLA_AE_LINES_PKG.SetNewLine;
74743 
74744    p_balance_type_code          := l_balance_type_code;
74745    -- set the flag so later we will know whether the gain loss line needs to be created
74746    
74747    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
74748      p_actual_flag :='A';
74749    END IF;
74750 
74751    --
74752    -- bulk performance
74753    --
74754    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
74755                                       p_header_num   => 0); -- 4262811
74756    --
74757    -- set accounting line options
74758    --
74759    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
74760            p_natural_side_code          => 'D'
74761          , p_gain_or_loss_flag          => 'N'
74762          , p_gl_transfer_mode_code      => 'S'
74763          , p_acct_entry_type_code       => 'A'
74764          , p_switch_side_flag           => 'Y'
74765          , p_merge_duplicate_code       => 'N'
74766          );
74767    --
74768    l_acc_rev_natural_side_code := 'C';  -- 4262811
74769    -- 
74770    --
74771    -- set accounting line type info
74772    --
74773    xla_ae_lines_pkg.SetAcctLineType
74774       (p_component_type             => l_component_type
74775       ,p_event_type_code            => l_event_type_code
74776       ,p_line_definition_owner_code => l_line_definition_owner_code
74777       ,p_line_definition_code       => l_line_definition_code
74778       ,p_accounting_line_code       => l_component_code
74779       ,p_accounting_line_type_code  => l_component_type_code
74780       ,p_accounting_line_appl_id    => l_component_appl_id
74781       ,p_amb_context_code           => l_amb_context_code
74782       ,p_entity_code                => l_entity_code
74783       ,p_event_class_code           => l_event_class_code);
74784    --
74785    -- set accounting class
74786    --
74787    xla_ae_lines_pkg.SetAcctClass(
74788            p_accounting_class_code  => 'ASSET'
74789          , p_ae_header_id           => l_ae_header_id
74790          );
74791 
74792    --
74796                       'ASSET';
74793    -- set rounding class
74794    --
74795    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
74797 
74798    --
74799    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
74800    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
74801    --
74802    -- bulk performance
74803    --
74804    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
74805 
74806    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
74807       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
74808 
74809    -- 4955764
74810    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
74811       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
74812 
74813    -- 4458381 Public Sector Enh
74814    
74815    --
74816    -- set accounting attributes for the line type
74817    --
74818    l_entered_amt_idx := 4;
74819    l_accted_amt_idx  := 6;
74820    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
74821    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
74822    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
74823    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
74824    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
74825    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
74826    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
74827    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
74828    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
74829    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
74830    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
74831    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
74832    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
74833 
74834    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
74835    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
74836 
74837    ---------------------------------------------------------------------------------------------------------------
74838    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
74839    ---------------------------------------------------------------------------------------------------------------
74840    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
74841 
74842    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
74843    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
74844 
74845    IF xla_accounting_cache_pkg.GetValueChar
74846          (p_source_code         => 'LEDGER_CATEGORY_CODE'
74847          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
74848    AND l_bflow_method_code = 'PRIOR_ENTRY'
74849 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
74850    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
74851          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
74852        )
74853    THEN
74854          xla_ae_lines_pkg.BflowUpgEntry
74855            (p_business_method_code    => l_bflow_method_code
74856            ,p_business_class_code     => l_bflow_class_code
74857            ,p_balance_type            => l_balance_type_code);
74858    ELSE
74859       NULL;
74860 -- No business flow processing for business flow method of NONE.
74861    END IF;
74862 
74863    --
74864    -- call analytical criteria
74865    --
74866    
74867    --
74868    -- call description
74869    --
74870    
74871 xla_ae_lines_pkg.SetLineDescription(
74872    p_ae_header_id => l_ae_header_id
74873   ,p_description  => Description_78 (
74874      p_application_id         => p_application_id
74875    , p_ae_header_id           => l_ae_header_id 
74876 , p_source_1 => p_source_1
74877    )
74878 );
74879 
74880 
74881    --
74882    -- call ADRs
74883    -- Bug 4922099
74884    --
74885    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
74886         (NVL(l_actual_upg_option, 'N') = 'O') OR
74887         (NVL(l_enc_upg_option, 'N') = 'O')
74888       )
74889    THEN
74890    NULL;
74891    --
74892    --
74893    
74894   l_ccid := AcctDerRule_173(
74895            p_application_id           => p_application_id
74896          , p_ae_header_id             => l_ae_header_id 
74897 , p_source_3 => p_source_3
74898 , p_source_30 => p_source_30
74899          , x_transaction_coa_id       => l_adr_transaction_coa_id
74900          , x_accounting_coa_id        => l_adr_accounting_coa_id
74901          , x_value_type_code          => l_adr_value_type_code
74902          , p_side                     => 'NA'
74903    );
74904 
74905    xla_ae_lines_pkg.set_ccid(
74906     p_code_combination_id          => l_ccid
74907   , p_value_type_code              => l_adr_value_type_code
74908   , p_transaction_coa_id           => l_adr_transaction_coa_id
74909   , p_accounting_coa_id            => l_adr_accounting_coa_id
74910   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
74911   , p_adr_type_code                => 'S'
74912   , p_component_type               => l_component_type
74913   , p_component_code               => l_component_code
74914   , p_component_type_code          => l_component_type_code
74915   , p_component_appl_id            => l_component_appl_id
74916   , p_amb_context_code             => l_amb_context_code
74917   , p_side                         => 'NA'
74918   );
74919 
74920 
74924 , p_source_3 => p_source_3
74921    l_segment := AcctDerRule_153(
74922            p_application_id           => p_application_id
74923          , p_ae_header_id             => l_ae_header_id 
74925 , p_source_14 => p_source_14
74926          , x_transaction_coa_id       => l_adr_transaction_coa_id
74927          , x_accounting_coa_id        => l_adr_accounting_coa_id
74928          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
74929          , x_flex_value_set_id        => l_adr_flex_value_set_id
74930          , x_value_type_code          => l_adr_value_type_code
74931          , x_value_combination_id     => l_adr_value_combination_id
74932          , x_value_segment_code       => l_adr_value_segment_code
74933          , p_side                     => 'NA'
74934          , p_override_seg_flag        => 'Y'
74935    );
74936 
74937    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
74938 
74939       xla_ae_lines_pkg.set_segment(
74940           p_to_segment_code         => 'GL_ACCOUNT'
74941         , p_segment_value           => l_segment
74942         , p_from_segment_code       => l_adr_value_segment_code
74943         , p_from_combination_id     => l_adr_value_combination_id
74944         , p_value_type_code         => l_adr_value_type_code
74945         , p_transaction_coa_id      => l_adr_transaction_coa_id
74946         , p_accounting_coa_id       => l_adr_accounting_coa_id
74947         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
74948         , p_flex_value_set_id       => l_adr_flex_value_set_id
74949         , p_adr_code                => 'FA_COST_OF_REM_LOSS_SEGMENT'
74950         , p_adr_type_code           => 'S'
74951         , p_component_type          => l_component_type
74952         , p_component_code          => l_component_code
74953         , p_component_type_code     => l_component_type_code
74954         , p_component_appl_id       => l_component_appl_id
74955         , p_amb_context_code        => l_amb_context_code
74956         , p_entity_code             => 'TRANSACTIONS'
74957         , p_event_class_code        => 'RETIREMENTS'
74958         , p_side                    => 'NA'
74959         );
74960 
74961   END IF;
74962 
74963    l_segment := AcctDerRule_168(
74964            p_application_id           => p_application_id
74965          , p_ae_header_id             => l_ae_header_id 
74966 , p_source_3 => p_source_3
74967 , p_source_29 => p_source_29
74968          , x_transaction_coa_id       => l_adr_transaction_coa_id
74969          , x_accounting_coa_id        => l_adr_accounting_coa_id
74970          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
74971          , x_flex_value_set_id        => l_adr_flex_value_set_id
74972          , x_value_type_code          => l_adr_value_type_code
74973          , x_value_combination_id     => l_adr_value_combination_id
74974          , x_value_segment_code       => l_adr_value_segment_code
74975          , p_side                     => 'NA'
74976          , p_override_seg_flag        => 'Y'
74977    );
74978 
74979    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
74980 
74981       xla_ae_lines_pkg.set_segment(
74982           p_to_segment_code         => 'GL_BALANCING'
74983         , p_segment_value           => l_segment
74984         , p_from_segment_code       => l_adr_value_segment_code
74985         , p_from_combination_id     => l_adr_value_combination_id
74986         , p_value_type_code         => l_adr_value_type_code
74987         , p_transaction_coa_id      => l_adr_transaction_coa_id
74988         , p_accounting_coa_id       => l_adr_accounting_coa_id
74989         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
74990         , p_flex_value_set_id       => l_adr_flex_value_set_id
74991         , p_adr_code                => 'FA_EXPENSE_ACCT'
74992         , p_adr_type_code           => 'S'
74993         , p_component_type          => l_component_type
74994         , p_component_code          => l_component_code
74995         , p_component_type_code     => l_component_type_code
74996         , p_component_appl_id       => l_component_appl_id
74997         , p_amb_context_code        => l_amb_context_code
74998         , p_entity_code             => 'TRANSACTIONS'
74999         , p_event_class_code        => 'RETIREMENTS'
75000         , p_side                    => 'NA'
75001         );
75002 
75003   END IF;
75004 
75005    --
75006    --
75007    END IF;
75008    --
75009    -- Bug 4922099
75010    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
75011           (NVL(l_enc_upg_option, 'N') = 'O')
75012         ) AND
75013         (l_bflow_method_code = 'PRIOR_ENTRY')
75014       )
75015    THEN
75016       IF
75017       --
75018       1 = 2
75019       --
75020       THEN
75021       xla_accounting_err_pkg.build_message
75022                                     (p_appli_s_name            => 'XLA'
75023                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
75024                                     ,p_token_1                 => 'LINE_NUMBER'
75025                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
75026                                     ,p_token_2                 => 'LINE_TYPE_NAME'
75027                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
75028                                                                              l_component_type
75029                                                                             ,l_component_code
75030                                                                             ,l_component_type_code
75031                                                                             ,l_component_appl_id
75032                                                                             ,l_amb_context_code
75033                                                                             ,l_entity_code
75037                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
75034                                                                             ,l_event_class_code
75035                                                                            )
75036                                     ,p_token_3                 => 'OWNER'
75038                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
75039                                                                           ,p_lookup_code    => l_component_type_code
75040                                                                          )
75041                                     ,p_token_4                 => 'PRODUCT_NAME'
75042                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
75043                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
75044                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
75045                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
75046                                     ,p_ae_header_id            =>  NULL
75047                                        );
75048 
75049         IF (C_LEVEL_ERROR>= g_log_level) THEN
75050                  trace
75051                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
75052                       ,p_level    => C_LEVEL_ERROR
75053                       ,p_module   => l_log_module);
75054         END IF;
75055       END IF;
75056    END IF;
75057    --
75058    --
75059    ------------------------------------------------------------------------------------------------
75060    -- 4219869 Business Flow
75061    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
75062    -- Prior Entry.  Currently, the following code is always generated.
75063    ------------------------------------------------------------------------------------------------
75064    XLA_AE_LINES_PKG.ValidateCurrentLine;
75065 
75066    ------------------------------------------------------------------------------------
75067    -- 4219869 Business Flow
75068    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
75069    ------------------------------------------------------------------------------------
75070    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
75071 
75072    ----------------------------------------------------------------------------------
75073    -- 4219869 Business Flow
75074    -- Update journal entry status -- Need to generate this within IF <condition>
75075    ----------------------------------------------------------------------------------
75076    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
75077          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
75078          ,p_balance_type_code => l_balance_type_code
75079          );
75080 
75081    -------------------------------------------------------------------------------------------
75082    -- 4262811 - Generate the Accrual Reversal lines
75083    -------------------------------------------------------------------------------------------
75084    BEGIN
75085       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
75086                               (g_array_event(p_event_id).array_value_num('header_index'));
75087       IF l_acc_rev_flag IS NULL THEN
75088          l_acc_rev_flag := 'N';
75089       END IF;
75090    EXCEPTION
75091       WHEN OTHERS THEN
75092          l_acc_rev_flag := 'N';
75093    END;
75094    --
75095    IF (l_acc_rev_flag = 'Y') THEN
75096 
75097        -- 4645092  ------------------------------------------------------------------------------
75098        -- To allow MPA report to determine if it should generate report process
75099        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
75100        ------------------------------------------------------------------------------------------
75101 
75102        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
75103        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
75104    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
75105    -- call ADRs
75106    -- Bug 4922099
75107    --
75108    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
75109         (NVL(l_actual_upg_option, 'N') = 'O') OR
75110         (NVL(l_enc_upg_option, 'N') = 'O')
75111       )
75112    THEN
75113    NULL;
75114    --
75115    --
75116    
75117   l_ccid := AcctDerRule_173(
75118            p_application_id           => p_application_id
75119          , p_ae_header_id             => l_ae_header_id 
75120 , p_source_3 => p_source_3
75121 , p_source_30 => p_source_30
75122          , x_transaction_coa_id       => l_adr_transaction_coa_id
75123          , x_accounting_coa_id        => l_adr_accounting_coa_id
75124          , x_value_type_code          => l_adr_value_type_code
75125          , p_side                     => 'NA'
75126    );
75127 
75128    xla_ae_lines_pkg.set_ccid(
75129     p_code_combination_id          => l_ccid
75130   , p_value_type_code              => l_adr_value_type_code
75131   , p_transaction_coa_id           => l_adr_transaction_coa_id
75132   , p_accounting_coa_id            => l_adr_accounting_coa_id
75133   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
75134   , p_adr_type_code                => 'S'
75135   , p_component_type               => l_component_type
75136   , p_component_code               => l_component_code
75137   , p_component_type_code          => l_component_type_code
75138   , p_component_appl_id            => l_component_appl_id
75139   , p_amb_context_code             => l_amb_context_code
75140   , p_side                         => 'NA'
75141   );
75142 
75143 
75144    l_segment := AcctDerRule_153(
75148 , p_source_14 => p_source_14
75145            p_application_id           => p_application_id
75146          , p_ae_header_id             => l_ae_header_id 
75147 , p_source_3 => p_source_3
75149          , x_transaction_coa_id       => l_adr_transaction_coa_id
75150          , x_accounting_coa_id        => l_adr_accounting_coa_id
75151          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
75152          , x_flex_value_set_id        => l_adr_flex_value_set_id
75153          , x_value_type_code          => l_adr_value_type_code
75154          , x_value_combination_id     => l_adr_value_combination_id
75155          , x_value_segment_code       => l_adr_value_segment_code
75156          , p_side                     => 'NA'
75157          , p_override_seg_flag        => 'Y'
75158    );
75159 
75160    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
75161 
75162       xla_ae_lines_pkg.set_segment(
75163           p_to_segment_code         => 'GL_ACCOUNT'
75164         , p_segment_value           => l_segment
75165         , p_from_segment_code       => l_adr_value_segment_code
75166         , p_from_combination_id     => l_adr_value_combination_id
75167         , p_value_type_code         => l_adr_value_type_code
75168         , p_transaction_coa_id      => l_adr_transaction_coa_id
75169         , p_accounting_coa_id       => l_adr_accounting_coa_id
75170         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
75171         , p_flex_value_set_id       => l_adr_flex_value_set_id
75172         , p_adr_code                => 'FA_COST_OF_REM_LOSS_SEGMENT'
75173         , p_adr_type_code           => 'S'
75174         , p_component_type          => l_component_type
75175         , p_component_code          => l_component_code
75176         , p_component_type_code     => l_component_type_code
75177         , p_component_appl_id       => l_component_appl_id
75178         , p_amb_context_code        => l_amb_context_code
75179         , p_entity_code             => 'TRANSACTIONS'
75180         , p_event_class_code        => 'RETIREMENTS'
75181         , p_side                    => 'NA'
75182         );
75183 
75184   END IF;
75185 
75186    l_segment := AcctDerRule_168(
75187            p_application_id           => p_application_id
75188          , p_ae_header_id             => l_ae_header_id 
75189 , p_source_3 => p_source_3
75190 , p_source_29 => p_source_29
75191          , x_transaction_coa_id       => l_adr_transaction_coa_id
75192          , x_accounting_coa_id        => l_adr_accounting_coa_id
75193          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
75194          , x_flex_value_set_id        => l_adr_flex_value_set_id
75195          , x_value_type_code          => l_adr_value_type_code
75196          , x_value_combination_id     => l_adr_value_combination_id
75197          , x_value_segment_code       => l_adr_value_segment_code
75198          , p_side                     => 'NA'
75199          , p_override_seg_flag        => 'Y'
75200    );
75201 
75202    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
75203 
75204       xla_ae_lines_pkg.set_segment(
75205           p_to_segment_code         => 'GL_BALANCING'
75206         , p_segment_value           => l_segment
75207         , p_from_segment_code       => l_adr_value_segment_code
75208         , p_from_combination_id     => l_adr_value_combination_id
75209         , p_value_type_code         => l_adr_value_type_code
75210         , p_transaction_coa_id      => l_adr_transaction_coa_id
75211         , p_accounting_coa_id       => l_adr_accounting_coa_id
75212         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
75213         , p_flex_value_set_id       => l_adr_flex_value_set_id
75214         , p_adr_code                => 'FA_EXPENSE_ACCT'
75215         , p_adr_type_code           => 'S'
75216         , p_component_type          => l_component_type
75217         , p_component_code          => l_component_code
75218         , p_component_type_code     => l_component_type_code
75219         , p_component_appl_id       => l_component_appl_id
75220         , p_amb_context_code        => l_amb_context_code
75221         , p_entity_code             => 'TRANSACTIONS'
75222         , p_event_class_code        => 'RETIREMENTS'
75223         , p_side                    => 'NA'
75224         );
75225 
75226   END IF;
75227 
75228    --
75229    --
75230    END IF;
75231 
75232        --
75233        -- Update the line information that should be overwritten
75234        --
75235        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
75236                                          p_header_num   => 1);
75237        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
75238 
75239        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
75240 
75241        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
75242           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
75243        END IF;
75244 
75245       --
75246       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
75247       --
75248       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
75249           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
75250       ELSE
75251           ---------------------------------------------------------------------------------------------------
75252           -- 4262811a Switch Sign
75253           ---------------------------------------------------------------------------------------------------
75254           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
75255           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
75259           -- 5132302
75256                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
75257           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
75258                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
75260           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
75261                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
75262 
75263       END IF;
75264 
75265       -- 4955764
75266       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
75267       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
75268 
75269 
75270       XLA_AE_LINES_PKG.ValidateCurrentLine;
75271       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
75272 
75273       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
75274                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
75275                ,p_balance_type_code => l_balance_type_code);
75276 
75277    END IF;
75278 
75279    -----------------------------------------------------------------------------------------
75280    -- 4262811 Multiperiod Accounting
75281    -----------------------------------------------------------------------------------------
75282      -- No MPA option is assigned.
75283 
75284 
75285 END IF;
75286 END IF;
75287 --
75288 
75289 --
75290 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
75291    trace
75292       (p_msg      => 'END of AcctLineType_258'
75293       ,p_level    => C_LEVEL_PROCEDURE
75294       ,p_module   => l_log_module);
75295 END IF;
75296 --
75297 EXCEPTION
75298   WHEN xla_exceptions_pkg.application_exception THEN
75299       RAISE;
75300   WHEN OTHERS THEN
75301        xla_exceptions_pkg.raise_message
75302            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_258');
75303 END AcctLineType_258;
75304 --
75305 
75306 ---------------------------------------
75307 --
75308 -- PRIVATE FUNCTION
75309 --         AcctLineType_259
75310 --
75311 ---------------------------------------
75312 PROCEDURE AcctLineType_259 (
75313   p_application_id        IN NUMBER
75314  ,p_event_id              IN NUMBER
75315  ,p_calculate_acctd_flag  IN VARCHAR2
75316  ,p_calculate_g_l_flag    IN VARCHAR2
75317  ,p_actual_flag           IN OUT VARCHAR2
75318  ,p_balance_type_code     OUT VARCHAR2
75319  ,p_gain_or_loss_ref      OUT VARCHAR2
75320  
75321 --Period Close Date
75322  , p_source_1            IN DATE
75323 --Generated Code Combination Identifier
75324  , p_source_3            IN NUMBER
75325 --Deferred Depreciation Expense Account
75326  , p_source_15            IN VARCHAR2
75327 --Expense Account Code Combination Identifier
75328  , p_source_29            IN NUMBER
75329 --Default Code Combination Identifier
75330  , p_source_30            IN NUMBER
75331 --Distribution Type Code
75332  , p_source_38            IN VARCHAR2
75333 --Entered Amount
75334  , p_source_39            IN NUMBER
75335 --Currency Code
75336  , p_source_40            IN VARCHAR2
75337 --Asset Identifier
75338  , p_source_43            IN NUMBER
75339 --Period Counter
75340  , p_source_44            IN NUMBER
75341 --Distribution Identifier
75342  , p_source_45            IN NUMBER
75343 --Book Type Code
75344  , p_source_46            IN VARCHAR2
75345 --Tax Book Type Code
75346  , p_source_47            IN VARCHAR2
75347 )
75348 IS
75349 
75350 l_component_type              VARCHAR2(80);
75351 l_component_code              VARCHAR2(30);
75352 l_component_type_code         VARCHAR2(1);
75353 l_component_appl_id           INTEGER;
75354 l_amb_context_code            VARCHAR2(30);
75355 l_entity_code                 VARCHAR2(30);
75356 l_event_class_code            VARCHAR2(30);
75357 l_ae_header_id                NUMBER;
75358 l_event_type_code             VARCHAR2(30);
75359 l_line_definition_code        VARCHAR2(30);
75360 l_line_definition_owner_code  VARCHAR2(1);
75361 --
75362 -- adr variables
75363 l_segment                     VARCHAR2(30);
75364 l_ccid                        NUMBER;
75365 l_adr_transaction_coa_id      NUMBER;
75366 l_adr_accounting_coa_id       NUMBER;
75367 l_adr_flexfield_segment_code  VARCHAR2(30);
75368 l_adr_flex_value_set_id       NUMBER;
75369 l_adr_value_type_code         VARCHAR2(30);
75370 l_adr_value_combination_id    NUMBER;
75371 l_adr_value_segment_code      VARCHAR2(30);
75372 
75373 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
75374 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
75375 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
75376 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
75377 
75378 -- 4262811 Variables ------------------------------------------------------------------------------------------
75379 l_entered_amt_idx             NUMBER;
75380 l_accted_amt_idx              NUMBER;
75381 l_acc_rev_flag                VARCHAR2(1);
75382 l_accrual_line_num            NUMBER;
75383 l_tmp_amt                     NUMBER;
75384 l_acc_rev_natural_side_code   VARCHAR2(1);
75385 
75386 l_num_entries                 NUMBER;
75387 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
75388 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
75389 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
75390 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
75391 l_recog_line_1                NUMBER;
75392 l_recog_line_2                NUMBER;
75393 
75394 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
75398 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
75395 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
75396 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
75397 
75399 
75400 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
75401 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
75402 
75403 ---------------------------------------------------------------------------------------------------------------
75404 
75405 
75406 --
75407 -- bulk performance
75408 --
75409 l_balance_type_code           VARCHAR2(1);
75410 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
75411 l_log_module                  VARCHAR2(240);
75412 
75413 --
75414 -- Upgrade strategy
75415 --
75416 l_actual_upg_option           VARCHAR2(1);
75417 l_enc_upg_option           VARCHAR2(1);
75418 
75419 --
75420 BEGIN
75421 --
75422 IF g_log_enabled THEN
75423       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_259';
75424 END IF;
75425 --
75426 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
75427 
75428       trace
75429          (p_msg      => 'BEGIN of AcctLineType_259'
75430          ,p_level    => C_LEVEL_PROCEDURE
75431          ,p_module   => l_log_module);
75432 
75433 END IF;
75434 --
75435 l_component_type             := 'AMB_JLT';
75436 l_component_code             := 'FA_DEF_DEPRN_EXP';
75437 l_component_type_code        := 'S';
75438 l_component_appl_id          :=  140;
75439 l_amb_context_code           := 'DEFAULT';
75440 l_entity_code                := 'DEFERRED_DEPRECIATION';
75441 l_event_class_code           := 'DEFERRED_DEPRECIATION';
75442 l_event_type_code            := 'DEFERRED_DEPRECIATION_ALL';
75443 l_line_definition_owner_code := 'S';
75444 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEFER14';
75445 --
75446 l_balance_type_code          := 'A';
75447 l_segment                     := NULL;
75448 l_ccid                        := NULL;
75449 l_adr_transaction_coa_id      := NULL;
75450 l_adr_accounting_coa_id       := NULL;
75451 l_adr_flexfield_segment_code  := NULL;
75452 l_adr_flex_value_set_id       := NULL;
75453 l_adr_value_type_code         := NULL;
75454 l_adr_value_combination_id    := NULL;
75455 l_adr_value_segment_code      := NULL;
75456 
75457 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
75458 l_bflow_class_code           := '';    -- 4219869 Business Flow
75459 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
75460 l_budgetary_control_flag     := 'N';
75461 
75462 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
75463 l_bflow_applied_to_amt       := NULL; -- 5132302
75464 l_entered_amt_idx            := NULL;          -- 4262811
75465 l_accted_amt_idx             := NULL;          -- 4262811
75466 l_acc_rev_flag               := NULL;          -- 4262811
75467 l_accrual_line_num           := NULL;          -- 4262811
75468 l_tmp_amt                    := NULL;          -- 4262811
75469 --
75470  
75471 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
75472     l_balance_type_code <> 'B' THEN
75473 
75474    --
75475    XLA_AE_LINES_PKG.SetNewLine;
75476 
75477    p_balance_type_code          := l_balance_type_code;
75478    -- set the flag so later we will know whether the gain loss line needs to be created
75479    
75480    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
75481      p_actual_flag :='A';
75482    END IF;
75483 
75484    --
75485    -- bulk performance
75486    --
75487    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
75488                                       p_header_num   => 0); -- 4262811
75489    --
75490    -- set accounting line options
75491    --
75492    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
75493            p_natural_side_code          => 'D'
75494          , p_gain_or_loss_flag          => 'N'
75495          , p_gl_transfer_mode_code      => 'S'
75496          , p_acct_entry_type_code       => 'A'
75497          , p_switch_side_flag           => 'Y'
75498          , p_merge_duplicate_code       => 'N'
75499          );
75500    --
75501    l_acc_rev_natural_side_code := 'C';  -- 4262811
75502    -- 
75503    --
75504    -- set accounting line type info
75505    --
75506    xla_ae_lines_pkg.SetAcctLineType
75507       (p_component_type             => l_component_type
75508       ,p_event_type_code            => l_event_type_code
75509       ,p_line_definition_owner_code => l_line_definition_owner_code
75510       ,p_line_definition_code       => l_line_definition_code
75511       ,p_accounting_line_code       => l_component_code
75512       ,p_accounting_line_type_code  => l_component_type_code
75513       ,p_accounting_line_appl_id    => l_component_appl_id
75514       ,p_amb_context_code           => l_amb_context_code
75515       ,p_entity_code                => l_entity_code
75516       ,p_event_class_code           => l_event_class_code);
75517    --
75518    -- set accounting class
75519    --
75520    xla_ae_lines_pkg.SetAcctClass(
75521            p_accounting_class_code  => 'EXPENSE'
75522          , p_ae_header_id           => l_ae_header_id
75523          );
75524 
75525    --
75526    -- set rounding class
75527    --
75528    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
75529                       'EXPENSE';
75530 
75531    --
75532    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
75533    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
75534    --
75535    -- bulk performance
75539    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
75536    --
75537    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
75538 
75540       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
75541 
75542    -- 4955764
75543    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
75544       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
75545 
75546    -- 4458381 Public Sector Enh
75547    
75548    --
75549    -- set accounting attributes for the line type
75550    --
75551    l_entered_amt_idx := 7;
75552    l_accted_amt_idx  := 9;
75553    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
75554    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
75555    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
75556    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
75557    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
75558    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
75559    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_45);
75560    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
75561    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
75562    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
75563    l_rec_acct_attrs.array_char_value(5)  := p_source_47;
75564    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
75565    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
75566    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
75567    l_rec_acct_attrs.array_num_value(7)  := p_source_39;
75568    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
75569    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
75570    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
75571    l_rec_acct_attrs.array_num_value(9)  := p_source_39;
75572 
75573    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
75574    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
75575 
75576    ---------------------------------------------------------------------------------------------------------------
75577    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
75578    ---------------------------------------------------------------------------------------------------------------
75579    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
75580 
75581    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
75582    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
75583 
75584    IF xla_accounting_cache_pkg.GetValueChar
75585          (p_source_code         => 'LEDGER_CATEGORY_CODE'
75586          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
75587    AND l_bflow_method_code = 'PRIOR_ENTRY'
75588 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
75589    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
75590          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
75591        )
75592    THEN
75593          xla_ae_lines_pkg.BflowUpgEntry
75594            (p_business_method_code    => l_bflow_method_code
75595            ,p_business_class_code     => l_bflow_class_code
75596            ,p_balance_type            => l_balance_type_code);
75597    ELSE
75598       NULL;
75599 -- No business flow processing for business flow method of NONE.
75600    END IF;
75601 
75602    --
75603    -- call analytical criteria
75604    --
75605    
75606    --
75607    -- call description
75608    --
75609    
75610 xla_ae_lines_pkg.SetLineDescription(
75611    p_ae_header_id => l_ae_header_id
75612   ,p_description  => Description_55 (
75613      p_application_id         => p_application_id
75614    , p_ae_header_id           => l_ae_header_id 
75615 , p_source_1 => p_source_1
75616    )
75617 );
75618 
75619 
75620    --
75621    -- call ADRs
75622    -- Bug 4922099
75623    --
75624    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
75625         (NVL(l_actual_upg_option, 'N') = 'O') OR
75626         (NVL(l_enc_upg_option, 'N') = 'O')
75627       )
75628    THEN
75629    NULL;
75630    --
75631    --
75632    
75633   l_ccid := AcctDerRule_173(
75634            p_application_id           => p_application_id
75635          , p_ae_header_id             => l_ae_header_id 
75636 , p_source_3 => p_source_3
75637 , p_source_30 => p_source_30
75638          , x_transaction_coa_id       => l_adr_transaction_coa_id
75639          , x_accounting_coa_id        => l_adr_accounting_coa_id
75640          , x_value_type_code          => l_adr_value_type_code
75641          , p_side                     => 'NA'
75642    );
75643 
75644    xla_ae_lines_pkg.set_ccid(
75645     p_code_combination_id          => l_ccid
75646   , p_value_type_code              => l_adr_value_type_code
75647   , p_transaction_coa_id           => l_adr_transaction_coa_id
75648   , p_accounting_coa_id            => l_adr_accounting_coa_id
75649   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
75650   , p_adr_type_code                => 'S'
75651   , p_component_type               => l_component_type
75652   , p_component_code               => l_component_code
75653   , p_component_type_code          => l_component_type_code
75654   , p_component_appl_id            => l_component_appl_id
75655   , p_amb_context_code             => l_amb_context_code
75656   , p_side                         => 'NA'
75657   );
75658 
75659 
75660    l_segment := AcctDerRule_154(
75664 , p_source_15 => p_source_15
75661            p_application_id           => p_application_id
75662          , p_ae_header_id             => l_ae_header_id 
75663 , p_source_3 => p_source_3
75665          , x_transaction_coa_id       => l_adr_transaction_coa_id
75666          , x_accounting_coa_id        => l_adr_accounting_coa_id
75667          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
75668          , x_flex_value_set_id        => l_adr_flex_value_set_id
75669          , x_value_type_code          => l_adr_value_type_code
75670          , x_value_combination_id     => l_adr_value_combination_id
75671          , x_value_segment_code       => l_adr_value_segment_code
75672          , p_side                     => 'NA'
75673          , p_override_seg_flag        => 'Y'
75674    );
75675 
75676    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
75677 
75678       xla_ae_lines_pkg.set_segment(
75679           p_to_segment_code         => 'GL_ACCOUNT'
75680         , p_segment_value           => l_segment
75681         , p_from_segment_code       => l_adr_value_segment_code
75682         , p_from_combination_id     => l_adr_value_combination_id
75683         , p_value_type_code         => l_adr_value_type_code
75684         , p_transaction_coa_id      => l_adr_transaction_coa_id
75685         , p_accounting_coa_id       => l_adr_accounting_coa_id
75686         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
75687         , p_flex_value_set_id       => l_adr_flex_value_set_id
75688         , p_adr_code                => 'FA_DEF_DEPRN_EXPENSE_SEGMENT'
75689         , p_adr_type_code           => 'S'
75690         , p_component_type          => l_component_type
75691         , p_component_code          => l_component_code
75692         , p_component_type_code     => l_component_type_code
75693         , p_component_appl_id       => l_component_appl_id
75694         , p_amb_context_code        => l_amb_context_code
75695         , p_entity_code             => 'DEFERRED_DEPRECIATION'
75696         , p_event_class_code        => 'DEFERRED_DEPRECIATION'
75697         , p_side                    => 'NA'
75698         );
75699 
75700   END IF;
75701 
75702    l_segment := AcctDerRule_168(
75703            p_application_id           => p_application_id
75704          , p_ae_header_id             => l_ae_header_id 
75705 , p_source_3 => p_source_3
75706 , p_source_29 => p_source_29
75707          , x_transaction_coa_id       => l_adr_transaction_coa_id
75708          , x_accounting_coa_id        => l_adr_accounting_coa_id
75709          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
75710          , x_flex_value_set_id        => l_adr_flex_value_set_id
75711          , x_value_type_code          => l_adr_value_type_code
75712          , x_value_combination_id     => l_adr_value_combination_id
75713          , x_value_segment_code       => l_adr_value_segment_code
75714          , p_side                     => 'NA'
75715          , p_override_seg_flag        => 'Y'
75716    );
75717 
75718    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
75719 
75720       xla_ae_lines_pkg.set_segment(
75721           p_to_segment_code         => 'GL_BALANCING'
75722         , p_segment_value           => l_segment
75723         , p_from_segment_code       => l_adr_value_segment_code
75724         , p_from_combination_id     => l_adr_value_combination_id
75725         , p_value_type_code         => l_adr_value_type_code
75726         , p_transaction_coa_id      => l_adr_transaction_coa_id
75727         , p_accounting_coa_id       => l_adr_accounting_coa_id
75728         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
75729         , p_flex_value_set_id       => l_adr_flex_value_set_id
75730         , p_adr_code                => 'FA_EXPENSE_ACCT'
75731         , p_adr_type_code           => 'S'
75732         , p_component_type          => l_component_type
75733         , p_component_code          => l_component_code
75734         , p_component_type_code     => l_component_type_code
75735         , p_component_appl_id       => l_component_appl_id
75736         , p_amb_context_code        => l_amb_context_code
75737         , p_entity_code             => 'DEFERRED_DEPRECIATION'
75738         , p_event_class_code        => 'DEFERRED_DEPRECIATION'
75739         , p_side                    => 'NA'
75740         );
75741 
75742   END IF;
75743 
75744    --
75745    --
75746    END IF;
75747    --
75748    -- Bug 4922099
75749    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
75750           (NVL(l_enc_upg_option, 'N') = 'O')
75751         ) AND
75752         (l_bflow_method_code = 'PRIOR_ENTRY')
75753       )
75754    THEN
75755       IF
75756       --
75757       1 = 2
75758       --
75759       THEN
75760       xla_accounting_err_pkg.build_message
75761                                     (p_appli_s_name            => 'XLA'
75762                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
75763                                     ,p_token_1                 => 'LINE_NUMBER'
75764                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
75765                                     ,p_token_2                 => 'LINE_TYPE_NAME'
75766                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
75767                                                                              l_component_type
75768                                                                             ,l_component_code
75769                                                                             ,l_component_type_code
75770                                                                             ,l_component_appl_id
75771                                                                             ,l_amb_context_code
75772                                                                             ,l_entity_code
75776                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
75773                                                                             ,l_event_class_code
75774                                                                            )
75775                                     ,p_token_3                 => 'OWNER'
75777                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
75778                                                                           ,p_lookup_code    => l_component_type_code
75779                                                                          )
75780                                     ,p_token_4                 => 'PRODUCT_NAME'
75781                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
75782                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
75783                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
75784                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
75785                                     ,p_ae_header_id            =>  NULL
75786                                        );
75787 
75788         IF (C_LEVEL_ERROR>= g_log_level) THEN
75789                  trace
75790                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
75791                       ,p_level    => C_LEVEL_ERROR
75792                       ,p_module   => l_log_module);
75793         END IF;
75794       END IF;
75795    END IF;
75796    --
75797    --
75798    ------------------------------------------------------------------------------------------------
75799    -- 4219869 Business Flow
75800    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
75801    -- Prior Entry.  Currently, the following code is always generated.
75802    ------------------------------------------------------------------------------------------------
75803    XLA_AE_LINES_PKG.ValidateCurrentLine;
75804 
75805    ------------------------------------------------------------------------------------
75806    -- 4219869 Business Flow
75807    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
75808    ------------------------------------------------------------------------------------
75809    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
75810 
75811    ----------------------------------------------------------------------------------
75812    -- 4219869 Business Flow
75813    -- Update journal entry status -- Need to generate this within IF <condition>
75814    ----------------------------------------------------------------------------------
75815    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
75816          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
75817          ,p_balance_type_code => l_balance_type_code
75818          );
75819 
75820    -------------------------------------------------------------------------------------------
75821    -- 4262811 - Generate the Accrual Reversal lines
75822    -------------------------------------------------------------------------------------------
75823    BEGIN
75824       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
75825                               (g_array_event(p_event_id).array_value_num('header_index'));
75826       IF l_acc_rev_flag IS NULL THEN
75827          l_acc_rev_flag := 'N';
75828       END IF;
75829    EXCEPTION
75830       WHEN OTHERS THEN
75831          l_acc_rev_flag := 'N';
75832    END;
75833    --
75834    IF (l_acc_rev_flag = 'Y') THEN
75835 
75836        -- 4645092  ------------------------------------------------------------------------------
75837        -- To allow MPA report to determine if it should generate report process
75838        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
75839        ------------------------------------------------------------------------------------------
75840 
75841        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
75842        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
75843    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
75844    -- call ADRs
75845    -- Bug 4922099
75846    --
75847    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
75848         (NVL(l_actual_upg_option, 'N') = 'O') OR
75849         (NVL(l_enc_upg_option, 'N') = 'O')
75850       )
75851    THEN
75852    NULL;
75853    --
75854    --
75855    
75856   l_ccid := AcctDerRule_173(
75857            p_application_id           => p_application_id
75858          , p_ae_header_id             => l_ae_header_id 
75859 , p_source_3 => p_source_3
75860 , p_source_30 => p_source_30
75861          , x_transaction_coa_id       => l_adr_transaction_coa_id
75862          , x_accounting_coa_id        => l_adr_accounting_coa_id
75863          , x_value_type_code          => l_adr_value_type_code
75864          , p_side                     => 'NA'
75865    );
75866 
75867    xla_ae_lines_pkg.set_ccid(
75868     p_code_combination_id          => l_ccid
75869   , p_value_type_code              => l_adr_value_type_code
75870   , p_transaction_coa_id           => l_adr_transaction_coa_id
75871   , p_accounting_coa_id            => l_adr_accounting_coa_id
75872   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
75873   , p_adr_type_code                => 'S'
75874   , p_component_type               => l_component_type
75875   , p_component_code               => l_component_code
75876   , p_component_type_code          => l_component_type_code
75877   , p_component_appl_id            => l_component_appl_id
75878   , p_amb_context_code             => l_amb_context_code
75879   , p_side                         => 'NA'
75880   );
75881 
75882 
75883    l_segment := AcctDerRule_154(
75887 , p_source_15 => p_source_15
75884            p_application_id           => p_application_id
75885          , p_ae_header_id             => l_ae_header_id 
75886 , p_source_3 => p_source_3
75888          , x_transaction_coa_id       => l_adr_transaction_coa_id
75889          , x_accounting_coa_id        => l_adr_accounting_coa_id
75890          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
75891          , x_flex_value_set_id        => l_adr_flex_value_set_id
75892          , x_value_type_code          => l_adr_value_type_code
75893          , x_value_combination_id     => l_adr_value_combination_id
75894          , x_value_segment_code       => l_adr_value_segment_code
75895          , p_side                     => 'NA'
75896          , p_override_seg_flag        => 'Y'
75897    );
75898 
75899    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
75900 
75901       xla_ae_lines_pkg.set_segment(
75902           p_to_segment_code         => 'GL_ACCOUNT'
75903         , p_segment_value           => l_segment
75904         , p_from_segment_code       => l_adr_value_segment_code
75905         , p_from_combination_id     => l_adr_value_combination_id
75906         , p_value_type_code         => l_adr_value_type_code
75907         , p_transaction_coa_id      => l_adr_transaction_coa_id
75908         , p_accounting_coa_id       => l_adr_accounting_coa_id
75909         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
75910         , p_flex_value_set_id       => l_adr_flex_value_set_id
75911         , p_adr_code                => 'FA_DEF_DEPRN_EXPENSE_SEGMENT'
75912         , p_adr_type_code           => 'S'
75913         , p_component_type          => l_component_type
75914         , p_component_code          => l_component_code
75915         , p_component_type_code     => l_component_type_code
75916         , p_component_appl_id       => l_component_appl_id
75917         , p_amb_context_code        => l_amb_context_code
75918         , p_entity_code             => 'DEFERRED_DEPRECIATION'
75919         , p_event_class_code        => 'DEFERRED_DEPRECIATION'
75920         , p_side                    => 'NA'
75921         );
75922 
75923   END IF;
75924 
75925    l_segment := AcctDerRule_168(
75926            p_application_id           => p_application_id
75927          , p_ae_header_id             => l_ae_header_id 
75928 , p_source_3 => p_source_3
75929 , p_source_29 => p_source_29
75930          , x_transaction_coa_id       => l_adr_transaction_coa_id
75931          , x_accounting_coa_id        => l_adr_accounting_coa_id
75932          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
75933          , x_flex_value_set_id        => l_adr_flex_value_set_id
75934          , x_value_type_code          => l_adr_value_type_code
75935          , x_value_combination_id     => l_adr_value_combination_id
75936          , x_value_segment_code       => l_adr_value_segment_code
75937          , p_side                     => 'NA'
75938          , p_override_seg_flag        => 'Y'
75939    );
75940 
75941    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
75942 
75943       xla_ae_lines_pkg.set_segment(
75944           p_to_segment_code         => 'GL_BALANCING'
75945         , p_segment_value           => l_segment
75946         , p_from_segment_code       => l_adr_value_segment_code
75947         , p_from_combination_id     => l_adr_value_combination_id
75948         , p_value_type_code         => l_adr_value_type_code
75949         , p_transaction_coa_id      => l_adr_transaction_coa_id
75950         , p_accounting_coa_id       => l_adr_accounting_coa_id
75951         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
75952         , p_flex_value_set_id       => l_adr_flex_value_set_id
75953         , p_adr_code                => 'FA_EXPENSE_ACCT'
75954         , p_adr_type_code           => 'S'
75955         , p_component_type          => l_component_type
75956         , p_component_code          => l_component_code
75957         , p_component_type_code     => l_component_type_code
75958         , p_component_appl_id       => l_component_appl_id
75959         , p_amb_context_code        => l_amb_context_code
75960         , p_entity_code             => 'DEFERRED_DEPRECIATION'
75961         , p_event_class_code        => 'DEFERRED_DEPRECIATION'
75962         , p_side                    => 'NA'
75963         );
75964 
75965   END IF;
75966 
75967    --
75968    --
75969    END IF;
75970 
75971        --
75972        -- Update the line information that should be overwritten
75973        --
75974        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
75975                                          p_header_num   => 1);
75976        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
75977 
75978        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
75979 
75980        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
75981           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
75982        END IF;
75983 
75984       --
75985       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
75986       --
75987       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
75988           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
75989       ELSE
75990           ---------------------------------------------------------------------------------------------------
75991           -- 4262811a Switch Sign
75992           ---------------------------------------------------------------------------------------------------
75993           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
75994           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
75998           -- 5132302
75995                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
75996           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
75997                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
75999           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
76000                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
76001 
76002       END IF;
76003 
76004       -- 4955764
76005       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
76006       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
76007 
76008 
76009       XLA_AE_LINES_PKG.ValidateCurrentLine;
76010       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
76011 
76012       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
76013                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
76014                ,p_balance_type_code => l_balance_type_code);
76015 
76016    END IF;
76017 
76018    -----------------------------------------------------------------------------------------
76019    -- 4262811 Multiperiod Accounting
76020    -----------------------------------------------------------------------------------------
76021      -- No MPA option is assigned.
76022 
76023 
76024 END IF;
76025 --
76026 
76027 --
76028 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
76029    trace
76030       (p_msg      => 'END of AcctLineType_259'
76031       ,p_level    => C_LEVEL_PROCEDURE
76032       ,p_module   => l_log_module);
76033 END IF;
76034 --
76035 EXCEPTION
76036   WHEN xla_exceptions_pkg.application_exception THEN
76037       RAISE;
76038   WHEN OTHERS THEN
76039        xla_exceptions_pkg.raise_message
76040            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_259');
76041 END AcctLineType_259;
76042 --
76043 
76044 ---------------------------------------
76045 --
76046 -- PRIVATE FUNCTION
76047 --         AcctLineType_260
76048 --
76049 ---------------------------------------
76050 PROCEDURE AcctLineType_260 (
76051   p_application_id        IN NUMBER
76052  ,p_event_id              IN NUMBER
76053  ,p_calculate_acctd_flag  IN VARCHAR2
76054  ,p_calculate_g_l_flag    IN VARCHAR2
76055  ,p_actual_flag           IN OUT VARCHAR2
76056  ,p_balance_type_code     OUT VARCHAR2
76057  ,p_gain_or_loss_ref      OUT VARCHAR2
76058  
76059 --Period Close Date
76060  , p_source_1            IN DATE
76061 --Generated Code Combination Identifier
76062  , p_source_3            IN NUMBER
76063 --Deferred Depreciation Reserve Account
76064  , p_source_16            IN VARCHAR2
76065 --Generated Offset Code Combination Identifier
76066  , p_source_17            IN NUMBER
76067 --Expense Account Code Combination Identifier
76068  , p_source_29            IN NUMBER
76069 --Default Code Combination Identifier
76070  , p_source_30            IN NUMBER
76071 --Distribution Type Code
76072  , p_source_38            IN VARCHAR2
76073 --Entered Amount
76074  , p_source_39            IN NUMBER
76075 --Currency Code
76076  , p_source_40            IN VARCHAR2
76077 --Asset Identifier
76078  , p_source_43            IN NUMBER
76079 --Period Counter
76080  , p_source_44            IN NUMBER
76081 --Distribution Identifier
76082  , p_source_45            IN NUMBER
76083 --Book Type Code
76084  , p_source_46            IN VARCHAR2
76085 --Tax Book Type Code
76086  , p_source_47            IN VARCHAR2
76087 )
76088 IS
76089 
76090 l_component_type              VARCHAR2(80);
76091 l_component_code              VARCHAR2(30);
76092 l_component_type_code         VARCHAR2(1);
76093 l_component_appl_id           INTEGER;
76094 l_amb_context_code            VARCHAR2(30);
76095 l_entity_code                 VARCHAR2(30);
76096 l_event_class_code            VARCHAR2(30);
76097 l_ae_header_id                NUMBER;
76098 l_event_type_code             VARCHAR2(30);
76099 l_line_definition_code        VARCHAR2(30);
76100 l_line_definition_owner_code  VARCHAR2(1);
76101 --
76102 -- adr variables
76103 l_segment                     VARCHAR2(30);
76104 l_ccid                        NUMBER;
76105 l_adr_transaction_coa_id      NUMBER;
76106 l_adr_accounting_coa_id       NUMBER;
76107 l_adr_flexfield_segment_code  VARCHAR2(30);
76108 l_adr_flex_value_set_id       NUMBER;
76109 l_adr_value_type_code         VARCHAR2(30);
76110 l_adr_value_combination_id    NUMBER;
76111 l_adr_value_segment_code      VARCHAR2(30);
76112 
76113 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
76114 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
76115 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
76116 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
76117 
76118 -- 4262811 Variables ------------------------------------------------------------------------------------------
76119 l_entered_amt_idx             NUMBER;
76120 l_accted_amt_idx              NUMBER;
76121 l_acc_rev_flag                VARCHAR2(1);
76122 l_accrual_line_num            NUMBER;
76123 l_tmp_amt                     NUMBER;
76124 l_acc_rev_natural_side_code   VARCHAR2(1);
76125 
76126 l_num_entries                 NUMBER;
76127 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
76128 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
76129 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
76130 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
76131 l_recog_line_1                NUMBER;
76132 l_recog_line_2                NUMBER;
76133 
76137 
76134 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
76135 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
76136 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
76138 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
76139 
76140 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
76141 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
76142 
76143 ---------------------------------------------------------------------------------------------------------------
76144 
76145 
76146 --
76147 -- bulk performance
76148 --
76149 l_balance_type_code           VARCHAR2(1);
76150 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
76151 l_log_module                  VARCHAR2(240);
76152 
76153 --
76154 -- Upgrade strategy
76155 --
76156 l_actual_upg_option           VARCHAR2(1);
76157 l_enc_upg_option           VARCHAR2(1);
76158 
76159 --
76160 BEGIN
76161 --
76162 IF g_log_enabled THEN
76163       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_260';
76164 END IF;
76165 --
76166 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
76167 
76168       trace
76169          (p_msg      => 'BEGIN of AcctLineType_260'
76170          ,p_level    => C_LEVEL_PROCEDURE
76171          ,p_module   => l_log_module);
76172 
76173 END IF;
76174 --
76175 l_component_type             := 'AMB_JLT';
76176 l_component_code             := 'FA_DEF_DEPRN_RESERVE';
76177 l_component_type_code        := 'S';
76178 l_component_appl_id          :=  140;
76179 l_amb_context_code           := 'DEFAULT';
76180 l_entity_code                := 'DEFERRED_DEPRECIATION';
76181 l_event_class_code           := 'DEFERRED_DEPRECIATION';
76182 l_event_type_code            := 'DEFERRED_DEPRECIATION_ALL';
76183 l_line_definition_owner_code := 'S';
76184 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEFER14';
76185 --
76186 l_balance_type_code          := 'A';
76187 l_segment                     := NULL;
76188 l_ccid                        := NULL;
76189 l_adr_transaction_coa_id      := NULL;
76190 l_adr_accounting_coa_id       := NULL;
76191 l_adr_flexfield_segment_code  := NULL;
76192 l_adr_flex_value_set_id       := NULL;
76193 l_adr_value_type_code         := NULL;
76194 l_adr_value_combination_id    := NULL;
76195 l_adr_value_segment_code      := NULL;
76196 
76197 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
76198 l_bflow_class_code           := '';    -- 4219869 Business Flow
76199 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
76200 l_budgetary_control_flag     := 'N';
76201 
76202 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
76203 l_bflow_applied_to_amt       := NULL; -- 5132302
76204 l_entered_amt_idx            := NULL;          -- 4262811
76205 l_accted_amt_idx             := NULL;          -- 4262811
76206 l_acc_rev_flag               := NULL;          -- 4262811
76207 l_accrual_line_num           := NULL;          -- 4262811
76208 l_tmp_amt                    := NULL;          -- 4262811
76209 --
76210  
76211 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
76212     l_balance_type_code <> 'B' THEN
76213 
76214    --
76215    XLA_AE_LINES_PKG.SetNewLine;
76216 
76217    p_balance_type_code          := l_balance_type_code;
76218    -- set the flag so later we will know whether the gain loss line needs to be created
76219    
76220    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
76221      p_actual_flag :='A';
76222    END IF;
76223 
76224    --
76225    -- bulk performance
76226    --
76227    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
76228                                       p_header_num   => 0); -- 4262811
76229    --
76230    -- set accounting line options
76231    --
76232    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
76233            p_natural_side_code          => 'C'
76234          , p_gain_or_loss_flag          => 'N'
76235          , p_gl_transfer_mode_code      => 'S'
76236          , p_acct_entry_type_code       => 'A'
76237          , p_switch_side_flag           => 'Y'
76238          , p_merge_duplicate_code       => 'N'
76239          );
76240    --
76241    l_acc_rev_natural_side_code := 'D';  -- 4262811
76242    -- 
76243    --
76244    -- set accounting line type info
76245    --
76246    xla_ae_lines_pkg.SetAcctLineType
76247       (p_component_type             => l_component_type
76248       ,p_event_type_code            => l_event_type_code
76249       ,p_line_definition_owner_code => l_line_definition_owner_code
76250       ,p_line_definition_code       => l_line_definition_code
76251       ,p_accounting_line_code       => l_component_code
76252       ,p_accounting_line_type_code  => l_component_type_code
76253       ,p_accounting_line_appl_id    => l_component_appl_id
76254       ,p_amb_context_code           => l_amb_context_code
76255       ,p_entity_code                => l_entity_code
76256       ,p_event_class_code           => l_event_class_code);
76257    --
76258    -- set accounting class
76259    --
76260    xla_ae_lines_pkg.SetAcctClass(
76261            p_accounting_class_code  => 'ASSET'
76262          , p_ae_header_id           => l_ae_header_id
76263          );
76264 
76265    --
76266    -- set rounding class
76267    --
76268    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
76269                       'ASSET';
76270 
76271    --
76272    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
76276    --
76273    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
76274    --
76275    -- bulk performance
76277    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
76278 
76279    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
76280       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
76281 
76282    -- 4955764
76283    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
76284       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
76285 
76286    -- 4458381 Public Sector Enh
76287    
76288    --
76289    -- set accounting attributes for the line type
76290    --
76291    l_entered_amt_idx := 7;
76292    l_accted_amt_idx  := 9;
76293    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
76294    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
76295    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
76296    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
76297    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
76298    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
76299    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_45);
76300    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
76301    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
76302    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
76303    l_rec_acct_attrs.array_char_value(5)  := p_source_47;
76304    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
76305    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
76306    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
76307    l_rec_acct_attrs.array_num_value(7)  := p_source_39;
76308    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
76309    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
76310    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
76311    l_rec_acct_attrs.array_num_value(9)  := p_source_39;
76312 
76313    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
76314    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
76315 
76316    ---------------------------------------------------------------------------------------------------------------
76317    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
76318    ---------------------------------------------------------------------------------------------------------------
76319    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
76320 
76321    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
76322    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
76323 
76324    IF xla_accounting_cache_pkg.GetValueChar
76325          (p_source_code         => 'LEDGER_CATEGORY_CODE'
76326          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
76327    AND l_bflow_method_code = 'PRIOR_ENTRY'
76328 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
76329    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
76330          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
76331        )
76332    THEN
76333          xla_ae_lines_pkg.BflowUpgEntry
76334            (p_business_method_code    => l_bflow_method_code
76335            ,p_business_class_code     => l_bflow_class_code
76336            ,p_balance_type            => l_balance_type_code);
76337    ELSE
76338       NULL;
76339 -- No business flow processing for business flow method of NONE.
76340    END IF;
76341 
76342    --
76343    -- call analytical criteria
76344    --
76345    
76346    --
76347    -- call description
76348    --
76349    
76350 xla_ae_lines_pkg.SetLineDescription(
76351    p_ae_header_id => l_ae_header_id
76352   ,p_description  => Description_56 (
76353      p_application_id         => p_application_id
76354    , p_ae_header_id           => l_ae_header_id 
76355 , p_source_1 => p_source_1
76356    )
76357 );
76358 
76359 
76360    --
76361    -- call ADRs
76362    -- Bug 4922099
76363    --
76364    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
76365         (NVL(l_actual_upg_option, 'N') = 'O') OR
76366         (NVL(l_enc_upg_option, 'N') = 'O')
76367       )
76368    THEN
76369    NULL;
76370    --
76371    --
76372    
76373   l_ccid := AcctDerRule_174(
76374            p_application_id           => p_application_id
76375          , p_ae_header_id             => l_ae_header_id 
76376 , p_source_3 => p_source_3
76377 , p_source_17 => p_source_17
76378 , p_source_30 => p_source_30
76379          , x_transaction_coa_id       => l_adr_transaction_coa_id
76380          , x_accounting_coa_id        => l_adr_accounting_coa_id
76381          , x_value_type_code          => l_adr_value_type_code
76382          , p_side                     => 'NA'
76383    );
76384 
76385    xla_ae_lines_pkg.set_ccid(
76386     p_code_combination_id          => l_ccid
76387   , p_value_type_code              => l_adr_value_type_code
76388   , p_transaction_coa_id           => l_adr_transaction_coa_id
76389   , p_accounting_coa_id            => l_adr_accounting_coa_id
76390   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
76391   , p_adr_type_code                => 'S'
76392   , p_component_type               => l_component_type
76393   , p_component_code               => l_component_code
76394   , p_component_type_code          => l_component_type_code
76395   , p_component_appl_id            => l_component_appl_id
76399 
76396   , p_amb_context_code             => l_amb_context_code
76397   , p_side                         => 'NA'
76398   );
76400 
76401    l_segment := AcctDerRule_155(
76402            p_application_id           => p_application_id
76403          , p_ae_header_id             => l_ae_header_id 
76404 , p_source_16 => p_source_16
76405 , p_source_17 => p_source_17
76406          , x_transaction_coa_id       => l_adr_transaction_coa_id
76407          , x_accounting_coa_id        => l_adr_accounting_coa_id
76408          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
76409          , x_flex_value_set_id        => l_adr_flex_value_set_id
76410          , x_value_type_code          => l_adr_value_type_code
76411          , x_value_combination_id     => l_adr_value_combination_id
76412          , x_value_segment_code       => l_adr_value_segment_code
76413          , p_side                     => 'NA'
76414          , p_override_seg_flag        => 'Y'
76415    );
76416 
76417    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
76418 
76419       xla_ae_lines_pkg.set_segment(
76420           p_to_segment_code         => 'GL_ACCOUNT'
76421         , p_segment_value           => l_segment
76422         , p_from_segment_code       => l_adr_value_segment_code
76423         , p_from_combination_id     => l_adr_value_combination_id
76424         , p_value_type_code         => l_adr_value_type_code
76425         , p_transaction_coa_id      => l_adr_transaction_coa_id
76426         , p_accounting_coa_id       => l_adr_accounting_coa_id
76427         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
76428         , p_flex_value_set_id       => l_adr_flex_value_set_id
76429         , p_adr_code                => 'FA_DEF_DEPRN_RESERVE_SEGMENT'
76430         , p_adr_type_code           => 'S'
76431         , p_component_type          => l_component_type
76432         , p_component_code          => l_component_code
76433         , p_component_type_code     => l_component_type_code
76434         , p_component_appl_id       => l_component_appl_id
76435         , p_amb_context_code        => l_amb_context_code
76436         , p_entity_code             => 'DEFERRED_DEPRECIATION'
76437         , p_event_class_code        => 'DEFERRED_DEPRECIATION'
76438         , p_side                    => 'NA'
76439         );
76440 
76441   END IF;
76442 
76443    l_segment := AcctDerRule_168(
76444            p_application_id           => p_application_id
76445          , p_ae_header_id             => l_ae_header_id 
76446 , p_source_3 => p_source_3
76447 , p_source_29 => p_source_29
76448          , x_transaction_coa_id       => l_adr_transaction_coa_id
76449          , x_accounting_coa_id        => l_adr_accounting_coa_id
76450          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
76451          , x_flex_value_set_id        => l_adr_flex_value_set_id
76452          , x_value_type_code          => l_adr_value_type_code
76453          , x_value_combination_id     => l_adr_value_combination_id
76454          , x_value_segment_code       => l_adr_value_segment_code
76455          , p_side                     => 'NA'
76456          , p_override_seg_flag        => 'Y'
76457    );
76458 
76459    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
76460 
76461       xla_ae_lines_pkg.set_segment(
76462           p_to_segment_code         => 'GL_BALANCING'
76463         , p_segment_value           => l_segment
76464         , p_from_segment_code       => l_adr_value_segment_code
76465         , p_from_combination_id     => l_adr_value_combination_id
76466         , p_value_type_code         => l_adr_value_type_code
76467         , p_transaction_coa_id      => l_adr_transaction_coa_id
76468         , p_accounting_coa_id       => l_adr_accounting_coa_id
76469         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
76470         , p_flex_value_set_id       => l_adr_flex_value_set_id
76471         , p_adr_code                => 'FA_EXPENSE_ACCT'
76472         , p_adr_type_code           => 'S'
76473         , p_component_type          => l_component_type
76474         , p_component_code          => l_component_code
76475         , p_component_type_code     => l_component_type_code
76476         , p_component_appl_id       => l_component_appl_id
76477         , p_amb_context_code        => l_amb_context_code
76478         , p_entity_code             => 'DEFERRED_DEPRECIATION'
76479         , p_event_class_code        => 'DEFERRED_DEPRECIATION'
76480         , p_side                    => 'NA'
76481         );
76482 
76483   END IF;
76484 
76485    --
76486    --
76487    END IF;
76488    --
76489    -- Bug 4922099
76490    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
76491           (NVL(l_enc_upg_option, 'N') = 'O')
76492         ) AND
76493         (l_bflow_method_code = 'PRIOR_ENTRY')
76494       )
76495    THEN
76496       IF
76497       --
76498       1 = 2
76499       --
76500       THEN
76501       xla_accounting_err_pkg.build_message
76502                                     (p_appli_s_name            => 'XLA'
76503                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
76504                                     ,p_token_1                 => 'LINE_NUMBER'
76505                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
76506                                     ,p_token_2                 => 'LINE_TYPE_NAME'
76507                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
76508                                                                              l_component_type
76509                                                                             ,l_component_code
76510                                                                             ,l_component_type_code
76511                                                                             ,l_component_appl_id
76515                                                                            )
76512                                                                             ,l_amb_context_code
76513                                                                             ,l_entity_code
76514                                                                             ,l_event_class_code
76516                                     ,p_token_3                 => 'OWNER'
76517                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
76518                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
76519                                                                           ,p_lookup_code    => l_component_type_code
76520                                                                          )
76521                                     ,p_token_4                 => 'PRODUCT_NAME'
76522                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
76523                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
76524                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
76525                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
76526                                     ,p_ae_header_id            =>  NULL
76527                                        );
76528 
76529         IF (C_LEVEL_ERROR>= g_log_level) THEN
76530                  trace
76531                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
76532                       ,p_level    => C_LEVEL_ERROR
76533                       ,p_module   => l_log_module);
76534         END IF;
76535       END IF;
76536    END IF;
76537    --
76538    --
76539    ------------------------------------------------------------------------------------------------
76540    -- 4219869 Business Flow
76541    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
76542    -- Prior Entry.  Currently, the following code is always generated.
76543    ------------------------------------------------------------------------------------------------
76544    XLA_AE_LINES_PKG.ValidateCurrentLine;
76545 
76546    ------------------------------------------------------------------------------------
76547    -- 4219869 Business Flow
76548    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
76549    ------------------------------------------------------------------------------------
76550    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
76551 
76552    ----------------------------------------------------------------------------------
76553    -- 4219869 Business Flow
76554    -- Update journal entry status -- Need to generate this within IF <condition>
76555    ----------------------------------------------------------------------------------
76556    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
76557          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
76558          ,p_balance_type_code => l_balance_type_code
76559          );
76560 
76561    -------------------------------------------------------------------------------------------
76562    -- 4262811 - Generate the Accrual Reversal lines
76563    -------------------------------------------------------------------------------------------
76564    BEGIN
76565       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
76566                               (g_array_event(p_event_id).array_value_num('header_index'));
76567       IF l_acc_rev_flag IS NULL THEN
76568          l_acc_rev_flag := 'N';
76569       END IF;
76570    EXCEPTION
76571       WHEN OTHERS THEN
76572          l_acc_rev_flag := 'N';
76573    END;
76574    --
76575    IF (l_acc_rev_flag = 'Y') THEN
76576 
76577        -- 4645092  ------------------------------------------------------------------------------
76578        -- To allow MPA report to determine if it should generate report process
76579        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
76580        ------------------------------------------------------------------------------------------
76581 
76582        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
76583        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
76584    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
76585    -- call ADRs
76586    -- Bug 4922099
76587    --
76588    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
76589         (NVL(l_actual_upg_option, 'N') = 'O') OR
76590         (NVL(l_enc_upg_option, 'N') = 'O')
76591       )
76592    THEN
76593    NULL;
76594    --
76595    --
76596    
76597   l_ccid := AcctDerRule_174(
76598            p_application_id           => p_application_id
76599          , p_ae_header_id             => l_ae_header_id 
76600 , p_source_3 => p_source_3
76601 , p_source_17 => p_source_17
76602 , p_source_30 => p_source_30
76603          , x_transaction_coa_id       => l_adr_transaction_coa_id
76604          , x_accounting_coa_id        => l_adr_accounting_coa_id
76605          , x_value_type_code          => l_adr_value_type_code
76606          , p_side                     => 'NA'
76607    );
76608 
76609    xla_ae_lines_pkg.set_ccid(
76610     p_code_combination_id          => l_ccid
76611   , p_value_type_code              => l_adr_value_type_code
76612   , p_transaction_coa_id           => l_adr_transaction_coa_id
76613   , p_accounting_coa_id            => l_adr_accounting_coa_id
76614   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
76615   , p_adr_type_code                => 'S'
76616   , p_component_type               => l_component_type
76617   , p_component_code               => l_component_code
76618   , p_component_type_code          => l_component_type_code
76619   , p_component_appl_id            => l_component_appl_id
76623 
76620   , p_amb_context_code             => l_amb_context_code
76621   , p_side                         => 'NA'
76622   );
76624 
76625    l_segment := AcctDerRule_155(
76626            p_application_id           => p_application_id
76627          , p_ae_header_id             => l_ae_header_id 
76628 , p_source_16 => p_source_16
76629 , p_source_17 => p_source_17
76630          , x_transaction_coa_id       => l_adr_transaction_coa_id
76631          , x_accounting_coa_id        => l_adr_accounting_coa_id
76632          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
76633          , x_flex_value_set_id        => l_adr_flex_value_set_id
76634          , x_value_type_code          => l_adr_value_type_code
76635          , x_value_combination_id     => l_adr_value_combination_id
76636          , x_value_segment_code       => l_adr_value_segment_code
76637          , p_side                     => 'NA'
76638          , p_override_seg_flag        => 'Y'
76639    );
76640 
76641    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
76642 
76643       xla_ae_lines_pkg.set_segment(
76644           p_to_segment_code         => 'GL_ACCOUNT'
76645         , p_segment_value           => l_segment
76646         , p_from_segment_code       => l_adr_value_segment_code
76647         , p_from_combination_id     => l_adr_value_combination_id
76648         , p_value_type_code         => l_adr_value_type_code
76649         , p_transaction_coa_id      => l_adr_transaction_coa_id
76650         , p_accounting_coa_id       => l_adr_accounting_coa_id
76651         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
76652         , p_flex_value_set_id       => l_adr_flex_value_set_id
76653         , p_adr_code                => 'FA_DEF_DEPRN_RESERVE_SEGMENT'
76654         , p_adr_type_code           => 'S'
76655         , p_component_type          => l_component_type
76656         , p_component_code          => l_component_code
76657         , p_component_type_code     => l_component_type_code
76658         , p_component_appl_id       => l_component_appl_id
76659         , p_amb_context_code        => l_amb_context_code
76660         , p_entity_code             => 'DEFERRED_DEPRECIATION'
76661         , p_event_class_code        => 'DEFERRED_DEPRECIATION'
76662         , p_side                    => 'NA'
76663         );
76664 
76665   END IF;
76666 
76667    l_segment := AcctDerRule_168(
76668            p_application_id           => p_application_id
76669          , p_ae_header_id             => l_ae_header_id 
76670 , p_source_3 => p_source_3
76671 , p_source_29 => p_source_29
76672          , x_transaction_coa_id       => l_adr_transaction_coa_id
76673          , x_accounting_coa_id        => l_adr_accounting_coa_id
76674          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
76675          , x_flex_value_set_id        => l_adr_flex_value_set_id
76676          , x_value_type_code          => l_adr_value_type_code
76677          , x_value_combination_id     => l_adr_value_combination_id
76678          , x_value_segment_code       => l_adr_value_segment_code
76679          , p_side                     => 'NA'
76680          , p_override_seg_flag        => 'Y'
76681    );
76682 
76683    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
76684 
76685       xla_ae_lines_pkg.set_segment(
76686           p_to_segment_code         => 'GL_BALANCING'
76687         , p_segment_value           => l_segment
76688         , p_from_segment_code       => l_adr_value_segment_code
76689         , p_from_combination_id     => l_adr_value_combination_id
76690         , p_value_type_code         => l_adr_value_type_code
76691         , p_transaction_coa_id      => l_adr_transaction_coa_id
76692         , p_accounting_coa_id       => l_adr_accounting_coa_id
76693         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
76694         , p_flex_value_set_id       => l_adr_flex_value_set_id
76695         , p_adr_code                => 'FA_EXPENSE_ACCT'
76696         , p_adr_type_code           => 'S'
76697         , p_component_type          => l_component_type
76698         , p_component_code          => l_component_code
76699         , p_component_type_code     => l_component_type_code
76700         , p_component_appl_id       => l_component_appl_id
76701         , p_amb_context_code        => l_amb_context_code
76702         , p_entity_code             => 'DEFERRED_DEPRECIATION'
76703         , p_event_class_code        => 'DEFERRED_DEPRECIATION'
76704         , p_side                    => 'NA'
76705         );
76706 
76707   END IF;
76708 
76709    --
76710    --
76711    END IF;
76712 
76713        --
76714        -- Update the line information that should be overwritten
76715        --
76716        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
76717                                          p_header_num   => 1);
76718        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
76719 
76720        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
76721 
76722        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
76723           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
76724        END IF;
76725 
76726       --
76727       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
76728       --
76729       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
76730           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
76731       ELSE
76732           ---------------------------------------------------------------------------------------------------
76733           -- 4262811a Switch Sign
76734           ---------------------------------------------------------------------------------------------------
76738           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
76735           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
76736           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
76737                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
76739                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
76740           -- 5132302
76741           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
76742                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
76743 
76744       END IF;
76745 
76746       -- 4955764
76747       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
76748       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
76749 
76750 
76751       XLA_AE_LINES_PKG.ValidateCurrentLine;
76752       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
76753 
76754       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
76755                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
76756                ,p_balance_type_code => l_balance_type_code);
76757 
76758    END IF;
76759 
76760    -----------------------------------------------------------------------------------------
76761    -- 4262811 Multiperiod Accounting
76762    -----------------------------------------------------------------------------------------
76763      -- No MPA option is assigned.
76764 
76765 
76766 END IF;
76767 --
76768 
76769 --
76770 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
76771    trace
76772       (p_msg      => 'END of AcctLineType_260'
76773       ,p_level    => C_LEVEL_PROCEDURE
76774       ,p_module   => l_log_module);
76775 END IF;
76776 --
76777 EXCEPTION
76778   WHEN xla_exceptions_pkg.application_exception THEN
76779       RAISE;
76780   WHEN OTHERS THEN
76781        xla_exceptions_pkg.raise_message
76782            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_260');
76783 END AcctLineType_260;
76784 --
76785 
76786 ---------------------------------------
76787 --
76788 -- PRIVATE FUNCTION
76789 --         AcctLineType_261
76790 --
76791 ---------------------------------------
76792 PROCEDURE AcctLineType_261 (
76793   p_application_id        IN NUMBER
76794  ,p_event_id              IN NUMBER
76795  ,p_calculate_acctd_flag  IN VARCHAR2
76796  ,p_calculate_g_l_flag    IN VARCHAR2
76797  ,p_actual_flag           IN OUT VARCHAR2
76798  ,p_balance_type_code     OUT VARCHAR2
76799  ,p_gain_or_loss_ref      OUT VARCHAR2
76800  
76801 --Period Close Date
76802  , p_source_1            IN DATE
76803 --Generated Code Combination Identifier
76804  , p_source_3            IN NUMBER
76805 --Net Book Value Retired Gain Account
76806  , p_source_21            IN VARCHAR2
76807 --Expense Account Code Combination Identifier
76808  , p_source_29            IN NUMBER
76809 --Default Code Combination Identifier
76810  , p_source_30            IN NUMBER
76811 --Adjustment Type
76812  , p_source_35            IN VARCHAR2
76813 --Transaction Header Identifier
76814  , p_source_36            IN NUMBER
76815 --Adjustment Line Identifier
76816  , p_source_37            IN NUMBER
76817 --Distribution Type Code
76818  , p_source_38            IN VARCHAR2
76819 --Entered Amount
76820  , p_source_39            IN NUMBER
76821 --Currency Code
76822  , p_source_40            IN VARCHAR2
76823 --Gain Loss Amount
76824  , p_source_41            IN NUMBER
76825 )
76826 IS
76827 
76828 l_component_type              VARCHAR2(80);
76829 l_component_code              VARCHAR2(30);
76830 l_component_type_code         VARCHAR2(1);
76831 l_component_appl_id           INTEGER;
76832 l_amb_context_code            VARCHAR2(30);
76833 l_entity_code                 VARCHAR2(30);
76834 l_event_class_code            VARCHAR2(30);
76835 l_ae_header_id                NUMBER;
76836 l_event_type_code             VARCHAR2(30);
76837 l_line_definition_code        VARCHAR2(30);
76838 l_line_definition_owner_code  VARCHAR2(1);
76839 --
76840 -- adr variables
76841 l_segment                     VARCHAR2(30);
76842 l_ccid                        NUMBER;
76843 l_adr_transaction_coa_id      NUMBER;
76844 l_adr_accounting_coa_id       NUMBER;
76845 l_adr_flexfield_segment_code  VARCHAR2(30);
76846 l_adr_flex_value_set_id       NUMBER;
76847 l_adr_value_type_code         VARCHAR2(30);
76848 l_adr_value_combination_id    NUMBER;
76849 l_adr_value_segment_code      VARCHAR2(30);
76850 
76851 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
76852 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
76853 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
76854 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
76855 
76856 -- 4262811 Variables ------------------------------------------------------------------------------------------
76857 l_entered_amt_idx             NUMBER;
76858 l_accted_amt_idx              NUMBER;
76859 l_acc_rev_flag                VARCHAR2(1);
76860 l_accrual_line_num            NUMBER;
76861 l_tmp_amt                     NUMBER;
76862 l_acc_rev_natural_side_code   VARCHAR2(1);
76863 
76864 l_num_entries                 NUMBER;
76865 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
76866 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
76867 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
76868 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
76869 l_recog_line_1                NUMBER;
76870 l_recog_line_2                NUMBER;
76874 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
76871 
76872 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
76873 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
76875 
76876 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
76877 
76878 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
76879 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
76880 
76881 ---------------------------------------------------------------------------------------------------------------
76882 
76883 
76884 --
76885 -- bulk performance
76886 --
76887 l_balance_type_code           VARCHAR2(1);
76888 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
76889 l_log_module                  VARCHAR2(240);
76890 
76891 --
76892 -- Upgrade strategy
76893 --
76894 l_actual_upg_option           VARCHAR2(1);
76895 l_enc_upg_option           VARCHAR2(1);
76896 
76897 --
76898 BEGIN
76899 --
76900 IF g_log_enabled THEN
76901       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_261';
76902 END IF;
76903 --
76904 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
76905 
76906       trace
76907          (p_msg      => 'BEGIN of AcctLineType_261'
76908          ,p_level    => C_LEVEL_PROCEDURE
76909          ,p_module   => l_log_module);
76910 
76911 END IF;
76912 --
76913 l_component_type             := 'AMB_JLT';
76914 l_component_code             := 'FA_NBV_RETIRED_GAIN';
76915 l_component_type_code        := 'S';
76916 l_component_appl_id          :=  140;
76917 l_amb_context_code           := 'DEFAULT';
76918 l_entity_code                := 'TRANSACTIONS';
76919 l_event_class_code           := 'RETIREMENTS';
76920 l_event_type_code            := 'RETIREMENTS';
76921 l_line_definition_owner_code := 'S';
76922 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
76923 --
76924 l_balance_type_code          := 'A';
76925 l_segment                     := NULL;
76926 l_ccid                        := NULL;
76927 l_adr_transaction_coa_id      := NULL;
76928 l_adr_accounting_coa_id       := NULL;
76929 l_adr_flexfield_segment_code  := NULL;
76930 l_adr_flex_value_set_id       := NULL;
76931 l_adr_value_type_code         := NULL;
76932 l_adr_value_combination_id    := NULL;
76933 l_adr_value_segment_code      := NULL;
76934 
76935 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
76936 l_bflow_class_code           := '';    -- 4219869 Business Flow
76937 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
76938 l_budgetary_control_flag     := 'N';
76939 
76940 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
76941 l_bflow_applied_to_amt       := NULL; -- 5132302
76942 l_entered_amt_idx            := NULL;          -- 4262811
76943 l_accted_amt_idx             := NULL;          -- 4262811
76944 l_acc_rev_flag               := NULL;          -- 4262811
76945 l_accrual_line_num           := NULL;          -- 4262811
76946 l_tmp_amt                    := NULL;          -- 4262811
76947 --
76948  
76949 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
76950     l_balance_type_code <> 'B' THEN
76951 IF NVL(p_source_35,'
76952 ') =  'NBV RETIRED' AND 
76953 p_source_41 >=  0
76954  THEN 
76955 
76956    --
76957    XLA_AE_LINES_PKG.SetNewLine;
76958 
76959    p_balance_type_code          := l_balance_type_code;
76960    -- set the flag so later we will know whether the gain loss line needs to be created
76961    
76962    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
76963      p_actual_flag :='A';
76964    END IF;
76965 
76966    --
76967    -- bulk performance
76968    --
76969    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
76970                                       p_header_num   => 0); -- 4262811
76971    --
76972    -- set accounting line options
76973    --
76974    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
76975            p_natural_side_code          => 'D'
76976          , p_gain_or_loss_flag          => 'N'
76977          , p_gl_transfer_mode_code      => 'S'
76978          , p_acct_entry_type_code       => 'A'
76979          , p_switch_side_flag           => 'Y'
76980          , p_merge_duplicate_code       => 'N'
76981          );
76982    --
76983    l_acc_rev_natural_side_code := 'C';  -- 4262811
76984    -- 
76985    --
76986    -- set accounting line type info
76987    --
76988    xla_ae_lines_pkg.SetAcctLineType
76989       (p_component_type             => l_component_type
76990       ,p_event_type_code            => l_event_type_code
76991       ,p_line_definition_owner_code => l_line_definition_owner_code
76992       ,p_line_definition_code       => l_line_definition_code
76993       ,p_accounting_line_code       => l_component_code
76994       ,p_accounting_line_type_code  => l_component_type_code
76995       ,p_accounting_line_appl_id    => l_component_appl_id
76996       ,p_amb_context_code           => l_amb_context_code
76997       ,p_entity_code                => l_entity_code
76998       ,p_event_class_code           => l_event_class_code);
76999    --
77000    -- set accounting class
77001    --
77002    xla_ae_lines_pkg.SetAcctClass(
77003            p_accounting_class_code  => 'ASSET'
77004          , p_ae_header_id           => l_ae_header_id
77005          );
77006 
77007    --
77008    -- set rounding class
77009    --
77010    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
77011                       'ASSET';
77012 
77013    --
77017    -- bulk performance
77014    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
77015    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
77016    --
77018    --
77019    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
77020 
77021    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
77022       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
77023 
77024    -- 4955764
77025    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
77026       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
77027 
77028    -- 4458381 Public Sector Enh
77029    
77030    --
77031    -- set accounting attributes for the line type
77032    --
77033    l_entered_amt_idx := 4;
77034    l_accted_amt_idx  := 6;
77035    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
77036    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
77037    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
77038    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
77039    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
77040    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
77041    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
77042    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
77043    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
77044    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
77045    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
77046    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
77047    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
77048 
77049    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
77050    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
77051 
77052    ---------------------------------------------------------------------------------------------------------------
77053    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
77054    ---------------------------------------------------------------------------------------------------------------
77055    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
77056 
77057    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
77058    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
77059 
77060    IF xla_accounting_cache_pkg.GetValueChar
77061          (p_source_code         => 'LEDGER_CATEGORY_CODE'
77062          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
77063    AND l_bflow_method_code = 'PRIOR_ENTRY'
77064 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
77065    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
77066          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
77067        )
77068    THEN
77069          xla_ae_lines_pkg.BflowUpgEntry
77070            (p_business_method_code    => l_bflow_method_code
77071            ,p_business_class_code     => l_bflow_class_code
77072            ,p_balance_type            => l_balance_type_code);
77073    ELSE
77074       NULL;
77075 -- No business flow processing for business flow method of NONE.
77076    END IF;
77077 
77078    --
77079    -- call analytical criteria
77080    --
77081    
77082    --
77083    -- call description
77084    --
77085    
77086 xla_ae_lines_pkg.SetLineDescription(
77087    p_ae_header_id => l_ae_header_id
77088   ,p_description  => Description_80 (
77089      p_application_id         => p_application_id
77090    , p_ae_header_id           => l_ae_header_id 
77091 , p_source_1 => p_source_1
77092    )
77093 );
77094 
77095 
77096    --
77097    -- call ADRs
77098    -- Bug 4922099
77099    --
77100    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
77101         (NVL(l_actual_upg_option, 'N') = 'O') OR
77102         (NVL(l_enc_upg_option, 'N') = 'O')
77103       )
77104    THEN
77105    NULL;
77106    --
77107    --
77108    
77109   l_ccid := AcctDerRule_173(
77110            p_application_id           => p_application_id
77111          , p_ae_header_id             => l_ae_header_id 
77112 , p_source_3 => p_source_3
77113 , p_source_30 => p_source_30
77114          , x_transaction_coa_id       => l_adr_transaction_coa_id
77115          , x_accounting_coa_id        => l_adr_accounting_coa_id
77116          , x_value_type_code          => l_adr_value_type_code
77117          , p_side                     => 'NA'
77118    );
77119 
77120    xla_ae_lines_pkg.set_ccid(
77121     p_code_combination_id          => l_ccid
77122   , p_value_type_code              => l_adr_value_type_code
77123   , p_transaction_coa_id           => l_adr_transaction_coa_id
77124   , p_accounting_coa_id            => l_adr_accounting_coa_id
77125   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
77126   , p_adr_type_code                => 'S'
77127   , p_component_type               => l_component_type
77128   , p_component_code               => l_component_code
77129   , p_component_type_code          => l_component_type_code
77130   , p_component_appl_id            => l_component_appl_id
77131   , p_amb_context_code             => l_amb_context_code
77132   , p_side                         => 'NA'
77133   );
77134 
77135 
77136    l_segment := AcctDerRule_168(
77137            p_application_id           => p_application_id
77138          , p_ae_header_id             => l_ae_header_id 
77139 , p_source_3 => p_source_3
77140 , p_source_29 => p_source_29
77144          , x_flex_value_set_id        => l_adr_flex_value_set_id
77141          , x_transaction_coa_id       => l_adr_transaction_coa_id
77142          , x_accounting_coa_id        => l_adr_accounting_coa_id
77143          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
77145          , x_value_type_code          => l_adr_value_type_code
77146          , x_value_combination_id     => l_adr_value_combination_id
77147          , x_value_segment_code       => l_adr_value_segment_code
77148          , p_side                     => 'NA'
77149          , p_override_seg_flag        => 'Y'
77150    );
77151 
77152    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
77153 
77154       xla_ae_lines_pkg.set_segment(
77155           p_to_segment_code         => 'GL_BALANCING'
77156         , p_segment_value           => l_segment
77157         , p_from_segment_code       => l_adr_value_segment_code
77158         , p_from_combination_id     => l_adr_value_combination_id
77159         , p_value_type_code         => l_adr_value_type_code
77160         , p_transaction_coa_id      => l_adr_transaction_coa_id
77161         , p_accounting_coa_id       => l_adr_accounting_coa_id
77162         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
77163         , p_flex_value_set_id       => l_adr_flex_value_set_id
77164         , p_adr_code                => 'FA_EXPENSE_ACCT'
77165         , p_adr_type_code           => 'S'
77166         , p_component_type          => l_component_type
77167         , p_component_code          => l_component_code
77168         , p_component_type_code     => l_component_type_code
77169         , p_component_appl_id       => l_component_appl_id
77170         , p_amb_context_code        => l_amb_context_code
77171         , p_entity_code             => 'TRANSACTIONS'
77172         , p_event_class_code        => 'RETIREMENTS'
77173         , p_side                    => 'NA'
77174         );
77175 
77176   END IF;
77177 
77178    l_segment := AcctDerRule_159(
77179            p_application_id           => p_application_id
77180          , p_ae_header_id             => l_ae_header_id 
77181 , p_source_3 => p_source_3
77182 , p_source_21 => p_source_21
77183          , x_transaction_coa_id       => l_adr_transaction_coa_id
77184          , x_accounting_coa_id        => l_adr_accounting_coa_id
77185          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
77186          , x_flex_value_set_id        => l_adr_flex_value_set_id
77187          , x_value_type_code          => l_adr_value_type_code
77188          , x_value_combination_id     => l_adr_value_combination_id
77189          , x_value_segment_code       => l_adr_value_segment_code
77190          , p_side                     => 'NA'
77191          , p_override_seg_flag        => 'Y'
77192    );
77193 
77194    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
77195 
77196       xla_ae_lines_pkg.set_segment(
77197           p_to_segment_code         => 'GL_ACCOUNT'
77198         , p_segment_value           => l_segment
77199         , p_from_segment_code       => l_adr_value_segment_code
77200         , p_from_combination_id     => l_adr_value_combination_id
77201         , p_value_type_code         => l_adr_value_type_code
77202         , p_transaction_coa_id      => l_adr_transaction_coa_id
77203         , p_accounting_coa_id       => l_adr_accounting_coa_id
77204         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
77205         , p_flex_value_set_id       => l_adr_flex_value_set_id
77206         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
77207         , p_adr_type_code           => 'S'
77208         , p_component_type          => l_component_type
77209         , p_component_code          => l_component_code
77210         , p_component_type_code     => l_component_type_code
77211         , p_component_appl_id       => l_component_appl_id
77212         , p_amb_context_code        => l_amb_context_code
77213         , p_entity_code             => 'TRANSACTIONS'
77214         , p_event_class_code        => 'RETIREMENTS'
77215         , p_side                    => 'NA'
77216         );
77217 
77218   END IF;
77219 
77220    --
77221    --
77222    END IF;
77223    --
77224    -- Bug 4922099
77225    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
77226           (NVL(l_enc_upg_option, 'N') = 'O')
77227         ) AND
77228         (l_bflow_method_code = 'PRIOR_ENTRY')
77229       )
77230    THEN
77231       IF
77232       --
77233       1 = 2
77234       --
77235       THEN
77236       xla_accounting_err_pkg.build_message
77237                                     (p_appli_s_name            => 'XLA'
77238                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
77239                                     ,p_token_1                 => 'LINE_NUMBER'
77240                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
77241                                     ,p_token_2                 => 'LINE_TYPE_NAME'
77242                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
77243                                                                              l_component_type
77244                                                                             ,l_component_code
77245                                                                             ,l_component_type_code
77246                                                                             ,l_component_appl_id
77247                                                                             ,l_amb_context_code
77248                                                                             ,l_entity_code
77249                                                                             ,l_event_class_code
77250                                                                            )
77251                                     ,p_token_3                 => 'OWNER'
77255                                                                          )
77252                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
77253                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
77254                                                                           ,p_lookup_code    => l_component_type_code
77256                                     ,p_token_4                 => 'PRODUCT_NAME'
77257                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
77258                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
77259                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
77260                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
77261                                     ,p_ae_header_id            =>  NULL
77262                                        );
77263 
77264         IF (C_LEVEL_ERROR>= g_log_level) THEN
77265                  trace
77266                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
77267                       ,p_level    => C_LEVEL_ERROR
77268                       ,p_module   => l_log_module);
77269         END IF;
77270       END IF;
77271    END IF;
77272    --
77273    --
77274    ------------------------------------------------------------------------------------------------
77275    -- 4219869 Business Flow
77276    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
77277    -- Prior Entry.  Currently, the following code is always generated.
77278    ------------------------------------------------------------------------------------------------
77279    XLA_AE_LINES_PKG.ValidateCurrentLine;
77280 
77281    ------------------------------------------------------------------------------------
77282    -- 4219869 Business Flow
77283    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
77284    ------------------------------------------------------------------------------------
77285    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
77286 
77287    ----------------------------------------------------------------------------------
77288    -- 4219869 Business Flow
77289    -- Update journal entry status -- Need to generate this within IF <condition>
77290    ----------------------------------------------------------------------------------
77291    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
77292          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
77293          ,p_balance_type_code => l_balance_type_code
77294          );
77295 
77296    -------------------------------------------------------------------------------------------
77297    -- 4262811 - Generate the Accrual Reversal lines
77298    -------------------------------------------------------------------------------------------
77299    BEGIN
77300       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
77301                               (g_array_event(p_event_id).array_value_num('header_index'));
77302       IF l_acc_rev_flag IS NULL THEN
77303          l_acc_rev_flag := 'N';
77304       END IF;
77305    EXCEPTION
77306       WHEN OTHERS THEN
77307          l_acc_rev_flag := 'N';
77308    END;
77309    --
77310    IF (l_acc_rev_flag = 'Y') THEN
77311 
77312        -- 4645092  ------------------------------------------------------------------------------
77313        -- To allow MPA report to determine if it should generate report process
77314        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
77315        ------------------------------------------------------------------------------------------
77316 
77317        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
77318        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
77319    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
77320    -- call ADRs
77321    -- Bug 4922099
77322    --
77323    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
77324         (NVL(l_actual_upg_option, 'N') = 'O') OR
77325         (NVL(l_enc_upg_option, 'N') = 'O')
77326       )
77327    THEN
77328    NULL;
77329    --
77330    --
77331    
77332   l_ccid := AcctDerRule_173(
77333            p_application_id           => p_application_id
77334          , p_ae_header_id             => l_ae_header_id 
77335 , p_source_3 => p_source_3
77336 , p_source_30 => p_source_30
77337          , x_transaction_coa_id       => l_adr_transaction_coa_id
77338          , x_accounting_coa_id        => l_adr_accounting_coa_id
77339          , x_value_type_code          => l_adr_value_type_code
77340          , p_side                     => 'NA'
77341    );
77342 
77343    xla_ae_lines_pkg.set_ccid(
77344     p_code_combination_id          => l_ccid
77345   , p_value_type_code              => l_adr_value_type_code
77346   , p_transaction_coa_id           => l_adr_transaction_coa_id
77347   , p_accounting_coa_id            => l_adr_accounting_coa_id
77348   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
77349   , p_adr_type_code                => 'S'
77350   , p_component_type               => l_component_type
77351   , p_component_code               => l_component_code
77352   , p_component_type_code          => l_component_type_code
77353   , p_component_appl_id            => l_component_appl_id
77354   , p_amb_context_code             => l_amb_context_code
77355   , p_side                         => 'NA'
77356   );
77357 
77358 
77359    l_segment := AcctDerRule_168(
77360            p_application_id           => p_application_id
77361          , p_ae_header_id             => l_ae_header_id 
77362 , p_source_3 => p_source_3
77363 , p_source_29 => p_source_29
77364          , x_transaction_coa_id       => l_adr_transaction_coa_id
77368          , x_value_type_code          => l_adr_value_type_code
77365          , x_accounting_coa_id        => l_adr_accounting_coa_id
77366          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
77367          , x_flex_value_set_id        => l_adr_flex_value_set_id
77369          , x_value_combination_id     => l_adr_value_combination_id
77370          , x_value_segment_code       => l_adr_value_segment_code
77371          , p_side                     => 'NA'
77372          , p_override_seg_flag        => 'Y'
77373    );
77374 
77375    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
77376 
77377       xla_ae_lines_pkg.set_segment(
77378           p_to_segment_code         => 'GL_BALANCING'
77379         , p_segment_value           => l_segment
77380         , p_from_segment_code       => l_adr_value_segment_code
77381         , p_from_combination_id     => l_adr_value_combination_id
77382         , p_value_type_code         => l_adr_value_type_code
77383         , p_transaction_coa_id      => l_adr_transaction_coa_id
77384         , p_accounting_coa_id       => l_adr_accounting_coa_id
77385         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
77386         , p_flex_value_set_id       => l_adr_flex_value_set_id
77387         , p_adr_code                => 'FA_EXPENSE_ACCT'
77388         , p_adr_type_code           => 'S'
77389         , p_component_type          => l_component_type
77390         , p_component_code          => l_component_code
77391         , p_component_type_code     => l_component_type_code
77392         , p_component_appl_id       => l_component_appl_id
77393         , p_amb_context_code        => l_amb_context_code
77394         , p_entity_code             => 'TRANSACTIONS'
77395         , p_event_class_code        => 'RETIREMENTS'
77396         , p_side                    => 'NA'
77397         );
77398 
77399   END IF;
77400 
77401    l_segment := AcctDerRule_159(
77402            p_application_id           => p_application_id
77403          , p_ae_header_id             => l_ae_header_id 
77404 , p_source_3 => p_source_3
77405 , p_source_21 => p_source_21
77406          , x_transaction_coa_id       => l_adr_transaction_coa_id
77407          , x_accounting_coa_id        => l_adr_accounting_coa_id
77408          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
77409          , x_flex_value_set_id        => l_adr_flex_value_set_id
77410          , x_value_type_code          => l_adr_value_type_code
77411          , x_value_combination_id     => l_adr_value_combination_id
77412          , x_value_segment_code       => l_adr_value_segment_code
77413          , p_side                     => 'NA'
77414          , p_override_seg_flag        => 'Y'
77415    );
77416 
77417    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
77418 
77419       xla_ae_lines_pkg.set_segment(
77420           p_to_segment_code         => 'GL_ACCOUNT'
77421         , p_segment_value           => l_segment
77422         , p_from_segment_code       => l_adr_value_segment_code
77423         , p_from_combination_id     => l_adr_value_combination_id
77424         , p_value_type_code         => l_adr_value_type_code
77425         , p_transaction_coa_id      => l_adr_transaction_coa_id
77426         , p_accounting_coa_id       => l_adr_accounting_coa_id
77427         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
77428         , p_flex_value_set_id       => l_adr_flex_value_set_id
77429         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
77430         , p_adr_type_code           => 'S'
77431         , p_component_type          => l_component_type
77432         , p_component_code          => l_component_code
77433         , p_component_type_code     => l_component_type_code
77434         , p_component_appl_id       => l_component_appl_id
77435         , p_amb_context_code        => l_amb_context_code
77436         , p_entity_code             => 'TRANSACTIONS'
77437         , p_event_class_code        => 'RETIREMENTS'
77438         , p_side                    => 'NA'
77439         );
77440 
77441   END IF;
77442 
77443    --
77444    --
77445    END IF;
77446 
77447        --
77448        -- Update the line information that should be overwritten
77449        --
77450        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
77451                                          p_header_num   => 1);
77452        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
77453 
77454        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
77455 
77456        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
77457           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
77458        END IF;
77459 
77460       --
77461       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
77462       --
77463       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
77464           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
77465       ELSE
77466           ---------------------------------------------------------------------------------------------------
77467           -- 4262811a Switch Sign
77468           ---------------------------------------------------------------------------------------------------
77469           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
77470           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
77471                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
77472           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
77473                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
77474           -- 5132302
77478       END IF;
77475           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
77476                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
77477 
77479 
77480       -- 4955764
77481       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
77482       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
77483 
77484 
77485       XLA_AE_LINES_PKG.ValidateCurrentLine;
77486       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
77487 
77488       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
77489                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
77490                ,p_balance_type_code => l_balance_type_code);
77491 
77492    END IF;
77493 
77494    -----------------------------------------------------------------------------------------
77495    -- 4262811 Multiperiod Accounting
77496    -----------------------------------------------------------------------------------------
77497      -- No MPA option is assigned.
77498 
77499 
77500 END IF;
77501 END IF;
77502 --
77503 
77504 --
77505 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
77506    trace
77507       (p_msg      => 'END of AcctLineType_261'
77508       ,p_level    => C_LEVEL_PROCEDURE
77509       ,p_module   => l_log_module);
77510 END IF;
77511 --
77512 EXCEPTION
77513   WHEN xla_exceptions_pkg.application_exception THEN
77514       RAISE;
77515   WHEN OTHERS THEN
77516        xla_exceptions_pkg.raise_message
77517            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_261');
77518 END AcctLineType_261;
77519 --
77520 
77521 ---------------------------------------
77522 --
77523 -- PRIVATE FUNCTION
77524 --         AcctLineType_262
77525 --
77526 ---------------------------------------
77527 PROCEDURE AcctLineType_262 (
77528   p_application_id        IN NUMBER
77529  ,p_event_id              IN NUMBER
77530  ,p_calculate_acctd_flag  IN VARCHAR2
77531  ,p_calculate_g_l_flag    IN VARCHAR2
77532  ,p_actual_flag           IN OUT VARCHAR2
77533  ,p_balance_type_code     OUT VARCHAR2
77534  ,p_gain_or_loss_ref      OUT VARCHAR2
77535  
77536 --Period Close Date
77537  , p_source_1            IN DATE
77538 --Generated Code Combination Identifier
77539  , p_source_3            IN NUMBER
77540 --Net Book Value Retired Gain Account
77541  , p_source_21            IN VARCHAR2
77542 --Expense Account Code Combination Identifier
77543  , p_source_29            IN NUMBER
77544 --Default Code Combination Identifier
77545  , p_source_30            IN NUMBER
77546 --Adjustment Type
77547  , p_source_35            IN VARCHAR2
77548 --Transaction Header Identifier
77549  , p_source_36            IN NUMBER
77550 --Adjustment Line Identifier
77551  , p_source_37            IN NUMBER
77552 --Distribution Type Code
77553  , p_source_38            IN VARCHAR2
77554 --Entered Amount
77555  , p_source_39            IN NUMBER
77556 --Currency Code
77557  , p_source_40            IN VARCHAR2
77558 --Gain Loss Amount
77559  , p_source_41            IN NUMBER
77560 )
77561 IS
77562 
77563 l_component_type              VARCHAR2(80);
77564 l_component_code              VARCHAR2(30);
77565 l_component_type_code         VARCHAR2(1);
77566 l_component_appl_id           INTEGER;
77567 l_amb_context_code            VARCHAR2(30);
77568 l_entity_code                 VARCHAR2(30);
77569 l_event_class_code            VARCHAR2(30);
77570 l_ae_header_id                NUMBER;
77571 l_event_type_code             VARCHAR2(30);
77572 l_line_definition_code        VARCHAR2(30);
77573 l_line_definition_owner_code  VARCHAR2(1);
77574 --
77575 -- adr variables
77576 l_segment                     VARCHAR2(30);
77577 l_ccid                        NUMBER;
77578 l_adr_transaction_coa_id      NUMBER;
77579 l_adr_accounting_coa_id       NUMBER;
77580 l_adr_flexfield_segment_code  VARCHAR2(30);
77581 l_adr_flex_value_set_id       NUMBER;
77582 l_adr_value_type_code         VARCHAR2(30);
77583 l_adr_value_combination_id    NUMBER;
77584 l_adr_value_segment_code      VARCHAR2(30);
77585 
77586 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
77587 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
77588 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
77589 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
77590 
77591 -- 4262811 Variables ------------------------------------------------------------------------------------------
77592 l_entered_amt_idx             NUMBER;
77593 l_accted_amt_idx              NUMBER;
77594 l_acc_rev_flag                VARCHAR2(1);
77595 l_accrual_line_num            NUMBER;
77596 l_tmp_amt                     NUMBER;
77597 l_acc_rev_natural_side_code   VARCHAR2(1);
77598 
77599 l_num_entries                 NUMBER;
77600 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
77601 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
77602 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
77603 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
77604 l_recog_line_1                NUMBER;
77605 l_recog_line_2                NUMBER;
77606 
77607 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
77608 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
77609 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
77610 
77611 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
77612 
77613 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
77617 
77614 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
77615 
77616 ---------------------------------------------------------------------------------------------------------------
77618 
77619 --
77620 -- bulk performance
77621 --
77622 l_balance_type_code           VARCHAR2(1);
77623 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
77624 l_log_module                  VARCHAR2(240);
77625 
77626 --
77627 -- Upgrade strategy
77628 --
77629 l_actual_upg_option           VARCHAR2(1);
77630 l_enc_upg_option           VARCHAR2(1);
77631 
77632 --
77633 BEGIN
77634 --
77635 IF g_log_enabled THEN
77636       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_262';
77637 END IF;
77638 --
77639 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
77640 
77641       trace
77642          (p_msg      => 'BEGIN of AcctLineType_262'
77643          ,p_level    => C_LEVEL_PROCEDURE
77644          ,p_module   => l_log_module);
77645 
77646 END IF;
77647 --
77648 l_component_type             := 'AMB_JLT';
77649 l_component_code             := 'FA_NBV_RETIRED_GAIN';
77650 l_component_type_code        := 'S';
77651 l_component_appl_id          :=  140;
77652 l_amb_context_code           := 'DEFAULT';
77653 l_entity_code                := 'TRANSACTIONS';
77654 l_event_class_code           := 'RETIREMENTS';
77655 l_event_type_code            := 'REINSTATEMENTS';
77656 l_line_definition_owner_code := 'S';
77657 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
77658 --
77659 l_balance_type_code          := 'A';
77660 l_segment                     := NULL;
77661 l_ccid                        := NULL;
77662 l_adr_transaction_coa_id      := NULL;
77663 l_adr_accounting_coa_id       := NULL;
77664 l_adr_flexfield_segment_code  := NULL;
77665 l_adr_flex_value_set_id       := NULL;
77666 l_adr_value_type_code         := NULL;
77667 l_adr_value_combination_id    := NULL;
77668 l_adr_value_segment_code      := NULL;
77669 
77670 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
77671 l_bflow_class_code           := '';    -- 4219869 Business Flow
77672 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
77673 l_budgetary_control_flag     := 'N';
77674 
77675 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
77676 l_bflow_applied_to_amt       := NULL; -- 5132302
77677 l_entered_amt_idx            := NULL;          -- 4262811
77678 l_accted_amt_idx             := NULL;          -- 4262811
77679 l_acc_rev_flag               := NULL;          -- 4262811
77680 l_accrual_line_num           := NULL;          -- 4262811
77681 l_tmp_amt                    := NULL;          -- 4262811
77682 --
77683  
77684 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
77685     l_balance_type_code <> 'B' THEN
77686 IF NVL(p_source_35,'
77687 ') =  'NBV RETIRED' AND 
77688 p_source_41 >=  0
77689  THEN 
77690 
77691    --
77692    XLA_AE_LINES_PKG.SetNewLine;
77693 
77694    p_balance_type_code          := l_balance_type_code;
77695    -- set the flag so later we will know whether the gain loss line needs to be created
77696    
77697    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
77698      p_actual_flag :='A';
77699    END IF;
77700 
77701    --
77702    -- bulk performance
77703    --
77704    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
77705                                       p_header_num   => 0); -- 4262811
77706    --
77707    -- set accounting line options
77708    --
77709    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
77710            p_natural_side_code          => 'D'
77711          , p_gain_or_loss_flag          => 'N'
77712          , p_gl_transfer_mode_code      => 'S'
77713          , p_acct_entry_type_code       => 'A'
77714          , p_switch_side_flag           => 'Y'
77715          , p_merge_duplicate_code       => 'N'
77716          );
77717    --
77718    l_acc_rev_natural_side_code := 'C';  -- 4262811
77719    -- 
77720    --
77721    -- set accounting line type info
77722    --
77723    xla_ae_lines_pkg.SetAcctLineType
77724       (p_component_type             => l_component_type
77725       ,p_event_type_code            => l_event_type_code
77726       ,p_line_definition_owner_code => l_line_definition_owner_code
77727       ,p_line_definition_code       => l_line_definition_code
77728       ,p_accounting_line_code       => l_component_code
77729       ,p_accounting_line_type_code  => l_component_type_code
77730       ,p_accounting_line_appl_id    => l_component_appl_id
77731       ,p_amb_context_code           => l_amb_context_code
77732       ,p_entity_code                => l_entity_code
77733       ,p_event_class_code           => l_event_class_code);
77734    --
77735    -- set accounting class
77736    --
77737    xla_ae_lines_pkg.SetAcctClass(
77738            p_accounting_class_code  => 'ASSET'
77739          , p_ae_header_id           => l_ae_header_id
77740          );
77741 
77742    --
77743    -- set rounding class
77744    --
77745    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
77746                       'ASSET';
77747 
77748    --
77749    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
77750    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
77751    --
77752    -- bulk performance
77753    --
77754    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
77755 
77756    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
77757       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
77758 
77762 
77759    -- 4955764
77760    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
77761       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
77763    -- 4458381 Public Sector Enh
77764    
77765    --
77766    -- set accounting attributes for the line type
77767    --
77768    l_entered_amt_idx := 4;
77769    l_accted_amt_idx  := 6;
77770    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
77771    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
77772    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
77773    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
77774    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
77775    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
77776    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
77777    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
77778    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
77779    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
77780    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
77781    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
77782    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
77783 
77784    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
77785    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
77786 
77787    ---------------------------------------------------------------------------------------------------------------
77788    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
77789    ---------------------------------------------------------------------------------------------------------------
77790    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
77791 
77792    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
77793    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
77794 
77795    IF xla_accounting_cache_pkg.GetValueChar
77796          (p_source_code         => 'LEDGER_CATEGORY_CODE'
77797          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
77798    AND l_bflow_method_code = 'PRIOR_ENTRY'
77799 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
77800    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
77801          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
77802        )
77803    THEN
77804          xla_ae_lines_pkg.BflowUpgEntry
77805            (p_business_method_code    => l_bflow_method_code
77806            ,p_business_class_code     => l_bflow_class_code
77807            ,p_balance_type            => l_balance_type_code);
77808    ELSE
77809       NULL;
77810 -- No business flow processing for business flow method of NONE.
77811    END IF;
77812 
77813    --
77814    -- call analytical criteria
77815    --
77816    
77817    --
77818    -- call description
77819    --
77820    
77821 xla_ae_lines_pkg.SetLineDescription(
77822    p_ae_header_id => l_ae_header_id
77823   ,p_description  => Description_80 (
77824      p_application_id         => p_application_id
77825    , p_ae_header_id           => l_ae_header_id 
77826 , p_source_1 => p_source_1
77827    )
77828 );
77829 
77830 
77831    --
77832    -- call ADRs
77833    -- Bug 4922099
77834    --
77835    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
77836         (NVL(l_actual_upg_option, 'N') = 'O') OR
77837         (NVL(l_enc_upg_option, 'N') = 'O')
77838       )
77839    THEN
77840    NULL;
77841    --
77842    --
77843    
77844   l_ccid := AcctDerRule_173(
77845            p_application_id           => p_application_id
77846          , p_ae_header_id             => l_ae_header_id 
77847 , p_source_3 => p_source_3
77848 , p_source_30 => p_source_30
77849          , x_transaction_coa_id       => l_adr_transaction_coa_id
77850          , x_accounting_coa_id        => l_adr_accounting_coa_id
77851          , x_value_type_code          => l_adr_value_type_code
77852          , p_side                     => 'NA'
77853    );
77854 
77855    xla_ae_lines_pkg.set_ccid(
77856     p_code_combination_id          => l_ccid
77857   , p_value_type_code              => l_adr_value_type_code
77858   , p_transaction_coa_id           => l_adr_transaction_coa_id
77859   , p_accounting_coa_id            => l_adr_accounting_coa_id
77860   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
77861   , p_adr_type_code                => 'S'
77862   , p_component_type               => l_component_type
77863   , p_component_code               => l_component_code
77864   , p_component_type_code          => l_component_type_code
77865   , p_component_appl_id            => l_component_appl_id
77866   , p_amb_context_code             => l_amb_context_code
77867   , p_side                         => 'NA'
77868   );
77869 
77870 
77871    l_segment := AcctDerRule_168(
77872            p_application_id           => p_application_id
77873          , p_ae_header_id             => l_ae_header_id 
77874 , p_source_3 => p_source_3
77875 , p_source_29 => p_source_29
77876          , x_transaction_coa_id       => l_adr_transaction_coa_id
77877          , x_accounting_coa_id        => l_adr_accounting_coa_id
77878          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
77879          , x_flex_value_set_id        => l_adr_flex_value_set_id
77880          , x_value_type_code          => l_adr_value_type_code
77881          , x_value_combination_id     => l_adr_value_combination_id
77882          , x_value_segment_code       => l_adr_value_segment_code
77883          , p_side                     => 'NA'
77887    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
77884          , p_override_seg_flag        => 'Y'
77885    );
77886 
77888 
77889       xla_ae_lines_pkg.set_segment(
77890           p_to_segment_code         => 'GL_BALANCING'
77891         , p_segment_value           => l_segment
77892         , p_from_segment_code       => l_adr_value_segment_code
77893         , p_from_combination_id     => l_adr_value_combination_id
77894         , p_value_type_code         => l_adr_value_type_code
77895         , p_transaction_coa_id      => l_adr_transaction_coa_id
77896         , p_accounting_coa_id       => l_adr_accounting_coa_id
77897         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
77898         , p_flex_value_set_id       => l_adr_flex_value_set_id
77899         , p_adr_code                => 'FA_EXPENSE_ACCT'
77900         , p_adr_type_code           => 'S'
77901         , p_component_type          => l_component_type
77902         , p_component_code          => l_component_code
77903         , p_component_type_code     => l_component_type_code
77904         , p_component_appl_id       => l_component_appl_id
77905         , p_amb_context_code        => l_amb_context_code
77906         , p_entity_code             => 'TRANSACTIONS'
77907         , p_event_class_code        => 'RETIREMENTS'
77908         , p_side                    => 'NA'
77909         );
77910 
77911   END IF;
77912 
77913    l_segment := AcctDerRule_159(
77914            p_application_id           => p_application_id
77915          , p_ae_header_id             => l_ae_header_id 
77916 , p_source_3 => p_source_3
77917 , p_source_21 => p_source_21
77918          , x_transaction_coa_id       => l_adr_transaction_coa_id
77919          , x_accounting_coa_id        => l_adr_accounting_coa_id
77920          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
77921          , x_flex_value_set_id        => l_adr_flex_value_set_id
77922          , x_value_type_code          => l_adr_value_type_code
77923          , x_value_combination_id     => l_adr_value_combination_id
77924          , x_value_segment_code       => l_adr_value_segment_code
77925          , p_side                     => 'NA'
77926          , p_override_seg_flag        => 'Y'
77927    );
77928 
77929    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
77930 
77931       xla_ae_lines_pkg.set_segment(
77932           p_to_segment_code         => 'GL_ACCOUNT'
77933         , p_segment_value           => l_segment
77934         , p_from_segment_code       => l_adr_value_segment_code
77935         , p_from_combination_id     => l_adr_value_combination_id
77936         , p_value_type_code         => l_adr_value_type_code
77937         , p_transaction_coa_id      => l_adr_transaction_coa_id
77938         , p_accounting_coa_id       => l_adr_accounting_coa_id
77939         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
77940         , p_flex_value_set_id       => l_adr_flex_value_set_id
77941         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
77942         , p_adr_type_code           => 'S'
77943         , p_component_type          => l_component_type
77944         , p_component_code          => l_component_code
77945         , p_component_type_code     => l_component_type_code
77946         , p_component_appl_id       => l_component_appl_id
77947         , p_amb_context_code        => l_amb_context_code
77948         , p_entity_code             => 'TRANSACTIONS'
77949         , p_event_class_code        => 'RETIREMENTS'
77950         , p_side                    => 'NA'
77951         );
77952 
77953   END IF;
77954 
77955    --
77956    --
77957    END IF;
77958    --
77959    -- Bug 4922099
77960    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
77961           (NVL(l_enc_upg_option, 'N') = 'O')
77962         ) AND
77963         (l_bflow_method_code = 'PRIOR_ENTRY')
77964       )
77965    THEN
77966       IF
77967       --
77968       1 = 2
77969       --
77970       THEN
77971       xla_accounting_err_pkg.build_message
77972                                     (p_appli_s_name            => 'XLA'
77973                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
77974                                     ,p_token_1                 => 'LINE_NUMBER'
77975                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
77976                                     ,p_token_2                 => 'LINE_TYPE_NAME'
77977                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
77978                                                                              l_component_type
77979                                                                             ,l_component_code
77980                                                                             ,l_component_type_code
77981                                                                             ,l_component_appl_id
77982                                                                             ,l_amb_context_code
77983                                                                             ,l_entity_code
77984                                                                             ,l_event_class_code
77985                                                                            )
77986                                     ,p_token_3                 => 'OWNER'
77987                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
77988                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
77989                                                                           ,p_lookup_code    => l_component_type_code
77990                                                                          )
77991                                     ,p_token_4                 => 'PRODUCT_NAME'
77992                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
77996                                     ,p_ae_header_id            =>  NULL
77993                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
77994                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
77995                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
77997                                        );
77998 
77999         IF (C_LEVEL_ERROR>= g_log_level) THEN
78000                  trace
78001                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
78002                       ,p_level    => C_LEVEL_ERROR
78003                       ,p_module   => l_log_module);
78004         END IF;
78005       END IF;
78006    END IF;
78007    --
78008    --
78009    ------------------------------------------------------------------------------------------------
78010    -- 4219869 Business Flow
78011    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
78012    -- Prior Entry.  Currently, the following code is always generated.
78013    ------------------------------------------------------------------------------------------------
78014    XLA_AE_LINES_PKG.ValidateCurrentLine;
78015 
78016    ------------------------------------------------------------------------------------
78017    -- 4219869 Business Flow
78018    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
78019    ------------------------------------------------------------------------------------
78020    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
78021 
78022    ----------------------------------------------------------------------------------
78023    -- 4219869 Business Flow
78024    -- Update journal entry status -- Need to generate this within IF <condition>
78025    ----------------------------------------------------------------------------------
78026    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
78027          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
78028          ,p_balance_type_code => l_balance_type_code
78029          );
78030 
78031    -------------------------------------------------------------------------------------------
78032    -- 4262811 - Generate the Accrual Reversal lines
78033    -------------------------------------------------------------------------------------------
78034    BEGIN
78035       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
78036                               (g_array_event(p_event_id).array_value_num('header_index'));
78037       IF l_acc_rev_flag IS NULL THEN
78038          l_acc_rev_flag := 'N';
78039       END IF;
78040    EXCEPTION
78041       WHEN OTHERS THEN
78042          l_acc_rev_flag := 'N';
78043    END;
78044    --
78045    IF (l_acc_rev_flag = 'Y') THEN
78046 
78047        -- 4645092  ------------------------------------------------------------------------------
78048        -- To allow MPA report to determine if it should generate report process
78049        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
78050        ------------------------------------------------------------------------------------------
78051 
78052        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
78053        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
78054    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
78055    -- call ADRs
78056    -- Bug 4922099
78057    --
78058    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
78059         (NVL(l_actual_upg_option, 'N') = 'O') OR
78060         (NVL(l_enc_upg_option, 'N') = 'O')
78061       )
78062    THEN
78063    NULL;
78064    --
78065    --
78066    
78067   l_ccid := AcctDerRule_173(
78068            p_application_id           => p_application_id
78069          , p_ae_header_id             => l_ae_header_id 
78070 , p_source_3 => p_source_3
78071 , p_source_30 => p_source_30
78072          , x_transaction_coa_id       => l_adr_transaction_coa_id
78073          , x_accounting_coa_id        => l_adr_accounting_coa_id
78074          , x_value_type_code          => l_adr_value_type_code
78075          , p_side                     => 'NA'
78076    );
78077 
78078    xla_ae_lines_pkg.set_ccid(
78079     p_code_combination_id          => l_ccid
78080   , p_value_type_code              => l_adr_value_type_code
78081   , p_transaction_coa_id           => l_adr_transaction_coa_id
78082   , p_accounting_coa_id            => l_adr_accounting_coa_id
78083   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
78084   , p_adr_type_code                => 'S'
78085   , p_component_type               => l_component_type
78086   , p_component_code               => l_component_code
78087   , p_component_type_code          => l_component_type_code
78088   , p_component_appl_id            => l_component_appl_id
78089   , p_amb_context_code             => l_amb_context_code
78090   , p_side                         => 'NA'
78091   );
78092 
78093 
78094    l_segment := AcctDerRule_168(
78095            p_application_id           => p_application_id
78096          , p_ae_header_id             => l_ae_header_id 
78097 , p_source_3 => p_source_3
78098 , p_source_29 => p_source_29
78099          , x_transaction_coa_id       => l_adr_transaction_coa_id
78100          , x_accounting_coa_id        => l_adr_accounting_coa_id
78101          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
78102          , x_flex_value_set_id        => l_adr_flex_value_set_id
78103          , x_value_type_code          => l_adr_value_type_code
78104          , x_value_combination_id     => l_adr_value_combination_id
78105          , x_value_segment_code       => l_adr_value_segment_code
78106          , p_side                     => 'NA'
78107          , p_override_seg_flag        => 'Y'
78108    );
78109 
78110    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
78114         , p_segment_value           => l_segment
78111 
78112       xla_ae_lines_pkg.set_segment(
78113           p_to_segment_code         => 'GL_BALANCING'
78115         , p_from_segment_code       => l_adr_value_segment_code
78116         , p_from_combination_id     => l_adr_value_combination_id
78117         , p_value_type_code         => l_adr_value_type_code
78118         , p_transaction_coa_id      => l_adr_transaction_coa_id
78119         , p_accounting_coa_id       => l_adr_accounting_coa_id
78120         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
78121         , p_flex_value_set_id       => l_adr_flex_value_set_id
78122         , p_adr_code                => 'FA_EXPENSE_ACCT'
78123         , p_adr_type_code           => 'S'
78124         , p_component_type          => l_component_type
78125         , p_component_code          => l_component_code
78126         , p_component_type_code     => l_component_type_code
78127         , p_component_appl_id       => l_component_appl_id
78128         , p_amb_context_code        => l_amb_context_code
78129         , p_entity_code             => 'TRANSACTIONS'
78130         , p_event_class_code        => 'RETIREMENTS'
78131         , p_side                    => 'NA'
78132         );
78133 
78134   END IF;
78135 
78136    l_segment := AcctDerRule_159(
78137            p_application_id           => p_application_id
78138          , p_ae_header_id             => l_ae_header_id 
78139 , p_source_3 => p_source_3
78140 , p_source_21 => p_source_21
78141          , x_transaction_coa_id       => l_adr_transaction_coa_id
78142          , x_accounting_coa_id        => l_adr_accounting_coa_id
78143          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
78144          , x_flex_value_set_id        => l_adr_flex_value_set_id
78145          , x_value_type_code          => l_adr_value_type_code
78146          , x_value_combination_id     => l_adr_value_combination_id
78147          , x_value_segment_code       => l_adr_value_segment_code
78148          , p_side                     => 'NA'
78149          , p_override_seg_flag        => 'Y'
78150    );
78151 
78152    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
78153 
78154       xla_ae_lines_pkg.set_segment(
78155           p_to_segment_code         => 'GL_ACCOUNT'
78156         , p_segment_value           => l_segment
78157         , p_from_segment_code       => l_adr_value_segment_code
78158         , p_from_combination_id     => l_adr_value_combination_id
78159         , p_value_type_code         => l_adr_value_type_code
78160         , p_transaction_coa_id      => l_adr_transaction_coa_id
78161         , p_accounting_coa_id       => l_adr_accounting_coa_id
78162         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
78163         , p_flex_value_set_id       => l_adr_flex_value_set_id
78164         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
78165         , p_adr_type_code           => 'S'
78166         , p_component_type          => l_component_type
78167         , p_component_code          => l_component_code
78168         , p_component_type_code     => l_component_type_code
78169         , p_component_appl_id       => l_component_appl_id
78170         , p_amb_context_code        => l_amb_context_code
78171         , p_entity_code             => 'TRANSACTIONS'
78172         , p_event_class_code        => 'RETIREMENTS'
78173         , p_side                    => 'NA'
78174         );
78175 
78176   END IF;
78177 
78178    --
78179    --
78180    END IF;
78181 
78182        --
78183        -- Update the line information that should be overwritten
78184        --
78185        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
78186                                          p_header_num   => 1);
78187        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
78188 
78189        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
78190 
78191        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
78192           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
78193        END IF;
78194 
78195       --
78196       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
78197       --
78198       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
78199           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
78200       ELSE
78201           ---------------------------------------------------------------------------------------------------
78202           -- 4262811a Switch Sign
78203           ---------------------------------------------------------------------------------------------------
78204           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
78205           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
78206                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
78207           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
78208                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
78209           -- 5132302
78210           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
78211                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
78212 
78213       END IF;
78214 
78215       -- 4955764
78216       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
78217       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
78218 
78219 
78220       XLA_AE_LINES_PKG.ValidateCurrentLine;
78221       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
78222 
78226 
78223       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
78224                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
78225                ,p_balance_type_code => l_balance_type_code);
78227    END IF;
78228 
78229    -----------------------------------------------------------------------------------------
78230    -- 4262811 Multiperiod Accounting
78231    -----------------------------------------------------------------------------------------
78232      -- No MPA option is assigned.
78233 
78234 
78235 END IF;
78236 END IF;
78237 --
78238 
78239 --
78240 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
78241    trace
78242       (p_msg      => 'END of AcctLineType_262'
78243       ,p_level    => C_LEVEL_PROCEDURE
78244       ,p_module   => l_log_module);
78245 END IF;
78246 --
78247 EXCEPTION
78248   WHEN xla_exceptions_pkg.application_exception THEN
78249       RAISE;
78250   WHEN OTHERS THEN
78251        xla_exceptions_pkg.raise_message
78252            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_262');
78253 END AcctLineType_262;
78254 --
78255 
78256 ---------------------------------------
78257 --
78258 -- PRIVATE FUNCTION
78259 --         AcctLineType_263
78260 --
78261 ---------------------------------------
78262 PROCEDURE AcctLineType_263 (
78263   p_application_id        IN NUMBER
78264  ,p_event_id              IN NUMBER
78265  ,p_calculate_acctd_flag  IN VARCHAR2
78266  ,p_calculate_g_l_flag    IN VARCHAR2
78267  ,p_actual_flag           IN OUT VARCHAR2
78268  ,p_balance_type_code     OUT VARCHAR2
78269  ,p_gain_or_loss_ref      OUT VARCHAR2
78270  
78271 --Period Close Date
78272  , p_source_1            IN DATE
78273 --Generated Code Combination Identifier
78274  , p_source_3            IN NUMBER
78275 --Net Book Value Retired Loss Account
78276  , p_source_22            IN VARCHAR2
78277 --Expense Account Code Combination Identifier
78278  , p_source_29            IN NUMBER
78279 --Default Code Combination Identifier
78280  , p_source_30            IN NUMBER
78281 --Adjustment Type
78282  , p_source_35            IN VARCHAR2
78283 --Transaction Header Identifier
78284  , p_source_36            IN NUMBER
78285 --Adjustment Line Identifier
78286  , p_source_37            IN NUMBER
78287 --Distribution Type Code
78288  , p_source_38            IN VARCHAR2
78289 --Entered Amount
78290  , p_source_39            IN NUMBER
78291 --Currency Code
78292  , p_source_40            IN VARCHAR2
78293 --Gain Loss Amount
78294  , p_source_41            IN NUMBER
78295 )
78296 IS
78297 
78298 l_component_type              VARCHAR2(80);
78299 l_component_code              VARCHAR2(30);
78300 l_component_type_code         VARCHAR2(1);
78301 l_component_appl_id           INTEGER;
78302 l_amb_context_code            VARCHAR2(30);
78303 l_entity_code                 VARCHAR2(30);
78304 l_event_class_code            VARCHAR2(30);
78305 l_ae_header_id                NUMBER;
78306 l_event_type_code             VARCHAR2(30);
78307 l_line_definition_code        VARCHAR2(30);
78308 l_line_definition_owner_code  VARCHAR2(1);
78309 --
78310 -- adr variables
78311 l_segment                     VARCHAR2(30);
78312 l_ccid                        NUMBER;
78313 l_adr_transaction_coa_id      NUMBER;
78314 l_adr_accounting_coa_id       NUMBER;
78315 l_adr_flexfield_segment_code  VARCHAR2(30);
78316 l_adr_flex_value_set_id       NUMBER;
78317 l_adr_value_type_code         VARCHAR2(30);
78318 l_adr_value_combination_id    NUMBER;
78319 l_adr_value_segment_code      VARCHAR2(30);
78320 
78321 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
78322 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
78323 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
78324 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
78325 
78326 -- 4262811 Variables ------------------------------------------------------------------------------------------
78327 l_entered_amt_idx             NUMBER;
78328 l_accted_amt_idx              NUMBER;
78329 l_acc_rev_flag                VARCHAR2(1);
78330 l_accrual_line_num            NUMBER;
78331 l_tmp_amt                     NUMBER;
78332 l_acc_rev_natural_side_code   VARCHAR2(1);
78333 
78334 l_num_entries                 NUMBER;
78335 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
78336 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
78337 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
78338 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
78339 l_recog_line_1                NUMBER;
78340 l_recog_line_2                NUMBER;
78341 
78342 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
78343 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
78344 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
78345 
78346 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
78347 
78348 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
78349 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
78350 
78351 ---------------------------------------------------------------------------------------------------------------
78352 
78353 
78354 --
78355 -- bulk performance
78356 --
78357 l_balance_type_code           VARCHAR2(1);
78358 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
78359 l_log_module                  VARCHAR2(240);
78360 
78361 --
78362 -- Upgrade strategy
78363 --
78364 l_actual_upg_option           VARCHAR2(1);
78365 l_enc_upg_option           VARCHAR2(1);
78366 
78367 --
78371       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_263';
78368 BEGIN
78369 --
78370 IF g_log_enabled THEN
78372 END IF;
78373 --
78374 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
78375 
78376       trace
78377          (p_msg      => 'BEGIN of AcctLineType_263'
78378          ,p_level    => C_LEVEL_PROCEDURE
78379          ,p_module   => l_log_module);
78380 
78381 END IF;
78382 --
78383 l_component_type             := 'AMB_JLT';
78384 l_component_code             := 'FA_NBV_RETIRED_LOSS';
78385 l_component_type_code        := 'S';
78386 l_component_appl_id          :=  140;
78387 l_amb_context_code           := 'DEFAULT';
78388 l_entity_code                := 'TRANSACTIONS';
78389 l_event_class_code           := 'RETIREMENTS';
78390 l_event_type_code            := 'RETIREMENTS';
78391 l_line_definition_owner_code := 'S';
78392 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
78393 --
78394 l_balance_type_code          := 'A';
78395 l_segment                     := NULL;
78396 l_ccid                        := NULL;
78397 l_adr_transaction_coa_id      := NULL;
78398 l_adr_accounting_coa_id       := NULL;
78399 l_adr_flexfield_segment_code  := NULL;
78400 l_adr_flex_value_set_id       := NULL;
78401 l_adr_value_type_code         := NULL;
78402 l_adr_value_combination_id    := NULL;
78403 l_adr_value_segment_code      := NULL;
78404 
78405 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
78406 l_bflow_class_code           := '';    -- 4219869 Business Flow
78407 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
78408 l_budgetary_control_flag     := 'N';
78409 
78410 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
78411 l_bflow_applied_to_amt       := NULL; -- 5132302
78412 l_entered_amt_idx            := NULL;          -- 4262811
78413 l_accted_amt_idx             := NULL;          -- 4262811
78414 l_acc_rev_flag               := NULL;          -- 4262811
78415 l_accrual_line_num           := NULL;          -- 4262811
78416 l_tmp_amt                    := NULL;          -- 4262811
78417 --
78418  
78419 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
78420     l_balance_type_code <> 'B' THEN
78421 IF NVL(p_source_35,'
78422 ') =  'NBV RETIRED' AND 
78423 p_source_41 <  0
78424  THEN 
78425 
78426    --
78427    XLA_AE_LINES_PKG.SetNewLine;
78428 
78429    p_balance_type_code          := l_balance_type_code;
78430    -- set the flag so later we will know whether the gain loss line needs to be created
78431    
78432    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
78433      p_actual_flag :='A';
78434    END IF;
78435 
78436    --
78437    -- bulk performance
78438    --
78439    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
78440                                       p_header_num   => 0); -- 4262811
78441    --
78442    -- set accounting line options
78443    --
78444    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
78445            p_natural_side_code          => 'D'
78446          , p_gain_or_loss_flag          => 'N'
78447          , p_gl_transfer_mode_code      => 'S'
78448          , p_acct_entry_type_code       => 'A'
78449          , p_switch_side_flag           => 'Y'
78450          , p_merge_duplicate_code       => 'N'
78451          );
78452    --
78453    l_acc_rev_natural_side_code := 'C';  -- 4262811
78454    -- 
78455    --
78456    -- set accounting line type info
78457    --
78458    xla_ae_lines_pkg.SetAcctLineType
78459       (p_component_type             => l_component_type
78460       ,p_event_type_code            => l_event_type_code
78461       ,p_line_definition_owner_code => l_line_definition_owner_code
78462       ,p_line_definition_code       => l_line_definition_code
78463       ,p_accounting_line_code       => l_component_code
78464       ,p_accounting_line_type_code  => l_component_type_code
78465       ,p_accounting_line_appl_id    => l_component_appl_id
78466       ,p_amb_context_code           => l_amb_context_code
78467       ,p_entity_code                => l_entity_code
78468       ,p_event_class_code           => l_event_class_code);
78469    --
78470    -- set accounting class
78471    --
78472    xla_ae_lines_pkg.SetAcctClass(
78473            p_accounting_class_code  => 'ASSET'
78474          , p_ae_header_id           => l_ae_header_id
78475          );
78476 
78477    --
78478    -- set rounding class
78479    --
78480    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
78481                       'ASSET';
78482 
78483    --
78484    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
78485    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
78486    --
78487    -- bulk performance
78488    --
78489    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
78490 
78491    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
78492       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
78493 
78494    -- 4955764
78495    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
78496       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
78497 
78498    -- 4458381 Public Sector Enh
78499    
78500    --
78501    -- set accounting attributes for the line type
78502    --
78503    l_entered_amt_idx := 4;
78504    l_accted_amt_idx  := 6;
78505    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
78506    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
78507    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
78511    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
78508    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
78509    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
78510    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
78512    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
78513    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
78514    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
78515    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
78516    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
78517    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
78518 
78519    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
78520    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
78521 
78522    ---------------------------------------------------------------------------------------------------------------
78523    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
78524    ---------------------------------------------------------------------------------------------------------------
78525    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
78526 
78527    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
78528    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
78529 
78530    IF xla_accounting_cache_pkg.GetValueChar
78531          (p_source_code         => 'LEDGER_CATEGORY_CODE'
78532          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
78533    AND l_bflow_method_code = 'PRIOR_ENTRY'
78534 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
78535    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
78536          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
78537        )
78538    THEN
78539          xla_ae_lines_pkg.BflowUpgEntry
78540            (p_business_method_code    => l_bflow_method_code
78541            ,p_business_class_code     => l_bflow_class_code
78542            ,p_balance_type            => l_balance_type_code);
78543    ELSE
78544       NULL;
78545 -- No business flow processing for business flow method of NONE.
78546    END IF;
78547 
78548    --
78549    -- call analytical criteria
78550    --
78551    
78552    --
78553    -- call description
78554    --
78555    
78556 xla_ae_lines_pkg.SetLineDescription(
78557    p_ae_header_id => l_ae_header_id
78558   ,p_description  => Description_80 (
78559      p_application_id         => p_application_id
78560    , p_ae_header_id           => l_ae_header_id 
78561 , p_source_1 => p_source_1
78562    )
78563 );
78564 
78565 
78566    --
78567    -- call ADRs
78568    -- Bug 4922099
78569    --
78570    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
78571         (NVL(l_actual_upg_option, 'N') = 'O') OR
78572         (NVL(l_enc_upg_option, 'N') = 'O')
78573       )
78574    THEN
78575    NULL;
78576    --
78577    --
78578    
78579   l_ccid := AcctDerRule_173(
78580            p_application_id           => p_application_id
78581          , p_ae_header_id             => l_ae_header_id 
78582 , p_source_3 => p_source_3
78583 , p_source_30 => p_source_30
78584          , x_transaction_coa_id       => l_adr_transaction_coa_id
78585          , x_accounting_coa_id        => l_adr_accounting_coa_id
78586          , x_value_type_code          => l_adr_value_type_code
78587          , p_side                     => 'NA'
78588    );
78589 
78590    xla_ae_lines_pkg.set_ccid(
78591     p_code_combination_id          => l_ccid
78592   , p_value_type_code              => l_adr_value_type_code
78593   , p_transaction_coa_id           => l_adr_transaction_coa_id
78594   , p_accounting_coa_id            => l_adr_accounting_coa_id
78595   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
78596   , p_adr_type_code                => 'S'
78597   , p_component_type               => l_component_type
78598   , p_component_code               => l_component_code
78599   , p_component_type_code          => l_component_type_code
78600   , p_component_appl_id            => l_component_appl_id
78601   , p_amb_context_code             => l_amb_context_code
78602   , p_side                         => 'NA'
78603   );
78604 
78605 
78606    l_segment := AcctDerRule_168(
78607            p_application_id           => p_application_id
78608          , p_ae_header_id             => l_ae_header_id 
78609 , p_source_3 => p_source_3
78610 , p_source_29 => p_source_29
78611          , x_transaction_coa_id       => l_adr_transaction_coa_id
78612          , x_accounting_coa_id        => l_adr_accounting_coa_id
78613          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
78614          , x_flex_value_set_id        => l_adr_flex_value_set_id
78615          , x_value_type_code          => l_adr_value_type_code
78616          , x_value_combination_id     => l_adr_value_combination_id
78617          , x_value_segment_code       => l_adr_value_segment_code
78618          , p_side                     => 'NA'
78619          , p_override_seg_flag        => 'Y'
78620    );
78621 
78622    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
78623 
78624       xla_ae_lines_pkg.set_segment(
78625           p_to_segment_code         => 'GL_BALANCING'
78626         , p_segment_value           => l_segment
78627         , p_from_segment_code       => l_adr_value_segment_code
78628         , p_from_combination_id     => l_adr_value_combination_id
78629         , p_value_type_code         => l_adr_value_type_code
78630         , p_transaction_coa_id      => l_adr_transaction_coa_id
78631         , p_accounting_coa_id       => l_adr_accounting_coa_id
78635         , p_adr_type_code           => 'S'
78632         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
78633         , p_flex_value_set_id       => l_adr_flex_value_set_id
78634         , p_adr_code                => 'FA_EXPENSE_ACCT'
78636         , p_component_type          => l_component_type
78637         , p_component_code          => l_component_code
78638         , p_component_type_code     => l_component_type_code
78639         , p_component_appl_id       => l_component_appl_id
78640         , p_amb_context_code        => l_amb_context_code
78641         , p_entity_code             => 'TRANSACTIONS'
78642         , p_event_class_code        => 'RETIREMENTS'
78643         , p_side                    => 'NA'
78644         );
78645 
78646   END IF;
78647 
78648    l_segment := AcctDerRule_160(
78649            p_application_id           => p_application_id
78650          , p_ae_header_id             => l_ae_header_id 
78651 , p_source_3 => p_source_3
78652 , p_source_22 => p_source_22
78653          , x_transaction_coa_id       => l_adr_transaction_coa_id
78654          , x_accounting_coa_id        => l_adr_accounting_coa_id
78655          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
78656          , x_flex_value_set_id        => l_adr_flex_value_set_id
78657          , x_value_type_code          => l_adr_value_type_code
78658          , x_value_combination_id     => l_adr_value_combination_id
78659          , x_value_segment_code       => l_adr_value_segment_code
78660          , p_side                     => 'NA'
78661          , p_override_seg_flag        => 'Y'
78662    );
78663 
78664    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
78665 
78666       xla_ae_lines_pkg.set_segment(
78667           p_to_segment_code         => 'GL_ACCOUNT'
78668         , p_segment_value           => l_segment
78669         , p_from_segment_code       => l_adr_value_segment_code
78670         , p_from_combination_id     => l_adr_value_combination_id
78671         , p_value_type_code         => l_adr_value_type_code
78672         , p_transaction_coa_id      => l_adr_transaction_coa_id
78673         , p_accounting_coa_id       => l_adr_accounting_coa_id
78674         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
78675         , p_flex_value_set_id       => l_adr_flex_value_set_id
78676         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
78677         , p_adr_type_code           => 'S'
78678         , p_component_type          => l_component_type
78679         , p_component_code          => l_component_code
78680         , p_component_type_code     => l_component_type_code
78681         , p_component_appl_id       => l_component_appl_id
78682         , p_amb_context_code        => l_amb_context_code
78683         , p_entity_code             => 'TRANSACTIONS'
78684         , p_event_class_code        => 'RETIREMENTS'
78685         , p_side                    => 'NA'
78686         );
78687 
78688   END IF;
78689 
78690    --
78691    --
78692    END IF;
78693    --
78694    -- Bug 4922099
78695    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
78696           (NVL(l_enc_upg_option, 'N') = 'O')
78697         ) AND
78698         (l_bflow_method_code = 'PRIOR_ENTRY')
78699       )
78700    THEN
78701       IF
78702       --
78703       1 = 2
78704       --
78705       THEN
78706       xla_accounting_err_pkg.build_message
78707                                     (p_appli_s_name            => 'XLA'
78708                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
78709                                     ,p_token_1                 => 'LINE_NUMBER'
78710                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
78711                                     ,p_token_2                 => 'LINE_TYPE_NAME'
78712                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
78713                                                                              l_component_type
78714                                                                             ,l_component_code
78715                                                                             ,l_component_type_code
78716                                                                             ,l_component_appl_id
78717                                                                             ,l_amb_context_code
78718                                                                             ,l_entity_code
78719                                                                             ,l_event_class_code
78720                                                                            )
78721                                     ,p_token_3                 => 'OWNER'
78722                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
78723                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
78724                                                                           ,p_lookup_code    => l_component_type_code
78725                                                                          )
78726                                     ,p_token_4                 => 'PRODUCT_NAME'
78727                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
78728                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
78729                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
78730                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
78731                                     ,p_ae_header_id            =>  NULL
78732                                        );
78733 
78734         IF (C_LEVEL_ERROR>= g_log_level) THEN
78735                  trace
78736                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
78740       END IF;
78737                       ,p_level    => C_LEVEL_ERROR
78738                       ,p_module   => l_log_module);
78739         END IF;
78741    END IF;
78742    --
78743    --
78744    ------------------------------------------------------------------------------------------------
78745    -- 4219869 Business Flow
78746    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
78747    -- Prior Entry.  Currently, the following code is always generated.
78748    ------------------------------------------------------------------------------------------------
78749    XLA_AE_LINES_PKG.ValidateCurrentLine;
78750 
78751    ------------------------------------------------------------------------------------
78752    -- 4219869 Business Flow
78753    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
78754    ------------------------------------------------------------------------------------
78755    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
78756 
78757    ----------------------------------------------------------------------------------
78758    -- 4219869 Business Flow
78759    -- Update journal entry status -- Need to generate this within IF <condition>
78760    ----------------------------------------------------------------------------------
78761    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
78762          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
78763          ,p_balance_type_code => l_balance_type_code
78764          );
78765 
78766    -------------------------------------------------------------------------------------------
78767    -- 4262811 - Generate the Accrual Reversal lines
78768    -------------------------------------------------------------------------------------------
78769    BEGIN
78770       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
78771                               (g_array_event(p_event_id).array_value_num('header_index'));
78772       IF l_acc_rev_flag IS NULL THEN
78773          l_acc_rev_flag := 'N';
78774       END IF;
78775    EXCEPTION
78776       WHEN OTHERS THEN
78777          l_acc_rev_flag := 'N';
78778    END;
78779    --
78780    IF (l_acc_rev_flag = 'Y') THEN
78781 
78782        -- 4645092  ------------------------------------------------------------------------------
78783        -- To allow MPA report to determine if it should generate report process
78784        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
78785        ------------------------------------------------------------------------------------------
78786 
78787        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
78788        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
78789    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
78790    -- call ADRs
78791    -- Bug 4922099
78792    --
78793    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
78794         (NVL(l_actual_upg_option, 'N') = 'O') OR
78795         (NVL(l_enc_upg_option, 'N') = 'O')
78796       )
78797    THEN
78798    NULL;
78799    --
78800    --
78801    
78802   l_ccid := AcctDerRule_173(
78803            p_application_id           => p_application_id
78804          , p_ae_header_id             => l_ae_header_id 
78805 , p_source_3 => p_source_3
78806 , p_source_30 => p_source_30
78807          , x_transaction_coa_id       => l_adr_transaction_coa_id
78808          , x_accounting_coa_id        => l_adr_accounting_coa_id
78809          , x_value_type_code          => l_adr_value_type_code
78810          , p_side                     => 'NA'
78811    );
78812 
78813    xla_ae_lines_pkg.set_ccid(
78814     p_code_combination_id          => l_ccid
78815   , p_value_type_code              => l_adr_value_type_code
78816   , p_transaction_coa_id           => l_adr_transaction_coa_id
78817   , p_accounting_coa_id            => l_adr_accounting_coa_id
78818   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
78819   , p_adr_type_code                => 'S'
78820   , p_component_type               => l_component_type
78821   , p_component_code               => l_component_code
78822   , p_component_type_code          => l_component_type_code
78823   , p_component_appl_id            => l_component_appl_id
78824   , p_amb_context_code             => l_amb_context_code
78825   , p_side                         => 'NA'
78826   );
78827 
78828 
78829    l_segment := AcctDerRule_168(
78830            p_application_id           => p_application_id
78831          , p_ae_header_id             => l_ae_header_id 
78832 , p_source_3 => p_source_3
78833 , p_source_29 => p_source_29
78834          , x_transaction_coa_id       => l_adr_transaction_coa_id
78835          , x_accounting_coa_id        => l_adr_accounting_coa_id
78836          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
78837          , x_flex_value_set_id        => l_adr_flex_value_set_id
78838          , x_value_type_code          => l_adr_value_type_code
78839          , x_value_combination_id     => l_adr_value_combination_id
78840          , x_value_segment_code       => l_adr_value_segment_code
78841          , p_side                     => 'NA'
78842          , p_override_seg_flag        => 'Y'
78843    );
78844 
78845    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
78846 
78847       xla_ae_lines_pkg.set_segment(
78848           p_to_segment_code         => 'GL_BALANCING'
78849         , p_segment_value           => l_segment
78850         , p_from_segment_code       => l_adr_value_segment_code
78851         , p_from_combination_id     => l_adr_value_combination_id
78852         , p_value_type_code         => l_adr_value_type_code
78853         , p_transaction_coa_id      => l_adr_transaction_coa_id
78854         , p_accounting_coa_id       => l_adr_accounting_coa_id
78855         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
78859         , p_component_type          => l_component_type
78856         , p_flex_value_set_id       => l_adr_flex_value_set_id
78857         , p_adr_code                => 'FA_EXPENSE_ACCT'
78858         , p_adr_type_code           => 'S'
78860         , p_component_code          => l_component_code
78861         , p_component_type_code     => l_component_type_code
78862         , p_component_appl_id       => l_component_appl_id
78863         , p_amb_context_code        => l_amb_context_code
78864         , p_entity_code             => 'TRANSACTIONS'
78865         , p_event_class_code        => 'RETIREMENTS'
78866         , p_side                    => 'NA'
78867         );
78868 
78869   END IF;
78870 
78871    l_segment := AcctDerRule_160(
78872            p_application_id           => p_application_id
78873          , p_ae_header_id             => l_ae_header_id 
78874 , p_source_3 => p_source_3
78875 , p_source_22 => p_source_22
78876          , x_transaction_coa_id       => l_adr_transaction_coa_id
78877          , x_accounting_coa_id        => l_adr_accounting_coa_id
78878          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
78879          , x_flex_value_set_id        => l_adr_flex_value_set_id
78880          , x_value_type_code          => l_adr_value_type_code
78881          , x_value_combination_id     => l_adr_value_combination_id
78882          , x_value_segment_code       => l_adr_value_segment_code
78883          , p_side                     => 'NA'
78884          , p_override_seg_flag        => 'Y'
78885    );
78886 
78887    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
78888 
78889       xla_ae_lines_pkg.set_segment(
78890           p_to_segment_code         => 'GL_ACCOUNT'
78891         , p_segment_value           => l_segment
78892         , p_from_segment_code       => l_adr_value_segment_code
78893         , p_from_combination_id     => l_adr_value_combination_id
78894         , p_value_type_code         => l_adr_value_type_code
78895         , p_transaction_coa_id      => l_adr_transaction_coa_id
78896         , p_accounting_coa_id       => l_adr_accounting_coa_id
78897         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
78898         , p_flex_value_set_id       => l_adr_flex_value_set_id
78899         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
78900         , p_adr_type_code           => 'S'
78901         , p_component_type          => l_component_type
78902         , p_component_code          => l_component_code
78903         , p_component_type_code     => l_component_type_code
78904         , p_component_appl_id       => l_component_appl_id
78905         , p_amb_context_code        => l_amb_context_code
78906         , p_entity_code             => 'TRANSACTIONS'
78907         , p_event_class_code        => 'RETIREMENTS'
78908         , p_side                    => 'NA'
78909         );
78910 
78911   END IF;
78912 
78913    --
78914    --
78915    END IF;
78916 
78917        --
78918        -- Update the line information that should be overwritten
78919        --
78920        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
78921                                          p_header_num   => 1);
78922        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
78923 
78924        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
78925 
78926        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
78927           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
78928        END IF;
78929 
78930       --
78931       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
78932       --
78933       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
78934           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
78935       ELSE
78936           ---------------------------------------------------------------------------------------------------
78937           -- 4262811a Switch Sign
78938           ---------------------------------------------------------------------------------------------------
78939           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
78940           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
78941                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
78942           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
78943                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
78944           -- 5132302
78945           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
78946                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
78947 
78948       END IF;
78949 
78950       -- 4955764
78951       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
78952       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
78953 
78954 
78955       XLA_AE_LINES_PKG.ValidateCurrentLine;
78956       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
78957 
78958       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
78959                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
78960                ,p_balance_type_code => l_balance_type_code);
78961 
78962    END IF;
78963 
78964    -----------------------------------------------------------------------------------------
78965    -- 4262811 Multiperiod Accounting
78966    -----------------------------------------------------------------------------------------
78967      -- No MPA option is assigned.
78968 
78969 
78973 
78970 END IF;
78971 END IF;
78972 --
78974 --
78975 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
78976    trace
78977       (p_msg      => 'END of AcctLineType_263'
78978       ,p_level    => C_LEVEL_PROCEDURE
78979       ,p_module   => l_log_module);
78980 END IF;
78981 --
78982 EXCEPTION
78983   WHEN xla_exceptions_pkg.application_exception THEN
78984       RAISE;
78985   WHEN OTHERS THEN
78986        xla_exceptions_pkg.raise_message
78987            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_263');
78988 END AcctLineType_263;
78989 --
78990 
78991 ---------------------------------------
78992 --
78993 -- PRIVATE FUNCTION
78994 --         AcctLineType_264
78995 --
78996 ---------------------------------------
78997 PROCEDURE AcctLineType_264 (
78998   p_application_id        IN NUMBER
78999  ,p_event_id              IN NUMBER
79000  ,p_calculate_acctd_flag  IN VARCHAR2
79001  ,p_calculate_g_l_flag    IN VARCHAR2
79002  ,p_actual_flag           IN OUT VARCHAR2
79003  ,p_balance_type_code     OUT VARCHAR2
79004  ,p_gain_or_loss_ref      OUT VARCHAR2
79005  
79006 --Period Close Date
79007  , p_source_1            IN DATE
79008 --Generated Code Combination Identifier
79009  , p_source_3            IN NUMBER
79010 --Net Book Value Retired Loss Account
79011  , p_source_22            IN VARCHAR2
79012 --Expense Account Code Combination Identifier
79013  , p_source_29            IN NUMBER
79014 --Default Code Combination Identifier
79015  , p_source_30            IN NUMBER
79016 --Adjustment Type
79017  , p_source_35            IN VARCHAR2
79018 --Transaction Header Identifier
79019  , p_source_36            IN NUMBER
79020 --Adjustment Line Identifier
79021  , p_source_37            IN NUMBER
79022 --Distribution Type Code
79023  , p_source_38            IN VARCHAR2
79024 --Entered Amount
79025  , p_source_39            IN NUMBER
79026 --Currency Code
79027  , p_source_40            IN VARCHAR2
79028 --Gain Loss Amount
79029  , p_source_41            IN NUMBER
79030 )
79031 IS
79032 
79033 l_component_type              VARCHAR2(80);
79034 l_component_code              VARCHAR2(30);
79035 l_component_type_code         VARCHAR2(1);
79036 l_component_appl_id           INTEGER;
79037 l_amb_context_code            VARCHAR2(30);
79038 l_entity_code                 VARCHAR2(30);
79039 l_event_class_code            VARCHAR2(30);
79040 l_ae_header_id                NUMBER;
79041 l_event_type_code             VARCHAR2(30);
79042 l_line_definition_code        VARCHAR2(30);
79043 l_line_definition_owner_code  VARCHAR2(1);
79044 --
79045 -- adr variables
79046 l_segment                     VARCHAR2(30);
79047 l_ccid                        NUMBER;
79048 l_adr_transaction_coa_id      NUMBER;
79049 l_adr_accounting_coa_id       NUMBER;
79050 l_adr_flexfield_segment_code  VARCHAR2(30);
79051 l_adr_flex_value_set_id       NUMBER;
79052 l_adr_value_type_code         VARCHAR2(30);
79053 l_adr_value_combination_id    NUMBER;
79054 l_adr_value_segment_code      VARCHAR2(30);
79055 
79056 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
79057 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
79058 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
79059 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
79060 
79061 -- 4262811 Variables ------------------------------------------------------------------------------------------
79062 l_entered_amt_idx             NUMBER;
79063 l_accted_amt_idx              NUMBER;
79064 l_acc_rev_flag                VARCHAR2(1);
79065 l_accrual_line_num            NUMBER;
79066 l_tmp_amt                     NUMBER;
79067 l_acc_rev_natural_side_code   VARCHAR2(1);
79068 
79069 l_num_entries                 NUMBER;
79070 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
79071 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
79072 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
79073 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
79074 l_recog_line_1                NUMBER;
79075 l_recog_line_2                NUMBER;
79076 
79077 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
79078 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
79079 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
79080 
79081 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
79082 
79083 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
79084 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
79085 
79086 ---------------------------------------------------------------------------------------------------------------
79087 
79088 
79089 --
79090 -- bulk performance
79091 --
79092 l_balance_type_code           VARCHAR2(1);
79093 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
79094 l_log_module                  VARCHAR2(240);
79095 
79096 --
79097 -- Upgrade strategy
79098 --
79099 l_actual_upg_option           VARCHAR2(1);
79100 l_enc_upg_option           VARCHAR2(1);
79101 
79102 --
79103 BEGIN
79104 --
79105 IF g_log_enabled THEN
79106       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_264';
79107 END IF;
79108 --
79109 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
79110 
79111       trace
79112          (p_msg      => 'BEGIN of AcctLineType_264'
79113          ,p_level    => C_LEVEL_PROCEDURE
79114          ,p_module   => l_log_module);
79115 
79116 END IF;
79117 --
79118 l_component_type             := 'AMB_JLT';
79119 l_component_code             := 'FA_NBV_RETIRED_LOSS';
79123 l_entity_code                := 'TRANSACTIONS';
79120 l_component_type_code        := 'S';
79121 l_component_appl_id          :=  140;
79122 l_amb_context_code           := 'DEFAULT';
79124 l_event_class_code           := 'RETIREMENTS';
79125 l_event_type_code            := 'REINSTATEMENTS';
79126 l_line_definition_owner_code := 'S';
79127 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
79128 --
79129 l_balance_type_code          := 'A';
79130 l_segment                     := NULL;
79131 l_ccid                        := NULL;
79132 l_adr_transaction_coa_id      := NULL;
79133 l_adr_accounting_coa_id       := NULL;
79134 l_adr_flexfield_segment_code  := NULL;
79135 l_adr_flex_value_set_id       := NULL;
79136 l_adr_value_type_code         := NULL;
79137 l_adr_value_combination_id    := NULL;
79138 l_adr_value_segment_code      := NULL;
79139 
79140 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
79141 l_bflow_class_code           := '';    -- 4219869 Business Flow
79142 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
79143 l_budgetary_control_flag     := 'N';
79144 
79145 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
79146 l_bflow_applied_to_amt       := NULL; -- 5132302
79147 l_entered_amt_idx            := NULL;          -- 4262811
79148 l_accted_amt_idx             := NULL;          -- 4262811
79149 l_acc_rev_flag               := NULL;          -- 4262811
79150 l_accrual_line_num           := NULL;          -- 4262811
79151 l_tmp_amt                    := NULL;          -- 4262811
79152 --
79153  
79154 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
79155     l_balance_type_code <> 'B' THEN
79156 IF NVL(p_source_35,'
79157 ') =  'NBV RETIRED' AND 
79158 p_source_41 <  0
79159  THEN 
79160 
79161    --
79162    XLA_AE_LINES_PKG.SetNewLine;
79163 
79164    p_balance_type_code          := l_balance_type_code;
79165    -- set the flag so later we will know whether the gain loss line needs to be created
79166    
79167    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
79168      p_actual_flag :='A';
79169    END IF;
79170 
79171    --
79172    -- bulk performance
79173    --
79174    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
79175                                       p_header_num   => 0); -- 4262811
79176    --
79177    -- set accounting line options
79178    --
79179    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
79180            p_natural_side_code          => 'D'
79181          , p_gain_or_loss_flag          => 'N'
79182          , p_gl_transfer_mode_code      => 'S'
79183          , p_acct_entry_type_code       => 'A'
79184          , p_switch_side_flag           => 'Y'
79185          , p_merge_duplicate_code       => 'N'
79186          );
79187    --
79188    l_acc_rev_natural_side_code := 'C';  -- 4262811
79189    -- 
79190    --
79191    -- set accounting line type info
79192    --
79193    xla_ae_lines_pkg.SetAcctLineType
79194       (p_component_type             => l_component_type
79195       ,p_event_type_code            => l_event_type_code
79196       ,p_line_definition_owner_code => l_line_definition_owner_code
79197       ,p_line_definition_code       => l_line_definition_code
79198       ,p_accounting_line_code       => l_component_code
79199       ,p_accounting_line_type_code  => l_component_type_code
79200       ,p_accounting_line_appl_id    => l_component_appl_id
79201       ,p_amb_context_code           => l_amb_context_code
79202       ,p_entity_code                => l_entity_code
79203       ,p_event_class_code           => l_event_class_code);
79204    --
79205    -- set accounting class
79206    --
79207    xla_ae_lines_pkg.SetAcctClass(
79208            p_accounting_class_code  => 'ASSET'
79209          , p_ae_header_id           => l_ae_header_id
79210          );
79211 
79212    --
79213    -- set rounding class
79214    --
79215    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
79216                       'ASSET';
79217 
79218    --
79219    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
79220    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
79221    --
79222    -- bulk performance
79223    --
79224    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
79225 
79226    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
79227       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
79228 
79229    -- 4955764
79230    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
79231       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
79232 
79233    -- 4458381 Public Sector Enh
79234    
79235    --
79236    -- set accounting attributes for the line type
79237    --
79238    l_entered_amt_idx := 4;
79239    l_accted_amt_idx  := 6;
79240    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
79241    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
79242    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
79243    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
79244    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
79245    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
79246    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
79247    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
79248    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
79249    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
79250    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
79254    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
79251    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
79252    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
79253 
79255    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
79256 
79257    ---------------------------------------------------------------------------------------------------------------
79258    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
79259    ---------------------------------------------------------------------------------------------------------------
79260    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
79261 
79262    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
79263    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
79264 
79265    IF xla_accounting_cache_pkg.GetValueChar
79266          (p_source_code         => 'LEDGER_CATEGORY_CODE'
79267          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
79268    AND l_bflow_method_code = 'PRIOR_ENTRY'
79269 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
79270    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
79271          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
79272        )
79273    THEN
79274          xla_ae_lines_pkg.BflowUpgEntry
79275            (p_business_method_code    => l_bflow_method_code
79276            ,p_business_class_code     => l_bflow_class_code
79277            ,p_balance_type            => l_balance_type_code);
79278    ELSE
79279       NULL;
79280 -- No business flow processing for business flow method of NONE.
79281    END IF;
79282 
79283    --
79284    -- call analytical criteria
79285    --
79286    
79287    --
79288    -- call description
79289    --
79290    
79291 xla_ae_lines_pkg.SetLineDescription(
79292    p_ae_header_id => l_ae_header_id
79293   ,p_description  => Description_80 (
79294      p_application_id         => p_application_id
79295    , p_ae_header_id           => l_ae_header_id 
79296 , p_source_1 => p_source_1
79297    )
79298 );
79299 
79300 
79301    --
79302    -- call ADRs
79303    -- Bug 4922099
79304    --
79305    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
79306         (NVL(l_actual_upg_option, 'N') = 'O') OR
79307         (NVL(l_enc_upg_option, 'N') = 'O')
79308       )
79309    THEN
79310    NULL;
79311    --
79312    --
79313    
79314   l_ccid := AcctDerRule_173(
79315            p_application_id           => p_application_id
79316          , p_ae_header_id             => l_ae_header_id 
79317 , p_source_3 => p_source_3
79318 , p_source_30 => p_source_30
79319          , x_transaction_coa_id       => l_adr_transaction_coa_id
79320          , x_accounting_coa_id        => l_adr_accounting_coa_id
79321          , x_value_type_code          => l_adr_value_type_code
79322          , p_side                     => 'NA'
79323    );
79324 
79325    xla_ae_lines_pkg.set_ccid(
79326     p_code_combination_id          => l_ccid
79327   , p_value_type_code              => l_adr_value_type_code
79328   , p_transaction_coa_id           => l_adr_transaction_coa_id
79329   , p_accounting_coa_id            => l_adr_accounting_coa_id
79330   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
79331   , p_adr_type_code                => 'S'
79332   , p_component_type               => l_component_type
79333   , p_component_code               => l_component_code
79334   , p_component_type_code          => l_component_type_code
79335   , p_component_appl_id            => l_component_appl_id
79336   , p_amb_context_code             => l_amb_context_code
79337   , p_side                         => 'NA'
79338   );
79339 
79340 
79341    l_segment := AcctDerRule_168(
79342            p_application_id           => p_application_id
79343          , p_ae_header_id             => l_ae_header_id 
79344 , p_source_3 => p_source_3
79345 , p_source_29 => p_source_29
79346          , x_transaction_coa_id       => l_adr_transaction_coa_id
79347          , x_accounting_coa_id        => l_adr_accounting_coa_id
79348          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
79349          , x_flex_value_set_id        => l_adr_flex_value_set_id
79350          , x_value_type_code          => l_adr_value_type_code
79351          , x_value_combination_id     => l_adr_value_combination_id
79352          , x_value_segment_code       => l_adr_value_segment_code
79353          , p_side                     => 'NA'
79354          , p_override_seg_flag        => 'Y'
79355    );
79356 
79357    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
79358 
79359       xla_ae_lines_pkg.set_segment(
79360           p_to_segment_code         => 'GL_BALANCING'
79361         , p_segment_value           => l_segment
79362         , p_from_segment_code       => l_adr_value_segment_code
79363         , p_from_combination_id     => l_adr_value_combination_id
79364         , p_value_type_code         => l_adr_value_type_code
79365         , p_transaction_coa_id      => l_adr_transaction_coa_id
79366         , p_accounting_coa_id       => l_adr_accounting_coa_id
79367         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
79368         , p_flex_value_set_id       => l_adr_flex_value_set_id
79369         , p_adr_code                => 'FA_EXPENSE_ACCT'
79370         , p_adr_type_code           => 'S'
79371         , p_component_type          => l_component_type
79372         , p_component_code          => l_component_code
79373         , p_component_type_code     => l_component_type_code
79374         , p_component_appl_id       => l_component_appl_id
79375         , p_amb_context_code        => l_amb_context_code
79379         );
79376         , p_entity_code             => 'TRANSACTIONS'
79377         , p_event_class_code        => 'RETIREMENTS'
79378         , p_side                    => 'NA'
79380 
79381   END IF;
79382 
79383    l_segment := AcctDerRule_160(
79384            p_application_id           => p_application_id
79385          , p_ae_header_id             => l_ae_header_id 
79386 , p_source_3 => p_source_3
79387 , p_source_22 => p_source_22
79388          , x_transaction_coa_id       => l_adr_transaction_coa_id
79389          , x_accounting_coa_id        => l_adr_accounting_coa_id
79390          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
79391          , x_flex_value_set_id        => l_adr_flex_value_set_id
79392          , x_value_type_code          => l_adr_value_type_code
79393          , x_value_combination_id     => l_adr_value_combination_id
79394          , x_value_segment_code       => l_adr_value_segment_code
79395          , p_side                     => 'NA'
79396          , p_override_seg_flag        => 'Y'
79397    );
79398 
79399    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
79400 
79401       xla_ae_lines_pkg.set_segment(
79402           p_to_segment_code         => 'GL_ACCOUNT'
79403         , p_segment_value           => l_segment
79404         , p_from_segment_code       => l_adr_value_segment_code
79405         , p_from_combination_id     => l_adr_value_combination_id
79406         , p_value_type_code         => l_adr_value_type_code
79407         , p_transaction_coa_id      => l_adr_transaction_coa_id
79408         , p_accounting_coa_id       => l_adr_accounting_coa_id
79409         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
79410         , p_flex_value_set_id       => l_adr_flex_value_set_id
79411         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
79412         , p_adr_type_code           => 'S'
79413         , p_component_type          => l_component_type
79414         , p_component_code          => l_component_code
79415         , p_component_type_code     => l_component_type_code
79416         , p_component_appl_id       => l_component_appl_id
79417         , p_amb_context_code        => l_amb_context_code
79418         , p_entity_code             => 'TRANSACTIONS'
79419         , p_event_class_code        => 'RETIREMENTS'
79420         , p_side                    => 'NA'
79421         );
79422 
79423   END IF;
79424 
79425    --
79426    --
79427    END IF;
79428    --
79429    -- Bug 4922099
79430    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
79431           (NVL(l_enc_upg_option, 'N') = 'O')
79432         ) AND
79433         (l_bflow_method_code = 'PRIOR_ENTRY')
79434       )
79435    THEN
79436       IF
79437       --
79438       1 = 2
79439       --
79440       THEN
79441       xla_accounting_err_pkg.build_message
79442                                     (p_appli_s_name            => 'XLA'
79443                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
79444                                     ,p_token_1                 => 'LINE_NUMBER'
79445                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
79446                                     ,p_token_2                 => 'LINE_TYPE_NAME'
79447                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
79448                                                                              l_component_type
79449                                                                             ,l_component_code
79450                                                                             ,l_component_type_code
79451                                                                             ,l_component_appl_id
79452                                                                             ,l_amb_context_code
79453                                                                             ,l_entity_code
79454                                                                             ,l_event_class_code
79455                                                                            )
79456                                     ,p_token_3                 => 'OWNER'
79457                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
79461                                     ,p_token_4                 => 'PRODUCT_NAME'
79458                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
79459                                                                           ,p_lookup_code    => l_component_type_code
79460                                                                          )
79462                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
79463                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
79464                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
79465                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
79466                                     ,p_ae_header_id            =>  NULL
79467                                        );
79468 
79469         IF (C_LEVEL_ERROR>= g_log_level) THEN
79470                  trace
79471                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
79472                       ,p_level    => C_LEVEL_ERROR
79473                       ,p_module   => l_log_module);
79474         END IF;
79475       END IF;
79476    END IF;
79477    --
79478    --
79479    ------------------------------------------------------------------------------------------------
79480    -- 4219869 Business Flow
79481    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
79482    -- Prior Entry.  Currently, the following code is always generated.
79483    ------------------------------------------------------------------------------------------------
79484    XLA_AE_LINES_PKG.ValidateCurrentLine;
79485 
79486    ------------------------------------------------------------------------------------
79487    -- 4219869 Business Flow
79488    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
79489    ------------------------------------------------------------------------------------
79490    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
79491 
79492    ----------------------------------------------------------------------------------
79493    -- 4219869 Business Flow
79494    -- Update journal entry status -- Need to generate this within IF <condition>
79495    ----------------------------------------------------------------------------------
79496    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
79497          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
79498          ,p_balance_type_code => l_balance_type_code
79499          );
79500 
79501    -------------------------------------------------------------------------------------------
79502    -- 4262811 - Generate the Accrual Reversal lines
79503    -------------------------------------------------------------------------------------------
79504    BEGIN
79505       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
79506                               (g_array_event(p_event_id).array_value_num('header_index'));
79507       IF l_acc_rev_flag IS NULL THEN
79508          l_acc_rev_flag := 'N';
79509       END IF;
79510    EXCEPTION
79511       WHEN OTHERS THEN
79512          l_acc_rev_flag := 'N';
79513    END;
79514    --
79515    IF (l_acc_rev_flag = 'Y') THEN
79516 
79517        -- 4645092  ------------------------------------------------------------------------------
79518        -- To allow MPA report to determine if it should generate report process
79519        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
79520        ------------------------------------------------------------------------------------------
79521 
79522        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
79523        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
79524    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
79525    -- call ADRs
79526    -- Bug 4922099
79527    --
79528    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
79529         (NVL(l_actual_upg_option, 'N') = 'O') OR
79530         (NVL(l_enc_upg_option, 'N') = 'O')
79531       )
79532    THEN
79533    NULL;
79534    --
79535    --
79536    
79537   l_ccid := AcctDerRule_173(
79538            p_application_id           => p_application_id
79539          , p_ae_header_id             => l_ae_header_id 
79540 , p_source_3 => p_source_3
79541 , p_source_30 => p_source_30
79545          , p_side                     => 'NA'
79542          , x_transaction_coa_id       => l_adr_transaction_coa_id
79543          , x_accounting_coa_id        => l_adr_accounting_coa_id
79544          , x_value_type_code          => l_adr_value_type_code
79546    );
79547 
79548    xla_ae_lines_pkg.set_ccid(
79549     p_code_combination_id          => l_ccid
79550   , p_value_type_code              => l_adr_value_type_code
79551   , p_transaction_coa_id           => l_adr_transaction_coa_id
79552   , p_accounting_coa_id            => l_adr_accounting_coa_id
79553   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
79554   , p_adr_type_code                => 'S'
79555   , p_component_type               => l_component_type
79556   , p_component_code               => l_component_code
79557   , p_component_type_code          => l_component_type_code
79558   , p_component_appl_id            => l_component_appl_id
79559   , p_amb_context_code             => l_amb_context_code
79560   , p_side                         => 'NA'
79561   );
79562 
79563 
79564    l_segment := AcctDerRule_168(
79565            p_application_id           => p_application_id
79566          , p_ae_header_id             => l_ae_header_id 
79567 , p_source_3 => p_source_3
79568 , p_source_29 => p_source_29
79569          , x_transaction_coa_id       => l_adr_transaction_coa_id
79570          , x_accounting_coa_id        => l_adr_accounting_coa_id
79571          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
79572          , x_flex_value_set_id        => l_adr_flex_value_set_id
79573          , x_value_type_code          => l_adr_value_type_code
79574          , x_value_combination_id     => l_adr_value_combination_id
79575          , x_value_segment_code       => l_adr_value_segment_code
79576          , p_side                     => 'NA'
79577          , p_override_seg_flag        => 'Y'
79578    );
79579 
79580    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
79581 
79582       xla_ae_lines_pkg.set_segment(
79583           p_to_segment_code         => 'GL_BALANCING'
79584         , p_segment_value           => l_segment
79585         , p_from_segment_code       => l_adr_value_segment_code
79586         , p_from_combination_id     => l_adr_value_combination_id
79587         , p_value_type_code         => l_adr_value_type_code
79588         , p_transaction_coa_id      => l_adr_transaction_coa_id
79589         , p_accounting_coa_id       => l_adr_accounting_coa_id
79590         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
79591         , p_flex_value_set_id       => l_adr_flex_value_set_id
79592         , p_adr_code                => 'FA_EXPENSE_ACCT'
79593         , p_adr_type_code           => 'S'
79594         , p_component_type          => l_component_type
79595         , p_component_code          => l_component_code
79596         , p_component_type_code     => l_component_type_code
79597         , p_component_appl_id       => l_component_appl_id
79598         , p_amb_context_code        => l_amb_context_code
79599         , p_entity_code             => 'TRANSACTIONS'
79600         , p_event_class_code        => 'RETIREMENTS'
79601         , p_side                    => 'NA'
79602         );
79603 
79604   END IF;
79605 
79606    l_segment := AcctDerRule_160(
79607            p_application_id           => p_application_id
79608          , p_ae_header_id             => l_ae_header_id 
79609 , p_source_3 => p_source_3
79610 , p_source_22 => p_source_22
79611          , x_transaction_coa_id       => l_adr_transaction_coa_id
79612          , x_accounting_coa_id        => l_adr_accounting_coa_id
79613          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
79614          , x_flex_value_set_id        => l_adr_flex_value_set_id
79615          , x_value_type_code          => l_adr_value_type_code
79616          , x_value_combination_id     => l_adr_value_combination_id
79617          , x_value_segment_code       => l_adr_value_segment_code
79618          , p_side                     => 'NA'
79619          , p_override_seg_flag        => 'Y'
79620    );
79621 
79622    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
79623 
79624       xla_ae_lines_pkg.set_segment(
79625           p_to_segment_code         => 'GL_ACCOUNT'
79626         , p_segment_value           => l_segment
79627         , p_from_segment_code       => l_adr_value_segment_code
79628         , p_from_combination_id     => l_adr_value_combination_id
79629         , p_value_type_code         => l_adr_value_type_code
79630         , p_transaction_coa_id      => l_adr_transaction_coa_id
79631         , p_accounting_coa_id       => l_adr_accounting_coa_id
79632         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
79633         , p_flex_value_set_id       => l_adr_flex_value_set_id
79634         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
79635         , p_adr_type_code           => 'S'
79636         , p_component_type          => l_component_type
79637         , p_component_code          => l_component_code
79638         , p_component_type_code     => l_component_type_code
79639         , p_component_appl_id       => l_component_appl_id
79640         , p_amb_context_code        => l_amb_context_code
79641         , p_entity_code             => 'TRANSACTIONS'
79642         , p_event_class_code        => 'RETIREMENTS'
79643         , p_side                    => 'NA'
79644         );
79645 
79646   END IF;
79647 
79648    --
79649    --
79650    END IF;
79651 
79652        --
79653        -- Update the line information that should be overwritten
79654        --
79655        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
79656                                          p_header_num   => 1);
79657        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
79658 
79659        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
79660 
79664 
79661        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
79662           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
79663        END IF;
79665       --
79666       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
79667       --
79668       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
79669           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
79670       ELSE
79671           ---------------------------------------------------------------------------------------------------
79672           -- 4262811a Switch Sign
79673           ---------------------------------------------------------------------------------------------------
79674           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
79675           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
79676                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
79677           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
79678                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
79679           -- 5132302
79680           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
79681                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
79682 
79683       END IF;
79684 
79685       -- 4955764
79686       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
79687       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
79688 
79689 
79690       XLA_AE_LINES_PKG.ValidateCurrentLine;
79691       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
79692 
79693       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
79694                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
79695                ,p_balance_type_code => l_balance_type_code);
79696 
79697    END IF;
79698 
79699    -----------------------------------------------------------------------------------------
79700    -- 4262811 Multiperiod Accounting
79701    -----------------------------------------------------------------------------------------
79702      -- No MPA option is assigned.
79703 
79704 
79705 END IF;
79706 END IF;
79707 --
79708 
79709 --
79710 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
79711    trace
79712       (p_msg      => 'END of AcctLineType_264'
79713       ,p_level    => C_LEVEL_PROCEDURE
79714       ,p_module   => l_log_module);
79715 END IF;
79716 --
79717 EXCEPTION
79718   WHEN xla_exceptions_pkg.application_exception THEN
79719       RAISE;
79720   WHEN OTHERS THEN
79721        xla_exceptions_pkg.raise_message
79722            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_264');
79723 END AcctLineType_264;
79724 --
79725 
79726 ---------------------------------------
79727 --
79728 -- PRIVATE FUNCTION
79729 --         AcctLineType_265
79730 --
79731 ---------------------------------------
79732 PROCEDURE AcctLineType_265 (
79733   p_application_id        IN NUMBER
79734  ,p_event_id              IN NUMBER
79735  ,p_calculate_acctd_flag  IN VARCHAR2
79736  ,p_calculate_g_l_flag    IN VARCHAR2
79737  ,p_actual_flag           IN OUT VARCHAR2
79738  ,p_balance_type_code     OUT VARCHAR2
79739  ,p_gain_or_loss_ref      OUT VARCHAR2
79740  
79741 --Period Close Date
79742  , p_source_1            IN DATE
79743 --Bonus Depreciation Expense Account
79744  , p_source_2            IN VARCHAR2
79745 --Generated Code Combination Identifier
79746  , p_source_3            IN NUMBER
79747 --Expense Account Code Combination Identifier
79748  , p_source_29            IN NUMBER
79749 --Bonus Generated Code Combination Identifier
79750  , p_source_31            IN NUMBER
79751 --Distribution Type Code
79752  , p_source_38            IN VARCHAR2
79753 --Currency Code
79754  , p_source_40            IN VARCHAR2
79755 --Asset Identifier
79756  , p_source_43            IN NUMBER
79757 --Period Counter
79758  , p_source_44            IN NUMBER
79759 --Distribution Identifier
79760  , p_source_45            IN NUMBER
79761 --Book Type Code
79762  , p_source_46            IN VARCHAR2
79763 --Bonus Entered Amount
79764  , p_source_48            IN NUMBER
79765 --Depreciation Run Identifier
79766  , p_source_49            IN NUMBER
79767 )
79768 IS
79769 
79770 l_component_type              VARCHAR2(80);
79771 l_component_code              VARCHAR2(30);
79772 l_component_type_code         VARCHAR2(1);
79773 l_component_appl_id           INTEGER;
79774 l_amb_context_code            VARCHAR2(30);
79775 l_entity_code                 VARCHAR2(30);
79776 l_event_class_code            VARCHAR2(30);
79777 l_ae_header_id                NUMBER;
79778 l_event_type_code             VARCHAR2(30);
79779 l_line_definition_code        VARCHAR2(30);
79780 l_line_definition_owner_code  VARCHAR2(1);
79781 --
79782 -- adr variables
79783 l_segment                     VARCHAR2(30);
79784 l_ccid                        NUMBER;
79785 l_adr_transaction_coa_id      NUMBER;
79786 l_adr_accounting_coa_id       NUMBER;
79787 l_adr_flexfield_segment_code  VARCHAR2(30);
79788 l_adr_flex_value_set_id       NUMBER;
79789 l_adr_value_type_code         VARCHAR2(30);
79790 l_adr_value_combination_id    NUMBER;
79791 l_adr_value_segment_code      VARCHAR2(30);
79792 
79793 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
79794 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
79798 -- 4262811 Variables ------------------------------------------------------------------------------------------
79795 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
79796 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
79797 
79799 l_entered_amt_idx             NUMBER;
79800 l_accted_amt_idx              NUMBER;
79801 l_acc_rev_flag                VARCHAR2(1);
79802 l_accrual_line_num            NUMBER;
79803 l_tmp_amt                     NUMBER;
79804 l_acc_rev_natural_side_code   VARCHAR2(1);
79805 
79806 l_num_entries                 NUMBER;
79807 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
79808 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
79809 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
79810 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
79811 l_recog_line_1                NUMBER;
79812 l_recog_line_2                NUMBER;
79813 
79814 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
79815 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
79816 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
79817 
79818 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
79819 
79820 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
79821 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
79822 
79823 ---------------------------------------------------------------------------------------------------------------
79824 
79825 
79826 --
79827 -- bulk performance
79828 --
79829 l_balance_type_code           VARCHAR2(1);
79830 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
79831 l_log_module                  VARCHAR2(240);
79832 
79833 --
79834 -- Upgrade strategy
79835 --
79836 l_actual_upg_option           VARCHAR2(1);
79837 l_enc_upg_option           VARCHAR2(1);
79838 
79839 --
79840 BEGIN
79841 --
79842 IF g_log_enabled THEN
79843       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_265';
79844 END IF;
79845 --
79846 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
79847 
79848       trace
79849          (p_msg      => 'BEGIN of AcctLineType_265'
79850          ,p_level    => C_LEVEL_PROCEDURE
79851          ,p_module   => l_log_module);
79852 
79853 END IF;
79854 --
79855 l_component_type             := 'AMB_JLT';
79856 l_component_code             := 'FA_PER_BONUS_DEPRN_EXP';
79857 l_component_type_code        := 'S';
79858 l_component_appl_id          :=  140;
79859 l_amb_context_code           := 'DEFAULT';
79860 l_entity_code                := 'DEPRECIATION';
79861 l_event_class_code           := 'DEPRECIATION';
79862 l_event_type_code            := 'DEPRECIATION_ALL';
79863 l_line_definition_owner_code := 'S';
79864 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE16';
79865 --
79866 l_balance_type_code          := 'A';
79867 l_segment                     := NULL;
79868 l_ccid                        := NULL;
79869 l_adr_transaction_coa_id      := NULL;
79870 l_adr_accounting_coa_id       := NULL;
79871 l_adr_flexfield_segment_code  := NULL;
79872 l_adr_flex_value_set_id       := NULL;
79873 l_adr_value_type_code         := NULL;
79874 l_adr_value_combination_id    := NULL;
79875 l_adr_value_segment_code      := NULL;
79876 
79877 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
79878 l_bflow_class_code           := '';    -- 4219869 Business Flow
79879 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
79880 l_budgetary_control_flag     := 'N';
79881 
79882 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
79883 l_bflow_applied_to_amt       := NULL; -- 5132302
79884 l_entered_amt_idx            := NULL;          -- 4262811
79885 l_accted_amt_idx             := NULL;          -- 4262811
79886 l_acc_rev_flag               := NULL;          -- 4262811
79887 l_accrual_line_num           := NULL;          -- 4262811
79888 l_tmp_amt                    := NULL;          -- 4262811
79889 --
79890  
79891 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
79892     l_balance_type_code <> 'B' THEN
79893 IF NVL(p_source_48,9E125) <>  0 AND 
79894 NVL(p_source_38,'
79895 ') =  'DEPRN'
79896  THEN 
79897 
79898    --
79899    XLA_AE_LINES_PKG.SetNewLine;
79900 
79901    p_balance_type_code          := l_balance_type_code;
79902    -- set the flag so later we will know whether the gain loss line needs to be created
79903    
79904    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
79905      p_actual_flag :='A';
79906    END IF;
79907 
79908    --
79909    -- bulk performance
79910    --
79911    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
79912                                       p_header_num   => 0); -- 4262811
79913    --
79914    -- set accounting line options
79915    --
79916    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
79917            p_natural_side_code          => 'D'
79918          , p_gain_or_loss_flag          => 'N'
79919          , p_gl_transfer_mode_code      => 'S'
79920          , p_acct_entry_type_code       => 'A'
79921          , p_switch_side_flag           => 'Y'
79922          , p_merge_duplicate_code       => 'N'
79923          );
79924    --
79925    l_acc_rev_natural_side_code := 'C';  -- 4262811
79926    -- 
79927    --
79928    -- set accounting line type info
79929    --
79930    xla_ae_lines_pkg.SetAcctLineType
79931       (p_component_type             => l_component_type
79932       ,p_event_type_code            => l_event_type_code
79933       ,p_line_definition_owner_code => l_line_definition_owner_code
79937       ,p_accounting_line_appl_id    => l_component_appl_id
79934       ,p_line_definition_code       => l_line_definition_code
79935       ,p_accounting_line_code       => l_component_code
79936       ,p_accounting_line_type_code  => l_component_type_code
79938       ,p_amb_context_code           => l_amb_context_code
79939       ,p_entity_code                => l_entity_code
79940       ,p_event_class_code           => l_event_class_code);
79941    --
79942    -- set accounting class
79943    --
79944    xla_ae_lines_pkg.SetAcctClass(
79945            p_accounting_class_code  => 'EXPENSE'
79946          , p_ae_header_id           => l_ae_header_id
79947          );
79948 
79949    --
79950    -- set rounding class
79951    --
79952    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
79953                       'EXPENSE';
79954 
79955    --
79956    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
79957    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
79958    --
79959    -- bulk performance
79960    --
79961    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
79962 
79963    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
79964       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
79965 
79966    -- 4955764
79967    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
79968       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
79969 
79970    -- 4458381 Public Sector Enh
79971    
79972    --
79973    -- set accounting attributes for the line type
79974    --
79975    l_entered_amt_idx := 7;
79976    l_accted_amt_idx  := 9;
79977    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
79978    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
79979    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
79980    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
79981    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
79982    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
79983    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_49);
79984    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
79985    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
79986    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
79987    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_45);
79988    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
79989    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
79990    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
79991    l_rec_acct_attrs.array_num_value(7)  := p_source_48;
79992    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
79993    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
79994    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
79995    l_rec_acct_attrs.array_num_value(9)  := p_source_48;
79996 
79997    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
79998    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
79999 
80000    ---------------------------------------------------------------------------------------------------------------
80001    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
80002    ---------------------------------------------------------------------------------------------------------------
80003    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
80004 
80005    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
80006    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
80007 
80008    IF xla_accounting_cache_pkg.GetValueChar
80009          (p_source_code         => 'LEDGER_CATEGORY_CODE'
80010          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
80011    AND l_bflow_method_code = 'PRIOR_ENTRY'
80012 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
80013    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
80014          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
80015        )
80016    THEN
80017          xla_ae_lines_pkg.BflowUpgEntry
80018            (p_business_method_code    => l_bflow_method_code
80019            ,p_business_class_code     => l_bflow_class_code
80020            ,p_balance_type            => l_balance_type_code);
80021    ELSE
80022       NULL;
80023 -- No business flow processing for business flow method of NONE.
80024    END IF;
80025 
80026    --
80027    -- call analytical criteria
80028    --
80029    
80030    --
80031    -- call description
80032    --
80033    
80034 xla_ae_lines_pkg.SetLineDescription(
80035    p_ae_header_id => l_ae_header_id
80036   ,p_description  => Description_2 (
80037      p_application_id         => p_application_id
80038    , p_ae_header_id           => l_ae_header_id 
80039 , p_source_1 => p_source_1
80040    )
80041 );
80042 
80043 
80044    --
80045    -- call ADRs
80046    -- Bug 4922099
80047    --
80048    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
80049         (NVL(l_actual_upg_option, 'N') = 'O') OR
80050         (NVL(l_enc_upg_option, 'N') = 'O')
80051       )
80052    THEN
80053    NULL;
80054    --
80055    --
80056    
80057   l_ccid := AcctDerRule_176(
80058            p_application_id           => p_application_id
80059          , p_ae_header_id             => l_ae_header_id 
80060 , p_source_29 => p_source_29
80064          , x_value_type_code          => l_adr_value_type_code
80061 , p_source_31 => p_source_31
80062          , x_transaction_coa_id       => l_adr_transaction_coa_id
80063          , x_accounting_coa_id        => l_adr_accounting_coa_id
80065          , p_side                     => 'NA'
80066    );
80067 
80068    xla_ae_lines_pkg.set_ccid(
80069     p_code_combination_id          => l_ccid
80070   , p_value_type_code              => l_adr_value_type_code
80071   , p_transaction_coa_id           => l_adr_transaction_coa_id
80072   , p_accounting_coa_id            => l_adr_accounting_coa_id
80073   , p_adr_code                     => 'FA_PER_BONUS_DEPRN_EXPENSE'
80074   , p_adr_type_code                => 'S'
80075   , p_component_type               => l_component_type
80076   , p_component_code               => l_component_code
80077   , p_component_type_code          => l_component_type_code
80078   , p_component_appl_id            => l_component_appl_id
80079   , p_amb_context_code             => l_amb_context_code
80080   , p_side                         => 'NA'
80081   );
80082 
80083 
80084    l_segment := AcctDerRule_143(
80085            p_application_id           => p_application_id
80086          , p_ae_header_id             => l_ae_header_id 
80087 , p_source_2 => p_source_2
80088 , p_source_3 => p_source_3
80089          , x_transaction_coa_id       => l_adr_transaction_coa_id
80090          , x_accounting_coa_id        => l_adr_accounting_coa_id
80091          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
80092          , x_flex_value_set_id        => l_adr_flex_value_set_id
80093          , x_value_type_code          => l_adr_value_type_code
80094          , x_value_combination_id     => l_adr_value_combination_id
80095          , x_value_segment_code       => l_adr_value_segment_code
80096          , p_side                     => 'NA'
80097          , p_override_seg_flag        => 'Y'
80098    );
80099 
80100    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
80101 
80102       xla_ae_lines_pkg.set_segment(
80103           p_to_segment_code         => 'GL_ACCOUNT'
80104         , p_segment_value           => l_segment
80105         , p_from_segment_code       => l_adr_value_segment_code
80106         , p_from_combination_id     => l_adr_value_combination_id
80107         , p_value_type_code         => l_adr_value_type_code
80108         , p_transaction_coa_id      => l_adr_transaction_coa_id
80109         , p_accounting_coa_id       => l_adr_accounting_coa_id
80110         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
80111         , p_flex_value_set_id       => l_adr_flex_value_set_id
80112         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
80113         , p_adr_type_code           => 'S'
80114         , p_component_type          => l_component_type
80115         , p_component_code          => l_component_code
80116         , p_component_type_code     => l_component_type_code
80117         , p_component_appl_id       => l_component_appl_id
80118         , p_amb_context_code        => l_amb_context_code
80119         , p_entity_code             => 'DEPRECIATION'
80120         , p_event_class_code        => 'DEPRECIATION'
80121         , p_side                    => 'NA'
80122         );
80123 
80124   END IF;
80125 
80126    --
80127    --
80128    END IF;
80129    --
80130    -- Bug 4922099
80131    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
80132           (NVL(l_enc_upg_option, 'N') = 'O')
80133         ) AND
80134         (l_bflow_method_code = 'PRIOR_ENTRY')
80135       )
80136    THEN
80137       IF
80138       --
80139       1 = 2
80140       --
80141       THEN
80142       xla_accounting_err_pkg.build_message
80143                                     (p_appli_s_name            => 'XLA'
80144                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
80145                                     ,p_token_1                 => 'LINE_NUMBER'
80146                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
80147                                     ,p_token_2                 => 'LINE_TYPE_NAME'
80148                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
80149                                                                              l_component_type
80150                                                                             ,l_component_code
80151                                                                             ,l_component_type_code
80152                                                                             ,l_component_appl_id
80153                                                                             ,l_amb_context_code
80154                                                                             ,l_entity_code
80155                                                                             ,l_event_class_code
80156                                                                            )
80157                                     ,p_token_3                 => 'OWNER'
80158                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
80159                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
80160                                                                           ,p_lookup_code    => l_component_type_code
80161                                                                          )
80162                                     ,p_token_4                 => 'PRODUCT_NAME'
80163                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
80164                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
80165                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
80166                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
80170         IF (C_LEVEL_ERROR>= g_log_level) THEN
80167                                     ,p_ae_header_id            =>  NULL
80168                                        );
80169 
80171                  trace
80172                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
80173                       ,p_level    => C_LEVEL_ERROR
80174                       ,p_module   => l_log_module);
80175         END IF;
80176       END IF;
80177    END IF;
80178    --
80179    --
80180    ------------------------------------------------------------------------------------------------
80181    -- 4219869 Business Flow
80182    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
80183    -- Prior Entry.  Currently, the following code is always generated.
80184    ------------------------------------------------------------------------------------------------
80185    XLA_AE_LINES_PKG.ValidateCurrentLine;
80186 
80187    ------------------------------------------------------------------------------------
80188    -- 4219869 Business Flow
80189    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
80190    ------------------------------------------------------------------------------------
80191    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
80192 
80193    ----------------------------------------------------------------------------------
80194    -- 4219869 Business Flow
80195    -- Update journal entry status -- Need to generate this within IF <condition>
80196    ----------------------------------------------------------------------------------
80197    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
80198          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
80199          ,p_balance_type_code => l_balance_type_code
80200          );
80201 
80202    -------------------------------------------------------------------------------------------
80203    -- 4262811 - Generate the Accrual Reversal lines
80204    -------------------------------------------------------------------------------------------
80205    BEGIN
80206       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
80207                               (g_array_event(p_event_id).array_value_num('header_index'));
80208       IF l_acc_rev_flag IS NULL THEN
80209          l_acc_rev_flag := 'N';
80210       END IF;
80211    EXCEPTION
80212       WHEN OTHERS THEN
80213          l_acc_rev_flag := 'N';
80214    END;
80215    --
80216    IF (l_acc_rev_flag = 'Y') THEN
80217 
80218        -- 4645092  ------------------------------------------------------------------------------
80219        -- To allow MPA report to determine if it should generate report process
80220        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
80221        ------------------------------------------------------------------------------------------
80222 
80223        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
80224        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
80225    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
80226    -- call ADRs
80227    -- Bug 4922099
80228    --
80229    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
80230         (NVL(l_actual_upg_option, 'N') = 'O') OR
80231         (NVL(l_enc_upg_option, 'N') = 'O')
80232       )
80233    THEN
80234    NULL;
80235    --
80236    --
80237    
80238   l_ccid := AcctDerRule_176(
80239            p_application_id           => p_application_id
80240          , p_ae_header_id             => l_ae_header_id 
80241 , p_source_29 => p_source_29
80242 , p_source_31 => p_source_31
80243          , x_transaction_coa_id       => l_adr_transaction_coa_id
80244          , x_accounting_coa_id        => l_adr_accounting_coa_id
80245          , x_value_type_code          => l_adr_value_type_code
80246          , p_side                     => 'NA'
80247    );
80248 
80249    xla_ae_lines_pkg.set_ccid(
80250     p_code_combination_id          => l_ccid
80251   , p_value_type_code              => l_adr_value_type_code
80252   , p_transaction_coa_id           => l_adr_transaction_coa_id
80253   , p_accounting_coa_id            => l_adr_accounting_coa_id
80254   , p_adr_code                     => 'FA_PER_BONUS_DEPRN_EXPENSE'
80255   , p_adr_type_code                => 'S'
80256   , p_component_type               => l_component_type
80257   , p_component_code               => l_component_code
80258   , p_component_type_code          => l_component_type_code
80259   , p_component_appl_id            => l_component_appl_id
80260   , p_amb_context_code             => l_amb_context_code
80261   , p_side                         => 'NA'
80262   );
80263 
80264 
80265    l_segment := AcctDerRule_143(
80266            p_application_id           => p_application_id
80267          , p_ae_header_id             => l_ae_header_id 
80268 , p_source_2 => p_source_2
80269 , p_source_3 => p_source_3
80270          , x_transaction_coa_id       => l_adr_transaction_coa_id
80271          , x_accounting_coa_id        => l_adr_accounting_coa_id
80272          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
80273          , x_flex_value_set_id        => l_adr_flex_value_set_id
80274          , x_value_type_code          => l_adr_value_type_code
80275          , x_value_combination_id     => l_adr_value_combination_id
80276          , x_value_segment_code       => l_adr_value_segment_code
80277          , p_side                     => 'NA'
80278          , p_override_seg_flag        => 'Y'
80279    );
80280 
80281    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
80282 
80283       xla_ae_lines_pkg.set_segment(
80284           p_to_segment_code         => 'GL_ACCOUNT'
80285         , p_segment_value           => l_segment
80286         , p_from_segment_code       => l_adr_value_segment_code
80287         , p_from_combination_id     => l_adr_value_combination_id
80291         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
80288         , p_value_type_code         => l_adr_value_type_code
80289         , p_transaction_coa_id      => l_adr_transaction_coa_id
80290         , p_accounting_coa_id       => l_adr_accounting_coa_id
80292         , p_flex_value_set_id       => l_adr_flex_value_set_id
80293         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
80294         , p_adr_type_code           => 'S'
80295         , p_component_type          => l_component_type
80296         , p_component_code          => l_component_code
80297         , p_component_type_code     => l_component_type_code
80298         , p_component_appl_id       => l_component_appl_id
80299         , p_amb_context_code        => l_amb_context_code
80300         , p_entity_code             => 'DEPRECIATION'
80301         , p_event_class_code        => 'DEPRECIATION'
80302         , p_side                    => 'NA'
80303         );
80304 
80305   END IF;
80306 
80307    --
80308    --
80309    END IF;
80310 
80311        --
80312        -- Update the line information that should be overwritten
80313        --
80314        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
80315                                          p_header_num   => 1);
80316        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
80317 
80318        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
80319 
80320        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
80321           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
80322        END IF;
80323 
80324       --
80325       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
80326       --
80327       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
80328           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
80329       ELSE
80330           ---------------------------------------------------------------------------------------------------
80331           -- 4262811a Switch Sign
80332           ---------------------------------------------------------------------------------------------------
80333           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
80334           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
80335                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
80336           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
80337                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
80338           -- 5132302
80339           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
80340                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
80341 
80342       END IF;
80343 
80344       -- 4955764
80345       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
80346       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
80347 
80348 
80349       XLA_AE_LINES_PKG.ValidateCurrentLine;
80350       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
80351 
80352       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
80353                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
80354                ,p_balance_type_code => l_balance_type_code);
80355 
80356    END IF;
80357 
80358    -----------------------------------------------------------------------------------------
80359    -- 4262811 Multiperiod Accounting
80360    -----------------------------------------------------------------------------------------
80361      -- No MPA option is assigned.
80362 
80363 
80364 END IF;
80365 END IF;
80366 --
80367 
80368 --
80369 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
80370    trace
80371       (p_msg      => 'END of AcctLineType_265'
80372       ,p_level    => C_LEVEL_PROCEDURE
80373       ,p_module   => l_log_module);
80374 END IF;
80375 --
80376 EXCEPTION
80377   WHEN xla_exceptions_pkg.application_exception THEN
80378       RAISE;
80379   WHEN OTHERS THEN
80380        xla_exceptions_pkg.raise_message
80381            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_265');
80382 END AcctLineType_265;
80383 --
80384 
80385 ---------------------------------------
80386 --
80387 -- PRIVATE FUNCTION
80388 --         AcctLineType_266
80389 --
80390 ---------------------------------------
80391 PROCEDURE AcctLineType_266 (
80392   p_application_id        IN NUMBER
80393  ,p_event_id              IN NUMBER
80394  ,p_calculate_acctd_flag  IN VARCHAR2
80395  ,p_calculate_g_l_flag    IN VARCHAR2
80396  ,p_actual_flag           IN OUT VARCHAR2
80397  ,p_balance_type_code     OUT VARCHAR2
80398  ,p_gain_or_loss_ref      OUT VARCHAR2
80399  
80400 --Period Close Date
80401  , p_source_1            IN DATE
80402 --Generated Code Combination Identifier
80403  , p_source_3            IN NUMBER
80404 --Bonus Reserve Account
80405  , p_source_4            IN VARCHAR2
80406 --Expense Account Code Combination Identifier
80407  , p_source_29            IN NUMBER
80408 --Default Code Combination Identifier
80409  , p_source_30            IN NUMBER
80410 --Bonus Generated Offset Code Combination Identifier
80411  , p_source_32            IN NUMBER
80412 --Distribution Type Code
80413  , p_source_38            IN VARCHAR2
80414 --Currency Code
80415  , p_source_40            IN VARCHAR2
80416 --Asset Identifier
80420 --Distribution Identifier
80417  , p_source_43            IN NUMBER
80418 --Period Counter
80419  , p_source_44            IN NUMBER
80421  , p_source_45            IN NUMBER
80422 --Book Type Code
80423  , p_source_46            IN VARCHAR2
80424 --Bonus Entered Amount
80425  , p_source_48            IN NUMBER
80426 --Depreciation Run Identifier
80427  , p_source_49            IN NUMBER
80428 )
80429 IS
80430 
80431 l_component_type              VARCHAR2(80);
80432 l_component_code              VARCHAR2(30);
80433 l_component_type_code         VARCHAR2(1);
80434 l_component_appl_id           INTEGER;
80435 l_amb_context_code            VARCHAR2(30);
80436 l_entity_code                 VARCHAR2(30);
80437 l_event_class_code            VARCHAR2(30);
80438 l_ae_header_id                NUMBER;
80439 l_event_type_code             VARCHAR2(30);
80440 l_line_definition_code        VARCHAR2(30);
80441 l_line_definition_owner_code  VARCHAR2(1);
80442 --
80443 -- adr variables
80444 l_segment                     VARCHAR2(30);
80445 l_ccid                        NUMBER;
80446 l_adr_transaction_coa_id      NUMBER;
80447 l_adr_accounting_coa_id       NUMBER;
80448 l_adr_flexfield_segment_code  VARCHAR2(30);
80449 l_adr_flex_value_set_id       NUMBER;
80450 l_adr_value_type_code         VARCHAR2(30);
80451 l_adr_value_combination_id    NUMBER;
80452 l_adr_value_segment_code      VARCHAR2(30);
80453 
80454 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
80455 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
80456 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
80457 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
80458 
80459 -- 4262811 Variables ------------------------------------------------------------------------------------------
80460 l_entered_amt_idx             NUMBER;
80461 l_accted_amt_idx              NUMBER;
80462 l_acc_rev_flag                VARCHAR2(1);
80463 l_accrual_line_num            NUMBER;
80464 l_tmp_amt                     NUMBER;
80465 l_acc_rev_natural_side_code   VARCHAR2(1);
80466 
80467 l_num_entries                 NUMBER;
80468 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
80469 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
80470 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
80471 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
80472 l_recog_line_1                NUMBER;
80473 l_recog_line_2                NUMBER;
80474 
80475 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
80476 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
80477 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
80478 
80479 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
80480 
80481 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
80482 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
80483 
80484 ---------------------------------------------------------------------------------------------------------------
80485 
80486 
80487 --
80488 -- bulk performance
80489 --
80490 l_balance_type_code           VARCHAR2(1);
80491 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
80492 l_log_module                  VARCHAR2(240);
80493 
80494 --
80495 -- Upgrade strategy
80496 --
80497 l_actual_upg_option           VARCHAR2(1);
80498 l_enc_upg_option           VARCHAR2(1);
80499 
80500 --
80501 BEGIN
80502 --
80503 IF g_log_enabled THEN
80504       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_266';
80505 END IF;
80506 --
80507 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
80508 
80509       trace
80510          (p_msg      => 'BEGIN of AcctLineType_266'
80511          ,p_level    => C_LEVEL_PROCEDURE
80512          ,p_module   => l_log_module);
80513 
80514 END IF;
80515 --
80516 l_component_type             := 'AMB_JLT';
80517 l_component_code             := 'FA_PER_BONUS_DEPRN_RESERVE';
80518 l_component_type_code        := 'S';
80519 l_component_appl_id          :=  140;
80520 l_amb_context_code           := 'DEFAULT';
80521 l_entity_code                := 'DEPRECIATION';
80522 l_event_class_code           := 'DEPRECIATION';
80523 l_event_type_code            := 'DEPRECIATION_ALL';
80524 l_line_definition_owner_code := 'S';
80525 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE16';
80526 --
80527 l_balance_type_code          := 'A';
80528 l_segment                     := NULL;
80529 l_ccid                        := NULL;
80530 l_adr_transaction_coa_id      := NULL;
80531 l_adr_accounting_coa_id       := NULL;
80532 l_adr_flexfield_segment_code  := NULL;
80533 l_adr_flex_value_set_id       := NULL;
80534 l_adr_value_type_code         := NULL;
80535 l_adr_value_combination_id    := NULL;
80536 l_adr_value_segment_code      := NULL;
80537 
80538 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
80539 l_bflow_class_code           := '';    -- 4219869 Business Flow
80540 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
80541 l_budgetary_control_flag     := 'N';
80542 
80543 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
80544 l_bflow_applied_to_amt       := NULL; -- 5132302
80545 l_entered_amt_idx            := NULL;          -- 4262811
80546 l_accted_amt_idx             := NULL;          -- 4262811
80547 l_acc_rev_flag               := NULL;          -- 4262811
80548 l_accrual_line_num           := NULL;          -- 4262811
80549 l_tmp_amt                    := NULL;          -- 4262811
80550 --
80551  
80552 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
80553     l_balance_type_code <> 'B' THEN
80557  THEN 
80554 IF NVL(p_source_48,9E125) <>  0 AND 
80555 NVL(p_source_38,'
80556 ') =  'DEPRN'
80558 
80559    --
80560    XLA_AE_LINES_PKG.SetNewLine;
80561 
80562    p_balance_type_code          := l_balance_type_code;
80563    -- set the flag so later we will know whether the gain loss line needs to be created
80564    
80565    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
80566      p_actual_flag :='A';
80567    END IF;
80568 
80569    --
80570    -- bulk performance
80571    --
80572    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
80573                                       p_header_num   => 0); -- 4262811
80574    --
80575    -- set accounting line options
80576    --
80577    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
80578            p_natural_side_code          => 'C'
80579          , p_gain_or_loss_flag          => 'N'
80580          , p_gl_transfer_mode_code      => 'S'
80581          , p_acct_entry_type_code       => 'A'
80582          , p_switch_side_flag           => 'Y'
80583          , p_merge_duplicate_code       => 'N'
80584          );
80585    --
80586    l_acc_rev_natural_side_code := 'D';  -- 4262811
80587    -- 
80588    --
80589    -- set accounting line type info
80590    --
80591    xla_ae_lines_pkg.SetAcctLineType
80592       (p_component_type             => l_component_type
80593       ,p_event_type_code            => l_event_type_code
80594       ,p_line_definition_owner_code => l_line_definition_owner_code
80595       ,p_line_definition_code       => l_line_definition_code
80596       ,p_accounting_line_code       => l_component_code
80597       ,p_accounting_line_type_code  => l_component_type_code
80598       ,p_accounting_line_appl_id    => l_component_appl_id
80599       ,p_amb_context_code           => l_amb_context_code
80600       ,p_entity_code                => l_entity_code
80601       ,p_event_class_code           => l_event_class_code);
80602    --
80603    -- set accounting class
80604    --
80605    xla_ae_lines_pkg.SetAcctClass(
80606            p_accounting_class_code  => 'ASSET'
80607          , p_ae_header_id           => l_ae_header_id
80608          );
80609 
80610    --
80611    -- set rounding class
80612    --
80613    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
80614                       'ASSET';
80615 
80616    --
80617    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
80618    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
80619    --
80620    -- bulk performance
80621    --
80622    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
80623 
80624    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
80625       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
80626 
80627    -- 4955764
80628    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
80629       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
80630 
80631    -- 4458381 Public Sector Enh
80632    
80633    --
80634    -- set accounting attributes for the line type
80635    --
80636    l_entered_amt_idx := 7;
80637    l_accted_amt_idx  := 9;
80638    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
80639    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
80640    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
80641    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
80642    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
80643    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
80644    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_49);
80645    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
80646    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
80647    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
80648    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_45);
80649    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
80650    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
80651    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
80652    l_rec_acct_attrs.array_num_value(7)  := p_source_48;
80653    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
80654    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
80655    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
80656    l_rec_acct_attrs.array_num_value(9)  := p_source_48;
80657 
80658    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
80659    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
80660 
80661    ---------------------------------------------------------------------------------------------------------------
80662    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
80663    ---------------------------------------------------------------------------------------------------------------
80664    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
80665 
80666    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
80667    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
80668 
80669    IF xla_accounting_cache_pkg.GetValueChar
80670          (p_source_code         => 'LEDGER_CATEGORY_CODE'
80671          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
80672    AND l_bflow_method_code = 'PRIOR_ENTRY'
80673 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
80677    THEN
80674    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
80675          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
80676        )
80678          xla_ae_lines_pkg.BflowUpgEntry
80679            (p_business_method_code    => l_bflow_method_code
80680            ,p_business_class_code     => l_bflow_class_code
80681            ,p_balance_type            => l_balance_type_code);
80682    ELSE
80683       NULL;
80684 -- No business flow processing for business flow method of NONE.
80685    END IF;
80686 
80687    --
80688    -- call analytical criteria
80689    --
80690    
80691    --
80692    -- call description
80693    --
80694    
80695 xla_ae_lines_pkg.SetLineDescription(
80696    p_ae_header_id => l_ae_header_id
80697   ,p_description  => Description_3 (
80698      p_application_id         => p_application_id
80699    , p_ae_header_id           => l_ae_header_id 
80700 , p_source_1 => p_source_1
80701    )
80702 );
80703 
80704 
80705    --
80706    -- call ADRs
80707    -- Bug 4922099
80708    --
80709    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
80710         (NVL(l_actual_upg_option, 'N') = 'O') OR
80711         (NVL(l_enc_upg_option, 'N') = 'O')
80712       )
80713    THEN
80714    NULL;
80715    --
80716    --
80717    
80718   l_ccid := AcctDerRule_177(
80719            p_application_id           => p_application_id
80720          , p_ae_header_id             => l_ae_header_id 
80721 , p_source_30 => p_source_30
80722 , p_source_32 => p_source_32
80723          , x_transaction_coa_id       => l_adr_transaction_coa_id
80724          , x_accounting_coa_id        => l_adr_accounting_coa_id
80725          , x_value_type_code          => l_adr_value_type_code
80726          , p_side                     => 'NA'
80727    );
80728 
80729    xla_ae_lines_pkg.set_ccid(
80730     p_code_combination_id          => l_ccid
80731   , p_value_type_code              => l_adr_value_type_code
80732   , p_transaction_coa_id           => l_adr_transaction_coa_id
80733   , p_accounting_coa_id            => l_adr_accounting_coa_id
80734   , p_adr_code                     => 'FA_PER_BONUS_DEPRN_RESERVE'
80735   , p_adr_type_code                => 'S'
80736   , p_component_type               => l_component_type
80737   , p_component_code               => l_component_code
80738   , p_component_type_code          => l_component_type_code
80739   , p_component_appl_id            => l_component_appl_id
80740   , p_amb_context_code             => l_amb_context_code
80741   , p_side                         => 'NA'
80742   );
80743 
80744 
80745    l_segment := AcctDerRule_144(
80746            p_application_id           => p_application_id
80747          , p_ae_header_id             => l_ae_header_id 
80748 , p_source_3 => p_source_3
80749 , p_source_4 => p_source_4
80750          , x_transaction_coa_id       => l_adr_transaction_coa_id
80751          , x_accounting_coa_id        => l_adr_accounting_coa_id
80752          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
80753          , x_flex_value_set_id        => l_adr_flex_value_set_id
80754          , x_value_type_code          => l_adr_value_type_code
80755          , x_value_combination_id     => l_adr_value_combination_id
80756          , x_value_segment_code       => l_adr_value_segment_code
80757          , p_side                     => 'NA'
80758          , p_override_seg_flag        => 'Y'
80759    );
80760 
80761    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
80762 
80763       xla_ae_lines_pkg.set_segment(
80764           p_to_segment_code         => 'GL_ACCOUNT'
80765         , p_segment_value           => l_segment
80766         , p_from_segment_code       => l_adr_value_segment_code
80767         , p_from_combination_id     => l_adr_value_combination_id
80768         , p_value_type_code         => l_adr_value_type_code
80769         , p_transaction_coa_id      => l_adr_transaction_coa_id
80770         , p_accounting_coa_id       => l_adr_accounting_coa_id
80771         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
80772         , p_flex_value_set_id       => l_adr_flex_value_set_id
80773         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
80774         , p_adr_type_code           => 'S'
80775         , p_component_type          => l_component_type
80776         , p_component_code          => l_component_code
80777         , p_component_type_code     => l_component_type_code
80778         , p_component_appl_id       => l_component_appl_id
80779         , p_amb_context_code        => l_amb_context_code
80780         , p_entity_code             => 'DEPRECIATION'
80781         , p_event_class_code        => 'DEPRECIATION'
80782         , p_side                    => 'NA'
80783         );
80784 
80785   END IF;
80786 
80787    l_segment := AcctDerRule_168(
80788            p_application_id           => p_application_id
80789          , p_ae_header_id             => l_ae_header_id 
80790 , p_source_3 => p_source_3
80791 , p_source_29 => p_source_29
80792          , x_transaction_coa_id       => l_adr_transaction_coa_id
80793          , x_accounting_coa_id        => l_adr_accounting_coa_id
80794          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
80795          , x_flex_value_set_id        => l_adr_flex_value_set_id
80796          , x_value_type_code          => l_adr_value_type_code
80797          , x_value_combination_id     => l_adr_value_combination_id
80798          , x_value_segment_code       => l_adr_value_segment_code
80799          , p_side                     => 'NA'
80800          , p_override_seg_flag        => 'Y'
80801    );
80802 
80803    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
80804 
80805       xla_ae_lines_pkg.set_segment(
80806           p_to_segment_code         => 'GL_BALANCING'
80807         , p_segment_value           => l_segment
80811         , p_transaction_coa_id      => l_adr_transaction_coa_id
80808         , p_from_segment_code       => l_adr_value_segment_code
80809         , p_from_combination_id     => l_adr_value_combination_id
80810         , p_value_type_code         => l_adr_value_type_code
80812         , p_accounting_coa_id       => l_adr_accounting_coa_id
80813         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
80814         , p_flex_value_set_id       => l_adr_flex_value_set_id
80815         , p_adr_code                => 'FA_EXPENSE_ACCT'
80816         , p_adr_type_code           => 'S'
80817         , p_component_type          => l_component_type
80818         , p_component_code          => l_component_code
80819         , p_component_type_code     => l_component_type_code
80820         , p_component_appl_id       => l_component_appl_id
80821         , p_amb_context_code        => l_amb_context_code
80822         , p_entity_code             => 'DEPRECIATION'
80823         , p_event_class_code        => 'DEPRECIATION'
80824         , p_side                    => 'NA'
80825         );
80826 
80827   END IF;
80828 
80829    --
80830    --
80831    END IF;
80832    --
80833    -- Bug 4922099
80834    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
80835           (NVL(l_enc_upg_option, 'N') = 'O')
80836         ) AND
80837         (l_bflow_method_code = 'PRIOR_ENTRY')
80838       )
80839    THEN
80840       IF
80841       --
80842       1 = 2
80843       --
80844       THEN
80845       xla_accounting_err_pkg.build_message
80846                                     (p_appli_s_name            => 'XLA'
80847                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
80848                                     ,p_token_1                 => 'LINE_NUMBER'
80849                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
80850                                     ,p_token_2                 => 'LINE_TYPE_NAME'
80851                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
80852                                                                              l_component_type
80853                                                                             ,l_component_code
80854                                                                             ,l_component_type_code
80855                                                                             ,l_component_appl_id
80856                                                                             ,l_amb_context_code
80857                                                                             ,l_entity_code
80858                                                                             ,l_event_class_code
80859                                                                            )
80860                                     ,p_token_3                 => 'OWNER'
80861                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
80862                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
80863                                                                           ,p_lookup_code    => l_component_type_code
80864                                                                          )
80865                                     ,p_token_4                 => 'PRODUCT_NAME'
80866                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
80867                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
80868                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
80869                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
80870                                     ,p_ae_header_id            =>  NULL
80871                                        );
80872 
80873         IF (C_LEVEL_ERROR>= g_log_level) THEN
80874                  trace
80875                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
80876                       ,p_level    => C_LEVEL_ERROR
80877                       ,p_module   => l_log_module);
80878         END IF;
80879       END IF;
80880    END IF;
80881    --
80882    --
80883    ------------------------------------------------------------------------------------------------
80884    -- 4219869 Business Flow
80885    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
80886    -- Prior Entry.  Currently, the following code is always generated.
80887    ------------------------------------------------------------------------------------------------
80888    XLA_AE_LINES_PKG.ValidateCurrentLine;
80889 
80890    ------------------------------------------------------------------------------------
80891    -- 4219869 Business Flow
80892    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
80893    ------------------------------------------------------------------------------------
80894    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
80895 
80896    ----------------------------------------------------------------------------------
80897    -- 4219869 Business Flow
80898    -- Update journal entry status -- Need to generate this within IF <condition>
80899    ----------------------------------------------------------------------------------
80900    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
80901          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
80902          ,p_balance_type_code => l_balance_type_code
80903          );
80904 
80905    -------------------------------------------------------------------------------------------
80906    -- 4262811 - Generate the Accrual Reversal lines
80907    -------------------------------------------------------------------------------------------
80908    BEGIN
80909       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
80913       END IF;
80910                               (g_array_event(p_event_id).array_value_num('header_index'));
80911       IF l_acc_rev_flag IS NULL THEN
80912          l_acc_rev_flag := 'N';
80914    EXCEPTION
80915       WHEN OTHERS THEN
80916          l_acc_rev_flag := 'N';
80917    END;
80918    --
80919    IF (l_acc_rev_flag = 'Y') THEN
80920 
80921        -- 4645092  ------------------------------------------------------------------------------
80922        -- To allow MPA report to determine if it should generate report process
80923        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
80924        ------------------------------------------------------------------------------------------
80925 
80926        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
80927        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
80928    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
80929    -- call ADRs
80930    -- Bug 4922099
80931    --
80932    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
80933         (NVL(l_actual_upg_option, 'N') = 'O') OR
80934         (NVL(l_enc_upg_option, 'N') = 'O')
80935       )
80936    THEN
80937    NULL;
80938    --
80939    --
80940    
80941   l_ccid := AcctDerRule_177(
80942            p_application_id           => p_application_id
80943          , p_ae_header_id             => l_ae_header_id 
80944 , p_source_30 => p_source_30
80945 , p_source_32 => p_source_32
80946          , x_transaction_coa_id       => l_adr_transaction_coa_id
80947          , x_accounting_coa_id        => l_adr_accounting_coa_id
80948          , x_value_type_code          => l_adr_value_type_code
80949          , p_side                     => 'NA'
80950    );
80951 
80952    xla_ae_lines_pkg.set_ccid(
80953     p_code_combination_id          => l_ccid
80954   , p_value_type_code              => l_adr_value_type_code
80955   , p_transaction_coa_id           => l_adr_transaction_coa_id
80956   , p_accounting_coa_id            => l_adr_accounting_coa_id
80957   , p_adr_code                     => 'FA_PER_BONUS_DEPRN_RESERVE'
80958   , p_adr_type_code                => 'S'
80959   , p_component_type               => l_component_type
80960   , p_component_code               => l_component_code
80961   , p_component_type_code          => l_component_type_code
80962   , p_component_appl_id            => l_component_appl_id
80963   , p_amb_context_code             => l_amb_context_code
80964   , p_side                         => 'NA'
80965   );
80966 
80967 
80968    l_segment := AcctDerRule_144(
80969            p_application_id           => p_application_id
80970          , p_ae_header_id             => l_ae_header_id 
80971 , p_source_3 => p_source_3
80972 , p_source_4 => p_source_4
80973          , x_transaction_coa_id       => l_adr_transaction_coa_id
80974          , x_accounting_coa_id        => l_adr_accounting_coa_id
80975          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
80976          , x_flex_value_set_id        => l_adr_flex_value_set_id
80977          , x_value_type_code          => l_adr_value_type_code
80978          , x_value_combination_id     => l_adr_value_combination_id
80979          , x_value_segment_code       => l_adr_value_segment_code
80980          , p_side                     => 'NA'
80981          , p_override_seg_flag        => 'Y'
80982    );
80983 
80984    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
80985 
80986       xla_ae_lines_pkg.set_segment(
80987           p_to_segment_code         => 'GL_ACCOUNT'
80988         , p_segment_value           => l_segment
80989         , p_from_segment_code       => l_adr_value_segment_code
80990         , p_from_combination_id     => l_adr_value_combination_id
80991         , p_value_type_code         => l_adr_value_type_code
80992         , p_transaction_coa_id      => l_adr_transaction_coa_id
80993         , p_accounting_coa_id       => l_adr_accounting_coa_id
80994         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
80995         , p_flex_value_set_id       => l_adr_flex_value_set_id
80996         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
80997         , p_adr_type_code           => 'S'
80998         , p_component_type          => l_component_type
80999         , p_component_code          => l_component_code
81000         , p_component_type_code     => l_component_type_code
81001         , p_component_appl_id       => l_component_appl_id
81002         , p_amb_context_code        => l_amb_context_code
81003         , p_entity_code             => 'DEPRECIATION'
81004         , p_event_class_code        => 'DEPRECIATION'
81005         , p_side                    => 'NA'
81006         );
81007 
81008   END IF;
81009 
81010    l_segment := AcctDerRule_168(
81011            p_application_id           => p_application_id
81012          , p_ae_header_id             => l_ae_header_id 
81013 , p_source_3 => p_source_3
81014 , p_source_29 => p_source_29
81015          , x_transaction_coa_id       => l_adr_transaction_coa_id
81016          , x_accounting_coa_id        => l_adr_accounting_coa_id
81017          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
81018          , x_flex_value_set_id        => l_adr_flex_value_set_id
81019          , x_value_type_code          => l_adr_value_type_code
81020          , x_value_combination_id     => l_adr_value_combination_id
81021          , x_value_segment_code       => l_adr_value_segment_code
81022          , p_side                     => 'NA'
81023          , p_override_seg_flag        => 'Y'
81024    );
81025 
81026    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
81027 
81028       xla_ae_lines_pkg.set_segment(
81029           p_to_segment_code         => 'GL_BALANCING'
81030         , p_segment_value           => l_segment
81031         , p_from_segment_code       => l_adr_value_segment_code
81032         , p_from_combination_id     => l_adr_value_combination_id
81036         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
81033         , p_value_type_code         => l_adr_value_type_code
81034         , p_transaction_coa_id      => l_adr_transaction_coa_id
81035         , p_accounting_coa_id       => l_adr_accounting_coa_id
81037         , p_flex_value_set_id       => l_adr_flex_value_set_id
81038         , p_adr_code                => 'FA_EXPENSE_ACCT'
81039         , p_adr_type_code           => 'S'
81040         , p_component_type          => l_component_type
81041         , p_component_code          => l_component_code
81042         , p_component_type_code     => l_component_type_code
81043         , p_component_appl_id       => l_component_appl_id
81044         , p_amb_context_code        => l_amb_context_code
81045         , p_entity_code             => 'DEPRECIATION'
81046         , p_event_class_code        => 'DEPRECIATION'
81047         , p_side                    => 'NA'
81048         );
81049 
81050   END IF;
81051 
81052    --
81053    --
81054    END IF;
81055 
81056        --
81057        -- Update the line information that should be overwritten
81058        --
81059        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
81060                                          p_header_num   => 1);
81061        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
81062 
81063        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
81064 
81065        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
81066           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
81067        END IF;
81068 
81069       --
81070       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
81071       --
81072       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
81073           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
81074       ELSE
81075           ---------------------------------------------------------------------------------------------------
81076           -- 4262811a Switch Sign
81077           ---------------------------------------------------------------------------------------------------
81078           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
81079           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
81080                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
81081           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
81082                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
81083           -- 5132302
81084           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
81085                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
81086 
81087       END IF;
81088 
81089       -- 4955764
81090       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
81091       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
81092 
81093 
81094       XLA_AE_LINES_PKG.ValidateCurrentLine;
81095       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
81096 
81097       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
81098                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
81099                ,p_balance_type_code => l_balance_type_code);
81100 
81101    END IF;
81102 
81103    -----------------------------------------------------------------------------------------
81104    -- 4262811 Multiperiod Accounting
81105    -----------------------------------------------------------------------------------------
81106      -- No MPA option is assigned.
81107 
81108 
81109 END IF;
81110 END IF;
81111 --
81112 
81113 --
81114 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
81115    trace
81116       (p_msg      => 'END of AcctLineType_266'
81117       ,p_level    => C_LEVEL_PROCEDURE
81118       ,p_module   => l_log_module);
81119 END IF;
81120 --
81121 EXCEPTION
81122   WHEN xla_exceptions_pkg.application_exception THEN
81123       RAISE;
81124   WHEN OTHERS THEN
81125        xla_exceptions_pkg.raise_message
81126            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_266');
81127 END AcctLineType_266;
81128 --
81129 
81130 ---------------------------------------
81131 --
81132 -- PRIVATE FUNCTION
81133 --         AcctLineType_267
81134 --
81135 ---------------------------------------
81136 PROCEDURE AcctLineType_267 (
81137   p_application_id        IN NUMBER
81138  ,p_event_id              IN NUMBER
81139  ,p_calculate_acctd_flag  IN VARCHAR2
81140  ,p_calculate_g_l_flag    IN VARCHAR2
81141  ,p_actual_flag           IN OUT VARCHAR2
81142  ,p_balance_type_code     OUT VARCHAR2
81143  ,p_gain_or_loss_ref      OUT VARCHAR2
81144  
81145 --Period Close Date
81146  , p_source_1            IN DATE
81147 --Generated Code Combination Identifier
81148  , p_source_3            IN NUMBER
81149 --Expense Account Code Combination Identifier
81150  , p_source_29            IN NUMBER
81151 --Distribution Type Code
81152  , p_source_38            IN VARCHAR2
81153 --Entered Amount
81154  , p_source_39            IN NUMBER
81155 --Currency Code
81156  , p_source_40            IN VARCHAR2
81157 --Asset Identifier
81158  , p_source_43            IN NUMBER
81159 --Period Counter
81160  , p_source_44            IN NUMBER
81161 --Distribution Identifier
81162  , p_source_45            IN NUMBER
81163 --Book Type Code
81167 )
81164  , p_source_46            IN VARCHAR2
81165 --Depreciation Run Identifier
81166  , p_source_49            IN NUMBER
81168 IS
81169 
81170 l_component_type              VARCHAR2(80);
81171 l_component_code              VARCHAR2(30);
81172 l_component_type_code         VARCHAR2(1);
81173 l_component_appl_id           INTEGER;
81174 l_amb_context_code            VARCHAR2(30);
81175 l_entity_code                 VARCHAR2(30);
81176 l_event_class_code            VARCHAR2(30);
81177 l_ae_header_id                NUMBER;
81178 l_event_type_code             VARCHAR2(30);
81179 l_line_definition_code        VARCHAR2(30);
81180 l_line_definition_owner_code  VARCHAR2(1);
81181 --
81182 -- adr variables
81183 l_segment                     VARCHAR2(30);
81184 l_ccid                        NUMBER;
81185 l_adr_transaction_coa_id      NUMBER;
81186 l_adr_accounting_coa_id       NUMBER;
81187 l_adr_flexfield_segment_code  VARCHAR2(30);
81188 l_adr_flex_value_set_id       NUMBER;
81189 l_adr_value_type_code         VARCHAR2(30);
81190 l_adr_value_combination_id    NUMBER;
81191 l_adr_value_segment_code      VARCHAR2(30);
81192 
81193 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
81194 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
81195 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
81196 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
81197 
81198 -- 4262811 Variables ------------------------------------------------------------------------------------------
81199 l_entered_amt_idx             NUMBER;
81200 l_accted_amt_idx              NUMBER;
81201 l_acc_rev_flag                VARCHAR2(1);
81202 l_accrual_line_num            NUMBER;
81203 l_tmp_amt                     NUMBER;
81204 l_acc_rev_natural_side_code   VARCHAR2(1);
81205 
81206 l_num_entries                 NUMBER;
81207 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
81208 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
81209 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
81210 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
81211 l_recog_line_1                NUMBER;
81212 l_recog_line_2                NUMBER;
81213 
81214 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
81215 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
81216 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
81217 
81218 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
81219 
81220 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
81221 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
81222 
81223 ---------------------------------------------------------------------------------------------------------------
81224 
81225 
81226 --
81227 -- bulk performance
81228 --
81229 l_balance_type_code           VARCHAR2(1);
81230 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
81231 l_log_module                  VARCHAR2(240);
81232 
81233 --
81234 -- Upgrade strategy
81235 --
81236 l_actual_upg_option           VARCHAR2(1);
81237 l_enc_upg_option           VARCHAR2(1);
81238 
81239 --
81240 BEGIN
81241 --
81242 IF g_log_enabled THEN
81243       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_267';
81244 END IF;
81245 --
81246 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
81247 
81248       trace
81249          (p_msg      => 'BEGIN of AcctLineType_267'
81250          ,p_level    => C_LEVEL_PROCEDURE
81251          ,p_module   => l_log_module);
81252 
81253 END IF;
81254 --
81255 l_component_type             := 'AMB_JLT';
81256 l_component_code             := 'FA_PER_DEPRN_EXP';
81257 l_component_type_code        := 'S';
81258 l_component_appl_id          :=  140;
81259 l_amb_context_code           := 'DEFAULT';
81260 l_entity_code                := 'DEPRECIATION';
81261 l_event_class_code           := 'DEPRECIATION';
81262 l_event_type_code            := 'DEPRECIATION_ALL';
81263 l_line_definition_owner_code := 'S';
81264 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE16';
81265 --
81266 l_balance_type_code          := 'A';
81267 l_segment                     := NULL;
81268 l_ccid                        := NULL;
81269 l_adr_transaction_coa_id      := NULL;
81270 l_adr_accounting_coa_id       := NULL;
81271 l_adr_flexfield_segment_code  := NULL;
81272 l_adr_flex_value_set_id       := NULL;
81273 l_adr_value_type_code         := NULL;
81274 l_adr_value_combination_id    := NULL;
81275 l_adr_value_segment_code      := NULL;
81276 
81277 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
81278 l_bflow_class_code           := '';    -- 4219869 Business Flow
81279 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
81280 l_budgetary_control_flag     := 'N';
81281 
81282 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
81283 l_bflow_applied_to_amt       := NULL; -- 5132302
81284 l_entered_amt_idx            := NULL;          -- 4262811
81285 l_accted_amt_idx             := NULL;          -- 4262811
81286 l_acc_rev_flag               := NULL;          -- 4262811
81287 l_accrual_line_num           := NULL;          -- 4262811
81288 l_tmp_amt                    := NULL;          -- 4262811
81289 --
81290  
81291 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
81292     l_balance_type_code <> 'B' THEN
81293 IF NVL(p_source_39,9E125) <>  0 AND 
81294 NVL(p_source_38,'
81295 ') =  'DEPRN'
81296  THEN 
81297 
81298    --
81299    XLA_AE_LINES_PKG.SetNewLine;
81300 
81301    p_balance_type_code          := l_balance_type_code;
81305      p_actual_flag :='A';
81302    -- set the flag so later we will know whether the gain loss line needs to be created
81303    
81304    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
81306    END IF;
81307 
81308    --
81309    -- bulk performance
81310    --
81311    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
81312                                       p_header_num   => 0); -- 4262811
81313    --
81314    -- set accounting line options
81315    --
81316    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
81317            p_natural_side_code          => 'D'
81318          , p_gain_or_loss_flag          => 'N'
81319          , p_gl_transfer_mode_code      => 'S'
81320          , p_acct_entry_type_code       => 'A'
81321          , p_switch_side_flag           => 'Y'
81322          , p_merge_duplicate_code       => 'N'
81323          );
81324    --
81325    l_acc_rev_natural_side_code := 'C';  -- 4262811
81326    -- 
81327    --
81328    -- set accounting line type info
81329    --
81330    xla_ae_lines_pkg.SetAcctLineType
81331       (p_component_type             => l_component_type
81332       ,p_event_type_code            => l_event_type_code
81333       ,p_line_definition_owner_code => l_line_definition_owner_code
81334       ,p_line_definition_code       => l_line_definition_code
81335       ,p_accounting_line_code       => l_component_code
81336       ,p_accounting_line_type_code  => l_component_type_code
81337       ,p_accounting_line_appl_id    => l_component_appl_id
81338       ,p_amb_context_code           => l_amb_context_code
81339       ,p_entity_code                => l_entity_code
81340       ,p_event_class_code           => l_event_class_code);
81341    --
81342    -- set accounting class
81343    --
81344    xla_ae_lines_pkg.SetAcctClass(
81345            p_accounting_class_code  => 'EXPENSE'
81346          , p_ae_header_id           => l_ae_header_id
81347          );
81348 
81349    --
81350    -- set rounding class
81351    --
81352    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
81353                       'EXPENSE';
81354 
81355    --
81356    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
81357    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
81358    --
81359    -- bulk performance
81360    --
81361    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
81362 
81363    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
81364       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
81365 
81366    -- 4955764
81367    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
81368       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
81369 
81370    -- 4458381 Public Sector Enh
81371    
81372    --
81373    -- set accounting attributes for the line type
81374    --
81375    l_entered_amt_idx := 7;
81376    l_accted_amt_idx  := 9;
81377    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
81378    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
81379    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
81380    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
81381    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
81382    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
81383    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_49);
81384    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
81385    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
81386    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
81387    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_45);
81388    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
81389    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
81390    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
81391    l_rec_acct_attrs.array_num_value(7)  := p_source_39;
81392    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
81393    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
81394    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
81395    l_rec_acct_attrs.array_num_value(9)  := p_source_39;
81396 
81397    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
81398    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
81399 
81400    ---------------------------------------------------------------------------------------------------------------
81401    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
81402    ---------------------------------------------------------------------------------------------------------------
81403    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
81404 
81405    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
81406    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
81407 
81408    IF xla_accounting_cache_pkg.GetValueChar
81409          (p_source_code         => 'LEDGER_CATEGORY_CODE'
81410          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
81411    AND l_bflow_method_code = 'PRIOR_ENTRY'
81412 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
81413    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
81414          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
81415        )
81416    THEN
81417          xla_ae_lines_pkg.BflowUpgEntry
81418            (p_business_method_code    => l_bflow_method_code
81422       NULL;
81419            ,p_business_class_code     => l_bflow_class_code
81420            ,p_balance_type            => l_balance_type_code);
81421    ELSE
81423 -- No business flow processing for business flow method of NONE.
81424    END IF;
81425 
81426    --
81427    -- call analytical criteria
81428    --
81429    
81430    --
81431    -- call description
81432    --
81433    
81434 xla_ae_lines_pkg.SetLineDescription(
81435    p_ae_header_id => l_ae_header_id
81436   ,p_description  => Description_57 (
81437      p_application_id         => p_application_id
81438    , p_ae_header_id           => l_ae_header_id 
81439 , p_source_1 => p_source_1
81440    )
81441 );
81442 
81443 
81444    --
81445    -- call ADRs
81446    -- Bug 4922099
81447    --
81448    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
81449         (NVL(l_actual_upg_option, 'N') = 'O') OR
81450         (NVL(l_enc_upg_option, 'N') = 'O')
81451       )
81452    THEN
81453    NULL;
81454    --
81455    --
81456    
81457   l_ccid := AcctDerRule_175(
81458            p_application_id           => p_application_id
81459          , p_ae_header_id             => l_ae_header_id 
81460 , p_source_3 => p_source_3
81461 , p_source_29 => p_source_29
81462          , x_transaction_coa_id       => l_adr_transaction_coa_id
81463          , x_accounting_coa_id        => l_adr_accounting_coa_id
81464          , x_value_type_code          => l_adr_value_type_code
81465          , p_side                     => 'NA'
81466    );
81467 
81468    xla_ae_lines_pkg.set_ccid(
81469     p_code_combination_id          => l_ccid
81470   , p_value_type_code              => l_adr_value_type_code
81471   , p_transaction_coa_id           => l_adr_transaction_coa_id
81472   , p_accounting_coa_id            => l_adr_accounting_coa_id
81473   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
81474   , p_adr_type_code                => 'S'
81475   , p_component_type               => l_component_type
81476   , p_component_code               => l_component_code
81477   , p_component_type_code          => l_component_type_code
81478   , p_component_appl_id            => l_component_appl_id
81479   , p_amb_context_code             => l_amb_context_code
81480   , p_side                         => 'NA'
81481   );
81482 
81483 
81484    --
81485    --
81486    END IF;
81487    --
81488    -- Bug 4922099
81489    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
81490           (NVL(l_enc_upg_option, 'N') = 'O')
81491         ) AND
81492         (l_bflow_method_code = 'PRIOR_ENTRY')
81493       )
81494    THEN
81495       IF
81496       --
81497       1 = 2
81498       --
81499       THEN
81500       xla_accounting_err_pkg.build_message
81501                                     (p_appli_s_name            => 'XLA'
81502                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
81503                                     ,p_token_1                 => 'LINE_NUMBER'
81504                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
81505                                     ,p_token_2                 => 'LINE_TYPE_NAME'
81506                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
81507                                                                              l_component_type
81508                                                                             ,l_component_code
81509                                                                             ,l_component_type_code
81510                                                                             ,l_component_appl_id
81511                                                                             ,l_amb_context_code
81512                                                                             ,l_entity_code
81513                                                                             ,l_event_class_code
81514                                                                            )
81515                                     ,p_token_3                 => 'OWNER'
81516                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
81517                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
81518                                                                           ,p_lookup_code    => l_component_type_code
81519                                                                          )
81520                                     ,p_token_4                 => 'PRODUCT_NAME'
81521                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
81522                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
81523                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
81524                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
81525                                     ,p_ae_header_id            =>  NULL
81526                                        );
81527 
81528         IF (C_LEVEL_ERROR>= g_log_level) THEN
81529                  trace
81530                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
81531                       ,p_level    => C_LEVEL_ERROR
81532                       ,p_module   => l_log_module);
81533         END IF;
81534       END IF;
81535    END IF;
81536    --
81537    --
81538    ------------------------------------------------------------------------------------------------
81539    -- 4219869 Business Flow
81540    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
81541    -- Prior Entry.  Currently, the following code is always generated.
81545    ------------------------------------------------------------------------------------
81542    ------------------------------------------------------------------------------------------------
81543    XLA_AE_LINES_PKG.ValidateCurrentLine;
81544 
81546    -- 4219869 Business Flow
81547    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
81548    ------------------------------------------------------------------------------------
81549    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
81550 
81551    ----------------------------------------------------------------------------------
81552    -- 4219869 Business Flow
81553    -- Update journal entry status -- Need to generate this within IF <condition>
81554    ----------------------------------------------------------------------------------
81555    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
81556          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
81557          ,p_balance_type_code => l_balance_type_code
81558          );
81559 
81560    -------------------------------------------------------------------------------------------
81561    -- 4262811 - Generate the Accrual Reversal lines
81562    -------------------------------------------------------------------------------------------
81563    BEGIN
81564       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
81565                               (g_array_event(p_event_id).array_value_num('header_index'));
81566       IF l_acc_rev_flag IS NULL THEN
81567          l_acc_rev_flag := 'N';
81568       END IF;
81569    EXCEPTION
81570       WHEN OTHERS THEN
81571          l_acc_rev_flag := 'N';
81572    END;
81573    --
81574    IF (l_acc_rev_flag = 'Y') THEN
81575 
81576        -- 4645092  ------------------------------------------------------------------------------
81577        -- To allow MPA report to determine if it should generate report process
81578        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
81579        ------------------------------------------------------------------------------------------
81580 
81581        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
81582        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
81583    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
81584    -- call ADRs
81585    -- Bug 4922099
81586    --
81587    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
81588         (NVL(l_actual_upg_option, 'N') = 'O') OR
81589         (NVL(l_enc_upg_option, 'N') = 'O')
81590       )
81591    THEN
81592    NULL;
81593    --
81594    --
81595    
81596   l_ccid := AcctDerRule_175(
81597            p_application_id           => p_application_id
81598          , p_ae_header_id             => l_ae_header_id 
81599 , p_source_3 => p_source_3
81600 , p_source_29 => p_source_29
81601          , x_transaction_coa_id       => l_adr_transaction_coa_id
81602          , x_accounting_coa_id        => l_adr_accounting_coa_id
81603          , x_value_type_code          => l_adr_value_type_code
81604          , p_side                     => 'NA'
81605    );
81606 
81607    xla_ae_lines_pkg.set_ccid(
81608     p_code_combination_id          => l_ccid
81609   , p_value_type_code              => l_adr_value_type_code
81610   , p_transaction_coa_id           => l_adr_transaction_coa_id
81611   , p_accounting_coa_id            => l_adr_accounting_coa_id
81612   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
81613   , p_adr_type_code                => 'S'
81614   , p_component_type               => l_component_type
81615   , p_component_code               => l_component_code
81616   , p_component_type_code          => l_component_type_code
81617   , p_component_appl_id            => l_component_appl_id
81618   , p_amb_context_code             => l_amb_context_code
81619   , p_side                         => 'NA'
81620   );
81621 
81622 
81623    --
81624    --
81625    END IF;
81626 
81627        --
81628        -- Update the line information that should be overwritten
81629        --
81630        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
81631                                          p_header_num   => 1);
81632        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
81633 
81634        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
81635 
81636        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
81637           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
81638        END IF;
81639 
81640       --
81641       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
81642       --
81643       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
81644           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
81645       ELSE
81646           ---------------------------------------------------------------------------------------------------
81647           -- 4262811a Switch Sign
81648           ---------------------------------------------------------------------------------------------------
81649           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
81650           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
81651                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
81652           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
81653                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
81654           -- 5132302
81655           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
81659 
81656                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
81657 
81658       END IF;
81660       -- 4955764
81661       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
81662       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
81663 
81664 
81665       XLA_AE_LINES_PKG.ValidateCurrentLine;
81666       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
81667 
81668       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
81669                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
81670                ,p_balance_type_code => l_balance_type_code);
81671 
81672    END IF;
81673 
81674    -----------------------------------------------------------------------------------------
81675    -- 4262811 Multiperiod Accounting
81676    -----------------------------------------------------------------------------------------
81677      -- No MPA option is assigned.
81678 
81679 
81680 END IF;
81681 END IF;
81682 --
81683 
81684 --
81685 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
81686    trace
81687       (p_msg      => 'END of AcctLineType_267'
81688       ,p_level    => C_LEVEL_PROCEDURE
81689       ,p_module   => l_log_module);
81690 END IF;
81691 --
81692 EXCEPTION
81693   WHEN xla_exceptions_pkg.application_exception THEN
81694       RAISE;
81695   WHEN OTHERS THEN
81696        xla_exceptions_pkg.raise_message
81697            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_267');
81698 END AcctLineType_267;
81699 --
81700 
81701 ---------------------------------------
81702 --
81703 -- PRIVATE FUNCTION
81704 --         AcctLineType_268
81705 --
81706 ---------------------------------------
81707 PROCEDURE AcctLineType_268 (
81708   p_application_id        IN NUMBER
81709  ,p_event_id              IN NUMBER
81710  ,p_calculate_acctd_flag  IN VARCHAR2
81711  ,p_calculate_g_l_flag    IN VARCHAR2
81712  ,p_actual_flag           IN OUT VARCHAR2
81713  ,p_balance_type_code     OUT VARCHAR2
81714  ,p_gain_or_loss_ref      OUT VARCHAR2
81715  
81716 --Period Close Date
81717  , p_source_1            IN DATE
81718 --Generated Code Combination Identifier
81719  , p_source_3            IN NUMBER
81720 --Depreciation Reserve Account
81721  , p_source_10            IN VARCHAR2
81722 --Generated Offset Code Combination Identifier
81723  , p_source_17            IN NUMBER
81724 --Expense Account Code Combination Identifier
81725  , p_source_29            IN NUMBER
81726 --Default Code Combination Identifier
81727  , p_source_30            IN NUMBER
81728 --Distribution Type Code
81729  , p_source_38            IN VARCHAR2
81730 --Entered Amount
81731  , p_source_39            IN NUMBER
81732 --Currency Code
81733  , p_source_40            IN VARCHAR2
81734 --Asset Identifier
81735  , p_source_43            IN NUMBER
81736 --Period Counter
81737  , p_source_44            IN NUMBER
81738 --Distribution Identifier
81739  , p_source_45            IN NUMBER
81740 --Book Type Code
81741  , p_source_46            IN VARCHAR2
81742 --Depreciation Run Identifier
81743  , p_source_49            IN NUMBER
81744 )
81745 IS
81746 
81747 l_component_type              VARCHAR2(80);
81748 l_component_code              VARCHAR2(30);
81749 l_component_type_code         VARCHAR2(1);
81750 l_component_appl_id           INTEGER;
81751 l_amb_context_code            VARCHAR2(30);
81752 l_entity_code                 VARCHAR2(30);
81753 l_event_class_code            VARCHAR2(30);
81754 l_ae_header_id                NUMBER;
81755 l_event_type_code             VARCHAR2(30);
81756 l_line_definition_code        VARCHAR2(30);
81757 l_line_definition_owner_code  VARCHAR2(1);
81758 --
81759 -- adr variables
81760 l_segment                     VARCHAR2(30);
81761 l_ccid                        NUMBER;
81762 l_adr_transaction_coa_id      NUMBER;
81763 l_adr_accounting_coa_id       NUMBER;
81764 l_adr_flexfield_segment_code  VARCHAR2(30);
81765 l_adr_flex_value_set_id       NUMBER;
81766 l_adr_value_type_code         VARCHAR2(30);
81767 l_adr_value_combination_id    NUMBER;
81768 l_adr_value_segment_code      VARCHAR2(30);
81769 
81770 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
81771 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
81772 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
81773 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
81774 
81775 -- 4262811 Variables ------------------------------------------------------------------------------------------
81776 l_entered_amt_idx             NUMBER;
81777 l_accted_amt_idx              NUMBER;
81778 l_acc_rev_flag                VARCHAR2(1);
81779 l_accrual_line_num            NUMBER;
81780 l_tmp_amt                     NUMBER;
81781 l_acc_rev_natural_side_code   VARCHAR2(1);
81782 
81783 l_num_entries                 NUMBER;
81784 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
81785 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
81786 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
81787 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
81788 l_recog_line_1                NUMBER;
81789 l_recog_line_2                NUMBER;
81790 
81791 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
81792 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
81793 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
81794 
81795 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
81796 
81800 ---------------------------------------------------------------------------------------------------------------
81797 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
81798 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
81799 
81801 
81802 
81803 --
81804 -- bulk performance
81805 --
81806 l_balance_type_code           VARCHAR2(1);
81807 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
81808 l_log_module                  VARCHAR2(240);
81809 
81810 --
81811 -- Upgrade strategy
81812 --
81813 l_actual_upg_option           VARCHAR2(1);
81814 l_enc_upg_option           VARCHAR2(1);
81815 
81816 --
81817 BEGIN
81818 --
81819 IF g_log_enabled THEN
81820       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_268';
81821 END IF;
81822 --
81823 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
81824 
81825       trace
81826          (p_msg      => 'BEGIN of AcctLineType_268'
81827          ,p_level    => C_LEVEL_PROCEDURE
81828          ,p_module   => l_log_module);
81829 
81830 END IF;
81831 --
81832 l_component_type             := 'AMB_JLT';
81833 l_component_code             := 'FA_PER_DEPRN_RESERVE';
81834 l_component_type_code        := 'S';
81835 l_component_appl_id          :=  140;
81836 l_amb_context_code           := 'DEFAULT';
81837 l_entity_code                := 'DEPRECIATION';
81838 l_event_class_code           := 'DEPRECIATION';
81839 l_event_type_code            := 'DEPRECIATION_ALL';
81840 l_line_definition_owner_code := 'S';
81841 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE16';
81842 --
81843 l_balance_type_code          := 'A';
81844 l_segment                     := NULL;
81845 l_ccid                        := NULL;
81846 l_adr_transaction_coa_id      := NULL;
81847 l_adr_accounting_coa_id       := NULL;
81848 l_adr_flexfield_segment_code  := NULL;
81849 l_adr_flex_value_set_id       := NULL;
81850 l_adr_value_type_code         := NULL;
81851 l_adr_value_combination_id    := NULL;
81852 l_adr_value_segment_code      := NULL;
81853 
81854 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
81855 l_bflow_class_code           := '';    -- 4219869 Business Flow
81856 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
81857 l_budgetary_control_flag     := 'N';
81858 
81859 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
81860 l_bflow_applied_to_amt       := NULL; -- 5132302
81861 l_entered_amt_idx            := NULL;          -- 4262811
81862 l_accted_amt_idx             := NULL;          -- 4262811
81863 l_acc_rev_flag               := NULL;          -- 4262811
81864 l_accrual_line_num           := NULL;          -- 4262811
81865 l_tmp_amt                    := NULL;          -- 4262811
81866 --
81867  
81868 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
81869     l_balance_type_code <> 'B' THEN
81870 IF NVL(p_source_39,9E125) <>  0 AND 
81871 NVL(p_source_38,'
81872 ') =  'DEPRN'
81873  THEN 
81874 
81875    --
81876    XLA_AE_LINES_PKG.SetNewLine;
81877 
81878    p_balance_type_code          := l_balance_type_code;
81879    -- set the flag so later we will know whether the gain loss line needs to be created
81880    
81881    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
81882      p_actual_flag :='A';
81883    END IF;
81884 
81885    --
81886    -- bulk performance
81887    --
81888    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
81889                                       p_header_num   => 0); -- 4262811
81890    --
81891    -- set accounting line options
81892    --
81893    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
81894            p_natural_side_code          => 'C'
81895          , p_gain_or_loss_flag          => 'N'
81896          , p_gl_transfer_mode_code      => 'S'
81897          , p_acct_entry_type_code       => 'A'
81898          , p_switch_side_flag           => 'Y'
81899          , p_merge_duplicate_code       => 'N'
81900          );
81901    --
81902    l_acc_rev_natural_side_code := 'D';  -- 4262811
81903    -- 
81904    --
81905    -- set accounting line type info
81906    --
81907    xla_ae_lines_pkg.SetAcctLineType
81908       (p_component_type             => l_component_type
81909       ,p_event_type_code            => l_event_type_code
81910       ,p_line_definition_owner_code => l_line_definition_owner_code
81911       ,p_line_definition_code       => l_line_definition_code
81912       ,p_accounting_line_code       => l_component_code
81913       ,p_accounting_line_type_code  => l_component_type_code
81914       ,p_accounting_line_appl_id    => l_component_appl_id
81915       ,p_amb_context_code           => l_amb_context_code
81916       ,p_entity_code                => l_entity_code
81917       ,p_event_class_code           => l_event_class_code);
81918    --
81919    -- set accounting class
81920    --
81921    xla_ae_lines_pkg.SetAcctClass(
81922            p_accounting_class_code  => 'ASSET'
81923          , p_ae_header_id           => l_ae_header_id
81924          );
81925 
81926    --
81927    -- set rounding class
81928    --
81929    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
81930                       'ASSET';
81931 
81932    --
81933    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
81934    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
81935    --
81936    -- bulk performance
81937    --
81938    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
81939 
81943    -- 4955764
81940    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
81941       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
81942 
81944    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
81945       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
81946 
81947    -- 4458381 Public Sector Enh
81948    
81949    --
81950    -- set accounting attributes for the line type
81951    --
81952    l_entered_amt_idx := 7;
81953    l_accted_amt_idx  := 9;
81954    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
81955    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
81956    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
81957    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
81958    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
81959    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
81960    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_49);
81961    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
81962    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
81963    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
81964    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_45);
81965    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
81966    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
81967    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
81968    l_rec_acct_attrs.array_num_value(7)  := p_source_39;
81969    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
81970    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
81971    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
81972    l_rec_acct_attrs.array_num_value(9)  := p_source_39;
81973 
81974    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
81975    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
81976 
81977    ---------------------------------------------------------------------------------------------------------------
81978    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
81979    ---------------------------------------------------------------------------------------------------------------
81980    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
81981 
81982    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
81983    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
81984 
81985    IF xla_accounting_cache_pkg.GetValueChar
81986          (p_source_code         => 'LEDGER_CATEGORY_CODE'
81987          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
81988    AND l_bflow_method_code = 'PRIOR_ENTRY'
81989 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
81990    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
81991          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
81992        )
81993    THEN
81994          xla_ae_lines_pkg.BflowUpgEntry
81995            (p_business_method_code    => l_bflow_method_code
81996            ,p_business_class_code     => l_bflow_class_code
81997            ,p_balance_type            => l_balance_type_code);
81998    ELSE
81999       NULL;
82000 -- No business flow processing for business flow method of NONE.
82001    END IF;
82002 
82003    --
82004    -- call analytical criteria
82005    --
82006    
82007    --
82008    -- call description
82009    --
82010    
82011 xla_ae_lines_pkg.SetLineDescription(
82012    p_ae_header_id => l_ae_header_id
82013   ,p_description  => Description_59 (
82014      p_application_id         => p_application_id
82015    , p_ae_header_id           => l_ae_header_id 
82016 , p_source_1 => p_source_1
82017    )
82018 );
82019 
82020 
82021    --
82022    -- call ADRs
82023    -- Bug 4922099
82024    --
82025    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
82026         (NVL(l_actual_upg_option, 'N') = 'O') OR
82027         (NVL(l_enc_upg_option, 'N') = 'O')
82028       )
82029    THEN
82030    NULL;
82031    --
82032    --
82033    
82034   l_ccid := AcctDerRule_174(
82035            p_application_id           => p_application_id
82036          , p_ae_header_id             => l_ae_header_id 
82037 , p_source_3 => p_source_3
82038 , p_source_17 => p_source_17
82039 , p_source_30 => p_source_30
82040          , x_transaction_coa_id       => l_adr_transaction_coa_id
82041          , x_accounting_coa_id        => l_adr_accounting_coa_id
82042          , x_value_type_code          => l_adr_value_type_code
82043          , p_side                     => 'NA'
82044    );
82045 
82046    xla_ae_lines_pkg.set_ccid(
82047     p_code_combination_id          => l_ccid
82048   , p_value_type_code              => l_adr_value_type_code
82049   , p_transaction_coa_id           => l_adr_transaction_coa_id
82050   , p_accounting_coa_id            => l_adr_accounting_coa_id
82051   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
82052   , p_adr_type_code                => 'S'
82053   , p_component_type               => l_component_type
82054   , p_component_code               => l_component_code
82055   , p_component_type_code          => l_component_type_code
82056   , p_component_appl_id            => l_component_appl_id
82057   , p_amb_context_code             => l_amb_context_code
82058   , p_side                         => 'NA'
82059   );
82060 
82061 
82062    l_segment := AcctDerRule_149(
82063            p_application_id           => p_application_id
82064          , p_ae_header_id             => l_ae_header_id 
82068          , x_accounting_coa_id        => l_adr_accounting_coa_id
82065 , p_source_3 => p_source_3
82066 , p_source_10 => p_source_10
82067          , x_transaction_coa_id       => l_adr_transaction_coa_id
82069          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
82070          , x_flex_value_set_id        => l_adr_flex_value_set_id
82071          , x_value_type_code          => l_adr_value_type_code
82072          , x_value_combination_id     => l_adr_value_combination_id
82073          , x_value_segment_code       => l_adr_value_segment_code
82074          , p_side                     => 'NA'
82075          , p_override_seg_flag        => 'Y'
82076    );
82077 
82078    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
82079 
82080       xla_ae_lines_pkg.set_segment(
82081           p_to_segment_code         => 'GL_ACCOUNT'
82082         , p_segment_value           => l_segment
82083         , p_from_segment_code       => l_adr_value_segment_code
82084         , p_from_combination_id     => l_adr_value_combination_id
82085         , p_value_type_code         => l_adr_value_type_code
82086         , p_transaction_coa_id      => l_adr_transaction_coa_id
82087         , p_accounting_coa_id       => l_adr_accounting_coa_id
82088         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
82089         , p_flex_value_set_id       => l_adr_flex_value_set_id
82090         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
82091         , p_adr_type_code           => 'S'
82092         , p_component_type          => l_component_type
82093         , p_component_code          => l_component_code
82094         , p_component_type_code     => l_component_type_code
82095         , p_component_appl_id       => l_component_appl_id
82096         , p_amb_context_code        => l_amb_context_code
82097         , p_entity_code             => 'DEPRECIATION'
82098         , p_event_class_code        => 'DEPRECIATION'
82099         , p_side                    => 'NA'
82100         );
82101 
82102   END IF;
82103 
82104    l_segment := AcctDerRule_168(
82105            p_application_id           => p_application_id
82106          , p_ae_header_id             => l_ae_header_id 
82107 , p_source_3 => p_source_3
82108 , p_source_29 => p_source_29
82109          , x_transaction_coa_id       => l_adr_transaction_coa_id
82110          , x_accounting_coa_id        => l_adr_accounting_coa_id
82111          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
82112          , x_flex_value_set_id        => l_adr_flex_value_set_id
82113          , x_value_type_code          => l_adr_value_type_code
82114          , x_value_combination_id     => l_adr_value_combination_id
82115          , x_value_segment_code       => l_adr_value_segment_code
82116          , p_side                     => 'NA'
82117          , p_override_seg_flag        => 'Y'
82118    );
82119 
82120    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
82121 
82122       xla_ae_lines_pkg.set_segment(
82123           p_to_segment_code         => 'GL_BALANCING'
82124         , p_segment_value           => l_segment
82125         , p_from_segment_code       => l_adr_value_segment_code
82126         , p_from_combination_id     => l_adr_value_combination_id
82127         , p_value_type_code         => l_adr_value_type_code
82128         , p_transaction_coa_id      => l_adr_transaction_coa_id
82129         , p_accounting_coa_id       => l_adr_accounting_coa_id
82130         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
82131         , p_flex_value_set_id       => l_adr_flex_value_set_id
82132         , p_adr_code                => 'FA_EXPENSE_ACCT'
82133         , p_adr_type_code           => 'S'
82134         , p_component_type          => l_component_type
82135         , p_component_code          => l_component_code
82136         , p_component_type_code     => l_component_type_code
82137         , p_component_appl_id       => l_component_appl_id
82138         , p_amb_context_code        => l_amb_context_code
82139         , p_entity_code             => 'DEPRECIATION'
82140         , p_event_class_code        => 'DEPRECIATION'
82141         , p_side                    => 'NA'
82142         );
82143 
82144   END IF;
82145 
82146    --
82147    --
82148    END IF;
82149    --
82150    -- Bug 4922099
82151    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
82152           (NVL(l_enc_upg_option, 'N') = 'O')
82153         ) AND
82154         (l_bflow_method_code = 'PRIOR_ENTRY')
82155       )
82156    THEN
82157       IF
82158       --
82159       1 = 2
82160       --
82161       THEN
82162       xla_accounting_err_pkg.build_message
82163                                     (p_appli_s_name            => 'XLA'
82164                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
82165                                     ,p_token_1                 => 'LINE_NUMBER'
82166                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
82167                                     ,p_token_2                 => 'LINE_TYPE_NAME'
82168                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
82169                                                                              l_component_type
82170                                                                             ,l_component_code
82171                                                                             ,l_component_type_code
82172                                                                             ,l_component_appl_id
82173                                                                             ,l_amb_context_code
82174                                                                             ,l_entity_code
82175                                                                             ,l_event_class_code
82176                                                                            )
82180                                                                           ,p_lookup_code    => l_component_type_code
82177                                     ,p_token_3                 => 'OWNER'
82178                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
82179                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
82181                                                                          )
82182                                     ,p_token_4                 => 'PRODUCT_NAME'
82183                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
82184                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
82185                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
82186                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
82187                                     ,p_ae_header_id            =>  NULL
82188                                        );
82189 
82190         IF (C_LEVEL_ERROR>= g_log_level) THEN
82191                  trace
82192                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
82193                       ,p_level    => C_LEVEL_ERROR
82194                       ,p_module   => l_log_module);
82195         END IF;
82196       END IF;
82197    END IF;
82198    --
82199    --
82200    ------------------------------------------------------------------------------------------------
82201    -- 4219869 Business Flow
82202    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
82203    -- Prior Entry.  Currently, the following code is always generated.
82204    ------------------------------------------------------------------------------------------------
82205    XLA_AE_LINES_PKG.ValidateCurrentLine;
82206 
82207    ------------------------------------------------------------------------------------
82208    -- 4219869 Business Flow
82209    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
82210    ------------------------------------------------------------------------------------
82211    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
82212 
82213    ----------------------------------------------------------------------------------
82214    -- 4219869 Business Flow
82215    -- Update journal entry status -- Need to generate this within IF <condition>
82216    ----------------------------------------------------------------------------------
82217    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
82218          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
82219          ,p_balance_type_code => l_balance_type_code
82220          );
82221 
82222    -------------------------------------------------------------------------------------------
82223    -- 4262811 - Generate the Accrual Reversal lines
82224    -------------------------------------------------------------------------------------------
82225    BEGIN
82226       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
82227                               (g_array_event(p_event_id).array_value_num('header_index'));
82228       IF l_acc_rev_flag IS NULL THEN
82229          l_acc_rev_flag := 'N';
82230       END IF;
82231    EXCEPTION
82232       WHEN OTHERS THEN
82233          l_acc_rev_flag := 'N';
82234    END;
82235    --
82236    IF (l_acc_rev_flag = 'Y') THEN
82237 
82238        -- 4645092  ------------------------------------------------------------------------------
82239        -- To allow MPA report to determine if it should generate report process
82240        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
82241        ------------------------------------------------------------------------------------------
82242 
82243        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
82244        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
82245    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
82246    -- call ADRs
82247    -- Bug 4922099
82248    --
82249    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
82250         (NVL(l_actual_upg_option, 'N') = 'O') OR
82251         (NVL(l_enc_upg_option, 'N') = 'O')
82252       )
82253    THEN
82254    NULL;
82255    --
82256    --
82257    
82258   l_ccid := AcctDerRule_174(
82259            p_application_id           => p_application_id
82260          , p_ae_header_id             => l_ae_header_id 
82261 , p_source_3 => p_source_3
82262 , p_source_17 => p_source_17
82263 , p_source_30 => p_source_30
82264          , x_transaction_coa_id       => l_adr_transaction_coa_id
82265          , x_accounting_coa_id        => l_adr_accounting_coa_id
82266          , x_value_type_code          => l_adr_value_type_code
82267          , p_side                     => 'NA'
82268    );
82269 
82270    xla_ae_lines_pkg.set_ccid(
82271     p_code_combination_id          => l_ccid
82272   , p_value_type_code              => l_adr_value_type_code
82273   , p_transaction_coa_id           => l_adr_transaction_coa_id
82274   , p_accounting_coa_id            => l_adr_accounting_coa_id
82275   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
82276   , p_adr_type_code                => 'S'
82277   , p_component_type               => l_component_type
82278   , p_component_code               => l_component_code
82279   , p_component_type_code          => l_component_type_code
82280   , p_component_appl_id            => l_component_appl_id
82281   , p_amb_context_code             => l_amb_context_code
82282   , p_side                         => 'NA'
82283   );
82284 
82285 
82286    l_segment := AcctDerRule_149(
82287            p_application_id           => p_application_id
82288          , p_ae_header_id             => l_ae_header_id 
82289 , p_source_3 => p_source_3
82293          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
82290 , p_source_10 => p_source_10
82291          , x_transaction_coa_id       => l_adr_transaction_coa_id
82292          , x_accounting_coa_id        => l_adr_accounting_coa_id
82294          , x_flex_value_set_id        => l_adr_flex_value_set_id
82295          , x_value_type_code          => l_adr_value_type_code
82296          , x_value_combination_id     => l_adr_value_combination_id
82297          , x_value_segment_code       => l_adr_value_segment_code
82298          , p_side                     => 'NA'
82299          , p_override_seg_flag        => 'Y'
82300    );
82301 
82302    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
82303 
82304       xla_ae_lines_pkg.set_segment(
82305           p_to_segment_code         => 'GL_ACCOUNT'
82306         , p_segment_value           => l_segment
82307         , p_from_segment_code       => l_adr_value_segment_code
82308         , p_from_combination_id     => l_adr_value_combination_id
82309         , p_value_type_code         => l_adr_value_type_code
82310         , p_transaction_coa_id      => l_adr_transaction_coa_id
82311         , p_accounting_coa_id       => l_adr_accounting_coa_id
82312         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
82313         , p_flex_value_set_id       => l_adr_flex_value_set_id
82314         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
82315         , p_adr_type_code           => 'S'
82316         , p_component_type          => l_component_type
82317         , p_component_code          => l_component_code
82318         , p_component_type_code     => l_component_type_code
82319         , p_component_appl_id       => l_component_appl_id
82320         , p_amb_context_code        => l_amb_context_code
82321         , p_entity_code             => 'DEPRECIATION'
82322         , p_event_class_code        => 'DEPRECIATION'
82323         , p_side                    => 'NA'
82324         );
82325 
82326   END IF;
82327 
82328    l_segment := AcctDerRule_168(
82329            p_application_id           => p_application_id
82330          , p_ae_header_id             => l_ae_header_id 
82331 , p_source_3 => p_source_3
82332 , p_source_29 => p_source_29
82333          , x_transaction_coa_id       => l_adr_transaction_coa_id
82334          , x_accounting_coa_id        => l_adr_accounting_coa_id
82335          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
82336          , x_flex_value_set_id        => l_adr_flex_value_set_id
82337          , x_value_type_code          => l_adr_value_type_code
82338          , x_value_combination_id     => l_adr_value_combination_id
82339          , x_value_segment_code       => l_adr_value_segment_code
82340          , p_side                     => 'NA'
82341          , p_override_seg_flag        => 'Y'
82342    );
82343 
82344    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
82345 
82346       xla_ae_lines_pkg.set_segment(
82347           p_to_segment_code         => 'GL_BALANCING'
82348         , p_segment_value           => l_segment
82349         , p_from_segment_code       => l_adr_value_segment_code
82350         , p_from_combination_id     => l_adr_value_combination_id
82351         , p_value_type_code         => l_adr_value_type_code
82352         , p_transaction_coa_id      => l_adr_transaction_coa_id
82353         , p_accounting_coa_id       => l_adr_accounting_coa_id
82354         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
82355         , p_flex_value_set_id       => l_adr_flex_value_set_id
82356         , p_adr_code                => 'FA_EXPENSE_ACCT'
82357         , p_adr_type_code           => 'S'
82358         , p_component_type          => l_component_type
82359         , p_component_code          => l_component_code
82360         , p_component_type_code     => l_component_type_code
82361         , p_component_appl_id       => l_component_appl_id
82362         , p_amb_context_code        => l_amb_context_code
82363         , p_entity_code             => 'DEPRECIATION'
82364         , p_event_class_code        => 'DEPRECIATION'
82365         , p_side                    => 'NA'
82366         );
82367 
82368   END IF;
82369 
82370    --
82371    --
82372    END IF;
82373 
82374        --
82375        -- Update the line information that should be overwritten
82376        --
82377        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
82378                                          p_header_num   => 1);
82379        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
82380 
82381        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
82382 
82383        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
82384           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
82385        END IF;
82386 
82387       --
82388       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
82389       --
82390       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
82391           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
82392       ELSE
82393           ---------------------------------------------------------------------------------------------------
82394           -- 4262811a Switch Sign
82395           ---------------------------------------------------------------------------------------------------
82396           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
82397           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
82398                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
82399           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
82403                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
82400                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
82401           -- 5132302
82402           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
82404 
82405       END IF;
82406 
82407       -- 4955764
82408       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
82409       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
82410 
82411 
82412       XLA_AE_LINES_PKG.ValidateCurrentLine;
82413       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
82414 
82415       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
82416                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
82417                ,p_balance_type_code => l_balance_type_code);
82418 
82419    END IF;
82420 
82421    -----------------------------------------------------------------------------------------
82422    -- 4262811 Multiperiod Accounting
82423    -----------------------------------------------------------------------------------------
82424      -- No MPA option is assigned.
82425 
82426 
82427 END IF;
82428 END IF;
82429 --
82430 
82431 --
82432 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
82433    trace
82434       (p_msg      => 'END of AcctLineType_268'
82435       ,p_level    => C_LEVEL_PROCEDURE
82436       ,p_module   => l_log_module);
82437 END IF;
82438 --
82439 EXCEPTION
82440   WHEN xla_exceptions_pkg.application_exception THEN
82441       RAISE;
82442   WHEN OTHERS THEN
82443        xla_exceptions_pkg.raise_message
82444            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_268');
82445 END AcctLineType_268;
82446 --
82447 
82448 ---------------------------------------
82449 --
82450 -- PRIVATE FUNCTION
82451 --         AcctLineType_269
82452 --
82453 ---------------------------------------
82454 PROCEDURE AcctLineType_269 (
82455   p_application_id        IN NUMBER
82456  ,p_event_id              IN NUMBER
82457  ,p_calculate_acctd_flag  IN VARCHAR2
82458  ,p_calculate_g_l_flag    IN VARCHAR2
82459  ,p_actual_flag           IN OUT VARCHAR2
82460  ,p_balance_type_code     OUT VARCHAR2
82461  ,p_gain_or_loss_ref      OUT VARCHAR2
82462  
82463 --Period Close Date
82464  , p_source_1            IN DATE
82465 --Generated Code Combination Identifier
82466  , p_source_3            IN NUMBER
82467 --Revaluation Amortization Account
82468  , p_source_26            IN VARCHAR2
82469 --Expense Account Code Combination Identifier
82470  , p_source_29            IN NUMBER
82471 --Default Code Combination Identifier
82472  , p_source_30            IN NUMBER
82473 --Revaluation Generated Code Combination Identifier
82474  , p_source_33            IN NUMBER
82475 --Distribution Type Code
82476  , p_source_38            IN VARCHAR2
82477 --Currency Code
82478  , p_source_40            IN VARCHAR2
82479 --Asset Identifier
82480  , p_source_43            IN NUMBER
82481 --Period Counter
82482  , p_source_44            IN NUMBER
82483 --Distribution Identifier
82484  , p_source_45            IN NUMBER
82485 --Book Type Code
82486  , p_source_46            IN VARCHAR2
82487 --Depreciation Run Identifier
82488  , p_source_49            IN NUMBER
82489 --Revaluation Entered Amount
82490  , p_source_50            IN NUMBER
82491 )
82492 IS
82493 
82494 l_component_type              VARCHAR2(80);
82495 l_component_code              VARCHAR2(30);
82496 l_component_type_code         VARCHAR2(1);
82497 l_component_appl_id           INTEGER;
82498 l_amb_context_code            VARCHAR2(30);
82499 l_entity_code                 VARCHAR2(30);
82500 l_event_class_code            VARCHAR2(30);
82501 l_ae_header_id                NUMBER;
82502 l_event_type_code             VARCHAR2(30);
82503 l_line_definition_code        VARCHAR2(30);
82504 l_line_definition_owner_code  VARCHAR2(1);
82505 --
82506 -- adr variables
82507 l_segment                     VARCHAR2(30);
82508 l_ccid                        NUMBER;
82509 l_adr_transaction_coa_id      NUMBER;
82510 l_adr_accounting_coa_id       NUMBER;
82511 l_adr_flexfield_segment_code  VARCHAR2(30);
82512 l_adr_flex_value_set_id       NUMBER;
82513 l_adr_value_type_code         VARCHAR2(30);
82514 l_adr_value_combination_id    NUMBER;
82515 l_adr_value_segment_code      VARCHAR2(30);
82516 
82517 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
82518 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
82519 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
82520 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
82521 
82522 -- 4262811 Variables ------------------------------------------------------------------------------------------
82523 l_entered_amt_idx             NUMBER;
82524 l_accted_amt_idx              NUMBER;
82525 l_acc_rev_flag                VARCHAR2(1);
82526 l_accrual_line_num            NUMBER;
82527 l_tmp_amt                     NUMBER;
82528 l_acc_rev_natural_side_code   VARCHAR2(1);
82529 
82530 l_num_entries                 NUMBER;
82531 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
82532 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
82533 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
82534 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
82535 l_recog_line_1                NUMBER;
82536 l_recog_line_2                NUMBER;
82537 
82538 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
82539 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
82543 
82540 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
82541 
82542 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
82544 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
82545 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
82546 
82547 ---------------------------------------------------------------------------------------------------------------
82548 
82549 
82550 --
82551 -- bulk performance
82552 --
82553 l_balance_type_code           VARCHAR2(1);
82554 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
82555 l_log_module                  VARCHAR2(240);
82556 
82557 --
82558 -- Upgrade strategy
82559 --
82560 l_actual_upg_option           VARCHAR2(1);
82561 l_enc_upg_option           VARCHAR2(1);
82562 
82563 --
82564 BEGIN
82565 --
82566 IF g_log_enabled THEN
82567       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_269';
82568 END IF;
82569 --
82570 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
82571 
82572       trace
82573          (p_msg      => 'BEGIN of AcctLineType_269'
82574          ,p_level    => C_LEVEL_PROCEDURE
82575          ,p_module   => l_log_module);
82576 
82577 END IF;
82578 --
82579 l_component_type             := 'AMB_JLT';
82580 l_component_code             := 'FA_PER_DEPRN_REVAL_AMORT';
82581 l_component_type_code        := 'S';
82582 l_component_appl_id          :=  140;
82583 l_amb_context_code           := 'DEFAULT';
82584 l_entity_code                := 'DEPRECIATION';
82585 l_event_class_code           := 'DEPRECIATION';
82586 l_event_type_code            := 'DEPRECIATION_ALL';
82587 l_line_definition_owner_code := 'S';
82588 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE16';
82589 --
82590 l_balance_type_code          := 'A';
82591 l_segment                     := NULL;
82592 l_ccid                        := NULL;
82593 l_adr_transaction_coa_id      := NULL;
82594 l_adr_accounting_coa_id       := NULL;
82595 l_adr_flexfield_segment_code  := NULL;
82596 l_adr_flex_value_set_id       := NULL;
82597 l_adr_value_type_code         := NULL;
82598 l_adr_value_combination_id    := NULL;
82599 l_adr_value_segment_code      := NULL;
82600 
82601 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
82602 l_bflow_class_code           := '';    -- 4219869 Business Flow
82603 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
82604 l_budgetary_control_flag     := 'N';
82605 
82606 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
82607 l_bflow_applied_to_amt       := NULL; -- 5132302
82608 l_entered_amt_idx            := NULL;          -- 4262811
82609 l_accted_amt_idx             := NULL;          -- 4262811
82610 l_acc_rev_flag               := NULL;          -- 4262811
82611 l_accrual_line_num           := NULL;          -- 4262811
82612 l_tmp_amt                    := NULL;          -- 4262811
82613 --
82614  
82615 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
82616     l_balance_type_code <> 'B' THEN
82617 IF NVL(p_source_50,9E125) <>  0 AND 
82618 NVL(p_source_38,'
82619 ') =  'DEPRN'
82620  THEN 
82621 
82622    --
82623    XLA_AE_LINES_PKG.SetNewLine;
82624 
82625    p_balance_type_code          := l_balance_type_code;
82626    -- set the flag so later we will know whether the gain loss line needs to be created
82627    
82628    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
82629      p_actual_flag :='A';
82630    END IF;
82631 
82632    --
82633    -- bulk performance
82634    --
82635    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
82636                                       p_header_num   => 0); -- 4262811
82637    --
82638    -- set accounting line options
82639    --
82640    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
82641            p_natural_side_code          => 'C'
82642          , p_gain_or_loss_flag          => 'N'
82643          , p_gl_transfer_mode_code      => 'S'
82644          , p_acct_entry_type_code       => 'A'
82645          , p_switch_side_flag           => 'Y'
82646          , p_merge_duplicate_code       => 'N'
82647          );
82648    --
82649    l_acc_rev_natural_side_code := 'D';  -- 4262811
82650    -- 
82651    --
82652    -- set accounting line type info
82653    --
82654    xla_ae_lines_pkg.SetAcctLineType
82655       (p_component_type             => l_component_type
82656       ,p_event_type_code            => l_event_type_code
82657       ,p_line_definition_owner_code => l_line_definition_owner_code
82658       ,p_line_definition_code       => l_line_definition_code
82659       ,p_accounting_line_code       => l_component_code
82660       ,p_accounting_line_type_code  => l_component_type_code
82661       ,p_accounting_line_appl_id    => l_component_appl_id
82662       ,p_amb_context_code           => l_amb_context_code
82663       ,p_entity_code                => l_entity_code
82664       ,p_event_class_code           => l_event_class_code);
82665    --
82666    -- set accounting class
82667    --
82668    xla_ae_lines_pkg.SetAcctClass(
82669            p_accounting_class_code  => 'EXPENSE'
82670          , p_ae_header_id           => l_ae_header_id
82671          );
82672 
82673    --
82674    -- set rounding class
82675    --
82676    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
82677                       'EXPENSE';
82678 
82679    --
82680    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
82681    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
82682    --
82686 
82683    -- bulk performance
82684    --
82685    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
82687    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
82688       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
82689 
82690    -- 4955764
82691    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
82692       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
82693 
82694    -- 4458381 Public Sector Enh
82695    
82696    --
82697    -- set accounting attributes for the line type
82698    --
82699    l_entered_amt_idx := 7;
82700    l_accted_amt_idx  := 9;
82701    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
82702    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
82703    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
82704    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
82705    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
82706    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
82707    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_49);
82708    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
82709    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
82710    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
82711    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_45);
82712    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
82713    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
82714    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
82715    l_rec_acct_attrs.array_num_value(7)  := p_source_50;
82716    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
82717    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
82718    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
82719    l_rec_acct_attrs.array_num_value(9)  := p_source_50;
82720 
82721    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
82722    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
82723 
82724    ---------------------------------------------------------------------------------------------------------------
82725    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
82726    ---------------------------------------------------------------------------------------------------------------
82727    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
82728 
82729    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
82730    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
82731 
82732    IF xla_accounting_cache_pkg.GetValueChar
82733          (p_source_code         => 'LEDGER_CATEGORY_CODE'
82734          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
82735    AND l_bflow_method_code = 'PRIOR_ENTRY'
82736 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
82737    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
82738          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
82739        )
82740    THEN
82741          xla_ae_lines_pkg.BflowUpgEntry
82742            (p_business_method_code    => l_bflow_method_code
82743            ,p_business_class_code     => l_bflow_class_code
82744            ,p_balance_type            => l_balance_type_code);
82745    ELSE
82746       NULL;
82747 -- No business flow processing for business flow method of NONE.
82748    END IF;
82749 
82750    --
82751    -- call analytical criteria
82752    --
82753    
82754    --
82755    -- call description
82756    --
82757    
82758 xla_ae_lines_pkg.SetLineDescription(
82759    p_ae_header_id => l_ae_header_id
82760   ,p_description  => Description_60 (
82761      p_application_id         => p_application_id
82762    , p_ae_header_id           => l_ae_header_id 
82763 , p_source_1 => p_source_1
82764    )
82765 );
82766 
82767 
82768    --
82769    -- call ADRs
82770    -- Bug 4922099
82771    --
82772    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
82773         (NVL(l_actual_upg_option, 'N') = 'O') OR
82774         (NVL(l_enc_upg_option, 'N') = 'O')
82775       )
82776    THEN
82777    NULL;
82778    --
82779    --
82780    
82781   l_ccid := AcctDerRule_178(
82782            p_application_id           => p_application_id
82783          , p_ae_header_id             => l_ae_header_id 
82784 , p_source_30 => p_source_30
82785 , p_source_33 => p_source_33
82786          , x_transaction_coa_id       => l_adr_transaction_coa_id
82787          , x_accounting_coa_id        => l_adr_accounting_coa_id
82788          , x_value_type_code          => l_adr_value_type_code
82789          , p_side                     => 'NA'
82790    );
82791 
82792    xla_ae_lines_pkg.set_ccid(
82793     p_code_combination_id          => l_ccid
82794   , p_value_type_code              => l_adr_value_type_code
82795   , p_transaction_coa_id           => l_adr_transaction_coa_id
82796   , p_accounting_coa_id            => l_adr_accounting_coa_id
82797   , p_adr_code                     => 'FA_PER_REVAL_AMORTIZATION'
82798   , p_adr_type_code                => 'S'
82799   , p_component_type               => l_component_type
82800   , p_component_code               => l_component_code
82801   , p_component_type_code          => l_component_type_code
82802   , p_component_appl_id            => l_component_appl_id
82803   , p_amb_context_code             => l_amb_context_code
82804   , p_side                         => 'NA'
82805   );
82806 
82807 
82808    l_segment := AcctDerRule_168(
82812 , p_source_29 => p_source_29
82809            p_application_id           => p_application_id
82810          , p_ae_header_id             => l_ae_header_id 
82811 , p_source_3 => p_source_3
82813          , x_transaction_coa_id       => l_adr_transaction_coa_id
82814          , x_accounting_coa_id        => l_adr_accounting_coa_id
82815          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
82816          , x_flex_value_set_id        => l_adr_flex_value_set_id
82817          , x_value_type_code          => l_adr_value_type_code
82818          , x_value_combination_id     => l_adr_value_combination_id
82819          , x_value_segment_code       => l_adr_value_segment_code
82820          , p_side                     => 'NA'
82821          , p_override_seg_flag        => 'Y'
82822    );
82823 
82824    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
82825 
82826       xla_ae_lines_pkg.set_segment(
82827           p_to_segment_code         => 'GL_BALANCING'
82828         , p_segment_value           => l_segment
82829         , p_from_segment_code       => l_adr_value_segment_code
82830         , p_from_combination_id     => l_adr_value_combination_id
82831         , p_value_type_code         => l_adr_value_type_code
82832         , p_transaction_coa_id      => l_adr_transaction_coa_id
82833         , p_accounting_coa_id       => l_adr_accounting_coa_id
82834         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
82835         , p_flex_value_set_id       => l_adr_flex_value_set_id
82836         , p_adr_code                => 'FA_EXPENSE_ACCT'
82837         , p_adr_type_code           => 'S'
82838         , p_component_type          => l_component_type
82839         , p_component_code          => l_component_code
82840         , p_component_type_code     => l_component_type_code
82841         , p_component_appl_id       => l_component_appl_id
82842         , p_amb_context_code        => l_amb_context_code
82843         , p_entity_code             => 'DEPRECIATION'
82844         , p_event_class_code        => 'DEPRECIATION'
82845         , p_side                    => 'NA'
82846         );
82847 
82848   END IF;
82849 
82850    l_segment := AcctDerRule_164(
82851            p_application_id           => p_application_id
82852          , p_ae_header_id             => l_ae_header_id 
82853 , p_source_3 => p_source_3
82854 , p_source_26 => p_source_26
82855          , x_transaction_coa_id       => l_adr_transaction_coa_id
82856          , x_accounting_coa_id        => l_adr_accounting_coa_id
82857          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
82858          , x_flex_value_set_id        => l_adr_flex_value_set_id
82859          , x_value_type_code          => l_adr_value_type_code
82860          , x_value_combination_id     => l_adr_value_combination_id
82861          , x_value_segment_code       => l_adr_value_segment_code
82862          , p_side                     => 'NA'
82863          , p_override_seg_flag        => 'Y'
82864    );
82865 
82866    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
82867 
82868       xla_ae_lines_pkg.set_segment(
82869           p_to_segment_code         => 'GL_ACCOUNT'
82870         , p_segment_value           => l_segment
82871         , p_from_segment_code       => l_adr_value_segment_code
82872         , p_from_combination_id     => l_adr_value_combination_id
82873         , p_value_type_code         => l_adr_value_type_code
82874         , p_transaction_coa_id      => l_adr_transaction_coa_id
82875         , p_accounting_coa_id       => l_adr_accounting_coa_id
82876         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
82877         , p_flex_value_set_id       => l_adr_flex_value_set_id
82878         , p_adr_code                => 'FA_REVAL_AMORT_SEGMENT'
82879         , p_adr_type_code           => 'S'
82880         , p_component_type          => l_component_type
82881         , p_component_code          => l_component_code
82882         , p_component_type_code     => l_component_type_code
82883         , p_component_appl_id       => l_component_appl_id
82884         , p_amb_context_code        => l_amb_context_code
82885         , p_entity_code             => 'DEPRECIATION'
82886         , p_event_class_code        => 'DEPRECIATION'
82887         , p_side                    => 'NA'
82888         );
82889 
82890   END IF;
82891 
82892    --
82893    --
82894    END IF;
82895    --
82896    -- Bug 4922099
82897    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
82898           (NVL(l_enc_upg_option, 'N') = 'O')
82899         ) AND
82900         (l_bflow_method_code = 'PRIOR_ENTRY')
82901       )
82902    THEN
82903       IF
82904       --
82905       1 = 2
82906       --
82907       THEN
82908       xla_accounting_err_pkg.build_message
82909                                     (p_appli_s_name            => 'XLA'
82910                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
82911                                     ,p_token_1                 => 'LINE_NUMBER'
82912                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
82913                                     ,p_token_2                 => 'LINE_TYPE_NAME'
82914                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
82915                                                                              l_component_type
82916                                                                             ,l_component_code
82917                                                                             ,l_component_type_code
82918                                                                             ,l_component_appl_id
82919                                                                             ,l_amb_context_code
82920                                                                             ,l_entity_code
82921                                                                             ,l_event_class_code
82925                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
82922                                                                            )
82923                                     ,p_token_3                 => 'OWNER'
82924                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
82926                                                                           ,p_lookup_code    => l_component_type_code
82927                                                                          )
82928                                     ,p_token_4                 => 'PRODUCT_NAME'
82929                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
82930                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
82931                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
82932                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
82933                                     ,p_ae_header_id            =>  NULL
82934                                        );
82935 
82936         IF (C_LEVEL_ERROR>= g_log_level) THEN
82937                  trace
82938                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
82939                       ,p_level    => C_LEVEL_ERROR
82940                       ,p_module   => l_log_module);
82941         END IF;
82942       END IF;
82943    END IF;
82944    --
82945    --
82946    ------------------------------------------------------------------------------------------------
82947    -- 4219869 Business Flow
82948    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
82949    -- Prior Entry.  Currently, the following code is always generated.
82950    ------------------------------------------------------------------------------------------------
82951    XLA_AE_LINES_PKG.ValidateCurrentLine;
82952 
82953    ------------------------------------------------------------------------------------
82954    -- 4219869 Business Flow
82955    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
82956    ------------------------------------------------------------------------------------
82957    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
82958 
82959    ----------------------------------------------------------------------------------
82960    -- 4219869 Business Flow
82961    -- Update journal entry status -- Need to generate this within IF <condition>
82962    ----------------------------------------------------------------------------------
82963    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
82964          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
82965          ,p_balance_type_code => l_balance_type_code
82966          );
82967 
82968    -------------------------------------------------------------------------------------------
82969    -- 4262811 - Generate the Accrual Reversal lines
82970    -------------------------------------------------------------------------------------------
82971    BEGIN
82972       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
82973                               (g_array_event(p_event_id).array_value_num('header_index'));
82974       IF l_acc_rev_flag IS NULL THEN
82975          l_acc_rev_flag := 'N';
82976       END IF;
82977    EXCEPTION
82978       WHEN OTHERS THEN
82979          l_acc_rev_flag := 'N';
82980    END;
82981    --
82982    IF (l_acc_rev_flag = 'Y') THEN
82983 
82984        -- 4645092  ------------------------------------------------------------------------------
82985        -- To allow MPA report to determine if it should generate report process
82986        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
82987        ------------------------------------------------------------------------------------------
82988 
82989        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
82990        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
82991    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
82992    -- call ADRs
82993    -- Bug 4922099
82994    --
82995    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
82996         (NVL(l_actual_upg_option, 'N') = 'O') OR
82997         (NVL(l_enc_upg_option, 'N') = 'O')
82998       )
82999    THEN
83000    NULL;
83001    --
83002    --
83003    
83004   l_ccid := AcctDerRule_178(
83005            p_application_id           => p_application_id
83006          , p_ae_header_id             => l_ae_header_id 
83007 , p_source_30 => p_source_30
83008 , p_source_33 => p_source_33
83009          , x_transaction_coa_id       => l_adr_transaction_coa_id
83010          , x_accounting_coa_id        => l_adr_accounting_coa_id
83011          , x_value_type_code          => l_adr_value_type_code
83012          , p_side                     => 'NA'
83013    );
83014 
83015    xla_ae_lines_pkg.set_ccid(
83016     p_code_combination_id          => l_ccid
83017   , p_value_type_code              => l_adr_value_type_code
83018   , p_transaction_coa_id           => l_adr_transaction_coa_id
83019   , p_accounting_coa_id            => l_adr_accounting_coa_id
83020   , p_adr_code                     => 'FA_PER_REVAL_AMORTIZATION'
83021   , p_adr_type_code                => 'S'
83022   , p_component_type               => l_component_type
83023   , p_component_code               => l_component_code
83024   , p_component_type_code          => l_component_type_code
83025   , p_component_appl_id            => l_component_appl_id
83026   , p_amb_context_code             => l_amb_context_code
83027   , p_side                         => 'NA'
83028   );
83029 
83030 
83031    l_segment := AcctDerRule_168(
83032            p_application_id           => p_application_id
83033          , p_ae_header_id             => l_ae_header_id 
83037          , x_accounting_coa_id        => l_adr_accounting_coa_id
83034 , p_source_3 => p_source_3
83035 , p_source_29 => p_source_29
83036          , x_transaction_coa_id       => l_adr_transaction_coa_id
83038          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
83039          , x_flex_value_set_id        => l_adr_flex_value_set_id
83040          , x_value_type_code          => l_adr_value_type_code
83041          , x_value_combination_id     => l_adr_value_combination_id
83042          , x_value_segment_code       => l_adr_value_segment_code
83043          , p_side                     => 'NA'
83044          , p_override_seg_flag        => 'Y'
83045    );
83046 
83047    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
83048 
83049       xla_ae_lines_pkg.set_segment(
83050           p_to_segment_code         => 'GL_BALANCING'
83051         , p_segment_value           => l_segment
83052         , p_from_segment_code       => l_adr_value_segment_code
83053         , p_from_combination_id     => l_adr_value_combination_id
83054         , p_value_type_code         => l_adr_value_type_code
83055         , p_transaction_coa_id      => l_adr_transaction_coa_id
83056         , p_accounting_coa_id       => l_adr_accounting_coa_id
83057         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
83058         , p_flex_value_set_id       => l_adr_flex_value_set_id
83059         , p_adr_code                => 'FA_EXPENSE_ACCT'
83060         , p_adr_type_code           => 'S'
83061         , p_component_type          => l_component_type
83062         , p_component_code          => l_component_code
83063         , p_component_type_code     => l_component_type_code
83064         , p_component_appl_id       => l_component_appl_id
83065         , p_amb_context_code        => l_amb_context_code
83066         , p_entity_code             => 'DEPRECIATION'
83067         , p_event_class_code        => 'DEPRECIATION'
83068         , p_side                    => 'NA'
83069         );
83070 
83071   END IF;
83072 
83073    l_segment := AcctDerRule_164(
83074            p_application_id           => p_application_id
83075          , p_ae_header_id             => l_ae_header_id 
83076 , p_source_3 => p_source_3
83077 , p_source_26 => p_source_26
83078          , x_transaction_coa_id       => l_adr_transaction_coa_id
83079          , x_accounting_coa_id        => l_adr_accounting_coa_id
83080          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
83081          , x_flex_value_set_id        => l_adr_flex_value_set_id
83082          , x_value_type_code          => l_adr_value_type_code
83083          , x_value_combination_id     => l_adr_value_combination_id
83084          , x_value_segment_code       => l_adr_value_segment_code
83085          , p_side                     => 'NA'
83086          , p_override_seg_flag        => 'Y'
83087    );
83088 
83089    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
83090 
83091       xla_ae_lines_pkg.set_segment(
83092           p_to_segment_code         => 'GL_ACCOUNT'
83093         , p_segment_value           => l_segment
83094         , p_from_segment_code       => l_adr_value_segment_code
83095         , p_from_combination_id     => l_adr_value_combination_id
83096         , p_value_type_code         => l_adr_value_type_code
83097         , p_transaction_coa_id      => l_adr_transaction_coa_id
83098         , p_accounting_coa_id       => l_adr_accounting_coa_id
83099         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
83100         , p_flex_value_set_id       => l_adr_flex_value_set_id
83101         , p_adr_code                => 'FA_REVAL_AMORT_SEGMENT'
83102         , p_adr_type_code           => 'S'
83103         , p_component_type          => l_component_type
83104         , p_component_code          => l_component_code
83105         , p_component_type_code     => l_component_type_code
83106         , p_component_appl_id       => l_component_appl_id
83107         , p_amb_context_code        => l_amb_context_code
83108         , p_entity_code             => 'DEPRECIATION'
83109         , p_event_class_code        => 'DEPRECIATION'
83110         , p_side                    => 'NA'
83111         );
83112 
83113   END IF;
83114 
83115    --
83116    --
83117    END IF;
83118 
83119        --
83120        -- Update the line information that should be overwritten
83121        --
83122        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
83123                                          p_header_num   => 1);
83124        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
83125 
83126        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
83127 
83128        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
83129           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
83130        END IF;
83131 
83132       --
83133       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
83134       --
83135       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
83136           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
83137       ELSE
83138           ---------------------------------------------------------------------------------------------------
83139           -- 4262811a Switch Sign
83140           ---------------------------------------------------------------------------------------------------
83141           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
83142           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
83143                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
83144           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
83148                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
83145                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
83146           -- 5132302
83147           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
83149 
83150       END IF;
83151 
83152       -- 4955764
83153       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
83154       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
83155 
83156 
83157       XLA_AE_LINES_PKG.ValidateCurrentLine;
83158       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
83159 
83160       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
83161                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
83162                ,p_balance_type_code => l_balance_type_code);
83163 
83164    END IF;
83165 
83166    -----------------------------------------------------------------------------------------
83167    -- 4262811 Multiperiod Accounting
83168    -----------------------------------------------------------------------------------------
83169      -- No MPA option is assigned.
83170 
83171 
83172 END IF;
83173 END IF;
83174 --
83175 
83176 --
83177 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
83178    trace
83179       (p_msg      => 'END of AcctLineType_269'
83180       ,p_level    => C_LEVEL_PROCEDURE
83181       ,p_module   => l_log_module);
83182 END IF;
83183 --
83184 EXCEPTION
83185   WHEN xla_exceptions_pkg.application_exception THEN
83186       RAISE;
83187   WHEN OTHERS THEN
83188        xla_exceptions_pkg.raise_message
83189            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_269');
83190 END AcctLineType_269;
83191 --
83192 
83193 ---------------------------------------
83194 --
83195 -- PRIVATE FUNCTION
83196 --         AcctLineType_270
83197 --
83198 ---------------------------------------
83199 PROCEDURE AcctLineType_270 (
83200   p_application_id        IN NUMBER
83201  ,p_event_id              IN NUMBER
83202  ,p_calculate_acctd_flag  IN VARCHAR2
83203  ,p_calculate_g_l_flag    IN VARCHAR2
83204  ,p_actual_flag           IN OUT VARCHAR2
83205  ,p_balance_type_code     OUT VARCHAR2
83206  ,p_gain_or_loss_ref      OUT VARCHAR2
83207  
83208 --Period Close Date
83209  , p_source_1            IN DATE
83210 --Generated Code Combination Identifier
83211  , p_source_3            IN NUMBER
83212 --Revaluation Reserve Account
83213  , p_source_11            IN VARCHAR2
83214 --Expense Account Code Combination Identifier
83215  , p_source_29            IN NUMBER
83216 --Default Code Combination Identifier
83217  , p_source_30            IN NUMBER
83218 --Revaluation Generated Offset Code Combination Identifier
83219  , p_source_34            IN NUMBER
83220 --Distribution Type Code
83221  , p_source_38            IN VARCHAR2
83222 --Currency Code
83223  , p_source_40            IN VARCHAR2
83224 --Asset Identifier
83225  , p_source_43            IN NUMBER
83226 --Period Counter
83227  , p_source_44            IN NUMBER
83228 --Distribution Identifier
83229  , p_source_45            IN NUMBER
83230 --Book Type Code
83231  , p_source_46            IN VARCHAR2
83232 --Depreciation Run Identifier
83233  , p_source_49            IN NUMBER
83234 --Revaluation Entered Amount
83235  , p_source_50            IN NUMBER
83236 )
83237 IS
83238 
83239 l_component_type              VARCHAR2(80);
83240 l_component_code              VARCHAR2(30);
83241 l_component_type_code         VARCHAR2(1);
83242 l_component_appl_id           INTEGER;
83243 l_amb_context_code            VARCHAR2(30);
83244 l_entity_code                 VARCHAR2(30);
83245 l_event_class_code            VARCHAR2(30);
83246 l_ae_header_id                NUMBER;
83247 l_event_type_code             VARCHAR2(30);
83248 l_line_definition_code        VARCHAR2(30);
83249 l_line_definition_owner_code  VARCHAR2(1);
83250 --
83251 -- adr variables
83252 l_segment                     VARCHAR2(30);
83253 l_ccid                        NUMBER;
83254 l_adr_transaction_coa_id      NUMBER;
83255 l_adr_accounting_coa_id       NUMBER;
83256 l_adr_flexfield_segment_code  VARCHAR2(30);
83257 l_adr_flex_value_set_id       NUMBER;
83258 l_adr_value_type_code         VARCHAR2(30);
83259 l_adr_value_combination_id    NUMBER;
83260 l_adr_value_segment_code      VARCHAR2(30);
83261 
83262 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
83263 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
83264 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
83265 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
83266 
83267 -- 4262811 Variables ------------------------------------------------------------------------------------------
83268 l_entered_amt_idx             NUMBER;
83269 l_accted_amt_idx              NUMBER;
83270 l_acc_rev_flag                VARCHAR2(1);
83271 l_accrual_line_num            NUMBER;
83272 l_tmp_amt                     NUMBER;
83273 l_acc_rev_natural_side_code   VARCHAR2(1);
83274 
83275 l_num_entries                 NUMBER;
83276 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
83277 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
83278 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
83279 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
83280 l_recog_line_1                NUMBER;
83281 l_recog_line_2                NUMBER;
83282 
83283 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
83284 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
83288 
83285 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
83286 
83287 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
83289 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
83290 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
83291 
83292 ---------------------------------------------------------------------------------------------------------------
83293 
83294 
83295 --
83296 -- bulk performance
83297 --
83298 l_balance_type_code           VARCHAR2(1);
83299 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
83300 l_log_module                  VARCHAR2(240);
83301 
83302 --
83303 -- Upgrade strategy
83304 --
83305 l_actual_upg_option           VARCHAR2(1);
83306 l_enc_upg_option           VARCHAR2(1);
83307 
83308 --
83309 BEGIN
83310 --
83311 IF g_log_enabled THEN
83312       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_270';
83313 END IF;
83314 --
83315 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
83316 
83317       trace
83318          (p_msg      => 'BEGIN of AcctLineType_270'
83319          ,p_level    => C_LEVEL_PROCEDURE
83320          ,p_module   => l_log_module);
83321 
83322 END IF;
83323 --
83324 l_component_type             := 'AMB_JLT';
83325 l_component_code             := 'FA_PER_DEPRN_REVAL_RESERVE';
83326 l_component_type_code        := 'S';
83327 l_component_appl_id          :=  140;
83328 l_amb_context_code           := 'DEFAULT';
83329 l_entity_code                := 'DEPRECIATION';
83330 l_event_class_code           := 'DEPRECIATION';
83331 l_event_type_code            := 'DEPRECIATION_ALL';
83332 l_line_definition_owner_code := 'S';
83333 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE16';
83334 --
83335 l_balance_type_code          := 'A';
83336 l_segment                     := NULL;
83337 l_ccid                        := NULL;
83338 l_adr_transaction_coa_id      := NULL;
83339 l_adr_accounting_coa_id       := NULL;
83340 l_adr_flexfield_segment_code  := NULL;
83341 l_adr_flex_value_set_id       := NULL;
83342 l_adr_value_type_code         := NULL;
83343 l_adr_value_combination_id    := NULL;
83344 l_adr_value_segment_code      := NULL;
83345 
83346 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
83347 l_bflow_class_code           := '';    -- 4219869 Business Flow
83348 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
83349 l_budgetary_control_flag     := 'N';
83350 
83351 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
83352 l_bflow_applied_to_amt       := NULL; -- 5132302
83353 l_entered_amt_idx            := NULL;          -- 4262811
83354 l_accted_amt_idx             := NULL;          -- 4262811
83355 l_acc_rev_flag               := NULL;          -- 4262811
83356 l_accrual_line_num           := NULL;          -- 4262811
83357 l_tmp_amt                    := NULL;          -- 4262811
83358 --
83359  
83360 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
83361     l_balance_type_code <> 'B' THEN
83362 IF NVL(p_source_50,9E125) <>  0 AND 
83363 NVL(p_source_38,'
83364 ') =  'DEPRN'
83365  THEN 
83366 
83367    --
83368    XLA_AE_LINES_PKG.SetNewLine;
83369 
83370    p_balance_type_code          := l_balance_type_code;
83371    -- set the flag so later we will know whether the gain loss line needs to be created
83372    
83373    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
83374      p_actual_flag :='A';
83375    END IF;
83376 
83377    --
83378    -- bulk performance
83379    --
83380    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
83381                                       p_header_num   => 0); -- 4262811
83382    --
83383    -- set accounting line options
83384    --
83385    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
83386            p_natural_side_code          => 'D'
83387          , p_gain_or_loss_flag          => 'N'
83388          , p_gl_transfer_mode_code      => 'S'
83389          , p_acct_entry_type_code       => 'A'
83390          , p_switch_side_flag           => 'Y'
83391          , p_merge_duplicate_code       => 'N'
83392          );
83393    --
83394    l_acc_rev_natural_side_code := 'C';  -- 4262811
83395    -- 
83396    --
83397    -- set accounting line type info
83398    --
83399    xla_ae_lines_pkg.SetAcctLineType
83400       (p_component_type             => l_component_type
83401       ,p_event_type_code            => l_event_type_code
83402       ,p_line_definition_owner_code => l_line_definition_owner_code
83403       ,p_line_definition_code       => l_line_definition_code
83404       ,p_accounting_line_code       => l_component_code
83405       ,p_accounting_line_type_code  => l_component_type_code
83406       ,p_accounting_line_appl_id    => l_component_appl_id
83407       ,p_amb_context_code           => l_amb_context_code
83408       ,p_entity_code                => l_entity_code
83409       ,p_event_class_code           => l_event_class_code);
83410    --
83411    -- set accounting class
83412    --
83413    xla_ae_lines_pkg.SetAcctClass(
83414            p_accounting_class_code  => 'ASSET'
83415          , p_ae_header_id           => l_ae_header_id
83416          );
83417 
83418    --
83419    -- set rounding class
83420    --
83421    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
83422                       'ASSET';
83423 
83424    --
83425    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
83426    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
83427    --
83431 
83428    -- bulk performance
83429    --
83430    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
83432    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
83433       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
83434 
83435    -- 4955764
83436    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
83437       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
83438 
83439    -- 4458381 Public Sector Enh
83440    
83441    --
83442    -- set accounting attributes for the line type
83443    --
83444    l_entered_amt_idx := 7;
83445    l_accted_amt_idx  := 9;
83446    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
83447    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
83448    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
83449    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
83450    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
83451    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
83452    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_49);
83453    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
83454    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
83455    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
83456    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_45);
83457    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
83458    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
83459    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
83460    l_rec_acct_attrs.array_num_value(7)  := p_source_50;
83461    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
83462    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
83463    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
83464    l_rec_acct_attrs.array_num_value(9)  := p_source_50;
83465 
83466    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
83467    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
83468 
83469    ---------------------------------------------------------------------------------------------------------------
83470    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
83471    ---------------------------------------------------------------------------------------------------------------
83472    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
83473 
83474    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
83475    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
83476 
83477    IF xla_accounting_cache_pkg.GetValueChar
83478          (p_source_code         => 'LEDGER_CATEGORY_CODE'
83479          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
83480    AND l_bflow_method_code = 'PRIOR_ENTRY'
83481 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
83482    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
83483          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
83484        )
83485    THEN
83486          xla_ae_lines_pkg.BflowUpgEntry
83487            (p_business_method_code    => l_bflow_method_code
83488            ,p_business_class_code     => l_bflow_class_code
83489            ,p_balance_type            => l_balance_type_code);
83490    ELSE
83491       NULL;
83492 -- No business flow processing for business flow method of NONE.
83493    END IF;
83494 
83495    --
83496    -- call analytical criteria
83497    --
83498    
83499    --
83500    -- call description
83501    --
83502    
83503 xla_ae_lines_pkg.SetLineDescription(
83504    p_ae_header_id => l_ae_header_id
83505   ,p_description  => Description_61 (
83506      p_application_id         => p_application_id
83507    , p_ae_header_id           => l_ae_header_id 
83508 , p_source_1 => p_source_1
83509    )
83510 );
83511 
83512 
83513    --
83514    -- call ADRs
83515    -- Bug 4922099
83516    --
83517    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
83518         (NVL(l_actual_upg_option, 'N') = 'O') OR
83519         (NVL(l_enc_upg_option, 'N') = 'O')
83520       )
83521    THEN
83522    NULL;
83523    --
83524    --
83525    
83526   l_ccid := AcctDerRule_179(
83527            p_application_id           => p_application_id
83528          , p_ae_header_id             => l_ae_header_id 
83529 , p_source_30 => p_source_30
83530 , p_source_34 => p_source_34
83531          , x_transaction_coa_id       => l_adr_transaction_coa_id
83532          , x_accounting_coa_id        => l_adr_accounting_coa_id
83533          , x_value_type_code          => l_adr_value_type_code
83534          , p_side                     => 'NA'
83535    );
83536 
83537    xla_ae_lines_pkg.set_ccid(
83538     p_code_combination_id          => l_ccid
83539   , p_value_type_code              => l_adr_value_type_code
83540   , p_transaction_coa_id           => l_adr_transaction_coa_id
83541   , p_accounting_coa_id            => l_adr_accounting_coa_id
83542   , p_adr_code                     => 'FA_PER_REVAL_RESERVE'
83543   , p_adr_type_code                => 'S'
83544   , p_component_type               => l_component_type
83545   , p_component_code               => l_component_code
83546   , p_component_type_code          => l_component_type_code
83547   , p_component_appl_id            => l_component_appl_id
83548   , p_amb_context_code             => l_amb_context_code
83549   , p_side                         => 'NA'
83550   );
83551 
83552 
83553    l_segment := AcctDerRule_150(
83557 , p_source_11 => p_source_11
83554            p_application_id           => p_application_id
83555          , p_ae_header_id             => l_ae_header_id 
83556 , p_source_3 => p_source_3
83558          , x_transaction_coa_id       => l_adr_transaction_coa_id
83559          , x_accounting_coa_id        => l_adr_accounting_coa_id
83560          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
83561          , x_flex_value_set_id        => l_adr_flex_value_set_id
83562          , x_value_type_code          => l_adr_value_type_code
83563          , x_value_combination_id     => l_adr_value_combination_id
83564          , x_value_segment_code       => l_adr_value_segment_code
83565          , p_side                     => 'NA'
83566          , p_override_seg_flag        => 'Y'
83567    );
83568 
83569    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
83570 
83571       xla_ae_lines_pkg.set_segment(
83572           p_to_segment_code         => 'GL_ACCOUNT'
83573         , p_segment_value           => l_segment
83574         , p_from_segment_code       => l_adr_value_segment_code
83575         , p_from_combination_id     => l_adr_value_combination_id
83576         , p_value_type_code         => l_adr_value_type_code
83577         , p_transaction_coa_id      => l_adr_transaction_coa_id
83578         , p_accounting_coa_id       => l_adr_accounting_coa_id
83579         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
83580         , p_flex_value_set_id       => l_adr_flex_value_set_id
83581         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
83582         , p_adr_type_code           => 'S'
83583         , p_component_type          => l_component_type
83584         , p_component_code          => l_component_code
83585         , p_component_type_code     => l_component_type_code
83586         , p_component_appl_id       => l_component_appl_id
83587         , p_amb_context_code        => l_amb_context_code
83588         , p_entity_code             => 'DEPRECIATION'
83589         , p_event_class_code        => 'DEPRECIATION'
83590         , p_side                    => 'NA'
83591         );
83592 
83593   END IF;
83594 
83595    l_segment := AcctDerRule_168(
83596            p_application_id           => p_application_id
83597          , p_ae_header_id             => l_ae_header_id 
83598 , p_source_3 => p_source_3
83599 , p_source_29 => p_source_29
83600          , x_transaction_coa_id       => l_adr_transaction_coa_id
83601          , x_accounting_coa_id        => l_adr_accounting_coa_id
83602          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
83603          , x_flex_value_set_id        => l_adr_flex_value_set_id
83604          , x_value_type_code          => l_adr_value_type_code
83605          , x_value_combination_id     => l_adr_value_combination_id
83606          , x_value_segment_code       => l_adr_value_segment_code
83607          , p_side                     => 'NA'
83608          , p_override_seg_flag        => 'Y'
83609    );
83610 
83611    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
83612 
83613       xla_ae_lines_pkg.set_segment(
83614           p_to_segment_code         => 'GL_BALANCING'
83615         , p_segment_value           => l_segment
83616         , p_from_segment_code       => l_adr_value_segment_code
83617         , p_from_combination_id     => l_adr_value_combination_id
83618         , p_value_type_code         => l_adr_value_type_code
83619         , p_transaction_coa_id      => l_adr_transaction_coa_id
83620         , p_accounting_coa_id       => l_adr_accounting_coa_id
83621         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
83622         , p_flex_value_set_id       => l_adr_flex_value_set_id
83623         , p_adr_code                => 'FA_EXPENSE_ACCT'
83624         , p_adr_type_code           => 'S'
83625         , p_component_type          => l_component_type
83626         , p_component_code          => l_component_code
83627         , p_component_type_code     => l_component_type_code
83628         , p_component_appl_id       => l_component_appl_id
83629         , p_amb_context_code        => l_amb_context_code
83630         , p_entity_code             => 'DEPRECIATION'
83631         , p_event_class_code        => 'DEPRECIATION'
83632         , p_side                    => 'NA'
83633         );
83634 
83635   END IF;
83636 
83637    --
83638    --
83639    END IF;
83640    --
83641    -- Bug 4922099
83642    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
83643           (NVL(l_enc_upg_option, 'N') = 'O')
83644         ) AND
83645         (l_bflow_method_code = 'PRIOR_ENTRY')
83646       )
83647    THEN
83648       IF
83649       --
83650       1 = 2
83651       --
83652       THEN
83653       xla_accounting_err_pkg.build_message
83654                                     (p_appli_s_name            => 'XLA'
83655                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
83656                                     ,p_token_1                 => 'LINE_NUMBER'
83657                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
83658                                     ,p_token_2                 => 'LINE_TYPE_NAME'
83659                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
83660                                                                              l_component_type
83661                                                                             ,l_component_code
83662                                                                             ,l_component_type_code
83663                                                                             ,l_component_appl_id
83664                                                                             ,l_amb_context_code
83665                                                                             ,l_entity_code
83666                                                                             ,l_event_class_code
83670                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
83667                                                                            )
83668                                     ,p_token_3                 => 'OWNER'
83669                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
83671                                                                           ,p_lookup_code    => l_component_type_code
83672                                                                          )
83673                                     ,p_token_4                 => 'PRODUCT_NAME'
83674                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
83675                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
83676                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
83677                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
83678                                     ,p_ae_header_id            =>  NULL
83679                                        );
83680 
83681         IF (C_LEVEL_ERROR>= g_log_level) THEN
83682                  trace
83683                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
83684                       ,p_level    => C_LEVEL_ERROR
83685                       ,p_module   => l_log_module);
83686         END IF;
83687       END IF;
83688    END IF;
83689    --
83690    --
83691    ------------------------------------------------------------------------------------------------
83692    -- 4219869 Business Flow
83693    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
83694    -- Prior Entry.  Currently, the following code is always generated.
83695    ------------------------------------------------------------------------------------------------
83696    XLA_AE_LINES_PKG.ValidateCurrentLine;
83697 
83698    ------------------------------------------------------------------------------------
83699    -- 4219869 Business Flow
83700    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
83701    ------------------------------------------------------------------------------------
83702    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
83703 
83704    ----------------------------------------------------------------------------------
83705    -- 4219869 Business Flow
83706    -- Update journal entry status -- Need to generate this within IF <condition>
83707    ----------------------------------------------------------------------------------
83708    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
83709          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
83710          ,p_balance_type_code => l_balance_type_code
83711          );
83712 
83713    -------------------------------------------------------------------------------------------
83714    -- 4262811 - Generate the Accrual Reversal lines
83715    -------------------------------------------------------------------------------------------
83716    BEGIN
83717       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
83718                               (g_array_event(p_event_id).array_value_num('header_index'));
83719       IF l_acc_rev_flag IS NULL THEN
83720          l_acc_rev_flag := 'N';
83721       END IF;
83722    EXCEPTION
83723       WHEN OTHERS THEN
83724          l_acc_rev_flag := 'N';
83725    END;
83726    --
83727    IF (l_acc_rev_flag = 'Y') THEN
83728 
83729        -- 4645092  ------------------------------------------------------------------------------
83730        -- To allow MPA report to determine if it should generate report process
83731        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
83732        ------------------------------------------------------------------------------------------
83733 
83734        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
83735        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
83736    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
83737    -- call ADRs
83738    -- Bug 4922099
83739    --
83740    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
83741         (NVL(l_actual_upg_option, 'N') = 'O') OR
83742         (NVL(l_enc_upg_option, 'N') = 'O')
83743       )
83744    THEN
83745    NULL;
83746    --
83747    --
83748    
83749   l_ccid := AcctDerRule_179(
83750            p_application_id           => p_application_id
83751          , p_ae_header_id             => l_ae_header_id 
83752 , p_source_30 => p_source_30
83753 , p_source_34 => p_source_34
83754          , x_transaction_coa_id       => l_adr_transaction_coa_id
83755          , x_accounting_coa_id        => l_adr_accounting_coa_id
83756          , x_value_type_code          => l_adr_value_type_code
83757          , p_side                     => 'NA'
83758    );
83759 
83760    xla_ae_lines_pkg.set_ccid(
83761     p_code_combination_id          => l_ccid
83762   , p_value_type_code              => l_adr_value_type_code
83763   , p_transaction_coa_id           => l_adr_transaction_coa_id
83764   , p_accounting_coa_id            => l_adr_accounting_coa_id
83765   , p_adr_code                     => 'FA_PER_REVAL_RESERVE'
83766   , p_adr_type_code                => 'S'
83767   , p_component_type               => l_component_type
83768   , p_component_code               => l_component_code
83769   , p_component_type_code          => l_component_type_code
83770   , p_component_appl_id            => l_component_appl_id
83771   , p_amb_context_code             => l_amb_context_code
83772   , p_side                         => 'NA'
83773   );
83774 
83775 
83776    l_segment := AcctDerRule_150(
83777            p_application_id           => p_application_id
83778          , p_ae_header_id             => l_ae_header_id 
83782          , x_accounting_coa_id        => l_adr_accounting_coa_id
83779 , p_source_3 => p_source_3
83780 , p_source_11 => p_source_11
83781          , x_transaction_coa_id       => l_adr_transaction_coa_id
83783          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
83784          , x_flex_value_set_id        => l_adr_flex_value_set_id
83785          , x_value_type_code          => l_adr_value_type_code
83786          , x_value_combination_id     => l_adr_value_combination_id
83787          , x_value_segment_code       => l_adr_value_segment_code
83788          , p_side                     => 'NA'
83789          , p_override_seg_flag        => 'Y'
83790    );
83791 
83792    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
83793 
83794       xla_ae_lines_pkg.set_segment(
83795           p_to_segment_code         => 'GL_ACCOUNT'
83796         , p_segment_value           => l_segment
83797         , p_from_segment_code       => l_adr_value_segment_code
83798         , p_from_combination_id     => l_adr_value_combination_id
83799         , p_value_type_code         => l_adr_value_type_code
83800         , p_transaction_coa_id      => l_adr_transaction_coa_id
83801         , p_accounting_coa_id       => l_adr_accounting_coa_id
83802         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
83803         , p_flex_value_set_id       => l_adr_flex_value_set_id
83804         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
83805         , p_adr_type_code           => 'S'
83806         , p_component_type          => l_component_type
83807         , p_component_code          => l_component_code
83808         , p_component_type_code     => l_component_type_code
83809         , p_component_appl_id       => l_component_appl_id
83810         , p_amb_context_code        => l_amb_context_code
83811         , p_entity_code             => 'DEPRECIATION'
83812         , p_event_class_code        => 'DEPRECIATION'
83813         , p_side                    => 'NA'
83814         );
83815 
83816   END IF;
83817 
83818    l_segment := AcctDerRule_168(
83819            p_application_id           => p_application_id
83820          , p_ae_header_id             => l_ae_header_id 
83821 , p_source_3 => p_source_3
83822 , p_source_29 => p_source_29
83823          , x_transaction_coa_id       => l_adr_transaction_coa_id
83824          , x_accounting_coa_id        => l_adr_accounting_coa_id
83825          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
83826          , x_flex_value_set_id        => l_adr_flex_value_set_id
83827          , x_value_type_code          => l_adr_value_type_code
83828          , x_value_combination_id     => l_adr_value_combination_id
83829          , x_value_segment_code       => l_adr_value_segment_code
83830          , p_side                     => 'NA'
83831          , p_override_seg_flag        => 'Y'
83832    );
83833 
83834    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
83835 
83836       xla_ae_lines_pkg.set_segment(
83837           p_to_segment_code         => 'GL_BALANCING'
83838         , p_segment_value           => l_segment
83839         , p_from_segment_code       => l_adr_value_segment_code
83840         , p_from_combination_id     => l_adr_value_combination_id
83841         , p_value_type_code         => l_adr_value_type_code
83842         , p_transaction_coa_id      => l_adr_transaction_coa_id
83843         , p_accounting_coa_id       => l_adr_accounting_coa_id
83844         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
83845         , p_flex_value_set_id       => l_adr_flex_value_set_id
83846         , p_adr_code                => 'FA_EXPENSE_ACCT'
83847         , p_adr_type_code           => 'S'
83848         , p_component_type          => l_component_type
83849         , p_component_code          => l_component_code
83850         , p_component_type_code     => l_component_type_code
83851         , p_component_appl_id       => l_component_appl_id
83852         , p_amb_context_code        => l_amb_context_code
83853         , p_entity_code             => 'DEPRECIATION'
83854         , p_event_class_code        => 'DEPRECIATION'
83855         , p_side                    => 'NA'
83856         );
83857 
83858   END IF;
83859 
83860    --
83861    --
83862    END IF;
83863 
83864        --
83865        -- Update the line information that should be overwritten
83866        --
83867        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
83868                                          p_header_num   => 1);
83869        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
83870 
83871        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
83872 
83873        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
83874           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
83875        END IF;
83876 
83877       --
83878       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
83879       --
83880       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
83881           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
83882       ELSE
83883           ---------------------------------------------------------------------------------------------------
83884           -- 4262811a Switch Sign
83885           ---------------------------------------------------------------------------------------------------
83886           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
83887           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
83888                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
83889           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
83893                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
83890                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
83891           -- 5132302
83892           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
83894 
83895       END IF;
83896 
83897       -- 4955764
83898       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
83899       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
83900 
83901 
83902       XLA_AE_LINES_PKG.ValidateCurrentLine;
83903       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
83904 
83905       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
83906                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
83907                ,p_balance_type_code => l_balance_type_code);
83908 
83909    END IF;
83910 
83911    -----------------------------------------------------------------------------------------
83912    -- 4262811 Multiperiod Accounting
83913    -----------------------------------------------------------------------------------------
83914      -- No MPA option is assigned.
83915 
83916 
83917 END IF;
83918 END IF;
83919 --
83920 
83921 --
83922 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
83923    trace
83924       (p_msg      => 'END of AcctLineType_270'
83925       ,p_level    => C_LEVEL_PROCEDURE
83926       ,p_module   => l_log_module);
83927 END IF;
83928 --
83929 EXCEPTION
83930   WHEN xla_exceptions_pkg.application_exception THEN
83931       RAISE;
83932   WHEN OTHERS THEN
83933        xla_exceptions_pkg.raise_message
83934            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_270');
83935 END AcctLineType_270;
83936 --
83937 
83938 ---------------------------------------
83939 --
83940 -- PRIVATE FUNCTION
83941 --         AcctLineType_271
83942 --
83943 ---------------------------------------
83944 PROCEDURE AcctLineType_271 (
83945   p_application_id        IN NUMBER
83946  ,p_event_id              IN NUMBER
83947  ,p_calculate_acctd_flag  IN VARCHAR2
83948  ,p_calculate_g_l_flag    IN VARCHAR2
83949  ,p_actual_flag           IN OUT VARCHAR2
83950  ,p_balance_type_code     OUT VARCHAR2
83951  ,p_gain_or_loss_ref      OUT VARCHAR2
83952  
83953 --Period Close Date
83954  , p_source_1            IN DATE
83955 --Generated Code Combination Identifier
83956  , p_source_3            IN NUMBER
83957 --Expense Account Code Combination Identifier
83958  , p_source_29            IN NUMBER
83959 --Distribution Type Code
83960  , p_source_38            IN VARCHAR2
83961 --Currency Code
83962  , p_source_40            IN VARCHAR2
83963 --Asset Identifier
83964  , p_source_43            IN NUMBER
83965 --Period Counter
83966  , p_source_44            IN NUMBER
83967 --Distribution Identifier
83968  , p_source_45            IN NUMBER
83969 --Book Type Code
83970  , p_source_46            IN VARCHAR2
83971 --Bonus Entered Amount
83972  , p_source_48            IN NUMBER
83973 --Depreciation Run Identifier
83974  , p_source_49            IN NUMBER
83975 )
83976 IS
83977 
83978 l_component_type              VARCHAR2(80);
83979 l_component_code              VARCHAR2(30);
83980 l_component_type_code         VARCHAR2(1);
83981 l_component_appl_id           INTEGER;
83982 l_amb_context_code            VARCHAR2(30);
83983 l_entity_code                 VARCHAR2(30);
83984 l_event_class_code            VARCHAR2(30);
83985 l_ae_header_id                NUMBER;
83986 l_event_type_code             VARCHAR2(30);
83987 l_line_definition_code        VARCHAR2(30);
83988 l_line_definition_owner_code  VARCHAR2(1);
83989 --
83990 -- adr variables
83991 l_segment                     VARCHAR2(30);
83992 l_ccid                        NUMBER;
83993 l_adr_transaction_coa_id      NUMBER;
83994 l_adr_accounting_coa_id       NUMBER;
83995 l_adr_flexfield_segment_code  VARCHAR2(30);
83996 l_adr_flex_value_set_id       NUMBER;
83997 l_adr_value_type_code         VARCHAR2(30);
83998 l_adr_value_combination_id    NUMBER;
83999 l_adr_value_segment_code      VARCHAR2(30);
84000 
84001 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
84002 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
84003 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
84004 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
84005 
84006 -- 4262811 Variables ------------------------------------------------------------------------------------------
84007 l_entered_amt_idx             NUMBER;
84008 l_accted_amt_idx              NUMBER;
84009 l_acc_rev_flag                VARCHAR2(1);
84010 l_accrual_line_num            NUMBER;
84011 l_tmp_amt                     NUMBER;
84012 l_acc_rev_natural_side_code   VARCHAR2(1);
84013 
84014 l_num_entries                 NUMBER;
84015 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
84016 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
84017 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
84018 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
84019 l_recog_line_1                NUMBER;
84020 l_recog_line_2                NUMBER;
84021 
84022 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
84023 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
84024 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
84025 
84026 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
84027 
84028 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
84032 
84029 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
84030 
84031 ---------------------------------------------------------------------------------------------------------------
84033 
84034 --
84035 -- bulk performance
84036 --
84037 l_balance_type_code           VARCHAR2(1);
84038 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
84039 l_log_module                  VARCHAR2(240);
84040 
84041 --
84042 -- Upgrade strategy
84043 --
84044 l_actual_upg_option           VARCHAR2(1);
84045 l_enc_upg_option           VARCHAR2(1);
84046 
84047 --
84048 BEGIN
84049 --
84050 IF g_log_enabled THEN
84051       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_271';
84052 END IF;
84053 --
84054 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
84055 
84056       trace
84057          (p_msg      => 'BEGIN of AcctLineType_271'
84058          ,p_level    => C_LEVEL_PROCEDURE
84059          ,p_module   => l_log_module);
84060 
84061 END IF;
84062 --
84063 l_component_type             := 'AMB_JLT';
84064 l_component_code             := 'FA_PER_EXP_BAL';
84065 l_component_type_code        := 'S';
84066 l_component_appl_id          :=  140;
84067 l_amb_context_code           := 'DEFAULT';
84068 l_entity_code                := 'DEPRECIATION';
84069 l_event_class_code           := 'DEPRECIATION';
84070 l_event_type_code            := 'DEPRECIATION_ALL';
84071 l_line_definition_owner_code := 'S';
84072 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE16';
84073 --
84074 l_balance_type_code          := 'A';
84075 l_segment                     := NULL;
84076 l_ccid                        := NULL;
84077 l_adr_transaction_coa_id      := NULL;
84078 l_adr_accounting_coa_id       := NULL;
84079 l_adr_flexfield_segment_code  := NULL;
84080 l_adr_flex_value_set_id       := NULL;
84081 l_adr_value_type_code         := NULL;
84082 l_adr_value_combination_id    := NULL;
84083 l_adr_value_segment_code      := NULL;
84084 
84085 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
84086 l_bflow_class_code           := '';    -- 4219869 Business Flow
84087 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
84088 l_budgetary_control_flag     := 'N';
84089 
84090 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
84091 l_bflow_applied_to_amt       := NULL; -- 5132302
84092 l_entered_amt_idx            := NULL;          -- 4262811
84093 l_accted_amt_idx             := NULL;          -- 4262811
84094 l_acc_rev_flag               := NULL;          -- 4262811
84095 l_accrual_line_num           := NULL;          -- 4262811
84096 l_tmp_amt                    := NULL;          -- 4262811
84097 --
84098  
84099 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
84100     l_balance_type_code <> 'B' THEN
84101 IF NVL(p_source_48,9E125) <>  0 AND 
84102 NVL(p_source_38,'
84103 ') =  'DEPRN'
84104  THEN 
84105 
84106    --
84107    XLA_AE_LINES_PKG.SetNewLine;
84108 
84109    p_balance_type_code          := l_balance_type_code;
84110    -- set the flag so later we will know whether the gain loss line needs to be created
84111    
84112    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
84113      p_actual_flag :='A';
84114    END IF;
84115 
84116    --
84117    -- bulk performance
84118    --
84119    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
84120                                       p_header_num   => 0); -- 4262811
84121    --
84122    -- set accounting line options
84123    --
84124    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
84125            p_natural_side_code          => 'C'
84126          , p_gain_or_loss_flag          => 'N'
84127          , p_gl_transfer_mode_code      => 'S'
84128          , p_acct_entry_type_code       => 'A'
84129          , p_switch_side_flag           => 'Y'
84130          , p_merge_duplicate_code       => 'N'
84131          );
84132    --
84133    l_acc_rev_natural_side_code := 'D';  -- 4262811
84134    -- 
84135    --
84136    -- set accounting line type info
84137    --
84138    xla_ae_lines_pkg.SetAcctLineType
84139       (p_component_type             => l_component_type
84140       ,p_event_type_code            => l_event_type_code
84141       ,p_line_definition_owner_code => l_line_definition_owner_code
84142       ,p_line_definition_code       => l_line_definition_code
84143       ,p_accounting_line_code       => l_component_code
84144       ,p_accounting_line_type_code  => l_component_type_code
84145       ,p_accounting_line_appl_id    => l_component_appl_id
84146       ,p_amb_context_code           => l_amb_context_code
84147       ,p_entity_code                => l_entity_code
84148       ,p_event_class_code           => l_event_class_code);
84149    --
84150    -- set accounting class
84151    --
84152    xla_ae_lines_pkg.SetAcctClass(
84153            p_accounting_class_code  => 'EXPENSE'
84154          , p_ae_header_id           => l_ae_header_id
84155          );
84156 
84157    --
84158    -- set rounding class
84159    --
84160    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
84161                       'EXPENSE';
84162 
84163    --
84164    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
84165    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
84166    --
84167    -- bulk performance
84168    --
84169    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
84170 
84171    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
84172       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
84176       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
84173 
84174    -- 4955764
84175    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
84177 
84178    -- 4458381 Public Sector Enh
84179    
84180    --
84181    -- set accounting attributes for the line type
84182    --
84183    l_entered_amt_idx := 7;
84184    l_accted_amt_idx  := 9;
84185    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
84186    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
84187    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
84188    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
84189    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
84190    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
84191    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_49);
84192    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
84193    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
84194    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
84195    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_45);
84196    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
84197    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
84198    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
84199    l_rec_acct_attrs.array_num_value(7)  := p_source_48;
84200    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
84201    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
84202    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
84203    l_rec_acct_attrs.array_num_value(9)  := p_source_48;
84204 
84205    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
84206    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
84207 
84208    ---------------------------------------------------------------------------------------------------------------
84209    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
84210    ---------------------------------------------------------------------------------------------------------------
84211    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
84212 
84213    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
84214    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
84215 
84216    IF xla_accounting_cache_pkg.GetValueChar
84217          (p_source_code         => 'LEDGER_CATEGORY_CODE'
84218          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
84219    AND l_bflow_method_code = 'PRIOR_ENTRY'
84220 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
84221    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
84222          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
84223        )
84224    THEN
84225          xla_ae_lines_pkg.BflowUpgEntry
84226            (p_business_method_code    => l_bflow_method_code
84227            ,p_business_class_code     => l_bflow_class_code
84228            ,p_balance_type            => l_balance_type_code);
84229    ELSE
84230       NULL;
84231 -- No business flow processing for business flow method of NONE.
84232    END IF;
84233 
84234    --
84235    -- call analytical criteria
84236    --
84237    
84238    --
84239    -- call description
84240    --
84241    
84242 xla_ae_lines_pkg.SetLineDescription(
84243    p_ae_header_id => l_ae_header_id
84244   ,p_description  => Description_57 (
84245      p_application_id         => p_application_id
84246    , p_ae_header_id           => l_ae_header_id 
84247 , p_source_1 => p_source_1
84248    )
84249 );
84250 
84251 
84252    --
84253    -- call ADRs
84254    -- Bug 4922099
84255    --
84256    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
84257         (NVL(l_actual_upg_option, 'N') = 'O') OR
84258         (NVL(l_enc_upg_option, 'N') = 'O')
84259       )
84260    THEN
84261    NULL;
84262    --
84263    --
84264    
84265   l_ccid := AcctDerRule_175(
84266            p_application_id           => p_application_id
84267          , p_ae_header_id             => l_ae_header_id 
84268 , p_source_3 => p_source_3
84269 , p_source_29 => p_source_29
84270          , x_transaction_coa_id       => l_adr_transaction_coa_id
84271          , x_accounting_coa_id        => l_adr_accounting_coa_id
84272          , x_value_type_code          => l_adr_value_type_code
84273          , p_side                     => 'NA'
84274    );
84275 
84276    xla_ae_lines_pkg.set_ccid(
84277     p_code_combination_id          => l_ccid
84278   , p_value_type_code              => l_adr_value_type_code
84279   , p_transaction_coa_id           => l_adr_transaction_coa_id
84280   , p_accounting_coa_id            => l_adr_accounting_coa_id
84281   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
84282   , p_adr_type_code                => 'S'
84283   , p_component_type               => l_component_type
84284   , p_component_code               => l_component_code
84285   , p_component_type_code          => l_component_type_code
84286   , p_component_appl_id            => l_component_appl_id
84287   , p_amb_context_code             => l_amb_context_code
84288   , p_side                         => 'NA'
84289   );
84290 
84291 
84292    --
84293    --
84294    END IF;
84295    --
84296    -- Bug 4922099
84297    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
84298           (NVL(l_enc_upg_option, 'N') = 'O')
84299         ) AND
84300         (l_bflow_method_code = 'PRIOR_ENTRY')
84301       )
84302    THEN
84303       IF
84304       --
84308       xla_accounting_err_pkg.build_message
84305       1 = 2
84306       --
84307       THEN
84309                                     (p_appli_s_name            => 'XLA'
84310                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
84311                                     ,p_token_1                 => 'LINE_NUMBER'
84312                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
84313                                     ,p_token_2                 => 'LINE_TYPE_NAME'
84314                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
84315                                                                              l_component_type
84316                                                                             ,l_component_code
84317                                                                             ,l_component_type_code
84318                                                                             ,l_component_appl_id
84319                                                                             ,l_amb_context_code
84320                                                                             ,l_entity_code
84321                                                                             ,l_event_class_code
84322                                                                            )
84323                                     ,p_token_3                 => 'OWNER'
84324                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
84325                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
84326                                                                           ,p_lookup_code    => l_component_type_code
84327                                                                          )
84328                                     ,p_token_4                 => 'PRODUCT_NAME'
84329                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
84330                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
84331                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
84332                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
84333                                     ,p_ae_header_id            =>  NULL
84334                                        );
84335 
84336         IF (C_LEVEL_ERROR>= g_log_level) THEN
84337                  trace
84338                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
84339                       ,p_level    => C_LEVEL_ERROR
84340                       ,p_module   => l_log_module);
84341         END IF;
84342       END IF;
84343    END IF;
84344    --
84345    --
84346    ------------------------------------------------------------------------------------------------
84347    -- 4219869 Business Flow
84348    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
84349    -- Prior Entry.  Currently, the following code is always generated.
84350    ------------------------------------------------------------------------------------------------
84351    XLA_AE_LINES_PKG.ValidateCurrentLine;
84352 
84353    ------------------------------------------------------------------------------------
84354    -- 4219869 Business Flow
84355    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
84356    ------------------------------------------------------------------------------------
84357    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
84358 
84359    ----------------------------------------------------------------------------------
84360    -- 4219869 Business Flow
84361    -- Update journal entry status -- Need to generate this within IF <condition>
84362    ----------------------------------------------------------------------------------
84363    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
84364          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
84365          ,p_balance_type_code => l_balance_type_code
84366          );
84367 
84368    -------------------------------------------------------------------------------------------
84369    -- 4262811 - Generate the Accrual Reversal lines
84370    -------------------------------------------------------------------------------------------
84371    BEGIN
84372       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
84373                               (g_array_event(p_event_id).array_value_num('header_index'));
84374       IF l_acc_rev_flag IS NULL THEN
84375          l_acc_rev_flag := 'N';
84376       END IF;
84377    EXCEPTION
84378       WHEN OTHERS THEN
84379          l_acc_rev_flag := 'N';
84380    END;
84381    --
84382    IF (l_acc_rev_flag = 'Y') THEN
84383 
84384        -- 4645092  ------------------------------------------------------------------------------
84385        -- To allow MPA report to determine if it should generate report process
84386        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
84387        ------------------------------------------------------------------------------------------
84388 
84389        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
84390        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
84391    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
84392    -- call ADRs
84393    -- Bug 4922099
84394    --
84395    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
84396         (NVL(l_actual_upg_option, 'N') = 'O') OR
84397         (NVL(l_enc_upg_option, 'N') = 'O')
84398       )
84399    THEN
84400    NULL;
84401    --
84402    --
84403    
84404   l_ccid := AcctDerRule_175(
84405            p_application_id           => p_application_id
84406          , p_ae_header_id             => l_ae_header_id 
84407 , p_source_3 => p_source_3
84411          , x_value_type_code          => l_adr_value_type_code
84408 , p_source_29 => p_source_29
84409          , x_transaction_coa_id       => l_adr_transaction_coa_id
84410          , x_accounting_coa_id        => l_adr_accounting_coa_id
84412          , p_side                     => 'NA'
84413    );
84414 
84415    xla_ae_lines_pkg.set_ccid(
84416     p_code_combination_id          => l_ccid
84417   , p_value_type_code              => l_adr_value_type_code
84418   , p_transaction_coa_id           => l_adr_transaction_coa_id
84419   , p_accounting_coa_id            => l_adr_accounting_coa_id
84420   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
84421   , p_adr_type_code                => 'S'
84422   , p_component_type               => l_component_type
84423   , p_component_code               => l_component_code
84424   , p_component_type_code          => l_component_type_code
84425   , p_component_appl_id            => l_component_appl_id
84426   , p_amb_context_code             => l_amb_context_code
84427   , p_side                         => 'NA'
84428   );
84429 
84430 
84431    --
84432    --
84433    END IF;
84434 
84435        --
84436        -- Update the line information that should be overwritten
84437        --
84438        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
84439                                          p_header_num   => 1);
84440        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
84441 
84442        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
84443 
84444        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
84445           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
84446        END IF;
84447 
84448       --
84449       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
84450       --
84451       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
84452           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
84453       ELSE
84454           ---------------------------------------------------------------------------------------------------
84455           -- 4262811a Switch Sign
84456           ---------------------------------------------------------------------------------------------------
84457           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
84458           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
84459                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
84460           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
84461                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
84462           -- 5132302
84463           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
84464                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
84465 
84466       END IF;
84467 
84468       -- 4955764
84469       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
84470       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
84471 
84472 
84473       XLA_AE_LINES_PKG.ValidateCurrentLine;
84474       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
84475 
84476       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
84477                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
84478                ,p_balance_type_code => l_balance_type_code);
84479 
84480    END IF;
84481 
84482    -----------------------------------------------------------------------------------------
84483    -- 4262811 Multiperiod Accounting
84484    -----------------------------------------------------------------------------------------
84485      -- No MPA option is assigned.
84486 
84487 
84488 END IF;
84489 END IF;
84490 --
84491 
84492 --
84493 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
84494    trace
84495       (p_msg      => 'END of AcctLineType_271'
84496       ,p_level    => C_LEVEL_PROCEDURE
84497       ,p_module   => l_log_module);
84498 END IF;
84499 --
84500 EXCEPTION
84501   WHEN xla_exceptions_pkg.application_exception THEN
84502       RAISE;
84503   WHEN OTHERS THEN
84504        xla_exceptions_pkg.raise_message
84505            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_271');
84506 END AcctLineType_271;
84507 --
84508 
84509 ---------------------------------------
84510 --
84511 -- PRIVATE FUNCTION
84512 --         AcctLineType_272
84513 --
84514 ---------------------------------------
84515 PROCEDURE AcctLineType_272 (
84516   p_application_id        IN NUMBER
84517  ,p_event_id              IN NUMBER
84518  ,p_calculate_acctd_flag  IN VARCHAR2
84519  ,p_calculate_g_l_flag    IN VARCHAR2
84520  ,p_actual_flag           IN OUT VARCHAR2
84521  ,p_balance_type_code     OUT VARCHAR2
84522  ,p_gain_or_loss_ref      OUT VARCHAR2
84523  
84524 --Period Close Date
84525  , p_source_1            IN DATE
84526 --Generated Code Combination Identifier
84527  , p_source_3            IN NUMBER
84528 --Depreciation Reserve Account
84529  , p_source_10            IN VARCHAR2
84530 --Generated Offset Code Combination Identifier
84531  , p_source_17            IN NUMBER
84532 --Expense Account Code Combination Identifier
84533  , p_source_29            IN NUMBER
84534 --Default Code Combination Identifier
84535  , p_source_30            IN NUMBER
84536 --Distribution Type Code
84537  , p_source_38            IN VARCHAR2
84538 --Currency Code
84542 --Period Counter
84539  , p_source_40            IN VARCHAR2
84540 --Asset Identifier
84541  , p_source_43            IN NUMBER
84543  , p_source_44            IN NUMBER
84544 --Distribution Identifier
84545  , p_source_45            IN NUMBER
84546 --Book Type Code
84547  , p_source_46            IN VARCHAR2
84548 --Bonus Entered Amount
84549  , p_source_48            IN NUMBER
84550 --Depreciation Run Identifier
84551  , p_source_49            IN NUMBER
84552 )
84553 IS
84554 
84555 l_component_type              VARCHAR2(80);
84556 l_component_code              VARCHAR2(30);
84557 l_component_type_code         VARCHAR2(1);
84558 l_component_appl_id           INTEGER;
84559 l_amb_context_code            VARCHAR2(30);
84560 l_entity_code                 VARCHAR2(30);
84561 l_event_class_code            VARCHAR2(30);
84562 l_ae_header_id                NUMBER;
84563 l_event_type_code             VARCHAR2(30);
84564 l_line_definition_code        VARCHAR2(30);
84565 l_line_definition_owner_code  VARCHAR2(1);
84566 --
84567 -- adr variables
84568 l_segment                     VARCHAR2(30);
84569 l_ccid                        NUMBER;
84570 l_adr_transaction_coa_id      NUMBER;
84571 l_adr_accounting_coa_id       NUMBER;
84572 l_adr_flexfield_segment_code  VARCHAR2(30);
84573 l_adr_flex_value_set_id       NUMBER;
84574 l_adr_value_type_code         VARCHAR2(30);
84575 l_adr_value_combination_id    NUMBER;
84576 l_adr_value_segment_code      VARCHAR2(30);
84577 
84578 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
84579 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
84580 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
84581 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
84582 
84583 -- 4262811 Variables ------------------------------------------------------------------------------------------
84584 l_entered_amt_idx             NUMBER;
84585 l_accted_amt_idx              NUMBER;
84586 l_acc_rev_flag                VARCHAR2(1);
84587 l_accrual_line_num            NUMBER;
84588 l_tmp_amt                     NUMBER;
84589 l_acc_rev_natural_side_code   VARCHAR2(1);
84590 
84591 l_num_entries                 NUMBER;
84592 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
84593 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
84594 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
84595 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
84596 l_recog_line_1                NUMBER;
84597 l_recog_line_2                NUMBER;
84598 
84599 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
84600 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
84601 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
84602 
84603 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
84604 
84605 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
84606 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
84607 
84608 ---------------------------------------------------------------------------------------------------------------
84609 
84610 
84611 --
84612 -- bulk performance
84613 --
84614 l_balance_type_code           VARCHAR2(1);
84615 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
84616 l_log_module                  VARCHAR2(240);
84617 
84618 --
84619 -- Upgrade strategy
84620 --
84621 l_actual_upg_option           VARCHAR2(1);
84622 l_enc_upg_option           VARCHAR2(1);
84623 
84624 --
84625 BEGIN
84626 --
84627 IF g_log_enabled THEN
84628       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_272';
84629 END IF;
84630 --
84631 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
84632 
84633       trace
84634          (p_msg      => 'BEGIN of AcctLineType_272'
84635          ,p_level    => C_LEVEL_PROCEDURE
84636          ,p_module   => l_log_module);
84637 
84638 END IF;
84639 --
84640 l_component_type             := 'AMB_JLT';
84641 l_component_code             := 'FA_PER_RESERVE_BAL';
84642 l_component_type_code        := 'S';
84643 l_component_appl_id          :=  140;
84644 l_amb_context_code           := 'DEFAULT';
84645 l_entity_code                := 'DEPRECIATION';
84646 l_event_class_code           := 'DEPRECIATION';
84647 l_event_type_code            := 'DEPRECIATION_ALL';
84648 l_line_definition_owner_code := 'S';
84649 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE16';
84650 --
84651 l_balance_type_code          := 'A';
84652 l_segment                     := NULL;
84653 l_ccid                        := NULL;
84654 l_adr_transaction_coa_id      := NULL;
84655 l_adr_accounting_coa_id       := NULL;
84656 l_adr_flexfield_segment_code  := NULL;
84657 l_adr_flex_value_set_id       := NULL;
84658 l_adr_value_type_code         := NULL;
84659 l_adr_value_combination_id    := NULL;
84660 l_adr_value_segment_code      := NULL;
84661 
84662 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
84663 l_bflow_class_code           := '';    -- 4219869 Business Flow
84664 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
84665 l_budgetary_control_flag     := 'N';
84666 
84667 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
84668 l_bflow_applied_to_amt       := NULL; -- 5132302
84669 l_entered_amt_idx            := NULL;          -- 4262811
84670 l_accted_amt_idx             := NULL;          -- 4262811
84671 l_acc_rev_flag               := NULL;          -- 4262811
84672 l_accrual_line_num           := NULL;          -- 4262811
84673 l_tmp_amt                    := NULL;          -- 4262811
84674 --
84675  
84679 NVL(p_source_38,'
84676 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
84677     l_balance_type_code <> 'B' THEN
84678 IF NVL(p_source_48,9E125) <>  0 AND 
84680 ') =  'DEPRN'
84681  THEN 
84682 
84683    --
84684    XLA_AE_LINES_PKG.SetNewLine;
84685 
84686    p_balance_type_code          := l_balance_type_code;
84687    -- set the flag so later we will know whether the gain loss line needs to be created
84688    
84689    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
84690      p_actual_flag :='A';
84691    END IF;
84692 
84693    --
84694    -- bulk performance
84695    --
84696    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
84697                                       p_header_num   => 0); -- 4262811
84698    --
84699    -- set accounting line options
84700    --
84701    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
84702            p_natural_side_code          => 'D'
84703          , p_gain_or_loss_flag          => 'N'
84704          , p_gl_transfer_mode_code      => 'S'
84705          , p_acct_entry_type_code       => 'A'
84706          , p_switch_side_flag           => 'Y'
84707          , p_merge_duplicate_code       => 'N'
84708          );
84709    --
84710    l_acc_rev_natural_side_code := 'C';  -- 4262811
84711    -- 
84712    --
84713    -- set accounting line type info
84714    --
84715    xla_ae_lines_pkg.SetAcctLineType
84716       (p_component_type             => l_component_type
84717       ,p_event_type_code            => l_event_type_code
84718       ,p_line_definition_owner_code => l_line_definition_owner_code
84719       ,p_line_definition_code       => l_line_definition_code
84720       ,p_accounting_line_code       => l_component_code
84721       ,p_accounting_line_type_code  => l_component_type_code
84722       ,p_accounting_line_appl_id    => l_component_appl_id
84723       ,p_amb_context_code           => l_amb_context_code
84724       ,p_entity_code                => l_entity_code
84725       ,p_event_class_code           => l_event_class_code);
84726    --
84727    -- set accounting class
84728    --
84729    xla_ae_lines_pkg.SetAcctClass(
84730            p_accounting_class_code  => 'ASSET'
84731          , p_ae_header_id           => l_ae_header_id
84732          );
84733 
84734    --
84735    -- set rounding class
84736    --
84737    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
84738                       'ASSET';
84739 
84740    --
84741    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
84742    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
84743    --
84744    -- bulk performance
84745    --
84746    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
84747 
84748    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
84749       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
84750 
84751    -- 4955764
84752    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
84753       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
84754 
84755    -- 4458381 Public Sector Enh
84756    
84757    --
84758    -- set accounting attributes for the line type
84759    --
84760    l_entered_amt_idx := 7;
84761    l_accted_amt_idx  := 9;
84762    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
84763    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
84764    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_43);
84765    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
84766    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_44);
84767    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_IDENTIFIER_3';
84768    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_49);
84769    l_rec_acct_attrs.array_acct_attr_code(4) := 'DISTRIBUTION_IDENTIFIER_4';
84770    l_rec_acct_attrs.array_char_value(4)  := p_source_46;
84771    l_rec_acct_attrs.array_acct_attr_code(5) := 'DISTRIBUTION_IDENTIFIER_5';
84772    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_45);
84773    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_TYPE';
84774    l_rec_acct_attrs.array_char_value(6)  := p_source_38;
84775    l_rec_acct_attrs.array_acct_attr_code(7) := 'ENTERED_CURRENCY_AMOUNT';
84776    l_rec_acct_attrs.array_num_value(7)  := p_source_48;
84777    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_CODE';
84778    l_rec_acct_attrs.array_char_value(8)  := p_source_40;
84779    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
84780    l_rec_acct_attrs.array_num_value(9)  := p_source_48;
84781 
84782    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
84783    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
84784 
84785    ---------------------------------------------------------------------------------------------------------------
84786    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
84787    ---------------------------------------------------------------------------------------------------------------
84788    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
84789 
84790    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
84791    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
84792 
84793    IF xla_accounting_cache_pkg.GetValueChar
84794          (p_source_code         => 'LEDGER_CATEGORY_CODE'
84795          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
84799          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
84796    AND l_bflow_method_code = 'PRIOR_ENTRY'
84797 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
84798    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
84800        )
84801    THEN
84802          xla_ae_lines_pkg.BflowUpgEntry
84803            (p_business_method_code    => l_bflow_method_code
84804            ,p_business_class_code     => l_bflow_class_code
84805            ,p_balance_type            => l_balance_type_code);
84806    ELSE
84807       NULL;
84808 -- No business flow processing for business flow method of NONE.
84809    END IF;
84810 
84811    --
84812    -- call analytical criteria
84813    --
84814    
84815    --
84816    -- call description
84817    --
84818    
84819 xla_ae_lines_pkg.SetLineDescription(
84820    p_ae_header_id => l_ae_header_id
84821   ,p_description  => Description_59 (
84822      p_application_id         => p_application_id
84823    , p_ae_header_id           => l_ae_header_id 
84824 , p_source_1 => p_source_1
84825    )
84826 );
84827 
84828 
84829    --
84830    -- call ADRs
84831    -- Bug 4922099
84832    --
84833    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
84834         (NVL(l_actual_upg_option, 'N') = 'O') OR
84835         (NVL(l_enc_upg_option, 'N') = 'O')
84836       )
84837    THEN
84838    NULL;
84839    --
84840    --
84841    
84842   l_ccid := AcctDerRule_174(
84843            p_application_id           => p_application_id
84844          , p_ae_header_id             => l_ae_header_id 
84845 , p_source_3 => p_source_3
84846 , p_source_17 => p_source_17
84847 , p_source_30 => p_source_30
84848          , x_transaction_coa_id       => l_adr_transaction_coa_id
84849          , x_accounting_coa_id        => l_adr_accounting_coa_id
84850          , x_value_type_code          => l_adr_value_type_code
84851          , p_side                     => 'NA'
84852    );
84853 
84854    xla_ae_lines_pkg.set_ccid(
84855     p_code_combination_id          => l_ccid
84856   , p_value_type_code              => l_adr_value_type_code
84857   , p_transaction_coa_id           => l_adr_transaction_coa_id
84858   , p_accounting_coa_id            => l_adr_accounting_coa_id
84859   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
84860   , p_adr_type_code                => 'S'
84861   , p_component_type               => l_component_type
84862   , p_component_code               => l_component_code
84863   , p_component_type_code          => l_component_type_code
84864   , p_component_appl_id            => l_component_appl_id
84865   , p_amb_context_code             => l_amb_context_code
84866   , p_side                         => 'NA'
84867   );
84868 
84869 
84870    l_segment := AcctDerRule_149(
84871            p_application_id           => p_application_id
84872          , p_ae_header_id             => l_ae_header_id 
84873 , p_source_3 => p_source_3
84874 , p_source_10 => p_source_10
84875          , x_transaction_coa_id       => l_adr_transaction_coa_id
84876          , x_accounting_coa_id        => l_adr_accounting_coa_id
84877          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
84878          , x_flex_value_set_id        => l_adr_flex_value_set_id
84879          , x_value_type_code          => l_adr_value_type_code
84880          , x_value_combination_id     => l_adr_value_combination_id
84881          , x_value_segment_code       => l_adr_value_segment_code
84882          , p_side                     => 'NA'
84883          , p_override_seg_flag        => 'Y'
84884    );
84885 
84886    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
84887 
84888       xla_ae_lines_pkg.set_segment(
84889           p_to_segment_code         => 'GL_ACCOUNT'
84890         , p_segment_value           => l_segment
84891         , p_from_segment_code       => l_adr_value_segment_code
84892         , p_from_combination_id     => l_adr_value_combination_id
84893         , p_value_type_code         => l_adr_value_type_code
84894         , p_transaction_coa_id      => l_adr_transaction_coa_id
84895         , p_accounting_coa_id       => l_adr_accounting_coa_id
84896         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
84897         , p_flex_value_set_id       => l_adr_flex_value_set_id
84898         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
84899         , p_adr_type_code           => 'S'
84900         , p_component_type          => l_component_type
84901         , p_component_code          => l_component_code
84902         , p_component_type_code     => l_component_type_code
84903         , p_component_appl_id       => l_component_appl_id
84904         , p_amb_context_code        => l_amb_context_code
84905         , p_entity_code             => 'DEPRECIATION'
84906         , p_event_class_code        => 'DEPRECIATION'
84907         , p_side                    => 'NA'
84908         );
84909 
84910   END IF;
84911 
84912    l_segment := AcctDerRule_168(
84913            p_application_id           => p_application_id
84914          , p_ae_header_id             => l_ae_header_id 
84915 , p_source_3 => p_source_3
84916 , p_source_29 => p_source_29
84917          , x_transaction_coa_id       => l_adr_transaction_coa_id
84918          , x_accounting_coa_id        => l_adr_accounting_coa_id
84919          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
84920          , x_flex_value_set_id        => l_adr_flex_value_set_id
84921          , x_value_type_code          => l_adr_value_type_code
84922          , x_value_combination_id     => l_adr_value_combination_id
84923          , x_value_segment_code       => l_adr_value_segment_code
84924          , p_side                     => 'NA'
84925          , p_override_seg_flag        => 'Y'
84926    );
84927 
84928    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
84929 
84933         , p_from_segment_code       => l_adr_value_segment_code
84930       xla_ae_lines_pkg.set_segment(
84931           p_to_segment_code         => 'GL_BALANCING'
84932         , p_segment_value           => l_segment
84934         , p_from_combination_id     => l_adr_value_combination_id
84935         , p_value_type_code         => l_adr_value_type_code
84936         , p_transaction_coa_id      => l_adr_transaction_coa_id
84937         , p_accounting_coa_id       => l_adr_accounting_coa_id
84938         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
84939         , p_flex_value_set_id       => l_adr_flex_value_set_id
84940         , p_adr_code                => 'FA_EXPENSE_ACCT'
84941         , p_adr_type_code           => 'S'
84942         , p_component_type          => l_component_type
84943         , p_component_code          => l_component_code
84944         , p_component_type_code     => l_component_type_code
84945         , p_component_appl_id       => l_component_appl_id
84946         , p_amb_context_code        => l_amb_context_code
84947         , p_entity_code             => 'DEPRECIATION'
84948         , p_event_class_code        => 'DEPRECIATION'
84949         , p_side                    => 'NA'
84950         );
84951 
84952   END IF;
84953 
84954    --
84955    --
84956    END IF;
84957    --
84958    -- Bug 4922099
84959    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
84960           (NVL(l_enc_upg_option, 'N') = 'O')
84961         ) AND
84962         (l_bflow_method_code = 'PRIOR_ENTRY')
84963       )
84964    THEN
84965       IF
84966       --
84967       1 = 2
84968       --
84969       THEN
84970       xla_accounting_err_pkg.build_message
84971                                     (p_appli_s_name            => 'XLA'
84972                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
84973                                     ,p_token_1                 => 'LINE_NUMBER'
84974                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
84975                                     ,p_token_2                 => 'LINE_TYPE_NAME'
84976                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
84977                                                                              l_component_type
84978                                                                             ,l_component_code
84979                                                                             ,l_component_type_code
84980                                                                             ,l_component_appl_id
84981                                                                             ,l_amb_context_code
84982                                                                             ,l_entity_code
84983                                                                             ,l_event_class_code
84984                                                                            )
84985                                     ,p_token_3                 => 'OWNER'
84986                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
84987                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
84988                                                                           ,p_lookup_code    => l_component_type_code
84989                                                                          )
84990                                     ,p_token_4                 => 'PRODUCT_NAME'
84991                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
84992                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
84993                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
84994                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
84995                                     ,p_ae_header_id            =>  NULL
84996                                        );
84997 
84998         IF (C_LEVEL_ERROR>= g_log_level) THEN
84999                  trace
85000                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
85001                       ,p_level    => C_LEVEL_ERROR
85002                       ,p_module   => l_log_module);
85003         END IF;
85004       END IF;
85005    END IF;
85006    --
85007    --
85008    ------------------------------------------------------------------------------------------------
85009    -- 4219869 Business Flow
85010    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
85011    -- Prior Entry.  Currently, the following code is always generated.
85012    ------------------------------------------------------------------------------------------------
85013    XLA_AE_LINES_PKG.ValidateCurrentLine;
85014 
85015    ------------------------------------------------------------------------------------
85016    -- 4219869 Business Flow
85017    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
85018    ------------------------------------------------------------------------------------
85019    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
85020 
85021    ----------------------------------------------------------------------------------
85022    -- 4219869 Business Flow
85023    -- Update journal entry status -- Need to generate this within IF <condition>
85024    ----------------------------------------------------------------------------------
85025    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
85026          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
85027          ,p_balance_type_code => l_balance_type_code
85028          );
85029 
85030    -------------------------------------------------------------------------------------------
85031    -- 4262811 - Generate the Accrual Reversal lines
85035                               (g_array_event(p_event_id).array_value_num('header_index'));
85032    -------------------------------------------------------------------------------------------
85033    BEGIN
85034       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
85036       IF l_acc_rev_flag IS NULL THEN
85037          l_acc_rev_flag := 'N';
85038       END IF;
85039    EXCEPTION
85040       WHEN OTHERS THEN
85041          l_acc_rev_flag := 'N';
85042    END;
85043    --
85044    IF (l_acc_rev_flag = 'Y') THEN
85045 
85046        -- 4645092  ------------------------------------------------------------------------------
85047        -- To allow MPA report to determine if it should generate report process
85048        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
85049        ------------------------------------------------------------------------------------------
85050 
85051        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
85052        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
85053    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
85054    -- call ADRs
85055    -- Bug 4922099
85056    --
85057    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
85058         (NVL(l_actual_upg_option, 'N') = 'O') OR
85059         (NVL(l_enc_upg_option, 'N') = 'O')
85060       )
85061    THEN
85062    NULL;
85063    --
85064    --
85065    
85066   l_ccid := AcctDerRule_174(
85067            p_application_id           => p_application_id
85068          , p_ae_header_id             => l_ae_header_id 
85069 , p_source_3 => p_source_3
85070 , p_source_17 => p_source_17
85071 , p_source_30 => p_source_30
85072          , x_transaction_coa_id       => l_adr_transaction_coa_id
85073          , x_accounting_coa_id        => l_adr_accounting_coa_id
85074          , x_value_type_code          => l_adr_value_type_code
85075          , p_side                     => 'NA'
85076    );
85077 
85078    xla_ae_lines_pkg.set_ccid(
85079     p_code_combination_id          => l_ccid
85080   , p_value_type_code              => l_adr_value_type_code
85081   , p_transaction_coa_id           => l_adr_transaction_coa_id
85082   , p_accounting_coa_id            => l_adr_accounting_coa_id
85083   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
85084   , p_adr_type_code                => 'S'
85085   , p_component_type               => l_component_type
85086   , p_component_code               => l_component_code
85087   , p_component_type_code          => l_component_type_code
85088   , p_component_appl_id            => l_component_appl_id
85089   , p_amb_context_code             => l_amb_context_code
85090   , p_side                         => 'NA'
85091   );
85092 
85093 
85094    l_segment := AcctDerRule_149(
85095            p_application_id           => p_application_id
85096          , p_ae_header_id             => l_ae_header_id 
85097 , p_source_3 => p_source_3
85098 , p_source_10 => p_source_10
85099          , x_transaction_coa_id       => l_adr_transaction_coa_id
85100          , x_accounting_coa_id        => l_adr_accounting_coa_id
85101          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
85102          , x_flex_value_set_id        => l_adr_flex_value_set_id
85103          , x_value_type_code          => l_adr_value_type_code
85104          , x_value_combination_id     => l_adr_value_combination_id
85105          , x_value_segment_code       => l_adr_value_segment_code
85106          , p_side                     => 'NA'
85107          , p_override_seg_flag        => 'Y'
85108    );
85109 
85110    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
85111 
85112       xla_ae_lines_pkg.set_segment(
85113           p_to_segment_code         => 'GL_ACCOUNT'
85114         , p_segment_value           => l_segment
85115         , p_from_segment_code       => l_adr_value_segment_code
85116         , p_from_combination_id     => l_adr_value_combination_id
85117         , p_value_type_code         => l_adr_value_type_code
85118         , p_transaction_coa_id      => l_adr_transaction_coa_id
85119         , p_accounting_coa_id       => l_adr_accounting_coa_id
85120         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
85121         , p_flex_value_set_id       => l_adr_flex_value_set_id
85122         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
85123         , p_adr_type_code           => 'S'
85124         , p_component_type          => l_component_type
85125         , p_component_code          => l_component_code
85126         , p_component_type_code     => l_component_type_code
85127         , p_component_appl_id       => l_component_appl_id
85128         , p_amb_context_code        => l_amb_context_code
85129         , p_entity_code             => 'DEPRECIATION'
85130         , p_event_class_code        => 'DEPRECIATION'
85131         , p_side                    => 'NA'
85132         );
85133 
85134   END IF;
85135 
85136    l_segment := AcctDerRule_168(
85137            p_application_id           => p_application_id
85138          , p_ae_header_id             => l_ae_header_id 
85139 , p_source_3 => p_source_3
85140 , p_source_29 => p_source_29
85141          , x_transaction_coa_id       => l_adr_transaction_coa_id
85142          , x_accounting_coa_id        => l_adr_accounting_coa_id
85143          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
85144          , x_flex_value_set_id        => l_adr_flex_value_set_id
85145          , x_value_type_code          => l_adr_value_type_code
85146          , x_value_combination_id     => l_adr_value_combination_id
85147          , x_value_segment_code       => l_adr_value_segment_code
85148          , p_side                     => 'NA'
85149          , p_override_seg_flag        => 'Y'
85150    );
85151 
85152    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
85153 
85154       xla_ae_lines_pkg.set_segment(
85158         , p_from_combination_id     => l_adr_value_combination_id
85155           p_to_segment_code         => 'GL_BALANCING'
85156         , p_segment_value           => l_segment
85157         , p_from_segment_code       => l_adr_value_segment_code
85159         , p_value_type_code         => l_adr_value_type_code
85160         , p_transaction_coa_id      => l_adr_transaction_coa_id
85161         , p_accounting_coa_id       => l_adr_accounting_coa_id
85162         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
85163         , p_flex_value_set_id       => l_adr_flex_value_set_id
85164         , p_adr_code                => 'FA_EXPENSE_ACCT'
85165         , p_adr_type_code           => 'S'
85166         , p_component_type          => l_component_type
85167         , p_component_code          => l_component_code
85168         , p_component_type_code     => l_component_type_code
85169         , p_component_appl_id       => l_component_appl_id
85170         , p_amb_context_code        => l_amb_context_code
85171         , p_entity_code             => 'DEPRECIATION'
85172         , p_event_class_code        => 'DEPRECIATION'
85173         , p_side                    => 'NA'
85174         );
85175 
85176   END IF;
85177 
85178    --
85179    --
85180    END IF;
85181 
85182        --
85183        -- Update the line information that should be overwritten
85184        --
85185        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
85186                                          p_header_num   => 1);
85187        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
85188 
85189        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
85190 
85191        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
85192           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
85193        END IF;
85194 
85195       --
85196       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
85197       --
85198       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
85199           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
85200       ELSE
85201           ---------------------------------------------------------------------------------------------------
85202           -- 4262811a Switch Sign
85203           ---------------------------------------------------------------------------------------------------
85204           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
85205           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
85206                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
85207           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
85208                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
85209           -- 5132302
85210           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
85211                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
85212 
85213       END IF;
85214 
85215       -- 4955764
85216       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
85217       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
85218 
85219 
85220       XLA_AE_LINES_PKG.ValidateCurrentLine;
85221       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
85222 
85223       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
85224                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
85225                ,p_balance_type_code => l_balance_type_code);
85226 
85227    END IF;
85228 
85229    -----------------------------------------------------------------------------------------
85230    -- 4262811 Multiperiod Accounting
85231    -----------------------------------------------------------------------------------------
85232      -- No MPA option is assigned.
85233 
85234 
85235 END IF;
85236 END IF;
85237 --
85238 
85239 --
85240 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
85241    trace
85242       (p_msg      => 'END of AcctLineType_272'
85243       ,p_level    => C_LEVEL_PROCEDURE
85244       ,p_module   => l_log_module);
85245 END IF;
85246 --
85247 EXCEPTION
85248   WHEN xla_exceptions_pkg.application_exception THEN
85249       RAISE;
85250   WHEN OTHERS THEN
85251        xla_exceptions_pkg.raise_message
85252            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_272');
85253 END AcctLineType_272;
85254 --
85255 
85256 ---------------------------------------
85257 --
85258 -- PRIVATE FUNCTION
85259 --         AcctLineType_273
85260 --
85261 ---------------------------------------
85262 PROCEDURE AcctLineType_273 (
85263   p_application_id        IN NUMBER
85264  ,p_event_id              IN NUMBER
85265  ,p_calculate_acctd_flag  IN VARCHAR2
85266  ,p_calculate_g_l_flag    IN VARCHAR2
85267  ,p_actual_flag           IN OUT VARCHAR2
85268  ,p_balance_type_code     OUT VARCHAR2
85269  ,p_gain_or_loss_ref      OUT VARCHAR2
85270  
85271 --Period Close Date
85272  , p_source_1            IN DATE
85273 --Generated Code Combination Identifier
85274  , p_source_3            IN NUMBER
85275 --Proceeds Of Sale Clearing Account
85276  , p_source_23            IN VARCHAR2
85277 --Expense Account Code Combination Identifier
85278  , p_source_29            IN NUMBER
85279 --Default Code Combination Identifier
85280  , p_source_30            IN NUMBER
85281 --Adjustment Type
85282  , p_source_35            IN VARCHAR2
85286  , p_source_37            IN NUMBER
85283 --Transaction Header Identifier
85284  , p_source_36            IN NUMBER
85285 --Adjustment Line Identifier
85287 --Distribution Type Code
85288  , p_source_38            IN VARCHAR2
85289 --Entered Amount
85290  , p_source_39            IN NUMBER
85291 --Currency Code
85292  , p_source_40            IN VARCHAR2
85293 )
85294 IS
85295 
85296 l_component_type              VARCHAR2(80);
85297 l_component_code              VARCHAR2(30);
85298 l_component_type_code         VARCHAR2(1);
85299 l_component_appl_id           INTEGER;
85300 l_amb_context_code            VARCHAR2(30);
85301 l_entity_code                 VARCHAR2(30);
85302 l_event_class_code            VARCHAR2(30);
85303 l_ae_header_id                NUMBER;
85304 l_event_type_code             VARCHAR2(30);
85305 l_line_definition_code        VARCHAR2(30);
85306 l_line_definition_owner_code  VARCHAR2(1);
85307 --
85308 -- adr variables
85309 l_segment                     VARCHAR2(30);
85310 l_ccid                        NUMBER;
85311 l_adr_transaction_coa_id      NUMBER;
85312 l_adr_accounting_coa_id       NUMBER;
85313 l_adr_flexfield_segment_code  VARCHAR2(30);
85314 l_adr_flex_value_set_id       NUMBER;
85315 l_adr_value_type_code         VARCHAR2(30);
85316 l_adr_value_combination_id    NUMBER;
85317 l_adr_value_segment_code      VARCHAR2(30);
85318 
85319 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
85320 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
85321 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
85322 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
85323 
85324 -- 4262811 Variables ------------------------------------------------------------------------------------------
85325 l_entered_amt_idx             NUMBER;
85326 l_accted_amt_idx              NUMBER;
85327 l_acc_rev_flag                VARCHAR2(1);
85328 l_accrual_line_num            NUMBER;
85329 l_tmp_amt                     NUMBER;
85330 l_acc_rev_natural_side_code   VARCHAR2(1);
85331 
85332 l_num_entries                 NUMBER;
85333 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
85334 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
85335 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
85336 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
85337 l_recog_line_1                NUMBER;
85338 l_recog_line_2                NUMBER;
85339 
85340 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
85341 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
85342 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
85343 
85344 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
85345 
85346 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
85347 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
85348 
85349 ---------------------------------------------------------------------------------------------------------------
85350 
85351 
85352 --
85353 -- bulk performance
85354 --
85355 l_balance_type_code           VARCHAR2(1);
85356 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
85357 l_log_module                  VARCHAR2(240);
85358 
85359 --
85360 -- Upgrade strategy
85361 --
85362 l_actual_upg_option           VARCHAR2(1);
85363 l_enc_upg_option           VARCHAR2(1);
85364 
85365 --
85366 BEGIN
85367 --
85368 IF g_log_enabled THEN
85369       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_273';
85370 END IF;
85371 --
85372 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
85373 
85374       trace
85375          (p_msg      => 'BEGIN of AcctLineType_273'
85376          ,p_level    => C_LEVEL_PROCEDURE
85377          ,p_module   => l_log_module);
85378 
85379 END IF;
85380 --
85381 l_component_type             := 'AMB_JLT';
85382 l_component_code             := 'FA_PROC_OF_SALE_CLR';
85383 l_component_type_code        := 'S';
85384 l_component_appl_id          :=  140;
85385 l_amb_context_code           := 'DEFAULT';
85386 l_entity_code                := 'TRANSACTIONS';
85387 l_event_class_code           := 'RETIREMENTS';
85388 l_event_type_code            := 'RETIREMENTS';
85389 l_line_definition_owner_code := 'S';
85390 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
85391 --
85392 l_balance_type_code          := 'A';
85393 l_segment                     := NULL;
85394 l_ccid                        := NULL;
85395 l_adr_transaction_coa_id      := NULL;
85396 l_adr_accounting_coa_id       := NULL;
85397 l_adr_flexfield_segment_code  := NULL;
85398 l_adr_flex_value_set_id       := NULL;
85399 l_adr_value_type_code         := NULL;
85400 l_adr_value_combination_id    := NULL;
85401 l_adr_value_segment_code      := NULL;
85402 
85403 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
85404 l_bflow_class_code           := '';    -- 4219869 Business Flow
85405 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
85406 l_budgetary_control_flag     := 'N';
85407 
85408 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
85409 l_bflow_applied_to_amt       := NULL; -- 5132302
85410 l_entered_amt_idx            := NULL;          -- 4262811
85411 l_accted_amt_idx             := NULL;          -- 4262811
85412 l_acc_rev_flag               := NULL;          -- 4262811
85413 l_accrual_line_num           := NULL;          -- 4262811
85414 l_tmp_amt                    := NULL;          -- 4262811
85415 --
85416  
85417 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
85418     l_balance_type_code <> 'B' THEN
85419 IF NVL(p_source_35,'
85423    --
85420 ') =  'PROCEEDS CLR'
85421  THEN 
85422 
85424    XLA_AE_LINES_PKG.SetNewLine;
85425 
85426    p_balance_type_code          := l_balance_type_code;
85427    -- set the flag so later we will know whether the gain loss line needs to be created
85428    
85429    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
85430      p_actual_flag :='A';
85431    END IF;
85432 
85433    --
85434    -- bulk performance
85435    --
85436    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
85437                                       p_header_num   => 0); -- 4262811
85438    --
85439    -- set accounting line options
85440    --
85441    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
85442            p_natural_side_code          => 'D'
85443          , p_gain_or_loss_flag          => 'N'
85444          , p_gl_transfer_mode_code      => 'S'
85445          , p_acct_entry_type_code       => 'A'
85446          , p_switch_side_flag           => 'Y'
85447          , p_merge_duplicate_code       => 'N'
85448          );
85449    --
85450    l_acc_rev_natural_side_code := 'C';  -- 4262811
85451    -- 
85452    --
85453    -- set accounting line type info
85454    --
85455    xla_ae_lines_pkg.SetAcctLineType
85456       (p_component_type             => l_component_type
85457       ,p_event_type_code            => l_event_type_code
85458       ,p_line_definition_owner_code => l_line_definition_owner_code
85459       ,p_line_definition_code       => l_line_definition_code
85460       ,p_accounting_line_code       => l_component_code
85461       ,p_accounting_line_type_code  => l_component_type_code
85462       ,p_accounting_line_appl_id    => l_component_appl_id
85463       ,p_amb_context_code           => l_amb_context_code
85464       ,p_entity_code                => l_entity_code
85465       ,p_event_class_code           => l_event_class_code);
85466    --
85467    -- set accounting class
85468    --
85469    xla_ae_lines_pkg.SetAcctClass(
85470            p_accounting_class_code  => 'ASSET'
85471          , p_ae_header_id           => l_ae_header_id
85472          );
85473 
85474    --
85475    -- set rounding class
85476    --
85477    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
85478                       'ASSET';
85479 
85480    --
85481    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
85482    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
85483    --
85484    -- bulk performance
85485    --
85486    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
85487 
85488    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
85489       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
85490 
85491    -- 4955764
85492    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
85493       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
85494 
85495    -- 4458381 Public Sector Enh
85496    
85497    --
85498    -- set accounting attributes for the line type
85499    --
85500    l_entered_amt_idx := 4;
85501    l_accted_amt_idx  := 6;
85502    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
85503    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
85504    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
85505    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
85506    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
85507    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
85508    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
85509    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
85510    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
85511    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
85512    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
85513    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
85514    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
85515 
85516    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
85517    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
85518 
85519    ---------------------------------------------------------------------------------------------------------------
85520    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
85521    ---------------------------------------------------------------------------------------------------------------
85522    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
85523 
85524    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
85525    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
85526 
85527    IF xla_accounting_cache_pkg.GetValueChar
85528          (p_source_code         => 'LEDGER_CATEGORY_CODE'
85529          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
85530    AND l_bflow_method_code = 'PRIOR_ENTRY'
85531 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
85532    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
85533          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
85534        )
85535    THEN
85536          xla_ae_lines_pkg.BflowUpgEntry
85537            (p_business_method_code    => l_bflow_method_code
85538            ,p_business_class_code     => l_bflow_class_code
85539            ,p_balance_type            => l_balance_type_code);
85540    ELSE
85541       NULL;
85542 -- No business flow processing for business flow method of NONE.
85546    -- call analytical criteria
85543    END IF;
85544 
85545    --
85547    --
85548    
85549    --
85550    -- call description
85551    --
85552    
85553 xla_ae_lines_pkg.SetLineDescription(
85554    p_ae_header_id => l_ae_header_id
85555   ,p_description  => Description_88 (
85556      p_application_id         => p_application_id
85557    , p_ae_header_id           => l_ae_header_id 
85558 , p_source_1 => p_source_1
85559    )
85560 );
85561 
85562 
85563    --
85564    -- call ADRs
85565    -- Bug 4922099
85566    --
85567    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
85568         (NVL(l_actual_upg_option, 'N') = 'O') OR
85569         (NVL(l_enc_upg_option, 'N') = 'O')
85570       )
85571    THEN
85572    NULL;
85573    --
85574    --
85575    
85576   l_ccid := AcctDerRule_173(
85577            p_application_id           => p_application_id
85578          , p_ae_header_id             => l_ae_header_id 
85579 , p_source_3 => p_source_3
85580 , p_source_30 => p_source_30
85581          , x_transaction_coa_id       => l_adr_transaction_coa_id
85582          , x_accounting_coa_id        => l_adr_accounting_coa_id
85583          , x_value_type_code          => l_adr_value_type_code
85584          , p_side                     => 'NA'
85585    );
85586 
85587    xla_ae_lines_pkg.set_ccid(
85588     p_code_combination_id          => l_ccid
85589   , p_value_type_code              => l_adr_value_type_code
85590   , p_transaction_coa_id           => l_adr_transaction_coa_id
85591   , p_accounting_coa_id            => l_adr_accounting_coa_id
85592   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
85593   , p_adr_type_code                => 'S'
85594   , p_component_type               => l_component_type
85595   , p_component_code               => l_component_code
85596   , p_component_type_code          => l_component_type_code
85597   , p_component_appl_id            => l_component_appl_id
85598   , p_amb_context_code             => l_amb_context_code
85599   , p_side                         => 'NA'
85600   );
85601 
85602 
85603    l_segment := AcctDerRule_168(
85604            p_application_id           => p_application_id
85605          , p_ae_header_id             => l_ae_header_id 
85606 , p_source_3 => p_source_3
85607 , p_source_29 => p_source_29
85608          , x_transaction_coa_id       => l_adr_transaction_coa_id
85609          , x_accounting_coa_id        => l_adr_accounting_coa_id
85610          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
85611          , x_flex_value_set_id        => l_adr_flex_value_set_id
85612          , x_value_type_code          => l_adr_value_type_code
85613          , x_value_combination_id     => l_adr_value_combination_id
85614          , x_value_segment_code       => l_adr_value_segment_code
85615          , p_side                     => 'NA'
85616          , p_override_seg_flag        => 'Y'
85617    );
85618 
85619    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
85620 
85621       xla_ae_lines_pkg.set_segment(
85622           p_to_segment_code         => 'GL_BALANCING'
85623         , p_segment_value           => l_segment
85624         , p_from_segment_code       => l_adr_value_segment_code
85625         , p_from_combination_id     => l_adr_value_combination_id
85626         , p_value_type_code         => l_adr_value_type_code
85627         , p_transaction_coa_id      => l_adr_transaction_coa_id
85628         , p_accounting_coa_id       => l_adr_accounting_coa_id
85629         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
85630         , p_flex_value_set_id       => l_adr_flex_value_set_id
85631         , p_adr_code                => 'FA_EXPENSE_ACCT'
85632         , p_adr_type_code           => 'S'
85633         , p_component_type          => l_component_type
85634         , p_component_code          => l_component_code
85635         , p_component_type_code     => l_component_type_code
85636         , p_component_appl_id       => l_component_appl_id
85637         , p_amb_context_code        => l_amb_context_code
85638         , p_entity_code             => 'TRANSACTIONS'
85639         , p_event_class_code        => 'RETIREMENTS'
85640         , p_side                    => 'NA'
85641         );
85642 
85643   END IF;
85644 
85645    l_segment := AcctDerRule_161(
85646            p_application_id           => p_application_id
85647          , p_ae_header_id             => l_ae_header_id 
85648 , p_source_3 => p_source_3
85649 , p_source_23 => p_source_23
85650          , x_transaction_coa_id       => l_adr_transaction_coa_id
85651          , x_accounting_coa_id        => l_adr_accounting_coa_id
85652          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
85653          , x_flex_value_set_id        => l_adr_flex_value_set_id
85654          , x_value_type_code          => l_adr_value_type_code
85655          , x_value_combination_id     => l_adr_value_combination_id
85656          , x_value_segment_code       => l_adr_value_segment_code
85657          , p_side                     => 'NA'
85658          , p_override_seg_flag        => 'Y'
85659    );
85660 
85661    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
85662 
85663       xla_ae_lines_pkg.set_segment(
85664           p_to_segment_code         => 'GL_ACCOUNT'
85665         , p_segment_value           => l_segment
85666         , p_from_segment_code       => l_adr_value_segment_code
85667         , p_from_combination_id     => l_adr_value_combination_id
85668         , p_value_type_code         => l_adr_value_type_code
85669         , p_transaction_coa_id      => l_adr_transaction_coa_id
85670         , p_accounting_coa_id       => l_adr_accounting_coa_id
85671         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
85672         , p_flex_value_set_id       => l_adr_flex_value_set_id
85673         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
85677         , p_component_type_code     => l_component_type_code
85674         , p_adr_type_code           => 'S'
85675         , p_component_type          => l_component_type
85676         , p_component_code          => l_component_code
85678         , p_component_appl_id       => l_component_appl_id
85679         , p_amb_context_code        => l_amb_context_code
85680         , p_entity_code             => 'TRANSACTIONS'
85681         , p_event_class_code        => 'RETIREMENTS'
85682         , p_side                    => 'NA'
85683         );
85684 
85685   END IF;
85686 
85687    --
85688    --
85689    END IF;
85690    --
85691    -- Bug 4922099
85692    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
85693           (NVL(l_enc_upg_option, 'N') = 'O')
85694         ) AND
85695         (l_bflow_method_code = 'PRIOR_ENTRY')
85696       )
85697    THEN
85698       IF
85699       --
85700       1 = 2
85701       --
85702       THEN
85703       xla_accounting_err_pkg.build_message
85704                                     (p_appli_s_name            => 'XLA'
85705                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
85706                                     ,p_token_1                 => 'LINE_NUMBER'
85707                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
85708                                     ,p_token_2                 => 'LINE_TYPE_NAME'
85709                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
85710                                                                              l_component_type
85711                                                                             ,l_component_code
85712                                                                             ,l_component_type_code
85713                                                                             ,l_component_appl_id
85714                                                                             ,l_amb_context_code
85715                                                                             ,l_entity_code
85716                                                                             ,l_event_class_code
85717                                                                            )
85718                                     ,p_token_3                 => 'OWNER'
85719                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
85720                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
85721                                                                           ,p_lookup_code    => l_component_type_code
85722                                                                          )
85723                                     ,p_token_4                 => 'PRODUCT_NAME'
85724                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
85725                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
85726                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
85727                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
85728                                     ,p_ae_header_id            =>  NULL
85729                                        );
85730 
85731         IF (C_LEVEL_ERROR>= g_log_level) THEN
85732                  trace
85733                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
85734                       ,p_level    => C_LEVEL_ERROR
85735                       ,p_module   => l_log_module);
85736         END IF;
85737       END IF;
85738    END IF;
85739    --
85740    --
85741    ------------------------------------------------------------------------------------------------
85742    -- 4219869 Business Flow
85743    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
85744    -- Prior Entry.  Currently, the following code is always generated.
85745    ------------------------------------------------------------------------------------------------
85746    XLA_AE_LINES_PKG.ValidateCurrentLine;
85747 
85748    ------------------------------------------------------------------------------------
85749    -- 4219869 Business Flow
85750    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
85751    ------------------------------------------------------------------------------------
85752    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
85753 
85754    ----------------------------------------------------------------------------------
85755    -- 4219869 Business Flow
85756    -- Update journal entry status -- Need to generate this within IF <condition>
85757    ----------------------------------------------------------------------------------
85758    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
85759          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
85760          ,p_balance_type_code => l_balance_type_code
85761          );
85762 
85763    -------------------------------------------------------------------------------------------
85764    -- 4262811 - Generate the Accrual Reversal lines
85765    -------------------------------------------------------------------------------------------
85766    BEGIN
85767       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
85768                               (g_array_event(p_event_id).array_value_num('header_index'));
85769       IF l_acc_rev_flag IS NULL THEN
85770          l_acc_rev_flag := 'N';
85771       END IF;
85772    EXCEPTION
85773       WHEN OTHERS THEN
85774          l_acc_rev_flag := 'N';
85775    END;
85776    --
85777    IF (l_acc_rev_flag = 'Y') THEN
85778 
85779        -- 4645092  ------------------------------------------------------------------------------
85783 
85780        -- To allow MPA report to determine if it should generate report process
85781        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
85782        ------------------------------------------------------------------------------------------
85784        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
85785        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
85786    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
85787    -- call ADRs
85788    -- Bug 4922099
85789    --
85790    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
85791         (NVL(l_actual_upg_option, 'N') = 'O') OR
85792         (NVL(l_enc_upg_option, 'N') = 'O')
85793       )
85794    THEN
85795    NULL;
85796    --
85797    --
85798    
85799   l_ccid := AcctDerRule_173(
85800            p_application_id           => p_application_id
85801          , p_ae_header_id             => l_ae_header_id 
85802 , p_source_3 => p_source_3
85803 , p_source_30 => p_source_30
85804          , x_transaction_coa_id       => l_adr_transaction_coa_id
85805          , x_accounting_coa_id        => l_adr_accounting_coa_id
85806          , x_value_type_code          => l_adr_value_type_code
85807          , p_side                     => 'NA'
85808    );
85809 
85810    xla_ae_lines_pkg.set_ccid(
85811     p_code_combination_id          => l_ccid
85812   , p_value_type_code              => l_adr_value_type_code
85813   , p_transaction_coa_id           => l_adr_transaction_coa_id
85814   , p_accounting_coa_id            => l_adr_accounting_coa_id
85815   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
85816   , p_adr_type_code                => 'S'
85817   , p_component_type               => l_component_type
85818   , p_component_code               => l_component_code
85819   , p_component_type_code          => l_component_type_code
85820   , p_component_appl_id            => l_component_appl_id
85821   , p_amb_context_code             => l_amb_context_code
85822   , p_side                         => 'NA'
85823   );
85824 
85825 
85826    l_segment := AcctDerRule_168(
85827            p_application_id           => p_application_id
85828          , p_ae_header_id             => l_ae_header_id 
85829 , p_source_3 => p_source_3
85830 , p_source_29 => p_source_29
85831          , x_transaction_coa_id       => l_adr_transaction_coa_id
85832          , x_accounting_coa_id        => l_adr_accounting_coa_id
85833          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
85834          , x_flex_value_set_id        => l_adr_flex_value_set_id
85835          , x_value_type_code          => l_adr_value_type_code
85836          , x_value_combination_id     => l_adr_value_combination_id
85837          , x_value_segment_code       => l_adr_value_segment_code
85838          , p_side                     => 'NA'
85839          , p_override_seg_flag        => 'Y'
85840    );
85841 
85842    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
85843 
85844       xla_ae_lines_pkg.set_segment(
85845           p_to_segment_code         => 'GL_BALANCING'
85846         , p_segment_value           => l_segment
85847         , p_from_segment_code       => l_adr_value_segment_code
85848         , p_from_combination_id     => l_adr_value_combination_id
85849         , p_value_type_code         => l_adr_value_type_code
85850         , p_transaction_coa_id      => l_adr_transaction_coa_id
85851         , p_accounting_coa_id       => l_adr_accounting_coa_id
85852         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
85853         , p_flex_value_set_id       => l_adr_flex_value_set_id
85854         , p_adr_code                => 'FA_EXPENSE_ACCT'
85855         , p_adr_type_code           => 'S'
85856         , p_component_type          => l_component_type
85857         , p_component_code          => l_component_code
85858         , p_component_type_code     => l_component_type_code
85859         , p_component_appl_id       => l_component_appl_id
85860         , p_amb_context_code        => l_amb_context_code
85861         , p_entity_code             => 'TRANSACTIONS'
85862         , p_event_class_code        => 'RETIREMENTS'
85863         , p_side                    => 'NA'
85864         );
85865 
85866   END IF;
85867 
85868    l_segment := AcctDerRule_161(
85869            p_application_id           => p_application_id
85870          , p_ae_header_id             => l_ae_header_id 
85871 , p_source_3 => p_source_3
85872 , p_source_23 => p_source_23
85873          , x_transaction_coa_id       => l_adr_transaction_coa_id
85874          , x_accounting_coa_id        => l_adr_accounting_coa_id
85875          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
85876          , x_flex_value_set_id        => l_adr_flex_value_set_id
85877          , x_value_type_code          => l_adr_value_type_code
85878          , x_value_combination_id     => l_adr_value_combination_id
85879          , x_value_segment_code       => l_adr_value_segment_code
85880          , p_side                     => 'NA'
85881          , p_override_seg_flag        => 'Y'
85882    );
85883 
85884    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
85885 
85886       xla_ae_lines_pkg.set_segment(
85887           p_to_segment_code         => 'GL_ACCOUNT'
85888         , p_segment_value           => l_segment
85889         , p_from_segment_code       => l_adr_value_segment_code
85890         , p_from_combination_id     => l_adr_value_combination_id
85891         , p_value_type_code         => l_adr_value_type_code
85892         , p_transaction_coa_id      => l_adr_transaction_coa_id
85893         , p_accounting_coa_id       => l_adr_accounting_coa_id
85894         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
85895         , p_flex_value_set_id       => l_adr_flex_value_set_id
85896         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
85897         , p_adr_type_code           => 'S'
85898         , p_component_type          => l_component_type
85902         , p_amb_context_code        => l_amb_context_code
85899         , p_component_code          => l_component_code
85900         , p_component_type_code     => l_component_type_code
85901         , p_component_appl_id       => l_component_appl_id
85903         , p_entity_code             => 'TRANSACTIONS'
85904         , p_event_class_code        => 'RETIREMENTS'
85905         , p_side                    => 'NA'
85906         );
85907 
85908   END IF;
85909 
85910    --
85911    --
85912    END IF;
85913 
85914        --
85915        -- Update the line information that should be overwritten
85916        --
85917        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
85918                                          p_header_num   => 1);
85919        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
85920 
85921        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
85922 
85923        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
85924           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
85925        END IF;
85926 
85927       --
85928       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
85929       --
85930       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
85931           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
85932       ELSE
85933           ---------------------------------------------------------------------------------------------------
85934           -- 4262811a Switch Sign
85935           ---------------------------------------------------------------------------------------------------
85936           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
85937           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
85938                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
85939           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
85940                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
85941           -- 5132302
85942           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
85943                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
85944 
85945       END IF;
85946 
85947       -- 4955764
85948       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
85949       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
85950 
85951 
85952       XLA_AE_LINES_PKG.ValidateCurrentLine;
85953       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
85954 
85955       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
85956                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
85957                ,p_balance_type_code => l_balance_type_code);
85958 
85959    END IF;
85960 
85961    -----------------------------------------------------------------------------------------
85962    -- 4262811 Multiperiod Accounting
85963    -----------------------------------------------------------------------------------------
85964      -- No MPA option is assigned.
85965 
85966 
85967 END IF;
85968 END IF;
85969 --
85970 
85971 --
85972 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
85973    trace
85974       (p_msg      => 'END of AcctLineType_273'
85975       ,p_level    => C_LEVEL_PROCEDURE
85976       ,p_module   => l_log_module);
85977 END IF;
85978 --
85979 EXCEPTION
85980   WHEN xla_exceptions_pkg.application_exception THEN
85981       RAISE;
85982   WHEN OTHERS THEN
85983        xla_exceptions_pkg.raise_message
85984            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_273');
85985 END AcctLineType_273;
85986 --
85987 
85988 ---------------------------------------
85989 --
85990 -- PRIVATE FUNCTION
85991 --         AcctLineType_274
85992 --
85993 ---------------------------------------
85994 PROCEDURE AcctLineType_274 (
85995   p_application_id        IN NUMBER
85996  ,p_event_id              IN NUMBER
85997  ,p_calculate_acctd_flag  IN VARCHAR2
85998  ,p_calculate_g_l_flag    IN VARCHAR2
85999  ,p_actual_flag           IN OUT VARCHAR2
86000  ,p_balance_type_code     OUT VARCHAR2
86001  ,p_gain_or_loss_ref      OUT VARCHAR2
86002  
86003 --Period Close Date
86004  , p_source_1            IN DATE
86005 --Generated Code Combination Identifier
86006  , p_source_3            IN NUMBER
86007 --Proceeds Of Sale Clearing Account
86008  , p_source_23            IN VARCHAR2
86009 --Expense Account Code Combination Identifier
86010  , p_source_29            IN NUMBER
86011 --Default Code Combination Identifier
86012  , p_source_30            IN NUMBER
86013 --Adjustment Type
86014  , p_source_35            IN VARCHAR2
86015 --Transaction Header Identifier
86016  , p_source_36            IN NUMBER
86017 --Adjustment Line Identifier
86018  , p_source_37            IN NUMBER
86019 --Distribution Type Code
86020  , p_source_38            IN VARCHAR2
86021 --Entered Amount
86022  , p_source_39            IN NUMBER
86023 --Currency Code
86024  , p_source_40            IN VARCHAR2
86025 )
86026 IS
86027 
86028 l_component_type              VARCHAR2(80);
86029 l_component_code              VARCHAR2(30);
86030 l_component_type_code         VARCHAR2(1);
86031 l_component_appl_id           INTEGER;
86032 l_amb_context_code            VARCHAR2(30);
86033 l_entity_code                 VARCHAR2(30);
86037 l_line_definition_code        VARCHAR2(30);
86034 l_event_class_code            VARCHAR2(30);
86035 l_ae_header_id                NUMBER;
86036 l_event_type_code             VARCHAR2(30);
86038 l_line_definition_owner_code  VARCHAR2(1);
86039 --
86040 -- adr variables
86041 l_segment                     VARCHAR2(30);
86042 l_ccid                        NUMBER;
86043 l_adr_transaction_coa_id      NUMBER;
86044 l_adr_accounting_coa_id       NUMBER;
86045 l_adr_flexfield_segment_code  VARCHAR2(30);
86046 l_adr_flex_value_set_id       NUMBER;
86047 l_adr_value_type_code         VARCHAR2(30);
86048 l_adr_value_combination_id    NUMBER;
86049 l_adr_value_segment_code      VARCHAR2(30);
86050 
86051 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
86052 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
86053 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
86054 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
86055 
86056 -- 4262811 Variables ------------------------------------------------------------------------------------------
86057 l_entered_amt_idx             NUMBER;
86058 l_accted_amt_idx              NUMBER;
86059 l_acc_rev_flag                VARCHAR2(1);
86060 l_accrual_line_num            NUMBER;
86061 l_tmp_amt                     NUMBER;
86062 l_acc_rev_natural_side_code   VARCHAR2(1);
86063 
86064 l_num_entries                 NUMBER;
86065 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
86066 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
86067 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
86068 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
86069 l_recog_line_1                NUMBER;
86070 l_recog_line_2                NUMBER;
86071 
86072 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
86073 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
86074 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
86075 
86076 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
86077 
86078 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
86079 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
86080 
86081 ---------------------------------------------------------------------------------------------------------------
86082 
86083 
86084 --
86085 -- bulk performance
86086 --
86087 l_balance_type_code           VARCHAR2(1);
86088 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
86089 l_log_module                  VARCHAR2(240);
86090 
86091 --
86092 -- Upgrade strategy
86093 --
86094 l_actual_upg_option           VARCHAR2(1);
86095 l_enc_upg_option           VARCHAR2(1);
86096 
86097 --
86098 BEGIN
86099 --
86100 IF g_log_enabled THEN
86101       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_274';
86102 END IF;
86103 --
86104 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
86105 
86106       trace
86107          (p_msg      => 'BEGIN of AcctLineType_274'
86108          ,p_level    => C_LEVEL_PROCEDURE
86109          ,p_module   => l_log_module);
86110 
86111 END IF;
86112 --
86113 l_component_type             := 'AMB_JLT';
86114 l_component_code             := 'FA_PROC_OF_SALE_CLR';
86115 l_component_type_code        := 'S';
86116 l_component_appl_id          :=  140;
86117 l_amb_context_code           := 'DEFAULT';
86118 l_entity_code                := 'TRANSACTIONS';
86119 l_event_class_code           := 'RETIREMENTS';
86120 l_event_type_code            := 'REINSTATEMENTS';
86121 l_line_definition_owner_code := 'S';
86122 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
86123 --
86124 l_balance_type_code          := 'A';
86125 l_segment                     := NULL;
86126 l_ccid                        := NULL;
86127 l_adr_transaction_coa_id      := NULL;
86128 l_adr_accounting_coa_id       := NULL;
86129 l_adr_flexfield_segment_code  := NULL;
86130 l_adr_flex_value_set_id       := NULL;
86131 l_adr_value_type_code         := NULL;
86132 l_adr_value_combination_id    := NULL;
86133 l_adr_value_segment_code      := NULL;
86134 
86135 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
86136 l_bflow_class_code           := '';    -- 4219869 Business Flow
86137 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
86138 l_budgetary_control_flag     := 'N';
86139 
86140 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
86141 l_bflow_applied_to_amt       := NULL; -- 5132302
86142 l_entered_amt_idx            := NULL;          -- 4262811
86143 l_accted_amt_idx             := NULL;          -- 4262811
86144 l_acc_rev_flag               := NULL;          -- 4262811
86145 l_accrual_line_num           := NULL;          -- 4262811
86146 l_tmp_amt                    := NULL;          -- 4262811
86147 --
86148  
86149 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
86150     l_balance_type_code <> 'B' THEN
86151 IF NVL(p_source_35,'
86152 ') =  'PROCEEDS CLR'
86153  THEN 
86154 
86155    --
86156    XLA_AE_LINES_PKG.SetNewLine;
86157 
86158    p_balance_type_code          := l_balance_type_code;
86159    -- set the flag so later we will know whether the gain loss line needs to be created
86160    
86161    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
86162      p_actual_flag :='A';
86163    END IF;
86164 
86165    --
86166    -- bulk performance
86167    --
86168    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
86169                                       p_header_num   => 0); -- 4262811
86170    --
86171    -- set accounting line options
86172    --
86176          , p_gl_transfer_mode_code      => 'S'
86173    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
86174            p_natural_side_code          => 'D'
86175          , p_gain_or_loss_flag          => 'N'
86177          , p_acct_entry_type_code       => 'A'
86178          , p_switch_side_flag           => 'Y'
86179          , p_merge_duplicate_code       => 'N'
86180          );
86181    --
86182    l_acc_rev_natural_side_code := 'C';  -- 4262811
86183    -- 
86184    --
86185    -- set accounting line type info
86186    --
86187    xla_ae_lines_pkg.SetAcctLineType
86188       (p_component_type             => l_component_type
86189       ,p_event_type_code            => l_event_type_code
86190       ,p_line_definition_owner_code => l_line_definition_owner_code
86191       ,p_line_definition_code       => l_line_definition_code
86192       ,p_accounting_line_code       => l_component_code
86193       ,p_accounting_line_type_code  => l_component_type_code
86194       ,p_accounting_line_appl_id    => l_component_appl_id
86195       ,p_amb_context_code           => l_amb_context_code
86196       ,p_entity_code                => l_entity_code
86197       ,p_event_class_code           => l_event_class_code);
86198    --
86199    -- set accounting class
86200    --
86201    xla_ae_lines_pkg.SetAcctClass(
86202            p_accounting_class_code  => 'ASSET'
86203          , p_ae_header_id           => l_ae_header_id
86204          );
86205 
86206    --
86207    -- set rounding class
86208    --
86209    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
86210                       'ASSET';
86211 
86212    --
86213    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
86214    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
86215    --
86216    -- bulk performance
86217    --
86218    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
86219 
86220    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
86221       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
86222 
86223    -- 4955764
86224    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
86225       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
86226 
86227    -- 4458381 Public Sector Enh
86228    
86229    --
86230    -- set accounting attributes for the line type
86231    --
86232    l_entered_amt_idx := 4;
86233    l_accted_amt_idx  := 6;
86234    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
86235    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
86236    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
86237    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
86238    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
86239    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
86240    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
86241    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
86242    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
86243    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
86244    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
86245    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
86246    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
86247 
86248    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
86249    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
86250 
86251    ---------------------------------------------------------------------------------------------------------------
86252    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
86253    ---------------------------------------------------------------------------------------------------------------
86254    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
86255 
86256    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
86257    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
86258 
86259    IF xla_accounting_cache_pkg.GetValueChar
86260          (p_source_code         => 'LEDGER_CATEGORY_CODE'
86261          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
86262    AND l_bflow_method_code = 'PRIOR_ENTRY'
86263 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
86264    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
86265          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
86266        )
86267    THEN
86268          xla_ae_lines_pkg.BflowUpgEntry
86269            (p_business_method_code    => l_bflow_method_code
86270            ,p_business_class_code     => l_bflow_class_code
86271            ,p_balance_type            => l_balance_type_code);
86272    ELSE
86273       NULL;
86274 -- No business flow processing for business flow method of NONE.
86275    END IF;
86276 
86277    --
86278    -- call analytical criteria
86279    --
86280    
86281    --
86282    -- call description
86283    --
86284    
86285 xla_ae_lines_pkg.SetLineDescription(
86286    p_ae_header_id => l_ae_header_id
86287   ,p_description  => Description_88 (
86288      p_application_id         => p_application_id
86289    , p_ae_header_id           => l_ae_header_id 
86290 , p_source_1 => p_source_1
86291    )
86292 );
86293 
86294 
86295    --
86296    -- call ADRs
86297    -- Bug 4922099
86298    --
86299    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
86303    THEN
86300         (NVL(l_actual_upg_option, 'N') = 'O') OR
86301         (NVL(l_enc_upg_option, 'N') = 'O')
86302       )
86304    NULL;
86305    --
86306    --
86307    
86308   l_ccid := AcctDerRule_173(
86309            p_application_id           => p_application_id
86310          , p_ae_header_id             => l_ae_header_id 
86311 , p_source_3 => p_source_3
86312 , p_source_30 => p_source_30
86313          , x_transaction_coa_id       => l_adr_transaction_coa_id
86314          , x_accounting_coa_id        => l_adr_accounting_coa_id
86315          , x_value_type_code          => l_adr_value_type_code
86316          , p_side                     => 'NA'
86317    );
86318 
86319    xla_ae_lines_pkg.set_ccid(
86320     p_code_combination_id          => l_ccid
86321   , p_value_type_code              => l_adr_value_type_code
86322   , p_transaction_coa_id           => l_adr_transaction_coa_id
86323   , p_accounting_coa_id            => l_adr_accounting_coa_id
86324   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
86325   , p_adr_type_code                => 'S'
86326   , p_component_type               => l_component_type
86327   , p_component_code               => l_component_code
86328   , p_component_type_code          => l_component_type_code
86329   , p_component_appl_id            => l_component_appl_id
86330   , p_amb_context_code             => l_amb_context_code
86331   , p_side                         => 'NA'
86332   );
86333 
86334 
86335    l_segment := AcctDerRule_168(
86336            p_application_id           => p_application_id
86337          , p_ae_header_id             => l_ae_header_id 
86338 , p_source_3 => p_source_3
86339 , p_source_29 => p_source_29
86340          , x_transaction_coa_id       => l_adr_transaction_coa_id
86341          , x_accounting_coa_id        => l_adr_accounting_coa_id
86342          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
86343          , x_flex_value_set_id        => l_adr_flex_value_set_id
86344          , x_value_type_code          => l_adr_value_type_code
86345          , x_value_combination_id     => l_adr_value_combination_id
86346          , x_value_segment_code       => l_adr_value_segment_code
86347          , p_side                     => 'NA'
86348          , p_override_seg_flag        => 'Y'
86349    );
86350 
86351    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
86352 
86353       xla_ae_lines_pkg.set_segment(
86354           p_to_segment_code         => 'GL_BALANCING'
86355         , p_segment_value           => l_segment
86356         , p_from_segment_code       => l_adr_value_segment_code
86357         , p_from_combination_id     => l_adr_value_combination_id
86358         , p_value_type_code         => l_adr_value_type_code
86359         , p_transaction_coa_id      => l_adr_transaction_coa_id
86360         , p_accounting_coa_id       => l_adr_accounting_coa_id
86361         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
86362         , p_flex_value_set_id       => l_adr_flex_value_set_id
86363         , p_adr_code                => 'FA_EXPENSE_ACCT'
86364         , p_adr_type_code           => 'S'
86365         , p_component_type          => l_component_type
86366         , p_component_code          => l_component_code
86367         , p_component_type_code     => l_component_type_code
86368         , p_component_appl_id       => l_component_appl_id
86369         , p_amb_context_code        => l_amb_context_code
86370         , p_entity_code             => 'TRANSACTIONS'
86371         , p_event_class_code        => 'RETIREMENTS'
86372         , p_side                    => 'NA'
86373         );
86374 
86375   END IF;
86376 
86377    l_segment := AcctDerRule_161(
86378            p_application_id           => p_application_id
86379          , p_ae_header_id             => l_ae_header_id 
86380 , p_source_3 => p_source_3
86381 , p_source_23 => p_source_23
86382          , x_transaction_coa_id       => l_adr_transaction_coa_id
86383          , x_accounting_coa_id        => l_adr_accounting_coa_id
86384          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
86385          , x_flex_value_set_id        => l_adr_flex_value_set_id
86386          , x_value_type_code          => l_adr_value_type_code
86387          , x_value_combination_id     => l_adr_value_combination_id
86388          , x_value_segment_code       => l_adr_value_segment_code
86389          , p_side                     => 'NA'
86390          , p_override_seg_flag        => 'Y'
86391    );
86392 
86393    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
86394 
86395       xla_ae_lines_pkg.set_segment(
86396           p_to_segment_code         => 'GL_ACCOUNT'
86397         , p_segment_value           => l_segment
86398         , p_from_segment_code       => l_adr_value_segment_code
86399         , p_from_combination_id     => l_adr_value_combination_id
86400         , p_value_type_code         => l_adr_value_type_code
86401         , p_transaction_coa_id      => l_adr_transaction_coa_id
86402         , p_accounting_coa_id       => l_adr_accounting_coa_id
86403         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
86404         , p_flex_value_set_id       => l_adr_flex_value_set_id
86405         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
86406         , p_adr_type_code           => 'S'
86407         , p_component_type          => l_component_type
86408         , p_component_code          => l_component_code
86409         , p_component_type_code     => l_component_type_code
86410         , p_component_appl_id       => l_component_appl_id
86411         , p_amb_context_code        => l_amb_context_code
86412         , p_entity_code             => 'TRANSACTIONS'
86413         , p_event_class_code        => 'RETIREMENTS'
86414         , p_side                    => 'NA'
86415         );
86416 
86417   END IF;
86418 
86419    --
86420    --
86421    END IF;
86422    --
86423    -- Bug 4922099
86427         (l_bflow_method_code = 'PRIOR_ENTRY')
86424    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
86425           (NVL(l_enc_upg_option, 'N') = 'O')
86426         ) AND
86428       )
86429    THEN
86430       IF
86431       --
86432       1 = 2
86433       --
86434       THEN
86435       xla_accounting_err_pkg.build_message
86436                                     (p_appli_s_name            => 'XLA'
86437                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
86438                                     ,p_token_1                 => 'LINE_NUMBER'
86439                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
86440                                     ,p_token_2                 => 'LINE_TYPE_NAME'
86441                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
86442                                                                              l_component_type
86443                                                                             ,l_component_code
86444                                                                             ,l_component_type_code
86445                                                                             ,l_component_appl_id
86446                                                                             ,l_amb_context_code
86447                                                                             ,l_entity_code
86448                                                                             ,l_event_class_code
86449                                                                            )
86450                                     ,p_token_3                 => 'OWNER'
86451                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
86452                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
86453                                                                           ,p_lookup_code    => l_component_type_code
86454                                                                          )
86455                                     ,p_token_4                 => 'PRODUCT_NAME'
86456                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
86457                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
86458                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
86459                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
86460                                     ,p_ae_header_id            =>  NULL
86461                                        );
86462 
86463         IF (C_LEVEL_ERROR>= g_log_level) THEN
86464                  trace
86465                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
86466                       ,p_level    => C_LEVEL_ERROR
86467                       ,p_module   => l_log_module);
86468         END IF;
86469       END IF;
86470    END IF;
86471    --
86472    --
86473    ------------------------------------------------------------------------------------------------
86474    -- 4219869 Business Flow
86475    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
86476    -- Prior Entry.  Currently, the following code is always generated.
86477    ------------------------------------------------------------------------------------------------
86478    XLA_AE_LINES_PKG.ValidateCurrentLine;
86479 
86480    ------------------------------------------------------------------------------------
86481    -- 4219869 Business Flow
86482    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
86483    ------------------------------------------------------------------------------------
86484    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
86485 
86486    ----------------------------------------------------------------------------------
86487    -- 4219869 Business Flow
86488    -- Update journal entry status -- Need to generate this within IF <condition>
86489    ----------------------------------------------------------------------------------
86490    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
86491          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
86492          ,p_balance_type_code => l_balance_type_code
86493          );
86494 
86495    -------------------------------------------------------------------------------------------
86496    -- 4262811 - Generate the Accrual Reversal lines
86497    -------------------------------------------------------------------------------------------
86498    BEGIN
86499       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
86500                               (g_array_event(p_event_id).array_value_num('header_index'));
86501       IF l_acc_rev_flag IS NULL THEN
86502          l_acc_rev_flag := 'N';
86503       END IF;
86504    EXCEPTION
86505       WHEN OTHERS THEN
86506          l_acc_rev_flag := 'N';
86507    END;
86508    --
86509    IF (l_acc_rev_flag = 'Y') THEN
86510 
86511        -- 4645092  ------------------------------------------------------------------------------
86512        -- To allow MPA report to determine if it should generate report process
86513        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
86514        ------------------------------------------------------------------------------------------
86515 
86516        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
86517        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
86518    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
86519    -- call ADRs
86520    -- Bug 4922099
86521    --
86522    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
86523         (NVL(l_actual_upg_option, 'N') = 'O') OR
86524         (NVL(l_enc_upg_option, 'N') = 'O')
86525       )
86526    THEN
86530    
86527    NULL;
86528    --
86529    --
86531   l_ccid := AcctDerRule_173(
86532            p_application_id           => p_application_id
86533          , p_ae_header_id             => l_ae_header_id 
86534 , p_source_3 => p_source_3
86535 , p_source_30 => p_source_30
86536          , x_transaction_coa_id       => l_adr_transaction_coa_id
86537          , x_accounting_coa_id        => l_adr_accounting_coa_id
86538          , x_value_type_code          => l_adr_value_type_code
86539          , p_side                     => 'NA'
86540    );
86541 
86542    xla_ae_lines_pkg.set_ccid(
86543     p_code_combination_id          => l_ccid
86544   , p_value_type_code              => l_adr_value_type_code
86545   , p_transaction_coa_id           => l_adr_transaction_coa_id
86546   , p_accounting_coa_id            => l_adr_accounting_coa_id
86547   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
86548   , p_adr_type_code                => 'S'
86549   , p_component_type               => l_component_type
86550   , p_component_code               => l_component_code
86551   , p_component_type_code          => l_component_type_code
86552   , p_component_appl_id            => l_component_appl_id
86553   , p_amb_context_code             => l_amb_context_code
86554   , p_side                         => 'NA'
86555   );
86556 
86557 
86558    l_segment := AcctDerRule_168(
86559            p_application_id           => p_application_id
86560          , p_ae_header_id             => l_ae_header_id 
86561 , p_source_3 => p_source_3
86562 , p_source_29 => p_source_29
86563          , x_transaction_coa_id       => l_adr_transaction_coa_id
86564          , x_accounting_coa_id        => l_adr_accounting_coa_id
86565          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
86566          , x_flex_value_set_id        => l_adr_flex_value_set_id
86567          , x_value_type_code          => l_adr_value_type_code
86568          , x_value_combination_id     => l_adr_value_combination_id
86569          , x_value_segment_code       => l_adr_value_segment_code
86570          , p_side                     => 'NA'
86571          , p_override_seg_flag        => 'Y'
86572    );
86573 
86574    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
86575 
86576       xla_ae_lines_pkg.set_segment(
86577           p_to_segment_code         => 'GL_BALANCING'
86578         , p_segment_value           => l_segment
86579         , p_from_segment_code       => l_adr_value_segment_code
86580         , p_from_combination_id     => l_adr_value_combination_id
86581         , p_value_type_code         => l_adr_value_type_code
86582         , p_transaction_coa_id      => l_adr_transaction_coa_id
86583         , p_accounting_coa_id       => l_adr_accounting_coa_id
86584         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
86585         , p_flex_value_set_id       => l_adr_flex_value_set_id
86586         , p_adr_code                => 'FA_EXPENSE_ACCT'
86587         , p_adr_type_code           => 'S'
86588         , p_component_type          => l_component_type
86589         , p_component_code          => l_component_code
86590         , p_component_type_code     => l_component_type_code
86591         , p_component_appl_id       => l_component_appl_id
86592         , p_amb_context_code        => l_amb_context_code
86593         , p_entity_code             => 'TRANSACTIONS'
86594         , p_event_class_code        => 'RETIREMENTS'
86595         , p_side                    => 'NA'
86596         );
86597 
86598   END IF;
86599 
86600    l_segment := AcctDerRule_161(
86601            p_application_id           => p_application_id
86602          , p_ae_header_id             => l_ae_header_id 
86603 , p_source_3 => p_source_3
86604 , p_source_23 => p_source_23
86605          , x_transaction_coa_id       => l_adr_transaction_coa_id
86606          , x_accounting_coa_id        => l_adr_accounting_coa_id
86607          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
86608          , x_flex_value_set_id        => l_adr_flex_value_set_id
86609          , x_value_type_code          => l_adr_value_type_code
86610          , x_value_combination_id     => l_adr_value_combination_id
86611          , x_value_segment_code       => l_adr_value_segment_code
86612          , p_side                     => 'NA'
86613          , p_override_seg_flag        => 'Y'
86614    );
86615 
86616    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
86617 
86618       xla_ae_lines_pkg.set_segment(
86619           p_to_segment_code         => 'GL_ACCOUNT'
86620         , p_segment_value           => l_segment
86621         , p_from_segment_code       => l_adr_value_segment_code
86622         , p_from_combination_id     => l_adr_value_combination_id
86623         , p_value_type_code         => l_adr_value_type_code
86624         , p_transaction_coa_id      => l_adr_transaction_coa_id
86625         , p_accounting_coa_id       => l_adr_accounting_coa_id
86626         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
86627         , p_flex_value_set_id       => l_adr_flex_value_set_id
86628         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
86629         , p_adr_type_code           => 'S'
86630         , p_component_type          => l_component_type
86631         , p_component_code          => l_component_code
86632         , p_component_type_code     => l_component_type_code
86633         , p_component_appl_id       => l_component_appl_id
86634         , p_amb_context_code        => l_amb_context_code
86635         , p_entity_code             => 'TRANSACTIONS'
86636         , p_event_class_code        => 'RETIREMENTS'
86637         , p_side                    => 'NA'
86638         );
86639 
86640   END IF;
86641 
86642    --
86643    --
86644    END IF;
86645 
86646        --
86647        -- Update the line information that should be overwritten
86648        --
86652 
86649        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
86650                                          p_header_num   => 1);
86651        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
86653        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
86654 
86655        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
86656           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
86657        END IF;
86658 
86659       --
86660       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
86661       --
86662       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
86663           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
86664       ELSE
86665           ---------------------------------------------------------------------------------------------------
86666           -- 4262811a Switch Sign
86667           ---------------------------------------------------------------------------------------------------
86668           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
86669           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
86670                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
86671           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
86672                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
86673           -- 5132302
86674           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
86675                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
86676 
86677       END IF;
86678 
86679       -- 4955764
86680       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
86681       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
86682 
86683 
86684       XLA_AE_LINES_PKG.ValidateCurrentLine;
86685       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
86686 
86687       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
86688                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
86689                ,p_balance_type_code => l_balance_type_code);
86690 
86691    END IF;
86692 
86693    -----------------------------------------------------------------------------------------
86694    -- 4262811 Multiperiod Accounting
86695    -----------------------------------------------------------------------------------------
86696      -- No MPA option is assigned.
86697 
86698 
86699 END IF;
86700 END IF;
86701 --
86702 
86703 --
86704 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
86705    trace
86706       (p_msg      => 'END of AcctLineType_274'
86707       ,p_level    => C_LEVEL_PROCEDURE
86708       ,p_module   => l_log_module);
86709 END IF;
86710 --
86711 EXCEPTION
86712   WHEN xla_exceptions_pkg.application_exception THEN
86713       RAISE;
86714   WHEN OTHERS THEN
86715        xla_exceptions_pkg.raise_message
86716            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_274');
86717 END AcctLineType_274;
86718 --
86719 
86720 ---------------------------------------
86721 --
86722 -- PRIVATE FUNCTION
86723 --         AcctLineType_275
86724 --
86725 ---------------------------------------
86726 PROCEDURE AcctLineType_275 (
86727   p_application_id        IN NUMBER
86728  ,p_event_id              IN NUMBER
86729  ,p_calculate_acctd_flag  IN VARCHAR2
86730  ,p_calculate_g_l_flag    IN VARCHAR2
86731  ,p_actual_flag           IN OUT VARCHAR2
86732  ,p_balance_type_code     OUT VARCHAR2
86733  ,p_gain_or_loss_ref      OUT VARCHAR2
86734  
86735 --Period Close Date
86736  , p_source_1            IN DATE
86737 --Generated Code Combination Identifier
86738  , p_source_3            IN NUMBER
86739 --Proceeds Of Sale Gain Account
86740  , p_source_24            IN VARCHAR2
86741 --Expense Account Code Combination Identifier
86742  , p_source_29            IN NUMBER
86743 --Default Code Combination Identifier
86744  , p_source_30            IN NUMBER
86745 --Adjustment Type
86746  , p_source_35            IN VARCHAR2
86747 --Transaction Header Identifier
86748  , p_source_36            IN NUMBER
86749 --Adjustment Line Identifier
86750  , p_source_37            IN NUMBER
86751 --Distribution Type Code
86752  , p_source_38            IN VARCHAR2
86753 --Entered Amount
86754  , p_source_39            IN NUMBER
86755 --Currency Code
86756  , p_source_40            IN VARCHAR2
86757 --Gain Loss Amount
86758  , p_source_41            IN NUMBER
86759 )
86760 IS
86761 
86762 l_component_type              VARCHAR2(80);
86763 l_component_code              VARCHAR2(30);
86764 l_component_type_code         VARCHAR2(1);
86765 l_component_appl_id           INTEGER;
86766 l_amb_context_code            VARCHAR2(30);
86767 l_entity_code                 VARCHAR2(30);
86768 l_event_class_code            VARCHAR2(30);
86769 l_ae_header_id                NUMBER;
86770 l_event_type_code             VARCHAR2(30);
86771 l_line_definition_code        VARCHAR2(30);
86772 l_line_definition_owner_code  VARCHAR2(1);
86773 --
86774 -- adr variables
86775 l_segment                     VARCHAR2(30);
86776 l_ccid                        NUMBER;
86777 l_adr_transaction_coa_id      NUMBER;
86778 l_adr_accounting_coa_id       NUMBER;
86779 l_adr_flexfield_segment_code  VARCHAR2(30);
86780 l_adr_flex_value_set_id       NUMBER;
86781 l_adr_value_type_code         VARCHAR2(30);
86785 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
86782 l_adr_value_combination_id    NUMBER;
86783 l_adr_value_segment_code      VARCHAR2(30);
86784 
86786 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
86787 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
86788 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
86789 
86790 -- 4262811 Variables ------------------------------------------------------------------------------------------
86791 l_entered_amt_idx             NUMBER;
86792 l_accted_amt_idx              NUMBER;
86793 l_acc_rev_flag                VARCHAR2(1);
86794 l_accrual_line_num            NUMBER;
86795 l_tmp_amt                     NUMBER;
86796 l_acc_rev_natural_side_code   VARCHAR2(1);
86797 
86798 l_num_entries                 NUMBER;
86799 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
86800 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
86801 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
86802 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
86803 l_recog_line_1                NUMBER;
86804 l_recog_line_2                NUMBER;
86805 
86806 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
86807 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
86808 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
86809 
86810 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
86811 
86812 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
86813 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
86814 
86815 ---------------------------------------------------------------------------------------------------------------
86816 
86817 
86818 --
86819 -- bulk performance
86820 --
86821 l_balance_type_code           VARCHAR2(1);
86822 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
86823 l_log_module                  VARCHAR2(240);
86824 
86825 --
86826 -- Upgrade strategy
86827 --
86828 l_actual_upg_option           VARCHAR2(1);
86829 l_enc_upg_option           VARCHAR2(1);
86830 
86831 --
86832 BEGIN
86833 --
86834 IF g_log_enabled THEN
86835       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_275';
86836 END IF;
86837 --
86838 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
86839 
86840       trace
86841          (p_msg      => 'BEGIN of AcctLineType_275'
86842          ,p_level    => C_LEVEL_PROCEDURE
86843          ,p_module   => l_log_module);
86844 
86845 END IF;
86846 --
86847 l_component_type             := 'AMB_JLT';
86848 l_component_code             := 'FA_PROC_OF_SALE_GAIN';
86849 l_component_type_code        := 'S';
86850 l_component_appl_id          :=  140;
86851 l_amb_context_code           := 'DEFAULT';
86852 l_entity_code                := 'TRANSACTIONS';
86853 l_event_class_code           := 'RETIREMENTS';
86854 l_event_type_code            := 'RETIREMENTS';
86855 l_line_definition_owner_code := 'S';
86856 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
86857 --
86858 l_balance_type_code          := 'A';
86859 l_segment                     := NULL;
86860 l_ccid                        := NULL;
86861 l_adr_transaction_coa_id      := NULL;
86862 l_adr_accounting_coa_id       := NULL;
86863 l_adr_flexfield_segment_code  := NULL;
86864 l_adr_flex_value_set_id       := NULL;
86865 l_adr_value_type_code         := NULL;
86866 l_adr_value_combination_id    := NULL;
86867 l_adr_value_segment_code      := NULL;
86868 
86869 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
86870 l_bflow_class_code           := '';    -- 4219869 Business Flow
86871 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
86872 l_budgetary_control_flag     := 'N';
86873 
86874 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
86875 l_bflow_applied_to_amt       := NULL; -- 5132302
86876 l_entered_amt_idx            := NULL;          -- 4262811
86877 l_accted_amt_idx             := NULL;          -- 4262811
86878 l_acc_rev_flag               := NULL;          -- 4262811
86879 l_accrual_line_num           := NULL;          -- 4262811
86880 l_tmp_amt                    := NULL;          -- 4262811
86881 --
86882  
86883 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
86884     l_balance_type_code <> 'B' THEN
86885 IF NVL(p_source_35,'
86886 ') =  'PROCEEDS' AND 
86887 p_source_41 >=  0
86888  THEN 
86889 
86890    --
86891    XLA_AE_LINES_PKG.SetNewLine;
86892 
86893    p_balance_type_code          := l_balance_type_code;
86894    -- set the flag so later we will know whether the gain loss line needs to be created
86895    
86896    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
86897      p_actual_flag :='A';
86898    END IF;
86899 
86900    --
86901    -- bulk performance
86902    --
86903    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
86904                                       p_header_num   => 0); -- 4262811
86905    --
86906    -- set accounting line options
86907    --
86908    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
86909            p_natural_side_code          => 'C'
86910          , p_gain_or_loss_flag          => 'N'
86911          , p_gl_transfer_mode_code      => 'S'
86912          , p_acct_entry_type_code       => 'A'
86913          , p_switch_side_flag           => 'Y'
86914          , p_merge_duplicate_code       => 'N'
86915          );
86916    --
86917    l_acc_rev_natural_side_code := 'D';  -- 4262811
86918    -- 
86919    --
86920    -- set accounting line type info
86921    --
86925       ,p_line_definition_owner_code => l_line_definition_owner_code
86922    xla_ae_lines_pkg.SetAcctLineType
86923       (p_component_type             => l_component_type
86924       ,p_event_type_code            => l_event_type_code
86926       ,p_line_definition_code       => l_line_definition_code
86927       ,p_accounting_line_code       => l_component_code
86928       ,p_accounting_line_type_code  => l_component_type_code
86929       ,p_accounting_line_appl_id    => l_component_appl_id
86930       ,p_amb_context_code           => l_amb_context_code
86931       ,p_entity_code                => l_entity_code
86932       ,p_event_class_code           => l_event_class_code);
86933    --
86934    -- set accounting class
86935    --
86936    xla_ae_lines_pkg.SetAcctClass(
86937            p_accounting_class_code  => 'ASSET'
86938          , p_ae_header_id           => l_ae_header_id
86939          );
86940 
86941    --
86942    -- set rounding class
86943    --
86944    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
86945                       'ASSET';
86946 
86947    --
86948    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
86949    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
86950    --
86951    -- bulk performance
86952    --
86953    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
86954 
86955    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
86956       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
86957 
86958    -- 4955764
86959    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
86960       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
86961 
86962    -- 4458381 Public Sector Enh
86963    
86964    --
86965    -- set accounting attributes for the line type
86966    --
86967    l_entered_amt_idx := 4;
86968    l_accted_amt_idx  := 6;
86969    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
86970    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
86971    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
86972    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
86973    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
86974    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
86975    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
86976    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
86977    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
86978    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
86979    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
86980    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
86981    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
86982 
86983    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
86984    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
86985 
86986    ---------------------------------------------------------------------------------------------------------------
86987    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
86988    ---------------------------------------------------------------------------------------------------------------
86989    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
86990 
86991    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
86992    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
86993 
86994    IF xla_accounting_cache_pkg.GetValueChar
86995          (p_source_code         => 'LEDGER_CATEGORY_CODE'
86996          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
86997    AND l_bflow_method_code = 'PRIOR_ENTRY'
86998 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
86999    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
87000          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
87001        )
87002    THEN
87003          xla_ae_lines_pkg.BflowUpgEntry
87004            (p_business_method_code    => l_bflow_method_code
87005            ,p_business_class_code     => l_bflow_class_code
87006            ,p_balance_type            => l_balance_type_code);
87007    ELSE
87008       NULL;
87009 -- No business flow processing for business flow method of NONE.
87010    END IF;
87011 
87012    --
87013    -- call analytical criteria
87014    --
87015    
87016    --
87017    -- call description
87018    --
87019    
87020 xla_ae_lines_pkg.SetLineDescription(
87021    p_ae_header_id => l_ae_header_id
87022   ,p_description  => Description_81 (
87023      p_application_id         => p_application_id
87024    , p_ae_header_id           => l_ae_header_id 
87025 , p_source_1 => p_source_1
87026    )
87027 );
87028 
87029 
87030    --
87031    -- call ADRs
87032    -- Bug 4922099
87033    --
87034    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
87035         (NVL(l_actual_upg_option, 'N') = 'O') OR
87036         (NVL(l_enc_upg_option, 'N') = 'O')
87037       )
87038    THEN
87039    NULL;
87040    --
87041    --
87042    
87043   l_ccid := AcctDerRule_173(
87044            p_application_id           => p_application_id
87045          , p_ae_header_id             => l_ae_header_id 
87046 , p_source_3 => p_source_3
87047 , p_source_30 => p_source_30
87048          , x_transaction_coa_id       => l_adr_transaction_coa_id
87049          , x_accounting_coa_id        => l_adr_accounting_coa_id
87053 
87050          , x_value_type_code          => l_adr_value_type_code
87051          , p_side                     => 'NA'
87052    );
87054    xla_ae_lines_pkg.set_ccid(
87055     p_code_combination_id          => l_ccid
87056   , p_value_type_code              => l_adr_value_type_code
87057   , p_transaction_coa_id           => l_adr_transaction_coa_id
87058   , p_accounting_coa_id            => l_adr_accounting_coa_id
87059   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
87060   , p_adr_type_code                => 'S'
87061   , p_component_type               => l_component_type
87062   , p_component_code               => l_component_code
87063   , p_component_type_code          => l_component_type_code
87064   , p_component_appl_id            => l_component_appl_id
87065   , p_amb_context_code             => l_amb_context_code
87066   , p_side                         => 'NA'
87067   );
87068 
87069 
87070    l_segment := AcctDerRule_168(
87071            p_application_id           => p_application_id
87072          , p_ae_header_id             => l_ae_header_id 
87073 , p_source_3 => p_source_3
87074 , p_source_29 => p_source_29
87075          , x_transaction_coa_id       => l_adr_transaction_coa_id
87076          , x_accounting_coa_id        => l_adr_accounting_coa_id
87077          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
87078          , x_flex_value_set_id        => l_adr_flex_value_set_id
87079          , x_value_type_code          => l_adr_value_type_code
87080          , x_value_combination_id     => l_adr_value_combination_id
87081          , x_value_segment_code       => l_adr_value_segment_code
87082          , p_side                     => 'NA'
87083          , p_override_seg_flag        => 'Y'
87084    );
87085 
87086    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
87087 
87088       xla_ae_lines_pkg.set_segment(
87089           p_to_segment_code         => 'GL_BALANCING'
87090         , p_segment_value           => l_segment
87091         , p_from_segment_code       => l_adr_value_segment_code
87092         , p_from_combination_id     => l_adr_value_combination_id
87093         , p_value_type_code         => l_adr_value_type_code
87094         , p_transaction_coa_id      => l_adr_transaction_coa_id
87095         , p_accounting_coa_id       => l_adr_accounting_coa_id
87096         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
87097         , p_flex_value_set_id       => l_adr_flex_value_set_id
87098         , p_adr_code                => 'FA_EXPENSE_ACCT'
87099         , p_adr_type_code           => 'S'
87100         , p_component_type          => l_component_type
87101         , p_component_code          => l_component_code
87102         , p_component_type_code     => l_component_type_code
87103         , p_component_appl_id       => l_component_appl_id
87104         , p_amb_context_code        => l_amb_context_code
87105         , p_entity_code             => 'TRANSACTIONS'
87106         , p_event_class_code        => 'RETIREMENTS'
87107         , p_side                    => 'NA'
87108         );
87109 
87110   END IF;
87111 
87112    l_segment := AcctDerRule_162(
87113            p_application_id           => p_application_id
87114          , p_ae_header_id             => l_ae_header_id 
87115 , p_source_3 => p_source_3
87116 , p_source_24 => p_source_24
87117          , x_transaction_coa_id       => l_adr_transaction_coa_id
87118          , x_accounting_coa_id        => l_adr_accounting_coa_id
87119          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
87120          , x_flex_value_set_id        => l_adr_flex_value_set_id
87121          , x_value_type_code          => l_adr_value_type_code
87122          , x_value_combination_id     => l_adr_value_combination_id
87123          , x_value_segment_code       => l_adr_value_segment_code
87124          , p_side                     => 'NA'
87125          , p_override_seg_flag        => 'Y'
87126    );
87127 
87128    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
87129 
87130       xla_ae_lines_pkg.set_segment(
87131           p_to_segment_code         => 'GL_ACCOUNT'
87132         , p_segment_value           => l_segment
87133         , p_from_segment_code       => l_adr_value_segment_code
87134         , p_from_combination_id     => l_adr_value_combination_id
87135         , p_value_type_code         => l_adr_value_type_code
87136         , p_transaction_coa_id      => l_adr_transaction_coa_id
87137         , p_accounting_coa_id       => l_adr_accounting_coa_id
87138         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
87139         , p_flex_value_set_id       => l_adr_flex_value_set_id
87140         , p_adr_code                => 'FA_PROC_OF_SALE_GAIN_SEGMENT'
87141         , p_adr_type_code           => 'S'
87142         , p_component_type          => l_component_type
87143         , p_component_code          => l_component_code
87144         , p_component_type_code     => l_component_type_code
87145         , p_component_appl_id       => l_component_appl_id
87146         , p_amb_context_code        => l_amb_context_code
87147         , p_entity_code             => 'TRANSACTIONS'
87148         , p_event_class_code        => 'RETIREMENTS'
87149         , p_side                    => 'NA'
87150         );
87151 
87152   END IF;
87153 
87154    --
87155    --
87156    END IF;
87157    --
87158    -- Bug 4922099
87159    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
87160           (NVL(l_enc_upg_option, 'N') = 'O')
87161         ) AND
87162         (l_bflow_method_code = 'PRIOR_ENTRY')
87163       )
87164    THEN
87165       IF
87166       --
87167       1 = 2
87168       --
87169       THEN
87170       xla_accounting_err_pkg.build_message
87171                                     (p_appli_s_name            => 'XLA'
87172                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
87176                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
87173                                     ,p_token_1                 => 'LINE_NUMBER'
87174                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
87175                                     ,p_token_2                 => 'LINE_TYPE_NAME'
87177                                                                              l_component_type
87178                                                                             ,l_component_code
87179                                                                             ,l_component_type_code
87180                                                                             ,l_component_appl_id
87181                                                                             ,l_amb_context_code
87182                                                                             ,l_entity_code
87183                                                                             ,l_event_class_code
87184                                                                            )
87185                                     ,p_token_3                 => 'OWNER'
87186                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
87187                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
87188                                                                           ,p_lookup_code    => l_component_type_code
87189                                                                          )
87190                                     ,p_token_4                 => 'PRODUCT_NAME'
87191                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
87192                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
87193                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
87194                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
87195                                     ,p_ae_header_id            =>  NULL
87196                                        );
87197 
87198         IF (C_LEVEL_ERROR>= g_log_level) THEN
87199                  trace
87200                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
87201                       ,p_level    => C_LEVEL_ERROR
87202                       ,p_module   => l_log_module);
87203         END IF;
87204       END IF;
87205    END IF;
87206    --
87207    --
87208    ------------------------------------------------------------------------------------------------
87209    -- 4219869 Business Flow
87210    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
87211    -- Prior Entry.  Currently, the following code is always generated.
87212    ------------------------------------------------------------------------------------------------
87213    XLA_AE_LINES_PKG.ValidateCurrentLine;
87214 
87215    ------------------------------------------------------------------------------------
87216    -- 4219869 Business Flow
87217    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
87218    ------------------------------------------------------------------------------------
87219    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
87220 
87221    ----------------------------------------------------------------------------------
87222    -- 4219869 Business Flow
87223    -- Update journal entry status -- Need to generate this within IF <condition>
87224    ----------------------------------------------------------------------------------
87225    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
87226          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
87227          ,p_balance_type_code => l_balance_type_code
87228          );
87229 
87230    -------------------------------------------------------------------------------------------
87231    -- 4262811 - Generate the Accrual Reversal lines
87232    -------------------------------------------------------------------------------------------
87233    BEGIN
87234       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
87235                               (g_array_event(p_event_id).array_value_num('header_index'));
87236       IF l_acc_rev_flag IS NULL THEN
87237          l_acc_rev_flag := 'N';
87238       END IF;
87239    EXCEPTION
87240       WHEN OTHERS THEN
87241          l_acc_rev_flag := 'N';
87242    END;
87243    --
87244    IF (l_acc_rev_flag = 'Y') THEN
87245 
87246        -- 4645092  ------------------------------------------------------------------------------
87247        -- To allow MPA report to determine if it should generate report process
87248        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
87249        ------------------------------------------------------------------------------------------
87250 
87251        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
87252        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
87253    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
87254    -- call ADRs
87255    -- Bug 4922099
87256    --
87257    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
87258         (NVL(l_actual_upg_option, 'N') = 'O') OR
87259         (NVL(l_enc_upg_option, 'N') = 'O')
87260       )
87261    THEN
87262    NULL;
87263    --
87264    --
87265    
87266   l_ccid := AcctDerRule_173(
87267            p_application_id           => p_application_id
87268          , p_ae_header_id             => l_ae_header_id 
87269 , p_source_3 => p_source_3
87270 , p_source_30 => p_source_30
87271          , x_transaction_coa_id       => l_adr_transaction_coa_id
87272          , x_accounting_coa_id        => l_adr_accounting_coa_id
87273          , x_value_type_code          => l_adr_value_type_code
87274          , p_side                     => 'NA'
87278     p_code_combination_id          => l_ccid
87275    );
87276 
87277    xla_ae_lines_pkg.set_ccid(
87279   , p_value_type_code              => l_adr_value_type_code
87280   , p_transaction_coa_id           => l_adr_transaction_coa_id
87281   , p_accounting_coa_id            => l_adr_accounting_coa_id
87282   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
87283   , p_adr_type_code                => 'S'
87284   , p_component_type               => l_component_type
87285   , p_component_code               => l_component_code
87286   , p_component_type_code          => l_component_type_code
87287   , p_component_appl_id            => l_component_appl_id
87288   , p_amb_context_code             => l_amb_context_code
87289   , p_side                         => 'NA'
87290   );
87291 
87292 
87293    l_segment := AcctDerRule_168(
87294            p_application_id           => p_application_id
87295          , p_ae_header_id             => l_ae_header_id 
87296 , p_source_3 => p_source_3
87297 , p_source_29 => p_source_29
87298          , x_transaction_coa_id       => l_adr_transaction_coa_id
87299          , x_accounting_coa_id        => l_adr_accounting_coa_id
87300          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
87301          , x_flex_value_set_id        => l_adr_flex_value_set_id
87302          , x_value_type_code          => l_adr_value_type_code
87303          , x_value_combination_id     => l_adr_value_combination_id
87304          , x_value_segment_code       => l_adr_value_segment_code
87305          , p_side                     => 'NA'
87306          , p_override_seg_flag        => 'Y'
87307    );
87308 
87309    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
87310 
87311       xla_ae_lines_pkg.set_segment(
87312           p_to_segment_code         => 'GL_BALANCING'
87313         , p_segment_value           => l_segment
87314         , p_from_segment_code       => l_adr_value_segment_code
87315         , p_from_combination_id     => l_adr_value_combination_id
87316         , p_value_type_code         => l_adr_value_type_code
87317         , p_transaction_coa_id      => l_adr_transaction_coa_id
87318         , p_accounting_coa_id       => l_adr_accounting_coa_id
87319         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
87320         , p_flex_value_set_id       => l_adr_flex_value_set_id
87321         , p_adr_code                => 'FA_EXPENSE_ACCT'
87322         , p_adr_type_code           => 'S'
87323         , p_component_type          => l_component_type
87324         , p_component_code          => l_component_code
87325         , p_component_type_code     => l_component_type_code
87326         , p_component_appl_id       => l_component_appl_id
87327         , p_amb_context_code        => l_amb_context_code
87328         , p_entity_code             => 'TRANSACTIONS'
87329         , p_event_class_code        => 'RETIREMENTS'
87330         , p_side                    => 'NA'
87331         );
87332 
87333   END IF;
87334 
87335    l_segment := AcctDerRule_162(
87336            p_application_id           => p_application_id
87337          , p_ae_header_id             => l_ae_header_id 
87338 , p_source_3 => p_source_3
87339 , p_source_24 => p_source_24
87340          , x_transaction_coa_id       => l_adr_transaction_coa_id
87341          , x_accounting_coa_id        => l_adr_accounting_coa_id
87342          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
87343          , x_flex_value_set_id        => l_adr_flex_value_set_id
87344          , x_value_type_code          => l_adr_value_type_code
87345          , x_value_combination_id     => l_adr_value_combination_id
87346          , x_value_segment_code       => l_adr_value_segment_code
87347          , p_side                     => 'NA'
87348          , p_override_seg_flag        => 'Y'
87349    );
87350 
87351    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
87352 
87353       xla_ae_lines_pkg.set_segment(
87354           p_to_segment_code         => 'GL_ACCOUNT'
87355         , p_segment_value           => l_segment
87356         , p_from_segment_code       => l_adr_value_segment_code
87357         , p_from_combination_id     => l_adr_value_combination_id
87358         , p_value_type_code         => l_adr_value_type_code
87359         , p_transaction_coa_id      => l_adr_transaction_coa_id
87360         , p_accounting_coa_id       => l_adr_accounting_coa_id
87361         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
87362         , p_flex_value_set_id       => l_adr_flex_value_set_id
87363         , p_adr_code                => 'FA_PROC_OF_SALE_GAIN_SEGMENT'
87364         , p_adr_type_code           => 'S'
87365         , p_component_type          => l_component_type
87366         , p_component_code          => l_component_code
87367         , p_component_type_code     => l_component_type_code
87368         , p_component_appl_id       => l_component_appl_id
87369         , p_amb_context_code        => l_amb_context_code
87370         , p_entity_code             => 'TRANSACTIONS'
87371         , p_event_class_code        => 'RETIREMENTS'
87372         , p_side                    => 'NA'
87373         );
87374 
87375   END IF;
87376 
87377    --
87378    --
87379    END IF;
87380 
87381        --
87382        -- Update the line information that should be overwritten
87383        --
87384        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
87385                                          p_header_num   => 1);
87386        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
87387 
87388        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
87389 
87390        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
87391           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
87392        END IF;
87393 
87394       --
87398           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
87395       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
87396       --
87397       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
87399       ELSE
87400           ---------------------------------------------------------------------------------------------------
87401           -- 4262811a Switch Sign
87402           ---------------------------------------------------------------------------------------------------
87403           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
87404           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
87405                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
87406           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
87407                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
87408           -- 5132302
87409           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
87410                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
87411 
87412       END IF;
87413 
87414       -- 4955764
87415       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
87416       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
87417 
87418 
87419       XLA_AE_LINES_PKG.ValidateCurrentLine;
87420       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
87421 
87422       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
87423                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
87424                ,p_balance_type_code => l_balance_type_code);
87425 
87426    END IF;
87427 
87428    -----------------------------------------------------------------------------------------
87429    -- 4262811 Multiperiod Accounting
87430    -----------------------------------------------------------------------------------------
87431      -- No MPA option is assigned.
87432 
87433 
87434 END IF;
87435 END IF;
87436 --
87437 
87438 --
87439 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
87440    trace
87441       (p_msg      => 'END of AcctLineType_275'
87442       ,p_level    => C_LEVEL_PROCEDURE
87443       ,p_module   => l_log_module);
87444 END IF;
87445 --
87446 EXCEPTION
87447   WHEN xla_exceptions_pkg.application_exception THEN
87448       RAISE;
87449   WHEN OTHERS THEN
87450        xla_exceptions_pkg.raise_message
87451            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_275');
87452 END AcctLineType_275;
87453 --
87454 
87455 ---------------------------------------
87456 --
87457 -- PRIVATE FUNCTION
87458 --         AcctLineType_276
87459 --
87460 ---------------------------------------
87461 PROCEDURE AcctLineType_276 (
87462   p_application_id        IN NUMBER
87463  ,p_event_id              IN NUMBER
87464  ,p_calculate_acctd_flag  IN VARCHAR2
87465  ,p_calculate_g_l_flag    IN VARCHAR2
87466  ,p_actual_flag           IN OUT VARCHAR2
87467  ,p_balance_type_code     OUT VARCHAR2
87468  ,p_gain_or_loss_ref      OUT VARCHAR2
87469  
87470 --Period Close Date
87471  , p_source_1            IN DATE
87472 --Generated Code Combination Identifier
87473  , p_source_3            IN NUMBER
87474 --Proceeds Of Sale Gain Account
87475  , p_source_24            IN VARCHAR2
87476 --Expense Account Code Combination Identifier
87477  , p_source_29            IN NUMBER
87478 --Default Code Combination Identifier
87479  , p_source_30            IN NUMBER
87480 --Adjustment Type
87481  , p_source_35            IN VARCHAR2
87482 --Transaction Header Identifier
87483  , p_source_36            IN NUMBER
87484 --Adjustment Line Identifier
87485  , p_source_37            IN NUMBER
87486 --Distribution Type Code
87487  , p_source_38            IN VARCHAR2
87488 --Entered Amount
87489  , p_source_39            IN NUMBER
87490 --Currency Code
87491  , p_source_40            IN VARCHAR2
87492 --Gain Loss Amount
87493  , p_source_41            IN NUMBER
87494 )
87495 IS
87496 
87497 l_component_type              VARCHAR2(80);
87498 l_component_code              VARCHAR2(30);
87499 l_component_type_code         VARCHAR2(1);
87500 l_component_appl_id           INTEGER;
87501 l_amb_context_code            VARCHAR2(30);
87502 l_entity_code                 VARCHAR2(30);
87503 l_event_class_code            VARCHAR2(30);
87504 l_ae_header_id                NUMBER;
87505 l_event_type_code             VARCHAR2(30);
87506 l_line_definition_code        VARCHAR2(30);
87507 l_line_definition_owner_code  VARCHAR2(1);
87508 --
87509 -- adr variables
87510 l_segment                     VARCHAR2(30);
87511 l_ccid                        NUMBER;
87512 l_adr_transaction_coa_id      NUMBER;
87513 l_adr_accounting_coa_id       NUMBER;
87514 l_adr_flexfield_segment_code  VARCHAR2(30);
87515 l_adr_flex_value_set_id       NUMBER;
87516 l_adr_value_type_code         VARCHAR2(30);
87517 l_adr_value_combination_id    NUMBER;
87518 l_adr_value_segment_code      VARCHAR2(30);
87519 
87520 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
87521 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
87522 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
87523 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
87524 
87525 -- 4262811 Variables ------------------------------------------------------------------------------------------
87526 l_entered_amt_idx             NUMBER;
87527 l_accted_amt_idx              NUMBER;
87531 l_acc_rev_natural_side_code   VARCHAR2(1);
87528 l_acc_rev_flag                VARCHAR2(1);
87529 l_accrual_line_num            NUMBER;
87530 l_tmp_amt                     NUMBER;
87532 
87533 l_num_entries                 NUMBER;
87534 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
87535 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
87536 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
87537 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
87538 l_recog_line_1                NUMBER;
87539 l_recog_line_2                NUMBER;
87540 
87541 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
87542 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
87543 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
87544 
87545 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
87546 
87547 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
87548 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
87549 
87550 ---------------------------------------------------------------------------------------------------------------
87551 
87552 
87553 --
87554 -- bulk performance
87555 --
87556 l_balance_type_code           VARCHAR2(1);
87557 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
87558 l_log_module                  VARCHAR2(240);
87559 
87560 --
87561 -- Upgrade strategy
87562 --
87563 l_actual_upg_option           VARCHAR2(1);
87564 l_enc_upg_option           VARCHAR2(1);
87565 
87566 --
87567 BEGIN
87568 --
87569 IF g_log_enabled THEN
87570       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_276';
87571 END IF;
87572 --
87573 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
87574 
87575       trace
87576          (p_msg      => 'BEGIN of AcctLineType_276'
87577          ,p_level    => C_LEVEL_PROCEDURE
87578          ,p_module   => l_log_module);
87579 
87580 END IF;
87581 --
87582 l_component_type             := 'AMB_JLT';
87583 l_component_code             := 'FA_PROC_OF_SALE_GAIN';
87584 l_component_type_code        := 'S';
87585 l_component_appl_id          :=  140;
87586 l_amb_context_code           := 'DEFAULT';
87587 l_entity_code                := 'TRANSACTIONS';
87588 l_event_class_code           := 'RETIREMENTS';
87589 l_event_type_code            := 'REINSTATEMENTS';
87590 l_line_definition_owner_code := 'S';
87591 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
87592 --
87593 l_balance_type_code          := 'A';
87594 l_segment                     := NULL;
87595 l_ccid                        := NULL;
87596 l_adr_transaction_coa_id      := NULL;
87597 l_adr_accounting_coa_id       := NULL;
87598 l_adr_flexfield_segment_code  := NULL;
87599 l_adr_flex_value_set_id       := NULL;
87600 l_adr_value_type_code         := NULL;
87601 l_adr_value_combination_id    := NULL;
87602 l_adr_value_segment_code      := NULL;
87603 
87604 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
87605 l_bflow_class_code           := '';    -- 4219869 Business Flow
87606 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
87607 l_budgetary_control_flag     := 'N';
87608 
87609 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
87610 l_bflow_applied_to_amt       := NULL; -- 5132302
87611 l_entered_amt_idx            := NULL;          -- 4262811
87612 l_accted_amt_idx             := NULL;          -- 4262811
87613 l_acc_rev_flag               := NULL;          -- 4262811
87614 l_accrual_line_num           := NULL;          -- 4262811
87615 l_tmp_amt                    := NULL;          -- 4262811
87616 --
87617  
87618 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
87619     l_balance_type_code <> 'B' THEN
87620 IF NVL(p_source_35,'
87621 ') =  'PROCEEDS' AND 
87622 p_source_41 >=  0
87623  THEN 
87624 
87625    --
87626    XLA_AE_LINES_PKG.SetNewLine;
87627 
87628    p_balance_type_code          := l_balance_type_code;
87629    -- set the flag so later we will know whether the gain loss line needs to be created
87630    
87631    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
87632      p_actual_flag :='A';
87633    END IF;
87634 
87635    --
87636    -- bulk performance
87637    --
87638    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
87639                                       p_header_num   => 0); -- 4262811
87640    --
87641    -- set accounting line options
87642    --
87643    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
87644            p_natural_side_code          => 'C'
87645          , p_gain_or_loss_flag          => 'N'
87646          , p_gl_transfer_mode_code      => 'S'
87647          , p_acct_entry_type_code       => 'A'
87648          , p_switch_side_flag           => 'Y'
87649          , p_merge_duplicate_code       => 'N'
87650          );
87651    --
87652    l_acc_rev_natural_side_code := 'D';  -- 4262811
87653    -- 
87654    --
87655    -- set accounting line type info
87656    --
87657    xla_ae_lines_pkg.SetAcctLineType
87658       (p_component_type             => l_component_type
87659       ,p_event_type_code            => l_event_type_code
87660       ,p_line_definition_owner_code => l_line_definition_owner_code
87661       ,p_line_definition_code       => l_line_definition_code
87662       ,p_accounting_line_code       => l_component_code
87663       ,p_accounting_line_type_code  => l_component_type_code
87664       ,p_accounting_line_appl_id    => l_component_appl_id
87665       ,p_amb_context_code           => l_amb_context_code
87666       ,p_entity_code                => l_entity_code
87670    --
87667       ,p_event_class_code           => l_event_class_code);
87668    --
87669    -- set accounting class
87671    xla_ae_lines_pkg.SetAcctClass(
87672            p_accounting_class_code  => 'ASSET'
87673          , p_ae_header_id           => l_ae_header_id
87674          );
87675 
87676    --
87677    -- set rounding class
87678    --
87679    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
87680                       'ASSET';
87681 
87682    --
87683    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
87684    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
87685    --
87686    -- bulk performance
87687    --
87688    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
87689 
87690    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
87691       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
87692 
87693    -- 4955764
87694    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
87695       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
87696 
87697    -- 4458381 Public Sector Enh
87698    
87699    --
87700    -- set accounting attributes for the line type
87701    --
87702    l_entered_amt_idx := 4;
87703    l_accted_amt_idx  := 6;
87704    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
87705    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
87706    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
87707    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
87708    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
87709    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
87710    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
87711    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
87712    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
87713    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
87714    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
87715    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
87716    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
87717 
87718    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
87719    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
87720 
87721    ---------------------------------------------------------------------------------------------------------------
87722    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
87723    ---------------------------------------------------------------------------------------------------------------
87724    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
87725 
87726    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
87727    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
87728 
87729    IF xla_accounting_cache_pkg.GetValueChar
87730          (p_source_code         => 'LEDGER_CATEGORY_CODE'
87731          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
87732    AND l_bflow_method_code = 'PRIOR_ENTRY'
87733 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
87734    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
87735          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
87736        )
87737    THEN
87738          xla_ae_lines_pkg.BflowUpgEntry
87739            (p_business_method_code    => l_bflow_method_code
87740            ,p_business_class_code     => l_bflow_class_code
87741            ,p_balance_type            => l_balance_type_code);
87742    ELSE
87743       NULL;
87744 -- No business flow processing for business flow method of NONE.
87745    END IF;
87746 
87747    --
87748    -- call analytical criteria
87749    --
87750    
87751    --
87752    -- call description
87753    --
87754    
87755 xla_ae_lines_pkg.SetLineDescription(
87756    p_ae_header_id => l_ae_header_id
87757   ,p_description  => Description_81 (
87758      p_application_id         => p_application_id
87759    , p_ae_header_id           => l_ae_header_id 
87760 , p_source_1 => p_source_1
87761    )
87762 );
87763 
87764 
87765    --
87766    -- call ADRs
87767    -- Bug 4922099
87768    --
87769    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
87770         (NVL(l_actual_upg_option, 'N') = 'O') OR
87771         (NVL(l_enc_upg_option, 'N') = 'O')
87772       )
87773    THEN
87774    NULL;
87775    --
87776    --
87777    
87778   l_ccid := AcctDerRule_173(
87779            p_application_id           => p_application_id
87780          , p_ae_header_id             => l_ae_header_id 
87781 , p_source_3 => p_source_3
87782 , p_source_30 => p_source_30
87783          , x_transaction_coa_id       => l_adr_transaction_coa_id
87784          , x_accounting_coa_id        => l_adr_accounting_coa_id
87785          , x_value_type_code          => l_adr_value_type_code
87786          , p_side                     => 'NA'
87787    );
87788 
87789    xla_ae_lines_pkg.set_ccid(
87790     p_code_combination_id          => l_ccid
87791   , p_value_type_code              => l_adr_value_type_code
87792   , p_transaction_coa_id           => l_adr_transaction_coa_id
87793   , p_accounting_coa_id            => l_adr_accounting_coa_id
87794   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
87795   , p_adr_type_code                => 'S'
87796   , p_component_type               => l_component_type
87800   , p_amb_context_code             => l_amb_context_code
87797   , p_component_code               => l_component_code
87798   , p_component_type_code          => l_component_type_code
87799   , p_component_appl_id            => l_component_appl_id
87801   , p_side                         => 'NA'
87802   );
87803 
87804 
87805    l_segment := AcctDerRule_168(
87806            p_application_id           => p_application_id
87807          , p_ae_header_id             => l_ae_header_id 
87808 , p_source_3 => p_source_3
87809 , p_source_29 => p_source_29
87810          , x_transaction_coa_id       => l_adr_transaction_coa_id
87811          , x_accounting_coa_id        => l_adr_accounting_coa_id
87812          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
87813          , x_flex_value_set_id        => l_adr_flex_value_set_id
87814          , x_value_type_code          => l_adr_value_type_code
87815          , x_value_combination_id     => l_adr_value_combination_id
87816          , x_value_segment_code       => l_adr_value_segment_code
87817          , p_side                     => 'NA'
87818          , p_override_seg_flag        => 'Y'
87819    );
87820 
87821    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
87822 
87823       xla_ae_lines_pkg.set_segment(
87824           p_to_segment_code         => 'GL_BALANCING'
87825         , p_segment_value           => l_segment
87826         , p_from_segment_code       => l_adr_value_segment_code
87827         , p_from_combination_id     => l_adr_value_combination_id
87828         , p_value_type_code         => l_adr_value_type_code
87829         , p_transaction_coa_id      => l_adr_transaction_coa_id
87830         , p_accounting_coa_id       => l_adr_accounting_coa_id
87831         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
87832         , p_flex_value_set_id       => l_adr_flex_value_set_id
87833         , p_adr_code                => 'FA_EXPENSE_ACCT'
87834         , p_adr_type_code           => 'S'
87835         , p_component_type          => l_component_type
87836         , p_component_code          => l_component_code
87837         , p_component_type_code     => l_component_type_code
87838         , p_component_appl_id       => l_component_appl_id
87839         , p_amb_context_code        => l_amb_context_code
87840         , p_entity_code             => 'TRANSACTIONS'
87841         , p_event_class_code        => 'RETIREMENTS'
87842         , p_side                    => 'NA'
87843         );
87844 
87845   END IF;
87846 
87847    l_segment := AcctDerRule_162(
87848            p_application_id           => p_application_id
87849          , p_ae_header_id             => l_ae_header_id 
87850 , p_source_3 => p_source_3
87851 , p_source_24 => p_source_24
87852          , x_transaction_coa_id       => l_adr_transaction_coa_id
87853          , x_accounting_coa_id        => l_adr_accounting_coa_id
87854          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
87855          , x_flex_value_set_id        => l_adr_flex_value_set_id
87856          , x_value_type_code          => l_adr_value_type_code
87857          , x_value_combination_id     => l_adr_value_combination_id
87858          , x_value_segment_code       => l_adr_value_segment_code
87859          , p_side                     => 'NA'
87860          , p_override_seg_flag        => 'Y'
87861    );
87862 
87863    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
87864 
87865       xla_ae_lines_pkg.set_segment(
87866           p_to_segment_code         => 'GL_ACCOUNT'
87867         , p_segment_value           => l_segment
87868         , p_from_segment_code       => l_adr_value_segment_code
87869         , p_from_combination_id     => l_adr_value_combination_id
87870         , p_value_type_code         => l_adr_value_type_code
87871         , p_transaction_coa_id      => l_adr_transaction_coa_id
87872         , p_accounting_coa_id       => l_adr_accounting_coa_id
87873         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
87874         , p_flex_value_set_id       => l_adr_flex_value_set_id
87875         , p_adr_code                => 'FA_PROC_OF_SALE_GAIN_SEGMENT'
87876         , p_adr_type_code           => 'S'
87877         , p_component_type          => l_component_type
87878         , p_component_code          => l_component_code
87879         , p_component_type_code     => l_component_type_code
87880         , p_component_appl_id       => l_component_appl_id
87881         , p_amb_context_code        => l_amb_context_code
87882         , p_entity_code             => 'TRANSACTIONS'
87883         , p_event_class_code        => 'RETIREMENTS'
87884         , p_side                    => 'NA'
87885         );
87886 
87887   END IF;
87888 
87889    --
87890    --
87891    END IF;
87892    --
87893    -- Bug 4922099
87894    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
87895           (NVL(l_enc_upg_option, 'N') = 'O')
87896         ) AND
87897         (l_bflow_method_code = 'PRIOR_ENTRY')
87898       )
87899    THEN
87900       IF
87901       --
87902       1 = 2
87903       --
87904       THEN
87905       xla_accounting_err_pkg.build_message
87906                                     (p_appli_s_name            => 'XLA'
87907                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
87908                                     ,p_token_1                 => 'LINE_NUMBER'
87909                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
87910                                     ,p_token_2                 => 'LINE_TYPE_NAME'
87911                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
87912                                                                              l_component_type
87913                                                                             ,l_component_code
87914                                                                             ,l_component_type_code
87918                                                                             ,l_event_class_code
87915                                                                             ,l_component_appl_id
87916                                                                             ,l_amb_context_code
87917                                                                             ,l_entity_code
87919                                                                            )
87920                                     ,p_token_3                 => 'OWNER'
87921                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
87922                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
87923                                                                           ,p_lookup_code    => l_component_type_code
87924                                                                          )
87925                                     ,p_token_4                 => 'PRODUCT_NAME'
87926                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
87927                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
87928                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
87929                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
87930                                     ,p_ae_header_id            =>  NULL
87931                                        );
87932 
87933         IF (C_LEVEL_ERROR>= g_log_level) THEN
87934                  trace
87935                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
87936                       ,p_level    => C_LEVEL_ERROR
87937                       ,p_module   => l_log_module);
87938         END IF;
87939       END IF;
87940    END IF;
87941    --
87942    --
87943    ------------------------------------------------------------------------------------------------
87944    -- 4219869 Business Flow
87945    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
87946    -- Prior Entry.  Currently, the following code is always generated.
87947    ------------------------------------------------------------------------------------------------
87948    XLA_AE_LINES_PKG.ValidateCurrentLine;
87949 
87950    ------------------------------------------------------------------------------------
87951    -- 4219869 Business Flow
87952    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
87953    ------------------------------------------------------------------------------------
87954    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
87955 
87956    ----------------------------------------------------------------------------------
87957    -- 4219869 Business Flow
87958    -- Update journal entry status -- Need to generate this within IF <condition>
87959    ----------------------------------------------------------------------------------
87960    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
87961          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
87962          ,p_balance_type_code => l_balance_type_code
87963          );
87964 
87965    -------------------------------------------------------------------------------------------
87966    -- 4262811 - Generate the Accrual Reversal lines
87967    -------------------------------------------------------------------------------------------
87968    BEGIN
87969       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
87970                               (g_array_event(p_event_id).array_value_num('header_index'));
87971       IF l_acc_rev_flag IS NULL THEN
87972          l_acc_rev_flag := 'N';
87973       END IF;
87974    EXCEPTION
87975       WHEN OTHERS THEN
87976          l_acc_rev_flag := 'N';
87977    END;
87978    --
87979    IF (l_acc_rev_flag = 'Y') THEN
87980 
87981        -- 4645092  ------------------------------------------------------------------------------
87982        -- To allow MPA report to determine if it should generate report process
87983        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
87984        ------------------------------------------------------------------------------------------
87985 
87986        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
87987        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
87988    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
87989    -- call ADRs
87990    -- Bug 4922099
87991    --
87992    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
87993         (NVL(l_actual_upg_option, 'N') = 'O') OR
87994         (NVL(l_enc_upg_option, 'N') = 'O')
87995       )
87996    THEN
87997    NULL;
87998    --
87999    --
88000    
88001   l_ccid := AcctDerRule_173(
88002            p_application_id           => p_application_id
88003          , p_ae_header_id             => l_ae_header_id 
88004 , p_source_3 => p_source_3
88005 , p_source_30 => p_source_30
88006          , x_transaction_coa_id       => l_adr_transaction_coa_id
88007          , x_accounting_coa_id        => l_adr_accounting_coa_id
88008          , x_value_type_code          => l_adr_value_type_code
88009          , p_side                     => 'NA'
88010    );
88011 
88012    xla_ae_lines_pkg.set_ccid(
88013     p_code_combination_id          => l_ccid
88014   , p_value_type_code              => l_adr_value_type_code
88015   , p_transaction_coa_id           => l_adr_transaction_coa_id
88016   , p_accounting_coa_id            => l_adr_accounting_coa_id
88017   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
88018   , p_adr_type_code                => 'S'
88019   , p_component_type               => l_component_type
88020   , p_component_code               => l_component_code
88021   , p_component_type_code          => l_component_type_code
88025   );
88022   , p_component_appl_id            => l_component_appl_id
88023   , p_amb_context_code             => l_amb_context_code
88024   , p_side                         => 'NA'
88026 
88027 
88028    l_segment := AcctDerRule_168(
88029            p_application_id           => p_application_id
88030          , p_ae_header_id             => l_ae_header_id 
88031 , p_source_3 => p_source_3
88032 , p_source_29 => p_source_29
88033          , x_transaction_coa_id       => l_adr_transaction_coa_id
88034          , x_accounting_coa_id        => l_adr_accounting_coa_id
88035          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
88036          , x_flex_value_set_id        => l_adr_flex_value_set_id
88037          , x_value_type_code          => l_adr_value_type_code
88038          , x_value_combination_id     => l_adr_value_combination_id
88039          , x_value_segment_code       => l_adr_value_segment_code
88040          , p_side                     => 'NA'
88041          , p_override_seg_flag        => 'Y'
88042    );
88043 
88044    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
88045 
88046       xla_ae_lines_pkg.set_segment(
88047           p_to_segment_code         => 'GL_BALANCING'
88048         , p_segment_value           => l_segment
88049         , p_from_segment_code       => l_adr_value_segment_code
88050         , p_from_combination_id     => l_adr_value_combination_id
88051         , p_value_type_code         => l_adr_value_type_code
88052         , p_transaction_coa_id      => l_adr_transaction_coa_id
88053         , p_accounting_coa_id       => l_adr_accounting_coa_id
88054         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
88055         , p_flex_value_set_id       => l_adr_flex_value_set_id
88056         , p_adr_code                => 'FA_EXPENSE_ACCT'
88057         , p_adr_type_code           => 'S'
88058         , p_component_type          => l_component_type
88059         , p_component_code          => l_component_code
88060         , p_component_type_code     => l_component_type_code
88061         , p_component_appl_id       => l_component_appl_id
88062         , p_amb_context_code        => l_amb_context_code
88063         , p_entity_code             => 'TRANSACTIONS'
88064         , p_event_class_code        => 'RETIREMENTS'
88065         , p_side                    => 'NA'
88066         );
88067 
88068   END IF;
88069 
88070    l_segment := AcctDerRule_162(
88071            p_application_id           => p_application_id
88072          , p_ae_header_id             => l_ae_header_id 
88073 , p_source_3 => p_source_3
88074 , p_source_24 => p_source_24
88075          , x_transaction_coa_id       => l_adr_transaction_coa_id
88076          , x_accounting_coa_id        => l_adr_accounting_coa_id
88077          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
88078          , x_flex_value_set_id        => l_adr_flex_value_set_id
88079          , x_value_type_code          => l_adr_value_type_code
88080          , x_value_combination_id     => l_adr_value_combination_id
88081          , x_value_segment_code       => l_adr_value_segment_code
88082          , p_side                     => 'NA'
88083          , p_override_seg_flag        => 'Y'
88084    );
88085 
88086    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
88087 
88088       xla_ae_lines_pkg.set_segment(
88089           p_to_segment_code         => 'GL_ACCOUNT'
88090         , p_segment_value           => l_segment
88091         , p_from_segment_code       => l_adr_value_segment_code
88092         , p_from_combination_id     => l_adr_value_combination_id
88093         , p_value_type_code         => l_adr_value_type_code
88094         , p_transaction_coa_id      => l_adr_transaction_coa_id
88095         , p_accounting_coa_id       => l_adr_accounting_coa_id
88096         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
88097         , p_flex_value_set_id       => l_adr_flex_value_set_id
88098         , p_adr_code                => 'FA_PROC_OF_SALE_GAIN_SEGMENT'
88099         , p_adr_type_code           => 'S'
88100         , p_component_type          => l_component_type
88101         , p_component_code          => l_component_code
88102         , p_component_type_code     => l_component_type_code
88103         , p_component_appl_id       => l_component_appl_id
88104         , p_amb_context_code        => l_amb_context_code
88105         , p_entity_code             => 'TRANSACTIONS'
88106         , p_event_class_code        => 'RETIREMENTS'
88107         , p_side                    => 'NA'
88108         );
88109 
88110   END IF;
88111 
88112    --
88113    --
88114    END IF;
88115 
88116        --
88117        -- Update the line information that should be overwritten
88118        --
88119        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
88120                                          p_header_num   => 1);
88121        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
88122 
88123        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
88124 
88125        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
88126           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
88127        END IF;
88128 
88129       --
88130       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
88131       --
88132       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
88133           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
88134       ELSE
88135           ---------------------------------------------------------------------------------------------------
88136           -- 4262811a Switch Sign
88137           ---------------------------------------------------------------------------------------------------
88141           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
88138           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
88139           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
88140                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
88142                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
88143           -- 5132302
88144           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
88145                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
88146 
88147       END IF;
88148 
88149       -- 4955764
88150       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
88151       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
88152 
88153 
88154       XLA_AE_LINES_PKG.ValidateCurrentLine;
88155       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
88156 
88157       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
88158                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
88159                ,p_balance_type_code => l_balance_type_code);
88160 
88161    END IF;
88162 
88163    -----------------------------------------------------------------------------------------
88164    -- 4262811 Multiperiod Accounting
88165    -----------------------------------------------------------------------------------------
88166      -- No MPA option is assigned.
88167 
88168 
88169 END IF;
88170 END IF;
88171 --
88172 
88173 --
88174 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
88175    trace
88176       (p_msg      => 'END of AcctLineType_276'
88177       ,p_level    => C_LEVEL_PROCEDURE
88178       ,p_module   => l_log_module);
88179 END IF;
88180 --
88181 EXCEPTION
88182   WHEN xla_exceptions_pkg.application_exception THEN
88183       RAISE;
88184   WHEN OTHERS THEN
88185        xla_exceptions_pkg.raise_message
88186            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_276');
88187 END AcctLineType_276;
88188 --
88189 
88190 ---------------------------------------
88191 --
88192 -- PRIVATE FUNCTION
88193 --         AcctLineType_277
88194 --
88195 ---------------------------------------
88196 PROCEDURE AcctLineType_277 (
88197   p_application_id        IN NUMBER
88198  ,p_event_id              IN NUMBER
88199  ,p_calculate_acctd_flag  IN VARCHAR2
88200  ,p_calculate_g_l_flag    IN VARCHAR2
88201  ,p_actual_flag           IN OUT VARCHAR2
88202  ,p_balance_type_code     OUT VARCHAR2
88203  ,p_gain_or_loss_ref      OUT VARCHAR2
88204  
88205 --Period Close Date
88206  , p_source_1            IN DATE
88207 --Generated Code Combination Identifier
88208  , p_source_3            IN NUMBER
88209 --Proceeds Of Sale Loss Account
88210  , p_source_25            IN VARCHAR2
88211 --Expense Account Code Combination Identifier
88212  , p_source_29            IN NUMBER
88213 --Default Code Combination Identifier
88214  , p_source_30            IN NUMBER
88215 --Adjustment Type
88216  , p_source_35            IN VARCHAR2
88217 --Transaction Header Identifier
88218  , p_source_36            IN NUMBER
88219 --Adjustment Line Identifier
88220  , p_source_37            IN NUMBER
88221 --Distribution Type Code
88222  , p_source_38            IN VARCHAR2
88223 --Entered Amount
88224  , p_source_39            IN NUMBER
88225 --Currency Code
88226  , p_source_40            IN VARCHAR2
88227 --Gain Loss Amount
88228  , p_source_41            IN NUMBER
88229 )
88230 IS
88231 
88232 l_component_type              VARCHAR2(80);
88233 l_component_code              VARCHAR2(30);
88234 l_component_type_code         VARCHAR2(1);
88235 l_component_appl_id           INTEGER;
88236 l_amb_context_code            VARCHAR2(30);
88237 l_entity_code                 VARCHAR2(30);
88238 l_event_class_code            VARCHAR2(30);
88239 l_ae_header_id                NUMBER;
88240 l_event_type_code             VARCHAR2(30);
88241 l_line_definition_code        VARCHAR2(30);
88242 l_line_definition_owner_code  VARCHAR2(1);
88243 --
88244 -- adr variables
88245 l_segment                     VARCHAR2(30);
88246 l_ccid                        NUMBER;
88247 l_adr_transaction_coa_id      NUMBER;
88248 l_adr_accounting_coa_id       NUMBER;
88249 l_adr_flexfield_segment_code  VARCHAR2(30);
88250 l_adr_flex_value_set_id       NUMBER;
88251 l_adr_value_type_code         VARCHAR2(30);
88252 l_adr_value_combination_id    NUMBER;
88253 l_adr_value_segment_code      VARCHAR2(30);
88254 
88255 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
88256 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
88257 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
88258 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
88259 
88260 -- 4262811 Variables ------------------------------------------------------------------------------------------
88261 l_entered_amt_idx             NUMBER;
88262 l_accted_amt_idx              NUMBER;
88263 l_acc_rev_flag                VARCHAR2(1);
88264 l_accrual_line_num            NUMBER;
88265 l_tmp_amt                     NUMBER;
88266 l_acc_rev_natural_side_code   VARCHAR2(1);
88267 
88268 l_num_entries                 NUMBER;
88269 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
88270 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
88271 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
88272 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
88273 l_recog_line_1                NUMBER;
88277 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
88274 l_recog_line_2                NUMBER;
88275 
88276 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
88278 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
88279 
88280 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
88281 
88282 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
88283 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
88284 
88285 ---------------------------------------------------------------------------------------------------------------
88286 
88287 
88288 --
88289 -- bulk performance
88290 --
88291 l_balance_type_code           VARCHAR2(1);
88292 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
88293 l_log_module                  VARCHAR2(240);
88294 
88295 --
88296 -- Upgrade strategy
88297 --
88298 l_actual_upg_option           VARCHAR2(1);
88299 l_enc_upg_option           VARCHAR2(1);
88300 
88301 --
88302 BEGIN
88303 --
88304 IF g_log_enabled THEN
88305       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_277';
88306 END IF;
88307 --
88308 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
88309 
88310       trace
88311          (p_msg      => 'BEGIN of AcctLineType_277'
88312          ,p_level    => C_LEVEL_PROCEDURE
88313          ,p_module   => l_log_module);
88314 
88315 END IF;
88316 --
88317 l_component_type             := 'AMB_JLT';
88318 l_component_code             := 'FA_PROC_OF_SALE_LOSS';
88319 l_component_type_code        := 'S';
88320 l_component_appl_id          :=  140;
88321 l_amb_context_code           := 'DEFAULT';
88322 l_entity_code                := 'TRANSACTIONS';
88323 l_event_class_code           := 'RETIREMENTS';
88324 l_event_type_code            := 'RETIREMENTS';
88325 l_line_definition_owner_code := 'S';
88326 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
88327 --
88328 l_balance_type_code          := 'A';
88329 l_segment                     := NULL;
88330 l_ccid                        := NULL;
88331 l_adr_transaction_coa_id      := NULL;
88332 l_adr_accounting_coa_id       := NULL;
88333 l_adr_flexfield_segment_code  := NULL;
88334 l_adr_flex_value_set_id       := NULL;
88335 l_adr_value_type_code         := NULL;
88336 l_adr_value_combination_id    := NULL;
88337 l_adr_value_segment_code      := NULL;
88338 
88339 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
88340 l_bflow_class_code           := '';    -- 4219869 Business Flow
88341 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
88342 l_budgetary_control_flag     := 'N';
88343 
88344 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
88345 l_bflow_applied_to_amt       := NULL; -- 5132302
88346 l_entered_amt_idx            := NULL;          -- 4262811
88347 l_accted_amt_idx             := NULL;          -- 4262811
88348 l_acc_rev_flag               := NULL;          -- 4262811
88349 l_accrual_line_num           := NULL;          -- 4262811
88350 l_tmp_amt                    := NULL;          -- 4262811
88351 --
88352  
88353 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
88354     l_balance_type_code <> 'B' THEN
88355 IF NVL(p_source_35,'
88356 ') =  'PROCEEDS' AND 
88357 p_source_41 <  0
88358  THEN 
88359 
88360    --
88361    XLA_AE_LINES_PKG.SetNewLine;
88362 
88363    p_balance_type_code          := l_balance_type_code;
88364    -- set the flag so later we will know whether the gain loss line needs to be created
88365    
88366    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
88367      p_actual_flag :='A';
88368    END IF;
88369 
88370    --
88371    -- bulk performance
88372    --
88373    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
88374                                       p_header_num   => 0); -- 4262811
88375    --
88376    -- set accounting line options
88377    --
88378    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
88379            p_natural_side_code          => 'C'
88380          , p_gain_or_loss_flag          => 'N'
88381          , p_gl_transfer_mode_code      => 'S'
88382          , p_acct_entry_type_code       => 'A'
88383          , p_switch_side_flag           => 'Y'
88384          , p_merge_duplicate_code       => 'N'
88385          );
88386    --
88387    l_acc_rev_natural_side_code := 'D';  -- 4262811
88388    -- 
88389    --
88390    -- set accounting line type info
88391    --
88392    xla_ae_lines_pkg.SetAcctLineType
88393       (p_component_type             => l_component_type
88394       ,p_event_type_code            => l_event_type_code
88395       ,p_line_definition_owner_code => l_line_definition_owner_code
88396       ,p_line_definition_code       => l_line_definition_code
88397       ,p_accounting_line_code       => l_component_code
88398       ,p_accounting_line_type_code  => l_component_type_code
88399       ,p_accounting_line_appl_id    => l_component_appl_id
88400       ,p_amb_context_code           => l_amb_context_code
88401       ,p_entity_code                => l_entity_code
88402       ,p_event_class_code           => l_event_class_code);
88403    --
88404    -- set accounting class
88405    --
88406    xla_ae_lines_pkg.SetAcctClass(
88407            p_accounting_class_code  => 'ASSET'
88408          , p_ae_header_id           => l_ae_header_id
88409          );
88410 
88411    --
88412    -- set rounding class
88413    --
88414    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
88415                       'ASSET';
88416 
88417    --
88421    -- bulk performance
88418    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
88419    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
88420    --
88422    --
88423    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
88424 
88425    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
88426       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
88427 
88428    -- 4955764
88429    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
88430       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
88431 
88432    -- 4458381 Public Sector Enh
88433    
88434    --
88435    -- set accounting attributes for the line type
88436    --
88437    l_entered_amt_idx := 4;
88438    l_accted_amt_idx  := 6;
88439    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
88440    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
88441    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
88442    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
88443    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
88444    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
88445    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
88446    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
88447    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
88448    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
88449    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
88450    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
88451    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
88452 
88453    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
88454    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
88455 
88456    ---------------------------------------------------------------------------------------------------------------
88457    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
88458    ---------------------------------------------------------------------------------------------------------------
88459    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
88460 
88461    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
88462    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
88463 
88464    IF xla_accounting_cache_pkg.GetValueChar
88465          (p_source_code         => 'LEDGER_CATEGORY_CODE'
88466          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
88467    AND l_bflow_method_code = 'PRIOR_ENTRY'
88468 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
88469    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
88470          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
88471        )
88472    THEN
88473          xla_ae_lines_pkg.BflowUpgEntry
88474            (p_business_method_code    => l_bflow_method_code
88475            ,p_business_class_code     => l_bflow_class_code
88476            ,p_balance_type            => l_balance_type_code);
88477    ELSE
88478       NULL;
88479 -- No business flow processing for business flow method of NONE.
88480    END IF;
88481 
88482    --
88483    -- call analytical criteria
88484    --
88485    
88486    --
88487    -- call description
88488    --
88489    
88490 xla_ae_lines_pkg.SetLineDescription(
88491    p_ae_header_id => l_ae_header_id
88492   ,p_description  => Description_81 (
88493      p_application_id         => p_application_id
88494    , p_ae_header_id           => l_ae_header_id 
88495 , p_source_1 => p_source_1
88496    )
88497 );
88498 
88499 
88500    --
88501    -- call ADRs
88502    -- Bug 4922099
88503    --
88504    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
88505         (NVL(l_actual_upg_option, 'N') = 'O') OR
88506         (NVL(l_enc_upg_option, 'N') = 'O')
88507       )
88508    THEN
88509    NULL;
88510    --
88511    --
88512    
88513   l_ccid := AcctDerRule_173(
88514            p_application_id           => p_application_id
88515          , p_ae_header_id             => l_ae_header_id 
88516 , p_source_3 => p_source_3
88517 , p_source_30 => p_source_30
88518          , x_transaction_coa_id       => l_adr_transaction_coa_id
88519          , x_accounting_coa_id        => l_adr_accounting_coa_id
88520          , x_value_type_code          => l_adr_value_type_code
88521          , p_side                     => 'NA'
88522    );
88523 
88524    xla_ae_lines_pkg.set_ccid(
88525     p_code_combination_id          => l_ccid
88526   , p_value_type_code              => l_adr_value_type_code
88527   , p_transaction_coa_id           => l_adr_transaction_coa_id
88528   , p_accounting_coa_id            => l_adr_accounting_coa_id
88529   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
88530   , p_adr_type_code                => 'S'
88531   , p_component_type               => l_component_type
88532   , p_component_code               => l_component_code
88533   , p_component_type_code          => l_component_type_code
88534   , p_component_appl_id            => l_component_appl_id
88535   , p_amb_context_code             => l_amb_context_code
88536   , p_side                         => 'NA'
88537   );
88538 
88539 
88540    l_segment := AcctDerRule_168(
88541            p_application_id           => p_application_id
88542          , p_ae_header_id             => l_ae_header_id 
88543 , p_source_3 => p_source_3
88544 , p_source_29 => p_source_29
88548          , x_flex_value_set_id        => l_adr_flex_value_set_id
88545          , x_transaction_coa_id       => l_adr_transaction_coa_id
88546          , x_accounting_coa_id        => l_adr_accounting_coa_id
88547          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
88549          , x_value_type_code          => l_adr_value_type_code
88550          , x_value_combination_id     => l_adr_value_combination_id
88551          , x_value_segment_code       => l_adr_value_segment_code
88552          , p_side                     => 'NA'
88553          , p_override_seg_flag        => 'Y'
88554    );
88555 
88556    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
88557 
88558       xla_ae_lines_pkg.set_segment(
88559           p_to_segment_code         => 'GL_BALANCING'
88560         , p_segment_value           => l_segment
88561         , p_from_segment_code       => l_adr_value_segment_code
88562         , p_from_combination_id     => l_adr_value_combination_id
88563         , p_value_type_code         => l_adr_value_type_code
88564         , p_transaction_coa_id      => l_adr_transaction_coa_id
88565         , p_accounting_coa_id       => l_adr_accounting_coa_id
88566         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
88567         , p_flex_value_set_id       => l_adr_flex_value_set_id
88568         , p_adr_code                => 'FA_EXPENSE_ACCT'
88569         , p_adr_type_code           => 'S'
88570         , p_component_type          => l_component_type
88571         , p_component_code          => l_component_code
88572         , p_component_type_code     => l_component_type_code
88573         , p_component_appl_id       => l_component_appl_id
88574         , p_amb_context_code        => l_amb_context_code
88575         , p_entity_code             => 'TRANSACTIONS'
88576         , p_event_class_code        => 'RETIREMENTS'
88577         , p_side                    => 'NA'
88578         );
88579 
88580   END IF;
88581 
88582    l_segment := AcctDerRule_163(
88583            p_application_id           => p_application_id
88584          , p_ae_header_id             => l_ae_header_id 
88585 , p_source_3 => p_source_3
88586 , p_source_25 => p_source_25
88587          , x_transaction_coa_id       => l_adr_transaction_coa_id
88588          , x_accounting_coa_id        => l_adr_accounting_coa_id
88589          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
88590          , x_flex_value_set_id        => l_adr_flex_value_set_id
88591          , x_value_type_code          => l_adr_value_type_code
88592          , x_value_combination_id     => l_adr_value_combination_id
88593          , x_value_segment_code       => l_adr_value_segment_code
88594          , p_side                     => 'NA'
88595          , p_override_seg_flag        => 'Y'
88596    );
88597 
88598    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
88599 
88600       xla_ae_lines_pkg.set_segment(
88601           p_to_segment_code         => 'GL_ACCOUNT'
88602         , p_segment_value           => l_segment
88603         , p_from_segment_code       => l_adr_value_segment_code
88604         , p_from_combination_id     => l_adr_value_combination_id
88605         , p_value_type_code         => l_adr_value_type_code
88606         , p_transaction_coa_id      => l_adr_transaction_coa_id
88607         , p_accounting_coa_id       => l_adr_accounting_coa_id
88608         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
88609         , p_flex_value_set_id       => l_adr_flex_value_set_id
88610         , p_adr_code                => 'FA_PROC_OF_SALE_LOSS_SEGMENT'
88611         , p_adr_type_code           => 'S'
88612         , p_component_type          => l_component_type
88613         , p_component_code          => l_component_code
88614         , p_component_type_code     => l_component_type_code
88615         , p_component_appl_id       => l_component_appl_id
88616         , p_amb_context_code        => l_amb_context_code
88617         , p_entity_code             => 'TRANSACTIONS'
88618         , p_event_class_code        => 'RETIREMENTS'
88619         , p_side                    => 'NA'
88620         );
88621 
88622   END IF;
88623 
88624    --
88625    --
88626    END IF;
88627    --
88628    -- Bug 4922099
88629    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
88630           (NVL(l_enc_upg_option, 'N') = 'O')
88631         ) AND
88632         (l_bflow_method_code = 'PRIOR_ENTRY')
88633       )
88634    THEN
88635       IF
88636       --
88637       1 = 2
88638       --
88639       THEN
88640       xla_accounting_err_pkg.build_message
88641                                     (p_appli_s_name            => 'XLA'
88642                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
88643                                     ,p_token_1                 => 'LINE_NUMBER'
88644                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
88645                                     ,p_token_2                 => 'LINE_TYPE_NAME'
88646                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
88647                                                                              l_component_type
88648                                                                             ,l_component_code
88649                                                                             ,l_component_type_code
88650                                                                             ,l_component_appl_id
88651                                                                             ,l_amb_context_code
88652                                                                             ,l_entity_code
88653                                                                             ,l_event_class_code
88654                                                                            )
88655                                     ,p_token_3                 => 'OWNER'
88659                                                                          )
88656                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
88657                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
88658                                                                           ,p_lookup_code    => l_component_type_code
88660                                     ,p_token_4                 => 'PRODUCT_NAME'
88661                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
88662                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
88663                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
88664                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
88665                                     ,p_ae_header_id            =>  NULL
88666                                        );
88667 
88668         IF (C_LEVEL_ERROR>= g_log_level) THEN
88669                  trace
88670                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
88671                       ,p_level    => C_LEVEL_ERROR
88672                       ,p_module   => l_log_module);
88673         END IF;
88674       END IF;
88675    END IF;
88676    --
88677    --
88678    ------------------------------------------------------------------------------------------------
88679    -- 4219869 Business Flow
88680    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
88681    -- Prior Entry.  Currently, the following code is always generated.
88682    ------------------------------------------------------------------------------------------------
88683    XLA_AE_LINES_PKG.ValidateCurrentLine;
88684 
88685    ------------------------------------------------------------------------------------
88686    -- 4219869 Business Flow
88687    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
88688    ------------------------------------------------------------------------------------
88689    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
88690 
88691    ----------------------------------------------------------------------------------
88692    -- 4219869 Business Flow
88693    -- Update journal entry status -- Need to generate this within IF <condition>
88694    ----------------------------------------------------------------------------------
88695    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
88696          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
88697          ,p_balance_type_code => l_balance_type_code
88698          );
88699 
88700    -------------------------------------------------------------------------------------------
88701    -- 4262811 - Generate the Accrual Reversal lines
88702    -------------------------------------------------------------------------------------------
88703    BEGIN
88704       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
88705                               (g_array_event(p_event_id).array_value_num('header_index'));
88706       IF l_acc_rev_flag IS NULL THEN
88707          l_acc_rev_flag := 'N';
88708       END IF;
88709    EXCEPTION
88710       WHEN OTHERS THEN
88711          l_acc_rev_flag := 'N';
88712    END;
88713    --
88714    IF (l_acc_rev_flag = 'Y') THEN
88715 
88716        -- 4645092  ------------------------------------------------------------------------------
88717        -- To allow MPA report to determine if it should generate report process
88718        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
88719        ------------------------------------------------------------------------------------------
88720 
88721        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
88722        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
88723    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
88724    -- call ADRs
88725    -- Bug 4922099
88726    --
88727    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
88728         (NVL(l_actual_upg_option, 'N') = 'O') OR
88729         (NVL(l_enc_upg_option, 'N') = 'O')
88730       )
88731    THEN
88732    NULL;
88733    --
88734    --
88735    
88736   l_ccid := AcctDerRule_173(
88737            p_application_id           => p_application_id
88738          , p_ae_header_id             => l_ae_header_id 
88739 , p_source_3 => p_source_3
88740 , p_source_30 => p_source_30
88741          , x_transaction_coa_id       => l_adr_transaction_coa_id
88742          , x_accounting_coa_id        => l_adr_accounting_coa_id
88743          , x_value_type_code          => l_adr_value_type_code
88744          , p_side                     => 'NA'
88745    );
88746 
88747    xla_ae_lines_pkg.set_ccid(
88748     p_code_combination_id          => l_ccid
88749   , p_value_type_code              => l_adr_value_type_code
88750   , p_transaction_coa_id           => l_adr_transaction_coa_id
88751   , p_accounting_coa_id            => l_adr_accounting_coa_id
88752   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
88753   , p_adr_type_code                => 'S'
88754   , p_component_type               => l_component_type
88755   , p_component_code               => l_component_code
88756   , p_component_type_code          => l_component_type_code
88757   , p_component_appl_id            => l_component_appl_id
88758   , p_amb_context_code             => l_amb_context_code
88759   , p_side                         => 'NA'
88760   );
88761 
88762 
88763    l_segment := AcctDerRule_168(
88764            p_application_id           => p_application_id
88765          , p_ae_header_id             => l_ae_header_id 
88766 , p_source_3 => p_source_3
88767 , p_source_29 => p_source_29
88768          , x_transaction_coa_id       => l_adr_transaction_coa_id
88772          , x_value_type_code          => l_adr_value_type_code
88769          , x_accounting_coa_id        => l_adr_accounting_coa_id
88770          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
88771          , x_flex_value_set_id        => l_adr_flex_value_set_id
88773          , x_value_combination_id     => l_adr_value_combination_id
88774          , x_value_segment_code       => l_adr_value_segment_code
88775          , p_side                     => 'NA'
88776          , p_override_seg_flag        => 'Y'
88777    );
88778 
88779    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
88780 
88781       xla_ae_lines_pkg.set_segment(
88782           p_to_segment_code         => 'GL_BALANCING'
88783         , p_segment_value           => l_segment
88784         , p_from_segment_code       => l_adr_value_segment_code
88785         , p_from_combination_id     => l_adr_value_combination_id
88786         , p_value_type_code         => l_adr_value_type_code
88787         , p_transaction_coa_id      => l_adr_transaction_coa_id
88788         , p_accounting_coa_id       => l_adr_accounting_coa_id
88789         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
88790         , p_flex_value_set_id       => l_adr_flex_value_set_id
88791         , p_adr_code                => 'FA_EXPENSE_ACCT'
88792         , p_adr_type_code           => 'S'
88793         , p_component_type          => l_component_type
88794         , p_component_code          => l_component_code
88795         , p_component_type_code     => l_component_type_code
88796         , p_component_appl_id       => l_component_appl_id
88797         , p_amb_context_code        => l_amb_context_code
88798         , p_entity_code             => 'TRANSACTIONS'
88799         , p_event_class_code        => 'RETIREMENTS'
88800         , p_side                    => 'NA'
88801         );
88802 
88803   END IF;
88804 
88805    l_segment := AcctDerRule_163(
88806            p_application_id           => p_application_id
88807          , p_ae_header_id             => l_ae_header_id 
88808 , p_source_3 => p_source_3
88809 , p_source_25 => p_source_25
88810          , x_transaction_coa_id       => l_adr_transaction_coa_id
88811          , x_accounting_coa_id        => l_adr_accounting_coa_id
88812          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
88813          , x_flex_value_set_id        => l_adr_flex_value_set_id
88814          , x_value_type_code          => l_adr_value_type_code
88815          , x_value_combination_id     => l_adr_value_combination_id
88816          , x_value_segment_code       => l_adr_value_segment_code
88817          , p_side                     => 'NA'
88818          , p_override_seg_flag        => 'Y'
88819    );
88820 
88821    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
88822 
88823       xla_ae_lines_pkg.set_segment(
88824           p_to_segment_code         => 'GL_ACCOUNT'
88825         , p_segment_value           => l_segment
88826         , p_from_segment_code       => l_adr_value_segment_code
88827         , p_from_combination_id     => l_adr_value_combination_id
88828         , p_value_type_code         => l_adr_value_type_code
88829         , p_transaction_coa_id      => l_adr_transaction_coa_id
88830         , p_accounting_coa_id       => l_adr_accounting_coa_id
88831         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
88832         , p_flex_value_set_id       => l_adr_flex_value_set_id
88833         , p_adr_code                => 'FA_PROC_OF_SALE_LOSS_SEGMENT'
88834         , p_adr_type_code           => 'S'
88835         , p_component_type          => l_component_type
88836         , p_component_code          => l_component_code
88837         , p_component_type_code     => l_component_type_code
88838         , p_component_appl_id       => l_component_appl_id
88839         , p_amb_context_code        => l_amb_context_code
88840         , p_entity_code             => 'TRANSACTIONS'
88841         , p_event_class_code        => 'RETIREMENTS'
88842         , p_side                    => 'NA'
88843         );
88844 
88845   END IF;
88846 
88847    --
88848    --
88849    END IF;
88850 
88851        --
88852        -- Update the line information that should be overwritten
88853        --
88854        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
88855                                          p_header_num   => 1);
88856        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
88857 
88858        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
88859 
88860        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
88861           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
88862        END IF;
88863 
88864       --
88865       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
88866       --
88867       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
88868           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
88869       ELSE
88870           ---------------------------------------------------------------------------------------------------
88871           -- 4262811a Switch Sign
88872           ---------------------------------------------------------------------------------------------------
88873           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
88874           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
88875                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
88876           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
88877                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
88878           -- 5132302
88882       END IF;
88879           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
88880                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
88881 
88883 
88884       -- 4955764
88885       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
88886       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
88887 
88888 
88889       XLA_AE_LINES_PKG.ValidateCurrentLine;
88890       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
88891 
88892       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
88893                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
88894                ,p_balance_type_code => l_balance_type_code);
88895 
88896    END IF;
88897 
88898    -----------------------------------------------------------------------------------------
88899    -- 4262811 Multiperiod Accounting
88900    -----------------------------------------------------------------------------------------
88901      -- No MPA option is assigned.
88902 
88903 
88904 END IF;
88905 END IF;
88906 --
88907 
88908 --
88909 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
88910    trace
88911       (p_msg      => 'END of AcctLineType_277'
88912       ,p_level    => C_LEVEL_PROCEDURE
88913       ,p_module   => l_log_module);
88914 END IF;
88915 --
88916 EXCEPTION
88917   WHEN xla_exceptions_pkg.application_exception THEN
88918       RAISE;
88919   WHEN OTHERS THEN
88920        xla_exceptions_pkg.raise_message
88921            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_277');
88922 END AcctLineType_277;
88923 --
88924 
88925 ---------------------------------------
88926 --
88927 -- PRIVATE FUNCTION
88928 --         AcctLineType_278
88929 --
88930 ---------------------------------------
88931 PROCEDURE AcctLineType_278 (
88932   p_application_id        IN NUMBER
88933  ,p_event_id              IN NUMBER
88934  ,p_calculate_acctd_flag  IN VARCHAR2
88935  ,p_calculate_g_l_flag    IN VARCHAR2
88936  ,p_actual_flag           IN OUT VARCHAR2
88937  ,p_balance_type_code     OUT VARCHAR2
88938  ,p_gain_or_loss_ref      OUT VARCHAR2
88939  
88940 --Period Close Date
88941  , p_source_1            IN DATE
88942 --Generated Code Combination Identifier
88943  , p_source_3            IN NUMBER
88944 --Proceeds Of Sale Loss Account
88945  , p_source_25            IN VARCHAR2
88946 --Expense Account Code Combination Identifier
88947  , p_source_29            IN NUMBER
88948 --Default Code Combination Identifier
88949  , p_source_30            IN NUMBER
88950 --Adjustment Type
88951  , p_source_35            IN VARCHAR2
88952 --Transaction Header Identifier
88953  , p_source_36            IN NUMBER
88954 --Adjustment Line Identifier
88955  , p_source_37            IN NUMBER
88956 --Distribution Type Code
88957  , p_source_38            IN VARCHAR2
88958 --Entered Amount
88959  , p_source_39            IN NUMBER
88960 --Currency Code
88961  , p_source_40            IN VARCHAR2
88962 --Gain Loss Amount
88963  , p_source_41            IN NUMBER
88964 )
88965 IS
88966 
88967 l_component_type              VARCHAR2(80);
88968 l_component_code              VARCHAR2(30);
88969 l_component_type_code         VARCHAR2(1);
88970 l_component_appl_id           INTEGER;
88971 l_amb_context_code            VARCHAR2(30);
88972 l_entity_code                 VARCHAR2(30);
88973 l_event_class_code            VARCHAR2(30);
88974 l_ae_header_id                NUMBER;
88975 l_event_type_code             VARCHAR2(30);
88976 l_line_definition_code        VARCHAR2(30);
88977 l_line_definition_owner_code  VARCHAR2(1);
88978 --
88979 -- adr variables
88980 l_segment                     VARCHAR2(30);
88981 l_ccid                        NUMBER;
88982 l_adr_transaction_coa_id      NUMBER;
88983 l_adr_accounting_coa_id       NUMBER;
88984 l_adr_flexfield_segment_code  VARCHAR2(30);
88985 l_adr_flex_value_set_id       NUMBER;
88986 l_adr_value_type_code         VARCHAR2(30);
88987 l_adr_value_combination_id    NUMBER;
88988 l_adr_value_segment_code      VARCHAR2(30);
88989 
88990 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
88991 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
88992 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
88993 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
88994 
88995 -- 4262811 Variables ------------------------------------------------------------------------------------------
88996 l_entered_amt_idx             NUMBER;
88997 l_accted_amt_idx              NUMBER;
88998 l_acc_rev_flag                VARCHAR2(1);
88999 l_accrual_line_num            NUMBER;
89000 l_tmp_amt                     NUMBER;
89001 l_acc_rev_natural_side_code   VARCHAR2(1);
89002 
89003 l_num_entries                 NUMBER;
89004 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
89005 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
89006 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
89007 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
89008 l_recog_line_1                NUMBER;
89009 l_recog_line_2                NUMBER;
89010 
89011 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
89012 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
89013 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
89014 
89015 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
89016 
89017 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
89021 
89018 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
89019 
89020 ---------------------------------------------------------------------------------------------------------------
89022 
89023 --
89024 -- bulk performance
89025 --
89026 l_balance_type_code           VARCHAR2(1);
89027 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
89028 l_log_module                  VARCHAR2(240);
89029 
89030 --
89031 -- Upgrade strategy
89032 --
89033 l_actual_upg_option           VARCHAR2(1);
89034 l_enc_upg_option           VARCHAR2(1);
89035 
89036 --
89037 BEGIN
89038 --
89039 IF g_log_enabled THEN
89040       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_278';
89041 END IF;
89042 --
89043 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
89044 
89045       trace
89046          (p_msg      => 'BEGIN of AcctLineType_278'
89047          ,p_level    => C_LEVEL_PROCEDURE
89048          ,p_module   => l_log_module);
89049 
89050 END IF;
89051 --
89052 l_component_type             := 'AMB_JLT';
89053 l_component_code             := 'FA_PROC_OF_SALE_LOSS';
89054 l_component_type_code        := 'S';
89055 l_component_appl_id          :=  140;
89056 l_amb_context_code           := 'DEFAULT';
89057 l_entity_code                := 'TRANSACTIONS';
89058 l_event_class_code           := 'RETIREMENTS';
89059 l_event_type_code            := 'REINSTATEMENTS';
89060 l_line_definition_owner_code := 'S';
89061 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
89062 --
89063 l_balance_type_code          := 'A';
89064 l_segment                     := NULL;
89065 l_ccid                        := NULL;
89066 l_adr_transaction_coa_id      := NULL;
89067 l_adr_accounting_coa_id       := NULL;
89068 l_adr_flexfield_segment_code  := NULL;
89069 l_adr_flex_value_set_id       := NULL;
89070 l_adr_value_type_code         := NULL;
89071 l_adr_value_combination_id    := NULL;
89072 l_adr_value_segment_code      := NULL;
89073 
89074 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
89075 l_bflow_class_code           := '';    -- 4219869 Business Flow
89076 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
89077 l_budgetary_control_flag     := 'N';
89078 
89079 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
89080 l_bflow_applied_to_amt       := NULL; -- 5132302
89081 l_entered_amt_idx            := NULL;          -- 4262811
89082 l_accted_amt_idx             := NULL;          -- 4262811
89083 l_acc_rev_flag               := NULL;          -- 4262811
89084 l_accrual_line_num           := NULL;          -- 4262811
89085 l_tmp_amt                    := NULL;          -- 4262811
89086 --
89087  
89088 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
89089     l_balance_type_code <> 'B' THEN
89090 IF NVL(p_source_35,'
89091 ') =  'PROCEEDS' AND 
89092 p_source_41 <  0
89093  THEN 
89094 
89095    --
89096    XLA_AE_LINES_PKG.SetNewLine;
89097 
89098    p_balance_type_code          := l_balance_type_code;
89099    -- set the flag so later we will know whether the gain loss line needs to be created
89100    
89101    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
89102      p_actual_flag :='A';
89103    END IF;
89104 
89105    --
89106    -- bulk performance
89107    --
89108    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
89109                                       p_header_num   => 0); -- 4262811
89110    --
89111    -- set accounting line options
89112    --
89113    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
89114            p_natural_side_code          => 'C'
89115          , p_gain_or_loss_flag          => 'N'
89116          , p_gl_transfer_mode_code      => 'S'
89117          , p_acct_entry_type_code       => 'A'
89118          , p_switch_side_flag           => 'Y'
89119          , p_merge_duplicate_code       => 'N'
89120          );
89121    --
89122    l_acc_rev_natural_side_code := 'D';  -- 4262811
89123    -- 
89124    --
89125    -- set accounting line type info
89126    --
89127    xla_ae_lines_pkg.SetAcctLineType
89128       (p_component_type             => l_component_type
89129       ,p_event_type_code            => l_event_type_code
89130       ,p_line_definition_owner_code => l_line_definition_owner_code
89131       ,p_line_definition_code       => l_line_definition_code
89132       ,p_accounting_line_code       => l_component_code
89133       ,p_accounting_line_type_code  => l_component_type_code
89134       ,p_accounting_line_appl_id    => l_component_appl_id
89135       ,p_amb_context_code           => l_amb_context_code
89136       ,p_entity_code                => l_entity_code
89137       ,p_event_class_code           => l_event_class_code);
89138    --
89139    -- set accounting class
89140    --
89141    xla_ae_lines_pkg.SetAcctClass(
89142            p_accounting_class_code  => 'ASSET'
89143          , p_ae_header_id           => l_ae_header_id
89144          );
89145 
89146    --
89147    -- set rounding class
89148    --
89149    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
89150                       'ASSET';
89151 
89152    --
89153    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
89154    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
89155    --
89156    -- bulk performance
89157    --
89158    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
89159 
89160    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
89161       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
89162 
89166 
89163    -- 4955764
89164    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
89165       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
89167    -- 4458381 Public Sector Enh
89168    
89169    --
89170    -- set accounting attributes for the line type
89171    --
89172    l_entered_amt_idx := 4;
89173    l_accted_amt_idx  := 6;
89174    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
89175    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
89176    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
89177    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
89178    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
89179    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
89180    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
89181    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
89182    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
89183    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
89184    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
89185    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
89186    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
89187 
89188    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
89189    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
89190 
89191    ---------------------------------------------------------------------------------------------------------------
89192    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
89193    ---------------------------------------------------------------------------------------------------------------
89194    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
89195 
89196    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
89197    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
89198 
89199    IF xla_accounting_cache_pkg.GetValueChar
89200          (p_source_code         => 'LEDGER_CATEGORY_CODE'
89201          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
89202    AND l_bflow_method_code = 'PRIOR_ENTRY'
89203 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
89204    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
89205          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
89206        )
89207    THEN
89208          xla_ae_lines_pkg.BflowUpgEntry
89209            (p_business_method_code    => l_bflow_method_code
89210            ,p_business_class_code     => l_bflow_class_code
89211            ,p_balance_type            => l_balance_type_code);
89212    ELSE
89213       NULL;
89214 -- No business flow processing for business flow method of NONE.
89215    END IF;
89216 
89217    --
89218    -- call analytical criteria
89219    --
89220    
89221    --
89222    -- call description
89223    --
89224    
89225 xla_ae_lines_pkg.SetLineDescription(
89226    p_ae_header_id => l_ae_header_id
89227   ,p_description  => Description_81 (
89228      p_application_id         => p_application_id
89229    , p_ae_header_id           => l_ae_header_id 
89230 , p_source_1 => p_source_1
89231    )
89232 );
89233 
89234 
89235    --
89236    -- call ADRs
89237    -- Bug 4922099
89238    --
89239    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
89240         (NVL(l_actual_upg_option, 'N') = 'O') OR
89241         (NVL(l_enc_upg_option, 'N') = 'O')
89242       )
89243    THEN
89244    NULL;
89245    --
89246    --
89247    
89248   l_ccid := AcctDerRule_173(
89249            p_application_id           => p_application_id
89250          , p_ae_header_id             => l_ae_header_id 
89251 , p_source_3 => p_source_3
89252 , p_source_30 => p_source_30
89253          , x_transaction_coa_id       => l_adr_transaction_coa_id
89254          , x_accounting_coa_id        => l_adr_accounting_coa_id
89255          , x_value_type_code          => l_adr_value_type_code
89256          , p_side                     => 'NA'
89257    );
89258 
89259    xla_ae_lines_pkg.set_ccid(
89260     p_code_combination_id          => l_ccid
89261   , p_value_type_code              => l_adr_value_type_code
89262   , p_transaction_coa_id           => l_adr_transaction_coa_id
89263   , p_accounting_coa_id            => l_adr_accounting_coa_id
89264   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
89265   , p_adr_type_code                => 'S'
89266   , p_component_type               => l_component_type
89267   , p_component_code               => l_component_code
89268   , p_component_type_code          => l_component_type_code
89269   , p_component_appl_id            => l_component_appl_id
89270   , p_amb_context_code             => l_amb_context_code
89271   , p_side                         => 'NA'
89272   );
89273 
89274 
89275    l_segment := AcctDerRule_168(
89276            p_application_id           => p_application_id
89277          , p_ae_header_id             => l_ae_header_id 
89278 , p_source_3 => p_source_3
89279 , p_source_29 => p_source_29
89280          , x_transaction_coa_id       => l_adr_transaction_coa_id
89281          , x_accounting_coa_id        => l_adr_accounting_coa_id
89282          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
89283          , x_flex_value_set_id        => l_adr_flex_value_set_id
89284          , x_value_type_code          => l_adr_value_type_code
89285          , x_value_combination_id     => l_adr_value_combination_id
89286          , x_value_segment_code       => l_adr_value_segment_code
89287          , p_side                     => 'NA'
89291    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
89288          , p_override_seg_flag        => 'Y'
89289    );
89290 
89292 
89293       xla_ae_lines_pkg.set_segment(
89294           p_to_segment_code         => 'GL_BALANCING'
89295         , p_segment_value           => l_segment
89296         , p_from_segment_code       => l_adr_value_segment_code
89297         , p_from_combination_id     => l_adr_value_combination_id
89298         , p_value_type_code         => l_adr_value_type_code
89299         , p_transaction_coa_id      => l_adr_transaction_coa_id
89300         , p_accounting_coa_id       => l_adr_accounting_coa_id
89301         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
89302         , p_flex_value_set_id       => l_adr_flex_value_set_id
89303         , p_adr_code                => 'FA_EXPENSE_ACCT'
89304         , p_adr_type_code           => 'S'
89305         , p_component_type          => l_component_type
89306         , p_component_code          => l_component_code
89307         , p_component_type_code     => l_component_type_code
89308         , p_component_appl_id       => l_component_appl_id
89309         , p_amb_context_code        => l_amb_context_code
89310         , p_entity_code             => 'TRANSACTIONS'
89311         , p_event_class_code        => 'RETIREMENTS'
89312         , p_side                    => 'NA'
89313         );
89314 
89315   END IF;
89316 
89317    l_segment := AcctDerRule_163(
89318            p_application_id           => p_application_id
89319          , p_ae_header_id             => l_ae_header_id 
89320 , p_source_3 => p_source_3
89321 , p_source_25 => p_source_25
89322          , x_transaction_coa_id       => l_adr_transaction_coa_id
89323          , x_accounting_coa_id        => l_adr_accounting_coa_id
89324          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
89325          , x_flex_value_set_id        => l_adr_flex_value_set_id
89326          , x_value_type_code          => l_adr_value_type_code
89327          , x_value_combination_id     => l_adr_value_combination_id
89328          , x_value_segment_code       => l_adr_value_segment_code
89329          , p_side                     => 'NA'
89330          , p_override_seg_flag        => 'Y'
89331    );
89332 
89333    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
89334 
89335       xla_ae_lines_pkg.set_segment(
89336           p_to_segment_code         => 'GL_ACCOUNT'
89337         , p_segment_value           => l_segment
89338         , p_from_segment_code       => l_adr_value_segment_code
89339         , p_from_combination_id     => l_adr_value_combination_id
89340         , p_value_type_code         => l_adr_value_type_code
89341         , p_transaction_coa_id      => l_adr_transaction_coa_id
89342         , p_accounting_coa_id       => l_adr_accounting_coa_id
89343         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
89344         , p_flex_value_set_id       => l_adr_flex_value_set_id
89345         , p_adr_code                => 'FA_PROC_OF_SALE_LOSS_SEGMENT'
89346         , p_adr_type_code           => 'S'
89347         , p_component_type          => l_component_type
89348         , p_component_code          => l_component_code
89349         , p_component_type_code     => l_component_type_code
89350         , p_component_appl_id       => l_component_appl_id
89351         , p_amb_context_code        => l_amb_context_code
89352         , p_entity_code             => 'TRANSACTIONS'
89353         , p_event_class_code        => 'RETIREMENTS'
89354         , p_side                    => 'NA'
89355         );
89356 
89357   END IF;
89358 
89359    --
89360    --
89361    END IF;
89362    --
89363    -- Bug 4922099
89364    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
89365           (NVL(l_enc_upg_option, 'N') = 'O')
89366         ) AND
89367         (l_bflow_method_code = 'PRIOR_ENTRY')
89368       )
89369    THEN
89370       IF
89371       --
89372       1 = 2
89373       --
89374       THEN
89375       xla_accounting_err_pkg.build_message
89376                                     (p_appli_s_name            => 'XLA'
89377                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
89378                                     ,p_token_1                 => 'LINE_NUMBER'
89379                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
89380                                     ,p_token_2                 => 'LINE_TYPE_NAME'
89381                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
89382                                                                              l_component_type
89383                                                                             ,l_component_code
89384                                                                             ,l_component_type_code
89385                                                                             ,l_component_appl_id
89386                                                                             ,l_amb_context_code
89387                                                                             ,l_entity_code
89388                                                                             ,l_event_class_code
89389                                                                            )
89390                                     ,p_token_3                 => 'OWNER'
89391                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
89392                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
89393                                                                           ,p_lookup_code    => l_component_type_code
89394                                                                          )
89395                                     ,p_token_4                 => 'PRODUCT_NAME'
89396                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
89400                                     ,p_ae_header_id            =>  NULL
89397                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
89398                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
89399                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
89401                                        );
89402 
89403         IF (C_LEVEL_ERROR>= g_log_level) THEN
89404                  trace
89405                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
89406                       ,p_level    => C_LEVEL_ERROR
89407                       ,p_module   => l_log_module);
89408         END IF;
89409       END IF;
89410    END IF;
89411    --
89412    --
89413    ------------------------------------------------------------------------------------------------
89414    -- 4219869 Business Flow
89415    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
89416    -- Prior Entry.  Currently, the following code is always generated.
89417    ------------------------------------------------------------------------------------------------
89418    XLA_AE_LINES_PKG.ValidateCurrentLine;
89419 
89420    ------------------------------------------------------------------------------------
89421    -- 4219869 Business Flow
89422    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
89423    ------------------------------------------------------------------------------------
89424    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
89425 
89426    ----------------------------------------------------------------------------------
89427    -- 4219869 Business Flow
89428    -- Update journal entry status -- Need to generate this within IF <condition>
89429    ----------------------------------------------------------------------------------
89430    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
89431          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
89432          ,p_balance_type_code => l_balance_type_code
89433          );
89434 
89435    -------------------------------------------------------------------------------------------
89436    -- 4262811 - Generate the Accrual Reversal lines
89437    -------------------------------------------------------------------------------------------
89438    BEGIN
89439       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
89440                               (g_array_event(p_event_id).array_value_num('header_index'));
89441       IF l_acc_rev_flag IS NULL THEN
89442          l_acc_rev_flag := 'N';
89443       END IF;
89444    EXCEPTION
89445       WHEN OTHERS THEN
89446          l_acc_rev_flag := 'N';
89447    END;
89448    --
89449    IF (l_acc_rev_flag = 'Y') THEN
89450 
89451        -- 4645092  ------------------------------------------------------------------------------
89452        -- To allow MPA report to determine if it should generate report process
89453        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
89454        ------------------------------------------------------------------------------------------
89455 
89456        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
89457        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
89458    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
89459    -- call ADRs
89460    -- Bug 4922099
89461    --
89462    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
89463         (NVL(l_actual_upg_option, 'N') = 'O') OR
89464         (NVL(l_enc_upg_option, 'N') = 'O')
89465       )
89466    THEN
89467    NULL;
89468    --
89469    --
89470    
89471   l_ccid := AcctDerRule_173(
89472            p_application_id           => p_application_id
89473          , p_ae_header_id             => l_ae_header_id 
89474 , p_source_3 => p_source_3
89475 , p_source_30 => p_source_30
89476          , x_transaction_coa_id       => l_adr_transaction_coa_id
89477          , x_accounting_coa_id        => l_adr_accounting_coa_id
89478          , x_value_type_code          => l_adr_value_type_code
89479          , p_side                     => 'NA'
89480    );
89481 
89482    xla_ae_lines_pkg.set_ccid(
89483     p_code_combination_id          => l_ccid
89484   , p_value_type_code              => l_adr_value_type_code
89485   , p_transaction_coa_id           => l_adr_transaction_coa_id
89486   , p_accounting_coa_id            => l_adr_accounting_coa_id
89487   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
89488   , p_adr_type_code                => 'S'
89489   , p_component_type               => l_component_type
89490   , p_component_code               => l_component_code
89491   , p_component_type_code          => l_component_type_code
89492   , p_component_appl_id            => l_component_appl_id
89493   , p_amb_context_code             => l_amb_context_code
89494   , p_side                         => 'NA'
89495   );
89496 
89497 
89498    l_segment := AcctDerRule_168(
89499            p_application_id           => p_application_id
89500          , p_ae_header_id             => l_ae_header_id 
89501 , p_source_3 => p_source_3
89502 , p_source_29 => p_source_29
89503          , x_transaction_coa_id       => l_adr_transaction_coa_id
89504          , x_accounting_coa_id        => l_adr_accounting_coa_id
89505          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
89506          , x_flex_value_set_id        => l_adr_flex_value_set_id
89507          , x_value_type_code          => l_adr_value_type_code
89508          , x_value_combination_id     => l_adr_value_combination_id
89509          , x_value_segment_code       => l_adr_value_segment_code
89510          , p_side                     => 'NA'
89511          , p_override_seg_flag        => 'Y'
89512    );
89513 
89514    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
89518         , p_segment_value           => l_segment
89515 
89516       xla_ae_lines_pkg.set_segment(
89517           p_to_segment_code         => 'GL_BALANCING'
89519         , p_from_segment_code       => l_adr_value_segment_code
89520         , p_from_combination_id     => l_adr_value_combination_id
89521         , p_value_type_code         => l_adr_value_type_code
89522         , p_transaction_coa_id      => l_adr_transaction_coa_id
89523         , p_accounting_coa_id       => l_adr_accounting_coa_id
89524         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
89525         , p_flex_value_set_id       => l_adr_flex_value_set_id
89526         , p_adr_code                => 'FA_EXPENSE_ACCT'
89527         , p_adr_type_code           => 'S'
89528         , p_component_type          => l_component_type
89529         , p_component_code          => l_component_code
89530         , p_component_type_code     => l_component_type_code
89531         , p_component_appl_id       => l_component_appl_id
89532         , p_amb_context_code        => l_amb_context_code
89533         , p_entity_code             => 'TRANSACTIONS'
89534         , p_event_class_code        => 'RETIREMENTS'
89535         , p_side                    => 'NA'
89536         );
89537 
89538   END IF;
89539 
89540    l_segment := AcctDerRule_163(
89541            p_application_id           => p_application_id
89542          , p_ae_header_id             => l_ae_header_id 
89543 , p_source_3 => p_source_3
89544 , p_source_25 => p_source_25
89545          , x_transaction_coa_id       => l_adr_transaction_coa_id
89546          , x_accounting_coa_id        => l_adr_accounting_coa_id
89547          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
89548          , x_flex_value_set_id        => l_adr_flex_value_set_id
89549          , x_value_type_code          => l_adr_value_type_code
89550          , x_value_combination_id     => l_adr_value_combination_id
89551          , x_value_segment_code       => l_adr_value_segment_code
89552          , p_side                     => 'NA'
89553          , p_override_seg_flag        => 'Y'
89554    );
89555 
89556    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
89557 
89558       xla_ae_lines_pkg.set_segment(
89559           p_to_segment_code         => 'GL_ACCOUNT'
89560         , p_segment_value           => l_segment
89561         , p_from_segment_code       => l_adr_value_segment_code
89562         , p_from_combination_id     => l_adr_value_combination_id
89563         , p_value_type_code         => l_adr_value_type_code
89564         , p_transaction_coa_id      => l_adr_transaction_coa_id
89565         , p_accounting_coa_id       => l_adr_accounting_coa_id
89566         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
89567         , p_flex_value_set_id       => l_adr_flex_value_set_id
89568         , p_adr_code                => 'FA_PROC_OF_SALE_LOSS_SEGMENT'
89569         , p_adr_type_code           => 'S'
89570         , p_component_type          => l_component_type
89571         , p_component_code          => l_component_code
89572         , p_component_type_code     => l_component_type_code
89573         , p_component_appl_id       => l_component_appl_id
89574         , p_amb_context_code        => l_amb_context_code
89575         , p_entity_code             => 'TRANSACTIONS'
89576         , p_event_class_code        => 'RETIREMENTS'
89577         , p_side                    => 'NA'
89578         );
89579 
89580   END IF;
89581 
89582    --
89583    --
89584    END IF;
89585 
89586        --
89587        -- Update the line information that should be overwritten
89588        --
89589        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
89590                                          p_header_num   => 1);
89591        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
89592 
89593        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
89594 
89595        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
89596           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
89597        END IF;
89598 
89599       --
89600       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
89601       --
89602       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
89603           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
89604       ELSE
89605           ---------------------------------------------------------------------------------------------------
89606           -- 4262811a Switch Sign
89607           ---------------------------------------------------------------------------------------------------
89608           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
89609           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
89610                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
89611           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
89612                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
89613           -- 5132302
89614           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
89615                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
89616 
89617       END IF;
89618 
89619       -- 4955764
89620       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
89621       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
89622 
89623 
89624       XLA_AE_LINES_PKG.ValidateCurrentLine;
89625       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
89626 
89630 
89627       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
89628                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
89629                ,p_balance_type_code => l_balance_type_code);
89631    END IF;
89632 
89633    -----------------------------------------------------------------------------------------
89634    -- 4262811 Multiperiod Accounting
89635    -----------------------------------------------------------------------------------------
89636      -- No MPA option is assigned.
89637 
89638 
89639 END IF;
89640 END IF;
89641 --
89642 
89643 --
89644 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
89645    trace
89646       (p_msg      => 'END of AcctLineType_278'
89647       ,p_level    => C_LEVEL_PROCEDURE
89648       ,p_module   => l_log_module);
89649 END IF;
89650 --
89651 EXCEPTION
89652   WHEN xla_exceptions_pkg.application_exception THEN
89653       RAISE;
89654   WHEN OTHERS THEN
89655        xla_exceptions_pkg.raise_message
89656            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_278');
89657 END AcctLineType_278;
89658 --
89659 
89660 ---------------------------------------
89661 --
89662 -- PRIVATE FUNCTION
89663 --         AcctLineType_279
89664 --
89665 ---------------------------------------
89666 PROCEDURE AcctLineType_279 (
89667   p_application_id        IN NUMBER
89668  ,p_event_id              IN NUMBER
89669  ,p_calculate_acctd_flag  IN VARCHAR2
89670  ,p_calculate_g_l_flag    IN VARCHAR2
89671  ,p_actual_flag           IN OUT VARCHAR2
89672  ,p_balance_type_code     OUT VARCHAR2
89673  ,p_gain_or_loss_ref      OUT VARCHAR2
89674  
89675 --Period Close Date
89676  , p_source_1            IN DATE
89677 --Bonus Depreciation Expense Account
89678  , p_source_2            IN VARCHAR2
89679 --Generated Code Combination Identifier
89680  , p_source_3            IN NUMBER
89681 --Expense Account Code Combination Identifier
89682  , p_source_29            IN NUMBER
89683 --Adjustment Type
89684  , p_source_35            IN VARCHAR2
89685 --Transaction Header Identifier
89686  , p_source_36            IN NUMBER
89687 --Adjustment Line Identifier
89688  , p_source_37            IN NUMBER
89689 --Distribution Type Code
89690  , p_source_38            IN VARCHAR2
89691 --Entered Amount
89692  , p_source_39            IN NUMBER
89693 --Currency Code
89694  , p_source_40            IN VARCHAR2
89695 --Source Destination Code
89696  , p_source_42            IN VARCHAR2
89697 )
89698 IS
89699 
89700 l_component_type              VARCHAR2(80);
89701 l_component_code              VARCHAR2(30);
89702 l_component_type_code         VARCHAR2(1);
89703 l_component_appl_id           INTEGER;
89704 l_amb_context_code            VARCHAR2(30);
89705 l_entity_code                 VARCHAR2(30);
89706 l_event_class_code            VARCHAR2(30);
89707 l_ae_header_id                NUMBER;
89708 l_event_type_code             VARCHAR2(30);
89709 l_line_definition_code        VARCHAR2(30);
89710 l_line_definition_owner_code  VARCHAR2(1);
89711 --
89712 -- adr variables
89713 l_segment                     VARCHAR2(30);
89714 l_ccid                        NUMBER;
89715 l_adr_transaction_coa_id      NUMBER;
89716 l_adr_accounting_coa_id       NUMBER;
89717 l_adr_flexfield_segment_code  VARCHAR2(30);
89718 l_adr_flex_value_set_id       NUMBER;
89719 l_adr_value_type_code         VARCHAR2(30);
89720 l_adr_value_combination_id    NUMBER;
89721 l_adr_value_segment_code      VARCHAR2(30);
89722 
89723 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
89724 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
89725 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
89726 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
89727 
89728 -- 4262811 Variables ------------------------------------------------------------------------------------------
89729 l_entered_amt_idx             NUMBER;
89730 l_accted_amt_idx              NUMBER;
89731 l_acc_rev_flag                VARCHAR2(1);
89732 l_accrual_line_num            NUMBER;
89733 l_tmp_amt                     NUMBER;
89734 l_acc_rev_natural_side_code   VARCHAR2(1);
89735 
89736 l_num_entries                 NUMBER;
89737 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
89738 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
89739 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
89740 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
89741 l_recog_line_1                NUMBER;
89742 l_recog_line_2                NUMBER;
89743 
89744 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
89745 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
89746 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
89747 
89748 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
89749 
89750 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
89751 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
89752 
89753 ---------------------------------------------------------------------------------------------------------------
89754 
89755 
89756 --
89757 -- bulk performance
89758 --
89759 l_balance_type_code           VARCHAR2(1);
89760 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
89761 l_log_module                  VARCHAR2(240);
89762 
89763 --
89764 -- Upgrade strategy
89765 --
89766 l_actual_upg_option           VARCHAR2(1);
89767 l_enc_upg_option           VARCHAR2(1);
89768 
89769 --
89770 BEGIN
89771 --
89772 IF g_log_enabled THEN
89776 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
89773       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_279';
89774 END IF;
89775 --
89777 
89778       trace
89779          (p_msg      => 'BEGIN of AcctLineType_279'
89780          ,p_level    => C_LEVEL_PROCEDURE
89781          ,p_module   => l_log_module);
89782 
89783 END IF;
89784 --
89785 l_component_type             := 'AMB_JLT';
89786 l_component_code             := 'FA_RECLASS_DEST_BONUS_EXP';
89787 l_component_type_code        := 'S';
89788 l_component_appl_id          :=  140;
89789 l_amb_context_code           := 'DEFAULT';
89790 l_entity_code                := 'TRANSACTIONS';
89791 l_event_class_code           := 'CATEGORY_RECLASS';
89792 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
89793 l_line_definition_owner_code := 'S';
89794 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
89795 --
89796 l_balance_type_code          := 'A';
89797 l_segment                     := NULL;
89798 l_ccid                        := NULL;
89799 l_adr_transaction_coa_id      := NULL;
89800 l_adr_accounting_coa_id       := NULL;
89801 l_adr_flexfield_segment_code  := NULL;
89802 l_adr_flex_value_set_id       := NULL;
89803 l_adr_value_type_code         := NULL;
89804 l_adr_value_combination_id    := NULL;
89805 l_adr_value_segment_code      := NULL;
89806 
89807 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
89808 l_bflow_class_code           := '';    -- 4219869 Business Flow
89809 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
89810 l_budgetary_control_flag     := 'N';
89811 
89812 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
89813 l_bflow_applied_to_amt       := NULL; -- 5132302
89814 l_entered_amt_idx            := NULL;          -- 4262811
89815 l_accted_amt_idx             := NULL;          -- 4262811
89816 l_acc_rev_flag               := NULL;          -- 4262811
89817 l_accrual_line_num           := NULL;          -- 4262811
89818 l_tmp_amt                    := NULL;          -- 4262811
89819 --
89820  
89821 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
89822     l_balance_type_code <> 'B' THEN
89823 IF NVL(p_source_35,'
89824 ') =  'BONUS EXPENSE' AND 
89825 NVL(p_source_42,'
89826 ') =  'DEST'
89827  THEN 
89828 
89829    --
89830    XLA_AE_LINES_PKG.SetNewLine;
89831 
89832    p_balance_type_code          := l_balance_type_code;
89833    -- set the flag so later we will know whether the gain loss line needs to be created
89834    
89835    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
89836      p_actual_flag :='A';
89837    END IF;
89838 
89839    --
89840    -- bulk performance
89841    --
89842    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
89843                                       p_header_num   => 0); -- 4262811
89844    --
89845    -- set accounting line options
89846    --
89847    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
89848            p_natural_side_code          => 'D'
89849          , p_gain_or_loss_flag          => 'N'
89850          , p_gl_transfer_mode_code      => 'S'
89851          , p_acct_entry_type_code       => 'A'
89852          , p_switch_side_flag           => 'Y'
89853          , p_merge_duplicate_code       => 'N'
89854          );
89855    --
89856    l_acc_rev_natural_side_code := 'C';  -- 4262811
89857    -- 
89858    --
89859    -- set accounting line type info
89860    --
89861    xla_ae_lines_pkg.SetAcctLineType
89862       (p_component_type             => l_component_type
89863       ,p_event_type_code            => l_event_type_code
89864       ,p_line_definition_owner_code => l_line_definition_owner_code
89865       ,p_line_definition_code       => l_line_definition_code
89866       ,p_accounting_line_code       => l_component_code
89867       ,p_accounting_line_type_code  => l_component_type_code
89868       ,p_accounting_line_appl_id    => l_component_appl_id
89869       ,p_amb_context_code           => l_amb_context_code
89870       ,p_entity_code                => l_entity_code
89871       ,p_event_class_code           => l_event_class_code);
89872    --
89873    -- set accounting class
89874    --
89875    xla_ae_lines_pkg.SetAcctClass(
89876            p_accounting_class_code  => 'EXPENSE'
89877          , p_ae_header_id           => l_ae_header_id
89878          );
89879 
89880    --
89881    -- set rounding class
89882    --
89883    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
89884                       'EXPENSE';
89885 
89886    --
89887    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
89888    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
89889    --
89890    -- bulk performance
89891    --
89892    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
89893 
89894    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
89895       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
89896 
89897    -- 4955764
89898    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
89899       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
89900 
89901    -- 4458381 Public Sector Enh
89902    
89903    --
89904    -- set accounting attributes for the line type
89905    --
89906    l_entered_amt_idx := 4;
89907    l_accted_amt_idx  := 6;
89908    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
89909    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
89910    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
89914    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
89911    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
89912    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
89913    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
89915    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
89916    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
89917    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
89918    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
89919    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
89920    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
89921 
89922    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
89923    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
89924 
89925    ---------------------------------------------------------------------------------------------------------------
89926    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
89927    ---------------------------------------------------------------------------------------------------------------
89928    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
89929 
89930    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
89931    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
89932 
89933    IF xla_accounting_cache_pkg.GetValueChar
89934          (p_source_code         => 'LEDGER_CATEGORY_CODE'
89935          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
89936    AND l_bflow_method_code = 'PRIOR_ENTRY'
89937 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
89938    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
89939          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
89940        )
89941    THEN
89942          xla_ae_lines_pkg.BflowUpgEntry
89943            (p_business_method_code    => l_bflow_method_code
89944            ,p_business_class_code     => l_bflow_class_code
89945            ,p_balance_type            => l_balance_type_code);
89946    ELSE
89947       NULL;
89948 -- No business flow processing for business flow method of NONE.
89949    END IF;
89950 
89951    --
89952    -- call analytical criteria
89953    --
89954    
89955    --
89956    -- call description
89957    --
89958    
89959 xla_ae_lines_pkg.SetLineDescription(
89960    p_ae_header_id => l_ae_header_id
89961   ,p_description  => Description_63 (
89962      p_application_id         => p_application_id
89963    , p_ae_header_id           => l_ae_header_id 
89964 , p_source_1 => p_source_1
89965    )
89966 );
89967 
89968 
89969    --
89970    -- call ADRs
89971    -- Bug 4922099
89972    --
89973    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
89974         (NVL(l_actual_upg_option, 'N') = 'O') OR
89975         (NVL(l_enc_upg_option, 'N') = 'O')
89976       )
89977    THEN
89978    NULL;
89979    --
89980    --
89981    
89982   l_ccid := AcctDerRule_175(
89983            p_application_id           => p_application_id
89984          , p_ae_header_id             => l_ae_header_id 
89985 , p_source_3 => p_source_3
89986 , p_source_29 => p_source_29
89987          , x_transaction_coa_id       => l_adr_transaction_coa_id
89988          , x_accounting_coa_id        => l_adr_accounting_coa_id
89989          , x_value_type_code          => l_adr_value_type_code
89990          , p_side                     => 'NA'
89991    );
89992 
89993    xla_ae_lines_pkg.set_ccid(
89994     p_code_combination_id          => l_ccid
89995   , p_value_type_code              => l_adr_value_type_code
89996   , p_transaction_coa_id           => l_adr_transaction_coa_id
89997   , p_accounting_coa_id            => l_adr_accounting_coa_id
89998   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
89999   , p_adr_type_code                => 'S'
90000   , p_component_type               => l_component_type
90001   , p_component_code               => l_component_code
90002   , p_component_type_code          => l_component_type_code
90003   , p_component_appl_id            => l_component_appl_id
90004   , p_amb_context_code             => l_amb_context_code
90005   , p_side                         => 'NA'
90006   );
90007 
90008 
90009    l_segment := AcctDerRule_143(
90010            p_application_id           => p_application_id
90011          , p_ae_header_id             => l_ae_header_id 
90012 , p_source_2 => p_source_2
90013 , p_source_3 => p_source_3
90014          , x_transaction_coa_id       => l_adr_transaction_coa_id
90015          , x_accounting_coa_id        => l_adr_accounting_coa_id
90016          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
90017          , x_flex_value_set_id        => l_adr_flex_value_set_id
90018          , x_value_type_code          => l_adr_value_type_code
90019          , x_value_combination_id     => l_adr_value_combination_id
90020          , x_value_segment_code       => l_adr_value_segment_code
90021          , p_side                     => 'NA'
90022          , p_override_seg_flag        => 'Y'
90023    );
90024 
90025    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
90026 
90027       xla_ae_lines_pkg.set_segment(
90028           p_to_segment_code         => 'GL_ACCOUNT'
90029         , p_segment_value           => l_segment
90030         , p_from_segment_code       => l_adr_value_segment_code
90031         , p_from_combination_id     => l_adr_value_combination_id
90032         , p_value_type_code         => l_adr_value_type_code
90033         , p_transaction_coa_id      => l_adr_transaction_coa_id
90034         , p_accounting_coa_id       => l_adr_accounting_coa_id
90038         , p_adr_type_code           => 'S'
90035         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
90036         , p_flex_value_set_id       => l_adr_flex_value_set_id
90037         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
90039         , p_component_type          => l_component_type
90040         , p_component_code          => l_component_code
90041         , p_component_type_code     => l_component_type_code
90042         , p_component_appl_id       => l_component_appl_id
90043         , p_amb_context_code        => l_amb_context_code
90044         , p_entity_code             => 'TRANSACTIONS'
90045         , p_event_class_code        => 'CATEGORY_RECLASS'
90046         , p_side                    => 'NA'
90047         );
90048 
90049   END IF;
90050 
90051    --
90052    --
90053    END IF;
90054    --
90055    -- Bug 4922099
90056    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
90057           (NVL(l_enc_upg_option, 'N') = 'O')
90058         ) AND
90059         (l_bflow_method_code = 'PRIOR_ENTRY')
90060       )
90061    THEN
90062       IF
90063       --
90064       1 = 2
90065       --
90066       THEN
90067       xla_accounting_err_pkg.build_message
90068                                     (p_appli_s_name            => 'XLA'
90069                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
90070                                     ,p_token_1                 => 'LINE_NUMBER'
90071                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
90072                                     ,p_token_2                 => 'LINE_TYPE_NAME'
90073                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
90074                                                                              l_component_type
90075                                                                             ,l_component_code
90076                                                                             ,l_component_type_code
90077                                                                             ,l_component_appl_id
90078                                                                             ,l_amb_context_code
90079                                                                             ,l_entity_code
90080                                                                             ,l_event_class_code
90081                                                                            )
90082                                     ,p_token_3                 => 'OWNER'
90083                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
90084                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
90085                                                                           ,p_lookup_code    => l_component_type_code
90086                                                                          )
90087                                     ,p_token_4                 => 'PRODUCT_NAME'
90088                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
90089                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
90090                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
90091                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
90092                                     ,p_ae_header_id            =>  NULL
90093                                        );
90094 
90095         IF (C_LEVEL_ERROR>= g_log_level) THEN
90096                  trace
90097                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
90098                       ,p_level    => C_LEVEL_ERROR
90099                       ,p_module   => l_log_module);
90100         END IF;
90101       END IF;
90102    END IF;
90103    --
90104    --
90105    ------------------------------------------------------------------------------------------------
90106    -- 4219869 Business Flow
90107    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
90108    -- Prior Entry.  Currently, the following code is always generated.
90109    ------------------------------------------------------------------------------------------------
90110    XLA_AE_LINES_PKG.ValidateCurrentLine;
90111 
90112    ------------------------------------------------------------------------------------
90113    -- 4219869 Business Flow
90114    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
90115    ------------------------------------------------------------------------------------
90116    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
90117 
90118    ----------------------------------------------------------------------------------
90119    -- 4219869 Business Flow
90120    -- Update journal entry status -- Need to generate this within IF <condition>
90121    ----------------------------------------------------------------------------------
90122    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
90123          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
90124          ,p_balance_type_code => l_balance_type_code
90125          );
90126 
90127    -------------------------------------------------------------------------------------------
90128    -- 4262811 - Generate the Accrual Reversal lines
90129    -------------------------------------------------------------------------------------------
90130    BEGIN
90131       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
90132                               (g_array_event(p_event_id).array_value_num('header_index'));
90133       IF l_acc_rev_flag IS NULL THEN
90134          l_acc_rev_flag := 'N';
90135       END IF;
90136    EXCEPTION
90137       WHEN OTHERS THEN
90138          l_acc_rev_flag := 'N';
90139    END;
90143        -- 4645092  ------------------------------------------------------------------------------
90140    --
90141    IF (l_acc_rev_flag = 'Y') THEN
90142 
90144        -- To allow MPA report to determine if it should generate report process
90145        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
90146        ------------------------------------------------------------------------------------------
90147 
90148        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
90149        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
90150    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
90151    -- call ADRs
90152    -- Bug 4922099
90153    --
90154    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
90155         (NVL(l_actual_upg_option, 'N') = 'O') OR
90156         (NVL(l_enc_upg_option, 'N') = 'O')
90157       )
90158    THEN
90159    NULL;
90160    --
90161    --
90162    
90163   l_ccid := AcctDerRule_175(
90164            p_application_id           => p_application_id
90165          , p_ae_header_id             => l_ae_header_id 
90166 , p_source_3 => p_source_3
90167 , p_source_29 => p_source_29
90168          , x_transaction_coa_id       => l_adr_transaction_coa_id
90169          , x_accounting_coa_id        => l_adr_accounting_coa_id
90170          , x_value_type_code          => l_adr_value_type_code
90171          , p_side                     => 'NA'
90172    );
90173 
90174    xla_ae_lines_pkg.set_ccid(
90175     p_code_combination_id          => l_ccid
90176   , p_value_type_code              => l_adr_value_type_code
90177   , p_transaction_coa_id           => l_adr_transaction_coa_id
90178   , p_accounting_coa_id            => l_adr_accounting_coa_id
90179   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
90180   , p_adr_type_code                => 'S'
90181   , p_component_type               => l_component_type
90182   , p_component_code               => l_component_code
90183   , p_component_type_code          => l_component_type_code
90184   , p_component_appl_id            => l_component_appl_id
90185   , p_amb_context_code             => l_amb_context_code
90186   , p_side                         => 'NA'
90187   );
90188 
90189 
90190    l_segment := AcctDerRule_143(
90191            p_application_id           => p_application_id
90192          , p_ae_header_id             => l_ae_header_id 
90193 , p_source_2 => p_source_2
90194 , p_source_3 => p_source_3
90195          , x_transaction_coa_id       => l_adr_transaction_coa_id
90196          , x_accounting_coa_id        => l_adr_accounting_coa_id
90197          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
90198          , x_flex_value_set_id        => l_adr_flex_value_set_id
90199          , x_value_type_code          => l_adr_value_type_code
90200          , x_value_combination_id     => l_adr_value_combination_id
90201          , x_value_segment_code       => l_adr_value_segment_code
90202          , p_side                     => 'NA'
90203          , p_override_seg_flag        => 'Y'
90204    );
90205 
90206    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
90207 
90208       xla_ae_lines_pkg.set_segment(
90209           p_to_segment_code         => 'GL_ACCOUNT'
90210         , p_segment_value           => l_segment
90211         , p_from_segment_code       => l_adr_value_segment_code
90212         , p_from_combination_id     => l_adr_value_combination_id
90213         , p_value_type_code         => l_adr_value_type_code
90214         , p_transaction_coa_id      => l_adr_transaction_coa_id
90215         , p_accounting_coa_id       => l_adr_accounting_coa_id
90216         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
90217         , p_flex_value_set_id       => l_adr_flex_value_set_id
90218         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
90219         , p_adr_type_code           => 'S'
90220         , p_component_type          => l_component_type
90221         , p_component_code          => l_component_code
90222         , p_component_type_code     => l_component_type_code
90223         , p_component_appl_id       => l_component_appl_id
90224         , p_amb_context_code        => l_amb_context_code
90225         , p_entity_code             => 'TRANSACTIONS'
90226         , p_event_class_code        => 'CATEGORY_RECLASS'
90227         , p_side                    => 'NA'
90228         );
90229 
90230   END IF;
90231 
90232    --
90233    --
90234    END IF;
90235 
90236        --
90237        -- Update the line information that should be overwritten
90238        --
90239        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
90240                                          p_header_num   => 1);
90241        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
90242 
90243        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
90244 
90245        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
90246           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
90247        END IF;
90248 
90249       --
90250       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
90251       --
90252       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
90253           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
90254       ELSE
90255           ---------------------------------------------------------------------------------------------------
90256           -- 4262811a Switch Sign
90257           ---------------------------------------------------------------------------------------------------
90258           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
90262                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
90259           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
90260                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
90261           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
90263           -- 5132302
90264           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
90265                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
90266 
90267       END IF;
90268 
90269       -- 4955764
90270       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
90271       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
90272 
90273 
90274       XLA_AE_LINES_PKG.ValidateCurrentLine;
90275       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
90276 
90277       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
90278                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
90279                ,p_balance_type_code => l_balance_type_code);
90280 
90281    END IF;
90282 
90283    -----------------------------------------------------------------------------------------
90284    -- 4262811 Multiperiod Accounting
90285    -----------------------------------------------------------------------------------------
90286      -- No MPA option is assigned.
90287 
90288 
90289 END IF;
90290 END IF;
90291 --
90292 
90293 --
90294 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
90295    trace
90296       (p_msg      => 'END of AcctLineType_279'
90297       ,p_level    => C_LEVEL_PROCEDURE
90298       ,p_module   => l_log_module);
90299 END IF;
90300 --
90301 EXCEPTION
90302   WHEN xla_exceptions_pkg.application_exception THEN
90303       RAISE;
90304   WHEN OTHERS THEN
90305        xla_exceptions_pkg.raise_message
90306            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_279');
90307 END AcctLineType_279;
90308 --
90309 
90310 ---------------------------------------
90311 --
90312 -- PRIVATE FUNCTION
90313 --         AcctLineType_280
90314 --
90315 ---------------------------------------
90316 PROCEDURE AcctLineType_280 (
90317   p_application_id        IN NUMBER
90318  ,p_event_id              IN NUMBER
90319  ,p_calculate_acctd_flag  IN VARCHAR2
90320  ,p_calculate_g_l_flag    IN VARCHAR2
90321  ,p_actual_flag           IN OUT VARCHAR2
90322  ,p_balance_type_code     OUT VARCHAR2
90323  ,p_gain_or_loss_ref      OUT VARCHAR2
90324  
90325 --Period Close Date
90326  , p_source_1            IN DATE
90327 --Generated Code Combination Identifier
90328  , p_source_3            IN NUMBER
90329 --Bonus Reserve Account
90330  , p_source_4            IN VARCHAR2
90331 --Generated Offset Code Combination Identifier
90332  , p_source_17            IN NUMBER
90333 --Expense Account Code Combination Identifier
90334  , p_source_29            IN NUMBER
90335 --Default Code Combination Identifier
90336  , p_source_30            IN NUMBER
90337 --Adjustment Type
90338  , p_source_35            IN VARCHAR2
90339 --Transaction Header Identifier
90340  , p_source_36            IN NUMBER
90341 --Adjustment Line Identifier
90342  , p_source_37            IN NUMBER
90343 --Distribution Type Code
90344  , p_source_38            IN VARCHAR2
90345 --Entered Amount
90346  , p_source_39            IN NUMBER
90347 --Currency Code
90348  , p_source_40            IN VARCHAR2
90349 --Source Destination Code
90350  , p_source_42            IN VARCHAR2
90351 )
90352 IS
90353 
90354 l_component_type              VARCHAR2(80);
90355 l_component_code              VARCHAR2(30);
90356 l_component_type_code         VARCHAR2(1);
90357 l_component_appl_id           INTEGER;
90358 l_amb_context_code            VARCHAR2(30);
90359 l_entity_code                 VARCHAR2(30);
90360 l_event_class_code            VARCHAR2(30);
90361 l_ae_header_id                NUMBER;
90362 l_event_type_code             VARCHAR2(30);
90363 l_line_definition_code        VARCHAR2(30);
90364 l_line_definition_owner_code  VARCHAR2(1);
90365 --
90366 -- adr variables
90367 l_segment                     VARCHAR2(30);
90368 l_ccid                        NUMBER;
90369 l_adr_transaction_coa_id      NUMBER;
90370 l_adr_accounting_coa_id       NUMBER;
90371 l_adr_flexfield_segment_code  VARCHAR2(30);
90372 l_adr_flex_value_set_id       NUMBER;
90373 l_adr_value_type_code         VARCHAR2(30);
90374 l_adr_value_combination_id    NUMBER;
90375 l_adr_value_segment_code      VARCHAR2(30);
90376 
90377 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
90378 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
90379 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
90380 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
90381 
90382 -- 4262811 Variables ------------------------------------------------------------------------------------------
90383 l_entered_amt_idx             NUMBER;
90384 l_accted_amt_idx              NUMBER;
90385 l_acc_rev_flag                VARCHAR2(1);
90386 l_accrual_line_num            NUMBER;
90387 l_tmp_amt                     NUMBER;
90388 l_acc_rev_natural_side_code   VARCHAR2(1);
90389 
90390 l_num_entries                 NUMBER;
90391 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
90392 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
90393 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
90394 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
90395 l_recog_line_1                NUMBER;
90396 l_recog_line_2                NUMBER;
90400 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
90397 
90398 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
90399 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
90401 
90402 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
90403 
90404 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
90405 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
90406 
90407 ---------------------------------------------------------------------------------------------------------------
90408 
90409 
90410 --
90411 -- bulk performance
90412 --
90413 l_balance_type_code           VARCHAR2(1);
90414 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
90415 l_log_module                  VARCHAR2(240);
90416 
90417 --
90418 -- Upgrade strategy
90419 --
90420 l_actual_upg_option           VARCHAR2(1);
90421 l_enc_upg_option           VARCHAR2(1);
90422 
90423 --
90424 BEGIN
90425 --
90426 IF g_log_enabled THEN
90427       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_280';
90428 END IF;
90429 --
90430 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
90431 
90432       trace
90433          (p_msg      => 'BEGIN of AcctLineType_280'
90434          ,p_level    => C_LEVEL_PROCEDURE
90435          ,p_module   => l_log_module);
90436 
90437 END IF;
90438 --
90439 l_component_type             := 'AMB_JLT';
90440 l_component_code             := 'FA_RECLASS_DEST_BONUS_RESERVE';
90441 l_component_type_code        := 'S';
90442 l_component_appl_id          :=  140;
90443 l_amb_context_code           := 'DEFAULT';
90444 l_entity_code                := 'TRANSACTIONS';
90445 l_event_class_code           := 'CATEGORY_RECLASS';
90446 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
90447 l_line_definition_owner_code := 'S';
90448 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
90449 --
90450 l_balance_type_code          := 'A';
90451 l_segment                     := NULL;
90452 l_ccid                        := NULL;
90453 l_adr_transaction_coa_id      := NULL;
90454 l_adr_accounting_coa_id       := NULL;
90455 l_adr_flexfield_segment_code  := NULL;
90456 l_adr_flex_value_set_id       := NULL;
90457 l_adr_value_type_code         := NULL;
90458 l_adr_value_combination_id    := NULL;
90459 l_adr_value_segment_code      := NULL;
90460 
90461 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
90462 l_bflow_class_code           := '';    -- 4219869 Business Flow
90463 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
90464 l_budgetary_control_flag     := 'N';
90465 
90466 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
90467 l_bflow_applied_to_amt       := NULL; -- 5132302
90468 l_entered_amt_idx            := NULL;          -- 4262811
90469 l_accted_amt_idx             := NULL;          -- 4262811
90470 l_acc_rev_flag               := NULL;          -- 4262811
90471 l_accrual_line_num           := NULL;          -- 4262811
90472 l_tmp_amt                    := NULL;          -- 4262811
90473 --
90474  
90475 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
90476     l_balance_type_code <> 'B' THEN
90477 IF (NVL(p_source_35,'
90478 ') =  'BONUS EXPENSE' OR 
90479 NVL(p_source_35,'
90480 ') =  'BONUS RESERVE') AND 
90481 NVL(p_source_42,'
90482 ') =  'DEST'
90483  THEN 
90484 
90485    --
90486    XLA_AE_LINES_PKG.SetNewLine;
90487 
90488    p_balance_type_code          := l_balance_type_code;
90489    -- set the flag so later we will know whether the gain loss line needs to be created
90490    
90491    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
90492      p_actual_flag :='A';
90493    END IF;
90494 
90495    --
90496    -- bulk performance
90497    --
90498    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
90499                                       p_header_num   => 0); -- 4262811
90500    --
90501    -- set accounting line options
90502    --
90503    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
90504            p_natural_side_code          => 'C'
90505          , p_gain_or_loss_flag          => 'N'
90506          , p_gl_transfer_mode_code      => 'S'
90507          , p_acct_entry_type_code       => 'A'
90508          , p_switch_side_flag           => 'Y'
90509          , p_merge_duplicate_code       => 'N'
90510          );
90511    --
90512    l_acc_rev_natural_side_code := 'D';  -- 4262811
90513    -- 
90514    --
90515    -- set accounting line type info
90516    --
90517    xla_ae_lines_pkg.SetAcctLineType
90518       (p_component_type             => l_component_type
90519       ,p_event_type_code            => l_event_type_code
90520       ,p_line_definition_owner_code => l_line_definition_owner_code
90521       ,p_line_definition_code       => l_line_definition_code
90522       ,p_accounting_line_code       => l_component_code
90523       ,p_accounting_line_type_code  => l_component_type_code
90524       ,p_accounting_line_appl_id    => l_component_appl_id
90525       ,p_amb_context_code           => l_amb_context_code
90526       ,p_entity_code                => l_entity_code
90527       ,p_event_class_code           => l_event_class_code);
90528    --
90529    -- set accounting class
90530    --
90531    xla_ae_lines_pkg.SetAcctClass(
90532            p_accounting_class_code  => 'ASSET'
90533          , p_ae_header_id           => l_ae_header_id
90534          );
90535 
90536    --
90537    -- set rounding class
90538    --
90539    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
90540                       'ASSET';
90541 
90545    --
90542    --
90543    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
90544    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
90546    -- bulk performance
90547    --
90548    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
90549 
90550    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
90551       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
90552 
90553    -- 4955764
90554    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
90555       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
90556 
90557    -- 4458381 Public Sector Enh
90558    
90559    --
90560    -- set accounting attributes for the line type
90561    --
90562    l_entered_amt_idx := 4;
90563    l_accted_amt_idx  := 6;
90564    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
90565    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
90566    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
90567    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
90568    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
90569    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
90570    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
90571    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
90572    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
90573    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
90574    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
90575    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
90576    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
90577 
90578    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
90579    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
90580 
90581    ---------------------------------------------------------------------------------------------------------------
90582    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
90583    ---------------------------------------------------------------------------------------------------------------
90584    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
90585 
90586    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
90587    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
90588 
90589    IF xla_accounting_cache_pkg.GetValueChar
90590          (p_source_code         => 'LEDGER_CATEGORY_CODE'
90591          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
90592    AND l_bflow_method_code = 'PRIOR_ENTRY'
90593 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
90594    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
90595          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
90596        )
90597    THEN
90598          xla_ae_lines_pkg.BflowUpgEntry
90599            (p_business_method_code    => l_bflow_method_code
90600            ,p_business_class_code     => l_bflow_class_code
90601            ,p_balance_type            => l_balance_type_code);
90602    ELSE
90603       NULL;
90604 -- No business flow processing for business flow method of NONE.
90605    END IF;
90606 
90607    --
90608    -- call analytical criteria
90609    --
90610    
90611    --
90612    -- call description
90613    --
90614    
90615 xla_ae_lines_pkg.SetLineDescription(
90616    p_ae_header_id => l_ae_header_id
90617   ,p_description  => Description_64 (
90618      p_application_id         => p_application_id
90619    , p_ae_header_id           => l_ae_header_id 
90620 , p_source_1 => p_source_1
90621    )
90622 );
90623 
90624 
90625    --
90626    -- call ADRs
90627    -- Bug 4922099
90628    --
90629    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
90630         (NVL(l_actual_upg_option, 'N') = 'O') OR
90631         (NVL(l_enc_upg_option, 'N') = 'O')
90632       )
90633    THEN
90634    NULL;
90635    --
90636    --
90637    
90638   l_ccid := AcctDerRule_174(
90639            p_application_id           => p_application_id
90640          , p_ae_header_id             => l_ae_header_id 
90641 , p_source_3 => p_source_3
90642 , p_source_17 => p_source_17
90643 , p_source_30 => p_source_30
90644          , x_transaction_coa_id       => l_adr_transaction_coa_id
90645          , x_accounting_coa_id        => l_adr_accounting_coa_id
90646          , x_value_type_code          => l_adr_value_type_code
90647          , p_side                     => 'NA'
90648    );
90649 
90650    xla_ae_lines_pkg.set_ccid(
90651     p_code_combination_id          => l_ccid
90652   , p_value_type_code              => l_adr_value_type_code
90653   , p_transaction_coa_id           => l_adr_transaction_coa_id
90654   , p_accounting_coa_id            => l_adr_accounting_coa_id
90655   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
90656   , p_adr_type_code                => 'S'
90657   , p_component_type               => l_component_type
90658   , p_component_code               => l_component_code
90659   , p_component_type_code          => l_component_type_code
90660   , p_component_appl_id            => l_component_appl_id
90661   , p_amb_context_code             => l_amb_context_code
90662   , p_side                         => 'NA'
90663   );
90664 
90665 
90666    l_segment := AcctDerRule_144(
90667            p_application_id           => p_application_id
90668          , p_ae_header_id             => l_ae_header_id 
90672          , x_accounting_coa_id        => l_adr_accounting_coa_id
90669 , p_source_3 => p_source_3
90670 , p_source_4 => p_source_4
90671          , x_transaction_coa_id       => l_adr_transaction_coa_id
90673          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
90674          , x_flex_value_set_id        => l_adr_flex_value_set_id
90675          , x_value_type_code          => l_adr_value_type_code
90676          , x_value_combination_id     => l_adr_value_combination_id
90677          , x_value_segment_code       => l_adr_value_segment_code
90678          , p_side                     => 'NA'
90679          , p_override_seg_flag        => 'Y'
90680    );
90681 
90682    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
90683 
90684       xla_ae_lines_pkg.set_segment(
90685           p_to_segment_code         => 'GL_ACCOUNT'
90686         , p_segment_value           => l_segment
90687         , p_from_segment_code       => l_adr_value_segment_code
90688         , p_from_combination_id     => l_adr_value_combination_id
90689         , p_value_type_code         => l_adr_value_type_code
90690         , p_transaction_coa_id      => l_adr_transaction_coa_id
90691         , p_accounting_coa_id       => l_adr_accounting_coa_id
90692         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
90693         , p_flex_value_set_id       => l_adr_flex_value_set_id
90694         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
90695         , p_adr_type_code           => 'S'
90696         , p_component_type          => l_component_type
90697         , p_component_code          => l_component_code
90698         , p_component_type_code     => l_component_type_code
90699         , p_component_appl_id       => l_component_appl_id
90700         , p_amb_context_code        => l_amb_context_code
90701         , p_entity_code             => 'TRANSACTIONS'
90702         , p_event_class_code        => 'CATEGORY_RECLASS'
90703         , p_side                    => 'NA'
90704         );
90705 
90706   END IF;
90707 
90708    l_segment := AcctDerRule_168(
90709            p_application_id           => p_application_id
90710          , p_ae_header_id             => l_ae_header_id 
90711 , p_source_3 => p_source_3
90712 , p_source_29 => p_source_29
90713          , x_transaction_coa_id       => l_adr_transaction_coa_id
90714          , x_accounting_coa_id        => l_adr_accounting_coa_id
90715          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
90716          , x_flex_value_set_id        => l_adr_flex_value_set_id
90717          , x_value_type_code          => l_adr_value_type_code
90718          , x_value_combination_id     => l_adr_value_combination_id
90719          , x_value_segment_code       => l_adr_value_segment_code
90720          , p_side                     => 'NA'
90721          , p_override_seg_flag        => 'Y'
90722    );
90723 
90724    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
90725 
90726       xla_ae_lines_pkg.set_segment(
90727           p_to_segment_code         => 'GL_BALANCING'
90728         , p_segment_value           => l_segment
90729         , p_from_segment_code       => l_adr_value_segment_code
90730         , p_from_combination_id     => l_adr_value_combination_id
90731         , p_value_type_code         => l_adr_value_type_code
90732         , p_transaction_coa_id      => l_adr_transaction_coa_id
90733         , p_accounting_coa_id       => l_adr_accounting_coa_id
90734         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
90735         , p_flex_value_set_id       => l_adr_flex_value_set_id
90736         , p_adr_code                => 'FA_EXPENSE_ACCT'
90737         , p_adr_type_code           => 'S'
90738         , p_component_type          => l_component_type
90739         , p_component_code          => l_component_code
90740         , p_component_type_code     => l_component_type_code
90741         , p_component_appl_id       => l_component_appl_id
90742         , p_amb_context_code        => l_amb_context_code
90743         , p_entity_code             => 'TRANSACTIONS'
90744         , p_event_class_code        => 'CATEGORY_RECLASS'
90745         , p_side                    => 'NA'
90746         );
90747 
90748   END IF;
90749 
90750    --
90751    --
90752    END IF;
90753    --
90754    -- Bug 4922099
90755    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
90756           (NVL(l_enc_upg_option, 'N') = 'O')
90757         ) AND
90758         (l_bflow_method_code = 'PRIOR_ENTRY')
90759       )
90760    THEN
90761       IF
90762       --
90763       1 = 2
90764       --
90765       THEN
90766       xla_accounting_err_pkg.build_message
90767                                     (p_appli_s_name            => 'XLA'
90768                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
90769                                     ,p_token_1                 => 'LINE_NUMBER'
90770                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
90771                                     ,p_token_2                 => 'LINE_TYPE_NAME'
90772                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
90773                                                                              l_component_type
90774                                                                             ,l_component_code
90775                                                                             ,l_component_type_code
90776                                                                             ,l_component_appl_id
90777                                                                             ,l_amb_context_code
90778                                                                             ,l_entity_code
90779                                                                             ,l_event_class_code
90780                                                                            )
90784                                                                           ,p_lookup_code    => l_component_type_code
90781                                     ,p_token_3                 => 'OWNER'
90782                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
90783                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
90785                                                                          )
90786                                     ,p_token_4                 => 'PRODUCT_NAME'
90787                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
90788                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
90789                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
90790                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
90791                                     ,p_ae_header_id            =>  NULL
90792                                        );
90793 
90794         IF (C_LEVEL_ERROR>= g_log_level) THEN
90795                  trace
90796                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
90797                       ,p_level    => C_LEVEL_ERROR
90798                       ,p_module   => l_log_module);
90799         END IF;
90800       END IF;
90801    END IF;
90802    --
90803    --
90804    ------------------------------------------------------------------------------------------------
90805    -- 4219869 Business Flow
90806    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
90807    -- Prior Entry.  Currently, the following code is always generated.
90808    ------------------------------------------------------------------------------------------------
90809    XLA_AE_LINES_PKG.ValidateCurrentLine;
90810 
90811    ------------------------------------------------------------------------------------
90812    -- 4219869 Business Flow
90813    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
90814    ------------------------------------------------------------------------------------
90815    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
90816 
90817    ----------------------------------------------------------------------------------
90818    -- 4219869 Business Flow
90819    -- Update journal entry status -- Need to generate this within IF <condition>
90820    ----------------------------------------------------------------------------------
90821    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
90822          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
90823          ,p_balance_type_code => l_balance_type_code
90824          );
90825 
90826    -------------------------------------------------------------------------------------------
90827    -- 4262811 - Generate the Accrual Reversal lines
90828    -------------------------------------------------------------------------------------------
90829    BEGIN
90830       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
90831                               (g_array_event(p_event_id).array_value_num('header_index'));
90832       IF l_acc_rev_flag IS NULL THEN
90833          l_acc_rev_flag := 'N';
90834       END IF;
90835    EXCEPTION
90836       WHEN OTHERS THEN
90837          l_acc_rev_flag := 'N';
90838    END;
90839    --
90840    IF (l_acc_rev_flag = 'Y') THEN
90841 
90842        -- 4645092  ------------------------------------------------------------------------------
90843        -- To allow MPA report to determine if it should generate report process
90844        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
90845        ------------------------------------------------------------------------------------------
90846 
90847        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
90848        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
90849    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
90850    -- call ADRs
90851    -- Bug 4922099
90852    --
90853    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
90854         (NVL(l_actual_upg_option, 'N') = 'O') OR
90855         (NVL(l_enc_upg_option, 'N') = 'O')
90856       )
90857    THEN
90858    NULL;
90859    --
90860    --
90861    
90862   l_ccid := AcctDerRule_174(
90863            p_application_id           => p_application_id
90864          , p_ae_header_id             => l_ae_header_id 
90865 , p_source_3 => p_source_3
90866 , p_source_17 => p_source_17
90867 , p_source_30 => p_source_30
90868          , x_transaction_coa_id       => l_adr_transaction_coa_id
90869          , x_accounting_coa_id        => l_adr_accounting_coa_id
90870          , x_value_type_code          => l_adr_value_type_code
90871          , p_side                     => 'NA'
90872    );
90873 
90874    xla_ae_lines_pkg.set_ccid(
90875     p_code_combination_id          => l_ccid
90876   , p_value_type_code              => l_adr_value_type_code
90877   , p_transaction_coa_id           => l_adr_transaction_coa_id
90878   , p_accounting_coa_id            => l_adr_accounting_coa_id
90879   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
90880   , p_adr_type_code                => 'S'
90881   , p_component_type               => l_component_type
90882   , p_component_code               => l_component_code
90883   , p_component_type_code          => l_component_type_code
90884   , p_component_appl_id            => l_component_appl_id
90885   , p_amb_context_code             => l_amb_context_code
90886   , p_side                         => 'NA'
90887   );
90888 
90889 
90890    l_segment := AcctDerRule_144(
90891            p_application_id           => p_application_id
90892          , p_ae_header_id             => l_ae_header_id 
90893 , p_source_3 => p_source_3
90897          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
90894 , p_source_4 => p_source_4
90895          , x_transaction_coa_id       => l_adr_transaction_coa_id
90896          , x_accounting_coa_id        => l_adr_accounting_coa_id
90898          , x_flex_value_set_id        => l_adr_flex_value_set_id
90899          , x_value_type_code          => l_adr_value_type_code
90900          , x_value_combination_id     => l_adr_value_combination_id
90901          , x_value_segment_code       => l_adr_value_segment_code
90902          , p_side                     => 'NA'
90903          , p_override_seg_flag        => 'Y'
90904    );
90905 
90906    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
90907 
90908       xla_ae_lines_pkg.set_segment(
90909           p_to_segment_code         => 'GL_ACCOUNT'
90910         , p_segment_value           => l_segment
90911         , p_from_segment_code       => l_adr_value_segment_code
90912         , p_from_combination_id     => l_adr_value_combination_id
90913         , p_value_type_code         => l_adr_value_type_code
90914         , p_transaction_coa_id      => l_adr_transaction_coa_id
90915         , p_accounting_coa_id       => l_adr_accounting_coa_id
90916         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
90917         , p_flex_value_set_id       => l_adr_flex_value_set_id
90918         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
90919         , p_adr_type_code           => 'S'
90920         , p_component_type          => l_component_type
90921         , p_component_code          => l_component_code
90922         , p_component_type_code     => l_component_type_code
90923         , p_component_appl_id       => l_component_appl_id
90924         , p_amb_context_code        => l_amb_context_code
90925         , p_entity_code             => 'TRANSACTIONS'
90926         , p_event_class_code        => 'CATEGORY_RECLASS'
90927         , p_side                    => 'NA'
90928         );
90929 
90930   END IF;
90931 
90932    l_segment := AcctDerRule_168(
90933            p_application_id           => p_application_id
90934          , p_ae_header_id             => l_ae_header_id 
90935 , p_source_3 => p_source_3
90936 , p_source_29 => p_source_29
90937          , x_transaction_coa_id       => l_adr_transaction_coa_id
90938          , x_accounting_coa_id        => l_adr_accounting_coa_id
90939          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
90940          , x_flex_value_set_id        => l_adr_flex_value_set_id
90941          , x_value_type_code          => l_adr_value_type_code
90942          , x_value_combination_id     => l_adr_value_combination_id
90943          , x_value_segment_code       => l_adr_value_segment_code
90944          , p_side                     => 'NA'
90945          , p_override_seg_flag        => 'Y'
90946    );
90947 
90948    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
90949 
90950       xla_ae_lines_pkg.set_segment(
90951           p_to_segment_code         => 'GL_BALANCING'
90952         , p_segment_value           => l_segment
90953         , p_from_segment_code       => l_adr_value_segment_code
90954         , p_from_combination_id     => l_adr_value_combination_id
90955         , p_value_type_code         => l_adr_value_type_code
90956         , p_transaction_coa_id      => l_adr_transaction_coa_id
90957         , p_accounting_coa_id       => l_adr_accounting_coa_id
90958         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
90959         , p_flex_value_set_id       => l_adr_flex_value_set_id
90960         , p_adr_code                => 'FA_EXPENSE_ACCT'
90961         , p_adr_type_code           => 'S'
90962         , p_component_type          => l_component_type
90963         , p_component_code          => l_component_code
90964         , p_component_type_code     => l_component_type_code
90965         , p_component_appl_id       => l_component_appl_id
90966         , p_amb_context_code        => l_amb_context_code
90967         , p_entity_code             => 'TRANSACTIONS'
90968         , p_event_class_code        => 'CATEGORY_RECLASS'
90969         , p_side                    => 'NA'
90970         );
90971 
90972   END IF;
90973 
90974    --
90975    --
90976    END IF;
90977 
90978        --
90979        -- Update the line information that should be overwritten
90980        --
90981        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
90982                                          p_header_num   => 1);
90983        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
90984 
90985        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
90986 
90987        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
90988           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
90989        END IF;
90990 
90991       --
90992       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
90993       --
90994       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
90995           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
90996       ELSE
90997           ---------------------------------------------------------------------------------------------------
90998           -- 4262811a Switch Sign
90999           ---------------------------------------------------------------------------------------------------
91000           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
91001           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
91002                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
91003           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
91007                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
91004                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
91005           -- 5132302
91006           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
91008 
91009       END IF;
91010 
91011       -- 4955764
91012       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
91013       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
91014 
91015 
91016       XLA_AE_LINES_PKG.ValidateCurrentLine;
91017       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
91018 
91019       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
91020                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
91021                ,p_balance_type_code => l_balance_type_code);
91022 
91023    END IF;
91024 
91025    -----------------------------------------------------------------------------------------
91026    -- 4262811 Multiperiod Accounting
91027    -----------------------------------------------------------------------------------------
91028      -- No MPA option is assigned.
91029 
91030 
91031 END IF;
91032 END IF;
91033 --
91034 
91035 --
91036 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
91037    trace
91038       (p_msg      => 'END of AcctLineType_280'
91039       ,p_level    => C_LEVEL_PROCEDURE
91040       ,p_module   => l_log_module);
91041 END IF;
91042 --
91043 EXCEPTION
91044   WHEN xla_exceptions_pkg.application_exception THEN
91045       RAISE;
91046   WHEN OTHERS THEN
91047        xla_exceptions_pkg.raise_message
91048            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_280');
91049 END AcctLineType_280;
91050 --
91051 
91052 ---------------------------------------
91053 --
91054 -- PRIVATE FUNCTION
91055 --         AcctLineType_281
91056 --
91057 ---------------------------------------
91058 PROCEDURE AcctLineType_281 (
91059   p_application_id        IN NUMBER
91060  ,p_event_id              IN NUMBER
91061  ,p_calculate_acctd_flag  IN VARCHAR2
91062  ,p_calculate_g_l_flag    IN VARCHAR2
91063  ,p_actual_flag           IN OUT VARCHAR2
91064  ,p_balance_type_code     OUT VARCHAR2
91065  ,p_gain_or_loss_ref      OUT VARCHAR2
91066  
91067 --Period Close Date
91068  , p_source_1            IN DATE
91069 --Generated Code Combination Identifier
91070  , p_source_3            IN NUMBER
91071 --Asset Cost Account
91072  , p_source_9            IN VARCHAR2
91073 --Expense Account Code Combination Identifier
91074  , p_source_29            IN NUMBER
91075 --Default Code Combination Identifier
91076  , p_source_30            IN NUMBER
91077 --Adjustment Type
91078  , p_source_35            IN VARCHAR2
91079 --Transaction Header Identifier
91080  , p_source_36            IN NUMBER
91081 --Adjustment Line Identifier
91082  , p_source_37            IN NUMBER
91083 --Distribution Type Code
91084  , p_source_38            IN VARCHAR2
91085 --Entered Amount
91086  , p_source_39            IN NUMBER
91087 --Currency Code
91088  , p_source_40            IN VARCHAR2
91089 --Source Destination Code
91090  , p_source_42            IN VARCHAR2
91091 )
91092 IS
91093 
91094 l_component_type              VARCHAR2(80);
91095 l_component_code              VARCHAR2(30);
91096 l_component_type_code         VARCHAR2(1);
91097 l_component_appl_id           INTEGER;
91098 l_amb_context_code            VARCHAR2(30);
91099 l_entity_code                 VARCHAR2(30);
91100 l_event_class_code            VARCHAR2(30);
91101 l_ae_header_id                NUMBER;
91102 l_event_type_code             VARCHAR2(30);
91103 l_line_definition_code        VARCHAR2(30);
91104 l_line_definition_owner_code  VARCHAR2(1);
91105 --
91106 -- adr variables
91107 l_segment                     VARCHAR2(30);
91108 l_ccid                        NUMBER;
91109 l_adr_transaction_coa_id      NUMBER;
91110 l_adr_accounting_coa_id       NUMBER;
91111 l_adr_flexfield_segment_code  VARCHAR2(30);
91112 l_adr_flex_value_set_id       NUMBER;
91113 l_adr_value_type_code         VARCHAR2(30);
91114 l_adr_value_combination_id    NUMBER;
91115 l_adr_value_segment_code      VARCHAR2(30);
91116 
91117 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
91118 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
91119 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
91120 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
91121 
91122 -- 4262811 Variables ------------------------------------------------------------------------------------------
91123 l_entered_amt_idx             NUMBER;
91124 l_accted_amt_idx              NUMBER;
91125 l_acc_rev_flag                VARCHAR2(1);
91126 l_accrual_line_num            NUMBER;
91127 l_tmp_amt                     NUMBER;
91128 l_acc_rev_natural_side_code   VARCHAR2(1);
91129 
91130 l_num_entries                 NUMBER;
91131 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
91132 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
91133 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
91134 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
91135 l_recog_line_1                NUMBER;
91136 l_recog_line_2                NUMBER;
91137 
91138 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
91139 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
91140 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
91141 
91142 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
91146 
91143 
91144 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
91145 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
91147 ---------------------------------------------------------------------------------------------------------------
91148 
91149 
91150 --
91151 -- bulk performance
91152 --
91153 l_balance_type_code           VARCHAR2(1);
91154 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
91155 l_log_module                  VARCHAR2(240);
91156 
91157 --
91158 -- Upgrade strategy
91159 --
91160 l_actual_upg_option           VARCHAR2(1);
91161 l_enc_upg_option           VARCHAR2(1);
91162 
91163 --
91164 BEGIN
91165 --
91166 IF g_log_enabled THEN
91167       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_281';
91168 END IF;
91169 --
91170 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
91171 
91172       trace
91173          (p_msg      => 'BEGIN of AcctLineType_281'
91174          ,p_level    => C_LEVEL_PROCEDURE
91175          ,p_module   => l_log_module);
91176 
91177 END IF;
91178 --
91179 l_component_type             := 'AMB_JLT';
91180 l_component_code             := 'FA_RECLASS_DEST_COST';
91181 l_component_type_code        := 'S';
91182 l_component_appl_id          :=  140;
91183 l_amb_context_code           := 'DEFAULT';
91184 l_entity_code                := 'TRANSACTIONS';
91185 l_event_class_code           := 'CATEGORY_RECLASS';
91186 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
91187 l_line_definition_owner_code := 'S';
91188 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
91189 --
91190 l_balance_type_code          := 'A';
91191 l_segment                     := NULL;
91192 l_ccid                        := NULL;
91193 l_adr_transaction_coa_id      := NULL;
91194 l_adr_accounting_coa_id       := NULL;
91195 l_adr_flexfield_segment_code  := NULL;
91196 l_adr_flex_value_set_id       := NULL;
91197 l_adr_value_type_code         := NULL;
91198 l_adr_value_combination_id    := NULL;
91199 l_adr_value_segment_code      := NULL;
91200 
91201 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
91202 l_bflow_class_code           := '';    -- 4219869 Business Flow
91203 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
91204 l_budgetary_control_flag     := 'N';
91205 
91206 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
91207 l_bflow_applied_to_amt       := NULL; -- 5132302
91208 l_entered_amt_idx            := NULL;          -- 4262811
91209 l_accted_amt_idx             := NULL;          -- 4262811
91210 l_acc_rev_flag               := NULL;          -- 4262811
91211 l_accrual_line_num           := NULL;          -- 4262811
91212 l_tmp_amt                    := NULL;          -- 4262811
91213 --
91214  
91215 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
91216     l_balance_type_code <> 'B' THEN
91217 IF NVL(p_source_35,'
91218 ') =  'COST' AND 
91219 NVL(p_source_42,'
91220 ') =  'DEST'
91221  THEN 
91222 
91223    --
91224    XLA_AE_LINES_PKG.SetNewLine;
91225 
91226    p_balance_type_code          := l_balance_type_code;
91227    -- set the flag so later we will know whether the gain loss line needs to be created
91228    
91229    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
91230      p_actual_flag :='A';
91231    END IF;
91232 
91233    --
91234    -- bulk performance
91235    --
91236    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
91237                                       p_header_num   => 0); -- 4262811
91238    --
91239    -- set accounting line options
91240    --
91241    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
91242            p_natural_side_code          => 'D'
91243          , p_gain_or_loss_flag          => 'N'
91244          , p_gl_transfer_mode_code      => 'S'
91245          , p_acct_entry_type_code       => 'A'
91246          , p_switch_side_flag           => 'Y'
91247          , p_merge_duplicate_code       => 'N'
91248          );
91249    --
91250    l_acc_rev_natural_side_code := 'C';  -- 4262811
91251    -- 
91252    --
91253    -- set accounting line type info
91254    --
91255    xla_ae_lines_pkg.SetAcctLineType
91256       (p_component_type             => l_component_type
91257       ,p_event_type_code            => l_event_type_code
91258       ,p_line_definition_owner_code => l_line_definition_owner_code
91259       ,p_line_definition_code       => l_line_definition_code
91260       ,p_accounting_line_code       => l_component_code
91261       ,p_accounting_line_type_code  => l_component_type_code
91262       ,p_accounting_line_appl_id    => l_component_appl_id
91263       ,p_amb_context_code           => l_amb_context_code
91264       ,p_entity_code                => l_entity_code
91265       ,p_event_class_code           => l_event_class_code);
91266    --
91267    -- set accounting class
91268    --
91269    xla_ae_lines_pkg.SetAcctClass(
91270            p_accounting_class_code  => 'ASSET'
91271          , p_ae_header_id           => l_ae_header_id
91272          );
91273 
91274    --
91275    -- set rounding class
91276    --
91277    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
91278                       'ASSET';
91279 
91280    --
91281    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
91282    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
91283    --
91284    -- bulk performance
91285    --
91286    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
91287 
91291    -- 4955764
91288    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
91289       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
91290 
91292    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
91293       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
91294 
91295    -- 4458381 Public Sector Enh
91296    
91297    --
91298    -- set accounting attributes for the line type
91299    --
91300    l_entered_amt_idx := 4;
91301    l_accted_amt_idx  := 6;
91302    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
91303    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
91304    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
91305    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
91306    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
91307    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
91308    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
91309    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
91310    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
91311    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
91312    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
91313    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
91314    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
91315 
91316    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
91317    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
91318 
91319    ---------------------------------------------------------------------------------------------------------------
91320    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
91321    ---------------------------------------------------------------------------------------------------------------
91322    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
91323 
91324    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
91325    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
91326 
91327    IF xla_accounting_cache_pkg.GetValueChar
91328          (p_source_code         => 'LEDGER_CATEGORY_CODE'
91329          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
91330    AND l_bflow_method_code = 'PRIOR_ENTRY'
91331 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
91332    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
91333          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
91334        )
91335    THEN
91336          xla_ae_lines_pkg.BflowUpgEntry
91337            (p_business_method_code    => l_bflow_method_code
91338            ,p_business_class_code     => l_bflow_class_code
91339            ,p_balance_type            => l_balance_type_code);
91340    ELSE
91341       NULL;
91342 -- No business flow processing for business flow method of NONE.
91343    END IF;
91344 
91345    --
91346    -- call analytical criteria
91347    --
91348    
91349    --
91350    -- call description
91351    --
91352    
91353 xla_ae_lines_pkg.SetLineDescription(
91354    p_ae_header_id => l_ae_header_id
91355   ,p_description  => Description_65 (
91356      p_application_id         => p_application_id
91357    , p_ae_header_id           => l_ae_header_id 
91358 , p_source_1 => p_source_1
91359    )
91360 );
91361 
91362 
91363    --
91364    -- call ADRs
91365    -- Bug 4922099
91366    --
91367    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
91368         (NVL(l_actual_upg_option, 'N') = 'O') OR
91369         (NVL(l_enc_upg_option, 'N') = 'O')
91370       )
91371    THEN
91372    NULL;
91373    --
91374    --
91375    
91376   l_ccid := AcctDerRule_173(
91377            p_application_id           => p_application_id
91378          , p_ae_header_id             => l_ae_header_id 
91379 , p_source_3 => p_source_3
91380 , p_source_30 => p_source_30
91381          , x_transaction_coa_id       => l_adr_transaction_coa_id
91382          , x_accounting_coa_id        => l_adr_accounting_coa_id
91383          , x_value_type_code          => l_adr_value_type_code
91384          , p_side                     => 'NA'
91385    );
91386 
91387    xla_ae_lines_pkg.set_ccid(
91388     p_code_combination_id          => l_ccid
91389   , p_value_type_code              => l_adr_value_type_code
91390   , p_transaction_coa_id           => l_adr_transaction_coa_id
91391   , p_accounting_coa_id            => l_adr_accounting_coa_id
91392   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
91393   , p_adr_type_code                => 'S'
91394   , p_component_type               => l_component_type
91395   , p_component_code               => l_component_code
91396   , p_component_type_code          => l_component_type_code
91397   , p_component_appl_id            => l_component_appl_id
91398   , p_amb_context_code             => l_amb_context_code
91399   , p_side                         => 'NA'
91400   );
91401 
91402 
91403    l_segment := AcctDerRule_148(
91404            p_application_id           => p_application_id
91405          , p_ae_header_id             => l_ae_header_id 
91406 , p_source_3 => p_source_3
91407 , p_source_9 => p_source_9
91408          , x_transaction_coa_id       => l_adr_transaction_coa_id
91409          , x_accounting_coa_id        => l_adr_accounting_coa_id
91410          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
91411          , x_flex_value_set_id        => l_adr_flex_value_set_id
91412          , x_value_type_code          => l_adr_value_type_code
91413          , x_value_combination_id     => l_adr_value_combination_id
91417    );
91414          , x_value_segment_code       => l_adr_value_segment_code
91415          , p_side                     => 'NA'
91416          , p_override_seg_flag        => 'Y'
91418 
91419    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
91420 
91421       xla_ae_lines_pkg.set_segment(
91422           p_to_segment_code         => 'GL_ACCOUNT'
91423         , p_segment_value           => l_segment
91424         , p_from_segment_code       => l_adr_value_segment_code
91425         , p_from_combination_id     => l_adr_value_combination_id
91426         , p_value_type_code         => l_adr_value_type_code
91427         , p_transaction_coa_id      => l_adr_transaction_coa_id
91428         , p_accounting_coa_id       => l_adr_accounting_coa_id
91429         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
91430         , p_flex_value_set_id       => l_adr_flex_value_set_id
91431         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
91432         , p_adr_type_code           => 'S'
91433         , p_component_type          => l_component_type
91434         , p_component_code          => l_component_code
91435         , p_component_type_code     => l_component_type_code
91436         , p_component_appl_id       => l_component_appl_id
91437         , p_amb_context_code        => l_amb_context_code
91438         , p_entity_code             => 'TRANSACTIONS'
91439         , p_event_class_code        => 'CATEGORY_RECLASS'
91440         , p_side                    => 'NA'
91441         );
91442 
91443   END IF;
91444 
91445    l_segment := AcctDerRule_168(
91446            p_application_id           => p_application_id
91447          , p_ae_header_id             => l_ae_header_id 
91448 , p_source_3 => p_source_3
91449 , p_source_29 => p_source_29
91450          , x_transaction_coa_id       => l_adr_transaction_coa_id
91451          , x_accounting_coa_id        => l_adr_accounting_coa_id
91452          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
91453          , x_flex_value_set_id        => l_adr_flex_value_set_id
91454          , x_value_type_code          => l_adr_value_type_code
91455          , x_value_combination_id     => l_adr_value_combination_id
91456          , x_value_segment_code       => l_adr_value_segment_code
91457          , p_side                     => 'NA'
91458          , p_override_seg_flag        => 'Y'
91459    );
91460 
91461    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
91462 
91463       xla_ae_lines_pkg.set_segment(
91464           p_to_segment_code         => 'GL_BALANCING'
91465         , p_segment_value           => l_segment
91466         , p_from_segment_code       => l_adr_value_segment_code
91467         , p_from_combination_id     => l_adr_value_combination_id
91468         , p_value_type_code         => l_adr_value_type_code
91469         , p_transaction_coa_id      => l_adr_transaction_coa_id
91470         , p_accounting_coa_id       => l_adr_accounting_coa_id
91471         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
91472         , p_flex_value_set_id       => l_adr_flex_value_set_id
91473         , p_adr_code                => 'FA_EXPENSE_ACCT'
91474         , p_adr_type_code           => 'S'
91475         , p_component_type          => l_component_type
91476         , p_component_code          => l_component_code
91477         , p_component_type_code     => l_component_type_code
91478         , p_component_appl_id       => l_component_appl_id
91479         , p_amb_context_code        => l_amb_context_code
91480         , p_entity_code             => 'TRANSACTIONS'
91481         , p_event_class_code        => 'CATEGORY_RECLASS'
91482         , p_side                    => 'NA'
91483         );
91484 
91485   END IF;
91486 
91487    --
91488    --
91489    END IF;
91490    --
91491    -- Bug 4922099
91492    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
91493           (NVL(l_enc_upg_option, 'N') = 'O')
91494         ) AND
91495         (l_bflow_method_code = 'PRIOR_ENTRY')
91496       )
91497    THEN
91498       IF
91499       --
91500       1 = 2
91501       --
91502       THEN
91503       xla_accounting_err_pkg.build_message
91504                                     (p_appli_s_name            => 'XLA'
91505                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
91506                                     ,p_token_1                 => 'LINE_NUMBER'
91507                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
91508                                     ,p_token_2                 => 'LINE_TYPE_NAME'
91509                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
91510                                                                              l_component_type
91511                                                                             ,l_component_code
91512                                                                             ,l_component_type_code
91513                                                                             ,l_component_appl_id
91514                                                                             ,l_amb_context_code
91515                                                                             ,l_entity_code
91516                                                                             ,l_event_class_code
91517                                                                            )
91518                                     ,p_token_3                 => 'OWNER'
91519                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
91520                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
91521                                                                           ,p_lookup_code    => l_component_type_code
91522                                                                          )
91523                                     ,p_token_4                 => 'PRODUCT_NAME'
91527                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
91524                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
91525                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
91526                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
91528                                     ,p_ae_header_id            =>  NULL
91529                                        );
91530 
91531         IF (C_LEVEL_ERROR>= g_log_level) THEN
91532                  trace
91533                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
91534                       ,p_level    => C_LEVEL_ERROR
91535                       ,p_module   => l_log_module);
91536         END IF;
91537       END IF;
91538    END IF;
91539    --
91540    --
91541    ------------------------------------------------------------------------------------------------
91542    -- 4219869 Business Flow
91543    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
91544    -- Prior Entry.  Currently, the following code is always generated.
91545    ------------------------------------------------------------------------------------------------
91546    XLA_AE_LINES_PKG.ValidateCurrentLine;
91547 
91548    ------------------------------------------------------------------------------------
91549    -- 4219869 Business Flow
91550    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
91551    ------------------------------------------------------------------------------------
91552    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
91553 
91554    ----------------------------------------------------------------------------------
91555    -- 4219869 Business Flow
91556    -- Update journal entry status -- Need to generate this within IF <condition>
91557    ----------------------------------------------------------------------------------
91558    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
91559          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
91560          ,p_balance_type_code => l_balance_type_code
91561          );
91562 
91563    -------------------------------------------------------------------------------------------
91564    -- 4262811 - Generate the Accrual Reversal lines
91565    -------------------------------------------------------------------------------------------
91566    BEGIN
91567       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
91568                               (g_array_event(p_event_id).array_value_num('header_index'));
91569       IF l_acc_rev_flag IS NULL THEN
91570          l_acc_rev_flag := 'N';
91571       END IF;
91572    EXCEPTION
91573       WHEN OTHERS THEN
91574          l_acc_rev_flag := 'N';
91575    END;
91576    --
91577    IF (l_acc_rev_flag = 'Y') THEN
91578 
91579        -- 4645092  ------------------------------------------------------------------------------
91580        -- To allow MPA report to determine if it should generate report process
91581        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
91582        ------------------------------------------------------------------------------------------
91583 
91584        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
91585        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
91586    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
91587    -- call ADRs
91588    -- Bug 4922099
91589    --
91590    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
91591         (NVL(l_actual_upg_option, 'N') = 'O') OR
91592         (NVL(l_enc_upg_option, 'N') = 'O')
91593       )
91594    THEN
91595    NULL;
91596    --
91597    --
91598    
91599   l_ccid := AcctDerRule_173(
91600            p_application_id           => p_application_id
91601          , p_ae_header_id             => l_ae_header_id 
91602 , p_source_3 => p_source_3
91603 , p_source_30 => p_source_30
91604          , x_transaction_coa_id       => l_adr_transaction_coa_id
91605          , x_accounting_coa_id        => l_adr_accounting_coa_id
91606          , x_value_type_code          => l_adr_value_type_code
91607          , p_side                     => 'NA'
91608    );
91609 
91610    xla_ae_lines_pkg.set_ccid(
91611     p_code_combination_id          => l_ccid
91612   , p_value_type_code              => l_adr_value_type_code
91613   , p_transaction_coa_id           => l_adr_transaction_coa_id
91614   , p_accounting_coa_id            => l_adr_accounting_coa_id
91615   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
91616   , p_adr_type_code                => 'S'
91617   , p_component_type               => l_component_type
91618   , p_component_code               => l_component_code
91619   , p_component_type_code          => l_component_type_code
91620   , p_component_appl_id            => l_component_appl_id
91621   , p_amb_context_code             => l_amb_context_code
91622   , p_side                         => 'NA'
91623   );
91624 
91625 
91626    l_segment := AcctDerRule_148(
91627            p_application_id           => p_application_id
91628          , p_ae_header_id             => l_ae_header_id 
91629 , p_source_3 => p_source_3
91630 , p_source_9 => p_source_9
91631          , x_transaction_coa_id       => l_adr_transaction_coa_id
91632          , x_accounting_coa_id        => l_adr_accounting_coa_id
91633          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
91634          , x_flex_value_set_id        => l_adr_flex_value_set_id
91635          , x_value_type_code          => l_adr_value_type_code
91636          , x_value_combination_id     => l_adr_value_combination_id
91637          , x_value_segment_code       => l_adr_value_segment_code
91638          , p_side                     => 'NA'
91642    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
91639          , p_override_seg_flag        => 'Y'
91640    );
91641 
91643 
91644       xla_ae_lines_pkg.set_segment(
91645           p_to_segment_code         => 'GL_ACCOUNT'
91646         , p_segment_value           => l_segment
91647         , p_from_segment_code       => l_adr_value_segment_code
91648         , p_from_combination_id     => l_adr_value_combination_id
91649         , p_value_type_code         => l_adr_value_type_code
91650         , p_transaction_coa_id      => l_adr_transaction_coa_id
91651         , p_accounting_coa_id       => l_adr_accounting_coa_id
91652         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
91653         , p_flex_value_set_id       => l_adr_flex_value_set_id
91654         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
91655         , p_adr_type_code           => 'S'
91656         , p_component_type          => l_component_type
91657         , p_component_code          => l_component_code
91658         , p_component_type_code     => l_component_type_code
91659         , p_component_appl_id       => l_component_appl_id
91660         , p_amb_context_code        => l_amb_context_code
91661         , p_entity_code             => 'TRANSACTIONS'
91662         , p_event_class_code        => 'CATEGORY_RECLASS'
91663         , p_side                    => 'NA'
91664         );
91665 
91666   END IF;
91667 
91668    l_segment := AcctDerRule_168(
91669            p_application_id           => p_application_id
91670          , p_ae_header_id             => l_ae_header_id 
91671 , p_source_3 => p_source_3
91672 , p_source_29 => p_source_29
91673          , x_transaction_coa_id       => l_adr_transaction_coa_id
91674          , x_accounting_coa_id        => l_adr_accounting_coa_id
91675          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
91676          , x_flex_value_set_id        => l_adr_flex_value_set_id
91677          , x_value_type_code          => l_adr_value_type_code
91678          , x_value_combination_id     => l_adr_value_combination_id
91679          , x_value_segment_code       => l_adr_value_segment_code
91680          , p_side                     => 'NA'
91681          , p_override_seg_flag        => 'Y'
91682    );
91683 
91684    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
91685 
91686       xla_ae_lines_pkg.set_segment(
91687           p_to_segment_code         => 'GL_BALANCING'
91688         , p_segment_value           => l_segment
91689         , p_from_segment_code       => l_adr_value_segment_code
91690         , p_from_combination_id     => l_adr_value_combination_id
91691         , p_value_type_code         => l_adr_value_type_code
91692         , p_transaction_coa_id      => l_adr_transaction_coa_id
91693         , p_accounting_coa_id       => l_adr_accounting_coa_id
91694         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
91695         , p_flex_value_set_id       => l_adr_flex_value_set_id
91696         , p_adr_code                => 'FA_EXPENSE_ACCT'
91697         , p_adr_type_code           => 'S'
91698         , p_component_type          => l_component_type
91699         , p_component_code          => l_component_code
91700         , p_component_type_code     => l_component_type_code
91701         , p_component_appl_id       => l_component_appl_id
91702         , p_amb_context_code        => l_amb_context_code
91703         , p_entity_code             => 'TRANSACTIONS'
91704         , p_event_class_code        => 'CATEGORY_RECLASS'
91705         , p_side                    => 'NA'
91706         );
91707 
91708   END IF;
91709 
91710    --
91711    --
91712    END IF;
91713 
91714        --
91715        -- Update the line information that should be overwritten
91716        --
91717        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
91718                                          p_header_num   => 1);
91719        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
91720 
91721        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
91722 
91723        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
91724           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
91725        END IF;
91726 
91727       --
91728       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
91729       --
91730       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
91731           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
91732       ELSE
91733           ---------------------------------------------------------------------------------------------------
91734           -- 4262811a Switch Sign
91735           ---------------------------------------------------------------------------------------------------
91736           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
91737           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
91738                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
91739           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
91740                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
91741           -- 5132302
91742           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
91743                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
91744 
91745       END IF;
91746 
91747       -- 4955764
91748       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
91752       XLA_AE_LINES_PKG.ValidateCurrentLine;
91749       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
91750 
91751 
91753       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
91754 
91755       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
91756                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
91757                ,p_balance_type_code => l_balance_type_code);
91758 
91759    END IF;
91760 
91761    -----------------------------------------------------------------------------------------
91762    -- 4262811 Multiperiod Accounting
91763    -----------------------------------------------------------------------------------------
91764      -- No MPA option is assigned.
91765 
91766 
91767 END IF;
91768 END IF;
91769 --
91770 
91771 --
91772 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
91773    trace
91774       (p_msg      => 'END of AcctLineType_281'
91775       ,p_level    => C_LEVEL_PROCEDURE
91776       ,p_module   => l_log_module);
91777 END IF;
91778 --
91779 EXCEPTION
91780   WHEN xla_exceptions_pkg.application_exception THEN
91781       RAISE;
91782   WHEN OTHERS THEN
91783        xla_exceptions_pkg.raise_message
91784            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_281');
91785 END AcctLineType_281;
91786 --
91787 
91788 ---------------------------------------
91789 --
91790 -- PRIVATE FUNCTION
91791 --         AcctLineType_282
91792 --
91793 ---------------------------------------
91794 PROCEDURE AcctLineType_282 (
91795   p_application_id        IN NUMBER
91796  ,p_event_id              IN NUMBER
91797  ,p_calculate_acctd_flag  IN VARCHAR2
91798  ,p_calculate_g_l_flag    IN VARCHAR2
91799  ,p_actual_flag           IN OUT VARCHAR2
91800  ,p_balance_type_code     OUT VARCHAR2
91801  ,p_gain_or_loss_ref      OUT VARCHAR2
91802  
91803 --Period Close Date
91804  , p_source_1            IN DATE
91805 --Generated Code Combination Identifier
91806  , p_source_3            IN NUMBER
91807 --Expense Account Code Combination Identifier
91808  , p_source_29            IN NUMBER
91809 --Adjustment Type
91810  , p_source_35            IN VARCHAR2
91811 --Transaction Header Identifier
91812  , p_source_36            IN NUMBER
91813 --Adjustment Line Identifier
91814  , p_source_37            IN NUMBER
91815 --Distribution Type Code
91816  , p_source_38            IN VARCHAR2
91817 --Entered Amount
91818  , p_source_39            IN NUMBER
91819 --Currency Code
91820  , p_source_40            IN VARCHAR2
91821 --Source Destination Code
91822  , p_source_42            IN VARCHAR2
91823 )
91824 IS
91825 
91826 l_component_type              VARCHAR2(80);
91827 l_component_code              VARCHAR2(30);
91828 l_component_type_code         VARCHAR2(1);
91829 l_component_appl_id           INTEGER;
91830 l_amb_context_code            VARCHAR2(30);
91831 l_entity_code                 VARCHAR2(30);
91832 l_event_class_code            VARCHAR2(30);
91833 l_ae_header_id                NUMBER;
91834 l_event_type_code             VARCHAR2(30);
91835 l_line_definition_code        VARCHAR2(30);
91836 l_line_definition_owner_code  VARCHAR2(1);
91837 --
91838 -- adr variables
91839 l_segment                     VARCHAR2(30);
91840 l_ccid                        NUMBER;
91841 l_adr_transaction_coa_id      NUMBER;
91842 l_adr_accounting_coa_id       NUMBER;
91843 l_adr_flexfield_segment_code  VARCHAR2(30);
91844 l_adr_flex_value_set_id       NUMBER;
91845 l_adr_value_type_code         VARCHAR2(30);
91846 l_adr_value_combination_id    NUMBER;
91847 l_adr_value_segment_code      VARCHAR2(30);
91848 
91849 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
91850 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
91851 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
91852 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
91853 
91854 -- 4262811 Variables ------------------------------------------------------------------------------------------
91855 l_entered_amt_idx             NUMBER;
91856 l_accted_amt_idx              NUMBER;
91857 l_acc_rev_flag                VARCHAR2(1);
91858 l_accrual_line_num            NUMBER;
91859 l_tmp_amt                     NUMBER;
91860 l_acc_rev_natural_side_code   VARCHAR2(1);
91861 
91862 l_num_entries                 NUMBER;
91863 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
91864 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
91865 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
91866 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
91867 l_recog_line_1                NUMBER;
91868 l_recog_line_2                NUMBER;
91869 
91870 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
91871 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
91872 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
91873 
91874 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
91875 
91876 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
91877 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
91878 
91879 ---------------------------------------------------------------------------------------------------------------
91880 
91881 
91882 --
91883 -- bulk performance
91884 --
91885 l_balance_type_code           VARCHAR2(1);
91886 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
91887 l_log_module                  VARCHAR2(240);
91888 
91889 --
91890 -- Upgrade strategy
91891 --
91895 --
91892 l_actual_upg_option           VARCHAR2(1);
91893 l_enc_upg_option           VARCHAR2(1);
91894 
91896 BEGIN
91897 --
91898 IF g_log_enabled THEN
91899       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_282';
91900 END IF;
91901 --
91902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
91903 
91904       trace
91905          (p_msg      => 'BEGIN of AcctLineType_282'
91906          ,p_level    => C_LEVEL_PROCEDURE
91907          ,p_module   => l_log_module);
91908 
91909 END IF;
91910 --
91911 l_component_type             := 'AMB_JLT';
91912 l_component_code             := 'FA_RECLASS_DEST_DEPRN_EXP';
91913 l_component_type_code        := 'S';
91914 l_component_appl_id          :=  140;
91915 l_amb_context_code           := 'DEFAULT';
91916 l_entity_code                := 'TRANSACTIONS';
91917 l_event_class_code           := 'CATEGORY_RECLASS';
91918 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
91919 l_line_definition_owner_code := 'S';
91920 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
91921 --
91922 l_balance_type_code          := 'A';
91923 l_segment                     := NULL;
91924 l_ccid                        := NULL;
91925 l_adr_transaction_coa_id      := NULL;
91926 l_adr_accounting_coa_id       := NULL;
91927 l_adr_flexfield_segment_code  := NULL;
91928 l_adr_flex_value_set_id       := NULL;
91929 l_adr_value_type_code         := NULL;
91930 l_adr_value_combination_id    := NULL;
91931 l_adr_value_segment_code      := NULL;
91932 
91933 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
91934 l_bflow_class_code           := '';    -- 4219869 Business Flow
91935 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
91936 l_budgetary_control_flag     := 'N';
91937 
91938 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
91939 l_bflow_applied_to_amt       := NULL; -- 5132302
91940 l_entered_amt_idx            := NULL;          -- 4262811
91941 l_accted_amt_idx             := NULL;          -- 4262811
91942 l_acc_rev_flag               := NULL;          -- 4262811
91943 l_accrual_line_num           := NULL;          -- 4262811
91944 l_tmp_amt                    := NULL;          -- 4262811
91945 --
91946  
91947 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
91948     l_balance_type_code <> 'B' THEN
91949 IF NVL(p_source_35,'
91950 ') =  'EXPENSE' AND 
91951 NVL(p_source_42,'
91952 ') =  'DEST'
91953  THEN 
91954 
91955    --
91956    XLA_AE_LINES_PKG.SetNewLine;
91957 
91958    p_balance_type_code          := l_balance_type_code;
91959    -- set the flag so later we will know whether the gain loss line needs to be created
91960    
91961    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
91962      p_actual_flag :='A';
91963    END IF;
91964 
91965    --
91966    -- bulk performance
91967    --
91968    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
91969                                       p_header_num   => 0); -- 4262811
91970    --
91971    -- set accounting line options
91972    --
91973    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
91974            p_natural_side_code          => 'D'
91975          , p_gain_or_loss_flag          => 'N'
91976          , p_gl_transfer_mode_code      => 'S'
91977          , p_acct_entry_type_code       => 'A'
91978          , p_switch_side_flag           => 'Y'
91979          , p_merge_duplicate_code       => 'N'
91980          );
91981    --
91982    l_acc_rev_natural_side_code := 'C';  -- 4262811
91983    -- 
91984    --
91985    -- set accounting line type info
91986    --
91987    xla_ae_lines_pkg.SetAcctLineType
91988       (p_component_type             => l_component_type
91989       ,p_event_type_code            => l_event_type_code
91990       ,p_line_definition_owner_code => l_line_definition_owner_code
91991       ,p_line_definition_code       => l_line_definition_code
91992       ,p_accounting_line_code       => l_component_code
91993       ,p_accounting_line_type_code  => l_component_type_code
91994       ,p_accounting_line_appl_id    => l_component_appl_id
91995       ,p_amb_context_code           => l_amb_context_code
91996       ,p_entity_code                => l_entity_code
91997       ,p_event_class_code           => l_event_class_code);
91998    --
91999    -- set accounting class
92000    --
92001    xla_ae_lines_pkg.SetAcctClass(
92002            p_accounting_class_code  => 'EXPENSE'
92003          , p_ae_header_id           => l_ae_header_id
92004          );
92005 
92006    --
92007    -- set rounding class
92008    --
92009    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
92010                       'EXPENSE';
92011 
92012    --
92013    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
92014    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
92015    --
92016    -- bulk performance
92017    --
92018    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
92019 
92020    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
92021       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
92022 
92023    -- 4955764
92024    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
92025       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
92026 
92027    -- 4458381 Public Sector Enh
92028    
92029    --
92030    -- set accounting attributes for the line type
92031    --
92032    l_entered_amt_idx := 4;
92033    l_accted_amt_idx  := 6;
92037    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
92034    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
92035    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
92036    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
92038    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
92039    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
92040    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
92041    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
92042    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
92043    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
92044    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
92045    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
92046    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
92047 
92048    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
92049    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
92050 
92051    ---------------------------------------------------------------------------------------------------------------
92052    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
92053    ---------------------------------------------------------------------------------------------------------------
92054    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
92055 
92056    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
92057    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
92058 
92059    IF xla_accounting_cache_pkg.GetValueChar
92060          (p_source_code         => 'LEDGER_CATEGORY_CODE'
92061          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
92062    AND l_bflow_method_code = 'PRIOR_ENTRY'
92063 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
92064    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
92065          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
92066        )
92067    THEN
92068          xla_ae_lines_pkg.BflowUpgEntry
92069            (p_business_method_code    => l_bflow_method_code
92070            ,p_business_class_code     => l_bflow_class_code
92071            ,p_balance_type            => l_balance_type_code);
92072    ELSE
92073       NULL;
92074 -- No business flow processing for business flow method of NONE.
92075    END IF;
92076 
92077    --
92078    -- call analytical criteria
92079    --
92080    
92081    --
92082    -- call description
92083    --
92084    
92085 xla_ae_lines_pkg.SetLineDescription(
92086    p_ae_header_id => l_ae_header_id
92087   ,p_description  => Description_66 (
92088      p_application_id         => p_application_id
92089    , p_ae_header_id           => l_ae_header_id 
92090 , p_source_1 => p_source_1
92091    )
92092 );
92093 
92094 
92095    --
92096    -- call ADRs
92097    -- Bug 4922099
92098    --
92099    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
92100         (NVL(l_actual_upg_option, 'N') = 'O') OR
92101         (NVL(l_enc_upg_option, 'N') = 'O')
92102       )
92103    THEN
92104    NULL;
92105    --
92106    --
92107    
92108   l_ccid := AcctDerRule_175(
92109            p_application_id           => p_application_id
92110          , p_ae_header_id             => l_ae_header_id 
92111 , p_source_3 => p_source_3
92112 , p_source_29 => p_source_29
92113          , x_transaction_coa_id       => l_adr_transaction_coa_id
92114          , x_accounting_coa_id        => l_adr_accounting_coa_id
92115          , x_value_type_code          => l_adr_value_type_code
92116          , p_side                     => 'NA'
92117    );
92118 
92119    xla_ae_lines_pkg.set_ccid(
92120     p_code_combination_id          => l_ccid
92121   , p_value_type_code              => l_adr_value_type_code
92122   , p_transaction_coa_id           => l_adr_transaction_coa_id
92123   , p_accounting_coa_id            => l_adr_accounting_coa_id
92124   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
92125   , p_adr_type_code                => 'S'
92126   , p_component_type               => l_component_type
92127   , p_component_code               => l_component_code
92128   , p_component_type_code          => l_component_type_code
92129   , p_component_appl_id            => l_component_appl_id
92130   , p_amb_context_code             => l_amb_context_code
92131   , p_side                         => 'NA'
92132   );
92133 
92134 
92135    --
92136    --
92137    END IF;
92138    --
92139    -- Bug 4922099
92140    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
92141           (NVL(l_enc_upg_option, 'N') = 'O')
92142         ) AND
92143         (l_bflow_method_code = 'PRIOR_ENTRY')
92144       )
92145    THEN
92146       IF
92147       --
92148       1 = 2
92149       --
92150       THEN
92151       xla_accounting_err_pkg.build_message
92152                                     (p_appli_s_name            => 'XLA'
92153                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
92154                                     ,p_token_1                 => 'LINE_NUMBER'
92155                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
92156                                     ,p_token_2                 => 'LINE_TYPE_NAME'
92157                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
92158                                                                              l_component_type
92159                                                                             ,l_component_code
92163                                                                             ,l_entity_code
92160                                                                             ,l_component_type_code
92161                                                                             ,l_component_appl_id
92162                                                                             ,l_amb_context_code
92164                                                                             ,l_event_class_code
92165                                                                            )
92166                                     ,p_token_3                 => 'OWNER'
92167                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
92168                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
92169                                                                           ,p_lookup_code    => l_component_type_code
92170                                                                          )
92171                                     ,p_token_4                 => 'PRODUCT_NAME'
92172                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
92173                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
92174                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
92175                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
92176                                     ,p_ae_header_id            =>  NULL
92177                                        );
92178 
92179         IF (C_LEVEL_ERROR>= g_log_level) THEN
92180                  trace
92181                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
92182                       ,p_level    => C_LEVEL_ERROR
92183                       ,p_module   => l_log_module);
92184         END IF;
92185       END IF;
92186    END IF;
92187    --
92188    --
92189    ------------------------------------------------------------------------------------------------
92190    -- 4219869 Business Flow
92191    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
92192    -- Prior Entry.  Currently, the following code is always generated.
92193    ------------------------------------------------------------------------------------------------
92194    XLA_AE_LINES_PKG.ValidateCurrentLine;
92195 
92196    ------------------------------------------------------------------------------------
92197    -- 4219869 Business Flow
92198    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
92199    ------------------------------------------------------------------------------------
92200    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
92201 
92202    ----------------------------------------------------------------------------------
92203    -- 4219869 Business Flow
92204    -- Update journal entry status -- Need to generate this within IF <condition>
92205    ----------------------------------------------------------------------------------
92206    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
92207          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
92208          ,p_balance_type_code => l_balance_type_code
92209          );
92210 
92211    -------------------------------------------------------------------------------------------
92212    -- 4262811 - Generate the Accrual Reversal lines
92213    -------------------------------------------------------------------------------------------
92214    BEGIN
92215       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
92216                               (g_array_event(p_event_id).array_value_num('header_index'));
92217       IF l_acc_rev_flag IS NULL THEN
92218          l_acc_rev_flag := 'N';
92219       END IF;
92220    EXCEPTION
92221       WHEN OTHERS THEN
92222          l_acc_rev_flag := 'N';
92223    END;
92224    --
92225    IF (l_acc_rev_flag = 'Y') THEN
92226 
92227        -- 4645092  ------------------------------------------------------------------------------
92228        -- To allow MPA report to determine if it should generate report process
92229        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
92230        ------------------------------------------------------------------------------------------
92231 
92232        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
92233        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
92234    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
92235    -- call ADRs
92236    -- Bug 4922099
92237    --
92238    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
92239         (NVL(l_actual_upg_option, 'N') = 'O') OR
92240         (NVL(l_enc_upg_option, 'N') = 'O')
92241       )
92242    THEN
92243    NULL;
92244    --
92245    --
92246    
92247   l_ccid := AcctDerRule_175(
92248            p_application_id           => p_application_id
92249          , p_ae_header_id             => l_ae_header_id 
92250 , p_source_3 => p_source_3
92251 , p_source_29 => p_source_29
92252          , x_transaction_coa_id       => l_adr_transaction_coa_id
92253          , x_accounting_coa_id        => l_adr_accounting_coa_id
92254          , x_value_type_code          => l_adr_value_type_code
92255          , p_side                     => 'NA'
92256    );
92257 
92258    xla_ae_lines_pkg.set_ccid(
92259     p_code_combination_id          => l_ccid
92260   , p_value_type_code              => l_adr_value_type_code
92261   , p_transaction_coa_id           => l_adr_transaction_coa_id
92262   , p_accounting_coa_id            => l_adr_accounting_coa_id
92263   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
92264   , p_adr_type_code                => 'S'
92265   , p_component_type               => l_component_type
92266   , p_component_code               => l_component_code
92270   , p_side                         => 'NA'
92267   , p_component_type_code          => l_component_type_code
92268   , p_component_appl_id            => l_component_appl_id
92269   , p_amb_context_code             => l_amb_context_code
92271   );
92272 
92273 
92274    --
92275    --
92276    END IF;
92277 
92278        --
92279        -- Update the line information that should be overwritten
92280        --
92281        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
92282                                          p_header_num   => 1);
92283        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
92284 
92285        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
92286 
92287        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
92288           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
92289        END IF;
92290 
92291       --
92292       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
92293       --
92294       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
92295           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
92296       ELSE
92297           ---------------------------------------------------------------------------------------------------
92298           -- 4262811a Switch Sign
92299           ---------------------------------------------------------------------------------------------------
92300           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
92301           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
92302                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
92303           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
92304                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
92305           -- 5132302
92306           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
92307                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
92308 
92309       END IF;
92310 
92311       -- 4955764
92312       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
92313       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
92314 
92315 
92316       XLA_AE_LINES_PKG.ValidateCurrentLine;
92317       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
92318 
92319       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
92320                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
92321                ,p_balance_type_code => l_balance_type_code);
92322 
92323    END IF;
92324 
92325    -----------------------------------------------------------------------------------------
92326    -- 4262811 Multiperiod Accounting
92327    -----------------------------------------------------------------------------------------
92328      -- No MPA option is assigned.
92329 
92330 
92331 END IF;
92332 END IF;
92333 --
92334 
92335 --
92336 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
92337    trace
92338       (p_msg      => 'END of AcctLineType_282'
92339       ,p_level    => C_LEVEL_PROCEDURE
92340       ,p_module   => l_log_module);
92341 END IF;
92342 --
92343 EXCEPTION
92344   WHEN xla_exceptions_pkg.application_exception THEN
92345       RAISE;
92346   WHEN OTHERS THEN
92347        xla_exceptions_pkg.raise_message
92348            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_282');
92349 END AcctLineType_282;
92350 --
92351 
92352 ---------------------------------------
92353 --
92354 -- PRIVATE FUNCTION
92355 --         AcctLineType_283
92356 --
92357 ---------------------------------------
92358 PROCEDURE AcctLineType_283 (
92359   p_application_id        IN NUMBER
92360  ,p_event_id              IN NUMBER
92361  ,p_calculate_acctd_flag  IN VARCHAR2
92362  ,p_calculate_g_l_flag    IN VARCHAR2
92363  ,p_actual_flag           IN OUT VARCHAR2
92364  ,p_balance_type_code     OUT VARCHAR2
92365  ,p_gain_or_loss_ref      OUT VARCHAR2
92366  
92367 --Period Close Date
92368  , p_source_1            IN DATE
92369 --Generated Code Combination Identifier
92370  , p_source_3            IN NUMBER
92371 --Depreciation Reserve Account
92372  , p_source_10            IN VARCHAR2
92373 --Expense Account Code Combination Identifier
92374  , p_source_29            IN NUMBER
92375 --Default Code Combination Identifier
92376  , p_source_30            IN NUMBER
92377 --Adjustment Type
92378  , p_source_35            IN VARCHAR2
92379 --Transaction Header Identifier
92380  , p_source_36            IN NUMBER
92381 --Adjustment Line Identifier
92382  , p_source_37            IN NUMBER
92383 --Distribution Type Code
92384  , p_source_38            IN VARCHAR2
92385 --Entered Amount
92386  , p_source_39            IN NUMBER
92387 --Currency Code
92388  , p_source_40            IN VARCHAR2
92389 --Source Destination Code
92390  , p_source_42            IN VARCHAR2
92391 )
92392 IS
92393 
92394 l_component_type              VARCHAR2(80);
92395 l_component_code              VARCHAR2(30);
92396 l_component_type_code         VARCHAR2(1);
92397 l_component_appl_id           INTEGER;
92398 l_amb_context_code            VARCHAR2(30);
92399 l_entity_code                 VARCHAR2(30);
92400 l_event_class_code            VARCHAR2(30);
92401 l_ae_header_id                NUMBER;
92402 l_event_type_code             VARCHAR2(30);
92406 -- adr variables
92403 l_line_definition_code        VARCHAR2(30);
92404 l_line_definition_owner_code  VARCHAR2(1);
92405 --
92407 l_segment                     VARCHAR2(30);
92408 l_ccid                        NUMBER;
92409 l_adr_transaction_coa_id      NUMBER;
92410 l_adr_accounting_coa_id       NUMBER;
92411 l_adr_flexfield_segment_code  VARCHAR2(30);
92412 l_adr_flex_value_set_id       NUMBER;
92413 l_adr_value_type_code         VARCHAR2(30);
92414 l_adr_value_combination_id    NUMBER;
92415 l_adr_value_segment_code      VARCHAR2(30);
92416 
92417 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
92418 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
92419 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
92420 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
92421 
92422 -- 4262811 Variables ------------------------------------------------------------------------------------------
92423 l_entered_amt_idx             NUMBER;
92424 l_accted_amt_idx              NUMBER;
92425 l_acc_rev_flag                VARCHAR2(1);
92426 l_accrual_line_num            NUMBER;
92427 l_tmp_amt                     NUMBER;
92428 l_acc_rev_natural_side_code   VARCHAR2(1);
92429 
92430 l_num_entries                 NUMBER;
92431 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
92432 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
92433 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
92434 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
92435 l_recog_line_1                NUMBER;
92436 l_recog_line_2                NUMBER;
92437 
92438 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
92439 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
92440 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
92441 
92442 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
92443 
92444 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
92445 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
92446 
92447 ---------------------------------------------------------------------------------------------------------------
92448 
92449 
92450 --
92451 -- bulk performance
92452 --
92453 l_balance_type_code           VARCHAR2(1);
92454 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
92455 l_log_module                  VARCHAR2(240);
92456 
92457 --
92458 -- Upgrade strategy
92459 --
92460 l_actual_upg_option           VARCHAR2(1);
92461 l_enc_upg_option           VARCHAR2(1);
92462 
92463 --
92464 BEGIN
92465 --
92466 IF g_log_enabled THEN
92467       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_283';
92468 END IF;
92469 --
92470 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
92471 
92472       trace
92473          (p_msg      => 'BEGIN of AcctLineType_283'
92474          ,p_level    => C_LEVEL_PROCEDURE
92475          ,p_module   => l_log_module);
92476 
92477 END IF;
92478 --
92479 l_component_type             := 'AMB_JLT';
92480 l_component_code             := 'FA_RECLASS_DEST_DEPRN_RESERVE';
92481 l_component_type_code        := 'S';
92482 l_component_appl_id          :=  140;
92483 l_amb_context_code           := 'DEFAULT';
92484 l_entity_code                := 'TRANSACTIONS';
92485 l_event_class_code           := 'CATEGORY_RECLASS';
92486 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
92487 l_line_definition_owner_code := 'S';
92488 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
92489 --
92490 l_balance_type_code          := 'A';
92491 l_segment                     := NULL;
92492 l_ccid                        := NULL;
92493 l_adr_transaction_coa_id      := NULL;
92494 l_adr_accounting_coa_id       := NULL;
92495 l_adr_flexfield_segment_code  := NULL;
92496 l_adr_flex_value_set_id       := NULL;
92497 l_adr_value_type_code         := NULL;
92498 l_adr_value_combination_id    := NULL;
92499 l_adr_value_segment_code      := NULL;
92500 
92501 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
92502 l_bflow_class_code           := '';    -- 4219869 Business Flow
92503 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
92504 l_budgetary_control_flag     := 'N';
92505 
92506 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
92507 l_bflow_applied_to_amt       := NULL; -- 5132302
92508 l_entered_amt_idx            := NULL;          -- 4262811
92509 l_accted_amt_idx             := NULL;          -- 4262811
92510 l_acc_rev_flag               := NULL;          -- 4262811
92511 l_accrual_line_num           := NULL;          -- 4262811
92512 l_tmp_amt                    := NULL;          -- 4262811
92513 --
92514  
92515 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
92516     l_balance_type_code <> 'B' THEN
92517 IF (NVL(p_source_35,'
92518 ') =  'EXPENSE' OR 
92519 NVL(p_source_35,'
92520 ') =  'RESERVE') AND 
92521 NVL(p_source_42,'
92522 ') =  'DEST'
92523  THEN 
92524 
92525    --
92526    XLA_AE_LINES_PKG.SetNewLine;
92527 
92528    p_balance_type_code          := l_balance_type_code;
92529    -- set the flag so later we will know whether the gain loss line needs to be created
92530    
92531    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
92532      p_actual_flag :='A';
92533    END IF;
92534 
92535    --
92536    -- bulk performance
92537    --
92538    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
92539                                       p_header_num   => 0); -- 4262811
92540    --
92541    -- set accounting line options
92542    --
92546          , p_gl_transfer_mode_code      => 'S'
92543    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
92544            p_natural_side_code          => 'C'
92545          , p_gain_or_loss_flag          => 'N'
92547          , p_acct_entry_type_code       => 'A'
92548          , p_switch_side_flag           => 'Y'
92549          , p_merge_duplicate_code       => 'N'
92550          );
92551    --
92552    l_acc_rev_natural_side_code := 'D';  -- 4262811
92553    -- 
92554    --
92555    -- set accounting line type info
92556    --
92557    xla_ae_lines_pkg.SetAcctLineType
92558       (p_component_type             => l_component_type
92559       ,p_event_type_code            => l_event_type_code
92560       ,p_line_definition_owner_code => l_line_definition_owner_code
92561       ,p_line_definition_code       => l_line_definition_code
92562       ,p_accounting_line_code       => l_component_code
92563       ,p_accounting_line_type_code  => l_component_type_code
92564       ,p_accounting_line_appl_id    => l_component_appl_id
92565       ,p_amb_context_code           => l_amb_context_code
92566       ,p_entity_code                => l_entity_code
92567       ,p_event_class_code           => l_event_class_code);
92568    --
92569    -- set accounting class
92570    --
92571    xla_ae_lines_pkg.SetAcctClass(
92572            p_accounting_class_code  => 'ASSET'
92573          , p_ae_header_id           => l_ae_header_id
92574          );
92575 
92576    --
92577    -- set rounding class
92578    --
92579    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
92580                       'ASSET';
92581 
92582    --
92583    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
92584    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
92585    --
92586    -- bulk performance
92587    --
92588    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
92589 
92590    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
92591       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
92592 
92593    -- 4955764
92594    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
92595       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
92596 
92597    -- 4458381 Public Sector Enh
92598    
92599    --
92600    -- set accounting attributes for the line type
92601    --
92602    l_entered_amt_idx := 4;
92603    l_accted_amt_idx  := 6;
92604    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
92605    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
92606    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
92607    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
92608    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
92609    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
92610    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
92611    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
92612    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
92613    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
92614    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
92615    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
92616    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
92617 
92618    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
92619    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
92620 
92621    ---------------------------------------------------------------------------------------------------------------
92622    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
92623    ---------------------------------------------------------------------------------------------------------------
92624    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
92625 
92626    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
92627    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
92628 
92629    IF xla_accounting_cache_pkg.GetValueChar
92630          (p_source_code         => 'LEDGER_CATEGORY_CODE'
92631          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
92632    AND l_bflow_method_code = 'PRIOR_ENTRY'
92633 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
92634    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
92635          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
92636        )
92637    THEN
92638          xla_ae_lines_pkg.BflowUpgEntry
92639            (p_business_method_code    => l_bflow_method_code
92640            ,p_business_class_code     => l_bflow_class_code
92641            ,p_balance_type            => l_balance_type_code);
92642    ELSE
92643       NULL;
92644 -- No business flow processing for business flow method of NONE.
92645    END IF;
92646 
92647    --
92648    -- call analytical criteria
92649    --
92650    
92651    --
92652    -- call description
92653    --
92654    
92655 xla_ae_lines_pkg.SetLineDescription(
92656    p_ae_header_id => l_ae_header_id
92657   ,p_description  => Description_67 (
92658      p_application_id         => p_application_id
92659    , p_ae_header_id           => l_ae_header_id 
92660 , p_source_1 => p_source_1
92661    )
92662 );
92663 
92664 
92665    --
92666    -- call ADRs
92667    -- Bug 4922099
92668    --
92669    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
92673    THEN
92670         (NVL(l_actual_upg_option, 'N') = 'O') OR
92671         (NVL(l_enc_upg_option, 'N') = 'O')
92672       )
92674    NULL;
92675    --
92676    --
92677    
92678   l_ccid := AcctDerRule_173(
92679            p_application_id           => p_application_id
92680          , p_ae_header_id             => l_ae_header_id 
92681 , p_source_3 => p_source_3
92682 , p_source_30 => p_source_30
92683          , x_transaction_coa_id       => l_adr_transaction_coa_id
92684          , x_accounting_coa_id        => l_adr_accounting_coa_id
92685          , x_value_type_code          => l_adr_value_type_code
92686          , p_side                     => 'NA'
92687    );
92688 
92689    xla_ae_lines_pkg.set_ccid(
92690     p_code_combination_id          => l_ccid
92691   , p_value_type_code              => l_adr_value_type_code
92692   , p_transaction_coa_id           => l_adr_transaction_coa_id
92693   , p_accounting_coa_id            => l_adr_accounting_coa_id
92694   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
92695   , p_adr_type_code                => 'S'
92696   , p_component_type               => l_component_type
92697   , p_component_code               => l_component_code
92698   , p_component_type_code          => l_component_type_code
92699   , p_component_appl_id            => l_component_appl_id
92700   , p_amb_context_code             => l_amb_context_code
92701   , p_side                         => 'NA'
92702   );
92703 
92704 
92705    l_segment := AcctDerRule_149(
92706            p_application_id           => p_application_id
92707          , p_ae_header_id             => l_ae_header_id 
92708 , p_source_3 => p_source_3
92709 , p_source_10 => p_source_10
92710          , x_transaction_coa_id       => l_adr_transaction_coa_id
92711          , x_accounting_coa_id        => l_adr_accounting_coa_id
92712          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
92713          , x_flex_value_set_id        => l_adr_flex_value_set_id
92714          , x_value_type_code          => l_adr_value_type_code
92715          , x_value_combination_id     => l_adr_value_combination_id
92716          , x_value_segment_code       => l_adr_value_segment_code
92717          , p_side                     => 'NA'
92718          , p_override_seg_flag        => 'Y'
92719    );
92720 
92721    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
92722 
92723       xla_ae_lines_pkg.set_segment(
92724           p_to_segment_code         => 'GL_ACCOUNT'
92725         , p_segment_value           => l_segment
92726         , p_from_segment_code       => l_adr_value_segment_code
92727         , p_from_combination_id     => l_adr_value_combination_id
92728         , p_value_type_code         => l_adr_value_type_code
92729         , p_transaction_coa_id      => l_adr_transaction_coa_id
92730         , p_accounting_coa_id       => l_adr_accounting_coa_id
92731         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
92732         , p_flex_value_set_id       => l_adr_flex_value_set_id
92733         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
92734         , p_adr_type_code           => 'S'
92735         , p_component_type          => l_component_type
92736         , p_component_code          => l_component_code
92737         , p_component_type_code     => l_component_type_code
92738         , p_component_appl_id       => l_component_appl_id
92739         , p_amb_context_code        => l_amb_context_code
92740         , p_entity_code             => 'TRANSACTIONS'
92741         , p_event_class_code        => 'CATEGORY_RECLASS'
92742         , p_side                    => 'NA'
92743         );
92744 
92745   END IF;
92746 
92747    l_segment := AcctDerRule_168(
92748            p_application_id           => p_application_id
92749          , p_ae_header_id             => l_ae_header_id 
92750 , p_source_3 => p_source_3
92751 , p_source_29 => p_source_29
92752          , x_transaction_coa_id       => l_adr_transaction_coa_id
92753          , x_accounting_coa_id        => l_adr_accounting_coa_id
92754          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
92755          , x_flex_value_set_id        => l_adr_flex_value_set_id
92756          , x_value_type_code          => l_adr_value_type_code
92757          , x_value_combination_id     => l_adr_value_combination_id
92758          , x_value_segment_code       => l_adr_value_segment_code
92759          , p_side                     => 'NA'
92760          , p_override_seg_flag        => 'Y'
92761    );
92762 
92763    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
92764 
92765       xla_ae_lines_pkg.set_segment(
92766           p_to_segment_code         => 'GL_BALANCING'
92767         , p_segment_value           => l_segment
92768         , p_from_segment_code       => l_adr_value_segment_code
92769         , p_from_combination_id     => l_adr_value_combination_id
92770         , p_value_type_code         => l_adr_value_type_code
92771         , p_transaction_coa_id      => l_adr_transaction_coa_id
92772         , p_accounting_coa_id       => l_adr_accounting_coa_id
92773         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
92774         , p_flex_value_set_id       => l_adr_flex_value_set_id
92775         , p_adr_code                => 'FA_EXPENSE_ACCT'
92776         , p_adr_type_code           => 'S'
92777         , p_component_type          => l_component_type
92778         , p_component_code          => l_component_code
92779         , p_component_type_code     => l_component_type_code
92780         , p_component_appl_id       => l_component_appl_id
92781         , p_amb_context_code        => l_amb_context_code
92782         , p_entity_code             => 'TRANSACTIONS'
92783         , p_event_class_code        => 'CATEGORY_RECLASS'
92784         , p_side                    => 'NA'
92785         );
92786 
92787   END IF;
92788 
92789    --
92790    --
92791    END IF;
92792    --
92796         ) AND
92793    -- Bug 4922099
92794    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
92795           (NVL(l_enc_upg_option, 'N') = 'O')
92797         (l_bflow_method_code = 'PRIOR_ENTRY')
92798       )
92799    THEN
92800       IF
92801       --
92802       1 = 2
92803       --
92804       THEN
92805       xla_accounting_err_pkg.build_message
92806                                     (p_appli_s_name            => 'XLA'
92807                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
92808                                     ,p_token_1                 => 'LINE_NUMBER'
92809                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
92810                                     ,p_token_2                 => 'LINE_TYPE_NAME'
92811                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
92812                                                                              l_component_type
92813                                                                             ,l_component_code
92814                                                                             ,l_component_type_code
92815                                                                             ,l_component_appl_id
92816                                                                             ,l_amb_context_code
92817                                                                             ,l_entity_code
92818                                                                             ,l_event_class_code
92819                                                                            )
92820                                     ,p_token_3                 => 'OWNER'
92821                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
92822                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
92823                                                                           ,p_lookup_code    => l_component_type_code
92824                                                                          )
92825                                     ,p_token_4                 => 'PRODUCT_NAME'
92826                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
92827                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
92828                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
92829                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
92830                                     ,p_ae_header_id            =>  NULL
92831                                        );
92832 
92833         IF (C_LEVEL_ERROR>= g_log_level) THEN
92834                  trace
92835                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
92836                       ,p_level    => C_LEVEL_ERROR
92837                       ,p_module   => l_log_module);
92838         END IF;
92839       END IF;
92840    END IF;
92841    --
92842    --
92843    ------------------------------------------------------------------------------------------------
92844    -- 4219869 Business Flow
92845    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
92846    -- Prior Entry.  Currently, the following code is always generated.
92847    ------------------------------------------------------------------------------------------------
92848    XLA_AE_LINES_PKG.ValidateCurrentLine;
92849 
92850    ------------------------------------------------------------------------------------
92851    -- 4219869 Business Flow
92852    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
92853    ------------------------------------------------------------------------------------
92854    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
92855 
92856    ----------------------------------------------------------------------------------
92857    -- 4219869 Business Flow
92858    -- Update journal entry status -- Need to generate this within IF <condition>
92859    ----------------------------------------------------------------------------------
92860    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
92861          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
92862          ,p_balance_type_code => l_balance_type_code
92863          );
92864 
92865    -------------------------------------------------------------------------------------------
92866    -- 4262811 - Generate the Accrual Reversal lines
92867    -------------------------------------------------------------------------------------------
92868    BEGIN
92869       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
92870                               (g_array_event(p_event_id).array_value_num('header_index'));
92871       IF l_acc_rev_flag IS NULL THEN
92872          l_acc_rev_flag := 'N';
92873       END IF;
92874    EXCEPTION
92875       WHEN OTHERS THEN
92876          l_acc_rev_flag := 'N';
92877    END;
92878    --
92879    IF (l_acc_rev_flag = 'Y') THEN
92880 
92881        -- 4645092  ------------------------------------------------------------------------------
92882        -- To allow MPA report to determine if it should generate report process
92883        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
92884        ------------------------------------------------------------------------------------------
92885 
92886        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
92887        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
92888    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
92889    -- call ADRs
92890    -- Bug 4922099
92891    --
92892    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
92893         (NVL(l_actual_upg_option, 'N') = 'O') OR
92894         (NVL(l_enc_upg_option, 'N') = 'O')
92895       )
92899    --
92896    THEN
92897    NULL;
92898    --
92900    
92901   l_ccid := AcctDerRule_173(
92902            p_application_id           => p_application_id
92903          , p_ae_header_id             => l_ae_header_id 
92904 , p_source_3 => p_source_3
92905 , p_source_30 => p_source_30
92906          , x_transaction_coa_id       => l_adr_transaction_coa_id
92907          , x_accounting_coa_id        => l_adr_accounting_coa_id
92908          , x_value_type_code          => l_adr_value_type_code
92909          , p_side                     => 'NA'
92910    );
92911 
92912    xla_ae_lines_pkg.set_ccid(
92913     p_code_combination_id          => l_ccid
92914   , p_value_type_code              => l_adr_value_type_code
92915   , p_transaction_coa_id           => l_adr_transaction_coa_id
92916   , p_accounting_coa_id            => l_adr_accounting_coa_id
92917   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
92918   , p_adr_type_code                => 'S'
92919   , p_component_type               => l_component_type
92920   , p_component_code               => l_component_code
92921   , p_component_type_code          => l_component_type_code
92922   , p_component_appl_id            => l_component_appl_id
92923   , p_amb_context_code             => l_amb_context_code
92924   , p_side                         => 'NA'
92925   );
92926 
92927 
92928    l_segment := AcctDerRule_149(
92929            p_application_id           => p_application_id
92930          , p_ae_header_id             => l_ae_header_id 
92931 , p_source_3 => p_source_3
92932 , p_source_10 => p_source_10
92933          , x_transaction_coa_id       => l_adr_transaction_coa_id
92934          , x_accounting_coa_id        => l_adr_accounting_coa_id
92935          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
92936          , x_flex_value_set_id        => l_adr_flex_value_set_id
92937          , x_value_type_code          => l_adr_value_type_code
92938          , x_value_combination_id     => l_adr_value_combination_id
92939          , x_value_segment_code       => l_adr_value_segment_code
92940          , p_side                     => 'NA'
92941          , p_override_seg_flag        => 'Y'
92942    );
92943 
92944    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
92945 
92946       xla_ae_lines_pkg.set_segment(
92947           p_to_segment_code         => 'GL_ACCOUNT'
92948         , p_segment_value           => l_segment
92949         , p_from_segment_code       => l_adr_value_segment_code
92950         , p_from_combination_id     => l_adr_value_combination_id
92951         , p_value_type_code         => l_adr_value_type_code
92952         , p_transaction_coa_id      => l_adr_transaction_coa_id
92953         , p_accounting_coa_id       => l_adr_accounting_coa_id
92954         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
92955         , p_flex_value_set_id       => l_adr_flex_value_set_id
92956         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
92957         , p_adr_type_code           => 'S'
92958         , p_component_type          => l_component_type
92959         , p_component_code          => l_component_code
92960         , p_component_type_code     => l_component_type_code
92961         , p_component_appl_id       => l_component_appl_id
92962         , p_amb_context_code        => l_amb_context_code
92963         , p_entity_code             => 'TRANSACTIONS'
92964         , p_event_class_code        => 'CATEGORY_RECLASS'
92965         , p_side                    => 'NA'
92966         );
92967 
92968   END IF;
92969 
92970    l_segment := AcctDerRule_168(
92971            p_application_id           => p_application_id
92972          , p_ae_header_id             => l_ae_header_id 
92973 , p_source_3 => p_source_3
92974 , p_source_29 => p_source_29
92975          , x_transaction_coa_id       => l_adr_transaction_coa_id
92976          , x_accounting_coa_id        => l_adr_accounting_coa_id
92977          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
92978          , x_flex_value_set_id        => l_adr_flex_value_set_id
92979          , x_value_type_code          => l_adr_value_type_code
92980          , x_value_combination_id     => l_adr_value_combination_id
92981          , x_value_segment_code       => l_adr_value_segment_code
92982          , p_side                     => 'NA'
92983          , p_override_seg_flag        => 'Y'
92984    );
92985 
92986    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
92987 
92988       xla_ae_lines_pkg.set_segment(
92989           p_to_segment_code         => 'GL_BALANCING'
92990         , p_segment_value           => l_segment
92991         , p_from_segment_code       => l_adr_value_segment_code
92992         , p_from_combination_id     => l_adr_value_combination_id
92993         , p_value_type_code         => l_adr_value_type_code
92994         , p_transaction_coa_id      => l_adr_transaction_coa_id
92995         , p_accounting_coa_id       => l_adr_accounting_coa_id
92996         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
92997         , p_flex_value_set_id       => l_adr_flex_value_set_id
92998         , p_adr_code                => 'FA_EXPENSE_ACCT'
92999         , p_adr_type_code           => 'S'
93000         , p_component_type          => l_component_type
93001         , p_component_code          => l_component_code
93002         , p_component_type_code     => l_component_type_code
93003         , p_component_appl_id       => l_component_appl_id
93004         , p_amb_context_code        => l_amb_context_code
93005         , p_entity_code             => 'TRANSACTIONS'
93006         , p_event_class_code        => 'CATEGORY_RECLASS'
93007         , p_side                    => 'NA'
93008         );
93009 
93010   END IF;
93011 
93012    --
93013    --
93014    END IF;
93015 
93016        --
93017        -- Update the line information that should be overwritten
93018        --
93022 
93019        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
93020                                          p_header_num   => 1);
93021        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
93023        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
93024 
93025        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
93026           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
93027        END IF;
93028 
93029       --
93030       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
93031       --
93032       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
93033           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
93034       ELSE
93035           ---------------------------------------------------------------------------------------------------
93036           -- 4262811a Switch Sign
93037           ---------------------------------------------------------------------------------------------------
93038           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
93039           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
93040                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
93041           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
93042                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
93043           -- 5132302
93044           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
93045                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
93046 
93047       END IF;
93048 
93049       -- 4955764
93050       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
93051       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
93052 
93053 
93054       XLA_AE_LINES_PKG.ValidateCurrentLine;
93055       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
93056 
93057       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
93058                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
93059                ,p_balance_type_code => l_balance_type_code);
93060 
93061    END IF;
93062 
93063    -----------------------------------------------------------------------------------------
93064    -- 4262811 Multiperiod Accounting
93065    -----------------------------------------------------------------------------------------
93066      -- No MPA option is assigned.
93067 
93068 
93069 END IF;
93070 END IF;
93071 --
93072 
93073 --
93074 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
93075    trace
93076       (p_msg      => 'END of AcctLineType_283'
93077       ,p_level    => C_LEVEL_PROCEDURE
93078       ,p_module   => l_log_module);
93079 END IF;
93080 --
93081 EXCEPTION
93082   WHEN xla_exceptions_pkg.application_exception THEN
93083       RAISE;
93084   WHEN OTHERS THEN
93085        xla_exceptions_pkg.raise_message
93086            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_283');
93087 END AcctLineType_283;
93088 --
93089 
93090 ---------------------------------------
93091 --
93092 -- PRIVATE FUNCTION
93093 --         AcctLineType_284
93094 --
93095 ---------------------------------------
93096 PROCEDURE AcctLineType_284 (
93097   p_application_id        IN NUMBER
93098  ,p_event_id              IN NUMBER
93099  ,p_calculate_acctd_flag  IN VARCHAR2
93100  ,p_calculate_g_l_flag    IN VARCHAR2
93101  ,p_actual_flag           IN OUT VARCHAR2
93102  ,p_balance_type_code     OUT VARCHAR2
93103  ,p_gain_or_loss_ref      OUT VARCHAR2
93104  
93105 --Period Close Date
93106  , p_source_1            IN DATE
93107 --Generated Code Combination Identifier
93108  , p_source_3            IN NUMBER
93109 --Revaluation Reserve Account
93110  , p_source_11            IN VARCHAR2
93111 --Expense Account Code Combination Identifier
93112  , p_source_29            IN NUMBER
93113 --Default Code Combination Identifier
93114  , p_source_30            IN NUMBER
93115 --Adjustment Type
93116  , p_source_35            IN VARCHAR2
93117 --Transaction Header Identifier
93118  , p_source_36            IN NUMBER
93119 --Adjustment Line Identifier
93120  , p_source_37            IN NUMBER
93121 --Distribution Type Code
93122  , p_source_38            IN VARCHAR2
93123 --Entered Amount
93124  , p_source_39            IN NUMBER
93125 --Currency Code
93126  , p_source_40            IN VARCHAR2
93127 --Source Destination Code
93128  , p_source_42            IN VARCHAR2
93129 )
93130 IS
93131 
93132 l_component_type              VARCHAR2(80);
93133 l_component_code              VARCHAR2(30);
93134 l_component_type_code         VARCHAR2(1);
93135 l_component_appl_id           INTEGER;
93136 l_amb_context_code            VARCHAR2(30);
93137 l_entity_code                 VARCHAR2(30);
93138 l_event_class_code            VARCHAR2(30);
93139 l_ae_header_id                NUMBER;
93140 l_event_type_code             VARCHAR2(30);
93141 l_line_definition_code        VARCHAR2(30);
93142 l_line_definition_owner_code  VARCHAR2(1);
93143 --
93144 -- adr variables
93145 l_segment                     VARCHAR2(30);
93146 l_ccid                        NUMBER;
93147 l_adr_transaction_coa_id      NUMBER;
93148 l_adr_accounting_coa_id       NUMBER;
93149 l_adr_flexfield_segment_code  VARCHAR2(30);
93150 l_adr_flex_value_set_id       NUMBER;
93151 l_adr_value_type_code         VARCHAR2(30);
93155 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
93152 l_adr_value_combination_id    NUMBER;
93153 l_adr_value_segment_code      VARCHAR2(30);
93154 
93156 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
93157 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
93158 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
93159 
93160 -- 4262811 Variables ------------------------------------------------------------------------------------------
93161 l_entered_amt_idx             NUMBER;
93162 l_accted_amt_idx              NUMBER;
93163 l_acc_rev_flag                VARCHAR2(1);
93164 l_accrual_line_num            NUMBER;
93165 l_tmp_amt                     NUMBER;
93166 l_acc_rev_natural_side_code   VARCHAR2(1);
93167 
93168 l_num_entries                 NUMBER;
93169 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
93170 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
93171 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
93172 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
93173 l_recog_line_1                NUMBER;
93174 l_recog_line_2                NUMBER;
93175 
93176 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
93177 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
93178 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
93179 
93180 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
93181 
93182 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
93183 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
93184 
93185 ---------------------------------------------------------------------------------------------------------------
93186 
93187 
93188 --
93189 -- bulk performance
93190 --
93191 l_balance_type_code           VARCHAR2(1);
93192 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
93193 l_log_module                  VARCHAR2(240);
93194 
93195 --
93196 -- Upgrade strategy
93197 --
93198 l_actual_upg_option           VARCHAR2(1);
93199 l_enc_upg_option           VARCHAR2(1);
93200 
93201 --
93202 BEGIN
93203 --
93204 IF g_log_enabled THEN
93205       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_284';
93206 END IF;
93207 --
93208 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
93209 
93210       trace
93211          (p_msg      => 'BEGIN of AcctLineType_284'
93212          ,p_level    => C_LEVEL_PROCEDURE
93213          ,p_module   => l_log_module);
93214 
93215 END IF;
93216 --
93217 l_component_type             := 'AMB_JLT';
93218 l_component_code             := 'FA_RECLASS_DEST_REVAL_RESERVE';
93219 l_component_type_code        := 'S';
93220 l_component_appl_id          :=  140;
93221 l_amb_context_code           := 'DEFAULT';
93222 l_entity_code                := 'TRANSACTIONS';
93223 l_event_class_code           := 'CATEGORY_RECLASS';
93224 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
93225 l_line_definition_owner_code := 'S';
93226 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
93227 --
93228 l_balance_type_code          := 'A';
93229 l_segment                     := NULL;
93230 l_ccid                        := NULL;
93231 l_adr_transaction_coa_id      := NULL;
93232 l_adr_accounting_coa_id       := NULL;
93233 l_adr_flexfield_segment_code  := NULL;
93234 l_adr_flex_value_set_id       := NULL;
93235 l_adr_value_type_code         := NULL;
93236 l_adr_value_combination_id    := NULL;
93237 l_adr_value_segment_code      := NULL;
93238 
93239 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
93240 l_bflow_class_code           := '';    -- 4219869 Business Flow
93241 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
93242 l_budgetary_control_flag     := 'N';
93243 
93244 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
93245 l_bflow_applied_to_amt       := NULL; -- 5132302
93246 l_entered_amt_idx            := NULL;          -- 4262811
93247 l_accted_amt_idx             := NULL;          -- 4262811
93248 l_acc_rev_flag               := NULL;          -- 4262811
93249 l_accrual_line_num           := NULL;          -- 4262811
93250 l_tmp_amt                    := NULL;          -- 4262811
93251 --
93252  
93253 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
93254     l_balance_type_code <> 'B' THEN
93255 IF NVL(p_source_35,'
93256 ') =  'REVAL RESERVE' AND 
93257 NVL(p_source_42,'
93258 ') =  'DEST'
93259  THEN 
93260 
93261    --
93262    XLA_AE_LINES_PKG.SetNewLine;
93263 
93264    p_balance_type_code          := l_balance_type_code;
93265    -- set the flag so later we will know whether the gain loss line needs to be created
93266    
93267    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
93268      p_actual_flag :='A';
93269    END IF;
93270 
93271    --
93272    -- bulk performance
93273    --
93274    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
93275                                       p_header_num   => 0); -- 4262811
93276    --
93277    -- set accounting line options
93278    --
93279    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
93280            p_natural_side_code          => 'C'
93281          , p_gain_or_loss_flag          => 'N'
93282          , p_gl_transfer_mode_code      => 'S'
93283          , p_acct_entry_type_code       => 'A'
93284          , p_switch_side_flag           => 'Y'
93285          , p_merge_duplicate_code       => 'N'
93286          );
93287    --
93288    l_acc_rev_natural_side_code := 'D';  -- 4262811
93289    -- 
93290    --
93291    -- set accounting line type info
93295       ,p_event_type_code            => l_event_type_code
93292    --
93293    xla_ae_lines_pkg.SetAcctLineType
93294       (p_component_type             => l_component_type
93296       ,p_line_definition_owner_code => l_line_definition_owner_code
93297       ,p_line_definition_code       => l_line_definition_code
93298       ,p_accounting_line_code       => l_component_code
93299       ,p_accounting_line_type_code  => l_component_type_code
93300       ,p_accounting_line_appl_id    => l_component_appl_id
93301       ,p_amb_context_code           => l_amb_context_code
93302       ,p_entity_code                => l_entity_code
93303       ,p_event_class_code           => l_event_class_code);
93304    --
93305    -- set accounting class
93306    --
93307    xla_ae_lines_pkg.SetAcctClass(
93308            p_accounting_class_code  => 'ASSET'
93309          , p_ae_header_id           => l_ae_header_id
93310          );
93311 
93312    --
93313    -- set rounding class
93314    --
93315    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
93316                       'ASSET';
93317 
93318    --
93319    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
93320    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
93321    --
93322    -- bulk performance
93323    --
93324    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
93325 
93326    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
93327       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
93328 
93329    -- 4955764
93330    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
93331       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
93332 
93333    -- 4458381 Public Sector Enh
93334    
93335    --
93336    -- set accounting attributes for the line type
93337    --
93338    l_entered_amt_idx := 4;
93339    l_accted_amt_idx  := 6;
93340    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
93341    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
93342    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
93343    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
93344    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
93345    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
93346    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
93347    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
93348    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
93349    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
93350    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
93351    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
93352    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
93353 
93354    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
93355    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
93356 
93357    ---------------------------------------------------------------------------------------------------------------
93358    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
93359    ---------------------------------------------------------------------------------------------------------------
93360    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
93361 
93362    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
93363    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
93364 
93365    IF xla_accounting_cache_pkg.GetValueChar
93366          (p_source_code         => 'LEDGER_CATEGORY_CODE'
93367          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
93368    AND l_bflow_method_code = 'PRIOR_ENTRY'
93369 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
93370    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
93371          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
93372        )
93373    THEN
93374          xla_ae_lines_pkg.BflowUpgEntry
93375            (p_business_method_code    => l_bflow_method_code
93376            ,p_business_class_code     => l_bflow_class_code
93377            ,p_balance_type            => l_balance_type_code);
93378    ELSE
93379       NULL;
93380 -- No business flow processing for business flow method of NONE.
93381    END IF;
93382 
93383    --
93384    -- call analytical criteria
93385    --
93386    
93387    --
93388    -- call description
93389    --
93390    
93391 xla_ae_lines_pkg.SetLineDescription(
93392    p_ae_header_id => l_ae_header_id
93393   ,p_description  => Description_68 (
93394      p_application_id         => p_application_id
93395    , p_ae_header_id           => l_ae_header_id 
93396 , p_source_1 => p_source_1
93397    )
93398 );
93399 
93400 
93401    --
93402    -- call ADRs
93403    -- Bug 4922099
93404    --
93405    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
93406         (NVL(l_actual_upg_option, 'N') = 'O') OR
93407         (NVL(l_enc_upg_option, 'N') = 'O')
93408       )
93409    THEN
93410    NULL;
93411    --
93412    --
93413    
93414   l_ccid := AcctDerRule_173(
93415            p_application_id           => p_application_id
93416          , p_ae_header_id             => l_ae_header_id 
93417 , p_source_3 => p_source_3
93418 , p_source_30 => p_source_30
93419          , x_transaction_coa_id       => l_adr_transaction_coa_id
93420          , x_accounting_coa_id        => l_adr_accounting_coa_id
93424 
93421          , x_value_type_code          => l_adr_value_type_code
93422          , p_side                     => 'NA'
93423    );
93425    xla_ae_lines_pkg.set_ccid(
93426     p_code_combination_id          => l_ccid
93427   , p_value_type_code              => l_adr_value_type_code
93428   , p_transaction_coa_id           => l_adr_transaction_coa_id
93429   , p_accounting_coa_id            => l_adr_accounting_coa_id
93430   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
93431   , p_adr_type_code                => 'S'
93432   , p_component_type               => l_component_type
93433   , p_component_code               => l_component_code
93434   , p_component_type_code          => l_component_type_code
93435   , p_component_appl_id            => l_component_appl_id
93436   , p_amb_context_code             => l_amb_context_code
93437   , p_side                         => 'NA'
93438   );
93439 
93440 
93441    l_segment := AcctDerRule_150(
93442            p_application_id           => p_application_id
93443          , p_ae_header_id             => l_ae_header_id 
93444 , p_source_3 => p_source_3
93445 , p_source_11 => p_source_11
93446          , x_transaction_coa_id       => l_adr_transaction_coa_id
93447          , x_accounting_coa_id        => l_adr_accounting_coa_id
93448          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
93449          , x_flex_value_set_id        => l_adr_flex_value_set_id
93450          , x_value_type_code          => l_adr_value_type_code
93451          , x_value_combination_id     => l_adr_value_combination_id
93452          , x_value_segment_code       => l_adr_value_segment_code
93453          , p_side                     => 'NA'
93454          , p_override_seg_flag        => 'Y'
93455    );
93456 
93457    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
93458 
93459       xla_ae_lines_pkg.set_segment(
93460           p_to_segment_code         => 'GL_ACCOUNT'
93461         , p_segment_value           => l_segment
93462         , p_from_segment_code       => l_adr_value_segment_code
93463         , p_from_combination_id     => l_adr_value_combination_id
93464         , p_value_type_code         => l_adr_value_type_code
93465         , p_transaction_coa_id      => l_adr_transaction_coa_id
93466         , p_accounting_coa_id       => l_adr_accounting_coa_id
93467         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
93468         , p_flex_value_set_id       => l_adr_flex_value_set_id
93469         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
93470         , p_adr_type_code           => 'S'
93471         , p_component_type          => l_component_type
93472         , p_component_code          => l_component_code
93473         , p_component_type_code     => l_component_type_code
93474         , p_component_appl_id       => l_component_appl_id
93475         , p_amb_context_code        => l_amb_context_code
93476         , p_entity_code             => 'TRANSACTIONS'
93477         , p_event_class_code        => 'CATEGORY_RECLASS'
93478         , p_side                    => 'NA'
93479         );
93480 
93481   END IF;
93482 
93483    l_segment := AcctDerRule_168(
93484            p_application_id           => p_application_id
93485          , p_ae_header_id             => l_ae_header_id 
93486 , p_source_3 => p_source_3
93487 , p_source_29 => p_source_29
93488          , x_transaction_coa_id       => l_adr_transaction_coa_id
93489          , x_accounting_coa_id        => l_adr_accounting_coa_id
93490          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
93491          , x_flex_value_set_id        => l_adr_flex_value_set_id
93492          , x_value_type_code          => l_adr_value_type_code
93493          , x_value_combination_id     => l_adr_value_combination_id
93494          , x_value_segment_code       => l_adr_value_segment_code
93495          , p_side                     => 'NA'
93496          , p_override_seg_flag        => 'Y'
93497    );
93498 
93499    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
93500 
93501       xla_ae_lines_pkg.set_segment(
93502           p_to_segment_code         => 'GL_BALANCING'
93503         , p_segment_value           => l_segment
93504         , p_from_segment_code       => l_adr_value_segment_code
93505         , p_from_combination_id     => l_adr_value_combination_id
93506         , p_value_type_code         => l_adr_value_type_code
93507         , p_transaction_coa_id      => l_adr_transaction_coa_id
93508         , p_accounting_coa_id       => l_adr_accounting_coa_id
93509         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
93510         , p_flex_value_set_id       => l_adr_flex_value_set_id
93511         , p_adr_code                => 'FA_EXPENSE_ACCT'
93512         , p_adr_type_code           => 'S'
93513         , p_component_type          => l_component_type
93514         , p_component_code          => l_component_code
93515         , p_component_type_code     => l_component_type_code
93516         , p_component_appl_id       => l_component_appl_id
93517         , p_amb_context_code        => l_amb_context_code
93518         , p_entity_code             => 'TRANSACTIONS'
93519         , p_event_class_code        => 'CATEGORY_RECLASS'
93520         , p_side                    => 'NA'
93521         );
93522 
93523   END IF;
93524 
93525    --
93526    --
93527    END IF;
93528    --
93529    -- Bug 4922099
93530    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
93531           (NVL(l_enc_upg_option, 'N') = 'O')
93532         ) AND
93533         (l_bflow_method_code = 'PRIOR_ENTRY')
93534       )
93535    THEN
93536       IF
93537       --
93538       1 = 2
93539       --
93540       THEN
93541       xla_accounting_err_pkg.build_message
93542                                     (p_appli_s_name            => 'XLA'
93543                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
93547                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
93544                                     ,p_token_1                 => 'LINE_NUMBER'
93545                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
93546                                     ,p_token_2                 => 'LINE_TYPE_NAME'
93548                                                                              l_component_type
93549                                                                             ,l_component_code
93550                                                                             ,l_component_type_code
93551                                                                             ,l_component_appl_id
93552                                                                             ,l_amb_context_code
93553                                                                             ,l_entity_code
93554                                                                             ,l_event_class_code
93555                                                                            )
93556                                     ,p_token_3                 => 'OWNER'
93557                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
93558                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
93559                                                                           ,p_lookup_code    => l_component_type_code
93560                                                                          )
93561                                     ,p_token_4                 => 'PRODUCT_NAME'
93562                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
93563                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
93564                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
93565                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
93566                                     ,p_ae_header_id            =>  NULL
93567                                        );
93568 
93569         IF (C_LEVEL_ERROR>= g_log_level) THEN
93570                  trace
93571                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
93572                       ,p_level    => C_LEVEL_ERROR
93573                       ,p_module   => l_log_module);
93574         END IF;
93575       END IF;
93576    END IF;
93577    --
93578    --
93579    ------------------------------------------------------------------------------------------------
93580    -- 4219869 Business Flow
93581    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
93582    -- Prior Entry.  Currently, the following code is always generated.
93583    ------------------------------------------------------------------------------------------------
93584    XLA_AE_LINES_PKG.ValidateCurrentLine;
93585 
93586    ------------------------------------------------------------------------------------
93587    -- 4219869 Business Flow
93588    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
93589    ------------------------------------------------------------------------------------
93590    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
93591 
93592    ----------------------------------------------------------------------------------
93593    -- 4219869 Business Flow
93594    -- Update journal entry status -- Need to generate this within IF <condition>
93595    ----------------------------------------------------------------------------------
93596    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
93597          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
93598          ,p_balance_type_code => l_balance_type_code
93599          );
93600 
93601    -------------------------------------------------------------------------------------------
93602    -- 4262811 - Generate the Accrual Reversal lines
93603    -------------------------------------------------------------------------------------------
93604    BEGIN
93605       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
93606                               (g_array_event(p_event_id).array_value_num('header_index'));
93607       IF l_acc_rev_flag IS NULL THEN
93608          l_acc_rev_flag := 'N';
93609       END IF;
93610    EXCEPTION
93611       WHEN OTHERS THEN
93612          l_acc_rev_flag := 'N';
93613    END;
93614    --
93615    IF (l_acc_rev_flag = 'Y') THEN
93616 
93617        -- 4645092  ------------------------------------------------------------------------------
93618        -- To allow MPA report to determine if it should generate report process
93619        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
93620        ------------------------------------------------------------------------------------------
93621 
93622        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
93623        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
93624    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
93625    -- call ADRs
93626    -- Bug 4922099
93627    --
93628    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
93629         (NVL(l_actual_upg_option, 'N') = 'O') OR
93630         (NVL(l_enc_upg_option, 'N') = 'O')
93631       )
93632    THEN
93633    NULL;
93634    --
93635    --
93636    
93637   l_ccid := AcctDerRule_173(
93638            p_application_id           => p_application_id
93639          , p_ae_header_id             => l_ae_header_id 
93640 , p_source_3 => p_source_3
93641 , p_source_30 => p_source_30
93642          , x_transaction_coa_id       => l_adr_transaction_coa_id
93643          , x_accounting_coa_id        => l_adr_accounting_coa_id
93644          , x_value_type_code          => l_adr_value_type_code
93645          , p_side                     => 'NA'
93649     p_code_combination_id          => l_ccid
93646    );
93647 
93648    xla_ae_lines_pkg.set_ccid(
93650   , p_value_type_code              => l_adr_value_type_code
93651   , p_transaction_coa_id           => l_adr_transaction_coa_id
93652   , p_accounting_coa_id            => l_adr_accounting_coa_id
93653   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
93654   , p_adr_type_code                => 'S'
93655   , p_component_type               => l_component_type
93656   , p_component_code               => l_component_code
93657   , p_component_type_code          => l_component_type_code
93658   , p_component_appl_id            => l_component_appl_id
93659   , p_amb_context_code             => l_amb_context_code
93660   , p_side                         => 'NA'
93661   );
93662 
93663 
93664    l_segment := AcctDerRule_150(
93665            p_application_id           => p_application_id
93666          , p_ae_header_id             => l_ae_header_id 
93667 , p_source_3 => p_source_3
93668 , p_source_11 => p_source_11
93669          , x_transaction_coa_id       => l_adr_transaction_coa_id
93670          , x_accounting_coa_id        => l_adr_accounting_coa_id
93671          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
93672          , x_flex_value_set_id        => l_adr_flex_value_set_id
93673          , x_value_type_code          => l_adr_value_type_code
93674          , x_value_combination_id     => l_adr_value_combination_id
93675          , x_value_segment_code       => l_adr_value_segment_code
93676          , p_side                     => 'NA'
93677          , p_override_seg_flag        => 'Y'
93678    );
93679 
93680    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
93681 
93682       xla_ae_lines_pkg.set_segment(
93683           p_to_segment_code         => 'GL_ACCOUNT'
93684         , p_segment_value           => l_segment
93685         , p_from_segment_code       => l_adr_value_segment_code
93686         , p_from_combination_id     => l_adr_value_combination_id
93687         , p_value_type_code         => l_adr_value_type_code
93688         , p_transaction_coa_id      => l_adr_transaction_coa_id
93689         , p_accounting_coa_id       => l_adr_accounting_coa_id
93690         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
93691         , p_flex_value_set_id       => l_adr_flex_value_set_id
93692         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
93693         , p_adr_type_code           => 'S'
93694         , p_component_type          => l_component_type
93695         , p_component_code          => l_component_code
93696         , p_component_type_code     => l_component_type_code
93697         , p_component_appl_id       => l_component_appl_id
93698         , p_amb_context_code        => l_amb_context_code
93699         , p_entity_code             => 'TRANSACTIONS'
93700         , p_event_class_code        => 'CATEGORY_RECLASS'
93701         , p_side                    => 'NA'
93702         );
93703 
93704   END IF;
93705 
93706    l_segment := AcctDerRule_168(
93707            p_application_id           => p_application_id
93708          , p_ae_header_id             => l_ae_header_id 
93709 , p_source_3 => p_source_3
93710 , p_source_29 => p_source_29
93711          , x_transaction_coa_id       => l_adr_transaction_coa_id
93712          , x_accounting_coa_id        => l_adr_accounting_coa_id
93713          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
93714          , x_flex_value_set_id        => l_adr_flex_value_set_id
93715          , x_value_type_code          => l_adr_value_type_code
93716          , x_value_combination_id     => l_adr_value_combination_id
93717          , x_value_segment_code       => l_adr_value_segment_code
93718          , p_side                     => 'NA'
93719          , p_override_seg_flag        => 'Y'
93720    );
93721 
93722    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
93723 
93724       xla_ae_lines_pkg.set_segment(
93725           p_to_segment_code         => 'GL_BALANCING'
93726         , p_segment_value           => l_segment
93727         , p_from_segment_code       => l_adr_value_segment_code
93728         , p_from_combination_id     => l_adr_value_combination_id
93729         , p_value_type_code         => l_adr_value_type_code
93730         , p_transaction_coa_id      => l_adr_transaction_coa_id
93731         , p_accounting_coa_id       => l_adr_accounting_coa_id
93732         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
93733         , p_flex_value_set_id       => l_adr_flex_value_set_id
93734         , p_adr_code                => 'FA_EXPENSE_ACCT'
93735         , p_adr_type_code           => 'S'
93736         , p_component_type          => l_component_type
93737         , p_component_code          => l_component_code
93738         , p_component_type_code     => l_component_type_code
93739         , p_component_appl_id       => l_component_appl_id
93740         , p_amb_context_code        => l_amb_context_code
93741         , p_entity_code             => 'TRANSACTIONS'
93742         , p_event_class_code        => 'CATEGORY_RECLASS'
93743         , p_side                    => 'NA'
93744         );
93745 
93746   END IF;
93747 
93748    --
93749    --
93750    END IF;
93751 
93752        --
93753        -- Update the line information that should be overwritten
93754        --
93755        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
93756                                          p_header_num   => 1);
93757        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
93758 
93759        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
93760 
93761        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
93762           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
93763        END IF;
93764 
93765       --
93769           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
93766       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
93767       --
93768       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
93770       ELSE
93771           ---------------------------------------------------------------------------------------------------
93772           -- 4262811a Switch Sign
93773           ---------------------------------------------------------------------------------------------------
93774           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
93775           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
93776                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
93777           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
93778                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
93779           -- 5132302
93780           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
93781                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
93782 
93783       END IF;
93784 
93785       -- 4955764
93786       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
93787       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
93788 
93789 
93790       XLA_AE_LINES_PKG.ValidateCurrentLine;
93791       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
93792 
93793       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
93794                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
93795                ,p_balance_type_code => l_balance_type_code);
93796 
93797    END IF;
93798 
93799    -----------------------------------------------------------------------------------------
93800    -- 4262811 Multiperiod Accounting
93801    -----------------------------------------------------------------------------------------
93802      -- No MPA option is assigned.
93803 
93804 
93805 END IF;
93806 END IF;
93807 --
93808 
93809 --
93810 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
93811    trace
93812       (p_msg      => 'END of AcctLineType_284'
93813       ,p_level    => C_LEVEL_PROCEDURE
93814       ,p_module   => l_log_module);
93815 END IF;
93816 --
93817 EXCEPTION
93818   WHEN xla_exceptions_pkg.application_exception THEN
93819       RAISE;
93820   WHEN OTHERS THEN
93821        xla_exceptions_pkg.raise_message
93822            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_284');
93823 END AcctLineType_284;
93824 --
93825 
93826 ---------------------------------------
93827 --
93828 -- PRIVATE FUNCTION
93829 --         AcctLineType_285
93830 --
93831 ---------------------------------------
93832 PROCEDURE AcctLineType_285 (
93833   p_application_id        IN NUMBER
93834  ,p_event_id              IN NUMBER
93835  ,p_calculate_acctd_flag  IN VARCHAR2
93836  ,p_calculate_g_l_flag    IN VARCHAR2
93837  ,p_actual_flag           IN OUT VARCHAR2
93838  ,p_balance_type_code     OUT VARCHAR2
93839  ,p_gain_or_loss_ref      OUT VARCHAR2
93840  
93841 --Period Close Date
93842  , p_source_1            IN DATE
93843 --Bonus Depreciation Expense Account
93844  , p_source_2            IN VARCHAR2
93845 --Generated Code Combination Identifier
93846  , p_source_3            IN NUMBER
93847 --Expense Account Code Combination Identifier
93848  , p_source_29            IN NUMBER
93849 --Adjustment Type
93850  , p_source_35            IN VARCHAR2
93851 --Transaction Header Identifier
93852  , p_source_36            IN NUMBER
93853 --Adjustment Line Identifier
93854  , p_source_37            IN NUMBER
93855 --Distribution Type Code
93856  , p_source_38            IN VARCHAR2
93857 --Entered Amount
93858  , p_source_39            IN NUMBER
93859 --Currency Code
93860  , p_source_40            IN VARCHAR2
93861 --Source Destination Code
93862  , p_source_42            IN VARCHAR2
93863 )
93864 IS
93865 
93866 l_component_type              VARCHAR2(80);
93867 l_component_code              VARCHAR2(30);
93868 l_component_type_code         VARCHAR2(1);
93869 l_component_appl_id           INTEGER;
93870 l_amb_context_code            VARCHAR2(30);
93871 l_entity_code                 VARCHAR2(30);
93872 l_event_class_code            VARCHAR2(30);
93873 l_ae_header_id                NUMBER;
93874 l_event_type_code             VARCHAR2(30);
93875 l_line_definition_code        VARCHAR2(30);
93876 l_line_definition_owner_code  VARCHAR2(1);
93877 --
93878 -- adr variables
93879 l_segment                     VARCHAR2(30);
93880 l_ccid                        NUMBER;
93881 l_adr_transaction_coa_id      NUMBER;
93882 l_adr_accounting_coa_id       NUMBER;
93883 l_adr_flexfield_segment_code  VARCHAR2(30);
93884 l_adr_flex_value_set_id       NUMBER;
93885 l_adr_value_type_code         VARCHAR2(30);
93886 l_adr_value_combination_id    NUMBER;
93887 l_adr_value_segment_code      VARCHAR2(30);
93888 
93889 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
93890 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
93891 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
93892 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
93893 
93894 -- 4262811 Variables ------------------------------------------------------------------------------------------
93895 l_entered_amt_idx             NUMBER;
93896 l_accted_amt_idx              NUMBER;
93897 l_acc_rev_flag                VARCHAR2(1);
93901 
93898 l_accrual_line_num            NUMBER;
93899 l_tmp_amt                     NUMBER;
93900 l_acc_rev_natural_side_code   VARCHAR2(1);
93902 l_num_entries                 NUMBER;
93903 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
93904 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
93905 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
93906 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
93907 l_recog_line_1                NUMBER;
93908 l_recog_line_2                NUMBER;
93909 
93910 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
93911 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
93912 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
93913 
93914 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
93915 
93916 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
93917 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
93918 
93919 ---------------------------------------------------------------------------------------------------------------
93920 
93921 
93922 --
93923 -- bulk performance
93924 --
93925 l_balance_type_code           VARCHAR2(1);
93926 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
93927 l_log_module                  VARCHAR2(240);
93928 
93929 --
93930 -- Upgrade strategy
93931 --
93932 l_actual_upg_option           VARCHAR2(1);
93933 l_enc_upg_option           VARCHAR2(1);
93934 
93935 --
93936 BEGIN
93937 --
93938 IF g_log_enabled THEN
93939       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_285';
93940 END IF;
93941 --
93942 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
93943 
93944       trace
93945          (p_msg      => 'BEGIN of AcctLineType_285'
93946          ,p_level    => C_LEVEL_PROCEDURE
93947          ,p_module   => l_log_module);
93948 
93949 END IF;
93950 --
93951 l_component_type             := 'AMB_JLT';
93952 l_component_code             := 'FA_RECLASS_SOURCE_BONUS_EXP';
93953 l_component_type_code        := 'S';
93954 l_component_appl_id          :=  140;
93955 l_amb_context_code           := 'DEFAULT';
93956 l_entity_code                := 'TRANSACTIONS';
93957 l_event_class_code           := 'CATEGORY_RECLASS';
93958 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
93959 l_line_definition_owner_code := 'S';
93960 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
93961 --
93962 l_balance_type_code          := 'A';
93963 l_segment                     := NULL;
93964 l_ccid                        := NULL;
93965 l_adr_transaction_coa_id      := NULL;
93966 l_adr_accounting_coa_id       := NULL;
93967 l_adr_flexfield_segment_code  := NULL;
93968 l_adr_flex_value_set_id       := NULL;
93969 l_adr_value_type_code         := NULL;
93970 l_adr_value_combination_id    := NULL;
93971 l_adr_value_segment_code      := NULL;
93972 
93973 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
93974 l_bflow_class_code           := '';    -- 4219869 Business Flow
93975 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
93976 l_budgetary_control_flag     := 'N';
93977 
93978 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
93979 l_bflow_applied_to_amt       := NULL; -- 5132302
93980 l_entered_amt_idx            := NULL;          -- 4262811
93981 l_accted_amt_idx             := NULL;          -- 4262811
93982 l_acc_rev_flag               := NULL;          -- 4262811
93983 l_accrual_line_num           := NULL;          -- 4262811
93984 l_tmp_amt                    := NULL;          -- 4262811
93985 --
93986  
93987 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
93988     l_balance_type_code <> 'B' THEN
93989 IF NVL(p_source_35,'
93990 ') =  'BONUS EXPENSE' AND 
93991 NVL(p_source_42,'
93992 ') =  'SOURCE'
93993  THEN 
93994 
93995    --
93996    XLA_AE_LINES_PKG.SetNewLine;
93997 
93998    p_balance_type_code          := l_balance_type_code;
93999    -- set the flag so later we will know whether the gain loss line needs to be created
94000    
94001    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
94002      p_actual_flag :='A';
94003    END IF;
94004 
94005    --
94006    -- bulk performance
94007    --
94008    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
94009                                       p_header_num   => 0); -- 4262811
94010    --
94011    -- set accounting line options
94012    --
94013    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
94014            p_natural_side_code          => 'C'
94015          , p_gain_or_loss_flag          => 'N'
94016          , p_gl_transfer_mode_code      => 'S'
94017          , p_acct_entry_type_code       => 'A'
94018          , p_switch_side_flag           => 'Y'
94019          , p_merge_duplicate_code       => 'N'
94020          );
94021    --
94022    l_acc_rev_natural_side_code := 'D';  -- 4262811
94023    -- 
94024    --
94025    -- set accounting line type info
94026    --
94027    xla_ae_lines_pkg.SetAcctLineType
94028       (p_component_type             => l_component_type
94029       ,p_event_type_code            => l_event_type_code
94030       ,p_line_definition_owner_code => l_line_definition_owner_code
94031       ,p_line_definition_code       => l_line_definition_code
94032       ,p_accounting_line_code       => l_component_code
94033       ,p_accounting_line_type_code  => l_component_type_code
94034       ,p_accounting_line_appl_id    => l_component_appl_id
94035       ,p_amb_context_code           => l_amb_context_code
94036       ,p_entity_code                => l_entity_code
94040    --
94037       ,p_event_class_code           => l_event_class_code);
94038    --
94039    -- set accounting class
94041    xla_ae_lines_pkg.SetAcctClass(
94042            p_accounting_class_code  => 'EXPENSE'
94043          , p_ae_header_id           => l_ae_header_id
94044          );
94045 
94046    --
94047    -- set rounding class
94048    --
94049    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
94050                       'EXPENSE';
94051 
94052    --
94053    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
94054    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
94055    --
94056    -- bulk performance
94057    --
94058    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
94059 
94060    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
94061       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
94062 
94063    -- 4955764
94064    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
94065       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
94066 
94067    -- 4458381 Public Sector Enh
94068    
94069    --
94070    -- set accounting attributes for the line type
94071    --
94072    l_entered_amt_idx := 4;
94073    l_accted_amt_idx  := 6;
94074    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
94075    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
94076    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
94077    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
94078    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
94079    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
94080    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
94081    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
94082    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
94083    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
94084    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
94085    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
94086    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
94087 
94088    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
94089    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
94090 
94091    ---------------------------------------------------------------------------------------------------------------
94092    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
94093    ---------------------------------------------------------------------------------------------------------------
94094    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
94095 
94096    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
94097    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
94098 
94099    IF xla_accounting_cache_pkg.GetValueChar
94100          (p_source_code         => 'LEDGER_CATEGORY_CODE'
94101          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
94102    AND l_bflow_method_code = 'PRIOR_ENTRY'
94103 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
94104    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
94105          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
94106        )
94107    THEN
94108          xla_ae_lines_pkg.BflowUpgEntry
94109            (p_business_method_code    => l_bflow_method_code
94110            ,p_business_class_code     => l_bflow_class_code
94111            ,p_balance_type            => l_balance_type_code);
94112    ELSE
94113       NULL;
94114 -- No business flow processing for business flow method of NONE.
94115    END IF;
94116 
94117    --
94118    -- call analytical criteria
94119    --
94120    
94121    --
94122    -- call description
94123    --
94124    
94125 xla_ae_lines_pkg.SetLineDescription(
94126    p_ae_header_id => l_ae_header_id
94127   ,p_description  => Description_63 (
94128      p_application_id         => p_application_id
94129    , p_ae_header_id           => l_ae_header_id 
94130 , p_source_1 => p_source_1
94131    )
94132 );
94133 
94134 
94135    --
94136    -- call ADRs
94137    -- Bug 4922099
94138    --
94139    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
94140         (NVL(l_actual_upg_option, 'N') = 'O') OR
94141         (NVL(l_enc_upg_option, 'N') = 'O')
94142       )
94143    THEN
94144    NULL;
94145    --
94146    --
94147    
94148   l_ccid := AcctDerRule_175(
94149            p_application_id           => p_application_id
94150          , p_ae_header_id             => l_ae_header_id 
94151 , p_source_3 => p_source_3
94152 , p_source_29 => p_source_29
94153          , x_transaction_coa_id       => l_adr_transaction_coa_id
94154          , x_accounting_coa_id        => l_adr_accounting_coa_id
94155          , x_value_type_code          => l_adr_value_type_code
94156          , p_side                     => 'NA'
94157    );
94158 
94159    xla_ae_lines_pkg.set_ccid(
94160     p_code_combination_id          => l_ccid
94161   , p_value_type_code              => l_adr_value_type_code
94162   , p_transaction_coa_id           => l_adr_transaction_coa_id
94163   , p_accounting_coa_id            => l_adr_accounting_coa_id
94164   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
94165   , p_adr_type_code                => 'S'
94166   , p_component_type               => l_component_type
94170   , p_amb_context_code             => l_amb_context_code
94167   , p_component_code               => l_component_code
94168   , p_component_type_code          => l_component_type_code
94169   , p_component_appl_id            => l_component_appl_id
94171   , p_side                         => 'NA'
94172   );
94173 
94174 
94175    l_segment := AcctDerRule_143(
94176            p_application_id           => p_application_id
94177          , p_ae_header_id             => l_ae_header_id 
94178 , p_source_2 => p_source_2
94179 , p_source_3 => p_source_3
94180          , x_transaction_coa_id       => l_adr_transaction_coa_id
94181          , x_accounting_coa_id        => l_adr_accounting_coa_id
94182          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
94183          , x_flex_value_set_id        => l_adr_flex_value_set_id
94184          , x_value_type_code          => l_adr_value_type_code
94185          , x_value_combination_id     => l_adr_value_combination_id
94186          , x_value_segment_code       => l_adr_value_segment_code
94187          , p_side                     => 'NA'
94188          , p_override_seg_flag        => 'Y'
94189    );
94190 
94191    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
94192 
94193       xla_ae_lines_pkg.set_segment(
94194           p_to_segment_code         => 'GL_ACCOUNT'
94195         , p_segment_value           => l_segment
94196         , p_from_segment_code       => l_adr_value_segment_code
94197         , p_from_combination_id     => l_adr_value_combination_id
94198         , p_value_type_code         => l_adr_value_type_code
94199         , p_transaction_coa_id      => l_adr_transaction_coa_id
94200         , p_accounting_coa_id       => l_adr_accounting_coa_id
94201         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
94202         , p_flex_value_set_id       => l_adr_flex_value_set_id
94203         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
94204         , p_adr_type_code           => 'S'
94205         , p_component_type          => l_component_type
94206         , p_component_code          => l_component_code
94207         , p_component_type_code     => l_component_type_code
94208         , p_component_appl_id       => l_component_appl_id
94209         , p_amb_context_code        => l_amb_context_code
94210         , p_entity_code             => 'TRANSACTIONS'
94211         , p_event_class_code        => 'CATEGORY_RECLASS'
94212         , p_side                    => 'NA'
94213         );
94214 
94215   END IF;
94216 
94217    --
94218    --
94219    END IF;
94220    --
94221    -- Bug 4922099
94222    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
94223           (NVL(l_enc_upg_option, 'N') = 'O')
94224         ) AND
94225         (l_bflow_method_code = 'PRIOR_ENTRY')
94226       )
94227    THEN
94228       IF
94229       --
94230       1 = 2
94231       --
94232       THEN
94233       xla_accounting_err_pkg.build_message
94234                                     (p_appli_s_name            => 'XLA'
94235                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
94236                                     ,p_token_1                 => 'LINE_NUMBER'
94237                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
94238                                     ,p_token_2                 => 'LINE_TYPE_NAME'
94239                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
94240                                                                              l_component_type
94241                                                                             ,l_component_code
94242                                                                             ,l_component_type_code
94243                                                                             ,l_component_appl_id
94244                                                                             ,l_amb_context_code
94245                                                                             ,l_entity_code
94246                                                                             ,l_event_class_code
94247                                                                            )
94248                                     ,p_token_3                 => 'OWNER'
94249                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
94250                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
94251                                                                           ,p_lookup_code    => l_component_type_code
94252                                                                          )
94253                                     ,p_token_4                 => 'PRODUCT_NAME'
94254                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
94255                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
94256                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
94257                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
94258                                     ,p_ae_header_id            =>  NULL
94259                                        );
94260 
94261         IF (C_LEVEL_ERROR>= g_log_level) THEN
94262                  trace
94263                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
94264                       ,p_level    => C_LEVEL_ERROR
94265                       ,p_module   => l_log_module);
94266         END IF;
94267       END IF;
94268    END IF;
94269    --
94270    --
94271    ------------------------------------------------------------------------------------------------
94272    -- 4219869 Business Flow
94273    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
94277 
94274    -- Prior Entry.  Currently, the following code is always generated.
94275    ------------------------------------------------------------------------------------------------
94276    XLA_AE_LINES_PKG.ValidateCurrentLine;
94278    ------------------------------------------------------------------------------------
94279    -- 4219869 Business Flow
94280    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
94281    ------------------------------------------------------------------------------------
94282    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
94283 
94284    ----------------------------------------------------------------------------------
94285    -- 4219869 Business Flow
94286    -- Update journal entry status -- Need to generate this within IF <condition>
94287    ----------------------------------------------------------------------------------
94288    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
94289          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
94290          ,p_balance_type_code => l_balance_type_code
94291          );
94292 
94293    -------------------------------------------------------------------------------------------
94294    -- 4262811 - Generate the Accrual Reversal lines
94295    -------------------------------------------------------------------------------------------
94296    BEGIN
94297       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
94298                               (g_array_event(p_event_id).array_value_num('header_index'));
94299       IF l_acc_rev_flag IS NULL THEN
94300          l_acc_rev_flag := 'N';
94301       END IF;
94302    EXCEPTION
94303       WHEN OTHERS THEN
94304          l_acc_rev_flag := 'N';
94305    END;
94306    --
94307    IF (l_acc_rev_flag = 'Y') THEN
94308 
94309        -- 4645092  ------------------------------------------------------------------------------
94310        -- To allow MPA report to determine if it should generate report process
94311        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
94312        ------------------------------------------------------------------------------------------
94313 
94314        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
94315        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
94316    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
94317    -- call ADRs
94318    -- Bug 4922099
94319    --
94320    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
94321         (NVL(l_actual_upg_option, 'N') = 'O') OR
94322         (NVL(l_enc_upg_option, 'N') = 'O')
94323       )
94324    THEN
94325    NULL;
94326    --
94327    --
94328    
94329   l_ccid := AcctDerRule_175(
94330            p_application_id           => p_application_id
94331          , p_ae_header_id             => l_ae_header_id 
94332 , p_source_3 => p_source_3
94333 , p_source_29 => p_source_29
94334          , x_transaction_coa_id       => l_adr_transaction_coa_id
94335          , x_accounting_coa_id        => l_adr_accounting_coa_id
94336          , x_value_type_code          => l_adr_value_type_code
94337          , p_side                     => 'NA'
94338    );
94339 
94340    xla_ae_lines_pkg.set_ccid(
94341     p_code_combination_id          => l_ccid
94342   , p_value_type_code              => l_adr_value_type_code
94343   , p_transaction_coa_id           => l_adr_transaction_coa_id
94344   , p_accounting_coa_id            => l_adr_accounting_coa_id
94345   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
94346   , p_adr_type_code                => 'S'
94347   , p_component_type               => l_component_type
94348   , p_component_code               => l_component_code
94349   , p_component_type_code          => l_component_type_code
94350   , p_component_appl_id            => l_component_appl_id
94351   , p_amb_context_code             => l_amb_context_code
94352   , p_side                         => 'NA'
94353   );
94354 
94355 
94356    l_segment := AcctDerRule_143(
94357            p_application_id           => p_application_id
94358          , p_ae_header_id             => l_ae_header_id 
94359 , p_source_2 => p_source_2
94360 , p_source_3 => p_source_3
94361          , x_transaction_coa_id       => l_adr_transaction_coa_id
94362          , x_accounting_coa_id        => l_adr_accounting_coa_id
94363          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
94364          , x_flex_value_set_id        => l_adr_flex_value_set_id
94365          , x_value_type_code          => l_adr_value_type_code
94366          , x_value_combination_id     => l_adr_value_combination_id
94367          , x_value_segment_code       => l_adr_value_segment_code
94368          , p_side                     => 'NA'
94369          , p_override_seg_flag        => 'Y'
94370    );
94371 
94372    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
94373 
94374       xla_ae_lines_pkg.set_segment(
94375           p_to_segment_code         => 'GL_ACCOUNT'
94376         , p_segment_value           => l_segment
94377         , p_from_segment_code       => l_adr_value_segment_code
94378         , p_from_combination_id     => l_adr_value_combination_id
94379         , p_value_type_code         => l_adr_value_type_code
94380         , p_transaction_coa_id      => l_adr_transaction_coa_id
94381         , p_accounting_coa_id       => l_adr_accounting_coa_id
94382         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
94383         , p_flex_value_set_id       => l_adr_flex_value_set_id
94384         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
94385         , p_adr_type_code           => 'S'
94386         , p_component_type          => l_component_type
94387         , p_component_code          => l_component_code
94388         , p_component_type_code     => l_component_type_code
94389         , p_component_appl_id       => l_component_appl_id
94390         , p_amb_context_code        => l_amb_context_code
94394         );
94391         , p_entity_code             => 'TRANSACTIONS'
94392         , p_event_class_code        => 'CATEGORY_RECLASS'
94393         , p_side                    => 'NA'
94395 
94396   END IF;
94397 
94398    --
94399    --
94400    END IF;
94401 
94402        --
94403        -- Update the line information that should be overwritten
94404        --
94405        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
94406                                          p_header_num   => 1);
94407        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
94408 
94409        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
94410 
94411        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
94412           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
94413        END IF;
94414 
94415       --
94416       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
94417       --
94418       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
94419           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
94420       ELSE
94421           ---------------------------------------------------------------------------------------------------
94422           -- 4262811a Switch Sign
94423           ---------------------------------------------------------------------------------------------------
94424           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
94425           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
94426                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
94427           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
94428                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
94429           -- 5132302
94430           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
94431                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
94432 
94433       END IF;
94434 
94435       -- 4955764
94436       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
94437       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
94438 
94439 
94440       XLA_AE_LINES_PKG.ValidateCurrentLine;
94441       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
94442 
94443       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
94444                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
94445                ,p_balance_type_code => l_balance_type_code);
94446 
94447    END IF;
94448 
94449    -----------------------------------------------------------------------------------------
94450    -- 4262811 Multiperiod Accounting
94451    -----------------------------------------------------------------------------------------
94452      -- No MPA option is assigned.
94453 
94454 
94455 END IF;
94456 END IF;
94457 --
94458 
94459 --
94460 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
94461    trace
94462       (p_msg      => 'END of AcctLineType_285'
94463       ,p_level    => C_LEVEL_PROCEDURE
94464       ,p_module   => l_log_module);
94465 END IF;
94466 --
94467 EXCEPTION
94468   WHEN xla_exceptions_pkg.application_exception THEN
94469       RAISE;
94470   WHEN OTHERS THEN
94471        xla_exceptions_pkg.raise_message
94472            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_285');
94473 END AcctLineType_285;
94474 --
94475 
94476 ---------------------------------------
94477 --
94478 -- PRIVATE FUNCTION
94479 --         AcctLineType_286
94480 --
94481 ---------------------------------------
94482 PROCEDURE AcctLineType_286 (
94483   p_application_id        IN NUMBER
94484  ,p_event_id              IN NUMBER
94485  ,p_calculate_acctd_flag  IN VARCHAR2
94486  ,p_calculate_g_l_flag    IN VARCHAR2
94487  ,p_actual_flag           IN OUT VARCHAR2
94488  ,p_balance_type_code     OUT VARCHAR2
94489  ,p_gain_or_loss_ref      OUT VARCHAR2
94490  
94491 --Period Close Date
94492  , p_source_1            IN DATE
94493 --Generated Code Combination Identifier
94494  , p_source_3            IN NUMBER
94495 --Bonus Reserve Account
94496  , p_source_4            IN VARCHAR2
94497 --Generated Offset Code Combination Identifier
94498  , p_source_17            IN NUMBER
94499 --Expense Account Code Combination Identifier
94500  , p_source_29            IN NUMBER
94501 --Default Code Combination Identifier
94502  , p_source_30            IN NUMBER
94503 --Adjustment Type
94504  , p_source_35            IN VARCHAR2
94505 --Transaction Header Identifier
94506  , p_source_36            IN NUMBER
94507 --Adjustment Line Identifier
94508  , p_source_37            IN NUMBER
94509 --Distribution Type Code
94510  , p_source_38            IN VARCHAR2
94511 --Entered Amount
94512  , p_source_39            IN NUMBER
94513 --Currency Code
94514  , p_source_40            IN VARCHAR2
94515 --Source Destination Code
94516  , p_source_42            IN VARCHAR2
94517 )
94518 IS
94519 
94520 l_component_type              VARCHAR2(80);
94521 l_component_code              VARCHAR2(30);
94522 l_component_type_code         VARCHAR2(1);
94523 l_component_appl_id           INTEGER;
94524 l_amb_context_code            VARCHAR2(30);
94525 l_entity_code                 VARCHAR2(30);
94526 l_event_class_code            VARCHAR2(30);
94527 l_ae_header_id                NUMBER;
94531 --
94528 l_event_type_code             VARCHAR2(30);
94529 l_line_definition_code        VARCHAR2(30);
94530 l_line_definition_owner_code  VARCHAR2(1);
94532 -- adr variables
94533 l_segment                     VARCHAR2(30);
94534 l_ccid                        NUMBER;
94535 l_adr_transaction_coa_id      NUMBER;
94536 l_adr_accounting_coa_id       NUMBER;
94537 l_adr_flexfield_segment_code  VARCHAR2(30);
94538 l_adr_flex_value_set_id       NUMBER;
94539 l_adr_value_type_code         VARCHAR2(30);
94540 l_adr_value_combination_id    NUMBER;
94541 l_adr_value_segment_code      VARCHAR2(30);
94542 
94543 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
94544 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
94545 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
94546 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
94547 
94548 -- 4262811 Variables ------------------------------------------------------------------------------------------
94549 l_entered_amt_idx             NUMBER;
94550 l_accted_amt_idx              NUMBER;
94551 l_acc_rev_flag                VARCHAR2(1);
94552 l_accrual_line_num            NUMBER;
94553 l_tmp_amt                     NUMBER;
94554 l_acc_rev_natural_side_code   VARCHAR2(1);
94555 
94556 l_num_entries                 NUMBER;
94557 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
94558 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
94559 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
94560 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
94561 l_recog_line_1                NUMBER;
94562 l_recog_line_2                NUMBER;
94563 
94564 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
94565 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
94566 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
94567 
94568 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
94569 
94570 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
94571 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
94572 
94573 ---------------------------------------------------------------------------------------------------------------
94574 
94575 
94576 --
94577 -- bulk performance
94578 --
94579 l_balance_type_code           VARCHAR2(1);
94580 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
94581 l_log_module                  VARCHAR2(240);
94582 
94583 --
94584 -- Upgrade strategy
94585 --
94586 l_actual_upg_option           VARCHAR2(1);
94587 l_enc_upg_option           VARCHAR2(1);
94588 
94589 --
94590 BEGIN
94591 --
94592 IF g_log_enabled THEN
94593       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_286';
94594 END IF;
94595 --
94596 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
94597 
94598       trace
94599          (p_msg      => 'BEGIN of AcctLineType_286'
94600          ,p_level    => C_LEVEL_PROCEDURE
94601          ,p_module   => l_log_module);
94602 
94603 END IF;
94604 --
94605 l_component_type             := 'AMB_JLT';
94606 l_component_code             := 'FA_RECLASS_SOURCE_BONUS_RESERV';
94607 l_component_type_code        := 'S';
94608 l_component_appl_id          :=  140;
94609 l_amb_context_code           := 'DEFAULT';
94610 l_entity_code                := 'TRANSACTIONS';
94611 l_event_class_code           := 'CATEGORY_RECLASS';
94612 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
94613 l_line_definition_owner_code := 'S';
94614 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
94615 --
94616 l_balance_type_code          := 'A';
94617 l_segment                     := NULL;
94618 l_ccid                        := NULL;
94619 l_adr_transaction_coa_id      := NULL;
94620 l_adr_accounting_coa_id       := NULL;
94621 l_adr_flexfield_segment_code  := NULL;
94622 l_adr_flex_value_set_id       := NULL;
94623 l_adr_value_type_code         := NULL;
94624 l_adr_value_combination_id    := NULL;
94625 l_adr_value_segment_code      := NULL;
94626 
94627 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
94628 l_bflow_class_code           := '';    -- 4219869 Business Flow
94629 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
94630 l_budgetary_control_flag     := 'N';
94631 
94632 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
94633 l_bflow_applied_to_amt       := NULL; -- 5132302
94634 l_entered_amt_idx            := NULL;          -- 4262811
94635 l_accted_amt_idx             := NULL;          -- 4262811
94636 l_acc_rev_flag               := NULL;          -- 4262811
94637 l_accrual_line_num           := NULL;          -- 4262811
94638 l_tmp_amt                    := NULL;          -- 4262811
94639 --
94640  
94641 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
94642     l_balance_type_code <> 'B' THEN
94643 IF (NVL(p_source_35,'
94644 ') =  'BONUS EXPENSE' OR 
94645 NVL(p_source_35,'
94646 ') =  'BONUS RESERVE') AND 
94647 NVL(p_source_42,'
94648 ') =  'SOURCE'
94649  THEN 
94650 
94651    --
94652    XLA_AE_LINES_PKG.SetNewLine;
94653 
94654    p_balance_type_code          := l_balance_type_code;
94655    -- set the flag so later we will know whether the gain loss line needs to be created
94656    
94657    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
94658      p_actual_flag :='A';
94659    END IF;
94660 
94661    --
94662    -- bulk performance
94663    --
94664    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
94665                                       p_header_num   => 0); -- 4262811
94666    --
94670            p_natural_side_code          => 'D'
94667    -- set accounting line options
94668    --
94669    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
94671          , p_gain_or_loss_flag          => 'N'
94672          , p_gl_transfer_mode_code      => 'S'
94673          , p_acct_entry_type_code       => 'A'
94674          , p_switch_side_flag           => 'Y'
94675          , p_merge_duplicate_code       => 'N'
94676          );
94677    --
94678    l_acc_rev_natural_side_code := 'C';  -- 4262811
94679    -- 
94680    --
94681    -- set accounting line type info
94682    --
94683    xla_ae_lines_pkg.SetAcctLineType
94684       (p_component_type             => l_component_type
94685       ,p_event_type_code            => l_event_type_code
94686       ,p_line_definition_owner_code => l_line_definition_owner_code
94687       ,p_line_definition_code       => l_line_definition_code
94688       ,p_accounting_line_code       => l_component_code
94689       ,p_accounting_line_type_code  => l_component_type_code
94690       ,p_accounting_line_appl_id    => l_component_appl_id
94691       ,p_amb_context_code           => l_amb_context_code
94692       ,p_entity_code                => l_entity_code
94693       ,p_event_class_code           => l_event_class_code);
94694    --
94695    -- set accounting class
94696    --
94697    xla_ae_lines_pkg.SetAcctClass(
94698            p_accounting_class_code  => 'ASSET'
94699          , p_ae_header_id           => l_ae_header_id
94700          );
94701 
94702    --
94703    -- set rounding class
94704    --
94705    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
94706                       'ASSET';
94707 
94708    --
94709    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
94710    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
94711    --
94712    -- bulk performance
94713    --
94714    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
94715 
94716    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
94717       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
94718 
94719    -- 4955764
94720    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
94721       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
94722 
94723    -- 4458381 Public Sector Enh
94724    
94725    --
94726    -- set accounting attributes for the line type
94727    --
94728    l_entered_amt_idx := 4;
94729    l_accted_amt_idx  := 6;
94730    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
94731    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
94732    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
94733    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
94734    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
94735    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
94736    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
94737    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
94738    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
94739    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
94740    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
94741    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
94742    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
94743 
94744    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
94745    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
94746 
94747    ---------------------------------------------------------------------------------------------------------------
94748    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
94749    ---------------------------------------------------------------------------------------------------------------
94750    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
94751 
94752    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
94753    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
94754 
94755    IF xla_accounting_cache_pkg.GetValueChar
94756          (p_source_code         => 'LEDGER_CATEGORY_CODE'
94757          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
94758    AND l_bflow_method_code = 'PRIOR_ENTRY'
94759 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
94760    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
94761          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
94762        )
94763    THEN
94764          xla_ae_lines_pkg.BflowUpgEntry
94765            (p_business_method_code    => l_bflow_method_code
94766            ,p_business_class_code     => l_bflow_class_code
94767            ,p_balance_type            => l_balance_type_code);
94768    ELSE
94769       NULL;
94770 -- No business flow processing for business flow method of NONE.
94771    END IF;
94772 
94773    --
94774    -- call analytical criteria
94775    --
94776    
94777    --
94778    -- call description
94779    --
94780    
94781 xla_ae_lines_pkg.SetLineDescription(
94782    p_ae_header_id => l_ae_header_id
94783   ,p_description  => Description_64 (
94784      p_application_id         => p_application_id
94785    , p_ae_header_id           => l_ae_header_id 
94786 , p_source_1 => p_source_1
94787    )
94788 );
94789 
94790 
94791    --
94792    -- call ADRs
94793    -- Bug 4922099
94794    --
94798       )
94795    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
94796         (NVL(l_actual_upg_option, 'N') = 'O') OR
94797         (NVL(l_enc_upg_option, 'N') = 'O')
94799    THEN
94800    NULL;
94801    --
94802    --
94803    
94804   l_ccid := AcctDerRule_174(
94805            p_application_id           => p_application_id
94806          , p_ae_header_id             => l_ae_header_id 
94807 , p_source_3 => p_source_3
94808 , p_source_17 => p_source_17
94809 , p_source_30 => p_source_30
94810          , x_transaction_coa_id       => l_adr_transaction_coa_id
94811          , x_accounting_coa_id        => l_adr_accounting_coa_id
94812          , x_value_type_code          => l_adr_value_type_code
94813          , p_side                     => 'NA'
94814    );
94815 
94816    xla_ae_lines_pkg.set_ccid(
94817     p_code_combination_id          => l_ccid
94818   , p_value_type_code              => l_adr_value_type_code
94819   , p_transaction_coa_id           => l_adr_transaction_coa_id
94820   , p_accounting_coa_id            => l_adr_accounting_coa_id
94821   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
94822   , p_adr_type_code                => 'S'
94823   , p_component_type               => l_component_type
94824   , p_component_code               => l_component_code
94825   , p_component_type_code          => l_component_type_code
94826   , p_component_appl_id            => l_component_appl_id
94827   , p_amb_context_code             => l_amb_context_code
94828   , p_side                         => 'NA'
94829   );
94830 
94831 
94832    l_segment := AcctDerRule_144(
94833            p_application_id           => p_application_id
94834          , p_ae_header_id             => l_ae_header_id 
94835 , p_source_3 => p_source_3
94836 , p_source_4 => p_source_4
94837          , x_transaction_coa_id       => l_adr_transaction_coa_id
94838          , x_accounting_coa_id        => l_adr_accounting_coa_id
94839          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
94840          , x_flex_value_set_id        => l_adr_flex_value_set_id
94841          , x_value_type_code          => l_adr_value_type_code
94842          , x_value_combination_id     => l_adr_value_combination_id
94843          , x_value_segment_code       => l_adr_value_segment_code
94844          , p_side                     => 'NA'
94845          , p_override_seg_flag        => 'Y'
94846    );
94847 
94848    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
94849 
94850       xla_ae_lines_pkg.set_segment(
94851           p_to_segment_code         => 'GL_ACCOUNT'
94852         , p_segment_value           => l_segment
94853         , p_from_segment_code       => l_adr_value_segment_code
94854         , p_from_combination_id     => l_adr_value_combination_id
94855         , p_value_type_code         => l_adr_value_type_code
94856         , p_transaction_coa_id      => l_adr_transaction_coa_id
94857         , p_accounting_coa_id       => l_adr_accounting_coa_id
94858         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
94859         , p_flex_value_set_id       => l_adr_flex_value_set_id
94860         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
94861         , p_adr_type_code           => 'S'
94862         , p_component_type          => l_component_type
94863         , p_component_code          => l_component_code
94864         , p_component_type_code     => l_component_type_code
94865         , p_component_appl_id       => l_component_appl_id
94866         , p_amb_context_code        => l_amb_context_code
94867         , p_entity_code             => 'TRANSACTIONS'
94868         , p_event_class_code        => 'CATEGORY_RECLASS'
94869         , p_side                    => 'NA'
94870         );
94871 
94872   END IF;
94873 
94874    l_segment := AcctDerRule_168(
94875            p_application_id           => p_application_id
94876          , p_ae_header_id             => l_ae_header_id 
94877 , p_source_3 => p_source_3
94878 , p_source_29 => p_source_29
94879          , x_transaction_coa_id       => l_adr_transaction_coa_id
94880          , x_accounting_coa_id        => l_adr_accounting_coa_id
94881          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
94882          , x_flex_value_set_id        => l_adr_flex_value_set_id
94883          , x_value_type_code          => l_adr_value_type_code
94884          , x_value_combination_id     => l_adr_value_combination_id
94885          , x_value_segment_code       => l_adr_value_segment_code
94886          , p_side                     => 'NA'
94887          , p_override_seg_flag        => 'Y'
94888    );
94889 
94890    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
94891 
94892       xla_ae_lines_pkg.set_segment(
94893           p_to_segment_code         => 'GL_BALANCING'
94894         , p_segment_value           => l_segment
94895         , p_from_segment_code       => l_adr_value_segment_code
94896         , p_from_combination_id     => l_adr_value_combination_id
94897         , p_value_type_code         => l_adr_value_type_code
94898         , p_transaction_coa_id      => l_adr_transaction_coa_id
94899         , p_accounting_coa_id       => l_adr_accounting_coa_id
94900         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
94901         , p_flex_value_set_id       => l_adr_flex_value_set_id
94902         , p_adr_code                => 'FA_EXPENSE_ACCT'
94903         , p_adr_type_code           => 'S'
94904         , p_component_type          => l_component_type
94905         , p_component_code          => l_component_code
94906         , p_component_type_code     => l_component_type_code
94907         , p_component_appl_id       => l_component_appl_id
94908         , p_amb_context_code        => l_amb_context_code
94909         , p_entity_code             => 'TRANSACTIONS'
94910         , p_event_class_code        => 'CATEGORY_RECLASS'
94911         , p_side                    => 'NA'
94912         );
94913 
94914   END IF;
94915 
94919    --
94916    --
94917    --
94918    END IF;
94920    -- Bug 4922099
94921    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
94922           (NVL(l_enc_upg_option, 'N') = 'O')
94923         ) AND
94924         (l_bflow_method_code = 'PRIOR_ENTRY')
94925       )
94926    THEN
94927       IF
94928       --
94929       1 = 2
94930       --
94931       THEN
94932       xla_accounting_err_pkg.build_message
94933                                     (p_appli_s_name            => 'XLA'
94934                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
94935                                     ,p_token_1                 => 'LINE_NUMBER'
94936                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
94937                                     ,p_token_2                 => 'LINE_TYPE_NAME'
94938                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
94939                                                                              l_component_type
94940                                                                             ,l_component_code
94941                                                                             ,l_component_type_code
94942                                                                             ,l_component_appl_id
94943                                                                             ,l_amb_context_code
94944                                                                             ,l_entity_code
94945                                                                             ,l_event_class_code
94946                                                                            )
94947                                     ,p_token_3                 => 'OWNER'
94948                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
94949                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
94950                                                                           ,p_lookup_code    => l_component_type_code
94951                                                                          )
94952                                     ,p_token_4                 => 'PRODUCT_NAME'
94953                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
94954                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
94955                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
94956                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
94957                                     ,p_ae_header_id            =>  NULL
94958                                        );
94959 
94960         IF (C_LEVEL_ERROR>= g_log_level) THEN
94961                  trace
94962                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
94963                       ,p_level    => C_LEVEL_ERROR
94964                       ,p_module   => l_log_module);
94965         END IF;
94966       END IF;
94967    END IF;
94968    --
94969    --
94970    ------------------------------------------------------------------------------------------------
94971    -- 4219869 Business Flow
94972    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
94973    -- Prior Entry.  Currently, the following code is always generated.
94974    ------------------------------------------------------------------------------------------------
94975    XLA_AE_LINES_PKG.ValidateCurrentLine;
94976 
94977    ------------------------------------------------------------------------------------
94978    -- 4219869 Business Flow
94979    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
94980    ------------------------------------------------------------------------------------
94981    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
94982 
94983    ----------------------------------------------------------------------------------
94984    -- 4219869 Business Flow
94985    -- Update journal entry status -- Need to generate this within IF <condition>
94986    ----------------------------------------------------------------------------------
94987    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
94988          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
94989          ,p_balance_type_code => l_balance_type_code
94990          );
94991 
94992    -------------------------------------------------------------------------------------------
94993    -- 4262811 - Generate the Accrual Reversal lines
94994    -------------------------------------------------------------------------------------------
94995    BEGIN
94996       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
94997                               (g_array_event(p_event_id).array_value_num('header_index'));
94998       IF l_acc_rev_flag IS NULL THEN
94999          l_acc_rev_flag := 'N';
95000       END IF;
95001    EXCEPTION
95002       WHEN OTHERS THEN
95003          l_acc_rev_flag := 'N';
95004    END;
95005    --
95006    IF (l_acc_rev_flag = 'Y') THEN
95007 
95008        -- 4645092  ------------------------------------------------------------------------------
95009        -- To allow MPA report to determine if it should generate report process
95010        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
95011        ------------------------------------------------------------------------------------------
95012 
95013        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
95014        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
95015    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
95016    -- call ADRs
95017    -- Bug 4922099
95018    --
95019    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
95020         (NVL(l_actual_upg_option, 'N') = 'O') OR
95024    NULL;
95021         (NVL(l_enc_upg_option, 'N') = 'O')
95022       )
95023    THEN
95025    --
95026    --
95027    
95028   l_ccid := AcctDerRule_174(
95029            p_application_id           => p_application_id
95030          , p_ae_header_id             => l_ae_header_id 
95031 , p_source_3 => p_source_3
95032 , p_source_17 => p_source_17
95033 , p_source_30 => p_source_30
95034          , x_transaction_coa_id       => l_adr_transaction_coa_id
95035          , x_accounting_coa_id        => l_adr_accounting_coa_id
95036          , x_value_type_code          => l_adr_value_type_code
95037          , p_side                     => 'NA'
95038    );
95039 
95040    xla_ae_lines_pkg.set_ccid(
95041     p_code_combination_id          => l_ccid
95042   , p_value_type_code              => l_adr_value_type_code
95043   , p_transaction_coa_id           => l_adr_transaction_coa_id
95044   , p_accounting_coa_id            => l_adr_accounting_coa_id
95045   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
95046   , p_adr_type_code                => 'S'
95047   , p_component_type               => l_component_type
95048   , p_component_code               => l_component_code
95049   , p_component_type_code          => l_component_type_code
95050   , p_component_appl_id            => l_component_appl_id
95051   , p_amb_context_code             => l_amb_context_code
95052   , p_side                         => 'NA'
95053   );
95054 
95055 
95056    l_segment := AcctDerRule_144(
95057            p_application_id           => p_application_id
95058          , p_ae_header_id             => l_ae_header_id 
95059 , p_source_3 => p_source_3
95060 , p_source_4 => p_source_4
95061          , x_transaction_coa_id       => l_adr_transaction_coa_id
95062          , x_accounting_coa_id        => l_adr_accounting_coa_id
95063          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
95064          , x_flex_value_set_id        => l_adr_flex_value_set_id
95065          , x_value_type_code          => l_adr_value_type_code
95066          , x_value_combination_id     => l_adr_value_combination_id
95067          , x_value_segment_code       => l_adr_value_segment_code
95068          , p_side                     => 'NA'
95069          , p_override_seg_flag        => 'Y'
95070    );
95071 
95072    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
95073 
95074       xla_ae_lines_pkg.set_segment(
95075           p_to_segment_code         => 'GL_ACCOUNT'
95076         , p_segment_value           => l_segment
95077         , p_from_segment_code       => l_adr_value_segment_code
95078         , p_from_combination_id     => l_adr_value_combination_id
95079         , p_value_type_code         => l_adr_value_type_code
95080         , p_transaction_coa_id      => l_adr_transaction_coa_id
95081         , p_accounting_coa_id       => l_adr_accounting_coa_id
95082         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
95083         , p_flex_value_set_id       => l_adr_flex_value_set_id
95084         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
95085         , p_adr_type_code           => 'S'
95086         , p_component_type          => l_component_type
95087         , p_component_code          => l_component_code
95088         , p_component_type_code     => l_component_type_code
95089         , p_component_appl_id       => l_component_appl_id
95090         , p_amb_context_code        => l_amb_context_code
95091         , p_entity_code             => 'TRANSACTIONS'
95092         , p_event_class_code        => 'CATEGORY_RECLASS'
95093         , p_side                    => 'NA'
95094         );
95095 
95096   END IF;
95097 
95098    l_segment := AcctDerRule_168(
95099            p_application_id           => p_application_id
95100          , p_ae_header_id             => l_ae_header_id 
95101 , p_source_3 => p_source_3
95102 , p_source_29 => p_source_29
95103          , x_transaction_coa_id       => l_adr_transaction_coa_id
95104          , x_accounting_coa_id        => l_adr_accounting_coa_id
95105          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
95106          , x_flex_value_set_id        => l_adr_flex_value_set_id
95107          , x_value_type_code          => l_adr_value_type_code
95108          , x_value_combination_id     => l_adr_value_combination_id
95109          , x_value_segment_code       => l_adr_value_segment_code
95110          , p_side                     => 'NA'
95111          , p_override_seg_flag        => 'Y'
95112    );
95113 
95114    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
95115 
95116       xla_ae_lines_pkg.set_segment(
95117           p_to_segment_code         => 'GL_BALANCING'
95118         , p_segment_value           => l_segment
95119         , p_from_segment_code       => l_adr_value_segment_code
95120         , p_from_combination_id     => l_adr_value_combination_id
95121         , p_value_type_code         => l_adr_value_type_code
95122         , p_transaction_coa_id      => l_adr_transaction_coa_id
95123         , p_accounting_coa_id       => l_adr_accounting_coa_id
95124         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
95125         , p_flex_value_set_id       => l_adr_flex_value_set_id
95126         , p_adr_code                => 'FA_EXPENSE_ACCT'
95127         , p_adr_type_code           => 'S'
95128         , p_component_type          => l_component_type
95129         , p_component_code          => l_component_code
95130         , p_component_type_code     => l_component_type_code
95131         , p_component_appl_id       => l_component_appl_id
95132         , p_amb_context_code        => l_amb_context_code
95133         , p_entity_code             => 'TRANSACTIONS'
95134         , p_event_class_code        => 'CATEGORY_RECLASS'
95135         , p_side                    => 'NA'
95136         );
95137 
95138   END IF;
95139 
95140    --
95141    --
95142    END IF;
95143 
95144        --
95148                                          p_header_num   => 1);
95145        -- Update the line information that should be overwritten
95146        --
95147        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
95149        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
95150 
95151        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
95152 
95153        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
95154           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
95155        END IF;
95156 
95157       --
95158       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
95159       --
95160       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
95161           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
95162       ELSE
95163           ---------------------------------------------------------------------------------------------------
95164           -- 4262811a Switch Sign
95165           ---------------------------------------------------------------------------------------------------
95166           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
95167           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
95168                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
95169           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
95170                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
95171           -- 5132302
95172           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
95173                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
95174 
95175       END IF;
95176 
95177       -- 4955764
95178       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
95179       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
95180 
95181 
95182       XLA_AE_LINES_PKG.ValidateCurrentLine;
95183       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
95184 
95185       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
95186                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
95187                ,p_balance_type_code => l_balance_type_code);
95188 
95189    END IF;
95190 
95191    -----------------------------------------------------------------------------------------
95192    -- 4262811 Multiperiod Accounting
95193    -----------------------------------------------------------------------------------------
95194      -- No MPA option is assigned.
95195 
95196 
95197 END IF;
95198 END IF;
95199 --
95200 
95201 --
95202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
95203    trace
95204       (p_msg      => 'END of AcctLineType_286'
95205       ,p_level    => C_LEVEL_PROCEDURE
95206       ,p_module   => l_log_module);
95207 END IF;
95208 --
95209 EXCEPTION
95210   WHEN xla_exceptions_pkg.application_exception THEN
95211       RAISE;
95212   WHEN OTHERS THEN
95213        xla_exceptions_pkg.raise_message
95214            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_286');
95215 END AcctLineType_286;
95216 --
95217 
95218 ---------------------------------------
95219 --
95220 -- PRIVATE FUNCTION
95221 --         AcctLineType_287
95222 --
95223 ---------------------------------------
95224 PROCEDURE AcctLineType_287 (
95225   p_application_id        IN NUMBER
95226  ,p_event_id              IN NUMBER
95227  ,p_calculate_acctd_flag  IN VARCHAR2
95228  ,p_calculate_g_l_flag    IN VARCHAR2
95229  ,p_actual_flag           IN OUT VARCHAR2
95230  ,p_balance_type_code     OUT VARCHAR2
95231  ,p_gain_or_loss_ref      OUT VARCHAR2
95232  
95233 --Period Close Date
95234  , p_source_1            IN DATE
95235 --Generated Code Combination Identifier
95236  , p_source_3            IN NUMBER
95237 --Asset Cost Account
95238  , p_source_9            IN VARCHAR2
95239 --Expense Account Code Combination Identifier
95240  , p_source_29            IN NUMBER
95241 --Default Code Combination Identifier
95242  , p_source_30            IN NUMBER
95243 --Adjustment Type
95244  , p_source_35            IN VARCHAR2
95245 --Transaction Header Identifier
95246  , p_source_36            IN NUMBER
95247 --Adjustment Line Identifier
95248  , p_source_37            IN NUMBER
95249 --Distribution Type Code
95250  , p_source_38            IN VARCHAR2
95251 --Entered Amount
95252  , p_source_39            IN NUMBER
95253 --Currency Code
95254  , p_source_40            IN VARCHAR2
95255 --Source Destination Code
95256  , p_source_42            IN VARCHAR2
95257 )
95258 IS
95259 
95260 l_component_type              VARCHAR2(80);
95261 l_component_code              VARCHAR2(30);
95262 l_component_type_code         VARCHAR2(1);
95263 l_component_appl_id           INTEGER;
95264 l_amb_context_code            VARCHAR2(30);
95265 l_entity_code                 VARCHAR2(30);
95266 l_event_class_code            VARCHAR2(30);
95267 l_ae_header_id                NUMBER;
95268 l_event_type_code             VARCHAR2(30);
95269 l_line_definition_code        VARCHAR2(30);
95270 l_line_definition_owner_code  VARCHAR2(1);
95271 --
95272 -- adr variables
95273 l_segment                     VARCHAR2(30);
95274 l_ccid                        NUMBER;
95275 l_adr_transaction_coa_id      NUMBER;
95276 l_adr_accounting_coa_id       NUMBER;
95277 l_adr_flexfield_segment_code  VARCHAR2(30);
95281 l_adr_value_segment_code      VARCHAR2(30);
95278 l_adr_flex_value_set_id       NUMBER;
95279 l_adr_value_type_code         VARCHAR2(30);
95280 l_adr_value_combination_id    NUMBER;
95282 
95283 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
95284 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
95285 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
95286 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
95287 
95288 -- 4262811 Variables ------------------------------------------------------------------------------------------
95289 l_entered_amt_idx             NUMBER;
95290 l_accted_amt_idx              NUMBER;
95291 l_acc_rev_flag                VARCHAR2(1);
95292 l_accrual_line_num            NUMBER;
95293 l_tmp_amt                     NUMBER;
95294 l_acc_rev_natural_side_code   VARCHAR2(1);
95295 
95296 l_num_entries                 NUMBER;
95297 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
95298 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
95299 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
95300 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
95301 l_recog_line_1                NUMBER;
95302 l_recog_line_2                NUMBER;
95303 
95304 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
95305 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
95306 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
95307 
95308 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
95309 
95310 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
95311 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
95312 
95313 ---------------------------------------------------------------------------------------------------------------
95314 
95315 
95316 --
95317 -- bulk performance
95318 --
95319 l_balance_type_code           VARCHAR2(1);
95320 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
95321 l_log_module                  VARCHAR2(240);
95322 
95323 --
95324 -- Upgrade strategy
95325 --
95326 l_actual_upg_option           VARCHAR2(1);
95327 l_enc_upg_option           VARCHAR2(1);
95328 
95329 --
95330 BEGIN
95331 --
95332 IF g_log_enabled THEN
95333       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_287';
95334 END IF;
95335 --
95336 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
95337 
95338       trace
95339          (p_msg      => 'BEGIN of AcctLineType_287'
95340          ,p_level    => C_LEVEL_PROCEDURE
95341          ,p_module   => l_log_module);
95342 
95343 END IF;
95344 --
95345 l_component_type             := 'AMB_JLT';
95346 l_component_code             := 'FA_RECLASS_SOURCE_COST';
95347 l_component_type_code        := 'S';
95348 l_component_appl_id          :=  140;
95349 l_amb_context_code           := 'DEFAULT';
95350 l_entity_code                := 'TRANSACTIONS';
95351 l_event_class_code           := 'CATEGORY_RECLASS';
95352 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
95353 l_line_definition_owner_code := 'S';
95354 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
95355 --
95356 l_balance_type_code          := 'A';
95357 l_segment                     := NULL;
95358 l_ccid                        := NULL;
95359 l_adr_transaction_coa_id      := NULL;
95360 l_adr_accounting_coa_id       := NULL;
95361 l_adr_flexfield_segment_code  := NULL;
95362 l_adr_flex_value_set_id       := NULL;
95363 l_adr_value_type_code         := NULL;
95364 l_adr_value_combination_id    := NULL;
95365 l_adr_value_segment_code      := NULL;
95366 
95367 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
95368 l_bflow_class_code           := '';    -- 4219869 Business Flow
95369 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
95370 l_budgetary_control_flag     := 'N';
95371 
95372 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
95373 l_bflow_applied_to_amt       := NULL; -- 5132302
95374 l_entered_amt_idx            := NULL;          -- 4262811
95375 l_accted_amt_idx             := NULL;          -- 4262811
95376 l_acc_rev_flag               := NULL;          -- 4262811
95377 l_accrual_line_num           := NULL;          -- 4262811
95378 l_tmp_amt                    := NULL;          -- 4262811
95379 --
95380  
95381 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
95382     l_balance_type_code <> 'B' THEN
95383 IF NVL(p_source_35,'
95384 ') =  'COST' AND 
95385 NVL(p_source_42,'
95386 ') =  'SOURCE'
95387  THEN 
95388 
95389    --
95390    XLA_AE_LINES_PKG.SetNewLine;
95391 
95392    p_balance_type_code          := l_balance_type_code;
95393    -- set the flag so later we will know whether the gain loss line needs to be created
95394    
95395    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
95396      p_actual_flag :='A';
95397    END IF;
95398 
95399    --
95400    -- bulk performance
95401    --
95402    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
95403                                       p_header_num   => 0); -- 4262811
95404    --
95405    -- set accounting line options
95406    --
95407    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
95408            p_natural_side_code          => 'C'
95409          , p_gain_or_loss_flag          => 'N'
95410          , p_gl_transfer_mode_code      => 'S'
95411          , p_acct_entry_type_code       => 'A'
95412          , p_switch_side_flag           => 'Y'
95413          , p_merge_duplicate_code       => 'N'
95414          );
95415    --
95416    l_acc_rev_natural_side_code := 'D';  -- 4262811
95420    --
95417    -- 
95418    --
95419    -- set accounting line type info
95421    xla_ae_lines_pkg.SetAcctLineType
95422       (p_component_type             => l_component_type
95423       ,p_event_type_code            => l_event_type_code
95424       ,p_line_definition_owner_code => l_line_definition_owner_code
95425       ,p_line_definition_code       => l_line_definition_code
95426       ,p_accounting_line_code       => l_component_code
95427       ,p_accounting_line_type_code  => l_component_type_code
95428       ,p_accounting_line_appl_id    => l_component_appl_id
95429       ,p_amb_context_code           => l_amb_context_code
95430       ,p_entity_code                => l_entity_code
95431       ,p_event_class_code           => l_event_class_code);
95432    --
95433    -- set accounting class
95434    --
95435    xla_ae_lines_pkg.SetAcctClass(
95436            p_accounting_class_code  => 'ASSET'
95437          , p_ae_header_id           => l_ae_header_id
95438          );
95439 
95440    --
95441    -- set rounding class
95442    --
95443    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
95444                       'ASSET';
95445 
95446    --
95447    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
95448    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
95449    --
95450    -- bulk performance
95451    --
95452    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
95453 
95454    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
95455       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
95456 
95457    -- 4955764
95458    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
95459       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
95460 
95461    -- 4458381 Public Sector Enh
95462    
95463    --
95464    -- set accounting attributes for the line type
95465    --
95466    l_entered_amt_idx := 4;
95467    l_accted_amt_idx  := 6;
95468    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
95469    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
95470    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
95471    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
95472    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
95473    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
95474    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
95475    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
95476    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
95477    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
95478    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
95479    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
95480    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
95481 
95482    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
95483    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
95484 
95485    ---------------------------------------------------------------------------------------------------------------
95486    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
95487    ---------------------------------------------------------------------------------------------------------------
95488    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
95489 
95490    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
95491    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
95492 
95493    IF xla_accounting_cache_pkg.GetValueChar
95494          (p_source_code         => 'LEDGER_CATEGORY_CODE'
95495          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
95496    AND l_bflow_method_code = 'PRIOR_ENTRY'
95497 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
95498    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
95499          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
95500        )
95501    THEN
95502          xla_ae_lines_pkg.BflowUpgEntry
95503            (p_business_method_code    => l_bflow_method_code
95504            ,p_business_class_code     => l_bflow_class_code
95505            ,p_balance_type            => l_balance_type_code);
95506    ELSE
95507       NULL;
95508 -- No business flow processing for business flow method of NONE.
95509    END IF;
95510 
95511    --
95512    -- call analytical criteria
95513    --
95514    
95515    --
95516    -- call description
95517    --
95518    
95519 xla_ae_lines_pkg.SetLineDescription(
95520    p_ae_header_id => l_ae_header_id
95521   ,p_description  => Description_65 (
95522      p_application_id         => p_application_id
95523    , p_ae_header_id           => l_ae_header_id 
95524 , p_source_1 => p_source_1
95525    )
95526 );
95527 
95528 
95529    --
95530    -- call ADRs
95531    -- Bug 4922099
95532    --
95533    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
95534         (NVL(l_actual_upg_option, 'N') = 'O') OR
95535         (NVL(l_enc_upg_option, 'N') = 'O')
95536       )
95537    THEN
95538    NULL;
95539    --
95540    --
95541    
95542   l_ccid := AcctDerRule_173(
95543            p_application_id           => p_application_id
95544          , p_ae_header_id             => l_ae_header_id 
95545 , p_source_3 => p_source_3
95546 , p_source_30 => p_source_30
95550          , p_side                     => 'NA'
95547          , x_transaction_coa_id       => l_adr_transaction_coa_id
95548          , x_accounting_coa_id        => l_adr_accounting_coa_id
95549          , x_value_type_code          => l_adr_value_type_code
95551    );
95552 
95553    xla_ae_lines_pkg.set_ccid(
95554     p_code_combination_id          => l_ccid
95555   , p_value_type_code              => l_adr_value_type_code
95556   , p_transaction_coa_id           => l_adr_transaction_coa_id
95557   , p_accounting_coa_id            => l_adr_accounting_coa_id
95558   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
95559   , p_adr_type_code                => 'S'
95560   , p_component_type               => l_component_type
95561   , p_component_code               => l_component_code
95562   , p_component_type_code          => l_component_type_code
95563   , p_component_appl_id            => l_component_appl_id
95564   , p_amb_context_code             => l_amb_context_code
95565   , p_side                         => 'NA'
95566   );
95567 
95568 
95569    l_segment := AcctDerRule_148(
95570            p_application_id           => p_application_id
95571          , p_ae_header_id             => l_ae_header_id 
95572 , p_source_3 => p_source_3
95573 , p_source_9 => p_source_9
95574          , x_transaction_coa_id       => l_adr_transaction_coa_id
95575          , x_accounting_coa_id        => l_adr_accounting_coa_id
95576          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
95577          , x_flex_value_set_id        => l_adr_flex_value_set_id
95578          , x_value_type_code          => l_adr_value_type_code
95579          , x_value_combination_id     => l_adr_value_combination_id
95580          , x_value_segment_code       => l_adr_value_segment_code
95581          , p_side                     => 'NA'
95582          , p_override_seg_flag        => 'Y'
95583    );
95584 
95585    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
95586 
95587       xla_ae_lines_pkg.set_segment(
95588           p_to_segment_code         => 'GL_ACCOUNT'
95589         , p_segment_value           => l_segment
95590         , p_from_segment_code       => l_adr_value_segment_code
95591         , p_from_combination_id     => l_adr_value_combination_id
95592         , p_value_type_code         => l_adr_value_type_code
95593         , p_transaction_coa_id      => l_adr_transaction_coa_id
95594         , p_accounting_coa_id       => l_adr_accounting_coa_id
95595         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
95596         , p_flex_value_set_id       => l_adr_flex_value_set_id
95597         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
95598         , p_adr_type_code           => 'S'
95599         , p_component_type          => l_component_type
95600         , p_component_code          => l_component_code
95601         , p_component_type_code     => l_component_type_code
95602         , p_component_appl_id       => l_component_appl_id
95603         , p_amb_context_code        => l_amb_context_code
95604         , p_entity_code             => 'TRANSACTIONS'
95605         , p_event_class_code        => 'CATEGORY_RECLASS'
95606         , p_side                    => 'NA'
95607         );
95608 
95609   END IF;
95610 
95611    l_segment := AcctDerRule_168(
95612            p_application_id           => p_application_id
95613          , p_ae_header_id             => l_ae_header_id 
95614 , p_source_3 => p_source_3
95615 , p_source_29 => p_source_29
95616          , x_transaction_coa_id       => l_adr_transaction_coa_id
95617          , x_accounting_coa_id        => l_adr_accounting_coa_id
95618          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
95619          , x_flex_value_set_id        => l_adr_flex_value_set_id
95620          , x_value_type_code          => l_adr_value_type_code
95621          , x_value_combination_id     => l_adr_value_combination_id
95622          , x_value_segment_code       => l_adr_value_segment_code
95623          , p_side                     => 'NA'
95624          , p_override_seg_flag        => 'Y'
95625    );
95626 
95627    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
95628 
95629       xla_ae_lines_pkg.set_segment(
95630           p_to_segment_code         => 'GL_BALANCING'
95631         , p_segment_value           => l_segment
95632         , p_from_segment_code       => l_adr_value_segment_code
95633         , p_from_combination_id     => l_adr_value_combination_id
95634         , p_value_type_code         => l_adr_value_type_code
95635         , p_transaction_coa_id      => l_adr_transaction_coa_id
95636         , p_accounting_coa_id       => l_adr_accounting_coa_id
95637         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
95638         , p_flex_value_set_id       => l_adr_flex_value_set_id
95639         , p_adr_code                => 'FA_EXPENSE_ACCT'
95640         , p_adr_type_code           => 'S'
95641         , p_component_type          => l_component_type
95642         , p_component_code          => l_component_code
95643         , p_component_type_code     => l_component_type_code
95644         , p_component_appl_id       => l_component_appl_id
95645         , p_amb_context_code        => l_amb_context_code
95646         , p_entity_code             => 'TRANSACTIONS'
95647         , p_event_class_code        => 'CATEGORY_RECLASS'
95648         , p_side                    => 'NA'
95649         );
95650 
95651   END IF;
95652 
95653    --
95654    --
95655    END IF;
95656    --
95657    -- Bug 4922099
95658    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
95659           (NVL(l_enc_upg_option, 'N') = 'O')
95660         ) AND
95661         (l_bflow_method_code = 'PRIOR_ENTRY')
95662       )
95663    THEN
95664       IF
95665       --
95666       1 = 2
95667       --
95668       THEN
95669       xla_accounting_err_pkg.build_message
95673                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
95670                                     (p_appli_s_name            => 'XLA'
95671                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
95672                                     ,p_token_1                 => 'LINE_NUMBER'
95674                                     ,p_token_2                 => 'LINE_TYPE_NAME'
95675                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
95676                                                                              l_component_type
95677                                                                             ,l_component_code
95678                                                                             ,l_component_type_code
95679                                                                             ,l_component_appl_id
95680                                                                             ,l_amb_context_code
95681                                                                             ,l_entity_code
95682                                                                             ,l_event_class_code
95683                                                                            )
95684                                     ,p_token_3                 => 'OWNER'
95685                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
95686                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
95687                                                                           ,p_lookup_code    => l_component_type_code
95688                                                                          )
95689                                     ,p_token_4                 => 'PRODUCT_NAME'
95690                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
95691                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
95692                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
95693                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
95694                                     ,p_ae_header_id            =>  NULL
95695                                        );
95696 
95697         IF (C_LEVEL_ERROR>= g_log_level) THEN
95698                  trace
95699                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
95700                       ,p_level    => C_LEVEL_ERROR
95701                       ,p_module   => l_log_module);
95702         END IF;
95703       END IF;
95704    END IF;
95705    --
95706    --
95707    ------------------------------------------------------------------------------------------------
95708    -- 4219869 Business Flow
95709    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
95710    -- Prior Entry.  Currently, the following code is always generated.
95711    ------------------------------------------------------------------------------------------------
95712    XLA_AE_LINES_PKG.ValidateCurrentLine;
95713 
95714    ------------------------------------------------------------------------------------
95715    -- 4219869 Business Flow
95716    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
95717    ------------------------------------------------------------------------------------
95718    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
95719 
95720    ----------------------------------------------------------------------------------
95721    -- 4219869 Business Flow
95722    -- Update journal entry status -- Need to generate this within IF <condition>
95723    ----------------------------------------------------------------------------------
95724    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
95725          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
95726          ,p_balance_type_code => l_balance_type_code
95727          );
95728 
95729    -------------------------------------------------------------------------------------------
95730    -- 4262811 - Generate the Accrual Reversal lines
95731    -------------------------------------------------------------------------------------------
95732    BEGIN
95733       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
95734                               (g_array_event(p_event_id).array_value_num('header_index'));
95735       IF l_acc_rev_flag IS NULL THEN
95736          l_acc_rev_flag := 'N';
95737       END IF;
95738    EXCEPTION
95739       WHEN OTHERS THEN
95740          l_acc_rev_flag := 'N';
95741    END;
95742    --
95743    IF (l_acc_rev_flag = 'Y') THEN
95744 
95745        -- 4645092  ------------------------------------------------------------------------------
95746        -- To allow MPA report to determine if it should generate report process
95747        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
95748        ------------------------------------------------------------------------------------------
95749 
95750        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
95751        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
95752    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
95753    -- call ADRs
95754    -- Bug 4922099
95755    --
95756    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
95757         (NVL(l_actual_upg_option, 'N') = 'O') OR
95758         (NVL(l_enc_upg_option, 'N') = 'O')
95759       )
95760    THEN
95761    NULL;
95762    --
95763    --
95764    
95765   l_ccid := AcctDerRule_173(
95766            p_application_id           => p_application_id
95767          , p_ae_header_id             => l_ae_header_id 
95768 , p_source_3 => p_source_3
95769 , p_source_30 => p_source_30
95770          , x_transaction_coa_id       => l_adr_transaction_coa_id
95774    );
95771          , x_accounting_coa_id        => l_adr_accounting_coa_id
95772          , x_value_type_code          => l_adr_value_type_code
95773          , p_side                     => 'NA'
95775 
95776    xla_ae_lines_pkg.set_ccid(
95777     p_code_combination_id          => l_ccid
95778   , p_value_type_code              => l_adr_value_type_code
95779   , p_transaction_coa_id           => l_adr_transaction_coa_id
95780   , p_accounting_coa_id            => l_adr_accounting_coa_id
95781   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
95782   , p_adr_type_code                => 'S'
95783   , p_component_type               => l_component_type
95784   , p_component_code               => l_component_code
95785   , p_component_type_code          => l_component_type_code
95786   , p_component_appl_id            => l_component_appl_id
95787   , p_amb_context_code             => l_amb_context_code
95788   , p_side                         => 'NA'
95789   );
95790 
95791 
95792    l_segment := AcctDerRule_148(
95793            p_application_id           => p_application_id
95794          , p_ae_header_id             => l_ae_header_id 
95795 , p_source_3 => p_source_3
95796 , p_source_9 => p_source_9
95797          , x_transaction_coa_id       => l_adr_transaction_coa_id
95798          , x_accounting_coa_id        => l_adr_accounting_coa_id
95799          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
95800          , x_flex_value_set_id        => l_adr_flex_value_set_id
95801          , x_value_type_code          => l_adr_value_type_code
95802          , x_value_combination_id     => l_adr_value_combination_id
95803          , x_value_segment_code       => l_adr_value_segment_code
95804          , p_side                     => 'NA'
95805          , p_override_seg_flag        => 'Y'
95806    );
95807 
95808    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
95809 
95810       xla_ae_lines_pkg.set_segment(
95811           p_to_segment_code         => 'GL_ACCOUNT'
95812         , p_segment_value           => l_segment
95813         , p_from_segment_code       => l_adr_value_segment_code
95814         , p_from_combination_id     => l_adr_value_combination_id
95815         , p_value_type_code         => l_adr_value_type_code
95816         , p_transaction_coa_id      => l_adr_transaction_coa_id
95817         , p_accounting_coa_id       => l_adr_accounting_coa_id
95818         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
95819         , p_flex_value_set_id       => l_adr_flex_value_set_id
95820         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
95821         , p_adr_type_code           => 'S'
95822         , p_component_type          => l_component_type
95823         , p_component_code          => l_component_code
95824         , p_component_type_code     => l_component_type_code
95825         , p_component_appl_id       => l_component_appl_id
95826         , p_amb_context_code        => l_amb_context_code
95827         , p_entity_code             => 'TRANSACTIONS'
95828         , p_event_class_code        => 'CATEGORY_RECLASS'
95829         , p_side                    => 'NA'
95830         );
95831 
95832   END IF;
95833 
95834    l_segment := AcctDerRule_168(
95835            p_application_id           => p_application_id
95836          , p_ae_header_id             => l_ae_header_id 
95837 , p_source_3 => p_source_3
95838 , p_source_29 => p_source_29
95839          , x_transaction_coa_id       => l_adr_transaction_coa_id
95840          , x_accounting_coa_id        => l_adr_accounting_coa_id
95841          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
95842          , x_flex_value_set_id        => l_adr_flex_value_set_id
95843          , x_value_type_code          => l_adr_value_type_code
95844          , x_value_combination_id     => l_adr_value_combination_id
95845          , x_value_segment_code       => l_adr_value_segment_code
95846          , p_side                     => 'NA'
95847          , p_override_seg_flag        => 'Y'
95848    );
95849 
95850    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
95851 
95852       xla_ae_lines_pkg.set_segment(
95853           p_to_segment_code         => 'GL_BALANCING'
95854         , p_segment_value           => l_segment
95855         , p_from_segment_code       => l_adr_value_segment_code
95856         , p_from_combination_id     => l_adr_value_combination_id
95857         , p_value_type_code         => l_adr_value_type_code
95858         , p_transaction_coa_id      => l_adr_transaction_coa_id
95859         , p_accounting_coa_id       => l_adr_accounting_coa_id
95860         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
95861         , p_flex_value_set_id       => l_adr_flex_value_set_id
95862         , p_adr_code                => 'FA_EXPENSE_ACCT'
95863         , p_adr_type_code           => 'S'
95864         , p_component_type          => l_component_type
95865         , p_component_code          => l_component_code
95866         , p_component_type_code     => l_component_type_code
95867         , p_component_appl_id       => l_component_appl_id
95868         , p_amb_context_code        => l_amb_context_code
95869         , p_entity_code             => 'TRANSACTIONS'
95870         , p_event_class_code        => 'CATEGORY_RECLASS'
95871         , p_side                    => 'NA'
95872         );
95873 
95874   END IF;
95875 
95876    --
95877    --
95878    END IF;
95879 
95880        --
95881        -- Update the line information that should be overwritten
95882        --
95883        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
95884                                          p_header_num   => 1);
95885        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
95886 
95887        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
95888 
95889        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
95893       --
95890           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
95891        END IF;
95892 
95894       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
95895       --
95896       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
95897           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
95898       ELSE
95899           ---------------------------------------------------------------------------------------------------
95900           -- 4262811a Switch Sign
95901           ---------------------------------------------------------------------------------------------------
95902           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
95903           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
95904                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
95905           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
95906                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
95907           -- 5132302
95908           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
95909                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
95910 
95911       END IF;
95912 
95913       -- 4955764
95914       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
95915       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
95916 
95917 
95918       XLA_AE_LINES_PKG.ValidateCurrentLine;
95919       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
95920 
95921       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
95922                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
95923                ,p_balance_type_code => l_balance_type_code);
95924 
95925    END IF;
95926 
95927    -----------------------------------------------------------------------------------------
95928    -- 4262811 Multiperiod Accounting
95929    -----------------------------------------------------------------------------------------
95930      -- No MPA option is assigned.
95931 
95932 
95933 END IF;
95934 END IF;
95935 --
95936 
95937 --
95938 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
95939    trace
95940       (p_msg      => 'END of AcctLineType_287'
95941       ,p_level    => C_LEVEL_PROCEDURE
95942       ,p_module   => l_log_module);
95943 END IF;
95944 --
95945 EXCEPTION
95946   WHEN xla_exceptions_pkg.application_exception THEN
95947       RAISE;
95948   WHEN OTHERS THEN
95949        xla_exceptions_pkg.raise_message
95950            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_287');
95951 END AcctLineType_287;
95952 --
95953 
95954 ---------------------------------------
95955 --
95956 -- PRIVATE FUNCTION
95957 --         AcctLineType_288
95958 --
95959 ---------------------------------------
95960 PROCEDURE AcctLineType_288 (
95961   p_application_id        IN NUMBER
95962  ,p_event_id              IN NUMBER
95963  ,p_calculate_acctd_flag  IN VARCHAR2
95964  ,p_calculate_g_l_flag    IN VARCHAR2
95965  ,p_actual_flag           IN OUT VARCHAR2
95966  ,p_balance_type_code     OUT VARCHAR2
95967  ,p_gain_or_loss_ref      OUT VARCHAR2
95968  
95969 --Period Close Date
95970  , p_source_1            IN DATE
95971 --Generated Code Combination Identifier
95972  , p_source_3            IN NUMBER
95973 --Expense Account Code Combination Identifier
95974  , p_source_29            IN NUMBER
95975 --Adjustment Type
95976  , p_source_35            IN VARCHAR2
95977 --Transaction Header Identifier
95978  , p_source_36            IN NUMBER
95979 --Adjustment Line Identifier
95980  , p_source_37            IN NUMBER
95981 --Distribution Type Code
95982  , p_source_38            IN VARCHAR2
95983 --Entered Amount
95984  , p_source_39            IN NUMBER
95985 --Currency Code
95986  , p_source_40            IN VARCHAR2
95987 --Source Destination Code
95988  , p_source_42            IN VARCHAR2
95989 )
95990 IS
95991 
95992 l_component_type              VARCHAR2(80);
95993 l_component_code              VARCHAR2(30);
95994 l_component_type_code         VARCHAR2(1);
95995 l_component_appl_id           INTEGER;
95996 l_amb_context_code            VARCHAR2(30);
95997 l_entity_code                 VARCHAR2(30);
95998 l_event_class_code            VARCHAR2(30);
95999 l_ae_header_id                NUMBER;
96000 l_event_type_code             VARCHAR2(30);
96001 l_line_definition_code        VARCHAR2(30);
96002 l_line_definition_owner_code  VARCHAR2(1);
96003 --
96004 -- adr variables
96005 l_segment                     VARCHAR2(30);
96006 l_ccid                        NUMBER;
96007 l_adr_transaction_coa_id      NUMBER;
96008 l_adr_accounting_coa_id       NUMBER;
96009 l_adr_flexfield_segment_code  VARCHAR2(30);
96010 l_adr_flex_value_set_id       NUMBER;
96011 l_adr_value_type_code         VARCHAR2(30);
96012 l_adr_value_combination_id    NUMBER;
96013 l_adr_value_segment_code      VARCHAR2(30);
96014 
96015 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
96016 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
96017 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
96018 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
96019 
96020 -- 4262811 Variables ------------------------------------------------------------------------------------------
96021 l_entered_amt_idx             NUMBER;
96025 l_tmp_amt                     NUMBER;
96022 l_accted_amt_idx              NUMBER;
96023 l_acc_rev_flag                VARCHAR2(1);
96024 l_accrual_line_num            NUMBER;
96026 l_acc_rev_natural_side_code   VARCHAR2(1);
96027 
96028 l_num_entries                 NUMBER;
96029 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
96030 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
96031 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
96032 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
96033 l_recog_line_1                NUMBER;
96034 l_recog_line_2                NUMBER;
96035 
96036 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
96037 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
96038 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
96039 
96040 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
96041 
96042 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
96043 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
96044 
96045 ---------------------------------------------------------------------------------------------------------------
96046 
96047 
96048 --
96049 -- bulk performance
96050 --
96051 l_balance_type_code           VARCHAR2(1);
96052 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
96053 l_log_module                  VARCHAR2(240);
96054 
96055 --
96056 -- Upgrade strategy
96057 --
96058 l_actual_upg_option           VARCHAR2(1);
96059 l_enc_upg_option           VARCHAR2(1);
96060 
96061 --
96062 BEGIN
96063 --
96064 IF g_log_enabled THEN
96065       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_288';
96066 END IF;
96067 --
96068 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
96069 
96070       trace
96071          (p_msg      => 'BEGIN of AcctLineType_288'
96072          ,p_level    => C_LEVEL_PROCEDURE
96073          ,p_module   => l_log_module);
96074 
96075 END IF;
96076 --
96077 l_component_type             := 'AMB_JLT';
96078 l_component_code             := 'FA_RECLASS_SOURCE_DEPRN_EXP';
96079 l_component_type_code        := 'S';
96080 l_component_appl_id          :=  140;
96081 l_amb_context_code           := 'DEFAULT';
96082 l_entity_code                := 'TRANSACTIONS';
96083 l_event_class_code           := 'CATEGORY_RECLASS';
96084 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
96085 l_line_definition_owner_code := 'S';
96086 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
96087 --
96088 l_balance_type_code          := 'A';
96089 l_segment                     := NULL;
96090 l_ccid                        := NULL;
96091 l_adr_transaction_coa_id      := NULL;
96092 l_adr_accounting_coa_id       := NULL;
96093 l_adr_flexfield_segment_code  := NULL;
96094 l_adr_flex_value_set_id       := NULL;
96095 l_adr_value_type_code         := NULL;
96096 l_adr_value_combination_id    := NULL;
96097 l_adr_value_segment_code      := NULL;
96098 
96099 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
96100 l_bflow_class_code           := '';    -- 4219869 Business Flow
96101 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
96102 l_budgetary_control_flag     := 'N';
96103 
96104 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
96105 l_bflow_applied_to_amt       := NULL; -- 5132302
96106 l_entered_amt_idx            := NULL;          -- 4262811
96107 l_accted_amt_idx             := NULL;          -- 4262811
96108 l_acc_rev_flag               := NULL;          -- 4262811
96109 l_accrual_line_num           := NULL;          -- 4262811
96110 l_tmp_amt                    := NULL;          -- 4262811
96111 --
96112  
96113 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
96114     l_balance_type_code <> 'B' THEN
96115 IF NVL(p_source_35,'
96116 ') =  'EXPENSE' AND 
96117 NVL(p_source_42,'
96118 ') =  'SOURCE'
96119  THEN 
96120 
96121    --
96122    XLA_AE_LINES_PKG.SetNewLine;
96123 
96124    p_balance_type_code          := l_balance_type_code;
96125    -- set the flag so later we will know whether the gain loss line needs to be created
96126    
96127    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
96128      p_actual_flag :='A';
96129    END IF;
96130 
96131    --
96132    -- bulk performance
96133    --
96134    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
96135                                       p_header_num   => 0); -- 4262811
96136    --
96137    -- set accounting line options
96138    --
96139    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
96140            p_natural_side_code          => 'C'
96141          , p_gain_or_loss_flag          => 'N'
96142          , p_gl_transfer_mode_code      => 'S'
96143          , p_acct_entry_type_code       => 'A'
96144          , p_switch_side_flag           => 'Y'
96145          , p_merge_duplicate_code       => 'N'
96146          );
96147    --
96148    l_acc_rev_natural_side_code := 'D';  -- 4262811
96149    -- 
96150    --
96151    -- set accounting line type info
96152    --
96153    xla_ae_lines_pkg.SetAcctLineType
96154       (p_component_type             => l_component_type
96155       ,p_event_type_code            => l_event_type_code
96156       ,p_line_definition_owner_code => l_line_definition_owner_code
96157       ,p_line_definition_code       => l_line_definition_code
96158       ,p_accounting_line_code       => l_component_code
96159       ,p_accounting_line_type_code  => l_component_type_code
96160       ,p_accounting_line_appl_id    => l_component_appl_id
96161       ,p_amb_context_code           => l_amb_context_code
96165    -- set accounting class
96162       ,p_entity_code                => l_entity_code
96163       ,p_event_class_code           => l_event_class_code);
96164    --
96166    --
96167    xla_ae_lines_pkg.SetAcctClass(
96168            p_accounting_class_code  => 'EXPENSE'
96169          , p_ae_header_id           => l_ae_header_id
96170          );
96171 
96172    --
96173    -- set rounding class
96174    --
96175    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
96176                       'EXPENSE';
96177 
96178    --
96179    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
96180    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
96181    --
96182    -- bulk performance
96183    --
96184    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
96185 
96186    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
96187       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
96188 
96189    -- 4955764
96190    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
96191       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
96192 
96193    -- 4458381 Public Sector Enh
96194    
96195    --
96196    -- set accounting attributes for the line type
96197    --
96198    l_entered_amt_idx := 4;
96199    l_accted_amt_idx  := 6;
96200    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
96201    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
96202    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
96203    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
96204    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
96205    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
96206    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
96207    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
96208    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
96209    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
96210    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
96211    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
96212    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
96213 
96214    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
96215    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
96216 
96217    ---------------------------------------------------------------------------------------------------------------
96218    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
96219    ---------------------------------------------------------------------------------------------------------------
96220    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
96221 
96222    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
96223    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
96224 
96225    IF xla_accounting_cache_pkg.GetValueChar
96226          (p_source_code         => 'LEDGER_CATEGORY_CODE'
96227          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
96228    AND l_bflow_method_code = 'PRIOR_ENTRY'
96229 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
96230    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
96231          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
96232        )
96233    THEN
96234          xla_ae_lines_pkg.BflowUpgEntry
96235            (p_business_method_code    => l_bflow_method_code
96236            ,p_business_class_code     => l_bflow_class_code
96237            ,p_balance_type            => l_balance_type_code);
96238    ELSE
96239       NULL;
96240 -- No business flow processing for business flow method of NONE.
96241    END IF;
96242 
96243    --
96244    -- call analytical criteria
96245    --
96246    
96247    --
96248    -- call description
96249    --
96250    
96251 xla_ae_lines_pkg.SetLineDescription(
96252    p_ae_header_id => l_ae_header_id
96253   ,p_description  => Description_66 (
96254      p_application_id         => p_application_id
96255    , p_ae_header_id           => l_ae_header_id 
96256 , p_source_1 => p_source_1
96257    )
96258 );
96259 
96260 
96261    --
96262    -- call ADRs
96263    -- Bug 4922099
96264    --
96265    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
96266         (NVL(l_actual_upg_option, 'N') = 'O') OR
96267         (NVL(l_enc_upg_option, 'N') = 'O')
96268       )
96269    THEN
96270    NULL;
96271    --
96272    --
96273    
96274   l_ccid := AcctDerRule_175(
96275            p_application_id           => p_application_id
96276          , p_ae_header_id             => l_ae_header_id 
96277 , p_source_3 => p_source_3
96278 , p_source_29 => p_source_29
96279          , x_transaction_coa_id       => l_adr_transaction_coa_id
96280          , x_accounting_coa_id        => l_adr_accounting_coa_id
96281          , x_value_type_code          => l_adr_value_type_code
96282          , p_side                     => 'NA'
96283    );
96284 
96285    xla_ae_lines_pkg.set_ccid(
96286     p_code_combination_id          => l_ccid
96287   , p_value_type_code              => l_adr_value_type_code
96288   , p_transaction_coa_id           => l_adr_transaction_coa_id
96289   , p_accounting_coa_id            => l_adr_accounting_coa_id
96290   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
96291   , p_adr_type_code                => 'S'
96295   , p_component_appl_id            => l_component_appl_id
96292   , p_component_type               => l_component_type
96293   , p_component_code               => l_component_code
96294   , p_component_type_code          => l_component_type_code
96296   , p_amb_context_code             => l_amb_context_code
96297   , p_side                         => 'NA'
96298   );
96299 
96300 
96301    --
96302    --
96303    END IF;
96304    --
96305    -- Bug 4922099
96306    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
96307           (NVL(l_enc_upg_option, 'N') = 'O')
96308         ) AND
96309         (l_bflow_method_code = 'PRIOR_ENTRY')
96310       )
96311    THEN
96312       IF
96313       --
96314       1 = 2
96315       --
96316       THEN
96317       xla_accounting_err_pkg.build_message
96318                                     (p_appli_s_name            => 'XLA'
96319                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
96320                                     ,p_token_1                 => 'LINE_NUMBER'
96321                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
96322                                     ,p_token_2                 => 'LINE_TYPE_NAME'
96323                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
96324                                                                              l_component_type
96325                                                                             ,l_component_code
96326                                                                             ,l_component_type_code
96327                                                                             ,l_component_appl_id
96328                                                                             ,l_amb_context_code
96329                                                                             ,l_entity_code
96330                                                                             ,l_event_class_code
96331                                                                            )
96332                                     ,p_token_3                 => 'OWNER'
96333                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
96334                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
96335                                                                           ,p_lookup_code    => l_component_type_code
96336                                                                          )
96337                                     ,p_token_4                 => 'PRODUCT_NAME'
96338                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
96339                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
96340                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
96341                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
96342                                     ,p_ae_header_id            =>  NULL
96343                                        );
96344 
96345         IF (C_LEVEL_ERROR>= g_log_level) THEN
96346                  trace
96347                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
96348                       ,p_level    => C_LEVEL_ERROR
96349                       ,p_module   => l_log_module);
96350         END IF;
96351       END IF;
96352    END IF;
96353    --
96354    --
96355    ------------------------------------------------------------------------------------------------
96356    -- 4219869 Business Flow
96357    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
96358    -- Prior Entry.  Currently, the following code is always generated.
96359    ------------------------------------------------------------------------------------------------
96360    XLA_AE_LINES_PKG.ValidateCurrentLine;
96361 
96362    ------------------------------------------------------------------------------------
96363    -- 4219869 Business Flow
96364    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
96365    ------------------------------------------------------------------------------------
96366    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
96367 
96368    ----------------------------------------------------------------------------------
96369    -- 4219869 Business Flow
96370    -- Update journal entry status -- Need to generate this within IF <condition>
96371    ----------------------------------------------------------------------------------
96372    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
96373          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
96374          ,p_balance_type_code => l_balance_type_code
96375          );
96376 
96377    -------------------------------------------------------------------------------------------
96378    -- 4262811 - Generate the Accrual Reversal lines
96379    -------------------------------------------------------------------------------------------
96380    BEGIN
96381       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
96382                               (g_array_event(p_event_id).array_value_num('header_index'));
96383       IF l_acc_rev_flag IS NULL THEN
96384          l_acc_rev_flag := 'N';
96385       END IF;
96386    EXCEPTION
96387       WHEN OTHERS THEN
96388          l_acc_rev_flag := 'N';
96389    END;
96390    --
96391    IF (l_acc_rev_flag = 'Y') THEN
96392 
96393        -- 4645092  ------------------------------------------------------------------------------
96394        -- To allow MPA report to determine if it should generate report process
96395        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
96396        ------------------------------------------------------------------------------------------
96397 
96401    -- call ADRs
96398        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
96399        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
96400    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
96402    -- Bug 4922099
96403    --
96404    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
96405         (NVL(l_actual_upg_option, 'N') = 'O') OR
96406         (NVL(l_enc_upg_option, 'N') = 'O')
96407       )
96408    THEN
96409    NULL;
96410    --
96411    --
96412    
96413   l_ccid := AcctDerRule_175(
96414            p_application_id           => p_application_id
96415          , p_ae_header_id             => l_ae_header_id 
96416 , p_source_3 => p_source_3
96417 , p_source_29 => p_source_29
96418          , x_transaction_coa_id       => l_adr_transaction_coa_id
96419          , x_accounting_coa_id        => l_adr_accounting_coa_id
96420          , x_value_type_code          => l_adr_value_type_code
96421          , p_side                     => 'NA'
96422    );
96423 
96424    xla_ae_lines_pkg.set_ccid(
96425     p_code_combination_id          => l_ccid
96426   , p_value_type_code              => l_adr_value_type_code
96427   , p_transaction_coa_id           => l_adr_transaction_coa_id
96428   , p_accounting_coa_id            => l_adr_accounting_coa_id
96429   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
96430   , p_adr_type_code                => 'S'
96431   , p_component_type               => l_component_type
96432   , p_component_code               => l_component_code
96433   , p_component_type_code          => l_component_type_code
96434   , p_component_appl_id            => l_component_appl_id
96435   , p_amb_context_code             => l_amb_context_code
96436   , p_side                         => 'NA'
96437   );
96438 
96439 
96440    --
96441    --
96442    END IF;
96443 
96444        --
96445        -- Update the line information that should be overwritten
96446        --
96447        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
96448                                          p_header_num   => 1);
96449        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
96450 
96451        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
96452 
96453        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
96454           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
96455        END IF;
96456 
96457       --
96458       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
96459       --
96460       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
96461           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
96462       ELSE
96463           ---------------------------------------------------------------------------------------------------
96464           -- 4262811a Switch Sign
96465           ---------------------------------------------------------------------------------------------------
96466           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
96467           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
96468                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
96469           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
96470                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
96471           -- 5132302
96472           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
96473                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
96474 
96475       END IF;
96476 
96477       -- 4955764
96478       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
96479       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
96480 
96481 
96482       XLA_AE_LINES_PKG.ValidateCurrentLine;
96483       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
96484 
96485       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
96486                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
96487                ,p_balance_type_code => l_balance_type_code);
96488 
96489    END IF;
96490 
96491    -----------------------------------------------------------------------------------------
96492    -- 4262811 Multiperiod Accounting
96493    -----------------------------------------------------------------------------------------
96494      -- No MPA option is assigned.
96495 
96496 
96497 END IF;
96498 END IF;
96499 --
96500 
96501 --
96502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
96503    trace
96504       (p_msg      => 'END of AcctLineType_288'
96505       ,p_level    => C_LEVEL_PROCEDURE
96506       ,p_module   => l_log_module);
96507 END IF;
96508 --
96509 EXCEPTION
96510   WHEN xla_exceptions_pkg.application_exception THEN
96511       RAISE;
96512   WHEN OTHERS THEN
96513        xla_exceptions_pkg.raise_message
96514            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_288');
96515 END AcctLineType_288;
96516 --
96517 
96518 ---------------------------------------
96519 --
96520 -- PRIVATE FUNCTION
96521 --         AcctLineType_289
96522 --
96523 ---------------------------------------
96524 PROCEDURE AcctLineType_289 (
96525   p_application_id        IN NUMBER
96526  ,p_event_id              IN NUMBER
96527  ,p_calculate_acctd_flag  IN VARCHAR2
96528  ,p_calculate_g_l_flag    IN VARCHAR2
96532  
96529  ,p_actual_flag           IN OUT VARCHAR2
96530  ,p_balance_type_code     OUT VARCHAR2
96531  ,p_gain_or_loss_ref      OUT VARCHAR2
96533 --Period Close Date
96534  , p_source_1            IN DATE
96535 --Generated Code Combination Identifier
96536  , p_source_3            IN NUMBER
96537 --Depreciation Reserve Account
96538  , p_source_10            IN VARCHAR2
96539 --Generated Offset Code Combination Identifier
96540  , p_source_17            IN NUMBER
96541 --Expense Account Code Combination Identifier
96542  , p_source_29            IN NUMBER
96543 --Default Code Combination Identifier
96544  , p_source_30            IN NUMBER
96545 --Adjustment Type
96546  , p_source_35            IN VARCHAR2
96547 --Transaction Header Identifier
96548  , p_source_36            IN NUMBER
96549 --Adjustment Line Identifier
96550  , p_source_37            IN NUMBER
96551 --Distribution Type Code
96552  , p_source_38            IN VARCHAR2
96553 --Entered Amount
96554  , p_source_39            IN NUMBER
96555 --Currency Code
96556  , p_source_40            IN VARCHAR2
96557 --Source Destination Code
96558  , p_source_42            IN VARCHAR2
96559 )
96560 IS
96561 
96562 l_component_type              VARCHAR2(80);
96563 l_component_code              VARCHAR2(30);
96564 l_component_type_code         VARCHAR2(1);
96565 l_component_appl_id           INTEGER;
96566 l_amb_context_code            VARCHAR2(30);
96567 l_entity_code                 VARCHAR2(30);
96568 l_event_class_code            VARCHAR2(30);
96569 l_ae_header_id                NUMBER;
96570 l_event_type_code             VARCHAR2(30);
96571 l_line_definition_code        VARCHAR2(30);
96572 l_line_definition_owner_code  VARCHAR2(1);
96573 --
96574 -- adr variables
96575 l_segment                     VARCHAR2(30);
96576 l_ccid                        NUMBER;
96577 l_adr_transaction_coa_id      NUMBER;
96578 l_adr_accounting_coa_id       NUMBER;
96579 l_adr_flexfield_segment_code  VARCHAR2(30);
96580 l_adr_flex_value_set_id       NUMBER;
96581 l_adr_value_type_code         VARCHAR2(30);
96582 l_adr_value_combination_id    NUMBER;
96583 l_adr_value_segment_code      VARCHAR2(30);
96584 
96585 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
96586 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
96587 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
96588 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
96589 
96590 -- 4262811 Variables ------------------------------------------------------------------------------------------
96591 l_entered_amt_idx             NUMBER;
96592 l_accted_amt_idx              NUMBER;
96593 l_acc_rev_flag                VARCHAR2(1);
96594 l_accrual_line_num            NUMBER;
96595 l_tmp_amt                     NUMBER;
96596 l_acc_rev_natural_side_code   VARCHAR2(1);
96597 
96598 l_num_entries                 NUMBER;
96599 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
96600 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
96601 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
96602 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
96603 l_recog_line_1                NUMBER;
96604 l_recog_line_2                NUMBER;
96605 
96606 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
96607 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
96608 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
96609 
96610 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
96611 
96612 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
96613 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
96614 
96615 ---------------------------------------------------------------------------------------------------------------
96616 
96617 
96618 --
96619 -- bulk performance
96620 --
96621 l_balance_type_code           VARCHAR2(1);
96622 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
96623 l_log_module                  VARCHAR2(240);
96624 
96625 --
96626 -- Upgrade strategy
96627 --
96628 l_actual_upg_option           VARCHAR2(1);
96629 l_enc_upg_option           VARCHAR2(1);
96630 
96631 --
96632 BEGIN
96633 --
96634 IF g_log_enabled THEN
96635       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_289';
96636 END IF;
96637 --
96638 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
96639 
96640       trace
96641          (p_msg      => 'BEGIN of AcctLineType_289'
96642          ,p_level    => C_LEVEL_PROCEDURE
96643          ,p_module   => l_log_module);
96644 
96645 END IF;
96646 --
96647 l_component_type             := 'AMB_JLT';
96648 l_component_code             := 'FA_RECLASS_SOURCE_DEPRN_RESERV';
96649 l_component_type_code        := 'S';
96650 l_component_appl_id          :=  140;
96651 l_amb_context_code           := 'DEFAULT';
96652 l_entity_code                := 'TRANSACTIONS';
96653 l_event_class_code           := 'CATEGORY_RECLASS';
96654 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
96655 l_line_definition_owner_code := 'S';
96656 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
96657 --
96658 l_balance_type_code          := 'A';
96659 l_segment                     := NULL;
96660 l_ccid                        := NULL;
96661 l_adr_transaction_coa_id      := NULL;
96662 l_adr_accounting_coa_id       := NULL;
96663 l_adr_flexfield_segment_code  := NULL;
96664 l_adr_flex_value_set_id       := NULL;
96665 l_adr_value_type_code         := NULL;
96666 l_adr_value_combination_id    := NULL;
96667 l_adr_value_segment_code      := NULL;
96668 
96672 l_budgetary_control_flag     := 'N';
96669 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
96670 l_bflow_class_code           := '';    -- 4219869 Business Flow
96671 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
96673 
96674 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
96675 l_bflow_applied_to_amt       := NULL; -- 5132302
96676 l_entered_amt_idx            := NULL;          -- 4262811
96677 l_accted_amt_idx             := NULL;          -- 4262811
96678 l_acc_rev_flag               := NULL;          -- 4262811
96679 l_accrual_line_num           := NULL;          -- 4262811
96680 l_tmp_amt                    := NULL;          -- 4262811
96681 --
96682  
96683 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
96684     l_balance_type_code <> 'B' THEN
96685 IF (NVL(p_source_35,'
96686 ') =  'EXPENSE' OR 
96687 NVL(p_source_35,'
96688 ') =  'RESERVE') AND 
96689 NVL(p_source_42,'
96690 ') =  'SOURCE'
96691  THEN 
96692 
96693    --
96694    XLA_AE_LINES_PKG.SetNewLine;
96695 
96696    p_balance_type_code          := l_balance_type_code;
96697    -- set the flag so later we will know whether the gain loss line needs to be created
96698    
96699    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
96700      p_actual_flag :='A';
96701    END IF;
96702 
96703    --
96704    -- bulk performance
96705    --
96706    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
96707                                       p_header_num   => 0); -- 4262811
96708    --
96709    -- set accounting line options
96710    --
96711    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
96712            p_natural_side_code          => 'D'
96713          , p_gain_or_loss_flag          => 'N'
96714          , p_gl_transfer_mode_code      => 'S'
96715          , p_acct_entry_type_code       => 'A'
96716          , p_switch_side_flag           => 'Y'
96717          , p_merge_duplicate_code       => 'N'
96718          );
96719    --
96720    l_acc_rev_natural_side_code := 'C';  -- 4262811
96721    -- 
96722    --
96723    -- set accounting line type info
96724    --
96725    xla_ae_lines_pkg.SetAcctLineType
96726       (p_component_type             => l_component_type
96727       ,p_event_type_code            => l_event_type_code
96728       ,p_line_definition_owner_code => l_line_definition_owner_code
96729       ,p_line_definition_code       => l_line_definition_code
96730       ,p_accounting_line_code       => l_component_code
96731       ,p_accounting_line_type_code  => l_component_type_code
96732       ,p_accounting_line_appl_id    => l_component_appl_id
96733       ,p_amb_context_code           => l_amb_context_code
96734       ,p_entity_code                => l_entity_code
96735       ,p_event_class_code           => l_event_class_code);
96736    --
96737    -- set accounting class
96738    --
96739    xla_ae_lines_pkg.SetAcctClass(
96740            p_accounting_class_code  => 'ASSET'
96741          , p_ae_header_id           => l_ae_header_id
96742          );
96743 
96744    --
96745    -- set rounding class
96746    --
96747    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
96748                       'ASSET';
96749 
96750    --
96751    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
96752    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
96753    --
96754    -- bulk performance
96755    --
96756    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
96757 
96758    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
96759       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
96760 
96761    -- 4955764
96762    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
96763       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
96764 
96765    -- 4458381 Public Sector Enh
96766    
96767    --
96768    -- set accounting attributes for the line type
96769    --
96770    l_entered_amt_idx := 4;
96771    l_accted_amt_idx  := 6;
96772    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
96773    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
96774    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
96775    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
96776    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
96777    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
96778    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
96779    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
96780    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
96781    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
96782    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
96783    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
96784    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
96785 
96786    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
96787    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
96788 
96789    ---------------------------------------------------------------------------------------------------------------
96790    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
96791    ---------------------------------------------------------------------------------------------------------------
96792    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
96793 
96797    IF xla_accounting_cache_pkg.GetValueChar
96794    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
96795    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
96796 
96798          (p_source_code         => 'LEDGER_CATEGORY_CODE'
96799          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
96800    AND l_bflow_method_code = 'PRIOR_ENTRY'
96801 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
96802    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
96803          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
96804        )
96805    THEN
96806          xla_ae_lines_pkg.BflowUpgEntry
96807            (p_business_method_code    => l_bflow_method_code
96808            ,p_business_class_code     => l_bflow_class_code
96809            ,p_balance_type            => l_balance_type_code);
96810    ELSE
96811       NULL;
96812 -- No business flow processing for business flow method of NONE.
96813    END IF;
96814 
96815    --
96816    -- call analytical criteria
96817    --
96818    
96819    --
96820    -- call description
96821    --
96822    
96823 xla_ae_lines_pkg.SetLineDescription(
96824    p_ae_header_id => l_ae_header_id
96825   ,p_description  => Description_67 (
96826      p_application_id         => p_application_id
96827    , p_ae_header_id           => l_ae_header_id 
96828 , p_source_1 => p_source_1
96829    )
96830 );
96831 
96832 
96833    --
96834    -- call ADRs
96835    -- Bug 4922099
96836    --
96837    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
96838         (NVL(l_actual_upg_option, 'N') = 'O') OR
96839         (NVL(l_enc_upg_option, 'N') = 'O')
96840       )
96841    THEN
96842    NULL;
96843    --
96844    --
96845    
96846   l_ccid := AcctDerRule_174(
96847            p_application_id           => p_application_id
96848          , p_ae_header_id             => l_ae_header_id 
96849 , p_source_3 => p_source_3
96850 , p_source_17 => p_source_17
96851 , p_source_30 => p_source_30
96852          , x_transaction_coa_id       => l_adr_transaction_coa_id
96853          , x_accounting_coa_id        => l_adr_accounting_coa_id
96854          , x_value_type_code          => l_adr_value_type_code
96855          , p_side                     => 'NA'
96856    );
96857 
96858    xla_ae_lines_pkg.set_ccid(
96859     p_code_combination_id          => l_ccid
96860   , p_value_type_code              => l_adr_value_type_code
96861   , p_transaction_coa_id           => l_adr_transaction_coa_id
96862   , p_accounting_coa_id            => l_adr_accounting_coa_id
96863   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
96864   , p_adr_type_code                => 'S'
96865   , p_component_type               => l_component_type
96866   , p_component_code               => l_component_code
96867   , p_component_type_code          => l_component_type_code
96868   , p_component_appl_id            => l_component_appl_id
96869   , p_amb_context_code             => l_amb_context_code
96870   , p_side                         => 'NA'
96871   );
96872 
96873 
96874    l_segment := AcctDerRule_149(
96875            p_application_id           => p_application_id
96876          , p_ae_header_id             => l_ae_header_id 
96877 , p_source_3 => p_source_3
96878 , p_source_10 => p_source_10
96879          , x_transaction_coa_id       => l_adr_transaction_coa_id
96880          , x_accounting_coa_id        => l_adr_accounting_coa_id
96881          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
96882          , x_flex_value_set_id        => l_adr_flex_value_set_id
96883          , x_value_type_code          => l_adr_value_type_code
96884          , x_value_combination_id     => l_adr_value_combination_id
96885          , x_value_segment_code       => l_adr_value_segment_code
96886          , p_side                     => 'NA'
96887          , p_override_seg_flag        => 'Y'
96888    );
96889 
96890    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
96891 
96892       xla_ae_lines_pkg.set_segment(
96893           p_to_segment_code         => 'GL_ACCOUNT'
96894         , p_segment_value           => l_segment
96895         , p_from_segment_code       => l_adr_value_segment_code
96896         , p_from_combination_id     => l_adr_value_combination_id
96897         , p_value_type_code         => l_adr_value_type_code
96898         , p_transaction_coa_id      => l_adr_transaction_coa_id
96899         , p_accounting_coa_id       => l_adr_accounting_coa_id
96900         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
96901         , p_flex_value_set_id       => l_adr_flex_value_set_id
96902         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
96903         , p_adr_type_code           => 'S'
96904         , p_component_type          => l_component_type
96905         , p_component_code          => l_component_code
96906         , p_component_type_code     => l_component_type_code
96907         , p_component_appl_id       => l_component_appl_id
96908         , p_amb_context_code        => l_amb_context_code
96909         , p_entity_code             => 'TRANSACTIONS'
96910         , p_event_class_code        => 'CATEGORY_RECLASS'
96911         , p_side                    => 'NA'
96912         );
96913 
96914   END IF;
96915 
96916    l_segment := AcctDerRule_168(
96917            p_application_id           => p_application_id
96918          , p_ae_header_id             => l_ae_header_id 
96919 , p_source_3 => p_source_3
96920 , p_source_29 => p_source_29
96921          , x_transaction_coa_id       => l_adr_transaction_coa_id
96922          , x_accounting_coa_id        => l_adr_accounting_coa_id
96923          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
96927          , x_value_segment_code       => l_adr_value_segment_code
96924          , x_flex_value_set_id        => l_adr_flex_value_set_id
96925          , x_value_type_code          => l_adr_value_type_code
96926          , x_value_combination_id     => l_adr_value_combination_id
96928          , p_side                     => 'NA'
96929          , p_override_seg_flag        => 'Y'
96930    );
96931 
96932    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
96933 
96934       xla_ae_lines_pkg.set_segment(
96935           p_to_segment_code         => 'GL_BALANCING'
96936         , p_segment_value           => l_segment
96937         , p_from_segment_code       => l_adr_value_segment_code
96938         , p_from_combination_id     => l_adr_value_combination_id
96939         , p_value_type_code         => l_adr_value_type_code
96940         , p_transaction_coa_id      => l_adr_transaction_coa_id
96941         , p_accounting_coa_id       => l_adr_accounting_coa_id
96942         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
96943         , p_flex_value_set_id       => l_adr_flex_value_set_id
96944         , p_adr_code                => 'FA_EXPENSE_ACCT'
96945         , p_adr_type_code           => 'S'
96946         , p_component_type          => l_component_type
96947         , p_component_code          => l_component_code
96948         , p_component_type_code     => l_component_type_code
96949         , p_component_appl_id       => l_component_appl_id
96950         , p_amb_context_code        => l_amb_context_code
96951         , p_entity_code             => 'TRANSACTIONS'
96952         , p_event_class_code        => 'CATEGORY_RECLASS'
96953         , p_side                    => 'NA'
96954         );
96955 
96956   END IF;
96957 
96958    --
96959    --
96960    END IF;
96961    --
96962    -- Bug 4922099
96963    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
96964           (NVL(l_enc_upg_option, 'N') = 'O')
96965         ) AND
96966         (l_bflow_method_code = 'PRIOR_ENTRY')
96967       )
96968    THEN
96969       IF
96970       --
96971       1 = 2
96972       --
96973       THEN
96974       xla_accounting_err_pkg.build_message
96975                                     (p_appli_s_name            => 'XLA'
96976                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
96977                                     ,p_token_1                 => 'LINE_NUMBER'
96978                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
96979                                     ,p_token_2                 => 'LINE_TYPE_NAME'
96980                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
96981                                                                              l_component_type
96982                                                                             ,l_component_code
96983                                                                             ,l_component_type_code
96984                                                                             ,l_component_appl_id
96985                                                                             ,l_amb_context_code
96986                                                                             ,l_entity_code
96987                                                                             ,l_event_class_code
96988                                                                            )
96989                                     ,p_token_3                 => 'OWNER'
96990                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
96991                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
96992                                                                           ,p_lookup_code    => l_component_type_code
96993                                                                          )
96994                                     ,p_token_4                 => 'PRODUCT_NAME'
96995                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
96996                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
96997                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
96998                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
96999                                     ,p_ae_header_id            =>  NULL
97000                                        );
97001 
97002         IF (C_LEVEL_ERROR>= g_log_level) THEN
97003                  trace
97004                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
97005                       ,p_level    => C_LEVEL_ERROR
97006                       ,p_module   => l_log_module);
97007         END IF;
97008       END IF;
97009    END IF;
97010    --
97011    --
97012    ------------------------------------------------------------------------------------------------
97013    -- 4219869 Business Flow
97014    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
97015    -- Prior Entry.  Currently, the following code is always generated.
97016    ------------------------------------------------------------------------------------------------
97017    XLA_AE_LINES_PKG.ValidateCurrentLine;
97018 
97019    ------------------------------------------------------------------------------------
97020    -- 4219869 Business Flow
97021    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
97022    ------------------------------------------------------------------------------------
97023    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
97024 
97025    ----------------------------------------------------------------------------------
97026    -- 4219869 Business Flow
97027    -- Update journal entry status -- Need to generate this within IF <condition>
97031          ,p_balance_type_code => l_balance_type_code
97028    ----------------------------------------------------------------------------------
97029    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
97030          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
97032          );
97033 
97034    -------------------------------------------------------------------------------------------
97035    -- 4262811 - Generate the Accrual Reversal lines
97036    -------------------------------------------------------------------------------------------
97037    BEGIN
97038       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
97039                               (g_array_event(p_event_id).array_value_num('header_index'));
97040       IF l_acc_rev_flag IS NULL THEN
97041          l_acc_rev_flag := 'N';
97042       END IF;
97043    EXCEPTION
97044       WHEN OTHERS THEN
97045          l_acc_rev_flag := 'N';
97046    END;
97047    --
97048    IF (l_acc_rev_flag = 'Y') THEN
97049 
97050        -- 4645092  ------------------------------------------------------------------------------
97051        -- To allow MPA report to determine if it should generate report process
97052        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
97053        ------------------------------------------------------------------------------------------
97054 
97055        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
97056        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
97057    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
97058    -- call ADRs
97059    -- Bug 4922099
97060    --
97061    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
97062         (NVL(l_actual_upg_option, 'N') = 'O') OR
97063         (NVL(l_enc_upg_option, 'N') = 'O')
97064       )
97065    THEN
97066    NULL;
97067    --
97068    --
97069    
97070   l_ccid := AcctDerRule_174(
97071            p_application_id           => p_application_id
97072          , p_ae_header_id             => l_ae_header_id 
97073 , p_source_3 => p_source_3
97074 , p_source_17 => p_source_17
97075 , p_source_30 => p_source_30
97076          , x_transaction_coa_id       => l_adr_transaction_coa_id
97077          , x_accounting_coa_id        => l_adr_accounting_coa_id
97078          , x_value_type_code          => l_adr_value_type_code
97079          , p_side                     => 'NA'
97080    );
97081 
97082    xla_ae_lines_pkg.set_ccid(
97083     p_code_combination_id          => l_ccid
97084   , p_value_type_code              => l_adr_value_type_code
97085   , p_transaction_coa_id           => l_adr_transaction_coa_id
97086   , p_accounting_coa_id            => l_adr_accounting_coa_id
97087   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
97088   , p_adr_type_code                => 'S'
97089   , p_component_type               => l_component_type
97090   , p_component_code               => l_component_code
97091   , p_component_type_code          => l_component_type_code
97092   , p_component_appl_id            => l_component_appl_id
97093   , p_amb_context_code             => l_amb_context_code
97094   , p_side                         => 'NA'
97095   );
97096 
97097 
97098    l_segment := AcctDerRule_149(
97099            p_application_id           => p_application_id
97100          , p_ae_header_id             => l_ae_header_id 
97101 , p_source_3 => p_source_3
97102 , p_source_10 => p_source_10
97103          , x_transaction_coa_id       => l_adr_transaction_coa_id
97104          , x_accounting_coa_id        => l_adr_accounting_coa_id
97105          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
97106          , x_flex_value_set_id        => l_adr_flex_value_set_id
97107          , x_value_type_code          => l_adr_value_type_code
97108          , x_value_combination_id     => l_adr_value_combination_id
97109          , x_value_segment_code       => l_adr_value_segment_code
97110          , p_side                     => 'NA'
97111          , p_override_seg_flag        => 'Y'
97112    );
97113 
97114    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
97115 
97116       xla_ae_lines_pkg.set_segment(
97117           p_to_segment_code         => 'GL_ACCOUNT'
97118         , p_segment_value           => l_segment
97119         , p_from_segment_code       => l_adr_value_segment_code
97120         , p_from_combination_id     => l_adr_value_combination_id
97121         , p_value_type_code         => l_adr_value_type_code
97122         , p_transaction_coa_id      => l_adr_transaction_coa_id
97123         , p_accounting_coa_id       => l_adr_accounting_coa_id
97124         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
97125         , p_flex_value_set_id       => l_adr_flex_value_set_id
97126         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
97127         , p_adr_type_code           => 'S'
97128         , p_component_type          => l_component_type
97129         , p_component_code          => l_component_code
97130         , p_component_type_code     => l_component_type_code
97131         , p_component_appl_id       => l_component_appl_id
97132         , p_amb_context_code        => l_amb_context_code
97133         , p_entity_code             => 'TRANSACTIONS'
97134         , p_event_class_code        => 'CATEGORY_RECLASS'
97135         , p_side                    => 'NA'
97136         );
97137 
97138   END IF;
97139 
97140    l_segment := AcctDerRule_168(
97141            p_application_id           => p_application_id
97142          , p_ae_header_id             => l_ae_header_id 
97143 , p_source_3 => p_source_3
97144 , p_source_29 => p_source_29
97145          , x_transaction_coa_id       => l_adr_transaction_coa_id
97146          , x_accounting_coa_id        => l_adr_accounting_coa_id
97147          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
97148          , x_flex_value_set_id        => l_adr_flex_value_set_id
97152          , p_side                     => 'NA'
97149          , x_value_type_code          => l_adr_value_type_code
97150          , x_value_combination_id     => l_adr_value_combination_id
97151          , x_value_segment_code       => l_adr_value_segment_code
97153          , p_override_seg_flag        => 'Y'
97154    );
97155 
97156    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
97157 
97158       xla_ae_lines_pkg.set_segment(
97159           p_to_segment_code         => 'GL_BALANCING'
97160         , p_segment_value           => l_segment
97161         , p_from_segment_code       => l_adr_value_segment_code
97162         , p_from_combination_id     => l_adr_value_combination_id
97163         , p_value_type_code         => l_adr_value_type_code
97164         , p_transaction_coa_id      => l_adr_transaction_coa_id
97165         , p_accounting_coa_id       => l_adr_accounting_coa_id
97166         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
97167         , p_flex_value_set_id       => l_adr_flex_value_set_id
97168         , p_adr_code                => 'FA_EXPENSE_ACCT'
97169         , p_adr_type_code           => 'S'
97170         , p_component_type          => l_component_type
97171         , p_component_code          => l_component_code
97172         , p_component_type_code     => l_component_type_code
97173         , p_component_appl_id       => l_component_appl_id
97174         , p_amb_context_code        => l_amb_context_code
97175         , p_entity_code             => 'TRANSACTIONS'
97176         , p_event_class_code        => 'CATEGORY_RECLASS'
97177         , p_side                    => 'NA'
97178         );
97179 
97180   END IF;
97181 
97182    --
97183    --
97184    END IF;
97185 
97186        --
97187        -- Update the line information that should be overwritten
97188        --
97189        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
97190                                          p_header_num   => 1);
97191        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
97192 
97193        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
97194 
97195        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
97196           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
97197        END IF;
97198 
97199       --
97200       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
97201       --
97202       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
97203           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
97204       ELSE
97205           ---------------------------------------------------------------------------------------------------
97206           -- 4262811a Switch Sign
97207           ---------------------------------------------------------------------------------------------------
97208           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
97209           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
97210                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
97211           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
97212                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
97213           -- 5132302
97214           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
97215                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
97216 
97217       END IF;
97218 
97219       -- 4955764
97220       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
97221       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
97222 
97223 
97224       XLA_AE_LINES_PKG.ValidateCurrentLine;
97225       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
97226 
97227       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
97228                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
97229                ,p_balance_type_code => l_balance_type_code);
97230 
97231    END IF;
97232 
97233    -----------------------------------------------------------------------------------------
97234    -- 4262811 Multiperiod Accounting
97235    -----------------------------------------------------------------------------------------
97236      -- No MPA option is assigned.
97237 
97238 
97239 END IF;
97240 END IF;
97241 --
97242 
97243 --
97244 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
97245    trace
97246       (p_msg      => 'END of AcctLineType_289'
97247       ,p_level    => C_LEVEL_PROCEDURE
97248       ,p_module   => l_log_module);
97249 END IF;
97250 --
97251 EXCEPTION
97252   WHEN xla_exceptions_pkg.application_exception THEN
97253       RAISE;
97254   WHEN OTHERS THEN
97255        xla_exceptions_pkg.raise_message
97256            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_289');
97257 END AcctLineType_289;
97258 --
97259 
97260 ---------------------------------------
97261 --
97262 -- PRIVATE FUNCTION
97263 --         AcctLineType_290
97264 --
97265 ---------------------------------------
97266 PROCEDURE AcctLineType_290 (
97267   p_application_id        IN NUMBER
97268  ,p_event_id              IN NUMBER
97269  ,p_calculate_acctd_flag  IN VARCHAR2
97270  ,p_calculate_g_l_flag    IN VARCHAR2
97271  ,p_actual_flag           IN OUT VARCHAR2
97272  ,p_balance_type_code     OUT VARCHAR2
97273  ,p_gain_or_loss_ref      OUT VARCHAR2
97274  
97275 --Period Close Date
97279 --Revaluation Reserve Account
97276  , p_source_1            IN DATE
97277 --Generated Code Combination Identifier
97278  , p_source_3            IN NUMBER
97280  , p_source_11            IN VARCHAR2
97281 --Generated Offset Code Combination Identifier
97282  , p_source_17            IN NUMBER
97283 --Expense Account Code Combination Identifier
97284  , p_source_29            IN NUMBER
97285 --Default Code Combination Identifier
97286  , p_source_30            IN NUMBER
97287 --Adjustment Type
97288  , p_source_35            IN VARCHAR2
97289 --Transaction Header Identifier
97290  , p_source_36            IN NUMBER
97291 --Adjustment Line Identifier
97292  , p_source_37            IN NUMBER
97293 --Distribution Type Code
97294  , p_source_38            IN VARCHAR2
97295 --Entered Amount
97296  , p_source_39            IN NUMBER
97297 --Currency Code
97298  , p_source_40            IN VARCHAR2
97299 --Source Destination Code
97300  , p_source_42            IN VARCHAR2
97301 )
97302 IS
97303 
97304 l_component_type              VARCHAR2(80);
97305 l_component_code              VARCHAR2(30);
97306 l_component_type_code         VARCHAR2(1);
97307 l_component_appl_id           INTEGER;
97308 l_amb_context_code            VARCHAR2(30);
97309 l_entity_code                 VARCHAR2(30);
97310 l_event_class_code            VARCHAR2(30);
97311 l_ae_header_id                NUMBER;
97312 l_event_type_code             VARCHAR2(30);
97313 l_line_definition_code        VARCHAR2(30);
97314 l_line_definition_owner_code  VARCHAR2(1);
97315 --
97316 -- adr variables
97317 l_segment                     VARCHAR2(30);
97318 l_ccid                        NUMBER;
97319 l_adr_transaction_coa_id      NUMBER;
97320 l_adr_accounting_coa_id       NUMBER;
97321 l_adr_flexfield_segment_code  VARCHAR2(30);
97322 l_adr_flex_value_set_id       NUMBER;
97323 l_adr_value_type_code         VARCHAR2(30);
97324 l_adr_value_combination_id    NUMBER;
97325 l_adr_value_segment_code      VARCHAR2(30);
97326 
97327 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
97328 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
97329 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
97330 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
97331 
97332 -- 4262811 Variables ------------------------------------------------------------------------------------------
97333 l_entered_amt_idx             NUMBER;
97334 l_accted_amt_idx              NUMBER;
97335 l_acc_rev_flag                VARCHAR2(1);
97336 l_accrual_line_num            NUMBER;
97337 l_tmp_amt                     NUMBER;
97338 l_acc_rev_natural_side_code   VARCHAR2(1);
97339 
97340 l_num_entries                 NUMBER;
97341 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
97342 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
97343 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
97344 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
97345 l_recog_line_1                NUMBER;
97346 l_recog_line_2                NUMBER;
97347 
97348 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
97349 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
97350 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
97351 
97352 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
97353 
97354 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
97355 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
97356 
97357 ---------------------------------------------------------------------------------------------------------------
97358 
97359 
97360 --
97361 -- bulk performance
97362 --
97363 l_balance_type_code           VARCHAR2(1);
97364 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
97365 l_log_module                  VARCHAR2(240);
97366 
97367 --
97368 -- Upgrade strategy
97369 --
97370 l_actual_upg_option           VARCHAR2(1);
97371 l_enc_upg_option           VARCHAR2(1);
97372 
97373 --
97374 BEGIN
97375 --
97376 IF g_log_enabled THEN
97377       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_290';
97378 END IF;
97379 --
97380 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
97381 
97382       trace
97383          (p_msg      => 'BEGIN of AcctLineType_290'
97384          ,p_level    => C_LEVEL_PROCEDURE
97385          ,p_module   => l_log_module);
97386 
97387 END IF;
97388 --
97389 l_component_type             := 'AMB_JLT';
97390 l_component_code             := 'FA_RECLASS_SOURCE_REVAL_RESERV';
97391 l_component_type_code        := 'S';
97392 l_component_appl_id          :=  140;
97393 l_amb_context_code           := 'DEFAULT';
97394 l_entity_code                := 'TRANSACTIONS';
97395 l_event_class_code           := 'CATEGORY_RECLASS';
97396 l_event_type_code            := 'CATEGORY_RECLASS_ALL';
97397 l_line_definition_owner_code := 'S';
97398 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CATEGO4';
97399 --
97400 l_balance_type_code          := 'A';
97401 l_segment                     := NULL;
97402 l_ccid                        := NULL;
97403 l_adr_transaction_coa_id      := NULL;
97404 l_adr_accounting_coa_id       := NULL;
97405 l_adr_flexfield_segment_code  := NULL;
97406 l_adr_flex_value_set_id       := NULL;
97407 l_adr_value_type_code         := NULL;
97408 l_adr_value_combination_id    := NULL;
97409 l_adr_value_segment_code      := NULL;
97410 
97411 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
97412 l_bflow_class_code           := '';    -- 4219869 Business Flow
97413 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
97414 l_budgetary_control_flag     := 'N';
97418 l_entered_amt_idx            := NULL;          -- 4262811
97415 
97416 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
97417 l_bflow_applied_to_amt       := NULL; -- 5132302
97419 l_accted_amt_idx             := NULL;          -- 4262811
97420 l_acc_rev_flag               := NULL;          -- 4262811
97421 l_accrual_line_num           := NULL;          -- 4262811
97422 l_tmp_amt                    := NULL;          -- 4262811
97423 --
97424  
97425 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
97426     l_balance_type_code <> 'B' THEN
97427 IF NVL(p_source_35,'
97428 ') =  'REVAL RESERVE' AND 
97429 NVL(p_source_42,'
97430 ') =  'SOURCE'
97431  THEN 
97432 
97433    --
97434    XLA_AE_LINES_PKG.SetNewLine;
97435 
97436    p_balance_type_code          := l_balance_type_code;
97437    -- set the flag so later we will know whether the gain loss line needs to be created
97438    
97439    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
97440      p_actual_flag :='A';
97441    END IF;
97442 
97443    --
97444    -- bulk performance
97445    --
97446    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
97447                                       p_header_num   => 0); -- 4262811
97448    --
97449    -- set accounting line options
97450    --
97451    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
97452            p_natural_side_code          => 'D'
97453          , p_gain_or_loss_flag          => 'N'
97454          , p_gl_transfer_mode_code      => 'S'
97455          , p_acct_entry_type_code       => 'A'
97456          , p_switch_side_flag           => 'Y'
97457          , p_merge_duplicate_code       => 'N'
97458          );
97459    --
97460    l_acc_rev_natural_side_code := 'C';  -- 4262811
97461    -- 
97462    --
97463    -- set accounting line type info
97464    --
97465    xla_ae_lines_pkg.SetAcctLineType
97466       (p_component_type             => l_component_type
97467       ,p_event_type_code            => l_event_type_code
97468       ,p_line_definition_owner_code => l_line_definition_owner_code
97469       ,p_line_definition_code       => l_line_definition_code
97470       ,p_accounting_line_code       => l_component_code
97471       ,p_accounting_line_type_code  => l_component_type_code
97472       ,p_accounting_line_appl_id    => l_component_appl_id
97473       ,p_amb_context_code           => l_amb_context_code
97474       ,p_entity_code                => l_entity_code
97475       ,p_event_class_code           => l_event_class_code);
97476    --
97477    -- set accounting class
97478    --
97479    xla_ae_lines_pkg.SetAcctClass(
97480            p_accounting_class_code  => 'ASSET'
97481          , p_ae_header_id           => l_ae_header_id
97482          );
97483 
97484    --
97485    -- set rounding class
97486    --
97487    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
97488                       'ASSET';
97489 
97490    --
97491    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
97492    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
97493    --
97494    -- bulk performance
97495    --
97496    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
97497 
97498    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
97499       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
97500 
97501    -- 4955764
97502    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
97503       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
97504 
97505    -- 4458381 Public Sector Enh
97506    
97507    --
97508    -- set accounting attributes for the line type
97509    --
97510    l_entered_amt_idx := 4;
97511    l_accted_amt_idx  := 6;
97512    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
97513    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
97514    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
97515    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
97516    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
97517    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
97518    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
97519    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
97520    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
97521    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
97522    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
97523    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
97524    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
97525 
97526    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
97527    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
97528 
97529    ---------------------------------------------------------------------------------------------------------------
97530    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
97531    ---------------------------------------------------------------------------------------------------------------
97532    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
97533 
97534    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
97535    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
97536 
97537    IF xla_accounting_cache_pkg.GetValueChar
97538          (p_source_code         => 'LEDGER_CATEGORY_CODE'
97542    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
97539          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
97540    AND l_bflow_method_code = 'PRIOR_ENTRY'
97541 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
97543          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
97544        )
97545    THEN
97546          xla_ae_lines_pkg.BflowUpgEntry
97547            (p_business_method_code    => l_bflow_method_code
97548            ,p_business_class_code     => l_bflow_class_code
97549            ,p_balance_type            => l_balance_type_code);
97550    ELSE
97551       NULL;
97552 -- No business flow processing for business flow method of NONE.
97553    END IF;
97554 
97555    --
97556    -- call analytical criteria
97557    --
97558    
97559    --
97560    -- call description
97561    --
97562    
97563 xla_ae_lines_pkg.SetLineDescription(
97564    p_ae_header_id => l_ae_header_id
97565   ,p_description  => Description_68 (
97566      p_application_id         => p_application_id
97567    , p_ae_header_id           => l_ae_header_id 
97568 , p_source_1 => p_source_1
97569    )
97570 );
97571 
97572 
97573    --
97574    -- call ADRs
97575    -- Bug 4922099
97576    --
97577    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
97578         (NVL(l_actual_upg_option, 'N') = 'O') OR
97579         (NVL(l_enc_upg_option, 'N') = 'O')
97580       )
97581    THEN
97582    NULL;
97583    --
97584    --
97585    
97586   l_ccid := AcctDerRule_174(
97587            p_application_id           => p_application_id
97588          , p_ae_header_id             => l_ae_header_id 
97589 , p_source_3 => p_source_3
97590 , p_source_17 => p_source_17
97591 , p_source_30 => p_source_30
97592          , x_transaction_coa_id       => l_adr_transaction_coa_id
97593          , x_accounting_coa_id        => l_adr_accounting_coa_id
97594          , x_value_type_code          => l_adr_value_type_code
97595          , p_side                     => 'NA'
97596    );
97597 
97598    xla_ae_lines_pkg.set_ccid(
97599     p_code_combination_id          => l_ccid
97600   , p_value_type_code              => l_adr_value_type_code
97601   , p_transaction_coa_id           => l_adr_transaction_coa_id
97602   , p_accounting_coa_id            => l_adr_accounting_coa_id
97603   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
97604   , p_adr_type_code                => 'S'
97605   , p_component_type               => l_component_type
97606   , p_component_code               => l_component_code
97607   , p_component_type_code          => l_component_type_code
97608   , p_component_appl_id            => l_component_appl_id
97609   , p_amb_context_code             => l_amb_context_code
97610   , p_side                         => 'NA'
97611   );
97612 
97613 
97614    l_segment := AcctDerRule_150(
97615            p_application_id           => p_application_id
97616          , p_ae_header_id             => l_ae_header_id 
97617 , p_source_3 => p_source_3
97618 , p_source_11 => p_source_11
97619          , x_transaction_coa_id       => l_adr_transaction_coa_id
97620          , x_accounting_coa_id        => l_adr_accounting_coa_id
97621          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
97622          , x_flex_value_set_id        => l_adr_flex_value_set_id
97623          , x_value_type_code          => l_adr_value_type_code
97624          , x_value_combination_id     => l_adr_value_combination_id
97625          , x_value_segment_code       => l_adr_value_segment_code
97626          , p_side                     => 'NA'
97627          , p_override_seg_flag        => 'Y'
97628    );
97629 
97630    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
97631 
97632       xla_ae_lines_pkg.set_segment(
97633           p_to_segment_code         => 'GL_ACCOUNT'
97634         , p_segment_value           => l_segment
97635         , p_from_segment_code       => l_adr_value_segment_code
97636         , p_from_combination_id     => l_adr_value_combination_id
97637         , p_value_type_code         => l_adr_value_type_code
97638         , p_transaction_coa_id      => l_adr_transaction_coa_id
97639         , p_accounting_coa_id       => l_adr_accounting_coa_id
97640         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
97641         , p_flex_value_set_id       => l_adr_flex_value_set_id
97642         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
97643         , p_adr_type_code           => 'S'
97644         , p_component_type          => l_component_type
97645         , p_component_code          => l_component_code
97646         , p_component_type_code     => l_component_type_code
97647         , p_component_appl_id       => l_component_appl_id
97648         , p_amb_context_code        => l_amb_context_code
97649         , p_entity_code             => 'TRANSACTIONS'
97650         , p_event_class_code        => 'CATEGORY_RECLASS'
97651         , p_side                    => 'NA'
97652         );
97653 
97654   END IF;
97655 
97656    l_segment := AcctDerRule_168(
97657            p_application_id           => p_application_id
97658          , p_ae_header_id             => l_ae_header_id 
97659 , p_source_3 => p_source_3
97660 , p_source_29 => p_source_29
97661          , x_transaction_coa_id       => l_adr_transaction_coa_id
97662          , x_accounting_coa_id        => l_adr_accounting_coa_id
97663          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
97664          , x_flex_value_set_id        => l_adr_flex_value_set_id
97665          , x_value_type_code          => l_adr_value_type_code
97666          , x_value_combination_id     => l_adr_value_combination_id
97667          , x_value_segment_code       => l_adr_value_segment_code
97668          , p_side                     => 'NA'
97669          , p_override_seg_flag        => 'Y'
97670    );
97674       xla_ae_lines_pkg.set_segment(
97671 
97672    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
97673 
97675           p_to_segment_code         => 'GL_BALANCING'
97676         , p_segment_value           => l_segment
97677         , p_from_segment_code       => l_adr_value_segment_code
97678         , p_from_combination_id     => l_adr_value_combination_id
97679         , p_value_type_code         => l_adr_value_type_code
97680         , p_transaction_coa_id      => l_adr_transaction_coa_id
97681         , p_accounting_coa_id       => l_adr_accounting_coa_id
97682         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
97683         , p_flex_value_set_id       => l_adr_flex_value_set_id
97684         , p_adr_code                => 'FA_EXPENSE_ACCT'
97685         , p_adr_type_code           => 'S'
97686         , p_component_type          => l_component_type
97687         , p_component_code          => l_component_code
97688         , p_component_type_code     => l_component_type_code
97689         , p_component_appl_id       => l_component_appl_id
97690         , p_amb_context_code        => l_amb_context_code
97691         , p_entity_code             => 'TRANSACTIONS'
97692         , p_event_class_code        => 'CATEGORY_RECLASS'
97693         , p_side                    => 'NA'
97694         );
97695 
97696   END IF;
97697 
97698    --
97699    --
97700    END IF;
97701    --
97702    -- Bug 4922099
97703    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
97704           (NVL(l_enc_upg_option, 'N') = 'O')
97705         ) AND
97706         (l_bflow_method_code = 'PRIOR_ENTRY')
97707       )
97708    THEN
97709       IF
97710       --
97711       1 = 2
97712       --
97713       THEN
97714       xla_accounting_err_pkg.build_message
97715                                     (p_appli_s_name            => 'XLA'
97716                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
97717                                     ,p_token_1                 => 'LINE_NUMBER'
97718                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
97719                                     ,p_token_2                 => 'LINE_TYPE_NAME'
97720                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
97721                                                                              l_component_type
97722                                                                             ,l_component_code
97723                                                                             ,l_component_type_code
97724                                                                             ,l_component_appl_id
97725                                                                             ,l_amb_context_code
97726                                                                             ,l_entity_code
97727                                                                             ,l_event_class_code
97728                                                                            )
97729                                     ,p_token_3                 => 'OWNER'
97730                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
97731                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
97732                                                                           ,p_lookup_code    => l_component_type_code
97733                                                                          )
97734                                     ,p_token_4                 => 'PRODUCT_NAME'
97735                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
97736                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
97737                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
97738                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
97739                                     ,p_ae_header_id            =>  NULL
97740                                        );
97741 
97742         IF (C_LEVEL_ERROR>= g_log_level) THEN
97743                  trace
97744                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
97745                       ,p_level    => C_LEVEL_ERROR
97746                       ,p_module   => l_log_module);
97747         END IF;
97748       END IF;
97749    END IF;
97750    --
97751    --
97752    ------------------------------------------------------------------------------------------------
97753    -- 4219869 Business Flow
97754    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
97755    -- Prior Entry.  Currently, the following code is always generated.
97756    ------------------------------------------------------------------------------------------------
97757    XLA_AE_LINES_PKG.ValidateCurrentLine;
97758 
97759    ------------------------------------------------------------------------------------
97760    -- 4219869 Business Flow
97761    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
97762    ------------------------------------------------------------------------------------
97763    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
97764 
97765    ----------------------------------------------------------------------------------
97766    -- 4219869 Business Flow
97767    -- Update journal entry status -- Need to generate this within IF <condition>
97768    ----------------------------------------------------------------------------------
97769    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
97770          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
97771          ,p_balance_type_code => l_balance_type_code
97772          );
97773 
97774    -------------------------------------------------------------------------------------------
97778       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
97775    -- 4262811 - Generate the Accrual Reversal lines
97776    -------------------------------------------------------------------------------------------
97777    BEGIN
97779                               (g_array_event(p_event_id).array_value_num('header_index'));
97780       IF l_acc_rev_flag IS NULL THEN
97781          l_acc_rev_flag := 'N';
97782       END IF;
97783    EXCEPTION
97784       WHEN OTHERS THEN
97785          l_acc_rev_flag := 'N';
97786    END;
97787    --
97788    IF (l_acc_rev_flag = 'Y') THEN
97789 
97790        -- 4645092  ------------------------------------------------------------------------------
97791        -- To allow MPA report to determine if it should generate report process
97792        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
97793        ------------------------------------------------------------------------------------------
97794 
97795        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
97796        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
97797    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
97798    -- call ADRs
97799    -- Bug 4922099
97800    --
97801    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
97802         (NVL(l_actual_upg_option, 'N') = 'O') OR
97803         (NVL(l_enc_upg_option, 'N') = 'O')
97804       )
97805    THEN
97806    NULL;
97807    --
97808    --
97809    
97810   l_ccid := AcctDerRule_174(
97811            p_application_id           => p_application_id
97812          , p_ae_header_id             => l_ae_header_id 
97813 , p_source_3 => p_source_3
97814 , p_source_17 => p_source_17
97815 , p_source_30 => p_source_30
97816          , x_transaction_coa_id       => l_adr_transaction_coa_id
97817          , x_accounting_coa_id        => l_adr_accounting_coa_id
97818          , x_value_type_code          => l_adr_value_type_code
97819          , p_side                     => 'NA'
97820    );
97821 
97822    xla_ae_lines_pkg.set_ccid(
97823     p_code_combination_id          => l_ccid
97824   , p_value_type_code              => l_adr_value_type_code
97825   , p_transaction_coa_id           => l_adr_transaction_coa_id
97826   , p_accounting_coa_id            => l_adr_accounting_coa_id
97827   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
97828   , p_adr_type_code                => 'S'
97829   , p_component_type               => l_component_type
97830   , p_component_code               => l_component_code
97831   , p_component_type_code          => l_component_type_code
97832   , p_component_appl_id            => l_component_appl_id
97833   , p_amb_context_code             => l_amb_context_code
97834   , p_side                         => 'NA'
97835   );
97836 
97837 
97838    l_segment := AcctDerRule_150(
97839            p_application_id           => p_application_id
97840          , p_ae_header_id             => l_ae_header_id 
97841 , p_source_3 => p_source_3
97842 , p_source_11 => p_source_11
97843          , x_transaction_coa_id       => l_adr_transaction_coa_id
97844          , x_accounting_coa_id        => l_adr_accounting_coa_id
97845          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
97846          , x_flex_value_set_id        => l_adr_flex_value_set_id
97847          , x_value_type_code          => l_adr_value_type_code
97848          , x_value_combination_id     => l_adr_value_combination_id
97849          , x_value_segment_code       => l_adr_value_segment_code
97850          , p_side                     => 'NA'
97851          , p_override_seg_flag        => 'Y'
97852    );
97853 
97854    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
97855 
97856       xla_ae_lines_pkg.set_segment(
97857           p_to_segment_code         => 'GL_ACCOUNT'
97858         , p_segment_value           => l_segment
97859         , p_from_segment_code       => l_adr_value_segment_code
97863         , p_accounting_coa_id       => l_adr_accounting_coa_id
97860         , p_from_combination_id     => l_adr_value_combination_id
97861         , p_value_type_code         => l_adr_value_type_code
97862         , p_transaction_coa_id      => l_adr_transaction_coa_id
97864         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
97865         , p_flex_value_set_id       => l_adr_flex_value_set_id
97866         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
97867         , p_adr_type_code           => 'S'
97868         , p_component_type          => l_component_type
97869         , p_component_code          => l_component_code
97870         , p_component_type_code     => l_component_type_code
97871         , p_component_appl_id       => l_component_appl_id
97872         , p_amb_context_code        => l_amb_context_code
97873         , p_entity_code             => 'TRANSACTIONS'
97874         , p_event_class_code        => 'CATEGORY_RECLASS'
97875         , p_side                    => 'NA'
97876         );
97877 
97878   END IF;
97879 
97880    l_segment := AcctDerRule_168(
97881            p_application_id           => p_application_id
97882          , p_ae_header_id             => l_ae_header_id 
97883 , p_source_3 => p_source_3
97884 , p_source_29 => p_source_29
97885          , x_transaction_coa_id       => l_adr_transaction_coa_id
97886          , x_accounting_coa_id        => l_adr_accounting_coa_id
97887          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
97888          , x_flex_value_set_id        => l_adr_flex_value_set_id
97889          , x_value_type_code          => l_adr_value_type_code
97890          , x_value_combination_id     => l_adr_value_combination_id
97891          , x_value_segment_code       => l_adr_value_segment_code
97892          , p_side                     => 'NA'
97893          , p_override_seg_flag        => 'Y'
97894    );
97895 
97896    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
97897 
97898       xla_ae_lines_pkg.set_segment(
97899           p_to_segment_code         => 'GL_BALANCING'
97900         , p_segment_value           => l_segment
97901         , p_from_segment_code       => l_adr_value_segment_code
97902         , p_from_combination_id     => l_adr_value_combination_id
97903         , p_value_type_code         => l_adr_value_type_code
97904         , p_transaction_coa_id      => l_adr_transaction_coa_id
97905         , p_accounting_coa_id       => l_adr_accounting_coa_id
97906         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
97907         , p_flex_value_set_id       => l_adr_flex_value_set_id
97908         , p_adr_code                => 'FA_EXPENSE_ACCT'
97909         , p_adr_type_code           => 'S'
97910         , p_component_type          => l_component_type
97911         , p_component_code          => l_component_code
97912         , p_component_type_code     => l_component_type_code
97913         , p_component_appl_id       => l_component_appl_id
97914         , p_amb_context_code        => l_amb_context_code
97915         , p_entity_code             => 'TRANSACTIONS'
97916         , p_event_class_code        => 'CATEGORY_RECLASS'
97917         , p_side                    => 'NA'
97918         );
97919 
97920   END IF;
97921 
97922    --
97923    --
97924    END IF;
97925 
97926        --
97927        -- Update the line information that should be overwritten
97928        --
97929        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
97930                                          p_header_num   => 1);
97931        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
97932 
97933        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
97934 
97938 
97935        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
97936           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
97937        END IF;
97939       --
97940       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
97941       --
97942       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
97943           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
97944       ELSE
97945           ---------------------------------------------------------------------------------------------------
97946           -- 4262811a Switch Sign
97947           ---------------------------------------------------------------------------------------------------
97948           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
97949           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
97950                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
97951           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
97952                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
97953           -- 5132302
97954           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
97955                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
97956 
97957       END IF;
97958 
97959       -- 4955764
97960       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
97961       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
97962 
97963 
97964       XLA_AE_LINES_PKG.ValidateCurrentLine;
97965       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
97966 
97967       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
97968                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
97969                ,p_balance_type_code => l_balance_type_code);
97970 
97971    END IF;
97972 
97973    -----------------------------------------------------------------------------------------
97974    -- 4262811 Multiperiod Accounting
97975    -----------------------------------------------------------------------------------------
97976      -- No MPA option is assigned.
97977 
97978 
97979 END IF;
97980 END IF;
97981 --
97982 
97983 --
97984 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
97985    trace
97986       (p_msg      => 'END of AcctLineType_290'
97987       ,p_level    => C_LEVEL_PROCEDURE
97988       ,p_module   => l_log_module);
97989 END IF;
97990 --
97991 EXCEPTION
97992   WHEN xla_exceptions_pkg.application_exception THEN
97993       RAISE;
97994   WHEN OTHERS THEN
97995        xla_exceptions_pkg.raise_message
97996            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_290');
97997 END AcctLineType_290;
97998 --
97999 
98000 ---------------------------------------
98001 --
98002 -- PRIVATE FUNCTION
98003 --         AcctLineType_291
98004 --
98005 ---------------------------------------
98006 PROCEDURE AcctLineType_291 (
98007   p_application_id        IN NUMBER
98008  ,p_event_id              IN NUMBER
98009  ,p_calculate_acctd_flag  IN VARCHAR2
98010  ,p_calculate_g_l_flag    IN VARCHAR2
98011  ,p_actual_flag           IN OUT VARCHAR2
98012  ,p_balance_type_code     OUT VARCHAR2
98013  ,p_gain_or_loss_ref      OUT VARCHAR2
98014  
98015 --Period Close Date
98016  , p_source_1            IN DATE
98017 --Generated Code Combination Identifier
98018  , p_source_3            IN NUMBER
98019 --Intercompany Payables Account
98020  , p_source_19            IN VARCHAR2
98021 --Expense Account Code Combination Identifier
98022  , p_source_29            IN NUMBER
98023 --Default Code Combination Identifier
98024  , p_source_30            IN NUMBER
98025 --Adjustment Type
98026  , p_source_35            IN VARCHAR2
98027 --Transaction Header Identifier
98028  , p_source_36            IN NUMBER
98029 --Adjustment Line Identifier
98030  , p_source_37            IN NUMBER
98031 --Distribution Type Code
98032  , p_source_38            IN VARCHAR2
98033 --Entered Amount
98034  , p_source_39            IN NUMBER
98035 --Currency Code
98036  , p_source_40            IN VARCHAR2
98037 )
98038 IS
98039 
98040 l_component_type              VARCHAR2(80);
98041 l_component_code              VARCHAR2(30);
98042 l_component_type_code         VARCHAR2(1);
98043 l_component_appl_id           INTEGER;
98044 l_amb_context_code            VARCHAR2(30);
98045 l_entity_code                 VARCHAR2(30);
98046 l_event_class_code            VARCHAR2(30);
98047 l_ae_header_id                NUMBER;
98048 l_event_type_code             VARCHAR2(30);
98049 l_line_definition_code        VARCHAR2(30);
98050 l_line_definition_owner_code  VARCHAR2(1);
98051 --
98052 -- adr variables
98053 l_segment                     VARCHAR2(30);
98054 l_ccid                        NUMBER;
98055 l_adr_transaction_coa_id      NUMBER;
98056 l_adr_accounting_coa_id       NUMBER;
98057 l_adr_flexfield_segment_code  VARCHAR2(30);
98058 l_adr_flex_value_set_id       NUMBER;
98059 l_adr_value_type_code         VARCHAR2(30);
98060 l_adr_value_combination_id    NUMBER;
98061 l_adr_value_segment_code      VARCHAR2(30);
98062 
98063 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
98064 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
98065 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
98066 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
98067 
98071 l_acc_rev_flag                VARCHAR2(1);
98068 -- 4262811 Variables ------------------------------------------------------------------------------------------
98069 l_entered_amt_idx             NUMBER;
98070 l_accted_amt_idx              NUMBER;
98072 l_accrual_line_num            NUMBER;
98073 l_tmp_amt                     NUMBER;
98074 l_acc_rev_natural_side_code   VARCHAR2(1);
98075 
98076 l_num_entries                 NUMBER;
98077 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
98078 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
98079 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
98080 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
98081 l_recog_line_1                NUMBER;
98082 l_recog_line_2                NUMBER;
98083 
98084 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
98085 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
98086 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
98087 
98088 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
98089 
98090 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
98091 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
98092 
98093 ---------------------------------------------------------------------------------------------------------------
98094 
98095 
98096 --
98097 -- bulk performance
98098 --
98099 l_balance_type_code           VARCHAR2(1);
98100 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
98101 l_log_module                  VARCHAR2(240);
98102 
98103 --
98104 -- Upgrade strategy
98105 --
98106 l_actual_upg_option           VARCHAR2(1);
98107 l_enc_upg_option           VARCHAR2(1);
98108 
98109 --
98110 BEGIN
98111 --
98112 IF g_log_enabled THEN
98113       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_291';
98114 END IF;
98115 --
98116 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
98117 
98118       trace
98119          (p_msg      => 'BEGIN of AcctLineType_291'
98120          ,p_level    => C_LEVEL_PROCEDURE
98121          ,p_module   => l_log_module);
98122 
98123 END IF;
98124 --
98125 l_component_type             := 'AMB_JLT';
98126 l_component_code             := 'FA_RES_IC_PAY';
98127 l_component_type_code        := 'S';
98128 l_component_appl_id          :=  140;
98129 l_amb_context_code           := 'DEFAULT';
98130 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
98131 l_event_class_code           := 'RESERVE_TRANSFERS';
98132 l_event_type_code            := 'RESERVE_TRANSFERS_ALL';
98133 l_line_definition_owner_code := 'S';
98134 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RESER18';
98135 --
98136 l_balance_type_code          := 'A';
98137 l_segment                     := NULL;
98138 l_ccid                        := NULL;
98139 l_adr_transaction_coa_id      := NULL;
98140 l_adr_accounting_coa_id       := NULL;
98141 l_adr_flexfield_segment_code  := NULL;
98142 l_adr_flex_value_set_id       := NULL;
98143 l_adr_value_type_code         := NULL;
98144 l_adr_value_combination_id    := NULL;
98145 l_adr_value_segment_code      := NULL;
98146 
98147 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
98148 l_bflow_class_code           := '';    -- 4219869 Business Flow
98149 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
98150 l_budgetary_control_flag     := 'N';
98151 
98152 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
98153 l_bflow_applied_to_amt       := NULL; -- 5132302
98154 l_entered_amt_idx            := NULL;          -- 4262811
98155 l_accted_amt_idx             := NULL;          -- 4262811
98156 l_acc_rev_flag               := NULL;          -- 4262811
98157 l_accrual_line_num           := NULL;          -- 4262811
98158 l_tmp_amt                    := NULL;          -- 4262811
98159 --
98160  
98161 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
98162     l_balance_type_code <> 'B' THEN
98163 IF NVL(p_source_35,'
98164 ') =  'INTERCO AP'
98165  THEN 
98166 
98167    --
98168    XLA_AE_LINES_PKG.SetNewLine;
98169 
98170    p_balance_type_code          := l_balance_type_code;
98171    -- set the flag so later we will know whether the gain loss line needs to be created
98172    
98173    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
98174      p_actual_flag :='A';
98175    END IF;
98176 
98177    --
98178    -- bulk performance
98179    --
98180    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
98181                                       p_header_num   => 0); -- 4262811
98182    --
98183    -- set accounting line options
98184    --
98185    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
98186            p_natural_side_code          => 'D'
98187          , p_gain_or_loss_flag          => 'N'
98188          , p_gl_transfer_mode_code      => 'S'
98189          , p_acct_entry_type_code       => 'A'
98190          , p_switch_side_flag           => 'Y'
98191          , p_merge_duplicate_code       => 'N'
98192          );
98193    --
98194    l_acc_rev_natural_side_code := 'C';  -- 4262811
98195    -- 
98196    --
98197    -- set accounting line type info
98198    --
98199    xla_ae_lines_pkg.SetAcctLineType
98200       (p_component_type             => l_component_type
98201       ,p_event_type_code            => l_event_type_code
98202       ,p_line_definition_owner_code => l_line_definition_owner_code
98203       ,p_line_definition_code       => l_line_definition_code
98204       ,p_accounting_line_code       => l_component_code
98205       ,p_accounting_line_type_code  => l_component_type_code
98209       ,p_event_class_code           => l_event_class_code);
98206       ,p_accounting_line_appl_id    => l_component_appl_id
98207       ,p_amb_context_code           => l_amb_context_code
98208       ,p_entity_code                => l_entity_code
98210    --
98211    -- set accounting class
98212    --
98213    xla_ae_lines_pkg.SetAcctClass(
98214            p_accounting_class_code  => 'LIABILITY'
98215          , p_ae_header_id           => l_ae_header_id
98216          );
98217 
98218    --
98219    -- set rounding class
98220    --
98221    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
98222                       'LIABILITY';
98223 
98224    --
98225    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
98226    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
98227    --
98228    -- bulk performance
98229    --
98230    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
98231 
98232    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
98233       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
98234 
98235    -- 4955764
98236    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
98237       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
98238 
98239    -- 4458381 Public Sector Enh
98240    
98241    --
98242    -- set accounting attributes for the line type
98243    --
98244    l_entered_amt_idx := 4;
98245    l_accted_amt_idx  := 6;
98246    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
98247    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
98248    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
98249    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
98250    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
98251    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
98252    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
98253    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
98254    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
98255    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
98256    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
98257    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
98258    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
98259 
98260    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
98261    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
98262 
98263    ---------------------------------------------------------------------------------------------------------------
98264    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
98265    ---------------------------------------------------------------------------------------------------------------
98266    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
98267 
98268    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
98269    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
98270 
98271    IF xla_accounting_cache_pkg.GetValueChar
98272          (p_source_code         => 'LEDGER_CATEGORY_CODE'
98273          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
98274    AND l_bflow_method_code = 'PRIOR_ENTRY'
98275 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
98276    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
98277          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
98278        )
98279    THEN
98280          xla_ae_lines_pkg.BflowUpgEntry
98281            (p_business_method_code    => l_bflow_method_code
98282            ,p_business_class_code     => l_bflow_class_code
98283            ,p_balance_type            => l_balance_type_code);
98284    ELSE
98285       NULL;
98286 -- No business flow processing for business flow method of NONE.
98287    END IF;
98288 
98289    --
98290    -- call analytical criteria
98291    --
98292    
98293    --
98294    -- call description
98295    --
98296    
98297 xla_ae_lines_pkg.SetLineDescription(
98298    p_ae_header_id => l_ae_header_id
98299   ,p_description  => Description_71 (
98300      p_application_id         => p_application_id
98301    , p_ae_header_id           => l_ae_header_id 
98302 , p_source_1 => p_source_1
98303    )
98304 );
98305 
98306 
98307    --
98308    -- call ADRs
98309    -- Bug 4922099
98310    --
98311    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
98312         (NVL(l_actual_upg_option, 'N') = 'O') OR
98313         (NVL(l_enc_upg_option, 'N') = 'O')
98314       )
98315    THEN
98316    NULL;
98317    --
98318    --
98319    
98320   l_ccid := AcctDerRule_173(
98321            p_application_id           => p_application_id
98322          , p_ae_header_id             => l_ae_header_id 
98323 , p_source_3 => p_source_3
98324 , p_source_30 => p_source_30
98325          , x_transaction_coa_id       => l_adr_transaction_coa_id
98326          , x_accounting_coa_id        => l_adr_accounting_coa_id
98327          , x_value_type_code          => l_adr_value_type_code
98328          , p_side                     => 'NA'
98329    );
98330 
98331    xla_ae_lines_pkg.set_ccid(
98332     p_code_combination_id          => l_ccid
98333   , p_value_type_code              => l_adr_value_type_code
98334   , p_transaction_coa_id           => l_adr_transaction_coa_id
98335   , p_accounting_coa_id            => l_adr_accounting_coa_id
98339   , p_component_code               => l_component_code
98336   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
98337   , p_adr_type_code                => 'S'
98338   , p_component_type               => l_component_type
98340   , p_component_type_code          => l_component_type_code
98341   , p_component_appl_id            => l_component_appl_id
98342   , p_amb_context_code             => l_amb_context_code
98343   , p_side                         => 'NA'
98344   );
98345 
98346 
98347    l_segment := AcctDerRule_168(
98348            p_application_id           => p_application_id
98349          , p_ae_header_id             => l_ae_header_id 
98350 , p_source_3 => p_source_3
98351 , p_source_29 => p_source_29
98352          , x_transaction_coa_id       => l_adr_transaction_coa_id
98353          , x_accounting_coa_id        => l_adr_accounting_coa_id
98354          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
98355          , x_flex_value_set_id        => l_adr_flex_value_set_id
98356          , x_value_type_code          => l_adr_value_type_code
98357          , x_value_combination_id     => l_adr_value_combination_id
98358          , x_value_segment_code       => l_adr_value_segment_code
98359          , p_side                     => 'NA'
98360          , p_override_seg_flag        => 'Y'
98361    );
98362 
98363    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
98364 
98365       xla_ae_lines_pkg.set_segment(
98366           p_to_segment_code         => 'GL_BALANCING'
98367         , p_segment_value           => l_segment
98368         , p_from_segment_code       => l_adr_value_segment_code
98369         , p_from_combination_id     => l_adr_value_combination_id
98370         , p_value_type_code         => l_adr_value_type_code
98371         , p_transaction_coa_id      => l_adr_transaction_coa_id
98372         , p_accounting_coa_id       => l_adr_accounting_coa_id
98373         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
98374         , p_flex_value_set_id       => l_adr_flex_value_set_id
98375         , p_adr_code                => 'FA_EXPENSE_ACCT'
98376         , p_adr_type_code           => 'S'
98377         , p_component_type          => l_component_type
98378         , p_component_code          => l_component_code
98379         , p_component_type_code     => l_component_type_code
98380         , p_component_appl_id       => l_component_appl_id
98381         , p_amb_context_code        => l_amb_context_code
98382         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
98383         , p_event_class_code        => 'RESERVE_TRANSFERS'
98384         , p_side                    => 'NA'
98385         );
98386 
98387   END IF;
98388 
98389    l_segment := AcctDerRule_157(
98390            p_application_id           => p_application_id
98391          , p_ae_header_id             => l_ae_header_id 
98392 , p_source_3 => p_source_3
98393 , p_source_19 => p_source_19
98394          , x_transaction_coa_id       => l_adr_transaction_coa_id
98395          , x_accounting_coa_id        => l_adr_accounting_coa_id
98396          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
98397          , x_flex_value_set_id        => l_adr_flex_value_set_id
98398          , x_value_type_code          => l_adr_value_type_code
98399          , x_value_combination_id     => l_adr_value_combination_id
98400          , x_value_segment_code       => l_adr_value_segment_code
98401          , p_side                     => 'NA'
98402          , p_override_seg_flag        => 'Y'
98403    );
98404 
98405    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
98406 
98407       xla_ae_lines_pkg.set_segment(
98408           p_to_segment_code         => 'GL_ACCOUNT'
98409         , p_segment_value           => l_segment
98410         , p_from_segment_code       => l_adr_value_segment_code
98411         , p_from_combination_id     => l_adr_value_combination_id
98412         , p_value_type_code         => l_adr_value_type_code
98413         , p_transaction_coa_id      => l_adr_transaction_coa_id
98414         , p_accounting_coa_id       => l_adr_accounting_coa_id
98415         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
98416         , p_flex_value_set_id       => l_adr_flex_value_set_id
98417         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
98418         , p_adr_type_code           => 'S'
98419         , p_component_type          => l_component_type
98420         , p_component_code          => l_component_code
98421         , p_component_type_code     => l_component_type_code
98422         , p_component_appl_id       => l_component_appl_id
98423         , p_amb_context_code        => l_amb_context_code
98424         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
98425         , p_event_class_code        => 'RESERVE_TRANSFERS'
98426         , p_side                    => 'NA'
98427         );
98428 
98429   END IF;
98430 
98431    --
98432    --
98433    END IF;
98434    --
98435    -- Bug 4922099
98436    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
98437           (NVL(l_enc_upg_option, 'N') = 'O')
98438         ) AND
98439         (l_bflow_method_code = 'PRIOR_ENTRY')
98440       )
98441    THEN
98442       IF
98443       --
98444       1 = 2
98445       --
98446       THEN
98447       xla_accounting_err_pkg.build_message
98448                                     (p_appli_s_name            => 'XLA'
98449                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
98450                                     ,p_token_1                 => 'LINE_NUMBER'
98451                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
98452                                     ,p_token_2                 => 'LINE_TYPE_NAME'
98453                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
98454                                                                              l_component_type
98458                                                                             ,l_amb_context_code
98455                                                                             ,l_component_code
98456                                                                             ,l_component_type_code
98457                                                                             ,l_component_appl_id
98459                                                                             ,l_entity_code
98460                                                                             ,l_event_class_code
98461                                                                            )
98462                                     ,p_token_3                 => 'OWNER'
98463                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
98464                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
98465                                                                           ,p_lookup_code    => l_component_type_code
98466                                                                          )
98467                                     ,p_token_4                 => 'PRODUCT_NAME'
98468                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
98469                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
98470                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
98471                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
98472                                     ,p_ae_header_id            =>  NULL
98473                                        );
98474 
98475         IF (C_LEVEL_ERROR>= g_log_level) THEN
98476                  trace
98477                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
98478                       ,p_level    => C_LEVEL_ERROR
98479                       ,p_module   => l_log_module);
98480         END IF;
98481       END IF;
98482    END IF;
98483    --
98484    --
98485    ------------------------------------------------------------------------------------------------
98486    -- 4219869 Business Flow
98487    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
98488    -- Prior Entry.  Currently, the following code is always generated.
98489    ------------------------------------------------------------------------------------------------
98490    XLA_AE_LINES_PKG.ValidateCurrentLine;
98491 
98492    ------------------------------------------------------------------------------------
98493    -- 4219869 Business Flow
98494    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
98495    ------------------------------------------------------------------------------------
98496    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
98497 
98498    ----------------------------------------------------------------------------------
98499    -- 4219869 Business Flow
98500    -- Update journal entry status -- Need to generate this within IF <condition>
98501    ----------------------------------------------------------------------------------
98502    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
98503          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
98504          ,p_balance_type_code => l_balance_type_code
98505          );
98506 
98507    -------------------------------------------------------------------------------------------
98508    -- 4262811 - Generate the Accrual Reversal lines
98509    -------------------------------------------------------------------------------------------
98510    BEGIN
98511       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
98512                               (g_array_event(p_event_id).array_value_num('header_index'));
98513       IF l_acc_rev_flag IS NULL THEN
98514          l_acc_rev_flag := 'N';
98515       END IF;
98516    EXCEPTION
98517       WHEN OTHERS THEN
98518          l_acc_rev_flag := 'N';
98519    END;
98520    --
98521    IF (l_acc_rev_flag = 'Y') THEN
98522 
98523        -- 4645092  ------------------------------------------------------------------------------
98524        -- To allow MPA report to determine if it should generate report process
98525        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
98526        ------------------------------------------------------------------------------------------
98527 
98528        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
98529        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
98530    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
98531    -- call ADRs
98532    -- Bug 4922099
98533    --
98534    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
98535         (NVL(l_actual_upg_option, 'N') = 'O') OR
98536         (NVL(l_enc_upg_option, 'N') = 'O')
98537       )
98538    THEN
98539    NULL;
98540    --
98541    --
98542    
98543   l_ccid := AcctDerRule_173(
98544            p_application_id           => p_application_id
98545          , p_ae_header_id             => l_ae_header_id 
98546 , p_source_3 => p_source_3
98547 , p_source_30 => p_source_30
98548          , x_transaction_coa_id       => l_adr_transaction_coa_id
98549          , x_accounting_coa_id        => l_adr_accounting_coa_id
98550          , x_value_type_code          => l_adr_value_type_code
98551          , p_side                     => 'NA'
98552    );
98553 
98554    xla_ae_lines_pkg.set_ccid(
98555     p_code_combination_id          => l_ccid
98556   , p_value_type_code              => l_adr_value_type_code
98557   , p_transaction_coa_id           => l_adr_transaction_coa_id
98558   , p_accounting_coa_id            => l_adr_accounting_coa_id
98559   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
98560   , p_adr_type_code                => 'S'
98564   , p_component_appl_id            => l_component_appl_id
98561   , p_component_type               => l_component_type
98562   , p_component_code               => l_component_code
98563   , p_component_type_code          => l_component_type_code
98565   , p_amb_context_code             => l_amb_context_code
98566   , p_side                         => 'NA'
98567   );
98568 
98569 
98570    l_segment := AcctDerRule_168(
98571            p_application_id           => p_application_id
98572          , p_ae_header_id             => l_ae_header_id 
98573 , p_source_3 => p_source_3
98574 , p_source_29 => p_source_29
98575          , x_transaction_coa_id       => l_adr_transaction_coa_id
98576          , x_accounting_coa_id        => l_adr_accounting_coa_id
98577          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
98578          , x_flex_value_set_id        => l_adr_flex_value_set_id
98579          , x_value_type_code          => l_adr_value_type_code
98580          , x_value_combination_id     => l_adr_value_combination_id
98581          , x_value_segment_code       => l_adr_value_segment_code
98582          , p_side                     => 'NA'
98583          , p_override_seg_flag        => 'Y'
98584    );
98585 
98586    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
98587 
98588       xla_ae_lines_pkg.set_segment(
98589           p_to_segment_code         => 'GL_BALANCING'
98590         , p_segment_value           => l_segment
98591         , p_from_segment_code       => l_adr_value_segment_code
98592         , p_from_combination_id     => l_adr_value_combination_id
98593         , p_value_type_code         => l_adr_value_type_code
98594         , p_transaction_coa_id      => l_adr_transaction_coa_id
98595         , p_accounting_coa_id       => l_adr_accounting_coa_id
98596         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
98597         , p_flex_value_set_id       => l_adr_flex_value_set_id
98598         , p_adr_code                => 'FA_EXPENSE_ACCT'
98599         , p_adr_type_code           => 'S'
98600         , p_component_type          => l_component_type
98601         , p_component_code          => l_component_code
98602         , p_component_type_code     => l_component_type_code
98603         , p_component_appl_id       => l_component_appl_id
98604         , p_amb_context_code        => l_amb_context_code
98605         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
98606         , p_event_class_code        => 'RESERVE_TRANSFERS'
98607         , p_side                    => 'NA'
98608         );
98609 
98610   END IF;
98611 
98612    l_segment := AcctDerRule_157(
98613            p_application_id           => p_application_id
98614          , p_ae_header_id             => l_ae_header_id 
98615 , p_source_3 => p_source_3
98616 , p_source_19 => p_source_19
98617          , x_transaction_coa_id       => l_adr_transaction_coa_id
98618          , x_accounting_coa_id        => l_adr_accounting_coa_id
98619          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
98620          , x_flex_value_set_id        => l_adr_flex_value_set_id
98621          , x_value_type_code          => l_adr_value_type_code
98622          , x_value_combination_id     => l_adr_value_combination_id
98623          , x_value_segment_code       => l_adr_value_segment_code
98624          , p_side                     => 'NA'
98625          , p_override_seg_flag        => 'Y'
98626    );
98627 
98628    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
98629 
98630       xla_ae_lines_pkg.set_segment(
98631           p_to_segment_code         => 'GL_ACCOUNT'
98632         , p_segment_value           => l_segment
98633         , p_from_segment_code       => l_adr_value_segment_code
98634         , p_from_combination_id     => l_adr_value_combination_id
98635         , p_value_type_code         => l_adr_value_type_code
98636         , p_transaction_coa_id      => l_adr_transaction_coa_id
98637         , p_accounting_coa_id       => l_adr_accounting_coa_id
98638         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
98639         , p_flex_value_set_id       => l_adr_flex_value_set_id
98640         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
98641         , p_adr_type_code           => 'S'
98642         , p_component_type          => l_component_type
98643         , p_component_code          => l_component_code
98644         , p_component_type_code     => l_component_type_code
98645         , p_component_appl_id       => l_component_appl_id
98646         , p_amb_context_code        => l_amb_context_code
98647         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
98648         , p_event_class_code        => 'RESERVE_TRANSFERS'
98649         , p_side                    => 'NA'
98650         );
98651 
98652   END IF;
98653 
98654    --
98655    --
98656    END IF;
98657 
98658        --
98659        -- Update the line information that should be overwritten
98660        --
98661        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
98662                                          p_header_num   => 1);
98663        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
98664 
98665        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
98666 
98667        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
98668           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
98669        END IF;
98670 
98671       --
98672       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
98673       --
98674       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
98675           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
98676       ELSE
98680           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
98677           ---------------------------------------------------------------------------------------------------
98678           -- 4262811a Switch Sign
98679           ---------------------------------------------------------------------------------------------------
98681           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
98682                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
98683           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
98684                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
98685           -- 5132302
98686           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
98687                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
98688 
98689       END IF;
98690 
98691       -- 4955764
98692       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
98693       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
98694 
98695 
98696       XLA_AE_LINES_PKG.ValidateCurrentLine;
98697       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
98698 
98699       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
98700                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
98701                ,p_balance_type_code => l_balance_type_code);
98702 
98703    END IF;
98704 
98705    -----------------------------------------------------------------------------------------
98706    -- 4262811 Multiperiod Accounting
98707    -----------------------------------------------------------------------------------------
98708      -- No MPA option is assigned.
98709 
98710 
98711 END IF;
98712 END IF;
98713 --
98714 
98715 --
98716 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
98717    trace
98718       (p_msg      => 'END of AcctLineType_291'
98719       ,p_level    => C_LEVEL_PROCEDURE
98720       ,p_module   => l_log_module);
98721 END IF;
98722 --
98723 EXCEPTION
98724   WHEN xla_exceptions_pkg.application_exception THEN
98725       RAISE;
98726   WHEN OTHERS THEN
98727        xla_exceptions_pkg.raise_message
98728            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_291');
98729 END AcctLineType_291;
98730 --
98731 
98732 ---------------------------------------
98733 --
98734 -- PRIVATE FUNCTION
98735 --         AcctLineType_292
98736 --
98737 ---------------------------------------
98738 PROCEDURE AcctLineType_292 (
98739   p_application_id        IN NUMBER
98740  ,p_event_id              IN NUMBER
98741  ,p_calculate_acctd_flag  IN VARCHAR2
98742  ,p_calculate_g_l_flag    IN VARCHAR2
98743  ,p_actual_flag           IN OUT VARCHAR2
98744  ,p_balance_type_code     OUT VARCHAR2
98745  ,p_gain_or_loss_ref      OUT VARCHAR2
98746  
98747 --Period Close Date
98748  , p_source_1            IN DATE
98749 --Generated Code Combination Identifier
98750  , p_source_3            IN NUMBER
98751 --Intercompany Receivables Account
98752  , p_source_20            IN VARCHAR2
98753 --Expense Account Code Combination Identifier
98754  , p_source_29            IN NUMBER
98755 --Default Code Combination Identifier
98756  , p_source_30            IN NUMBER
98757 --Adjustment Type
98758  , p_source_35            IN VARCHAR2
98759 --Transaction Header Identifier
98760  , p_source_36            IN NUMBER
98761 --Adjustment Line Identifier
98762  , p_source_37            IN NUMBER
98763 --Distribution Type Code
98764  , p_source_38            IN VARCHAR2
98765 --Entered Amount
98766  , p_source_39            IN NUMBER
98767 --Currency Code
98768  , p_source_40            IN VARCHAR2
98769 )
98770 IS
98771 
98772 l_component_type              VARCHAR2(80);
98773 l_component_code              VARCHAR2(30);
98774 l_component_type_code         VARCHAR2(1);
98775 l_component_appl_id           INTEGER;
98776 l_amb_context_code            VARCHAR2(30);
98777 l_entity_code                 VARCHAR2(30);
98778 l_event_class_code            VARCHAR2(30);
98779 l_ae_header_id                NUMBER;
98780 l_event_type_code             VARCHAR2(30);
98781 l_line_definition_code        VARCHAR2(30);
98782 l_line_definition_owner_code  VARCHAR2(1);
98783 --
98784 -- adr variables
98785 l_segment                     VARCHAR2(30);
98786 l_ccid                        NUMBER;
98787 l_adr_transaction_coa_id      NUMBER;
98788 l_adr_accounting_coa_id       NUMBER;
98789 l_adr_flexfield_segment_code  VARCHAR2(30);
98790 l_adr_flex_value_set_id       NUMBER;
98791 l_adr_value_type_code         VARCHAR2(30);
98792 l_adr_value_combination_id    NUMBER;
98793 l_adr_value_segment_code      VARCHAR2(30);
98794 
98795 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
98796 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
98797 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
98798 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
98799 
98800 -- 4262811 Variables ------------------------------------------------------------------------------------------
98801 l_entered_amt_idx             NUMBER;
98802 l_accted_amt_idx              NUMBER;
98803 l_acc_rev_flag                VARCHAR2(1);
98804 l_accrual_line_num            NUMBER;
98805 l_tmp_amt                     NUMBER;
98806 l_acc_rev_natural_side_code   VARCHAR2(1);
98807 
98808 l_num_entries                 NUMBER;
98809 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
98810 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
98814 l_recog_line_2                NUMBER;
98811 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
98812 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
98813 l_recog_line_1                NUMBER;
98815 
98816 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
98817 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
98818 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
98819 
98820 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
98821 
98822 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
98823 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
98824 
98825 ---------------------------------------------------------------------------------------------------------------
98826 
98827 
98828 --
98829 -- bulk performance
98830 --
98831 l_balance_type_code           VARCHAR2(1);
98832 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
98833 l_log_module                  VARCHAR2(240);
98834 
98835 --
98836 -- Upgrade strategy
98837 --
98838 l_actual_upg_option           VARCHAR2(1);
98839 l_enc_upg_option           VARCHAR2(1);
98840 
98841 --
98842 BEGIN
98843 --
98844 IF g_log_enabled THEN
98845       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_292';
98846 END IF;
98847 --
98848 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
98849 
98850       trace
98851          (p_msg      => 'BEGIN of AcctLineType_292'
98852          ,p_level    => C_LEVEL_PROCEDURE
98853          ,p_module   => l_log_module);
98854 
98855 END IF;
98856 --
98857 l_component_type             := 'AMB_JLT';
98858 l_component_code             := 'FA_RES_IC_REC`';
98859 l_component_type_code        := 'S';
98860 l_component_appl_id          :=  140;
98861 l_amb_context_code           := 'DEFAULT';
98862 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
98863 l_event_class_code           := 'RESERVE_TRANSFERS';
98864 l_event_type_code            := 'RESERVE_TRANSFERS_ALL';
98865 l_line_definition_owner_code := 'S';
98866 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RESER18';
98867 --
98868 l_balance_type_code          := 'A';
98869 l_segment                     := NULL;
98870 l_ccid                        := NULL;
98871 l_adr_transaction_coa_id      := NULL;
98872 l_adr_accounting_coa_id       := NULL;
98873 l_adr_flexfield_segment_code  := NULL;
98874 l_adr_flex_value_set_id       := NULL;
98875 l_adr_value_type_code         := NULL;
98876 l_adr_value_combination_id    := NULL;
98877 l_adr_value_segment_code      := NULL;
98878 
98879 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
98880 l_bflow_class_code           := '';    -- 4219869 Business Flow
98881 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
98882 l_budgetary_control_flag     := 'N';
98883 
98884 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
98885 l_bflow_applied_to_amt       := NULL; -- 5132302
98886 l_entered_amt_idx            := NULL;          -- 4262811
98887 l_accted_amt_idx             := NULL;          -- 4262811
98888 l_acc_rev_flag               := NULL;          -- 4262811
98889 l_accrual_line_num           := NULL;          -- 4262811
98890 l_tmp_amt                    := NULL;          -- 4262811
98891 --
98892  
98893 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
98894     l_balance_type_code <> 'B' THEN
98895 IF NVL(p_source_35,'
98896 ') =  'INTERCO AR'
98897  THEN 
98898 
98899    --
98900    XLA_AE_LINES_PKG.SetNewLine;
98901 
98902    p_balance_type_code          := l_balance_type_code;
98903    -- set the flag so later we will know whether the gain loss line needs to be created
98904    
98905    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
98906      p_actual_flag :='A';
98907    END IF;
98908 
98909    --
98910    -- bulk performance
98911    --
98912    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
98913                                       p_header_num   => 0); -- 4262811
98914    --
98915    -- set accounting line options
98916    --
98917    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
98918            p_natural_side_code          => 'D'
98919          , p_gain_or_loss_flag          => 'N'
98920          , p_gl_transfer_mode_code      => 'S'
98921          , p_acct_entry_type_code       => 'A'
98922          , p_switch_side_flag           => 'Y'
98923          , p_merge_duplicate_code       => 'N'
98924          );
98925    --
98926    l_acc_rev_natural_side_code := 'C';  -- 4262811
98927    -- 
98928    --
98929    -- set accounting line type info
98930    --
98931    xla_ae_lines_pkg.SetAcctLineType
98932       (p_component_type             => l_component_type
98933       ,p_event_type_code            => l_event_type_code
98934       ,p_line_definition_owner_code => l_line_definition_owner_code
98935       ,p_line_definition_code       => l_line_definition_code
98936       ,p_accounting_line_code       => l_component_code
98937       ,p_accounting_line_type_code  => l_component_type_code
98938       ,p_accounting_line_appl_id    => l_component_appl_id
98939       ,p_amb_context_code           => l_amb_context_code
98940       ,p_entity_code                => l_entity_code
98941       ,p_event_class_code           => l_event_class_code);
98942    --
98943    -- set accounting class
98944    --
98945    xla_ae_lines_pkg.SetAcctClass(
98946            p_accounting_class_code  => 'ASSET'
98947          , p_ae_header_id           => l_ae_header_id
98948          );
98949 
98950    --
98951    -- set rounding class
98952    --
98956    --
98953    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
98954                       'ASSET';
98955 
98957    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
98958    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
98959    --
98960    -- bulk performance
98961    --
98962    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
98963 
98964    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
98965       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
98966 
98967    -- 4955764
98968    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
98969       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
98970 
98971    -- 4458381 Public Sector Enh
98972    
98973    --
98974    -- set accounting attributes for the line type
98975    --
98976    l_entered_amt_idx := 4;
98977    l_accted_amt_idx  := 6;
98978    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
98979    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
98980    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
98981    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
98982    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
98983    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
98984    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
98985    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
98986    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
98987    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
98988    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
98989    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
98990    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
98991 
98992    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
98993    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
98994 
98995    ---------------------------------------------------------------------------------------------------------------
98996    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
98997    ---------------------------------------------------------------------------------------------------------------
98998    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
98999 
99000    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
99001    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
99002 
99003    IF xla_accounting_cache_pkg.GetValueChar
99004          (p_source_code         => 'LEDGER_CATEGORY_CODE'
99005          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
99006    AND l_bflow_method_code = 'PRIOR_ENTRY'
99007 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
99008    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
99009          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
99010        )
99011    THEN
99012          xla_ae_lines_pkg.BflowUpgEntry
99013            (p_business_method_code    => l_bflow_method_code
99014            ,p_business_class_code     => l_bflow_class_code
99015            ,p_balance_type            => l_balance_type_code);
99016    ELSE
99017       NULL;
99018 -- No business flow processing for business flow method of NONE.
99019    END IF;
99020 
99021    --
99022    -- call analytical criteria
99023    --
99024    
99025    --
99026    -- call description
99027    --
99028    
99029 xla_ae_lines_pkg.SetLineDescription(
99030    p_ae_header_id => l_ae_header_id
99031   ,p_description  => Description_72 (
99032      p_application_id         => p_application_id
99033    , p_ae_header_id           => l_ae_header_id 
99034 , p_source_1 => p_source_1
99035    )
99036 );
99037 
99038 
99039    --
99040    -- call ADRs
99041    -- Bug 4922099
99042    --
99043    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
99044         (NVL(l_actual_upg_option, 'N') = 'O') OR
99045         (NVL(l_enc_upg_option, 'N') = 'O')
99046       )
99047    THEN
99048    NULL;
99049    --
99050    --
99051    
99052   l_ccid := AcctDerRule_173(
99053            p_application_id           => p_application_id
99054          , p_ae_header_id             => l_ae_header_id 
99055 , p_source_3 => p_source_3
99056 , p_source_30 => p_source_30
99057          , x_transaction_coa_id       => l_adr_transaction_coa_id
99058          , x_accounting_coa_id        => l_adr_accounting_coa_id
99059          , x_value_type_code          => l_adr_value_type_code
99060          , p_side                     => 'NA'
99061    );
99062 
99063    xla_ae_lines_pkg.set_ccid(
99064     p_code_combination_id          => l_ccid
99065   , p_value_type_code              => l_adr_value_type_code
99066   , p_transaction_coa_id           => l_adr_transaction_coa_id
99067   , p_accounting_coa_id            => l_adr_accounting_coa_id
99068   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
99069   , p_adr_type_code                => 'S'
99070   , p_component_type               => l_component_type
99071   , p_component_code               => l_component_code
99072   , p_component_type_code          => l_component_type_code
99073   , p_component_appl_id            => l_component_appl_id
99074   , p_amb_context_code             => l_amb_context_code
99075   , p_side                         => 'NA'
99076   );
99077 
99078 
99079    l_segment := AcctDerRule_168(
99083 , p_source_29 => p_source_29
99080            p_application_id           => p_application_id
99081          , p_ae_header_id             => l_ae_header_id 
99082 , p_source_3 => p_source_3
99084          , x_transaction_coa_id       => l_adr_transaction_coa_id
99085          , x_accounting_coa_id        => l_adr_accounting_coa_id
99086          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
99087          , x_flex_value_set_id        => l_adr_flex_value_set_id
99088          , x_value_type_code          => l_adr_value_type_code
99089          , x_value_combination_id     => l_adr_value_combination_id
99090          , x_value_segment_code       => l_adr_value_segment_code
99091          , p_side                     => 'NA'
99092          , p_override_seg_flag        => 'Y'
99093    );
99094 
99095    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
99096 
99097       xla_ae_lines_pkg.set_segment(
99098           p_to_segment_code         => 'GL_BALANCING'
99099         , p_segment_value           => l_segment
99100         , p_from_segment_code       => l_adr_value_segment_code
99101         , p_from_combination_id     => l_adr_value_combination_id
99102         , p_value_type_code         => l_adr_value_type_code
99103         , p_transaction_coa_id      => l_adr_transaction_coa_id
99104         , p_accounting_coa_id       => l_adr_accounting_coa_id
99105         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
99106         , p_flex_value_set_id       => l_adr_flex_value_set_id
99107         , p_adr_code                => 'FA_EXPENSE_ACCT'
99108         , p_adr_type_code           => 'S'
99109         , p_component_type          => l_component_type
99110         , p_component_code          => l_component_code
99111         , p_component_type_code     => l_component_type_code
99112         , p_component_appl_id       => l_component_appl_id
99113         , p_amb_context_code        => l_amb_context_code
99114         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
99115         , p_event_class_code        => 'RESERVE_TRANSFERS'
99116         , p_side                    => 'NA'
99117         );
99118 
99119   END IF;
99120 
99121    l_segment := AcctDerRule_158(
99122            p_application_id           => p_application_id
99123          , p_ae_header_id             => l_ae_header_id 
99124 , p_source_3 => p_source_3
99125 , p_source_20 => p_source_20
99126          , x_transaction_coa_id       => l_adr_transaction_coa_id
99127          , x_accounting_coa_id        => l_adr_accounting_coa_id
99128          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
99129          , x_flex_value_set_id        => l_adr_flex_value_set_id
99130          , x_value_type_code          => l_adr_value_type_code
99131          , x_value_combination_id     => l_adr_value_combination_id
99132          , x_value_segment_code       => l_adr_value_segment_code
99133          , p_side                     => 'NA'
99134          , p_override_seg_flag        => 'Y'
99135    );
99136 
99137    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
99138 
99139       xla_ae_lines_pkg.set_segment(
99140           p_to_segment_code         => 'GL_ACCOUNT'
99141         , p_segment_value           => l_segment
99142         , p_from_segment_code       => l_adr_value_segment_code
99143         , p_from_combination_id     => l_adr_value_combination_id
99144         , p_value_type_code         => l_adr_value_type_code
99145         , p_transaction_coa_id      => l_adr_transaction_coa_id
99146         , p_accounting_coa_id       => l_adr_accounting_coa_id
99147         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
99148         , p_flex_value_set_id       => l_adr_flex_value_set_id
99149         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
99150         , p_adr_type_code           => 'S'
99151         , p_component_type          => l_component_type
99152         , p_component_code          => l_component_code
99153         , p_component_type_code     => l_component_type_code
99154         , p_component_appl_id       => l_component_appl_id
99155         , p_amb_context_code        => l_amb_context_code
99156         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
99157         , p_event_class_code        => 'RESERVE_TRANSFERS'
99158         , p_side                    => 'NA'
99159         );
99160 
99161   END IF;
99162 
99163    --
99164    --
99165    END IF;
99166    --
99167    -- Bug 4922099
99168    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
99169           (NVL(l_enc_upg_option, 'N') = 'O')
99170         ) AND
99171         (l_bflow_method_code = 'PRIOR_ENTRY')
99172       )
99173    THEN
99174       IF
99175       --
99176       1 = 2
99177       --
99178       THEN
99179       xla_accounting_err_pkg.build_message
99180                                     (p_appli_s_name            => 'XLA'
99181                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
99182                                     ,p_token_1                 => 'LINE_NUMBER'
99183                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
99184                                     ,p_token_2                 => 'LINE_TYPE_NAME'
99185                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
99186                                                                              l_component_type
99187                                                                             ,l_component_code
99188                                                                             ,l_component_type_code
99189                                                                             ,l_component_appl_id
99190                                                                             ,l_amb_context_code
99191                                                                             ,l_entity_code
99195                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
99192                                                                             ,l_event_class_code
99193                                                                            )
99194                                     ,p_token_3                 => 'OWNER'
99196                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
99197                                                                           ,p_lookup_code    => l_component_type_code
99198                                                                          )
99199                                     ,p_token_4                 => 'PRODUCT_NAME'
99200                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
99201                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
99202                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
99203                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
99204                                     ,p_ae_header_id            =>  NULL
99205                                        );
99206 
99207         IF (C_LEVEL_ERROR>= g_log_level) THEN
99208                  trace
99209                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
99210                       ,p_level    => C_LEVEL_ERROR
99211                       ,p_module   => l_log_module);
99212         END IF;
99213       END IF;
99214    END IF;
99215    --
99216    --
99217    ------------------------------------------------------------------------------------------------
99218    -- 4219869 Business Flow
99219    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
99220    -- Prior Entry.  Currently, the following code is always generated.
99221    ------------------------------------------------------------------------------------------------
99222    XLA_AE_LINES_PKG.ValidateCurrentLine;
99223 
99224    ------------------------------------------------------------------------------------
99225    -- 4219869 Business Flow
99226    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
99227    ------------------------------------------------------------------------------------
99228    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
99229 
99230    ----------------------------------------------------------------------------------
99231    -- 4219869 Business Flow
99232    -- Update journal entry status -- Need to generate this within IF <condition>
99233    ----------------------------------------------------------------------------------
99234    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
99235          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
99236          ,p_balance_type_code => l_balance_type_code
99237          );
99238 
99239    -------------------------------------------------------------------------------------------
99240    -- 4262811 - Generate the Accrual Reversal lines
99241    -------------------------------------------------------------------------------------------
99242    BEGIN
99243       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
99244                               (g_array_event(p_event_id).array_value_num('header_index'));
99245       IF l_acc_rev_flag IS NULL THEN
99246          l_acc_rev_flag := 'N';
99247       END IF;
99248    EXCEPTION
99249       WHEN OTHERS THEN
99250          l_acc_rev_flag := 'N';
99251    END;
99252    --
99253    IF (l_acc_rev_flag = 'Y') THEN
99254 
99255        -- 4645092  ------------------------------------------------------------------------------
99256        -- To allow MPA report to determine if it should generate report process
99257        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
99258        ------------------------------------------------------------------------------------------
99259 
99260        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
99261        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
99262    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
99263    -- call ADRs
99264    -- Bug 4922099
99265    --
99266    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
99267         (NVL(l_actual_upg_option, 'N') = 'O') OR
99268         (NVL(l_enc_upg_option, 'N') = 'O')
99269       )
99270    THEN
99271    NULL;
99272    --
99273    --
99274    
99275   l_ccid := AcctDerRule_173(
99276            p_application_id           => p_application_id
99277          , p_ae_header_id             => l_ae_header_id 
99278 , p_source_3 => p_source_3
99279 , p_source_30 => p_source_30
99280          , x_transaction_coa_id       => l_adr_transaction_coa_id
99281          , x_accounting_coa_id        => l_adr_accounting_coa_id
99282          , x_value_type_code          => l_adr_value_type_code
99283          , p_side                     => 'NA'
99284    );
99285 
99286    xla_ae_lines_pkg.set_ccid(
99287     p_code_combination_id          => l_ccid
99288   , p_value_type_code              => l_adr_value_type_code
99289   , p_transaction_coa_id           => l_adr_transaction_coa_id
99290   , p_accounting_coa_id            => l_adr_accounting_coa_id
99291   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
99292   , p_adr_type_code                => 'S'
99293   , p_component_type               => l_component_type
99294   , p_component_code               => l_component_code
99295   , p_component_type_code          => l_component_type_code
99296   , p_component_appl_id            => l_component_appl_id
99297   , p_amb_context_code             => l_amb_context_code
99298   , p_side                         => 'NA'
99299   );
99300 
99301 
99302    l_segment := AcctDerRule_168(
99306 , p_source_29 => p_source_29
99303            p_application_id           => p_application_id
99304          , p_ae_header_id             => l_ae_header_id 
99305 , p_source_3 => p_source_3
99307          , x_transaction_coa_id       => l_adr_transaction_coa_id
99308          , x_accounting_coa_id        => l_adr_accounting_coa_id
99309          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
99310          , x_flex_value_set_id        => l_adr_flex_value_set_id
99311          , x_value_type_code          => l_adr_value_type_code
99312          , x_value_combination_id     => l_adr_value_combination_id
99313          , x_value_segment_code       => l_adr_value_segment_code
99314          , p_side                     => 'NA'
99315          , p_override_seg_flag        => 'Y'
99316    );
99317 
99318    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
99319 
99320       xla_ae_lines_pkg.set_segment(
99321           p_to_segment_code         => 'GL_BALANCING'
99322         , p_segment_value           => l_segment
99323         , p_from_segment_code       => l_adr_value_segment_code
99324         , p_from_combination_id     => l_adr_value_combination_id
99325         , p_value_type_code         => l_adr_value_type_code
99326         , p_transaction_coa_id      => l_adr_transaction_coa_id
99327         , p_accounting_coa_id       => l_adr_accounting_coa_id
99328         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
99329         , p_flex_value_set_id       => l_adr_flex_value_set_id
99330         , p_adr_code                => 'FA_EXPENSE_ACCT'
99331         , p_adr_type_code           => 'S'
99332         , p_component_type          => l_component_type
99333         , p_component_code          => l_component_code
99334         , p_component_type_code     => l_component_type_code
99335         , p_component_appl_id       => l_component_appl_id
99336         , p_amb_context_code        => l_amb_context_code
99337         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
99338         , p_event_class_code        => 'RESERVE_TRANSFERS'
99339         , p_side                    => 'NA'
99340         );
99341 
99342   END IF;
99343 
99344    l_segment := AcctDerRule_158(
99345            p_application_id           => p_application_id
99346          , p_ae_header_id             => l_ae_header_id 
99347 , p_source_3 => p_source_3
99348 , p_source_20 => p_source_20
99349          , x_transaction_coa_id       => l_adr_transaction_coa_id
99350          , x_accounting_coa_id        => l_adr_accounting_coa_id
99351          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
99352          , x_flex_value_set_id        => l_adr_flex_value_set_id
99353          , x_value_type_code          => l_adr_value_type_code
99354          , x_value_combination_id     => l_adr_value_combination_id
99355          , x_value_segment_code       => l_adr_value_segment_code
99356          , p_side                     => 'NA'
99357          , p_override_seg_flag        => 'Y'
99358    );
99359 
99360    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
99361 
99362       xla_ae_lines_pkg.set_segment(
99363           p_to_segment_code         => 'GL_ACCOUNT'
99364         , p_segment_value           => l_segment
99365         , p_from_segment_code       => l_adr_value_segment_code
99366         , p_from_combination_id     => l_adr_value_combination_id
99367         , p_value_type_code         => l_adr_value_type_code
99368         , p_transaction_coa_id      => l_adr_transaction_coa_id
99369         , p_accounting_coa_id       => l_adr_accounting_coa_id
99370         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
99371         , p_flex_value_set_id       => l_adr_flex_value_set_id
99372         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
99373         , p_adr_type_code           => 'S'
99374         , p_component_type          => l_component_type
99375         , p_component_code          => l_component_code
99376         , p_component_type_code     => l_component_type_code
99377         , p_component_appl_id       => l_component_appl_id
99378         , p_amb_context_code        => l_amb_context_code
99379         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
99380         , p_event_class_code        => 'RESERVE_TRANSFERS'
99381         , p_side                    => 'NA'
99382         );
99383 
99384   END IF;
99385 
99386    --
99387    --
99388    END IF;
99389 
99390        --
99391        -- Update the line information that should be overwritten
99392        --
99393        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
99394                                          p_header_num   => 1);
99395        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
99396 
99397        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
99398 
99399        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
99400           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
99401        END IF;
99402 
99403       --
99404       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
99405       --
99406       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
99407           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
99408       ELSE
99409           ---------------------------------------------------------------------------------------------------
99410           -- 4262811a Switch Sign
99411           ---------------------------------------------------------------------------------------------------
99412           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
99413           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
99417           -- 5132302
99414                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
99415           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
99416                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
99418           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
99419                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
99420 
99421       END IF;
99422 
99423       -- 4955764
99424       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
99425       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
99426 
99427 
99428       XLA_AE_LINES_PKG.ValidateCurrentLine;
99429       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
99430 
99431       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
99432                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
99433                ,p_balance_type_code => l_balance_type_code);
99434 
99435    END IF;
99436 
99437    -----------------------------------------------------------------------------------------
99438    -- 4262811 Multiperiod Accounting
99439    -----------------------------------------------------------------------------------------
99440      -- No MPA option is assigned.
99441 
99442 
99443 END IF;
99444 END IF;
99445 --
99446 
99447 --
99448 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
99449    trace
99450       (p_msg      => 'END of AcctLineType_292'
99451       ,p_level    => C_LEVEL_PROCEDURE
99452       ,p_module   => l_log_module);
99453 END IF;
99454 --
99455 EXCEPTION
99456   WHEN xla_exceptions_pkg.application_exception THEN
99457       RAISE;
99458   WHEN OTHERS THEN
99459        xla_exceptions_pkg.raise_message
99460            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_292');
99461 END AcctLineType_292;
99462 --
99463 
99464 ---------------------------------------
99465 --
99466 -- PRIVATE FUNCTION
99467 --         AcctLineType_293
99468 --
99469 ---------------------------------------
99470 PROCEDURE AcctLineType_293 (
99471   p_application_id        IN NUMBER
99472  ,p_event_id              IN NUMBER
99473  ,p_calculate_acctd_flag  IN VARCHAR2
99474  ,p_calculate_g_l_flag    IN VARCHAR2
99475  ,p_actual_flag           IN OUT VARCHAR2
99476  ,p_balance_type_code     OUT VARCHAR2
99477  ,p_gain_or_loss_ref      OUT VARCHAR2
99478  
99479 --Period Close Date
99480  , p_source_1            IN DATE
99481 --Generated Code Combination Identifier
99482  , p_source_3            IN NUMBER
99483 --Depreciation Reserve Account
99484  , p_source_10            IN VARCHAR2
99485 --Generated Offset Code Combination Identifier
99486  , p_source_17            IN NUMBER
99487 --Expense Account Code Combination Identifier
99488  , p_source_29            IN NUMBER
99489 --Default Code Combination Identifier
99490  , p_source_30            IN NUMBER
99491 --Adjustment Type
99492  , p_source_35            IN VARCHAR2
99493 --Transaction Header Identifier
99494  , p_source_36            IN NUMBER
99495 --Adjustment Line Identifier
99496  , p_source_37            IN NUMBER
99497 --Distribution Type Code
99498  , p_source_38            IN VARCHAR2
99499 --Entered Amount
99500  , p_source_39            IN NUMBER
99501 --Currency Code
99502  , p_source_40            IN VARCHAR2
99503 --Source Destination Code
99504  , p_source_42            IN VARCHAR2
99505 )
99506 IS
99507 
99508 l_component_type              VARCHAR2(80);
99509 l_component_code              VARCHAR2(30);
99510 l_component_type_code         VARCHAR2(1);
99511 l_component_appl_id           INTEGER;
99512 l_amb_context_code            VARCHAR2(30);
99513 l_entity_code                 VARCHAR2(30);
99514 l_event_class_code            VARCHAR2(30);
99515 l_ae_header_id                NUMBER;
99516 l_event_type_code             VARCHAR2(30);
99517 l_line_definition_code        VARCHAR2(30);
99518 l_line_definition_owner_code  VARCHAR2(1);
99519 --
99520 -- adr variables
99521 l_segment                     VARCHAR2(30);
99522 l_ccid                        NUMBER;
99523 l_adr_transaction_coa_id      NUMBER;
99524 l_adr_accounting_coa_id       NUMBER;
99525 l_adr_flexfield_segment_code  VARCHAR2(30);
99526 l_adr_flex_value_set_id       NUMBER;
99527 l_adr_value_type_code         VARCHAR2(30);
99528 l_adr_value_combination_id    NUMBER;
99529 l_adr_value_segment_code      VARCHAR2(30);
99530 
99531 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
99532 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
99533 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
99534 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
99535 
99536 -- 4262811 Variables ------------------------------------------------------------------------------------------
99537 l_entered_amt_idx             NUMBER;
99538 l_accted_amt_idx              NUMBER;
99539 l_acc_rev_flag                VARCHAR2(1);
99540 l_accrual_line_num            NUMBER;
99541 l_tmp_amt                     NUMBER;
99542 l_acc_rev_natural_side_code   VARCHAR2(1);
99543 
99544 l_num_entries                 NUMBER;
99545 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
99546 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
99547 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
99548 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
99549 l_recog_line_1                NUMBER;
99550 l_recog_line_2                NUMBER;
99551 
99555 
99552 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
99553 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
99554 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
99556 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
99557 
99558 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
99559 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
99560 
99561 ---------------------------------------------------------------------------------------------------------------
99562 
99563 
99564 --
99565 -- bulk performance
99566 --
99567 l_balance_type_code           VARCHAR2(1);
99568 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
99569 l_log_module                  VARCHAR2(240);
99570 
99571 --
99572 -- Upgrade strategy
99573 --
99574 l_actual_upg_option           VARCHAR2(1);
99575 l_enc_upg_option           VARCHAR2(1);
99576 
99577 --
99578 BEGIN
99579 --
99580 IF g_log_enabled THEN
99581       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_293';
99582 END IF;
99583 --
99584 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
99585 
99586       trace
99587          (p_msg      => 'BEGIN of AcctLineType_293'
99588          ,p_level    => C_LEVEL_PROCEDURE
99589          ,p_module   => l_log_module);
99590 
99591 END IF;
99592 --
99593 l_component_type             := 'AMB_JLT';
99594 l_component_code             := 'FA_RES_TRF_DEST_RES';
99595 l_component_type_code        := 'S';
99596 l_component_appl_id          :=  140;
99597 l_amb_context_code           := 'DEFAULT';
99598 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
99599 l_event_class_code           := 'RESERVE_TRANSFERS';
99600 l_event_type_code            := 'RESERVE_TRANSFERS_ALL';
99601 l_line_definition_owner_code := 'S';
99602 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RESER18';
99603 --
99604 l_balance_type_code          := 'A';
99605 l_segment                     := NULL;
99606 l_ccid                        := NULL;
99607 l_adr_transaction_coa_id      := NULL;
99608 l_adr_accounting_coa_id       := NULL;
99609 l_adr_flexfield_segment_code  := NULL;
99610 l_adr_flex_value_set_id       := NULL;
99611 l_adr_value_type_code         := NULL;
99612 l_adr_value_combination_id    := NULL;
99613 l_adr_value_segment_code      := NULL;
99614 
99615 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
99616 l_bflow_class_code           := '';    -- 4219869 Business Flow
99617 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
99618 l_budgetary_control_flag     := 'N';
99619 
99620 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
99621 l_bflow_applied_to_amt       := NULL; -- 5132302
99622 l_entered_amt_idx            := NULL;          -- 4262811
99623 l_accted_amt_idx             := NULL;          -- 4262811
99624 l_acc_rev_flag               := NULL;          -- 4262811
99625 l_accrual_line_num           := NULL;          -- 4262811
99626 l_tmp_amt                    := NULL;          -- 4262811
99627 --
99628  
99629 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
99630     l_balance_type_code <> 'B' THEN
99631 IF NVL(p_source_35,'
99632 ') =  'RESERVE' AND 
99633 NVL(p_source_42,'
99634 ') =  'DEST'
99635  THEN 
99636 
99637    --
99638    XLA_AE_LINES_PKG.SetNewLine;
99639 
99640    p_balance_type_code          := l_balance_type_code;
99641    -- set the flag so later we will know whether the gain loss line needs to be created
99642    
99643    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
99644      p_actual_flag :='A';
99645    END IF;
99646 
99647    --
99648    -- bulk performance
99649    --
99650    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
99651                                       p_header_num   => 0); -- 4262811
99652    --
99653    -- set accounting line options
99654    --
99655    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
99656            p_natural_side_code          => 'D'
99657          , p_gain_or_loss_flag          => 'N'
99658          , p_gl_transfer_mode_code      => 'S'
99659          , p_acct_entry_type_code       => 'A'
99660          , p_switch_side_flag           => 'Y'
99661          , p_merge_duplicate_code       => 'N'
99662          );
99663    --
99664    l_acc_rev_natural_side_code := 'C';  -- 4262811
99665    -- 
99666    --
99667    -- set accounting line type info
99668    --
99669    xla_ae_lines_pkg.SetAcctLineType
99670       (p_component_type             => l_component_type
99671       ,p_event_type_code            => l_event_type_code
99672       ,p_line_definition_owner_code => l_line_definition_owner_code
99673       ,p_line_definition_code       => l_line_definition_code
99674       ,p_accounting_line_code       => l_component_code
99675       ,p_accounting_line_type_code  => l_component_type_code
99676       ,p_accounting_line_appl_id    => l_component_appl_id
99677       ,p_amb_context_code           => l_amb_context_code
99678       ,p_entity_code                => l_entity_code
99679       ,p_event_class_code           => l_event_class_code);
99680    --
99681    -- set accounting class
99682    --
99683    xla_ae_lines_pkg.SetAcctClass(
99684            p_accounting_class_code  => 'ASSET'
99685          , p_ae_header_id           => l_ae_header_id
99686          );
99687 
99688    --
99689    -- set rounding class
99690    --
99691    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
99692                       'ASSET';
99693 
99694    --
99698    -- bulk performance
99695    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
99696    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
99697    --
99699    --
99700    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
99701 
99702    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
99703       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
99704 
99705    -- 4955764
99706    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
99707       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
99708 
99709    -- 4458381 Public Sector Enh
99710    
99711    --
99712    -- set accounting attributes for the line type
99713    --
99714    l_entered_amt_idx := 4;
99715    l_accted_amt_idx  := 6;
99716    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
99717    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
99718    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
99719    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
99720    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
99721    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
99722    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
99723    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
99724    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
99725    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
99726    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
99727    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
99728    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
99729 
99730    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
99731    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
99732 
99733    ---------------------------------------------------------------------------------------------------------------
99734    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
99735    ---------------------------------------------------------------------------------------------------------------
99736    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
99737 
99738    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
99739    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
99740 
99741    IF xla_accounting_cache_pkg.GetValueChar
99742          (p_source_code         => 'LEDGER_CATEGORY_CODE'
99743          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
99744    AND l_bflow_method_code = 'PRIOR_ENTRY'
99745 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
99746    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
99747          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
99748        )
99749    THEN
99750          xla_ae_lines_pkg.BflowUpgEntry
99751            (p_business_method_code    => l_bflow_method_code
99752            ,p_business_class_code     => l_bflow_class_code
99753            ,p_balance_type            => l_balance_type_code);
99754    ELSE
99755       NULL;
99756 -- No business flow processing for business flow method of NONE.
99757    END IF;
99758 
99759    --
99760    -- call analytical criteria
99761    --
99762    
99763    --
99764    -- call description
99765    --
99766    
99767 xla_ae_lines_pkg.SetLineDescription(
99768    p_ae_header_id => l_ae_header_id
99769   ,p_description  => Description_73 (
99770      p_application_id         => p_application_id
99771    , p_ae_header_id           => l_ae_header_id 
99772 , p_source_1 => p_source_1
99773    )
99774 );
99775 
99776 
99777    --
99778    -- call ADRs
99779    -- Bug 4922099
99780    --
99781    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
99782         (NVL(l_actual_upg_option, 'N') = 'O') OR
99783         (NVL(l_enc_upg_option, 'N') = 'O')
99784       )
99785    THEN
99786    NULL;
99787    --
99788    --
99789    
99790   l_ccid := AcctDerRule_174(
99791            p_application_id           => p_application_id
99792          , p_ae_header_id             => l_ae_header_id 
99793 , p_source_3 => p_source_3
99794 , p_source_17 => p_source_17
99795 , p_source_30 => p_source_30
99796          , x_transaction_coa_id       => l_adr_transaction_coa_id
99797          , x_accounting_coa_id        => l_adr_accounting_coa_id
99798          , x_value_type_code          => l_adr_value_type_code
99799          , p_side                     => 'NA'
99800    );
99801 
99802    xla_ae_lines_pkg.set_ccid(
99803     p_code_combination_id          => l_ccid
99804   , p_value_type_code              => l_adr_value_type_code
99805   , p_transaction_coa_id           => l_adr_transaction_coa_id
99806   , p_accounting_coa_id            => l_adr_accounting_coa_id
99807   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
99808   , p_adr_type_code                => 'S'
99809   , p_component_type               => l_component_type
99810   , p_component_code               => l_component_code
99811   , p_component_type_code          => l_component_type_code
99812   , p_component_appl_id            => l_component_appl_id
99813   , p_amb_context_code             => l_amb_context_code
99814   , p_side                         => 'NA'
99815   );
99816 
99817 
99818    l_segment := AcctDerRule_149(
99819            p_application_id           => p_application_id
99820          , p_ae_header_id             => l_ae_header_id 
99821 , p_source_3 => p_source_3
99825          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
99822 , p_source_10 => p_source_10
99823          , x_transaction_coa_id       => l_adr_transaction_coa_id
99824          , x_accounting_coa_id        => l_adr_accounting_coa_id
99826          , x_flex_value_set_id        => l_adr_flex_value_set_id
99827          , x_value_type_code          => l_adr_value_type_code
99828          , x_value_combination_id     => l_adr_value_combination_id
99829          , x_value_segment_code       => l_adr_value_segment_code
99830          , p_side                     => 'NA'
99831          , p_override_seg_flag        => 'Y'
99832    );
99833 
99834    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
99835 
99836       xla_ae_lines_pkg.set_segment(
99837           p_to_segment_code         => 'GL_ACCOUNT'
99838         , p_segment_value           => l_segment
99839         , p_from_segment_code       => l_adr_value_segment_code
99840         , p_from_combination_id     => l_adr_value_combination_id
99841         , p_value_type_code         => l_adr_value_type_code
99842         , p_transaction_coa_id      => l_adr_transaction_coa_id
99843         , p_accounting_coa_id       => l_adr_accounting_coa_id
99844         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
99845         , p_flex_value_set_id       => l_adr_flex_value_set_id
99846         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
99847         , p_adr_type_code           => 'S'
99848         , p_component_type          => l_component_type
99849         , p_component_code          => l_component_code
99850         , p_component_type_code     => l_component_type_code
99851         , p_component_appl_id       => l_component_appl_id
99852         , p_amb_context_code        => l_amb_context_code
99853         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
99854         , p_event_class_code        => 'RESERVE_TRANSFERS'
99855         , p_side                    => 'NA'
99856         );
99857 
99858   END IF;
99859 
99860    l_segment := AcctDerRule_168(
99861            p_application_id           => p_application_id
99862          , p_ae_header_id             => l_ae_header_id 
99863 , p_source_3 => p_source_3
99864 , p_source_29 => p_source_29
99865          , x_transaction_coa_id       => l_adr_transaction_coa_id
99866          , x_accounting_coa_id        => l_adr_accounting_coa_id
99867          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
99868          , x_flex_value_set_id        => l_adr_flex_value_set_id
99869          , x_value_type_code          => l_adr_value_type_code
99870          , x_value_combination_id     => l_adr_value_combination_id
99871          , x_value_segment_code       => l_adr_value_segment_code
99872          , p_side                     => 'NA'
99873          , p_override_seg_flag        => 'Y'
99874    );
99875 
99876    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
99877 
99878       xla_ae_lines_pkg.set_segment(
99879           p_to_segment_code         => 'GL_BALANCING'
99880         , p_segment_value           => l_segment
99881         , p_from_segment_code       => l_adr_value_segment_code
99882         , p_from_combination_id     => l_adr_value_combination_id
99883         , p_value_type_code         => l_adr_value_type_code
99884         , p_transaction_coa_id      => l_adr_transaction_coa_id
99885         , p_accounting_coa_id       => l_adr_accounting_coa_id
99886         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
99887         , p_flex_value_set_id       => l_adr_flex_value_set_id
99888         , p_adr_code                => 'FA_EXPENSE_ACCT'
99889         , p_adr_type_code           => 'S'
99890         , p_component_type          => l_component_type
99891         , p_component_code          => l_component_code
99892         , p_component_type_code     => l_component_type_code
99893         , p_component_appl_id       => l_component_appl_id
99894         , p_amb_context_code        => l_amb_context_code
99895         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
99896         , p_event_class_code        => 'RESERVE_TRANSFERS'
99897         , p_side                    => 'NA'
99898         );
99899 
99900   END IF;
99901 
99902    --
99903    --
99904    END IF;
99905    --
99906    -- Bug 4922099
99907    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
99908           (NVL(l_enc_upg_option, 'N') = 'O')
99909         ) AND
99910         (l_bflow_method_code = 'PRIOR_ENTRY')
99911       )
99912    THEN
99913       IF
99914       --
99915       1 = 2
99916       --
99917       THEN
99918       xla_accounting_err_pkg.build_message
99919                                     (p_appli_s_name            => 'XLA'
99920                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
99921                                     ,p_token_1                 => 'LINE_NUMBER'
99922                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
99923                                     ,p_token_2                 => 'LINE_TYPE_NAME'
99924                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
99925                                                                              l_component_type
99926                                                                             ,l_component_code
99927                                                                             ,l_component_type_code
99928                                                                             ,l_component_appl_id
99929                                                                             ,l_amb_context_code
99930                                                                             ,l_entity_code
99931                                                                             ,l_event_class_code
99932                                                                            )
99936                                                                           ,p_lookup_code    => l_component_type_code
99933                                     ,p_token_3                 => 'OWNER'
99934                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
99935                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
99937                                                                          )
99938                                     ,p_token_4                 => 'PRODUCT_NAME'
99939                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
99940                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
99941                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
99942                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
99943                                     ,p_ae_header_id            =>  NULL
99944                                        );
99945 
99946         IF (C_LEVEL_ERROR>= g_log_level) THEN
99947                  trace
99948                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
99949                       ,p_level    => C_LEVEL_ERROR
99950                       ,p_module   => l_log_module);
99951         END IF;
99952       END IF;
99953    END IF;
99954    --
99955    --
99956    ------------------------------------------------------------------------------------------------
99957    -- 4219869 Business Flow
99958    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
99959    -- Prior Entry.  Currently, the following code is always generated.
99960    ------------------------------------------------------------------------------------------------
99961    XLA_AE_LINES_PKG.ValidateCurrentLine;
99962 
99963    ------------------------------------------------------------------------------------
99964    -- 4219869 Business Flow
99965    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
99966    ------------------------------------------------------------------------------------
99967    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
99968 
99969    ----------------------------------------------------------------------------------
99970    -- 4219869 Business Flow
99971    -- Update journal entry status -- Need to generate this within IF <condition>
99972    ----------------------------------------------------------------------------------
99973    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
99974          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
99975          ,p_balance_type_code => l_balance_type_code
99976          );
99977 
99978    -------------------------------------------------------------------------------------------
99979    -- 4262811 - Generate the Accrual Reversal lines
99980    -------------------------------------------------------------------------------------------
99981    BEGIN
99982       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
99983                               (g_array_event(p_event_id).array_value_num('header_index'));
99984       IF l_acc_rev_flag IS NULL THEN
99985          l_acc_rev_flag := 'N';
99986       END IF;
99987    EXCEPTION
99988       WHEN OTHERS THEN
99989          l_acc_rev_flag := 'N';
99990    END;
99991    --
99992    IF (l_acc_rev_flag = 'Y') THEN
99993 
99994        -- 4645092  ------------------------------------------------------------------------------
99995        -- To allow MPA report to determine if it should generate report process
99996        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
99997        ------------------------------------------------------------------------------------------
99998 
99999        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
100000        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
100001    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
100002    -- call ADRs
100003    -- Bug 4922099
100004    --
100005    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
100006         (NVL(l_actual_upg_option, 'N') = 'O') OR
100007         (NVL(l_enc_upg_option, 'N') = 'O')
100008       )
100009    THEN
100010    NULL;
100011    --
100012    --
100013    
100014   l_ccid := AcctDerRule_174(
100015            p_application_id           => p_application_id
100016          , p_ae_header_id             => l_ae_header_id 
100017 , p_source_3 => p_source_3
100018 , p_source_17 => p_source_17
100019 , p_source_30 => p_source_30
100020          , x_transaction_coa_id       => l_adr_transaction_coa_id
100021          , x_accounting_coa_id        => l_adr_accounting_coa_id
100022          , x_value_type_code          => l_adr_value_type_code
100023          , p_side                     => 'NA'
100024    );
100025 
100026    xla_ae_lines_pkg.set_ccid(
100027     p_code_combination_id          => l_ccid
100028   , p_value_type_code              => l_adr_value_type_code
100029   , p_transaction_coa_id           => l_adr_transaction_coa_id
100030   , p_accounting_coa_id            => l_adr_accounting_coa_id
100031   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
100032   , p_adr_type_code                => 'S'
100033   , p_component_type               => l_component_type
100034   , p_component_code               => l_component_code
100035   , p_component_type_code          => l_component_type_code
100036   , p_component_appl_id            => l_component_appl_id
100037   , p_amb_context_code             => l_amb_context_code
100038   , p_side                         => 'NA'
100039   );
100040 
100041 
100042    l_segment := AcctDerRule_149(
100043            p_application_id           => p_application_id
100044          , p_ae_header_id             => l_ae_header_id 
100045 , p_source_3 => p_source_3
100049          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
100046 , p_source_10 => p_source_10
100047          , x_transaction_coa_id       => l_adr_transaction_coa_id
100048          , x_accounting_coa_id        => l_adr_accounting_coa_id
100050          , x_flex_value_set_id        => l_adr_flex_value_set_id
100051          , x_value_type_code          => l_adr_value_type_code
100052          , x_value_combination_id     => l_adr_value_combination_id
100053          , x_value_segment_code       => l_adr_value_segment_code
100054          , p_side                     => 'NA'
100055          , p_override_seg_flag        => 'Y'
100056    );
100057 
100058    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
100059 
100060       xla_ae_lines_pkg.set_segment(
100061           p_to_segment_code         => 'GL_ACCOUNT'
100062         , p_segment_value           => l_segment
100063         , p_from_segment_code       => l_adr_value_segment_code
100064         , p_from_combination_id     => l_adr_value_combination_id
100065         , p_value_type_code         => l_adr_value_type_code
100066         , p_transaction_coa_id      => l_adr_transaction_coa_id
100067         , p_accounting_coa_id       => l_adr_accounting_coa_id
100068         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
100069         , p_flex_value_set_id       => l_adr_flex_value_set_id
100070         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
100071         , p_adr_type_code           => 'S'
100072         , p_component_type          => l_component_type
100073         , p_component_code          => l_component_code
100074         , p_component_type_code     => l_component_type_code
100075         , p_component_appl_id       => l_component_appl_id
100076         , p_amb_context_code        => l_amb_context_code
100077         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
100078         , p_event_class_code        => 'RESERVE_TRANSFERS'
100079         , p_side                    => 'NA'
100080         );
100081 
100082   END IF;
100083 
100084    l_segment := AcctDerRule_168(
100085            p_application_id           => p_application_id
100086          , p_ae_header_id             => l_ae_header_id 
100087 , p_source_3 => p_source_3
100088 , p_source_29 => p_source_29
100089          , x_transaction_coa_id       => l_adr_transaction_coa_id
100090          , x_accounting_coa_id        => l_adr_accounting_coa_id
100091          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
100092          , x_flex_value_set_id        => l_adr_flex_value_set_id
100093          , x_value_type_code          => l_adr_value_type_code
100094          , x_value_combination_id     => l_adr_value_combination_id
100095          , x_value_segment_code       => l_adr_value_segment_code
100096          , p_side                     => 'NA'
100097          , p_override_seg_flag        => 'Y'
100098    );
100099 
100100    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
100101 
100102       xla_ae_lines_pkg.set_segment(
100103           p_to_segment_code         => 'GL_BALANCING'
100104         , p_segment_value           => l_segment
100105         , p_from_segment_code       => l_adr_value_segment_code
100106         , p_from_combination_id     => l_adr_value_combination_id
100107         , p_value_type_code         => l_adr_value_type_code
100108         , p_transaction_coa_id      => l_adr_transaction_coa_id
100109         , p_accounting_coa_id       => l_adr_accounting_coa_id
100110         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
100111         , p_flex_value_set_id       => l_adr_flex_value_set_id
100112         , p_adr_code                => 'FA_EXPENSE_ACCT'
100113         , p_adr_type_code           => 'S'
100114         , p_component_type          => l_component_type
100115         , p_component_code          => l_component_code
100116         , p_component_type_code     => l_component_type_code
100117         , p_component_appl_id       => l_component_appl_id
100118         , p_amb_context_code        => l_amb_context_code
100119         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
100120         , p_event_class_code        => 'RESERVE_TRANSFERS'
100121         , p_side                    => 'NA'
100122         );
100123 
100124   END IF;
100125 
100126    --
100127    --
100128    END IF;
100129 
100130        --
100131        -- Update the line information that should be overwritten
100132        --
100133        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
100134                                          p_header_num   => 1);
100135        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
100136 
100137        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
100138 
100139        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
100140           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
100141        END IF;
100142 
100143       --
100144       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
100145       --
100146       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
100147           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
100148       ELSE
100149           ---------------------------------------------------------------------------------------------------
100150           -- 4262811a Switch Sign
100151           ---------------------------------------------------------------------------------------------------
100152           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
100153           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
100154                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
100155           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
100159                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
100156                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
100157           -- 5132302
100158           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
100160 
100161       END IF;
100162 
100163       -- 4955764
100164       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
100165       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
100166 
100167 
100168       XLA_AE_LINES_PKG.ValidateCurrentLine;
100169       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
100170 
100171       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
100172                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
100173                ,p_balance_type_code => l_balance_type_code);
100174 
100175    END IF;
100176 
100177    -----------------------------------------------------------------------------------------
100178    -- 4262811 Multiperiod Accounting
100179    -----------------------------------------------------------------------------------------
100180      -- No MPA option is assigned.
100181 
100182 
100183 END IF;
100184 END IF;
100185 --
100186 
100187 --
100188 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
100189    trace
100190       (p_msg      => 'END of AcctLineType_293'
100191       ,p_level    => C_LEVEL_PROCEDURE
100192       ,p_module   => l_log_module);
100193 END IF;
100194 --
100195 EXCEPTION
100196   WHEN xla_exceptions_pkg.application_exception THEN
100197       RAISE;
100198   WHEN OTHERS THEN
100199        xla_exceptions_pkg.raise_message
100200            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_293');
100201 END AcctLineType_293;
100202 --
100203 
100204 ---------------------------------------
100205 --
100206 -- PRIVATE FUNCTION
100207 --         AcctLineType_294
100208 --
100209 ---------------------------------------
100210 PROCEDURE AcctLineType_294 (
100211   p_application_id        IN NUMBER
100212  ,p_event_id              IN NUMBER
100213  ,p_calculate_acctd_flag  IN VARCHAR2
100214  ,p_calculate_g_l_flag    IN VARCHAR2
100215  ,p_actual_flag           IN OUT VARCHAR2
100216  ,p_balance_type_code     OUT VARCHAR2
100217  ,p_gain_or_loss_ref      OUT VARCHAR2
100218  
100219 --Period Close Date
100220  , p_source_1            IN DATE
100221 --Generated Code Combination Identifier
100222  , p_source_3            IN NUMBER
100223 --Depreciation Reserve Account
100224  , p_source_10            IN VARCHAR2
100225 --Generated Offset Code Combination Identifier
100226  , p_source_17            IN NUMBER
100227 --Expense Account Code Combination Identifier
100228  , p_source_29            IN NUMBER
100229 --Default Code Combination Identifier
100230  , p_source_30            IN NUMBER
100231 --Adjustment Type
100232  , p_source_35            IN VARCHAR2
100233 --Transaction Header Identifier
100234  , p_source_36            IN NUMBER
100235 --Adjustment Line Identifier
100236  , p_source_37            IN NUMBER
100237 --Distribution Type Code
100238  , p_source_38            IN VARCHAR2
100239 --Entered Amount
100240  , p_source_39            IN NUMBER
100241 --Currency Code
100242  , p_source_40            IN VARCHAR2
100243 --Source Destination Code
100244  , p_source_42            IN VARCHAR2
100245 )
100246 IS
100247 
100248 l_component_type              VARCHAR2(80);
100249 l_component_code              VARCHAR2(30);
100250 l_component_type_code         VARCHAR2(1);
100251 l_component_appl_id           INTEGER;
100252 l_amb_context_code            VARCHAR2(30);
100253 l_entity_code                 VARCHAR2(30);
100254 l_event_class_code            VARCHAR2(30);
100255 l_ae_header_id                NUMBER;
100256 l_event_type_code             VARCHAR2(30);
100257 l_line_definition_code        VARCHAR2(30);
100258 l_line_definition_owner_code  VARCHAR2(1);
100259 --
100260 -- adr variables
100261 l_segment                     VARCHAR2(30);
100262 l_ccid                        NUMBER;
100263 l_adr_transaction_coa_id      NUMBER;
100264 l_adr_accounting_coa_id       NUMBER;
100265 l_adr_flexfield_segment_code  VARCHAR2(30);
100266 l_adr_flex_value_set_id       NUMBER;
100267 l_adr_value_type_code         VARCHAR2(30);
100268 l_adr_value_combination_id    NUMBER;
100269 l_adr_value_segment_code      VARCHAR2(30);
100270 
100271 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
100272 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
100273 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
100274 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
100275 
100276 -- 4262811 Variables ------------------------------------------------------------------------------------------
100277 l_entered_amt_idx             NUMBER;
100278 l_accted_amt_idx              NUMBER;
100279 l_acc_rev_flag                VARCHAR2(1);
100280 l_accrual_line_num            NUMBER;
100281 l_tmp_amt                     NUMBER;
100282 l_acc_rev_natural_side_code   VARCHAR2(1);
100283 
100284 l_num_entries                 NUMBER;
100285 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
100286 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
100287 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
100288 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
100289 l_recog_line_1                NUMBER;
100290 l_recog_line_2                NUMBER;
100291 
100292 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
100293 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
100294 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
100295 
100299 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
100296 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
100297 
100298 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
100300 
100301 ---------------------------------------------------------------------------------------------------------------
100302 
100303 
100304 --
100305 -- bulk performance
100306 --
100307 l_balance_type_code           VARCHAR2(1);
100308 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
100309 l_log_module                  VARCHAR2(240);
100310 
100311 --
100312 -- Upgrade strategy
100313 --
100314 l_actual_upg_option           VARCHAR2(1);
100315 l_enc_upg_option           VARCHAR2(1);
100316 
100317 --
100318 BEGIN
100319 --
100320 IF g_log_enabled THEN
100321       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_294';
100322 END IF;
100323 --
100324 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
100325 
100326       trace
100327          (p_msg      => 'BEGIN of AcctLineType_294'
100328          ,p_level    => C_LEVEL_PROCEDURE
100329          ,p_module   => l_log_module);
100330 
100331 END IF;
100332 --
100333 l_component_type             := 'AMB_JLT';
100334 l_component_code             := 'FA_RES_TRF_SOURCE_RES';
100335 l_component_type_code        := 'S';
100336 l_component_appl_id          :=  140;
100337 l_amb_context_code           := 'DEFAULT';
100338 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
100339 l_event_class_code           := 'RESERVE_TRANSFERS';
100340 l_event_type_code            := 'RESERVE_TRANSFERS_ALL';
100341 l_line_definition_owner_code := 'S';
100342 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RESER18';
100343 --
100344 l_balance_type_code          := 'A';
100345 l_segment                     := NULL;
100346 l_ccid                        := NULL;
100347 l_adr_transaction_coa_id      := NULL;
100348 l_adr_accounting_coa_id       := NULL;
100349 l_adr_flexfield_segment_code  := NULL;
100350 l_adr_flex_value_set_id       := NULL;
100351 l_adr_value_type_code         := NULL;
100352 l_adr_value_combination_id    := NULL;
100353 l_adr_value_segment_code      := NULL;
100354 
100355 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
100356 l_bflow_class_code           := '';    -- 4219869 Business Flow
100357 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
100358 l_budgetary_control_flag     := 'N';
100359 
100360 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
100361 l_bflow_applied_to_amt       := NULL; -- 5132302
100362 l_entered_amt_idx            := NULL;          -- 4262811
100363 l_accted_amt_idx             := NULL;          -- 4262811
100364 l_acc_rev_flag               := NULL;          -- 4262811
100365 l_accrual_line_num           := NULL;          -- 4262811
100366 l_tmp_amt                    := NULL;          -- 4262811
100367 --
100368  
100369 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
100370     l_balance_type_code <> 'B' THEN
100371 IF NVL(p_source_35,'
100372 ') =  'RESERVE' AND 
100373 NVL(p_source_42,'
100374 ') =  'SOURCE'
100375  THEN 
100376 
100377    --
100378    XLA_AE_LINES_PKG.SetNewLine;
100379 
100380    p_balance_type_code          := l_balance_type_code;
100381    -- set the flag so later we will know whether the gain loss line needs to be created
100382    
100383    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
100384      p_actual_flag :='A';
100385    END IF;
100386 
100387    --
100388    -- bulk performance
100389    --
100390    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
100391                                       p_header_num   => 0); -- 4262811
100392    --
100393    -- set accounting line options
100394    --
100395    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
100396            p_natural_side_code          => 'D'
100397          , p_gain_or_loss_flag          => 'N'
100398          , p_gl_transfer_mode_code      => 'S'
100399          , p_acct_entry_type_code       => 'A'
100400          , p_switch_side_flag           => 'Y'
100401          , p_merge_duplicate_code       => 'N'
100402          );
100403    --
100404    l_acc_rev_natural_side_code := 'C';  -- 4262811
100405    -- 
100406    --
100407    -- set accounting line type info
100408    --
100409    xla_ae_lines_pkg.SetAcctLineType
100410       (p_component_type             => l_component_type
100411       ,p_event_type_code            => l_event_type_code
100412       ,p_line_definition_owner_code => l_line_definition_owner_code
100413       ,p_line_definition_code       => l_line_definition_code
100414       ,p_accounting_line_code       => l_component_code
100415       ,p_accounting_line_type_code  => l_component_type_code
100416       ,p_accounting_line_appl_id    => l_component_appl_id
100417       ,p_amb_context_code           => l_amb_context_code
100418       ,p_entity_code                => l_entity_code
100419       ,p_event_class_code           => l_event_class_code);
100420    --
100421    -- set accounting class
100422    --
100423    xla_ae_lines_pkg.SetAcctClass(
100424            p_accounting_class_code  => 'ASSET'
100425          , p_ae_header_id           => l_ae_header_id
100426          );
100427 
100428    --
100429    -- set rounding class
100430    --
100431    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
100432                       'ASSET';
100433 
100434    --
100435    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
100436    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
100437    --
100438    -- bulk performance
100439    --
100443       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
100440    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
100441 
100442    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
100444 
100445    -- 4955764
100446    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
100447       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
100448 
100449    -- 4458381 Public Sector Enh
100450    
100451    --
100452    -- set accounting attributes for the line type
100453    --
100454    l_entered_amt_idx := 4;
100455    l_accted_amt_idx  := 6;
100456    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
100457    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
100458    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
100459    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
100460    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
100461    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
100462    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
100463    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
100464    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
100465    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
100466    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
100467    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
100468    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
100469 
100470    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
100471    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
100472 
100473    ---------------------------------------------------------------------------------------------------------------
100474    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
100475    ---------------------------------------------------------------------------------------------------------------
100476    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
100477 
100478    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
100479    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
100480 
100481    IF xla_accounting_cache_pkg.GetValueChar
100482          (p_source_code         => 'LEDGER_CATEGORY_CODE'
100483          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
100484    AND l_bflow_method_code = 'PRIOR_ENTRY'
100485 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
100486    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
100487          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
100488        )
100489    THEN
100490          xla_ae_lines_pkg.BflowUpgEntry
100491            (p_business_method_code    => l_bflow_method_code
100492            ,p_business_class_code     => l_bflow_class_code
100493            ,p_balance_type            => l_balance_type_code);
100494    ELSE
100495       NULL;
100496 -- No business flow processing for business flow method of NONE.
100497    END IF;
100498 
100499    --
100500    -- call analytical criteria
100501    --
100502    
100503    --
100504    -- call description
100505    --
100506    
100507 xla_ae_lines_pkg.SetLineDescription(
100508    p_ae_header_id => l_ae_header_id
100509   ,p_description  => Description_73 (
100510      p_application_id         => p_application_id
100511    , p_ae_header_id           => l_ae_header_id 
100512 , p_source_1 => p_source_1
100513    )
100514 );
100515 
100516 
100517    --
100518    -- call ADRs
100519    -- Bug 4922099
100520    --
100521    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
100522         (NVL(l_actual_upg_option, 'N') = 'O') OR
100523         (NVL(l_enc_upg_option, 'N') = 'O')
100524       )
100525    THEN
100526    NULL;
100527    --
100528    --
100529    
100530   l_ccid := AcctDerRule_174(
100531            p_application_id           => p_application_id
100532          , p_ae_header_id             => l_ae_header_id 
100533 , p_source_3 => p_source_3
100534 , p_source_17 => p_source_17
100535 , p_source_30 => p_source_30
100536          , x_transaction_coa_id       => l_adr_transaction_coa_id
100537          , x_accounting_coa_id        => l_adr_accounting_coa_id
100538          , x_value_type_code          => l_adr_value_type_code
100539          , p_side                     => 'NA'
100540    );
100541 
100542    xla_ae_lines_pkg.set_ccid(
100543     p_code_combination_id          => l_ccid
100544   , p_value_type_code              => l_adr_value_type_code
100545   , p_transaction_coa_id           => l_adr_transaction_coa_id
100546   , p_accounting_coa_id            => l_adr_accounting_coa_id
100547   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
100548   , p_adr_type_code                => 'S'
100549   , p_component_type               => l_component_type
100550   , p_component_code               => l_component_code
100551   , p_component_type_code          => l_component_type_code
100552   , p_component_appl_id            => l_component_appl_id
100553   , p_amb_context_code             => l_amb_context_code
100554   , p_side                         => 'NA'
100555   );
100556 
100557 
100558    l_segment := AcctDerRule_149(
100559            p_application_id           => p_application_id
100560          , p_ae_header_id             => l_ae_header_id 
100561 , p_source_3 => p_source_3
100562 , p_source_10 => p_source_10
100563          , x_transaction_coa_id       => l_adr_transaction_coa_id
100564          , x_accounting_coa_id        => l_adr_accounting_coa_id
100565          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
100569          , x_value_segment_code       => l_adr_value_segment_code
100566          , x_flex_value_set_id        => l_adr_flex_value_set_id
100567          , x_value_type_code          => l_adr_value_type_code
100568          , x_value_combination_id     => l_adr_value_combination_id
100570          , p_side                     => 'NA'
100571          , p_override_seg_flag        => 'Y'
100572    );
100573 
100574    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
100575 
100576       xla_ae_lines_pkg.set_segment(
100577           p_to_segment_code         => 'GL_ACCOUNT'
100578         , p_segment_value           => l_segment
100579         , p_from_segment_code       => l_adr_value_segment_code
100580         , p_from_combination_id     => l_adr_value_combination_id
100581         , p_value_type_code         => l_adr_value_type_code
100582         , p_transaction_coa_id      => l_adr_transaction_coa_id
100583         , p_accounting_coa_id       => l_adr_accounting_coa_id
100584         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
100585         , p_flex_value_set_id       => l_adr_flex_value_set_id
100586         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
100587         , p_adr_type_code           => 'S'
100588         , p_component_type          => l_component_type
100589         , p_component_code          => l_component_code
100590         , p_component_type_code     => l_component_type_code
100591         , p_component_appl_id       => l_component_appl_id
100592         , p_amb_context_code        => l_amb_context_code
100593         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
100594         , p_event_class_code        => 'RESERVE_TRANSFERS'
100595         , p_side                    => 'NA'
100596         );
100597 
100598   END IF;
100599 
100600    l_segment := AcctDerRule_168(
100601            p_application_id           => p_application_id
100602          , p_ae_header_id             => l_ae_header_id 
100603 , p_source_3 => p_source_3
100604 , p_source_29 => p_source_29
100605          , x_transaction_coa_id       => l_adr_transaction_coa_id
100606          , x_accounting_coa_id        => l_adr_accounting_coa_id
100607          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
100608          , x_flex_value_set_id        => l_adr_flex_value_set_id
100609          , x_value_type_code          => l_adr_value_type_code
100610          , x_value_combination_id     => l_adr_value_combination_id
100611          , x_value_segment_code       => l_adr_value_segment_code
100612          , p_side                     => 'NA'
100613          , p_override_seg_flag        => 'Y'
100614    );
100615 
100616    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
100617 
100618       xla_ae_lines_pkg.set_segment(
100619           p_to_segment_code         => 'GL_BALANCING'
100620         , p_segment_value           => l_segment
100621         , p_from_segment_code       => l_adr_value_segment_code
100622         , p_from_combination_id     => l_adr_value_combination_id
100623         , p_value_type_code         => l_adr_value_type_code
100624         , p_transaction_coa_id      => l_adr_transaction_coa_id
100625         , p_accounting_coa_id       => l_adr_accounting_coa_id
100626         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
100627         , p_flex_value_set_id       => l_adr_flex_value_set_id
100628         , p_adr_code                => 'FA_EXPENSE_ACCT'
100629         , p_adr_type_code           => 'S'
100630         , p_component_type          => l_component_type
100631         , p_component_code          => l_component_code
100632         , p_component_type_code     => l_component_type_code
100633         , p_component_appl_id       => l_component_appl_id
100634         , p_amb_context_code        => l_amb_context_code
100635         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
100636         , p_event_class_code        => 'RESERVE_TRANSFERS'
100637         , p_side                    => 'NA'
100638         );
100639 
100640   END IF;
100641 
100642    --
100643    --
100644    END IF;
100645    --
100646    -- Bug 4922099
100647    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
100648           (NVL(l_enc_upg_option, 'N') = 'O')
100649         ) AND
100650         (l_bflow_method_code = 'PRIOR_ENTRY')
100651       )
100652    THEN
100653       IF
100654       --
100655       1 = 2
100656       --
100657       THEN
100658       xla_accounting_err_pkg.build_message
100659                                     (p_appli_s_name            => 'XLA'
100660                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
100661                                     ,p_token_1                 => 'LINE_NUMBER'
100662                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
100663                                     ,p_token_2                 => 'LINE_TYPE_NAME'
100664                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
100665                                                                              l_component_type
100666                                                                             ,l_component_code
100667                                                                             ,l_component_type_code
100668                                                                             ,l_component_appl_id
100669                                                                             ,l_amb_context_code
100670                                                                             ,l_entity_code
100671                                                                             ,l_event_class_code
100672                                                                            )
100673                                     ,p_token_3                 => 'OWNER'
100674                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
100675                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
100679                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
100676                                                                           ,p_lookup_code    => l_component_type_code
100677                                                                          )
100678                                     ,p_token_4                 => 'PRODUCT_NAME'
100680                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
100681                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
100682                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
100683                                     ,p_ae_header_id            =>  NULL
100684                                        );
100685 
100686         IF (C_LEVEL_ERROR>= g_log_level) THEN
100687                  trace
100688                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
100689                       ,p_level    => C_LEVEL_ERROR
100690                       ,p_module   => l_log_module);
100691         END IF;
100692       END IF;
100693    END IF;
100694    --
100695    --
100696    ------------------------------------------------------------------------------------------------
100697    -- 4219869 Business Flow
100698    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
100699    -- Prior Entry.  Currently, the following code is always generated.
100700    ------------------------------------------------------------------------------------------------
100701    XLA_AE_LINES_PKG.ValidateCurrentLine;
100702 
100703    ------------------------------------------------------------------------------------
100704    -- 4219869 Business Flow
100705    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
100706    ------------------------------------------------------------------------------------
100707    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
100708 
100709    ----------------------------------------------------------------------------------
100710    -- 4219869 Business Flow
100711    -- Update journal entry status -- Need to generate this within IF <condition>
100712    ----------------------------------------------------------------------------------
100713    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
100714          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
100715          ,p_balance_type_code => l_balance_type_code
100716          );
100717 
100718    -------------------------------------------------------------------------------------------
100719    -- 4262811 - Generate the Accrual Reversal lines
100720    -------------------------------------------------------------------------------------------
100721    BEGIN
100722       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
100723                               (g_array_event(p_event_id).array_value_num('header_index'));
100724       IF l_acc_rev_flag IS NULL THEN
100725          l_acc_rev_flag := 'N';
100726       END IF;
100727    EXCEPTION
100728       WHEN OTHERS THEN
100729          l_acc_rev_flag := 'N';
100730    END;
100731    --
100732    IF (l_acc_rev_flag = 'Y') THEN
100733 
100734        -- 4645092  ------------------------------------------------------------------------------
100735        -- To allow MPA report to determine if it should generate report process
100736        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
100737        ------------------------------------------------------------------------------------------
100738 
100739        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
100740        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
100741    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
100742    -- call ADRs
100743    -- Bug 4922099
100744    --
100745    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
100746         (NVL(l_actual_upg_option, 'N') = 'O') OR
100747         (NVL(l_enc_upg_option, 'N') = 'O')
100748       )
100749    THEN
100750    NULL;
100751    --
100752    --
100753    
100754   l_ccid := AcctDerRule_174(
100755            p_application_id           => p_application_id
100756          , p_ae_header_id             => l_ae_header_id 
100757 , p_source_3 => p_source_3
100758 , p_source_17 => p_source_17
100759 , p_source_30 => p_source_30
100760          , x_transaction_coa_id       => l_adr_transaction_coa_id
100761          , x_accounting_coa_id        => l_adr_accounting_coa_id
100762          , x_value_type_code          => l_adr_value_type_code
100763          , p_side                     => 'NA'
100764    );
100765 
100766    xla_ae_lines_pkg.set_ccid(
100767     p_code_combination_id          => l_ccid
100768   , p_value_type_code              => l_adr_value_type_code
100769   , p_transaction_coa_id           => l_adr_transaction_coa_id
100770   , p_accounting_coa_id            => l_adr_accounting_coa_id
100771   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
100772   , p_adr_type_code                => 'S'
100773   , p_component_type               => l_component_type
100774   , p_component_code               => l_component_code
100775   , p_component_type_code          => l_component_type_code
100776   , p_component_appl_id            => l_component_appl_id
100777   , p_amb_context_code             => l_amb_context_code
100778   , p_side                         => 'NA'
100779   );
100780 
100781 
100782    l_segment := AcctDerRule_149(
100783            p_application_id           => p_application_id
100784          , p_ae_header_id             => l_ae_header_id 
100785 , p_source_3 => p_source_3
100786 , p_source_10 => p_source_10
100787          , x_transaction_coa_id       => l_adr_transaction_coa_id
100788          , x_accounting_coa_id        => l_adr_accounting_coa_id
100789          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
100793          , x_value_segment_code       => l_adr_value_segment_code
100790          , x_flex_value_set_id        => l_adr_flex_value_set_id
100791          , x_value_type_code          => l_adr_value_type_code
100792          , x_value_combination_id     => l_adr_value_combination_id
100794          , p_side                     => 'NA'
100795          , p_override_seg_flag        => 'Y'
100796    );
100797 
100798    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
100799 
100800       xla_ae_lines_pkg.set_segment(
100801           p_to_segment_code         => 'GL_ACCOUNT'
100802         , p_segment_value           => l_segment
100803         , p_from_segment_code       => l_adr_value_segment_code
100804         , p_from_combination_id     => l_adr_value_combination_id
100805         , p_value_type_code         => l_adr_value_type_code
100806         , p_transaction_coa_id      => l_adr_transaction_coa_id
100807         , p_accounting_coa_id       => l_adr_accounting_coa_id
100808         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
100809         , p_flex_value_set_id       => l_adr_flex_value_set_id
100810         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
100811         , p_adr_type_code           => 'S'
100812         , p_component_type          => l_component_type
100813         , p_component_code          => l_component_code
100814         , p_component_type_code     => l_component_type_code
100815         , p_component_appl_id       => l_component_appl_id
100816         , p_amb_context_code        => l_amb_context_code
100817         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
100818         , p_event_class_code        => 'RESERVE_TRANSFERS'
100819         , p_side                    => 'NA'
100820         );
100821 
100822   END IF;
100823 
100824    l_segment := AcctDerRule_168(
100825            p_application_id           => p_application_id
100826          , p_ae_header_id             => l_ae_header_id 
100827 , p_source_3 => p_source_3
100828 , p_source_29 => p_source_29
100829          , x_transaction_coa_id       => l_adr_transaction_coa_id
100830          , x_accounting_coa_id        => l_adr_accounting_coa_id
100831          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
100832          , x_flex_value_set_id        => l_adr_flex_value_set_id
100833          , x_value_type_code          => l_adr_value_type_code
100834          , x_value_combination_id     => l_adr_value_combination_id
100835          , x_value_segment_code       => l_adr_value_segment_code
100836          , p_side                     => 'NA'
100837          , p_override_seg_flag        => 'Y'
100838    );
100839 
100840    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
100841 
100842       xla_ae_lines_pkg.set_segment(
100843           p_to_segment_code         => 'GL_BALANCING'
100844         , p_segment_value           => l_segment
100845         , p_from_segment_code       => l_adr_value_segment_code
100846         , p_from_combination_id     => l_adr_value_combination_id
100847         , p_value_type_code         => l_adr_value_type_code
100848         , p_transaction_coa_id      => l_adr_transaction_coa_id
100849         , p_accounting_coa_id       => l_adr_accounting_coa_id
100850         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
100851         , p_flex_value_set_id       => l_adr_flex_value_set_id
100852         , p_adr_code                => 'FA_EXPENSE_ACCT'
100853         , p_adr_type_code           => 'S'
100854         , p_component_type          => l_component_type
100855         , p_component_code          => l_component_code
100856         , p_component_type_code     => l_component_type_code
100857         , p_component_appl_id       => l_component_appl_id
100858         , p_amb_context_code        => l_amb_context_code
100859         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
100860         , p_event_class_code        => 'RESERVE_TRANSFERS'
100861         , p_side                    => 'NA'
100862         );
100863 
100864   END IF;
100865 
100866    --
100867    --
100868    END IF;
100869 
100870        --
100871        -- Update the line information that should be overwritten
100872        --
100873        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
100874                                          p_header_num   => 1);
100875        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
100876 
100877        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
100878 
100879        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
100880           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
100881        END IF;
100882 
100883       --
100884       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
100885       --
100886       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
100887           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
100888       ELSE
100889           ---------------------------------------------------------------------------------------------------
100890           -- 4262811a Switch Sign
100891           ---------------------------------------------------------------------------------------------------
100892           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
100893           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
100894                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
100895           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
100896                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
100897           -- 5132302
100898           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
100902 
100899                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
100900 
100901       END IF;
100903       -- 4955764
100904       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
100905       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
100906 
100907 
100908       XLA_AE_LINES_PKG.ValidateCurrentLine;
100909       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
100910 
100911       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
100912                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
100913                ,p_balance_type_code => l_balance_type_code);
100914 
100915    END IF;
100916 
100917    -----------------------------------------------------------------------------------------
100918    -- 4262811 Multiperiod Accounting
100919    -----------------------------------------------------------------------------------------
100920      -- No MPA option is assigned.
100921 
100922 
100923 END IF;
100924 END IF;
100925 --
100926 
100927 --
100928 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
100929    trace
100930       (p_msg      => 'END of AcctLineType_294'
100931       ,p_level    => C_LEVEL_PROCEDURE
100932       ,p_module   => l_log_module);
100933 END IF;
100934 --
100935 EXCEPTION
100936   WHEN xla_exceptions_pkg.application_exception THEN
100937       RAISE;
100938   WHEN OTHERS THEN
100939        xla_exceptions_pkg.raise_message
100940            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_294');
100941 END AcctLineType_294;
100942 --
100943 
100944 ---------------------------------------
100945 --
100946 -- PRIVATE FUNCTION
100947 --         AcctLineType_295
100948 --
100949 ---------------------------------------
100950 PROCEDURE AcctLineType_295 (
100951   p_application_id        IN NUMBER
100952  ,p_event_id              IN NUMBER
100953  ,p_calculate_acctd_flag  IN VARCHAR2
100954  ,p_calculate_g_l_flag    IN VARCHAR2
100955  ,p_actual_flag           IN OUT VARCHAR2
100956  ,p_balance_type_code     OUT VARCHAR2
100957  ,p_gain_or_loss_ref      OUT VARCHAR2
100958  
100959 --Period Close Date
100960  , p_source_1            IN DATE
100961 --Bonus Depreciation Expense Account
100962  , p_source_2            IN VARCHAR2
100963 --Generated Code Combination Identifier
100964  , p_source_3            IN NUMBER
100965 --Expense Account Code Combination Identifier
100966  , p_source_29            IN NUMBER
100967 --Adjustment Type
100968  , p_source_35            IN VARCHAR2
100969 --Transaction Header Identifier
100970  , p_source_36            IN NUMBER
100971 --Adjustment Line Identifier
100972  , p_source_37            IN NUMBER
100973 --Distribution Type Code
100974  , p_source_38            IN VARCHAR2
100975 --Entered Amount
100976  , p_source_39            IN NUMBER
100977 --Currency Code
100978  , p_source_40            IN VARCHAR2
100979 )
100980 IS
100981 
100982 l_component_type              VARCHAR2(80);
100983 l_component_code              VARCHAR2(30);
100984 l_component_type_code         VARCHAR2(1);
100985 l_component_appl_id           INTEGER;
100986 l_amb_context_code            VARCHAR2(30);
100987 l_entity_code                 VARCHAR2(30);
100988 l_event_class_code            VARCHAR2(30);
100989 l_ae_header_id                NUMBER;
100990 l_event_type_code             VARCHAR2(30);
100991 l_line_definition_code        VARCHAR2(30);
100992 l_line_definition_owner_code  VARCHAR2(1);
100993 --
100994 -- adr variables
100995 l_segment                     VARCHAR2(30);
100996 l_ccid                        NUMBER;
100997 l_adr_transaction_coa_id      NUMBER;
100998 l_adr_accounting_coa_id       NUMBER;
100999 l_adr_flexfield_segment_code  VARCHAR2(30);
101000 l_adr_flex_value_set_id       NUMBER;
101001 l_adr_value_type_code         VARCHAR2(30);
101002 l_adr_value_combination_id    NUMBER;
101003 l_adr_value_segment_code      VARCHAR2(30);
101004 
101005 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
101006 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
101007 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
101008 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
101009 
101010 -- 4262811 Variables ------------------------------------------------------------------------------------------
101011 l_entered_amt_idx             NUMBER;
101012 l_accted_amt_idx              NUMBER;
101013 l_acc_rev_flag                VARCHAR2(1);
101014 l_accrual_line_num            NUMBER;
101015 l_tmp_amt                     NUMBER;
101016 l_acc_rev_natural_side_code   VARCHAR2(1);
101017 
101018 l_num_entries                 NUMBER;
101019 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
101020 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
101021 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
101022 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
101023 l_recog_line_1                NUMBER;
101024 l_recog_line_2                NUMBER;
101025 
101026 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
101027 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
101028 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
101029 
101030 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
101031 
101032 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
101033 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
101034 
101035 ---------------------------------------------------------------------------------------------------------------
101036 
101037 
101038 --
101039 -- bulk performance
101040 --
101044 
101041 l_balance_type_code           VARCHAR2(1);
101042 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
101043 l_log_module                  VARCHAR2(240);
101045 --
101046 -- Upgrade strategy
101047 --
101048 l_actual_upg_option           VARCHAR2(1);
101049 l_enc_upg_option           VARCHAR2(1);
101050 
101051 --
101052 BEGIN
101053 --
101054 IF g_log_enabled THEN
101055       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_295';
101056 END IF;
101057 --
101058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
101059 
101060       trace
101061          (p_msg      => 'BEGIN of AcctLineType_295'
101062          ,p_level    => C_LEVEL_PROCEDURE
101063          ,p_module   => l_log_module);
101064 
101065 END IF;
101066 --
101067 l_component_type             := 'AMB_JLT';
101068 l_component_code             := 'FA_RETIREMENT_BONUS_DEPRN_EXP';
101069 l_component_type_code        := 'S';
101070 l_component_appl_id          :=  140;
101071 l_amb_context_code           := 'DEFAULT';
101072 l_entity_code                := 'TRANSACTIONS';
101073 l_event_class_code           := 'RETIREMENTS';
101074 l_event_type_code            := 'RETIREMENTS';
101075 l_line_definition_owner_code := 'S';
101076 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
101077 --
101078 l_balance_type_code          := 'A';
101079 l_segment                     := NULL;
101080 l_ccid                        := NULL;
101081 l_adr_transaction_coa_id      := NULL;
101082 l_adr_accounting_coa_id       := NULL;
101083 l_adr_flexfield_segment_code  := NULL;
101084 l_adr_flex_value_set_id       := NULL;
101085 l_adr_value_type_code         := NULL;
101086 l_adr_value_combination_id    := NULL;
101087 l_adr_value_segment_code      := NULL;
101088 
101089 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
101090 l_bflow_class_code           := '';    -- 4219869 Business Flow
101091 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
101092 l_budgetary_control_flag     := 'N';
101093 
101094 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
101095 l_bflow_applied_to_amt       := NULL; -- 5132302
101096 l_entered_amt_idx            := NULL;          -- 4262811
101097 l_accted_amt_idx             := NULL;          -- 4262811
101098 l_acc_rev_flag               := NULL;          -- 4262811
101099 l_accrual_line_num           := NULL;          -- 4262811
101100 l_tmp_amt                    := NULL;          -- 4262811
101101 --
101102  
101103 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
101104     l_balance_type_code <> 'B' THEN
101105 IF NVL(p_source_35,'
101106 ') =  'BONUS EXPENSE'
101107  THEN 
101108 
101109    --
101110    XLA_AE_LINES_PKG.SetNewLine;
101111 
101112    p_balance_type_code          := l_balance_type_code;
101113    -- set the flag so later we will know whether the gain loss line needs to be created
101114    
101115    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
101116      p_actual_flag :='A';
101117    END IF;
101118 
101119    --
101120    -- bulk performance
101121    --
101122    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
101123                                       p_header_num   => 0); -- 4262811
101124    --
101125    -- set accounting line options
101126    --
101127    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
101128            p_natural_side_code          => 'C'
101129          , p_gain_or_loss_flag          => 'N'
101130          , p_gl_transfer_mode_code      => 'S'
101131          , p_acct_entry_type_code       => 'A'
101132          , p_switch_side_flag           => 'Y'
101133          , p_merge_duplicate_code       => 'N'
101134          );
101135    --
101136    l_acc_rev_natural_side_code := 'D';  -- 4262811
101137    -- 
101138    --
101139    -- set accounting line type info
101140    --
101141    xla_ae_lines_pkg.SetAcctLineType
101142       (p_component_type             => l_component_type
101143       ,p_event_type_code            => l_event_type_code
101144       ,p_line_definition_owner_code => l_line_definition_owner_code
101145       ,p_line_definition_code       => l_line_definition_code
101146       ,p_accounting_line_code       => l_component_code
101147       ,p_accounting_line_type_code  => l_component_type_code
101148       ,p_accounting_line_appl_id    => l_component_appl_id
101149       ,p_amb_context_code           => l_amb_context_code
101150       ,p_entity_code                => l_entity_code
101151       ,p_event_class_code           => l_event_class_code);
101152    --
101153    -- set accounting class
101154    --
101155    xla_ae_lines_pkg.SetAcctClass(
101156            p_accounting_class_code  => 'EXPENSE'
101157          , p_ae_header_id           => l_ae_header_id
101158          );
101159 
101160    --
101161    -- set rounding class
101162    --
101163    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
101164                       'EXPENSE';
101165 
101166    --
101167    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
101168    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
101169    --
101170    -- bulk performance
101171    --
101172    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
101173 
101174    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
101175       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
101176 
101177    -- 4955764
101178    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
101179       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
101180 
101181    -- 4458381 Public Sector Enh
101182    
101183    --
101187    l_accted_amt_idx  := 6;
101184    -- set accounting attributes for the line type
101185    --
101186    l_entered_amt_idx := 4;
101188    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
101189    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
101190    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
101191    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
101192    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
101193    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
101194    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
101195    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
101196    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
101197    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
101198    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
101199    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
101200    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
101201 
101202    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
101203    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
101204 
101205    ---------------------------------------------------------------------------------------------------------------
101206    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
101207    ---------------------------------------------------------------------------------------------------------------
101208    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
101209 
101210    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
101211    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
101212 
101213    IF xla_accounting_cache_pkg.GetValueChar
101214          (p_source_code         => 'LEDGER_CATEGORY_CODE'
101215          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
101216    AND l_bflow_method_code = 'PRIOR_ENTRY'
101217 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
101218    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
101219          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
101220        )
101221    THEN
101222          xla_ae_lines_pkg.BflowUpgEntry
101223            (p_business_method_code    => l_bflow_method_code
101224            ,p_business_class_code     => l_bflow_class_code
101225            ,p_balance_type            => l_balance_type_code);
101226    ELSE
101227       NULL;
101228 -- No business flow processing for business flow method of NONE.
101229    END IF;
101230 
101231    --
101232    -- call analytical criteria
101233    --
101234    
101235    --
101236    -- call description
101237    --
101238    
101239 xla_ae_lines_pkg.SetLineDescription(
101240    p_ae_header_id => l_ae_header_id
101241   ,p_description  => Description_75 (
101242      p_application_id         => p_application_id
101243    , p_ae_header_id           => l_ae_header_id 
101244 , p_source_1 => p_source_1
101245    )
101246 );
101247 
101248 
101249    --
101250    -- call ADRs
101251    -- Bug 4922099
101252    --
101253    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
101254         (NVL(l_actual_upg_option, 'N') = 'O') OR
101255         (NVL(l_enc_upg_option, 'N') = 'O')
101256       )
101257    THEN
101258    NULL;
101259    --
101260    --
101261    
101262   l_ccid := AcctDerRule_175(
101263            p_application_id           => p_application_id
101264          , p_ae_header_id             => l_ae_header_id 
101265 , p_source_3 => p_source_3
101266 , p_source_29 => p_source_29
101267          , x_transaction_coa_id       => l_adr_transaction_coa_id
101268          , x_accounting_coa_id        => l_adr_accounting_coa_id
101269          , x_value_type_code          => l_adr_value_type_code
101270          , p_side                     => 'NA'
101271    );
101272 
101273    xla_ae_lines_pkg.set_ccid(
101274     p_code_combination_id          => l_ccid
101275   , p_value_type_code              => l_adr_value_type_code
101276   , p_transaction_coa_id           => l_adr_transaction_coa_id
101277   , p_accounting_coa_id            => l_adr_accounting_coa_id
101278   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
101279   , p_adr_type_code                => 'S'
101280   , p_component_type               => l_component_type
101281   , p_component_code               => l_component_code
101282   , p_component_type_code          => l_component_type_code
101283   , p_component_appl_id            => l_component_appl_id
101284   , p_amb_context_code             => l_amb_context_code
101285   , p_side                         => 'NA'
101286   );
101287 
101288 
101289    l_segment := AcctDerRule_143(
101290            p_application_id           => p_application_id
101291          , p_ae_header_id             => l_ae_header_id 
101292 , p_source_2 => p_source_2
101293 , p_source_3 => p_source_3
101294          , x_transaction_coa_id       => l_adr_transaction_coa_id
101295          , x_accounting_coa_id        => l_adr_accounting_coa_id
101296          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
101297          , x_flex_value_set_id        => l_adr_flex_value_set_id
101298          , x_value_type_code          => l_adr_value_type_code
101299          , x_value_combination_id     => l_adr_value_combination_id
101300          , x_value_segment_code       => l_adr_value_segment_code
101301          , p_side                     => 'NA'
101302          , p_override_seg_flag        => 'Y'
101303    );
101304 
101305    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
101306 
101307       xla_ae_lines_pkg.set_segment(
101308           p_to_segment_code         => 'GL_ACCOUNT'
101309         , p_segment_value           => l_segment
101313         , p_transaction_coa_id      => l_adr_transaction_coa_id
101310         , p_from_segment_code       => l_adr_value_segment_code
101311         , p_from_combination_id     => l_adr_value_combination_id
101312         , p_value_type_code         => l_adr_value_type_code
101314         , p_accounting_coa_id       => l_adr_accounting_coa_id
101315         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
101316         , p_flex_value_set_id       => l_adr_flex_value_set_id
101317         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
101318         , p_adr_type_code           => 'S'
101319         , p_component_type          => l_component_type
101320         , p_component_code          => l_component_code
101321         , p_component_type_code     => l_component_type_code
101322         , p_component_appl_id       => l_component_appl_id
101323         , p_amb_context_code        => l_amb_context_code
101324         , p_entity_code             => 'TRANSACTIONS'
101325         , p_event_class_code        => 'RETIREMENTS'
101326         , p_side                    => 'NA'
101327         );
101328 
101329   END IF;
101330 
101331    --
101332    --
101333    END IF;
101334    --
101335    -- Bug 4922099
101336    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
101337           (NVL(l_enc_upg_option, 'N') = 'O')
101338         ) AND
101339         (l_bflow_method_code = 'PRIOR_ENTRY')
101340       )
101341    THEN
101342       IF
101343       --
101344       1 = 2
101345       --
101346       THEN
101347       xla_accounting_err_pkg.build_message
101348                                     (p_appli_s_name            => 'XLA'
101349                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
101350                                     ,p_token_1                 => 'LINE_NUMBER'
101351                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
101352                                     ,p_token_2                 => 'LINE_TYPE_NAME'
101353                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
101354                                                                              l_component_type
101355                                                                             ,l_component_code
101356                                                                             ,l_component_type_code
101357                                                                             ,l_component_appl_id
101358                                                                             ,l_amb_context_code
101359                                                                             ,l_entity_code
101360                                                                             ,l_event_class_code
101361                                                                            )
101362                                     ,p_token_3                 => 'OWNER'
101363                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
101364                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
101365                                                                           ,p_lookup_code    => l_component_type_code
101366                                                                          )
101367                                     ,p_token_4                 => 'PRODUCT_NAME'
101368                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
101369                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
101370                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
101371                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
101372                                     ,p_ae_header_id            =>  NULL
101373                                        );
101374 
101375         IF (C_LEVEL_ERROR>= g_log_level) THEN
101376                  trace
101377                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
101378                       ,p_level    => C_LEVEL_ERROR
101379                       ,p_module   => l_log_module);
101380         END IF;
101381       END IF;
101382    END IF;
101383    --
101384    --
101385    ------------------------------------------------------------------------------------------------
101386    -- 4219869 Business Flow
101387    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
101388    -- Prior Entry.  Currently, the following code is always generated.
101389    ------------------------------------------------------------------------------------------------
101390    XLA_AE_LINES_PKG.ValidateCurrentLine;
101391 
101392    ------------------------------------------------------------------------------------
101393    -- 4219869 Business Flow
101394    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
101395    ------------------------------------------------------------------------------------
101396    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
101397 
101398    ----------------------------------------------------------------------------------
101399    -- 4219869 Business Flow
101400    -- Update journal entry status -- Need to generate this within IF <condition>
101401    ----------------------------------------------------------------------------------
101402    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
101403          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
101404          ,p_balance_type_code => l_balance_type_code
101405          );
101406 
101407    -------------------------------------------------------------------------------------------
101408    -- 4262811 - Generate the Accrual Reversal lines
101409    -------------------------------------------------------------------------------------------
101410    BEGIN
101411       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
101415       END IF;
101412                               (g_array_event(p_event_id).array_value_num('header_index'));
101413       IF l_acc_rev_flag IS NULL THEN
101414          l_acc_rev_flag := 'N';
101416    EXCEPTION
101417       WHEN OTHERS THEN
101418          l_acc_rev_flag := 'N';
101419    END;
101420    --
101421    IF (l_acc_rev_flag = 'Y') THEN
101422 
101423        -- 4645092  ------------------------------------------------------------------------------
101424        -- To allow MPA report to determine if it should generate report process
101425        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
101426        ------------------------------------------------------------------------------------------
101427 
101428        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
101429        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
101430    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
101431    -- call ADRs
101432    -- Bug 4922099
101433    --
101434    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
101435         (NVL(l_actual_upg_option, 'N') = 'O') OR
101436         (NVL(l_enc_upg_option, 'N') = 'O')
101437       )
101438    THEN
101439    NULL;
101440    --
101441    --
101442    
101443   l_ccid := AcctDerRule_175(
101444            p_application_id           => p_application_id
101445          , p_ae_header_id             => l_ae_header_id 
101446 , p_source_3 => p_source_3
101447 , p_source_29 => p_source_29
101448          , x_transaction_coa_id       => l_adr_transaction_coa_id
101449          , x_accounting_coa_id        => l_adr_accounting_coa_id
101450          , x_value_type_code          => l_adr_value_type_code
101451          , p_side                     => 'NA'
101452    );
101453 
101454    xla_ae_lines_pkg.set_ccid(
101455     p_code_combination_id          => l_ccid
101456   , p_value_type_code              => l_adr_value_type_code
101457   , p_transaction_coa_id           => l_adr_transaction_coa_id
101458   , p_accounting_coa_id            => l_adr_accounting_coa_id
101459   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
101460   , p_adr_type_code                => 'S'
101461   , p_component_type               => l_component_type
101462   , p_component_code               => l_component_code
101463   , p_component_type_code          => l_component_type_code
101464   , p_component_appl_id            => l_component_appl_id
101465   , p_amb_context_code             => l_amb_context_code
101466   , p_side                         => 'NA'
101467   );
101468 
101469 
101470    l_segment := AcctDerRule_143(
101471            p_application_id           => p_application_id
101472          , p_ae_header_id             => l_ae_header_id 
101473 , p_source_2 => p_source_2
101474 , p_source_3 => p_source_3
101475          , x_transaction_coa_id       => l_adr_transaction_coa_id
101476          , x_accounting_coa_id        => l_adr_accounting_coa_id
101477          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
101478          , x_flex_value_set_id        => l_adr_flex_value_set_id
101479          , x_value_type_code          => l_adr_value_type_code
101480          , x_value_combination_id     => l_adr_value_combination_id
101481          , x_value_segment_code       => l_adr_value_segment_code
101482          , p_side                     => 'NA'
101483          , p_override_seg_flag        => 'Y'
101484    );
101485 
101486    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
101487 
101488       xla_ae_lines_pkg.set_segment(
101489           p_to_segment_code         => 'GL_ACCOUNT'
101490         , p_segment_value           => l_segment
101491         , p_from_segment_code       => l_adr_value_segment_code
101492         , p_from_combination_id     => l_adr_value_combination_id
101493         , p_value_type_code         => l_adr_value_type_code
101494         , p_transaction_coa_id      => l_adr_transaction_coa_id
101495         , p_accounting_coa_id       => l_adr_accounting_coa_id
101496         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
101497         , p_flex_value_set_id       => l_adr_flex_value_set_id
101498         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
101499         , p_adr_type_code           => 'S'
101500         , p_component_type          => l_component_type
101501         , p_component_code          => l_component_code
101502         , p_component_type_code     => l_component_type_code
101503         , p_component_appl_id       => l_component_appl_id
101504         , p_amb_context_code        => l_amb_context_code
101505         , p_entity_code             => 'TRANSACTIONS'
101506         , p_event_class_code        => 'RETIREMENTS'
101507         , p_side                    => 'NA'
101508         );
101509 
101510   END IF;
101511 
101512    --
101513    --
101514    END IF;
101515 
101516        --
101517        -- Update the line information that should be overwritten
101518        --
101519        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
101520                                          p_header_num   => 1);
101521        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
101522 
101523        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
101524 
101525        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
101526           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
101527        END IF;
101528 
101529       --
101530       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
101531       --
101532       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
101533           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
101534       ELSE
101538           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
101535           ---------------------------------------------------------------------------------------------------
101536           -- 4262811a Switch Sign
101537           ---------------------------------------------------------------------------------------------------
101539           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
101540                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
101541           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
101542                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
101543           -- 5132302
101544           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
101545                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
101546 
101547       END IF;
101548 
101549       -- 4955764
101550       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
101551       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
101552 
101553 
101554       XLA_AE_LINES_PKG.ValidateCurrentLine;
101555       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
101556 
101557       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
101558                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
101559                ,p_balance_type_code => l_balance_type_code);
101560 
101561    END IF;
101562 
101563    -----------------------------------------------------------------------------------------
101564    -- 4262811 Multiperiod Accounting
101565    -----------------------------------------------------------------------------------------
101566      -- No MPA option is assigned.
101567 
101568 
101569 END IF;
101570 END IF;
101571 --
101572 
101573 --
101574 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
101575    trace
101576       (p_msg      => 'END of AcctLineType_295'
101577       ,p_level    => C_LEVEL_PROCEDURE
101578       ,p_module   => l_log_module);
101579 END IF;
101580 --
101581 EXCEPTION
101582   WHEN xla_exceptions_pkg.application_exception THEN
101583       RAISE;
101584   WHEN OTHERS THEN
101585        xla_exceptions_pkg.raise_message
101586            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_295');
101587 END AcctLineType_295;
101588 --
101589 
101590 ---------------------------------------
101591 --
101592 -- PRIVATE FUNCTION
101593 --         AcctLineType_296
101594 --
101595 ---------------------------------------
101596 PROCEDURE AcctLineType_296 (
101597   p_application_id        IN NUMBER
101598  ,p_event_id              IN NUMBER
101599  ,p_calculate_acctd_flag  IN VARCHAR2
101600  ,p_calculate_g_l_flag    IN VARCHAR2
101601  ,p_actual_flag           IN OUT VARCHAR2
101602  ,p_balance_type_code     OUT VARCHAR2
101603  ,p_gain_or_loss_ref      OUT VARCHAR2
101604  
101605 --Period Close Date
101606  , p_source_1            IN DATE
101607 --Bonus Depreciation Expense Account
101608  , p_source_2            IN VARCHAR2
101609 --Generated Code Combination Identifier
101610  , p_source_3            IN NUMBER
101611 --Expense Account Code Combination Identifier
101612  , p_source_29            IN NUMBER
101613 --Adjustment Type
101614  , p_source_35            IN VARCHAR2
101615 --Transaction Header Identifier
101616  , p_source_36            IN NUMBER
101617 --Adjustment Line Identifier
101618  , p_source_37            IN NUMBER
101619 --Distribution Type Code
101620  , p_source_38            IN VARCHAR2
101621 --Entered Amount
101622  , p_source_39            IN NUMBER
101623 --Currency Code
101624  , p_source_40            IN VARCHAR2
101625 )
101626 IS
101627 
101628 l_component_type              VARCHAR2(80);
101629 l_component_code              VARCHAR2(30);
101630 l_component_type_code         VARCHAR2(1);
101631 l_component_appl_id           INTEGER;
101632 l_amb_context_code            VARCHAR2(30);
101633 l_entity_code                 VARCHAR2(30);
101634 l_event_class_code            VARCHAR2(30);
101635 l_ae_header_id                NUMBER;
101636 l_event_type_code             VARCHAR2(30);
101637 l_line_definition_code        VARCHAR2(30);
101638 l_line_definition_owner_code  VARCHAR2(1);
101639 --
101640 -- adr variables
101641 l_segment                     VARCHAR2(30);
101642 l_ccid                        NUMBER;
101643 l_adr_transaction_coa_id      NUMBER;
101644 l_adr_accounting_coa_id       NUMBER;
101645 l_adr_flexfield_segment_code  VARCHAR2(30);
101646 l_adr_flex_value_set_id       NUMBER;
101647 l_adr_value_type_code         VARCHAR2(30);
101648 l_adr_value_combination_id    NUMBER;
101649 l_adr_value_segment_code      VARCHAR2(30);
101650 
101651 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
101652 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
101653 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
101654 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
101655 
101656 -- 4262811 Variables ------------------------------------------------------------------------------------------
101657 l_entered_amt_idx             NUMBER;
101658 l_accted_amt_idx              NUMBER;
101659 l_acc_rev_flag                VARCHAR2(1);
101660 l_accrual_line_num            NUMBER;
101661 l_tmp_amt                     NUMBER;
101662 l_acc_rev_natural_side_code   VARCHAR2(1);
101663 
101664 l_num_entries                 NUMBER;
101665 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
101666 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
101667 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
101671 
101668 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
101669 l_recog_line_1                NUMBER;
101670 l_recog_line_2                NUMBER;
101672 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
101673 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
101674 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
101675 
101676 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
101677 
101678 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
101679 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
101680 
101681 ---------------------------------------------------------------------------------------------------------------
101682 
101683 
101684 --
101685 -- bulk performance
101686 --
101687 l_balance_type_code           VARCHAR2(1);
101688 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
101689 l_log_module                  VARCHAR2(240);
101690 
101691 --
101692 -- Upgrade strategy
101693 --
101694 l_actual_upg_option           VARCHAR2(1);
101695 l_enc_upg_option           VARCHAR2(1);
101696 
101697 --
101698 BEGIN
101699 --
101700 IF g_log_enabled THEN
101701       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_296';
101702 END IF;
101703 --
101704 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
101705 
101706       trace
101707          (p_msg      => 'BEGIN of AcctLineType_296'
101708          ,p_level    => C_LEVEL_PROCEDURE
101709          ,p_module   => l_log_module);
101710 
101711 END IF;
101712 --
101713 l_component_type             := 'AMB_JLT';
101714 l_component_code             := 'FA_RETIREMENT_BONUS_DEPRN_EXP';
101715 l_component_type_code        := 'S';
101716 l_component_appl_id          :=  140;
101717 l_amb_context_code           := 'DEFAULT';
101718 l_entity_code                := 'TRANSACTIONS';
101719 l_event_class_code           := 'RETIREMENTS';
101720 l_event_type_code            := 'REINSTATEMENTS';
101721 l_line_definition_owner_code := 'S';
101722 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
101723 --
101724 l_balance_type_code          := 'A';
101725 l_segment                     := NULL;
101726 l_ccid                        := NULL;
101727 l_adr_transaction_coa_id      := NULL;
101728 l_adr_accounting_coa_id       := NULL;
101729 l_adr_flexfield_segment_code  := NULL;
101730 l_adr_flex_value_set_id       := NULL;
101731 l_adr_value_type_code         := NULL;
101732 l_adr_value_combination_id    := NULL;
101733 l_adr_value_segment_code      := NULL;
101734 
101735 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
101736 l_bflow_class_code           := '';    -- 4219869 Business Flow
101737 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
101738 l_budgetary_control_flag     := 'N';
101739 
101740 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
101741 l_bflow_applied_to_amt       := NULL; -- 5132302
101742 l_entered_amt_idx            := NULL;          -- 4262811
101743 l_accted_amt_idx             := NULL;          -- 4262811
101744 l_acc_rev_flag               := NULL;          -- 4262811
101745 l_accrual_line_num           := NULL;          -- 4262811
101746 l_tmp_amt                    := NULL;          -- 4262811
101747 --
101748  
101749 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
101750     l_balance_type_code <> 'B' THEN
101751 IF NVL(p_source_35,'
101752 ') =  'BONUS EXPENSE'
101753  THEN 
101754 
101755    --
101756    XLA_AE_LINES_PKG.SetNewLine;
101757 
101758    p_balance_type_code          := l_balance_type_code;
101759    -- set the flag so later we will know whether the gain loss line needs to be created
101760    
101761    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
101762      p_actual_flag :='A';
101763    END IF;
101764 
101765    --
101766    -- bulk performance
101767    --
101768    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
101769                                       p_header_num   => 0); -- 4262811
101770    --
101771    -- set accounting line options
101772    --
101773    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
101774            p_natural_side_code          => 'C'
101775          , p_gain_or_loss_flag          => 'N'
101776          , p_gl_transfer_mode_code      => 'S'
101777          , p_acct_entry_type_code       => 'A'
101778          , p_switch_side_flag           => 'Y'
101779          , p_merge_duplicate_code       => 'N'
101780          );
101781    --
101782    l_acc_rev_natural_side_code := 'D';  -- 4262811
101783    -- 
101784    --
101785    -- set accounting line type info
101786    --
101787    xla_ae_lines_pkg.SetAcctLineType
101788       (p_component_type             => l_component_type
101789       ,p_event_type_code            => l_event_type_code
101790       ,p_line_definition_owner_code => l_line_definition_owner_code
101791       ,p_line_definition_code       => l_line_definition_code
101792       ,p_accounting_line_code       => l_component_code
101793       ,p_accounting_line_type_code  => l_component_type_code
101794       ,p_accounting_line_appl_id    => l_component_appl_id
101795       ,p_amb_context_code           => l_amb_context_code
101796       ,p_entity_code                => l_entity_code
101797       ,p_event_class_code           => l_event_class_code);
101798    --
101799    -- set accounting class
101800    --
101801    xla_ae_lines_pkg.SetAcctClass(
101802            p_accounting_class_code  => 'EXPENSE'
101803          , p_ae_header_id           => l_ae_header_id
101804          );
101805 
101806    --
101807    -- set rounding class
101808    --
101809    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
101813    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
101810                       'EXPENSE';
101811 
101812    --
101814    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
101815    --
101816    -- bulk performance
101817    --
101818    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
101819 
101820    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
101821       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
101822 
101823    -- 4955764
101824    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
101825       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
101826 
101827    -- 4458381 Public Sector Enh
101828    
101829    --
101830    -- set accounting attributes for the line type
101831    --
101832    l_entered_amt_idx := 4;
101833    l_accted_amt_idx  := 6;
101834    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
101835    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
101836    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
101837    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
101838    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
101839    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
101840    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
101841    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
101842    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
101843    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
101844    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
101845    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
101846    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
101847 
101848    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
101849    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
101850 
101851    ---------------------------------------------------------------------------------------------------------------
101852    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
101853    ---------------------------------------------------------------------------------------------------------------
101854    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
101855 
101856    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
101857    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
101858 
101859    IF xla_accounting_cache_pkg.GetValueChar
101860          (p_source_code         => 'LEDGER_CATEGORY_CODE'
101861          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
101862    AND l_bflow_method_code = 'PRIOR_ENTRY'
101863 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
101864    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
101865          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
101866        )
101867    THEN
101868          xla_ae_lines_pkg.BflowUpgEntry
101869            (p_business_method_code    => l_bflow_method_code
101870            ,p_business_class_code     => l_bflow_class_code
101871            ,p_balance_type            => l_balance_type_code);
101872    ELSE
101873       NULL;
101874 -- No business flow processing for business flow method of NONE.
101875    END IF;
101876 
101877    --
101878    -- call analytical criteria
101879    --
101880    
101881    --
101882    -- call description
101883    --
101884    
101885 xla_ae_lines_pkg.SetLineDescription(
101886    p_ae_header_id => l_ae_header_id
101887   ,p_description  => Description_75 (
101888      p_application_id         => p_application_id
101889    , p_ae_header_id           => l_ae_header_id 
101890 , p_source_1 => p_source_1
101891    )
101892 );
101893 
101894 
101895    --
101896    -- call ADRs
101897    -- Bug 4922099
101898    --
101899    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
101900         (NVL(l_actual_upg_option, 'N') = 'O') OR
101901         (NVL(l_enc_upg_option, 'N') = 'O')
101902       )
101903    THEN
101904    NULL;
101905    --
101906    --
101907    
101908   l_ccid := AcctDerRule_175(
101909            p_application_id           => p_application_id
101910          , p_ae_header_id             => l_ae_header_id 
101911 , p_source_3 => p_source_3
101912 , p_source_29 => p_source_29
101913          , x_transaction_coa_id       => l_adr_transaction_coa_id
101914          , x_accounting_coa_id        => l_adr_accounting_coa_id
101915          , x_value_type_code          => l_adr_value_type_code
101916          , p_side                     => 'NA'
101917    );
101918 
101919    xla_ae_lines_pkg.set_ccid(
101920     p_code_combination_id          => l_ccid
101921   , p_value_type_code              => l_adr_value_type_code
101922   , p_transaction_coa_id           => l_adr_transaction_coa_id
101923   , p_accounting_coa_id            => l_adr_accounting_coa_id
101924   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
101925   , p_adr_type_code                => 'S'
101926   , p_component_type               => l_component_type
101927   , p_component_code               => l_component_code
101928   , p_component_type_code          => l_component_type_code
101929   , p_component_appl_id            => l_component_appl_id
101930   , p_amb_context_code             => l_amb_context_code
101931   , p_side                         => 'NA'
101932   );
101933 
101934 
101935    l_segment := AcctDerRule_143(
101936            p_application_id           => p_application_id
101937          , p_ae_header_id             => l_ae_header_id 
101941          , x_accounting_coa_id        => l_adr_accounting_coa_id
101938 , p_source_2 => p_source_2
101939 , p_source_3 => p_source_3
101940          , x_transaction_coa_id       => l_adr_transaction_coa_id
101942          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
101943          , x_flex_value_set_id        => l_adr_flex_value_set_id
101944          , x_value_type_code          => l_adr_value_type_code
101945          , x_value_combination_id     => l_adr_value_combination_id
101946          , x_value_segment_code       => l_adr_value_segment_code
101947          , p_side                     => 'NA'
101948          , p_override_seg_flag        => 'Y'
101949    );
101950 
101951    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
101952 
101953       xla_ae_lines_pkg.set_segment(
101954           p_to_segment_code         => 'GL_ACCOUNT'
101955         , p_segment_value           => l_segment
101956         , p_from_segment_code       => l_adr_value_segment_code
101957         , p_from_combination_id     => l_adr_value_combination_id
101958         , p_value_type_code         => l_adr_value_type_code
101959         , p_transaction_coa_id      => l_adr_transaction_coa_id
101960         , p_accounting_coa_id       => l_adr_accounting_coa_id
101961         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
101962         , p_flex_value_set_id       => l_adr_flex_value_set_id
101963         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
101964         , p_adr_type_code           => 'S'
101965         , p_component_type          => l_component_type
101966         , p_component_code          => l_component_code
101967         , p_component_type_code     => l_component_type_code
101968         , p_component_appl_id       => l_component_appl_id
101969         , p_amb_context_code        => l_amb_context_code
101970         , p_entity_code             => 'TRANSACTIONS'
101971         , p_event_class_code        => 'RETIREMENTS'
101972         , p_side                    => 'NA'
101973         );
101974 
101975   END IF;
101976 
101977    --
101978    --
101979    END IF;
101980    --
101981    -- Bug 4922099
101982    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
101983           (NVL(l_enc_upg_option, 'N') = 'O')
101984         ) AND
101985         (l_bflow_method_code = 'PRIOR_ENTRY')
101986       )
101987    THEN
101988       IF
101989       --
101990       1 = 2
101991       --
101992       THEN
101993       xla_accounting_err_pkg.build_message
101994                                     (p_appli_s_name            => 'XLA'
101995                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
101996                                     ,p_token_1                 => 'LINE_NUMBER'
101997                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
101998                                     ,p_token_2                 => 'LINE_TYPE_NAME'
101999                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
102000                                                                              l_component_type
102001                                                                             ,l_component_code
102002                                                                             ,l_component_type_code
102003                                                                             ,l_component_appl_id
102004                                                                             ,l_amb_context_code
102005                                                                             ,l_entity_code
102006                                                                             ,l_event_class_code
102007                                                                            )
102008                                     ,p_token_3                 => 'OWNER'
102009                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
102010                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
102011                                                                           ,p_lookup_code    => l_component_type_code
102012                                                                          )
102013                                     ,p_token_4                 => 'PRODUCT_NAME'
102014                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
102015                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
102016                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
102017                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
102018                                     ,p_ae_header_id            =>  NULL
102019                                        );
102020 
102021         IF (C_LEVEL_ERROR>= g_log_level) THEN
102022                  trace
102023                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
102024                       ,p_level    => C_LEVEL_ERROR
102025                       ,p_module   => l_log_module);
102026         END IF;
102027       END IF;
102028    END IF;
102029    --
102030    --
102031    ------------------------------------------------------------------------------------------------
102032    -- 4219869 Business Flow
102033    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
102034    -- Prior Entry.  Currently, the following code is always generated.
102035    ------------------------------------------------------------------------------------------------
102036    XLA_AE_LINES_PKG.ValidateCurrentLine;
102037 
102038    ------------------------------------------------------------------------------------
102039    -- 4219869 Business Flow
102040    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
102041    ------------------------------------------------------------------------------------
102045    -- 4219869 Business Flow
102042    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
102043 
102044    ----------------------------------------------------------------------------------
102046    -- Update journal entry status -- Need to generate this within IF <condition>
102047    ----------------------------------------------------------------------------------
102048    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
102049          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
102050          ,p_balance_type_code => l_balance_type_code
102051          );
102052 
102053    -------------------------------------------------------------------------------------------
102054    -- 4262811 - Generate the Accrual Reversal lines
102055    -------------------------------------------------------------------------------------------
102056    BEGIN
102057       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
102058                               (g_array_event(p_event_id).array_value_num('header_index'));
102059       IF l_acc_rev_flag IS NULL THEN
102060          l_acc_rev_flag := 'N';
102061       END IF;
102062    EXCEPTION
102063       WHEN OTHERS THEN
102064          l_acc_rev_flag := 'N';
102065    END;
102066    --
102067    IF (l_acc_rev_flag = 'Y') THEN
102068 
102069        -- 4645092  ------------------------------------------------------------------------------
102070        -- To allow MPA report to determine if it should generate report process
102071        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
102072        ------------------------------------------------------------------------------------------
102073 
102074        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
102075        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
102076    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
102077    -- call ADRs
102078    -- Bug 4922099
102079    --
102080    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
102081         (NVL(l_actual_upg_option, 'N') = 'O') OR
102082         (NVL(l_enc_upg_option, 'N') = 'O')
102083       )
102084    THEN
102085    NULL;
102086    --
102087    --
102088    
102089   l_ccid := AcctDerRule_175(
102090            p_application_id           => p_application_id
102091          , p_ae_header_id             => l_ae_header_id 
102092 , p_source_3 => p_source_3
102093 , p_source_29 => p_source_29
102094          , x_transaction_coa_id       => l_adr_transaction_coa_id
102095          , x_accounting_coa_id        => l_adr_accounting_coa_id
102096          , x_value_type_code          => l_adr_value_type_code
102097          , p_side                     => 'NA'
102098    );
102099 
102100    xla_ae_lines_pkg.set_ccid(
102101     p_code_combination_id          => l_ccid
102102   , p_value_type_code              => l_adr_value_type_code
102103   , p_transaction_coa_id           => l_adr_transaction_coa_id
102104   , p_accounting_coa_id            => l_adr_accounting_coa_id
102105   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
102106   , p_adr_type_code                => 'S'
102107   , p_component_type               => l_component_type
102108   , p_component_code               => l_component_code
102109   , p_component_type_code          => l_component_type_code
102110   , p_component_appl_id            => l_component_appl_id
102111   , p_amb_context_code             => l_amb_context_code
102112   , p_side                         => 'NA'
102113   );
102114 
102115 
102116    l_segment := AcctDerRule_143(
102117            p_application_id           => p_application_id
102118          , p_ae_header_id             => l_ae_header_id 
102119 , p_source_2 => p_source_2
102120 , p_source_3 => p_source_3
102121          , x_transaction_coa_id       => l_adr_transaction_coa_id
102122          , x_accounting_coa_id        => l_adr_accounting_coa_id
102123          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
102124          , x_flex_value_set_id        => l_adr_flex_value_set_id
102125          , x_value_type_code          => l_adr_value_type_code
102126          , x_value_combination_id     => l_adr_value_combination_id
102127          , x_value_segment_code       => l_adr_value_segment_code
102128          , p_side                     => 'NA'
102129          , p_override_seg_flag        => 'Y'
102130    );
102131 
102132    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
102133 
102134       xla_ae_lines_pkg.set_segment(
102135           p_to_segment_code         => 'GL_ACCOUNT'
102136         , p_segment_value           => l_segment
102137         , p_from_segment_code       => l_adr_value_segment_code
102138         , p_from_combination_id     => l_adr_value_combination_id
102139         , p_value_type_code         => l_adr_value_type_code
102140         , p_transaction_coa_id      => l_adr_transaction_coa_id
102141         , p_accounting_coa_id       => l_adr_accounting_coa_id
102142         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
102143         , p_flex_value_set_id       => l_adr_flex_value_set_id
102144         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
102145         , p_adr_type_code           => 'S'
102146         , p_component_type          => l_component_type
102147         , p_component_code          => l_component_code
102148         , p_component_type_code     => l_component_type_code
102149         , p_component_appl_id       => l_component_appl_id
102150         , p_amb_context_code        => l_amb_context_code
102151         , p_entity_code             => 'TRANSACTIONS'
102152         , p_event_class_code        => 'RETIREMENTS'
102153         , p_side                    => 'NA'
102154         );
102155 
102156   END IF;
102157 
102158    --
102159    --
102160    END IF;
102161 
102162        --
102163        -- Update the line information that should be overwritten
102164        --
102165        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
102169        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
102166                                          p_header_num   => 1);
102167        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
102168 
102170 
102171        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
102172           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
102173        END IF;
102174 
102175       --
102176       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
102177       --
102178       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
102179           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
102180       ELSE
102181           ---------------------------------------------------------------------------------------------------
102182           -- 4262811a Switch Sign
102183           ---------------------------------------------------------------------------------------------------
102184           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
102185           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
102186                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
102187           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
102188                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
102189           -- 5132302
102190           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
102191                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
102192 
102193       END IF;
102194 
102195       -- 4955764
102196       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
102197       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
102198 
102199 
102200       XLA_AE_LINES_PKG.ValidateCurrentLine;
102201       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
102202 
102203       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
102204                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
102205                ,p_balance_type_code => l_balance_type_code);
102206 
102207    END IF;
102208 
102209    -----------------------------------------------------------------------------------------
102210    -- 4262811 Multiperiod Accounting
102211    -----------------------------------------------------------------------------------------
102212      -- No MPA option is assigned.
102213 
102214 
102215 END IF;
102216 END IF;
102217 --
102218 
102219 --
102220 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
102221    trace
102222       (p_msg      => 'END of AcctLineType_296'
102223       ,p_level    => C_LEVEL_PROCEDURE
102224       ,p_module   => l_log_module);
102225 END IF;
102226 --
102227 EXCEPTION
102228   WHEN xla_exceptions_pkg.application_exception THEN
102229       RAISE;
102230   WHEN OTHERS THEN
102231        xla_exceptions_pkg.raise_message
102232            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_296');
102233 END AcctLineType_296;
102234 --
102235 
102236 ---------------------------------------
102237 --
102238 -- PRIVATE FUNCTION
102239 --         AcctLineType_297
102240 --
102241 ---------------------------------------
102242 PROCEDURE AcctLineType_297 (
102243   p_application_id        IN NUMBER
102244  ,p_event_id              IN NUMBER
102245  ,p_calculate_acctd_flag  IN VARCHAR2
102246  ,p_calculate_g_l_flag    IN VARCHAR2
102247  ,p_actual_flag           IN OUT VARCHAR2
102248  ,p_balance_type_code     OUT VARCHAR2
102249  ,p_gain_or_loss_ref      OUT VARCHAR2
102250  
102251 --Period Close Date
102252  , p_source_1            IN DATE
102253 --Generated Code Combination Identifier
102254  , p_source_3            IN NUMBER
102255 --Bonus Reserve Account
102256  , p_source_4            IN VARCHAR2
102257 --Generated Offset Code Combination Identifier
102258  , p_source_17            IN NUMBER
102259 --Expense Account Code Combination Identifier
102260  , p_source_29            IN NUMBER
102261 --Default Code Combination Identifier
102262  , p_source_30            IN NUMBER
102263 --Adjustment Type
102264  , p_source_35            IN VARCHAR2
102265 --Transaction Header Identifier
102266  , p_source_36            IN NUMBER
102267 --Adjustment Line Identifier
102268  , p_source_37            IN NUMBER
102269 --Distribution Type Code
102270  , p_source_38            IN VARCHAR2
102271 --Entered Amount
102272  , p_source_39            IN NUMBER
102273 --Currency Code
102274  , p_source_40            IN VARCHAR2
102275 )
102276 IS
102277 
102278 l_component_type              VARCHAR2(80);
102279 l_component_code              VARCHAR2(30);
102280 l_component_type_code         VARCHAR2(1);
102281 l_component_appl_id           INTEGER;
102282 l_amb_context_code            VARCHAR2(30);
102283 l_entity_code                 VARCHAR2(30);
102284 l_event_class_code            VARCHAR2(30);
102285 l_ae_header_id                NUMBER;
102286 l_event_type_code             VARCHAR2(30);
102287 l_line_definition_code        VARCHAR2(30);
102288 l_line_definition_owner_code  VARCHAR2(1);
102289 --
102290 -- adr variables
102291 l_segment                     VARCHAR2(30);
102292 l_ccid                        NUMBER;
102293 l_adr_transaction_coa_id      NUMBER;
102294 l_adr_accounting_coa_id       NUMBER;
102295 l_adr_flexfield_segment_code  VARCHAR2(30);
102296 l_adr_flex_value_set_id       NUMBER;
102297 l_adr_value_type_code         VARCHAR2(30);
102298 l_adr_value_combination_id    NUMBER;
102302 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
102299 l_adr_value_segment_code      VARCHAR2(30);
102300 
102301 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
102303 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
102304 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
102305 
102306 -- 4262811 Variables ------------------------------------------------------------------------------------------
102307 l_entered_amt_idx             NUMBER;
102308 l_accted_amt_idx              NUMBER;
102309 l_acc_rev_flag                VARCHAR2(1);
102310 l_accrual_line_num            NUMBER;
102311 l_tmp_amt                     NUMBER;
102312 l_acc_rev_natural_side_code   VARCHAR2(1);
102313 
102314 l_num_entries                 NUMBER;
102315 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
102316 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
102317 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
102318 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
102319 l_recog_line_1                NUMBER;
102320 l_recog_line_2                NUMBER;
102321 
102322 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
102323 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
102324 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
102325 
102326 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
102327 
102328 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
102329 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
102330 
102331 ---------------------------------------------------------------------------------------------------------------
102332 
102333 
102334 --
102335 -- bulk performance
102336 --
102337 l_balance_type_code           VARCHAR2(1);
102338 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
102339 l_log_module                  VARCHAR2(240);
102340 
102341 --
102342 -- Upgrade strategy
102343 --
102344 l_actual_upg_option           VARCHAR2(1);
102345 l_enc_upg_option           VARCHAR2(1);
102346 
102347 --
102348 BEGIN
102349 --
102350 IF g_log_enabled THEN
102351       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_297';
102352 END IF;
102353 --
102354 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
102355 
102356       trace
102357          (p_msg      => 'BEGIN of AcctLineType_297'
102358          ,p_level    => C_LEVEL_PROCEDURE
102359          ,p_module   => l_log_module);
102360 
102361 END IF;
102362 --
102363 l_component_type             := 'AMB_JLT';
102364 l_component_code             := 'FA_RETIREMENT_BONUS_DEPRN_RES';
102365 l_component_type_code        := 'S';
102366 l_component_appl_id          :=  140;
102367 l_amb_context_code           := 'DEFAULT';
102368 l_entity_code                := 'TRANSACTIONS';
102369 l_event_class_code           := 'RETIREMENTS';
102370 l_event_type_code            := 'REINSTATEMENTS';
102371 l_line_definition_owner_code := 'S';
102372 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
102373 --
102374 l_balance_type_code          := 'A';
102375 l_segment                     := NULL;
102376 l_ccid                        := NULL;
102377 l_adr_transaction_coa_id      := NULL;
102378 l_adr_accounting_coa_id       := NULL;
102379 l_adr_flexfield_segment_code  := NULL;
102380 l_adr_flex_value_set_id       := NULL;
102381 l_adr_value_type_code         := NULL;
102382 l_adr_value_combination_id    := NULL;
102383 l_adr_value_segment_code      := NULL;
102384 
102385 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
102386 l_bflow_class_code           := '';    -- 4219869 Business Flow
102387 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
102388 l_budgetary_control_flag     := 'N';
102389 
102390 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
102391 l_bflow_applied_to_amt       := NULL; -- 5132302
102392 l_entered_amt_idx            := NULL;          -- 4262811
102393 l_accted_amt_idx             := NULL;          -- 4262811
102394 l_acc_rev_flag               := NULL;          -- 4262811
102395 l_accrual_line_num           := NULL;          -- 4262811
102396 l_tmp_amt                    := NULL;          -- 4262811
102397 --
102398  
102399 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
102400     l_balance_type_code <> 'B' THEN
102401 IF NVL(p_source_35,'
102402 ') =  'BONUS EXPENSE'
102403  THEN 
102404 
102405    --
102406    XLA_AE_LINES_PKG.SetNewLine;
102407 
102408    p_balance_type_code          := l_balance_type_code;
102409    -- set the flag so later we will know whether the gain loss line needs to be created
102410    
102411    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
102412      p_actual_flag :='A';
102413    END IF;
102414 
102415    --
102416    -- bulk performance
102417    --
102418    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
102419                                       p_header_num   => 0); -- 4262811
102420    --
102421    -- set accounting line options
102422    --
102423    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
102424            p_natural_side_code          => 'D'
102425          , p_gain_or_loss_flag          => 'N'
102426          , p_gl_transfer_mode_code      => 'S'
102427          , p_acct_entry_type_code       => 'A'
102428          , p_switch_side_flag           => 'Y'
102429          , p_merge_duplicate_code       => 'N'
102430          );
102431    --
102432    l_acc_rev_natural_side_code := 'C';  -- 4262811
102433    -- 
102434    --
102435    -- set accounting line type info
102436    --
102437    xla_ae_lines_pkg.SetAcctLineType
102441       ,p_line_definition_code       => l_line_definition_code
102438       (p_component_type             => l_component_type
102439       ,p_event_type_code            => l_event_type_code
102440       ,p_line_definition_owner_code => l_line_definition_owner_code
102442       ,p_accounting_line_code       => l_component_code
102443       ,p_accounting_line_type_code  => l_component_type_code
102444       ,p_accounting_line_appl_id    => l_component_appl_id
102445       ,p_amb_context_code           => l_amb_context_code
102446       ,p_entity_code                => l_entity_code
102447       ,p_event_class_code           => l_event_class_code);
102448    --
102449    -- set accounting class
102450    --
102451    xla_ae_lines_pkg.SetAcctClass(
102452            p_accounting_class_code  => 'ASSET'
102453          , p_ae_header_id           => l_ae_header_id
102454          );
102455 
102456    --
102457    -- set rounding class
102458    --
102459    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
102460                       'ASSET';
102461 
102462    --
102463    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
102464    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
102465    --
102466    -- bulk performance
102467    --
102468    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
102469 
102470    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
102471       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
102472 
102473    -- 4955764
102474    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
102475       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
102476 
102477    -- 4458381 Public Sector Enh
102478    
102479    --
102480    -- set accounting attributes for the line type
102481    --
102482    l_entered_amt_idx := 4;
102483    l_accted_amt_idx  := 6;
102484    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
102485    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
102486    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
102487    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
102488    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
102489    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
102490    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
102491    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
102492    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
102493    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
102494    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
102495    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
102496    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
102497 
102498    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
102499    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
102500 
102501    ---------------------------------------------------------------------------------------------------------------
102502    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
102503    ---------------------------------------------------------------------------------------------------------------
102504    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
102505 
102506    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
102507    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
102508 
102509    IF xla_accounting_cache_pkg.GetValueChar
102510          (p_source_code         => 'LEDGER_CATEGORY_CODE'
102511          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
102512    AND l_bflow_method_code = 'PRIOR_ENTRY'
102513 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
102514    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
102515          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
102516        )
102517    THEN
102518          xla_ae_lines_pkg.BflowUpgEntry
102519            (p_business_method_code    => l_bflow_method_code
102520            ,p_business_class_code     => l_bflow_class_code
102521            ,p_balance_type            => l_balance_type_code);
102522    ELSE
102523       NULL;
102524 -- No business flow processing for business flow method of NONE.
102525    END IF;
102526 
102527    --
102528    -- call analytical criteria
102529    --
102530    
102531    --
102532    -- call description
102533    --
102534    
102535 xla_ae_lines_pkg.SetLineDescription(
102536    p_ae_header_id => l_ae_header_id
102537   ,p_description  => Description_76 (
102538      p_application_id         => p_application_id
102539    , p_ae_header_id           => l_ae_header_id 
102540 , p_source_1 => p_source_1
102541    )
102542 );
102543 
102544 
102545    --
102546    -- call ADRs
102547    -- Bug 4922099
102548    --
102549    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
102550         (NVL(l_actual_upg_option, 'N') = 'O') OR
102551         (NVL(l_enc_upg_option, 'N') = 'O')
102552       )
102553    THEN
102554    NULL;
102555    --
102556    --
102557    
102558   l_ccid := AcctDerRule_174(
102559            p_application_id           => p_application_id
102560          , p_ae_header_id             => l_ae_header_id 
102561 , p_source_3 => p_source_3
102562 , p_source_17 => p_source_17
102563 , p_source_30 => p_source_30
102564          , x_transaction_coa_id       => l_adr_transaction_coa_id
102565          , x_accounting_coa_id        => l_adr_accounting_coa_id
102569 
102566          , x_value_type_code          => l_adr_value_type_code
102567          , p_side                     => 'NA'
102568    );
102570    xla_ae_lines_pkg.set_ccid(
102571     p_code_combination_id          => l_ccid
102572   , p_value_type_code              => l_adr_value_type_code
102573   , p_transaction_coa_id           => l_adr_transaction_coa_id
102574   , p_accounting_coa_id            => l_adr_accounting_coa_id
102575   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
102576   , p_adr_type_code                => 'S'
102577   , p_component_type               => l_component_type
102578   , p_component_code               => l_component_code
102579   , p_component_type_code          => l_component_type_code
102580   , p_component_appl_id            => l_component_appl_id
102581   , p_amb_context_code             => l_amb_context_code
102582   , p_side                         => 'NA'
102583   );
102584 
102585 
102586    l_segment := AcctDerRule_144(
102587            p_application_id           => p_application_id
102588          , p_ae_header_id             => l_ae_header_id 
102589 , p_source_3 => p_source_3
102590 , p_source_4 => p_source_4
102591          , x_transaction_coa_id       => l_adr_transaction_coa_id
102592          , x_accounting_coa_id        => l_adr_accounting_coa_id
102593          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
102594          , x_flex_value_set_id        => l_adr_flex_value_set_id
102595          , x_value_type_code          => l_adr_value_type_code
102596          , x_value_combination_id     => l_adr_value_combination_id
102597          , x_value_segment_code       => l_adr_value_segment_code
102598          , p_side                     => 'NA'
102599          , p_override_seg_flag        => 'Y'
102600    );
102601 
102602    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
102603 
102604       xla_ae_lines_pkg.set_segment(
102605           p_to_segment_code         => 'GL_ACCOUNT'
102606         , p_segment_value           => l_segment
102607         , p_from_segment_code       => l_adr_value_segment_code
102608         , p_from_combination_id     => l_adr_value_combination_id
102609         , p_value_type_code         => l_adr_value_type_code
102610         , p_transaction_coa_id      => l_adr_transaction_coa_id
102611         , p_accounting_coa_id       => l_adr_accounting_coa_id
102612         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
102613         , p_flex_value_set_id       => l_adr_flex_value_set_id
102614         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
102615         , p_adr_type_code           => 'S'
102616         , p_component_type          => l_component_type
102617         , p_component_code          => l_component_code
102618         , p_component_type_code     => l_component_type_code
102619         , p_component_appl_id       => l_component_appl_id
102620         , p_amb_context_code        => l_amb_context_code
102621         , p_entity_code             => 'TRANSACTIONS'
102622         , p_event_class_code        => 'RETIREMENTS'
102623         , p_side                    => 'NA'
102624         );
102625 
102626   END IF;
102627 
102628    l_segment := AcctDerRule_168(
102629            p_application_id           => p_application_id
102630          , p_ae_header_id             => l_ae_header_id 
102631 , p_source_3 => p_source_3
102632 , p_source_29 => p_source_29
102633          , x_transaction_coa_id       => l_adr_transaction_coa_id
102634          , x_accounting_coa_id        => l_adr_accounting_coa_id
102635          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
102636          , x_flex_value_set_id        => l_adr_flex_value_set_id
102637          , x_value_type_code          => l_adr_value_type_code
102638          , x_value_combination_id     => l_adr_value_combination_id
102639          , x_value_segment_code       => l_adr_value_segment_code
102640          , p_side                     => 'NA'
102641          , p_override_seg_flag        => 'Y'
102642    );
102643 
102644    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
102645 
102646       xla_ae_lines_pkg.set_segment(
102647           p_to_segment_code         => 'GL_BALANCING'
102648         , p_segment_value           => l_segment
102649         , p_from_segment_code       => l_adr_value_segment_code
102650         , p_from_combination_id     => l_adr_value_combination_id
102651         , p_value_type_code         => l_adr_value_type_code
102652         , p_transaction_coa_id      => l_adr_transaction_coa_id
102653         , p_accounting_coa_id       => l_adr_accounting_coa_id
102654         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
102655         , p_flex_value_set_id       => l_adr_flex_value_set_id
102656         , p_adr_code                => 'FA_EXPENSE_ACCT'
102657         , p_adr_type_code           => 'S'
102658         , p_component_type          => l_component_type
102659         , p_component_code          => l_component_code
102660         , p_component_type_code     => l_component_type_code
102661         , p_component_appl_id       => l_component_appl_id
102662         , p_amb_context_code        => l_amb_context_code
102663         , p_entity_code             => 'TRANSACTIONS'
102664         , p_event_class_code        => 'RETIREMENTS'
102665         , p_side                    => 'NA'
102666         );
102667 
102668   END IF;
102669 
102670    --
102671    --
102672    END IF;
102673    --
102674    -- Bug 4922099
102675    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
102676           (NVL(l_enc_upg_option, 'N') = 'O')
102677         ) AND
102678         (l_bflow_method_code = 'PRIOR_ENTRY')
102679       )
102680    THEN
102681       IF
102682       --
102683       1 = 2
102684       --
102685       THEN
102686       xla_accounting_err_pkg.build_message
102687                                     (p_appli_s_name            => 'XLA'
102688                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
102692                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
102689                                     ,p_token_1                 => 'LINE_NUMBER'
102690                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
102691                                     ,p_token_2                 => 'LINE_TYPE_NAME'
102693                                                                              l_component_type
102694                                                                             ,l_component_code
102695                                                                             ,l_component_type_code
102696                                                                             ,l_component_appl_id
102697                                                                             ,l_amb_context_code
102698                                                                             ,l_entity_code
102699                                                                             ,l_event_class_code
102700                                                                            )
102701                                     ,p_token_3                 => 'OWNER'
102702                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
102703                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
102704                                                                           ,p_lookup_code    => l_component_type_code
102705                                                                          )
102706                                     ,p_token_4                 => 'PRODUCT_NAME'
102707                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
102708                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
102709                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
102710                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
102711                                     ,p_ae_header_id            =>  NULL
102712                                        );
102713 
102714         IF (C_LEVEL_ERROR>= g_log_level) THEN
102715                  trace
102716                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
102717                       ,p_level    => C_LEVEL_ERROR
102718                       ,p_module   => l_log_module);
102719         END IF;
102720       END IF;
102721    END IF;
102722    --
102723    --
102724    ------------------------------------------------------------------------------------------------
102725    -- 4219869 Business Flow
102726    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
102727    -- Prior Entry.  Currently, the following code is always generated.
102728    ------------------------------------------------------------------------------------------------
102729    XLA_AE_LINES_PKG.ValidateCurrentLine;
102730 
102731    ------------------------------------------------------------------------------------
102732    -- 4219869 Business Flow
102733    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
102734    ------------------------------------------------------------------------------------
102735    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
102736 
102737    ----------------------------------------------------------------------------------
102738    -- 4219869 Business Flow
102739    -- Update journal entry status -- Need to generate this within IF <condition>
102740    ----------------------------------------------------------------------------------
102741    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
102742          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
102743          ,p_balance_type_code => l_balance_type_code
102744          );
102745 
102746    -------------------------------------------------------------------------------------------
102747    -- 4262811 - Generate the Accrual Reversal lines
102748    -------------------------------------------------------------------------------------------
102749    BEGIN
102750       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
102751                               (g_array_event(p_event_id).array_value_num('header_index'));
102752       IF l_acc_rev_flag IS NULL THEN
102753          l_acc_rev_flag := 'N';
102754       END IF;
102755    EXCEPTION
102756       WHEN OTHERS THEN
102757          l_acc_rev_flag := 'N';
102758    END;
102759    --
102760    IF (l_acc_rev_flag = 'Y') THEN
102761 
102762        -- 4645092  ------------------------------------------------------------------------------
102763        -- To allow MPA report to determine if it should generate report process
102764        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
102765        ------------------------------------------------------------------------------------------
102766 
102767        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
102768        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
102769    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
102770    -- call ADRs
102771    -- Bug 4922099
102772    --
102773    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
102774         (NVL(l_actual_upg_option, 'N') = 'O') OR
102775         (NVL(l_enc_upg_option, 'N') = 'O')
102776       )
102777    THEN
102778    NULL;
102779    --
102780    --
102781    
102782   l_ccid := AcctDerRule_174(
102783            p_application_id           => p_application_id
102784          , p_ae_header_id             => l_ae_header_id 
102785 , p_source_3 => p_source_3
102786 , p_source_17 => p_source_17
102787 , p_source_30 => p_source_30
102788          , x_transaction_coa_id       => l_adr_transaction_coa_id
102789          , x_accounting_coa_id        => l_adr_accounting_coa_id
102790          , x_value_type_code          => l_adr_value_type_code
102794    xla_ae_lines_pkg.set_ccid(
102791          , p_side                     => 'NA'
102792    );
102793 
102795     p_code_combination_id          => l_ccid
102796   , p_value_type_code              => l_adr_value_type_code
102797   , p_transaction_coa_id           => l_adr_transaction_coa_id
102798   , p_accounting_coa_id            => l_adr_accounting_coa_id
102799   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
102800   , p_adr_type_code                => 'S'
102801   , p_component_type               => l_component_type
102802   , p_component_code               => l_component_code
102803   , p_component_type_code          => l_component_type_code
102804   , p_component_appl_id            => l_component_appl_id
102805   , p_amb_context_code             => l_amb_context_code
102806   , p_side                         => 'NA'
102807   );
102808 
102809 
102810    l_segment := AcctDerRule_144(
102811            p_application_id           => p_application_id
102812          , p_ae_header_id             => l_ae_header_id 
102813 , p_source_3 => p_source_3
102814 , p_source_4 => p_source_4
102815          , x_transaction_coa_id       => l_adr_transaction_coa_id
102816          , x_accounting_coa_id        => l_adr_accounting_coa_id
102817          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
102818          , x_flex_value_set_id        => l_adr_flex_value_set_id
102819          , x_value_type_code          => l_adr_value_type_code
102820          , x_value_combination_id     => l_adr_value_combination_id
102821          , x_value_segment_code       => l_adr_value_segment_code
102822          , p_side                     => 'NA'
102823          , p_override_seg_flag        => 'Y'
102824    );
102825 
102826    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
102827 
102828       xla_ae_lines_pkg.set_segment(
102829           p_to_segment_code         => 'GL_ACCOUNT'
102830         , p_segment_value           => l_segment
102831         , p_from_segment_code       => l_adr_value_segment_code
102832         , p_from_combination_id     => l_adr_value_combination_id
102833         , p_value_type_code         => l_adr_value_type_code
102834         , p_transaction_coa_id      => l_adr_transaction_coa_id
102835         , p_accounting_coa_id       => l_adr_accounting_coa_id
102836         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
102837         , p_flex_value_set_id       => l_adr_flex_value_set_id
102838         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
102839         , p_adr_type_code           => 'S'
102840         , p_component_type          => l_component_type
102841         , p_component_code          => l_component_code
102842         , p_component_type_code     => l_component_type_code
102843         , p_component_appl_id       => l_component_appl_id
102844         , p_amb_context_code        => l_amb_context_code
102845         , p_entity_code             => 'TRANSACTIONS'
102846         , p_event_class_code        => 'RETIREMENTS'
102847         , p_side                    => 'NA'
102848         );
102849 
102850   END IF;
102851 
102852    l_segment := AcctDerRule_168(
102853            p_application_id           => p_application_id
102854          , p_ae_header_id             => l_ae_header_id 
102855 , p_source_3 => p_source_3
102856 , p_source_29 => p_source_29
102857          , x_transaction_coa_id       => l_adr_transaction_coa_id
102858          , x_accounting_coa_id        => l_adr_accounting_coa_id
102859          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
102860          , x_flex_value_set_id        => l_adr_flex_value_set_id
102861          , x_value_type_code          => l_adr_value_type_code
102862          , x_value_combination_id     => l_adr_value_combination_id
102863          , x_value_segment_code       => l_adr_value_segment_code
102864          , p_side                     => 'NA'
102865          , p_override_seg_flag        => 'Y'
102866    );
102867 
102868    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
102869 
102870       xla_ae_lines_pkg.set_segment(
102871           p_to_segment_code         => 'GL_BALANCING'
102872         , p_segment_value           => l_segment
102873         , p_from_segment_code       => l_adr_value_segment_code
102874         , p_from_combination_id     => l_adr_value_combination_id
102875         , p_value_type_code         => l_adr_value_type_code
102876         , p_transaction_coa_id      => l_adr_transaction_coa_id
102877         , p_accounting_coa_id       => l_adr_accounting_coa_id
102878         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
102879         , p_flex_value_set_id       => l_adr_flex_value_set_id
102880         , p_adr_code                => 'FA_EXPENSE_ACCT'
102881         , p_adr_type_code           => 'S'
102882         , p_component_type          => l_component_type
102883         , p_component_code          => l_component_code
102884         , p_component_type_code     => l_component_type_code
102885         , p_component_appl_id       => l_component_appl_id
102886         , p_amb_context_code        => l_amb_context_code
102887         , p_entity_code             => 'TRANSACTIONS'
102888         , p_event_class_code        => 'RETIREMENTS'
102889         , p_side                    => 'NA'
102890         );
102891 
102892   END IF;
102893 
102894    --
102895    --
102896    END IF;
102897 
102898        --
102899        -- Update the line information that should be overwritten
102900        --
102901        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
102902                                          p_header_num   => 1);
102903        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
102904 
102905        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
102906 
102907        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
102908           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
102909        END IF;
102913       --
102910 
102911       --
102912       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
102914       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
102915           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
102916       ELSE
102917           ---------------------------------------------------------------------------------------------------
102918           -- 4262811a Switch Sign
102919           ---------------------------------------------------------------------------------------------------
102920           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
102921           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
102922                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
102923           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
102924                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
102925           -- 5132302
102926           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
102927                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
102928 
102929       END IF;
102930 
102931       -- 4955764
102932       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
102933       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
102934 
102935 
102936       XLA_AE_LINES_PKG.ValidateCurrentLine;
102937       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
102938 
102939       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
102940                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
102941                ,p_balance_type_code => l_balance_type_code);
102942 
102943    END IF;
102944 
102945    -----------------------------------------------------------------------------------------
102946    -- 4262811 Multiperiod Accounting
102947    -----------------------------------------------------------------------------------------
102948      -- No MPA option is assigned.
102949 
102950 
102951 END IF;
102952 END IF;
102953 --
102954 
102955 --
102956 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
102957    trace
102958       (p_msg      => 'END of AcctLineType_297'
102959       ,p_level    => C_LEVEL_PROCEDURE
102960       ,p_module   => l_log_module);
102961 END IF;
102962 --
102963 EXCEPTION
102964   WHEN xla_exceptions_pkg.application_exception THEN
102965       RAISE;
102966   WHEN OTHERS THEN
102967        xla_exceptions_pkg.raise_message
102968            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_297');
102969 END AcctLineType_297;
102970 --
102971 
102972 ---------------------------------------
102973 --
102974 -- PRIVATE FUNCTION
102975 --         AcctLineType_298
102976 --
102977 ---------------------------------------
102978 PROCEDURE AcctLineType_298 (
102979   p_application_id        IN NUMBER
102980  ,p_event_id              IN NUMBER
102981  ,p_calculate_acctd_flag  IN VARCHAR2
102982  ,p_calculate_g_l_flag    IN VARCHAR2
102983  ,p_actual_flag           IN OUT VARCHAR2
102984  ,p_balance_type_code     OUT VARCHAR2
102985  ,p_gain_or_loss_ref      OUT VARCHAR2
102986  
102987 --Period Close Date
102988  , p_source_1            IN DATE
102989 --Generated Code Combination Identifier
102990  , p_source_3            IN NUMBER
102991 --Bonus Reserve Account
102992  , p_source_4            IN VARCHAR2
102993 --Generated Offset Code Combination Identifier
102994  , p_source_17            IN NUMBER
102995 --Expense Account Code Combination Identifier
102996  , p_source_29            IN NUMBER
102997 --Default Code Combination Identifier
102998  , p_source_30            IN NUMBER
102999 --Adjustment Type
103000  , p_source_35            IN VARCHAR2
103001 --Transaction Header Identifier
103002  , p_source_36            IN NUMBER
103003 --Adjustment Line Identifier
103004  , p_source_37            IN NUMBER
103005 --Distribution Type Code
103006  , p_source_38            IN VARCHAR2
103007 --Entered Amount
103008  , p_source_39            IN NUMBER
103009 --Currency Code
103010  , p_source_40            IN VARCHAR2
103011 )
103012 IS
103013 
103014 l_component_type              VARCHAR2(80);
103015 l_component_code              VARCHAR2(30);
103016 l_component_type_code         VARCHAR2(1);
103017 l_component_appl_id           INTEGER;
103018 l_amb_context_code            VARCHAR2(30);
103019 l_entity_code                 VARCHAR2(30);
103020 l_event_class_code            VARCHAR2(30);
103021 l_ae_header_id                NUMBER;
103022 l_event_type_code             VARCHAR2(30);
103023 l_line_definition_code        VARCHAR2(30);
103024 l_line_definition_owner_code  VARCHAR2(1);
103025 --
103026 -- adr variables
103027 l_segment                     VARCHAR2(30);
103028 l_ccid                        NUMBER;
103029 l_adr_transaction_coa_id      NUMBER;
103030 l_adr_accounting_coa_id       NUMBER;
103031 l_adr_flexfield_segment_code  VARCHAR2(30);
103032 l_adr_flex_value_set_id       NUMBER;
103033 l_adr_value_type_code         VARCHAR2(30);
103034 l_adr_value_combination_id    NUMBER;
103035 l_adr_value_segment_code      VARCHAR2(30);
103036 
103037 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
103038 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
103039 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
103040 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
103041 
103042 -- 4262811 Variables ------------------------------------------------------------------------------------------
103043 l_entered_amt_idx             NUMBER;
103047 l_tmp_amt                     NUMBER;
103044 l_accted_amt_idx              NUMBER;
103045 l_acc_rev_flag                VARCHAR2(1);
103046 l_accrual_line_num            NUMBER;
103048 l_acc_rev_natural_side_code   VARCHAR2(1);
103049 
103050 l_num_entries                 NUMBER;
103051 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
103052 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
103053 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
103054 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
103055 l_recog_line_1                NUMBER;
103056 l_recog_line_2                NUMBER;
103057 
103058 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
103059 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
103060 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
103061 
103062 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
103063 
103064 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
103065 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
103066 
103067 ---------------------------------------------------------------------------------------------------------------
103068 
103069 
103070 --
103071 -- bulk performance
103072 --
103073 l_balance_type_code           VARCHAR2(1);
103074 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
103075 l_log_module                  VARCHAR2(240);
103076 
103077 --
103078 -- Upgrade strategy
103079 --
103080 l_actual_upg_option           VARCHAR2(1);
103081 l_enc_upg_option           VARCHAR2(1);
103082 
103083 --
103084 BEGIN
103085 --
103086 IF g_log_enabled THEN
103087       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_298';
103088 END IF;
103089 --
103090 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
103091 
103092       trace
103093          (p_msg      => 'BEGIN of AcctLineType_298'
103094          ,p_level    => C_LEVEL_PROCEDURE
103095          ,p_module   => l_log_module);
103096 
103097 END IF;
103098 --
103099 l_component_type             := 'AMB_JLT';
103100 l_component_code             := 'FA_RETIREMENT_BONUS_DEPRN_RES';
103101 l_component_type_code        := 'S';
103102 l_component_appl_id          :=  140;
103103 l_amb_context_code           := 'DEFAULT';
103104 l_entity_code                := 'TRANSACTIONS';
103105 l_event_class_code           := 'RETIREMENTS';
103106 l_event_type_code            := 'RETIREMENTS';
103107 l_line_definition_owner_code := 'S';
103108 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
103109 --
103110 l_balance_type_code          := 'A';
103111 l_segment                     := NULL;
103112 l_ccid                        := NULL;
103113 l_adr_transaction_coa_id      := NULL;
103114 l_adr_accounting_coa_id       := NULL;
103115 l_adr_flexfield_segment_code  := NULL;
103116 l_adr_flex_value_set_id       := NULL;
103117 l_adr_value_type_code         := NULL;
103118 l_adr_value_combination_id    := NULL;
103119 l_adr_value_segment_code      := NULL;
103120 
103121 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
103122 l_bflow_class_code           := '';    -- 4219869 Business Flow
103123 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
103124 l_budgetary_control_flag     := 'N';
103125 
103126 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
103127 l_bflow_applied_to_amt       := NULL; -- 5132302
103128 l_entered_amt_idx            := NULL;          -- 4262811
103129 l_accted_amt_idx             := NULL;          -- 4262811
103130 l_acc_rev_flag               := NULL;          -- 4262811
103131 l_accrual_line_num           := NULL;          -- 4262811
103132 l_tmp_amt                    := NULL;          -- 4262811
103133 --
103134  
103135 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
103136     l_balance_type_code <> 'B' THEN
103137 IF NVL(p_source_35,'
103138 ') =  'BONUS EXPENSE'
103139  THEN 
103140 
103141    --
103142    XLA_AE_LINES_PKG.SetNewLine;
103143 
103144    p_balance_type_code          := l_balance_type_code;
103145    -- set the flag so later we will know whether the gain loss line needs to be created
103146    
103147    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
103148      p_actual_flag :='A';
103149    END IF;
103150 
103151    --
103152    -- bulk performance
103153    --
103154    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
103155                                       p_header_num   => 0); -- 4262811
103156    --
103157    -- set accounting line options
103158    --
103159    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
103160            p_natural_side_code          => 'D'
103161          , p_gain_or_loss_flag          => 'N'
103162          , p_gl_transfer_mode_code      => 'S'
103163          , p_acct_entry_type_code       => 'A'
103164          , p_switch_side_flag           => 'Y'
103165          , p_merge_duplicate_code       => 'N'
103166          );
103167    --
103168    l_acc_rev_natural_side_code := 'C';  -- 4262811
103169    -- 
103170    --
103171    -- set accounting line type info
103172    --
103173    xla_ae_lines_pkg.SetAcctLineType
103174       (p_component_type             => l_component_type
103175       ,p_event_type_code            => l_event_type_code
103176       ,p_line_definition_owner_code => l_line_definition_owner_code
103177       ,p_line_definition_code       => l_line_definition_code
103178       ,p_accounting_line_code       => l_component_code
103179       ,p_accounting_line_type_code  => l_component_type_code
103180       ,p_accounting_line_appl_id    => l_component_appl_id
103181       ,p_amb_context_code           => l_amb_context_code
103182       ,p_entity_code                => l_entity_code
103186    --
103183       ,p_event_class_code           => l_event_class_code);
103184    --
103185    -- set accounting class
103187    xla_ae_lines_pkg.SetAcctClass(
103188            p_accounting_class_code  => 'ASSET'
103189          , p_ae_header_id           => l_ae_header_id
103190          );
103191 
103192    --
103193    -- set rounding class
103194    --
103195    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
103196                       'ASSET';
103197 
103198    --
103199    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
103200    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
103201    --
103202    -- bulk performance
103203    --
103204    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
103205 
103206    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
103207       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
103208 
103209    -- 4955764
103210    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
103211       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
103212 
103213    -- 4458381 Public Sector Enh
103214    
103215    --
103216    -- set accounting attributes for the line type
103217    --
103218    l_entered_amt_idx := 4;
103219    l_accted_amt_idx  := 6;
103220    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
103221    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
103222    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
103223    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
103224    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
103225    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
103226    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
103227    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
103228    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
103229    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
103230    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
103231    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
103232    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
103233 
103234    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
103235    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
103236 
103237    ---------------------------------------------------------------------------------------------------------------
103238    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
103239    ---------------------------------------------------------------------------------------------------------------
103240    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
103241 
103242    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
103243    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
103244 
103245    IF xla_accounting_cache_pkg.GetValueChar
103246          (p_source_code         => 'LEDGER_CATEGORY_CODE'
103247          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
103248    AND l_bflow_method_code = 'PRIOR_ENTRY'
103249 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
103250    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
103251          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
103252        )
103253    THEN
103254          xla_ae_lines_pkg.BflowUpgEntry
103255            (p_business_method_code    => l_bflow_method_code
103256            ,p_business_class_code     => l_bflow_class_code
103257            ,p_balance_type            => l_balance_type_code);
103258    ELSE
103259       NULL;
103260 -- No business flow processing for business flow method of NONE.
103261    END IF;
103262 
103263    --
103264    -- call analytical criteria
103265    --
103266    
103267    --
103268    -- call description
103269    --
103270    
103271 xla_ae_lines_pkg.SetLineDescription(
103272    p_ae_header_id => l_ae_header_id
103273   ,p_description  => Description_76 (
103274      p_application_id         => p_application_id
103275    , p_ae_header_id           => l_ae_header_id 
103276 , p_source_1 => p_source_1
103277    )
103278 );
103279 
103280 
103281    --
103282    -- call ADRs
103283    -- Bug 4922099
103284    --
103285    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
103286         (NVL(l_actual_upg_option, 'N') = 'O') OR
103287         (NVL(l_enc_upg_option, 'N') = 'O')
103288       )
103289    THEN
103290    NULL;
103291    --
103292    --
103293    
103294   l_ccid := AcctDerRule_174(
103295            p_application_id           => p_application_id
103296          , p_ae_header_id             => l_ae_header_id 
103297 , p_source_3 => p_source_3
103298 , p_source_17 => p_source_17
103299 , p_source_30 => p_source_30
103300          , x_transaction_coa_id       => l_adr_transaction_coa_id
103301          , x_accounting_coa_id        => l_adr_accounting_coa_id
103302          , x_value_type_code          => l_adr_value_type_code
103303          , p_side                     => 'NA'
103304    );
103305 
103306    xla_ae_lines_pkg.set_ccid(
103307     p_code_combination_id          => l_ccid
103308   , p_value_type_code              => l_adr_value_type_code
103309   , p_transaction_coa_id           => l_adr_transaction_coa_id
103310   , p_accounting_coa_id            => l_adr_accounting_coa_id
103311   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
103312   , p_adr_type_code                => 'S'
103316   , p_component_appl_id            => l_component_appl_id
103313   , p_component_type               => l_component_type
103314   , p_component_code               => l_component_code
103315   , p_component_type_code          => l_component_type_code
103317   , p_amb_context_code             => l_amb_context_code
103318   , p_side                         => 'NA'
103319   );
103320 
103321 
103322    l_segment := AcctDerRule_144(
103323            p_application_id           => p_application_id
103324          , p_ae_header_id             => l_ae_header_id 
103325 , p_source_3 => p_source_3
103326 , p_source_4 => p_source_4
103327          , x_transaction_coa_id       => l_adr_transaction_coa_id
103328          , x_accounting_coa_id        => l_adr_accounting_coa_id
103329          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
103330          , x_flex_value_set_id        => l_adr_flex_value_set_id
103331          , x_value_type_code          => l_adr_value_type_code
103332          , x_value_combination_id     => l_adr_value_combination_id
103333          , x_value_segment_code       => l_adr_value_segment_code
103334          , p_side                     => 'NA'
103335          , p_override_seg_flag        => 'Y'
103336    );
103337 
103338    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
103339 
103340       xla_ae_lines_pkg.set_segment(
103341           p_to_segment_code         => 'GL_ACCOUNT'
103342         , p_segment_value           => l_segment
103343         , p_from_segment_code       => l_adr_value_segment_code
103344         , p_from_combination_id     => l_adr_value_combination_id
103345         , p_value_type_code         => l_adr_value_type_code
103346         , p_transaction_coa_id      => l_adr_transaction_coa_id
103347         , p_accounting_coa_id       => l_adr_accounting_coa_id
103348         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
103349         , p_flex_value_set_id       => l_adr_flex_value_set_id
103350         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
103351         , p_adr_type_code           => 'S'
103352         , p_component_type          => l_component_type
103353         , p_component_code          => l_component_code
103354         , p_component_type_code     => l_component_type_code
103355         , p_component_appl_id       => l_component_appl_id
103356         , p_amb_context_code        => l_amb_context_code
103357         , p_entity_code             => 'TRANSACTIONS'
103358         , p_event_class_code        => 'RETIREMENTS'
103359         , p_side                    => 'NA'
103360         );
103361 
103362   END IF;
103363 
103364    l_segment := AcctDerRule_168(
103365            p_application_id           => p_application_id
103366          , p_ae_header_id             => l_ae_header_id 
103367 , p_source_3 => p_source_3
103368 , p_source_29 => p_source_29
103369          , x_transaction_coa_id       => l_adr_transaction_coa_id
103370          , x_accounting_coa_id        => l_adr_accounting_coa_id
103371          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
103372          , x_flex_value_set_id        => l_adr_flex_value_set_id
103373          , x_value_type_code          => l_adr_value_type_code
103374          , x_value_combination_id     => l_adr_value_combination_id
103375          , x_value_segment_code       => l_adr_value_segment_code
103376          , p_side                     => 'NA'
103377          , p_override_seg_flag        => 'Y'
103378    );
103379 
103380    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
103381 
103382       xla_ae_lines_pkg.set_segment(
103383           p_to_segment_code         => 'GL_BALANCING'
103384         , p_segment_value           => l_segment
103385         , p_from_segment_code       => l_adr_value_segment_code
103386         , p_from_combination_id     => l_adr_value_combination_id
103387         , p_value_type_code         => l_adr_value_type_code
103388         , p_transaction_coa_id      => l_adr_transaction_coa_id
103389         , p_accounting_coa_id       => l_adr_accounting_coa_id
103390         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
103391         , p_flex_value_set_id       => l_adr_flex_value_set_id
103392         , p_adr_code                => 'FA_EXPENSE_ACCT'
103393         , p_adr_type_code           => 'S'
103394         , p_component_type          => l_component_type
103395         , p_component_code          => l_component_code
103396         , p_component_type_code     => l_component_type_code
103397         , p_component_appl_id       => l_component_appl_id
103398         , p_amb_context_code        => l_amb_context_code
103399         , p_entity_code             => 'TRANSACTIONS'
103400         , p_event_class_code        => 'RETIREMENTS'
103401         , p_side                    => 'NA'
103402         );
103403 
103404   END IF;
103405 
103406    --
103407    --
103408    END IF;
103409    --
103410    -- Bug 4922099
103411    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
103412           (NVL(l_enc_upg_option, 'N') = 'O')
103413         ) AND
103414         (l_bflow_method_code = 'PRIOR_ENTRY')
103415       )
103416    THEN
103417       IF
103418       --
103419       1 = 2
103420       --
103421       THEN
103422       xla_accounting_err_pkg.build_message
103423                                     (p_appli_s_name            => 'XLA'
103424                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
103425                                     ,p_token_1                 => 'LINE_NUMBER'
103426                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
103427                                     ,p_token_2                 => 'LINE_TYPE_NAME'
103428                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
103429                                                                              l_component_type
103430                                                                             ,l_component_code
103434                                                                             ,l_entity_code
103431                                                                             ,l_component_type_code
103432                                                                             ,l_component_appl_id
103433                                                                             ,l_amb_context_code
103435                                                                             ,l_event_class_code
103436                                                                            )
103437                                     ,p_token_3                 => 'OWNER'
103438                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
103439                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
103440                                                                           ,p_lookup_code    => l_component_type_code
103441                                                                          )
103442                                     ,p_token_4                 => 'PRODUCT_NAME'
103443                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
103444                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
103445                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
103446                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
103447                                     ,p_ae_header_id            =>  NULL
103448                                        );
103449 
103450         IF (C_LEVEL_ERROR>= g_log_level) THEN
103451                  trace
103452                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
103453                       ,p_level    => C_LEVEL_ERROR
103454                       ,p_module   => l_log_module);
103455         END IF;
103456       END IF;
103457    END IF;
103458    --
103459    --
103460    ------------------------------------------------------------------------------------------------
103461    -- 4219869 Business Flow
103462    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
103463    -- Prior Entry.  Currently, the following code is always generated.
103464    ------------------------------------------------------------------------------------------------
103465    XLA_AE_LINES_PKG.ValidateCurrentLine;
103466 
103467    ------------------------------------------------------------------------------------
103468    -- 4219869 Business Flow
103469    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
103470    ------------------------------------------------------------------------------------
103471    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
103472 
103473    ----------------------------------------------------------------------------------
103474    -- 4219869 Business Flow
103475    -- Update journal entry status -- Need to generate this within IF <condition>
103476    ----------------------------------------------------------------------------------
103477    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
103478          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
103479          ,p_balance_type_code => l_balance_type_code
103480          );
103481 
103482    -------------------------------------------------------------------------------------------
103483    -- 4262811 - Generate the Accrual Reversal lines
103484    -------------------------------------------------------------------------------------------
103485    BEGIN
103486       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
103487                               (g_array_event(p_event_id).array_value_num('header_index'));
103488       IF l_acc_rev_flag IS NULL THEN
103489          l_acc_rev_flag := 'N';
103490       END IF;
103491    EXCEPTION
103492       WHEN OTHERS THEN
103493          l_acc_rev_flag := 'N';
103494    END;
103495    --
103496    IF (l_acc_rev_flag = 'Y') THEN
103497 
103498        -- 4645092  ------------------------------------------------------------------------------
103499        -- To allow MPA report to determine if it should generate report process
103500        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
103501        ------------------------------------------------------------------------------------------
103502 
103503        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
103504        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
103505    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
103506    -- call ADRs
103507    -- Bug 4922099
103508    --
103509    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
103510         (NVL(l_actual_upg_option, 'N') = 'O') OR
103511         (NVL(l_enc_upg_option, 'N') = 'O')
103512       )
103513    THEN
103514    NULL;
103515    --
103516    --
103517    
103518   l_ccid := AcctDerRule_174(
103519            p_application_id           => p_application_id
103520          , p_ae_header_id             => l_ae_header_id 
103521 , p_source_3 => p_source_3
103522 , p_source_17 => p_source_17
103523 , p_source_30 => p_source_30
103524          , x_transaction_coa_id       => l_adr_transaction_coa_id
103525          , x_accounting_coa_id        => l_adr_accounting_coa_id
103526          , x_value_type_code          => l_adr_value_type_code
103527          , p_side                     => 'NA'
103528    );
103529 
103530    xla_ae_lines_pkg.set_ccid(
103531     p_code_combination_id          => l_ccid
103532   , p_value_type_code              => l_adr_value_type_code
103533   , p_transaction_coa_id           => l_adr_transaction_coa_id
103534   , p_accounting_coa_id            => l_adr_accounting_coa_id
103535   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
103536   , p_adr_type_code                => 'S'
103537   , p_component_type               => l_component_type
103541   , p_amb_context_code             => l_amb_context_code
103538   , p_component_code               => l_component_code
103539   , p_component_type_code          => l_component_type_code
103540   , p_component_appl_id            => l_component_appl_id
103542   , p_side                         => 'NA'
103543   );
103544 
103545 
103546    l_segment := AcctDerRule_144(
103547            p_application_id           => p_application_id
103548          , p_ae_header_id             => l_ae_header_id 
103549 , p_source_3 => p_source_3
103550 , p_source_4 => p_source_4
103551          , x_transaction_coa_id       => l_adr_transaction_coa_id
103552          , x_accounting_coa_id        => l_adr_accounting_coa_id
103553          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
103554          , x_flex_value_set_id        => l_adr_flex_value_set_id
103555          , x_value_type_code          => l_adr_value_type_code
103556          , x_value_combination_id     => l_adr_value_combination_id
103557          , x_value_segment_code       => l_adr_value_segment_code
103558          , p_side                     => 'NA'
103559          , p_override_seg_flag        => 'Y'
103560    );
103561 
103562    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
103563 
103564       xla_ae_lines_pkg.set_segment(
103565           p_to_segment_code         => 'GL_ACCOUNT'
103566         , p_segment_value           => l_segment
103567         , p_from_segment_code       => l_adr_value_segment_code
103568         , p_from_combination_id     => l_adr_value_combination_id
103569         , p_value_type_code         => l_adr_value_type_code
103570         , p_transaction_coa_id      => l_adr_transaction_coa_id
103571         , p_accounting_coa_id       => l_adr_accounting_coa_id
103572         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
103573         , p_flex_value_set_id       => l_adr_flex_value_set_id
103574         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
103575         , p_adr_type_code           => 'S'
103576         , p_component_type          => l_component_type
103577         , p_component_code          => l_component_code
103578         , p_component_type_code     => l_component_type_code
103579         , p_component_appl_id       => l_component_appl_id
103580         , p_amb_context_code        => l_amb_context_code
103581         , p_entity_code             => 'TRANSACTIONS'
103582         , p_event_class_code        => 'RETIREMENTS'
103583         , p_side                    => 'NA'
103584         );
103585 
103586   END IF;
103587 
103588    l_segment := AcctDerRule_168(
103589            p_application_id           => p_application_id
103590          , p_ae_header_id             => l_ae_header_id 
103591 , p_source_3 => p_source_3
103592 , p_source_29 => p_source_29
103593          , x_transaction_coa_id       => l_adr_transaction_coa_id
103594          , x_accounting_coa_id        => l_adr_accounting_coa_id
103595          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
103596          , x_flex_value_set_id        => l_adr_flex_value_set_id
103597          , x_value_type_code          => l_adr_value_type_code
103598          , x_value_combination_id     => l_adr_value_combination_id
103599          , x_value_segment_code       => l_adr_value_segment_code
103600          , p_side                     => 'NA'
103601          , p_override_seg_flag        => 'Y'
103602    );
103603 
103604    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
103605 
103606       xla_ae_lines_pkg.set_segment(
103607           p_to_segment_code         => 'GL_BALANCING'
103608         , p_segment_value           => l_segment
103609         , p_from_segment_code       => l_adr_value_segment_code
103610         , p_from_combination_id     => l_adr_value_combination_id
103611         , p_value_type_code         => l_adr_value_type_code
103612         , p_transaction_coa_id      => l_adr_transaction_coa_id
103613         , p_accounting_coa_id       => l_adr_accounting_coa_id
103614         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
103615         , p_flex_value_set_id       => l_adr_flex_value_set_id
103616         , p_adr_code                => 'FA_EXPENSE_ACCT'
103617         , p_adr_type_code           => 'S'
103618         , p_component_type          => l_component_type
103619         , p_component_code          => l_component_code
103620         , p_component_type_code     => l_component_type_code
103621         , p_component_appl_id       => l_component_appl_id
103622         , p_amb_context_code        => l_amb_context_code
103623         , p_entity_code             => 'TRANSACTIONS'
103624         , p_event_class_code        => 'RETIREMENTS'
103625         , p_side                    => 'NA'
103626         );
103627 
103628   END IF;
103629 
103630    --
103631    --
103632    END IF;
103633 
103634        --
103635        -- Update the line information that should be overwritten
103636        --
103637        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
103638                                          p_header_num   => 1);
103639        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
103640 
103641        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
103642 
103643        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
103644           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
103645        END IF;
103646 
103647       --
103648       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
103649       --
103650       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
103651           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
103652       ELSE
103653           ---------------------------------------------------------------------------------------------------
103654           -- 4262811a Switch Sign
103658                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
103655           ---------------------------------------------------------------------------------------------------
103656           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
103657           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
103659           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
103660                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
103661           -- 5132302
103662           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
103663                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
103664 
103665       END IF;
103666 
103667       -- 4955764
103668       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
103669       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
103670 
103671 
103672       XLA_AE_LINES_PKG.ValidateCurrentLine;
103673       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
103674 
103675       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
103676                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
103677                ,p_balance_type_code => l_balance_type_code);
103678 
103679    END IF;
103680 
103681    -----------------------------------------------------------------------------------------
103682    -- 4262811 Multiperiod Accounting
103683    -----------------------------------------------------------------------------------------
103684      -- No MPA option is assigned.
103685 
103686 
103687 END IF;
103688 END IF;
103689 --
103690 
103691 --
103692 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
103693    trace
103694       (p_msg      => 'END of AcctLineType_298'
103695       ,p_level    => C_LEVEL_PROCEDURE
103696       ,p_module   => l_log_module);
103697 END IF;
103698 --
103699 EXCEPTION
103700   WHEN xla_exceptions_pkg.application_exception THEN
103701       RAISE;
103702   WHEN OTHERS THEN
103703        xla_exceptions_pkg.raise_message
103704            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_298');
103705 END AcctLineType_298;
103706 --
103707 
103708 ---------------------------------------
103709 --
103710 -- PRIVATE FUNCTION
103711 --         AcctLineType_299
103712 --
103713 ---------------------------------------
103714 PROCEDURE AcctLineType_299 (
103715   p_application_id        IN NUMBER
103716  ,p_event_id              IN NUMBER
103717  ,p_calculate_acctd_flag  IN VARCHAR2
103718  ,p_calculate_g_l_flag    IN VARCHAR2
103719  ,p_actual_flag           IN OUT VARCHAR2
103720  ,p_balance_type_code     OUT VARCHAR2
103721  ,p_gain_or_loss_ref      OUT VARCHAR2
103722  
103723 --Period Close Date
103724  , p_source_1            IN DATE
103725 --Generated Code Combination Identifier
103726  , p_source_3            IN NUMBER
103727 --Asset Cost Account
103728  , p_source_9            IN VARCHAR2
103729 --Expense Account Code Combination Identifier
103730  , p_source_29            IN NUMBER
103731 --Default Code Combination Identifier
103732  , p_source_30            IN NUMBER
103733 --Adjustment Type
103734  , p_source_35            IN VARCHAR2
103735 --Transaction Header Identifier
103736  , p_source_36            IN NUMBER
103737 --Adjustment Line Identifier
103738  , p_source_37            IN NUMBER
103739 --Distribution Type Code
103740  , p_source_38            IN VARCHAR2
103741 --Entered Amount
103742  , p_source_39            IN NUMBER
103743 --Currency Code
103744  , p_source_40            IN VARCHAR2
103745 )
103746 IS
103747 
103748 l_component_type              VARCHAR2(80);
103749 l_component_code              VARCHAR2(30);
103750 l_component_type_code         VARCHAR2(1);
103751 l_component_appl_id           INTEGER;
103752 l_amb_context_code            VARCHAR2(30);
103753 l_entity_code                 VARCHAR2(30);
103754 l_event_class_code            VARCHAR2(30);
103755 l_ae_header_id                NUMBER;
103756 l_event_type_code             VARCHAR2(30);
103757 l_line_definition_code        VARCHAR2(30);
103758 l_line_definition_owner_code  VARCHAR2(1);
103759 --
103760 -- adr variables
103761 l_segment                     VARCHAR2(30);
103762 l_ccid                        NUMBER;
103763 l_adr_transaction_coa_id      NUMBER;
103764 l_adr_accounting_coa_id       NUMBER;
103765 l_adr_flexfield_segment_code  VARCHAR2(30);
103766 l_adr_flex_value_set_id       NUMBER;
103767 l_adr_value_type_code         VARCHAR2(30);
103768 l_adr_value_combination_id    NUMBER;
103769 l_adr_value_segment_code      VARCHAR2(30);
103770 
103771 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
103772 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
103773 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
103774 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
103775 
103776 -- 4262811 Variables ------------------------------------------------------------------------------------------
103777 l_entered_amt_idx             NUMBER;
103778 l_accted_amt_idx              NUMBER;
103779 l_acc_rev_flag                VARCHAR2(1);
103780 l_accrual_line_num            NUMBER;
103781 l_tmp_amt                     NUMBER;
103782 l_acc_rev_natural_side_code   VARCHAR2(1);
103783 
103784 l_num_entries                 NUMBER;
103785 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
103786 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
103787 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
103788 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
103789 l_recog_line_1                NUMBER;
103793 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
103790 l_recog_line_2                NUMBER;
103791 
103792 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
103794 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
103795 
103796 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
103797 
103798 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
103799 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
103800 
103801 ---------------------------------------------------------------------------------------------------------------
103802 
103803 
103804 --
103805 -- bulk performance
103806 --
103807 l_balance_type_code           VARCHAR2(1);
103808 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
103809 l_log_module                  VARCHAR2(240);
103810 
103811 --
103812 -- Upgrade strategy
103813 --
103814 l_actual_upg_option           VARCHAR2(1);
103815 l_enc_upg_option           VARCHAR2(1);
103816 
103817 --
103818 BEGIN
103819 --
103820 IF g_log_enabled THEN
103821       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_299';
103822 END IF;
103823 --
103824 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
103825 
103826       trace
103827          (p_msg      => 'BEGIN of AcctLineType_299'
103828          ,p_level    => C_LEVEL_PROCEDURE
103829          ,p_module   => l_log_module);
103830 
103831 END IF;
103832 --
103833 l_component_type             := 'AMB_JLT';
103834 l_component_code             := 'FA_RETIREMENT_COST';
103835 l_component_type_code        := 'S';
103836 l_component_appl_id          :=  140;
103837 l_amb_context_code           := 'DEFAULT';
103838 l_entity_code                := 'TRANSACTIONS';
103839 l_event_class_code           := 'RETIREMENTS';
103840 l_event_type_code            := 'RETIREMENTS';
103841 l_line_definition_owner_code := 'S';
103842 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
103843 --
103844 l_balance_type_code          := 'A';
103845 l_segment                     := NULL;
103846 l_ccid                        := NULL;
103847 l_adr_transaction_coa_id      := NULL;
103848 l_adr_accounting_coa_id       := NULL;
103849 l_adr_flexfield_segment_code  := NULL;
103850 l_adr_flex_value_set_id       := NULL;
103851 l_adr_value_type_code         := NULL;
103852 l_adr_value_combination_id    := NULL;
103853 l_adr_value_segment_code      := NULL;
103854 
103855 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
103856 l_bflow_class_code           := '';    -- 4219869 Business Flow
103857 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
103858 l_budgetary_control_flag     := 'N';
103859 
103860 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
103861 l_bflow_applied_to_amt       := NULL; -- 5132302
103862 l_entered_amt_idx            := NULL;          -- 4262811
103863 l_accted_amt_idx             := NULL;          -- 4262811
103864 l_acc_rev_flag               := NULL;          -- 4262811
103865 l_accrual_line_num           := NULL;          -- 4262811
103866 l_tmp_amt                    := NULL;          -- 4262811
103867 --
103868  
103869 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
103870     l_balance_type_code <> 'B' THEN
103871 IF NVL(p_source_35,'
103872 ') =  'COST'
103873  THEN 
103874 
103875    --
103876    XLA_AE_LINES_PKG.SetNewLine;
103877 
103878    p_balance_type_code          := l_balance_type_code;
103879    -- set the flag so later we will know whether the gain loss line needs to be created
103880    
103881    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
103882      p_actual_flag :='A';
103883    END IF;
103884 
103885    --
103886    -- bulk performance
103887    --
103888    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
103889                                       p_header_num   => 0); -- 4262811
103890    --
103891    -- set accounting line options
103892    --
103893    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
103894            p_natural_side_code          => 'C'
103895          , p_gain_or_loss_flag          => 'N'
103896          , p_gl_transfer_mode_code      => 'S'
103897          , p_acct_entry_type_code       => 'A'
103898          , p_switch_side_flag           => 'Y'
103899          , p_merge_duplicate_code       => 'N'
103900          );
103901    --
103902    l_acc_rev_natural_side_code := 'D';  -- 4262811
103903    -- 
103904    --
103905    -- set accounting line type info
103906    --
103907    xla_ae_lines_pkg.SetAcctLineType
103908       (p_component_type             => l_component_type
103909       ,p_event_type_code            => l_event_type_code
103910       ,p_line_definition_owner_code => l_line_definition_owner_code
103911       ,p_line_definition_code       => l_line_definition_code
103912       ,p_accounting_line_code       => l_component_code
103913       ,p_accounting_line_type_code  => l_component_type_code
103914       ,p_accounting_line_appl_id    => l_component_appl_id
103915       ,p_amb_context_code           => l_amb_context_code
103916       ,p_entity_code                => l_entity_code
103917       ,p_event_class_code           => l_event_class_code);
103918    --
103919    -- set accounting class
103920    --
103921    xla_ae_lines_pkg.SetAcctClass(
103922            p_accounting_class_code  => 'ASSET'
103923          , p_ae_header_id           => l_ae_header_id
103924          );
103925 
103926    --
103927    -- set rounding class
103928    --
103929    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
103930                       'ASSET';
103931 
103932    --
103936    -- bulk performance
103933    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
103934    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
103935    --
103937    --
103938    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
103939 
103940    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
103941       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
103942 
103943    -- 4955764
103944    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
103945       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
103946 
103947    -- 4458381 Public Sector Enh
103948    
103949    --
103950    -- set accounting attributes for the line type
103951    --
103952    l_entered_amt_idx := 4;
103953    l_accted_amt_idx  := 6;
103954    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
103955    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
103956    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
103957    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
103958    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
103959    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
103960    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
103961    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
103962    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
103963    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
103964    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
103965    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
103966    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
103967 
103968    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
103969    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
103970 
103971    ---------------------------------------------------------------------------------------------------------------
103972    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
103973    ---------------------------------------------------------------------------------------------------------------
103974    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
103975 
103976    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
103977    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
103978 
103979    IF xla_accounting_cache_pkg.GetValueChar
103980          (p_source_code         => 'LEDGER_CATEGORY_CODE'
103981          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
103982    AND l_bflow_method_code = 'PRIOR_ENTRY'
103983 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
103984    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
103985          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
103986        )
103987    THEN
103988          xla_ae_lines_pkg.BflowUpgEntry
103989            (p_business_method_code    => l_bflow_method_code
103990            ,p_business_class_code     => l_bflow_class_code
103991            ,p_balance_type            => l_balance_type_code);
103992    ELSE
103993       NULL;
103994 -- No business flow processing for business flow method of NONE.
103995    END IF;
103996 
103997    --
103998    -- call analytical criteria
103999    --
104000    
104001    --
104002    -- call description
104003    --
104004    
104005 xla_ae_lines_pkg.SetLineDescription(
104006    p_ae_header_id => l_ae_header_id
104007   ,p_description  => Description_77 (
104008      p_application_id         => p_application_id
104009    , p_ae_header_id           => l_ae_header_id 
104010 , p_source_1 => p_source_1
104011    )
104012 );
104013 
104014 
104015    --
104016    -- call ADRs
104017    -- Bug 4922099
104018    --
104019    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
104020         (NVL(l_actual_upg_option, 'N') = 'O') OR
104021         (NVL(l_enc_upg_option, 'N') = 'O')
104022       )
104023    THEN
104024    NULL;
104025    --
104026    --
104027    
104028   l_ccid := AcctDerRule_173(
104029            p_application_id           => p_application_id
104030          , p_ae_header_id             => l_ae_header_id 
104031 , p_source_3 => p_source_3
104032 , p_source_30 => p_source_30
104033          , x_transaction_coa_id       => l_adr_transaction_coa_id
104034          , x_accounting_coa_id        => l_adr_accounting_coa_id
104035          , x_value_type_code          => l_adr_value_type_code
104036          , p_side                     => 'NA'
104037    );
104038 
104039    xla_ae_lines_pkg.set_ccid(
104040     p_code_combination_id          => l_ccid
104041   , p_value_type_code              => l_adr_value_type_code
104042   , p_transaction_coa_id           => l_adr_transaction_coa_id
104043   , p_accounting_coa_id            => l_adr_accounting_coa_id
104044   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
104045   , p_adr_type_code                => 'S'
104046   , p_component_type               => l_component_type
104047   , p_component_code               => l_component_code
104048   , p_component_type_code          => l_component_type_code
104049   , p_component_appl_id            => l_component_appl_id
104050   , p_amb_context_code             => l_amb_context_code
104051   , p_side                         => 'NA'
104052   );
104053 
104054 
104055    l_segment := AcctDerRule_148(
104056            p_application_id           => p_application_id
104057          , p_ae_header_id             => l_ae_header_id 
104058 , p_source_3 => p_source_3
104059 , p_source_9 => p_source_9
104063          , x_flex_value_set_id        => l_adr_flex_value_set_id
104060          , x_transaction_coa_id       => l_adr_transaction_coa_id
104061          , x_accounting_coa_id        => l_adr_accounting_coa_id
104062          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
104064          , x_value_type_code          => l_adr_value_type_code
104065          , x_value_combination_id     => l_adr_value_combination_id
104066          , x_value_segment_code       => l_adr_value_segment_code
104067          , p_side                     => 'NA'
104068          , p_override_seg_flag        => 'Y'
104069    );
104070 
104071    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
104072 
104073       xla_ae_lines_pkg.set_segment(
104074           p_to_segment_code         => 'GL_ACCOUNT'
104075         , p_segment_value           => l_segment
104076         , p_from_segment_code       => l_adr_value_segment_code
104077         , p_from_combination_id     => l_adr_value_combination_id
104078         , p_value_type_code         => l_adr_value_type_code
104079         , p_transaction_coa_id      => l_adr_transaction_coa_id
104080         , p_accounting_coa_id       => l_adr_accounting_coa_id
104081         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
104082         , p_flex_value_set_id       => l_adr_flex_value_set_id
104083         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
104084         , p_adr_type_code           => 'S'
104085         , p_component_type          => l_component_type
104086         , p_component_code          => l_component_code
104087         , p_component_type_code     => l_component_type_code
104088         , p_component_appl_id       => l_component_appl_id
104089         , p_amb_context_code        => l_amb_context_code
104090         , p_entity_code             => 'TRANSACTIONS'
104091         , p_event_class_code        => 'RETIREMENTS'
104092         , p_side                    => 'NA'
104093         );
104094 
104095   END IF;
104096 
104097    l_segment := AcctDerRule_168(
104098            p_application_id           => p_application_id
104099          , p_ae_header_id             => l_ae_header_id 
104100 , p_source_3 => p_source_3
104101 , p_source_29 => p_source_29
104102          , x_transaction_coa_id       => l_adr_transaction_coa_id
104103          , x_accounting_coa_id        => l_adr_accounting_coa_id
104104          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
104105          , x_flex_value_set_id        => l_adr_flex_value_set_id
104106          , x_value_type_code          => l_adr_value_type_code
104107          , x_value_combination_id     => l_adr_value_combination_id
104108          , x_value_segment_code       => l_adr_value_segment_code
104109          , p_side                     => 'NA'
104110          , p_override_seg_flag        => 'Y'
104111    );
104112 
104113    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
104114 
104115       xla_ae_lines_pkg.set_segment(
104116           p_to_segment_code         => 'GL_BALANCING'
104117         , p_segment_value           => l_segment
104118         , p_from_segment_code       => l_adr_value_segment_code
104119         , p_from_combination_id     => l_adr_value_combination_id
104120         , p_value_type_code         => l_adr_value_type_code
104121         , p_transaction_coa_id      => l_adr_transaction_coa_id
104122         , p_accounting_coa_id       => l_adr_accounting_coa_id
104123         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
104124         , p_flex_value_set_id       => l_adr_flex_value_set_id
104125         , p_adr_code                => 'FA_EXPENSE_ACCT'
104126         , p_adr_type_code           => 'S'
104127         , p_component_type          => l_component_type
104128         , p_component_code          => l_component_code
104129         , p_component_type_code     => l_component_type_code
104130         , p_component_appl_id       => l_component_appl_id
104131         , p_amb_context_code        => l_amb_context_code
104132         , p_entity_code             => 'TRANSACTIONS'
104133         , p_event_class_code        => 'RETIREMENTS'
104134         , p_side                    => 'NA'
104135         );
104136 
104137   END IF;
104138 
104139    --
104140    --
104141    END IF;
104142    --
104143    -- Bug 4922099
104144    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
104145           (NVL(l_enc_upg_option, 'N') = 'O')
104146         ) AND
104147         (l_bflow_method_code = 'PRIOR_ENTRY')
104148       )
104149    THEN
104150       IF
104151       --
104152       1 = 2
104153       --
104154       THEN
104155       xla_accounting_err_pkg.build_message
104156                                     (p_appli_s_name            => 'XLA'
104157                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
104158                                     ,p_token_1                 => 'LINE_NUMBER'
104159                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
104160                                     ,p_token_2                 => 'LINE_TYPE_NAME'
104161                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
104162                                                                              l_component_type
104163                                                                             ,l_component_code
104164                                                                             ,l_component_type_code
104165                                                                             ,l_component_appl_id
104166                                                                             ,l_amb_context_code
104167                                                                             ,l_entity_code
104168                                                                             ,l_event_class_code
104169                                                                            )
104170                                     ,p_token_3                 => 'OWNER'
104174                                                                          )
104171                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
104172                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
104173                                                                           ,p_lookup_code    => l_component_type_code
104175                                     ,p_token_4                 => 'PRODUCT_NAME'
104176                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
104177                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
104178                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
104179                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
104180                                     ,p_ae_header_id            =>  NULL
104181                                        );
104182 
104183         IF (C_LEVEL_ERROR>= g_log_level) THEN
104184                  trace
104185                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
104186                       ,p_level    => C_LEVEL_ERROR
104187                       ,p_module   => l_log_module);
104188         END IF;
104189       END IF;
104190    END IF;
104191    --
104192    --
104193    ------------------------------------------------------------------------------------------------
104194    -- 4219869 Business Flow
104195    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
104196    -- Prior Entry.  Currently, the following code is always generated.
104197    ------------------------------------------------------------------------------------------------
104198    XLA_AE_LINES_PKG.ValidateCurrentLine;
104199 
104200    ------------------------------------------------------------------------------------
104201    -- 4219869 Business Flow
104202    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
104203    ------------------------------------------------------------------------------------
104204    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
104205 
104206    ----------------------------------------------------------------------------------
104207    -- 4219869 Business Flow
104208    -- Update journal entry status -- Need to generate this within IF <condition>
104209    ----------------------------------------------------------------------------------
104210    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
104211          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
104212          ,p_balance_type_code => l_balance_type_code
104213          );
104214 
104215    -------------------------------------------------------------------------------------------
104216    -- 4262811 - Generate the Accrual Reversal lines
104217    -------------------------------------------------------------------------------------------
104218    BEGIN
104219       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
104220                               (g_array_event(p_event_id).array_value_num('header_index'));
104221       IF l_acc_rev_flag IS NULL THEN
104222          l_acc_rev_flag := 'N';
104223       END IF;
104224    EXCEPTION
104225       WHEN OTHERS THEN
104226          l_acc_rev_flag := 'N';
104227    END;
104228    --
104229    IF (l_acc_rev_flag = 'Y') THEN
104230 
104231        -- 4645092  ------------------------------------------------------------------------------
104232        -- To allow MPA report to determine if it should generate report process
104233        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
104234        ------------------------------------------------------------------------------------------
104235 
104236        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
104237        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
104238    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
104239    -- call ADRs
104240    -- Bug 4922099
104241    --
104242    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
104243         (NVL(l_actual_upg_option, 'N') = 'O') OR
104244         (NVL(l_enc_upg_option, 'N') = 'O')
104245       )
104246    THEN
104247    NULL;
104248    --
104249    --
104250    
104251   l_ccid := AcctDerRule_173(
104252            p_application_id           => p_application_id
104253          , p_ae_header_id             => l_ae_header_id 
104254 , p_source_3 => p_source_3
104255 , p_source_30 => p_source_30
104256          , x_transaction_coa_id       => l_adr_transaction_coa_id
104257          , x_accounting_coa_id        => l_adr_accounting_coa_id
104258          , x_value_type_code          => l_adr_value_type_code
104259          , p_side                     => 'NA'
104260    );
104261 
104262    xla_ae_lines_pkg.set_ccid(
104263     p_code_combination_id          => l_ccid
104264   , p_value_type_code              => l_adr_value_type_code
104265   , p_transaction_coa_id           => l_adr_transaction_coa_id
104266   , p_accounting_coa_id            => l_adr_accounting_coa_id
104267   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
104268   , p_adr_type_code                => 'S'
104269   , p_component_type               => l_component_type
104270   , p_component_code               => l_component_code
104271   , p_component_type_code          => l_component_type_code
104272   , p_component_appl_id            => l_component_appl_id
104273   , p_amb_context_code             => l_amb_context_code
104274   , p_side                         => 'NA'
104275   );
104276 
104277 
104278    l_segment := AcctDerRule_148(
104279            p_application_id           => p_application_id
104280          , p_ae_header_id             => l_ae_header_id 
104281 , p_source_3 => p_source_3
104282 , p_source_9 => p_source_9
104283          , x_transaction_coa_id       => l_adr_transaction_coa_id
104287          , x_value_type_code          => l_adr_value_type_code
104284          , x_accounting_coa_id        => l_adr_accounting_coa_id
104285          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
104286          , x_flex_value_set_id        => l_adr_flex_value_set_id
104288          , x_value_combination_id     => l_adr_value_combination_id
104289          , x_value_segment_code       => l_adr_value_segment_code
104290          , p_side                     => 'NA'
104291          , p_override_seg_flag        => 'Y'
104292    );
104293 
104294    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
104295 
104296       xla_ae_lines_pkg.set_segment(
104297           p_to_segment_code         => 'GL_ACCOUNT'
104298         , p_segment_value           => l_segment
104299         , p_from_segment_code       => l_adr_value_segment_code
104300         , p_from_combination_id     => l_adr_value_combination_id
104301         , p_value_type_code         => l_adr_value_type_code
104302         , p_transaction_coa_id      => l_adr_transaction_coa_id
104303         , p_accounting_coa_id       => l_adr_accounting_coa_id
104304         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
104305         , p_flex_value_set_id       => l_adr_flex_value_set_id
104306         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
104307         , p_adr_type_code           => 'S'
104308         , p_component_type          => l_component_type
104309         , p_component_code          => l_component_code
104310         , p_component_type_code     => l_component_type_code
104311         , p_component_appl_id       => l_component_appl_id
104312         , p_amb_context_code        => l_amb_context_code
104313         , p_entity_code             => 'TRANSACTIONS'
104314         , p_event_class_code        => 'RETIREMENTS'
104315         , p_side                    => 'NA'
104316         );
104317 
104318   END IF;
104319 
104320    l_segment := AcctDerRule_168(
104321            p_application_id           => p_application_id
104322          , p_ae_header_id             => l_ae_header_id 
104323 , p_source_3 => p_source_3
104324 , p_source_29 => p_source_29
104325          , x_transaction_coa_id       => l_adr_transaction_coa_id
104326          , x_accounting_coa_id        => l_adr_accounting_coa_id
104327          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
104328          , x_flex_value_set_id        => l_adr_flex_value_set_id
104329          , x_value_type_code          => l_adr_value_type_code
104330          , x_value_combination_id     => l_adr_value_combination_id
104331          , x_value_segment_code       => l_adr_value_segment_code
104332          , p_side                     => 'NA'
104333          , p_override_seg_flag        => 'Y'
104334    );
104335 
104336    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
104337 
104338       xla_ae_lines_pkg.set_segment(
104339           p_to_segment_code         => 'GL_BALANCING'
104340         , p_segment_value           => l_segment
104341         , p_from_segment_code       => l_adr_value_segment_code
104342         , p_from_combination_id     => l_adr_value_combination_id
104343         , p_value_type_code         => l_adr_value_type_code
104344         , p_transaction_coa_id      => l_adr_transaction_coa_id
104345         , p_accounting_coa_id       => l_adr_accounting_coa_id
104346         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
104347         , p_flex_value_set_id       => l_adr_flex_value_set_id
104348         , p_adr_code                => 'FA_EXPENSE_ACCT'
104349         , p_adr_type_code           => 'S'
104350         , p_component_type          => l_component_type
104351         , p_component_code          => l_component_code
104352         , p_component_type_code     => l_component_type_code
104353         , p_component_appl_id       => l_component_appl_id
104354         , p_amb_context_code        => l_amb_context_code
104355         , p_entity_code             => 'TRANSACTIONS'
104356         , p_event_class_code        => 'RETIREMENTS'
104357         , p_side                    => 'NA'
104358         );
104359 
104360   END IF;
104361 
104362    --
104363    --
104364    END IF;
104365 
104366        --
104367        -- Update the line information that should be overwritten
104368        --
104369        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
104370                                          p_header_num   => 1);
104371        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
104372 
104373        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
104374 
104375        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
104376           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
104377        END IF;
104378 
104379       --
104380       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
104381       --
104382       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
104383           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
104384       ELSE
104385           ---------------------------------------------------------------------------------------------------
104386           -- 4262811a Switch Sign
104387           ---------------------------------------------------------------------------------------------------
104388           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
104389           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
104390                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
104391           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
104392                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
104393           -- 5132302
104397       END IF;
104394           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
104395                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
104396 
104398 
104399       -- 4955764
104400       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
104401       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
104402 
104403 
104404       XLA_AE_LINES_PKG.ValidateCurrentLine;
104405       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
104406 
104407       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
104408                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
104409                ,p_balance_type_code => l_balance_type_code);
104410 
104411    END IF;
104412 
104413    -----------------------------------------------------------------------------------------
104414    -- 4262811 Multiperiod Accounting
104415    -----------------------------------------------------------------------------------------
104416      -- No MPA option is assigned.
104417 
104418 
104419 END IF;
104420 END IF;
104421 --
104422 
104423 --
104424 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
104425    trace
104426       (p_msg      => 'END of AcctLineType_299'
104427       ,p_level    => C_LEVEL_PROCEDURE
104428       ,p_module   => l_log_module);
104429 END IF;
104430 --
104431 EXCEPTION
104432   WHEN xla_exceptions_pkg.application_exception THEN
104433       RAISE;
104434   WHEN OTHERS THEN
104435        xla_exceptions_pkg.raise_message
104436            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_299');
104437 END AcctLineType_299;
104438 --
104439 
104440 ---------------------------------------
104441 --
104442 -- PRIVATE FUNCTION
104443 --         AcctLineType_300
104444 --
104445 ---------------------------------------
104446 PROCEDURE AcctLineType_300 (
104447   p_application_id        IN NUMBER
104448  ,p_event_id              IN NUMBER
104449  ,p_calculate_acctd_flag  IN VARCHAR2
104450  ,p_calculate_g_l_flag    IN VARCHAR2
104451  ,p_actual_flag           IN OUT VARCHAR2
104452  ,p_balance_type_code     OUT VARCHAR2
104453  ,p_gain_or_loss_ref      OUT VARCHAR2
104454  
104455 --Period Close Date
104456  , p_source_1            IN DATE
104457 --Generated Code Combination Identifier
104458  , p_source_3            IN NUMBER
104459 --Asset Cost Account
104460  , p_source_9            IN VARCHAR2
104461 --Expense Account Code Combination Identifier
104462  , p_source_29            IN NUMBER
104463 --Default Code Combination Identifier
104464  , p_source_30            IN NUMBER
104465 --Adjustment Type
104466  , p_source_35            IN VARCHAR2
104467 --Transaction Header Identifier
104468  , p_source_36            IN NUMBER
104469 --Adjustment Line Identifier
104470  , p_source_37            IN NUMBER
104471 --Distribution Type Code
104472  , p_source_38            IN VARCHAR2
104473 --Entered Amount
104474  , p_source_39            IN NUMBER
104475 --Currency Code
104476  , p_source_40            IN VARCHAR2
104477 )
104478 IS
104479 
104480 l_component_type              VARCHAR2(80);
104481 l_component_code              VARCHAR2(30);
104482 l_component_type_code         VARCHAR2(1);
104483 l_component_appl_id           INTEGER;
104484 l_amb_context_code            VARCHAR2(30);
104485 l_entity_code                 VARCHAR2(30);
104486 l_event_class_code            VARCHAR2(30);
104487 l_ae_header_id                NUMBER;
104488 l_event_type_code             VARCHAR2(30);
104489 l_line_definition_code        VARCHAR2(30);
104490 l_line_definition_owner_code  VARCHAR2(1);
104491 --
104492 -- adr variables
104493 l_segment                     VARCHAR2(30);
104494 l_ccid                        NUMBER;
104495 l_adr_transaction_coa_id      NUMBER;
104496 l_adr_accounting_coa_id       NUMBER;
104497 l_adr_flexfield_segment_code  VARCHAR2(30);
104498 l_adr_flex_value_set_id       NUMBER;
104499 l_adr_value_type_code         VARCHAR2(30);
104500 l_adr_value_combination_id    NUMBER;
104501 l_adr_value_segment_code      VARCHAR2(30);
104502 
104503 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
104504 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
104505 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
104506 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
104507 
104508 -- 4262811 Variables ------------------------------------------------------------------------------------------
104509 l_entered_amt_idx             NUMBER;
104510 l_accted_amt_idx              NUMBER;
104511 l_acc_rev_flag                VARCHAR2(1);
104512 l_accrual_line_num            NUMBER;
104513 l_tmp_amt                     NUMBER;
104514 l_acc_rev_natural_side_code   VARCHAR2(1);
104515 
104516 l_num_entries                 NUMBER;
104517 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
104518 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
104519 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
104520 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
104521 l_recog_line_1                NUMBER;
104522 l_recog_line_2                NUMBER;
104523 
104524 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
104525 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
104526 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
104527 
104528 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
104529 
104530 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
104531 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
104532 
104536 --
104533 ---------------------------------------------------------------------------------------------------------------
104534 
104535 
104537 -- bulk performance
104538 --
104539 l_balance_type_code           VARCHAR2(1);
104540 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
104541 l_log_module                  VARCHAR2(240);
104542 
104543 --
104544 -- Upgrade strategy
104545 --
104546 l_actual_upg_option           VARCHAR2(1);
104547 l_enc_upg_option           VARCHAR2(1);
104548 
104549 --
104550 BEGIN
104551 --
104552 IF g_log_enabled THEN
104553       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_300';
104554 END IF;
104555 --
104556 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
104557 
104558       trace
104559          (p_msg      => 'BEGIN of AcctLineType_300'
104560          ,p_level    => C_LEVEL_PROCEDURE
104561          ,p_module   => l_log_module);
104562 
104563 END IF;
104564 --
104565 l_component_type             := 'AMB_JLT';
104566 l_component_code             := 'FA_RETIREMENT_COST';
104567 l_component_type_code        := 'S';
104568 l_component_appl_id          :=  140;
104569 l_amb_context_code           := 'DEFAULT';
104570 l_entity_code                := 'TRANSACTIONS';
104571 l_event_class_code           := 'RETIREMENTS';
104572 l_event_type_code            := 'REINSTATEMENTS';
104573 l_line_definition_owner_code := 'S';
104574 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
104575 --
104576 l_balance_type_code          := 'A';
104577 l_segment                     := NULL;
104578 l_ccid                        := NULL;
104579 l_adr_transaction_coa_id      := NULL;
104580 l_adr_accounting_coa_id       := NULL;
104581 l_adr_flexfield_segment_code  := NULL;
104582 l_adr_flex_value_set_id       := NULL;
104583 l_adr_value_type_code         := NULL;
104584 l_adr_value_combination_id    := NULL;
104585 l_adr_value_segment_code      := NULL;
104586 
104587 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
104588 l_bflow_class_code           := '';    -- 4219869 Business Flow
104589 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
104590 l_budgetary_control_flag     := 'N';
104591 
104592 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
104593 l_bflow_applied_to_amt       := NULL; -- 5132302
104594 l_entered_amt_idx            := NULL;          -- 4262811
104595 l_accted_amt_idx             := NULL;          -- 4262811
104596 l_acc_rev_flag               := NULL;          -- 4262811
104597 l_accrual_line_num           := NULL;          -- 4262811
104598 l_tmp_amt                    := NULL;          -- 4262811
104599 --
104600  
104601 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
104602     l_balance_type_code <> 'B' THEN
104603 IF NVL(p_source_35,'
104604 ') =  'COST'
104605  THEN 
104606 
104607    --
104608    XLA_AE_LINES_PKG.SetNewLine;
104609 
104610    p_balance_type_code          := l_balance_type_code;
104611    -- set the flag so later we will know whether the gain loss line needs to be created
104612    
104613    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
104614      p_actual_flag :='A';
104615    END IF;
104616 
104617    --
104618    -- bulk performance
104619    --
104620    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
104621                                       p_header_num   => 0); -- 4262811
104622    --
104623    -- set accounting line options
104624    --
104625    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
104626            p_natural_side_code          => 'C'
104627          , p_gain_or_loss_flag          => 'N'
104628          , p_gl_transfer_mode_code      => 'S'
104629          , p_acct_entry_type_code       => 'A'
104630          , p_switch_side_flag           => 'Y'
104631          , p_merge_duplicate_code       => 'N'
104632          );
104633    --
104634    l_acc_rev_natural_side_code := 'D';  -- 4262811
104635    -- 
104636    --
104637    -- set accounting line type info
104638    --
104639    xla_ae_lines_pkg.SetAcctLineType
104640       (p_component_type             => l_component_type
104641       ,p_event_type_code            => l_event_type_code
104642       ,p_line_definition_owner_code => l_line_definition_owner_code
104643       ,p_line_definition_code       => l_line_definition_code
104644       ,p_accounting_line_code       => l_component_code
104645       ,p_accounting_line_type_code  => l_component_type_code
104646       ,p_accounting_line_appl_id    => l_component_appl_id
104647       ,p_amb_context_code           => l_amb_context_code
104648       ,p_entity_code                => l_entity_code
104649       ,p_event_class_code           => l_event_class_code);
104650    --
104651    -- set accounting class
104652    --
104653    xla_ae_lines_pkg.SetAcctClass(
104654            p_accounting_class_code  => 'ASSET'
104655          , p_ae_header_id           => l_ae_header_id
104656          );
104657 
104658    --
104659    -- set rounding class
104660    --
104661    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
104662                       'ASSET';
104663 
104664    --
104665    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
104666    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
104667    --
104668    -- bulk performance
104669    --
104670    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
104671 
104672    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
104673       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
104674 
104675    -- 4955764
104676    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
104680    
104677       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
104678 
104679    -- 4458381 Public Sector Enh
104681    --
104682    -- set accounting attributes for the line type
104683    --
104684    l_entered_amt_idx := 4;
104685    l_accted_amt_idx  := 6;
104686    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
104687    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
104688    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
104689    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
104690    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
104691    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
104692    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
104693    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
104694    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
104695    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
104696    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
104697    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
104698    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
104699 
104700    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
104701    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
104702 
104703    ---------------------------------------------------------------------------------------------------------------
104704    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
104705    ---------------------------------------------------------------------------------------------------------------
104706    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
104707 
104708    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
104709    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
104710 
104711    IF xla_accounting_cache_pkg.GetValueChar
104712          (p_source_code         => 'LEDGER_CATEGORY_CODE'
104713          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
104714    AND l_bflow_method_code = 'PRIOR_ENTRY'
104715 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
104716    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
104717          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
104718        )
104719    THEN
104720          xla_ae_lines_pkg.BflowUpgEntry
104721            (p_business_method_code    => l_bflow_method_code
104722            ,p_business_class_code     => l_bflow_class_code
104723            ,p_balance_type            => l_balance_type_code);
104724    ELSE
104725       NULL;
104726 -- No business flow processing for business flow method of NONE.
104727    END IF;
104728 
104729    --
104730    -- call analytical criteria
104731    --
104732    
104733    --
104734    -- call description
104735    --
104736    
104737 xla_ae_lines_pkg.SetLineDescription(
104738    p_ae_header_id => l_ae_header_id
104739   ,p_description  => Description_77 (
104740      p_application_id         => p_application_id
104741    , p_ae_header_id           => l_ae_header_id 
104742 , p_source_1 => p_source_1
104743    )
104744 );
104745 
104746 
104747    --
104748    -- call ADRs
104749    -- Bug 4922099
104750    --
104751    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
104752         (NVL(l_actual_upg_option, 'N') = 'O') OR
104753         (NVL(l_enc_upg_option, 'N') = 'O')
104754       )
104755    THEN
104756    NULL;
104757    --
104758    --
104759    
104760   l_ccid := AcctDerRule_173(
104761            p_application_id           => p_application_id
104762          , p_ae_header_id             => l_ae_header_id 
104763 , p_source_3 => p_source_3
104764 , p_source_30 => p_source_30
104765          , x_transaction_coa_id       => l_adr_transaction_coa_id
104766          , x_accounting_coa_id        => l_adr_accounting_coa_id
104767          , x_value_type_code          => l_adr_value_type_code
104768          , p_side                     => 'NA'
104769    );
104770 
104771    xla_ae_lines_pkg.set_ccid(
104772     p_code_combination_id          => l_ccid
104773   , p_value_type_code              => l_adr_value_type_code
104774   , p_transaction_coa_id           => l_adr_transaction_coa_id
104775   , p_accounting_coa_id            => l_adr_accounting_coa_id
104776   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
104777   , p_adr_type_code                => 'S'
104778   , p_component_type               => l_component_type
104779   , p_component_code               => l_component_code
104780   , p_component_type_code          => l_component_type_code
104781   , p_component_appl_id            => l_component_appl_id
104782   , p_amb_context_code             => l_amb_context_code
104783   , p_side                         => 'NA'
104784   );
104785 
104786 
104787    l_segment := AcctDerRule_148(
104788            p_application_id           => p_application_id
104789          , p_ae_header_id             => l_ae_header_id 
104790 , p_source_3 => p_source_3
104791 , p_source_9 => p_source_9
104792          , x_transaction_coa_id       => l_adr_transaction_coa_id
104793          , x_accounting_coa_id        => l_adr_accounting_coa_id
104794          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
104795          , x_flex_value_set_id        => l_adr_flex_value_set_id
104796          , x_value_type_code          => l_adr_value_type_code
104797          , x_value_combination_id     => l_adr_value_combination_id
104798          , x_value_segment_code       => l_adr_value_segment_code
104799          , p_side                     => 'NA'
104800          , p_override_seg_flag        => 'Y'
104801    );
104802 
104803    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
104807         , p_segment_value           => l_segment
104804 
104805       xla_ae_lines_pkg.set_segment(
104806           p_to_segment_code         => 'GL_ACCOUNT'
104808         , p_from_segment_code       => l_adr_value_segment_code
104809         , p_from_combination_id     => l_adr_value_combination_id
104810         , p_value_type_code         => l_adr_value_type_code
104811         , p_transaction_coa_id      => l_adr_transaction_coa_id
104812         , p_accounting_coa_id       => l_adr_accounting_coa_id
104813         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
104814         , p_flex_value_set_id       => l_adr_flex_value_set_id
104815         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
104816         , p_adr_type_code           => 'S'
104817         , p_component_type          => l_component_type
104818         , p_component_code          => l_component_code
104819         , p_component_type_code     => l_component_type_code
104820         , p_component_appl_id       => l_component_appl_id
104821         , p_amb_context_code        => l_amb_context_code
104822         , p_entity_code             => 'TRANSACTIONS'
104823         , p_event_class_code        => 'RETIREMENTS'
104824         , p_side                    => 'NA'
104825         );
104826 
104827   END IF;
104828 
104829    l_segment := AcctDerRule_168(
104830            p_application_id           => p_application_id
104831          , p_ae_header_id             => l_ae_header_id 
104832 , p_source_3 => p_source_3
104833 , p_source_29 => p_source_29
104834          , x_transaction_coa_id       => l_adr_transaction_coa_id
104835          , x_accounting_coa_id        => l_adr_accounting_coa_id
104836          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
104837          , x_flex_value_set_id        => l_adr_flex_value_set_id
104838          , x_value_type_code          => l_adr_value_type_code
104839          , x_value_combination_id     => l_adr_value_combination_id
104840          , x_value_segment_code       => l_adr_value_segment_code
104841          , p_side                     => 'NA'
104842          , p_override_seg_flag        => 'Y'
104843    );
104844 
104845    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
104846 
104847       xla_ae_lines_pkg.set_segment(
104848           p_to_segment_code         => 'GL_BALANCING'
104849         , p_segment_value           => l_segment
104850         , p_from_segment_code       => l_adr_value_segment_code
104851         , p_from_combination_id     => l_adr_value_combination_id
104852         , p_value_type_code         => l_adr_value_type_code
104853         , p_transaction_coa_id      => l_adr_transaction_coa_id
104854         , p_accounting_coa_id       => l_adr_accounting_coa_id
104855         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
104856         , p_flex_value_set_id       => l_adr_flex_value_set_id
104857         , p_adr_code                => 'FA_EXPENSE_ACCT'
104858         , p_adr_type_code           => 'S'
104859         , p_component_type          => l_component_type
104860         , p_component_code          => l_component_code
104861         , p_component_type_code     => l_component_type_code
104862         , p_component_appl_id       => l_component_appl_id
104863         , p_amb_context_code        => l_amb_context_code
104864         , p_entity_code             => 'TRANSACTIONS'
104865         , p_event_class_code        => 'RETIREMENTS'
104866         , p_side                    => 'NA'
104867         );
104868 
104869   END IF;
104870 
104871    --
104872    --
104873    END IF;
104874    --
104875    -- Bug 4922099
104876    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
104877           (NVL(l_enc_upg_option, 'N') = 'O')
104878         ) AND
104879         (l_bflow_method_code = 'PRIOR_ENTRY')
104880       )
104881    THEN
104882       IF
104883       --
104884       1 = 2
104885       --
104886       THEN
104887       xla_accounting_err_pkg.build_message
104888                                     (p_appli_s_name            => 'XLA'
104889                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
104890                                     ,p_token_1                 => 'LINE_NUMBER'
104891                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
104892                                     ,p_token_2                 => 'LINE_TYPE_NAME'
104893                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
104894                                                                              l_component_type
104895                                                                             ,l_component_code
104896                                                                             ,l_component_type_code
104897                                                                             ,l_component_appl_id
104898                                                                             ,l_amb_context_code
104899                                                                             ,l_entity_code
104900                                                                             ,l_event_class_code
104901                                                                            )
104902                                     ,p_token_3                 => 'OWNER'
104903                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
104904                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
104905                                                                           ,p_lookup_code    => l_component_type_code
104906                                                                          )
104907                                     ,p_token_4                 => 'PRODUCT_NAME'
104908                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
104909                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
104913                                        );
104910                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
104911                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
104912                                     ,p_ae_header_id            =>  NULL
104914 
104915         IF (C_LEVEL_ERROR>= g_log_level) THEN
104916                  trace
104917                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
104918                       ,p_level    => C_LEVEL_ERROR
104919                       ,p_module   => l_log_module);
104920         END IF;
104921       END IF;
104922    END IF;
104923    --
104924    --
104925    ------------------------------------------------------------------------------------------------
104926    -- 4219869 Business Flow
104927    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
104928    -- Prior Entry.  Currently, the following code is always generated.
104929    ------------------------------------------------------------------------------------------------
104930    XLA_AE_LINES_PKG.ValidateCurrentLine;
104931 
104932    ------------------------------------------------------------------------------------
104933    -- 4219869 Business Flow
104934    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
104935    ------------------------------------------------------------------------------------
104936    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
104937 
104938    ----------------------------------------------------------------------------------
104939    -- 4219869 Business Flow
104940    -- Update journal entry status -- Need to generate this within IF <condition>
104941    ----------------------------------------------------------------------------------
104942    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
104943          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
104944          ,p_balance_type_code => l_balance_type_code
104945          );
104946 
104947    -------------------------------------------------------------------------------------------
104948    -- 4262811 - Generate the Accrual Reversal lines
104949    -------------------------------------------------------------------------------------------
104950    BEGIN
104951       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
104952                               (g_array_event(p_event_id).array_value_num('header_index'));
104953       IF l_acc_rev_flag IS NULL THEN
104954          l_acc_rev_flag := 'N';
104955       END IF;
104956    EXCEPTION
104957       WHEN OTHERS THEN
104958          l_acc_rev_flag := 'N';
104959    END;
104960    --
104961    IF (l_acc_rev_flag = 'Y') THEN
104962 
104963        -- 4645092  ------------------------------------------------------------------------------
104964        -- To allow MPA report to determine if it should generate report process
104965        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
104966        ------------------------------------------------------------------------------------------
104967 
104968        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
104969        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
104970    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
104971    -- call ADRs
104972    -- Bug 4922099
104973    --
104974    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
104975         (NVL(l_actual_upg_option, 'N') = 'O') OR
104976         (NVL(l_enc_upg_option, 'N') = 'O')
104977       )
104978    THEN
104979    NULL;
104980    --
104981    --
104982    
104983   l_ccid := AcctDerRule_173(
104984            p_application_id           => p_application_id
104985          , p_ae_header_id             => l_ae_header_id 
104986 , p_source_3 => p_source_3
104987 , p_source_30 => p_source_30
104988          , x_transaction_coa_id       => l_adr_transaction_coa_id
104989          , x_accounting_coa_id        => l_adr_accounting_coa_id
104990          , x_value_type_code          => l_adr_value_type_code
104991          , p_side                     => 'NA'
104992    );
104993 
104994    xla_ae_lines_pkg.set_ccid(
104995     p_code_combination_id          => l_ccid
104996   , p_value_type_code              => l_adr_value_type_code
104997   , p_transaction_coa_id           => l_adr_transaction_coa_id
104998   , p_accounting_coa_id            => l_adr_accounting_coa_id
104999   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
105000   , p_adr_type_code                => 'S'
105001   , p_component_type               => l_component_type
105002   , p_component_code               => l_component_code
105003   , p_component_type_code          => l_component_type_code
105004   , p_component_appl_id            => l_component_appl_id
105005   , p_amb_context_code             => l_amb_context_code
105006   , p_side                         => 'NA'
105007   );
105008 
105009 
105010    l_segment := AcctDerRule_148(
105011            p_application_id           => p_application_id
105012          , p_ae_header_id             => l_ae_header_id 
105013 , p_source_3 => p_source_3
105014 , p_source_9 => p_source_9
105015          , x_transaction_coa_id       => l_adr_transaction_coa_id
105016          , x_accounting_coa_id        => l_adr_accounting_coa_id
105017          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
105018          , x_flex_value_set_id        => l_adr_flex_value_set_id
105019          , x_value_type_code          => l_adr_value_type_code
105020          , x_value_combination_id     => l_adr_value_combination_id
105021          , x_value_segment_code       => l_adr_value_segment_code
105022          , p_side                     => 'NA'
105023          , p_override_seg_flag        => 'Y'
105024    );
105025 
105026    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
105027 
105028       xla_ae_lines_pkg.set_segment(
105032         , p_from_combination_id     => l_adr_value_combination_id
105029           p_to_segment_code         => 'GL_ACCOUNT'
105030         , p_segment_value           => l_segment
105031         , p_from_segment_code       => l_adr_value_segment_code
105033         , p_value_type_code         => l_adr_value_type_code
105034         , p_transaction_coa_id      => l_adr_transaction_coa_id
105035         , p_accounting_coa_id       => l_adr_accounting_coa_id
105036         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
105037         , p_flex_value_set_id       => l_adr_flex_value_set_id
105038         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
105039         , p_adr_type_code           => 'S'
105040         , p_component_type          => l_component_type
105041         , p_component_code          => l_component_code
105042         , p_component_type_code     => l_component_type_code
105043         , p_component_appl_id       => l_component_appl_id
105044         , p_amb_context_code        => l_amb_context_code
105045         , p_entity_code             => 'TRANSACTIONS'
105046         , p_event_class_code        => 'RETIREMENTS'
105047         , p_side                    => 'NA'
105048         );
105049 
105050   END IF;
105051 
105052    l_segment := AcctDerRule_168(
105053            p_application_id           => p_application_id
105054          , p_ae_header_id             => l_ae_header_id 
105055 , p_source_3 => p_source_3
105056 , p_source_29 => p_source_29
105057          , x_transaction_coa_id       => l_adr_transaction_coa_id
105058          , x_accounting_coa_id        => l_adr_accounting_coa_id
105059          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
105060          , x_flex_value_set_id        => l_adr_flex_value_set_id
105061          , x_value_type_code          => l_adr_value_type_code
105062          , x_value_combination_id     => l_adr_value_combination_id
105063          , x_value_segment_code       => l_adr_value_segment_code
105064          , p_side                     => 'NA'
105065          , p_override_seg_flag        => 'Y'
105066    );
105067 
105068    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
105069 
105070       xla_ae_lines_pkg.set_segment(
105071           p_to_segment_code         => 'GL_BALANCING'
105072         , p_segment_value           => l_segment
105073         , p_from_segment_code       => l_adr_value_segment_code
105074         , p_from_combination_id     => l_adr_value_combination_id
105075         , p_value_type_code         => l_adr_value_type_code
105076         , p_transaction_coa_id      => l_adr_transaction_coa_id
105077         , p_accounting_coa_id       => l_adr_accounting_coa_id
105078         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
105079         , p_flex_value_set_id       => l_adr_flex_value_set_id
105080         , p_adr_code                => 'FA_EXPENSE_ACCT'
105081         , p_adr_type_code           => 'S'
105082         , p_component_type          => l_component_type
105083         , p_component_code          => l_component_code
105084         , p_component_type_code     => l_component_type_code
105085         , p_component_appl_id       => l_component_appl_id
105086         , p_amb_context_code        => l_amb_context_code
105087         , p_entity_code             => 'TRANSACTIONS'
105088         , p_event_class_code        => 'RETIREMENTS'
105089         , p_side                    => 'NA'
105090         );
105091 
105092   END IF;
105093 
105094    --
105095    --
105096    END IF;
105097 
105098        --
105099        -- Update the line information that should be overwritten
105100        --
105101        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
105102                                          p_header_num   => 1);
105103        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
105104 
105105        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
105106 
105107        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
105108           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
105109        END IF;
105110 
105111       --
105112       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
105113       --
105114       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
105115           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
105116       ELSE
105117           ---------------------------------------------------------------------------------------------------
105118           -- 4262811a Switch Sign
105119           ---------------------------------------------------------------------------------------------------
105120           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
105121           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
105122                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
105123           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
105124                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
105125           -- 5132302
105126           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
105127                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
105128 
105129       END IF;
105130 
105131       -- 4955764
105132       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
105133       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
105134 
105135 
105136       XLA_AE_LINES_PKG.ValidateCurrentLine;
105137       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
105138 
105139       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
105143    END IF;
105140                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
105141                ,p_balance_type_code => l_balance_type_code);
105142 
105144 
105145    -----------------------------------------------------------------------------------------
105146    -- 4262811 Multiperiod Accounting
105147    -----------------------------------------------------------------------------------------
105148      -- No MPA option is assigned.
105149 
105150 
105151 END IF;
105152 END IF;
105153 --
105154 
105155 --
105156 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
105157    trace
105158       (p_msg      => 'END of AcctLineType_300'
105159       ,p_level    => C_LEVEL_PROCEDURE
105160       ,p_module   => l_log_module);
105161 END IF;
105162 --
105163 EXCEPTION
105164   WHEN xla_exceptions_pkg.application_exception THEN
105165       RAISE;
105166   WHEN OTHERS THEN
105167        xla_exceptions_pkg.raise_message
105168            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_300');
105169 END AcctLineType_300;
105170 --
105171 
105172 ---------------------------------------
105173 --
105174 -- PRIVATE FUNCTION
105175 --         AcctLineType_301
105176 --
105177 ---------------------------------------
105178 PROCEDURE AcctLineType_301 (
105179   p_application_id        IN NUMBER
105180  ,p_event_id              IN NUMBER
105181  ,p_calculate_acctd_flag  IN VARCHAR2
105182  ,p_calculate_g_l_flag    IN VARCHAR2
105183  ,p_actual_flag           IN OUT VARCHAR2
105184  ,p_balance_type_code     OUT VARCHAR2
105185  ,p_gain_or_loss_ref      OUT VARCHAR2
105186  
105187 --Period Close Date
105188  , p_source_1            IN DATE
105189 --Generated Code Combination Identifier
105190  , p_source_3            IN NUMBER
105191 --Expense Account Code Combination Identifier
105192  , p_source_29            IN NUMBER
105193 --Adjustment Type
105194  , p_source_35            IN VARCHAR2
105195 --Transaction Header Identifier
105196  , p_source_36            IN NUMBER
105197 --Adjustment Line Identifier
105198  , p_source_37            IN NUMBER
105199 --Distribution Type Code
105200  , p_source_38            IN VARCHAR2
105201 --Entered Amount
105202  , p_source_39            IN NUMBER
105203 --Currency Code
105204  , p_source_40            IN VARCHAR2
105205 )
105206 IS
105207 
105208 l_component_type              VARCHAR2(80);
105209 l_component_code              VARCHAR2(30);
105210 l_component_type_code         VARCHAR2(1);
105211 l_component_appl_id           INTEGER;
105212 l_amb_context_code            VARCHAR2(30);
105213 l_entity_code                 VARCHAR2(30);
105214 l_event_class_code            VARCHAR2(30);
105215 l_ae_header_id                NUMBER;
105216 l_event_type_code             VARCHAR2(30);
105217 l_line_definition_code        VARCHAR2(30);
105218 l_line_definition_owner_code  VARCHAR2(1);
105219 --
105220 -- adr variables
105221 l_segment                     VARCHAR2(30);
105222 l_ccid                        NUMBER;
105223 l_adr_transaction_coa_id      NUMBER;
105224 l_adr_accounting_coa_id       NUMBER;
105225 l_adr_flexfield_segment_code  VARCHAR2(30);
105226 l_adr_flex_value_set_id       NUMBER;
105227 l_adr_value_type_code         VARCHAR2(30);
105228 l_adr_value_combination_id    NUMBER;
105229 l_adr_value_segment_code      VARCHAR2(30);
105230 
105231 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
105232 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
105233 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
105234 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
105235 
105236 -- 4262811 Variables ------------------------------------------------------------------------------------------
105237 l_entered_amt_idx             NUMBER;
105238 l_accted_amt_idx              NUMBER;
105239 l_acc_rev_flag                VARCHAR2(1);
105240 l_accrual_line_num            NUMBER;
105241 l_tmp_amt                     NUMBER;
105242 l_acc_rev_natural_side_code   VARCHAR2(1);
105243 
105244 l_num_entries                 NUMBER;
105245 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
105246 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
105247 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
105248 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
105249 l_recog_line_1                NUMBER;
105250 l_recog_line_2                NUMBER;
105251 
105252 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
105253 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
105254 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
105255 
105256 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
105257 
105258 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
105259 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
105260 
105261 ---------------------------------------------------------------------------------------------------------------
105262 
105263 
105264 --
105265 -- bulk performance
105266 --
105267 l_balance_type_code           VARCHAR2(1);
105268 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
105269 l_log_module                  VARCHAR2(240);
105270 
105271 --
105272 -- Upgrade strategy
105273 --
105274 l_actual_upg_option           VARCHAR2(1);
105275 l_enc_upg_option           VARCHAR2(1);
105276 
105277 --
105278 BEGIN
105279 --
105280 IF g_log_enabled THEN
105281       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_301';
105282 END IF;
105283 --
105284 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
105285 
105286       trace
105287          (p_msg      => 'BEGIN of AcctLineType_301'
105291 END IF;
105288          ,p_level    => C_LEVEL_PROCEDURE
105289          ,p_module   => l_log_module);
105290 
105292 --
105293 l_component_type             := 'AMB_JLT';
105294 l_component_code             := 'FA_RETIREMENT_DEPRN_EXP';
105295 l_component_type_code        := 'S';
105296 l_component_appl_id          :=  140;
105297 l_amb_context_code           := 'DEFAULT';
105298 l_entity_code                := 'TRANSACTIONS';
105299 l_event_class_code           := 'RETIREMENTS';
105300 l_event_type_code            := 'REINSTATEMENTS';
105301 l_line_definition_owner_code := 'S';
105302 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
105303 --
105304 l_balance_type_code          := 'A';
105305 l_segment                     := NULL;
105306 l_ccid                        := NULL;
105307 l_adr_transaction_coa_id      := NULL;
105308 l_adr_accounting_coa_id       := NULL;
105309 l_adr_flexfield_segment_code  := NULL;
105310 l_adr_flex_value_set_id       := NULL;
105311 l_adr_value_type_code         := NULL;
105312 l_adr_value_combination_id    := NULL;
105313 l_adr_value_segment_code      := NULL;
105314 
105315 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
105316 l_bflow_class_code           := '';    -- 4219869 Business Flow
105317 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
105318 l_budgetary_control_flag     := 'N';
105319 
105320 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
105321 l_bflow_applied_to_amt       := NULL; -- 5132302
105322 l_entered_amt_idx            := NULL;          -- 4262811
105323 l_accted_amt_idx             := NULL;          -- 4262811
105324 l_acc_rev_flag               := NULL;          -- 4262811
105325 l_accrual_line_num           := NULL;          -- 4262811
105326 l_tmp_amt                    := NULL;          -- 4262811
105327 --
105328  
105329 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
105330     l_balance_type_code <> 'B' THEN
105331 IF NVL(p_source_35,'
105332 ') =  'EXPENSE'
105333  THEN 
105334 
105335    --
105336    XLA_AE_LINES_PKG.SetNewLine;
105337 
105338    p_balance_type_code          := l_balance_type_code;
105339    -- set the flag so later we will know whether the gain loss line needs to be created
105340    
105341    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
105342      p_actual_flag :='A';
105343    END IF;
105344 
105345    --
105346    -- bulk performance
105347    --
105348    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
105349                                       p_header_num   => 0); -- 4262811
105350    --
105351    -- set accounting line options
105352    --
105353    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
105354            p_natural_side_code          => 'C'
105355          , p_gain_or_loss_flag          => 'N'
105356          , p_gl_transfer_mode_code      => 'S'
105357          , p_acct_entry_type_code       => 'A'
105358          , p_switch_side_flag           => 'Y'
105359          , p_merge_duplicate_code       => 'N'
105360          );
105361    --
105362    l_acc_rev_natural_side_code := 'D';  -- 4262811
105363    -- 
105364    --
105365    -- set accounting line type info
105366    --
105367    xla_ae_lines_pkg.SetAcctLineType
105368       (p_component_type             => l_component_type
105369       ,p_event_type_code            => l_event_type_code
105370       ,p_line_definition_owner_code => l_line_definition_owner_code
105371       ,p_line_definition_code       => l_line_definition_code
105372       ,p_accounting_line_code       => l_component_code
105373       ,p_accounting_line_type_code  => l_component_type_code
105374       ,p_accounting_line_appl_id    => l_component_appl_id
105375       ,p_amb_context_code           => l_amb_context_code
105376       ,p_entity_code                => l_entity_code
105377       ,p_event_class_code           => l_event_class_code);
105378    --
105379    -- set accounting class
105380    --
105381    xla_ae_lines_pkg.SetAcctClass(
105382            p_accounting_class_code  => 'EXPENSE'
105383          , p_ae_header_id           => l_ae_header_id
105384          );
105385 
105386    --
105387    -- set rounding class
105388    --
105389    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
105390                       'EXPENSE';
105391 
105392    --
105393    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
105394    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
105395    --
105396    -- bulk performance
105397    --
105398    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
105399 
105400    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
105401       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
105402 
105403    -- 4955764
105404    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
105405       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
105406 
105407    -- 4458381 Public Sector Enh
105408    
105409    --
105410    -- set accounting attributes for the line type
105411    --
105412    l_entered_amt_idx := 4;
105413    l_accted_amt_idx  := 6;
105414    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
105415    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
105416    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
105417    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
105418    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
105419    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
105420    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
105421    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
105425    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
105422    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
105423    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
105424    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
105426    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
105427 
105428    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
105429    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
105430 
105431    ---------------------------------------------------------------------------------------------------------------
105432    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
105433    ---------------------------------------------------------------------------------------------------------------
105434    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
105435 
105436    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
105437    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
105438 
105439    IF xla_accounting_cache_pkg.GetValueChar
105440          (p_source_code         => 'LEDGER_CATEGORY_CODE'
105441          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
105442    AND l_bflow_method_code = 'PRIOR_ENTRY'
105443 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
105444    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
105445          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
105446        )
105447    THEN
105448          xla_ae_lines_pkg.BflowUpgEntry
105449            (p_business_method_code    => l_bflow_method_code
105450            ,p_business_class_code     => l_bflow_class_code
105451            ,p_balance_type            => l_balance_type_code);
105452    ELSE
105453       NULL;
105454 -- No business flow processing for business flow method of NONE.
105455    END IF;
105456 
105457    --
105458    -- call analytical criteria
105459    --
105460    
105461    --
105462    -- call description
105463    --
105464    
105465 xla_ae_lines_pkg.SetLineDescription(
105466    p_ae_header_id => l_ae_header_id
105467   ,p_description  => Description_79 (
105468      p_application_id         => p_application_id
105469    , p_ae_header_id           => l_ae_header_id 
105470 , p_source_1 => p_source_1
105471    )
105472 );
105473 
105474 
105475    --
105476    -- call ADRs
105477    -- Bug 4922099
105478    --
105479    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
105480         (NVL(l_actual_upg_option, 'N') = 'O') OR
105481         (NVL(l_enc_upg_option, 'N') = 'O')
105482       )
105483    THEN
105484    NULL;
105485    --
105486    --
105487    
105488   l_ccid := AcctDerRule_175(
105489            p_application_id           => p_application_id
105490          , p_ae_header_id             => l_ae_header_id 
105491 , p_source_3 => p_source_3
105492 , p_source_29 => p_source_29
105493          , x_transaction_coa_id       => l_adr_transaction_coa_id
105494          , x_accounting_coa_id        => l_adr_accounting_coa_id
105495          , x_value_type_code          => l_adr_value_type_code
105496          , p_side                     => 'NA'
105497    );
105498 
105499    xla_ae_lines_pkg.set_ccid(
105500     p_code_combination_id          => l_ccid
105501   , p_value_type_code              => l_adr_value_type_code
105502   , p_transaction_coa_id           => l_adr_transaction_coa_id
105503   , p_accounting_coa_id            => l_adr_accounting_coa_id
105504   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
105505   , p_adr_type_code                => 'S'
105506   , p_component_type               => l_component_type
105507   , p_component_code               => l_component_code
105508   , p_component_type_code          => l_component_type_code
105509   , p_component_appl_id            => l_component_appl_id
105510   , p_amb_context_code             => l_amb_context_code
105511   , p_side                         => 'NA'
105512   );
105513 
105514 
105515    --
105516    --
105517    END IF;
105518    --
105519    -- Bug 4922099
105520    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
105521           (NVL(l_enc_upg_option, 'N') = 'O')
105522         ) AND
105523         (l_bflow_method_code = 'PRIOR_ENTRY')
105524       )
105525    THEN
105526       IF
105527       --
105528       1 = 2
105529       --
105530       THEN
105531       xla_accounting_err_pkg.build_message
105532                                     (p_appli_s_name            => 'XLA'
105533                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
105534                                     ,p_token_1                 => 'LINE_NUMBER'
105535                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
105536                                     ,p_token_2                 => 'LINE_TYPE_NAME'
105537                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
105538                                                                              l_component_type
105539                                                                             ,l_component_code
105540                                                                             ,l_component_type_code
105541                                                                             ,l_component_appl_id
105542                                                                             ,l_amb_context_code
105543                                                                             ,l_entity_code
105544                                                                             ,l_event_class_code
105545                                                                            )
105546                                     ,p_token_3                 => 'OWNER'
105550                                                                          )
105547                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
105548                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
105549                                                                           ,p_lookup_code    => l_component_type_code
105551                                     ,p_token_4                 => 'PRODUCT_NAME'
105552                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
105553                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
105554                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
105555                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
105556                                     ,p_ae_header_id            =>  NULL
105557                                        );
105558 
105559         IF (C_LEVEL_ERROR>= g_log_level) THEN
105560                  trace
105561                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
105562                       ,p_level    => C_LEVEL_ERROR
105563                       ,p_module   => l_log_module);
105564         END IF;
105565       END IF;
105566    END IF;
105567    --
105568    --
105569    ------------------------------------------------------------------------------------------------
105570    -- 4219869 Business Flow
105571    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
105572    -- Prior Entry.  Currently, the following code is always generated.
105573    ------------------------------------------------------------------------------------------------
105574    XLA_AE_LINES_PKG.ValidateCurrentLine;
105575 
105576    ------------------------------------------------------------------------------------
105577    -- 4219869 Business Flow
105578    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
105579    ------------------------------------------------------------------------------------
105580    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
105581 
105582    ----------------------------------------------------------------------------------
105583    -- 4219869 Business Flow
105584    -- Update journal entry status -- Need to generate this within IF <condition>
105585    ----------------------------------------------------------------------------------
105586    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
105587          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
105588          ,p_balance_type_code => l_balance_type_code
105589          );
105590 
105591    -------------------------------------------------------------------------------------------
105592    -- 4262811 - Generate the Accrual Reversal lines
105593    -------------------------------------------------------------------------------------------
105594    BEGIN
105595       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
105596                               (g_array_event(p_event_id).array_value_num('header_index'));
105597       IF l_acc_rev_flag IS NULL THEN
105598          l_acc_rev_flag := 'N';
105599       END IF;
105600    EXCEPTION
105601       WHEN OTHERS THEN
105602          l_acc_rev_flag := 'N';
105603    END;
105604    --
105605    IF (l_acc_rev_flag = 'Y') THEN
105606 
105607        -- 4645092  ------------------------------------------------------------------------------
105608        -- To allow MPA report to determine if it should generate report process
105609        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
105610        ------------------------------------------------------------------------------------------
105611 
105612        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
105613        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
105614    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
105615    -- call ADRs
105616    -- Bug 4922099
105617    --
105618    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
105619         (NVL(l_actual_upg_option, 'N') = 'O') OR
105620         (NVL(l_enc_upg_option, 'N') = 'O')
105621       )
105622    THEN
105623    NULL;
105624    --
105625    --
105626    
105627   l_ccid := AcctDerRule_175(
105628            p_application_id           => p_application_id
105629          , p_ae_header_id             => l_ae_header_id 
105630 , p_source_3 => p_source_3
105631 , p_source_29 => p_source_29
105632          , x_transaction_coa_id       => l_adr_transaction_coa_id
105633          , x_accounting_coa_id        => l_adr_accounting_coa_id
105634          , x_value_type_code          => l_adr_value_type_code
105635          , p_side                     => 'NA'
105636    );
105637 
105638    xla_ae_lines_pkg.set_ccid(
105639     p_code_combination_id          => l_ccid
105640   , p_value_type_code              => l_adr_value_type_code
105641   , p_transaction_coa_id           => l_adr_transaction_coa_id
105642   , p_accounting_coa_id            => l_adr_accounting_coa_id
105643   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
105644   , p_adr_type_code                => 'S'
105645   , p_component_type               => l_component_type
105646   , p_component_code               => l_component_code
105647   , p_component_type_code          => l_component_type_code
105648   , p_component_appl_id            => l_component_appl_id
105649   , p_amb_context_code             => l_amb_context_code
105650   , p_side                         => 'NA'
105651   );
105652 
105653 
105654    --
105655    --
105656    END IF;
105657 
105658        --
105659        -- Update the line information that should be overwritten
105660        --
105661        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
105662                                          p_header_num   => 1);
105666 
105663        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
105664 
105665        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
105667        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
105668           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
105669        END IF;
105670 
105671       --
105672       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
105673       --
105674       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
105675           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
105676       ELSE
105677           ---------------------------------------------------------------------------------------------------
105678           -- 4262811a Switch Sign
105679           ---------------------------------------------------------------------------------------------------
105680           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
105681           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
105682                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
105683           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
105684                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
105685           -- 5132302
105686           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
105687                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
105688 
105689       END IF;
105690 
105691       -- 4955764
105692       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
105693       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
105694 
105695 
105696       XLA_AE_LINES_PKG.ValidateCurrentLine;
105697       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
105698 
105699       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
105700                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
105701                ,p_balance_type_code => l_balance_type_code);
105702 
105703    END IF;
105704 
105705    -----------------------------------------------------------------------------------------
105706    -- 4262811 Multiperiod Accounting
105707    -----------------------------------------------------------------------------------------
105708      -- No MPA option is assigned.
105709 
105710 
105711 END IF;
105712 END IF;
105713 --
105714 
105715 --
105716 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
105717    trace
105718       (p_msg      => 'END of AcctLineType_301'
105719       ,p_level    => C_LEVEL_PROCEDURE
105720       ,p_module   => l_log_module);
105721 END IF;
105722 --
105723 EXCEPTION
105724   WHEN xla_exceptions_pkg.application_exception THEN
105725       RAISE;
105726   WHEN OTHERS THEN
105727        xla_exceptions_pkg.raise_message
105728            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_301');
105729 END AcctLineType_301;
105730 --
105731 
105732 ---------------------------------------
105733 --
105734 -- PRIVATE FUNCTION
105735 --         AcctLineType_302
105736 --
105737 ---------------------------------------
105738 PROCEDURE AcctLineType_302 (
105739   p_application_id        IN NUMBER
105740  ,p_event_id              IN NUMBER
105741  ,p_calculate_acctd_flag  IN VARCHAR2
105742  ,p_calculate_g_l_flag    IN VARCHAR2
105743  ,p_actual_flag           IN OUT VARCHAR2
105744  ,p_balance_type_code     OUT VARCHAR2
105745  ,p_gain_or_loss_ref      OUT VARCHAR2
105746  
105747 --Period Close Date
105748  , p_source_1            IN DATE
105749 --Generated Code Combination Identifier
105750  , p_source_3            IN NUMBER
105751 --Expense Account Code Combination Identifier
105752  , p_source_29            IN NUMBER
105753 --Adjustment Type
105754  , p_source_35            IN VARCHAR2
105755 --Transaction Header Identifier
105756  , p_source_36            IN NUMBER
105757 --Adjustment Line Identifier
105758  , p_source_37            IN NUMBER
105759 --Distribution Type Code
105760  , p_source_38            IN VARCHAR2
105761 --Entered Amount
105762  , p_source_39            IN NUMBER
105763 --Currency Code
105764  , p_source_40            IN VARCHAR2
105765 )
105766 IS
105767 
105768 l_component_type              VARCHAR2(80);
105769 l_component_code              VARCHAR2(30);
105770 l_component_type_code         VARCHAR2(1);
105771 l_component_appl_id           INTEGER;
105772 l_amb_context_code            VARCHAR2(30);
105773 l_entity_code                 VARCHAR2(30);
105774 l_event_class_code            VARCHAR2(30);
105775 l_ae_header_id                NUMBER;
105776 l_event_type_code             VARCHAR2(30);
105777 l_line_definition_code        VARCHAR2(30);
105778 l_line_definition_owner_code  VARCHAR2(1);
105779 --
105780 -- adr variables
105781 l_segment                     VARCHAR2(30);
105782 l_ccid                        NUMBER;
105783 l_adr_transaction_coa_id      NUMBER;
105784 l_adr_accounting_coa_id       NUMBER;
105785 l_adr_flexfield_segment_code  VARCHAR2(30);
105786 l_adr_flex_value_set_id       NUMBER;
105787 l_adr_value_type_code         VARCHAR2(30);
105788 l_adr_value_combination_id    NUMBER;
105789 l_adr_value_segment_code      VARCHAR2(30);
105790 
105791 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
105792 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
105793 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
105797 l_entered_amt_idx             NUMBER;
105794 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
105795 
105796 -- 4262811 Variables ------------------------------------------------------------------------------------------
105798 l_accted_amt_idx              NUMBER;
105799 l_acc_rev_flag                VARCHAR2(1);
105800 l_accrual_line_num            NUMBER;
105801 l_tmp_amt                     NUMBER;
105802 l_acc_rev_natural_side_code   VARCHAR2(1);
105803 
105804 l_num_entries                 NUMBER;
105805 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
105806 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
105807 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
105808 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
105809 l_recog_line_1                NUMBER;
105810 l_recog_line_2                NUMBER;
105811 
105812 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
105813 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
105814 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
105815 
105816 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
105817 
105818 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
105819 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
105820 
105821 ---------------------------------------------------------------------------------------------------------------
105822 
105823 
105824 --
105825 -- bulk performance
105826 --
105827 l_balance_type_code           VARCHAR2(1);
105828 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
105829 l_log_module                  VARCHAR2(240);
105830 
105831 --
105832 -- Upgrade strategy
105833 --
105834 l_actual_upg_option           VARCHAR2(1);
105835 l_enc_upg_option           VARCHAR2(1);
105836 
105837 --
105838 BEGIN
105839 --
105840 IF g_log_enabled THEN
105841       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_302';
105842 END IF;
105843 --
105844 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
105845 
105846       trace
105847          (p_msg      => 'BEGIN of AcctLineType_302'
105848          ,p_level    => C_LEVEL_PROCEDURE
105849          ,p_module   => l_log_module);
105850 
105851 END IF;
105852 --
105853 l_component_type             := 'AMB_JLT';
105854 l_component_code             := 'FA_RETIREMENT_DEPRN_EXP';
105855 l_component_type_code        := 'S';
105856 l_component_appl_id          :=  140;
105857 l_amb_context_code           := 'DEFAULT';
105858 l_entity_code                := 'TRANSACTIONS';
105859 l_event_class_code           := 'RETIREMENTS';
105860 l_event_type_code            := 'RETIREMENTS';
105861 l_line_definition_owner_code := 'S';
105862 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
105863 --
105864 l_balance_type_code          := 'A';
105865 l_segment                     := NULL;
105866 l_ccid                        := NULL;
105867 l_adr_transaction_coa_id      := NULL;
105868 l_adr_accounting_coa_id       := NULL;
105869 l_adr_flexfield_segment_code  := NULL;
105870 l_adr_flex_value_set_id       := NULL;
105871 l_adr_value_type_code         := NULL;
105872 l_adr_value_combination_id    := NULL;
105873 l_adr_value_segment_code      := NULL;
105874 
105875 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
105876 l_bflow_class_code           := '';    -- 4219869 Business Flow
105877 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
105878 l_budgetary_control_flag     := 'N';
105879 
105880 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
105881 l_bflow_applied_to_amt       := NULL; -- 5132302
105882 l_entered_amt_idx            := NULL;          -- 4262811
105883 l_accted_amt_idx             := NULL;          -- 4262811
105884 l_acc_rev_flag               := NULL;          -- 4262811
105885 l_accrual_line_num           := NULL;          -- 4262811
105886 l_tmp_amt                    := NULL;          -- 4262811
105887 --
105888  
105889 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
105890     l_balance_type_code <> 'B' THEN
105891 IF NVL(p_source_35,'
105892 ') =  'EXPENSE'
105893  THEN 
105894 
105895    --
105896    XLA_AE_LINES_PKG.SetNewLine;
105897 
105898    p_balance_type_code          := l_balance_type_code;
105899    -- set the flag so later we will know whether the gain loss line needs to be created
105900    
105901    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
105902      p_actual_flag :='A';
105903    END IF;
105904 
105905    --
105906    -- bulk performance
105907    --
105908    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
105909                                       p_header_num   => 0); -- 4262811
105910    --
105911    -- set accounting line options
105912    --
105913    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
105914            p_natural_side_code          => 'C'
105915          , p_gain_or_loss_flag          => 'N'
105916          , p_gl_transfer_mode_code      => 'S'
105917          , p_acct_entry_type_code       => 'A'
105918          , p_switch_side_flag           => 'Y'
105919          , p_merge_duplicate_code       => 'N'
105920          );
105921    --
105922    l_acc_rev_natural_side_code := 'D';  -- 4262811
105923    -- 
105924    --
105925    -- set accounting line type info
105926    --
105927    xla_ae_lines_pkg.SetAcctLineType
105928       (p_component_type             => l_component_type
105929       ,p_event_type_code            => l_event_type_code
105930       ,p_line_definition_owner_code => l_line_definition_owner_code
105931       ,p_line_definition_code       => l_line_definition_code
105932       ,p_accounting_line_code       => l_component_code
105936       ,p_entity_code                => l_entity_code
105933       ,p_accounting_line_type_code  => l_component_type_code
105934       ,p_accounting_line_appl_id    => l_component_appl_id
105935       ,p_amb_context_code           => l_amb_context_code
105937       ,p_event_class_code           => l_event_class_code);
105938    --
105939    -- set accounting class
105940    --
105941    xla_ae_lines_pkg.SetAcctClass(
105942            p_accounting_class_code  => 'EXPENSE'
105943          , p_ae_header_id           => l_ae_header_id
105944          );
105945 
105946    --
105947    -- set rounding class
105948    --
105949    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
105950                       'EXPENSE';
105951 
105952    --
105953    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
105954    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
105955    --
105956    -- bulk performance
105957    --
105958    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
105959 
105960    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
105961       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
105962 
105963    -- 4955764
105964    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
105965       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
105966 
105967    -- 4458381 Public Sector Enh
105968    
105969    --
105970    -- set accounting attributes for the line type
105971    --
105972    l_entered_amt_idx := 4;
105973    l_accted_amt_idx  := 6;
105974    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
105975    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
105976    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
105977    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
105978    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
105979    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
105980    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
105981    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
105982    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
105983    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
105984    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
105985    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
105986    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
105987 
105988    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
105989    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
105990 
105991    ---------------------------------------------------------------------------------------------------------------
105992    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
105993    ---------------------------------------------------------------------------------------------------------------
105994    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
105995 
105996    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
105997    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
105998 
105999    IF xla_accounting_cache_pkg.GetValueChar
106000          (p_source_code         => 'LEDGER_CATEGORY_CODE'
106001          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
106002    AND l_bflow_method_code = 'PRIOR_ENTRY'
106003 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
106004    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
106005          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
106006        )
106007    THEN
106008          xla_ae_lines_pkg.BflowUpgEntry
106009            (p_business_method_code    => l_bflow_method_code
106010            ,p_business_class_code     => l_bflow_class_code
106011            ,p_balance_type            => l_balance_type_code);
106012    ELSE
106013       NULL;
106014 -- No business flow processing for business flow method of NONE.
106015    END IF;
106016 
106017    --
106018    -- call analytical criteria
106019    --
106020    
106021    --
106022    -- call description
106023    --
106024    
106025 xla_ae_lines_pkg.SetLineDescription(
106026    p_ae_header_id => l_ae_header_id
106027   ,p_description  => Description_79 (
106028      p_application_id         => p_application_id
106029    , p_ae_header_id           => l_ae_header_id 
106030 , p_source_1 => p_source_1
106031    )
106032 );
106033 
106034 
106035    --
106036    -- call ADRs
106037    -- Bug 4922099
106038    --
106039    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
106040         (NVL(l_actual_upg_option, 'N') = 'O') OR
106041         (NVL(l_enc_upg_option, 'N') = 'O')
106042       )
106043    THEN
106044    NULL;
106045    --
106046    --
106047    
106048   l_ccid := AcctDerRule_175(
106049            p_application_id           => p_application_id
106050          , p_ae_header_id             => l_ae_header_id 
106051 , p_source_3 => p_source_3
106052 , p_source_29 => p_source_29
106053          , x_transaction_coa_id       => l_adr_transaction_coa_id
106054          , x_accounting_coa_id        => l_adr_accounting_coa_id
106055          , x_value_type_code          => l_adr_value_type_code
106056          , p_side                     => 'NA'
106057    );
106058 
106059    xla_ae_lines_pkg.set_ccid(
106060     p_code_combination_id          => l_ccid
106061   , p_value_type_code              => l_adr_value_type_code
106062   , p_transaction_coa_id           => l_adr_transaction_coa_id
106066   , p_component_type               => l_component_type
106063   , p_accounting_coa_id            => l_adr_accounting_coa_id
106064   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
106065   , p_adr_type_code                => 'S'
106067   , p_component_code               => l_component_code
106068   , p_component_type_code          => l_component_type_code
106069   , p_component_appl_id            => l_component_appl_id
106070   , p_amb_context_code             => l_amb_context_code
106071   , p_side                         => 'NA'
106072   );
106073 
106074 
106075    --
106076    --
106077    END IF;
106078    --
106079    -- Bug 4922099
106080    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
106081           (NVL(l_enc_upg_option, 'N') = 'O')
106082         ) AND
106083         (l_bflow_method_code = 'PRIOR_ENTRY')
106084       )
106085    THEN
106086       IF
106087       --
106088       1 = 2
106089       --
106090       THEN
106091       xla_accounting_err_pkg.build_message
106092                                     (p_appli_s_name            => 'XLA'
106093                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
106094                                     ,p_token_1                 => 'LINE_NUMBER'
106095                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
106096                                     ,p_token_2                 => 'LINE_TYPE_NAME'
106097                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
106098                                                                              l_component_type
106099                                                                             ,l_component_code
106100                                                                             ,l_component_type_code
106101                                                                             ,l_component_appl_id
106102                                                                             ,l_amb_context_code
106103                                                                             ,l_entity_code
106104                                                                             ,l_event_class_code
106105                                                                            )
106106                                     ,p_token_3                 => 'OWNER'
106107                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
106108                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
106109                                                                           ,p_lookup_code    => l_component_type_code
106110                                                                          )
106111                                     ,p_token_4                 => 'PRODUCT_NAME'
106112                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
106113                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
106114                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
106115                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
106116                                     ,p_ae_header_id            =>  NULL
106117                                        );
106118 
106119         IF (C_LEVEL_ERROR>= g_log_level) THEN
106120                  trace
106121                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
106122                       ,p_level    => C_LEVEL_ERROR
106123                       ,p_module   => l_log_module);
106124         END IF;
106125       END IF;
106126    END IF;
106127    --
106128    --
106129    ------------------------------------------------------------------------------------------------
106130    -- 4219869 Business Flow
106131    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
106132    -- Prior Entry.  Currently, the following code is always generated.
106133    ------------------------------------------------------------------------------------------------
106134    XLA_AE_LINES_PKG.ValidateCurrentLine;
106135 
106136    ------------------------------------------------------------------------------------
106137    -- 4219869 Business Flow
106138    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
106139    ------------------------------------------------------------------------------------
106140    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
106141 
106142    ----------------------------------------------------------------------------------
106143    -- 4219869 Business Flow
106144    -- Update journal entry status -- Need to generate this within IF <condition>
106145    ----------------------------------------------------------------------------------
106146    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
106147          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
106148          ,p_balance_type_code => l_balance_type_code
106149          );
106150 
106151    -------------------------------------------------------------------------------------------
106152    -- 4262811 - Generate the Accrual Reversal lines
106153    -------------------------------------------------------------------------------------------
106154    BEGIN
106155       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
106156                               (g_array_event(p_event_id).array_value_num('header_index'));
106157       IF l_acc_rev_flag IS NULL THEN
106158          l_acc_rev_flag := 'N';
106159       END IF;
106160    EXCEPTION
106161       WHEN OTHERS THEN
106162          l_acc_rev_flag := 'N';
106163    END;
106164    --
106165    IF (l_acc_rev_flag = 'Y') THEN
106166 
106167        -- 4645092  ------------------------------------------------------------------------------
106168        -- To allow MPA report to determine if it should generate report process
106172        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
106169        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
106170        ------------------------------------------------------------------------------------------
106171 
106173        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
106174    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
106175    -- call ADRs
106176    -- Bug 4922099
106177    --
106178    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
106179         (NVL(l_actual_upg_option, 'N') = 'O') OR
106180         (NVL(l_enc_upg_option, 'N') = 'O')
106181       )
106182    THEN
106183    NULL;
106184    --
106185    --
106186    
106187   l_ccid := AcctDerRule_175(
106188            p_application_id           => p_application_id
106189          , p_ae_header_id             => l_ae_header_id 
106190 , p_source_3 => p_source_3
106191 , p_source_29 => p_source_29
106192          , x_transaction_coa_id       => l_adr_transaction_coa_id
106193          , x_accounting_coa_id        => l_adr_accounting_coa_id
106194          , x_value_type_code          => l_adr_value_type_code
106195          , p_side                     => 'NA'
106196    );
106197 
106198    xla_ae_lines_pkg.set_ccid(
106199     p_code_combination_id          => l_ccid
106200   , p_value_type_code              => l_adr_value_type_code
106201   , p_transaction_coa_id           => l_adr_transaction_coa_id
106202   , p_accounting_coa_id            => l_adr_accounting_coa_id
106203   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
106204   , p_adr_type_code                => 'S'
106205   , p_component_type               => l_component_type
106206   , p_component_code               => l_component_code
106207   , p_component_type_code          => l_component_type_code
106208   , p_component_appl_id            => l_component_appl_id
106209   , p_amb_context_code             => l_amb_context_code
106210   , p_side                         => 'NA'
106211   );
106212 
106213 
106214    --
106215    --
106216    END IF;
106217 
106218        --
106219        -- Update the line information that should be overwritten
106220        --
106221        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
106222                                          p_header_num   => 1);
106223        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
106224 
106225        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
106226 
106227        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
106228           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
106229        END IF;
106230 
106231       --
106232       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
106233       --
106234       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
106235           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
106236       ELSE
106237           ---------------------------------------------------------------------------------------------------
106238           -- 4262811a Switch Sign
106239           ---------------------------------------------------------------------------------------------------
106240           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
106241           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
106242                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
106243           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
106244                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
106245           -- 5132302
106246           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
106247                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
106248 
106249       END IF;
106250 
106251       -- 4955764
106252       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
106253       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
106254 
106255 
106256       XLA_AE_LINES_PKG.ValidateCurrentLine;
106257       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
106258 
106259       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
106260                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
106261                ,p_balance_type_code => l_balance_type_code);
106262 
106263    END IF;
106264 
106265    -----------------------------------------------------------------------------------------
106266    -- 4262811 Multiperiod Accounting
106267    -----------------------------------------------------------------------------------------
106268      -- No MPA option is assigned.
106269 
106270 
106271 END IF;
106272 END IF;
106273 --
106274 
106275 --
106276 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
106277    trace
106278       (p_msg      => 'END of AcctLineType_302'
106279       ,p_level    => C_LEVEL_PROCEDURE
106280       ,p_module   => l_log_module);
106281 END IF;
106282 --
106283 EXCEPTION
106284   WHEN xla_exceptions_pkg.application_exception THEN
106285       RAISE;
106286   WHEN OTHERS THEN
106287        xla_exceptions_pkg.raise_message
106288            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_302');
106289 END AcctLineType_302;
106290 --
106291 
106292 ---------------------------------------
106293 --
106294 -- PRIVATE FUNCTION
106295 --         AcctLineType_303
106296 --
106297 ---------------------------------------
106298 PROCEDURE AcctLineType_303 (
106302  ,p_calculate_g_l_flag    IN VARCHAR2
106299   p_application_id        IN NUMBER
106300  ,p_event_id              IN NUMBER
106301  ,p_calculate_acctd_flag  IN VARCHAR2
106303  ,p_actual_flag           IN OUT VARCHAR2
106304  ,p_balance_type_code     OUT VARCHAR2
106305  ,p_gain_or_loss_ref      OUT VARCHAR2
106306  
106307 --Period Close Date
106308  , p_source_1            IN DATE
106309 --Generated Code Combination Identifier
106310  , p_source_3            IN NUMBER
106311 --Depreciation Reserve Account
106312  , p_source_10            IN VARCHAR2
106313 --Generated Offset Code Combination Identifier
106314  , p_source_17            IN NUMBER
106315 --Expense Account Code Combination Identifier
106316  , p_source_29            IN NUMBER
106317 --Default Code Combination Identifier
106318  , p_source_30            IN NUMBER
106319 --Adjustment Type
106320  , p_source_35            IN VARCHAR2
106321 --Transaction Header Identifier
106322  , p_source_36            IN NUMBER
106323 --Adjustment Line Identifier
106324  , p_source_37            IN NUMBER
106325 --Distribution Type Code
106326  , p_source_38            IN VARCHAR2
106327 --Entered Amount
106328  , p_source_39            IN NUMBER
106329 --Currency Code
106330  , p_source_40            IN VARCHAR2
106331 )
106332 IS
106333 
106334 l_component_type              VARCHAR2(80);
106335 l_component_code              VARCHAR2(30);
106336 l_component_type_code         VARCHAR2(1);
106337 l_component_appl_id           INTEGER;
106338 l_amb_context_code            VARCHAR2(30);
106339 l_entity_code                 VARCHAR2(30);
106340 l_event_class_code            VARCHAR2(30);
106341 l_ae_header_id                NUMBER;
106342 l_event_type_code             VARCHAR2(30);
106343 l_line_definition_code        VARCHAR2(30);
106344 l_line_definition_owner_code  VARCHAR2(1);
106345 --
106346 -- adr variables
106347 l_segment                     VARCHAR2(30);
106348 l_ccid                        NUMBER;
106349 l_adr_transaction_coa_id      NUMBER;
106350 l_adr_accounting_coa_id       NUMBER;
106351 l_adr_flexfield_segment_code  VARCHAR2(30);
106352 l_adr_flex_value_set_id       NUMBER;
106353 l_adr_value_type_code         VARCHAR2(30);
106354 l_adr_value_combination_id    NUMBER;
106355 l_adr_value_segment_code      VARCHAR2(30);
106356 
106357 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
106358 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
106359 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
106360 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
106361 
106362 -- 4262811 Variables ------------------------------------------------------------------------------------------
106363 l_entered_amt_idx             NUMBER;
106364 l_accted_amt_idx              NUMBER;
106365 l_acc_rev_flag                VARCHAR2(1);
106366 l_accrual_line_num            NUMBER;
106367 l_tmp_amt                     NUMBER;
106368 l_acc_rev_natural_side_code   VARCHAR2(1);
106369 
106370 l_num_entries                 NUMBER;
106371 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
106372 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
106373 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
106374 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
106375 l_recog_line_1                NUMBER;
106376 l_recog_line_2                NUMBER;
106377 
106378 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
106379 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
106380 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
106381 
106382 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
106383 
106384 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
106385 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
106386 
106387 ---------------------------------------------------------------------------------------------------------------
106388 
106389 
106390 --
106391 -- bulk performance
106392 --
106393 l_balance_type_code           VARCHAR2(1);
106394 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
106395 l_log_module                  VARCHAR2(240);
106396 
106397 --
106398 -- Upgrade strategy
106399 --
106400 l_actual_upg_option           VARCHAR2(1);
106401 l_enc_upg_option           VARCHAR2(1);
106402 
106403 --
106404 BEGIN
106405 --
106406 IF g_log_enabled THEN
106407       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_303';
106408 END IF;
106409 --
106410 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
106411 
106412       trace
106413          (p_msg      => 'BEGIN of AcctLineType_303'
106414          ,p_level    => C_LEVEL_PROCEDURE
106415          ,p_module   => l_log_module);
106416 
106417 END IF;
106418 --
106419 l_component_type             := 'AMB_JLT';
106420 l_component_code             := 'FA_RETIREMENT_DEPRN_RESERVE';
106421 l_component_type_code        := 'S';
106422 l_component_appl_id          :=  140;
106423 l_amb_context_code           := 'DEFAULT';
106424 l_entity_code                := 'TRANSACTIONS';
106425 l_event_class_code           := 'RETIREMENTS';
106426 l_event_type_code            := 'RETIREMENTS';
106427 l_line_definition_owner_code := 'S';
106428 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
106429 --
106430 l_balance_type_code          := 'A';
106431 l_segment                     := NULL;
106432 l_ccid                        := NULL;
106433 l_adr_transaction_coa_id      := NULL;
106434 l_adr_accounting_coa_id       := NULL;
106435 l_adr_flexfield_segment_code  := NULL;
106436 l_adr_flex_value_set_id       := NULL;
106437 l_adr_value_type_code         := NULL;
106438 l_adr_value_combination_id    := NULL;
106442 l_bflow_class_code           := '';    -- 4219869 Business Flow
106439 l_adr_value_segment_code      := NULL;
106440 
106441 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
106443 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
106444 l_budgetary_control_flag     := 'N';
106445 
106446 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
106447 l_bflow_applied_to_amt       := NULL; -- 5132302
106448 l_entered_amt_idx            := NULL;          -- 4262811
106449 l_accted_amt_idx             := NULL;          -- 4262811
106450 l_acc_rev_flag               := NULL;          -- 4262811
106451 l_accrual_line_num           := NULL;          -- 4262811
106452 l_tmp_amt                    := NULL;          -- 4262811
106453 --
106454  
106455 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
106456     l_balance_type_code <> 'B' THEN
106457 IF NVL(p_source_35,'
106458 ') =  'EXPENSE'
106459  THEN 
106460 
106461    --
106462    XLA_AE_LINES_PKG.SetNewLine;
106463 
106464    p_balance_type_code          := l_balance_type_code;
106465    -- set the flag so later we will know whether the gain loss line needs to be created
106466    
106467    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
106468      p_actual_flag :='A';
106469    END IF;
106470 
106471    --
106472    -- bulk performance
106473    --
106474    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
106475                                       p_header_num   => 0); -- 4262811
106476    --
106477    -- set accounting line options
106478    --
106479    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
106480            p_natural_side_code          => 'D'
106481          , p_gain_or_loss_flag          => 'N'
106482          , p_gl_transfer_mode_code      => 'S'
106483          , p_acct_entry_type_code       => 'A'
106484          , p_switch_side_flag           => 'Y'
106485          , p_merge_duplicate_code       => 'N'
106486          );
106487    --
106488    l_acc_rev_natural_side_code := 'C';  -- 4262811
106489    -- 
106490    --
106491    -- set accounting line type info
106492    --
106493    xla_ae_lines_pkg.SetAcctLineType
106494       (p_component_type             => l_component_type
106495       ,p_event_type_code            => l_event_type_code
106496       ,p_line_definition_owner_code => l_line_definition_owner_code
106497       ,p_line_definition_code       => l_line_definition_code
106498       ,p_accounting_line_code       => l_component_code
106499       ,p_accounting_line_type_code  => l_component_type_code
106500       ,p_accounting_line_appl_id    => l_component_appl_id
106501       ,p_amb_context_code           => l_amb_context_code
106502       ,p_entity_code                => l_entity_code
106503       ,p_event_class_code           => l_event_class_code);
106504    --
106505    -- set accounting class
106506    --
106507    xla_ae_lines_pkg.SetAcctClass(
106508            p_accounting_class_code  => 'ASSET'
106509          , p_ae_header_id           => l_ae_header_id
106510          );
106511 
106512    --
106513    -- set rounding class
106514    --
106515    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
106516                       'ASSET';
106517 
106518    --
106519    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
106520    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
106521    --
106522    -- bulk performance
106523    --
106524    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
106525 
106526    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
106527       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
106528 
106529    -- 4955764
106530    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
106531       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
106532 
106533    -- 4458381 Public Sector Enh
106534    
106535    --
106536    -- set accounting attributes for the line type
106537    --
106538    l_entered_amt_idx := 4;
106539    l_accted_amt_idx  := 6;
106540    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
106541    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
106542    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
106543    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
106544    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
106545    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
106546    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
106547    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
106548    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
106549    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
106550    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
106551    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
106552    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
106553 
106554    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
106555    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
106556 
106557    ---------------------------------------------------------------------------------------------------------------
106558    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
106559    ---------------------------------------------------------------------------------------------------------------
106560    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
106561 
106562    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
106566          (p_source_code         => 'LEDGER_CATEGORY_CODE'
106563    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
106564 
106565    IF xla_accounting_cache_pkg.GetValueChar
106567          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
106568    AND l_bflow_method_code = 'PRIOR_ENTRY'
106569 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
106570    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
106571          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
106572        )
106573    THEN
106574          xla_ae_lines_pkg.BflowUpgEntry
106575            (p_business_method_code    => l_bflow_method_code
106576            ,p_business_class_code     => l_bflow_class_code
106577            ,p_balance_type            => l_balance_type_code);
106578    ELSE
106579       NULL;
106580 -- No business flow processing for business flow method of NONE.
106581    END IF;
106582 
106583    --
106584    -- call analytical criteria
106585    --
106586    
106587    --
106588    -- call description
106589    --
106590    
106591 xla_ae_lines_pkg.SetLineDescription(
106592    p_ae_header_id => l_ae_header_id
106593   ,p_description  => Description_82 (
106594      p_application_id         => p_application_id
106595    , p_ae_header_id           => l_ae_header_id 
106596 , p_source_1 => p_source_1
106597    )
106598 );
106599 
106600 
106601    --
106602    -- call ADRs
106603    -- Bug 4922099
106604    --
106605    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
106606         (NVL(l_actual_upg_option, 'N') = 'O') OR
106607         (NVL(l_enc_upg_option, 'N') = 'O')
106608       )
106609    THEN
106610    NULL;
106611    --
106612    --
106613    
106614   l_ccid := AcctDerRule_174(
106615            p_application_id           => p_application_id
106616          , p_ae_header_id             => l_ae_header_id 
106617 , p_source_3 => p_source_3
106618 , p_source_17 => p_source_17
106619 , p_source_30 => p_source_30
106620          , x_transaction_coa_id       => l_adr_transaction_coa_id
106621          , x_accounting_coa_id        => l_adr_accounting_coa_id
106622          , x_value_type_code          => l_adr_value_type_code
106623          , p_side                     => 'NA'
106624    );
106625 
106626    xla_ae_lines_pkg.set_ccid(
106627     p_code_combination_id          => l_ccid
106628   , p_value_type_code              => l_adr_value_type_code
106629   , p_transaction_coa_id           => l_adr_transaction_coa_id
106630   , p_accounting_coa_id            => l_adr_accounting_coa_id
106631   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
106632   , p_adr_type_code                => 'S'
106633   , p_component_type               => l_component_type
106634   , p_component_code               => l_component_code
106635   , p_component_type_code          => l_component_type_code
106636   , p_component_appl_id            => l_component_appl_id
106637   , p_amb_context_code             => l_amb_context_code
106638   , p_side                         => 'NA'
106639   );
106640 
106641 
106642    l_segment := AcctDerRule_149(
106643            p_application_id           => p_application_id
106644          , p_ae_header_id             => l_ae_header_id 
106645 , p_source_3 => p_source_3
106646 , p_source_10 => p_source_10
106647          , x_transaction_coa_id       => l_adr_transaction_coa_id
106648          , x_accounting_coa_id        => l_adr_accounting_coa_id
106649          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
106650          , x_flex_value_set_id        => l_adr_flex_value_set_id
106651          , x_value_type_code          => l_adr_value_type_code
106652          , x_value_combination_id     => l_adr_value_combination_id
106653          , x_value_segment_code       => l_adr_value_segment_code
106654          , p_side                     => 'NA'
106655          , p_override_seg_flag        => 'Y'
106656    );
106657 
106658    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
106659 
106660       xla_ae_lines_pkg.set_segment(
106661           p_to_segment_code         => 'GL_ACCOUNT'
106662         , p_segment_value           => l_segment
106663         , p_from_segment_code       => l_adr_value_segment_code
106664         , p_from_combination_id     => l_adr_value_combination_id
106665         , p_value_type_code         => l_adr_value_type_code
106666         , p_transaction_coa_id      => l_adr_transaction_coa_id
106667         , p_accounting_coa_id       => l_adr_accounting_coa_id
106668         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
106669         , p_flex_value_set_id       => l_adr_flex_value_set_id
106670         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
106671         , p_adr_type_code           => 'S'
106672         , p_component_type          => l_component_type
106673         , p_component_code          => l_component_code
106674         , p_component_type_code     => l_component_type_code
106675         , p_component_appl_id       => l_component_appl_id
106676         , p_amb_context_code        => l_amb_context_code
106677         , p_entity_code             => 'TRANSACTIONS'
106678         , p_event_class_code        => 'RETIREMENTS'
106679         , p_side                    => 'NA'
106680         );
106681 
106682   END IF;
106683 
106684    l_segment := AcctDerRule_168(
106685            p_application_id           => p_application_id
106686          , p_ae_header_id             => l_ae_header_id 
106687 , p_source_3 => p_source_3
106688 , p_source_29 => p_source_29
106689          , x_transaction_coa_id       => l_adr_transaction_coa_id
106690          , x_accounting_coa_id        => l_adr_accounting_coa_id
106691          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
106692          , x_flex_value_set_id        => l_adr_flex_value_set_id
106693          , x_value_type_code          => l_adr_value_type_code
106697          , p_override_seg_flag        => 'Y'
106694          , x_value_combination_id     => l_adr_value_combination_id
106695          , x_value_segment_code       => l_adr_value_segment_code
106696          , p_side                     => 'NA'
106698    );
106699 
106700    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
106701 
106702       xla_ae_lines_pkg.set_segment(
106703           p_to_segment_code         => 'GL_BALANCING'
106704         , p_segment_value           => l_segment
106705         , p_from_segment_code       => l_adr_value_segment_code
106706         , p_from_combination_id     => l_adr_value_combination_id
106707         , p_value_type_code         => l_adr_value_type_code
106708         , p_transaction_coa_id      => l_adr_transaction_coa_id
106709         , p_accounting_coa_id       => l_adr_accounting_coa_id
106710         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
106711         , p_flex_value_set_id       => l_adr_flex_value_set_id
106712         , p_adr_code                => 'FA_EXPENSE_ACCT'
106713         , p_adr_type_code           => 'S'
106714         , p_component_type          => l_component_type
106715         , p_component_code          => l_component_code
106716         , p_component_type_code     => l_component_type_code
106717         , p_component_appl_id       => l_component_appl_id
106718         , p_amb_context_code        => l_amb_context_code
106719         , p_entity_code             => 'TRANSACTIONS'
106720         , p_event_class_code        => 'RETIREMENTS'
106721         , p_side                    => 'NA'
106722         );
106723 
106724   END IF;
106725 
106726    --
106727    --
106728    END IF;
106729    --
106730    -- Bug 4922099
106731    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
106732           (NVL(l_enc_upg_option, 'N') = 'O')
106733         ) AND
106734         (l_bflow_method_code = 'PRIOR_ENTRY')
106735       )
106736    THEN
106737       IF
106738       --
106739       1 = 2
106740       --
106741       THEN
106742       xla_accounting_err_pkg.build_message
106743                                     (p_appli_s_name            => 'XLA'
106744                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
106745                                     ,p_token_1                 => 'LINE_NUMBER'
106746                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
106747                                     ,p_token_2                 => 'LINE_TYPE_NAME'
106748                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
106749                                                                              l_component_type
106750                                                                             ,l_component_code
106751                                                                             ,l_component_type_code
106752                                                                             ,l_component_appl_id
106753                                                                             ,l_amb_context_code
106754                                                                             ,l_entity_code
106755                                                                             ,l_event_class_code
106756                                                                            )
106757                                     ,p_token_3                 => 'OWNER'
106758                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
106759                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
106760                                                                           ,p_lookup_code    => l_component_type_code
106761                                                                          )
106762                                     ,p_token_4                 => 'PRODUCT_NAME'
106763                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
106764                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
106765                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
106766                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
106767                                     ,p_ae_header_id            =>  NULL
106768                                        );
106769 
106770         IF (C_LEVEL_ERROR>= g_log_level) THEN
106771                  trace
106772                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
106773                       ,p_level    => C_LEVEL_ERROR
106774                       ,p_module   => l_log_module);
106775         END IF;
106776       END IF;
106777    END IF;
106778    --
106779    --
106780    ------------------------------------------------------------------------------------------------
106781    -- 4219869 Business Flow
106782    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
106783    -- Prior Entry.  Currently, the following code is always generated.
106784    ------------------------------------------------------------------------------------------------
106785    XLA_AE_LINES_PKG.ValidateCurrentLine;
106786 
106787    ------------------------------------------------------------------------------------
106788    -- 4219869 Business Flow
106789    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
106790    ------------------------------------------------------------------------------------
106791    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
106792 
106793    ----------------------------------------------------------------------------------
106794    -- 4219869 Business Flow
106795    -- Update journal entry status -- Need to generate this within IF <condition>
106796    ----------------------------------------------------------------------------------
106797    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
106801 
106798          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
106799          ,p_balance_type_code => l_balance_type_code
106800          );
106802    -------------------------------------------------------------------------------------------
106803    -- 4262811 - Generate the Accrual Reversal lines
106804    -------------------------------------------------------------------------------------------
106805    BEGIN
106806       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
106807                               (g_array_event(p_event_id).array_value_num('header_index'));
106808       IF l_acc_rev_flag IS NULL THEN
106809          l_acc_rev_flag := 'N';
106810       END IF;
106811    EXCEPTION
106812       WHEN OTHERS THEN
106813          l_acc_rev_flag := 'N';
106814    END;
106815    --
106816    IF (l_acc_rev_flag = 'Y') THEN
106817 
106818        -- 4645092  ------------------------------------------------------------------------------
106819        -- To allow MPA report to determine if it should generate report process
106820        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
106821        ------------------------------------------------------------------------------------------
106822 
106823        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
106824        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
106825    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
106826    -- call ADRs
106827    -- Bug 4922099
106828    --
106829    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
106830         (NVL(l_actual_upg_option, 'N') = 'O') OR
106831         (NVL(l_enc_upg_option, 'N') = 'O')
106832       )
106833    THEN
106834    NULL;
106835    --
106836    --
106837    
106838   l_ccid := AcctDerRule_174(
106839            p_application_id           => p_application_id
106840          , p_ae_header_id             => l_ae_header_id 
106841 , p_source_3 => p_source_3
106842 , p_source_17 => p_source_17
106843 , p_source_30 => p_source_30
106844          , x_transaction_coa_id       => l_adr_transaction_coa_id
106845          , x_accounting_coa_id        => l_adr_accounting_coa_id
106846          , x_value_type_code          => l_adr_value_type_code
106847          , p_side                     => 'NA'
106848    );
106849 
106850    xla_ae_lines_pkg.set_ccid(
106851     p_code_combination_id          => l_ccid
106852   , p_value_type_code              => l_adr_value_type_code
106853   , p_transaction_coa_id           => l_adr_transaction_coa_id
106854   , p_accounting_coa_id            => l_adr_accounting_coa_id
106855   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
106856   , p_adr_type_code                => 'S'
106857   , p_component_type               => l_component_type
106858   , p_component_code               => l_component_code
106859   , p_component_type_code          => l_component_type_code
106860   , p_component_appl_id            => l_component_appl_id
106861   , p_amb_context_code             => l_amb_context_code
106862   , p_side                         => 'NA'
106863   );
106864 
106865 
106866    l_segment := AcctDerRule_149(
106867            p_application_id           => p_application_id
106868          , p_ae_header_id             => l_ae_header_id 
106869 , p_source_3 => p_source_3
106870 , p_source_10 => p_source_10
106871          , x_transaction_coa_id       => l_adr_transaction_coa_id
106872          , x_accounting_coa_id        => l_adr_accounting_coa_id
106873          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
106874          , x_flex_value_set_id        => l_adr_flex_value_set_id
106875          , x_value_type_code          => l_adr_value_type_code
106876          , x_value_combination_id     => l_adr_value_combination_id
106877          , x_value_segment_code       => l_adr_value_segment_code
106878          , p_side                     => 'NA'
106879          , p_override_seg_flag        => 'Y'
106880    );
106881 
106882    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
106883 
106884       xla_ae_lines_pkg.set_segment(
106885           p_to_segment_code         => 'GL_ACCOUNT'
106886         , p_segment_value           => l_segment
106887         , p_from_segment_code       => l_adr_value_segment_code
106888         , p_from_combination_id     => l_adr_value_combination_id
106889         , p_value_type_code         => l_adr_value_type_code
106890         , p_transaction_coa_id      => l_adr_transaction_coa_id
106891         , p_accounting_coa_id       => l_adr_accounting_coa_id
106892         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
106893         , p_flex_value_set_id       => l_adr_flex_value_set_id
106894         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
106895         , p_adr_type_code           => 'S'
106896         , p_component_type          => l_component_type
106897         , p_component_code          => l_component_code
106898         , p_component_type_code     => l_component_type_code
106899         , p_component_appl_id       => l_component_appl_id
106900         , p_amb_context_code        => l_amb_context_code
106901         , p_entity_code             => 'TRANSACTIONS'
106902         , p_event_class_code        => 'RETIREMENTS'
106903         , p_side                    => 'NA'
106904         );
106905 
106906   END IF;
106907 
106908    l_segment := AcctDerRule_168(
106909            p_application_id           => p_application_id
106910          , p_ae_header_id             => l_ae_header_id 
106911 , p_source_3 => p_source_3
106912 , p_source_29 => p_source_29
106913          , x_transaction_coa_id       => l_adr_transaction_coa_id
106914          , x_accounting_coa_id        => l_adr_accounting_coa_id
106915          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
106916          , x_flex_value_set_id        => l_adr_flex_value_set_id
106917          , x_value_type_code          => l_adr_value_type_code
106918          , x_value_combination_id     => l_adr_value_combination_id
106922    );
106919          , x_value_segment_code       => l_adr_value_segment_code
106920          , p_side                     => 'NA'
106921          , p_override_seg_flag        => 'Y'
106923 
106924    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
106925 
106926       xla_ae_lines_pkg.set_segment(
106927           p_to_segment_code         => 'GL_BALANCING'
106928         , p_segment_value           => l_segment
106929         , p_from_segment_code       => l_adr_value_segment_code
106930         , p_from_combination_id     => l_adr_value_combination_id
106931         , p_value_type_code         => l_adr_value_type_code
106932         , p_transaction_coa_id      => l_adr_transaction_coa_id
106933         , p_accounting_coa_id       => l_adr_accounting_coa_id
106934         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
106935         , p_flex_value_set_id       => l_adr_flex_value_set_id
106936         , p_adr_code                => 'FA_EXPENSE_ACCT'
106937         , p_adr_type_code           => 'S'
106938         , p_component_type          => l_component_type
106939         , p_component_code          => l_component_code
106940         , p_component_type_code     => l_component_type_code
106941         , p_component_appl_id       => l_component_appl_id
106942         , p_amb_context_code        => l_amb_context_code
106943         , p_entity_code             => 'TRANSACTIONS'
106944         , p_event_class_code        => 'RETIREMENTS'
106945         , p_side                    => 'NA'
106946         );
106947 
106948   END IF;
106949 
106950    --
106951    --
106952    END IF;
106953 
106954        --
106955        -- Update the line information that should be overwritten
106956        --
106957        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
106958                                          p_header_num   => 1);
106959        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
106960 
106961        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
106962 
106963        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
106964           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
106965        END IF;
106966 
106967       --
106968       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
106969       --
106970       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
106971           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
106972       ELSE
106973           ---------------------------------------------------------------------------------------------------
106974           -- 4262811a Switch Sign
106975           ---------------------------------------------------------------------------------------------------
106976           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
106977           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
106978                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
106979           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
106980                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
106981           -- 5132302
106982           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
106983                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
106984 
106985       END IF;
106986 
106987       -- 4955764
106988       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
106989       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
106990 
106991 
106992       XLA_AE_LINES_PKG.ValidateCurrentLine;
106993       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
106994 
106995       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
106996                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
106997                ,p_balance_type_code => l_balance_type_code);
106998 
106999    END IF;
107000 
107001    -----------------------------------------------------------------------------------------
107002    -- 4262811 Multiperiod Accounting
107003    -----------------------------------------------------------------------------------------
107004      -- No MPA option is assigned.
107005 
107006 
107007 END IF;
107008 END IF;
107009 --
107010 
107011 --
107012 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
107013    trace
107014       (p_msg      => 'END of AcctLineType_303'
107015       ,p_level    => C_LEVEL_PROCEDURE
107016       ,p_module   => l_log_module);
107017 END IF;
107018 --
107019 EXCEPTION
107020   WHEN xla_exceptions_pkg.application_exception THEN
107021       RAISE;
107022   WHEN OTHERS THEN
107023        xla_exceptions_pkg.raise_message
107024            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_303');
107025 END AcctLineType_303;
107026 --
107027 
107028 ---------------------------------------
107029 --
107030 -- PRIVATE FUNCTION
107031 --         AcctLineType_304
107032 --
107033 ---------------------------------------
107034 PROCEDURE AcctLineType_304 (
107035   p_application_id        IN NUMBER
107036  ,p_event_id              IN NUMBER
107037  ,p_calculate_acctd_flag  IN VARCHAR2
107038  ,p_calculate_g_l_flag    IN VARCHAR2
107039  ,p_actual_flag           IN OUT VARCHAR2
107040  ,p_balance_type_code     OUT VARCHAR2
107041  ,p_gain_or_loss_ref      OUT VARCHAR2
107042  
107043 --Period Close Date
107044  , p_source_1            IN DATE
107045 --Generated Code Combination Identifier
107046  , p_source_3            IN NUMBER
107050  , p_source_17            IN NUMBER
107047 --Depreciation Reserve Account
107048  , p_source_10            IN VARCHAR2
107049 --Generated Offset Code Combination Identifier
107051 --Expense Account Code Combination Identifier
107052  , p_source_29            IN NUMBER
107053 --Default Code Combination Identifier
107054  , p_source_30            IN NUMBER
107055 --Adjustment Type
107056  , p_source_35            IN VARCHAR2
107057 --Transaction Header Identifier
107058  , p_source_36            IN NUMBER
107059 --Adjustment Line Identifier
107060  , p_source_37            IN NUMBER
107061 --Distribution Type Code
107062  , p_source_38            IN VARCHAR2
107063 --Entered Amount
107064  , p_source_39            IN NUMBER
107065 --Currency Code
107066  , p_source_40            IN VARCHAR2
107067 )
107068 IS
107069 
107070 l_component_type              VARCHAR2(80);
107071 l_component_code              VARCHAR2(30);
107072 l_component_type_code         VARCHAR2(1);
107073 l_component_appl_id           INTEGER;
107074 l_amb_context_code            VARCHAR2(30);
107075 l_entity_code                 VARCHAR2(30);
107076 l_event_class_code            VARCHAR2(30);
107077 l_ae_header_id                NUMBER;
107078 l_event_type_code             VARCHAR2(30);
107079 l_line_definition_code        VARCHAR2(30);
107080 l_line_definition_owner_code  VARCHAR2(1);
107081 --
107082 -- adr variables
107083 l_segment                     VARCHAR2(30);
107084 l_ccid                        NUMBER;
107085 l_adr_transaction_coa_id      NUMBER;
107086 l_adr_accounting_coa_id       NUMBER;
107087 l_adr_flexfield_segment_code  VARCHAR2(30);
107088 l_adr_flex_value_set_id       NUMBER;
107089 l_adr_value_type_code         VARCHAR2(30);
107090 l_adr_value_combination_id    NUMBER;
107091 l_adr_value_segment_code      VARCHAR2(30);
107092 
107093 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
107094 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
107095 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
107096 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
107097 
107098 -- 4262811 Variables ------------------------------------------------------------------------------------------
107099 l_entered_amt_idx             NUMBER;
107100 l_accted_amt_idx              NUMBER;
107101 l_acc_rev_flag                VARCHAR2(1);
107102 l_accrual_line_num            NUMBER;
107103 l_tmp_amt                     NUMBER;
107104 l_acc_rev_natural_side_code   VARCHAR2(1);
107105 
107106 l_num_entries                 NUMBER;
107107 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
107108 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
107109 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
107110 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
107111 l_recog_line_1                NUMBER;
107112 l_recog_line_2                NUMBER;
107113 
107114 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
107115 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
107116 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
107117 
107118 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
107119 
107120 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
107121 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
107122 
107123 ---------------------------------------------------------------------------------------------------------------
107124 
107125 
107126 --
107127 -- bulk performance
107128 --
107129 l_balance_type_code           VARCHAR2(1);
107130 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
107131 l_log_module                  VARCHAR2(240);
107132 
107133 --
107134 -- Upgrade strategy
107135 --
107136 l_actual_upg_option           VARCHAR2(1);
107137 l_enc_upg_option           VARCHAR2(1);
107138 
107139 --
107140 BEGIN
107141 --
107142 IF g_log_enabled THEN
107143       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_304';
107144 END IF;
107145 --
107146 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
107147 
107148       trace
107149          (p_msg      => 'BEGIN of AcctLineType_304'
107150          ,p_level    => C_LEVEL_PROCEDURE
107151          ,p_module   => l_log_module);
107152 
107153 END IF;
107154 --
107155 l_component_type             := 'AMB_JLT';
107156 l_component_code             := 'FA_RETIREMENT_DEPRN_RESERVE';
107157 l_component_type_code        := 'S';
107158 l_component_appl_id          :=  140;
107159 l_amb_context_code           := 'DEFAULT';
107160 l_entity_code                := 'TRANSACTIONS';
107161 l_event_class_code           := 'RETIREMENTS';
107162 l_event_type_code            := 'REINSTATEMENTS';
107163 l_line_definition_owner_code := 'S';
107164 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
107165 --
107166 l_balance_type_code          := 'A';
107167 l_segment                     := NULL;
107168 l_ccid                        := NULL;
107169 l_adr_transaction_coa_id      := NULL;
107170 l_adr_accounting_coa_id       := NULL;
107171 l_adr_flexfield_segment_code  := NULL;
107172 l_adr_flex_value_set_id       := NULL;
107173 l_adr_value_type_code         := NULL;
107174 l_adr_value_combination_id    := NULL;
107175 l_adr_value_segment_code      := NULL;
107176 
107177 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
107178 l_bflow_class_code           := '';    -- 4219869 Business Flow
107179 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
107180 l_budgetary_control_flag     := 'N';
107181 
107182 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
107183 l_bflow_applied_to_amt       := NULL; -- 5132302
107184 l_entered_amt_idx            := NULL;          -- 4262811
107188 l_tmp_amt                    := NULL;          -- 4262811
107185 l_accted_amt_idx             := NULL;          -- 4262811
107186 l_acc_rev_flag               := NULL;          -- 4262811
107187 l_accrual_line_num           := NULL;          -- 4262811
107189 --
107190  
107191 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
107192     l_balance_type_code <> 'B' THEN
107193 IF NVL(p_source_35,'
107194 ') =  'EXPENSE'
107195  THEN 
107196 
107197    --
107198    XLA_AE_LINES_PKG.SetNewLine;
107199 
107200    p_balance_type_code          := l_balance_type_code;
107201    -- set the flag so later we will know whether the gain loss line needs to be created
107202    
107203    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
107204      p_actual_flag :='A';
107205    END IF;
107206 
107207    --
107208    -- bulk performance
107209    --
107210    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
107211                                       p_header_num   => 0); -- 4262811
107212    --
107213    -- set accounting line options
107214    --
107215    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
107216            p_natural_side_code          => 'D'
107217          , p_gain_or_loss_flag          => 'N'
107218          , p_gl_transfer_mode_code      => 'S'
107219          , p_acct_entry_type_code       => 'A'
107220          , p_switch_side_flag           => 'Y'
107221          , p_merge_duplicate_code       => 'N'
107222          );
107223    --
107224    l_acc_rev_natural_side_code := 'C';  -- 4262811
107225    -- 
107226    --
107227    -- set accounting line type info
107228    --
107229    xla_ae_lines_pkg.SetAcctLineType
107230       (p_component_type             => l_component_type
107231       ,p_event_type_code            => l_event_type_code
107232       ,p_line_definition_owner_code => l_line_definition_owner_code
107233       ,p_line_definition_code       => l_line_definition_code
107234       ,p_accounting_line_code       => l_component_code
107235       ,p_accounting_line_type_code  => l_component_type_code
107236       ,p_accounting_line_appl_id    => l_component_appl_id
107237       ,p_amb_context_code           => l_amb_context_code
107238       ,p_entity_code                => l_entity_code
107239       ,p_event_class_code           => l_event_class_code);
107240    --
107241    -- set accounting class
107242    --
107243    xla_ae_lines_pkg.SetAcctClass(
107244            p_accounting_class_code  => 'ASSET'
107245          , p_ae_header_id           => l_ae_header_id
107246          );
107247 
107248    --
107249    -- set rounding class
107250    --
107251    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
107252                       'ASSET';
107253 
107254    --
107255    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
107256    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
107257    --
107258    -- bulk performance
107259    --
107260    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
107261 
107262    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
107263       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
107264 
107265    -- 4955764
107266    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
107267       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
107268 
107269    -- 4458381 Public Sector Enh
107270    
107271    --
107272    -- set accounting attributes for the line type
107273    --
107274    l_entered_amt_idx := 4;
107275    l_accted_amt_idx  := 6;
107276    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
107277    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
107278    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
107279    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
107280    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
107281    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
107282    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
107283    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
107284    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
107285    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
107286    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
107287    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
107288    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
107289 
107290    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
107291    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
107292 
107293    ---------------------------------------------------------------------------------------------------------------
107294    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
107295    ---------------------------------------------------------------------------------------------------------------
107296    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
107297 
107298    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
107299    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
107300 
107301    IF xla_accounting_cache_pkg.GetValueChar
107302          (p_source_code         => 'LEDGER_CATEGORY_CODE'
107303          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
107304    AND l_bflow_method_code = 'PRIOR_ENTRY'
107305 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
107306    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
107310          xla_ae_lines_pkg.BflowUpgEntry
107307          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
107308        )
107309    THEN
107311            (p_business_method_code    => l_bflow_method_code
107312            ,p_business_class_code     => l_bflow_class_code
107313            ,p_balance_type            => l_balance_type_code);
107314    ELSE
107315       NULL;
107316 -- No business flow processing for business flow method of NONE.
107317    END IF;
107318 
107319    --
107320    -- call analytical criteria
107321    --
107322    
107323    --
107324    -- call description
107325    --
107326    
107327 xla_ae_lines_pkg.SetLineDescription(
107328    p_ae_header_id => l_ae_header_id
107329   ,p_description  => Description_82 (
107330      p_application_id         => p_application_id
107331    , p_ae_header_id           => l_ae_header_id 
107332 , p_source_1 => p_source_1
107333    )
107334 );
107335 
107336 
107337    --
107338    -- call ADRs
107339    -- Bug 4922099
107340    --
107341    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
107342         (NVL(l_actual_upg_option, 'N') = 'O') OR
107343         (NVL(l_enc_upg_option, 'N') = 'O')
107344       )
107345    THEN
107346    NULL;
107347    --
107348    --
107349    
107350   l_ccid := AcctDerRule_174(
107351            p_application_id           => p_application_id
107352          , p_ae_header_id             => l_ae_header_id 
107353 , p_source_3 => p_source_3
107354 , p_source_17 => p_source_17
107355 , p_source_30 => p_source_30
107356          , x_transaction_coa_id       => l_adr_transaction_coa_id
107357          , x_accounting_coa_id        => l_adr_accounting_coa_id
107358          , x_value_type_code          => l_adr_value_type_code
107359          , p_side                     => 'NA'
107360    );
107361 
107362    xla_ae_lines_pkg.set_ccid(
107363     p_code_combination_id          => l_ccid
107364   , p_value_type_code              => l_adr_value_type_code
107365   , p_transaction_coa_id           => l_adr_transaction_coa_id
107366   , p_accounting_coa_id            => l_adr_accounting_coa_id
107367   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
107368   , p_adr_type_code                => 'S'
107369   , p_component_type               => l_component_type
107370   , p_component_code               => l_component_code
107371   , p_component_type_code          => l_component_type_code
107372   , p_component_appl_id            => l_component_appl_id
107373   , p_amb_context_code             => l_amb_context_code
107374   , p_side                         => 'NA'
107375   );
107376 
107377 
107378    l_segment := AcctDerRule_149(
107379            p_application_id           => p_application_id
107380          , p_ae_header_id             => l_ae_header_id 
107381 , p_source_3 => p_source_3
107382 , p_source_10 => p_source_10
107383          , x_transaction_coa_id       => l_adr_transaction_coa_id
107384          , x_accounting_coa_id        => l_adr_accounting_coa_id
107385          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
107386          , x_flex_value_set_id        => l_adr_flex_value_set_id
107387          , x_value_type_code          => l_adr_value_type_code
107388          , x_value_combination_id     => l_adr_value_combination_id
107389          , x_value_segment_code       => l_adr_value_segment_code
107390          , p_side                     => 'NA'
107391          , p_override_seg_flag        => 'Y'
107392    );
107393 
107394    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
107395 
107396       xla_ae_lines_pkg.set_segment(
107397           p_to_segment_code         => 'GL_ACCOUNT'
107398         , p_segment_value           => l_segment
107399         , p_from_segment_code       => l_adr_value_segment_code
107400         , p_from_combination_id     => l_adr_value_combination_id
107401         , p_value_type_code         => l_adr_value_type_code
107402         , p_transaction_coa_id      => l_adr_transaction_coa_id
107403         , p_accounting_coa_id       => l_adr_accounting_coa_id
107404         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
107405         , p_flex_value_set_id       => l_adr_flex_value_set_id
107406         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
107407         , p_adr_type_code           => 'S'
107408         , p_component_type          => l_component_type
107409         , p_component_code          => l_component_code
107410         , p_component_type_code     => l_component_type_code
107411         , p_component_appl_id       => l_component_appl_id
107412         , p_amb_context_code        => l_amb_context_code
107413         , p_entity_code             => 'TRANSACTIONS'
107414         , p_event_class_code        => 'RETIREMENTS'
107415         , p_side                    => 'NA'
107416         );
107417 
107418   END IF;
107419 
107420    l_segment := AcctDerRule_168(
107421            p_application_id           => p_application_id
107422          , p_ae_header_id             => l_ae_header_id 
107423 , p_source_3 => p_source_3
107424 , p_source_29 => p_source_29
107425          , x_transaction_coa_id       => l_adr_transaction_coa_id
107426          , x_accounting_coa_id        => l_adr_accounting_coa_id
107427          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
107428          , x_flex_value_set_id        => l_adr_flex_value_set_id
107429          , x_value_type_code          => l_adr_value_type_code
107430          , x_value_combination_id     => l_adr_value_combination_id
107431          , x_value_segment_code       => l_adr_value_segment_code
107432          , p_side                     => 'NA'
107433          , p_override_seg_flag        => 'Y'
107434    );
107435 
107436    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
107437 
107438       xla_ae_lines_pkg.set_segment(
107439           p_to_segment_code         => 'GL_BALANCING'
107440         , p_segment_value           => l_segment
107444         , p_transaction_coa_id      => l_adr_transaction_coa_id
107441         , p_from_segment_code       => l_adr_value_segment_code
107442         , p_from_combination_id     => l_adr_value_combination_id
107443         , p_value_type_code         => l_adr_value_type_code
107445         , p_accounting_coa_id       => l_adr_accounting_coa_id
107446         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
107447         , p_flex_value_set_id       => l_adr_flex_value_set_id
107448         , p_adr_code                => 'FA_EXPENSE_ACCT'
107449         , p_adr_type_code           => 'S'
107450         , p_component_type          => l_component_type
107451         , p_component_code          => l_component_code
107452         , p_component_type_code     => l_component_type_code
107453         , p_component_appl_id       => l_component_appl_id
107454         , p_amb_context_code        => l_amb_context_code
107455         , p_entity_code             => 'TRANSACTIONS'
107456         , p_event_class_code        => 'RETIREMENTS'
107457         , p_side                    => 'NA'
107458         );
107459 
107460   END IF;
107461 
107462    --
107463    --
107464    END IF;
107465    --
107466    -- Bug 4922099
107467    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
107468           (NVL(l_enc_upg_option, 'N') = 'O')
107469         ) AND
107470         (l_bflow_method_code = 'PRIOR_ENTRY')
107471       )
107472    THEN
107473       IF
107474       --
107475       1 = 2
107476       --
107477       THEN
107478       xla_accounting_err_pkg.build_message
107479                                     (p_appli_s_name            => 'XLA'
107480                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
107481                                     ,p_token_1                 => 'LINE_NUMBER'
107482                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
107483                                     ,p_token_2                 => 'LINE_TYPE_NAME'
107484                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
107485                                                                              l_component_type
107486                                                                             ,l_component_code
107487                                                                             ,l_component_type_code
107488                                                                             ,l_component_appl_id
107489                                                                             ,l_amb_context_code
107490                                                                             ,l_entity_code
107491                                                                             ,l_event_class_code
107492                                                                            )
107493                                     ,p_token_3                 => 'OWNER'
107494                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
107495                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
107496                                                                           ,p_lookup_code    => l_component_type_code
107497                                                                          )
107498                                     ,p_token_4                 => 'PRODUCT_NAME'
107499                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
107500                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
107501                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
107502                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
107503                                     ,p_ae_header_id            =>  NULL
107504                                        );
107505 
107506         IF (C_LEVEL_ERROR>= g_log_level) THEN
107507                  trace
107508                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
107509                       ,p_level    => C_LEVEL_ERROR
107510                       ,p_module   => l_log_module);
107511         END IF;
107512       END IF;
107513    END IF;
107514    --
107515    --
107516    ------------------------------------------------------------------------------------------------
107517    -- 4219869 Business Flow
107518    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
107519    -- Prior Entry.  Currently, the following code is always generated.
107520    ------------------------------------------------------------------------------------------------
107521    XLA_AE_LINES_PKG.ValidateCurrentLine;
107522 
107523    ------------------------------------------------------------------------------------
107524    -- 4219869 Business Flow
107525    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
107526    ------------------------------------------------------------------------------------
107527    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
107528 
107529    ----------------------------------------------------------------------------------
107530    -- 4219869 Business Flow
107531    -- Update journal entry status -- Need to generate this within IF <condition>
107532    ----------------------------------------------------------------------------------
107533    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
107534          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
107535          ,p_balance_type_code => l_balance_type_code
107536          );
107537 
107538    -------------------------------------------------------------------------------------------
107539    -- 4262811 - Generate the Accrual Reversal lines
107540    -------------------------------------------------------------------------------------------
107541    BEGIN
107542       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
107546       END IF;
107543                               (g_array_event(p_event_id).array_value_num('header_index'));
107544       IF l_acc_rev_flag IS NULL THEN
107545          l_acc_rev_flag := 'N';
107547    EXCEPTION
107548       WHEN OTHERS THEN
107549          l_acc_rev_flag := 'N';
107550    END;
107551    --
107552    IF (l_acc_rev_flag = 'Y') THEN
107553 
107554        -- 4645092  ------------------------------------------------------------------------------
107555        -- To allow MPA report to determine if it should generate report process
107556        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
107557        ------------------------------------------------------------------------------------------
107558 
107559        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
107560        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
107561    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
107562    -- call ADRs
107563    -- Bug 4922099
107564    --
107565    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
107566         (NVL(l_actual_upg_option, 'N') = 'O') OR
107567         (NVL(l_enc_upg_option, 'N') = 'O')
107568       )
107569    THEN
107570    NULL;
107571    --
107572    --
107573    
107574   l_ccid := AcctDerRule_174(
107575            p_application_id           => p_application_id
107576          , p_ae_header_id             => l_ae_header_id 
107577 , p_source_3 => p_source_3
107578 , p_source_17 => p_source_17
107579 , p_source_30 => p_source_30
107580          , x_transaction_coa_id       => l_adr_transaction_coa_id
107581          , x_accounting_coa_id        => l_adr_accounting_coa_id
107582          , x_value_type_code          => l_adr_value_type_code
107583          , p_side                     => 'NA'
107584    );
107585 
107586    xla_ae_lines_pkg.set_ccid(
107587     p_code_combination_id          => l_ccid
107588   , p_value_type_code              => l_adr_value_type_code
107589   , p_transaction_coa_id           => l_adr_transaction_coa_id
107590   , p_accounting_coa_id            => l_adr_accounting_coa_id
107591   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
107592   , p_adr_type_code                => 'S'
107593   , p_component_type               => l_component_type
107594   , p_component_code               => l_component_code
107595   , p_component_type_code          => l_component_type_code
107596   , p_component_appl_id            => l_component_appl_id
107597   , p_amb_context_code             => l_amb_context_code
107598   , p_side                         => 'NA'
107599   );
107600 
107601 
107602    l_segment := AcctDerRule_149(
107603            p_application_id           => p_application_id
107604          , p_ae_header_id             => l_ae_header_id 
107605 , p_source_3 => p_source_3
107606 , p_source_10 => p_source_10
107607          , x_transaction_coa_id       => l_adr_transaction_coa_id
107608          , x_accounting_coa_id        => l_adr_accounting_coa_id
107609          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
107610          , x_flex_value_set_id        => l_adr_flex_value_set_id
107611          , x_value_type_code          => l_adr_value_type_code
107612          , x_value_combination_id     => l_adr_value_combination_id
107613          , x_value_segment_code       => l_adr_value_segment_code
107614          , p_side                     => 'NA'
107615          , p_override_seg_flag        => 'Y'
107616    );
107617 
107618    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
107619 
107620       xla_ae_lines_pkg.set_segment(
107621           p_to_segment_code         => 'GL_ACCOUNT'
107622         , p_segment_value           => l_segment
107623         , p_from_segment_code       => l_adr_value_segment_code
107624         , p_from_combination_id     => l_adr_value_combination_id
107625         , p_value_type_code         => l_adr_value_type_code
107626         , p_transaction_coa_id      => l_adr_transaction_coa_id
107627         , p_accounting_coa_id       => l_adr_accounting_coa_id
107628         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
107629         , p_flex_value_set_id       => l_adr_flex_value_set_id
107630         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
107631         , p_adr_type_code           => 'S'
107632         , p_component_type          => l_component_type
107633         , p_component_code          => l_component_code
107634         , p_component_type_code     => l_component_type_code
107635         , p_component_appl_id       => l_component_appl_id
107636         , p_amb_context_code        => l_amb_context_code
107637         , p_entity_code             => 'TRANSACTIONS'
107638         , p_event_class_code        => 'RETIREMENTS'
107639         , p_side                    => 'NA'
107640         );
107641 
107642   END IF;
107643 
107644    l_segment := AcctDerRule_168(
107645            p_application_id           => p_application_id
107646          , p_ae_header_id             => l_ae_header_id 
107647 , p_source_3 => p_source_3
107648 , p_source_29 => p_source_29
107649          , x_transaction_coa_id       => l_adr_transaction_coa_id
107650          , x_accounting_coa_id        => l_adr_accounting_coa_id
107651          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
107652          , x_flex_value_set_id        => l_adr_flex_value_set_id
107653          , x_value_type_code          => l_adr_value_type_code
107654          , x_value_combination_id     => l_adr_value_combination_id
107655          , x_value_segment_code       => l_adr_value_segment_code
107656          , p_side                     => 'NA'
107657          , p_override_seg_flag        => 'Y'
107658    );
107659 
107660    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
107661 
107662       xla_ae_lines_pkg.set_segment(
107663           p_to_segment_code         => 'GL_BALANCING'
107664         , p_segment_value           => l_segment
107665         , p_from_segment_code       => l_adr_value_segment_code
107669         , p_accounting_coa_id       => l_adr_accounting_coa_id
107666         , p_from_combination_id     => l_adr_value_combination_id
107667         , p_value_type_code         => l_adr_value_type_code
107668         , p_transaction_coa_id      => l_adr_transaction_coa_id
107670         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
107671         , p_flex_value_set_id       => l_adr_flex_value_set_id
107672         , p_adr_code                => 'FA_EXPENSE_ACCT'
107673         , p_adr_type_code           => 'S'
107674         , p_component_type          => l_component_type
107675         , p_component_code          => l_component_code
107676         , p_component_type_code     => l_component_type_code
107677         , p_component_appl_id       => l_component_appl_id
107678         , p_amb_context_code        => l_amb_context_code
107679         , p_entity_code             => 'TRANSACTIONS'
107680         , p_event_class_code        => 'RETIREMENTS'
107681         , p_side                    => 'NA'
107682         );
107683 
107684   END IF;
107685 
107686    --
107687    --
107688    END IF;
107689 
107690        --
107691        -- Update the line information that should be overwritten
107692        --
107693        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
107694                                          p_header_num   => 1);
107695        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
107696 
107697        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
107698 
107699        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
107700           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
107701        END IF;
107702 
107703       --
107704       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
107705       --
107706       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
107707           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
107708       ELSE
107709           ---------------------------------------------------------------------------------------------------
107710           -- 4262811a Switch Sign
107711           ---------------------------------------------------------------------------------------------------
107712           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
107713           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
107714                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
107715           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
107716                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
107717           -- 5132302
107718           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
107719                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
107720 
107721       END IF;
107722 
107723       -- 4955764
107724       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
107725       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
107726 
107727 
107728       XLA_AE_LINES_PKG.ValidateCurrentLine;
107729       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
107730 
107731       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
107732                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
107733                ,p_balance_type_code => l_balance_type_code);
107734 
107735    END IF;
107736 
107737    -----------------------------------------------------------------------------------------
107738    -- 4262811 Multiperiod Accounting
107739    -----------------------------------------------------------------------------------------
107740      -- No MPA option is assigned.
107741 
107742 
107743 END IF;
107744 END IF;
107745 --
107746 
107747 --
107748 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
107749    trace
107750       (p_msg      => 'END of AcctLineType_304'
107751       ,p_level    => C_LEVEL_PROCEDURE
107752       ,p_module   => l_log_module);
107753 END IF;
107754 --
107755 EXCEPTION
107756   WHEN xla_exceptions_pkg.application_exception THEN
107757       RAISE;
107758   WHEN OTHERS THEN
107759        xla_exceptions_pkg.raise_message
107760            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_304');
107761 END AcctLineType_304;
107762 --
107763 
107764 ---------------------------------------
107765 --
107766 -- PRIVATE FUNCTION
107767 --         AcctLineType_305
107768 --
107769 ---------------------------------------
107770 PROCEDURE AcctLineType_305 (
107771   p_application_id        IN NUMBER
107772  ,p_event_id              IN NUMBER
107773  ,p_calculate_acctd_flag  IN VARCHAR2
107774  ,p_calculate_g_l_flag    IN VARCHAR2
107775  ,p_actual_flag           IN OUT VARCHAR2
107776  ,p_balance_type_code     OUT VARCHAR2
107777  ,p_gain_or_loss_ref      OUT VARCHAR2
107778  
107779 --Period Close Date
107780  , p_source_1            IN DATE
107781 --Generated Code Combination Identifier
107782  , p_source_3            IN NUMBER
107783 --Expense Account Code Combination Identifier
107784  , p_source_29            IN NUMBER
107785 --Adjustment Type
107786  , p_source_35            IN VARCHAR2
107787 --Transaction Header Identifier
107788  , p_source_36            IN NUMBER
107789 --Adjustment Line Identifier
107790  , p_source_37            IN NUMBER
107791 --Distribution Type Code
107792  , p_source_38            IN VARCHAR2
107793 --Entered Amount
107794  , p_source_39            IN NUMBER
107795 --Currency Code
107799 
107796  , p_source_40            IN VARCHAR2
107797 )
107798 IS
107800 l_component_type              VARCHAR2(80);
107801 l_component_code              VARCHAR2(30);
107802 l_component_type_code         VARCHAR2(1);
107803 l_component_appl_id           INTEGER;
107804 l_amb_context_code            VARCHAR2(30);
107805 l_entity_code                 VARCHAR2(30);
107806 l_event_class_code            VARCHAR2(30);
107807 l_ae_header_id                NUMBER;
107808 l_event_type_code             VARCHAR2(30);
107809 l_line_definition_code        VARCHAR2(30);
107810 l_line_definition_owner_code  VARCHAR2(1);
107811 --
107812 -- adr variables
107813 l_segment                     VARCHAR2(30);
107814 l_ccid                        NUMBER;
107815 l_adr_transaction_coa_id      NUMBER;
107816 l_adr_accounting_coa_id       NUMBER;
107817 l_adr_flexfield_segment_code  VARCHAR2(30);
107818 l_adr_flex_value_set_id       NUMBER;
107819 l_adr_value_type_code         VARCHAR2(30);
107820 l_adr_value_combination_id    NUMBER;
107821 l_adr_value_segment_code      VARCHAR2(30);
107822 
107823 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
107824 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
107825 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
107826 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
107827 
107828 -- 4262811 Variables ------------------------------------------------------------------------------------------
107829 l_entered_amt_idx             NUMBER;
107830 l_accted_amt_idx              NUMBER;
107831 l_acc_rev_flag                VARCHAR2(1);
107832 l_accrual_line_num            NUMBER;
107833 l_tmp_amt                     NUMBER;
107834 l_acc_rev_natural_side_code   VARCHAR2(1);
107835 
107836 l_num_entries                 NUMBER;
107837 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
107838 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
107839 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
107840 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
107841 l_recog_line_1                NUMBER;
107842 l_recog_line_2                NUMBER;
107843 
107844 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
107845 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
107846 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
107847 
107848 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
107849 
107850 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
107851 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
107852 
107853 ---------------------------------------------------------------------------------------------------------------
107854 
107855 
107856 --
107857 -- bulk performance
107858 --
107859 l_balance_type_code           VARCHAR2(1);
107860 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
107861 l_log_module                  VARCHAR2(240);
107862 
107863 --
107864 -- Upgrade strategy
107865 --
107866 l_actual_upg_option           VARCHAR2(1);
107867 l_enc_upg_option           VARCHAR2(1);
107868 
107869 --
107870 BEGIN
107871 --
107872 IF g_log_enabled THEN
107873       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_305';
107874 END IF;
107875 --
107876 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
107877 
107878       trace
107879          (p_msg      => 'BEGIN of AcctLineType_305'
107880          ,p_level    => C_LEVEL_PROCEDURE
107881          ,p_module   => l_log_module);
107882 
107883 END IF;
107884 --
107885 l_component_type             := 'AMB_JLT';
107886 l_component_code             := 'FA_RETIREMENT_EXP_BAL';
107887 l_component_type_code        := 'S';
107888 l_component_appl_id          :=  140;
107889 l_amb_context_code           := 'DEFAULT';
107890 l_entity_code                := 'TRANSACTIONS';
107891 l_event_class_code           := 'RETIREMENTS';
107892 l_event_type_code            := 'REINSTATEMENTS';
107893 l_line_definition_owner_code := 'S';
107894 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
107895 --
107896 l_balance_type_code          := 'A';
107897 l_segment                     := NULL;
107898 l_ccid                        := NULL;
107899 l_adr_transaction_coa_id      := NULL;
107900 l_adr_accounting_coa_id       := NULL;
107901 l_adr_flexfield_segment_code  := NULL;
107902 l_adr_flex_value_set_id       := NULL;
107903 l_adr_value_type_code         := NULL;
107904 l_adr_value_combination_id    := NULL;
107905 l_adr_value_segment_code      := NULL;
107906 
107907 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
107908 l_bflow_class_code           := '';    -- 4219869 Business Flow
107909 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
107910 l_budgetary_control_flag     := 'N';
107911 
107912 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
107913 l_bflow_applied_to_amt       := NULL; -- 5132302
107914 l_entered_amt_idx            := NULL;          -- 4262811
107915 l_accted_amt_idx             := NULL;          -- 4262811
107916 l_acc_rev_flag               := NULL;          -- 4262811
107917 l_accrual_line_num           := NULL;          -- 4262811
107918 l_tmp_amt                    := NULL;          -- 4262811
107919 --
107920  
107921 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
107922     l_balance_type_code <> 'B' THEN
107923 IF NVL(p_source_35,'
107924 ') =  'BONUS EXPENSE'
107925  THEN 
107926 
107927    --
107928    XLA_AE_LINES_PKG.SetNewLine;
107929 
107930    p_balance_type_code          := l_balance_type_code;
107931    -- set the flag so later we will know whether the gain loss line needs to be created
107932    
107936 
107933    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
107934      p_actual_flag :='A';
107935    END IF;
107937    --
107938    -- bulk performance
107939    --
107940    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
107941                                       p_header_num   => 0); -- 4262811
107942    --
107943    -- set accounting line options
107944    --
107945    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
107946            p_natural_side_code          => 'D'
107947          , p_gain_or_loss_flag          => 'N'
107948          , p_gl_transfer_mode_code      => 'S'
107949          , p_acct_entry_type_code       => 'A'
107950          , p_switch_side_flag           => 'Y'
107951          , p_merge_duplicate_code       => 'N'
107952          );
107953    --
107954    l_acc_rev_natural_side_code := 'C';  -- 4262811
107955    -- 
107956    --
107957    -- set accounting line type info
107958    --
107959    xla_ae_lines_pkg.SetAcctLineType
107960       (p_component_type             => l_component_type
107961       ,p_event_type_code            => l_event_type_code
107962       ,p_line_definition_owner_code => l_line_definition_owner_code
107963       ,p_line_definition_code       => l_line_definition_code
107964       ,p_accounting_line_code       => l_component_code
107965       ,p_accounting_line_type_code  => l_component_type_code
107966       ,p_accounting_line_appl_id    => l_component_appl_id
107967       ,p_amb_context_code           => l_amb_context_code
107968       ,p_entity_code                => l_entity_code
107969       ,p_event_class_code           => l_event_class_code);
107970    --
107971    -- set accounting class
107972    --
107973    xla_ae_lines_pkg.SetAcctClass(
107974            p_accounting_class_code  => 'EXPENSE'
107975          , p_ae_header_id           => l_ae_header_id
107976          );
107977 
107978    --
107979    -- set rounding class
107980    --
107981    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
107982                       'EXPENSE';
107983 
107984    --
107985    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
107986    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
107987    --
107988    -- bulk performance
107989    --
107990    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
107991 
107992    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
107993       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
107994 
107995    -- 4955764
107996    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
107997       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
107998 
107999    -- 4458381 Public Sector Enh
108000    
108001    --
108002    -- set accounting attributes for the line type
108003    --
108004    l_entered_amt_idx := 4;
108005    l_accted_amt_idx  := 6;
108006    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
108007    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
108008    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
108009    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
108010    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
108011    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
108012    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
108013    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
108014    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
108015    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
108016    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
108017    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
108018    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
108019 
108020    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
108021    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
108022 
108023    ---------------------------------------------------------------------------------------------------------------
108024    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
108025    ---------------------------------------------------------------------------------------------------------------
108026    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
108027 
108028    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
108029    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
108030 
108031    IF xla_accounting_cache_pkg.GetValueChar
108032          (p_source_code         => 'LEDGER_CATEGORY_CODE'
108033          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
108034    AND l_bflow_method_code = 'PRIOR_ENTRY'
108035 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
108036    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
108037          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
108038        )
108039    THEN
108040          xla_ae_lines_pkg.BflowUpgEntry
108041            (p_business_method_code    => l_bflow_method_code
108042            ,p_business_class_code     => l_bflow_class_code
108043            ,p_balance_type            => l_balance_type_code);
108044    ELSE
108045       NULL;
108046 -- No business flow processing for business flow method of NONE.
108047    END IF;
108048 
108049    --
108050    -- call analytical criteria
108051    --
108052    
108053    --
108054    -- call description
108055    --
108056    
108057 xla_ae_lines_pkg.SetLineDescription(
108058    p_ae_header_id => l_ae_header_id
108062 , p_source_1 => p_source_1
108059   ,p_description  => Description_79 (
108060      p_application_id         => p_application_id
108061    , p_ae_header_id           => l_ae_header_id 
108063    )
108064 );
108065 
108066 
108067    --
108068    -- call ADRs
108069    -- Bug 4922099
108070    --
108071    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
108072         (NVL(l_actual_upg_option, 'N') = 'O') OR
108073         (NVL(l_enc_upg_option, 'N') = 'O')
108074       )
108075    THEN
108076    NULL;
108077    --
108078    --
108079    
108080   l_ccid := AcctDerRule_175(
108081            p_application_id           => p_application_id
108082          , p_ae_header_id             => l_ae_header_id 
108083 , p_source_3 => p_source_3
108084 , p_source_29 => p_source_29
108085          , x_transaction_coa_id       => l_adr_transaction_coa_id
108086          , x_accounting_coa_id        => l_adr_accounting_coa_id
108087          , x_value_type_code          => l_adr_value_type_code
108088          , p_side                     => 'NA'
108089    );
108090 
108091    xla_ae_lines_pkg.set_ccid(
108092     p_code_combination_id          => l_ccid
108093   , p_value_type_code              => l_adr_value_type_code
108094   , p_transaction_coa_id           => l_adr_transaction_coa_id
108095   , p_accounting_coa_id            => l_adr_accounting_coa_id
108096   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
108097   , p_adr_type_code                => 'S'
108098   , p_component_type               => l_component_type
108099   , p_component_code               => l_component_code
108100   , p_component_type_code          => l_component_type_code
108101   , p_component_appl_id            => l_component_appl_id
108102   , p_amb_context_code             => l_amb_context_code
108103   , p_side                         => 'NA'
108104   );
108105 
108106 
108107    --
108108    --
108109    END IF;
108110    --
108111    -- Bug 4922099
108112    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
108113           (NVL(l_enc_upg_option, 'N') = 'O')
108114         ) AND
108115         (l_bflow_method_code = 'PRIOR_ENTRY')
108116       )
108117    THEN
108118       IF
108119       --
108120       1 = 2
108121       --
108122       THEN
108123       xla_accounting_err_pkg.build_message
108124                                     (p_appli_s_name            => 'XLA'
108125                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
108126                                     ,p_token_1                 => 'LINE_NUMBER'
108127                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
108128                                     ,p_token_2                 => 'LINE_TYPE_NAME'
108129                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
108130                                                                              l_component_type
108131                                                                             ,l_component_code
108132                                                                             ,l_component_type_code
108133                                                                             ,l_component_appl_id
108134                                                                             ,l_amb_context_code
108135                                                                             ,l_entity_code
108136                                                                             ,l_event_class_code
108137                                                                            )
108138                                     ,p_token_3                 => 'OWNER'
108139                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
108140                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
108141                                                                           ,p_lookup_code    => l_component_type_code
108142                                                                          )
108143                                     ,p_token_4                 => 'PRODUCT_NAME'
108144                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
108145                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
108146                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
108147                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
108148                                     ,p_ae_header_id            =>  NULL
108149                                        );
108150 
108151         IF (C_LEVEL_ERROR>= g_log_level) THEN
108152                  trace
108153                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
108154                       ,p_level    => C_LEVEL_ERROR
108155                       ,p_module   => l_log_module);
108156         END IF;
108157       END IF;
108158    END IF;
108159    --
108160    --
108161    ------------------------------------------------------------------------------------------------
108162    -- 4219869 Business Flow
108163    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
108164    -- Prior Entry.  Currently, the following code is always generated.
108165    ------------------------------------------------------------------------------------------------
108166    XLA_AE_LINES_PKG.ValidateCurrentLine;
108167 
108168    ------------------------------------------------------------------------------------
108169    -- 4219869 Business Flow
108170    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
108171    ------------------------------------------------------------------------------------
108172    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
108173 
108177    ----------------------------------------------------------------------------------
108174    ----------------------------------------------------------------------------------
108175    -- 4219869 Business Flow
108176    -- Update journal entry status -- Need to generate this within IF <condition>
108178    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
108179          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
108180          ,p_balance_type_code => l_balance_type_code
108181          );
108182 
108183    -------------------------------------------------------------------------------------------
108184    -- 4262811 - Generate the Accrual Reversal lines
108185    -------------------------------------------------------------------------------------------
108186    BEGIN
108187       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
108188                               (g_array_event(p_event_id).array_value_num('header_index'));
108189       IF l_acc_rev_flag IS NULL THEN
108190          l_acc_rev_flag := 'N';
108191       END IF;
108192    EXCEPTION
108193       WHEN OTHERS THEN
108194          l_acc_rev_flag := 'N';
108195    END;
108196    --
108197    IF (l_acc_rev_flag = 'Y') THEN
108198 
108199        -- 4645092  ------------------------------------------------------------------------------
108200        -- To allow MPA report to determine if it should generate report process
108201        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
108202        ------------------------------------------------------------------------------------------
108203 
108204        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
108205        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
108206    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
108207    -- call ADRs
108208    -- Bug 4922099
108209    --
108210    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
108211         (NVL(l_actual_upg_option, 'N') = 'O') OR
108212         (NVL(l_enc_upg_option, 'N') = 'O')
108213       )
108214    THEN
108215    NULL;
108216    --
108217    --
108218    
108219   l_ccid := AcctDerRule_175(
108220            p_application_id           => p_application_id
108221          , p_ae_header_id             => l_ae_header_id 
108222 , p_source_3 => p_source_3
108223 , p_source_29 => p_source_29
108224          , x_transaction_coa_id       => l_adr_transaction_coa_id
108225          , x_accounting_coa_id        => l_adr_accounting_coa_id
108226          , x_value_type_code          => l_adr_value_type_code
108227          , p_side                     => 'NA'
108228    );
108229 
108230    xla_ae_lines_pkg.set_ccid(
108231     p_code_combination_id          => l_ccid
108232   , p_value_type_code              => l_adr_value_type_code
108233   , p_transaction_coa_id           => l_adr_transaction_coa_id
108234   , p_accounting_coa_id            => l_adr_accounting_coa_id
108235   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
108236   , p_adr_type_code                => 'S'
108237   , p_component_type               => l_component_type
108238   , p_component_code               => l_component_code
108239   , p_component_type_code          => l_component_type_code
108240   , p_component_appl_id            => l_component_appl_id
108241   , p_amb_context_code             => l_amb_context_code
108242   , p_side                         => 'NA'
108243   );
108244 
108245 
108246    --
108247    --
108248    END IF;
108249 
108250        --
108251        -- Update the line information that should be overwritten
108252        --
108253        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
108254                                          p_header_num   => 1);
108255        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
108256 
108257        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
108258 
108259        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
108260           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
108261        END IF;
108262 
108263       --
108264       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
108265       --
108266       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
108267           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
108268       ELSE
108269           ---------------------------------------------------------------------------------------------------
108270           -- 4262811a Switch Sign
108271           ---------------------------------------------------------------------------------------------------
108272           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
108273           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
108274                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
108275           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
108276                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
108277           -- 5132302
108278           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
108279                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
108280 
108281       END IF;
108282 
108283       -- 4955764
108284       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
108285       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
108286 
108287 
108288       XLA_AE_LINES_PKG.ValidateCurrentLine;
108289       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
108290 
108294 
108291       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
108292                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
108293                ,p_balance_type_code => l_balance_type_code);
108295    END IF;
108296 
108297    -----------------------------------------------------------------------------------------
108298    -- 4262811 Multiperiod Accounting
108299    -----------------------------------------------------------------------------------------
108300      -- No MPA option is assigned.
108301 
108302 
108303 END IF;
108304 END IF;
108305 --
108306 
108307 --
108308 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
108309    trace
108310       (p_msg      => 'END of AcctLineType_305'
108311       ,p_level    => C_LEVEL_PROCEDURE
108312       ,p_module   => l_log_module);
108313 END IF;
108314 --
108315 EXCEPTION
108316   WHEN xla_exceptions_pkg.application_exception THEN
108317       RAISE;
108318   WHEN OTHERS THEN
108319        xla_exceptions_pkg.raise_message
108320            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_305');
108321 END AcctLineType_305;
108322 --
108323 
108324 ---------------------------------------
108325 --
108326 -- PRIVATE FUNCTION
108327 --         AcctLineType_306
108328 --
108329 ---------------------------------------
108330 PROCEDURE AcctLineType_306 (
108331   p_application_id        IN NUMBER
108332  ,p_event_id              IN NUMBER
108333  ,p_calculate_acctd_flag  IN VARCHAR2
108334  ,p_calculate_g_l_flag    IN VARCHAR2
108335  ,p_actual_flag           IN OUT VARCHAR2
108336  ,p_balance_type_code     OUT VARCHAR2
108337  ,p_gain_or_loss_ref      OUT VARCHAR2
108338  
108339 --Period Close Date
108340  , p_source_1            IN DATE
108341 --Generated Code Combination Identifier
108342  , p_source_3            IN NUMBER
108343 --Depreciation Reserve Account
108344  , p_source_10            IN VARCHAR2
108345 --Generated Offset Code Combination Identifier
108346  , p_source_17            IN NUMBER
108347 --Expense Account Code Combination Identifier
108348  , p_source_29            IN NUMBER
108349 --Default Code Combination Identifier
108350  , p_source_30            IN NUMBER
108351 --Adjustment Type
108352  , p_source_35            IN VARCHAR2
108353 --Transaction Header Identifier
108354  , p_source_36            IN NUMBER
108355 --Adjustment Line Identifier
108356  , p_source_37            IN NUMBER
108357 --Distribution Type Code
108358  , p_source_38            IN VARCHAR2
108359 --Entered Amount
108360  , p_source_39            IN NUMBER
108361 --Currency Code
108362  , p_source_40            IN VARCHAR2
108363 )
108364 IS
108365 
108366 l_component_type              VARCHAR2(80);
108367 l_component_code              VARCHAR2(30);
108368 l_component_type_code         VARCHAR2(1);
108369 l_component_appl_id           INTEGER;
108370 l_amb_context_code            VARCHAR2(30);
108371 l_entity_code                 VARCHAR2(30);
108372 l_event_class_code            VARCHAR2(30);
108373 l_ae_header_id                NUMBER;
108374 l_event_type_code             VARCHAR2(30);
108375 l_line_definition_code        VARCHAR2(30);
108376 l_line_definition_owner_code  VARCHAR2(1);
108377 --
108378 -- adr variables
108379 l_segment                     VARCHAR2(30);
108380 l_ccid                        NUMBER;
108381 l_adr_transaction_coa_id      NUMBER;
108382 l_adr_accounting_coa_id       NUMBER;
108383 l_adr_flexfield_segment_code  VARCHAR2(30);
108384 l_adr_flex_value_set_id       NUMBER;
108385 l_adr_value_type_code         VARCHAR2(30);
108386 l_adr_value_combination_id    NUMBER;
108387 l_adr_value_segment_code      VARCHAR2(30);
108388 
108389 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
108390 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
108391 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
108392 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
108393 
108394 -- 4262811 Variables ------------------------------------------------------------------------------------------
108395 l_entered_amt_idx             NUMBER;
108396 l_accted_amt_idx              NUMBER;
108397 l_acc_rev_flag                VARCHAR2(1);
108398 l_accrual_line_num            NUMBER;
108399 l_tmp_amt                     NUMBER;
108400 l_acc_rev_natural_side_code   VARCHAR2(1);
108401 
108402 l_num_entries                 NUMBER;
108403 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
108404 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
108405 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
108406 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
108407 l_recog_line_1                NUMBER;
108408 l_recog_line_2                NUMBER;
108409 
108410 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
108411 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
108412 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
108413 
108414 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
108415 
108416 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
108417 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
108418 
108419 ---------------------------------------------------------------------------------------------------------------
108420 
108421 
108422 --
108423 -- bulk performance
108424 --
108425 l_balance_type_code           VARCHAR2(1);
108426 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
108427 l_log_module                  VARCHAR2(240);
108428 
108429 --
108430 -- Upgrade strategy
108431 --
108432 l_actual_upg_option           VARCHAR2(1);
108433 l_enc_upg_option           VARCHAR2(1);
108434 
108438 IF g_log_enabled THEN
108435 --
108436 BEGIN
108437 --
108439       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_306';
108440 END IF;
108441 --
108442 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
108443 
108444       trace
108445          (p_msg      => 'BEGIN of AcctLineType_306'
108446          ,p_level    => C_LEVEL_PROCEDURE
108447          ,p_module   => l_log_module);
108448 
108449 END IF;
108450 --
108451 l_component_type             := 'AMB_JLT';
108452 l_component_code             := 'FA_RETIREMENT_RESERVE';
108453 l_component_type_code        := 'S';
108454 l_component_appl_id          :=  140;
108455 l_amb_context_code           := 'DEFAULT';
108456 l_entity_code                := 'TRANSACTIONS';
108457 l_event_class_code           := 'RETIREMENTS';
108458 l_event_type_code            := 'RETIREMENTS';
108459 l_line_definition_owner_code := 'S';
108460 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
108461 --
108462 l_balance_type_code          := 'A';
108463 l_segment                     := NULL;
108464 l_ccid                        := NULL;
108465 l_adr_transaction_coa_id      := NULL;
108466 l_adr_accounting_coa_id       := NULL;
108467 l_adr_flexfield_segment_code  := NULL;
108468 l_adr_flex_value_set_id       := NULL;
108469 l_adr_value_type_code         := NULL;
108470 l_adr_value_combination_id    := NULL;
108471 l_adr_value_segment_code      := NULL;
108472 
108473 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
108474 l_bflow_class_code           := '';    -- 4219869 Business Flow
108475 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
108476 l_budgetary_control_flag     := 'N';
108477 
108478 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
108479 l_bflow_applied_to_amt       := NULL; -- 5132302
108480 l_entered_amt_idx            := NULL;          -- 4262811
108481 l_accted_amt_idx             := NULL;          -- 4262811
108482 l_acc_rev_flag               := NULL;          -- 4262811
108483 l_accrual_line_num           := NULL;          -- 4262811
108484 l_tmp_amt                    := NULL;          -- 4262811
108485 --
108486  
108487 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
108488     l_balance_type_code <> 'B' THEN
108489 IF NVL(p_source_35,'
108490 ') =  'RESERVE'
108491  THEN 
108492 
108493    --
108494    XLA_AE_LINES_PKG.SetNewLine;
108495 
108496    p_balance_type_code          := l_balance_type_code;
108497    -- set the flag so later we will know whether the gain loss line needs to be created
108498    
108499    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
108500      p_actual_flag :='A';
108501    END IF;
108502 
108503    --
108504    -- bulk performance
108505    --
108506    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
108507                                       p_header_num   => 0); -- 4262811
108508    --
108509    -- set accounting line options
108510    --
108511    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
108512            p_natural_side_code          => 'D'
108513          , p_gain_or_loss_flag          => 'N'
108514          , p_gl_transfer_mode_code      => 'S'
108515          , p_acct_entry_type_code       => 'A'
108516          , p_switch_side_flag           => 'Y'
108517          , p_merge_duplicate_code       => 'N'
108518          );
108519    --
108520    l_acc_rev_natural_side_code := 'C';  -- 4262811
108521    -- 
108522    --
108523    -- set accounting line type info
108524    --
108525    xla_ae_lines_pkg.SetAcctLineType
108526       (p_component_type             => l_component_type
108527       ,p_event_type_code            => l_event_type_code
108528       ,p_line_definition_owner_code => l_line_definition_owner_code
108529       ,p_line_definition_code       => l_line_definition_code
108530       ,p_accounting_line_code       => l_component_code
108531       ,p_accounting_line_type_code  => l_component_type_code
108532       ,p_accounting_line_appl_id    => l_component_appl_id
108533       ,p_amb_context_code           => l_amb_context_code
108534       ,p_entity_code                => l_entity_code
108535       ,p_event_class_code           => l_event_class_code);
108536    --
108537    -- set accounting class
108538    --
108539    xla_ae_lines_pkg.SetAcctClass(
108540            p_accounting_class_code  => 'ASSET'
108541          , p_ae_header_id           => l_ae_header_id
108542          );
108543 
108544    --
108545    -- set rounding class
108546    --
108547    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
108548                       'ASSET';
108549 
108550    --
108551    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
108552    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
108553    --
108554    -- bulk performance
108555    --
108556    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
108557 
108558    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
108559       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
108560 
108561    -- 4955764
108562    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
108563       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
108564 
108565    -- 4458381 Public Sector Enh
108566    
108567    --
108568    -- set accounting attributes for the line type
108569    --
108570    l_entered_amt_idx := 4;
108571    l_accted_amt_idx  := 6;
108572    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
108573    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
108574    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
108578    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
108575    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
108576    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
108577    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
108579    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
108580    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
108581    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
108582    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
108583    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
108584    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
108585 
108586    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
108587    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
108588 
108589    ---------------------------------------------------------------------------------------------------------------
108590    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
108591    ---------------------------------------------------------------------------------------------------------------
108592    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
108593 
108594    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
108595    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
108596 
108597    IF xla_accounting_cache_pkg.GetValueChar
108598          (p_source_code         => 'LEDGER_CATEGORY_CODE'
108599          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
108600    AND l_bflow_method_code = 'PRIOR_ENTRY'
108601 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
108602    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
108603          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
108604        )
108605    THEN
108606          xla_ae_lines_pkg.BflowUpgEntry
108607            (p_business_method_code    => l_bflow_method_code
108608            ,p_business_class_code     => l_bflow_class_code
108609            ,p_balance_type            => l_balance_type_code);
108610    ELSE
108611       NULL;
108612 -- No business flow processing for business flow method of NONE.
108613    END IF;
108614 
108615    --
108616    -- call analytical criteria
108617    --
108618    
108619    --
108620    -- call description
108621    --
108622    
108623 xla_ae_lines_pkg.SetLineDescription(
108624    p_ae_header_id => l_ae_header_id
108625   ,p_description  => Description_82 (
108626      p_application_id         => p_application_id
108627    , p_ae_header_id           => l_ae_header_id 
108628 , p_source_1 => p_source_1
108629    )
108630 );
108631 
108632 
108633    --
108634    -- call ADRs
108635    -- Bug 4922099
108636    --
108637    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
108638         (NVL(l_actual_upg_option, 'N') = 'O') OR
108639         (NVL(l_enc_upg_option, 'N') = 'O')
108640       )
108641    THEN
108642    NULL;
108643    --
108644    --
108645    
108646   l_ccid := AcctDerRule_174(
108647            p_application_id           => p_application_id
108648          , p_ae_header_id             => l_ae_header_id 
108649 , p_source_3 => p_source_3
108650 , p_source_17 => p_source_17
108651 , p_source_30 => p_source_30
108652          , x_transaction_coa_id       => l_adr_transaction_coa_id
108653          , x_accounting_coa_id        => l_adr_accounting_coa_id
108654          , x_value_type_code          => l_adr_value_type_code
108655          , p_side                     => 'NA'
108656    );
108657 
108658    xla_ae_lines_pkg.set_ccid(
108659     p_code_combination_id          => l_ccid
108660   , p_value_type_code              => l_adr_value_type_code
108661   , p_transaction_coa_id           => l_adr_transaction_coa_id
108662   , p_accounting_coa_id            => l_adr_accounting_coa_id
108663   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
108664   , p_adr_type_code                => 'S'
108665   , p_component_type               => l_component_type
108666   , p_component_code               => l_component_code
108667   , p_component_type_code          => l_component_type_code
108668   , p_component_appl_id            => l_component_appl_id
108669   , p_amb_context_code             => l_amb_context_code
108670   , p_side                         => 'NA'
108671   );
108672 
108673 
108674    l_segment := AcctDerRule_149(
108675            p_application_id           => p_application_id
108676          , p_ae_header_id             => l_ae_header_id 
108677 , p_source_3 => p_source_3
108678 , p_source_10 => p_source_10
108679          , x_transaction_coa_id       => l_adr_transaction_coa_id
108680          , x_accounting_coa_id        => l_adr_accounting_coa_id
108681          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
108682          , x_flex_value_set_id        => l_adr_flex_value_set_id
108683          , x_value_type_code          => l_adr_value_type_code
108684          , x_value_combination_id     => l_adr_value_combination_id
108685          , x_value_segment_code       => l_adr_value_segment_code
108686          , p_side                     => 'NA'
108687          , p_override_seg_flag        => 'Y'
108688    );
108689 
108690    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
108691 
108692       xla_ae_lines_pkg.set_segment(
108693           p_to_segment_code         => 'GL_ACCOUNT'
108694         , p_segment_value           => l_segment
108695         , p_from_segment_code       => l_adr_value_segment_code
108696         , p_from_combination_id     => l_adr_value_combination_id
108697         , p_value_type_code         => l_adr_value_type_code
108698         , p_transaction_coa_id      => l_adr_transaction_coa_id
108699         , p_accounting_coa_id       => l_adr_accounting_coa_id
108703         , p_adr_type_code           => 'S'
108700         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
108701         , p_flex_value_set_id       => l_adr_flex_value_set_id
108702         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
108704         , p_component_type          => l_component_type
108705         , p_component_code          => l_component_code
108706         , p_component_type_code     => l_component_type_code
108707         , p_component_appl_id       => l_component_appl_id
108708         , p_amb_context_code        => l_amb_context_code
108709         , p_entity_code             => 'TRANSACTIONS'
108710         , p_event_class_code        => 'RETIREMENTS'
108711         , p_side                    => 'NA'
108712         );
108713 
108714   END IF;
108715 
108716    l_segment := AcctDerRule_168(
108717            p_application_id           => p_application_id
108718          , p_ae_header_id             => l_ae_header_id 
108719 , p_source_3 => p_source_3
108720 , p_source_29 => p_source_29
108721          , x_transaction_coa_id       => l_adr_transaction_coa_id
108722          , x_accounting_coa_id        => l_adr_accounting_coa_id
108723          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
108724          , x_flex_value_set_id        => l_adr_flex_value_set_id
108725          , x_value_type_code          => l_adr_value_type_code
108726          , x_value_combination_id     => l_adr_value_combination_id
108727          , x_value_segment_code       => l_adr_value_segment_code
108728          , p_side                     => 'NA'
108729          , p_override_seg_flag        => 'Y'
108730    );
108731 
108732    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
108733 
108734       xla_ae_lines_pkg.set_segment(
108735           p_to_segment_code         => 'GL_BALANCING'
108736         , p_segment_value           => l_segment
108737         , p_from_segment_code       => l_adr_value_segment_code
108738         , p_from_combination_id     => l_adr_value_combination_id
108739         , p_value_type_code         => l_adr_value_type_code
108740         , p_transaction_coa_id      => l_adr_transaction_coa_id
108741         , p_accounting_coa_id       => l_adr_accounting_coa_id
108742         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
108743         , p_flex_value_set_id       => l_adr_flex_value_set_id
108744         , p_adr_code                => 'FA_EXPENSE_ACCT'
108745         , p_adr_type_code           => 'S'
108746         , p_component_type          => l_component_type
108747         , p_component_code          => l_component_code
108748         , p_component_type_code     => l_component_type_code
108749         , p_component_appl_id       => l_component_appl_id
108750         , p_amb_context_code        => l_amb_context_code
108751         , p_entity_code             => 'TRANSACTIONS'
108752         , p_event_class_code        => 'RETIREMENTS'
108753         , p_side                    => 'NA'
108754         );
108755 
108756   END IF;
108757 
108758    --
108759    --
108760    END IF;
108761    --
108762    -- Bug 4922099
108763    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
108764           (NVL(l_enc_upg_option, 'N') = 'O')
108765         ) AND
108766         (l_bflow_method_code = 'PRIOR_ENTRY')
108767       )
108768    THEN
108769       IF
108770       --
108771       1 = 2
108772       --
108773       THEN
108774       xla_accounting_err_pkg.build_message
108775                                     (p_appli_s_name            => 'XLA'
108776                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
108777                                     ,p_token_1                 => 'LINE_NUMBER'
108778                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
108779                                     ,p_token_2                 => 'LINE_TYPE_NAME'
108780                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
108781                                                                              l_component_type
108782                                                                             ,l_component_code
108783                                                                             ,l_component_type_code
108784                                                                             ,l_component_appl_id
108785                                                                             ,l_amb_context_code
108786                                                                             ,l_entity_code
108787                                                                             ,l_event_class_code
108788                                                                            )
108789                                     ,p_token_3                 => 'OWNER'
108790                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
108791                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
108792                                                                           ,p_lookup_code    => l_component_type_code
108793                                                                          )
108794                                     ,p_token_4                 => 'PRODUCT_NAME'
108795                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
108796                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
108797                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
108798                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
108799                                     ,p_ae_header_id            =>  NULL
108800                                        );
108801 
108802         IF (C_LEVEL_ERROR>= g_log_level) THEN
108803                  trace
108804                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
108808       END IF;
108805                       ,p_level    => C_LEVEL_ERROR
108806                       ,p_module   => l_log_module);
108807         END IF;
108809    END IF;
108810    --
108811    --
108812    ------------------------------------------------------------------------------------------------
108813    -- 4219869 Business Flow
108814    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
108815    -- Prior Entry.  Currently, the following code is always generated.
108816    ------------------------------------------------------------------------------------------------
108817    XLA_AE_LINES_PKG.ValidateCurrentLine;
108818 
108819    ------------------------------------------------------------------------------------
108820    -- 4219869 Business Flow
108821    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
108822    ------------------------------------------------------------------------------------
108823    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
108824 
108825    ----------------------------------------------------------------------------------
108826    -- 4219869 Business Flow
108827    -- Update journal entry status -- Need to generate this within IF <condition>
108828    ----------------------------------------------------------------------------------
108829    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
108830          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
108831          ,p_balance_type_code => l_balance_type_code
108832          );
108833 
108834    -------------------------------------------------------------------------------------------
108835    -- 4262811 - Generate the Accrual Reversal lines
108836    -------------------------------------------------------------------------------------------
108837    BEGIN
108838       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
108839                               (g_array_event(p_event_id).array_value_num('header_index'));
108840       IF l_acc_rev_flag IS NULL THEN
108841          l_acc_rev_flag := 'N';
108842       END IF;
108843    EXCEPTION
108844       WHEN OTHERS THEN
108845          l_acc_rev_flag := 'N';
108846    END;
108847    --
108848    IF (l_acc_rev_flag = 'Y') THEN
108849 
108850        -- 4645092  ------------------------------------------------------------------------------
108851        -- To allow MPA report to determine if it should generate report process
108852        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
108853        ------------------------------------------------------------------------------------------
108854 
108855        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
108856        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
108857    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
108858    -- call ADRs
108859    -- Bug 4922099
108860    --
108861    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
108862         (NVL(l_actual_upg_option, 'N') = 'O') OR
108863         (NVL(l_enc_upg_option, 'N') = 'O')
108864       )
108865    THEN
108866    NULL;
108867    --
108868    --
108869    
108870   l_ccid := AcctDerRule_174(
108871            p_application_id           => p_application_id
108872          , p_ae_header_id             => l_ae_header_id 
108873 , p_source_3 => p_source_3
108874 , p_source_17 => p_source_17
108875 , p_source_30 => p_source_30
108876          , x_transaction_coa_id       => l_adr_transaction_coa_id
108877          , x_accounting_coa_id        => l_adr_accounting_coa_id
108878          , x_value_type_code          => l_adr_value_type_code
108879          , p_side                     => 'NA'
108880    );
108881 
108882    xla_ae_lines_pkg.set_ccid(
108883     p_code_combination_id          => l_ccid
108884   , p_value_type_code              => l_adr_value_type_code
108885   , p_transaction_coa_id           => l_adr_transaction_coa_id
108886   , p_accounting_coa_id            => l_adr_accounting_coa_id
108887   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
108888   , p_adr_type_code                => 'S'
108889   , p_component_type               => l_component_type
108890   , p_component_code               => l_component_code
108891   , p_component_type_code          => l_component_type_code
108892   , p_component_appl_id            => l_component_appl_id
108893   , p_amb_context_code             => l_amb_context_code
108894   , p_side                         => 'NA'
108895   );
108896 
108897 
108898    l_segment := AcctDerRule_149(
108899            p_application_id           => p_application_id
108900          , p_ae_header_id             => l_ae_header_id 
108901 , p_source_3 => p_source_3
108902 , p_source_10 => p_source_10
108903          , x_transaction_coa_id       => l_adr_transaction_coa_id
108904          , x_accounting_coa_id        => l_adr_accounting_coa_id
108905          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
108906          , x_flex_value_set_id        => l_adr_flex_value_set_id
108907          , x_value_type_code          => l_adr_value_type_code
108908          , x_value_combination_id     => l_adr_value_combination_id
108909          , x_value_segment_code       => l_adr_value_segment_code
108910          , p_side                     => 'NA'
108911          , p_override_seg_flag        => 'Y'
108912    );
108913 
108914    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
108915 
108916       xla_ae_lines_pkg.set_segment(
108917           p_to_segment_code         => 'GL_ACCOUNT'
108918         , p_segment_value           => l_segment
108919         , p_from_segment_code       => l_adr_value_segment_code
108920         , p_from_combination_id     => l_adr_value_combination_id
108921         , p_value_type_code         => l_adr_value_type_code
108922         , p_transaction_coa_id      => l_adr_transaction_coa_id
108923         , p_accounting_coa_id       => l_adr_accounting_coa_id
108924         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
108928         , p_component_type          => l_component_type
108925         , p_flex_value_set_id       => l_adr_flex_value_set_id
108926         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
108927         , p_adr_type_code           => 'S'
108929         , p_component_code          => l_component_code
108930         , p_component_type_code     => l_component_type_code
108931         , p_component_appl_id       => l_component_appl_id
108932         , p_amb_context_code        => l_amb_context_code
108933         , p_entity_code             => 'TRANSACTIONS'
108934         , p_event_class_code        => 'RETIREMENTS'
108935         , p_side                    => 'NA'
108936         );
108937 
108938   END IF;
108939 
108940    l_segment := AcctDerRule_168(
108941            p_application_id           => p_application_id
108942          , p_ae_header_id             => l_ae_header_id 
108943 , p_source_3 => p_source_3
108944 , p_source_29 => p_source_29
108945          , x_transaction_coa_id       => l_adr_transaction_coa_id
108946          , x_accounting_coa_id        => l_adr_accounting_coa_id
108947          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
108948          , x_flex_value_set_id        => l_adr_flex_value_set_id
108949          , x_value_type_code          => l_adr_value_type_code
108950          , x_value_combination_id     => l_adr_value_combination_id
108951          , x_value_segment_code       => l_adr_value_segment_code
108952          , p_side                     => 'NA'
108953          , p_override_seg_flag        => 'Y'
108954    );
108955 
108956    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
108957 
108958       xla_ae_lines_pkg.set_segment(
108959           p_to_segment_code         => 'GL_BALANCING'
108960         , p_segment_value           => l_segment
108961         , p_from_segment_code       => l_adr_value_segment_code
108962         , p_from_combination_id     => l_adr_value_combination_id
108963         , p_value_type_code         => l_adr_value_type_code
108964         , p_transaction_coa_id      => l_adr_transaction_coa_id
108965         , p_accounting_coa_id       => l_adr_accounting_coa_id
108966         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
108967         , p_flex_value_set_id       => l_adr_flex_value_set_id
108968         , p_adr_code                => 'FA_EXPENSE_ACCT'
108969         , p_adr_type_code           => 'S'
108970         , p_component_type          => l_component_type
108971         , p_component_code          => l_component_code
108972         , p_component_type_code     => l_component_type_code
108973         , p_component_appl_id       => l_component_appl_id
108974         , p_amb_context_code        => l_amb_context_code
108975         , p_entity_code             => 'TRANSACTIONS'
108976         , p_event_class_code        => 'RETIREMENTS'
108977         , p_side                    => 'NA'
108978         );
108979 
108980   END IF;
108981 
108982    --
108983    --
108984    END IF;
108985 
108986        --
108987        -- Update the line information that should be overwritten
108988        --
108989        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
108990                                          p_header_num   => 1);
108991        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
108992 
108993        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
108994 
108995        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
108996           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
108997        END IF;
108998 
108999       --
109000       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
109001       --
109002       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
109003           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
109004       ELSE
109008           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
109005           ---------------------------------------------------------------------------------------------------
109006           -- 4262811a Switch Sign
109007           ---------------------------------------------------------------------------------------------------
109009           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
109010                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
109011           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
109012                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
109013           -- 5132302
109014           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
109015                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
109016 
109017       END IF;
109018 
109019       -- 4955764
109020       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
109021       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
109022 
109023 
109024       XLA_AE_LINES_PKG.ValidateCurrentLine;
109025       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
109026 
109027       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
109028                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
109029                ,p_balance_type_code => l_balance_type_code);
109030 
109031    END IF;
109032 
109033    -----------------------------------------------------------------------------------------
109034    -- 4262811 Multiperiod Accounting
109035    -----------------------------------------------------------------------------------------
109036      -- No MPA option is assigned.
109037 
109038 
109039 END IF;
109040 END IF;
109041 --
109042 
109043 --
109044 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
109045    trace
109046       (p_msg      => 'END of AcctLineType_306'
109047       ,p_level    => C_LEVEL_PROCEDURE
109048       ,p_module   => l_log_module);
109049 END IF;
109050 --
109051 EXCEPTION
109052   WHEN xla_exceptions_pkg.application_exception THEN
109053       RAISE;
109054   WHEN OTHERS THEN
109055        xla_exceptions_pkg.raise_message
109056            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_306');
109057 END AcctLineType_306;
109058 --
109059 
109060 ---------------------------------------
109061 --
109062 -- PRIVATE FUNCTION
109063 --         AcctLineType_307
109064 --
109065 ---------------------------------------
109066 PROCEDURE AcctLineType_307 (
109067   p_application_id        IN NUMBER
109068  ,p_event_id              IN NUMBER
109069  ,p_calculate_acctd_flag  IN VARCHAR2
109070  ,p_calculate_g_l_flag    IN VARCHAR2
109071  ,p_actual_flag           IN OUT VARCHAR2
109072  ,p_balance_type_code     OUT VARCHAR2
109073  ,p_gain_or_loss_ref      OUT VARCHAR2
109074  
109075 --Period Close Date
109076  , p_source_1            IN DATE
109077 --Generated Code Combination Identifier
109078  , p_source_3            IN NUMBER
109079 --Depreciation Reserve Account
109080  , p_source_10            IN VARCHAR2
109081 --Generated Offset Code Combination Identifier
109082  , p_source_17            IN NUMBER
109083 --Expense Account Code Combination Identifier
109084  , p_source_29            IN NUMBER
109085 --Default Code Combination Identifier
109086  , p_source_30            IN NUMBER
109087 --Adjustment Type
109088  , p_source_35            IN VARCHAR2
109089 --Transaction Header Identifier
109090  , p_source_36            IN NUMBER
109091 --Adjustment Line Identifier
109092  , p_source_37            IN NUMBER
109093 --Distribution Type Code
109094  , p_source_38            IN VARCHAR2
109095 --Entered Amount
109096  , p_source_39            IN NUMBER
109097 --Currency Code
109098  , p_source_40            IN VARCHAR2
109099 )
109100 IS
109101 
109102 l_component_type              VARCHAR2(80);
109103 l_component_code              VARCHAR2(30);
109104 l_component_type_code         VARCHAR2(1);
109105 l_component_appl_id           INTEGER;
109106 l_amb_context_code            VARCHAR2(30);
109107 l_entity_code                 VARCHAR2(30);
109108 l_event_class_code            VARCHAR2(30);
109109 l_ae_header_id                NUMBER;
109110 l_event_type_code             VARCHAR2(30);
109111 l_line_definition_code        VARCHAR2(30);
109112 l_line_definition_owner_code  VARCHAR2(1);
109113 --
109114 -- adr variables
109115 l_segment                     VARCHAR2(30);
109116 l_ccid                        NUMBER;
109120 l_adr_flex_value_set_id       NUMBER;
109117 l_adr_transaction_coa_id      NUMBER;
109118 l_adr_accounting_coa_id       NUMBER;
109119 l_adr_flexfield_segment_code  VARCHAR2(30);
109121 l_adr_value_type_code         VARCHAR2(30);
109122 l_adr_value_combination_id    NUMBER;
109123 l_adr_value_segment_code      VARCHAR2(30);
109124 
109125 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
109126 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
109127 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
109128 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
109129 
109130 -- 4262811 Variables ------------------------------------------------------------------------------------------
109131 l_entered_amt_idx             NUMBER;
109132 l_accted_amt_idx              NUMBER;
109133 l_acc_rev_flag                VARCHAR2(1);
109134 l_accrual_line_num            NUMBER;
109135 l_tmp_amt                     NUMBER;
109136 l_acc_rev_natural_side_code   VARCHAR2(1);
109137 
109138 l_num_entries                 NUMBER;
109139 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
109140 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
109141 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
109142 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
109143 l_recog_line_1                NUMBER;
109144 l_recog_line_2                NUMBER;
109145 
109146 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
109147 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
109148 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
109149 
109150 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
109151 
109152 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
109153 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
109154 
109155 ---------------------------------------------------------------------------------------------------------------
109156 
109157 
109161 l_balance_type_code           VARCHAR2(1);
109158 --
109159 -- bulk performance
109160 --
109162 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
109163 l_log_module                  VARCHAR2(240);
109164 
109165 --
109166 -- Upgrade strategy
109167 --
109168 l_actual_upg_option           VARCHAR2(1);
109169 l_enc_upg_option           VARCHAR2(1);
109170 
109171 --
109172 BEGIN
109173 --
109174 IF g_log_enabled THEN
109175       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_307';
109176 END IF;
109177 --
109178 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
109179 
109180       trace
109181          (p_msg      => 'BEGIN of AcctLineType_307'
109182          ,p_level    => C_LEVEL_PROCEDURE
109183          ,p_module   => l_log_module);
109184 
109185 END IF;
109186 --
109187 l_component_type             := 'AMB_JLT';
109188 l_component_code             := 'FA_RETIREMENT_RESERVE';
109189 l_component_type_code        := 'S';
109190 l_component_appl_id          :=  140;
109191 l_amb_context_code           := 'DEFAULT';
109192 l_entity_code                := 'TRANSACTIONS';
109193 l_event_class_code           := 'RETIREMENTS';
109194 l_event_type_code            := 'REINSTATEMENTS';
109195 l_line_definition_owner_code := 'S';
109196 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
109197 --
109198 l_balance_type_code          := 'A';
109199 l_segment                     := NULL;
109200 l_ccid                        := NULL;
109201 l_adr_transaction_coa_id      := NULL;
109202 l_adr_accounting_coa_id       := NULL;
109203 l_adr_flexfield_segment_code  := NULL;
109204 l_adr_flex_value_set_id       := NULL;
109205 l_adr_value_type_code         := NULL;
109206 l_adr_value_combination_id    := NULL;
109207 l_adr_value_segment_code      := NULL;
109208 
109209 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
109210 l_bflow_class_code           := '';    -- 4219869 Business Flow
109211 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
109212 l_budgetary_control_flag     := 'N';
109213 
109214 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
109215 l_bflow_applied_to_amt       := NULL; -- 5132302
109216 l_entered_amt_idx            := NULL;          -- 4262811
109217 l_accted_amt_idx             := NULL;          -- 4262811
109218 l_acc_rev_flag               := NULL;          -- 4262811
109219 l_accrual_line_num           := NULL;          -- 4262811
109220 l_tmp_amt                    := NULL;          -- 4262811
109221 --
109222  
109223 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
109224     l_balance_type_code <> 'B' THEN
109225 IF NVL(p_source_35,'
109226 ') =  'RESERVE'
109227  THEN 
109228 
109229    --
109230    XLA_AE_LINES_PKG.SetNewLine;
109231 
109235    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
109232    p_balance_type_code          := l_balance_type_code;
109233    -- set the flag so later we will know whether the gain loss line needs to be created
109234    
109236      p_actual_flag :='A';
109237    END IF;
109238 
109239    --
109240    -- bulk performance
109241    --
109242    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
109243                                       p_header_num   => 0); -- 4262811
109244    --
109245    -- set accounting line options
109246    --
109247    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
109248            p_natural_side_code          => 'D'
109249          , p_gain_or_loss_flag          => 'N'
109250          , p_gl_transfer_mode_code      => 'S'
109251          , p_acct_entry_type_code       => 'A'
109252          , p_switch_side_flag           => 'Y'
109253          , p_merge_duplicate_code       => 'N'
109254          );
109255    --
109256    l_acc_rev_natural_side_code := 'C';  -- 4262811
109257    -- 
109258    --
109259    -- set accounting line type info
109260    --
109261    xla_ae_lines_pkg.SetAcctLineType
109262       (p_component_type             => l_component_type
109263       ,p_event_type_code            => l_event_type_code
109264       ,p_line_definition_owner_code => l_line_definition_owner_code
109265       ,p_line_definition_code       => l_line_definition_code
109266       ,p_accounting_line_code       => l_component_code
109267       ,p_accounting_line_type_code  => l_component_type_code
109268       ,p_accounting_line_appl_id    => l_component_appl_id
109269       ,p_amb_context_code           => l_amb_context_code
109270       ,p_entity_code                => l_entity_code
109271       ,p_event_class_code           => l_event_class_code);
109272    --
109273    -- set accounting class
109274    --
109275    xla_ae_lines_pkg.SetAcctClass(
109276            p_accounting_class_code  => 'ASSET'
109277          , p_ae_header_id           => l_ae_header_id
109278          );
109279 
109280    --
109281    -- set rounding class
109282    --
109283    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
109284                       'ASSET';
109285 
109286    --
109287    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
109288    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
109289    --
109290    -- bulk performance
109291    --
109292    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
109293 
109294    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
109295       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
109296 
109297    -- 4955764
109298    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
109299       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
109300 
109301    -- 4458381 Public Sector Enh
109302    
109303    --
109304    -- set accounting attributes for the line type
109305    --
109306    l_entered_amt_idx := 4;
109307    l_accted_amt_idx  := 6;
109308    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
109309    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
109310    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
109311    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
109312    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
109313    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
109314    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
109315    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
109316    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
109317    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
109318    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
109319    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
109323    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
109320    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
109321 
109322    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
109324 
109325    ---------------------------------------------------------------------------------------------------------------
109326    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
109327    ---------------------------------------------------------------------------------------------------------------
109328    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
109329 
109330    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
109331    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
109335          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
109332 
109333    IF xla_accounting_cache_pkg.GetValueChar
109334          (p_source_code         => 'LEDGER_CATEGORY_CODE'
109336    AND l_bflow_method_code = 'PRIOR_ENTRY'
109337 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
109338    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
109339          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
109340        )
109341    THEN
109342          xla_ae_lines_pkg.BflowUpgEntry
109343            (p_business_method_code    => l_bflow_method_code
109344            ,p_business_class_code     => l_bflow_class_code
109345            ,p_balance_type            => l_balance_type_code);
109346    ELSE
109347       NULL;
109348 -- No business flow processing for business flow method of NONE.
109349    END IF;
109350 
109351    --
109352    -- call analytical criteria
109353    --
109354    
109355    --
109356    -- call description
109357    --
109358    
109359 xla_ae_lines_pkg.SetLineDescription(
109360    p_ae_header_id => l_ae_header_id
109361   ,p_description  => Description_82 (
109362      p_application_id         => p_application_id
109363    , p_ae_header_id           => l_ae_header_id 
109364 , p_source_1 => p_source_1
109365    )
109366 );
109367 
109368 
109369    --
109370    -- call ADRs
109371    -- Bug 4922099
109372    --
109373    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
109374         (NVL(l_actual_upg_option, 'N') = 'O') OR
109375         (NVL(l_enc_upg_option, 'N') = 'O')
109376       )
109377    THEN
109378    NULL;
109379    --
109380    --
109381    
109382   l_ccid := AcctDerRule_174(
109383            p_application_id           => p_application_id
109384          , p_ae_header_id             => l_ae_header_id 
109385 , p_source_3 => p_source_3
109386 , p_source_17 => p_source_17
109387 , p_source_30 => p_source_30
109388          , x_transaction_coa_id       => l_adr_transaction_coa_id
109389          , x_accounting_coa_id        => l_adr_accounting_coa_id
109390          , x_value_type_code          => l_adr_value_type_code
109391          , p_side                     => 'NA'
109392    );
109393 
109394    xla_ae_lines_pkg.set_ccid(
109395     p_code_combination_id          => l_ccid
109396   , p_value_type_code              => l_adr_value_type_code
109397   , p_transaction_coa_id           => l_adr_transaction_coa_id
109398   , p_accounting_coa_id            => l_adr_accounting_coa_id
109399   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
109400   , p_adr_type_code                => 'S'
109401   , p_component_type               => l_component_type
109402   , p_component_code               => l_component_code
109403   , p_component_type_code          => l_component_type_code
109404   , p_component_appl_id            => l_component_appl_id
109405   , p_amb_context_code             => l_amb_context_code
109406   , p_side                         => 'NA'
109407   );
109408 
109409 
109410    l_segment := AcctDerRule_149(
109411            p_application_id           => p_application_id
109412          , p_ae_header_id             => l_ae_header_id 
109413 , p_source_3 => p_source_3
109414 , p_source_10 => p_source_10
109415          , x_transaction_coa_id       => l_adr_transaction_coa_id
109416          , x_accounting_coa_id        => l_adr_accounting_coa_id
109417          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
109418          , x_flex_value_set_id        => l_adr_flex_value_set_id
109419          , x_value_type_code          => l_adr_value_type_code
109420          , x_value_combination_id     => l_adr_value_combination_id
109421          , x_value_segment_code       => l_adr_value_segment_code
109422          , p_side                     => 'NA'
109423          , p_override_seg_flag        => 'Y'
109424    );
109425 
109426    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
109427 
109428       xla_ae_lines_pkg.set_segment(
109429           p_to_segment_code         => 'GL_ACCOUNT'
109430         , p_segment_value           => l_segment
109431         , p_from_segment_code       => l_adr_value_segment_code
109432         , p_from_combination_id     => l_adr_value_combination_id
109433         , p_value_type_code         => l_adr_value_type_code
109434         , p_transaction_coa_id      => l_adr_transaction_coa_id
109435         , p_accounting_coa_id       => l_adr_accounting_coa_id
109436         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
109437         , p_flex_value_set_id       => l_adr_flex_value_set_id
109438         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
109439         , p_adr_type_code           => 'S'
109440         , p_component_type          => l_component_type
109441         , p_component_code          => l_component_code
109442         , p_component_type_code     => l_component_type_code
109443         , p_component_appl_id       => l_component_appl_id
109444         , p_amb_context_code        => l_amb_context_code
109445         , p_entity_code             => 'TRANSACTIONS'
109446         , p_event_class_code        => 'RETIREMENTS'
109447         , p_side                    => 'NA'
109448         );
109449 
109450   END IF;
109451 
109452    l_segment := AcctDerRule_168(
109453            p_application_id           => p_application_id
109454          , p_ae_header_id             => l_ae_header_id 
109455 , p_source_3 => p_source_3
109456 , p_source_29 => p_source_29
109457          , x_transaction_coa_id       => l_adr_transaction_coa_id
109458          , x_accounting_coa_id        => l_adr_accounting_coa_id
109459          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
109460          , x_flex_value_set_id        => l_adr_flex_value_set_id
109461          , x_value_type_code          => l_adr_value_type_code
109462          , x_value_combination_id     => l_adr_value_combination_id
109468    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
109463          , x_value_segment_code       => l_adr_value_segment_code
109464          , p_side                     => 'NA'
109465          , p_override_seg_flag        => 'Y'
109466    );
109467 
109469 
109470       xla_ae_lines_pkg.set_segment(
109471           p_to_segment_code         => 'GL_BALANCING'
109472         , p_segment_value           => l_segment
109473         , p_from_segment_code       => l_adr_value_segment_code
109474         , p_from_combination_id     => l_adr_value_combination_id
109475         , p_value_type_code         => l_adr_value_type_code
109476         , p_transaction_coa_id      => l_adr_transaction_coa_id
109477         , p_accounting_coa_id       => l_adr_accounting_coa_id
109478         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
109479         , p_flex_value_set_id       => l_adr_flex_value_set_id
109480         , p_adr_code                => 'FA_EXPENSE_ACCT'
109481         , p_adr_type_code           => 'S'
109482         , p_component_type          => l_component_type
109483         , p_component_code          => l_component_code
109484         , p_component_type_code     => l_component_type_code
109485         , p_component_appl_id       => l_component_appl_id
109486         , p_amb_context_code        => l_amb_context_code
109487         , p_entity_code             => 'TRANSACTIONS'
109488         , p_event_class_code        => 'RETIREMENTS'
109489         , p_side                    => 'NA'
109490         );
109491 
109492   END IF;
109493 
109494    --
109495    --
109496    END IF;
109497    --
109498    -- Bug 4922099
109499    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
109500           (NVL(l_enc_upg_option, 'N') = 'O')
109501         ) AND
109502         (l_bflow_method_code = 'PRIOR_ENTRY')
109503       )
109504    THEN
109505       IF
109506       --
109507       1 = 2
109508       --
109509       THEN
109510       xla_accounting_err_pkg.build_message
109511                                     (p_appli_s_name            => 'XLA'
109512                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
109513                                     ,p_token_1                 => 'LINE_NUMBER'
109514                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
109515                                     ,p_token_2                 => 'LINE_TYPE_NAME'
109516                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
109517                                                                              l_component_type
109518                                                                             ,l_component_code
109519                                                                             ,l_component_type_code
109520                                                                             ,l_component_appl_id
109521                                                                             ,l_amb_context_code
109522                                                                             ,l_entity_code
109523                                                                             ,l_event_class_code
109524                                                                            )
109525                                     ,p_token_3                 => 'OWNER'
109526                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
109527                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
109528                                                                           ,p_lookup_code    => l_component_type_code
109529                                                                          )
109530                                     ,p_token_4                 => 'PRODUCT_NAME'
109531                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
109532                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
109533                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
109534                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
109535                                     ,p_ae_header_id            =>  NULL
109536                                        );
109537 
109538         IF (C_LEVEL_ERROR>= g_log_level) THEN
109539                  trace
109540                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
109541                       ,p_level    => C_LEVEL_ERROR
109542                       ,p_module   => l_log_module);
109543         END IF;
109544       END IF;
109545    END IF;
109546    --
109547    --
109548    ------------------------------------------------------------------------------------------------
109549    -- 4219869 Business Flow
109550    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
109554 
109551    -- Prior Entry.  Currently, the following code is always generated.
109552    ------------------------------------------------------------------------------------------------
109553    XLA_AE_LINES_PKG.ValidateCurrentLine;
109555    ------------------------------------------------------------------------------------
109556    -- 4219869 Business Flow
109557    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
109558    ------------------------------------------------------------------------------------
109559    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
109560 
109561    ----------------------------------------------------------------------------------
109562    -- 4219869 Business Flow
109563    -- Update journal entry status -- Need to generate this within IF <condition>
109564    ----------------------------------------------------------------------------------
109565    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
109566          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
109567          ,p_balance_type_code => l_balance_type_code
109568          );
109569 
109570    -------------------------------------------------------------------------------------------
109571    -- 4262811 - Generate the Accrual Reversal lines
109572    -------------------------------------------------------------------------------------------
109573    BEGIN
109574       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
109575                               (g_array_event(p_event_id).array_value_num('header_index'));
109576       IF l_acc_rev_flag IS NULL THEN
109577          l_acc_rev_flag := 'N';
109578       END IF;
109579    EXCEPTION
109580       WHEN OTHERS THEN
109581          l_acc_rev_flag := 'N';
109582    END;
109583    --
109584    IF (l_acc_rev_flag = 'Y') THEN
109585 
109586        -- 4645092  ------------------------------------------------------------------------------
109587        -- To allow MPA report to determine if it should generate report process
109588        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
109589        ------------------------------------------------------------------------------------------
109590 
109591        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
109592        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
109593    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
109594    -- call ADRs
109595    -- Bug 4922099
109596    --
109597    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
109598         (NVL(l_actual_upg_option, 'N') = 'O') OR
109599         (NVL(l_enc_upg_option, 'N') = 'O')
109600       )
109601    THEN
109602    NULL;
109603    --
109604    --
109605    
109606   l_ccid := AcctDerRule_174(
109607            p_application_id           => p_application_id
109608          , p_ae_header_id             => l_ae_header_id 
109609 , p_source_3 => p_source_3
109610 , p_source_17 => p_source_17
109611 , p_source_30 => p_source_30
109612          , x_transaction_coa_id       => l_adr_transaction_coa_id
109613          , x_accounting_coa_id        => l_adr_accounting_coa_id
109614          , x_value_type_code          => l_adr_value_type_code
109615          , p_side                     => 'NA'
109616    );
109617 
109618    xla_ae_lines_pkg.set_ccid(
109619     p_code_combination_id          => l_ccid
109620   , p_value_type_code              => l_adr_value_type_code
109621   , p_transaction_coa_id           => l_adr_transaction_coa_id
109622   , p_accounting_coa_id            => l_adr_accounting_coa_id
109623   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
109624   , p_adr_type_code                => 'S'
109625   , p_component_type               => l_component_type
109626   , p_component_code               => l_component_code
109627   , p_component_type_code          => l_component_type_code
109628   , p_component_appl_id            => l_component_appl_id
109629   , p_amb_context_code             => l_amb_context_code
109630   , p_side                         => 'NA'
109631   );
109632 
109633 
109634    l_segment := AcctDerRule_149(
109635            p_application_id           => p_application_id
109636          , p_ae_header_id             => l_ae_header_id 
109637 , p_source_3 => p_source_3
109638 , p_source_10 => p_source_10
109639          , x_transaction_coa_id       => l_adr_transaction_coa_id
109640          , x_accounting_coa_id        => l_adr_accounting_coa_id
109641          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
109642          , x_flex_value_set_id        => l_adr_flex_value_set_id
109643          , x_value_type_code          => l_adr_value_type_code
109644          , x_value_combination_id     => l_adr_value_combination_id
109645          , x_value_segment_code       => l_adr_value_segment_code
109646          , p_side                     => 'NA'
109647          , p_override_seg_flag        => 'Y'
109648    );
109649 
109650    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
109651 
109652       xla_ae_lines_pkg.set_segment(
109653           p_to_segment_code         => 'GL_ACCOUNT'
109654         , p_segment_value           => l_segment
109655         , p_from_segment_code       => l_adr_value_segment_code
109656         , p_from_combination_id     => l_adr_value_combination_id
109657         , p_value_type_code         => l_adr_value_type_code
109658         , p_transaction_coa_id      => l_adr_transaction_coa_id
109659         , p_accounting_coa_id       => l_adr_accounting_coa_id
109660         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
109661         , p_flex_value_set_id       => l_adr_flex_value_set_id
109662         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
109663         , p_adr_type_code           => 'S'
109664         , p_component_type          => l_component_type
109665         , p_component_code          => l_component_code
109666         , p_component_type_code     => l_component_type_code
109667         , p_component_appl_id       => l_component_appl_id
109671         , p_side                    => 'NA'
109668         , p_amb_context_code        => l_amb_context_code
109669         , p_entity_code             => 'TRANSACTIONS'
109670         , p_event_class_code        => 'RETIREMENTS'
109672         );
109673 
109674   END IF;
109675 
109676    l_segment := AcctDerRule_168(
109677            p_application_id           => p_application_id
109678          , p_ae_header_id             => l_ae_header_id 
109679 , p_source_3 => p_source_3
109680 , p_source_29 => p_source_29
109681          , x_transaction_coa_id       => l_adr_transaction_coa_id
109682          , x_accounting_coa_id        => l_adr_accounting_coa_id
109683          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
109684          , x_flex_value_set_id        => l_adr_flex_value_set_id
109685          , x_value_type_code          => l_adr_value_type_code
109686          , x_value_combination_id     => l_adr_value_combination_id
109687          , x_value_segment_code       => l_adr_value_segment_code
109688          , p_side                     => 'NA'
109689          , p_override_seg_flag        => 'Y'
109690    );
109691 
109692    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
109693 
109694       xla_ae_lines_pkg.set_segment(
109695           p_to_segment_code         => 'GL_BALANCING'
109696         , p_segment_value           => l_segment
109697         , p_from_segment_code       => l_adr_value_segment_code
109698         , p_from_combination_id     => l_adr_value_combination_id
109699         , p_value_type_code         => l_adr_value_type_code
109700         , p_transaction_coa_id      => l_adr_transaction_coa_id
109701         , p_accounting_coa_id       => l_adr_accounting_coa_id
109702         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
109703         , p_flex_value_set_id       => l_adr_flex_value_set_id
109704         , p_adr_code                => 'FA_EXPENSE_ACCT'
109705         , p_adr_type_code           => 'S'
109706         , p_component_type          => l_component_type
109707         , p_component_code          => l_component_code
109708         , p_component_type_code     => l_component_type_code
109709         , p_component_appl_id       => l_component_appl_id
109710         , p_amb_context_code        => l_amb_context_code
109711         , p_entity_code             => 'TRANSACTIONS'
109712         , p_event_class_code        => 'RETIREMENTS'
109713         , p_side                    => 'NA'
109714         );
109715 
109716   END IF;
109717 
109718    --
109719    --
109720    END IF;
109721 
109722        --
109723        -- Update the line information that should be overwritten
109724        --
109725        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
109726                                          p_header_num   => 1);
109727        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
109728 
109729        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
109730 
109734 
109731        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
109732           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
109733        END IF;
109735       --
109736       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
109737       --
109738       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
109739           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
109740       ELSE
109741           ---------------------------------------------------------------------------------------------------
109742           -- 4262811a Switch Sign
109743           ---------------------------------------------------------------------------------------------------
109744           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
109745           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
109746                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
109747           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
109748                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
109749           -- 5132302
109750           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
109751                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
109752 
109753       END IF;
109754 
109755       -- 4955764
109756       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
109757       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
109758 
109759 
109760       XLA_AE_LINES_PKG.ValidateCurrentLine;
109764                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
109761       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
109762 
109763       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
109765                ,p_balance_type_code => l_balance_type_code);
109766 
109767    END IF;
109768 
109769    -----------------------------------------------------------------------------------------
109770    -- 4262811 Multiperiod Accounting
109771    -----------------------------------------------------------------------------------------
109772      -- No MPA option is assigned.
109773 
109774 
109775 END IF;
109776 END IF;
109777 --
109778 
109779 --
109780 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
109781    trace
109782       (p_msg      => 'END of AcctLineType_307'
109783       ,p_level    => C_LEVEL_PROCEDURE
109784       ,p_module   => l_log_module);
109785 END IF;
109786 --
109787 EXCEPTION
109788   WHEN xla_exceptions_pkg.application_exception THEN
109789       RAISE;
109790   WHEN OTHERS THEN
109791        xla_exceptions_pkg.raise_message
109792            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_307');
109793 END AcctLineType_307;
109794 --
109795 
109796 ---------------------------------------
109797 --
109798 -- PRIVATE FUNCTION
109799 --         AcctLineType_308
109800 --
109801 ---------------------------------------
109802 PROCEDURE AcctLineType_308 (
109803   p_application_id        IN NUMBER
109804  ,p_event_id              IN NUMBER
109805  ,p_calculate_acctd_flag  IN VARCHAR2
109806  ,p_calculate_g_l_flag    IN VARCHAR2
109807  ,p_actual_flag           IN OUT VARCHAR2
109808  ,p_balance_type_code     OUT VARCHAR2
109809  ,p_gain_or_loss_ref      OUT VARCHAR2
109810  
109811 --Period Close Date
109812  , p_source_1            IN DATE
109813 --Generated Code Combination Identifier
109814  , p_source_3            IN NUMBER
109815 --Depreciation Reserve Account
109816  , p_source_10            IN VARCHAR2
109817 --Generated Offset Code Combination Identifier
109818  , p_source_17            IN NUMBER
109819 --Expense Account Code Combination Identifier
109820  , p_source_29            IN NUMBER
109821 --Default Code Combination Identifier
109822  , p_source_30            IN NUMBER
109823 --Adjustment Type
109824  , p_source_35            IN VARCHAR2
109825 --Transaction Header Identifier
109826  , p_source_36            IN NUMBER
109827 --Adjustment Line Identifier
109828  , p_source_37            IN NUMBER
109829 --Distribution Type Code
109830  , p_source_38            IN VARCHAR2
109831 --Entered Amount
109832  , p_source_39            IN NUMBER
109833 --Currency Code
109834  , p_source_40            IN VARCHAR2
109835 )
109836 IS
109837 
109838 l_component_type              VARCHAR2(80);
109839 l_component_code              VARCHAR2(30);
109840 l_component_type_code         VARCHAR2(1);
109841 l_component_appl_id           INTEGER;
109842 l_amb_context_code            VARCHAR2(30);
109843 l_entity_code                 VARCHAR2(30);
109844 l_event_class_code            VARCHAR2(30);
109845 l_ae_header_id                NUMBER;
109846 l_event_type_code             VARCHAR2(30);
109847 l_line_definition_code        VARCHAR2(30);
109848 l_line_definition_owner_code  VARCHAR2(1);
109849 --
109850 -- adr variables
109851 l_segment                     VARCHAR2(30);
109852 l_ccid                        NUMBER;
109853 l_adr_transaction_coa_id      NUMBER;
109854 l_adr_accounting_coa_id       NUMBER;
109855 l_adr_flexfield_segment_code  VARCHAR2(30);
109856 l_adr_flex_value_set_id       NUMBER;
109857 l_adr_value_type_code         VARCHAR2(30);
109858 l_adr_value_combination_id    NUMBER;
109859 l_adr_value_segment_code      VARCHAR2(30);
109860 
109861 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
109862 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
109863 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
109864 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
109865 
109866 -- 4262811 Variables ------------------------------------------------------------------------------------------
109867 l_entered_amt_idx             NUMBER;
109868 l_accted_amt_idx              NUMBER;
109869 l_acc_rev_flag                VARCHAR2(1);
109870 l_accrual_line_num            NUMBER;
109871 l_tmp_amt                     NUMBER;
109872 l_acc_rev_natural_side_code   VARCHAR2(1);
109873 
109874 l_num_entries                 NUMBER;
109875 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
109876 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
109877 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
109878 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
109879 l_recog_line_1                NUMBER;
109880 l_recog_line_2                NUMBER;
109881 
109882 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
109886 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
109883 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
109884 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
109885 
109887 
109888 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
109889 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
109890 
109891 ---------------------------------------------------------------------------------------------------------------
109892 
109893 
109894 --
109895 -- bulk performance
109896 --
109897 l_balance_type_code           VARCHAR2(1);
109898 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
109899 l_log_module                  VARCHAR2(240);
109900 
109901 --
109902 -- Upgrade strategy
109903 --
109904 l_actual_upg_option           VARCHAR2(1);
109905 l_enc_upg_option           VARCHAR2(1);
109906 
109907 --
109908 BEGIN
109909 --
109910 IF g_log_enabled THEN
109911       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_308';
109912 END IF;
109913 --
109914 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
109915 
109916       trace
109917          (p_msg      => 'BEGIN of AcctLineType_308'
109918          ,p_level    => C_LEVEL_PROCEDURE
109919          ,p_module   => l_log_module);
109920 
109921 END IF;
109922 --
109923 l_component_type             := 'AMB_JLT';
109924 l_component_code             := 'FA_RETIREMENT_RESERVE_BAL';
109925 l_component_type_code        := 'S';
109926 l_component_appl_id          :=  140;
109927 l_amb_context_code           := 'DEFAULT';
109928 l_entity_code                := 'TRANSACTIONS';
109929 l_event_class_code           := 'RETIREMENTS';
109930 l_event_type_code            := 'REINSTATEMENTS';
109931 l_line_definition_owner_code := 'S';
109932 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
109933 --
109934 l_balance_type_code          := 'A';
109935 l_segment                     := NULL;
109936 l_ccid                        := NULL;
109937 l_adr_transaction_coa_id      := NULL;
109938 l_adr_accounting_coa_id       := NULL;
109939 l_adr_flexfield_segment_code  := NULL;
109940 l_adr_flex_value_set_id       := NULL;
109941 l_adr_value_type_code         := NULL;
109942 l_adr_value_combination_id    := NULL;
109943 l_adr_value_segment_code      := NULL;
109944 
109945 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
109946 l_bflow_class_code           := '';    -- 4219869 Business Flow
109947 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
109948 l_budgetary_control_flag     := 'N';
109949 
109950 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
109951 l_bflow_applied_to_amt       := NULL; -- 5132302
109952 l_entered_amt_idx            := NULL;          -- 4262811
109953 l_accted_amt_idx             := NULL;          -- 4262811
109954 l_acc_rev_flag               := NULL;          -- 4262811
109955 l_accrual_line_num           := NULL;          -- 4262811
109956 l_tmp_amt                    := NULL;          -- 4262811
109957 --
109958  
109959 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
109960     l_balance_type_code <> 'B' THEN
109961 IF NVL(p_source_35,'
109962 ') =  'BONUS EXPENSE'
109963  THEN 
109964 
109965    --
109966    XLA_AE_LINES_PKG.SetNewLine;
109967 
109968    p_balance_type_code          := l_balance_type_code;
109969    -- set the flag so later we will know whether the gain loss line needs to be created
109970    
109971    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
109972      p_actual_flag :='A';
109973    END IF;
109974 
109975    --
109976    -- bulk performance
109977    --
109978    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
109979                                       p_header_num   => 0); -- 4262811
109980    --
109981    -- set accounting line options
109982    --
109983    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
109984            p_natural_side_code          => 'C'
109985          , p_gain_or_loss_flag          => 'N'
109986          , p_gl_transfer_mode_code      => 'S'
109987          , p_acct_entry_type_code       => 'A'
109988          , p_switch_side_flag           => 'Y'
109989          , p_merge_duplicate_code       => 'N'
109990          );
109991    --
109992    l_acc_rev_natural_side_code := 'D';  -- 4262811
109993    -- 
109994    --
109995    -- set accounting line type info
109996    --
109997    xla_ae_lines_pkg.SetAcctLineType
109998       (p_component_type             => l_component_type
109999       ,p_event_type_code            => l_event_type_code
110000       ,p_line_definition_owner_code => l_line_definition_owner_code
110001       ,p_line_definition_code       => l_line_definition_code
110002       ,p_accounting_line_code       => l_component_code
110003       ,p_accounting_line_type_code  => l_component_type_code
110004       ,p_accounting_line_appl_id    => l_component_appl_id
110005       ,p_amb_context_code           => l_amb_context_code
110006       ,p_entity_code                => l_entity_code
110007       ,p_event_class_code           => l_event_class_code);
110008    --
110009    -- set accounting class
110010    --
110011    xla_ae_lines_pkg.SetAcctClass(
110012            p_accounting_class_code  => 'ASSET'
110013          , p_ae_header_id           => l_ae_header_id
110014          );
110015 
110016    --
110017    -- set rounding class
110018    --
110019    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
110020                       'ASSET';
110021 
110022    --
110023    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
110027    --
110024    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
110025    --
110026    -- bulk performance
110028    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
110029 
110030    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
110031       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
110032 
110033    -- 4955764
110034    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
110035       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
110036 
110037    -- 4458381 Public Sector Enh
110038    
110039    --
110040    -- set accounting attributes for the line type
110041    --
110042    l_entered_amt_idx := 4;
110043    l_accted_amt_idx  := 6;
110044    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
110045    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
110046    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
110047    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
110048    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
110049    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
110050    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
110051    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
110052    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
110053    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
110054    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
110055    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
110056    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
110057 
110058    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
110059    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
110060 
110061    ---------------------------------------------------------------------------------------------------------------
110062    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
110063    ---------------------------------------------------------------------------------------------------------------
110064    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
110065 
110066    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
110067    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
110068 
110069    IF xla_accounting_cache_pkg.GetValueChar
110070          (p_source_code         => 'LEDGER_CATEGORY_CODE'
110071          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
110072    AND l_bflow_method_code = 'PRIOR_ENTRY'
110073 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
110074    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
110075          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
110076        )
110077    THEN
110078          xla_ae_lines_pkg.BflowUpgEntry
110079            (p_business_method_code    => l_bflow_method_code
110080            ,p_business_class_code     => l_bflow_class_code
110081            ,p_balance_type            => l_balance_type_code);
110082    ELSE
110083       NULL;
110084 -- No business flow processing for business flow method of NONE.
110085    END IF;
110086 
110087    --
110088    -- call analytical criteria
110089    --
110090    
110091    --
110092    -- call description
110093    --
110094    
110095 xla_ae_lines_pkg.SetLineDescription(
110096    p_ae_header_id => l_ae_header_id
110097   ,p_description  => Description_82 (
110098      p_application_id         => p_application_id
110099    , p_ae_header_id           => l_ae_header_id 
110100 , p_source_1 => p_source_1
110101    )
110102 );
110103 
110104 
110105    --
110106    -- call ADRs
110107    -- Bug 4922099
110108    --
110109    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
110110         (NVL(l_actual_upg_option, 'N') = 'O') OR
110111         (NVL(l_enc_upg_option, 'N') = 'O')
110112       )
110113    THEN
110114    NULL;
110115    --
110116    --
110117    
110118   l_ccid := AcctDerRule_174(
110119            p_application_id           => p_application_id
110120          , p_ae_header_id             => l_ae_header_id 
110121 , p_source_3 => p_source_3
110122 , p_source_17 => p_source_17
110123 , p_source_30 => p_source_30
110124          , x_transaction_coa_id       => l_adr_transaction_coa_id
110125          , x_accounting_coa_id        => l_adr_accounting_coa_id
110126          , x_value_type_code          => l_adr_value_type_code
110127          , p_side                     => 'NA'
110128    );
110129 
110130    xla_ae_lines_pkg.set_ccid(
110131     p_code_combination_id          => l_ccid
110132   , p_value_type_code              => l_adr_value_type_code
110133   , p_transaction_coa_id           => l_adr_transaction_coa_id
110134   , p_accounting_coa_id            => l_adr_accounting_coa_id
110135   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
110136   , p_adr_type_code                => 'S'
110137   , p_component_type               => l_component_type
110138   , p_component_code               => l_component_code
110139   , p_component_type_code          => l_component_type_code
110140   , p_component_appl_id            => l_component_appl_id
110141   , p_amb_context_code             => l_amb_context_code
110142   , p_side                         => 'NA'
110143   );
110144 
110145 
110146    l_segment := AcctDerRule_149(
110147            p_application_id           => p_application_id
110148          , p_ae_header_id             => l_ae_header_id 
110149 , p_source_3 => p_source_3
110150 , p_source_10 => p_source_10
110151          , x_transaction_coa_id       => l_adr_transaction_coa_id
110155          , x_value_type_code          => l_adr_value_type_code
110152          , x_accounting_coa_id        => l_adr_accounting_coa_id
110153          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
110154          , x_flex_value_set_id        => l_adr_flex_value_set_id
110156          , x_value_combination_id     => l_adr_value_combination_id
110157          , x_value_segment_code       => l_adr_value_segment_code
110158          , p_side                     => 'NA'
110159          , p_override_seg_flag        => 'Y'
110160    );
110161 
110162    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
110163 
110164       xla_ae_lines_pkg.set_segment(
110165           p_to_segment_code         => 'GL_ACCOUNT'
110166         , p_segment_value           => l_segment
110167         , p_from_segment_code       => l_adr_value_segment_code
110168         , p_from_combination_id     => l_adr_value_combination_id
110169         , p_value_type_code         => l_adr_value_type_code
110170         , p_transaction_coa_id      => l_adr_transaction_coa_id
110171         , p_accounting_coa_id       => l_adr_accounting_coa_id
110172         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
110173         , p_flex_value_set_id       => l_adr_flex_value_set_id
110174         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
110175         , p_adr_type_code           => 'S'
110176         , p_component_type          => l_component_type
110177         , p_component_code          => l_component_code
110178         , p_component_type_code     => l_component_type_code
110179         , p_component_appl_id       => l_component_appl_id
110180         , p_amb_context_code        => l_amb_context_code
110181         , p_entity_code             => 'TRANSACTIONS'
110182         , p_event_class_code        => 'RETIREMENTS'
110183         , p_side                    => 'NA'
110184         );
110185 
110186   END IF;
110187 
110188    l_segment := AcctDerRule_168(
110189            p_application_id           => p_application_id
110190          , p_ae_header_id             => l_ae_header_id 
110194          , x_accounting_coa_id        => l_adr_accounting_coa_id
110191 , p_source_3 => p_source_3
110192 , p_source_29 => p_source_29
110193          , x_transaction_coa_id       => l_adr_transaction_coa_id
110195          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
110196          , x_flex_value_set_id        => l_adr_flex_value_set_id
110197          , x_value_type_code          => l_adr_value_type_code
110198          , x_value_combination_id     => l_adr_value_combination_id
110199          , x_value_segment_code       => l_adr_value_segment_code
110200          , p_side                     => 'NA'
110201          , p_override_seg_flag        => 'Y'
110202    );
110203 
110204    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
110205 
110206       xla_ae_lines_pkg.set_segment(
110207           p_to_segment_code         => 'GL_BALANCING'
110208         , p_segment_value           => l_segment
110209         , p_from_segment_code       => l_adr_value_segment_code
110210         , p_from_combination_id     => l_adr_value_combination_id
110211         , p_value_type_code         => l_adr_value_type_code
110212         , p_transaction_coa_id      => l_adr_transaction_coa_id
110213         , p_accounting_coa_id       => l_adr_accounting_coa_id
110214         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
110215         , p_flex_value_set_id       => l_adr_flex_value_set_id
110216         , p_adr_code                => 'FA_EXPENSE_ACCT'
110217         , p_adr_type_code           => 'S'
110218         , p_component_type          => l_component_type
110219         , p_component_code          => l_component_code
110220         , p_component_type_code     => l_component_type_code
110221         , p_component_appl_id       => l_component_appl_id
110222         , p_amb_context_code        => l_amb_context_code
110223         , p_entity_code             => 'TRANSACTIONS'
110224         , p_event_class_code        => 'RETIREMENTS'
110225         , p_side                    => 'NA'
110226         );
110227 
110228   END IF;
110229 
110230    --
110231    --
110232    END IF;
110233    --
110234    -- Bug 4922099
110235    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
110236           (NVL(l_enc_upg_option, 'N') = 'O')
110237         ) AND
110238         (l_bflow_method_code = 'PRIOR_ENTRY')
110239       )
110240    THEN
110241       IF
110242       --
110243       1 = 2
110244       --
110245       THEN
110246       xla_accounting_err_pkg.build_message
110247                                     (p_appli_s_name            => 'XLA'
110248                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
110249                                     ,p_token_1                 => 'LINE_NUMBER'
110250                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
110251                                     ,p_token_2                 => 'LINE_TYPE_NAME'
110255                                                                             ,l_component_type_code
110252                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
110253                                                                              l_component_type
110254                                                                             ,l_component_code
110256                                                                             ,l_component_appl_id
110257                                                                             ,l_amb_context_code
110258                                                                             ,l_entity_code
110259                                                                             ,l_event_class_code
110260                                                                            )
110261                                     ,p_token_3                 => 'OWNER'
110262                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
110263                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
110264                                                                           ,p_lookup_code    => l_component_type_code
110265                                                                          )
110266                                     ,p_token_4                 => 'PRODUCT_NAME'
110267                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
110268                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
110269                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
110270                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
110271                                     ,p_ae_header_id            =>  NULL
110272                                        );
110273 
110274         IF (C_LEVEL_ERROR>= g_log_level) THEN
110275                  trace
110276                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
110277                       ,p_level    => C_LEVEL_ERROR
110278                       ,p_module   => l_log_module);
110279         END IF;
110280       END IF;
110281    END IF;
110282    --
110283    --
110284    ------------------------------------------------------------------------------------------------
110285    -- 4219869 Business Flow
110286    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
110287    -- Prior Entry.  Currently, the following code is always generated.
110288    ------------------------------------------------------------------------------------------------
110289    XLA_AE_LINES_PKG.ValidateCurrentLine;
110290 
110291    ------------------------------------------------------------------------------------
110292    -- 4219869 Business Flow
110293    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
110294    ------------------------------------------------------------------------------------
110295    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
110296 
110297    ----------------------------------------------------------------------------------
110298    -- 4219869 Business Flow
110299    -- Update journal entry status -- Need to generate this within IF <condition>
110300    ----------------------------------------------------------------------------------
110301    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
110302          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
110303          ,p_balance_type_code => l_balance_type_code
110304          );
110305 
110306    -------------------------------------------------------------------------------------------
110307    -- 4262811 - Generate the Accrual Reversal lines
110308    -------------------------------------------------------------------------------------------
110309    BEGIN
110310       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
110314       END IF;
110311                               (g_array_event(p_event_id).array_value_num('header_index'));
110312       IF l_acc_rev_flag IS NULL THEN
110313          l_acc_rev_flag := 'N';
110315    EXCEPTION
110316       WHEN OTHERS THEN
110317          l_acc_rev_flag := 'N';
110318    END;
110319    --
110320    IF (l_acc_rev_flag = 'Y') THEN
110321 
110322        -- 4645092  ------------------------------------------------------------------------------
110323        -- To allow MPA report to determine if it should generate report process
110324        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
110325        ------------------------------------------------------------------------------------------
110326 
110327        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
110328        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
110329    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
110330    -- call ADRs
110331    -- Bug 4922099
110332    --
110333    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
110334         (NVL(l_actual_upg_option, 'N') = 'O') OR
110335         (NVL(l_enc_upg_option, 'N') = 'O')
110336       )
110337    THEN
110338    NULL;
110339    --
110340    --
110341    
110342   l_ccid := AcctDerRule_174(
110343            p_application_id           => p_application_id
110344          , p_ae_header_id             => l_ae_header_id 
110345 , p_source_3 => p_source_3
110346 , p_source_17 => p_source_17
110347 , p_source_30 => p_source_30
110348          , x_transaction_coa_id       => l_adr_transaction_coa_id
110349          , x_accounting_coa_id        => l_adr_accounting_coa_id
110350          , x_value_type_code          => l_adr_value_type_code
110351          , p_side                     => 'NA'
110352    );
110353 
110354    xla_ae_lines_pkg.set_ccid(
110355     p_code_combination_id          => l_ccid
110356   , p_value_type_code              => l_adr_value_type_code
110357   , p_transaction_coa_id           => l_adr_transaction_coa_id
110358   , p_accounting_coa_id            => l_adr_accounting_coa_id
110359   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
110360   , p_adr_type_code                => 'S'
110361   , p_component_type               => l_component_type
110362   , p_component_code               => l_component_code
110363   , p_component_type_code          => l_component_type_code
110364   , p_component_appl_id            => l_component_appl_id
110368 
110365   , p_amb_context_code             => l_amb_context_code
110366   , p_side                         => 'NA'
110367   );
110369 
110370    l_segment := AcctDerRule_149(
110371            p_application_id           => p_application_id
110372          , p_ae_header_id             => l_ae_header_id 
110373 , p_source_3 => p_source_3
110374 , p_source_10 => p_source_10
110375          , x_transaction_coa_id       => l_adr_transaction_coa_id
110376          , x_accounting_coa_id        => l_adr_accounting_coa_id
110377          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
110378          , x_flex_value_set_id        => l_adr_flex_value_set_id
110379          , x_value_type_code          => l_adr_value_type_code
110380          , x_value_combination_id     => l_adr_value_combination_id
110381          , x_value_segment_code       => l_adr_value_segment_code
110382          , p_side                     => 'NA'
110383          , p_override_seg_flag        => 'Y'
110384    );
110385 
110386    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
110387 
110388       xla_ae_lines_pkg.set_segment(
110389           p_to_segment_code         => 'GL_ACCOUNT'
110390         , p_segment_value           => l_segment
110391         , p_from_segment_code       => l_adr_value_segment_code
110392         , p_from_combination_id     => l_adr_value_combination_id
110393         , p_value_type_code         => l_adr_value_type_code
110394         , p_transaction_coa_id      => l_adr_transaction_coa_id
110395         , p_accounting_coa_id       => l_adr_accounting_coa_id
110396         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
110397         , p_flex_value_set_id       => l_adr_flex_value_set_id
110398         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
110399         , p_adr_type_code           => 'S'
110400         , p_component_type          => l_component_type
110401         , p_component_code          => l_component_code
110402         , p_component_type_code     => l_component_type_code
110403         , p_component_appl_id       => l_component_appl_id
110404         , p_amb_context_code        => l_amb_context_code
110405         , p_entity_code             => 'TRANSACTIONS'
110406         , p_event_class_code        => 'RETIREMENTS'
110407         , p_side                    => 'NA'
110408         );
110409 
110410   END IF;
110411 
110412    l_segment := AcctDerRule_168(
110413            p_application_id           => p_application_id
110414          , p_ae_header_id             => l_ae_header_id 
110415 , p_source_3 => p_source_3
110416 , p_source_29 => p_source_29
110417          , x_transaction_coa_id       => l_adr_transaction_coa_id
110418          , x_accounting_coa_id        => l_adr_accounting_coa_id
110419          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
110420          , x_flex_value_set_id        => l_adr_flex_value_set_id
110421          , x_value_type_code          => l_adr_value_type_code
110422          , x_value_combination_id     => l_adr_value_combination_id
110423          , x_value_segment_code       => l_adr_value_segment_code
110424          , p_side                     => 'NA'
110425          , p_override_seg_flag        => 'Y'
110426    );
110427 
110428    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
110429 
110430       xla_ae_lines_pkg.set_segment(
110431           p_to_segment_code         => 'GL_BALANCING'
110432         , p_segment_value           => l_segment
110433         , p_from_segment_code       => l_adr_value_segment_code
110434         , p_from_combination_id     => l_adr_value_combination_id
110435         , p_value_type_code         => l_adr_value_type_code
110436         , p_transaction_coa_id      => l_adr_transaction_coa_id
110437         , p_accounting_coa_id       => l_adr_accounting_coa_id
110438         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
110439         , p_flex_value_set_id       => l_adr_flex_value_set_id
110440         , p_adr_code                => 'FA_EXPENSE_ACCT'
110441         , p_adr_type_code           => 'S'
110442         , p_component_type          => l_component_type
110443         , p_component_code          => l_component_code
110444         , p_component_type_code     => l_component_type_code
110445         , p_component_appl_id       => l_component_appl_id
110446         , p_amb_context_code        => l_amb_context_code
110447         , p_entity_code             => 'TRANSACTIONS'
110448         , p_event_class_code        => 'RETIREMENTS'
110449         , p_side                    => 'NA'
110450         );
110451 
110452   END IF;
110453 
110454    --
110455    --
110456    END IF;
110457 
110458        --
110459        -- Update the line information that should be overwritten
110460        --
110461        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
110462                                          p_header_num   => 1);
110463        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
110464 
110465        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
110466 
110467        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
110468           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
110469        END IF;
110470 
110471       --
110472       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
110473       --
110474       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
110475           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
110476       ELSE
110477           ---------------------------------------------------------------------------------------------------
110478           -- 4262811a Switch Sign
110479           ---------------------------------------------------------------------------------------------------
110483           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
110480           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
110481           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
110482                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
110484                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
110485           -- 5132302
110486           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
110487                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
110488 
110489       END IF;
110490 
110491       -- 4955764
110492       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
110493       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
110494 
110495 
110496       XLA_AE_LINES_PKG.ValidateCurrentLine;
110497       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
110498 
110499       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
110500                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
110501                ,p_balance_type_code => l_balance_type_code);
110502 
110503    END IF;
110504 
110505    -----------------------------------------------------------------------------------------
110506    -- 4262811 Multiperiod Accounting
110507    -----------------------------------------------------------------------------------------
110508      -- No MPA option is assigned.
110509 
110510 
110511 END IF;
110512 END IF;
110513 --
110514 
110515 --
110516 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
110517    trace
110518       (p_msg      => 'END of AcctLineType_308'
110519       ,p_level    => C_LEVEL_PROCEDURE
110520       ,p_module   => l_log_module);
110521 END IF;
110522 --
110523 EXCEPTION
110524   WHEN xla_exceptions_pkg.application_exception THEN
110525       RAISE;
110526   WHEN OTHERS THEN
110527        xla_exceptions_pkg.raise_message
110528            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_308');
110529 END AcctLineType_308;
110530 --
110531 
110532 ---------------------------------------
110533 --
110534 -- PRIVATE FUNCTION
110535 --         AcctLineType_309
110536 --
110537 ---------------------------------------
110538 PROCEDURE AcctLineType_309 (
110539   p_application_id        IN NUMBER
110540  ,p_event_id              IN NUMBER
110541  ,p_calculate_acctd_flag  IN VARCHAR2
110542  ,p_calculate_g_l_flag    IN VARCHAR2
110543  ,p_actual_flag           IN OUT VARCHAR2
110544  ,p_balance_type_code     OUT VARCHAR2
110545  ,p_gain_or_loss_ref      OUT VARCHAR2
110546  
110547 --Period Close Date
110548  , p_source_1            IN DATE
110549 --Generated Code Combination Identifier
110550  , p_source_3            IN NUMBER
110551 --Cost Of Removal Clearing Account
110552  , p_source_12            IN VARCHAR2
110553 --Expense Account Code Combination Identifier
110554  , p_source_29            IN NUMBER
110555 --Default Code Combination Identifier
110556  , p_source_30            IN NUMBER
110557 --Adjustment Type
110558  , p_source_35            IN VARCHAR2
110559 --Transaction Header Identifier
110560  , p_source_36            IN NUMBER
110561 --Adjustment Line Identifier
110562  , p_source_37            IN NUMBER
110563 --Distribution Type Code
110564  , p_source_38            IN VARCHAR2
110565 --Entered Amount
110566  , p_source_39            IN NUMBER
110567 --Currency Code
110568  , p_source_40            IN VARCHAR2
110569 )
110570 IS
110571 
110572 l_component_type              VARCHAR2(80);
110573 l_component_code              VARCHAR2(30);
110574 l_component_type_code         VARCHAR2(1);
110575 l_component_appl_id           INTEGER;
110576 l_amb_context_code            VARCHAR2(30);
110577 l_entity_code                 VARCHAR2(30);
110578 l_event_class_code            VARCHAR2(30);
110579 l_ae_header_id                NUMBER;
110580 l_event_type_code             VARCHAR2(30);
110581 l_line_definition_code        VARCHAR2(30);
110582 l_line_definition_owner_code  VARCHAR2(1);
110583 --
110584 -- adr variables
110585 l_segment                     VARCHAR2(30);
110586 l_ccid                        NUMBER;
110587 l_adr_transaction_coa_id      NUMBER;
110588 l_adr_accounting_coa_id       NUMBER;
110589 l_adr_flexfield_segment_code  VARCHAR2(30);
110590 l_adr_flex_value_set_id       NUMBER;
110591 l_adr_value_type_code         VARCHAR2(30);
110592 l_adr_value_combination_id    NUMBER;
110593 l_adr_value_segment_code      VARCHAR2(30);
110594 
110595 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
110596 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
110597 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
110598 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
110599 
110600 -- 4262811 Variables ------------------------------------------------------------------------------------------
110601 l_entered_amt_idx             NUMBER;
110602 l_accted_amt_idx              NUMBER;
110603 l_acc_rev_flag                VARCHAR2(1);
110604 l_accrual_line_num            NUMBER;
110605 l_tmp_amt                     NUMBER;
110606 l_acc_rev_natural_side_code   VARCHAR2(1);
110607 
110611 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
110608 l_num_entries                 NUMBER;
110609 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
110610 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
110612 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
110613 l_recog_line_1                NUMBER;
110614 l_recog_line_2                NUMBER;
110615 
110616 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
110617 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
110618 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
110619 
110620 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
110621 
110622 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
110623 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
110624 
110625 ---------------------------------------------------------------------------------------------------------------
110626 
110627 
110628 --
110629 -- bulk performance
110630 --
110631 l_balance_type_code           VARCHAR2(1);
110632 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
110633 l_log_module                  VARCHAR2(240);
110634 
110635 --
110636 -- Upgrade strategy
110637 --
110638 l_actual_upg_option           VARCHAR2(1);
110639 l_enc_upg_option           VARCHAR2(1);
110640 
110641 --
110642 BEGIN
110643 --
110644 IF g_log_enabled THEN
110645       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_309';
110646 END IF;
110647 --
110648 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
110649 
110650       trace
110651          (p_msg      => 'BEGIN of AcctLineType_309'
110652          ,p_level    => C_LEVEL_PROCEDURE
110653          ,p_module   => l_log_module);
110654 
110655 END IF;
110656 --
110657 l_component_type             := 'AMB_JLT';
110658 l_component_code             := 'FA_RET_ADJ_COST_REM_CLR';
110659 l_component_type_code        := 'S';
110660 l_component_appl_id          :=  140;
110661 l_amb_context_code           := 'DEFAULT';
110662 l_entity_code                := 'TRANSACTIONS';
110663 l_event_class_code           := 'RETIREMENT_ADJUSTMENTS';
110664 l_event_type_code            := 'RETIREMENT_ADJUSTMENTS_ALL';
110665 l_line_definition_owner_code := 'S';
110666 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR20';
110667 --
110668 l_balance_type_code          := 'A';
110669 l_segment                     := NULL;
110670 l_ccid                        := NULL;
110671 l_adr_transaction_coa_id      := NULL;
110672 l_adr_accounting_coa_id       := NULL;
110673 l_adr_flexfield_segment_code  := NULL;
110674 l_adr_flex_value_set_id       := NULL;
110675 l_adr_value_type_code         := NULL;
110676 l_adr_value_combination_id    := NULL;
110677 l_adr_value_segment_code      := NULL;
110678 
110679 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
110680 l_bflow_class_code           := '';    -- 4219869 Business Flow
110681 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
110682 l_budgetary_control_flag     := 'N';
110683 
110684 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
110685 l_bflow_applied_to_amt       := NULL; -- 5132302
110686 l_entered_amt_idx            := NULL;          -- 4262811
110687 l_accted_amt_idx             := NULL;          -- 4262811
110688 l_acc_rev_flag               := NULL;          -- 4262811
110689 l_accrual_line_num           := NULL;          -- 4262811
110690 l_tmp_amt                    := NULL;          -- 4262811
110691 --
110692  
110693 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
110694     l_balance_type_code <> 'B' THEN
110695 IF NVL(p_source_35,'
110696 ') =  'REMOVALCOST'
110697  THEN 
110698 
110699    --
110700    XLA_AE_LINES_PKG.SetNewLine;
110701 
110702    p_balance_type_code          := l_balance_type_code;
110703    -- set the flag so later we will know whether the gain loss line needs to be created
110704    
110705    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
110706      p_actual_flag :='A';
110707    END IF;
110708 
110709    --
110710    -- bulk performance
110711    --
110712    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
110713                                       p_header_num   => 0); -- 4262811
110714    --
110715    -- set accounting line options
110716    --
110717    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
110718            p_natural_side_code          => 'C'
110719          , p_gain_or_loss_flag          => 'N'
110720          , p_gl_transfer_mode_code      => 'S'
110721          , p_acct_entry_type_code       => 'A'
110722          , p_switch_side_flag           => 'Y'
110723          , p_merge_duplicate_code       => 'N'
110724          );
110725    --
110726    l_acc_rev_natural_side_code := 'D';  -- 4262811
110727    -- 
110728    --
110729    -- set accounting line type info
110730    --
110731    xla_ae_lines_pkg.SetAcctLineType
110732       (p_component_type             => l_component_type
110733       ,p_event_type_code            => l_event_type_code
110734       ,p_line_definition_owner_code => l_line_definition_owner_code
110738       ,p_accounting_line_appl_id    => l_component_appl_id
110735       ,p_line_definition_code       => l_line_definition_code
110736       ,p_accounting_line_code       => l_component_code
110737       ,p_accounting_line_type_code  => l_component_type_code
110739       ,p_amb_context_code           => l_amb_context_code
110740       ,p_entity_code                => l_entity_code
110741       ,p_event_class_code           => l_event_class_code);
110742    --
110743    -- set accounting class
110744    --
110745    xla_ae_lines_pkg.SetAcctClass(
110746            p_accounting_class_code  => 'ASSET'
110747          , p_ae_header_id           => l_ae_header_id
110748          );
110749 
110750    --
110751    -- set rounding class
110752    --
110753    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
110754                       'ASSET';
110755 
110756    --
110757    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
110758    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
110759    --
110760    -- bulk performance
110761    --
110762    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
110763 
110764    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
110765       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
110766 
110767    -- 4955764
110768    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
110772    
110769       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
110770 
110771    -- 4458381 Public Sector Enh
110773    --
110774    -- set accounting attributes for the line type
110775    --
110776    l_entered_amt_idx := 4;
110777    l_accted_amt_idx  := 6;
110778    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
110779    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
110780    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
110781    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
110782    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
110783    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
110784    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
110785    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
110786    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
110787    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
110788    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
110789    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
110790    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
110791 
110792    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
110793    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
110794 
110795    ---------------------------------------------------------------------------------------------------------------
110796    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
110797    ---------------------------------------------------------------------------------------------------------------
110798    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
110799 
110800    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
110801    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
110802 
110803    IF xla_accounting_cache_pkg.GetValueChar
110804          (p_source_code         => 'LEDGER_CATEGORY_CODE'
110805          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
110806    AND l_bflow_method_code = 'PRIOR_ENTRY'
110807 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
110808    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
110809          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
110810        )
110811    THEN
110812          xla_ae_lines_pkg.BflowUpgEntry
110813            (p_business_method_code    => l_bflow_method_code
110814            ,p_business_class_code     => l_bflow_class_code
110815            ,p_balance_type            => l_balance_type_code);
110816    ELSE
110817       NULL;
110818 -- No business flow processing for business flow method of NONE.
110819    END IF;
110820 
110821    --
110822    -- call analytical criteria
110823    --
110824    
110825    --
110826    -- call description
110827    --
110828    
110829 xla_ae_lines_pkg.SetLineDescription(
110830    p_ae_header_id => l_ae_header_id
110831   ,p_description  => Description_85 (
110832      p_application_id         => p_application_id
110833    , p_ae_header_id           => l_ae_header_id 
110834 , p_source_1 => p_source_1
110838 
110835    )
110836 );
110837 
110839    --
110840    -- call ADRs
110841    -- Bug 4922099
110842    --
110843    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
110844         (NVL(l_actual_upg_option, 'N') = 'O') OR
110845         (NVL(l_enc_upg_option, 'N') = 'O')
110846       )
110847    THEN
110848    NULL;
110849    --
110850    --
110851    
110852   l_ccid := AcctDerRule_173(
110853            p_application_id           => p_application_id
110854          , p_ae_header_id             => l_ae_header_id 
110855 , p_source_3 => p_source_3
110856 , p_source_30 => p_source_30
110857          , x_transaction_coa_id       => l_adr_transaction_coa_id
110858          , x_accounting_coa_id        => l_adr_accounting_coa_id
110859          , x_value_type_code          => l_adr_value_type_code
110860          , p_side                     => 'NA'
110861    );
110862 
110863    xla_ae_lines_pkg.set_ccid(
110864     p_code_combination_id          => l_ccid
110865   , p_value_type_code              => l_adr_value_type_code
110866   , p_transaction_coa_id           => l_adr_transaction_coa_id
110867   , p_accounting_coa_id            => l_adr_accounting_coa_id
110868   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
110869   , p_adr_type_code                => 'S'
110870   , p_component_type               => l_component_type
110871   , p_component_code               => l_component_code
110872   , p_component_type_code          => l_component_type_code
110873   , p_component_appl_id            => l_component_appl_id
110874   , p_amb_context_code             => l_amb_context_code
110875   , p_side                         => 'NA'
110876   );
110877 
110878 
110879    l_segment := AcctDerRule_151(
110880            p_application_id           => p_application_id
110881          , p_ae_header_id             => l_ae_header_id 
110882 , p_source_3 => p_source_3
110883 , p_source_12 => p_source_12
110884          , x_transaction_coa_id       => l_adr_transaction_coa_id
110885          , x_accounting_coa_id        => l_adr_accounting_coa_id
110886          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
110887          , x_flex_value_set_id        => l_adr_flex_value_set_id
110888          , x_value_type_code          => l_adr_value_type_code
110889          , x_value_combination_id     => l_adr_value_combination_id
110890          , x_value_segment_code       => l_adr_value_segment_code
110891          , p_side                     => 'NA'
110892          , p_override_seg_flag        => 'Y'
110893    );
110894 
110895    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
110896 
110897       xla_ae_lines_pkg.set_segment(
110898           p_to_segment_code         => 'GL_ACCOUNT'
110899         , p_segment_value           => l_segment
110900         , p_from_segment_code       => l_adr_value_segment_code
110901         , p_from_combination_id     => l_adr_value_combination_id
110902         , p_value_type_code         => l_adr_value_type_code
110903         , p_transaction_coa_id      => l_adr_transaction_coa_id
110904         , p_accounting_coa_id       => l_adr_accounting_coa_id
110905         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
110906         , p_flex_value_set_id       => l_adr_flex_value_set_id
110907         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
110908         , p_adr_type_code           => 'S'
110909         , p_component_type          => l_component_type
110910         , p_component_code          => l_component_code
110911         , p_component_type_code     => l_component_type_code
110915         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
110912         , p_component_appl_id       => l_component_appl_id
110913         , p_amb_context_code        => l_amb_context_code
110914         , p_entity_code             => 'TRANSACTIONS'
110916         , p_side                    => 'NA'
110917         );
110918 
110919   END IF;
110920 
110921    l_segment := AcctDerRule_168(
110922            p_application_id           => p_application_id
110923          , p_ae_header_id             => l_ae_header_id 
110924 , p_source_3 => p_source_3
110925 , p_source_29 => p_source_29
110926          , x_transaction_coa_id       => l_adr_transaction_coa_id
110927          , x_accounting_coa_id        => l_adr_accounting_coa_id
110928          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
110929          , x_flex_value_set_id        => l_adr_flex_value_set_id
110930          , x_value_type_code          => l_adr_value_type_code
110931          , x_value_combination_id     => l_adr_value_combination_id
110932          , x_value_segment_code       => l_adr_value_segment_code
110933          , p_side                     => 'NA'
110934          , p_override_seg_flag        => 'Y'
110935    );
110936 
110937    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
110938 
110939       xla_ae_lines_pkg.set_segment(
110940           p_to_segment_code         => 'GL_BALANCING'
110944         , p_value_type_code         => l_adr_value_type_code
110941         , p_segment_value           => l_segment
110942         , p_from_segment_code       => l_adr_value_segment_code
110943         , p_from_combination_id     => l_adr_value_combination_id
110945         , p_transaction_coa_id      => l_adr_transaction_coa_id
110946         , p_accounting_coa_id       => l_adr_accounting_coa_id
110947         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
110948         , p_flex_value_set_id       => l_adr_flex_value_set_id
110949         , p_adr_code                => 'FA_EXPENSE_ACCT'
110950         , p_adr_type_code           => 'S'
110951         , p_component_type          => l_component_type
110952         , p_component_code          => l_component_code
110953         , p_component_type_code     => l_component_type_code
110954         , p_component_appl_id       => l_component_appl_id
110955         , p_amb_context_code        => l_amb_context_code
110956         , p_entity_code             => 'TRANSACTIONS'
110957         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
110958         , p_side                    => 'NA'
110959         );
110960 
110961   END IF;
110962 
110963    --
110964    --
110965    END IF;
110966    --
110967    -- Bug 4922099
110968    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
110969           (NVL(l_enc_upg_option, 'N') = 'O')
110970         ) AND
110971         (l_bflow_method_code = 'PRIOR_ENTRY')
110972       )
110973    THEN
110974       IF
110975       --
110976       1 = 2
110977       --
110978       THEN
110979       xla_accounting_err_pkg.build_message
110980                                     (p_appli_s_name            => 'XLA'
110981                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
110982                                     ,p_token_1                 => 'LINE_NUMBER'
110983                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
110984                                     ,p_token_2                 => 'LINE_TYPE_NAME'
110985                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
110986                                                                              l_component_type
110987                                                                             ,l_component_code
110988                                                                             ,l_component_type_code
110989                                                                             ,l_component_appl_id
110990                                                                             ,l_amb_context_code
110991                                                                             ,l_entity_code
110992                                                                             ,l_event_class_code
110993                                                                            )
110994                                     ,p_token_3                 => 'OWNER'
110995                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
110996                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
110997                                                                           ,p_lookup_code    => l_component_type_code
110998                                                                          )
110999                                     ,p_token_4                 => 'PRODUCT_NAME'
111000                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
111001                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
111002                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
111003                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
111004                                     ,p_ae_header_id            =>  NULL
111005                                        );
111006 
111007         IF (C_LEVEL_ERROR>= g_log_level) THEN
111008                  trace
111009                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
111010                       ,p_level    => C_LEVEL_ERROR
111011                       ,p_module   => l_log_module);
111012         END IF;
111013       END IF;
111014    END IF;
111015    --
111016    --
111017    ------------------------------------------------------------------------------------------------
111018    -- 4219869 Business Flow
111019    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
111020    -- Prior Entry.  Currently, the following code is always generated.
111021    ------------------------------------------------------------------------------------------------
111022    XLA_AE_LINES_PKG.ValidateCurrentLine;
111023 
111024    ------------------------------------------------------------------------------------
111025    -- 4219869 Business Flow
111026    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
111027    ------------------------------------------------------------------------------------
111028    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
111029 
111030    ----------------------------------------------------------------------------------
111031    -- 4219869 Business Flow
111032    -- Update journal entry status -- Need to generate this within IF <condition>
111033    ----------------------------------------------------------------------------------
111034    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
111035          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
111036          ,p_balance_type_code => l_balance_type_code
111037          );
111038 
111039    -------------------------------------------------------------------------------------------
111040    -- 4262811 - Generate the Accrual Reversal lines
111041    -------------------------------------------------------------------------------------------
111042    BEGIN
111046          l_acc_rev_flag := 'N';
111043       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
111044                               (g_array_event(p_event_id).array_value_num('header_index'));
111045       IF l_acc_rev_flag IS NULL THEN
111047       END IF;
111048    EXCEPTION
111049       WHEN OTHERS THEN
111050          l_acc_rev_flag := 'N';
111051    END;
111052    --
111053    IF (l_acc_rev_flag = 'Y') THEN
111054 
111055        -- 4645092  ------------------------------------------------------------------------------
111056        -- To allow MPA report to determine if it should generate report process
111057        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
111058        ------------------------------------------------------------------------------------------
111059 
111060        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
111061        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
111062    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
111063    -- call ADRs
111064    -- Bug 4922099
111065    --
111066    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
111067         (NVL(l_actual_upg_option, 'N') = 'O') OR
111068         (NVL(l_enc_upg_option, 'N') = 'O')
111069       )
111070    THEN
111071    NULL;
111072    --
111073    --
111074    
111075   l_ccid := AcctDerRule_173(
111076            p_application_id           => p_application_id
111077          , p_ae_header_id             => l_ae_header_id 
111078 , p_source_3 => p_source_3
111079 , p_source_30 => p_source_30
111080          , x_transaction_coa_id       => l_adr_transaction_coa_id
111081          , x_accounting_coa_id        => l_adr_accounting_coa_id
111082          , x_value_type_code          => l_adr_value_type_code
111083          , p_side                     => 'NA'
111084    );
111085 
111086    xla_ae_lines_pkg.set_ccid(
111087     p_code_combination_id          => l_ccid
111088   , p_value_type_code              => l_adr_value_type_code
111089   , p_transaction_coa_id           => l_adr_transaction_coa_id
111090   , p_accounting_coa_id            => l_adr_accounting_coa_id
111091   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
111092   , p_adr_type_code                => 'S'
111093   , p_component_type               => l_component_type
111094   , p_component_code               => l_component_code
111095   , p_component_type_code          => l_component_type_code
111096   , p_component_appl_id            => l_component_appl_id
111097   , p_amb_context_code             => l_amb_context_code
111098   , p_side                         => 'NA'
111099   );
111100 
111101 
111102    l_segment := AcctDerRule_151(
111103            p_application_id           => p_application_id
111104          , p_ae_header_id             => l_ae_header_id 
111105 , p_source_3 => p_source_3
111106 , p_source_12 => p_source_12
111107          , x_transaction_coa_id       => l_adr_transaction_coa_id
111108          , x_accounting_coa_id        => l_adr_accounting_coa_id
111109          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
111110          , x_flex_value_set_id        => l_adr_flex_value_set_id
111111          , x_value_type_code          => l_adr_value_type_code
111112          , x_value_combination_id     => l_adr_value_combination_id
111113          , x_value_segment_code       => l_adr_value_segment_code
111114          , p_side                     => 'NA'
111115          , p_override_seg_flag        => 'Y'
111116    );
111117 
111118    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
111119 
111120       xla_ae_lines_pkg.set_segment(
111121           p_to_segment_code         => 'GL_ACCOUNT'
111122         , p_segment_value           => l_segment
111123         , p_from_segment_code       => l_adr_value_segment_code
111124         , p_from_combination_id     => l_adr_value_combination_id
111125         , p_value_type_code         => l_adr_value_type_code
111126         , p_transaction_coa_id      => l_adr_transaction_coa_id
111127         , p_accounting_coa_id       => l_adr_accounting_coa_id
111128         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
111129         , p_flex_value_set_id       => l_adr_flex_value_set_id
111130         , p_adr_code                => 'FA_COST_OF_REMOVAL_CLR_SEGMENT'
111131         , p_adr_type_code           => 'S'
111132         , p_component_type          => l_component_type
111133         , p_component_code          => l_component_code
111134         , p_component_type_code     => l_component_type_code
111135         , p_component_appl_id       => l_component_appl_id
111136         , p_amb_context_code        => l_amb_context_code
111137         , p_entity_code             => 'TRANSACTIONS'
111138         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
111139         , p_side                    => 'NA'
111140         );
111141 
111142   END IF;
111143 
111144    l_segment := AcctDerRule_168(
111145            p_application_id           => p_application_id
111146          , p_ae_header_id             => l_ae_header_id 
111147 , p_source_3 => p_source_3
111148 , p_source_29 => p_source_29
111149          , x_transaction_coa_id       => l_adr_transaction_coa_id
111150          , x_accounting_coa_id        => l_adr_accounting_coa_id
111151          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
111152          , x_flex_value_set_id        => l_adr_flex_value_set_id
111153          , x_value_type_code          => l_adr_value_type_code
111154          , x_value_combination_id     => l_adr_value_combination_id
111155          , x_value_segment_code       => l_adr_value_segment_code
111156          , p_side                     => 'NA'
111157          , p_override_seg_flag        => 'Y'
111158    );
111159 
111160    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
111161 
111162       xla_ae_lines_pkg.set_segment(
111163           p_to_segment_code         => 'GL_BALANCING'
111164         , p_segment_value           => l_segment
111168         , p_transaction_coa_id      => l_adr_transaction_coa_id
111165         , p_from_segment_code       => l_adr_value_segment_code
111166         , p_from_combination_id     => l_adr_value_combination_id
111167         , p_value_type_code         => l_adr_value_type_code
111169         , p_accounting_coa_id       => l_adr_accounting_coa_id
111170         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
111171         , p_flex_value_set_id       => l_adr_flex_value_set_id
111172         , p_adr_code                => 'FA_EXPENSE_ACCT'
111173         , p_adr_type_code           => 'S'
111177         , p_component_appl_id       => l_component_appl_id
111174         , p_component_type          => l_component_type
111175         , p_component_code          => l_component_code
111176         , p_component_type_code     => l_component_type_code
111178         , p_amb_context_code        => l_amb_context_code
111179         , p_entity_code             => 'TRANSACTIONS'
111180         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
111181         , p_side                    => 'NA'
111182         );
111183 
111184   END IF;
111185 
111186    --
111187    --
111188    END IF;
111189 
111190        --
111191        -- Update the line information that should be overwritten
111192        --
111193        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
111194                                          p_header_num   => 1);
111195        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
111196 
111197        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
111198 
111199        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
111200           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
111201        END IF;
111202 
111203       --
111204       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
111205       --
111206       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
111207           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
111208       ELSE
111209           ---------------------------------------------------------------------------------------------------
111210           -- 4262811a Switch Sign
111211           ---------------------------------------------------------------------------------------------------
111212           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
111213           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
111214                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
111215           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
111216                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
111217           -- 5132302
111218           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
111219                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
111220 
111221       END IF;
111222 
111223       -- 4955764
111224       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
111225       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
111226 
111227 
111228       XLA_AE_LINES_PKG.ValidateCurrentLine;
111229       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
111230 
111231       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
111232                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
111233                ,p_balance_type_code => l_balance_type_code);
111234 
111235    END IF;
111236 
111237    -----------------------------------------------------------------------------------------
111238    -- 4262811 Multiperiod Accounting
111239    -----------------------------------------------------------------------------------------
111240      -- No MPA option is assigned.
111241 
111242 
111243 END IF;
111244 END IF;
111245 --
111246 
111247 --
111248 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
111249    trace
111250       (p_msg      => 'END of AcctLineType_309'
111251       ,p_level    => C_LEVEL_PROCEDURE
111252       ,p_module   => l_log_module);
111253 END IF;
111254 --
111255 EXCEPTION
111256   WHEN xla_exceptions_pkg.application_exception THEN
111257       RAISE;
111258   WHEN OTHERS THEN
111259        xla_exceptions_pkg.raise_message
111260            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_309');
111261 END AcctLineType_309;
111262 --
111263 
111264 ---------------------------------------
111265 --
111266 -- PRIVATE FUNCTION
111267 --         AcctLineType_310
111268 --
111272  ,p_event_id              IN NUMBER
111269 ---------------------------------------
111270 PROCEDURE AcctLineType_310 (
111271   p_application_id        IN NUMBER
111273  ,p_calculate_acctd_flag  IN VARCHAR2
111274  ,p_calculate_g_l_flag    IN VARCHAR2
111275  ,p_actual_flag           IN OUT VARCHAR2
111276  ,p_balance_type_code     OUT VARCHAR2
111277  ,p_gain_or_loss_ref      OUT VARCHAR2
111278  
111279 --Period Close Date
111280  , p_source_1            IN DATE
111281 --Generated Code Combination Identifier
111282  , p_source_3            IN NUMBER
111283 --Proceeds Of Sale Clearing Account
111284  , p_source_23            IN VARCHAR2
111285 --Expense Account Code Combination Identifier
111286  , p_source_29            IN NUMBER
111287 --Default Code Combination Identifier
111288  , p_source_30            IN NUMBER
111289 --Adjustment Type
111290  , p_source_35            IN VARCHAR2
111291 --Transaction Header Identifier
111292  , p_source_36            IN NUMBER
111293 --Adjustment Line Identifier
111294  , p_source_37            IN NUMBER
111295 --Distribution Type Code
111296  , p_source_38            IN VARCHAR2
111297 --Entered Amount
111298  , p_source_39            IN NUMBER
111299 --Currency Code
111300  , p_source_40            IN VARCHAR2
111301 )
111302 IS
111303 
111304 l_component_type              VARCHAR2(80);
111305 l_component_code              VARCHAR2(30);
111306 l_component_type_code         VARCHAR2(1);
111307 l_component_appl_id           INTEGER;
111308 l_amb_context_code            VARCHAR2(30);
111309 l_entity_code                 VARCHAR2(30);
111310 l_event_class_code            VARCHAR2(30);
111311 l_ae_header_id                NUMBER;
111312 l_event_type_code             VARCHAR2(30);
111313 l_line_definition_code        VARCHAR2(30);
111314 l_line_definition_owner_code  VARCHAR2(1);
111315 --
111316 -- adr variables
111317 l_segment                     VARCHAR2(30);
111318 l_ccid                        NUMBER;
111319 l_adr_transaction_coa_id      NUMBER;
111320 l_adr_accounting_coa_id       NUMBER;
111321 l_adr_flexfield_segment_code  VARCHAR2(30);
111322 l_adr_flex_value_set_id       NUMBER;
111323 l_adr_value_type_code         VARCHAR2(30);
111324 l_adr_value_combination_id    NUMBER;
111325 l_adr_value_segment_code      VARCHAR2(30);
111326 
111327 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
111328 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
111329 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
111333 l_entered_amt_idx             NUMBER;
111330 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
111331 
111332 -- 4262811 Variables ------------------------------------------------------------------------------------------
111334 l_accted_amt_idx              NUMBER;
111335 l_acc_rev_flag                VARCHAR2(1);
111336 l_accrual_line_num            NUMBER;
111337 l_tmp_amt                     NUMBER;
111338 l_acc_rev_natural_side_code   VARCHAR2(1);
111339 
111340 l_num_entries                 NUMBER;
111341 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
111342 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
111343 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
111344 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
111345 l_recog_line_1                NUMBER;
111346 l_recog_line_2                NUMBER;
111347 
111348 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
111349 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
111350 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
111351 
111352 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
111353 
111354 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
111355 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
111356 
111357 ---------------------------------------------------------------------------------------------------------------
111358 
111359 
111360 --
111361 -- bulk performance
111362 --
111363 l_balance_type_code           VARCHAR2(1);
111364 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
111365 l_log_module                  VARCHAR2(240);
111366 
111367 --
111368 -- Upgrade strategy
111369 --
111370 l_actual_upg_option           VARCHAR2(1);
111371 l_enc_upg_option           VARCHAR2(1);
111372 
111373 --
111374 BEGIN
111375 --
111376 IF g_log_enabled THEN
111377       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_310';
111378 END IF;
111379 --
111380 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
111381 
111382       trace
111383          (p_msg      => 'BEGIN of AcctLineType_310'
111384          ,p_level    => C_LEVEL_PROCEDURE
111385          ,p_module   => l_log_module);
111386 
111387 END IF;
111388 --
111392 l_component_appl_id          :=  140;
111389 l_component_type             := 'AMB_JLT';
111390 l_component_code             := 'FA_RET_ADJ_PROC_SALE_CLR';
111391 l_component_type_code        := 'S';
111393 l_amb_context_code           := 'DEFAULT';
111394 l_entity_code                := 'TRANSACTIONS';
111395 l_event_class_code           := 'RETIREMENT_ADJUSTMENTS';
111396 l_event_type_code            := 'RETIREMENT_ADJUSTMENTS_ALL';
111397 l_line_definition_owner_code := 'S';
111398 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR20';
111399 --
111400 l_balance_type_code          := 'A';
111401 l_segment                     := NULL;
111402 l_ccid                        := NULL;
111403 l_adr_transaction_coa_id      := NULL;
111404 l_adr_accounting_coa_id       := NULL;
111405 l_adr_flexfield_segment_code  := NULL;
111406 l_adr_flex_value_set_id       := NULL;
111407 l_adr_value_type_code         := NULL;
111408 l_adr_value_combination_id    := NULL;
111409 l_adr_value_segment_code      := NULL;
111410 
111411 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
111412 l_bflow_class_code           := '';    -- 4219869 Business Flow
111413 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
111414 l_budgetary_control_flag     := 'N';
111415 
111416 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
111417 l_bflow_applied_to_amt       := NULL; -- 5132302
111418 l_entered_amt_idx            := NULL;          -- 4262811
111419 l_accted_amt_idx             := NULL;          -- 4262811
111420 l_acc_rev_flag               := NULL;          -- 4262811
111421 l_accrual_line_num           := NULL;          -- 4262811
111422 l_tmp_amt                    := NULL;          -- 4262811
111423 --
111424  
111425 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
111426     l_balance_type_code <> 'B' THEN
111427 IF NVL(p_source_35,'
111428 ') =  'PROCEEDS'
111429  THEN 
111430 
111431    --
111432    XLA_AE_LINES_PKG.SetNewLine;
111433 
111434    p_balance_type_code          := l_balance_type_code;
111435    -- set the flag so later we will know whether the gain loss line needs to be created
111436    
111437    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
111438      p_actual_flag :='A';
111439    END IF;
111440 
111441    --
111442    -- bulk performance
111443    --
111444    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
111445                                       p_header_num   => 0); -- 4262811
111446    --
111447    -- set accounting line options
111448    --
111449    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
111450            p_natural_side_code          => 'D'
111451          , p_gain_or_loss_flag          => 'N'
111452          , p_gl_transfer_mode_code      => 'S'
111453          , p_acct_entry_type_code       => 'A'
111454          , p_switch_side_flag           => 'Y'
111455          , p_merge_duplicate_code       => 'N'
111456          );
111457    --
111458    l_acc_rev_natural_side_code := 'C';  -- 4262811
111459    -- 
111460    --
111461    -- set accounting line type info
111462    --
111463    xla_ae_lines_pkg.SetAcctLineType
111464       (p_component_type             => l_component_type
111465       ,p_event_type_code            => l_event_type_code
111466       ,p_line_definition_owner_code => l_line_definition_owner_code
111467       ,p_line_definition_code       => l_line_definition_code
111468       ,p_accounting_line_code       => l_component_code
111469       ,p_accounting_line_type_code  => l_component_type_code
111470       ,p_accounting_line_appl_id    => l_component_appl_id
111471       ,p_amb_context_code           => l_amb_context_code
111472       ,p_entity_code                => l_entity_code
111473       ,p_event_class_code           => l_event_class_code);
111474    --
111475    -- set accounting class
111476    --
111477    xla_ae_lines_pkg.SetAcctClass(
111478            p_accounting_class_code  => 'ASSET'
111479          , p_ae_header_id           => l_ae_header_id
111480          );
111481 
111482    --
111483    -- set rounding class
111484    --
111485    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
111486                       'ASSET';
111487 
111488    --
111489    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
111493    --
111490    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
111491    --
111492    -- bulk performance
111494    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
111495 
111496    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
111497       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
111498 
111499    -- 4955764
111500    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
111504    
111501       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
111502 
111503    -- 4458381 Public Sector Enh
111505    --
111506    -- set accounting attributes for the line type
111507    --
111508    l_entered_amt_idx := 4;
111509    l_accted_amt_idx  := 6;
111510    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
111511    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
111512    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
111513    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
111514    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
111515    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
111516    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
111517    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
111518    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
111519    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
111520    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
111521    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
111522    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
111523 
111524    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
111525    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
111526 
111527    ---------------------------------------------------------------------------------------------------------------
111528    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
111529    ---------------------------------------------------------------------------------------------------------------
111530    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
111531 
111532    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
111533    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
111534 
111535    IF xla_accounting_cache_pkg.GetValueChar
111536          (p_source_code         => 'LEDGER_CATEGORY_CODE'
111537          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
111538    AND l_bflow_method_code = 'PRIOR_ENTRY'
111539 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
111540    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
111541          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
111542        )
111543    THEN
111544          xla_ae_lines_pkg.BflowUpgEntry
111545            (p_business_method_code    => l_bflow_method_code
111546            ,p_business_class_code     => l_bflow_class_code
111547            ,p_balance_type            => l_balance_type_code);
111548    ELSE
111549       NULL;
111550 -- No business flow processing for business flow method of NONE.
111551    END IF;
111552 
111553    --
111554    -- call analytical criteria
111555    --
111556    
111557    --
111558    -- call description
111559    --
111560    
111561 xla_ae_lines_pkg.SetLineDescription(
111562    p_ae_header_id => l_ae_header_id
111563   ,p_description  => Description_88 (
111564      p_application_id         => p_application_id
111565    , p_ae_header_id           => l_ae_header_id 
111566 , p_source_1 => p_source_1
111567    )
111568 );
111569 
111570 
111571    --
111572    -- call ADRs
111573    -- Bug 4922099
111574    --
111575    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
111576         (NVL(l_actual_upg_option, 'N') = 'O') OR
111577         (NVL(l_enc_upg_option, 'N') = 'O')
111578       )
111579    THEN
111580    NULL;
111581    --
111582    --
111583    
111584   l_ccid := AcctDerRule_173(
111585            p_application_id           => p_application_id
111586          , p_ae_header_id             => l_ae_header_id 
111587 , p_source_3 => p_source_3
111588 , p_source_30 => p_source_30
111589          , x_transaction_coa_id       => l_adr_transaction_coa_id
111590          , x_accounting_coa_id        => l_adr_accounting_coa_id
111591          , x_value_type_code          => l_adr_value_type_code
111592          , p_side                     => 'NA'
111593    );
111594 
111595    xla_ae_lines_pkg.set_ccid(
111596     p_code_combination_id          => l_ccid
111597   , p_value_type_code              => l_adr_value_type_code
111598   , p_transaction_coa_id           => l_adr_transaction_coa_id
111599   , p_accounting_coa_id            => l_adr_accounting_coa_id
111600   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
111601   , p_adr_type_code                => 'S'
111602   , p_component_type               => l_component_type
111603   , p_component_code               => l_component_code
111604   , p_component_type_code          => l_component_type_code
111605   , p_component_appl_id            => l_component_appl_id
111606   , p_amb_context_code             => l_amb_context_code
111607   , p_side                         => 'NA'
111608   );
111609 
111610 
111611    l_segment := AcctDerRule_168(
111612            p_application_id           => p_application_id
111613          , p_ae_header_id             => l_ae_header_id 
111614 , p_source_3 => p_source_3
111615 , p_source_29 => p_source_29
111616          , x_transaction_coa_id       => l_adr_transaction_coa_id
111617          , x_accounting_coa_id        => l_adr_accounting_coa_id
111618          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
111619          , x_flex_value_set_id        => l_adr_flex_value_set_id
111620          , x_value_type_code          => l_adr_value_type_code
111621          , x_value_combination_id     => l_adr_value_combination_id
111622          , x_value_segment_code       => l_adr_value_segment_code
111623          , p_side                     => 'NA'
111624          , p_override_seg_flag        => 'Y'
111625    );
111626 
111630           p_to_segment_code         => 'GL_BALANCING'
111627    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
111628 
111629       xla_ae_lines_pkg.set_segment(
111631         , p_segment_value           => l_segment
111632         , p_from_segment_code       => l_adr_value_segment_code
111633         , p_from_combination_id     => l_adr_value_combination_id
111634         , p_value_type_code         => l_adr_value_type_code
111638         , p_flex_value_set_id       => l_adr_flex_value_set_id
111635         , p_transaction_coa_id      => l_adr_transaction_coa_id
111636         , p_accounting_coa_id       => l_adr_accounting_coa_id
111637         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
111639         , p_adr_code                => 'FA_EXPENSE_ACCT'
111640         , p_adr_type_code           => 'S'
111641         , p_component_type          => l_component_type
111642         , p_component_code          => l_component_code
111643         , p_component_type_code     => l_component_type_code
111644         , p_component_appl_id       => l_component_appl_id
111645         , p_amb_context_code        => l_amb_context_code
111646         , p_entity_code             => 'TRANSACTIONS'
111647         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
111648         , p_side                    => 'NA'
111649         );
111650 
111651   END IF;
111652 
111653    l_segment := AcctDerRule_161(
111654            p_application_id           => p_application_id
111655          , p_ae_header_id             => l_ae_header_id 
111656 , p_source_3 => p_source_3
111657 , p_source_23 => p_source_23
111658          , x_transaction_coa_id       => l_adr_transaction_coa_id
111659          , x_accounting_coa_id        => l_adr_accounting_coa_id
111660          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
111661          , x_flex_value_set_id        => l_adr_flex_value_set_id
111662          , x_value_type_code          => l_adr_value_type_code
111663          , x_value_combination_id     => l_adr_value_combination_id
111664          , x_value_segment_code       => l_adr_value_segment_code
111665          , p_side                     => 'NA'
111666          , p_override_seg_flag        => 'Y'
111667    );
111668 
111669    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
111670 
111671       xla_ae_lines_pkg.set_segment(
111672           p_to_segment_code         => 'GL_ACCOUNT'
111673         , p_segment_value           => l_segment
111674         , p_from_segment_code       => l_adr_value_segment_code
111675         , p_from_combination_id     => l_adr_value_combination_id
111676         , p_value_type_code         => l_adr_value_type_code
111677         , p_transaction_coa_id      => l_adr_transaction_coa_id
111678         , p_accounting_coa_id       => l_adr_accounting_coa_id
111679         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
111680         , p_flex_value_set_id       => l_adr_flex_value_set_id
111681         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
111682         , p_adr_type_code           => 'S'
111683         , p_component_type          => l_component_type
111684         , p_component_code          => l_component_code
111685         , p_component_type_code     => l_component_type_code
111686         , p_component_appl_id       => l_component_appl_id
111687         , p_amb_context_code        => l_amb_context_code
111688         , p_entity_code             => 'TRANSACTIONS'
111689         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
111690         , p_side                    => 'NA'
111691         );
111692 
111693   END IF;
111694 
111695    --
111696    --
111697    END IF;
111698    --
111699    -- Bug 4922099
111700    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
111701           (NVL(l_enc_upg_option, 'N') = 'O')
111702         ) AND
111703         (l_bflow_method_code = 'PRIOR_ENTRY')
111704       )
111705    THEN
111706       IF
111707       --
111708       1 = 2
111709       --
111710       THEN
111711       xla_accounting_err_pkg.build_message
111712                                     (p_appli_s_name            => 'XLA'
111713                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
111714                                     ,p_token_1                 => 'LINE_NUMBER'
111715                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
111716                                     ,p_token_2                 => 'LINE_TYPE_NAME'
111717                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
111718                                                                              l_component_type
111719                                                                             ,l_component_code
111720                                                                             ,l_component_type_code
111721                                                                             ,l_component_appl_id
111725                                                                            )
111722                                                                             ,l_amb_context_code
111723                                                                             ,l_entity_code
111724                                                                             ,l_event_class_code
111726                                     ,p_token_3                 => 'OWNER'
111727                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
111728                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
111729                                                                           ,p_lookup_code    => l_component_type_code
111730                                                                          )
111731                                     ,p_token_4                 => 'PRODUCT_NAME'
111732                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
111733                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
111734                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
111735                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
111736                                     ,p_ae_header_id            =>  NULL
111737                                        );
111738 
111739         IF (C_LEVEL_ERROR>= g_log_level) THEN
111740                  trace
111741                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
111742                       ,p_level    => C_LEVEL_ERROR
111743                       ,p_module   => l_log_module);
111744         END IF;
111745       END IF;
111746    END IF;
111747    --
111748    --
111749    ------------------------------------------------------------------------------------------------
111750    -- 4219869 Business Flow
111751    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
111752    -- Prior Entry.  Currently, the following code is always generated.
111753    ------------------------------------------------------------------------------------------------
111754    XLA_AE_LINES_PKG.ValidateCurrentLine;
111755 
111756    ------------------------------------------------------------------------------------
111757    -- 4219869 Business Flow
111758    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
111759    ------------------------------------------------------------------------------------
111760    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
111761 
111762    ----------------------------------------------------------------------------------
111763    -- 4219869 Business Flow
111764    -- Update journal entry status -- Need to generate this within IF <condition>
111765    ----------------------------------------------------------------------------------
111766    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
111767          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
111768          ,p_balance_type_code => l_balance_type_code
111769          );
111770 
111771    -------------------------------------------------------------------------------------------
111772    -- 4262811 - Generate the Accrual Reversal lines
111773    -------------------------------------------------------------------------------------------
111774    BEGIN
111775       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
111776                               (g_array_event(p_event_id).array_value_num('header_index'));
111777       IF l_acc_rev_flag IS NULL THEN
111778          l_acc_rev_flag := 'N';
111779       END IF;
111780    EXCEPTION
111781       WHEN OTHERS THEN
111782          l_acc_rev_flag := 'N';
111783    END;
111784    --
111785    IF (l_acc_rev_flag = 'Y') THEN
111786 
111787        -- 4645092  ------------------------------------------------------------------------------
111788        -- To allow MPA report to determine if it should generate report process
111789        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
111790        ------------------------------------------------------------------------------------------
111791 
111792        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
111793        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
111794    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
111795    -- call ADRs
111796    -- Bug 4922099
111797    --
111798    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
111799         (NVL(l_actual_upg_option, 'N') = 'O') OR
111800         (NVL(l_enc_upg_option, 'N') = 'O')
111801       )
111802    THEN
111803    NULL;
111804    --
111805    --
111806    
111807   l_ccid := AcctDerRule_173(
111808            p_application_id           => p_application_id
111809          , p_ae_header_id             => l_ae_header_id 
111810 , p_source_3 => p_source_3
111811 , p_source_30 => p_source_30
111812          , x_transaction_coa_id       => l_adr_transaction_coa_id
111813          , x_accounting_coa_id        => l_adr_accounting_coa_id
111814          , x_value_type_code          => l_adr_value_type_code
111815          , p_side                     => 'NA'
111816    );
111817 
111818    xla_ae_lines_pkg.set_ccid(
111819     p_code_combination_id          => l_ccid
111820   , p_value_type_code              => l_adr_value_type_code
111821   , p_transaction_coa_id           => l_adr_transaction_coa_id
111822   , p_accounting_coa_id            => l_adr_accounting_coa_id
111823   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
111824   , p_adr_type_code                => 'S'
111825   , p_component_type               => l_component_type
111826   , p_component_code               => l_component_code
111827   , p_component_type_code          => l_component_type_code
111828   , p_component_appl_id            => l_component_appl_id
111829   , p_amb_context_code             => l_amb_context_code
111833 
111830   , p_side                         => 'NA'
111831   );
111832 
111834    l_segment := AcctDerRule_168(
111835            p_application_id           => p_application_id
111836          , p_ae_header_id             => l_ae_header_id 
111837 , p_source_3 => p_source_3
111838 , p_source_29 => p_source_29
111839          , x_transaction_coa_id       => l_adr_transaction_coa_id
111840          , x_accounting_coa_id        => l_adr_accounting_coa_id
111841          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
111842          , x_flex_value_set_id        => l_adr_flex_value_set_id
111843          , x_value_type_code          => l_adr_value_type_code
111844          , x_value_combination_id     => l_adr_value_combination_id
111845          , x_value_segment_code       => l_adr_value_segment_code
111846          , p_side                     => 'NA'
111847          , p_override_seg_flag        => 'Y'
111848    );
111849 
111850    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
111851 
111852       xla_ae_lines_pkg.set_segment(
111853           p_to_segment_code         => 'GL_BALANCING'
111854         , p_segment_value           => l_segment
111855         , p_from_segment_code       => l_adr_value_segment_code
111856         , p_from_combination_id     => l_adr_value_combination_id
111857         , p_value_type_code         => l_adr_value_type_code
111858         , p_transaction_coa_id      => l_adr_transaction_coa_id
111859         , p_accounting_coa_id       => l_adr_accounting_coa_id
111860         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
111861         , p_flex_value_set_id       => l_adr_flex_value_set_id
111862         , p_adr_code                => 'FA_EXPENSE_ACCT'
111863         , p_adr_type_code           => 'S'
111864         , p_component_type          => l_component_type
111865         , p_component_code          => l_component_code
111866         , p_component_type_code     => l_component_type_code
111867         , p_component_appl_id       => l_component_appl_id
111868         , p_amb_context_code        => l_amb_context_code
111869         , p_entity_code             => 'TRANSACTIONS'
111870         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
111871         , p_side                    => 'NA'
111872         );
111873 
111874   END IF;
111875 
111876    l_segment := AcctDerRule_161(
111877            p_application_id           => p_application_id
111878          , p_ae_header_id             => l_ae_header_id 
111879 , p_source_3 => p_source_3
111880 , p_source_23 => p_source_23
111881          , x_transaction_coa_id       => l_adr_transaction_coa_id
111882          , x_accounting_coa_id        => l_adr_accounting_coa_id
111883          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
111884          , x_flex_value_set_id        => l_adr_flex_value_set_id
111885          , x_value_type_code          => l_adr_value_type_code
111886          , x_value_combination_id     => l_adr_value_combination_id
111887          , x_value_segment_code       => l_adr_value_segment_code
111888          , p_side                     => 'NA'
111889          , p_override_seg_flag        => 'Y'
111890    );
111891 
111892    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
111893 
111894       xla_ae_lines_pkg.set_segment(
111895           p_to_segment_code         => 'GL_ACCOUNT'
111896         , p_segment_value           => l_segment
111900         , p_transaction_coa_id      => l_adr_transaction_coa_id
111897         , p_from_segment_code       => l_adr_value_segment_code
111898         , p_from_combination_id     => l_adr_value_combination_id
111899         , p_value_type_code         => l_adr_value_type_code
111901         , p_accounting_coa_id       => l_adr_accounting_coa_id
111902         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
111903         , p_flex_value_set_id       => l_adr_flex_value_set_id
111904         , p_adr_code                => 'FA_PROC_OF_SALE_CLR_SEGMENT'
111905         , p_adr_type_code           => 'S'
111906         , p_component_type          => l_component_type
111907         , p_component_code          => l_component_code
111908         , p_component_type_code     => l_component_type_code
111909         , p_component_appl_id       => l_component_appl_id
111910         , p_amb_context_code        => l_amb_context_code
111911         , p_entity_code             => 'TRANSACTIONS'
111912         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
111913         , p_side                    => 'NA'
111914         );
111915 
111916   END IF;
111917 
111918    --
111919    --
111920    END IF;
111921 
111922        --
111923        -- Update the line information that should be overwritten
111924        --
111925        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
111926                                          p_header_num   => 1);
111927        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
111928 
111929        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
111930 
111931        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
111932           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
111933        END IF;
111934 
111935       --
111936       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
111937       --
111938       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
111939           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
111940       ELSE
111941           ---------------------------------------------------------------------------------------------------
111942           -- 4262811a Switch Sign
111943           ---------------------------------------------------------------------------------------------------
111944           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
111945           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
111946                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
111947           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
111948                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
111949           -- 5132302
111950           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
111951                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
111955       -- 4955764
111952 
111953       END IF;
111954 
111956       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
111957       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
111958 
111959 
111960       XLA_AE_LINES_PKG.ValidateCurrentLine;
111961       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
111962 
111963       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
111964                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
111965                ,p_balance_type_code => l_balance_type_code);
111966 
111967    END IF;
111968 
111969    -----------------------------------------------------------------------------------------
111970    -- 4262811 Multiperiod Accounting
111971    -----------------------------------------------------------------------------------------
111972      -- No MPA option is assigned.
111973 
111974 
111975 END IF;
111976 END IF;
111977 --
111978 
111979 --
111980 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
111981    trace
111982       (p_msg      => 'END of AcctLineType_310'
111983       ,p_level    => C_LEVEL_PROCEDURE
111984       ,p_module   => l_log_module);
111985 END IF;
111986 --
111987 EXCEPTION
111988   WHEN xla_exceptions_pkg.application_exception THEN
111989       RAISE;
111990   WHEN OTHERS THEN
111991        xla_exceptions_pkg.raise_message
111992            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_310');
111993 END AcctLineType_310;
111994 --
111995 
111996 ---------------------------------------
111997 --
111998 -- PRIVATE FUNCTION
111999 --         AcctLineType_311
112000 --
112001 ---------------------------------------
112002 PROCEDURE AcctLineType_311 (
112003   p_application_id        IN NUMBER
112004  ,p_event_id              IN NUMBER
112005  ,p_calculate_acctd_flag  IN VARCHAR2
112006  ,p_calculate_g_l_flag    IN VARCHAR2
112007  ,p_actual_flag           IN OUT VARCHAR2
112008  ,p_balance_type_code     OUT VARCHAR2
112009  ,p_gain_or_loss_ref      OUT VARCHAR2
112010  
112011 --Period Close Date
112012  , p_source_1            IN DATE
112013 --Generated Code Combination Identifier
112014  , p_source_3            IN NUMBER
112015 --Depreciation Reserve Account
112016  , p_source_10            IN VARCHAR2
112017 --Generated Offset Code Combination Identifier
112018  , p_source_17            IN NUMBER
112019 --Expense Account Code Combination Identifier
112020  , p_source_29            IN NUMBER
112021 --Default Code Combination Identifier
112022  , p_source_30            IN NUMBER
112023 --Adjustment Type
112024  , p_source_35            IN VARCHAR2
112025 --Transaction Header Identifier
112026  , p_source_36            IN NUMBER
112027 --Adjustment Line Identifier
112028  , p_source_37            IN NUMBER
112029 --Distribution Type Code
112030  , p_source_38            IN VARCHAR2
112031 --Entered Amount
112032  , p_source_39            IN NUMBER
112033 --Currency Code
112034  , p_source_40            IN VARCHAR2
112035 )
112036 IS
112037 
112038 l_component_type              VARCHAR2(80);
112039 l_component_code              VARCHAR2(30);
112040 l_component_type_code         VARCHAR2(1);
112041 l_component_appl_id           INTEGER;
112042 l_amb_context_code            VARCHAR2(30);
112043 l_entity_code                 VARCHAR2(30);
112044 l_event_class_code            VARCHAR2(30);
112045 l_ae_header_id                NUMBER;
112046 l_event_type_code             VARCHAR2(30);
112047 l_line_definition_code        VARCHAR2(30);
112048 l_line_definition_owner_code  VARCHAR2(1);
112049 --
112050 -- adr variables
112051 l_segment                     VARCHAR2(30);
112052 l_ccid                        NUMBER;
112053 l_adr_transaction_coa_id      NUMBER;
112054 l_adr_accounting_coa_id       NUMBER;
112055 l_adr_flexfield_segment_code  VARCHAR2(30);
112056 l_adr_flex_value_set_id       NUMBER;
112057 l_adr_value_type_code         VARCHAR2(30);
112058 l_adr_value_combination_id    NUMBER;
112059 l_adr_value_segment_code      VARCHAR2(30);
112060 
112061 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
112062 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
112063 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
112064 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
112065 
112066 -- 4262811 Variables ------------------------------------------------------------------------------------------
112067 l_entered_amt_idx             NUMBER;
112068 l_accted_amt_idx              NUMBER;
112069 l_acc_rev_flag                VARCHAR2(1);
112070 l_accrual_line_num            NUMBER;
112071 l_tmp_amt                     NUMBER;
112072 l_acc_rev_natural_side_code   VARCHAR2(1);
112073 
112074 l_num_entries                 NUMBER;
112075 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
112076 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
112077 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
112078 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
112079 l_recog_line_1                NUMBER;
112080 l_recog_line_2                NUMBER;
112081 
112082 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
112083 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
112084 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
112085 
112086 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
112087 
112088 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
112089 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
112090 
112091 ---------------------------------------------------------------------------------------------------------------
112092 
112093 
112097 l_balance_type_code           VARCHAR2(1);
112094 --
112095 -- bulk performance
112096 --
112098 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
112099 l_log_module                  VARCHAR2(240);
112100 
112101 --
112102 -- Upgrade strategy
112103 --
112104 l_actual_upg_option           VARCHAR2(1);
112105 l_enc_upg_option           VARCHAR2(1);
112106 
112107 --
112108 BEGIN
112109 --
112110 IF g_log_enabled THEN
112111       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_311';
112112 END IF;
112113 --
112114 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
112115 
112116       trace
112117          (p_msg      => 'BEGIN of AcctLineType_311'
112118          ,p_level    => C_LEVEL_PROCEDURE
112119          ,p_module   => l_log_module);
112120 
112121 END IF;
112122 --
112123 l_component_type             := 'AMB_JLT';
112124 l_component_code             := 'FA_RET_ADJ_RES';
112125 l_component_type_code        := 'S';
112126 l_component_appl_id          :=  140;
112127 l_amb_context_code           := 'DEFAULT';
112128 l_entity_code                := 'TRANSACTIONS';
112129 l_event_class_code           := 'RETIREMENT_ADJUSTMENTS';
112130 l_event_type_code            := 'RETIREMENT_ADJUSTMENTS_ALL';
112131 l_line_definition_owner_code := 'S';
112132 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR20';
112133 --
112134 l_balance_type_code          := 'A';
112135 l_segment                     := NULL;
112136 l_ccid                        := NULL;
112137 l_adr_transaction_coa_id      := NULL;
112138 l_adr_accounting_coa_id       := NULL;
112139 l_adr_flexfield_segment_code  := NULL;
112140 l_adr_flex_value_set_id       := NULL;
112141 l_adr_value_type_code         := NULL;
112142 l_adr_value_combination_id    := NULL;
112143 l_adr_value_segment_code      := NULL;
112144 
112145 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
112146 l_bflow_class_code           := '';    -- 4219869 Business Flow
112147 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
112148 l_budgetary_control_flag     := 'N';
112149 
112150 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
112151 l_bflow_applied_to_amt       := NULL; -- 5132302
112152 l_entered_amt_idx            := NULL;          -- 4262811
112153 l_accted_amt_idx             := NULL;          -- 4262811
112154 l_acc_rev_flag               := NULL;          -- 4262811
112155 l_accrual_line_num           := NULL;          -- 4262811
112156 l_tmp_amt                    := NULL;          -- 4262811
112157 --
112158  
112159 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
112160     l_balance_type_code <> 'B' THEN
112161 IF NVL(p_source_35,'
112162 ') =  'RESERVE'
112163  THEN 
112164 
112165    --
112166    XLA_AE_LINES_PKG.SetNewLine;
112167 
112168    p_balance_type_code          := l_balance_type_code;
112169    -- set the flag so later we will know whether the gain loss line needs to be created
112170    
112171    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
112172      p_actual_flag :='A';
112173    END IF;
112174 
112175    --
112176    -- bulk performance
112177    --
112178    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
112179                                       p_header_num   => 0); -- 4262811
112180    --
112181    -- set accounting line options
112182    --
112183    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
112184            p_natural_side_code          => 'C'
112185          , p_gain_or_loss_flag          => 'N'
112186          , p_gl_transfer_mode_code      => 'S'
112187          , p_acct_entry_type_code       => 'A'
112188          , p_switch_side_flag           => 'Y'
112189          , p_merge_duplicate_code       => 'N'
112190          );
112191    --
112192    l_acc_rev_natural_side_code := 'D';  -- 4262811
112193    -- 
112194    --
112195    -- set accounting line type info
112196    --
112197    xla_ae_lines_pkg.SetAcctLineType
112198       (p_component_type             => l_component_type
112199       ,p_event_type_code            => l_event_type_code
112200       ,p_line_definition_owner_code => l_line_definition_owner_code
112201       ,p_line_definition_code       => l_line_definition_code
112202       ,p_accounting_line_code       => l_component_code
112203       ,p_accounting_line_type_code  => l_component_type_code
112204       ,p_accounting_line_appl_id    => l_component_appl_id
112205       ,p_amb_context_code           => l_amb_context_code
112206       ,p_entity_code                => l_entity_code
112207       ,p_event_class_code           => l_event_class_code);
112208    --
112209    -- set accounting class
112210    --
112211    xla_ae_lines_pkg.SetAcctClass(
112212            p_accounting_class_code  => 'ASSET'
112213          , p_ae_header_id           => l_ae_header_id
112214          );
112215 
112216    --
112217    -- set rounding class
112218    --
112219    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
112220                       'ASSET';
112221 
112222    --
112223    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
112224    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
112225    --
112226    -- bulk performance
112227    --
112228    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
112229 
112230    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
112231       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
112232 
112233    -- 4955764
112234    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
112235       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
112236 
112240    -- set accounting attributes for the line type
112237    -- 4458381 Public Sector Enh
112238    
112239    --
112241    --
112242    l_entered_amt_idx := 4;
112243    l_accted_amt_idx  := 6;
112244    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
112245    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
112246    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
112247    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
112248    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
112249    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
112250    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
112251    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
112252    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
112253    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
112254    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
112255    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
112256    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
112257 
112258    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
112259    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
112260 
112261    ---------------------------------------------------------------------------------------------------------------
112262    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
112263    ---------------------------------------------------------------------------------------------------------------
112264    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
112265 
112266    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
112267    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
112268 
112269    IF xla_accounting_cache_pkg.GetValueChar
112270          (p_source_code         => 'LEDGER_CATEGORY_CODE'
112271          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
112272    AND l_bflow_method_code = 'PRIOR_ENTRY'
112273 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
112274    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
112275          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
112276        )
112277    THEN
112278          xla_ae_lines_pkg.BflowUpgEntry
112279            (p_business_method_code    => l_bflow_method_code
112280            ,p_business_class_code     => l_bflow_class_code
112281            ,p_balance_type            => l_balance_type_code);
112282    ELSE
112283       NULL;
112284 -- No business flow processing for business flow method of NONE.
112285    END IF;
112286 
112287    --
112288    -- call analytical criteria
112289    --
112290    
112291    --
112292    -- call description
112293    --
112294    
112295 xla_ae_lines_pkg.SetLineDescription(
112296    p_ae_header_id => l_ae_header_id
112297   ,p_description  => Description_86 (
112298      p_application_id         => p_application_id
112299    , p_ae_header_id           => l_ae_header_id 
112300 , p_source_1 => p_source_1
112301    )
112302 );
112303 
112304 
112305    --
112306    -- call ADRs
112307    -- Bug 4922099
112308    --
112309    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
112310         (NVL(l_actual_upg_option, 'N') = 'O') OR
112311         (NVL(l_enc_upg_option, 'N') = 'O')
112312       )
112313    THEN
112314    NULL;
112315    --
112316    --
112317    
112318   l_ccid := AcctDerRule_174(
112319            p_application_id           => p_application_id
112320          , p_ae_header_id             => l_ae_header_id 
112321 , p_source_3 => p_source_3
112322 , p_source_17 => p_source_17
112323 , p_source_30 => p_source_30
112324          , x_transaction_coa_id       => l_adr_transaction_coa_id
112325          , x_accounting_coa_id        => l_adr_accounting_coa_id
112326          , x_value_type_code          => l_adr_value_type_code
112327          , p_side                     => 'NA'
112328    );
112329 
112330    xla_ae_lines_pkg.set_ccid(
112331     p_code_combination_id          => l_ccid
112332   , p_value_type_code              => l_adr_value_type_code
112333   , p_transaction_coa_id           => l_adr_transaction_coa_id
112334   , p_accounting_coa_id            => l_adr_accounting_coa_id
112335   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
112336   , p_adr_type_code                => 'S'
112337   , p_component_type               => l_component_type
112338   , p_component_code               => l_component_code
112339   , p_component_type_code          => l_component_type_code
112340   , p_component_appl_id            => l_component_appl_id
112341   , p_amb_context_code             => l_amb_context_code
112342   , p_side                         => 'NA'
112343   );
112344 
112345 
112346    l_segment := AcctDerRule_149(
112347            p_application_id           => p_application_id
112348          , p_ae_header_id             => l_ae_header_id 
112349 , p_source_3 => p_source_3
112350 , p_source_10 => p_source_10
112351          , x_transaction_coa_id       => l_adr_transaction_coa_id
112352          , x_accounting_coa_id        => l_adr_accounting_coa_id
112353          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
112354          , x_flex_value_set_id        => l_adr_flex_value_set_id
112355          , x_value_type_code          => l_adr_value_type_code
112356          , x_value_combination_id     => l_adr_value_combination_id
112357          , x_value_segment_code       => l_adr_value_segment_code
112358          , p_side                     => 'NA'
112359          , p_override_seg_flag        => 'Y'
112360    );
112361 
112362    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
112363 
112364       xla_ae_lines_pkg.set_segment(
112368         , p_from_combination_id     => l_adr_value_combination_id
112365           p_to_segment_code         => 'GL_ACCOUNT'
112366         , p_segment_value           => l_segment
112367         , p_from_segment_code       => l_adr_value_segment_code
112369         , p_value_type_code         => l_adr_value_type_code
112370         , p_transaction_coa_id      => l_adr_transaction_coa_id
112371         , p_accounting_coa_id       => l_adr_accounting_coa_id
112372         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
112373         , p_flex_value_set_id       => l_adr_flex_value_set_id
112374         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
112375         , p_adr_type_code           => 'S'
112376         , p_component_type          => l_component_type
112377         , p_component_code          => l_component_code
112378         , p_component_type_code     => l_component_type_code
112379         , p_component_appl_id       => l_component_appl_id
112380         , p_amb_context_code        => l_amb_context_code
112381         , p_entity_code             => 'TRANSACTIONS'
112382         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
112383         , p_side                    => 'NA'
112384         );
112385 
112386   END IF;
112387 
112388    l_segment := AcctDerRule_168(
112389            p_application_id           => p_application_id
112390          , p_ae_header_id             => l_ae_header_id 
112391 , p_source_3 => p_source_3
112392 , p_source_29 => p_source_29
112393          , x_transaction_coa_id       => l_adr_transaction_coa_id
112394          , x_accounting_coa_id        => l_adr_accounting_coa_id
112395          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
112396          , x_flex_value_set_id        => l_adr_flex_value_set_id
112397          , x_value_type_code          => l_adr_value_type_code
112398          , x_value_combination_id     => l_adr_value_combination_id
112399          , x_value_segment_code       => l_adr_value_segment_code
112400          , p_side                     => 'NA'
112401          , p_override_seg_flag        => 'Y'
112402    );
112403 
112404    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
112405 
112406       xla_ae_lines_pkg.set_segment(
112407           p_to_segment_code         => 'GL_BALANCING'
112408         , p_segment_value           => l_segment
112409         , p_from_segment_code       => l_adr_value_segment_code
112410         , p_from_combination_id     => l_adr_value_combination_id
112411         , p_value_type_code         => l_adr_value_type_code
112412         , p_transaction_coa_id      => l_adr_transaction_coa_id
112413         , p_accounting_coa_id       => l_adr_accounting_coa_id
112414         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
112415         , p_flex_value_set_id       => l_adr_flex_value_set_id
112416         , p_adr_code                => 'FA_EXPENSE_ACCT'
112417         , p_adr_type_code           => 'S'
112418         , p_component_type          => l_component_type
112419         , p_component_code          => l_component_code
112420         , p_component_type_code     => l_component_type_code
112421         , p_component_appl_id       => l_component_appl_id
112422         , p_amb_context_code        => l_amb_context_code
112423         , p_entity_code             => 'TRANSACTIONS'
112424         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
112425         , p_side                    => 'NA'
112426         );
112427 
112428   END IF;
112429 
112430    --
112431    --
112432    END IF;
112433    --
112434    -- Bug 4922099
112435    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
112436           (NVL(l_enc_upg_option, 'N') = 'O')
112437         ) AND
112438         (l_bflow_method_code = 'PRIOR_ENTRY')
112439       )
112440    THEN
112441       IF
112442       --
112443       1 = 2
112444       --
112445       THEN
112446       xla_accounting_err_pkg.build_message
112447                                     (p_appli_s_name            => 'XLA'
112448                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
112449                                     ,p_token_1                 => 'LINE_NUMBER'
112450                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
112451                                     ,p_token_2                 => 'LINE_TYPE_NAME'
112452                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
112453                                                                              l_component_type
112454                                                                             ,l_component_code
112455                                                                             ,l_component_type_code
112456                                                                             ,l_component_appl_id
112457                                                                             ,l_amb_context_code
112458                                                                             ,l_entity_code
112459                                                                             ,l_event_class_code
112460                                                                            )
112461                                     ,p_token_3                 => 'OWNER'
112462                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
112463                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
112464                                                                           ,p_lookup_code    => l_component_type_code
112465                                                                          )
112466                                     ,p_token_4                 => 'PRODUCT_NAME'
112467                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
112468                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
112472                                        );
112469                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
112470                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
112471                                     ,p_ae_header_id            =>  NULL
112473 
112474         IF (C_LEVEL_ERROR>= g_log_level) THEN
112475                  trace
112476                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
112477                       ,p_level    => C_LEVEL_ERROR
112478                       ,p_module   => l_log_module);
112479         END IF;
112480       END IF;
112481    END IF;
112482    --
112483    --
112484    ------------------------------------------------------------------------------------------------
112485    -- 4219869 Business Flow
112486    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
112487    -- Prior Entry.  Currently, the following code is always generated.
112488    ------------------------------------------------------------------------------------------------
112489    XLA_AE_LINES_PKG.ValidateCurrentLine;
112490 
112491    ------------------------------------------------------------------------------------
112492    -- 4219869 Business Flow
112493    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
112494    ------------------------------------------------------------------------------------
112495    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
112496 
112497    ----------------------------------------------------------------------------------
112498    -- 4219869 Business Flow
112499    -- Update journal entry status -- Need to generate this within IF <condition>
112500    ----------------------------------------------------------------------------------
112501    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
112502          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
112503          ,p_balance_type_code => l_balance_type_code
112504          );
112505 
112506    -------------------------------------------------------------------------------------------
112507    -- 4262811 - Generate the Accrual Reversal lines
112508    -------------------------------------------------------------------------------------------
112509    BEGIN
112510       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
112511                               (g_array_event(p_event_id).array_value_num('header_index'));
112512       IF l_acc_rev_flag IS NULL THEN
112513          l_acc_rev_flag := 'N';
112514       END IF;
112515    EXCEPTION
112516       WHEN OTHERS THEN
112517          l_acc_rev_flag := 'N';
112518    END;
112519    --
112520    IF (l_acc_rev_flag = 'Y') THEN
112521 
112522        -- 4645092  ------------------------------------------------------------------------------
112523        -- To allow MPA report to determine if it should generate report process
112524        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
112525        ------------------------------------------------------------------------------------------
112526 
112527        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
112528        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
112529    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
112530    -- call ADRs
112531    -- Bug 4922099
112532    --
112533    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
112534         (NVL(l_actual_upg_option, 'N') = 'O') OR
112535         (NVL(l_enc_upg_option, 'N') = 'O')
112536       )
112537    THEN
112538    NULL;
112539    --
112540    --
112541    
112542   l_ccid := AcctDerRule_174(
112543            p_application_id           => p_application_id
112544          , p_ae_header_id             => l_ae_header_id 
112545 , p_source_3 => p_source_3
112546 , p_source_17 => p_source_17
112547 , p_source_30 => p_source_30
112548          , x_transaction_coa_id       => l_adr_transaction_coa_id
112549          , x_accounting_coa_id        => l_adr_accounting_coa_id
112550          , x_value_type_code          => l_adr_value_type_code
112551          , p_side                     => 'NA'
112552    );
112553 
112554    xla_ae_lines_pkg.set_ccid(
112555     p_code_combination_id          => l_ccid
112556   , p_value_type_code              => l_adr_value_type_code
112557   , p_transaction_coa_id           => l_adr_transaction_coa_id
112558   , p_accounting_coa_id            => l_adr_accounting_coa_id
112559   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
112560   , p_adr_type_code                => 'S'
112561   , p_component_type               => l_component_type
112562   , p_component_code               => l_component_code
112563   , p_component_type_code          => l_component_type_code
112564   , p_component_appl_id            => l_component_appl_id
112565   , p_amb_context_code             => l_amb_context_code
112566   , p_side                         => 'NA'
112567   );
112568 
112569 
112570    l_segment := AcctDerRule_149(
112571            p_application_id           => p_application_id
112572          , p_ae_header_id             => l_ae_header_id 
112573 , p_source_3 => p_source_3
112574 , p_source_10 => p_source_10
112575          , x_transaction_coa_id       => l_adr_transaction_coa_id
112576          , x_accounting_coa_id        => l_adr_accounting_coa_id
112577          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
112578          , x_flex_value_set_id        => l_adr_flex_value_set_id
112579          , x_value_type_code          => l_adr_value_type_code
112580          , x_value_combination_id     => l_adr_value_combination_id
112581          , x_value_segment_code       => l_adr_value_segment_code
112582          , p_side                     => 'NA'
112583          , p_override_seg_flag        => 'Y'
112584    );
112585 
112586    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
112587 
112588       xla_ae_lines_pkg.set_segment(
112592         , p_from_combination_id     => l_adr_value_combination_id
112589           p_to_segment_code         => 'GL_ACCOUNT'
112590         , p_segment_value           => l_segment
112591         , p_from_segment_code       => l_adr_value_segment_code
112593         , p_value_type_code         => l_adr_value_type_code
112594         , p_transaction_coa_id      => l_adr_transaction_coa_id
112595         , p_accounting_coa_id       => l_adr_accounting_coa_id
112596         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
112597         , p_flex_value_set_id       => l_adr_flex_value_set_id
112598         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
112599         , p_adr_type_code           => 'S'
112600         , p_component_type          => l_component_type
112601         , p_component_code          => l_component_code
112602         , p_component_type_code     => l_component_type_code
112603         , p_component_appl_id       => l_component_appl_id
112604         , p_amb_context_code        => l_amb_context_code
112605         , p_entity_code             => 'TRANSACTIONS'
112606         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
112607         , p_side                    => 'NA'
112608         );
112609 
112610   END IF;
112611 
112612    l_segment := AcctDerRule_168(
112613            p_application_id           => p_application_id
112614          , p_ae_header_id             => l_ae_header_id 
112615 , p_source_3 => p_source_3
112616 , p_source_29 => p_source_29
112617          , x_transaction_coa_id       => l_adr_transaction_coa_id
112618          , x_accounting_coa_id        => l_adr_accounting_coa_id
112619          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
112620          , x_flex_value_set_id        => l_adr_flex_value_set_id
112621          , x_value_type_code          => l_adr_value_type_code
112622          , x_value_combination_id     => l_adr_value_combination_id
112623          , x_value_segment_code       => l_adr_value_segment_code
112624          , p_side                     => 'NA'
112625          , p_override_seg_flag        => 'Y'
112626    );
112627 
112628    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
112629 
112630       xla_ae_lines_pkg.set_segment(
112631           p_to_segment_code         => 'GL_BALANCING'
112632         , p_segment_value           => l_segment
112633         , p_from_segment_code       => l_adr_value_segment_code
112634         , p_from_combination_id     => l_adr_value_combination_id
112635         , p_value_type_code         => l_adr_value_type_code
112636         , p_transaction_coa_id      => l_adr_transaction_coa_id
112637         , p_accounting_coa_id       => l_adr_accounting_coa_id
112638         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
112639         , p_flex_value_set_id       => l_adr_flex_value_set_id
112640         , p_adr_code                => 'FA_EXPENSE_ACCT'
112641         , p_adr_type_code           => 'S'
112642         , p_component_type          => l_component_type
112643         , p_component_code          => l_component_code
112644         , p_component_type_code     => l_component_type_code
112645         , p_component_appl_id       => l_component_appl_id
112646         , p_amb_context_code        => l_amb_context_code
112647         , p_entity_code             => 'TRANSACTIONS'
112648         , p_event_class_code        => 'RETIREMENT_ADJUSTMENTS'
112649         , p_side                    => 'NA'
112650         );
112651 
112652   END IF;
112653 
112654    --
112655    --
112656    END IF;
112657 
112658        --
112659        -- Update the line information that should be overwritten
112660        --
112661        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
112662                                          p_header_num   => 1);
112663        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
112664 
112665        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
112666 
112667        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
112668           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
112669        END IF;
112670 
112671       --
112672       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
112673       --
112674       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
112675           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
112676       ELSE
112677           ---------------------------------------------------------------------------------------------------
112678           -- 4262811a Switch Sign
112679           ---------------------------------------------------------------------------------------------------
112680           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
112681           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
112682                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
112683           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
112684                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
112685           -- 5132302
112686           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
112687                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
112688 
112689       END IF;
112690 
112691       -- 4955764
112692       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
112693       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
112694 
112695 
112696       XLA_AE_LINES_PKG.ValidateCurrentLine;
112697       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
112698 
112702 
112699       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
112700                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
112701                ,p_balance_type_code => l_balance_type_code);
112703    END IF;
112704 
112705    -----------------------------------------------------------------------------------------
112706    -- 4262811 Multiperiod Accounting
112707    -----------------------------------------------------------------------------------------
112708      -- No MPA option is assigned.
112709 
112710 
112711 END IF;
112712 END IF;
112713 --
112714 
112715 --
112716 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
112717    trace
112718       (p_msg      => 'END of AcctLineType_311'
112719       ,p_level    => C_LEVEL_PROCEDURE
112720       ,p_module   => l_log_module);
112721 END IF;
112722 --
112723 EXCEPTION
112724   WHEN xla_exceptions_pkg.application_exception THEN
112725       RAISE;
112726   WHEN OTHERS THEN
112727        xla_exceptions_pkg.raise_message
112728            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_311');
112729 END AcctLineType_311;
112730 --
112731 
112732 ---------------------------------------
112733 --
112734 -- PRIVATE FUNCTION
112735 --         AcctLineType_312
112736 --
112737 ---------------------------------------
112738 PROCEDURE AcctLineType_312 (
112739   p_application_id        IN NUMBER
112740  ,p_event_id              IN NUMBER
112741  ,p_calculate_acctd_flag  IN VARCHAR2
112742  ,p_calculate_g_l_flag    IN VARCHAR2
112743  ,p_actual_flag           IN OUT VARCHAR2
112744  ,p_balance_type_code     OUT VARCHAR2
112745  ,p_gain_or_loss_ref      OUT VARCHAR2
112746  
112747 --Period Close Date
112748  , p_source_1            IN DATE
112749 --Generated Code Combination Identifier
112750  , p_source_3            IN NUMBER
112751 --Revaluation Reserve Account
112752  , p_source_11            IN VARCHAR2
112753 --Generated Offset Code Combination Identifier
112754  , p_source_17            IN NUMBER
112755 --Expense Account Code Combination Identifier
112756  , p_source_29            IN NUMBER
112757 --Default Code Combination Identifier
112758  , p_source_30            IN NUMBER
112759 --Adjustment Type
112760  , p_source_35            IN VARCHAR2
112761 --Transaction Header Identifier
112762  , p_source_36            IN NUMBER
112763 --Adjustment Line Identifier
112764  , p_source_37            IN NUMBER
112765 --Distribution Type Code
112766  , p_source_38            IN VARCHAR2
112767 --Entered Amount
112768  , p_source_39            IN NUMBER
112769 --Currency Code
112770  , p_source_40            IN VARCHAR2
112771 )
112772 IS
112773 
112774 l_component_type              VARCHAR2(80);
112775 l_component_code              VARCHAR2(30);
112776 l_component_type_code         VARCHAR2(1);
112777 l_component_appl_id           INTEGER;
112778 l_amb_context_code            VARCHAR2(30);
112779 l_entity_code                 VARCHAR2(30);
112780 l_event_class_code            VARCHAR2(30);
112781 l_ae_header_id                NUMBER;
112782 l_event_type_code             VARCHAR2(30);
112783 l_line_definition_code        VARCHAR2(30);
112784 l_line_definition_owner_code  VARCHAR2(1);
112785 --
112786 -- adr variables
112787 l_segment                     VARCHAR2(30);
112788 l_ccid                        NUMBER;
112789 l_adr_transaction_coa_id      NUMBER;
112790 l_adr_accounting_coa_id       NUMBER;
112791 l_adr_flexfield_segment_code  VARCHAR2(30);
112792 l_adr_flex_value_set_id       NUMBER;
112793 l_adr_value_type_code         VARCHAR2(30);
112794 l_adr_value_combination_id    NUMBER;
112795 l_adr_value_segment_code      VARCHAR2(30);
112796 
112797 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
112798 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
112799 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
112800 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
112801 
112802 -- 4262811 Variables ------------------------------------------------------------------------------------------
112803 l_entered_amt_idx             NUMBER;
112804 l_accted_amt_idx              NUMBER;
112805 l_acc_rev_flag                VARCHAR2(1);
112806 l_accrual_line_num            NUMBER;
112807 l_tmp_amt                     NUMBER;
112808 l_acc_rev_natural_side_code   VARCHAR2(1);
112809 
112810 l_num_entries                 NUMBER;
112811 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
112812 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
112813 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
112814 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
112815 l_recog_line_1                NUMBER;
112816 l_recog_line_2                NUMBER;
112817 
112818 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
112819 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
112820 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
112821 
112822 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
112823 
112824 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
112825 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
112826 
112827 ---------------------------------------------------------------------------------------------------------------
112828 
112829 
112830 --
112831 -- bulk performance
112832 --
112833 l_balance_type_code           VARCHAR2(1);
112834 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
112835 l_log_module                  VARCHAR2(240);
112836 
112837 --
112838 -- Upgrade strategy
112839 --
112840 l_actual_upg_option           VARCHAR2(1);
112841 l_enc_upg_option           VARCHAR2(1);
112842 
112846 IF g_log_enabled THEN
112843 --
112844 BEGIN
112845 --
112847       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_312';
112848 END IF;
112849 --
112850 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
112851 
112852       trace
112853          (p_msg      => 'BEGIN of AcctLineType_312'
112854          ,p_level    => C_LEVEL_PROCEDURE
112855          ,p_module   => l_log_module);
112856 
112857 END IF;
112858 --
112859 l_component_type             := 'AMB_JLT';
112860 l_component_code             := 'FA_RET_REVAL_RESERVE';
112861 l_component_type_code        := 'S';
112862 l_component_appl_id          :=  140;
112863 l_amb_context_code           := 'DEFAULT';
112864 l_entity_code                := 'TRANSACTIONS';
112865 l_event_class_code           := 'RETIREMENTS';
112866 l_event_type_code            := 'RETIREMENTS';
112867 l_line_definition_owner_code := 'S';
112868 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
112869 --
112870 l_balance_type_code          := 'A';
112871 l_segment                     := NULL;
112872 l_ccid                        := NULL;
112873 l_adr_transaction_coa_id      := NULL;
112874 l_adr_accounting_coa_id       := NULL;
112875 l_adr_flexfield_segment_code  := NULL;
112876 l_adr_flex_value_set_id       := NULL;
112877 l_adr_value_type_code         := NULL;
112878 l_adr_value_combination_id    := NULL;
112879 l_adr_value_segment_code      := NULL;
112880 
112881 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
112882 l_bflow_class_code           := '';    -- 4219869 Business Flow
112883 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
112884 l_budgetary_control_flag     := 'N';
112885 
112886 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
112887 l_bflow_applied_to_amt       := NULL; -- 5132302
112888 l_entered_amt_idx            := NULL;          -- 4262811
112889 l_accted_amt_idx             := NULL;          -- 4262811
112890 l_acc_rev_flag               := NULL;          -- 4262811
112891 l_accrual_line_num           := NULL;          -- 4262811
112892 l_tmp_amt                    := NULL;          -- 4262811
112893 --
112894  
112895 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
112896     l_balance_type_code <> 'B' THEN
112897 IF NVL(p_source_35,'
112898 ') =  'REVAL RESERVE'
112899  THEN 
112900 
112901    --
112902    XLA_AE_LINES_PKG.SetNewLine;
112903 
112904    p_balance_type_code          := l_balance_type_code;
112905    -- set the flag so later we will know whether the gain loss line needs to be created
112906    
112907    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
112908      p_actual_flag :='A';
112909    END IF;
112910 
112911    --
112912    -- bulk performance
112913    --
112914    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
112915                                       p_header_num   => 0); -- 4262811
112916    --
112917    -- set accounting line options
112918    --
112919    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
112920            p_natural_side_code          => 'D'
112921          , p_gain_or_loss_flag          => 'N'
112922          , p_gl_transfer_mode_code      => 'S'
112923          , p_acct_entry_type_code       => 'A'
112924          , p_switch_side_flag           => 'Y'
112925          , p_merge_duplicate_code       => 'N'
112926          );
112927    --
112928    l_acc_rev_natural_side_code := 'C';  -- 4262811
112929    -- 
112930    --
112931    -- set accounting line type info
112932    --
112933    xla_ae_lines_pkg.SetAcctLineType
112934       (p_component_type             => l_component_type
112935       ,p_event_type_code            => l_event_type_code
112936       ,p_line_definition_owner_code => l_line_definition_owner_code
112937       ,p_line_definition_code       => l_line_definition_code
112938       ,p_accounting_line_code       => l_component_code
112939       ,p_accounting_line_type_code  => l_component_type_code
112940       ,p_accounting_line_appl_id    => l_component_appl_id
112941       ,p_amb_context_code           => l_amb_context_code
112942       ,p_entity_code                => l_entity_code
112943       ,p_event_class_code           => l_event_class_code);
112944    --
112945    -- set accounting class
112946    --
112947    xla_ae_lines_pkg.SetAcctClass(
112948            p_accounting_class_code  => 'ASSET'
112949          , p_ae_header_id           => l_ae_header_id
112950          );
112951 
112952    --
112953    -- set rounding class
112954    --
112955    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
112956                       'ASSET';
112957 
112958    --
112959    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
112960    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
112961    --
112962    -- bulk performance
112963    --
112964    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
112965 
112966    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
112967       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
112968 
112969    -- 4955764
112970    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
112971       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
112972 
112973    -- 4458381 Public Sector Enh
112974    
112975    --
112976    -- set accounting attributes for the line type
112977    --
112978    l_entered_amt_idx := 4;
112979    l_accted_amt_idx  := 6;
112980    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
112981    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
112982    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
112986    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
112983    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
112984    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
112985    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
112987    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
112988    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
112989    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
112990    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
112991    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
112992    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
112993 
112994    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
112995    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
112996 
112997    ---------------------------------------------------------------------------------------------------------------
112998    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
112999    ---------------------------------------------------------------------------------------------------------------
113000    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
113001 
113002    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
113003    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
113004 
113005    IF xla_accounting_cache_pkg.GetValueChar
113006          (p_source_code         => 'LEDGER_CATEGORY_CODE'
113007          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
113008    AND l_bflow_method_code = 'PRIOR_ENTRY'
113009 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
113010    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
113011          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
113012        )
113013    THEN
113014          xla_ae_lines_pkg.BflowUpgEntry
113015            (p_business_method_code    => l_bflow_method_code
113016            ,p_business_class_code     => l_bflow_class_code
113017            ,p_balance_type            => l_balance_type_code);
113018    ELSE
113019       NULL;
113020 -- No business flow processing for business flow method of NONE.
113021    END IF;
113022 
113023    --
113024    -- call analytical criteria
113025    --
113026    
113027    --
113028    -- call description
113029    --
113030    
113031 xla_ae_lines_pkg.SetLineDescription(
113032    p_ae_header_id => l_ae_header_id
113033   ,p_description  => Description_83 (
113034      p_application_id         => p_application_id
113035    , p_ae_header_id           => l_ae_header_id 
113036 , p_source_1 => p_source_1
113037    )
113038 );
113039 
113040 
113041    --
113042    -- call ADRs
113043    -- Bug 4922099
113044    --
113045    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
113046         (NVL(l_actual_upg_option, 'N') = 'O') OR
113047         (NVL(l_enc_upg_option, 'N') = 'O')
113048       )
113049    THEN
113050    NULL;
113051    --
113052    --
113053    
113054   l_ccid := AcctDerRule_174(
113055            p_application_id           => p_application_id
113056          , p_ae_header_id             => l_ae_header_id 
113057 , p_source_3 => p_source_3
113058 , p_source_17 => p_source_17
113059 , p_source_30 => p_source_30
113060          , x_transaction_coa_id       => l_adr_transaction_coa_id
113061          , x_accounting_coa_id        => l_adr_accounting_coa_id
113062          , x_value_type_code          => l_adr_value_type_code
113063          , p_side                     => 'NA'
113064    );
113065 
113066    xla_ae_lines_pkg.set_ccid(
113067     p_code_combination_id          => l_ccid
113068   , p_value_type_code              => l_adr_value_type_code
113069   , p_transaction_coa_id           => l_adr_transaction_coa_id
113070   , p_accounting_coa_id            => l_adr_accounting_coa_id
113071   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
113072   , p_adr_type_code                => 'S'
113073   , p_component_type               => l_component_type
113074   , p_component_code               => l_component_code
113075   , p_component_type_code          => l_component_type_code
113076   , p_component_appl_id            => l_component_appl_id
113077   , p_amb_context_code             => l_amb_context_code
113078   , p_side                         => 'NA'
113079   );
113080 
113081 
113082    l_segment := AcctDerRule_150(
113083            p_application_id           => p_application_id
113084          , p_ae_header_id             => l_ae_header_id 
113085 , p_source_3 => p_source_3
113086 , p_source_11 => p_source_11
113087          , x_transaction_coa_id       => l_adr_transaction_coa_id
113088          , x_accounting_coa_id        => l_adr_accounting_coa_id
113089          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
113090          , x_flex_value_set_id        => l_adr_flex_value_set_id
113091          , x_value_type_code          => l_adr_value_type_code
113092          , x_value_combination_id     => l_adr_value_combination_id
113093          , x_value_segment_code       => l_adr_value_segment_code
113094          , p_side                     => 'NA'
113095          , p_override_seg_flag        => 'Y'
113096    );
113097 
113098    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
113099 
113100       xla_ae_lines_pkg.set_segment(
113101           p_to_segment_code         => 'GL_ACCOUNT'
113102         , p_segment_value           => l_segment
113103         , p_from_segment_code       => l_adr_value_segment_code
113104         , p_from_combination_id     => l_adr_value_combination_id
113105         , p_value_type_code         => l_adr_value_type_code
113106         , p_transaction_coa_id      => l_adr_transaction_coa_id
113107         , p_accounting_coa_id       => l_adr_accounting_coa_id
113111         , p_adr_type_code           => 'S'
113108         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
113109         , p_flex_value_set_id       => l_adr_flex_value_set_id
113110         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
113112         , p_component_type          => l_component_type
113113         , p_component_code          => l_component_code
113114         , p_component_type_code     => l_component_type_code
113115         , p_component_appl_id       => l_component_appl_id
113116         , p_amb_context_code        => l_amb_context_code
113117         , p_entity_code             => 'TRANSACTIONS'
113118         , p_event_class_code        => 'RETIREMENTS'
113119         , p_side                    => 'NA'
113120         );
113121 
113122   END IF;
113123 
113124    l_segment := AcctDerRule_168(
113125            p_application_id           => p_application_id
113126          , p_ae_header_id             => l_ae_header_id 
113127 , p_source_3 => p_source_3
113128 , p_source_29 => p_source_29
113129          , x_transaction_coa_id       => l_adr_transaction_coa_id
113130          , x_accounting_coa_id        => l_adr_accounting_coa_id
113131          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
113132          , x_flex_value_set_id        => l_adr_flex_value_set_id
113133          , x_value_type_code          => l_adr_value_type_code
113134          , x_value_combination_id     => l_adr_value_combination_id
113135          , x_value_segment_code       => l_adr_value_segment_code
113136          , p_side                     => 'NA'
113137          , p_override_seg_flag        => 'Y'
113138    );
113139 
113140    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
113141 
113142       xla_ae_lines_pkg.set_segment(
113143           p_to_segment_code         => 'GL_BALANCING'
113144         , p_segment_value           => l_segment
113145         , p_from_segment_code       => l_adr_value_segment_code
113146         , p_from_combination_id     => l_adr_value_combination_id
113147         , p_value_type_code         => l_adr_value_type_code
113148         , p_transaction_coa_id      => l_adr_transaction_coa_id
113149         , p_accounting_coa_id       => l_adr_accounting_coa_id
113150         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
113151         , p_flex_value_set_id       => l_adr_flex_value_set_id
113152         , p_adr_code                => 'FA_EXPENSE_ACCT'
113153         , p_adr_type_code           => 'S'
113154         , p_component_type          => l_component_type
113155         , p_component_code          => l_component_code
113156         , p_component_type_code     => l_component_type_code
113157         , p_component_appl_id       => l_component_appl_id
113158         , p_amb_context_code        => l_amb_context_code
113159         , p_entity_code             => 'TRANSACTIONS'
113160         , p_event_class_code        => 'RETIREMENTS'
113161         , p_side                    => 'NA'
113162         );
113163 
113164   END IF;
113165 
113166    --
113167    --
113168    END IF;
113169    --
113170    -- Bug 4922099
113171    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
113172           (NVL(l_enc_upg_option, 'N') = 'O')
113173         ) AND
113174         (l_bflow_method_code = 'PRIOR_ENTRY')
113175       )
113176    THEN
113177       IF
113178       --
113179       1 = 2
113180       --
113181       THEN
113182       xla_accounting_err_pkg.build_message
113183                                     (p_appli_s_name            => 'XLA'
113184                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
113185                                     ,p_token_1                 => 'LINE_NUMBER'
113186                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
113187                                     ,p_token_2                 => 'LINE_TYPE_NAME'
113188                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
113189                                                                              l_component_type
113190                                                                             ,l_component_code
113191                                                                             ,l_component_type_code
113192                                                                             ,l_component_appl_id
113193                                                                             ,l_amb_context_code
113194                                                                             ,l_entity_code
113195                                                                             ,l_event_class_code
113196                                                                            )
113197                                     ,p_token_3                 => 'OWNER'
113198                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
113199                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
113200                                                                           ,p_lookup_code    => l_component_type_code
113201                                                                          )
113202                                     ,p_token_4                 => 'PRODUCT_NAME'
113203                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
113204                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
113205                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
113206                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
113207                                     ,p_ae_header_id            =>  NULL
113208                                        );
113209 
113210         IF (C_LEVEL_ERROR>= g_log_level) THEN
113211                  trace
113212                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
113216       END IF;
113213                       ,p_level    => C_LEVEL_ERROR
113214                       ,p_module   => l_log_module);
113215         END IF;
113217    END IF;
113218    --
113219    --
113220    ------------------------------------------------------------------------------------------------
113221    -- 4219869 Business Flow
113222    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
113223    -- Prior Entry.  Currently, the following code is always generated.
113224    ------------------------------------------------------------------------------------------------
113225    XLA_AE_LINES_PKG.ValidateCurrentLine;
113226 
113227    ------------------------------------------------------------------------------------
113228    -- 4219869 Business Flow
113229    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
113230    ------------------------------------------------------------------------------------
113231    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
113232 
113233    ----------------------------------------------------------------------------------
113234    -- 4219869 Business Flow
113235    -- Update journal entry status -- Need to generate this within IF <condition>
113236    ----------------------------------------------------------------------------------
113237    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
113238          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
113239          ,p_balance_type_code => l_balance_type_code
113240          );
113241 
113242    -------------------------------------------------------------------------------------------
113243    -- 4262811 - Generate the Accrual Reversal lines
113244    -------------------------------------------------------------------------------------------
113245    BEGIN
113246       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
113247                               (g_array_event(p_event_id).array_value_num('header_index'));
113248       IF l_acc_rev_flag IS NULL THEN
113249          l_acc_rev_flag := 'N';
113250       END IF;
113251    EXCEPTION
113252       WHEN OTHERS THEN
113253          l_acc_rev_flag := 'N';
113254    END;
113255    --
113256    IF (l_acc_rev_flag = 'Y') THEN
113257 
113258        -- 4645092  ------------------------------------------------------------------------------
113259        -- To allow MPA report to determine if it should generate report process
113260        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
113261        ------------------------------------------------------------------------------------------
113262 
113263        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
113264        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
113265    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
113266    -- call ADRs
113267    -- Bug 4922099
113268    --
113269    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
113270         (NVL(l_actual_upg_option, 'N') = 'O') OR
113271         (NVL(l_enc_upg_option, 'N') = 'O')
113272       )
113273    THEN
113274    NULL;
113275    --
113276    --
113277    
113278   l_ccid := AcctDerRule_174(
113279            p_application_id           => p_application_id
113280          , p_ae_header_id             => l_ae_header_id 
113281 , p_source_3 => p_source_3
113282 , p_source_17 => p_source_17
113283 , p_source_30 => p_source_30
113284          , x_transaction_coa_id       => l_adr_transaction_coa_id
113285          , x_accounting_coa_id        => l_adr_accounting_coa_id
113286          , x_value_type_code          => l_adr_value_type_code
113287          , p_side                     => 'NA'
113288    );
113289 
113290    xla_ae_lines_pkg.set_ccid(
113291     p_code_combination_id          => l_ccid
113292   , p_value_type_code              => l_adr_value_type_code
113293   , p_transaction_coa_id           => l_adr_transaction_coa_id
113294   , p_accounting_coa_id            => l_adr_accounting_coa_id
113295   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
113296   , p_adr_type_code                => 'S'
113297   , p_component_type               => l_component_type
113298   , p_component_code               => l_component_code
113299   , p_component_type_code          => l_component_type_code
113300   , p_component_appl_id            => l_component_appl_id
113301   , p_amb_context_code             => l_amb_context_code
113302   , p_side                         => 'NA'
113303   );
113304 
113305 
113306    l_segment := AcctDerRule_150(
113307            p_application_id           => p_application_id
113308          , p_ae_header_id             => l_ae_header_id 
113309 , p_source_3 => p_source_3
113310 , p_source_11 => p_source_11
113311          , x_transaction_coa_id       => l_adr_transaction_coa_id
113312          , x_accounting_coa_id        => l_adr_accounting_coa_id
113313          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
113314          , x_flex_value_set_id        => l_adr_flex_value_set_id
113315          , x_value_type_code          => l_adr_value_type_code
113316          , x_value_combination_id     => l_adr_value_combination_id
113317          , x_value_segment_code       => l_adr_value_segment_code
113318          , p_side                     => 'NA'
113319          , p_override_seg_flag        => 'Y'
113320    );
113321 
113322    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
113323 
113324       xla_ae_lines_pkg.set_segment(
113325           p_to_segment_code         => 'GL_ACCOUNT'
113326         , p_segment_value           => l_segment
113327         , p_from_segment_code       => l_adr_value_segment_code
113328         , p_from_combination_id     => l_adr_value_combination_id
113329         , p_value_type_code         => l_adr_value_type_code
113330         , p_transaction_coa_id      => l_adr_transaction_coa_id
113331         , p_accounting_coa_id       => l_adr_accounting_coa_id
113332         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
113336         , p_component_type          => l_component_type
113333         , p_flex_value_set_id       => l_adr_flex_value_set_id
113334         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
113335         , p_adr_type_code           => 'S'
113337         , p_component_code          => l_component_code
113338         , p_component_type_code     => l_component_type_code
113339         , p_component_appl_id       => l_component_appl_id
113340         , p_amb_context_code        => l_amb_context_code
113341         , p_entity_code             => 'TRANSACTIONS'
113342         , p_event_class_code        => 'RETIREMENTS'
113343         , p_side                    => 'NA'
113344         );
113345 
113346   END IF;
113347 
113348    l_segment := AcctDerRule_168(
113349            p_application_id           => p_application_id
113350          , p_ae_header_id             => l_ae_header_id 
113351 , p_source_3 => p_source_3
113352 , p_source_29 => p_source_29
113353          , x_transaction_coa_id       => l_adr_transaction_coa_id
113354          , x_accounting_coa_id        => l_adr_accounting_coa_id
113355          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
113356          , x_flex_value_set_id        => l_adr_flex_value_set_id
113357          , x_value_type_code          => l_adr_value_type_code
113358          , x_value_combination_id     => l_adr_value_combination_id
113359          , x_value_segment_code       => l_adr_value_segment_code
113360          , p_side                     => 'NA'
113361          , p_override_seg_flag        => 'Y'
113362    );
113363 
113364    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
113365 
113366       xla_ae_lines_pkg.set_segment(
113367           p_to_segment_code         => 'GL_BALANCING'
113368         , p_segment_value           => l_segment
113369         , p_from_segment_code       => l_adr_value_segment_code
113370         , p_from_combination_id     => l_adr_value_combination_id
113371         , p_value_type_code         => l_adr_value_type_code
113372         , p_transaction_coa_id      => l_adr_transaction_coa_id
113373         , p_accounting_coa_id       => l_adr_accounting_coa_id
113374         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
113375         , p_flex_value_set_id       => l_adr_flex_value_set_id
113376         , p_adr_code                => 'FA_EXPENSE_ACCT'
113377         , p_adr_type_code           => 'S'
113378         , p_component_type          => l_component_type
113379         , p_component_code          => l_component_code
113380         , p_component_type_code     => l_component_type_code
113381         , p_component_appl_id       => l_component_appl_id
113382         , p_amb_context_code        => l_amb_context_code
113383         , p_entity_code             => 'TRANSACTIONS'
113384         , p_event_class_code        => 'RETIREMENTS'
113385         , p_side                    => 'NA'
113386         );
113387 
113388   END IF;
113389 
113390    --
113391    --
113392    END IF;
113393 
113394        --
113395        -- Update the line information that should be overwritten
113396        --
113397        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
113398                                          p_header_num   => 1);
113399        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
113400 
113401        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
113402 
113403        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
113404           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
113405        END IF;
113406 
113407       --
113408       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
113409       --
113410       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
113411           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
113412       ELSE
113413           ---------------------------------------------------------------------------------------------------
113414           -- 4262811a Switch Sign
113415           ---------------------------------------------------------------------------------------------------
113416           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
113417           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
113418                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
113419           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
113420                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
113421           -- 5132302
113422           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
113423                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
113424 
113425       END IF;
113426 
113427       -- 4955764
113428       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
113429       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
113430 
113431 
113432       XLA_AE_LINES_PKG.ValidateCurrentLine;
113433       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
113434 
113435       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
113436                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
113437                ,p_balance_type_code => l_balance_type_code);
113438 
113439    END IF;
113440 
113441    -----------------------------------------------------------------------------------------
113442    -- 4262811 Multiperiod Accounting
113443    -----------------------------------------------------------------------------------------
113444      -- No MPA option is assigned.
113445 
113446 
113450 
113447 END IF;
113448 END IF;
113449 --
113451 --
113452 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
113453    trace
113454       (p_msg      => 'END of AcctLineType_312'
113455       ,p_level    => C_LEVEL_PROCEDURE
113456       ,p_module   => l_log_module);
113457 END IF;
113458 --
113459 EXCEPTION
113460   WHEN xla_exceptions_pkg.application_exception THEN
113461       RAISE;
113462   WHEN OTHERS THEN
113463        xla_exceptions_pkg.raise_message
113464            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_312');
113465 END AcctLineType_312;
113466 --
113467 
113468 ---------------------------------------
113469 --
113470 -- PRIVATE FUNCTION
113471 --         AcctLineType_313
113472 --
113473 ---------------------------------------
113474 PROCEDURE AcctLineType_313 (
113475   p_application_id        IN NUMBER
113476  ,p_event_id              IN NUMBER
113477  ,p_calculate_acctd_flag  IN VARCHAR2
113478  ,p_calculate_g_l_flag    IN VARCHAR2
113479  ,p_actual_flag           IN OUT VARCHAR2
113480  ,p_balance_type_code     OUT VARCHAR2
113481  ,p_gain_or_loss_ref      OUT VARCHAR2
113482  
113483 --Period Close Date
113484  , p_source_1            IN DATE
113485 --Generated Code Combination Identifier
113486  , p_source_3            IN NUMBER
113487 --Revaluation Reserve Account
113488  , p_source_11            IN VARCHAR2
113489 --Generated Offset Code Combination Identifier
113490  , p_source_17            IN NUMBER
113491 --Expense Account Code Combination Identifier
113492  , p_source_29            IN NUMBER
113493 --Default Code Combination Identifier
113494  , p_source_30            IN NUMBER
113495 --Adjustment Type
113496  , p_source_35            IN VARCHAR2
113497 --Transaction Header Identifier
113498  , p_source_36            IN NUMBER
113499 --Adjustment Line Identifier
113500  , p_source_37            IN NUMBER
113501 --Distribution Type Code
113502  , p_source_38            IN VARCHAR2
113503 --Entered Amount
113504  , p_source_39            IN NUMBER
113505 --Currency Code
113506  , p_source_40            IN VARCHAR2
113507 )
113508 IS
113509 
113510 l_component_type              VARCHAR2(80);
113511 l_component_code              VARCHAR2(30);
113512 l_component_type_code         VARCHAR2(1);
113513 l_component_appl_id           INTEGER;
113514 l_amb_context_code            VARCHAR2(30);
113515 l_entity_code                 VARCHAR2(30);
113516 l_event_class_code            VARCHAR2(30);
113517 l_ae_header_id                NUMBER;
113518 l_event_type_code             VARCHAR2(30);
113519 l_line_definition_code        VARCHAR2(30);
113520 l_line_definition_owner_code  VARCHAR2(1);
113521 --
113522 -- adr variables
113523 l_segment                     VARCHAR2(30);
113524 l_ccid                        NUMBER;
113525 l_adr_transaction_coa_id      NUMBER;
113526 l_adr_accounting_coa_id       NUMBER;
113527 l_adr_flexfield_segment_code  VARCHAR2(30);
113528 l_adr_flex_value_set_id       NUMBER;
113529 l_adr_value_type_code         VARCHAR2(30);
113530 l_adr_value_combination_id    NUMBER;
113531 l_adr_value_segment_code      VARCHAR2(30);
113532 
113533 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
113534 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
113535 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
113536 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
113537 
113538 -- 4262811 Variables ------------------------------------------------------------------------------------------
113539 l_entered_amt_idx             NUMBER;
113540 l_accted_amt_idx              NUMBER;
113541 l_acc_rev_flag                VARCHAR2(1);
113542 l_accrual_line_num            NUMBER;
113543 l_tmp_amt                     NUMBER;
113544 l_acc_rev_natural_side_code   VARCHAR2(1);
113545 
113546 l_num_entries                 NUMBER;
113547 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
113548 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
113549 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
113550 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
113551 l_recog_line_1                NUMBER;
113552 l_recog_line_2                NUMBER;
113553 
113554 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
113555 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
113556 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
113557 
113558 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
113559 
113560 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
113561 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
113562 
113563 ---------------------------------------------------------------------------------------------------------------
113564 
113565 
113566 --
113567 -- bulk performance
113568 --
113569 l_balance_type_code           VARCHAR2(1);
113570 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
113571 l_log_module                  VARCHAR2(240);
113572 
113573 --
113574 -- Upgrade strategy
113575 --
113576 l_actual_upg_option           VARCHAR2(1);
113577 l_enc_upg_option           VARCHAR2(1);
113578 
113579 --
113580 BEGIN
113581 --
113582 IF g_log_enabled THEN
113583       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_313';
113584 END IF;
113585 --
113586 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
113587 
113588       trace
113589          (p_msg      => 'BEGIN of AcctLineType_313'
113590          ,p_level    => C_LEVEL_PROCEDURE
113591          ,p_module   => l_log_module);
113592 
113593 END IF;
113594 --
113595 l_component_type             := 'AMB_JLT';
113596 l_component_code             := 'FA_RET_REVAL_RESERVE';
113600 l_entity_code                := 'TRANSACTIONS';
113597 l_component_type_code        := 'S';
113598 l_component_appl_id          :=  140;
113599 l_amb_context_code           := 'DEFAULT';
113601 l_event_class_code           := 'RETIREMENTS';
113602 l_event_type_code            := 'REINSTATEMENTS';
113603 l_line_definition_owner_code := 'S';
113604 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
113605 --
113606 l_balance_type_code          := 'A';
113607 l_segment                     := NULL;
113608 l_ccid                        := NULL;
113609 l_adr_transaction_coa_id      := NULL;
113610 l_adr_accounting_coa_id       := NULL;
113611 l_adr_flexfield_segment_code  := NULL;
113612 l_adr_flex_value_set_id       := NULL;
113613 l_adr_value_type_code         := NULL;
113614 l_adr_value_combination_id    := NULL;
113615 l_adr_value_segment_code      := NULL;
113616 
113617 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
113618 l_bflow_class_code           := '';    -- 4219869 Business Flow
113619 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
113620 l_budgetary_control_flag     := 'N';
113621 
113622 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
113623 l_bflow_applied_to_amt       := NULL; -- 5132302
113624 l_entered_amt_idx            := NULL;          -- 4262811
113625 l_accted_amt_idx             := NULL;          -- 4262811
113626 l_acc_rev_flag               := NULL;          -- 4262811
113627 l_accrual_line_num           := NULL;          -- 4262811
113628 l_tmp_amt                    := NULL;          -- 4262811
113629 --
113630  
113631 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
113632     l_balance_type_code <> 'B' THEN
113633 IF NVL(p_source_35,'
113634 ') =  'REVAL RESERVE'
113635  THEN 
113636 
113637    --
113638    XLA_AE_LINES_PKG.SetNewLine;
113639 
113640    p_balance_type_code          := l_balance_type_code;
113641    -- set the flag so later we will know whether the gain loss line needs to be created
113642    
113643    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
113644      p_actual_flag :='A';
113645    END IF;
113646 
113647    --
113648    -- bulk performance
113649    --
113650    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
113651                                       p_header_num   => 0); -- 4262811
113652    --
113653    -- set accounting line options
113654    --
113655    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
113656            p_natural_side_code          => 'D'
113657          , p_gain_or_loss_flag          => 'N'
113658          , p_gl_transfer_mode_code      => 'S'
113659          , p_acct_entry_type_code       => 'A'
113660          , p_switch_side_flag           => 'Y'
113661          , p_merge_duplicate_code       => 'N'
113662          );
113663    --
113664    l_acc_rev_natural_side_code := 'C';  -- 4262811
113665    -- 
113666    --
113667    -- set accounting line type info
113668    --
113669    xla_ae_lines_pkg.SetAcctLineType
113670       (p_component_type             => l_component_type
113671       ,p_event_type_code            => l_event_type_code
113672       ,p_line_definition_owner_code => l_line_definition_owner_code
113673       ,p_line_definition_code       => l_line_definition_code
113674       ,p_accounting_line_code       => l_component_code
113675       ,p_accounting_line_type_code  => l_component_type_code
113676       ,p_accounting_line_appl_id    => l_component_appl_id
113677       ,p_amb_context_code           => l_amb_context_code
113678       ,p_entity_code                => l_entity_code
113679       ,p_event_class_code           => l_event_class_code);
113680    --
113681    -- set accounting class
113682    --
113683    xla_ae_lines_pkg.SetAcctClass(
113684            p_accounting_class_code  => 'ASSET'
113685          , p_ae_header_id           => l_ae_header_id
113686          );
113687 
113688    --
113689    -- set rounding class
113690    --
113691    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
113692                       'ASSET';
113693 
113694    --
113695    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
113696    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
113697    --
113698    -- bulk performance
113699    --
113700    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
113701 
113702    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
113703       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
113704 
113705    -- 4955764
113706    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
113707       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
113708 
113709    -- 4458381 Public Sector Enh
113710    
113711    --
113712    -- set accounting attributes for the line type
113713    --
113714    l_entered_amt_idx := 4;
113715    l_accted_amt_idx  := 6;
113716    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
113717    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
113718    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
113719    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
113720    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
113721    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
113722    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
113723    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
113724    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
113725    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
113726    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
113730    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
113727    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
113728    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
113729 
113731    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
113732 
113733    ---------------------------------------------------------------------------------------------------------------
113734    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
113735    ---------------------------------------------------------------------------------------------------------------
113736    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
113737 
113738    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
113739    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
113740 
113741    IF xla_accounting_cache_pkg.GetValueChar
113742          (p_source_code         => 'LEDGER_CATEGORY_CODE'
113743          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
113744    AND l_bflow_method_code = 'PRIOR_ENTRY'
113745 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
113746    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
113747          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
113748        )
113749    THEN
113750          xla_ae_lines_pkg.BflowUpgEntry
113751            (p_business_method_code    => l_bflow_method_code
113752            ,p_business_class_code     => l_bflow_class_code
113753            ,p_balance_type            => l_balance_type_code);
113754    ELSE
113755       NULL;
113756 -- No business flow processing for business flow method of NONE.
113757    END IF;
113758 
113759    --
113760    -- call analytical criteria
113761    --
113762    
113763    --
113764    -- call description
113765    --
113766    
113767 xla_ae_lines_pkg.SetLineDescription(
113768    p_ae_header_id => l_ae_header_id
113769   ,p_description  => Description_83 (
113770      p_application_id         => p_application_id
113771    , p_ae_header_id           => l_ae_header_id 
113772 , p_source_1 => p_source_1
113773    )
113774 );
113775 
113776 
113777    --
113778    -- call ADRs
113779    -- Bug 4922099
113780    --
113781    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
113782         (NVL(l_actual_upg_option, 'N') = 'O') OR
113783         (NVL(l_enc_upg_option, 'N') = 'O')
113784       )
113785    THEN
113786    NULL;
113787    --
113788    --
113789    
113790   l_ccid := AcctDerRule_174(
113791            p_application_id           => p_application_id
113792          , p_ae_header_id             => l_ae_header_id 
113793 , p_source_3 => p_source_3
113794 , p_source_17 => p_source_17
113795 , p_source_30 => p_source_30
113796          , x_transaction_coa_id       => l_adr_transaction_coa_id
113797          , x_accounting_coa_id        => l_adr_accounting_coa_id
113798          , x_value_type_code          => l_adr_value_type_code
113799          , p_side                     => 'NA'
113800    );
113801 
113802    xla_ae_lines_pkg.set_ccid(
113803     p_code_combination_id          => l_ccid
113804   , p_value_type_code              => l_adr_value_type_code
113805   , p_transaction_coa_id           => l_adr_transaction_coa_id
113806   , p_accounting_coa_id            => l_adr_accounting_coa_id
113807   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
113808   , p_adr_type_code                => 'S'
113809   , p_component_type               => l_component_type
113810   , p_component_code               => l_component_code
113811   , p_component_type_code          => l_component_type_code
113812   , p_component_appl_id            => l_component_appl_id
113813   , p_amb_context_code             => l_amb_context_code
113814   , p_side                         => 'NA'
113815   );
113816 
113817 
113818    l_segment := AcctDerRule_150(
113819            p_application_id           => p_application_id
113820          , p_ae_header_id             => l_ae_header_id 
113821 , p_source_3 => p_source_3
113822 , p_source_11 => p_source_11
113823          , x_transaction_coa_id       => l_adr_transaction_coa_id
113824          , x_accounting_coa_id        => l_adr_accounting_coa_id
113825          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
113826          , x_flex_value_set_id        => l_adr_flex_value_set_id
113827          , x_value_type_code          => l_adr_value_type_code
113828          , x_value_combination_id     => l_adr_value_combination_id
113829          , x_value_segment_code       => l_adr_value_segment_code
113830          , p_side                     => 'NA'
113831          , p_override_seg_flag        => 'Y'
113832    );
113833 
113834    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
113835 
113836       xla_ae_lines_pkg.set_segment(
113837           p_to_segment_code         => 'GL_ACCOUNT'
113838         , p_segment_value           => l_segment
113839         , p_from_segment_code       => l_adr_value_segment_code
113840         , p_from_combination_id     => l_adr_value_combination_id
113841         , p_value_type_code         => l_adr_value_type_code
113842         , p_transaction_coa_id      => l_adr_transaction_coa_id
113843         , p_accounting_coa_id       => l_adr_accounting_coa_id
113844         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
113845         , p_flex_value_set_id       => l_adr_flex_value_set_id
113846         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
113847         , p_adr_type_code           => 'S'
113848         , p_component_type          => l_component_type
113849         , p_component_code          => l_component_code
113850         , p_component_type_code     => l_component_type_code
113851         , p_component_appl_id       => l_component_appl_id
113855         , p_side                    => 'NA'
113852         , p_amb_context_code        => l_amb_context_code
113853         , p_entity_code             => 'TRANSACTIONS'
113854         , p_event_class_code        => 'RETIREMENTS'
113856         );
113857 
113858   END IF;
113859 
113860    l_segment := AcctDerRule_168(
113861            p_application_id           => p_application_id
113862          , p_ae_header_id             => l_ae_header_id 
113863 , p_source_3 => p_source_3
113864 , p_source_29 => p_source_29
113865          , x_transaction_coa_id       => l_adr_transaction_coa_id
113866          , x_accounting_coa_id        => l_adr_accounting_coa_id
113867          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
113868          , x_flex_value_set_id        => l_adr_flex_value_set_id
113869          , x_value_type_code          => l_adr_value_type_code
113870          , x_value_combination_id     => l_adr_value_combination_id
113871          , x_value_segment_code       => l_adr_value_segment_code
113872          , p_side                     => 'NA'
113873          , p_override_seg_flag        => 'Y'
113874    );
113875 
113876    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
113877 
113878       xla_ae_lines_pkg.set_segment(
113879           p_to_segment_code         => 'GL_BALANCING'
113880         , p_segment_value           => l_segment
113881         , p_from_segment_code       => l_adr_value_segment_code
113882         , p_from_combination_id     => l_adr_value_combination_id
113883         , p_value_type_code         => l_adr_value_type_code
113884         , p_transaction_coa_id      => l_adr_transaction_coa_id
113885         , p_accounting_coa_id       => l_adr_accounting_coa_id
113886         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
113887         , p_flex_value_set_id       => l_adr_flex_value_set_id
113888         , p_adr_code                => 'FA_EXPENSE_ACCT'
113889         , p_adr_type_code           => 'S'
113890         , p_component_type          => l_component_type
113891         , p_component_code          => l_component_code
113892         , p_component_type_code     => l_component_type_code
113893         , p_component_appl_id       => l_component_appl_id
113894         , p_amb_context_code        => l_amb_context_code
113895         , p_entity_code             => 'TRANSACTIONS'
113896         , p_event_class_code        => 'RETIREMENTS'
113897         , p_side                    => 'NA'
113898         );
113899 
113900   END IF;
113901 
113902    --
113903    --
113904    END IF;
113905    --
113906    -- Bug 4922099
113907    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
113908           (NVL(l_enc_upg_option, 'N') = 'O')
113909         ) AND
113910         (l_bflow_method_code = 'PRIOR_ENTRY')
113911       )
113912    THEN
113913       IF
113914       --
113915       1 = 2
113916       --
113917       THEN
113918       xla_accounting_err_pkg.build_message
113919                                     (p_appli_s_name            => 'XLA'
113920                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
113921                                     ,p_token_1                 => 'LINE_NUMBER'
113922                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
113923                                     ,p_token_2                 => 'LINE_TYPE_NAME'
113924                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
113925                                                                              l_component_type
113926                                                                             ,l_component_code
113927                                                                             ,l_component_type_code
113928                                                                             ,l_component_appl_id
113929                                                                             ,l_amb_context_code
113930                                                                             ,l_entity_code
113931                                                                             ,l_event_class_code
113932                                                                            )
113933                                     ,p_token_3                 => 'OWNER'
113934                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
113935                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
113936                                                                           ,p_lookup_code    => l_component_type_code
113937                                                                          )
113938                                     ,p_token_4                 => 'PRODUCT_NAME'
113939                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
113940                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
113941                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
113942                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
113943                                     ,p_ae_header_id            =>  NULL
113944                                        );
113945 
113946         IF (C_LEVEL_ERROR>= g_log_level) THEN
113947                  trace
113948                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
113949                       ,p_level    => C_LEVEL_ERROR
113950                       ,p_module   => l_log_module);
113951         END IF;
113952       END IF;
113953    END IF;
113954    --
113955    --
113956    ------------------------------------------------------------------------------------------------
113957    -- 4219869 Business Flow
113958    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
113959    -- Prior Entry.  Currently, the following code is always generated.
113963    ------------------------------------------------------------------------------------
113960    ------------------------------------------------------------------------------------------------
113961    XLA_AE_LINES_PKG.ValidateCurrentLine;
113962 
113964    -- 4219869 Business Flow
113965    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
113966    ------------------------------------------------------------------------------------
113967    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
113968 
113969    ----------------------------------------------------------------------------------
113970    -- 4219869 Business Flow
113971    -- Update journal entry status -- Need to generate this within IF <condition>
113972    ----------------------------------------------------------------------------------
113973    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
113974          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
113975          ,p_balance_type_code => l_balance_type_code
113976          );
113977 
113978    -------------------------------------------------------------------------------------------
113979    -- 4262811 - Generate the Accrual Reversal lines
113980    -------------------------------------------------------------------------------------------
113981    BEGIN
113982       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
113983                               (g_array_event(p_event_id).array_value_num('header_index'));
113984       IF l_acc_rev_flag IS NULL THEN
113985          l_acc_rev_flag := 'N';
113986       END IF;
113987    EXCEPTION
113988       WHEN OTHERS THEN
113989          l_acc_rev_flag := 'N';
113990    END;
113991    --
113992    IF (l_acc_rev_flag = 'Y') THEN
113993 
113994        -- 4645092  ------------------------------------------------------------------------------
113995        -- To allow MPA report to determine if it should generate report process
113996        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
113997        ------------------------------------------------------------------------------------------
113998 
113999        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
114000        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
114001    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
114002    -- call ADRs
114003    -- Bug 4922099
114004    --
114005    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
114006         (NVL(l_actual_upg_option, 'N') = 'O') OR
114007         (NVL(l_enc_upg_option, 'N') = 'O')
114008       )
114009    THEN
114010    NULL;
114011    --
114012    --
114013    
114014   l_ccid := AcctDerRule_174(
114015            p_application_id           => p_application_id
114016          , p_ae_header_id             => l_ae_header_id 
114017 , p_source_3 => p_source_3
114018 , p_source_17 => p_source_17
114019 , p_source_30 => p_source_30
114020          , x_transaction_coa_id       => l_adr_transaction_coa_id
114021          , x_accounting_coa_id        => l_adr_accounting_coa_id
114022          , x_value_type_code          => l_adr_value_type_code
114023          , p_side                     => 'NA'
114024    );
114025 
114026    xla_ae_lines_pkg.set_ccid(
114027     p_code_combination_id          => l_ccid
114028   , p_value_type_code              => l_adr_value_type_code
114029   , p_transaction_coa_id           => l_adr_transaction_coa_id
114030   , p_accounting_coa_id            => l_adr_accounting_coa_id
114031   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
114032   , p_adr_type_code                => 'S'
114033   , p_component_type               => l_component_type
114034   , p_component_code               => l_component_code
114035   , p_component_type_code          => l_component_type_code
114036   , p_component_appl_id            => l_component_appl_id
114037   , p_amb_context_code             => l_amb_context_code
114038   , p_side                         => 'NA'
114039   );
114040 
114041 
114042    l_segment := AcctDerRule_150(
114043            p_application_id           => p_application_id
114044          , p_ae_header_id             => l_ae_header_id 
114045 , p_source_3 => p_source_3
114046 , p_source_11 => p_source_11
114047          , x_transaction_coa_id       => l_adr_transaction_coa_id
114048          , x_accounting_coa_id        => l_adr_accounting_coa_id
114049          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
114050          , x_flex_value_set_id        => l_adr_flex_value_set_id
114051          , x_value_type_code          => l_adr_value_type_code
114052          , x_value_combination_id     => l_adr_value_combination_id
114053          , x_value_segment_code       => l_adr_value_segment_code
114054          , p_side                     => 'NA'
114055          , p_override_seg_flag        => 'Y'
114056    );
114057 
114058    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
114059 
114060       xla_ae_lines_pkg.set_segment(
114061           p_to_segment_code         => 'GL_ACCOUNT'
114062         , p_segment_value           => l_segment
114063         , p_from_segment_code       => l_adr_value_segment_code
114064         , p_from_combination_id     => l_adr_value_combination_id
114065         , p_value_type_code         => l_adr_value_type_code
114066         , p_transaction_coa_id      => l_adr_transaction_coa_id
114067         , p_accounting_coa_id       => l_adr_accounting_coa_id
114068         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
114069         , p_flex_value_set_id       => l_adr_flex_value_set_id
114070         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
114071         , p_adr_type_code           => 'S'
114072         , p_component_type          => l_component_type
114073         , p_component_code          => l_component_code
114074         , p_component_type_code     => l_component_type_code
114075         , p_component_appl_id       => l_component_appl_id
114076         , p_amb_context_code        => l_amb_context_code
114080         );
114077         , p_entity_code             => 'TRANSACTIONS'
114078         , p_event_class_code        => 'RETIREMENTS'
114079         , p_side                    => 'NA'
114081 
114082   END IF;
114083 
114084    l_segment := AcctDerRule_168(
114085            p_application_id           => p_application_id
114086          , p_ae_header_id             => l_ae_header_id 
114087 , p_source_3 => p_source_3
114088 , p_source_29 => p_source_29
114089          , x_transaction_coa_id       => l_adr_transaction_coa_id
114090          , x_accounting_coa_id        => l_adr_accounting_coa_id
114091          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
114092          , x_flex_value_set_id        => l_adr_flex_value_set_id
114093          , x_value_type_code          => l_adr_value_type_code
114094          , x_value_combination_id     => l_adr_value_combination_id
114095          , x_value_segment_code       => l_adr_value_segment_code
114096          , p_side                     => 'NA'
114097          , p_override_seg_flag        => 'Y'
114098    );
114099 
114100    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
114101 
114102       xla_ae_lines_pkg.set_segment(
114103           p_to_segment_code         => 'GL_BALANCING'
114104         , p_segment_value           => l_segment
114105         , p_from_segment_code       => l_adr_value_segment_code
114106         , p_from_combination_id     => l_adr_value_combination_id
114107         , p_value_type_code         => l_adr_value_type_code
114108         , p_transaction_coa_id      => l_adr_transaction_coa_id
114109         , p_accounting_coa_id       => l_adr_accounting_coa_id
114110         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
114111         , p_flex_value_set_id       => l_adr_flex_value_set_id
114112         , p_adr_code                => 'FA_EXPENSE_ACCT'
114113         , p_adr_type_code           => 'S'
114114         , p_component_type          => l_component_type
114115         , p_component_code          => l_component_code
114116         , p_component_type_code     => l_component_type_code
114117         , p_component_appl_id       => l_component_appl_id
114118         , p_amb_context_code        => l_amb_context_code
114119         , p_entity_code             => 'TRANSACTIONS'
114120         , p_event_class_code        => 'RETIREMENTS'
114121         , p_side                    => 'NA'
114122         );
114123 
114124   END IF;
114125 
114126    --
114127    --
114128    END IF;
114129 
114130        --
114131        -- Update the line information that should be overwritten
114132        --
114133        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
114134                                          p_header_num   => 1);
114135        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
114136 
114137        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
114138 
114139        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
114140           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
114141        END IF;
114142 
114143       --
114144       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
114145       --
114146       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
114147           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
114148       ELSE
114149           ---------------------------------------------------------------------------------------------------
114150           -- 4262811a Switch Sign
114151           ---------------------------------------------------------------------------------------------------
114152           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
114153           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
114154                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
114155           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
114156                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
114157           -- 5132302
114158           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
114159                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
114160 
114161       END IF;
114162 
114163       -- 4955764
114164       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
114165       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
114166 
114167 
114168       XLA_AE_LINES_PKG.ValidateCurrentLine;
114169       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
114170 
114171       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
114172                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
114173                ,p_balance_type_code => l_balance_type_code);
114174 
114175    END IF;
114176 
114177    -----------------------------------------------------------------------------------------
114178    -- 4262811 Multiperiod Accounting
114179    -----------------------------------------------------------------------------------------
114180      -- No MPA option is assigned.
114181 
114182 
114183 END IF;
114184 END IF;
114185 --
114186 
114187 --
114188 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
114189    trace
114190       (p_msg      => 'END of AcctLineType_313'
114191       ,p_level    => C_LEVEL_PROCEDURE
114192       ,p_module   => l_log_module);
114193 END IF;
114194 --
114195 EXCEPTION
114196   WHEN xla_exceptions_pkg.application_exception THEN
114197       RAISE;
114198   WHEN OTHERS THEN
114202 --
114199        xla_exceptions_pkg.raise_message
114200            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_313');
114201 END AcctLineType_313;
114203 
114204 ---------------------------------------
114205 --
114206 -- PRIVATE FUNCTION
114207 --         AcctLineType_314
114208 --
114209 ---------------------------------------
114210 PROCEDURE AcctLineType_314 (
114211   p_application_id        IN NUMBER
114212  ,p_event_id              IN NUMBER
114213  ,p_calculate_acctd_flag  IN VARCHAR2
114214  ,p_calculate_g_l_flag    IN VARCHAR2
114215  ,p_actual_flag           IN OUT VARCHAR2
114216  ,p_balance_type_code     OUT VARCHAR2
114217  ,p_gain_or_loss_ref      OUT VARCHAR2
114218  
114219 --Period Close Date
114220  , p_source_1            IN DATE
114221 --Generated Code Combination Identifier
114222  , p_source_3            IN NUMBER
114223 --Revaluation Reserve Retired Gain Account
114224  , p_source_27            IN VARCHAR2
114225 --Expense Account Code Combination Identifier
114226  , p_source_29            IN NUMBER
114227 --Default Code Combination Identifier
114228  , p_source_30            IN NUMBER
114229 --Adjustment Type
114230  , p_source_35            IN VARCHAR2
114231 --Transaction Header Identifier
114232  , p_source_36            IN NUMBER
114233 --Adjustment Line Identifier
114234  , p_source_37            IN NUMBER
114235 --Distribution Type Code
114236  , p_source_38            IN VARCHAR2
114237 --Entered Amount
114238  , p_source_39            IN NUMBER
114239 --Currency Code
114240  , p_source_40            IN VARCHAR2
114241 --Gain Loss Amount
114242  , p_source_41            IN NUMBER
114243 )
114244 IS
114245 
114246 l_component_type              VARCHAR2(80);
114247 l_component_code              VARCHAR2(30);
114248 l_component_type_code         VARCHAR2(1);
114249 l_component_appl_id           INTEGER;
114250 l_amb_context_code            VARCHAR2(30);
114251 l_entity_code                 VARCHAR2(30);
114252 l_event_class_code            VARCHAR2(30);
114253 l_ae_header_id                NUMBER;
114254 l_event_type_code             VARCHAR2(30);
114255 l_line_definition_code        VARCHAR2(30);
114256 l_line_definition_owner_code  VARCHAR2(1);
114257 --
114258 -- adr variables
114259 l_segment                     VARCHAR2(30);
114260 l_ccid                        NUMBER;
114261 l_adr_transaction_coa_id      NUMBER;
114262 l_adr_accounting_coa_id       NUMBER;
114263 l_adr_flexfield_segment_code  VARCHAR2(30);
114264 l_adr_flex_value_set_id       NUMBER;
114265 l_adr_value_type_code         VARCHAR2(30);
114266 l_adr_value_combination_id    NUMBER;
114267 l_adr_value_segment_code      VARCHAR2(30);
114268 
114269 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
114270 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
114271 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
114272 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
114273 
114274 -- 4262811 Variables ------------------------------------------------------------------------------------------
114275 l_entered_amt_idx             NUMBER;
114276 l_accted_amt_idx              NUMBER;
114277 l_acc_rev_flag                VARCHAR2(1);
114278 l_accrual_line_num            NUMBER;
114279 l_tmp_amt                     NUMBER;
114280 l_acc_rev_natural_side_code   VARCHAR2(1);
114281 
114282 l_num_entries                 NUMBER;
114283 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
114284 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
114285 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
114286 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
114287 l_recog_line_1                NUMBER;
114288 l_recog_line_2                NUMBER;
114289 
114290 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
114291 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
114292 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
114293 
114294 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
114295 
114296 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
114297 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
114298 
114299 ---------------------------------------------------------------------------------------------------------------
114300 
114301 
114302 --
114303 -- bulk performance
114304 --
114305 l_balance_type_code           VARCHAR2(1);
114306 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
114307 l_log_module                  VARCHAR2(240);
114308 
114309 --
114310 -- Upgrade strategy
114311 --
114312 l_actual_upg_option           VARCHAR2(1);
114313 l_enc_upg_option           VARCHAR2(1);
114314 
114315 --
114316 BEGIN
114317 --
114318 IF g_log_enabled THEN
114319       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_314';
114320 END IF;
114321 --
114322 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
114323 
114324       trace
114325          (p_msg      => 'BEGIN of AcctLineType_314'
114326          ,p_level    => C_LEVEL_PROCEDURE
114327          ,p_module   => l_log_module);
114328 
114329 END IF;
114330 --
114331 l_component_type             := 'AMB_JLT';
114332 l_component_code             := 'FA_RET_REVAL_RESERVE_GAIN';
114333 l_component_type_code        := 'S';
114334 l_component_appl_id          :=  140;
114335 l_amb_context_code           := 'DEFAULT';
114336 l_entity_code                := 'TRANSACTIONS';
114337 l_event_class_code           := 'RETIREMENTS';
114338 l_event_type_code            := 'REINSTATEMENTS';
114339 l_line_definition_owner_code := 'S';
114340 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
114341 --
114342 l_balance_type_code          := 'A';
114346 l_adr_accounting_coa_id       := NULL;
114343 l_segment                     := NULL;
114344 l_ccid                        := NULL;
114345 l_adr_transaction_coa_id      := NULL;
114347 l_adr_flexfield_segment_code  := NULL;
114348 l_adr_flex_value_set_id       := NULL;
114349 l_adr_value_type_code         := NULL;
114350 l_adr_value_combination_id    := NULL;
114351 l_adr_value_segment_code      := NULL;
114352 
114353 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
114354 l_bflow_class_code           := '';    -- 4219869 Business Flow
114355 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
114356 l_budgetary_control_flag     := 'N';
114357 
114358 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
114359 l_bflow_applied_to_amt       := NULL; -- 5132302
114360 l_entered_amt_idx            := NULL;          -- 4262811
114361 l_accted_amt_idx             := NULL;          -- 4262811
114362 l_acc_rev_flag               := NULL;          -- 4262811
114363 l_accrual_line_num           := NULL;          -- 4262811
114364 l_tmp_amt                    := NULL;          -- 4262811
114365 --
114366  
114367 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
114368     l_balance_type_code <> 'B' THEN
114369 IF NVL(p_source_35,'
114370 ') =  'REVAL RSV RET' AND 
114371 p_source_41 >=  0
114372  THEN 
114373 
114374    --
114375    XLA_AE_LINES_PKG.SetNewLine;
114376 
114377    p_balance_type_code          := l_balance_type_code;
114378    -- set the flag so later we will know whether the gain loss line needs to be created
114379    
114380    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
114381      p_actual_flag :='A';
114382    END IF;
114383 
114384    --
114385    -- bulk performance
114386    --
114387    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
114388                                       p_header_num   => 0); -- 4262811
114389    --
114390    -- set accounting line options
114391    --
114392    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
114393            p_natural_side_code          => 'C'
114394          , p_gain_or_loss_flag          => 'N'
114395          , p_gl_transfer_mode_code      => 'S'
114396          , p_acct_entry_type_code       => 'A'
114397          , p_switch_side_flag           => 'Y'
114398          , p_merge_duplicate_code       => 'N'
114399          );
114400    --
114401    l_acc_rev_natural_side_code := 'D';  -- 4262811
114402    -- 
114403    --
114404    -- set accounting line type info
114405    --
114406    xla_ae_lines_pkg.SetAcctLineType
114407       (p_component_type             => l_component_type
114408       ,p_event_type_code            => l_event_type_code
114409       ,p_line_definition_owner_code => l_line_definition_owner_code
114410       ,p_line_definition_code       => l_line_definition_code
114411       ,p_accounting_line_code       => l_component_code
114412       ,p_accounting_line_type_code  => l_component_type_code
114413       ,p_accounting_line_appl_id    => l_component_appl_id
114414       ,p_amb_context_code           => l_amb_context_code
114415       ,p_entity_code                => l_entity_code
114416       ,p_event_class_code           => l_event_class_code);
114417    --
114418    -- set accounting class
114419    --
114420    xla_ae_lines_pkg.SetAcctClass(
114421            p_accounting_class_code  => 'ASSET'
114422          , p_ae_header_id           => l_ae_header_id
114423          );
114424 
114425    --
114426    -- set rounding class
114427    --
114428    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
114429                       'ASSET';
114430 
114431    --
114432    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
114433    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
114434    --
114435    -- bulk performance
114436    --
114437    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
114438 
114439    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
114440       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
114441 
114442    -- 4955764
114443    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
114444       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
114445 
114446    -- 4458381 Public Sector Enh
114447    
114448    --
114449    -- set accounting attributes for the line type
114450    --
114451    l_entered_amt_idx := 4;
114452    l_accted_amt_idx  := 6;
114453    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
114454    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
114455    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
114456    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
114457    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
114458    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
114459    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
114460    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
114461    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
114462    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
114463    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
114464    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
114465    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
114466 
114467    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
114468    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
114469 
114470    ---------------------------------------------------------------------------------------------------------------
114474 
114471    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
114472    ---------------------------------------------------------------------------------------------------------------
114473    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
114475    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
114476    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
114477 
114478    IF xla_accounting_cache_pkg.GetValueChar
114479          (p_source_code         => 'LEDGER_CATEGORY_CODE'
114480          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
114481    AND l_bflow_method_code = 'PRIOR_ENTRY'
114482 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
114483    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
114484          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
114485        )
114486    THEN
114487          xla_ae_lines_pkg.BflowUpgEntry
114488            (p_business_method_code    => l_bflow_method_code
114489            ,p_business_class_code     => l_bflow_class_code
114490            ,p_balance_type            => l_balance_type_code);
114491    ELSE
114492       NULL;
114493 -- No business flow processing for business flow method of NONE.
114494    END IF;
114495 
114496    --
114497    -- call analytical criteria
114498    --
114499    
114500    --
114501    -- call description
114502    --
114503    
114504 xla_ae_lines_pkg.SetLineDescription(
114505    p_ae_header_id => l_ae_header_id
114506   ,p_description  => Description_83 (
114507      p_application_id         => p_application_id
114508    , p_ae_header_id           => l_ae_header_id 
114509 , p_source_1 => p_source_1
114510    )
114511 );
114512 
114513 
114514    --
114515    -- call ADRs
114516    -- Bug 4922099
114517    --
114518    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
114519         (NVL(l_actual_upg_option, 'N') = 'O') OR
114520         (NVL(l_enc_upg_option, 'N') = 'O')
114521       )
114522    THEN
114523    NULL;
114524    --
114525    --
114526    
114527   l_ccid := AcctDerRule_173(
114528            p_application_id           => p_application_id
114529          , p_ae_header_id             => l_ae_header_id 
114530 , p_source_3 => p_source_3
114531 , p_source_30 => p_source_30
114532          , x_transaction_coa_id       => l_adr_transaction_coa_id
114533          , x_accounting_coa_id        => l_adr_accounting_coa_id
114534          , x_value_type_code          => l_adr_value_type_code
114535          , p_side                     => 'NA'
114536    );
114537 
114538    xla_ae_lines_pkg.set_ccid(
114539     p_code_combination_id          => l_ccid
114540   , p_value_type_code              => l_adr_value_type_code
114541   , p_transaction_coa_id           => l_adr_transaction_coa_id
114542   , p_accounting_coa_id            => l_adr_accounting_coa_id
114543   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
114544   , p_adr_type_code                => 'S'
114545   , p_component_type               => l_component_type
114546   , p_component_code               => l_component_code
114547   , p_component_type_code          => l_component_type_code
114548   , p_component_appl_id            => l_component_appl_id
114549   , p_amb_context_code             => l_amb_context_code
114550   , p_side                         => 'NA'
114551   );
114552 
114553 
114554    l_segment := AcctDerRule_168(
114555            p_application_id           => p_application_id
114556          , p_ae_header_id             => l_ae_header_id 
114557 , p_source_3 => p_source_3
114558 , p_source_29 => p_source_29
114559          , x_transaction_coa_id       => l_adr_transaction_coa_id
114560          , x_accounting_coa_id        => l_adr_accounting_coa_id
114561          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
114562          , x_flex_value_set_id        => l_adr_flex_value_set_id
114563          , x_value_type_code          => l_adr_value_type_code
114564          , x_value_combination_id     => l_adr_value_combination_id
114565          , x_value_segment_code       => l_adr_value_segment_code
114566          , p_side                     => 'NA'
114567          , p_override_seg_flag        => 'Y'
114568    );
114569 
114570    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
114571 
114572       xla_ae_lines_pkg.set_segment(
114573           p_to_segment_code         => 'GL_BALANCING'
114574         , p_segment_value           => l_segment
114575         , p_from_segment_code       => l_adr_value_segment_code
114576         , p_from_combination_id     => l_adr_value_combination_id
114577         , p_value_type_code         => l_adr_value_type_code
114578         , p_transaction_coa_id      => l_adr_transaction_coa_id
114579         , p_accounting_coa_id       => l_adr_accounting_coa_id
114580         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
114581         , p_flex_value_set_id       => l_adr_flex_value_set_id
114582         , p_adr_code                => 'FA_EXPENSE_ACCT'
114583         , p_adr_type_code           => 'S'
114584         , p_component_type          => l_component_type
114585         , p_component_code          => l_component_code
114586         , p_component_type_code     => l_component_type_code
114587         , p_component_appl_id       => l_component_appl_id
114588         , p_amb_context_code        => l_amb_context_code
114589         , p_entity_code             => 'TRANSACTIONS'
114590         , p_event_class_code        => 'RETIREMENTS'
114591         , p_side                    => 'NA'
114592         );
114593 
114594   END IF;
114595 
114596    l_segment := AcctDerRule_165(
114597            p_application_id           => p_application_id
114598          , p_ae_header_id             => l_ae_header_id 
114599 , p_source_3 => p_source_3
114603          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
114600 , p_source_27 => p_source_27
114601          , x_transaction_coa_id       => l_adr_transaction_coa_id
114602          , x_accounting_coa_id        => l_adr_accounting_coa_id
114604          , x_flex_value_set_id        => l_adr_flex_value_set_id
114605          , x_value_type_code          => l_adr_value_type_code
114606          , x_value_combination_id     => l_adr_value_combination_id
114607          , x_value_segment_code       => l_adr_value_segment_code
114608          , p_side                     => 'NA'
114609          , p_override_seg_flag        => 'Y'
114610    );
114611 
114612    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
114613 
114614       xla_ae_lines_pkg.set_segment(
114615           p_to_segment_code         => 'GL_ACCOUNT'
114616         , p_segment_value           => l_segment
114617         , p_from_segment_code       => l_adr_value_segment_code
114618         , p_from_combination_id     => l_adr_value_combination_id
114619         , p_value_type_code         => l_adr_value_type_code
114620         , p_transaction_coa_id      => l_adr_transaction_coa_id
114621         , p_accounting_coa_id       => l_adr_accounting_coa_id
114622         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
114623         , p_flex_value_set_id       => l_adr_flex_value_set_id
114624         , p_adr_code                => 'FA_REVAL_RES_RET_GAIN_SEGMENT'
114625         , p_adr_type_code           => 'S'
114626         , p_component_type          => l_component_type
114627         , p_component_code          => l_component_code
114628         , p_component_type_code     => l_component_type_code
114629         , p_component_appl_id       => l_component_appl_id
114630         , p_amb_context_code        => l_amb_context_code
114631         , p_entity_code             => 'TRANSACTIONS'
114632         , p_event_class_code        => 'RETIREMENTS'
114633         , p_side                    => 'NA'
114634         );
114635 
114636   END IF;
114637 
114638    --
114639    --
114640    END IF;
114641    --
114642    -- Bug 4922099
114643    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
114644           (NVL(l_enc_upg_option, 'N') = 'O')
114645         ) AND
114646         (l_bflow_method_code = 'PRIOR_ENTRY')
114647       )
114648    THEN
114649       IF
114650       --
114651       1 = 2
114652       --
114653       THEN
114654       xla_accounting_err_pkg.build_message
114655                                     (p_appli_s_name            => 'XLA'
114656                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
114657                                     ,p_token_1                 => 'LINE_NUMBER'
114658                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
114659                                     ,p_token_2                 => 'LINE_TYPE_NAME'
114660                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
114661                                                                              l_component_type
114662                                                                             ,l_component_code
114663                                                                             ,l_component_type_code
114664                                                                             ,l_component_appl_id
114665                                                                             ,l_amb_context_code
114666                                                                             ,l_entity_code
114667                                                                             ,l_event_class_code
114668                                                                            )
114669                                     ,p_token_3                 => 'OWNER'
114670                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
114671                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
114672                                                                           ,p_lookup_code    => l_component_type_code
114673                                                                          )
114674                                     ,p_token_4                 => 'PRODUCT_NAME'
114675                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
114676                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
114677                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
114678                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
114679                                     ,p_ae_header_id            =>  NULL
114680                                        );
114681 
114682         IF (C_LEVEL_ERROR>= g_log_level) THEN
114683                  trace
114684                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
114685                       ,p_level    => C_LEVEL_ERROR
114686                       ,p_module   => l_log_module);
114687         END IF;
114688       END IF;
114689    END IF;
114690    --
114691    --
114692    ------------------------------------------------------------------------------------------------
114693    -- 4219869 Business Flow
114694    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
114695    -- Prior Entry.  Currently, the following code is always generated.
114696    ------------------------------------------------------------------------------------------------
114697    XLA_AE_LINES_PKG.ValidateCurrentLine;
114698 
114699    ------------------------------------------------------------------------------------
114700    -- 4219869 Business Flow
114701    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
114702    ------------------------------------------------------------------------------------
114706    -- 4219869 Business Flow
114703    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
114704 
114705    ----------------------------------------------------------------------------------
114707    -- Update journal entry status -- Need to generate this within IF <condition>
114708    ----------------------------------------------------------------------------------
114709    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
114710          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
114711          ,p_balance_type_code => l_balance_type_code
114712          );
114713 
114714    -------------------------------------------------------------------------------------------
114715    -- 4262811 - Generate the Accrual Reversal lines
114716    -------------------------------------------------------------------------------------------
114717    BEGIN
114718       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
114719                               (g_array_event(p_event_id).array_value_num('header_index'));
114720       IF l_acc_rev_flag IS NULL THEN
114721          l_acc_rev_flag := 'N';
114722       END IF;
114723    EXCEPTION
114724       WHEN OTHERS THEN
114725          l_acc_rev_flag := 'N';
114726    END;
114727    --
114728    IF (l_acc_rev_flag = 'Y') THEN
114729 
114730        -- 4645092  ------------------------------------------------------------------------------
114731        -- To allow MPA report to determine if it should generate report process
114732        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
114733        ------------------------------------------------------------------------------------------
114734 
114735        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
114736        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
114737    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
114738    -- call ADRs
114739    -- Bug 4922099
114740    --
114741    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
114742         (NVL(l_actual_upg_option, 'N') = 'O') OR
114743         (NVL(l_enc_upg_option, 'N') = 'O')
114744       )
114745    THEN
114746    NULL;
114747    --
114748    --
114749    
114750   l_ccid := AcctDerRule_173(
114751            p_application_id           => p_application_id
114752          , p_ae_header_id             => l_ae_header_id 
114753 , p_source_3 => p_source_3
114754 , p_source_30 => p_source_30
114755          , x_transaction_coa_id       => l_adr_transaction_coa_id
114756          , x_accounting_coa_id        => l_adr_accounting_coa_id
114757          , x_value_type_code          => l_adr_value_type_code
114758          , p_side                     => 'NA'
114759    );
114760 
114761    xla_ae_lines_pkg.set_ccid(
114762     p_code_combination_id          => l_ccid
114763   , p_value_type_code              => l_adr_value_type_code
114764   , p_transaction_coa_id           => l_adr_transaction_coa_id
114765   , p_accounting_coa_id            => l_adr_accounting_coa_id
114766   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
114767   , p_adr_type_code                => 'S'
114768   , p_component_type               => l_component_type
114769   , p_component_code               => l_component_code
114770   , p_component_type_code          => l_component_type_code
114771   , p_component_appl_id            => l_component_appl_id
114772   , p_amb_context_code             => l_amb_context_code
114773   , p_side                         => 'NA'
114774   );
114775 
114776 
114777    l_segment := AcctDerRule_168(
114778            p_application_id           => p_application_id
114779          , p_ae_header_id             => l_ae_header_id 
114780 , p_source_3 => p_source_3
114781 , p_source_29 => p_source_29
114782          , x_transaction_coa_id       => l_adr_transaction_coa_id
114783          , x_accounting_coa_id        => l_adr_accounting_coa_id
114784          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
114785          , x_flex_value_set_id        => l_adr_flex_value_set_id
114786          , x_value_type_code          => l_adr_value_type_code
114787          , x_value_combination_id     => l_adr_value_combination_id
114791    );
114788          , x_value_segment_code       => l_adr_value_segment_code
114789          , p_side                     => 'NA'
114790          , p_override_seg_flag        => 'Y'
114792 
114793    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
114794 
114795       xla_ae_lines_pkg.set_segment(
114796           p_to_segment_code         => 'GL_BALANCING'
114797         , p_segment_value           => l_segment
114798         , p_from_segment_code       => l_adr_value_segment_code
114799         , p_from_combination_id     => l_adr_value_combination_id
114800         , p_value_type_code         => l_adr_value_type_code
114801         , p_transaction_coa_id      => l_adr_transaction_coa_id
114802         , p_accounting_coa_id       => l_adr_accounting_coa_id
114803         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
114804         , p_flex_value_set_id       => l_adr_flex_value_set_id
114805         , p_adr_code                => 'FA_EXPENSE_ACCT'
114806         , p_adr_type_code           => 'S'
114807         , p_component_type          => l_component_type
114808         , p_component_code          => l_component_code
114809         , p_component_type_code     => l_component_type_code
114810         , p_component_appl_id       => l_component_appl_id
114811         , p_amb_context_code        => l_amb_context_code
114812         , p_entity_code             => 'TRANSACTIONS'
114813         , p_event_class_code        => 'RETIREMENTS'
114814         , p_side                    => 'NA'
114815         );
114816 
114817   END IF;
114818 
114819    l_segment := AcctDerRule_165(
114820            p_application_id           => p_application_id
114821          , p_ae_header_id             => l_ae_header_id 
114822 , p_source_3 => p_source_3
114823 , p_source_27 => p_source_27
114824          , x_transaction_coa_id       => l_adr_transaction_coa_id
114825          , x_accounting_coa_id        => l_adr_accounting_coa_id
114826          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
114827          , x_flex_value_set_id        => l_adr_flex_value_set_id
114828          , x_value_type_code          => l_adr_value_type_code
114829          , x_value_combination_id     => l_adr_value_combination_id
114830          , x_value_segment_code       => l_adr_value_segment_code
114831          , p_side                     => 'NA'
114832          , p_override_seg_flag        => 'Y'
114833    );
114834 
114835    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
114836 
114837       xla_ae_lines_pkg.set_segment(
114838           p_to_segment_code         => 'GL_ACCOUNT'
114839         , p_segment_value           => l_segment
114840         , p_from_segment_code       => l_adr_value_segment_code
114841         , p_from_combination_id     => l_adr_value_combination_id
114842         , p_value_type_code         => l_adr_value_type_code
114843         , p_transaction_coa_id      => l_adr_transaction_coa_id
114844         , p_accounting_coa_id       => l_adr_accounting_coa_id
114845         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
114846         , p_flex_value_set_id       => l_adr_flex_value_set_id
114847         , p_adr_code                => 'FA_REVAL_RES_RET_GAIN_SEGMENT'
114848         , p_adr_type_code           => 'S'
114849         , p_component_type          => l_component_type
114850         , p_component_code          => l_component_code
114851         , p_component_type_code     => l_component_type_code
114852         , p_component_appl_id       => l_component_appl_id
114853         , p_amb_context_code        => l_amb_context_code
114854         , p_entity_code             => 'TRANSACTIONS'
114855         , p_event_class_code        => 'RETIREMENTS'
114856         , p_side                    => 'NA'
114857         );
114858 
114859   END IF;
114860 
114861    --
114862    --
114863    END IF;
114864 
114865        --
114866        -- Update the line information that should be overwritten
114867        --
114868        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
114869                                          p_header_num   => 1);
114870        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
114871 
114872        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
114873 
114874        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
114875           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
114876        END IF;
114877 
114878       --
114879       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
114880       --
114881       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
114882           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
114883       ELSE
114884           ---------------------------------------------------------------------------------------------------
114885           -- 4262811a Switch Sign
114886           ---------------------------------------------------------------------------------------------------
114887           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
114888           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
114889                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
114890           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
114891                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
114892           -- 5132302
114893           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
114894                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
114895 
114899       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
114896       END IF;
114897 
114898       -- 4955764
114900       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
114901 
114902 
114903       XLA_AE_LINES_PKG.ValidateCurrentLine;
114904       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
114905 
114906       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
114907                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
114908                ,p_balance_type_code => l_balance_type_code);
114909 
114910    END IF;
114911 
114912    -----------------------------------------------------------------------------------------
114913    -- 4262811 Multiperiod Accounting
114914    -----------------------------------------------------------------------------------------
114915      -- No MPA option is assigned.
114916 
114917 
114918 END IF;
114919 END IF;
114920 --
114921 
114922 --
114926       ,p_level    => C_LEVEL_PROCEDURE
114923 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
114924    trace
114925       (p_msg      => 'END of AcctLineType_314'
114927       ,p_module   => l_log_module);
114928 END IF;
114929 --
114930 EXCEPTION
114931   WHEN xla_exceptions_pkg.application_exception THEN
114932       RAISE;
114933   WHEN OTHERS THEN
114934        xla_exceptions_pkg.raise_message
114935            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_314');
114936 END AcctLineType_314;
114937 --
114938 
114939 ---------------------------------------
114940 --
114941 -- PRIVATE FUNCTION
114942 --         AcctLineType_315
114943 --
114944 ---------------------------------------
114945 PROCEDURE AcctLineType_315 (
114946   p_application_id        IN NUMBER
114947  ,p_event_id              IN NUMBER
114948  ,p_calculate_acctd_flag  IN VARCHAR2
114949  ,p_calculate_g_l_flag    IN VARCHAR2
114950  ,p_actual_flag           IN OUT VARCHAR2
114951  ,p_balance_type_code     OUT VARCHAR2
114952  ,p_gain_or_loss_ref      OUT VARCHAR2
114953  
114954 --Period Close Date
114955  , p_source_1            IN DATE
114956 --Generated Code Combination Identifier
114957  , p_source_3            IN NUMBER
114958 --Revaluation Reserve Retired Gain Account
114959  , p_source_27            IN VARCHAR2
114960 --Expense Account Code Combination Identifier
114961  , p_source_29            IN NUMBER
114962 --Default Code Combination Identifier
114963  , p_source_30            IN NUMBER
114964 --Adjustment Type
114965  , p_source_35            IN VARCHAR2
114966 --Transaction Header Identifier
114967  , p_source_36            IN NUMBER
114968 --Adjustment Line Identifier
114969  , p_source_37            IN NUMBER
114970 --Distribution Type Code
114971  , p_source_38            IN VARCHAR2
114972 --Entered Amount
114973  , p_source_39            IN NUMBER
114974 --Currency Code
114975  , p_source_40            IN VARCHAR2
114976 --Gain Loss Amount
114977  , p_source_41            IN NUMBER
114978 )
114979 IS
114980 
114981 l_component_type              VARCHAR2(80);
114982 l_component_code              VARCHAR2(30);
114983 l_component_type_code         VARCHAR2(1);
114984 l_component_appl_id           INTEGER;
114985 l_amb_context_code            VARCHAR2(30);
114986 l_entity_code                 VARCHAR2(30);
114987 l_event_class_code            VARCHAR2(30);
114988 l_ae_header_id                NUMBER;
114989 l_event_type_code             VARCHAR2(30);
114990 l_line_definition_code        VARCHAR2(30);
114991 l_line_definition_owner_code  VARCHAR2(1);
114992 --
114993 -- adr variables
114994 l_segment                     VARCHAR2(30);
114995 l_ccid                        NUMBER;
114996 l_adr_transaction_coa_id      NUMBER;
114997 l_adr_accounting_coa_id       NUMBER;
114998 l_adr_flexfield_segment_code  VARCHAR2(30);
114999 l_adr_flex_value_set_id       NUMBER;
115000 l_adr_value_type_code         VARCHAR2(30);
115001 l_adr_value_combination_id    NUMBER;
115002 l_adr_value_segment_code      VARCHAR2(30);
115003 
115004 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
115005 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
115006 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
115007 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
115008 
115009 -- 4262811 Variables ------------------------------------------------------------------------------------------
115010 l_entered_amt_idx             NUMBER;
115011 l_accted_amt_idx              NUMBER;
115012 l_acc_rev_flag                VARCHAR2(1);
115013 l_accrual_line_num            NUMBER;
115014 l_tmp_amt                     NUMBER;
115015 l_acc_rev_natural_side_code   VARCHAR2(1);
115016 
115017 l_num_entries                 NUMBER;
115018 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
115022 l_recog_line_1                NUMBER;
115019 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
115020 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
115021 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
115023 l_recog_line_2                NUMBER;
115024 
115025 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
115026 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
115027 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
115028 
115029 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
115030 
115031 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
115032 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
115033 
115034 ---------------------------------------------------------------------------------------------------------------
115035 
115036 
115037 --
115038 -- bulk performance
115039 --
115040 l_balance_type_code           VARCHAR2(1);
115041 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
115042 l_log_module                  VARCHAR2(240);
115043 
115044 --
115045 -- Upgrade strategy
115046 --
115047 l_actual_upg_option           VARCHAR2(1);
115048 l_enc_upg_option           VARCHAR2(1);
115049 
115050 --
115051 BEGIN
115052 --
115053 IF g_log_enabled THEN
115054       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_315';
115055 END IF;
115056 --
115057 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
115058 
115059       trace
115060          (p_msg      => 'BEGIN of AcctLineType_315'
115061          ,p_level    => C_LEVEL_PROCEDURE
115062          ,p_module   => l_log_module);
115063 
115064 END IF;
115065 --
115066 l_component_type             := 'AMB_JLT';
115067 l_component_code             := 'FA_RET_REVAL_RESERVE_GAIN';
115068 l_component_type_code        := 'S';
115069 l_component_appl_id          :=  140;
115070 l_amb_context_code           := 'DEFAULT';
115071 l_entity_code                := 'TRANSACTIONS';
115072 l_event_class_code           := 'RETIREMENTS';
115073 l_event_type_code            := 'RETIREMENTS';
115074 l_line_definition_owner_code := 'S';
115075 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
115076 --
115077 l_balance_type_code          := 'A';
115078 l_segment                     := NULL;
115079 l_ccid                        := NULL;
115080 l_adr_transaction_coa_id      := NULL;
115081 l_adr_accounting_coa_id       := NULL;
115082 l_adr_flexfield_segment_code  := NULL;
115083 l_adr_flex_value_set_id       := NULL;
115084 l_adr_value_type_code         := NULL;
115085 l_adr_value_combination_id    := NULL;
115086 l_adr_value_segment_code      := NULL;
115087 
115088 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
115089 l_bflow_class_code           := '';    -- 4219869 Business Flow
115090 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
115091 l_budgetary_control_flag     := 'N';
115092 
115093 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
115094 l_bflow_applied_to_amt       := NULL; -- 5132302
115095 l_entered_amt_idx            := NULL;          -- 4262811
115096 l_accted_amt_idx             := NULL;          -- 4262811
115097 l_acc_rev_flag               := NULL;          -- 4262811
115098 l_accrual_line_num           := NULL;          -- 4262811
115099 l_tmp_amt                    := NULL;          -- 4262811
115100 --
115101  
115102 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
115103     l_balance_type_code <> 'B' THEN
115104 IF NVL(p_source_35,'
115105 ') =  'REVAL RSV RET' AND 
115106 p_source_41 >=  0
115107  THEN 
115108 
115109    --
115110    XLA_AE_LINES_PKG.SetNewLine;
115111 
115112    p_balance_type_code          := l_balance_type_code;
115113    -- set the flag so later we will know whether the gain loss line needs to be created
115114    
115115    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
115116      p_actual_flag :='A';
115117    END IF;
115118 
115119    --
115120    -- bulk performance
115121    --
115122    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
115123                                       p_header_num   => 0); -- 4262811
115124    --
115125    -- set accounting line options
115126    --
115127    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
115128            p_natural_side_code          => 'C'
115129          , p_gain_or_loss_flag          => 'N'
115130          , p_gl_transfer_mode_code      => 'S'
115131          , p_acct_entry_type_code       => 'A'
115132          , p_switch_side_flag           => 'Y'
115133          , p_merge_duplicate_code       => 'N'
115134          );
115135    --
115136    l_acc_rev_natural_side_code := 'D';  -- 4262811
115137    -- 
115138    --
115139    -- set accounting line type info
115140    --
115141    xla_ae_lines_pkg.SetAcctLineType
115142       (p_component_type             => l_component_type
115143       ,p_event_type_code            => l_event_type_code
115144       ,p_line_definition_owner_code => l_line_definition_owner_code
115145       ,p_line_definition_code       => l_line_definition_code
115146       ,p_accounting_line_code       => l_component_code
115147       ,p_accounting_line_type_code  => l_component_type_code
115148       ,p_accounting_line_appl_id    => l_component_appl_id
115149       ,p_amb_context_code           => l_amb_context_code
115150       ,p_entity_code                => l_entity_code
115151       ,p_event_class_code           => l_event_class_code);
115152    --
115153    -- set accounting class
115154    --
115155    xla_ae_lines_pkg.SetAcctClass(
115156            p_accounting_class_code  => 'ASSET'
115157          , p_ae_header_id           => l_ae_header_id
115158          );
115159 
115160    --
115164                       'ASSET';
115161    -- set rounding class
115162    --
115163    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
115165 
115166    --
115167    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
115168    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
115169    --
115170    -- bulk performance
115171    --
115172    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
115173 
115174    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
115175       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
115176 
115177    -- 4955764
115178    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
115179       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
115180 
115181    -- 4458381 Public Sector Enh
115182    
115183    --
115184    -- set accounting attributes for the line type
115185    --
115186    l_entered_amt_idx := 4;
115187    l_accted_amt_idx  := 6;
115188    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
115189    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
115190    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
115191    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
115192    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
115193    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
115194    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
115195    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
115196    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
115197    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
115198    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
115199    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
115200    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
115201 
115202    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
115203    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
115204 
115205    ---------------------------------------------------------------------------------------------------------------
115206    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
115207    ---------------------------------------------------------------------------------------------------------------
115208    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
115209 
115210    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
115211    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
115212 
115213    IF xla_accounting_cache_pkg.GetValueChar
115214          (p_source_code         => 'LEDGER_CATEGORY_CODE'
115215          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
115216    AND l_bflow_method_code = 'PRIOR_ENTRY'
115217 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
115218    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
115219          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
115220        )
115221    THEN
115222          xla_ae_lines_pkg.BflowUpgEntry
115223            (p_business_method_code    => l_bflow_method_code
115224            ,p_business_class_code     => l_bflow_class_code
115225            ,p_balance_type            => l_balance_type_code);
115226    ELSE
115227       NULL;
115228 -- No business flow processing for business flow method of NONE.
115229    END IF;
115230 
115231    --
115232    -- call analytical criteria
115233    --
115234    
115235    --
115236    -- call description
115237    --
115238    
115239 xla_ae_lines_pkg.SetLineDescription(
115240    p_ae_header_id => l_ae_header_id
115241   ,p_description  => Description_89 (
115242      p_application_id         => p_application_id
115243    , p_ae_header_id           => l_ae_header_id 
115244 , p_source_1 => p_source_1
115245    )
115246 );
115247 
115248 
115249    --
115250    -- call ADRs
115251    -- Bug 4922099
115252    --
115253    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
115254         (NVL(l_actual_upg_option, 'N') = 'O') OR
115255         (NVL(l_enc_upg_option, 'N') = 'O')
115256       )
115257    THEN
115258    NULL;
115259    --
115260    --
115261    
115262   l_ccid := AcctDerRule_173(
115263            p_application_id           => p_application_id
115264          , p_ae_header_id             => l_ae_header_id 
115265 , p_source_3 => p_source_3
115266 , p_source_30 => p_source_30
115267          , x_transaction_coa_id       => l_adr_transaction_coa_id
115268          , x_accounting_coa_id        => l_adr_accounting_coa_id
115269          , x_value_type_code          => l_adr_value_type_code
115270          , p_side                     => 'NA'
115271    );
115272 
115273    xla_ae_lines_pkg.set_ccid(
115274     p_code_combination_id          => l_ccid
115275   , p_value_type_code              => l_adr_value_type_code
115276   , p_transaction_coa_id           => l_adr_transaction_coa_id
115277   , p_accounting_coa_id            => l_adr_accounting_coa_id
115278   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
115279   , p_adr_type_code                => 'S'
115280   , p_component_type               => l_component_type
115281   , p_component_code               => l_component_code
115282   , p_component_type_code          => l_component_type_code
115283   , p_component_appl_id            => l_component_appl_id
115284   , p_amb_context_code             => l_amb_context_code
115285   , p_side                         => 'NA'
115286   );
115287 
115288 
115292 , p_source_3 => p_source_3
115289    l_segment := AcctDerRule_168(
115290            p_application_id           => p_application_id
115291          , p_ae_header_id             => l_ae_header_id 
115293 , p_source_29 => p_source_29
115294          , x_transaction_coa_id       => l_adr_transaction_coa_id
115295          , x_accounting_coa_id        => l_adr_accounting_coa_id
115296          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
115297          , x_flex_value_set_id        => l_adr_flex_value_set_id
115298          , x_value_type_code          => l_adr_value_type_code
115299          , x_value_combination_id     => l_adr_value_combination_id
115300          , x_value_segment_code       => l_adr_value_segment_code
115301          , p_side                     => 'NA'
115302          , p_override_seg_flag        => 'Y'
115303    );
115304 
115305    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
115306 
115307       xla_ae_lines_pkg.set_segment(
115308           p_to_segment_code         => 'GL_BALANCING'
115309         , p_segment_value           => l_segment
115310         , p_from_segment_code       => l_adr_value_segment_code
115311         , p_from_combination_id     => l_adr_value_combination_id
115312         , p_value_type_code         => l_adr_value_type_code
115313         , p_transaction_coa_id      => l_adr_transaction_coa_id
115314         , p_accounting_coa_id       => l_adr_accounting_coa_id
115315         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
115316         , p_flex_value_set_id       => l_adr_flex_value_set_id
115317         , p_adr_code                => 'FA_EXPENSE_ACCT'
115318         , p_adr_type_code           => 'S'
115319         , p_component_type          => l_component_type
115320         , p_component_code          => l_component_code
115321         , p_component_type_code     => l_component_type_code
115322         , p_component_appl_id       => l_component_appl_id
115323         , p_amb_context_code        => l_amb_context_code
115324         , p_entity_code             => 'TRANSACTIONS'
115325         , p_event_class_code        => 'RETIREMENTS'
115326         , p_side                    => 'NA'
115327         );
115328 
115329   END IF;
115330 
115331    l_segment := AcctDerRule_165(
115332            p_application_id           => p_application_id
115333          , p_ae_header_id             => l_ae_header_id 
115334 , p_source_3 => p_source_3
115335 , p_source_27 => p_source_27
115336          , x_transaction_coa_id       => l_adr_transaction_coa_id
115337          , x_accounting_coa_id        => l_adr_accounting_coa_id
115338          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
115339          , x_flex_value_set_id        => l_adr_flex_value_set_id
115340          , x_value_type_code          => l_adr_value_type_code
115341          , x_value_combination_id     => l_adr_value_combination_id
115342          , x_value_segment_code       => l_adr_value_segment_code
115343          , p_side                     => 'NA'
115344          , p_override_seg_flag        => 'Y'
115345    );
115346 
115347    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
115348 
115349       xla_ae_lines_pkg.set_segment(
115350           p_to_segment_code         => 'GL_ACCOUNT'
115351         , p_segment_value           => l_segment
115352         , p_from_segment_code       => l_adr_value_segment_code
115353         , p_from_combination_id     => l_adr_value_combination_id
115354         , p_value_type_code         => l_adr_value_type_code
115355         , p_transaction_coa_id      => l_adr_transaction_coa_id
115356         , p_accounting_coa_id       => l_adr_accounting_coa_id
115357         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
115358         , p_flex_value_set_id       => l_adr_flex_value_set_id
115359         , p_adr_code                => 'FA_REVAL_RES_RET_GAIN_SEGMENT'
115360         , p_adr_type_code           => 'S'
115361         , p_component_type          => l_component_type
115362         , p_component_code          => l_component_code
115363         , p_component_type_code     => l_component_type_code
115364         , p_component_appl_id       => l_component_appl_id
115365         , p_amb_context_code        => l_amb_context_code
115366         , p_entity_code             => 'TRANSACTIONS'
115367         , p_event_class_code        => 'RETIREMENTS'
115368         , p_side                    => 'NA'
115369         );
115370 
115371   END IF;
115372 
115373    --
115374    --
115375    END IF;
115376    --
115377    -- Bug 4922099
115378    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
115379           (NVL(l_enc_upg_option, 'N') = 'O')
115380         ) AND
115381         (l_bflow_method_code = 'PRIOR_ENTRY')
115382       )
115383    THEN
115384       IF
115385       --
115386       1 = 2
115387       --
115388       THEN
115389       xla_accounting_err_pkg.build_message
115390                                     (p_appli_s_name            => 'XLA'
115391                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
115392                                     ,p_token_1                 => 'LINE_NUMBER'
115393                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
115394                                     ,p_token_2                 => 'LINE_TYPE_NAME'
115395                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
115396                                                                              l_component_type
115397                                                                             ,l_component_code
115398                                                                             ,l_component_type_code
115399                                                                             ,l_component_appl_id
115400                                                                             ,l_amb_context_code
115401                                                                             ,l_entity_code
115405                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
115402                                                                             ,l_event_class_code
115403                                                                            )
115404                                     ,p_token_3                 => 'OWNER'
115406                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
115407                                                                           ,p_lookup_code    => l_component_type_code
115408                                                                          )
115409                                     ,p_token_4                 => 'PRODUCT_NAME'
115410                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
115411                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
115412                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
115413                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
115414                                     ,p_ae_header_id            =>  NULL
115415                                        );
115416 
115417         IF (C_LEVEL_ERROR>= g_log_level) THEN
115418                  trace
115419                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
115420                       ,p_level    => C_LEVEL_ERROR
115421                       ,p_module   => l_log_module);
115422         END IF;
115423       END IF;
115424    END IF;
115425    --
115426    --
115427    ------------------------------------------------------------------------------------------------
115428    -- 4219869 Business Flow
115429    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
115430    -- Prior Entry.  Currently, the following code is always generated.
115431    ------------------------------------------------------------------------------------------------
115432    XLA_AE_LINES_PKG.ValidateCurrentLine;
115433 
115434    ------------------------------------------------------------------------------------
115435    -- 4219869 Business Flow
115436    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
115437    ------------------------------------------------------------------------------------
115438    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
115439 
115440    ----------------------------------------------------------------------------------
115441    -- 4219869 Business Flow
115442    -- Update journal entry status -- Need to generate this within IF <condition>
115443    ----------------------------------------------------------------------------------
115444    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
115445          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
115446          ,p_balance_type_code => l_balance_type_code
115447          );
115448 
115449    -------------------------------------------------------------------------------------------
115450    -- 4262811 - Generate the Accrual Reversal lines
115451    -------------------------------------------------------------------------------------------
115452    BEGIN
115453       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
115454                               (g_array_event(p_event_id).array_value_num('header_index'));
115455       IF l_acc_rev_flag IS NULL THEN
115456          l_acc_rev_flag := 'N';
115457       END IF;
115458    EXCEPTION
115459       WHEN OTHERS THEN
115460          l_acc_rev_flag := 'N';
115461    END;
115462    --
115463    IF (l_acc_rev_flag = 'Y') THEN
115464 
115465        -- 4645092  ------------------------------------------------------------------------------
115466        -- To allow MPA report to determine if it should generate report process
115467        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
115468        ------------------------------------------------------------------------------------------
115469 
115470        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
115471        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
115472    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
115473    -- call ADRs
115474    -- Bug 4922099
115475    --
115476    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
115477         (NVL(l_actual_upg_option, 'N') = 'O') OR
115478         (NVL(l_enc_upg_option, 'N') = 'O')
115479       )
115480    THEN
115481    NULL;
115482    --
115483    --
115484    
115485   l_ccid := AcctDerRule_173(
115486            p_application_id           => p_application_id
115487          , p_ae_header_id             => l_ae_header_id 
115488 , p_source_3 => p_source_3
115489 , p_source_30 => p_source_30
115490          , x_transaction_coa_id       => l_adr_transaction_coa_id
115491          , x_accounting_coa_id        => l_adr_accounting_coa_id
115492          , x_value_type_code          => l_adr_value_type_code
115493          , p_side                     => 'NA'
115494    );
115495 
115496    xla_ae_lines_pkg.set_ccid(
115497     p_code_combination_id          => l_ccid
115498   , p_value_type_code              => l_adr_value_type_code
115499   , p_transaction_coa_id           => l_adr_transaction_coa_id
115500   , p_accounting_coa_id            => l_adr_accounting_coa_id
115501   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
115502   , p_adr_type_code                => 'S'
115503   , p_component_type               => l_component_type
115504   , p_component_code               => l_component_code
115505   , p_component_type_code          => l_component_type_code
115506   , p_component_appl_id            => l_component_appl_id
115507   , p_amb_context_code             => l_amb_context_code
115508   , p_side                         => 'NA'
115509   );
115510 
115511 
115512    l_segment := AcctDerRule_168(
115516 , p_source_29 => p_source_29
115513            p_application_id           => p_application_id
115514          , p_ae_header_id             => l_ae_header_id 
115515 , p_source_3 => p_source_3
115517          , x_transaction_coa_id       => l_adr_transaction_coa_id
115518          , x_accounting_coa_id        => l_adr_accounting_coa_id
115519          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
115520          , x_flex_value_set_id        => l_adr_flex_value_set_id
115521          , x_value_type_code          => l_adr_value_type_code
115522          , x_value_combination_id     => l_adr_value_combination_id
115523          , x_value_segment_code       => l_adr_value_segment_code
115524          , p_side                     => 'NA'
115525          , p_override_seg_flag        => 'Y'
115526    );
115527 
115528    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
115529 
115530       xla_ae_lines_pkg.set_segment(
115531           p_to_segment_code         => 'GL_BALANCING'
115532         , p_segment_value           => l_segment
115533         , p_from_segment_code       => l_adr_value_segment_code
115534         , p_from_combination_id     => l_adr_value_combination_id
115535         , p_value_type_code         => l_adr_value_type_code
115536         , p_transaction_coa_id      => l_adr_transaction_coa_id
115537         , p_accounting_coa_id       => l_adr_accounting_coa_id
115538         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
115539         , p_flex_value_set_id       => l_adr_flex_value_set_id
115540         , p_adr_code                => 'FA_EXPENSE_ACCT'
115541         , p_adr_type_code           => 'S'
115542         , p_component_type          => l_component_type
115543         , p_component_code          => l_component_code
115544         , p_component_type_code     => l_component_type_code
115545         , p_component_appl_id       => l_component_appl_id
115546         , p_amb_context_code        => l_amb_context_code
115547         , p_entity_code             => 'TRANSACTIONS'
115548         , p_event_class_code        => 'RETIREMENTS'
115549         , p_side                    => 'NA'
115550         );
115551 
115552   END IF;
115553 
115554    l_segment := AcctDerRule_165(
115555            p_application_id           => p_application_id
115556          , p_ae_header_id             => l_ae_header_id 
115557 , p_source_3 => p_source_3
115558 , p_source_27 => p_source_27
115559          , x_transaction_coa_id       => l_adr_transaction_coa_id
115560          , x_accounting_coa_id        => l_adr_accounting_coa_id
115561          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
115562          , x_flex_value_set_id        => l_adr_flex_value_set_id
115563          , x_value_type_code          => l_adr_value_type_code
115564          , x_value_combination_id     => l_adr_value_combination_id
115565          , x_value_segment_code       => l_adr_value_segment_code
115566          , p_side                     => 'NA'
115567          , p_override_seg_flag        => 'Y'
115568    );
115569 
115570    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
115571 
115572       xla_ae_lines_pkg.set_segment(
115573           p_to_segment_code         => 'GL_ACCOUNT'
115574         , p_segment_value           => l_segment
115575         , p_from_segment_code       => l_adr_value_segment_code
115576         , p_from_combination_id     => l_adr_value_combination_id
115577         , p_value_type_code         => l_adr_value_type_code
115578         , p_transaction_coa_id      => l_adr_transaction_coa_id
115579         , p_accounting_coa_id       => l_adr_accounting_coa_id
115580         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
115581         , p_flex_value_set_id       => l_adr_flex_value_set_id
115582         , p_adr_code                => 'FA_REVAL_RES_RET_GAIN_SEGMENT'
115583         , p_adr_type_code           => 'S'
115584         , p_component_type          => l_component_type
115585         , p_component_code          => l_component_code
115586         , p_component_type_code     => l_component_type_code
115587         , p_component_appl_id       => l_component_appl_id
115588         , p_amb_context_code        => l_amb_context_code
115589         , p_entity_code             => 'TRANSACTIONS'
115590         , p_event_class_code        => 'RETIREMENTS'
115591         , p_side                    => 'NA'
115592         );
115593 
115594   END IF;
115595 
115596    --
115597    --
115598    END IF;
115599 
115600        --
115601        -- Update the line information that should be overwritten
115602        --
115603        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
115604                                          p_header_num   => 1);
115605        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
115606 
115607        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
115608 
115609        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
115610           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
115611        END IF;
115612 
115613       --
115614       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
115615       --
115616       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
115617           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
115618       ELSE
115619           ---------------------------------------------------------------------------------------------------
115620           -- 4262811a Switch Sign
115621           ---------------------------------------------------------------------------------------------------
115622           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
115623           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
115627           -- 5132302
115624                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
115625           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
115626                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
115628           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
115629                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
115630 
115631       END IF;
115632 
115633       -- 4955764
115634       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
115635       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
115636 
115637 
115638       XLA_AE_LINES_PKG.ValidateCurrentLine;
115639       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
115640 
115641       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
115642                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
115643                ,p_balance_type_code => l_balance_type_code);
115644 
115645    END IF;
115646 
115647    -----------------------------------------------------------------------------------------
115648    -- 4262811 Multiperiod Accounting
115649    -----------------------------------------------------------------------------------------
115650      -- No MPA option is assigned.
115651 
115652 
115653 END IF;
115654 END IF;
115655 --
115656 
115657 --
115658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
115659    trace
115660       (p_msg      => 'END of AcctLineType_315'
115661       ,p_level    => C_LEVEL_PROCEDURE
115662       ,p_module   => l_log_module);
115663 END IF;
115664 --
115665 EXCEPTION
115666   WHEN xla_exceptions_pkg.application_exception THEN
115667       RAISE;
115668   WHEN OTHERS THEN
115669        xla_exceptions_pkg.raise_message
115670            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_315');
115671 END AcctLineType_315;
115672 --
115673 
115674 ---------------------------------------
115675 --
115676 -- PRIVATE FUNCTION
115677 --         AcctLineType_316
115678 --
115679 ---------------------------------------
115680 PROCEDURE AcctLineType_316 (
115681   p_application_id        IN NUMBER
115682  ,p_event_id              IN NUMBER
115683  ,p_calculate_acctd_flag  IN VARCHAR2
115684  ,p_calculate_g_l_flag    IN VARCHAR2
115685  ,p_actual_flag           IN OUT VARCHAR2
115686  ,p_balance_type_code     OUT VARCHAR2
115687  ,p_gain_or_loss_ref      OUT VARCHAR2
115688  
115689 --Period Close Date
115690  , p_source_1            IN DATE
115691 --Generated Code Combination Identifier
115692  , p_source_3            IN NUMBER
115693 --Revaluation Reserve Retired Loss Account
115694  , p_source_28            IN VARCHAR2
115695 --Expense Account Code Combination Identifier
115696  , p_source_29            IN NUMBER
115697 --Default Code Combination Identifier
115698  , p_source_30            IN NUMBER
115699 --Adjustment Type
115700  , p_source_35            IN VARCHAR2
115701 --Transaction Header Identifier
115702  , p_source_36            IN NUMBER
115703 --Adjustment Line Identifier
115704  , p_source_37            IN NUMBER
115705 --Distribution Type Code
115706  , p_source_38            IN VARCHAR2
115707 --Entered Amount
115708  , p_source_39            IN NUMBER
115709 --Currency Code
115710  , p_source_40            IN VARCHAR2
115711 --Gain Loss Amount
115712  , p_source_41            IN NUMBER
115713 )
115714 IS
115715 
115716 l_component_type              VARCHAR2(80);
115717 l_component_code              VARCHAR2(30);
115718 l_component_type_code         VARCHAR2(1);
115719 l_component_appl_id           INTEGER;
115720 l_amb_context_code            VARCHAR2(30);
115721 l_entity_code                 VARCHAR2(30);
115722 l_event_class_code            VARCHAR2(30);
115723 l_ae_header_id                NUMBER;
115724 l_event_type_code             VARCHAR2(30);
115725 l_line_definition_code        VARCHAR2(30);
115726 l_line_definition_owner_code  VARCHAR2(1);
115727 --
115728 -- adr variables
115729 l_segment                     VARCHAR2(30);
115730 l_ccid                        NUMBER;
115731 l_adr_transaction_coa_id      NUMBER;
115732 l_adr_accounting_coa_id       NUMBER;
115733 l_adr_flexfield_segment_code  VARCHAR2(30);
115734 l_adr_flex_value_set_id       NUMBER;
115735 l_adr_value_type_code         VARCHAR2(30);
115736 l_adr_value_combination_id    NUMBER;
115737 l_adr_value_segment_code      VARCHAR2(30);
115738 
115739 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
115740 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
115741 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
115742 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
115743 
115744 -- 4262811 Variables ------------------------------------------------------------------------------------------
115745 l_entered_amt_idx             NUMBER;
115746 l_accted_amt_idx              NUMBER;
115747 l_acc_rev_flag                VARCHAR2(1);
115748 l_accrual_line_num            NUMBER;
115749 l_tmp_amt                     NUMBER;
115750 l_acc_rev_natural_side_code   VARCHAR2(1);
115751 
115752 l_num_entries                 NUMBER;
115753 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
115754 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
115755 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
115756 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
115757 l_recog_line_1                NUMBER;
115758 l_recog_line_2                NUMBER;
115759 
115760 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
115761 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
115765 
115762 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
115763 
115764 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
115766 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
115767 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
115768 
115769 ---------------------------------------------------------------------------------------------------------------
115770 
115771 
115772 --
115773 -- bulk performance
115774 --
115775 l_balance_type_code           VARCHAR2(1);
115776 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
115777 l_log_module                  VARCHAR2(240);
115778 
115779 --
115780 -- Upgrade strategy
115781 --
115782 l_actual_upg_option           VARCHAR2(1);
115783 l_enc_upg_option           VARCHAR2(1);
115784 
115785 --
115786 BEGIN
115787 --
115788 IF g_log_enabled THEN
115789       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_316';
115790 END IF;
115791 --
115792 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
115793 
115794       trace
115795          (p_msg      => 'BEGIN of AcctLineType_316'
115796          ,p_level    => C_LEVEL_PROCEDURE
115797          ,p_module   => l_log_module);
115798 
115799 END IF;
115800 --
115801 l_component_type             := 'AMB_JLT';
115802 l_component_code             := 'FA_RET_REVAL_RESERVE_LOSS';
115803 l_component_type_code        := 'S';
115804 l_component_appl_id          :=  140;
115805 l_amb_context_code           := 'DEFAULT';
115806 l_entity_code                := 'TRANSACTIONS';
115807 l_event_class_code           := 'RETIREMENTS';
115808 l_event_type_code            := 'RETIREMENTS';
115809 l_line_definition_owner_code := 'S';
115810 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_RETIR19';
115811 --
115812 l_balance_type_code          := 'A';
115813 l_segment                     := NULL;
115814 l_ccid                        := NULL;
115815 l_adr_transaction_coa_id      := NULL;
115816 l_adr_accounting_coa_id       := NULL;
115817 l_adr_flexfield_segment_code  := NULL;
115818 l_adr_flex_value_set_id       := NULL;
115819 l_adr_value_type_code         := NULL;
115820 l_adr_value_combination_id    := NULL;
115821 l_adr_value_segment_code      := NULL;
115822 
115823 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
115824 l_bflow_class_code           := '';    -- 4219869 Business Flow
115825 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
115826 l_budgetary_control_flag     := 'N';
115827 
115828 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
115829 l_bflow_applied_to_amt       := NULL; -- 5132302
115830 l_entered_amt_idx            := NULL;          -- 4262811
115831 l_accted_amt_idx             := NULL;          -- 4262811
115832 l_acc_rev_flag               := NULL;          -- 4262811
115833 l_accrual_line_num           := NULL;          -- 4262811
115834 l_tmp_amt                    := NULL;          -- 4262811
115835 --
115836  
115837 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
115838     l_balance_type_code <> 'B' THEN
115839 IF NVL(p_source_35,'
115840 ') =  'REVAL RSV RET' AND 
115841 p_source_41 <  0
115842  THEN 
115843 
115844    --
115845    XLA_AE_LINES_PKG.SetNewLine;
115846 
115847    p_balance_type_code          := l_balance_type_code;
115848    -- set the flag so later we will know whether the gain loss line needs to be created
115849    
115850    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
115851      p_actual_flag :='A';
115852    END IF;
115853 
115854    --
115855    -- bulk performance
115856    --
115857    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
115858                                       p_header_num   => 0); -- 4262811
115859    --
115860    -- set accounting line options
115861    --
115862    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
115863            p_natural_side_code          => 'C'
115864          , p_gain_or_loss_flag          => 'N'
115865          , p_gl_transfer_mode_code      => 'S'
115866          , p_acct_entry_type_code       => 'A'
115867          , p_switch_side_flag           => 'Y'
115868          , p_merge_duplicate_code       => 'N'
115869          );
115870    --
115871    l_acc_rev_natural_side_code := 'D';  -- 4262811
115872    -- 
115873    --
115874    -- set accounting line type info
115875    --
115876    xla_ae_lines_pkg.SetAcctLineType
115877       (p_component_type             => l_component_type
115878       ,p_event_type_code            => l_event_type_code
115879       ,p_line_definition_owner_code => l_line_definition_owner_code
115880       ,p_line_definition_code       => l_line_definition_code
115881       ,p_accounting_line_code       => l_component_code
115882       ,p_accounting_line_type_code  => l_component_type_code
115883       ,p_accounting_line_appl_id    => l_component_appl_id
115884       ,p_amb_context_code           => l_amb_context_code
115885       ,p_entity_code                => l_entity_code
115886       ,p_event_class_code           => l_event_class_code);
115887    --
115888    -- set accounting class
115889    --
115890    xla_ae_lines_pkg.SetAcctClass(
115891            p_accounting_class_code  => 'ASSET'
115892          , p_ae_header_id           => l_ae_header_id
115893          );
115894 
115895    --
115896    -- set rounding class
115897    --
115898    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
115899                       'ASSET';
115900 
115901    --
115902    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
115903    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
115904    --
115905    -- bulk performance
115909    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
115906    --
115907    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
115908 
115910       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
115911 
115912    -- 4955764
115913    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
115914       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
115915 
115916    -- 4458381 Public Sector Enh
115917    
115918    --
115919    -- set accounting attributes for the line type
115920    --
115921    l_entered_amt_idx := 4;
115922    l_accted_amt_idx  := 6;
115923    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
115924    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
115925    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
115926    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
115927    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
115928    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
115929    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
115930    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
115931    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
115932    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
115933    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
115934    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
115935    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
115936 
115937    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
115938    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
115939 
115940    ---------------------------------------------------------------------------------------------------------------
115941    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
115942    ---------------------------------------------------------------------------------------------------------------
115943    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
115944 
115945    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
115946    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
115947 
115948    IF xla_accounting_cache_pkg.GetValueChar
115949          (p_source_code         => 'LEDGER_CATEGORY_CODE'
115950          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
115951    AND l_bflow_method_code = 'PRIOR_ENTRY'
115952 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
115953    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
115954          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
115955        )
115956    THEN
115957          xla_ae_lines_pkg.BflowUpgEntry
115958            (p_business_method_code    => l_bflow_method_code
115959            ,p_business_class_code     => l_bflow_class_code
115960            ,p_balance_type            => l_balance_type_code);
115961    ELSE
115962       NULL;
115963 -- No business flow processing for business flow method of NONE.
115964    END IF;
115965 
115966    --
115967    -- call analytical criteria
115968    --
115969    
115970    --
115971    -- call description
115972    --
115973    
115974 xla_ae_lines_pkg.SetLineDescription(
115975    p_ae_header_id => l_ae_header_id
115976   ,p_description  => Description_89 (
115977      p_application_id         => p_application_id
115978    , p_ae_header_id           => l_ae_header_id 
115979 , p_source_1 => p_source_1
115980    )
115981 );
115982 
115983 
115984    --
115985    -- call ADRs
115986    -- Bug 4922099
115987    --
115988    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
115989         (NVL(l_actual_upg_option, 'N') = 'O') OR
115990         (NVL(l_enc_upg_option, 'N') = 'O')
115991       )
115992    THEN
115993    NULL;
115994    --
115995    --
115996    
115997   l_ccid := AcctDerRule_173(
115998            p_application_id           => p_application_id
115999          , p_ae_header_id             => l_ae_header_id 
116000 , p_source_3 => p_source_3
116001 , p_source_30 => p_source_30
116002          , x_transaction_coa_id       => l_adr_transaction_coa_id
116003          , x_accounting_coa_id        => l_adr_accounting_coa_id
116004          , x_value_type_code          => l_adr_value_type_code
116005          , p_side                     => 'NA'
116006    );
116007 
116008    xla_ae_lines_pkg.set_ccid(
116009     p_code_combination_id          => l_ccid
116010   , p_value_type_code              => l_adr_value_type_code
116011   , p_transaction_coa_id           => l_adr_transaction_coa_id
116012   , p_accounting_coa_id            => l_adr_accounting_coa_id
116013   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
116014   , p_adr_type_code                => 'S'
116015   , p_component_type               => l_component_type
116016   , p_component_code               => l_component_code
116017   , p_component_type_code          => l_component_type_code
116018   , p_component_appl_id            => l_component_appl_id
116019   , p_amb_context_code             => l_amb_context_code
116020   , p_side                         => 'NA'
116021   );
116022 
116023 
116024    l_segment := AcctDerRule_168(
116025            p_application_id           => p_application_id
116026          , p_ae_header_id             => l_ae_header_id 
116027 , p_source_3 => p_source_3
116028 , p_source_29 => p_source_29
116029          , x_transaction_coa_id       => l_adr_transaction_coa_id
116030          , x_accounting_coa_id        => l_adr_accounting_coa_id
116031          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
116032          , x_flex_value_set_id        => l_adr_flex_value_set_id
116036          , p_side                     => 'NA'
116033          , x_value_type_code          => l_adr_value_type_code
116034          , x_value_combination_id     => l_adr_value_combination_id
116035          , x_value_segment_code       => l_adr_value_segment_code
116037          , p_override_seg_flag        => 'Y'
116038    );
116039 
116040    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
116041 
116042       xla_ae_lines_pkg.set_segment(
116043           p_to_segment_code         => 'GL_BALANCING'
116044         , p_segment_value           => l_segment
116045         , p_from_segment_code       => l_adr_value_segment_code
116046         , p_from_combination_id     => l_adr_value_combination_id
116047         , p_value_type_code         => l_adr_value_type_code
116048         , p_transaction_coa_id      => l_adr_transaction_coa_id
116049         , p_accounting_coa_id       => l_adr_accounting_coa_id
116050         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
116051         , p_flex_value_set_id       => l_adr_flex_value_set_id
116052         , p_adr_code                => 'FA_EXPENSE_ACCT'
116053         , p_adr_type_code           => 'S'
116054         , p_component_type          => l_component_type
116055         , p_component_code          => l_component_code
116056         , p_component_type_code     => l_component_type_code
116057         , p_component_appl_id       => l_component_appl_id
116058         , p_amb_context_code        => l_amb_context_code
116059         , p_entity_code             => 'TRANSACTIONS'
116060         , p_event_class_code        => 'RETIREMENTS'
116061         , p_side                    => 'NA'
116062         );
116063 
116064   END IF;
116065 
116066    l_segment := AcctDerRule_166(
116067            p_application_id           => p_application_id
116068          , p_ae_header_id             => l_ae_header_id 
116069 , p_source_3 => p_source_3
116070 , p_source_28 => p_source_28
116071          , x_transaction_coa_id       => l_adr_transaction_coa_id
116072          , x_accounting_coa_id        => l_adr_accounting_coa_id
116073          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
116074          , x_flex_value_set_id        => l_adr_flex_value_set_id
116075          , x_value_type_code          => l_adr_value_type_code
116076          , x_value_combination_id     => l_adr_value_combination_id
116077          , x_value_segment_code       => l_adr_value_segment_code
116078          , p_side                     => 'NA'
116079          , p_override_seg_flag        => 'Y'
116080    );
116081 
116082    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
116083 
116084       xla_ae_lines_pkg.set_segment(
116085           p_to_segment_code         => 'GL_ACCOUNT'
116086         , p_segment_value           => l_segment
116087         , p_from_segment_code       => l_adr_value_segment_code
116088         , p_from_combination_id     => l_adr_value_combination_id
116089         , p_value_type_code         => l_adr_value_type_code
116090         , p_transaction_coa_id      => l_adr_transaction_coa_id
116091         , p_accounting_coa_id       => l_adr_accounting_coa_id
116092         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
116093         , p_flex_value_set_id       => l_adr_flex_value_set_id
116094         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
116095         , p_adr_type_code           => 'S'
116096         , p_component_type          => l_component_type
116097         , p_component_code          => l_component_code
116098         , p_component_type_code     => l_component_type_code
116099         , p_component_appl_id       => l_component_appl_id
116100         , p_amb_context_code        => l_amb_context_code
116101         , p_entity_code             => 'TRANSACTIONS'
116102         , p_event_class_code        => 'RETIREMENTS'
116103         , p_side                    => 'NA'
116104         );
116105 
116106   END IF;
116107 
116108    --
116109    --
116110    END IF;
116111    --
116112    -- Bug 4922099
116113    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
116114           (NVL(l_enc_upg_option, 'N') = 'O')
116115         ) AND
116116         (l_bflow_method_code = 'PRIOR_ENTRY')
116117       )
116118    THEN
116119       IF
116120       --
116121       1 = 2
116122       --
116123       THEN
116124       xla_accounting_err_pkg.build_message
116125                                     (p_appli_s_name            => 'XLA'
116126                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
116127                                     ,p_token_1                 => 'LINE_NUMBER'
116128                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
116129                                     ,p_token_2                 => 'LINE_TYPE_NAME'
116130                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
116131                                                                              l_component_type
116132                                                                             ,l_component_code
116133                                                                             ,l_component_type_code
116134                                                                             ,l_component_appl_id
116135                                                                             ,l_amb_context_code
116136                                                                             ,l_entity_code
116137                                                                             ,l_event_class_code
116138                                                                            )
116139                                     ,p_token_3                 => 'OWNER'
116140                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
116141                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
116142                                                                           ,p_lookup_code    => l_component_type_code
116146                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
116143                                                                          )
116144                                     ,p_token_4                 => 'PRODUCT_NAME'
116145                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
116147                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
116148                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
116149                                     ,p_ae_header_id            =>  NULL
116150                                        );
116151 
116152         IF (C_LEVEL_ERROR>= g_log_level) THEN
116153                  trace
116154                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
116155                       ,p_level    => C_LEVEL_ERROR
116156                       ,p_module   => l_log_module);
116157         END IF;
116158       END IF;
116159    END IF;
116160    --
116161    --
116162    ------------------------------------------------------------------------------------------------
116163    -- 4219869 Business Flow
116164    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
116165    -- Prior Entry.  Currently, the following code is always generated.
116166    ------------------------------------------------------------------------------------------------
116167    XLA_AE_LINES_PKG.ValidateCurrentLine;
116168 
116169    ------------------------------------------------------------------------------------
116170    -- 4219869 Business Flow
116171    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
116172    ------------------------------------------------------------------------------------
116173    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
116174 
116175    ----------------------------------------------------------------------------------
116176    -- 4219869 Business Flow
116177    -- Update journal entry status -- Need to generate this within IF <condition>
116178    ----------------------------------------------------------------------------------
116179    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
116180          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
116181          ,p_balance_type_code => l_balance_type_code
116182          );
116183 
116184    -------------------------------------------------------------------------------------------
116185    -- 4262811 - Generate the Accrual Reversal lines
116186    -------------------------------------------------------------------------------------------
116187    BEGIN
116188       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
116189                               (g_array_event(p_event_id).array_value_num('header_index'));
116190       IF l_acc_rev_flag IS NULL THEN
116191          l_acc_rev_flag := 'N';
116192       END IF;
116193    EXCEPTION
116194       WHEN OTHERS THEN
116195          l_acc_rev_flag := 'N';
116196    END;
116197    --
116198    IF (l_acc_rev_flag = 'Y') THEN
116199 
116200        -- 4645092  ------------------------------------------------------------------------------
116201        -- To allow MPA report to determine if it should generate report process
116202        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
116203        ------------------------------------------------------------------------------------------
116204 
116205        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
116206        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
116207    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
116208    -- call ADRs
116209    -- Bug 4922099
116210    --
116211    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
116212         (NVL(l_actual_upg_option, 'N') = 'O') OR
116213         (NVL(l_enc_upg_option, 'N') = 'O')
116214       )
116215    THEN
116216    NULL;
116217    --
116218    --
116219    
116220   l_ccid := AcctDerRule_173(
116221            p_application_id           => p_application_id
116222          , p_ae_header_id             => l_ae_header_id 
116223 , p_source_3 => p_source_3
116224 , p_source_30 => p_source_30
116225          , x_transaction_coa_id       => l_adr_transaction_coa_id
116226          , x_accounting_coa_id        => l_adr_accounting_coa_id
116227          , x_value_type_code          => l_adr_value_type_code
116228          , p_side                     => 'NA'
116229    );
116230 
116231    xla_ae_lines_pkg.set_ccid(
116232     p_code_combination_id          => l_ccid
116233   , p_value_type_code              => l_adr_value_type_code
116234   , p_transaction_coa_id           => l_adr_transaction_coa_id
116235   , p_accounting_coa_id            => l_adr_accounting_coa_id
116236   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
116237   , p_adr_type_code                => 'S'
116238   , p_component_type               => l_component_type
116239   , p_component_code               => l_component_code
116240   , p_component_type_code          => l_component_type_code
116241   , p_component_appl_id            => l_component_appl_id
116242   , p_amb_context_code             => l_amb_context_code
116243   , p_side                         => 'NA'
116244   );
116245 
116246 
116247    l_segment := AcctDerRule_168(
116248            p_application_id           => p_application_id
116249          , p_ae_header_id             => l_ae_header_id 
116250 , p_source_3 => p_source_3
116251 , p_source_29 => p_source_29
116252          , x_transaction_coa_id       => l_adr_transaction_coa_id
116253          , x_accounting_coa_id        => l_adr_accounting_coa_id
116254          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
116255          , x_flex_value_set_id        => l_adr_flex_value_set_id
116256          , x_value_type_code          => l_adr_value_type_code
116257          , x_value_combination_id     => l_adr_value_combination_id
116261    );
116258          , x_value_segment_code       => l_adr_value_segment_code
116259          , p_side                     => 'NA'
116260          , p_override_seg_flag        => 'Y'
116262 
116263    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
116264 
116265       xla_ae_lines_pkg.set_segment(
116266           p_to_segment_code         => 'GL_BALANCING'
116267         , p_segment_value           => l_segment
116268         , p_from_segment_code       => l_adr_value_segment_code
116269         , p_from_combination_id     => l_adr_value_combination_id
116270         , p_value_type_code         => l_adr_value_type_code
116271         , p_transaction_coa_id      => l_adr_transaction_coa_id
116272         , p_accounting_coa_id       => l_adr_accounting_coa_id
116273         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
116274         , p_flex_value_set_id       => l_adr_flex_value_set_id
116275         , p_adr_code                => 'FA_EXPENSE_ACCT'
116276         , p_adr_type_code           => 'S'
116277         , p_component_type          => l_component_type
116278         , p_component_code          => l_component_code
116279         , p_component_type_code     => l_component_type_code
116280         , p_component_appl_id       => l_component_appl_id
116281         , p_amb_context_code        => l_amb_context_code
116282         , p_entity_code             => 'TRANSACTIONS'
116283         , p_event_class_code        => 'RETIREMENTS'
116284         , p_side                    => 'NA'
116285         );
116286 
116287   END IF;
116288 
116289    l_segment := AcctDerRule_166(
116290            p_application_id           => p_application_id
116291          , p_ae_header_id             => l_ae_header_id 
116292 , p_source_3 => p_source_3
116293 , p_source_28 => p_source_28
116294          , x_transaction_coa_id       => l_adr_transaction_coa_id
116295          , x_accounting_coa_id        => l_adr_accounting_coa_id
116296          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
116297          , x_flex_value_set_id        => l_adr_flex_value_set_id
116298          , x_value_type_code          => l_adr_value_type_code
116299          , x_value_combination_id     => l_adr_value_combination_id
116300          , x_value_segment_code       => l_adr_value_segment_code
116301          , p_side                     => 'NA'
116302          , p_override_seg_flag        => 'Y'
116303    );
116304 
116305    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
116306 
116307       xla_ae_lines_pkg.set_segment(
116308           p_to_segment_code         => 'GL_ACCOUNT'
116309         , p_segment_value           => l_segment
116310         , p_from_segment_code       => l_adr_value_segment_code
116311         , p_from_combination_id     => l_adr_value_combination_id
116312         , p_value_type_code         => l_adr_value_type_code
116313         , p_transaction_coa_id      => l_adr_transaction_coa_id
116314         , p_accounting_coa_id       => l_adr_accounting_coa_id
116315         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
116316         , p_flex_value_set_id       => l_adr_flex_value_set_id
116317         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
116318         , p_adr_type_code           => 'S'
116319         , p_component_type          => l_component_type
116320         , p_component_code          => l_component_code
116321         , p_component_type_code     => l_component_type_code
116322         , p_component_appl_id       => l_component_appl_id
116323         , p_amb_context_code        => l_amb_context_code
116324         , p_entity_code             => 'TRANSACTIONS'
116325         , p_event_class_code        => 'RETIREMENTS'
116326         , p_side                    => 'NA'
116327         );
116328 
116329   END IF;
116330 
116331    --
116332    --
116333    END IF;
116334 
116335        --
116336        -- Update the line information that should be overwritten
116337        --
116338        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
116339                                          p_header_num   => 1);
116340        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
116341 
116342        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
116343 
116344        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
116345           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
116346        END IF;
116347 
116348       --
116349       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
116350       --
116351       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
116352           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
116353       ELSE
116354           ---------------------------------------------------------------------------------------------------
116355           -- 4262811a Switch Sign
116356           ---------------------------------------------------------------------------------------------------
116357           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
116358           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
116359                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
116360           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
116361                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
116362           -- 5132302
116363           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
116364                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
116365 
116366       END IF;
116367 
116368       -- 4955764
116372 
116369       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
116370       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
116371 
116373       XLA_AE_LINES_PKG.ValidateCurrentLine;
116374       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
116375 
116376       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
116377                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
116378                ,p_balance_type_code => l_balance_type_code);
116379 
116380    END IF;
116381 
116382    -----------------------------------------------------------------------------------------
116383    -- 4262811 Multiperiod Accounting
116384    -----------------------------------------------------------------------------------------
116385      -- No MPA option is assigned.
116386 
116387 
116388 END IF;
116389 END IF;
116390 --
116391 
116392 --
116393 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
116394    trace
116395       (p_msg      => 'END of AcctLineType_316'
116396       ,p_level    => C_LEVEL_PROCEDURE
116397       ,p_module   => l_log_module);
116398 END IF;
116399 --
116400 EXCEPTION
116401   WHEN xla_exceptions_pkg.application_exception THEN
116402       RAISE;
116403   WHEN OTHERS THEN
116404        xla_exceptions_pkg.raise_message
116405            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_316');
116406 END AcctLineType_316;
116407 --
116408 
116409 ---------------------------------------
116410 --
116411 -- PRIVATE FUNCTION
116412 --         AcctLineType_317
116413 --
116414 ---------------------------------------
116415 PROCEDURE AcctLineType_317 (
116416   p_application_id        IN NUMBER
116417  ,p_event_id              IN NUMBER
116418  ,p_calculate_acctd_flag  IN VARCHAR2
116419  ,p_calculate_g_l_flag    IN VARCHAR2
116420  ,p_actual_flag           IN OUT VARCHAR2
116421  ,p_balance_type_code     OUT VARCHAR2
116422  ,p_gain_or_loss_ref      OUT VARCHAR2
116423  
116424 --Period Close Date
116425  , p_source_1            IN DATE
116426 --Generated Code Combination Identifier
116427  , p_source_3            IN NUMBER
116428 --Revaluation Reserve Retired Loss Account
116429  , p_source_28            IN VARCHAR2
116430 --Expense Account Code Combination Identifier
116431  , p_source_29            IN NUMBER
116432 --Default Code Combination Identifier
116433  , p_source_30            IN NUMBER
116434 --Adjustment Type
116435  , p_source_35            IN VARCHAR2
116436 --Transaction Header Identifier
116437  , p_source_36            IN NUMBER
116438 --Adjustment Line Identifier
116439  , p_source_37            IN NUMBER
116440 --Distribution Type Code
116441  , p_source_38            IN VARCHAR2
116442 --Entered Amount
116443  , p_source_39            IN NUMBER
116444 --Currency Code
116445  , p_source_40            IN VARCHAR2
116446 --Gain Loss Amount
116447  , p_source_41            IN NUMBER
116448 )
116449 IS
116450 
116451 l_component_type              VARCHAR2(80);
116452 l_component_code              VARCHAR2(30);
116453 l_component_type_code         VARCHAR2(1);
116454 l_component_appl_id           INTEGER;
116455 l_amb_context_code            VARCHAR2(30);
116456 l_entity_code                 VARCHAR2(30);
116457 l_event_class_code            VARCHAR2(30);
116458 l_ae_header_id                NUMBER;
116459 l_event_type_code             VARCHAR2(30);
116460 l_line_definition_code        VARCHAR2(30);
116461 l_line_definition_owner_code  VARCHAR2(1);
116462 --
116463 -- adr variables
116464 l_segment                     VARCHAR2(30);
116465 l_ccid                        NUMBER;
116466 l_adr_transaction_coa_id      NUMBER;
116467 l_adr_accounting_coa_id       NUMBER;
116468 l_adr_flexfield_segment_code  VARCHAR2(30);
116469 l_adr_flex_value_set_id       NUMBER;
116470 l_adr_value_type_code         VARCHAR2(30);
116471 l_adr_value_combination_id    NUMBER;
116472 l_adr_value_segment_code      VARCHAR2(30);
116473 
116474 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
116475 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
116476 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
116477 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
116478 
116479 -- 4262811 Variables ------------------------------------------------------------------------------------------
116480 l_entered_amt_idx             NUMBER;
116481 l_accted_amt_idx              NUMBER;
116482 l_acc_rev_flag                VARCHAR2(1);
116483 l_accrual_line_num            NUMBER;
116484 l_tmp_amt                     NUMBER;
116485 l_acc_rev_natural_side_code   VARCHAR2(1);
116486 
116487 l_num_entries                 NUMBER;
116488 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
116489 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
116490 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
116491 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
116492 l_recog_line_1                NUMBER;
116493 l_recog_line_2                NUMBER;
116494 
116495 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
116496 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
116497 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
116498 
116499 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
116500 
116501 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
116502 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
116503 
116504 ---------------------------------------------------------------------------------------------------------------
116505 
116506 
116507 --
116508 -- bulk performance
116509 --
116513 
116510 l_balance_type_code           VARCHAR2(1);
116511 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
116512 l_log_module                  VARCHAR2(240);
116514 --
116515 -- Upgrade strategy
116516 --
116517 l_actual_upg_option           VARCHAR2(1);
116518 l_enc_upg_option           VARCHAR2(1);
116519 
116520 --
116521 BEGIN
116522 --
116523 IF g_log_enabled THEN
116524       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_317';
116525 END IF;
116526 --
116527 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
116528 
116529       trace
116530          (p_msg      => 'BEGIN of AcctLineType_317'
116531          ,p_level    => C_LEVEL_PROCEDURE
116532          ,p_module   => l_log_module);
116533 
116534 END IF;
116535 --
116536 l_component_type             := 'AMB_JLT';
116537 l_component_code             := 'FA_RET_REVAL_RESERVE_LOSS';
116538 l_component_type_code        := 'S';
116539 l_component_appl_id          :=  140;
116540 l_amb_context_code           := 'DEFAULT';
116541 l_entity_code                := 'TRANSACTIONS';
116542 l_event_class_code           := 'RETIREMENTS';
116543 l_event_type_code            := 'REINSTATEMENTS';
116544 l_line_definition_owner_code := 'S';
116545 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REINS17';
116546 --
116547 l_balance_type_code          := 'A';
116548 l_segment                     := NULL;
116549 l_ccid                        := NULL;
116550 l_adr_transaction_coa_id      := NULL;
116551 l_adr_accounting_coa_id       := NULL;
116552 l_adr_flexfield_segment_code  := NULL;
116553 l_adr_flex_value_set_id       := NULL;
116554 l_adr_value_type_code         := NULL;
116555 l_adr_value_combination_id    := NULL;
116556 l_adr_value_segment_code      := NULL;
116557 
116558 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
116559 l_bflow_class_code           := '';    -- 4219869 Business Flow
116560 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
116561 l_budgetary_control_flag     := 'N';
116562 
116563 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
116564 l_bflow_applied_to_amt       := NULL; -- 5132302
116565 l_entered_amt_idx            := NULL;          -- 4262811
116566 l_accted_amt_idx             := NULL;          -- 4262811
116567 l_acc_rev_flag               := NULL;          -- 4262811
116568 l_accrual_line_num           := NULL;          -- 4262811
116569 l_tmp_amt                    := NULL;          -- 4262811
116570 --
116571  
116572 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
116573     l_balance_type_code <> 'B' THEN
116574 IF NVL(p_source_35,'
116575 ') =  'REVAL RSV RET' AND 
116576 p_source_41 <  0
116577  THEN 
116578 
116579    --
116580    XLA_AE_LINES_PKG.SetNewLine;
116581 
116582    p_balance_type_code          := l_balance_type_code;
116583    -- set the flag so later we will know whether the gain loss line needs to be created
116584    
116585    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
116586      p_actual_flag :='A';
116587    END IF;
116588 
116589    --
116590    -- bulk performance
116591    --
116592    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
116593                                       p_header_num   => 0); -- 4262811
116594    --
116595    -- set accounting line options
116596    --
116597    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
116598            p_natural_side_code          => 'C'
116599          , p_gain_or_loss_flag          => 'N'
116600          , p_gl_transfer_mode_code      => 'S'
116601          , p_acct_entry_type_code       => 'A'
116602          , p_switch_side_flag           => 'Y'
116603          , p_merge_duplicate_code       => 'N'
116604          );
116605    --
116606    l_acc_rev_natural_side_code := 'D';  -- 4262811
116607    -- 
116608    --
116609    -- set accounting line type info
116610    --
116611    xla_ae_lines_pkg.SetAcctLineType
116612       (p_component_type             => l_component_type
116613       ,p_event_type_code            => l_event_type_code
116614       ,p_line_definition_owner_code => l_line_definition_owner_code
116615       ,p_line_definition_code       => l_line_definition_code
116616       ,p_accounting_line_code       => l_component_code
116617       ,p_accounting_line_type_code  => l_component_type_code
116618       ,p_accounting_line_appl_id    => l_component_appl_id
116619       ,p_amb_context_code           => l_amb_context_code
116620       ,p_entity_code                => l_entity_code
116621       ,p_event_class_code           => l_event_class_code);
116622    --
116623    -- set accounting class
116624    --
116625    xla_ae_lines_pkg.SetAcctClass(
116626            p_accounting_class_code  => 'ASSET'
116627          , p_ae_header_id           => l_ae_header_id
116628          );
116629 
116630    --
116631    -- set rounding class
116632    --
116633    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
116634                       'ASSET';
116635 
116636    --
116637    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
116638    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
116639    --
116640    -- bulk performance
116641    --
116642    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
116643 
116644    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
116645       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
116646 
116647    -- 4955764
116648    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
116649       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
116650 
116651    -- 4458381 Public Sector Enh
116652    
116656    l_entered_amt_idx := 4;
116653    --
116654    -- set accounting attributes for the line type
116655    --
116657    l_accted_amt_idx  := 6;
116658    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
116659    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
116660    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
116661    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
116662    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
116663    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
116664    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
116665    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
116666    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
116667    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
116668    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
116669    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
116670    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
116671 
116672    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
116673    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
116674 
116675    ---------------------------------------------------------------------------------------------------------------
116676    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
116677    ---------------------------------------------------------------------------------------------------------------
116678    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
116679 
116680    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
116681    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
116682 
116683    IF xla_accounting_cache_pkg.GetValueChar
116684          (p_source_code         => 'LEDGER_CATEGORY_CODE'
116685          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
116686    AND l_bflow_method_code = 'PRIOR_ENTRY'
116687 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
116688    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
116689          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
116690        )
116691    THEN
116692          xla_ae_lines_pkg.BflowUpgEntry
116693            (p_business_method_code    => l_bflow_method_code
116694            ,p_business_class_code     => l_bflow_class_code
116695            ,p_balance_type            => l_balance_type_code);
116696    ELSE
116697       NULL;
116698 -- No business flow processing for business flow method of NONE.
116699    END IF;
116700 
116701    --
116702    -- call analytical criteria
116703    --
116704    
116705    --
116706    -- call description
116707    --
116708    
116709 xla_ae_lines_pkg.SetLineDescription(
116710    p_ae_header_id => l_ae_header_id
116711   ,p_description  => Description_89 (
116712      p_application_id         => p_application_id
116713    , p_ae_header_id           => l_ae_header_id 
116714 , p_source_1 => p_source_1
116715    )
116716 );
116717 
116718 
116719    --
116720    -- call ADRs
116721    -- Bug 4922099
116722    --
116723    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
116724         (NVL(l_actual_upg_option, 'N') = 'O') OR
116725         (NVL(l_enc_upg_option, 'N') = 'O')
116726       )
116727    THEN
116728    NULL;
116729    --
116730    --
116731    
116732   l_ccid := AcctDerRule_173(
116733            p_application_id           => p_application_id
116734          , p_ae_header_id             => l_ae_header_id 
116735 , p_source_3 => p_source_3
116736 , p_source_30 => p_source_30
116737          , x_transaction_coa_id       => l_adr_transaction_coa_id
116738          , x_accounting_coa_id        => l_adr_accounting_coa_id
116739          , x_value_type_code          => l_adr_value_type_code
116740          , p_side                     => 'NA'
116741    );
116742 
116743    xla_ae_lines_pkg.set_ccid(
116744     p_code_combination_id          => l_ccid
116745   , p_value_type_code              => l_adr_value_type_code
116746   , p_transaction_coa_id           => l_adr_transaction_coa_id
116747   , p_accounting_coa_id            => l_adr_accounting_coa_id
116748   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
116749   , p_adr_type_code                => 'S'
116750   , p_component_type               => l_component_type
116751   , p_component_code               => l_component_code
116752   , p_component_type_code          => l_component_type_code
116753   , p_component_appl_id            => l_component_appl_id
116754   , p_amb_context_code             => l_amb_context_code
116755   , p_side                         => 'NA'
116756   );
116757 
116758 
116759    l_segment := AcctDerRule_168(
116760            p_application_id           => p_application_id
116761          , p_ae_header_id             => l_ae_header_id 
116762 , p_source_3 => p_source_3
116763 , p_source_29 => p_source_29
116764          , x_transaction_coa_id       => l_adr_transaction_coa_id
116765          , x_accounting_coa_id        => l_adr_accounting_coa_id
116766          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
116767          , x_flex_value_set_id        => l_adr_flex_value_set_id
116768          , x_value_type_code          => l_adr_value_type_code
116769          , x_value_combination_id     => l_adr_value_combination_id
116770          , x_value_segment_code       => l_adr_value_segment_code
116771          , p_side                     => 'NA'
116772          , p_override_seg_flag        => 'Y'
116773    );
116774 
116775    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
116776 
116777       xla_ae_lines_pkg.set_segment(
116778           p_to_segment_code         => 'GL_BALANCING'
116779         , p_segment_value           => l_segment
116783         , p_transaction_coa_id      => l_adr_transaction_coa_id
116780         , p_from_segment_code       => l_adr_value_segment_code
116781         , p_from_combination_id     => l_adr_value_combination_id
116782         , p_value_type_code         => l_adr_value_type_code
116784         , p_accounting_coa_id       => l_adr_accounting_coa_id
116785         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
116786         , p_flex_value_set_id       => l_adr_flex_value_set_id
116787         , p_adr_code                => 'FA_EXPENSE_ACCT'
116788         , p_adr_type_code           => 'S'
116789         , p_component_type          => l_component_type
116790         , p_component_code          => l_component_code
116791         , p_component_type_code     => l_component_type_code
116792         , p_component_appl_id       => l_component_appl_id
116793         , p_amb_context_code        => l_amb_context_code
116794         , p_entity_code             => 'TRANSACTIONS'
116795         , p_event_class_code        => 'RETIREMENTS'
116796         , p_side                    => 'NA'
116797         );
116798 
116799   END IF;
116800 
116801    l_segment := AcctDerRule_166(
116802            p_application_id           => p_application_id
116803          , p_ae_header_id             => l_ae_header_id 
116804 , p_source_3 => p_source_3
116805 , p_source_28 => p_source_28
116806          , x_transaction_coa_id       => l_adr_transaction_coa_id
116807          , x_accounting_coa_id        => l_adr_accounting_coa_id
116808          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
116809          , x_flex_value_set_id        => l_adr_flex_value_set_id
116810          , x_value_type_code          => l_adr_value_type_code
116811          , x_value_combination_id     => l_adr_value_combination_id
116812          , x_value_segment_code       => l_adr_value_segment_code
116813          , p_side                     => 'NA'
116814          , p_override_seg_flag        => 'Y'
116815    );
116816 
116817    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
116818 
116819       xla_ae_lines_pkg.set_segment(
116820           p_to_segment_code         => 'GL_ACCOUNT'
116821         , p_segment_value           => l_segment
116822         , p_from_segment_code       => l_adr_value_segment_code
116823         , p_from_combination_id     => l_adr_value_combination_id
116824         , p_value_type_code         => l_adr_value_type_code
116825         , p_transaction_coa_id      => l_adr_transaction_coa_id
116826         , p_accounting_coa_id       => l_adr_accounting_coa_id
116827         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
116828         , p_flex_value_set_id       => l_adr_flex_value_set_id
116829         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
116830         , p_adr_type_code           => 'S'
116831         , p_component_type          => l_component_type
116832         , p_component_code          => l_component_code
116833         , p_component_type_code     => l_component_type_code
116834         , p_component_appl_id       => l_component_appl_id
116835         , p_amb_context_code        => l_amb_context_code
116836         , p_entity_code             => 'TRANSACTIONS'
116837         , p_event_class_code        => 'RETIREMENTS'
116838         , p_side                    => 'NA'
116839         );
116840 
116841   END IF;
116842 
116843    --
116844    --
116845    END IF;
116846    --
116847    -- Bug 4922099
116848    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
116849           (NVL(l_enc_upg_option, 'N') = 'O')
116850         ) AND
116851         (l_bflow_method_code = 'PRIOR_ENTRY')
116852       )
116853    THEN
116854       IF
116855       --
116856       1 = 2
116857       --
116858       THEN
116859       xla_accounting_err_pkg.build_message
116860                                     (p_appli_s_name            => 'XLA'
116861                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
116862                                     ,p_token_1                 => 'LINE_NUMBER'
116863                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
116864                                     ,p_token_2                 => 'LINE_TYPE_NAME'
116865                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
116866                                                                              l_component_type
116867                                                                             ,l_component_code
116868                                                                             ,l_component_type_code
116869                                                                             ,l_component_appl_id
116870                                                                             ,l_amb_context_code
116871                                                                             ,l_entity_code
116872                                                                             ,l_event_class_code
116873                                                                            )
116874                                     ,p_token_3                 => 'OWNER'
116875                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
116876                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
116877                                                                           ,p_lookup_code    => l_component_type_code
116878                                                                          )
116879                                     ,p_token_4                 => 'PRODUCT_NAME'
116880                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
116881                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
116882                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
116883                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
116887         IF (C_LEVEL_ERROR>= g_log_level) THEN
116884                                     ,p_ae_header_id            =>  NULL
116885                                        );
116886 
116888                  trace
116889                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
116890                       ,p_level    => C_LEVEL_ERROR
116891                       ,p_module   => l_log_module);
116892         END IF;
116893       END IF;
116894    END IF;
116895    --
116896    --
116897    ------------------------------------------------------------------------------------------------
116898    -- 4219869 Business Flow
116899    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
116900    -- Prior Entry.  Currently, the following code is always generated.
116901    ------------------------------------------------------------------------------------------------
116902    XLA_AE_LINES_PKG.ValidateCurrentLine;
116903 
116904    ------------------------------------------------------------------------------------
116905    -- 4219869 Business Flow
116906    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
116907    ------------------------------------------------------------------------------------
116908    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
116909 
116910    ----------------------------------------------------------------------------------
116911    -- 4219869 Business Flow
116912    -- Update journal entry status -- Need to generate this within IF <condition>
116913    ----------------------------------------------------------------------------------
116914    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
116915          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
116916          ,p_balance_type_code => l_balance_type_code
116917          );
116918 
116919    -------------------------------------------------------------------------------------------
116920    -- 4262811 - Generate the Accrual Reversal lines
116921    -------------------------------------------------------------------------------------------
116922    BEGIN
116923       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
116924                               (g_array_event(p_event_id).array_value_num('header_index'));
116925       IF l_acc_rev_flag IS NULL THEN
116926          l_acc_rev_flag := 'N';
116927       END IF;
116928    EXCEPTION
116929       WHEN OTHERS THEN
116930          l_acc_rev_flag := 'N';
116931    END;
116932    --
116933    IF (l_acc_rev_flag = 'Y') THEN
116934 
116935        -- 4645092  ------------------------------------------------------------------------------
116936        -- To allow MPA report to determine if it should generate report process
116937        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
116938        ------------------------------------------------------------------------------------------
116939 
116940        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
116941        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
116942    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
116943    -- call ADRs
116944    -- Bug 4922099
116945    --
116946    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
116947         (NVL(l_actual_upg_option, 'N') = 'O') OR
116948         (NVL(l_enc_upg_option, 'N') = 'O')
116949       )
116950    THEN
116951    NULL;
116952    --
116953    --
116954    
116955   l_ccid := AcctDerRule_173(
116956            p_application_id           => p_application_id
116957          , p_ae_header_id             => l_ae_header_id 
116958 , p_source_3 => p_source_3
116959 , p_source_30 => p_source_30
116960          , x_transaction_coa_id       => l_adr_transaction_coa_id
116961          , x_accounting_coa_id        => l_adr_accounting_coa_id
116962          , x_value_type_code          => l_adr_value_type_code
116963          , p_side                     => 'NA'
116964    );
116965 
116966    xla_ae_lines_pkg.set_ccid(
116967     p_code_combination_id          => l_ccid
116968   , p_value_type_code              => l_adr_value_type_code
116969   , p_transaction_coa_id           => l_adr_transaction_coa_id
116970   , p_accounting_coa_id            => l_adr_accounting_coa_id
116971   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
116972   , p_adr_type_code                => 'S'
116973   , p_component_type               => l_component_type
116974   , p_component_code               => l_component_code
116975   , p_component_type_code          => l_component_type_code
116976   , p_component_appl_id            => l_component_appl_id
116977   , p_amb_context_code             => l_amb_context_code
116978   , p_side                         => 'NA'
116979   );
116980 
116981 
116982    l_segment := AcctDerRule_168(
116983            p_application_id           => p_application_id
116984          , p_ae_header_id             => l_ae_header_id 
116985 , p_source_3 => p_source_3
116986 , p_source_29 => p_source_29
116987          , x_transaction_coa_id       => l_adr_transaction_coa_id
116988          , x_accounting_coa_id        => l_adr_accounting_coa_id
116989          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
116990          , x_flex_value_set_id        => l_adr_flex_value_set_id
116991          , x_value_type_code          => l_adr_value_type_code
116992          , x_value_combination_id     => l_adr_value_combination_id
116993          , x_value_segment_code       => l_adr_value_segment_code
116994          , p_side                     => 'NA'
116995          , p_override_seg_flag        => 'Y'
116996    );
116997 
116998    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
116999 
117000       xla_ae_lines_pkg.set_segment(
117001           p_to_segment_code         => 'GL_BALANCING'
117002         , p_segment_value           => l_segment
117003         , p_from_segment_code       => l_adr_value_segment_code
117004         , p_from_combination_id     => l_adr_value_combination_id
117008         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
117005         , p_value_type_code         => l_adr_value_type_code
117006         , p_transaction_coa_id      => l_adr_transaction_coa_id
117007         , p_accounting_coa_id       => l_adr_accounting_coa_id
117009         , p_flex_value_set_id       => l_adr_flex_value_set_id
117010         , p_adr_code                => 'FA_EXPENSE_ACCT'
117011         , p_adr_type_code           => 'S'
117012         , p_component_type          => l_component_type
117013         , p_component_code          => l_component_code
117014         , p_component_type_code     => l_component_type_code
117015         , p_component_appl_id       => l_component_appl_id
117016         , p_amb_context_code        => l_amb_context_code
117017         , p_entity_code             => 'TRANSACTIONS'
117018         , p_event_class_code        => 'RETIREMENTS'
117019         , p_side                    => 'NA'
117020         );
117021 
117022   END IF;
117023 
117024    l_segment := AcctDerRule_166(
117025            p_application_id           => p_application_id
117026          , p_ae_header_id             => l_ae_header_id 
117027 , p_source_3 => p_source_3
117028 , p_source_28 => p_source_28
117029          , x_transaction_coa_id       => l_adr_transaction_coa_id
117030          , x_accounting_coa_id        => l_adr_accounting_coa_id
117031          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
117032          , x_flex_value_set_id        => l_adr_flex_value_set_id
117033          , x_value_type_code          => l_adr_value_type_code
117034          , x_value_combination_id     => l_adr_value_combination_id
117035          , x_value_segment_code       => l_adr_value_segment_code
117036          , p_side                     => 'NA'
117037          , p_override_seg_flag        => 'Y'
117038    );
117039 
117040    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
117041 
117042       xla_ae_lines_pkg.set_segment(
117043           p_to_segment_code         => 'GL_ACCOUNT'
117044         , p_segment_value           => l_segment
117045         , p_from_segment_code       => l_adr_value_segment_code
117046         , p_from_combination_id     => l_adr_value_combination_id
117047         , p_value_type_code         => l_adr_value_type_code
117048         , p_transaction_coa_id      => l_adr_transaction_coa_id
117049         , p_accounting_coa_id       => l_adr_accounting_coa_id
117050         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
117051         , p_flex_value_set_id       => l_adr_flex_value_set_id
117052         , p_adr_code                => 'FA_REVAL_RES_RET_LOSS_SEGMENT'
117053         , p_adr_type_code           => 'S'
117054         , p_component_type          => l_component_type
117055         , p_component_code          => l_component_code
117056         , p_component_type_code     => l_component_type_code
117057         , p_component_appl_id       => l_component_appl_id
117058         , p_amb_context_code        => l_amb_context_code
117059         , p_entity_code             => 'TRANSACTIONS'
117060         , p_event_class_code        => 'RETIREMENTS'
117061         , p_side                    => 'NA'
117062         );
117063 
117064   END IF;
117065 
117066    --
117067    --
117068    END IF;
117069 
117070        --
117071        -- Update the line information that should be overwritten
117072        --
117073        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
117074                                          p_header_num   => 1);
117075        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
117076 
117077        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
117078 
117079        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
117080           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
117081        END IF;
117082 
117083       --
117084       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
117085       --
117086       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
117087           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
117088       ELSE
117089           ---------------------------------------------------------------------------------------------------
117090           -- 4262811a Switch Sign
117091           ---------------------------------------------------------------------------------------------------
117092           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
117093           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
117094                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
117095           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
117096                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
117097           -- 5132302
117098           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
117099                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
117100 
117101       END IF;
117102 
117103       -- 4955764
117104       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
117105       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
117106 
117107 
117108       XLA_AE_LINES_PKG.ValidateCurrentLine;
117109       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
117110 
117111       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
117112                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
117113                ,p_balance_type_code => l_balance_type_code);
117114 
117115    END IF;
117116 
117120      -- No MPA option is assigned.
117117    -----------------------------------------------------------------------------------------
117118    -- 4262811 Multiperiod Accounting
117119    -----------------------------------------------------------------------------------------
117121 
117122 
117123 END IF;
117124 END IF;
117125 --
117126 
117127 --
117128 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
117129    trace
117130       (p_msg      => 'END of AcctLineType_317'
117131       ,p_level    => C_LEVEL_PROCEDURE
117132       ,p_module   => l_log_module);
117133 END IF;
117134 --
117135 EXCEPTION
117136   WHEN xla_exceptions_pkg.application_exception THEN
117137       RAISE;
117138   WHEN OTHERS THEN
117139        xla_exceptions_pkg.raise_message
117140            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_317');
117141 END AcctLineType_317;
117142 --
117143 
117144 ---------------------------------------
117145 --
117146 -- PRIVATE FUNCTION
117147 --         AcctLineType_318
117148 --
117149 ---------------------------------------
117150 PROCEDURE AcctLineType_318 (
117151   p_application_id        IN NUMBER
117152  ,p_event_id              IN NUMBER
117153  ,p_calculate_acctd_flag  IN VARCHAR2
117154  ,p_calculate_g_l_flag    IN VARCHAR2
117155  ,p_actual_flag           IN OUT VARCHAR2
117156  ,p_balance_type_code     OUT VARCHAR2
117157  ,p_gain_or_loss_ref      OUT VARCHAR2
117158  
117159 --Period Close Date
117160  , p_source_1            IN DATE
117161 --Generated Code Combination Identifier
117162  , p_source_3            IN NUMBER
117163 --Bonus Reserve Account
117164  , p_source_4            IN VARCHAR2
117165 --Generated Offset Code Combination Identifier
117166  , p_source_17            IN NUMBER
117167 --Expense Account Code Combination Identifier
117168  , p_source_29            IN NUMBER
117169 --Default Code Combination Identifier
117170  , p_source_30            IN NUMBER
117171 --Adjustment Type
117172  , p_source_35            IN VARCHAR2
117173 --Transaction Header Identifier
117174  , p_source_36            IN NUMBER
117175 --Adjustment Line Identifier
117176  , p_source_37            IN NUMBER
117177 --Distribution Type Code
117178  , p_source_38            IN VARCHAR2
117179 --Entered Amount
117180  , p_source_39            IN NUMBER
117181 --Currency Code
117182  , p_source_40            IN VARCHAR2
117183 )
117184 IS
117185 
117186 l_component_type              VARCHAR2(80);
117187 l_component_code              VARCHAR2(30);
117188 l_component_type_code         VARCHAR2(1);
117189 l_component_appl_id           INTEGER;
117190 l_amb_context_code            VARCHAR2(30);
117191 l_entity_code                 VARCHAR2(30);
117192 l_event_class_code            VARCHAR2(30);
117193 l_ae_header_id                NUMBER;
117194 l_event_type_code             VARCHAR2(30);
117195 l_line_definition_code        VARCHAR2(30);
117196 l_line_definition_owner_code  VARCHAR2(1);
117197 --
117198 -- adr variables
117199 l_segment                     VARCHAR2(30);
117200 l_ccid                        NUMBER;
117201 l_adr_transaction_coa_id      NUMBER;
117202 l_adr_accounting_coa_id       NUMBER;
117203 l_adr_flexfield_segment_code  VARCHAR2(30);
117204 l_adr_flex_value_set_id       NUMBER;
117205 l_adr_value_type_code         VARCHAR2(30);
117206 l_adr_value_combination_id    NUMBER;
117207 l_adr_value_segment_code      VARCHAR2(30);
117208 
117209 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
117210 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
117211 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
117212 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
117213 
117214 -- 4262811 Variables ------------------------------------------------------------------------------------------
117215 l_entered_amt_idx             NUMBER;
117216 l_accted_amt_idx              NUMBER;
117217 l_acc_rev_flag                VARCHAR2(1);
117218 l_accrual_line_num            NUMBER;
117219 l_tmp_amt                     NUMBER;
117220 l_acc_rev_natural_side_code   VARCHAR2(1);
117221 
117222 l_num_entries                 NUMBER;
117223 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
117224 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
117225 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
117226 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
117227 l_recog_line_1                NUMBER;
117228 l_recog_line_2                NUMBER;
117229 
117230 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
117231 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
117232 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
117233 
117234 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
117235 
117236 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
117237 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
117238 
117239 ---------------------------------------------------------------------------------------------------------------
117240 
117241 
117242 --
117243 -- bulk performance
117244 --
117245 l_balance_type_code           VARCHAR2(1);
117246 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
117247 l_log_module                  VARCHAR2(240);
117248 
117249 --
117250 -- Upgrade strategy
117251 --
117252 l_actual_upg_option           VARCHAR2(1);
117253 l_enc_upg_option           VARCHAR2(1);
117254 
117255 --
117256 BEGIN
117257 --
117258 IF g_log_enabled THEN
117259       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_318';
117260 END IF;
117261 --
117262 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
117263 
117264       trace
117268 
117265          (p_msg      => 'BEGIN of AcctLineType_318'
117266          ,p_level    => C_LEVEL_PROCEDURE
117267          ,p_module   => l_log_module);
117269 END IF;
117270 --
117271 l_component_type             := 'AMB_JLT';
117272 l_component_code             := 'FA_REVAL_BONUS_DEPRN_RESERVE';
117273 l_component_type_code        := 'S';
117274 l_component_appl_id          :=  140;
117275 l_amb_context_code           := 'DEFAULT';
117276 l_entity_code                := 'TRANSACTIONS';
117277 l_event_class_code           := 'REVALUATION';
117278 l_event_type_code            := 'REVALUATION_ALL';
117279 l_line_definition_owner_code := 'S';
117280 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVAL21';
117281 --
117282 l_balance_type_code          := 'A';
117283 l_segment                     := NULL;
117284 l_ccid                        := NULL;
117285 l_adr_transaction_coa_id      := NULL;
117286 l_adr_accounting_coa_id       := NULL;
117287 l_adr_flexfield_segment_code  := NULL;
117288 l_adr_flex_value_set_id       := NULL;
117289 l_adr_value_type_code         := NULL;
117290 l_adr_value_combination_id    := NULL;
117291 l_adr_value_segment_code      := NULL;
117292 
117293 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
117294 l_bflow_class_code           := '';    -- 4219869 Business Flow
117295 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
117296 l_budgetary_control_flag     := 'N';
117297 
117298 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
117299 l_bflow_applied_to_amt       := NULL; -- 5132302
117300 l_entered_amt_idx            := NULL;          -- 4262811
117301 l_accted_amt_idx             := NULL;          -- 4262811
117302 l_acc_rev_flag               := NULL;          -- 4262811
117303 l_accrual_line_num           := NULL;          -- 4262811
117304 l_tmp_amt                    := NULL;          -- 4262811
117305 --
117306  
117307 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
117308     l_balance_type_code <> 'B' THEN
117309 IF NVL(p_source_35,'
117310 ') =  'BONUS RESERVE'
117311  THEN 
117312 
117313    --
117314    XLA_AE_LINES_PKG.SetNewLine;
117315 
117316    p_balance_type_code          := l_balance_type_code;
117317    -- set the flag so later we will know whether the gain loss line needs to be created
117318    
117319    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
117320      p_actual_flag :='A';
117321    END IF;
117322 
117323    --
117324    -- bulk performance
117325    --
117326    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
117327                                       p_header_num   => 0); -- 4262811
117328    --
117329    -- set accounting line options
117330    --
117331    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
117332            p_natural_side_code          => 'C'
117333          , p_gain_or_loss_flag          => 'N'
117334          , p_gl_transfer_mode_code      => 'S'
117335          , p_acct_entry_type_code       => 'A'
117336          , p_switch_side_flag           => 'Y'
117337          , p_merge_duplicate_code       => 'N'
117338          );
117339    --
117340    l_acc_rev_natural_side_code := 'D';  -- 4262811
117341    -- 
117342    --
117343    -- set accounting line type info
117344    --
117345    xla_ae_lines_pkg.SetAcctLineType
117346       (p_component_type             => l_component_type
117347       ,p_event_type_code            => l_event_type_code
117348       ,p_line_definition_owner_code => l_line_definition_owner_code
117349       ,p_line_definition_code       => l_line_definition_code
117350       ,p_accounting_line_code       => l_component_code
117351       ,p_accounting_line_type_code  => l_component_type_code
117352       ,p_accounting_line_appl_id    => l_component_appl_id
117353       ,p_amb_context_code           => l_amb_context_code
117354       ,p_entity_code                => l_entity_code
117355       ,p_event_class_code           => l_event_class_code);
117356    --
117357    -- set accounting class
117358    --
117359    xla_ae_lines_pkg.SetAcctClass(
117360            p_accounting_class_code  => 'ASSET'
117361          , p_ae_header_id           => l_ae_header_id
117362          );
117363 
117364    --
117365    -- set rounding class
117366    --
117367    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
117368                       'ASSET';
117369 
117370    --
117371    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
117372    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
117373    --
117374    -- bulk performance
117375    --
117376    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
117377 
117378    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
117379       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
117380 
117381    -- 4955764
117382    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
117383       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
117384 
117385    -- 4458381 Public Sector Enh
117386    
117387    --
117388    -- set accounting attributes for the line type
117389    --
117390    l_entered_amt_idx := 4;
117391    l_accted_amt_idx  := 6;
117392    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
117393    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
117394    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
117395    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
117396    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
117397    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
117398    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
117402    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
117399    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
117400    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
117401    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
117403    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
117404    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
117405 
117406    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
117407    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
117408 
117409    ---------------------------------------------------------------------------------------------------------------
117410    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
117411    ---------------------------------------------------------------------------------------------------------------
117412    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
117413 
117414    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
117415    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
117416 
117417    IF xla_accounting_cache_pkg.GetValueChar
117418          (p_source_code         => 'LEDGER_CATEGORY_CODE'
117419          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
117420    AND l_bflow_method_code = 'PRIOR_ENTRY'
117421 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
117422    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
117423          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
117424        )
117425    THEN
117426          xla_ae_lines_pkg.BflowUpgEntry
117427            (p_business_method_code    => l_bflow_method_code
117428            ,p_business_class_code     => l_bflow_class_code
117429            ,p_balance_type            => l_balance_type_code);
117430    ELSE
117431       NULL;
117432 -- No business flow processing for business flow method of NONE.
117433    END IF;
117434 
117435    --
117436    -- call analytical criteria
117437    --
117438    
117439    --
117440    -- call description
117441    --
117442    
117443 xla_ae_lines_pkg.SetLineDescription(
117444    p_ae_header_id => l_ae_header_id
117445   ,p_description  => Description_92 (
117446      p_application_id         => p_application_id
117447    , p_ae_header_id           => l_ae_header_id 
117448 , p_source_1 => p_source_1
117449    )
117450 );
117451 
117452 
117453    --
117454    -- call ADRs
117455    -- Bug 4922099
117456    --
117457    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
117458         (NVL(l_actual_upg_option, 'N') = 'O') OR
117459         (NVL(l_enc_upg_option, 'N') = 'O')
117460       )
117461    THEN
117462    NULL;
117463    --
117464    --
117465    
117466   l_ccid := AcctDerRule_174(
117467            p_application_id           => p_application_id
117468          , p_ae_header_id             => l_ae_header_id 
117469 , p_source_3 => p_source_3
117470 , p_source_17 => p_source_17
117471 , p_source_30 => p_source_30
117472          , x_transaction_coa_id       => l_adr_transaction_coa_id
117473          , x_accounting_coa_id        => l_adr_accounting_coa_id
117474          , x_value_type_code          => l_adr_value_type_code
117475          , p_side                     => 'NA'
117476    );
117477 
117478    xla_ae_lines_pkg.set_ccid(
117479     p_code_combination_id          => l_ccid
117480   , p_value_type_code              => l_adr_value_type_code
117481   , p_transaction_coa_id           => l_adr_transaction_coa_id
117482   , p_accounting_coa_id            => l_adr_accounting_coa_id
117483   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
117484   , p_adr_type_code                => 'S'
117485   , p_component_type               => l_component_type
117486   , p_component_code               => l_component_code
117487   , p_component_type_code          => l_component_type_code
117488   , p_component_appl_id            => l_component_appl_id
117489   , p_amb_context_code             => l_amb_context_code
117490   , p_side                         => 'NA'
117491   );
117492 
117493 
117494    l_segment := AcctDerRule_144(
117495            p_application_id           => p_application_id
117496          , p_ae_header_id             => l_ae_header_id 
117497 , p_source_3 => p_source_3
117498 , p_source_4 => p_source_4
117499          , x_transaction_coa_id       => l_adr_transaction_coa_id
117500          , x_accounting_coa_id        => l_adr_accounting_coa_id
117501          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
117502          , x_flex_value_set_id        => l_adr_flex_value_set_id
117503          , x_value_type_code          => l_adr_value_type_code
117504          , x_value_combination_id     => l_adr_value_combination_id
117505          , x_value_segment_code       => l_adr_value_segment_code
117506          , p_side                     => 'NA'
117507          , p_override_seg_flag        => 'Y'
117508    );
117509 
117510    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
117511 
117512       xla_ae_lines_pkg.set_segment(
117513           p_to_segment_code         => 'GL_ACCOUNT'
117514         , p_segment_value           => l_segment
117515         , p_from_segment_code       => l_adr_value_segment_code
117516         , p_from_combination_id     => l_adr_value_combination_id
117517         , p_value_type_code         => l_adr_value_type_code
117518         , p_transaction_coa_id      => l_adr_transaction_coa_id
117519         , p_accounting_coa_id       => l_adr_accounting_coa_id
117520         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
117521         , p_flex_value_set_id       => l_adr_flex_value_set_id
117522         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
117523         , p_adr_type_code           => 'S'
117527         , p_component_appl_id       => l_component_appl_id
117524         , p_component_type          => l_component_type
117525         , p_component_code          => l_component_code
117526         , p_component_type_code     => l_component_type_code
117528         , p_amb_context_code        => l_amb_context_code
117529         , p_entity_code             => 'TRANSACTIONS'
117530         , p_event_class_code        => 'REVALUATION'
117531         , p_side                    => 'NA'
117532         );
117533 
117534   END IF;
117535 
117536    l_segment := AcctDerRule_168(
117537            p_application_id           => p_application_id
117538          , p_ae_header_id             => l_ae_header_id 
117539 , p_source_3 => p_source_3
117540 , p_source_29 => p_source_29
117541          , x_transaction_coa_id       => l_adr_transaction_coa_id
117542          , x_accounting_coa_id        => l_adr_accounting_coa_id
117543          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
117544          , x_flex_value_set_id        => l_adr_flex_value_set_id
117545          , x_value_type_code          => l_adr_value_type_code
117546          , x_value_combination_id     => l_adr_value_combination_id
117547          , x_value_segment_code       => l_adr_value_segment_code
117548          , p_side                     => 'NA'
117549          , p_override_seg_flag        => 'Y'
117550    );
117551 
117552    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
117553 
117554       xla_ae_lines_pkg.set_segment(
117555           p_to_segment_code         => 'GL_BALANCING'
117556         , p_segment_value           => l_segment
117557         , p_from_segment_code       => l_adr_value_segment_code
117558         , p_from_combination_id     => l_adr_value_combination_id
117559         , p_value_type_code         => l_adr_value_type_code
117560         , p_transaction_coa_id      => l_adr_transaction_coa_id
117561         , p_accounting_coa_id       => l_adr_accounting_coa_id
117562         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
117563         , p_flex_value_set_id       => l_adr_flex_value_set_id
117564         , p_adr_code                => 'FA_EXPENSE_ACCT'
117565         , p_adr_type_code           => 'S'
117566         , p_component_type          => l_component_type
117567         , p_component_code          => l_component_code
117568         , p_component_type_code     => l_component_type_code
117569         , p_component_appl_id       => l_component_appl_id
117570         , p_amb_context_code        => l_amb_context_code
117571         , p_entity_code             => 'TRANSACTIONS'
117572         , p_event_class_code        => 'REVALUATION'
117573         , p_side                    => 'NA'
117574         );
117575 
117576   END IF;
117577 
117578    --
117579    --
117580    END IF;
117581    --
117582    -- Bug 4922099
117583    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
117584           (NVL(l_enc_upg_option, 'N') = 'O')
117585         ) AND
117586         (l_bflow_method_code = 'PRIOR_ENTRY')
117587       )
117588    THEN
117589       IF
117590       --
117591       1 = 2
117592       --
117593       THEN
117594       xla_accounting_err_pkg.build_message
117595                                     (p_appli_s_name            => 'XLA'
117596                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
117597                                     ,p_token_1                 => 'LINE_NUMBER'
117598                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
117599                                     ,p_token_2                 => 'LINE_TYPE_NAME'
117600                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
117601                                                                              l_component_type
117602                                                                             ,l_component_code
117603                                                                             ,l_component_type_code
117604                                                                             ,l_component_appl_id
117605                                                                             ,l_amb_context_code
117606                                                                             ,l_entity_code
117607                                                                             ,l_event_class_code
117608                                                                            )
117609                                     ,p_token_3                 => 'OWNER'
117610                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
117611                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
117612                                                                           ,p_lookup_code    => l_component_type_code
117613                                                                          )
117614                                     ,p_token_4                 => 'PRODUCT_NAME'
117615                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
117616                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
117617                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
117618                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
117619                                     ,p_ae_header_id            =>  NULL
117620                                        );
117621 
117622         IF (C_LEVEL_ERROR>= g_log_level) THEN
117623                  trace
117624                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
117625                       ,p_level    => C_LEVEL_ERROR
117626                       ,p_module   => l_log_module);
117627         END IF;
117628       END IF;
117629    END IF;
117630    --
117631    --
117635    -- Prior Entry.  Currently, the following code is always generated.
117632    ------------------------------------------------------------------------------------------------
117633    -- 4219869 Business Flow
117634    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
117636    ------------------------------------------------------------------------------------------------
117637    XLA_AE_LINES_PKG.ValidateCurrentLine;
117638 
117639    ------------------------------------------------------------------------------------
117640    -- 4219869 Business Flow
117641    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
117642    ------------------------------------------------------------------------------------
117643    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
117644 
117645    ----------------------------------------------------------------------------------
117646    -- 4219869 Business Flow
117647    -- Update journal entry status -- Need to generate this within IF <condition>
117648    ----------------------------------------------------------------------------------
117649    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
117650          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
117651          ,p_balance_type_code => l_balance_type_code
117652          );
117653 
117654    -------------------------------------------------------------------------------------------
117655    -- 4262811 - Generate the Accrual Reversal lines
117656    -------------------------------------------------------------------------------------------
117657    BEGIN
117658       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
117659                               (g_array_event(p_event_id).array_value_num('header_index'));
117660       IF l_acc_rev_flag IS NULL THEN
117661          l_acc_rev_flag := 'N';
117662       END IF;
117663    EXCEPTION
117664       WHEN OTHERS THEN
117665          l_acc_rev_flag := 'N';
117666    END;
117667    --
117668    IF (l_acc_rev_flag = 'Y') THEN
117669 
117670        -- 4645092  ------------------------------------------------------------------------------
117671        -- To allow MPA report to determine if it should generate report process
117672        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
117673        ------------------------------------------------------------------------------------------
117674 
117675        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
117676        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
117677    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
117678    -- call ADRs
117679    -- Bug 4922099
117680    --
117681    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
117682         (NVL(l_actual_upg_option, 'N') = 'O') OR
117683         (NVL(l_enc_upg_option, 'N') = 'O')
117684       )
117685    THEN
117686    NULL;
117687    --
117688    --
117689    
117690   l_ccid := AcctDerRule_174(
117691            p_application_id           => p_application_id
117692          , p_ae_header_id             => l_ae_header_id 
117693 , p_source_3 => p_source_3
117694 , p_source_17 => p_source_17
117695 , p_source_30 => p_source_30
117696          , x_transaction_coa_id       => l_adr_transaction_coa_id
117697          , x_accounting_coa_id        => l_adr_accounting_coa_id
117698          , x_value_type_code          => l_adr_value_type_code
117699          , p_side                     => 'NA'
117700    );
117701 
117702    xla_ae_lines_pkg.set_ccid(
117703     p_code_combination_id          => l_ccid
117704   , p_value_type_code              => l_adr_value_type_code
117705   , p_transaction_coa_id           => l_adr_transaction_coa_id
117706   , p_accounting_coa_id            => l_adr_accounting_coa_id
117707   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
117708   , p_adr_type_code                => 'S'
117709   , p_component_type               => l_component_type
117710   , p_component_code               => l_component_code
117711   , p_component_type_code          => l_component_type_code
117712   , p_component_appl_id            => l_component_appl_id
117713   , p_amb_context_code             => l_amb_context_code
117714   , p_side                         => 'NA'
117715   );
117716 
117717 
117718    l_segment := AcctDerRule_144(
117719            p_application_id           => p_application_id
117720          , p_ae_header_id             => l_ae_header_id 
117721 , p_source_3 => p_source_3
117722 , p_source_4 => p_source_4
117723          , x_transaction_coa_id       => l_adr_transaction_coa_id
117724          , x_accounting_coa_id        => l_adr_accounting_coa_id
117725          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
117726          , x_flex_value_set_id        => l_adr_flex_value_set_id
117727          , x_value_type_code          => l_adr_value_type_code
117728          , x_value_combination_id     => l_adr_value_combination_id
117729          , x_value_segment_code       => l_adr_value_segment_code
117730          , p_side                     => 'NA'
117731          , p_override_seg_flag        => 'Y'
117732    );
117733 
117734    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
117735 
117736       xla_ae_lines_pkg.set_segment(
117737           p_to_segment_code         => 'GL_ACCOUNT'
117738         , p_segment_value           => l_segment
117739         , p_from_segment_code       => l_adr_value_segment_code
117740         , p_from_combination_id     => l_adr_value_combination_id
117741         , p_value_type_code         => l_adr_value_type_code
117742         , p_transaction_coa_id      => l_adr_transaction_coa_id
117743         , p_accounting_coa_id       => l_adr_accounting_coa_id
117744         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
117745         , p_flex_value_set_id       => l_adr_flex_value_set_id
117746         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
117747         , p_adr_type_code           => 'S'
117751         , p_component_appl_id       => l_component_appl_id
117748         , p_component_type          => l_component_type
117749         , p_component_code          => l_component_code
117750         , p_component_type_code     => l_component_type_code
117752         , p_amb_context_code        => l_amb_context_code
117753         , p_entity_code             => 'TRANSACTIONS'
117754         , p_event_class_code        => 'REVALUATION'
117755         , p_side                    => 'NA'
117756         );
117757 
117758   END IF;
117759 
117760    l_segment := AcctDerRule_168(
117761            p_application_id           => p_application_id
117762          , p_ae_header_id             => l_ae_header_id 
117763 , p_source_3 => p_source_3
117764 , p_source_29 => p_source_29
117765          , x_transaction_coa_id       => l_adr_transaction_coa_id
117766          , x_accounting_coa_id        => l_adr_accounting_coa_id
117767          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
117768          , x_flex_value_set_id        => l_adr_flex_value_set_id
117769          , x_value_type_code          => l_adr_value_type_code
117770          , x_value_combination_id     => l_adr_value_combination_id
117771          , x_value_segment_code       => l_adr_value_segment_code
117772          , p_side                     => 'NA'
117773          , p_override_seg_flag        => 'Y'
117774    );
117775 
117776    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
117777 
117778       xla_ae_lines_pkg.set_segment(
117779           p_to_segment_code         => 'GL_BALANCING'
117780         , p_segment_value           => l_segment
117781         , p_from_segment_code       => l_adr_value_segment_code
117782         , p_from_combination_id     => l_adr_value_combination_id
117783         , p_value_type_code         => l_adr_value_type_code
117784         , p_transaction_coa_id      => l_adr_transaction_coa_id
117785         , p_accounting_coa_id       => l_adr_accounting_coa_id
117786         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
117787         , p_flex_value_set_id       => l_adr_flex_value_set_id
117788         , p_adr_code                => 'FA_EXPENSE_ACCT'
117789         , p_adr_type_code           => 'S'
117790         , p_component_type          => l_component_type
117791         , p_component_code          => l_component_code
117792         , p_component_type_code     => l_component_type_code
117793         , p_component_appl_id       => l_component_appl_id
117794         , p_amb_context_code        => l_amb_context_code
117795         , p_entity_code             => 'TRANSACTIONS'
117796         , p_event_class_code        => 'REVALUATION'
117797         , p_side                    => 'NA'
117798         );
117799 
117800   END IF;
117801 
117802    --
117803    --
117804    END IF;
117805 
117806        --
117807        -- Update the line information that should be overwritten
117808        --
117809        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
117810                                          p_header_num   => 1);
117811        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
117812 
117813        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
117814 
117815        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
117816           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
117817        END IF;
117818 
117819       --
117820       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
117821       --
117822       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
117823           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
117824       ELSE
117825           ---------------------------------------------------------------------------------------------------
117826           -- 4262811a Switch Sign
117827           ---------------------------------------------------------------------------------------------------
117828           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
117829           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
117830                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
117831           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
117832                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
117833           -- 5132302
117834           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
117835                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
117836 
117837       END IF;
117838 
117839       -- 4955764
117840       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
117841       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
117842 
117843 
117844       XLA_AE_LINES_PKG.ValidateCurrentLine;
117845       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
117846 
117847       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
117848                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
117849                ,p_balance_type_code => l_balance_type_code);
117850 
117851    END IF;
117852 
117853    -----------------------------------------------------------------------------------------
117854    -- 4262811 Multiperiod Accounting
117855    -----------------------------------------------------------------------------------------
117856      -- No MPA option is assigned.
117857 
117858 
117859 END IF;
117860 END IF;
117861 --
117862 
117863 --
117864 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
117865    trace
117869 END IF;
117866       (p_msg      => 'END of AcctLineType_318'
117867       ,p_level    => C_LEVEL_PROCEDURE
117868       ,p_module   => l_log_module);
117870 --
117871 EXCEPTION
117872   WHEN xla_exceptions_pkg.application_exception THEN
117873       RAISE;
117874   WHEN OTHERS THEN
117875        xla_exceptions_pkg.raise_message
117876            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_318');
117877 END AcctLineType_318;
117878 --
117879 
117880 ---------------------------------------
117881 --
117882 -- PRIVATE FUNCTION
117883 --         AcctLineType_319
117884 --
117885 ---------------------------------------
117886 PROCEDURE AcctLineType_319 (
117887   p_application_id        IN NUMBER
117888  ,p_event_id              IN NUMBER
117889  ,p_calculate_acctd_flag  IN VARCHAR2
117890  ,p_calculate_g_l_flag    IN VARCHAR2
117891  ,p_actual_flag           IN OUT VARCHAR2
117892  ,p_balance_type_code     OUT VARCHAR2
117893  ,p_gain_or_loss_ref      OUT VARCHAR2
117894  
117895 --Period Close Date
117896  , p_source_1            IN DATE
117897 --Bonus Depreciation Expense Account
117898  , p_source_2            IN VARCHAR2
117899 --Generated Code Combination Identifier
117900  , p_source_3            IN NUMBER
117901 --Expense Account Code Combination Identifier
117902  , p_source_29            IN NUMBER
117903 --Adjustment Type
117904  , p_source_35            IN VARCHAR2
117905 --Transaction Header Identifier
117906  , p_source_36            IN NUMBER
117907 --Adjustment Line Identifier
117908  , p_source_37            IN NUMBER
117909 --Distribution Type Code
117910  , p_source_38            IN VARCHAR2
117911 --Entered Amount
117912  , p_source_39            IN NUMBER
117913 --Currency Code
117914  , p_source_40            IN VARCHAR2
117915 )
117916 IS
117917 
117918 l_component_type              VARCHAR2(80);
117919 l_component_code              VARCHAR2(30);
117920 l_component_type_code         VARCHAR2(1);
117921 l_component_appl_id           INTEGER;
117922 l_amb_context_code            VARCHAR2(30);
117923 l_entity_code                 VARCHAR2(30);
117924 l_event_class_code            VARCHAR2(30);
117925 l_ae_header_id                NUMBER;
117926 l_event_type_code             VARCHAR2(30);
117927 l_line_definition_code        VARCHAR2(30);
117928 l_line_definition_owner_code  VARCHAR2(1);
117929 --
117930 -- adr variables
117931 l_segment                     VARCHAR2(30);
117932 l_ccid                        NUMBER;
117933 l_adr_transaction_coa_id      NUMBER;
117934 l_adr_accounting_coa_id       NUMBER;
117935 l_adr_flexfield_segment_code  VARCHAR2(30);
117936 l_adr_flex_value_set_id       NUMBER;
117937 l_adr_value_type_code         VARCHAR2(30);
117938 l_adr_value_combination_id    NUMBER;
117939 l_adr_value_segment_code      VARCHAR2(30);
117940 
117941 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
117942 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
117943 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
117944 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
117945 
117946 -- 4262811 Variables ------------------------------------------------------------------------------------------
117947 l_entered_amt_idx             NUMBER;
117948 l_accted_amt_idx              NUMBER;
117949 l_acc_rev_flag                VARCHAR2(1);
117950 l_accrual_line_num            NUMBER;
117951 l_tmp_amt                     NUMBER;
117952 l_acc_rev_natural_side_code   VARCHAR2(1);
117953 
117954 l_num_entries                 NUMBER;
117955 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
117956 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
117957 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
117958 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
117959 l_recog_line_1                NUMBER;
117960 l_recog_line_2                NUMBER;
117961 
117962 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
117963 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
117964 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
117965 
117966 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
117967 
117968 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
117969 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
117970 
117971 ---------------------------------------------------------------------------------------------------------------
117972 
117973 
117974 --
117975 -- bulk performance
117976 --
117977 l_balance_type_code           VARCHAR2(1);
117978 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
117979 l_log_module                  VARCHAR2(240);
117980 
117981 --
117982 -- Upgrade strategy
117983 --
117984 l_actual_upg_option           VARCHAR2(1);
117985 l_enc_upg_option           VARCHAR2(1);
117986 
117987 --
117988 BEGIN
117989 --
117990 IF g_log_enabled THEN
117991       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_319';
117992 END IF;
117993 --
117994 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
117995 
117996       trace
117997          (p_msg      => 'BEGIN of AcctLineType_319'
117998          ,p_level    => C_LEVEL_PROCEDURE
117999          ,p_module   => l_log_module);
118000 
118001 END IF;
118002 --
118003 l_component_type             := 'AMB_JLT';
118004 l_component_code             := 'FA_REVAL_BONUS_EXPENSE';
118005 l_component_type_code        := 'S';
118006 l_component_appl_id          :=  140;
118007 l_amb_context_code           := 'DEFAULT';
118008 l_entity_code                := 'TRANSACTIONS';
118009 l_event_class_code           := 'REVALUATION';
118010 l_event_type_code            := 'REVALUATION_ALL';
118014 l_balance_type_code          := 'A';
118011 l_line_definition_owner_code := 'S';
118012 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVAL21';
118013 --
118015 l_segment                     := NULL;
118016 l_ccid                        := NULL;
118017 l_adr_transaction_coa_id      := NULL;
118018 l_adr_accounting_coa_id       := NULL;
118019 l_adr_flexfield_segment_code  := NULL;
118020 l_adr_flex_value_set_id       := NULL;
118021 l_adr_value_type_code         := NULL;
118022 l_adr_value_combination_id    := NULL;
118023 l_adr_value_segment_code      := NULL;
118024 
118025 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
118026 l_bflow_class_code           := '';    -- 4219869 Business Flow
118027 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
118028 l_budgetary_control_flag     := 'N';
118029 
118030 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
118031 l_bflow_applied_to_amt       := NULL; -- 5132302
118032 l_entered_amt_idx            := NULL;          -- 4262811
118033 l_accted_amt_idx             := NULL;          -- 4262811
118034 l_acc_rev_flag               := NULL;          -- 4262811
118035 l_accrual_line_num           := NULL;          -- 4262811
118036 l_tmp_amt                    := NULL;          -- 4262811
118037 --
118038  
118039 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
118040     l_balance_type_code <> 'B' THEN
118041 IF NVL(p_source_35,'
118042 ') =  'BONUS EXPENSE'
118043  THEN 
118044 
118045    --
118046    XLA_AE_LINES_PKG.SetNewLine;
118047 
118048    p_balance_type_code          := l_balance_type_code;
118049    -- set the flag so later we will know whether the gain loss line needs to be created
118050    
118051    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
118052      p_actual_flag :='A';
118053    END IF;
118054 
118055    --
118056    -- bulk performance
118057    --
118058    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
118059                                       p_header_num   => 0); -- 4262811
118060    --
118061    -- set accounting line options
118062    --
118063    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
118064            p_natural_side_code          => 'D'
118065          , p_gain_or_loss_flag          => 'N'
118066          , p_gl_transfer_mode_code      => 'S'
118067          , p_acct_entry_type_code       => 'A'
118068          , p_switch_side_flag           => 'Y'
118069          , p_merge_duplicate_code       => 'N'
118070          );
118071    --
118072    l_acc_rev_natural_side_code := 'C';  -- 4262811
118073    -- 
118074    --
118075    -- set accounting line type info
118076    --
118077    xla_ae_lines_pkg.SetAcctLineType
118078       (p_component_type             => l_component_type
118079       ,p_event_type_code            => l_event_type_code
118080       ,p_line_definition_owner_code => l_line_definition_owner_code
118081       ,p_line_definition_code       => l_line_definition_code
118082       ,p_accounting_line_code       => l_component_code
118083       ,p_accounting_line_type_code  => l_component_type_code
118084       ,p_accounting_line_appl_id    => l_component_appl_id
118085       ,p_amb_context_code           => l_amb_context_code
118086       ,p_entity_code                => l_entity_code
118087       ,p_event_class_code           => l_event_class_code);
118088    --
118089    -- set accounting class
118090    --
118091    xla_ae_lines_pkg.SetAcctClass(
118092            p_accounting_class_code  => 'EXPENSE'
118093          , p_ae_header_id           => l_ae_header_id
118094          );
118095 
118096    --
118097    -- set rounding class
118098    --
118099    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
118100                       'EXPENSE';
118101 
118102    --
118103    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
118104    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
118105    --
118106    -- bulk performance
118107    --
118108    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
118109 
118110    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
118111       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
118112 
118113    -- 4955764
118114    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
118115       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
118116 
118117    -- 4458381 Public Sector Enh
118118    
118119    --
118120    -- set accounting attributes for the line type
118121    --
118122    l_entered_amt_idx := 4;
118123    l_accted_amt_idx  := 6;
118124    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
118125    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
118126    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
118127    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
118128    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
118129    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
118130    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
118131    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
118132    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
118133    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
118134    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
118135    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
118136    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
118137 
118138    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
118139    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
118140 
118144    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
118141    ---------------------------------------------------------------------------------------------------------------
118142    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
118143    ---------------------------------------------------------------------------------------------------------------
118145 
118146    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
118147    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
118148 
118149    IF xla_accounting_cache_pkg.GetValueChar
118150          (p_source_code         => 'LEDGER_CATEGORY_CODE'
118151          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
118152    AND l_bflow_method_code = 'PRIOR_ENTRY'
118153 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
118154    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
118155          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
118156        )
118157    THEN
118158          xla_ae_lines_pkg.BflowUpgEntry
118159            (p_business_method_code    => l_bflow_method_code
118160            ,p_business_class_code     => l_bflow_class_code
118161            ,p_balance_type            => l_balance_type_code);
118162    ELSE
118163       NULL;
118164 -- No business flow processing for business flow method of NONE.
118165    END IF;
118166 
118167    --
118168    -- call analytical criteria
118169    --
118170    
118171    --
118172    -- call description
118173    --
118174    
118175 xla_ae_lines_pkg.SetLineDescription(
118176    p_ae_header_id => l_ae_header_id
118177   ,p_description  => Description_91 (
118178      p_application_id         => p_application_id
118179    , p_ae_header_id           => l_ae_header_id 
118180 , p_source_1 => p_source_1
118181    )
118182 );
118183 
118184 
118185    --
118186    -- call ADRs
118187    -- Bug 4922099
118188    --
118189    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
118190         (NVL(l_actual_upg_option, 'N') = 'O') OR
118191         (NVL(l_enc_upg_option, 'N') = 'O')
118192       )
118193    THEN
118194    NULL;
118195    --
118196    --
118197    
118198   l_ccid := AcctDerRule_175(
118199            p_application_id           => p_application_id
118200          , p_ae_header_id             => l_ae_header_id 
118201 , p_source_3 => p_source_3
118202 , p_source_29 => p_source_29
118203          , x_transaction_coa_id       => l_adr_transaction_coa_id
118204          , x_accounting_coa_id        => l_adr_accounting_coa_id
118205          , x_value_type_code          => l_adr_value_type_code
118206          , p_side                     => 'NA'
118207    );
118208 
118209    xla_ae_lines_pkg.set_ccid(
118210     p_code_combination_id          => l_ccid
118211   , p_value_type_code              => l_adr_value_type_code
118212   , p_transaction_coa_id           => l_adr_transaction_coa_id
118213   , p_accounting_coa_id            => l_adr_accounting_coa_id
118214   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
118215   , p_adr_type_code                => 'S'
118216   , p_component_type               => l_component_type
118217   , p_component_code               => l_component_code
118218   , p_component_type_code          => l_component_type_code
118219   , p_component_appl_id            => l_component_appl_id
118220   , p_amb_context_code             => l_amb_context_code
118221   , p_side                         => 'NA'
118222   );
118223 
118224 
118225    l_segment := AcctDerRule_143(
118226            p_application_id           => p_application_id
118227          , p_ae_header_id             => l_ae_header_id 
118228 , p_source_2 => p_source_2
118229 , p_source_3 => p_source_3
118230          , x_transaction_coa_id       => l_adr_transaction_coa_id
118231          , x_accounting_coa_id        => l_adr_accounting_coa_id
118232          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
118233          , x_flex_value_set_id        => l_adr_flex_value_set_id
118234          , x_value_type_code          => l_adr_value_type_code
118235          , x_value_combination_id     => l_adr_value_combination_id
118236          , x_value_segment_code       => l_adr_value_segment_code
118237          , p_side                     => 'NA'
118238          , p_override_seg_flag        => 'Y'
118239    );
118240 
118241    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
118242 
118243       xla_ae_lines_pkg.set_segment(
118244           p_to_segment_code         => 'GL_ACCOUNT'
118245         , p_segment_value           => l_segment
118246         , p_from_segment_code       => l_adr_value_segment_code
118247         , p_from_combination_id     => l_adr_value_combination_id
118248         , p_value_type_code         => l_adr_value_type_code
118249         , p_transaction_coa_id      => l_adr_transaction_coa_id
118250         , p_accounting_coa_id       => l_adr_accounting_coa_id
118251         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
118252         , p_flex_value_set_id       => l_adr_flex_value_set_id
118253         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
118254         , p_adr_type_code           => 'S'
118255         , p_component_type          => l_component_type
118256         , p_component_code          => l_component_code
118257         , p_component_type_code     => l_component_type_code
118258         , p_component_appl_id       => l_component_appl_id
118259         , p_amb_context_code        => l_amb_context_code
118260         , p_entity_code             => 'TRANSACTIONS'
118261         , p_event_class_code        => 'REVALUATION'
118262         , p_side                    => 'NA'
118263         );
118264 
118265   END IF;
118266 
118267    --
118268    --
118269    END IF;
118270    --
118271    -- Bug 4922099
118275         (l_bflow_method_code = 'PRIOR_ENTRY')
118272    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
118273           (NVL(l_enc_upg_option, 'N') = 'O')
118274         ) AND
118276       )
118277    THEN
118278       IF
118279       --
118280       1 = 2
118281       --
118282       THEN
118283       xla_accounting_err_pkg.build_message
118284                                     (p_appli_s_name            => 'XLA'
118285                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
118286                                     ,p_token_1                 => 'LINE_NUMBER'
118287                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
118288                                     ,p_token_2                 => 'LINE_TYPE_NAME'
118289                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
118290                                                                              l_component_type
118291                                                                             ,l_component_code
118292                                                                             ,l_component_type_code
118293                                                                             ,l_component_appl_id
118294                                                                             ,l_amb_context_code
118295                                                                             ,l_entity_code
118296                                                                             ,l_event_class_code
118297                                                                            )
118298                                     ,p_token_3                 => 'OWNER'
118299                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
118300                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
118301                                                                           ,p_lookup_code    => l_component_type_code
118302                                                                          )
118303                                     ,p_token_4                 => 'PRODUCT_NAME'
118304                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
118305                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
118306                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
118307                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
118308                                     ,p_ae_header_id            =>  NULL
118309                                        );
118310 
118311         IF (C_LEVEL_ERROR>= g_log_level) THEN
118312                  trace
118313                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
118314                       ,p_level    => C_LEVEL_ERROR
118315                       ,p_module   => l_log_module);
118316         END IF;
118317       END IF;
118318    END IF;
118319    --
118320    --
118321    ------------------------------------------------------------------------------------------------
118322    -- 4219869 Business Flow
118323    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
118324    -- Prior Entry.  Currently, the following code is always generated.
118325    ------------------------------------------------------------------------------------------------
118326    XLA_AE_LINES_PKG.ValidateCurrentLine;
118327 
118328    ------------------------------------------------------------------------------------
118329    -- 4219869 Business Flow
118330    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
118331    ------------------------------------------------------------------------------------
118332    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
118333 
118334    ----------------------------------------------------------------------------------
118335    -- 4219869 Business Flow
118336    -- Update journal entry status -- Need to generate this within IF <condition>
118337    ----------------------------------------------------------------------------------
118338    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
118339          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
118340          ,p_balance_type_code => l_balance_type_code
118341          );
118342 
118343    -------------------------------------------------------------------------------------------
118344    -- 4262811 - Generate the Accrual Reversal lines
118345    -------------------------------------------------------------------------------------------
118346    BEGIN
118347       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
118348                               (g_array_event(p_event_id).array_value_num('header_index'));
118349       IF l_acc_rev_flag IS NULL THEN
118350          l_acc_rev_flag := 'N';
118351       END IF;
118352    EXCEPTION
118353       WHEN OTHERS THEN
118354          l_acc_rev_flag := 'N';
118355    END;
118356    --
118357    IF (l_acc_rev_flag = 'Y') THEN
118358 
118359        -- 4645092  ------------------------------------------------------------------------------
118360        -- To allow MPA report to determine if it should generate report process
118361        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
118362        ------------------------------------------------------------------------------------------
118363 
118364        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
118365        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
118366    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
118367    -- call ADRs
118368    -- Bug 4922099
118369    --
118370    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
118371         (NVL(l_actual_upg_option, 'N') = 'O') OR
118372         (NVL(l_enc_upg_option, 'N') = 'O')
118373       )
118374    THEN
118378    
118375    NULL;
118376    --
118377    --
118379   l_ccid := AcctDerRule_175(
118380            p_application_id           => p_application_id
118381          , p_ae_header_id             => l_ae_header_id 
118382 , p_source_3 => p_source_3
118383 , p_source_29 => p_source_29
118384          , x_transaction_coa_id       => l_adr_transaction_coa_id
118385          , x_accounting_coa_id        => l_adr_accounting_coa_id
118386          , x_value_type_code          => l_adr_value_type_code
118387          , p_side                     => 'NA'
118388    );
118389 
118390    xla_ae_lines_pkg.set_ccid(
118391     p_code_combination_id          => l_ccid
118392   , p_value_type_code              => l_adr_value_type_code
118393   , p_transaction_coa_id           => l_adr_transaction_coa_id
118394   , p_accounting_coa_id            => l_adr_accounting_coa_id
118395   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
118396   , p_adr_type_code                => 'S'
118397   , p_component_type               => l_component_type
118398   , p_component_code               => l_component_code
118399   , p_component_type_code          => l_component_type_code
118400   , p_component_appl_id            => l_component_appl_id
118401   , p_amb_context_code             => l_amb_context_code
118402   , p_side                         => 'NA'
118403   );
118404 
118405 
118406    l_segment := AcctDerRule_143(
118407            p_application_id           => p_application_id
118408          , p_ae_header_id             => l_ae_header_id 
118409 , p_source_2 => p_source_2
118410 , p_source_3 => p_source_3
118411          , x_transaction_coa_id       => l_adr_transaction_coa_id
118412          , x_accounting_coa_id        => l_adr_accounting_coa_id
118413          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
118414          , x_flex_value_set_id        => l_adr_flex_value_set_id
118415          , x_value_type_code          => l_adr_value_type_code
118416          , x_value_combination_id     => l_adr_value_combination_id
118417          , x_value_segment_code       => l_adr_value_segment_code
118418          , p_side                     => 'NA'
118419          , p_override_seg_flag        => 'Y'
118420    );
118421 
118422    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
118423 
118424       xla_ae_lines_pkg.set_segment(
118425           p_to_segment_code         => 'GL_ACCOUNT'
118426         , p_segment_value           => l_segment
118427         , p_from_segment_code       => l_adr_value_segment_code
118428         , p_from_combination_id     => l_adr_value_combination_id
118429         , p_value_type_code         => l_adr_value_type_code
118430         , p_transaction_coa_id      => l_adr_transaction_coa_id
118431         , p_accounting_coa_id       => l_adr_accounting_coa_id
118432         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
118433         , p_flex_value_set_id       => l_adr_flex_value_set_id
118434         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
118435         , p_adr_type_code           => 'S'
118436         , p_component_type          => l_component_type
118437         , p_component_code          => l_component_code
118438         , p_component_type_code     => l_component_type_code
118439         , p_component_appl_id       => l_component_appl_id
118440         , p_amb_context_code        => l_amb_context_code
118441         , p_entity_code             => 'TRANSACTIONS'
118442         , p_event_class_code        => 'REVALUATION'
118443         , p_side                    => 'NA'
118444         );
118445 
118446   END IF;
118447 
118448    --
118449    --
118450    END IF;
118451 
118452        --
118453        -- Update the line information that should be overwritten
118454        --
118455        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
118456                                          p_header_num   => 1);
118457        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
118458 
118459        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
118460 
118461        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
118462           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
118463        END IF;
118464 
118465       --
118466       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
118467       --
118468       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
118469           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
118470       ELSE
118471           ---------------------------------------------------------------------------------------------------
118472           -- 4262811a Switch Sign
118473           ---------------------------------------------------------------------------------------------------
118474           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
118475           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
118476                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
118477           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
118478                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
118479           -- 5132302
118480           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
118481                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
118482 
118483       END IF;
118484 
118485       -- 4955764
118486       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
118487       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
118488 
118489 
118493       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
118490       XLA_AE_LINES_PKG.ValidateCurrentLine;
118491       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
118492 
118494                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
118495                ,p_balance_type_code => l_balance_type_code);
118496 
118497    END IF;
118498 
118499    -----------------------------------------------------------------------------------------
118500    -- 4262811 Multiperiod Accounting
118501    -----------------------------------------------------------------------------------------
118502      -- No MPA option is assigned.
118503 
118504 
118505 END IF;
118506 END IF;
118507 --
118508 
118509 --
118510 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
118511    trace
118512       (p_msg      => 'END of AcctLineType_319'
118513       ,p_level    => C_LEVEL_PROCEDURE
118514       ,p_module   => l_log_module);
118515 END IF;
118516 --
118517 EXCEPTION
118518   WHEN xla_exceptions_pkg.application_exception THEN
118519       RAISE;
118520   WHEN OTHERS THEN
118521        xla_exceptions_pkg.raise_message
118522            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_319');
118523 END AcctLineType_319;
118524 --
118525 
118526 ---------------------------------------
118527 --
118528 -- PRIVATE FUNCTION
118529 --         AcctLineType_320
118530 --
118531 ---------------------------------------
118532 PROCEDURE AcctLineType_320 (
118533   p_application_id        IN NUMBER
118534  ,p_event_id              IN NUMBER
118535  ,p_calculate_acctd_flag  IN VARCHAR2
118536  ,p_calculate_g_l_flag    IN VARCHAR2
118537  ,p_actual_flag           IN OUT VARCHAR2
118538  ,p_balance_type_code     OUT VARCHAR2
118539  ,p_gain_or_loss_ref      OUT VARCHAR2
118540  
118541 --Period Close Date
118542  , p_source_1            IN DATE
118543 --Generated Code Combination Identifier
118544  , p_source_3            IN NUMBER
118545 --Asset Cost Account
118546  , p_source_9            IN VARCHAR2
118547 --Expense Account Code Combination Identifier
118548  , p_source_29            IN NUMBER
118549 --Default Code Combination Identifier
118550  , p_source_30            IN NUMBER
118551 --Adjustment Type
118552  , p_source_35            IN VARCHAR2
118553 --Transaction Header Identifier
118554  , p_source_36            IN NUMBER
118555 --Adjustment Line Identifier
118556  , p_source_37            IN NUMBER
118557 --Distribution Type Code
118558  , p_source_38            IN VARCHAR2
118559 --Entered Amount
118560  , p_source_39            IN NUMBER
118561 --Currency Code
118562  , p_source_40            IN VARCHAR2
118563 )
118564 IS
118565 
118566 l_component_type              VARCHAR2(80);
118567 l_component_code              VARCHAR2(30);
118568 l_component_type_code         VARCHAR2(1);
118569 l_component_appl_id           INTEGER;
118570 l_amb_context_code            VARCHAR2(30);
118571 l_entity_code                 VARCHAR2(30);
118572 l_event_class_code            VARCHAR2(30);
118573 l_ae_header_id                NUMBER;
118574 l_event_type_code             VARCHAR2(30);
118575 l_line_definition_code        VARCHAR2(30);
118576 l_line_definition_owner_code  VARCHAR2(1);
118577 --
118578 -- adr variables
118579 l_segment                     VARCHAR2(30);
118580 l_ccid                        NUMBER;
118581 l_adr_transaction_coa_id      NUMBER;
118582 l_adr_accounting_coa_id       NUMBER;
118583 l_adr_flexfield_segment_code  VARCHAR2(30);
118584 l_adr_flex_value_set_id       NUMBER;
118585 l_adr_value_type_code         VARCHAR2(30);
118586 l_adr_value_combination_id    NUMBER;
118587 l_adr_value_segment_code      VARCHAR2(30);
118588 
118589 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
118590 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
118591 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
118592 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
118593 
118594 -- 4262811 Variables ------------------------------------------------------------------------------------------
118595 l_entered_amt_idx             NUMBER;
118596 l_accted_amt_idx              NUMBER;
118597 l_acc_rev_flag                VARCHAR2(1);
118598 l_accrual_line_num            NUMBER;
118599 l_tmp_amt                     NUMBER;
118600 l_acc_rev_natural_side_code   VARCHAR2(1);
118601 
118602 l_num_entries                 NUMBER;
118603 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
118604 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
118605 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
118606 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
118607 l_recog_line_1                NUMBER;
118608 l_recog_line_2                NUMBER;
118609 
118610 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
118611 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
118612 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
118613 
118614 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
118615 
118616 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
118617 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
118618 
118619 ---------------------------------------------------------------------------------------------------------------
118620 
118621 
118622 --
118623 -- bulk performance
118624 --
118625 l_balance_type_code           VARCHAR2(1);
118626 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
118627 l_log_module                  VARCHAR2(240);
118628 
118629 --
118630 -- Upgrade strategy
118631 --
118632 l_actual_upg_option           VARCHAR2(1);
118633 l_enc_upg_option           VARCHAR2(1);
118637 --
118634 
118635 --
118636 BEGIN
118638 IF g_log_enabled THEN
118639       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_320';
118640 END IF;
118641 --
118642 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
118643 
118644       trace
118645          (p_msg      => 'BEGIN of AcctLineType_320'
118646          ,p_level    => C_LEVEL_PROCEDURE
118647          ,p_module   => l_log_module);
118648 
118649 END IF;
118650 --
118651 l_component_type             := 'AMB_JLT';
118652 l_component_code             := 'FA_REVAL_COST';
118653 l_component_type_code        := 'S';
118654 l_component_appl_id          :=  140;
118655 l_amb_context_code           := 'DEFAULT';
118656 l_entity_code                := 'TRANSACTIONS';
118657 l_event_class_code           := 'REVALUATION';
118658 l_event_type_code            := 'REVALUATION_ALL';
118659 l_line_definition_owner_code := 'S';
118660 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVAL21';
118661 --
118662 l_balance_type_code          := 'A';
118663 l_segment                     := NULL;
118664 l_ccid                        := NULL;
118665 l_adr_transaction_coa_id      := NULL;
118666 l_adr_accounting_coa_id       := NULL;
118667 l_adr_flexfield_segment_code  := NULL;
118668 l_adr_flex_value_set_id       := NULL;
118669 l_adr_value_type_code         := NULL;
118670 l_adr_value_combination_id    := NULL;
118671 l_adr_value_segment_code      := NULL;
118672 
118673 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
118674 l_bflow_class_code           := '';    -- 4219869 Business Flow
118675 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
118676 l_budgetary_control_flag     := 'N';
118677 
118678 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
118679 l_bflow_applied_to_amt       := NULL; -- 5132302
118680 l_entered_amt_idx            := NULL;          -- 4262811
118681 l_accted_amt_idx             := NULL;          -- 4262811
118682 l_acc_rev_flag               := NULL;          -- 4262811
118683 l_accrual_line_num           := NULL;          -- 4262811
118684 l_tmp_amt                    := NULL;          -- 4262811
118685 --
118686  
118687 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
118688     l_balance_type_code <> 'B' THEN
118689 IF NVL(p_source_35,'
118690 ') =  'COST'
118691  THEN 
118692 
118693    --
118694    XLA_AE_LINES_PKG.SetNewLine;
118695 
118696    p_balance_type_code          := l_balance_type_code;
118697    -- set the flag so later we will know whether the gain loss line needs to be created
118698    
118699    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
118700      p_actual_flag :='A';
118701    END IF;
118702 
118703    --
118704    -- bulk performance
118705    --
118706    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
118707                                       p_header_num   => 0); -- 4262811
118708    --
118709    -- set accounting line options
118710    --
118711    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
118712            p_natural_side_code          => 'D'
118713          , p_gain_or_loss_flag          => 'N'
118714          , p_gl_transfer_mode_code      => 'S'
118715          , p_acct_entry_type_code       => 'A'
118716          , p_switch_side_flag           => 'Y'
118717          , p_merge_duplicate_code       => 'N'
118718          );
118719    --
118720    l_acc_rev_natural_side_code := 'C';  -- 4262811
118721    -- 
118722    --
118723    -- set accounting line type info
118724    --
118725    xla_ae_lines_pkg.SetAcctLineType
118726       (p_component_type             => l_component_type
118727       ,p_event_type_code            => l_event_type_code
118728       ,p_line_definition_owner_code => l_line_definition_owner_code
118729       ,p_line_definition_code       => l_line_definition_code
118730       ,p_accounting_line_code       => l_component_code
118731       ,p_accounting_line_type_code  => l_component_type_code
118732       ,p_accounting_line_appl_id    => l_component_appl_id
118733       ,p_amb_context_code           => l_amb_context_code
118734       ,p_entity_code                => l_entity_code
118735       ,p_event_class_code           => l_event_class_code);
118736    --
118737    -- set accounting class
118738    --
118739    xla_ae_lines_pkg.SetAcctClass(
118740            p_accounting_class_code  => 'ASSET'
118741          , p_ae_header_id           => l_ae_header_id
118742          );
118743 
118744    --
118745    -- set rounding class
118746    --
118747    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
118748                       'ASSET';
118749 
118750    --
118751    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
118752    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
118753    --
118754    -- bulk performance
118755    --
118756    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
118757 
118758    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
118759       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
118760 
118761    -- 4955764
118762    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
118763       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
118764 
118765    -- 4458381 Public Sector Enh
118766    
118767    --
118768    -- set accounting attributes for the line type
118769    --
118770    l_entered_amt_idx := 4;
118771    l_accted_amt_idx  := 6;
118772    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
118773    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
118774    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
118778    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
118775    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
118776    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
118777    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
118779    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
118780    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
118781    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
118782    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
118783    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
118784    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
118785 
118786    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
118787    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
118788 
118789    ---------------------------------------------------------------------------------------------------------------
118790    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
118791    ---------------------------------------------------------------------------------------------------------------
118792    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
118793 
118794    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
118795    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
118796 
118797    IF xla_accounting_cache_pkg.GetValueChar
118798          (p_source_code         => 'LEDGER_CATEGORY_CODE'
118799          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
118800    AND l_bflow_method_code = 'PRIOR_ENTRY'
118801 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
118802    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
118803          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
118804        )
118805    THEN
118806          xla_ae_lines_pkg.BflowUpgEntry
118807            (p_business_method_code    => l_bflow_method_code
118808            ,p_business_class_code     => l_bflow_class_code
118809            ,p_balance_type            => l_balance_type_code);
118810    ELSE
118811       NULL;
118812 -- No business flow processing for business flow method of NONE.
118813    END IF;
118814 
118815    --
118816    -- call analytical criteria
118817    --
118818    
118819    --
118820    -- call description
118821    --
118822    
118823 xla_ae_lines_pkg.SetLineDescription(
118824    p_ae_header_id => l_ae_header_id
118825   ,p_description  => Description_93 (
118826      p_application_id         => p_application_id
118827    , p_ae_header_id           => l_ae_header_id 
118828 , p_source_1 => p_source_1
118829    )
118830 );
118831 
118832 
118833    --
118834    -- call ADRs
118835    -- Bug 4922099
118836    --
118837    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
118838         (NVL(l_actual_upg_option, 'N') = 'O') OR
118839         (NVL(l_enc_upg_option, 'N') = 'O')
118840       )
118841    THEN
118842    NULL;
118843    --
118844    --
118845    
118846   l_ccid := AcctDerRule_173(
118847            p_application_id           => p_application_id
118848          , p_ae_header_id             => l_ae_header_id 
118849 , p_source_3 => p_source_3
118850 , p_source_30 => p_source_30
118851          , x_transaction_coa_id       => l_adr_transaction_coa_id
118852          , x_accounting_coa_id        => l_adr_accounting_coa_id
118853          , x_value_type_code          => l_adr_value_type_code
118854          , p_side                     => 'NA'
118855    );
118856 
118857    xla_ae_lines_pkg.set_ccid(
118858     p_code_combination_id          => l_ccid
118859   , p_value_type_code              => l_adr_value_type_code
118860   , p_transaction_coa_id           => l_adr_transaction_coa_id
118861   , p_accounting_coa_id            => l_adr_accounting_coa_id
118862   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
118863   , p_adr_type_code                => 'S'
118864   , p_component_type               => l_component_type
118865   , p_component_code               => l_component_code
118866   , p_component_type_code          => l_component_type_code
118867   , p_component_appl_id            => l_component_appl_id
118868   , p_amb_context_code             => l_amb_context_code
118869   , p_side                         => 'NA'
118870   );
118871 
118872 
118873    l_segment := AcctDerRule_148(
118874            p_application_id           => p_application_id
118875          , p_ae_header_id             => l_ae_header_id 
118876 , p_source_3 => p_source_3
118877 , p_source_9 => p_source_9
118878          , x_transaction_coa_id       => l_adr_transaction_coa_id
118879          , x_accounting_coa_id        => l_adr_accounting_coa_id
118880          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
118881          , x_flex_value_set_id        => l_adr_flex_value_set_id
118882          , x_value_type_code          => l_adr_value_type_code
118883          , x_value_combination_id     => l_adr_value_combination_id
118884          , x_value_segment_code       => l_adr_value_segment_code
118885          , p_side                     => 'NA'
118886          , p_override_seg_flag        => 'Y'
118887    );
118888 
118889    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
118890 
118891       xla_ae_lines_pkg.set_segment(
118892           p_to_segment_code         => 'GL_ACCOUNT'
118893         , p_segment_value           => l_segment
118894         , p_from_segment_code       => l_adr_value_segment_code
118895         , p_from_combination_id     => l_adr_value_combination_id
118896         , p_value_type_code         => l_adr_value_type_code
118897         , p_transaction_coa_id      => l_adr_transaction_coa_id
118898         , p_accounting_coa_id       => l_adr_accounting_coa_id
118902         , p_adr_type_code           => 'S'
118899         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
118900         , p_flex_value_set_id       => l_adr_flex_value_set_id
118901         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
118903         , p_component_type          => l_component_type
118904         , p_component_code          => l_component_code
118905         , p_component_type_code     => l_component_type_code
118906         , p_component_appl_id       => l_component_appl_id
118907         , p_amb_context_code        => l_amb_context_code
118908         , p_entity_code             => 'TRANSACTIONS'
118909         , p_event_class_code        => 'REVALUATION'
118910         , p_side                    => 'NA'
118911         );
118912 
118913   END IF;
118914 
118915    l_segment := AcctDerRule_168(
118916            p_application_id           => p_application_id
118917          , p_ae_header_id             => l_ae_header_id 
118918 , p_source_3 => p_source_3
118919 , p_source_29 => p_source_29
118920          , x_transaction_coa_id       => l_adr_transaction_coa_id
118921          , x_accounting_coa_id        => l_adr_accounting_coa_id
118922          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
118923          , x_flex_value_set_id        => l_adr_flex_value_set_id
118924          , x_value_type_code          => l_adr_value_type_code
118925          , x_value_combination_id     => l_adr_value_combination_id
118926          , x_value_segment_code       => l_adr_value_segment_code
118927          , p_side                     => 'NA'
118928          , p_override_seg_flag        => 'Y'
118929    );
118930 
118931    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
118932 
118933       xla_ae_lines_pkg.set_segment(
118934           p_to_segment_code         => 'GL_BALANCING'
118935         , p_segment_value           => l_segment
118936         , p_from_segment_code       => l_adr_value_segment_code
118937         , p_from_combination_id     => l_adr_value_combination_id
118938         , p_value_type_code         => l_adr_value_type_code
118939         , p_transaction_coa_id      => l_adr_transaction_coa_id
118940         , p_accounting_coa_id       => l_adr_accounting_coa_id
118941         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
118942         , p_flex_value_set_id       => l_adr_flex_value_set_id
118943         , p_adr_code                => 'FA_EXPENSE_ACCT'
118944         , p_adr_type_code           => 'S'
118945         , p_component_type          => l_component_type
118946         , p_component_code          => l_component_code
118947         , p_component_type_code     => l_component_type_code
118948         , p_component_appl_id       => l_component_appl_id
118949         , p_amb_context_code        => l_amb_context_code
118950         , p_entity_code             => 'TRANSACTIONS'
118951         , p_event_class_code        => 'REVALUATION'
118952         , p_side                    => 'NA'
118953         );
118954 
118955   END IF;
118956 
118957    --
118958    --
118959    END IF;
118960    --
118961    -- Bug 4922099
118962    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
118963           (NVL(l_enc_upg_option, 'N') = 'O')
118964         ) AND
118965         (l_bflow_method_code = 'PRIOR_ENTRY')
118966       )
118967    THEN
118968       IF
118969       --
118970       1 = 2
118971       --
118972       THEN
118973       xla_accounting_err_pkg.build_message
118974                                     (p_appli_s_name            => 'XLA'
118975                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
118976                                     ,p_token_1                 => 'LINE_NUMBER'
118977                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
118978                                     ,p_token_2                 => 'LINE_TYPE_NAME'
118979                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
118980                                                                              l_component_type
118981                                                                             ,l_component_code
118982                                                                             ,l_component_type_code
118983                                                                             ,l_component_appl_id
118984                                                                             ,l_amb_context_code
118985                                                                             ,l_entity_code
118986                                                                             ,l_event_class_code
118987                                                                            )
118988                                     ,p_token_3                 => 'OWNER'
118989                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
118990                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
118991                                                                           ,p_lookup_code    => l_component_type_code
118992                                                                          )
118993                                     ,p_token_4                 => 'PRODUCT_NAME'
118994                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
118995                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
118996                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
118997                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
118998                                     ,p_ae_header_id            =>  NULL
118999                                        );
119000 
119001         IF (C_LEVEL_ERROR>= g_log_level) THEN
119002                  trace
119003                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
119007       END IF;
119004                       ,p_level    => C_LEVEL_ERROR
119005                       ,p_module   => l_log_module);
119006         END IF;
119008    END IF;
119009    --
119010    --
119011    ------------------------------------------------------------------------------------------------
119012    -- 4219869 Business Flow
119013    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
119014    -- Prior Entry.  Currently, the following code is always generated.
119015    ------------------------------------------------------------------------------------------------
119016    XLA_AE_LINES_PKG.ValidateCurrentLine;
119017 
119018    ------------------------------------------------------------------------------------
119019    -- 4219869 Business Flow
119020    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
119021    ------------------------------------------------------------------------------------
119022    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
119023 
119024    ----------------------------------------------------------------------------------
119025    -- 4219869 Business Flow
119026    -- Update journal entry status -- Need to generate this within IF <condition>
119027    ----------------------------------------------------------------------------------
119028    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
119029          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
119030          ,p_balance_type_code => l_balance_type_code
119031          );
119032 
119033    -------------------------------------------------------------------------------------------
119034    -- 4262811 - Generate the Accrual Reversal lines
119035    -------------------------------------------------------------------------------------------
119036    BEGIN
119037       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
119038                               (g_array_event(p_event_id).array_value_num('header_index'));
119039       IF l_acc_rev_flag IS NULL THEN
119040          l_acc_rev_flag := 'N';
119041       END IF;
119042    EXCEPTION
119043       WHEN OTHERS THEN
119044          l_acc_rev_flag := 'N';
119045    END;
119046    --
119047    IF (l_acc_rev_flag = 'Y') THEN
119048 
119049        -- 4645092  ------------------------------------------------------------------------------
119050        -- To allow MPA report to determine if it should generate report process
119051        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
119052        ------------------------------------------------------------------------------------------
119053 
119054        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
119055        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
119056    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
119057    -- call ADRs
119058    -- Bug 4922099
119059    --
119060    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
119061         (NVL(l_actual_upg_option, 'N') = 'O') OR
119062         (NVL(l_enc_upg_option, 'N') = 'O')
119063       )
119064    THEN
119065    NULL;
119066    --
119067    --
119068    
119069   l_ccid := AcctDerRule_173(
119070            p_application_id           => p_application_id
119071          , p_ae_header_id             => l_ae_header_id 
119072 , p_source_3 => p_source_3
119073 , p_source_30 => p_source_30
119074          , x_transaction_coa_id       => l_adr_transaction_coa_id
119075          , x_accounting_coa_id        => l_adr_accounting_coa_id
119076          , x_value_type_code          => l_adr_value_type_code
119077          , p_side                     => 'NA'
119078    );
119079 
119080    xla_ae_lines_pkg.set_ccid(
119081     p_code_combination_id          => l_ccid
119082   , p_value_type_code              => l_adr_value_type_code
119083   , p_transaction_coa_id           => l_adr_transaction_coa_id
119084   , p_accounting_coa_id            => l_adr_accounting_coa_id
119085   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
119086   , p_adr_type_code                => 'S'
119087   , p_component_type               => l_component_type
119088   , p_component_code               => l_component_code
119089   , p_component_type_code          => l_component_type_code
119090   , p_component_appl_id            => l_component_appl_id
119091   , p_amb_context_code             => l_amb_context_code
119092   , p_side                         => 'NA'
119093   );
119094 
119095 
119096    l_segment := AcctDerRule_148(
119097            p_application_id           => p_application_id
119098          , p_ae_header_id             => l_ae_header_id 
119099 , p_source_3 => p_source_3
119100 , p_source_9 => p_source_9
119101          , x_transaction_coa_id       => l_adr_transaction_coa_id
119102          , x_accounting_coa_id        => l_adr_accounting_coa_id
119103          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
119104          , x_flex_value_set_id        => l_adr_flex_value_set_id
119105          , x_value_type_code          => l_adr_value_type_code
119106          , x_value_combination_id     => l_adr_value_combination_id
119107          , x_value_segment_code       => l_adr_value_segment_code
119108          , p_side                     => 'NA'
119109          , p_override_seg_flag        => 'Y'
119110    );
119111 
119112    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
119113 
119114       xla_ae_lines_pkg.set_segment(
119115           p_to_segment_code         => 'GL_ACCOUNT'
119116         , p_segment_value           => l_segment
119117         , p_from_segment_code       => l_adr_value_segment_code
119118         , p_from_combination_id     => l_adr_value_combination_id
119119         , p_value_type_code         => l_adr_value_type_code
119120         , p_transaction_coa_id      => l_adr_transaction_coa_id
119121         , p_accounting_coa_id       => l_adr_accounting_coa_id
119122         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
119126         , p_component_type          => l_component_type
119123         , p_flex_value_set_id       => l_adr_flex_value_set_id
119124         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
119125         , p_adr_type_code           => 'S'
119127         , p_component_code          => l_component_code
119128         , p_component_type_code     => l_component_type_code
119129         , p_component_appl_id       => l_component_appl_id
119130         , p_amb_context_code        => l_amb_context_code
119131         , p_entity_code             => 'TRANSACTIONS'
119132         , p_event_class_code        => 'REVALUATION'
119133         , p_side                    => 'NA'
119134         );
119135 
119136   END IF;
119137 
119138    l_segment := AcctDerRule_168(
119139            p_application_id           => p_application_id
119140          , p_ae_header_id             => l_ae_header_id 
119141 , p_source_3 => p_source_3
119142 , p_source_29 => p_source_29
119143          , x_transaction_coa_id       => l_adr_transaction_coa_id
119144          , x_accounting_coa_id        => l_adr_accounting_coa_id
119145          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
119146          , x_flex_value_set_id        => l_adr_flex_value_set_id
119147          , x_value_type_code          => l_adr_value_type_code
119148          , x_value_combination_id     => l_adr_value_combination_id
119149          , x_value_segment_code       => l_adr_value_segment_code
119150          , p_side                     => 'NA'
119151          , p_override_seg_flag        => 'Y'
119152    );
119153 
119154    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
119155 
119156       xla_ae_lines_pkg.set_segment(
119157           p_to_segment_code         => 'GL_BALANCING'
119158         , p_segment_value           => l_segment
119159         , p_from_segment_code       => l_adr_value_segment_code
119160         , p_from_combination_id     => l_adr_value_combination_id
119161         , p_value_type_code         => l_adr_value_type_code
119162         , p_transaction_coa_id      => l_adr_transaction_coa_id
119163         , p_accounting_coa_id       => l_adr_accounting_coa_id
119164         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
119165         , p_flex_value_set_id       => l_adr_flex_value_set_id
119166         , p_adr_code                => 'FA_EXPENSE_ACCT'
119167         , p_adr_type_code           => 'S'
119168         , p_component_type          => l_component_type
119169         , p_component_code          => l_component_code
119170         , p_component_type_code     => l_component_type_code
119171         , p_component_appl_id       => l_component_appl_id
119172         , p_amb_context_code        => l_amb_context_code
119173         , p_entity_code             => 'TRANSACTIONS'
119174         , p_event_class_code        => 'REVALUATION'
119175         , p_side                    => 'NA'
119176         );
119177 
119178   END IF;
119179 
119180    --
119181    --
119182    END IF;
119183 
119184        --
119185        -- Update the line information that should be overwritten
119186        --
119187        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
119188                                          p_header_num   => 1);
119189        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
119190 
119191        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
119192 
119193        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
119194           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
119195        END IF;
119196 
119197       --
119198       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
119199       --
119200       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
119201           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
119202       ELSE
119203           ---------------------------------------------------------------------------------------------------
119204           -- 4262811a Switch Sign
119205           ---------------------------------------------------------------------------------------------------
119206           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
119207           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
119208                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
119209           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
119210                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
119211           -- 5132302
119212           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
119213                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
119214 
119215       END IF;
119216 
119217       -- 4955764
119218       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
119219       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
119220 
119221 
119222       XLA_AE_LINES_PKG.ValidateCurrentLine;
119223       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
119224 
119225       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
119226                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
119227                ,p_balance_type_code => l_balance_type_code);
119228 
119229    END IF;
119230 
119231    -----------------------------------------------------------------------------------------
119232    -- 4262811 Multiperiod Accounting
119233    -----------------------------------------------------------------------------------------
119234      -- No MPA option is assigned.
119235 
119236 
119240 
119237 END IF;
119238 END IF;
119239 --
119241 --
119242 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
119243    trace
119244       (p_msg      => 'END of AcctLineType_320'
119245       ,p_level    => C_LEVEL_PROCEDURE
119246       ,p_module   => l_log_module);
119247 END IF;
119248 --
119249 EXCEPTION
119250   WHEN xla_exceptions_pkg.application_exception THEN
119251       RAISE;
119252   WHEN OTHERS THEN
119253        xla_exceptions_pkg.raise_message
119254            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_320');
119255 END AcctLineType_320;
119256 --
119257 
119258 ---------------------------------------
119259 --
119260 -- PRIVATE FUNCTION
119261 --         AcctLineType_321
119262 --
119263 ---------------------------------------
119264 PROCEDURE AcctLineType_321 (
119265   p_application_id        IN NUMBER
119266  ,p_event_id              IN NUMBER
119267  ,p_calculate_acctd_flag  IN VARCHAR2
119268  ,p_calculate_g_l_flag    IN VARCHAR2
119269  ,p_actual_flag           IN OUT VARCHAR2
119270  ,p_balance_type_code     OUT VARCHAR2
119271  ,p_gain_or_loss_ref      OUT VARCHAR2
119272  
119273 --Period Close Date
119274  , p_source_1            IN DATE
119275 --Generated Code Combination Identifier
119276  , p_source_3            IN NUMBER
119277 --Depreciation Reserve Account
119278  , p_source_10            IN VARCHAR2
119279 --Generated Offset Code Combination Identifier
119280  , p_source_17            IN NUMBER
119281 --Expense Account Code Combination Identifier
119282  , p_source_29            IN NUMBER
119283 --Default Code Combination Identifier
119284  , p_source_30            IN NUMBER
119285 --Adjustment Type
119286  , p_source_35            IN VARCHAR2
119287 --Transaction Header Identifier
119288  , p_source_36            IN NUMBER
119289 --Adjustment Line Identifier
119290  , p_source_37            IN NUMBER
119291 --Distribution Type Code
119292  , p_source_38            IN VARCHAR2
119293 --Entered Amount
119294  , p_source_39            IN NUMBER
119295 --Currency Code
119296  , p_source_40            IN VARCHAR2
119297 )
119298 IS
119299 
119300 l_component_type              VARCHAR2(80);
119301 l_component_code              VARCHAR2(30);
119302 l_component_type_code         VARCHAR2(1);
119303 l_component_appl_id           INTEGER;
119304 l_amb_context_code            VARCHAR2(30);
119305 l_entity_code                 VARCHAR2(30);
119306 l_event_class_code            VARCHAR2(30);
119307 l_ae_header_id                NUMBER;
119308 l_event_type_code             VARCHAR2(30);
119309 l_line_definition_code        VARCHAR2(30);
119310 l_line_definition_owner_code  VARCHAR2(1);
119311 --
119312 -- adr variables
119313 l_segment                     VARCHAR2(30);
119314 l_ccid                        NUMBER;
119315 l_adr_transaction_coa_id      NUMBER;
119316 l_adr_accounting_coa_id       NUMBER;
119317 l_adr_flexfield_segment_code  VARCHAR2(30);
119318 l_adr_flex_value_set_id       NUMBER;
119319 l_adr_value_type_code         VARCHAR2(30);
119320 l_adr_value_combination_id    NUMBER;
119321 l_adr_value_segment_code      VARCHAR2(30);
119322 
119323 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
119324 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
119325 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
119326 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
119327 
119328 -- 4262811 Variables ------------------------------------------------------------------------------------------
119329 l_entered_amt_idx             NUMBER;
119330 l_accted_amt_idx              NUMBER;
119331 l_acc_rev_flag                VARCHAR2(1);
119332 l_accrual_line_num            NUMBER;
119333 l_tmp_amt                     NUMBER;
119334 l_acc_rev_natural_side_code   VARCHAR2(1);
119335 
119336 l_num_entries                 NUMBER;
119337 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
119338 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
119339 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
119340 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
119341 l_recog_line_1                NUMBER;
119342 l_recog_line_2                NUMBER;
119343 
119344 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
119345 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
119346 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
119347 
119348 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
119349 
119350 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
119351 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
119352 
119353 ---------------------------------------------------------------------------------------------------------------
119354 
119355 
119356 --
119357 -- bulk performance
119358 --
119359 l_balance_type_code           VARCHAR2(1);
119360 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
119361 l_log_module                  VARCHAR2(240);
119362 
119363 --
119364 -- Upgrade strategy
119365 --
119366 l_actual_upg_option           VARCHAR2(1);
119367 l_enc_upg_option           VARCHAR2(1);
119368 
119369 --
119370 BEGIN
119371 --
119372 IF g_log_enabled THEN
119373       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_321';
119374 END IF;
119375 --
119376 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
119377 
119378       trace
119379          (p_msg      => 'BEGIN of AcctLineType_321'
119380          ,p_level    => C_LEVEL_PROCEDURE
119381          ,p_module   => l_log_module);
119382 
119383 END IF;
119384 --
119385 l_component_type             := 'AMB_JLT';
119386 l_component_code             := 'FA_REVAL_DEPRN_RESERVE';
119390 l_entity_code                := 'TRANSACTIONS';
119387 l_component_type_code        := 'S';
119388 l_component_appl_id          :=  140;
119389 l_amb_context_code           := 'DEFAULT';
119391 l_event_class_code           := 'REVALUATION';
119392 l_event_type_code            := 'REVALUATION_ALL';
119393 l_line_definition_owner_code := 'S';
119394 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVAL21';
119395 --
119396 l_balance_type_code          := 'A';
119397 l_segment                     := NULL;
119398 l_ccid                        := NULL;
119399 l_adr_transaction_coa_id      := NULL;
119400 l_adr_accounting_coa_id       := NULL;
119401 l_adr_flexfield_segment_code  := NULL;
119402 l_adr_flex_value_set_id       := NULL;
119403 l_adr_value_type_code         := NULL;
119404 l_adr_value_combination_id    := NULL;
119405 l_adr_value_segment_code      := NULL;
119406 
119407 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
119408 l_bflow_class_code           := '';    -- 4219869 Business Flow
119409 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
119410 l_budgetary_control_flag     := 'N';
119411 
119412 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
119413 l_bflow_applied_to_amt       := NULL; -- 5132302
119414 l_entered_amt_idx            := NULL;          -- 4262811
119415 l_accted_amt_idx             := NULL;          -- 4262811
119416 l_acc_rev_flag               := NULL;          -- 4262811
119417 l_accrual_line_num           := NULL;          -- 4262811
119418 l_tmp_amt                    := NULL;          -- 4262811
119419 --
119420  
119421 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
119422     l_balance_type_code <> 'B' THEN
119423 IF NVL(p_source_35,'
119424 ') =  'RESERVE'
119425  THEN 
119426 
119427    --
119428    XLA_AE_LINES_PKG.SetNewLine;
119429 
119430    p_balance_type_code          := l_balance_type_code;
119431    -- set the flag so later we will know whether the gain loss line needs to be created
119432    
119433    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
119434      p_actual_flag :='A';
119435    END IF;
119436 
119437    --
119438    -- bulk performance
119439    --
119440    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
119441                                       p_header_num   => 0); -- 4262811
119442    --
119443    -- set accounting line options
119444    --
119445    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
119446            p_natural_side_code          => 'C'
119447          , p_gain_or_loss_flag          => 'N'
119448          , p_gl_transfer_mode_code      => 'S'
119449          , p_acct_entry_type_code       => 'A'
119450          , p_switch_side_flag           => 'Y'
119451          , p_merge_duplicate_code       => 'N'
119452          );
119453    --
119454    l_acc_rev_natural_side_code := 'D';  -- 4262811
119455    -- 
119456    --
119457    -- set accounting line type info
119458    --
119459    xla_ae_lines_pkg.SetAcctLineType
119460       (p_component_type             => l_component_type
119461       ,p_event_type_code            => l_event_type_code
119462       ,p_line_definition_owner_code => l_line_definition_owner_code
119463       ,p_line_definition_code       => l_line_definition_code
119464       ,p_accounting_line_code       => l_component_code
119465       ,p_accounting_line_type_code  => l_component_type_code
119466       ,p_accounting_line_appl_id    => l_component_appl_id
119467       ,p_amb_context_code           => l_amb_context_code
119468       ,p_entity_code                => l_entity_code
119469       ,p_event_class_code           => l_event_class_code);
119470    --
119471    -- set accounting class
119472    --
119473    xla_ae_lines_pkg.SetAcctClass(
119474            p_accounting_class_code  => 'ASSET'
119475          , p_ae_header_id           => l_ae_header_id
119476          );
119477 
119478    --
119479    -- set rounding class
119480    --
119481    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
119482                       'ASSET';
119483 
119484    --
119485    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
119486    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
119487    --
119488    -- bulk performance
119489    --
119490    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
119491 
119492    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
119493       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
119494 
119495    -- 4955764
119496    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
119497       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
119498 
119499    -- 4458381 Public Sector Enh
119500    
119501    --
119502    -- set accounting attributes for the line type
119503    --
119504    l_entered_amt_idx := 4;
119505    l_accted_amt_idx  := 6;
119506    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
119507    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
119508    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
119509    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
119510    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
119511    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
119512    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
119513    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
119514    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
119515    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
119516    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
119517    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
119521    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
119518    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
119519 
119520    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
119522 
119523    ---------------------------------------------------------------------------------------------------------------
119524    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
119525    ---------------------------------------------------------------------------------------------------------------
119526    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
119527 
119528    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
119529    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
119530 
119531    IF xla_accounting_cache_pkg.GetValueChar
119532          (p_source_code         => 'LEDGER_CATEGORY_CODE'
119533          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
119534    AND l_bflow_method_code = 'PRIOR_ENTRY'
119535 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
119536    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
119537          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
119538        )
119539    THEN
119540          xla_ae_lines_pkg.BflowUpgEntry
119541            (p_business_method_code    => l_bflow_method_code
119542            ,p_business_class_code     => l_bflow_class_code
119543            ,p_balance_type            => l_balance_type_code);
119544    ELSE
119545       NULL;
119546 -- No business flow processing for business flow method of NONE.
119547    END IF;
119548 
119549    --
119550    -- call analytical criteria
119551    --
119552    
119553    --
119554    -- call description
119555    --
119556    
119557 xla_ae_lines_pkg.SetLineDescription(
119558    p_ae_header_id => l_ae_header_id
119559   ,p_description  => Description_94 (
119560      p_application_id         => p_application_id
119561    , p_ae_header_id           => l_ae_header_id 
119562 , p_source_1 => p_source_1
119563    )
119564 );
119565 
119566 
119567    --
119568    -- call ADRs
119569    -- Bug 4922099
119570    --
119571    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
119572         (NVL(l_actual_upg_option, 'N') = 'O') OR
119573         (NVL(l_enc_upg_option, 'N') = 'O')
119574       )
119575    THEN
119576    NULL;
119577    --
119578    --
119579    
119580   l_ccid := AcctDerRule_174(
119581            p_application_id           => p_application_id
119582          , p_ae_header_id             => l_ae_header_id 
119583 , p_source_3 => p_source_3
119584 , p_source_17 => p_source_17
119585 , p_source_30 => p_source_30
119586          , x_transaction_coa_id       => l_adr_transaction_coa_id
119587          , x_accounting_coa_id        => l_adr_accounting_coa_id
119588          , x_value_type_code          => l_adr_value_type_code
119589          , p_side                     => 'NA'
119590    );
119591 
119592    xla_ae_lines_pkg.set_ccid(
119593     p_code_combination_id          => l_ccid
119594   , p_value_type_code              => l_adr_value_type_code
119595   , p_transaction_coa_id           => l_adr_transaction_coa_id
119596   , p_accounting_coa_id            => l_adr_accounting_coa_id
119597   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
119598   , p_adr_type_code                => 'S'
119599   , p_component_type               => l_component_type
119600   , p_component_code               => l_component_code
119601   , p_component_type_code          => l_component_type_code
119602   , p_component_appl_id            => l_component_appl_id
119603   , p_amb_context_code             => l_amb_context_code
119604   , p_side                         => 'NA'
119605   );
119606 
119607 
119608    l_segment := AcctDerRule_149(
119609            p_application_id           => p_application_id
119610          , p_ae_header_id             => l_ae_header_id 
119611 , p_source_3 => p_source_3
119612 , p_source_10 => p_source_10
119613          , x_transaction_coa_id       => l_adr_transaction_coa_id
119614          , x_accounting_coa_id        => l_adr_accounting_coa_id
119615          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
119616          , x_flex_value_set_id        => l_adr_flex_value_set_id
119617          , x_value_type_code          => l_adr_value_type_code
119618          , x_value_combination_id     => l_adr_value_combination_id
119619          , x_value_segment_code       => l_adr_value_segment_code
119620          , p_side                     => 'NA'
119621          , p_override_seg_flag        => 'Y'
119622    );
119623 
119624    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
119625 
119626       xla_ae_lines_pkg.set_segment(
119627           p_to_segment_code         => 'GL_ACCOUNT'
119628         , p_segment_value           => l_segment
119629         , p_from_segment_code       => l_adr_value_segment_code
119630         , p_from_combination_id     => l_adr_value_combination_id
119631         , p_value_type_code         => l_adr_value_type_code
119632         , p_transaction_coa_id      => l_adr_transaction_coa_id
119633         , p_accounting_coa_id       => l_adr_accounting_coa_id
119634         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
119635         , p_flex_value_set_id       => l_adr_flex_value_set_id
119636         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
119637         , p_adr_type_code           => 'S'
119638         , p_component_type          => l_component_type
119639         , p_component_code          => l_component_code
119640         , p_component_type_code     => l_component_type_code
119641         , p_component_appl_id       => l_component_appl_id
119642         , p_amb_context_code        => l_amb_context_code
119646         );
119643         , p_entity_code             => 'TRANSACTIONS'
119644         , p_event_class_code        => 'REVALUATION'
119645         , p_side                    => 'NA'
119647 
119648   END IF;
119649 
119650    l_segment := AcctDerRule_168(
119651            p_application_id           => p_application_id
119652          , p_ae_header_id             => l_ae_header_id 
119653 , p_source_3 => p_source_3
119654 , p_source_29 => p_source_29
119655          , x_transaction_coa_id       => l_adr_transaction_coa_id
119656          , x_accounting_coa_id        => l_adr_accounting_coa_id
119657          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
119658          , x_flex_value_set_id        => l_adr_flex_value_set_id
119659          , x_value_type_code          => l_adr_value_type_code
119660          , x_value_combination_id     => l_adr_value_combination_id
119661          , x_value_segment_code       => l_adr_value_segment_code
119662          , p_side                     => 'NA'
119663          , p_override_seg_flag        => 'Y'
119664    );
119665 
119666    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
119667 
119668       xla_ae_lines_pkg.set_segment(
119669           p_to_segment_code         => 'GL_BALANCING'
119670         , p_segment_value           => l_segment
119671         , p_from_segment_code       => l_adr_value_segment_code
119672         , p_from_combination_id     => l_adr_value_combination_id
119673         , p_value_type_code         => l_adr_value_type_code
119674         , p_transaction_coa_id      => l_adr_transaction_coa_id
119675         , p_accounting_coa_id       => l_adr_accounting_coa_id
119676         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
119677         , p_flex_value_set_id       => l_adr_flex_value_set_id
119678         , p_adr_code                => 'FA_EXPENSE_ACCT'
119679         , p_adr_type_code           => 'S'
119680         , p_component_type          => l_component_type
119681         , p_component_code          => l_component_code
119682         , p_component_type_code     => l_component_type_code
119683         , p_component_appl_id       => l_component_appl_id
119684         , p_amb_context_code        => l_amb_context_code
119685         , p_entity_code             => 'TRANSACTIONS'
119686         , p_event_class_code        => 'REVALUATION'
119687         , p_side                    => 'NA'
119688         );
119689 
119690   END IF;
119691 
119692    --
119693    --
119694    END IF;
119695    --
119696    -- Bug 4922099
119697    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
119698           (NVL(l_enc_upg_option, 'N') = 'O')
119699         ) AND
119700         (l_bflow_method_code = 'PRIOR_ENTRY')
119701       )
119702    THEN
119703       IF
119704       --
119705       1 = 2
119706       --
119707       THEN
119708       xla_accounting_err_pkg.build_message
119709                                     (p_appli_s_name            => 'XLA'
119710                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
119711                                     ,p_token_1                 => 'LINE_NUMBER'
119712                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
119713                                     ,p_token_2                 => 'LINE_TYPE_NAME'
119714                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
119715                                                                              l_component_type
119716                                                                             ,l_component_code
119717                                                                             ,l_component_type_code
119718                                                                             ,l_component_appl_id
119719                                                                             ,l_amb_context_code
119720                                                                             ,l_entity_code
119721                                                                             ,l_event_class_code
119722                                                                            )
119723                                     ,p_token_3                 => 'OWNER'
119724                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
119725                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
119726                                                                           ,p_lookup_code    => l_component_type_code
119727                                                                          )
119728                                     ,p_token_4                 => 'PRODUCT_NAME'
119729                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
119730                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
119731                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
119732                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
119733                                     ,p_ae_header_id            =>  NULL
119734                                        );
119735 
119736         IF (C_LEVEL_ERROR>= g_log_level) THEN
119737                  trace
119738                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
119739                       ,p_level    => C_LEVEL_ERROR
119740                       ,p_module   => l_log_module);
119741         END IF;
119742       END IF;
119743    END IF;
119744    --
119745    --
119746    ------------------------------------------------------------------------------------------------
119747    -- 4219869 Business Flow
119748    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
119749    -- Prior Entry.  Currently, the following code is always generated.
119753    ------------------------------------------------------------------------------------
119750    ------------------------------------------------------------------------------------------------
119751    XLA_AE_LINES_PKG.ValidateCurrentLine;
119752 
119754    -- 4219869 Business Flow
119755    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
119756    ------------------------------------------------------------------------------------
119757    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
119758 
119759    ----------------------------------------------------------------------------------
119760    -- 4219869 Business Flow
119761    -- Update journal entry status -- Need to generate this within IF <condition>
119762    ----------------------------------------------------------------------------------
119763    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
119764          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
119765          ,p_balance_type_code => l_balance_type_code
119766          );
119767 
119768    -------------------------------------------------------------------------------------------
119769    -- 4262811 - Generate the Accrual Reversal lines
119770    -------------------------------------------------------------------------------------------
119771    BEGIN
119772       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
119773                               (g_array_event(p_event_id).array_value_num('header_index'));
119774       IF l_acc_rev_flag IS NULL THEN
119775          l_acc_rev_flag := 'N';
119776       END IF;
119777    EXCEPTION
119778       WHEN OTHERS THEN
119779          l_acc_rev_flag := 'N';
119780    END;
119781    --
119782    IF (l_acc_rev_flag = 'Y') THEN
119783 
119784        -- 4645092  ------------------------------------------------------------------------------
119785        -- To allow MPA report to determine if it should generate report process
119786        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
119787        ------------------------------------------------------------------------------------------
119788 
119789        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
119790        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
119791    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
119792    -- call ADRs
119793    -- Bug 4922099
119794    --
119795    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
119796         (NVL(l_actual_upg_option, 'N') = 'O') OR
119797         (NVL(l_enc_upg_option, 'N') = 'O')
119798       )
119799    THEN
119800    NULL;
119801    --
119802    --
119803    
119804   l_ccid := AcctDerRule_174(
119805            p_application_id           => p_application_id
119806          , p_ae_header_id             => l_ae_header_id 
119807 , p_source_3 => p_source_3
119808 , p_source_17 => p_source_17
119809 , p_source_30 => p_source_30
119810          , x_transaction_coa_id       => l_adr_transaction_coa_id
119811          , x_accounting_coa_id        => l_adr_accounting_coa_id
119812          , x_value_type_code          => l_adr_value_type_code
119813          , p_side                     => 'NA'
119814    );
119815 
119816    xla_ae_lines_pkg.set_ccid(
119817     p_code_combination_id          => l_ccid
119818   , p_value_type_code              => l_adr_value_type_code
119819   , p_transaction_coa_id           => l_adr_transaction_coa_id
119820   , p_accounting_coa_id            => l_adr_accounting_coa_id
119821   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
119822   , p_adr_type_code                => 'S'
119823   , p_component_type               => l_component_type
119824   , p_component_code               => l_component_code
119825   , p_component_type_code          => l_component_type_code
119826   , p_component_appl_id            => l_component_appl_id
119827   , p_amb_context_code             => l_amb_context_code
119828   , p_side                         => 'NA'
119829   );
119830 
119831 
119832    l_segment := AcctDerRule_149(
119833            p_application_id           => p_application_id
119834          , p_ae_header_id             => l_ae_header_id 
119835 , p_source_3 => p_source_3
119836 , p_source_10 => p_source_10
119837          , x_transaction_coa_id       => l_adr_transaction_coa_id
119838          , x_accounting_coa_id        => l_adr_accounting_coa_id
119839          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
119840          , x_flex_value_set_id        => l_adr_flex_value_set_id
119841          , x_value_type_code          => l_adr_value_type_code
119842          , x_value_combination_id     => l_adr_value_combination_id
119843          , x_value_segment_code       => l_adr_value_segment_code
119844          , p_side                     => 'NA'
119845          , p_override_seg_flag        => 'Y'
119846    );
119847 
119848    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
119849 
119850       xla_ae_lines_pkg.set_segment(
119851           p_to_segment_code         => 'GL_ACCOUNT'
119852         , p_segment_value           => l_segment
119853         , p_from_segment_code       => l_adr_value_segment_code
119854         , p_from_combination_id     => l_adr_value_combination_id
119855         , p_value_type_code         => l_adr_value_type_code
119856         , p_transaction_coa_id      => l_adr_transaction_coa_id
119857         , p_accounting_coa_id       => l_adr_accounting_coa_id
119858         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
119859         , p_flex_value_set_id       => l_adr_flex_value_set_id
119860         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
119861         , p_adr_type_code           => 'S'
119862         , p_component_type          => l_component_type
119863         , p_component_code          => l_component_code
119864         , p_component_type_code     => l_component_type_code
119865         , p_component_appl_id       => l_component_appl_id
119866         , p_amb_context_code        => l_amb_context_code
119870         );
119867         , p_entity_code             => 'TRANSACTIONS'
119868         , p_event_class_code        => 'REVALUATION'
119869         , p_side                    => 'NA'
119871 
119872   END IF;
119873 
119874    l_segment := AcctDerRule_168(
119875            p_application_id           => p_application_id
119876          , p_ae_header_id             => l_ae_header_id 
119877 , p_source_3 => p_source_3
119878 , p_source_29 => p_source_29
119879          , x_transaction_coa_id       => l_adr_transaction_coa_id
119880          , x_accounting_coa_id        => l_adr_accounting_coa_id
119881          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
119882          , x_flex_value_set_id        => l_adr_flex_value_set_id
119883          , x_value_type_code          => l_adr_value_type_code
119884          , x_value_combination_id     => l_adr_value_combination_id
119885          , x_value_segment_code       => l_adr_value_segment_code
119886          , p_side                     => 'NA'
119887          , p_override_seg_flag        => 'Y'
119888    );
119889 
119890    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
119891 
119892       xla_ae_lines_pkg.set_segment(
119893           p_to_segment_code         => 'GL_BALANCING'
119894         , p_segment_value           => l_segment
119895         , p_from_segment_code       => l_adr_value_segment_code
119896         , p_from_combination_id     => l_adr_value_combination_id
119897         , p_value_type_code         => l_adr_value_type_code
119898         , p_transaction_coa_id      => l_adr_transaction_coa_id
119899         , p_accounting_coa_id       => l_adr_accounting_coa_id
119900         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
119901         , p_flex_value_set_id       => l_adr_flex_value_set_id
119902         , p_adr_code                => 'FA_EXPENSE_ACCT'
119903         , p_adr_type_code           => 'S'
119904         , p_component_type          => l_component_type
119905         , p_component_code          => l_component_code
119906         , p_component_type_code     => l_component_type_code
119907         , p_component_appl_id       => l_component_appl_id
119908         , p_amb_context_code        => l_amb_context_code
119909         , p_entity_code             => 'TRANSACTIONS'
119910         , p_event_class_code        => 'REVALUATION'
119911         , p_side                    => 'NA'
119912         );
119913 
119914   END IF;
119915 
119916    --
119917    --
119918    END IF;
119919 
119920        --
119921        -- Update the line information that should be overwritten
119922        --
119923        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
119924                                          p_header_num   => 1);
119925        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
119926 
119927        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
119928 
119929        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
119930           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
119931        END IF;
119932 
119933       --
119934       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
119935       --
119936       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
119937           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
119938       ELSE
119939           ---------------------------------------------------------------------------------------------------
119940           -- 4262811a Switch Sign
119941           ---------------------------------------------------------------------------------------------------
119942           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
119943           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
119944                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
119945           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
119946                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
119947           -- 5132302
119948           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
119949                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
119950 
119951       END IF;
119952 
119953       -- 4955764
119954       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
119955       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
119956 
119957 
119958       XLA_AE_LINES_PKG.ValidateCurrentLine;
119959       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
119960 
119961       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
119962                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
119963                ,p_balance_type_code => l_balance_type_code);
119964 
119965    END IF;
119966 
119967    -----------------------------------------------------------------------------------------
119968    -- 4262811 Multiperiod Accounting
119969    -----------------------------------------------------------------------------------------
119970      -- No MPA option is assigned.
119971 
119972 
119973 END IF;
119974 END IF;
119975 --
119976 
119977 --
119978 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
119979    trace
119980       (p_msg      => 'END of AcctLineType_321'
119981       ,p_level    => C_LEVEL_PROCEDURE
119982       ,p_module   => l_log_module);
119983 END IF;
119984 --
119985 EXCEPTION
119986   WHEN xla_exceptions_pkg.application_exception THEN
119987       RAISE;
119988   WHEN OTHERS THEN
119992 --
119989        xla_exceptions_pkg.raise_message
119990            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_321');
119991 END AcctLineType_321;
119993 
119994 ---------------------------------------
119995 --
119996 -- PRIVATE FUNCTION
119997 --         AcctLineType_322
119998 --
119999 ---------------------------------------
120000 PROCEDURE AcctLineType_322 (
120001   p_application_id        IN NUMBER
120002  ,p_event_id              IN NUMBER
120003  ,p_calculate_acctd_flag  IN VARCHAR2
120004  ,p_calculate_g_l_flag    IN VARCHAR2
120005  ,p_actual_flag           IN OUT VARCHAR2
120006  ,p_balance_type_code     OUT VARCHAR2
120007  ,p_gain_or_loss_ref      OUT VARCHAR2
120008  
120009 --Period Close Date
120010  , p_source_1            IN DATE
120011 --Generated Code Combination Identifier
120012  , p_source_3            IN NUMBER
120013 --Expense Account Code Combination Identifier
120014  , p_source_29            IN NUMBER
120015 --Adjustment Type
120016  , p_source_35            IN VARCHAR2
120017 --Transaction Header Identifier
120018  , p_source_36            IN NUMBER
120019 --Adjustment Line Identifier
120020  , p_source_37            IN NUMBER
120021 --Distribution Type Code
120022  , p_source_38            IN VARCHAR2
120023 --Entered Amount
120024  , p_source_39            IN NUMBER
120025 --Currency Code
120026  , p_source_40            IN VARCHAR2
120027 )
120028 IS
120029 
120030 l_component_type              VARCHAR2(80);
120031 l_component_code              VARCHAR2(30);
120032 l_component_type_code         VARCHAR2(1);
120033 l_component_appl_id           INTEGER;
120034 l_amb_context_code            VARCHAR2(30);
120035 l_entity_code                 VARCHAR2(30);
120036 l_event_class_code            VARCHAR2(30);
120037 l_ae_header_id                NUMBER;
120038 l_event_type_code             VARCHAR2(30);
120039 l_line_definition_code        VARCHAR2(30);
120040 l_line_definition_owner_code  VARCHAR2(1);
120041 --
120042 -- adr variables
120043 l_segment                     VARCHAR2(30);
120044 l_ccid                        NUMBER;
120045 l_adr_transaction_coa_id      NUMBER;
120046 l_adr_accounting_coa_id       NUMBER;
120047 l_adr_flexfield_segment_code  VARCHAR2(30);
120048 l_adr_flex_value_set_id       NUMBER;
120049 l_adr_value_type_code         VARCHAR2(30);
120050 l_adr_value_combination_id    NUMBER;
120051 l_adr_value_segment_code      VARCHAR2(30);
120052 
120053 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
120054 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
120055 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
120056 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
120057 
120058 -- 4262811 Variables ------------------------------------------------------------------------------------------
120059 l_entered_amt_idx             NUMBER;
120060 l_accted_amt_idx              NUMBER;
120061 l_acc_rev_flag                VARCHAR2(1);
120062 l_accrual_line_num            NUMBER;
120063 l_tmp_amt                     NUMBER;
120064 l_acc_rev_natural_side_code   VARCHAR2(1);
120065 
120066 l_num_entries                 NUMBER;
120067 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
120068 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
120069 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
120070 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
120071 l_recog_line_1                NUMBER;
120072 l_recog_line_2                NUMBER;
120073 
120074 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
120075 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
120076 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
120077 
120078 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
120079 
120080 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
120081 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
120082 
120083 ---------------------------------------------------------------------------------------------------------------
120084 
120085 
120086 --
120087 -- bulk performance
120088 --
120089 l_balance_type_code           VARCHAR2(1);
120090 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
120091 l_log_module                  VARCHAR2(240);
120092 
120093 --
120094 -- Upgrade strategy
120095 --
120096 l_actual_upg_option           VARCHAR2(1);
120097 l_enc_upg_option           VARCHAR2(1);
120098 
120099 --
120100 BEGIN
120101 --
120102 IF g_log_enabled THEN
120103       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_322';
120104 END IF;
120105 --
120106 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
120107 
120108       trace
120109          (p_msg      => 'BEGIN of AcctLineType_322'
120110          ,p_level    => C_LEVEL_PROCEDURE
120111          ,p_module   => l_log_module);
120112 
120113 END IF;
120114 --
120115 l_component_type             := 'AMB_JLT';
120116 l_component_code             := 'FA_REVAL_EXPENSE';
120117 l_component_type_code        := 'S';
120118 l_component_appl_id          :=  140;
120119 l_amb_context_code           := 'DEFAULT';
120120 l_entity_code                := 'TRANSACTIONS';
120121 l_event_class_code           := 'REVALUATION';
120122 l_event_type_code            := 'REVALUATION_ALL';
120123 l_line_definition_owner_code := 'S';
120124 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVAL21';
120125 --
120126 l_balance_type_code          := 'A';
120127 l_segment                     := NULL;
120128 l_ccid                        := NULL;
120129 l_adr_transaction_coa_id      := NULL;
120130 l_adr_accounting_coa_id       := NULL;
120131 l_adr_flexfield_segment_code  := NULL;
120135 l_adr_value_segment_code      := NULL;
120132 l_adr_flex_value_set_id       := NULL;
120133 l_adr_value_type_code         := NULL;
120134 l_adr_value_combination_id    := NULL;
120136 
120137 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
120138 l_bflow_class_code           := '';    -- 4219869 Business Flow
120139 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
120140 l_budgetary_control_flag     := 'N';
120141 
120142 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
120143 l_bflow_applied_to_amt       := NULL; -- 5132302
120144 l_entered_amt_idx            := NULL;          -- 4262811
120145 l_accted_amt_idx             := NULL;          -- 4262811
120146 l_acc_rev_flag               := NULL;          -- 4262811
120147 l_accrual_line_num           := NULL;          -- 4262811
120148 l_tmp_amt                    := NULL;          -- 4262811
120149 --
120150  
120151 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
120152     l_balance_type_code <> 'B' THEN
120153 IF NVL(p_source_35,'
120154 ') =  'EXPENSE'
120155  THEN 
120156 
120157    --
120158    XLA_AE_LINES_PKG.SetNewLine;
120159 
120160    p_balance_type_code          := l_balance_type_code;
120161    -- set the flag so later we will know whether the gain loss line needs to be created
120162    
120163    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
120164      p_actual_flag :='A';
120165    END IF;
120166 
120167    --
120168    -- bulk performance
120169    --
120170    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
120171                                       p_header_num   => 0); -- 4262811
120172    --
120173    -- set accounting line options
120174    --
120175    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
120176            p_natural_side_code          => 'D'
120177          , p_gain_or_loss_flag          => 'N'
120178          , p_gl_transfer_mode_code      => 'S'
120179          , p_acct_entry_type_code       => 'A'
120180          , p_switch_side_flag           => 'Y'
120181          , p_merge_duplicate_code       => 'N'
120182          );
120183    --
120184    l_acc_rev_natural_side_code := 'C';  -- 4262811
120185    -- 
120186    --
120187    -- set accounting line type info
120188    --
120189    xla_ae_lines_pkg.SetAcctLineType
120190       (p_component_type             => l_component_type
120191       ,p_event_type_code            => l_event_type_code
120192       ,p_line_definition_owner_code => l_line_definition_owner_code
120193       ,p_line_definition_code       => l_line_definition_code
120194       ,p_accounting_line_code       => l_component_code
120195       ,p_accounting_line_type_code  => l_component_type_code
120196       ,p_accounting_line_appl_id    => l_component_appl_id
120197       ,p_amb_context_code           => l_amb_context_code
120198       ,p_entity_code                => l_entity_code
120199       ,p_event_class_code           => l_event_class_code);
120200    --
120201    -- set accounting class
120202    --
120203    xla_ae_lines_pkg.SetAcctClass(
120204            p_accounting_class_code  => 'EXPENSE'
120205          , p_ae_header_id           => l_ae_header_id
120206          );
120207 
120208    --
120209    -- set rounding class
120210    --
120211    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
120212                       'EXPENSE';
120213 
120214    --
120215    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
120216    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
120217    --
120218    -- bulk performance
120219    --
120220    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
120221 
120222    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
120223       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
120224 
120225    -- 4955764
120226    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
120227       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
120228 
120229    -- 4458381 Public Sector Enh
120230    
120231    --
120232    -- set accounting attributes for the line type
120233    --
120234    l_entered_amt_idx := 4;
120235    l_accted_amt_idx  := 6;
120236    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
120237    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
120238    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
120239    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
120240    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
120241    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
120242    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
120243    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
120244    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
120245    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
120246    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
120247    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
120248    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
120249 
120250    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
120251    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
120252 
120253    ---------------------------------------------------------------------------------------------------------------
120254    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
120255    ---------------------------------------------------------------------------------------------------------------
120256    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
120257 
120261    IF xla_accounting_cache_pkg.GetValueChar
120258    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
120259    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
120260 
120262          (p_source_code         => 'LEDGER_CATEGORY_CODE'
120263          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
120264    AND l_bflow_method_code = 'PRIOR_ENTRY'
120265 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
120266    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
120267          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
120268        )
120269    THEN
120270          xla_ae_lines_pkg.BflowUpgEntry
120271            (p_business_method_code    => l_bflow_method_code
120272            ,p_business_class_code     => l_bflow_class_code
120273            ,p_balance_type            => l_balance_type_code);
120274    ELSE
120275       NULL;
120276 -- No business flow processing for business flow method of NONE.
120277    END IF;
120278 
120279    --
120280    -- call analytical criteria
120281    --
120282    
120283    --
120284    -- call description
120285    --
120286    
120287 xla_ae_lines_pkg.SetLineDescription(
120288    p_ae_header_id => l_ae_header_id
120289   ,p_description  => Description_95 (
120290      p_application_id         => p_application_id
120291    , p_ae_header_id           => l_ae_header_id 
120292 , p_source_1 => p_source_1
120293    )
120294 );
120295 
120296 
120297    --
120298    -- call ADRs
120299    -- Bug 4922099
120300    --
120301    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
120302         (NVL(l_actual_upg_option, 'N') = 'O') OR
120303         (NVL(l_enc_upg_option, 'N') = 'O')
120304       )
120305    THEN
120306    NULL;
120307    --
120308    --
120309    
120310   l_ccid := AcctDerRule_175(
120311            p_application_id           => p_application_id
120312          , p_ae_header_id             => l_ae_header_id 
120313 , p_source_3 => p_source_3
120314 , p_source_29 => p_source_29
120315          , x_transaction_coa_id       => l_adr_transaction_coa_id
120316          , x_accounting_coa_id        => l_adr_accounting_coa_id
120317          , x_value_type_code          => l_adr_value_type_code
120318          , p_side                     => 'NA'
120319    );
120320 
120321    xla_ae_lines_pkg.set_ccid(
120322     p_code_combination_id          => l_ccid
120323   , p_value_type_code              => l_adr_value_type_code
120324   , p_transaction_coa_id           => l_adr_transaction_coa_id
120325   , p_accounting_coa_id            => l_adr_accounting_coa_id
120326   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
120327   , p_adr_type_code                => 'S'
120328   , p_component_type               => l_component_type
120329   , p_component_code               => l_component_code
120330   , p_component_type_code          => l_component_type_code
120331   , p_component_appl_id            => l_component_appl_id
120332   , p_amb_context_code             => l_amb_context_code
120333   , p_side                         => 'NA'
120334   );
120335 
120336 
120337    --
120338    --
120339    END IF;
120340    --
120341    -- Bug 4922099
120342    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
120343           (NVL(l_enc_upg_option, 'N') = 'O')
120344         ) AND
120345         (l_bflow_method_code = 'PRIOR_ENTRY')
120346       )
120347    THEN
120348       IF
120349       --
120350       1 = 2
120351       --
120352       THEN
120353       xla_accounting_err_pkg.build_message
120354                                     (p_appli_s_name            => 'XLA'
120355                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
120356                                     ,p_token_1                 => 'LINE_NUMBER'
120357                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
120358                                     ,p_token_2                 => 'LINE_TYPE_NAME'
120359                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
120360                                                                              l_component_type
120361                                                                             ,l_component_code
120362                                                                             ,l_component_type_code
120363                                                                             ,l_component_appl_id
120364                                                                             ,l_amb_context_code
120365                                                                             ,l_entity_code
120366                                                                             ,l_event_class_code
120367                                                                            )
120368                                     ,p_token_3                 => 'OWNER'
120369                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
120370                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
120371                                                                           ,p_lookup_code    => l_component_type_code
120372                                                                          )
120373                                     ,p_token_4                 => 'PRODUCT_NAME'
120374                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
120375                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
120376                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
120377                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
120381         IF (C_LEVEL_ERROR>= g_log_level) THEN
120378                                     ,p_ae_header_id            =>  NULL
120379                                        );
120380 
120382                  trace
120383                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
120384                       ,p_level    => C_LEVEL_ERROR
120385                       ,p_module   => l_log_module);
120386         END IF;
120387       END IF;
120388    END IF;
120389    --
120390    --
120391    ------------------------------------------------------------------------------------------------
120392    -- 4219869 Business Flow
120393    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
120394    -- Prior Entry.  Currently, the following code is always generated.
120395    ------------------------------------------------------------------------------------------------
120396    XLA_AE_LINES_PKG.ValidateCurrentLine;
120397 
120398    ------------------------------------------------------------------------------------
120399    -- 4219869 Business Flow
120400    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
120401    ------------------------------------------------------------------------------------
120402    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
120403 
120404    ----------------------------------------------------------------------------------
120405    -- 4219869 Business Flow
120406    -- Update journal entry status -- Need to generate this within IF <condition>
120407    ----------------------------------------------------------------------------------
120408    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
120409          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
120410          ,p_balance_type_code => l_balance_type_code
120411          );
120412 
120413    -------------------------------------------------------------------------------------------
120414    -- 4262811 - Generate the Accrual Reversal lines
120415    -------------------------------------------------------------------------------------------
120416    BEGIN
120417       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
120418                               (g_array_event(p_event_id).array_value_num('header_index'));
120419       IF l_acc_rev_flag IS NULL THEN
120420          l_acc_rev_flag := 'N';
120421       END IF;
120422    EXCEPTION
120423       WHEN OTHERS THEN
120424          l_acc_rev_flag := 'N';
120425    END;
120426    --
120427    IF (l_acc_rev_flag = 'Y') THEN
120428 
120429        -- 4645092  ------------------------------------------------------------------------------
120430        -- To allow MPA report to determine if it should generate report process
120431        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
120432        ------------------------------------------------------------------------------------------
120433 
120434        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
120435        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
120436    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
120437    -- call ADRs
120438    -- Bug 4922099
120439    --
120440    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
120441         (NVL(l_actual_upg_option, 'N') = 'O') OR
120442         (NVL(l_enc_upg_option, 'N') = 'O')
120443       )
120444    THEN
120445    NULL;
120446    --
120447    --
120448    
120449   l_ccid := AcctDerRule_175(
120450            p_application_id           => p_application_id
120451          , p_ae_header_id             => l_ae_header_id 
120452 , p_source_3 => p_source_3
120453 , p_source_29 => p_source_29
120454          , x_transaction_coa_id       => l_adr_transaction_coa_id
120455          , x_accounting_coa_id        => l_adr_accounting_coa_id
120456          , x_value_type_code          => l_adr_value_type_code
120457          , p_side                     => 'NA'
120458    );
120459 
120460    xla_ae_lines_pkg.set_ccid(
120461     p_code_combination_id          => l_ccid
120462   , p_value_type_code              => l_adr_value_type_code
120463   , p_transaction_coa_id           => l_adr_transaction_coa_id
120464   , p_accounting_coa_id            => l_adr_accounting_coa_id
120465   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
120466   , p_adr_type_code                => 'S'
120467   , p_component_type               => l_component_type
120468   , p_component_code               => l_component_code
120469   , p_component_type_code          => l_component_type_code
120470   , p_component_appl_id            => l_component_appl_id
120471   , p_amb_context_code             => l_amb_context_code
120472   , p_side                         => 'NA'
120473   );
120474 
120475 
120476    --
120477    --
120478    END IF;
120479 
120480        --
120481        -- Update the line information that should be overwritten
120482        --
120483        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
120484                                          p_header_num   => 1);
120485        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
120486 
120487        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
120488 
120489        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
120490           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
120491        END IF;
120492 
120493       --
120494       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
120495       --
120496       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
120497           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
120498       ELSE
120499           ---------------------------------------------------------------------------------------------------
120503           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
120500           -- 4262811a Switch Sign
120501           ---------------------------------------------------------------------------------------------------
120502           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
120504                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
120505           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
120506                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
120507           -- 5132302
120508           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
120509                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
120510 
120511       END IF;
120512 
120513       -- 4955764
120514       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
120515       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
120516 
120517 
120518       XLA_AE_LINES_PKG.ValidateCurrentLine;
120519       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
120520 
120521       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
120522                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
120523                ,p_balance_type_code => l_balance_type_code);
120524 
120525    END IF;
120526 
120527    -----------------------------------------------------------------------------------------
120528    -- 4262811 Multiperiod Accounting
120529    -----------------------------------------------------------------------------------------
120530      -- No MPA option is assigned.
120531 
120532 
120533 END IF;
120534 END IF;
120535 --
120536 
120537 --
120538 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
120539    trace
120540       (p_msg      => 'END of AcctLineType_322'
120541       ,p_level    => C_LEVEL_PROCEDURE
120542       ,p_module   => l_log_module);
120543 END IF;
120544 --
120545 EXCEPTION
120546   WHEN xla_exceptions_pkg.application_exception THEN
120547       RAISE;
120548   WHEN OTHERS THEN
120549        xla_exceptions_pkg.raise_message
120550            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_322');
120551 END AcctLineType_322;
120552 --
120553 
120554 ---------------------------------------
120555 --
120556 -- PRIVATE FUNCTION
120557 --         AcctLineType_323
120558 --
120559 ---------------------------------------
120560 PROCEDURE AcctLineType_323 (
120561   p_application_id        IN NUMBER
120562  ,p_event_id              IN NUMBER
120563  ,p_calculate_acctd_flag  IN VARCHAR2
120564  ,p_calculate_g_l_flag    IN VARCHAR2
120565  ,p_actual_flag           IN OUT VARCHAR2
120566  ,p_balance_type_code     OUT VARCHAR2
120567  ,p_gain_or_loss_ref      OUT VARCHAR2
120568  
120569 --Period Close Date
120570  , p_source_1            IN DATE
120571 --Generated Code Combination Identifier
120572  , p_source_3            IN NUMBER
120573 --Expense Account Code Combination Identifier
120574  , p_source_29            IN NUMBER
120575 --Adjustment Type
120576  , p_source_35            IN VARCHAR2
120577 --Transaction Header Identifier
120578  , p_source_36            IN NUMBER
120579 --Adjustment Line Identifier
120580  , p_source_37            IN NUMBER
120581 --Distribution Type Code
120582  , p_source_38            IN VARCHAR2
120583 --Entered Amount
120584  , p_source_39            IN NUMBER
120585 --Currency Code
120586  , p_source_40            IN VARCHAR2
120587 )
120588 IS
120589 
120590 l_component_type              VARCHAR2(80);
120591 l_component_code              VARCHAR2(30);
120592 l_component_type_code         VARCHAR2(1);
120593 l_component_appl_id           INTEGER;
120594 l_amb_context_code            VARCHAR2(30);
120595 l_entity_code                 VARCHAR2(30);
120596 l_event_class_code            VARCHAR2(30);
120597 l_ae_header_id                NUMBER;
120598 l_event_type_code             VARCHAR2(30);
120599 l_line_definition_code        VARCHAR2(30);
120600 l_line_definition_owner_code  VARCHAR2(1);
120601 --
120602 -- adr variables
120603 l_segment                     VARCHAR2(30);
120604 l_ccid                        NUMBER;
120605 l_adr_transaction_coa_id      NUMBER;
120606 l_adr_accounting_coa_id       NUMBER;
120607 l_adr_flexfield_segment_code  VARCHAR2(30);
120608 l_adr_flex_value_set_id       NUMBER;
120609 l_adr_value_type_code         VARCHAR2(30);
120610 l_adr_value_combination_id    NUMBER;
120611 l_adr_value_segment_code      VARCHAR2(30);
120612 
120613 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
120614 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
120615 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
120616 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
120617 
120618 -- 4262811 Variables ------------------------------------------------------------------------------------------
120619 l_entered_amt_idx             NUMBER;
120620 l_accted_amt_idx              NUMBER;
120621 l_acc_rev_flag                VARCHAR2(1);
120622 l_accrual_line_num            NUMBER;
120623 l_tmp_amt                     NUMBER;
120624 l_acc_rev_natural_side_code   VARCHAR2(1);
120625 
120626 l_num_entries                 NUMBER;
120627 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
120628 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
120629 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
120630 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
120631 l_recog_line_1                NUMBER;
120632 l_recog_line_2                NUMBER;
120633 
120637 
120634 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
120635 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
120636 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
120638 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
120639 
120640 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
120641 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
120642 
120643 ---------------------------------------------------------------------------------------------------------------
120644 
120645 
120646 --
120647 -- bulk performance
120648 --
120649 l_balance_type_code           VARCHAR2(1);
120650 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
120651 l_log_module                  VARCHAR2(240);
120652 
120653 --
120654 -- Upgrade strategy
120655 --
120656 l_actual_upg_option           VARCHAR2(1);
120657 l_enc_upg_option           VARCHAR2(1);
120658 
120659 --
120660 BEGIN
120661 --
120662 IF g_log_enabled THEN
120663       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_323';
120664 END IF;
120665 --
120666 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
120667 
120668       trace
120669          (p_msg      => 'BEGIN of AcctLineType_323'
120670          ,p_level    => C_LEVEL_PROCEDURE
120671          ,p_module   => l_log_module);
120672 
120673 END IF;
120674 --
120675 l_component_type             := 'AMB_JLT';
120676 l_component_code             := 'FA_REVAL_EXP_BAL';
120677 l_component_type_code        := 'S';
120678 l_component_appl_id          :=  140;
120679 l_amb_context_code           := 'DEFAULT';
120680 l_entity_code                := 'TRANSACTIONS';
120681 l_event_class_code           := 'REVALUATION';
120682 l_event_type_code            := 'REVALUATION_ALL';
120683 l_line_definition_owner_code := 'S';
120684 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVAL21';
120685 --
120686 l_balance_type_code          := 'A';
120687 l_segment                     := NULL;
120688 l_ccid                        := NULL;
120689 l_adr_transaction_coa_id      := NULL;
120690 l_adr_accounting_coa_id       := NULL;
120691 l_adr_flexfield_segment_code  := NULL;
120692 l_adr_flex_value_set_id       := NULL;
120693 l_adr_value_type_code         := NULL;
120694 l_adr_value_combination_id    := NULL;
120695 l_adr_value_segment_code      := NULL;
120696 
120697 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
120698 l_bflow_class_code           := '';    -- 4219869 Business Flow
120699 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
120700 l_budgetary_control_flag     := 'N';
120701 
120702 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
120703 l_bflow_applied_to_amt       := NULL; -- 5132302
120704 l_entered_amt_idx            := NULL;          -- 4262811
120705 l_accted_amt_idx             := NULL;          -- 4262811
120706 l_acc_rev_flag               := NULL;          -- 4262811
120707 l_accrual_line_num           := NULL;          -- 4262811
120708 l_tmp_amt                    := NULL;          -- 4262811
120709 --
120710  
120711 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
120712     l_balance_type_code <> 'B' THEN
120713 IF NVL(p_source_35,'
120714 ') =  'BONUS EXPENSE'
120715  THEN 
120716 
120717    --
120718    XLA_AE_LINES_PKG.SetNewLine;
120719 
120720    p_balance_type_code          := l_balance_type_code;
120721    -- set the flag so later we will know whether the gain loss line needs to be created
120722    
120723    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
120724      p_actual_flag :='A';
120725    END IF;
120726 
120727    --
120728    -- bulk performance
120729    --
120730    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
120731                                       p_header_num   => 0); -- 4262811
120732    --
120733    -- set accounting line options
120734    --
120735    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
120736            p_natural_side_code          => 'C'
120737          , p_gain_or_loss_flag          => 'N'
120738          , p_gl_transfer_mode_code      => 'S'
120739          , p_acct_entry_type_code       => 'A'
120740          , p_switch_side_flag           => 'Y'
120741          , p_merge_duplicate_code       => 'N'
120742          );
120743    --
120744    l_acc_rev_natural_side_code := 'D';  -- 4262811
120745    -- 
120746    --
120747    -- set accounting line type info
120748    --
120749    xla_ae_lines_pkg.SetAcctLineType
120750       (p_component_type             => l_component_type
120751       ,p_event_type_code            => l_event_type_code
120752       ,p_line_definition_owner_code => l_line_definition_owner_code
120753       ,p_line_definition_code       => l_line_definition_code
120754       ,p_accounting_line_code       => l_component_code
120755       ,p_accounting_line_type_code  => l_component_type_code
120756       ,p_accounting_line_appl_id    => l_component_appl_id
120757       ,p_amb_context_code           => l_amb_context_code
120758       ,p_entity_code                => l_entity_code
120759       ,p_event_class_code           => l_event_class_code);
120760    --
120761    -- set accounting class
120762    --
120763    xla_ae_lines_pkg.SetAcctClass(
120764            p_accounting_class_code  => 'EXPENSE'
120765          , p_ae_header_id           => l_ae_header_id
120766          );
120767 
120768    --
120769    -- set rounding class
120770    --
120771    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
120772                       'EXPENSE';
120773 
120774    --
120775    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
120779    --
120776    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
120777    --
120778    -- bulk performance
120780    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
120781 
120782    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
120783       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
120784 
120785    -- 4955764
120786    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
120787       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
120788 
120789    -- 4458381 Public Sector Enh
120790    
120791    --
120792    -- set accounting attributes for the line type
120793    --
120794    l_entered_amt_idx := 4;
120795    l_accted_amt_idx  := 6;
120796    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
120797    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
120798    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
120799    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
120800    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
120801    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
120802    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
120803    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
120804    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
120805    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
120806    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
120807    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
120808    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
120809 
120810    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
120811    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
120812 
120813    ---------------------------------------------------------------------------------------------------------------
120814    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
120815    ---------------------------------------------------------------------------------------------------------------
120816    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
120817 
120818    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
120819    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
120820 
120821    IF xla_accounting_cache_pkg.GetValueChar
120822          (p_source_code         => 'LEDGER_CATEGORY_CODE'
120823          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
120824    AND l_bflow_method_code = 'PRIOR_ENTRY'
120825 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
120826    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
120827          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
120828        )
120829    THEN
120830          xla_ae_lines_pkg.BflowUpgEntry
120831            (p_business_method_code    => l_bflow_method_code
120832            ,p_business_class_code     => l_bflow_class_code
120833            ,p_balance_type            => l_balance_type_code);
120834    ELSE
120835       NULL;
120836 -- No business flow processing for business flow method of NONE.
120837    END IF;
120838 
120839    --
120840    -- call analytical criteria
120841    --
120842    
120843    --
120844    -- call description
120845    --
120846    
120847 xla_ae_lines_pkg.SetLineDescription(
120848    p_ae_header_id => l_ae_header_id
120849   ,p_description  => Description_95 (
120850      p_application_id         => p_application_id
120851    , p_ae_header_id           => l_ae_header_id 
120852 , p_source_1 => p_source_1
120853    )
120854 );
120855 
120856 
120857    --
120858    -- call ADRs
120859    -- Bug 4922099
120860    --
120861    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
120862         (NVL(l_actual_upg_option, 'N') = 'O') OR
120863         (NVL(l_enc_upg_option, 'N') = 'O')
120864       )
120865    THEN
120866    NULL;
120867    --
120868    --
120869    
120870   l_ccid := AcctDerRule_175(
120871            p_application_id           => p_application_id
120872          , p_ae_header_id             => l_ae_header_id 
120873 , p_source_3 => p_source_3
120874 , p_source_29 => p_source_29
120875          , x_transaction_coa_id       => l_adr_transaction_coa_id
120876          , x_accounting_coa_id        => l_adr_accounting_coa_id
120877          , x_value_type_code          => l_adr_value_type_code
120878          , p_side                     => 'NA'
120879    );
120880 
120881    xla_ae_lines_pkg.set_ccid(
120882     p_code_combination_id          => l_ccid
120883   , p_value_type_code              => l_adr_value_type_code
120884   , p_transaction_coa_id           => l_adr_transaction_coa_id
120885   , p_accounting_coa_id            => l_adr_accounting_coa_id
120886   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
120887   , p_adr_type_code                => 'S'
120888   , p_component_type               => l_component_type
120889   , p_component_code               => l_component_code
120890   , p_component_type_code          => l_component_type_code
120891   , p_component_appl_id            => l_component_appl_id
120892   , p_amb_context_code             => l_amb_context_code
120893   , p_side                         => 'NA'
120894   );
120895 
120896 
120897    --
120898    --
120899    END IF;
120900    --
120901    -- Bug 4922099
120902    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
120903           (NVL(l_enc_upg_option, 'N') = 'O')
120904         ) AND
120905         (l_bflow_method_code = 'PRIOR_ENTRY')
120906       )
120907    THEN
120908       IF
120912       THEN
120909       --
120910       1 = 2
120911       --
120913       xla_accounting_err_pkg.build_message
120914                                     (p_appli_s_name            => 'XLA'
120915                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
120916                                     ,p_token_1                 => 'LINE_NUMBER'
120917                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
120918                                     ,p_token_2                 => 'LINE_TYPE_NAME'
120919                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
120920                                                                              l_component_type
120921                                                                             ,l_component_code
120922                                                                             ,l_component_type_code
120923                                                                             ,l_component_appl_id
120924                                                                             ,l_amb_context_code
120925                                                                             ,l_entity_code
120926                                                                             ,l_event_class_code
120927                                                                            )
120928                                     ,p_token_3                 => 'OWNER'
120929                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
120930                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
120931                                                                           ,p_lookup_code    => l_component_type_code
120932                                                                          )
120933                                     ,p_token_4                 => 'PRODUCT_NAME'
120934                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
120935                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
120936                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
120937                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
120938                                     ,p_ae_header_id            =>  NULL
120939                                        );
120940 
120941         IF (C_LEVEL_ERROR>= g_log_level) THEN
120942                  trace
120943                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
120944                       ,p_level    => C_LEVEL_ERROR
120945                       ,p_module   => l_log_module);
120946         END IF;
120947       END IF;
120948    END IF;
120949    --
120950    --
120951    ------------------------------------------------------------------------------------------------
120952    -- 4219869 Business Flow
120953    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
120954    -- Prior Entry.  Currently, the following code is always generated.
120955    ------------------------------------------------------------------------------------------------
120956    XLA_AE_LINES_PKG.ValidateCurrentLine;
120957 
120958    ------------------------------------------------------------------------------------
120959    -- 4219869 Business Flow
120960    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
120961    ------------------------------------------------------------------------------------
120962    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
120963 
120964    ----------------------------------------------------------------------------------
120965    -- 4219869 Business Flow
120966    -- Update journal entry status -- Need to generate this within IF <condition>
120967    ----------------------------------------------------------------------------------
120968    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
120969          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
120970          ,p_balance_type_code => l_balance_type_code
120971          );
120972 
120973    -------------------------------------------------------------------------------------------
120974    -- 4262811 - Generate the Accrual Reversal lines
120975    -------------------------------------------------------------------------------------------
120976    BEGIN
120977       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
120978                               (g_array_event(p_event_id).array_value_num('header_index'));
120979       IF l_acc_rev_flag IS NULL THEN
120980          l_acc_rev_flag := 'N';
120981       END IF;
120982    EXCEPTION
120983       WHEN OTHERS THEN
120984          l_acc_rev_flag := 'N';
120985    END;
120986    --
120987    IF (l_acc_rev_flag = 'Y') THEN
120988 
120989        -- 4645092  ------------------------------------------------------------------------------
120990        -- To allow MPA report to determine if it should generate report process
120991        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
120992        ------------------------------------------------------------------------------------------
120993 
120994        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
120995        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
120996    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
120997    -- call ADRs
120998    -- Bug 4922099
120999    --
121000    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
121001         (NVL(l_actual_upg_option, 'N') = 'O') OR
121002         (NVL(l_enc_upg_option, 'N') = 'O')
121003       )
121004    THEN
121005    NULL;
121006    --
121007    --
121008    
121009   l_ccid := AcctDerRule_175(
121010            p_application_id           => p_application_id
121011          , p_ae_header_id             => l_ae_header_id 
121015          , x_accounting_coa_id        => l_adr_accounting_coa_id
121012 , p_source_3 => p_source_3
121013 , p_source_29 => p_source_29
121014          , x_transaction_coa_id       => l_adr_transaction_coa_id
121016          , x_value_type_code          => l_adr_value_type_code
121017          , p_side                     => 'NA'
121018    );
121019 
121020    xla_ae_lines_pkg.set_ccid(
121021     p_code_combination_id          => l_ccid
121022   , p_value_type_code              => l_adr_value_type_code
121023   , p_transaction_coa_id           => l_adr_transaction_coa_id
121024   , p_accounting_coa_id            => l_adr_accounting_coa_id
121025   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
121026   , p_adr_type_code                => 'S'
121027   , p_component_type               => l_component_type
121028   , p_component_code               => l_component_code
121029   , p_component_type_code          => l_component_type_code
121030   , p_component_appl_id            => l_component_appl_id
121031   , p_amb_context_code             => l_amb_context_code
121032   , p_side                         => 'NA'
121033   );
121034 
121035 
121036    --
121037    --
121038    END IF;
121039 
121040        --
121041        -- Update the line information that should be overwritten
121042        --
121043        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
121044                                          p_header_num   => 1);
121045        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
121046 
121047        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
121048 
121049        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
121050           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
121051        END IF;
121052 
121053       --
121054       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
121055       --
121056       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
121057           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
121058       ELSE
121059           ---------------------------------------------------------------------------------------------------
121060           -- 4262811a Switch Sign
121061           ---------------------------------------------------------------------------------------------------
121062           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
121063           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
121064                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
121065           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
121066                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
121067           -- 5132302
121068           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
121069                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
121070 
121071       END IF;
121072 
121073       -- 4955764
121074       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
121075       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
121076 
121077 
121078       XLA_AE_LINES_PKG.ValidateCurrentLine;
121079       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
121080 
121081       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
121082                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
121083                ,p_balance_type_code => l_balance_type_code);
121084 
121085    END IF;
121086 
121087    -----------------------------------------------------------------------------------------
121088    -- 4262811 Multiperiod Accounting
121089    -----------------------------------------------------------------------------------------
121090      -- No MPA option is assigned.
121091 
121092 
121093 END IF;
121094 END IF;
121095 --
121096 
121097 --
121098 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
121099    trace
121100       (p_msg      => 'END of AcctLineType_323'
121101       ,p_level    => C_LEVEL_PROCEDURE
121102       ,p_module   => l_log_module);
121103 END IF;
121104 --
121105 EXCEPTION
121106   WHEN xla_exceptions_pkg.application_exception THEN
121107       RAISE;
121108   WHEN OTHERS THEN
121109        xla_exceptions_pkg.raise_message
121110            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_323');
121111 END AcctLineType_323;
121112 --
121113 
121114 ---------------------------------------
121115 --
121116 -- PRIVATE FUNCTION
121117 --         AcctLineType_324
121118 --
121119 ---------------------------------------
121120 PROCEDURE AcctLineType_324 (
121121   p_application_id        IN NUMBER
121122  ,p_event_id              IN NUMBER
121123  ,p_calculate_acctd_flag  IN VARCHAR2
121124  ,p_calculate_g_l_flag    IN VARCHAR2
121125  ,p_actual_flag           IN OUT VARCHAR2
121126  ,p_balance_type_code     OUT VARCHAR2
121127  ,p_gain_or_loss_ref      OUT VARCHAR2
121128  
121129 --Period Close Date
121130  , p_source_1            IN DATE
121131 --Generated Code Combination Identifier
121132  , p_source_3            IN NUMBER
121133 --Revaluation Reserve Account
121134  , p_source_11            IN VARCHAR2
121135 --Generated Offset Code Combination Identifier
121136  , p_source_17            IN NUMBER
121137 --Expense Account Code Combination Identifier
121138  , p_source_29            IN NUMBER
121139 --Default Code Combination Identifier
121140  , p_source_30            IN NUMBER
121141 --Adjustment Type
121145 --Adjustment Line Identifier
121142  , p_source_35            IN VARCHAR2
121143 --Transaction Header Identifier
121144  , p_source_36            IN NUMBER
121146  , p_source_37            IN NUMBER
121147 --Distribution Type Code
121148  , p_source_38            IN VARCHAR2
121149 --Entered Amount
121150  , p_source_39            IN NUMBER
121151 --Currency Code
121152  , p_source_40            IN VARCHAR2
121153 )
121154 IS
121155 
121156 l_component_type              VARCHAR2(80);
121157 l_component_code              VARCHAR2(30);
121158 l_component_type_code         VARCHAR2(1);
121159 l_component_appl_id           INTEGER;
121160 l_amb_context_code            VARCHAR2(30);
121161 l_entity_code                 VARCHAR2(30);
121162 l_event_class_code            VARCHAR2(30);
121163 l_ae_header_id                NUMBER;
121164 l_event_type_code             VARCHAR2(30);
121165 l_line_definition_code        VARCHAR2(30);
121166 l_line_definition_owner_code  VARCHAR2(1);
121167 --
121168 -- adr variables
121169 l_segment                     VARCHAR2(30);
121170 l_ccid                        NUMBER;
121171 l_adr_transaction_coa_id      NUMBER;
121172 l_adr_accounting_coa_id       NUMBER;
121173 l_adr_flexfield_segment_code  VARCHAR2(30);
121174 l_adr_flex_value_set_id       NUMBER;
121175 l_adr_value_type_code         VARCHAR2(30);
121176 l_adr_value_combination_id    NUMBER;
121177 l_adr_value_segment_code      VARCHAR2(30);
121178 
121179 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
121180 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
121181 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
121182 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
121183 
121184 -- 4262811 Variables ------------------------------------------------------------------------------------------
121185 l_entered_amt_idx             NUMBER;
121186 l_accted_amt_idx              NUMBER;
121187 l_acc_rev_flag                VARCHAR2(1);
121188 l_accrual_line_num            NUMBER;
121189 l_tmp_amt                     NUMBER;
121190 l_acc_rev_natural_side_code   VARCHAR2(1);
121191 
121192 l_num_entries                 NUMBER;
121193 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
121194 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
121195 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
121196 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
121197 l_recog_line_1                NUMBER;
121198 l_recog_line_2                NUMBER;
121199 
121200 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
121201 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
121202 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
121203 
121204 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
121205 
121206 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
121207 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
121208 
121209 ---------------------------------------------------------------------------------------------------------------
121210 
121211 
121212 --
121213 -- bulk performance
121214 --
121215 l_balance_type_code           VARCHAR2(1);
121216 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
121217 l_log_module                  VARCHAR2(240);
121218 
121219 --
121220 -- Upgrade strategy
121221 --
121222 l_actual_upg_option           VARCHAR2(1);
121223 l_enc_upg_option           VARCHAR2(1);
121224 
121225 --
121226 BEGIN
121227 --
121228 IF g_log_enabled THEN
121229       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_324';
121230 END IF;
121231 --
121232 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
121233 
121234       trace
121235          (p_msg      => 'BEGIN of AcctLineType_324'
121236          ,p_level    => C_LEVEL_PROCEDURE
121237          ,p_module   => l_log_module);
121238 
121239 END IF;
121240 --
121241 l_component_type             := 'AMB_JLT';
121242 l_component_code             := 'FA_REVAL_RESERVE';
121243 l_component_type_code        := 'S';
121244 l_component_appl_id          :=  140;
121245 l_amb_context_code           := 'DEFAULT';
121246 l_entity_code                := 'TRANSACTIONS';
121247 l_event_class_code           := 'REVALUATION';
121248 l_event_type_code            := 'REVALUATION_ALL';
121249 l_line_definition_owner_code := 'S';
121250 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVAL21';
121251 --
121252 l_balance_type_code          := 'A';
121253 l_segment                     := NULL;
121254 l_ccid                        := NULL;
121255 l_adr_transaction_coa_id      := NULL;
121256 l_adr_accounting_coa_id       := NULL;
121257 l_adr_flexfield_segment_code  := NULL;
121258 l_adr_flex_value_set_id       := NULL;
121259 l_adr_value_type_code         := NULL;
121260 l_adr_value_combination_id    := NULL;
121261 l_adr_value_segment_code      := NULL;
121262 
121263 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
121264 l_bflow_class_code           := '';    -- 4219869 Business Flow
121265 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
121266 l_budgetary_control_flag     := 'N';
121267 
121268 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
121269 l_bflow_applied_to_amt       := NULL; -- 5132302
121270 l_entered_amt_idx            := NULL;          -- 4262811
121271 l_accted_amt_idx             := NULL;          -- 4262811
121272 l_acc_rev_flag               := NULL;          -- 4262811
121273 l_accrual_line_num           := NULL;          -- 4262811
121274 l_tmp_amt                    := NULL;          -- 4262811
121275 --
121276  
121277 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
121278     l_balance_type_code <> 'B' THEN
121282 
121279 IF NVL(p_source_35,'
121280 ') =  'REVAL RESERVE'
121281  THEN 
121283    --
121284    XLA_AE_LINES_PKG.SetNewLine;
121285 
121286    p_balance_type_code          := l_balance_type_code;
121287    -- set the flag so later we will know whether the gain loss line needs to be created
121288    
121289    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
121290      p_actual_flag :='A';
121291    END IF;
121292 
121293    --
121294    -- bulk performance
121295    --
121296    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
121297                                       p_header_num   => 0); -- 4262811
121298    --
121299    -- set accounting line options
121300    --
121301    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
121302            p_natural_side_code          => 'C'
121303          , p_gain_or_loss_flag          => 'N'
121304          , p_gl_transfer_mode_code      => 'S'
121305          , p_acct_entry_type_code       => 'A'
121306          , p_switch_side_flag           => 'Y'
121307          , p_merge_duplicate_code       => 'N'
121308          );
121309    --
121310    l_acc_rev_natural_side_code := 'D';  -- 4262811
121311    -- 
121312    --
121313    -- set accounting line type info
121314    --
121315    xla_ae_lines_pkg.SetAcctLineType
121316       (p_component_type             => l_component_type
121317       ,p_event_type_code            => l_event_type_code
121318       ,p_line_definition_owner_code => l_line_definition_owner_code
121319       ,p_line_definition_code       => l_line_definition_code
121320       ,p_accounting_line_code       => l_component_code
121321       ,p_accounting_line_type_code  => l_component_type_code
121322       ,p_accounting_line_appl_id    => l_component_appl_id
121323       ,p_amb_context_code           => l_amb_context_code
121324       ,p_entity_code                => l_entity_code
121325       ,p_event_class_code           => l_event_class_code);
121326    --
121327    -- set accounting class
121328    --
121329    xla_ae_lines_pkg.SetAcctClass(
121330            p_accounting_class_code  => 'ASSET'
121331          , p_ae_header_id           => l_ae_header_id
121332          );
121333 
121334    --
121335    -- set rounding class
121336    --
121337    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
121338                       'ASSET';
121339 
121340    --
121341    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
121342    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
121343    --
121344    -- bulk performance
121345    --
121346    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
121347 
121348    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
121349       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
121350 
121351    -- 4955764
121352    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
121353       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
121354 
121355    -- 4458381 Public Sector Enh
121356    
121357    --
121358    -- set accounting attributes for the line type
121359    --
121360    l_entered_amt_idx := 4;
121361    l_accted_amt_idx  := 6;
121362    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
121363    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
121364    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
121365    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
121366    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
121367    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
121368    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
121369    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
121370    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
121371    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
121372    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
121373    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
121374    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
121375 
121376    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
121377    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
121378 
121379    ---------------------------------------------------------------------------------------------------------------
121380    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
121381    ---------------------------------------------------------------------------------------------------------------
121382    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
121383 
121384    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
121385    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
121386 
121387    IF xla_accounting_cache_pkg.GetValueChar
121388          (p_source_code         => 'LEDGER_CATEGORY_CODE'
121389          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
121390    AND l_bflow_method_code = 'PRIOR_ENTRY'
121391 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
121392    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
121393          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
121394        )
121395    THEN
121396          xla_ae_lines_pkg.BflowUpgEntry
121397            (p_business_method_code    => l_bflow_method_code
121398            ,p_business_class_code     => l_bflow_class_code
121399            ,p_balance_type            => l_balance_type_code);
121400    ELSE
121401       NULL;
121405    --
121402 -- No business flow processing for business flow method of NONE.
121403    END IF;
121404 
121406    -- call analytical criteria
121407    --
121408    
121409    --
121410    -- call description
121411    --
121412    
121413 xla_ae_lines_pkg.SetLineDescription(
121414    p_ae_header_id => l_ae_header_id
121415   ,p_description  => Description_96 (
121416      p_application_id         => p_application_id
121417    , p_ae_header_id           => l_ae_header_id 
121418 , p_source_1 => p_source_1
121419    )
121420 );
121421 
121422 
121423    --
121424    -- call ADRs
121425    -- Bug 4922099
121426    --
121427    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
121428         (NVL(l_actual_upg_option, 'N') = 'O') OR
121429         (NVL(l_enc_upg_option, 'N') = 'O')
121430       )
121431    THEN
121432    NULL;
121433    --
121434    --
121435    
121436   l_ccid := AcctDerRule_174(
121437            p_application_id           => p_application_id
121438          , p_ae_header_id             => l_ae_header_id 
121439 , p_source_3 => p_source_3
121440 , p_source_17 => p_source_17
121441 , p_source_30 => p_source_30
121442          , x_transaction_coa_id       => l_adr_transaction_coa_id
121443          , x_accounting_coa_id        => l_adr_accounting_coa_id
121444          , x_value_type_code          => l_adr_value_type_code
121445          , p_side                     => 'NA'
121446    );
121447 
121448    xla_ae_lines_pkg.set_ccid(
121449     p_code_combination_id          => l_ccid
121450   , p_value_type_code              => l_adr_value_type_code
121451   , p_transaction_coa_id           => l_adr_transaction_coa_id
121452   , p_accounting_coa_id            => l_adr_accounting_coa_id
121453   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
121454   , p_adr_type_code                => 'S'
121455   , p_component_type               => l_component_type
121456   , p_component_code               => l_component_code
121457   , p_component_type_code          => l_component_type_code
121458   , p_component_appl_id            => l_component_appl_id
121459   , p_amb_context_code             => l_amb_context_code
121460   , p_side                         => 'NA'
121461   );
121462 
121463 
121464    l_segment := AcctDerRule_150(
121465            p_application_id           => p_application_id
121466          , p_ae_header_id             => l_ae_header_id 
121467 , p_source_3 => p_source_3
121468 , p_source_11 => p_source_11
121469          , x_transaction_coa_id       => l_adr_transaction_coa_id
121470          , x_accounting_coa_id        => l_adr_accounting_coa_id
121471          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
121472          , x_flex_value_set_id        => l_adr_flex_value_set_id
121473          , x_value_type_code          => l_adr_value_type_code
121474          , x_value_combination_id     => l_adr_value_combination_id
121475          , x_value_segment_code       => l_adr_value_segment_code
121476          , p_side                     => 'NA'
121477          , p_override_seg_flag        => 'Y'
121478    );
121479 
121480    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
121481 
121482       xla_ae_lines_pkg.set_segment(
121483           p_to_segment_code         => 'GL_ACCOUNT'
121484         , p_segment_value           => l_segment
121485         , p_from_segment_code       => l_adr_value_segment_code
121486         , p_from_combination_id     => l_adr_value_combination_id
121487         , p_value_type_code         => l_adr_value_type_code
121488         , p_transaction_coa_id      => l_adr_transaction_coa_id
121489         , p_accounting_coa_id       => l_adr_accounting_coa_id
121490         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
121491         , p_flex_value_set_id       => l_adr_flex_value_set_id
121492         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
121493         , p_adr_type_code           => 'S'
121494         , p_component_type          => l_component_type
121495         , p_component_code          => l_component_code
121496         , p_component_type_code     => l_component_type_code
121497         , p_component_appl_id       => l_component_appl_id
121498         , p_amb_context_code        => l_amb_context_code
121499         , p_entity_code             => 'TRANSACTIONS'
121500         , p_event_class_code        => 'REVALUATION'
121501         , p_side                    => 'NA'
121502         );
121503 
121504   END IF;
121505 
121506    l_segment := AcctDerRule_168(
121507            p_application_id           => p_application_id
121508          , p_ae_header_id             => l_ae_header_id 
121509 , p_source_3 => p_source_3
121510 , p_source_29 => p_source_29
121511          , x_transaction_coa_id       => l_adr_transaction_coa_id
121512          , x_accounting_coa_id        => l_adr_accounting_coa_id
121513          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
121514          , x_flex_value_set_id        => l_adr_flex_value_set_id
121515          , x_value_type_code          => l_adr_value_type_code
121516          , x_value_combination_id     => l_adr_value_combination_id
121517          , x_value_segment_code       => l_adr_value_segment_code
121518          , p_side                     => 'NA'
121519          , p_override_seg_flag        => 'Y'
121520    );
121521 
121522    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
121523 
121524       xla_ae_lines_pkg.set_segment(
121525           p_to_segment_code         => 'GL_BALANCING'
121526         , p_segment_value           => l_segment
121527         , p_from_segment_code       => l_adr_value_segment_code
121528         , p_from_combination_id     => l_adr_value_combination_id
121529         , p_value_type_code         => l_adr_value_type_code
121530         , p_transaction_coa_id      => l_adr_transaction_coa_id
121531         , p_accounting_coa_id       => l_adr_accounting_coa_id
121532         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
121536         , p_component_type          => l_component_type
121533         , p_flex_value_set_id       => l_adr_flex_value_set_id
121534         , p_adr_code                => 'FA_EXPENSE_ACCT'
121535         , p_adr_type_code           => 'S'
121537         , p_component_code          => l_component_code
121538         , p_component_type_code     => l_component_type_code
121539         , p_component_appl_id       => l_component_appl_id
121540         , p_amb_context_code        => l_amb_context_code
121541         , p_entity_code             => 'TRANSACTIONS'
121542         , p_event_class_code        => 'REVALUATION'
121543         , p_side                    => 'NA'
121544         );
121545 
121546   END IF;
121547 
121548    --
121549    --
121550    END IF;
121551    --
121552    -- Bug 4922099
121553    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
121554           (NVL(l_enc_upg_option, 'N') = 'O')
121555         ) AND
121556         (l_bflow_method_code = 'PRIOR_ENTRY')
121557       )
121558    THEN
121559       IF
121560       --
121561       1 = 2
121562       --
121563       THEN
121564       xla_accounting_err_pkg.build_message
121565                                     (p_appli_s_name            => 'XLA'
121566                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
121567                                     ,p_token_1                 => 'LINE_NUMBER'
121568                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
121569                                     ,p_token_2                 => 'LINE_TYPE_NAME'
121570                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
121571                                                                              l_component_type
121572                                                                             ,l_component_code
121573                                                                             ,l_component_type_code
121574                                                                             ,l_component_appl_id
121575                                                                             ,l_amb_context_code
121576                                                                             ,l_entity_code
121577                                                                             ,l_event_class_code
121578                                                                            )
121579                                     ,p_token_3                 => 'OWNER'
121580                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
121581                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
121582                                                                           ,p_lookup_code    => l_component_type_code
121583                                                                          )
121584                                     ,p_token_4                 => 'PRODUCT_NAME'
121585                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
121586                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
121587                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
121588                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
121589                                     ,p_ae_header_id            =>  NULL
121590                                        );
121591 
121592         IF (C_LEVEL_ERROR>= g_log_level) THEN
121593                  trace
121594                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
121595                       ,p_level    => C_LEVEL_ERROR
121596                       ,p_module   => l_log_module);
121597         END IF;
121598       END IF;
121599    END IF;
121600    --
121601    --
121602    ------------------------------------------------------------------------------------------------
121603    -- 4219869 Business Flow
121604    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
121605    -- Prior Entry.  Currently, the following code is always generated.
121606    ------------------------------------------------------------------------------------------------
121607    XLA_AE_LINES_PKG.ValidateCurrentLine;
121608 
121609    ------------------------------------------------------------------------------------
121610    -- 4219869 Business Flow
121611    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
121612    ------------------------------------------------------------------------------------
121613    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
121614 
121615    ----------------------------------------------------------------------------------
121616    -- 4219869 Business Flow
121617    -- Update journal entry status -- Need to generate this within IF <condition>
121618    ----------------------------------------------------------------------------------
121619    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
121620          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
121621          ,p_balance_type_code => l_balance_type_code
121622          );
121623 
121624    -------------------------------------------------------------------------------------------
121625    -- 4262811 - Generate the Accrual Reversal lines
121626    -------------------------------------------------------------------------------------------
121627    BEGIN
121628       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
121629                               (g_array_event(p_event_id).array_value_num('header_index'));
121630       IF l_acc_rev_flag IS NULL THEN
121631          l_acc_rev_flag := 'N';
121632       END IF;
121633    EXCEPTION
121634       WHEN OTHERS THEN
121635          l_acc_rev_flag := 'N';
121636    END;
121637    --
121638    IF (l_acc_rev_flag = 'Y') THEN
121639 
121643        ------------------------------------------------------------------------------------------
121640        -- 4645092  ------------------------------------------------------------------------------
121641        -- To allow MPA report to determine if it should generate report process
121642        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
121644 
121645        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
121646        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
121647    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
121648    -- call ADRs
121649    -- Bug 4922099
121650    --
121651    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
121652         (NVL(l_actual_upg_option, 'N') = 'O') OR
121653         (NVL(l_enc_upg_option, 'N') = 'O')
121654       )
121655    THEN
121656    NULL;
121657    --
121658    --
121659    
121660   l_ccid := AcctDerRule_174(
121661            p_application_id           => p_application_id
121662          , p_ae_header_id             => l_ae_header_id 
121663 , p_source_3 => p_source_3
121664 , p_source_17 => p_source_17
121665 , p_source_30 => p_source_30
121666          , x_transaction_coa_id       => l_adr_transaction_coa_id
121667          , x_accounting_coa_id        => l_adr_accounting_coa_id
121668          , x_value_type_code          => l_adr_value_type_code
121669          , p_side                     => 'NA'
121670    );
121671 
121672    xla_ae_lines_pkg.set_ccid(
121673     p_code_combination_id          => l_ccid
121674   , p_value_type_code              => l_adr_value_type_code
121675   , p_transaction_coa_id           => l_adr_transaction_coa_id
121676   , p_accounting_coa_id            => l_adr_accounting_coa_id
121677   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
121678   , p_adr_type_code                => 'S'
121679   , p_component_type               => l_component_type
121680   , p_component_code               => l_component_code
121681   , p_component_type_code          => l_component_type_code
121682   , p_component_appl_id            => l_component_appl_id
121683   , p_amb_context_code             => l_amb_context_code
121684   , p_side                         => 'NA'
121685   );
121686 
121687 
121688    l_segment := AcctDerRule_150(
121689            p_application_id           => p_application_id
121690          , p_ae_header_id             => l_ae_header_id 
121691 , p_source_3 => p_source_3
121692 , p_source_11 => p_source_11
121693          , x_transaction_coa_id       => l_adr_transaction_coa_id
121694          , x_accounting_coa_id        => l_adr_accounting_coa_id
121695          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
121696          , x_flex_value_set_id        => l_adr_flex_value_set_id
121697          , x_value_type_code          => l_adr_value_type_code
121698          , x_value_combination_id     => l_adr_value_combination_id
121699          , x_value_segment_code       => l_adr_value_segment_code
121700          , p_side                     => 'NA'
121701          , p_override_seg_flag        => 'Y'
121702    );
121703 
121704    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
121705 
121706       xla_ae_lines_pkg.set_segment(
121707           p_to_segment_code         => 'GL_ACCOUNT'
121708         , p_segment_value           => l_segment
121709         , p_from_segment_code       => l_adr_value_segment_code
121710         , p_from_combination_id     => l_adr_value_combination_id
121711         , p_value_type_code         => l_adr_value_type_code
121712         , p_transaction_coa_id      => l_adr_transaction_coa_id
121713         , p_accounting_coa_id       => l_adr_accounting_coa_id
121714         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
121715         , p_flex_value_set_id       => l_adr_flex_value_set_id
121716         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
121717         , p_adr_type_code           => 'S'
121718         , p_component_type          => l_component_type
121719         , p_component_code          => l_component_code
121720         , p_component_type_code     => l_component_type_code
121721         , p_component_appl_id       => l_component_appl_id
121722         , p_amb_context_code        => l_amb_context_code
121723         , p_entity_code             => 'TRANSACTIONS'
121724         , p_event_class_code        => 'REVALUATION'
121725         , p_side                    => 'NA'
121726         );
121727 
121728   END IF;
121729 
121730    l_segment := AcctDerRule_168(
121731            p_application_id           => p_application_id
121732          , p_ae_header_id             => l_ae_header_id 
121733 , p_source_3 => p_source_3
121734 , p_source_29 => p_source_29
121735          , x_transaction_coa_id       => l_adr_transaction_coa_id
121736          , x_accounting_coa_id        => l_adr_accounting_coa_id
121737          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
121738          , x_flex_value_set_id        => l_adr_flex_value_set_id
121739          , x_value_type_code          => l_adr_value_type_code
121740          , x_value_combination_id     => l_adr_value_combination_id
121741          , x_value_segment_code       => l_adr_value_segment_code
121742          , p_side                     => 'NA'
121743          , p_override_seg_flag        => 'Y'
121744    );
121745 
121746    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
121747 
121748       xla_ae_lines_pkg.set_segment(
121749           p_to_segment_code         => 'GL_BALANCING'
121750         , p_segment_value           => l_segment
121751         , p_from_segment_code       => l_adr_value_segment_code
121752         , p_from_combination_id     => l_adr_value_combination_id
121753         , p_value_type_code         => l_adr_value_type_code
121754         , p_transaction_coa_id      => l_adr_transaction_coa_id
121755         , p_accounting_coa_id       => l_adr_accounting_coa_id
121756         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
121757         , p_flex_value_set_id       => l_adr_flex_value_set_id
121761         , p_component_code          => l_component_code
121758         , p_adr_code                => 'FA_EXPENSE_ACCT'
121759         , p_adr_type_code           => 'S'
121760         , p_component_type          => l_component_type
121762         , p_component_type_code     => l_component_type_code
121763         , p_component_appl_id       => l_component_appl_id
121764         , p_amb_context_code        => l_amb_context_code
121765         , p_entity_code             => 'TRANSACTIONS'
121766         , p_event_class_code        => 'REVALUATION'
121767         , p_side                    => 'NA'
121768         );
121769 
121770   END IF;
121771 
121772    --
121773    --
121774    END IF;
121775 
121776        --
121777        -- Update the line information that should be overwritten
121778        --
121779        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
121780                                          p_header_num   => 1);
121781        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
121782 
121783        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
121784 
121785        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
121786           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
121787        END IF;
121788 
121789       --
121790       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
121791       --
121792       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
121793           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
121794       ELSE
121795           ---------------------------------------------------------------------------------------------------
121796           -- 4262811a Switch Sign
121797           ---------------------------------------------------------------------------------------------------
121798           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
121799           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
121800                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
121801           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
121802                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
121803           -- 5132302
121804           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
121805                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
121806 
121807       END IF;
121808 
121809       -- 4955764
121810       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
121811       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
121812 
121813 
121814       XLA_AE_LINES_PKG.ValidateCurrentLine;
121815       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
121816 
121817       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
121818                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
121819                ,p_balance_type_code => l_balance_type_code);
121820 
121821    END IF;
121822 
121823    -----------------------------------------------------------------------------------------
121824    -- 4262811 Multiperiod Accounting
121825    -----------------------------------------------------------------------------------------
121826      -- No MPA option is assigned.
121827 
121828 
121829 END IF;
121830 END IF;
121831 --
121832 
121833 --
121834 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
121835    trace
121836       (p_msg      => 'END of AcctLineType_324'
121837       ,p_level    => C_LEVEL_PROCEDURE
121838       ,p_module   => l_log_module);
121839 END IF;
121840 --
121841 EXCEPTION
121842   WHEN xla_exceptions_pkg.application_exception THEN
121843       RAISE;
121844   WHEN OTHERS THEN
121845        xla_exceptions_pkg.raise_message
121846            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_324');
121847 END AcctLineType_324;
121848 --
121849 
121850 ---------------------------------------
121851 --
121852 -- PRIVATE FUNCTION
121853 --         AcctLineType_325
121854 --
121855 ---------------------------------------
121856 PROCEDURE AcctLineType_325 (
121857   p_application_id        IN NUMBER
121858  ,p_event_id              IN NUMBER
121859  ,p_calculate_acctd_flag  IN VARCHAR2
121860  ,p_calculate_g_l_flag    IN VARCHAR2
121861  ,p_actual_flag           IN OUT VARCHAR2
121862  ,p_balance_type_code     OUT VARCHAR2
121863  ,p_gain_or_loss_ref      OUT VARCHAR2
121864  
121865 --Period Close Date
121866  , p_source_1            IN DATE
121867 --Generated Code Combination Identifier
121868  , p_source_3            IN NUMBER
121869 --Depreciation Reserve Account
121870  , p_source_10            IN VARCHAR2
121871 --Generated Offset Code Combination Identifier
121872  , p_source_17            IN NUMBER
121873 --Expense Account Code Combination Identifier
121874  , p_source_29            IN NUMBER
121875 --Default Code Combination Identifier
121876  , p_source_30            IN NUMBER
121877 --Adjustment Type
121878  , p_source_35            IN VARCHAR2
121879 --Transaction Header Identifier
121880  , p_source_36            IN NUMBER
121881 --Adjustment Line Identifier
121882  , p_source_37            IN NUMBER
121883 --Distribution Type Code
121884  , p_source_38            IN VARCHAR2
121885 --Entered Amount
121886  , p_source_39            IN NUMBER
121887 --Currency Code
121888  , p_source_40            IN VARCHAR2
121889 )
121890 IS
121891 
121892 l_component_type              VARCHAR2(80);
121896 l_amb_context_code            VARCHAR2(30);
121893 l_component_code              VARCHAR2(30);
121894 l_component_type_code         VARCHAR2(1);
121895 l_component_appl_id           INTEGER;
121897 l_entity_code                 VARCHAR2(30);
121898 l_event_class_code            VARCHAR2(30);
121899 l_ae_header_id                NUMBER;
121900 l_event_type_code             VARCHAR2(30);
121901 l_line_definition_code        VARCHAR2(30);
121902 l_line_definition_owner_code  VARCHAR2(1);
121903 --
121904 -- adr variables
121905 l_segment                     VARCHAR2(30);
121906 l_ccid                        NUMBER;
121907 l_adr_transaction_coa_id      NUMBER;
121908 l_adr_accounting_coa_id       NUMBER;
121909 l_adr_flexfield_segment_code  VARCHAR2(30);
121910 l_adr_flex_value_set_id       NUMBER;
121911 l_adr_value_type_code         VARCHAR2(30);
121912 l_adr_value_combination_id    NUMBER;
121913 l_adr_value_segment_code      VARCHAR2(30);
121914 
121915 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
121916 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
121917 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
121918 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
121919 
121920 -- 4262811 Variables ------------------------------------------------------------------------------------------
121921 l_entered_amt_idx             NUMBER;
121922 l_accted_amt_idx              NUMBER;
121923 l_acc_rev_flag                VARCHAR2(1);
121924 l_accrual_line_num            NUMBER;
121925 l_tmp_amt                     NUMBER;
121926 l_acc_rev_natural_side_code   VARCHAR2(1);
121927 
121928 l_num_entries                 NUMBER;
121929 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
121930 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
121931 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
121932 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
121933 l_recog_line_1                NUMBER;
121934 l_recog_line_2                NUMBER;
121935 
121936 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
121937 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
121938 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
121939 
121940 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
121941 
121942 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
121943 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
121944 
121945 ---------------------------------------------------------------------------------------------------------------
121946 
121947 
121948 --
121949 -- bulk performance
121950 --
121951 l_balance_type_code           VARCHAR2(1);
121952 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
121953 l_log_module                  VARCHAR2(240);
121954 
121955 --
121956 -- Upgrade strategy
121957 --
121958 l_actual_upg_option           VARCHAR2(1);
121959 l_enc_upg_option           VARCHAR2(1);
121960 
121961 --
121962 BEGIN
121963 --
121964 IF g_log_enabled THEN
121965       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_325';
121966 END IF;
121967 --
121968 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
121969 
121970       trace
121971          (p_msg      => 'BEGIN of AcctLineType_325'
121972          ,p_level    => C_LEVEL_PROCEDURE
121973          ,p_module   => l_log_module);
121974 
121975 END IF;
121976 --
121977 l_component_type             := 'AMB_JLT';
121978 l_component_code             := 'FA_REVAL_RESERVE_BAL';
121979 l_component_type_code        := 'S';
121980 l_component_appl_id          :=  140;
121981 l_amb_context_code           := 'DEFAULT';
121982 l_entity_code                := 'TRANSACTIONS';
121983 l_event_class_code           := 'REVALUATION';
121984 l_event_type_code            := 'REVALUATION_ALL';
121985 l_line_definition_owner_code := 'S';
121986 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVAL21';
121987 --
121988 l_balance_type_code          := 'A';
121989 l_segment                     := NULL;
121990 l_ccid                        := NULL;
121991 l_adr_transaction_coa_id      := NULL;
121992 l_adr_accounting_coa_id       := NULL;
121993 l_adr_flexfield_segment_code  := NULL;
121994 l_adr_flex_value_set_id       := NULL;
121995 l_adr_value_type_code         := NULL;
121996 l_adr_value_combination_id    := NULL;
121997 l_adr_value_segment_code      := NULL;
121998 
121999 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
122000 l_bflow_class_code           := '';    -- 4219869 Business Flow
122001 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
122002 l_budgetary_control_flag     := 'N';
122003 
122004 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
122005 l_bflow_applied_to_amt       := NULL; -- 5132302
122006 l_entered_amt_idx            := NULL;          -- 4262811
122007 l_accted_amt_idx             := NULL;          -- 4262811
122008 l_acc_rev_flag               := NULL;          -- 4262811
122009 l_accrual_line_num           := NULL;          -- 4262811
122010 l_tmp_amt                    := NULL;          -- 4262811
122011 --
122012  
122013 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
122014     l_balance_type_code <> 'B' THEN
122015 IF NVL(p_source_35,'
122016 ') =  'BONUS RESERVE'
122017  THEN 
122018 
122019    --
122020    XLA_AE_LINES_PKG.SetNewLine;
122021 
122022    p_balance_type_code          := l_balance_type_code;
122023    -- set the flag so later we will know whether the gain loss line needs to be created
122024    
122025    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
122026      p_actual_flag :='A';
122027    END IF;
122028 
122029    --
122030    -- bulk performance
122034    --
122031    --
122032    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
122033                                       p_header_num   => 0); -- 4262811
122035    -- set accounting line options
122036    --
122037    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
122038            p_natural_side_code          => 'D'
122039          , p_gain_or_loss_flag          => 'N'
122040          , p_gl_transfer_mode_code      => 'S'
122041          , p_acct_entry_type_code       => 'A'
122042          , p_switch_side_flag           => 'Y'
122043          , p_merge_duplicate_code       => 'N'
122044          );
122045    --
122046    l_acc_rev_natural_side_code := 'C';  -- 4262811
122047    -- 
122048    --
122049    -- set accounting line type info
122050    --
122051    xla_ae_lines_pkg.SetAcctLineType
122052       (p_component_type             => l_component_type
122053       ,p_event_type_code            => l_event_type_code
122054       ,p_line_definition_owner_code => l_line_definition_owner_code
122055       ,p_line_definition_code       => l_line_definition_code
122056       ,p_accounting_line_code       => l_component_code
122057       ,p_accounting_line_type_code  => l_component_type_code
122058       ,p_accounting_line_appl_id    => l_component_appl_id
122059       ,p_amb_context_code           => l_amb_context_code
122060       ,p_entity_code                => l_entity_code
122061       ,p_event_class_code           => l_event_class_code);
122062    --
122063    -- set accounting class
122064    --
122065    xla_ae_lines_pkg.SetAcctClass(
122066            p_accounting_class_code  => 'ASSET'
122067          , p_ae_header_id           => l_ae_header_id
122068          );
122069 
122070    --
122071    -- set rounding class
122072    --
122073    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
122074                       'ASSET';
122075 
122076    --
122077    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
122078    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
122079    --
122080    -- bulk performance
122081    --
122082    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
122083 
122084    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
122085       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
122086 
122087    -- 4955764
122088    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
122089       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
122090 
122091    -- 4458381 Public Sector Enh
122092    
122093    --
122094    -- set accounting attributes for the line type
122095    --
122096    l_entered_amt_idx := 4;
122097    l_accted_amt_idx  := 6;
122098    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
122099    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
122100    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
122101    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
122102    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
122103    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
122104    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
122105    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
122106    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
122107    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
122108    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
122109    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
122110    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
122111 
122112    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
122113    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
122114 
122115    ---------------------------------------------------------------------------------------------------------------
122116    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
122117    ---------------------------------------------------------------------------------------------------------------
122118    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
122119 
122120    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
122121    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
122122 
122123    IF xla_accounting_cache_pkg.GetValueChar
122124          (p_source_code         => 'LEDGER_CATEGORY_CODE'
122125          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
122126    AND l_bflow_method_code = 'PRIOR_ENTRY'
122127 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
122128    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
122129          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
122130        )
122131    THEN
122132          xla_ae_lines_pkg.BflowUpgEntry
122133            (p_business_method_code    => l_bflow_method_code
122134            ,p_business_class_code     => l_bflow_class_code
122135            ,p_balance_type            => l_balance_type_code);
122136    ELSE
122137       NULL;
122138 -- No business flow processing for business flow method of NONE.
122139    END IF;
122140 
122141    --
122142    -- call analytical criteria
122143    --
122144    
122145    --
122146    -- call description
122147    --
122148    
122149 xla_ae_lines_pkg.SetLineDescription(
122150    p_ae_header_id => l_ae_header_id
122151   ,p_description  => Description_94 (
122152      p_application_id         => p_application_id
122153    , p_ae_header_id           => l_ae_header_id 
122154 , p_source_1 => p_source_1
122158 
122155    )
122156 );
122157 
122159    --
122160    -- call ADRs
122161    -- Bug 4922099
122162    --
122163    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
122164         (NVL(l_actual_upg_option, 'N') = 'O') OR
122165         (NVL(l_enc_upg_option, 'N') = 'O')
122166       )
122167    THEN
122168    NULL;
122169    --
122170    --
122171    
122172   l_ccid := AcctDerRule_174(
122173            p_application_id           => p_application_id
122174          , p_ae_header_id             => l_ae_header_id 
122175 , p_source_3 => p_source_3
122176 , p_source_17 => p_source_17
122177 , p_source_30 => p_source_30
122178          , x_transaction_coa_id       => l_adr_transaction_coa_id
122179          , x_accounting_coa_id        => l_adr_accounting_coa_id
122180          , x_value_type_code          => l_adr_value_type_code
122181          , p_side                     => 'NA'
122182    );
122183 
122184    xla_ae_lines_pkg.set_ccid(
122185     p_code_combination_id          => l_ccid
122186   , p_value_type_code              => l_adr_value_type_code
122187   , p_transaction_coa_id           => l_adr_transaction_coa_id
122188   , p_accounting_coa_id            => l_adr_accounting_coa_id
122189   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
122190   , p_adr_type_code                => 'S'
122191   , p_component_type               => l_component_type
122192   , p_component_code               => l_component_code
122193   , p_component_type_code          => l_component_type_code
122194   , p_component_appl_id            => l_component_appl_id
122195   , p_amb_context_code             => l_amb_context_code
122196   , p_side                         => 'NA'
122197   );
122198 
122199 
122200    l_segment := AcctDerRule_149(
122201            p_application_id           => p_application_id
122202          , p_ae_header_id             => l_ae_header_id 
122203 , p_source_3 => p_source_3
122204 , p_source_10 => p_source_10
122205          , x_transaction_coa_id       => l_adr_transaction_coa_id
122206          , x_accounting_coa_id        => l_adr_accounting_coa_id
122207          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
122208          , x_flex_value_set_id        => l_adr_flex_value_set_id
122209          , x_value_type_code          => l_adr_value_type_code
122210          , x_value_combination_id     => l_adr_value_combination_id
122211          , x_value_segment_code       => l_adr_value_segment_code
122212          , p_side                     => 'NA'
122213          , p_override_seg_flag        => 'Y'
122214    );
122215 
122216    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
122217 
122218       xla_ae_lines_pkg.set_segment(
122219           p_to_segment_code         => 'GL_ACCOUNT'
122220         , p_segment_value           => l_segment
122221         , p_from_segment_code       => l_adr_value_segment_code
122222         , p_from_combination_id     => l_adr_value_combination_id
122223         , p_value_type_code         => l_adr_value_type_code
122224         , p_transaction_coa_id      => l_adr_transaction_coa_id
122225         , p_accounting_coa_id       => l_adr_accounting_coa_id
122226         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
122227         , p_flex_value_set_id       => l_adr_flex_value_set_id
122228         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
122229         , p_adr_type_code           => 'S'
122230         , p_component_type          => l_component_type
122231         , p_component_code          => l_component_code
122232         , p_component_type_code     => l_component_type_code
122233         , p_component_appl_id       => l_component_appl_id
122234         , p_amb_context_code        => l_amb_context_code
122235         , p_entity_code             => 'TRANSACTIONS'
122236         , p_event_class_code        => 'REVALUATION'
122237         , p_side                    => 'NA'
122238         );
122239 
122240   END IF;
122241 
122242    l_segment := AcctDerRule_168(
122243            p_application_id           => p_application_id
122244          , p_ae_header_id             => l_ae_header_id 
122245 , p_source_3 => p_source_3
122246 , p_source_29 => p_source_29
122247          , x_transaction_coa_id       => l_adr_transaction_coa_id
122248          , x_accounting_coa_id        => l_adr_accounting_coa_id
122249          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
122250          , x_flex_value_set_id        => l_adr_flex_value_set_id
122251          , x_value_type_code          => l_adr_value_type_code
122252          , x_value_combination_id     => l_adr_value_combination_id
122253          , x_value_segment_code       => l_adr_value_segment_code
122254          , p_side                     => 'NA'
122255          , p_override_seg_flag        => 'Y'
122256    );
122257 
122258    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
122259 
122260       xla_ae_lines_pkg.set_segment(
122261           p_to_segment_code         => 'GL_BALANCING'
122262         , p_segment_value           => l_segment
122263         , p_from_segment_code       => l_adr_value_segment_code
122264         , p_from_combination_id     => l_adr_value_combination_id
122265         , p_value_type_code         => l_adr_value_type_code
122266         , p_transaction_coa_id      => l_adr_transaction_coa_id
122267         , p_accounting_coa_id       => l_adr_accounting_coa_id
122268         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
122269         , p_flex_value_set_id       => l_adr_flex_value_set_id
122270         , p_adr_code                => 'FA_EXPENSE_ACCT'
122271         , p_adr_type_code           => 'S'
122272         , p_component_type          => l_component_type
122273         , p_component_code          => l_component_code
122274         , p_component_type_code     => l_component_type_code
122275         , p_component_appl_id       => l_component_appl_id
122276         , p_amb_context_code        => l_amb_context_code
122277         , p_entity_code             => 'TRANSACTIONS'
122281 
122278         , p_event_class_code        => 'REVALUATION'
122279         , p_side                    => 'NA'
122280         );
122282   END IF;
122283 
122284    --
122285    --
122286    END IF;
122287    --
122288    -- Bug 4922099
122289    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
122290           (NVL(l_enc_upg_option, 'N') = 'O')
122291         ) AND
122292         (l_bflow_method_code = 'PRIOR_ENTRY')
122293       )
122294    THEN
122295       IF
122296       --
122297       1 = 2
122298       --
122299       THEN
122300       xla_accounting_err_pkg.build_message
122301                                     (p_appli_s_name            => 'XLA'
122302                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
122303                                     ,p_token_1                 => 'LINE_NUMBER'
122304                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
122305                                     ,p_token_2                 => 'LINE_TYPE_NAME'
122306                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
122307                                                                              l_component_type
122308                                                                             ,l_component_code
122309                                                                             ,l_component_type_code
122310                                                                             ,l_component_appl_id
122311                                                                             ,l_amb_context_code
122312                                                                             ,l_entity_code
122313                                                                             ,l_event_class_code
122314                                                                            )
122315                                     ,p_token_3                 => 'OWNER'
122316                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
122317                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
122318                                                                           ,p_lookup_code    => l_component_type_code
122319                                                                          )
122320                                     ,p_token_4                 => 'PRODUCT_NAME'
122321                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
122322                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
122323                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
122324                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
122325                                     ,p_ae_header_id            =>  NULL
122326                                        );
122327 
122328         IF (C_LEVEL_ERROR>= g_log_level) THEN
122329                  trace
122330                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
122331                       ,p_level    => C_LEVEL_ERROR
122332                       ,p_module   => l_log_module);
122333         END IF;
122334       END IF;
122335    END IF;
122336    --
122337    --
122338    ------------------------------------------------------------------------------------------------
122339    -- 4219869 Business Flow
122340    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
122341    -- Prior Entry.  Currently, the following code is always generated.
122342    ------------------------------------------------------------------------------------------------
122343    XLA_AE_LINES_PKG.ValidateCurrentLine;
122344 
122345    ------------------------------------------------------------------------------------
122346    -- 4219869 Business Flow
122347    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
122348    ------------------------------------------------------------------------------------
122349    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
122350 
122351    ----------------------------------------------------------------------------------
122352    -- 4219869 Business Flow
122353    -- Update journal entry status -- Need to generate this within IF <condition>
122354    ----------------------------------------------------------------------------------
122355    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
122356          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
122357          ,p_balance_type_code => l_balance_type_code
122358          );
122359 
122360    -------------------------------------------------------------------------------------------
122361    -- 4262811 - Generate the Accrual Reversal lines
122362    -------------------------------------------------------------------------------------------
122363    BEGIN
122364       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
122365                               (g_array_event(p_event_id).array_value_num('header_index'));
122366       IF l_acc_rev_flag IS NULL THEN
122367          l_acc_rev_flag := 'N';
122368       END IF;
122369    EXCEPTION
122370       WHEN OTHERS THEN
122371          l_acc_rev_flag := 'N';
122372    END;
122373    --
122374    IF (l_acc_rev_flag = 'Y') THEN
122375 
122376        -- 4645092  ------------------------------------------------------------------------------
122377        -- To allow MPA report to determine if it should generate report process
122378        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
122379        ------------------------------------------------------------------------------------------
122380 
122381        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
122382        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
122383    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
122387    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
122384    -- call ADRs
122385    -- Bug 4922099
122386    --
122388         (NVL(l_actual_upg_option, 'N') = 'O') OR
122389         (NVL(l_enc_upg_option, 'N') = 'O')
122390       )
122391    THEN
122392    NULL;
122393    --
122394    --
122395    
122396   l_ccid := AcctDerRule_174(
122397            p_application_id           => p_application_id
122398          , p_ae_header_id             => l_ae_header_id 
122399 , p_source_3 => p_source_3
122400 , p_source_17 => p_source_17
122401 , p_source_30 => p_source_30
122402          , x_transaction_coa_id       => l_adr_transaction_coa_id
122403          , x_accounting_coa_id        => l_adr_accounting_coa_id
122404          , x_value_type_code          => l_adr_value_type_code
122405          , p_side                     => 'NA'
122406    );
122407 
122408    xla_ae_lines_pkg.set_ccid(
122409     p_code_combination_id          => l_ccid
122410   , p_value_type_code              => l_adr_value_type_code
122411   , p_transaction_coa_id           => l_adr_transaction_coa_id
122412   , p_accounting_coa_id            => l_adr_accounting_coa_id
122413   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
122414   , p_adr_type_code                => 'S'
122415   , p_component_type               => l_component_type
122416   , p_component_code               => l_component_code
122417   , p_component_type_code          => l_component_type_code
122418   , p_component_appl_id            => l_component_appl_id
122419   , p_amb_context_code             => l_amb_context_code
122420   , p_side                         => 'NA'
122421   );
122422 
122423 
122424    l_segment := AcctDerRule_149(
122425            p_application_id           => p_application_id
122426          , p_ae_header_id             => l_ae_header_id 
122427 , p_source_3 => p_source_3
122428 , p_source_10 => p_source_10
122429          , x_transaction_coa_id       => l_adr_transaction_coa_id
122430          , x_accounting_coa_id        => l_adr_accounting_coa_id
122431          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
122432          , x_flex_value_set_id        => l_adr_flex_value_set_id
122433          , x_value_type_code          => l_adr_value_type_code
122434          , x_value_combination_id     => l_adr_value_combination_id
122435          , x_value_segment_code       => l_adr_value_segment_code
122436          , p_side                     => 'NA'
122437          , p_override_seg_flag        => 'Y'
122438    );
122439 
122440    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
122441 
122442       xla_ae_lines_pkg.set_segment(
122443           p_to_segment_code         => 'GL_ACCOUNT'
122444         , p_segment_value           => l_segment
122445         , p_from_segment_code       => l_adr_value_segment_code
122446         , p_from_combination_id     => l_adr_value_combination_id
122447         , p_value_type_code         => l_adr_value_type_code
122448         , p_transaction_coa_id      => l_adr_transaction_coa_id
122449         , p_accounting_coa_id       => l_adr_accounting_coa_id
122450         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
122451         , p_flex_value_set_id       => l_adr_flex_value_set_id
122452         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
122453         , p_adr_type_code           => 'S'
122454         , p_component_type          => l_component_type
122455         , p_component_code          => l_component_code
122456         , p_component_type_code     => l_component_type_code
122457         , p_component_appl_id       => l_component_appl_id
122458         , p_amb_context_code        => l_amb_context_code
122459         , p_entity_code             => 'TRANSACTIONS'
122460         , p_event_class_code        => 'REVALUATION'
122461         , p_side                    => 'NA'
122462         );
122463 
122464   END IF;
122465 
122466    l_segment := AcctDerRule_168(
122467            p_application_id           => p_application_id
122468          , p_ae_header_id             => l_ae_header_id 
122469 , p_source_3 => p_source_3
122470 , p_source_29 => p_source_29
122471          , x_transaction_coa_id       => l_adr_transaction_coa_id
122472          , x_accounting_coa_id        => l_adr_accounting_coa_id
122473          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
122474          , x_flex_value_set_id        => l_adr_flex_value_set_id
122475          , x_value_type_code          => l_adr_value_type_code
122476          , x_value_combination_id     => l_adr_value_combination_id
122477          , x_value_segment_code       => l_adr_value_segment_code
122478          , p_side                     => 'NA'
122479          , p_override_seg_flag        => 'Y'
122480    );
122481 
122482    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
122483 
122484       xla_ae_lines_pkg.set_segment(
122485           p_to_segment_code         => 'GL_BALANCING'
122486         , p_segment_value           => l_segment
122487         , p_from_segment_code       => l_adr_value_segment_code
122488         , p_from_combination_id     => l_adr_value_combination_id
122489         , p_value_type_code         => l_adr_value_type_code
122490         , p_transaction_coa_id      => l_adr_transaction_coa_id
122491         , p_accounting_coa_id       => l_adr_accounting_coa_id
122492         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
122493         , p_flex_value_set_id       => l_adr_flex_value_set_id
122494         , p_adr_code                => 'FA_EXPENSE_ACCT'
122495         , p_adr_type_code           => 'S'
122496         , p_component_type          => l_component_type
122497         , p_component_code          => l_component_code
122498         , p_component_type_code     => l_component_type_code
122499         , p_component_appl_id       => l_component_appl_id
122500         , p_amb_context_code        => l_amb_context_code
122501         , p_entity_code             => 'TRANSACTIONS'
122502         , p_event_class_code        => 'REVALUATION'
122503         , p_side                    => 'NA'
122507 
122504         );
122505 
122506   END IF;
122508    --
122509    --
122510    END IF;
122511 
122512        --
122513        -- Update the line information that should be overwritten
122514        --
122515        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
122516                                          p_header_num   => 1);
122517        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
122518 
122519        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
122520 
122521        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
122522           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
122523        END IF;
122524 
122525       --
122526       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
122527       --
122528       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
122529           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
122530       ELSE
122531           ---------------------------------------------------------------------------------------------------
122532           -- 4262811a Switch Sign
122533           ---------------------------------------------------------------------------------------------------
122534           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
122535           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
122536                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
122537           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
122538                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
122539           -- 5132302
122540           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
122541                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
122542 
122543       END IF;
122544 
122545       -- 4955764
122546       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
122547       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
122548 
122549 
122550       XLA_AE_LINES_PKG.ValidateCurrentLine;
122551       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
122552 
122553       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
122554                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
122555                ,p_balance_type_code => l_balance_type_code);
122556 
122557    END IF;
122558 
122559    -----------------------------------------------------------------------------------------
122560    -- 4262811 Multiperiod Accounting
122561    -----------------------------------------------------------------------------------------
122562      -- No MPA option is assigned.
122563 
122564 
122565 END IF;
122566 END IF;
122567 --
122568 
122569 --
122570 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
122571    trace
122572       (p_msg      => 'END of AcctLineType_325'
122573       ,p_level    => C_LEVEL_PROCEDURE
122574       ,p_module   => l_log_module);
122575 END IF;
122576 --
122577 EXCEPTION
122578   WHEN xla_exceptions_pkg.application_exception THEN
122579       RAISE;
122580   WHEN OTHERS THEN
122581        xla_exceptions_pkg.raise_message
122582            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_325');
122583 END AcctLineType_325;
122584 --
122585 
122586 ---------------------------------------
122587 --
122588 -- PRIVATE FUNCTION
122589 --         AcctLineType_326
122590 --
122591 ---------------------------------------
122592 PROCEDURE AcctLineType_326 (
122593   p_application_id        IN NUMBER
122594  ,p_event_id              IN NUMBER
122595  ,p_calculate_acctd_flag  IN VARCHAR2
122596  ,p_calculate_g_l_flag    IN VARCHAR2
122597  ,p_actual_flag           IN OUT VARCHAR2
122598  ,p_balance_type_code     OUT VARCHAR2
122599  ,p_gain_or_loss_ref      OUT VARCHAR2
122600  
122601 --Period Close Date
122602  , p_source_1            IN DATE
122603 --Generated Code Combination Identifier
122604  , p_source_3            IN NUMBER
122605 --CIP Cost Account
122606  , p_source_7            IN VARCHAR2
122607 --Expense Account Code Combination Identifier
122608  , p_source_29            IN NUMBER
122609 --Default Code Combination Identifier
122610  , p_source_30            IN NUMBER
122611 --Adjustment Type
122612  , p_source_35            IN VARCHAR2
122613 --Transaction Header Identifier
122614  , p_source_36            IN NUMBER
122615 --Adjustment Line Identifier
122616  , p_source_37            IN NUMBER
122617 --Distribution Type Code
122618  , p_source_38            IN VARCHAR2
122619 --Entered Amount
122620  , p_source_39            IN NUMBER
122621 --Currency Code
122622  , p_source_40            IN VARCHAR2
122623 )
122624 IS
122625 
122626 l_component_type              VARCHAR2(80);
122627 l_component_code              VARCHAR2(30);
122628 l_component_type_code         VARCHAR2(1);
122629 l_component_appl_id           INTEGER;
122630 l_amb_context_code            VARCHAR2(30);
122631 l_entity_code                 VARCHAR2(30);
122632 l_event_class_code            VARCHAR2(30);
122633 l_ae_header_id                NUMBER;
122634 l_event_type_code             VARCHAR2(30);
122635 l_line_definition_code        VARCHAR2(30);
122636 l_line_definition_owner_code  VARCHAR2(1);
122637 --
122638 -- adr variables
122639 l_segment                     VARCHAR2(30);
122640 l_ccid                        NUMBER;
122641 l_adr_transaction_coa_id      NUMBER;
122645 l_adr_value_type_code         VARCHAR2(30);
122642 l_adr_accounting_coa_id       NUMBER;
122643 l_adr_flexfield_segment_code  VARCHAR2(30);
122644 l_adr_flex_value_set_id       NUMBER;
122646 l_adr_value_combination_id    NUMBER;
122647 l_adr_value_segment_code      VARCHAR2(30);
122648 
122649 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
122650 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
122651 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
122652 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
122653 
122654 -- 4262811 Variables ------------------------------------------------------------------------------------------
122655 l_entered_amt_idx             NUMBER;
122656 l_accted_amt_idx              NUMBER;
122657 l_acc_rev_flag                VARCHAR2(1);
122658 l_accrual_line_num            NUMBER;
122659 l_tmp_amt                     NUMBER;
122660 l_acc_rev_natural_side_code   VARCHAR2(1);
122661 
122662 l_num_entries                 NUMBER;
122663 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
122664 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
122665 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
122666 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
122667 l_recog_line_1                NUMBER;
122668 l_recog_line_2                NUMBER;
122669 
122670 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
122671 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
122672 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
122673 
122674 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
122675 
122676 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
122677 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
122678 
122679 ---------------------------------------------------------------------------------------------------------------
122680 
122681 
122682 --
122683 -- bulk performance
122684 --
122685 l_balance_type_code           VARCHAR2(1);
122686 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
122687 l_log_module                  VARCHAR2(240);
122688 
122689 --
122690 -- Upgrade strategy
122691 --
122692 l_actual_upg_option           VARCHAR2(1);
122693 l_enc_upg_option           VARCHAR2(1);
122694 
122695 --
122696 BEGIN
122697 --
122698 IF g_log_enabled THEN
122699       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_326';
122700 END IF;
122701 --
122702 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
122703 
122704       trace
122705          (p_msg      => 'BEGIN of AcctLineType_326'
122706          ,p_level    => C_LEVEL_PROCEDURE
122707          ,p_module   => l_log_module);
122708 
122709 END IF;
122710 --
122711 l_component_type             := 'AMB_JLT';
122712 l_component_code             := 'FA_REV_ASSET_CIP_COST';
122713 l_component_type_code        := 'S';
122714 l_component_appl_id          :=  140;
122715 l_amb_context_code           := 'DEFAULT';
122716 l_entity_code                := 'TRANSACTIONS';
122717 l_event_class_code           := 'CAPITALIZATION';
122718 l_event_type_code            := 'REVERSE_CAPITALIZATION';
122719 l_line_definition_owner_code := 'S';
122720 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVER22';
122721 --
122722 l_balance_type_code          := 'A';
122723 l_segment                     := NULL;
122724 l_ccid                        := NULL;
122725 l_adr_transaction_coa_id      := NULL;
122726 l_adr_accounting_coa_id       := NULL;
122727 l_adr_flexfield_segment_code  := NULL;
122728 l_adr_flex_value_set_id       := NULL;
122729 l_adr_value_type_code         := NULL;
122730 l_adr_value_combination_id    := NULL;
122731 l_adr_value_segment_code      := NULL;
122732 
122733 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
122734 l_bflow_class_code           := '';    -- 4219869 Business Flow
122735 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
122736 l_budgetary_control_flag     := 'N';
122737 
122738 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
122739 l_bflow_applied_to_amt       := NULL; -- 5132302
122740 l_entered_amt_idx            := NULL;          -- 4262811
122741 l_accted_amt_idx             := NULL;          -- 4262811
122742 l_acc_rev_flag               := NULL;          -- 4262811
122743 l_accrual_line_num           := NULL;          -- 4262811
122744 l_tmp_amt                    := NULL;          -- 4262811
122745 --
122746  
122747 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
122748     l_balance_type_code <> 'B' THEN
122749 IF NVL(p_source_35,'
122750 ') =  'CIP COST'
122751  THEN 
122752 
122753    --
122754    XLA_AE_LINES_PKG.SetNewLine;
122755 
122756    p_balance_type_code          := l_balance_type_code;
122757    -- set the flag so later we will know whether the gain loss line needs to be created
122758    
122759    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
122760      p_actual_flag :='A';
122761    END IF;
122762 
122763    --
122764    -- bulk performance
122765    --
122766    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
122767                                       p_header_num   => 0); -- 4262811
122768    --
122769    -- set accounting line options
122770    --
122771    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
122772            p_natural_side_code          => 'C'
122773          , p_gain_or_loss_flag          => 'N'
122774          , p_gl_transfer_mode_code      => 'S'
122775          , p_acct_entry_type_code       => 'A'
122776          , p_switch_side_flag           => 'Y'
122777          , p_merge_duplicate_code       => 'N'
122778          );
122779    --
122783    -- set accounting line type info
122780    l_acc_rev_natural_side_code := 'D';  -- 4262811
122781    -- 
122782    --
122784    --
122785    xla_ae_lines_pkg.SetAcctLineType
122786       (p_component_type             => l_component_type
122787       ,p_event_type_code            => l_event_type_code
122788       ,p_line_definition_owner_code => l_line_definition_owner_code
122789       ,p_line_definition_code       => l_line_definition_code
122790       ,p_accounting_line_code       => l_component_code
122791       ,p_accounting_line_type_code  => l_component_type_code
122792       ,p_accounting_line_appl_id    => l_component_appl_id
122793       ,p_amb_context_code           => l_amb_context_code
122794       ,p_entity_code                => l_entity_code
122795       ,p_event_class_code           => l_event_class_code);
122796    --
122797    -- set accounting class
122798    --
122799    xla_ae_lines_pkg.SetAcctClass(
122800            p_accounting_class_code  => 'ASSET'
122801          , p_ae_header_id           => l_ae_header_id
122802          );
122803 
122804    --
122805    -- set rounding class
122806    --
122807    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
122808                       'ASSET';
122809 
122810    --
122811    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
122812    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
122813    --
122814    -- bulk performance
122815    --
122816    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
122817 
122818    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
122819       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
122820 
122821    -- 4955764
122822    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
122823       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
122824 
122825    -- 4458381 Public Sector Enh
122826    
122827    --
122828    -- set accounting attributes for the line type
122829    --
122830    l_entered_amt_idx := 4;
122831    l_accted_amt_idx  := 6;
122832    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
122833    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
122834    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
122835    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
122836    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
122837    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
122838    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
122839    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
122840    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
122841    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
122842    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
122843    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
122844    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
122845 
122846    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
122847    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
122848 
122849    ---------------------------------------------------------------------------------------------------------------
122850    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
122851    ---------------------------------------------------------------------------------------------------------------
122852    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
122853 
122854    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
122855    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
122856 
122857    IF xla_accounting_cache_pkg.GetValueChar
122858          (p_source_code         => 'LEDGER_CATEGORY_CODE'
122859          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
122860    AND l_bflow_method_code = 'PRIOR_ENTRY'
122861 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
122862    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
122863          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
122864        )
122865    THEN
122866          xla_ae_lines_pkg.BflowUpgEntry
122867            (p_business_method_code    => l_bflow_method_code
122868            ,p_business_class_code     => l_bflow_class_code
122869            ,p_balance_type            => l_balance_type_code);
122870    ELSE
122871       NULL;
122872 -- No business flow processing for business flow method of NONE.
122873    END IF;
122874 
122875    --
122876    -- call analytical criteria
122877    --
122878    
122879    --
122880    -- call description
122881    --
122882    
122883 xla_ae_lines_pkg.SetLineDescription(
122884    p_ae_header_id => l_ae_header_id
122885   ,p_description  => Description_99 (
122886      p_application_id         => p_application_id
122887    , p_ae_header_id           => l_ae_header_id 
122888 , p_source_1 => p_source_1
122889    )
122890 );
122891 
122892 
122893    --
122894    -- call ADRs
122895    -- Bug 4922099
122896    --
122897    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
122898         (NVL(l_actual_upg_option, 'N') = 'O') OR
122899         (NVL(l_enc_upg_option, 'N') = 'O')
122900       )
122901    THEN
122902    NULL;
122903    --
122904    --
122905    
122906   l_ccid := AcctDerRule_173(
122907            p_application_id           => p_application_id
122908          , p_ae_header_id             => l_ae_header_id 
122909 , p_source_3 => p_source_3
122910 , p_source_30 => p_source_30
122914          , p_side                     => 'NA'
122911          , x_transaction_coa_id       => l_adr_transaction_coa_id
122912          , x_accounting_coa_id        => l_adr_accounting_coa_id
122913          , x_value_type_code          => l_adr_value_type_code
122915    );
122916 
122917    xla_ae_lines_pkg.set_ccid(
122918     p_code_combination_id          => l_ccid
122919   , p_value_type_code              => l_adr_value_type_code
122920   , p_transaction_coa_id           => l_adr_transaction_coa_id
122921   , p_accounting_coa_id            => l_adr_accounting_coa_id
122922   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
122923   , p_adr_type_code                => 'S'
122924   , p_component_type               => l_component_type
122925   , p_component_code               => l_component_code
122926   , p_component_type_code          => l_component_type_code
122927   , p_component_appl_id            => l_component_appl_id
122928   , p_amb_context_code             => l_amb_context_code
122929   , p_side                         => 'NA'
122930   );
122931 
122932 
122933    l_segment := AcctDerRule_146(
122934            p_application_id           => p_application_id
122935          , p_ae_header_id             => l_ae_header_id 
122936 , p_source_3 => p_source_3
122937 , p_source_7 => p_source_7
122938          , x_transaction_coa_id       => l_adr_transaction_coa_id
122939          , x_accounting_coa_id        => l_adr_accounting_coa_id
122940          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
122941          , x_flex_value_set_id        => l_adr_flex_value_set_id
122942          , x_value_type_code          => l_adr_value_type_code
122943          , x_value_combination_id     => l_adr_value_combination_id
122944          , x_value_segment_code       => l_adr_value_segment_code
122945          , p_side                     => 'NA'
122946          , p_override_seg_flag        => 'Y'
122947    );
122948 
122949    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
122950 
122951       xla_ae_lines_pkg.set_segment(
122952           p_to_segment_code         => 'GL_ACCOUNT'
122953         , p_segment_value           => l_segment
122954         , p_from_segment_code       => l_adr_value_segment_code
122955         , p_from_combination_id     => l_adr_value_combination_id
122956         , p_value_type_code         => l_adr_value_type_code
122957         , p_transaction_coa_id      => l_adr_transaction_coa_id
122958         , p_accounting_coa_id       => l_adr_accounting_coa_id
122959         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
122960         , p_flex_value_set_id       => l_adr_flex_value_set_id
122961         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
122962         , p_adr_type_code           => 'S'
122963         , p_component_type          => l_component_type
122964         , p_component_code          => l_component_code
122965         , p_component_type_code     => l_component_type_code
122966         , p_component_appl_id       => l_component_appl_id
122967         , p_amb_context_code        => l_amb_context_code
122968         , p_entity_code             => 'TRANSACTIONS'
122969         , p_event_class_code        => 'CAPITALIZATION'
122970         , p_side                    => 'NA'
122971         );
122972 
122973   END IF;
122974 
122975    l_segment := AcctDerRule_168(
122976            p_application_id           => p_application_id
122977          , p_ae_header_id             => l_ae_header_id 
122978 , p_source_3 => p_source_3
122979 , p_source_29 => p_source_29
122980          , x_transaction_coa_id       => l_adr_transaction_coa_id
122981          , x_accounting_coa_id        => l_adr_accounting_coa_id
122982          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
122983          , x_flex_value_set_id        => l_adr_flex_value_set_id
122984          , x_value_type_code          => l_adr_value_type_code
122985          , x_value_combination_id     => l_adr_value_combination_id
122986          , x_value_segment_code       => l_adr_value_segment_code
122987          , p_side                     => 'NA'
122988          , p_override_seg_flag        => 'Y'
122989    );
122990 
122991    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
122992 
122993       xla_ae_lines_pkg.set_segment(
122994           p_to_segment_code         => 'GL_BALANCING'
122995         , p_segment_value           => l_segment
122996         , p_from_segment_code       => l_adr_value_segment_code
122997         , p_from_combination_id     => l_adr_value_combination_id
122998         , p_value_type_code         => l_adr_value_type_code
122999         , p_transaction_coa_id      => l_adr_transaction_coa_id
123000         , p_accounting_coa_id       => l_adr_accounting_coa_id
123001         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
123002         , p_flex_value_set_id       => l_adr_flex_value_set_id
123003         , p_adr_code                => 'FA_EXPENSE_ACCT'
123004         , p_adr_type_code           => 'S'
123005         , p_component_type          => l_component_type
123006         , p_component_code          => l_component_code
123007         , p_component_type_code     => l_component_type_code
123008         , p_component_appl_id       => l_component_appl_id
123009         , p_amb_context_code        => l_amb_context_code
123010         , p_entity_code             => 'TRANSACTIONS'
123011         , p_event_class_code        => 'CAPITALIZATION'
123012         , p_side                    => 'NA'
123013         );
123014 
123015   END IF;
123016 
123017    --
123018    --
123019    END IF;
123020    --
123021    -- Bug 4922099
123022    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
123023           (NVL(l_enc_upg_option, 'N') = 'O')
123024         ) AND
123025         (l_bflow_method_code = 'PRIOR_ENTRY')
123026       )
123027    THEN
123028       IF
123029       --
123030       1 = 2
123031       --
123032       THEN
123033       xla_accounting_err_pkg.build_message
123034                                     (p_appli_s_name            => 'XLA'
123038                                     ,p_token_2                 => 'LINE_TYPE_NAME'
123035                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
123036                                     ,p_token_1                 => 'LINE_NUMBER'
123037                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
123039                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
123040                                                                              l_component_type
123041                                                                             ,l_component_code
123042                                                                             ,l_component_type_code
123043                                                                             ,l_component_appl_id
123044                                                                             ,l_amb_context_code
123045                                                                             ,l_entity_code
123046                                                                             ,l_event_class_code
123047                                                                            )
123048                                     ,p_token_3                 => 'OWNER'
123049                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
123050                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
123051                                                                           ,p_lookup_code    => l_component_type_code
123052                                                                          )
123053                                     ,p_token_4                 => 'PRODUCT_NAME'
123054                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
123055                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
123056                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
123057                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
123058                                     ,p_ae_header_id            =>  NULL
123059                                        );
123060 
123061         IF (C_LEVEL_ERROR>= g_log_level) THEN
123062                  trace
123063                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
123064                       ,p_level    => C_LEVEL_ERROR
123065                       ,p_module   => l_log_module);
123066         END IF;
123067       END IF;
123068    END IF;
123069    --
123070    --
123071    ------------------------------------------------------------------------------------------------
123072    -- 4219869 Business Flow
123073    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
123074    -- Prior Entry.  Currently, the following code is always generated.
123075    ------------------------------------------------------------------------------------------------
123076    XLA_AE_LINES_PKG.ValidateCurrentLine;
123077 
123078    ------------------------------------------------------------------------------------
123079    -- 4219869 Business Flow
123080    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
123081    ------------------------------------------------------------------------------------
123082    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
123083 
123084    ----------------------------------------------------------------------------------
123085    -- 4219869 Business Flow
123086    -- Update journal entry status -- Need to generate this within IF <condition>
123087    ----------------------------------------------------------------------------------
123088    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
123089          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
123090          ,p_balance_type_code => l_balance_type_code
123091          );
123092 
123093    -------------------------------------------------------------------------------------------
123094    -- 4262811 - Generate the Accrual Reversal lines
123095    -------------------------------------------------------------------------------------------
123096    BEGIN
123097       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
123098                               (g_array_event(p_event_id).array_value_num('header_index'));
123099       IF l_acc_rev_flag IS NULL THEN
123100          l_acc_rev_flag := 'N';
123101       END IF;
123102    EXCEPTION
123103       WHEN OTHERS THEN
123104          l_acc_rev_flag := 'N';
123105    END;
123106    --
123107    IF (l_acc_rev_flag = 'Y') THEN
123108 
123109        -- 4645092  ------------------------------------------------------------------------------
123110        -- To allow MPA report to determine if it should generate report process
123111        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
123112        ------------------------------------------------------------------------------------------
123113 
123114        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
123115        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
123116    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
123117    -- call ADRs
123118    -- Bug 4922099
123119    --
123120    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
123121         (NVL(l_actual_upg_option, 'N') = 'O') OR
123122         (NVL(l_enc_upg_option, 'N') = 'O')
123123       )
123124    THEN
123125    NULL;
123126    --
123127    --
123128    
123129   l_ccid := AcctDerRule_173(
123130            p_application_id           => p_application_id
123131          , p_ae_header_id             => l_ae_header_id 
123132 , p_source_3 => p_source_3
123133 , p_source_30 => p_source_30
123134          , x_transaction_coa_id       => l_adr_transaction_coa_id
123135          , x_accounting_coa_id        => l_adr_accounting_coa_id
123139 
123136          , x_value_type_code          => l_adr_value_type_code
123137          , p_side                     => 'NA'
123138    );
123140    xla_ae_lines_pkg.set_ccid(
123141     p_code_combination_id          => l_ccid
123142   , p_value_type_code              => l_adr_value_type_code
123143   , p_transaction_coa_id           => l_adr_transaction_coa_id
123144   , p_accounting_coa_id            => l_adr_accounting_coa_id
123145   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
123146   , p_adr_type_code                => 'S'
123147   , p_component_type               => l_component_type
123148   , p_component_code               => l_component_code
123149   , p_component_type_code          => l_component_type_code
123150   , p_component_appl_id            => l_component_appl_id
123151   , p_amb_context_code             => l_amb_context_code
123152   , p_side                         => 'NA'
123153   );
123154 
123155 
123156    l_segment := AcctDerRule_146(
123157            p_application_id           => p_application_id
123158          , p_ae_header_id             => l_ae_header_id 
123159 , p_source_3 => p_source_3
123160 , p_source_7 => p_source_7
123161          , x_transaction_coa_id       => l_adr_transaction_coa_id
123162          , x_accounting_coa_id        => l_adr_accounting_coa_id
123163          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
123164          , x_flex_value_set_id        => l_adr_flex_value_set_id
123165          , x_value_type_code          => l_adr_value_type_code
123166          , x_value_combination_id     => l_adr_value_combination_id
123167          , x_value_segment_code       => l_adr_value_segment_code
123168          , p_side                     => 'NA'
123169          , p_override_seg_flag        => 'Y'
123170    );
123171 
123172    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
123173 
123174       xla_ae_lines_pkg.set_segment(
123175           p_to_segment_code         => 'GL_ACCOUNT'
123176         , p_segment_value           => l_segment
123177         , p_from_segment_code       => l_adr_value_segment_code
123178         , p_from_combination_id     => l_adr_value_combination_id
123179         , p_value_type_code         => l_adr_value_type_code
123180         , p_transaction_coa_id      => l_adr_transaction_coa_id
123181         , p_accounting_coa_id       => l_adr_accounting_coa_id
123182         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
123183         , p_flex_value_set_id       => l_adr_flex_value_set_id
123184         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
123185         , p_adr_type_code           => 'S'
123186         , p_component_type          => l_component_type
123187         , p_component_code          => l_component_code
123188         , p_component_type_code     => l_component_type_code
123189         , p_component_appl_id       => l_component_appl_id
123190         , p_amb_context_code        => l_amb_context_code
123191         , p_entity_code             => 'TRANSACTIONS'
123192         , p_event_class_code        => 'CAPITALIZATION'
123193         , p_side                    => 'NA'
123194         );
123195 
123196   END IF;
123197 
123198    l_segment := AcctDerRule_168(
123199            p_application_id           => p_application_id
123200          , p_ae_header_id             => l_ae_header_id 
123201 , p_source_3 => p_source_3
123202 , p_source_29 => p_source_29
123203          , x_transaction_coa_id       => l_adr_transaction_coa_id
123204          , x_accounting_coa_id        => l_adr_accounting_coa_id
123205          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
123206          , x_flex_value_set_id        => l_adr_flex_value_set_id
123207          , x_value_type_code          => l_adr_value_type_code
123208          , x_value_combination_id     => l_adr_value_combination_id
123209          , x_value_segment_code       => l_adr_value_segment_code
123210          , p_side                     => 'NA'
123211          , p_override_seg_flag        => 'Y'
123212    );
123213 
123214    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
123215 
123216       xla_ae_lines_pkg.set_segment(
123217           p_to_segment_code         => 'GL_BALANCING'
123218         , p_segment_value           => l_segment
123219         , p_from_segment_code       => l_adr_value_segment_code
123220         , p_from_combination_id     => l_adr_value_combination_id
123221         , p_value_type_code         => l_adr_value_type_code
123222         , p_transaction_coa_id      => l_adr_transaction_coa_id
123223         , p_accounting_coa_id       => l_adr_accounting_coa_id
123224         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
123225         , p_flex_value_set_id       => l_adr_flex_value_set_id
123226         , p_adr_code                => 'FA_EXPENSE_ACCT'
123227         , p_adr_type_code           => 'S'
123228         , p_component_type          => l_component_type
123229         , p_component_code          => l_component_code
123230         , p_component_type_code     => l_component_type_code
123231         , p_component_appl_id       => l_component_appl_id
123232         , p_amb_context_code        => l_amb_context_code
123233         , p_entity_code             => 'TRANSACTIONS'
123234         , p_event_class_code        => 'CAPITALIZATION'
123235         , p_side                    => 'NA'
123236         );
123237 
123238   END IF;
123239 
123240    --
123241    --
123242    END IF;
123243 
123244        --
123245        -- Update the line information that should be overwritten
123246        --
123247        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
123248                                          p_header_num   => 1);
123249        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
123250 
123251        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
123252 
123253        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
123257       --
123254           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
123255        END IF;
123256 
123258       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
123259       --
123260       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
123261           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
123262       ELSE
123263           ---------------------------------------------------------------------------------------------------
123264           -- 4262811a Switch Sign
123265           ---------------------------------------------------------------------------------------------------
123266           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
123267           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
123268                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
123269           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
123270                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
123271           -- 5132302
123272           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
123273                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
123274 
123275       END IF;
123276 
123277       -- 4955764
123278       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
123279       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
123280 
123281 
123282       XLA_AE_LINES_PKG.ValidateCurrentLine;
123283       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
123284 
123285       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
123286                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
123287                ,p_balance_type_code => l_balance_type_code);
123288 
123289    END IF;
123290 
123291    -----------------------------------------------------------------------------------------
123292    -- 4262811 Multiperiod Accounting
123293    -----------------------------------------------------------------------------------------
123294      -- No MPA option is assigned.
123295 
123296 
123297 END IF;
123298 END IF;
123299 --
123300 
123301 --
123302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
123303    trace
123304       (p_msg      => 'END of AcctLineType_326'
123305       ,p_level    => C_LEVEL_PROCEDURE
123306       ,p_module   => l_log_module);
123307 END IF;
123308 --
123309 EXCEPTION
123310   WHEN xla_exceptions_pkg.application_exception THEN
123311       RAISE;
123312   WHEN OTHERS THEN
123313        xla_exceptions_pkg.raise_message
123314            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_326');
123315 END AcctLineType_326;
123316 --
123317 
123318 ---------------------------------------
123319 --
123320 -- PRIVATE FUNCTION
123321 --         AcctLineType_327
123322 --
123323 ---------------------------------------
123324 PROCEDURE AcctLineType_327 (
123325   p_application_id        IN NUMBER
123326  ,p_event_id              IN NUMBER
123327  ,p_calculate_acctd_flag  IN VARCHAR2
123328  ,p_calculate_g_l_flag    IN VARCHAR2
123329  ,p_actual_flag           IN OUT VARCHAR2
123330  ,p_balance_type_code     OUT VARCHAR2
123331  ,p_gain_or_loss_ref      OUT VARCHAR2
123332  
123333 --Period Close Date
123334  , p_source_1            IN DATE
123335 --Generated Code Combination Identifier
123336  , p_source_3            IN NUMBER
123337 --Asset Cost Account
123338  , p_source_9            IN VARCHAR2
123339 --Expense Account Code Combination Identifier
123340  , p_source_29            IN NUMBER
123341 --Default Code Combination Identifier
123342  , p_source_30            IN NUMBER
123343 --Adjustment Type
123344  , p_source_35            IN VARCHAR2
123345 --Transaction Header Identifier
123346  , p_source_36            IN NUMBER
123347 --Adjustment Line Identifier
123348  , p_source_37            IN NUMBER
123349 --Distribution Type Code
123350  , p_source_38            IN VARCHAR2
123351 --Entered Amount
123352  , p_source_39            IN NUMBER
123353 --Currency Code
123354  , p_source_40            IN VARCHAR2
123355 )
123356 IS
123357 
123358 l_component_type              VARCHAR2(80);
123359 l_component_code              VARCHAR2(30);
123360 l_component_type_code         VARCHAR2(1);
123361 l_component_appl_id           INTEGER;
123362 l_amb_context_code            VARCHAR2(30);
123363 l_entity_code                 VARCHAR2(30);
123364 l_event_class_code            VARCHAR2(30);
123365 l_ae_header_id                NUMBER;
123366 l_event_type_code             VARCHAR2(30);
123367 l_line_definition_code        VARCHAR2(30);
123368 l_line_definition_owner_code  VARCHAR2(1);
123369 --
123370 -- adr variables
123371 l_segment                     VARCHAR2(30);
123372 l_ccid                        NUMBER;
123373 l_adr_transaction_coa_id      NUMBER;
123374 l_adr_accounting_coa_id       NUMBER;
123375 l_adr_flexfield_segment_code  VARCHAR2(30);
123376 l_adr_flex_value_set_id       NUMBER;
123377 l_adr_value_type_code         VARCHAR2(30);
123378 l_adr_value_combination_id    NUMBER;
123379 l_adr_value_segment_code      VARCHAR2(30);
123380 
123381 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
123382 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
123383 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
123384 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
123385 
123386 -- 4262811 Variables ------------------------------------------------------------------------------------------
123390 l_accrual_line_num            NUMBER;
123387 l_entered_amt_idx             NUMBER;
123388 l_accted_amt_idx              NUMBER;
123389 l_acc_rev_flag                VARCHAR2(1);
123391 l_tmp_amt                     NUMBER;
123392 l_acc_rev_natural_side_code   VARCHAR2(1);
123393 
123394 l_num_entries                 NUMBER;
123395 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
123396 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
123397 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
123398 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
123399 l_recog_line_1                NUMBER;
123400 l_recog_line_2                NUMBER;
123401 
123402 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
123403 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
123404 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
123405 
123406 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
123407 
123408 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
123409 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
123410 
123411 ---------------------------------------------------------------------------------------------------------------
123412 
123413 
123414 --
123415 -- bulk performance
123416 --
123417 l_balance_type_code           VARCHAR2(1);
123418 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
123419 l_log_module                  VARCHAR2(240);
123420 
123421 --
123422 -- Upgrade strategy
123423 --
123424 l_actual_upg_option           VARCHAR2(1);
123425 l_enc_upg_option           VARCHAR2(1);
123426 
123427 --
123428 BEGIN
123429 --
123430 IF g_log_enabled THEN
123431       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_327';
123432 END IF;
123433 --
123434 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
123435 
123436       trace
123437          (p_msg      => 'BEGIN of AcctLineType_327'
123438          ,p_level    => C_LEVEL_PROCEDURE
123439          ,p_module   => l_log_module);
123440 
123441 END IF;
123442 --
123443 l_component_type             := 'AMB_JLT';
123444 l_component_code             := 'FA_REV_ASSET_COST';
123445 l_component_type_code        := 'S';
123446 l_component_appl_id          :=  140;
123447 l_amb_context_code           := 'DEFAULT';
123448 l_entity_code                := 'TRANSACTIONS';
123449 l_event_class_code           := 'CAPITALIZATION';
123450 l_event_type_code            := 'REVERSE_CAPITALIZATION';
123451 l_line_definition_owner_code := 'S';
123452 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVER22';
123453 --
123454 l_balance_type_code          := 'A';
123455 l_segment                     := NULL;
123456 l_ccid                        := NULL;
123457 l_adr_transaction_coa_id      := NULL;
123458 l_adr_accounting_coa_id       := NULL;
123459 l_adr_flexfield_segment_code  := NULL;
123460 l_adr_flex_value_set_id       := NULL;
123461 l_adr_value_type_code         := NULL;
123462 l_adr_value_combination_id    := NULL;
123463 l_adr_value_segment_code      := NULL;
123464 
123465 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
123466 l_bflow_class_code           := '';    -- 4219869 Business Flow
123467 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
123468 l_budgetary_control_flag     := 'N';
123469 
123470 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
123471 l_bflow_applied_to_amt       := NULL; -- 5132302
123472 l_entered_amt_idx            := NULL;          -- 4262811
123473 l_accted_amt_idx             := NULL;          -- 4262811
123474 l_acc_rev_flag               := NULL;          -- 4262811
123475 l_accrual_line_num           := NULL;          -- 4262811
123476 l_tmp_amt                    := NULL;          -- 4262811
123477 --
123478  
123479 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
123480     l_balance_type_code <> 'B' THEN
123481 IF NVL(p_source_35,'
123482 ') =  'COST'
123483  THEN 
123484 
123485    --
123486    XLA_AE_LINES_PKG.SetNewLine;
123487 
123488    p_balance_type_code          := l_balance_type_code;
123489    -- set the flag so later we will know whether the gain loss line needs to be created
123490    
123491    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
123492      p_actual_flag :='A';
123493    END IF;
123494 
123495    --
123496    -- bulk performance
123497    --
123498    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
123499                                       p_header_num   => 0); -- 4262811
123500    --
123501    -- set accounting line options
123502    --
123503    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
123504            p_natural_side_code          => 'D'
123505          , p_gain_or_loss_flag          => 'N'
123506          , p_gl_transfer_mode_code      => 'S'
123507          , p_acct_entry_type_code       => 'A'
123508          , p_switch_side_flag           => 'Y'
123509          , p_merge_duplicate_code       => 'N'
123510          );
123511    --
123512    l_acc_rev_natural_side_code := 'C';  -- 4262811
123513    -- 
123514    --
123515    -- set accounting line type info
123516    --
123517    xla_ae_lines_pkg.SetAcctLineType
123518       (p_component_type             => l_component_type
123519       ,p_event_type_code            => l_event_type_code
123520       ,p_line_definition_owner_code => l_line_definition_owner_code
123521       ,p_line_definition_code       => l_line_definition_code
123522       ,p_accounting_line_code       => l_component_code
123523       ,p_accounting_line_type_code  => l_component_type_code
123524       ,p_accounting_line_appl_id    => l_component_appl_id
123525       ,p_amb_context_code           => l_amb_context_code
123529    -- set accounting class
123526       ,p_entity_code                => l_entity_code
123527       ,p_event_class_code           => l_event_class_code);
123528    --
123530    --
123531    xla_ae_lines_pkg.SetAcctClass(
123532            p_accounting_class_code  => 'ASSET'
123533          , p_ae_header_id           => l_ae_header_id
123534          );
123535 
123536    --
123537    -- set rounding class
123538    --
123539    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
123540                       'ASSET';
123541 
123542    --
123543    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
123544    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
123545    --
123546    -- bulk performance
123547    --
123548    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
123549 
123550    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
123551       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
123552 
123553    -- 4955764
123554    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
123555       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
123556 
123557    -- 4458381 Public Sector Enh
123558    
123559    --
123560    -- set accounting attributes for the line type
123561    --
123562    l_entered_amt_idx := 4;
123563    l_accted_amt_idx  := 6;
123564    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
123565    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
123566    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
123567    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
123568    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
123569    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
123570    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
123571    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
123572    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
123573    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
123574    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
123575    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
123576    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
123577 
123578    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
123579    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
123580 
123581    ---------------------------------------------------------------------------------------------------------------
123582    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
123583    ---------------------------------------------------------------------------------------------------------------
123584    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
123585 
123586    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
123587    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
123588 
123589    IF xla_accounting_cache_pkg.GetValueChar
123590          (p_source_code         => 'LEDGER_CATEGORY_CODE'
123591          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
123592    AND l_bflow_method_code = 'PRIOR_ENTRY'
123593 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
123594    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
123595          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
123596        )
123597    THEN
123598          xla_ae_lines_pkg.BflowUpgEntry
123599            (p_business_method_code    => l_bflow_method_code
123600            ,p_business_class_code     => l_bflow_class_code
123601            ,p_balance_type            => l_balance_type_code);
123602    ELSE
123603       NULL;
123604 -- No business flow processing for business flow method of NONE.
123605    END IF;
123606 
123607    --
123608    -- call analytical criteria
123609    --
123610    
123611    --
123612    -- call description
123613    --
123614    
123615 xla_ae_lines_pkg.SetLineDescription(
123616    p_ae_header_id => l_ae_header_id
123617   ,p_description  => Description_100 (
123618      p_application_id         => p_application_id
123619    , p_ae_header_id           => l_ae_header_id 
123620 , p_source_1 => p_source_1
123621    )
123622 );
123623 
123624 
123625    --
123626    -- call ADRs
123627    -- Bug 4922099
123628    --
123629    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
123630         (NVL(l_actual_upg_option, 'N') = 'O') OR
123631         (NVL(l_enc_upg_option, 'N') = 'O')
123632       )
123633    THEN
123634    NULL;
123635    --
123636    --
123637    
123638   l_ccid := AcctDerRule_173(
123639            p_application_id           => p_application_id
123640          , p_ae_header_id             => l_ae_header_id 
123641 , p_source_3 => p_source_3
123642 , p_source_30 => p_source_30
123643          , x_transaction_coa_id       => l_adr_transaction_coa_id
123644          , x_accounting_coa_id        => l_adr_accounting_coa_id
123645          , x_value_type_code          => l_adr_value_type_code
123646          , p_side                     => 'NA'
123647    );
123648 
123649    xla_ae_lines_pkg.set_ccid(
123650     p_code_combination_id          => l_ccid
123651   , p_value_type_code              => l_adr_value_type_code
123652   , p_transaction_coa_id           => l_adr_transaction_coa_id
123653   , p_accounting_coa_id            => l_adr_accounting_coa_id
123654   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
123655   , p_adr_type_code                => 'S'
123659   , p_component_appl_id            => l_component_appl_id
123656   , p_component_type               => l_component_type
123657   , p_component_code               => l_component_code
123658   , p_component_type_code          => l_component_type_code
123660   , p_amb_context_code             => l_amb_context_code
123661   , p_side                         => 'NA'
123662   );
123663 
123664 
123665    l_segment := AcctDerRule_148(
123666            p_application_id           => p_application_id
123667          , p_ae_header_id             => l_ae_header_id 
123668 , p_source_3 => p_source_3
123669 , p_source_9 => p_source_9
123670          , x_transaction_coa_id       => l_adr_transaction_coa_id
123671          , x_accounting_coa_id        => l_adr_accounting_coa_id
123672          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
123673          , x_flex_value_set_id        => l_adr_flex_value_set_id
123674          , x_value_type_code          => l_adr_value_type_code
123675          , x_value_combination_id     => l_adr_value_combination_id
123676          , x_value_segment_code       => l_adr_value_segment_code
123677          , p_side                     => 'NA'
123678          , p_override_seg_flag        => 'Y'
123679    );
123680 
123681    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
123682 
123683       xla_ae_lines_pkg.set_segment(
123684           p_to_segment_code         => 'GL_ACCOUNT'
123685         , p_segment_value           => l_segment
123686         , p_from_segment_code       => l_adr_value_segment_code
123687         , p_from_combination_id     => l_adr_value_combination_id
123688         , p_value_type_code         => l_adr_value_type_code
123689         , p_transaction_coa_id      => l_adr_transaction_coa_id
123690         , p_accounting_coa_id       => l_adr_accounting_coa_id
123691         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
123692         , p_flex_value_set_id       => l_adr_flex_value_set_id
123693         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
123694         , p_adr_type_code           => 'S'
123695         , p_component_type          => l_component_type
123696         , p_component_code          => l_component_code
123697         , p_component_type_code     => l_component_type_code
123698         , p_component_appl_id       => l_component_appl_id
123699         , p_amb_context_code        => l_amb_context_code
123700         , p_entity_code             => 'TRANSACTIONS'
123701         , p_event_class_code        => 'CAPITALIZATION'
123702         , p_side                    => 'NA'
123703         );
123704 
123705   END IF;
123706 
123707    l_segment := AcctDerRule_168(
123708            p_application_id           => p_application_id
123709          , p_ae_header_id             => l_ae_header_id 
123710 , p_source_3 => p_source_3
123711 , p_source_29 => p_source_29
123712          , x_transaction_coa_id       => l_adr_transaction_coa_id
123713          , x_accounting_coa_id        => l_adr_accounting_coa_id
123714          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
123715          , x_flex_value_set_id        => l_adr_flex_value_set_id
123716          , x_value_type_code          => l_adr_value_type_code
123717          , x_value_combination_id     => l_adr_value_combination_id
123718          , x_value_segment_code       => l_adr_value_segment_code
123719          , p_side                     => 'NA'
123720          , p_override_seg_flag        => 'Y'
123721    );
123722 
123723    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
123724 
123725       xla_ae_lines_pkg.set_segment(
123726           p_to_segment_code         => 'GL_BALANCING'
123727         , p_segment_value           => l_segment
123728         , p_from_segment_code       => l_adr_value_segment_code
123729         , p_from_combination_id     => l_adr_value_combination_id
123730         , p_value_type_code         => l_adr_value_type_code
123731         , p_transaction_coa_id      => l_adr_transaction_coa_id
123732         , p_accounting_coa_id       => l_adr_accounting_coa_id
123733         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
123734         , p_flex_value_set_id       => l_adr_flex_value_set_id
123735         , p_adr_code                => 'FA_EXPENSE_ACCT'
123736         , p_adr_type_code           => 'S'
123737         , p_component_type          => l_component_type
123738         , p_component_code          => l_component_code
123739         , p_component_type_code     => l_component_type_code
123740         , p_component_appl_id       => l_component_appl_id
123741         , p_amb_context_code        => l_amb_context_code
123742         , p_entity_code             => 'TRANSACTIONS'
123743         , p_event_class_code        => 'CAPITALIZATION'
123744         , p_side                    => 'NA'
123745         );
123746 
123747   END IF;
123748 
123749    --
123750    --
123751    END IF;
123752    --
123753    -- Bug 4922099
123754    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
123755           (NVL(l_enc_upg_option, 'N') = 'O')
123756         ) AND
123757         (l_bflow_method_code = 'PRIOR_ENTRY')
123758       )
123759    THEN
123760       IF
123761       --
123762       1 = 2
123763       --
123764       THEN
123765       xla_accounting_err_pkg.build_message
123766                                     (p_appli_s_name            => 'XLA'
123767                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
123768                                     ,p_token_1                 => 'LINE_NUMBER'
123769                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
123770                                     ,p_token_2                 => 'LINE_TYPE_NAME'
123771                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
123772                                                                              l_component_type
123773                                                                             ,l_component_code
123777                                                                             ,l_entity_code
123774                                                                             ,l_component_type_code
123775                                                                             ,l_component_appl_id
123776                                                                             ,l_amb_context_code
123778                                                                             ,l_event_class_code
123779                                                                            )
123780                                     ,p_token_3                 => 'OWNER'
123781                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
123782                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
123783                                                                           ,p_lookup_code    => l_component_type_code
123784                                                                          )
123785                                     ,p_token_4                 => 'PRODUCT_NAME'
123786                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
123787                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
123788                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
123789                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
123790                                     ,p_ae_header_id            =>  NULL
123791                                        );
123792 
123793         IF (C_LEVEL_ERROR>= g_log_level) THEN
123794                  trace
123795                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
123796                       ,p_level    => C_LEVEL_ERROR
123797                       ,p_module   => l_log_module);
123798         END IF;
123799       END IF;
123800    END IF;
123801    --
123802    --
123803    ------------------------------------------------------------------------------------------------
123804    -- 4219869 Business Flow
123805    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
123806    -- Prior Entry.  Currently, the following code is always generated.
123807    ------------------------------------------------------------------------------------------------
123808    XLA_AE_LINES_PKG.ValidateCurrentLine;
123809 
123810    ------------------------------------------------------------------------------------
123811    -- 4219869 Business Flow
123812    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
123813    ------------------------------------------------------------------------------------
123814    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
123815 
123816    ----------------------------------------------------------------------------------
123817    -- 4219869 Business Flow
123818    -- Update journal entry status -- Need to generate this within IF <condition>
123819    ----------------------------------------------------------------------------------
123820    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
123821          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
123822          ,p_balance_type_code => l_balance_type_code
123823          );
123824 
123825    -------------------------------------------------------------------------------------------
123826    -- 4262811 - Generate the Accrual Reversal lines
123827    -------------------------------------------------------------------------------------------
123828    BEGIN
123829       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
123830                               (g_array_event(p_event_id).array_value_num('header_index'));
123831       IF l_acc_rev_flag IS NULL THEN
123832          l_acc_rev_flag := 'N';
123833       END IF;
123834    EXCEPTION
123835       WHEN OTHERS THEN
123836          l_acc_rev_flag := 'N';
123837    END;
123838    --
123839    IF (l_acc_rev_flag = 'Y') THEN
123840 
123841        -- 4645092  ------------------------------------------------------------------------------
123842        -- To allow MPA report to determine if it should generate report process
123843        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
123844        ------------------------------------------------------------------------------------------
123845 
123846        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
123847        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
123848    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
123849    -- call ADRs
123850    -- Bug 4922099
123851    --
123852    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
123853         (NVL(l_actual_upg_option, 'N') = 'O') OR
123854         (NVL(l_enc_upg_option, 'N') = 'O')
123855       )
123856    THEN
123857    NULL;
123858    --
123859    --
123860    
123861   l_ccid := AcctDerRule_173(
123862            p_application_id           => p_application_id
123863          , p_ae_header_id             => l_ae_header_id 
123864 , p_source_3 => p_source_3
123865 , p_source_30 => p_source_30
123866          , x_transaction_coa_id       => l_adr_transaction_coa_id
123867          , x_accounting_coa_id        => l_adr_accounting_coa_id
123868          , x_value_type_code          => l_adr_value_type_code
123869          , p_side                     => 'NA'
123870    );
123871 
123872    xla_ae_lines_pkg.set_ccid(
123873     p_code_combination_id          => l_ccid
123874   , p_value_type_code              => l_adr_value_type_code
123875   , p_transaction_coa_id           => l_adr_transaction_coa_id
123876   , p_accounting_coa_id            => l_adr_accounting_coa_id
123877   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
123878   , p_adr_type_code                => 'S'
123879   , p_component_type               => l_component_type
123880   , p_component_code               => l_component_code
123884   , p_side                         => 'NA'
123881   , p_component_type_code          => l_component_type_code
123882   , p_component_appl_id            => l_component_appl_id
123883   , p_amb_context_code             => l_amb_context_code
123885   );
123886 
123887 
123888    l_segment := AcctDerRule_148(
123889            p_application_id           => p_application_id
123890          , p_ae_header_id             => l_ae_header_id 
123891 , p_source_3 => p_source_3
123892 , p_source_9 => p_source_9
123893          , x_transaction_coa_id       => l_adr_transaction_coa_id
123894          , x_accounting_coa_id        => l_adr_accounting_coa_id
123895          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
123896          , x_flex_value_set_id        => l_adr_flex_value_set_id
123897          , x_value_type_code          => l_adr_value_type_code
123898          , x_value_combination_id     => l_adr_value_combination_id
123899          , x_value_segment_code       => l_adr_value_segment_code
123900          , p_side                     => 'NA'
123901          , p_override_seg_flag        => 'Y'
123902    );
123903 
123904    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
123905 
123906       xla_ae_lines_pkg.set_segment(
123907           p_to_segment_code         => 'GL_ACCOUNT'
123908         , p_segment_value           => l_segment
123909         , p_from_segment_code       => l_adr_value_segment_code
123910         , p_from_combination_id     => l_adr_value_combination_id
123911         , p_value_type_code         => l_adr_value_type_code
123912         , p_transaction_coa_id      => l_adr_transaction_coa_id
123913         , p_accounting_coa_id       => l_adr_accounting_coa_id
123914         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
123915         , p_flex_value_set_id       => l_adr_flex_value_set_id
123916         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
123917         , p_adr_type_code           => 'S'
123918         , p_component_type          => l_component_type
123919         , p_component_code          => l_component_code
123920         , p_component_type_code     => l_component_type_code
123921         , p_component_appl_id       => l_component_appl_id
123922         , p_amb_context_code        => l_amb_context_code
123923         , p_entity_code             => 'TRANSACTIONS'
123924         , p_event_class_code        => 'CAPITALIZATION'
123925         , p_side                    => 'NA'
123926         );
123927 
123928   END IF;
123929 
123930    l_segment := AcctDerRule_168(
123931            p_application_id           => p_application_id
123932          , p_ae_header_id             => l_ae_header_id 
123933 , p_source_3 => p_source_3
123934 , p_source_29 => p_source_29
123935          , x_transaction_coa_id       => l_adr_transaction_coa_id
123936          , x_accounting_coa_id        => l_adr_accounting_coa_id
123937          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
123938          , x_flex_value_set_id        => l_adr_flex_value_set_id
123939          , x_value_type_code          => l_adr_value_type_code
123940          , x_value_combination_id     => l_adr_value_combination_id
123941          , x_value_segment_code       => l_adr_value_segment_code
123942          , p_side                     => 'NA'
123943          , p_override_seg_flag        => 'Y'
123944    );
123945 
123946    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
123947 
123948       xla_ae_lines_pkg.set_segment(
123949           p_to_segment_code         => 'GL_BALANCING'
123950         , p_segment_value           => l_segment
123951         , p_from_segment_code       => l_adr_value_segment_code
123952         , p_from_combination_id     => l_adr_value_combination_id
123953         , p_value_type_code         => l_adr_value_type_code
123954         , p_transaction_coa_id      => l_adr_transaction_coa_id
123955         , p_accounting_coa_id       => l_adr_accounting_coa_id
123956         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
123957         , p_flex_value_set_id       => l_adr_flex_value_set_id
123958         , p_adr_code                => 'FA_EXPENSE_ACCT'
123959         , p_adr_type_code           => 'S'
123960         , p_component_type          => l_component_type
123961         , p_component_code          => l_component_code
123962         , p_component_type_code     => l_component_type_code
123963         , p_component_appl_id       => l_component_appl_id
123964         , p_amb_context_code        => l_amb_context_code
123965         , p_entity_code             => 'TRANSACTIONS'
123966         , p_event_class_code        => 'CAPITALIZATION'
123967         , p_side                    => 'NA'
123968         );
123969 
123970   END IF;
123971 
123972    --
123973    --
123974    END IF;
123975 
123976        --
123977        -- Update the line information that should be overwritten
123978        --
123979        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
123980                                          p_header_num   => 1);
123981        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
123982 
123983        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
123984 
123985        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
123986           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
123987        END IF;
123988 
123989       --
123990       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
123991       --
123992       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
123993           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
123994       ELSE
123995           ---------------------------------------------------------------------------------------------------
123996           -- 4262811a Switch Sign
124000                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
123997           ---------------------------------------------------------------------------------------------------
123998           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
123999           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
124001           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
124002                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
124003           -- 5132302
124004           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
124005                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
124006 
124007       END IF;
124008 
124009       -- 4955764
124010       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
124011       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
124012 
124013 
124014       XLA_AE_LINES_PKG.ValidateCurrentLine;
124015       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
124016 
124017       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
124018                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
124019                ,p_balance_type_code => l_balance_type_code);
124020 
124021    END IF;
124022 
124023    -----------------------------------------------------------------------------------------
124024    -- 4262811 Multiperiod Accounting
124025    -----------------------------------------------------------------------------------------
124026      -- No MPA option is assigned.
124027 
124028 
124029 END IF;
124030 END IF;
124031 --
124032 
124033 --
124034 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
124035    trace
124036       (p_msg      => 'END of AcctLineType_327'
124037       ,p_level    => C_LEVEL_PROCEDURE
124038       ,p_module   => l_log_module);
124039 END IF;
124040 --
124041 EXCEPTION
124042   WHEN xla_exceptions_pkg.application_exception THEN
124043       RAISE;
124044   WHEN OTHERS THEN
124045        xla_exceptions_pkg.raise_message
124046            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_327');
124047 END AcctLineType_327;
124048 --
124049 
124050 ---------------------------------------
124051 --
124052 -- PRIVATE FUNCTION
124053 --         AcctLineType_328
124054 --
124055 ---------------------------------------
124056 PROCEDURE AcctLineType_328 (
124057   p_application_id        IN NUMBER
124058  ,p_event_id              IN NUMBER
124059  ,p_calculate_acctd_flag  IN VARCHAR2
124060  ,p_calculate_g_l_flag    IN VARCHAR2
124061  ,p_actual_flag           IN OUT VARCHAR2
124062  ,p_balance_type_code     OUT VARCHAR2
124063  ,p_gain_or_loss_ref      OUT VARCHAR2
124064  
124065 --Period Close Date
124066  , p_source_1            IN DATE
124067 --Generated Code Combination Identifier
124068  , p_source_3            IN NUMBER
124069 --Expense Account Code Combination Identifier
124070  , p_source_29            IN NUMBER
124071 --Adjustment Type
124072  , p_source_35            IN VARCHAR2
124073 --Transaction Header Identifier
124074  , p_source_36            IN NUMBER
124075 --Adjustment Line Identifier
124076  , p_source_37            IN NUMBER
124077 --Distribution Type Code
124078  , p_source_38            IN VARCHAR2
124079 --Entered Amount
124080  , p_source_39            IN NUMBER
124081 --Currency Code
124082  , p_source_40            IN VARCHAR2
124083 )
124084 IS
124085 
124086 l_component_type              VARCHAR2(80);
124087 l_component_code              VARCHAR2(30);
124088 l_component_type_code         VARCHAR2(1);
124089 l_component_appl_id           INTEGER;
124090 l_amb_context_code            VARCHAR2(30);
124091 l_entity_code                 VARCHAR2(30);
124092 l_event_class_code            VARCHAR2(30);
124093 l_ae_header_id                NUMBER;
124094 l_event_type_code             VARCHAR2(30);
124095 l_line_definition_code        VARCHAR2(30);
124096 l_line_definition_owner_code  VARCHAR2(1);
124097 --
124098 -- adr variables
124099 l_segment                     VARCHAR2(30);
124100 l_ccid                        NUMBER;
124101 l_adr_transaction_coa_id      NUMBER;
124102 l_adr_accounting_coa_id       NUMBER;
124103 l_adr_flexfield_segment_code  VARCHAR2(30);
124104 l_adr_flex_value_set_id       NUMBER;
124105 l_adr_value_type_code         VARCHAR2(30);
124106 l_adr_value_combination_id    NUMBER;
124107 l_adr_value_segment_code      VARCHAR2(30);
124108 
124109 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
124110 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
124111 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
124112 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
124113 
124114 -- 4262811 Variables ------------------------------------------------------------------------------------------
124115 l_entered_amt_idx             NUMBER;
124116 l_accted_amt_idx              NUMBER;
124117 l_acc_rev_flag                VARCHAR2(1);
124118 l_accrual_line_num            NUMBER;
124119 l_tmp_amt                     NUMBER;
124120 l_acc_rev_natural_side_code   VARCHAR2(1);
124121 
124122 l_num_entries                 NUMBER;
124123 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
124124 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
124125 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
124126 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
124127 l_recog_line_1                NUMBER;
124128 l_recog_line_2                NUMBER;
124129 
124130 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
124134 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
124131 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
124132 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
124133 
124135 
124136 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
124137 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
124138 
124139 ---------------------------------------------------------------------------------------------------------------
124140 
124141 
124142 --
124143 -- bulk performance
124144 --
124145 l_balance_type_code           VARCHAR2(1);
124146 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
124147 l_log_module                  VARCHAR2(240);
124148 
124149 --
124150 -- Upgrade strategy
124151 --
124152 l_actual_upg_option           VARCHAR2(1);
124153 l_enc_upg_option           VARCHAR2(1);
124154 
124155 --
124156 BEGIN
124157 --
124158 IF g_log_enabled THEN
124159       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_328';
124160 END IF;
124161 --
124162 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
124163 
124164       trace
124165          (p_msg      => 'BEGIN of AcctLineType_328'
124166          ,p_level    => C_LEVEL_PROCEDURE
124167          ,p_module   => l_log_module);
124168 
124169 END IF;
124170 --
124171 l_component_type             := 'AMB_JLT';
124172 l_component_code             := 'FA_REV_ASSET_EXP';
124173 l_component_type_code        := 'S';
124174 l_component_appl_id          :=  140;
124175 l_amb_context_code           := 'DEFAULT';
124176 l_entity_code                := 'TRANSACTIONS';
124177 l_event_class_code           := 'CAPITALIZATION';
124178 l_event_type_code            := 'REVERSE_CAPITALIZATION';
124179 l_line_definition_owner_code := 'S';
124180 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVER22';
124181 --
124182 l_balance_type_code          := 'A';
124183 l_segment                     := NULL;
124184 l_ccid                        := NULL;
124185 l_adr_transaction_coa_id      := NULL;
124186 l_adr_accounting_coa_id       := NULL;
124187 l_adr_flexfield_segment_code  := NULL;
124188 l_adr_flex_value_set_id       := NULL;
124189 l_adr_value_type_code         := NULL;
124190 l_adr_value_combination_id    := NULL;
124191 l_adr_value_segment_code      := NULL;
124192 
124193 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
124194 l_bflow_class_code           := '';    -- 4219869 Business Flow
124195 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
124196 l_budgetary_control_flag     := 'N';
124197 
124198 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
124199 l_bflow_applied_to_amt       := NULL; -- 5132302
124200 l_entered_amt_idx            := NULL;          -- 4262811
124201 l_accted_amt_idx             := NULL;          -- 4262811
124202 l_acc_rev_flag               := NULL;          -- 4262811
124203 l_accrual_line_num           := NULL;          -- 4262811
124204 l_tmp_amt                    := NULL;          -- 4262811
124205 --
124206  
124207 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
124208     l_balance_type_code <> 'B' THEN
124209 IF NVL(p_source_35,'
124210 ') =  'EXPENSE'
124211  THEN 
124212 
124213    --
124214    XLA_AE_LINES_PKG.SetNewLine;
124215 
124216    p_balance_type_code          := l_balance_type_code;
124217    -- set the flag so later we will know whether the gain loss line needs to be created
124218    
124219    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
124220      p_actual_flag :='A';
124221    END IF;
124222 
124223    --
124224    -- bulk performance
124225    --
124226    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
124227                                       p_header_num   => 0); -- 4262811
124228    --
124229    -- set accounting line options
124230    --
124231    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
124232            p_natural_side_code          => 'D'
124233          , p_gain_or_loss_flag          => 'N'
124234          , p_gl_transfer_mode_code      => 'S'
124235          , p_acct_entry_type_code       => 'A'
124236          , p_switch_side_flag           => 'Y'
124237          , p_merge_duplicate_code       => 'N'
124238          );
124239    --
124240    l_acc_rev_natural_side_code := 'C';  -- 4262811
124241    -- 
124242    --
124243    -- set accounting line type info
124244    --
124245    xla_ae_lines_pkg.SetAcctLineType
124246       (p_component_type             => l_component_type
124247       ,p_event_type_code            => l_event_type_code
124248       ,p_line_definition_owner_code => l_line_definition_owner_code
124249       ,p_line_definition_code       => l_line_definition_code
124250       ,p_accounting_line_code       => l_component_code
124251       ,p_accounting_line_type_code  => l_component_type_code
124252       ,p_accounting_line_appl_id    => l_component_appl_id
124253       ,p_amb_context_code           => l_amb_context_code
124254       ,p_entity_code                => l_entity_code
124255       ,p_event_class_code           => l_event_class_code);
124256    --
124257    -- set accounting class
124258    --
124259    xla_ae_lines_pkg.SetAcctClass(
124260            p_accounting_class_code  => 'EXPENSE'
124261          , p_ae_header_id           => l_ae_header_id
124262          );
124263 
124264    --
124265    -- set rounding class
124266    --
124267    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
124268                       'EXPENSE';
124269 
124270    --
124271    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
124272    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
124276    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
124273    --
124274    -- bulk performance
124275    --
124277 
124278    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
124279       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
124280 
124281    -- 4955764
124282    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
124283       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
124284 
124285    -- 4458381 Public Sector Enh
124286    
124287    --
124288    -- set accounting attributes for the line type
124289    --
124290    l_entered_amt_idx := 4;
124291    l_accted_amt_idx  := 6;
124292    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
124293    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
124294    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
124295    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
124296    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
124297    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
124298    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
124299    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
124300    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
124301    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
124302    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
124303    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
124304    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
124305 
124306    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
124307    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
124308 
124309    ---------------------------------------------------------------------------------------------------------------
124310    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
124311    ---------------------------------------------------------------------------------------------------------------
124312    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
124313 
124314    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
124315    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
124316 
124317    IF xla_accounting_cache_pkg.GetValueChar
124318          (p_source_code         => 'LEDGER_CATEGORY_CODE'
124319          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
124320    AND l_bflow_method_code = 'PRIOR_ENTRY'
124321 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
124322    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
124323          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
124324        )
124325    THEN
124326          xla_ae_lines_pkg.BflowUpgEntry
124327            (p_business_method_code    => l_bflow_method_code
124328            ,p_business_class_code     => l_bflow_class_code
124329            ,p_balance_type            => l_balance_type_code);
124330    ELSE
124331       NULL;
124332 -- No business flow processing for business flow method of NONE.
124333    END IF;
124334 
124335    --
124336    -- call analytical criteria
124337    --
124338    
124339    --
124340    -- call description
124341    --
124342    
124343 xla_ae_lines_pkg.SetLineDescription(
124344    p_ae_header_id => l_ae_header_id
124345   ,p_description  => Description_101 (
124346      p_application_id         => p_application_id
124347    , p_ae_header_id           => l_ae_header_id 
124348 , p_source_1 => p_source_1
124349    )
124350 );
124351 
124352 
124353    --
124354    -- call ADRs
124355    -- Bug 4922099
124356    --
124357    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
124358         (NVL(l_actual_upg_option, 'N') = 'O') OR
124359         (NVL(l_enc_upg_option, 'N') = 'O')
124360       )
124361    THEN
124362    NULL;
124363    --
124364    --
124365    
124366   l_ccid := AcctDerRule_175(
124367            p_application_id           => p_application_id
124368          , p_ae_header_id             => l_ae_header_id 
124369 , p_source_3 => p_source_3
124370 , p_source_29 => p_source_29
124371          , x_transaction_coa_id       => l_adr_transaction_coa_id
124372          , x_accounting_coa_id        => l_adr_accounting_coa_id
124373          , x_value_type_code          => l_adr_value_type_code
124374          , p_side                     => 'NA'
124375    );
124376 
124377    xla_ae_lines_pkg.set_ccid(
124378     p_code_combination_id          => l_ccid
124379   , p_value_type_code              => l_adr_value_type_code
124380   , p_transaction_coa_id           => l_adr_transaction_coa_id
124381   , p_accounting_coa_id            => l_adr_accounting_coa_id
124382   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
124383   , p_adr_type_code                => 'S'
124384   , p_component_type               => l_component_type
124385   , p_component_code               => l_component_code
124386   , p_component_type_code          => l_component_type_code
124387   , p_component_appl_id            => l_component_appl_id
124388   , p_amb_context_code             => l_amb_context_code
124389   , p_side                         => 'NA'
124390   );
124391 
124392 
124393    --
124394    --
124395    END IF;
124396    --
124397    -- Bug 4922099
124398    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
124399           (NVL(l_enc_upg_option, 'N') = 'O')
124400         ) AND
124401         (l_bflow_method_code = 'PRIOR_ENTRY')
124402       )
124403    THEN
124404       IF
124405       --
124406       1 = 2
124407       --
124408       THEN
124412                                     ,p_token_1                 => 'LINE_NUMBER'
124409       xla_accounting_err_pkg.build_message
124410                                     (p_appli_s_name            => 'XLA'
124411                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
124413                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
124414                                     ,p_token_2                 => 'LINE_TYPE_NAME'
124415                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
124416                                                                              l_component_type
124417                                                                             ,l_component_code
124418                                                                             ,l_component_type_code
124419                                                                             ,l_component_appl_id
124420                                                                             ,l_amb_context_code
124421                                                                             ,l_entity_code
124422                                                                             ,l_event_class_code
124423                                                                            )
124424                                     ,p_token_3                 => 'OWNER'
124425                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
124426                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
124427                                                                           ,p_lookup_code    => l_component_type_code
124428                                                                          )
124429                                     ,p_token_4                 => 'PRODUCT_NAME'
124430                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
124431                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
124432                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
124433                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
124434                                     ,p_ae_header_id            =>  NULL
124435                                        );
124436 
124437         IF (C_LEVEL_ERROR>= g_log_level) THEN
124438                  trace
124439                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
124440                       ,p_level    => C_LEVEL_ERROR
124441                       ,p_module   => l_log_module);
124442         END IF;
124443       END IF;
124444    END IF;
124445    --
124446    --
124447    ------------------------------------------------------------------------------------------------
124448    -- 4219869 Business Flow
124449    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
124450    -- Prior Entry.  Currently, the following code is always generated.
124451    ------------------------------------------------------------------------------------------------
124452    XLA_AE_LINES_PKG.ValidateCurrentLine;
124453 
124454    ------------------------------------------------------------------------------------
124455    -- 4219869 Business Flow
124456    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
124457    ------------------------------------------------------------------------------------
124458    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
124459 
124460    ----------------------------------------------------------------------------------
124461    -- 4219869 Business Flow
124462    -- Update journal entry status -- Need to generate this within IF <condition>
124463    ----------------------------------------------------------------------------------
124464    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
124465          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
124466          ,p_balance_type_code => l_balance_type_code
124467          );
124468 
124469    -------------------------------------------------------------------------------------------
124470    -- 4262811 - Generate the Accrual Reversal lines
124471    -------------------------------------------------------------------------------------------
124472    BEGIN
124473       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
124474                               (g_array_event(p_event_id).array_value_num('header_index'));
124475       IF l_acc_rev_flag IS NULL THEN
124476          l_acc_rev_flag := 'N';
124477       END IF;
124478    EXCEPTION
124479       WHEN OTHERS THEN
124480          l_acc_rev_flag := 'N';
124481    END;
124482    --
124483    IF (l_acc_rev_flag = 'Y') THEN
124484 
124485        -- 4645092  ------------------------------------------------------------------------------
124486        -- To allow MPA report to determine if it should generate report process
124487        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
124488        ------------------------------------------------------------------------------------------
124489 
124490        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
124491        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
124492    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
124493    -- call ADRs
124494    -- Bug 4922099
124495    --
124496    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
124497         (NVL(l_actual_upg_option, 'N') = 'O') OR
124498         (NVL(l_enc_upg_option, 'N') = 'O')
124499       )
124500    THEN
124501    NULL;
124502    --
124503    --
124504    
124505   l_ccid := AcctDerRule_175(
124506            p_application_id           => p_application_id
124507          , p_ae_header_id             => l_ae_header_id 
124508 , p_source_3 => p_source_3
124509 , p_source_29 => p_source_29
124513          , p_side                     => 'NA'
124510          , x_transaction_coa_id       => l_adr_transaction_coa_id
124511          , x_accounting_coa_id        => l_adr_accounting_coa_id
124512          , x_value_type_code          => l_adr_value_type_code
124514    );
124515 
124516    xla_ae_lines_pkg.set_ccid(
124517     p_code_combination_id          => l_ccid
124518   , p_value_type_code              => l_adr_value_type_code
124519   , p_transaction_coa_id           => l_adr_transaction_coa_id
124520   , p_accounting_coa_id            => l_adr_accounting_coa_id
124521   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
124522   , p_adr_type_code                => 'S'
124523   , p_component_type               => l_component_type
124524   , p_component_code               => l_component_code
124525   , p_component_type_code          => l_component_type_code
124526   , p_component_appl_id            => l_component_appl_id
124527   , p_amb_context_code             => l_amb_context_code
124528   , p_side                         => 'NA'
124529   );
124530 
124531 
124532    --
124533    --
124534    END IF;
124535 
124536        --
124537        -- Update the line information that should be overwritten
124538        --
124539        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
124540                                          p_header_num   => 1);
124541        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
124542 
124543        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
124544 
124545        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
124546           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
124547        END IF;
124548 
124549       --
124550       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
124551       --
124552       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
124553           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
124554       ELSE
124555           ---------------------------------------------------------------------------------------------------
124556           -- 4262811a Switch Sign
124557           ---------------------------------------------------------------------------------------------------
124558           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
124559           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
124560                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
124561           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
124562                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
124563           -- 5132302
124564           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
124565                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
124566 
124567       END IF;
124568 
124569       -- 4955764
124570       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
124571       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
124572 
124573 
124574       XLA_AE_LINES_PKG.ValidateCurrentLine;
124575       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
124576 
124577       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
124578                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
124579                ,p_balance_type_code => l_balance_type_code);
124580 
124581    END IF;
124582 
124583    -----------------------------------------------------------------------------------------
124584    -- 4262811 Multiperiod Accounting
124585    -----------------------------------------------------------------------------------------
124586      -- No MPA option is assigned.
124587 
124588 
124589 END IF;
124590 END IF;
124591 --
124592 
124593 --
124594 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
124595    trace
124596       (p_msg      => 'END of AcctLineType_328'
124597       ,p_level    => C_LEVEL_PROCEDURE
124598       ,p_module   => l_log_module);
124599 END IF;
124600 --
124601 EXCEPTION
124602   WHEN xla_exceptions_pkg.application_exception THEN
124603       RAISE;
124604   WHEN OTHERS THEN
124605        xla_exceptions_pkg.raise_message
124606            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_328');
124607 END AcctLineType_328;
124608 --
124609 
124610 ---------------------------------------
124611 --
124612 -- PRIVATE FUNCTION
124613 --         AcctLineType_329
124614 --
124615 ---------------------------------------
124616 PROCEDURE AcctLineType_329 (
124617   p_application_id        IN NUMBER
124618  ,p_event_id              IN NUMBER
124619  ,p_calculate_acctd_flag  IN VARCHAR2
124620  ,p_calculate_g_l_flag    IN VARCHAR2
124621  ,p_actual_flag           IN OUT VARCHAR2
124622  ,p_balance_type_code     OUT VARCHAR2
124623  ,p_gain_or_loss_ref      OUT VARCHAR2
124624  
124625 --Period Close Date
124626  , p_source_1            IN DATE
124627 --Bonus Depreciation Expense Account
124628  , p_source_2            IN VARCHAR2
124629 --Generated Code Combination Identifier
124630  , p_source_3            IN NUMBER
124631 --Expense Account Code Combination Identifier
124632  , p_source_29            IN NUMBER
124633 --Adjustment Type
124634  , p_source_35            IN VARCHAR2
124635 --Transaction Header Identifier
124636  , p_source_36            IN NUMBER
124637 --Adjustment Line Identifier
124638  , p_source_37            IN NUMBER
124639 --Distribution Type Code
124640  , p_source_38            IN VARCHAR2
124644  , p_source_40            IN VARCHAR2
124641 --Entered Amount
124642  , p_source_39            IN NUMBER
124643 --Currency Code
124645 )
124646 IS
124647 
124648 l_component_type              VARCHAR2(80);
124649 l_component_code              VARCHAR2(30);
124650 l_component_type_code         VARCHAR2(1);
124651 l_component_appl_id           INTEGER;
124652 l_amb_context_code            VARCHAR2(30);
124653 l_entity_code                 VARCHAR2(30);
124654 l_event_class_code            VARCHAR2(30);
124655 l_ae_header_id                NUMBER;
124656 l_event_type_code             VARCHAR2(30);
124657 l_line_definition_code        VARCHAR2(30);
124658 l_line_definition_owner_code  VARCHAR2(1);
124659 --
124660 -- adr variables
124661 l_segment                     VARCHAR2(30);
124662 l_ccid                        NUMBER;
124663 l_adr_transaction_coa_id      NUMBER;
124664 l_adr_accounting_coa_id       NUMBER;
124665 l_adr_flexfield_segment_code  VARCHAR2(30);
124666 l_adr_flex_value_set_id       NUMBER;
124667 l_adr_value_type_code         VARCHAR2(30);
124668 l_adr_value_combination_id    NUMBER;
124669 l_adr_value_segment_code      VARCHAR2(30);
124670 
124671 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
124672 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
124673 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
124674 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
124675 
124676 -- 4262811 Variables ------------------------------------------------------------------------------------------
124677 l_entered_amt_idx             NUMBER;
124678 l_accted_amt_idx              NUMBER;
124679 l_acc_rev_flag                VARCHAR2(1);
124680 l_accrual_line_num            NUMBER;
124681 l_tmp_amt                     NUMBER;
124682 l_acc_rev_natural_side_code   VARCHAR2(1);
124683 
124684 l_num_entries                 NUMBER;
124685 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
124686 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
124687 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
124688 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
124689 l_recog_line_1                NUMBER;
124690 l_recog_line_2                NUMBER;
124691 
124692 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
124693 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
124694 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
124695 
124696 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
124697 
124698 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
124699 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
124700 
124701 ---------------------------------------------------------------------------------------------------------------
124702 
124703 
124704 --
124705 -- bulk performance
124706 --
124707 l_balance_type_code           VARCHAR2(1);
124708 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
124709 l_log_module                  VARCHAR2(240);
124710 
124711 --
124712 -- Upgrade strategy
124713 --
124714 l_actual_upg_option           VARCHAR2(1);
124715 l_enc_upg_option           VARCHAR2(1);
124716 
124717 --
124718 BEGIN
124719 --
124720 IF g_log_enabled THEN
124721       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_329';
124722 END IF;
124723 --
124724 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
124725 
124726       trace
124727          (p_msg      => 'BEGIN of AcctLineType_329'
124728          ,p_level    => C_LEVEL_PROCEDURE
124729          ,p_module   => l_log_module);
124730 
124731 END IF;
124732 --
124733 l_component_type             := 'AMB_JLT';
124734 l_component_code             := 'FA_REV_BONUS_EXP';
124735 l_component_type_code        := 'S';
124736 l_component_appl_id          :=  140;
124737 l_amb_context_code           := 'DEFAULT';
124738 l_entity_code                := 'TRANSACTIONS';
124739 l_event_class_code           := 'CAPITALIZATION';
124740 l_event_type_code            := 'REVERSE_CAPITALIZATION';
124741 l_line_definition_owner_code := 'S';
124742 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVER22';
124743 --
124744 l_balance_type_code          := 'A';
124745 l_segment                     := NULL;
124746 l_ccid                        := NULL;
124747 l_adr_transaction_coa_id      := NULL;
124748 l_adr_accounting_coa_id       := NULL;
124749 l_adr_flexfield_segment_code  := NULL;
124750 l_adr_flex_value_set_id       := NULL;
124751 l_adr_value_type_code         := NULL;
124752 l_adr_value_combination_id    := NULL;
124753 l_adr_value_segment_code      := NULL;
124754 
124755 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
124756 l_bflow_class_code           := '';    -- 4219869 Business Flow
124757 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
124758 l_budgetary_control_flag     := 'N';
124759 
124760 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
124761 l_bflow_applied_to_amt       := NULL; -- 5132302
124762 l_entered_amt_idx            := NULL;          -- 4262811
124763 l_accted_amt_idx             := NULL;          -- 4262811
124764 l_acc_rev_flag               := NULL;          -- 4262811
124765 l_accrual_line_num           := NULL;          -- 4262811
124766 l_tmp_amt                    := NULL;          -- 4262811
124767 --
124768  
124769 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
124770     l_balance_type_code <> 'B' THEN
124771 IF NVL(p_source_35,'
124772 ') =  'BONUS EXPENSE'
124773  THEN 
124774 
124775    --
124776    XLA_AE_LINES_PKG.SetNewLine;
124777 
124778    p_balance_type_code          := l_balance_type_code;
124782      p_actual_flag :='A';
124779    -- set the flag so later we will know whether the gain loss line needs to be created
124780    
124781    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
124783    END IF;
124784 
124785    --
124786    -- bulk performance
124787    --
124788    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
124789                                       p_header_num   => 0); -- 4262811
124790    --
124791    -- set accounting line options
124792    --
124793    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
124794            p_natural_side_code          => 'D'
124795          , p_gain_or_loss_flag          => 'N'
124796          , p_gl_transfer_mode_code      => 'S'
124797          , p_acct_entry_type_code       => 'A'
124798          , p_switch_side_flag           => 'Y'
124799          , p_merge_duplicate_code       => 'N'
124800          );
124801    --
124802    l_acc_rev_natural_side_code := 'C';  -- 4262811
124803    -- 
124804    --
124805    -- set accounting line type info
124806    --
124807    xla_ae_lines_pkg.SetAcctLineType
124808       (p_component_type             => l_component_type
124809       ,p_event_type_code            => l_event_type_code
124810       ,p_line_definition_owner_code => l_line_definition_owner_code
124811       ,p_line_definition_code       => l_line_definition_code
124812       ,p_accounting_line_code       => l_component_code
124813       ,p_accounting_line_type_code  => l_component_type_code
124814       ,p_accounting_line_appl_id    => l_component_appl_id
124815       ,p_amb_context_code           => l_amb_context_code
124816       ,p_entity_code                => l_entity_code
124817       ,p_event_class_code           => l_event_class_code);
124818    --
124819    -- set accounting class
124820    --
124821    xla_ae_lines_pkg.SetAcctClass(
124822            p_accounting_class_code  => 'EXPENSE'
124823          , p_ae_header_id           => l_ae_header_id
124824          );
124825 
124826    --
124827    -- set rounding class
124828    --
124829    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
124830                       'EXPENSE';
124831 
124832    --
124833    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
124834    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
124835    --
124836    -- bulk performance
124837    --
124838    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
124839 
124840    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
124841       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
124842 
124843    -- 4955764
124844    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
124845       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
124846 
124847    -- 4458381 Public Sector Enh
124848    
124849    --
124850    -- set accounting attributes for the line type
124851    --
124852    l_entered_amt_idx := 4;
124853    l_accted_amt_idx  := 6;
124854    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
124855    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
124856    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
124857    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
124858    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
124859    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
124860    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
124861    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
124862    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
124863    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
124864    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
124865    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
124866    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
124867 
124868    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
124869    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
124870 
124871    ---------------------------------------------------------------------------------------------------------------
124872    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
124873    ---------------------------------------------------------------------------------------------------------------
124874    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
124875 
124876    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
124877    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
124878 
124879    IF xla_accounting_cache_pkg.GetValueChar
124880          (p_source_code         => 'LEDGER_CATEGORY_CODE'
124881          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
124882    AND l_bflow_method_code = 'PRIOR_ENTRY'
124883 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
124884    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
124885          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
124886        )
124887    THEN
124888          xla_ae_lines_pkg.BflowUpgEntry
124889            (p_business_method_code    => l_bflow_method_code
124890            ,p_business_class_code     => l_bflow_class_code
124891            ,p_balance_type            => l_balance_type_code);
124892    ELSE
124893       NULL;
124894 -- No business flow processing for business flow method of NONE.
124895    END IF;
124896 
124897    --
124898    -- call analytical criteria
124899    --
124900    
124901    --
124902    -- call description
124903    --
124907   ,p_description  => Description_97 (
124904    
124905 xla_ae_lines_pkg.SetLineDescription(
124906    p_ae_header_id => l_ae_header_id
124908      p_application_id         => p_application_id
124909    , p_ae_header_id           => l_ae_header_id 
124910 , p_source_1 => p_source_1
124911    )
124912 );
124913 
124914 
124915    --
124916    -- call ADRs
124917    -- Bug 4922099
124918    --
124919    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
124920         (NVL(l_actual_upg_option, 'N') = 'O') OR
124921         (NVL(l_enc_upg_option, 'N') = 'O')
124922       )
124923    THEN
124924    NULL;
124925    --
124926    --
124927    
124928   l_ccid := AcctDerRule_175(
124929            p_application_id           => p_application_id
124930          , p_ae_header_id             => l_ae_header_id 
124931 , p_source_3 => p_source_3
124932 , p_source_29 => p_source_29
124933          , x_transaction_coa_id       => l_adr_transaction_coa_id
124934          , x_accounting_coa_id        => l_adr_accounting_coa_id
124935          , x_value_type_code          => l_adr_value_type_code
124936          , p_side                     => 'NA'
124937    );
124938 
124939    xla_ae_lines_pkg.set_ccid(
124940     p_code_combination_id          => l_ccid
124941   , p_value_type_code              => l_adr_value_type_code
124942   , p_transaction_coa_id           => l_adr_transaction_coa_id
124943   , p_accounting_coa_id            => l_adr_accounting_coa_id
124944   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
124945   , p_adr_type_code                => 'S'
124946   , p_component_type               => l_component_type
124947   , p_component_code               => l_component_code
124948   , p_component_type_code          => l_component_type_code
124949   , p_component_appl_id            => l_component_appl_id
124950   , p_amb_context_code             => l_amb_context_code
124951   , p_side                         => 'NA'
124952   );
124953 
124954 
124955    l_segment := AcctDerRule_143(
124956            p_application_id           => p_application_id
124957          , p_ae_header_id             => l_ae_header_id 
124958 , p_source_2 => p_source_2
124959 , p_source_3 => p_source_3
124960          , x_transaction_coa_id       => l_adr_transaction_coa_id
124961          , x_accounting_coa_id        => l_adr_accounting_coa_id
124962          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
124963          , x_flex_value_set_id        => l_adr_flex_value_set_id
124964          , x_value_type_code          => l_adr_value_type_code
124965          , x_value_combination_id     => l_adr_value_combination_id
124966          , x_value_segment_code       => l_adr_value_segment_code
124967          , p_side                     => 'NA'
124968          , p_override_seg_flag        => 'Y'
124969    );
124970 
124971    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
124972 
124973       xla_ae_lines_pkg.set_segment(
124974           p_to_segment_code         => 'GL_ACCOUNT'
124975         , p_segment_value           => l_segment
124976         , p_from_segment_code       => l_adr_value_segment_code
124977         , p_from_combination_id     => l_adr_value_combination_id
124978         , p_value_type_code         => l_adr_value_type_code
124979         , p_transaction_coa_id      => l_adr_transaction_coa_id
124980         , p_accounting_coa_id       => l_adr_accounting_coa_id
124981         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
124982         , p_flex_value_set_id       => l_adr_flex_value_set_id
124983         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
124984         , p_adr_type_code           => 'S'
124985         , p_component_type          => l_component_type
124986         , p_component_code          => l_component_code
124987         , p_component_type_code     => l_component_type_code
124988         , p_component_appl_id       => l_component_appl_id
124989         , p_amb_context_code        => l_amb_context_code
124990         , p_entity_code             => 'TRANSACTIONS'
124991         , p_event_class_code        => 'CAPITALIZATION'
124992         , p_side                    => 'NA'
124993         );
124994 
124995   END IF;
124996 
124997    --
124998    --
124999    END IF;
125000    --
125001    -- Bug 4922099
125002    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
125003           (NVL(l_enc_upg_option, 'N') = 'O')
125004         ) AND
125005         (l_bflow_method_code = 'PRIOR_ENTRY')
125006       )
125007    THEN
125008       IF
125009       --
125010       1 = 2
125011       --
125012       THEN
125013       xla_accounting_err_pkg.build_message
125014                                     (p_appli_s_name            => 'XLA'
125015                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
125016                                     ,p_token_1                 => 'LINE_NUMBER'
125017                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
125018                                     ,p_token_2                 => 'LINE_TYPE_NAME'
125019                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
125020                                                                              l_component_type
125021                                                                             ,l_component_code
125022                                                                             ,l_component_type_code
125023                                                                             ,l_component_appl_id
125024                                                                             ,l_amb_context_code
125025                                                                             ,l_entity_code
125026                                                                             ,l_event_class_code
125027                                                                            )
125028                                     ,p_token_3                 => 'OWNER'
125032                                                                          )
125029                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
125030                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
125031                                                                           ,p_lookup_code    => l_component_type_code
125033                                     ,p_token_4                 => 'PRODUCT_NAME'
125034                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
125035                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
125036                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
125037                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
125038                                     ,p_ae_header_id            =>  NULL
125039                                        );
125040 
125041         IF (C_LEVEL_ERROR>= g_log_level) THEN
125042                  trace
125043                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
125044                       ,p_level    => C_LEVEL_ERROR
125045                       ,p_module   => l_log_module);
125046         END IF;
125047       END IF;
125048    END IF;
125049    --
125050    --
125051    ------------------------------------------------------------------------------------------------
125052    -- 4219869 Business Flow
125053    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
125054    -- Prior Entry.  Currently, the following code is always generated.
125055    ------------------------------------------------------------------------------------------------
125056    XLA_AE_LINES_PKG.ValidateCurrentLine;
125057 
125058    ------------------------------------------------------------------------------------
125059    -- 4219869 Business Flow
125060    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
125061    ------------------------------------------------------------------------------------
125062    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
125063 
125064    ----------------------------------------------------------------------------------
125065    -- 4219869 Business Flow
125066    -- Update journal entry status -- Need to generate this within IF <condition>
125067    ----------------------------------------------------------------------------------
125068    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
125069          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
125070          ,p_balance_type_code => l_balance_type_code
125071          );
125072 
125073    -------------------------------------------------------------------------------------------
125074    -- 4262811 - Generate the Accrual Reversal lines
125075    -------------------------------------------------------------------------------------------
125076    BEGIN
125077       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
125078                               (g_array_event(p_event_id).array_value_num('header_index'));
125079       IF l_acc_rev_flag IS NULL THEN
125080          l_acc_rev_flag := 'N';
125081       END IF;
125082    EXCEPTION
125083       WHEN OTHERS THEN
125084          l_acc_rev_flag := 'N';
125085    END;
125086    --
125087    IF (l_acc_rev_flag = 'Y') THEN
125088 
125089        -- 4645092  ------------------------------------------------------------------------------
125090        -- To allow MPA report to determine if it should generate report process
125091        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
125092        ------------------------------------------------------------------------------------------
125093 
125094        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
125095        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
125096    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
125097    -- call ADRs
125098    -- Bug 4922099
125099    --
125100    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
125101         (NVL(l_actual_upg_option, 'N') = 'O') OR
125102         (NVL(l_enc_upg_option, 'N') = 'O')
125103       )
125104    THEN
125105    NULL;
125106    --
125107    --
125108    
125109   l_ccid := AcctDerRule_175(
125110            p_application_id           => p_application_id
125111          , p_ae_header_id             => l_ae_header_id 
125112 , p_source_3 => p_source_3
125113 , p_source_29 => p_source_29
125114          , x_transaction_coa_id       => l_adr_transaction_coa_id
125115          , x_accounting_coa_id        => l_adr_accounting_coa_id
125116          , x_value_type_code          => l_adr_value_type_code
125117          , p_side                     => 'NA'
125118    );
125119 
125120    xla_ae_lines_pkg.set_ccid(
125121     p_code_combination_id          => l_ccid
125122   , p_value_type_code              => l_adr_value_type_code
125123   , p_transaction_coa_id           => l_adr_transaction_coa_id
125124   , p_accounting_coa_id            => l_adr_accounting_coa_id
125125   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
125126   , p_adr_type_code                => 'S'
125127   , p_component_type               => l_component_type
125128   , p_component_code               => l_component_code
125129   , p_component_type_code          => l_component_type_code
125130   , p_component_appl_id            => l_component_appl_id
125131   , p_amb_context_code             => l_amb_context_code
125132   , p_side                         => 'NA'
125133   );
125134 
125135 
125136    l_segment := AcctDerRule_143(
125137            p_application_id           => p_application_id
125138          , p_ae_header_id             => l_ae_header_id 
125139 , p_source_2 => p_source_2
125140 , p_source_3 => p_source_3
125141          , x_transaction_coa_id       => l_adr_transaction_coa_id
125145          , x_value_type_code          => l_adr_value_type_code
125142          , x_accounting_coa_id        => l_adr_accounting_coa_id
125143          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
125144          , x_flex_value_set_id        => l_adr_flex_value_set_id
125146          , x_value_combination_id     => l_adr_value_combination_id
125147          , x_value_segment_code       => l_adr_value_segment_code
125148          , p_side                     => 'NA'
125149          , p_override_seg_flag        => 'Y'
125150    );
125151 
125152    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
125153 
125154       xla_ae_lines_pkg.set_segment(
125155           p_to_segment_code         => 'GL_ACCOUNT'
125156         , p_segment_value           => l_segment
125157         , p_from_segment_code       => l_adr_value_segment_code
125158         , p_from_combination_id     => l_adr_value_combination_id
125159         , p_value_type_code         => l_adr_value_type_code
125160         , p_transaction_coa_id      => l_adr_transaction_coa_id
125161         , p_accounting_coa_id       => l_adr_accounting_coa_id
125162         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
125163         , p_flex_value_set_id       => l_adr_flex_value_set_id
125164         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
125165         , p_adr_type_code           => 'S'
125166         , p_component_type          => l_component_type
125167         , p_component_code          => l_component_code
125168         , p_component_type_code     => l_component_type_code
125169         , p_component_appl_id       => l_component_appl_id
125170         , p_amb_context_code        => l_amb_context_code
125171         , p_entity_code             => 'TRANSACTIONS'
125172         , p_event_class_code        => 'CAPITALIZATION'
125173         , p_side                    => 'NA'
125174         );
125175 
125176   END IF;
125177 
125178    --
125179    --
125180    END IF;
125181 
125182        --
125183        -- Update the line information that should be overwritten
125184        --
125185        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
125186                                          p_header_num   => 1);
125187        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
125188 
125189        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
125190 
125191        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
125192           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
125193        END IF;
125194 
125195       --
125196       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
125197       --
125198       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
125199           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
125200       ELSE
125201           ---------------------------------------------------------------------------------------------------
125202           -- 4262811a Switch Sign
125203           ---------------------------------------------------------------------------------------------------
125204           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
125205           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
125206                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
125207           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
125208                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
125209           -- 5132302
125210           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
125211                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
125212 
125213       END IF;
125214 
125215       -- 4955764
125216       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
125217       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
125218 
125219 
125220       XLA_AE_LINES_PKG.ValidateCurrentLine;
125221       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
125222 
125223       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
125224                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
125225                ,p_balance_type_code => l_balance_type_code);
125226 
125227    END IF;
125228 
125229    -----------------------------------------------------------------------------------------
125230    -- 4262811 Multiperiod Accounting
125231    -----------------------------------------------------------------------------------------
125232      -- No MPA option is assigned.
125233 
125234 
125235 END IF;
125236 END IF;
125237 --
125238 
125239 --
125240 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
125241    trace
125242       (p_msg      => 'END of AcctLineType_329'
125243       ,p_level    => C_LEVEL_PROCEDURE
125244       ,p_module   => l_log_module);
125245 END IF;
125246 --
125247 EXCEPTION
125248   WHEN xla_exceptions_pkg.application_exception THEN
125249       RAISE;
125250   WHEN OTHERS THEN
125251        xla_exceptions_pkg.raise_message
125252            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_329');
125253 END AcctLineType_329;
125254 --
125255 
125256 ---------------------------------------
125257 --
125258 -- PRIVATE FUNCTION
125259 --         AcctLineType_330
125260 --
125261 ---------------------------------------
125262 PROCEDURE AcctLineType_330 (
125263   p_application_id        IN NUMBER
125264  ,p_event_id              IN NUMBER
125265  ,p_calculate_acctd_flag  IN VARCHAR2
125269  ,p_gain_or_loss_ref      OUT VARCHAR2
125266  ,p_calculate_g_l_flag    IN VARCHAR2
125267  ,p_actual_flag           IN OUT VARCHAR2
125268  ,p_balance_type_code     OUT VARCHAR2
125270  
125271 --Period Close Date
125272  , p_source_1            IN DATE
125273 --Generated Code Combination Identifier
125274  , p_source_3            IN NUMBER
125275 --Bonus Reserve Account
125276  , p_source_4            IN VARCHAR2
125277 --Generated Offset Code Combination Identifier
125278  , p_source_17            IN NUMBER
125279 --Expense Account Code Combination Identifier
125280  , p_source_29            IN NUMBER
125281 --Default Code Combination Identifier
125282  , p_source_30            IN NUMBER
125283 --Adjustment Type
125284  , p_source_35            IN VARCHAR2
125285 --Transaction Header Identifier
125286  , p_source_36            IN NUMBER
125287 --Adjustment Line Identifier
125288  , p_source_37            IN NUMBER
125289 --Distribution Type Code
125290  , p_source_38            IN VARCHAR2
125291 --Entered Amount
125292  , p_source_39            IN NUMBER
125293 --Currency Code
125294  , p_source_40            IN VARCHAR2
125295 )
125296 IS
125297 
125298 l_component_type              VARCHAR2(80);
125299 l_component_code              VARCHAR2(30);
125300 l_component_type_code         VARCHAR2(1);
125301 l_component_appl_id           INTEGER;
125302 l_amb_context_code            VARCHAR2(30);
125303 l_entity_code                 VARCHAR2(30);
125304 l_event_class_code            VARCHAR2(30);
125305 l_ae_header_id                NUMBER;
125306 l_event_type_code             VARCHAR2(30);
125307 l_line_definition_code        VARCHAR2(30);
125308 l_line_definition_owner_code  VARCHAR2(1);
125309 --
125310 -- adr variables
125311 l_segment                     VARCHAR2(30);
125312 l_ccid                        NUMBER;
125313 l_adr_transaction_coa_id      NUMBER;
125314 l_adr_accounting_coa_id       NUMBER;
125315 l_adr_flexfield_segment_code  VARCHAR2(30);
125316 l_adr_flex_value_set_id       NUMBER;
125317 l_adr_value_type_code         VARCHAR2(30);
125318 l_adr_value_combination_id    NUMBER;
125319 l_adr_value_segment_code      VARCHAR2(30);
125320 
125321 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
125322 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
125323 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
125324 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
125325 
125326 -- 4262811 Variables ------------------------------------------------------------------------------------------
125327 l_entered_amt_idx             NUMBER;
125328 l_accted_amt_idx              NUMBER;
125329 l_acc_rev_flag                VARCHAR2(1);
125330 l_accrual_line_num            NUMBER;
125331 l_tmp_amt                     NUMBER;
125332 l_acc_rev_natural_side_code   VARCHAR2(1);
125333 
125334 l_num_entries                 NUMBER;
125335 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
125336 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
125337 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
125338 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
125339 l_recog_line_1                NUMBER;
125340 l_recog_line_2                NUMBER;
125341 
125342 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
125343 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
125344 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
125345 
125346 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
125347 
125348 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
125349 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
125350 
125351 ---------------------------------------------------------------------------------------------------------------
125352 
125353 
125354 --
125355 -- bulk performance
125356 --
125357 l_balance_type_code           VARCHAR2(1);
125358 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
125359 l_log_module                  VARCHAR2(240);
125360 
125361 --
125362 -- Upgrade strategy
125363 --
125364 l_actual_upg_option           VARCHAR2(1);
125365 l_enc_upg_option           VARCHAR2(1);
125366 
125367 --
125368 BEGIN
125369 --
125370 IF g_log_enabled THEN
125371       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_330';
125372 END IF;
125373 --
125374 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
125375 
125376       trace
125377          (p_msg      => 'BEGIN of AcctLineType_330'
125378          ,p_level    => C_LEVEL_PROCEDURE
125379          ,p_module   => l_log_module);
125380 
125381 END IF;
125382 --
125383 l_component_type             := 'AMB_JLT';
125384 l_component_code             := 'FA_REV_BONUS_RESERVE';
125385 l_component_type_code        := 'S';
125386 l_component_appl_id          :=  140;
125387 l_amb_context_code           := 'DEFAULT';
125388 l_entity_code                := 'TRANSACTIONS';
125389 l_event_class_code           := 'CAPITALIZATION';
125390 l_event_type_code            := 'REVERSE_CAPITALIZATION';
125391 l_line_definition_owner_code := 'S';
125392 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVER22';
125393 --
125394 l_balance_type_code          := 'A';
125395 l_segment                     := NULL;
125396 l_ccid                        := NULL;
125397 l_adr_transaction_coa_id      := NULL;
125398 l_adr_accounting_coa_id       := NULL;
125399 l_adr_flexfield_segment_code  := NULL;
125400 l_adr_flex_value_set_id       := NULL;
125401 l_adr_value_type_code         := NULL;
125402 l_adr_value_combination_id    := NULL;
125403 l_adr_value_segment_code      := NULL;
125404 
125405 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
125409 
125406 l_bflow_class_code           := '';    -- 4219869 Business Flow
125407 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
125408 l_budgetary_control_flag     := 'N';
125410 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
125411 l_bflow_applied_to_amt       := NULL; -- 5132302
125412 l_entered_amt_idx            := NULL;          -- 4262811
125413 l_accted_amt_idx             := NULL;          -- 4262811
125414 l_acc_rev_flag               := NULL;          -- 4262811
125415 l_accrual_line_num           := NULL;          -- 4262811
125416 l_tmp_amt                    := NULL;          -- 4262811
125417 --
125418  
125419 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
125420     l_balance_type_code <> 'B' THEN
125421 IF NVL(p_source_35,'
125422 ') =  'BONUS EXPENSE'
125423  THEN 
125424 
125425    --
125426    XLA_AE_LINES_PKG.SetNewLine;
125427 
125428    p_balance_type_code          := l_balance_type_code;
125429    -- set the flag so later we will know whether the gain loss line needs to be created
125430    
125431    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
125432      p_actual_flag :='A';
125433    END IF;
125434 
125435    --
125436    -- bulk performance
125437    --
125438    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
125439                                       p_header_num   => 0); -- 4262811
125440    --
125441    -- set accounting line options
125442    --
125443    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
125444            p_natural_side_code          => 'C'
125445          , p_gain_or_loss_flag          => 'N'
125446          , p_gl_transfer_mode_code      => 'S'
125447          , p_acct_entry_type_code       => 'A'
125448          , p_switch_side_flag           => 'Y'
125449          , p_merge_duplicate_code       => 'N'
125450          );
125451    --
125452    l_acc_rev_natural_side_code := 'D';  -- 4262811
125453    -- 
125454    --
125455    -- set accounting line type info
125456    --
125457    xla_ae_lines_pkg.SetAcctLineType
125458       (p_component_type             => l_component_type
125459       ,p_event_type_code            => l_event_type_code
125460       ,p_line_definition_owner_code => l_line_definition_owner_code
125461       ,p_line_definition_code       => l_line_definition_code
125462       ,p_accounting_line_code       => l_component_code
125463       ,p_accounting_line_type_code  => l_component_type_code
125464       ,p_accounting_line_appl_id    => l_component_appl_id
125465       ,p_amb_context_code           => l_amb_context_code
125466       ,p_entity_code                => l_entity_code
125467       ,p_event_class_code           => l_event_class_code);
125468    --
125469    -- set accounting class
125470    --
125471    xla_ae_lines_pkg.SetAcctClass(
125472            p_accounting_class_code  => 'ASSET'
125473          , p_ae_header_id           => l_ae_header_id
125474          );
125475 
125476    --
125477    -- set rounding class
125478    --
125479    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
125480                       'ASSET';
125481 
125482    --
125483    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
125484    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
125485    --
125486    -- bulk performance
125487    --
125488    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
125489 
125490    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
125491       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
125492 
125493    -- 4955764
125494    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
125495       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
125496 
125497    -- 4458381 Public Sector Enh
125498    
125499    --
125500    -- set accounting attributes for the line type
125501    --
125502    l_entered_amt_idx := 4;
125503    l_accted_amt_idx  := 6;
125504    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
125505    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
125506    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
125507    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
125508    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
125509    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
125510    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
125511    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
125512    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
125513    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
125514    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
125515    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
125516    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
125517 
125518    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
125519    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
125520 
125521    ---------------------------------------------------------------------------------------------------------------
125522    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
125523    ---------------------------------------------------------------------------------------------------------------
125524    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
125525 
125526    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
125527    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
125528 
125532    AND l_bflow_method_code = 'PRIOR_ENTRY'
125529    IF xla_accounting_cache_pkg.GetValueChar
125530          (p_source_code         => 'LEDGER_CATEGORY_CODE'
125531          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
125533 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
125534    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
125535          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
125536        )
125537    THEN
125538          xla_ae_lines_pkg.BflowUpgEntry
125539            (p_business_method_code    => l_bflow_method_code
125540            ,p_business_class_code     => l_bflow_class_code
125541            ,p_balance_type            => l_balance_type_code);
125542    ELSE
125543       NULL;
125544 -- No business flow processing for business flow method of NONE.
125545    END IF;
125546 
125547    --
125548    -- call analytical criteria
125549    --
125550    
125551    --
125552    -- call description
125553    --
125554    
125555 xla_ae_lines_pkg.SetLineDescription(
125556    p_ae_header_id => l_ae_header_id
125557   ,p_description  => Description_98 (
125558      p_application_id         => p_application_id
125559    , p_ae_header_id           => l_ae_header_id 
125560 , p_source_1 => p_source_1
125561    )
125562 );
125563 
125564 
125565    --
125566    -- call ADRs
125567    -- Bug 4922099
125568    --
125569    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
125570         (NVL(l_actual_upg_option, 'N') = 'O') OR
125571         (NVL(l_enc_upg_option, 'N') = 'O')
125572       )
125573    THEN
125574    NULL;
125575    --
125576    --
125577    
125578   l_ccid := AcctDerRule_174(
125579            p_application_id           => p_application_id
125580          , p_ae_header_id             => l_ae_header_id 
125581 , p_source_3 => p_source_3
125582 , p_source_17 => p_source_17
125583 , p_source_30 => p_source_30
125584          , x_transaction_coa_id       => l_adr_transaction_coa_id
125585          , x_accounting_coa_id        => l_adr_accounting_coa_id
125586          , x_value_type_code          => l_adr_value_type_code
125587          , p_side                     => 'NA'
125588    );
125589 
125590    xla_ae_lines_pkg.set_ccid(
125591     p_code_combination_id          => l_ccid
125592   , p_value_type_code              => l_adr_value_type_code
125593   , p_transaction_coa_id           => l_adr_transaction_coa_id
125594   , p_accounting_coa_id            => l_adr_accounting_coa_id
125595   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
125596   , p_adr_type_code                => 'S'
125597   , p_component_type               => l_component_type
125598   , p_component_code               => l_component_code
125599   , p_component_type_code          => l_component_type_code
125600   , p_component_appl_id            => l_component_appl_id
125601   , p_amb_context_code             => l_amb_context_code
125602   , p_side                         => 'NA'
125603   );
125604 
125605 
125606    l_segment := AcctDerRule_144(
125607            p_application_id           => p_application_id
125608          , p_ae_header_id             => l_ae_header_id 
125609 , p_source_3 => p_source_3
125610 , p_source_4 => p_source_4
125611          , x_transaction_coa_id       => l_adr_transaction_coa_id
125612          , x_accounting_coa_id        => l_adr_accounting_coa_id
125613          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
125614          , x_flex_value_set_id        => l_adr_flex_value_set_id
125615          , x_value_type_code          => l_adr_value_type_code
125616          , x_value_combination_id     => l_adr_value_combination_id
125617          , x_value_segment_code       => l_adr_value_segment_code
125618          , p_side                     => 'NA'
125619          , p_override_seg_flag        => 'Y'
125620    );
125621 
125622    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
125623 
125624       xla_ae_lines_pkg.set_segment(
125625           p_to_segment_code         => 'GL_ACCOUNT'
125626         , p_segment_value           => l_segment
125627         , p_from_segment_code       => l_adr_value_segment_code
125628         , p_from_combination_id     => l_adr_value_combination_id
125629         , p_value_type_code         => l_adr_value_type_code
125630         , p_transaction_coa_id      => l_adr_transaction_coa_id
125631         , p_accounting_coa_id       => l_adr_accounting_coa_id
125632         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
125633         , p_flex_value_set_id       => l_adr_flex_value_set_id
125634         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
125635         , p_adr_type_code           => 'S'
125636         , p_component_type          => l_component_type
125637         , p_component_code          => l_component_code
125638         , p_component_type_code     => l_component_type_code
125639         , p_component_appl_id       => l_component_appl_id
125640         , p_amb_context_code        => l_amb_context_code
125641         , p_entity_code             => 'TRANSACTIONS'
125642         , p_event_class_code        => 'CAPITALIZATION'
125643         , p_side                    => 'NA'
125644         );
125645 
125646   END IF;
125647 
125648    l_segment := AcctDerRule_168(
125649            p_application_id           => p_application_id
125650          , p_ae_header_id             => l_ae_header_id 
125651 , p_source_3 => p_source_3
125652 , p_source_29 => p_source_29
125653          , x_transaction_coa_id       => l_adr_transaction_coa_id
125654          , x_accounting_coa_id        => l_adr_accounting_coa_id
125655          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
125656          , x_flex_value_set_id        => l_adr_flex_value_set_id
125657          , x_value_type_code          => l_adr_value_type_code
125658          , x_value_combination_id     => l_adr_value_combination_id
125659          , x_value_segment_code       => l_adr_value_segment_code
125663 
125660          , p_side                     => 'NA'
125661          , p_override_seg_flag        => 'Y'
125662    );
125664    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
125665 
125666       xla_ae_lines_pkg.set_segment(
125667           p_to_segment_code         => 'GL_BALANCING'
125668         , p_segment_value           => l_segment
125669         , p_from_segment_code       => l_adr_value_segment_code
125670         , p_from_combination_id     => l_adr_value_combination_id
125671         , p_value_type_code         => l_adr_value_type_code
125672         , p_transaction_coa_id      => l_adr_transaction_coa_id
125673         , p_accounting_coa_id       => l_adr_accounting_coa_id
125674         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
125675         , p_flex_value_set_id       => l_adr_flex_value_set_id
125676         , p_adr_code                => 'FA_EXPENSE_ACCT'
125677         , p_adr_type_code           => 'S'
125678         , p_component_type          => l_component_type
125679         , p_component_code          => l_component_code
125680         , p_component_type_code     => l_component_type_code
125681         , p_component_appl_id       => l_component_appl_id
125682         , p_amb_context_code        => l_amb_context_code
125683         , p_entity_code             => 'TRANSACTIONS'
125684         , p_event_class_code        => 'CAPITALIZATION'
125685         , p_side                    => 'NA'
125686         );
125687 
125688   END IF;
125689 
125690    --
125691    --
125692    END IF;
125693    --
125694    -- Bug 4922099
125695    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
125696           (NVL(l_enc_upg_option, 'N') = 'O')
125697         ) AND
125698         (l_bflow_method_code = 'PRIOR_ENTRY')
125699       )
125700    THEN
125701       IF
125702       --
125703       1 = 2
125704       --
125705       THEN
125706       xla_accounting_err_pkg.build_message
125707                                     (p_appli_s_name            => 'XLA'
125708                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
125709                                     ,p_token_1                 => 'LINE_NUMBER'
125710                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
125711                                     ,p_token_2                 => 'LINE_TYPE_NAME'
125712                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
125713                                                                              l_component_type
125714                                                                             ,l_component_code
125715                                                                             ,l_component_type_code
125716                                                                             ,l_component_appl_id
125717                                                                             ,l_amb_context_code
125718                                                                             ,l_entity_code
125719                                                                             ,l_event_class_code
125720                                                                            )
125721                                     ,p_token_3                 => 'OWNER'
125722                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
125723                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
125724                                                                           ,p_lookup_code    => l_component_type_code
125725                                                                          )
125726                                     ,p_token_4                 => 'PRODUCT_NAME'
125727                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
125728                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
125729                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
125730                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
125731                                     ,p_ae_header_id            =>  NULL
125732                                        );
125733 
125734         IF (C_LEVEL_ERROR>= g_log_level) THEN
125735                  trace
125736                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
125737                       ,p_level    => C_LEVEL_ERROR
125738                       ,p_module   => l_log_module);
125739         END IF;
125740       END IF;
125741    END IF;
125742    --
125743    --
125744    ------------------------------------------------------------------------------------------------
125745    -- 4219869 Business Flow
125746    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
125747    -- Prior Entry.  Currently, the following code is always generated.
125748    ------------------------------------------------------------------------------------------------
125749    XLA_AE_LINES_PKG.ValidateCurrentLine;
125750 
125751    ------------------------------------------------------------------------------------
125752    -- 4219869 Business Flow
125753    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
125754    ------------------------------------------------------------------------------------
125755    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
125756 
125757    ----------------------------------------------------------------------------------
125758    -- 4219869 Business Flow
125759    -- Update journal entry status -- Need to generate this within IF <condition>
125760    ----------------------------------------------------------------------------------
125761    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
125762          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
125763          ,p_balance_type_code => l_balance_type_code
125764          );
125768    -------------------------------------------------------------------------------------------
125765 
125766    -------------------------------------------------------------------------------------------
125767    -- 4262811 - Generate the Accrual Reversal lines
125769    BEGIN
125770       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
125771                               (g_array_event(p_event_id).array_value_num('header_index'));
125772       IF l_acc_rev_flag IS NULL THEN
125773          l_acc_rev_flag := 'N';
125774       END IF;
125775    EXCEPTION
125776       WHEN OTHERS THEN
125777          l_acc_rev_flag := 'N';
125778    END;
125779    --
125780    IF (l_acc_rev_flag = 'Y') THEN
125781 
125782        -- 4645092  ------------------------------------------------------------------------------
125783        -- To allow MPA report to determine if it should generate report process
125784        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
125785        ------------------------------------------------------------------------------------------
125786 
125787        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
125788        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
125789    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
125790    -- call ADRs
125791    -- Bug 4922099
125792    --
125793    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
125794         (NVL(l_actual_upg_option, 'N') = 'O') OR
125795         (NVL(l_enc_upg_option, 'N') = 'O')
125796       )
125797    THEN
125798    NULL;
125799    --
125800    --
125801    
125802   l_ccid := AcctDerRule_174(
125803            p_application_id           => p_application_id
125804          , p_ae_header_id             => l_ae_header_id 
125805 , p_source_3 => p_source_3
125806 , p_source_17 => p_source_17
125807 , p_source_30 => p_source_30
125808          , x_transaction_coa_id       => l_adr_transaction_coa_id
125809          , x_accounting_coa_id        => l_adr_accounting_coa_id
125810          , x_value_type_code          => l_adr_value_type_code
125811          , p_side                     => 'NA'
125812    );
125813 
125814    xla_ae_lines_pkg.set_ccid(
125815     p_code_combination_id          => l_ccid
125816   , p_value_type_code              => l_adr_value_type_code
125817   , p_transaction_coa_id           => l_adr_transaction_coa_id
125818   , p_accounting_coa_id            => l_adr_accounting_coa_id
125819   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
125820   , p_adr_type_code                => 'S'
125821   , p_component_type               => l_component_type
125822   , p_component_code               => l_component_code
125823   , p_component_type_code          => l_component_type_code
125824   , p_component_appl_id            => l_component_appl_id
125825   , p_amb_context_code             => l_amb_context_code
125826   , p_side                         => 'NA'
125827   );
125828 
125829 
125830    l_segment := AcctDerRule_144(
125831            p_application_id           => p_application_id
125832          , p_ae_header_id             => l_ae_header_id 
125833 , p_source_3 => p_source_3
125834 , p_source_4 => p_source_4
125835          , x_transaction_coa_id       => l_adr_transaction_coa_id
125836          , x_accounting_coa_id        => l_adr_accounting_coa_id
125837          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
125838          , x_flex_value_set_id        => l_adr_flex_value_set_id
125839          , x_value_type_code          => l_adr_value_type_code
125840          , x_value_combination_id     => l_adr_value_combination_id
125841          , x_value_segment_code       => l_adr_value_segment_code
125842          , p_side                     => 'NA'
125843          , p_override_seg_flag        => 'Y'
125844    );
125845 
125846    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
125847 
125848       xla_ae_lines_pkg.set_segment(
125849           p_to_segment_code         => 'GL_ACCOUNT'
125850         , p_segment_value           => l_segment
125851         , p_from_segment_code       => l_adr_value_segment_code
125852         , p_from_combination_id     => l_adr_value_combination_id
125853         , p_value_type_code         => l_adr_value_type_code
125854         , p_transaction_coa_id      => l_adr_transaction_coa_id
125855         , p_accounting_coa_id       => l_adr_accounting_coa_id
125856         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
125857         , p_flex_value_set_id       => l_adr_flex_value_set_id
125858         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
125859         , p_adr_type_code           => 'S'
125860         , p_component_type          => l_component_type
125861         , p_component_code          => l_component_code
125862         , p_component_type_code     => l_component_type_code
125863         , p_component_appl_id       => l_component_appl_id
125864         , p_amb_context_code        => l_amb_context_code
125865         , p_entity_code             => 'TRANSACTIONS'
125866         , p_event_class_code        => 'CAPITALIZATION'
125867         , p_side                    => 'NA'
125868         );
125869 
125870   END IF;
125871 
125872    l_segment := AcctDerRule_168(
125873            p_application_id           => p_application_id
125874          , p_ae_header_id             => l_ae_header_id 
125875 , p_source_3 => p_source_3
125876 , p_source_29 => p_source_29
125877          , x_transaction_coa_id       => l_adr_transaction_coa_id
125878          , x_accounting_coa_id        => l_adr_accounting_coa_id
125879          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
125880          , x_flex_value_set_id        => l_adr_flex_value_set_id
125881          , x_value_type_code          => l_adr_value_type_code
125882          , x_value_combination_id     => l_adr_value_combination_id
125883          , x_value_segment_code       => l_adr_value_segment_code
125884          , p_side                     => 'NA'
125885          , p_override_seg_flag        => 'Y'
125889 
125886    );
125887 
125888    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
125890       xla_ae_lines_pkg.set_segment(
125891           p_to_segment_code         => 'GL_BALANCING'
125892         , p_segment_value           => l_segment
125893         , p_from_segment_code       => l_adr_value_segment_code
125894         , p_from_combination_id     => l_adr_value_combination_id
125895         , p_value_type_code         => l_adr_value_type_code
125896         , p_transaction_coa_id      => l_adr_transaction_coa_id
125897         , p_accounting_coa_id       => l_adr_accounting_coa_id
125898         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
125899         , p_flex_value_set_id       => l_adr_flex_value_set_id
125900         , p_adr_code                => 'FA_EXPENSE_ACCT'
125901         , p_adr_type_code           => 'S'
125902         , p_component_type          => l_component_type
125903         , p_component_code          => l_component_code
125904         , p_component_type_code     => l_component_type_code
125905         , p_component_appl_id       => l_component_appl_id
125906         , p_amb_context_code        => l_amb_context_code
125907         , p_entity_code             => 'TRANSACTIONS'
125908         , p_event_class_code        => 'CAPITALIZATION'
125909         , p_side                    => 'NA'
125910         );
125911 
125912   END IF;
125913 
125914    --
125915    --
125916    END IF;
125917 
125918        --
125919        -- Update the line information that should be overwritten
125920        --
125921        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
125922                                          p_header_num   => 1);
125923        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
125924 
125925        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
125926 
125927        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
125928           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
125929        END IF;
125930 
125931       --
125932       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
125933       --
125934       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
125935           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
125936       ELSE
125937           ---------------------------------------------------------------------------------------------------
125938           -- 4262811a Switch Sign
125939           ---------------------------------------------------------------------------------------------------
125940           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
125941           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
125942                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
125943           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
125944                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
125945           -- 5132302
125946           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
125947                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
125948 
125949       END IF;
125950 
125951       -- 4955764
125952       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
125953       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
125954 
125955 
125956       XLA_AE_LINES_PKG.ValidateCurrentLine;
125957       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
125958 
125959       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
125960                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
125961                ,p_balance_type_code => l_balance_type_code);
125962 
125963    END IF;
125964 
125965    -----------------------------------------------------------------------------------------
125966    -- 4262811 Multiperiod Accounting
125967    -----------------------------------------------------------------------------------------
125968      -- No MPA option is assigned.
125969 
125970 
125971 END IF;
125972 END IF;
125973 --
125974 
125975 --
125976 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
125977    trace
125978       (p_msg      => 'END of AcctLineType_330'
125979       ,p_level    => C_LEVEL_PROCEDURE
125980       ,p_module   => l_log_module);
125981 END IF;
125982 --
125983 EXCEPTION
125984   WHEN xla_exceptions_pkg.application_exception THEN
125985       RAISE;
125986   WHEN OTHERS THEN
125987        xla_exceptions_pkg.raise_message
125988            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_330');
125989 END AcctLineType_330;
125990 --
125991 
125992 ---------------------------------------
125993 --
125994 -- PRIVATE FUNCTION
125995 --         AcctLineType_331
125996 --
125997 ---------------------------------------
125998 PROCEDURE AcctLineType_331 (
125999   p_application_id        IN NUMBER
126000  ,p_event_id              IN NUMBER
126001  ,p_calculate_acctd_flag  IN VARCHAR2
126002  ,p_calculate_g_l_flag    IN VARCHAR2
126003  ,p_actual_flag           IN OUT VARCHAR2
126004  ,p_balance_type_code     OUT VARCHAR2
126005  ,p_gain_or_loss_ref      OUT VARCHAR2
126006  
126007 --Period Close Date
126008  , p_source_1            IN DATE
126009 --Generated Code Combination Identifier
126010  , p_source_3            IN NUMBER
126011 --Expense Account Code Combination Identifier
126012  , p_source_29            IN NUMBER
126013 --Adjustment Type
126014  , p_source_35            IN VARCHAR2
126018  , p_source_37            IN NUMBER
126015 --Transaction Header Identifier
126016  , p_source_36            IN NUMBER
126017 --Adjustment Line Identifier
126019 --Distribution Type Code
126020  , p_source_38            IN VARCHAR2
126021 --Entered Amount
126022  , p_source_39            IN NUMBER
126023 --Currency Code
126024  , p_source_40            IN VARCHAR2
126025 )
126026 IS
126027 
126028 l_component_type              VARCHAR2(80);
126029 l_component_code              VARCHAR2(30);
126030 l_component_type_code         VARCHAR2(1);
126031 l_component_appl_id           INTEGER;
126032 l_amb_context_code            VARCHAR2(30);
126033 l_entity_code                 VARCHAR2(30);
126034 l_event_class_code            VARCHAR2(30);
126035 l_ae_header_id                NUMBER;
126036 l_event_type_code             VARCHAR2(30);
126037 l_line_definition_code        VARCHAR2(30);
126038 l_line_definition_owner_code  VARCHAR2(1);
126039 --
126040 -- adr variables
126041 l_segment                     VARCHAR2(30);
126042 l_ccid                        NUMBER;
126043 l_adr_transaction_coa_id      NUMBER;
126044 l_adr_accounting_coa_id       NUMBER;
126045 l_adr_flexfield_segment_code  VARCHAR2(30);
126046 l_adr_flex_value_set_id       NUMBER;
126047 l_adr_value_type_code         VARCHAR2(30);
126048 l_adr_value_combination_id    NUMBER;
126049 l_adr_value_segment_code      VARCHAR2(30);
126050 
126051 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
126052 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
126053 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
126054 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
126055 
126056 -- 4262811 Variables ------------------------------------------------------------------------------------------
126057 l_entered_amt_idx             NUMBER;
126058 l_accted_amt_idx              NUMBER;
126059 l_acc_rev_flag                VARCHAR2(1);
126060 l_accrual_line_num            NUMBER;
126061 l_tmp_amt                     NUMBER;
126062 l_acc_rev_natural_side_code   VARCHAR2(1);
126063 
126064 l_num_entries                 NUMBER;
126065 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
126066 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
126067 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
126068 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
126069 l_recog_line_1                NUMBER;
126070 l_recog_line_2                NUMBER;
126071 
126072 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
126073 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
126074 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
126075 
126076 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
126077 
126078 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
126079 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
126080 
126081 ---------------------------------------------------------------------------------------------------------------
126082 
126083 
126084 --
126085 -- bulk performance
126086 --
126087 l_balance_type_code           VARCHAR2(1);
126088 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
126089 l_log_module                  VARCHAR2(240);
126090 
126091 --
126092 -- Upgrade strategy
126093 --
126094 l_actual_upg_option           VARCHAR2(1);
126095 l_enc_upg_option           VARCHAR2(1);
126096 
126097 --
126098 BEGIN
126099 --
126100 IF g_log_enabled THEN
126101       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_331';
126102 END IF;
126103 --
126104 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
126105 
126106       trace
126107          (p_msg      => 'BEGIN of AcctLineType_331'
126108          ,p_level    => C_LEVEL_PROCEDURE
126109          ,p_module   => l_log_module);
126110 
126111 END IF;
126112 --
126113 l_component_type             := 'AMB_JLT';
126114 l_component_code             := 'FA_REV_EXP_BAL';
126115 l_component_type_code        := 'S';
126116 l_component_appl_id          :=  140;
126117 l_amb_context_code           := 'DEFAULT';
126118 l_entity_code                := 'TRANSACTIONS';
126119 l_event_class_code           := 'CAPITALIZATION';
126120 l_event_type_code            := 'REVERSE_CAPITALIZATION';
126121 l_line_definition_owner_code := 'S';
126122 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVER22';
126123 --
126124 l_balance_type_code          := 'A';
126125 l_segment                     := NULL;
126126 l_ccid                        := NULL;
126127 l_adr_transaction_coa_id      := NULL;
126128 l_adr_accounting_coa_id       := NULL;
126129 l_adr_flexfield_segment_code  := NULL;
126130 l_adr_flex_value_set_id       := NULL;
126131 l_adr_value_type_code         := NULL;
126132 l_adr_value_combination_id    := NULL;
126133 l_adr_value_segment_code      := NULL;
126134 
126135 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
126136 l_bflow_class_code           := '';    -- 4219869 Business Flow
126137 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
126138 l_budgetary_control_flag     := 'N';
126139 
126140 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
126141 l_bflow_applied_to_amt       := NULL; -- 5132302
126142 l_entered_amt_idx            := NULL;          -- 4262811
126143 l_accted_amt_idx             := NULL;          -- 4262811
126144 l_acc_rev_flag               := NULL;          -- 4262811
126145 l_accrual_line_num           := NULL;          -- 4262811
126146 l_tmp_amt                    := NULL;          -- 4262811
126147 --
126148  
126149 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
126150     l_balance_type_code <> 'B' THEN
126151 IF NVL(p_source_35,'
126155    --
126152 ') =  'BONUS EXPENSE'
126153  THEN 
126154 
126156    XLA_AE_LINES_PKG.SetNewLine;
126157 
126158    p_balance_type_code          := l_balance_type_code;
126159    -- set the flag so later we will know whether the gain loss line needs to be created
126160    
126161    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
126162      p_actual_flag :='A';
126163    END IF;
126164 
126165    --
126166    -- bulk performance
126167    --
126168    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
126169                                       p_header_num   => 0); -- 4262811
126170    --
126171    -- set accounting line options
126172    --
126173    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
126174            p_natural_side_code          => 'C'
126175          , p_gain_or_loss_flag          => 'N'
126176          , p_gl_transfer_mode_code      => 'S'
126177          , p_acct_entry_type_code       => 'A'
126178          , p_switch_side_flag           => 'Y'
126179          , p_merge_duplicate_code       => 'N'
126180          );
126181    --
126182    l_acc_rev_natural_side_code := 'D';  -- 4262811
126183    -- 
126184    --
126185    -- set accounting line type info
126186    --
126187    xla_ae_lines_pkg.SetAcctLineType
126188       (p_component_type             => l_component_type
126189       ,p_event_type_code            => l_event_type_code
126190       ,p_line_definition_owner_code => l_line_definition_owner_code
126191       ,p_line_definition_code       => l_line_definition_code
126192       ,p_accounting_line_code       => l_component_code
126193       ,p_accounting_line_type_code  => l_component_type_code
126194       ,p_accounting_line_appl_id    => l_component_appl_id
126195       ,p_amb_context_code           => l_amb_context_code
126196       ,p_entity_code                => l_entity_code
126197       ,p_event_class_code           => l_event_class_code);
126198    --
126199    -- set accounting class
126200    --
126201    xla_ae_lines_pkg.SetAcctClass(
126202            p_accounting_class_code  => 'EXPENSE'
126203          , p_ae_header_id           => l_ae_header_id
126204          );
126205 
126206    --
126207    -- set rounding class
126208    --
126209    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
126210                       'EXPENSE';
126211 
126212    --
126213    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
126214    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
126215    --
126216    -- bulk performance
126217    --
126218    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
126219 
126220    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
126221       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
126222 
126223    -- 4955764
126224    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
126225       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
126226 
126227    -- 4458381 Public Sector Enh
126228    
126229    --
126230    -- set accounting attributes for the line type
126231    --
126232    l_entered_amt_idx := 4;
126233    l_accted_amt_idx  := 6;
126234    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
126235    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
126236    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
126237    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
126238    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
126239    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
126240    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
126241    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
126242    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
126243    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
126244    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
126245    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
126246    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
126247 
126248    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
126249    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
126250 
126251    ---------------------------------------------------------------------------------------------------------------
126252    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
126253    ---------------------------------------------------------------------------------------------------------------
126254    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
126255 
126256    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
126257    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
126258 
126259    IF xla_accounting_cache_pkg.GetValueChar
126260          (p_source_code         => 'LEDGER_CATEGORY_CODE'
126261          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
126262    AND l_bflow_method_code = 'PRIOR_ENTRY'
126263 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
126264    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
126265          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
126266        )
126267    THEN
126268          xla_ae_lines_pkg.BflowUpgEntry
126269            (p_business_method_code    => l_bflow_method_code
126270            ,p_business_class_code     => l_bflow_class_code
126271            ,p_balance_type            => l_balance_type_code);
126272    ELSE
126273       NULL;
126274 -- No business flow processing for business flow method of NONE.
126278    -- call analytical criteria
126275    END IF;
126276 
126277    --
126279    --
126280    
126281    --
126282    -- call description
126283    --
126284    
126285 xla_ae_lines_pkg.SetLineDescription(
126286    p_ae_header_id => l_ae_header_id
126287   ,p_description  => Description_101 (
126288      p_application_id         => p_application_id
126289    , p_ae_header_id           => l_ae_header_id 
126290 , p_source_1 => p_source_1
126291    )
126292 );
126293 
126294 
126295    --
126296    -- call ADRs
126297    -- Bug 4922099
126298    --
126299    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
126300         (NVL(l_actual_upg_option, 'N') = 'O') OR
126301         (NVL(l_enc_upg_option, 'N') = 'O')
126302       )
126303    THEN
126304    NULL;
126305    --
126306    --
126307    
126308   l_ccid := AcctDerRule_175(
126309            p_application_id           => p_application_id
126310          , p_ae_header_id             => l_ae_header_id 
126311 , p_source_3 => p_source_3
126312 , p_source_29 => p_source_29
126313          , x_transaction_coa_id       => l_adr_transaction_coa_id
126314          , x_accounting_coa_id        => l_adr_accounting_coa_id
126315          , x_value_type_code          => l_adr_value_type_code
126316          , p_side                     => 'NA'
126317    );
126318 
126319    xla_ae_lines_pkg.set_ccid(
126320     p_code_combination_id          => l_ccid
126321   , p_value_type_code              => l_adr_value_type_code
126322   , p_transaction_coa_id           => l_adr_transaction_coa_id
126323   , p_accounting_coa_id            => l_adr_accounting_coa_id
126324   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
126325   , p_adr_type_code                => 'S'
126326   , p_component_type               => l_component_type
126327   , p_component_code               => l_component_code
126328   , p_component_type_code          => l_component_type_code
126329   , p_component_appl_id            => l_component_appl_id
126330   , p_amb_context_code             => l_amb_context_code
126331   , p_side                         => 'NA'
126332   );
126333 
126334 
126335    --
126336    --
126337    END IF;
126338    --
126339    -- Bug 4922099
126340    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
126341           (NVL(l_enc_upg_option, 'N') = 'O')
126342         ) AND
126343         (l_bflow_method_code = 'PRIOR_ENTRY')
126344       )
126345    THEN
126346       IF
126347       --
126348       1 = 2
126349       --
126350       THEN
126351       xla_accounting_err_pkg.build_message
126352                                     (p_appli_s_name            => 'XLA'
126353                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
126354                                     ,p_token_1                 => 'LINE_NUMBER'
126355                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
126356                                     ,p_token_2                 => 'LINE_TYPE_NAME'
126357                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
126358                                                                              l_component_type
126359                                                                             ,l_component_code
126360                                                                             ,l_component_type_code
126361                                                                             ,l_component_appl_id
126362                                                                             ,l_amb_context_code
126363                                                                             ,l_entity_code
126364                                                                             ,l_event_class_code
126365                                                                            )
126366                                     ,p_token_3                 => 'OWNER'
126367                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
126368                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
126369                                                                           ,p_lookup_code    => l_component_type_code
126370                                                                          )
126371                                     ,p_token_4                 => 'PRODUCT_NAME'
126372                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
126373                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
126374                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
126375                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
126376                                     ,p_ae_header_id            =>  NULL
126377                                        );
126378 
126379         IF (C_LEVEL_ERROR>= g_log_level) THEN
126380                  trace
126381                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
126382                       ,p_level    => C_LEVEL_ERROR
126383                       ,p_module   => l_log_module);
126384         END IF;
126385       END IF;
126386    END IF;
126387    --
126388    --
126389    ------------------------------------------------------------------------------------------------
126390    -- 4219869 Business Flow
126391    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
126392    -- Prior Entry.  Currently, the following code is always generated.
126393    ------------------------------------------------------------------------------------------------
126394    XLA_AE_LINES_PKG.ValidateCurrentLine;
126395 
126396    ------------------------------------------------------------------------------------
126397    -- 4219869 Business Flow
126401 
126398    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
126399    ------------------------------------------------------------------------------------
126400    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
126402    ----------------------------------------------------------------------------------
126403    -- 4219869 Business Flow
126404    -- Update journal entry status -- Need to generate this within IF <condition>
126405    ----------------------------------------------------------------------------------
126406    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
126407          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
126408          ,p_balance_type_code => l_balance_type_code
126409          );
126410 
126411    -------------------------------------------------------------------------------------------
126412    -- 4262811 - Generate the Accrual Reversal lines
126413    -------------------------------------------------------------------------------------------
126414    BEGIN
126415       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
126416                               (g_array_event(p_event_id).array_value_num('header_index'));
126417       IF l_acc_rev_flag IS NULL THEN
126418          l_acc_rev_flag := 'N';
126419       END IF;
126420    EXCEPTION
126421       WHEN OTHERS THEN
126422          l_acc_rev_flag := 'N';
126423    END;
126424    --
126425    IF (l_acc_rev_flag = 'Y') THEN
126426 
126427        -- 4645092  ------------------------------------------------------------------------------
126428        -- To allow MPA report to determine if it should generate report process
126429        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
126430        ------------------------------------------------------------------------------------------
126431 
126432        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
126433        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
126434    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
126435    -- call ADRs
126436    -- Bug 4922099
126437    --
126438    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
126439         (NVL(l_actual_upg_option, 'N') = 'O') OR
126440         (NVL(l_enc_upg_option, 'N') = 'O')
126441       )
126442    THEN
126443    NULL;
126444    --
126445    --
126446    
126447   l_ccid := AcctDerRule_175(
126448            p_application_id           => p_application_id
126449          , p_ae_header_id             => l_ae_header_id 
126450 , p_source_3 => p_source_3
126451 , p_source_29 => p_source_29
126452          , x_transaction_coa_id       => l_adr_transaction_coa_id
126453          , x_accounting_coa_id        => l_adr_accounting_coa_id
126454          , x_value_type_code          => l_adr_value_type_code
126455          , p_side                     => 'NA'
126456    );
126457 
126458    xla_ae_lines_pkg.set_ccid(
126459     p_code_combination_id          => l_ccid
126460   , p_value_type_code              => l_adr_value_type_code
126461   , p_transaction_coa_id           => l_adr_transaction_coa_id
126462   , p_accounting_coa_id            => l_adr_accounting_coa_id
126463   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
126464   , p_adr_type_code                => 'S'
126465   , p_component_type               => l_component_type
126466   , p_component_code               => l_component_code
126467   , p_component_type_code          => l_component_type_code
126468   , p_component_appl_id            => l_component_appl_id
126469   , p_amb_context_code             => l_amb_context_code
126470   , p_side                         => 'NA'
126471   );
126472 
126473 
126474    --
126475    --
126476    END IF;
126477 
126478        --
126479        -- Update the line information that should be overwritten
126480        --
126481        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
126482                                          p_header_num   => 1);
126483        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
126484 
126485        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
126486 
126487        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
126488           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
126489        END IF;
126490 
126491       --
126492       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
126493       --
126494       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
126495           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
126496       ELSE
126497           ---------------------------------------------------------------------------------------------------
126498           -- 4262811a Switch Sign
126499           ---------------------------------------------------------------------------------------------------
126500           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
126501           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
126502                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
126503           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
126504                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
126505           -- 5132302
126506           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
126507                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
126508 
126509       END IF;
126510 
126511       -- 4955764
126512       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
126516       XLA_AE_LINES_PKG.ValidateCurrentLine;
126513       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
126514 
126515 
126517       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
126518 
126519       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
126520                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
126521                ,p_balance_type_code => l_balance_type_code);
126522 
126523    END IF;
126524 
126525    -----------------------------------------------------------------------------------------
126526    -- 4262811 Multiperiod Accounting
126527    -----------------------------------------------------------------------------------------
126528      -- No MPA option is assigned.
126529 
126530 
126531 END IF;
126532 END IF;
126533 --
126534 
126535 --
126536 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
126537    trace
126538       (p_msg      => 'END of AcctLineType_331'
126539       ,p_level    => C_LEVEL_PROCEDURE
126540       ,p_module   => l_log_module);
126541 END IF;
126542 --
126543 EXCEPTION
126544   WHEN xla_exceptions_pkg.application_exception THEN
126545       RAISE;
126546   WHEN OTHERS THEN
126547        xla_exceptions_pkg.raise_message
126548            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_331');
126549 END AcctLineType_331;
126550 --
126551 
126552 ---------------------------------------
126553 --
126554 -- PRIVATE FUNCTION
126555 --         AcctLineType_332
126556 --
126557 ---------------------------------------
126558 PROCEDURE AcctLineType_332 (
126559   p_application_id        IN NUMBER
126560  ,p_event_id              IN NUMBER
126561  ,p_calculate_acctd_flag  IN VARCHAR2
126562  ,p_calculate_g_l_flag    IN VARCHAR2
126563  ,p_actual_flag           IN OUT VARCHAR2
126564  ,p_balance_type_code     OUT VARCHAR2
126565  ,p_gain_or_loss_ref      OUT VARCHAR2
126566  
126567 --Period Close Date
126568  , p_source_1            IN DATE
126569 --Generated Code Combination Identifier
126570  , p_source_3            IN NUMBER
126571 --Depreciation Reserve Account
126572  , p_source_10            IN VARCHAR2
126573 --Generated Offset Code Combination Identifier
126574  , p_source_17            IN NUMBER
126575 --Expense Account Code Combination Identifier
126576  , p_source_29            IN NUMBER
126577 --Default Code Combination Identifier
126578  , p_source_30            IN NUMBER
126579 --Adjustment Type
126580  , p_source_35            IN VARCHAR2
126581 --Transaction Header Identifier
126582  , p_source_36            IN NUMBER
126583 --Adjustment Line Identifier
126584  , p_source_37            IN NUMBER
126585 --Distribution Type Code
126586  , p_source_38            IN VARCHAR2
126587 --Entered Amount
126588  , p_source_39            IN NUMBER
126589 --Currency Code
126590  , p_source_40            IN VARCHAR2
126591 )
126592 IS
126593 
126594 l_component_type              VARCHAR2(80);
126595 l_component_code              VARCHAR2(30);
126596 l_component_type_code         VARCHAR2(1);
126597 l_component_appl_id           INTEGER;
126598 l_amb_context_code            VARCHAR2(30);
126599 l_entity_code                 VARCHAR2(30);
126600 l_event_class_code            VARCHAR2(30);
126601 l_ae_header_id                NUMBER;
126602 l_event_type_code             VARCHAR2(30);
126603 l_line_definition_code        VARCHAR2(30);
126604 l_line_definition_owner_code  VARCHAR2(1);
126605 --
126606 -- adr variables
126607 l_segment                     VARCHAR2(30);
126608 l_ccid                        NUMBER;
126609 l_adr_transaction_coa_id      NUMBER;
126610 l_adr_accounting_coa_id       NUMBER;
126611 l_adr_flexfield_segment_code  VARCHAR2(30);
126612 l_adr_flex_value_set_id       NUMBER;
126613 l_adr_value_type_code         VARCHAR2(30);
126614 l_adr_value_combination_id    NUMBER;
126615 l_adr_value_segment_code      VARCHAR2(30);
126616 
126617 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
126618 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
126619 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
126620 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
126621 
126622 -- 4262811 Variables ------------------------------------------------------------------------------------------
126623 l_entered_amt_idx             NUMBER;
126624 l_accted_amt_idx              NUMBER;
126625 l_acc_rev_flag                VARCHAR2(1);
126626 l_accrual_line_num            NUMBER;
126627 l_tmp_amt                     NUMBER;
126628 l_acc_rev_natural_side_code   VARCHAR2(1);
126629 
126630 l_num_entries                 NUMBER;
126631 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
126632 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
126633 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
126634 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
126635 l_recog_line_1                NUMBER;
126636 l_recog_line_2                NUMBER;
126637 
126638 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
126639 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
126640 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
126641 
126642 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
126643 
126644 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
126645 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
126646 
126647 ---------------------------------------------------------------------------------------------------------------
126648 
126649 
126650 --
126651 -- bulk performance
126652 --
126653 l_balance_type_code           VARCHAR2(1);
126657 --
126654 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
126655 l_log_module                  VARCHAR2(240);
126656 
126658 -- Upgrade strategy
126659 --
126660 l_actual_upg_option           VARCHAR2(1);
126661 l_enc_upg_option           VARCHAR2(1);
126662 
126663 --
126664 BEGIN
126665 --
126666 IF g_log_enabled THEN
126667       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_332';
126668 END IF;
126669 --
126670 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
126671 
126672       trace
126673          (p_msg      => 'BEGIN of AcctLineType_332'
126674          ,p_level    => C_LEVEL_PROCEDURE
126675          ,p_module   => l_log_module);
126676 
126677 END IF;
126678 --
126679 l_component_type             := 'AMB_JLT';
126680 l_component_code             := 'FA_REV_RESERVE';
126681 l_component_type_code        := 'S';
126682 l_component_appl_id          :=  140;
126683 l_amb_context_code           := 'DEFAULT';
126684 l_entity_code                := 'TRANSACTIONS';
126685 l_event_class_code           := 'CAPITALIZATION';
126686 l_event_type_code            := 'REVERSE_CAPITALIZATION';
126687 l_line_definition_owner_code := 'S';
126688 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVER22';
126689 --
126690 l_balance_type_code          := 'A';
126691 l_segment                     := NULL;
126692 l_ccid                        := NULL;
126693 l_adr_transaction_coa_id      := NULL;
126694 l_adr_accounting_coa_id       := NULL;
126695 l_adr_flexfield_segment_code  := NULL;
126696 l_adr_flex_value_set_id       := NULL;
126697 l_adr_value_type_code         := NULL;
126698 l_adr_value_combination_id    := NULL;
126699 l_adr_value_segment_code      := NULL;
126700 
126701 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
126702 l_bflow_class_code           := '';    -- 4219869 Business Flow
126703 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
126704 l_budgetary_control_flag     := 'N';
126705 
126706 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
126707 l_bflow_applied_to_amt       := NULL; -- 5132302
126708 l_entered_amt_idx            := NULL;          -- 4262811
126709 l_accted_amt_idx             := NULL;          -- 4262811
126710 l_acc_rev_flag               := NULL;          -- 4262811
126711 l_accrual_line_num           := NULL;          -- 4262811
126712 l_tmp_amt                    := NULL;          -- 4262811
126713 --
126714  
126715 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
126716     l_balance_type_code <> 'B' THEN
126717 IF NVL(p_source_35,'
126718 ') =  'EXPENSE'
126719  THEN 
126720 
126721    --
126722    XLA_AE_LINES_PKG.SetNewLine;
126723 
126724    p_balance_type_code          := l_balance_type_code;
126725    -- set the flag so later we will know whether the gain loss line needs to be created
126726    
126727    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
126728      p_actual_flag :='A';
126729    END IF;
126730 
126731    --
126732    -- bulk performance
126733    --
126734    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
126735                                       p_header_num   => 0); -- 4262811
126736    --
126737    -- set accounting line options
126738    --
126739    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
126740            p_natural_side_code          => 'C'
126741          , p_gain_or_loss_flag          => 'N'
126742          , p_gl_transfer_mode_code      => 'S'
126743          , p_acct_entry_type_code       => 'A'
126744          , p_switch_side_flag           => 'Y'
126745          , p_merge_duplicate_code       => 'N'
126746          );
126747    --
126748    l_acc_rev_natural_side_code := 'D';  -- 4262811
126749    -- 
126750    --
126751    -- set accounting line type info
126752    --
126753    xla_ae_lines_pkg.SetAcctLineType
126754       (p_component_type             => l_component_type
126755       ,p_event_type_code            => l_event_type_code
126756       ,p_line_definition_owner_code => l_line_definition_owner_code
126757       ,p_line_definition_code       => l_line_definition_code
126758       ,p_accounting_line_code       => l_component_code
126759       ,p_accounting_line_type_code  => l_component_type_code
126760       ,p_accounting_line_appl_id    => l_component_appl_id
126761       ,p_amb_context_code           => l_amb_context_code
126762       ,p_entity_code                => l_entity_code
126763       ,p_event_class_code           => l_event_class_code);
126764    --
126765    -- set accounting class
126766    --
126767    xla_ae_lines_pkg.SetAcctClass(
126768            p_accounting_class_code  => 'ASSET'
126769          , p_ae_header_id           => l_ae_header_id
126770          );
126771 
126772    --
126773    -- set rounding class
126774    --
126775    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
126776                       'ASSET';
126777 
126778    --
126779    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
126780    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
126781    --
126782    -- bulk performance
126783    --
126784    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
126785 
126786    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
126787       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
126788 
126789    -- 4955764
126790    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
126791       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
126792 
126793    -- 4458381 Public Sector Enh
126794    
126795    --
126796    -- set accounting attributes for the line type
126797    --
126801    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
126798    l_entered_amt_idx := 4;
126799    l_accted_amt_idx  := 6;
126800    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
126802    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
126803    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
126804    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
126805    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
126806    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
126807    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
126808    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
126809    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
126810    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
126811    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
126812    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
126813 
126814    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
126815    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
126816 
126817    ---------------------------------------------------------------------------------------------------------------
126818    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
126819    ---------------------------------------------------------------------------------------------------------------
126820    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
126821 
126822    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
126823    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
126824 
126825    IF xla_accounting_cache_pkg.GetValueChar
126826          (p_source_code         => 'LEDGER_CATEGORY_CODE'
126827          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
126828    AND l_bflow_method_code = 'PRIOR_ENTRY'
126829 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
126830    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
126831          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
126832        )
126833    THEN
126834          xla_ae_lines_pkg.BflowUpgEntry
126835            (p_business_method_code    => l_bflow_method_code
126836            ,p_business_class_code     => l_bflow_class_code
126837            ,p_balance_type            => l_balance_type_code);
126838    ELSE
126839       NULL;
126840 -- No business flow processing for business flow method of NONE.
126841    END IF;
126842 
126843    --
126844    -- call analytical criteria
126845    --
126846    
126847    --
126848    -- call description
126849    --
126850    
126851 xla_ae_lines_pkg.SetLineDescription(
126852    p_ae_header_id => l_ae_header_id
126853   ,p_description  => Description_102 (
126854      p_application_id         => p_application_id
126855    , p_ae_header_id           => l_ae_header_id 
126856 , p_source_1 => p_source_1
126857    )
126858 );
126859 
126860 
126861    --
126862    -- call ADRs
126863    -- Bug 4922099
126864    --
126865    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
126866         (NVL(l_actual_upg_option, 'N') = 'O') OR
126867         (NVL(l_enc_upg_option, 'N') = 'O')
126868       )
126869    THEN
126870    NULL;
126871    --
126872    --
126873    
126874   l_ccid := AcctDerRule_174(
126875            p_application_id           => p_application_id
126876          , p_ae_header_id             => l_ae_header_id 
126877 , p_source_3 => p_source_3
126878 , p_source_17 => p_source_17
126879 , p_source_30 => p_source_30
126880          , x_transaction_coa_id       => l_adr_transaction_coa_id
126881          , x_accounting_coa_id        => l_adr_accounting_coa_id
126882          , x_value_type_code          => l_adr_value_type_code
126883          , p_side                     => 'NA'
126884    );
126885 
126886    xla_ae_lines_pkg.set_ccid(
126887     p_code_combination_id          => l_ccid
126888   , p_value_type_code              => l_adr_value_type_code
126889   , p_transaction_coa_id           => l_adr_transaction_coa_id
126890   , p_accounting_coa_id            => l_adr_accounting_coa_id
126891   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
126892   , p_adr_type_code                => 'S'
126893   , p_component_type               => l_component_type
126894   , p_component_code               => l_component_code
126895   , p_component_type_code          => l_component_type_code
126896   , p_component_appl_id            => l_component_appl_id
126897   , p_amb_context_code             => l_amb_context_code
126898   , p_side                         => 'NA'
126899   );
126900 
126901 
126902    l_segment := AcctDerRule_149(
126903            p_application_id           => p_application_id
126904          , p_ae_header_id             => l_ae_header_id 
126905 , p_source_3 => p_source_3
126906 , p_source_10 => p_source_10
126907          , x_transaction_coa_id       => l_adr_transaction_coa_id
126908          , x_accounting_coa_id        => l_adr_accounting_coa_id
126909          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
126910          , x_flex_value_set_id        => l_adr_flex_value_set_id
126911          , x_value_type_code          => l_adr_value_type_code
126912          , x_value_combination_id     => l_adr_value_combination_id
126913          , x_value_segment_code       => l_adr_value_segment_code
126914          , p_side                     => 'NA'
126915          , p_override_seg_flag        => 'Y'
126916    );
126917 
126918    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
126919 
126920       xla_ae_lines_pkg.set_segment(
126921           p_to_segment_code         => 'GL_ACCOUNT'
126922         , p_segment_value           => l_segment
126926         , p_transaction_coa_id      => l_adr_transaction_coa_id
126923         , p_from_segment_code       => l_adr_value_segment_code
126924         , p_from_combination_id     => l_adr_value_combination_id
126925         , p_value_type_code         => l_adr_value_type_code
126927         , p_accounting_coa_id       => l_adr_accounting_coa_id
126928         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
126929         , p_flex_value_set_id       => l_adr_flex_value_set_id
126930         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
126931         , p_adr_type_code           => 'S'
126932         , p_component_type          => l_component_type
126933         , p_component_code          => l_component_code
126934         , p_component_type_code     => l_component_type_code
126935         , p_component_appl_id       => l_component_appl_id
126936         , p_amb_context_code        => l_amb_context_code
126937         , p_entity_code             => 'TRANSACTIONS'
126938         , p_event_class_code        => 'CAPITALIZATION'
126939         , p_side                    => 'NA'
126940         );
126941 
126942   END IF;
126943 
126944    l_segment := AcctDerRule_168(
126945            p_application_id           => p_application_id
126946          , p_ae_header_id             => l_ae_header_id 
126947 , p_source_3 => p_source_3
126948 , p_source_29 => p_source_29
126949          , x_transaction_coa_id       => l_adr_transaction_coa_id
126950          , x_accounting_coa_id        => l_adr_accounting_coa_id
126951          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
126952          , x_flex_value_set_id        => l_adr_flex_value_set_id
126953          , x_value_type_code          => l_adr_value_type_code
126954          , x_value_combination_id     => l_adr_value_combination_id
126955          , x_value_segment_code       => l_adr_value_segment_code
126956          , p_side                     => 'NA'
126957          , p_override_seg_flag        => 'Y'
126958    );
126959 
126960    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
126961 
126962       xla_ae_lines_pkg.set_segment(
126963           p_to_segment_code         => 'GL_BALANCING'
126964         , p_segment_value           => l_segment
126965         , p_from_segment_code       => l_adr_value_segment_code
126966         , p_from_combination_id     => l_adr_value_combination_id
126967         , p_value_type_code         => l_adr_value_type_code
126968         , p_transaction_coa_id      => l_adr_transaction_coa_id
126969         , p_accounting_coa_id       => l_adr_accounting_coa_id
126970         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
126971         , p_flex_value_set_id       => l_adr_flex_value_set_id
126972         , p_adr_code                => 'FA_EXPENSE_ACCT'
126973         , p_adr_type_code           => 'S'
126974         , p_component_type          => l_component_type
126975         , p_component_code          => l_component_code
126976         , p_component_type_code     => l_component_type_code
126977         , p_component_appl_id       => l_component_appl_id
126978         , p_amb_context_code        => l_amb_context_code
126979         , p_entity_code             => 'TRANSACTIONS'
126980         , p_event_class_code        => 'CAPITALIZATION'
126981         , p_side                    => 'NA'
126982         );
126983 
126984   END IF;
126985 
126986    --
126987    --
126988    END IF;
126989    --
126990    -- Bug 4922099
126991    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
126992           (NVL(l_enc_upg_option, 'N') = 'O')
126993         ) AND
126994         (l_bflow_method_code = 'PRIOR_ENTRY')
126995       )
126996    THEN
126997       IF
126998       --
126999       1 = 2
127000       --
127001       THEN
127002       xla_accounting_err_pkg.build_message
127003                                     (p_appli_s_name            => 'XLA'
127004                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
127005                                     ,p_token_1                 => 'LINE_NUMBER'
127006                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
127007                                     ,p_token_2                 => 'LINE_TYPE_NAME'
127008                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
127009                                                                              l_component_type
127010                                                                             ,l_component_code
127011                                                                             ,l_component_type_code
127012                                                                             ,l_component_appl_id
127013                                                                             ,l_amb_context_code
127014                                                                             ,l_entity_code
127015                                                                             ,l_event_class_code
127016                                                                            )
127017                                     ,p_token_3                 => 'OWNER'
127018                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
127019                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
127020                                                                           ,p_lookup_code    => l_component_type_code
127021                                                                          )
127022                                     ,p_token_4                 => 'PRODUCT_NAME'
127023                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
127024                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
127025                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
127029 
127026                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
127027                                     ,p_ae_header_id            =>  NULL
127028                                        );
127030         IF (C_LEVEL_ERROR>= g_log_level) THEN
127031                  trace
127032                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
127033                       ,p_level    => C_LEVEL_ERROR
127034                       ,p_module   => l_log_module);
127035         END IF;
127036       END IF;
127037    END IF;
127038    --
127039    --
127040    ------------------------------------------------------------------------------------------------
127041    -- 4219869 Business Flow
127042    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
127043    -- Prior Entry.  Currently, the following code is always generated.
127044    ------------------------------------------------------------------------------------------------
127045    XLA_AE_LINES_PKG.ValidateCurrentLine;
127046 
127047    ------------------------------------------------------------------------------------
127048    -- 4219869 Business Flow
127049    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
127050    ------------------------------------------------------------------------------------
127051    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
127052 
127053    ----------------------------------------------------------------------------------
127054    -- 4219869 Business Flow
127055    -- Update journal entry status -- Need to generate this within IF <condition>
127056    ----------------------------------------------------------------------------------
127057    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
127058          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
127059          ,p_balance_type_code => l_balance_type_code
127060          );
127061 
127062    -------------------------------------------------------------------------------------------
127063    -- 4262811 - Generate the Accrual Reversal lines
127064    -------------------------------------------------------------------------------------------
127065    BEGIN
127066       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
127067                               (g_array_event(p_event_id).array_value_num('header_index'));
127068       IF l_acc_rev_flag IS NULL THEN
127069          l_acc_rev_flag := 'N';
127070       END IF;
127071    EXCEPTION
127072       WHEN OTHERS THEN
127073          l_acc_rev_flag := 'N';
127074    END;
127075    --
127076    IF (l_acc_rev_flag = 'Y') THEN
127077 
127078        -- 4645092  ------------------------------------------------------------------------------
127079        -- To allow MPA report to determine if it should generate report process
127080        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
127081        ------------------------------------------------------------------------------------------
127082 
127083        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
127084        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
127085    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
127086    -- call ADRs
127087    -- Bug 4922099
127088    --
127089    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
127090         (NVL(l_actual_upg_option, 'N') = 'O') OR
127091         (NVL(l_enc_upg_option, 'N') = 'O')
127092       )
127093    THEN
127094    NULL;
127095    --
127096    --
127097    
127098   l_ccid := AcctDerRule_174(
127099            p_application_id           => p_application_id
127100          , p_ae_header_id             => l_ae_header_id 
127101 , p_source_3 => p_source_3
127102 , p_source_17 => p_source_17
127103 , p_source_30 => p_source_30
127104          , x_transaction_coa_id       => l_adr_transaction_coa_id
127105          , x_accounting_coa_id        => l_adr_accounting_coa_id
127106          , x_value_type_code          => l_adr_value_type_code
127107          , p_side                     => 'NA'
127108    );
127109 
127110    xla_ae_lines_pkg.set_ccid(
127111     p_code_combination_id          => l_ccid
127112   , p_value_type_code              => l_adr_value_type_code
127113   , p_transaction_coa_id           => l_adr_transaction_coa_id
127114   , p_accounting_coa_id            => l_adr_accounting_coa_id
127115   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
127116   , p_adr_type_code                => 'S'
127117   , p_component_type               => l_component_type
127118   , p_component_code               => l_component_code
127119   , p_component_type_code          => l_component_type_code
127120   , p_component_appl_id            => l_component_appl_id
127121   , p_amb_context_code             => l_amb_context_code
127122   , p_side                         => 'NA'
127123   );
127124 
127125 
127126    l_segment := AcctDerRule_149(
127127            p_application_id           => p_application_id
127128          , p_ae_header_id             => l_ae_header_id 
127129 , p_source_3 => p_source_3
127130 , p_source_10 => p_source_10
127131          , x_transaction_coa_id       => l_adr_transaction_coa_id
127132          , x_accounting_coa_id        => l_adr_accounting_coa_id
127133          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
127134          , x_flex_value_set_id        => l_adr_flex_value_set_id
127135          , x_value_type_code          => l_adr_value_type_code
127136          , x_value_combination_id     => l_adr_value_combination_id
127137          , x_value_segment_code       => l_adr_value_segment_code
127138          , p_side                     => 'NA'
127139          , p_override_seg_flag        => 'Y'
127140    );
127141 
127142    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
127143 
127144       xla_ae_lines_pkg.set_segment(
127145           p_to_segment_code         => 'GL_ACCOUNT'
127146         , p_segment_value           => l_segment
127150         , p_transaction_coa_id      => l_adr_transaction_coa_id
127147         , p_from_segment_code       => l_adr_value_segment_code
127148         , p_from_combination_id     => l_adr_value_combination_id
127149         , p_value_type_code         => l_adr_value_type_code
127151         , p_accounting_coa_id       => l_adr_accounting_coa_id
127152         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
127153         , p_flex_value_set_id       => l_adr_flex_value_set_id
127154         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
127155         , p_adr_type_code           => 'S'
127156         , p_component_type          => l_component_type
127157         , p_component_code          => l_component_code
127158         , p_component_type_code     => l_component_type_code
127159         , p_component_appl_id       => l_component_appl_id
127160         , p_amb_context_code        => l_amb_context_code
127161         , p_entity_code             => 'TRANSACTIONS'
127162         , p_event_class_code        => 'CAPITALIZATION'
127163         , p_side                    => 'NA'
127164         );
127165 
127166   END IF;
127167 
127168    l_segment := AcctDerRule_168(
127169            p_application_id           => p_application_id
127170          , p_ae_header_id             => l_ae_header_id 
127171 , p_source_3 => p_source_3
127172 , p_source_29 => p_source_29
127173          , x_transaction_coa_id       => l_adr_transaction_coa_id
127174          , x_accounting_coa_id        => l_adr_accounting_coa_id
127175          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
127176          , x_flex_value_set_id        => l_adr_flex_value_set_id
127177          , x_value_type_code          => l_adr_value_type_code
127178          , x_value_combination_id     => l_adr_value_combination_id
127179          , x_value_segment_code       => l_adr_value_segment_code
127180          , p_side                     => 'NA'
127181          , p_override_seg_flag        => 'Y'
127182    );
127183 
127184    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
127185 
127186       xla_ae_lines_pkg.set_segment(
127187           p_to_segment_code         => 'GL_BALANCING'
127188         , p_segment_value           => l_segment
127189         , p_from_segment_code       => l_adr_value_segment_code
127190         , p_from_combination_id     => l_adr_value_combination_id
127191         , p_value_type_code         => l_adr_value_type_code
127192         , p_transaction_coa_id      => l_adr_transaction_coa_id
127193         , p_accounting_coa_id       => l_adr_accounting_coa_id
127194         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
127195         , p_flex_value_set_id       => l_adr_flex_value_set_id
127196         , p_adr_code                => 'FA_EXPENSE_ACCT'
127197         , p_adr_type_code           => 'S'
127198         , p_component_type          => l_component_type
127199         , p_component_code          => l_component_code
127200         , p_component_type_code     => l_component_type_code
127201         , p_component_appl_id       => l_component_appl_id
127202         , p_amb_context_code        => l_amb_context_code
127203         , p_entity_code             => 'TRANSACTIONS'
127204         , p_event_class_code        => 'CAPITALIZATION'
127205         , p_side                    => 'NA'
127206         );
127207 
127208   END IF;
127209 
127210    --
127211    --
127212    END IF;
127213 
127214        --
127215        -- Update the line information that should be overwritten
127216        --
127217        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
127218                                          p_header_num   => 1);
127219        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
127220 
127221        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
127222 
127223        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
127224           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
127225        END IF;
127226 
127227       --
127228       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
127229       --
127230       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
127231           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
127232       ELSE
127233           ---------------------------------------------------------------------------------------------------
127234           -- 4262811a Switch Sign
127235           ---------------------------------------------------------------------------------------------------
127236           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
127237           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
127238                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
127239           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
127240                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
127241           -- 5132302
127242           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
127243                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
127244 
127245       END IF;
127246 
127247       -- 4955764
127248       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
127249       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
127250 
127251 
127252       XLA_AE_LINES_PKG.ValidateCurrentLine;
127253       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
127254 
127255       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
127256                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
127260 
127257                ,p_balance_type_code => l_balance_type_code);
127258 
127259    END IF;
127261    -----------------------------------------------------------------------------------------
127262    -- 4262811 Multiperiod Accounting
127263    -----------------------------------------------------------------------------------------
127264      -- No MPA option is assigned.
127265 
127266 
127267 END IF;
127268 END IF;
127269 --
127270 
127271 --
127272 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
127273    trace
127274       (p_msg      => 'END of AcctLineType_332'
127275       ,p_level    => C_LEVEL_PROCEDURE
127276       ,p_module   => l_log_module);
127277 END IF;
127278 --
127279 EXCEPTION
127280   WHEN xla_exceptions_pkg.application_exception THEN
127281       RAISE;
127282   WHEN OTHERS THEN
127283        xla_exceptions_pkg.raise_message
127284            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_332');
127285 END AcctLineType_332;
127286 --
127287 
127288 ---------------------------------------
127289 --
127290 -- PRIVATE FUNCTION
127291 --         AcctLineType_333
127292 --
127293 ---------------------------------------
127294 PROCEDURE AcctLineType_333 (
127295   p_application_id        IN NUMBER
127296  ,p_event_id              IN NUMBER
127297  ,p_calculate_acctd_flag  IN VARCHAR2
127298  ,p_calculate_g_l_flag    IN VARCHAR2
127299  ,p_actual_flag           IN OUT VARCHAR2
127300  ,p_balance_type_code     OUT VARCHAR2
127301  ,p_gain_or_loss_ref      OUT VARCHAR2
127302  
127303 --Period Close Date
127304  , p_source_1            IN DATE
127305 --Generated Code Combination Identifier
127306  , p_source_3            IN NUMBER
127307 --Depreciation Reserve Account
127308  , p_source_10            IN VARCHAR2
127309 --Generated Offset Code Combination Identifier
127310  , p_source_17            IN NUMBER
127311 --Expense Account Code Combination Identifier
127312  , p_source_29            IN NUMBER
127313 --Default Code Combination Identifier
127314  , p_source_30            IN NUMBER
127315 --Adjustment Type
127316  , p_source_35            IN VARCHAR2
127317 --Transaction Header Identifier
127318  , p_source_36            IN NUMBER
127319 --Adjustment Line Identifier
127320  , p_source_37            IN NUMBER
127321 --Distribution Type Code
127322  , p_source_38            IN VARCHAR2
127323 --Entered Amount
127324  , p_source_39            IN NUMBER
127325 --Currency Code
127326  , p_source_40            IN VARCHAR2
127327 )
127328 IS
127329 
127330 l_component_type              VARCHAR2(80);
127331 l_component_code              VARCHAR2(30);
127332 l_component_type_code         VARCHAR2(1);
127333 l_component_appl_id           INTEGER;
127334 l_amb_context_code            VARCHAR2(30);
127335 l_entity_code                 VARCHAR2(30);
127336 l_event_class_code            VARCHAR2(30);
127337 l_ae_header_id                NUMBER;
127338 l_event_type_code             VARCHAR2(30);
127339 l_line_definition_code        VARCHAR2(30);
127340 l_line_definition_owner_code  VARCHAR2(1);
127341 --
127342 -- adr variables
127343 l_segment                     VARCHAR2(30);
127344 l_ccid                        NUMBER;
127345 l_adr_transaction_coa_id      NUMBER;
127346 l_adr_accounting_coa_id       NUMBER;
127347 l_adr_flexfield_segment_code  VARCHAR2(30);
127348 l_adr_flex_value_set_id       NUMBER;
127349 l_adr_value_type_code         VARCHAR2(30);
127350 l_adr_value_combination_id    NUMBER;
127351 l_adr_value_segment_code      VARCHAR2(30);
127352 
127353 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
127354 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
127355 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
127356 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
127357 
127358 -- 4262811 Variables ------------------------------------------------------------------------------------------
127359 l_entered_amt_idx             NUMBER;
127360 l_accted_amt_idx              NUMBER;
127361 l_acc_rev_flag                VARCHAR2(1);
127362 l_accrual_line_num            NUMBER;
127363 l_tmp_amt                     NUMBER;
127364 l_acc_rev_natural_side_code   VARCHAR2(1);
127365 
127366 l_num_entries                 NUMBER;
127367 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
127368 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
127369 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
127370 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
127371 l_recog_line_1                NUMBER;
127372 l_recog_line_2                NUMBER;
127373 
127374 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
127375 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
127376 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
127377 
127378 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
127379 
127380 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
127381 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
127382 
127383 ---------------------------------------------------------------------------------------------------------------
127384 
127385 
127386 --
127387 -- bulk performance
127388 --
127389 l_balance_type_code           VARCHAR2(1);
127390 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
127391 l_log_module                  VARCHAR2(240);
127392 
127393 --
127394 -- Upgrade strategy
127395 --
127396 l_actual_upg_option           VARCHAR2(1);
127397 l_enc_upg_option           VARCHAR2(1);
127398 
127399 --
127400 BEGIN
127401 --
127402 IF g_log_enabled THEN
127403       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_333';
127404 END IF;
127408       trace
127405 --
127406 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
127407 
127409          (p_msg      => 'BEGIN of AcctLineType_333'
127410          ,p_level    => C_LEVEL_PROCEDURE
127411          ,p_module   => l_log_module);
127412 
127413 END IF;
127414 --
127415 l_component_type             := 'AMB_JLT';
127416 l_component_code             := 'FA_REV_RESERVE_BAL';
127417 l_component_type_code        := 'S';
127418 l_component_appl_id          :=  140;
127419 l_amb_context_code           := 'DEFAULT';
127420 l_entity_code                := 'TRANSACTIONS';
127421 l_event_class_code           := 'CAPITALIZATION';
127422 l_event_type_code            := 'REVERSE_CAPITALIZATION';
127423 l_line_definition_owner_code := 'S';
127424 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_REVER22';
127425 --
127426 l_balance_type_code          := 'A';
127427 l_segment                     := NULL;
127428 l_ccid                        := NULL;
127429 l_adr_transaction_coa_id      := NULL;
127430 l_adr_accounting_coa_id       := NULL;
127431 l_adr_flexfield_segment_code  := NULL;
127432 l_adr_flex_value_set_id       := NULL;
127433 l_adr_value_type_code         := NULL;
127434 l_adr_value_combination_id    := NULL;
127435 l_adr_value_segment_code      := NULL;
127436 
127437 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
127438 l_bflow_class_code           := '';    -- 4219869 Business Flow
127439 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
127440 l_budgetary_control_flag     := 'N';
127441 
127442 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
127443 l_bflow_applied_to_amt       := NULL; -- 5132302
127444 l_entered_amt_idx            := NULL;          -- 4262811
127445 l_accted_amt_idx             := NULL;          -- 4262811
127446 l_acc_rev_flag               := NULL;          -- 4262811
127447 l_accrual_line_num           := NULL;          -- 4262811
127448 l_tmp_amt                    := NULL;          -- 4262811
127449 --
127450  
127451 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
127452     l_balance_type_code <> 'B' THEN
127453 IF NVL(p_source_35,'
127454 ') =  'BONUS EXPENSE'
127455  THEN 
127456 
127457    --
127458    XLA_AE_LINES_PKG.SetNewLine;
127459 
127460    p_balance_type_code          := l_balance_type_code;
127461    -- set the flag so later we will know whether the gain loss line needs to be created
127462    
127463    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
127464      p_actual_flag :='A';
127465    END IF;
127466 
127467    --
127468    -- bulk performance
127469    --
127470    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
127471                                       p_header_num   => 0); -- 4262811
127472    --
127473    -- set accounting line options
127474    --
127475    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
127476            p_natural_side_code          => 'D'
127477          , p_gain_or_loss_flag          => 'N'
127478          , p_gl_transfer_mode_code      => 'S'
127479          , p_acct_entry_type_code       => 'A'
127480          , p_switch_side_flag           => 'Y'
127481          , p_merge_duplicate_code       => 'N'
127482          );
127483    --
127484    l_acc_rev_natural_side_code := 'C';  -- 4262811
127485    -- 
127486    --
127487    -- set accounting line type info
127488    --
127489    xla_ae_lines_pkg.SetAcctLineType
127490       (p_component_type             => l_component_type
127491       ,p_event_type_code            => l_event_type_code
127492       ,p_line_definition_owner_code => l_line_definition_owner_code
127493       ,p_line_definition_code       => l_line_definition_code
127494       ,p_accounting_line_code       => l_component_code
127495       ,p_accounting_line_type_code  => l_component_type_code
127496       ,p_accounting_line_appl_id    => l_component_appl_id
127497       ,p_amb_context_code           => l_amb_context_code
127498       ,p_entity_code                => l_entity_code
127499       ,p_event_class_code           => l_event_class_code);
127500    --
127501    -- set accounting class
127502    --
127503    xla_ae_lines_pkg.SetAcctClass(
127504            p_accounting_class_code  => 'ASSET'
127505          , p_ae_header_id           => l_ae_header_id
127506          );
127507 
127508    --
127509    -- set rounding class
127510    --
127511    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
127512                       'ASSET';
127513 
127514    --
127515    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
127516    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
127517    --
127518    -- bulk performance
127519    --
127520    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
127521 
127522    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
127523       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
127524 
127525    -- 4955764
127526    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
127527       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
127528 
127529    -- 4458381 Public Sector Enh
127530    
127531    --
127532    -- set accounting attributes for the line type
127533    --
127534    l_entered_amt_idx := 4;
127535    l_accted_amt_idx  := 6;
127536    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
127537    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
127538    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
127539    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
127540    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
127544    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
127541    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
127542    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
127543    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
127545    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
127546    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
127547    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
127548    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
127549 
127550    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
127551    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
127552 
127553    ---------------------------------------------------------------------------------------------------------------
127554    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
127555    ---------------------------------------------------------------------------------------------------------------
127556    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
127557 
127558    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
127559    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
127560 
127561    IF xla_accounting_cache_pkg.GetValueChar
127562          (p_source_code         => 'LEDGER_CATEGORY_CODE'
127563          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
127564    AND l_bflow_method_code = 'PRIOR_ENTRY'
127565 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
127566    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
127567          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
127568        )
127569    THEN
127570          xla_ae_lines_pkg.BflowUpgEntry
127571            (p_business_method_code    => l_bflow_method_code
127572            ,p_business_class_code     => l_bflow_class_code
127573            ,p_balance_type            => l_balance_type_code);
127574    ELSE
127575       NULL;
127576 -- No business flow processing for business flow method of NONE.
127577    END IF;
127578 
127579    --
127580    -- call analytical criteria
127581    --
127582    
127583    --
127584    -- call description
127585    --
127586    
127587 xla_ae_lines_pkg.SetLineDescription(
127588    p_ae_header_id => l_ae_header_id
127589   ,p_description  => Description_102 (
127590      p_application_id         => p_application_id
127591    , p_ae_header_id           => l_ae_header_id 
127592 , p_source_1 => p_source_1
127593    )
127594 );
127595 
127596 
127597    --
127598    -- call ADRs
127599    -- Bug 4922099
127600    --
127601    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
127602         (NVL(l_actual_upg_option, 'N') = 'O') OR
127603         (NVL(l_enc_upg_option, 'N') = 'O')
127604       )
127605    THEN
127606    NULL;
127607    --
127608    --
127609    
127610   l_ccid := AcctDerRule_174(
127611            p_application_id           => p_application_id
127612          , p_ae_header_id             => l_ae_header_id 
127613 , p_source_3 => p_source_3
127614 , p_source_17 => p_source_17
127615 , p_source_30 => p_source_30
127616          , x_transaction_coa_id       => l_adr_transaction_coa_id
127617          , x_accounting_coa_id        => l_adr_accounting_coa_id
127618          , x_value_type_code          => l_adr_value_type_code
127619          , p_side                     => 'NA'
127620    );
127621 
127622    xla_ae_lines_pkg.set_ccid(
127623     p_code_combination_id          => l_ccid
127624   , p_value_type_code              => l_adr_value_type_code
127625   , p_transaction_coa_id           => l_adr_transaction_coa_id
127626   , p_accounting_coa_id            => l_adr_accounting_coa_id
127627   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
127628   , p_adr_type_code                => 'S'
127629   , p_component_type               => l_component_type
127630   , p_component_code               => l_component_code
127631   , p_component_type_code          => l_component_type_code
127632   , p_component_appl_id            => l_component_appl_id
127633   , p_amb_context_code             => l_amb_context_code
127634   , p_side                         => 'NA'
127635   );
127636 
127637 
127638    l_segment := AcctDerRule_149(
127639            p_application_id           => p_application_id
127640          , p_ae_header_id             => l_ae_header_id 
127641 , p_source_3 => p_source_3
127642 , p_source_10 => p_source_10
127643          , x_transaction_coa_id       => l_adr_transaction_coa_id
127644          , x_accounting_coa_id        => l_adr_accounting_coa_id
127645          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
127646          , x_flex_value_set_id        => l_adr_flex_value_set_id
127647          , x_value_type_code          => l_adr_value_type_code
127648          , x_value_combination_id     => l_adr_value_combination_id
127649          , x_value_segment_code       => l_adr_value_segment_code
127650          , p_side                     => 'NA'
127651          , p_override_seg_flag        => 'Y'
127652    );
127653 
127654    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
127655 
127656       xla_ae_lines_pkg.set_segment(
127657           p_to_segment_code         => 'GL_ACCOUNT'
127658         , p_segment_value           => l_segment
127659         , p_from_segment_code       => l_adr_value_segment_code
127660         , p_from_combination_id     => l_adr_value_combination_id
127661         , p_value_type_code         => l_adr_value_type_code
127662         , p_transaction_coa_id      => l_adr_transaction_coa_id
127663         , p_accounting_coa_id       => l_adr_accounting_coa_id
127664         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
127665         , p_flex_value_set_id       => l_adr_flex_value_set_id
127669         , p_component_code          => l_component_code
127666         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
127667         , p_adr_type_code           => 'S'
127668         , p_component_type          => l_component_type
127670         , p_component_type_code     => l_component_type_code
127671         , p_component_appl_id       => l_component_appl_id
127672         , p_amb_context_code        => l_amb_context_code
127673         , p_entity_code             => 'TRANSACTIONS'
127674         , p_event_class_code        => 'CAPITALIZATION'
127675         , p_side                    => 'NA'
127676         );
127677 
127678   END IF;
127679 
127680    l_segment := AcctDerRule_168(
127681            p_application_id           => p_application_id
127682          , p_ae_header_id             => l_ae_header_id 
127683 , p_source_3 => p_source_3
127684 , p_source_29 => p_source_29
127685          , x_transaction_coa_id       => l_adr_transaction_coa_id
127686          , x_accounting_coa_id        => l_adr_accounting_coa_id
127687          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
127688          , x_flex_value_set_id        => l_adr_flex_value_set_id
127689          , x_value_type_code          => l_adr_value_type_code
127690          , x_value_combination_id     => l_adr_value_combination_id
127691          , x_value_segment_code       => l_adr_value_segment_code
127692          , p_side                     => 'NA'
127693          , p_override_seg_flag        => 'Y'
127694    );
127695 
127696    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
127697 
127698       xla_ae_lines_pkg.set_segment(
127699           p_to_segment_code         => 'GL_BALANCING'
127700         , p_segment_value           => l_segment
127701         , p_from_segment_code       => l_adr_value_segment_code
127702         , p_from_combination_id     => l_adr_value_combination_id
127703         , p_value_type_code         => l_adr_value_type_code
127704         , p_transaction_coa_id      => l_adr_transaction_coa_id
127705         , p_accounting_coa_id       => l_adr_accounting_coa_id
127706         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
127707         , p_flex_value_set_id       => l_adr_flex_value_set_id
127708         , p_adr_code                => 'FA_EXPENSE_ACCT'
127709         , p_adr_type_code           => 'S'
127710         , p_component_type          => l_component_type
127711         , p_component_code          => l_component_code
127712         , p_component_type_code     => l_component_type_code
127713         , p_component_appl_id       => l_component_appl_id
127714         , p_amb_context_code        => l_amb_context_code
127715         , p_entity_code             => 'TRANSACTIONS'
127716         , p_event_class_code        => 'CAPITALIZATION'
127717         , p_side                    => 'NA'
127718         );
127719 
127720   END IF;
127721 
127722    --
127723    --
127724    END IF;
127725    --
127726    -- Bug 4922099
127727    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
127728           (NVL(l_enc_upg_option, 'N') = 'O')
127729         ) AND
127730         (l_bflow_method_code = 'PRIOR_ENTRY')
127731       )
127732    THEN
127733       IF
127734       --
127735       1 = 2
127736       --
127737       THEN
127738       xla_accounting_err_pkg.build_message
127739                                     (p_appli_s_name            => 'XLA'
127740                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
127741                                     ,p_token_1                 => 'LINE_NUMBER'
127742                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
127743                                     ,p_token_2                 => 'LINE_TYPE_NAME'
127744                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
127745                                                                              l_component_type
127746                                                                             ,l_component_code
127747                                                                             ,l_component_type_code
127748                                                                             ,l_component_appl_id
127749                                                                             ,l_amb_context_code
127750                                                                             ,l_entity_code
127751                                                                             ,l_event_class_code
127752                                                                            )
127753                                     ,p_token_3                 => 'OWNER'
127754                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
127755                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
127756                                                                           ,p_lookup_code    => l_component_type_code
127757                                                                          )
127758                                     ,p_token_4                 => 'PRODUCT_NAME'
127759                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
127760                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
127761                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
127762                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
127763                                     ,p_ae_header_id            =>  NULL
127764                                        );
127765 
127766         IF (C_LEVEL_ERROR>= g_log_level) THEN
127767                  trace
127768                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
127769                       ,p_level    => C_LEVEL_ERROR
127770                       ,p_module   => l_log_module);
127771         END IF;
127772       END IF;
127776    ------------------------------------------------------------------------------------------------
127773    END IF;
127774    --
127775    --
127777    -- 4219869 Business Flow
127778    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
127779    -- Prior Entry.  Currently, the following code is always generated.
127780    ------------------------------------------------------------------------------------------------
127781    XLA_AE_LINES_PKG.ValidateCurrentLine;
127782 
127783    ------------------------------------------------------------------------------------
127784    -- 4219869 Business Flow
127785    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
127786    ------------------------------------------------------------------------------------
127787    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
127788 
127789    ----------------------------------------------------------------------------------
127790    -- 4219869 Business Flow
127791    -- Update journal entry status -- Need to generate this within IF <condition>
127792    ----------------------------------------------------------------------------------
127793    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
127794          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
127795          ,p_balance_type_code => l_balance_type_code
127796          );
127797 
127798    -------------------------------------------------------------------------------------------
127799    -- 4262811 - Generate the Accrual Reversal lines
127800    -------------------------------------------------------------------------------------------
127801    BEGIN
127802       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
127803                               (g_array_event(p_event_id).array_value_num('header_index'));
127804       IF l_acc_rev_flag IS NULL THEN
127805          l_acc_rev_flag := 'N';
127806       END IF;
127807    EXCEPTION
127808       WHEN OTHERS THEN
127809          l_acc_rev_flag := 'N';
127810    END;
127811    --
127812    IF (l_acc_rev_flag = 'Y') THEN
127813 
127814        -- 4645092  ------------------------------------------------------------------------------
127815        -- To allow MPA report to determine if it should generate report process
127816        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
127817        ------------------------------------------------------------------------------------------
127818 
127819        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
127820        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
127821    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
127822    -- call ADRs
127823    -- Bug 4922099
127824    --
127825    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
127826         (NVL(l_actual_upg_option, 'N') = 'O') OR
127827         (NVL(l_enc_upg_option, 'N') = 'O')
127828       )
127829    THEN
127830    NULL;
127831    --
127832    --
127833    
127834   l_ccid := AcctDerRule_174(
127835            p_application_id           => p_application_id
127836          , p_ae_header_id             => l_ae_header_id 
127837 , p_source_3 => p_source_3
127838 , p_source_17 => p_source_17
127839 , p_source_30 => p_source_30
127840          , x_transaction_coa_id       => l_adr_transaction_coa_id
127841          , x_accounting_coa_id        => l_adr_accounting_coa_id
127842          , x_value_type_code          => l_adr_value_type_code
127843          , p_side                     => 'NA'
127844    );
127845 
127846    xla_ae_lines_pkg.set_ccid(
127847     p_code_combination_id          => l_ccid
127848   , p_value_type_code              => l_adr_value_type_code
127849   , p_transaction_coa_id           => l_adr_transaction_coa_id
127850   , p_accounting_coa_id            => l_adr_accounting_coa_id
127851   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
127852   , p_adr_type_code                => 'S'
127853   , p_component_type               => l_component_type
127854   , p_component_code               => l_component_code
127855   , p_component_type_code          => l_component_type_code
127856   , p_component_appl_id            => l_component_appl_id
127857   , p_amb_context_code             => l_amb_context_code
127858   , p_side                         => 'NA'
127859   );
127860 
127861 
127862    l_segment := AcctDerRule_149(
127863            p_application_id           => p_application_id
127864          , p_ae_header_id             => l_ae_header_id 
127865 , p_source_3 => p_source_3
127866 , p_source_10 => p_source_10
127867          , x_transaction_coa_id       => l_adr_transaction_coa_id
127868          , x_accounting_coa_id        => l_adr_accounting_coa_id
127869          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
127870          , x_flex_value_set_id        => l_adr_flex_value_set_id
127871          , x_value_type_code          => l_adr_value_type_code
127872          , x_value_combination_id     => l_adr_value_combination_id
127873          , x_value_segment_code       => l_adr_value_segment_code
127874          , p_side                     => 'NA'
127875          , p_override_seg_flag        => 'Y'
127876    );
127877 
127878    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
127879 
127880       xla_ae_lines_pkg.set_segment(
127881           p_to_segment_code         => 'GL_ACCOUNT'
127882         , p_segment_value           => l_segment
127883         , p_from_segment_code       => l_adr_value_segment_code
127884         , p_from_combination_id     => l_adr_value_combination_id
127885         , p_value_type_code         => l_adr_value_type_code
127886         , p_transaction_coa_id      => l_adr_transaction_coa_id
127887         , p_accounting_coa_id       => l_adr_accounting_coa_id
127888         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
127889         , p_flex_value_set_id       => l_adr_flex_value_set_id
127890         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
127894         , p_component_type_code     => l_component_type_code
127891         , p_adr_type_code           => 'S'
127892         , p_component_type          => l_component_type
127893         , p_component_code          => l_component_code
127895         , p_component_appl_id       => l_component_appl_id
127896         , p_amb_context_code        => l_amb_context_code
127897         , p_entity_code             => 'TRANSACTIONS'
127898         , p_event_class_code        => 'CAPITALIZATION'
127899         , p_side                    => 'NA'
127900         );
127901 
127902   END IF;
127903 
127904    l_segment := AcctDerRule_168(
127905            p_application_id           => p_application_id
127906          , p_ae_header_id             => l_ae_header_id 
127907 , p_source_3 => p_source_3
127908 , p_source_29 => p_source_29
127909          , x_transaction_coa_id       => l_adr_transaction_coa_id
127910          , x_accounting_coa_id        => l_adr_accounting_coa_id
127911          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
127912          , x_flex_value_set_id        => l_adr_flex_value_set_id
127913          , x_value_type_code          => l_adr_value_type_code
127914          , x_value_combination_id     => l_adr_value_combination_id
127915          , x_value_segment_code       => l_adr_value_segment_code
127916          , p_side                     => 'NA'
127917          , p_override_seg_flag        => 'Y'
127918    );
127919 
127920    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
127921 
127922       xla_ae_lines_pkg.set_segment(
127923           p_to_segment_code         => 'GL_BALANCING'
127924         , p_segment_value           => l_segment
127925         , p_from_segment_code       => l_adr_value_segment_code
127926         , p_from_combination_id     => l_adr_value_combination_id
127927         , p_value_type_code         => l_adr_value_type_code
127928         , p_transaction_coa_id      => l_adr_transaction_coa_id
127929         , p_accounting_coa_id       => l_adr_accounting_coa_id
127930         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
127931         , p_flex_value_set_id       => l_adr_flex_value_set_id
127932         , p_adr_code                => 'FA_EXPENSE_ACCT'
127933         , p_adr_type_code           => 'S'
127934         , p_component_type          => l_component_type
127935         , p_component_code          => l_component_code
127936         , p_component_type_code     => l_component_type_code
127937         , p_component_appl_id       => l_component_appl_id
127938         , p_amb_context_code        => l_amb_context_code
127939         , p_entity_code             => 'TRANSACTIONS'
127940         , p_event_class_code        => 'CAPITALIZATION'
127941         , p_side                    => 'NA'
127942         );
127943 
127944   END IF;
127945 
127946    --
127947    --
127948    END IF;
127949 
127950        --
127951        -- Update the line information that should be overwritten
127952        --
127953        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
127954                                          p_header_num   => 1);
127955        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
127956 
127957        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
127958 
127959        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
127960           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
127961        END IF;
127962 
127963       --
127964       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
127965       --
127966       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
127967           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
127968       ELSE
127969           ---------------------------------------------------------------------------------------------------
127970           -- 4262811a Switch Sign
127971           ---------------------------------------------------------------------------------------------------
127972           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
127973           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
127974                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
127975           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
127976                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
127977           -- 5132302
127978           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
127979                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
127980 
127981       END IF;
127982 
127983       -- 4955764
127984       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
127985       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
127986 
127987 
127988       XLA_AE_LINES_PKG.ValidateCurrentLine;
127989       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
127990 
127991       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
127992                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
127993                ,p_balance_type_code => l_balance_type_code);
127994 
127995    END IF;
127996 
127997    -----------------------------------------------------------------------------------------
127998    -- 4262811 Multiperiod Accounting
127999    -----------------------------------------------------------------------------------------
128000      -- No MPA option is assigned.
128001 
128002 
128003 END IF;
128004 END IF;
128005 --
128006 
128007 --
128008 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
128012       ,p_module   => l_log_module);
128009    trace
128010       (p_msg      => 'END of AcctLineType_333'
128011       ,p_level    => C_LEVEL_PROCEDURE
128013 END IF;
128014 --
128015 EXCEPTION
128016   WHEN xla_exceptions_pkg.application_exception THEN
128017       RAISE;
128018   WHEN OTHERS THEN
128019        xla_exceptions_pkg.raise_message
128020            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_333');
128021 END AcctLineType_333;
128022 --
128023 
128024 ---------------------------------------
128025 --
128026 -- PRIVATE FUNCTION
128027 --         AcctLineType_334
128028 --
128029 ---------------------------------------
128030 PROCEDURE AcctLineType_334 (
128031   p_application_id        IN NUMBER
128032  ,p_event_id              IN NUMBER
128033  ,p_calculate_acctd_flag  IN VARCHAR2
128034  ,p_calculate_g_l_flag    IN VARCHAR2
128035  ,p_actual_flag           IN OUT VARCHAR2
128036  ,p_balance_type_code     OUT VARCHAR2
128037  ,p_gain_or_loss_ref      OUT VARCHAR2
128038  
128039 --Period Close Date
128040  , p_source_1            IN DATE
128041 --Generated Code Combination Identifier
128042  , p_source_3            IN NUMBER
128043 --Intercompany Payables Account
128044  , p_source_19            IN VARCHAR2
128045 --Expense Account Code Combination Identifier
128046  , p_source_29            IN NUMBER
128047 --Default Code Combination Identifier
128048  , p_source_30            IN NUMBER
128049 --Adjustment Type
128050  , p_source_35            IN VARCHAR2
128051 --Transaction Header Identifier
128052  , p_source_36            IN NUMBER
128053 --Adjustment Line Identifier
128054  , p_source_37            IN NUMBER
128055 --Distribution Type Code
128056  , p_source_38            IN VARCHAR2
128057 --Entered Amount
128058  , p_source_39            IN NUMBER
128059 --Currency Code
128060  , p_source_40            IN VARCHAR2
128061 )
128062 IS
128063 
128064 l_component_type              VARCHAR2(80);
128065 l_component_code              VARCHAR2(30);
128066 l_component_type_code         VARCHAR2(1);
128067 l_component_appl_id           INTEGER;
128068 l_amb_context_code            VARCHAR2(30);
128069 l_entity_code                 VARCHAR2(30);
128070 l_event_class_code            VARCHAR2(30);
128071 l_ae_header_id                NUMBER;
128072 l_event_type_code             VARCHAR2(30);
128073 l_line_definition_code        VARCHAR2(30);
128074 l_line_definition_owner_code  VARCHAR2(1);
128075 --
128076 -- adr variables
128077 l_segment                     VARCHAR2(30);
128078 l_ccid                        NUMBER;
128079 l_adr_transaction_coa_id      NUMBER;
128080 l_adr_accounting_coa_id       NUMBER;
128081 l_adr_flexfield_segment_code  VARCHAR2(30);
128082 l_adr_flex_value_set_id       NUMBER;
128083 l_adr_value_type_code         VARCHAR2(30);
128084 l_adr_value_combination_id    NUMBER;
128085 l_adr_value_segment_code      VARCHAR2(30);
128086 
128087 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
128088 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
128089 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
128090 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
128091 
128092 -- 4262811 Variables ------------------------------------------------------------------------------------------
128093 l_entered_amt_idx             NUMBER;
128094 l_accted_amt_idx              NUMBER;
128095 l_acc_rev_flag                VARCHAR2(1);
128096 l_accrual_line_num            NUMBER;
128097 l_tmp_amt                     NUMBER;
128098 l_acc_rev_natural_side_code   VARCHAR2(1);
128099 
128100 l_num_entries                 NUMBER;
128101 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
128102 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
128103 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
128104 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
128105 l_recog_line_1                NUMBER;
128106 l_recog_line_2                NUMBER;
128107 
128108 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
128109 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
128110 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
128111 
128112 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
128113 
128114 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
128115 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
128116 
128117 ---------------------------------------------------------------------------------------------------------------
128118 
128119 
128120 --
128121 -- bulk performance
128122 --
128123 l_balance_type_code           VARCHAR2(1);
128124 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
128125 l_log_module                  VARCHAR2(240);
128126 
128127 --
128128 -- Upgrade strategy
128129 --
128130 l_actual_upg_option           VARCHAR2(1);
128131 l_enc_upg_option           VARCHAR2(1);
128132 
128133 --
128134 BEGIN
128135 --
128136 IF g_log_enabled THEN
128137       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_334';
128138 END IF;
128139 --
128140 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
128141 
128142       trace
128143          (p_msg      => 'BEGIN of AcctLineType_334'
128144          ,p_level    => C_LEVEL_PROCEDURE
128145          ,p_module   => l_log_module);
128146 
128147 END IF;
128148 --
128149 l_component_type             := 'AMB_JLT';
128150 l_component_code             := 'FA_SLT_CIP_IC_PAY';
128151 l_component_type_code        := 'S';
128152 l_component_appl_id          :=  140;
128153 l_amb_context_code           := 'DEFAULT';
128154 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
128158 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_S11';
128155 l_event_class_code           := 'CIP_SOURCE_LINE_TRANSFERS';
128156 l_event_type_code            := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
128157 l_line_definition_owner_code := 'S';
128159 --
128160 l_balance_type_code          := 'A';
128161 l_segment                     := NULL;
128162 l_ccid                        := NULL;
128163 l_adr_transaction_coa_id      := NULL;
128164 l_adr_accounting_coa_id       := NULL;
128165 l_adr_flexfield_segment_code  := NULL;
128166 l_adr_flex_value_set_id       := NULL;
128167 l_adr_value_type_code         := NULL;
128168 l_adr_value_combination_id    := NULL;
128169 l_adr_value_segment_code      := NULL;
128170 
128171 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
128172 l_bflow_class_code           := '';    -- 4219869 Business Flow
128173 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
128174 l_budgetary_control_flag     := 'N';
128175 
128176 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
128177 l_bflow_applied_to_amt       := NULL; -- 5132302
128178 l_entered_amt_idx            := NULL;          -- 4262811
128179 l_accted_amt_idx             := NULL;          -- 4262811
128180 l_acc_rev_flag               := NULL;          -- 4262811
128181 l_accrual_line_num           := NULL;          -- 4262811
128182 l_tmp_amt                    := NULL;          -- 4262811
128183 --
128184  
128185 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
128186     l_balance_type_code <> 'B' THEN
128187 IF NVL(p_source_35,'
128188 ') =  'INTERCO AP'
128189  THEN 
128190 
128191    --
128192    XLA_AE_LINES_PKG.SetNewLine;
128193 
128194    p_balance_type_code          := l_balance_type_code;
128195    -- set the flag so later we will know whether the gain loss line needs to be created
128196    
128197    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
128198      p_actual_flag :='A';
128199    END IF;
128200 
128201    --
128202    -- bulk performance
128203    --
128204    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
128205                                       p_header_num   => 0); -- 4262811
128206    --
128207    -- set accounting line options
128208    --
128209    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
128210            p_natural_side_code          => 'C'
128211          , p_gain_or_loss_flag          => 'N'
128212          , p_gl_transfer_mode_code      => 'S'
128213          , p_acct_entry_type_code       => 'A'
128214          , p_switch_side_flag           => 'Y'
128215          , p_merge_duplicate_code       => 'N'
128216          );
128217    --
128218    l_acc_rev_natural_side_code := 'D';  -- 4262811
128219    -- 
128220    --
128221    -- set accounting line type info
128222    --
128223    xla_ae_lines_pkg.SetAcctLineType
128224       (p_component_type             => l_component_type
128225       ,p_event_type_code            => l_event_type_code
128226       ,p_line_definition_owner_code => l_line_definition_owner_code
128227       ,p_line_definition_code       => l_line_definition_code
128228       ,p_accounting_line_code       => l_component_code
128229       ,p_accounting_line_type_code  => l_component_type_code
128230       ,p_accounting_line_appl_id    => l_component_appl_id
128231       ,p_amb_context_code           => l_amb_context_code
128232       ,p_entity_code                => l_entity_code
128233       ,p_event_class_code           => l_event_class_code);
128234    --
128235    -- set accounting class
128236    --
128237    xla_ae_lines_pkg.SetAcctClass(
128238            p_accounting_class_code  => 'LIABILITY'
128239          , p_ae_header_id           => l_ae_header_id
128240          );
128241 
128242    --
128243    -- set rounding class
128244    --
128245    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
128246                       'LIABILITY';
128247 
128248    --
128249    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
128250    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
128251    --
128252    -- bulk performance
128253    --
128254    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
128255 
128256    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
128257       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
128258 
128259    -- 4955764
128260    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
128261       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
128262 
128263    -- 4458381 Public Sector Enh
128264    
128265    --
128266    -- set accounting attributes for the line type
128267    --
128268    l_entered_amt_idx := 4;
128269    l_accted_amt_idx  := 6;
128270    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
128271    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
128272    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
128273    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
128274    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
128275    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
128276    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
128277    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
128278    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
128279    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
128280    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
128281    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
128282    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
128283 
128284    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
128288    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
128285    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
128286 
128287    ---------------------------------------------------------------------------------------------------------------
128289    ---------------------------------------------------------------------------------------------------------------
128290    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
128291 
128292    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
128293    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
128294 
128295    IF xla_accounting_cache_pkg.GetValueChar
128296          (p_source_code         => 'LEDGER_CATEGORY_CODE'
128297          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
128298    AND l_bflow_method_code = 'PRIOR_ENTRY'
128299 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
128300    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
128301          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
128302        )
128303    THEN
128304          xla_ae_lines_pkg.BflowUpgEntry
128305            (p_business_method_code    => l_bflow_method_code
128306            ,p_business_class_code     => l_bflow_class_code
128307            ,p_balance_type            => l_balance_type_code);
128308    ELSE
128309       NULL;
128310 -- No business flow processing for business flow method of NONE.
128311    END IF;
128312 
128313    --
128314    -- call analytical criteria
128315    --
128316    
128317    --
128318    -- call description
128319    --
128320    
128321 xla_ae_lines_pkg.SetLineDescription(
128322    p_ae_header_id => l_ae_header_id
128323   ,p_description  => Description_107 (
128324      p_application_id         => p_application_id
128325    , p_ae_header_id           => l_ae_header_id 
128326 , p_source_1 => p_source_1
128327    )
128328 );
128329 
128330 
128331    --
128332    -- call ADRs
128333    -- Bug 4922099
128334    --
128335    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
128336         (NVL(l_actual_upg_option, 'N') = 'O') OR
128337         (NVL(l_enc_upg_option, 'N') = 'O')
128338       )
128339    THEN
128340    NULL;
128341    --
128342    --
128343    
128344   l_ccid := AcctDerRule_173(
128345            p_application_id           => p_application_id
128346          , p_ae_header_id             => l_ae_header_id 
128347 , p_source_3 => p_source_3
128348 , p_source_30 => p_source_30
128349          , x_transaction_coa_id       => l_adr_transaction_coa_id
128350          , x_accounting_coa_id        => l_adr_accounting_coa_id
128351          , x_value_type_code          => l_adr_value_type_code
128352          , p_side                     => 'NA'
128353    );
128354 
128355    xla_ae_lines_pkg.set_ccid(
128356     p_code_combination_id          => l_ccid
128357   , p_value_type_code              => l_adr_value_type_code
128358   , p_transaction_coa_id           => l_adr_transaction_coa_id
128359   , p_accounting_coa_id            => l_adr_accounting_coa_id
128360   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
128361   , p_adr_type_code                => 'S'
128362   , p_component_type               => l_component_type
128363   , p_component_code               => l_component_code
128364   , p_component_type_code          => l_component_type_code
128365   , p_component_appl_id            => l_component_appl_id
128366   , p_amb_context_code             => l_amb_context_code
128367   , p_side                         => 'NA'
128368   );
128369 
128370 
128371    l_segment := AcctDerRule_168(
128372            p_application_id           => p_application_id
128373          , p_ae_header_id             => l_ae_header_id 
128374 , p_source_3 => p_source_3
128375 , p_source_29 => p_source_29
128376          , x_transaction_coa_id       => l_adr_transaction_coa_id
128377          , x_accounting_coa_id        => l_adr_accounting_coa_id
128378          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
128379          , x_flex_value_set_id        => l_adr_flex_value_set_id
128380          , x_value_type_code          => l_adr_value_type_code
128381          , x_value_combination_id     => l_adr_value_combination_id
128382          , x_value_segment_code       => l_adr_value_segment_code
128383          , p_side                     => 'NA'
128384          , p_override_seg_flag        => 'Y'
128385    );
128386 
128387    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
128388 
128389       xla_ae_lines_pkg.set_segment(
128390           p_to_segment_code         => 'GL_BALANCING'
128391         , p_segment_value           => l_segment
128392         , p_from_segment_code       => l_adr_value_segment_code
128393         , p_from_combination_id     => l_adr_value_combination_id
128394         , p_value_type_code         => l_adr_value_type_code
128395         , p_transaction_coa_id      => l_adr_transaction_coa_id
128396         , p_accounting_coa_id       => l_adr_accounting_coa_id
128397         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
128398         , p_flex_value_set_id       => l_adr_flex_value_set_id
128399         , p_adr_code                => 'FA_EXPENSE_ACCT'
128400         , p_adr_type_code           => 'S'
128401         , p_component_type          => l_component_type
128402         , p_component_code          => l_component_code
128403         , p_component_type_code     => l_component_type_code
128404         , p_component_appl_id       => l_component_appl_id
128405         , p_amb_context_code        => l_amb_context_code
128406         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
128407         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
128408         , p_side                    => 'NA'
128409         );
128410 
128414            p_application_id           => p_application_id
128411   END IF;
128412 
128413    l_segment := AcctDerRule_157(
128415          , p_ae_header_id             => l_ae_header_id 
128416 , p_source_3 => p_source_3
128417 , p_source_19 => p_source_19
128418          , x_transaction_coa_id       => l_adr_transaction_coa_id
128419          , x_accounting_coa_id        => l_adr_accounting_coa_id
128420          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
128421          , x_flex_value_set_id        => l_adr_flex_value_set_id
128422          , x_value_type_code          => l_adr_value_type_code
128423          , x_value_combination_id     => l_adr_value_combination_id
128424          , x_value_segment_code       => l_adr_value_segment_code
128425          , p_side                     => 'NA'
128426          , p_override_seg_flag        => 'Y'
128427    );
128428 
128429    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
128430 
128431       xla_ae_lines_pkg.set_segment(
128432           p_to_segment_code         => 'GL_ACCOUNT'
128433         , p_segment_value           => l_segment
128434         , p_from_segment_code       => l_adr_value_segment_code
128435         , p_from_combination_id     => l_adr_value_combination_id
128436         , p_value_type_code         => l_adr_value_type_code
128437         , p_transaction_coa_id      => l_adr_transaction_coa_id
128438         , p_accounting_coa_id       => l_adr_accounting_coa_id
128439         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
128440         , p_flex_value_set_id       => l_adr_flex_value_set_id
128441         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
128442         , p_adr_type_code           => 'S'
128443         , p_component_type          => l_component_type
128444         , p_component_code          => l_component_code
128445         , p_component_type_code     => l_component_type_code
128446         , p_component_appl_id       => l_component_appl_id
128447         , p_amb_context_code        => l_amb_context_code
128448         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
128449         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
128450         , p_side                    => 'NA'
128451         );
128452 
128453   END IF;
128454 
128455    --
128456    --
128457    END IF;
128458    --
128459    -- Bug 4922099
128460    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
128461           (NVL(l_enc_upg_option, 'N') = 'O')
128462         ) AND
128463         (l_bflow_method_code = 'PRIOR_ENTRY')
128464       )
128465    THEN
128466       IF
128467       --
128468       1 = 2
128469       --
128470       THEN
128471       xla_accounting_err_pkg.build_message
128472                                     (p_appli_s_name            => 'XLA'
128473                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
128474                                     ,p_token_1                 => 'LINE_NUMBER'
128475                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
128476                                     ,p_token_2                 => 'LINE_TYPE_NAME'
128477                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
128478                                                                              l_component_type
128479                                                                             ,l_component_code
128480                                                                             ,l_component_type_code
128481                                                                             ,l_component_appl_id
128482                                                                             ,l_amb_context_code
128483                                                                             ,l_entity_code
128484                                                                             ,l_event_class_code
128485                                                                            )
128486                                     ,p_token_3                 => 'OWNER'
128487                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
128488                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
128489                                                                           ,p_lookup_code    => l_component_type_code
128490                                                                          )
128491                                     ,p_token_4                 => 'PRODUCT_NAME'
128492                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
128493                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
128494                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
128495                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
128496                                     ,p_ae_header_id            =>  NULL
128497                                        );
128498 
128499         IF (C_LEVEL_ERROR>= g_log_level) THEN
128500                  trace
128501                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
128502                       ,p_level    => C_LEVEL_ERROR
128503                       ,p_module   => l_log_module);
128504         END IF;
128505       END IF;
128506    END IF;
128507    --
128508    --
128509    ------------------------------------------------------------------------------------------------
128510    -- 4219869 Business Flow
128511    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
128512    -- Prior Entry.  Currently, the following code is always generated.
128513    ------------------------------------------------------------------------------------------------
128514    XLA_AE_LINES_PKG.ValidateCurrentLine;
128515 
128516    ------------------------------------------------------------------------------------
128520    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
128517    -- 4219869 Business Flow
128518    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
128519    ------------------------------------------------------------------------------------
128521 
128522    ----------------------------------------------------------------------------------
128523    -- 4219869 Business Flow
128524    -- Update journal entry status -- Need to generate this within IF <condition>
128525    ----------------------------------------------------------------------------------
128526    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
128527          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
128528          ,p_balance_type_code => l_balance_type_code
128529          );
128530 
128531    -------------------------------------------------------------------------------------------
128532    -- 4262811 - Generate the Accrual Reversal lines
128533    -------------------------------------------------------------------------------------------
128534    BEGIN
128535       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
128536                               (g_array_event(p_event_id).array_value_num('header_index'));
128537       IF l_acc_rev_flag IS NULL THEN
128538          l_acc_rev_flag := 'N';
128539       END IF;
128540    EXCEPTION
128541       WHEN OTHERS THEN
128542          l_acc_rev_flag := 'N';
128543    END;
128544    --
128545    IF (l_acc_rev_flag = 'Y') THEN
128546 
128547        -- 4645092  ------------------------------------------------------------------------------
128548        -- To allow MPA report to determine if it should generate report process
128549        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
128550        ------------------------------------------------------------------------------------------
128551 
128552        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
128553        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
128554    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
128555    -- call ADRs
128556    -- Bug 4922099
128557    --
128558    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
128559         (NVL(l_actual_upg_option, 'N') = 'O') OR
128560         (NVL(l_enc_upg_option, 'N') = 'O')
128561       )
128562    THEN
128563    NULL;
128564    --
128565    --
128566    
128567   l_ccid := AcctDerRule_173(
128568            p_application_id           => p_application_id
128569          , p_ae_header_id             => l_ae_header_id 
128570 , p_source_3 => p_source_3
128571 , p_source_30 => p_source_30
128572          , x_transaction_coa_id       => l_adr_transaction_coa_id
128573          , x_accounting_coa_id        => l_adr_accounting_coa_id
128574          , x_value_type_code          => l_adr_value_type_code
128575          , p_side                     => 'NA'
128576    );
128577 
128578    xla_ae_lines_pkg.set_ccid(
128579     p_code_combination_id          => l_ccid
128580   , p_value_type_code              => l_adr_value_type_code
128581   , p_transaction_coa_id           => l_adr_transaction_coa_id
128582   , p_accounting_coa_id            => l_adr_accounting_coa_id
128583   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
128584   , p_adr_type_code                => 'S'
128585   , p_component_type               => l_component_type
128586   , p_component_code               => l_component_code
128587   , p_component_type_code          => l_component_type_code
128588   , p_component_appl_id            => l_component_appl_id
128589   , p_amb_context_code             => l_amb_context_code
128590   , p_side                         => 'NA'
128591   );
128592 
128593 
128594    l_segment := AcctDerRule_168(
128595            p_application_id           => p_application_id
128596          , p_ae_header_id             => l_ae_header_id 
128597 , p_source_3 => p_source_3
128598 , p_source_29 => p_source_29
128599          , x_transaction_coa_id       => l_adr_transaction_coa_id
128600          , x_accounting_coa_id        => l_adr_accounting_coa_id
128601          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
128602          , x_flex_value_set_id        => l_adr_flex_value_set_id
128603          , x_value_type_code          => l_adr_value_type_code
128604          , x_value_combination_id     => l_adr_value_combination_id
128605          , x_value_segment_code       => l_adr_value_segment_code
128606          , p_side                     => 'NA'
128607          , p_override_seg_flag        => 'Y'
128608    );
128609 
128610    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
128611 
128612       xla_ae_lines_pkg.set_segment(
128613           p_to_segment_code         => 'GL_BALANCING'
128614         , p_segment_value           => l_segment
128615         , p_from_segment_code       => l_adr_value_segment_code
128616         , p_from_combination_id     => l_adr_value_combination_id
128617         , p_value_type_code         => l_adr_value_type_code
128618         , p_transaction_coa_id      => l_adr_transaction_coa_id
128619         , p_accounting_coa_id       => l_adr_accounting_coa_id
128620         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
128621         , p_flex_value_set_id       => l_adr_flex_value_set_id
128622         , p_adr_code                => 'FA_EXPENSE_ACCT'
128623         , p_adr_type_code           => 'S'
128624         , p_component_type          => l_component_type
128625         , p_component_code          => l_component_code
128626         , p_component_type_code     => l_component_type_code
128627         , p_component_appl_id       => l_component_appl_id
128628         , p_amb_context_code        => l_amb_context_code
128629         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
128630         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
128631         , p_side                    => 'NA'
128632         );
128633 
128634   END IF;
128635 
128636    l_segment := AcctDerRule_157(
128640 , p_source_19 => p_source_19
128637            p_application_id           => p_application_id
128638          , p_ae_header_id             => l_ae_header_id 
128639 , p_source_3 => p_source_3
128641          , x_transaction_coa_id       => l_adr_transaction_coa_id
128642          , x_accounting_coa_id        => l_adr_accounting_coa_id
128643          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
128644          , x_flex_value_set_id        => l_adr_flex_value_set_id
128645          , x_value_type_code          => l_adr_value_type_code
128646          , x_value_combination_id     => l_adr_value_combination_id
128647          , x_value_segment_code       => l_adr_value_segment_code
128648          , p_side                     => 'NA'
128649          , p_override_seg_flag        => 'Y'
128650    );
128651 
128652    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
128653 
128654       xla_ae_lines_pkg.set_segment(
128655           p_to_segment_code         => 'GL_ACCOUNT'
128656         , p_segment_value           => l_segment
128657         , p_from_segment_code       => l_adr_value_segment_code
128658         , p_from_combination_id     => l_adr_value_combination_id
128659         , p_value_type_code         => l_adr_value_type_code
128660         , p_transaction_coa_id      => l_adr_transaction_coa_id
128661         , p_accounting_coa_id       => l_adr_accounting_coa_id
128662         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
128663         , p_flex_value_set_id       => l_adr_flex_value_set_id
128664         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
128665         , p_adr_type_code           => 'S'
128666         , p_component_type          => l_component_type
128667         , p_component_code          => l_component_code
128668         , p_component_type_code     => l_component_type_code
128669         , p_component_appl_id       => l_component_appl_id
128670         , p_amb_context_code        => l_amb_context_code
128671         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
128672         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
128673         , p_side                    => 'NA'
128674         );
128675 
128676   END IF;
128677 
128678    --
128679    --
128680    END IF;
128681 
128682        --
128683        -- Update the line information that should be overwritten
128684        --
128685        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
128686                                          p_header_num   => 1);
128687        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
128688 
128689        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
128690 
128691        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
128692           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
128693        END IF;
128694 
128695       --
128696       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
128697       --
128698       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
128699           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
128700       ELSE
128701           ---------------------------------------------------------------------------------------------------
128702           -- 4262811a Switch Sign
128703           ---------------------------------------------------------------------------------------------------
128704           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
128705           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
128706                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
128707           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
128708                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
128709           -- 5132302
128710           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
128711                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
128712 
128713       END IF;
128714 
128715       -- 4955764
128716       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
128717       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
128718 
128719 
128720       XLA_AE_LINES_PKG.ValidateCurrentLine;
128721       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
128722 
128723       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
128724                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
128725                ,p_balance_type_code => l_balance_type_code);
128726 
128727    END IF;
128728 
128729    -----------------------------------------------------------------------------------------
128730    -- 4262811 Multiperiod Accounting
128731    -----------------------------------------------------------------------------------------
128732      -- No MPA option is assigned.
128733 
128734 
128735 END IF;
128736 END IF;
128737 --
128738 
128739 --
128740 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
128741    trace
128742       (p_msg      => 'END of AcctLineType_334'
128743       ,p_level    => C_LEVEL_PROCEDURE
128744       ,p_module   => l_log_module);
128745 END IF;
128746 --
128747 EXCEPTION
128748   WHEN xla_exceptions_pkg.application_exception THEN
128749       RAISE;
128750   WHEN OTHERS THEN
128751        xla_exceptions_pkg.raise_message
128752            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_334');
128753 END AcctLineType_334;
128754 --
128755 
128756 ---------------------------------------
128757 --
128758 -- PRIVATE FUNCTION
128762 PROCEDURE AcctLineType_335 (
128759 --         AcctLineType_335
128760 --
128761 ---------------------------------------
128763   p_application_id        IN NUMBER
128764  ,p_event_id              IN NUMBER
128765  ,p_calculate_acctd_flag  IN VARCHAR2
128766  ,p_calculate_g_l_flag    IN VARCHAR2
128767  ,p_actual_flag           IN OUT VARCHAR2
128768  ,p_balance_type_code     OUT VARCHAR2
128769  ,p_gain_or_loss_ref      OUT VARCHAR2
128770  
128771 --Period Close Date
128772  , p_source_1            IN DATE
128773 --Generated Code Combination Identifier
128774  , p_source_3            IN NUMBER
128775 --Intercompany Receivables Account
128776  , p_source_20            IN VARCHAR2
128777 --Expense Account Code Combination Identifier
128778  , p_source_29            IN NUMBER
128779 --Default Code Combination Identifier
128780  , p_source_30            IN NUMBER
128781 --Adjustment Type
128782  , p_source_35            IN VARCHAR2
128783 --Transaction Header Identifier
128784  , p_source_36            IN NUMBER
128785 --Adjustment Line Identifier
128786  , p_source_37            IN NUMBER
128787 --Distribution Type Code
128788  , p_source_38            IN VARCHAR2
128789 --Entered Amount
128790  , p_source_39            IN NUMBER
128791 --Currency Code
128792  , p_source_40            IN VARCHAR2
128793 )
128794 IS
128795 
128796 l_component_type              VARCHAR2(80);
128797 l_component_code              VARCHAR2(30);
128798 l_component_type_code         VARCHAR2(1);
128799 l_component_appl_id           INTEGER;
128800 l_amb_context_code            VARCHAR2(30);
128801 l_entity_code                 VARCHAR2(30);
128802 l_event_class_code            VARCHAR2(30);
128803 l_ae_header_id                NUMBER;
128804 l_event_type_code             VARCHAR2(30);
128805 l_line_definition_code        VARCHAR2(30);
128806 l_line_definition_owner_code  VARCHAR2(1);
128807 --
128808 -- adr variables
128809 l_segment                     VARCHAR2(30);
128810 l_ccid                        NUMBER;
128811 l_adr_transaction_coa_id      NUMBER;
128812 l_adr_accounting_coa_id       NUMBER;
128813 l_adr_flexfield_segment_code  VARCHAR2(30);
128814 l_adr_flex_value_set_id       NUMBER;
128815 l_adr_value_type_code         VARCHAR2(30);
128816 l_adr_value_combination_id    NUMBER;
128817 l_adr_value_segment_code      VARCHAR2(30);
128818 
128819 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
128820 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
128821 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
128822 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
128823 
128824 -- 4262811 Variables ------------------------------------------------------------------------------------------
128825 l_entered_amt_idx             NUMBER;
128826 l_accted_amt_idx              NUMBER;
128827 l_acc_rev_flag                VARCHAR2(1);
128828 l_accrual_line_num            NUMBER;
128829 l_tmp_amt                     NUMBER;
128830 l_acc_rev_natural_side_code   VARCHAR2(1);
128831 
128832 l_num_entries                 NUMBER;
128833 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
128834 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
128835 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
128836 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
128837 l_recog_line_1                NUMBER;
128838 l_recog_line_2                NUMBER;
128839 
128840 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
128841 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
128842 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
128843 
128844 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
128845 
128846 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
128847 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
128848 
128849 ---------------------------------------------------------------------------------------------------------------
128850 
128851 
128852 --
128853 -- bulk performance
128854 --
128855 l_balance_type_code           VARCHAR2(1);
128856 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
128857 l_log_module                  VARCHAR2(240);
128858 
128859 --
128860 -- Upgrade strategy
128861 --
128862 l_actual_upg_option           VARCHAR2(1);
128863 l_enc_upg_option           VARCHAR2(1);
128864 
128865 --
128866 BEGIN
128867 --
128868 IF g_log_enabled THEN
128869       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_335';
128870 END IF;
128871 --
128872 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
128873 
128874       trace
128875          (p_msg      => 'BEGIN of AcctLineType_335'
128876          ,p_level    => C_LEVEL_PROCEDURE
128877          ,p_module   => l_log_module);
128878 
128879 END IF;
128880 --
128881 l_component_type             := 'AMB_JLT';
128882 l_component_code             := 'FA_SLT_CIP_IC_REC';
128883 l_component_type_code        := 'S';
128884 l_component_appl_id          :=  140;
128885 l_amb_context_code           := 'DEFAULT';
128886 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
128887 l_event_class_code           := 'CIP_SOURCE_LINE_TRANSFERS';
128888 l_event_type_code            := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
128889 l_line_definition_owner_code := 'S';
128890 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_S11';
128891 --
128892 l_balance_type_code          := 'A';
128893 l_segment                     := NULL;
128894 l_ccid                        := NULL;
128895 l_adr_transaction_coa_id      := NULL;
128896 l_adr_accounting_coa_id       := NULL;
128897 l_adr_flexfield_segment_code  := NULL;
128898 l_adr_flex_value_set_id       := NULL;
128899 l_adr_value_type_code         := NULL;
128903 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
128900 l_adr_value_combination_id    := NULL;
128901 l_adr_value_segment_code      := NULL;
128902 
128904 l_bflow_class_code           := '';    -- 4219869 Business Flow
128905 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
128906 l_budgetary_control_flag     := 'N';
128907 
128908 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
128909 l_bflow_applied_to_amt       := NULL; -- 5132302
128910 l_entered_amt_idx            := NULL;          -- 4262811
128911 l_accted_amt_idx             := NULL;          -- 4262811
128912 l_acc_rev_flag               := NULL;          -- 4262811
128913 l_accrual_line_num           := NULL;          -- 4262811
128914 l_tmp_amt                    := NULL;          -- 4262811
128915 --
128916  
128917 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
128918     l_balance_type_code <> 'B' THEN
128919 IF NVL(p_source_35,'
128920 ') =  'INTERCO AR'
128921  THEN 
128922 
128923    --
128924    XLA_AE_LINES_PKG.SetNewLine;
128925 
128926    p_balance_type_code          := l_balance_type_code;
128927    -- set the flag so later we will know whether the gain loss line needs to be created
128928    
128929    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
128930      p_actual_flag :='A';
128931    END IF;
128932 
128933    --
128934    -- bulk performance
128935    --
128936    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
128937                                       p_header_num   => 0); -- 4262811
128938    --
128939    -- set accounting line options
128940    --
128941    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
128942            p_natural_side_code          => 'D'
128943          , p_gain_or_loss_flag          => 'N'
128944          , p_gl_transfer_mode_code      => 'S'
128945          , p_acct_entry_type_code       => 'A'
128946          , p_switch_side_flag           => 'Y'
128947          , p_merge_duplicate_code       => 'N'
128948          );
128949    --
128950    l_acc_rev_natural_side_code := 'C';  -- 4262811
128951    -- 
128952    --
128953    -- set accounting line type info
128954    --
128955    xla_ae_lines_pkg.SetAcctLineType
128956       (p_component_type             => l_component_type
128957       ,p_event_type_code            => l_event_type_code
128958       ,p_line_definition_owner_code => l_line_definition_owner_code
128959       ,p_line_definition_code       => l_line_definition_code
128960       ,p_accounting_line_code       => l_component_code
128961       ,p_accounting_line_type_code  => l_component_type_code
128962       ,p_accounting_line_appl_id    => l_component_appl_id
128963       ,p_amb_context_code           => l_amb_context_code
128964       ,p_entity_code                => l_entity_code
128965       ,p_event_class_code           => l_event_class_code);
128966    --
128967    -- set accounting class
128968    --
128969    xla_ae_lines_pkg.SetAcctClass(
128970            p_accounting_class_code  => 'ASSET'
128971          , p_ae_header_id           => l_ae_header_id
128972          );
128973 
128974    --
128975    -- set rounding class
128976    --
128977    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
128978                       'ASSET';
128979 
128980    --
128981    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
128982    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
128983    --
128984    -- bulk performance
128985    --
128986    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
128987 
128988    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
128989       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
128990 
128991    -- 4955764
128992    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
128993       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
128994 
128995    -- 4458381 Public Sector Enh
128996    
128997    --
128998    -- set accounting attributes for the line type
128999    --
129000    l_entered_amt_idx := 4;
129001    l_accted_amt_idx  := 6;
129002    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
129003    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
129004    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
129005    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
129006    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
129007    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
129008    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
129009    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
129010    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
129011    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
129012    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
129013    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
129014    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
129015 
129016    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
129017    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
129018 
129019    ---------------------------------------------------------------------------------------------------------------
129020    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
129021    ---------------------------------------------------------------------------------------------------------------
129022    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
129023 
129027    IF xla_accounting_cache_pkg.GetValueChar
129024    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
129025    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
129026 
129028          (p_source_code         => 'LEDGER_CATEGORY_CODE'
129029          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
129030    AND l_bflow_method_code = 'PRIOR_ENTRY'
129031 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
129032    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
129033          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
129034        )
129035    THEN
129036          xla_ae_lines_pkg.BflowUpgEntry
129037            (p_business_method_code    => l_bflow_method_code
129038            ,p_business_class_code     => l_bflow_class_code
129039            ,p_balance_type            => l_balance_type_code);
129040    ELSE
129041       NULL;
129042 -- No business flow processing for business flow method of NONE.
129043    END IF;
129044 
129045    --
129046    -- call analytical criteria
129047    --
129048    
129049    --
129050    -- call description
129051    --
129052    
129053 xla_ae_lines_pkg.SetLineDescription(
129054    p_ae_header_id => l_ae_header_id
129055   ,p_description  => Description_108 (
129056      p_application_id         => p_application_id
129057    , p_ae_header_id           => l_ae_header_id 
129058 , p_source_1 => p_source_1
129059    )
129060 );
129061 
129062 
129063    --
129064    -- call ADRs
129065    -- Bug 4922099
129066    --
129067    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
129068         (NVL(l_actual_upg_option, 'N') = 'O') OR
129069         (NVL(l_enc_upg_option, 'N') = 'O')
129070       )
129071    THEN
129072    NULL;
129073    --
129074    --
129075    
129076   l_ccid := AcctDerRule_173(
129077            p_application_id           => p_application_id
129078          , p_ae_header_id             => l_ae_header_id 
129079 , p_source_3 => p_source_3
129080 , p_source_30 => p_source_30
129081          , x_transaction_coa_id       => l_adr_transaction_coa_id
129082          , x_accounting_coa_id        => l_adr_accounting_coa_id
129083          , x_value_type_code          => l_adr_value_type_code
129084          , p_side                     => 'NA'
129085    );
129086 
129087    xla_ae_lines_pkg.set_ccid(
129088     p_code_combination_id          => l_ccid
129089   , p_value_type_code              => l_adr_value_type_code
129090   , p_transaction_coa_id           => l_adr_transaction_coa_id
129091   , p_accounting_coa_id            => l_adr_accounting_coa_id
129092   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
129093   , p_adr_type_code                => 'S'
129094   , p_component_type               => l_component_type
129095   , p_component_code               => l_component_code
129096   , p_component_type_code          => l_component_type_code
129097   , p_component_appl_id            => l_component_appl_id
129098   , p_amb_context_code             => l_amb_context_code
129099   , p_side                         => 'NA'
129100   );
129101 
129102 
129103    l_segment := AcctDerRule_168(
129104            p_application_id           => p_application_id
129105          , p_ae_header_id             => l_ae_header_id 
129106 , p_source_3 => p_source_3
129107 , p_source_29 => p_source_29
129108          , x_transaction_coa_id       => l_adr_transaction_coa_id
129109          , x_accounting_coa_id        => l_adr_accounting_coa_id
129110          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
129111          , x_flex_value_set_id        => l_adr_flex_value_set_id
129112          , x_value_type_code          => l_adr_value_type_code
129113          , x_value_combination_id     => l_adr_value_combination_id
129114          , x_value_segment_code       => l_adr_value_segment_code
129115          , p_side                     => 'NA'
129116          , p_override_seg_flag        => 'Y'
129117    );
129118 
129119    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
129120 
129121       xla_ae_lines_pkg.set_segment(
129122           p_to_segment_code         => 'GL_BALANCING'
129123         , p_segment_value           => l_segment
129124         , p_from_segment_code       => l_adr_value_segment_code
129125         , p_from_combination_id     => l_adr_value_combination_id
129126         , p_value_type_code         => l_adr_value_type_code
129127         , p_transaction_coa_id      => l_adr_transaction_coa_id
129128         , p_accounting_coa_id       => l_adr_accounting_coa_id
129129         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
129130         , p_flex_value_set_id       => l_adr_flex_value_set_id
129131         , p_adr_code                => 'FA_EXPENSE_ACCT'
129132         , p_adr_type_code           => 'S'
129133         , p_component_type          => l_component_type
129134         , p_component_code          => l_component_code
129135         , p_component_type_code     => l_component_type_code
129136         , p_component_appl_id       => l_component_appl_id
129137         , p_amb_context_code        => l_amb_context_code
129138         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
129139         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
129140         , p_side                    => 'NA'
129141         );
129142 
129143   END IF;
129144 
129145    l_segment := AcctDerRule_158(
129146            p_application_id           => p_application_id
129147          , p_ae_header_id             => l_ae_header_id 
129148 , p_source_3 => p_source_3
129149 , p_source_20 => p_source_20
129150          , x_transaction_coa_id       => l_adr_transaction_coa_id
129151          , x_accounting_coa_id        => l_adr_accounting_coa_id
129152          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
129153          , x_flex_value_set_id        => l_adr_flex_value_set_id
129157          , p_side                     => 'NA'
129154          , x_value_type_code          => l_adr_value_type_code
129155          , x_value_combination_id     => l_adr_value_combination_id
129156          , x_value_segment_code       => l_adr_value_segment_code
129158          , p_override_seg_flag        => 'Y'
129159    );
129160 
129161    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
129162 
129163       xla_ae_lines_pkg.set_segment(
129164           p_to_segment_code         => 'GL_ACCOUNT'
129165         , p_segment_value           => l_segment
129166         , p_from_segment_code       => l_adr_value_segment_code
129167         , p_from_combination_id     => l_adr_value_combination_id
129168         , p_value_type_code         => l_adr_value_type_code
129169         , p_transaction_coa_id      => l_adr_transaction_coa_id
129170         , p_accounting_coa_id       => l_adr_accounting_coa_id
129171         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
129172         , p_flex_value_set_id       => l_adr_flex_value_set_id
129173         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
129174         , p_adr_type_code           => 'S'
129175         , p_component_type          => l_component_type
129176         , p_component_code          => l_component_code
129177         , p_component_type_code     => l_component_type_code
129178         , p_component_appl_id       => l_component_appl_id
129179         , p_amb_context_code        => l_amb_context_code
129180         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
129181         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
129182         , p_side                    => 'NA'
129183         );
129184 
129185   END IF;
129186 
129187    --
129188    --
129189    END IF;
129190    --
129191    -- Bug 4922099
129192    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
129193           (NVL(l_enc_upg_option, 'N') = 'O')
129194         ) AND
129195         (l_bflow_method_code = 'PRIOR_ENTRY')
129196       )
129197    THEN
129198       IF
129199       --
129200       1 = 2
129201       --
129202       THEN
129203       xla_accounting_err_pkg.build_message
129204                                     (p_appli_s_name            => 'XLA'
129205                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
129206                                     ,p_token_1                 => 'LINE_NUMBER'
129207                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
129208                                     ,p_token_2                 => 'LINE_TYPE_NAME'
129209                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
129210                                                                              l_component_type
129211                                                                             ,l_component_code
129212                                                                             ,l_component_type_code
129213                                                                             ,l_component_appl_id
129214                                                                             ,l_amb_context_code
129215                                                                             ,l_entity_code
129216                                                                             ,l_event_class_code
129217                                                                            )
129218                                     ,p_token_3                 => 'OWNER'
129219                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
129220                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
129221                                                                           ,p_lookup_code    => l_component_type_code
129222                                                                          )
129223                                     ,p_token_4                 => 'PRODUCT_NAME'
129224                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
129225                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
129226                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
129227                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
129228                                     ,p_ae_header_id            =>  NULL
129229                                        );
129230 
129231         IF (C_LEVEL_ERROR>= g_log_level) THEN
129232                  trace
129233                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
129234                       ,p_level    => C_LEVEL_ERROR
129235                       ,p_module   => l_log_module);
129236         END IF;
129237       END IF;
129238    END IF;
129239    --
129240    --
129241    ------------------------------------------------------------------------------------------------
129242    -- 4219869 Business Flow
129243    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
129244    -- Prior Entry.  Currently, the following code is always generated.
129245    ------------------------------------------------------------------------------------------------
129246    XLA_AE_LINES_PKG.ValidateCurrentLine;
129247 
129248    ------------------------------------------------------------------------------------
129249    -- 4219869 Business Flow
129250    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
129251    ------------------------------------------------------------------------------------
129252    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
129253 
129254    ----------------------------------------------------------------------------------
129255    -- 4219869 Business Flow
129256    -- Update journal entry status -- Need to generate this within IF <condition>
129260          ,p_balance_type_code => l_balance_type_code
129257    ----------------------------------------------------------------------------------
129258    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
129259          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
129261          );
129262 
129263    -------------------------------------------------------------------------------------------
129264    -- 4262811 - Generate the Accrual Reversal lines
129265    -------------------------------------------------------------------------------------------
129266    BEGIN
129267       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
129268                               (g_array_event(p_event_id).array_value_num('header_index'));
129269       IF l_acc_rev_flag IS NULL THEN
129270          l_acc_rev_flag := 'N';
129271       END IF;
129272    EXCEPTION
129273       WHEN OTHERS THEN
129274          l_acc_rev_flag := 'N';
129275    END;
129276    --
129277    IF (l_acc_rev_flag = 'Y') THEN
129278 
129279        -- 4645092  ------------------------------------------------------------------------------
129280        -- To allow MPA report to determine if it should generate report process
129281        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
129282        ------------------------------------------------------------------------------------------
129283 
129284        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
129285        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
129286    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
129287    -- call ADRs
129288    -- Bug 4922099
129289    --
129290    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
129291         (NVL(l_actual_upg_option, 'N') = 'O') OR
129292         (NVL(l_enc_upg_option, 'N') = 'O')
129293       )
129294    THEN
129295    NULL;
129296    --
129297    --
129298    
129299   l_ccid := AcctDerRule_173(
129300            p_application_id           => p_application_id
129301          , p_ae_header_id             => l_ae_header_id 
129302 , p_source_3 => p_source_3
129303 , p_source_30 => p_source_30
129304          , x_transaction_coa_id       => l_adr_transaction_coa_id
129305          , x_accounting_coa_id        => l_adr_accounting_coa_id
129306          , x_value_type_code          => l_adr_value_type_code
129307          , p_side                     => 'NA'
129308    );
129309 
129310    xla_ae_lines_pkg.set_ccid(
129311     p_code_combination_id          => l_ccid
129312   , p_value_type_code              => l_adr_value_type_code
129313   , p_transaction_coa_id           => l_adr_transaction_coa_id
129314   , p_accounting_coa_id            => l_adr_accounting_coa_id
129315   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
129316   , p_adr_type_code                => 'S'
129317   , p_component_type               => l_component_type
129318   , p_component_code               => l_component_code
129319   , p_component_type_code          => l_component_type_code
129320   , p_component_appl_id            => l_component_appl_id
129321   , p_amb_context_code             => l_amb_context_code
129322   , p_side                         => 'NA'
129323   );
129324 
129325 
129326    l_segment := AcctDerRule_168(
129327            p_application_id           => p_application_id
129328          , p_ae_header_id             => l_ae_header_id 
129329 , p_source_3 => p_source_3
129330 , p_source_29 => p_source_29
129331          , x_transaction_coa_id       => l_adr_transaction_coa_id
129332          , x_accounting_coa_id        => l_adr_accounting_coa_id
129333          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
129334          , x_flex_value_set_id        => l_adr_flex_value_set_id
129335          , x_value_type_code          => l_adr_value_type_code
129336          , x_value_combination_id     => l_adr_value_combination_id
129337          , x_value_segment_code       => l_adr_value_segment_code
129338          , p_side                     => 'NA'
129339          , p_override_seg_flag        => 'Y'
129340    );
129341 
129342    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
129343 
129344       xla_ae_lines_pkg.set_segment(
129345           p_to_segment_code         => 'GL_BALANCING'
129346         , p_segment_value           => l_segment
129347         , p_from_segment_code       => l_adr_value_segment_code
129348         , p_from_combination_id     => l_adr_value_combination_id
129349         , p_value_type_code         => l_adr_value_type_code
129350         , p_transaction_coa_id      => l_adr_transaction_coa_id
129351         , p_accounting_coa_id       => l_adr_accounting_coa_id
129352         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
129353         , p_flex_value_set_id       => l_adr_flex_value_set_id
129354         , p_adr_code                => 'FA_EXPENSE_ACCT'
129355         , p_adr_type_code           => 'S'
129356         , p_component_type          => l_component_type
129357         , p_component_code          => l_component_code
129358         , p_component_type_code     => l_component_type_code
129359         , p_component_appl_id       => l_component_appl_id
129360         , p_amb_context_code        => l_amb_context_code
129361         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
129362         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
129363         , p_side                    => 'NA'
129364         );
129365 
129366   END IF;
129367 
129368    l_segment := AcctDerRule_158(
129369            p_application_id           => p_application_id
129370          , p_ae_header_id             => l_ae_header_id 
129371 , p_source_3 => p_source_3
129372 , p_source_20 => p_source_20
129373          , x_transaction_coa_id       => l_adr_transaction_coa_id
129374          , x_accounting_coa_id        => l_adr_accounting_coa_id
129375          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
129376          , x_flex_value_set_id        => l_adr_flex_value_set_id
129380          , p_side                     => 'NA'
129377          , x_value_type_code          => l_adr_value_type_code
129378          , x_value_combination_id     => l_adr_value_combination_id
129379          , x_value_segment_code       => l_adr_value_segment_code
129381          , p_override_seg_flag        => 'Y'
129382    );
129383 
129384    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
129385 
129386       xla_ae_lines_pkg.set_segment(
129387           p_to_segment_code         => 'GL_ACCOUNT'
129388         , p_segment_value           => l_segment
129389         , p_from_segment_code       => l_adr_value_segment_code
129390         , p_from_combination_id     => l_adr_value_combination_id
129391         , p_value_type_code         => l_adr_value_type_code
129392         , p_transaction_coa_id      => l_adr_transaction_coa_id
129393         , p_accounting_coa_id       => l_adr_accounting_coa_id
129394         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
129395         , p_flex_value_set_id       => l_adr_flex_value_set_id
129396         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
129397         , p_adr_type_code           => 'S'
129398         , p_component_type          => l_component_type
129399         , p_component_code          => l_component_code
129400         , p_component_type_code     => l_component_type_code
129401         , p_component_appl_id       => l_component_appl_id
129402         , p_amb_context_code        => l_amb_context_code
129403         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
129404         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
129405         , p_side                    => 'NA'
129406         );
129407 
129408   END IF;
129409 
129410    --
129411    --
129412    END IF;
129413 
129414        --
129415        -- Update the line information that should be overwritten
129416        --
129417        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
129418                                          p_header_num   => 1);
129419        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
129420 
129421        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
129422 
129423        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
129424           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
129425        END IF;
129426 
129427       --
129428       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
129429       --
129430       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
129431           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
129432       ELSE
129433           ---------------------------------------------------------------------------------------------------
129434           -- 4262811a Switch Sign
129435           ---------------------------------------------------------------------------------------------------
129436           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
129437           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
129438                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
129439           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
129440                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
129441           -- 5132302
129442           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
129443                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
129444 
129445       END IF;
129446 
129447       -- 4955764
129448       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
129449       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
129450 
129451 
129452       XLA_AE_LINES_PKG.ValidateCurrentLine;
129453       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
129454 
129455       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
129456                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
129457                ,p_balance_type_code => l_balance_type_code);
129458 
129459    END IF;
129460 
129461    -----------------------------------------------------------------------------------------
129462    -- 4262811 Multiperiod Accounting
129463    -----------------------------------------------------------------------------------------
129464      -- No MPA option is assigned.
129465 
129466 
129467 END IF;
129468 END IF;
129469 --
129470 
129471 --
129472 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
129473    trace
129474       (p_msg      => 'END of AcctLineType_335'
129475       ,p_level    => C_LEVEL_PROCEDURE
129476       ,p_module   => l_log_module);
129477 END IF;
129478 --
129479 EXCEPTION
129480   WHEN xla_exceptions_pkg.application_exception THEN
129481       RAISE;
129482   WHEN OTHERS THEN
129483        xla_exceptions_pkg.raise_message
129484            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_335');
129485 END AcctLineType_335;
129486 --
129487 
129488 ---------------------------------------
129489 --
129490 -- PRIVATE FUNCTION
129491 --         AcctLineType_336
129492 --
129493 ---------------------------------------
129494 PROCEDURE AcctLineType_336 (
129495   p_application_id        IN NUMBER
129496  ,p_event_id              IN NUMBER
129497  ,p_calculate_acctd_flag  IN VARCHAR2
129498  ,p_calculate_g_l_flag    IN VARCHAR2
129499  ,p_actual_flag           IN OUT VARCHAR2
129500  ,p_balance_type_code     OUT VARCHAR2
129501  ,p_gain_or_loss_ref      OUT VARCHAR2
129502  
129506  , p_source_2            IN VARCHAR2
129503 --Period Close Date
129504  , p_source_1            IN DATE
129505 --Bonus Depreciation Expense Account
129507 --Generated Code Combination Identifier
129508  , p_source_3            IN NUMBER
129509 --Expense Account Code Combination Identifier
129510  , p_source_29            IN NUMBER
129511 --Adjustment Type
129512  , p_source_35            IN VARCHAR2
129513 --Transaction Header Identifier
129514  , p_source_36            IN NUMBER
129515 --Adjustment Line Identifier
129516  , p_source_37            IN NUMBER
129517 --Distribution Type Code
129518  , p_source_38            IN VARCHAR2
129519 --Entered Amount
129520  , p_source_39            IN NUMBER
129521 --Currency Code
129522  , p_source_40            IN VARCHAR2
129523 --Source Destination Code
129524  , p_source_42            IN VARCHAR2
129525 )
129526 IS
129527 
129528 l_component_type              VARCHAR2(80);
129529 l_component_code              VARCHAR2(30);
129530 l_component_type_code         VARCHAR2(1);
129531 l_component_appl_id           INTEGER;
129532 l_amb_context_code            VARCHAR2(30);
129533 l_entity_code                 VARCHAR2(30);
129534 l_event_class_code            VARCHAR2(30);
129535 l_ae_header_id                NUMBER;
129536 l_event_type_code             VARCHAR2(30);
129537 l_line_definition_code        VARCHAR2(30);
129538 l_line_definition_owner_code  VARCHAR2(1);
129539 --
129540 -- adr variables
129541 l_segment                     VARCHAR2(30);
129542 l_ccid                        NUMBER;
129543 l_adr_transaction_coa_id      NUMBER;
129544 l_adr_accounting_coa_id       NUMBER;
129545 l_adr_flexfield_segment_code  VARCHAR2(30);
129546 l_adr_flex_value_set_id       NUMBER;
129547 l_adr_value_type_code         VARCHAR2(30);
129548 l_adr_value_combination_id    NUMBER;
129549 l_adr_value_segment_code      VARCHAR2(30);
129550 
129551 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
129552 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
129553 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
129554 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
129555 
129556 -- 4262811 Variables ------------------------------------------------------------------------------------------
129557 l_entered_amt_idx             NUMBER;
129558 l_accted_amt_idx              NUMBER;
129559 l_acc_rev_flag                VARCHAR2(1);
129560 l_accrual_line_num            NUMBER;
129561 l_tmp_amt                     NUMBER;
129562 l_acc_rev_natural_side_code   VARCHAR2(1);
129563 
129564 l_num_entries                 NUMBER;
129565 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
129566 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
129567 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
129568 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
129569 l_recog_line_1                NUMBER;
129570 l_recog_line_2                NUMBER;
129571 
129572 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
129573 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
129574 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
129575 
129576 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
129577 
129578 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
129579 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
129580 
129581 ---------------------------------------------------------------------------------------------------------------
129582 
129583 
129584 --
129585 -- bulk performance
129586 --
129587 l_balance_type_code           VARCHAR2(1);
129588 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
129589 l_log_module                  VARCHAR2(240);
129590 
129591 --
129592 -- Upgrade strategy
129593 --
129594 l_actual_upg_option           VARCHAR2(1);
129595 l_enc_upg_option           VARCHAR2(1);
129596 
129597 --
129598 BEGIN
129599 --
129600 IF g_log_enabled THEN
129601       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_336';
129602 END IF;
129603 --
129604 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
129605 
129606       trace
129607          (p_msg      => 'BEGIN of AcctLineType_336'
129608          ,p_level    => C_LEVEL_PROCEDURE
129609          ,p_module   => l_log_module);
129610 
129611 END IF;
129612 --
129613 l_component_type             := 'AMB_JLT';
129614 l_component_code             := 'FA_SLT_DEST_BONUS_EXP';
129615 l_component_type_code        := 'S';
129616 l_component_appl_id          :=  140;
129617 l_amb_context_code           := 'DEFAULT';
129618 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
129619 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
129620 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
129621 l_line_definition_owner_code := 'S';
129622 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
129623 --
129624 l_balance_type_code          := 'A';
129625 l_segment                     := NULL;
129626 l_ccid                        := NULL;
129627 l_adr_transaction_coa_id      := NULL;
129628 l_adr_accounting_coa_id       := NULL;
129629 l_adr_flexfield_segment_code  := NULL;
129630 l_adr_flex_value_set_id       := NULL;
129631 l_adr_value_type_code         := NULL;
129632 l_adr_value_combination_id    := NULL;
129633 l_adr_value_segment_code      := NULL;
129634 
129635 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
129636 l_bflow_class_code           := '';    -- 4219869 Business Flow
129637 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
129638 l_budgetary_control_flag     := 'N';
129639 
129640 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
129641 l_bflow_applied_to_amt       := NULL; -- 5132302
129645 l_accrual_line_num           := NULL;          -- 4262811
129642 l_entered_amt_idx            := NULL;          -- 4262811
129643 l_accted_amt_idx             := NULL;          -- 4262811
129644 l_acc_rev_flag               := NULL;          -- 4262811
129646 l_tmp_amt                    := NULL;          -- 4262811
129647 --
129648  
129649 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
129650     l_balance_type_code <> 'B' THEN
129651 IF NVL(p_source_35,'
129652 ') =  'BONUS EXPENSE' AND 
129653 NVL(p_source_42,'
129654 ') =  'DEST'
129655  THEN 
129656 
129657    --
129658    XLA_AE_LINES_PKG.SetNewLine;
129659 
129660    p_balance_type_code          := l_balance_type_code;
129661    -- set the flag so later we will know whether the gain loss line needs to be created
129662    
129663    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
129664      p_actual_flag :='A';
129665    END IF;
129666 
129667    --
129668    -- bulk performance
129669    --
129670    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
129671                                       p_header_num   => 0); -- 4262811
129672    --
129673    -- set accounting line options
129674    --
129675    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
129676            p_natural_side_code          => 'D'
129677          , p_gain_or_loss_flag          => 'N'
129678          , p_gl_transfer_mode_code      => 'S'
129679          , p_acct_entry_type_code       => 'A'
129680          , p_switch_side_flag           => 'Y'
129681          , p_merge_duplicate_code       => 'N'
129682          );
129683    --
129684    l_acc_rev_natural_side_code := 'C';  -- 4262811
129685    -- 
129686    --
129687    -- set accounting line type info
129688    --
129689    xla_ae_lines_pkg.SetAcctLineType
129690       (p_component_type             => l_component_type
129691       ,p_event_type_code            => l_event_type_code
129692       ,p_line_definition_owner_code => l_line_definition_owner_code
129693       ,p_line_definition_code       => l_line_definition_code
129694       ,p_accounting_line_code       => l_component_code
129695       ,p_accounting_line_type_code  => l_component_type_code
129696       ,p_accounting_line_appl_id    => l_component_appl_id
129697       ,p_amb_context_code           => l_amb_context_code
129698       ,p_entity_code                => l_entity_code
129699       ,p_event_class_code           => l_event_class_code);
129700    --
129701    -- set accounting class
129702    --
129703    xla_ae_lines_pkg.SetAcctClass(
129704            p_accounting_class_code  => 'EXPENSE'
129705          , p_ae_header_id           => l_ae_header_id
129706          );
129707 
129708    --
129709    -- set rounding class
129710    --
129711    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
129712                       'EXPENSE';
129713 
129714    --
129715    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
129716    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
129717    --
129718    -- bulk performance
129719    --
129720    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
129721 
129722    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
129723       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
129724 
129725    -- 4955764
129726    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
129727       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
129728 
129729    -- 4458381 Public Sector Enh
129730    
129731    --
129732    -- set accounting attributes for the line type
129733    --
129734    l_entered_amt_idx := 4;
129735    l_accted_amt_idx  := 6;
129736    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
129737    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
129738    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
129739    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
129740    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
129741    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
129742    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
129743    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
129744    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
129745    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
129746    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
129747    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
129748    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
129749 
129750    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
129751    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
129752 
129753    ---------------------------------------------------------------------------------------------------------------
129754    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
129755    ---------------------------------------------------------------------------------------------------------------
129756    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
129757 
129758    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
129759    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
129760 
129761    IF xla_accounting_cache_pkg.GetValueChar
129762          (p_source_code         => 'LEDGER_CATEGORY_CODE'
129763          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
129764    AND l_bflow_method_code = 'PRIOR_ENTRY'
129768        )
129765 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
129766    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
129767          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
129769    THEN
129770          xla_ae_lines_pkg.BflowUpgEntry
129771            (p_business_method_code    => l_bflow_method_code
129772            ,p_business_class_code     => l_bflow_class_code
129773            ,p_balance_type            => l_balance_type_code);
129774    ELSE
129775       NULL;
129776 -- No business flow processing for business flow method of NONE.
129777    END IF;
129778 
129779    --
129780    -- call analytical criteria
129781    --
129782    
129783    --
129784    -- call description
129785    --
129786    
129787 xla_ae_lines_pkg.SetLineDescription(
129788    p_ae_header_id => l_ae_header_id
129789   ,p_description  => Description_103 (
129790      p_application_id         => p_application_id
129791    , p_ae_header_id           => l_ae_header_id 
129792 , p_source_1 => p_source_1
129793    )
129794 );
129795 
129796 
129797    --
129798    -- call ADRs
129799    -- Bug 4922099
129800    --
129801    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
129802         (NVL(l_actual_upg_option, 'N') = 'O') OR
129803         (NVL(l_enc_upg_option, 'N') = 'O')
129804       )
129805    THEN
129806    NULL;
129807    --
129808    --
129809    
129810   l_ccid := AcctDerRule_175(
129811            p_application_id           => p_application_id
129812          , p_ae_header_id             => l_ae_header_id 
129813 , p_source_3 => p_source_3
129814 , p_source_29 => p_source_29
129815          , x_transaction_coa_id       => l_adr_transaction_coa_id
129816          , x_accounting_coa_id        => l_adr_accounting_coa_id
129817          , x_value_type_code          => l_adr_value_type_code
129818          , p_side                     => 'NA'
129819    );
129820 
129821    xla_ae_lines_pkg.set_ccid(
129822     p_code_combination_id          => l_ccid
129823   , p_value_type_code              => l_adr_value_type_code
129824   , p_transaction_coa_id           => l_adr_transaction_coa_id
129825   , p_accounting_coa_id            => l_adr_accounting_coa_id
129826   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
129827   , p_adr_type_code                => 'S'
129828   , p_component_type               => l_component_type
129829   , p_component_code               => l_component_code
129830   , p_component_type_code          => l_component_type_code
129831   , p_component_appl_id            => l_component_appl_id
129832   , p_amb_context_code             => l_amb_context_code
129833   , p_side                         => 'NA'
129834   );
129835 
129836 
129837    l_segment := AcctDerRule_143(
129838            p_application_id           => p_application_id
129839          , p_ae_header_id             => l_ae_header_id 
129840 , p_source_2 => p_source_2
129841 , p_source_3 => p_source_3
129842          , x_transaction_coa_id       => l_adr_transaction_coa_id
129843          , x_accounting_coa_id        => l_adr_accounting_coa_id
129844          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
129845          , x_flex_value_set_id        => l_adr_flex_value_set_id
129846          , x_value_type_code          => l_adr_value_type_code
129847          , x_value_combination_id     => l_adr_value_combination_id
129848          , x_value_segment_code       => l_adr_value_segment_code
129849          , p_side                     => 'NA'
129850          , p_override_seg_flag        => 'Y'
129851    );
129852 
129853    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
129854 
129855       xla_ae_lines_pkg.set_segment(
129856           p_to_segment_code         => 'GL_ACCOUNT'
129857         , p_segment_value           => l_segment
129858         , p_from_segment_code       => l_adr_value_segment_code
129859         , p_from_combination_id     => l_adr_value_combination_id
129860         , p_value_type_code         => l_adr_value_type_code
129861         , p_transaction_coa_id      => l_adr_transaction_coa_id
129862         , p_accounting_coa_id       => l_adr_accounting_coa_id
129863         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
129864         , p_flex_value_set_id       => l_adr_flex_value_set_id
129865         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
129866         , p_adr_type_code           => 'S'
129867         , p_component_type          => l_component_type
129868         , p_component_code          => l_component_code
129869         , p_component_type_code     => l_component_type_code
129870         , p_component_appl_id       => l_component_appl_id
129871         , p_amb_context_code        => l_amb_context_code
129872         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
129873         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
129874         , p_side                    => 'NA'
129875         );
129876 
129877   END IF;
129878 
129879    --
129880    --
129881    END IF;
129882    --
129883    -- Bug 4922099
129884    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
129885           (NVL(l_enc_upg_option, 'N') = 'O')
129886         ) AND
129887         (l_bflow_method_code = 'PRIOR_ENTRY')
129888       )
129889    THEN
129890       IF
129891       --
129892       1 = 2
129893       --
129894       THEN
129895       xla_accounting_err_pkg.build_message
129896                                     (p_appli_s_name            => 'XLA'
129897                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
129898                                     ,p_token_1                 => 'LINE_NUMBER'
129899                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
129900                                     ,p_token_2                 => 'LINE_TYPE_NAME'
129901                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
129905                                                                             ,l_component_appl_id
129902                                                                              l_component_type
129903                                                                             ,l_component_code
129904                                                                             ,l_component_type_code
129906                                                                             ,l_amb_context_code
129907                                                                             ,l_entity_code
129908                                                                             ,l_event_class_code
129909                                                                            )
129910                                     ,p_token_3                 => 'OWNER'
129911                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
129912                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
129913                                                                           ,p_lookup_code    => l_component_type_code
129914                                                                          )
129915                                     ,p_token_4                 => 'PRODUCT_NAME'
129916                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
129917                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
129918                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
129919                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
129920                                     ,p_ae_header_id            =>  NULL
129921                                        );
129922 
129923         IF (C_LEVEL_ERROR>= g_log_level) THEN
129924                  trace
129925                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
129926                       ,p_level    => C_LEVEL_ERROR
129927                       ,p_module   => l_log_module);
129928         END IF;
129929       END IF;
129930    END IF;
129931    --
129932    --
129933    ------------------------------------------------------------------------------------------------
129934    -- 4219869 Business Flow
129935    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
129936    -- Prior Entry.  Currently, the following code is always generated.
129937    ------------------------------------------------------------------------------------------------
129938    XLA_AE_LINES_PKG.ValidateCurrentLine;
129939 
129940    ------------------------------------------------------------------------------------
129941    -- 4219869 Business Flow
129942    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
129943    ------------------------------------------------------------------------------------
129944    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
129945 
129946    ----------------------------------------------------------------------------------
129947    -- 4219869 Business Flow
129948    -- Update journal entry status -- Need to generate this within IF <condition>
129949    ----------------------------------------------------------------------------------
129950    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
129951          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
129952          ,p_balance_type_code => l_balance_type_code
129953          );
129954 
129955    -------------------------------------------------------------------------------------------
129956    -- 4262811 - Generate the Accrual Reversal lines
129957    -------------------------------------------------------------------------------------------
129958    BEGIN
129959       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
129960                               (g_array_event(p_event_id).array_value_num('header_index'));
129961       IF l_acc_rev_flag IS NULL THEN
129962          l_acc_rev_flag := 'N';
129963       END IF;
129964    EXCEPTION
129965       WHEN OTHERS THEN
129966          l_acc_rev_flag := 'N';
129967    END;
129968    --
129969    IF (l_acc_rev_flag = 'Y') THEN
129970 
129971        -- 4645092  ------------------------------------------------------------------------------
129972        -- To allow MPA report to determine if it should generate report process
129973        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
129974        ------------------------------------------------------------------------------------------
129975 
129976        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
129977        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
129978    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
129979    -- call ADRs
129980    -- Bug 4922099
129981    --
129982    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
129983         (NVL(l_actual_upg_option, 'N') = 'O') OR
129984         (NVL(l_enc_upg_option, 'N') = 'O')
129985       )
129986    THEN
129987    NULL;
129988    --
129989    --
129990    
129991   l_ccid := AcctDerRule_175(
129992            p_application_id           => p_application_id
129993          , p_ae_header_id             => l_ae_header_id 
129994 , p_source_3 => p_source_3
129995 , p_source_29 => p_source_29
129996          , x_transaction_coa_id       => l_adr_transaction_coa_id
129997          , x_accounting_coa_id        => l_adr_accounting_coa_id
129998          , x_value_type_code          => l_adr_value_type_code
129999          , p_side                     => 'NA'
130000    );
130001 
130002    xla_ae_lines_pkg.set_ccid(
130003     p_code_combination_id          => l_ccid
130004   , p_value_type_code              => l_adr_value_type_code
130005   , p_transaction_coa_id           => l_adr_transaction_coa_id
130006   , p_accounting_coa_id            => l_adr_accounting_coa_id
130010   , p_component_code               => l_component_code
130007   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
130008   , p_adr_type_code                => 'S'
130009   , p_component_type               => l_component_type
130011   , p_component_type_code          => l_component_type_code
130012   , p_component_appl_id            => l_component_appl_id
130013   , p_amb_context_code             => l_amb_context_code
130014   , p_side                         => 'NA'
130015   );
130016 
130017 
130018    l_segment := AcctDerRule_143(
130019            p_application_id           => p_application_id
130020          , p_ae_header_id             => l_ae_header_id 
130021 , p_source_2 => p_source_2
130022 , p_source_3 => p_source_3
130023          , x_transaction_coa_id       => l_adr_transaction_coa_id
130024          , x_accounting_coa_id        => l_adr_accounting_coa_id
130025          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
130026          , x_flex_value_set_id        => l_adr_flex_value_set_id
130027          , x_value_type_code          => l_adr_value_type_code
130028          , x_value_combination_id     => l_adr_value_combination_id
130029          , x_value_segment_code       => l_adr_value_segment_code
130030          , p_side                     => 'NA'
130031          , p_override_seg_flag        => 'Y'
130032    );
130033 
130034    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
130035 
130036       xla_ae_lines_pkg.set_segment(
130037           p_to_segment_code         => 'GL_ACCOUNT'
130038         , p_segment_value           => l_segment
130039         , p_from_segment_code       => l_adr_value_segment_code
130040         , p_from_combination_id     => l_adr_value_combination_id
130041         , p_value_type_code         => l_adr_value_type_code
130042         , p_transaction_coa_id      => l_adr_transaction_coa_id
130043         , p_accounting_coa_id       => l_adr_accounting_coa_id
130044         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
130045         , p_flex_value_set_id       => l_adr_flex_value_set_id
130046         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
130047         , p_adr_type_code           => 'S'
130048         , p_component_type          => l_component_type
130049         , p_component_code          => l_component_code
130050         , p_component_type_code     => l_component_type_code
130051         , p_component_appl_id       => l_component_appl_id
130052         , p_amb_context_code        => l_amb_context_code
130053         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
130054         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
130055         , p_side                    => 'NA'
130056         );
130057 
130058   END IF;
130059 
130060    --
130061    --
130062    END IF;
130063 
130064        --
130065        -- Update the line information that should be overwritten
130066        --
130067        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
130068                                          p_header_num   => 1);
130069        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
130070 
130071        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
130072 
130073        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
130074           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
130075        END IF;
130076 
130077       --
130078       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
130079       --
130080       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
130081           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
130082       ELSE
130083           ---------------------------------------------------------------------------------------------------
130084           -- 4262811a Switch Sign
130085           ---------------------------------------------------------------------------------------------------
130086           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
130087           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
130088                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
130089           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
130090                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
130091           -- 5132302
130092           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
130093                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
130094 
130095       END IF;
130096 
130097       -- 4955764
130098       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
130099       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
130100 
130101 
130102       XLA_AE_LINES_PKG.ValidateCurrentLine;
130103       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
130104 
130105       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
130106                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
130107                ,p_balance_type_code => l_balance_type_code);
130108 
130109    END IF;
130110 
130111    -----------------------------------------------------------------------------------------
130112    -- 4262811 Multiperiod Accounting
130113    -----------------------------------------------------------------------------------------
130114      -- No MPA option is assigned.
130115 
130116 
130117 END IF;
130118 END IF;
130119 --
130120 
130121 --
130122 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
130123    trace
130127 END IF;
130124       (p_msg      => 'END of AcctLineType_336'
130125       ,p_level    => C_LEVEL_PROCEDURE
130126       ,p_module   => l_log_module);
130128 --
130129 EXCEPTION
130130   WHEN xla_exceptions_pkg.application_exception THEN
130131       RAISE;
130132   WHEN OTHERS THEN
130133        xla_exceptions_pkg.raise_message
130134            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_336');
130135 END AcctLineType_336;
130136 --
130137 
130138 ---------------------------------------
130139 --
130140 -- PRIVATE FUNCTION
130141 --         AcctLineType_337
130142 --
130143 ---------------------------------------
130144 PROCEDURE AcctLineType_337 (
130145   p_application_id        IN NUMBER
130146  ,p_event_id              IN NUMBER
130147  ,p_calculate_acctd_flag  IN VARCHAR2
130148  ,p_calculate_g_l_flag    IN VARCHAR2
130149  ,p_actual_flag           IN OUT VARCHAR2
130150  ,p_balance_type_code     OUT VARCHAR2
130151  ,p_gain_or_loss_ref      OUT VARCHAR2
130152  
130153 --Period Close Date
130154  , p_source_1            IN DATE
130155 --Generated Code Combination Identifier
130156  , p_source_3            IN NUMBER
130157 --Bonus Reserve Account
130158  , p_source_4            IN VARCHAR2
130159 --Generated Offset Code Combination Identifier
130160  , p_source_17            IN NUMBER
130161 --Expense Account Code Combination Identifier
130162  , p_source_29            IN NUMBER
130163 --Default Code Combination Identifier
130164  , p_source_30            IN NUMBER
130165 --Adjustment Type
130166  , p_source_35            IN VARCHAR2
130167 --Transaction Header Identifier
130168  , p_source_36            IN NUMBER
130169 --Adjustment Line Identifier
130170  , p_source_37            IN NUMBER
130171 --Distribution Type Code
130172  , p_source_38            IN VARCHAR2
130173 --Entered Amount
130174  , p_source_39            IN NUMBER
130175 --Currency Code
130176  , p_source_40            IN VARCHAR2
130177 --Source Destination Code
130178  , p_source_42            IN VARCHAR2
130179 )
130180 IS
130181 
130182 l_component_type              VARCHAR2(80);
130183 l_component_code              VARCHAR2(30);
130184 l_component_type_code         VARCHAR2(1);
130185 l_component_appl_id           INTEGER;
130186 l_amb_context_code            VARCHAR2(30);
130187 l_entity_code                 VARCHAR2(30);
130188 l_event_class_code            VARCHAR2(30);
130189 l_ae_header_id                NUMBER;
130190 l_event_type_code             VARCHAR2(30);
130191 l_line_definition_code        VARCHAR2(30);
130192 l_line_definition_owner_code  VARCHAR2(1);
130193 --
130194 -- adr variables
130195 l_segment                     VARCHAR2(30);
130196 l_ccid                        NUMBER;
130197 l_adr_transaction_coa_id      NUMBER;
130198 l_adr_accounting_coa_id       NUMBER;
130199 l_adr_flexfield_segment_code  VARCHAR2(30);
130200 l_adr_flex_value_set_id       NUMBER;
130201 l_adr_value_type_code         VARCHAR2(30);
130202 l_adr_value_combination_id    NUMBER;
130203 l_adr_value_segment_code      VARCHAR2(30);
130204 
130205 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
130206 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
130207 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
130208 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
130209 
130210 -- 4262811 Variables ------------------------------------------------------------------------------------------
130211 l_entered_amt_idx             NUMBER;
130212 l_accted_amt_idx              NUMBER;
130213 l_acc_rev_flag                VARCHAR2(1);
130214 l_accrual_line_num            NUMBER;
130215 l_tmp_amt                     NUMBER;
130216 l_acc_rev_natural_side_code   VARCHAR2(1);
130217 
130218 l_num_entries                 NUMBER;
130219 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
130220 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
130221 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
130222 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
130223 l_recog_line_1                NUMBER;
130224 l_recog_line_2                NUMBER;
130225 
130226 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
130227 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
130228 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
130229 
130230 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
130231 
130232 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
130233 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
130234 
130235 ---------------------------------------------------------------------------------------------------------------
130236 
130237 
130238 --
130239 -- bulk performance
130240 --
130241 l_balance_type_code           VARCHAR2(1);
130242 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
130243 l_log_module                  VARCHAR2(240);
130244 
130245 --
130246 -- Upgrade strategy
130247 --
130248 l_actual_upg_option           VARCHAR2(1);
130249 l_enc_upg_option           VARCHAR2(1);
130250 
130251 --
130252 BEGIN
130253 --
130254 IF g_log_enabled THEN
130255       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_337';
130256 END IF;
130257 --
130258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
130259 
130260       trace
130261          (p_msg      => 'BEGIN of AcctLineType_337'
130262          ,p_level    => C_LEVEL_PROCEDURE
130263          ,p_module   => l_log_module);
130264 
130265 END IF;
130266 --
130267 l_component_type             := 'AMB_JLT';
130268 l_component_code             := 'FA_SLT_DEST_BONUS_RESERVE';
130269 l_component_type_code        := 'S';
130273 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
130270 l_component_appl_id          :=  140;
130271 l_amb_context_code           := 'DEFAULT';
130272 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
130274 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
130275 l_line_definition_owner_code := 'S';
130276 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
130277 --
130278 l_balance_type_code          := 'A';
130279 l_segment                     := NULL;
130280 l_ccid                        := NULL;
130281 l_adr_transaction_coa_id      := NULL;
130282 l_adr_accounting_coa_id       := NULL;
130283 l_adr_flexfield_segment_code  := NULL;
130284 l_adr_flex_value_set_id       := NULL;
130285 l_adr_value_type_code         := NULL;
130286 l_adr_value_combination_id    := NULL;
130287 l_adr_value_segment_code      := NULL;
130288 
130289 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
130290 l_bflow_class_code           := '';    -- 4219869 Business Flow
130291 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
130292 l_budgetary_control_flag     := 'N';
130293 
130294 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
130295 l_bflow_applied_to_amt       := NULL; -- 5132302
130296 l_entered_amt_idx            := NULL;          -- 4262811
130297 l_accted_amt_idx             := NULL;          -- 4262811
130298 l_acc_rev_flag               := NULL;          -- 4262811
130299 l_accrual_line_num           := NULL;          -- 4262811
130300 l_tmp_amt                    := NULL;          -- 4262811
130301 --
130302  
130303 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
130304     l_balance_type_code <> 'B' THEN
130305 IF (NVL(p_source_35,'
130306 ') =  'BONUS EXPENSE' OR 
130307 NVL(p_source_35,'
130308 ') =  'BONUS RESERVE') AND 
130309 NVL(p_source_42,'
130310 ') =  'DEST'
130311  THEN 
130312 
130313    --
130314    XLA_AE_LINES_PKG.SetNewLine;
130315 
130316    p_balance_type_code          := l_balance_type_code;
130317    -- set the flag so later we will know whether the gain loss line needs to be created
130318    
130319    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
130320      p_actual_flag :='A';
130321    END IF;
130322 
130323    --
130324    -- bulk performance
130325    --
130326    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
130327                                       p_header_num   => 0); -- 4262811
130328    --
130329    -- set accounting line options
130330    --
130331    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
130332            p_natural_side_code          => 'C'
130333          , p_gain_or_loss_flag          => 'N'
130334          , p_gl_transfer_mode_code      => 'S'
130335          , p_acct_entry_type_code       => 'A'
130336          , p_switch_side_flag           => 'Y'
130337          , p_merge_duplicate_code       => 'N'
130338          );
130339    --
130340    l_acc_rev_natural_side_code := 'D';  -- 4262811
130341    -- 
130342    --
130343    -- set accounting line type info
130344    --
130345    xla_ae_lines_pkg.SetAcctLineType
130346       (p_component_type             => l_component_type
130347       ,p_event_type_code            => l_event_type_code
130348       ,p_line_definition_owner_code => l_line_definition_owner_code
130349       ,p_line_definition_code       => l_line_definition_code
130350       ,p_accounting_line_code       => l_component_code
130351       ,p_accounting_line_type_code  => l_component_type_code
130352       ,p_accounting_line_appl_id    => l_component_appl_id
130353       ,p_amb_context_code           => l_amb_context_code
130354       ,p_entity_code                => l_entity_code
130355       ,p_event_class_code           => l_event_class_code);
130356    --
130357    -- set accounting class
130358    --
130359    xla_ae_lines_pkg.SetAcctClass(
130360            p_accounting_class_code  => 'ASSET'
130361          , p_ae_header_id           => l_ae_header_id
130362          );
130363 
130364    --
130365    -- set rounding class
130366    --
130367    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
130368                       'ASSET';
130369 
130370    --
130371    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
130372    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
130373    --
130374    -- bulk performance
130375    --
130376    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
130377 
130378    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
130379       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
130380 
130381    -- 4955764
130382    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
130383       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
130384 
130385    -- 4458381 Public Sector Enh
130386    
130387    --
130388    -- set accounting attributes for the line type
130389    --
130390    l_entered_amt_idx := 4;
130391    l_accted_amt_idx  := 6;
130392    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
130393    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
130394    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
130395    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
130396    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
130397    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
130398    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
130399    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
130400    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
130401    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
130405 
130402    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
130403    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
130404    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
130406    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
130407    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
130408 
130409    ---------------------------------------------------------------------------------------------------------------
130410    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
130411    ---------------------------------------------------------------------------------------------------------------
130412    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
130413 
130414    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
130415    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
130416 
130417    IF xla_accounting_cache_pkg.GetValueChar
130418          (p_source_code         => 'LEDGER_CATEGORY_CODE'
130419          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
130420    AND l_bflow_method_code = 'PRIOR_ENTRY'
130421 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
130422    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
130423          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
130424        )
130425    THEN
130426          xla_ae_lines_pkg.BflowUpgEntry
130427            (p_business_method_code    => l_bflow_method_code
130428            ,p_business_class_code     => l_bflow_class_code
130429            ,p_balance_type            => l_balance_type_code);
130430    ELSE
130431       NULL;
130432 -- No business flow processing for business flow method of NONE.
130433    END IF;
130434 
130435    --
130436    -- call analytical criteria
130437    --
130438    
130439    --
130440    -- call description
130441    --
130442    
130443 xla_ae_lines_pkg.SetLineDescription(
130444    p_ae_header_id => l_ae_header_id
130445   ,p_description  => Description_104 (
130446      p_application_id         => p_application_id
130447    , p_ae_header_id           => l_ae_header_id 
130448 , p_source_1 => p_source_1
130449    )
130450 );
130451 
130452 
130453    --
130454    -- call ADRs
130455    -- Bug 4922099
130456    --
130457    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
130458         (NVL(l_actual_upg_option, 'N') = 'O') OR
130459         (NVL(l_enc_upg_option, 'N') = 'O')
130460       )
130461    THEN
130462    NULL;
130463    --
130464    --
130465    
130466   l_ccid := AcctDerRule_174(
130467            p_application_id           => p_application_id
130468          , p_ae_header_id             => l_ae_header_id 
130469 , p_source_3 => p_source_3
130470 , p_source_17 => p_source_17
130471 , p_source_30 => p_source_30
130472          , x_transaction_coa_id       => l_adr_transaction_coa_id
130473          , x_accounting_coa_id        => l_adr_accounting_coa_id
130474          , x_value_type_code          => l_adr_value_type_code
130475          , p_side                     => 'NA'
130476    );
130477 
130478    xla_ae_lines_pkg.set_ccid(
130479     p_code_combination_id          => l_ccid
130480   , p_value_type_code              => l_adr_value_type_code
130481   , p_transaction_coa_id           => l_adr_transaction_coa_id
130482   , p_accounting_coa_id            => l_adr_accounting_coa_id
130483   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
130484   , p_adr_type_code                => 'S'
130485   , p_component_type               => l_component_type
130486   , p_component_code               => l_component_code
130487   , p_component_type_code          => l_component_type_code
130488   , p_component_appl_id            => l_component_appl_id
130489   , p_amb_context_code             => l_amb_context_code
130490   , p_side                         => 'NA'
130491   );
130492 
130493 
130494    l_segment := AcctDerRule_144(
130495            p_application_id           => p_application_id
130496          , p_ae_header_id             => l_ae_header_id 
130497 , p_source_3 => p_source_3
130498 , p_source_4 => p_source_4
130499          , x_transaction_coa_id       => l_adr_transaction_coa_id
130500          , x_accounting_coa_id        => l_adr_accounting_coa_id
130501          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
130502          , x_flex_value_set_id        => l_adr_flex_value_set_id
130503          , x_value_type_code          => l_adr_value_type_code
130504          , x_value_combination_id     => l_adr_value_combination_id
130505          , x_value_segment_code       => l_adr_value_segment_code
130506          , p_side                     => 'NA'
130507          , p_override_seg_flag        => 'Y'
130508    );
130509 
130510    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
130511 
130512       xla_ae_lines_pkg.set_segment(
130513           p_to_segment_code         => 'GL_ACCOUNT'
130514         , p_segment_value           => l_segment
130515         , p_from_segment_code       => l_adr_value_segment_code
130516         , p_from_combination_id     => l_adr_value_combination_id
130517         , p_value_type_code         => l_adr_value_type_code
130518         , p_transaction_coa_id      => l_adr_transaction_coa_id
130519         , p_accounting_coa_id       => l_adr_accounting_coa_id
130520         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
130521         , p_flex_value_set_id       => l_adr_flex_value_set_id
130522         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
130523         , p_adr_type_code           => 'S'
130524         , p_component_type          => l_component_type
130525         , p_component_code          => l_component_code
130526         , p_component_type_code     => l_component_type_code
130530         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
130527         , p_component_appl_id       => l_component_appl_id
130528         , p_amb_context_code        => l_amb_context_code
130529         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
130531         , p_side                    => 'NA'
130532         );
130533 
130534   END IF;
130535 
130536    l_segment := AcctDerRule_168(
130537            p_application_id           => p_application_id
130538          , p_ae_header_id             => l_ae_header_id 
130539 , p_source_3 => p_source_3
130540 , p_source_29 => p_source_29
130541          , x_transaction_coa_id       => l_adr_transaction_coa_id
130542          , x_accounting_coa_id        => l_adr_accounting_coa_id
130543          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
130544          , x_flex_value_set_id        => l_adr_flex_value_set_id
130545          , x_value_type_code          => l_adr_value_type_code
130546          , x_value_combination_id     => l_adr_value_combination_id
130547          , x_value_segment_code       => l_adr_value_segment_code
130548          , p_side                     => 'NA'
130549          , p_override_seg_flag        => 'Y'
130550    );
130551 
130552    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
130553 
130554       xla_ae_lines_pkg.set_segment(
130555           p_to_segment_code         => 'GL_BALANCING'
130556         , p_segment_value           => l_segment
130557         , p_from_segment_code       => l_adr_value_segment_code
130558         , p_from_combination_id     => l_adr_value_combination_id
130559         , p_value_type_code         => l_adr_value_type_code
130560         , p_transaction_coa_id      => l_adr_transaction_coa_id
130561         , p_accounting_coa_id       => l_adr_accounting_coa_id
130562         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
130563         , p_flex_value_set_id       => l_adr_flex_value_set_id
130564         , p_adr_code                => 'FA_EXPENSE_ACCT'
130565         , p_adr_type_code           => 'S'
130566         , p_component_type          => l_component_type
130567         , p_component_code          => l_component_code
130568         , p_component_type_code     => l_component_type_code
130569         , p_component_appl_id       => l_component_appl_id
130570         , p_amb_context_code        => l_amb_context_code
130571         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
130572         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
130573         , p_side                    => 'NA'
130574         );
130575 
130576   END IF;
130577 
130578    --
130579    --
130580    END IF;
130581    --
130582    -- Bug 4922099
130583    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
130584           (NVL(l_enc_upg_option, 'N') = 'O')
130585         ) AND
130586         (l_bflow_method_code = 'PRIOR_ENTRY')
130587       )
130588    THEN
130589       IF
130590       --
130591       1 = 2
130592       --
130593       THEN
130594       xla_accounting_err_pkg.build_message
130595                                     (p_appli_s_name            => 'XLA'
130596                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
130597                                     ,p_token_1                 => 'LINE_NUMBER'
130598                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
130599                                     ,p_token_2                 => 'LINE_TYPE_NAME'
130600                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
130601                                                                              l_component_type
130602                                                                             ,l_component_code
130603                                                                             ,l_component_type_code
130604                                                                             ,l_component_appl_id
130605                                                                             ,l_amb_context_code
130606                                                                             ,l_entity_code
130607                                                                             ,l_event_class_code
130608                                                                            )
130609                                     ,p_token_3                 => 'OWNER'
130610                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
130611                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
130612                                                                           ,p_lookup_code    => l_component_type_code
130613                                                                          )
130614                                     ,p_token_4                 => 'PRODUCT_NAME'
130615                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
130616                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
130617                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
130618                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
130619                                     ,p_ae_header_id            =>  NULL
130620                                        );
130621 
130622         IF (C_LEVEL_ERROR>= g_log_level) THEN
130623                  trace
130624                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
130625                       ,p_level    => C_LEVEL_ERROR
130626                       ,p_module   => l_log_module);
130627         END IF;
130628       END IF;
130629    END IF;
130630    --
130631    --
130632    ------------------------------------------------------------------------------------------------
130633    -- 4219869 Business Flow
130637    XLA_AE_LINES_PKG.ValidateCurrentLine;
130634    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
130635    -- Prior Entry.  Currently, the following code is always generated.
130636    ------------------------------------------------------------------------------------------------
130638 
130639    ------------------------------------------------------------------------------------
130640    -- 4219869 Business Flow
130641    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
130642    ------------------------------------------------------------------------------------
130643    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
130644 
130645    ----------------------------------------------------------------------------------
130646    -- 4219869 Business Flow
130647    -- Update journal entry status -- Need to generate this within IF <condition>
130648    ----------------------------------------------------------------------------------
130649    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
130650          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
130651          ,p_balance_type_code => l_balance_type_code
130652          );
130653 
130654    -------------------------------------------------------------------------------------------
130655    -- 4262811 - Generate the Accrual Reversal lines
130656    -------------------------------------------------------------------------------------------
130657    BEGIN
130658       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
130659                               (g_array_event(p_event_id).array_value_num('header_index'));
130660       IF l_acc_rev_flag IS NULL THEN
130661          l_acc_rev_flag := 'N';
130662       END IF;
130663    EXCEPTION
130664       WHEN OTHERS THEN
130665          l_acc_rev_flag := 'N';
130666    END;
130667    --
130668    IF (l_acc_rev_flag = 'Y') THEN
130669 
130670        -- 4645092  ------------------------------------------------------------------------------
130671        -- To allow MPA report to determine if it should generate report process
130672        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
130673        ------------------------------------------------------------------------------------------
130674 
130675        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
130676        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
130677    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
130678    -- call ADRs
130679    -- Bug 4922099
130680    --
130681    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
130682         (NVL(l_actual_upg_option, 'N') = 'O') OR
130683         (NVL(l_enc_upg_option, 'N') = 'O')
130684       )
130685    THEN
130686    NULL;
130687    --
130688    --
130689    
130690   l_ccid := AcctDerRule_174(
130691            p_application_id           => p_application_id
130692          , p_ae_header_id             => l_ae_header_id 
130693 , p_source_3 => p_source_3
130694 , p_source_17 => p_source_17
130695 , p_source_30 => p_source_30
130696          , x_transaction_coa_id       => l_adr_transaction_coa_id
130697          , x_accounting_coa_id        => l_adr_accounting_coa_id
130698          , x_value_type_code          => l_adr_value_type_code
130699          , p_side                     => 'NA'
130700    );
130701 
130702    xla_ae_lines_pkg.set_ccid(
130703     p_code_combination_id          => l_ccid
130704   , p_value_type_code              => l_adr_value_type_code
130705   , p_transaction_coa_id           => l_adr_transaction_coa_id
130706   , p_accounting_coa_id            => l_adr_accounting_coa_id
130707   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
130708   , p_adr_type_code                => 'S'
130709   , p_component_type               => l_component_type
130710   , p_component_code               => l_component_code
130711   , p_component_type_code          => l_component_type_code
130712   , p_component_appl_id            => l_component_appl_id
130713   , p_amb_context_code             => l_amb_context_code
130714   , p_side                         => 'NA'
130715   );
130716 
130717 
130718    l_segment := AcctDerRule_144(
130719            p_application_id           => p_application_id
130720          , p_ae_header_id             => l_ae_header_id 
130721 , p_source_3 => p_source_3
130722 , p_source_4 => p_source_4
130723          , x_transaction_coa_id       => l_adr_transaction_coa_id
130724          , x_accounting_coa_id        => l_adr_accounting_coa_id
130725          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
130726          , x_flex_value_set_id        => l_adr_flex_value_set_id
130727          , x_value_type_code          => l_adr_value_type_code
130728          , x_value_combination_id     => l_adr_value_combination_id
130729          , x_value_segment_code       => l_adr_value_segment_code
130730          , p_side                     => 'NA'
130731          , p_override_seg_flag        => 'Y'
130732    );
130733 
130734    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
130735 
130736       xla_ae_lines_pkg.set_segment(
130737           p_to_segment_code         => 'GL_ACCOUNT'
130738         , p_segment_value           => l_segment
130739         , p_from_segment_code       => l_adr_value_segment_code
130740         , p_from_combination_id     => l_adr_value_combination_id
130741         , p_value_type_code         => l_adr_value_type_code
130742         , p_transaction_coa_id      => l_adr_transaction_coa_id
130743         , p_accounting_coa_id       => l_adr_accounting_coa_id
130744         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
130745         , p_flex_value_set_id       => l_adr_flex_value_set_id
130746         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
130747         , p_adr_type_code           => 'S'
130748         , p_component_type          => l_component_type
130749         , p_component_code          => l_component_code
130750         , p_component_type_code     => l_component_type_code
130754         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
130751         , p_component_appl_id       => l_component_appl_id
130752         , p_amb_context_code        => l_amb_context_code
130753         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
130755         , p_side                    => 'NA'
130756         );
130757 
130758   END IF;
130759 
130760    l_segment := AcctDerRule_168(
130761            p_application_id           => p_application_id
130762          , p_ae_header_id             => l_ae_header_id 
130763 , p_source_3 => p_source_3
130764 , p_source_29 => p_source_29
130765          , x_transaction_coa_id       => l_adr_transaction_coa_id
130766          , x_accounting_coa_id        => l_adr_accounting_coa_id
130767          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
130768          , x_flex_value_set_id        => l_adr_flex_value_set_id
130769          , x_value_type_code          => l_adr_value_type_code
130770          , x_value_combination_id     => l_adr_value_combination_id
130771          , x_value_segment_code       => l_adr_value_segment_code
130772          , p_side                     => 'NA'
130773          , p_override_seg_flag        => 'Y'
130774    );
130775 
130776    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
130777 
130778       xla_ae_lines_pkg.set_segment(
130779           p_to_segment_code         => 'GL_BALANCING'
130780         , p_segment_value           => l_segment
130781         , p_from_segment_code       => l_adr_value_segment_code
130782         , p_from_combination_id     => l_adr_value_combination_id
130783         , p_value_type_code         => l_adr_value_type_code
130784         , p_transaction_coa_id      => l_adr_transaction_coa_id
130785         , p_accounting_coa_id       => l_adr_accounting_coa_id
130786         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
130787         , p_flex_value_set_id       => l_adr_flex_value_set_id
130788         , p_adr_code                => 'FA_EXPENSE_ACCT'
130789         , p_adr_type_code           => 'S'
130790         , p_component_type          => l_component_type
130791         , p_component_code          => l_component_code
130792         , p_component_type_code     => l_component_type_code
130793         , p_component_appl_id       => l_component_appl_id
130794         , p_amb_context_code        => l_amb_context_code
130795         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
130796         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
130797         , p_side                    => 'NA'
130798         );
130799 
130800   END IF;
130801 
130802    --
130803    --
130804    END IF;
130805 
130806        --
130807        -- Update the line information that should be overwritten
130808        --
130809        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
130810                                          p_header_num   => 1);
130811        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
130812 
130813        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
130814 
130815        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
130816           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
130817        END IF;
130818 
130819       --
130820       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
130821       --
130822       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
130823           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
130824       ELSE
130825           ---------------------------------------------------------------------------------------------------
130826           -- 4262811a Switch Sign
130827           ---------------------------------------------------------------------------------------------------
130828           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
130829           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
130830                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
130831           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
130832                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
130833           -- 5132302
130834           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
130835                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
130836 
130837       END IF;
130838 
130839       -- 4955764
130840       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
130841       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
130842 
130843 
130844       XLA_AE_LINES_PKG.ValidateCurrentLine;
130845       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
130846 
130847       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
130848                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
130849                ,p_balance_type_code => l_balance_type_code);
130850 
130851    END IF;
130852 
130853    -----------------------------------------------------------------------------------------
130854    -- 4262811 Multiperiod Accounting
130855    -----------------------------------------------------------------------------------------
130856      -- No MPA option is assigned.
130857 
130858 
130859 END IF;
130860 END IF;
130861 --
130862 
130863 --
130864 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
130865    trace
130866       (p_msg      => 'END of AcctLineType_337'
130867       ,p_level    => C_LEVEL_PROCEDURE
130868       ,p_module   => l_log_module);
130869 END IF;
130870 --
130874   WHEN OTHERS THEN
130871 EXCEPTION
130872   WHEN xla_exceptions_pkg.application_exception THEN
130873       RAISE;
130875        xla_exceptions_pkg.raise_message
130876            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_337');
130877 END AcctLineType_337;
130878 --
130879 
130880 ---------------------------------------
130881 --
130882 -- PRIVATE FUNCTION
130883 --         AcctLineType_338
130884 --
130885 ---------------------------------------
130886 PROCEDURE AcctLineType_338 (
130887   p_application_id        IN NUMBER
130888  ,p_event_id              IN NUMBER
130889  ,p_calculate_acctd_flag  IN VARCHAR2
130890  ,p_calculate_g_l_flag    IN VARCHAR2
130891  ,p_actual_flag           IN OUT VARCHAR2
130892  ,p_balance_type_code     OUT VARCHAR2
130893  ,p_gain_or_loss_ref      OUT VARCHAR2
130894  
130895 --Period Close Date
130896  , p_source_1            IN DATE
130897 --Generated Code Combination Identifier
130898  , p_source_3            IN NUMBER
130899 --CIP Cost Account
130900  , p_source_7            IN VARCHAR2
130901 --Expense Account Code Combination Identifier
130902  , p_source_29            IN NUMBER
130903 --Default Code Combination Identifier
130904  , p_source_30            IN NUMBER
130905 --Adjustment Type
130906  , p_source_35            IN VARCHAR2
130907 --Transaction Header Identifier
130908  , p_source_36            IN NUMBER
130909 --Adjustment Line Identifier
130910  , p_source_37            IN NUMBER
130911 --Distribution Type Code
130912  , p_source_38            IN VARCHAR2
130913 --Entered Amount
130914  , p_source_39            IN NUMBER
130915 --Currency Code
130916  , p_source_40            IN VARCHAR2
130917 --Source Destination Code
130918  , p_source_42            IN VARCHAR2
130919 )
130920 IS
130921 
130922 l_component_type              VARCHAR2(80);
130923 l_component_code              VARCHAR2(30);
130924 l_component_type_code         VARCHAR2(1);
130925 l_component_appl_id           INTEGER;
130926 l_amb_context_code            VARCHAR2(30);
130927 l_entity_code                 VARCHAR2(30);
130928 l_event_class_code            VARCHAR2(30);
130929 l_ae_header_id                NUMBER;
130930 l_event_type_code             VARCHAR2(30);
130931 l_line_definition_code        VARCHAR2(30);
130932 l_line_definition_owner_code  VARCHAR2(1);
130933 --
130934 -- adr variables
130935 l_segment                     VARCHAR2(30);
130936 l_ccid                        NUMBER;
130937 l_adr_transaction_coa_id      NUMBER;
130938 l_adr_accounting_coa_id       NUMBER;
130939 l_adr_flexfield_segment_code  VARCHAR2(30);
130940 l_adr_flex_value_set_id       NUMBER;
130941 l_adr_value_type_code         VARCHAR2(30);
130942 l_adr_value_combination_id    NUMBER;
130943 l_adr_value_segment_code      VARCHAR2(30);
130944 
130945 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
130946 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
130947 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
130948 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
130949 
130950 -- 4262811 Variables ------------------------------------------------------------------------------------------
130951 l_entered_amt_idx             NUMBER;
130952 l_accted_amt_idx              NUMBER;
130953 l_acc_rev_flag                VARCHAR2(1);
130954 l_accrual_line_num            NUMBER;
130955 l_tmp_amt                     NUMBER;
130956 l_acc_rev_natural_side_code   VARCHAR2(1);
130957 
130958 l_num_entries                 NUMBER;
130959 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
130960 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
130961 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
130962 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
130963 l_recog_line_1                NUMBER;
130964 l_recog_line_2                NUMBER;
130965 
130966 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
130967 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
130968 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
130969 
130970 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
130971 
130972 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
130973 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
130974 
130975 ---------------------------------------------------------------------------------------------------------------
130976 
130977 
130978 --
130979 -- bulk performance
130980 --
130981 l_balance_type_code           VARCHAR2(1);
130982 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
130983 l_log_module                  VARCHAR2(240);
130984 
130985 --
130986 -- Upgrade strategy
130987 --
130988 l_actual_upg_option           VARCHAR2(1);
130989 l_enc_upg_option           VARCHAR2(1);
130990 
130991 --
130992 BEGIN
130993 --
130994 IF g_log_enabled THEN
130995       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_338';
130996 END IF;
130997 --
130998 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
130999 
131000       trace
131001          (p_msg      => 'BEGIN of AcctLineType_338'
131002          ,p_level    => C_LEVEL_PROCEDURE
131003          ,p_module   => l_log_module);
131004 
131005 END IF;
131006 --
131007 l_component_type             := 'AMB_JLT';
131008 l_component_code             := 'FA_SLT_DEST_CIP_COST';
131009 l_component_type_code        := 'S';
131010 l_component_appl_id          :=  140;
131011 l_amb_context_code           := 'DEFAULT';
131012 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
131013 l_event_class_code           := 'CIP_SOURCE_LINE_TRANSFERS';
131014 l_event_type_code            := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
131018 l_balance_type_code          := 'A';
131015 l_line_definition_owner_code := 'S';
131016 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_S11';
131017 --
131019 l_segment                     := NULL;
131020 l_ccid                        := NULL;
131021 l_adr_transaction_coa_id      := NULL;
131022 l_adr_accounting_coa_id       := NULL;
131023 l_adr_flexfield_segment_code  := NULL;
131024 l_adr_flex_value_set_id       := NULL;
131025 l_adr_value_type_code         := NULL;
131026 l_adr_value_combination_id    := NULL;
131027 l_adr_value_segment_code      := NULL;
131028 
131029 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
131030 l_bflow_class_code           := '';    -- 4219869 Business Flow
131031 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
131032 l_budgetary_control_flag     := 'N';
131033 
131034 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
131035 l_bflow_applied_to_amt       := NULL; -- 5132302
131036 l_entered_amt_idx            := NULL;          -- 4262811
131037 l_accted_amt_idx             := NULL;          -- 4262811
131038 l_acc_rev_flag               := NULL;          -- 4262811
131039 l_accrual_line_num           := NULL;          -- 4262811
131040 l_tmp_amt                    := NULL;          -- 4262811
131041 --
131042  
131043 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
131044     l_balance_type_code <> 'B' THEN
131045 IF NVL(p_source_35,'
131046 ') =  'CIP COST' AND 
131047 NVL(p_source_42,'
131048 ') =  'DEST'
131049  THEN 
131050 
131051    --
131052    XLA_AE_LINES_PKG.SetNewLine;
131053 
131054    p_balance_type_code          := l_balance_type_code;
131055    -- set the flag so later we will know whether the gain loss line needs to be created
131056    
131057    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
131058      p_actual_flag :='A';
131059    END IF;
131060 
131061    --
131062    -- bulk performance
131063    --
131064    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
131065                                       p_header_num   => 0); -- 4262811
131066    --
131067    -- set accounting line options
131068    --
131069    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
131070            p_natural_side_code          => 'D'
131071          , p_gain_or_loss_flag          => 'N'
131072          , p_gl_transfer_mode_code      => 'S'
131073          , p_acct_entry_type_code       => 'A'
131074          , p_switch_side_flag           => 'Y'
131075          , p_merge_duplicate_code       => 'N'
131076          );
131077    --
131078    l_acc_rev_natural_side_code := 'C';  -- 4262811
131079    -- 
131080    --
131081    -- set accounting line type info
131082    --
131083    xla_ae_lines_pkg.SetAcctLineType
131084       (p_component_type             => l_component_type
131085       ,p_event_type_code            => l_event_type_code
131086       ,p_line_definition_owner_code => l_line_definition_owner_code
131087       ,p_line_definition_code       => l_line_definition_code
131088       ,p_accounting_line_code       => l_component_code
131089       ,p_accounting_line_type_code  => l_component_type_code
131090       ,p_accounting_line_appl_id    => l_component_appl_id
131091       ,p_amb_context_code           => l_amb_context_code
131092       ,p_entity_code                => l_entity_code
131093       ,p_event_class_code           => l_event_class_code);
131094    --
131095    -- set accounting class
131096    --
131097    xla_ae_lines_pkg.SetAcctClass(
131098            p_accounting_class_code  => 'ASSET'
131099          , p_ae_header_id           => l_ae_header_id
131100          );
131101 
131102    --
131103    -- set rounding class
131104    --
131105    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
131106                       'ASSET';
131107 
131108    --
131109    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
131110    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
131111    --
131112    -- bulk performance
131113    --
131114    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
131115 
131116    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
131117       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
131118 
131119    -- 4955764
131120    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
131121       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
131122 
131123    -- 4458381 Public Sector Enh
131124    
131125    --
131126    -- set accounting attributes for the line type
131127    --
131128    l_entered_amt_idx := 4;
131129    l_accted_amt_idx  := 6;
131130    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
131131    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
131132    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
131133    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
131134    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
131135    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
131136    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
131137    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
131138    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
131139    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
131140    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
131141    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
131142    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
131143 
131144    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
131145    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
131149    ---------------------------------------------------------------------------------------------------------------
131146 
131147    ---------------------------------------------------------------------------------------------------------------
131148    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
131150    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
131151 
131152    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
131153    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
131154 
131155    IF xla_accounting_cache_pkg.GetValueChar
131156          (p_source_code         => 'LEDGER_CATEGORY_CODE'
131157          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
131158    AND l_bflow_method_code = 'PRIOR_ENTRY'
131159 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
131160    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
131161          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
131162        )
131163    THEN
131164          xla_ae_lines_pkg.BflowUpgEntry
131165            (p_business_method_code    => l_bflow_method_code
131166            ,p_business_class_code     => l_bflow_class_code
131167            ,p_balance_type            => l_balance_type_code);
131168    ELSE
131169       NULL;
131170 -- No business flow processing for business flow method of NONE.
131171    END IF;
131172 
131173    --
131174    -- call analytical criteria
131175    --
131176    
131177    --
131178    -- call description
131179    --
131180    
131181 xla_ae_lines_pkg.SetLineDescription(
131182    p_ae_header_id => l_ae_header_id
131183   ,p_description  => Description_105 (
131184      p_application_id         => p_application_id
131185    , p_ae_header_id           => l_ae_header_id 
131186 , p_source_1 => p_source_1
131187    )
131188 );
131189 
131190 
131191    --
131192    -- call ADRs
131193    -- Bug 4922099
131194    --
131195    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
131196         (NVL(l_actual_upg_option, 'N') = 'O') OR
131197         (NVL(l_enc_upg_option, 'N') = 'O')
131198       )
131199    THEN
131200    NULL;
131201    --
131202    --
131203    
131204   l_ccid := AcctDerRule_173(
131205            p_application_id           => p_application_id
131206          , p_ae_header_id             => l_ae_header_id 
131207 , p_source_3 => p_source_3
131208 , p_source_30 => p_source_30
131209          , x_transaction_coa_id       => l_adr_transaction_coa_id
131210          , x_accounting_coa_id        => l_adr_accounting_coa_id
131211          , x_value_type_code          => l_adr_value_type_code
131212          , p_side                     => 'NA'
131213    );
131214 
131215    xla_ae_lines_pkg.set_ccid(
131216     p_code_combination_id          => l_ccid
131217   , p_value_type_code              => l_adr_value_type_code
131218   , p_transaction_coa_id           => l_adr_transaction_coa_id
131219   , p_accounting_coa_id            => l_adr_accounting_coa_id
131220   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
131221   , p_adr_type_code                => 'S'
131222   , p_component_type               => l_component_type
131223   , p_component_code               => l_component_code
131224   , p_component_type_code          => l_component_type_code
131225   , p_component_appl_id            => l_component_appl_id
131226   , p_amb_context_code             => l_amb_context_code
131227   , p_side                         => 'NA'
131228   );
131229 
131230 
131231    l_segment := AcctDerRule_146(
131232            p_application_id           => p_application_id
131233          , p_ae_header_id             => l_ae_header_id 
131234 , p_source_3 => p_source_3
131235 , p_source_7 => p_source_7
131236          , x_transaction_coa_id       => l_adr_transaction_coa_id
131237          , x_accounting_coa_id        => l_adr_accounting_coa_id
131238          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
131239          , x_flex_value_set_id        => l_adr_flex_value_set_id
131240          , x_value_type_code          => l_adr_value_type_code
131241          , x_value_combination_id     => l_adr_value_combination_id
131242          , x_value_segment_code       => l_adr_value_segment_code
131243          , p_side                     => 'NA'
131244          , p_override_seg_flag        => 'Y'
131245    );
131246 
131247    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
131248 
131249       xla_ae_lines_pkg.set_segment(
131250           p_to_segment_code         => 'GL_ACCOUNT'
131251         , p_segment_value           => l_segment
131252         , p_from_segment_code       => l_adr_value_segment_code
131253         , p_from_combination_id     => l_adr_value_combination_id
131254         , p_value_type_code         => l_adr_value_type_code
131255         , p_transaction_coa_id      => l_adr_transaction_coa_id
131256         , p_accounting_coa_id       => l_adr_accounting_coa_id
131257         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
131258         , p_flex_value_set_id       => l_adr_flex_value_set_id
131259         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
131260         , p_adr_type_code           => 'S'
131261         , p_component_type          => l_component_type
131262         , p_component_code          => l_component_code
131263         , p_component_type_code     => l_component_type_code
131264         , p_component_appl_id       => l_component_appl_id
131265         , p_amb_context_code        => l_amb_context_code
131266         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
131267         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
131268         , p_side                    => 'NA'
131269         );
131270 
131271   END IF;
131272 
131273    l_segment := AcctDerRule_168(
131277 , p_source_29 => p_source_29
131274            p_application_id           => p_application_id
131275          , p_ae_header_id             => l_ae_header_id 
131276 , p_source_3 => p_source_3
131278          , x_transaction_coa_id       => l_adr_transaction_coa_id
131279          , x_accounting_coa_id        => l_adr_accounting_coa_id
131280          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
131281          , x_flex_value_set_id        => l_adr_flex_value_set_id
131282          , x_value_type_code          => l_adr_value_type_code
131283          , x_value_combination_id     => l_adr_value_combination_id
131284          , x_value_segment_code       => l_adr_value_segment_code
131285          , p_side                     => 'NA'
131286          , p_override_seg_flag        => 'Y'
131287    );
131288 
131289    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
131290 
131291       xla_ae_lines_pkg.set_segment(
131292           p_to_segment_code         => 'GL_BALANCING'
131293         , p_segment_value           => l_segment
131294         , p_from_segment_code       => l_adr_value_segment_code
131295         , p_from_combination_id     => l_adr_value_combination_id
131296         , p_value_type_code         => l_adr_value_type_code
131297         , p_transaction_coa_id      => l_adr_transaction_coa_id
131298         , p_accounting_coa_id       => l_adr_accounting_coa_id
131299         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
131300         , p_flex_value_set_id       => l_adr_flex_value_set_id
131301         , p_adr_code                => 'FA_EXPENSE_ACCT'
131302         , p_adr_type_code           => 'S'
131303         , p_component_type          => l_component_type
131304         , p_component_code          => l_component_code
131305         , p_component_type_code     => l_component_type_code
131306         , p_component_appl_id       => l_component_appl_id
131307         , p_amb_context_code        => l_amb_context_code
131308         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
131309         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
131310         , p_side                    => 'NA'
131311         );
131312 
131313   END IF;
131314 
131315    --
131316    --
131317    END IF;
131318    --
131319    -- Bug 4922099
131320    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
131321           (NVL(l_enc_upg_option, 'N') = 'O')
131322         ) AND
131323         (l_bflow_method_code = 'PRIOR_ENTRY')
131324       )
131325    THEN
131326       IF
131327       --
131328       1 = 2
131329       --
131330       THEN
131331       xla_accounting_err_pkg.build_message
131332                                     (p_appli_s_name            => 'XLA'
131333                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
131334                                     ,p_token_1                 => 'LINE_NUMBER'
131335                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
131336                                     ,p_token_2                 => 'LINE_TYPE_NAME'
131337                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
131338                                                                              l_component_type
131339                                                                             ,l_component_code
131340                                                                             ,l_component_type_code
131341                                                                             ,l_component_appl_id
131342                                                                             ,l_amb_context_code
131343                                                                             ,l_entity_code
131344                                                                             ,l_event_class_code
131345                                                                            )
131346                                     ,p_token_3                 => 'OWNER'
131347                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
131348                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
131349                                                                           ,p_lookup_code    => l_component_type_code
131350                                                                          )
131351                                     ,p_token_4                 => 'PRODUCT_NAME'
131352                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
131353                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
131354                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
131355                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
131356                                     ,p_ae_header_id            =>  NULL
131357                                        );
131358 
131359         IF (C_LEVEL_ERROR>= g_log_level) THEN
131360                  trace
131361                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
131362                       ,p_level    => C_LEVEL_ERROR
131363                       ,p_module   => l_log_module);
131364         END IF;
131365       END IF;
131366    END IF;
131367    --
131368    --
131369    ------------------------------------------------------------------------------------------------
131370    -- 4219869 Business Flow
131371    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
131372    -- Prior Entry.  Currently, the following code is always generated.
131373    ------------------------------------------------------------------------------------------------
131374    XLA_AE_LINES_PKG.ValidateCurrentLine;
131375 
131376    ------------------------------------------------------------------------------------
131377    -- 4219869 Business Flow
131381 
131378    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
131379    ------------------------------------------------------------------------------------
131380    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
131382    ----------------------------------------------------------------------------------
131383    -- 4219869 Business Flow
131384    -- Update journal entry status -- Need to generate this within IF <condition>
131385    ----------------------------------------------------------------------------------
131386    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
131387          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
131388          ,p_balance_type_code => l_balance_type_code
131389          );
131390 
131391    -------------------------------------------------------------------------------------------
131392    -- 4262811 - Generate the Accrual Reversal lines
131393    -------------------------------------------------------------------------------------------
131394    BEGIN
131395       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
131396                               (g_array_event(p_event_id).array_value_num('header_index'));
131397       IF l_acc_rev_flag IS NULL THEN
131398          l_acc_rev_flag := 'N';
131399       END IF;
131400    EXCEPTION
131401       WHEN OTHERS THEN
131402          l_acc_rev_flag := 'N';
131403    END;
131404    --
131405    IF (l_acc_rev_flag = 'Y') THEN
131406 
131407        -- 4645092  ------------------------------------------------------------------------------
131408        -- To allow MPA report to determine if it should generate report process
131409        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
131410        ------------------------------------------------------------------------------------------
131411 
131412        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
131413        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
131414    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
131415    -- call ADRs
131416    -- Bug 4922099
131417    --
131418    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
131419         (NVL(l_actual_upg_option, 'N') = 'O') OR
131420         (NVL(l_enc_upg_option, 'N') = 'O')
131421       )
131422    THEN
131423    NULL;
131424    --
131425    --
131426    
131427   l_ccid := AcctDerRule_173(
131428            p_application_id           => p_application_id
131429          , p_ae_header_id             => l_ae_header_id 
131430 , p_source_3 => p_source_3
131431 , p_source_30 => p_source_30
131432          , x_transaction_coa_id       => l_adr_transaction_coa_id
131433          , x_accounting_coa_id        => l_adr_accounting_coa_id
131434          , x_value_type_code          => l_adr_value_type_code
131435          , p_side                     => 'NA'
131436    );
131437 
131438    xla_ae_lines_pkg.set_ccid(
131439     p_code_combination_id          => l_ccid
131440   , p_value_type_code              => l_adr_value_type_code
131441   , p_transaction_coa_id           => l_adr_transaction_coa_id
131442   , p_accounting_coa_id            => l_adr_accounting_coa_id
131443   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
131444   , p_adr_type_code                => 'S'
131445   , p_component_type               => l_component_type
131446   , p_component_code               => l_component_code
131447   , p_component_type_code          => l_component_type_code
131448   , p_component_appl_id            => l_component_appl_id
131449   , p_amb_context_code             => l_amb_context_code
131450   , p_side                         => 'NA'
131451   );
131452 
131453 
131454    l_segment := AcctDerRule_146(
131455            p_application_id           => p_application_id
131456          , p_ae_header_id             => l_ae_header_id 
131457 , p_source_3 => p_source_3
131458 , p_source_7 => p_source_7
131459          , x_transaction_coa_id       => l_adr_transaction_coa_id
131460          , x_accounting_coa_id        => l_adr_accounting_coa_id
131461          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
131462          , x_flex_value_set_id        => l_adr_flex_value_set_id
131463          , x_value_type_code          => l_adr_value_type_code
131464          , x_value_combination_id     => l_adr_value_combination_id
131465          , x_value_segment_code       => l_adr_value_segment_code
131466          , p_side                     => 'NA'
131467          , p_override_seg_flag        => 'Y'
131468    );
131469 
131470    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
131471 
131472       xla_ae_lines_pkg.set_segment(
131473           p_to_segment_code         => 'GL_ACCOUNT'
131474         , p_segment_value           => l_segment
131475         , p_from_segment_code       => l_adr_value_segment_code
131476         , p_from_combination_id     => l_adr_value_combination_id
131477         , p_value_type_code         => l_adr_value_type_code
131478         , p_transaction_coa_id      => l_adr_transaction_coa_id
131479         , p_accounting_coa_id       => l_adr_accounting_coa_id
131480         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
131481         , p_flex_value_set_id       => l_adr_flex_value_set_id
131482         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
131483         , p_adr_type_code           => 'S'
131484         , p_component_type          => l_component_type
131485         , p_component_code          => l_component_code
131486         , p_component_type_code     => l_component_type_code
131487         , p_component_appl_id       => l_component_appl_id
131488         , p_amb_context_code        => l_amb_context_code
131489         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
131490         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
131491         , p_side                    => 'NA'
131492         );
131493 
131494   END IF;
131495 
131496    l_segment := AcctDerRule_168(
131497            p_application_id           => p_application_id
131501          , x_transaction_coa_id       => l_adr_transaction_coa_id
131498          , p_ae_header_id             => l_ae_header_id 
131499 , p_source_3 => p_source_3
131500 , p_source_29 => p_source_29
131502          , x_accounting_coa_id        => l_adr_accounting_coa_id
131503          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
131504          , x_flex_value_set_id        => l_adr_flex_value_set_id
131505          , x_value_type_code          => l_adr_value_type_code
131506          , x_value_combination_id     => l_adr_value_combination_id
131507          , x_value_segment_code       => l_adr_value_segment_code
131508          , p_side                     => 'NA'
131509          , p_override_seg_flag        => 'Y'
131510    );
131511 
131512    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
131513 
131514       xla_ae_lines_pkg.set_segment(
131515           p_to_segment_code         => 'GL_BALANCING'
131516         , p_segment_value           => l_segment
131517         , p_from_segment_code       => l_adr_value_segment_code
131518         , p_from_combination_id     => l_adr_value_combination_id
131519         , p_value_type_code         => l_adr_value_type_code
131520         , p_transaction_coa_id      => l_adr_transaction_coa_id
131521         , p_accounting_coa_id       => l_adr_accounting_coa_id
131522         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
131523         , p_flex_value_set_id       => l_adr_flex_value_set_id
131524         , p_adr_code                => 'FA_EXPENSE_ACCT'
131525         , p_adr_type_code           => 'S'
131526         , p_component_type          => l_component_type
131527         , p_component_code          => l_component_code
131528         , p_component_type_code     => l_component_type_code
131529         , p_component_appl_id       => l_component_appl_id
131530         , p_amb_context_code        => l_amb_context_code
131531         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
131532         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
131533         , p_side                    => 'NA'
131534         );
131535 
131536   END IF;
131537 
131538    --
131539    --
131540    END IF;
131541 
131542        --
131543        -- Update the line information that should be overwritten
131544        --
131545        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
131546                                          p_header_num   => 1);
131547        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
131548 
131549        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
131550 
131551        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
131552           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
131553        END IF;
131554 
131555       --
131556       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
131557       --
131558       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
131559           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
131560       ELSE
131561           ---------------------------------------------------------------------------------------------------
131562           -- 4262811a Switch Sign
131563           ---------------------------------------------------------------------------------------------------
131564           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
131565           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
131566                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
131567           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
131568                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
131569           -- 5132302
131570           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
131571                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
131572 
131573       END IF;
131574 
131575       -- 4955764
131576       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
131577       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
131578 
131579 
131580       XLA_AE_LINES_PKG.ValidateCurrentLine;
131581       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
131582 
131583       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
131584                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
131585                ,p_balance_type_code => l_balance_type_code);
131586 
131587    END IF;
131588 
131589    -----------------------------------------------------------------------------------------
131590    -- 4262811 Multiperiod Accounting
131591    -----------------------------------------------------------------------------------------
131592      -- No MPA option is assigned.
131593 
131594 
131595 END IF;
131596 END IF;
131597 --
131598 
131599 --
131600 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
131601    trace
131602       (p_msg      => 'END of AcctLineType_338'
131603       ,p_level    => C_LEVEL_PROCEDURE
131604       ,p_module   => l_log_module);
131605 END IF;
131606 --
131607 EXCEPTION
131608   WHEN xla_exceptions_pkg.application_exception THEN
131609       RAISE;
131610   WHEN OTHERS THEN
131611        xla_exceptions_pkg.raise_message
131612            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_338');
131613 END AcctLineType_338;
131614 --
131615 
131616 ---------------------------------------
131617 --
131618 -- PRIVATE FUNCTION
131619 --         AcctLineType_339
131620 --
131624  ,p_event_id              IN NUMBER
131621 ---------------------------------------
131622 PROCEDURE AcctLineType_339 (
131623   p_application_id        IN NUMBER
131625  ,p_calculate_acctd_flag  IN VARCHAR2
131626  ,p_calculate_g_l_flag    IN VARCHAR2
131627  ,p_actual_flag           IN OUT VARCHAR2
131628  ,p_balance_type_code     OUT VARCHAR2
131629  ,p_gain_or_loss_ref      OUT VARCHAR2
131630  
131631 --Period Close Date
131632  , p_source_1            IN DATE
131633 --Generated Code Combination Identifier
131634  , p_source_3            IN NUMBER
131635 --CIP Cost Account
131636  , p_source_7            IN VARCHAR2
131637 --Expense Account Code Combination Identifier
131638  , p_source_29            IN NUMBER
131639 --Default Code Combination Identifier
131640  , p_source_30            IN NUMBER
131641 --Adjustment Type
131642  , p_source_35            IN VARCHAR2
131643 --Transaction Header Identifier
131644  , p_source_36            IN NUMBER
131645 --Adjustment Line Identifier
131646  , p_source_37            IN NUMBER
131647 --Distribution Type Code
131648  , p_source_38            IN VARCHAR2
131649 --Entered Amount
131650  , p_source_39            IN NUMBER
131651 --Currency Code
131652  , p_source_40            IN VARCHAR2
131653 --Source Destination Code
131654  , p_source_42            IN VARCHAR2
131655 )
131656 IS
131657 
131658 l_component_type              VARCHAR2(80);
131659 l_component_code              VARCHAR2(30);
131660 l_component_type_code         VARCHAR2(1);
131661 l_component_appl_id           INTEGER;
131662 l_amb_context_code            VARCHAR2(30);
131663 l_entity_code                 VARCHAR2(30);
131664 l_event_class_code            VARCHAR2(30);
131665 l_ae_header_id                NUMBER;
131666 l_event_type_code             VARCHAR2(30);
131667 l_line_definition_code        VARCHAR2(30);
131668 l_line_definition_owner_code  VARCHAR2(1);
131669 --
131670 -- adr variables
131671 l_segment                     VARCHAR2(30);
131672 l_ccid                        NUMBER;
131673 l_adr_transaction_coa_id      NUMBER;
131674 l_adr_accounting_coa_id       NUMBER;
131675 l_adr_flexfield_segment_code  VARCHAR2(30);
131676 l_adr_flex_value_set_id       NUMBER;
131677 l_adr_value_type_code         VARCHAR2(30);
131678 l_adr_value_combination_id    NUMBER;
131679 l_adr_value_segment_code      VARCHAR2(30);
131680 
131681 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
131682 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
131683 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
131684 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
131685 
131686 -- 4262811 Variables ------------------------------------------------------------------------------------------
131687 l_entered_amt_idx             NUMBER;
131688 l_accted_amt_idx              NUMBER;
131689 l_acc_rev_flag                VARCHAR2(1);
131690 l_accrual_line_num            NUMBER;
131691 l_tmp_amt                     NUMBER;
131692 l_acc_rev_natural_side_code   VARCHAR2(1);
131693 
131694 l_num_entries                 NUMBER;
131695 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
131696 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
131697 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
131698 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
131699 l_recog_line_1                NUMBER;
131700 l_recog_line_2                NUMBER;
131701 
131702 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
131703 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
131704 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
131705 
131706 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
131707 
131708 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
131709 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
131710 
131711 ---------------------------------------------------------------------------------------------------------------
131712 
131713 
131714 --
131715 -- bulk performance
131716 --
131717 l_balance_type_code           VARCHAR2(1);
131718 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
131719 l_log_module                  VARCHAR2(240);
131720 
131721 --
131722 -- Upgrade strategy
131723 --
131724 l_actual_upg_option           VARCHAR2(1);
131725 l_enc_upg_option           VARCHAR2(1);
131726 
131727 --
131728 BEGIN
131729 --
131730 IF g_log_enabled THEN
131731       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_339';
131732 END IF;
131733 --
131734 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
131735 
131736       trace
131737          (p_msg      => 'BEGIN of AcctLineType_339'
131738          ,p_level    => C_LEVEL_PROCEDURE
131739          ,p_module   => l_log_module);
131740 
131741 END IF;
131742 --
131743 l_component_type             := 'AMB_JLT';
131744 l_component_code             := 'FA_SLT_DEST_CIP_COST';
131745 l_component_type_code        := 'S';
131746 l_component_appl_id          :=  140;
131747 l_amb_context_code           := 'DEFAULT';
131748 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
131749 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
131750 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
131751 l_line_definition_owner_code := 'S';
131752 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
131753 --
131754 l_balance_type_code          := 'A';
131755 l_segment                     := NULL;
131756 l_ccid                        := NULL;
131757 l_adr_transaction_coa_id      := NULL;
131758 l_adr_accounting_coa_id       := NULL;
131759 l_adr_flexfield_segment_code  := NULL;
131760 l_adr_flex_value_set_id       := NULL;
131761 l_adr_value_type_code         := NULL;
131765 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
131762 l_adr_value_combination_id    := NULL;
131763 l_adr_value_segment_code      := NULL;
131764 
131766 l_bflow_class_code           := '';    -- 4219869 Business Flow
131767 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
131768 l_budgetary_control_flag     := 'N';
131769 
131770 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
131771 l_bflow_applied_to_amt       := NULL; -- 5132302
131772 l_entered_amt_idx            := NULL;          -- 4262811
131773 l_accted_amt_idx             := NULL;          -- 4262811
131774 l_acc_rev_flag               := NULL;          -- 4262811
131775 l_accrual_line_num           := NULL;          -- 4262811
131776 l_tmp_amt                    := NULL;          -- 4262811
131777 --
131778  
131779 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
131780     l_balance_type_code <> 'B' THEN
131781 IF NVL(p_source_35,'
131782 ') =  'CIP COST' AND 
131783 NVL(p_source_42,'
131784 ') =  'DEST'
131785  THEN 
131786 
131787    --
131788    XLA_AE_LINES_PKG.SetNewLine;
131789 
131790    p_balance_type_code          := l_balance_type_code;
131791    -- set the flag so later we will know whether the gain loss line needs to be created
131792    
131793    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
131794      p_actual_flag :='A';
131795    END IF;
131796 
131797    --
131798    -- bulk performance
131799    --
131800    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
131801                                       p_header_num   => 0); -- 4262811
131802    --
131803    -- set accounting line options
131804    --
131805    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
131806            p_natural_side_code          => 'D'
131807          , p_gain_or_loss_flag          => 'N'
131808          , p_gl_transfer_mode_code      => 'S'
131809          , p_acct_entry_type_code       => 'A'
131810          , p_switch_side_flag           => 'Y'
131811          , p_merge_duplicate_code       => 'N'
131812          );
131813    --
131814    l_acc_rev_natural_side_code := 'C';  -- 4262811
131815    -- 
131816    --
131817    -- set accounting line type info
131818    --
131819    xla_ae_lines_pkg.SetAcctLineType
131820       (p_component_type             => l_component_type
131821       ,p_event_type_code            => l_event_type_code
131822       ,p_line_definition_owner_code => l_line_definition_owner_code
131823       ,p_line_definition_code       => l_line_definition_code
131824       ,p_accounting_line_code       => l_component_code
131825       ,p_accounting_line_type_code  => l_component_type_code
131826       ,p_accounting_line_appl_id    => l_component_appl_id
131827       ,p_amb_context_code           => l_amb_context_code
131828       ,p_entity_code                => l_entity_code
131829       ,p_event_class_code           => l_event_class_code);
131830    --
131831    -- set accounting class
131832    --
131833    xla_ae_lines_pkg.SetAcctClass(
131834            p_accounting_class_code  => 'ASSET'
131835          , p_ae_header_id           => l_ae_header_id
131836          );
131837 
131838    --
131839    -- set rounding class
131840    --
131841    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
131842                       'ASSET';
131843 
131844    --
131845    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
131846    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
131847    --
131848    -- bulk performance
131849    --
131850    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
131851 
131852    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
131853       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
131854 
131855    -- 4955764
131856    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
131857       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
131858 
131859    -- 4458381 Public Sector Enh
131860    
131861    --
131862    -- set accounting attributes for the line type
131863    --
131864    l_entered_amt_idx := 4;
131865    l_accted_amt_idx  := 6;
131866    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
131867    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
131868    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
131869    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
131870    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
131871    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
131872    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
131873    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
131874    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
131875    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
131876    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
131877    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
131878    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
131879 
131880    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
131881    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
131882 
131883    ---------------------------------------------------------------------------------------------------------------
131884    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
131885    ---------------------------------------------------------------------------------------------------------------
131886    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
131887 
131891    IF xla_accounting_cache_pkg.GetValueChar
131888    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
131889    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
131890 
131892          (p_source_code         => 'LEDGER_CATEGORY_CODE'
131893          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
131894    AND l_bflow_method_code = 'PRIOR_ENTRY'
131895 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
131896    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
131897          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
131898        )
131899    THEN
131900          xla_ae_lines_pkg.BflowUpgEntry
131901            (p_business_method_code    => l_bflow_method_code
131902            ,p_business_class_code     => l_bflow_class_code
131903            ,p_balance_type            => l_balance_type_code);
131904    ELSE
131905       NULL;
131906 -- No business flow processing for business flow method of NONE.
131907    END IF;
131908 
131909    --
131910    -- call analytical criteria
131911    --
131912    
131913    --
131914    -- call description
131915    --
131916    
131917 xla_ae_lines_pkg.SetLineDescription(
131918    p_ae_header_id => l_ae_header_id
131919   ,p_description  => Description_105 (
131920      p_application_id         => p_application_id
131921    , p_ae_header_id           => l_ae_header_id 
131922 , p_source_1 => p_source_1
131923    )
131924 );
131925 
131926 
131927    --
131928    -- call ADRs
131929    -- Bug 4922099
131930    --
131931    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
131932         (NVL(l_actual_upg_option, 'N') = 'O') OR
131933         (NVL(l_enc_upg_option, 'N') = 'O')
131934       )
131935    THEN
131936    NULL;
131937    --
131938    --
131939    
131940   l_ccid := AcctDerRule_173(
131941            p_application_id           => p_application_id
131942          , p_ae_header_id             => l_ae_header_id 
131943 , p_source_3 => p_source_3
131944 , p_source_30 => p_source_30
131945          , x_transaction_coa_id       => l_adr_transaction_coa_id
131946          , x_accounting_coa_id        => l_adr_accounting_coa_id
131947          , x_value_type_code          => l_adr_value_type_code
131948          , p_side                     => 'NA'
131949    );
131950 
131951    xla_ae_lines_pkg.set_ccid(
131952     p_code_combination_id          => l_ccid
131953   , p_value_type_code              => l_adr_value_type_code
131954   , p_transaction_coa_id           => l_adr_transaction_coa_id
131955   , p_accounting_coa_id            => l_adr_accounting_coa_id
131956   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
131957   , p_adr_type_code                => 'S'
131958   , p_component_type               => l_component_type
131959   , p_component_code               => l_component_code
131960   , p_component_type_code          => l_component_type_code
131961   , p_component_appl_id            => l_component_appl_id
131962   , p_amb_context_code             => l_amb_context_code
131963   , p_side                         => 'NA'
131964   );
131965 
131966 
131967    l_segment := AcctDerRule_146(
131968            p_application_id           => p_application_id
131969          , p_ae_header_id             => l_ae_header_id 
131970 , p_source_3 => p_source_3
131971 , p_source_7 => p_source_7
131972          , x_transaction_coa_id       => l_adr_transaction_coa_id
131973          , x_accounting_coa_id        => l_adr_accounting_coa_id
131974          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
131975          , x_flex_value_set_id        => l_adr_flex_value_set_id
131976          , x_value_type_code          => l_adr_value_type_code
131977          , x_value_combination_id     => l_adr_value_combination_id
131978          , x_value_segment_code       => l_adr_value_segment_code
131979          , p_side                     => 'NA'
131980          , p_override_seg_flag        => 'Y'
131981    );
131982 
131983    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
131984 
131985       xla_ae_lines_pkg.set_segment(
131986           p_to_segment_code         => 'GL_ACCOUNT'
131987         , p_segment_value           => l_segment
131988         , p_from_segment_code       => l_adr_value_segment_code
131989         , p_from_combination_id     => l_adr_value_combination_id
131990         , p_value_type_code         => l_adr_value_type_code
131991         , p_transaction_coa_id      => l_adr_transaction_coa_id
131992         , p_accounting_coa_id       => l_adr_accounting_coa_id
131993         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
131994         , p_flex_value_set_id       => l_adr_flex_value_set_id
131995         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
131996         , p_adr_type_code           => 'S'
131997         , p_component_type          => l_component_type
131998         , p_component_code          => l_component_code
131999         , p_component_type_code     => l_component_type_code
132000         , p_component_appl_id       => l_component_appl_id
132001         , p_amb_context_code        => l_amb_context_code
132002         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
132003         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
132004         , p_side                    => 'NA'
132005         );
132006 
132007   END IF;
132008 
132009    l_segment := AcctDerRule_168(
132010            p_application_id           => p_application_id
132011          , p_ae_header_id             => l_ae_header_id 
132012 , p_source_3 => p_source_3
132013 , p_source_29 => p_source_29
132014          , x_transaction_coa_id       => l_adr_transaction_coa_id
132015          , x_accounting_coa_id        => l_adr_accounting_coa_id
132016          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
132017          , x_flex_value_set_id        => l_adr_flex_value_set_id
132021          , p_side                     => 'NA'
132018          , x_value_type_code          => l_adr_value_type_code
132019          , x_value_combination_id     => l_adr_value_combination_id
132020          , x_value_segment_code       => l_adr_value_segment_code
132022          , p_override_seg_flag        => 'Y'
132023    );
132024 
132025    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
132026 
132027       xla_ae_lines_pkg.set_segment(
132028           p_to_segment_code         => 'GL_BALANCING'
132029         , p_segment_value           => l_segment
132030         , p_from_segment_code       => l_adr_value_segment_code
132031         , p_from_combination_id     => l_adr_value_combination_id
132032         , p_value_type_code         => l_adr_value_type_code
132033         , p_transaction_coa_id      => l_adr_transaction_coa_id
132034         , p_accounting_coa_id       => l_adr_accounting_coa_id
132035         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
132036         , p_flex_value_set_id       => l_adr_flex_value_set_id
132037         , p_adr_code                => 'FA_EXPENSE_ACCT'
132038         , p_adr_type_code           => 'S'
132039         , p_component_type          => l_component_type
132040         , p_component_code          => l_component_code
132041         , p_component_type_code     => l_component_type_code
132042         , p_component_appl_id       => l_component_appl_id
132043         , p_amb_context_code        => l_amb_context_code
132044         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
132045         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
132046         , p_side                    => 'NA'
132047         );
132048 
132049   END IF;
132050 
132051    --
132052    --
132053    END IF;
132054    --
132055    -- Bug 4922099
132056    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
132057           (NVL(l_enc_upg_option, 'N') = 'O')
132058         ) AND
132059         (l_bflow_method_code = 'PRIOR_ENTRY')
132060       )
132061    THEN
132062       IF
132063       --
132064       1 = 2
132065       --
132066       THEN
132067       xla_accounting_err_pkg.build_message
132068                                     (p_appli_s_name            => 'XLA'
132069                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
132070                                     ,p_token_1                 => 'LINE_NUMBER'
132071                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
132072                                     ,p_token_2                 => 'LINE_TYPE_NAME'
132073                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
132074                                                                              l_component_type
132075                                                                             ,l_component_code
132076                                                                             ,l_component_type_code
132077                                                                             ,l_component_appl_id
132078                                                                             ,l_amb_context_code
132079                                                                             ,l_entity_code
132080                                                                             ,l_event_class_code
132081                                                                            )
132082                                     ,p_token_3                 => 'OWNER'
132083                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
132084                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
132085                                                                           ,p_lookup_code    => l_component_type_code
132086                                                                          )
132087                                     ,p_token_4                 => 'PRODUCT_NAME'
132088                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
132089                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
132090                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
132091                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
132092                                     ,p_ae_header_id            =>  NULL
132093                                        );
132094 
132095         IF (C_LEVEL_ERROR>= g_log_level) THEN
132096                  trace
132097                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
132098                       ,p_level    => C_LEVEL_ERROR
132099                       ,p_module   => l_log_module);
132100         END IF;
132101       END IF;
132102    END IF;
132103    --
132104    --
132105    ------------------------------------------------------------------------------------------------
132106    -- 4219869 Business Flow
132107    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
132108    -- Prior Entry.  Currently, the following code is always generated.
132109    ------------------------------------------------------------------------------------------------
132110    XLA_AE_LINES_PKG.ValidateCurrentLine;
132111 
132112    ------------------------------------------------------------------------------------
132113    -- 4219869 Business Flow
132114    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
132115    ------------------------------------------------------------------------------------
132116    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
132117 
132118    ----------------------------------------------------------------------------------
132119    -- 4219869 Business Flow
132120    -- Update journal entry status -- Need to generate this within IF <condition>
132121    ----------------------------------------------------------------------------------
132125          );
132122    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
132123          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
132124          ,p_balance_type_code => l_balance_type_code
132126 
132127    -------------------------------------------------------------------------------------------
132128    -- 4262811 - Generate the Accrual Reversal lines
132129    -------------------------------------------------------------------------------------------
132130    BEGIN
132131       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
132132                               (g_array_event(p_event_id).array_value_num('header_index'));
132133       IF l_acc_rev_flag IS NULL THEN
132134          l_acc_rev_flag := 'N';
132135       END IF;
132136    EXCEPTION
132137       WHEN OTHERS THEN
132138          l_acc_rev_flag := 'N';
132139    END;
132140    --
132141    IF (l_acc_rev_flag = 'Y') THEN
132142 
132143        -- 4645092  ------------------------------------------------------------------------------
132144        -- To allow MPA report to determine if it should generate report process
132145        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
132146        ------------------------------------------------------------------------------------------
132147 
132148        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
132149        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
132150    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
132151    -- call ADRs
132152    -- Bug 4922099
132153    --
132154    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
132155         (NVL(l_actual_upg_option, 'N') = 'O') OR
132156         (NVL(l_enc_upg_option, 'N') = 'O')
132157       )
132158    THEN
132159    NULL;
132160    --
132161    --
132162    
132163   l_ccid := AcctDerRule_173(
132164            p_application_id           => p_application_id
132165          , p_ae_header_id             => l_ae_header_id 
132166 , p_source_3 => p_source_3
132167 , p_source_30 => p_source_30
132168          , x_transaction_coa_id       => l_adr_transaction_coa_id
132169          , x_accounting_coa_id        => l_adr_accounting_coa_id
132170          , x_value_type_code          => l_adr_value_type_code
132171          , p_side                     => 'NA'
132172    );
132173 
132174    xla_ae_lines_pkg.set_ccid(
132175     p_code_combination_id          => l_ccid
132176   , p_value_type_code              => l_adr_value_type_code
132177   , p_transaction_coa_id           => l_adr_transaction_coa_id
132178   , p_accounting_coa_id            => l_adr_accounting_coa_id
132179   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
132180   , p_adr_type_code                => 'S'
132181   , p_component_type               => l_component_type
132182   , p_component_code               => l_component_code
132183   , p_component_type_code          => l_component_type_code
132184   , p_component_appl_id            => l_component_appl_id
132185   , p_amb_context_code             => l_amb_context_code
132186   , p_side                         => 'NA'
132187   );
132188 
132189 
132190    l_segment := AcctDerRule_146(
132191            p_application_id           => p_application_id
132192          , p_ae_header_id             => l_ae_header_id 
132193 , p_source_3 => p_source_3
132194 , p_source_7 => p_source_7
132195          , x_transaction_coa_id       => l_adr_transaction_coa_id
132196          , x_accounting_coa_id        => l_adr_accounting_coa_id
132197          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
132198          , x_flex_value_set_id        => l_adr_flex_value_set_id
132199          , x_value_type_code          => l_adr_value_type_code
132200          , x_value_combination_id     => l_adr_value_combination_id
132201          , x_value_segment_code       => l_adr_value_segment_code
132202          , p_side                     => 'NA'
132203          , p_override_seg_flag        => 'Y'
132204    );
132205 
132206    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
132207 
132208       xla_ae_lines_pkg.set_segment(
132209           p_to_segment_code         => 'GL_ACCOUNT'
132210         , p_segment_value           => l_segment
132211         , p_from_segment_code       => l_adr_value_segment_code
132212         , p_from_combination_id     => l_adr_value_combination_id
132213         , p_value_type_code         => l_adr_value_type_code
132214         , p_transaction_coa_id      => l_adr_transaction_coa_id
132215         , p_accounting_coa_id       => l_adr_accounting_coa_id
132216         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
132217         , p_flex_value_set_id       => l_adr_flex_value_set_id
132218         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
132219         , p_adr_type_code           => 'S'
132220         , p_component_type          => l_component_type
132221         , p_component_code          => l_component_code
132222         , p_component_type_code     => l_component_type_code
132223         , p_component_appl_id       => l_component_appl_id
132224         , p_amb_context_code        => l_amb_context_code
132225         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
132226         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
132227         , p_side                    => 'NA'
132228         );
132229 
132230   END IF;
132231 
132232    l_segment := AcctDerRule_168(
132233            p_application_id           => p_application_id
132234          , p_ae_header_id             => l_ae_header_id 
132235 , p_source_3 => p_source_3
132236 , p_source_29 => p_source_29
132237          , x_transaction_coa_id       => l_adr_transaction_coa_id
132238          , x_accounting_coa_id        => l_adr_accounting_coa_id
132239          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
132240          , x_flex_value_set_id        => l_adr_flex_value_set_id
132241          , x_value_type_code          => l_adr_value_type_code
132242          , x_value_combination_id     => l_adr_value_combination_id
132246    );
132243          , x_value_segment_code       => l_adr_value_segment_code
132244          , p_side                     => 'NA'
132245          , p_override_seg_flag        => 'Y'
132247 
132248    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
132249 
132250       xla_ae_lines_pkg.set_segment(
132251           p_to_segment_code         => 'GL_BALANCING'
132252         , p_segment_value           => l_segment
132253         , p_from_segment_code       => l_adr_value_segment_code
132254         , p_from_combination_id     => l_adr_value_combination_id
132255         , p_value_type_code         => l_adr_value_type_code
132256         , p_transaction_coa_id      => l_adr_transaction_coa_id
132257         , p_accounting_coa_id       => l_adr_accounting_coa_id
132258         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
132259         , p_flex_value_set_id       => l_adr_flex_value_set_id
132260         , p_adr_code                => 'FA_EXPENSE_ACCT'
132261         , p_adr_type_code           => 'S'
132262         , p_component_type          => l_component_type
132263         , p_component_code          => l_component_code
132264         , p_component_type_code     => l_component_type_code
132265         , p_component_appl_id       => l_component_appl_id
132266         , p_amb_context_code        => l_amb_context_code
132267         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
132268         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
132269         , p_side                    => 'NA'
132270         );
132271 
132272   END IF;
132273 
132274    --
132275    --
132276    END IF;
132277 
132278        --
132279        -- Update the line information that should be overwritten
132280        --
132281        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
132282                                          p_header_num   => 1);
132283        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
132284 
132285        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
132286 
132287        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
132288           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
132289        END IF;
132290 
132291       --
132292       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
132293       --
132294       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
132295           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
132296       ELSE
132297           ---------------------------------------------------------------------------------------------------
132298           -- 4262811a Switch Sign
132299           ---------------------------------------------------------------------------------------------------
132300           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
132301           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
132302                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
132303           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
132304                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
132305           -- 5132302
132306           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
132307                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
132308 
132309       END IF;
132310 
132311       -- 4955764
132312       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
132313       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
132314 
132315 
132316       XLA_AE_LINES_PKG.ValidateCurrentLine;
132317       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
132318 
132319       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
132320                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
132321                ,p_balance_type_code => l_balance_type_code);
132322 
132323    END IF;
132324 
132325    -----------------------------------------------------------------------------------------
132326    -- 4262811 Multiperiod Accounting
132327    -----------------------------------------------------------------------------------------
132328      -- No MPA option is assigned.
132329 
132330 
132331 END IF;
132332 END IF;
132333 --
132334 
132335 --
132336 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
132337    trace
132338       (p_msg      => 'END of AcctLineType_339'
132339       ,p_level    => C_LEVEL_PROCEDURE
132340       ,p_module   => l_log_module);
132341 END IF;
132342 --
132343 EXCEPTION
132344   WHEN xla_exceptions_pkg.application_exception THEN
132345       RAISE;
132346   WHEN OTHERS THEN
132347        xla_exceptions_pkg.raise_message
132348            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_339');
132349 END AcctLineType_339;
132350 --
132351 
132352 ---------------------------------------
132353 --
132354 -- PRIVATE FUNCTION
132355 --         AcctLineType_340
132356 --
132357 ---------------------------------------
132358 PROCEDURE AcctLineType_340 (
132359   p_application_id        IN NUMBER
132360  ,p_event_id              IN NUMBER
132361  ,p_calculate_acctd_flag  IN VARCHAR2
132362  ,p_calculate_g_l_flag    IN VARCHAR2
132363  ,p_actual_flag           IN OUT VARCHAR2
132364  ,p_balance_type_code     OUT VARCHAR2
132365  ,p_gain_or_loss_ref      OUT VARCHAR2
132366  
132367 --Period Close Date
132368  , p_source_1            IN DATE
132369 --Generated Code Combination Identifier
132370  , p_source_3            IN NUMBER
132374  , p_source_6            IN NUMBER
132371 --CIP Clearing Account
132372  , p_source_5            IN VARCHAR2
132373 --Payables Code Combination Identifier
132375 --Expense Account Code Combination Identifier
132376  , p_source_29            IN NUMBER
132377 --Default Code Combination Identifier
132378  , p_source_30            IN NUMBER
132379 --Adjustment Type
132380  , p_source_35            IN VARCHAR2
132381 --Transaction Header Identifier
132382  , p_source_36            IN NUMBER
132383 --Adjustment Line Identifier
132384  , p_source_37            IN NUMBER
132385 --Distribution Type Code
132386  , p_source_38            IN VARCHAR2
132387 --Entered Amount
132388  , p_source_39            IN NUMBER
132389 --Currency Code
132390  , p_source_40            IN VARCHAR2
132391 --Source Destination Code
132392  , p_source_42            IN VARCHAR2
132393 )
132394 IS
132395 
132396 l_component_type              VARCHAR2(80);
132397 l_component_code              VARCHAR2(30);
132398 l_component_type_code         VARCHAR2(1);
132399 l_component_appl_id           INTEGER;
132400 l_amb_context_code            VARCHAR2(30);
132401 l_entity_code                 VARCHAR2(30);
132402 l_event_class_code            VARCHAR2(30);
132403 l_ae_header_id                NUMBER;
132404 l_event_type_code             VARCHAR2(30);
132405 l_line_definition_code        VARCHAR2(30);
132406 l_line_definition_owner_code  VARCHAR2(1);
132407 --
132408 -- adr variables
132409 l_segment                     VARCHAR2(30);
132410 l_ccid                        NUMBER;
132411 l_adr_transaction_coa_id      NUMBER;
132412 l_adr_accounting_coa_id       NUMBER;
132413 l_adr_flexfield_segment_code  VARCHAR2(30);
132414 l_adr_flex_value_set_id       NUMBER;
132415 l_adr_value_type_code         VARCHAR2(30);
132416 l_adr_value_combination_id    NUMBER;
132417 l_adr_value_segment_code      VARCHAR2(30);
132418 
132419 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
132420 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
132421 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
132422 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
132423 
132424 -- 4262811 Variables ------------------------------------------------------------------------------------------
132425 l_entered_amt_idx             NUMBER;
132426 l_accted_amt_idx              NUMBER;
132427 l_acc_rev_flag                VARCHAR2(1);
132428 l_accrual_line_num            NUMBER;
132429 l_tmp_amt                     NUMBER;
132430 l_acc_rev_natural_side_code   VARCHAR2(1);
132431 
132432 l_num_entries                 NUMBER;
132433 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
132434 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
132435 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
132436 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
132437 l_recog_line_1                NUMBER;
132438 l_recog_line_2                NUMBER;
132439 
132440 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
132441 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
132442 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
132443 
132444 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
132445 
132446 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
132447 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
132448 
132449 ---------------------------------------------------------------------------------------------------------------
132450 
132451 
132452 --
132453 -- bulk performance
132454 --
132455 l_balance_type_code           VARCHAR2(1);
132456 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
132457 l_log_module                  VARCHAR2(240);
132458 
132459 --
132460 -- Upgrade strategy
132461 --
132462 l_actual_upg_option           VARCHAR2(1);
132463 l_enc_upg_option           VARCHAR2(1);
132464 
132465 --
132466 BEGIN
132467 --
132468 IF g_log_enabled THEN
132469       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_340';
132470 END IF;
132471 --
132472 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
132473 
132474       trace
132475          (p_msg      => 'BEGIN of AcctLineType_340'
132476          ,p_level    => C_LEVEL_PROCEDURE
132477          ,p_module   => l_log_module);
132478 
132479 END IF;
132480 --
132481 l_component_type             := 'AMB_JLT';
132482 l_component_code             := 'FA_SLT_DEST_CIP_COST_CLR';
132483 l_component_type_code        := 'S';
132484 l_component_appl_id          :=  140;
132485 l_amb_context_code           := 'DEFAULT';
132486 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
132487 l_event_class_code           := 'CIP_SOURCE_LINE_TRANSFERS';
132488 l_event_type_code            := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
132489 l_line_definition_owner_code := 'S';
132490 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_S11';
132491 --
132492 l_balance_type_code          := 'A';
132493 l_segment                     := NULL;
132494 l_ccid                        := NULL;
132495 l_adr_transaction_coa_id      := NULL;
132496 l_adr_accounting_coa_id       := NULL;
132497 l_adr_flexfield_segment_code  := NULL;
132498 l_adr_flex_value_set_id       := NULL;
132499 l_adr_value_type_code         := NULL;
132500 l_adr_value_combination_id    := NULL;
132501 l_adr_value_segment_code      := NULL;
132502 
132503 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
132504 l_bflow_class_code           := '';    -- 4219869 Business Flow
132505 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
132506 l_budgetary_control_flag     := 'N';
132507 
132508 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
132509 l_bflow_applied_to_amt       := NULL; -- 5132302
132513 l_accrual_line_num           := NULL;          -- 4262811
132510 l_entered_amt_idx            := NULL;          -- 4262811
132511 l_accted_amt_idx             := NULL;          -- 4262811
132512 l_acc_rev_flag               := NULL;          -- 4262811
132514 l_tmp_amt                    := NULL;          -- 4262811
132515 --
132516  
132517 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
132518     l_balance_type_code <> 'B' THEN
132519 IF NVL(p_source_35,'
132520 ') =  'COST CLEARING' AND 
132521 NVL(p_source_42,'
132522 ') =  'DEST'
132523  THEN 
132524 
132525    --
132526    XLA_AE_LINES_PKG.SetNewLine;
132527 
132528    p_balance_type_code          := l_balance_type_code;
132529    -- set the flag so later we will know whether the gain loss line needs to be created
132530    
132531    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
132532      p_actual_flag :='A';
132533    END IF;
132534 
132535    --
132536    -- bulk performance
132537    --
132538    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
132539                                       p_header_num   => 0); -- 4262811
132540    --
132541    -- set accounting line options
132542    --
132543    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
132544            p_natural_side_code          => 'C'
132545          , p_gain_or_loss_flag          => 'N'
132546          , p_gl_transfer_mode_code      => 'S'
132547          , p_acct_entry_type_code       => 'A'
132548          , p_switch_side_flag           => 'Y'
132549          , p_merge_duplicate_code       => 'N'
132550          );
132551    --
132552    l_acc_rev_natural_side_code := 'D';  -- 4262811
132553    -- 
132554    --
132555    -- set accounting line type info
132556    --
132557    xla_ae_lines_pkg.SetAcctLineType
132558       (p_component_type             => l_component_type
132559       ,p_event_type_code            => l_event_type_code
132560       ,p_line_definition_owner_code => l_line_definition_owner_code
132561       ,p_line_definition_code       => l_line_definition_code
132562       ,p_accounting_line_code       => l_component_code
132563       ,p_accounting_line_type_code  => l_component_type_code
132564       ,p_accounting_line_appl_id    => l_component_appl_id
132565       ,p_amb_context_code           => l_amb_context_code
132566       ,p_entity_code                => l_entity_code
132567       ,p_event_class_code           => l_event_class_code);
132568    --
132569    -- set accounting class
132570    --
132571    xla_ae_lines_pkg.SetAcctClass(
132572            p_accounting_class_code  => 'ASSET'
132573          , p_ae_header_id           => l_ae_header_id
132574          );
132575 
132576    --
132577    -- set rounding class
132578    --
132579    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
132580                       'ASSET';
132581 
132582    --
132583    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
132584    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
132585    --
132586    -- bulk performance
132587    --
132588    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
132589 
132590    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
132591       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
132592 
132593    -- 4955764
132594    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
132595       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
132596 
132597    -- 4458381 Public Sector Enh
132598    
132599    --
132600    -- set accounting attributes for the line type
132601    --
132602    l_entered_amt_idx := 4;
132603    l_accted_amt_idx  := 6;
132604    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
132605    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
132606    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
132607    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
132608    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
132609    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
132610    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
132611    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
132612    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
132613    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
132614    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
132615    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
132616    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
132617 
132618    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
132619    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
132620 
132621    ---------------------------------------------------------------------------------------------------------------
132622    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
132623    ---------------------------------------------------------------------------------------------------------------
132624    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
132625 
132626    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
132627    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
132628 
132629    IF xla_accounting_cache_pkg.GetValueChar
132630          (p_source_code         => 'LEDGER_CATEGORY_CODE'
132631          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
132632    AND l_bflow_method_code = 'PRIOR_ENTRY'
132636        )
132633 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
132634    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
132635          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
132637    THEN
132638          xla_ae_lines_pkg.BflowUpgEntry
132639            (p_business_method_code    => l_bflow_method_code
132640            ,p_business_class_code     => l_bflow_class_code
132641            ,p_balance_type            => l_balance_type_code);
132642    ELSE
132643       NULL;
132644 -- No business flow processing for business flow method of NONE.
132645    END IF;
132646 
132647    --
132648    -- call analytical criteria
132649    --
132650    
132651    --
132652    -- call description
132653    --
132654    
132655 xla_ae_lines_pkg.SetLineDescription(
132656    p_ae_header_id => l_ae_header_id
132657   ,p_description  => Description_106 (
132658      p_application_id         => p_application_id
132659    , p_ae_header_id           => l_ae_header_id 
132660 , p_source_1 => p_source_1
132661    )
132662 );
132663 
132664 
132665    --
132666    -- call ADRs
132667    -- Bug 4922099
132668    --
132669    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
132670         (NVL(l_actual_upg_option, 'N') = 'O') OR
132671         (NVL(l_enc_upg_option, 'N') = 'O')
132672       )
132673    THEN
132674    NULL;
132675    --
132676    --
132677    
132678   l_ccid := AcctDerRule_173(
132679            p_application_id           => p_application_id
132680          , p_ae_header_id             => l_ae_header_id 
132681 , p_source_3 => p_source_3
132682 , p_source_30 => p_source_30
132683          , x_transaction_coa_id       => l_adr_transaction_coa_id
132684          , x_accounting_coa_id        => l_adr_accounting_coa_id
132685          , x_value_type_code          => l_adr_value_type_code
132686          , p_side                     => 'NA'
132687    );
132688 
132689    xla_ae_lines_pkg.set_ccid(
132690     p_code_combination_id          => l_ccid
132691   , p_value_type_code              => l_adr_value_type_code
132692   , p_transaction_coa_id           => l_adr_transaction_coa_id
132693   , p_accounting_coa_id            => l_adr_accounting_coa_id
132694   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
132695   , p_adr_type_code                => 'S'
132696   , p_component_type               => l_component_type
132697   , p_component_code               => l_component_code
132698   , p_component_type_code          => l_component_type_code
132699   , p_component_appl_id            => l_component_appl_id
132700   , p_amb_context_code             => l_amb_context_code
132701   , p_side                         => 'NA'
132702   );
132703 
132704 
132705    l_segment := AcctDerRule_145(
132706            p_application_id           => p_application_id
132707          , p_ae_header_id             => l_ae_header_id 
132708 , p_source_3 => p_source_3
132709 , p_source_5 => p_source_5
132710 , p_source_6 => p_source_6
132711          , x_transaction_coa_id       => l_adr_transaction_coa_id
132712          , x_accounting_coa_id        => l_adr_accounting_coa_id
132713          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
132714          , x_flex_value_set_id        => l_adr_flex_value_set_id
132715          , x_value_type_code          => l_adr_value_type_code
132716          , x_value_combination_id     => l_adr_value_combination_id
132717          , x_value_segment_code       => l_adr_value_segment_code
132718          , p_side                     => 'NA'
132719          , p_override_seg_flag        => 'Y'
132720    );
132721 
132722    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
132723 
132724       xla_ae_lines_pkg.set_segment(
132725           p_to_segment_code         => 'GL_ACCOUNT'
132726         , p_segment_value           => l_segment
132727         , p_from_segment_code       => l_adr_value_segment_code
132728         , p_from_combination_id     => l_adr_value_combination_id
132729         , p_value_type_code         => l_adr_value_type_code
132730         , p_transaction_coa_id      => l_adr_transaction_coa_id
132731         , p_accounting_coa_id       => l_adr_accounting_coa_id
132732         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
132733         , p_flex_value_set_id       => l_adr_flex_value_set_id
132734         , p_adr_code                => 'FA_CAT_CIP_CLR_SEGMENT'
132735         , p_adr_type_code           => 'S'
132736         , p_component_type          => l_component_type
132737         , p_component_code          => l_component_code
132738         , p_component_type_code     => l_component_type_code
132739         , p_component_appl_id       => l_component_appl_id
132740         , p_amb_context_code        => l_amb_context_code
132741         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
132742         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
132743         , p_side                    => 'NA'
132744         );
132745 
132746   END IF;
132747 
132748    l_segment := AcctDerRule_169(
132749            p_application_id           => p_application_id
132750          , p_ae_header_id             => l_ae_header_id 
132751 , p_source_3 => p_source_3
132752 , p_source_6 => p_source_6
132753 , p_source_29 => p_source_29
132754          , x_transaction_coa_id       => l_adr_transaction_coa_id
132755          , x_accounting_coa_id        => l_adr_accounting_coa_id
132756          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
132757          , x_flex_value_set_id        => l_adr_flex_value_set_id
132758          , x_value_type_code          => l_adr_value_type_code
132759          , x_value_combination_id     => l_adr_value_combination_id
132760          , x_value_segment_code       => l_adr_value_segment_code
132761          , p_side                     => 'NA'
132762          , p_override_seg_flag        => 'Y'
132763    );
132764 
132765    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
132766 
132770         , p_from_segment_code       => l_adr_value_segment_code
132767       xla_ae_lines_pkg.set_segment(
132768           p_to_segment_code         => 'GL_BALANCING'
132769         , p_segment_value           => l_segment
132771         , p_from_combination_id     => l_adr_value_combination_id
132772         , p_value_type_code         => l_adr_value_type_code
132773         , p_transaction_coa_id      => l_adr_transaction_coa_id
132774         , p_accounting_coa_id       => l_adr_accounting_coa_id
132775         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
132776         , p_flex_value_set_id       => l_adr_flex_value_set_id
132777         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
132778         , p_adr_type_code           => 'S'
132779         , p_component_type          => l_component_type
132780         , p_component_code          => l_component_code
132781         , p_component_type_code     => l_component_type_code
132782         , p_component_appl_id       => l_component_appl_id
132783         , p_amb_context_code        => l_amb_context_code
132784         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
132785         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
132786         , p_side                    => 'NA'
132787         );
132788 
132789   END IF;
132790 
132791    --
132792    --
132793    END IF;
132794    --
132795    -- Bug 4922099
132796    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
132797           (NVL(l_enc_upg_option, 'N') = 'O')
132798         ) AND
132799         (l_bflow_method_code = 'PRIOR_ENTRY')
132800       )
132801    THEN
132802       IF
132803       --
132804       1 = 2
132805       --
132806       THEN
132807       xla_accounting_err_pkg.build_message
132808                                     (p_appli_s_name            => 'XLA'
132809                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
132810                                     ,p_token_1                 => 'LINE_NUMBER'
132811                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
132812                                     ,p_token_2                 => 'LINE_TYPE_NAME'
132813                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
132814                                                                              l_component_type
132815                                                                             ,l_component_code
132816                                                                             ,l_component_type_code
132817                                                                             ,l_component_appl_id
132818                                                                             ,l_amb_context_code
132819                                                                             ,l_entity_code
132820                                                                             ,l_event_class_code
132821                                                                            )
132822                                     ,p_token_3                 => 'OWNER'
132823                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
132824                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
132825                                                                           ,p_lookup_code    => l_component_type_code
132826                                                                          )
132827                                     ,p_token_4                 => 'PRODUCT_NAME'
132828                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
132829                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
132830                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
132831                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
132832                                     ,p_ae_header_id            =>  NULL
132833                                        );
132834 
132835         IF (C_LEVEL_ERROR>= g_log_level) THEN
132836                  trace
132837                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
132838                       ,p_level    => C_LEVEL_ERROR
132839                       ,p_module   => l_log_module);
132840         END IF;
132841       END IF;
132842    END IF;
132843    --
132844    --
132845    ------------------------------------------------------------------------------------------------
132846    -- 4219869 Business Flow
132847    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
132848    -- Prior Entry.  Currently, the following code is always generated.
132849    ------------------------------------------------------------------------------------------------
132850    XLA_AE_LINES_PKG.ValidateCurrentLine;
132851 
132852    ------------------------------------------------------------------------------------
132853    -- 4219869 Business Flow
132854    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
132855    ------------------------------------------------------------------------------------
132856    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
132857 
132858    ----------------------------------------------------------------------------------
132859    -- 4219869 Business Flow
132860    -- Update journal entry status -- Need to generate this within IF <condition>
132861    ----------------------------------------------------------------------------------
132862    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
132863          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
132864          ,p_balance_type_code => l_balance_type_code
132865          );
132866 
132867    -------------------------------------------------------------------------------------------
132868    -- 4262811 - Generate the Accrual Reversal lines
132872                               (g_array_event(p_event_id).array_value_num('header_index'));
132869    -------------------------------------------------------------------------------------------
132870    BEGIN
132871       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
132873       IF l_acc_rev_flag IS NULL THEN
132874          l_acc_rev_flag := 'N';
132875       END IF;
132876    EXCEPTION
132877       WHEN OTHERS THEN
132878          l_acc_rev_flag := 'N';
132879    END;
132880    --
132881    IF (l_acc_rev_flag = 'Y') THEN
132882 
132883        -- 4645092  ------------------------------------------------------------------------------
132884        -- To allow MPA report to determine if it should generate report process
132885        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
132886        ------------------------------------------------------------------------------------------
132887 
132888        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
132889        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
132890    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
132891    -- call ADRs
132892    -- Bug 4922099
132893    --
132894    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
132895         (NVL(l_actual_upg_option, 'N') = 'O') OR
132896         (NVL(l_enc_upg_option, 'N') = 'O')
132897       )
132898    THEN
132899    NULL;
132900    --
132901    --
132902    
132903   l_ccid := AcctDerRule_173(
132904            p_application_id           => p_application_id
132905          , p_ae_header_id             => l_ae_header_id 
132906 , p_source_3 => p_source_3
132907 , p_source_30 => p_source_30
132908          , x_transaction_coa_id       => l_adr_transaction_coa_id
132909          , x_accounting_coa_id        => l_adr_accounting_coa_id
132910          , x_value_type_code          => l_adr_value_type_code
132911          , p_side                     => 'NA'
132912    );
132913 
132914    xla_ae_lines_pkg.set_ccid(
132915     p_code_combination_id          => l_ccid
132916   , p_value_type_code              => l_adr_value_type_code
132917   , p_transaction_coa_id           => l_adr_transaction_coa_id
132918   , p_accounting_coa_id            => l_adr_accounting_coa_id
132919   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
132920   , p_adr_type_code                => 'S'
132921   , p_component_type               => l_component_type
132922   , p_component_code               => l_component_code
132923   , p_component_type_code          => l_component_type_code
132924   , p_component_appl_id            => l_component_appl_id
132925   , p_amb_context_code             => l_amb_context_code
132926   , p_side                         => 'NA'
132927   );
132928 
132929 
132930    l_segment := AcctDerRule_145(
132931            p_application_id           => p_application_id
132932          , p_ae_header_id             => l_ae_header_id 
132933 , p_source_3 => p_source_3
132934 , p_source_5 => p_source_5
132935 , p_source_6 => p_source_6
132936          , x_transaction_coa_id       => l_adr_transaction_coa_id
132937          , x_accounting_coa_id        => l_adr_accounting_coa_id
132938          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
132939          , x_flex_value_set_id        => l_adr_flex_value_set_id
132940          , x_value_type_code          => l_adr_value_type_code
132941          , x_value_combination_id     => l_adr_value_combination_id
132942          , x_value_segment_code       => l_adr_value_segment_code
132943          , p_side                     => 'NA'
132944          , p_override_seg_flag        => 'Y'
132945    );
132946 
132947    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
132948 
132949       xla_ae_lines_pkg.set_segment(
132950           p_to_segment_code         => 'GL_ACCOUNT'
132951         , p_segment_value           => l_segment
132952         , p_from_segment_code       => l_adr_value_segment_code
132953         , p_from_combination_id     => l_adr_value_combination_id
132954         , p_value_type_code         => l_adr_value_type_code
132955         , p_transaction_coa_id      => l_adr_transaction_coa_id
132956         , p_accounting_coa_id       => l_adr_accounting_coa_id
132957         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
132958         , p_flex_value_set_id       => l_adr_flex_value_set_id
132959         , p_adr_code                => 'FA_CAT_CIP_CLR_SEGMENT'
132960         , p_adr_type_code           => 'S'
132961         , p_component_type          => l_component_type
132962         , p_component_code          => l_component_code
132963         , p_component_type_code     => l_component_type_code
132964         , p_component_appl_id       => l_component_appl_id
132965         , p_amb_context_code        => l_amb_context_code
132966         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
132967         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
132968         , p_side                    => 'NA'
132969         );
132970 
132971   END IF;
132972 
132973    l_segment := AcctDerRule_169(
132974            p_application_id           => p_application_id
132975          , p_ae_header_id             => l_ae_header_id 
132976 , p_source_3 => p_source_3
132977 , p_source_6 => p_source_6
132978 , p_source_29 => p_source_29
132979          , x_transaction_coa_id       => l_adr_transaction_coa_id
132980          , x_accounting_coa_id        => l_adr_accounting_coa_id
132981          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
132982          , x_flex_value_set_id        => l_adr_flex_value_set_id
132983          , x_value_type_code          => l_adr_value_type_code
132984          , x_value_combination_id     => l_adr_value_combination_id
132985          , x_value_segment_code       => l_adr_value_segment_code
132986          , p_side                     => 'NA'
132987          , p_override_seg_flag        => 'Y'
132988    );
132989 
132990    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
132991 
132995         , p_from_segment_code       => l_adr_value_segment_code
132992       xla_ae_lines_pkg.set_segment(
132993           p_to_segment_code         => 'GL_BALANCING'
132994         , p_segment_value           => l_segment
132996         , p_from_combination_id     => l_adr_value_combination_id
132997         , p_value_type_code         => l_adr_value_type_code
132998         , p_transaction_coa_id      => l_adr_transaction_coa_id
132999         , p_accounting_coa_id       => l_adr_accounting_coa_id
133000         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
133001         , p_flex_value_set_id       => l_adr_flex_value_set_id
133002         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
133003         , p_adr_type_code           => 'S'
133004         , p_component_type          => l_component_type
133005         , p_component_code          => l_component_code
133006         , p_component_type_code     => l_component_type_code
133007         , p_component_appl_id       => l_component_appl_id
133008         , p_amb_context_code        => l_amb_context_code
133009         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
133010         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
133011         , p_side                    => 'NA'
133012         );
133013 
133014   END IF;
133015 
133016    --
133017    --
133018    END IF;
133019 
133020        --
133021        -- Update the line information that should be overwritten
133022        --
133023        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
133024                                          p_header_num   => 1);
133025        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
133026 
133027        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
133028 
133029        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
133030           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
133031        END IF;
133032 
133033       --
133034       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
133035       --
133036       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
133037           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
133038       ELSE
133039           ---------------------------------------------------------------------------------------------------
133040           -- 4262811a Switch Sign
133041           ---------------------------------------------------------------------------------------------------
133042           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
133043           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
133044                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
133045           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
133046                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
133047           -- 5132302
133048           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
133049                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
133050 
133051       END IF;
133052 
133053       -- 4955764
133054       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
133055       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
133056 
133057 
133058       XLA_AE_LINES_PKG.ValidateCurrentLine;
133059       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
133060 
133061       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
133062                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
133063                ,p_balance_type_code => l_balance_type_code);
133064 
133065    END IF;
133066 
133067    -----------------------------------------------------------------------------------------
133068    -- 4262811 Multiperiod Accounting
133069    -----------------------------------------------------------------------------------------
133070      -- No MPA option is assigned.
133071 
133072 
133073 END IF;
133074 END IF;
133075 --
133076 
133077 --
133078 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
133079    trace
133080       (p_msg      => 'END of AcctLineType_340'
133081       ,p_level    => C_LEVEL_PROCEDURE
133082       ,p_module   => l_log_module);
133083 END IF;
133084 --
133085 EXCEPTION
133086   WHEN xla_exceptions_pkg.application_exception THEN
133087       RAISE;
133088   WHEN OTHERS THEN
133089        xla_exceptions_pkg.raise_message
133090            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_340');
133091 END AcctLineType_340;
133092 --
133093 
133094 ---------------------------------------
133095 --
133096 -- PRIVATE FUNCTION
133097 --         AcctLineType_341
133098 --
133099 ---------------------------------------
133100 PROCEDURE AcctLineType_341 (
133101   p_application_id        IN NUMBER
133102  ,p_event_id              IN NUMBER
133103  ,p_calculate_acctd_flag  IN VARCHAR2
133104  ,p_calculate_g_l_flag    IN VARCHAR2
133105  ,p_actual_flag           IN OUT VARCHAR2
133106  ,p_balance_type_code     OUT VARCHAR2
133107  ,p_gain_or_loss_ref      OUT VARCHAR2
133108  
133109 --Period Close Date
133110  , p_source_1            IN DATE
133111 --Generated Code Combination Identifier
133112  , p_source_3            IN NUMBER
133113 --Revaluation Reserve Account
133114  , p_source_11            IN VARCHAR2
133115 --Generated Offset Code Combination Identifier
133116  , p_source_17            IN NUMBER
133117 --Expense Account Code Combination Identifier
133118  , p_source_29            IN NUMBER
133122  , p_source_35            IN VARCHAR2
133119 --Default Code Combination Identifier
133120  , p_source_30            IN NUMBER
133121 --Adjustment Type
133123 --Transaction Header Identifier
133124  , p_source_36            IN NUMBER
133125 --Adjustment Line Identifier
133126  , p_source_37            IN NUMBER
133127 --Distribution Type Code
133128  , p_source_38            IN VARCHAR2
133129 --Entered Amount
133130  , p_source_39            IN NUMBER
133131 --Currency Code
133132  , p_source_40            IN VARCHAR2
133133 --Source Destination Code
133134  , p_source_42            IN VARCHAR2
133135 )
133136 IS
133137 
133138 l_component_type              VARCHAR2(80);
133139 l_component_code              VARCHAR2(30);
133140 l_component_type_code         VARCHAR2(1);
133141 l_component_appl_id           INTEGER;
133142 l_amb_context_code            VARCHAR2(30);
133143 l_entity_code                 VARCHAR2(30);
133144 l_event_class_code            VARCHAR2(30);
133145 l_ae_header_id                NUMBER;
133146 l_event_type_code             VARCHAR2(30);
133147 l_line_definition_code        VARCHAR2(30);
133148 l_line_definition_owner_code  VARCHAR2(1);
133149 --
133150 -- adr variables
133151 l_segment                     VARCHAR2(30);
133152 l_ccid                        NUMBER;
133153 l_adr_transaction_coa_id      NUMBER;
133154 l_adr_accounting_coa_id       NUMBER;
133155 l_adr_flexfield_segment_code  VARCHAR2(30);
133156 l_adr_flex_value_set_id       NUMBER;
133157 l_adr_value_type_code         VARCHAR2(30);
133158 l_adr_value_combination_id    NUMBER;
133159 l_adr_value_segment_code      VARCHAR2(30);
133160 
133161 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
133162 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
133163 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
133164 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
133165 
133166 -- 4262811 Variables ------------------------------------------------------------------------------------------
133167 l_entered_amt_idx             NUMBER;
133168 l_accted_amt_idx              NUMBER;
133169 l_acc_rev_flag                VARCHAR2(1);
133170 l_accrual_line_num            NUMBER;
133171 l_tmp_amt                     NUMBER;
133172 l_acc_rev_natural_side_code   VARCHAR2(1);
133173 
133174 l_num_entries                 NUMBER;
133175 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
133176 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
133177 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
133178 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
133179 l_recog_line_1                NUMBER;
133180 l_recog_line_2                NUMBER;
133181 
133182 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
133183 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
133184 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
133185 
133186 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
133187 
133188 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
133189 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
133190 
133191 ---------------------------------------------------------------------------------------------------------------
133192 
133193 
133194 --
133195 -- bulk performance
133196 --
133197 l_balance_type_code           VARCHAR2(1);
133198 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
133199 l_log_module                  VARCHAR2(240);
133200 
133201 --
133202 -- Upgrade strategy
133203 --
133204 l_actual_upg_option           VARCHAR2(1);
133205 l_enc_upg_option           VARCHAR2(1);
133206 
133207 --
133208 BEGIN
133209 --
133210 IF g_log_enabled THEN
133211       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_341';
133212 END IF;
133213 --
133214 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
133215 
133216       trace
133217          (p_msg      => 'BEGIN of AcctLineType_341'
133218          ,p_level    => C_LEVEL_PROCEDURE
133219          ,p_module   => l_log_module);
133220 
133221 END IF;
133222 --
133223 l_component_type             := 'AMB_JLT';
133224 l_component_code             := 'FA_SLT_DEST_CIP_REVAL_RESERVE';
133225 l_component_type_code        := 'S';
133226 l_component_appl_id          :=  140;
133227 l_amb_context_code           := 'DEFAULT';
133228 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
133229 l_event_class_code           := 'CIP_SOURCE_LINE_TRANSFERS';
133230 l_event_type_code            := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
133231 l_line_definition_owner_code := 'S';
133232 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_S11';
133233 --
133234 l_balance_type_code          := 'A';
133235 l_segment                     := NULL;
133236 l_ccid                        := NULL;
133237 l_adr_transaction_coa_id      := NULL;
133238 l_adr_accounting_coa_id       := NULL;
133239 l_adr_flexfield_segment_code  := NULL;
133240 l_adr_flex_value_set_id       := NULL;
133241 l_adr_value_type_code         := NULL;
133242 l_adr_value_combination_id    := NULL;
133243 l_adr_value_segment_code      := NULL;
133244 
133245 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
133246 l_bflow_class_code           := '';    -- 4219869 Business Flow
133247 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
133248 l_budgetary_control_flag     := 'N';
133249 
133250 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
133251 l_bflow_applied_to_amt       := NULL; -- 5132302
133252 l_entered_amt_idx            := NULL;          -- 4262811
133253 l_accted_amt_idx             := NULL;          -- 4262811
133254 l_acc_rev_flag               := NULL;          -- 4262811
133255 l_accrual_line_num           := NULL;          -- 4262811
133259 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
133256 l_tmp_amt                    := NULL;          -- 4262811
133257 --
133258  
133260     l_balance_type_code <> 'B' THEN
133261 IF NVL(p_source_35,'
133262 ') =  'REVAL RESERVE' AND 
133263 NVL(p_source_42,'
133264 ') =  'DEST'
133265  THEN 
133266 
133267    --
133268    XLA_AE_LINES_PKG.SetNewLine;
133269 
133270    p_balance_type_code          := l_balance_type_code;
133271    -- set the flag so later we will know whether the gain loss line needs to be created
133272    
133273    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
133274      p_actual_flag :='A';
133275    END IF;
133276 
133277    --
133278    -- bulk performance
133279    --
133280    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
133281                                       p_header_num   => 0); -- 4262811
133282    --
133283    -- set accounting line options
133284    --
133285    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
133286            p_natural_side_code          => 'C'
133287          , p_gain_or_loss_flag          => 'N'
133288          , p_gl_transfer_mode_code      => 'S'
133289          , p_acct_entry_type_code       => 'A'
133290          , p_switch_side_flag           => 'Y'
133291          , p_merge_duplicate_code       => 'N'
133292          );
133293    --
133294    l_acc_rev_natural_side_code := 'D';  -- 4262811
133295    -- 
133296    --
133297    -- set accounting line type info
133298    --
133299    xla_ae_lines_pkg.SetAcctLineType
133300       (p_component_type             => l_component_type
133301       ,p_event_type_code            => l_event_type_code
133302       ,p_line_definition_owner_code => l_line_definition_owner_code
133303       ,p_line_definition_code       => l_line_definition_code
133304       ,p_accounting_line_code       => l_component_code
133305       ,p_accounting_line_type_code  => l_component_type_code
133306       ,p_accounting_line_appl_id    => l_component_appl_id
133307       ,p_amb_context_code           => l_amb_context_code
133308       ,p_entity_code                => l_entity_code
133309       ,p_event_class_code           => l_event_class_code);
133310    --
133311    -- set accounting class
133312    --
133313    xla_ae_lines_pkg.SetAcctClass(
133314            p_accounting_class_code  => 'ASSET'
133315          , p_ae_header_id           => l_ae_header_id
133316          );
133317 
133318    --
133319    -- set rounding class
133320    --
133321    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
133322                       'ASSET';
133323 
133324    --
133325    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
133326    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
133327    --
133328    -- bulk performance
133329    --
133330    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
133331 
133332    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
133333       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
133334 
133335    -- 4955764
133336    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
133337       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
133338 
133339    -- 4458381 Public Sector Enh
133340    
133341    --
133342    -- set accounting attributes for the line type
133343    --
133344    l_entered_amt_idx := 4;
133345    l_accted_amt_idx  := 6;
133346    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
133347    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
133348    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
133349    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
133350    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
133351    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
133352    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
133353    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
133354    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
133355    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
133356    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
133357    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
133358    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
133359 
133360    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
133361    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
133362 
133363    ---------------------------------------------------------------------------------------------------------------
133364    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
133365    ---------------------------------------------------------------------------------------------------------------
133366    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
133367 
133368    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
133369    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
133370 
133371    IF xla_accounting_cache_pkg.GetValueChar
133372          (p_source_code         => 'LEDGER_CATEGORY_CODE'
133373          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
133374    AND l_bflow_method_code = 'PRIOR_ENTRY'
133375 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
133376    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
133377          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
133378        )
133379    THEN
133383            ,p_balance_type            => l_balance_type_code);
133380          xla_ae_lines_pkg.BflowUpgEntry
133381            (p_business_method_code    => l_bflow_method_code
133382            ,p_business_class_code     => l_bflow_class_code
133384    ELSE
133385       NULL;
133386 -- No business flow processing for business flow method of NONE.
133387    END IF;
133388 
133389    --
133390    -- call analytical criteria
133391    --
133392    
133393    --
133394    -- call description
133395    --
133396    
133397 xla_ae_lines_pkg.SetLineDescription(
133398    p_ae_header_id => l_ae_header_id
133399   ,p_description  => Description_109 (
133400      p_application_id         => p_application_id
133401    , p_ae_header_id           => l_ae_header_id 
133402 , p_source_1 => p_source_1
133403    )
133404 );
133405 
133406 
133407    --
133408    -- call ADRs
133409    -- Bug 4922099
133410    --
133411    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
133412         (NVL(l_actual_upg_option, 'N') = 'O') OR
133413         (NVL(l_enc_upg_option, 'N') = 'O')
133414       )
133415    THEN
133416    NULL;
133417    --
133418    --
133419    
133420   l_ccid := AcctDerRule_174(
133421            p_application_id           => p_application_id
133422          , p_ae_header_id             => l_ae_header_id 
133423 , p_source_3 => p_source_3
133424 , p_source_17 => p_source_17
133425 , p_source_30 => p_source_30
133426          , x_transaction_coa_id       => l_adr_transaction_coa_id
133427          , x_accounting_coa_id        => l_adr_accounting_coa_id
133428          , x_value_type_code          => l_adr_value_type_code
133429          , p_side                     => 'NA'
133430    );
133431 
133432    xla_ae_lines_pkg.set_ccid(
133433     p_code_combination_id          => l_ccid
133434   , p_value_type_code              => l_adr_value_type_code
133435   , p_transaction_coa_id           => l_adr_transaction_coa_id
133436   , p_accounting_coa_id            => l_adr_accounting_coa_id
133437   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
133438   , p_adr_type_code                => 'S'
133439   , p_component_type               => l_component_type
133440   , p_component_code               => l_component_code
133441   , p_component_type_code          => l_component_type_code
133442   , p_component_appl_id            => l_component_appl_id
133443   , p_amb_context_code             => l_amb_context_code
133444   , p_side                         => 'NA'
133445   );
133446 
133447 
133448    l_segment := AcctDerRule_150(
133449            p_application_id           => p_application_id
133450          , p_ae_header_id             => l_ae_header_id 
133451 , p_source_3 => p_source_3
133452 , p_source_11 => p_source_11
133453          , x_transaction_coa_id       => l_adr_transaction_coa_id
133454          , x_accounting_coa_id        => l_adr_accounting_coa_id
133455          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
133456          , x_flex_value_set_id        => l_adr_flex_value_set_id
133457          , x_value_type_code          => l_adr_value_type_code
133458          , x_value_combination_id     => l_adr_value_combination_id
133459          , x_value_segment_code       => l_adr_value_segment_code
133460          , p_side                     => 'NA'
133461          , p_override_seg_flag        => 'Y'
133462    );
133463 
133464    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
133465 
133466       xla_ae_lines_pkg.set_segment(
133467           p_to_segment_code         => 'GL_ACCOUNT'
133468         , p_segment_value           => l_segment
133469         , p_from_segment_code       => l_adr_value_segment_code
133470         , p_from_combination_id     => l_adr_value_combination_id
133471         , p_value_type_code         => l_adr_value_type_code
133472         , p_transaction_coa_id      => l_adr_transaction_coa_id
133473         , p_accounting_coa_id       => l_adr_accounting_coa_id
133474         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
133475         , p_flex_value_set_id       => l_adr_flex_value_set_id
133476         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
133477         , p_adr_type_code           => 'S'
133478         , p_component_type          => l_component_type
133479         , p_component_code          => l_component_code
133480         , p_component_type_code     => l_component_type_code
133481         , p_component_appl_id       => l_component_appl_id
133482         , p_amb_context_code        => l_amb_context_code
133483         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
133484         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
133485         , p_side                    => 'NA'
133486         );
133487 
133488   END IF;
133489 
133490    l_segment := AcctDerRule_168(
133491            p_application_id           => p_application_id
133492          , p_ae_header_id             => l_ae_header_id 
133493 , p_source_3 => p_source_3
133494 , p_source_29 => p_source_29
133495          , x_transaction_coa_id       => l_adr_transaction_coa_id
133496          , x_accounting_coa_id        => l_adr_accounting_coa_id
133497          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
133498          , x_flex_value_set_id        => l_adr_flex_value_set_id
133499          , x_value_type_code          => l_adr_value_type_code
133500          , x_value_combination_id     => l_adr_value_combination_id
133501          , x_value_segment_code       => l_adr_value_segment_code
133502          , p_side                     => 'NA'
133503          , p_override_seg_flag        => 'Y'
133504    );
133505 
133506    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
133507 
133508       xla_ae_lines_pkg.set_segment(
133509           p_to_segment_code         => 'GL_BALANCING'
133510         , p_segment_value           => l_segment
133511         , p_from_segment_code       => l_adr_value_segment_code
133515         , p_accounting_coa_id       => l_adr_accounting_coa_id
133512         , p_from_combination_id     => l_adr_value_combination_id
133513         , p_value_type_code         => l_adr_value_type_code
133514         , p_transaction_coa_id      => l_adr_transaction_coa_id
133516         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
133517         , p_flex_value_set_id       => l_adr_flex_value_set_id
133518         , p_adr_code                => 'FA_EXPENSE_ACCT'
133519         , p_adr_type_code           => 'S'
133520         , p_component_type          => l_component_type
133521         , p_component_code          => l_component_code
133522         , p_component_type_code     => l_component_type_code
133523         , p_component_appl_id       => l_component_appl_id
133524         , p_amb_context_code        => l_amb_context_code
133525         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
133526         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
133527         , p_side                    => 'NA'
133528         );
133529 
133530   END IF;
133531 
133532    --
133533    --
133534    END IF;
133535    --
133536    -- Bug 4922099
133537    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
133538           (NVL(l_enc_upg_option, 'N') = 'O')
133539         ) AND
133540         (l_bflow_method_code = 'PRIOR_ENTRY')
133541       )
133542    THEN
133543       IF
133544       --
133545       1 = 2
133546       --
133547       THEN
133548       xla_accounting_err_pkg.build_message
133549                                     (p_appli_s_name            => 'XLA'
133550                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
133551                                     ,p_token_1                 => 'LINE_NUMBER'
133552                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
133553                                     ,p_token_2                 => 'LINE_TYPE_NAME'
133554                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
133555                                                                              l_component_type
133556                                                                             ,l_component_code
133557                                                                             ,l_component_type_code
133558                                                                             ,l_component_appl_id
133559                                                                             ,l_amb_context_code
133560                                                                             ,l_entity_code
133561                                                                             ,l_event_class_code
133562                                                                            )
133563                                     ,p_token_3                 => 'OWNER'
133564                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
133565                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
133566                                                                           ,p_lookup_code    => l_component_type_code
133567                                                                          )
133568                                     ,p_token_4                 => 'PRODUCT_NAME'
133569                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
133570                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
133571                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
133572                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
133573                                     ,p_ae_header_id            =>  NULL
133574                                        );
133575 
133576         IF (C_LEVEL_ERROR>= g_log_level) THEN
133577                  trace
133578                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
133579                       ,p_level    => C_LEVEL_ERROR
133580                       ,p_module   => l_log_module);
133581         END IF;
133582       END IF;
133583    END IF;
133584    --
133585    --
133586    ------------------------------------------------------------------------------------------------
133587    -- 4219869 Business Flow
133588    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
133589    -- Prior Entry.  Currently, the following code is always generated.
133590    ------------------------------------------------------------------------------------------------
133591    XLA_AE_LINES_PKG.ValidateCurrentLine;
133592 
133593    ------------------------------------------------------------------------------------
133594    -- 4219869 Business Flow
133595    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
133596    ------------------------------------------------------------------------------------
133597    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
133598 
133599    ----------------------------------------------------------------------------------
133600    -- 4219869 Business Flow
133601    -- Update journal entry status -- Need to generate this within IF <condition>
133602    ----------------------------------------------------------------------------------
133603    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
133604          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
133605          ,p_balance_type_code => l_balance_type_code
133606          );
133607 
133608    -------------------------------------------------------------------------------------------
133609    -- 4262811 - Generate the Accrual Reversal lines
133610    -------------------------------------------------------------------------------------------
133611    BEGIN
133612       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
133616       END IF;
133613                               (g_array_event(p_event_id).array_value_num('header_index'));
133614       IF l_acc_rev_flag IS NULL THEN
133615          l_acc_rev_flag := 'N';
133617    EXCEPTION
133618       WHEN OTHERS THEN
133619          l_acc_rev_flag := 'N';
133620    END;
133621    --
133622    IF (l_acc_rev_flag = 'Y') THEN
133623 
133624        -- 4645092  ------------------------------------------------------------------------------
133625        -- To allow MPA report to determine if it should generate report process
133626        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
133627        ------------------------------------------------------------------------------------------
133628 
133629        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
133630        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
133631    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
133632    -- call ADRs
133633    -- Bug 4922099
133634    --
133635    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
133636         (NVL(l_actual_upg_option, 'N') = 'O') OR
133637         (NVL(l_enc_upg_option, 'N') = 'O')
133638       )
133639    THEN
133640    NULL;
133641    --
133642    --
133643    
133644   l_ccid := AcctDerRule_174(
133645            p_application_id           => p_application_id
133646          , p_ae_header_id             => l_ae_header_id 
133647 , p_source_3 => p_source_3
133648 , p_source_17 => p_source_17
133649 , p_source_30 => p_source_30
133650          , x_transaction_coa_id       => l_adr_transaction_coa_id
133651          , x_accounting_coa_id        => l_adr_accounting_coa_id
133652          , x_value_type_code          => l_adr_value_type_code
133653          , p_side                     => 'NA'
133654    );
133655 
133656    xla_ae_lines_pkg.set_ccid(
133657     p_code_combination_id          => l_ccid
133658   , p_value_type_code              => l_adr_value_type_code
133659   , p_transaction_coa_id           => l_adr_transaction_coa_id
133660   , p_accounting_coa_id            => l_adr_accounting_coa_id
133661   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
133662   , p_adr_type_code                => 'S'
133663   , p_component_type               => l_component_type
133664   , p_component_code               => l_component_code
133665   , p_component_type_code          => l_component_type_code
133666   , p_component_appl_id            => l_component_appl_id
133667   , p_amb_context_code             => l_amb_context_code
133668   , p_side                         => 'NA'
133669   );
133670 
133671 
133672    l_segment := AcctDerRule_150(
133673            p_application_id           => p_application_id
133674          , p_ae_header_id             => l_ae_header_id 
133675 , p_source_3 => p_source_3
133676 , p_source_11 => p_source_11
133677          , x_transaction_coa_id       => l_adr_transaction_coa_id
133678          , x_accounting_coa_id        => l_adr_accounting_coa_id
133679          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
133680          , x_flex_value_set_id        => l_adr_flex_value_set_id
133681          , x_value_type_code          => l_adr_value_type_code
133682          , x_value_combination_id     => l_adr_value_combination_id
133683          , x_value_segment_code       => l_adr_value_segment_code
133684          , p_side                     => 'NA'
133685          , p_override_seg_flag        => 'Y'
133686    );
133687 
133688    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
133689 
133690       xla_ae_lines_pkg.set_segment(
133691           p_to_segment_code         => 'GL_ACCOUNT'
133692         , p_segment_value           => l_segment
133693         , p_from_segment_code       => l_adr_value_segment_code
133694         , p_from_combination_id     => l_adr_value_combination_id
133695         , p_value_type_code         => l_adr_value_type_code
133696         , p_transaction_coa_id      => l_adr_transaction_coa_id
133697         , p_accounting_coa_id       => l_adr_accounting_coa_id
133698         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
133699         , p_flex_value_set_id       => l_adr_flex_value_set_id
133700         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
133701         , p_adr_type_code           => 'S'
133702         , p_component_type          => l_component_type
133703         , p_component_code          => l_component_code
133704         , p_component_type_code     => l_component_type_code
133705         , p_component_appl_id       => l_component_appl_id
133706         , p_amb_context_code        => l_amb_context_code
133707         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
133708         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
133709         , p_side                    => 'NA'
133710         );
133711 
133712   END IF;
133713 
133714    l_segment := AcctDerRule_168(
133715            p_application_id           => p_application_id
133716          , p_ae_header_id             => l_ae_header_id 
133717 , p_source_3 => p_source_3
133718 , p_source_29 => p_source_29
133719          , x_transaction_coa_id       => l_adr_transaction_coa_id
133720          , x_accounting_coa_id        => l_adr_accounting_coa_id
133721          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
133722          , x_flex_value_set_id        => l_adr_flex_value_set_id
133723          , x_value_type_code          => l_adr_value_type_code
133724          , x_value_combination_id     => l_adr_value_combination_id
133725          , x_value_segment_code       => l_adr_value_segment_code
133726          , p_side                     => 'NA'
133727          , p_override_seg_flag        => 'Y'
133728    );
133729 
133730    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
133731 
133732       xla_ae_lines_pkg.set_segment(
133733           p_to_segment_code         => 'GL_BALANCING'
133734         , p_segment_value           => l_segment
133735         , p_from_segment_code       => l_adr_value_segment_code
133739         , p_accounting_coa_id       => l_adr_accounting_coa_id
133736         , p_from_combination_id     => l_adr_value_combination_id
133737         , p_value_type_code         => l_adr_value_type_code
133738         , p_transaction_coa_id      => l_adr_transaction_coa_id
133740         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
133741         , p_flex_value_set_id       => l_adr_flex_value_set_id
133742         , p_adr_code                => 'FA_EXPENSE_ACCT'
133743         , p_adr_type_code           => 'S'
133744         , p_component_type          => l_component_type
133745         , p_component_code          => l_component_code
133746         , p_component_type_code     => l_component_type_code
133747         , p_component_appl_id       => l_component_appl_id
133748         , p_amb_context_code        => l_amb_context_code
133749         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
133750         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
133751         , p_side                    => 'NA'
133752         );
133753 
133754   END IF;
133755 
133756    --
133757    --
133758    END IF;
133759 
133760        --
133761        -- Update the line information that should be overwritten
133762        --
133763        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
133764                                          p_header_num   => 1);
133765        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
133766 
133767        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
133768 
133769        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
133770           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
133771        END IF;
133772 
133773       --
133774       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
133775       --
133776       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
133777           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
133778       ELSE
133779           ---------------------------------------------------------------------------------------------------
133780           -- 4262811a Switch Sign
133781           ---------------------------------------------------------------------------------------------------
133782           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
133783           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
133784                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
133785           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
133786                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
133787           -- 5132302
133788           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
133789                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
133790 
133791       END IF;
133792 
133793       -- 4955764
133794       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
133795       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
133796 
133797 
133798       XLA_AE_LINES_PKG.ValidateCurrentLine;
133799       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
133800 
133801       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
133802                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
133803                ,p_balance_type_code => l_balance_type_code);
133804 
133805    END IF;
133806 
133807    -----------------------------------------------------------------------------------------
133808    -- 4262811 Multiperiod Accounting
133809    -----------------------------------------------------------------------------------------
133810      -- No MPA option is assigned.
133811 
133812 
133813 END IF;
133814 END IF;
133815 --
133816 
133817 --
133818 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
133819    trace
133820       (p_msg      => 'END of AcctLineType_341'
133821       ,p_level    => C_LEVEL_PROCEDURE
133822       ,p_module   => l_log_module);
133823 END IF;
133824 --
133825 EXCEPTION
133826   WHEN xla_exceptions_pkg.application_exception THEN
133827       RAISE;
133828   WHEN OTHERS THEN
133829        xla_exceptions_pkg.raise_message
133830            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_341');
133831 END AcctLineType_341;
133832 --
133833 
133834 ---------------------------------------
133835 --
133836 -- PRIVATE FUNCTION
133837 --         AcctLineType_342
133838 --
133839 ---------------------------------------
133840 PROCEDURE AcctLineType_342 (
133841   p_application_id        IN NUMBER
133842  ,p_event_id              IN NUMBER
133843  ,p_calculate_acctd_flag  IN VARCHAR2
133844  ,p_calculate_g_l_flag    IN VARCHAR2
133845  ,p_actual_flag           IN OUT VARCHAR2
133846  ,p_balance_type_code     OUT VARCHAR2
133847  ,p_gain_or_loss_ref      OUT VARCHAR2
133848  
133849 --Period Close Date
133850  , p_source_1            IN DATE
133851 --Generated Code Combination Identifier
133852  , p_source_3            IN NUMBER
133853 --Asset Cost Account
133854  , p_source_9            IN VARCHAR2
133855 --Expense Account Code Combination Identifier
133856  , p_source_29            IN NUMBER
133857 --Default Code Combination Identifier
133858  , p_source_30            IN NUMBER
133859 --Adjustment Type
133860  , p_source_35            IN VARCHAR2
133861 --Transaction Header Identifier
133862  , p_source_36            IN NUMBER
133863 --Adjustment Line Identifier
133864  , p_source_37            IN NUMBER
133868  , p_source_39            IN NUMBER
133865 --Distribution Type Code
133866  , p_source_38            IN VARCHAR2
133867 --Entered Amount
133869 --Currency Code
133870  , p_source_40            IN VARCHAR2
133871 --Source Destination Code
133872  , p_source_42            IN VARCHAR2
133873 )
133874 IS
133875 
133876 l_component_type              VARCHAR2(80);
133877 l_component_code              VARCHAR2(30);
133878 l_component_type_code         VARCHAR2(1);
133879 l_component_appl_id           INTEGER;
133880 l_amb_context_code            VARCHAR2(30);
133881 l_entity_code                 VARCHAR2(30);
133882 l_event_class_code            VARCHAR2(30);
133883 l_ae_header_id                NUMBER;
133884 l_event_type_code             VARCHAR2(30);
133885 l_line_definition_code        VARCHAR2(30);
133886 l_line_definition_owner_code  VARCHAR2(1);
133887 --
133888 -- adr variables
133889 l_segment                     VARCHAR2(30);
133890 l_ccid                        NUMBER;
133891 l_adr_transaction_coa_id      NUMBER;
133892 l_adr_accounting_coa_id       NUMBER;
133893 l_adr_flexfield_segment_code  VARCHAR2(30);
133894 l_adr_flex_value_set_id       NUMBER;
133895 l_adr_value_type_code         VARCHAR2(30);
133896 l_adr_value_combination_id    NUMBER;
133897 l_adr_value_segment_code      VARCHAR2(30);
133898 
133899 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
133900 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
133901 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
133902 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
133903 
133904 -- 4262811 Variables ------------------------------------------------------------------------------------------
133905 l_entered_amt_idx             NUMBER;
133906 l_accted_amt_idx              NUMBER;
133907 l_acc_rev_flag                VARCHAR2(1);
133908 l_accrual_line_num            NUMBER;
133909 l_tmp_amt                     NUMBER;
133910 l_acc_rev_natural_side_code   VARCHAR2(1);
133911 
133912 l_num_entries                 NUMBER;
133913 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
133914 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
133915 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
133916 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
133917 l_recog_line_1                NUMBER;
133918 l_recog_line_2                NUMBER;
133919 
133920 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
133921 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
133922 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
133923 
133924 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
133925 
133926 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
133927 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
133928 
133929 ---------------------------------------------------------------------------------------------------------------
133930 
133931 
133932 --
133933 -- bulk performance
133934 --
133935 l_balance_type_code           VARCHAR2(1);
133936 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
133937 l_log_module                  VARCHAR2(240);
133938 
133939 --
133940 -- Upgrade strategy
133941 --
133942 l_actual_upg_option           VARCHAR2(1);
133943 l_enc_upg_option           VARCHAR2(1);
133944 
133945 --
133946 BEGIN
133947 --
133948 IF g_log_enabled THEN
133949       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_342';
133950 END IF;
133951 --
133952 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
133953 
133954       trace
133955          (p_msg      => 'BEGIN of AcctLineType_342'
133956          ,p_level    => C_LEVEL_PROCEDURE
133957          ,p_module   => l_log_module);
133958 
133959 END IF;
133960 --
133961 l_component_type             := 'AMB_JLT';
133962 l_component_code             := 'FA_SLT_DEST_COST';
133963 l_component_type_code        := 'S';
133964 l_component_appl_id          :=  140;
133965 l_amb_context_code           := 'DEFAULT';
133966 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
133967 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
133968 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
133969 l_line_definition_owner_code := 'S';
133970 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
133971 --
133972 l_balance_type_code          := 'A';
133973 l_segment                     := NULL;
133974 l_ccid                        := NULL;
133975 l_adr_transaction_coa_id      := NULL;
133976 l_adr_accounting_coa_id       := NULL;
133977 l_adr_flexfield_segment_code  := NULL;
133978 l_adr_flex_value_set_id       := NULL;
133979 l_adr_value_type_code         := NULL;
133980 l_adr_value_combination_id    := NULL;
133981 l_adr_value_segment_code      := NULL;
133982 
133983 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
133984 l_bflow_class_code           := '';    -- 4219869 Business Flow
133985 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
133986 l_budgetary_control_flag     := 'N';
133987 
133988 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
133989 l_bflow_applied_to_amt       := NULL; -- 5132302
133990 l_entered_amt_idx            := NULL;          -- 4262811
133991 l_accted_amt_idx             := NULL;          -- 4262811
133992 l_acc_rev_flag               := NULL;          -- 4262811
133993 l_accrual_line_num           := NULL;          -- 4262811
133994 l_tmp_amt                    := NULL;          -- 4262811
133995 --
133996  
133997 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
133998     l_balance_type_code <> 'B' THEN
133999 IF NVL(p_source_35,'
134000 ') =  'COST' AND 
134001 NVL(p_source_42,'
134002 ') =  'DEST'
134006    XLA_AE_LINES_PKG.SetNewLine;
134003  THEN 
134004 
134005    --
134007 
134008    p_balance_type_code          := l_balance_type_code;
134009    -- set the flag so later we will know whether the gain loss line needs to be created
134010    
134011    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
134012      p_actual_flag :='A';
134013    END IF;
134014 
134015    --
134016    -- bulk performance
134017    --
134018    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
134019                                       p_header_num   => 0); -- 4262811
134020    --
134021    -- set accounting line options
134022    --
134023    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
134024            p_natural_side_code          => 'D'
134025          , p_gain_or_loss_flag          => 'N'
134026          , p_gl_transfer_mode_code      => 'S'
134027          , p_acct_entry_type_code       => 'A'
134028          , p_switch_side_flag           => 'Y'
134029          , p_merge_duplicate_code       => 'N'
134030          );
134031    --
134032    l_acc_rev_natural_side_code := 'C';  -- 4262811
134033    -- 
134034    --
134035    -- set accounting line type info
134036    --
134037    xla_ae_lines_pkg.SetAcctLineType
134038       (p_component_type             => l_component_type
134039       ,p_event_type_code            => l_event_type_code
134040       ,p_line_definition_owner_code => l_line_definition_owner_code
134041       ,p_line_definition_code       => l_line_definition_code
134042       ,p_accounting_line_code       => l_component_code
134043       ,p_accounting_line_type_code  => l_component_type_code
134044       ,p_accounting_line_appl_id    => l_component_appl_id
134045       ,p_amb_context_code           => l_amb_context_code
134046       ,p_entity_code                => l_entity_code
134047       ,p_event_class_code           => l_event_class_code);
134048    --
134049    -- set accounting class
134050    --
134051    xla_ae_lines_pkg.SetAcctClass(
134052            p_accounting_class_code  => 'ASSET'
134053          , p_ae_header_id           => l_ae_header_id
134054          );
134055 
134056    --
134057    -- set rounding class
134058    --
134059    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
134060                       'ASSET';
134061 
134062    --
134063    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
134064    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
134065    --
134066    -- bulk performance
134067    --
134068    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
134069 
134070    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
134071       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
134072 
134073    -- 4955764
134074    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
134075       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
134076 
134077    -- 4458381 Public Sector Enh
134078    
134079    --
134080    -- set accounting attributes for the line type
134081    --
134082    l_entered_amt_idx := 4;
134083    l_accted_amt_idx  := 6;
134084    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
134085    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
134086    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
134087    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
134088    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
134089    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
134090    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
134091    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
134092    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
134093    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
134094    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
134095    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
134096    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
134097 
134098    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
134099    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
134100 
134101    ---------------------------------------------------------------------------------------------------------------
134102    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
134103    ---------------------------------------------------------------------------------------------------------------
134104    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
134105 
134106    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
134107    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
134108 
134109    IF xla_accounting_cache_pkg.GetValueChar
134110          (p_source_code         => 'LEDGER_CATEGORY_CODE'
134111          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
134112    AND l_bflow_method_code = 'PRIOR_ENTRY'
134113 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
134114    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
134115          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
134116        )
134117    THEN
134118          xla_ae_lines_pkg.BflowUpgEntry
134119            (p_business_method_code    => l_bflow_method_code
134120            ,p_business_class_code     => l_bflow_class_code
134121            ,p_balance_type            => l_balance_type_code);
134122    ELSE
134123       NULL;
134124 -- No business flow processing for business flow method of NONE.
134125    END IF;
134126 
134130    
134127    --
134128    -- call analytical criteria
134129    --
134131    --
134132    -- call description
134133    --
134134    
134135 xla_ae_lines_pkg.SetLineDescription(
134136    p_ae_header_id => l_ae_header_id
134137   ,p_description  => Description_110 (
134138      p_application_id         => p_application_id
134139    , p_ae_header_id           => l_ae_header_id 
134140 , p_source_1 => p_source_1
134141    )
134142 );
134143 
134144 
134145    --
134146    -- call ADRs
134147    -- Bug 4922099
134148    --
134149    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
134150         (NVL(l_actual_upg_option, 'N') = 'O') OR
134151         (NVL(l_enc_upg_option, 'N') = 'O')
134152       )
134153    THEN
134154    NULL;
134155    --
134156    --
134157    
134158   l_ccid := AcctDerRule_173(
134159            p_application_id           => p_application_id
134160          , p_ae_header_id             => l_ae_header_id 
134161 , p_source_3 => p_source_3
134162 , p_source_30 => p_source_30
134163          , x_transaction_coa_id       => l_adr_transaction_coa_id
134164          , x_accounting_coa_id        => l_adr_accounting_coa_id
134165          , x_value_type_code          => l_adr_value_type_code
134166          , p_side                     => 'NA'
134167    );
134168 
134169    xla_ae_lines_pkg.set_ccid(
134170     p_code_combination_id          => l_ccid
134171   , p_value_type_code              => l_adr_value_type_code
134172   , p_transaction_coa_id           => l_adr_transaction_coa_id
134173   , p_accounting_coa_id            => l_adr_accounting_coa_id
134174   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
134175   , p_adr_type_code                => 'S'
134176   , p_component_type               => l_component_type
134177   , p_component_code               => l_component_code
134178   , p_component_type_code          => l_component_type_code
134179   , p_component_appl_id            => l_component_appl_id
134180   , p_amb_context_code             => l_amb_context_code
134181   , p_side                         => 'NA'
134182   );
134183 
134184 
134185    l_segment := AcctDerRule_148(
134186            p_application_id           => p_application_id
134187          , p_ae_header_id             => l_ae_header_id 
134188 , p_source_3 => p_source_3
134189 , p_source_9 => p_source_9
134190          , x_transaction_coa_id       => l_adr_transaction_coa_id
134191          , x_accounting_coa_id        => l_adr_accounting_coa_id
134192          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
134193          , x_flex_value_set_id        => l_adr_flex_value_set_id
134194          , x_value_type_code          => l_adr_value_type_code
134195          , x_value_combination_id     => l_adr_value_combination_id
134196          , x_value_segment_code       => l_adr_value_segment_code
134197          , p_side                     => 'NA'
134198          , p_override_seg_flag        => 'Y'
134199    );
134200 
134201    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
134202 
134203       xla_ae_lines_pkg.set_segment(
134204           p_to_segment_code         => 'GL_ACCOUNT'
134205         , p_segment_value           => l_segment
134206         , p_from_segment_code       => l_adr_value_segment_code
134207         , p_from_combination_id     => l_adr_value_combination_id
134208         , p_value_type_code         => l_adr_value_type_code
134209         , p_transaction_coa_id      => l_adr_transaction_coa_id
134210         , p_accounting_coa_id       => l_adr_accounting_coa_id
134211         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
134212         , p_flex_value_set_id       => l_adr_flex_value_set_id
134213         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
134214         , p_adr_type_code           => 'S'
134215         , p_component_type          => l_component_type
134216         , p_component_code          => l_component_code
134217         , p_component_type_code     => l_component_type_code
134218         , p_component_appl_id       => l_component_appl_id
134219         , p_amb_context_code        => l_amb_context_code
134220         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
134221         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
134222         , p_side                    => 'NA'
134223         );
134224 
134225   END IF;
134226 
134227    l_segment := AcctDerRule_168(
134228            p_application_id           => p_application_id
134229          , p_ae_header_id             => l_ae_header_id 
134230 , p_source_3 => p_source_3
134231 , p_source_29 => p_source_29
134232          , x_transaction_coa_id       => l_adr_transaction_coa_id
134233          , x_accounting_coa_id        => l_adr_accounting_coa_id
134234          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
134235          , x_flex_value_set_id        => l_adr_flex_value_set_id
134236          , x_value_type_code          => l_adr_value_type_code
134237          , x_value_combination_id     => l_adr_value_combination_id
134238          , x_value_segment_code       => l_adr_value_segment_code
134239          , p_side                     => 'NA'
134240          , p_override_seg_flag        => 'Y'
134241    );
134242 
134243    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
134244 
134245       xla_ae_lines_pkg.set_segment(
134246           p_to_segment_code         => 'GL_BALANCING'
134247         , p_segment_value           => l_segment
134248         , p_from_segment_code       => l_adr_value_segment_code
134249         , p_from_combination_id     => l_adr_value_combination_id
134250         , p_value_type_code         => l_adr_value_type_code
134251         , p_transaction_coa_id      => l_adr_transaction_coa_id
134252         , p_accounting_coa_id       => l_adr_accounting_coa_id
134253         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
134254         , p_flex_value_set_id       => l_adr_flex_value_set_id
134255         , p_adr_code                => 'FA_EXPENSE_ACCT'
134259         , p_component_type_code     => l_component_type_code
134256         , p_adr_type_code           => 'S'
134257         , p_component_type          => l_component_type
134258         , p_component_code          => l_component_code
134260         , p_component_appl_id       => l_component_appl_id
134261         , p_amb_context_code        => l_amb_context_code
134262         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
134263         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
134264         , p_side                    => 'NA'
134265         );
134266 
134267   END IF;
134268 
134269    --
134270    --
134271    END IF;
134272    --
134273    -- Bug 4922099
134274    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
134275           (NVL(l_enc_upg_option, 'N') = 'O')
134276         ) AND
134277         (l_bflow_method_code = 'PRIOR_ENTRY')
134278       )
134279    THEN
134280       IF
134281       --
134282       1 = 2
134283       --
134284       THEN
134285       xla_accounting_err_pkg.build_message
134286                                     (p_appli_s_name            => 'XLA'
134287                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
134288                                     ,p_token_1                 => 'LINE_NUMBER'
134289                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
134290                                     ,p_token_2                 => 'LINE_TYPE_NAME'
134291                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
134292                                                                              l_component_type
134293                                                                             ,l_component_code
134294                                                                             ,l_component_type_code
134295                                                                             ,l_component_appl_id
134296                                                                             ,l_amb_context_code
134297                                                                             ,l_entity_code
134298                                                                             ,l_event_class_code
134299                                                                            )
134300                                     ,p_token_3                 => 'OWNER'
134301                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
134302                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
134303                                                                           ,p_lookup_code    => l_component_type_code
134304                                                                          )
134305                                     ,p_token_4                 => 'PRODUCT_NAME'
134306                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
134307                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
134308                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
134309                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
134310                                     ,p_ae_header_id            =>  NULL
134311                                        );
134312 
134313         IF (C_LEVEL_ERROR>= g_log_level) THEN
134314                  trace
134315                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
134316                       ,p_level    => C_LEVEL_ERROR
134317                       ,p_module   => l_log_module);
134318         END IF;
134319       END IF;
134320    END IF;
134321    --
134322    --
134323    ------------------------------------------------------------------------------------------------
134324    -- 4219869 Business Flow
134325    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
134326    -- Prior Entry.  Currently, the following code is always generated.
134327    ------------------------------------------------------------------------------------------------
134328    XLA_AE_LINES_PKG.ValidateCurrentLine;
134329 
134330    ------------------------------------------------------------------------------------
134331    -- 4219869 Business Flow
134332    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
134333    ------------------------------------------------------------------------------------
134334    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
134335 
134336    ----------------------------------------------------------------------------------
134337    -- 4219869 Business Flow
134338    -- Update journal entry status -- Need to generate this within IF <condition>
134339    ----------------------------------------------------------------------------------
134340    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
134341          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
134342          ,p_balance_type_code => l_balance_type_code
134343          );
134344 
134345    -------------------------------------------------------------------------------------------
134346    -- 4262811 - Generate the Accrual Reversal lines
134347    -------------------------------------------------------------------------------------------
134348    BEGIN
134349       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
134350                               (g_array_event(p_event_id).array_value_num('header_index'));
134351       IF l_acc_rev_flag IS NULL THEN
134352          l_acc_rev_flag := 'N';
134353       END IF;
134354    EXCEPTION
134355       WHEN OTHERS THEN
134356          l_acc_rev_flag := 'N';
134357    END;
134358    --
134359    IF (l_acc_rev_flag = 'Y') THEN
134360 
134361        -- 4645092  ------------------------------------------------------------------------------
134365 
134362        -- To allow MPA report to determine if it should generate report process
134363        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
134364        ------------------------------------------------------------------------------------------
134366        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
134367        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
134368    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
134369    -- call ADRs
134370    -- Bug 4922099
134371    --
134372    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
134373         (NVL(l_actual_upg_option, 'N') = 'O') OR
134374         (NVL(l_enc_upg_option, 'N') = 'O')
134375       )
134376    THEN
134377    NULL;
134378    --
134379    --
134380    
134381   l_ccid := AcctDerRule_173(
134382            p_application_id           => p_application_id
134383          , p_ae_header_id             => l_ae_header_id 
134384 , p_source_3 => p_source_3
134385 , p_source_30 => p_source_30
134386          , x_transaction_coa_id       => l_adr_transaction_coa_id
134387          , x_accounting_coa_id        => l_adr_accounting_coa_id
134388          , x_value_type_code          => l_adr_value_type_code
134389          , p_side                     => 'NA'
134390    );
134391 
134392    xla_ae_lines_pkg.set_ccid(
134393     p_code_combination_id          => l_ccid
134394   , p_value_type_code              => l_adr_value_type_code
134395   , p_transaction_coa_id           => l_adr_transaction_coa_id
134396   , p_accounting_coa_id            => l_adr_accounting_coa_id
134397   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
134398   , p_adr_type_code                => 'S'
134399   , p_component_type               => l_component_type
134400   , p_component_code               => l_component_code
134401   , p_component_type_code          => l_component_type_code
134402   , p_component_appl_id            => l_component_appl_id
134403   , p_amb_context_code             => l_amb_context_code
134404   , p_side                         => 'NA'
134405   );
134406 
134407 
134408    l_segment := AcctDerRule_148(
134409            p_application_id           => p_application_id
134410          , p_ae_header_id             => l_ae_header_id 
134411 , p_source_3 => p_source_3
134412 , p_source_9 => p_source_9
134413          , x_transaction_coa_id       => l_adr_transaction_coa_id
134414          , x_accounting_coa_id        => l_adr_accounting_coa_id
134415          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
134416          , x_flex_value_set_id        => l_adr_flex_value_set_id
134417          , x_value_type_code          => l_adr_value_type_code
134418          , x_value_combination_id     => l_adr_value_combination_id
134419          , x_value_segment_code       => l_adr_value_segment_code
134420          , p_side                     => 'NA'
134421          , p_override_seg_flag        => 'Y'
134422    );
134423 
134424    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
134425 
134426       xla_ae_lines_pkg.set_segment(
134427           p_to_segment_code         => 'GL_ACCOUNT'
134428         , p_segment_value           => l_segment
134429         , p_from_segment_code       => l_adr_value_segment_code
134430         , p_from_combination_id     => l_adr_value_combination_id
134431         , p_value_type_code         => l_adr_value_type_code
134432         , p_transaction_coa_id      => l_adr_transaction_coa_id
134433         , p_accounting_coa_id       => l_adr_accounting_coa_id
134434         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
134435         , p_flex_value_set_id       => l_adr_flex_value_set_id
134436         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
134437         , p_adr_type_code           => 'S'
134438         , p_component_type          => l_component_type
134439         , p_component_code          => l_component_code
134440         , p_component_type_code     => l_component_type_code
134441         , p_component_appl_id       => l_component_appl_id
134442         , p_amb_context_code        => l_amb_context_code
134443         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
134444         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
134445         , p_side                    => 'NA'
134446         );
134447 
134448   END IF;
134449 
134450    l_segment := AcctDerRule_168(
134451            p_application_id           => p_application_id
134452          , p_ae_header_id             => l_ae_header_id 
134453 , p_source_3 => p_source_3
134454 , p_source_29 => p_source_29
134455          , x_transaction_coa_id       => l_adr_transaction_coa_id
134456          , x_accounting_coa_id        => l_adr_accounting_coa_id
134457          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
134458          , x_flex_value_set_id        => l_adr_flex_value_set_id
134459          , x_value_type_code          => l_adr_value_type_code
134460          , x_value_combination_id     => l_adr_value_combination_id
134461          , x_value_segment_code       => l_adr_value_segment_code
134462          , p_side                     => 'NA'
134463          , p_override_seg_flag        => 'Y'
134464    );
134465 
134466    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
134467 
134468       xla_ae_lines_pkg.set_segment(
134469           p_to_segment_code         => 'GL_BALANCING'
134470         , p_segment_value           => l_segment
134471         , p_from_segment_code       => l_adr_value_segment_code
134472         , p_from_combination_id     => l_adr_value_combination_id
134473         , p_value_type_code         => l_adr_value_type_code
134474         , p_transaction_coa_id      => l_adr_transaction_coa_id
134475         , p_accounting_coa_id       => l_adr_accounting_coa_id
134476         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
134477         , p_flex_value_set_id       => l_adr_flex_value_set_id
134478         , p_adr_code                => 'FA_EXPENSE_ACCT'
134479         , p_adr_type_code           => 'S'
134483         , p_component_appl_id       => l_component_appl_id
134480         , p_component_type          => l_component_type
134481         , p_component_code          => l_component_code
134482         , p_component_type_code     => l_component_type_code
134484         , p_amb_context_code        => l_amb_context_code
134485         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
134486         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
134487         , p_side                    => 'NA'
134488         );
134489 
134490   END IF;
134491 
134492    --
134493    --
134494    END IF;
134495 
134496        --
134497        -- Update the line information that should be overwritten
134498        --
134499        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
134500                                          p_header_num   => 1);
134501        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
134502 
134503        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
134504 
134505        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
134506           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
134507        END IF;
134508 
134509       --
134510       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
134511       --
134512       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
134513           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
134514       ELSE
134515           ---------------------------------------------------------------------------------------------------
134516           -- 4262811a Switch Sign
134517           ---------------------------------------------------------------------------------------------------
134518           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
134519           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
134520                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
134521           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
134522                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
134523           -- 5132302
134524           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
134525                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
134526 
134527       END IF;
134528 
134529       -- 4955764
134530       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
134531       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
134532 
134533 
134534       XLA_AE_LINES_PKG.ValidateCurrentLine;
134535       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
134536 
134537       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
134538                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
134539                ,p_balance_type_code => l_balance_type_code);
134540 
134541    END IF;
134542 
134543    -----------------------------------------------------------------------------------------
134544    -- 4262811 Multiperiod Accounting
134545    -----------------------------------------------------------------------------------------
134546      -- No MPA option is assigned.
134547 
134548 
134549 END IF;
134550 END IF;
134551 --
134552 
134553 --
134554 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
134555    trace
134556       (p_msg      => 'END of AcctLineType_342'
134557       ,p_level    => C_LEVEL_PROCEDURE
134558       ,p_module   => l_log_module);
134559 END IF;
134560 --
134561 EXCEPTION
134562   WHEN xla_exceptions_pkg.application_exception THEN
134563       RAISE;
134564   WHEN OTHERS THEN
134565        xla_exceptions_pkg.raise_message
134566            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_342');
134567 END AcctLineType_342;
134568 --
134569 
134570 ---------------------------------------
134571 --
134572 -- PRIVATE FUNCTION
134573 --         AcctLineType_343
134574 --
134575 ---------------------------------------
134576 PROCEDURE AcctLineType_343 (
134577   p_application_id        IN NUMBER
134578  ,p_event_id              IN NUMBER
134579  ,p_calculate_acctd_flag  IN VARCHAR2
134580  ,p_calculate_g_l_flag    IN VARCHAR2
134581  ,p_actual_flag           IN OUT VARCHAR2
134582  ,p_balance_type_code     OUT VARCHAR2
134583  ,p_gain_or_loss_ref      OUT VARCHAR2
134584  
134585 --Period Close Date
134586  , p_source_1            IN DATE
134587 --Generated Code Combination Identifier
134588  , p_source_3            IN NUMBER
134589 --Payables Code Combination Identifier
134590  , p_source_6            IN NUMBER
134591 --Asset Clearing Account
134592  , p_source_8            IN VARCHAR2
134593 --Expense Account Code Combination Identifier
134594  , p_source_29            IN NUMBER
134595 --Default Code Combination Identifier
134596  , p_source_30            IN NUMBER
134597 --Adjustment Type
134598  , p_source_35            IN VARCHAR2
134599 --Transaction Header Identifier
134600  , p_source_36            IN NUMBER
134601 --Adjustment Line Identifier
134602  , p_source_37            IN NUMBER
134603 --Distribution Type Code
134604  , p_source_38            IN VARCHAR2
134605 --Entered Amount
134606  , p_source_39            IN NUMBER
134607 --Currency Code
134608  , p_source_40            IN VARCHAR2
134609 --Source Destination Code
134610  , p_source_42            IN VARCHAR2
134611 )
134612 IS
134613 
134614 l_component_type              VARCHAR2(80);
134618 l_amb_context_code            VARCHAR2(30);
134615 l_component_code              VARCHAR2(30);
134616 l_component_type_code         VARCHAR2(1);
134617 l_component_appl_id           INTEGER;
134619 l_entity_code                 VARCHAR2(30);
134620 l_event_class_code            VARCHAR2(30);
134621 l_ae_header_id                NUMBER;
134622 l_event_type_code             VARCHAR2(30);
134623 l_line_definition_code        VARCHAR2(30);
134624 l_line_definition_owner_code  VARCHAR2(1);
134625 --
134626 -- adr variables
134627 l_segment                     VARCHAR2(30);
134628 l_ccid                        NUMBER;
134629 l_adr_transaction_coa_id      NUMBER;
134630 l_adr_accounting_coa_id       NUMBER;
134631 l_adr_flexfield_segment_code  VARCHAR2(30);
134632 l_adr_flex_value_set_id       NUMBER;
134633 l_adr_value_type_code         VARCHAR2(30);
134634 l_adr_value_combination_id    NUMBER;
134635 l_adr_value_segment_code      VARCHAR2(30);
134636 
134637 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
134638 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
134639 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
134640 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
134641 
134642 -- 4262811 Variables ------------------------------------------------------------------------------------------
134643 l_entered_amt_idx             NUMBER;
134644 l_accted_amt_idx              NUMBER;
134645 l_acc_rev_flag                VARCHAR2(1);
134646 l_accrual_line_num            NUMBER;
134647 l_tmp_amt                     NUMBER;
134648 l_acc_rev_natural_side_code   VARCHAR2(1);
134649 
134650 l_num_entries                 NUMBER;
134651 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
134652 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
134653 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
134654 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
134655 l_recog_line_1                NUMBER;
134656 l_recog_line_2                NUMBER;
134657 
134658 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
134659 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
134660 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
134661 
134662 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
134663 
134664 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
134665 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
134666 
134667 ---------------------------------------------------------------------------------------------------------------
134668 
134669 
134670 --
134671 -- bulk performance
134672 --
134673 l_balance_type_code           VARCHAR2(1);
134674 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
134675 l_log_module                  VARCHAR2(240);
134676 
134677 --
134678 -- Upgrade strategy
134679 --
134680 l_actual_upg_option           VARCHAR2(1);
134681 l_enc_upg_option           VARCHAR2(1);
134682 
134683 --
134684 BEGIN
134685 --
134686 IF g_log_enabled THEN
134687       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_343';
134688 END IF;
134689 --
134690 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
134691 
134692       trace
134693          (p_msg      => 'BEGIN of AcctLineType_343'
134694          ,p_level    => C_LEVEL_PROCEDURE
134695          ,p_module   => l_log_module);
134696 
134697 END IF;
134698 --
134699 l_component_type             := 'AMB_JLT';
134700 l_component_code             := 'FA_SLT_DEST_COST_CLEARING';
134701 l_component_type_code        := 'S';
134702 l_component_appl_id          :=  140;
134703 l_amb_context_code           := 'DEFAULT';
134704 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
134705 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
134706 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
134707 l_line_definition_owner_code := 'S';
134708 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
134709 --
134710 l_balance_type_code          := 'A';
134711 l_segment                     := NULL;
134712 l_ccid                        := NULL;
134713 l_adr_transaction_coa_id      := NULL;
134714 l_adr_accounting_coa_id       := NULL;
134715 l_adr_flexfield_segment_code  := NULL;
134716 l_adr_flex_value_set_id       := NULL;
134717 l_adr_value_type_code         := NULL;
134718 l_adr_value_combination_id    := NULL;
134719 l_adr_value_segment_code      := NULL;
134720 
134721 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
134722 l_bflow_class_code           := '';    -- 4219869 Business Flow
134723 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
134724 l_budgetary_control_flag     := 'N';
134725 
134726 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
134727 l_bflow_applied_to_amt       := NULL; -- 5132302
134728 l_entered_amt_idx            := NULL;          -- 4262811
134729 l_accted_amt_idx             := NULL;          -- 4262811
134730 l_acc_rev_flag               := NULL;          -- 4262811
134731 l_accrual_line_num           := NULL;          -- 4262811
134732 l_tmp_amt                    := NULL;          -- 4262811
134733 --
134734  
134735 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
134736     l_balance_type_code <> 'B' THEN
134737 IF NVL(p_source_35,'
134738 ') =  'COST CLEARING' AND 
134739 NVL(p_source_42,'
134740 ') =  'DEST'
134741  THEN 
134742 
134743    --
134744    XLA_AE_LINES_PKG.SetNewLine;
134745 
134746    p_balance_type_code          := l_balance_type_code;
134747    -- set the flag so later we will know whether the gain loss line needs to be created
134748    
134749    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
134750      p_actual_flag :='A';
134754    -- bulk performance
134751    END IF;
134752 
134753    --
134755    --
134756    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
134757                                       p_header_num   => 0); -- 4262811
134758    --
134759    -- set accounting line options
134760    --
134761    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
134762            p_natural_side_code          => 'C'
134763          , p_gain_or_loss_flag          => 'N'
134764          , p_gl_transfer_mode_code      => 'S'
134765          , p_acct_entry_type_code       => 'A'
134766          , p_switch_side_flag           => 'Y'
134767          , p_merge_duplicate_code       => 'N'
134768          );
134769    --
134770    l_acc_rev_natural_side_code := 'D';  -- 4262811
134771    -- 
134772    --
134773    -- set accounting line type info
134774    --
134775    xla_ae_lines_pkg.SetAcctLineType
134776       (p_component_type             => l_component_type
134777       ,p_event_type_code            => l_event_type_code
134778       ,p_line_definition_owner_code => l_line_definition_owner_code
134779       ,p_line_definition_code       => l_line_definition_code
134780       ,p_accounting_line_code       => l_component_code
134781       ,p_accounting_line_type_code  => l_component_type_code
134782       ,p_accounting_line_appl_id    => l_component_appl_id
134783       ,p_amb_context_code           => l_amb_context_code
134784       ,p_entity_code                => l_entity_code
134785       ,p_event_class_code           => l_event_class_code);
134786    --
134787    -- set accounting class
134788    --
134789    xla_ae_lines_pkg.SetAcctClass(
134790            p_accounting_class_code  => 'ASSET'
134791          , p_ae_header_id           => l_ae_header_id
134792          );
134793 
134794    --
134795    -- set rounding class
134796    --
134797    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
134798                       'ASSET';
134799 
134800    --
134801    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
134802    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
134803    --
134804    -- bulk performance
134805    --
134806    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
134807 
134808    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
134809       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
134810 
134811    -- 4955764
134812    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
134813       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
134814 
134815    -- 4458381 Public Sector Enh
134816    
134817    --
134818    -- set accounting attributes for the line type
134819    --
134820    l_entered_amt_idx := 4;
134821    l_accted_amt_idx  := 6;
134822    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
134823    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
134824    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
134825    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
134826    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
134827    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
134828    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
134829    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
134830    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
134831    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
134832    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
134833    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
134834    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
134835 
134836    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
134837    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
134838 
134839    ---------------------------------------------------------------------------------------------------------------
134840    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
134841    ---------------------------------------------------------------------------------------------------------------
134842    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
134843 
134844    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
134845    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
134846 
134847    IF xla_accounting_cache_pkg.GetValueChar
134848          (p_source_code         => 'LEDGER_CATEGORY_CODE'
134849          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
134850    AND l_bflow_method_code = 'PRIOR_ENTRY'
134851 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
134852    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
134853          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
134854        )
134855    THEN
134856          xla_ae_lines_pkg.BflowUpgEntry
134857            (p_business_method_code    => l_bflow_method_code
134858            ,p_business_class_code     => l_bflow_class_code
134859            ,p_balance_type            => l_balance_type_code);
134860    ELSE
134861       NULL;
134862 -- No business flow processing for business flow method of NONE.
134863    END IF;
134864 
134865    --
134866    -- call analytical criteria
134867    --
134868    
134869    --
134870    -- call description
134871    --
134872    
134873 xla_ae_lines_pkg.SetLineDescription(
134874    p_ae_header_id => l_ae_header_id
134875   ,p_description  => Description_111 (
134876      p_application_id         => p_application_id
134880 );
134877    , p_ae_header_id           => l_ae_header_id 
134878 , p_source_1 => p_source_1
134879    )
134881 
134882 
134883    --
134884    -- call ADRs
134885    -- Bug 4922099
134886    --
134887    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
134888         (NVL(l_actual_upg_option, 'N') = 'O') OR
134889         (NVL(l_enc_upg_option, 'N') = 'O')
134890       )
134891    THEN
134892    NULL;
134893    --
134894    --
134895    
134896   l_ccid := AcctDerRule_172(
134897            p_application_id           => p_application_id
134898          , p_ae_header_id             => l_ae_header_id 
134899 , p_source_3 => p_source_3
134900 , p_source_6 => p_source_6
134901 , p_source_30 => p_source_30
134902          , x_transaction_coa_id       => l_adr_transaction_coa_id
134903          , x_accounting_coa_id        => l_adr_accounting_coa_id
134904          , x_value_type_code          => l_adr_value_type_code
134905          , p_side                     => 'NA'
134906    );
134907 
134908    xla_ae_lines_pkg.set_ccid(
134909     p_code_combination_id          => l_ccid
134910   , p_value_type_code              => l_adr_value_type_code
134911   , p_transaction_coa_id           => l_adr_transaction_coa_id
134912   , p_accounting_coa_id            => l_adr_accounting_coa_id
134913   , p_adr_code                     => 'FA_CAT_COST_CLEARING'
134914   , p_adr_type_code                => 'S'
134915   , p_component_type               => l_component_type
134916   , p_component_code               => l_component_code
134917   , p_component_type_code          => l_component_type_code
134918   , p_component_appl_id            => l_component_appl_id
134919   , p_amb_context_code             => l_amb_context_code
134920   , p_side                         => 'NA'
134921   );
134922 
134923 
134924    l_segment := AcctDerRule_147(
134925            p_application_id           => p_application_id
134926          , p_ae_header_id             => l_ae_header_id 
134927 , p_source_3 => p_source_3
134928 , p_source_6 => p_source_6
134929 , p_source_8 => p_source_8
134930          , x_transaction_coa_id       => l_adr_transaction_coa_id
134931          , x_accounting_coa_id        => l_adr_accounting_coa_id
134932          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
134933          , x_flex_value_set_id        => l_adr_flex_value_set_id
134934          , x_value_type_code          => l_adr_value_type_code
134935          , x_value_combination_id     => l_adr_value_combination_id
134936          , x_value_segment_code       => l_adr_value_segment_code
134937          , p_side                     => 'NA'
134938          , p_override_seg_flag        => 'Y'
134939    );
134940 
134941    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
134942 
134943       xla_ae_lines_pkg.set_segment(
134944           p_to_segment_code         => 'GL_ACCOUNT'
134945         , p_segment_value           => l_segment
134946         , p_from_segment_code       => l_adr_value_segment_code
134947         , p_from_combination_id     => l_adr_value_combination_id
134948         , p_value_type_code         => l_adr_value_type_code
134949         , p_transaction_coa_id      => l_adr_transaction_coa_id
134950         , p_accounting_coa_id       => l_adr_accounting_coa_id
134951         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
134952         , p_flex_value_set_id       => l_adr_flex_value_set_id
134953         , p_adr_code                => 'FA_CAT_CLR_ACCOUNT_SEGMENT'
134954         , p_adr_type_code           => 'S'
134955         , p_component_type          => l_component_type
134956         , p_component_code          => l_component_code
134957         , p_component_type_code     => l_component_type_code
134958         , p_component_appl_id       => l_component_appl_id
134959         , p_amb_context_code        => l_amb_context_code
134960         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
134961         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
134962         , p_side                    => 'NA'
134963         );
134964 
134965   END IF;
134966 
134967    l_segment := AcctDerRule_169(
134968            p_application_id           => p_application_id
134969          , p_ae_header_id             => l_ae_header_id 
134970 , p_source_3 => p_source_3
134971 , p_source_6 => p_source_6
134972 , p_source_29 => p_source_29
134973          , x_transaction_coa_id       => l_adr_transaction_coa_id
134974          , x_accounting_coa_id        => l_adr_accounting_coa_id
134975          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
134976          , x_flex_value_set_id        => l_adr_flex_value_set_id
134977          , x_value_type_code          => l_adr_value_type_code
134978          , x_value_combination_id     => l_adr_value_combination_id
134979          , x_value_segment_code       => l_adr_value_segment_code
134980          , p_side                     => 'NA'
134981          , p_override_seg_flag        => 'Y'
134982    );
134983 
134984    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
134985 
134986       xla_ae_lines_pkg.set_segment(
134987           p_to_segment_code         => 'GL_BALANCING'
134988         , p_segment_value           => l_segment
134989         , p_from_segment_code       => l_adr_value_segment_code
134990         , p_from_combination_id     => l_adr_value_combination_id
134991         , p_value_type_code         => l_adr_value_type_code
134992         , p_transaction_coa_id      => l_adr_transaction_coa_id
134993         , p_accounting_coa_id       => l_adr_accounting_coa_id
134994         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
134995         , p_flex_value_set_id       => l_adr_flex_value_set_id
134996         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
134997         , p_adr_type_code           => 'S'
134998         , p_component_type          => l_component_type
134999         , p_component_code          => l_component_code
135000         , p_component_type_code     => l_component_type_code
135004         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
135001         , p_component_appl_id       => l_component_appl_id
135002         , p_amb_context_code        => l_amb_context_code
135003         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
135005         , p_side                    => 'NA'
135006         );
135007 
135008   END IF;
135009 
135010    --
135011    --
135012    END IF;
135013    --
135014    -- Bug 4922099
135015    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
135016           (NVL(l_enc_upg_option, 'N') = 'O')
135017         ) AND
135018         (l_bflow_method_code = 'PRIOR_ENTRY')
135019       )
135020    THEN
135021       IF
135022       --
135023       1 = 2
135024       --
135025       THEN
135026       xla_accounting_err_pkg.build_message
135027                                     (p_appli_s_name            => 'XLA'
135028                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
135029                                     ,p_token_1                 => 'LINE_NUMBER'
135030                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
135031                                     ,p_token_2                 => 'LINE_TYPE_NAME'
135032                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
135033                                                                              l_component_type
135034                                                                             ,l_component_code
135035                                                                             ,l_component_type_code
135036                                                                             ,l_component_appl_id
135037                                                                             ,l_amb_context_code
135038                                                                             ,l_entity_code
135039                                                                             ,l_event_class_code
135040                                                                            )
135041                                     ,p_token_3                 => 'OWNER'
135042                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
135043                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
135044                                                                           ,p_lookup_code    => l_component_type_code
135045                                                                          )
135046                                     ,p_token_4                 => 'PRODUCT_NAME'
135047                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
135048                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
135049                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
135050                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
135051                                     ,p_ae_header_id            =>  NULL
135052                                        );
135053 
135054         IF (C_LEVEL_ERROR>= g_log_level) THEN
135055                  trace
135056                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
135057                       ,p_level    => C_LEVEL_ERROR
135058                       ,p_module   => l_log_module);
135059         END IF;
135060       END IF;
135061    END IF;
135062    --
135063    --
135064    ------------------------------------------------------------------------------------------------
135065    -- 4219869 Business Flow
135066    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
135067    -- Prior Entry.  Currently, the following code is always generated.
135068    ------------------------------------------------------------------------------------------------
135069    XLA_AE_LINES_PKG.ValidateCurrentLine;
135070 
135071    ------------------------------------------------------------------------------------
135072    -- 4219869 Business Flow
135073    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
135074    ------------------------------------------------------------------------------------
135075    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
135076 
135077    ----------------------------------------------------------------------------------
135078    -- 4219869 Business Flow
135079    -- Update journal entry status -- Need to generate this within IF <condition>
135080    ----------------------------------------------------------------------------------
135081    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
135082          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
135083          ,p_balance_type_code => l_balance_type_code
135084          );
135085 
135086    -------------------------------------------------------------------------------------------
135087    -- 4262811 - Generate the Accrual Reversal lines
135088    -------------------------------------------------------------------------------------------
135089    BEGIN
135090       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
135091                               (g_array_event(p_event_id).array_value_num('header_index'));
135092       IF l_acc_rev_flag IS NULL THEN
135093          l_acc_rev_flag := 'N';
135094       END IF;
135095    EXCEPTION
135096       WHEN OTHERS THEN
135097          l_acc_rev_flag := 'N';
135098    END;
135099    --
135100    IF (l_acc_rev_flag = 'Y') THEN
135101 
135102        -- 4645092  ------------------------------------------------------------------------------
135103        -- To allow MPA report to determine if it should generate report process
135104        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
135105        ------------------------------------------------------------------------------------------
135106 
135110    -- call ADRs
135107        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
135108        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
135109    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
135111    -- Bug 4922099
135112    --
135113    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
135114         (NVL(l_actual_upg_option, 'N') = 'O') OR
135115         (NVL(l_enc_upg_option, 'N') = 'O')
135116       )
135117    THEN
135118    NULL;
135119    --
135120    --
135121    
135122   l_ccid := AcctDerRule_172(
135123            p_application_id           => p_application_id
135124          , p_ae_header_id             => l_ae_header_id 
135125 , p_source_3 => p_source_3
135126 , p_source_6 => p_source_6
135127 , p_source_30 => p_source_30
135128          , x_transaction_coa_id       => l_adr_transaction_coa_id
135129          , x_accounting_coa_id        => l_adr_accounting_coa_id
135130          , x_value_type_code          => l_adr_value_type_code
135131          , p_side                     => 'NA'
135132    );
135133 
135134    xla_ae_lines_pkg.set_ccid(
135135     p_code_combination_id          => l_ccid
135136   , p_value_type_code              => l_adr_value_type_code
135137   , p_transaction_coa_id           => l_adr_transaction_coa_id
135138   , p_accounting_coa_id            => l_adr_accounting_coa_id
135139   , p_adr_code                     => 'FA_CAT_COST_CLEARING'
135140   , p_adr_type_code                => 'S'
135141   , p_component_type               => l_component_type
135142   , p_component_code               => l_component_code
135143   , p_component_type_code          => l_component_type_code
135144   , p_component_appl_id            => l_component_appl_id
135145   , p_amb_context_code             => l_amb_context_code
135146   , p_side                         => 'NA'
135147   );
135148 
135149 
135150    l_segment := AcctDerRule_147(
135151            p_application_id           => p_application_id
135152          , p_ae_header_id             => l_ae_header_id 
135153 , p_source_3 => p_source_3
135154 , p_source_6 => p_source_6
135155 , p_source_8 => p_source_8
135156          , x_transaction_coa_id       => l_adr_transaction_coa_id
135157          , x_accounting_coa_id        => l_adr_accounting_coa_id
135158          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
135159          , x_flex_value_set_id        => l_adr_flex_value_set_id
135160          , x_value_type_code          => l_adr_value_type_code
135161          , x_value_combination_id     => l_adr_value_combination_id
135162          , x_value_segment_code       => l_adr_value_segment_code
135163          , p_side                     => 'NA'
135164          , p_override_seg_flag        => 'Y'
135165    );
135166 
135167    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
135168 
135169       xla_ae_lines_pkg.set_segment(
135170           p_to_segment_code         => 'GL_ACCOUNT'
135171         , p_segment_value           => l_segment
135172         , p_from_segment_code       => l_adr_value_segment_code
135173         , p_from_combination_id     => l_adr_value_combination_id
135174         , p_value_type_code         => l_adr_value_type_code
135175         , p_transaction_coa_id      => l_adr_transaction_coa_id
135176         , p_accounting_coa_id       => l_adr_accounting_coa_id
135177         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
135178         , p_flex_value_set_id       => l_adr_flex_value_set_id
135179         , p_adr_code                => 'FA_CAT_CLR_ACCOUNT_SEGMENT'
135180         , p_adr_type_code           => 'S'
135181         , p_component_type          => l_component_type
135182         , p_component_code          => l_component_code
135183         , p_component_type_code     => l_component_type_code
135184         , p_component_appl_id       => l_component_appl_id
135185         , p_amb_context_code        => l_amb_context_code
135186         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
135187         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
135188         , p_side                    => 'NA'
135189         );
135190 
135191   END IF;
135192 
135193    l_segment := AcctDerRule_169(
135194            p_application_id           => p_application_id
135195          , p_ae_header_id             => l_ae_header_id 
135196 , p_source_3 => p_source_3
135197 , p_source_6 => p_source_6
135198 , p_source_29 => p_source_29
135199          , x_transaction_coa_id       => l_adr_transaction_coa_id
135200          , x_accounting_coa_id        => l_adr_accounting_coa_id
135201          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
135202          , x_flex_value_set_id        => l_adr_flex_value_set_id
135203          , x_value_type_code          => l_adr_value_type_code
135204          , x_value_combination_id     => l_adr_value_combination_id
135205          , x_value_segment_code       => l_adr_value_segment_code
135206          , p_side                     => 'NA'
135207          , p_override_seg_flag        => 'Y'
135208    );
135209 
135210    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
135211 
135212       xla_ae_lines_pkg.set_segment(
135213           p_to_segment_code         => 'GL_BALANCING'
135214         , p_segment_value           => l_segment
135215         , p_from_segment_code       => l_adr_value_segment_code
135216         , p_from_combination_id     => l_adr_value_combination_id
135217         , p_value_type_code         => l_adr_value_type_code
135218         , p_transaction_coa_id      => l_adr_transaction_coa_id
135219         , p_accounting_coa_id       => l_adr_accounting_coa_id
135220         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
135221         , p_flex_value_set_id       => l_adr_flex_value_set_id
135222         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
135223         , p_adr_type_code           => 'S'
135224         , p_component_type          => l_component_type
135225         , p_component_code          => l_component_code
135229         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
135226         , p_component_type_code     => l_component_type_code
135227         , p_component_appl_id       => l_component_appl_id
135228         , p_amb_context_code        => l_amb_context_code
135230         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
135231         , p_side                    => 'NA'
135232         );
135233 
135234   END IF;
135235 
135236    --
135237    --
135238    END IF;
135239 
135240        --
135241        -- Update the line information that should be overwritten
135242        --
135243        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
135244                                          p_header_num   => 1);
135245        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
135246 
135247        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
135248 
135249        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
135250           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
135251        END IF;
135252 
135253       --
135254       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
135255       --
135256       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
135257           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
135258       ELSE
135259           ---------------------------------------------------------------------------------------------------
135260           -- 4262811a Switch Sign
135261           ---------------------------------------------------------------------------------------------------
135262           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
135263           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
135264                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
135265           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
135266                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
135267           -- 5132302
135268           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
135269                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
135270 
135271       END IF;
135272 
135273       -- 4955764
135274       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
135275       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
135276 
135277 
135278       XLA_AE_LINES_PKG.ValidateCurrentLine;
135279       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
135280 
135281       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
135282                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
135283                ,p_balance_type_code => l_balance_type_code);
135284 
135285    END IF;
135286 
135287    -----------------------------------------------------------------------------------------
135288    -- 4262811 Multiperiod Accounting
135289    -----------------------------------------------------------------------------------------
135290      -- No MPA option is assigned.
135291 
135292 
135293 END IF;
135294 END IF;
135295 --
135296 
135297 --
135298 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
135299    trace
135300       (p_msg      => 'END of AcctLineType_343'
135301       ,p_level    => C_LEVEL_PROCEDURE
135302       ,p_module   => l_log_module);
135303 END IF;
135304 --
135305 EXCEPTION
135306   WHEN xla_exceptions_pkg.application_exception THEN
135307       RAISE;
135308   WHEN OTHERS THEN
135309        xla_exceptions_pkg.raise_message
135310            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_343');
135311 END AcctLineType_343;
135312 --
135313 
135314 ---------------------------------------
135315 --
135316 -- PRIVATE FUNCTION
135317 --         AcctLineType_344
135318 --
135319 ---------------------------------------
135320 PROCEDURE AcctLineType_344 (
135321   p_application_id        IN NUMBER
135322  ,p_event_id              IN NUMBER
135323  ,p_calculate_acctd_flag  IN VARCHAR2
135324  ,p_calculate_g_l_flag    IN VARCHAR2
135325  ,p_actual_flag           IN OUT VARCHAR2
135326  ,p_balance_type_code     OUT VARCHAR2
135327  ,p_gain_or_loss_ref      OUT VARCHAR2
135328  
135329 --Period Close Date
135330  , p_source_1            IN DATE
135331 --Generated Code Combination Identifier
135332  , p_source_3            IN NUMBER
135333 --Expense Account Code Combination Identifier
135334  , p_source_29            IN NUMBER
135335 --Adjustment Type
135336  , p_source_35            IN VARCHAR2
135337 --Transaction Header Identifier
135338  , p_source_36            IN NUMBER
135339 --Adjustment Line Identifier
135340  , p_source_37            IN NUMBER
135341 --Distribution Type Code
135342  , p_source_38            IN VARCHAR2
135343 --Entered Amount
135344  , p_source_39            IN NUMBER
135345 --Currency Code
135346  , p_source_40            IN VARCHAR2
135347 --Source Destination Code
135348  , p_source_42            IN VARCHAR2
135349 )
135350 IS
135351 
135352 l_component_type              VARCHAR2(80);
135353 l_component_code              VARCHAR2(30);
135354 l_component_type_code         VARCHAR2(1);
135355 l_component_appl_id           INTEGER;
135356 l_amb_context_code            VARCHAR2(30);
135357 l_entity_code                 VARCHAR2(30);
135358 l_event_class_code            VARCHAR2(30);
135359 l_ae_header_id                NUMBER;
135360 l_event_type_code             VARCHAR2(30);
135364 -- adr variables
135361 l_line_definition_code        VARCHAR2(30);
135362 l_line_definition_owner_code  VARCHAR2(1);
135363 --
135365 l_segment                     VARCHAR2(30);
135366 l_ccid                        NUMBER;
135367 l_adr_transaction_coa_id      NUMBER;
135368 l_adr_accounting_coa_id       NUMBER;
135369 l_adr_flexfield_segment_code  VARCHAR2(30);
135370 l_adr_flex_value_set_id       NUMBER;
135371 l_adr_value_type_code         VARCHAR2(30);
135372 l_adr_value_combination_id    NUMBER;
135373 l_adr_value_segment_code      VARCHAR2(30);
135374 
135375 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
135376 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
135377 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
135378 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
135379 
135380 -- 4262811 Variables ------------------------------------------------------------------------------------------
135381 l_entered_amt_idx             NUMBER;
135382 l_accted_amt_idx              NUMBER;
135383 l_acc_rev_flag                VARCHAR2(1);
135384 l_accrual_line_num            NUMBER;
135385 l_tmp_amt                     NUMBER;
135386 l_acc_rev_natural_side_code   VARCHAR2(1);
135387 
135388 l_num_entries                 NUMBER;
135389 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
135390 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
135391 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
135392 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
135393 l_recog_line_1                NUMBER;
135394 l_recog_line_2                NUMBER;
135395 
135396 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
135397 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
135398 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
135399 
135400 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
135401 
135402 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
135403 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
135404 
135405 ---------------------------------------------------------------------------------------------------------------
135406 
135407 
135408 --
135409 -- bulk performance
135410 --
135411 l_balance_type_code           VARCHAR2(1);
135412 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
135413 l_log_module                  VARCHAR2(240);
135414 
135415 --
135416 -- Upgrade strategy
135417 --
135418 l_actual_upg_option           VARCHAR2(1);
135419 l_enc_upg_option           VARCHAR2(1);
135420 
135421 --
135422 BEGIN
135423 --
135424 IF g_log_enabled THEN
135425       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_344';
135426 END IF;
135427 --
135428 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
135429 
135430       trace
135431          (p_msg      => 'BEGIN of AcctLineType_344'
135432          ,p_level    => C_LEVEL_PROCEDURE
135433          ,p_module   => l_log_module);
135434 
135435 END IF;
135436 --
135437 l_component_type             := 'AMB_JLT';
135438 l_component_code             := 'FA_SLT_DEST_DEPRN_EXP';
135439 l_component_type_code        := 'S';
135440 l_component_appl_id          :=  140;
135441 l_amb_context_code           := 'DEFAULT';
135442 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
135443 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
135444 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
135445 l_line_definition_owner_code := 'S';
135446 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
135447 --
135448 l_balance_type_code          := 'A';
135449 l_segment                     := NULL;
135450 l_ccid                        := NULL;
135451 l_adr_transaction_coa_id      := NULL;
135452 l_adr_accounting_coa_id       := NULL;
135453 l_adr_flexfield_segment_code  := NULL;
135454 l_adr_flex_value_set_id       := NULL;
135455 l_adr_value_type_code         := NULL;
135456 l_adr_value_combination_id    := NULL;
135457 l_adr_value_segment_code      := NULL;
135458 
135459 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
135460 l_bflow_class_code           := '';    -- 4219869 Business Flow
135461 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
135462 l_budgetary_control_flag     := 'N';
135463 
135464 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
135465 l_bflow_applied_to_amt       := NULL; -- 5132302
135466 l_entered_amt_idx            := NULL;          -- 4262811
135467 l_accted_amt_idx             := NULL;          -- 4262811
135468 l_acc_rev_flag               := NULL;          -- 4262811
135469 l_accrual_line_num           := NULL;          -- 4262811
135470 l_tmp_amt                    := NULL;          -- 4262811
135471 --
135472  
135473 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
135474     l_balance_type_code <> 'B' THEN
135475 IF NVL(p_source_35,'
135476 ') =  'EXPENSE' AND 
135477 NVL(p_source_42,'
135478 ') =  'DEST'
135479  THEN 
135480 
135481    --
135482    XLA_AE_LINES_PKG.SetNewLine;
135483 
135484    p_balance_type_code          := l_balance_type_code;
135485    -- set the flag so later we will know whether the gain loss line needs to be created
135486    
135487    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
135488      p_actual_flag :='A';
135489    END IF;
135490 
135491    --
135492    -- bulk performance
135493    --
135494    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
135495                                       p_header_num   => 0); -- 4262811
135496    --
135497    -- set accounting line options
135498    --
135499    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
135503          , p_acct_entry_type_code       => 'A'
135500            p_natural_side_code          => 'D'
135501          , p_gain_or_loss_flag          => 'N'
135502          , p_gl_transfer_mode_code      => 'S'
135504          , p_switch_side_flag           => 'Y'
135505          , p_merge_duplicate_code       => 'N'
135506          );
135507    --
135508    l_acc_rev_natural_side_code := 'C';  -- 4262811
135509    -- 
135510    --
135511    -- set accounting line type info
135512    --
135513    xla_ae_lines_pkg.SetAcctLineType
135514       (p_component_type             => l_component_type
135515       ,p_event_type_code            => l_event_type_code
135516       ,p_line_definition_owner_code => l_line_definition_owner_code
135517       ,p_line_definition_code       => l_line_definition_code
135518       ,p_accounting_line_code       => l_component_code
135519       ,p_accounting_line_type_code  => l_component_type_code
135520       ,p_accounting_line_appl_id    => l_component_appl_id
135521       ,p_amb_context_code           => l_amb_context_code
135522       ,p_entity_code                => l_entity_code
135523       ,p_event_class_code           => l_event_class_code);
135524    --
135525    -- set accounting class
135526    --
135527    xla_ae_lines_pkg.SetAcctClass(
135528            p_accounting_class_code  => 'EXPENSE'
135529          , p_ae_header_id           => l_ae_header_id
135530          );
135531 
135532    --
135533    -- set rounding class
135534    --
135535    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
135536                       'EXPENSE';
135537 
135538    --
135539    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
135540    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
135541    --
135542    -- bulk performance
135543    --
135544    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
135545 
135546    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
135547       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
135548 
135549    -- 4955764
135550    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
135551       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
135552 
135553    -- 4458381 Public Sector Enh
135554    
135555    --
135556    -- set accounting attributes for the line type
135557    --
135558    l_entered_amt_idx := 4;
135559    l_accted_amt_idx  := 6;
135560    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
135561    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
135562    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
135563    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
135564    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
135565    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
135566    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
135567    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
135568    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
135569    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
135570    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
135571    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
135572    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
135573 
135574    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
135575    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
135576 
135577    ---------------------------------------------------------------------------------------------------------------
135578    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
135579    ---------------------------------------------------------------------------------------------------------------
135580    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
135581 
135582    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
135583    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
135584 
135585    IF xla_accounting_cache_pkg.GetValueChar
135586          (p_source_code         => 'LEDGER_CATEGORY_CODE'
135587          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
135588    AND l_bflow_method_code = 'PRIOR_ENTRY'
135589 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
135590    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
135591          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
135592        )
135593    THEN
135594          xla_ae_lines_pkg.BflowUpgEntry
135595            (p_business_method_code    => l_bflow_method_code
135596            ,p_business_class_code     => l_bflow_class_code
135597            ,p_balance_type            => l_balance_type_code);
135598    ELSE
135599       NULL;
135600 -- No business flow processing for business flow method of NONE.
135601    END IF;
135602 
135603    --
135604    -- call analytical criteria
135605    --
135606    
135607    --
135608    -- call description
135609    --
135610    
135611 xla_ae_lines_pkg.SetLineDescription(
135612    p_ae_header_id => l_ae_header_id
135613   ,p_description  => Description_112 (
135614      p_application_id         => p_application_id
135615    , p_ae_header_id           => l_ae_header_id 
135616 , p_source_1 => p_source_1
135617    )
135618 );
135619 
135620 
135621    --
135622    -- call ADRs
135623    -- Bug 4922099
135624    --
135625    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
135626         (NVL(l_actual_upg_option, 'N') = 'O') OR
135630    NULL;
135627         (NVL(l_enc_upg_option, 'N') = 'O')
135628       )
135629    THEN
135631    --
135632    --
135633    
135634   l_ccid := AcctDerRule_175(
135635            p_application_id           => p_application_id
135636          , p_ae_header_id             => l_ae_header_id 
135637 , p_source_3 => p_source_3
135638 , p_source_29 => p_source_29
135639          , x_transaction_coa_id       => l_adr_transaction_coa_id
135640          , x_accounting_coa_id        => l_adr_accounting_coa_id
135641          , x_value_type_code          => l_adr_value_type_code
135642          , p_side                     => 'NA'
135643    );
135644 
135645    xla_ae_lines_pkg.set_ccid(
135646     p_code_combination_id          => l_ccid
135647   , p_value_type_code              => l_adr_value_type_code
135648   , p_transaction_coa_id           => l_adr_transaction_coa_id
135649   , p_accounting_coa_id            => l_adr_accounting_coa_id
135650   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
135651   , p_adr_type_code                => 'S'
135652   , p_component_type               => l_component_type
135653   , p_component_code               => l_component_code
135654   , p_component_type_code          => l_component_type_code
135655   , p_component_appl_id            => l_component_appl_id
135656   , p_amb_context_code             => l_amb_context_code
135657   , p_side                         => 'NA'
135658   );
135659 
135660 
135661    --
135662    --
135663    END IF;
135664    --
135665    -- Bug 4922099
135666    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
135667           (NVL(l_enc_upg_option, 'N') = 'O')
135668         ) AND
135669         (l_bflow_method_code = 'PRIOR_ENTRY')
135670       )
135671    THEN
135672       IF
135673       --
135674       1 = 2
135675       --
135676       THEN
135677       xla_accounting_err_pkg.build_message
135678                                     (p_appli_s_name            => 'XLA'
135679                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
135680                                     ,p_token_1                 => 'LINE_NUMBER'
135681                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
135682                                     ,p_token_2                 => 'LINE_TYPE_NAME'
135683                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
135684                                                                              l_component_type
135685                                                                             ,l_component_code
135686                                                                             ,l_component_type_code
135687                                                                             ,l_component_appl_id
135688                                                                             ,l_amb_context_code
135689                                                                             ,l_entity_code
135690                                                                             ,l_event_class_code
135691                                                                            )
135692                                     ,p_token_3                 => 'OWNER'
135693                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
135694                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
135695                                                                           ,p_lookup_code    => l_component_type_code
135696                                                                          )
135697                                     ,p_token_4                 => 'PRODUCT_NAME'
135698                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
135699                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
135700                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
135701                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
135702                                     ,p_ae_header_id            =>  NULL
135703                                        );
135704 
135705         IF (C_LEVEL_ERROR>= g_log_level) THEN
135706                  trace
135707                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
135708                       ,p_level    => C_LEVEL_ERROR
135709                       ,p_module   => l_log_module);
135710         END IF;
135711       END IF;
135712    END IF;
135713    --
135714    --
135715    ------------------------------------------------------------------------------------------------
135716    -- 4219869 Business Flow
135717    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
135718    -- Prior Entry.  Currently, the following code is always generated.
135719    ------------------------------------------------------------------------------------------------
135720    XLA_AE_LINES_PKG.ValidateCurrentLine;
135721 
135722    ------------------------------------------------------------------------------------
135723    -- 4219869 Business Flow
135724    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
135725    ------------------------------------------------------------------------------------
135726    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
135727 
135728    ----------------------------------------------------------------------------------
135729    -- 4219869 Business Flow
135730    -- Update journal entry status -- Need to generate this within IF <condition>
135731    ----------------------------------------------------------------------------------
135732    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
135733          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
135734          ,p_balance_type_code => l_balance_type_code
135735          );
135736 
135740    BEGIN
135737    -------------------------------------------------------------------------------------------
135738    -- 4262811 - Generate the Accrual Reversal lines
135739    -------------------------------------------------------------------------------------------
135741       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
135742                               (g_array_event(p_event_id).array_value_num('header_index'));
135743       IF l_acc_rev_flag IS NULL THEN
135744          l_acc_rev_flag := 'N';
135745       END IF;
135746    EXCEPTION
135747       WHEN OTHERS THEN
135748          l_acc_rev_flag := 'N';
135749    END;
135750    --
135751    IF (l_acc_rev_flag = 'Y') THEN
135752 
135753        -- 4645092  ------------------------------------------------------------------------------
135754        -- To allow MPA report to determine if it should generate report process
135755        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
135756        ------------------------------------------------------------------------------------------
135757 
135758        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
135759        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
135760    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
135761    -- call ADRs
135762    -- Bug 4922099
135763    --
135764    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
135765         (NVL(l_actual_upg_option, 'N') = 'O') OR
135766         (NVL(l_enc_upg_option, 'N') = 'O')
135767       )
135768    THEN
135769    NULL;
135770    --
135771    --
135772    
135773   l_ccid := AcctDerRule_175(
135774            p_application_id           => p_application_id
135775          , p_ae_header_id             => l_ae_header_id 
135776 , p_source_3 => p_source_3
135777 , p_source_29 => p_source_29
135778          , x_transaction_coa_id       => l_adr_transaction_coa_id
135779          , x_accounting_coa_id        => l_adr_accounting_coa_id
135780          , x_value_type_code          => l_adr_value_type_code
135781          , p_side                     => 'NA'
135782    );
135783 
135784    xla_ae_lines_pkg.set_ccid(
135785     p_code_combination_id          => l_ccid
135786   , p_value_type_code              => l_adr_value_type_code
135787   , p_transaction_coa_id           => l_adr_transaction_coa_id
135788   , p_accounting_coa_id            => l_adr_accounting_coa_id
135789   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
135790   , p_adr_type_code                => 'S'
135791   , p_component_type               => l_component_type
135792   , p_component_code               => l_component_code
135793   , p_component_type_code          => l_component_type_code
135794   , p_component_appl_id            => l_component_appl_id
135795   , p_amb_context_code             => l_amb_context_code
135796   , p_side                         => 'NA'
135797   );
135798 
135799 
135800    --
135801    --
135802    END IF;
135803 
135804        --
135805        -- Update the line information that should be overwritten
135806        --
135807        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
135808                                          p_header_num   => 1);
135809        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
135810 
135811        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
135812 
135813        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
135814           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
135815        END IF;
135816 
135817       --
135818       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
135819       --
135820       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
135821           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
135822       ELSE
135823           ---------------------------------------------------------------------------------------------------
135824           -- 4262811a Switch Sign
135825           ---------------------------------------------------------------------------------------------------
135826           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
135827           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
135828                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
135829           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
135830                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
135831           -- 5132302
135832           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
135833                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
135834 
135835       END IF;
135836 
135837       -- 4955764
135838       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
135839       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
135840 
135841 
135842       XLA_AE_LINES_PKG.ValidateCurrentLine;
135843       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
135844 
135845       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
135846                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
135847                ,p_balance_type_code => l_balance_type_code);
135848 
135849    END IF;
135850 
135851    -----------------------------------------------------------------------------------------
135852    -- 4262811 Multiperiod Accounting
135853    -----------------------------------------------------------------------------------------
135854      -- No MPA option is assigned.
135855 
135859 --
135856 
135857 END IF;
135858 END IF;
135860 
135861 --
135862 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
135863    trace
135864       (p_msg      => 'END of AcctLineType_344'
135865       ,p_level    => C_LEVEL_PROCEDURE
135866       ,p_module   => l_log_module);
135867 END IF;
135868 --
135869 EXCEPTION
135870   WHEN xla_exceptions_pkg.application_exception THEN
135871       RAISE;
135872   WHEN OTHERS THEN
135873        xla_exceptions_pkg.raise_message
135874            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_344');
135875 END AcctLineType_344;
135876 --
135877 
135878 ---------------------------------------
135879 --
135880 -- PRIVATE FUNCTION
135881 --         AcctLineType_345
135882 --
135883 ---------------------------------------
135884 PROCEDURE AcctLineType_345 (
135885   p_application_id        IN NUMBER
135886  ,p_event_id              IN NUMBER
135887  ,p_calculate_acctd_flag  IN VARCHAR2
135888  ,p_calculate_g_l_flag    IN VARCHAR2
135889  ,p_actual_flag           IN OUT VARCHAR2
135890  ,p_balance_type_code     OUT VARCHAR2
135891  ,p_gain_or_loss_ref      OUT VARCHAR2
135892  
135893 --Period Close Date
135894  , p_source_1            IN DATE
135895 --Generated Code Combination Identifier
135896  , p_source_3            IN NUMBER
135897 --Depreciation Reserve Account
135898  , p_source_10            IN VARCHAR2
135899 --Generated Offset Code Combination Identifier
135900  , p_source_17            IN NUMBER
135901 --Expense Account Code Combination Identifier
135902  , p_source_29            IN NUMBER
135903 --Default Code Combination Identifier
135904  , p_source_30            IN NUMBER
135905 --Adjustment Type
135906  , p_source_35            IN VARCHAR2
135907 --Transaction Header Identifier
135908  , p_source_36            IN NUMBER
135909 --Adjustment Line Identifier
135910  , p_source_37            IN NUMBER
135911 --Distribution Type Code
135912  , p_source_38            IN VARCHAR2
135913 --Entered Amount
135914  , p_source_39            IN NUMBER
135915 --Currency Code
135916  , p_source_40            IN VARCHAR2
135917 --Source Destination Code
135918  , p_source_42            IN VARCHAR2
135919 )
135920 IS
135921 
135922 l_component_type              VARCHAR2(80);
135923 l_component_code              VARCHAR2(30);
135924 l_component_type_code         VARCHAR2(1);
135925 l_component_appl_id           INTEGER;
135926 l_amb_context_code            VARCHAR2(30);
135927 l_entity_code                 VARCHAR2(30);
135928 l_event_class_code            VARCHAR2(30);
135929 l_ae_header_id                NUMBER;
135930 l_event_type_code             VARCHAR2(30);
135931 l_line_definition_code        VARCHAR2(30);
135932 l_line_definition_owner_code  VARCHAR2(1);
135933 --
135934 -- adr variables
135935 l_segment                     VARCHAR2(30);
135936 l_ccid                        NUMBER;
135937 l_adr_transaction_coa_id      NUMBER;
135938 l_adr_accounting_coa_id       NUMBER;
135939 l_adr_flexfield_segment_code  VARCHAR2(30);
135940 l_adr_flex_value_set_id       NUMBER;
135941 l_adr_value_type_code         VARCHAR2(30);
135942 l_adr_value_combination_id    NUMBER;
135943 l_adr_value_segment_code      VARCHAR2(30);
135944 
135945 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
135946 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
135947 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
135948 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
135949 
135950 -- 4262811 Variables ------------------------------------------------------------------------------------------
135951 l_entered_amt_idx             NUMBER;
135952 l_accted_amt_idx              NUMBER;
135953 l_acc_rev_flag                VARCHAR2(1);
135954 l_accrual_line_num            NUMBER;
135955 l_tmp_amt                     NUMBER;
135956 l_acc_rev_natural_side_code   VARCHAR2(1);
135957 
135958 l_num_entries                 NUMBER;
135959 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
135960 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
135961 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
135962 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
135963 l_recog_line_1                NUMBER;
135964 l_recog_line_2                NUMBER;
135965 
135966 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
135967 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
135968 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
135969 
135970 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
135971 
135972 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
135973 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
135974 
135975 ---------------------------------------------------------------------------------------------------------------
135976 
135977 
135978 --
135979 -- bulk performance
135980 --
135981 l_balance_type_code           VARCHAR2(1);
135982 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
135983 l_log_module                  VARCHAR2(240);
135984 
135985 --
135986 -- Upgrade strategy
135987 --
135988 l_actual_upg_option           VARCHAR2(1);
135989 l_enc_upg_option           VARCHAR2(1);
135990 
135991 --
135992 BEGIN
135993 --
135994 IF g_log_enabled THEN
135995       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_345';
135996 END IF;
135997 --
135998 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
135999 
136000       trace
136001          (p_msg      => 'BEGIN of AcctLineType_345'
136002          ,p_level    => C_LEVEL_PROCEDURE
136003          ,p_module   => l_log_module);
136004 
136005 END IF;
136006 --
136010 l_component_appl_id          :=  140;
136007 l_component_type             := 'AMB_JLT';
136008 l_component_code             := 'FA_SLT_DEST_DEPRN_RESERVE';
136009 l_component_type_code        := 'S';
136011 l_amb_context_code           := 'DEFAULT';
136012 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
136013 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
136014 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
136015 l_line_definition_owner_code := 'S';
136016 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
136017 --
136018 l_balance_type_code          := 'A';
136019 l_segment                     := NULL;
136020 l_ccid                        := NULL;
136021 l_adr_transaction_coa_id      := NULL;
136022 l_adr_accounting_coa_id       := NULL;
136023 l_adr_flexfield_segment_code  := NULL;
136024 l_adr_flex_value_set_id       := NULL;
136025 l_adr_value_type_code         := NULL;
136026 l_adr_value_combination_id    := NULL;
136027 l_adr_value_segment_code      := NULL;
136028 
136029 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
136030 l_bflow_class_code           := '';    -- 4219869 Business Flow
136031 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
136032 l_budgetary_control_flag     := 'N';
136033 
136034 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
136035 l_bflow_applied_to_amt       := NULL; -- 5132302
136036 l_entered_amt_idx            := NULL;          -- 4262811
136037 l_accted_amt_idx             := NULL;          -- 4262811
136038 l_acc_rev_flag               := NULL;          -- 4262811
136039 l_accrual_line_num           := NULL;          -- 4262811
136040 l_tmp_amt                    := NULL;          -- 4262811
136041 --
136042  
136043 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
136044     l_balance_type_code <> 'B' THEN
136045 IF (NVL(p_source_35,'
136046 ') =  'EXPENSE' OR 
136047 NVL(p_source_35,'
136048 ') =  'RESERVE') AND 
136049 NVL(p_source_42,'
136050 ') =  'DEST'
136051  THEN 
136052 
136053    --
136054    XLA_AE_LINES_PKG.SetNewLine;
136055 
136056    p_balance_type_code          := l_balance_type_code;
136057    -- set the flag so later we will know whether the gain loss line needs to be created
136058    
136059    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
136060      p_actual_flag :='A';
136061    END IF;
136062 
136063    --
136064    -- bulk performance
136065    --
136066    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
136067                                       p_header_num   => 0); -- 4262811
136068    --
136069    -- set accounting line options
136070    --
136071    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
136072            p_natural_side_code          => 'C'
136073          , p_gain_or_loss_flag          => 'N'
136074          , p_gl_transfer_mode_code      => 'S'
136075          , p_acct_entry_type_code       => 'A'
136076          , p_switch_side_flag           => 'Y'
136077          , p_merge_duplicate_code       => 'N'
136078          );
136079    --
136080    l_acc_rev_natural_side_code := 'D';  -- 4262811
136081    -- 
136082    --
136083    -- set accounting line type info
136084    --
136085    xla_ae_lines_pkg.SetAcctLineType
136086       (p_component_type             => l_component_type
136087       ,p_event_type_code            => l_event_type_code
136088       ,p_line_definition_owner_code => l_line_definition_owner_code
136089       ,p_line_definition_code       => l_line_definition_code
136090       ,p_accounting_line_code       => l_component_code
136091       ,p_accounting_line_type_code  => l_component_type_code
136092       ,p_accounting_line_appl_id    => l_component_appl_id
136093       ,p_amb_context_code           => l_amb_context_code
136094       ,p_entity_code                => l_entity_code
136095       ,p_event_class_code           => l_event_class_code);
136096    --
136097    -- set accounting class
136098    --
136099    xla_ae_lines_pkg.SetAcctClass(
136100            p_accounting_class_code  => 'ASSET'
136101          , p_ae_header_id           => l_ae_header_id
136102          );
136103 
136104    --
136105    -- set rounding class
136106    --
136107    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
136108                       'ASSET';
136109 
136110    --
136111    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
136112    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
136113    --
136114    -- bulk performance
136115    --
136116    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
136117 
136118    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
136119       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
136120 
136121    -- 4955764
136122    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
136123       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
136124 
136125    -- 4458381 Public Sector Enh
136126    
136127    --
136128    -- set accounting attributes for the line type
136129    --
136130    l_entered_amt_idx := 4;
136131    l_accted_amt_idx  := 6;
136132    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
136133    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
136134    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
136135    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
136136    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
136137    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
136138    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
136139    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
136143    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
136140    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
136141    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
136142    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
136144    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
136145 
136146    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
136147    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
136148 
136149    ---------------------------------------------------------------------------------------------------------------
136150    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
136151    ---------------------------------------------------------------------------------------------------------------
136152    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
136153 
136154    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
136155    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
136156 
136157    IF xla_accounting_cache_pkg.GetValueChar
136158          (p_source_code         => 'LEDGER_CATEGORY_CODE'
136159          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
136160    AND l_bflow_method_code = 'PRIOR_ENTRY'
136161 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
136162    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
136163          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
136164        )
136165    THEN
136166          xla_ae_lines_pkg.BflowUpgEntry
136167            (p_business_method_code    => l_bflow_method_code
136168            ,p_business_class_code     => l_bflow_class_code
136169            ,p_balance_type            => l_balance_type_code);
136170    ELSE
136171       NULL;
136172 -- No business flow processing for business flow method of NONE.
136173    END IF;
136174 
136175    --
136176    -- call analytical criteria
136177    --
136178    
136179    --
136180    -- call description
136181    --
136182    
136183 xla_ae_lines_pkg.SetLineDescription(
136184    p_ae_header_id => l_ae_header_id
136185   ,p_description  => Description_113 (
136186      p_application_id         => p_application_id
136187    , p_ae_header_id           => l_ae_header_id 
136188 , p_source_1 => p_source_1
136189    )
136190 );
136191 
136192 
136193    --
136194    -- call ADRs
136195    -- Bug 4922099
136196    --
136197    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
136198         (NVL(l_actual_upg_option, 'N') = 'O') OR
136199         (NVL(l_enc_upg_option, 'N') = 'O')
136200       )
136201    THEN
136202    NULL;
136203    --
136204    --
136205    
136206   l_ccid := AcctDerRule_174(
136207            p_application_id           => p_application_id
136208          , p_ae_header_id             => l_ae_header_id 
136209 , p_source_3 => p_source_3
136210 , p_source_17 => p_source_17
136211 , p_source_30 => p_source_30
136212          , x_transaction_coa_id       => l_adr_transaction_coa_id
136213          , x_accounting_coa_id        => l_adr_accounting_coa_id
136214          , x_value_type_code          => l_adr_value_type_code
136215          , p_side                     => 'NA'
136216    );
136217 
136218    xla_ae_lines_pkg.set_ccid(
136219     p_code_combination_id          => l_ccid
136220   , p_value_type_code              => l_adr_value_type_code
136221   , p_transaction_coa_id           => l_adr_transaction_coa_id
136222   , p_accounting_coa_id            => l_adr_accounting_coa_id
136223   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
136224   , p_adr_type_code                => 'S'
136225   , p_component_type               => l_component_type
136226   , p_component_code               => l_component_code
136227   , p_component_type_code          => l_component_type_code
136228   , p_component_appl_id            => l_component_appl_id
136229   , p_amb_context_code             => l_amb_context_code
136230   , p_side                         => 'NA'
136231   );
136232 
136233 
136234    l_segment := AcctDerRule_149(
136235            p_application_id           => p_application_id
136236          , p_ae_header_id             => l_ae_header_id 
136237 , p_source_3 => p_source_3
136238 , p_source_10 => p_source_10
136239          , x_transaction_coa_id       => l_adr_transaction_coa_id
136240          , x_accounting_coa_id        => l_adr_accounting_coa_id
136241          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
136242          , x_flex_value_set_id        => l_adr_flex_value_set_id
136243          , x_value_type_code          => l_adr_value_type_code
136244          , x_value_combination_id     => l_adr_value_combination_id
136245          , x_value_segment_code       => l_adr_value_segment_code
136246          , p_side                     => 'NA'
136247          , p_override_seg_flag        => 'Y'
136248    );
136249 
136250    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
136251 
136252       xla_ae_lines_pkg.set_segment(
136253           p_to_segment_code         => 'GL_ACCOUNT'
136254         , p_segment_value           => l_segment
136255         , p_from_segment_code       => l_adr_value_segment_code
136256         , p_from_combination_id     => l_adr_value_combination_id
136257         , p_value_type_code         => l_adr_value_type_code
136258         , p_transaction_coa_id      => l_adr_transaction_coa_id
136259         , p_accounting_coa_id       => l_adr_accounting_coa_id
136260         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
136261         , p_flex_value_set_id       => l_adr_flex_value_set_id
136262         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
136263         , p_adr_type_code           => 'S'
136264         , p_component_type          => l_component_type
136268         , p_amb_context_code        => l_amb_context_code
136265         , p_component_code          => l_component_code
136266         , p_component_type_code     => l_component_type_code
136267         , p_component_appl_id       => l_component_appl_id
136269         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
136270         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
136271         , p_side                    => 'NA'
136272         );
136273 
136274   END IF;
136275 
136276    l_segment := AcctDerRule_168(
136277            p_application_id           => p_application_id
136278          , p_ae_header_id             => l_ae_header_id 
136279 , p_source_3 => p_source_3
136280 , p_source_29 => p_source_29
136281          , x_transaction_coa_id       => l_adr_transaction_coa_id
136282          , x_accounting_coa_id        => l_adr_accounting_coa_id
136283          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
136284          , x_flex_value_set_id        => l_adr_flex_value_set_id
136285          , x_value_type_code          => l_adr_value_type_code
136286          , x_value_combination_id     => l_adr_value_combination_id
136287          , x_value_segment_code       => l_adr_value_segment_code
136288          , p_side                     => 'NA'
136289          , p_override_seg_flag        => 'Y'
136290    );
136291 
136292    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
136293 
136294       xla_ae_lines_pkg.set_segment(
136295           p_to_segment_code         => 'GL_BALANCING'
136296         , p_segment_value           => l_segment
136297         , p_from_segment_code       => l_adr_value_segment_code
136298         , p_from_combination_id     => l_adr_value_combination_id
136299         , p_value_type_code         => l_adr_value_type_code
136300         , p_transaction_coa_id      => l_adr_transaction_coa_id
136301         , p_accounting_coa_id       => l_adr_accounting_coa_id
136302         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
136303         , p_flex_value_set_id       => l_adr_flex_value_set_id
136304         , p_adr_code                => 'FA_EXPENSE_ACCT'
136305         , p_adr_type_code           => 'S'
136306         , p_component_type          => l_component_type
136307         , p_component_code          => l_component_code
136308         , p_component_type_code     => l_component_type_code
136309         , p_component_appl_id       => l_component_appl_id
136310         , p_amb_context_code        => l_amb_context_code
136311         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
136312         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
136313         , p_side                    => 'NA'
136314         );
136315 
136316   END IF;
136317 
136318    --
136319    --
136320    END IF;
136321    --
136322    -- Bug 4922099
136323    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
136324           (NVL(l_enc_upg_option, 'N') = 'O')
136325         ) AND
136326         (l_bflow_method_code = 'PRIOR_ENTRY')
136327       )
136328    THEN
136329       IF
136330       --
136331       1 = 2
136332       --
136333       THEN
136334       xla_accounting_err_pkg.build_message
136335                                     (p_appli_s_name            => 'XLA'
136336                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
136337                                     ,p_token_1                 => 'LINE_NUMBER'
136338                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
136339                                     ,p_token_2                 => 'LINE_TYPE_NAME'
136340                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
136341                                                                              l_component_type
136342                                                                             ,l_component_code
136343                                                                             ,l_component_type_code
136344                                                                             ,l_component_appl_id
136345                                                                             ,l_amb_context_code
136346                                                                             ,l_entity_code
136347                                                                             ,l_event_class_code
136348                                                                            )
136349                                     ,p_token_3                 => 'OWNER'
136350                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
136351                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
136352                                                                           ,p_lookup_code    => l_component_type_code
136353                                                                          )
136354                                     ,p_token_4                 => 'PRODUCT_NAME'
136355                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
136356                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
136357                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
136358                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
136359                                     ,p_ae_header_id            =>  NULL
136360                                        );
136361 
136362         IF (C_LEVEL_ERROR>= g_log_level) THEN
136363                  trace
136364                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
136365                       ,p_level    => C_LEVEL_ERROR
136366                       ,p_module   => l_log_module);
136367         END IF;
136368       END IF;
136369    END IF;
136370    --
136371    --
136375    -- Prior Entry.  Currently, the following code is always generated.
136372    ------------------------------------------------------------------------------------------------
136373    -- 4219869 Business Flow
136374    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
136376    ------------------------------------------------------------------------------------------------
136377    XLA_AE_LINES_PKG.ValidateCurrentLine;
136378 
136379    ------------------------------------------------------------------------------------
136380    -- 4219869 Business Flow
136381    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
136382    ------------------------------------------------------------------------------------
136383    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
136384 
136385    ----------------------------------------------------------------------------------
136386    -- 4219869 Business Flow
136387    -- Update journal entry status -- Need to generate this within IF <condition>
136388    ----------------------------------------------------------------------------------
136389    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
136390          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
136391          ,p_balance_type_code => l_balance_type_code
136392          );
136393 
136394    -------------------------------------------------------------------------------------------
136395    -- 4262811 - Generate the Accrual Reversal lines
136396    -------------------------------------------------------------------------------------------
136397    BEGIN
136398       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
136399                               (g_array_event(p_event_id).array_value_num('header_index'));
136400       IF l_acc_rev_flag IS NULL THEN
136401          l_acc_rev_flag := 'N';
136402       END IF;
136403    EXCEPTION
136404       WHEN OTHERS THEN
136405          l_acc_rev_flag := 'N';
136406    END;
136407    --
136408    IF (l_acc_rev_flag = 'Y') THEN
136409 
136410        -- 4645092  ------------------------------------------------------------------------------
136411        -- To allow MPA report to determine if it should generate report process
136412        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
136413        ------------------------------------------------------------------------------------------
136414 
136415        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
136416        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
136417    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
136418    -- call ADRs
136419    -- Bug 4922099
136420    --
136421    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
136422         (NVL(l_actual_upg_option, 'N') = 'O') OR
136423         (NVL(l_enc_upg_option, 'N') = 'O')
136424       )
136425    THEN
136426    NULL;
136427    --
136428    --
136429    
136430   l_ccid := AcctDerRule_174(
136431            p_application_id           => p_application_id
136432          , p_ae_header_id             => l_ae_header_id 
136433 , p_source_3 => p_source_3
136434 , p_source_17 => p_source_17
136435 , p_source_30 => p_source_30
136436          , x_transaction_coa_id       => l_adr_transaction_coa_id
136437          , x_accounting_coa_id        => l_adr_accounting_coa_id
136438          , x_value_type_code          => l_adr_value_type_code
136439          , p_side                     => 'NA'
136440    );
136441 
136442    xla_ae_lines_pkg.set_ccid(
136443     p_code_combination_id          => l_ccid
136444   , p_value_type_code              => l_adr_value_type_code
136445   , p_transaction_coa_id           => l_adr_transaction_coa_id
136446   , p_accounting_coa_id            => l_adr_accounting_coa_id
136447   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
136448   , p_adr_type_code                => 'S'
136449   , p_component_type               => l_component_type
136450   , p_component_code               => l_component_code
136451   , p_component_type_code          => l_component_type_code
136452   , p_component_appl_id            => l_component_appl_id
136453   , p_amb_context_code             => l_amb_context_code
136454   , p_side                         => 'NA'
136455   );
136456 
136457 
136458    l_segment := AcctDerRule_149(
136459            p_application_id           => p_application_id
136460          , p_ae_header_id             => l_ae_header_id 
136461 , p_source_3 => p_source_3
136462 , p_source_10 => p_source_10
136463          , x_transaction_coa_id       => l_adr_transaction_coa_id
136464          , x_accounting_coa_id        => l_adr_accounting_coa_id
136465          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
136466          , x_flex_value_set_id        => l_adr_flex_value_set_id
136467          , x_value_type_code          => l_adr_value_type_code
136468          , x_value_combination_id     => l_adr_value_combination_id
136469          , x_value_segment_code       => l_adr_value_segment_code
136470          , p_side                     => 'NA'
136471          , p_override_seg_flag        => 'Y'
136472    );
136473 
136474    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
136475 
136476       xla_ae_lines_pkg.set_segment(
136477           p_to_segment_code         => 'GL_ACCOUNT'
136478         , p_segment_value           => l_segment
136479         , p_from_segment_code       => l_adr_value_segment_code
136480         , p_from_combination_id     => l_adr_value_combination_id
136481         , p_value_type_code         => l_adr_value_type_code
136482         , p_transaction_coa_id      => l_adr_transaction_coa_id
136483         , p_accounting_coa_id       => l_adr_accounting_coa_id
136484         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
136485         , p_flex_value_set_id       => l_adr_flex_value_set_id
136486         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
136487         , p_adr_type_code           => 'S'
136491         , p_component_appl_id       => l_component_appl_id
136488         , p_component_type          => l_component_type
136489         , p_component_code          => l_component_code
136490         , p_component_type_code     => l_component_type_code
136492         , p_amb_context_code        => l_amb_context_code
136493         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
136494         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
136495         , p_side                    => 'NA'
136496         );
136497 
136498   END IF;
136499 
136500    l_segment := AcctDerRule_168(
136501            p_application_id           => p_application_id
136502          , p_ae_header_id             => l_ae_header_id 
136503 , p_source_3 => p_source_3
136504 , p_source_29 => p_source_29
136505          , x_transaction_coa_id       => l_adr_transaction_coa_id
136506          , x_accounting_coa_id        => l_adr_accounting_coa_id
136507          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
136508          , x_flex_value_set_id        => l_adr_flex_value_set_id
136509          , x_value_type_code          => l_adr_value_type_code
136510          , x_value_combination_id     => l_adr_value_combination_id
136511          , x_value_segment_code       => l_adr_value_segment_code
136512          , p_side                     => 'NA'
136513          , p_override_seg_flag        => 'Y'
136514    );
136515 
136516    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
136517 
136518       xla_ae_lines_pkg.set_segment(
136519           p_to_segment_code         => 'GL_BALANCING'
136520         , p_segment_value           => l_segment
136521         , p_from_segment_code       => l_adr_value_segment_code
136522         , p_from_combination_id     => l_adr_value_combination_id
136523         , p_value_type_code         => l_adr_value_type_code
136524         , p_transaction_coa_id      => l_adr_transaction_coa_id
136525         , p_accounting_coa_id       => l_adr_accounting_coa_id
136526         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
136527         , p_flex_value_set_id       => l_adr_flex_value_set_id
136528         , p_adr_code                => 'FA_EXPENSE_ACCT'
136529         , p_adr_type_code           => 'S'
136530         , p_component_type          => l_component_type
136531         , p_component_code          => l_component_code
136532         , p_component_type_code     => l_component_type_code
136533         , p_component_appl_id       => l_component_appl_id
136534         , p_amb_context_code        => l_amb_context_code
136535         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
136536         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
136537         , p_side                    => 'NA'
136538         );
136539 
136540   END IF;
136541 
136542    --
136543    --
136544    END IF;
136545 
136546        --
136547        -- Update the line information that should be overwritten
136548        --
136549        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
136550                                          p_header_num   => 1);
136551        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
136552 
136553        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
136554 
136555        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
136556           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
136557        END IF;
136558 
136559       --
136560       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
136561       --
136562       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
136563           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
136564       ELSE
136565           ---------------------------------------------------------------------------------------------------
136566           -- 4262811a Switch Sign
136567           ---------------------------------------------------------------------------------------------------
136568           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
136569           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
136570                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
136571           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
136572                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
136573           -- 5132302
136574           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
136575                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
136576 
136577       END IF;
136578 
136579       -- 4955764
136580       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
136581       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
136582 
136583 
136584       XLA_AE_LINES_PKG.ValidateCurrentLine;
136585       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
136586 
136587       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
136588                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
136589                ,p_balance_type_code => l_balance_type_code);
136590 
136591    END IF;
136592 
136593    -----------------------------------------------------------------------------------------
136594    -- 4262811 Multiperiod Accounting
136595    -----------------------------------------------------------------------------------------
136596      -- No MPA option is assigned.
136597 
136598 
136599 END IF;
136600 END IF;
136601 --
136602 
136603 --
136604 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
136605    trace
136609 END IF;
136606       (p_msg      => 'END of AcctLineType_345'
136607       ,p_level    => C_LEVEL_PROCEDURE
136608       ,p_module   => l_log_module);
136610 --
136611 EXCEPTION
136612   WHEN xla_exceptions_pkg.application_exception THEN
136613       RAISE;
136614   WHEN OTHERS THEN
136615        xla_exceptions_pkg.raise_message
136616            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_345');
136617 END AcctLineType_345;
136618 --
136619 
136620 ---------------------------------------
136621 --
136622 -- PRIVATE FUNCTION
136623 --         AcctLineType_346
136624 --
136625 ---------------------------------------
136626 PROCEDURE AcctLineType_346 (
136627   p_application_id        IN NUMBER
136628  ,p_event_id              IN NUMBER
136629  ,p_calculate_acctd_flag  IN VARCHAR2
136630  ,p_calculate_g_l_flag    IN VARCHAR2
136631  ,p_actual_flag           IN OUT VARCHAR2
136632  ,p_balance_type_code     OUT VARCHAR2
136633  ,p_gain_or_loss_ref      OUT VARCHAR2
136634  
136635 --Period Close Date
136636  , p_source_1            IN DATE
136637 --Generated Code Combination Identifier
136638  , p_source_3            IN NUMBER
136639 --Expense Account Code Combination Identifier
136640  , p_source_29            IN NUMBER
136641 --Adjustment Type
136642  , p_source_35            IN VARCHAR2
136643 --Transaction Header Identifier
136644  , p_source_36            IN NUMBER
136645 --Adjustment Line Identifier
136646  , p_source_37            IN NUMBER
136647 --Distribution Type Code
136648  , p_source_38            IN VARCHAR2
136649 --Entered Amount
136650  , p_source_39            IN NUMBER
136651 --Currency Code
136652  , p_source_40            IN VARCHAR2
136653 --Source Destination Code
136654  , p_source_42            IN VARCHAR2
136655 )
136656 IS
136657 
136658 l_component_type              VARCHAR2(80);
136659 l_component_code              VARCHAR2(30);
136660 l_component_type_code         VARCHAR2(1);
136661 l_component_appl_id           INTEGER;
136662 l_amb_context_code            VARCHAR2(30);
136663 l_entity_code                 VARCHAR2(30);
136664 l_event_class_code            VARCHAR2(30);
136665 l_ae_header_id                NUMBER;
136666 l_event_type_code             VARCHAR2(30);
136667 l_line_definition_code        VARCHAR2(30);
136668 l_line_definition_owner_code  VARCHAR2(1);
136669 --
136670 -- adr variables
136671 l_segment                     VARCHAR2(30);
136672 l_ccid                        NUMBER;
136673 l_adr_transaction_coa_id      NUMBER;
136674 l_adr_accounting_coa_id       NUMBER;
136675 l_adr_flexfield_segment_code  VARCHAR2(30);
136676 l_adr_flex_value_set_id       NUMBER;
136677 l_adr_value_type_code         VARCHAR2(30);
136678 l_adr_value_combination_id    NUMBER;
136679 l_adr_value_segment_code      VARCHAR2(30);
136680 
136681 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
136682 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
136683 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
136684 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
136685 
136686 -- 4262811 Variables ------------------------------------------------------------------------------------------
136687 l_entered_amt_idx             NUMBER;
136688 l_accted_amt_idx              NUMBER;
136689 l_acc_rev_flag                VARCHAR2(1);
136690 l_accrual_line_num            NUMBER;
136691 l_tmp_amt                     NUMBER;
136692 l_acc_rev_natural_side_code   VARCHAR2(1);
136693 
136694 l_num_entries                 NUMBER;
136695 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
136696 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
136697 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
136698 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
136699 l_recog_line_1                NUMBER;
136700 l_recog_line_2                NUMBER;
136701 
136702 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
136703 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
136704 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
136705 
136706 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
136707 
136708 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
136709 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
136710 
136711 ---------------------------------------------------------------------------------------------------------------
136712 
136713 
136714 --
136715 -- bulk performance
136716 --
136717 l_balance_type_code           VARCHAR2(1);
136718 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
136719 l_log_module                  VARCHAR2(240);
136720 
136721 --
136722 -- Upgrade strategy
136723 --
136724 l_actual_upg_option           VARCHAR2(1);
136725 l_enc_upg_option           VARCHAR2(1);
136726 
136727 --
136728 BEGIN
136729 --
136730 IF g_log_enabled THEN
136731       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_346';
136732 END IF;
136733 --
136734 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
136735 
136736       trace
136737          (p_msg      => 'BEGIN of AcctLineType_346'
136738          ,p_level    => C_LEVEL_PROCEDURE
136739          ,p_module   => l_log_module);
136740 
136741 END IF;
136742 --
136743 l_component_type             := 'AMB_JLT';
136744 l_component_code             := 'FA_SLT_DEST_EXP_BAL';
136745 l_component_type_code        := 'S';
136746 l_component_appl_id          :=  140;
136747 l_amb_context_code           := 'DEFAULT';
136748 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
136749 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
136750 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
136754 l_balance_type_code          := 'A';
136751 l_line_definition_owner_code := 'S';
136752 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
136753 --
136755 l_segment                     := NULL;
136756 l_ccid                        := NULL;
136757 l_adr_transaction_coa_id      := NULL;
136758 l_adr_accounting_coa_id       := NULL;
136759 l_adr_flexfield_segment_code  := NULL;
136760 l_adr_flex_value_set_id       := NULL;
136761 l_adr_value_type_code         := NULL;
136762 l_adr_value_combination_id    := NULL;
136763 l_adr_value_segment_code      := NULL;
136764 
136765 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
136766 l_bflow_class_code           := '';    -- 4219869 Business Flow
136767 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
136768 l_budgetary_control_flag     := 'N';
136769 
136770 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
136771 l_bflow_applied_to_amt       := NULL; -- 5132302
136772 l_entered_amt_idx            := NULL;          -- 4262811
136773 l_accted_amt_idx             := NULL;          -- 4262811
136774 l_acc_rev_flag               := NULL;          -- 4262811
136775 l_accrual_line_num           := NULL;          -- 4262811
136776 l_tmp_amt                    := NULL;          -- 4262811
136777 --
136778  
136779 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
136780     l_balance_type_code <> 'B' THEN
136781 IF NVL(p_source_35,'
136782 ') =  'BONUS EXPENSE' AND 
136783 NVL(p_source_42,'
136784 ') =  'DEST'
136785  THEN 
136786 
136787    --
136788    XLA_AE_LINES_PKG.SetNewLine;
136789 
136790    p_balance_type_code          := l_balance_type_code;
136791    -- set the flag so later we will know whether the gain loss line needs to be created
136792    
136793    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
136794      p_actual_flag :='A';
136795    END IF;
136796 
136797    --
136798    -- bulk performance
136799    --
136800    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
136801                                       p_header_num   => 0); -- 4262811
136802    --
136803    -- set accounting line options
136804    --
136805    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
136806            p_natural_side_code          => 'C'
136807          , p_gain_or_loss_flag          => 'N'
136808          , p_gl_transfer_mode_code      => 'S'
136809          , p_acct_entry_type_code       => 'A'
136810          , p_switch_side_flag           => 'Y'
136811          , p_merge_duplicate_code       => 'N'
136812          );
136813    --
136814    l_acc_rev_natural_side_code := 'D';  -- 4262811
136815    -- 
136816    --
136817    -- set accounting line type info
136818    --
136819    xla_ae_lines_pkg.SetAcctLineType
136820       (p_component_type             => l_component_type
136821       ,p_event_type_code            => l_event_type_code
136822       ,p_line_definition_owner_code => l_line_definition_owner_code
136823       ,p_line_definition_code       => l_line_definition_code
136824       ,p_accounting_line_code       => l_component_code
136825       ,p_accounting_line_type_code  => l_component_type_code
136826       ,p_accounting_line_appl_id    => l_component_appl_id
136827       ,p_amb_context_code           => l_amb_context_code
136828       ,p_entity_code                => l_entity_code
136829       ,p_event_class_code           => l_event_class_code);
136830    --
136831    -- set accounting class
136832    --
136833    xla_ae_lines_pkg.SetAcctClass(
136834            p_accounting_class_code  => 'EXPENSE'
136835          , p_ae_header_id           => l_ae_header_id
136836          );
136837 
136838    --
136839    -- set rounding class
136840    --
136841    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
136842                       'EXPENSE';
136843 
136844    --
136845    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
136846    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
136847    --
136848    -- bulk performance
136849    --
136850    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
136851 
136852    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
136853       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
136854 
136855    -- 4955764
136856    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
136857       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
136858 
136859    -- 4458381 Public Sector Enh
136860    
136861    --
136862    -- set accounting attributes for the line type
136863    --
136864    l_entered_amt_idx := 4;
136865    l_accted_amt_idx  := 6;
136866    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
136867    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
136868    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
136869    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
136870    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
136871    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
136872    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
136873    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
136874    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
136875    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
136876    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
136877    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
136878    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
136879 
136880    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
136884    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
136881    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
136882 
136883    ---------------------------------------------------------------------------------------------------------------
136885    ---------------------------------------------------------------------------------------------------------------
136886    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
136887 
136888    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
136889    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
136890 
136891    IF xla_accounting_cache_pkg.GetValueChar
136892          (p_source_code         => 'LEDGER_CATEGORY_CODE'
136893          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
136894    AND l_bflow_method_code = 'PRIOR_ENTRY'
136895 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
136896    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
136897          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
136898        )
136899    THEN
136900          xla_ae_lines_pkg.BflowUpgEntry
136901            (p_business_method_code    => l_bflow_method_code
136902            ,p_business_class_code     => l_bflow_class_code
136903            ,p_balance_type            => l_balance_type_code);
136904    ELSE
136905       NULL;
136906 -- No business flow processing for business flow method of NONE.
136907    END IF;
136908 
136909    --
136910    -- call analytical criteria
136911    --
136912    
136913    --
136914    -- call description
136915    --
136916    
136917 xla_ae_lines_pkg.SetLineDescription(
136918    p_ae_header_id => l_ae_header_id
136919   ,p_description  => Description_112 (
136920      p_application_id         => p_application_id
136921    , p_ae_header_id           => l_ae_header_id 
136922 , p_source_1 => p_source_1
136923    )
136924 );
136925 
136926 
136927    --
136928    -- call ADRs
136929    -- Bug 4922099
136930    --
136931    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
136932         (NVL(l_actual_upg_option, 'N') = 'O') OR
136933         (NVL(l_enc_upg_option, 'N') = 'O')
136934       )
136935    THEN
136936    NULL;
136937    --
136938    --
136939    
136940   l_ccid := AcctDerRule_175(
136941            p_application_id           => p_application_id
136942          , p_ae_header_id             => l_ae_header_id 
136943 , p_source_3 => p_source_3
136944 , p_source_29 => p_source_29
136945          , x_transaction_coa_id       => l_adr_transaction_coa_id
136946          , x_accounting_coa_id        => l_adr_accounting_coa_id
136947          , x_value_type_code          => l_adr_value_type_code
136948          , p_side                     => 'NA'
136949    );
136950 
136951    xla_ae_lines_pkg.set_ccid(
136952     p_code_combination_id          => l_ccid
136953   , p_value_type_code              => l_adr_value_type_code
136954   , p_transaction_coa_id           => l_adr_transaction_coa_id
136955   , p_accounting_coa_id            => l_adr_accounting_coa_id
136956   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
136957   , p_adr_type_code                => 'S'
136958   , p_component_type               => l_component_type
136959   , p_component_code               => l_component_code
136960   , p_component_type_code          => l_component_type_code
136961   , p_component_appl_id            => l_component_appl_id
136962   , p_amb_context_code             => l_amb_context_code
136963   , p_side                         => 'NA'
136964   );
136965 
136966 
136967    --
136968    --
136969    END IF;
136970    --
136971    -- Bug 4922099
136972    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
136973           (NVL(l_enc_upg_option, 'N') = 'O')
136974         ) AND
136975         (l_bflow_method_code = 'PRIOR_ENTRY')
136976       )
136977    THEN
136978       IF
136979       --
136980       1 = 2
136981       --
136982       THEN
136983       xla_accounting_err_pkg.build_message
136984                                     (p_appli_s_name            => 'XLA'
136985                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
136986                                     ,p_token_1                 => 'LINE_NUMBER'
136987                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
136988                                     ,p_token_2                 => 'LINE_TYPE_NAME'
136989                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
136990                                                                              l_component_type
136991                                                                             ,l_component_code
136992                                                                             ,l_component_type_code
136993                                                                             ,l_component_appl_id
136994                                                                             ,l_amb_context_code
136995                                                                             ,l_entity_code
136996                                                                             ,l_event_class_code
136997                                                                            )
136998                                     ,p_token_3                 => 'OWNER'
136999                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
137000                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
137001                                                                           ,p_lookup_code    => l_component_type_code
137002                                                                          )
137006                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
137003                                     ,p_token_4                 => 'PRODUCT_NAME'
137004                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
137005                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
137007                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
137008                                     ,p_ae_header_id            =>  NULL
137009                                        );
137010 
137011         IF (C_LEVEL_ERROR>= g_log_level) THEN
137012                  trace
137013                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
137014                       ,p_level    => C_LEVEL_ERROR
137015                       ,p_module   => l_log_module);
137016         END IF;
137017       END IF;
137018    END IF;
137019    --
137020    --
137021    ------------------------------------------------------------------------------------------------
137022    -- 4219869 Business Flow
137023    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
137024    -- Prior Entry.  Currently, the following code is always generated.
137025    ------------------------------------------------------------------------------------------------
137026    XLA_AE_LINES_PKG.ValidateCurrentLine;
137027 
137028    ------------------------------------------------------------------------------------
137029    -- 4219869 Business Flow
137030    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
137031    ------------------------------------------------------------------------------------
137032    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
137033 
137034    ----------------------------------------------------------------------------------
137035    -- 4219869 Business Flow
137036    -- Update journal entry status -- Need to generate this within IF <condition>
137037    ----------------------------------------------------------------------------------
137038    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
137039          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
137040          ,p_balance_type_code => l_balance_type_code
137041          );
137042 
137043    -------------------------------------------------------------------------------------------
137044    -- 4262811 - Generate the Accrual Reversal lines
137045    -------------------------------------------------------------------------------------------
137046    BEGIN
137047       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
137048                               (g_array_event(p_event_id).array_value_num('header_index'));
137049       IF l_acc_rev_flag IS NULL THEN
137050          l_acc_rev_flag := 'N';
137051       END IF;
137052    EXCEPTION
137053       WHEN OTHERS THEN
137054          l_acc_rev_flag := 'N';
137055    END;
137056    --
137057    IF (l_acc_rev_flag = 'Y') THEN
137058 
137059        -- 4645092  ------------------------------------------------------------------------------
137060        -- To allow MPA report to determine if it should generate report process
137061        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
137062        ------------------------------------------------------------------------------------------
137063 
137064        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
137065        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
137066    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
137067    -- call ADRs
137068    -- Bug 4922099
137069    --
137070    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
137071         (NVL(l_actual_upg_option, 'N') = 'O') OR
137072         (NVL(l_enc_upg_option, 'N') = 'O')
137073       )
137074    THEN
137075    NULL;
137076    --
137077    --
137078    
137079   l_ccid := AcctDerRule_175(
137080            p_application_id           => p_application_id
137081          , p_ae_header_id             => l_ae_header_id 
137082 , p_source_3 => p_source_3
137083 , p_source_29 => p_source_29
137084          , x_transaction_coa_id       => l_adr_transaction_coa_id
137085          , x_accounting_coa_id        => l_adr_accounting_coa_id
137086          , x_value_type_code          => l_adr_value_type_code
137087          , p_side                     => 'NA'
137088    );
137089 
137090    xla_ae_lines_pkg.set_ccid(
137091     p_code_combination_id          => l_ccid
137092   , p_value_type_code              => l_adr_value_type_code
137093   , p_transaction_coa_id           => l_adr_transaction_coa_id
137094   , p_accounting_coa_id            => l_adr_accounting_coa_id
137095   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
137096   , p_adr_type_code                => 'S'
137097   , p_component_type               => l_component_type
137098   , p_component_code               => l_component_code
137099   , p_component_type_code          => l_component_type_code
137100   , p_component_appl_id            => l_component_appl_id
137101   , p_amb_context_code             => l_amb_context_code
137102   , p_side                         => 'NA'
137103   );
137104 
137105 
137106    --
137107    --
137108    END IF;
137109 
137110        --
137111        -- Update the line information that should be overwritten
137112        --
137113        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
137114                                          p_header_num   => 1);
137115        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
137116 
137117        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
137118 
137119        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
137123       --
137120           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
137121        END IF;
137122 
137124       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
137125       --
137126       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
137127           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
137128       ELSE
137129           ---------------------------------------------------------------------------------------------------
137130           -- 4262811a Switch Sign
137131           ---------------------------------------------------------------------------------------------------
137132           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
137133           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
137134                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
137135           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
137136                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
137137           -- 5132302
137138           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
137139                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
137140 
137141       END IF;
137142 
137143       -- 4955764
137144       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
137145       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
137146 
137147 
137148       XLA_AE_LINES_PKG.ValidateCurrentLine;
137149       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
137150 
137151       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
137152                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
137153                ,p_balance_type_code => l_balance_type_code);
137154 
137155    END IF;
137156 
137157    -----------------------------------------------------------------------------------------
137158    -- 4262811 Multiperiod Accounting
137159    -----------------------------------------------------------------------------------------
137160      -- No MPA option is assigned.
137161 
137162 
137163 END IF;
137164 END IF;
137165 --
137166 
137167 --
137168 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
137169    trace
137170       (p_msg      => 'END of AcctLineType_346'
137171       ,p_level    => C_LEVEL_PROCEDURE
137172       ,p_module   => l_log_module);
137173 END IF;
137174 --
137175 EXCEPTION
137176   WHEN xla_exceptions_pkg.application_exception THEN
137177       RAISE;
137178   WHEN OTHERS THEN
137179        xla_exceptions_pkg.raise_message
137180            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_346');
137181 END AcctLineType_346;
137182 --
137183 
137184 ---------------------------------------
137185 --
137186 -- PRIVATE FUNCTION
137187 --         AcctLineType_347
137188 --
137189 ---------------------------------------
137190 PROCEDURE AcctLineType_347 (
137191   p_application_id        IN NUMBER
137192  ,p_event_id              IN NUMBER
137193  ,p_calculate_acctd_flag  IN VARCHAR2
137194  ,p_calculate_g_l_flag    IN VARCHAR2
137195  ,p_actual_flag           IN OUT VARCHAR2
137196  ,p_balance_type_code     OUT VARCHAR2
137197  ,p_gain_or_loss_ref      OUT VARCHAR2
137198  
137199 --Period Close Date
137200  , p_source_1            IN DATE
137201 --Generated Code Combination Identifier
137202  , p_source_3            IN NUMBER
137203 --Depreciation Reserve Account
137204  , p_source_10            IN VARCHAR2
137205 --Generated Offset Code Combination Identifier
137206  , p_source_17            IN NUMBER
137207 --Expense Account Code Combination Identifier
137208  , p_source_29            IN NUMBER
137209 --Default Code Combination Identifier
137210  , p_source_30            IN NUMBER
137211 --Adjustment Type
137212  , p_source_35            IN VARCHAR2
137213 --Transaction Header Identifier
137214  , p_source_36            IN NUMBER
137215 --Adjustment Line Identifier
137216  , p_source_37            IN NUMBER
137217 --Distribution Type Code
137218  , p_source_38            IN VARCHAR2
137219 --Entered Amount
137220  , p_source_39            IN NUMBER
137221 --Currency Code
137222  , p_source_40            IN VARCHAR2
137223 --Source Destination Code
137224  , p_source_42            IN VARCHAR2
137225 )
137226 IS
137227 
137228 l_component_type              VARCHAR2(80);
137229 l_component_code              VARCHAR2(30);
137230 l_component_type_code         VARCHAR2(1);
137231 l_component_appl_id           INTEGER;
137232 l_amb_context_code            VARCHAR2(30);
137233 l_entity_code                 VARCHAR2(30);
137234 l_event_class_code            VARCHAR2(30);
137235 l_ae_header_id                NUMBER;
137236 l_event_type_code             VARCHAR2(30);
137237 l_line_definition_code        VARCHAR2(30);
137238 l_line_definition_owner_code  VARCHAR2(1);
137239 --
137240 -- adr variables
137241 l_segment                     VARCHAR2(30);
137242 l_ccid                        NUMBER;
137243 l_adr_transaction_coa_id      NUMBER;
137244 l_adr_accounting_coa_id       NUMBER;
137245 l_adr_flexfield_segment_code  VARCHAR2(30);
137246 l_adr_flex_value_set_id       NUMBER;
137247 l_adr_value_type_code         VARCHAR2(30);
137248 l_adr_value_combination_id    NUMBER;
137249 l_adr_value_segment_code      VARCHAR2(30);
137250 
137251 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
137252 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
137253 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
137257 l_entered_amt_idx             NUMBER;
137254 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
137255 
137256 -- 4262811 Variables ------------------------------------------------------------------------------------------
137258 l_accted_amt_idx              NUMBER;
137259 l_acc_rev_flag                VARCHAR2(1);
137260 l_accrual_line_num            NUMBER;
137261 l_tmp_amt                     NUMBER;
137262 l_acc_rev_natural_side_code   VARCHAR2(1);
137263 
137264 l_num_entries                 NUMBER;
137265 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
137266 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
137267 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
137268 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
137269 l_recog_line_1                NUMBER;
137270 l_recog_line_2                NUMBER;
137271 
137272 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
137273 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
137274 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
137275 
137276 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
137277 
137278 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
137279 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
137280 
137281 ---------------------------------------------------------------------------------------------------------------
137282 
137283 
137284 --
137285 -- bulk performance
137286 --
137287 l_balance_type_code           VARCHAR2(1);
137288 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
137289 l_log_module                  VARCHAR2(240);
137290 
137291 --
137292 -- Upgrade strategy
137293 --
137294 l_actual_upg_option           VARCHAR2(1);
137295 l_enc_upg_option           VARCHAR2(1);
137296 
137297 --
137298 BEGIN
137299 --
137300 IF g_log_enabled THEN
137301       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_347';
137302 END IF;
137303 --
137304 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
137305 
137306       trace
137307          (p_msg      => 'BEGIN of AcctLineType_347'
137308          ,p_level    => C_LEVEL_PROCEDURE
137309          ,p_module   => l_log_module);
137310 
137311 END IF;
137312 --
137313 l_component_type             := 'AMB_JLT';
137314 l_component_code             := 'FA_SLT_DEST_RESERVE_BAL';
137315 l_component_type_code        := 'S';
137316 l_component_appl_id          :=  140;
137317 l_amb_context_code           := 'DEFAULT';
137318 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
137319 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
137320 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
137321 l_line_definition_owner_code := 'S';
137322 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
137323 --
137324 l_balance_type_code          := 'A';
137325 l_segment                     := NULL;
137326 l_ccid                        := NULL;
137327 l_adr_transaction_coa_id      := NULL;
137328 l_adr_accounting_coa_id       := NULL;
137329 l_adr_flexfield_segment_code  := NULL;
137330 l_adr_flex_value_set_id       := NULL;
137331 l_adr_value_type_code         := NULL;
137332 l_adr_value_combination_id    := NULL;
137333 l_adr_value_segment_code      := NULL;
137334 
137335 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
137336 l_bflow_class_code           := '';    -- 4219869 Business Flow
137337 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
137338 l_budgetary_control_flag     := 'N';
137339 
137340 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
137341 l_bflow_applied_to_amt       := NULL; -- 5132302
137342 l_entered_amt_idx            := NULL;          -- 4262811
137343 l_accted_amt_idx             := NULL;          -- 4262811
137344 l_acc_rev_flag               := NULL;          -- 4262811
137345 l_accrual_line_num           := NULL;          -- 4262811
137346 l_tmp_amt                    := NULL;          -- 4262811
137347 --
137348  
137349 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
137350     l_balance_type_code <> 'B' THEN
137351 IF (NVL(p_source_35,'
137352 ') =  'BONUS EXPENSE' OR 
137353 NVL(p_source_35,'
137354 ') =  'BONUS RESERVE') AND 
137355 NVL(p_source_42,'
137356 ') =  'DEST'
137357  THEN 
137358 
137359    --
137360    XLA_AE_LINES_PKG.SetNewLine;
137361 
137362    p_balance_type_code          := l_balance_type_code;
137363    -- set the flag so later we will know whether the gain loss line needs to be created
137364    
137365    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
137366      p_actual_flag :='A';
137367    END IF;
137368 
137369    --
137370    -- bulk performance
137371    --
137372    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
137373                                       p_header_num   => 0); -- 4262811
137374    --
137375    -- set accounting line options
137376    --
137377    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
137378            p_natural_side_code          => 'D'
137379          , p_gain_or_loss_flag          => 'N'
137380          , p_gl_transfer_mode_code      => 'S'
137381          , p_acct_entry_type_code       => 'A'
137382          , p_switch_side_flag           => 'Y'
137383          , p_merge_duplicate_code       => 'N'
137384          );
137385    --
137386    l_acc_rev_natural_side_code := 'C';  -- 4262811
137387    -- 
137388    --
137389    -- set accounting line type info
137390    --
137391    xla_ae_lines_pkg.SetAcctLineType
137392       (p_component_type             => l_component_type
137393       ,p_event_type_code            => l_event_type_code
137394       ,p_line_definition_owner_code => l_line_definition_owner_code
137398       ,p_accounting_line_appl_id    => l_component_appl_id
137395       ,p_line_definition_code       => l_line_definition_code
137396       ,p_accounting_line_code       => l_component_code
137397       ,p_accounting_line_type_code  => l_component_type_code
137399       ,p_amb_context_code           => l_amb_context_code
137400       ,p_entity_code                => l_entity_code
137401       ,p_event_class_code           => l_event_class_code);
137402    --
137403    -- set accounting class
137404    --
137405    xla_ae_lines_pkg.SetAcctClass(
137406            p_accounting_class_code  => 'ASSET'
137407          , p_ae_header_id           => l_ae_header_id
137408          );
137409 
137410    --
137411    -- set rounding class
137412    --
137413    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
137414                       'ASSET';
137415 
137416    --
137417    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
137418    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
137419    --
137420    -- bulk performance
137421    --
137422    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
137423 
137424    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
137425       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
137426 
137427    -- 4955764
137428    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
137429       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
137430 
137431    -- 4458381 Public Sector Enh
137432    
137433    --
137434    -- set accounting attributes for the line type
137435    --
137436    l_entered_amt_idx := 4;
137437    l_accted_amt_idx  := 6;
137438    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
137439    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
137440    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
137441    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
137442    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
137443    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
137444    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
137445    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
137446    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
137447    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
137448    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
137449    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
137450    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
137451 
137452    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
137453    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
137454 
137455    ---------------------------------------------------------------------------------------------------------------
137456    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
137457    ---------------------------------------------------------------------------------------------------------------
137458    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
137459 
137460    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
137461    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
137462 
137463    IF xla_accounting_cache_pkg.GetValueChar
137464          (p_source_code         => 'LEDGER_CATEGORY_CODE'
137465          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
137466    AND l_bflow_method_code = 'PRIOR_ENTRY'
137467 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
137468    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
137469          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
137470        )
137471    THEN
137472          xla_ae_lines_pkg.BflowUpgEntry
137473            (p_business_method_code    => l_bflow_method_code
137474            ,p_business_class_code     => l_bflow_class_code
137475            ,p_balance_type            => l_balance_type_code);
137476    ELSE
137477       NULL;
137478 -- No business flow processing for business flow method of NONE.
137479    END IF;
137480 
137481    --
137482    -- call analytical criteria
137483    --
137484    
137485    --
137486    -- call description
137487    --
137488    
137489 xla_ae_lines_pkg.SetLineDescription(
137490    p_ae_header_id => l_ae_header_id
137491   ,p_description  => Description_113 (
137492      p_application_id         => p_application_id
137493    , p_ae_header_id           => l_ae_header_id 
137494 , p_source_1 => p_source_1
137495    )
137496 );
137497 
137498 
137499    --
137500    -- call ADRs
137501    -- Bug 4922099
137502    --
137503    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
137504         (NVL(l_actual_upg_option, 'N') = 'O') OR
137505         (NVL(l_enc_upg_option, 'N') = 'O')
137506       )
137507    THEN
137508    NULL;
137509    --
137510    --
137511    
137512   l_ccid := AcctDerRule_174(
137513            p_application_id           => p_application_id
137514          , p_ae_header_id             => l_ae_header_id 
137515 , p_source_3 => p_source_3
137516 , p_source_17 => p_source_17
137517 , p_source_30 => p_source_30
137518          , x_transaction_coa_id       => l_adr_transaction_coa_id
137519          , x_accounting_coa_id        => l_adr_accounting_coa_id
137520          , x_value_type_code          => l_adr_value_type_code
137521          , p_side                     => 'NA'
137522    );
137523 
137524    xla_ae_lines_pkg.set_ccid(
137528   , p_accounting_coa_id            => l_adr_accounting_coa_id
137525     p_code_combination_id          => l_ccid
137526   , p_value_type_code              => l_adr_value_type_code
137527   , p_transaction_coa_id           => l_adr_transaction_coa_id
137529   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
137530   , p_adr_type_code                => 'S'
137531   , p_component_type               => l_component_type
137532   , p_component_code               => l_component_code
137533   , p_component_type_code          => l_component_type_code
137534   , p_component_appl_id            => l_component_appl_id
137535   , p_amb_context_code             => l_amb_context_code
137536   , p_side                         => 'NA'
137537   );
137538 
137539 
137540    l_segment := AcctDerRule_149(
137541            p_application_id           => p_application_id
137542          , p_ae_header_id             => l_ae_header_id 
137543 , p_source_3 => p_source_3
137544 , p_source_10 => p_source_10
137545          , x_transaction_coa_id       => l_adr_transaction_coa_id
137546          , x_accounting_coa_id        => l_adr_accounting_coa_id
137547          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
137548          , x_flex_value_set_id        => l_adr_flex_value_set_id
137549          , x_value_type_code          => l_adr_value_type_code
137550          , x_value_combination_id     => l_adr_value_combination_id
137551          , x_value_segment_code       => l_adr_value_segment_code
137552          , p_side                     => 'NA'
137553          , p_override_seg_flag        => 'Y'
137554    );
137555 
137556    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
137557 
137558       xla_ae_lines_pkg.set_segment(
137559           p_to_segment_code         => 'GL_ACCOUNT'
137560         , p_segment_value           => l_segment
137561         , p_from_segment_code       => l_adr_value_segment_code
137562         , p_from_combination_id     => l_adr_value_combination_id
137563         , p_value_type_code         => l_adr_value_type_code
137564         , p_transaction_coa_id      => l_adr_transaction_coa_id
137565         , p_accounting_coa_id       => l_adr_accounting_coa_id
137566         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
137567         , p_flex_value_set_id       => l_adr_flex_value_set_id
137568         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
137569         , p_adr_type_code           => 'S'
137570         , p_component_type          => l_component_type
137571         , p_component_code          => l_component_code
137572         , p_component_type_code     => l_component_type_code
137573         , p_component_appl_id       => l_component_appl_id
137574         , p_amb_context_code        => l_amb_context_code
137575         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
137576         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
137577         , p_side                    => 'NA'
137578         );
137579 
137580   END IF;
137581 
137582    l_segment := AcctDerRule_168(
137583            p_application_id           => p_application_id
137584          , p_ae_header_id             => l_ae_header_id 
137585 , p_source_3 => p_source_3
137586 , p_source_29 => p_source_29
137587          , x_transaction_coa_id       => l_adr_transaction_coa_id
137588          , x_accounting_coa_id        => l_adr_accounting_coa_id
137589          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
137590          , x_flex_value_set_id        => l_adr_flex_value_set_id
137591          , x_value_type_code          => l_adr_value_type_code
137592          , x_value_combination_id     => l_adr_value_combination_id
137593          , x_value_segment_code       => l_adr_value_segment_code
137594          , p_side                     => 'NA'
137595          , p_override_seg_flag        => 'Y'
137596    );
137597 
137598    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
137599 
137600       xla_ae_lines_pkg.set_segment(
137601           p_to_segment_code         => 'GL_BALANCING'
137602         , p_segment_value           => l_segment
137603         , p_from_segment_code       => l_adr_value_segment_code
137604         , p_from_combination_id     => l_adr_value_combination_id
137605         , p_value_type_code         => l_adr_value_type_code
137606         , p_transaction_coa_id      => l_adr_transaction_coa_id
137607         , p_accounting_coa_id       => l_adr_accounting_coa_id
137608         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
137609         , p_flex_value_set_id       => l_adr_flex_value_set_id
137610         , p_adr_code                => 'FA_EXPENSE_ACCT'
137611         , p_adr_type_code           => 'S'
137612         , p_component_type          => l_component_type
137613         , p_component_code          => l_component_code
137614         , p_component_type_code     => l_component_type_code
137615         , p_component_appl_id       => l_component_appl_id
137616         , p_amb_context_code        => l_amb_context_code
137617         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
137618         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
137619         , p_side                    => 'NA'
137620         );
137621 
137622   END IF;
137623 
137624    --
137625    --
137626    END IF;
137627    --
137628    -- Bug 4922099
137629    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
137630           (NVL(l_enc_upg_option, 'N') = 'O')
137631         ) AND
137632         (l_bflow_method_code = 'PRIOR_ENTRY')
137633       )
137634    THEN
137635       IF
137636       --
137637       1 = 2
137638       --
137639       THEN
137640       xla_accounting_err_pkg.build_message
137641                                     (p_appli_s_name            => 'XLA'
137642                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
137643                                     ,p_token_1                 => 'LINE_NUMBER'
137644                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
137648                                                                             ,l_component_code
137645                                     ,p_token_2                 => 'LINE_TYPE_NAME'
137646                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
137647                                                                              l_component_type
137649                                                                             ,l_component_type_code
137650                                                                             ,l_component_appl_id
137651                                                                             ,l_amb_context_code
137652                                                                             ,l_entity_code
137653                                                                             ,l_event_class_code
137654                                                                            )
137655                                     ,p_token_3                 => 'OWNER'
137656                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
137657                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
137658                                                                           ,p_lookup_code    => l_component_type_code
137659                                                                          )
137660                                     ,p_token_4                 => 'PRODUCT_NAME'
137661                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
137662                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
137663                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
137664                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
137665                                     ,p_ae_header_id            =>  NULL
137666                                        );
137667 
137668         IF (C_LEVEL_ERROR>= g_log_level) THEN
137669                  trace
137670                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
137671                       ,p_level    => C_LEVEL_ERROR
137672                       ,p_module   => l_log_module);
137673         END IF;
137674       END IF;
137675    END IF;
137676    --
137677    --
137678    ------------------------------------------------------------------------------------------------
137679    -- 4219869 Business Flow
137680    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
137681    -- Prior Entry.  Currently, the following code is always generated.
137682    ------------------------------------------------------------------------------------------------
137683    XLA_AE_LINES_PKG.ValidateCurrentLine;
137684 
137685    ------------------------------------------------------------------------------------
137686    -- 4219869 Business Flow
137687    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
137688    ------------------------------------------------------------------------------------
137689    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
137690 
137691    ----------------------------------------------------------------------------------
137692    -- 4219869 Business Flow
137693    -- Update journal entry status -- Need to generate this within IF <condition>
137694    ----------------------------------------------------------------------------------
137695    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
137696          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
137697          ,p_balance_type_code => l_balance_type_code
137698          );
137699 
137700    -------------------------------------------------------------------------------------------
137701    -- 4262811 - Generate the Accrual Reversal lines
137702    -------------------------------------------------------------------------------------------
137703    BEGIN
137704       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
137705                               (g_array_event(p_event_id).array_value_num('header_index'));
137706       IF l_acc_rev_flag IS NULL THEN
137707          l_acc_rev_flag := 'N';
137708       END IF;
137709    EXCEPTION
137710       WHEN OTHERS THEN
137711          l_acc_rev_flag := 'N';
137712    END;
137713    --
137714    IF (l_acc_rev_flag = 'Y') THEN
137715 
137716        -- 4645092  ------------------------------------------------------------------------------
137717        -- To allow MPA report to determine if it should generate report process
137718        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
137719        ------------------------------------------------------------------------------------------
137720 
137721        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
137722        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
137723    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
137724    -- call ADRs
137725    -- Bug 4922099
137726    --
137727    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
137728         (NVL(l_actual_upg_option, 'N') = 'O') OR
137729         (NVL(l_enc_upg_option, 'N') = 'O')
137730       )
137731    THEN
137732    NULL;
137733    --
137734    --
137735    
137736   l_ccid := AcctDerRule_174(
137737            p_application_id           => p_application_id
137738          , p_ae_header_id             => l_ae_header_id 
137739 , p_source_3 => p_source_3
137740 , p_source_17 => p_source_17
137741 , p_source_30 => p_source_30
137742          , x_transaction_coa_id       => l_adr_transaction_coa_id
137743          , x_accounting_coa_id        => l_adr_accounting_coa_id
137744          , x_value_type_code          => l_adr_value_type_code
137745          , p_side                     => 'NA'
137746    );
137747 
137748    xla_ae_lines_pkg.set_ccid(
137749     p_code_combination_id          => l_ccid
137753   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
137750   , p_value_type_code              => l_adr_value_type_code
137751   , p_transaction_coa_id           => l_adr_transaction_coa_id
137752   , p_accounting_coa_id            => l_adr_accounting_coa_id
137754   , p_adr_type_code                => 'S'
137755   , p_component_type               => l_component_type
137756   , p_component_code               => l_component_code
137757   , p_component_type_code          => l_component_type_code
137758   , p_component_appl_id            => l_component_appl_id
137759   , p_amb_context_code             => l_amb_context_code
137760   , p_side                         => 'NA'
137761   );
137762 
137763 
137764    l_segment := AcctDerRule_149(
137765            p_application_id           => p_application_id
137766          , p_ae_header_id             => l_ae_header_id 
137767 , p_source_3 => p_source_3
137768 , p_source_10 => p_source_10
137769          , x_transaction_coa_id       => l_adr_transaction_coa_id
137770          , x_accounting_coa_id        => l_adr_accounting_coa_id
137771          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
137772          , x_flex_value_set_id        => l_adr_flex_value_set_id
137773          , x_value_type_code          => l_adr_value_type_code
137774          , x_value_combination_id     => l_adr_value_combination_id
137775          , x_value_segment_code       => l_adr_value_segment_code
137776          , p_side                     => 'NA'
137777          , p_override_seg_flag        => 'Y'
137778    );
137779 
137780    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
137781 
137782       xla_ae_lines_pkg.set_segment(
137783           p_to_segment_code         => 'GL_ACCOUNT'
137784         , p_segment_value           => l_segment
137785         , p_from_segment_code       => l_adr_value_segment_code
137786         , p_from_combination_id     => l_adr_value_combination_id
137787         , p_value_type_code         => l_adr_value_type_code
137788         , p_transaction_coa_id      => l_adr_transaction_coa_id
137789         , p_accounting_coa_id       => l_adr_accounting_coa_id
137790         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
137791         , p_flex_value_set_id       => l_adr_flex_value_set_id
137792         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
137793         , p_adr_type_code           => 'S'
137794         , p_component_type          => l_component_type
137795         , p_component_code          => l_component_code
137796         , p_component_type_code     => l_component_type_code
137797         , p_component_appl_id       => l_component_appl_id
137798         , p_amb_context_code        => l_amb_context_code
137799         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
137800         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
137801         , p_side                    => 'NA'
137802         );
137803 
137804   END IF;
137805 
137806    l_segment := AcctDerRule_168(
137807            p_application_id           => p_application_id
137808          , p_ae_header_id             => l_ae_header_id 
137809 , p_source_3 => p_source_3
137810 , p_source_29 => p_source_29
137811          , x_transaction_coa_id       => l_adr_transaction_coa_id
137812          , x_accounting_coa_id        => l_adr_accounting_coa_id
137813          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
137814          , x_flex_value_set_id        => l_adr_flex_value_set_id
137815          , x_value_type_code          => l_adr_value_type_code
137816          , x_value_combination_id     => l_adr_value_combination_id
137817          , x_value_segment_code       => l_adr_value_segment_code
137818          , p_side                     => 'NA'
137819          , p_override_seg_flag        => 'Y'
137820    );
137821 
137822    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
137823 
137824       xla_ae_lines_pkg.set_segment(
137825           p_to_segment_code         => 'GL_BALANCING'
137826         , p_segment_value           => l_segment
137827         , p_from_segment_code       => l_adr_value_segment_code
137828         , p_from_combination_id     => l_adr_value_combination_id
137829         , p_value_type_code         => l_adr_value_type_code
137830         , p_transaction_coa_id      => l_adr_transaction_coa_id
137831         , p_accounting_coa_id       => l_adr_accounting_coa_id
137832         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
137833         , p_flex_value_set_id       => l_adr_flex_value_set_id
137834         , p_adr_code                => 'FA_EXPENSE_ACCT'
137835         , p_adr_type_code           => 'S'
137836         , p_component_type          => l_component_type
137837         , p_component_code          => l_component_code
137838         , p_component_type_code     => l_component_type_code
137839         , p_component_appl_id       => l_component_appl_id
137840         , p_amb_context_code        => l_amb_context_code
137841         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
137842         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
137843         , p_side                    => 'NA'
137844         );
137845 
137846   END IF;
137847 
137848    --
137849    --
137850    END IF;
137851 
137852        --
137853        -- Update the line information that should be overwritten
137854        --
137855        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
137856                                          p_header_num   => 1);
137857        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
137858 
137859        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
137860 
137861        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
137862           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
137863        END IF;
137864 
137865       --
137866       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
137870       ELSE
137867       --
137868       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
137869           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
137871           ---------------------------------------------------------------------------------------------------
137872           -- 4262811a Switch Sign
137873           ---------------------------------------------------------------------------------------------------
137874           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
137875           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
137876                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
137877           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
137878                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
137879           -- 5132302
137880           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
137881                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
137882 
137883       END IF;
137884 
137885       -- 4955764
137886       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
137887       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
137888 
137889 
137890       XLA_AE_LINES_PKG.ValidateCurrentLine;
137891       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
137892 
137893       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
137894                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
137895                ,p_balance_type_code => l_balance_type_code);
137896 
137897    END IF;
137898 
137899    -----------------------------------------------------------------------------------------
137900    -- 4262811 Multiperiod Accounting
137901    -----------------------------------------------------------------------------------------
137902      -- No MPA option is assigned.
137903 
137904 
137905 END IF;
137906 END IF;
137907 --
137908 
137909 --
137910 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
137911    trace
137912       (p_msg      => 'END of AcctLineType_347'
137913       ,p_level    => C_LEVEL_PROCEDURE
137914       ,p_module   => l_log_module);
137915 END IF;
137916 --
137917 EXCEPTION
137918   WHEN xla_exceptions_pkg.application_exception THEN
137919       RAISE;
137920   WHEN OTHERS THEN
137921        xla_exceptions_pkg.raise_message
137922            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_347');
137923 END AcctLineType_347;
137924 --
137925 
137926 ---------------------------------------
137927 --
137928 -- PRIVATE FUNCTION
137929 --         AcctLineType_348
137930 --
137931 ---------------------------------------
137932 PROCEDURE AcctLineType_348 (
137933   p_application_id        IN NUMBER
137934  ,p_event_id              IN NUMBER
137935  ,p_calculate_acctd_flag  IN VARCHAR2
137936  ,p_calculate_g_l_flag    IN VARCHAR2
137937  ,p_actual_flag           IN OUT VARCHAR2
137938  ,p_balance_type_code     OUT VARCHAR2
137939  ,p_gain_or_loss_ref      OUT VARCHAR2
137940  
137941 --Period Close Date
137942  , p_source_1            IN DATE
137943 --Generated Code Combination Identifier
137944  , p_source_3            IN NUMBER
137945 --Revaluation Reserve Account
137946  , p_source_11            IN VARCHAR2
137947 --Generated Offset Code Combination Identifier
137948  , p_source_17            IN NUMBER
137949 --Expense Account Code Combination Identifier
137950  , p_source_29            IN NUMBER
137951 --Default Code Combination Identifier
137952  , p_source_30            IN NUMBER
137953 --Adjustment Type
137954  , p_source_35            IN VARCHAR2
137955 --Transaction Header Identifier
137956  , p_source_36            IN NUMBER
137957 --Adjustment Line Identifier
137958  , p_source_37            IN NUMBER
137959 --Distribution Type Code
137960  , p_source_38            IN VARCHAR2
137961 --Entered Amount
137962  , p_source_39            IN NUMBER
137963 --Currency Code
137964  , p_source_40            IN VARCHAR2
137965 --Source Destination Code
137966  , p_source_42            IN VARCHAR2
137967 )
137968 IS
137969 
137970 l_component_type              VARCHAR2(80);
137971 l_component_code              VARCHAR2(30);
137972 l_component_type_code         VARCHAR2(1);
137973 l_component_appl_id           INTEGER;
137974 l_amb_context_code            VARCHAR2(30);
137975 l_entity_code                 VARCHAR2(30);
137976 l_event_class_code            VARCHAR2(30);
137977 l_ae_header_id                NUMBER;
137978 l_event_type_code             VARCHAR2(30);
137979 l_line_definition_code        VARCHAR2(30);
137980 l_line_definition_owner_code  VARCHAR2(1);
137981 --
137982 -- adr variables
137983 l_segment                     VARCHAR2(30);
137984 l_ccid                        NUMBER;
137985 l_adr_transaction_coa_id      NUMBER;
137986 l_adr_accounting_coa_id       NUMBER;
137987 l_adr_flexfield_segment_code  VARCHAR2(30);
137988 l_adr_flex_value_set_id       NUMBER;
137989 l_adr_value_type_code         VARCHAR2(30);
137990 l_adr_value_combination_id    NUMBER;
137991 l_adr_value_segment_code      VARCHAR2(30);
137992 
137993 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
137994 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
137995 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
137996 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
137997 
137998 -- 4262811 Variables ------------------------------------------------------------------------------------------
137999 l_entered_amt_idx             NUMBER;
138000 l_accted_amt_idx              NUMBER;
138004 l_acc_rev_natural_side_code   VARCHAR2(1);
138001 l_acc_rev_flag                VARCHAR2(1);
138002 l_accrual_line_num            NUMBER;
138003 l_tmp_amt                     NUMBER;
138005 
138006 l_num_entries                 NUMBER;
138007 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
138008 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
138009 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
138010 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
138011 l_recog_line_1                NUMBER;
138012 l_recog_line_2                NUMBER;
138013 
138014 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
138015 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
138016 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
138017 
138018 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
138019 
138020 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
138021 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
138022 
138023 ---------------------------------------------------------------------------------------------------------------
138024 
138025 
138026 --
138027 -- bulk performance
138028 --
138029 l_balance_type_code           VARCHAR2(1);
138030 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
138031 l_log_module                  VARCHAR2(240);
138032 
138033 --
138034 -- Upgrade strategy
138035 --
138036 l_actual_upg_option           VARCHAR2(1);
138037 l_enc_upg_option           VARCHAR2(1);
138038 
138039 --
138040 BEGIN
138041 --
138042 IF g_log_enabled THEN
138043       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_348';
138044 END IF;
138045 --
138046 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
138047 
138048       trace
138049          (p_msg      => 'BEGIN of AcctLineType_348'
138050          ,p_level    => C_LEVEL_PROCEDURE
138051          ,p_module   => l_log_module);
138052 
138053 END IF;
138054 --
138055 l_component_type             := 'AMB_JLT';
138056 l_component_code             := 'FA_SLT_DEST_REVAL_RESERVE';
138057 l_component_type_code        := 'S';
138058 l_component_appl_id          :=  140;
138059 l_amb_context_code           := 'DEFAULT';
138060 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
138061 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
138062 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
138063 l_line_definition_owner_code := 'S';
138064 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
138065 --
138066 l_balance_type_code          := 'A';
138067 l_segment                     := NULL;
138068 l_ccid                        := NULL;
138069 l_adr_transaction_coa_id      := NULL;
138070 l_adr_accounting_coa_id       := NULL;
138071 l_adr_flexfield_segment_code  := NULL;
138072 l_adr_flex_value_set_id       := NULL;
138073 l_adr_value_type_code         := NULL;
138074 l_adr_value_combination_id    := NULL;
138075 l_adr_value_segment_code      := NULL;
138076 
138077 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
138078 l_bflow_class_code           := '';    -- 4219869 Business Flow
138079 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
138080 l_budgetary_control_flag     := 'N';
138081 
138082 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
138083 l_bflow_applied_to_amt       := NULL; -- 5132302
138084 l_entered_amt_idx            := NULL;          -- 4262811
138085 l_accted_amt_idx             := NULL;          -- 4262811
138086 l_acc_rev_flag               := NULL;          -- 4262811
138087 l_accrual_line_num           := NULL;          -- 4262811
138088 l_tmp_amt                    := NULL;          -- 4262811
138089 --
138090  
138091 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
138092     l_balance_type_code <> 'B' THEN
138093 IF NVL(p_source_35,'
138094 ') =  'REVAL RESERVE' AND 
138095 NVL(p_source_42,'
138096 ') =  'DEST'
138097  THEN 
138098 
138099    --
138100    XLA_AE_LINES_PKG.SetNewLine;
138101 
138102    p_balance_type_code          := l_balance_type_code;
138103    -- set the flag so later we will know whether the gain loss line needs to be created
138104    
138105    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
138106      p_actual_flag :='A';
138107    END IF;
138108 
138109    --
138110    -- bulk performance
138111    --
138112    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
138113                                       p_header_num   => 0); -- 4262811
138114    --
138115    -- set accounting line options
138116    --
138117    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
138118            p_natural_side_code          => 'C'
138119          , p_gain_or_loss_flag          => 'N'
138120          , p_gl_transfer_mode_code      => 'S'
138121          , p_acct_entry_type_code       => 'A'
138122          , p_switch_side_flag           => 'Y'
138123          , p_merge_duplicate_code       => 'N'
138124          );
138125    --
138126    l_acc_rev_natural_side_code := 'D';  -- 4262811
138127    -- 
138128    --
138129    -- set accounting line type info
138130    --
138131    xla_ae_lines_pkg.SetAcctLineType
138132       (p_component_type             => l_component_type
138133       ,p_event_type_code            => l_event_type_code
138134       ,p_line_definition_owner_code => l_line_definition_owner_code
138135       ,p_line_definition_code       => l_line_definition_code
138136       ,p_accounting_line_code       => l_component_code
138137       ,p_accounting_line_type_code  => l_component_type_code
138138       ,p_accounting_line_appl_id    => l_component_appl_id
138139       ,p_amb_context_code           => l_amb_context_code
138143    -- set accounting class
138140       ,p_entity_code                => l_entity_code
138141       ,p_event_class_code           => l_event_class_code);
138142    --
138144    --
138145    xla_ae_lines_pkg.SetAcctClass(
138146            p_accounting_class_code  => 'ASSET'
138147          , p_ae_header_id           => l_ae_header_id
138148          );
138149 
138150    --
138151    -- set rounding class
138152    --
138153    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
138154                       'ASSET';
138155 
138156    --
138157    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
138158    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
138159    --
138160    -- bulk performance
138161    --
138162    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
138163 
138164    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
138165       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
138166 
138167    -- 4955764
138168    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
138169       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
138170 
138171    -- 4458381 Public Sector Enh
138172    
138173    --
138174    -- set accounting attributes for the line type
138175    --
138176    l_entered_amt_idx := 4;
138177    l_accted_amt_idx  := 6;
138178    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
138179    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
138180    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
138181    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
138182    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
138183    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
138184    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
138185    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
138186    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
138187    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
138188    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
138189    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
138190    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
138191 
138192    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
138193    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
138194 
138195    ---------------------------------------------------------------------------------------------------------------
138196    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
138197    ---------------------------------------------------------------------------------------------------------------
138198    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
138199 
138200    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
138201    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
138202 
138203    IF xla_accounting_cache_pkg.GetValueChar
138204          (p_source_code         => 'LEDGER_CATEGORY_CODE'
138205          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
138206    AND l_bflow_method_code = 'PRIOR_ENTRY'
138207 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
138208    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
138209          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
138210        )
138211    THEN
138212          xla_ae_lines_pkg.BflowUpgEntry
138213            (p_business_method_code    => l_bflow_method_code
138214            ,p_business_class_code     => l_bflow_class_code
138215            ,p_balance_type            => l_balance_type_code);
138216    ELSE
138217       NULL;
138218 -- No business flow processing for business flow method of NONE.
138219    END IF;
138220 
138221    --
138222    -- call analytical criteria
138223    --
138224    
138225    --
138226    -- call description
138227    --
138228    
138229 xla_ae_lines_pkg.SetLineDescription(
138230    p_ae_header_id => l_ae_header_id
138231   ,p_description  => Description_116 (
138232      p_application_id         => p_application_id
138233    , p_ae_header_id           => l_ae_header_id 
138234 , p_source_1 => p_source_1
138235    )
138236 );
138237 
138238 
138239    --
138240    -- call ADRs
138241    -- Bug 4922099
138242    --
138243    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
138244         (NVL(l_actual_upg_option, 'N') = 'O') OR
138245         (NVL(l_enc_upg_option, 'N') = 'O')
138246       )
138247    THEN
138248    NULL;
138249    --
138250    --
138251    
138252   l_ccid := AcctDerRule_174(
138253            p_application_id           => p_application_id
138254          , p_ae_header_id             => l_ae_header_id 
138255 , p_source_3 => p_source_3
138256 , p_source_17 => p_source_17
138257 , p_source_30 => p_source_30
138258          , x_transaction_coa_id       => l_adr_transaction_coa_id
138259          , x_accounting_coa_id        => l_adr_accounting_coa_id
138260          , x_value_type_code          => l_adr_value_type_code
138261          , p_side                     => 'NA'
138262    );
138263 
138264    xla_ae_lines_pkg.set_ccid(
138265     p_code_combination_id          => l_ccid
138266   , p_value_type_code              => l_adr_value_type_code
138267   , p_transaction_coa_id           => l_adr_transaction_coa_id
138268   , p_accounting_coa_id            => l_adr_accounting_coa_id
138269   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
138273   , p_component_type_code          => l_component_type_code
138270   , p_adr_type_code                => 'S'
138271   , p_component_type               => l_component_type
138272   , p_component_code               => l_component_code
138274   , p_component_appl_id            => l_component_appl_id
138275   , p_amb_context_code             => l_amb_context_code
138276   , p_side                         => 'NA'
138277   );
138278 
138279 
138280    l_segment := AcctDerRule_150(
138281            p_application_id           => p_application_id
138282          , p_ae_header_id             => l_ae_header_id 
138283 , p_source_3 => p_source_3
138284 , p_source_11 => p_source_11
138285          , x_transaction_coa_id       => l_adr_transaction_coa_id
138286          , x_accounting_coa_id        => l_adr_accounting_coa_id
138287          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
138288          , x_flex_value_set_id        => l_adr_flex_value_set_id
138289          , x_value_type_code          => l_adr_value_type_code
138290          , x_value_combination_id     => l_adr_value_combination_id
138291          , x_value_segment_code       => l_adr_value_segment_code
138292          , p_side                     => 'NA'
138293          , p_override_seg_flag        => 'Y'
138294    );
138295 
138296    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
138297 
138298       xla_ae_lines_pkg.set_segment(
138299           p_to_segment_code         => 'GL_ACCOUNT'
138300         , p_segment_value           => l_segment
138301         , p_from_segment_code       => l_adr_value_segment_code
138302         , p_from_combination_id     => l_adr_value_combination_id
138303         , p_value_type_code         => l_adr_value_type_code
138304         , p_transaction_coa_id      => l_adr_transaction_coa_id
138305         , p_accounting_coa_id       => l_adr_accounting_coa_id
138306         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
138307         , p_flex_value_set_id       => l_adr_flex_value_set_id
138308         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
138309         , p_adr_type_code           => 'S'
138310         , p_component_type          => l_component_type
138311         , p_component_code          => l_component_code
138312         , p_component_type_code     => l_component_type_code
138313         , p_component_appl_id       => l_component_appl_id
138314         , p_amb_context_code        => l_amb_context_code
138315         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
138316         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
138317         , p_side                    => 'NA'
138318         );
138319 
138320   END IF;
138321 
138322    l_segment := AcctDerRule_168(
138323            p_application_id           => p_application_id
138324          , p_ae_header_id             => l_ae_header_id 
138325 , p_source_3 => p_source_3
138326 , p_source_29 => p_source_29
138327          , x_transaction_coa_id       => l_adr_transaction_coa_id
138328          , x_accounting_coa_id        => l_adr_accounting_coa_id
138329          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
138330          , x_flex_value_set_id        => l_adr_flex_value_set_id
138331          , x_value_type_code          => l_adr_value_type_code
138332          , x_value_combination_id     => l_adr_value_combination_id
138333          , x_value_segment_code       => l_adr_value_segment_code
138334          , p_side                     => 'NA'
138335          , p_override_seg_flag        => 'Y'
138336    );
138337 
138338    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
138339 
138340       xla_ae_lines_pkg.set_segment(
138341           p_to_segment_code         => 'GL_BALANCING'
138342         , p_segment_value           => l_segment
138343         , p_from_segment_code       => l_adr_value_segment_code
138344         , p_from_combination_id     => l_adr_value_combination_id
138345         , p_value_type_code         => l_adr_value_type_code
138346         , p_transaction_coa_id      => l_adr_transaction_coa_id
138347         , p_accounting_coa_id       => l_adr_accounting_coa_id
138348         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
138349         , p_flex_value_set_id       => l_adr_flex_value_set_id
138350         , p_adr_code                => 'FA_EXPENSE_ACCT'
138351         , p_adr_type_code           => 'S'
138352         , p_component_type          => l_component_type
138353         , p_component_code          => l_component_code
138354         , p_component_type_code     => l_component_type_code
138355         , p_component_appl_id       => l_component_appl_id
138356         , p_amb_context_code        => l_amb_context_code
138357         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
138358         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
138359         , p_side                    => 'NA'
138360         );
138361 
138362   END IF;
138363 
138364    --
138365    --
138366    END IF;
138367    --
138368    -- Bug 4922099
138369    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
138370           (NVL(l_enc_upg_option, 'N') = 'O')
138371         ) AND
138372         (l_bflow_method_code = 'PRIOR_ENTRY')
138373       )
138374    THEN
138375       IF
138376       --
138377       1 = 2
138378       --
138379       THEN
138380       xla_accounting_err_pkg.build_message
138381                                     (p_appli_s_name            => 'XLA'
138382                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
138383                                     ,p_token_1                 => 'LINE_NUMBER'
138384                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
138385                                     ,p_token_2                 => 'LINE_TYPE_NAME'
138386                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
138387                                                                              l_component_type
138391                                                                             ,l_amb_context_code
138388                                                                             ,l_component_code
138389                                                                             ,l_component_type_code
138390                                                                             ,l_component_appl_id
138392                                                                             ,l_entity_code
138393                                                                             ,l_event_class_code
138394                                                                            )
138395                                     ,p_token_3                 => 'OWNER'
138396                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
138397                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
138398                                                                           ,p_lookup_code    => l_component_type_code
138399                                                                          )
138400                                     ,p_token_4                 => 'PRODUCT_NAME'
138401                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
138402                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
138403                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
138404                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
138405                                     ,p_ae_header_id            =>  NULL
138406                                        );
138407 
138408         IF (C_LEVEL_ERROR>= g_log_level) THEN
138409                  trace
138410                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
138411                       ,p_level    => C_LEVEL_ERROR
138412                       ,p_module   => l_log_module);
138413         END IF;
138414       END IF;
138415    END IF;
138416    --
138417    --
138418    ------------------------------------------------------------------------------------------------
138419    -- 4219869 Business Flow
138420    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
138421    -- Prior Entry.  Currently, the following code is always generated.
138422    ------------------------------------------------------------------------------------------------
138423    XLA_AE_LINES_PKG.ValidateCurrentLine;
138424 
138425    ------------------------------------------------------------------------------------
138426    -- 4219869 Business Flow
138427    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
138428    ------------------------------------------------------------------------------------
138429    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
138430 
138431    ----------------------------------------------------------------------------------
138432    -- 4219869 Business Flow
138433    -- Update journal entry status -- Need to generate this within IF <condition>
138434    ----------------------------------------------------------------------------------
138435    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
138436          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
138437          ,p_balance_type_code => l_balance_type_code
138438          );
138439 
138440    -------------------------------------------------------------------------------------------
138441    -- 4262811 - Generate the Accrual Reversal lines
138442    -------------------------------------------------------------------------------------------
138443    BEGIN
138444       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
138445                               (g_array_event(p_event_id).array_value_num('header_index'));
138446       IF l_acc_rev_flag IS NULL THEN
138447          l_acc_rev_flag := 'N';
138448       END IF;
138449    EXCEPTION
138450       WHEN OTHERS THEN
138451          l_acc_rev_flag := 'N';
138452    END;
138453    --
138454    IF (l_acc_rev_flag = 'Y') THEN
138455 
138456        -- 4645092  ------------------------------------------------------------------------------
138457        -- To allow MPA report to determine if it should generate report process
138458        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
138459        ------------------------------------------------------------------------------------------
138460 
138461        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
138462        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
138463    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
138464    -- call ADRs
138465    -- Bug 4922099
138466    --
138467    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
138468         (NVL(l_actual_upg_option, 'N') = 'O') OR
138469         (NVL(l_enc_upg_option, 'N') = 'O')
138470       )
138471    THEN
138472    NULL;
138473    --
138474    --
138475    
138476   l_ccid := AcctDerRule_174(
138477            p_application_id           => p_application_id
138478          , p_ae_header_id             => l_ae_header_id 
138479 , p_source_3 => p_source_3
138480 , p_source_17 => p_source_17
138481 , p_source_30 => p_source_30
138482          , x_transaction_coa_id       => l_adr_transaction_coa_id
138483          , x_accounting_coa_id        => l_adr_accounting_coa_id
138484          , x_value_type_code          => l_adr_value_type_code
138485          , p_side                     => 'NA'
138486    );
138487 
138488    xla_ae_lines_pkg.set_ccid(
138489     p_code_combination_id          => l_ccid
138490   , p_value_type_code              => l_adr_value_type_code
138491   , p_transaction_coa_id           => l_adr_transaction_coa_id
138492   , p_accounting_coa_id            => l_adr_accounting_coa_id
138493   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
138497   , p_component_type_code          => l_component_type_code
138494   , p_adr_type_code                => 'S'
138495   , p_component_type               => l_component_type
138496   , p_component_code               => l_component_code
138498   , p_component_appl_id            => l_component_appl_id
138499   , p_amb_context_code             => l_amb_context_code
138500   , p_side                         => 'NA'
138501   );
138502 
138503 
138504    l_segment := AcctDerRule_150(
138505            p_application_id           => p_application_id
138506          , p_ae_header_id             => l_ae_header_id 
138507 , p_source_3 => p_source_3
138508 , p_source_11 => p_source_11
138509          , x_transaction_coa_id       => l_adr_transaction_coa_id
138510          , x_accounting_coa_id        => l_adr_accounting_coa_id
138511          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
138512          , x_flex_value_set_id        => l_adr_flex_value_set_id
138513          , x_value_type_code          => l_adr_value_type_code
138514          , x_value_combination_id     => l_adr_value_combination_id
138515          , x_value_segment_code       => l_adr_value_segment_code
138516          , p_side                     => 'NA'
138517          , p_override_seg_flag        => 'Y'
138518    );
138519 
138520    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
138521 
138522       xla_ae_lines_pkg.set_segment(
138523           p_to_segment_code         => 'GL_ACCOUNT'
138524         , p_segment_value           => l_segment
138525         , p_from_segment_code       => l_adr_value_segment_code
138526         , p_from_combination_id     => l_adr_value_combination_id
138527         , p_value_type_code         => l_adr_value_type_code
138528         , p_transaction_coa_id      => l_adr_transaction_coa_id
138529         , p_accounting_coa_id       => l_adr_accounting_coa_id
138530         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
138531         , p_flex_value_set_id       => l_adr_flex_value_set_id
138532         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
138533         , p_adr_type_code           => 'S'
138534         , p_component_type          => l_component_type
138535         , p_component_code          => l_component_code
138536         , p_component_type_code     => l_component_type_code
138537         , p_component_appl_id       => l_component_appl_id
138538         , p_amb_context_code        => l_amb_context_code
138539         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
138540         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
138541         , p_side                    => 'NA'
138542         );
138543 
138544   END IF;
138545 
138546    l_segment := AcctDerRule_168(
138547            p_application_id           => p_application_id
138548          , p_ae_header_id             => l_ae_header_id 
138549 , p_source_3 => p_source_3
138550 , p_source_29 => p_source_29
138551          , x_transaction_coa_id       => l_adr_transaction_coa_id
138552          , x_accounting_coa_id        => l_adr_accounting_coa_id
138553          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
138554          , x_flex_value_set_id        => l_adr_flex_value_set_id
138555          , x_value_type_code          => l_adr_value_type_code
138556          , x_value_combination_id     => l_adr_value_combination_id
138557          , x_value_segment_code       => l_adr_value_segment_code
138558          , p_side                     => 'NA'
138559          , p_override_seg_flag        => 'Y'
138560    );
138561 
138562    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
138563 
138564       xla_ae_lines_pkg.set_segment(
138565           p_to_segment_code         => 'GL_BALANCING'
138566         , p_segment_value           => l_segment
138567         , p_from_segment_code       => l_adr_value_segment_code
138568         , p_from_combination_id     => l_adr_value_combination_id
138569         , p_value_type_code         => l_adr_value_type_code
138570         , p_transaction_coa_id      => l_adr_transaction_coa_id
138571         , p_accounting_coa_id       => l_adr_accounting_coa_id
138572         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
138573         , p_flex_value_set_id       => l_adr_flex_value_set_id
138574         , p_adr_code                => 'FA_EXPENSE_ACCT'
138575         , p_adr_type_code           => 'S'
138576         , p_component_type          => l_component_type
138577         , p_component_code          => l_component_code
138578         , p_component_type_code     => l_component_type_code
138579         , p_component_appl_id       => l_component_appl_id
138580         , p_amb_context_code        => l_amb_context_code
138581         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
138582         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
138583         , p_side                    => 'NA'
138584         );
138585 
138586   END IF;
138587 
138588    --
138589    --
138590    END IF;
138591 
138592        --
138593        -- Update the line information that should be overwritten
138594        --
138595        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
138596                                          p_header_num   => 1);
138597        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
138598 
138599        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
138600 
138601        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
138602           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
138603        END IF;
138604 
138605       --
138606       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
138607       --
138608       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
138609           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
138610       ELSE
138614           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
138611           ---------------------------------------------------------------------------------------------------
138612           -- 4262811a Switch Sign
138613           ---------------------------------------------------------------------------------------------------
138615           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
138616                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
138617           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
138618                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
138619           -- 5132302
138620           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
138621                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
138622 
138623       END IF;
138624 
138625       -- 4955764
138626       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
138627       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
138628 
138629 
138630       XLA_AE_LINES_PKG.ValidateCurrentLine;
138631       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
138632 
138633       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
138634                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
138635                ,p_balance_type_code => l_balance_type_code);
138636 
138637    END IF;
138638 
138639    -----------------------------------------------------------------------------------------
138640    -- 4262811 Multiperiod Accounting
138641    -----------------------------------------------------------------------------------------
138642      -- No MPA option is assigned.
138643 
138644 
138645 END IF;
138646 END IF;
138647 --
138648 
138649 --
138650 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
138651    trace
138652       (p_msg      => 'END of AcctLineType_348'
138653       ,p_level    => C_LEVEL_PROCEDURE
138654       ,p_module   => l_log_module);
138655 END IF;
138656 --
138657 EXCEPTION
138658   WHEN xla_exceptions_pkg.application_exception THEN
138659       RAISE;
138660   WHEN OTHERS THEN
138661        xla_exceptions_pkg.raise_message
138662            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_348');
138663 END AcctLineType_348;
138664 --
138665 
138666 ---------------------------------------
138667 --
138668 -- PRIVATE FUNCTION
138669 --         AcctLineType_349
138670 --
138671 ---------------------------------------
138672 PROCEDURE AcctLineType_349 (
138673   p_application_id        IN NUMBER
138674  ,p_event_id              IN NUMBER
138675  ,p_calculate_acctd_flag  IN VARCHAR2
138676  ,p_calculate_g_l_flag    IN VARCHAR2
138677  ,p_actual_flag           IN OUT VARCHAR2
138678  ,p_balance_type_code     OUT VARCHAR2
138679  ,p_gain_or_loss_ref      OUT VARCHAR2
138680  
138681 --Period Close Date
138682  , p_source_1            IN DATE
138683 --Generated Code Combination Identifier
138684  , p_source_3            IN NUMBER
138685 --Intercompany Payables Account
138686  , p_source_19            IN VARCHAR2
138687 --Expense Account Code Combination Identifier
138688  , p_source_29            IN NUMBER
138689 --Default Code Combination Identifier
138690  , p_source_30            IN NUMBER
138691 --Adjustment Type
138692  , p_source_35            IN VARCHAR2
138693 --Transaction Header Identifier
138694  , p_source_36            IN NUMBER
138695 --Adjustment Line Identifier
138696  , p_source_37            IN NUMBER
138697 --Distribution Type Code
138698  , p_source_38            IN VARCHAR2
138699 --Entered Amount
138700  , p_source_39            IN NUMBER
138701 --Currency Code
138702  , p_source_40            IN VARCHAR2
138703 )
138704 IS
138705 
138706 l_component_type              VARCHAR2(80);
138707 l_component_code              VARCHAR2(30);
138708 l_component_type_code         VARCHAR2(1);
138709 l_component_appl_id           INTEGER;
138710 l_amb_context_code            VARCHAR2(30);
138711 l_entity_code                 VARCHAR2(30);
138712 l_event_class_code            VARCHAR2(30);
138713 l_ae_header_id                NUMBER;
138714 l_event_type_code             VARCHAR2(30);
138715 l_line_definition_code        VARCHAR2(30);
138716 l_line_definition_owner_code  VARCHAR2(1);
138717 --
138718 -- adr variables
138719 l_segment                     VARCHAR2(30);
138720 l_ccid                        NUMBER;
138721 l_adr_transaction_coa_id      NUMBER;
138722 l_adr_accounting_coa_id       NUMBER;
138723 l_adr_flexfield_segment_code  VARCHAR2(30);
138724 l_adr_flex_value_set_id       NUMBER;
138725 l_adr_value_type_code         VARCHAR2(30);
138726 l_adr_value_combination_id    NUMBER;
138727 l_adr_value_segment_code      VARCHAR2(30);
138728 
138729 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
138730 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
138731 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
138732 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
138733 
138734 -- 4262811 Variables ------------------------------------------------------------------------------------------
138735 l_entered_amt_idx             NUMBER;
138736 l_accted_amt_idx              NUMBER;
138737 l_acc_rev_flag                VARCHAR2(1);
138738 l_accrual_line_num            NUMBER;
138739 l_tmp_amt                     NUMBER;
138740 l_acc_rev_natural_side_code   VARCHAR2(1);
138741 
138742 l_num_entries                 NUMBER;
138743 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
138744 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
138748 l_recog_line_2                NUMBER;
138745 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
138746 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
138747 l_recog_line_1                NUMBER;
138749 
138750 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
138751 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
138752 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
138753 
138754 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
138755 
138756 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
138757 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
138758 
138759 ---------------------------------------------------------------------------------------------------------------
138760 
138761 
138762 --
138763 -- bulk performance
138764 --
138765 l_balance_type_code           VARCHAR2(1);
138766 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
138767 l_log_module                  VARCHAR2(240);
138768 
138769 --
138770 -- Upgrade strategy
138771 --
138772 l_actual_upg_option           VARCHAR2(1);
138773 l_enc_upg_option           VARCHAR2(1);
138774 
138775 --
138776 BEGIN
138777 --
138778 IF g_log_enabled THEN
138779       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_349';
138780 END IF;
138781 --
138782 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
138783 
138784       trace
138785          (p_msg      => 'BEGIN of AcctLineType_349'
138786          ,p_level    => C_LEVEL_PROCEDURE
138787          ,p_module   => l_log_module);
138788 
138789 END IF;
138790 --
138791 l_component_type             := 'AMB_JLT';
138792 l_component_code             := 'FA_SLT_IC_PAY';
138793 l_component_type_code        := 'S';
138794 l_component_appl_id          :=  140;
138795 l_amb_context_code           := 'DEFAULT';
138796 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
138797 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
138798 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
138799 l_line_definition_owner_code := 'S';
138800 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
138801 --
138802 l_balance_type_code          := 'A';
138803 l_segment                     := NULL;
138804 l_ccid                        := NULL;
138805 l_adr_transaction_coa_id      := NULL;
138806 l_adr_accounting_coa_id       := NULL;
138807 l_adr_flexfield_segment_code  := NULL;
138808 l_adr_flex_value_set_id       := NULL;
138809 l_adr_value_type_code         := NULL;
138810 l_adr_value_combination_id    := NULL;
138811 l_adr_value_segment_code      := NULL;
138812 
138813 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
138814 l_bflow_class_code           := '';    -- 4219869 Business Flow
138815 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
138816 l_budgetary_control_flag     := 'N';
138817 
138818 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
138819 l_bflow_applied_to_amt       := NULL; -- 5132302
138820 l_entered_amt_idx            := NULL;          -- 4262811
138821 l_accted_amt_idx             := NULL;          -- 4262811
138822 l_acc_rev_flag               := NULL;          -- 4262811
138823 l_accrual_line_num           := NULL;          -- 4262811
138824 l_tmp_amt                    := NULL;          -- 4262811
138825 --
138826  
138827 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
138828     l_balance_type_code <> 'B' THEN
138829 IF NVL(p_source_35,'
138830 ') =  'INTERCO AP'
138831  THEN 
138832 
138833    --
138834    XLA_AE_LINES_PKG.SetNewLine;
138835 
138836    p_balance_type_code          := l_balance_type_code;
138837    -- set the flag so later we will know whether the gain loss line needs to be created
138838    
138839    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
138840      p_actual_flag :='A';
138841    END IF;
138842 
138843    --
138844    -- bulk performance
138845    --
138846    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
138847                                       p_header_num   => 0); -- 4262811
138848    --
138849    -- set accounting line options
138850    --
138851    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
138852            p_natural_side_code          => 'C'
138853          , p_gain_or_loss_flag          => 'N'
138854          , p_gl_transfer_mode_code      => 'S'
138855          , p_acct_entry_type_code       => 'A'
138856          , p_switch_side_flag           => 'Y'
138857          , p_merge_duplicate_code       => 'N'
138858          );
138859    --
138860    l_acc_rev_natural_side_code := 'D';  -- 4262811
138861    -- 
138862    --
138863    -- set accounting line type info
138864    --
138865    xla_ae_lines_pkg.SetAcctLineType
138866       (p_component_type             => l_component_type
138867       ,p_event_type_code            => l_event_type_code
138868       ,p_line_definition_owner_code => l_line_definition_owner_code
138869       ,p_line_definition_code       => l_line_definition_code
138870       ,p_accounting_line_code       => l_component_code
138871       ,p_accounting_line_type_code  => l_component_type_code
138872       ,p_accounting_line_appl_id    => l_component_appl_id
138873       ,p_amb_context_code           => l_amb_context_code
138874       ,p_entity_code                => l_entity_code
138875       ,p_event_class_code           => l_event_class_code);
138876    --
138877    -- set accounting class
138878    --
138879    xla_ae_lines_pkg.SetAcctClass(
138880            p_accounting_class_code  => 'LIABILITY'
138881          , p_ae_header_id           => l_ae_header_id
138882          );
138883 
138884    --
138885    -- set rounding class
138886    --
138890    --
138887    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
138888                       'LIABILITY';
138889 
138891    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
138892    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
138893    --
138894    -- bulk performance
138895    --
138896    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
138897 
138898    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
138899       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
138900 
138901    -- 4955764
138902    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
138903       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
138904 
138905    -- 4458381 Public Sector Enh
138906    
138907    --
138908    -- set accounting attributes for the line type
138909    --
138910    l_entered_amt_idx := 4;
138911    l_accted_amt_idx  := 6;
138912    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
138913    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
138914    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
138915    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
138916    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
138917    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
138918    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
138919    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
138920    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
138921    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
138922    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
138923    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
138924    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
138925 
138926    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
138927    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
138928 
138929    ---------------------------------------------------------------------------------------------------------------
138930    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
138931    ---------------------------------------------------------------------------------------------------------------
138932    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
138933 
138934    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
138935    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
138936 
138937    IF xla_accounting_cache_pkg.GetValueChar
138938          (p_source_code         => 'LEDGER_CATEGORY_CODE'
138939          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
138940    AND l_bflow_method_code = 'PRIOR_ENTRY'
138941 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
138942    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
138943          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
138944        )
138945    THEN
138946          xla_ae_lines_pkg.BflowUpgEntry
138947            (p_business_method_code    => l_bflow_method_code
138948            ,p_business_class_code     => l_bflow_class_code
138949            ,p_balance_type            => l_balance_type_code);
138950    ELSE
138951       NULL;
138952 -- No business flow processing for business flow method of NONE.
138953    END IF;
138954 
138955    --
138956    -- call analytical criteria
138957    --
138958    
138959    --
138960    -- call description
138961    --
138962    
138963 xla_ae_lines_pkg.SetLineDescription(
138964    p_ae_header_id => l_ae_header_id
138965   ,p_description  => Description_114 (
138966      p_application_id         => p_application_id
138967    , p_ae_header_id           => l_ae_header_id 
138968 , p_source_1 => p_source_1
138969    )
138970 );
138971 
138972 
138973    --
138974    -- call ADRs
138975    -- Bug 4922099
138976    --
138977    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
138978         (NVL(l_actual_upg_option, 'N') = 'O') OR
138979         (NVL(l_enc_upg_option, 'N') = 'O')
138980       )
138981    THEN
138982    NULL;
138983    --
138984    --
138985    
138986   l_ccid := AcctDerRule_173(
138987            p_application_id           => p_application_id
138988          , p_ae_header_id             => l_ae_header_id 
138989 , p_source_3 => p_source_3
138990 , p_source_30 => p_source_30
138991          , x_transaction_coa_id       => l_adr_transaction_coa_id
138992          , x_accounting_coa_id        => l_adr_accounting_coa_id
138993          , x_value_type_code          => l_adr_value_type_code
138994          , p_side                     => 'NA'
138995    );
138996 
138997    xla_ae_lines_pkg.set_ccid(
138998     p_code_combination_id          => l_ccid
138999   , p_value_type_code              => l_adr_value_type_code
139000   , p_transaction_coa_id           => l_adr_transaction_coa_id
139001   , p_accounting_coa_id            => l_adr_accounting_coa_id
139002   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
139003   , p_adr_type_code                => 'S'
139004   , p_component_type               => l_component_type
139005   , p_component_code               => l_component_code
139006   , p_component_type_code          => l_component_type_code
139007   , p_component_appl_id            => l_component_appl_id
139008   , p_amb_context_code             => l_amb_context_code
139009   , p_side                         => 'NA'
139010   );
139011 
139012 
139013    l_segment := AcctDerRule_168(
139017 , p_source_29 => p_source_29
139014            p_application_id           => p_application_id
139015          , p_ae_header_id             => l_ae_header_id 
139016 , p_source_3 => p_source_3
139018          , x_transaction_coa_id       => l_adr_transaction_coa_id
139019          , x_accounting_coa_id        => l_adr_accounting_coa_id
139020          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
139021          , x_flex_value_set_id        => l_adr_flex_value_set_id
139022          , x_value_type_code          => l_adr_value_type_code
139023          , x_value_combination_id     => l_adr_value_combination_id
139024          , x_value_segment_code       => l_adr_value_segment_code
139025          , p_side                     => 'NA'
139026          , p_override_seg_flag        => 'Y'
139027    );
139028 
139029    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
139030 
139031       xla_ae_lines_pkg.set_segment(
139032           p_to_segment_code         => 'GL_BALANCING'
139033         , p_segment_value           => l_segment
139034         , p_from_segment_code       => l_adr_value_segment_code
139035         , p_from_combination_id     => l_adr_value_combination_id
139036         , p_value_type_code         => l_adr_value_type_code
139037         , p_transaction_coa_id      => l_adr_transaction_coa_id
139038         , p_accounting_coa_id       => l_adr_accounting_coa_id
139039         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
139040         , p_flex_value_set_id       => l_adr_flex_value_set_id
139041         , p_adr_code                => 'FA_EXPENSE_ACCT'
139042         , p_adr_type_code           => 'S'
139043         , p_component_type          => l_component_type
139044         , p_component_code          => l_component_code
139045         , p_component_type_code     => l_component_type_code
139046         , p_component_appl_id       => l_component_appl_id
139047         , p_amb_context_code        => l_amb_context_code
139048         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
139049         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
139050         , p_side                    => 'NA'
139051         );
139052 
139053   END IF;
139054 
139055    l_segment := AcctDerRule_157(
139056            p_application_id           => p_application_id
139057          , p_ae_header_id             => l_ae_header_id 
139058 , p_source_3 => p_source_3
139059 , p_source_19 => p_source_19
139060          , x_transaction_coa_id       => l_adr_transaction_coa_id
139061          , x_accounting_coa_id        => l_adr_accounting_coa_id
139062          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
139063          , x_flex_value_set_id        => l_adr_flex_value_set_id
139064          , x_value_type_code          => l_adr_value_type_code
139065          , x_value_combination_id     => l_adr_value_combination_id
139066          , x_value_segment_code       => l_adr_value_segment_code
139067          , p_side                     => 'NA'
139068          , p_override_seg_flag        => 'Y'
139069    );
139070 
139071    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
139072 
139073       xla_ae_lines_pkg.set_segment(
139074           p_to_segment_code         => 'GL_ACCOUNT'
139075         , p_segment_value           => l_segment
139076         , p_from_segment_code       => l_adr_value_segment_code
139077         , p_from_combination_id     => l_adr_value_combination_id
139078         , p_value_type_code         => l_adr_value_type_code
139079         , p_transaction_coa_id      => l_adr_transaction_coa_id
139080         , p_accounting_coa_id       => l_adr_accounting_coa_id
139081         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
139082         , p_flex_value_set_id       => l_adr_flex_value_set_id
139083         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
139084         , p_adr_type_code           => 'S'
139085         , p_component_type          => l_component_type
139086         , p_component_code          => l_component_code
139087         , p_component_type_code     => l_component_type_code
139088         , p_component_appl_id       => l_component_appl_id
139089         , p_amb_context_code        => l_amb_context_code
139090         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
139091         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
139092         , p_side                    => 'NA'
139093         );
139094 
139095   END IF;
139096 
139097    --
139098    --
139099    END IF;
139100    --
139101    -- Bug 4922099
139102    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
139103           (NVL(l_enc_upg_option, 'N') = 'O')
139104         ) AND
139105         (l_bflow_method_code = 'PRIOR_ENTRY')
139106       )
139107    THEN
139108       IF
139109       --
139110       1 = 2
139111       --
139112       THEN
139113       xla_accounting_err_pkg.build_message
139114                                     (p_appli_s_name            => 'XLA'
139115                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
139116                                     ,p_token_1                 => 'LINE_NUMBER'
139117                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
139118                                     ,p_token_2                 => 'LINE_TYPE_NAME'
139119                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
139120                                                                              l_component_type
139121                                                                             ,l_component_code
139122                                                                             ,l_component_type_code
139123                                                                             ,l_component_appl_id
139124                                                                             ,l_amb_context_code
139125                                                                             ,l_entity_code
139129                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
139126                                                                             ,l_event_class_code
139127                                                                            )
139128                                     ,p_token_3                 => 'OWNER'
139130                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
139131                                                                           ,p_lookup_code    => l_component_type_code
139132                                                                          )
139133                                     ,p_token_4                 => 'PRODUCT_NAME'
139134                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
139135                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
139136                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
139137                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
139138                                     ,p_ae_header_id            =>  NULL
139139                                        );
139140 
139141         IF (C_LEVEL_ERROR>= g_log_level) THEN
139142                  trace
139143                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
139144                       ,p_level    => C_LEVEL_ERROR
139145                       ,p_module   => l_log_module);
139146         END IF;
139147       END IF;
139148    END IF;
139149    --
139150    --
139151    ------------------------------------------------------------------------------------------------
139152    -- 4219869 Business Flow
139153    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
139154    -- Prior Entry.  Currently, the following code is always generated.
139155    ------------------------------------------------------------------------------------------------
139156    XLA_AE_LINES_PKG.ValidateCurrentLine;
139157 
139158    ------------------------------------------------------------------------------------
139159    -- 4219869 Business Flow
139160    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
139161    ------------------------------------------------------------------------------------
139162    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
139163 
139164    ----------------------------------------------------------------------------------
139165    -- 4219869 Business Flow
139166    -- Update journal entry status -- Need to generate this within IF <condition>
139167    ----------------------------------------------------------------------------------
139168    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
139169          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
139170          ,p_balance_type_code => l_balance_type_code
139171          );
139172 
139173    -------------------------------------------------------------------------------------------
139174    -- 4262811 - Generate the Accrual Reversal lines
139175    -------------------------------------------------------------------------------------------
139176    BEGIN
139177       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
139178                               (g_array_event(p_event_id).array_value_num('header_index'));
139179       IF l_acc_rev_flag IS NULL THEN
139180          l_acc_rev_flag := 'N';
139181       END IF;
139182    EXCEPTION
139183       WHEN OTHERS THEN
139184          l_acc_rev_flag := 'N';
139185    END;
139186    --
139187    IF (l_acc_rev_flag = 'Y') THEN
139188 
139189        -- 4645092  ------------------------------------------------------------------------------
139190        -- To allow MPA report to determine if it should generate report process
139191        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
139192        ------------------------------------------------------------------------------------------
139193 
139194        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
139195        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
139196    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
139197    -- call ADRs
139198    -- Bug 4922099
139199    --
139200    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
139201         (NVL(l_actual_upg_option, 'N') = 'O') OR
139202         (NVL(l_enc_upg_option, 'N') = 'O')
139203       )
139204    THEN
139205    NULL;
139206    --
139207    --
139208    
139209   l_ccid := AcctDerRule_173(
139210            p_application_id           => p_application_id
139211          , p_ae_header_id             => l_ae_header_id 
139212 , p_source_3 => p_source_3
139213 , p_source_30 => p_source_30
139214          , x_transaction_coa_id       => l_adr_transaction_coa_id
139215          , x_accounting_coa_id        => l_adr_accounting_coa_id
139216          , x_value_type_code          => l_adr_value_type_code
139217          , p_side                     => 'NA'
139218    );
139219 
139220    xla_ae_lines_pkg.set_ccid(
139221     p_code_combination_id          => l_ccid
139222   , p_value_type_code              => l_adr_value_type_code
139223   , p_transaction_coa_id           => l_adr_transaction_coa_id
139224   , p_accounting_coa_id            => l_adr_accounting_coa_id
139225   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
139226   , p_adr_type_code                => 'S'
139227   , p_component_type               => l_component_type
139228   , p_component_code               => l_component_code
139229   , p_component_type_code          => l_component_type_code
139230   , p_component_appl_id            => l_component_appl_id
139231   , p_amb_context_code             => l_amb_context_code
139232   , p_side                         => 'NA'
139233   );
139234 
139235 
139236    l_segment := AcctDerRule_168(
139240 , p_source_29 => p_source_29
139237            p_application_id           => p_application_id
139238          , p_ae_header_id             => l_ae_header_id 
139239 , p_source_3 => p_source_3
139241          , x_transaction_coa_id       => l_adr_transaction_coa_id
139242          , x_accounting_coa_id        => l_adr_accounting_coa_id
139243          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
139244          , x_flex_value_set_id        => l_adr_flex_value_set_id
139245          , x_value_type_code          => l_adr_value_type_code
139246          , x_value_combination_id     => l_adr_value_combination_id
139247          , x_value_segment_code       => l_adr_value_segment_code
139248          , p_side                     => 'NA'
139249          , p_override_seg_flag        => 'Y'
139250    );
139251 
139252    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
139253 
139254       xla_ae_lines_pkg.set_segment(
139255           p_to_segment_code         => 'GL_BALANCING'
139256         , p_segment_value           => l_segment
139257         , p_from_segment_code       => l_adr_value_segment_code
139258         , p_from_combination_id     => l_adr_value_combination_id
139259         , p_value_type_code         => l_adr_value_type_code
139260         , p_transaction_coa_id      => l_adr_transaction_coa_id
139261         , p_accounting_coa_id       => l_adr_accounting_coa_id
139262         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
139263         , p_flex_value_set_id       => l_adr_flex_value_set_id
139264         , p_adr_code                => 'FA_EXPENSE_ACCT'
139265         , p_adr_type_code           => 'S'
139266         , p_component_type          => l_component_type
139267         , p_component_code          => l_component_code
139268         , p_component_type_code     => l_component_type_code
139269         , p_component_appl_id       => l_component_appl_id
139270         , p_amb_context_code        => l_amb_context_code
139271         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
139272         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
139273         , p_side                    => 'NA'
139274         );
139275 
139276   END IF;
139277 
139278    l_segment := AcctDerRule_157(
139279            p_application_id           => p_application_id
139280          , p_ae_header_id             => l_ae_header_id 
139281 , p_source_3 => p_source_3
139282 , p_source_19 => p_source_19
139283          , x_transaction_coa_id       => l_adr_transaction_coa_id
139284          , x_accounting_coa_id        => l_adr_accounting_coa_id
139285          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
139286          , x_flex_value_set_id        => l_adr_flex_value_set_id
139287          , x_value_type_code          => l_adr_value_type_code
139288          , x_value_combination_id     => l_adr_value_combination_id
139289          , x_value_segment_code       => l_adr_value_segment_code
139290          , p_side                     => 'NA'
139291          , p_override_seg_flag        => 'Y'
139292    );
139293 
139294    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
139295 
139296       xla_ae_lines_pkg.set_segment(
139297           p_to_segment_code         => 'GL_ACCOUNT'
139298         , p_segment_value           => l_segment
139299         , p_from_segment_code       => l_adr_value_segment_code
139300         , p_from_combination_id     => l_adr_value_combination_id
139301         , p_value_type_code         => l_adr_value_type_code
139302         , p_transaction_coa_id      => l_adr_transaction_coa_id
139303         , p_accounting_coa_id       => l_adr_accounting_coa_id
139304         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
139305         , p_flex_value_set_id       => l_adr_flex_value_set_id
139306         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
139307         , p_adr_type_code           => 'S'
139308         , p_component_type          => l_component_type
139309         , p_component_code          => l_component_code
139310         , p_component_type_code     => l_component_type_code
139311         , p_component_appl_id       => l_component_appl_id
139312         , p_amb_context_code        => l_amb_context_code
139313         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
139314         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
139315         , p_side                    => 'NA'
139316         );
139317 
139318   END IF;
139319 
139320    --
139321    --
139322    END IF;
139323 
139324        --
139325        -- Update the line information that should be overwritten
139326        --
139327        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
139328                                          p_header_num   => 1);
139329        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
139330 
139331        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
139332 
139333        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
139334           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
139335        END IF;
139336 
139337       --
139338       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
139339       --
139340       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
139341           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
139342       ELSE
139343           ---------------------------------------------------------------------------------------------------
139344           -- 4262811a Switch Sign
139345           ---------------------------------------------------------------------------------------------------
139346           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
139347           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
139351           -- 5132302
139348                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
139349           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
139350                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
139352           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
139353                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
139354 
139355       END IF;
139356 
139357       -- 4955764
139358       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
139359       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
139360 
139361 
139362       XLA_AE_LINES_PKG.ValidateCurrentLine;
139363       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
139364 
139365       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
139366                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
139367                ,p_balance_type_code => l_balance_type_code);
139368 
139369    END IF;
139370 
139371    -----------------------------------------------------------------------------------------
139372    -- 4262811 Multiperiod Accounting
139373    -----------------------------------------------------------------------------------------
139374      -- No MPA option is assigned.
139375 
139376 
139377 END IF;
139378 END IF;
139379 --
139380 
139381 --
139382 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
139383    trace
139384       (p_msg      => 'END of AcctLineType_349'
139385       ,p_level    => C_LEVEL_PROCEDURE
139386       ,p_module   => l_log_module);
139387 END IF;
139388 --
139389 EXCEPTION
139390   WHEN xla_exceptions_pkg.application_exception THEN
139391       RAISE;
139392   WHEN OTHERS THEN
139393        xla_exceptions_pkg.raise_message
139394            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_349');
139395 END AcctLineType_349;
139396 --
139397 
139398 ---------------------------------------
139399 --
139400 -- PRIVATE FUNCTION
139401 --         AcctLineType_350
139402 --
139403 ---------------------------------------
139404 PROCEDURE AcctLineType_350 (
139405   p_application_id        IN NUMBER
139406  ,p_event_id              IN NUMBER
139407  ,p_calculate_acctd_flag  IN VARCHAR2
139408  ,p_calculate_g_l_flag    IN VARCHAR2
139409  ,p_actual_flag           IN OUT VARCHAR2
139410  ,p_balance_type_code     OUT VARCHAR2
139411  ,p_gain_or_loss_ref      OUT VARCHAR2
139412  
139413 --Period Close Date
139414  , p_source_1            IN DATE
139415 --Generated Code Combination Identifier
139416  , p_source_3            IN NUMBER
139417 --Intercompany Receivables Account
139418  , p_source_20            IN VARCHAR2
139419 --Expense Account Code Combination Identifier
139420  , p_source_29            IN NUMBER
139421 --Default Code Combination Identifier
139422  , p_source_30            IN NUMBER
139423 --Adjustment Type
139424  , p_source_35            IN VARCHAR2
139425 --Transaction Header Identifier
139426  , p_source_36            IN NUMBER
139427 --Adjustment Line Identifier
139428  , p_source_37            IN NUMBER
139429 --Distribution Type Code
139430  , p_source_38            IN VARCHAR2
139431 --Entered Amount
139432  , p_source_39            IN NUMBER
139433 --Currency Code
139434  , p_source_40            IN VARCHAR2
139435 )
139436 IS
139437 
139438 l_component_type              VARCHAR2(80);
139439 l_component_code              VARCHAR2(30);
139440 l_component_type_code         VARCHAR2(1);
139441 l_component_appl_id           INTEGER;
139442 l_amb_context_code            VARCHAR2(30);
139443 l_entity_code                 VARCHAR2(30);
139444 l_event_class_code            VARCHAR2(30);
139445 l_ae_header_id                NUMBER;
139446 l_event_type_code             VARCHAR2(30);
139447 l_line_definition_code        VARCHAR2(30);
139448 l_line_definition_owner_code  VARCHAR2(1);
139449 --
139450 -- adr variables
139451 l_segment                     VARCHAR2(30);
139452 l_ccid                        NUMBER;
139453 l_adr_transaction_coa_id      NUMBER;
139454 l_adr_accounting_coa_id       NUMBER;
139455 l_adr_flexfield_segment_code  VARCHAR2(30);
139456 l_adr_flex_value_set_id       NUMBER;
139457 l_adr_value_type_code         VARCHAR2(30);
139458 l_adr_value_combination_id    NUMBER;
139459 l_adr_value_segment_code      VARCHAR2(30);
139460 
139461 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
139462 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
139463 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
139464 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
139465 
139466 -- 4262811 Variables ------------------------------------------------------------------------------------------
139467 l_entered_amt_idx             NUMBER;
139468 l_accted_amt_idx              NUMBER;
139469 l_acc_rev_flag                VARCHAR2(1);
139470 l_accrual_line_num            NUMBER;
139471 l_tmp_amt                     NUMBER;
139472 l_acc_rev_natural_side_code   VARCHAR2(1);
139473 
139474 l_num_entries                 NUMBER;
139475 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
139476 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
139477 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
139478 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
139479 l_recog_line_1                NUMBER;
139480 l_recog_line_2                NUMBER;
139481 
139482 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
139483 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
139484 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
139488 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
139485 
139486 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
139487 
139489 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
139490 
139491 ---------------------------------------------------------------------------------------------------------------
139492 
139493 
139494 --
139495 -- bulk performance
139496 --
139497 l_balance_type_code           VARCHAR2(1);
139498 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
139499 l_log_module                  VARCHAR2(240);
139500 
139501 --
139502 -- Upgrade strategy
139503 --
139504 l_actual_upg_option           VARCHAR2(1);
139505 l_enc_upg_option           VARCHAR2(1);
139506 
139507 --
139508 BEGIN
139509 --
139510 IF g_log_enabled THEN
139511       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_350';
139512 END IF;
139513 --
139514 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
139515 
139516       trace
139517          (p_msg      => 'BEGIN of AcctLineType_350'
139518          ,p_level    => C_LEVEL_PROCEDURE
139519          ,p_module   => l_log_module);
139520 
139521 END IF;
139522 --
139523 l_component_type             := 'AMB_JLT';
139524 l_component_code             := 'FA_SLT_IC_REC';
139525 l_component_type_code        := 'S';
139526 l_component_appl_id          :=  140;
139527 l_amb_context_code           := 'DEFAULT';
139528 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
139529 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
139530 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
139531 l_line_definition_owner_code := 'S';
139532 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
139533 --
139534 l_balance_type_code          := 'A';
139535 l_segment                     := NULL;
139536 l_ccid                        := NULL;
139537 l_adr_transaction_coa_id      := NULL;
139538 l_adr_accounting_coa_id       := NULL;
139539 l_adr_flexfield_segment_code  := NULL;
139540 l_adr_flex_value_set_id       := NULL;
139541 l_adr_value_type_code         := NULL;
139542 l_adr_value_combination_id    := NULL;
139543 l_adr_value_segment_code      := NULL;
139544 
139545 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
139546 l_bflow_class_code           := '';    -- 4219869 Business Flow
139547 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
139548 l_budgetary_control_flag     := 'N';
139549 
139550 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
139551 l_bflow_applied_to_amt       := NULL; -- 5132302
139552 l_entered_amt_idx            := NULL;          -- 4262811
139553 l_accted_amt_idx             := NULL;          -- 4262811
139554 l_acc_rev_flag               := NULL;          -- 4262811
139555 l_accrual_line_num           := NULL;          -- 4262811
139556 l_tmp_amt                    := NULL;          -- 4262811
139557 --
139558  
139559 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
139560     l_balance_type_code <> 'B' THEN
139561 IF NVL(p_source_35,'
139562 ') =  'INTERCO AR'
139563  THEN 
139564 
139565    --
139566    XLA_AE_LINES_PKG.SetNewLine;
139567 
139568    p_balance_type_code          := l_balance_type_code;
139569    -- set the flag so later we will know whether the gain loss line needs to be created
139570    
139571    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
139572      p_actual_flag :='A';
139573    END IF;
139574 
139575    --
139576    -- bulk performance
139577    --
139578    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
139579                                       p_header_num   => 0); -- 4262811
139580    --
139581    -- set accounting line options
139582    --
139583    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
139584            p_natural_side_code          => 'D'
139585          , p_gain_or_loss_flag          => 'N'
139586          , p_gl_transfer_mode_code      => 'S'
139587          , p_acct_entry_type_code       => 'A'
139588          , p_switch_side_flag           => 'Y'
139589          , p_merge_duplicate_code       => 'N'
139590          );
139591    --
139592    l_acc_rev_natural_side_code := 'C';  -- 4262811
139593    -- 
139594    --
139595    -- set accounting line type info
139596    --
139597    xla_ae_lines_pkg.SetAcctLineType
139598       (p_component_type             => l_component_type
139599       ,p_event_type_code            => l_event_type_code
139600       ,p_line_definition_owner_code => l_line_definition_owner_code
139601       ,p_line_definition_code       => l_line_definition_code
139602       ,p_accounting_line_code       => l_component_code
139603       ,p_accounting_line_type_code  => l_component_type_code
139604       ,p_accounting_line_appl_id    => l_component_appl_id
139605       ,p_amb_context_code           => l_amb_context_code
139606       ,p_entity_code                => l_entity_code
139607       ,p_event_class_code           => l_event_class_code);
139608    --
139609    -- set accounting class
139610    --
139611    xla_ae_lines_pkg.SetAcctClass(
139612            p_accounting_class_code  => 'ASSET'
139613          , p_ae_header_id           => l_ae_header_id
139614          );
139615 
139616    --
139617    -- set rounding class
139618    --
139619    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
139620                       'ASSET';
139621 
139622    --
139623    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
139624    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
139625    --
139626    -- bulk performance
139627    --
139631       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
139628    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
139629 
139630    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
139632 
139633    -- 4955764
139634    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
139635       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
139636 
139637    -- 4458381 Public Sector Enh
139638    
139639    --
139640    -- set accounting attributes for the line type
139641    --
139642    l_entered_amt_idx := 4;
139643    l_accted_amt_idx  := 6;
139644    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
139645    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
139646    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
139647    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
139648    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
139649    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
139650    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
139651    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
139652    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
139653    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
139654    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
139655    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
139656    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
139657 
139658    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
139659    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
139660 
139661    ---------------------------------------------------------------------------------------------------------------
139662    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
139663    ---------------------------------------------------------------------------------------------------------------
139664    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
139665 
139666    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
139667    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
139668 
139669    IF xla_accounting_cache_pkg.GetValueChar
139670          (p_source_code         => 'LEDGER_CATEGORY_CODE'
139671          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
139672    AND l_bflow_method_code = 'PRIOR_ENTRY'
139673 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
139674    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
139675          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
139676        )
139677    THEN
139678          xla_ae_lines_pkg.BflowUpgEntry
139679            (p_business_method_code    => l_bflow_method_code
139680            ,p_business_class_code     => l_bflow_class_code
139681            ,p_balance_type            => l_balance_type_code);
139682    ELSE
139683       NULL;
139684 -- No business flow processing for business flow method of NONE.
139685    END IF;
139686 
139687    --
139688    -- call analytical criteria
139689    --
139690    
139691    --
139692    -- call description
139693    --
139694    
139695 xla_ae_lines_pkg.SetLineDescription(
139696    p_ae_header_id => l_ae_header_id
139697   ,p_description  => Description_115 (
139698      p_application_id         => p_application_id
139699    , p_ae_header_id           => l_ae_header_id 
139700 , p_source_1 => p_source_1
139701    )
139702 );
139703 
139704 
139705    --
139706    -- call ADRs
139707    -- Bug 4922099
139708    --
139709    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
139710         (NVL(l_actual_upg_option, 'N') = 'O') OR
139711         (NVL(l_enc_upg_option, 'N') = 'O')
139712       )
139713    THEN
139714    NULL;
139715    --
139716    --
139717    
139718   l_ccid := AcctDerRule_173(
139719            p_application_id           => p_application_id
139720          , p_ae_header_id             => l_ae_header_id 
139721 , p_source_3 => p_source_3
139722 , p_source_30 => p_source_30
139723          , x_transaction_coa_id       => l_adr_transaction_coa_id
139724          , x_accounting_coa_id        => l_adr_accounting_coa_id
139725          , x_value_type_code          => l_adr_value_type_code
139726          , p_side                     => 'NA'
139727    );
139728 
139729    xla_ae_lines_pkg.set_ccid(
139730     p_code_combination_id          => l_ccid
139731   , p_value_type_code              => l_adr_value_type_code
139732   , p_transaction_coa_id           => l_adr_transaction_coa_id
139733   , p_accounting_coa_id            => l_adr_accounting_coa_id
139734   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
139735   , p_adr_type_code                => 'S'
139736   , p_component_type               => l_component_type
139737   , p_component_code               => l_component_code
139738   , p_component_type_code          => l_component_type_code
139739   , p_component_appl_id            => l_component_appl_id
139740   , p_amb_context_code             => l_amb_context_code
139741   , p_side                         => 'NA'
139742   );
139743 
139744 
139745    l_segment := AcctDerRule_168(
139746            p_application_id           => p_application_id
139747          , p_ae_header_id             => l_ae_header_id 
139748 , p_source_3 => p_source_3
139749 , p_source_29 => p_source_29
139750          , x_transaction_coa_id       => l_adr_transaction_coa_id
139751          , x_accounting_coa_id        => l_adr_accounting_coa_id
139752          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
139753          , x_flex_value_set_id        => l_adr_flex_value_set_id
139757          , p_side                     => 'NA'
139754          , x_value_type_code          => l_adr_value_type_code
139755          , x_value_combination_id     => l_adr_value_combination_id
139756          , x_value_segment_code       => l_adr_value_segment_code
139758          , p_override_seg_flag        => 'Y'
139759    );
139760 
139761    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
139762 
139763       xla_ae_lines_pkg.set_segment(
139764           p_to_segment_code         => 'GL_BALANCING'
139765         , p_segment_value           => l_segment
139766         , p_from_segment_code       => l_adr_value_segment_code
139767         , p_from_combination_id     => l_adr_value_combination_id
139768         , p_value_type_code         => l_adr_value_type_code
139769         , p_transaction_coa_id      => l_adr_transaction_coa_id
139770         , p_accounting_coa_id       => l_adr_accounting_coa_id
139771         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
139772         , p_flex_value_set_id       => l_adr_flex_value_set_id
139773         , p_adr_code                => 'FA_EXPENSE_ACCT'
139774         , p_adr_type_code           => 'S'
139775         , p_component_type          => l_component_type
139776         , p_component_code          => l_component_code
139777         , p_component_type_code     => l_component_type_code
139778         , p_component_appl_id       => l_component_appl_id
139779         , p_amb_context_code        => l_amb_context_code
139780         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
139781         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
139782         , p_side                    => 'NA'
139783         );
139784 
139785   END IF;
139786 
139787    l_segment := AcctDerRule_158(
139788            p_application_id           => p_application_id
139789          , p_ae_header_id             => l_ae_header_id 
139790 , p_source_3 => p_source_3
139791 , p_source_20 => p_source_20
139792          , x_transaction_coa_id       => l_adr_transaction_coa_id
139793          , x_accounting_coa_id        => l_adr_accounting_coa_id
139794          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
139795          , x_flex_value_set_id        => l_adr_flex_value_set_id
139796          , x_value_type_code          => l_adr_value_type_code
139797          , x_value_combination_id     => l_adr_value_combination_id
139798          , x_value_segment_code       => l_adr_value_segment_code
139799          , p_side                     => 'NA'
139800          , p_override_seg_flag        => 'Y'
139801    );
139802 
139803    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
139804 
139805       xla_ae_lines_pkg.set_segment(
139806           p_to_segment_code         => 'GL_ACCOUNT'
139807         , p_segment_value           => l_segment
139808         , p_from_segment_code       => l_adr_value_segment_code
139809         , p_from_combination_id     => l_adr_value_combination_id
139810         , p_value_type_code         => l_adr_value_type_code
139811         , p_transaction_coa_id      => l_adr_transaction_coa_id
139812         , p_accounting_coa_id       => l_adr_accounting_coa_id
139813         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
139814         , p_flex_value_set_id       => l_adr_flex_value_set_id
139815         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
139816         , p_adr_type_code           => 'S'
139817         , p_component_type          => l_component_type
139818         , p_component_code          => l_component_code
139819         , p_component_type_code     => l_component_type_code
139820         , p_component_appl_id       => l_component_appl_id
139821         , p_amb_context_code        => l_amb_context_code
139822         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
139823         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
139824         , p_side                    => 'NA'
139825         );
139826 
139827   END IF;
139828 
139829    --
139830    --
139831    END IF;
139832    --
139833    -- Bug 4922099
139834    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
139835           (NVL(l_enc_upg_option, 'N') = 'O')
139836         ) AND
139837         (l_bflow_method_code = 'PRIOR_ENTRY')
139838       )
139839    THEN
139840       IF
139841       --
139842       1 = 2
139843       --
139844       THEN
139845       xla_accounting_err_pkg.build_message
139846                                     (p_appli_s_name            => 'XLA'
139847                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
139848                                     ,p_token_1                 => 'LINE_NUMBER'
139849                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
139850                                     ,p_token_2                 => 'LINE_TYPE_NAME'
139851                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
139852                                                                              l_component_type
139853                                                                             ,l_component_code
139854                                                                             ,l_component_type_code
139855                                                                             ,l_component_appl_id
139856                                                                             ,l_amb_context_code
139857                                                                             ,l_entity_code
139858                                                                             ,l_event_class_code
139859                                                                            )
139860                                     ,p_token_3                 => 'OWNER'
139861                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
139862                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
139866                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
139863                                                                           ,p_lookup_code    => l_component_type_code
139864                                                                          )
139865                                     ,p_token_4                 => 'PRODUCT_NAME'
139867                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
139868                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
139869                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
139870                                     ,p_ae_header_id            =>  NULL
139871                                        );
139872 
139873         IF (C_LEVEL_ERROR>= g_log_level) THEN
139874                  trace
139875                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
139876                       ,p_level    => C_LEVEL_ERROR
139877                       ,p_module   => l_log_module);
139878         END IF;
139879       END IF;
139880    END IF;
139881    --
139882    --
139883    ------------------------------------------------------------------------------------------------
139884    -- 4219869 Business Flow
139885    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
139886    -- Prior Entry.  Currently, the following code is always generated.
139887    ------------------------------------------------------------------------------------------------
139888    XLA_AE_LINES_PKG.ValidateCurrentLine;
139889 
139890    ------------------------------------------------------------------------------------
139891    -- 4219869 Business Flow
139892    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
139893    ------------------------------------------------------------------------------------
139894    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
139895 
139896    ----------------------------------------------------------------------------------
139897    -- 4219869 Business Flow
139898    -- Update journal entry status -- Need to generate this within IF <condition>
139899    ----------------------------------------------------------------------------------
139900    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
139901          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
139902          ,p_balance_type_code => l_balance_type_code
139903          );
139904 
139905    -------------------------------------------------------------------------------------------
139906    -- 4262811 - Generate the Accrual Reversal lines
139907    -------------------------------------------------------------------------------------------
139908    BEGIN
139909       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
139910                               (g_array_event(p_event_id).array_value_num('header_index'));
139911       IF l_acc_rev_flag IS NULL THEN
139912          l_acc_rev_flag := 'N';
139913       END IF;
139914    EXCEPTION
139915       WHEN OTHERS THEN
139916          l_acc_rev_flag := 'N';
139917    END;
139918    --
139919    IF (l_acc_rev_flag = 'Y') THEN
139920 
139921        -- 4645092  ------------------------------------------------------------------------------
139922        -- To allow MPA report to determine if it should generate report process
139923        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
139924        ------------------------------------------------------------------------------------------
139925 
139926        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
139927        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
139928    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
139929    -- call ADRs
139930    -- Bug 4922099
139931    --
139932    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
139933         (NVL(l_actual_upg_option, 'N') = 'O') OR
139934         (NVL(l_enc_upg_option, 'N') = 'O')
139935       )
139936    THEN
139937    NULL;
139938    --
139939    --
139940    
139941   l_ccid := AcctDerRule_173(
139942            p_application_id           => p_application_id
139943          , p_ae_header_id             => l_ae_header_id 
139944 , p_source_3 => p_source_3
139945 , p_source_30 => p_source_30
139946          , x_transaction_coa_id       => l_adr_transaction_coa_id
139947          , x_accounting_coa_id        => l_adr_accounting_coa_id
139948          , x_value_type_code          => l_adr_value_type_code
139949          , p_side                     => 'NA'
139950    );
139951 
139952    xla_ae_lines_pkg.set_ccid(
139953     p_code_combination_id          => l_ccid
139954   , p_value_type_code              => l_adr_value_type_code
139955   , p_transaction_coa_id           => l_adr_transaction_coa_id
139956   , p_accounting_coa_id            => l_adr_accounting_coa_id
139957   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
139958   , p_adr_type_code                => 'S'
139959   , p_component_type               => l_component_type
139960   , p_component_code               => l_component_code
139961   , p_component_type_code          => l_component_type_code
139962   , p_component_appl_id            => l_component_appl_id
139963   , p_amb_context_code             => l_amb_context_code
139964   , p_side                         => 'NA'
139965   );
139966 
139967 
139968    l_segment := AcctDerRule_168(
139969            p_application_id           => p_application_id
139970          , p_ae_header_id             => l_ae_header_id 
139971 , p_source_3 => p_source_3
139972 , p_source_29 => p_source_29
139973          , x_transaction_coa_id       => l_adr_transaction_coa_id
139974          , x_accounting_coa_id        => l_adr_accounting_coa_id
139975          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
139976          , x_flex_value_set_id        => l_adr_flex_value_set_id
139980          , p_side                     => 'NA'
139977          , x_value_type_code          => l_adr_value_type_code
139978          , x_value_combination_id     => l_adr_value_combination_id
139979          , x_value_segment_code       => l_adr_value_segment_code
139981          , p_override_seg_flag        => 'Y'
139982    );
139983 
139984    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
139985 
139986       xla_ae_lines_pkg.set_segment(
139987           p_to_segment_code         => 'GL_BALANCING'
139988         , p_segment_value           => l_segment
139989         , p_from_segment_code       => l_adr_value_segment_code
139990         , p_from_combination_id     => l_adr_value_combination_id
139991         , p_value_type_code         => l_adr_value_type_code
139992         , p_transaction_coa_id      => l_adr_transaction_coa_id
139993         , p_accounting_coa_id       => l_adr_accounting_coa_id
139994         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
139995         , p_flex_value_set_id       => l_adr_flex_value_set_id
139996         , p_adr_code                => 'FA_EXPENSE_ACCT'
139997         , p_adr_type_code           => 'S'
139998         , p_component_type          => l_component_type
139999         , p_component_code          => l_component_code
140000         , p_component_type_code     => l_component_type_code
140001         , p_component_appl_id       => l_component_appl_id
140002         , p_amb_context_code        => l_amb_context_code
140003         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
140004         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
140005         , p_side                    => 'NA'
140006         );
140007 
140008   END IF;
140009 
140010    l_segment := AcctDerRule_158(
140011            p_application_id           => p_application_id
140012          , p_ae_header_id             => l_ae_header_id 
140013 , p_source_3 => p_source_3
140014 , p_source_20 => p_source_20
140015          , x_transaction_coa_id       => l_adr_transaction_coa_id
140016          , x_accounting_coa_id        => l_adr_accounting_coa_id
140017          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
140018          , x_flex_value_set_id        => l_adr_flex_value_set_id
140019          , x_value_type_code          => l_adr_value_type_code
140020          , x_value_combination_id     => l_adr_value_combination_id
140021          , x_value_segment_code       => l_adr_value_segment_code
140022          , p_side                     => 'NA'
140023          , p_override_seg_flag        => 'Y'
140024    );
140025 
140026    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
140027 
140028       xla_ae_lines_pkg.set_segment(
140029           p_to_segment_code         => 'GL_ACCOUNT'
140030         , p_segment_value           => l_segment
140031         , p_from_segment_code       => l_adr_value_segment_code
140032         , p_from_combination_id     => l_adr_value_combination_id
140033         , p_value_type_code         => l_adr_value_type_code
140034         , p_transaction_coa_id      => l_adr_transaction_coa_id
140035         , p_accounting_coa_id       => l_adr_accounting_coa_id
140036         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
140037         , p_flex_value_set_id       => l_adr_flex_value_set_id
140038         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
140039         , p_adr_type_code           => 'S'
140040         , p_component_type          => l_component_type
140041         , p_component_code          => l_component_code
140042         , p_component_type_code     => l_component_type_code
140043         , p_component_appl_id       => l_component_appl_id
140044         , p_amb_context_code        => l_amb_context_code
140045         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
140046         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
140047         , p_side                    => 'NA'
140048         );
140049 
140050   END IF;
140051 
140052    --
140053    --
140054    END IF;
140055 
140056        --
140057        -- Update the line information that should be overwritten
140058        --
140059        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
140060                                          p_header_num   => 1);
140061        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
140062 
140063        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
140064 
140065        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
140066           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
140067        END IF;
140068 
140069       --
140070       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
140071       --
140072       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
140073           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
140074       ELSE
140075           ---------------------------------------------------------------------------------------------------
140076           -- 4262811a Switch Sign
140077           ---------------------------------------------------------------------------------------------------
140078           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
140079           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
140080                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
140081           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
140082                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
140083           -- 5132302
140084           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
140088 
140085                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
140086 
140087       END IF;
140089       -- 4955764
140090       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
140091       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
140092 
140093 
140094       XLA_AE_LINES_PKG.ValidateCurrentLine;
140095       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
140096 
140097       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
140098                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
140099                ,p_balance_type_code => l_balance_type_code);
140100 
140101    END IF;
140102 
140103    -----------------------------------------------------------------------------------------
140104    -- 4262811 Multiperiod Accounting
140105    -----------------------------------------------------------------------------------------
140106      -- No MPA option is assigned.
140107 
140108 
140109 END IF;
140110 END IF;
140111 --
140112 
140113 --
140114 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
140115    trace
140116       (p_msg      => 'END of AcctLineType_350'
140117       ,p_level    => C_LEVEL_PROCEDURE
140118       ,p_module   => l_log_module);
140119 END IF;
140120 --
140121 EXCEPTION
140122   WHEN xla_exceptions_pkg.application_exception THEN
140123       RAISE;
140124   WHEN OTHERS THEN
140125        xla_exceptions_pkg.raise_message
140126            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_350');
140127 END AcctLineType_350;
140128 --
140129 
140130 ---------------------------------------
140131 --
140132 -- PRIVATE FUNCTION
140133 --         AcctLineType_351
140134 --
140135 ---------------------------------------
140136 PROCEDURE AcctLineType_351 (
140137   p_application_id        IN NUMBER
140138  ,p_event_id              IN NUMBER
140139  ,p_calculate_acctd_flag  IN VARCHAR2
140140  ,p_calculate_g_l_flag    IN VARCHAR2
140141  ,p_actual_flag           IN OUT VARCHAR2
140142  ,p_balance_type_code     OUT VARCHAR2
140143  ,p_gain_or_loss_ref      OUT VARCHAR2
140144  
140145 --Period Close Date
140146  , p_source_1            IN DATE
140147 --Bonus Depreciation Expense Account
140148  , p_source_2            IN VARCHAR2
140149 --Generated Code Combination Identifier
140150  , p_source_3            IN NUMBER
140151 --Expense Account Code Combination Identifier
140152  , p_source_29            IN NUMBER
140153 --Adjustment Type
140154  , p_source_35            IN VARCHAR2
140155 --Transaction Header Identifier
140156  , p_source_36            IN NUMBER
140157 --Adjustment Line Identifier
140158  , p_source_37            IN NUMBER
140159 --Distribution Type Code
140160  , p_source_38            IN VARCHAR2
140161 --Entered Amount
140162  , p_source_39            IN NUMBER
140163 --Currency Code
140164  , p_source_40            IN VARCHAR2
140165 --Source Destination Code
140166  , p_source_42            IN VARCHAR2
140167 )
140168 IS
140169 
140170 l_component_type              VARCHAR2(80);
140171 l_component_code              VARCHAR2(30);
140172 l_component_type_code         VARCHAR2(1);
140173 l_component_appl_id           INTEGER;
140174 l_amb_context_code            VARCHAR2(30);
140175 l_entity_code                 VARCHAR2(30);
140176 l_event_class_code            VARCHAR2(30);
140177 l_ae_header_id                NUMBER;
140178 l_event_type_code             VARCHAR2(30);
140179 l_line_definition_code        VARCHAR2(30);
140180 l_line_definition_owner_code  VARCHAR2(1);
140181 --
140182 -- adr variables
140183 l_segment                     VARCHAR2(30);
140184 l_ccid                        NUMBER;
140185 l_adr_transaction_coa_id      NUMBER;
140186 l_adr_accounting_coa_id       NUMBER;
140187 l_adr_flexfield_segment_code  VARCHAR2(30);
140188 l_adr_flex_value_set_id       NUMBER;
140189 l_adr_value_type_code         VARCHAR2(30);
140190 l_adr_value_combination_id    NUMBER;
140191 l_adr_value_segment_code      VARCHAR2(30);
140192 
140193 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
140194 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
140195 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
140196 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
140197 
140198 -- 4262811 Variables ------------------------------------------------------------------------------------------
140199 l_entered_amt_idx             NUMBER;
140200 l_accted_amt_idx              NUMBER;
140201 l_acc_rev_flag                VARCHAR2(1);
140202 l_accrual_line_num            NUMBER;
140203 l_tmp_amt                     NUMBER;
140204 l_acc_rev_natural_side_code   VARCHAR2(1);
140205 
140206 l_num_entries                 NUMBER;
140207 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
140208 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
140209 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
140210 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
140211 l_recog_line_1                NUMBER;
140212 l_recog_line_2                NUMBER;
140213 
140214 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
140215 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
140216 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
140217 
140218 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
140219 
140220 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
140221 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
140222 
140223 ---------------------------------------------------------------------------------------------------------------
140224 
140228 --
140225 
140226 --
140227 -- bulk performance
140229 l_balance_type_code           VARCHAR2(1);
140230 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
140231 l_log_module                  VARCHAR2(240);
140232 
140233 --
140234 -- Upgrade strategy
140235 --
140236 l_actual_upg_option           VARCHAR2(1);
140237 l_enc_upg_option           VARCHAR2(1);
140238 
140239 --
140240 BEGIN
140241 --
140242 IF g_log_enabled THEN
140243       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_351';
140244 END IF;
140245 --
140246 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
140247 
140248       trace
140249          (p_msg      => 'BEGIN of AcctLineType_351'
140250          ,p_level    => C_LEVEL_PROCEDURE
140251          ,p_module   => l_log_module);
140252 
140253 END IF;
140254 --
140255 l_component_type             := 'AMB_JLT';
140256 l_component_code             := 'FA_SLT_SOURCE_BONUS_EXP';
140257 l_component_type_code        := 'S';
140258 l_component_appl_id          :=  140;
140259 l_amb_context_code           := 'DEFAULT';
140260 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
140261 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
140262 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
140263 l_line_definition_owner_code := 'S';
140264 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
140265 --
140266 l_balance_type_code          := 'A';
140267 l_segment                     := NULL;
140268 l_ccid                        := NULL;
140269 l_adr_transaction_coa_id      := NULL;
140270 l_adr_accounting_coa_id       := NULL;
140271 l_adr_flexfield_segment_code  := NULL;
140272 l_adr_flex_value_set_id       := NULL;
140273 l_adr_value_type_code         := NULL;
140274 l_adr_value_combination_id    := NULL;
140275 l_adr_value_segment_code      := NULL;
140276 
140277 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
140278 l_bflow_class_code           := '';    -- 4219869 Business Flow
140279 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
140280 l_budgetary_control_flag     := 'N';
140281 
140282 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
140283 l_bflow_applied_to_amt       := NULL; -- 5132302
140284 l_entered_amt_idx            := NULL;          -- 4262811
140285 l_accted_amt_idx             := NULL;          -- 4262811
140286 l_acc_rev_flag               := NULL;          -- 4262811
140287 l_accrual_line_num           := NULL;          -- 4262811
140288 l_tmp_amt                    := NULL;          -- 4262811
140289 --
140290  
140291 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
140292     l_balance_type_code <> 'B' THEN
140293 IF NVL(p_source_35,'
140294 ') =  'BONUS EXPENSE' AND 
140295 NVL(p_source_42,'
140296 ') =  'SOURCE'
140297  THEN 
140298 
140299    --
140300    XLA_AE_LINES_PKG.SetNewLine;
140301 
140302    p_balance_type_code          := l_balance_type_code;
140303    -- set the flag so later we will know whether the gain loss line needs to be created
140304    
140305    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
140306      p_actual_flag :='A';
140307    END IF;
140308 
140309    --
140310    -- bulk performance
140311    --
140312    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
140313                                       p_header_num   => 0); -- 4262811
140314    --
140315    -- set accounting line options
140316    --
140317    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
140318            p_natural_side_code          => 'C'
140319          , p_gain_or_loss_flag          => 'N'
140320          , p_gl_transfer_mode_code      => 'S'
140321          , p_acct_entry_type_code       => 'A'
140322          , p_switch_side_flag           => 'Y'
140323          , p_merge_duplicate_code       => 'N'
140324          );
140325    --
140326    l_acc_rev_natural_side_code := 'D';  -- 4262811
140327    -- 
140328    --
140329    -- set accounting line type info
140330    --
140331    xla_ae_lines_pkg.SetAcctLineType
140332       (p_component_type             => l_component_type
140333       ,p_event_type_code            => l_event_type_code
140334       ,p_line_definition_owner_code => l_line_definition_owner_code
140335       ,p_line_definition_code       => l_line_definition_code
140336       ,p_accounting_line_code       => l_component_code
140337       ,p_accounting_line_type_code  => l_component_type_code
140338       ,p_accounting_line_appl_id    => l_component_appl_id
140339       ,p_amb_context_code           => l_amb_context_code
140340       ,p_entity_code                => l_entity_code
140341       ,p_event_class_code           => l_event_class_code);
140342    --
140343    -- set accounting class
140344    --
140345    xla_ae_lines_pkg.SetAcctClass(
140346            p_accounting_class_code  => 'EXPENSE'
140347          , p_ae_header_id           => l_ae_header_id
140348          );
140349 
140350    --
140351    -- set rounding class
140352    --
140353    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
140354                       'EXPENSE';
140355 
140356    --
140357    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
140358    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
140359    --
140360    -- bulk performance
140361    --
140362    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
140363 
140364    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
140365       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
140366 
140367    -- 4955764
140368    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
140372    
140369       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
140370 
140371    -- 4458381 Public Sector Enh
140373    --
140374    -- set accounting attributes for the line type
140375    --
140376    l_entered_amt_idx := 4;
140377    l_accted_amt_idx  := 6;
140378    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
140379    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
140380    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
140381    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
140382    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
140383    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
140384    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
140385    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
140386    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
140387    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
140388    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
140389    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
140390    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
140391 
140392    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
140393    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
140394 
140395    ---------------------------------------------------------------------------------------------------------------
140396    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
140397    ---------------------------------------------------------------------------------------------------------------
140398    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
140399 
140400    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
140401    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
140402 
140403    IF xla_accounting_cache_pkg.GetValueChar
140404          (p_source_code         => 'LEDGER_CATEGORY_CODE'
140405          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
140406    AND l_bflow_method_code = 'PRIOR_ENTRY'
140407 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
140408    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
140409          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
140410        )
140411    THEN
140412          xla_ae_lines_pkg.BflowUpgEntry
140413            (p_business_method_code    => l_bflow_method_code
140414            ,p_business_class_code     => l_bflow_class_code
140415            ,p_balance_type            => l_balance_type_code);
140416    ELSE
140417       NULL;
140418 -- No business flow processing for business flow method of NONE.
140419    END IF;
140420 
140421    --
140422    -- call analytical criteria
140423    --
140424    
140425    --
140426    -- call description
140427    --
140428    
140429 xla_ae_lines_pkg.SetLineDescription(
140430    p_ae_header_id => l_ae_header_id
140431   ,p_description  => Description_103 (
140432      p_application_id         => p_application_id
140433    , p_ae_header_id           => l_ae_header_id 
140434 , p_source_1 => p_source_1
140435    )
140436 );
140437 
140438 
140439    --
140440    -- call ADRs
140441    -- Bug 4922099
140442    --
140443    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
140444         (NVL(l_actual_upg_option, 'N') = 'O') OR
140445         (NVL(l_enc_upg_option, 'N') = 'O')
140446       )
140447    THEN
140448    NULL;
140449    --
140450    --
140451    
140452   l_ccid := AcctDerRule_175(
140453            p_application_id           => p_application_id
140454          , p_ae_header_id             => l_ae_header_id 
140455 , p_source_3 => p_source_3
140456 , p_source_29 => p_source_29
140457          , x_transaction_coa_id       => l_adr_transaction_coa_id
140458          , x_accounting_coa_id        => l_adr_accounting_coa_id
140459          , x_value_type_code          => l_adr_value_type_code
140460          , p_side                     => 'NA'
140461    );
140462 
140463    xla_ae_lines_pkg.set_ccid(
140464     p_code_combination_id          => l_ccid
140465   , p_value_type_code              => l_adr_value_type_code
140466   , p_transaction_coa_id           => l_adr_transaction_coa_id
140467   , p_accounting_coa_id            => l_adr_accounting_coa_id
140468   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
140469   , p_adr_type_code                => 'S'
140470   , p_component_type               => l_component_type
140471   , p_component_code               => l_component_code
140472   , p_component_type_code          => l_component_type_code
140473   , p_component_appl_id            => l_component_appl_id
140474   , p_amb_context_code             => l_amb_context_code
140475   , p_side                         => 'NA'
140476   );
140477 
140478 
140479    l_segment := AcctDerRule_143(
140480            p_application_id           => p_application_id
140481          , p_ae_header_id             => l_ae_header_id 
140482 , p_source_2 => p_source_2
140483 , p_source_3 => p_source_3
140484          , x_transaction_coa_id       => l_adr_transaction_coa_id
140485          , x_accounting_coa_id        => l_adr_accounting_coa_id
140486          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
140487          , x_flex_value_set_id        => l_adr_flex_value_set_id
140488          , x_value_type_code          => l_adr_value_type_code
140489          , x_value_combination_id     => l_adr_value_combination_id
140490          , x_value_segment_code       => l_adr_value_segment_code
140491          , p_side                     => 'NA'
140492          , p_override_seg_flag        => 'Y'
140493    );
140494 
140495    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
140499         , p_segment_value           => l_segment
140496 
140497       xla_ae_lines_pkg.set_segment(
140498           p_to_segment_code         => 'GL_ACCOUNT'
140500         , p_from_segment_code       => l_adr_value_segment_code
140501         , p_from_combination_id     => l_adr_value_combination_id
140502         , p_value_type_code         => l_adr_value_type_code
140503         , p_transaction_coa_id      => l_adr_transaction_coa_id
140504         , p_accounting_coa_id       => l_adr_accounting_coa_id
140505         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
140506         , p_flex_value_set_id       => l_adr_flex_value_set_id
140507         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
140508         , p_adr_type_code           => 'S'
140509         , p_component_type          => l_component_type
140510         , p_component_code          => l_component_code
140511         , p_component_type_code     => l_component_type_code
140512         , p_component_appl_id       => l_component_appl_id
140513         , p_amb_context_code        => l_amb_context_code
140514         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
140515         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
140516         , p_side                    => 'NA'
140517         );
140518 
140519   END IF;
140520 
140521    --
140522    --
140523    END IF;
140524    --
140525    -- Bug 4922099
140526    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
140527           (NVL(l_enc_upg_option, 'N') = 'O')
140528         ) AND
140529         (l_bflow_method_code = 'PRIOR_ENTRY')
140530       )
140531    THEN
140532       IF
140533       --
140534       1 = 2
140535       --
140536       THEN
140537       xla_accounting_err_pkg.build_message
140538                                     (p_appli_s_name            => 'XLA'
140539                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
140540                                     ,p_token_1                 => 'LINE_NUMBER'
140541                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
140542                                     ,p_token_2                 => 'LINE_TYPE_NAME'
140543                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
140544                                                                              l_component_type
140545                                                                             ,l_component_code
140546                                                                             ,l_component_type_code
140547                                                                             ,l_component_appl_id
140548                                                                             ,l_amb_context_code
140549                                                                             ,l_entity_code
140550                                                                             ,l_event_class_code
140551                                                                            )
140552                                     ,p_token_3                 => 'OWNER'
140553                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
140554                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
140555                                                                           ,p_lookup_code    => l_component_type_code
140556                                                                          )
140557                                     ,p_token_4                 => 'PRODUCT_NAME'
140558                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
140559                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
140560                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
140561                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
140562                                     ,p_ae_header_id            =>  NULL
140563                                        );
140564 
140565         IF (C_LEVEL_ERROR>= g_log_level) THEN
140566                  trace
140567                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
140568                       ,p_level    => C_LEVEL_ERROR
140569                       ,p_module   => l_log_module);
140570         END IF;
140571       END IF;
140572    END IF;
140573    --
140574    --
140575    ------------------------------------------------------------------------------------------------
140576    -- 4219869 Business Flow
140577    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
140578    -- Prior Entry.  Currently, the following code is always generated.
140579    ------------------------------------------------------------------------------------------------
140580    XLA_AE_LINES_PKG.ValidateCurrentLine;
140581 
140582    ------------------------------------------------------------------------------------
140583    -- 4219869 Business Flow
140584    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
140585    ------------------------------------------------------------------------------------
140586    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
140587 
140588    ----------------------------------------------------------------------------------
140589    -- 4219869 Business Flow
140590    -- Update journal entry status -- Need to generate this within IF <condition>
140591    ----------------------------------------------------------------------------------
140592    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
140593          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
140594          ,p_balance_type_code => l_balance_type_code
140595          );
140596 
140597    -------------------------------------------------------------------------------------------
140598    -- 4262811 - Generate the Accrual Reversal lines
140602                               (g_array_event(p_event_id).array_value_num('header_index'));
140599    -------------------------------------------------------------------------------------------
140600    BEGIN
140601       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
140603       IF l_acc_rev_flag IS NULL THEN
140604          l_acc_rev_flag := 'N';
140605       END IF;
140606    EXCEPTION
140607       WHEN OTHERS THEN
140608          l_acc_rev_flag := 'N';
140609    END;
140610    --
140611    IF (l_acc_rev_flag = 'Y') THEN
140612 
140613        -- 4645092  ------------------------------------------------------------------------------
140614        -- To allow MPA report to determine if it should generate report process
140615        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
140616        ------------------------------------------------------------------------------------------
140617 
140618        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
140619        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
140620    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
140621    -- call ADRs
140622    -- Bug 4922099
140623    --
140624    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
140625         (NVL(l_actual_upg_option, 'N') = 'O') OR
140626         (NVL(l_enc_upg_option, 'N') = 'O')
140627       )
140628    THEN
140629    NULL;
140630    --
140631    --
140632    
140633   l_ccid := AcctDerRule_175(
140634            p_application_id           => p_application_id
140635          , p_ae_header_id             => l_ae_header_id 
140636 , p_source_3 => p_source_3
140637 , p_source_29 => p_source_29
140638          , x_transaction_coa_id       => l_adr_transaction_coa_id
140639          , x_accounting_coa_id        => l_adr_accounting_coa_id
140640          , x_value_type_code          => l_adr_value_type_code
140641          , p_side                     => 'NA'
140642    );
140643 
140644    xla_ae_lines_pkg.set_ccid(
140645     p_code_combination_id          => l_ccid
140646   , p_value_type_code              => l_adr_value_type_code
140647   , p_transaction_coa_id           => l_adr_transaction_coa_id
140648   , p_accounting_coa_id            => l_adr_accounting_coa_id
140649   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
140650   , p_adr_type_code                => 'S'
140651   , p_component_type               => l_component_type
140652   , p_component_code               => l_component_code
140653   , p_component_type_code          => l_component_type_code
140654   , p_component_appl_id            => l_component_appl_id
140655   , p_amb_context_code             => l_amb_context_code
140656   , p_side                         => 'NA'
140657   );
140658 
140659 
140660    l_segment := AcctDerRule_143(
140661            p_application_id           => p_application_id
140662          , p_ae_header_id             => l_ae_header_id 
140663 , p_source_2 => p_source_2
140664 , p_source_3 => p_source_3
140665          , x_transaction_coa_id       => l_adr_transaction_coa_id
140666          , x_accounting_coa_id        => l_adr_accounting_coa_id
140667          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
140668          , x_flex_value_set_id        => l_adr_flex_value_set_id
140669          , x_value_type_code          => l_adr_value_type_code
140670          , x_value_combination_id     => l_adr_value_combination_id
140671          , x_value_segment_code       => l_adr_value_segment_code
140672          , p_side                     => 'NA'
140673          , p_override_seg_flag        => 'Y'
140674    );
140675 
140676    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
140677 
140678       xla_ae_lines_pkg.set_segment(
140679           p_to_segment_code         => 'GL_ACCOUNT'
140680         , p_segment_value           => l_segment
140681         , p_from_segment_code       => l_adr_value_segment_code
140682         , p_from_combination_id     => l_adr_value_combination_id
140683         , p_value_type_code         => l_adr_value_type_code
140684         , p_transaction_coa_id      => l_adr_transaction_coa_id
140685         , p_accounting_coa_id       => l_adr_accounting_coa_id
140686         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
140687         , p_flex_value_set_id       => l_adr_flex_value_set_id
140688         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
140689         , p_adr_type_code           => 'S'
140690         , p_component_type          => l_component_type
140691         , p_component_code          => l_component_code
140692         , p_component_type_code     => l_component_type_code
140693         , p_component_appl_id       => l_component_appl_id
140694         , p_amb_context_code        => l_amb_context_code
140695         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
140696         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
140697         , p_side                    => 'NA'
140698         );
140699 
140700   END IF;
140701 
140702    --
140703    --
140704    END IF;
140705 
140706        --
140707        -- Update the line information that should be overwritten
140708        --
140709        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
140710                                          p_header_num   => 1);
140711        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
140712 
140713        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
140714 
140715        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
140716           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
140717        END IF;
140718 
140719       --
140720       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
140721       --
140722       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
140726           -- 4262811a Switch Sign
140723           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
140724       ELSE
140725           ---------------------------------------------------------------------------------------------------
140727           ---------------------------------------------------------------------------------------------------
140728           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
140729           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
140730                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
140731           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
140732                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
140733           -- 5132302
140734           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
140735                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
140736 
140737       END IF;
140738 
140739       -- 4955764
140740       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
140741       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
140742 
140743 
140744       XLA_AE_LINES_PKG.ValidateCurrentLine;
140745       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
140746 
140747       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
140748                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
140749                ,p_balance_type_code => l_balance_type_code);
140750 
140751    END IF;
140752 
140753    -----------------------------------------------------------------------------------------
140754    -- 4262811 Multiperiod Accounting
140755    -----------------------------------------------------------------------------------------
140756      -- No MPA option is assigned.
140757 
140758 
140759 END IF;
140760 END IF;
140761 --
140762 
140763 --
140764 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
140765    trace
140766       (p_msg      => 'END of AcctLineType_351'
140767       ,p_level    => C_LEVEL_PROCEDURE
140768       ,p_module   => l_log_module);
140769 END IF;
140770 --
140771 EXCEPTION
140772   WHEN xla_exceptions_pkg.application_exception THEN
140773       RAISE;
140774   WHEN OTHERS THEN
140775        xla_exceptions_pkg.raise_message
140776            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_351');
140777 END AcctLineType_351;
140778 --
140779 
140780 ---------------------------------------
140781 --
140782 -- PRIVATE FUNCTION
140783 --         AcctLineType_352
140784 --
140785 ---------------------------------------
140786 PROCEDURE AcctLineType_352 (
140787   p_application_id        IN NUMBER
140788  ,p_event_id              IN NUMBER
140789  ,p_calculate_acctd_flag  IN VARCHAR2
140790  ,p_calculate_g_l_flag    IN VARCHAR2
140791  ,p_actual_flag           IN OUT VARCHAR2
140792  ,p_balance_type_code     OUT VARCHAR2
140793  ,p_gain_or_loss_ref      OUT VARCHAR2
140794  
140795 --Period Close Date
140796  , p_source_1            IN DATE
140797 --Generated Code Combination Identifier
140798  , p_source_3            IN NUMBER
140799 --Bonus Reserve Account
140800  , p_source_4            IN VARCHAR2
140801 --Generated Offset Code Combination Identifier
140802  , p_source_17            IN NUMBER
140803 --Expense Account Code Combination Identifier
140804  , p_source_29            IN NUMBER
140805 --Default Code Combination Identifier
140806  , p_source_30            IN NUMBER
140807 --Adjustment Type
140808  , p_source_35            IN VARCHAR2
140809 --Transaction Header Identifier
140810  , p_source_36            IN NUMBER
140811 --Adjustment Line Identifier
140812  , p_source_37            IN NUMBER
140813 --Distribution Type Code
140814  , p_source_38            IN VARCHAR2
140815 --Entered Amount
140816  , p_source_39            IN NUMBER
140817 --Currency Code
140818  , p_source_40            IN VARCHAR2
140819 --Source Destination Code
140820  , p_source_42            IN VARCHAR2
140821 )
140822 IS
140823 
140824 l_component_type              VARCHAR2(80);
140825 l_component_code              VARCHAR2(30);
140826 l_component_type_code         VARCHAR2(1);
140827 l_component_appl_id           INTEGER;
140828 l_amb_context_code            VARCHAR2(30);
140829 l_entity_code                 VARCHAR2(30);
140830 l_event_class_code            VARCHAR2(30);
140831 l_ae_header_id                NUMBER;
140832 l_event_type_code             VARCHAR2(30);
140833 l_line_definition_code        VARCHAR2(30);
140834 l_line_definition_owner_code  VARCHAR2(1);
140835 --
140836 -- adr variables
140837 l_segment                     VARCHAR2(30);
140838 l_ccid                        NUMBER;
140839 l_adr_transaction_coa_id      NUMBER;
140840 l_adr_accounting_coa_id       NUMBER;
140841 l_adr_flexfield_segment_code  VARCHAR2(30);
140842 l_adr_flex_value_set_id       NUMBER;
140843 l_adr_value_type_code         VARCHAR2(30);
140844 l_adr_value_combination_id    NUMBER;
140845 l_adr_value_segment_code      VARCHAR2(30);
140846 
140847 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
140848 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
140849 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
140850 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
140851 
140852 -- 4262811 Variables ------------------------------------------------------------------------------------------
140853 l_entered_amt_idx             NUMBER;
140854 l_accted_amt_idx              NUMBER;
140855 l_acc_rev_flag                VARCHAR2(1);
140856 l_accrual_line_num            NUMBER;
140860 l_num_entries                 NUMBER;
140857 l_tmp_amt                     NUMBER;
140858 l_acc_rev_natural_side_code   VARCHAR2(1);
140859 
140861 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
140862 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
140863 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
140864 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
140865 l_recog_line_1                NUMBER;
140866 l_recog_line_2                NUMBER;
140867 
140868 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
140869 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
140870 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
140871 
140872 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
140873 
140874 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
140875 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
140876 
140877 ---------------------------------------------------------------------------------------------------------------
140878 
140879 
140880 --
140881 -- bulk performance
140882 --
140883 l_balance_type_code           VARCHAR2(1);
140884 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
140885 l_log_module                  VARCHAR2(240);
140886 
140887 --
140888 -- Upgrade strategy
140889 --
140890 l_actual_upg_option           VARCHAR2(1);
140891 l_enc_upg_option           VARCHAR2(1);
140892 
140893 --
140894 BEGIN
140895 --
140896 IF g_log_enabled THEN
140897       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_352';
140898 END IF;
140899 --
140900 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
140901 
140902       trace
140903          (p_msg      => 'BEGIN of AcctLineType_352'
140904          ,p_level    => C_LEVEL_PROCEDURE
140905          ,p_module   => l_log_module);
140906 
140907 END IF;
140908 --
140909 l_component_type             := 'AMB_JLT';
140910 l_component_code             := 'FA_SLT_SOURCE_BONUS_RESERVE';
140911 l_component_type_code        := 'S';
140912 l_component_appl_id          :=  140;
140913 l_amb_context_code           := 'DEFAULT';
140914 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
140915 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
140916 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
140917 l_line_definition_owner_code := 'S';
140918 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
140919 --
140920 l_balance_type_code          := 'A';
140921 l_segment                     := NULL;
140922 l_ccid                        := NULL;
140923 l_adr_transaction_coa_id      := NULL;
140924 l_adr_accounting_coa_id       := NULL;
140925 l_adr_flexfield_segment_code  := NULL;
140926 l_adr_flex_value_set_id       := NULL;
140927 l_adr_value_type_code         := NULL;
140928 l_adr_value_combination_id    := NULL;
140929 l_adr_value_segment_code      := NULL;
140930 
140931 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
140932 l_bflow_class_code           := '';    -- 4219869 Business Flow
140933 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
140934 l_budgetary_control_flag     := 'N';
140935 
140936 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
140937 l_bflow_applied_to_amt       := NULL; -- 5132302
140938 l_entered_amt_idx            := NULL;          -- 4262811
140939 l_accted_amt_idx             := NULL;          -- 4262811
140940 l_acc_rev_flag               := NULL;          -- 4262811
140941 l_accrual_line_num           := NULL;          -- 4262811
140942 l_tmp_amt                    := NULL;          -- 4262811
140943 --
140944  
140945 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
140946     l_balance_type_code <> 'B' THEN
140947 IF (NVL(p_source_35,'
140948 ') =  'BONUS EXPENSE' OR 
140949 NVL(p_source_35,'
140950 ') =  'BONUS RESERVE') AND 
140951 NVL(p_source_42,'
140952 ') =  'SOURCE'
140953  THEN 
140954 
140955    --
140956    XLA_AE_LINES_PKG.SetNewLine;
140957 
140958    p_balance_type_code          := l_balance_type_code;
140959    -- set the flag so later we will know whether the gain loss line needs to be created
140960    
140961    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
140962      p_actual_flag :='A';
140963    END IF;
140964 
140965    --
140966    -- bulk performance
140967    --
140968    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
140969                                       p_header_num   => 0); -- 4262811
140970    --
140971    -- set accounting line options
140972    --
140973    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
140974            p_natural_side_code          => 'D'
140975          , p_gain_or_loss_flag          => 'N'
140976          , p_gl_transfer_mode_code      => 'S'
140977          , p_acct_entry_type_code       => 'A'
140978          , p_switch_side_flag           => 'Y'
140979          , p_merge_duplicate_code       => 'N'
140980          );
140981    --
140982    l_acc_rev_natural_side_code := 'C';  -- 4262811
140983    -- 
140984    --
140985    -- set accounting line type info
140986    --
140987    xla_ae_lines_pkg.SetAcctLineType
140988       (p_component_type             => l_component_type
140989       ,p_event_type_code            => l_event_type_code
140990       ,p_line_definition_owner_code => l_line_definition_owner_code
140991       ,p_line_definition_code       => l_line_definition_code
140992       ,p_accounting_line_code       => l_component_code
140993       ,p_accounting_line_type_code  => l_component_type_code
140994       ,p_accounting_line_appl_id    => l_component_appl_id
140995       ,p_amb_context_code           => l_amb_context_code
140996       ,p_entity_code                => l_entity_code
141000    --
140997       ,p_event_class_code           => l_event_class_code);
140998    --
140999    -- set accounting class
141001    xla_ae_lines_pkg.SetAcctClass(
141002            p_accounting_class_code  => 'ASSET'
141003          , p_ae_header_id           => l_ae_header_id
141004          );
141005 
141006    --
141007    -- set rounding class
141008    --
141009    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
141010                       'ASSET';
141011 
141012    --
141013    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
141014    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
141015    --
141016    -- bulk performance
141017    --
141018    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
141019 
141020    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
141021       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
141022 
141023    -- 4955764
141024    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
141025       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
141026 
141027    -- 4458381 Public Sector Enh
141028    
141029    --
141030    -- set accounting attributes for the line type
141031    --
141032    l_entered_amt_idx := 4;
141033    l_accted_amt_idx  := 6;
141034    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
141035    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
141036    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
141037    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
141038    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
141039    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
141040    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
141041    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
141042    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
141043    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
141044    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
141045    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
141046    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
141047 
141048    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
141049    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
141050 
141051    ---------------------------------------------------------------------------------------------------------------
141052    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
141053    ---------------------------------------------------------------------------------------------------------------
141054    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
141055 
141056    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
141057    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
141058 
141059    IF xla_accounting_cache_pkg.GetValueChar
141060          (p_source_code         => 'LEDGER_CATEGORY_CODE'
141061          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
141062    AND l_bflow_method_code = 'PRIOR_ENTRY'
141063 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
141064    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
141065          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
141066        )
141067    THEN
141068          xla_ae_lines_pkg.BflowUpgEntry
141069            (p_business_method_code    => l_bflow_method_code
141070            ,p_business_class_code     => l_bflow_class_code
141071            ,p_balance_type            => l_balance_type_code);
141072    ELSE
141073       NULL;
141074 -- No business flow processing for business flow method of NONE.
141075    END IF;
141076 
141077    --
141078    -- call analytical criteria
141079    --
141080    
141081    --
141082    -- call description
141083    --
141084    
141085 xla_ae_lines_pkg.SetLineDescription(
141086    p_ae_header_id => l_ae_header_id
141087   ,p_description  => Description_104 (
141088      p_application_id         => p_application_id
141089    , p_ae_header_id           => l_ae_header_id 
141090 , p_source_1 => p_source_1
141091    )
141092 );
141093 
141094 
141095    --
141096    -- call ADRs
141097    -- Bug 4922099
141098    --
141099    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
141100         (NVL(l_actual_upg_option, 'N') = 'O') OR
141101         (NVL(l_enc_upg_option, 'N') = 'O')
141102       )
141103    THEN
141104    NULL;
141105    --
141106    --
141107    
141108   l_ccid := AcctDerRule_174(
141109            p_application_id           => p_application_id
141110          , p_ae_header_id             => l_ae_header_id 
141111 , p_source_3 => p_source_3
141112 , p_source_17 => p_source_17
141113 , p_source_30 => p_source_30
141114          , x_transaction_coa_id       => l_adr_transaction_coa_id
141115          , x_accounting_coa_id        => l_adr_accounting_coa_id
141116          , x_value_type_code          => l_adr_value_type_code
141117          , p_side                     => 'NA'
141118    );
141119 
141120    xla_ae_lines_pkg.set_ccid(
141121     p_code_combination_id          => l_ccid
141122   , p_value_type_code              => l_adr_value_type_code
141123   , p_transaction_coa_id           => l_adr_transaction_coa_id
141124   , p_accounting_coa_id            => l_adr_accounting_coa_id
141125   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
141126   , p_adr_type_code                => 'S'
141130   , p_component_appl_id            => l_component_appl_id
141127   , p_component_type               => l_component_type
141128   , p_component_code               => l_component_code
141129   , p_component_type_code          => l_component_type_code
141131   , p_amb_context_code             => l_amb_context_code
141132   , p_side                         => 'NA'
141133   );
141134 
141135 
141136    l_segment := AcctDerRule_144(
141137            p_application_id           => p_application_id
141138          , p_ae_header_id             => l_ae_header_id 
141139 , p_source_3 => p_source_3
141140 , p_source_4 => p_source_4
141141          , x_transaction_coa_id       => l_adr_transaction_coa_id
141142          , x_accounting_coa_id        => l_adr_accounting_coa_id
141143          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
141144          , x_flex_value_set_id        => l_adr_flex_value_set_id
141145          , x_value_type_code          => l_adr_value_type_code
141146          , x_value_combination_id     => l_adr_value_combination_id
141147          , x_value_segment_code       => l_adr_value_segment_code
141148          , p_side                     => 'NA'
141149          , p_override_seg_flag        => 'Y'
141150    );
141151 
141152    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
141153 
141154       xla_ae_lines_pkg.set_segment(
141155           p_to_segment_code         => 'GL_ACCOUNT'
141156         , p_segment_value           => l_segment
141157         , p_from_segment_code       => l_adr_value_segment_code
141158         , p_from_combination_id     => l_adr_value_combination_id
141159         , p_value_type_code         => l_adr_value_type_code
141160         , p_transaction_coa_id      => l_adr_transaction_coa_id
141161         , p_accounting_coa_id       => l_adr_accounting_coa_id
141162         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
141163         , p_flex_value_set_id       => l_adr_flex_value_set_id
141164         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
141165         , p_adr_type_code           => 'S'
141166         , p_component_type          => l_component_type
141167         , p_component_code          => l_component_code
141168         , p_component_type_code     => l_component_type_code
141169         , p_component_appl_id       => l_component_appl_id
141170         , p_amb_context_code        => l_amb_context_code
141171         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
141172         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
141173         , p_side                    => 'NA'
141174         );
141175 
141176   END IF;
141177 
141178    l_segment := AcctDerRule_168(
141179            p_application_id           => p_application_id
141180          , p_ae_header_id             => l_ae_header_id 
141181 , p_source_3 => p_source_3
141182 , p_source_29 => p_source_29
141183          , x_transaction_coa_id       => l_adr_transaction_coa_id
141184          , x_accounting_coa_id        => l_adr_accounting_coa_id
141185          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
141186          , x_flex_value_set_id        => l_adr_flex_value_set_id
141187          , x_value_type_code          => l_adr_value_type_code
141188          , x_value_combination_id     => l_adr_value_combination_id
141189          , x_value_segment_code       => l_adr_value_segment_code
141190          , p_side                     => 'NA'
141191          , p_override_seg_flag        => 'Y'
141192    );
141193 
141194    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
141195 
141196       xla_ae_lines_pkg.set_segment(
141197           p_to_segment_code         => 'GL_BALANCING'
141198         , p_segment_value           => l_segment
141199         , p_from_segment_code       => l_adr_value_segment_code
141200         , p_from_combination_id     => l_adr_value_combination_id
141201         , p_value_type_code         => l_adr_value_type_code
141202         , p_transaction_coa_id      => l_adr_transaction_coa_id
141203         , p_accounting_coa_id       => l_adr_accounting_coa_id
141204         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
141205         , p_flex_value_set_id       => l_adr_flex_value_set_id
141206         , p_adr_code                => 'FA_EXPENSE_ACCT'
141207         , p_adr_type_code           => 'S'
141208         , p_component_type          => l_component_type
141209         , p_component_code          => l_component_code
141210         , p_component_type_code     => l_component_type_code
141211         , p_component_appl_id       => l_component_appl_id
141212         , p_amb_context_code        => l_amb_context_code
141213         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
141214         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
141215         , p_side                    => 'NA'
141216         );
141217 
141218   END IF;
141219 
141220    --
141221    --
141222    END IF;
141223    --
141224    -- Bug 4922099
141225    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
141226           (NVL(l_enc_upg_option, 'N') = 'O')
141227         ) AND
141228         (l_bflow_method_code = 'PRIOR_ENTRY')
141229       )
141230    THEN
141231       IF
141232       --
141233       1 = 2
141234       --
141235       THEN
141236       xla_accounting_err_pkg.build_message
141237                                     (p_appli_s_name            => 'XLA'
141238                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
141239                                     ,p_token_1                 => 'LINE_NUMBER'
141240                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
141241                                     ,p_token_2                 => 'LINE_TYPE_NAME'
141242                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
141243                                                                              l_component_type
141244                                                                             ,l_component_code
141248                                                                             ,l_entity_code
141245                                                                             ,l_component_type_code
141246                                                                             ,l_component_appl_id
141247                                                                             ,l_amb_context_code
141249                                                                             ,l_event_class_code
141250                                                                            )
141251                                     ,p_token_3                 => 'OWNER'
141252                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
141253                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
141254                                                                           ,p_lookup_code    => l_component_type_code
141255                                                                          )
141256                                     ,p_token_4                 => 'PRODUCT_NAME'
141257                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
141258                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
141259                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
141260                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
141261                                     ,p_ae_header_id            =>  NULL
141262                                        );
141263 
141264         IF (C_LEVEL_ERROR>= g_log_level) THEN
141265                  trace
141266                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
141267                       ,p_level    => C_LEVEL_ERROR
141268                       ,p_module   => l_log_module);
141269         END IF;
141270       END IF;
141271    END IF;
141272    --
141273    --
141274    ------------------------------------------------------------------------------------------------
141275    -- 4219869 Business Flow
141276    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
141277    -- Prior Entry.  Currently, the following code is always generated.
141278    ------------------------------------------------------------------------------------------------
141279    XLA_AE_LINES_PKG.ValidateCurrentLine;
141280 
141281    ------------------------------------------------------------------------------------
141282    -- 4219869 Business Flow
141283    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
141284    ------------------------------------------------------------------------------------
141285    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
141286 
141287    ----------------------------------------------------------------------------------
141288    -- 4219869 Business Flow
141289    -- Update journal entry status -- Need to generate this within IF <condition>
141290    ----------------------------------------------------------------------------------
141291    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
141292          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
141293          ,p_balance_type_code => l_balance_type_code
141294          );
141295 
141296    -------------------------------------------------------------------------------------------
141297    -- 4262811 - Generate the Accrual Reversal lines
141298    -------------------------------------------------------------------------------------------
141299    BEGIN
141300       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
141301                               (g_array_event(p_event_id).array_value_num('header_index'));
141302       IF l_acc_rev_flag IS NULL THEN
141303          l_acc_rev_flag := 'N';
141304       END IF;
141305    EXCEPTION
141306       WHEN OTHERS THEN
141307          l_acc_rev_flag := 'N';
141308    END;
141309    --
141310    IF (l_acc_rev_flag = 'Y') THEN
141311 
141312        -- 4645092  ------------------------------------------------------------------------------
141313        -- To allow MPA report to determine if it should generate report process
141314        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
141315        ------------------------------------------------------------------------------------------
141316 
141317        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
141318        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
141319    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
141320    -- call ADRs
141321    -- Bug 4922099
141322    --
141323    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
141324         (NVL(l_actual_upg_option, 'N') = 'O') OR
141325         (NVL(l_enc_upg_option, 'N') = 'O')
141326       )
141327    THEN
141328    NULL;
141329    --
141330    --
141331    
141332   l_ccid := AcctDerRule_174(
141333            p_application_id           => p_application_id
141334          , p_ae_header_id             => l_ae_header_id 
141335 , p_source_3 => p_source_3
141336 , p_source_17 => p_source_17
141337 , p_source_30 => p_source_30
141338          , x_transaction_coa_id       => l_adr_transaction_coa_id
141339          , x_accounting_coa_id        => l_adr_accounting_coa_id
141340          , x_value_type_code          => l_adr_value_type_code
141341          , p_side                     => 'NA'
141342    );
141343 
141344    xla_ae_lines_pkg.set_ccid(
141345     p_code_combination_id          => l_ccid
141346   , p_value_type_code              => l_adr_value_type_code
141347   , p_transaction_coa_id           => l_adr_transaction_coa_id
141348   , p_accounting_coa_id            => l_adr_accounting_coa_id
141349   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
141350   , p_adr_type_code                => 'S'
141351   , p_component_type               => l_component_type
141355   , p_amb_context_code             => l_amb_context_code
141352   , p_component_code               => l_component_code
141353   , p_component_type_code          => l_component_type_code
141354   , p_component_appl_id            => l_component_appl_id
141356   , p_side                         => 'NA'
141357   );
141358 
141359 
141360    l_segment := AcctDerRule_144(
141361            p_application_id           => p_application_id
141362          , p_ae_header_id             => l_ae_header_id 
141363 , p_source_3 => p_source_3
141364 , p_source_4 => p_source_4
141365          , x_transaction_coa_id       => l_adr_transaction_coa_id
141366          , x_accounting_coa_id        => l_adr_accounting_coa_id
141367          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
141368          , x_flex_value_set_id        => l_adr_flex_value_set_id
141369          , x_value_type_code          => l_adr_value_type_code
141370          , x_value_combination_id     => l_adr_value_combination_id
141371          , x_value_segment_code       => l_adr_value_segment_code
141372          , p_side                     => 'NA'
141373          , p_override_seg_flag        => 'Y'
141374    );
141375 
141376    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
141377 
141378       xla_ae_lines_pkg.set_segment(
141379           p_to_segment_code         => 'GL_ACCOUNT'
141380         , p_segment_value           => l_segment
141381         , p_from_segment_code       => l_adr_value_segment_code
141382         , p_from_combination_id     => l_adr_value_combination_id
141383         , p_value_type_code         => l_adr_value_type_code
141384         , p_transaction_coa_id      => l_adr_transaction_coa_id
141385         , p_accounting_coa_id       => l_adr_accounting_coa_id
141386         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
141387         , p_flex_value_set_id       => l_adr_flex_value_set_id
141388         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
141389         , p_adr_type_code           => 'S'
141390         , p_component_type          => l_component_type
141391         , p_component_code          => l_component_code
141392         , p_component_type_code     => l_component_type_code
141393         , p_component_appl_id       => l_component_appl_id
141394         , p_amb_context_code        => l_amb_context_code
141395         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
141396         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
141397         , p_side                    => 'NA'
141398         );
141399 
141400   END IF;
141401 
141402    l_segment := AcctDerRule_168(
141403            p_application_id           => p_application_id
141404          , p_ae_header_id             => l_ae_header_id 
141405 , p_source_3 => p_source_3
141406 , p_source_29 => p_source_29
141407          , x_transaction_coa_id       => l_adr_transaction_coa_id
141408          , x_accounting_coa_id        => l_adr_accounting_coa_id
141409          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
141410          , x_flex_value_set_id        => l_adr_flex_value_set_id
141411          , x_value_type_code          => l_adr_value_type_code
141412          , x_value_combination_id     => l_adr_value_combination_id
141413          , x_value_segment_code       => l_adr_value_segment_code
141414          , p_side                     => 'NA'
141415          , p_override_seg_flag        => 'Y'
141416    );
141417 
141418    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
141419 
141420       xla_ae_lines_pkg.set_segment(
141421           p_to_segment_code         => 'GL_BALANCING'
141422         , p_segment_value           => l_segment
141423         , p_from_segment_code       => l_adr_value_segment_code
141424         , p_from_combination_id     => l_adr_value_combination_id
141425         , p_value_type_code         => l_adr_value_type_code
141426         , p_transaction_coa_id      => l_adr_transaction_coa_id
141427         , p_accounting_coa_id       => l_adr_accounting_coa_id
141428         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
141429         , p_flex_value_set_id       => l_adr_flex_value_set_id
141430         , p_adr_code                => 'FA_EXPENSE_ACCT'
141431         , p_adr_type_code           => 'S'
141432         , p_component_type          => l_component_type
141433         , p_component_code          => l_component_code
141434         , p_component_type_code     => l_component_type_code
141435         , p_component_appl_id       => l_component_appl_id
141436         , p_amb_context_code        => l_amb_context_code
141437         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
141438         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
141439         , p_side                    => 'NA'
141440         );
141441 
141442   END IF;
141443 
141444    --
141445    --
141446    END IF;
141447 
141448        --
141449        -- Update the line information that should be overwritten
141450        --
141451        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
141452                                          p_header_num   => 1);
141453        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
141454 
141455        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
141456 
141457        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
141458           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
141459        END IF;
141460 
141461       --
141462       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
141463       --
141464       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
141465           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
141466       ELSE
141467           ---------------------------------------------------------------------------------------------------
141471           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
141468           -- 4262811a Switch Sign
141469           ---------------------------------------------------------------------------------------------------
141470           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
141472                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
141473           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
141474                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
141475           -- 5132302
141476           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
141477                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
141478 
141479       END IF;
141480 
141481       -- 4955764
141482       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
141483       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
141484 
141485 
141486       XLA_AE_LINES_PKG.ValidateCurrentLine;
141487       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
141488 
141489       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
141490                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
141491                ,p_balance_type_code => l_balance_type_code);
141492 
141493    END IF;
141494 
141495    -----------------------------------------------------------------------------------------
141496    -- 4262811 Multiperiod Accounting
141497    -----------------------------------------------------------------------------------------
141498      -- No MPA option is assigned.
141499 
141500 
141501 END IF;
141502 END IF;
141503 --
141504 
141505 --
141506 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
141507    trace
141508       (p_msg      => 'END of AcctLineType_352'
141509       ,p_level    => C_LEVEL_PROCEDURE
141510       ,p_module   => l_log_module);
141511 END IF;
141512 --
141513 EXCEPTION
141514   WHEN xla_exceptions_pkg.application_exception THEN
141515       RAISE;
141516   WHEN OTHERS THEN
141517        xla_exceptions_pkg.raise_message
141518            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_352');
141519 END AcctLineType_352;
141520 --
141521 
141522 ---------------------------------------
141523 --
141524 -- PRIVATE FUNCTION
141525 --         AcctLineType_353
141526 --
141527 ---------------------------------------
141528 PROCEDURE AcctLineType_353 (
141529   p_application_id        IN NUMBER
141530  ,p_event_id              IN NUMBER
141531  ,p_calculate_acctd_flag  IN VARCHAR2
141532  ,p_calculate_g_l_flag    IN VARCHAR2
141533  ,p_actual_flag           IN OUT VARCHAR2
141534  ,p_balance_type_code     OUT VARCHAR2
141535  ,p_gain_or_loss_ref      OUT VARCHAR2
141536  
141537 --Period Close Date
141538  , p_source_1            IN DATE
141539 --Generated Code Combination Identifier
141540  , p_source_3            IN NUMBER
141541 --CIP Cost Account
141542  , p_source_7            IN VARCHAR2
141543 --Expense Account Code Combination Identifier
141544  , p_source_29            IN NUMBER
141545 --Default Code Combination Identifier
141546  , p_source_30            IN NUMBER
141547 --Adjustment Type
141548  , p_source_35            IN VARCHAR2
141549 --Transaction Header Identifier
141550  , p_source_36            IN NUMBER
141551 --Adjustment Line Identifier
141552  , p_source_37            IN NUMBER
141553 --Distribution Type Code
141554  , p_source_38            IN VARCHAR2
141555 --Entered Amount
141556  , p_source_39            IN NUMBER
141557 --Currency Code
141558  , p_source_40            IN VARCHAR2
141559 --Source Destination Code
141560  , p_source_42            IN VARCHAR2
141561 )
141562 IS
141563 
141564 l_component_type              VARCHAR2(80);
141565 l_component_code              VARCHAR2(30);
141566 l_component_type_code         VARCHAR2(1);
141567 l_component_appl_id           INTEGER;
141568 l_amb_context_code            VARCHAR2(30);
141569 l_entity_code                 VARCHAR2(30);
141570 l_event_class_code            VARCHAR2(30);
141571 l_ae_header_id                NUMBER;
141572 l_event_type_code             VARCHAR2(30);
141573 l_line_definition_code        VARCHAR2(30);
141574 l_line_definition_owner_code  VARCHAR2(1);
141575 --
141576 -- adr variables
141577 l_segment                     VARCHAR2(30);
141578 l_ccid                        NUMBER;
141579 l_adr_transaction_coa_id      NUMBER;
141580 l_adr_accounting_coa_id       NUMBER;
141581 l_adr_flexfield_segment_code  VARCHAR2(30);
141582 l_adr_flex_value_set_id       NUMBER;
141583 l_adr_value_type_code         VARCHAR2(30);
141584 l_adr_value_combination_id    NUMBER;
141585 l_adr_value_segment_code      VARCHAR2(30);
141586 
141587 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
141588 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
141589 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
141590 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
141591 
141592 -- 4262811 Variables ------------------------------------------------------------------------------------------
141593 l_entered_amt_idx             NUMBER;
141594 l_accted_amt_idx              NUMBER;
141595 l_acc_rev_flag                VARCHAR2(1);
141596 l_accrual_line_num            NUMBER;
141597 l_tmp_amt                     NUMBER;
141598 l_acc_rev_natural_side_code   VARCHAR2(1);
141599 
141600 l_num_entries                 NUMBER;
141601 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
141602 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
141603 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
141607 
141604 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
141605 l_recog_line_1                NUMBER;
141606 l_recog_line_2                NUMBER;
141608 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
141609 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
141610 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
141611 
141612 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
141613 
141614 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
141615 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
141616 
141617 ---------------------------------------------------------------------------------------------------------------
141618 
141619 
141620 --
141621 -- bulk performance
141622 --
141623 l_balance_type_code           VARCHAR2(1);
141624 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
141625 l_log_module                  VARCHAR2(240);
141626 
141627 --
141628 -- Upgrade strategy
141629 --
141630 l_actual_upg_option           VARCHAR2(1);
141631 l_enc_upg_option           VARCHAR2(1);
141632 
141633 --
141634 BEGIN
141635 --
141636 IF g_log_enabled THEN
141637       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_353';
141638 END IF;
141639 --
141640 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
141641 
141642       trace
141643          (p_msg      => 'BEGIN of AcctLineType_353'
141644          ,p_level    => C_LEVEL_PROCEDURE
141645          ,p_module   => l_log_module);
141646 
141647 END IF;
141648 --
141649 l_component_type             := 'AMB_JLT';
141650 l_component_code             := 'FA_SLT_SOURCE_CIP_COST';
141651 l_component_type_code        := 'S';
141652 l_component_appl_id          :=  140;
141653 l_amb_context_code           := 'DEFAULT';
141654 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
141655 l_event_class_code           := 'CIP_SOURCE_LINE_TRANSFERS';
141656 l_event_type_code            := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
141657 l_line_definition_owner_code := 'S';
141658 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_S11';
141659 --
141660 l_balance_type_code          := 'A';
141661 l_segment                     := NULL;
141662 l_ccid                        := NULL;
141663 l_adr_transaction_coa_id      := NULL;
141664 l_adr_accounting_coa_id       := NULL;
141665 l_adr_flexfield_segment_code  := NULL;
141666 l_adr_flex_value_set_id       := NULL;
141667 l_adr_value_type_code         := NULL;
141668 l_adr_value_combination_id    := NULL;
141669 l_adr_value_segment_code      := NULL;
141670 
141671 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
141672 l_bflow_class_code           := '';    -- 4219869 Business Flow
141673 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
141674 l_budgetary_control_flag     := 'N';
141675 
141676 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
141677 l_bflow_applied_to_amt       := NULL; -- 5132302
141678 l_entered_amt_idx            := NULL;          -- 4262811
141679 l_accted_amt_idx             := NULL;          -- 4262811
141680 l_acc_rev_flag               := NULL;          -- 4262811
141681 l_accrual_line_num           := NULL;          -- 4262811
141682 l_tmp_amt                    := NULL;          -- 4262811
141683 --
141684  
141685 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
141686     l_balance_type_code <> 'B' THEN
141687 IF NVL(p_source_35,'
141688 ') =  'CIP COST' AND 
141689 NVL(p_source_42,'
141690 ') =  'SOURCE'
141691  THEN 
141692 
141693    --
141694    XLA_AE_LINES_PKG.SetNewLine;
141695 
141696    p_balance_type_code          := l_balance_type_code;
141697    -- set the flag so later we will know whether the gain loss line needs to be created
141698    
141699    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
141700      p_actual_flag :='A';
141701    END IF;
141702 
141703    --
141704    -- bulk performance
141705    --
141706    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
141707                                       p_header_num   => 0); -- 4262811
141708    --
141709    -- set accounting line options
141710    --
141711    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
141712            p_natural_side_code          => 'C'
141713          , p_gain_or_loss_flag          => 'N'
141714          , p_gl_transfer_mode_code      => 'S'
141715          , p_acct_entry_type_code       => 'A'
141716          , p_switch_side_flag           => 'Y'
141717          , p_merge_duplicate_code       => 'N'
141718          );
141719    --
141720    l_acc_rev_natural_side_code := 'D';  -- 4262811
141721    -- 
141722    --
141723    -- set accounting line type info
141724    --
141725    xla_ae_lines_pkg.SetAcctLineType
141726       (p_component_type             => l_component_type
141727       ,p_event_type_code            => l_event_type_code
141728       ,p_line_definition_owner_code => l_line_definition_owner_code
141729       ,p_line_definition_code       => l_line_definition_code
141730       ,p_accounting_line_code       => l_component_code
141731       ,p_accounting_line_type_code  => l_component_type_code
141732       ,p_accounting_line_appl_id    => l_component_appl_id
141733       ,p_amb_context_code           => l_amb_context_code
141734       ,p_entity_code                => l_entity_code
141735       ,p_event_class_code           => l_event_class_code);
141736    --
141737    -- set accounting class
141738    --
141739    xla_ae_lines_pkg.SetAcctClass(
141740            p_accounting_class_code  => 'ASSET'
141741          , p_ae_header_id           => l_ae_header_id
141742          );
141743 
141744    --
141745    -- set rounding class
141746    --
141750    --
141747    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
141748                       'ASSET';
141749 
141751    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
141752    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
141753    --
141754    -- bulk performance
141755    --
141756    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
141757 
141758    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
141759       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
141760 
141761    -- 4955764
141762    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
141763       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
141764 
141765    -- 4458381 Public Sector Enh
141766    
141767    --
141768    -- set accounting attributes for the line type
141769    --
141770    l_entered_amt_idx := 4;
141771    l_accted_amt_idx  := 6;
141772    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
141773    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
141774    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
141775    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
141776    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
141777    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
141778    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
141779    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
141780    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
141781    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
141782    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
141783    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
141784    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
141785 
141786    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
141787    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
141788 
141789    ---------------------------------------------------------------------------------------------------------------
141790    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
141791    ---------------------------------------------------------------------------------------------------------------
141792    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
141793 
141794    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
141795    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
141796 
141797    IF xla_accounting_cache_pkg.GetValueChar
141798          (p_source_code         => 'LEDGER_CATEGORY_CODE'
141799          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
141800    AND l_bflow_method_code = 'PRIOR_ENTRY'
141801 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
141802    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
141803          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
141804        )
141805    THEN
141806          xla_ae_lines_pkg.BflowUpgEntry
141807            (p_business_method_code    => l_bflow_method_code
141808            ,p_business_class_code     => l_bflow_class_code
141809            ,p_balance_type            => l_balance_type_code);
141810    ELSE
141811       NULL;
141812 -- No business flow processing for business flow method of NONE.
141813    END IF;
141814 
141815    --
141816    -- call analytical criteria
141817    --
141818    
141819    --
141820    -- call description
141821    --
141822    
141823 xla_ae_lines_pkg.SetLineDescription(
141824    p_ae_header_id => l_ae_header_id
141825   ,p_description  => Description_105 (
141826      p_application_id         => p_application_id
141827    , p_ae_header_id           => l_ae_header_id 
141828 , p_source_1 => p_source_1
141829    )
141830 );
141831 
141832 
141833    --
141834    -- call ADRs
141835    -- Bug 4922099
141836    --
141837    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
141838         (NVL(l_actual_upg_option, 'N') = 'O') OR
141839         (NVL(l_enc_upg_option, 'N') = 'O')
141840       )
141841    THEN
141842    NULL;
141843    --
141844    --
141845    
141846   l_ccid := AcctDerRule_173(
141847            p_application_id           => p_application_id
141848          , p_ae_header_id             => l_ae_header_id 
141849 , p_source_3 => p_source_3
141850 , p_source_30 => p_source_30
141851          , x_transaction_coa_id       => l_adr_transaction_coa_id
141852          , x_accounting_coa_id        => l_adr_accounting_coa_id
141853          , x_value_type_code          => l_adr_value_type_code
141854          , p_side                     => 'NA'
141855    );
141856 
141857    xla_ae_lines_pkg.set_ccid(
141858     p_code_combination_id          => l_ccid
141859   , p_value_type_code              => l_adr_value_type_code
141860   , p_transaction_coa_id           => l_adr_transaction_coa_id
141861   , p_accounting_coa_id            => l_adr_accounting_coa_id
141862   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
141863   , p_adr_type_code                => 'S'
141864   , p_component_type               => l_component_type
141865   , p_component_code               => l_component_code
141866   , p_component_type_code          => l_component_type_code
141867   , p_component_appl_id            => l_component_appl_id
141868   , p_amb_context_code             => l_amb_context_code
141869   , p_side                         => 'NA'
141870   );
141871 
141872 
141873    l_segment := AcctDerRule_146(
141877 , p_source_7 => p_source_7
141874            p_application_id           => p_application_id
141875          , p_ae_header_id             => l_ae_header_id 
141876 , p_source_3 => p_source_3
141878          , x_transaction_coa_id       => l_adr_transaction_coa_id
141879          , x_accounting_coa_id        => l_adr_accounting_coa_id
141880          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
141881          , x_flex_value_set_id        => l_adr_flex_value_set_id
141882          , x_value_type_code          => l_adr_value_type_code
141883          , x_value_combination_id     => l_adr_value_combination_id
141884          , x_value_segment_code       => l_adr_value_segment_code
141885          , p_side                     => 'NA'
141886          , p_override_seg_flag        => 'Y'
141887    );
141888 
141889    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
141890 
141891       xla_ae_lines_pkg.set_segment(
141892           p_to_segment_code         => 'GL_ACCOUNT'
141893         , p_segment_value           => l_segment
141894         , p_from_segment_code       => l_adr_value_segment_code
141895         , p_from_combination_id     => l_adr_value_combination_id
141896         , p_value_type_code         => l_adr_value_type_code
141897         , p_transaction_coa_id      => l_adr_transaction_coa_id
141898         , p_accounting_coa_id       => l_adr_accounting_coa_id
141899         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
141900         , p_flex_value_set_id       => l_adr_flex_value_set_id
141901         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
141902         , p_adr_type_code           => 'S'
141903         , p_component_type          => l_component_type
141904         , p_component_code          => l_component_code
141905         , p_component_type_code     => l_component_type_code
141906         , p_component_appl_id       => l_component_appl_id
141907         , p_amb_context_code        => l_amb_context_code
141908         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
141909         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
141910         , p_side                    => 'NA'
141911         );
141912 
141913   END IF;
141914 
141915    l_segment := AcctDerRule_168(
141916            p_application_id           => p_application_id
141917          , p_ae_header_id             => l_ae_header_id 
141918 , p_source_3 => p_source_3
141919 , p_source_29 => p_source_29
141920          , x_transaction_coa_id       => l_adr_transaction_coa_id
141921          , x_accounting_coa_id        => l_adr_accounting_coa_id
141922          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
141923          , x_flex_value_set_id        => l_adr_flex_value_set_id
141924          , x_value_type_code          => l_adr_value_type_code
141925          , x_value_combination_id     => l_adr_value_combination_id
141926          , x_value_segment_code       => l_adr_value_segment_code
141927          , p_side                     => 'NA'
141928          , p_override_seg_flag        => 'Y'
141929    );
141930 
141931    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
141932 
141933       xla_ae_lines_pkg.set_segment(
141934           p_to_segment_code         => 'GL_BALANCING'
141935         , p_segment_value           => l_segment
141936         , p_from_segment_code       => l_adr_value_segment_code
141937         , p_from_combination_id     => l_adr_value_combination_id
141938         , p_value_type_code         => l_adr_value_type_code
141939         , p_transaction_coa_id      => l_adr_transaction_coa_id
141940         , p_accounting_coa_id       => l_adr_accounting_coa_id
141941         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
141942         , p_flex_value_set_id       => l_adr_flex_value_set_id
141943         , p_adr_code                => 'FA_EXPENSE_ACCT'
141944         , p_adr_type_code           => 'S'
141945         , p_component_type          => l_component_type
141946         , p_component_code          => l_component_code
141947         , p_component_type_code     => l_component_type_code
141948         , p_component_appl_id       => l_component_appl_id
141949         , p_amb_context_code        => l_amb_context_code
141950         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
141951         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
141952         , p_side                    => 'NA'
141953         );
141954 
141955   END IF;
141956 
141957    --
141958    --
141959    END IF;
141960    --
141961    -- Bug 4922099
141962    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
141963           (NVL(l_enc_upg_option, 'N') = 'O')
141964         ) AND
141965         (l_bflow_method_code = 'PRIOR_ENTRY')
141966       )
141967    THEN
141968       IF
141969       --
141970       1 = 2
141971       --
141972       THEN
141973       xla_accounting_err_pkg.build_message
141974                                     (p_appli_s_name            => 'XLA'
141975                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
141976                                     ,p_token_1                 => 'LINE_NUMBER'
141977                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
141978                                     ,p_token_2                 => 'LINE_TYPE_NAME'
141979                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
141980                                                                              l_component_type
141981                                                                             ,l_component_code
141982                                                                             ,l_component_type_code
141983                                                                             ,l_component_appl_id
141984                                                                             ,l_amb_context_code
141985                                                                             ,l_entity_code
141989                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
141986                                                                             ,l_event_class_code
141987                                                                            )
141988                                     ,p_token_3                 => 'OWNER'
141990                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
141991                                                                           ,p_lookup_code    => l_component_type_code
141992                                                                          )
141993                                     ,p_token_4                 => 'PRODUCT_NAME'
141994                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
141995                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
141996                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
141997                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
141998                                     ,p_ae_header_id            =>  NULL
141999                                        );
142000 
142001         IF (C_LEVEL_ERROR>= g_log_level) THEN
142002                  trace
142003                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
142004                       ,p_level    => C_LEVEL_ERROR
142005                       ,p_module   => l_log_module);
142006         END IF;
142007       END IF;
142008    END IF;
142009    --
142010    --
142011    ------------------------------------------------------------------------------------------------
142012    -- 4219869 Business Flow
142013    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
142014    -- Prior Entry.  Currently, the following code is always generated.
142015    ------------------------------------------------------------------------------------------------
142016    XLA_AE_LINES_PKG.ValidateCurrentLine;
142017 
142018    ------------------------------------------------------------------------------------
142019    -- 4219869 Business Flow
142020    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
142021    ------------------------------------------------------------------------------------
142022    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
142023 
142024    ----------------------------------------------------------------------------------
142025    -- 4219869 Business Flow
142026    -- Update journal entry status -- Need to generate this within IF <condition>
142027    ----------------------------------------------------------------------------------
142028    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
142029          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
142030          ,p_balance_type_code => l_balance_type_code
142031          );
142032 
142033    -------------------------------------------------------------------------------------------
142034    -- 4262811 - Generate the Accrual Reversal lines
142035    -------------------------------------------------------------------------------------------
142036    BEGIN
142037       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
142038                               (g_array_event(p_event_id).array_value_num('header_index'));
142039       IF l_acc_rev_flag IS NULL THEN
142040          l_acc_rev_flag := 'N';
142041       END IF;
142042    EXCEPTION
142043       WHEN OTHERS THEN
142044          l_acc_rev_flag := 'N';
142045    END;
142046    --
142047    IF (l_acc_rev_flag = 'Y') THEN
142048 
142049        -- 4645092  ------------------------------------------------------------------------------
142050        -- To allow MPA report to determine if it should generate report process
142051        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
142052        ------------------------------------------------------------------------------------------
142053 
142054        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
142055        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
142056    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
142057    -- call ADRs
142058    -- Bug 4922099
142059    --
142060    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
142061         (NVL(l_actual_upg_option, 'N') = 'O') OR
142062         (NVL(l_enc_upg_option, 'N') = 'O')
142063       )
142064    THEN
142065    NULL;
142066    --
142067    --
142068    
142069   l_ccid := AcctDerRule_173(
142070            p_application_id           => p_application_id
142071          , p_ae_header_id             => l_ae_header_id 
142072 , p_source_3 => p_source_3
142073 , p_source_30 => p_source_30
142074          , x_transaction_coa_id       => l_adr_transaction_coa_id
142075          , x_accounting_coa_id        => l_adr_accounting_coa_id
142076          , x_value_type_code          => l_adr_value_type_code
142077          , p_side                     => 'NA'
142078    );
142079 
142080    xla_ae_lines_pkg.set_ccid(
142081     p_code_combination_id          => l_ccid
142082   , p_value_type_code              => l_adr_value_type_code
142083   , p_transaction_coa_id           => l_adr_transaction_coa_id
142084   , p_accounting_coa_id            => l_adr_accounting_coa_id
142085   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
142086   , p_adr_type_code                => 'S'
142087   , p_component_type               => l_component_type
142088   , p_component_code               => l_component_code
142089   , p_component_type_code          => l_component_type_code
142090   , p_component_appl_id            => l_component_appl_id
142091   , p_amb_context_code             => l_amb_context_code
142092   , p_side                         => 'NA'
142093   );
142094 
142095 
142096    l_segment := AcctDerRule_146(
142100 , p_source_7 => p_source_7
142097            p_application_id           => p_application_id
142098          , p_ae_header_id             => l_ae_header_id 
142099 , p_source_3 => p_source_3
142101          , x_transaction_coa_id       => l_adr_transaction_coa_id
142102          , x_accounting_coa_id        => l_adr_accounting_coa_id
142103          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
142104          , x_flex_value_set_id        => l_adr_flex_value_set_id
142105          , x_value_type_code          => l_adr_value_type_code
142106          , x_value_combination_id     => l_adr_value_combination_id
142107          , x_value_segment_code       => l_adr_value_segment_code
142108          , p_side                     => 'NA'
142109          , p_override_seg_flag        => 'Y'
142110    );
142111 
142112    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
142113 
142114       xla_ae_lines_pkg.set_segment(
142115           p_to_segment_code         => 'GL_ACCOUNT'
142116         , p_segment_value           => l_segment
142117         , p_from_segment_code       => l_adr_value_segment_code
142118         , p_from_combination_id     => l_adr_value_combination_id
142119         , p_value_type_code         => l_adr_value_type_code
142120         , p_transaction_coa_id      => l_adr_transaction_coa_id
142121         , p_accounting_coa_id       => l_adr_accounting_coa_id
142122         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
142123         , p_flex_value_set_id       => l_adr_flex_value_set_id
142124         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
142125         , p_adr_type_code           => 'S'
142126         , p_component_type          => l_component_type
142127         , p_component_code          => l_component_code
142128         , p_component_type_code     => l_component_type_code
142129         , p_component_appl_id       => l_component_appl_id
142130         , p_amb_context_code        => l_amb_context_code
142131         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
142132         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
142133         , p_side                    => 'NA'
142134         );
142135 
142136   END IF;
142137 
142138    l_segment := AcctDerRule_168(
142139            p_application_id           => p_application_id
142140          , p_ae_header_id             => l_ae_header_id 
142141 , p_source_3 => p_source_3
142142 , p_source_29 => p_source_29
142143          , x_transaction_coa_id       => l_adr_transaction_coa_id
142144          , x_accounting_coa_id        => l_adr_accounting_coa_id
142145          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
142146          , x_flex_value_set_id        => l_adr_flex_value_set_id
142147          , x_value_type_code          => l_adr_value_type_code
142148          , x_value_combination_id     => l_adr_value_combination_id
142149          , x_value_segment_code       => l_adr_value_segment_code
142150          , p_side                     => 'NA'
142151          , p_override_seg_flag        => 'Y'
142152    );
142153 
142154    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
142155 
142156       xla_ae_lines_pkg.set_segment(
142157           p_to_segment_code         => 'GL_BALANCING'
142158         , p_segment_value           => l_segment
142159         , p_from_segment_code       => l_adr_value_segment_code
142160         , p_from_combination_id     => l_adr_value_combination_id
142161         , p_value_type_code         => l_adr_value_type_code
142162         , p_transaction_coa_id      => l_adr_transaction_coa_id
142163         , p_accounting_coa_id       => l_adr_accounting_coa_id
142164         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
142165         , p_flex_value_set_id       => l_adr_flex_value_set_id
142166         , p_adr_code                => 'FA_EXPENSE_ACCT'
142167         , p_adr_type_code           => 'S'
142168         , p_component_type          => l_component_type
142169         , p_component_code          => l_component_code
142170         , p_component_type_code     => l_component_type_code
142171         , p_component_appl_id       => l_component_appl_id
142172         , p_amb_context_code        => l_amb_context_code
142173         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
142174         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
142175         , p_side                    => 'NA'
142176         );
142177 
142178   END IF;
142179 
142180    --
142181    --
142182    END IF;
142183 
142184        --
142185        -- Update the line information that should be overwritten
142186        --
142187        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
142188                                          p_header_num   => 1);
142189        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
142190 
142191        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
142192 
142193        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
142194           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
142195        END IF;
142196 
142197       --
142198       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
142199       --
142200       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
142201           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
142202       ELSE
142203           ---------------------------------------------------------------------------------------------------
142204           -- 4262811a Switch Sign
142205           ---------------------------------------------------------------------------------------------------
142206           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
142207           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
142211           -- 5132302
142208                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
142209           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
142210                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
142212           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
142213                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
142214 
142215       END IF;
142216 
142217       -- 4955764
142218       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
142219       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
142220 
142221 
142222       XLA_AE_LINES_PKG.ValidateCurrentLine;
142223       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
142224 
142225       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
142226                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
142227                ,p_balance_type_code => l_balance_type_code);
142228 
142229    END IF;
142230 
142231    -----------------------------------------------------------------------------------------
142232    -- 4262811 Multiperiod Accounting
142233    -----------------------------------------------------------------------------------------
142234      -- No MPA option is assigned.
142235 
142236 
142237 END IF;
142238 END IF;
142239 --
142240 
142241 --
142242 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
142243    trace
142244       (p_msg      => 'END of AcctLineType_353'
142245       ,p_level    => C_LEVEL_PROCEDURE
142246       ,p_module   => l_log_module);
142247 END IF;
142248 --
142249 EXCEPTION
142250   WHEN xla_exceptions_pkg.application_exception THEN
142251       RAISE;
142252   WHEN OTHERS THEN
142253        xla_exceptions_pkg.raise_message
142254            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_353');
142255 END AcctLineType_353;
142256 --
142257 
142258 ---------------------------------------
142259 --
142260 -- PRIVATE FUNCTION
142261 --         AcctLineType_354
142262 --
142263 ---------------------------------------
142264 PROCEDURE AcctLineType_354 (
142265   p_application_id        IN NUMBER
142266  ,p_event_id              IN NUMBER
142267  ,p_calculate_acctd_flag  IN VARCHAR2
142268  ,p_calculate_g_l_flag    IN VARCHAR2
142269  ,p_actual_flag           IN OUT VARCHAR2
142270  ,p_balance_type_code     OUT VARCHAR2
142271  ,p_gain_or_loss_ref      OUT VARCHAR2
142272  
142273 --Period Close Date
142274  , p_source_1            IN DATE
142275 --Generated Code Combination Identifier
142276  , p_source_3            IN NUMBER
142277 --CIP Cost Account
142278  , p_source_7            IN VARCHAR2
142279 --Expense Account Code Combination Identifier
142280  , p_source_29            IN NUMBER
142281 --Default Code Combination Identifier
142282  , p_source_30            IN NUMBER
142283 --Adjustment Type
142284  , p_source_35            IN VARCHAR2
142285 --Transaction Header Identifier
142286  , p_source_36            IN NUMBER
142287 --Adjustment Line Identifier
142288  , p_source_37            IN NUMBER
142289 --Distribution Type Code
142290  , p_source_38            IN VARCHAR2
142291 --Entered Amount
142292  , p_source_39            IN NUMBER
142293 --Currency Code
142294  , p_source_40            IN VARCHAR2
142295 --Source Destination Code
142296  , p_source_42            IN VARCHAR2
142297 )
142298 IS
142299 
142300 l_component_type              VARCHAR2(80);
142301 l_component_code              VARCHAR2(30);
142302 l_component_type_code         VARCHAR2(1);
142303 l_component_appl_id           INTEGER;
142304 l_amb_context_code            VARCHAR2(30);
142305 l_entity_code                 VARCHAR2(30);
142306 l_event_class_code            VARCHAR2(30);
142307 l_ae_header_id                NUMBER;
142308 l_event_type_code             VARCHAR2(30);
142309 l_line_definition_code        VARCHAR2(30);
142310 l_line_definition_owner_code  VARCHAR2(1);
142311 --
142312 -- adr variables
142313 l_segment                     VARCHAR2(30);
142314 l_ccid                        NUMBER;
142315 l_adr_transaction_coa_id      NUMBER;
142316 l_adr_accounting_coa_id       NUMBER;
142317 l_adr_flexfield_segment_code  VARCHAR2(30);
142318 l_adr_flex_value_set_id       NUMBER;
142319 l_adr_value_type_code         VARCHAR2(30);
142320 l_adr_value_combination_id    NUMBER;
142321 l_adr_value_segment_code      VARCHAR2(30);
142322 
142323 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
142324 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
142325 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
142326 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
142327 
142328 -- 4262811 Variables ------------------------------------------------------------------------------------------
142329 l_entered_amt_idx             NUMBER;
142330 l_accted_amt_idx              NUMBER;
142331 l_acc_rev_flag                VARCHAR2(1);
142332 l_accrual_line_num            NUMBER;
142333 l_tmp_amt                     NUMBER;
142334 l_acc_rev_natural_side_code   VARCHAR2(1);
142335 
142336 l_num_entries                 NUMBER;
142337 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
142338 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
142339 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
142340 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
142341 l_recog_line_1                NUMBER;
142342 l_recog_line_2                NUMBER;
142343 
142344 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
142345 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
142349 
142346 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
142347 
142348 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
142350 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
142351 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
142352 
142353 ---------------------------------------------------------------------------------------------------------------
142354 
142355 
142356 --
142357 -- bulk performance
142358 --
142359 l_balance_type_code           VARCHAR2(1);
142360 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
142361 l_log_module                  VARCHAR2(240);
142362 
142363 --
142364 -- Upgrade strategy
142365 --
142366 l_actual_upg_option           VARCHAR2(1);
142367 l_enc_upg_option           VARCHAR2(1);
142368 
142369 --
142370 BEGIN
142371 --
142372 IF g_log_enabled THEN
142373       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_354';
142374 END IF;
142375 --
142376 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
142377 
142378       trace
142379          (p_msg      => 'BEGIN of AcctLineType_354'
142380          ,p_level    => C_LEVEL_PROCEDURE
142381          ,p_module   => l_log_module);
142382 
142383 END IF;
142384 --
142385 l_component_type             := 'AMB_JLT';
142386 l_component_code             := 'FA_SLT_SOURCE_CIP_COST';
142387 l_component_type_code        := 'S';
142388 l_component_appl_id          :=  140;
142389 l_amb_context_code           := 'DEFAULT';
142390 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
142391 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
142392 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
142393 l_line_definition_owner_code := 'S';
142394 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
142395 --
142396 l_balance_type_code          := 'A';
142397 l_segment                     := NULL;
142398 l_ccid                        := NULL;
142399 l_adr_transaction_coa_id      := NULL;
142400 l_adr_accounting_coa_id       := NULL;
142401 l_adr_flexfield_segment_code  := NULL;
142402 l_adr_flex_value_set_id       := NULL;
142403 l_adr_value_type_code         := NULL;
142404 l_adr_value_combination_id    := NULL;
142405 l_adr_value_segment_code      := NULL;
142406 
142407 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
142408 l_bflow_class_code           := '';    -- 4219869 Business Flow
142409 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
142410 l_budgetary_control_flag     := 'N';
142411 
142412 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
142413 l_bflow_applied_to_amt       := NULL; -- 5132302
142414 l_entered_amt_idx            := NULL;          -- 4262811
142415 l_accted_amt_idx             := NULL;          -- 4262811
142416 l_acc_rev_flag               := NULL;          -- 4262811
142417 l_accrual_line_num           := NULL;          -- 4262811
142418 l_tmp_amt                    := NULL;          -- 4262811
142419 --
142420  
142421 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
142422     l_balance_type_code <> 'B' THEN
142423 IF NVL(p_source_35,'
142424 ') =  'CIP COST' AND 
142425 NVL(p_source_42,'
142426 ') =  'SOURCE'
142427  THEN 
142428 
142429    --
142430    XLA_AE_LINES_PKG.SetNewLine;
142431 
142432    p_balance_type_code          := l_balance_type_code;
142433    -- set the flag so later we will know whether the gain loss line needs to be created
142434    
142435    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
142436      p_actual_flag :='A';
142437    END IF;
142438 
142439    --
142440    -- bulk performance
142441    --
142442    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
142443                                       p_header_num   => 0); -- 4262811
142444    --
142445    -- set accounting line options
142446    --
142447    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
142448            p_natural_side_code          => 'C'
142449          , p_gain_or_loss_flag          => 'N'
142450          , p_gl_transfer_mode_code      => 'S'
142451          , p_acct_entry_type_code       => 'A'
142452          , p_switch_side_flag           => 'Y'
142453          , p_merge_duplicate_code       => 'N'
142454          );
142455    --
142456    l_acc_rev_natural_side_code := 'D';  -- 4262811
142457    -- 
142458    --
142459    -- set accounting line type info
142460    --
142461    xla_ae_lines_pkg.SetAcctLineType
142462       (p_component_type             => l_component_type
142463       ,p_event_type_code            => l_event_type_code
142464       ,p_line_definition_owner_code => l_line_definition_owner_code
142465       ,p_line_definition_code       => l_line_definition_code
142466       ,p_accounting_line_code       => l_component_code
142467       ,p_accounting_line_type_code  => l_component_type_code
142468       ,p_accounting_line_appl_id    => l_component_appl_id
142469       ,p_amb_context_code           => l_amb_context_code
142470       ,p_entity_code                => l_entity_code
142471       ,p_event_class_code           => l_event_class_code);
142472    --
142473    -- set accounting class
142474    --
142475    xla_ae_lines_pkg.SetAcctClass(
142476            p_accounting_class_code  => 'ASSET'
142477          , p_ae_header_id           => l_ae_header_id
142478          );
142479 
142480    --
142481    -- set rounding class
142482    --
142483    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
142484                       'ASSET';
142485 
142486    --
142487    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
142488    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
142492    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
142489    --
142490    -- bulk performance
142491    --
142493 
142494    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
142495       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
142496 
142497    -- 4955764
142498    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
142499       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
142500 
142501    -- 4458381 Public Sector Enh
142502    
142503    --
142504    -- set accounting attributes for the line type
142505    --
142506    l_entered_amt_idx := 4;
142507    l_accted_amt_idx  := 6;
142508    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
142509    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
142510    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
142511    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
142512    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
142513    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
142514    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
142515    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
142516    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
142517    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
142518    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
142519    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
142520    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
142521 
142522    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
142523    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
142524 
142525    ---------------------------------------------------------------------------------------------------------------
142526    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
142527    ---------------------------------------------------------------------------------------------------------------
142528    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
142529 
142530    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
142531    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
142532 
142533    IF xla_accounting_cache_pkg.GetValueChar
142534          (p_source_code         => 'LEDGER_CATEGORY_CODE'
142535          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
142536    AND l_bflow_method_code = 'PRIOR_ENTRY'
142537 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
142538    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
142539          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
142540        )
142541    THEN
142542          xla_ae_lines_pkg.BflowUpgEntry
142543            (p_business_method_code    => l_bflow_method_code
142544            ,p_business_class_code     => l_bflow_class_code
142545            ,p_balance_type            => l_balance_type_code);
142546    ELSE
142547       NULL;
142548 -- No business flow processing for business flow method of NONE.
142549    END IF;
142550 
142551    --
142552    -- call analytical criteria
142553    --
142554    
142555    --
142556    -- call description
142557    --
142558    
142559 xla_ae_lines_pkg.SetLineDescription(
142560    p_ae_header_id => l_ae_header_id
142561   ,p_description  => Description_105 (
142562      p_application_id         => p_application_id
142563    , p_ae_header_id           => l_ae_header_id 
142564 , p_source_1 => p_source_1
142565    )
142566 );
142567 
142568 
142569    --
142570    -- call ADRs
142571    -- Bug 4922099
142572    --
142573    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
142574         (NVL(l_actual_upg_option, 'N') = 'O') OR
142575         (NVL(l_enc_upg_option, 'N') = 'O')
142576       )
142577    THEN
142578    NULL;
142579    --
142580    --
142581    
142582   l_ccid := AcctDerRule_173(
142583            p_application_id           => p_application_id
142584          , p_ae_header_id             => l_ae_header_id 
142585 , p_source_3 => p_source_3
142586 , p_source_30 => p_source_30
142587          , x_transaction_coa_id       => l_adr_transaction_coa_id
142588          , x_accounting_coa_id        => l_adr_accounting_coa_id
142589          , x_value_type_code          => l_adr_value_type_code
142590          , p_side                     => 'NA'
142591    );
142592 
142593    xla_ae_lines_pkg.set_ccid(
142594     p_code_combination_id          => l_ccid
142595   , p_value_type_code              => l_adr_value_type_code
142596   , p_transaction_coa_id           => l_adr_transaction_coa_id
142597   , p_accounting_coa_id            => l_adr_accounting_coa_id
142598   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
142599   , p_adr_type_code                => 'S'
142600   , p_component_type               => l_component_type
142601   , p_component_code               => l_component_code
142602   , p_component_type_code          => l_component_type_code
142603   , p_component_appl_id            => l_component_appl_id
142604   , p_amb_context_code             => l_amb_context_code
142605   , p_side                         => 'NA'
142606   );
142607 
142608 
142609    l_segment := AcctDerRule_146(
142610            p_application_id           => p_application_id
142611          , p_ae_header_id             => l_ae_header_id 
142612 , p_source_3 => p_source_3
142613 , p_source_7 => p_source_7
142614          , x_transaction_coa_id       => l_adr_transaction_coa_id
142615          , x_accounting_coa_id        => l_adr_accounting_coa_id
142616          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
142620          , x_value_segment_code       => l_adr_value_segment_code
142617          , x_flex_value_set_id        => l_adr_flex_value_set_id
142618          , x_value_type_code          => l_adr_value_type_code
142619          , x_value_combination_id     => l_adr_value_combination_id
142621          , p_side                     => 'NA'
142622          , p_override_seg_flag        => 'Y'
142623    );
142624 
142625    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
142626 
142627       xla_ae_lines_pkg.set_segment(
142628           p_to_segment_code         => 'GL_ACCOUNT'
142629         , p_segment_value           => l_segment
142630         , p_from_segment_code       => l_adr_value_segment_code
142631         , p_from_combination_id     => l_adr_value_combination_id
142632         , p_value_type_code         => l_adr_value_type_code
142633         , p_transaction_coa_id      => l_adr_transaction_coa_id
142634         , p_accounting_coa_id       => l_adr_accounting_coa_id
142635         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
142636         , p_flex_value_set_id       => l_adr_flex_value_set_id
142637         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
142638         , p_adr_type_code           => 'S'
142639         , p_component_type          => l_component_type
142640         , p_component_code          => l_component_code
142641         , p_component_type_code     => l_component_type_code
142642         , p_component_appl_id       => l_component_appl_id
142643         , p_amb_context_code        => l_amb_context_code
142644         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
142645         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
142646         , p_side                    => 'NA'
142647         );
142648 
142649   END IF;
142650 
142651    l_segment := AcctDerRule_168(
142652            p_application_id           => p_application_id
142653          , p_ae_header_id             => l_ae_header_id 
142654 , p_source_3 => p_source_3
142655 , p_source_29 => p_source_29
142656          , x_transaction_coa_id       => l_adr_transaction_coa_id
142657          , x_accounting_coa_id        => l_adr_accounting_coa_id
142658          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
142659          , x_flex_value_set_id        => l_adr_flex_value_set_id
142660          , x_value_type_code          => l_adr_value_type_code
142661          , x_value_combination_id     => l_adr_value_combination_id
142662          , x_value_segment_code       => l_adr_value_segment_code
142663          , p_side                     => 'NA'
142664          , p_override_seg_flag        => 'Y'
142665    );
142666 
142667    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
142668 
142669       xla_ae_lines_pkg.set_segment(
142670           p_to_segment_code         => 'GL_BALANCING'
142671         , p_segment_value           => l_segment
142672         , p_from_segment_code       => l_adr_value_segment_code
142673         , p_from_combination_id     => l_adr_value_combination_id
142674         , p_value_type_code         => l_adr_value_type_code
142675         , p_transaction_coa_id      => l_adr_transaction_coa_id
142676         , p_accounting_coa_id       => l_adr_accounting_coa_id
142677         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
142678         , p_flex_value_set_id       => l_adr_flex_value_set_id
142679         , p_adr_code                => 'FA_EXPENSE_ACCT'
142680         , p_adr_type_code           => 'S'
142681         , p_component_type          => l_component_type
142682         , p_component_code          => l_component_code
142683         , p_component_type_code     => l_component_type_code
142684         , p_component_appl_id       => l_component_appl_id
142685         , p_amb_context_code        => l_amb_context_code
142686         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
142687         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
142688         , p_side                    => 'NA'
142689         );
142690 
142691   END IF;
142692 
142693    --
142694    --
142695    END IF;
142696    --
142697    -- Bug 4922099
142698    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
142699           (NVL(l_enc_upg_option, 'N') = 'O')
142700         ) AND
142701         (l_bflow_method_code = 'PRIOR_ENTRY')
142702       )
142703    THEN
142704       IF
142705       --
142706       1 = 2
142707       --
142708       THEN
142709       xla_accounting_err_pkg.build_message
142710                                     (p_appli_s_name            => 'XLA'
142711                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
142712                                     ,p_token_1                 => 'LINE_NUMBER'
142713                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
142714                                     ,p_token_2                 => 'LINE_TYPE_NAME'
142715                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
142716                                                                              l_component_type
142717                                                                             ,l_component_code
142718                                                                             ,l_component_type_code
142719                                                                             ,l_component_appl_id
142720                                                                             ,l_amb_context_code
142721                                                                             ,l_entity_code
142722                                                                             ,l_event_class_code
142723                                                                            )
142724                                     ,p_token_3                 => 'OWNER'
142725                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
142726                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
142730                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
142727                                                                           ,p_lookup_code    => l_component_type_code
142728                                                                          )
142729                                     ,p_token_4                 => 'PRODUCT_NAME'
142731                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
142732                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
142733                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
142734                                     ,p_ae_header_id            =>  NULL
142735                                        );
142736 
142737         IF (C_LEVEL_ERROR>= g_log_level) THEN
142738                  trace
142739                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
142740                       ,p_level    => C_LEVEL_ERROR
142741                       ,p_module   => l_log_module);
142742         END IF;
142743       END IF;
142744    END IF;
142745    --
142746    --
142747    ------------------------------------------------------------------------------------------------
142748    -- 4219869 Business Flow
142749    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
142750    -- Prior Entry.  Currently, the following code is always generated.
142751    ------------------------------------------------------------------------------------------------
142752    XLA_AE_LINES_PKG.ValidateCurrentLine;
142753 
142754    ------------------------------------------------------------------------------------
142755    -- 4219869 Business Flow
142756    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
142757    ------------------------------------------------------------------------------------
142758    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
142759 
142760    ----------------------------------------------------------------------------------
142761    -- 4219869 Business Flow
142762    -- Update journal entry status -- Need to generate this within IF <condition>
142763    ----------------------------------------------------------------------------------
142764    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
142765          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
142766          ,p_balance_type_code => l_balance_type_code
142767          );
142768 
142769    -------------------------------------------------------------------------------------------
142770    -- 4262811 - Generate the Accrual Reversal lines
142771    -------------------------------------------------------------------------------------------
142772    BEGIN
142773       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
142774                               (g_array_event(p_event_id).array_value_num('header_index'));
142775       IF l_acc_rev_flag IS NULL THEN
142776          l_acc_rev_flag := 'N';
142777       END IF;
142778    EXCEPTION
142779       WHEN OTHERS THEN
142780          l_acc_rev_flag := 'N';
142781    END;
142782    --
142783    IF (l_acc_rev_flag = 'Y') THEN
142784 
142785        -- 4645092  ------------------------------------------------------------------------------
142786        -- To allow MPA report to determine if it should generate report process
142787        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
142788        ------------------------------------------------------------------------------------------
142789 
142790        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
142791        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
142792    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
142793    -- call ADRs
142794    -- Bug 4922099
142795    --
142796    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
142797         (NVL(l_actual_upg_option, 'N') = 'O') OR
142798         (NVL(l_enc_upg_option, 'N') = 'O')
142799       )
142800    THEN
142801    NULL;
142802    --
142803    --
142804    
142805   l_ccid := AcctDerRule_173(
142806            p_application_id           => p_application_id
142807          , p_ae_header_id             => l_ae_header_id 
142808 , p_source_3 => p_source_3
142809 , p_source_30 => p_source_30
142810          , x_transaction_coa_id       => l_adr_transaction_coa_id
142811          , x_accounting_coa_id        => l_adr_accounting_coa_id
142812          , x_value_type_code          => l_adr_value_type_code
142813          , p_side                     => 'NA'
142814    );
142815 
142816    xla_ae_lines_pkg.set_ccid(
142817     p_code_combination_id          => l_ccid
142818   , p_value_type_code              => l_adr_value_type_code
142819   , p_transaction_coa_id           => l_adr_transaction_coa_id
142820   , p_accounting_coa_id            => l_adr_accounting_coa_id
142821   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
142822   , p_adr_type_code                => 'S'
142823   , p_component_type               => l_component_type
142824   , p_component_code               => l_component_code
142825   , p_component_type_code          => l_component_type_code
142826   , p_component_appl_id            => l_component_appl_id
142827   , p_amb_context_code             => l_amb_context_code
142828   , p_side                         => 'NA'
142829   );
142830 
142831 
142832    l_segment := AcctDerRule_146(
142833            p_application_id           => p_application_id
142834          , p_ae_header_id             => l_ae_header_id 
142835 , p_source_3 => p_source_3
142836 , p_source_7 => p_source_7
142837          , x_transaction_coa_id       => l_adr_transaction_coa_id
142838          , x_accounting_coa_id        => l_adr_accounting_coa_id
142839          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
142840          , x_flex_value_set_id        => l_adr_flex_value_set_id
142844          , p_side                     => 'NA'
142841          , x_value_type_code          => l_adr_value_type_code
142842          , x_value_combination_id     => l_adr_value_combination_id
142843          , x_value_segment_code       => l_adr_value_segment_code
142845          , p_override_seg_flag        => 'Y'
142846    );
142847 
142848    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
142849 
142850       xla_ae_lines_pkg.set_segment(
142851           p_to_segment_code         => 'GL_ACCOUNT'
142852         , p_segment_value           => l_segment
142853         , p_from_segment_code       => l_adr_value_segment_code
142854         , p_from_combination_id     => l_adr_value_combination_id
142855         , p_value_type_code         => l_adr_value_type_code
142856         , p_transaction_coa_id      => l_adr_transaction_coa_id
142857         , p_accounting_coa_id       => l_adr_accounting_coa_id
142858         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
142859         , p_flex_value_set_id       => l_adr_flex_value_set_id
142860         , p_adr_code                => 'FA_CAT_CIP_COST_SEGMENT'
142861         , p_adr_type_code           => 'S'
142862         , p_component_type          => l_component_type
142863         , p_component_code          => l_component_code
142864         , p_component_type_code     => l_component_type_code
142865         , p_component_appl_id       => l_component_appl_id
142866         , p_amb_context_code        => l_amb_context_code
142867         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
142868         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
142869         , p_side                    => 'NA'
142870         );
142871 
142872   END IF;
142873 
142874    l_segment := AcctDerRule_168(
142875            p_application_id           => p_application_id
142876          , p_ae_header_id             => l_ae_header_id 
142877 , p_source_3 => p_source_3
142878 , p_source_29 => p_source_29
142879          , x_transaction_coa_id       => l_adr_transaction_coa_id
142880          , x_accounting_coa_id        => l_adr_accounting_coa_id
142881          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
142882          , x_flex_value_set_id        => l_adr_flex_value_set_id
142883          , x_value_type_code          => l_adr_value_type_code
142884          , x_value_combination_id     => l_adr_value_combination_id
142885          , x_value_segment_code       => l_adr_value_segment_code
142886          , p_side                     => 'NA'
142887          , p_override_seg_flag        => 'Y'
142888    );
142889 
142890    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
142891 
142892       xla_ae_lines_pkg.set_segment(
142893           p_to_segment_code         => 'GL_BALANCING'
142894         , p_segment_value           => l_segment
142895         , p_from_segment_code       => l_adr_value_segment_code
142896         , p_from_combination_id     => l_adr_value_combination_id
142897         , p_value_type_code         => l_adr_value_type_code
142898         , p_transaction_coa_id      => l_adr_transaction_coa_id
142899         , p_accounting_coa_id       => l_adr_accounting_coa_id
142900         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
142901         , p_flex_value_set_id       => l_adr_flex_value_set_id
142902         , p_adr_code                => 'FA_EXPENSE_ACCT'
142903         , p_adr_type_code           => 'S'
142904         , p_component_type          => l_component_type
142905         , p_component_code          => l_component_code
142906         , p_component_type_code     => l_component_type_code
142907         , p_component_appl_id       => l_component_appl_id
142908         , p_amb_context_code        => l_amb_context_code
142909         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
142910         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
142911         , p_side                    => 'NA'
142912         );
142913 
142914   END IF;
142915 
142916    --
142917    --
142918    END IF;
142919 
142920        --
142921        -- Update the line information that should be overwritten
142922        --
142923        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
142924                                          p_header_num   => 1);
142925        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
142926 
142927        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
142928 
142929        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
142930           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
142931        END IF;
142932 
142933       --
142934       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
142935       --
142936       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
142937           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
142938       ELSE
142939           ---------------------------------------------------------------------------------------------------
142940           -- 4262811a Switch Sign
142941           ---------------------------------------------------------------------------------------------------
142942           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
142943           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
142944                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
142945           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
142946                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
142947           -- 5132302
142948           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
142952 
142949                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
142950 
142951       END IF;
142953       -- 4955764
142954       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
142955       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
142956 
142957 
142958       XLA_AE_LINES_PKG.ValidateCurrentLine;
142959       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
142960 
142961       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
142962                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
142963                ,p_balance_type_code => l_balance_type_code);
142964 
142965    END IF;
142966 
142967    -----------------------------------------------------------------------------------------
142968    -- 4262811 Multiperiod Accounting
142969    -----------------------------------------------------------------------------------------
142970      -- No MPA option is assigned.
142971 
142972 
142973 END IF;
142974 END IF;
142975 --
142976 
142977 --
142978 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
142979    trace
142980       (p_msg      => 'END of AcctLineType_354'
142981       ,p_level    => C_LEVEL_PROCEDURE
142982       ,p_module   => l_log_module);
142983 END IF;
142984 --
142985 EXCEPTION
142986   WHEN xla_exceptions_pkg.application_exception THEN
142987       RAISE;
142988   WHEN OTHERS THEN
142989        xla_exceptions_pkg.raise_message
142990            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_354');
142991 END AcctLineType_354;
142992 --
142993 
142994 ---------------------------------------
142995 --
142996 -- PRIVATE FUNCTION
142997 --         AcctLineType_355
142998 --
142999 ---------------------------------------
143000 PROCEDURE AcctLineType_355 (
143001   p_application_id        IN NUMBER
143002  ,p_event_id              IN NUMBER
143003  ,p_calculate_acctd_flag  IN VARCHAR2
143004  ,p_calculate_g_l_flag    IN VARCHAR2
143005  ,p_actual_flag           IN OUT VARCHAR2
143006  ,p_balance_type_code     OUT VARCHAR2
143007  ,p_gain_or_loss_ref      OUT VARCHAR2
143008  
143009 --Period Close Date
143010  , p_source_1            IN DATE
143011 --Generated Code Combination Identifier
143012  , p_source_3            IN NUMBER
143013 --CIP Clearing Account
143014  , p_source_5            IN VARCHAR2
143015 --Payables Code Combination Identifier
143016  , p_source_6            IN NUMBER
143017 --Expense Account Code Combination Identifier
143018  , p_source_29            IN NUMBER
143019 --Default Code Combination Identifier
143020  , p_source_30            IN NUMBER
143021 --Adjustment Type
143022  , p_source_35            IN VARCHAR2
143023 --Transaction Header Identifier
143024  , p_source_36            IN NUMBER
143025 --Adjustment Line Identifier
143026  , p_source_37            IN NUMBER
143027 --Distribution Type Code
143028  , p_source_38            IN VARCHAR2
143029 --Entered Amount
143030  , p_source_39            IN NUMBER
143031 --Currency Code
143032  , p_source_40            IN VARCHAR2
143033 --Source Destination Code
143034  , p_source_42            IN VARCHAR2
143035 )
143036 IS
143037 
143038 l_component_type              VARCHAR2(80);
143039 l_component_code              VARCHAR2(30);
143040 l_component_type_code         VARCHAR2(1);
143041 l_component_appl_id           INTEGER;
143042 l_amb_context_code            VARCHAR2(30);
143043 l_entity_code                 VARCHAR2(30);
143044 l_event_class_code            VARCHAR2(30);
143045 l_ae_header_id                NUMBER;
143046 l_event_type_code             VARCHAR2(30);
143047 l_line_definition_code        VARCHAR2(30);
143048 l_line_definition_owner_code  VARCHAR2(1);
143049 --
143050 -- adr variables
143051 l_segment                     VARCHAR2(30);
143052 l_ccid                        NUMBER;
143053 l_adr_transaction_coa_id      NUMBER;
143054 l_adr_accounting_coa_id       NUMBER;
143055 l_adr_flexfield_segment_code  VARCHAR2(30);
143056 l_adr_flex_value_set_id       NUMBER;
143057 l_adr_value_type_code         VARCHAR2(30);
143058 l_adr_value_combination_id    NUMBER;
143059 l_adr_value_segment_code      VARCHAR2(30);
143060 
143061 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
143062 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
143063 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
143064 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
143065 
143066 -- 4262811 Variables ------------------------------------------------------------------------------------------
143067 l_entered_amt_idx             NUMBER;
143068 l_accted_amt_idx              NUMBER;
143069 l_acc_rev_flag                VARCHAR2(1);
143070 l_accrual_line_num            NUMBER;
143071 l_tmp_amt                     NUMBER;
143072 l_acc_rev_natural_side_code   VARCHAR2(1);
143073 
143074 l_num_entries                 NUMBER;
143075 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
143076 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
143077 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
143078 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
143079 l_recog_line_1                NUMBER;
143080 l_recog_line_2                NUMBER;
143081 
143082 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
143083 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
143084 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
143085 
143086 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
143087 
143088 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
143092 
143089 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
143090 
143091 ---------------------------------------------------------------------------------------------------------------
143093 
143094 --
143095 -- bulk performance
143096 --
143097 l_balance_type_code           VARCHAR2(1);
143098 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
143099 l_log_module                  VARCHAR2(240);
143100 
143101 --
143102 -- Upgrade strategy
143103 --
143104 l_actual_upg_option           VARCHAR2(1);
143105 l_enc_upg_option           VARCHAR2(1);
143106 
143107 --
143108 BEGIN
143109 --
143110 IF g_log_enabled THEN
143111       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_355';
143112 END IF;
143113 --
143114 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
143115 
143116       trace
143117          (p_msg      => 'BEGIN of AcctLineType_355'
143118          ,p_level    => C_LEVEL_PROCEDURE
143119          ,p_module   => l_log_module);
143120 
143121 END IF;
143122 --
143123 l_component_type             := 'AMB_JLT';
143124 l_component_code             := 'FA_SLT_SOURCE_CIP_COST_CLR';
143125 l_component_type_code        := 'S';
143126 l_component_appl_id          :=  140;
143127 l_amb_context_code           := 'DEFAULT';
143128 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
143129 l_event_class_code           := 'CIP_SOURCE_LINE_TRANSFERS';
143130 l_event_type_code            := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
143131 l_line_definition_owner_code := 'S';
143132 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_S11';
143133 --
143134 l_balance_type_code          := 'A';
143135 l_segment                     := NULL;
143136 l_ccid                        := NULL;
143137 l_adr_transaction_coa_id      := NULL;
143138 l_adr_accounting_coa_id       := NULL;
143139 l_adr_flexfield_segment_code  := NULL;
143140 l_adr_flex_value_set_id       := NULL;
143141 l_adr_value_type_code         := NULL;
143142 l_adr_value_combination_id    := NULL;
143143 l_adr_value_segment_code      := NULL;
143144 
143145 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
143146 l_bflow_class_code           := '';    -- 4219869 Business Flow
143147 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
143148 l_budgetary_control_flag     := 'N';
143149 
143150 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
143151 l_bflow_applied_to_amt       := NULL; -- 5132302
143152 l_entered_amt_idx            := NULL;          -- 4262811
143153 l_accted_amt_idx             := NULL;          -- 4262811
143154 l_acc_rev_flag               := NULL;          -- 4262811
143155 l_accrual_line_num           := NULL;          -- 4262811
143156 l_tmp_amt                    := NULL;          -- 4262811
143157 --
143158  
143159 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
143160     l_balance_type_code <> 'B' THEN
143161 IF NVL(p_source_35,'
143162 ') =  'COST CLEARING' AND 
143163 NVL(p_source_42,'
143164 ') =  'SOURCE'
143165  THEN 
143166 
143167    --
143168    XLA_AE_LINES_PKG.SetNewLine;
143169 
143170    p_balance_type_code          := l_balance_type_code;
143171    -- set the flag so later we will know whether the gain loss line needs to be created
143172    
143173    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
143174      p_actual_flag :='A';
143175    END IF;
143176 
143177    --
143178    -- bulk performance
143179    --
143180    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
143181                                       p_header_num   => 0); -- 4262811
143182    --
143183    -- set accounting line options
143184    --
143185    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
143186            p_natural_side_code          => 'D'
143187          , p_gain_or_loss_flag          => 'N'
143188          , p_gl_transfer_mode_code      => 'S'
143189          , p_acct_entry_type_code       => 'A'
143190          , p_switch_side_flag           => 'Y'
143191          , p_merge_duplicate_code       => 'N'
143192          );
143193    --
143194    l_acc_rev_natural_side_code := 'C';  -- 4262811
143195    -- 
143196    --
143197    -- set accounting line type info
143198    --
143199    xla_ae_lines_pkg.SetAcctLineType
143200       (p_component_type             => l_component_type
143201       ,p_event_type_code            => l_event_type_code
143202       ,p_line_definition_owner_code => l_line_definition_owner_code
143203       ,p_line_definition_code       => l_line_definition_code
143204       ,p_accounting_line_code       => l_component_code
143205       ,p_accounting_line_type_code  => l_component_type_code
143206       ,p_accounting_line_appl_id    => l_component_appl_id
143207       ,p_amb_context_code           => l_amb_context_code
143208       ,p_entity_code                => l_entity_code
143209       ,p_event_class_code           => l_event_class_code);
143210    --
143211    -- set accounting class
143212    --
143213    xla_ae_lines_pkg.SetAcctClass(
143214            p_accounting_class_code  => 'ASSET'
143215          , p_ae_header_id           => l_ae_header_id
143216          );
143217 
143218    --
143219    -- set rounding class
143220    --
143221    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
143222                       'ASSET';
143223 
143224    --
143225    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
143226    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
143227    --
143228    -- bulk performance
143229    --
143230    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
143231 
143232    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
143236    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
143233       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
143234 
143235    -- 4955764
143237       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
143238 
143239    -- 4458381 Public Sector Enh
143240    
143241    --
143242    -- set accounting attributes for the line type
143243    --
143244    l_entered_amt_idx := 4;
143245    l_accted_amt_idx  := 6;
143246    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
143247    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
143248    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
143249    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
143250    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
143251    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
143252    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
143253    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
143254    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
143255    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
143256    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
143257    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
143258    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
143259 
143260    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
143261    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
143262 
143263    ---------------------------------------------------------------------------------------------------------------
143264    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
143265    ---------------------------------------------------------------------------------------------------------------
143266    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
143267 
143268    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
143269    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
143270 
143271    IF xla_accounting_cache_pkg.GetValueChar
143272          (p_source_code         => 'LEDGER_CATEGORY_CODE'
143273          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
143274    AND l_bflow_method_code = 'PRIOR_ENTRY'
143275 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
143276    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
143277          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
143278        )
143279    THEN
143280          xla_ae_lines_pkg.BflowUpgEntry
143281            (p_business_method_code    => l_bflow_method_code
143282            ,p_business_class_code     => l_bflow_class_code
143283            ,p_balance_type            => l_balance_type_code);
143284    ELSE
143285       NULL;
143286 -- No business flow processing for business flow method of NONE.
143287    END IF;
143288 
143289    --
143290    -- call analytical criteria
143291    --
143292    
143293    --
143294    -- call description
143295    --
143296    
143297 xla_ae_lines_pkg.SetLineDescription(
143298    p_ae_header_id => l_ae_header_id
143299   ,p_description  => Description_106 (
143300      p_application_id         => p_application_id
143301    , p_ae_header_id           => l_ae_header_id 
143302 , p_source_1 => p_source_1
143303    )
143304 );
143305 
143306 
143307    --
143308    -- call ADRs
143309    -- Bug 4922099
143310    --
143311    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
143312         (NVL(l_actual_upg_option, 'N') = 'O') OR
143313         (NVL(l_enc_upg_option, 'N') = 'O')
143314       )
143315    THEN
143316    NULL;
143317    --
143318    --
143319    
143320   l_ccid := AcctDerRule_173(
143321            p_application_id           => p_application_id
143322          , p_ae_header_id             => l_ae_header_id 
143323 , p_source_3 => p_source_3
143324 , p_source_30 => p_source_30
143325          , x_transaction_coa_id       => l_adr_transaction_coa_id
143326          , x_accounting_coa_id        => l_adr_accounting_coa_id
143327          , x_value_type_code          => l_adr_value_type_code
143328          , p_side                     => 'NA'
143329    );
143330 
143331    xla_ae_lines_pkg.set_ccid(
143332     p_code_combination_id          => l_ccid
143333   , p_value_type_code              => l_adr_value_type_code
143334   , p_transaction_coa_id           => l_adr_transaction_coa_id
143335   , p_accounting_coa_id            => l_adr_accounting_coa_id
143336   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
143337   , p_adr_type_code                => 'S'
143338   , p_component_type               => l_component_type
143339   , p_component_code               => l_component_code
143340   , p_component_type_code          => l_component_type_code
143341   , p_component_appl_id            => l_component_appl_id
143342   , p_amb_context_code             => l_amb_context_code
143343   , p_side                         => 'NA'
143344   );
143345 
143346 
143347    l_segment := AcctDerRule_145(
143348            p_application_id           => p_application_id
143349          , p_ae_header_id             => l_ae_header_id 
143350 , p_source_3 => p_source_3
143351 , p_source_5 => p_source_5
143352 , p_source_6 => p_source_6
143353          , x_transaction_coa_id       => l_adr_transaction_coa_id
143354          , x_accounting_coa_id        => l_adr_accounting_coa_id
143355          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
143356          , x_flex_value_set_id        => l_adr_flex_value_set_id
143357          , x_value_type_code          => l_adr_value_type_code
143358          , x_value_combination_id     => l_adr_value_combination_id
143362    );
143359          , x_value_segment_code       => l_adr_value_segment_code
143360          , p_side                     => 'NA'
143361          , p_override_seg_flag        => 'Y'
143363 
143364    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
143365 
143366       xla_ae_lines_pkg.set_segment(
143367           p_to_segment_code         => 'GL_ACCOUNT'
143368         , p_segment_value           => l_segment
143369         , p_from_segment_code       => l_adr_value_segment_code
143370         , p_from_combination_id     => l_adr_value_combination_id
143371         , p_value_type_code         => l_adr_value_type_code
143372         , p_transaction_coa_id      => l_adr_transaction_coa_id
143373         , p_accounting_coa_id       => l_adr_accounting_coa_id
143374         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
143375         , p_flex_value_set_id       => l_adr_flex_value_set_id
143376         , p_adr_code                => 'FA_CAT_CIP_CLR_SEGMENT'
143377         , p_adr_type_code           => 'S'
143378         , p_component_type          => l_component_type
143379         , p_component_code          => l_component_code
143380         , p_component_type_code     => l_component_type_code
143381         , p_component_appl_id       => l_component_appl_id
143382         , p_amb_context_code        => l_amb_context_code
143383         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
143384         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
143385         , p_side                    => 'NA'
143386         );
143387 
143388   END IF;
143389 
143390    l_segment := AcctDerRule_169(
143391            p_application_id           => p_application_id
143392          , p_ae_header_id             => l_ae_header_id 
143393 , p_source_3 => p_source_3
143394 , p_source_6 => p_source_6
143395 , p_source_29 => p_source_29
143396          , x_transaction_coa_id       => l_adr_transaction_coa_id
143397          , x_accounting_coa_id        => l_adr_accounting_coa_id
143398          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
143399          , x_flex_value_set_id        => l_adr_flex_value_set_id
143400          , x_value_type_code          => l_adr_value_type_code
143401          , x_value_combination_id     => l_adr_value_combination_id
143402          , x_value_segment_code       => l_adr_value_segment_code
143403          , p_side                     => 'NA'
143404          , p_override_seg_flag        => 'Y'
143405    );
143406 
143407    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
143408 
143409       xla_ae_lines_pkg.set_segment(
143410           p_to_segment_code         => 'GL_BALANCING'
143411         , p_segment_value           => l_segment
143412         , p_from_segment_code       => l_adr_value_segment_code
143413         , p_from_combination_id     => l_adr_value_combination_id
143414         , p_value_type_code         => l_adr_value_type_code
143415         , p_transaction_coa_id      => l_adr_transaction_coa_id
143416         , p_accounting_coa_id       => l_adr_accounting_coa_id
143417         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
143418         , p_flex_value_set_id       => l_adr_flex_value_set_id
143419         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
143420         , p_adr_type_code           => 'S'
143421         , p_component_type          => l_component_type
143422         , p_component_code          => l_component_code
143423         , p_component_type_code     => l_component_type_code
143424         , p_component_appl_id       => l_component_appl_id
143425         , p_amb_context_code        => l_amb_context_code
143426         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
143427         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
143428         , p_side                    => 'NA'
143429         );
143430 
143431   END IF;
143432 
143433    --
143434    --
143435    END IF;
143436    --
143437    -- Bug 4922099
143438    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
143439           (NVL(l_enc_upg_option, 'N') = 'O')
143440         ) AND
143441         (l_bflow_method_code = 'PRIOR_ENTRY')
143442       )
143443    THEN
143444       IF
143445       --
143446       1 = 2
143447       --
143448       THEN
143449       xla_accounting_err_pkg.build_message
143450                                     (p_appli_s_name            => 'XLA'
143451                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
143452                                     ,p_token_1                 => 'LINE_NUMBER'
143453                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
143454                                     ,p_token_2                 => 'LINE_TYPE_NAME'
143455                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
143456                                                                              l_component_type
143457                                                                             ,l_component_code
143458                                                                             ,l_component_type_code
143459                                                                             ,l_component_appl_id
143460                                                                             ,l_amb_context_code
143461                                                                             ,l_entity_code
143462                                                                             ,l_event_class_code
143463                                                                            )
143464                                     ,p_token_3                 => 'OWNER'
143465                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
143466                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
143467                                                                           ,p_lookup_code    => l_component_type_code
143468                                                                          )
143472                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
143469                                     ,p_token_4                 => 'PRODUCT_NAME'
143470                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
143471                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
143473                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
143474                                     ,p_ae_header_id            =>  NULL
143475                                        );
143476 
143477         IF (C_LEVEL_ERROR>= g_log_level) THEN
143478                  trace
143479                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
143480                       ,p_level    => C_LEVEL_ERROR
143481                       ,p_module   => l_log_module);
143482         END IF;
143483       END IF;
143484    END IF;
143485    --
143486    --
143487    ------------------------------------------------------------------------------------------------
143488    -- 4219869 Business Flow
143489    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
143490    -- Prior Entry.  Currently, the following code is always generated.
143491    ------------------------------------------------------------------------------------------------
143492    XLA_AE_LINES_PKG.ValidateCurrentLine;
143493 
143494    ------------------------------------------------------------------------------------
143495    -- 4219869 Business Flow
143496    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
143497    ------------------------------------------------------------------------------------
143498    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
143499 
143500    ----------------------------------------------------------------------------------
143501    -- 4219869 Business Flow
143502    -- Update journal entry status -- Need to generate this within IF <condition>
143503    ----------------------------------------------------------------------------------
143504    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
143505          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
143506          ,p_balance_type_code => l_balance_type_code
143507          );
143508 
143509    -------------------------------------------------------------------------------------------
143510    -- 4262811 - Generate the Accrual Reversal lines
143511    -------------------------------------------------------------------------------------------
143512    BEGIN
143513       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
143514                               (g_array_event(p_event_id).array_value_num('header_index'));
143515       IF l_acc_rev_flag IS NULL THEN
143516          l_acc_rev_flag := 'N';
143517       END IF;
143518    EXCEPTION
143519       WHEN OTHERS THEN
143520          l_acc_rev_flag := 'N';
143521    END;
143522    --
143523    IF (l_acc_rev_flag = 'Y') THEN
143524 
143525        -- 4645092  ------------------------------------------------------------------------------
143526        -- To allow MPA report to determine if it should generate report process
143527        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
143528        ------------------------------------------------------------------------------------------
143529 
143530        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
143531        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
143532    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
143533    -- call ADRs
143534    -- Bug 4922099
143535    --
143536    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
143537         (NVL(l_actual_upg_option, 'N') = 'O') OR
143538         (NVL(l_enc_upg_option, 'N') = 'O')
143539       )
143540    THEN
143541    NULL;
143542    --
143543    --
143544    
143545   l_ccid := AcctDerRule_173(
143546            p_application_id           => p_application_id
143547          , p_ae_header_id             => l_ae_header_id 
143548 , p_source_3 => p_source_3
143549 , p_source_30 => p_source_30
143550          , x_transaction_coa_id       => l_adr_transaction_coa_id
143551          , x_accounting_coa_id        => l_adr_accounting_coa_id
143552          , x_value_type_code          => l_adr_value_type_code
143553          , p_side                     => 'NA'
143554    );
143555 
143556    xla_ae_lines_pkg.set_ccid(
143557     p_code_combination_id          => l_ccid
143558   , p_value_type_code              => l_adr_value_type_code
143559   , p_transaction_coa_id           => l_adr_transaction_coa_id
143560   , p_accounting_coa_id            => l_adr_accounting_coa_id
143561   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
143562   , p_adr_type_code                => 'S'
143563   , p_component_type               => l_component_type
143564   , p_component_code               => l_component_code
143565   , p_component_type_code          => l_component_type_code
143566   , p_component_appl_id            => l_component_appl_id
143567   , p_amb_context_code             => l_amb_context_code
143568   , p_side                         => 'NA'
143569   );
143570 
143571 
143572    l_segment := AcctDerRule_145(
143573            p_application_id           => p_application_id
143574          , p_ae_header_id             => l_ae_header_id 
143575 , p_source_3 => p_source_3
143576 , p_source_5 => p_source_5
143577 , p_source_6 => p_source_6
143578          , x_transaction_coa_id       => l_adr_transaction_coa_id
143579          , x_accounting_coa_id        => l_adr_accounting_coa_id
143580          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
143581          , x_flex_value_set_id        => l_adr_flex_value_set_id
143582          , x_value_type_code          => l_adr_value_type_code
143583          , x_value_combination_id     => l_adr_value_combination_id
143587    );
143584          , x_value_segment_code       => l_adr_value_segment_code
143585          , p_side                     => 'NA'
143586          , p_override_seg_flag        => 'Y'
143588 
143589    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
143590 
143591       xla_ae_lines_pkg.set_segment(
143592           p_to_segment_code         => 'GL_ACCOUNT'
143593         , p_segment_value           => l_segment
143594         , p_from_segment_code       => l_adr_value_segment_code
143595         , p_from_combination_id     => l_adr_value_combination_id
143596         , p_value_type_code         => l_adr_value_type_code
143597         , p_transaction_coa_id      => l_adr_transaction_coa_id
143598         , p_accounting_coa_id       => l_adr_accounting_coa_id
143599         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
143600         , p_flex_value_set_id       => l_adr_flex_value_set_id
143601         , p_adr_code                => 'FA_CAT_CIP_CLR_SEGMENT'
143602         , p_adr_type_code           => 'S'
143603         , p_component_type          => l_component_type
143604         , p_component_code          => l_component_code
143605         , p_component_type_code     => l_component_type_code
143606         , p_component_appl_id       => l_component_appl_id
143607         , p_amb_context_code        => l_amb_context_code
143608         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
143609         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
143610         , p_side                    => 'NA'
143611         );
143612 
143613   END IF;
143614 
143615    l_segment := AcctDerRule_169(
143616            p_application_id           => p_application_id
143617          , p_ae_header_id             => l_ae_header_id 
143618 , p_source_3 => p_source_3
143619 , p_source_6 => p_source_6
143620 , p_source_29 => p_source_29
143621          , x_transaction_coa_id       => l_adr_transaction_coa_id
143622          , x_accounting_coa_id        => l_adr_accounting_coa_id
143623          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
143624          , x_flex_value_set_id        => l_adr_flex_value_set_id
143625          , x_value_type_code          => l_adr_value_type_code
143626          , x_value_combination_id     => l_adr_value_combination_id
143627          , x_value_segment_code       => l_adr_value_segment_code
143628          , p_side                     => 'NA'
143629          , p_override_seg_flag        => 'Y'
143630    );
143631 
143632    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
143633 
143634       xla_ae_lines_pkg.set_segment(
143635           p_to_segment_code         => 'GL_BALANCING'
143636         , p_segment_value           => l_segment
143637         , p_from_segment_code       => l_adr_value_segment_code
143638         , p_from_combination_id     => l_adr_value_combination_id
143639         , p_value_type_code         => l_adr_value_type_code
143640         , p_transaction_coa_id      => l_adr_transaction_coa_id
143641         , p_accounting_coa_id       => l_adr_accounting_coa_id
143642         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
143643         , p_flex_value_set_id       => l_adr_flex_value_set_id
143644         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
143645         , p_adr_type_code           => 'S'
143646         , p_component_type          => l_component_type
143647         , p_component_code          => l_component_code
143648         , p_component_type_code     => l_component_type_code
143649         , p_component_appl_id       => l_component_appl_id
143650         , p_amb_context_code        => l_amb_context_code
143651         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
143652         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
143653         , p_side                    => 'NA'
143654         );
143655 
143656   END IF;
143657 
143658    --
143659    --
143660    END IF;
143661 
143662        --
143663        -- Update the line information that should be overwritten
143664        --
143665        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
143666                                          p_header_num   => 1);
143667        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
143668 
143669        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
143670 
143671        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
143672           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
143673        END IF;
143674 
143675       --
143676       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
143677       --
143678       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
143679           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
143680       ELSE
143681           ---------------------------------------------------------------------------------------------------
143682           -- 4262811a Switch Sign
143683           ---------------------------------------------------------------------------------------------------
143684           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
143685           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
143686                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
143687           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
143688                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
143689           -- 5132302
143690           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
143691                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
143692 
143693       END IF;
143694 
143695       -- 4955764
143699 
143696       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
143697       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
143698 
143700       XLA_AE_LINES_PKG.ValidateCurrentLine;
143701       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
143702 
143703       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
143704                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
143705                ,p_balance_type_code => l_balance_type_code);
143706 
143707    END IF;
143708 
143709    -----------------------------------------------------------------------------------------
143710    -- 4262811 Multiperiod Accounting
143711    -----------------------------------------------------------------------------------------
143712      -- No MPA option is assigned.
143713 
143714 
143715 END IF;
143716 END IF;
143717 --
143718 
143719 --
143720 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
143721    trace
143722       (p_msg      => 'END of AcctLineType_355'
143723       ,p_level    => C_LEVEL_PROCEDURE
143724       ,p_module   => l_log_module);
143725 END IF;
143726 --
143727 EXCEPTION
143728   WHEN xla_exceptions_pkg.application_exception THEN
143729       RAISE;
143730   WHEN OTHERS THEN
143731        xla_exceptions_pkg.raise_message
143732            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_355');
143733 END AcctLineType_355;
143734 --
143735 
143736 ---------------------------------------
143737 --
143738 -- PRIVATE FUNCTION
143739 --         AcctLineType_356
143740 --
143741 ---------------------------------------
143742 PROCEDURE AcctLineType_356 (
143743   p_application_id        IN NUMBER
143744  ,p_event_id              IN NUMBER
143745  ,p_calculate_acctd_flag  IN VARCHAR2
143746  ,p_calculate_g_l_flag    IN VARCHAR2
143747  ,p_actual_flag           IN OUT VARCHAR2
143748  ,p_balance_type_code     OUT VARCHAR2
143749  ,p_gain_or_loss_ref      OUT VARCHAR2
143750  
143751 --Period Close Date
143752  , p_source_1            IN DATE
143753 --Generated Code Combination Identifier
143754  , p_source_3            IN NUMBER
143755 --Revaluation Reserve Account
143756  , p_source_11            IN VARCHAR2
143757 --Generated Offset Code Combination Identifier
143758  , p_source_17            IN NUMBER
143759 --Expense Account Code Combination Identifier
143760  , p_source_29            IN NUMBER
143761 --Default Code Combination Identifier
143762  , p_source_30            IN NUMBER
143763 --Adjustment Type
143764  , p_source_35            IN VARCHAR2
143765 --Transaction Header Identifier
143766  , p_source_36            IN NUMBER
143767 --Adjustment Line Identifier
143768  , p_source_37            IN NUMBER
143769 --Distribution Type Code
143770  , p_source_38            IN VARCHAR2
143771 --Entered Amount
143772  , p_source_39            IN NUMBER
143773 --Currency Code
143774  , p_source_40            IN VARCHAR2
143775 --Source Destination Code
143776  , p_source_42            IN VARCHAR2
143777 )
143778 IS
143779 
143780 l_component_type              VARCHAR2(80);
143781 l_component_code              VARCHAR2(30);
143782 l_component_type_code         VARCHAR2(1);
143783 l_component_appl_id           INTEGER;
143784 l_amb_context_code            VARCHAR2(30);
143785 l_entity_code                 VARCHAR2(30);
143786 l_event_class_code            VARCHAR2(30);
143787 l_ae_header_id                NUMBER;
143788 l_event_type_code             VARCHAR2(30);
143789 l_line_definition_code        VARCHAR2(30);
143790 l_line_definition_owner_code  VARCHAR2(1);
143791 --
143792 -- adr variables
143793 l_segment                     VARCHAR2(30);
143794 l_ccid                        NUMBER;
143795 l_adr_transaction_coa_id      NUMBER;
143796 l_adr_accounting_coa_id       NUMBER;
143797 l_adr_flexfield_segment_code  VARCHAR2(30);
143798 l_adr_flex_value_set_id       NUMBER;
143799 l_adr_value_type_code         VARCHAR2(30);
143800 l_adr_value_combination_id    NUMBER;
143801 l_adr_value_segment_code      VARCHAR2(30);
143802 
143803 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
143804 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
143805 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
143806 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
143807 
143808 -- 4262811 Variables ------------------------------------------------------------------------------------------
143809 l_entered_amt_idx             NUMBER;
143810 l_accted_amt_idx              NUMBER;
143811 l_acc_rev_flag                VARCHAR2(1);
143812 l_accrual_line_num            NUMBER;
143813 l_tmp_amt                     NUMBER;
143814 l_acc_rev_natural_side_code   VARCHAR2(1);
143815 
143816 l_num_entries                 NUMBER;
143817 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
143818 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
143819 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
143820 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
143821 l_recog_line_1                NUMBER;
143822 l_recog_line_2                NUMBER;
143823 
143824 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
143825 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
143826 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
143827 
143828 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
143829 
143830 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
143831 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
143832 
143833 ---------------------------------------------------------------------------------------------------------------
143834 
143835 
143839 l_balance_type_code           VARCHAR2(1);
143836 --
143837 -- bulk performance
143838 --
143840 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
143841 l_log_module                  VARCHAR2(240);
143842 
143843 --
143844 -- Upgrade strategy
143845 --
143846 l_actual_upg_option           VARCHAR2(1);
143847 l_enc_upg_option           VARCHAR2(1);
143848 
143849 --
143850 BEGIN
143851 --
143852 IF g_log_enabled THEN
143853       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_356';
143854 END IF;
143855 --
143856 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
143857 
143858       trace
143859          (p_msg      => 'BEGIN of AcctLineType_356'
143860          ,p_level    => C_LEVEL_PROCEDURE
143861          ,p_module   => l_log_module);
143862 
143863 END IF;
143864 --
143865 l_component_type             := 'AMB_JLT';
143866 l_component_code             := 'FA_SLT_SOURCE_CIP_REVAL_RESERV';
143867 l_component_type_code        := 'S';
143868 l_component_appl_id          :=  140;
143869 l_amb_context_code           := 'DEFAULT';
143870 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
143871 l_event_class_code           := 'CIP_SOURCE_LINE_TRANSFERS';
143872 l_event_type_code            := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
143873 l_line_definition_owner_code := 'S';
143874 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_CIP_S11';
143875 --
143876 l_balance_type_code          := 'A';
143877 l_segment                     := NULL;
143878 l_ccid                        := NULL;
143879 l_adr_transaction_coa_id      := NULL;
143880 l_adr_accounting_coa_id       := NULL;
143881 l_adr_flexfield_segment_code  := NULL;
143882 l_adr_flex_value_set_id       := NULL;
143883 l_adr_value_type_code         := NULL;
143884 l_adr_value_combination_id    := NULL;
143885 l_adr_value_segment_code      := NULL;
143886 
143887 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
143888 l_bflow_class_code           := '';    -- 4219869 Business Flow
143889 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
143890 l_budgetary_control_flag     := 'N';
143891 
143892 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
143893 l_bflow_applied_to_amt       := NULL; -- 5132302
143894 l_entered_amt_idx            := NULL;          -- 4262811
143895 l_accted_amt_idx             := NULL;          -- 4262811
143896 l_acc_rev_flag               := NULL;          -- 4262811
143897 l_accrual_line_num           := NULL;          -- 4262811
143898 l_tmp_amt                    := NULL;          -- 4262811
143899 --
143900  
143901 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
143902     l_balance_type_code <> 'B' THEN
143903 IF NVL(p_source_35,'
143904 ') =  'REVAL RESERVE' AND 
143905 NVL(p_source_42,'
143906 ') =  'SOURCE'
143907  THEN 
143908 
143909    --
143910    XLA_AE_LINES_PKG.SetNewLine;
143911 
143912    p_balance_type_code          := l_balance_type_code;
143913    -- set the flag so later we will know whether the gain loss line needs to be created
143914    
143915    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
143916      p_actual_flag :='A';
143917    END IF;
143918 
143919    --
143920    -- bulk performance
143921    --
143922    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
143923                                       p_header_num   => 0); -- 4262811
143924    --
143925    -- set accounting line options
143926    --
143927    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
143928            p_natural_side_code          => 'D'
143929          , p_gain_or_loss_flag          => 'N'
143930          , p_gl_transfer_mode_code      => 'S'
143931          , p_acct_entry_type_code       => 'A'
143932          , p_switch_side_flag           => 'Y'
143933          , p_merge_duplicate_code       => 'N'
143934          );
143935    --
143936    l_acc_rev_natural_side_code := 'C';  -- 4262811
143937    -- 
143938    --
143939    -- set accounting line type info
143940    --
143941    xla_ae_lines_pkg.SetAcctLineType
143942       (p_component_type             => l_component_type
143943       ,p_event_type_code            => l_event_type_code
143944       ,p_line_definition_owner_code => l_line_definition_owner_code
143945       ,p_line_definition_code       => l_line_definition_code
143946       ,p_accounting_line_code       => l_component_code
143947       ,p_accounting_line_type_code  => l_component_type_code
143948       ,p_accounting_line_appl_id    => l_component_appl_id
143949       ,p_amb_context_code           => l_amb_context_code
143950       ,p_entity_code                => l_entity_code
143951       ,p_event_class_code           => l_event_class_code);
143952    --
143953    -- set accounting class
143954    --
143955    xla_ae_lines_pkg.SetAcctClass(
143956            p_accounting_class_code  => 'ASSET'
143957          , p_ae_header_id           => l_ae_header_id
143958          );
143959 
143960    --
143961    -- set rounding class
143962    --
143963    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
143964                       'ASSET';
143965 
143966    --
143967    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
143968    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
143969    --
143970    -- bulk performance
143971    --
143972    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
143973 
143974    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
143975       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
143976 
143977    -- 4955764
143978    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
143982    
143979       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
143980 
143981    -- 4458381 Public Sector Enh
143983    --
143984    -- set accounting attributes for the line type
143985    --
143986    l_entered_amt_idx := 4;
143987    l_accted_amt_idx  := 6;
143988    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
143989    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
143990    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
143991    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
143992    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
143993    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
143994    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
143995    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
143996    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
143997    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
143998    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
143999    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
144000    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
144001 
144002    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
144003    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
144004 
144005    ---------------------------------------------------------------------------------------------------------------
144006    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
144007    ---------------------------------------------------------------------------------------------------------------
144008    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
144009 
144010    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
144011    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
144012 
144013    IF xla_accounting_cache_pkg.GetValueChar
144014          (p_source_code         => 'LEDGER_CATEGORY_CODE'
144015          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
144016    AND l_bflow_method_code = 'PRIOR_ENTRY'
144017 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
144018    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
144019          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
144020        )
144021    THEN
144022          xla_ae_lines_pkg.BflowUpgEntry
144023            (p_business_method_code    => l_bflow_method_code
144024            ,p_business_class_code     => l_bflow_class_code
144025            ,p_balance_type            => l_balance_type_code);
144026    ELSE
144027       NULL;
144028 -- No business flow processing for business flow method of NONE.
144029    END IF;
144030 
144031    --
144032    -- call analytical criteria
144033    --
144034    
144035    --
144036    -- call description
144037    --
144038    
144039 xla_ae_lines_pkg.SetLineDescription(
144040    p_ae_header_id => l_ae_header_id
144041   ,p_description  => Description_109 (
144042      p_application_id         => p_application_id
144043    , p_ae_header_id           => l_ae_header_id 
144044 , p_source_1 => p_source_1
144045    )
144046 );
144047 
144048 
144049    --
144050    -- call ADRs
144051    -- Bug 4922099
144052    --
144053    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
144054         (NVL(l_actual_upg_option, 'N') = 'O') OR
144055         (NVL(l_enc_upg_option, 'N') = 'O')
144056       )
144057    THEN
144058    NULL;
144059    --
144060    --
144061    
144062   l_ccid := AcctDerRule_174(
144063            p_application_id           => p_application_id
144064          , p_ae_header_id             => l_ae_header_id 
144065 , p_source_3 => p_source_3
144066 , p_source_17 => p_source_17
144067 , p_source_30 => p_source_30
144068          , x_transaction_coa_id       => l_adr_transaction_coa_id
144069          , x_accounting_coa_id        => l_adr_accounting_coa_id
144070          , x_value_type_code          => l_adr_value_type_code
144071          , p_side                     => 'NA'
144072    );
144073 
144074    xla_ae_lines_pkg.set_ccid(
144075     p_code_combination_id          => l_ccid
144076   , p_value_type_code              => l_adr_value_type_code
144077   , p_transaction_coa_id           => l_adr_transaction_coa_id
144078   , p_accounting_coa_id            => l_adr_accounting_coa_id
144079   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
144080   , p_adr_type_code                => 'S'
144081   , p_component_type               => l_component_type
144082   , p_component_code               => l_component_code
144083   , p_component_type_code          => l_component_type_code
144084   , p_component_appl_id            => l_component_appl_id
144085   , p_amb_context_code             => l_amb_context_code
144086   , p_side                         => 'NA'
144087   );
144088 
144089 
144090    l_segment := AcctDerRule_150(
144091            p_application_id           => p_application_id
144092          , p_ae_header_id             => l_ae_header_id 
144093 , p_source_3 => p_source_3
144094 , p_source_11 => p_source_11
144095          , x_transaction_coa_id       => l_adr_transaction_coa_id
144096          , x_accounting_coa_id        => l_adr_accounting_coa_id
144097          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
144098          , x_flex_value_set_id        => l_adr_flex_value_set_id
144099          , x_value_type_code          => l_adr_value_type_code
144100          , x_value_combination_id     => l_adr_value_combination_id
144101          , x_value_segment_code       => l_adr_value_segment_code
144102          , p_side                     => 'NA'
144103          , p_override_seg_flag        => 'Y'
144104    );
144105 
144109           p_to_segment_code         => 'GL_ACCOUNT'
144106    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
144107 
144108       xla_ae_lines_pkg.set_segment(
144110         , p_segment_value           => l_segment
144111         , p_from_segment_code       => l_adr_value_segment_code
144112         , p_from_combination_id     => l_adr_value_combination_id
144113         , p_value_type_code         => l_adr_value_type_code
144114         , p_transaction_coa_id      => l_adr_transaction_coa_id
144115         , p_accounting_coa_id       => l_adr_accounting_coa_id
144116         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
144117         , p_flex_value_set_id       => l_adr_flex_value_set_id
144118         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
144119         , p_adr_type_code           => 'S'
144120         , p_component_type          => l_component_type
144121         , p_component_code          => l_component_code
144122         , p_component_type_code     => l_component_type_code
144123         , p_component_appl_id       => l_component_appl_id
144124         , p_amb_context_code        => l_amb_context_code
144125         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
144126         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
144127         , p_side                    => 'NA'
144128         );
144129 
144130   END IF;
144131 
144132    l_segment := AcctDerRule_168(
144133            p_application_id           => p_application_id
144134          , p_ae_header_id             => l_ae_header_id 
144135 , p_source_3 => p_source_3
144136 , p_source_29 => p_source_29
144137          , x_transaction_coa_id       => l_adr_transaction_coa_id
144138          , x_accounting_coa_id        => l_adr_accounting_coa_id
144139          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
144140          , x_flex_value_set_id        => l_adr_flex_value_set_id
144141          , x_value_type_code          => l_adr_value_type_code
144142          , x_value_combination_id     => l_adr_value_combination_id
144143          , x_value_segment_code       => l_adr_value_segment_code
144144          , p_side                     => 'NA'
144145          , p_override_seg_flag        => 'Y'
144146    );
144147 
144148    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
144149 
144150       xla_ae_lines_pkg.set_segment(
144151           p_to_segment_code         => 'GL_BALANCING'
144152         , p_segment_value           => l_segment
144153         , p_from_segment_code       => l_adr_value_segment_code
144154         , p_from_combination_id     => l_adr_value_combination_id
144155         , p_value_type_code         => l_adr_value_type_code
144156         , p_transaction_coa_id      => l_adr_transaction_coa_id
144157         , p_accounting_coa_id       => l_adr_accounting_coa_id
144158         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
144159         , p_flex_value_set_id       => l_adr_flex_value_set_id
144160         , p_adr_code                => 'FA_EXPENSE_ACCT'
144161         , p_adr_type_code           => 'S'
144162         , p_component_type          => l_component_type
144163         , p_component_code          => l_component_code
144164         , p_component_type_code     => l_component_type_code
144165         , p_component_appl_id       => l_component_appl_id
144166         , p_amb_context_code        => l_amb_context_code
144167         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
144168         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
144169         , p_side                    => 'NA'
144170         );
144171 
144172   END IF;
144173 
144174    --
144175    --
144176    END IF;
144177    --
144178    -- Bug 4922099
144179    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
144180           (NVL(l_enc_upg_option, 'N') = 'O')
144181         ) AND
144182         (l_bflow_method_code = 'PRIOR_ENTRY')
144183       )
144184    THEN
144185       IF
144186       --
144187       1 = 2
144188       --
144189       THEN
144190       xla_accounting_err_pkg.build_message
144191                                     (p_appli_s_name            => 'XLA'
144192                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
144193                                     ,p_token_1                 => 'LINE_NUMBER'
144194                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
144195                                     ,p_token_2                 => 'LINE_TYPE_NAME'
144196                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
144197                                                                              l_component_type
144198                                                                             ,l_component_code
144199                                                                             ,l_component_type_code
144200                                                                             ,l_component_appl_id
144201                                                                             ,l_amb_context_code
144202                                                                             ,l_entity_code
144203                                                                             ,l_event_class_code
144204                                                                            )
144205                                     ,p_token_3                 => 'OWNER'
144206                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
144207                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
144208                                                                           ,p_lookup_code    => l_component_type_code
144209                                                                          )
144210                                     ,p_token_4                 => 'PRODUCT_NAME'
144211                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
144215                                     ,p_ae_header_id            =>  NULL
144212                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
144213                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
144214                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
144216                                        );
144217 
144218         IF (C_LEVEL_ERROR>= g_log_level) THEN
144219                  trace
144220                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
144221                       ,p_level    => C_LEVEL_ERROR
144222                       ,p_module   => l_log_module);
144223         END IF;
144224       END IF;
144225    END IF;
144226    --
144227    --
144228    ------------------------------------------------------------------------------------------------
144229    -- 4219869 Business Flow
144230    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
144231    -- Prior Entry.  Currently, the following code is always generated.
144232    ------------------------------------------------------------------------------------------------
144233    XLA_AE_LINES_PKG.ValidateCurrentLine;
144234 
144235    ------------------------------------------------------------------------------------
144236    -- 4219869 Business Flow
144237    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
144238    ------------------------------------------------------------------------------------
144239    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
144240 
144241    ----------------------------------------------------------------------------------
144242    -- 4219869 Business Flow
144243    -- Update journal entry status -- Need to generate this within IF <condition>
144244    ----------------------------------------------------------------------------------
144245    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
144246          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
144247          ,p_balance_type_code => l_balance_type_code
144248          );
144249 
144250    -------------------------------------------------------------------------------------------
144251    -- 4262811 - Generate the Accrual Reversal lines
144252    -------------------------------------------------------------------------------------------
144253    BEGIN
144254       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
144255                               (g_array_event(p_event_id).array_value_num('header_index'));
144256       IF l_acc_rev_flag IS NULL THEN
144257          l_acc_rev_flag := 'N';
144258       END IF;
144259    EXCEPTION
144260       WHEN OTHERS THEN
144261          l_acc_rev_flag := 'N';
144262    END;
144263    --
144264    IF (l_acc_rev_flag = 'Y') THEN
144265 
144266        -- 4645092  ------------------------------------------------------------------------------
144267        -- To allow MPA report to determine if it should generate report process
144268        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
144269        ------------------------------------------------------------------------------------------
144270 
144271        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
144272        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
144273    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
144274    -- call ADRs
144275    -- Bug 4922099
144276    --
144277    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
144278         (NVL(l_actual_upg_option, 'N') = 'O') OR
144279         (NVL(l_enc_upg_option, 'N') = 'O')
144280       )
144281    THEN
144282    NULL;
144283    --
144284    --
144285    
144286   l_ccid := AcctDerRule_174(
144287            p_application_id           => p_application_id
144288          , p_ae_header_id             => l_ae_header_id 
144289 , p_source_3 => p_source_3
144290 , p_source_17 => p_source_17
144291 , p_source_30 => p_source_30
144292          , x_transaction_coa_id       => l_adr_transaction_coa_id
144293          , x_accounting_coa_id        => l_adr_accounting_coa_id
144294          , x_value_type_code          => l_adr_value_type_code
144295          , p_side                     => 'NA'
144296    );
144297 
144298    xla_ae_lines_pkg.set_ccid(
144299     p_code_combination_id          => l_ccid
144300   , p_value_type_code              => l_adr_value_type_code
144301   , p_transaction_coa_id           => l_adr_transaction_coa_id
144302   , p_accounting_coa_id            => l_adr_accounting_coa_id
144303   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
144304   , p_adr_type_code                => 'S'
144305   , p_component_type               => l_component_type
144306   , p_component_code               => l_component_code
144307   , p_component_type_code          => l_component_type_code
144308   , p_component_appl_id            => l_component_appl_id
144309   , p_amb_context_code             => l_amb_context_code
144310   , p_side                         => 'NA'
144311   );
144312 
144313 
144314    l_segment := AcctDerRule_150(
144315            p_application_id           => p_application_id
144316          , p_ae_header_id             => l_ae_header_id 
144317 , p_source_3 => p_source_3
144318 , p_source_11 => p_source_11
144319          , x_transaction_coa_id       => l_adr_transaction_coa_id
144320          , x_accounting_coa_id        => l_adr_accounting_coa_id
144321          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
144322          , x_flex_value_set_id        => l_adr_flex_value_set_id
144323          , x_value_type_code          => l_adr_value_type_code
144324          , x_value_combination_id     => l_adr_value_combination_id
144325          , x_value_segment_code       => l_adr_value_segment_code
144326          , p_side                     => 'NA'
144327          , p_override_seg_flag        => 'Y'
144328    );
144329 
144333           p_to_segment_code         => 'GL_ACCOUNT'
144330    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
144331 
144332       xla_ae_lines_pkg.set_segment(
144334         , p_segment_value           => l_segment
144335         , p_from_segment_code       => l_adr_value_segment_code
144336         , p_from_combination_id     => l_adr_value_combination_id
144337         , p_value_type_code         => l_adr_value_type_code
144338         , p_transaction_coa_id      => l_adr_transaction_coa_id
144339         , p_accounting_coa_id       => l_adr_accounting_coa_id
144340         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
144341         , p_flex_value_set_id       => l_adr_flex_value_set_id
144342         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
144343         , p_adr_type_code           => 'S'
144344         , p_component_type          => l_component_type
144345         , p_component_code          => l_component_code
144346         , p_component_type_code     => l_component_type_code
144347         , p_component_appl_id       => l_component_appl_id
144348         , p_amb_context_code        => l_amb_context_code
144349         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
144350         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
144351         , p_side                    => 'NA'
144352         );
144353 
144354   END IF;
144355 
144356    l_segment := AcctDerRule_168(
144357            p_application_id           => p_application_id
144358          , p_ae_header_id             => l_ae_header_id 
144359 , p_source_3 => p_source_3
144360 , p_source_29 => p_source_29
144361          , x_transaction_coa_id       => l_adr_transaction_coa_id
144362          , x_accounting_coa_id        => l_adr_accounting_coa_id
144363          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
144364          , x_flex_value_set_id        => l_adr_flex_value_set_id
144365          , x_value_type_code          => l_adr_value_type_code
144366          , x_value_combination_id     => l_adr_value_combination_id
144367          , x_value_segment_code       => l_adr_value_segment_code
144368          , p_side                     => 'NA'
144369          , p_override_seg_flag        => 'Y'
144370    );
144371 
144372    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
144373 
144374       xla_ae_lines_pkg.set_segment(
144375           p_to_segment_code         => 'GL_BALANCING'
144376         , p_segment_value           => l_segment
144377         , p_from_segment_code       => l_adr_value_segment_code
144378         , p_from_combination_id     => l_adr_value_combination_id
144379         , p_value_type_code         => l_adr_value_type_code
144380         , p_transaction_coa_id      => l_adr_transaction_coa_id
144381         , p_accounting_coa_id       => l_adr_accounting_coa_id
144382         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
144383         , p_flex_value_set_id       => l_adr_flex_value_set_id
144384         , p_adr_code                => 'FA_EXPENSE_ACCT'
144385         , p_adr_type_code           => 'S'
144386         , p_component_type          => l_component_type
144387         , p_component_code          => l_component_code
144388         , p_component_type_code     => l_component_type_code
144389         , p_component_appl_id       => l_component_appl_id
144390         , p_amb_context_code        => l_amb_context_code
144391         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
144392         , p_event_class_code        => 'CIP_SOURCE_LINE_TRANSFERS'
144393         , p_side                    => 'NA'
144394         );
144395 
144396   END IF;
144397 
144398    --
144399    --
144400    END IF;
144401 
144402        --
144403        -- Update the line information that should be overwritten
144404        --
144405        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
144406                                          p_header_num   => 1);
144407        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
144408 
144409        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
144410 
144411        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
144412           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
144413        END IF;
144414 
144415       --
144416       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
144417       --
144418       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
144419           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
144420       ELSE
144421           ---------------------------------------------------------------------------------------------------
144422           -- 4262811a Switch Sign
144423           ---------------------------------------------------------------------------------------------------
144424           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
144425           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
144426                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
144427           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
144428                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
144429           -- 5132302
144430           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
144431                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
144432 
144433       END IF;
144434 
144435       -- 4955764
144436       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
144437       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
144438 
144439 
144443       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
144440       XLA_AE_LINES_PKG.ValidateCurrentLine;
144441       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
144442 
144444                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
144445                ,p_balance_type_code => l_balance_type_code);
144446 
144447    END IF;
144448 
144449    -----------------------------------------------------------------------------------------
144450    -- 4262811 Multiperiod Accounting
144451    -----------------------------------------------------------------------------------------
144452      -- No MPA option is assigned.
144453 
144454 
144455 END IF;
144456 END IF;
144457 --
144458 
144459 --
144460 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
144461    trace
144462       (p_msg      => 'END of AcctLineType_356'
144463       ,p_level    => C_LEVEL_PROCEDURE
144464       ,p_module   => l_log_module);
144465 END IF;
144466 --
144467 EXCEPTION
144468   WHEN xla_exceptions_pkg.application_exception THEN
144469       RAISE;
144470   WHEN OTHERS THEN
144471        xla_exceptions_pkg.raise_message
144472            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_356');
144473 END AcctLineType_356;
144474 --
144475 
144476 ---------------------------------------
144477 --
144478 -- PRIVATE FUNCTION
144479 --         AcctLineType_357
144480 --
144481 ---------------------------------------
144482 PROCEDURE AcctLineType_357 (
144483   p_application_id        IN NUMBER
144484  ,p_event_id              IN NUMBER
144485  ,p_calculate_acctd_flag  IN VARCHAR2
144486  ,p_calculate_g_l_flag    IN VARCHAR2
144487  ,p_actual_flag           IN OUT VARCHAR2
144488  ,p_balance_type_code     OUT VARCHAR2
144489  ,p_gain_or_loss_ref      OUT VARCHAR2
144490  
144491 --Period Close Date
144492  , p_source_1            IN DATE
144493 --Generated Code Combination Identifier
144494  , p_source_3            IN NUMBER
144495 --Asset Cost Account
144496  , p_source_9            IN VARCHAR2
144497 --Expense Account Code Combination Identifier
144498  , p_source_29            IN NUMBER
144499 --Default Code Combination Identifier
144500  , p_source_30            IN NUMBER
144501 --Adjustment Type
144502  , p_source_35            IN VARCHAR2
144503 --Transaction Header Identifier
144504  , p_source_36            IN NUMBER
144505 --Adjustment Line Identifier
144506  , p_source_37            IN NUMBER
144507 --Distribution Type Code
144508  , p_source_38            IN VARCHAR2
144509 --Entered Amount
144510  , p_source_39            IN NUMBER
144511 --Currency Code
144512  , p_source_40            IN VARCHAR2
144513 --Source Destination Code
144514  , p_source_42            IN VARCHAR2
144515 )
144516 IS
144517 
144518 l_component_type              VARCHAR2(80);
144519 l_component_code              VARCHAR2(30);
144520 l_component_type_code         VARCHAR2(1);
144521 l_component_appl_id           INTEGER;
144522 l_amb_context_code            VARCHAR2(30);
144523 l_entity_code                 VARCHAR2(30);
144524 l_event_class_code            VARCHAR2(30);
144525 l_ae_header_id                NUMBER;
144526 l_event_type_code             VARCHAR2(30);
144527 l_line_definition_code        VARCHAR2(30);
144528 l_line_definition_owner_code  VARCHAR2(1);
144529 --
144530 -- adr variables
144531 l_segment                     VARCHAR2(30);
144532 l_ccid                        NUMBER;
144533 l_adr_transaction_coa_id      NUMBER;
144534 l_adr_accounting_coa_id       NUMBER;
144535 l_adr_flexfield_segment_code  VARCHAR2(30);
144536 l_adr_flex_value_set_id       NUMBER;
144537 l_adr_value_type_code         VARCHAR2(30);
144538 l_adr_value_combination_id    NUMBER;
144539 l_adr_value_segment_code      VARCHAR2(30);
144540 
144541 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
144542 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
144543 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
144544 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
144545 
144546 -- 4262811 Variables ------------------------------------------------------------------------------------------
144547 l_entered_amt_idx             NUMBER;
144548 l_accted_amt_idx              NUMBER;
144549 l_acc_rev_flag                VARCHAR2(1);
144550 l_accrual_line_num            NUMBER;
144551 l_tmp_amt                     NUMBER;
144552 l_acc_rev_natural_side_code   VARCHAR2(1);
144553 
144554 l_num_entries                 NUMBER;
144555 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
144556 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
144557 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
144558 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
144559 l_recog_line_1                NUMBER;
144560 l_recog_line_2                NUMBER;
144561 
144562 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
144563 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
144564 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
144565 
144566 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
144567 
144568 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
144569 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
144570 
144571 ---------------------------------------------------------------------------------------------------------------
144572 
144573 
144574 --
144575 -- bulk performance
144576 --
144577 l_balance_type_code           VARCHAR2(1);
144578 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
144579 l_log_module                  VARCHAR2(240);
144580 
144581 --
144582 -- Upgrade strategy
144583 --
144587 --
144584 l_actual_upg_option           VARCHAR2(1);
144585 l_enc_upg_option           VARCHAR2(1);
144586 
144588 BEGIN
144589 --
144590 IF g_log_enabled THEN
144591       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_357';
144592 END IF;
144593 --
144594 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
144595 
144596       trace
144597          (p_msg      => 'BEGIN of AcctLineType_357'
144598          ,p_level    => C_LEVEL_PROCEDURE
144599          ,p_module   => l_log_module);
144600 
144601 END IF;
144602 --
144603 l_component_type             := 'AMB_JLT';
144604 l_component_code             := 'FA_SLT_SOURCE_COST';
144605 l_component_type_code        := 'S';
144606 l_component_appl_id          :=  140;
144607 l_amb_context_code           := 'DEFAULT';
144608 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
144609 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
144610 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
144611 l_line_definition_owner_code := 'S';
144612 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
144613 --
144614 l_balance_type_code          := 'A';
144615 l_segment                     := NULL;
144616 l_ccid                        := NULL;
144617 l_adr_transaction_coa_id      := NULL;
144618 l_adr_accounting_coa_id       := NULL;
144619 l_adr_flexfield_segment_code  := NULL;
144620 l_adr_flex_value_set_id       := NULL;
144621 l_adr_value_type_code         := NULL;
144622 l_adr_value_combination_id    := NULL;
144623 l_adr_value_segment_code      := NULL;
144624 
144625 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
144626 l_bflow_class_code           := '';    -- 4219869 Business Flow
144627 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
144628 l_budgetary_control_flag     := 'N';
144629 
144630 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
144631 l_bflow_applied_to_amt       := NULL; -- 5132302
144632 l_entered_amt_idx            := NULL;          -- 4262811
144633 l_accted_amt_idx             := NULL;          -- 4262811
144634 l_acc_rev_flag               := NULL;          -- 4262811
144635 l_accrual_line_num           := NULL;          -- 4262811
144636 l_tmp_amt                    := NULL;          -- 4262811
144637 --
144638  
144639 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
144640     l_balance_type_code <> 'B' THEN
144641 IF NVL(p_source_35,'
144642 ') =  'COST' AND 
144643 NVL(p_source_42,'
144644 ') =  'SOURCE'
144645  THEN 
144646 
144647    --
144648    XLA_AE_LINES_PKG.SetNewLine;
144649 
144650    p_balance_type_code          := l_balance_type_code;
144651    -- set the flag so later we will know whether the gain loss line needs to be created
144652    
144653    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
144654      p_actual_flag :='A';
144655    END IF;
144656 
144657    --
144658    -- bulk performance
144659    --
144660    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
144661                                       p_header_num   => 0); -- 4262811
144662    --
144663    -- set accounting line options
144664    --
144665    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
144666            p_natural_side_code          => 'C'
144667          , p_gain_or_loss_flag          => 'N'
144668          , p_gl_transfer_mode_code      => 'S'
144669          , p_acct_entry_type_code       => 'A'
144670          , p_switch_side_flag           => 'Y'
144671          , p_merge_duplicate_code       => 'N'
144672          );
144673    --
144674    l_acc_rev_natural_side_code := 'D';  -- 4262811
144675    -- 
144676    --
144677    -- set accounting line type info
144678    --
144679    xla_ae_lines_pkg.SetAcctLineType
144680       (p_component_type             => l_component_type
144681       ,p_event_type_code            => l_event_type_code
144682       ,p_line_definition_owner_code => l_line_definition_owner_code
144683       ,p_line_definition_code       => l_line_definition_code
144684       ,p_accounting_line_code       => l_component_code
144685       ,p_accounting_line_type_code  => l_component_type_code
144686       ,p_accounting_line_appl_id    => l_component_appl_id
144687       ,p_amb_context_code           => l_amb_context_code
144688       ,p_entity_code                => l_entity_code
144689       ,p_event_class_code           => l_event_class_code);
144690    --
144691    -- set accounting class
144692    --
144693    xla_ae_lines_pkg.SetAcctClass(
144694            p_accounting_class_code  => 'ASSET'
144695          , p_ae_header_id           => l_ae_header_id
144696          );
144697 
144698    --
144699    -- set rounding class
144700    --
144701    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
144702                       'ASSET';
144703 
144704    --
144705    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
144706    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
144707    --
144708    -- bulk performance
144709    --
144710    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
144711 
144712    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
144713       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
144714 
144715    -- 4955764
144716    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
144717       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
144718 
144719    -- 4458381 Public Sector Enh
144720    
144721    --
144722    -- set accounting attributes for the line type
144723    --
144724    l_entered_amt_idx := 4;
144725    l_accted_amt_idx  := 6;
144729    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
144726    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
144727    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
144728    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
144730    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
144731    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
144732    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
144733    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
144734    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
144735    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
144736    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
144737    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
144738    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
144739 
144740    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
144741    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
144742 
144743    ---------------------------------------------------------------------------------------------------------------
144744    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
144745    ---------------------------------------------------------------------------------------------------------------
144746    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
144747 
144748    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
144749    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
144750 
144751    IF xla_accounting_cache_pkg.GetValueChar
144752          (p_source_code         => 'LEDGER_CATEGORY_CODE'
144753          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
144754    AND l_bflow_method_code = 'PRIOR_ENTRY'
144755 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
144756    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
144757          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
144758        )
144759    THEN
144760          xla_ae_lines_pkg.BflowUpgEntry
144761            (p_business_method_code    => l_bflow_method_code
144762            ,p_business_class_code     => l_bflow_class_code
144763            ,p_balance_type            => l_balance_type_code);
144764    ELSE
144765       NULL;
144766 -- No business flow processing for business flow method of NONE.
144767    END IF;
144768 
144769    --
144770    -- call analytical criteria
144771    --
144772    
144773    --
144774    -- call description
144775    --
144776    
144777 xla_ae_lines_pkg.SetLineDescription(
144778    p_ae_header_id => l_ae_header_id
144779   ,p_description  => Description_110 (
144780      p_application_id         => p_application_id
144781    , p_ae_header_id           => l_ae_header_id 
144782 , p_source_1 => p_source_1
144783    )
144784 );
144785 
144786 
144787    --
144788    -- call ADRs
144789    -- Bug 4922099
144790    --
144791    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
144792         (NVL(l_actual_upg_option, 'N') = 'O') OR
144793         (NVL(l_enc_upg_option, 'N') = 'O')
144794       )
144795    THEN
144796    NULL;
144797    --
144798    --
144799    
144800   l_ccid := AcctDerRule_173(
144801            p_application_id           => p_application_id
144802          , p_ae_header_id             => l_ae_header_id 
144803 , p_source_3 => p_source_3
144804 , p_source_30 => p_source_30
144805          , x_transaction_coa_id       => l_adr_transaction_coa_id
144806          , x_accounting_coa_id        => l_adr_accounting_coa_id
144807          , x_value_type_code          => l_adr_value_type_code
144808          , p_side                     => 'NA'
144809    );
144810 
144811    xla_ae_lines_pkg.set_ccid(
144812     p_code_combination_id          => l_ccid
144813   , p_value_type_code              => l_adr_value_type_code
144814   , p_transaction_coa_id           => l_adr_transaction_coa_id
144815   , p_accounting_coa_id            => l_adr_accounting_coa_id
144816   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
144817   , p_adr_type_code                => 'S'
144818   , p_component_type               => l_component_type
144819   , p_component_code               => l_component_code
144820   , p_component_type_code          => l_component_type_code
144821   , p_component_appl_id            => l_component_appl_id
144822   , p_amb_context_code             => l_amb_context_code
144823   , p_side                         => 'NA'
144824   );
144825 
144826 
144827    l_segment := AcctDerRule_148(
144828            p_application_id           => p_application_id
144829          , p_ae_header_id             => l_ae_header_id 
144830 , p_source_3 => p_source_3
144831 , p_source_9 => p_source_9
144832          , x_transaction_coa_id       => l_adr_transaction_coa_id
144833          , x_accounting_coa_id        => l_adr_accounting_coa_id
144834          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
144835          , x_flex_value_set_id        => l_adr_flex_value_set_id
144836          , x_value_type_code          => l_adr_value_type_code
144837          , x_value_combination_id     => l_adr_value_combination_id
144838          , x_value_segment_code       => l_adr_value_segment_code
144839          , p_side                     => 'NA'
144840          , p_override_seg_flag        => 'Y'
144841    );
144842 
144843    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
144844 
144845       xla_ae_lines_pkg.set_segment(
144846           p_to_segment_code         => 'GL_ACCOUNT'
144847         , p_segment_value           => l_segment
144848         , p_from_segment_code       => l_adr_value_segment_code
144849         , p_from_combination_id     => l_adr_value_combination_id
144853         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
144850         , p_value_type_code         => l_adr_value_type_code
144851         , p_transaction_coa_id      => l_adr_transaction_coa_id
144852         , p_accounting_coa_id       => l_adr_accounting_coa_id
144854         , p_flex_value_set_id       => l_adr_flex_value_set_id
144855         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
144856         , p_adr_type_code           => 'S'
144857         , p_component_type          => l_component_type
144858         , p_component_code          => l_component_code
144859         , p_component_type_code     => l_component_type_code
144860         , p_component_appl_id       => l_component_appl_id
144861         , p_amb_context_code        => l_amb_context_code
144862         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
144863         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
144864         , p_side                    => 'NA'
144865         );
144866 
144867   END IF;
144868 
144869    l_segment := AcctDerRule_168(
144870            p_application_id           => p_application_id
144871          , p_ae_header_id             => l_ae_header_id 
144872 , p_source_3 => p_source_3
144873 , p_source_29 => p_source_29
144874          , x_transaction_coa_id       => l_adr_transaction_coa_id
144875          , x_accounting_coa_id        => l_adr_accounting_coa_id
144876          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
144877          , x_flex_value_set_id        => l_adr_flex_value_set_id
144878          , x_value_type_code          => l_adr_value_type_code
144879          , x_value_combination_id     => l_adr_value_combination_id
144880          , x_value_segment_code       => l_adr_value_segment_code
144881          , p_side                     => 'NA'
144882          , p_override_seg_flag        => 'Y'
144883    );
144884 
144885    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
144886 
144887       xla_ae_lines_pkg.set_segment(
144888           p_to_segment_code         => 'GL_BALANCING'
144889         , p_segment_value           => l_segment
144890         , p_from_segment_code       => l_adr_value_segment_code
144891         , p_from_combination_id     => l_adr_value_combination_id
144892         , p_value_type_code         => l_adr_value_type_code
144893         , p_transaction_coa_id      => l_adr_transaction_coa_id
144894         , p_accounting_coa_id       => l_adr_accounting_coa_id
144895         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
144896         , p_flex_value_set_id       => l_adr_flex_value_set_id
144897         , p_adr_code                => 'FA_EXPENSE_ACCT'
144898         , p_adr_type_code           => 'S'
144899         , p_component_type          => l_component_type
144900         , p_component_code          => l_component_code
144901         , p_component_type_code     => l_component_type_code
144902         , p_component_appl_id       => l_component_appl_id
144903         , p_amb_context_code        => l_amb_context_code
144904         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
144905         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
144906         , p_side                    => 'NA'
144907         );
144908 
144909   END IF;
144910 
144911    --
144912    --
144913    END IF;
144914    --
144915    -- Bug 4922099
144916    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
144917           (NVL(l_enc_upg_option, 'N') = 'O')
144918         ) AND
144919         (l_bflow_method_code = 'PRIOR_ENTRY')
144920       )
144921    THEN
144922       IF
144923       --
144924       1 = 2
144925       --
144926       THEN
144927       xla_accounting_err_pkg.build_message
144928                                     (p_appli_s_name            => 'XLA'
144929                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
144930                                     ,p_token_1                 => 'LINE_NUMBER'
144931                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
144932                                     ,p_token_2                 => 'LINE_TYPE_NAME'
144933                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
144934                                                                              l_component_type
144935                                                                             ,l_component_code
144936                                                                             ,l_component_type_code
144937                                                                             ,l_component_appl_id
144938                                                                             ,l_amb_context_code
144939                                                                             ,l_entity_code
144940                                                                             ,l_event_class_code
144941                                                                            )
144942                                     ,p_token_3                 => 'OWNER'
144943                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
144944                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
144945                                                                           ,p_lookup_code    => l_component_type_code
144946                                                                          )
144947                                     ,p_token_4                 => 'PRODUCT_NAME'
144948                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
144949                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
144950                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
144951                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
144952                                     ,p_ae_header_id            =>  NULL
144956                  trace
144953                                        );
144954 
144955         IF (C_LEVEL_ERROR>= g_log_level) THEN
144957                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
144958                       ,p_level    => C_LEVEL_ERROR
144959                       ,p_module   => l_log_module);
144960         END IF;
144961       END IF;
144962    END IF;
144963    --
144964    --
144965    ------------------------------------------------------------------------------------------------
144966    -- 4219869 Business Flow
144967    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
144968    -- Prior Entry.  Currently, the following code is always generated.
144969    ------------------------------------------------------------------------------------------------
144970    XLA_AE_LINES_PKG.ValidateCurrentLine;
144971 
144972    ------------------------------------------------------------------------------------
144973    -- 4219869 Business Flow
144974    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
144975    ------------------------------------------------------------------------------------
144976    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
144977 
144978    ----------------------------------------------------------------------------------
144979    -- 4219869 Business Flow
144980    -- Update journal entry status -- Need to generate this within IF <condition>
144981    ----------------------------------------------------------------------------------
144982    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
144983          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
144984          ,p_balance_type_code => l_balance_type_code
144985          );
144986 
144987    -------------------------------------------------------------------------------------------
144988    -- 4262811 - Generate the Accrual Reversal lines
144989    -------------------------------------------------------------------------------------------
144990    BEGIN
144991       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
144992                               (g_array_event(p_event_id).array_value_num('header_index'));
144993       IF l_acc_rev_flag IS NULL THEN
144994          l_acc_rev_flag := 'N';
144995       END IF;
144996    EXCEPTION
144997       WHEN OTHERS THEN
144998          l_acc_rev_flag := 'N';
144999    END;
145000    --
145001    IF (l_acc_rev_flag = 'Y') THEN
145002 
145003        -- 4645092  ------------------------------------------------------------------------------
145004        -- To allow MPA report to determine if it should generate report process
145005        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
145006        ------------------------------------------------------------------------------------------
145007 
145008        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
145009        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
145010    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
145011    -- call ADRs
145012    -- Bug 4922099
145013    --
145014    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
145015         (NVL(l_actual_upg_option, 'N') = 'O') OR
145016         (NVL(l_enc_upg_option, 'N') = 'O')
145017       )
145018    THEN
145019    NULL;
145020    --
145021    --
145022    
145023   l_ccid := AcctDerRule_173(
145024            p_application_id           => p_application_id
145025          , p_ae_header_id             => l_ae_header_id 
145026 , p_source_3 => p_source_3
145027 , p_source_30 => p_source_30
145028          , x_transaction_coa_id       => l_adr_transaction_coa_id
145029          , x_accounting_coa_id        => l_adr_accounting_coa_id
145030          , x_value_type_code          => l_adr_value_type_code
145031          , p_side                     => 'NA'
145032    );
145033 
145034    xla_ae_lines_pkg.set_ccid(
145035     p_code_combination_id          => l_ccid
145036   , p_value_type_code              => l_adr_value_type_code
145037   , p_transaction_coa_id           => l_adr_transaction_coa_id
145038   , p_accounting_coa_id            => l_adr_accounting_coa_id
145039   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
145040   , p_adr_type_code                => 'S'
145041   , p_component_type               => l_component_type
145042   , p_component_code               => l_component_code
145043   , p_component_type_code          => l_component_type_code
145044   , p_component_appl_id            => l_component_appl_id
145045   , p_amb_context_code             => l_amb_context_code
145046   , p_side                         => 'NA'
145047   );
145048 
145049 
145050    l_segment := AcctDerRule_148(
145051            p_application_id           => p_application_id
145052          , p_ae_header_id             => l_ae_header_id 
145053 , p_source_3 => p_source_3
145054 , p_source_9 => p_source_9
145055          , x_transaction_coa_id       => l_adr_transaction_coa_id
145056          , x_accounting_coa_id        => l_adr_accounting_coa_id
145057          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
145058          , x_flex_value_set_id        => l_adr_flex_value_set_id
145059          , x_value_type_code          => l_adr_value_type_code
145060          , x_value_combination_id     => l_adr_value_combination_id
145061          , x_value_segment_code       => l_adr_value_segment_code
145062          , p_side                     => 'NA'
145063          , p_override_seg_flag        => 'Y'
145064    );
145065 
145066    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
145067 
145068       xla_ae_lines_pkg.set_segment(
145069           p_to_segment_code         => 'GL_ACCOUNT'
145070         , p_segment_value           => l_segment
145071         , p_from_segment_code       => l_adr_value_segment_code
145072         , p_from_combination_id     => l_adr_value_combination_id
145073         , p_value_type_code         => l_adr_value_type_code
145077         , p_flex_value_set_id       => l_adr_flex_value_set_id
145074         , p_transaction_coa_id      => l_adr_transaction_coa_id
145075         , p_accounting_coa_id       => l_adr_accounting_coa_id
145076         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
145078         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
145079         , p_adr_type_code           => 'S'
145080         , p_component_type          => l_component_type
145081         , p_component_code          => l_component_code
145082         , p_component_type_code     => l_component_type_code
145083         , p_component_appl_id       => l_component_appl_id
145084         , p_amb_context_code        => l_amb_context_code
145085         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
145086         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
145087         , p_side                    => 'NA'
145088         );
145089 
145090   END IF;
145091 
145092    l_segment := AcctDerRule_168(
145093            p_application_id           => p_application_id
145094          , p_ae_header_id             => l_ae_header_id 
145095 , p_source_3 => p_source_3
145096 , p_source_29 => p_source_29
145097          , x_transaction_coa_id       => l_adr_transaction_coa_id
145098          , x_accounting_coa_id        => l_adr_accounting_coa_id
145099          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
145100          , x_flex_value_set_id        => l_adr_flex_value_set_id
145101          , x_value_type_code          => l_adr_value_type_code
145102          , x_value_combination_id     => l_adr_value_combination_id
145103          , x_value_segment_code       => l_adr_value_segment_code
145104          , p_side                     => 'NA'
145105          , p_override_seg_flag        => 'Y'
145106    );
145107 
145108    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
145109 
145110       xla_ae_lines_pkg.set_segment(
145111           p_to_segment_code         => 'GL_BALANCING'
145112         , p_segment_value           => l_segment
145113         , p_from_segment_code       => l_adr_value_segment_code
145114         , p_from_combination_id     => l_adr_value_combination_id
145115         , p_value_type_code         => l_adr_value_type_code
145116         , p_transaction_coa_id      => l_adr_transaction_coa_id
145117         , p_accounting_coa_id       => l_adr_accounting_coa_id
145118         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
145119         , p_flex_value_set_id       => l_adr_flex_value_set_id
145120         , p_adr_code                => 'FA_EXPENSE_ACCT'
145121         , p_adr_type_code           => 'S'
145122         , p_component_type          => l_component_type
145123         , p_component_code          => l_component_code
145124         , p_component_type_code     => l_component_type_code
145125         , p_component_appl_id       => l_component_appl_id
145126         , p_amb_context_code        => l_amb_context_code
145127         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
145128         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
145129         , p_side                    => 'NA'
145130         );
145131 
145132   END IF;
145133 
145134    --
145135    --
145136    END IF;
145137 
145138        --
145139        -- Update the line information that should be overwritten
145140        --
145141        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
145142                                          p_header_num   => 1);
145143        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
145144 
145145        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
145146 
145147        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
145148           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
145149        END IF;
145150 
145151       --
145152       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
145153       --
145154       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
145155           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
145156       ELSE
145157           ---------------------------------------------------------------------------------------------------
145158           -- 4262811a Switch Sign
145159           ---------------------------------------------------------------------------------------------------
145160           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
145161           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
145162                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
145163           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
145164                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
145165           -- 5132302
145166           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
145167                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
145168 
145169       END IF;
145170 
145171       -- 4955764
145172       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
145173       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
145174 
145175 
145176       XLA_AE_LINES_PKG.ValidateCurrentLine;
145177       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
145178 
145179       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
145180                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
145181                ,p_balance_type_code => l_balance_type_code);
145182 
145183    END IF;
145184 
145188      -- No MPA option is assigned.
145185    -----------------------------------------------------------------------------------------
145186    -- 4262811 Multiperiod Accounting
145187    -----------------------------------------------------------------------------------------
145189 
145190 
145191 END IF;
145192 END IF;
145193 --
145194 
145195 --
145196 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
145197    trace
145198       (p_msg      => 'END of AcctLineType_357'
145199       ,p_level    => C_LEVEL_PROCEDURE
145200       ,p_module   => l_log_module);
145201 END IF;
145202 --
145203 EXCEPTION
145204   WHEN xla_exceptions_pkg.application_exception THEN
145205       RAISE;
145206   WHEN OTHERS THEN
145207        xla_exceptions_pkg.raise_message
145208            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_357');
145209 END AcctLineType_357;
145210 --
145211 
145212 ---------------------------------------
145213 --
145214 -- PRIVATE FUNCTION
145215 --         AcctLineType_358
145216 --
145217 ---------------------------------------
145218 PROCEDURE AcctLineType_358 (
145219   p_application_id        IN NUMBER
145220  ,p_event_id              IN NUMBER
145221  ,p_calculate_acctd_flag  IN VARCHAR2
145222  ,p_calculate_g_l_flag    IN VARCHAR2
145223  ,p_actual_flag           IN OUT VARCHAR2
145224  ,p_balance_type_code     OUT VARCHAR2
145225  ,p_gain_or_loss_ref      OUT VARCHAR2
145226  
145227 --Period Close Date
145228  , p_source_1            IN DATE
145229 --Generated Code Combination Identifier
145230  , p_source_3            IN NUMBER
145231 --Payables Code Combination Identifier
145232  , p_source_6            IN NUMBER
145233 --Asset Clearing Account
145234  , p_source_8            IN VARCHAR2
145235 --Expense Account Code Combination Identifier
145236  , p_source_29            IN NUMBER
145237 --Default Code Combination Identifier
145238  , p_source_30            IN NUMBER
145239 --Adjustment Type
145240  , p_source_35            IN VARCHAR2
145241 --Transaction Header Identifier
145242  , p_source_36            IN NUMBER
145243 --Adjustment Line Identifier
145244  , p_source_37            IN NUMBER
145245 --Distribution Type Code
145246  , p_source_38            IN VARCHAR2
145247 --Entered Amount
145248  , p_source_39            IN NUMBER
145249 --Currency Code
145250  , p_source_40            IN VARCHAR2
145251 --Source Destination Code
145252  , p_source_42            IN VARCHAR2
145253 )
145254 IS
145255 
145256 l_component_type              VARCHAR2(80);
145257 l_component_code              VARCHAR2(30);
145258 l_component_type_code         VARCHAR2(1);
145259 l_component_appl_id           INTEGER;
145260 l_amb_context_code            VARCHAR2(30);
145261 l_entity_code                 VARCHAR2(30);
145262 l_event_class_code            VARCHAR2(30);
145263 l_ae_header_id                NUMBER;
145264 l_event_type_code             VARCHAR2(30);
145265 l_line_definition_code        VARCHAR2(30);
145266 l_line_definition_owner_code  VARCHAR2(1);
145267 --
145268 -- adr variables
145269 l_segment                     VARCHAR2(30);
145270 l_ccid                        NUMBER;
145271 l_adr_transaction_coa_id      NUMBER;
145272 l_adr_accounting_coa_id       NUMBER;
145273 l_adr_flexfield_segment_code  VARCHAR2(30);
145274 l_adr_flex_value_set_id       NUMBER;
145275 l_adr_value_type_code         VARCHAR2(30);
145276 l_adr_value_combination_id    NUMBER;
145277 l_adr_value_segment_code      VARCHAR2(30);
145278 
145279 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
145280 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
145281 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
145282 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
145283 
145284 -- 4262811 Variables ------------------------------------------------------------------------------------------
145285 l_entered_amt_idx             NUMBER;
145286 l_accted_amt_idx              NUMBER;
145287 l_acc_rev_flag                VARCHAR2(1);
145288 l_accrual_line_num            NUMBER;
145289 l_tmp_amt                     NUMBER;
145290 l_acc_rev_natural_side_code   VARCHAR2(1);
145291 
145292 l_num_entries                 NUMBER;
145293 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
145294 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
145295 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
145296 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
145297 l_recog_line_1                NUMBER;
145298 l_recog_line_2                NUMBER;
145299 
145300 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
145301 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
145302 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
145303 
145304 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
145305 
145306 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
145307 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
145308 
145309 ---------------------------------------------------------------------------------------------------------------
145310 
145311 
145312 --
145313 -- bulk performance
145314 --
145315 l_balance_type_code           VARCHAR2(1);
145316 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
145317 l_log_module                  VARCHAR2(240);
145318 
145319 --
145320 -- Upgrade strategy
145321 --
145322 l_actual_upg_option           VARCHAR2(1);
145323 l_enc_upg_option           VARCHAR2(1);
145324 
145325 --
145326 BEGIN
145327 --
145328 IF g_log_enabled THEN
145329       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_358';
145330 END IF;
145331 --
145335          (p_msg      => 'BEGIN of AcctLineType_358'
145332 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
145333 
145334       trace
145336          ,p_level    => C_LEVEL_PROCEDURE
145337          ,p_module   => l_log_module);
145338 
145339 END IF;
145340 --
145341 l_component_type             := 'AMB_JLT';
145342 l_component_code             := 'FA_SLT_SOURCE_COST_CLEARING';
145343 l_component_type_code        := 'S';
145344 l_component_appl_id          :=  140;
145345 l_amb_context_code           := 'DEFAULT';
145346 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
145347 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
145348 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
145349 l_line_definition_owner_code := 'S';
145350 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
145351 --
145352 l_balance_type_code          := 'A';
145353 l_segment                     := NULL;
145354 l_ccid                        := NULL;
145355 l_adr_transaction_coa_id      := NULL;
145356 l_adr_accounting_coa_id       := NULL;
145357 l_adr_flexfield_segment_code  := NULL;
145358 l_adr_flex_value_set_id       := NULL;
145359 l_adr_value_type_code         := NULL;
145360 l_adr_value_combination_id    := NULL;
145361 l_adr_value_segment_code      := NULL;
145362 
145363 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
145364 l_bflow_class_code           := '';    -- 4219869 Business Flow
145365 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
145366 l_budgetary_control_flag     := 'N';
145367 
145368 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
145369 l_bflow_applied_to_amt       := NULL; -- 5132302
145370 l_entered_amt_idx            := NULL;          -- 4262811
145371 l_accted_amt_idx             := NULL;          -- 4262811
145372 l_acc_rev_flag               := NULL;          -- 4262811
145373 l_accrual_line_num           := NULL;          -- 4262811
145374 l_tmp_amt                    := NULL;          -- 4262811
145375 --
145376  
145377 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
145378     l_balance_type_code <> 'B' THEN
145379 IF NVL(p_source_35,'
145380 ') =  'COST CLEARING' AND 
145381 NVL(p_source_42,'
145382 ') =  'SOURCE'
145383  THEN 
145384 
145385    --
145386    XLA_AE_LINES_PKG.SetNewLine;
145387 
145388    p_balance_type_code          := l_balance_type_code;
145389    -- set the flag so later we will know whether the gain loss line needs to be created
145390    
145391    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
145392      p_actual_flag :='A';
145393    END IF;
145394 
145395    --
145396    -- bulk performance
145397    --
145398    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
145399                                       p_header_num   => 0); -- 4262811
145400    --
145401    -- set accounting line options
145402    --
145403    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
145404            p_natural_side_code          => 'D'
145405          , p_gain_or_loss_flag          => 'N'
145406          , p_gl_transfer_mode_code      => 'S'
145407          , p_acct_entry_type_code       => 'A'
145408          , p_switch_side_flag           => 'Y'
145409          , p_merge_duplicate_code       => 'N'
145410          );
145411    --
145412    l_acc_rev_natural_side_code := 'C';  -- 4262811
145413    -- 
145414    --
145415    -- set accounting line type info
145416    --
145417    xla_ae_lines_pkg.SetAcctLineType
145418       (p_component_type             => l_component_type
145419       ,p_event_type_code            => l_event_type_code
145420       ,p_line_definition_owner_code => l_line_definition_owner_code
145421       ,p_line_definition_code       => l_line_definition_code
145422       ,p_accounting_line_code       => l_component_code
145423       ,p_accounting_line_type_code  => l_component_type_code
145424       ,p_accounting_line_appl_id    => l_component_appl_id
145425       ,p_amb_context_code           => l_amb_context_code
145426       ,p_entity_code                => l_entity_code
145427       ,p_event_class_code           => l_event_class_code);
145428    --
145429    -- set accounting class
145430    --
145431    xla_ae_lines_pkg.SetAcctClass(
145432            p_accounting_class_code  => 'ASSET'
145433          , p_ae_header_id           => l_ae_header_id
145434          );
145435 
145436    --
145437    -- set rounding class
145438    --
145439    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
145440                       'ASSET';
145441 
145442    --
145443    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
145444    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
145445    --
145446    -- bulk performance
145447    --
145448    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
145449 
145450    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
145451       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
145452 
145453    -- 4955764
145454    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
145455       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
145456 
145457    -- 4458381 Public Sector Enh
145458    
145459    --
145460    -- set accounting attributes for the line type
145461    --
145462    l_entered_amt_idx := 4;
145463    l_accted_amt_idx  := 6;
145464    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
145465    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
145466    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
145467    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
145471    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
145468    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
145469    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
145470    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
145472    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
145473    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
145474    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
145475    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
145476    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
145477 
145478    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
145479    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
145480 
145481    ---------------------------------------------------------------------------------------------------------------
145482    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
145483    ---------------------------------------------------------------------------------------------------------------
145484    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
145485 
145486    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
145487    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
145488 
145489    IF xla_accounting_cache_pkg.GetValueChar
145490          (p_source_code         => 'LEDGER_CATEGORY_CODE'
145491          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
145492    AND l_bflow_method_code = 'PRIOR_ENTRY'
145493 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
145494    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
145495          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
145496        )
145497    THEN
145498          xla_ae_lines_pkg.BflowUpgEntry
145499            (p_business_method_code    => l_bflow_method_code
145500            ,p_business_class_code     => l_bflow_class_code
145501            ,p_balance_type            => l_balance_type_code);
145502    ELSE
145503       NULL;
145504 -- No business flow processing for business flow method of NONE.
145505    END IF;
145506 
145507    --
145508    -- call analytical criteria
145509    --
145510    
145511    --
145512    -- call description
145513    --
145514    
145515 xla_ae_lines_pkg.SetLineDescription(
145516    p_ae_header_id => l_ae_header_id
145517   ,p_description  => Description_111 (
145518      p_application_id         => p_application_id
145519    , p_ae_header_id           => l_ae_header_id 
145520 , p_source_1 => p_source_1
145521    )
145522 );
145523 
145524 
145525    --
145526    -- call ADRs
145527    -- Bug 4922099
145528    --
145529    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
145530         (NVL(l_actual_upg_option, 'N') = 'O') OR
145531         (NVL(l_enc_upg_option, 'N') = 'O')
145532       )
145533    THEN
145534    NULL;
145535    --
145536    --
145537    
145538   l_ccid := AcctDerRule_172(
145539            p_application_id           => p_application_id
145540          , p_ae_header_id             => l_ae_header_id 
145541 , p_source_3 => p_source_3
145542 , p_source_6 => p_source_6
145543 , p_source_30 => p_source_30
145544          , x_transaction_coa_id       => l_adr_transaction_coa_id
145545          , x_accounting_coa_id        => l_adr_accounting_coa_id
145546          , x_value_type_code          => l_adr_value_type_code
145547          , p_side                     => 'NA'
145548    );
145549 
145550    xla_ae_lines_pkg.set_ccid(
145551     p_code_combination_id          => l_ccid
145552   , p_value_type_code              => l_adr_value_type_code
145553   , p_transaction_coa_id           => l_adr_transaction_coa_id
145554   , p_accounting_coa_id            => l_adr_accounting_coa_id
145555   , p_adr_code                     => 'FA_CAT_COST_CLEARING'
145556   , p_adr_type_code                => 'S'
145557   , p_component_type               => l_component_type
145558   , p_component_code               => l_component_code
145559   , p_component_type_code          => l_component_type_code
145560   , p_component_appl_id            => l_component_appl_id
145561   , p_amb_context_code             => l_amb_context_code
145562   , p_side                         => 'NA'
145563   );
145564 
145565 
145566    l_segment := AcctDerRule_147(
145567            p_application_id           => p_application_id
145568          , p_ae_header_id             => l_ae_header_id 
145569 , p_source_3 => p_source_3
145570 , p_source_6 => p_source_6
145571 , p_source_8 => p_source_8
145572          , x_transaction_coa_id       => l_adr_transaction_coa_id
145573          , x_accounting_coa_id        => l_adr_accounting_coa_id
145574          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
145575          , x_flex_value_set_id        => l_adr_flex_value_set_id
145576          , x_value_type_code          => l_adr_value_type_code
145577          , x_value_combination_id     => l_adr_value_combination_id
145578          , x_value_segment_code       => l_adr_value_segment_code
145579          , p_side                     => 'NA'
145580          , p_override_seg_flag        => 'Y'
145581    );
145582 
145583    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
145584 
145585       xla_ae_lines_pkg.set_segment(
145586           p_to_segment_code         => 'GL_ACCOUNT'
145587         , p_segment_value           => l_segment
145588         , p_from_segment_code       => l_adr_value_segment_code
145589         , p_from_combination_id     => l_adr_value_combination_id
145590         , p_value_type_code         => l_adr_value_type_code
145591         , p_transaction_coa_id      => l_adr_transaction_coa_id
145592         , p_accounting_coa_id       => l_adr_accounting_coa_id
145596         , p_adr_type_code           => 'S'
145593         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
145594         , p_flex_value_set_id       => l_adr_flex_value_set_id
145595         , p_adr_code                => 'FA_CAT_CLR_ACCOUNT_SEGMENT'
145597         , p_component_type          => l_component_type
145598         , p_component_code          => l_component_code
145599         , p_component_type_code     => l_component_type_code
145600         , p_component_appl_id       => l_component_appl_id
145601         , p_amb_context_code        => l_amb_context_code
145602         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
145603         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
145604         , p_side                    => 'NA'
145605         );
145606 
145607   END IF;
145608 
145609    l_segment := AcctDerRule_169(
145610            p_application_id           => p_application_id
145611          , p_ae_header_id             => l_ae_header_id 
145612 , p_source_3 => p_source_3
145613 , p_source_6 => p_source_6
145614 , p_source_29 => p_source_29
145615          , x_transaction_coa_id       => l_adr_transaction_coa_id
145616          , x_accounting_coa_id        => l_adr_accounting_coa_id
145617          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
145618          , x_flex_value_set_id        => l_adr_flex_value_set_id
145619          , x_value_type_code          => l_adr_value_type_code
145620          , x_value_combination_id     => l_adr_value_combination_id
145621          , x_value_segment_code       => l_adr_value_segment_code
145622          , p_side                     => 'NA'
145623          , p_override_seg_flag        => 'Y'
145624    );
145625 
145626    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
145627 
145628       xla_ae_lines_pkg.set_segment(
145629           p_to_segment_code         => 'GL_BALANCING'
145630         , p_segment_value           => l_segment
145631         , p_from_segment_code       => l_adr_value_segment_code
145632         , p_from_combination_id     => l_adr_value_combination_id
145633         , p_value_type_code         => l_adr_value_type_code
145634         , p_transaction_coa_id      => l_adr_transaction_coa_id
145635         , p_accounting_coa_id       => l_adr_accounting_coa_id
145636         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
145637         , p_flex_value_set_id       => l_adr_flex_value_set_id
145638         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
145639         , p_adr_type_code           => 'S'
145640         , p_component_type          => l_component_type
145641         , p_component_code          => l_component_code
145642         , p_component_type_code     => l_component_type_code
145643         , p_component_appl_id       => l_component_appl_id
145644         , p_amb_context_code        => l_amb_context_code
145645         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
145646         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
145647         , p_side                    => 'NA'
145648         );
145649 
145650   END IF;
145651 
145652    --
145653    --
145654    END IF;
145655    --
145656    -- Bug 4922099
145657    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
145658           (NVL(l_enc_upg_option, 'N') = 'O')
145659         ) AND
145660         (l_bflow_method_code = 'PRIOR_ENTRY')
145661       )
145662    THEN
145663       IF
145664       --
145665       1 = 2
145666       --
145667       THEN
145668       xla_accounting_err_pkg.build_message
145669                                     (p_appli_s_name            => 'XLA'
145670                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
145671                                     ,p_token_1                 => 'LINE_NUMBER'
145672                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
145673                                     ,p_token_2                 => 'LINE_TYPE_NAME'
145674                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
145675                                                                              l_component_type
145676                                                                             ,l_component_code
145677                                                                             ,l_component_type_code
145678                                                                             ,l_component_appl_id
145679                                                                             ,l_amb_context_code
145680                                                                             ,l_entity_code
145681                                                                             ,l_event_class_code
145682                                                                            )
145683                                     ,p_token_3                 => 'OWNER'
145684                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
145685                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
145686                                                                           ,p_lookup_code    => l_component_type_code
145687                                                                          )
145688                                     ,p_token_4                 => 'PRODUCT_NAME'
145689                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
145690                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
145691                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
145692                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
145693                                     ,p_ae_header_id            =>  NULL
145694                                        );
145695 
145696         IF (C_LEVEL_ERROR>= g_log_level) THEN
145697                  trace
145701         END IF;
145698                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
145699                       ,p_level    => C_LEVEL_ERROR
145700                       ,p_module   => l_log_module);
145702       END IF;
145703    END IF;
145704    --
145705    --
145706    ------------------------------------------------------------------------------------------------
145707    -- 4219869 Business Flow
145708    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
145709    -- Prior Entry.  Currently, the following code is always generated.
145710    ------------------------------------------------------------------------------------------------
145711    XLA_AE_LINES_PKG.ValidateCurrentLine;
145712 
145713    ------------------------------------------------------------------------------------
145714    -- 4219869 Business Flow
145715    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
145716    ------------------------------------------------------------------------------------
145717    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
145718 
145719    ----------------------------------------------------------------------------------
145720    -- 4219869 Business Flow
145721    -- Update journal entry status -- Need to generate this within IF <condition>
145722    ----------------------------------------------------------------------------------
145723    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
145724          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
145725          ,p_balance_type_code => l_balance_type_code
145726          );
145727 
145728    -------------------------------------------------------------------------------------------
145729    -- 4262811 - Generate the Accrual Reversal lines
145730    -------------------------------------------------------------------------------------------
145731    BEGIN
145732       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
145733                               (g_array_event(p_event_id).array_value_num('header_index'));
145734       IF l_acc_rev_flag IS NULL THEN
145735          l_acc_rev_flag := 'N';
145736       END IF;
145737    EXCEPTION
145738       WHEN OTHERS THEN
145739          l_acc_rev_flag := 'N';
145740    END;
145741    --
145742    IF (l_acc_rev_flag = 'Y') THEN
145743 
145744        -- 4645092  ------------------------------------------------------------------------------
145745        -- To allow MPA report to determine if it should generate report process
145746        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
145747        ------------------------------------------------------------------------------------------
145748 
145749        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
145750        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
145751    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
145752    -- call ADRs
145753    -- Bug 4922099
145754    --
145755    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
145756         (NVL(l_actual_upg_option, 'N') = 'O') OR
145757         (NVL(l_enc_upg_option, 'N') = 'O')
145758       )
145759    THEN
145760    NULL;
145761    --
145762    --
145763    
145764   l_ccid := AcctDerRule_172(
145765            p_application_id           => p_application_id
145766          , p_ae_header_id             => l_ae_header_id 
145767 , p_source_3 => p_source_3
145768 , p_source_6 => p_source_6
145769 , p_source_30 => p_source_30
145770          , x_transaction_coa_id       => l_adr_transaction_coa_id
145771          , x_accounting_coa_id        => l_adr_accounting_coa_id
145772          , x_value_type_code          => l_adr_value_type_code
145773          , p_side                     => 'NA'
145774    );
145775 
145776    xla_ae_lines_pkg.set_ccid(
145777     p_code_combination_id          => l_ccid
145778   , p_value_type_code              => l_adr_value_type_code
145779   , p_transaction_coa_id           => l_adr_transaction_coa_id
145780   , p_accounting_coa_id            => l_adr_accounting_coa_id
145781   , p_adr_code                     => 'FA_CAT_COST_CLEARING'
145782   , p_adr_type_code                => 'S'
145783   , p_component_type               => l_component_type
145784   , p_component_code               => l_component_code
145785   , p_component_type_code          => l_component_type_code
145786   , p_component_appl_id            => l_component_appl_id
145787   , p_amb_context_code             => l_amb_context_code
145788   , p_side                         => 'NA'
145789   );
145790 
145791 
145792    l_segment := AcctDerRule_147(
145793            p_application_id           => p_application_id
145794          , p_ae_header_id             => l_ae_header_id 
145795 , p_source_3 => p_source_3
145796 , p_source_6 => p_source_6
145797 , p_source_8 => p_source_8
145798          , x_transaction_coa_id       => l_adr_transaction_coa_id
145799          , x_accounting_coa_id        => l_adr_accounting_coa_id
145800          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
145801          , x_flex_value_set_id        => l_adr_flex_value_set_id
145802          , x_value_type_code          => l_adr_value_type_code
145803          , x_value_combination_id     => l_adr_value_combination_id
145804          , x_value_segment_code       => l_adr_value_segment_code
145805          , p_side                     => 'NA'
145806          , p_override_seg_flag        => 'Y'
145807    );
145808 
145809    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
145810 
145811       xla_ae_lines_pkg.set_segment(
145812           p_to_segment_code         => 'GL_ACCOUNT'
145813         , p_segment_value           => l_segment
145814         , p_from_segment_code       => l_adr_value_segment_code
145815         , p_from_combination_id     => l_adr_value_combination_id
145816         , p_value_type_code         => l_adr_value_type_code
145817         , p_transaction_coa_id      => l_adr_transaction_coa_id
145821         , p_adr_code                => 'FA_CAT_CLR_ACCOUNT_SEGMENT'
145818         , p_accounting_coa_id       => l_adr_accounting_coa_id
145819         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
145820         , p_flex_value_set_id       => l_adr_flex_value_set_id
145822         , p_adr_type_code           => 'S'
145823         , p_component_type          => l_component_type
145824         , p_component_code          => l_component_code
145825         , p_component_type_code     => l_component_type_code
145826         , p_component_appl_id       => l_component_appl_id
145827         , p_amb_context_code        => l_amb_context_code
145828         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
145829         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
145830         , p_side                    => 'NA'
145831         );
145832 
145833   END IF;
145834 
145835    l_segment := AcctDerRule_169(
145836            p_application_id           => p_application_id
145837          , p_ae_header_id             => l_ae_header_id 
145838 , p_source_3 => p_source_3
145839 , p_source_6 => p_source_6
145840 , p_source_29 => p_source_29
145841          , x_transaction_coa_id       => l_adr_transaction_coa_id
145842          , x_accounting_coa_id        => l_adr_accounting_coa_id
145843          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
145844          , x_flex_value_set_id        => l_adr_flex_value_set_id
145845          , x_value_type_code          => l_adr_value_type_code
145846          , x_value_combination_id     => l_adr_value_combination_id
145847          , x_value_segment_code       => l_adr_value_segment_code
145848          , p_side                     => 'NA'
145849          , p_override_seg_flag        => 'Y'
145850    );
145851 
145852    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
145853 
145854       xla_ae_lines_pkg.set_segment(
145855           p_to_segment_code         => 'GL_BALANCING'
145856         , p_segment_value           => l_segment
145857         , p_from_segment_code       => l_adr_value_segment_code
145858         , p_from_combination_id     => l_adr_value_combination_id
145859         , p_value_type_code         => l_adr_value_type_code
145860         , p_transaction_coa_id      => l_adr_transaction_coa_id
145861         , p_accounting_coa_id       => l_adr_accounting_coa_id
145862         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
145863         , p_flex_value_set_id       => l_adr_flex_value_set_id
145864         , p_adr_code                => 'FA_EXPENSE_ACCT_PAY'
145865         , p_adr_type_code           => 'S'
145866         , p_component_type          => l_component_type
145867         , p_component_code          => l_component_code
145868         , p_component_type_code     => l_component_type_code
145869         , p_component_appl_id       => l_component_appl_id
145870         , p_amb_context_code        => l_amb_context_code
145871         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
145872         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
145873         , p_side                    => 'NA'
145874         );
145875 
145876   END IF;
145877 
145878    --
145879    --
145880    END IF;
145881 
145882        --
145883        -- Update the line information that should be overwritten
145884        --
145885        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
145886                                          p_header_num   => 1);
145887        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
145888 
145889        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
145890 
145891        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
145892           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
145893        END IF;
145894 
145895       --
145896       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
145897       --
145898       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
145899           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
145900       ELSE
145901           ---------------------------------------------------------------------------------------------------
145902           -- 4262811a Switch Sign
145903           ---------------------------------------------------------------------------------------------------
145904           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
145905           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
145906                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
145907           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
145908                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
145909           -- 5132302
145910           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
145911                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
145912 
145913       END IF;
145914 
145915       -- 4955764
145916       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
145917       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
145918 
145919 
145920       XLA_AE_LINES_PKG.ValidateCurrentLine;
145921       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
145922 
145923       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
145924                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
145925                ,p_balance_type_code => l_balance_type_code);
145926 
145927    END IF;
145928 
145929    -----------------------------------------------------------------------------------------
145933 
145930    -- 4262811 Multiperiod Accounting
145931    -----------------------------------------------------------------------------------------
145932      -- No MPA option is assigned.
145934 
145935 END IF;
145936 END IF;
145937 --
145938 
145939 --
145940 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
145941    trace
145942       (p_msg      => 'END of AcctLineType_358'
145943       ,p_level    => C_LEVEL_PROCEDURE
145944       ,p_module   => l_log_module);
145945 END IF;
145946 --
145947 EXCEPTION
145948   WHEN xla_exceptions_pkg.application_exception THEN
145949       RAISE;
145950   WHEN OTHERS THEN
145951        xla_exceptions_pkg.raise_message
145952            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_358');
145953 END AcctLineType_358;
145954 --
145955 
145956 ---------------------------------------
145957 --
145958 -- PRIVATE FUNCTION
145959 --         AcctLineType_359
145960 --
145961 ---------------------------------------
145962 PROCEDURE AcctLineType_359 (
145963   p_application_id        IN NUMBER
145964  ,p_event_id              IN NUMBER
145965  ,p_calculate_acctd_flag  IN VARCHAR2
145966  ,p_calculate_g_l_flag    IN VARCHAR2
145967  ,p_actual_flag           IN OUT VARCHAR2
145968  ,p_balance_type_code     OUT VARCHAR2
145969  ,p_gain_or_loss_ref      OUT VARCHAR2
145970  
145971 --Period Close Date
145972  , p_source_1            IN DATE
145973 --Generated Code Combination Identifier
145974  , p_source_3            IN NUMBER
145975 --Expense Account Code Combination Identifier
145976  , p_source_29            IN NUMBER
145977 --Adjustment Type
145978  , p_source_35            IN VARCHAR2
145979 --Transaction Header Identifier
145980  , p_source_36            IN NUMBER
145981 --Adjustment Line Identifier
145982  , p_source_37            IN NUMBER
145983 --Distribution Type Code
145984  , p_source_38            IN VARCHAR2
145985 --Entered Amount
145986  , p_source_39            IN NUMBER
145987 --Currency Code
145988  , p_source_40            IN VARCHAR2
145989 --Source Destination Code
145990  , p_source_42            IN VARCHAR2
145991 )
145992 IS
145993 
145994 l_component_type              VARCHAR2(80);
145995 l_component_code              VARCHAR2(30);
145996 l_component_type_code         VARCHAR2(1);
145997 l_component_appl_id           INTEGER;
145998 l_amb_context_code            VARCHAR2(30);
145999 l_entity_code                 VARCHAR2(30);
146000 l_event_class_code            VARCHAR2(30);
146001 l_ae_header_id                NUMBER;
146002 l_event_type_code             VARCHAR2(30);
146003 l_line_definition_code        VARCHAR2(30);
146004 l_line_definition_owner_code  VARCHAR2(1);
146005 --
146006 -- adr variables
146007 l_segment                     VARCHAR2(30);
146008 l_ccid                        NUMBER;
146009 l_adr_transaction_coa_id      NUMBER;
146010 l_adr_accounting_coa_id       NUMBER;
146011 l_adr_flexfield_segment_code  VARCHAR2(30);
146012 l_adr_flex_value_set_id       NUMBER;
146013 l_adr_value_type_code         VARCHAR2(30);
146014 l_adr_value_combination_id    NUMBER;
146015 l_adr_value_segment_code      VARCHAR2(30);
146016 
146017 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
146018 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
146019 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
146020 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
146021 
146022 -- 4262811 Variables ------------------------------------------------------------------------------------------
146023 l_entered_amt_idx             NUMBER;
146024 l_accted_amt_idx              NUMBER;
146025 l_acc_rev_flag                VARCHAR2(1);
146026 l_accrual_line_num            NUMBER;
146027 l_tmp_amt                     NUMBER;
146028 l_acc_rev_natural_side_code   VARCHAR2(1);
146029 
146030 l_num_entries                 NUMBER;
146031 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
146032 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
146033 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
146034 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
146035 l_recog_line_1                NUMBER;
146036 l_recog_line_2                NUMBER;
146037 
146038 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
146039 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
146040 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
146041 
146042 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
146043 
146044 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
146045 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
146046 
146047 ---------------------------------------------------------------------------------------------------------------
146048 
146049 
146050 --
146051 -- bulk performance
146052 --
146053 l_balance_type_code           VARCHAR2(1);
146054 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
146055 l_log_module                  VARCHAR2(240);
146056 
146057 --
146058 -- Upgrade strategy
146059 --
146060 l_actual_upg_option           VARCHAR2(1);
146061 l_enc_upg_option           VARCHAR2(1);
146062 
146063 --
146064 BEGIN
146065 --
146066 IF g_log_enabled THEN
146067       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_359';
146068 END IF;
146069 --
146070 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
146071 
146072       trace
146073          (p_msg      => 'BEGIN of AcctLineType_359'
146074          ,p_level    => C_LEVEL_PROCEDURE
146075          ,p_module   => l_log_module);
146076 
146077 END IF;
146078 --
146079 l_component_type             := 'AMB_JLT';
146083 l_amb_context_code           := 'DEFAULT';
146080 l_component_code             := 'FA_SLT_SOURCE_DEPRN_EXP';
146081 l_component_type_code        := 'S';
146082 l_component_appl_id          :=  140;
146084 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
146085 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
146086 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
146087 l_line_definition_owner_code := 'S';
146088 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
146089 --
146090 l_balance_type_code          := 'A';
146091 l_segment                     := NULL;
146092 l_ccid                        := NULL;
146093 l_adr_transaction_coa_id      := NULL;
146094 l_adr_accounting_coa_id       := NULL;
146095 l_adr_flexfield_segment_code  := NULL;
146096 l_adr_flex_value_set_id       := NULL;
146097 l_adr_value_type_code         := NULL;
146098 l_adr_value_combination_id    := NULL;
146099 l_adr_value_segment_code      := NULL;
146100 
146101 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
146102 l_bflow_class_code           := '';    -- 4219869 Business Flow
146103 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
146104 l_budgetary_control_flag     := 'N';
146105 
146106 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
146107 l_bflow_applied_to_amt       := NULL; -- 5132302
146108 l_entered_amt_idx            := NULL;          -- 4262811
146109 l_accted_amt_idx             := NULL;          -- 4262811
146110 l_acc_rev_flag               := NULL;          -- 4262811
146111 l_accrual_line_num           := NULL;          -- 4262811
146112 l_tmp_amt                    := NULL;          -- 4262811
146113 --
146114  
146115 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
146116     l_balance_type_code <> 'B' THEN
146117 IF NVL(p_source_35,'
146118 ') =  'EXPENSE' AND 
146119 NVL(p_source_42,'
146120 ') =  'SOURCE'
146121  THEN 
146122 
146123    --
146124    XLA_AE_LINES_PKG.SetNewLine;
146125 
146126    p_balance_type_code          := l_balance_type_code;
146127    -- set the flag so later we will know whether the gain loss line needs to be created
146128    
146129    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
146130      p_actual_flag :='A';
146131    END IF;
146132 
146133    --
146134    -- bulk performance
146135    --
146136    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
146137                                       p_header_num   => 0); -- 4262811
146138    --
146139    -- set accounting line options
146140    --
146141    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
146142            p_natural_side_code          => 'C'
146143          , p_gain_or_loss_flag          => 'N'
146144          , p_gl_transfer_mode_code      => 'S'
146145          , p_acct_entry_type_code       => 'A'
146146          , p_switch_side_flag           => 'Y'
146147          , p_merge_duplicate_code       => 'N'
146148          );
146149    --
146150    l_acc_rev_natural_side_code := 'D';  -- 4262811
146151    -- 
146152    --
146153    -- set accounting line type info
146154    --
146155    xla_ae_lines_pkg.SetAcctLineType
146156       (p_component_type             => l_component_type
146157       ,p_event_type_code            => l_event_type_code
146158       ,p_line_definition_owner_code => l_line_definition_owner_code
146159       ,p_line_definition_code       => l_line_definition_code
146160       ,p_accounting_line_code       => l_component_code
146161       ,p_accounting_line_type_code  => l_component_type_code
146162       ,p_accounting_line_appl_id    => l_component_appl_id
146163       ,p_amb_context_code           => l_amb_context_code
146164       ,p_entity_code                => l_entity_code
146165       ,p_event_class_code           => l_event_class_code);
146166    --
146167    -- set accounting class
146168    --
146169    xla_ae_lines_pkg.SetAcctClass(
146170            p_accounting_class_code  => 'EXPENSE'
146171          , p_ae_header_id           => l_ae_header_id
146172          );
146173 
146174    --
146175    -- set rounding class
146176    --
146177    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
146178                       'EXPENSE';
146179 
146180    --
146181    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
146182    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
146183    --
146184    -- bulk performance
146185    --
146186    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
146187 
146188    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
146189       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
146190 
146191    -- 4955764
146192    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
146193       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
146194 
146195    -- 4458381 Public Sector Enh
146196    
146197    --
146198    -- set accounting attributes for the line type
146199    --
146200    l_entered_amt_idx := 4;
146201    l_accted_amt_idx  := 6;
146202    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
146203    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
146204    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
146205    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
146206    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
146207    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
146208    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
146209    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
146210    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
146214    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
146211    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
146212    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
146213    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
146215 
146216    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
146217    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
146218 
146219    ---------------------------------------------------------------------------------------------------------------
146220    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
146221    ---------------------------------------------------------------------------------------------------------------
146222    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
146223 
146224    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
146225    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
146226 
146227    IF xla_accounting_cache_pkg.GetValueChar
146228          (p_source_code         => 'LEDGER_CATEGORY_CODE'
146229          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
146230    AND l_bflow_method_code = 'PRIOR_ENTRY'
146231 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
146232    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
146233          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
146234        )
146235    THEN
146236          xla_ae_lines_pkg.BflowUpgEntry
146237            (p_business_method_code    => l_bflow_method_code
146238            ,p_business_class_code     => l_bflow_class_code
146239            ,p_balance_type            => l_balance_type_code);
146240    ELSE
146241       NULL;
146242 -- No business flow processing for business flow method of NONE.
146243    END IF;
146244 
146245    --
146246    -- call analytical criteria
146247    --
146248    
146249    --
146250    -- call description
146251    --
146252    
146253 xla_ae_lines_pkg.SetLineDescription(
146254    p_ae_header_id => l_ae_header_id
146255   ,p_description  => Description_112 (
146256      p_application_id         => p_application_id
146257    , p_ae_header_id           => l_ae_header_id 
146258 , p_source_1 => p_source_1
146259    )
146260 );
146261 
146262 
146263    --
146264    -- call ADRs
146265    -- Bug 4922099
146266    --
146267    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
146268         (NVL(l_actual_upg_option, 'N') = 'O') OR
146269         (NVL(l_enc_upg_option, 'N') = 'O')
146270       )
146271    THEN
146272    NULL;
146273    --
146274    --
146275    
146276   l_ccid := AcctDerRule_175(
146277            p_application_id           => p_application_id
146278          , p_ae_header_id             => l_ae_header_id 
146279 , p_source_3 => p_source_3
146280 , p_source_29 => p_source_29
146281          , x_transaction_coa_id       => l_adr_transaction_coa_id
146282          , x_accounting_coa_id        => l_adr_accounting_coa_id
146283          , x_value_type_code          => l_adr_value_type_code
146284          , p_side                     => 'NA'
146285    );
146286 
146287    xla_ae_lines_pkg.set_ccid(
146288     p_code_combination_id          => l_ccid
146289   , p_value_type_code              => l_adr_value_type_code
146290   , p_transaction_coa_id           => l_adr_transaction_coa_id
146291   , p_accounting_coa_id            => l_adr_accounting_coa_id
146292   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
146293   , p_adr_type_code                => 'S'
146294   , p_component_type               => l_component_type
146295   , p_component_code               => l_component_code
146296   , p_component_type_code          => l_component_type_code
146297   , p_component_appl_id            => l_component_appl_id
146298   , p_amb_context_code             => l_amb_context_code
146299   , p_side                         => 'NA'
146300   );
146301 
146302 
146303    --
146304    --
146305    END IF;
146306    --
146307    -- Bug 4922099
146308    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
146309           (NVL(l_enc_upg_option, 'N') = 'O')
146310         ) AND
146311         (l_bflow_method_code = 'PRIOR_ENTRY')
146312       )
146313    THEN
146314       IF
146315       --
146316       1 = 2
146317       --
146318       THEN
146319       xla_accounting_err_pkg.build_message
146320                                     (p_appli_s_name            => 'XLA'
146321                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
146322                                     ,p_token_1                 => 'LINE_NUMBER'
146323                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
146324                                     ,p_token_2                 => 'LINE_TYPE_NAME'
146325                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
146326                                                                              l_component_type
146327                                                                             ,l_component_code
146328                                                                             ,l_component_type_code
146329                                                                             ,l_component_appl_id
146330                                                                             ,l_amb_context_code
146331                                                                             ,l_entity_code
146332                                                                             ,l_event_class_code
146333                                                                            )
146334                                     ,p_token_3                 => 'OWNER'
146338                                                                          )
146335                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
146336                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
146337                                                                           ,p_lookup_code    => l_component_type_code
146339                                     ,p_token_4                 => 'PRODUCT_NAME'
146340                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
146341                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
146342                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
146343                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
146344                                     ,p_ae_header_id            =>  NULL
146345                                        );
146346 
146347         IF (C_LEVEL_ERROR>= g_log_level) THEN
146348                  trace
146349                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
146350                       ,p_level    => C_LEVEL_ERROR
146351                       ,p_module   => l_log_module);
146352         END IF;
146353       END IF;
146354    END IF;
146355    --
146356    --
146357    ------------------------------------------------------------------------------------------------
146358    -- 4219869 Business Flow
146359    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
146360    -- Prior Entry.  Currently, the following code is always generated.
146361    ------------------------------------------------------------------------------------------------
146362    XLA_AE_LINES_PKG.ValidateCurrentLine;
146363 
146364    ------------------------------------------------------------------------------------
146365    -- 4219869 Business Flow
146366    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
146367    ------------------------------------------------------------------------------------
146368    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
146369 
146370    ----------------------------------------------------------------------------------
146371    -- 4219869 Business Flow
146372    -- Update journal entry status -- Need to generate this within IF <condition>
146373    ----------------------------------------------------------------------------------
146374    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
146375          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
146376          ,p_balance_type_code => l_balance_type_code
146377          );
146378 
146379    -------------------------------------------------------------------------------------------
146380    -- 4262811 - Generate the Accrual Reversal lines
146381    -------------------------------------------------------------------------------------------
146382    BEGIN
146383       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
146384                               (g_array_event(p_event_id).array_value_num('header_index'));
146385       IF l_acc_rev_flag IS NULL THEN
146386          l_acc_rev_flag := 'N';
146387       END IF;
146388    EXCEPTION
146389       WHEN OTHERS THEN
146390          l_acc_rev_flag := 'N';
146391    END;
146392    --
146393    IF (l_acc_rev_flag = 'Y') THEN
146394 
146395        -- 4645092  ------------------------------------------------------------------------------
146396        -- To allow MPA report to determine if it should generate report process
146397        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
146398        ------------------------------------------------------------------------------------------
146399 
146400        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
146401        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
146402    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
146403    -- call ADRs
146404    -- Bug 4922099
146405    --
146406    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
146407         (NVL(l_actual_upg_option, 'N') = 'O') OR
146408         (NVL(l_enc_upg_option, 'N') = 'O')
146409       )
146410    THEN
146411    NULL;
146412    --
146413    --
146414    
146415   l_ccid := AcctDerRule_175(
146416            p_application_id           => p_application_id
146417          , p_ae_header_id             => l_ae_header_id 
146418 , p_source_3 => p_source_3
146419 , p_source_29 => p_source_29
146420          , x_transaction_coa_id       => l_adr_transaction_coa_id
146421          , x_accounting_coa_id        => l_adr_accounting_coa_id
146422          , x_value_type_code          => l_adr_value_type_code
146423          , p_side                     => 'NA'
146424    );
146425 
146426    xla_ae_lines_pkg.set_ccid(
146427     p_code_combination_id          => l_ccid
146428   , p_value_type_code              => l_adr_value_type_code
146429   , p_transaction_coa_id           => l_adr_transaction_coa_id
146430   , p_accounting_coa_id            => l_adr_accounting_coa_id
146431   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
146432   , p_adr_type_code                => 'S'
146433   , p_component_type               => l_component_type
146434   , p_component_code               => l_component_code
146435   , p_component_type_code          => l_component_type_code
146436   , p_component_appl_id            => l_component_appl_id
146437   , p_amb_context_code             => l_amb_context_code
146438   , p_side                         => 'NA'
146439   );
146440 
146441 
146442    --
146443    --
146444    END IF;
146445 
146446        --
146447        -- Update the line information that should be overwritten
146448        --
146449        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
146450                                          p_header_num   => 1);
146454 
146451        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
146452 
146453        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
146455        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
146456           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
146457        END IF;
146458 
146459       --
146460       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
146461       --
146462       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
146463           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
146464       ELSE
146465           ---------------------------------------------------------------------------------------------------
146466           -- 4262811a Switch Sign
146467           ---------------------------------------------------------------------------------------------------
146468           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
146469           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
146470                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
146471           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
146472                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
146473           -- 5132302
146474           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
146475                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
146476 
146477       END IF;
146478 
146479       -- 4955764
146480       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
146481       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
146482 
146483 
146484       XLA_AE_LINES_PKG.ValidateCurrentLine;
146485       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
146486 
146487       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
146488                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
146489                ,p_balance_type_code => l_balance_type_code);
146490 
146491    END IF;
146492 
146493    -----------------------------------------------------------------------------------------
146494    -- 4262811 Multiperiod Accounting
146495    -----------------------------------------------------------------------------------------
146496      -- No MPA option is assigned.
146497 
146498 
146499 END IF;
146500 END IF;
146501 --
146502 
146503 --
146504 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
146505    trace
146506       (p_msg      => 'END of AcctLineType_359'
146507       ,p_level    => C_LEVEL_PROCEDURE
146508       ,p_module   => l_log_module);
146509 END IF;
146510 --
146511 EXCEPTION
146512   WHEN xla_exceptions_pkg.application_exception THEN
146513       RAISE;
146514   WHEN OTHERS THEN
146515        xla_exceptions_pkg.raise_message
146516            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_359');
146517 END AcctLineType_359;
146518 --
146519 
146520 ---------------------------------------
146521 --
146522 -- PRIVATE FUNCTION
146523 --         AcctLineType_360
146524 --
146525 ---------------------------------------
146526 PROCEDURE AcctLineType_360 (
146527   p_application_id        IN NUMBER
146528  ,p_event_id              IN NUMBER
146529  ,p_calculate_acctd_flag  IN VARCHAR2
146530  ,p_calculate_g_l_flag    IN VARCHAR2
146531  ,p_actual_flag           IN OUT VARCHAR2
146532  ,p_balance_type_code     OUT VARCHAR2
146533  ,p_gain_or_loss_ref      OUT VARCHAR2
146534  
146535 --Period Close Date
146536  , p_source_1            IN DATE
146537 --Generated Code Combination Identifier
146538  , p_source_3            IN NUMBER
146539 --Depreciation Reserve Account
146540  , p_source_10            IN VARCHAR2
146541 --Generated Offset Code Combination Identifier
146542  , p_source_17            IN NUMBER
146543 --Expense Account Code Combination Identifier
146544  , p_source_29            IN NUMBER
146545 --Default Code Combination Identifier
146546  , p_source_30            IN NUMBER
146547 --Adjustment Type
146548  , p_source_35            IN VARCHAR2
146549 --Transaction Header Identifier
146550  , p_source_36            IN NUMBER
146551 --Adjustment Line Identifier
146552  , p_source_37            IN NUMBER
146553 --Distribution Type Code
146554  , p_source_38            IN VARCHAR2
146555 --Entered Amount
146556  , p_source_39            IN NUMBER
146557 --Currency Code
146558  , p_source_40            IN VARCHAR2
146559 --Source Destination Code
146560  , p_source_42            IN VARCHAR2
146561 )
146562 IS
146563 
146564 l_component_type              VARCHAR2(80);
146565 l_component_code              VARCHAR2(30);
146566 l_component_type_code         VARCHAR2(1);
146567 l_component_appl_id           INTEGER;
146568 l_amb_context_code            VARCHAR2(30);
146569 l_entity_code                 VARCHAR2(30);
146570 l_event_class_code            VARCHAR2(30);
146571 l_ae_header_id                NUMBER;
146572 l_event_type_code             VARCHAR2(30);
146573 l_line_definition_code        VARCHAR2(30);
146574 l_line_definition_owner_code  VARCHAR2(1);
146575 --
146576 -- adr variables
146577 l_segment                     VARCHAR2(30);
146578 l_ccid                        NUMBER;
146579 l_adr_transaction_coa_id      NUMBER;
146580 l_adr_accounting_coa_id       NUMBER;
146581 l_adr_flexfield_segment_code  VARCHAR2(30);
146582 l_adr_flex_value_set_id       NUMBER;
146583 l_adr_value_type_code         VARCHAR2(30);
146584 l_adr_value_combination_id    NUMBER;
146588 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
146585 l_adr_value_segment_code      VARCHAR2(30);
146586 
146587 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
146589 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
146590 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
146591 
146592 -- 4262811 Variables ------------------------------------------------------------------------------------------
146593 l_entered_amt_idx             NUMBER;
146594 l_accted_amt_idx              NUMBER;
146595 l_acc_rev_flag                VARCHAR2(1);
146596 l_accrual_line_num            NUMBER;
146597 l_tmp_amt                     NUMBER;
146598 l_acc_rev_natural_side_code   VARCHAR2(1);
146599 
146600 l_num_entries                 NUMBER;
146601 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
146602 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
146603 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
146604 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
146605 l_recog_line_1                NUMBER;
146606 l_recog_line_2                NUMBER;
146607 
146608 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
146609 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
146610 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
146611 
146612 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
146613 
146614 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
146615 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
146616 
146617 ---------------------------------------------------------------------------------------------------------------
146618 
146619 
146620 --
146621 -- bulk performance
146622 --
146623 l_balance_type_code           VARCHAR2(1);
146624 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
146625 l_log_module                  VARCHAR2(240);
146626 
146627 --
146628 -- Upgrade strategy
146629 --
146630 l_actual_upg_option           VARCHAR2(1);
146631 l_enc_upg_option           VARCHAR2(1);
146632 
146633 --
146634 BEGIN
146635 --
146636 IF g_log_enabled THEN
146637       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_360';
146638 END IF;
146639 --
146640 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
146641 
146642       trace
146643          (p_msg      => 'BEGIN of AcctLineType_360'
146644          ,p_level    => C_LEVEL_PROCEDURE
146645          ,p_module   => l_log_module);
146646 
146647 END IF;
146648 --
146649 l_component_type             := 'AMB_JLT';
146650 l_component_code             := 'FA_SLT_SOURCE_DEPRN_RESERVE';
146651 l_component_type_code        := 'S';
146652 l_component_appl_id          :=  140;
146653 l_amb_context_code           := 'DEFAULT';
146654 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
146655 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
146656 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
146657 l_line_definition_owner_code := 'S';
146658 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
146659 --
146660 l_balance_type_code          := 'A';
146661 l_segment                     := NULL;
146662 l_ccid                        := NULL;
146663 l_adr_transaction_coa_id      := NULL;
146664 l_adr_accounting_coa_id       := NULL;
146665 l_adr_flexfield_segment_code  := NULL;
146666 l_adr_flex_value_set_id       := NULL;
146667 l_adr_value_type_code         := NULL;
146668 l_adr_value_combination_id    := NULL;
146669 l_adr_value_segment_code      := NULL;
146670 
146671 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
146672 l_bflow_class_code           := '';    -- 4219869 Business Flow
146673 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
146674 l_budgetary_control_flag     := 'N';
146675 
146676 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
146677 l_bflow_applied_to_amt       := NULL; -- 5132302
146678 l_entered_amt_idx            := NULL;          -- 4262811
146679 l_accted_amt_idx             := NULL;          -- 4262811
146680 l_acc_rev_flag               := NULL;          -- 4262811
146681 l_accrual_line_num           := NULL;          -- 4262811
146682 l_tmp_amt                    := NULL;          -- 4262811
146683 --
146684  
146685 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
146686     l_balance_type_code <> 'B' THEN
146687 IF (NVL(p_source_35,'
146688 ') =  'EXPENSE' OR 
146689 NVL(p_source_35,'
146690 ') =  'RESERVE') AND 
146691 NVL(p_source_42,'
146692 ') =  'SOURCE'
146693  THEN 
146694 
146695    --
146696    XLA_AE_LINES_PKG.SetNewLine;
146697 
146698    p_balance_type_code          := l_balance_type_code;
146699    -- set the flag so later we will know whether the gain loss line needs to be created
146700    
146701    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
146702      p_actual_flag :='A';
146703    END IF;
146704 
146705    --
146706    -- bulk performance
146707    --
146708    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
146709                                       p_header_num   => 0); -- 4262811
146710    --
146711    -- set accounting line options
146712    --
146713    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
146714            p_natural_side_code          => 'D'
146715          , p_gain_or_loss_flag          => 'N'
146716          , p_gl_transfer_mode_code      => 'S'
146717          , p_acct_entry_type_code       => 'A'
146718          , p_switch_side_flag           => 'Y'
146719          , p_merge_duplicate_code       => 'N'
146720          );
146721    --
146722    l_acc_rev_natural_side_code := 'C';  -- 4262811
146723    -- 
146724    --
146728       (p_component_type             => l_component_type
146725    -- set accounting line type info
146726    --
146727    xla_ae_lines_pkg.SetAcctLineType
146729       ,p_event_type_code            => l_event_type_code
146730       ,p_line_definition_owner_code => l_line_definition_owner_code
146731       ,p_line_definition_code       => l_line_definition_code
146732       ,p_accounting_line_code       => l_component_code
146733       ,p_accounting_line_type_code  => l_component_type_code
146734       ,p_accounting_line_appl_id    => l_component_appl_id
146735       ,p_amb_context_code           => l_amb_context_code
146736       ,p_entity_code                => l_entity_code
146737       ,p_event_class_code           => l_event_class_code);
146738    --
146739    -- set accounting class
146740    --
146741    xla_ae_lines_pkg.SetAcctClass(
146742            p_accounting_class_code  => 'ASSET'
146743          , p_ae_header_id           => l_ae_header_id
146744          );
146745 
146746    --
146747    -- set rounding class
146748    --
146749    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
146750                       'ASSET';
146751 
146752    --
146753    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
146754    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
146755    --
146756    -- bulk performance
146757    --
146758    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
146759 
146760    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
146761       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
146762 
146763    -- 4955764
146764    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
146765       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
146766 
146767    -- 4458381 Public Sector Enh
146768    
146769    --
146770    -- set accounting attributes for the line type
146771    --
146772    l_entered_amt_idx := 4;
146773    l_accted_amt_idx  := 6;
146774    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
146775    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
146776    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
146777    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
146778    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
146779    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
146780    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
146781    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
146782    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
146783    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
146784    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
146785    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
146786    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
146787 
146788    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
146789    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
146790 
146791    ---------------------------------------------------------------------------------------------------------------
146792    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
146793    ---------------------------------------------------------------------------------------------------------------
146794    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
146795 
146796    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
146797    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
146798 
146799    IF xla_accounting_cache_pkg.GetValueChar
146800          (p_source_code         => 'LEDGER_CATEGORY_CODE'
146801          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
146802    AND l_bflow_method_code = 'PRIOR_ENTRY'
146803 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
146804    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
146805          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
146806        )
146807    THEN
146808          xla_ae_lines_pkg.BflowUpgEntry
146809            (p_business_method_code    => l_bflow_method_code
146810            ,p_business_class_code     => l_bflow_class_code
146811            ,p_balance_type            => l_balance_type_code);
146812    ELSE
146813       NULL;
146814 -- No business flow processing for business flow method of NONE.
146815    END IF;
146816 
146817    --
146818    -- call analytical criteria
146819    --
146820    
146821    --
146822    -- call description
146823    --
146824    
146825 xla_ae_lines_pkg.SetLineDescription(
146826    p_ae_header_id => l_ae_header_id
146827   ,p_description  => Description_113 (
146828      p_application_id         => p_application_id
146829    , p_ae_header_id           => l_ae_header_id 
146830 , p_source_1 => p_source_1
146831    )
146832 );
146833 
146834 
146835    --
146836    -- call ADRs
146837    -- Bug 4922099
146838    --
146839    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
146840         (NVL(l_actual_upg_option, 'N') = 'O') OR
146841         (NVL(l_enc_upg_option, 'N') = 'O')
146842       )
146843    THEN
146844    NULL;
146845    --
146846    --
146847    
146848   l_ccid := AcctDerRule_174(
146849            p_application_id           => p_application_id
146850          , p_ae_header_id             => l_ae_header_id 
146851 , p_source_3 => p_source_3
146852 , p_source_17 => p_source_17
146853 , p_source_30 => p_source_30
146857          , p_side                     => 'NA'
146854          , x_transaction_coa_id       => l_adr_transaction_coa_id
146855          , x_accounting_coa_id        => l_adr_accounting_coa_id
146856          , x_value_type_code          => l_adr_value_type_code
146858    );
146859 
146860    xla_ae_lines_pkg.set_ccid(
146861     p_code_combination_id          => l_ccid
146862   , p_value_type_code              => l_adr_value_type_code
146863   , p_transaction_coa_id           => l_adr_transaction_coa_id
146864   , p_accounting_coa_id            => l_adr_accounting_coa_id
146865   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
146866   , p_adr_type_code                => 'S'
146867   , p_component_type               => l_component_type
146868   , p_component_code               => l_component_code
146869   , p_component_type_code          => l_component_type_code
146870   , p_component_appl_id            => l_component_appl_id
146871   , p_amb_context_code             => l_amb_context_code
146872   , p_side                         => 'NA'
146873   );
146874 
146875 
146876    l_segment := AcctDerRule_149(
146877            p_application_id           => p_application_id
146878          , p_ae_header_id             => l_ae_header_id 
146879 , p_source_3 => p_source_3
146880 , p_source_10 => p_source_10
146881          , x_transaction_coa_id       => l_adr_transaction_coa_id
146882          , x_accounting_coa_id        => l_adr_accounting_coa_id
146883          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
146884          , x_flex_value_set_id        => l_adr_flex_value_set_id
146885          , x_value_type_code          => l_adr_value_type_code
146886          , x_value_combination_id     => l_adr_value_combination_id
146887          , x_value_segment_code       => l_adr_value_segment_code
146888          , p_side                     => 'NA'
146889          , p_override_seg_flag        => 'Y'
146890    );
146891 
146892    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
146893 
146894       xla_ae_lines_pkg.set_segment(
146895           p_to_segment_code         => 'GL_ACCOUNT'
146896         , p_segment_value           => l_segment
146897         , p_from_segment_code       => l_adr_value_segment_code
146898         , p_from_combination_id     => l_adr_value_combination_id
146899         , p_value_type_code         => l_adr_value_type_code
146900         , p_transaction_coa_id      => l_adr_transaction_coa_id
146901         , p_accounting_coa_id       => l_adr_accounting_coa_id
146902         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
146903         , p_flex_value_set_id       => l_adr_flex_value_set_id
146904         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
146905         , p_adr_type_code           => 'S'
146906         , p_component_type          => l_component_type
146907         , p_component_code          => l_component_code
146908         , p_component_type_code     => l_component_type_code
146909         , p_component_appl_id       => l_component_appl_id
146910         , p_amb_context_code        => l_amb_context_code
146911         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
146912         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
146913         , p_side                    => 'NA'
146914         );
146915 
146916   END IF;
146917 
146918    l_segment := AcctDerRule_168(
146919            p_application_id           => p_application_id
146920          , p_ae_header_id             => l_ae_header_id 
146921 , p_source_3 => p_source_3
146922 , p_source_29 => p_source_29
146923          , x_transaction_coa_id       => l_adr_transaction_coa_id
146924          , x_accounting_coa_id        => l_adr_accounting_coa_id
146925          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
146926          , x_flex_value_set_id        => l_adr_flex_value_set_id
146927          , x_value_type_code          => l_adr_value_type_code
146928          , x_value_combination_id     => l_adr_value_combination_id
146929          , x_value_segment_code       => l_adr_value_segment_code
146930          , p_side                     => 'NA'
146931          , p_override_seg_flag        => 'Y'
146932    );
146933 
146934    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
146935 
146936       xla_ae_lines_pkg.set_segment(
146937           p_to_segment_code         => 'GL_BALANCING'
146938         , p_segment_value           => l_segment
146939         , p_from_segment_code       => l_adr_value_segment_code
146940         , p_from_combination_id     => l_adr_value_combination_id
146941         , p_value_type_code         => l_adr_value_type_code
146942         , p_transaction_coa_id      => l_adr_transaction_coa_id
146943         , p_accounting_coa_id       => l_adr_accounting_coa_id
146944         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
146945         , p_flex_value_set_id       => l_adr_flex_value_set_id
146946         , p_adr_code                => 'FA_EXPENSE_ACCT'
146947         , p_adr_type_code           => 'S'
146948         , p_component_type          => l_component_type
146949         , p_component_code          => l_component_code
146950         , p_component_type_code     => l_component_type_code
146951         , p_component_appl_id       => l_component_appl_id
146952         , p_amb_context_code        => l_amb_context_code
146953         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
146954         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
146955         , p_side                    => 'NA'
146956         );
146957 
146958   END IF;
146959 
146960    --
146961    --
146962    END IF;
146963    --
146964    -- Bug 4922099
146965    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
146966           (NVL(l_enc_upg_option, 'N') = 'O')
146967         ) AND
146968         (l_bflow_method_code = 'PRIOR_ENTRY')
146969       )
146970    THEN
146971       IF
146972       --
146973       1 = 2
146974       --
146975       THEN
146976       xla_accounting_err_pkg.build_message
146980                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
146977                                     (p_appli_s_name            => 'XLA'
146978                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
146979                                     ,p_token_1                 => 'LINE_NUMBER'
146981                                     ,p_token_2                 => 'LINE_TYPE_NAME'
146982                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
146983                                                                              l_component_type
146984                                                                             ,l_component_code
146985                                                                             ,l_component_type_code
146986                                                                             ,l_component_appl_id
146987                                                                             ,l_amb_context_code
146988                                                                             ,l_entity_code
146989                                                                             ,l_event_class_code
146990                                                                            )
146991                                     ,p_token_3                 => 'OWNER'
146992                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
146993                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
146994                                                                           ,p_lookup_code    => l_component_type_code
146995                                                                          )
146996                                     ,p_token_4                 => 'PRODUCT_NAME'
146997                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
146998                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
146999                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
147000                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
147001                                     ,p_ae_header_id            =>  NULL
147002                                        );
147003 
147004         IF (C_LEVEL_ERROR>= g_log_level) THEN
147005                  trace
147006                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
147007                       ,p_level    => C_LEVEL_ERROR
147008                       ,p_module   => l_log_module);
147009         END IF;
147010       END IF;
147011    END IF;
147012    --
147013    --
147014    ------------------------------------------------------------------------------------------------
147015    -- 4219869 Business Flow
147016    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
147017    -- Prior Entry.  Currently, the following code is always generated.
147018    ------------------------------------------------------------------------------------------------
147019    XLA_AE_LINES_PKG.ValidateCurrentLine;
147020 
147021    ------------------------------------------------------------------------------------
147022    -- 4219869 Business Flow
147023    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
147024    ------------------------------------------------------------------------------------
147025    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
147026 
147027    ----------------------------------------------------------------------------------
147028    -- 4219869 Business Flow
147029    -- Update journal entry status -- Need to generate this within IF <condition>
147030    ----------------------------------------------------------------------------------
147031    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
147032          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
147033          ,p_balance_type_code => l_balance_type_code
147034          );
147035 
147036    -------------------------------------------------------------------------------------------
147037    -- 4262811 - Generate the Accrual Reversal lines
147038    -------------------------------------------------------------------------------------------
147039    BEGIN
147040       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
147041                               (g_array_event(p_event_id).array_value_num('header_index'));
147042       IF l_acc_rev_flag IS NULL THEN
147043          l_acc_rev_flag := 'N';
147044       END IF;
147045    EXCEPTION
147046       WHEN OTHERS THEN
147047          l_acc_rev_flag := 'N';
147048    END;
147049    --
147050    IF (l_acc_rev_flag = 'Y') THEN
147051 
147052        -- 4645092  ------------------------------------------------------------------------------
147053        -- To allow MPA report to determine if it should generate report process
147054        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
147055        ------------------------------------------------------------------------------------------
147056 
147057        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
147058        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
147059    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
147060    -- call ADRs
147061    -- Bug 4922099
147062    --
147063    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
147064         (NVL(l_actual_upg_option, 'N') = 'O') OR
147065         (NVL(l_enc_upg_option, 'N') = 'O')
147066       )
147067    THEN
147068    NULL;
147069    --
147070    --
147071    
147072   l_ccid := AcctDerRule_174(
147073            p_application_id           => p_application_id
147074          , p_ae_header_id             => l_ae_header_id 
147075 , p_source_3 => p_source_3
147076 , p_source_17 => p_source_17
147077 , p_source_30 => p_source_30
147081          , p_side                     => 'NA'
147078          , x_transaction_coa_id       => l_adr_transaction_coa_id
147079          , x_accounting_coa_id        => l_adr_accounting_coa_id
147080          , x_value_type_code          => l_adr_value_type_code
147082    );
147083 
147084    xla_ae_lines_pkg.set_ccid(
147085     p_code_combination_id          => l_ccid
147086   , p_value_type_code              => l_adr_value_type_code
147087   , p_transaction_coa_id           => l_adr_transaction_coa_id
147088   , p_accounting_coa_id            => l_adr_accounting_coa_id
147089   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
147090   , p_adr_type_code                => 'S'
147091   , p_component_type               => l_component_type
147092   , p_component_code               => l_component_code
147093   , p_component_type_code          => l_component_type_code
147094   , p_component_appl_id            => l_component_appl_id
147095   , p_amb_context_code             => l_amb_context_code
147096   , p_side                         => 'NA'
147097   );
147098 
147099 
147100    l_segment := AcctDerRule_149(
147101            p_application_id           => p_application_id
147102          , p_ae_header_id             => l_ae_header_id 
147103 , p_source_3 => p_source_3
147104 , p_source_10 => p_source_10
147105          , x_transaction_coa_id       => l_adr_transaction_coa_id
147106          , x_accounting_coa_id        => l_adr_accounting_coa_id
147107          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
147108          , x_flex_value_set_id        => l_adr_flex_value_set_id
147109          , x_value_type_code          => l_adr_value_type_code
147110          , x_value_combination_id     => l_adr_value_combination_id
147111          , x_value_segment_code       => l_adr_value_segment_code
147112          , p_side                     => 'NA'
147113          , p_override_seg_flag        => 'Y'
147114    );
147115 
147116    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
147117 
147118       xla_ae_lines_pkg.set_segment(
147119           p_to_segment_code         => 'GL_ACCOUNT'
147120         , p_segment_value           => l_segment
147121         , p_from_segment_code       => l_adr_value_segment_code
147122         , p_from_combination_id     => l_adr_value_combination_id
147123         , p_value_type_code         => l_adr_value_type_code
147124         , p_transaction_coa_id      => l_adr_transaction_coa_id
147125         , p_accounting_coa_id       => l_adr_accounting_coa_id
147126         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
147127         , p_flex_value_set_id       => l_adr_flex_value_set_id
147128         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
147129         , p_adr_type_code           => 'S'
147130         , p_component_type          => l_component_type
147131         , p_component_code          => l_component_code
147132         , p_component_type_code     => l_component_type_code
147133         , p_component_appl_id       => l_component_appl_id
147134         , p_amb_context_code        => l_amb_context_code
147135         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
147136         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
147137         , p_side                    => 'NA'
147138         );
147139 
147140   END IF;
147141 
147142    l_segment := AcctDerRule_168(
147143            p_application_id           => p_application_id
147144          , p_ae_header_id             => l_ae_header_id 
147145 , p_source_3 => p_source_3
147146 , p_source_29 => p_source_29
147147          , x_transaction_coa_id       => l_adr_transaction_coa_id
147148          , x_accounting_coa_id        => l_adr_accounting_coa_id
147149          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
147150          , x_flex_value_set_id        => l_adr_flex_value_set_id
147151          , x_value_type_code          => l_adr_value_type_code
147152          , x_value_combination_id     => l_adr_value_combination_id
147153          , x_value_segment_code       => l_adr_value_segment_code
147154          , p_side                     => 'NA'
147155          , p_override_seg_flag        => 'Y'
147156    );
147157 
147158    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
147159 
147160       xla_ae_lines_pkg.set_segment(
147161           p_to_segment_code         => 'GL_BALANCING'
147162         , p_segment_value           => l_segment
147163         , p_from_segment_code       => l_adr_value_segment_code
147164         , p_from_combination_id     => l_adr_value_combination_id
147165         , p_value_type_code         => l_adr_value_type_code
147166         , p_transaction_coa_id      => l_adr_transaction_coa_id
147167         , p_accounting_coa_id       => l_adr_accounting_coa_id
147168         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
147169         , p_flex_value_set_id       => l_adr_flex_value_set_id
147170         , p_adr_code                => 'FA_EXPENSE_ACCT'
147171         , p_adr_type_code           => 'S'
147172         , p_component_type          => l_component_type
147173         , p_component_code          => l_component_code
147174         , p_component_type_code     => l_component_type_code
147175         , p_component_appl_id       => l_component_appl_id
147176         , p_amb_context_code        => l_amb_context_code
147177         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
147178         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
147179         , p_side                    => 'NA'
147180         );
147181 
147182   END IF;
147183 
147184    --
147185    --
147186    END IF;
147187 
147188        --
147189        -- Update the line information that should be overwritten
147190        --
147191        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
147192                                          p_header_num   => 1);
147193        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
147194 
147198           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
147195        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
147196 
147197        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
147199        END IF;
147200 
147201       --
147202       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
147203       --
147204       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
147205           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
147206       ELSE
147207           ---------------------------------------------------------------------------------------------------
147208           -- 4262811a Switch Sign
147209           ---------------------------------------------------------------------------------------------------
147210           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
147211           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
147212                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
147213           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
147214                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
147215           -- 5132302
147216           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
147217                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
147218 
147219       END IF;
147220 
147221       -- 4955764
147222       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
147223       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
147224 
147225 
147226       XLA_AE_LINES_PKG.ValidateCurrentLine;
147227       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
147228 
147229       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
147230                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
147231                ,p_balance_type_code => l_balance_type_code);
147232 
147233    END IF;
147234 
147235    -----------------------------------------------------------------------------------------
147236    -- 4262811 Multiperiod Accounting
147237    -----------------------------------------------------------------------------------------
147238      -- No MPA option is assigned.
147239 
147240 
147241 END IF;
147242 END IF;
147243 --
147244 
147245 --
147246 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
147247    trace
147248       (p_msg      => 'END of AcctLineType_360'
147249       ,p_level    => C_LEVEL_PROCEDURE
147250       ,p_module   => l_log_module);
147251 END IF;
147252 --
147253 EXCEPTION
147254   WHEN xla_exceptions_pkg.application_exception THEN
147255       RAISE;
147256   WHEN OTHERS THEN
147257        xla_exceptions_pkg.raise_message
147258            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_360');
147259 END AcctLineType_360;
147260 --
147261 
147262 ---------------------------------------
147263 --
147264 -- PRIVATE FUNCTION
147265 --         AcctLineType_361
147266 --
147267 ---------------------------------------
147268 PROCEDURE AcctLineType_361 (
147269   p_application_id        IN NUMBER
147270  ,p_event_id              IN NUMBER
147271  ,p_calculate_acctd_flag  IN VARCHAR2
147272  ,p_calculate_g_l_flag    IN VARCHAR2
147273  ,p_actual_flag           IN OUT VARCHAR2
147274  ,p_balance_type_code     OUT VARCHAR2
147275  ,p_gain_or_loss_ref      OUT VARCHAR2
147276  
147277 --Period Close Date
147278  , p_source_1            IN DATE
147279 --Generated Code Combination Identifier
147280  , p_source_3            IN NUMBER
147281 --Expense Account Code Combination Identifier
147282  , p_source_29            IN NUMBER
147283 --Adjustment Type
147284  , p_source_35            IN VARCHAR2
147285 --Transaction Header Identifier
147286  , p_source_36            IN NUMBER
147287 --Adjustment Line Identifier
147288  , p_source_37            IN NUMBER
147289 --Distribution Type Code
147290  , p_source_38            IN VARCHAR2
147291 --Entered Amount
147292  , p_source_39            IN NUMBER
147293 --Currency Code
147294  , p_source_40            IN VARCHAR2
147295 --Source Destination Code
147296  , p_source_42            IN VARCHAR2
147297 )
147298 IS
147299 
147300 l_component_type              VARCHAR2(80);
147301 l_component_code              VARCHAR2(30);
147302 l_component_type_code         VARCHAR2(1);
147303 l_component_appl_id           INTEGER;
147304 l_amb_context_code            VARCHAR2(30);
147305 l_entity_code                 VARCHAR2(30);
147306 l_event_class_code            VARCHAR2(30);
147307 l_ae_header_id                NUMBER;
147308 l_event_type_code             VARCHAR2(30);
147309 l_line_definition_code        VARCHAR2(30);
147310 l_line_definition_owner_code  VARCHAR2(1);
147311 --
147312 -- adr variables
147313 l_segment                     VARCHAR2(30);
147314 l_ccid                        NUMBER;
147315 l_adr_transaction_coa_id      NUMBER;
147316 l_adr_accounting_coa_id       NUMBER;
147317 l_adr_flexfield_segment_code  VARCHAR2(30);
147318 l_adr_flex_value_set_id       NUMBER;
147319 l_adr_value_type_code         VARCHAR2(30);
147320 l_adr_value_combination_id    NUMBER;
147321 l_adr_value_segment_code      VARCHAR2(30);
147322 
147323 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
147324 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
147325 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
147326 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
147327 
147331 l_acc_rev_flag                VARCHAR2(1);
147328 -- 4262811 Variables ------------------------------------------------------------------------------------------
147329 l_entered_amt_idx             NUMBER;
147330 l_accted_amt_idx              NUMBER;
147332 l_accrual_line_num            NUMBER;
147333 l_tmp_amt                     NUMBER;
147334 l_acc_rev_natural_side_code   VARCHAR2(1);
147335 
147336 l_num_entries                 NUMBER;
147337 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
147338 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
147339 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
147340 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
147341 l_recog_line_1                NUMBER;
147342 l_recog_line_2                NUMBER;
147343 
147344 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
147345 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
147346 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
147347 
147348 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
147349 
147350 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
147351 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
147352 
147353 ---------------------------------------------------------------------------------------------------------------
147354 
147355 
147356 --
147357 -- bulk performance
147358 --
147359 l_balance_type_code           VARCHAR2(1);
147360 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
147361 l_log_module                  VARCHAR2(240);
147362 
147363 --
147364 -- Upgrade strategy
147365 --
147366 l_actual_upg_option           VARCHAR2(1);
147367 l_enc_upg_option           VARCHAR2(1);
147368 
147369 --
147370 BEGIN
147371 --
147372 IF g_log_enabled THEN
147373       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_361';
147374 END IF;
147375 --
147376 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
147377 
147378       trace
147379          (p_msg      => 'BEGIN of AcctLineType_361'
147380          ,p_level    => C_LEVEL_PROCEDURE
147381          ,p_module   => l_log_module);
147382 
147383 END IF;
147384 --
147385 l_component_type             := 'AMB_JLT';
147386 l_component_code             := 'FA_SLT_SOURCE_EXP_BAL';
147387 l_component_type_code        := 'S';
147388 l_component_appl_id          :=  140;
147389 l_amb_context_code           := 'DEFAULT';
147390 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
147391 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
147392 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
147393 l_line_definition_owner_code := 'S';
147394 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
147395 --
147396 l_balance_type_code          := 'A';
147397 l_segment                     := NULL;
147398 l_ccid                        := NULL;
147399 l_adr_transaction_coa_id      := NULL;
147400 l_adr_accounting_coa_id       := NULL;
147401 l_adr_flexfield_segment_code  := NULL;
147402 l_adr_flex_value_set_id       := NULL;
147403 l_adr_value_type_code         := NULL;
147404 l_adr_value_combination_id    := NULL;
147405 l_adr_value_segment_code      := NULL;
147406 
147407 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
147408 l_bflow_class_code           := '';    -- 4219869 Business Flow
147409 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
147410 l_budgetary_control_flag     := 'N';
147411 
147412 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
147413 l_bflow_applied_to_amt       := NULL; -- 5132302
147414 l_entered_amt_idx            := NULL;          -- 4262811
147415 l_accted_amt_idx             := NULL;          -- 4262811
147416 l_acc_rev_flag               := NULL;          -- 4262811
147417 l_accrual_line_num           := NULL;          -- 4262811
147418 l_tmp_amt                    := NULL;          -- 4262811
147419 --
147420  
147421 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
147422     l_balance_type_code <> 'B' THEN
147423 IF NVL(p_source_35,'
147424 ') =  'BONUS EXPENSE' AND 
147425 NVL(p_source_42,'
147426 ') =  'SOURCE'
147427  THEN 
147428 
147429    --
147430    XLA_AE_LINES_PKG.SetNewLine;
147431 
147432    p_balance_type_code          := l_balance_type_code;
147433    -- set the flag so later we will know whether the gain loss line needs to be created
147434    
147435    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
147436      p_actual_flag :='A';
147437    END IF;
147438 
147439    --
147440    -- bulk performance
147441    --
147442    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
147443                                       p_header_num   => 0); -- 4262811
147444    --
147445    -- set accounting line options
147446    --
147447    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
147448            p_natural_side_code          => 'D'
147449          , p_gain_or_loss_flag          => 'N'
147450          , p_gl_transfer_mode_code      => 'S'
147451          , p_acct_entry_type_code       => 'A'
147452          , p_switch_side_flag           => 'Y'
147453          , p_merge_duplicate_code       => 'N'
147454          );
147455    --
147456    l_acc_rev_natural_side_code := 'C';  -- 4262811
147457    -- 
147458    --
147459    -- set accounting line type info
147460    --
147461    xla_ae_lines_pkg.SetAcctLineType
147462       (p_component_type             => l_component_type
147463       ,p_event_type_code            => l_event_type_code
147464       ,p_line_definition_owner_code => l_line_definition_owner_code
147465       ,p_line_definition_code       => l_line_definition_code
147466       ,p_accounting_line_code       => l_component_code
147470       ,p_entity_code                => l_entity_code
147467       ,p_accounting_line_type_code  => l_component_type_code
147468       ,p_accounting_line_appl_id    => l_component_appl_id
147469       ,p_amb_context_code           => l_amb_context_code
147471       ,p_event_class_code           => l_event_class_code);
147472    --
147473    -- set accounting class
147474    --
147475    xla_ae_lines_pkg.SetAcctClass(
147476            p_accounting_class_code  => 'EXPENSE'
147477          , p_ae_header_id           => l_ae_header_id
147478          );
147479 
147480    --
147481    -- set rounding class
147482    --
147483    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
147484                       'EXPENSE';
147485 
147486    --
147487    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
147488    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
147489    --
147490    -- bulk performance
147491    --
147492    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
147493 
147494    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
147495       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
147496 
147497    -- 4955764
147498    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
147499       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
147500 
147501    -- 4458381 Public Sector Enh
147502    
147503    --
147504    -- set accounting attributes for the line type
147505    --
147506    l_entered_amt_idx := 4;
147507    l_accted_amt_idx  := 6;
147508    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
147509    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
147510    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
147511    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
147512    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
147513    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
147514    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
147515    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
147516    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
147517    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
147518    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
147519    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
147520    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
147521 
147522    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
147523    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
147524 
147525    ---------------------------------------------------------------------------------------------------------------
147526    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
147527    ---------------------------------------------------------------------------------------------------------------
147528    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
147529 
147530    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
147531    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
147532 
147533    IF xla_accounting_cache_pkg.GetValueChar
147534          (p_source_code         => 'LEDGER_CATEGORY_CODE'
147535          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
147536    AND l_bflow_method_code = 'PRIOR_ENTRY'
147537 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
147538    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
147539          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
147540        )
147541    THEN
147542          xla_ae_lines_pkg.BflowUpgEntry
147543            (p_business_method_code    => l_bflow_method_code
147544            ,p_business_class_code     => l_bflow_class_code
147545            ,p_balance_type            => l_balance_type_code);
147546    ELSE
147547       NULL;
147548 -- No business flow processing for business flow method of NONE.
147549    END IF;
147550 
147551    --
147552    -- call analytical criteria
147553    --
147554    
147555    --
147556    -- call description
147557    --
147558    
147559 xla_ae_lines_pkg.SetLineDescription(
147560    p_ae_header_id => l_ae_header_id
147561   ,p_description  => Description_112 (
147562      p_application_id         => p_application_id
147563    , p_ae_header_id           => l_ae_header_id 
147564 , p_source_1 => p_source_1
147565    )
147566 );
147567 
147568 
147569    --
147570    -- call ADRs
147571    -- Bug 4922099
147572    --
147573    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
147574         (NVL(l_actual_upg_option, 'N') = 'O') OR
147575         (NVL(l_enc_upg_option, 'N') = 'O')
147576       )
147577    THEN
147578    NULL;
147579    --
147580    --
147581    
147582   l_ccid := AcctDerRule_175(
147583            p_application_id           => p_application_id
147584          , p_ae_header_id             => l_ae_header_id 
147585 , p_source_3 => p_source_3
147586 , p_source_29 => p_source_29
147587          , x_transaction_coa_id       => l_adr_transaction_coa_id
147588          , x_accounting_coa_id        => l_adr_accounting_coa_id
147589          , x_value_type_code          => l_adr_value_type_code
147590          , p_side                     => 'NA'
147591    );
147592 
147593    xla_ae_lines_pkg.set_ccid(
147594     p_code_combination_id          => l_ccid
147595   , p_value_type_code              => l_adr_value_type_code
147596   , p_transaction_coa_id           => l_adr_transaction_coa_id
147600   , p_component_type               => l_component_type
147597   , p_accounting_coa_id            => l_adr_accounting_coa_id
147598   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
147599   , p_adr_type_code                => 'S'
147601   , p_component_code               => l_component_code
147602   , p_component_type_code          => l_component_type_code
147603   , p_component_appl_id            => l_component_appl_id
147604   , p_amb_context_code             => l_amb_context_code
147605   , p_side                         => 'NA'
147606   );
147607 
147608 
147609    --
147610    --
147611    END IF;
147612    --
147613    -- Bug 4922099
147614    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
147615           (NVL(l_enc_upg_option, 'N') = 'O')
147616         ) AND
147617         (l_bflow_method_code = 'PRIOR_ENTRY')
147618       )
147619    THEN
147620       IF
147621       --
147622       1 = 2
147623       --
147624       THEN
147625       xla_accounting_err_pkg.build_message
147626                                     (p_appli_s_name            => 'XLA'
147627                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
147628                                     ,p_token_1                 => 'LINE_NUMBER'
147629                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
147630                                     ,p_token_2                 => 'LINE_TYPE_NAME'
147631                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
147632                                                                              l_component_type
147633                                                                             ,l_component_code
147634                                                                             ,l_component_type_code
147635                                                                             ,l_component_appl_id
147636                                                                             ,l_amb_context_code
147637                                                                             ,l_entity_code
147638                                                                             ,l_event_class_code
147639                                                                            )
147640                                     ,p_token_3                 => 'OWNER'
147641                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
147642                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
147643                                                                           ,p_lookup_code    => l_component_type_code
147644                                                                          )
147645                                     ,p_token_4                 => 'PRODUCT_NAME'
147646                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
147647                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
147648                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
147649                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
147650                                     ,p_ae_header_id            =>  NULL
147651                                        );
147652 
147653         IF (C_LEVEL_ERROR>= g_log_level) THEN
147654                  trace
147655                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
147656                       ,p_level    => C_LEVEL_ERROR
147657                       ,p_module   => l_log_module);
147658         END IF;
147659       END IF;
147660    END IF;
147661    --
147662    --
147663    ------------------------------------------------------------------------------------------------
147664    -- 4219869 Business Flow
147665    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
147666    -- Prior Entry.  Currently, the following code is always generated.
147667    ------------------------------------------------------------------------------------------------
147668    XLA_AE_LINES_PKG.ValidateCurrentLine;
147669 
147670    ------------------------------------------------------------------------------------
147671    -- 4219869 Business Flow
147672    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
147673    ------------------------------------------------------------------------------------
147674    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
147675 
147676    ----------------------------------------------------------------------------------
147677    -- 4219869 Business Flow
147678    -- Update journal entry status -- Need to generate this within IF <condition>
147679    ----------------------------------------------------------------------------------
147680    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
147681          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
147682          ,p_balance_type_code => l_balance_type_code
147683          );
147684 
147685    -------------------------------------------------------------------------------------------
147686    -- 4262811 - Generate the Accrual Reversal lines
147687    -------------------------------------------------------------------------------------------
147688    BEGIN
147689       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
147690                               (g_array_event(p_event_id).array_value_num('header_index'));
147691       IF l_acc_rev_flag IS NULL THEN
147692          l_acc_rev_flag := 'N';
147693       END IF;
147694    EXCEPTION
147695       WHEN OTHERS THEN
147696          l_acc_rev_flag := 'N';
147697    END;
147698    --
147699    IF (l_acc_rev_flag = 'Y') THEN
147700 
147701        -- 4645092  ------------------------------------------------------------------------------
147702        -- To allow MPA report to determine if it should generate report process
147706        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
147703        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
147704        ------------------------------------------------------------------------------------------
147705 
147707        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
147708    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
147709    -- call ADRs
147710    -- Bug 4922099
147711    --
147712    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
147713         (NVL(l_actual_upg_option, 'N') = 'O') OR
147714         (NVL(l_enc_upg_option, 'N') = 'O')
147715       )
147716    THEN
147717    NULL;
147718    --
147719    --
147720    
147721   l_ccid := AcctDerRule_175(
147722            p_application_id           => p_application_id
147723          , p_ae_header_id             => l_ae_header_id 
147724 , p_source_3 => p_source_3
147725 , p_source_29 => p_source_29
147726          , x_transaction_coa_id       => l_adr_transaction_coa_id
147727          , x_accounting_coa_id        => l_adr_accounting_coa_id
147728          , x_value_type_code          => l_adr_value_type_code
147729          , p_side                     => 'NA'
147730    );
147731 
147732    xla_ae_lines_pkg.set_ccid(
147733     p_code_combination_id          => l_ccid
147734   , p_value_type_code              => l_adr_value_type_code
147735   , p_transaction_coa_id           => l_adr_transaction_coa_id
147736   , p_accounting_coa_id            => l_adr_accounting_coa_id
147737   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
147738   , p_adr_type_code                => 'S'
147739   , p_component_type               => l_component_type
147740   , p_component_code               => l_component_code
147741   , p_component_type_code          => l_component_type_code
147742   , p_component_appl_id            => l_component_appl_id
147743   , p_amb_context_code             => l_amb_context_code
147744   , p_side                         => 'NA'
147745   );
147746 
147747 
147748    --
147749    --
147750    END IF;
147751 
147752        --
147753        -- Update the line information that should be overwritten
147754        --
147755        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
147756                                          p_header_num   => 1);
147757        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
147758 
147759        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
147760 
147761        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
147762           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
147763        END IF;
147764 
147765       --
147766       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
147767       --
147768       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
147769           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
147770       ELSE
147771           ---------------------------------------------------------------------------------------------------
147772           -- 4262811a Switch Sign
147773           ---------------------------------------------------------------------------------------------------
147774           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
147775           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
147776                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
147777           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
147778                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
147779           -- 5132302
147780           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
147781                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
147782 
147783       END IF;
147784 
147785       -- 4955764
147786       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
147787       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
147788 
147789 
147790       XLA_AE_LINES_PKG.ValidateCurrentLine;
147791       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
147792 
147793       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
147794                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
147795                ,p_balance_type_code => l_balance_type_code);
147796 
147797    END IF;
147798 
147799    -----------------------------------------------------------------------------------------
147800    -- 4262811 Multiperiod Accounting
147801    -----------------------------------------------------------------------------------------
147802      -- No MPA option is assigned.
147803 
147804 
147805 END IF;
147806 END IF;
147807 --
147808 
147809 --
147810 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
147811    trace
147812       (p_msg      => 'END of AcctLineType_361'
147813       ,p_level    => C_LEVEL_PROCEDURE
147814       ,p_module   => l_log_module);
147815 END IF;
147816 --
147817 EXCEPTION
147818   WHEN xla_exceptions_pkg.application_exception THEN
147819       RAISE;
147820   WHEN OTHERS THEN
147821        xla_exceptions_pkg.raise_message
147822            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_361');
147823 END AcctLineType_361;
147824 --
147825 
147826 ---------------------------------------
147827 --
147828 -- PRIVATE FUNCTION
147829 --         AcctLineType_362
147830 --
147831 ---------------------------------------
147832 PROCEDURE AcctLineType_362 (
147836  ,p_calculate_g_l_flag    IN VARCHAR2
147833   p_application_id        IN NUMBER
147834  ,p_event_id              IN NUMBER
147835  ,p_calculate_acctd_flag  IN VARCHAR2
147837  ,p_actual_flag           IN OUT VARCHAR2
147838  ,p_balance_type_code     OUT VARCHAR2
147839  ,p_gain_or_loss_ref      OUT VARCHAR2
147840  
147841 --Period Close Date
147842  , p_source_1            IN DATE
147843 --Generated Code Combination Identifier
147844  , p_source_3            IN NUMBER
147845 --Depreciation Reserve Account
147846  , p_source_10            IN VARCHAR2
147847 --Generated Offset Code Combination Identifier
147848  , p_source_17            IN NUMBER
147849 --Expense Account Code Combination Identifier
147850  , p_source_29            IN NUMBER
147851 --Default Code Combination Identifier
147852  , p_source_30            IN NUMBER
147853 --Adjustment Type
147854  , p_source_35            IN VARCHAR2
147855 --Transaction Header Identifier
147856  , p_source_36            IN NUMBER
147857 --Adjustment Line Identifier
147858  , p_source_37            IN NUMBER
147859 --Distribution Type Code
147860  , p_source_38            IN VARCHAR2
147861 --Entered Amount
147862  , p_source_39            IN NUMBER
147863 --Currency Code
147864  , p_source_40            IN VARCHAR2
147865 --Source Destination Code
147866  , p_source_42            IN VARCHAR2
147867 )
147868 IS
147869 
147870 l_component_type              VARCHAR2(80);
147871 l_component_code              VARCHAR2(30);
147872 l_component_type_code         VARCHAR2(1);
147873 l_component_appl_id           INTEGER;
147874 l_amb_context_code            VARCHAR2(30);
147875 l_entity_code                 VARCHAR2(30);
147876 l_event_class_code            VARCHAR2(30);
147877 l_ae_header_id                NUMBER;
147878 l_event_type_code             VARCHAR2(30);
147879 l_line_definition_code        VARCHAR2(30);
147880 l_line_definition_owner_code  VARCHAR2(1);
147881 --
147882 -- adr variables
147883 l_segment                     VARCHAR2(30);
147884 l_ccid                        NUMBER;
147885 l_adr_transaction_coa_id      NUMBER;
147886 l_adr_accounting_coa_id       NUMBER;
147887 l_adr_flexfield_segment_code  VARCHAR2(30);
147888 l_adr_flex_value_set_id       NUMBER;
147889 l_adr_value_type_code         VARCHAR2(30);
147890 l_adr_value_combination_id    NUMBER;
147891 l_adr_value_segment_code      VARCHAR2(30);
147892 
147893 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
147894 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
147895 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
147896 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
147897 
147898 -- 4262811 Variables ------------------------------------------------------------------------------------------
147899 l_entered_amt_idx             NUMBER;
147900 l_accted_amt_idx              NUMBER;
147901 l_acc_rev_flag                VARCHAR2(1);
147902 l_accrual_line_num            NUMBER;
147903 l_tmp_amt                     NUMBER;
147904 l_acc_rev_natural_side_code   VARCHAR2(1);
147905 
147906 l_num_entries                 NUMBER;
147907 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
147908 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
147909 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
147910 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
147911 l_recog_line_1                NUMBER;
147912 l_recog_line_2                NUMBER;
147913 
147914 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
147915 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
147916 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
147917 
147918 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
147919 
147920 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
147921 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
147922 
147923 ---------------------------------------------------------------------------------------------------------------
147924 
147925 
147926 --
147927 -- bulk performance
147928 --
147929 l_balance_type_code           VARCHAR2(1);
147930 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
147931 l_log_module                  VARCHAR2(240);
147932 
147933 --
147934 -- Upgrade strategy
147935 --
147936 l_actual_upg_option           VARCHAR2(1);
147937 l_enc_upg_option           VARCHAR2(1);
147938 
147939 --
147940 BEGIN
147941 --
147942 IF g_log_enabled THEN
147943       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_362';
147944 END IF;
147945 --
147946 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
147947 
147948       trace
147949          (p_msg      => 'BEGIN of AcctLineType_362'
147950          ,p_level    => C_LEVEL_PROCEDURE
147951          ,p_module   => l_log_module);
147952 
147953 END IF;
147954 --
147955 l_component_type             := 'AMB_JLT';
147956 l_component_code             := 'FA_SLT_SOURCE_RESERVE_BAL';
147957 l_component_type_code        := 'S';
147958 l_component_appl_id          :=  140;
147959 l_amb_context_code           := 'DEFAULT';
147960 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
147961 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
147962 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
147963 l_line_definition_owner_code := 'S';
147964 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
147965 --
147966 l_balance_type_code          := 'A';
147967 l_segment                     := NULL;
147968 l_ccid                        := NULL;
147969 l_adr_transaction_coa_id      := NULL;
147970 l_adr_accounting_coa_id       := NULL;
147971 l_adr_flexfield_segment_code  := NULL;
147972 l_adr_flex_value_set_id       := NULL;
147976 
147973 l_adr_value_type_code         := NULL;
147974 l_adr_value_combination_id    := NULL;
147975 l_adr_value_segment_code      := NULL;
147977 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
147978 l_bflow_class_code           := '';    -- 4219869 Business Flow
147979 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
147980 l_budgetary_control_flag     := 'N';
147981 
147982 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
147983 l_bflow_applied_to_amt       := NULL; -- 5132302
147984 l_entered_amt_idx            := NULL;          -- 4262811
147985 l_accted_amt_idx             := NULL;          -- 4262811
147986 l_acc_rev_flag               := NULL;          -- 4262811
147987 l_accrual_line_num           := NULL;          -- 4262811
147988 l_tmp_amt                    := NULL;          -- 4262811
147989 --
147990  
147991 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
147992     l_balance_type_code <> 'B' THEN
147993 IF (NVL(p_source_35,'
147994 ') =  'BONUS EXPENSE' OR 
147995 NVL(p_source_35,'
147996 ') =  'BONUS RESERVE') AND 
147997 NVL(p_source_42,'
147998 ') =  'SOURCE'
147999  THEN 
148000 
148001    --
148002    XLA_AE_LINES_PKG.SetNewLine;
148003 
148004    p_balance_type_code          := l_balance_type_code;
148005    -- set the flag so later we will know whether the gain loss line needs to be created
148006    
148007    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
148008      p_actual_flag :='A';
148009    END IF;
148010 
148011    --
148012    -- bulk performance
148013    --
148014    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
148015                                       p_header_num   => 0); -- 4262811
148016    --
148017    -- set accounting line options
148018    --
148019    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
148020            p_natural_side_code          => 'C'
148021          , p_gain_or_loss_flag          => 'N'
148022          , p_gl_transfer_mode_code      => 'S'
148023          , p_acct_entry_type_code       => 'A'
148024          , p_switch_side_flag           => 'Y'
148025          , p_merge_duplicate_code       => 'N'
148026          );
148027    --
148028    l_acc_rev_natural_side_code := 'D';  -- 4262811
148029    -- 
148030    --
148031    -- set accounting line type info
148032    --
148033    xla_ae_lines_pkg.SetAcctLineType
148034       (p_component_type             => l_component_type
148035       ,p_event_type_code            => l_event_type_code
148036       ,p_line_definition_owner_code => l_line_definition_owner_code
148037       ,p_line_definition_code       => l_line_definition_code
148038       ,p_accounting_line_code       => l_component_code
148039       ,p_accounting_line_type_code  => l_component_type_code
148040       ,p_accounting_line_appl_id    => l_component_appl_id
148041       ,p_amb_context_code           => l_amb_context_code
148042       ,p_entity_code                => l_entity_code
148043       ,p_event_class_code           => l_event_class_code);
148044    --
148045    -- set accounting class
148046    --
148047    xla_ae_lines_pkg.SetAcctClass(
148048            p_accounting_class_code  => 'ASSET'
148049          , p_ae_header_id           => l_ae_header_id
148050          );
148051 
148052    --
148053    -- set rounding class
148054    --
148055    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
148056                       'ASSET';
148057 
148058    --
148059    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
148060    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
148061    --
148062    -- bulk performance
148063    --
148064    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
148065 
148066    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
148067       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
148068 
148069    -- 4955764
148070    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
148071       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
148072 
148073    -- 4458381 Public Sector Enh
148074    
148075    --
148076    -- set accounting attributes for the line type
148077    --
148078    l_entered_amt_idx := 4;
148079    l_accted_amt_idx  := 6;
148080    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
148081    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
148082    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
148083    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
148084    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
148085    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
148086    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
148087    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
148088    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
148089    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
148090    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
148091    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
148092    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
148093 
148094    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
148095    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
148096 
148097    ---------------------------------------------------------------------------------------------------------------
148098    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
148099    ---------------------------------------------------------------------------------------------------------------
148103    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
148100    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
148101 
148102    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
148104 
148105    IF xla_accounting_cache_pkg.GetValueChar
148106          (p_source_code         => 'LEDGER_CATEGORY_CODE'
148107          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
148108    AND l_bflow_method_code = 'PRIOR_ENTRY'
148109 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
148110    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
148111          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
148112        )
148113    THEN
148114          xla_ae_lines_pkg.BflowUpgEntry
148115            (p_business_method_code    => l_bflow_method_code
148116            ,p_business_class_code     => l_bflow_class_code
148117            ,p_balance_type            => l_balance_type_code);
148118    ELSE
148119       NULL;
148120 -- No business flow processing for business flow method of NONE.
148121    END IF;
148122 
148123    --
148124    -- call analytical criteria
148125    --
148126    
148127    --
148128    -- call description
148129    --
148130    
148131 xla_ae_lines_pkg.SetLineDescription(
148132    p_ae_header_id => l_ae_header_id
148133   ,p_description  => Description_113 (
148134      p_application_id         => p_application_id
148135    , p_ae_header_id           => l_ae_header_id 
148136 , p_source_1 => p_source_1
148137    )
148138 );
148139 
148140 
148141    --
148142    -- call ADRs
148143    -- Bug 4922099
148144    --
148145    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
148146         (NVL(l_actual_upg_option, 'N') = 'O') OR
148147         (NVL(l_enc_upg_option, 'N') = 'O')
148148       )
148149    THEN
148150    NULL;
148151    --
148152    --
148153    
148154   l_ccid := AcctDerRule_174(
148155            p_application_id           => p_application_id
148156          , p_ae_header_id             => l_ae_header_id 
148157 , p_source_3 => p_source_3
148158 , p_source_17 => p_source_17
148159 , p_source_30 => p_source_30
148160          , x_transaction_coa_id       => l_adr_transaction_coa_id
148161          , x_accounting_coa_id        => l_adr_accounting_coa_id
148162          , x_value_type_code          => l_adr_value_type_code
148163          , p_side                     => 'NA'
148164    );
148165 
148166    xla_ae_lines_pkg.set_ccid(
148167     p_code_combination_id          => l_ccid
148168   , p_value_type_code              => l_adr_value_type_code
148169   , p_transaction_coa_id           => l_adr_transaction_coa_id
148170   , p_accounting_coa_id            => l_adr_accounting_coa_id
148171   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
148172   , p_adr_type_code                => 'S'
148173   , p_component_type               => l_component_type
148174   , p_component_code               => l_component_code
148175   , p_component_type_code          => l_component_type_code
148176   , p_component_appl_id            => l_component_appl_id
148177   , p_amb_context_code             => l_amb_context_code
148178   , p_side                         => 'NA'
148179   );
148180 
148181 
148182    l_segment := AcctDerRule_149(
148183            p_application_id           => p_application_id
148184          , p_ae_header_id             => l_ae_header_id 
148185 , p_source_3 => p_source_3
148186 , p_source_10 => p_source_10
148187          , x_transaction_coa_id       => l_adr_transaction_coa_id
148188          , x_accounting_coa_id        => l_adr_accounting_coa_id
148189          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
148190          , x_flex_value_set_id        => l_adr_flex_value_set_id
148191          , x_value_type_code          => l_adr_value_type_code
148192          , x_value_combination_id     => l_adr_value_combination_id
148193          , x_value_segment_code       => l_adr_value_segment_code
148194          , p_side                     => 'NA'
148195          , p_override_seg_flag        => 'Y'
148196    );
148197 
148198    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
148199 
148200       xla_ae_lines_pkg.set_segment(
148201           p_to_segment_code         => 'GL_ACCOUNT'
148202         , p_segment_value           => l_segment
148203         , p_from_segment_code       => l_adr_value_segment_code
148204         , p_from_combination_id     => l_adr_value_combination_id
148205         , p_value_type_code         => l_adr_value_type_code
148206         , p_transaction_coa_id      => l_adr_transaction_coa_id
148207         , p_accounting_coa_id       => l_adr_accounting_coa_id
148208         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
148209         , p_flex_value_set_id       => l_adr_flex_value_set_id
148210         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
148211         , p_adr_type_code           => 'S'
148212         , p_component_type          => l_component_type
148213         , p_component_code          => l_component_code
148214         , p_component_type_code     => l_component_type_code
148215         , p_component_appl_id       => l_component_appl_id
148216         , p_amb_context_code        => l_amb_context_code
148217         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
148218         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
148219         , p_side                    => 'NA'
148220         );
148221 
148222   END IF;
148223 
148224    l_segment := AcctDerRule_168(
148225            p_application_id           => p_application_id
148226          , p_ae_header_id             => l_ae_header_id 
148227 , p_source_3 => p_source_3
148228 , p_source_29 => p_source_29
148229          , x_transaction_coa_id       => l_adr_transaction_coa_id
148233          , x_value_type_code          => l_adr_value_type_code
148230          , x_accounting_coa_id        => l_adr_accounting_coa_id
148231          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
148232          , x_flex_value_set_id        => l_adr_flex_value_set_id
148234          , x_value_combination_id     => l_adr_value_combination_id
148235          , x_value_segment_code       => l_adr_value_segment_code
148236          , p_side                     => 'NA'
148237          , p_override_seg_flag        => 'Y'
148238    );
148239 
148240    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
148241 
148242       xla_ae_lines_pkg.set_segment(
148243           p_to_segment_code         => 'GL_BALANCING'
148244         , p_segment_value           => l_segment
148245         , p_from_segment_code       => l_adr_value_segment_code
148246         , p_from_combination_id     => l_adr_value_combination_id
148247         , p_value_type_code         => l_adr_value_type_code
148248         , p_transaction_coa_id      => l_adr_transaction_coa_id
148249         , p_accounting_coa_id       => l_adr_accounting_coa_id
148250         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
148251         , p_flex_value_set_id       => l_adr_flex_value_set_id
148252         , p_adr_code                => 'FA_EXPENSE_ACCT'
148253         , p_adr_type_code           => 'S'
148254         , p_component_type          => l_component_type
148255         , p_component_code          => l_component_code
148256         , p_component_type_code     => l_component_type_code
148257         , p_component_appl_id       => l_component_appl_id
148258         , p_amb_context_code        => l_amb_context_code
148259         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
148260         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
148261         , p_side                    => 'NA'
148262         );
148263 
148264   END IF;
148265 
148266    --
148267    --
148268    END IF;
148269    --
148270    -- Bug 4922099
148271    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
148272           (NVL(l_enc_upg_option, 'N') = 'O')
148273         ) AND
148274         (l_bflow_method_code = 'PRIOR_ENTRY')
148275       )
148276    THEN
148277       IF
148278       --
148279       1 = 2
148280       --
148281       THEN
148282       xla_accounting_err_pkg.build_message
148283                                     (p_appli_s_name            => 'XLA'
148284                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
148285                                     ,p_token_1                 => 'LINE_NUMBER'
148286                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
148287                                     ,p_token_2                 => 'LINE_TYPE_NAME'
148288                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
148289                                                                              l_component_type
148290                                                                             ,l_component_code
148291                                                                             ,l_component_type_code
148292                                                                             ,l_component_appl_id
148293                                                                             ,l_amb_context_code
148294                                                                             ,l_entity_code
148295                                                                             ,l_event_class_code
148296                                                                            )
148297                                     ,p_token_3                 => 'OWNER'
148298                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
148299                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
148300                                                                           ,p_lookup_code    => l_component_type_code
148301                                                                          )
148302                                     ,p_token_4                 => 'PRODUCT_NAME'
148303                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
148304                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
148305                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
148306                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
148307                                     ,p_ae_header_id            =>  NULL
148308                                        );
148309 
148310         IF (C_LEVEL_ERROR>= g_log_level) THEN
148311                  trace
148312                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
148313                       ,p_level    => C_LEVEL_ERROR
148314                       ,p_module   => l_log_module);
148315         END IF;
148316       END IF;
148317    END IF;
148318    --
148319    --
148320    ------------------------------------------------------------------------------------------------
148321    -- 4219869 Business Flow
148322    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
148323    -- Prior Entry.  Currently, the following code is always generated.
148324    ------------------------------------------------------------------------------------------------
148325    XLA_AE_LINES_PKG.ValidateCurrentLine;
148326 
148327    ------------------------------------------------------------------------------------
148328    -- 4219869 Business Flow
148329    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
148330    ------------------------------------------------------------------------------------
148331    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
148332 
148336    ----------------------------------------------------------------------------------
148333    ----------------------------------------------------------------------------------
148334    -- 4219869 Business Flow
148335    -- Update journal entry status -- Need to generate this within IF <condition>
148337    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
148338          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
148339          ,p_balance_type_code => l_balance_type_code
148340          );
148341 
148342    -------------------------------------------------------------------------------------------
148343    -- 4262811 - Generate the Accrual Reversal lines
148344    -------------------------------------------------------------------------------------------
148345    BEGIN
148346       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
148347                               (g_array_event(p_event_id).array_value_num('header_index'));
148348       IF l_acc_rev_flag IS NULL THEN
148349          l_acc_rev_flag := 'N';
148350       END IF;
148351    EXCEPTION
148352       WHEN OTHERS THEN
148353          l_acc_rev_flag := 'N';
148354    END;
148355    --
148356    IF (l_acc_rev_flag = 'Y') THEN
148357 
148358        -- 4645092  ------------------------------------------------------------------------------
148359        -- To allow MPA report to determine if it should generate report process
148360        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
148361        ------------------------------------------------------------------------------------------
148362 
148363        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
148364        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
148365    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
148366    -- call ADRs
148367    -- Bug 4922099
148368    --
148369    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
148370         (NVL(l_actual_upg_option, 'N') = 'O') OR
148371         (NVL(l_enc_upg_option, 'N') = 'O')
148372       )
148373    THEN
148374    NULL;
148375    --
148376    --
148377    
148378   l_ccid := AcctDerRule_174(
148379            p_application_id           => p_application_id
148380          , p_ae_header_id             => l_ae_header_id 
148381 , p_source_3 => p_source_3
148382 , p_source_17 => p_source_17
148383 , p_source_30 => p_source_30
148384          , x_transaction_coa_id       => l_adr_transaction_coa_id
148385          , x_accounting_coa_id        => l_adr_accounting_coa_id
148386          , x_value_type_code          => l_adr_value_type_code
148387          , p_side                     => 'NA'
148388    );
148389 
148390    xla_ae_lines_pkg.set_ccid(
148391     p_code_combination_id          => l_ccid
148392   , p_value_type_code              => l_adr_value_type_code
148393   , p_transaction_coa_id           => l_adr_transaction_coa_id
148394   , p_accounting_coa_id            => l_adr_accounting_coa_id
148395   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
148396   , p_adr_type_code                => 'S'
148397   , p_component_type               => l_component_type
148398   , p_component_code               => l_component_code
148399   , p_component_type_code          => l_component_type_code
148400   , p_component_appl_id            => l_component_appl_id
148401   , p_amb_context_code             => l_amb_context_code
148402   , p_side                         => 'NA'
148403   );
148404 
148405 
148406    l_segment := AcctDerRule_149(
148407            p_application_id           => p_application_id
148408          , p_ae_header_id             => l_ae_header_id 
148409 , p_source_3 => p_source_3
148410 , p_source_10 => p_source_10
148411          , x_transaction_coa_id       => l_adr_transaction_coa_id
148412          , x_accounting_coa_id        => l_adr_accounting_coa_id
148413          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
148414          , x_flex_value_set_id        => l_adr_flex_value_set_id
148415          , x_value_type_code          => l_adr_value_type_code
148416          , x_value_combination_id     => l_adr_value_combination_id
148417          , x_value_segment_code       => l_adr_value_segment_code
148418          , p_side                     => 'NA'
148419          , p_override_seg_flag        => 'Y'
148420    );
148421 
148422    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
148423 
148424       xla_ae_lines_pkg.set_segment(
148425           p_to_segment_code         => 'GL_ACCOUNT'
148426         , p_segment_value           => l_segment
148427         , p_from_segment_code       => l_adr_value_segment_code
148428         , p_from_combination_id     => l_adr_value_combination_id
148429         , p_value_type_code         => l_adr_value_type_code
148430         , p_transaction_coa_id      => l_adr_transaction_coa_id
148431         , p_accounting_coa_id       => l_adr_accounting_coa_id
148432         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
148433         , p_flex_value_set_id       => l_adr_flex_value_set_id
148434         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
148435         , p_adr_type_code           => 'S'
148436         , p_component_type          => l_component_type
148437         , p_component_code          => l_component_code
148438         , p_component_type_code     => l_component_type_code
148439         , p_component_appl_id       => l_component_appl_id
148440         , p_amb_context_code        => l_amb_context_code
148441         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
148442         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
148443         , p_side                    => 'NA'
148444         );
148445 
148446   END IF;
148447 
148448    l_segment := AcctDerRule_168(
148449            p_application_id           => p_application_id
148450          , p_ae_header_id             => l_ae_header_id 
148451 , p_source_3 => p_source_3
148452 , p_source_29 => p_source_29
148453          , x_transaction_coa_id       => l_adr_transaction_coa_id
148457          , x_value_type_code          => l_adr_value_type_code
148454          , x_accounting_coa_id        => l_adr_accounting_coa_id
148455          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
148456          , x_flex_value_set_id        => l_adr_flex_value_set_id
148458          , x_value_combination_id     => l_adr_value_combination_id
148459          , x_value_segment_code       => l_adr_value_segment_code
148460          , p_side                     => 'NA'
148461          , p_override_seg_flag        => 'Y'
148462    );
148463 
148464    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
148465 
148466       xla_ae_lines_pkg.set_segment(
148467           p_to_segment_code         => 'GL_BALANCING'
148468         , p_segment_value           => l_segment
148469         , p_from_segment_code       => l_adr_value_segment_code
148470         , p_from_combination_id     => l_adr_value_combination_id
148471         , p_value_type_code         => l_adr_value_type_code
148472         , p_transaction_coa_id      => l_adr_transaction_coa_id
148473         , p_accounting_coa_id       => l_adr_accounting_coa_id
148474         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
148475         , p_flex_value_set_id       => l_adr_flex_value_set_id
148476         , p_adr_code                => 'FA_EXPENSE_ACCT'
148477         , p_adr_type_code           => 'S'
148478         , p_component_type          => l_component_type
148479         , p_component_code          => l_component_code
148480         , p_component_type_code     => l_component_type_code
148481         , p_component_appl_id       => l_component_appl_id
148482         , p_amb_context_code        => l_amb_context_code
148483         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
148484         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
148485         , p_side                    => 'NA'
148486         );
148487 
148488   END IF;
148489 
148490    --
148491    --
148492    END IF;
148493 
148494        --
148495        -- Update the line information that should be overwritten
148496        --
148497        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
148498                                          p_header_num   => 1);
148499        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
148500 
148501        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
148502 
148503        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
148504           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
148505        END IF;
148506 
148507       --
148508       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
148509       --
148510       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
148511           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
148512       ELSE
148513           ---------------------------------------------------------------------------------------------------
148514           -- 4262811a Switch Sign
148515           ---------------------------------------------------------------------------------------------------
148516           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
148517           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
148518                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
148519           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
148520                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
148521           -- 5132302
148522           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
148523                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
148524 
148525       END IF;
148526 
148527       -- 4955764
148528       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
148529       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
148530 
148531 
148532       XLA_AE_LINES_PKG.ValidateCurrentLine;
148533       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
148534 
148535       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
148536                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
148537                ,p_balance_type_code => l_balance_type_code);
148538 
148539    END IF;
148540 
148541    -----------------------------------------------------------------------------------------
148542    -- 4262811 Multiperiod Accounting
148543    -----------------------------------------------------------------------------------------
148544      -- No MPA option is assigned.
148545 
148546 
148547 END IF;
148548 END IF;
148549 --
148550 
148551 --
148552 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
148553    trace
148554       (p_msg      => 'END of AcctLineType_362'
148555       ,p_level    => C_LEVEL_PROCEDURE
148556       ,p_module   => l_log_module);
148557 END IF;
148558 --
148559 EXCEPTION
148560   WHEN xla_exceptions_pkg.application_exception THEN
148561       RAISE;
148562   WHEN OTHERS THEN
148563        xla_exceptions_pkg.raise_message
148564            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_362');
148565 END AcctLineType_362;
148566 --
148567 
148568 ---------------------------------------
148569 --
148570 -- PRIVATE FUNCTION
148571 --         AcctLineType_363
148572 --
148573 ---------------------------------------
148574 PROCEDURE AcctLineType_363 (
148575   p_application_id        IN NUMBER
148576  ,p_event_id              IN NUMBER
148577  ,p_calculate_acctd_flag  IN VARCHAR2
148581  ,p_gain_or_loss_ref      OUT VARCHAR2
148578  ,p_calculate_g_l_flag    IN VARCHAR2
148579  ,p_actual_flag           IN OUT VARCHAR2
148580  ,p_balance_type_code     OUT VARCHAR2
148582  
148583 --Period Close Date
148584  , p_source_1            IN DATE
148585 --Generated Code Combination Identifier
148586  , p_source_3            IN NUMBER
148587 --Revaluation Reserve Account
148588  , p_source_11            IN VARCHAR2
148589 --Generated Offset Code Combination Identifier
148590  , p_source_17            IN NUMBER
148591 --Expense Account Code Combination Identifier
148592  , p_source_29            IN NUMBER
148593 --Default Code Combination Identifier
148594  , p_source_30            IN NUMBER
148595 --Adjustment Type
148596  , p_source_35            IN VARCHAR2
148597 --Transaction Header Identifier
148598  , p_source_36            IN NUMBER
148599 --Adjustment Line Identifier
148600  , p_source_37            IN NUMBER
148601 --Distribution Type Code
148602  , p_source_38            IN VARCHAR2
148603 --Entered Amount
148604  , p_source_39            IN NUMBER
148605 --Currency Code
148606  , p_source_40            IN VARCHAR2
148607 --Source Destination Code
148608  , p_source_42            IN VARCHAR2
148609 )
148610 IS
148611 
148612 l_component_type              VARCHAR2(80);
148613 l_component_code              VARCHAR2(30);
148614 l_component_type_code         VARCHAR2(1);
148615 l_component_appl_id           INTEGER;
148616 l_amb_context_code            VARCHAR2(30);
148617 l_entity_code                 VARCHAR2(30);
148618 l_event_class_code            VARCHAR2(30);
148619 l_ae_header_id                NUMBER;
148620 l_event_type_code             VARCHAR2(30);
148621 l_line_definition_code        VARCHAR2(30);
148622 l_line_definition_owner_code  VARCHAR2(1);
148623 --
148624 -- adr variables
148625 l_segment                     VARCHAR2(30);
148626 l_ccid                        NUMBER;
148627 l_adr_transaction_coa_id      NUMBER;
148628 l_adr_accounting_coa_id       NUMBER;
148629 l_adr_flexfield_segment_code  VARCHAR2(30);
148630 l_adr_flex_value_set_id       NUMBER;
148631 l_adr_value_type_code         VARCHAR2(30);
148632 l_adr_value_combination_id    NUMBER;
148633 l_adr_value_segment_code      VARCHAR2(30);
148634 
148635 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
148636 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
148637 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
148638 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
148639 
148640 -- 4262811 Variables ------------------------------------------------------------------------------------------
148641 l_entered_amt_idx             NUMBER;
148642 l_accted_amt_idx              NUMBER;
148643 l_acc_rev_flag                VARCHAR2(1);
148644 l_accrual_line_num            NUMBER;
148645 l_tmp_amt                     NUMBER;
148646 l_acc_rev_natural_side_code   VARCHAR2(1);
148647 
148648 l_num_entries                 NUMBER;
148649 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
148650 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
148651 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
148652 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
148653 l_recog_line_1                NUMBER;
148654 l_recog_line_2                NUMBER;
148655 
148656 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
148657 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
148658 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
148659 
148660 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
148661 
148662 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
148663 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
148664 
148665 ---------------------------------------------------------------------------------------------------------------
148666 
148667 
148668 --
148669 -- bulk performance
148670 --
148671 l_balance_type_code           VARCHAR2(1);
148672 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
148673 l_log_module                  VARCHAR2(240);
148674 
148675 --
148676 -- Upgrade strategy
148677 --
148678 l_actual_upg_option           VARCHAR2(1);
148679 l_enc_upg_option           VARCHAR2(1);
148680 
148681 --
148682 BEGIN
148683 --
148684 IF g_log_enabled THEN
148685       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_363';
148686 END IF;
148687 --
148688 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
148689 
148690       trace
148691          (p_msg      => 'BEGIN of AcctLineType_363'
148692          ,p_level    => C_LEVEL_PROCEDURE
148693          ,p_module   => l_log_module);
148694 
148695 END IF;
148696 --
148697 l_component_type             := 'AMB_JLT';
148698 l_component_code             := 'FA_SLT_SOURCE_REVAL_RESERVE';
148699 l_component_type_code        := 'S';
148700 l_component_appl_id          :=  140;
148701 l_amb_context_code           := 'DEFAULT';
148702 l_entity_code                := 'INTER_ASSET_TRANSACTIONS';
148703 l_event_class_code           := 'SOURCE_LINE_TRANSFERS';
148704 l_event_type_code            := 'SOURCE_LINE_TRANSFERS_ALL';
148705 l_line_definition_owner_code := 'S';
148706 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_SOURC23';
148707 --
148708 l_balance_type_code          := 'A';
148709 l_segment                     := NULL;
148710 l_ccid                        := NULL;
148711 l_adr_transaction_coa_id      := NULL;
148712 l_adr_accounting_coa_id       := NULL;
148713 l_adr_flexfield_segment_code  := NULL;
148714 l_adr_flex_value_set_id       := NULL;
148715 l_adr_value_type_code         := NULL;
148716 l_adr_value_combination_id    := NULL;
148717 l_adr_value_segment_code      := NULL;
148718 
148722 l_budgetary_control_flag     := 'N';
148719 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
148720 l_bflow_class_code           := '';    -- 4219869 Business Flow
148721 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
148723 
148724 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
148725 l_bflow_applied_to_amt       := NULL; -- 5132302
148726 l_entered_amt_idx            := NULL;          -- 4262811
148727 l_accted_amt_idx             := NULL;          -- 4262811
148728 l_acc_rev_flag               := NULL;          -- 4262811
148729 l_accrual_line_num           := NULL;          -- 4262811
148730 l_tmp_amt                    := NULL;          -- 4262811
148731 --
148732  
148733 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
148734     l_balance_type_code <> 'B' THEN
148735 IF NVL(p_source_35,'
148736 ') =  'REVAL RESERVE' AND 
148737 NVL(p_source_42,'
148738 ') =  'SOURCE'
148739  THEN 
148740 
148741    --
148742    XLA_AE_LINES_PKG.SetNewLine;
148743 
148744    p_balance_type_code          := l_balance_type_code;
148745    -- set the flag so later we will know whether the gain loss line needs to be created
148746    
148747    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
148748      p_actual_flag :='A';
148749    END IF;
148750 
148751    --
148752    -- bulk performance
148753    --
148754    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
148755                                       p_header_num   => 0); -- 4262811
148756    --
148757    -- set accounting line options
148758    --
148759    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
148760            p_natural_side_code          => 'D'
148761          , p_gain_or_loss_flag          => 'N'
148762          , p_gl_transfer_mode_code      => 'S'
148763          , p_acct_entry_type_code       => 'A'
148764          , p_switch_side_flag           => 'Y'
148765          , p_merge_duplicate_code       => 'N'
148766          );
148767    --
148768    l_acc_rev_natural_side_code := 'C';  -- 4262811
148769    -- 
148770    --
148771    -- set accounting line type info
148772    --
148773    xla_ae_lines_pkg.SetAcctLineType
148774       (p_component_type             => l_component_type
148775       ,p_event_type_code            => l_event_type_code
148776       ,p_line_definition_owner_code => l_line_definition_owner_code
148777       ,p_line_definition_code       => l_line_definition_code
148778       ,p_accounting_line_code       => l_component_code
148779       ,p_accounting_line_type_code  => l_component_type_code
148780       ,p_accounting_line_appl_id    => l_component_appl_id
148781       ,p_amb_context_code           => l_amb_context_code
148782       ,p_entity_code                => l_entity_code
148783       ,p_event_class_code           => l_event_class_code);
148784    --
148785    -- set accounting class
148786    --
148787    xla_ae_lines_pkg.SetAcctClass(
148788            p_accounting_class_code  => 'ASSET'
148789          , p_ae_header_id           => l_ae_header_id
148790          );
148791 
148792    --
148793    -- set rounding class
148794    --
148795    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
148796                       'ASSET';
148797 
148798    --
148799    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
148800    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
148801    --
148802    -- bulk performance
148803    --
148804    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
148805 
148806    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
148807       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
148808 
148809    -- 4955764
148810    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
148811       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
148812 
148813    -- 4458381 Public Sector Enh
148814    
148815    --
148816    -- set accounting attributes for the line type
148817    --
148818    l_entered_amt_idx := 4;
148819    l_accted_amt_idx  := 6;
148820    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
148821    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
148822    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
148823    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
148824    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
148825    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
148826    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
148827    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
148828    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
148829    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
148830    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
148831    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
148832    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
148833 
148834    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
148835    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
148836 
148837    ---------------------------------------------------------------------------------------------------------------
148838    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
148839    ---------------------------------------------------------------------------------------------------------------
148840    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
148841 
148842    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
148846          (p_source_code         => 'LEDGER_CATEGORY_CODE'
148843    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
148844 
148845    IF xla_accounting_cache_pkg.GetValueChar
148847          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
148848    AND l_bflow_method_code = 'PRIOR_ENTRY'
148849 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
148850    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
148851          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
148852        )
148853    THEN
148854          xla_ae_lines_pkg.BflowUpgEntry
148855            (p_business_method_code    => l_bflow_method_code
148856            ,p_business_class_code     => l_bflow_class_code
148857            ,p_balance_type            => l_balance_type_code);
148858    ELSE
148859       NULL;
148860 -- No business flow processing for business flow method of NONE.
148861    END IF;
148862 
148863    --
148864    -- call analytical criteria
148865    --
148866    
148867    --
148868    -- call description
148869    --
148870    
148871 xla_ae_lines_pkg.SetLineDescription(
148872    p_ae_header_id => l_ae_header_id
148873   ,p_description  => Description_116 (
148874      p_application_id         => p_application_id
148875    , p_ae_header_id           => l_ae_header_id 
148876 , p_source_1 => p_source_1
148877    )
148878 );
148879 
148880 
148881    --
148882    -- call ADRs
148883    -- Bug 4922099
148884    --
148885    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
148886         (NVL(l_actual_upg_option, 'N') = 'O') OR
148887         (NVL(l_enc_upg_option, 'N') = 'O')
148888       )
148889    THEN
148890    NULL;
148891    --
148892    --
148893    
148894   l_ccid := AcctDerRule_174(
148895            p_application_id           => p_application_id
148896          , p_ae_header_id             => l_ae_header_id 
148897 , p_source_3 => p_source_3
148898 , p_source_17 => p_source_17
148899 , p_source_30 => p_source_30
148900          , x_transaction_coa_id       => l_adr_transaction_coa_id
148901          , x_accounting_coa_id        => l_adr_accounting_coa_id
148902          , x_value_type_code          => l_adr_value_type_code
148903          , p_side                     => 'NA'
148904    );
148905 
148906    xla_ae_lines_pkg.set_ccid(
148907     p_code_combination_id          => l_ccid
148908   , p_value_type_code              => l_adr_value_type_code
148909   , p_transaction_coa_id           => l_adr_transaction_coa_id
148910   , p_accounting_coa_id            => l_adr_accounting_coa_id
148911   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
148912   , p_adr_type_code                => 'S'
148913   , p_component_type               => l_component_type
148914   , p_component_code               => l_component_code
148915   , p_component_type_code          => l_component_type_code
148916   , p_component_appl_id            => l_component_appl_id
148917   , p_amb_context_code             => l_amb_context_code
148918   , p_side                         => 'NA'
148919   );
148920 
148921 
148922    l_segment := AcctDerRule_150(
148923            p_application_id           => p_application_id
148924          , p_ae_header_id             => l_ae_header_id 
148925 , p_source_3 => p_source_3
148926 , p_source_11 => p_source_11
148927          , x_transaction_coa_id       => l_adr_transaction_coa_id
148928          , x_accounting_coa_id        => l_adr_accounting_coa_id
148929          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
148930          , x_flex_value_set_id        => l_adr_flex_value_set_id
148931          , x_value_type_code          => l_adr_value_type_code
148932          , x_value_combination_id     => l_adr_value_combination_id
148933          , x_value_segment_code       => l_adr_value_segment_code
148934          , p_side                     => 'NA'
148935          , p_override_seg_flag        => 'Y'
148936    );
148937 
148938    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
148939 
148940       xla_ae_lines_pkg.set_segment(
148941           p_to_segment_code         => 'GL_ACCOUNT'
148942         , p_segment_value           => l_segment
148943         , p_from_segment_code       => l_adr_value_segment_code
148944         , p_from_combination_id     => l_adr_value_combination_id
148945         , p_value_type_code         => l_adr_value_type_code
148946         , p_transaction_coa_id      => l_adr_transaction_coa_id
148947         , p_accounting_coa_id       => l_adr_accounting_coa_id
148948         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
148949         , p_flex_value_set_id       => l_adr_flex_value_set_id
148950         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
148951         , p_adr_type_code           => 'S'
148952         , p_component_type          => l_component_type
148953         , p_component_code          => l_component_code
148954         , p_component_type_code     => l_component_type_code
148955         , p_component_appl_id       => l_component_appl_id
148956         , p_amb_context_code        => l_amb_context_code
148957         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
148958         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
148959         , p_side                    => 'NA'
148960         );
148961 
148962   END IF;
148963 
148964    l_segment := AcctDerRule_168(
148965            p_application_id           => p_application_id
148966          , p_ae_header_id             => l_ae_header_id 
148967 , p_source_3 => p_source_3
148968 , p_source_29 => p_source_29
148969          , x_transaction_coa_id       => l_adr_transaction_coa_id
148970          , x_accounting_coa_id        => l_adr_accounting_coa_id
148971          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
148972          , x_flex_value_set_id        => l_adr_flex_value_set_id
148973          , x_value_type_code          => l_adr_value_type_code
148977          , p_override_seg_flag        => 'Y'
148974          , x_value_combination_id     => l_adr_value_combination_id
148975          , x_value_segment_code       => l_adr_value_segment_code
148976          , p_side                     => 'NA'
148978    );
148979 
148980    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
148981 
148982       xla_ae_lines_pkg.set_segment(
148983           p_to_segment_code         => 'GL_BALANCING'
148984         , p_segment_value           => l_segment
148985         , p_from_segment_code       => l_adr_value_segment_code
148986         , p_from_combination_id     => l_adr_value_combination_id
148987         , p_value_type_code         => l_adr_value_type_code
148988         , p_transaction_coa_id      => l_adr_transaction_coa_id
148989         , p_accounting_coa_id       => l_adr_accounting_coa_id
148990         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
148991         , p_flex_value_set_id       => l_adr_flex_value_set_id
148992         , p_adr_code                => 'FA_EXPENSE_ACCT'
148993         , p_adr_type_code           => 'S'
148994         , p_component_type          => l_component_type
148995         , p_component_code          => l_component_code
148996         , p_component_type_code     => l_component_type_code
148997         , p_component_appl_id       => l_component_appl_id
148998         , p_amb_context_code        => l_amb_context_code
148999         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
149000         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
149001         , p_side                    => 'NA'
149002         );
149003 
149004   END IF;
149005 
149006    --
149007    --
149008    END IF;
149009    --
149010    -- Bug 4922099
149011    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
149012           (NVL(l_enc_upg_option, 'N') = 'O')
149013         ) AND
149014         (l_bflow_method_code = 'PRIOR_ENTRY')
149015       )
149016    THEN
149017       IF
149018       --
149019       1 = 2
149020       --
149021       THEN
149022       xla_accounting_err_pkg.build_message
149023                                     (p_appli_s_name            => 'XLA'
149024                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
149025                                     ,p_token_1                 => 'LINE_NUMBER'
149026                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
149027                                     ,p_token_2                 => 'LINE_TYPE_NAME'
149028                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
149029                                                                              l_component_type
149030                                                                             ,l_component_code
149031                                                                             ,l_component_type_code
149032                                                                             ,l_component_appl_id
149033                                                                             ,l_amb_context_code
149034                                                                             ,l_entity_code
149035                                                                             ,l_event_class_code
149036                                                                            )
149037                                     ,p_token_3                 => 'OWNER'
149038                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
149039                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
149040                                                                           ,p_lookup_code    => l_component_type_code
149041                                                                          )
149042                                     ,p_token_4                 => 'PRODUCT_NAME'
149043                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
149044                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
149045                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
149046                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
149047                                     ,p_ae_header_id            =>  NULL
149048                                        );
149049 
149050         IF (C_LEVEL_ERROR>= g_log_level) THEN
149051                  trace
149052                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
149053                       ,p_level    => C_LEVEL_ERROR
149054                       ,p_module   => l_log_module);
149055         END IF;
149056       END IF;
149057    END IF;
149058    --
149059    --
149060    ------------------------------------------------------------------------------------------------
149061    -- 4219869 Business Flow
149062    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
149063    -- Prior Entry.  Currently, the following code is always generated.
149064    ------------------------------------------------------------------------------------------------
149065    XLA_AE_LINES_PKG.ValidateCurrentLine;
149066 
149067    ------------------------------------------------------------------------------------
149068    -- 4219869 Business Flow
149069    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
149070    ------------------------------------------------------------------------------------
149071    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
149072 
149073    ----------------------------------------------------------------------------------
149074    -- 4219869 Business Flow
149075    -- Update journal entry status -- Need to generate this within IF <condition>
149076    ----------------------------------------------------------------------------------
149077    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
149081 
149078          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
149079          ,p_balance_type_code => l_balance_type_code
149080          );
149082    -------------------------------------------------------------------------------------------
149083    -- 4262811 - Generate the Accrual Reversal lines
149084    -------------------------------------------------------------------------------------------
149085    BEGIN
149086       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
149087                               (g_array_event(p_event_id).array_value_num('header_index'));
149088       IF l_acc_rev_flag IS NULL THEN
149089          l_acc_rev_flag := 'N';
149090       END IF;
149091    EXCEPTION
149092       WHEN OTHERS THEN
149093          l_acc_rev_flag := 'N';
149094    END;
149095    --
149096    IF (l_acc_rev_flag = 'Y') THEN
149097 
149098        -- 4645092  ------------------------------------------------------------------------------
149099        -- To allow MPA report to determine if it should generate report process
149100        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
149101        ------------------------------------------------------------------------------------------
149102 
149103        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
149104        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
149105    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
149106    -- call ADRs
149107    -- Bug 4922099
149108    --
149109    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
149110         (NVL(l_actual_upg_option, 'N') = 'O') OR
149111         (NVL(l_enc_upg_option, 'N') = 'O')
149112       )
149113    THEN
149114    NULL;
149115    --
149116    --
149117    
149118   l_ccid := AcctDerRule_174(
149119            p_application_id           => p_application_id
149120          , p_ae_header_id             => l_ae_header_id 
149121 , p_source_3 => p_source_3
149122 , p_source_17 => p_source_17
149123 , p_source_30 => p_source_30
149124          , x_transaction_coa_id       => l_adr_transaction_coa_id
149125          , x_accounting_coa_id        => l_adr_accounting_coa_id
149126          , x_value_type_code          => l_adr_value_type_code
149127          , p_side                     => 'NA'
149128    );
149129 
149130    xla_ae_lines_pkg.set_ccid(
149131     p_code_combination_id          => l_ccid
149132   , p_value_type_code              => l_adr_value_type_code
149133   , p_transaction_coa_id           => l_adr_transaction_coa_id
149134   , p_accounting_coa_id            => l_adr_accounting_coa_id
149135   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
149136   , p_adr_type_code                => 'S'
149137   , p_component_type               => l_component_type
149138   , p_component_code               => l_component_code
149139   , p_component_type_code          => l_component_type_code
149140   , p_component_appl_id            => l_component_appl_id
149141   , p_amb_context_code             => l_amb_context_code
149142   , p_side                         => 'NA'
149143   );
149144 
149145 
149146    l_segment := AcctDerRule_150(
149147            p_application_id           => p_application_id
149148          , p_ae_header_id             => l_ae_header_id 
149149 , p_source_3 => p_source_3
149150 , p_source_11 => p_source_11
149151          , x_transaction_coa_id       => l_adr_transaction_coa_id
149152          , x_accounting_coa_id        => l_adr_accounting_coa_id
149153          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
149154          , x_flex_value_set_id        => l_adr_flex_value_set_id
149155          , x_value_type_code          => l_adr_value_type_code
149156          , x_value_combination_id     => l_adr_value_combination_id
149157          , x_value_segment_code       => l_adr_value_segment_code
149158          , p_side                     => 'NA'
149159          , p_override_seg_flag        => 'Y'
149160    );
149161 
149162    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
149163 
149164       xla_ae_lines_pkg.set_segment(
149165           p_to_segment_code         => 'GL_ACCOUNT'
149166         , p_segment_value           => l_segment
149167         , p_from_segment_code       => l_adr_value_segment_code
149168         , p_from_combination_id     => l_adr_value_combination_id
149169         , p_value_type_code         => l_adr_value_type_code
149170         , p_transaction_coa_id      => l_adr_transaction_coa_id
149171         , p_accounting_coa_id       => l_adr_accounting_coa_id
149172         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
149173         , p_flex_value_set_id       => l_adr_flex_value_set_id
149174         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
149175         , p_adr_type_code           => 'S'
149176         , p_component_type          => l_component_type
149177         , p_component_code          => l_component_code
149178         , p_component_type_code     => l_component_type_code
149179         , p_component_appl_id       => l_component_appl_id
149180         , p_amb_context_code        => l_amb_context_code
149181         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
149182         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
149183         , p_side                    => 'NA'
149184         );
149185 
149186   END IF;
149187 
149188    l_segment := AcctDerRule_168(
149189            p_application_id           => p_application_id
149190          , p_ae_header_id             => l_ae_header_id 
149191 , p_source_3 => p_source_3
149192 , p_source_29 => p_source_29
149193          , x_transaction_coa_id       => l_adr_transaction_coa_id
149194          , x_accounting_coa_id        => l_adr_accounting_coa_id
149195          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
149196          , x_flex_value_set_id        => l_adr_flex_value_set_id
149197          , x_value_type_code          => l_adr_value_type_code
149198          , x_value_combination_id     => l_adr_value_combination_id
149202    );
149199          , x_value_segment_code       => l_adr_value_segment_code
149200          , p_side                     => 'NA'
149201          , p_override_seg_flag        => 'Y'
149203 
149204    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
149205 
149206       xla_ae_lines_pkg.set_segment(
149207           p_to_segment_code         => 'GL_BALANCING'
149208         , p_segment_value           => l_segment
149209         , p_from_segment_code       => l_adr_value_segment_code
149210         , p_from_combination_id     => l_adr_value_combination_id
149211         , p_value_type_code         => l_adr_value_type_code
149212         , p_transaction_coa_id      => l_adr_transaction_coa_id
149213         , p_accounting_coa_id       => l_adr_accounting_coa_id
149214         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
149215         , p_flex_value_set_id       => l_adr_flex_value_set_id
149216         , p_adr_code                => 'FA_EXPENSE_ACCT'
149217         , p_adr_type_code           => 'S'
149218         , p_component_type          => l_component_type
149219         , p_component_code          => l_component_code
149220         , p_component_type_code     => l_component_type_code
149221         , p_component_appl_id       => l_component_appl_id
149222         , p_amb_context_code        => l_amb_context_code
149223         , p_entity_code             => 'INTER_ASSET_TRANSACTIONS'
149224         , p_event_class_code        => 'SOURCE_LINE_TRANSFERS'
149225         , p_side                    => 'NA'
149226         );
149227 
149228   END IF;
149229 
149230    --
149231    --
149232    END IF;
149233 
149234        --
149235        -- Update the line information that should be overwritten
149236        --
149237        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
149238                                          p_header_num   => 1);
149239        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
149240 
149241        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
149242 
149243        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
149244           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
149245        END IF;
149246 
149247       --
149248       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
149249       --
149250       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
149251           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
149252       ELSE
149253           ---------------------------------------------------------------------------------------------------
149254           -- 4262811a Switch Sign
149255           ---------------------------------------------------------------------------------------------------
149256           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
149257           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
149258                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
149259           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
149260                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
149261           -- 5132302
149262           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
149263                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
149264 
149265       END IF;
149266 
149267       -- 4955764
149268       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
149269       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
149270 
149271 
149272       XLA_AE_LINES_PKG.ValidateCurrentLine;
149273       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
149274 
149275       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
149276                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
149277                ,p_balance_type_code => l_balance_type_code);
149278 
149279    END IF;
149280 
149281    -----------------------------------------------------------------------------------------
149282    -- 4262811 Multiperiod Accounting
149283    -----------------------------------------------------------------------------------------
149284      -- No MPA option is assigned.
149285 
149286 
149287 END IF;
149288 END IF;
149289 --
149290 
149291 --
149292 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
149293    trace
149294       (p_msg      => 'END of AcctLineType_363'
149295       ,p_level    => C_LEVEL_PROCEDURE
149296       ,p_module   => l_log_module);
149297 END IF;
149298 --
149299 EXCEPTION
149300   WHEN xla_exceptions_pkg.application_exception THEN
149301       RAISE;
149302   WHEN OTHERS THEN
149303        xla_exceptions_pkg.raise_message
149304            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_363');
149305 END AcctLineType_363;
149306 --
149307 
149308 ---------------------------------------
149309 --
149310 -- PRIVATE FUNCTION
149311 --         AcctLineType_364
149312 --
149313 ---------------------------------------
149314 PROCEDURE AcctLineType_364 (
149315   p_application_id        IN NUMBER
149316  ,p_event_id              IN NUMBER
149317  ,p_calculate_acctd_flag  IN VARCHAR2
149318  ,p_calculate_g_l_flag    IN VARCHAR2
149319  ,p_actual_flag           IN OUT VARCHAR2
149320  ,p_balance_type_code     OUT VARCHAR2
149321  ,p_gain_or_loss_ref      OUT VARCHAR2
149322  
149323 --Period Close Date
149324  , p_source_1            IN DATE
149325 --Generated Code Combination Identifier
149326  , p_source_3            IN NUMBER
149330  , p_source_29            IN NUMBER
149327 --Depreciation Adjustment Account
149328  , p_source_18            IN VARCHAR2
149329 --Expense Account Code Combination Identifier
149331 --Default Code Combination Identifier
149332  , p_source_30            IN NUMBER
149333 --Adjustment Type
149334  , p_source_35            IN VARCHAR2
149335 --Transaction Header Identifier
149336  , p_source_36            IN NUMBER
149337 --Adjustment Line Identifier
149338  , p_source_37            IN NUMBER
149339 --Distribution Type Code
149340  , p_source_38            IN VARCHAR2
149341 --Entered Amount
149342  , p_source_39            IN NUMBER
149343 --Currency Code
149344  , p_source_40            IN VARCHAR2
149345 )
149346 IS
149347 
149348 l_component_type              VARCHAR2(80);
149349 l_component_code              VARCHAR2(30);
149350 l_component_type_code         VARCHAR2(1);
149351 l_component_appl_id           INTEGER;
149352 l_amb_context_code            VARCHAR2(30);
149353 l_entity_code                 VARCHAR2(30);
149354 l_event_class_code            VARCHAR2(30);
149355 l_ae_header_id                NUMBER;
149356 l_event_type_code             VARCHAR2(30);
149357 l_line_definition_code        VARCHAR2(30);
149358 l_line_definition_owner_code  VARCHAR2(1);
149359 --
149360 -- adr variables
149361 l_segment                     VARCHAR2(30);
149362 l_ccid                        NUMBER;
149363 l_adr_transaction_coa_id      NUMBER;
149364 l_adr_accounting_coa_id       NUMBER;
149365 l_adr_flexfield_segment_code  VARCHAR2(30);
149366 l_adr_flex_value_set_id       NUMBER;
149367 l_adr_value_type_code         VARCHAR2(30);
149368 l_adr_value_combination_id    NUMBER;
149369 l_adr_value_segment_code      VARCHAR2(30);
149370 
149371 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
149372 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
149373 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
149374 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
149375 
149376 -- 4262811 Variables ------------------------------------------------------------------------------------------
149377 l_entered_amt_idx             NUMBER;
149378 l_accted_amt_idx              NUMBER;
149379 l_acc_rev_flag                VARCHAR2(1);
149380 l_accrual_line_num            NUMBER;
149381 l_tmp_amt                     NUMBER;
149382 l_acc_rev_natural_side_code   VARCHAR2(1);
149383 
149384 l_num_entries                 NUMBER;
149385 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
149386 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
149387 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
149388 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
149389 l_recog_line_1                NUMBER;
149390 l_recog_line_2                NUMBER;
149391 
149392 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
149393 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
149394 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
149395 
149396 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
149397 
149398 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
149399 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
149400 
149401 ---------------------------------------------------------------------------------------------------------------
149402 
149403 
149404 --
149405 -- bulk performance
149406 --
149407 l_balance_type_code           VARCHAR2(1);
149408 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
149409 l_log_module                  VARCHAR2(240);
149410 
149411 --
149412 -- Upgrade strategy
149413 --
149414 l_actual_upg_option           VARCHAR2(1);
149415 l_enc_upg_option           VARCHAR2(1);
149416 
149417 --
149418 BEGIN
149419 --
149420 IF g_log_enabled THEN
149421       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_364';
149422 END IF;
149423 --
149424 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
149425 
149426       trace
149427          (p_msg      => 'BEGIN of AcctLineType_364'
149428          ,p_level    => C_LEVEL_PROCEDURE
149429          ,p_module   => l_log_module);
149430 
149431 END IF;
149432 --
149433 l_component_type             := 'AMB_JLT';
149434 l_component_code             := 'FA_TAX_DEP_ADJUSTMENT';
149435 l_component_type_code        := 'S';
149436 l_component_appl_id          :=  140;
149437 l_amb_context_code           := 'DEFAULT';
149438 l_entity_code                := 'TRANSACTIONS';
149439 l_event_class_code           := 'DEPRECIATION_ADJUSTMENTS';
149440 l_event_type_code            := 'DEPRECIATION_ADJUSTMENTS_ALL';
149441 l_line_definition_owner_code := 'S';
149442 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE15';
149443 --
149444 l_balance_type_code          := 'A';
149445 l_segment                     := NULL;
149446 l_ccid                        := NULL;
149447 l_adr_transaction_coa_id      := NULL;
149448 l_adr_accounting_coa_id       := NULL;
149449 l_adr_flexfield_segment_code  := NULL;
149450 l_adr_flex_value_set_id       := NULL;
149451 l_adr_value_type_code         := NULL;
149452 l_adr_value_combination_id    := NULL;
149453 l_adr_value_segment_code      := NULL;
149454 
149455 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
149456 l_bflow_class_code           := '';    -- 4219869 Business Flow
149457 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
149458 l_budgetary_control_flag     := 'N';
149459 
149460 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
149461 l_bflow_applied_to_amt       := NULL; -- 5132302
149462 l_entered_amt_idx            := NULL;          -- 4262811
149463 l_accted_amt_idx             := NULL;          -- 4262811
149467 --
149464 l_acc_rev_flag               := NULL;          -- 4262811
149465 l_accrual_line_num           := NULL;          -- 4262811
149466 l_tmp_amt                    := NULL;          -- 4262811
149468  
149469 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
149470     l_balance_type_code <> 'B' THEN
149471 IF NVL(p_source_35,'
149472 ') =  'DEPRN ADJUST'
149473  THEN 
149474 
149475    --
149476    XLA_AE_LINES_PKG.SetNewLine;
149477 
149478    p_balance_type_code          := l_balance_type_code;
149479    -- set the flag so later we will know whether the gain loss line needs to be created
149480    
149481    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
149482      p_actual_flag :='A';
149483    END IF;
149484 
149485    --
149486    -- bulk performance
149487    --
149488    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
149489                                       p_header_num   => 0); -- 4262811
149490    --
149491    -- set accounting line options
149492    --
149493    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
149494            p_natural_side_code          => 'D'
149495          , p_gain_or_loss_flag          => 'N'
149496          , p_gl_transfer_mode_code      => 'S'
149497          , p_acct_entry_type_code       => 'A'
149498          , p_switch_side_flag           => 'Y'
149499          , p_merge_duplicate_code       => 'N'
149500          );
149501    --
149502    l_acc_rev_natural_side_code := 'C';  -- 4262811
149503    -- 
149504    --
149505    -- set accounting line type info
149506    --
149507    xla_ae_lines_pkg.SetAcctLineType
149508       (p_component_type             => l_component_type
149509       ,p_event_type_code            => l_event_type_code
149510       ,p_line_definition_owner_code => l_line_definition_owner_code
149511       ,p_line_definition_code       => l_line_definition_code
149512       ,p_accounting_line_code       => l_component_code
149513       ,p_accounting_line_type_code  => l_component_type_code
149514       ,p_accounting_line_appl_id    => l_component_appl_id
149515       ,p_amb_context_code           => l_amb_context_code
149516       ,p_entity_code                => l_entity_code
149517       ,p_event_class_code           => l_event_class_code);
149518    --
149519    -- set accounting class
149520    --
149521    xla_ae_lines_pkg.SetAcctClass(
149522            p_accounting_class_code  => 'EXPENSE'
149523          , p_ae_header_id           => l_ae_header_id
149524          );
149525 
149526    --
149527    -- set rounding class
149528    --
149529    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
149530                       'EXPENSE';
149531 
149532    --
149533    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
149534    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
149535    --
149536    -- bulk performance
149537    --
149538    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
149539 
149540    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
149541       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
149542 
149543    -- 4955764
149544    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
149545       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
149546 
149547    -- 4458381 Public Sector Enh
149548    
149549    --
149550    -- set accounting attributes for the line type
149551    --
149552    l_entered_amt_idx := 4;
149553    l_accted_amt_idx  := 6;
149554    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
149555    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
149556    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
149557    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
149558    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
149559    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
149560    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
149561    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
149562    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
149563    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
149564    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
149565    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
149566    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
149567 
149568    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
149569    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
149570 
149571    ---------------------------------------------------------------------------------------------------------------
149572    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
149573    ---------------------------------------------------------------------------------------------------------------
149574    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
149575 
149576    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
149577    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
149578 
149579    IF xla_accounting_cache_pkg.GetValueChar
149580          (p_source_code         => 'LEDGER_CATEGORY_CODE'
149581          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
149582    AND l_bflow_method_code = 'PRIOR_ENTRY'
149583 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
149584    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
149585          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
149589            (p_business_method_code    => l_bflow_method_code
149586        )
149587    THEN
149588          xla_ae_lines_pkg.BflowUpgEntry
149590            ,p_business_class_code     => l_bflow_class_code
149591            ,p_balance_type            => l_balance_type_code);
149592    ELSE
149593       NULL;
149594 -- No business flow processing for business flow method of NONE.
149595    END IF;
149596 
149597    --
149598    -- call analytical criteria
149599    --
149600    
149601    --
149602    -- call description
149603    --
149604    
149605 xla_ae_lines_pkg.SetLineDescription(
149606    p_ae_header_id => l_ae_header_id
149607   ,p_description  => Description_58 (
149608      p_application_id         => p_application_id
149609    , p_ae_header_id           => l_ae_header_id 
149610 , p_source_1 => p_source_1
149611    )
149612 );
149613 
149614 
149615    --
149616    -- call ADRs
149617    -- Bug 4922099
149618    --
149619    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
149620         (NVL(l_actual_upg_option, 'N') = 'O') OR
149621         (NVL(l_enc_upg_option, 'N') = 'O')
149622       )
149623    THEN
149624    NULL;
149625    --
149626    --
149627    
149628   l_ccid := AcctDerRule_173(
149629            p_application_id           => p_application_id
149630          , p_ae_header_id             => l_ae_header_id 
149631 , p_source_3 => p_source_3
149632 , p_source_30 => p_source_30
149633          , x_transaction_coa_id       => l_adr_transaction_coa_id
149634          , x_accounting_coa_id        => l_adr_accounting_coa_id
149635          , x_value_type_code          => l_adr_value_type_code
149636          , p_side                     => 'NA'
149637    );
149638 
149639    xla_ae_lines_pkg.set_ccid(
149640     p_code_combination_id          => l_ccid
149641   , p_value_type_code              => l_adr_value_type_code
149642   , p_transaction_coa_id           => l_adr_transaction_coa_id
149643   , p_accounting_coa_id            => l_adr_accounting_coa_id
149644   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
149645   , p_adr_type_code                => 'S'
149646   , p_component_type               => l_component_type
149647   , p_component_code               => l_component_code
149648   , p_component_type_code          => l_component_type_code
149649   , p_component_appl_id            => l_component_appl_id
149650   , p_amb_context_code             => l_amb_context_code
149651   , p_side                         => 'NA'
149652   );
149653 
149654 
149655    l_segment := AcctDerRule_156(
149656            p_application_id           => p_application_id
149657          , p_ae_header_id             => l_ae_header_id 
149658 , p_source_3 => p_source_3
149659 , p_source_18 => p_source_18
149660          , x_transaction_coa_id       => l_adr_transaction_coa_id
149661          , x_accounting_coa_id        => l_adr_accounting_coa_id
149662          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
149663          , x_flex_value_set_id        => l_adr_flex_value_set_id
149664          , x_value_type_code          => l_adr_value_type_code
149665          , x_value_combination_id     => l_adr_value_combination_id
149666          , x_value_segment_code       => l_adr_value_segment_code
149667          , p_side                     => 'NA'
149668          , p_override_seg_flag        => 'Y'
149669    );
149670 
149671    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
149672 
149673       xla_ae_lines_pkg.set_segment(
149674           p_to_segment_code         => 'GL_ACCOUNT'
149675         , p_segment_value           => l_segment
149676         , p_from_segment_code       => l_adr_value_segment_code
149677         , p_from_combination_id     => l_adr_value_combination_id
149678         , p_value_type_code         => l_adr_value_type_code
149679         , p_transaction_coa_id      => l_adr_transaction_coa_id
149680         , p_accounting_coa_id       => l_adr_accounting_coa_id
149681         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
149682         , p_flex_value_set_id       => l_adr_flex_value_set_id
149683         , p_adr_code                => 'FA_DEPRN_ADJUSTMENT_SEGMENT'
149684         , p_adr_type_code           => 'S'
149685         , p_component_type          => l_component_type
149686         , p_component_code          => l_component_code
149687         , p_component_type_code     => l_component_type_code
149688         , p_component_appl_id       => l_component_appl_id
149689         , p_amb_context_code        => l_amb_context_code
149690         , p_entity_code             => 'TRANSACTIONS'
149691         , p_event_class_code        => 'DEPRECIATION_ADJUSTMENTS'
149692         , p_side                    => 'NA'
149693         );
149694 
149695   END IF;
149696 
149697    l_segment := AcctDerRule_168(
149698            p_application_id           => p_application_id
149699          , p_ae_header_id             => l_ae_header_id 
149700 , p_source_3 => p_source_3
149701 , p_source_29 => p_source_29
149702          , x_transaction_coa_id       => l_adr_transaction_coa_id
149703          , x_accounting_coa_id        => l_adr_accounting_coa_id
149704          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
149705          , x_flex_value_set_id        => l_adr_flex_value_set_id
149706          , x_value_type_code          => l_adr_value_type_code
149707          , x_value_combination_id     => l_adr_value_combination_id
149708          , x_value_segment_code       => l_adr_value_segment_code
149709          , p_side                     => 'NA'
149710          , p_override_seg_flag        => 'Y'
149711    );
149712 
149713    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
149714 
149715       xla_ae_lines_pkg.set_segment(
149719         , p_from_combination_id     => l_adr_value_combination_id
149716           p_to_segment_code         => 'GL_BALANCING'
149717         , p_segment_value           => l_segment
149718         , p_from_segment_code       => l_adr_value_segment_code
149720         , p_value_type_code         => l_adr_value_type_code
149721         , p_transaction_coa_id      => l_adr_transaction_coa_id
149722         , p_accounting_coa_id       => l_adr_accounting_coa_id
149723         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
149724         , p_flex_value_set_id       => l_adr_flex_value_set_id
149725         , p_adr_code                => 'FA_EXPENSE_ACCT'
149726         , p_adr_type_code           => 'S'
149727         , p_component_type          => l_component_type
149728         , p_component_code          => l_component_code
149729         , p_component_type_code     => l_component_type_code
149730         , p_component_appl_id       => l_component_appl_id
149731         , p_amb_context_code        => l_amb_context_code
149732         , p_entity_code             => 'TRANSACTIONS'
149733         , p_event_class_code        => 'DEPRECIATION_ADJUSTMENTS'
149734         , p_side                    => 'NA'
149735         );
149736 
149737   END IF;
149738 
149739    --
149740    --
149741    END IF;
149742    --
149743    -- Bug 4922099
149744    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
149745           (NVL(l_enc_upg_option, 'N') = 'O')
149746         ) AND
149747         (l_bflow_method_code = 'PRIOR_ENTRY')
149748       )
149749    THEN
149750       IF
149751       --
149752       1 = 2
149753       --
149754       THEN
149755       xla_accounting_err_pkg.build_message
149756                                     (p_appli_s_name            => 'XLA'
149757                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
149758                                     ,p_token_1                 => 'LINE_NUMBER'
149759                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
149760                                     ,p_token_2                 => 'LINE_TYPE_NAME'
149761                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
149762                                                                              l_component_type
149763                                                                             ,l_component_code
149764                                                                             ,l_component_type_code
149765                                                                             ,l_component_appl_id
149766                                                                             ,l_amb_context_code
149767                                                                             ,l_entity_code
149768                                                                             ,l_event_class_code
149769                                                                            )
149770                                     ,p_token_3                 => 'OWNER'
149771                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
149772                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
149773                                                                           ,p_lookup_code    => l_component_type_code
149774                                                                          )
149775                                     ,p_token_4                 => 'PRODUCT_NAME'
149776                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
149777                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
149778                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
149779                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
149780                                     ,p_ae_header_id            =>  NULL
149781                                        );
149782 
149783         IF (C_LEVEL_ERROR>= g_log_level) THEN
149784                  trace
149785                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
149786                       ,p_level    => C_LEVEL_ERROR
149787                       ,p_module   => l_log_module);
149788         END IF;
149789       END IF;
149790    END IF;
149791    --
149792    --
149793    ------------------------------------------------------------------------------------------------
149794    -- 4219869 Business Flow
149795    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
149796    -- Prior Entry.  Currently, the following code is always generated.
149797    ------------------------------------------------------------------------------------------------
149798    XLA_AE_LINES_PKG.ValidateCurrentLine;
149799 
149800    ------------------------------------------------------------------------------------
149801    -- 4219869 Business Flow
149802    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
149803    ------------------------------------------------------------------------------------
149804    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
149808    -- Update journal entry status -- Need to generate this within IF <condition>
149805 
149806    ----------------------------------------------------------------------------------
149807    -- 4219869 Business Flow
149809    ----------------------------------------------------------------------------------
149810    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
149811          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
149812          ,p_balance_type_code => l_balance_type_code
149813          );
149814 
149815    -------------------------------------------------------------------------------------------
149816    -- 4262811 - Generate the Accrual Reversal lines
149817    -------------------------------------------------------------------------------------------
149818    BEGIN
149819       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
149820                               (g_array_event(p_event_id).array_value_num('header_index'));
149821       IF l_acc_rev_flag IS NULL THEN
149822          l_acc_rev_flag := 'N';
149823       END IF;
149824    EXCEPTION
149825       WHEN OTHERS THEN
149826          l_acc_rev_flag := 'N';
149827    END;
149828    --
149829    IF (l_acc_rev_flag = 'Y') THEN
149830 
149831        -- 4645092  ------------------------------------------------------------------------------
149832        -- To allow MPA report to determine if it should generate report process
149833        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
149834        ------------------------------------------------------------------------------------------
149835 
149839    -- call ADRs
149836        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
149837        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
149838    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
149840    -- Bug 4922099
149841    --
149842    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
149843         (NVL(l_actual_upg_option, 'N') = 'O') OR
149844         (NVL(l_enc_upg_option, 'N') = 'O')
149845       )
149846    THEN
149847    NULL;
149848    --
149849    --
149850    
149851   l_ccid := AcctDerRule_173(
149852            p_application_id           => p_application_id
149853          , p_ae_header_id             => l_ae_header_id 
149854 , p_source_3 => p_source_3
149855 , p_source_30 => p_source_30
149856          , x_transaction_coa_id       => l_adr_transaction_coa_id
149857          , x_accounting_coa_id        => l_adr_accounting_coa_id
149858          , x_value_type_code          => l_adr_value_type_code
149859          , p_side                     => 'NA'
149860    );
149861 
149862    xla_ae_lines_pkg.set_ccid(
149863     p_code_combination_id          => l_ccid
149864   , p_value_type_code              => l_adr_value_type_code
149865   , p_transaction_coa_id           => l_adr_transaction_coa_id
149866   , p_accounting_coa_id            => l_adr_accounting_coa_id
149867   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
149868   , p_adr_type_code                => 'S'
149869   , p_component_type               => l_component_type
149870   , p_component_code               => l_component_code
149871   , p_component_type_code          => l_component_type_code
149872   , p_component_appl_id            => l_component_appl_id
149873   , p_amb_context_code             => l_amb_context_code
149874   , p_side                         => 'NA'
149875   );
149876 
149877 
149878    l_segment := AcctDerRule_156(
149879            p_application_id           => p_application_id
149880          , p_ae_header_id             => l_ae_header_id 
149881 , p_source_3 => p_source_3
149882 , p_source_18 => p_source_18
149883          , x_transaction_coa_id       => l_adr_transaction_coa_id
149884          , x_accounting_coa_id        => l_adr_accounting_coa_id
149885          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
149886          , x_flex_value_set_id        => l_adr_flex_value_set_id
149887          , x_value_type_code          => l_adr_value_type_code
149888          , x_value_combination_id     => l_adr_value_combination_id
149889          , x_value_segment_code       => l_adr_value_segment_code
149890          , p_side                     => 'NA'
149891          , p_override_seg_flag        => 'Y'
149892    );
149893 
149894    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
149895 
149896       xla_ae_lines_pkg.set_segment(
149897           p_to_segment_code         => 'GL_ACCOUNT'
149898         , p_segment_value           => l_segment
149899         , p_from_segment_code       => l_adr_value_segment_code
149900         , p_from_combination_id     => l_adr_value_combination_id
149901         , p_value_type_code         => l_adr_value_type_code
149902         , p_transaction_coa_id      => l_adr_transaction_coa_id
149903         , p_accounting_coa_id       => l_adr_accounting_coa_id
149904         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
149905         , p_flex_value_set_id       => l_adr_flex_value_set_id
149909         , p_component_code          => l_component_code
149906         , p_adr_code                => 'FA_DEPRN_ADJUSTMENT_SEGMENT'
149907         , p_adr_type_code           => 'S'
149908         , p_component_type          => l_component_type
149910         , p_component_type_code     => l_component_type_code
149911         , p_component_appl_id       => l_component_appl_id
149912         , p_amb_context_code        => l_amb_context_code
149913         , p_entity_code             => 'TRANSACTIONS'
149914         , p_event_class_code        => 'DEPRECIATION_ADJUSTMENTS'
149915         , p_side                    => 'NA'
149916         );
149917 
149918   END IF;
149919 
149920    l_segment := AcctDerRule_168(
149921            p_application_id           => p_application_id
149922          , p_ae_header_id             => l_ae_header_id 
149923 , p_source_3 => p_source_3
149924 , p_source_29 => p_source_29
149925          , x_transaction_coa_id       => l_adr_transaction_coa_id
149926          , x_accounting_coa_id        => l_adr_accounting_coa_id
149927          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
149928          , x_flex_value_set_id        => l_adr_flex_value_set_id
149929          , x_value_type_code          => l_adr_value_type_code
149930          , x_value_combination_id     => l_adr_value_combination_id
149931          , x_value_segment_code       => l_adr_value_segment_code
149932          , p_side                     => 'NA'
149933          , p_override_seg_flag        => 'Y'
149934    );
149935 
149936    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
149937 
149938       xla_ae_lines_pkg.set_segment(
149939           p_to_segment_code         => 'GL_BALANCING'
149940         , p_segment_value           => l_segment
149941         , p_from_segment_code       => l_adr_value_segment_code
149942         , p_from_combination_id     => l_adr_value_combination_id
149943         , p_value_type_code         => l_adr_value_type_code
149944         , p_transaction_coa_id      => l_adr_transaction_coa_id
149945         , p_accounting_coa_id       => l_adr_accounting_coa_id
149946         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
149947         , p_flex_value_set_id       => l_adr_flex_value_set_id
149948         , p_adr_code                => 'FA_EXPENSE_ACCT'
149949         , p_adr_type_code           => 'S'
149950         , p_component_type          => l_component_type
149951         , p_component_code          => l_component_code
149952         , p_component_type_code     => l_component_type_code
149953         , p_component_appl_id       => l_component_appl_id
149954         , p_amb_context_code        => l_amb_context_code
149955         , p_entity_code             => 'TRANSACTIONS'
149956         , p_event_class_code        => 'DEPRECIATION_ADJUSTMENTS'
149957         , p_side                    => 'NA'
149958         );
149959 
149960   END IF;
149961 
149962    --
149963    --
149964    END IF;
149965 
149966        --
149967        -- Update the line information that should be overwritten
149968        --
149969        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
149970                                          p_header_num   => 1);
149971        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
149972 
149973        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
149974 
149975        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
149976           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
149977        END IF;
149978 
149979       --
149980       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
149981       --
149982       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
149983           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
149984       ELSE
149985           ---------------------------------------------------------------------------------------------------
149986           -- 4262811a Switch Sign
149987           ---------------------------------------------------------------------------------------------------
149988           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
149989           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
149990                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
149991           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
149992                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
149993           -- 5132302
149994           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
149995                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
149996 
149997       END IF;
149998 
149999       -- 4955764
150000       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
150001       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
150002 
150003 
150004       XLA_AE_LINES_PKG.ValidateCurrentLine;
150005       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
150006 
150007       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
150008                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
150009                ,p_balance_type_code => l_balance_type_code);
150010 
150011    END IF;
150012 
150013    -----------------------------------------------------------------------------------------
150014    -- 4262811 Multiperiod Accounting
150015    -----------------------------------------------------------------------------------------
150016      -- No MPA option is assigned.
150017 
150018 
150019 END IF;
150020 END IF;
150024 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
150021 --
150022 
150023 --
150025    trace
150026       (p_msg      => 'END of AcctLineType_364'
150027       ,p_level    => C_LEVEL_PROCEDURE
150028       ,p_module   => l_log_module);
150029 END IF;
150030 --
150031 EXCEPTION
150032   WHEN xla_exceptions_pkg.application_exception THEN
150033       RAISE;
150034   WHEN OTHERS THEN
150035        xla_exceptions_pkg.raise_message
150036            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_364');
150037 END AcctLineType_364;
150038 --
150039 
150040 ---------------------------------------
150041 --
150042 -- PRIVATE FUNCTION
150043 --         AcctLineType_365
150044 --
150045 ---------------------------------------
150046 PROCEDURE AcctLineType_365 (
150047   p_application_id        IN NUMBER
150048  ,p_event_id              IN NUMBER
150049  ,p_calculate_acctd_flag  IN VARCHAR2
150050  ,p_calculate_g_l_flag    IN VARCHAR2
150051  ,p_actual_flag           IN OUT VARCHAR2
150052  ,p_balance_type_code     OUT VARCHAR2
150053  ,p_gain_or_loss_ref      OUT VARCHAR2
150054  
150055 --Period Close Date
150056  , p_source_1            IN DATE
150057 --Generated Code Combination Identifier
150058  , p_source_3            IN NUMBER
150059 --Depreciation Reserve Account
150060  , p_source_10            IN VARCHAR2
150061 --Generated Offset Code Combination Identifier
150062  , p_source_17            IN NUMBER
150063 --Expense Account Code Combination Identifier
150064  , p_source_29            IN NUMBER
150065 --Default Code Combination Identifier
150066  , p_source_30            IN NUMBER
150067 --Adjustment Type
150068  , p_source_35            IN VARCHAR2
150069 --Transaction Header Identifier
150070  , p_source_36            IN NUMBER
150071 --Adjustment Line Identifier
150072  , p_source_37            IN NUMBER
150073 --Distribution Type Code
150074  , p_source_38            IN VARCHAR2
150075 --Entered Amount
150076  , p_source_39            IN NUMBER
150077 --Currency Code
150078  , p_source_40            IN VARCHAR2
150079 )
150080 IS
150081 
150082 l_component_type              VARCHAR2(80);
150083 l_component_code              VARCHAR2(30);
150084 l_component_type_code         VARCHAR2(1);
150085 l_component_appl_id           INTEGER;
150086 l_amb_context_code            VARCHAR2(30);
150087 l_entity_code                 VARCHAR2(30);
150088 l_event_class_code            VARCHAR2(30);
150089 l_ae_header_id                NUMBER;
150090 l_event_type_code             VARCHAR2(30);
150091 l_line_definition_code        VARCHAR2(30);
150092 l_line_definition_owner_code  VARCHAR2(1);
150093 --
150094 -- adr variables
150095 l_segment                     VARCHAR2(30);
150096 l_ccid                        NUMBER;
150097 l_adr_transaction_coa_id      NUMBER;
150098 l_adr_accounting_coa_id       NUMBER;
150099 l_adr_flexfield_segment_code  VARCHAR2(30);
150100 l_adr_flex_value_set_id       NUMBER;
150101 l_adr_value_type_code         VARCHAR2(30);
150102 l_adr_value_combination_id    NUMBER;
150103 l_adr_value_segment_code      VARCHAR2(30);
150104 
150105 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
150106 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
150107 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
150108 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
150109 
150110 -- 4262811 Variables ------------------------------------------------------------------------------------------
150111 l_entered_amt_idx             NUMBER;
150112 l_accted_amt_idx              NUMBER;
150113 l_acc_rev_flag                VARCHAR2(1);
150114 l_accrual_line_num            NUMBER;
150115 l_tmp_amt                     NUMBER;
150116 l_acc_rev_natural_side_code   VARCHAR2(1);
150117 
150118 l_num_entries                 NUMBER;
150119 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
150120 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
150121 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
150122 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
150123 l_recog_line_1                NUMBER;
150124 l_recog_line_2                NUMBER;
150125 
150126 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
150127 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
150128 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
150129 
150130 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
150131 
150132 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
150133 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
150134 
150135 ---------------------------------------------------------------------------------------------------------------
150136 
150137 
150138 --
150139 -- bulk performance
150140 --
150141 l_balance_type_code           VARCHAR2(1);
150142 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
150143 l_log_module                  VARCHAR2(240);
150144 
150145 --
150146 -- Upgrade strategy
150147 --
150148 l_actual_upg_option           VARCHAR2(1);
150149 l_enc_upg_option           VARCHAR2(1);
150150 
150151 --
150152 BEGIN
150153 --
150154 IF g_log_enabled THEN
150155       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_365';
150156 END IF;
150157 --
150158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
150159 
150160       trace
150161          (p_msg      => 'BEGIN of AcctLineType_365'
150162          ,p_level    => C_LEVEL_PROCEDURE
150163          ,p_module   => l_log_module);
150164 
150165 END IF;
150166 --
150167 l_component_type             := 'AMB_JLT';
150168 l_component_code             := 'FA_TAX_DEP_RESERVE';
150169 l_component_type_code        := 'S';
150173 l_event_class_code           := 'DEPRECIATION_ADJUSTMENTS';
150170 l_component_appl_id          :=  140;
150171 l_amb_context_code           := 'DEFAULT';
150172 l_entity_code                := 'TRANSACTIONS';
150174 l_event_type_code            := 'DEPRECIATION_ADJUSTMENTS_ALL';
150175 l_line_definition_owner_code := 'S';
150176 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_DEPRE15';
150177 --
150178 l_balance_type_code          := 'A';
150179 l_segment                     := NULL;
150180 l_ccid                        := NULL;
150181 l_adr_transaction_coa_id      := NULL;
150182 l_adr_accounting_coa_id       := NULL;
150183 l_adr_flexfield_segment_code  := NULL;
150184 l_adr_flex_value_set_id       := NULL;
150185 l_adr_value_type_code         := NULL;
150186 l_adr_value_combination_id    := NULL;
150187 l_adr_value_segment_code      := NULL;
150188 
150189 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
150190 l_bflow_class_code           := '';    -- 4219869 Business Flow
150191 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
150192 l_budgetary_control_flag     := 'N';
150193 
150194 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
150195 l_bflow_applied_to_amt       := NULL; -- 5132302
150196 l_entered_amt_idx            := NULL;          -- 4262811
150197 l_accted_amt_idx             := NULL;          -- 4262811
150198 l_acc_rev_flag               := NULL;          -- 4262811
150199 l_accrual_line_num           := NULL;          -- 4262811
150200 l_tmp_amt                    := NULL;          -- 4262811
150201 --
150202  
150203 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
150204     l_balance_type_code <> 'B' THEN
150205 IF NVL(p_source_35,'
150206 ') =  'DEPRN ADJUST' OR 
150207 NVL(p_source_35,'
150208 ') =  'EXPENSE'
150209  THEN 
150210 
150211    --
150212    XLA_AE_LINES_PKG.SetNewLine;
150213 
150214    p_balance_type_code          := l_balance_type_code;
150215    -- set the flag so later we will know whether the gain loss line needs to be created
150216    
150217    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
150218      p_actual_flag :='A';
150219    END IF;
150220 
150221    --
150222    -- bulk performance
150223    --
150224    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
150225                                       p_header_num   => 0); -- 4262811
150226    --
150227    -- set accounting line options
150228    --
150229    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
150230            p_natural_side_code          => 'C'
150231          , p_gain_or_loss_flag          => 'N'
150232          , p_gl_transfer_mode_code      => 'S'
150233          , p_acct_entry_type_code       => 'A'
150234          , p_switch_side_flag           => 'Y'
150235          , p_merge_duplicate_code       => 'N'
150236          );
150237    --
150238    l_acc_rev_natural_side_code := 'D';  -- 4262811
150239    -- 
150240    --
150241    -- set accounting line type info
150242    --
150243    xla_ae_lines_pkg.SetAcctLineType
150244       (p_component_type             => l_component_type
150245       ,p_event_type_code            => l_event_type_code
150246       ,p_line_definition_owner_code => l_line_definition_owner_code
150247       ,p_line_definition_code       => l_line_definition_code
150248       ,p_accounting_line_code       => l_component_code
150249       ,p_accounting_line_type_code  => l_component_type_code
150250       ,p_accounting_line_appl_id    => l_component_appl_id
150251       ,p_amb_context_code           => l_amb_context_code
150252       ,p_entity_code                => l_entity_code
150253       ,p_event_class_code           => l_event_class_code);
150254    --
150255    -- set accounting class
150256    --
150257    xla_ae_lines_pkg.SetAcctClass(
150258            p_accounting_class_code  => 'ASSET'
150259          , p_ae_header_id           => l_ae_header_id
150260          );
150261 
150262    --
150263    -- set rounding class
150264    --
150265    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
150266                       'ASSET';
150267 
150268    --
150269    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
150270    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
150271    --
150272    -- bulk performance
150273    --
150274    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
150275 
150276    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
150277       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
150278 
150279    -- 4955764
150280    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
150281       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
150282 
150283    -- 4458381 Public Sector Enh
150284    
150285    --
150286    -- set accounting attributes for the line type
150287    --
150288    l_entered_amt_idx := 4;
150289    l_accted_amt_idx  := 6;
150290    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
150291    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
150292    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
150293    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
150294    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
150295    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
150296    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
150297    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
150298    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
150299    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
150300    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
150304    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
150301    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
150302    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
150303 
150305    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
150306 
150307    ---------------------------------------------------------------------------------------------------------------
150308    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
150309    ---------------------------------------------------------------------------------------------------------------
150310    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
150311 
150312    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
150313    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
150314 
150315    IF xla_accounting_cache_pkg.GetValueChar
150316          (p_source_code         => 'LEDGER_CATEGORY_CODE'
150317          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
150318    AND l_bflow_method_code = 'PRIOR_ENTRY'
150319 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
150320    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
150321          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
150322        )
150323    THEN
150324          xla_ae_lines_pkg.BflowUpgEntry
150325            (p_business_method_code    => l_bflow_method_code
150326            ,p_business_class_code     => l_bflow_class_code
150327            ,p_balance_type            => l_balance_type_code);
150328    ELSE
150329       NULL;
150330 -- No business flow processing for business flow method of NONE.
150331    END IF;
150332 
150333    --
150334    -- call analytical criteria
150335    --
150336    
150337    --
150338    -- call description
150339    --
150340    
150341 xla_ae_lines_pkg.SetLineDescription(
150342    p_ae_header_id => l_ae_header_id
150343   ,p_description  => Description_118 (
150344      p_application_id         => p_application_id
150345    , p_ae_header_id           => l_ae_header_id 
150346 , p_source_1 => p_source_1
150347    )
150348 );
150349 
150350 
150351    --
150352    -- call ADRs
150353    -- Bug 4922099
150354    --
150355    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
150356         (NVL(l_actual_upg_option, 'N') = 'O') OR
150357         (NVL(l_enc_upg_option, 'N') = 'O')
150358       )
150359    THEN
150360    NULL;
150361    --
150362    --
150363    
150364   l_ccid := AcctDerRule_174(
150365            p_application_id           => p_application_id
150366          , p_ae_header_id             => l_ae_header_id 
150367 , p_source_3 => p_source_3
150368 , p_source_17 => p_source_17
150369 , p_source_30 => p_source_30
150370          , x_transaction_coa_id       => l_adr_transaction_coa_id
150371          , x_accounting_coa_id        => l_adr_accounting_coa_id
150372          , x_value_type_code          => l_adr_value_type_code
150373          , p_side                     => 'NA'
150374    );
150375 
150376    xla_ae_lines_pkg.set_ccid(
150377     p_code_combination_id          => l_ccid
150378   , p_value_type_code              => l_adr_value_type_code
150379   , p_transaction_coa_id           => l_adr_transaction_coa_id
150380   , p_accounting_coa_id            => l_adr_accounting_coa_id
150381   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
150382   , p_adr_type_code                => 'S'
150383   , p_component_type               => l_component_type
150384   , p_component_code               => l_component_code
150385   , p_component_type_code          => l_component_type_code
150386   , p_component_appl_id            => l_component_appl_id
150387   , p_amb_context_code             => l_amb_context_code
150388   , p_side                         => 'NA'
150389   );
150390 
150391 
150392    l_segment := AcctDerRule_149(
150393            p_application_id           => p_application_id
150394          , p_ae_header_id             => l_ae_header_id 
150395 , p_source_3 => p_source_3
150396 , p_source_10 => p_source_10
150397          , x_transaction_coa_id       => l_adr_transaction_coa_id
150398          , x_accounting_coa_id        => l_adr_accounting_coa_id
150399          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
150400          , x_flex_value_set_id        => l_adr_flex_value_set_id
150401          , x_value_type_code          => l_adr_value_type_code
150402          , x_value_combination_id     => l_adr_value_combination_id
150403          , x_value_segment_code       => l_adr_value_segment_code
150404          , p_side                     => 'NA'
150405          , p_override_seg_flag        => 'Y'
150406    );
150407 
150408    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
150409 
150410       xla_ae_lines_pkg.set_segment(
150411           p_to_segment_code         => 'GL_ACCOUNT'
150412         , p_segment_value           => l_segment
150413         , p_from_segment_code       => l_adr_value_segment_code
150414         , p_from_combination_id     => l_adr_value_combination_id
150415         , p_value_type_code         => l_adr_value_type_code
150416         , p_transaction_coa_id      => l_adr_transaction_coa_id
150417         , p_accounting_coa_id       => l_adr_accounting_coa_id
150418         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
150419         , p_flex_value_set_id       => l_adr_flex_value_set_id
150420         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
150421         , p_adr_type_code           => 'S'
150422         , p_component_type          => l_component_type
150423         , p_component_code          => l_component_code
150424         , p_component_type_code     => l_component_type_code
150425         , p_component_appl_id       => l_component_appl_id
150429         , p_side                    => 'NA'
150426         , p_amb_context_code        => l_amb_context_code
150427         , p_entity_code             => 'TRANSACTIONS'
150428         , p_event_class_code        => 'DEPRECIATION_ADJUSTMENTS'
150430         );
150431 
150432   END IF;
150433 
150434    l_segment := AcctDerRule_168(
150435            p_application_id           => p_application_id
150436          , p_ae_header_id             => l_ae_header_id 
150437 , p_source_3 => p_source_3
150438 , p_source_29 => p_source_29
150439          , x_transaction_coa_id       => l_adr_transaction_coa_id
150440          , x_accounting_coa_id        => l_adr_accounting_coa_id
150441          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
150442          , x_flex_value_set_id        => l_adr_flex_value_set_id
150443          , x_value_type_code          => l_adr_value_type_code
150444          , x_value_combination_id     => l_adr_value_combination_id
150445          , x_value_segment_code       => l_adr_value_segment_code
150446          , p_side                     => 'NA'
150447          , p_override_seg_flag        => 'Y'
150448    );
150449 
150450    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
150451 
150452       xla_ae_lines_pkg.set_segment(
150453           p_to_segment_code         => 'GL_BALANCING'
150454         , p_segment_value           => l_segment
150455         , p_from_segment_code       => l_adr_value_segment_code
150456         , p_from_combination_id     => l_adr_value_combination_id
150457         , p_value_type_code         => l_adr_value_type_code
150458         , p_transaction_coa_id      => l_adr_transaction_coa_id
150459         , p_accounting_coa_id       => l_adr_accounting_coa_id
150460         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
150461         , p_flex_value_set_id       => l_adr_flex_value_set_id
150462         , p_adr_code                => 'FA_EXPENSE_ACCT'
150463         , p_adr_type_code           => 'S'
150464         , p_component_type          => l_component_type
150465         , p_component_code          => l_component_code
150466         , p_component_type_code     => l_component_type_code
150467         , p_component_appl_id       => l_component_appl_id
150468         , p_amb_context_code        => l_amb_context_code
150469         , p_entity_code             => 'TRANSACTIONS'
150470         , p_event_class_code        => 'DEPRECIATION_ADJUSTMENTS'
150471         , p_side                    => 'NA'
150472         );
150473 
150474   END IF;
150475 
150476    --
150477    --
150478    END IF;
150479    --
150480    -- Bug 4922099
150481    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
150482           (NVL(l_enc_upg_option, 'N') = 'O')
150483         ) AND
150484         (l_bflow_method_code = 'PRIOR_ENTRY')
150485       )
150486    THEN
150487       IF
150488       --
150489       1 = 2
150490       --
150491       THEN
150492       xla_accounting_err_pkg.build_message
150493                                     (p_appli_s_name            => 'XLA'
150494                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
150495                                     ,p_token_1                 => 'LINE_NUMBER'
150496                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
150497                                     ,p_token_2                 => 'LINE_TYPE_NAME'
150498                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
150499                                                                              l_component_type
150500                                                                             ,l_component_code
150501                                                                             ,l_component_type_code
150502                                                                             ,l_component_appl_id
150503                                                                             ,l_amb_context_code
150504                                                                             ,l_entity_code
150505                                                                             ,l_event_class_code
150506                                                                            )
150507                                     ,p_token_3                 => 'OWNER'
150508                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
150509                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
150510                                                                           ,p_lookup_code    => l_component_type_code
150511                                                                          )
150512                                     ,p_token_4                 => 'PRODUCT_NAME'
150513                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
150514                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
150515                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
150516                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
150517                                     ,p_ae_header_id            =>  NULL
150518                                        );
150519 
150520         IF (C_LEVEL_ERROR>= g_log_level) THEN
150521                  trace
150522                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
150523                       ,p_level    => C_LEVEL_ERROR
150524                       ,p_module   => l_log_module);
150525         END IF;
150526       END IF;
150527    END IF;
150528    --
150529    --
150530    ------------------------------------------------------------------------------------------------
150531    -- 4219869 Business Flow
150532    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
150536 
150533    -- Prior Entry.  Currently, the following code is always generated.
150534    ------------------------------------------------------------------------------------------------
150535    XLA_AE_LINES_PKG.ValidateCurrentLine;
150537    ------------------------------------------------------------------------------------
150538    -- 4219869 Business Flow
150539    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
150540    ------------------------------------------------------------------------------------
150541    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
150542 
150543    ----------------------------------------------------------------------------------
150544    -- 4219869 Business Flow
150545    -- Update journal entry status -- Need to generate this within IF <condition>
150546    ----------------------------------------------------------------------------------
150547    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
150548          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
150549          ,p_balance_type_code => l_balance_type_code
150550          );
150551 
150552    -------------------------------------------------------------------------------------------
150553    -- 4262811 - Generate the Accrual Reversal lines
150554    -------------------------------------------------------------------------------------------
150555    BEGIN
150556       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
150557                               (g_array_event(p_event_id).array_value_num('header_index'));
150558       IF l_acc_rev_flag IS NULL THEN
150559          l_acc_rev_flag := 'N';
150560       END IF;
150561    EXCEPTION
150562       WHEN OTHERS THEN
150563          l_acc_rev_flag := 'N';
150564    END;
150565    --
150566    IF (l_acc_rev_flag = 'Y') THEN
150567 
150568        -- 4645092  ------------------------------------------------------------------------------
150569        -- To allow MPA report to determine if it should generate report process
150570        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
150571        ------------------------------------------------------------------------------------------
150572 
150573        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
150574        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
150575    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
150576    -- call ADRs
150577    -- Bug 4922099
150578    --
150579    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
150580         (NVL(l_actual_upg_option, 'N') = 'O') OR
150581         (NVL(l_enc_upg_option, 'N') = 'O')
150582       )
150583    THEN
150584    NULL;
150585    --
150586    --
150587    
150588   l_ccid := AcctDerRule_174(
150589            p_application_id           => p_application_id
150590          , p_ae_header_id             => l_ae_header_id 
150591 , p_source_3 => p_source_3
150592 , p_source_17 => p_source_17
150593 , p_source_30 => p_source_30
150594          , x_transaction_coa_id       => l_adr_transaction_coa_id
150595          , x_accounting_coa_id        => l_adr_accounting_coa_id
150596          , x_value_type_code          => l_adr_value_type_code
150597          , p_side                     => 'NA'
150598    );
150599 
150600    xla_ae_lines_pkg.set_ccid(
150601     p_code_combination_id          => l_ccid
150602   , p_value_type_code              => l_adr_value_type_code
150603   , p_transaction_coa_id           => l_adr_transaction_coa_id
150604   , p_accounting_coa_id            => l_adr_accounting_coa_id
150605   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
150606   , p_adr_type_code                => 'S'
150607   , p_component_type               => l_component_type
150608   , p_component_code               => l_component_code
150609   , p_component_type_code          => l_component_type_code
150610   , p_component_appl_id            => l_component_appl_id
150611   , p_amb_context_code             => l_amb_context_code
150612   , p_side                         => 'NA'
150613   );
150614 
150615 
150616    l_segment := AcctDerRule_149(
150617            p_application_id           => p_application_id
150618          , p_ae_header_id             => l_ae_header_id 
150619 , p_source_3 => p_source_3
150620 , p_source_10 => p_source_10
150621          , x_transaction_coa_id       => l_adr_transaction_coa_id
150622          , x_accounting_coa_id        => l_adr_accounting_coa_id
150623          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
150624          , x_flex_value_set_id        => l_adr_flex_value_set_id
150625          , x_value_type_code          => l_adr_value_type_code
150626          , x_value_combination_id     => l_adr_value_combination_id
150627          , x_value_segment_code       => l_adr_value_segment_code
150628          , p_side                     => 'NA'
150629          , p_override_seg_flag        => 'Y'
150630    );
150631 
150632    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
150633 
150634       xla_ae_lines_pkg.set_segment(
150635           p_to_segment_code         => 'GL_ACCOUNT'
150636         , p_segment_value           => l_segment
150637         , p_from_segment_code       => l_adr_value_segment_code
150638         , p_from_combination_id     => l_adr_value_combination_id
150639         , p_value_type_code         => l_adr_value_type_code
150640         , p_transaction_coa_id      => l_adr_transaction_coa_id
150641         , p_accounting_coa_id       => l_adr_accounting_coa_id
150642         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
150643         , p_flex_value_set_id       => l_adr_flex_value_set_id
150644         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
150645         , p_adr_type_code           => 'S'
150646         , p_component_type          => l_component_type
150647         , p_component_code          => l_component_code
150648         , p_component_type_code     => l_component_type_code
150649         , p_component_appl_id       => l_component_appl_id
150653         , p_side                    => 'NA'
150650         , p_amb_context_code        => l_amb_context_code
150651         , p_entity_code             => 'TRANSACTIONS'
150652         , p_event_class_code        => 'DEPRECIATION_ADJUSTMENTS'
150654         );
150655 
150656   END IF;
150657 
150658    l_segment := AcctDerRule_168(
150659            p_application_id           => p_application_id
150660          , p_ae_header_id             => l_ae_header_id 
150661 , p_source_3 => p_source_3
150662 , p_source_29 => p_source_29
150663          , x_transaction_coa_id       => l_adr_transaction_coa_id
150664          , x_accounting_coa_id        => l_adr_accounting_coa_id
150665          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
150666          , x_flex_value_set_id        => l_adr_flex_value_set_id
150667          , x_value_type_code          => l_adr_value_type_code
150668          , x_value_combination_id     => l_adr_value_combination_id
150669          , x_value_segment_code       => l_adr_value_segment_code
150670          , p_side                     => 'NA'
150671          , p_override_seg_flag        => 'Y'
150672    );
150673 
150674    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
150675 
150676       xla_ae_lines_pkg.set_segment(
150677           p_to_segment_code         => 'GL_BALANCING'
150678         , p_segment_value           => l_segment
150679         , p_from_segment_code       => l_adr_value_segment_code
150680         , p_from_combination_id     => l_adr_value_combination_id
150681         , p_value_type_code         => l_adr_value_type_code
150682         , p_transaction_coa_id      => l_adr_transaction_coa_id
150683         , p_accounting_coa_id       => l_adr_accounting_coa_id
150684         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
150685         , p_flex_value_set_id       => l_adr_flex_value_set_id
150686         , p_adr_code                => 'FA_EXPENSE_ACCT'
150687         , p_adr_type_code           => 'S'
150688         , p_component_type          => l_component_type
150689         , p_component_code          => l_component_code
150690         , p_component_type_code     => l_component_type_code
150691         , p_component_appl_id       => l_component_appl_id
150692         , p_amb_context_code        => l_amb_context_code
150693         , p_entity_code             => 'TRANSACTIONS'
150694         , p_event_class_code        => 'DEPRECIATION_ADJUSTMENTS'
150695         , p_side                    => 'NA'
150696         );
150697 
150698   END IF;
150699 
150700    --
150701    --
150702    END IF;
150703 
150704        --
150705        -- Update the line information that should be overwritten
150706        --
150707        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
150708                                          p_header_num   => 1);
150709        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
150710 
150711        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
150712 
150713        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
150714           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
150715        END IF;
150716 
150717       --
150718       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
150719       --
150720       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
150721           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
150722       ELSE
150723           ---------------------------------------------------------------------------------------------------
150724           -- 4262811a Switch Sign
150725           ---------------------------------------------------------------------------------------------------
150726           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
150727           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
150728                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
150729           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
150730                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
150731           -- 5132302
150732           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
150733                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
150734 
150735       END IF;
150736 
150737       -- 4955764
150738       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
150739       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
150740 
150741 
150742       XLA_AE_LINES_PKG.ValidateCurrentLine;
150743       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
150744 
150745       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
150746                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
150747                ,p_balance_type_code => l_balance_type_code);
150748 
150749    END IF;
150750 
150751    -----------------------------------------------------------------------------------------
150752    -- 4262811 Multiperiod Accounting
150753    -----------------------------------------------------------------------------------------
150754      -- No MPA option is assigned.
150755 
150756 
150757 END IF;
150758 END IF;
150759 --
150760 
150761 --
150762 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
150763    trace
150764       (p_msg      => 'END of AcctLineType_365'
150765       ,p_level    => C_LEVEL_PROCEDURE
150766       ,p_module   => l_log_module);
150767 END IF;
150768 --
150769 EXCEPTION
150770   WHEN xla_exceptions_pkg.application_exception THEN
150774            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_365');
150771       RAISE;
150772   WHEN OTHERS THEN
150773        xla_exceptions_pkg.raise_message
150775 END AcctLineType_365;
150776 --
150777 
150778 ---------------------------------------
150779 --
150780 -- PRIVATE FUNCTION
150781 --         AcctLineType_366
150782 --
150783 ---------------------------------------
150784 PROCEDURE AcctLineType_366 (
150785   p_application_id        IN NUMBER
150786  ,p_event_id              IN NUMBER
150787  ,p_calculate_acctd_flag  IN VARCHAR2
150788  ,p_calculate_g_l_flag    IN VARCHAR2
150789  ,p_actual_flag           IN OUT VARCHAR2
150790  ,p_balance_type_code     OUT VARCHAR2
150791  ,p_gain_or_loss_ref      OUT VARCHAR2
150792  
150793 --Period Close Date
150794  , p_source_1            IN DATE
150795 --Generated Code Combination Identifier
150796  , p_source_3            IN NUMBER
150797 --Net Book Value Retired Gain Account
150798  , p_source_21            IN VARCHAR2
150799 --Expense Account Code Combination Identifier
150800  , p_source_29            IN NUMBER
150801 --Default Code Combination Identifier
150802  , p_source_30            IN NUMBER
150803 --Adjustment Type
150804  , p_source_35            IN VARCHAR2
150805 --Transaction Header Identifier
150806  , p_source_36            IN NUMBER
150807 --Adjustment Line Identifier
150808  , p_source_37            IN NUMBER
150809 --Distribution Type Code
150810  , p_source_38            IN VARCHAR2
150811 --Entered Amount
150812  , p_source_39            IN NUMBER
150813 --Currency Code
150814  , p_source_40            IN VARCHAR2
150815 )
150816 IS
150817 
150818 l_component_type              VARCHAR2(80);
150819 l_component_code              VARCHAR2(30);
150820 l_component_type_code         VARCHAR2(1);
150821 l_component_appl_id           INTEGER;
150822 l_amb_context_code            VARCHAR2(30);
150823 l_entity_code                 VARCHAR2(30);
150824 l_event_class_code            VARCHAR2(30);
150825 l_ae_header_id                NUMBER;
150826 l_event_type_code             VARCHAR2(30);
150827 l_line_definition_code        VARCHAR2(30);
150828 l_line_definition_owner_code  VARCHAR2(1);
150829 --
150830 -- adr variables
150831 l_segment                     VARCHAR2(30);
150832 l_ccid                        NUMBER;
150833 l_adr_transaction_coa_id      NUMBER;
150834 l_adr_accounting_coa_id       NUMBER;
150835 l_adr_flexfield_segment_code  VARCHAR2(30);
150836 l_adr_flex_value_set_id       NUMBER;
150837 l_adr_value_type_code         VARCHAR2(30);
150838 l_adr_value_combination_id    NUMBER;
150839 l_adr_value_segment_code      VARCHAR2(30);
150840 
150841 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
150842 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
150843 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
150844 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
150845 
150846 -- 4262811 Variables ------------------------------------------------------------------------------------------
150847 l_entered_amt_idx             NUMBER;
150848 l_accted_amt_idx              NUMBER;
150849 l_acc_rev_flag                VARCHAR2(1);
150850 l_accrual_line_num            NUMBER;
150851 l_tmp_amt                     NUMBER;
150852 l_acc_rev_natural_side_code   VARCHAR2(1);
150853 
150854 l_num_entries                 NUMBER;
150855 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
150856 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
150857 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
150858 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
150859 l_recog_line_1                NUMBER;
150860 l_recog_line_2                NUMBER;
150861 
150862 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
150863 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
150864 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
150865 
150866 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
150867 
150868 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
150869 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
150870 
150871 ---------------------------------------------------------------------------------------------------------------
150872 
150873 
150874 --
150875 -- bulk performance
150876 --
150877 l_balance_type_code           VARCHAR2(1);
150878 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
150879 l_log_module                  VARCHAR2(240);
150880 
150881 --
150882 -- Upgrade strategy
150883 --
150884 l_actual_upg_option           VARCHAR2(1);
150885 l_enc_upg_option           VARCHAR2(1);
150886 
150887 --
150888 BEGIN
150889 --
150890 IF g_log_enabled THEN
150891       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_366';
150892 END IF;
150893 --
150894 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
150895 
150896       trace
150897          (p_msg      => 'BEGIN of AcctLineType_366'
150898          ,p_level    => C_LEVEL_PROCEDURE
150899          ,p_module   => l_log_module);
150900 
150901 END IF;
150902 --
150903 l_component_type             := 'AMB_JLT';
150904 l_component_code             := 'FA_TGL_NBV_RETIRED_GAIN';
150905 l_component_type_code        := 'S';
150906 l_component_appl_id          :=  140;
150907 l_amb_context_code           := 'DEFAULT';
150908 l_entity_code                := 'TRANSACTIONS';
150909 l_event_class_code           := 'TERMINAL_GAIN_LOSS';
150910 l_event_type_code            := 'TERMINAL_GAIN_LOSS_ALL';
150911 l_line_definition_owner_code := 'S';
150912 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TERMI24';
150913 --
150914 l_balance_type_code          := 'A';
150918 l_adr_accounting_coa_id       := NULL;
150915 l_segment                     := NULL;
150916 l_ccid                        := NULL;
150917 l_adr_transaction_coa_id      := NULL;
150919 l_adr_flexfield_segment_code  := NULL;
150920 l_adr_flex_value_set_id       := NULL;
150921 l_adr_value_type_code         := NULL;
150922 l_adr_value_combination_id    := NULL;
150923 l_adr_value_segment_code      := NULL;
150924 
150925 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
150926 l_bflow_class_code           := '';    -- 4219869 Business Flow
150927 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
150928 l_budgetary_control_flag     := 'N';
150929 
150930 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
150931 l_bflow_applied_to_amt       := NULL; -- 5132302
150932 l_entered_amt_idx            := NULL;          -- 4262811
150933 l_accted_amt_idx             := NULL;          -- 4262811
150934 l_acc_rev_flag               := NULL;          -- 4262811
150935 l_accrual_line_num           := NULL;          -- 4262811
150936 l_tmp_amt                    := NULL;          -- 4262811
150937 --
150938  
150939 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
150940     l_balance_type_code <> 'B' THEN
150941 IF NVL(p_source_35,'
150942 ') =  'NBV RETIRED' AND 
150943 p_source_39 >  0
150944  THEN 
150945 
150946    --
150947    XLA_AE_LINES_PKG.SetNewLine;
150948 
150949    p_balance_type_code          := l_balance_type_code;
150950    -- set the flag so later we will know whether the gain loss line needs to be created
150951    
150952    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
150953      p_actual_flag :='A';
150954    END IF;
150955 
150956    --
150957    -- bulk performance
150958    --
150959    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
150960                                       p_header_num   => 0); -- 4262811
150961    --
150962    -- set accounting line options
150963    --
150964    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
150965            p_natural_side_code          => 'D'
150966          , p_gain_or_loss_flag          => 'N'
150967          , p_gl_transfer_mode_code      => 'S'
150968          , p_acct_entry_type_code       => 'A'
150969          , p_switch_side_flag           => 'Y'
150970          , p_merge_duplicate_code       => 'N'
150971          );
150972    --
150973    l_acc_rev_natural_side_code := 'C';  -- 4262811
150974    -- 
150975    --
150976    -- set accounting line type info
150977    --
150978    xla_ae_lines_pkg.SetAcctLineType
150979       (p_component_type             => l_component_type
150980       ,p_event_type_code            => l_event_type_code
150981       ,p_line_definition_owner_code => l_line_definition_owner_code
150982       ,p_line_definition_code       => l_line_definition_code
150983       ,p_accounting_line_code       => l_component_code
150984       ,p_accounting_line_type_code  => l_component_type_code
150985       ,p_accounting_line_appl_id    => l_component_appl_id
150986       ,p_amb_context_code           => l_amb_context_code
150987       ,p_entity_code                => l_entity_code
150988       ,p_event_class_code           => l_event_class_code);
150989    --
150990    -- set accounting class
150991    --
150992    xla_ae_lines_pkg.SetAcctClass(
150993            p_accounting_class_code  => 'ASSET'
150994          , p_ae_header_id           => l_ae_header_id
150995          );
150996 
150997    --
150998    -- set rounding class
150999    --
151000    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
151001                       'ASSET';
151002 
151003    --
151004    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
151005    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
151006    --
151007    -- bulk performance
151008    --
151009    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
151010 
151011    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
151012       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
151013 
151014    -- 4955764
151015    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
151016       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
151017 
151018    -- 4458381 Public Sector Enh
151019    
151020    --
151021    -- set accounting attributes for the line type
151022    --
151023    l_entered_amt_idx := 4;
151024    l_accted_amt_idx  := 6;
151025    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
151026    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
151027    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
151028    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
151029    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
151030    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
151031    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
151032    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
151033    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
151034    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
151035    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
151036    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
151037    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
151038 
151039    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
151040    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
151041 
151042    ---------------------------------------------------------------------------------------------------------------
151046 
151043    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
151044    ---------------------------------------------------------------------------------------------------------------
151045    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
151047    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
151048    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
151049 
151050    IF xla_accounting_cache_pkg.GetValueChar
151051          (p_source_code         => 'LEDGER_CATEGORY_CODE'
151052          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
151053    AND l_bflow_method_code = 'PRIOR_ENTRY'
151054 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
151055    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
151056          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
151057        )
151058    THEN
151059          xla_ae_lines_pkg.BflowUpgEntry
151060            (p_business_method_code    => l_bflow_method_code
151061            ,p_business_class_code     => l_bflow_class_code
151062            ,p_balance_type            => l_balance_type_code);
151063    ELSE
151064       NULL;
151065 -- No business flow processing for business flow method of NONE.
151066    END IF;
151067 
151068    --
151069    -- call analytical criteria
151070    --
151071    
151072    --
151073    -- call description
151074    --
151075    
151076 xla_ae_lines_pkg.SetLineDescription(
151077    p_ae_header_id => l_ae_header_id
151078   ,p_description  => Description_120 (
151079      p_application_id         => p_application_id
151080    , p_ae_header_id           => l_ae_header_id 
151081 , p_source_1 => p_source_1
151082    )
151083 );
151084 
151085 
151086    --
151087    -- call ADRs
151088    -- Bug 4922099
151089    --
151090    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
151091         (NVL(l_actual_upg_option, 'N') = 'O') OR
151092         (NVL(l_enc_upg_option, 'N') = 'O')
151093       )
151094    THEN
151095    NULL;
151096    --
151097    --
151098    
151099   l_ccid := AcctDerRule_173(
151100            p_application_id           => p_application_id
151101          , p_ae_header_id             => l_ae_header_id 
151102 , p_source_3 => p_source_3
151103 , p_source_30 => p_source_30
151104          , x_transaction_coa_id       => l_adr_transaction_coa_id
151105          , x_accounting_coa_id        => l_adr_accounting_coa_id
151106          , x_value_type_code          => l_adr_value_type_code
151107          , p_side                     => 'NA'
151108    );
151109 
151110    xla_ae_lines_pkg.set_ccid(
151111     p_code_combination_id          => l_ccid
151112   , p_value_type_code              => l_adr_value_type_code
151113   , p_transaction_coa_id           => l_adr_transaction_coa_id
151114   , p_accounting_coa_id            => l_adr_accounting_coa_id
151115   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
151116   , p_adr_type_code                => 'S'
151117   , p_component_type               => l_component_type
151118   , p_component_code               => l_component_code
151119   , p_component_type_code          => l_component_type_code
151120   , p_component_appl_id            => l_component_appl_id
151121   , p_amb_context_code             => l_amb_context_code
151122   , p_side                         => 'NA'
151123   );
151124 
151125 
151126    l_segment := AcctDerRule_168(
151127            p_application_id           => p_application_id
151128          , p_ae_header_id             => l_ae_header_id 
151129 , p_source_3 => p_source_3
151130 , p_source_29 => p_source_29
151131          , x_transaction_coa_id       => l_adr_transaction_coa_id
151132          , x_accounting_coa_id        => l_adr_accounting_coa_id
151133          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
151134          , x_flex_value_set_id        => l_adr_flex_value_set_id
151135          , x_value_type_code          => l_adr_value_type_code
151136          , x_value_combination_id     => l_adr_value_combination_id
151137          , x_value_segment_code       => l_adr_value_segment_code
151138          , p_side                     => 'NA'
151139          , p_override_seg_flag        => 'Y'
151140    );
151141 
151142    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
151143 
151144       xla_ae_lines_pkg.set_segment(
151145           p_to_segment_code         => 'GL_BALANCING'
151146         , p_segment_value           => l_segment
151147         , p_from_segment_code       => l_adr_value_segment_code
151148         , p_from_combination_id     => l_adr_value_combination_id
151149         , p_value_type_code         => l_adr_value_type_code
151150         , p_transaction_coa_id      => l_adr_transaction_coa_id
151151         , p_accounting_coa_id       => l_adr_accounting_coa_id
151152         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
151153         , p_flex_value_set_id       => l_adr_flex_value_set_id
151154         , p_adr_code                => 'FA_EXPENSE_ACCT'
151155         , p_adr_type_code           => 'S'
151156         , p_component_type          => l_component_type
151157         , p_component_code          => l_component_code
151158         , p_component_type_code     => l_component_type_code
151159         , p_component_appl_id       => l_component_appl_id
151160         , p_amb_context_code        => l_amb_context_code
151161         , p_entity_code             => 'TRANSACTIONS'
151162         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
151163         , p_side                    => 'NA'
151164         );
151165 
151166   END IF;
151167 
151168    l_segment := AcctDerRule_159(
151169            p_application_id           => p_application_id
151170          , p_ae_header_id             => l_ae_header_id 
151171 , p_source_3 => p_source_3
151175          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
151172 , p_source_21 => p_source_21
151173          , x_transaction_coa_id       => l_adr_transaction_coa_id
151174          , x_accounting_coa_id        => l_adr_accounting_coa_id
151176          , x_flex_value_set_id        => l_adr_flex_value_set_id
151177          , x_value_type_code          => l_adr_value_type_code
151178          , x_value_combination_id     => l_adr_value_combination_id
151179          , x_value_segment_code       => l_adr_value_segment_code
151180          , p_side                     => 'NA'
151181          , p_override_seg_flag        => 'Y'
151182    );
151183 
151184    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
151185 
151186       xla_ae_lines_pkg.set_segment(
151187           p_to_segment_code         => 'GL_ACCOUNT'
151188         , p_segment_value           => l_segment
151189         , p_from_segment_code       => l_adr_value_segment_code
151190         , p_from_combination_id     => l_adr_value_combination_id
151191         , p_value_type_code         => l_adr_value_type_code
151192         , p_transaction_coa_id      => l_adr_transaction_coa_id
151193         , p_accounting_coa_id       => l_adr_accounting_coa_id
151194         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
151195         , p_flex_value_set_id       => l_adr_flex_value_set_id
151196         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
151197         , p_adr_type_code           => 'S'
151198         , p_component_type          => l_component_type
151199         , p_component_code          => l_component_code
151200         , p_component_type_code     => l_component_type_code
151201         , p_component_appl_id       => l_component_appl_id
151202         , p_amb_context_code        => l_amb_context_code
151203         , p_entity_code             => 'TRANSACTIONS'
151204         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
151205         , p_side                    => 'NA'
151206         );
151207 
151208   END IF;
151209 
151210    --
151211    --
151212    END IF;
151213    --
151214    -- Bug 4922099
151215    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
151216           (NVL(l_enc_upg_option, 'N') = 'O')
151217         ) AND
151218         (l_bflow_method_code = 'PRIOR_ENTRY')
151219       )
151220    THEN
151221       IF
151222       --
151223       1 = 2
151224       --
151225       THEN
151226       xla_accounting_err_pkg.build_message
151227                                     (p_appli_s_name            => 'XLA'
151228                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
151229                                     ,p_token_1                 => 'LINE_NUMBER'
151230                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
151231                                     ,p_token_2                 => 'LINE_TYPE_NAME'
151232                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
151233                                                                              l_component_type
151234                                                                             ,l_component_code
151235                                                                             ,l_component_type_code
151236                                                                             ,l_component_appl_id
151237                                                                             ,l_amb_context_code
151238                                                                             ,l_entity_code
151239                                                                             ,l_event_class_code
151240                                                                            )
151241                                     ,p_token_3                 => 'OWNER'
151242                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
151243                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
151244                                                                           ,p_lookup_code    => l_component_type_code
151245                                                                          )
151246                                     ,p_token_4                 => 'PRODUCT_NAME'
151247                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
151248                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
151249                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
151250                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
151251                                     ,p_ae_header_id            =>  NULL
151252                                        );
151253 
151254         IF (C_LEVEL_ERROR>= g_log_level) THEN
151255                  trace
151256                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
151257                       ,p_level    => C_LEVEL_ERROR
151258                       ,p_module   => l_log_module);
151259         END IF;
151260       END IF;
151261    END IF;
151262    --
151263    --
151264    ------------------------------------------------------------------------------------------------
151265    -- 4219869 Business Flow
151266    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
151267    -- Prior Entry.  Currently, the following code is always generated.
151268    ------------------------------------------------------------------------------------------------
151269    XLA_AE_LINES_PKG.ValidateCurrentLine;
151270 
151271    ------------------------------------------------------------------------------------
151272    -- 4219869 Business Flow
151273    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
151274    ------------------------------------------------------------------------------------
151278    -- 4219869 Business Flow
151275    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
151276 
151277    ----------------------------------------------------------------------------------
151279    -- Update journal entry status -- Need to generate this within IF <condition>
151280    ----------------------------------------------------------------------------------
151281    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
151282          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
151283          ,p_balance_type_code => l_balance_type_code
151284          );
151285 
151286    -------------------------------------------------------------------------------------------
151287    -- 4262811 - Generate the Accrual Reversal lines
151288    -------------------------------------------------------------------------------------------
151289    BEGIN
151290       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
151291                               (g_array_event(p_event_id).array_value_num('header_index'));
151292       IF l_acc_rev_flag IS NULL THEN
151293          l_acc_rev_flag := 'N';
151294       END IF;
151295    EXCEPTION
151296       WHEN OTHERS THEN
151297          l_acc_rev_flag := 'N';
151298    END;
151299    --
151300    IF (l_acc_rev_flag = 'Y') THEN
151301 
151302        -- 4645092  ------------------------------------------------------------------------------
151303        -- To allow MPA report to determine if it should generate report process
151304        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
151305        ------------------------------------------------------------------------------------------
151306 
151307        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
151308        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
151309    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
151310    -- call ADRs
151311    -- Bug 4922099
151312    --
151313    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
151314         (NVL(l_actual_upg_option, 'N') = 'O') OR
151315         (NVL(l_enc_upg_option, 'N') = 'O')
151316       )
151317    THEN
151318    NULL;
151319    --
151320    --
151321    
151322   l_ccid := AcctDerRule_173(
151323            p_application_id           => p_application_id
151324          , p_ae_header_id             => l_ae_header_id 
151325 , p_source_3 => p_source_3
151326 , p_source_30 => p_source_30
151327          , x_transaction_coa_id       => l_adr_transaction_coa_id
151328          , x_accounting_coa_id        => l_adr_accounting_coa_id
151329          , x_value_type_code          => l_adr_value_type_code
151330          , p_side                     => 'NA'
151331    );
151332 
151333    xla_ae_lines_pkg.set_ccid(
151334     p_code_combination_id          => l_ccid
151335   , p_value_type_code              => l_adr_value_type_code
151336   , p_transaction_coa_id           => l_adr_transaction_coa_id
151337   , p_accounting_coa_id            => l_adr_accounting_coa_id
151338   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
151339   , p_adr_type_code                => 'S'
151340   , p_component_type               => l_component_type
151341   , p_component_code               => l_component_code
151342   , p_component_type_code          => l_component_type_code
151343   , p_component_appl_id            => l_component_appl_id
151344   , p_amb_context_code             => l_amb_context_code
151345   , p_side                         => 'NA'
151346   );
151347 
151348 
151349    l_segment := AcctDerRule_168(
151350            p_application_id           => p_application_id
151351          , p_ae_header_id             => l_ae_header_id 
151352 , p_source_3 => p_source_3
151353 , p_source_29 => p_source_29
151354          , x_transaction_coa_id       => l_adr_transaction_coa_id
151355          , x_accounting_coa_id        => l_adr_accounting_coa_id
151356          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
151357          , x_flex_value_set_id        => l_adr_flex_value_set_id
151358          , x_value_type_code          => l_adr_value_type_code
151359          , x_value_combination_id     => l_adr_value_combination_id
151360          , x_value_segment_code       => l_adr_value_segment_code
151361          , p_side                     => 'NA'
151362          , p_override_seg_flag        => 'Y'
151363    );
151364 
151365    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
151366 
151367       xla_ae_lines_pkg.set_segment(
151368           p_to_segment_code         => 'GL_BALANCING'
151369         , p_segment_value           => l_segment
151370         , p_from_segment_code       => l_adr_value_segment_code
151371         , p_from_combination_id     => l_adr_value_combination_id
151372         , p_value_type_code         => l_adr_value_type_code
151373         , p_transaction_coa_id      => l_adr_transaction_coa_id
151374         , p_accounting_coa_id       => l_adr_accounting_coa_id
151375         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
151376         , p_flex_value_set_id       => l_adr_flex_value_set_id
151377         , p_adr_code                => 'FA_EXPENSE_ACCT'
151378         , p_adr_type_code           => 'S'
151379         , p_component_type          => l_component_type
151380         , p_component_code          => l_component_code
151381         , p_component_type_code     => l_component_type_code
151382         , p_component_appl_id       => l_component_appl_id
151383         , p_amb_context_code        => l_amb_context_code
151384         , p_entity_code             => 'TRANSACTIONS'
151385         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
151386         , p_side                    => 'NA'
151387         );
151388 
151389   END IF;
151390 
151391    l_segment := AcctDerRule_159(
151392            p_application_id           => p_application_id
151393          , p_ae_header_id             => l_ae_header_id 
151394 , p_source_3 => p_source_3
151395 , p_source_21 => p_source_21
151396          , x_transaction_coa_id       => l_adr_transaction_coa_id
151400          , x_value_type_code          => l_adr_value_type_code
151397          , x_accounting_coa_id        => l_adr_accounting_coa_id
151398          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
151399          , x_flex_value_set_id        => l_adr_flex_value_set_id
151401          , x_value_combination_id     => l_adr_value_combination_id
151402          , x_value_segment_code       => l_adr_value_segment_code
151403          , p_side                     => 'NA'
151404          , p_override_seg_flag        => 'Y'
151405    );
151406 
151407    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
151408 
151409       xla_ae_lines_pkg.set_segment(
151410           p_to_segment_code         => 'GL_ACCOUNT'
151411         , p_segment_value           => l_segment
151412         , p_from_segment_code       => l_adr_value_segment_code
151413         , p_from_combination_id     => l_adr_value_combination_id
151414         , p_value_type_code         => l_adr_value_type_code
151415         , p_transaction_coa_id      => l_adr_transaction_coa_id
151416         , p_accounting_coa_id       => l_adr_accounting_coa_id
151417         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
151418         , p_flex_value_set_id       => l_adr_flex_value_set_id
151419         , p_adr_code                => 'FA_NBV_RETIRED_GAIN_SEGMENT'
151420         , p_adr_type_code           => 'S'
151421         , p_component_type          => l_component_type
151422         , p_component_code          => l_component_code
151423         , p_component_type_code     => l_component_type_code
151424         , p_component_appl_id       => l_component_appl_id
151425         , p_amb_context_code        => l_amb_context_code
151426         , p_entity_code             => 'TRANSACTIONS'
151427         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
151428         , p_side                    => 'NA'
151429         );
151430 
151431   END IF;
151432 
151433    --
151434    --
151435    END IF;
151436 
151437        --
151438        -- Update the line information that should be overwritten
151439        --
151440        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
151441                                          p_header_num   => 1);
151442        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
151443 
151444        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
151445 
151446        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
151447           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
151448        END IF;
151449 
151450       --
151451       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
151452       --
151453       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
151454           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
151455       ELSE
151456           ---------------------------------------------------------------------------------------------------
151457           -- 4262811a Switch Sign
151458           ---------------------------------------------------------------------------------------------------
151459           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
151460           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
151461                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
151462           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
151463                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
151464           -- 5132302
151465           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
151466                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
151467 
151468       END IF;
151469 
151470       -- 4955764
151471       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
151472       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
151473 
151474 
151475       XLA_AE_LINES_PKG.ValidateCurrentLine;
151476       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
151477 
151478       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
151479                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
151480                ,p_balance_type_code => l_balance_type_code);
151481 
151482    END IF;
151483 
151484    -----------------------------------------------------------------------------------------
151485    -- 4262811 Multiperiod Accounting
151486    -----------------------------------------------------------------------------------------
151487      -- No MPA option is assigned.
151488 
151489 
151490 END IF;
151491 END IF;
151492 --
151493 
151494 --
151495 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
151496    trace
151497       (p_msg      => 'END of AcctLineType_366'
151498       ,p_level    => C_LEVEL_PROCEDURE
151499       ,p_module   => l_log_module);
151500 END IF;
151501 --
151502 EXCEPTION
151503   WHEN xla_exceptions_pkg.application_exception THEN
151504       RAISE;
151505   WHEN OTHERS THEN
151506        xla_exceptions_pkg.raise_message
151507            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_366');
151508 END AcctLineType_366;
151509 --
151510 
151511 ---------------------------------------
151512 --
151513 -- PRIVATE FUNCTION
151514 --         AcctLineType_367
151515 --
151516 ---------------------------------------
151517 PROCEDURE AcctLineType_367 (
151518   p_application_id        IN NUMBER
151519  ,p_event_id              IN NUMBER
151520  ,p_calculate_acctd_flag  IN VARCHAR2
151524  ,p_gain_or_loss_ref      OUT VARCHAR2
151521  ,p_calculate_g_l_flag    IN VARCHAR2
151522  ,p_actual_flag           IN OUT VARCHAR2
151523  ,p_balance_type_code     OUT VARCHAR2
151525  
151526 --Period Close Date
151527  , p_source_1            IN DATE
151528 --Generated Code Combination Identifier
151529  , p_source_3            IN NUMBER
151530 --Net Book Value Retired Loss Account
151531  , p_source_22            IN VARCHAR2
151532 --Expense Account Code Combination Identifier
151533  , p_source_29            IN NUMBER
151534 --Default Code Combination Identifier
151535  , p_source_30            IN NUMBER
151536 --Adjustment Type
151537  , p_source_35            IN VARCHAR2
151538 --Transaction Header Identifier
151539  , p_source_36            IN NUMBER
151540 --Adjustment Line Identifier
151541  , p_source_37            IN NUMBER
151542 --Distribution Type Code
151543  , p_source_38            IN VARCHAR2
151544 --Entered Amount
151545  , p_source_39            IN NUMBER
151546 --Currency Code
151547  , p_source_40            IN VARCHAR2
151548 )
151549 IS
151550 
151551 l_component_type              VARCHAR2(80);
151552 l_component_code              VARCHAR2(30);
151553 l_component_type_code         VARCHAR2(1);
151554 l_component_appl_id           INTEGER;
151555 l_amb_context_code            VARCHAR2(30);
151556 l_entity_code                 VARCHAR2(30);
151557 l_event_class_code            VARCHAR2(30);
151558 l_ae_header_id                NUMBER;
151559 l_event_type_code             VARCHAR2(30);
151560 l_line_definition_code        VARCHAR2(30);
151561 l_line_definition_owner_code  VARCHAR2(1);
151562 --
151563 -- adr variables
151564 l_segment                     VARCHAR2(30);
151565 l_ccid                        NUMBER;
151566 l_adr_transaction_coa_id      NUMBER;
151567 l_adr_accounting_coa_id       NUMBER;
151568 l_adr_flexfield_segment_code  VARCHAR2(30);
151569 l_adr_flex_value_set_id       NUMBER;
151570 l_adr_value_type_code         VARCHAR2(30);
151571 l_adr_value_combination_id    NUMBER;
151572 l_adr_value_segment_code      VARCHAR2(30);
151573 
151574 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
151575 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
151576 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
151577 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
151578 
151579 -- 4262811 Variables ------------------------------------------------------------------------------------------
151580 l_entered_amt_idx             NUMBER;
151581 l_accted_amt_idx              NUMBER;
151582 l_acc_rev_flag                VARCHAR2(1);
151583 l_accrual_line_num            NUMBER;
151584 l_tmp_amt                     NUMBER;
151585 l_acc_rev_natural_side_code   VARCHAR2(1);
151586 
151587 l_num_entries                 NUMBER;
151588 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
151589 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
151590 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
151591 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
151592 l_recog_line_1                NUMBER;
151593 l_recog_line_2                NUMBER;
151594 
151595 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
151596 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
151597 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
151598 
151599 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
151600 
151601 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
151602 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
151603 
151604 ---------------------------------------------------------------------------------------------------------------
151605 
151606 
151607 --
151608 -- bulk performance
151609 --
151610 l_balance_type_code           VARCHAR2(1);
151611 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
151612 l_log_module                  VARCHAR2(240);
151613 
151614 --
151615 -- Upgrade strategy
151616 --
151617 l_actual_upg_option           VARCHAR2(1);
151618 l_enc_upg_option           VARCHAR2(1);
151619 
151620 --
151621 BEGIN
151622 --
151623 IF g_log_enabled THEN
151624       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_367';
151625 END IF;
151626 --
151627 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
151628 
151629       trace
151630          (p_msg      => 'BEGIN of AcctLineType_367'
151631          ,p_level    => C_LEVEL_PROCEDURE
151632          ,p_module   => l_log_module);
151633 
151634 END IF;
151635 --
151636 l_component_type             := 'AMB_JLT';
151637 l_component_code             := 'FA_TGL_NBV_RETIRED_LOSS';
151638 l_component_type_code        := 'S';
151639 l_component_appl_id          :=  140;
151640 l_amb_context_code           := 'DEFAULT';
151641 l_entity_code                := 'TRANSACTIONS';
151642 l_event_class_code           := 'TERMINAL_GAIN_LOSS';
151643 l_event_type_code            := 'TERMINAL_GAIN_LOSS_ALL';
151644 l_line_definition_owner_code := 'S';
151645 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TERMI24';
151646 --
151647 l_balance_type_code          := 'A';
151648 l_segment                     := NULL;
151649 l_ccid                        := NULL;
151650 l_adr_transaction_coa_id      := NULL;
151651 l_adr_accounting_coa_id       := NULL;
151652 l_adr_flexfield_segment_code  := NULL;
151653 l_adr_flex_value_set_id       := NULL;
151654 l_adr_value_type_code         := NULL;
151655 l_adr_value_combination_id    := NULL;
151656 l_adr_value_segment_code      := NULL;
151657 
151658 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
151659 l_bflow_class_code           := '';    -- 4219869 Business Flow
151663 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
151660 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
151661 l_budgetary_control_flag     := 'N';
151662 
151664 l_bflow_applied_to_amt       := NULL; -- 5132302
151665 l_entered_amt_idx            := NULL;          -- 4262811
151666 l_accted_amt_idx             := NULL;          -- 4262811
151667 l_acc_rev_flag               := NULL;          -- 4262811
151668 l_accrual_line_num           := NULL;          -- 4262811
151669 l_tmp_amt                    := NULL;          -- 4262811
151670 --
151671  
151672 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
151673     l_balance_type_code <> 'B' THEN
151674 IF NVL(p_source_35,'
151675 ') =  'NBV RETIRED' AND 
151676 p_source_39 <=  0
151677  THEN 
151678 
151679    --
151680    XLA_AE_LINES_PKG.SetNewLine;
151681 
151682    p_balance_type_code          := l_balance_type_code;
151683    -- set the flag so later we will know whether the gain loss line needs to be created
151684    
151685    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
151686      p_actual_flag :='A';
151687    END IF;
151688 
151689    --
151690    -- bulk performance
151691    --
151692    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
151693                                       p_header_num   => 0); -- 4262811
151694    --
151695    -- set accounting line options
151696    --
151697    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
151698            p_natural_side_code          => 'D'
151699          , p_gain_or_loss_flag          => 'N'
151700          , p_gl_transfer_mode_code      => 'S'
151701          , p_acct_entry_type_code       => 'A'
151702          , p_switch_side_flag           => 'Y'
151703          , p_merge_duplicate_code       => 'N'
151704          );
151705    --
151706    l_acc_rev_natural_side_code := 'C';  -- 4262811
151707    -- 
151708    --
151709    -- set accounting line type info
151710    --
151711    xla_ae_lines_pkg.SetAcctLineType
151712       (p_component_type             => l_component_type
151713       ,p_event_type_code            => l_event_type_code
151714       ,p_line_definition_owner_code => l_line_definition_owner_code
151715       ,p_line_definition_code       => l_line_definition_code
151716       ,p_accounting_line_code       => l_component_code
151717       ,p_accounting_line_type_code  => l_component_type_code
151718       ,p_accounting_line_appl_id    => l_component_appl_id
151719       ,p_amb_context_code           => l_amb_context_code
151720       ,p_entity_code                => l_entity_code
151721       ,p_event_class_code           => l_event_class_code);
151722    --
151723    -- set accounting class
151724    --
151725    xla_ae_lines_pkg.SetAcctClass(
151726            p_accounting_class_code  => 'ASSET'
151727          , p_ae_header_id           => l_ae_header_id
151728          );
151729 
151730    --
151731    -- set rounding class
151732    --
151733    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
151734                       'ASSET';
151735 
151736    --
151737    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
151738    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
151739    --
151740    -- bulk performance
151741    --
151742    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
151743 
151744    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
151745       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
151746 
151747    -- 4955764
151748    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
151749       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
151750 
151751    -- 4458381 Public Sector Enh
151752    
151753    --
151754    -- set accounting attributes for the line type
151755    --
151756    l_entered_amt_idx := 4;
151757    l_accted_amt_idx  := 6;
151758    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
151759    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
151760    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
151761    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
151762    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
151763    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
151764    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
151765    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
151766    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
151767    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
151768    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
151769    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
151770    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
151771 
151772    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
151773    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
151774 
151775    ---------------------------------------------------------------------------------------------------------------
151776    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
151777    ---------------------------------------------------------------------------------------------------------------
151778    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
151779 
151780    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
151781    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
151782 
151783    IF xla_accounting_cache_pkg.GetValueChar
151787 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
151784          (p_source_code         => 'LEDGER_CATEGORY_CODE'
151785          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
151786    AND l_bflow_method_code = 'PRIOR_ENTRY'
151788    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
151789          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
151790        )
151791    THEN
151792          xla_ae_lines_pkg.BflowUpgEntry
151793            (p_business_method_code    => l_bflow_method_code
151794            ,p_business_class_code     => l_bflow_class_code
151795            ,p_balance_type            => l_balance_type_code);
151796    ELSE
151797       NULL;
151798 -- No business flow processing for business flow method of NONE.
151799    END IF;
151800 
151801    --
151802    -- call analytical criteria
151803    --
151804    
151805    --
151806    -- call description
151807    --
151808    
151809 xla_ae_lines_pkg.SetLineDescription(
151810    p_ae_header_id => l_ae_header_id
151811   ,p_description  => Description_121 (
151812      p_application_id         => p_application_id
151813    , p_ae_header_id           => l_ae_header_id 
151814 , p_source_1 => p_source_1
151815    )
151816 );
151817 
151818 
151819    --
151820    -- call ADRs
151821    -- Bug 4922099
151822    --
151823    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
151824         (NVL(l_actual_upg_option, 'N') = 'O') OR
151825         (NVL(l_enc_upg_option, 'N') = 'O')
151826       )
151827    THEN
151828    NULL;
151829    --
151830    --
151831    
151832   l_ccid := AcctDerRule_173(
151833            p_application_id           => p_application_id
151834          , p_ae_header_id             => l_ae_header_id 
151835 , p_source_3 => p_source_3
151836 , p_source_30 => p_source_30
151837          , x_transaction_coa_id       => l_adr_transaction_coa_id
151838          , x_accounting_coa_id        => l_adr_accounting_coa_id
151839          , x_value_type_code          => l_adr_value_type_code
151840          , p_side                     => 'NA'
151841    );
151842 
151843    xla_ae_lines_pkg.set_ccid(
151844     p_code_combination_id          => l_ccid
151845   , p_value_type_code              => l_adr_value_type_code
151846   , p_transaction_coa_id           => l_adr_transaction_coa_id
151847   , p_accounting_coa_id            => l_adr_accounting_coa_id
151848   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
151849   , p_adr_type_code                => 'S'
151850   , p_component_type               => l_component_type
151851   , p_component_code               => l_component_code
151852   , p_component_type_code          => l_component_type_code
151853   , p_component_appl_id            => l_component_appl_id
151854   , p_amb_context_code             => l_amb_context_code
151855   , p_side                         => 'NA'
151856   );
151857 
151858 
151859    l_segment := AcctDerRule_168(
151860            p_application_id           => p_application_id
151861          , p_ae_header_id             => l_ae_header_id 
151862 , p_source_3 => p_source_3
151863 , p_source_29 => p_source_29
151864          , x_transaction_coa_id       => l_adr_transaction_coa_id
151865          , x_accounting_coa_id        => l_adr_accounting_coa_id
151866          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
151867          , x_flex_value_set_id        => l_adr_flex_value_set_id
151868          , x_value_type_code          => l_adr_value_type_code
151869          , x_value_combination_id     => l_adr_value_combination_id
151870          , x_value_segment_code       => l_adr_value_segment_code
151871          , p_side                     => 'NA'
151872          , p_override_seg_flag        => 'Y'
151873    );
151874 
151875    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
151876 
151877       xla_ae_lines_pkg.set_segment(
151878           p_to_segment_code         => 'GL_BALANCING'
151879         , p_segment_value           => l_segment
151880         , p_from_segment_code       => l_adr_value_segment_code
151881         , p_from_combination_id     => l_adr_value_combination_id
151882         , p_value_type_code         => l_adr_value_type_code
151883         , p_transaction_coa_id      => l_adr_transaction_coa_id
151884         , p_accounting_coa_id       => l_adr_accounting_coa_id
151885         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
151886         , p_flex_value_set_id       => l_adr_flex_value_set_id
151887         , p_adr_code                => 'FA_EXPENSE_ACCT'
151888         , p_adr_type_code           => 'S'
151889         , p_component_type          => l_component_type
151890         , p_component_code          => l_component_code
151891         , p_component_type_code     => l_component_type_code
151892         , p_component_appl_id       => l_component_appl_id
151893         , p_amb_context_code        => l_amb_context_code
151894         , p_entity_code             => 'TRANSACTIONS'
151895         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
151896         , p_side                    => 'NA'
151897         );
151898 
151899   END IF;
151900 
151901    l_segment := AcctDerRule_160(
151902            p_application_id           => p_application_id
151903          , p_ae_header_id             => l_ae_header_id 
151904 , p_source_3 => p_source_3
151905 , p_source_22 => p_source_22
151906          , x_transaction_coa_id       => l_adr_transaction_coa_id
151907          , x_accounting_coa_id        => l_adr_accounting_coa_id
151908          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
151909          , x_flex_value_set_id        => l_adr_flex_value_set_id
151910          , x_value_type_code          => l_adr_value_type_code
151911          , x_value_combination_id     => l_adr_value_combination_id
151912          , x_value_segment_code       => l_adr_value_segment_code
151913          , p_side                     => 'NA'
151914          , p_override_seg_flag        => 'Y'
151918 
151915    );
151916 
151917    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
151919       xla_ae_lines_pkg.set_segment(
151920           p_to_segment_code         => 'GL_ACCOUNT'
151921         , p_segment_value           => l_segment
151922         , p_from_segment_code       => l_adr_value_segment_code
151923         , p_from_combination_id     => l_adr_value_combination_id
151924         , p_value_type_code         => l_adr_value_type_code
151925         , p_transaction_coa_id      => l_adr_transaction_coa_id
151926         , p_accounting_coa_id       => l_adr_accounting_coa_id
151927         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
151928         , p_flex_value_set_id       => l_adr_flex_value_set_id
151929         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
151930         , p_adr_type_code           => 'S'
151931         , p_component_type          => l_component_type
151932         , p_component_code          => l_component_code
151933         , p_component_type_code     => l_component_type_code
151934         , p_component_appl_id       => l_component_appl_id
151935         , p_amb_context_code        => l_amb_context_code
151936         , p_entity_code             => 'TRANSACTIONS'
151937         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
151938         , p_side                    => 'NA'
151939         );
151940 
151941   END IF;
151942 
151943    --
151944    --
151945    END IF;
151946    --
151947    -- Bug 4922099
151948    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
151949           (NVL(l_enc_upg_option, 'N') = 'O')
151950         ) AND
151951         (l_bflow_method_code = 'PRIOR_ENTRY')
151952       )
151953    THEN
151954       IF
151955       --
151956       1 = 2
151957       --
151958       THEN
151959       xla_accounting_err_pkg.build_message
151960                                     (p_appli_s_name            => 'XLA'
151961                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
151962                                     ,p_token_1                 => 'LINE_NUMBER'
151963                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
151964                                     ,p_token_2                 => 'LINE_TYPE_NAME'
151965                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
151966                                                                              l_component_type
151967                                                                             ,l_component_code
151968                                                                             ,l_component_type_code
151969                                                                             ,l_component_appl_id
151970                                                                             ,l_amb_context_code
151971                                                                             ,l_entity_code
151972                                                                             ,l_event_class_code
151973                                                                            )
151974                                     ,p_token_3                 => 'OWNER'
151975                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
151976                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
151977                                                                           ,p_lookup_code    => l_component_type_code
151978                                                                          )
151979                                     ,p_token_4                 => 'PRODUCT_NAME'
151980                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
151981                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
151982                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
151983                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
151984                                     ,p_ae_header_id            =>  NULL
151985                                        );
151986 
151987         IF (C_LEVEL_ERROR>= g_log_level) THEN
151988                  trace
151989                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
151990                       ,p_level    => C_LEVEL_ERROR
151991                       ,p_module   => l_log_module);
151992         END IF;
151993       END IF;
151994    END IF;
151995    --
151996    --
151997    ------------------------------------------------------------------------------------------------
151998    -- 4219869 Business Flow
151999    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
152000    -- Prior Entry.  Currently, the following code is always generated.
152001    ------------------------------------------------------------------------------------------------
152002    XLA_AE_LINES_PKG.ValidateCurrentLine;
152003 
152004    ------------------------------------------------------------------------------------
152005    -- 4219869 Business Flow
152006    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
152007    ------------------------------------------------------------------------------------
152008    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
152009 
152010    ----------------------------------------------------------------------------------
152011    -- 4219869 Business Flow
152012    -- Update journal entry status -- Need to generate this within IF <condition>
152013    ----------------------------------------------------------------------------------
152014    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
152015          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
152016          ,p_balance_type_code => l_balance_type_code
152017          );
152018 
152022    BEGIN
152019    -------------------------------------------------------------------------------------------
152020    -- 4262811 - Generate the Accrual Reversal lines
152021    -------------------------------------------------------------------------------------------
152023       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
152024                               (g_array_event(p_event_id).array_value_num('header_index'));
152025       IF l_acc_rev_flag IS NULL THEN
152026          l_acc_rev_flag := 'N';
152027       END IF;
152028    EXCEPTION
152029       WHEN OTHERS THEN
152030          l_acc_rev_flag := 'N';
152031    END;
152032    --
152033    IF (l_acc_rev_flag = 'Y') THEN
152034 
152035        -- 4645092  ------------------------------------------------------------------------------
152036        -- To allow MPA report to determine if it should generate report process
152037        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
152038        ------------------------------------------------------------------------------------------
152039 
152040        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
152041        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
152042    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
152043    -- call ADRs
152044    -- Bug 4922099
152045    --
152046    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
152047         (NVL(l_actual_upg_option, 'N') = 'O') OR
152048         (NVL(l_enc_upg_option, 'N') = 'O')
152049       )
152050    THEN
152051    NULL;
152052    --
152053    --
152054    
152055   l_ccid := AcctDerRule_173(
152056            p_application_id           => p_application_id
152057          , p_ae_header_id             => l_ae_header_id 
152058 , p_source_3 => p_source_3
152059 , p_source_30 => p_source_30
152060          , x_transaction_coa_id       => l_adr_transaction_coa_id
152061          , x_accounting_coa_id        => l_adr_accounting_coa_id
152062          , x_value_type_code          => l_adr_value_type_code
152063          , p_side                     => 'NA'
152064    );
152065 
152066    xla_ae_lines_pkg.set_ccid(
152067     p_code_combination_id          => l_ccid
152068   , p_value_type_code              => l_adr_value_type_code
152069   , p_transaction_coa_id           => l_adr_transaction_coa_id
152070   , p_accounting_coa_id            => l_adr_accounting_coa_id
152071   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
152072   , p_adr_type_code                => 'S'
152073   , p_component_type               => l_component_type
152074   , p_component_code               => l_component_code
152075   , p_component_type_code          => l_component_type_code
152076   , p_component_appl_id            => l_component_appl_id
152077   , p_amb_context_code             => l_amb_context_code
152078   , p_side                         => 'NA'
152079   );
152080 
152081 
152082    l_segment := AcctDerRule_168(
152083            p_application_id           => p_application_id
152084          , p_ae_header_id             => l_ae_header_id 
152085 , p_source_3 => p_source_3
152086 , p_source_29 => p_source_29
152087          , x_transaction_coa_id       => l_adr_transaction_coa_id
152088          , x_accounting_coa_id        => l_adr_accounting_coa_id
152089          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
152090          , x_flex_value_set_id        => l_adr_flex_value_set_id
152091          , x_value_type_code          => l_adr_value_type_code
152092          , x_value_combination_id     => l_adr_value_combination_id
152093          , x_value_segment_code       => l_adr_value_segment_code
152094          , p_side                     => 'NA'
152095          , p_override_seg_flag        => 'Y'
152096    );
152097 
152098    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
152099 
152100       xla_ae_lines_pkg.set_segment(
152101           p_to_segment_code         => 'GL_BALANCING'
152102         , p_segment_value           => l_segment
152103         , p_from_segment_code       => l_adr_value_segment_code
152104         , p_from_combination_id     => l_adr_value_combination_id
152105         , p_value_type_code         => l_adr_value_type_code
152106         , p_transaction_coa_id      => l_adr_transaction_coa_id
152107         , p_accounting_coa_id       => l_adr_accounting_coa_id
152108         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
152109         , p_flex_value_set_id       => l_adr_flex_value_set_id
152110         , p_adr_code                => 'FA_EXPENSE_ACCT'
152111         , p_adr_type_code           => 'S'
152112         , p_component_type          => l_component_type
152113         , p_component_code          => l_component_code
152114         , p_component_type_code     => l_component_type_code
152115         , p_component_appl_id       => l_component_appl_id
152116         , p_amb_context_code        => l_amb_context_code
152117         , p_entity_code             => 'TRANSACTIONS'
152118         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
152119         , p_side                    => 'NA'
152120         );
152121 
152122   END IF;
152123 
152124    l_segment := AcctDerRule_160(
152125            p_application_id           => p_application_id
152126          , p_ae_header_id             => l_ae_header_id 
152127 , p_source_3 => p_source_3
152128 , p_source_22 => p_source_22
152129          , x_transaction_coa_id       => l_adr_transaction_coa_id
152130          , x_accounting_coa_id        => l_adr_accounting_coa_id
152131          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
152132          , x_flex_value_set_id        => l_adr_flex_value_set_id
152133          , x_value_type_code          => l_adr_value_type_code
152134          , x_value_combination_id     => l_adr_value_combination_id
152135          , x_value_segment_code       => l_adr_value_segment_code
152136          , p_side                     => 'NA'
152137          , p_override_seg_flag        => 'Y'
152138    );
152139 
152143           p_to_segment_code         => 'GL_ACCOUNT'
152140    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
152141 
152142       xla_ae_lines_pkg.set_segment(
152144         , p_segment_value           => l_segment
152145         , p_from_segment_code       => l_adr_value_segment_code
152146         , p_from_combination_id     => l_adr_value_combination_id
152147         , p_value_type_code         => l_adr_value_type_code
152148         , p_transaction_coa_id      => l_adr_transaction_coa_id
152149         , p_accounting_coa_id       => l_adr_accounting_coa_id
152150         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
152151         , p_flex_value_set_id       => l_adr_flex_value_set_id
152152         , p_adr_code                => 'FA_NBV_RETIRED_LOSS_SEGMENT'
152153         , p_adr_type_code           => 'S'
152154         , p_component_type          => l_component_type
152155         , p_component_code          => l_component_code
152156         , p_component_type_code     => l_component_type_code
152157         , p_component_appl_id       => l_component_appl_id
152158         , p_amb_context_code        => l_amb_context_code
152159         , p_entity_code             => 'TRANSACTIONS'
152160         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
152161         , p_side                    => 'NA'
152162         );
152163 
152164   END IF;
152165 
152166    --
152167    --
152168    END IF;
152169 
152170        --
152171        -- Update the line information that should be overwritten
152172        --
152173        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
152174                                          p_header_num   => 1);
152175        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
152176 
152177        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
152178 
152179        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
152180           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
152181        END IF;
152182 
152183       --
152184       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
152185       --
152186       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
152187           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
152188       ELSE
152189           ---------------------------------------------------------------------------------------------------
152190           -- 4262811a Switch Sign
152191           ---------------------------------------------------------------------------------------------------
152192           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
152193           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
152194                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
152195           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
152196                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
152197           -- 5132302
152198           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
152199                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
152200 
152201       END IF;
152202 
152203       -- 4955764
152204       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
152205       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
152206 
152207 
152208       XLA_AE_LINES_PKG.ValidateCurrentLine;
152209       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
152210 
152211       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
152212                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
152213                ,p_balance_type_code => l_balance_type_code);
152214 
152215    END IF;
152216 
152217    -----------------------------------------------------------------------------------------
152218    -- 4262811 Multiperiod Accounting
152219    -----------------------------------------------------------------------------------------
152220      -- No MPA option is assigned.
152221 
152222 
152223 END IF;
152224 END IF;
152225 --
152226 
152227 --
152228 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
152229    trace
152230       (p_msg      => 'END of AcctLineType_367'
152231       ,p_level    => C_LEVEL_PROCEDURE
152232       ,p_module   => l_log_module);
152233 END IF;
152234 --
152235 EXCEPTION
152236   WHEN xla_exceptions_pkg.application_exception THEN
152237       RAISE;
152238   WHEN OTHERS THEN
152239        xla_exceptions_pkg.raise_message
152240            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_367');
152241 END AcctLineType_367;
152242 --
152243 
152244 ---------------------------------------
152245 --
152246 -- PRIVATE FUNCTION
152247 --         AcctLineType_368
152248 --
152249 ---------------------------------------
152250 PROCEDURE AcctLineType_368 (
152251   p_application_id        IN NUMBER
152252  ,p_event_id              IN NUMBER
152253  ,p_calculate_acctd_flag  IN VARCHAR2
152254  ,p_calculate_g_l_flag    IN VARCHAR2
152255  ,p_actual_flag           IN OUT VARCHAR2
152256  ,p_balance_type_code     OUT VARCHAR2
152257  ,p_gain_or_loss_ref      OUT VARCHAR2
152258  
152259 --Period Close Date
152260  , p_source_1            IN DATE
152261 --Generated Code Combination Identifier
152262  , p_source_3            IN NUMBER
152263 --Depreciation Reserve Account
152264  , p_source_10            IN VARCHAR2
152265 --Generated Offset Code Combination Identifier
152266  , p_source_17            IN NUMBER
152270  , p_source_30            IN NUMBER
152267 --Expense Account Code Combination Identifier
152268  , p_source_29            IN NUMBER
152269 --Default Code Combination Identifier
152271 --Adjustment Type
152272  , p_source_35            IN VARCHAR2
152273 --Transaction Header Identifier
152274  , p_source_36            IN NUMBER
152275 --Adjustment Line Identifier
152276  , p_source_37            IN NUMBER
152277 --Distribution Type Code
152278  , p_source_38            IN VARCHAR2
152279 --Entered Amount
152280  , p_source_39            IN NUMBER
152281 --Currency Code
152282  , p_source_40            IN VARCHAR2
152283 )
152284 IS
152285 
152286 l_component_type              VARCHAR2(80);
152287 l_component_code              VARCHAR2(30);
152288 l_component_type_code         VARCHAR2(1);
152289 l_component_appl_id           INTEGER;
152290 l_amb_context_code            VARCHAR2(30);
152291 l_entity_code                 VARCHAR2(30);
152292 l_event_class_code            VARCHAR2(30);
152293 l_ae_header_id                NUMBER;
152294 l_event_type_code             VARCHAR2(30);
152295 l_line_definition_code        VARCHAR2(30);
152296 l_line_definition_owner_code  VARCHAR2(1);
152297 --
152298 -- adr variables
152299 l_segment                     VARCHAR2(30);
152300 l_ccid                        NUMBER;
152301 l_adr_transaction_coa_id      NUMBER;
152302 l_adr_accounting_coa_id       NUMBER;
152303 l_adr_flexfield_segment_code  VARCHAR2(30);
152304 l_adr_flex_value_set_id       NUMBER;
152305 l_adr_value_type_code         VARCHAR2(30);
152306 l_adr_value_combination_id    NUMBER;
152307 l_adr_value_segment_code      VARCHAR2(30);
152308 
152309 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
152310 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
152311 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
152312 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
152313 
152314 -- 4262811 Variables ------------------------------------------------------------------------------------------
152315 l_entered_amt_idx             NUMBER;
152316 l_accted_amt_idx              NUMBER;
152317 l_acc_rev_flag                VARCHAR2(1);
152318 l_accrual_line_num            NUMBER;
152319 l_tmp_amt                     NUMBER;
152320 l_acc_rev_natural_side_code   VARCHAR2(1);
152321 
152322 l_num_entries                 NUMBER;
152323 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
152324 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
152325 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
152326 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
152327 l_recog_line_1                NUMBER;
152328 l_recog_line_2                NUMBER;
152329 
152330 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
152331 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
152332 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
152333 
152334 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
152335 
152336 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
152337 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
152338 
152339 ---------------------------------------------------------------------------------------------------------------
152340 
152341 
152342 --
152343 -- bulk performance
152344 --
152345 l_balance_type_code           VARCHAR2(1);
152346 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
152347 l_log_module                  VARCHAR2(240);
152348 
152349 --
152350 -- Upgrade strategy
152351 --
152352 l_actual_upg_option           VARCHAR2(1);
152353 l_enc_upg_option           VARCHAR2(1);
152354 
152355 --
152356 BEGIN
152357 --
152358 IF g_log_enabled THEN
152359       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_368';
152360 END IF;
152361 --
152362 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
152363 
152364       trace
152365          (p_msg      => 'BEGIN of AcctLineType_368'
152366          ,p_level    => C_LEVEL_PROCEDURE
152367          ,p_module   => l_log_module);
152368 
152369 END IF;
152370 --
152371 l_component_type             := 'AMB_JLT';
152372 l_component_code             := 'FA_TGL_RES';
152373 l_component_type_code        := 'S';
152374 l_component_appl_id          :=  140;
152375 l_amb_context_code           := 'DEFAULT';
152376 l_entity_code                := 'TRANSACTIONS';
152377 l_event_class_code           := 'TERMINAL_GAIN_LOSS';
152378 l_event_type_code            := 'TERMINAL_GAIN_LOSS_ALL';
152379 l_line_definition_owner_code := 'S';
152380 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TERMI24';
152381 --
152382 l_balance_type_code          := 'A';
152383 l_segment                     := NULL;
152384 l_ccid                        := NULL;
152385 l_adr_transaction_coa_id      := NULL;
152386 l_adr_accounting_coa_id       := NULL;
152387 l_adr_flexfield_segment_code  := NULL;
152388 l_adr_flex_value_set_id       := NULL;
152389 l_adr_value_type_code         := NULL;
152390 l_adr_value_combination_id    := NULL;
152391 l_adr_value_segment_code      := NULL;
152392 
152393 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
152394 l_bflow_class_code           := '';    -- 4219869 Business Flow
152395 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
152396 l_budgetary_control_flag     := 'N';
152397 
152398 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
152399 l_bflow_applied_to_amt       := NULL; -- 5132302
152400 l_entered_amt_idx            := NULL;          -- 4262811
152401 l_accted_amt_idx             := NULL;          -- 4262811
152402 l_acc_rev_flag               := NULL;          -- 4262811
152403 l_accrual_line_num           := NULL;          -- 4262811
152407 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
152404 l_tmp_amt                    := NULL;          -- 4262811
152405 --
152406  
152408     l_balance_type_code <> 'B' THEN
152409 IF NVL(p_source_35,'
152410 ') =  'RESERVE'
152411  THEN 
152412 
152413    --
152414    XLA_AE_LINES_PKG.SetNewLine;
152415 
152416    p_balance_type_code          := l_balance_type_code;
152417    -- set the flag so later we will know whether the gain loss line needs to be created
152418    
152419    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
152420      p_actual_flag :='A';
152421    END IF;
152422 
152423    --
152424    -- bulk performance
152425    --
152426    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
152427                                       p_header_num   => 0); -- 4262811
152428    --
152429    -- set accounting line options
152430    --
152431    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
152432            p_natural_side_code          => 'C'
152433          , p_gain_or_loss_flag          => 'N'
152434          , p_gl_transfer_mode_code      => 'S'
152435          , p_acct_entry_type_code       => 'A'
152436          , p_switch_side_flag           => 'Y'
152437          , p_merge_duplicate_code       => 'N'
152438          );
152439    --
152440    l_acc_rev_natural_side_code := 'D';  -- 4262811
152441    -- 
152442    --
152443    -- set accounting line type info
152444    --
152445    xla_ae_lines_pkg.SetAcctLineType
152446       (p_component_type             => l_component_type
152447       ,p_event_type_code            => l_event_type_code
152448       ,p_line_definition_owner_code => l_line_definition_owner_code
152449       ,p_line_definition_code       => l_line_definition_code
152450       ,p_accounting_line_code       => l_component_code
152451       ,p_accounting_line_type_code  => l_component_type_code
152452       ,p_accounting_line_appl_id    => l_component_appl_id
152453       ,p_amb_context_code           => l_amb_context_code
152454       ,p_entity_code                => l_entity_code
152455       ,p_event_class_code           => l_event_class_code);
152456    --
152457    -- set accounting class
152458    --
152459    xla_ae_lines_pkg.SetAcctClass(
152460            p_accounting_class_code  => 'ASSET'
152461          , p_ae_header_id           => l_ae_header_id
152462          );
152463 
152464    --
152465    -- set rounding class
152466    --
152467    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
152468                       'ASSET';
152469 
152470    --
152471    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
152472    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
152473    --
152474    -- bulk performance
152475    --
152476    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
152477 
152478    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
152479       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
152480 
152481    -- 4955764
152482    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
152483       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
152484 
152485    -- 4458381 Public Sector Enh
152486    
152487    --
152488    -- set accounting attributes for the line type
152489    --
152490    l_entered_amt_idx := 4;
152491    l_accted_amt_idx  := 6;
152492    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
152493    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
152494    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
152495    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
152496    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
152497    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
152498    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
152499    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
152500    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
152501    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
152502    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
152503    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
152504    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
152505 
152506    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
152507    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
152508 
152509    ---------------------------------------------------------------------------------------------------------------
152510    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
152511    ---------------------------------------------------------------------------------------------------------------
152512    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
152513 
152514    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
152515    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
152516 
152517    IF xla_accounting_cache_pkg.GetValueChar
152518          (p_source_code         => 'LEDGER_CATEGORY_CODE'
152519          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
152520    AND l_bflow_method_code = 'PRIOR_ENTRY'
152521 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
152522    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
152523          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
152524        )
152525    THEN
152526          xla_ae_lines_pkg.BflowUpgEntry
152530    ELSE
152527            (p_business_method_code    => l_bflow_method_code
152528            ,p_business_class_code     => l_bflow_class_code
152529            ,p_balance_type            => l_balance_type_code);
152531       NULL;
152532 -- No business flow processing for business flow method of NONE.
152533    END IF;
152534 
152535    --
152536    -- call analytical criteria
152537    --
152538    
152539    --
152540    -- call description
152541    --
152542    
152543 xla_ae_lines_pkg.SetLineDescription(
152544    p_ae_header_id => l_ae_header_id
152545   ,p_description  => Description_122 (
152546      p_application_id         => p_application_id
152547    , p_ae_header_id           => l_ae_header_id 
152548 , p_source_1 => p_source_1
152549    )
152550 );
152551 
152552 
152553    --
152554    -- call ADRs
152555    -- Bug 4922099
152556    --
152557    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
152558         (NVL(l_actual_upg_option, 'N') = 'O') OR
152559         (NVL(l_enc_upg_option, 'N') = 'O')
152560       )
152561    THEN
152562    NULL;
152563    --
152564    --
152565    
152566   l_ccid := AcctDerRule_174(
152567            p_application_id           => p_application_id
152568          , p_ae_header_id             => l_ae_header_id 
152569 , p_source_3 => p_source_3
152570 , p_source_17 => p_source_17
152571 , p_source_30 => p_source_30
152572          , x_transaction_coa_id       => l_adr_transaction_coa_id
152573          , x_accounting_coa_id        => l_adr_accounting_coa_id
152574          , x_value_type_code          => l_adr_value_type_code
152575          , p_side                     => 'NA'
152576    );
152577 
152578    xla_ae_lines_pkg.set_ccid(
152579     p_code_combination_id          => l_ccid
152580   , p_value_type_code              => l_adr_value_type_code
152581   , p_transaction_coa_id           => l_adr_transaction_coa_id
152582   , p_accounting_coa_id            => l_adr_accounting_coa_id
152583   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
152584   , p_adr_type_code                => 'S'
152585   , p_component_type               => l_component_type
152586   , p_component_code               => l_component_code
152587   , p_component_type_code          => l_component_type_code
152588   , p_component_appl_id            => l_component_appl_id
152589   , p_amb_context_code             => l_amb_context_code
152590   , p_side                         => 'NA'
152591   );
152592 
152593 
152594    l_segment := AcctDerRule_149(
152595            p_application_id           => p_application_id
152596          , p_ae_header_id             => l_ae_header_id 
152597 , p_source_3 => p_source_3
152598 , p_source_10 => p_source_10
152599          , x_transaction_coa_id       => l_adr_transaction_coa_id
152600          , x_accounting_coa_id        => l_adr_accounting_coa_id
152601          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
152602          , x_flex_value_set_id        => l_adr_flex_value_set_id
152603          , x_value_type_code          => l_adr_value_type_code
152604          , x_value_combination_id     => l_adr_value_combination_id
152605          , x_value_segment_code       => l_adr_value_segment_code
152606          , p_side                     => 'NA'
152607          , p_override_seg_flag        => 'Y'
152608    );
152609 
152610    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
152611 
152612       xla_ae_lines_pkg.set_segment(
152613           p_to_segment_code         => 'GL_ACCOUNT'
152614         , p_segment_value           => l_segment
152615         , p_from_segment_code       => l_adr_value_segment_code
152616         , p_from_combination_id     => l_adr_value_combination_id
152617         , p_value_type_code         => l_adr_value_type_code
152618         , p_transaction_coa_id      => l_adr_transaction_coa_id
152619         , p_accounting_coa_id       => l_adr_accounting_coa_id
152620         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
152621         , p_flex_value_set_id       => l_adr_flex_value_set_id
152622         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
152623         , p_adr_type_code           => 'S'
152624         , p_component_type          => l_component_type
152625         , p_component_code          => l_component_code
152626         , p_component_type_code     => l_component_type_code
152627         , p_component_appl_id       => l_component_appl_id
152628         , p_amb_context_code        => l_amb_context_code
152629         , p_entity_code             => 'TRANSACTIONS'
152630         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
152631         , p_side                    => 'NA'
152632         );
152633 
152634   END IF;
152635 
152636    l_segment := AcctDerRule_168(
152637            p_application_id           => p_application_id
152638          , p_ae_header_id             => l_ae_header_id 
152639 , p_source_3 => p_source_3
152640 , p_source_29 => p_source_29
152641          , x_transaction_coa_id       => l_adr_transaction_coa_id
152642          , x_accounting_coa_id        => l_adr_accounting_coa_id
152643          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
152644          , x_flex_value_set_id        => l_adr_flex_value_set_id
152645          , x_value_type_code          => l_adr_value_type_code
152646          , x_value_combination_id     => l_adr_value_combination_id
152647          , x_value_segment_code       => l_adr_value_segment_code
152648          , p_side                     => 'NA'
152649          , p_override_seg_flag        => 'Y'
152650    );
152651 
152652    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
152653 
152654       xla_ae_lines_pkg.set_segment(
152655           p_to_segment_code         => 'GL_BALANCING'
152656         , p_segment_value           => l_segment
152657         , p_from_segment_code       => l_adr_value_segment_code
152658         , p_from_combination_id     => l_adr_value_combination_id
152662         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
152659         , p_value_type_code         => l_adr_value_type_code
152660         , p_transaction_coa_id      => l_adr_transaction_coa_id
152661         , p_accounting_coa_id       => l_adr_accounting_coa_id
152663         , p_flex_value_set_id       => l_adr_flex_value_set_id
152664         , p_adr_code                => 'FA_EXPENSE_ACCT'
152665         , p_adr_type_code           => 'S'
152666         , p_component_type          => l_component_type
152667         , p_component_code          => l_component_code
152668         , p_component_type_code     => l_component_type_code
152669         , p_component_appl_id       => l_component_appl_id
152670         , p_amb_context_code        => l_amb_context_code
152671         , p_entity_code             => 'TRANSACTIONS'
152672         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
152673         , p_side                    => 'NA'
152674         );
152675 
152676   END IF;
152677 
152678    --
152679    --
152680    END IF;
152681    --
152682    -- Bug 4922099
152683    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
152684           (NVL(l_enc_upg_option, 'N') = 'O')
152685         ) AND
152686         (l_bflow_method_code = 'PRIOR_ENTRY')
152687       )
152688    THEN
152689       IF
152690       --
152691       1 = 2
152692       --
152693       THEN
152694       xla_accounting_err_pkg.build_message
152695                                     (p_appli_s_name            => 'XLA'
152696                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
152697                                     ,p_token_1                 => 'LINE_NUMBER'
152698                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
152699                                     ,p_token_2                 => 'LINE_TYPE_NAME'
152700                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
152701                                                                              l_component_type
152702                                                                             ,l_component_code
152703                                                                             ,l_component_type_code
152704                                                                             ,l_component_appl_id
152705                                                                             ,l_amb_context_code
152706                                                                             ,l_entity_code
152707                                                                             ,l_event_class_code
152708                                                                            )
152709                                     ,p_token_3                 => 'OWNER'
152710                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
152711                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
152712                                                                           ,p_lookup_code    => l_component_type_code
152713                                                                          )
152714                                     ,p_token_4                 => 'PRODUCT_NAME'
152715                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
152716                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
152717                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
152718                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
152719                                     ,p_ae_header_id            =>  NULL
152720                                        );
152721 
152722         IF (C_LEVEL_ERROR>= g_log_level) THEN
152723                  trace
152724                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
152725                       ,p_level    => C_LEVEL_ERROR
152726                       ,p_module   => l_log_module);
152727         END IF;
152728       END IF;
152729    END IF;
152730    --
152731    --
152732    ------------------------------------------------------------------------------------------------
152733    -- 4219869 Business Flow
152734    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
152735    -- Prior Entry.  Currently, the following code is always generated.
152736    ------------------------------------------------------------------------------------------------
152737    XLA_AE_LINES_PKG.ValidateCurrentLine;
152738 
152739    ------------------------------------------------------------------------------------
152740    -- 4219869 Business Flow
152741    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
152742    ------------------------------------------------------------------------------------
152743    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
152744 
152745    ----------------------------------------------------------------------------------
152746    -- 4219869 Business Flow
152747    -- Update journal entry status -- Need to generate this within IF <condition>
152748    ----------------------------------------------------------------------------------
152749    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
152750          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
152751          ,p_balance_type_code => l_balance_type_code
152752          );
152753 
152754    -------------------------------------------------------------------------------------------
152755    -- 4262811 - Generate the Accrual Reversal lines
152756    -------------------------------------------------------------------------------------------
152757    BEGIN
152758       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
152759                               (g_array_event(p_event_id).array_value_num('header_index'));
152760       IF l_acc_rev_flag IS NULL THEN
152764       WHEN OTHERS THEN
152761          l_acc_rev_flag := 'N';
152762       END IF;
152763    EXCEPTION
152765          l_acc_rev_flag := 'N';
152766    END;
152767    --
152768    IF (l_acc_rev_flag = 'Y') THEN
152769 
152770        -- 4645092  ------------------------------------------------------------------------------
152771        -- To allow MPA report to determine if it should generate report process
152772        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
152773        ------------------------------------------------------------------------------------------
152774 
152775        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
152776        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
152777    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
152778    -- call ADRs
152779    -- Bug 4922099
152780    --
152781    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
152782         (NVL(l_actual_upg_option, 'N') = 'O') OR
152783         (NVL(l_enc_upg_option, 'N') = 'O')
152784       )
152785    THEN
152786    NULL;
152787    --
152788    --
152789    
152790   l_ccid := AcctDerRule_174(
152791            p_application_id           => p_application_id
152792          , p_ae_header_id             => l_ae_header_id 
152793 , p_source_3 => p_source_3
152794 , p_source_17 => p_source_17
152795 , p_source_30 => p_source_30
152796          , x_transaction_coa_id       => l_adr_transaction_coa_id
152797          , x_accounting_coa_id        => l_adr_accounting_coa_id
152798          , x_value_type_code          => l_adr_value_type_code
152799          , p_side                     => 'NA'
152800    );
152801 
152802    xla_ae_lines_pkg.set_ccid(
152803     p_code_combination_id          => l_ccid
152804   , p_value_type_code              => l_adr_value_type_code
152805   , p_transaction_coa_id           => l_adr_transaction_coa_id
152806   , p_accounting_coa_id            => l_adr_accounting_coa_id
152807   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
152808   , p_adr_type_code                => 'S'
152809   , p_component_type               => l_component_type
152810   , p_component_code               => l_component_code
152811   , p_component_type_code          => l_component_type_code
152812   , p_component_appl_id            => l_component_appl_id
152813   , p_amb_context_code             => l_amb_context_code
152814   , p_side                         => 'NA'
152815   );
152816 
152817 
152818    l_segment := AcctDerRule_149(
152819            p_application_id           => p_application_id
152820          , p_ae_header_id             => l_ae_header_id 
152821 , p_source_3 => p_source_3
152822 , p_source_10 => p_source_10
152823          , x_transaction_coa_id       => l_adr_transaction_coa_id
152824          , x_accounting_coa_id        => l_adr_accounting_coa_id
152825          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
152826          , x_flex_value_set_id        => l_adr_flex_value_set_id
152827          , x_value_type_code          => l_adr_value_type_code
152828          , x_value_combination_id     => l_adr_value_combination_id
152829          , x_value_segment_code       => l_adr_value_segment_code
152830          , p_side                     => 'NA'
152831          , p_override_seg_flag        => 'Y'
152832    );
152833 
152834    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
152835 
152836       xla_ae_lines_pkg.set_segment(
152837           p_to_segment_code         => 'GL_ACCOUNT'
152838         , p_segment_value           => l_segment
152839         , p_from_segment_code       => l_adr_value_segment_code
152840         , p_from_combination_id     => l_adr_value_combination_id
152841         , p_value_type_code         => l_adr_value_type_code
152842         , p_transaction_coa_id      => l_adr_transaction_coa_id
152843         , p_accounting_coa_id       => l_adr_accounting_coa_id
152844         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
152845         , p_flex_value_set_id       => l_adr_flex_value_set_id
152846         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
152847         , p_adr_type_code           => 'S'
152848         , p_component_type          => l_component_type
152849         , p_component_code          => l_component_code
152850         , p_component_type_code     => l_component_type_code
152851         , p_component_appl_id       => l_component_appl_id
152852         , p_amb_context_code        => l_amb_context_code
152853         , p_entity_code             => 'TRANSACTIONS'
152854         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
152855         , p_side                    => 'NA'
152856         );
152857 
152858   END IF;
152859 
152860    l_segment := AcctDerRule_168(
152861            p_application_id           => p_application_id
152862          , p_ae_header_id             => l_ae_header_id 
152863 , p_source_3 => p_source_3
152864 , p_source_29 => p_source_29
152865          , x_transaction_coa_id       => l_adr_transaction_coa_id
152866          , x_accounting_coa_id        => l_adr_accounting_coa_id
152867          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
152868          , x_flex_value_set_id        => l_adr_flex_value_set_id
152869          , x_value_type_code          => l_adr_value_type_code
152870          , x_value_combination_id     => l_adr_value_combination_id
152871          , x_value_segment_code       => l_adr_value_segment_code
152872          , p_side                     => 'NA'
152873          , p_override_seg_flag        => 'Y'
152874    );
152875 
152876    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
152877 
152878       xla_ae_lines_pkg.set_segment(
152879           p_to_segment_code         => 'GL_BALANCING'
152880         , p_segment_value           => l_segment
152881         , p_from_segment_code       => l_adr_value_segment_code
152882         , p_from_combination_id     => l_adr_value_combination_id
152883         , p_value_type_code         => l_adr_value_type_code
152887         , p_flex_value_set_id       => l_adr_flex_value_set_id
152884         , p_transaction_coa_id      => l_adr_transaction_coa_id
152885         , p_accounting_coa_id       => l_adr_accounting_coa_id
152886         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
152888         , p_adr_code                => 'FA_EXPENSE_ACCT'
152889         , p_adr_type_code           => 'S'
152890         , p_component_type          => l_component_type
152891         , p_component_code          => l_component_code
152892         , p_component_type_code     => l_component_type_code
152893         , p_component_appl_id       => l_component_appl_id
152894         , p_amb_context_code        => l_amb_context_code
152895         , p_entity_code             => 'TRANSACTIONS'
152896         , p_event_class_code        => 'TERMINAL_GAIN_LOSS'
152897         , p_side                    => 'NA'
152898         );
152899 
152900   END IF;
152901 
152902    --
152903    --
152904    END IF;
152905 
152906        --
152907        -- Update the line information that should be overwritten
152908        --
152909        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
152910                                          p_header_num   => 1);
152911        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
152912 
152913        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
152914 
152915        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
152916           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
152917        END IF;
152918 
152919       --
152920       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
152921       --
152922       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
152923           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
152924       ELSE
152925           ---------------------------------------------------------------------------------------------------
152926           -- 4262811a Switch Sign
152927           ---------------------------------------------------------------------------------------------------
152928           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
152929           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
152930                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
152931           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
152932                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
152933           -- 5132302
152934           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
152935                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
152936 
152937       END IF;
152938 
152939       -- 4955764
152940       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
152941       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
152942 
152943 
152944       XLA_AE_LINES_PKG.ValidateCurrentLine;
152945       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
152946 
152947       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
152948                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
152949                ,p_balance_type_code => l_balance_type_code);
152950 
152951    END IF;
152952 
152953    -----------------------------------------------------------------------------------------
152954    -- 4262811 Multiperiod Accounting
152955    -----------------------------------------------------------------------------------------
152956      -- No MPA option is assigned.
152957 
152958 
152959 END IF;
152960 END IF;
152961 --
152962 
152963 --
152964 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
152965    trace
152966       (p_msg      => 'END of AcctLineType_368'
152967       ,p_level    => C_LEVEL_PROCEDURE
152968       ,p_module   => l_log_module);
152969 END IF;
152970 --
152971 EXCEPTION
152972   WHEN xla_exceptions_pkg.application_exception THEN
152973       RAISE;
152974   WHEN OTHERS THEN
152975        xla_exceptions_pkg.raise_message
152976            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_368');
152977 END AcctLineType_368;
152978 --
152979 
152980 ---------------------------------------
152981 --
152982 -- PRIVATE FUNCTION
152983 --         AcctLineType_369
152984 --
152985 ---------------------------------------
152986 PROCEDURE AcctLineType_369 (
152987   p_application_id        IN NUMBER
152988  ,p_event_id              IN NUMBER
152989  ,p_calculate_acctd_flag  IN VARCHAR2
152990  ,p_calculate_g_l_flag    IN VARCHAR2
152991  ,p_actual_flag           IN OUT VARCHAR2
152992  ,p_balance_type_code     OUT VARCHAR2
152993  ,p_gain_or_loss_ref      OUT VARCHAR2
152994  
152995 --Period Close Date
152996  , p_source_1            IN DATE
152997 --Bonus Depreciation Expense Account
152998  , p_source_2            IN VARCHAR2
152999 --Generated Code Combination Identifier
153000  , p_source_3            IN NUMBER
153001 --Expense Account Code Combination Identifier
153002  , p_source_29            IN NUMBER
153003 --Adjustment Type
153004  , p_source_35            IN VARCHAR2
153005 --Transaction Header Identifier
153006  , p_source_36            IN NUMBER
153007 --Adjustment Line Identifier
153008  , p_source_37            IN NUMBER
153009 --Distribution Type Code
153010  , p_source_38            IN VARCHAR2
153011 --Entered Amount
153012  , p_source_39            IN NUMBER
153013 --Currency Code
153014  , p_source_40            IN VARCHAR2
153018 IS
153015 --Source Destination Code
153016  , p_source_42            IN VARCHAR2
153017 )
153019 
153020 l_component_type              VARCHAR2(80);
153021 l_component_code              VARCHAR2(30);
153022 l_component_type_code         VARCHAR2(1);
153023 l_component_appl_id           INTEGER;
153024 l_amb_context_code            VARCHAR2(30);
153025 l_entity_code                 VARCHAR2(30);
153026 l_event_class_code            VARCHAR2(30);
153027 l_ae_header_id                NUMBER;
153028 l_event_type_code             VARCHAR2(30);
153029 l_line_definition_code        VARCHAR2(30);
153030 l_line_definition_owner_code  VARCHAR2(1);
153031 --
153032 -- adr variables
153033 l_segment                     VARCHAR2(30);
153034 l_ccid                        NUMBER;
153035 l_adr_transaction_coa_id      NUMBER;
153036 l_adr_accounting_coa_id       NUMBER;
153037 l_adr_flexfield_segment_code  VARCHAR2(30);
153038 l_adr_flex_value_set_id       NUMBER;
153039 l_adr_value_type_code         VARCHAR2(30);
153040 l_adr_value_combination_id    NUMBER;
153041 l_adr_value_segment_code      VARCHAR2(30);
153042 
153043 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
153044 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
153045 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
153046 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
153047 
153048 -- 4262811 Variables ------------------------------------------------------------------------------------------
153049 l_entered_amt_idx             NUMBER;
153050 l_accted_amt_idx              NUMBER;
153051 l_acc_rev_flag                VARCHAR2(1);
153052 l_accrual_line_num            NUMBER;
153053 l_tmp_amt                     NUMBER;
153054 l_acc_rev_natural_side_code   VARCHAR2(1);
153055 
153056 l_num_entries                 NUMBER;
153057 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
153058 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
153059 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
153060 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
153061 l_recog_line_1                NUMBER;
153062 l_recog_line_2                NUMBER;
153063 
153064 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
153065 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
153066 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
153067 
153068 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
153069 
153070 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
153071 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
153072 
153073 ---------------------------------------------------------------------------------------------------------------
153074 
153075 
153076 --
153077 -- bulk performance
153078 --
153079 l_balance_type_code           VARCHAR2(1);
153080 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
153081 l_log_module                  VARCHAR2(240);
153082 
153083 --
153084 -- Upgrade strategy
153085 --
153086 l_actual_upg_option           VARCHAR2(1);
153087 l_enc_upg_option           VARCHAR2(1);
153088 
153089 --
153090 BEGIN
153091 --
153092 IF g_log_enabled THEN
153093       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_369';
153094 END IF;
153095 --
153096 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
153097 
153098       trace
153099          (p_msg      => 'BEGIN of AcctLineType_369'
153100          ,p_level    => C_LEVEL_PROCEDURE
153101          ,p_module   => l_log_module);
153102 
153103 END IF;
153104 --
153105 l_component_type             := 'AMB_JLT';
153106 l_component_code             := 'FA_TRANSFER_DEST_BONUS_EXP';
153107 l_component_type_code        := 'S';
153108 l_component_appl_id          :=  140;
153109 l_amb_context_code           := 'DEFAULT';
153110 l_entity_code                := 'TRANSACTIONS';
153111 l_event_class_code           := 'TRANSFERS';
153112 l_event_type_code            := 'TRANSFERS_ALL';
153113 l_line_definition_owner_code := 'S';
153114 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
153115 --
153116 l_balance_type_code          := 'A';
153117 l_segment                     := NULL;
153118 l_ccid                        := NULL;
153119 l_adr_transaction_coa_id      := NULL;
153120 l_adr_accounting_coa_id       := NULL;
153121 l_adr_flexfield_segment_code  := NULL;
153122 l_adr_flex_value_set_id       := NULL;
153123 l_adr_value_type_code         := NULL;
153124 l_adr_value_combination_id    := NULL;
153125 l_adr_value_segment_code      := NULL;
153126 
153127 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
153128 l_bflow_class_code           := '';    -- 4219869 Business Flow
153129 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
153130 l_budgetary_control_flag     := 'N';
153131 
153132 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
153133 l_bflow_applied_to_amt       := NULL; -- 5132302
153134 l_entered_amt_idx            := NULL;          -- 4262811
153135 l_accted_amt_idx             := NULL;          -- 4262811
153136 l_acc_rev_flag               := NULL;          -- 4262811
153137 l_accrual_line_num           := NULL;          -- 4262811
153138 l_tmp_amt                    := NULL;          -- 4262811
153139 --
153140  
153141 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
153142     l_balance_type_code <> 'B' THEN
153143 IF NVL(p_source_35,'
153144 ') =  'BONUS EXPENSE' AND 
153145 NVL(p_source_42,'
153146 ') =  'DEST'
153147  THEN 
153148 
153149    --
153150    XLA_AE_LINES_PKG.SetNewLine;
153151 
153152    p_balance_type_code          := l_balance_type_code;
153156      p_actual_flag :='A';
153153    -- set the flag so later we will know whether the gain loss line needs to be created
153154    
153155    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
153157    END IF;
153158 
153159    --
153160    -- bulk performance
153161    --
153162    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
153163                                       p_header_num   => 0); -- 4262811
153164    --
153165    -- set accounting line options
153166    --
153167    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
153168            p_natural_side_code          => 'D'
153169          , p_gain_or_loss_flag          => 'N'
153170          , p_gl_transfer_mode_code      => 'S'
153171          , p_acct_entry_type_code       => 'A'
153172          , p_switch_side_flag           => 'Y'
153173          , p_merge_duplicate_code       => 'N'
153174          );
153175    --
153176    l_acc_rev_natural_side_code := 'C';  -- 4262811
153177    -- 
153178    --
153179    -- set accounting line type info
153180    --
153181    xla_ae_lines_pkg.SetAcctLineType
153182       (p_component_type             => l_component_type
153183       ,p_event_type_code            => l_event_type_code
153184       ,p_line_definition_owner_code => l_line_definition_owner_code
153185       ,p_line_definition_code       => l_line_definition_code
153186       ,p_accounting_line_code       => l_component_code
153187       ,p_accounting_line_type_code  => l_component_type_code
153188       ,p_accounting_line_appl_id    => l_component_appl_id
153189       ,p_amb_context_code           => l_amb_context_code
153190       ,p_entity_code                => l_entity_code
153191       ,p_event_class_code           => l_event_class_code);
153192    --
153193    -- set accounting class
153194    --
153195    xla_ae_lines_pkg.SetAcctClass(
153196            p_accounting_class_code  => 'EXPENSE'
153197          , p_ae_header_id           => l_ae_header_id
153198          );
153199 
153200    --
153201    -- set rounding class
153202    --
153203    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
153204                       'EXPENSE';
153205 
153206    --
153207    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
153208    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
153209    --
153210    -- bulk performance
153211    --
153212    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
153213 
153214    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
153215       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
153216 
153217    -- 4955764
153218    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
153219       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
153220 
153221    -- 4458381 Public Sector Enh
153222    
153223    --
153224    -- set accounting attributes for the line type
153225    --
153226    l_entered_amt_idx := 4;
153227    l_accted_amt_idx  := 6;
153228    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
153229    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
153230    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
153231    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
153232    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
153233    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
153234    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
153235    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
153236    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
153237    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
153238    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
153239    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
153240    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
153241 
153242    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
153243    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
153244 
153245    ---------------------------------------------------------------------------------------------------------------
153246    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
153247    ---------------------------------------------------------------------------------------------------------------
153248    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
153249 
153250    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
153251    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
153252 
153253    IF xla_accounting_cache_pkg.GetValueChar
153254          (p_source_code         => 'LEDGER_CATEGORY_CODE'
153255          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
153256    AND l_bflow_method_code = 'PRIOR_ENTRY'
153257 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
153258    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
153259          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
153260        )
153261    THEN
153262          xla_ae_lines_pkg.BflowUpgEntry
153263            (p_business_method_code    => l_bflow_method_code
153264            ,p_business_class_code     => l_bflow_class_code
153265            ,p_balance_type            => l_balance_type_code);
153266    ELSE
153267       NULL;
153268 -- No business flow processing for business flow method of NONE.
153269    END IF;
153270 
153271    --
153272    -- call analytical criteria
153273    --
153274    
153275    --
153276    -- call description
153277    --
153281   ,p_description  => Description_124 (
153278    
153279 xla_ae_lines_pkg.SetLineDescription(
153280    p_ae_header_id => l_ae_header_id
153282      p_application_id         => p_application_id
153283    , p_ae_header_id           => l_ae_header_id 
153284 , p_source_1 => p_source_1
153285    )
153286 );
153287 
153288 
153289    --
153290    -- call ADRs
153291    -- Bug 4922099
153292    --
153293    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
153294         (NVL(l_actual_upg_option, 'N') = 'O') OR
153295         (NVL(l_enc_upg_option, 'N') = 'O')
153296       )
153297    THEN
153298    NULL;
153299    --
153300    --
153301    
153302   l_ccid := AcctDerRule_175(
153303            p_application_id           => p_application_id
153304          , p_ae_header_id             => l_ae_header_id 
153305 , p_source_3 => p_source_3
153306 , p_source_29 => p_source_29
153307          , x_transaction_coa_id       => l_adr_transaction_coa_id
153308          , x_accounting_coa_id        => l_adr_accounting_coa_id
153309          , x_value_type_code          => l_adr_value_type_code
153310          , p_side                     => 'NA'
153311    );
153312 
153313    xla_ae_lines_pkg.set_ccid(
153314     p_code_combination_id          => l_ccid
153315   , p_value_type_code              => l_adr_value_type_code
153316   , p_transaction_coa_id           => l_adr_transaction_coa_id
153317   , p_accounting_coa_id            => l_adr_accounting_coa_id
153318   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
153319   , p_adr_type_code                => 'S'
153320   , p_component_type               => l_component_type
153321   , p_component_code               => l_component_code
153322   , p_component_type_code          => l_component_type_code
153323   , p_component_appl_id            => l_component_appl_id
153324   , p_amb_context_code             => l_amb_context_code
153325   , p_side                         => 'NA'
153326   );
153327 
153328 
153329    l_segment := AcctDerRule_143(
153330            p_application_id           => p_application_id
153331          , p_ae_header_id             => l_ae_header_id 
153332 , p_source_2 => p_source_2
153333 , p_source_3 => p_source_3
153334          , x_transaction_coa_id       => l_adr_transaction_coa_id
153335          , x_accounting_coa_id        => l_adr_accounting_coa_id
153336          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
153337          , x_flex_value_set_id        => l_adr_flex_value_set_id
153338          , x_value_type_code          => l_adr_value_type_code
153339          , x_value_combination_id     => l_adr_value_combination_id
153340          , x_value_segment_code       => l_adr_value_segment_code
153341          , p_side                     => 'NA'
153342          , p_override_seg_flag        => 'Y'
153343    );
153344 
153345    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
153346 
153347       xla_ae_lines_pkg.set_segment(
153348           p_to_segment_code         => 'GL_ACCOUNT'
153349         , p_segment_value           => l_segment
153350         , p_from_segment_code       => l_adr_value_segment_code
153351         , p_from_combination_id     => l_adr_value_combination_id
153352         , p_value_type_code         => l_adr_value_type_code
153353         , p_transaction_coa_id      => l_adr_transaction_coa_id
153354         , p_accounting_coa_id       => l_adr_accounting_coa_id
153355         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
153356         , p_flex_value_set_id       => l_adr_flex_value_set_id
153357         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
153358         , p_adr_type_code           => 'S'
153359         , p_component_type          => l_component_type
153360         , p_component_code          => l_component_code
153361         , p_component_type_code     => l_component_type_code
153362         , p_component_appl_id       => l_component_appl_id
153363         , p_amb_context_code        => l_amb_context_code
153364         , p_entity_code             => 'TRANSACTIONS'
153365         , p_event_class_code        => 'TRANSFERS'
153366         , p_side                    => 'NA'
153367         );
153368 
153369   END IF;
153370 
153371    --
153372    --
153373    END IF;
153374    --
153375    -- Bug 4922099
153376    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
153377           (NVL(l_enc_upg_option, 'N') = 'O')
153378         ) AND
153379         (l_bflow_method_code = 'PRIOR_ENTRY')
153380       )
153381    THEN
153382       IF
153383       --
153384       1 = 2
153385       --
153386       THEN
153387       xla_accounting_err_pkg.build_message
153388                                     (p_appli_s_name            => 'XLA'
153389                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
153390                                     ,p_token_1                 => 'LINE_NUMBER'
153391                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
153392                                     ,p_token_2                 => 'LINE_TYPE_NAME'
153393                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
153394                                                                              l_component_type
153395                                                                             ,l_component_code
153396                                                                             ,l_component_type_code
153397                                                                             ,l_component_appl_id
153398                                                                             ,l_amb_context_code
153399                                                                             ,l_entity_code
153400                                                                             ,l_event_class_code
153401                                                                            )
153402                                     ,p_token_3                 => 'OWNER'
153406                                                                          )
153403                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
153404                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
153405                                                                           ,p_lookup_code    => l_component_type_code
153407                                     ,p_token_4                 => 'PRODUCT_NAME'
153408                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
153409                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
153410                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
153411                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
153412                                     ,p_ae_header_id            =>  NULL
153413                                        );
153414 
153415         IF (C_LEVEL_ERROR>= g_log_level) THEN
153416                  trace
153417                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
153418                       ,p_level    => C_LEVEL_ERROR
153419                       ,p_module   => l_log_module);
153420         END IF;
153421       END IF;
153422    END IF;
153423    --
153424    --
153425    ------------------------------------------------------------------------------------------------
153426    -- 4219869 Business Flow
153427    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
153428    -- Prior Entry.  Currently, the following code is always generated.
153429    ------------------------------------------------------------------------------------------------
153430    XLA_AE_LINES_PKG.ValidateCurrentLine;
153431 
153432    ------------------------------------------------------------------------------------
153433    -- 4219869 Business Flow
153434    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
153435    ------------------------------------------------------------------------------------
153436    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
153437 
153438    ----------------------------------------------------------------------------------
153439    -- 4219869 Business Flow
153440    -- Update journal entry status -- Need to generate this within IF <condition>
153441    ----------------------------------------------------------------------------------
153442    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
153443          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
153447    -------------------------------------------------------------------------------------------
153444          ,p_balance_type_code => l_balance_type_code
153445          );
153446 
153448    -- 4262811 - Generate the Accrual Reversal lines
153449    -------------------------------------------------------------------------------------------
153450    BEGIN
153451       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
153452                               (g_array_event(p_event_id).array_value_num('header_index'));
153453       IF l_acc_rev_flag IS NULL THEN
153454          l_acc_rev_flag := 'N';
153455       END IF;
153456    EXCEPTION
153457       WHEN OTHERS THEN
153458          l_acc_rev_flag := 'N';
153459    END;
153460    --
153461    IF (l_acc_rev_flag = 'Y') THEN
153462 
153463        -- 4645092  ------------------------------------------------------------------------------
153464        -- To allow MPA report to determine if it should generate report process
153465        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
153466        ------------------------------------------------------------------------------------------
153467 
153468        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
153469        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
153470    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
153471    -- call ADRs
153472    -- Bug 4922099
153473    --
153474    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
153475         (NVL(l_actual_upg_option, 'N') = 'O') OR
153476         (NVL(l_enc_upg_option, 'N') = 'O')
153477       )
153478    THEN
153479    NULL;
153480    --
153481    --
153482    
153483   l_ccid := AcctDerRule_175(
153484            p_application_id           => p_application_id
153485          , p_ae_header_id             => l_ae_header_id 
153486 , p_source_3 => p_source_3
153487 , p_source_29 => p_source_29
153488          , x_transaction_coa_id       => l_adr_transaction_coa_id
153489          , x_accounting_coa_id        => l_adr_accounting_coa_id
153490          , x_value_type_code          => l_adr_value_type_code
153491          , p_side                     => 'NA'
153492    );
153493 
153494    xla_ae_lines_pkg.set_ccid(
153498   , p_accounting_coa_id            => l_adr_accounting_coa_id
153495     p_code_combination_id          => l_ccid
153496   , p_value_type_code              => l_adr_value_type_code
153497   , p_transaction_coa_id           => l_adr_transaction_coa_id
153499   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
153500   , p_adr_type_code                => 'S'
153501   , p_component_type               => l_component_type
153502   , p_component_code               => l_component_code
153503   , p_component_type_code          => l_component_type_code
153504   , p_component_appl_id            => l_component_appl_id
153505   , p_amb_context_code             => l_amb_context_code
153506   , p_side                         => 'NA'
153507   );
153508 
153509 
153510    l_segment := AcctDerRule_143(
153511            p_application_id           => p_application_id
153512          , p_ae_header_id             => l_ae_header_id 
153513 , p_source_2 => p_source_2
153514 , p_source_3 => p_source_3
153515          , x_transaction_coa_id       => l_adr_transaction_coa_id
153516          , x_accounting_coa_id        => l_adr_accounting_coa_id
153517          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
153518          , x_flex_value_set_id        => l_adr_flex_value_set_id
153519          , x_value_type_code          => l_adr_value_type_code
153520          , x_value_combination_id     => l_adr_value_combination_id
153521          , x_value_segment_code       => l_adr_value_segment_code
153522          , p_side                     => 'NA'
153523          , p_override_seg_flag        => 'Y'
153524    );
153525 
153526    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
153527 
153528       xla_ae_lines_pkg.set_segment(
153529           p_to_segment_code         => 'GL_ACCOUNT'
153530         , p_segment_value           => l_segment
153531         , p_from_segment_code       => l_adr_value_segment_code
153532         , p_from_combination_id     => l_adr_value_combination_id
153533         , p_value_type_code         => l_adr_value_type_code
153534         , p_transaction_coa_id      => l_adr_transaction_coa_id
153535         , p_accounting_coa_id       => l_adr_accounting_coa_id
153536         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
153537         , p_flex_value_set_id       => l_adr_flex_value_set_id
153538         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
153539         , p_adr_type_code           => 'S'
153540         , p_component_type          => l_component_type
153541         , p_component_code          => l_component_code
153542         , p_component_type_code     => l_component_type_code
153543         , p_component_appl_id       => l_component_appl_id
153544         , p_amb_context_code        => l_amb_context_code
153545         , p_entity_code             => 'TRANSACTIONS'
153546         , p_event_class_code        => 'TRANSFERS'
153547         , p_side                    => 'NA'
153548         );
153549 
153550   END IF;
153551 
153552    --
153553    --
153554    END IF;
153555 
153556        --
153557        -- Update the line information that should be overwritten
153558        --
153559        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
153560                                          p_header_num   => 1);
153561        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
153562 
153563        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
153564 
153565        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
153566           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
153567        END IF;
153568 
153569       --
153570       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
153571       --
153572       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
153573           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
153574       ELSE
153575           ---------------------------------------------------------------------------------------------------
153576           -- 4262811a Switch Sign
153577           ---------------------------------------------------------------------------------------------------
153578           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
153579           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
153580                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
153581           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
153582                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
153583           -- 5132302
153584           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
153585                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
153586 
153587       END IF;
153588 
153589       -- 4955764
153590       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
153591       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
153592 
153593 
153594       XLA_AE_LINES_PKG.ValidateCurrentLine;
153595       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
153596 
153597       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
153598                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
153599                ,p_balance_type_code => l_balance_type_code);
153600 
153601    END IF;
153602 
153603    -----------------------------------------------------------------------------------------
153604    -- 4262811 Multiperiod Accounting
153605    -----------------------------------------------------------------------------------------
153606      -- No MPA option is assigned.
153610 END IF;
153607 
153608 
153609 END IF;
153611 --
153612 
153613 --
153614 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
153615    trace
153616       (p_msg      => 'END of AcctLineType_369'
153617       ,p_level    => C_LEVEL_PROCEDURE
153618       ,p_module   => l_log_module);
153619 END IF;
153620 --
153621 EXCEPTION
153622   WHEN xla_exceptions_pkg.application_exception THEN
153623       RAISE;
153624   WHEN OTHERS THEN
153625        xla_exceptions_pkg.raise_message
153626            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_369');
153627 END AcctLineType_369;
153628 --
153629 
153630 ---------------------------------------
153631 --
153632 -- PRIVATE FUNCTION
153633 --         AcctLineType_370
153634 --
153635 ---------------------------------------
153636 PROCEDURE AcctLineType_370 (
153637   p_application_id        IN NUMBER
153638  ,p_event_id              IN NUMBER
153639  ,p_calculate_acctd_flag  IN VARCHAR2
153640  ,p_calculate_g_l_flag    IN VARCHAR2
153641  ,p_actual_flag           IN OUT VARCHAR2
153642  ,p_balance_type_code     OUT VARCHAR2
153643  ,p_gain_or_loss_ref      OUT VARCHAR2
153644  
153645 --Period Close Date
153646  , p_source_1            IN DATE
153647 --Generated Code Combination Identifier
153648  , p_source_3            IN NUMBER
153649 --Bonus Reserve Account
153650  , p_source_4            IN VARCHAR2
153651 --Generated Offset Code Combination Identifier
153652  , p_source_17            IN NUMBER
153653 --Expense Account Code Combination Identifier
153654  , p_source_29            IN NUMBER
153655 --Default Code Combination Identifier
153656  , p_source_30            IN NUMBER
153657 --Adjustment Type
153658  , p_source_35            IN VARCHAR2
153659 --Transaction Header Identifier
153660  , p_source_36            IN NUMBER
153661 --Adjustment Line Identifier
153662  , p_source_37            IN NUMBER
153663 --Distribution Type Code
153664  , p_source_38            IN VARCHAR2
153665 --Entered Amount
153666  , p_source_39            IN NUMBER
153667 --Currency Code
153668  , p_source_40            IN VARCHAR2
153669 --Source Destination Code
153670  , p_source_42            IN VARCHAR2
153671 )
153672 IS
153673 
153674 l_component_type              VARCHAR2(80);
153675 l_component_code              VARCHAR2(30);
153676 l_component_type_code         VARCHAR2(1);
153677 l_component_appl_id           INTEGER;
153678 l_amb_context_code            VARCHAR2(30);
153679 l_entity_code                 VARCHAR2(30);
153680 l_event_class_code            VARCHAR2(30);
153681 l_ae_header_id                NUMBER;
153682 l_event_type_code             VARCHAR2(30);
153683 l_line_definition_code        VARCHAR2(30);
153684 l_line_definition_owner_code  VARCHAR2(1);
153685 --
153686 -- adr variables
153687 l_segment                     VARCHAR2(30);
153688 l_ccid                        NUMBER;
153689 l_adr_transaction_coa_id      NUMBER;
153690 l_adr_accounting_coa_id       NUMBER;
153691 l_adr_flexfield_segment_code  VARCHAR2(30);
153692 l_adr_flex_value_set_id       NUMBER;
153693 l_adr_value_type_code         VARCHAR2(30);
153694 l_adr_value_combination_id    NUMBER;
153695 l_adr_value_segment_code      VARCHAR2(30);
153696 
153697 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
153698 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
153699 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
153700 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
153701 
153702 -- 4262811 Variables ------------------------------------------------------------------------------------------
153703 l_entered_amt_idx             NUMBER;
153704 l_accted_amt_idx              NUMBER;
153705 l_acc_rev_flag                VARCHAR2(1);
153706 l_accrual_line_num            NUMBER;
153707 l_tmp_amt                     NUMBER;
153708 l_acc_rev_natural_side_code   VARCHAR2(1);
153709 
153710 l_num_entries                 NUMBER;
153711 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
153712 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
153713 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
153714 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
153715 l_recog_line_1                NUMBER;
153716 l_recog_line_2                NUMBER;
153717 
153718 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
153719 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
153720 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
153721 
153722 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
153723 
153724 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
153725 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
153726 
153727 ---------------------------------------------------------------------------------------------------------------
153728 
153729 
153730 --
153731 -- bulk performance
153732 --
153733 l_balance_type_code           VARCHAR2(1);
153734 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
153735 l_log_module                  VARCHAR2(240);
153736 
153737 --
153738 -- Upgrade strategy
153739 --
153740 l_actual_upg_option           VARCHAR2(1);
153741 l_enc_upg_option           VARCHAR2(1);
153742 
153743 --
153744 BEGIN
153745 --
153746 IF g_log_enabled THEN
153747       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_370';
153748 END IF;
153749 --
153750 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
153751 
153752       trace
153753          (p_msg      => 'BEGIN of AcctLineType_370'
153754          ,p_level    => C_LEVEL_PROCEDURE
153755          ,p_module   => l_log_module);
153756 
153757 END IF;
153758 --
153762 l_component_appl_id          :=  140;
153759 l_component_type             := 'AMB_JLT';
153760 l_component_code             := 'FA_TRANSFER_DEST_BONUS_RES';
153761 l_component_type_code        := 'S';
153763 l_amb_context_code           := 'DEFAULT';
153764 l_entity_code                := 'TRANSACTIONS';
153765 l_event_class_code           := 'TRANSFERS';
153766 l_event_type_code            := 'TRANSFERS_ALL';
153767 l_line_definition_owner_code := 'S';
153768 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
153769 --
153770 l_balance_type_code          := 'A';
153771 l_segment                     := NULL;
153772 l_ccid                        := NULL;
153773 l_adr_transaction_coa_id      := NULL;
153774 l_adr_accounting_coa_id       := NULL;
153775 l_adr_flexfield_segment_code  := NULL;
153776 l_adr_flex_value_set_id       := NULL;
153777 l_adr_value_type_code         := NULL;
153778 l_adr_value_combination_id    := NULL;
153779 l_adr_value_segment_code      := NULL;
153780 
153781 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
153782 l_bflow_class_code           := '';    -- 4219869 Business Flow
153783 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
153784 l_budgetary_control_flag     := 'N';
153785 
153786 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
153787 l_bflow_applied_to_amt       := NULL; -- 5132302
153788 l_entered_amt_idx            := NULL;          -- 4262811
153789 l_accted_amt_idx             := NULL;          -- 4262811
153790 l_acc_rev_flag               := NULL;          -- 4262811
153791 l_accrual_line_num           := NULL;          -- 4262811
153792 l_tmp_amt                    := NULL;          -- 4262811
153793 --
153794  
153795 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
153796     l_balance_type_code <> 'B' THEN
153797 IF (NVL(p_source_35,'
153798 ') =  'BONUS RESERVE' OR 
153799 NVL(p_source_35,'
153800 ') =  'BONUS EXPENSE') AND 
153801 NVL(p_source_42,'
153802 ') =  'DEST'
153803  THEN 
153804 
153805    --
153806    XLA_AE_LINES_PKG.SetNewLine;
153807 
153808    p_balance_type_code          := l_balance_type_code;
153809    -- set the flag so later we will know whether the gain loss line needs to be created
153810    
153811    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
153812      p_actual_flag :='A';
153813    END IF;
153814 
153815    --
153816    -- bulk performance
153817    --
153818    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
153819                                       p_header_num   => 0); -- 4262811
153820    --
153821    -- set accounting line options
153822    --
153823    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
153824            p_natural_side_code          => 'C'
153825          , p_gain_or_loss_flag          => 'N'
153826          , p_gl_transfer_mode_code      => 'S'
153827          , p_acct_entry_type_code       => 'A'
153828          , p_switch_side_flag           => 'Y'
153829          , p_merge_duplicate_code       => 'N'
153830          );
153831    --
153832    l_acc_rev_natural_side_code := 'D';  -- 4262811
153833    -- 
153834    --
153835    -- set accounting line type info
153836    --
153837    xla_ae_lines_pkg.SetAcctLineType
153838       (p_component_type             => l_component_type
153839       ,p_event_type_code            => l_event_type_code
153840       ,p_line_definition_owner_code => l_line_definition_owner_code
153841       ,p_line_definition_code       => l_line_definition_code
153842       ,p_accounting_line_code       => l_component_code
153843       ,p_accounting_line_type_code  => l_component_type_code
153844       ,p_accounting_line_appl_id    => l_component_appl_id
153845       ,p_amb_context_code           => l_amb_context_code
153846       ,p_entity_code                => l_entity_code
153847       ,p_event_class_code           => l_event_class_code);
153848    --
153849    -- set accounting class
153850    --
153851    xla_ae_lines_pkg.SetAcctClass(
153852            p_accounting_class_code  => 'ASSET'
153853          , p_ae_header_id           => l_ae_header_id
153854          );
153855 
153856    --
153857    -- set rounding class
153858    --
153859    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
153860                       'ASSET';
153861 
153862    --
153863    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
153864    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
153865    --
153866    -- bulk performance
153867    --
153868    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
153869 
153870    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
153871       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
153872 
153873    -- 4955764
153874    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
153875       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
153876 
153877    -- 4458381 Public Sector Enh
153878    
153879    --
153880    -- set accounting attributes for the line type
153881    --
153882    l_entered_amt_idx := 4;
153883    l_accted_amt_idx  := 6;
153884    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
153885    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
153886    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
153887    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
153888    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
153889    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
153890    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
153891    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
153895    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
153892    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
153893    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
153894    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
153896    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
153897 
153898    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
153899    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
153900 
153901    ---------------------------------------------------------------------------------------------------------------
153902    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
153903    ---------------------------------------------------------------------------------------------------------------
153904    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
153905 
153906    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
153907    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
153908 
153909    IF xla_accounting_cache_pkg.GetValueChar
153910          (p_source_code         => 'LEDGER_CATEGORY_CODE'
153911          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
153912    AND l_bflow_method_code = 'PRIOR_ENTRY'
153913 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
153914    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
153915          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
153916        )
153917    THEN
153918          xla_ae_lines_pkg.BflowUpgEntry
153919            (p_business_method_code    => l_bflow_method_code
153920            ,p_business_class_code     => l_bflow_class_code
153921            ,p_balance_type            => l_balance_type_code);
153922    ELSE
153923       NULL;
153924 -- No business flow processing for business flow method of NONE.
153925    END IF;
153926 
153927    --
153928    -- call analytical criteria
153929    --
153930    
153931    --
153932    -- call description
153933    --
153934    
153935 xla_ae_lines_pkg.SetLineDescription(
153936    p_ae_header_id => l_ae_header_id
153937   ,p_description  => Description_125 (
153938      p_application_id         => p_application_id
153939    , p_ae_header_id           => l_ae_header_id 
153940 , p_source_1 => p_source_1
153941    )
153942 );
153943 
153944 
153945    --
153946    -- call ADRs
153947    -- Bug 4922099
153948    --
153949    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
153950         (NVL(l_actual_upg_option, 'N') = 'O') OR
153951         (NVL(l_enc_upg_option, 'N') = 'O')
153952       )
153953    THEN
153954    NULL;
153955    --
153956    --
153957    
153958   l_ccid := AcctDerRule_174(
153959            p_application_id           => p_application_id
153960          , p_ae_header_id             => l_ae_header_id 
153961 , p_source_3 => p_source_3
153962 , p_source_17 => p_source_17
153963 , p_source_30 => p_source_30
153964          , x_transaction_coa_id       => l_adr_transaction_coa_id
153965          , x_accounting_coa_id        => l_adr_accounting_coa_id
153966          , x_value_type_code          => l_adr_value_type_code
153967          , p_side                     => 'NA'
153968    );
153969 
153970    xla_ae_lines_pkg.set_ccid(
153971     p_code_combination_id          => l_ccid
153972   , p_value_type_code              => l_adr_value_type_code
153973   , p_transaction_coa_id           => l_adr_transaction_coa_id
153974   , p_accounting_coa_id            => l_adr_accounting_coa_id
153975   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
153976   , p_adr_type_code                => 'S'
153977   , p_component_type               => l_component_type
153978   , p_component_code               => l_component_code
153979   , p_component_type_code          => l_component_type_code
153980   , p_component_appl_id            => l_component_appl_id
153981   , p_amb_context_code             => l_amb_context_code
153982   , p_side                         => 'NA'
153983   );
153984 
153985 
153986    l_segment := AcctDerRule_144(
153987            p_application_id           => p_application_id
153988          , p_ae_header_id             => l_ae_header_id 
153989 , p_source_3 => p_source_3
153990 , p_source_4 => p_source_4
153991          , x_transaction_coa_id       => l_adr_transaction_coa_id
153992          , x_accounting_coa_id        => l_adr_accounting_coa_id
153993          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
153994          , x_flex_value_set_id        => l_adr_flex_value_set_id
153995          , x_value_type_code          => l_adr_value_type_code
153996          , x_value_combination_id     => l_adr_value_combination_id
153997          , x_value_segment_code       => l_adr_value_segment_code
153998          , p_side                     => 'NA'
153999          , p_override_seg_flag        => 'Y'
154000    );
154001 
154002    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
154003 
154004       xla_ae_lines_pkg.set_segment(
154005           p_to_segment_code         => 'GL_ACCOUNT'
154006         , p_segment_value           => l_segment
154007         , p_from_segment_code       => l_adr_value_segment_code
154008         , p_from_combination_id     => l_adr_value_combination_id
154009         , p_value_type_code         => l_adr_value_type_code
154010         , p_transaction_coa_id      => l_adr_transaction_coa_id
154011         , p_accounting_coa_id       => l_adr_accounting_coa_id
154012         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
154013         , p_flex_value_set_id       => l_adr_flex_value_set_id
154014         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
154015         , p_adr_type_code           => 'S'
154016         , p_component_type          => l_component_type
154020         , p_amb_context_code        => l_amb_context_code
154017         , p_component_code          => l_component_code
154018         , p_component_type_code     => l_component_type_code
154019         , p_component_appl_id       => l_component_appl_id
154021         , p_entity_code             => 'TRANSACTIONS'
154022         , p_event_class_code        => 'TRANSFERS'
154023         , p_side                    => 'NA'
154024         );
154025 
154026   END IF;
154027 
154028    l_segment := AcctDerRule_168(
154029            p_application_id           => p_application_id
154030          , p_ae_header_id             => l_ae_header_id 
154031 , p_source_3 => p_source_3
154032 , p_source_29 => p_source_29
154033          , x_transaction_coa_id       => l_adr_transaction_coa_id
154034          , x_accounting_coa_id        => l_adr_accounting_coa_id
154035          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
154036          , x_flex_value_set_id        => l_adr_flex_value_set_id
154037          , x_value_type_code          => l_adr_value_type_code
154038          , x_value_combination_id     => l_adr_value_combination_id
154039          , x_value_segment_code       => l_adr_value_segment_code
154040          , p_side                     => 'NA'
154041          , p_override_seg_flag        => 'Y'
154042    );
154043 
154044    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
154045 
154046       xla_ae_lines_pkg.set_segment(
154047           p_to_segment_code         => 'GL_BALANCING'
154048         , p_segment_value           => l_segment
154049         , p_from_segment_code       => l_adr_value_segment_code
154050         , p_from_combination_id     => l_adr_value_combination_id
154051         , p_value_type_code         => l_adr_value_type_code
154052         , p_transaction_coa_id      => l_adr_transaction_coa_id
154053         , p_accounting_coa_id       => l_adr_accounting_coa_id
154054         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
154055         , p_flex_value_set_id       => l_adr_flex_value_set_id
154056         , p_adr_code                => 'FA_EXPENSE_ACCT'
154057         , p_adr_type_code           => 'S'
154058         , p_component_type          => l_component_type
154059         , p_component_code          => l_component_code
154060         , p_component_type_code     => l_component_type_code
154061         , p_component_appl_id       => l_component_appl_id
154062         , p_amb_context_code        => l_amb_context_code
154063         , p_entity_code             => 'TRANSACTIONS'
154064         , p_event_class_code        => 'TRANSFERS'
154065         , p_side                    => 'NA'
154066         );
154067 
154068   END IF;
154069 
154070    --
154071    --
154072    END IF;
154073    --
154074    -- Bug 4922099
154075    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
154076           (NVL(l_enc_upg_option, 'N') = 'O')
154077         ) AND
154078         (l_bflow_method_code = 'PRIOR_ENTRY')
154079       )
154080    THEN
154081       IF
154082       --
154083       1 = 2
154084       --
154085       THEN
154086       xla_accounting_err_pkg.build_message
154087                                     (p_appli_s_name            => 'XLA'
154088                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
154089                                     ,p_token_1                 => 'LINE_NUMBER'
154090                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
154091                                     ,p_token_2                 => 'LINE_TYPE_NAME'
154092                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
154093                                                                              l_component_type
154094                                                                             ,l_component_code
154095                                                                             ,l_component_type_code
154096                                                                             ,l_component_appl_id
154097                                                                             ,l_amb_context_code
154098                                                                             ,l_entity_code
154099                                                                             ,l_event_class_code
154100                                                                            )
154101                                     ,p_token_3                 => 'OWNER'
154102                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
154103                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
154104                                                                           ,p_lookup_code    => l_component_type_code
154105                                                                          )
154106                                     ,p_token_4                 => 'PRODUCT_NAME'
154107                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
154108                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
154109                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
154110                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
154111                                     ,p_ae_header_id            =>  NULL
154112                                        );
154113 
154114         IF (C_LEVEL_ERROR>= g_log_level) THEN
154115                  trace
154116                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
154117                       ,p_level    => C_LEVEL_ERROR
154118                       ,p_module   => l_log_module);
154119         END IF;
154120       END IF;
154121    END IF;
154122    --
154123    --
154124    ------------------------------------------------------------------------------------------------
154128    ------------------------------------------------------------------------------------------------
154125    -- 4219869 Business Flow
154126    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
154127    -- Prior Entry.  Currently, the following code is always generated.
154129    XLA_AE_LINES_PKG.ValidateCurrentLine;
154130 
154131    ------------------------------------------------------------------------------------
154132    -- 4219869 Business Flow
154133    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
154134    ------------------------------------------------------------------------------------
154135    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
154136 
154137    ----------------------------------------------------------------------------------
154138    -- 4219869 Business Flow
154139    -- Update journal entry status -- Need to generate this within IF <condition>
154140    ----------------------------------------------------------------------------------
154141    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
154142          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
154143          ,p_balance_type_code => l_balance_type_code
154144          );
154145 
154146    -------------------------------------------------------------------------------------------
154147    -- 4262811 - Generate the Accrual Reversal lines
154148    -------------------------------------------------------------------------------------------
154149    BEGIN
154150       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
154151                               (g_array_event(p_event_id).array_value_num('header_index'));
154152       IF l_acc_rev_flag IS NULL THEN
154153          l_acc_rev_flag := 'N';
154154       END IF;
154155    EXCEPTION
154156       WHEN OTHERS THEN
154157          l_acc_rev_flag := 'N';
154158    END;
154159    --
154160    IF (l_acc_rev_flag = 'Y') THEN
154161 
154162        -- 4645092  ------------------------------------------------------------------------------
154163        -- To allow MPA report to determine if it should generate report process
154164        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
154165        ------------------------------------------------------------------------------------------
154166 
154167        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
154168        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
154169    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
154170    -- call ADRs
154171    -- Bug 4922099
154172    --
154173    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
154174         (NVL(l_actual_upg_option, 'N') = 'O') OR
154175         (NVL(l_enc_upg_option, 'N') = 'O')
154176       )
154177    THEN
154178    NULL;
154179    --
154180    --
154181    
154182   l_ccid := AcctDerRule_174(
154183            p_application_id           => p_application_id
154184          , p_ae_header_id             => l_ae_header_id 
154185 , p_source_3 => p_source_3
154186 , p_source_17 => p_source_17
154187 , p_source_30 => p_source_30
154188          , x_transaction_coa_id       => l_adr_transaction_coa_id
154189          , x_accounting_coa_id        => l_adr_accounting_coa_id
154190          , x_value_type_code          => l_adr_value_type_code
154191          , p_side                     => 'NA'
154192    );
154193 
154194    xla_ae_lines_pkg.set_ccid(
154195     p_code_combination_id          => l_ccid
154196   , p_value_type_code              => l_adr_value_type_code
154197   , p_transaction_coa_id           => l_adr_transaction_coa_id
154198   , p_accounting_coa_id            => l_adr_accounting_coa_id
154199   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
154200   , p_adr_type_code                => 'S'
154201   , p_component_type               => l_component_type
154202   , p_component_code               => l_component_code
154203   , p_component_type_code          => l_component_type_code
154204   , p_component_appl_id            => l_component_appl_id
154205   , p_amb_context_code             => l_amb_context_code
154206   , p_side                         => 'NA'
154207   );
154208 
154209 
154210    l_segment := AcctDerRule_144(
154211            p_application_id           => p_application_id
154212          , p_ae_header_id             => l_ae_header_id 
154213 , p_source_3 => p_source_3
154214 , p_source_4 => p_source_4
154215          , x_transaction_coa_id       => l_adr_transaction_coa_id
154216          , x_accounting_coa_id        => l_adr_accounting_coa_id
154217          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
154218          , x_flex_value_set_id        => l_adr_flex_value_set_id
154219          , x_value_type_code          => l_adr_value_type_code
154220          , x_value_combination_id     => l_adr_value_combination_id
154221          , x_value_segment_code       => l_adr_value_segment_code
154222          , p_side                     => 'NA'
154223          , p_override_seg_flag        => 'Y'
154224    );
154225 
154226    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
154227 
154228       xla_ae_lines_pkg.set_segment(
154229           p_to_segment_code         => 'GL_ACCOUNT'
154230         , p_segment_value           => l_segment
154231         , p_from_segment_code       => l_adr_value_segment_code
154232         , p_from_combination_id     => l_adr_value_combination_id
154233         , p_value_type_code         => l_adr_value_type_code
154234         , p_transaction_coa_id      => l_adr_transaction_coa_id
154235         , p_accounting_coa_id       => l_adr_accounting_coa_id
154236         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
154237         , p_flex_value_set_id       => l_adr_flex_value_set_id
154238         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
154239         , p_adr_type_code           => 'S'
154240         , p_component_type          => l_component_type
154241         , p_component_code          => l_component_code
154245         , p_entity_code             => 'TRANSACTIONS'
154242         , p_component_type_code     => l_component_type_code
154243         , p_component_appl_id       => l_component_appl_id
154244         , p_amb_context_code        => l_amb_context_code
154246         , p_event_class_code        => 'TRANSFERS'
154247         , p_side                    => 'NA'
154248         );
154249 
154250   END IF;
154251 
154252    l_segment := AcctDerRule_168(
154253            p_application_id           => p_application_id
154254          , p_ae_header_id             => l_ae_header_id 
154255 , p_source_3 => p_source_3
154256 , p_source_29 => p_source_29
154257          , x_transaction_coa_id       => l_adr_transaction_coa_id
154258          , x_accounting_coa_id        => l_adr_accounting_coa_id
154259          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
154260          , x_flex_value_set_id        => l_adr_flex_value_set_id
154261          , x_value_type_code          => l_adr_value_type_code
154262          , x_value_combination_id     => l_adr_value_combination_id
154263          , x_value_segment_code       => l_adr_value_segment_code
154264          , p_side                     => 'NA'
154265          , p_override_seg_flag        => 'Y'
154266    );
154267 
154268    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
154269 
154270       xla_ae_lines_pkg.set_segment(
154271           p_to_segment_code         => 'GL_BALANCING'
154272         , p_segment_value           => l_segment
154273         , p_from_segment_code       => l_adr_value_segment_code
154274         , p_from_combination_id     => l_adr_value_combination_id
154275         , p_value_type_code         => l_adr_value_type_code
154276         , p_transaction_coa_id      => l_adr_transaction_coa_id
154277         , p_accounting_coa_id       => l_adr_accounting_coa_id
154278         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
154279         , p_flex_value_set_id       => l_adr_flex_value_set_id
154280         , p_adr_code                => 'FA_EXPENSE_ACCT'
154281         , p_adr_type_code           => 'S'
154282         , p_component_type          => l_component_type
154283         , p_component_code          => l_component_code
154284         , p_component_type_code     => l_component_type_code
154285         , p_component_appl_id       => l_component_appl_id
154286         , p_amb_context_code        => l_amb_context_code
154287         , p_entity_code             => 'TRANSACTIONS'
154288         , p_event_class_code        => 'TRANSFERS'
154289         , p_side                    => 'NA'
154290         );
154291 
154292   END IF;
154293 
154294    --
154295    --
154296    END IF;
154297 
154298        --
154299        -- Update the line information that should be overwritten
154300        --
154301        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
154302                                          p_header_num   => 1);
154303        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
154304 
154305        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
154306 
154307        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
154308           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
154309        END IF;
154310 
154311       --
154312       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
154313       --
154314       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
154315           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
154316       ELSE
154317           ---------------------------------------------------------------------------------------------------
154318           -- 4262811a Switch Sign
154319           ---------------------------------------------------------------------------------------------------
154320           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
154321           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
154322                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
154323           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
154324                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
154325           -- 5132302
154326           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
154327                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
154328 
154329       END IF;
154330 
154331       -- 4955764
154332       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
154333       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
154334 
154335 
154336       XLA_AE_LINES_PKG.ValidateCurrentLine;
154337       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
154338 
154339       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
154340                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
154341                ,p_balance_type_code => l_balance_type_code);
154342 
154343    END IF;
154344 
154345    -----------------------------------------------------------------------------------------
154346    -- 4262811 Multiperiod Accounting
154347    -----------------------------------------------------------------------------------------
154348      -- No MPA option is assigned.
154349 
154350 
154351 END IF;
154352 END IF;
154353 --
154354 
154355 --
154356 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
154357    trace
154358       (p_msg      => 'END of AcctLineType_370'
154359       ,p_level    => C_LEVEL_PROCEDURE
154360       ,p_module   => l_log_module);
154361 END IF;
154365       RAISE;
154362 --
154363 EXCEPTION
154364   WHEN xla_exceptions_pkg.application_exception THEN
154366   WHEN OTHERS THEN
154367        xla_exceptions_pkg.raise_message
154368            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_370');
154369 END AcctLineType_370;
154370 --
154371 
154372 ---------------------------------------
154373 --
154374 -- PRIVATE FUNCTION
154375 --         AcctLineType_371
154376 --
154377 ---------------------------------------
154378 PROCEDURE AcctLineType_371 (
154379   p_application_id        IN NUMBER
154380  ,p_event_id              IN NUMBER
154381  ,p_calculate_acctd_flag  IN VARCHAR2
154382  ,p_calculate_g_l_flag    IN VARCHAR2
154383  ,p_actual_flag           IN OUT VARCHAR2
154384  ,p_balance_type_code     OUT VARCHAR2
154385  ,p_gain_or_loss_ref      OUT VARCHAR2
154386  
154387 --Period Close Date
154388  , p_source_1            IN DATE
154389 --Generated Code Combination Identifier
154390  , p_source_3            IN NUMBER
154391 --Asset Cost Account
154392  , p_source_9            IN VARCHAR2
154393 --Expense Account Code Combination Identifier
154394  , p_source_29            IN NUMBER
154395 --Default Code Combination Identifier
154396  , p_source_30            IN NUMBER
154397 --Adjustment Type
154398  , p_source_35            IN VARCHAR2
154399 --Transaction Header Identifier
154400  , p_source_36            IN NUMBER
154401 --Adjustment Line Identifier
154402  , p_source_37            IN NUMBER
154403 --Distribution Type Code
154404  , p_source_38            IN VARCHAR2
154405 --Entered Amount
154406  , p_source_39            IN NUMBER
154407 --Currency Code
154408  , p_source_40            IN VARCHAR2
154409 --Source Destination Code
154410  , p_source_42            IN VARCHAR2
154411 )
154412 IS
154413 
154414 l_component_type              VARCHAR2(80);
154415 l_component_code              VARCHAR2(30);
154416 l_component_type_code         VARCHAR2(1);
154417 l_component_appl_id           INTEGER;
154418 l_amb_context_code            VARCHAR2(30);
154419 l_entity_code                 VARCHAR2(30);
154420 l_event_class_code            VARCHAR2(30);
154421 l_ae_header_id                NUMBER;
154422 l_event_type_code             VARCHAR2(30);
154423 l_line_definition_code        VARCHAR2(30);
154424 l_line_definition_owner_code  VARCHAR2(1);
154425 --
154426 -- adr variables
154427 l_segment                     VARCHAR2(30);
154428 l_ccid                        NUMBER;
154429 l_adr_transaction_coa_id      NUMBER;
154430 l_adr_accounting_coa_id       NUMBER;
154431 l_adr_flexfield_segment_code  VARCHAR2(30);
154432 l_adr_flex_value_set_id       NUMBER;
154433 l_adr_value_type_code         VARCHAR2(30);
154434 l_adr_value_combination_id    NUMBER;
154435 l_adr_value_segment_code      VARCHAR2(30);
154436 
154437 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
154438 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
154439 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
154440 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
154441 
154442 -- 4262811 Variables ------------------------------------------------------------------------------------------
154443 l_entered_amt_idx             NUMBER;
154444 l_accted_amt_idx              NUMBER;
154445 l_acc_rev_flag                VARCHAR2(1);
154446 l_accrual_line_num            NUMBER;
154447 l_tmp_amt                     NUMBER;
154448 l_acc_rev_natural_side_code   VARCHAR2(1);
154449 
154450 l_num_entries                 NUMBER;
154451 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
154452 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
154453 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
154454 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
154455 l_recog_line_1                NUMBER;
154456 l_recog_line_2                NUMBER;
154457 
154458 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
154459 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
154460 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
154461 
154462 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
154463 
154464 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
154465 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
154466 
154467 ---------------------------------------------------------------------------------------------------------------
154468 
154469 
154470 --
154471 -- bulk performance
154472 --
154473 l_balance_type_code           VARCHAR2(1);
154474 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
154475 l_log_module                  VARCHAR2(240);
154476 
154477 --
154478 -- Upgrade strategy
154479 --
154480 l_actual_upg_option           VARCHAR2(1);
154481 l_enc_upg_option           VARCHAR2(1);
154482 
154483 --
154484 BEGIN
154485 --
154486 IF g_log_enabled THEN
154487       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_371';
154488 END IF;
154489 --
154490 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
154491 
154492       trace
154493          (p_msg      => 'BEGIN of AcctLineType_371'
154494          ,p_level    => C_LEVEL_PROCEDURE
154495          ,p_module   => l_log_module);
154496 
154497 END IF;
154498 --
154499 l_component_type             := 'AMB_JLT';
154500 l_component_code             := 'FA_TRANSFER_DEST_COST';
154501 l_component_type_code        := 'S';
154502 l_component_appl_id          :=  140;
154503 l_amb_context_code           := 'DEFAULT';
154504 l_entity_code                := 'TRANSACTIONS';
154505 l_event_class_code           := 'TRANSFERS';
154506 l_event_type_code            := 'TRANSFERS_ALL';
154507 l_line_definition_owner_code := 'S';
154511 l_segment                     := NULL;
154508 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
154509 --
154510 l_balance_type_code          := 'A';
154512 l_ccid                        := NULL;
154513 l_adr_transaction_coa_id      := NULL;
154514 l_adr_accounting_coa_id       := NULL;
154515 l_adr_flexfield_segment_code  := NULL;
154516 l_adr_flex_value_set_id       := NULL;
154517 l_adr_value_type_code         := NULL;
154518 l_adr_value_combination_id    := NULL;
154519 l_adr_value_segment_code      := NULL;
154520 
154521 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
154522 l_bflow_class_code           := '';    -- 4219869 Business Flow
154523 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
154524 l_budgetary_control_flag     := 'N';
154525 
154526 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
154527 l_bflow_applied_to_amt       := NULL; -- 5132302
154528 l_entered_amt_idx            := NULL;          -- 4262811
154529 l_accted_amt_idx             := NULL;          -- 4262811
154530 l_acc_rev_flag               := NULL;          -- 4262811
154531 l_accrual_line_num           := NULL;          -- 4262811
154532 l_tmp_amt                    := NULL;          -- 4262811
154533 --
154534  
154535 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
154536     l_balance_type_code <> 'B' THEN
154537 IF NVL(p_source_35,'
154538 ') =  'COST' AND 
154539 NVL(p_source_42,'
154540 ') =  'DEST'
154541  THEN 
154542 
154543    --
154544    XLA_AE_LINES_PKG.SetNewLine;
154545 
154546    p_balance_type_code          := l_balance_type_code;
154547    -- set the flag so later we will know whether the gain loss line needs to be created
154548    
154549    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
154550      p_actual_flag :='A';
154551    END IF;
154552 
154553    --
154554    -- bulk performance
154555    --
154556    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
154557                                       p_header_num   => 0); -- 4262811
154558    --
154559    -- set accounting line options
154560    --
154561    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
154562            p_natural_side_code          => 'D'
154563          , p_gain_or_loss_flag          => 'N'
154564          , p_gl_transfer_mode_code      => 'S'
154565          , p_acct_entry_type_code       => 'A'
154566          , p_switch_side_flag           => 'Y'
154567          , p_merge_duplicate_code       => 'N'
154568          );
154569    --
154570    l_acc_rev_natural_side_code := 'C';  -- 4262811
154571    -- 
154572    --
154573    -- set accounting line type info
154574    --
154575    xla_ae_lines_pkg.SetAcctLineType
154576       (p_component_type             => l_component_type
154577       ,p_event_type_code            => l_event_type_code
154578       ,p_line_definition_owner_code => l_line_definition_owner_code
154579       ,p_line_definition_code       => l_line_definition_code
154580       ,p_accounting_line_code       => l_component_code
154581       ,p_accounting_line_type_code  => l_component_type_code
154582       ,p_accounting_line_appl_id    => l_component_appl_id
154583       ,p_amb_context_code           => l_amb_context_code
154584       ,p_entity_code                => l_entity_code
154585       ,p_event_class_code           => l_event_class_code);
154586    --
154587    -- set accounting class
154588    --
154589    xla_ae_lines_pkg.SetAcctClass(
154590            p_accounting_class_code  => 'ASSET'
154591          , p_ae_header_id           => l_ae_header_id
154592          );
154593 
154594    --
154595    -- set rounding class
154596    --
154597    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
154598                       'ASSET';
154599 
154600    --
154601    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
154602    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
154603    --
154604    -- bulk performance
154605    --
154606    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
154607 
154608    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
154609       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
154610 
154611    -- 4955764
154612    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
154613       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
154614 
154615    -- 4458381 Public Sector Enh
154616    
154617    --
154618    -- set accounting attributes for the line type
154619    --
154620    l_entered_amt_idx := 4;
154621    l_accted_amt_idx  := 6;
154622    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
154623    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
154624    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
154625    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
154626    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
154627    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
154628    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
154629    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
154630    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
154631    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
154632    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
154633    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
154634    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
154635 
154636    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
154637    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
154638 
154642    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
154639    ---------------------------------------------------------------------------------------------------------------
154640    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
154641    ---------------------------------------------------------------------------------------------------------------
154643 
154644    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
154645    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
154646 
154647    IF xla_accounting_cache_pkg.GetValueChar
154648          (p_source_code         => 'LEDGER_CATEGORY_CODE'
154649          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
154650    AND l_bflow_method_code = 'PRIOR_ENTRY'
154651 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
154652    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
154653          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
154654        )
154655    THEN
154656          xla_ae_lines_pkg.BflowUpgEntry
154657            (p_business_method_code    => l_bflow_method_code
154658            ,p_business_class_code     => l_bflow_class_code
154659            ,p_balance_type            => l_balance_type_code);
154660    ELSE
154661       NULL;
154662 -- No business flow processing for business flow method of NONE.
154663    END IF;
154664 
154665    --
154666    -- call analytical criteria
154667    --
154668    
154669    --
154670    -- call description
154671    --
154672    
154673 xla_ae_lines_pkg.SetLineDescription(
154674    p_ae_header_id => l_ae_header_id
154675   ,p_description  => Description_126 (
154676      p_application_id         => p_application_id
154677    , p_ae_header_id           => l_ae_header_id 
154678 , p_source_1 => p_source_1
154679    )
154680 );
154681 
154682 
154683    --
154684    -- call ADRs
154685    -- Bug 4922099
154686    --
154687    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
154688         (NVL(l_actual_upg_option, 'N') = 'O') OR
154689         (NVL(l_enc_upg_option, 'N') = 'O')
154690       )
154691    THEN
154692    NULL;
154693    --
154694    --
154695    
154696   l_ccid := AcctDerRule_173(
154697            p_application_id           => p_application_id
154698          , p_ae_header_id             => l_ae_header_id 
154699 , p_source_3 => p_source_3
154700 , p_source_30 => p_source_30
154701          , x_transaction_coa_id       => l_adr_transaction_coa_id
154702          , x_accounting_coa_id        => l_adr_accounting_coa_id
154703          , x_value_type_code          => l_adr_value_type_code
154704          , p_side                     => 'NA'
154705    );
154706 
154707    xla_ae_lines_pkg.set_ccid(
154708     p_code_combination_id          => l_ccid
154709   , p_value_type_code              => l_adr_value_type_code
154710   , p_transaction_coa_id           => l_adr_transaction_coa_id
154711   , p_accounting_coa_id            => l_adr_accounting_coa_id
154712   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
154713   , p_adr_type_code                => 'S'
154714   , p_component_type               => l_component_type
154715   , p_component_code               => l_component_code
154716   , p_component_type_code          => l_component_type_code
154717   , p_component_appl_id            => l_component_appl_id
154718   , p_amb_context_code             => l_amb_context_code
154719   , p_side                         => 'NA'
154720   );
154721 
154722 
154723    l_segment := AcctDerRule_148(
154724            p_application_id           => p_application_id
154725          , p_ae_header_id             => l_ae_header_id 
154726 , p_source_3 => p_source_3
154727 , p_source_9 => p_source_9
154728          , x_transaction_coa_id       => l_adr_transaction_coa_id
154729          , x_accounting_coa_id        => l_adr_accounting_coa_id
154730          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
154731          , x_flex_value_set_id        => l_adr_flex_value_set_id
154732          , x_value_type_code          => l_adr_value_type_code
154733          , x_value_combination_id     => l_adr_value_combination_id
154734          , x_value_segment_code       => l_adr_value_segment_code
154735          , p_side                     => 'NA'
154736          , p_override_seg_flag        => 'Y'
154737    );
154738 
154739    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
154740 
154741       xla_ae_lines_pkg.set_segment(
154742           p_to_segment_code         => 'GL_ACCOUNT'
154743         , p_segment_value           => l_segment
154744         , p_from_segment_code       => l_adr_value_segment_code
154745         , p_from_combination_id     => l_adr_value_combination_id
154746         , p_value_type_code         => l_adr_value_type_code
154747         , p_transaction_coa_id      => l_adr_transaction_coa_id
154748         , p_accounting_coa_id       => l_adr_accounting_coa_id
154749         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
154750         , p_flex_value_set_id       => l_adr_flex_value_set_id
154751         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
154752         , p_adr_type_code           => 'S'
154753         , p_component_type          => l_component_type
154754         , p_component_code          => l_component_code
154755         , p_component_type_code     => l_component_type_code
154756         , p_component_appl_id       => l_component_appl_id
154757         , p_amb_context_code        => l_amb_context_code
154758         , p_entity_code             => 'TRANSACTIONS'
154759         , p_event_class_code        => 'TRANSFERS'
154760         , p_side                    => 'NA'
154761         );
154762 
154763   END IF;
154764 
154765    l_segment := AcctDerRule_168(
154766            p_application_id           => p_application_id
154770          , x_transaction_coa_id       => l_adr_transaction_coa_id
154767          , p_ae_header_id             => l_ae_header_id 
154768 , p_source_3 => p_source_3
154769 , p_source_29 => p_source_29
154771          , x_accounting_coa_id        => l_adr_accounting_coa_id
154772          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
154773          , x_flex_value_set_id        => l_adr_flex_value_set_id
154774          , x_value_type_code          => l_adr_value_type_code
154775          , x_value_combination_id     => l_adr_value_combination_id
154776          , x_value_segment_code       => l_adr_value_segment_code
154777          , p_side                     => 'NA'
154778          , p_override_seg_flag        => 'Y'
154779    );
154780 
154781    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
154782 
154783       xla_ae_lines_pkg.set_segment(
154784           p_to_segment_code         => 'GL_BALANCING'
154785         , p_segment_value           => l_segment
154786         , p_from_segment_code       => l_adr_value_segment_code
154787         , p_from_combination_id     => l_adr_value_combination_id
154788         , p_value_type_code         => l_adr_value_type_code
154789         , p_transaction_coa_id      => l_adr_transaction_coa_id
154790         , p_accounting_coa_id       => l_adr_accounting_coa_id
154791         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
154792         , p_flex_value_set_id       => l_adr_flex_value_set_id
154793         , p_adr_code                => 'FA_EXPENSE_ACCT'
154794         , p_adr_type_code           => 'S'
154795         , p_component_type          => l_component_type
154796         , p_component_code          => l_component_code
154797         , p_component_type_code     => l_component_type_code
154798         , p_component_appl_id       => l_component_appl_id
154799         , p_amb_context_code        => l_amb_context_code
154800         , p_entity_code             => 'TRANSACTIONS'
154801         , p_event_class_code        => 'TRANSFERS'
154802         , p_side                    => 'NA'
154803         );
154804 
154805   END IF;
154806 
154807    --
154808    --
154809    END IF;
154810    --
154811    -- Bug 4922099
154812    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
154813           (NVL(l_enc_upg_option, 'N') = 'O')
154814         ) AND
154815         (l_bflow_method_code = 'PRIOR_ENTRY')
154816       )
154817    THEN
154818       IF
154819       --
154820       1 = 2
154821       --
154822       THEN
154823       xla_accounting_err_pkg.build_message
154824                                     (p_appli_s_name            => 'XLA'
154825                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
154826                                     ,p_token_1                 => 'LINE_NUMBER'
154827                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
154828                                     ,p_token_2                 => 'LINE_TYPE_NAME'
154829                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
154830                                                                              l_component_type
154831                                                                             ,l_component_code
154832                                                                             ,l_component_type_code
154833                                                                             ,l_component_appl_id
154834                                                                             ,l_amb_context_code
154835                                                                             ,l_entity_code
154836                                                                             ,l_event_class_code
154837                                                                            )
154838                                     ,p_token_3                 => 'OWNER'
154839                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
154840                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
154841                                                                           ,p_lookup_code    => l_component_type_code
154842                                                                          )
154843                                     ,p_token_4                 => 'PRODUCT_NAME'
154844                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
154845                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
154846                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
154847                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
154848                                     ,p_ae_header_id            =>  NULL
154849                                        );
154850 
154851         IF (C_LEVEL_ERROR>= g_log_level) THEN
154852                  trace
154853                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
154854                       ,p_level    => C_LEVEL_ERROR
154855                       ,p_module   => l_log_module);
154856         END IF;
154857       END IF;
154858    END IF;
154859    --
154860    --
154861    ------------------------------------------------------------------------------------------------
154862    -- 4219869 Business Flow
154863    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
154864    -- Prior Entry.  Currently, the following code is always generated.
154865    ------------------------------------------------------------------------------------------------
154866    XLA_AE_LINES_PKG.ValidateCurrentLine;
154867 
154868    ------------------------------------------------------------------------------------
154869    -- 4219869 Business Flow
154870    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
154874    ----------------------------------------------------------------------------------
154871    ------------------------------------------------------------------------------------
154872    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
154873 
154875    -- 4219869 Business Flow
154876    -- Update journal entry status -- Need to generate this within IF <condition>
154877    ----------------------------------------------------------------------------------
154878    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
154879          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
154880          ,p_balance_type_code => l_balance_type_code
154881          );
154882 
154883    -------------------------------------------------------------------------------------------
154884    -- 4262811 - Generate the Accrual Reversal lines
154885    -------------------------------------------------------------------------------------------
154886    BEGIN
154887       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
154888                               (g_array_event(p_event_id).array_value_num('header_index'));
154889       IF l_acc_rev_flag IS NULL THEN
154890          l_acc_rev_flag := 'N';
154891       END IF;
154892    EXCEPTION
154893       WHEN OTHERS THEN
154894          l_acc_rev_flag := 'N';
154895    END;
154896    --
154897    IF (l_acc_rev_flag = 'Y') THEN
154898 
154899        -- 4645092  ------------------------------------------------------------------------------
154900        -- To allow MPA report to determine if it should generate report process
154901        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
154902        ------------------------------------------------------------------------------------------
154903 
154904        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
154905        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
154906    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
154907    -- call ADRs
154908    -- Bug 4922099
154909    --
154910    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
154911         (NVL(l_actual_upg_option, 'N') = 'O') OR
154912         (NVL(l_enc_upg_option, 'N') = 'O')
154913       )
154914    THEN
154915    NULL;
154916    --
154917    --
154918    
154919   l_ccid := AcctDerRule_173(
154920            p_application_id           => p_application_id
154921          , p_ae_header_id             => l_ae_header_id 
154922 , p_source_3 => p_source_3
154923 , p_source_30 => p_source_30
154924          , x_transaction_coa_id       => l_adr_transaction_coa_id
154925          , x_accounting_coa_id        => l_adr_accounting_coa_id
154926          , x_value_type_code          => l_adr_value_type_code
154927          , p_side                     => 'NA'
154928    );
154929 
154930    xla_ae_lines_pkg.set_ccid(
154931     p_code_combination_id          => l_ccid
154932   , p_value_type_code              => l_adr_value_type_code
154933   , p_transaction_coa_id           => l_adr_transaction_coa_id
154934   , p_accounting_coa_id            => l_adr_accounting_coa_id
154935   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
154936   , p_adr_type_code                => 'S'
154937   , p_component_type               => l_component_type
154938   , p_component_code               => l_component_code
154939   , p_component_type_code          => l_component_type_code
154940   , p_component_appl_id            => l_component_appl_id
154941   , p_amb_context_code             => l_amb_context_code
154942   , p_side                         => 'NA'
154943   );
154944 
154945 
154946    l_segment := AcctDerRule_148(
154947            p_application_id           => p_application_id
154948          , p_ae_header_id             => l_ae_header_id 
154949 , p_source_3 => p_source_3
154950 , p_source_9 => p_source_9
154951          , x_transaction_coa_id       => l_adr_transaction_coa_id
154952          , x_accounting_coa_id        => l_adr_accounting_coa_id
154953          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
154954          , x_flex_value_set_id        => l_adr_flex_value_set_id
154955          , x_value_type_code          => l_adr_value_type_code
154956          , x_value_combination_id     => l_adr_value_combination_id
154957          , x_value_segment_code       => l_adr_value_segment_code
154958          , p_side                     => 'NA'
154959          , p_override_seg_flag        => 'Y'
154960    );
154961 
154962    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
154963 
154964       xla_ae_lines_pkg.set_segment(
154965           p_to_segment_code         => 'GL_ACCOUNT'
154966         , p_segment_value           => l_segment
154967         , p_from_segment_code       => l_adr_value_segment_code
154968         , p_from_combination_id     => l_adr_value_combination_id
154969         , p_value_type_code         => l_adr_value_type_code
154970         , p_transaction_coa_id      => l_adr_transaction_coa_id
154971         , p_accounting_coa_id       => l_adr_accounting_coa_id
154972         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
154973         , p_flex_value_set_id       => l_adr_flex_value_set_id
154974         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
154975         , p_adr_type_code           => 'S'
154976         , p_component_type          => l_component_type
154977         , p_component_code          => l_component_code
154978         , p_component_type_code     => l_component_type_code
154979         , p_component_appl_id       => l_component_appl_id
154980         , p_amb_context_code        => l_amb_context_code
154981         , p_entity_code             => 'TRANSACTIONS'
154982         , p_event_class_code        => 'TRANSFERS'
154983         , p_side                    => 'NA'
154984         );
154985 
154986   END IF;
154987 
154988    l_segment := AcctDerRule_168(
154989            p_application_id           => p_application_id
154990          , p_ae_header_id             => l_ae_header_id 
154991 , p_source_3 => p_source_3
154995          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
154992 , p_source_29 => p_source_29
154993          , x_transaction_coa_id       => l_adr_transaction_coa_id
154994          , x_accounting_coa_id        => l_adr_accounting_coa_id
154996          , x_flex_value_set_id        => l_adr_flex_value_set_id
154997          , x_value_type_code          => l_adr_value_type_code
154998          , x_value_combination_id     => l_adr_value_combination_id
154999          , x_value_segment_code       => l_adr_value_segment_code
155000          , p_side                     => 'NA'
155001          , p_override_seg_flag        => 'Y'
155002    );
155003 
155004    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
155005 
155006       xla_ae_lines_pkg.set_segment(
155007           p_to_segment_code         => 'GL_BALANCING'
155008         , p_segment_value           => l_segment
155009         , p_from_segment_code       => l_adr_value_segment_code
155010         , p_from_combination_id     => l_adr_value_combination_id
155011         , p_value_type_code         => l_adr_value_type_code
155012         , p_transaction_coa_id      => l_adr_transaction_coa_id
155013         , p_accounting_coa_id       => l_adr_accounting_coa_id
155014         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
155015         , p_flex_value_set_id       => l_adr_flex_value_set_id
155016         , p_adr_code                => 'FA_EXPENSE_ACCT'
155017         , p_adr_type_code           => 'S'
155018         , p_component_type          => l_component_type
155019         , p_component_code          => l_component_code
155020         , p_component_type_code     => l_component_type_code
155021         , p_component_appl_id       => l_component_appl_id
155022         , p_amb_context_code        => l_amb_context_code
155023         , p_entity_code             => 'TRANSACTIONS'
155024         , p_event_class_code        => 'TRANSFERS'
155025         , p_side                    => 'NA'
155026         );
155027 
155028   END IF;
155029 
155030    --
155031    --
155032    END IF;
155033 
155034        --
155035        -- Update the line information that should be overwritten
155036        --
155037        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
155038                                          p_header_num   => 1);
155039        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
155040 
155041        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
155042 
155043        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
155044           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
155045        END IF;
155046 
155047       --
155048       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
155049       --
155050       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
155051           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
155052       ELSE
155053           ---------------------------------------------------------------------------------------------------
155054           -- 4262811a Switch Sign
155055           ---------------------------------------------------------------------------------------------------
155056           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
155057           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
155058                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
155059           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
155060                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
155061           -- 5132302
155062           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
155063                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
155064 
155065       END IF;
155066 
155067       -- 4955764
155068       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
155069       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
155070 
155071 
155072       XLA_AE_LINES_PKG.ValidateCurrentLine;
155073       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
155074 
155075       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
155076                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
155077                ,p_balance_type_code => l_balance_type_code);
155078 
155079    END IF;
155080 
155081    -----------------------------------------------------------------------------------------
155082    -- 4262811 Multiperiod Accounting
155083    -----------------------------------------------------------------------------------------
155084      -- No MPA option is assigned.
155085 
155086 
155087 END IF;
155088 END IF;
155089 --
155090 
155091 --
155092 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
155093    trace
155094       (p_msg      => 'END of AcctLineType_371'
155095       ,p_level    => C_LEVEL_PROCEDURE
155096       ,p_module   => l_log_module);
155097 END IF;
155098 --
155099 EXCEPTION
155100   WHEN xla_exceptions_pkg.application_exception THEN
155101       RAISE;
155102   WHEN OTHERS THEN
155103        xla_exceptions_pkg.raise_message
155104            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_371');
155105 END AcctLineType_371;
155106 --
155107 
155108 ---------------------------------------
155109 --
155110 -- PRIVATE FUNCTION
155111 --         AcctLineType_372
155112 --
155113 ---------------------------------------
155114 PROCEDURE AcctLineType_372 (
155115   p_application_id        IN NUMBER
155119  ,p_actual_flag           IN OUT VARCHAR2
155116  ,p_event_id              IN NUMBER
155117  ,p_calculate_acctd_flag  IN VARCHAR2
155118  ,p_calculate_g_l_flag    IN VARCHAR2
155120  ,p_balance_type_code     OUT VARCHAR2
155121  ,p_gain_or_loss_ref      OUT VARCHAR2
155122  
155123 --Period Close Date
155124  , p_source_1            IN DATE
155125 --Generated Code Combination Identifier
155126  , p_source_3            IN NUMBER
155127 --Expense Account Code Combination Identifier
155128  , p_source_29            IN NUMBER
155129 --Adjustment Type
155130  , p_source_35            IN VARCHAR2
155131 --Transaction Header Identifier
155132  , p_source_36            IN NUMBER
155133 --Adjustment Line Identifier
155134  , p_source_37            IN NUMBER
155135 --Distribution Type Code
155136  , p_source_38            IN VARCHAR2
155137 --Entered Amount
155138  , p_source_39            IN NUMBER
155139 --Currency Code
155140  , p_source_40            IN VARCHAR2
155141 --Source Destination Code
155142  , p_source_42            IN VARCHAR2
155143 )
155144 IS
155145 
155146 l_component_type              VARCHAR2(80);
155147 l_component_code              VARCHAR2(30);
155148 l_component_type_code         VARCHAR2(1);
155149 l_component_appl_id           INTEGER;
155150 l_amb_context_code            VARCHAR2(30);
155151 l_entity_code                 VARCHAR2(30);
155152 l_event_class_code            VARCHAR2(30);
155153 l_ae_header_id                NUMBER;
155154 l_event_type_code             VARCHAR2(30);
155155 l_line_definition_code        VARCHAR2(30);
155156 l_line_definition_owner_code  VARCHAR2(1);
155157 --
155158 -- adr variables
155159 l_segment                     VARCHAR2(30);
155160 l_ccid                        NUMBER;
155161 l_adr_transaction_coa_id      NUMBER;
155162 l_adr_accounting_coa_id       NUMBER;
155163 l_adr_flexfield_segment_code  VARCHAR2(30);
155164 l_adr_flex_value_set_id       NUMBER;
155165 l_adr_value_type_code         VARCHAR2(30);
155166 l_adr_value_combination_id    NUMBER;
155167 l_adr_value_segment_code      VARCHAR2(30);
155168 
155169 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
155170 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
155171 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
155172 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
155173 
155174 -- 4262811 Variables ------------------------------------------------------------------------------------------
155175 l_entered_amt_idx             NUMBER;
155176 l_accted_amt_idx              NUMBER;
155177 l_acc_rev_flag                VARCHAR2(1);
155178 l_accrual_line_num            NUMBER;
155179 l_tmp_amt                     NUMBER;
155180 l_acc_rev_natural_side_code   VARCHAR2(1);
155181 
155182 l_num_entries                 NUMBER;
155183 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
155184 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
155185 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
155186 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
155187 l_recog_line_1                NUMBER;
155188 l_recog_line_2                NUMBER;
155189 
155190 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
155191 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
155192 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
155193 
155194 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
155195 
155196 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
155197 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
155198 
155199 ---------------------------------------------------------------------------------------------------------------
155200 
155201 
155202 --
155203 -- bulk performance
155204 --
155205 l_balance_type_code           VARCHAR2(1);
155206 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
155207 l_log_module                  VARCHAR2(240);
155208 
155209 --
155210 -- Upgrade strategy
155211 --
155212 l_actual_upg_option           VARCHAR2(1);
155213 l_enc_upg_option           VARCHAR2(1);
155214 
155215 --
155216 BEGIN
155217 --
155218 IF g_log_enabled THEN
155219       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_372';
155220 END IF;
155221 --
155222 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
155223 
155224       trace
155225          (p_msg      => 'BEGIN of AcctLineType_372'
155226          ,p_level    => C_LEVEL_PROCEDURE
155227          ,p_module   => l_log_module);
155228 
155229 END IF;
155230 --
155231 l_component_type             := 'AMB_JLT';
155232 l_component_code             := 'FA_TRANSFER_DEST_DEPRN_EXP';
155233 l_component_type_code        := 'S';
155234 l_component_appl_id          :=  140;
155235 l_amb_context_code           := 'DEFAULT';
155236 l_entity_code                := 'TRANSACTIONS';
155237 l_event_class_code           := 'TRANSFERS';
155238 l_event_type_code            := 'TRANSFERS_ALL';
155239 l_line_definition_owner_code := 'S';
155240 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
155241 --
155242 l_balance_type_code          := 'A';
155243 l_segment                     := NULL;
155244 l_ccid                        := NULL;
155245 l_adr_transaction_coa_id      := NULL;
155246 l_adr_accounting_coa_id       := NULL;
155247 l_adr_flexfield_segment_code  := NULL;
155248 l_adr_flex_value_set_id       := NULL;
155249 l_adr_value_type_code         := NULL;
155250 l_adr_value_combination_id    := NULL;
155251 l_adr_value_segment_code      := NULL;
155252 
155253 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
155254 l_bflow_class_code           := '';    -- 4219869 Business Flow
155255 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
155259 l_bflow_applied_to_amt       := NULL; -- 5132302
155256 l_budgetary_control_flag     := 'N';
155257 
155258 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
155260 l_entered_amt_idx            := NULL;          -- 4262811
155261 l_accted_amt_idx             := NULL;          -- 4262811
155262 l_acc_rev_flag               := NULL;          -- 4262811
155263 l_accrual_line_num           := NULL;          -- 4262811
155264 l_tmp_amt                    := NULL;          -- 4262811
155265 --
155266  
155267 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
155268     l_balance_type_code <> 'B' THEN
155269 IF NVL(p_source_35,'
155270 ') =  'EXPENSE' AND 
155271 NVL(p_source_42,'
155272 ') =  'DEST'
155273  THEN 
155274 
155275    --
155276    XLA_AE_LINES_PKG.SetNewLine;
155277 
155278    p_balance_type_code          := l_balance_type_code;
155279    -- set the flag so later we will know whether the gain loss line needs to be created
155280    
155281    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
155282      p_actual_flag :='A';
155283    END IF;
155284 
155285    --
155286    -- bulk performance
155287    --
155288    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
155289                                       p_header_num   => 0); -- 4262811
155290    --
155291    -- set accounting line options
155292    --
155293    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
155294            p_natural_side_code          => 'D'
155295          , p_gain_or_loss_flag          => 'N'
155296          , p_gl_transfer_mode_code      => 'S'
155297          , p_acct_entry_type_code       => 'A'
155298          , p_switch_side_flag           => 'Y'
155299          , p_merge_duplicate_code       => 'N'
155300          );
155301    --
155302    l_acc_rev_natural_side_code := 'C';  -- 4262811
155303    -- 
155304    --
155305    -- set accounting line type info
155306    --
155307    xla_ae_lines_pkg.SetAcctLineType
155308       (p_component_type             => l_component_type
155309       ,p_event_type_code            => l_event_type_code
155310       ,p_line_definition_owner_code => l_line_definition_owner_code
155311       ,p_line_definition_code       => l_line_definition_code
155312       ,p_accounting_line_code       => l_component_code
155313       ,p_accounting_line_type_code  => l_component_type_code
155314       ,p_accounting_line_appl_id    => l_component_appl_id
155315       ,p_amb_context_code           => l_amb_context_code
155316       ,p_entity_code                => l_entity_code
155317       ,p_event_class_code           => l_event_class_code);
155318    --
155319    -- set accounting class
155320    --
155321    xla_ae_lines_pkg.SetAcctClass(
155322            p_accounting_class_code  => 'EXPENSE'
155323          , p_ae_header_id           => l_ae_header_id
155324          );
155325 
155326    --
155327    -- set rounding class
155328    --
155329    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
155330                       'EXPENSE';
155331 
155332    --
155333    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
155334    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
155335    --
155336    -- bulk performance
155337    --
155338    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
155339 
155340    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
155341       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
155342 
155343    -- 4955764
155344    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
155345       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
155346 
155347    -- 4458381 Public Sector Enh
155348    
155349    --
155350    -- set accounting attributes for the line type
155351    --
155352    l_entered_amt_idx := 4;
155353    l_accted_amt_idx  := 6;
155354    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
155355    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
155356    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
155357    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
155358    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
155359    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
155360    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
155361    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
155362    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
155363    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
155364    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
155365    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
155366    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
155367 
155368    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
155369    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
155370 
155371    ---------------------------------------------------------------------------------------------------------------
155372    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
155373    ---------------------------------------------------------------------------------------------------------------
155374    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
155375 
155376    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
155377    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
155378 
155379    IF xla_accounting_cache_pkg.GetValueChar
155380          (p_source_code         => 'LEDGER_CATEGORY_CODE'
155384    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
155381          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
155382    AND l_bflow_method_code = 'PRIOR_ENTRY'
155383 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
155385          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
155386        )
155387    THEN
155388          xla_ae_lines_pkg.BflowUpgEntry
155389            (p_business_method_code    => l_bflow_method_code
155390            ,p_business_class_code     => l_bflow_class_code
155391            ,p_balance_type            => l_balance_type_code);
155392    ELSE
155393       NULL;
155394 -- No business flow processing for business flow method of NONE.
155395    END IF;
155396 
155397    --
155398    -- call analytical criteria
155399    --
155400    
155401    --
155402    -- call description
155403    --
155404    
155405 xla_ae_lines_pkg.SetLineDescription(
155406    p_ae_header_id => l_ae_header_id
155407   ,p_description  => Description_127 (
155408      p_application_id         => p_application_id
155409    , p_ae_header_id           => l_ae_header_id 
155410 , p_source_1 => p_source_1
155411    )
155412 );
155413 
155414 
155415    --
155416    -- call ADRs
155417    -- Bug 4922099
155418    --
155419    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
155420         (NVL(l_actual_upg_option, 'N') = 'O') OR
155421         (NVL(l_enc_upg_option, 'N') = 'O')
155422       )
155423    THEN
155424    NULL;
155425    --
155426    --
155427    
155428   l_ccid := AcctDerRule_175(
155429            p_application_id           => p_application_id
155430          , p_ae_header_id             => l_ae_header_id 
155431 , p_source_3 => p_source_3
155432 , p_source_29 => p_source_29
155433          , x_transaction_coa_id       => l_adr_transaction_coa_id
155434          , x_accounting_coa_id        => l_adr_accounting_coa_id
155435          , x_value_type_code          => l_adr_value_type_code
155436          , p_side                     => 'NA'
155437    );
155438 
155439    xla_ae_lines_pkg.set_ccid(
155440     p_code_combination_id          => l_ccid
155441   , p_value_type_code              => l_adr_value_type_code
155442   , p_transaction_coa_id           => l_adr_transaction_coa_id
155443   , p_accounting_coa_id            => l_adr_accounting_coa_id
155444   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
155445   , p_adr_type_code                => 'S'
155446   , p_component_type               => l_component_type
155447   , p_component_code               => l_component_code
155448   , p_component_type_code          => l_component_type_code
155449   , p_component_appl_id            => l_component_appl_id
155450   , p_amb_context_code             => l_amb_context_code
155451   , p_side                         => 'NA'
155452   );
155453 
155454 
155455    --
155456    --
155457    END IF;
155458    --
155459    -- Bug 4922099
155460    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
155461           (NVL(l_enc_upg_option, 'N') = 'O')
155462         ) AND
155463         (l_bflow_method_code = 'PRIOR_ENTRY')
155464       )
155465    THEN
155466       IF
155467       --
155468       1 = 2
155469       --
155470       THEN
155471       xla_accounting_err_pkg.build_message
155472                                     (p_appli_s_name            => 'XLA'
155473                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
155474                                     ,p_token_1                 => 'LINE_NUMBER'
155475                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
155476                                     ,p_token_2                 => 'LINE_TYPE_NAME'
155477                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
155478                                                                              l_component_type
155479                                                                             ,l_component_code
155480                                                                             ,l_component_type_code
155481                                                                             ,l_component_appl_id
155482                                                                             ,l_amb_context_code
155483                                                                             ,l_entity_code
155484                                                                             ,l_event_class_code
155485                                                                            )
155486                                     ,p_token_3                 => 'OWNER'
155487                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
155488                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
155489                                                                           ,p_lookup_code    => l_component_type_code
155490                                                                          )
155491                                     ,p_token_4                 => 'PRODUCT_NAME'
155492                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
155493                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
155494                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
155495                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
155496                                     ,p_ae_header_id            =>  NULL
155497                                        );
155498 
155499         IF (C_LEVEL_ERROR>= g_log_level) THEN
155500                  trace
155501                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
155502                       ,p_level    => C_LEVEL_ERROR
155506    END IF;
155503                       ,p_module   => l_log_module);
155504         END IF;
155505       END IF;
155507    --
155508    --
155509    ------------------------------------------------------------------------------------------------
155510    -- 4219869 Business Flow
155511    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
155512    -- Prior Entry.  Currently, the following code is always generated.
155513    ------------------------------------------------------------------------------------------------
155514    XLA_AE_LINES_PKG.ValidateCurrentLine;
155515 
155516    ------------------------------------------------------------------------------------
155517    -- 4219869 Business Flow
155518    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
155519    ------------------------------------------------------------------------------------
155520    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
155521 
155522    ----------------------------------------------------------------------------------
155523    -- 4219869 Business Flow
155524    -- Update journal entry status -- Need to generate this within IF <condition>
155525    ----------------------------------------------------------------------------------
155526    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
155527          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
155528          ,p_balance_type_code => l_balance_type_code
155529          );
155530 
155531    -------------------------------------------------------------------------------------------
155532    -- 4262811 - Generate the Accrual Reversal lines
155533    -------------------------------------------------------------------------------------------
155534    BEGIN
155535       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
155536                               (g_array_event(p_event_id).array_value_num('header_index'));
155537       IF l_acc_rev_flag IS NULL THEN
155538          l_acc_rev_flag := 'N';
155539       END IF;
155540    EXCEPTION
155541       WHEN OTHERS THEN
155542          l_acc_rev_flag := 'N';
155543    END;
155544    --
155545    IF (l_acc_rev_flag = 'Y') THEN
155546 
155547        -- 4645092  ------------------------------------------------------------------------------
155548        -- To allow MPA report to determine if it should generate report process
155549        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
155550        ------------------------------------------------------------------------------------------
155551 
155552        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
155553        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
155554    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
155555    -- call ADRs
155556    -- Bug 4922099
155557    --
155558    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
155559         (NVL(l_actual_upg_option, 'N') = 'O') OR
155560         (NVL(l_enc_upg_option, 'N') = 'O')
155561       )
155562    THEN
155563    NULL;
155564    --
155565    --
155566    
155567   l_ccid := AcctDerRule_175(
155568            p_application_id           => p_application_id
155569          , p_ae_header_id             => l_ae_header_id 
155570 , p_source_3 => p_source_3
155571 , p_source_29 => p_source_29
155572          , x_transaction_coa_id       => l_adr_transaction_coa_id
155573          , x_accounting_coa_id        => l_adr_accounting_coa_id
155574          , x_value_type_code          => l_adr_value_type_code
155575          , p_side                     => 'NA'
155576    );
155577 
155578    xla_ae_lines_pkg.set_ccid(
155579     p_code_combination_id          => l_ccid
155580   , p_value_type_code              => l_adr_value_type_code
155581   , p_transaction_coa_id           => l_adr_transaction_coa_id
155582   , p_accounting_coa_id            => l_adr_accounting_coa_id
155583   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
155584   , p_adr_type_code                => 'S'
155585   , p_component_type               => l_component_type
155586   , p_component_code               => l_component_code
155587   , p_component_type_code          => l_component_type_code
155588   , p_component_appl_id            => l_component_appl_id
155589   , p_amb_context_code             => l_amb_context_code
155590   , p_side                         => 'NA'
155591   );
155592 
155593 
155594    --
155595    --
155596    END IF;
155597 
155598        --
155599        -- Update the line information that should be overwritten
155600        --
155601        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
155602                                          p_header_num   => 1);
155603        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
155604 
155605        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
155606 
155607        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
155608           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
155609        END IF;
155610 
155611       --
155612       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
155613       --
155614       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
155615           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
155616       ELSE
155617           ---------------------------------------------------------------------------------------------------
155618           -- 4262811a Switch Sign
155619           ---------------------------------------------------------------------------------------------------
155620           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
155621           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
155625           -- 5132302
155622                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
155623           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
155624                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
155626           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
155627                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
155628 
155629       END IF;
155630 
155631       -- 4955764
155632       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
155633       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
155634 
155635 
155636       XLA_AE_LINES_PKG.ValidateCurrentLine;
155637       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
155638 
155639       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
155640                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
155641                ,p_balance_type_code => l_balance_type_code);
155642 
155643    END IF;
155644 
155645    -----------------------------------------------------------------------------------------
155646    -- 4262811 Multiperiod Accounting
155647    -----------------------------------------------------------------------------------------
155648      -- No MPA option is assigned.
155649 
155650 
155651 END IF;
155652 END IF;
155653 --
155654 
155655 --
155656 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
155657    trace
155658       (p_msg      => 'END of AcctLineType_372'
155659       ,p_level    => C_LEVEL_PROCEDURE
155660       ,p_module   => l_log_module);
155661 END IF;
155662 --
155663 EXCEPTION
155664   WHEN xla_exceptions_pkg.application_exception THEN
155665       RAISE;
155666   WHEN OTHERS THEN
155667        xla_exceptions_pkg.raise_message
155668            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_372');
155669 END AcctLineType_372;
155670 --
155671 
155672 ---------------------------------------
155673 --
155674 -- PRIVATE FUNCTION
155675 --         AcctLineType_373
155676 --
155677 ---------------------------------------
155678 PROCEDURE AcctLineType_373 (
155679   p_application_id        IN NUMBER
155680  ,p_event_id              IN NUMBER
155681  ,p_calculate_acctd_flag  IN VARCHAR2
155682  ,p_calculate_g_l_flag    IN VARCHAR2
155683  ,p_actual_flag           IN OUT VARCHAR2
155684  ,p_balance_type_code     OUT VARCHAR2
155685  ,p_gain_or_loss_ref      OUT VARCHAR2
155686  
155687 --Period Close Date
155688  , p_source_1            IN DATE
155689 --Generated Code Combination Identifier
155690  , p_source_3            IN NUMBER
155691 --Depreciation Reserve Account
155692  , p_source_10            IN VARCHAR2
155693 --Generated Offset Code Combination Identifier
155694  , p_source_17            IN NUMBER
155695 --Expense Account Code Combination Identifier
155696  , p_source_29            IN NUMBER
155697 --Default Code Combination Identifier
155698  , p_source_30            IN NUMBER
155699 --Adjustment Type
155700  , p_source_35            IN VARCHAR2
155701 --Transaction Header Identifier
155702  , p_source_36            IN NUMBER
155703 --Adjustment Line Identifier
155704  , p_source_37            IN NUMBER
155705 --Distribution Type Code
155706  , p_source_38            IN VARCHAR2
155707 --Entered Amount
155708  , p_source_39            IN NUMBER
155709 --Currency Code
155710  , p_source_40            IN VARCHAR2
155711 --Source Destination Code
155712  , p_source_42            IN VARCHAR2
155713 )
155714 IS
155715 
155716 l_component_type              VARCHAR2(80);
155717 l_component_code              VARCHAR2(30);
155718 l_component_type_code         VARCHAR2(1);
155719 l_component_appl_id           INTEGER;
155720 l_amb_context_code            VARCHAR2(30);
155721 l_entity_code                 VARCHAR2(30);
155722 l_event_class_code            VARCHAR2(30);
155723 l_ae_header_id                NUMBER;
155724 l_event_type_code             VARCHAR2(30);
155725 l_line_definition_code        VARCHAR2(30);
155726 l_line_definition_owner_code  VARCHAR2(1);
155727 --
155728 -- adr variables
155729 l_segment                     VARCHAR2(30);
155730 l_ccid                        NUMBER;
155731 l_adr_transaction_coa_id      NUMBER;
155732 l_adr_accounting_coa_id       NUMBER;
155733 l_adr_flexfield_segment_code  VARCHAR2(30);
155734 l_adr_flex_value_set_id       NUMBER;
155735 l_adr_value_type_code         VARCHAR2(30);
155736 l_adr_value_combination_id    NUMBER;
155737 l_adr_value_segment_code      VARCHAR2(30);
155738 
155739 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
155740 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
155741 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
155742 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
155743 
155744 -- 4262811 Variables ------------------------------------------------------------------------------------------
155745 l_entered_amt_idx             NUMBER;
155746 l_accted_amt_idx              NUMBER;
155747 l_acc_rev_flag                VARCHAR2(1);
155748 l_accrual_line_num            NUMBER;
155749 l_tmp_amt                     NUMBER;
155750 l_acc_rev_natural_side_code   VARCHAR2(1);
155751 
155752 l_num_entries                 NUMBER;
155753 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
155754 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
155755 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
155756 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
155757 l_recog_line_1                NUMBER;
155758 l_recog_line_2                NUMBER;
155759 
155763 
155760 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
155761 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
155762 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
155764 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
155765 
155766 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
155767 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
155768 
155769 ---------------------------------------------------------------------------------------------------------------
155770 
155771 
155772 --
155773 -- bulk performance
155774 --
155775 l_balance_type_code           VARCHAR2(1);
155776 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
155777 l_log_module                  VARCHAR2(240);
155778 
155779 --
155780 -- Upgrade strategy
155781 --
155782 l_actual_upg_option           VARCHAR2(1);
155783 l_enc_upg_option           VARCHAR2(1);
155784 
155785 --
155786 BEGIN
155787 --
155788 IF g_log_enabled THEN
155789       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_373';
155790 END IF;
155791 --
155792 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
155793 
155794       trace
155795          (p_msg      => 'BEGIN of AcctLineType_373'
155796          ,p_level    => C_LEVEL_PROCEDURE
155797          ,p_module   => l_log_module);
155798 
155799 END IF;
155800 --
155801 l_component_type             := 'AMB_JLT';
155802 l_component_code             := 'FA_TRANSFER_DEST_DEPRN_RES';
155803 l_component_type_code        := 'S';
155804 l_component_appl_id          :=  140;
155805 l_amb_context_code           := 'DEFAULT';
155806 l_entity_code                := 'TRANSACTIONS';
155807 l_event_class_code           := 'TRANSFERS';
155808 l_event_type_code            := 'TRANSFERS_ALL';
155809 l_line_definition_owner_code := 'S';
155810 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
155811 --
155812 l_balance_type_code          := 'A';
155813 l_segment                     := NULL;
155814 l_ccid                        := NULL;
155815 l_adr_transaction_coa_id      := NULL;
155816 l_adr_accounting_coa_id       := NULL;
155817 l_adr_flexfield_segment_code  := NULL;
155818 l_adr_flex_value_set_id       := NULL;
155819 l_adr_value_type_code         := NULL;
155820 l_adr_value_combination_id    := NULL;
155821 l_adr_value_segment_code      := NULL;
155822 
155823 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
155824 l_bflow_class_code           := '';    -- 4219869 Business Flow
155825 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
155826 l_budgetary_control_flag     := 'N';
155827 
155828 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
155829 l_bflow_applied_to_amt       := NULL; -- 5132302
155830 l_entered_amt_idx            := NULL;          -- 4262811
155831 l_accted_amt_idx             := NULL;          -- 4262811
155832 l_acc_rev_flag               := NULL;          -- 4262811
155833 l_accrual_line_num           := NULL;          -- 4262811
155834 l_tmp_amt                    := NULL;          -- 4262811
155835 --
155836  
155837 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
155838     l_balance_type_code <> 'B' THEN
155839 IF (NVL(p_source_35,'
155840 ') =  'RESERVE' OR 
155841 NVL(p_source_35,'
155842 ') =  'EXPENSE') AND 
155843 NVL(p_source_42,'
155844 ') =  'DEST'
155845  THEN 
155846 
155847    --
155848    XLA_AE_LINES_PKG.SetNewLine;
155849 
155850    p_balance_type_code          := l_balance_type_code;
155851    -- set the flag so later we will know whether the gain loss line needs to be created
155852    
155853    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
155854      p_actual_flag :='A';
155855    END IF;
155856 
155857    --
155858    -- bulk performance
155859    --
155860    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
155861                                       p_header_num   => 0); -- 4262811
155862    --
155863    -- set accounting line options
155864    --
155865    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
155866            p_natural_side_code          => 'C'
155867          , p_gain_or_loss_flag          => 'N'
155868          , p_gl_transfer_mode_code      => 'S'
155869          , p_acct_entry_type_code       => 'A'
155870          , p_switch_side_flag           => 'Y'
155871          , p_merge_duplicate_code       => 'N'
155872          );
155873    --
155874    l_acc_rev_natural_side_code := 'D';  -- 4262811
155875    -- 
155876    --
155877    -- set accounting line type info
155878    --
155879    xla_ae_lines_pkg.SetAcctLineType
155880       (p_component_type             => l_component_type
155881       ,p_event_type_code            => l_event_type_code
155882       ,p_line_definition_owner_code => l_line_definition_owner_code
155883       ,p_line_definition_code       => l_line_definition_code
155884       ,p_accounting_line_code       => l_component_code
155885       ,p_accounting_line_type_code  => l_component_type_code
155886       ,p_accounting_line_appl_id    => l_component_appl_id
155887       ,p_amb_context_code           => l_amb_context_code
155888       ,p_entity_code                => l_entity_code
155889       ,p_event_class_code           => l_event_class_code);
155890    --
155891    -- set accounting class
155892    --
155893    xla_ae_lines_pkg.SetAcctClass(
155894            p_accounting_class_code  => 'ASSET'
155895          , p_ae_header_id           => l_ae_header_id
155896          );
155897 
155898    --
155899    -- set rounding class
155900    --
155901    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
155902                       'ASSET';
155903 
155904    --
155908    -- bulk performance
155905    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
155906    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
155907    --
155909    --
155910    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
155911 
155912    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
155913       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
155914 
155915    -- 4955764
155916    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
155917       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
155918 
155919    -- 4458381 Public Sector Enh
155920    
155921    --
155922    -- set accounting attributes for the line type
155923    --
155924    l_entered_amt_idx := 4;
155925    l_accted_amt_idx  := 6;
155926    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
155927    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
155928    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
155929    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
155930    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
155931    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
155932    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
155933    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
155934    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
155935    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
155936    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
155937    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
155938    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
155939 
155940    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
155941    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
155942 
155943    ---------------------------------------------------------------------------------------------------------------
155944    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
155945    ---------------------------------------------------------------------------------------------------------------
155946    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
155947 
155948    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
155949    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
155950 
155951    IF xla_accounting_cache_pkg.GetValueChar
155952          (p_source_code         => 'LEDGER_CATEGORY_CODE'
155953          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
155954    AND l_bflow_method_code = 'PRIOR_ENTRY'
155955 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
155956    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
155957          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
155958        )
155959    THEN
155960          xla_ae_lines_pkg.BflowUpgEntry
155961            (p_business_method_code    => l_bflow_method_code
155962            ,p_business_class_code     => l_bflow_class_code
155963            ,p_balance_type            => l_balance_type_code);
155964    ELSE
155965       NULL;
155966 -- No business flow processing for business flow method of NONE.
155967    END IF;
155968 
155969    --
155970    -- call analytical criteria
155971    --
155972    
155973    --
155974    -- call description
155975    --
155976    
155977 xla_ae_lines_pkg.SetLineDescription(
155978    p_ae_header_id => l_ae_header_id
155979   ,p_description  => Description_130 (
155980      p_application_id         => p_application_id
155981    , p_ae_header_id           => l_ae_header_id 
155982 , p_source_1 => p_source_1
155983    )
155984 );
155985 
155986 
155987    --
155988    -- call ADRs
155989    -- Bug 4922099
155990    --
155991    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
155992         (NVL(l_actual_upg_option, 'N') = 'O') OR
155993         (NVL(l_enc_upg_option, 'N') = 'O')
155994       )
155995    THEN
155996    NULL;
155997    --
155998    --
155999    
156000   l_ccid := AcctDerRule_174(
156001            p_application_id           => p_application_id
156002          , p_ae_header_id             => l_ae_header_id 
156003 , p_source_3 => p_source_3
156004 , p_source_17 => p_source_17
156005 , p_source_30 => p_source_30
156006          , x_transaction_coa_id       => l_adr_transaction_coa_id
156007          , x_accounting_coa_id        => l_adr_accounting_coa_id
156008          , x_value_type_code          => l_adr_value_type_code
156009          , p_side                     => 'NA'
156010    );
156011 
156012    xla_ae_lines_pkg.set_ccid(
156013     p_code_combination_id          => l_ccid
156014   , p_value_type_code              => l_adr_value_type_code
156015   , p_transaction_coa_id           => l_adr_transaction_coa_id
156016   , p_accounting_coa_id            => l_adr_accounting_coa_id
156017   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
156018   , p_adr_type_code                => 'S'
156019   , p_component_type               => l_component_type
156020   , p_component_code               => l_component_code
156021   , p_component_type_code          => l_component_type_code
156022   , p_component_appl_id            => l_component_appl_id
156023   , p_amb_context_code             => l_amb_context_code
156024   , p_side                         => 'NA'
156025   );
156026 
156027 
156028    l_segment := AcctDerRule_149(
156029            p_application_id           => p_application_id
156030          , p_ae_header_id             => l_ae_header_id 
156031 , p_source_3 => p_source_3
156035          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
156032 , p_source_10 => p_source_10
156033          , x_transaction_coa_id       => l_adr_transaction_coa_id
156034          , x_accounting_coa_id        => l_adr_accounting_coa_id
156036          , x_flex_value_set_id        => l_adr_flex_value_set_id
156037          , x_value_type_code          => l_adr_value_type_code
156038          , x_value_combination_id     => l_adr_value_combination_id
156039          , x_value_segment_code       => l_adr_value_segment_code
156040          , p_side                     => 'NA'
156041          , p_override_seg_flag        => 'Y'
156042    );
156043 
156044    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
156045 
156046       xla_ae_lines_pkg.set_segment(
156047           p_to_segment_code         => 'GL_ACCOUNT'
156048         , p_segment_value           => l_segment
156049         , p_from_segment_code       => l_adr_value_segment_code
156050         , p_from_combination_id     => l_adr_value_combination_id
156051         , p_value_type_code         => l_adr_value_type_code
156052         , p_transaction_coa_id      => l_adr_transaction_coa_id
156053         , p_accounting_coa_id       => l_adr_accounting_coa_id
156054         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
156055         , p_flex_value_set_id       => l_adr_flex_value_set_id
156056         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
156057         , p_adr_type_code           => 'S'
156058         , p_component_type          => l_component_type
156059         , p_component_code          => l_component_code
156060         , p_component_type_code     => l_component_type_code
156061         , p_component_appl_id       => l_component_appl_id
156062         , p_amb_context_code        => l_amb_context_code
156063         , p_entity_code             => 'TRANSACTIONS'
156064         , p_event_class_code        => 'TRANSFERS'
156065         , p_side                    => 'NA'
156066         );
156067 
156068   END IF;
156069 
156070    l_segment := AcctDerRule_168(
156071            p_application_id           => p_application_id
156072          , p_ae_header_id             => l_ae_header_id 
156073 , p_source_3 => p_source_3
156074 , p_source_29 => p_source_29
156075          , x_transaction_coa_id       => l_adr_transaction_coa_id
156076          , x_accounting_coa_id        => l_adr_accounting_coa_id
156077          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
156078          , x_flex_value_set_id        => l_adr_flex_value_set_id
156079          , x_value_type_code          => l_adr_value_type_code
156080          , x_value_combination_id     => l_adr_value_combination_id
156081          , x_value_segment_code       => l_adr_value_segment_code
156082          , p_side                     => 'NA'
156083          , p_override_seg_flag        => 'Y'
156084    );
156085 
156086    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
156087 
156088       xla_ae_lines_pkg.set_segment(
156089           p_to_segment_code         => 'GL_BALANCING'
156090         , p_segment_value           => l_segment
156091         , p_from_segment_code       => l_adr_value_segment_code
156092         , p_from_combination_id     => l_adr_value_combination_id
156093         , p_value_type_code         => l_adr_value_type_code
156094         , p_transaction_coa_id      => l_adr_transaction_coa_id
156095         , p_accounting_coa_id       => l_adr_accounting_coa_id
156096         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
156097         , p_flex_value_set_id       => l_adr_flex_value_set_id
156098         , p_adr_code                => 'FA_EXPENSE_ACCT'
156099         , p_adr_type_code           => 'S'
156100         , p_component_type          => l_component_type
156101         , p_component_code          => l_component_code
156102         , p_component_type_code     => l_component_type_code
156103         , p_component_appl_id       => l_component_appl_id
156104         , p_amb_context_code        => l_amb_context_code
156105         , p_entity_code             => 'TRANSACTIONS'
156106         , p_event_class_code        => 'TRANSFERS'
156107         , p_side                    => 'NA'
156108         );
156109 
156110   END IF;
156111 
156112    --
156113    --
156114    END IF;
156115    --
156116    -- Bug 4922099
156117    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
156118           (NVL(l_enc_upg_option, 'N') = 'O')
156119         ) AND
156120         (l_bflow_method_code = 'PRIOR_ENTRY')
156121       )
156122    THEN
156123       IF
156124       --
156125       1 = 2
156126       --
156127       THEN
156128       xla_accounting_err_pkg.build_message
156129                                     (p_appli_s_name            => 'XLA'
156130                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
156131                                     ,p_token_1                 => 'LINE_NUMBER'
156132                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
156133                                     ,p_token_2                 => 'LINE_TYPE_NAME'
156134                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
156135                                                                              l_component_type
156136                                                                             ,l_component_code
156137                                                                             ,l_component_type_code
156138                                                                             ,l_component_appl_id
156139                                                                             ,l_amb_context_code
156140                                                                             ,l_entity_code
156141                                                                             ,l_event_class_code
156142                                                                            )
156143                                     ,p_token_3                 => 'OWNER'
156147                                                                          )
156144                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
156145                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
156146                                                                           ,p_lookup_code    => l_component_type_code
156148                                     ,p_token_4                 => 'PRODUCT_NAME'
156149                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
156150                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
156151                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
156152                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
156153                                     ,p_ae_header_id            =>  NULL
156154                                        );
156155 
156156         IF (C_LEVEL_ERROR>= g_log_level) THEN
156157                  trace
156158                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
156159                       ,p_level    => C_LEVEL_ERROR
156160                       ,p_module   => l_log_module);
156161         END IF;
156162       END IF;
156163    END IF;
156164    --
156165    --
156166    ------------------------------------------------------------------------------------------------
156167    -- 4219869 Business Flow
156168    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
156169    -- Prior Entry.  Currently, the following code is always generated.
156170    ------------------------------------------------------------------------------------------------
156171    XLA_AE_LINES_PKG.ValidateCurrentLine;
156172 
156173    ------------------------------------------------------------------------------------
156174    -- 4219869 Business Flow
156175    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
156176    ------------------------------------------------------------------------------------
156177    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
156178 
156179    ----------------------------------------------------------------------------------
156180    -- 4219869 Business Flow
156181    -- Update journal entry status -- Need to generate this within IF <condition>
156182    ----------------------------------------------------------------------------------
156183    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
156184          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
156185          ,p_balance_type_code => l_balance_type_code
156186          );
156187 
156188    -------------------------------------------------------------------------------------------
156189    -- 4262811 - Generate the Accrual Reversal lines
156190    -------------------------------------------------------------------------------------------
156191    BEGIN
156192       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
156193                               (g_array_event(p_event_id).array_value_num('header_index'));
156194       IF l_acc_rev_flag IS NULL THEN
156195          l_acc_rev_flag := 'N';
156196       END IF;
156197    EXCEPTION
156198       WHEN OTHERS THEN
156199          l_acc_rev_flag := 'N';
156200    END;
156201    --
156202    IF (l_acc_rev_flag = 'Y') THEN
156203 
156204        -- 4645092  ------------------------------------------------------------------------------
156205        -- To allow MPA report to determine if it should generate report process
156206        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
156207        ------------------------------------------------------------------------------------------
156208 
156209        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
156210        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
156211    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
156212    -- call ADRs
156213    -- Bug 4922099
156214    --
156215    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
156216         (NVL(l_actual_upg_option, 'N') = 'O') OR
156217         (NVL(l_enc_upg_option, 'N') = 'O')
156218       )
156219    THEN
156220    NULL;
156221    --
156222    --
156223    
156224   l_ccid := AcctDerRule_174(
156225            p_application_id           => p_application_id
156226          , p_ae_header_id             => l_ae_header_id 
156227 , p_source_3 => p_source_3
156228 , p_source_17 => p_source_17
156229 , p_source_30 => p_source_30
156230          , x_transaction_coa_id       => l_adr_transaction_coa_id
156231          , x_accounting_coa_id        => l_adr_accounting_coa_id
156232          , x_value_type_code          => l_adr_value_type_code
156233          , p_side                     => 'NA'
156234    );
156235 
156236    xla_ae_lines_pkg.set_ccid(
156237     p_code_combination_id          => l_ccid
156238   , p_value_type_code              => l_adr_value_type_code
156239   , p_transaction_coa_id           => l_adr_transaction_coa_id
156240   , p_accounting_coa_id            => l_adr_accounting_coa_id
156241   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
156242   , p_adr_type_code                => 'S'
156243   , p_component_type               => l_component_type
156244   , p_component_code               => l_component_code
156245   , p_component_type_code          => l_component_type_code
156246   , p_component_appl_id            => l_component_appl_id
156247   , p_amb_context_code             => l_amb_context_code
156248   , p_side                         => 'NA'
156249   );
156250 
156251 
156252    l_segment := AcctDerRule_149(
156253            p_application_id           => p_application_id
156254          , p_ae_header_id             => l_ae_header_id 
156255 , p_source_3 => p_source_3
156256 , p_source_10 => p_source_10
156260          , x_flex_value_set_id        => l_adr_flex_value_set_id
156257          , x_transaction_coa_id       => l_adr_transaction_coa_id
156258          , x_accounting_coa_id        => l_adr_accounting_coa_id
156259          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
156261          , x_value_type_code          => l_adr_value_type_code
156262          , x_value_combination_id     => l_adr_value_combination_id
156263          , x_value_segment_code       => l_adr_value_segment_code
156264          , p_side                     => 'NA'
156265          , p_override_seg_flag        => 'Y'
156266    );
156267 
156268    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
156269 
156270       xla_ae_lines_pkg.set_segment(
156271           p_to_segment_code         => 'GL_ACCOUNT'
156272         , p_segment_value           => l_segment
156273         , p_from_segment_code       => l_adr_value_segment_code
156274         , p_from_combination_id     => l_adr_value_combination_id
156275         , p_value_type_code         => l_adr_value_type_code
156276         , p_transaction_coa_id      => l_adr_transaction_coa_id
156277         , p_accounting_coa_id       => l_adr_accounting_coa_id
156278         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
156279         , p_flex_value_set_id       => l_adr_flex_value_set_id
156280         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
156281         , p_adr_type_code           => 'S'
156282         , p_component_type          => l_component_type
156283         , p_component_code          => l_component_code
156284         , p_component_type_code     => l_component_type_code
156285         , p_component_appl_id       => l_component_appl_id
156286         , p_amb_context_code        => l_amb_context_code
156287         , p_entity_code             => 'TRANSACTIONS'
156288         , p_event_class_code        => 'TRANSFERS'
156289         , p_side                    => 'NA'
156290         );
156291 
156292   END IF;
156293 
156294    l_segment := AcctDerRule_168(
156295            p_application_id           => p_application_id
156296          , p_ae_header_id             => l_ae_header_id 
156297 , p_source_3 => p_source_3
156298 , p_source_29 => p_source_29
156299          , x_transaction_coa_id       => l_adr_transaction_coa_id
156300          , x_accounting_coa_id        => l_adr_accounting_coa_id
156301          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
156302          , x_flex_value_set_id        => l_adr_flex_value_set_id
156303          , x_value_type_code          => l_adr_value_type_code
156304          , x_value_combination_id     => l_adr_value_combination_id
156305          , x_value_segment_code       => l_adr_value_segment_code
156306          , p_side                     => 'NA'
156307          , p_override_seg_flag        => 'Y'
156308    );
156309 
156310    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
156311 
156312       xla_ae_lines_pkg.set_segment(
156313           p_to_segment_code         => 'GL_BALANCING'
156314         , p_segment_value           => l_segment
156315         , p_from_segment_code       => l_adr_value_segment_code
156316         , p_from_combination_id     => l_adr_value_combination_id
156317         , p_value_type_code         => l_adr_value_type_code
156318         , p_transaction_coa_id      => l_adr_transaction_coa_id
156319         , p_accounting_coa_id       => l_adr_accounting_coa_id
156320         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
156321         , p_flex_value_set_id       => l_adr_flex_value_set_id
156322         , p_adr_code                => 'FA_EXPENSE_ACCT'
156323         , p_adr_type_code           => 'S'
156324         , p_component_type          => l_component_type
156325         , p_component_code          => l_component_code
156326         , p_component_type_code     => l_component_type_code
156327         , p_component_appl_id       => l_component_appl_id
156328         , p_amb_context_code        => l_amb_context_code
156329         , p_entity_code             => 'TRANSACTIONS'
156330         , p_event_class_code        => 'TRANSFERS'
156331         , p_side                    => 'NA'
156332         );
156333 
156334   END IF;
156335 
156336    --
156337    --
156338    END IF;
156339 
156340        --
156341        -- Update the line information that should be overwritten
156342        --
156343        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
156344                                          p_header_num   => 1);
156345        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
156346 
156347        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
156348 
156349        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
156350           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
156351        END IF;
156352 
156353       --
156354       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
156355       --
156356       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
156357           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
156358       ELSE
156359           ---------------------------------------------------------------------------------------------------
156360           -- 4262811a Switch Sign
156361           ---------------------------------------------------------------------------------------------------
156362           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
156363           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
156364                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
156365           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
156369                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
156366                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
156367           -- 5132302
156368           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
156370 
156371       END IF;
156372 
156373       -- 4955764
156374       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
156375       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
156376 
156377 
156378       XLA_AE_LINES_PKG.ValidateCurrentLine;
156379       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
156380 
156381       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
156382                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
156383                ,p_balance_type_code => l_balance_type_code);
156384 
156385    END IF;
156386 
156387    -----------------------------------------------------------------------------------------
156388    -- 4262811 Multiperiod Accounting
156389    -----------------------------------------------------------------------------------------
156390      -- No MPA option is assigned.
156391 
156392 
156393 END IF;
156394 END IF;
156395 --
156396 
156397 --
156398 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
156399    trace
156400       (p_msg      => 'END of AcctLineType_373'
156401       ,p_level    => C_LEVEL_PROCEDURE
156402       ,p_module   => l_log_module);
156403 END IF;
156404 --
156405 EXCEPTION
156406   WHEN xla_exceptions_pkg.application_exception THEN
156407       RAISE;
156408   WHEN OTHERS THEN
156409        xla_exceptions_pkg.raise_message
156410            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_373');
156411 END AcctLineType_373;
156412 --
156413 
156414 ---------------------------------------
156415 --
156416 -- PRIVATE FUNCTION
156417 --         AcctLineType_374
156418 --
156419 ---------------------------------------
156420 PROCEDURE AcctLineType_374 (
156421   p_application_id        IN NUMBER
156422  ,p_event_id              IN NUMBER
156423  ,p_calculate_acctd_flag  IN VARCHAR2
156424  ,p_calculate_g_l_flag    IN VARCHAR2
156425  ,p_actual_flag           IN OUT VARCHAR2
156426  ,p_balance_type_code     OUT VARCHAR2
156427  ,p_gain_or_loss_ref      OUT VARCHAR2
156428  
156429 --Period Close Date
156430  , p_source_1            IN DATE
156431 --Generated Code Combination Identifier
156432  , p_source_3            IN NUMBER
156433 --Expense Account Code Combination Identifier
156434  , p_source_29            IN NUMBER
156435 --Adjustment Type
156436  , p_source_35            IN VARCHAR2
156437 --Transaction Header Identifier
156438  , p_source_36            IN NUMBER
156439 --Adjustment Line Identifier
156440  , p_source_37            IN NUMBER
156441 --Distribution Type Code
156442  , p_source_38            IN VARCHAR2
156443 --Entered Amount
156444  , p_source_39            IN NUMBER
156445 --Currency Code
156446  , p_source_40            IN VARCHAR2
156447 --Source Destination Code
156448  , p_source_42            IN VARCHAR2
156449 )
156450 IS
156451 
156452 l_component_type              VARCHAR2(80);
156453 l_component_code              VARCHAR2(30);
156454 l_component_type_code         VARCHAR2(1);
156455 l_component_appl_id           INTEGER;
156456 l_amb_context_code            VARCHAR2(30);
156457 l_entity_code                 VARCHAR2(30);
156458 l_event_class_code            VARCHAR2(30);
156459 l_ae_header_id                NUMBER;
156460 l_event_type_code             VARCHAR2(30);
156461 l_line_definition_code        VARCHAR2(30);
156462 l_line_definition_owner_code  VARCHAR2(1);
156463 --
156464 -- adr variables
156465 l_segment                     VARCHAR2(30);
156466 l_ccid                        NUMBER;
156467 l_adr_transaction_coa_id      NUMBER;
156468 l_adr_accounting_coa_id       NUMBER;
156469 l_adr_flexfield_segment_code  VARCHAR2(30);
156470 l_adr_flex_value_set_id       NUMBER;
156471 l_adr_value_type_code         VARCHAR2(30);
156472 l_adr_value_combination_id    NUMBER;
156473 l_adr_value_segment_code      VARCHAR2(30);
156474 
156475 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
156476 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
156477 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
156478 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
156479 
156480 -- 4262811 Variables ------------------------------------------------------------------------------------------
156481 l_entered_amt_idx             NUMBER;
156482 l_accted_amt_idx              NUMBER;
156483 l_acc_rev_flag                VARCHAR2(1);
156484 l_accrual_line_num            NUMBER;
156485 l_tmp_amt                     NUMBER;
156486 l_acc_rev_natural_side_code   VARCHAR2(1);
156487 
156488 l_num_entries                 NUMBER;
156489 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
156490 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
156491 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
156492 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
156493 l_recog_line_1                NUMBER;
156494 l_recog_line_2                NUMBER;
156495 
156496 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
156497 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
156498 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
156499 
156500 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
156501 
156502 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
156506 
156503 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
156504 
156505 ---------------------------------------------------------------------------------------------------------------
156507 
156508 --
156509 -- bulk performance
156510 --
156511 l_balance_type_code           VARCHAR2(1);
156512 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
156513 l_log_module                  VARCHAR2(240);
156514 
156515 --
156516 -- Upgrade strategy
156517 --
156518 l_actual_upg_option           VARCHAR2(1);
156519 l_enc_upg_option           VARCHAR2(1);
156520 
156521 --
156522 BEGIN
156523 --
156524 IF g_log_enabled THEN
156525       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_374';
156526 END IF;
156527 --
156528 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
156529 
156530       trace
156531          (p_msg      => 'BEGIN of AcctLineType_374'
156532          ,p_level    => C_LEVEL_PROCEDURE
156533          ,p_module   => l_log_module);
156534 
156535 END IF;
156536 --
156537 l_component_type             := 'AMB_JLT';
156538 l_component_code             := 'FA_TRANSFER_DEST_EXP_BAL';
156539 l_component_type_code        := 'S';
156540 l_component_appl_id          :=  140;
156541 l_amb_context_code           := 'DEFAULT';
156542 l_entity_code                := 'TRANSACTIONS';
156543 l_event_class_code           := 'TRANSFERS';
156544 l_event_type_code            := 'TRANSFERS_ALL';
156545 l_line_definition_owner_code := 'S';
156546 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
156547 --
156548 l_balance_type_code          := 'A';
156549 l_segment                     := NULL;
156550 l_ccid                        := NULL;
156551 l_adr_transaction_coa_id      := NULL;
156552 l_adr_accounting_coa_id       := NULL;
156553 l_adr_flexfield_segment_code  := NULL;
156554 l_adr_flex_value_set_id       := NULL;
156555 l_adr_value_type_code         := NULL;
156556 l_adr_value_combination_id    := NULL;
156557 l_adr_value_segment_code      := NULL;
156558 
156559 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
156560 l_bflow_class_code           := '';    -- 4219869 Business Flow
156561 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
156562 l_budgetary_control_flag     := 'N';
156563 
156564 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
156565 l_bflow_applied_to_amt       := NULL; -- 5132302
156566 l_entered_amt_idx            := NULL;          -- 4262811
156567 l_accted_amt_idx             := NULL;          -- 4262811
156568 l_acc_rev_flag               := NULL;          -- 4262811
156569 l_accrual_line_num           := NULL;          -- 4262811
156570 l_tmp_amt                    := NULL;          -- 4262811
156571 --
156572  
156573 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
156574     l_balance_type_code <> 'B' THEN
156575 IF NVL(p_source_35,'
156576 ') =  'BONUS EXPENSE' AND 
156577 NVL(p_source_42,'
156578 ') =  'DEST'
156579  THEN 
156580 
156581    --
156582    XLA_AE_LINES_PKG.SetNewLine;
156583 
156584    p_balance_type_code          := l_balance_type_code;
156585    -- set the flag so later we will know whether the gain loss line needs to be created
156586    
156587    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
156588      p_actual_flag :='A';
156589    END IF;
156590 
156591    --
156592    -- bulk performance
156593    --
156594    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
156595                                       p_header_num   => 0); -- 4262811
156596    --
156597    -- set accounting line options
156598    --
156599    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
156600            p_natural_side_code          => 'C'
156601          , p_gain_or_loss_flag          => 'N'
156602          , p_gl_transfer_mode_code      => 'S'
156603          , p_acct_entry_type_code       => 'A'
156604          , p_switch_side_flag           => 'Y'
156605          , p_merge_duplicate_code       => 'N'
156606          );
156607    --
156608    l_acc_rev_natural_side_code := 'D';  -- 4262811
156609    -- 
156610    --
156611    -- set accounting line type info
156612    --
156613    xla_ae_lines_pkg.SetAcctLineType
156614       (p_component_type             => l_component_type
156615       ,p_event_type_code            => l_event_type_code
156616       ,p_line_definition_owner_code => l_line_definition_owner_code
156617       ,p_line_definition_code       => l_line_definition_code
156618       ,p_accounting_line_code       => l_component_code
156619       ,p_accounting_line_type_code  => l_component_type_code
156620       ,p_accounting_line_appl_id    => l_component_appl_id
156621       ,p_amb_context_code           => l_amb_context_code
156622       ,p_entity_code                => l_entity_code
156623       ,p_event_class_code           => l_event_class_code);
156624    --
156625    -- set accounting class
156626    --
156627    xla_ae_lines_pkg.SetAcctClass(
156628            p_accounting_class_code  => 'EXPENSE'
156629          , p_ae_header_id           => l_ae_header_id
156630          );
156631 
156632    --
156633    -- set rounding class
156634    --
156635    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
156636                       'EXPENSE';
156637 
156638    --
156639    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
156640    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
156641    --
156642    -- bulk performance
156643    --
156644    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
156645 
156646    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
156650    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
156647       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
156648 
156649    -- 4955764
156651       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
156652 
156653    -- 4458381 Public Sector Enh
156654    
156655    --
156656    -- set accounting attributes for the line type
156657    --
156658    l_entered_amt_idx := 4;
156659    l_accted_amt_idx  := 6;
156660    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
156661    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
156662    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
156663    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
156664    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
156665    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
156666    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
156667    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
156668    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
156669    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
156670    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
156671    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
156672    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
156673 
156674    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
156675    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
156676 
156677    ---------------------------------------------------------------------------------------------------------------
156678    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
156679    ---------------------------------------------------------------------------------------------------------------
156680    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
156681 
156682    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
156683    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
156684 
156685    IF xla_accounting_cache_pkg.GetValueChar
156686          (p_source_code         => 'LEDGER_CATEGORY_CODE'
156687          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
156688    AND l_bflow_method_code = 'PRIOR_ENTRY'
156689 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
156690    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
156691          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
156692        )
156693    THEN
156694          xla_ae_lines_pkg.BflowUpgEntry
156695            (p_business_method_code    => l_bflow_method_code
156696            ,p_business_class_code     => l_bflow_class_code
156697            ,p_balance_type            => l_balance_type_code);
156698    ELSE
156699       NULL;
156700 -- No business flow processing for business flow method of NONE.
156701    END IF;
156702 
156703    --
156704    -- call analytical criteria
156705    --
156706    
156707    --
156708    -- call description
156709    --
156710    
156711 xla_ae_lines_pkg.SetLineDescription(
156712    p_ae_header_id => l_ae_header_id
156713   ,p_description  => Description_127 (
156714      p_application_id         => p_application_id
156715    , p_ae_header_id           => l_ae_header_id 
156716 , p_source_1 => p_source_1
156717    )
156718 );
156719 
156720 
156721    --
156722    -- call ADRs
156723    -- Bug 4922099
156724    --
156725    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
156726         (NVL(l_actual_upg_option, 'N') = 'O') OR
156727         (NVL(l_enc_upg_option, 'N') = 'O')
156728       )
156729    THEN
156730    NULL;
156731    --
156732    --
156733    
156734   l_ccid := AcctDerRule_175(
156735            p_application_id           => p_application_id
156736          , p_ae_header_id             => l_ae_header_id 
156737 , p_source_3 => p_source_3
156738 , p_source_29 => p_source_29
156739          , x_transaction_coa_id       => l_adr_transaction_coa_id
156740          , x_accounting_coa_id        => l_adr_accounting_coa_id
156741          , x_value_type_code          => l_adr_value_type_code
156742          , p_side                     => 'NA'
156743    );
156744 
156745    xla_ae_lines_pkg.set_ccid(
156746     p_code_combination_id          => l_ccid
156747   , p_value_type_code              => l_adr_value_type_code
156748   , p_transaction_coa_id           => l_adr_transaction_coa_id
156749   , p_accounting_coa_id            => l_adr_accounting_coa_id
156750   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
156751   , p_adr_type_code                => 'S'
156752   , p_component_type               => l_component_type
156753   , p_component_code               => l_component_code
156754   , p_component_type_code          => l_component_type_code
156755   , p_component_appl_id            => l_component_appl_id
156756   , p_amb_context_code             => l_amb_context_code
156757   , p_side                         => 'NA'
156758   );
156759 
156760 
156761    --
156762    --
156763    END IF;
156764    --
156765    -- Bug 4922099
156766    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
156767           (NVL(l_enc_upg_option, 'N') = 'O')
156768         ) AND
156769         (l_bflow_method_code = 'PRIOR_ENTRY')
156770       )
156771    THEN
156772       IF
156773       --
156774       1 = 2
156775       --
156776       THEN
156777       xla_accounting_err_pkg.build_message
156778                                     (p_appli_s_name            => 'XLA'
156779                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
156783                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
156780                                     ,p_token_1                 => 'LINE_NUMBER'
156781                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
156782                                     ,p_token_2                 => 'LINE_TYPE_NAME'
156784                                                                              l_component_type
156785                                                                             ,l_component_code
156786                                                                             ,l_component_type_code
156787                                                                             ,l_component_appl_id
156788                                                                             ,l_amb_context_code
156789                                                                             ,l_entity_code
156790                                                                             ,l_event_class_code
156791                                                                            )
156792                                     ,p_token_3                 => 'OWNER'
156793                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
156794                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
156795                                                                           ,p_lookup_code    => l_component_type_code
156796                                                                          )
156797                                     ,p_token_4                 => 'PRODUCT_NAME'
156798                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
156799                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
156800                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
156801                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
156802                                     ,p_ae_header_id            =>  NULL
156803                                        );
156804 
156805         IF (C_LEVEL_ERROR>= g_log_level) THEN
156806                  trace
156807                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
156808                       ,p_level    => C_LEVEL_ERROR
156809                       ,p_module   => l_log_module);
156810         END IF;
156811       END IF;
156812    END IF;
156813    --
156814    --
156815    ------------------------------------------------------------------------------------------------
156816    -- 4219869 Business Flow
156817    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
156818    -- Prior Entry.  Currently, the following code is always generated.
156819    ------------------------------------------------------------------------------------------------
156820    XLA_AE_LINES_PKG.ValidateCurrentLine;
156821 
156822    ------------------------------------------------------------------------------------
156823    -- 4219869 Business Flow
156824    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
156825    ------------------------------------------------------------------------------------
156826    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
156827 
156828    ----------------------------------------------------------------------------------
156829    -- 4219869 Business Flow
156830    -- Update journal entry status -- Need to generate this within IF <condition>
156831    ----------------------------------------------------------------------------------
156832    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
156833          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
156834          ,p_balance_type_code => l_balance_type_code
156835          );
156836 
156837    -------------------------------------------------------------------------------------------
156838    -- 4262811 - Generate the Accrual Reversal lines
156839    -------------------------------------------------------------------------------------------
156840    BEGIN
156841       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
156842                               (g_array_event(p_event_id).array_value_num('header_index'));
156843       IF l_acc_rev_flag IS NULL THEN
156844          l_acc_rev_flag := 'N';
156845       END IF;
156846    EXCEPTION
156847       WHEN OTHERS THEN
156848          l_acc_rev_flag := 'N';
156849    END;
156850    --
156851    IF (l_acc_rev_flag = 'Y') THEN
156852 
156853        -- 4645092  ------------------------------------------------------------------------------
156854        -- To allow MPA report to determine if it should generate report process
156855        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
156856        ------------------------------------------------------------------------------------------
156857 
156858        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
156859        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
156860    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
156861    -- call ADRs
156862    -- Bug 4922099
156863    --
156864    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
156865         (NVL(l_actual_upg_option, 'N') = 'O') OR
156866         (NVL(l_enc_upg_option, 'N') = 'O')
156867       )
156868    THEN
156869    NULL;
156870    --
156871    --
156872    
156873   l_ccid := AcctDerRule_175(
156874            p_application_id           => p_application_id
156875          , p_ae_header_id             => l_ae_header_id 
156876 , p_source_3 => p_source_3
156877 , p_source_29 => p_source_29
156878          , x_transaction_coa_id       => l_adr_transaction_coa_id
156879          , x_accounting_coa_id        => l_adr_accounting_coa_id
156880          , x_value_type_code          => l_adr_value_type_code
156881          , p_side                     => 'NA'
156885     p_code_combination_id          => l_ccid
156882    );
156883 
156884    xla_ae_lines_pkg.set_ccid(
156886   , p_value_type_code              => l_adr_value_type_code
156887   , p_transaction_coa_id           => l_adr_transaction_coa_id
156888   , p_accounting_coa_id            => l_adr_accounting_coa_id
156889   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
156890   , p_adr_type_code                => 'S'
156891   , p_component_type               => l_component_type
156892   , p_component_code               => l_component_code
156893   , p_component_type_code          => l_component_type_code
156894   , p_component_appl_id            => l_component_appl_id
156895   , p_amb_context_code             => l_amb_context_code
156896   , p_side                         => 'NA'
156897   );
156898 
156899 
156900    --
156901    --
156902    END IF;
156903 
156904        --
156905        -- Update the line information that should be overwritten
156906        --
156907        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
156908                                          p_header_num   => 1);
156909        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
156910 
156911        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
156912 
156913        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
156914           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
156915        END IF;
156916 
156917       --
156918       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
156919       --
156920       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
156921           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
156922       ELSE
156923           ---------------------------------------------------------------------------------------------------
156924           -- 4262811a Switch Sign
156925           ---------------------------------------------------------------------------------------------------
156926           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
156927           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
156928                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
156929           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
156930                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
156931           -- 5132302
156932           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
156933                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
156934 
156935       END IF;
156936 
156937       -- 4955764
156938       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
156939       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
156940 
156941 
156942       XLA_AE_LINES_PKG.ValidateCurrentLine;
156943       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
156944 
156945       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
156946                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
156947                ,p_balance_type_code => l_balance_type_code);
156948 
156949    END IF;
156950 
156951    -----------------------------------------------------------------------------------------
156952    -- 4262811 Multiperiod Accounting
156953    -----------------------------------------------------------------------------------------
156954      -- No MPA option is assigned.
156955 
156956 
156957 END IF;
156958 END IF;
156959 --
156960 
156961 --
156962 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
156963    trace
156964       (p_msg      => 'END of AcctLineType_374'
156965       ,p_level    => C_LEVEL_PROCEDURE
156966       ,p_module   => l_log_module);
156967 END IF;
156968 --
156969 EXCEPTION
156970   WHEN xla_exceptions_pkg.application_exception THEN
156971       RAISE;
156972   WHEN OTHERS THEN
156973        xla_exceptions_pkg.raise_message
156974            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_374');
156975 END AcctLineType_374;
156976 --
156977 
156978 ---------------------------------------
156979 --
156980 -- PRIVATE FUNCTION
156981 --         AcctLineType_375
156982 --
156983 ---------------------------------------
156984 PROCEDURE AcctLineType_375 (
156985   p_application_id        IN NUMBER
156986  ,p_event_id              IN NUMBER
156987  ,p_calculate_acctd_flag  IN VARCHAR2
156988  ,p_calculate_g_l_flag    IN VARCHAR2
156989  ,p_actual_flag           IN OUT VARCHAR2
156990  ,p_balance_type_code     OUT VARCHAR2
156991  ,p_gain_or_loss_ref      OUT VARCHAR2
156992  
156993 --Period Close Date
156994  , p_source_1            IN DATE
156995 --Generated Code Combination Identifier
156996  , p_source_3            IN NUMBER
156997 --Depreciation Reserve Account
156998  , p_source_10            IN VARCHAR2
156999 --Generated Offset Code Combination Identifier
157000  , p_source_17            IN NUMBER
157001 --Expense Account Code Combination Identifier
157002  , p_source_29            IN NUMBER
157003 --Default Code Combination Identifier
157004  , p_source_30            IN NUMBER
157005 --Adjustment Type
157006  , p_source_35            IN VARCHAR2
157007 --Transaction Header Identifier
157008  , p_source_36            IN NUMBER
157009 --Adjustment Line Identifier
157010  , p_source_37            IN NUMBER
157011 --Distribution Type Code
157012  , p_source_38            IN VARCHAR2
157013 --Entered Amount
157014  , p_source_39            IN NUMBER
157018  , p_source_42            IN VARCHAR2
157015 --Currency Code
157016  , p_source_40            IN VARCHAR2
157017 --Source Destination Code
157019 )
157020 IS
157021 
157022 l_component_type              VARCHAR2(80);
157023 l_component_code              VARCHAR2(30);
157024 l_component_type_code         VARCHAR2(1);
157025 l_component_appl_id           INTEGER;
157026 l_amb_context_code            VARCHAR2(30);
157027 l_entity_code                 VARCHAR2(30);
157028 l_event_class_code            VARCHAR2(30);
157029 l_ae_header_id                NUMBER;
157030 l_event_type_code             VARCHAR2(30);
157031 l_line_definition_code        VARCHAR2(30);
157032 l_line_definition_owner_code  VARCHAR2(1);
157033 --
157034 -- adr variables
157035 l_segment                     VARCHAR2(30);
157036 l_ccid                        NUMBER;
157037 l_adr_transaction_coa_id      NUMBER;
157038 l_adr_accounting_coa_id       NUMBER;
157039 l_adr_flexfield_segment_code  VARCHAR2(30);
157040 l_adr_flex_value_set_id       NUMBER;
157041 l_adr_value_type_code         VARCHAR2(30);
157042 l_adr_value_combination_id    NUMBER;
157043 l_adr_value_segment_code      VARCHAR2(30);
157044 
157045 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
157046 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
157047 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
157048 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
157049 
157050 -- 4262811 Variables ------------------------------------------------------------------------------------------
157051 l_entered_amt_idx             NUMBER;
157052 l_accted_amt_idx              NUMBER;
157053 l_acc_rev_flag                VARCHAR2(1);
157054 l_accrual_line_num            NUMBER;
157055 l_tmp_amt                     NUMBER;
157056 l_acc_rev_natural_side_code   VARCHAR2(1);
157057 
157058 l_num_entries                 NUMBER;
157059 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
157060 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
157061 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
157062 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
157063 l_recog_line_1                NUMBER;
157064 l_recog_line_2                NUMBER;
157065 
157066 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
157067 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
157068 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
157069 
157070 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
157071 
157072 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
157073 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
157074 
157075 ---------------------------------------------------------------------------------------------------------------
157076 
157077 
157078 --
157079 -- bulk performance
157080 --
157081 l_balance_type_code           VARCHAR2(1);
157082 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
157083 l_log_module                  VARCHAR2(240);
157084 
157085 --
157086 -- Upgrade strategy
157087 --
157088 l_actual_upg_option           VARCHAR2(1);
157089 l_enc_upg_option           VARCHAR2(1);
157090 
157091 --
157092 BEGIN
157093 --
157094 IF g_log_enabled THEN
157095       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_375';
157096 END IF;
157097 --
157098 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
157099 
157100       trace
157101          (p_msg      => 'BEGIN of AcctLineType_375'
157102          ,p_level    => C_LEVEL_PROCEDURE
157103          ,p_module   => l_log_module);
157104 
157105 END IF;
157106 --
157107 l_component_type             := 'AMB_JLT';
157108 l_component_code             := 'FA_TRANSFER_DEST_RESERVE_BAL';
157109 l_component_type_code        := 'S';
157110 l_component_appl_id          :=  140;
157111 l_amb_context_code           := 'DEFAULT';
157112 l_entity_code                := 'TRANSACTIONS';
157113 l_event_class_code           := 'TRANSFERS';
157114 l_event_type_code            := 'TRANSFERS_ALL';
157115 l_line_definition_owner_code := 'S';
157116 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
157117 --
157118 l_balance_type_code          := 'A';
157119 l_segment                     := NULL;
157120 l_ccid                        := NULL;
157121 l_adr_transaction_coa_id      := NULL;
157122 l_adr_accounting_coa_id       := NULL;
157123 l_adr_flexfield_segment_code  := NULL;
157124 l_adr_flex_value_set_id       := NULL;
157125 l_adr_value_type_code         := NULL;
157126 l_adr_value_combination_id    := NULL;
157127 l_adr_value_segment_code      := NULL;
157128 
157129 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
157130 l_bflow_class_code           := '';    -- 4219869 Business Flow
157131 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
157132 l_budgetary_control_flag     := 'N';
157133 
157134 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
157135 l_bflow_applied_to_amt       := NULL; -- 5132302
157136 l_entered_amt_idx            := NULL;          -- 4262811
157137 l_accted_amt_idx             := NULL;          -- 4262811
157138 l_acc_rev_flag               := NULL;          -- 4262811
157139 l_accrual_line_num           := NULL;          -- 4262811
157140 l_tmp_amt                    := NULL;          -- 4262811
157141 --
157142  
157143 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
157144     l_balance_type_code <> 'B' THEN
157145 IF (NVL(p_source_35,'
157146 ') =  'BONUS RESERVE' OR 
157147 NVL(p_source_35,'
157148 ') =  'BONUS EXPENSE') AND 
157149 NVL(p_source_42,'
157150 ') =  'DEST'
157151  THEN 
157152 
157153    --
157154    XLA_AE_LINES_PKG.SetNewLine;
157158    
157155 
157156    p_balance_type_code          := l_balance_type_code;
157157    -- set the flag so later we will know whether the gain loss line needs to be created
157159    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
157160      p_actual_flag :='A';
157161    END IF;
157162 
157163    --
157164    -- bulk performance
157165    --
157166    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
157167                                       p_header_num   => 0); -- 4262811
157168    --
157169    -- set accounting line options
157170    --
157171    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
157172            p_natural_side_code          => 'D'
157173          , p_gain_or_loss_flag          => 'N'
157174          , p_gl_transfer_mode_code      => 'S'
157175          , p_acct_entry_type_code       => 'A'
157176          , p_switch_side_flag           => 'Y'
157177          , p_merge_duplicate_code       => 'N'
157178          );
157179    --
157180    l_acc_rev_natural_side_code := 'C';  -- 4262811
157181    -- 
157182    --
157183    -- set accounting line type info
157184    --
157185    xla_ae_lines_pkg.SetAcctLineType
157186       (p_component_type             => l_component_type
157187       ,p_event_type_code            => l_event_type_code
157188       ,p_line_definition_owner_code => l_line_definition_owner_code
157189       ,p_line_definition_code       => l_line_definition_code
157190       ,p_accounting_line_code       => l_component_code
157191       ,p_accounting_line_type_code  => l_component_type_code
157192       ,p_accounting_line_appl_id    => l_component_appl_id
157193       ,p_amb_context_code           => l_amb_context_code
157194       ,p_entity_code                => l_entity_code
157195       ,p_event_class_code           => l_event_class_code);
157196    --
157197    -- set accounting class
157198    --
157199    xla_ae_lines_pkg.SetAcctClass(
157200            p_accounting_class_code  => 'ASSET'
157201          , p_ae_header_id           => l_ae_header_id
157202          );
157203 
157204    --
157205    -- set rounding class
157206    --
157207    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
157208                       'ASSET';
157209 
157210    --
157211    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
157212    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
157213    --
157214    -- bulk performance
157215    --
157216    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
157217 
157218    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
157219       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
157220 
157221    -- 4955764
157222    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
157223       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
157224 
157225    -- 4458381 Public Sector Enh
157226    
157227    --
157228    -- set accounting attributes for the line type
157229    --
157230    l_entered_amt_idx := 4;
157231    l_accted_amt_idx  := 6;
157232    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
157233    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
157234    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
157235    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
157236    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
157237    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
157238    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
157239    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
157240    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
157241    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
157242    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
157243    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
157244    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
157245 
157246    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
157247    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
157248 
157249    ---------------------------------------------------------------------------------------------------------------
157250    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
157251    ---------------------------------------------------------------------------------------------------------------
157252    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
157253 
157254    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
157255    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
157256 
157257    IF xla_accounting_cache_pkg.GetValueChar
157258          (p_source_code         => 'LEDGER_CATEGORY_CODE'
157259          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
157260    AND l_bflow_method_code = 'PRIOR_ENTRY'
157261 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
157262    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
157263          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
157264        )
157265    THEN
157266          xla_ae_lines_pkg.BflowUpgEntry
157267            (p_business_method_code    => l_bflow_method_code
157268            ,p_business_class_code     => l_bflow_class_code
157269            ,p_balance_type            => l_balance_type_code);
157270    ELSE
157271       NULL;
157272 -- No business flow processing for business flow method of NONE.
157273    END IF;
157274 
157275    --
157276    -- call analytical criteria
157277    --
157278    
157282    
157279    --
157280    -- call description
157281    --
157283 xla_ae_lines_pkg.SetLineDescription(
157284    p_ae_header_id => l_ae_header_id
157285   ,p_description  => Description_130 (
157286      p_application_id         => p_application_id
157287    , p_ae_header_id           => l_ae_header_id 
157288 , p_source_1 => p_source_1
157289    )
157290 );
157291 
157292 
157293    --
157294    -- call ADRs
157295    -- Bug 4922099
157296    --
157297    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
157298         (NVL(l_actual_upg_option, 'N') = 'O') OR
157299         (NVL(l_enc_upg_option, 'N') = 'O')
157300       )
157301    THEN
157302    NULL;
157303    --
157304    --
157305    
157306   l_ccid := AcctDerRule_174(
157307            p_application_id           => p_application_id
157308          , p_ae_header_id             => l_ae_header_id 
157309 , p_source_3 => p_source_3
157310 , p_source_17 => p_source_17
157311 , p_source_30 => p_source_30
157312          , x_transaction_coa_id       => l_adr_transaction_coa_id
157313          , x_accounting_coa_id        => l_adr_accounting_coa_id
157314          , x_value_type_code          => l_adr_value_type_code
157315          , p_side                     => 'NA'
157316    );
157317 
157318    xla_ae_lines_pkg.set_ccid(
157319     p_code_combination_id          => l_ccid
157320   , p_value_type_code              => l_adr_value_type_code
157321   , p_transaction_coa_id           => l_adr_transaction_coa_id
157322   , p_accounting_coa_id            => l_adr_accounting_coa_id
157323   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
157324   , p_adr_type_code                => 'S'
157325   , p_component_type               => l_component_type
157326   , p_component_code               => l_component_code
157327   , p_component_type_code          => l_component_type_code
157328   , p_component_appl_id            => l_component_appl_id
157329   , p_amb_context_code             => l_amb_context_code
157330   , p_side                         => 'NA'
157331   );
157332 
157333 
157334    l_segment := AcctDerRule_149(
157335            p_application_id           => p_application_id
157336          , p_ae_header_id             => l_ae_header_id 
157337 , p_source_3 => p_source_3
157338 , p_source_10 => p_source_10
157339          , x_transaction_coa_id       => l_adr_transaction_coa_id
157340          , x_accounting_coa_id        => l_adr_accounting_coa_id
157341          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
157342          , x_flex_value_set_id        => l_adr_flex_value_set_id
157343          , x_value_type_code          => l_adr_value_type_code
157344          , x_value_combination_id     => l_adr_value_combination_id
157345          , x_value_segment_code       => l_adr_value_segment_code
157346          , p_side                     => 'NA'
157347          , p_override_seg_flag        => 'Y'
157348    );
157349 
157350    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
157351 
157352       xla_ae_lines_pkg.set_segment(
157353           p_to_segment_code         => 'GL_ACCOUNT'
157354         , p_segment_value           => l_segment
157355         , p_from_segment_code       => l_adr_value_segment_code
157356         , p_from_combination_id     => l_adr_value_combination_id
157357         , p_value_type_code         => l_adr_value_type_code
157358         , p_transaction_coa_id      => l_adr_transaction_coa_id
157359         , p_accounting_coa_id       => l_adr_accounting_coa_id
157360         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
157361         , p_flex_value_set_id       => l_adr_flex_value_set_id
157362         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
157363         , p_adr_type_code           => 'S'
157364         , p_component_type          => l_component_type
157365         , p_component_code          => l_component_code
157366         , p_component_type_code     => l_component_type_code
157367         , p_component_appl_id       => l_component_appl_id
157368         , p_amb_context_code        => l_amb_context_code
157369         , p_entity_code             => 'TRANSACTIONS'
157370         , p_event_class_code        => 'TRANSFERS'
157371         , p_side                    => 'NA'
157372         );
157373 
157374   END IF;
157375 
157376    l_segment := AcctDerRule_168(
157377            p_application_id           => p_application_id
157378          , p_ae_header_id             => l_ae_header_id 
157379 , p_source_3 => p_source_3
157380 , p_source_29 => p_source_29
157381          , x_transaction_coa_id       => l_adr_transaction_coa_id
157382          , x_accounting_coa_id        => l_adr_accounting_coa_id
157383          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
157384          , x_flex_value_set_id        => l_adr_flex_value_set_id
157385          , x_value_type_code          => l_adr_value_type_code
157386          , x_value_combination_id     => l_adr_value_combination_id
157387          , x_value_segment_code       => l_adr_value_segment_code
157388          , p_side                     => 'NA'
157389          , p_override_seg_flag        => 'Y'
157390    );
157391 
157392    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
157393 
157394       xla_ae_lines_pkg.set_segment(
157395           p_to_segment_code         => 'GL_BALANCING'
157396         , p_segment_value           => l_segment
157397         , p_from_segment_code       => l_adr_value_segment_code
157398         , p_from_combination_id     => l_adr_value_combination_id
157399         , p_value_type_code         => l_adr_value_type_code
157400         , p_transaction_coa_id      => l_adr_transaction_coa_id
157401         , p_accounting_coa_id       => l_adr_accounting_coa_id
157402         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
157403         , p_flex_value_set_id       => l_adr_flex_value_set_id
157404         , p_adr_code                => 'FA_EXPENSE_ACCT'
157405         , p_adr_type_code           => 'S'
157409         , p_component_appl_id       => l_component_appl_id
157406         , p_component_type          => l_component_type
157407         , p_component_code          => l_component_code
157408         , p_component_type_code     => l_component_type_code
157410         , p_amb_context_code        => l_amb_context_code
157411         , p_entity_code             => 'TRANSACTIONS'
157412         , p_event_class_code        => 'TRANSFERS'
157413         , p_side                    => 'NA'
157414         );
157415 
157416   END IF;
157417 
157418    --
157419    --
157420    END IF;
157421    --
157422    -- Bug 4922099
157423    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
157424           (NVL(l_enc_upg_option, 'N') = 'O')
157425         ) AND
157426         (l_bflow_method_code = 'PRIOR_ENTRY')
157427       )
157428    THEN
157429       IF
157430       --
157431       1 = 2
157432       --
157433       THEN
157434       xla_accounting_err_pkg.build_message
157435                                     (p_appli_s_name            => 'XLA'
157436                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
157437                                     ,p_token_1                 => 'LINE_NUMBER'
157438                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
157439                                     ,p_token_2                 => 'LINE_TYPE_NAME'
157440                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
157441                                                                              l_component_type
157442                                                                             ,l_component_code
157443                                                                             ,l_component_type_code
157444                                                                             ,l_component_appl_id
157445                                                                             ,l_amb_context_code
157446                                                                             ,l_entity_code
157447                                                                             ,l_event_class_code
157448                                                                            )
157449                                     ,p_token_3                 => 'OWNER'
157450                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
157451                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
157452                                                                           ,p_lookup_code    => l_component_type_code
157453                                                                          )
157454                                     ,p_token_4                 => 'PRODUCT_NAME'
157455                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
157456                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
157457                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
157458                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
157459                                     ,p_ae_header_id            =>  NULL
157460                                        );
157461 
157462         IF (C_LEVEL_ERROR>= g_log_level) THEN
157463                  trace
157464                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
157465                       ,p_level    => C_LEVEL_ERROR
157466                       ,p_module   => l_log_module);
157467         END IF;
157468       END IF;
157469    END IF;
157470    --
157471    --
157472    ------------------------------------------------------------------------------------------------
157473    -- 4219869 Business Flow
157474    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
157475    -- Prior Entry.  Currently, the following code is always generated.
157476    ------------------------------------------------------------------------------------------------
157477    XLA_AE_LINES_PKG.ValidateCurrentLine;
157478 
157479    ------------------------------------------------------------------------------------
157480    -- 4219869 Business Flow
157481    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
157482    ------------------------------------------------------------------------------------
157483    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
157484 
157485    ----------------------------------------------------------------------------------
157486    -- 4219869 Business Flow
157487    -- Update journal entry status -- Need to generate this within IF <condition>
157488    ----------------------------------------------------------------------------------
157489    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
157490          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
157491          ,p_balance_type_code => l_balance_type_code
157492          );
157493 
157494    -------------------------------------------------------------------------------------------
157495    -- 4262811 - Generate the Accrual Reversal lines
157496    -------------------------------------------------------------------------------------------
157497    BEGIN
157498       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
157499                               (g_array_event(p_event_id).array_value_num('header_index'));
157500       IF l_acc_rev_flag IS NULL THEN
157501          l_acc_rev_flag := 'N';
157502       END IF;
157503    EXCEPTION
157504       WHEN OTHERS THEN
157505          l_acc_rev_flag := 'N';
157506    END;
157507    --
157508    IF (l_acc_rev_flag = 'Y') THEN
157509 
157510        -- 4645092  ------------------------------------------------------------------------------
157511        -- To allow MPA report to determine if it should generate report process
157515        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
157512        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
157513        ------------------------------------------------------------------------------------------
157514 
157516        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
157517    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
157518    -- call ADRs
157519    -- Bug 4922099
157520    --
157521    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
157522         (NVL(l_actual_upg_option, 'N') = 'O') OR
157523         (NVL(l_enc_upg_option, 'N') = 'O')
157524       )
157525    THEN
157526    NULL;
157527    --
157528    --
157529    
157530   l_ccid := AcctDerRule_174(
157531            p_application_id           => p_application_id
157532          , p_ae_header_id             => l_ae_header_id 
157533 , p_source_3 => p_source_3
157534 , p_source_17 => p_source_17
157535 , p_source_30 => p_source_30
157536          , x_transaction_coa_id       => l_adr_transaction_coa_id
157537          , x_accounting_coa_id        => l_adr_accounting_coa_id
157538          , x_value_type_code          => l_adr_value_type_code
157539          , p_side                     => 'NA'
157540    );
157541 
157542    xla_ae_lines_pkg.set_ccid(
157543     p_code_combination_id          => l_ccid
157544   , p_value_type_code              => l_adr_value_type_code
157545   , p_transaction_coa_id           => l_adr_transaction_coa_id
157546   , p_accounting_coa_id            => l_adr_accounting_coa_id
157547   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
157548   , p_adr_type_code                => 'S'
157549   , p_component_type               => l_component_type
157550   , p_component_code               => l_component_code
157551   , p_component_type_code          => l_component_type_code
157552   , p_component_appl_id            => l_component_appl_id
157553   , p_amb_context_code             => l_amb_context_code
157554   , p_side                         => 'NA'
157555   );
157556 
157557 
157558    l_segment := AcctDerRule_149(
157559            p_application_id           => p_application_id
157560          , p_ae_header_id             => l_ae_header_id 
157561 , p_source_3 => p_source_3
157562 , p_source_10 => p_source_10
157563          , x_transaction_coa_id       => l_adr_transaction_coa_id
157564          , x_accounting_coa_id        => l_adr_accounting_coa_id
157565          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
157566          , x_flex_value_set_id        => l_adr_flex_value_set_id
157567          , x_value_type_code          => l_adr_value_type_code
157568          , x_value_combination_id     => l_adr_value_combination_id
157569          , x_value_segment_code       => l_adr_value_segment_code
157570          , p_side                     => 'NA'
157571          , p_override_seg_flag        => 'Y'
157572    );
157573 
157574    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
157575 
157576       xla_ae_lines_pkg.set_segment(
157577           p_to_segment_code         => 'GL_ACCOUNT'
157578         , p_segment_value           => l_segment
157579         , p_from_segment_code       => l_adr_value_segment_code
157580         , p_from_combination_id     => l_adr_value_combination_id
157581         , p_value_type_code         => l_adr_value_type_code
157582         , p_transaction_coa_id      => l_adr_transaction_coa_id
157583         , p_accounting_coa_id       => l_adr_accounting_coa_id
157584         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
157585         , p_flex_value_set_id       => l_adr_flex_value_set_id
157586         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
157587         , p_adr_type_code           => 'S'
157588         , p_component_type          => l_component_type
157589         , p_component_code          => l_component_code
157590         , p_component_type_code     => l_component_type_code
157591         , p_component_appl_id       => l_component_appl_id
157592         , p_amb_context_code        => l_amb_context_code
157593         , p_entity_code             => 'TRANSACTIONS'
157594         , p_event_class_code        => 'TRANSFERS'
157595         , p_side                    => 'NA'
157596         );
157597 
157598   END IF;
157599 
157600    l_segment := AcctDerRule_168(
157601            p_application_id           => p_application_id
157602          , p_ae_header_id             => l_ae_header_id 
157603 , p_source_3 => p_source_3
157604 , p_source_29 => p_source_29
157605          , x_transaction_coa_id       => l_adr_transaction_coa_id
157606          , x_accounting_coa_id        => l_adr_accounting_coa_id
157607          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
157608          , x_flex_value_set_id        => l_adr_flex_value_set_id
157609          , x_value_type_code          => l_adr_value_type_code
157610          , x_value_combination_id     => l_adr_value_combination_id
157611          , x_value_segment_code       => l_adr_value_segment_code
157612          , p_side                     => 'NA'
157613          , p_override_seg_flag        => 'Y'
157614    );
157615 
157616    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
157617 
157618       xla_ae_lines_pkg.set_segment(
157619           p_to_segment_code         => 'GL_BALANCING'
157620         , p_segment_value           => l_segment
157621         , p_from_segment_code       => l_adr_value_segment_code
157622         , p_from_combination_id     => l_adr_value_combination_id
157623         , p_value_type_code         => l_adr_value_type_code
157624         , p_transaction_coa_id      => l_adr_transaction_coa_id
157625         , p_accounting_coa_id       => l_adr_accounting_coa_id
157626         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
157627         , p_flex_value_set_id       => l_adr_flex_value_set_id
157628         , p_adr_code                => 'FA_EXPENSE_ACCT'
157629         , p_adr_type_code           => 'S'
157630         , p_component_type          => l_component_type
157634         , p_amb_context_code        => l_amb_context_code
157631         , p_component_code          => l_component_code
157632         , p_component_type_code     => l_component_type_code
157633         , p_component_appl_id       => l_component_appl_id
157635         , p_entity_code             => 'TRANSACTIONS'
157636         , p_event_class_code        => 'TRANSFERS'
157637         , p_side                    => 'NA'
157638         );
157639 
157640   END IF;
157641 
157642    --
157643    --
157644    END IF;
157645 
157646        --
157647        -- Update the line information that should be overwritten
157648        --
157649        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
157650                                          p_header_num   => 1);
157651        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
157652 
157653        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
157654 
157655        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
157656           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
157657        END IF;
157658 
157659       --
157660       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
157661       --
157662       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
157663           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
157664       ELSE
157665           ---------------------------------------------------------------------------------------------------
157666           -- 4262811a Switch Sign
157667           ---------------------------------------------------------------------------------------------------
157668           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
157669           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
157670                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
157671           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
157672                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
157673           -- 5132302
157674           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
157675                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
157676 
157677       END IF;
157678 
157679       -- 4955764
157680       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
157681       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
157682 
157683 
157684       XLA_AE_LINES_PKG.ValidateCurrentLine;
157685       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
157686 
157687       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
157688                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
157689                ,p_balance_type_code => l_balance_type_code);
157690 
157691    END IF;
157692 
157693    -----------------------------------------------------------------------------------------
157694    -- 4262811 Multiperiod Accounting
157695    -----------------------------------------------------------------------------------------
157696      -- No MPA option is assigned.
157697 
157698 
157699 END IF;
157700 END IF;
157701 --
157702 
157703 --
157704 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
157705    trace
157706       (p_msg      => 'END of AcctLineType_375'
157707       ,p_level    => C_LEVEL_PROCEDURE
157708       ,p_module   => l_log_module);
157709 END IF;
157710 --
157711 EXCEPTION
157712   WHEN xla_exceptions_pkg.application_exception THEN
157713       RAISE;
157714   WHEN OTHERS THEN
157715        xla_exceptions_pkg.raise_message
157716            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_375');
157717 END AcctLineType_375;
157718 --
157719 
157720 ---------------------------------------
157721 --
157722 -- PRIVATE FUNCTION
157723 --         AcctLineType_376
157724 --
157725 ---------------------------------------
157726 PROCEDURE AcctLineType_376 (
157727   p_application_id        IN NUMBER
157728  ,p_event_id              IN NUMBER
157729  ,p_calculate_acctd_flag  IN VARCHAR2
157730  ,p_calculate_g_l_flag    IN VARCHAR2
157731  ,p_actual_flag           IN OUT VARCHAR2
157732  ,p_balance_type_code     OUT VARCHAR2
157733  ,p_gain_or_loss_ref      OUT VARCHAR2
157734  
157735 --Period Close Date
157736  , p_source_1            IN DATE
157737 --Generated Code Combination Identifier
157738  , p_source_3            IN NUMBER
157739 --Revaluation Reserve Account
157740  , p_source_11            IN VARCHAR2
157741 --Generated Offset Code Combination Identifier
157742  , p_source_17            IN NUMBER
157743 --Expense Account Code Combination Identifier
157744  , p_source_29            IN NUMBER
157745 --Default Code Combination Identifier
157746  , p_source_30            IN NUMBER
157747 --Adjustment Type
157748  , p_source_35            IN VARCHAR2
157749 --Transaction Header Identifier
157750  , p_source_36            IN NUMBER
157751 --Adjustment Line Identifier
157752  , p_source_37            IN NUMBER
157753 --Distribution Type Code
157754  , p_source_38            IN VARCHAR2
157755 --Entered Amount
157756  , p_source_39            IN NUMBER
157757 --Currency Code
157758  , p_source_40            IN VARCHAR2
157759 --Source Destination Code
157760  , p_source_42            IN VARCHAR2
157761 )
157762 IS
157763 
157764 l_component_type              VARCHAR2(80);
157765 l_component_code              VARCHAR2(30);
157766 l_component_type_code         VARCHAR2(1);
157770 l_event_class_code            VARCHAR2(30);
157767 l_component_appl_id           INTEGER;
157768 l_amb_context_code            VARCHAR2(30);
157769 l_entity_code                 VARCHAR2(30);
157771 l_ae_header_id                NUMBER;
157772 l_event_type_code             VARCHAR2(30);
157773 l_line_definition_code        VARCHAR2(30);
157774 l_line_definition_owner_code  VARCHAR2(1);
157775 --
157776 -- adr variables
157777 l_segment                     VARCHAR2(30);
157778 l_ccid                        NUMBER;
157779 l_adr_transaction_coa_id      NUMBER;
157780 l_adr_accounting_coa_id       NUMBER;
157781 l_adr_flexfield_segment_code  VARCHAR2(30);
157782 l_adr_flex_value_set_id       NUMBER;
157783 l_adr_value_type_code         VARCHAR2(30);
157784 l_adr_value_combination_id    NUMBER;
157785 l_adr_value_segment_code      VARCHAR2(30);
157786 
157787 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
157788 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
157789 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
157790 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
157791 
157792 -- 4262811 Variables ------------------------------------------------------------------------------------------
157793 l_entered_amt_idx             NUMBER;
157794 l_accted_amt_idx              NUMBER;
157795 l_acc_rev_flag                VARCHAR2(1);
157796 l_accrual_line_num            NUMBER;
157797 l_tmp_amt                     NUMBER;
157798 l_acc_rev_natural_side_code   VARCHAR2(1);
157799 
157800 l_num_entries                 NUMBER;
157801 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
157802 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
157803 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
157804 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
157805 l_recog_line_1                NUMBER;
157806 l_recog_line_2                NUMBER;
157807 
157808 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
157809 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
157810 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
157811 
157812 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
157813 
157814 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
157815 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
157816 
157817 ---------------------------------------------------------------------------------------------------------------
157818 
157819 
157820 --
157821 -- bulk performance
157822 --
157823 l_balance_type_code           VARCHAR2(1);
157824 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
157825 l_log_module                  VARCHAR2(240);
157826 
157827 --
157828 -- Upgrade strategy
157829 --
157830 l_actual_upg_option           VARCHAR2(1);
157831 l_enc_upg_option           VARCHAR2(1);
157832 
157833 --
157834 BEGIN
157835 --
157836 IF g_log_enabled THEN
157837       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_376';
157838 END IF;
157839 --
157840 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
157841 
157842       trace
157843          (p_msg      => 'BEGIN of AcctLineType_376'
157844          ,p_level    => C_LEVEL_PROCEDURE
157845          ,p_module   => l_log_module);
157846 
157847 END IF;
157848 --
157849 l_component_type             := 'AMB_JLT';
157850 l_component_code             := 'FA_TRANSFER_DEST_REVAL_RES';
157851 l_component_type_code        := 'S';
157852 l_component_appl_id          :=  140;
157853 l_amb_context_code           := 'DEFAULT';
157854 l_entity_code                := 'TRANSACTIONS';
157855 l_event_class_code           := 'TRANSFERS';
157856 l_event_type_code            := 'TRANSFERS_ALL';
157857 l_line_definition_owner_code := 'S';
157858 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
157859 --
157860 l_balance_type_code          := 'A';
157861 l_segment                     := NULL;
157862 l_ccid                        := NULL;
157863 l_adr_transaction_coa_id      := NULL;
157864 l_adr_accounting_coa_id       := NULL;
157865 l_adr_flexfield_segment_code  := NULL;
157866 l_adr_flex_value_set_id       := NULL;
157867 l_adr_value_type_code         := NULL;
157868 l_adr_value_combination_id    := NULL;
157869 l_adr_value_segment_code      := NULL;
157870 
157871 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
157872 l_bflow_class_code           := '';    -- 4219869 Business Flow
157873 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
157874 l_budgetary_control_flag     := 'N';
157875 
157876 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
157877 l_bflow_applied_to_amt       := NULL; -- 5132302
157878 l_entered_amt_idx            := NULL;          -- 4262811
157879 l_accted_amt_idx             := NULL;          -- 4262811
157880 l_acc_rev_flag               := NULL;          -- 4262811
157881 l_accrual_line_num           := NULL;          -- 4262811
157882 l_tmp_amt                    := NULL;          -- 4262811
157883 --
157884  
157885 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
157886     l_balance_type_code <> 'B' THEN
157887 IF NVL(p_source_35,'
157888 ') =  'REVAL RESERVE' AND 
157889 NVL(p_source_42,'
157890 ') =  'DEST'
157891  THEN 
157892 
157893    --
157894    XLA_AE_LINES_PKG.SetNewLine;
157895 
157896    p_balance_type_code          := l_balance_type_code;
157897    -- set the flag so later we will know whether the gain loss line needs to be created
157898    
157899    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
157900      p_actual_flag :='A';
157901    END IF;
157902 
157903    --
157904    -- bulk performance
157905    --
157909    -- set accounting line options
157906    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
157907                                       p_header_num   => 0); -- 4262811
157908    --
157910    --
157911    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
157912            p_natural_side_code          => 'C'
157913          , p_gain_or_loss_flag          => 'N'
157914          , p_gl_transfer_mode_code      => 'S'
157915          , p_acct_entry_type_code       => 'A'
157916          , p_switch_side_flag           => 'Y'
157917          , p_merge_duplicate_code       => 'N'
157918          );
157919    --
157920    l_acc_rev_natural_side_code := 'D';  -- 4262811
157921    -- 
157922    --
157923    -- set accounting line type info
157924    --
157925    xla_ae_lines_pkg.SetAcctLineType
157926       (p_component_type             => l_component_type
157927       ,p_event_type_code            => l_event_type_code
157928       ,p_line_definition_owner_code => l_line_definition_owner_code
157929       ,p_line_definition_code       => l_line_definition_code
157930       ,p_accounting_line_code       => l_component_code
157931       ,p_accounting_line_type_code  => l_component_type_code
157932       ,p_accounting_line_appl_id    => l_component_appl_id
157933       ,p_amb_context_code           => l_amb_context_code
157934       ,p_entity_code                => l_entity_code
157935       ,p_event_class_code           => l_event_class_code);
157936    --
157937    -- set accounting class
157938    --
157939    xla_ae_lines_pkg.SetAcctClass(
157940            p_accounting_class_code  => 'ASSET'
157941          , p_ae_header_id           => l_ae_header_id
157942          );
157943 
157944    --
157945    -- set rounding class
157946    --
157947    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
157948                       'ASSET';
157949 
157950    --
157951    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
157952    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
157953    --
157954    -- bulk performance
157955    --
157956    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
157957 
157958    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
157959       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
157960 
157961    -- 4955764
157962    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
157963       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
157964 
157965    -- 4458381 Public Sector Enh
157966    
157967    --
157968    -- set accounting attributes for the line type
157969    --
157970    l_entered_amt_idx := 4;
157971    l_accted_amt_idx  := 6;
157972    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
157973    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
157974    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
157975    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
157976    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
157977    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
157978    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
157979    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
157980    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
157981    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
157982    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
157983    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
157984    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
157985 
157986    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
157987    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
157988 
157989    ---------------------------------------------------------------------------------------------------------------
157990    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
157991    ---------------------------------------------------------------------------------------------------------------
157992    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
157993 
157994    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
157995    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
157996 
157997    IF xla_accounting_cache_pkg.GetValueChar
157998          (p_source_code         => 'LEDGER_CATEGORY_CODE'
157999          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
158000    AND l_bflow_method_code = 'PRIOR_ENTRY'
158001 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
158002    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
158003          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
158004        )
158005    THEN
158006          xla_ae_lines_pkg.BflowUpgEntry
158007            (p_business_method_code    => l_bflow_method_code
158008            ,p_business_class_code     => l_bflow_class_code
158009            ,p_balance_type            => l_balance_type_code);
158010    ELSE
158011       NULL;
158012 -- No business flow processing for business flow method of NONE.
158013    END IF;
158014 
158015    --
158016    -- call analytical criteria
158017    --
158018    
158019    --
158020    -- call description
158021    --
158022    
158023 xla_ae_lines_pkg.SetLineDescription(
158024    p_ae_header_id => l_ae_header_id
158025   ,p_description  => Description_131 (
158026      p_application_id         => p_application_id
158027    , p_ae_header_id           => l_ae_header_id 
158028 , p_source_1 => p_source_1
158029    )
158033    --
158030 );
158031 
158032 
158034    -- call ADRs
158035    -- Bug 4922099
158036    --
158037    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
158038         (NVL(l_actual_upg_option, 'N') = 'O') OR
158039         (NVL(l_enc_upg_option, 'N') = 'O')
158040       )
158041    THEN
158042    NULL;
158043    --
158044    --
158045    
158046   l_ccid := AcctDerRule_174(
158047            p_application_id           => p_application_id
158048          , p_ae_header_id             => l_ae_header_id 
158049 , p_source_3 => p_source_3
158050 , p_source_17 => p_source_17
158051 , p_source_30 => p_source_30
158052          , x_transaction_coa_id       => l_adr_transaction_coa_id
158053          , x_accounting_coa_id        => l_adr_accounting_coa_id
158054          , x_value_type_code          => l_adr_value_type_code
158055          , p_side                     => 'NA'
158056    );
158057 
158058    xla_ae_lines_pkg.set_ccid(
158059     p_code_combination_id          => l_ccid
158060   , p_value_type_code              => l_adr_value_type_code
158061   , p_transaction_coa_id           => l_adr_transaction_coa_id
158062   , p_accounting_coa_id            => l_adr_accounting_coa_id
158063   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
158064   , p_adr_type_code                => 'S'
158065   , p_component_type               => l_component_type
158066   , p_component_code               => l_component_code
158067   , p_component_type_code          => l_component_type_code
158068   , p_component_appl_id            => l_component_appl_id
158069   , p_amb_context_code             => l_amb_context_code
158070   , p_side                         => 'NA'
158071   );
158072 
158073 
158074    l_segment := AcctDerRule_150(
158075            p_application_id           => p_application_id
158076          , p_ae_header_id             => l_ae_header_id 
158077 , p_source_3 => p_source_3
158078 , p_source_11 => p_source_11
158079          , x_transaction_coa_id       => l_adr_transaction_coa_id
158080          , x_accounting_coa_id        => l_adr_accounting_coa_id
158081          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
158082          , x_flex_value_set_id        => l_adr_flex_value_set_id
158083          , x_value_type_code          => l_adr_value_type_code
158084          , x_value_combination_id     => l_adr_value_combination_id
158085          , x_value_segment_code       => l_adr_value_segment_code
158086          , p_side                     => 'NA'
158087          , p_override_seg_flag        => 'Y'
158088    );
158089 
158090    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
158091 
158092       xla_ae_lines_pkg.set_segment(
158093           p_to_segment_code         => 'GL_ACCOUNT'
158094         , p_segment_value           => l_segment
158095         , p_from_segment_code       => l_adr_value_segment_code
158096         , p_from_combination_id     => l_adr_value_combination_id
158097         , p_value_type_code         => l_adr_value_type_code
158098         , p_transaction_coa_id      => l_adr_transaction_coa_id
158099         , p_accounting_coa_id       => l_adr_accounting_coa_id
158100         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
158101         , p_flex_value_set_id       => l_adr_flex_value_set_id
158102         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
158103         , p_adr_type_code           => 'S'
158104         , p_component_type          => l_component_type
158105         , p_component_code          => l_component_code
158106         , p_component_type_code     => l_component_type_code
158107         , p_component_appl_id       => l_component_appl_id
158108         , p_amb_context_code        => l_amb_context_code
158109         , p_entity_code             => 'TRANSACTIONS'
158110         , p_event_class_code        => 'TRANSFERS'
158111         , p_side                    => 'NA'
158112         );
158113 
158114   END IF;
158115 
158116    l_segment := AcctDerRule_168(
158117            p_application_id           => p_application_id
158118          , p_ae_header_id             => l_ae_header_id 
158119 , p_source_3 => p_source_3
158120 , p_source_29 => p_source_29
158121          , x_transaction_coa_id       => l_adr_transaction_coa_id
158122          , x_accounting_coa_id        => l_adr_accounting_coa_id
158123          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
158124          , x_flex_value_set_id        => l_adr_flex_value_set_id
158125          , x_value_type_code          => l_adr_value_type_code
158126          , x_value_combination_id     => l_adr_value_combination_id
158127          , x_value_segment_code       => l_adr_value_segment_code
158128          , p_side                     => 'NA'
158129          , p_override_seg_flag        => 'Y'
158130    );
158131 
158132    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
158133 
158134       xla_ae_lines_pkg.set_segment(
158135           p_to_segment_code         => 'GL_BALANCING'
158136         , p_segment_value           => l_segment
158137         , p_from_segment_code       => l_adr_value_segment_code
158138         , p_from_combination_id     => l_adr_value_combination_id
158139         , p_value_type_code         => l_adr_value_type_code
158140         , p_transaction_coa_id      => l_adr_transaction_coa_id
158141         , p_accounting_coa_id       => l_adr_accounting_coa_id
158142         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
158143         , p_flex_value_set_id       => l_adr_flex_value_set_id
158144         , p_adr_code                => 'FA_EXPENSE_ACCT'
158145         , p_adr_type_code           => 'S'
158146         , p_component_type          => l_component_type
158147         , p_component_code          => l_component_code
158148         , p_component_type_code     => l_component_type_code
158149         , p_component_appl_id       => l_component_appl_id
158150         , p_amb_context_code        => l_amb_context_code
158151         , p_entity_code             => 'TRANSACTIONS'
158152         , p_event_class_code        => 'TRANSFERS'
158156   END IF;
158153         , p_side                    => 'NA'
158154         );
158155 
158157 
158158    --
158159    --
158160    END IF;
158161    --
158162    -- Bug 4922099
158163    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
158164           (NVL(l_enc_upg_option, 'N') = 'O')
158165         ) AND
158166         (l_bflow_method_code = 'PRIOR_ENTRY')
158167       )
158168    THEN
158169       IF
158170       --
158171       1 = 2
158172       --
158173       THEN
158174       xla_accounting_err_pkg.build_message
158175                                     (p_appli_s_name            => 'XLA'
158176                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
158177                                     ,p_token_1                 => 'LINE_NUMBER'
158178                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
158179                                     ,p_token_2                 => 'LINE_TYPE_NAME'
158180                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
158181                                                                              l_component_type
158182                                                                             ,l_component_code
158183                                                                             ,l_component_type_code
158184                                                                             ,l_component_appl_id
158185                                                                             ,l_amb_context_code
158186                                                                             ,l_entity_code
158187                                                                             ,l_event_class_code
158188                                                                            )
158189                                     ,p_token_3                 => 'OWNER'
158190                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
158191                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
158192                                                                           ,p_lookup_code    => l_component_type_code
158193                                                                          )
158194                                     ,p_token_4                 => 'PRODUCT_NAME'
158195                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
158196                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
158197                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
158198                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
158199                                     ,p_ae_header_id            =>  NULL
158200                                        );
158201 
158202         IF (C_LEVEL_ERROR>= g_log_level) THEN
158203                  trace
158204                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
158205                       ,p_level    => C_LEVEL_ERROR
158206                       ,p_module   => l_log_module);
158207         END IF;
158208       END IF;
158209    END IF;
158210    --
158211    --
158212    ------------------------------------------------------------------------------------------------
158213    -- 4219869 Business Flow
158214    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
158215    -- Prior Entry.  Currently, the following code is always generated.
158216    ------------------------------------------------------------------------------------------------
158217    XLA_AE_LINES_PKG.ValidateCurrentLine;
158218 
158219    ------------------------------------------------------------------------------------
158220    -- 4219869 Business Flow
158221    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
158222    ------------------------------------------------------------------------------------
158223    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
158224 
158225    ----------------------------------------------------------------------------------
158226    -- 4219869 Business Flow
158227    -- Update journal entry status -- Need to generate this within IF <condition>
158228    ----------------------------------------------------------------------------------
158229    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
158230          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
158231          ,p_balance_type_code => l_balance_type_code
158232          );
158233 
158234    -------------------------------------------------------------------------------------------
158235    -- 4262811 - Generate the Accrual Reversal lines
158236    -------------------------------------------------------------------------------------------
158237    BEGIN
158238       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
158239                               (g_array_event(p_event_id).array_value_num('header_index'));
158240       IF l_acc_rev_flag IS NULL THEN
158241          l_acc_rev_flag := 'N';
158242       END IF;
158243    EXCEPTION
158244       WHEN OTHERS THEN
158245          l_acc_rev_flag := 'N';
158246    END;
158247    --
158248    IF (l_acc_rev_flag = 'Y') THEN
158249 
158250        -- 4645092  ------------------------------------------------------------------------------
158251        -- To allow MPA report to determine if it should generate report process
158252        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
158253        ------------------------------------------------------------------------------------------
158254 
158255        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
158256        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
158257    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
158258    -- call ADRs
158259    -- Bug 4922099
158263         (NVL(l_enc_upg_option, 'N') = 'O')
158260    --
158261    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
158262         (NVL(l_actual_upg_option, 'N') = 'O') OR
158264       )
158265    THEN
158266    NULL;
158267    --
158268    --
158269    
158270   l_ccid := AcctDerRule_174(
158271            p_application_id           => p_application_id
158272          , p_ae_header_id             => l_ae_header_id 
158273 , p_source_3 => p_source_3
158274 , p_source_17 => p_source_17
158275 , p_source_30 => p_source_30
158276          , x_transaction_coa_id       => l_adr_transaction_coa_id
158277          , x_accounting_coa_id        => l_adr_accounting_coa_id
158278          , x_value_type_code          => l_adr_value_type_code
158279          , p_side                     => 'NA'
158280    );
158281 
158282    xla_ae_lines_pkg.set_ccid(
158283     p_code_combination_id          => l_ccid
158284   , p_value_type_code              => l_adr_value_type_code
158285   , p_transaction_coa_id           => l_adr_transaction_coa_id
158286   , p_accounting_coa_id            => l_adr_accounting_coa_id
158287   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
158288   , p_adr_type_code                => 'S'
158289   , p_component_type               => l_component_type
158290   , p_component_code               => l_component_code
158291   , p_component_type_code          => l_component_type_code
158292   , p_component_appl_id            => l_component_appl_id
158293   , p_amb_context_code             => l_amb_context_code
158294   , p_side                         => 'NA'
158295   );
158296 
158297 
158298    l_segment := AcctDerRule_150(
158299            p_application_id           => p_application_id
158300          , p_ae_header_id             => l_ae_header_id 
158301 , p_source_3 => p_source_3
158302 , p_source_11 => p_source_11
158303          , x_transaction_coa_id       => l_adr_transaction_coa_id
158304          , x_accounting_coa_id        => l_adr_accounting_coa_id
158305          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
158306          , x_flex_value_set_id        => l_adr_flex_value_set_id
158307          , x_value_type_code          => l_adr_value_type_code
158308          , x_value_combination_id     => l_adr_value_combination_id
158309          , x_value_segment_code       => l_adr_value_segment_code
158310          , p_side                     => 'NA'
158311          , p_override_seg_flag        => 'Y'
158312    );
158313 
158314    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
158315 
158316       xla_ae_lines_pkg.set_segment(
158317           p_to_segment_code         => 'GL_ACCOUNT'
158318         , p_segment_value           => l_segment
158319         , p_from_segment_code       => l_adr_value_segment_code
158320         , p_from_combination_id     => l_adr_value_combination_id
158321         , p_value_type_code         => l_adr_value_type_code
158322         , p_transaction_coa_id      => l_adr_transaction_coa_id
158323         , p_accounting_coa_id       => l_adr_accounting_coa_id
158324         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
158325         , p_flex_value_set_id       => l_adr_flex_value_set_id
158326         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
158327         , p_adr_type_code           => 'S'
158328         , p_component_type          => l_component_type
158329         , p_component_code          => l_component_code
158330         , p_component_type_code     => l_component_type_code
158331         , p_component_appl_id       => l_component_appl_id
158332         , p_amb_context_code        => l_amb_context_code
158333         , p_entity_code             => 'TRANSACTIONS'
158334         , p_event_class_code        => 'TRANSFERS'
158335         , p_side                    => 'NA'
158336         );
158337 
158338   END IF;
158339 
158340    l_segment := AcctDerRule_168(
158341            p_application_id           => p_application_id
158342          , p_ae_header_id             => l_ae_header_id 
158343 , p_source_3 => p_source_3
158344 , p_source_29 => p_source_29
158345          , x_transaction_coa_id       => l_adr_transaction_coa_id
158346          , x_accounting_coa_id        => l_adr_accounting_coa_id
158347          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
158348          , x_flex_value_set_id        => l_adr_flex_value_set_id
158349          , x_value_type_code          => l_adr_value_type_code
158350          , x_value_combination_id     => l_adr_value_combination_id
158351          , x_value_segment_code       => l_adr_value_segment_code
158352          , p_side                     => 'NA'
158353          , p_override_seg_flag        => 'Y'
158354    );
158355 
158356    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
158357 
158358       xla_ae_lines_pkg.set_segment(
158359           p_to_segment_code         => 'GL_BALANCING'
158360         , p_segment_value           => l_segment
158361         , p_from_segment_code       => l_adr_value_segment_code
158362         , p_from_combination_id     => l_adr_value_combination_id
158363         , p_value_type_code         => l_adr_value_type_code
158364         , p_transaction_coa_id      => l_adr_transaction_coa_id
158365         , p_accounting_coa_id       => l_adr_accounting_coa_id
158366         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
158367         , p_flex_value_set_id       => l_adr_flex_value_set_id
158368         , p_adr_code                => 'FA_EXPENSE_ACCT'
158369         , p_adr_type_code           => 'S'
158370         , p_component_type          => l_component_type
158371         , p_component_code          => l_component_code
158372         , p_component_type_code     => l_component_type_code
158373         , p_component_appl_id       => l_component_appl_id
158374         , p_amb_context_code        => l_amb_context_code
158375         , p_entity_code             => 'TRANSACTIONS'
158376         , p_event_class_code        => 'TRANSFERS'
158377         , p_side                    => 'NA'
158378         );
158379 
158380   END IF;
158381 
158385 
158382    --
158383    --
158384    END IF;
158386        --
158387        -- Update the line information that should be overwritten
158388        --
158389        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
158390                                          p_header_num   => 1);
158391        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
158392 
158393        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
158394 
158395        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
158396           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
158397        END IF;
158398 
158399       --
158400       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
158401       --
158402       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
158403           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
158404       ELSE
158405           ---------------------------------------------------------------------------------------------------
158406           -- 4262811a Switch Sign
158407           ---------------------------------------------------------------------------------------------------
158408           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
158409           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
158410                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
158411           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
158412                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
158413           -- 5132302
158414           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
158415                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
158416 
158417       END IF;
158418 
158419       -- 4955764
158420       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
158421       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
158422 
158423 
158424       XLA_AE_LINES_PKG.ValidateCurrentLine;
158425       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
158426 
158427       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
158428                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
158429                ,p_balance_type_code => l_balance_type_code);
158430 
158431    END IF;
158432 
158433    -----------------------------------------------------------------------------------------
158434    -- 4262811 Multiperiod Accounting
158435    -----------------------------------------------------------------------------------------
158436      -- No MPA option is assigned.
158437 
158438 
158439 END IF;
158440 END IF;
158441 --
158442 
158443 --
158444 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
158445    trace
158446       (p_msg      => 'END of AcctLineType_376'
158447       ,p_level    => C_LEVEL_PROCEDURE
158448       ,p_module   => l_log_module);
158449 END IF;
158450 --
158451 EXCEPTION
158452   WHEN xla_exceptions_pkg.application_exception THEN
158453       RAISE;
158454   WHEN OTHERS THEN
158455        xla_exceptions_pkg.raise_message
158456            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_376');
158457 END AcctLineType_376;
158458 --
158459 
158460 ---------------------------------------
158461 --
158462 -- PRIVATE FUNCTION
158463 --         AcctLineType_377
158464 --
158465 ---------------------------------------
158466 PROCEDURE AcctLineType_377 (
158467   p_application_id        IN NUMBER
158468  ,p_event_id              IN NUMBER
158469  ,p_calculate_acctd_flag  IN VARCHAR2
158470  ,p_calculate_g_l_flag    IN VARCHAR2
158471  ,p_actual_flag           IN OUT VARCHAR2
158472  ,p_balance_type_code     OUT VARCHAR2
158473  ,p_gain_or_loss_ref      OUT VARCHAR2
158474  
158475 --Period Close Date
158476  , p_source_1            IN DATE
158477 --Generated Code Combination Identifier
158478  , p_source_3            IN NUMBER
158479 --Intercompany Payables Account
158480  , p_source_19            IN VARCHAR2
158481 --Expense Account Code Combination Identifier
158482  , p_source_29            IN NUMBER
158483 --Default Code Combination Identifier
158484  , p_source_30            IN NUMBER
158485 --Adjustment Type
158486  , p_source_35            IN VARCHAR2
158487 --Transaction Header Identifier
158488  , p_source_36            IN NUMBER
158489 --Adjustment Line Identifier
158490  , p_source_37            IN NUMBER
158491 --Distribution Type Code
158492  , p_source_38            IN VARCHAR2
158493 --Entered Amount
158494  , p_source_39            IN NUMBER
158495 --Currency Code
158496  , p_source_40            IN VARCHAR2
158497 )
158498 IS
158499 
158500 l_component_type              VARCHAR2(80);
158501 l_component_code              VARCHAR2(30);
158502 l_component_type_code         VARCHAR2(1);
158503 l_component_appl_id           INTEGER;
158504 l_amb_context_code            VARCHAR2(30);
158505 l_entity_code                 VARCHAR2(30);
158506 l_event_class_code            VARCHAR2(30);
158507 l_ae_header_id                NUMBER;
158508 l_event_type_code             VARCHAR2(30);
158509 l_line_definition_code        VARCHAR2(30);
158510 l_line_definition_owner_code  VARCHAR2(1);
158511 --
158512 -- adr variables
158513 l_segment                     VARCHAR2(30);
158514 l_ccid                        NUMBER;
158515 l_adr_transaction_coa_id      NUMBER;
158516 l_adr_accounting_coa_id       NUMBER;
158520 l_adr_value_combination_id    NUMBER;
158517 l_adr_flexfield_segment_code  VARCHAR2(30);
158518 l_adr_flex_value_set_id       NUMBER;
158519 l_adr_value_type_code         VARCHAR2(30);
158521 l_adr_value_segment_code      VARCHAR2(30);
158522 
158523 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
158524 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
158525 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
158526 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
158527 
158528 -- 4262811 Variables ------------------------------------------------------------------------------------------
158529 l_entered_amt_idx             NUMBER;
158530 l_accted_amt_idx              NUMBER;
158531 l_acc_rev_flag                VARCHAR2(1);
158532 l_accrual_line_num            NUMBER;
158533 l_tmp_amt                     NUMBER;
158534 l_acc_rev_natural_side_code   VARCHAR2(1);
158535 
158536 l_num_entries                 NUMBER;
158537 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
158538 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
158539 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
158540 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
158541 l_recog_line_1                NUMBER;
158542 l_recog_line_2                NUMBER;
158543 
158544 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
158545 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
158546 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
158547 
158548 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
158549 
158550 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
158551 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
158552 
158553 ---------------------------------------------------------------------------------------------------------------
158554 
158555 
158556 --
158557 -- bulk performance
158558 --
158559 l_balance_type_code           VARCHAR2(1);
158560 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
158561 l_log_module                  VARCHAR2(240);
158562 
158563 --
158564 -- Upgrade strategy
158565 --
158566 l_actual_upg_option           VARCHAR2(1);
158567 l_enc_upg_option           VARCHAR2(1);
158568 
158569 --
158570 BEGIN
158571 --
158572 IF g_log_enabled THEN
158573       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_377';
158574 END IF;
158575 --
158576 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
158577 
158578       trace
158579          (p_msg      => 'BEGIN of AcctLineType_377'
158580          ,p_level    => C_LEVEL_PROCEDURE
158581          ,p_module   => l_log_module);
158582 
158583 END IF;
158584 --
158585 l_component_type             := 'AMB_JLT';
158586 l_component_code             := 'FA_TRANSFER_IC_PAY';
158587 l_component_type_code        := 'S';
158588 l_component_appl_id          :=  140;
158589 l_amb_context_code           := 'DEFAULT';
158590 l_entity_code                := 'TRANSACTIONS';
158591 l_event_class_code           := 'TRANSFERS';
158592 l_event_type_code            := 'TRANSFERS_ALL';
158593 l_line_definition_owner_code := 'S';
158594 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
158595 --
158596 l_balance_type_code          := 'A';
158597 l_segment                     := NULL;
158598 l_ccid                        := NULL;
158599 l_adr_transaction_coa_id      := NULL;
158600 l_adr_accounting_coa_id       := NULL;
158601 l_adr_flexfield_segment_code  := NULL;
158602 l_adr_flex_value_set_id       := NULL;
158603 l_adr_value_type_code         := NULL;
158604 l_adr_value_combination_id    := NULL;
158605 l_adr_value_segment_code      := NULL;
158606 
158607 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
158608 l_bflow_class_code           := '';    -- 4219869 Business Flow
158609 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
158610 l_budgetary_control_flag     := 'N';
158611 
158612 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
158613 l_bflow_applied_to_amt       := NULL; -- 5132302
158614 l_entered_amt_idx            := NULL;          -- 4262811
158615 l_accted_amt_idx             := NULL;          -- 4262811
158616 l_acc_rev_flag               := NULL;          -- 4262811
158617 l_accrual_line_num           := NULL;          -- 4262811
158621 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
158618 l_tmp_amt                    := NULL;          -- 4262811
158619 --
158620  
158622     l_balance_type_code <> 'B' THEN
158623 IF NVL(p_source_35,'
158624 ') =  'INTERCO AP'
158625  THEN 
158626 
158627    --
158628    XLA_AE_LINES_PKG.SetNewLine;
158629 
158630    p_balance_type_code          := l_balance_type_code;
158631    -- set the flag so later we will know whether the gain loss line needs to be created
158632    
158633    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
158634      p_actual_flag :='A';
158635    END IF;
158636 
158637    --
158638    -- bulk performance
158639    --
158640    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
158641                                       p_header_num   => 0); -- 4262811
158642    --
158643    -- set accounting line options
158644    --
158645    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
158646            p_natural_side_code          => 'C'
158647          , p_gain_or_loss_flag          => 'N'
158648          , p_gl_transfer_mode_code      => 'S'
158649          , p_acct_entry_type_code       => 'A'
158650          , p_switch_side_flag           => 'Y'
158651          , p_merge_duplicate_code       => 'N'
158652          );
158653    --
158654    l_acc_rev_natural_side_code := 'D';  -- 4262811
158655    -- 
158656    --
158657    -- set accounting line type info
158658    --
158659    xla_ae_lines_pkg.SetAcctLineType
158660       (p_component_type             => l_component_type
158661       ,p_event_type_code            => l_event_type_code
158662       ,p_line_definition_owner_code => l_line_definition_owner_code
158663       ,p_line_definition_code       => l_line_definition_code
158664       ,p_accounting_line_code       => l_component_code
158665       ,p_accounting_line_type_code  => l_component_type_code
158666       ,p_accounting_line_appl_id    => l_component_appl_id
158667       ,p_amb_context_code           => l_amb_context_code
158668       ,p_entity_code                => l_entity_code
158669       ,p_event_class_code           => l_event_class_code);
158670    --
158671    -- set accounting class
158672    --
158673    xla_ae_lines_pkg.SetAcctClass(
158674            p_accounting_class_code  => 'LIABILITY'
158675          , p_ae_header_id           => l_ae_header_id
158676          );
158677 
158678    --
158679    -- set rounding class
158680    --
158681    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
158682                       'LIABILITY';
158683 
158684    --
158685    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
158686    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
158687    --
158688    -- bulk performance
158689    --
158690    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
158691 
158692    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
158693       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
158694 
158695    -- 4955764
158696    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
158697       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
158698 
158699    -- 4458381 Public Sector Enh
158700    
158701    --
158702    -- set accounting attributes for the line type
158703    --
158704    l_entered_amt_idx := 4;
158705    l_accted_amt_idx  := 6;
158706    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
158707    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
158708    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
158709    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
158710    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
158711    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
158712    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
158713    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
158714    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
158715    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
158716    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
158717    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
158718    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
158719 
158720    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
158721    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
158722 
158723    ---------------------------------------------------------------------------------------------------------------
158724    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
158725    ---------------------------------------------------------------------------------------------------------------
158726    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
158727 
158728    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
158729    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
158730 
158731    IF xla_accounting_cache_pkg.GetValueChar
158732          (p_source_code         => 'LEDGER_CATEGORY_CODE'
158733          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
158734    AND l_bflow_method_code = 'PRIOR_ENTRY'
158735 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
158736    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
158737          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
158738        )
158739    THEN
158740          xla_ae_lines_pkg.BflowUpgEntry
158744    ELSE
158741            (p_business_method_code    => l_bflow_method_code
158742            ,p_business_class_code     => l_bflow_class_code
158743            ,p_balance_type            => l_balance_type_code);
158745       NULL;
158746 -- No business flow processing for business flow method of NONE.
158747    END IF;
158748 
158749    --
158750    -- call analytical criteria
158751    --
158752    
158753    --
158754    -- call description
158755    --
158756    
158757 xla_ae_lines_pkg.SetLineDescription(
158758    p_ae_header_id => l_ae_header_id
158759   ,p_description  => Description_128 (
158760      p_application_id         => p_application_id
158761    , p_ae_header_id           => l_ae_header_id 
158762 , p_source_1 => p_source_1
158763    )
158764 );
158765 
158766 
158767    --
158768    -- call ADRs
158769    -- Bug 4922099
158770    --
158771    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
158772         (NVL(l_actual_upg_option, 'N') = 'O') OR
158773         (NVL(l_enc_upg_option, 'N') = 'O')
158774       )
158775    THEN
158776    NULL;
158777    --
158778    --
158779    
158780   l_ccid := AcctDerRule_173(
158781            p_application_id           => p_application_id
158782          , p_ae_header_id             => l_ae_header_id 
158783 , p_source_3 => p_source_3
158784 , p_source_30 => p_source_30
158785          , x_transaction_coa_id       => l_adr_transaction_coa_id
158786          , x_accounting_coa_id        => l_adr_accounting_coa_id
158787          , x_value_type_code          => l_adr_value_type_code
158788          , p_side                     => 'NA'
158789    );
158790 
158791    xla_ae_lines_pkg.set_ccid(
158792     p_code_combination_id          => l_ccid
158793   , p_value_type_code              => l_adr_value_type_code
158794   , p_transaction_coa_id           => l_adr_transaction_coa_id
158795   , p_accounting_coa_id            => l_adr_accounting_coa_id
158796   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
158797   , p_adr_type_code                => 'S'
158798   , p_component_type               => l_component_type
158799   , p_component_code               => l_component_code
158800   , p_component_type_code          => l_component_type_code
158801   , p_component_appl_id            => l_component_appl_id
158802   , p_amb_context_code             => l_amb_context_code
158803   , p_side                         => 'NA'
158804   );
158805 
158806 
158807    l_segment := AcctDerRule_168(
158808            p_application_id           => p_application_id
158809          , p_ae_header_id             => l_ae_header_id 
158810 , p_source_3 => p_source_3
158811 , p_source_29 => p_source_29
158812          , x_transaction_coa_id       => l_adr_transaction_coa_id
158813          , x_accounting_coa_id        => l_adr_accounting_coa_id
158814          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
158815          , x_flex_value_set_id        => l_adr_flex_value_set_id
158816          , x_value_type_code          => l_adr_value_type_code
158817          , x_value_combination_id     => l_adr_value_combination_id
158818          , x_value_segment_code       => l_adr_value_segment_code
158819          , p_side                     => 'NA'
158820          , p_override_seg_flag        => 'Y'
158821    );
158822 
158823    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
158824 
158825       xla_ae_lines_pkg.set_segment(
158826           p_to_segment_code         => 'GL_BALANCING'
158827         , p_segment_value           => l_segment
158828         , p_from_segment_code       => l_adr_value_segment_code
158829         , p_from_combination_id     => l_adr_value_combination_id
158830         , p_value_type_code         => l_adr_value_type_code
158831         , p_transaction_coa_id      => l_adr_transaction_coa_id
158832         , p_accounting_coa_id       => l_adr_accounting_coa_id
158833         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
158834         , p_flex_value_set_id       => l_adr_flex_value_set_id
158835         , p_adr_code                => 'FA_EXPENSE_ACCT'
158836         , p_adr_type_code           => 'S'
158837         , p_component_type          => l_component_type
158838         , p_component_code          => l_component_code
158839         , p_component_type_code     => l_component_type_code
158840         , p_component_appl_id       => l_component_appl_id
158841         , p_amb_context_code        => l_amb_context_code
158842         , p_entity_code             => 'TRANSACTIONS'
158843         , p_event_class_code        => 'TRANSFERS'
158844         , p_side                    => 'NA'
158845         );
158846 
158847   END IF;
158848 
158849    l_segment := AcctDerRule_157(
158850            p_application_id           => p_application_id
158851          , p_ae_header_id             => l_ae_header_id 
158852 , p_source_3 => p_source_3
158853 , p_source_19 => p_source_19
158854          , x_transaction_coa_id       => l_adr_transaction_coa_id
158855          , x_accounting_coa_id        => l_adr_accounting_coa_id
158856          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
158857          , x_flex_value_set_id        => l_adr_flex_value_set_id
158858          , x_value_type_code          => l_adr_value_type_code
158859          , x_value_combination_id     => l_adr_value_combination_id
158860          , x_value_segment_code       => l_adr_value_segment_code
158861          , p_side                     => 'NA'
158862          , p_override_seg_flag        => 'Y'
158863    );
158864 
158865    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
158866 
158867       xla_ae_lines_pkg.set_segment(
158868           p_to_segment_code         => 'GL_ACCOUNT'
158869         , p_segment_value           => l_segment
158870         , p_from_segment_code       => l_adr_value_segment_code
158871         , p_from_combination_id     => l_adr_value_combination_id
158872         , p_value_type_code         => l_adr_value_type_code
158876         , p_flex_value_set_id       => l_adr_flex_value_set_id
158873         , p_transaction_coa_id      => l_adr_transaction_coa_id
158874         , p_accounting_coa_id       => l_adr_accounting_coa_id
158875         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
158877         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
158878         , p_adr_type_code           => 'S'
158879         , p_component_type          => l_component_type
158880         , p_component_code          => l_component_code
158881         , p_component_type_code     => l_component_type_code
158882         , p_component_appl_id       => l_component_appl_id
158883         , p_amb_context_code        => l_amb_context_code
158884         , p_entity_code             => 'TRANSACTIONS'
158885         , p_event_class_code        => 'TRANSFERS'
158886         , p_side                    => 'NA'
158887         );
158888 
158889   END IF;
158890 
158891    --
158892    --
158893    END IF;
158894    --
158895    -- Bug 4922099
158896    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
158897           (NVL(l_enc_upg_option, 'N') = 'O')
158898         ) AND
158899         (l_bflow_method_code = 'PRIOR_ENTRY')
158900       )
158901    THEN
158902       IF
158903       --
158904       1 = 2
158905       --
158906       THEN
158907       xla_accounting_err_pkg.build_message
158908                                     (p_appli_s_name            => 'XLA'
158909                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
158910                                     ,p_token_1                 => 'LINE_NUMBER'
158911                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
158912                                     ,p_token_2                 => 'LINE_TYPE_NAME'
158913                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
158914                                                                              l_component_type
158915                                                                             ,l_component_code
158916                                                                             ,l_component_type_code
158917                                                                             ,l_component_appl_id
158918                                                                             ,l_amb_context_code
158919                                                                             ,l_entity_code
158920                                                                             ,l_event_class_code
158921                                                                            )
158922                                     ,p_token_3                 => 'OWNER'
158923                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
158924                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
158925                                                                           ,p_lookup_code    => l_component_type_code
158926                                                                          )
158927                                     ,p_token_4                 => 'PRODUCT_NAME'
158928                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
158929                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
158930                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
158931                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
158932                                     ,p_ae_header_id            =>  NULL
158933                                        );
158934 
158935         IF (C_LEVEL_ERROR>= g_log_level) THEN
158936                  trace
158937                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
158938                       ,p_level    => C_LEVEL_ERROR
158939                       ,p_module   => l_log_module);
158940         END IF;
158941       END IF;
158942    END IF;
158943    --
158944    --
158945    ------------------------------------------------------------------------------------------------
158946    -- 4219869 Business Flow
158947    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
158948    -- Prior Entry.  Currently, the following code is always generated.
158949    ------------------------------------------------------------------------------------------------
158950    XLA_AE_LINES_PKG.ValidateCurrentLine;
158951 
158952    ------------------------------------------------------------------------------------
158953    -- 4219869 Business Flow
158954    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
158955    ------------------------------------------------------------------------------------
158956    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
158957 
158958    ----------------------------------------------------------------------------------
158959    -- 4219869 Business Flow
158960    -- Update journal entry status -- Need to generate this within IF <condition>
158961    ----------------------------------------------------------------------------------
158962    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
158963          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
158964          ,p_balance_type_code => l_balance_type_code
158965          );
158966 
158967    -------------------------------------------------------------------------------------------
158968    -- 4262811 - Generate the Accrual Reversal lines
158969    -------------------------------------------------------------------------------------------
158970    BEGIN
158971       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
158972                               (g_array_event(p_event_id).array_value_num('header_index'));
158973       IF l_acc_rev_flag IS NULL THEN
158974          l_acc_rev_flag := 'N';
158975       END IF;
158979    END;
158976    EXCEPTION
158977       WHEN OTHERS THEN
158978          l_acc_rev_flag := 'N';
158980    --
158981    IF (l_acc_rev_flag = 'Y') THEN
158982 
158983        -- 4645092  ------------------------------------------------------------------------------
158984        -- To allow MPA report to determine if it should generate report process
158985        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
158986        ------------------------------------------------------------------------------------------
158987 
158988        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
158989        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
158990    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
158991    -- call ADRs
158992    -- Bug 4922099
158993    --
158994    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
158995         (NVL(l_actual_upg_option, 'N') = 'O') OR
158996         (NVL(l_enc_upg_option, 'N') = 'O')
158997       )
158998    THEN
158999    NULL;
159000    --
159001    --
159002    
159003   l_ccid := AcctDerRule_173(
159004            p_application_id           => p_application_id
159005          , p_ae_header_id             => l_ae_header_id 
159006 , p_source_3 => p_source_3
159007 , p_source_30 => p_source_30
159008          , x_transaction_coa_id       => l_adr_transaction_coa_id
159009          , x_accounting_coa_id        => l_adr_accounting_coa_id
159010          , x_value_type_code          => l_adr_value_type_code
159011          , p_side                     => 'NA'
159012    );
159013 
159014    xla_ae_lines_pkg.set_ccid(
159015     p_code_combination_id          => l_ccid
159016   , p_value_type_code              => l_adr_value_type_code
159017   , p_transaction_coa_id           => l_adr_transaction_coa_id
159018   , p_accounting_coa_id            => l_adr_accounting_coa_id
159019   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
159020   , p_adr_type_code                => 'S'
159021   , p_component_type               => l_component_type
159022   , p_component_code               => l_component_code
159023   , p_component_type_code          => l_component_type_code
159024   , p_component_appl_id            => l_component_appl_id
159025   , p_amb_context_code             => l_amb_context_code
159026   , p_side                         => 'NA'
159027   );
159028 
159029 
159030    l_segment := AcctDerRule_168(
159031            p_application_id           => p_application_id
159032          , p_ae_header_id             => l_ae_header_id 
159033 , p_source_3 => p_source_3
159034 , p_source_29 => p_source_29
159035          , x_transaction_coa_id       => l_adr_transaction_coa_id
159036          , x_accounting_coa_id        => l_adr_accounting_coa_id
159037          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
159038          , x_flex_value_set_id        => l_adr_flex_value_set_id
159039          , x_value_type_code          => l_adr_value_type_code
159040          , x_value_combination_id     => l_adr_value_combination_id
159041          , x_value_segment_code       => l_adr_value_segment_code
159042          , p_side                     => 'NA'
159043          , p_override_seg_flag        => 'Y'
159044    );
159045 
159046    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
159047 
159048       xla_ae_lines_pkg.set_segment(
159049           p_to_segment_code         => 'GL_BALANCING'
159050         , p_segment_value           => l_segment
159051         , p_from_segment_code       => l_adr_value_segment_code
159052         , p_from_combination_id     => l_adr_value_combination_id
159053         , p_value_type_code         => l_adr_value_type_code
159054         , p_transaction_coa_id      => l_adr_transaction_coa_id
159055         , p_accounting_coa_id       => l_adr_accounting_coa_id
159056         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
159057         , p_flex_value_set_id       => l_adr_flex_value_set_id
159058         , p_adr_code                => 'FA_EXPENSE_ACCT'
159059         , p_adr_type_code           => 'S'
159060         , p_component_type          => l_component_type
159061         , p_component_code          => l_component_code
159062         , p_component_type_code     => l_component_type_code
159063         , p_component_appl_id       => l_component_appl_id
159064         , p_amb_context_code        => l_amb_context_code
159065         , p_entity_code             => 'TRANSACTIONS'
159066         , p_event_class_code        => 'TRANSFERS'
159067         , p_side                    => 'NA'
159068         );
159069 
159070   END IF;
159071 
159072    l_segment := AcctDerRule_157(
159073            p_application_id           => p_application_id
159074          , p_ae_header_id             => l_ae_header_id 
159075 , p_source_3 => p_source_3
159076 , p_source_19 => p_source_19
159077          , x_transaction_coa_id       => l_adr_transaction_coa_id
159078          , x_accounting_coa_id        => l_adr_accounting_coa_id
159079          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
159080          , x_flex_value_set_id        => l_adr_flex_value_set_id
159081          , x_value_type_code          => l_adr_value_type_code
159082          , x_value_combination_id     => l_adr_value_combination_id
159083          , x_value_segment_code       => l_adr_value_segment_code
159084          , p_side                     => 'NA'
159085          , p_override_seg_flag        => 'Y'
159086    );
159087 
159088    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
159089 
159090       xla_ae_lines_pkg.set_segment(
159091           p_to_segment_code         => 'GL_ACCOUNT'
159092         , p_segment_value           => l_segment
159093         , p_from_segment_code       => l_adr_value_segment_code
159094         , p_from_combination_id     => l_adr_value_combination_id
159095         , p_value_type_code         => l_adr_value_type_code
159096         , p_transaction_coa_id      => l_adr_transaction_coa_id
159097         , p_accounting_coa_id       => l_adr_accounting_coa_id
159101         , p_adr_type_code           => 'S'
159098         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
159099         , p_flex_value_set_id       => l_adr_flex_value_set_id
159100         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
159102         , p_component_type          => l_component_type
159103         , p_component_code          => l_component_code
159104         , p_component_type_code     => l_component_type_code
159105         , p_component_appl_id       => l_component_appl_id
159106         , p_amb_context_code        => l_amb_context_code
159107         , p_entity_code             => 'TRANSACTIONS'
159108         , p_event_class_code        => 'TRANSFERS'
159109         , p_side                    => 'NA'
159110         );
159111 
159112   END IF;
159113 
159114    --
159115    --
159116    END IF;
159117 
159118        --
159119        -- Update the line information that should be overwritten
159120        --
159121        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
159122                                          p_header_num   => 1);
159123        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
159124 
159125        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
159126 
159127        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
159128           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
159129        END IF;
159130 
159131       --
159132       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
159133       --
159134       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
159135           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
159136       ELSE
159137           ---------------------------------------------------------------------------------------------------
159138           -- 4262811a Switch Sign
159139           ---------------------------------------------------------------------------------------------------
159140           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
159141           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
159142                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
159143           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
159144                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
159145           -- 5132302
159146           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
159147                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
159148 
159149       END IF;
159150 
159151       -- 4955764
159152       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
159153       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
159154 
159155 
159156       XLA_AE_LINES_PKG.ValidateCurrentLine;
159157       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
159158 
159159       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
159160                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
159161                ,p_balance_type_code => l_balance_type_code);
159162 
159163    END IF;
159164 
159165    -----------------------------------------------------------------------------------------
159166    -- 4262811 Multiperiod Accounting
159167    -----------------------------------------------------------------------------------------
159168      -- No MPA option is assigned.
159169 
159170 
159171 END IF;
159172 END IF;
159173 --
159174 
159175 --
159176 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
159177    trace
159178       (p_msg      => 'END of AcctLineType_377'
159179       ,p_level    => C_LEVEL_PROCEDURE
159180       ,p_module   => l_log_module);
159181 END IF;
159182 --
159183 EXCEPTION
159184   WHEN xla_exceptions_pkg.application_exception THEN
159185       RAISE;
159186   WHEN OTHERS THEN
159187        xla_exceptions_pkg.raise_message
159188            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_377');
159189 END AcctLineType_377;
159190 --
159191 
159192 ---------------------------------------
159193 --
159194 -- PRIVATE FUNCTION
159195 --         AcctLineType_378
159196 --
159197 ---------------------------------------
159198 PROCEDURE AcctLineType_378 (
159199   p_application_id        IN NUMBER
159200  ,p_event_id              IN NUMBER
159201  ,p_calculate_acctd_flag  IN VARCHAR2
159202  ,p_calculate_g_l_flag    IN VARCHAR2
159203  ,p_actual_flag           IN OUT VARCHAR2
159204  ,p_balance_type_code     OUT VARCHAR2
159205  ,p_gain_or_loss_ref      OUT VARCHAR2
159206  
159207 --Period Close Date
159208  , p_source_1            IN DATE
159209 --Generated Code Combination Identifier
159210  , p_source_3            IN NUMBER
159211 --Intercompany Receivables Account
159212  , p_source_20            IN VARCHAR2
159213 --Expense Account Code Combination Identifier
159214  , p_source_29            IN NUMBER
159215 --Default Code Combination Identifier
159216  , p_source_30            IN NUMBER
159217 --Adjustment Type
159218  , p_source_35            IN VARCHAR2
159219 --Transaction Header Identifier
159220  , p_source_36            IN NUMBER
159221 --Adjustment Line Identifier
159222  , p_source_37            IN NUMBER
159223 --Distribution Type Code
159224  , p_source_38            IN VARCHAR2
159225 --Entered Amount
159226  , p_source_39            IN NUMBER
159227 --Currency Code
159228  , p_source_40            IN VARCHAR2
159229 )
159230 IS
159231 
159235 l_component_appl_id           INTEGER;
159232 l_component_type              VARCHAR2(80);
159233 l_component_code              VARCHAR2(30);
159234 l_component_type_code         VARCHAR2(1);
159236 l_amb_context_code            VARCHAR2(30);
159237 l_entity_code                 VARCHAR2(30);
159238 l_event_class_code            VARCHAR2(30);
159239 l_ae_header_id                NUMBER;
159240 l_event_type_code             VARCHAR2(30);
159241 l_line_definition_code        VARCHAR2(30);
159242 l_line_definition_owner_code  VARCHAR2(1);
159243 --
159244 -- adr variables
159245 l_segment                     VARCHAR2(30);
159246 l_ccid                        NUMBER;
159247 l_adr_transaction_coa_id      NUMBER;
159248 l_adr_accounting_coa_id       NUMBER;
159249 l_adr_flexfield_segment_code  VARCHAR2(30);
159250 l_adr_flex_value_set_id       NUMBER;
159251 l_adr_value_type_code         VARCHAR2(30);
159252 l_adr_value_combination_id    NUMBER;
159253 l_adr_value_segment_code      VARCHAR2(30);
159254 
159255 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
159256 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
159257 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
159258 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
159259 
159260 -- 4262811 Variables ------------------------------------------------------------------------------------------
159261 l_entered_amt_idx             NUMBER;
159262 l_accted_amt_idx              NUMBER;
159263 l_acc_rev_flag                VARCHAR2(1);
159264 l_accrual_line_num            NUMBER;
159265 l_tmp_amt                     NUMBER;
159266 l_acc_rev_natural_side_code   VARCHAR2(1);
159267 
159268 l_num_entries                 NUMBER;
159269 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
159270 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
159271 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
159272 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
159273 l_recog_line_1                NUMBER;
159274 l_recog_line_2                NUMBER;
159275 
159276 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
159277 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
159278 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
159279 
159280 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
159281 
159282 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
159283 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
159284 
159285 ---------------------------------------------------------------------------------------------------------------
159286 
159287 
159288 --
159289 -- bulk performance
159290 --
159291 l_balance_type_code           VARCHAR2(1);
159292 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
159293 l_log_module                  VARCHAR2(240);
159294 
159295 --
159296 -- Upgrade strategy
159297 --
159298 l_actual_upg_option           VARCHAR2(1);
159299 l_enc_upg_option           VARCHAR2(1);
159300 
159301 --
159302 BEGIN
159303 --
159304 IF g_log_enabled THEN
159305       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_378';
159306 END IF;
159307 --
159308 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
159309 
159310       trace
159311          (p_msg      => 'BEGIN of AcctLineType_378'
159312          ,p_level    => C_LEVEL_PROCEDURE
159313          ,p_module   => l_log_module);
159314 
159315 END IF;
159316 --
159317 l_component_type             := 'AMB_JLT';
159318 l_component_code             := 'FA_TRANSFER_IC_REC';
159319 l_component_type_code        := 'S';
159320 l_component_appl_id          :=  140;
159321 l_amb_context_code           := 'DEFAULT';
159322 l_entity_code                := 'TRANSACTIONS';
159323 l_event_class_code           := 'TRANSFERS';
159324 l_event_type_code            := 'TRANSFERS_ALL';
159325 l_line_definition_owner_code := 'S';
159326 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
159327 --
159328 l_balance_type_code          := 'A';
159329 l_segment                     := NULL;
159330 l_ccid                        := NULL;
159331 l_adr_transaction_coa_id      := NULL;
159332 l_adr_accounting_coa_id       := NULL;
159333 l_adr_flexfield_segment_code  := NULL;
159334 l_adr_flex_value_set_id       := NULL;
159335 l_adr_value_type_code         := NULL;
159336 l_adr_value_combination_id    := NULL;
159337 l_adr_value_segment_code      := NULL;
159338 
159339 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
159340 l_bflow_class_code           := '';    -- 4219869 Business Flow
159341 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
159342 l_budgetary_control_flag     := 'N';
159343 
159344 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
159345 l_bflow_applied_to_amt       := NULL; -- 5132302
159346 l_entered_amt_idx            := NULL;          -- 4262811
159347 l_accted_amt_idx             := NULL;          -- 4262811
159348 l_acc_rev_flag               := NULL;          -- 4262811
159349 l_accrual_line_num           := NULL;          -- 4262811
159350 l_tmp_amt                    := NULL;          -- 4262811
159351 --
159352  
159353 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
159354     l_balance_type_code <> 'B' THEN
159355 IF NVL(p_source_35,'
159356 ') =  'INTERCO AR'
159357  THEN 
159358 
159359    --
159360    XLA_AE_LINES_PKG.SetNewLine;
159361 
159362    p_balance_type_code          := l_balance_type_code;
159363    -- set the flag so later we will know whether the gain loss line needs to be created
159364    
159365    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
159366      p_actual_flag :='A';
159367    END IF;
159368 
159369    --
159373                                       p_header_num   => 0); -- 4262811
159370    -- bulk performance
159371    --
159372    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
159374    --
159375    -- set accounting line options
159376    --
159377    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
159378            p_natural_side_code          => 'D'
159379          , p_gain_or_loss_flag          => 'N'
159380          , p_gl_transfer_mode_code      => 'S'
159381          , p_acct_entry_type_code       => 'A'
159382          , p_switch_side_flag           => 'Y'
159383          , p_merge_duplicate_code       => 'N'
159384          );
159385    --
159386    l_acc_rev_natural_side_code := 'C';  -- 4262811
159387    -- 
159388    --
159389    -- set accounting line type info
159390    --
159391    xla_ae_lines_pkg.SetAcctLineType
159392       (p_component_type             => l_component_type
159393       ,p_event_type_code            => l_event_type_code
159394       ,p_line_definition_owner_code => l_line_definition_owner_code
159395       ,p_line_definition_code       => l_line_definition_code
159396       ,p_accounting_line_code       => l_component_code
159397       ,p_accounting_line_type_code  => l_component_type_code
159398       ,p_accounting_line_appl_id    => l_component_appl_id
159399       ,p_amb_context_code           => l_amb_context_code
159400       ,p_entity_code                => l_entity_code
159401       ,p_event_class_code           => l_event_class_code);
159402    --
159403    -- set accounting class
159404    --
159405    xla_ae_lines_pkg.SetAcctClass(
159406            p_accounting_class_code  => 'ASSET'
159407          , p_ae_header_id           => l_ae_header_id
159408          );
159409 
159410    --
159411    -- set rounding class
159412    --
159413    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
159414                       'ASSET';
159415 
159416    --
159417    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
159418    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
159422    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
159419    --
159420    -- bulk performance
159421    --
159423 
159424    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
159425       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
159426 
159427    -- 4955764
159428    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
159429       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
159430 
159431    -- 4458381 Public Sector Enh
159432    
159433    --
159434    -- set accounting attributes for the line type
159435    --
159436    l_entered_amt_idx := 4;
159437    l_accted_amt_idx  := 6;
159438    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
159439    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
159440    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
159441    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
159442    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
159443    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
159444    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
159445    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
159446    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
159447    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
159448    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
159449    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
159450    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
159451 
159452    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
159453    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
159454 
159455    ---------------------------------------------------------------------------------------------------------------
159456    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
159457    ---------------------------------------------------------------------------------------------------------------
159458    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
159459 
159460    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
159461    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
159462 
159463    IF xla_accounting_cache_pkg.GetValueChar
159464          (p_source_code         => 'LEDGER_CATEGORY_CODE'
159465          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
159466    AND l_bflow_method_code = 'PRIOR_ENTRY'
159467 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
159468    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
159469          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
159470        )
159471    THEN
159472          xla_ae_lines_pkg.BflowUpgEntry
159473            (p_business_method_code    => l_bflow_method_code
159474            ,p_business_class_code     => l_bflow_class_code
159475            ,p_balance_type            => l_balance_type_code);
159476    ELSE
159477       NULL;
159478 -- No business flow processing for business flow method of NONE.
159479    END IF;
159480 
159481    --
159482    -- call analytical criteria
159483    --
159484    
159485    --
159486    -- call description
159487    --
159488    
159489 xla_ae_lines_pkg.SetLineDescription(
159490    p_ae_header_id => l_ae_header_id
159491   ,p_description  => Description_129 (
159492      p_application_id         => p_application_id
159493    , p_ae_header_id           => l_ae_header_id 
159494 , p_source_1 => p_source_1
159495    )
159496 );
159497 
159498 
159499    --
159500    -- call ADRs
159501    -- Bug 4922099
159502    --
159503    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
159504         (NVL(l_actual_upg_option, 'N') = 'O') OR
159505         (NVL(l_enc_upg_option, 'N') = 'O')
159506       )
159507    THEN
159508    NULL;
159509    --
159510    --
159511    
159512   l_ccid := AcctDerRule_173(
159513            p_application_id           => p_application_id
159514          , p_ae_header_id             => l_ae_header_id 
159518          , x_accounting_coa_id        => l_adr_accounting_coa_id
159515 , p_source_3 => p_source_3
159516 , p_source_30 => p_source_30
159517          , x_transaction_coa_id       => l_adr_transaction_coa_id
159519          , x_value_type_code          => l_adr_value_type_code
159520          , p_side                     => 'NA'
159521    );
159522 
159523    xla_ae_lines_pkg.set_ccid(
159524     p_code_combination_id          => l_ccid
159525   , p_value_type_code              => l_adr_value_type_code
159526   , p_transaction_coa_id           => l_adr_transaction_coa_id
159527   , p_accounting_coa_id            => l_adr_accounting_coa_id
159528   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
159529   , p_adr_type_code                => 'S'
159530   , p_component_type               => l_component_type
159531   , p_component_code               => l_component_code
159532   , p_component_type_code          => l_component_type_code
159533   , p_component_appl_id            => l_component_appl_id
159534   , p_amb_context_code             => l_amb_context_code
159535   , p_side                         => 'NA'
159536   );
159537 
159538 
159539    l_segment := AcctDerRule_168(
159540            p_application_id           => p_application_id
159541          , p_ae_header_id             => l_ae_header_id 
159542 , p_source_3 => p_source_3
159543 , p_source_29 => p_source_29
159544          , x_transaction_coa_id       => l_adr_transaction_coa_id
159545          , x_accounting_coa_id        => l_adr_accounting_coa_id
159546          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
159547          , x_flex_value_set_id        => l_adr_flex_value_set_id
159548          , x_value_type_code          => l_adr_value_type_code
159549          , x_value_combination_id     => l_adr_value_combination_id
159550          , x_value_segment_code       => l_adr_value_segment_code
159551          , p_side                     => 'NA'
159552          , p_override_seg_flag        => 'Y'
159553    );
159554 
159555    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
159556 
159557       xla_ae_lines_pkg.set_segment(
159558           p_to_segment_code         => 'GL_BALANCING'
159559         , p_segment_value           => l_segment
159560         , p_from_segment_code       => l_adr_value_segment_code
159561         , p_from_combination_id     => l_adr_value_combination_id
159562         , p_value_type_code         => l_adr_value_type_code
159563         , p_transaction_coa_id      => l_adr_transaction_coa_id
159564         , p_accounting_coa_id       => l_adr_accounting_coa_id
159565         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
159566         , p_flex_value_set_id       => l_adr_flex_value_set_id
159567         , p_adr_code                => 'FA_EXPENSE_ACCT'
159568         , p_adr_type_code           => 'S'
159569         , p_component_type          => l_component_type
159570         , p_component_code          => l_component_code
159571         , p_component_type_code     => l_component_type_code
159572         , p_component_appl_id       => l_component_appl_id
159573         , p_amb_context_code        => l_amb_context_code
159574         , p_entity_code             => 'TRANSACTIONS'
159575         , p_event_class_code        => 'TRANSFERS'
159576         , p_side                    => 'NA'
159577         );
159578 
159579   END IF;
159580 
159581    l_segment := AcctDerRule_158(
159582            p_application_id           => p_application_id
159583          , p_ae_header_id             => l_ae_header_id 
159584 , p_source_3 => p_source_3
159585 , p_source_20 => p_source_20
159586          , x_transaction_coa_id       => l_adr_transaction_coa_id
159587          , x_accounting_coa_id        => l_adr_accounting_coa_id
159588          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
159589          , x_flex_value_set_id        => l_adr_flex_value_set_id
159590          , x_value_type_code          => l_adr_value_type_code
159591          , x_value_combination_id     => l_adr_value_combination_id
159592          , x_value_segment_code       => l_adr_value_segment_code
159593          , p_side                     => 'NA'
159594          , p_override_seg_flag        => 'Y'
159595    );
159596 
159597    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
159598 
159599       xla_ae_lines_pkg.set_segment(
159600           p_to_segment_code         => 'GL_ACCOUNT'
159601         , p_segment_value           => l_segment
159602         , p_from_segment_code       => l_adr_value_segment_code
159603         , p_from_combination_id     => l_adr_value_combination_id
159604         , p_value_type_code         => l_adr_value_type_code
159605         , p_transaction_coa_id      => l_adr_transaction_coa_id
159606         , p_accounting_coa_id       => l_adr_accounting_coa_id
159607         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
159608         , p_flex_value_set_id       => l_adr_flex_value_set_id
159609         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
159610         , p_adr_type_code           => 'S'
159611         , p_component_type          => l_component_type
159612         , p_component_code          => l_component_code
159613         , p_component_type_code     => l_component_type_code
159614         , p_component_appl_id       => l_component_appl_id
159615         , p_amb_context_code        => l_amb_context_code
159616         , p_entity_code             => 'TRANSACTIONS'
159617         , p_event_class_code        => 'TRANSFERS'
159618         , p_side                    => 'NA'
159619         );
159620 
159621   END IF;
159622 
159623    --
159624    --
159625    END IF;
159626    --
159627    -- Bug 4922099
159628    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
159629           (NVL(l_enc_upg_option, 'N') = 'O')
159630         ) AND
159631         (l_bflow_method_code = 'PRIOR_ENTRY')
159632       )
159633    THEN
159634       IF
159635       --
159636       1 = 2
159637       --
159638       THEN
159639       xla_accounting_err_pkg.build_message
159643                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
159640                                     (p_appli_s_name            => 'XLA'
159641                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
159642                                     ,p_token_1                 => 'LINE_NUMBER'
159644                                     ,p_token_2                 => 'LINE_TYPE_NAME'
159645                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
159646                                                                              l_component_type
159647                                                                             ,l_component_code
159648                                                                             ,l_component_type_code
159649                                                                             ,l_component_appl_id
159650                                                                             ,l_amb_context_code
159651                                                                             ,l_entity_code
159652                                                                             ,l_event_class_code
159653                                                                            )
159654                                     ,p_token_3                 => 'OWNER'
159655                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
159656                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
159657                                                                           ,p_lookup_code    => l_component_type_code
159658                                                                          )
159659                                     ,p_token_4                 => 'PRODUCT_NAME'
159660                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
159661                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
159662                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
159663                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
159664                                     ,p_ae_header_id            =>  NULL
159665                                        );
159666 
159667         IF (C_LEVEL_ERROR>= g_log_level) THEN
159668                  trace
159669                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
159670                       ,p_level    => C_LEVEL_ERROR
159671                       ,p_module   => l_log_module);
159672         END IF;
159673       END IF;
159674    END IF;
159675    --
159676    --
159677    ------------------------------------------------------------------------------------------------
159678    -- 4219869 Business Flow
159679    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
159680    -- Prior Entry.  Currently, the following code is always generated.
159681    ------------------------------------------------------------------------------------------------
159682    XLA_AE_LINES_PKG.ValidateCurrentLine;
159683 
159684    ------------------------------------------------------------------------------------
159685    -- 4219869 Business Flow
159686    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
159687    ------------------------------------------------------------------------------------
159688    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
159689 
159690    ----------------------------------------------------------------------------------
159691    -- 4219869 Business Flow
159692    -- Update journal entry status -- Need to generate this within IF <condition>
159693    ----------------------------------------------------------------------------------
159694    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
159695          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
159696          ,p_balance_type_code => l_balance_type_code
159697          );
159698 
159699    -------------------------------------------------------------------------------------------
159700    -- 4262811 - Generate the Accrual Reversal lines
159701    -------------------------------------------------------------------------------------------
159702    BEGIN
159703       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
159704                               (g_array_event(p_event_id).array_value_num('header_index'));
159705       IF l_acc_rev_flag IS NULL THEN
159706          l_acc_rev_flag := 'N';
159707       END IF;
159708    EXCEPTION
159709       WHEN OTHERS THEN
159710          l_acc_rev_flag := 'N';
159711    END;
159712    --
159713    IF (l_acc_rev_flag = 'Y') THEN
159714 
159715        -- 4645092  ------------------------------------------------------------------------------
159716        -- To allow MPA report to determine if it should generate report process
159717        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
159718        ------------------------------------------------------------------------------------------
159719 
159720        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
159721        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
159722    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
159723    -- call ADRs
159724    -- Bug 4922099
159725    --
159726    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
159727         (NVL(l_actual_upg_option, 'N') = 'O') OR
159728         (NVL(l_enc_upg_option, 'N') = 'O')
159729       )
159730    THEN
159731    NULL;
159732    --
159733    --
159734    
159735   l_ccid := AcctDerRule_173(
159736            p_application_id           => p_application_id
159737          , p_ae_header_id             => l_ae_header_id 
159738 , p_source_3 => p_source_3
159739 , p_source_30 => p_source_30
159740          , x_transaction_coa_id       => l_adr_transaction_coa_id
159744    );
159741          , x_accounting_coa_id        => l_adr_accounting_coa_id
159742          , x_value_type_code          => l_adr_value_type_code
159743          , p_side                     => 'NA'
159745 
159746    xla_ae_lines_pkg.set_ccid(
159747     p_code_combination_id          => l_ccid
159748   , p_value_type_code              => l_adr_value_type_code
159749   , p_transaction_coa_id           => l_adr_transaction_coa_id
159750   , p_accounting_coa_id            => l_adr_accounting_coa_id
159751   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
159752   , p_adr_type_code                => 'S'
159753   , p_component_type               => l_component_type
159754   , p_component_code               => l_component_code
159755   , p_component_type_code          => l_component_type_code
159756   , p_component_appl_id            => l_component_appl_id
159757   , p_amb_context_code             => l_amb_context_code
159758   , p_side                         => 'NA'
159759   );
159760 
159761 
159762    l_segment := AcctDerRule_168(
159763            p_application_id           => p_application_id
159764          , p_ae_header_id             => l_ae_header_id 
159765 , p_source_3 => p_source_3
159766 , p_source_29 => p_source_29
159767          , x_transaction_coa_id       => l_adr_transaction_coa_id
159768          , x_accounting_coa_id        => l_adr_accounting_coa_id
159769          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
159770          , x_flex_value_set_id        => l_adr_flex_value_set_id
159771          , x_value_type_code          => l_adr_value_type_code
159772          , x_value_combination_id     => l_adr_value_combination_id
159773          , x_value_segment_code       => l_adr_value_segment_code
159774          , p_side                     => 'NA'
159775          , p_override_seg_flag        => 'Y'
159776    );
159777 
159778    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
159779 
159780       xla_ae_lines_pkg.set_segment(
159781           p_to_segment_code         => 'GL_BALANCING'
159782         , p_segment_value           => l_segment
159783         , p_from_segment_code       => l_adr_value_segment_code
159784         , p_from_combination_id     => l_adr_value_combination_id
159785         , p_value_type_code         => l_adr_value_type_code
159786         , p_transaction_coa_id      => l_adr_transaction_coa_id
159787         , p_accounting_coa_id       => l_adr_accounting_coa_id
159788         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
159789         , p_flex_value_set_id       => l_adr_flex_value_set_id
159790         , p_adr_code                => 'FA_EXPENSE_ACCT'
159791         , p_adr_type_code           => 'S'
159792         , p_component_type          => l_component_type
159793         , p_component_code          => l_component_code
159794         , p_component_type_code     => l_component_type_code
159795         , p_component_appl_id       => l_component_appl_id
159796         , p_amb_context_code        => l_amb_context_code
159797         , p_entity_code             => 'TRANSACTIONS'
159798         , p_event_class_code        => 'TRANSFERS'
159799         , p_side                    => 'NA'
159800         );
159801 
159802   END IF;
159803 
159804    l_segment := AcctDerRule_158(
159805            p_application_id           => p_application_id
159806          , p_ae_header_id             => l_ae_header_id 
159807 , p_source_3 => p_source_3
159808 , p_source_20 => p_source_20
159809          , x_transaction_coa_id       => l_adr_transaction_coa_id
159810          , x_accounting_coa_id        => l_adr_accounting_coa_id
159811          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
159812          , x_flex_value_set_id        => l_adr_flex_value_set_id
159813          , x_value_type_code          => l_adr_value_type_code
159814          , x_value_combination_id     => l_adr_value_combination_id
159815          , x_value_segment_code       => l_adr_value_segment_code
159816          , p_side                     => 'NA'
159817          , p_override_seg_flag        => 'Y'
159818    );
159819 
159820    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
159821 
159822       xla_ae_lines_pkg.set_segment(
159823           p_to_segment_code         => 'GL_ACCOUNT'
159824         , p_segment_value           => l_segment
159825         , p_from_segment_code       => l_adr_value_segment_code
159826         , p_from_combination_id     => l_adr_value_combination_id
159827         , p_value_type_code         => l_adr_value_type_code
159828         , p_transaction_coa_id      => l_adr_transaction_coa_id
159829         , p_accounting_coa_id       => l_adr_accounting_coa_id
159830         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
159831         , p_flex_value_set_id       => l_adr_flex_value_set_id
159832         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
159833         , p_adr_type_code           => 'S'
159834         , p_component_type          => l_component_type
159835         , p_component_code          => l_component_code
159836         , p_component_type_code     => l_component_type_code
159837         , p_component_appl_id       => l_component_appl_id
159838         , p_amb_context_code        => l_amb_context_code
159839         , p_entity_code             => 'TRANSACTIONS'
159840         , p_event_class_code        => 'TRANSFERS'
159841         , p_side                    => 'NA'
159842         );
159843 
159844   END IF;
159845 
159846    --
159847    --
159848    END IF;
159849 
159850        --
159851        -- Update the line information that should be overwritten
159852        --
159853        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
159854                                          p_header_num   => 1);
159855        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
159856 
159857        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
159858 
159859        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
159863       --
159860           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
159861        END IF;
159862 
159864       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
159865       --
159866       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
159867           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
159868       ELSE
159869           ---------------------------------------------------------------------------------------------------
159870           -- 4262811a Switch Sign
159871           ---------------------------------------------------------------------------------------------------
159872           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
159873           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
159874                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
159875           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
159876                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
159877           -- 5132302
159878           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
159879                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
159880 
159881       END IF;
159882 
159883       -- 4955764
159884       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
159885       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
159886 
159887 
159888       XLA_AE_LINES_PKG.ValidateCurrentLine;
159889       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
159890 
159891       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
159892                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
159893                ,p_balance_type_code => l_balance_type_code);
159894 
159895    END IF;
159896 
159897    -----------------------------------------------------------------------------------------
159898    -- 4262811 Multiperiod Accounting
159899    -----------------------------------------------------------------------------------------
159900      -- No MPA option is assigned.
159901 
159902 
159903 END IF;
159904 END IF;
159905 --
159906 
159907 --
159908 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
159909    trace
159910       (p_msg      => 'END of AcctLineType_378'
159911       ,p_level    => C_LEVEL_PROCEDURE
159912       ,p_module   => l_log_module);
159913 END IF;
159914 --
159915 EXCEPTION
159916   WHEN xla_exceptions_pkg.application_exception THEN
159917       RAISE;
159918   WHEN OTHERS THEN
159919        xla_exceptions_pkg.raise_message
159920            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_378');
159921 END AcctLineType_378;
159922 --
159923 
159924 ---------------------------------------
159925 --
159926 -- PRIVATE FUNCTION
159927 --         AcctLineType_379
159928 --
159929 ---------------------------------------
159930 PROCEDURE AcctLineType_379 (
159931   p_application_id        IN NUMBER
159932  ,p_event_id              IN NUMBER
159933  ,p_calculate_acctd_flag  IN VARCHAR2
159934  ,p_calculate_g_l_flag    IN VARCHAR2
159935  ,p_actual_flag           IN OUT VARCHAR2
159936  ,p_balance_type_code     OUT VARCHAR2
159937  ,p_gain_or_loss_ref      OUT VARCHAR2
159938  
159939 --Period Close Date
159940  , p_source_1            IN DATE
159941 --Bonus Depreciation Expense Account
159942  , p_source_2            IN VARCHAR2
159943 --Generated Code Combination Identifier
159944  , p_source_3            IN NUMBER
159945 --Expense Account Code Combination Identifier
159946  , p_source_29            IN NUMBER
159947 --Adjustment Type
159948  , p_source_35            IN VARCHAR2
159949 --Transaction Header Identifier
159950  , p_source_36            IN NUMBER
159951 --Adjustment Line Identifier
159952  , p_source_37            IN NUMBER
159953 --Distribution Type Code
159954  , p_source_38            IN VARCHAR2
159955 --Entered Amount
159956  , p_source_39            IN NUMBER
159957 --Currency Code
159958  , p_source_40            IN VARCHAR2
159959 --Source Destination Code
159960  , p_source_42            IN VARCHAR2
159961 )
159962 IS
159963 
159964 l_component_type              VARCHAR2(80);
159965 l_component_code              VARCHAR2(30);
159966 l_component_type_code         VARCHAR2(1);
159967 l_component_appl_id           INTEGER;
159968 l_amb_context_code            VARCHAR2(30);
159969 l_entity_code                 VARCHAR2(30);
159970 l_event_class_code            VARCHAR2(30);
159971 l_ae_header_id                NUMBER;
159972 l_event_type_code             VARCHAR2(30);
159973 l_line_definition_code        VARCHAR2(30);
159974 l_line_definition_owner_code  VARCHAR2(1);
159975 --
159976 -- adr variables
159977 l_segment                     VARCHAR2(30);
159978 l_ccid                        NUMBER;
159979 l_adr_transaction_coa_id      NUMBER;
159980 l_adr_accounting_coa_id       NUMBER;
159981 l_adr_flexfield_segment_code  VARCHAR2(30);
159982 l_adr_flex_value_set_id       NUMBER;
159983 l_adr_value_type_code         VARCHAR2(30);
159984 l_adr_value_combination_id    NUMBER;
159985 l_adr_value_segment_code      VARCHAR2(30);
159986 
159987 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
159988 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
159989 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
159990 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
159991 
159995 l_acc_rev_flag                VARCHAR2(1);
159992 -- 4262811 Variables ------------------------------------------------------------------------------------------
159993 l_entered_amt_idx             NUMBER;
159994 l_accted_amt_idx              NUMBER;
159996 l_accrual_line_num            NUMBER;
159997 l_tmp_amt                     NUMBER;
159998 l_acc_rev_natural_side_code   VARCHAR2(1);
159999 
160000 l_num_entries                 NUMBER;
160001 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
160002 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
160003 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
160004 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
160005 l_recog_line_1                NUMBER;
160006 l_recog_line_2                NUMBER;
160007 
160008 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
160009 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
160010 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
160011 
160012 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
160013 
160014 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
160015 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
160016 
160017 ---------------------------------------------------------------------------------------------------------------
160018 
160019 
160020 --
160021 -- bulk performance
160022 --
160023 l_balance_type_code           VARCHAR2(1);
160024 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
160025 l_log_module                  VARCHAR2(240);
160026 
160027 --
160028 -- Upgrade strategy
160029 --
160030 l_actual_upg_option           VARCHAR2(1);
160031 l_enc_upg_option           VARCHAR2(1);
160032 
160033 --
160034 BEGIN
160035 --
160036 IF g_log_enabled THEN
160037       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_379';
160038 END IF;
160039 --
160040 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
160041 
160042       trace
160043          (p_msg      => 'BEGIN of AcctLineType_379'
160044          ,p_level    => C_LEVEL_PROCEDURE
160045          ,p_module   => l_log_module);
160046 
160047 END IF;
160048 --
160049 l_component_type             := 'AMB_JLT';
160050 l_component_code             := 'FA_TRANSFER_SOURCE_BONUS_EXP';
160051 l_component_type_code        := 'S';
160052 l_component_appl_id          :=  140;
160053 l_amb_context_code           := 'DEFAULT';
160054 l_entity_code                := 'TRANSACTIONS';
160055 l_event_class_code           := 'TRANSFERS';
160056 l_event_type_code            := 'TRANSFERS_ALL';
160057 l_line_definition_owner_code := 'S';
160058 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
160059 --
160060 l_balance_type_code          := 'A';
160061 l_segment                     := NULL;
160062 l_ccid                        := NULL;
160063 l_adr_transaction_coa_id      := NULL;
160064 l_adr_accounting_coa_id       := NULL;
160065 l_adr_flexfield_segment_code  := NULL;
160066 l_adr_flex_value_set_id       := NULL;
160067 l_adr_value_type_code         := NULL;
160068 l_adr_value_combination_id    := NULL;
160069 l_adr_value_segment_code      := NULL;
160070 
160071 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
160072 l_bflow_class_code           := '';    -- 4219869 Business Flow
160073 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
160074 l_budgetary_control_flag     := 'N';
160075 
160076 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
160077 l_bflow_applied_to_amt       := NULL; -- 5132302
160078 l_entered_amt_idx            := NULL;          -- 4262811
160079 l_accted_amt_idx             := NULL;          -- 4262811
160080 l_acc_rev_flag               := NULL;          -- 4262811
160081 l_accrual_line_num           := NULL;          -- 4262811
160082 l_tmp_amt                    := NULL;          -- 4262811
160083 --
160084  
160085 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
160086     l_balance_type_code <> 'B' THEN
160087 IF NVL(p_source_35,'
160088 ') =  'BONUS EXPENSE' AND 
160089 NVL(p_source_42,'
160090 ') =  'SOURCE'
160091  THEN 
160092 
160093    --
160094    XLA_AE_LINES_PKG.SetNewLine;
160095 
160096    p_balance_type_code          := l_balance_type_code;
160097    -- set the flag so later we will know whether the gain loss line needs to be created
160098    
160099    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
160100      p_actual_flag :='A';
160101    END IF;
160102 
160103    --
160104    -- bulk performance
160105    --
160106    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
160107                                       p_header_num   => 0); -- 4262811
160108    --
160109    -- set accounting line options
160110    --
160111    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
160112            p_natural_side_code          => 'C'
160113          , p_gain_or_loss_flag          => 'N'
160114          , p_gl_transfer_mode_code      => 'S'
160115          , p_acct_entry_type_code       => 'A'
160116          , p_switch_side_flag           => 'Y'
160117          , p_merge_duplicate_code       => 'N'
160118          );
160119    --
160120    l_acc_rev_natural_side_code := 'D';  -- 4262811
160121    -- 
160122    --
160123    -- set accounting line type info
160124    --
160125    xla_ae_lines_pkg.SetAcctLineType
160126       (p_component_type             => l_component_type
160127       ,p_event_type_code            => l_event_type_code
160128       ,p_line_definition_owner_code => l_line_definition_owner_code
160129       ,p_line_definition_code       => l_line_definition_code
160130       ,p_accounting_line_code       => l_component_code
160134       ,p_entity_code                => l_entity_code
160131       ,p_accounting_line_type_code  => l_component_type_code
160132       ,p_accounting_line_appl_id    => l_component_appl_id
160133       ,p_amb_context_code           => l_amb_context_code
160135       ,p_event_class_code           => l_event_class_code);
160136    --
160137    -- set accounting class
160138    --
160139    xla_ae_lines_pkg.SetAcctClass(
160140            p_accounting_class_code  => 'EXPENSE'
160141          , p_ae_header_id           => l_ae_header_id
160142          );
160143 
160144    --
160145    -- set rounding class
160146    --
160147    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
160148                       'EXPENSE';
160149 
160150    --
160151    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
160152    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
160153    --
160154    -- bulk performance
160155    --
160156    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
160157 
160158    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
160159       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
160160 
160161    -- 4955764
160162    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
160163       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
160164 
160165    -- 4458381 Public Sector Enh
160166    
160167    --
160168    -- set accounting attributes for the line type
160169    --
160170    l_entered_amt_idx := 4;
160171    l_accted_amt_idx  := 6;
160172    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
160173    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
160174    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
160175    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
160176    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
160177    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
160178    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
160179    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
160180    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
160181    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
160182    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
160183    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
160184    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
160185 
160186    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
160187    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
160188 
160189    ---------------------------------------------------------------------------------------------------------------
160190    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
160191    ---------------------------------------------------------------------------------------------------------------
160192    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
160193 
160194    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
160195    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
160196 
160197    IF xla_accounting_cache_pkg.GetValueChar
160198          (p_source_code         => 'LEDGER_CATEGORY_CODE'
160199          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
160200    AND l_bflow_method_code = 'PRIOR_ENTRY'
160201 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
160202    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
160203          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
160204        )
160205    THEN
160206          xla_ae_lines_pkg.BflowUpgEntry
160207            (p_business_method_code    => l_bflow_method_code
160208            ,p_business_class_code     => l_bflow_class_code
160209            ,p_balance_type            => l_balance_type_code);
160210    ELSE
160211       NULL;
160212 -- No business flow processing for business flow method of NONE.
160213    END IF;
160214 
160215    --
160216    -- call analytical criteria
160217    --
160218    
160219    --
160220    -- call description
160221    --
160222    
160223 xla_ae_lines_pkg.SetLineDescription(
160224    p_ae_header_id => l_ae_header_id
160225   ,p_description  => Description_124 (
160226      p_application_id         => p_application_id
160227    , p_ae_header_id           => l_ae_header_id 
160228 , p_source_1 => p_source_1
160229    )
160230 );
160231 
160232 
160233    --
160234    -- call ADRs
160235    -- Bug 4922099
160236    --
160237    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
160238         (NVL(l_actual_upg_option, 'N') = 'O') OR
160239         (NVL(l_enc_upg_option, 'N') = 'O')
160240       )
160241    THEN
160242    NULL;
160243    --
160244    --
160245    
160246   l_ccid := AcctDerRule_175(
160247            p_application_id           => p_application_id
160248          , p_ae_header_id             => l_ae_header_id 
160249 , p_source_3 => p_source_3
160250 , p_source_29 => p_source_29
160251          , x_transaction_coa_id       => l_adr_transaction_coa_id
160252          , x_accounting_coa_id        => l_adr_accounting_coa_id
160253          , x_value_type_code          => l_adr_value_type_code
160254          , p_side                     => 'NA'
160255    );
160256 
160257    xla_ae_lines_pkg.set_ccid(
160258     p_code_combination_id          => l_ccid
160259   , p_value_type_code              => l_adr_value_type_code
160260   , p_transaction_coa_id           => l_adr_transaction_coa_id
160264   , p_component_type               => l_component_type
160261   , p_accounting_coa_id            => l_adr_accounting_coa_id
160262   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
160263   , p_adr_type_code                => 'S'
160265   , p_component_code               => l_component_code
160266   , p_component_type_code          => l_component_type_code
160267   , p_component_appl_id            => l_component_appl_id
160268   , p_amb_context_code             => l_amb_context_code
160269   , p_side                         => 'NA'
160270   );
160271 
160272 
160273    l_segment := AcctDerRule_143(
160274            p_application_id           => p_application_id
160275          , p_ae_header_id             => l_ae_header_id 
160276 , p_source_2 => p_source_2
160277 , p_source_3 => p_source_3
160278          , x_transaction_coa_id       => l_adr_transaction_coa_id
160279          , x_accounting_coa_id        => l_adr_accounting_coa_id
160280          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
160281          , x_flex_value_set_id        => l_adr_flex_value_set_id
160282          , x_value_type_code          => l_adr_value_type_code
160283          , x_value_combination_id     => l_adr_value_combination_id
160284          , x_value_segment_code       => l_adr_value_segment_code
160285          , p_side                     => 'NA'
160286          , p_override_seg_flag        => 'Y'
160287    );
160288 
160289    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
160290 
160291       xla_ae_lines_pkg.set_segment(
160292           p_to_segment_code         => 'GL_ACCOUNT'
160293         , p_segment_value           => l_segment
160294         , p_from_segment_code       => l_adr_value_segment_code
160295         , p_from_combination_id     => l_adr_value_combination_id
160296         , p_value_type_code         => l_adr_value_type_code
160297         , p_transaction_coa_id      => l_adr_transaction_coa_id
160298         , p_accounting_coa_id       => l_adr_accounting_coa_id
160299         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
160300         , p_flex_value_set_id       => l_adr_flex_value_set_id
160301         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
160302         , p_adr_type_code           => 'S'
160303         , p_component_type          => l_component_type
160304         , p_component_code          => l_component_code
160305         , p_component_type_code     => l_component_type_code
160306         , p_component_appl_id       => l_component_appl_id
160307         , p_amb_context_code        => l_amb_context_code
160308         , p_entity_code             => 'TRANSACTIONS'
160309         , p_event_class_code        => 'TRANSFERS'
160310         , p_side                    => 'NA'
160311         );
160312 
160313   END IF;
160314 
160315    --
160316    --
160317    END IF;
160318    --
160319    -- Bug 4922099
160320    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
160321           (NVL(l_enc_upg_option, 'N') = 'O')
160322         ) AND
160323         (l_bflow_method_code = 'PRIOR_ENTRY')
160324       )
160325    THEN
160326       IF
160327       --
160328       1 = 2
160329       --
160330       THEN
160331       xla_accounting_err_pkg.build_message
160332                                     (p_appli_s_name            => 'XLA'
160333                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
160334                                     ,p_token_1                 => 'LINE_NUMBER'
160335                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
160336                                     ,p_token_2                 => 'LINE_TYPE_NAME'
160337                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
160338                                                                              l_component_type
160339                                                                             ,l_component_code
160340                                                                             ,l_component_type_code
160341                                                                             ,l_component_appl_id
160342                                                                             ,l_amb_context_code
160343                                                                             ,l_entity_code
160344                                                                             ,l_event_class_code
160345                                                                            )
160346                                     ,p_token_3                 => 'OWNER'
160347                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
160348                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
160349                                                                           ,p_lookup_code    => l_component_type_code
160350                                                                          )
160351                                     ,p_token_4                 => 'PRODUCT_NAME'
160352                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
160353                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
160354                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
160355                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
160356                                     ,p_ae_header_id            =>  NULL
160357                                        );
160358 
160359         IF (C_LEVEL_ERROR>= g_log_level) THEN
160360                  trace
160361                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
160362                       ,p_level    => C_LEVEL_ERROR
160363                       ,p_module   => l_log_module);
160364         END IF;
160365       END IF;
160366    END IF;
160367    --
160368    --
160372    -- Prior Entry.  Currently, the following code is always generated.
160369    ------------------------------------------------------------------------------------------------
160370    -- 4219869 Business Flow
160371    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
160373    ------------------------------------------------------------------------------------------------
160374    XLA_AE_LINES_PKG.ValidateCurrentLine;
160375 
160376    ------------------------------------------------------------------------------------
160377    -- 4219869 Business Flow
160378    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
160379    ------------------------------------------------------------------------------------
160380    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
160381 
160382    ----------------------------------------------------------------------------------
160383    -- 4219869 Business Flow
160384    -- Update journal entry status -- Need to generate this within IF <condition>
160385    ----------------------------------------------------------------------------------
160386    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
160387          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
160388          ,p_balance_type_code => l_balance_type_code
160389          );
160390 
160391    -------------------------------------------------------------------------------------------
160392    -- 4262811 - Generate the Accrual Reversal lines
160393    -------------------------------------------------------------------------------------------
160394    BEGIN
160395       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
160396                               (g_array_event(p_event_id).array_value_num('header_index'));
160397       IF l_acc_rev_flag IS NULL THEN
160398          l_acc_rev_flag := 'N';
160399       END IF;
160400    EXCEPTION
160401       WHEN OTHERS THEN
160402          l_acc_rev_flag := 'N';
160403    END;
160404    --
160405    IF (l_acc_rev_flag = 'Y') THEN
160406 
160407        -- 4645092  ------------------------------------------------------------------------------
160408        -- To allow MPA report to determine if it should generate report process
160409        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
160410        ------------------------------------------------------------------------------------------
160411 
160412        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
160413        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
160414    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
160415    -- call ADRs
160416    -- Bug 4922099
160417    --
160418    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
160419         (NVL(l_actual_upg_option, 'N') = 'O') OR
160420         (NVL(l_enc_upg_option, 'N') = 'O')
160421       )
160422    THEN
160423    NULL;
160424    --
160425    --
160426    
160427   l_ccid := AcctDerRule_175(
160428            p_application_id           => p_application_id
160429          , p_ae_header_id             => l_ae_header_id 
160430 , p_source_3 => p_source_3
160431 , p_source_29 => p_source_29
160432          , x_transaction_coa_id       => l_adr_transaction_coa_id
160433          , x_accounting_coa_id        => l_adr_accounting_coa_id
160434          , x_value_type_code          => l_adr_value_type_code
160435          , p_side                     => 'NA'
160436    );
160437 
160438    xla_ae_lines_pkg.set_ccid(
160439     p_code_combination_id          => l_ccid
160440   , p_value_type_code              => l_adr_value_type_code
160441   , p_transaction_coa_id           => l_adr_transaction_coa_id
160442   , p_accounting_coa_id            => l_adr_accounting_coa_id
160443   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
160444   , p_adr_type_code                => 'S'
160445   , p_component_type               => l_component_type
160446   , p_component_code               => l_component_code
160447   , p_component_type_code          => l_component_type_code
160448   , p_component_appl_id            => l_component_appl_id
160449   , p_amb_context_code             => l_amb_context_code
160450   , p_side                         => 'NA'
160451   );
160452 
160453 
160454    l_segment := AcctDerRule_143(
160455            p_application_id           => p_application_id
160456          , p_ae_header_id             => l_ae_header_id 
160457 , p_source_2 => p_source_2
160458 , p_source_3 => p_source_3
160459          , x_transaction_coa_id       => l_adr_transaction_coa_id
160460          , x_accounting_coa_id        => l_adr_accounting_coa_id
160461          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
160462          , x_flex_value_set_id        => l_adr_flex_value_set_id
160463          , x_value_type_code          => l_adr_value_type_code
160464          , x_value_combination_id     => l_adr_value_combination_id
160465          , x_value_segment_code       => l_adr_value_segment_code
160466          , p_side                     => 'NA'
160467          , p_override_seg_flag        => 'Y'
160468    );
160469 
160470    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
160471 
160472       xla_ae_lines_pkg.set_segment(
160473           p_to_segment_code         => 'GL_ACCOUNT'
160474         , p_segment_value           => l_segment
160475         , p_from_segment_code       => l_adr_value_segment_code
160476         , p_from_combination_id     => l_adr_value_combination_id
160477         , p_value_type_code         => l_adr_value_type_code
160478         , p_transaction_coa_id      => l_adr_transaction_coa_id
160479         , p_accounting_coa_id       => l_adr_accounting_coa_id
160480         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
160481         , p_flex_value_set_id       => l_adr_flex_value_set_id
160482         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
160483         , p_adr_type_code           => 'S'
160484         , p_component_type          => l_component_type
160488         , p_amb_context_code        => l_amb_context_code
160485         , p_component_code          => l_component_code
160486         , p_component_type_code     => l_component_type_code
160487         , p_component_appl_id       => l_component_appl_id
160489         , p_entity_code             => 'TRANSACTIONS'
160490         , p_event_class_code        => 'TRANSFERS'
160491         , p_side                    => 'NA'
160492         );
160493 
160494   END IF;
160495 
160496    --
160497    --
160498    END IF;
160499 
160500        --
160501        -- Update the line information that should be overwritten
160502        --
160503        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
160504                                          p_header_num   => 1);
160505        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
160506 
160507        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
160508 
160509        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
160510           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
160511        END IF;
160512 
160513       --
160514       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
160515       --
160516       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
160517           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
160518       ELSE
160519           ---------------------------------------------------------------------------------------------------
160520           -- 4262811a Switch Sign
160521           ---------------------------------------------------------------------------------------------------
160522           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
160523           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
160524                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
160525           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
160526                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
160527           -- 5132302
160528           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
160529                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
160530 
160531       END IF;
160532 
160533       -- 4955764
160534       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
160535       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
160536 
160537 
160538       XLA_AE_LINES_PKG.ValidateCurrentLine;
160539       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
160540 
160541       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
160542                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
160543                ,p_balance_type_code => l_balance_type_code);
160544 
160545    END IF;
160546 
160547    -----------------------------------------------------------------------------------------
160548    -- 4262811 Multiperiod Accounting
160549    -----------------------------------------------------------------------------------------
160550      -- No MPA option is assigned.
160551 
160552 
160553 END IF;
160554 END IF;
160555 --
160556 
160557 --
160558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
160559    trace
160560       (p_msg      => 'END of AcctLineType_379'
160561       ,p_level    => C_LEVEL_PROCEDURE
160562       ,p_module   => l_log_module);
160563 END IF;
160564 --
160565 EXCEPTION
160566   WHEN xla_exceptions_pkg.application_exception THEN
160567       RAISE;
160568   WHEN OTHERS THEN
160569        xla_exceptions_pkg.raise_message
160570            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_379');
160571 END AcctLineType_379;
160572 --
160573 
160574 ---------------------------------------
160575 --
160576 -- PRIVATE FUNCTION
160577 --         AcctLineType_380
160578 --
160579 ---------------------------------------
160580 PROCEDURE AcctLineType_380 (
160581   p_application_id        IN NUMBER
160582  ,p_event_id              IN NUMBER
160583  ,p_calculate_acctd_flag  IN VARCHAR2
160584  ,p_calculate_g_l_flag    IN VARCHAR2
160585  ,p_actual_flag           IN OUT VARCHAR2
160586  ,p_balance_type_code     OUT VARCHAR2
160587  ,p_gain_or_loss_ref      OUT VARCHAR2
160588  
160589 --Period Close Date
160590  , p_source_1            IN DATE
160591 --Generated Code Combination Identifier
160592  , p_source_3            IN NUMBER
160593 --Bonus Reserve Account
160594  , p_source_4            IN VARCHAR2
160595 --Generated Offset Code Combination Identifier
160596  , p_source_17            IN NUMBER
160597 --Expense Account Code Combination Identifier
160598  , p_source_29            IN NUMBER
160599 --Default Code Combination Identifier
160600  , p_source_30            IN NUMBER
160601 --Adjustment Type
160602  , p_source_35            IN VARCHAR2
160603 --Transaction Header Identifier
160604  , p_source_36            IN NUMBER
160605 --Adjustment Line Identifier
160606  , p_source_37            IN NUMBER
160607 --Distribution Type Code
160608  , p_source_38            IN VARCHAR2
160609 --Entered Amount
160610  , p_source_39            IN NUMBER
160611 --Currency Code
160612  , p_source_40            IN VARCHAR2
160613 --Source Destination Code
160614  , p_source_42            IN VARCHAR2
160615 )
160616 IS
160617 
160618 l_component_type              VARCHAR2(80);
160619 l_component_code              VARCHAR2(30);
160620 l_component_type_code         VARCHAR2(1);
160624 l_event_class_code            VARCHAR2(30);
160621 l_component_appl_id           INTEGER;
160622 l_amb_context_code            VARCHAR2(30);
160623 l_entity_code                 VARCHAR2(30);
160625 l_ae_header_id                NUMBER;
160626 l_event_type_code             VARCHAR2(30);
160627 l_line_definition_code        VARCHAR2(30);
160628 l_line_definition_owner_code  VARCHAR2(1);
160629 --
160630 -- adr variables
160631 l_segment                     VARCHAR2(30);
160632 l_ccid                        NUMBER;
160633 l_adr_transaction_coa_id      NUMBER;
160634 l_adr_accounting_coa_id       NUMBER;
160635 l_adr_flexfield_segment_code  VARCHAR2(30);
160636 l_adr_flex_value_set_id       NUMBER;
160637 l_adr_value_type_code         VARCHAR2(30);
160638 l_adr_value_combination_id    NUMBER;
160639 l_adr_value_segment_code      VARCHAR2(30);
160640 
160641 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
160642 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
160643 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
160644 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
160645 
160646 -- 4262811 Variables ------------------------------------------------------------------------------------------
160647 l_entered_amt_idx             NUMBER;
160648 l_accted_amt_idx              NUMBER;
160649 l_acc_rev_flag                VARCHAR2(1);
160650 l_accrual_line_num            NUMBER;
160651 l_tmp_amt                     NUMBER;
160652 l_acc_rev_natural_side_code   VARCHAR2(1);
160653 
160654 l_num_entries                 NUMBER;
160655 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
160656 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
160657 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
160658 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
160659 l_recog_line_1                NUMBER;
160660 l_recog_line_2                NUMBER;
160661 
160662 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
160663 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
160664 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
160665 
160666 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
160667 
160668 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
160669 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
160670 
160671 ---------------------------------------------------------------------------------------------------------------
160672 
160673 
160674 --
160675 -- bulk performance
160676 --
160677 l_balance_type_code           VARCHAR2(1);
160678 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
160679 l_log_module                  VARCHAR2(240);
160680 
160681 --
160682 -- Upgrade strategy
160683 --
160684 l_actual_upg_option           VARCHAR2(1);
160685 l_enc_upg_option           VARCHAR2(1);
160686 
160687 --
160688 BEGIN
160689 --
160690 IF g_log_enabled THEN
160691       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_380';
160692 END IF;
160693 --
160694 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
160695 
160696       trace
160697          (p_msg      => 'BEGIN of AcctLineType_380'
160698          ,p_level    => C_LEVEL_PROCEDURE
160699          ,p_module   => l_log_module);
160700 
160701 END IF;
160702 --
160703 l_component_type             := 'AMB_JLT';
160704 l_component_code             := 'FA_TRANSFER_SOURCE_BONUS_RES';
160705 l_component_type_code        := 'S';
160706 l_component_appl_id          :=  140;
160707 l_amb_context_code           := 'DEFAULT';
160708 l_entity_code                := 'TRANSACTIONS';
160709 l_event_class_code           := 'TRANSFERS';
160710 l_event_type_code            := 'TRANSFERS_ALL';
160711 l_line_definition_owner_code := 'S';
160712 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
160713 --
160714 l_balance_type_code          := 'A';
160715 l_segment                     := NULL;
160716 l_ccid                        := NULL;
160717 l_adr_transaction_coa_id      := NULL;
160718 l_adr_accounting_coa_id       := NULL;
160719 l_adr_flexfield_segment_code  := NULL;
160720 l_adr_flex_value_set_id       := NULL;
160721 l_adr_value_type_code         := NULL;
160722 l_adr_value_combination_id    := NULL;
160723 l_adr_value_segment_code      := NULL;
160724 
160725 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
160726 l_bflow_class_code           := '';    -- 4219869 Business Flow
160727 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
160728 l_budgetary_control_flag     := 'N';
160729 
160730 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
160731 l_bflow_applied_to_amt       := NULL; -- 5132302
160732 l_entered_amt_idx            := NULL;          -- 4262811
160733 l_accted_amt_idx             := NULL;          -- 4262811
160734 l_acc_rev_flag               := NULL;          -- 4262811
160735 l_accrual_line_num           := NULL;          -- 4262811
160736 l_tmp_amt                    := NULL;          -- 4262811
160737 --
160738  
160739 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
160740     l_balance_type_code <> 'B' THEN
160741 IF (NVL(p_source_35,'
160742 ') =  'BONUS RESERVE' OR 
160743 NVL(p_source_35,'
160744 ') =  'BONUS EXPENSE') AND 
160745 NVL(p_source_42,'
160746 ') =  'SOURCE'
160747  THEN 
160748 
160749    --
160750    XLA_AE_LINES_PKG.SetNewLine;
160751 
160752    p_balance_type_code          := l_balance_type_code;
160753    -- set the flag so later we will know whether the gain loss line needs to be created
160754    
160755    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
160756      p_actual_flag :='A';
160757    END IF;
160758 
160759    --
160763                                       p_header_num   => 0); -- 4262811
160760    -- bulk performance
160761    --
160762    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
160764    --
160765    -- set accounting line options
160766    --
160767    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
160768            p_natural_side_code          => 'D'
160769          , p_gain_or_loss_flag          => 'N'
160770          , p_gl_transfer_mode_code      => 'S'
160771          , p_acct_entry_type_code       => 'A'
160772          , p_switch_side_flag           => 'Y'
160773          , p_merge_duplicate_code       => 'N'
160774          );
160775    --
160776    l_acc_rev_natural_side_code := 'C';  -- 4262811
160777    -- 
160778    --
160779    -- set accounting line type info
160780    --
160781    xla_ae_lines_pkg.SetAcctLineType
160782       (p_component_type             => l_component_type
160783       ,p_event_type_code            => l_event_type_code
160784       ,p_line_definition_owner_code => l_line_definition_owner_code
160785       ,p_line_definition_code       => l_line_definition_code
160786       ,p_accounting_line_code       => l_component_code
160787       ,p_accounting_line_type_code  => l_component_type_code
160788       ,p_accounting_line_appl_id    => l_component_appl_id
160789       ,p_amb_context_code           => l_amb_context_code
160790       ,p_entity_code                => l_entity_code
160791       ,p_event_class_code           => l_event_class_code);
160792    --
160793    -- set accounting class
160794    --
160795    xla_ae_lines_pkg.SetAcctClass(
160796            p_accounting_class_code  => 'ASSET'
160797          , p_ae_header_id           => l_ae_header_id
160798          );
160799 
160800    --
160801    -- set rounding class
160802    --
160803    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
160804                       'ASSET';
160805 
160806    --
160807    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
160808    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
160809    --
160810    -- bulk performance
160811    --
160812    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
160813 
160814    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
160815       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
160816 
160817    -- 4955764
160818    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
160819       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
160820 
160821    -- 4458381 Public Sector Enh
160822    
160823    --
160824    -- set accounting attributes for the line type
160825    --
160826    l_entered_amt_idx := 4;
160827    l_accted_amt_idx  := 6;
160828    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
160829    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
160830    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
160831    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
160832    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
160833    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
160834    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
160835    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
160836    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
160837    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
160838    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
160839    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
160840    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
160841 
160842    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
160843    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
160844 
160845    ---------------------------------------------------------------------------------------------------------------
160846    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
160847    ---------------------------------------------------------------------------------------------------------------
160848    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
160849 
160850    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
160851    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
160852 
160853    IF xla_accounting_cache_pkg.GetValueChar
160854          (p_source_code         => 'LEDGER_CATEGORY_CODE'
160855          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
160856    AND l_bflow_method_code = 'PRIOR_ENTRY'
160857 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
160858    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
160859          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
160860        )
160861    THEN
160862          xla_ae_lines_pkg.BflowUpgEntry
160863            (p_business_method_code    => l_bflow_method_code
160864            ,p_business_class_code     => l_bflow_class_code
160865            ,p_balance_type            => l_balance_type_code);
160866    ELSE
160867       NULL;
160868 -- No business flow processing for business flow method of NONE.
160869    END IF;
160870 
160871    --
160872    -- call analytical criteria
160873    --
160874    
160875    --
160876    -- call description
160877    --
160878    
160879 xla_ae_lines_pkg.SetLineDescription(
160880    p_ae_header_id => l_ae_header_id
160881   ,p_description  => Description_125 (
160882      p_application_id         => p_application_id
160883    , p_ae_header_id           => l_ae_header_id 
160887 
160884 , p_source_1 => p_source_1
160885    )
160886 );
160888 
160889    --
160890    -- call ADRs
160891    -- Bug 4922099
160892    --
160893    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
160894         (NVL(l_actual_upg_option, 'N') = 'O') OR
160895         (NVL(l_enc_upg_option, 'N') = 'O')
160896       )
160897    THEN
160898    NULL;
160899    --
160900    --
160901    
160902   l_ccid := AcctDerRule_174(
160903            p_application_id           => p_application_id
160904          , p_ae_header_id             => l_ae_header_id 
160905 , p_source_3 => p_source_3
160906 , p_source_17 => p_source_17
160907 , p_source_30 => p_source_30
160908          , x_transaction_coa_id       => l_adr_transaction_coa_id
160909          , x_accounting_coa_id        => l_adr_accounting_coa_id
160910          , x_value_type_code          => l_adr_value_type_code
160911          , p_side                     => 'NA'
160912    );
160913 
160914    xla_ae_lines_pkg.set_ccid(
160915     p_code_combination_id          => l_ccid
160916   , p_value_type_code              => l_adr_value_type_code
160917   , p_transaction_coa_id           => l_adr_transaction_coa_id
160918   , p_accounting_coa_id            => l_adr_accounting_coa_id
160919   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
160920   , p_adr_type_code                => 'S'
160921   , p_component_type               => l_component_type
160922   , p_component_code               => l_component_code
160923   , p_component_type_code          => l_component_type_code
160924   , p_component_appl_id            => l_component_appl_id
160925   , p_amb_context_code             => l_amb_context_code
160926   , p_side                         => 'NA'
160927   );
160928 
160929 
160930    l_segment := AcctDerRule_144(
160931            p_application_id           => p_application_id
160932          , p_ae_header_id             => l_ae_header_id 
160933 , p_source_3 => p_source_3
160934 , p_source_4 => p_source_4
160935          , x_transaction_coa_id       => l_adr_transaction_coa_id
160936          , x_accounting_coa_id        => l_adr_accounting_coa_id
160937          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
160938          , x_flex_value_set_id        => l_adr_flex_value_set_id
160939          , x_value_type_code          => l_adr_value_type_code
160940          , x_value_combination_id     => l_adr_value_combination_id
160941          , x_value_segment_code       => l_adr_value_segment_code
160942          , p_side                     => 'NA'
160943          , p_override_seg_flag        => 'Y'
160944    );
160945 
160946    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
160947 
160948       xla_ae_lines_pkg.set_segment(
160949           p_to_segment_code         => 'GL_ACCOUNT'
160950         , p_segment_value           => l_segment
160951         , p_from_segment_code       => l_adr_value_segment_code
160952         , p_from_combination_id     => l_adr_value_combination_id
160953         , p_value_type_code         => l_adr_value_type_code
160954         , p_transaction_coa_id      => l_adr_transaction_coa_id
160955         , p_accounting_coa_id       => l_adr_accounting_coa_id
160956         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
160957         , p_flex_value_set_id       => l_adr_flex_value_set_id
160958         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
160959         , p_adr_type_code           => 'S'
160960         , p_component_type          => l_component_type
160961         , p_component_code          => l_component_code
160962         , p_component_type_code     => l_component_type_code
160963         , p_component_appl_id       => l_component_appl_id
160964         , p_amb_context_code        => l_amb_context_code
160965         , p_entity_code             => 'TRANSACTIONS'
160966         , p_event_class_code        => 'TRANSFERS'
160967         , p_side                    => 'NA'
160968         );
160969 
160970   END IF;
160971 
160972    l_segment := AcctDerRule_168(
160973            p_application_id           => p_application_id
160974          , p_ae_header_id             => l_ae_header_id 
160975 , p_source_3 => p_source_3
160976 , p_source_29 => p_source_29
160977          , x_transaction_coa_id       => l_adr_transaction_coa_id
160978          , x_accounting_coa_id        => l_adr_accounting_coa_id
160979          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
160980          , x_flex_value_set_id        => l_adr_flex_value_set_id
160981          , x_value_type_code          => l_adr_value_type_code
160982          , x_value_combination_id     => l_adr_value_combination_id
160983          , x_value_segment_code       => l_adr_value_segment_code
160984          , p_side                     => 'NA'
160985          , p_override_seg_flag        => 'Y'
160986    );
160987 
160988    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
160989 
160990       xla_ae_lines_pkg.set_segment(
160991           p_to_segment_code         => 'GL_BALANCING'
160992         , p_segment_value           => l_segment
160993         , p_from_segment_code       => l_adr_value_segment_code
160994         , p_from_combination_id     => l_adr_value_combination_id
160995         , p_value_type_code         => l_adr_value_type_code
160996         , p_transaction_coa_id      => l_adr_transaction_coa_id
160997         , p_accounting_coa_id       => l_adr_accounting_coa_id
160998         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
160999         , p_flex_value_set_id       => l_adr_flex_value_set_id
161000         , p_adr_code                => 'FA_EXPENSE_ACCT'
161001         , p_adr_type_code           => 'S'
161002         , p_component_type          => l_component_type
161003         , p_component_code          => l_component_code
161004         , p_component_type_code     => l_component_type_code
161005         , p_component_appl_id       => l_component_appl_id
161006         , p_amb_context_code        => l_amb_context_code
161007         , p_entity_code             => 'TRANSACTIONS'
161011 
161008         , p_event_class_code        => 'TRANSFERS'
161009         , p_side                    => 'NA'
161010         );
161012   END IF;
161013 
161014    --
161015    --
161016    END IF;
161017    --
161018    -- Bug 4922099
161019    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
161020           (NVL(l_enc_upg_option, 'N') = 'O')
161021         ) AND
161022         (l_bflow_method_code = 'PRIOR_ENTRY')
161023       )
161024    THEN
161025       IF
161026       --
161027       1 = 2
161028       --
161029       THEN
161030       xla_accounting_err_pkg.build_message
161031                                     (p_appli_s_name            => 'XLA'
161032                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
161033                                     ,p_token_1                 => 'LINE_NUMBER'
161034                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
161035                                     ,p_token_2                 => 'LINE_TYPE_NAME'
161036                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
161037                                                                              l_component_type
161038                                                                             ,l_component_code
161039                                                                             ,l_component_type_code
161040                                                                             ,l_component_appl_id
161041                                                                             ,l_amb_context_code
161042                                                                             ,l_entity_code
161043                                                                             ,l_event_class_code
161044                                                                            )
161045                                     ,p_token_3                 => 'OWNER'
161046                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
161047                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
161048                                                                           ,p_lookup_code    => l_component_type_code
161049                                                                          )
161050                                     ,p_token_4                 => 'PRODUCT_NAME'
161051                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
161052                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
161053                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
161054                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
161055                                     ,p_ae_header_id            =>  NULL
161056                                        );
161057 
161058         IF (C_LEVEL_ERROR>= g_log_level) THEN
161059                  trace
161060                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
161061                       ,p_level    => C_LEVEL_ERROR
161062                       ,p_module   => l_log_module);
161063         END IF;
161064       END IF;
161065    END IF;
161066    --
161067    --
161068    ------------------------------------------------------------------------------------------------
161069    -- 4219869 Business Flow
161070    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
161071    -- Prior Entry.  Currently, the following code is always generated.
161072    ------------------------------------------------------------------------------------------------
161073    XLA_AE_LINES_PKG.ValidateCurrentLine;
161074 
161075    ------------------------------------------------------------------------------------
161076    -- 4219869 Business Flow
161077    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
161078    ------------------------------------------------------------------------------------
161079    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
161080 
161081    ----------------------------------------------------------------------------------
161082    -- 4219869 Business Flow
161083    -- Update journal entry status -- Need to generate this within IF <condition>
161084    ----------------------------------------------------------------------------------
161085    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
161086          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
161087          ,p_balance_type_code => l_balance_type_code
161088          );
161089 
161090    -------------------------------------------------------------------------------------------
161091    -- 4262811 - Generate the Accrual Reversal lines
161092    -------------------------------------------------------------------------------------------
161093    BEGIN
161094       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
161095                               (g_array_event(p_event_id).array_value_num('header_index'));
161096       IF l_acc_rev_flag IS NULL THEN
161097          l_acc_rev_flag := 'N';
161098       END IF;
161099    EXCEPTION
161100       WHEN OTHERS THEN
161101          l_acc_rev_flag := 'N';
161102    END;
161103    --
161104    IF (l_acc_rev_flag = 'Y') THEN
161105 
161106        -- 4645092  ------------------------------------------------------------------------------
161107        -- To allow MPA report to determine if it should generate report process
161108        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
161109        ------------------------------------------------------------------------------------------
161110 
161111        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
161112        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
161113    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
161117    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
161114    -- call ADRs
161115    -- Bug 4922099
161116    --
161118         (NVL(l_actual_upg_option, 'N') = 'O') OR
161119         (NVL(l_enc_upg_option, 'N') = 'O')
161120       )
161121    THEN
161122    NULL;
161123    --
161124    --
161125    
161126   l_ccid := AcctDerRule_174(
161127            p_application_id           => p_application_id
161128          , p_ae_header_id             => l_ae_header_id 
161129 , p_source_3 => p_source_3
161130 , p_source_17 => p_source_17
161131 , p_source_30 => p_source_30
161132          , x_transaction_coa_id       => l_adr_transaction_coa_id
161133          , x_accounting_coa_id        => l_adr_accounting_coa_id
161134          , x_value_type_code          => l_adr_value_type_code
161135          , p_side                     => 'NA'
161136    );
161137 
161138    xla_ae_lines_pkg.set_ccid(
161139     p_code_combination_id          => l_ccid
161140   , p_value_type_code              => l_adr_value_type_code
161141   , p_transaction_coa_id           => l_adr_transaction_coa_id
161142   , p_accounting_coa_id            => l_adr_accounting_coa_id
161143   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
161144   , p_adr_type_code                => 'S'
161145   , p_component_type               => l_component_type
161146   , p_component_code               => l_component_code
161147   , p_component_type_code          => l_component_type_code
161148   , p_component_appl_id            => l_component_appl_id
161149   , p_amb_context_code             => l_amb_context_code
161150   , p_side                         => 'NA'
161151   );
161152 
161153 
161154    l_segment := AcctDerRule_144(
161155            p_application_id           => p_application_id
161156          , p_ae_header_id             => l_ae_header_id 
161157 , p_source_3 => p_source_3
161158 , p_source_4 => p_source_4
161159          , x_transaction_coa_id       => l_adr_transaction_coa_id
161160          , x_accounting_coa_id        => l_adr_accounting_coa_id
161161          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
161162          , x_flex_value_set_id        => l_adr_flex_value_set_id
161163          , x_value_type_code          => l_adr_value_type_code
161164          , x_value_combination_id     => l_adr_value_combination_id
161165          , x_value_segment_code       => l_adr_value_segment_code
161166          , p_side                     => 'NA'
161167          , p_override_seg_flag        => 'Y'
161168    );
161169 
161170    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
161171 
161172       xla_ae_lines_pkg.set_segment(
161173           p_to_segment_code         => 'GL_ACCOUNT'
161174         , p_segment_value           => l_segment
161175         , p_from_segment_code       => l_adr_value_segment_code
161176         , p_from_combination_id     => l_adr_value_combination_id
161177         , p_value_type_code         => l_adr_value_type_code
161178         , p_transaction_coa_id      => l_adr_transaction_coa_id
161179         , p_accounting_coa_id       => l_adr_accounting_coa_id
161180         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
161181         , p_flex_value_set_id       => l_adr_flex_value_set_id
161182         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
161183         , p_adr_type_code           => 'S'
161184         , p_component_type          => l_component_type
161185         , p_component_code          => l_component_code
161186         , p_component_type_code     => l_component_type_code
161187         , p_component_appl_id       => l_component_appl_id
161188         , p_amb_context_code        => l_amb_context_code
161189         , p_entity_code             => 'TRANSACTIONS'
161190         , p_event_class_code        => 'TRANSFERS'
161191         , p_side                    => 'NA'
161192         );
161193 
161194   END IF;
161195 
161196    l_segment := AcctDerRule_168(
161197            p_application_id           => p_application_id
161198          , p_ae_header_id             => l_ae_header_id 
161199 , p_source_3 => p_source_3
161200 , p_source_29 => p_source_29
161201          , x_transaction_coa_id       => l_adr_transaction_coa_id
161202          , x_accounting_coa_id        => l_adr_accounting_coa_id
161203          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
161204          , x_flex_value_set_id        => l_adr_flex_value_set_id
161205          , x_value_type_code          => l_adr_value_type_code
161206          , x_value_combination_id     => l_adr_value_combination_id
161207          , x_value_segment_code       => l_adr_value_segment_code
161208          , p_side                     => 'NA'
161209          , p_override_seg_flag        => 'Y'
161210    );
161211 
161212    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
161213 
161214       xla_ae_lines_pkg.set_segment(
161215           p_to_segment_code         => 'GL_BALANCING'
161216         , p_segment_value           => l_segment
161217         , p_from_segment_code       => l_adr_value_segment_code
161218         , p_from_combination_id     => l_adr_value_combination_id
161219         , p_value_type_code         => l_adr_value_type_code
161220         , p_transaction_coa_id      => l_adr_transaction_coa_id
161221         , p_accounting_coa_id       => l_adr_accounting_coa_id
161222         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
161223         , p_flex_value_set_id       => l_adr_flex_value_set_id
161224         , p_adr_code                => 'FA_EXPENSE_ACCT'
161225         , p_adr_type_code           => 'S'
161226         , p_component_type          => l_component_type
161227         , p_component_code          => l_component_code
161228         , p_component_type_code     => l_component_type_code
161229         , p_component_appl_id       => l_component_appl_id
161230         , p_amb_context_code        => l_amb_context_code
161231         , p_entity_code             => 'TRANSACTIONS'
161232         , p_event_class_code        => 'TRANSFERS'
161233         , p_side                    => 'NA'
161237 
161234         );
161235 
161236   END IF;
161238    --
161239    --
161240    END IF;
161241 
161242        --
161243        -- Update the line information that should be overwritten
161244        --
161245        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
161246                                          p_header_num   => 1);
161247        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
161248 
161249        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
161250 
161251        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
161252           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
161253        END IF;
161254 
161255       --
161256       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
161257       --
161258       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
161259           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
161260       ELSE
161261           ---------------------------------------------------------------------------------------------------
161262           -- 4262811a Switch Sign
161263           ---------------------------------------------------------------------------------------------------
161264           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
161265           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
161266                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
161267           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
161268                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
161269           -- 5132302
161270           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
161271                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
161272 
161273       END IF;
161274 
161275       -- 4955764
161276       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
161277       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
161278 
161279 
161280       XLA_AE_LINES_PKG.ValidateCurrentLine;
161281       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
161282 
161283       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
161284                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
161288 
161285                ,p_balance_type_code => l_balance_type_code);
161286 
161287    END IF;
161289    -----------------------------------------------------------------------------------------
161290    -- 4262811 Multiperiod Accounting
161291    -----------------------------------------------------------------------------------------
161292      -- No MPA option is assigned.
161293 
161294 
161295 END IF;
161296 END IF;
161297 --
161298 
161299 --
161300 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
161301    trace
161302       (p_msg      => 'END of AcctLineType_380'
161303       ,p_level    => C_LEVEL_PROCEDURE
161304       ,p_module   => l_log_module);
161305 END IF;
161306 --
161307 EXCEPTION
161308   WHEN xla_exceptions_pkg.application_exception THEN
161309       RAISE;
161310   WHEN OTHERS THEN
161311        xla_exceptions_pkg.raise_message
161312            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_380');
161313 END AcctLineType_380;
161314 --
161315 
161316 ---------------------------------------
161317 --
161318 -- PRIVATE FUNCTION
161319 --         AcctLineType_381
161320 --
161321 ---------------------------------------
161322 PROCEDURE AcctLineType_381 (
161323   p_application_id        IN NUMBER
161324  ,p_event_id              IN NUMBER
161325  ,p_calculate_acctd_flag  IN VARCHAR2
161326  ,p_calculate_g_l_flag    IN VARCHAR2
161327  ,p_actual_flag           IN OUT VARCHAR2
161328  ,p_balance_type_code     OUT VARCHAR2
161329  ,p_gain_or_loss_ref      OUT VARCHAR2
161330  
161331 --Period Close Date
161332  , p_source_1            IN DATE
161333 --Generated Code Combination Identifier
161334  , p_source_3            IN NUMBER
161335 --Asset Cost Account
161336  , p_source_9            IN VARCHAR2
161337 --Expense Account Code Combination Identifier
161338  , p_source_29            IN NUMBER
161339 --Default Code Combination Identifier
161340  , p_source_30            IN NUMBER
161341 --Adjustment Type
161342  , p_source_35            IN VARCHAR2
161343 --Transaction Header Identifier
161344  , p_source_36            IN NUMBER
161345 --Adjustment Line Identifier
161346  , p_source_37            IN NUMBER
161347 --Distribution Type Code
161348  , p_source_38            IN VARCHAR2
161349 --Entered Amount
161350  , p_source_39            IN NUMBER
161351 --Currency Code
161352  , p_source_40            IN VARCHAR2
161353 --Source Destination Code
161354  , p_source_42            IN VARCHAR2
161355 )
161356 IS
161357 
161358 l_component_type              VARCHAR2(80);
161359 l_component_code              VARCHAR2(30);
161360 l_component_type_code         VARCHAR2(1);
161361 l_component_appl_id           INTEGER;
161362 l_amb_context_code            VARCHAR2(30);
161363 l_entity_code                 VARCHAR2(30);
161364 l_event_class_code            VARCHAR2(30);
161365 l_ae_header_id                NUMBER;
161366 l_event_type_code             VARCHAR2(30);
161367 l_line_definition_code        VARCHAR2(30);
161368 l_line_definition_owner_code  VARCHAR2(1);
161369 --
161370 -- adr variables
161371 l_segment                     VARCHAR2(30);
161372 l_ccid                        NUMBER;
161373 l_adr_transaction_coa_id      NUMBER;
161374 l_adr_accounting_coa_id       NUMBER;
161375 l_adr_flexfield_segment_code  VARCHAR2(30);
161376 l_adr_flex_value_set_id       NUMBER;
161377 l_adr_value_type_code         VARCHAR2(30);
161378 l_adr_value_combination_id    NUMBER;
161379 l_adr_value_segment_code      VARCHAR2(30);
161380 
161381 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
161382 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
161383 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
161384 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
161385 
161386 -- 4262811 Variables ------------------------------------------------------------------------------------------
161387 l_entered_amt_idx             NUMBER;
161388 l_accted_amt_idx              NUMBER;
161389 l_acc_rev_flag                VARCHAR2(1);
161390 l_accrual_line_num            NUMBER;
161391 l_tmp_amt                     NUMBER;
161392 l_acc_rev_natural_side_code   VARCHAR2(1);
161393 
161394 l_num_entries                 NUMBER;
161395 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
161396 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
161397 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
161398 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
161399 l_recog_line_1                NUMBER;
161400 l_recog_line_2                NUMBER;
161401 
161402 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
161403 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
161404 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
161405 
161406 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
161407 
161408 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
161409 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
161410 
161411 ---------------------------------------------------------------------------------------------------------------
161412 
161413 
161414 --
161415 -- bulk performance
161416 --
161417 l_balance_type_code           VARCHAR2(1);
161418 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
161419 l_log_module                  VARCHAR2(240);
161420 
161421 --
161422 -- Upgrade strategy
161423 --
161424 l_actual_upg_option           VARCHAR2(1);
161425 l_enc_upg_option           VARCHAR2(1);
161426 
161427 --
161428 BEGIN
161429 --
161430 IF g_log_enabled THEN
161431       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_381';
161432 END IF;
161433 --
161437          (p_msg      => 'BEGIN of AcctLineType_381'
161434 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
161435 
161436       trace
161438          ,p_level    => C_LEVEL_PROCEDURE
161439          ,p_module   => l_log_module);
161440 
161441 END IF;
161442 --
161443 l_component_type             := 'AMB_JLT';
161444 l_component_code             := 'FA_TRANSFER_SOURCE_COST';
161445 l_component_type_code        := 'S';
161446 l_component_appl_id          :=  140;
161447 l_amb_context_code           := 'DEFAULT';
161448 l_entity_code                := 'TRANSACTIONS';
161449 l_event_class_code           := 'TRANSFERS';
161450 l_event_type_code            := 'TRANSFERS_ALL';
161451 l_line_definition_owner_code := 'S';
161452 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
161453 --
161454 l_balance_type_code          := 'A';
161455 l_segment                     := NULL;
161456 l_ccid                        := NULL;
161457 l_adr_transaction_coa_id      := NULL;
161458 l_adr_accounting_coa_id       := NULL;
161459 l_adr_flexfield_segment_code  := NULL;
161460 l_adr_flex_value_set_id       := NULL;
161461 l_adr_value_type_code         := NULL;
161462 l_adr_value_combination_id    := NULL;
161463 l_adr_value_segment_code      := NULL;
161464 
161465 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
161466 l_bflow_class_code           := '';    -- 4219869 Business Flow
161467 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
161468 l_budgetary_control_flag     := 'N';
161469 
161470 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
161471 l_bflow_applied_to_amt       := NULL; -- 5132302
161472 l_entered_amt_idx            := NULL;          -- 4262811
161473 l_accted_amt_idx             := NULL;          -- 4262811
161474 l_acc_rev_flag               := NULL;          -- 4262811
161475 l_accrual_line_num           := NULL;          -- 4262811
161476 l_tmp_amt                    := NULL;          -- 4262811
161477 --
161478  
161479 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
161480     l_balance_type_code <> 'B' THEN
161481 IF NVL(p_source_35,'
161482 ') =  'COST' AND 
161483 NVL(p_source_42,'
161484 ') =  'SOURCE'
161485  THEN 
161486 
161487    --
161488    XLA_AE_LINES_PKG.SetNewLine;
161489 
161490    p_balance_type_code          := l_balance_type_code;
161491    -- set the flag so later we will know whether the gain loss line needs to be created
161492    
161493    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
161494      p_actual_flag :='A';
161495    END IF;
161496 
161497    --
161498    -- bulk performance
161499    --
161500    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
161501                                       p_header_num   => 0); -- 4262811
161502    --
161503    -- set accounting line options
161504    --
161505    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
161506            p_natural_side_code          => 'C'
161507          , p_gain_or_loss_flag          => 'N'
161508          , p_gl_transfer_mode_code      => 'S'
161509          , p_acct_entry_type_code       => 'A'
161510          , p_switch_side_flag           => 'Y'
161511          , p_merge_duplicate_code       => 'N'
161512          );
161513    --
161514    l_acc_rev_natural_side_code := 'D';  -- 4262811
161515    -- 
161516    --
161517    -- set accounting line type info
161518    --
161519    xla_ae_lines_pkg.SetAcctLineType
161520       (p_component_type             => l_component_type
161521       ,p_event_type_code            => l_event_type_code
161522       ,p_line_definition_owner_code => l_line_definition_owner_code
161523       ,p_line_definition_code       => l_line_definition_code
161524       ,p_accounting_line_code       => l_component_code
161525       ,p_accounting_line_type_code  => l_component_type_code
161526       ,p_accounting_line_appl_id    => l_component_appl_id
161527       ,p_amb_context_code           => l_amb_context_code
161528       ,p_entity_code                => l_entity_code
161529       ,p_event_class_code           => l_event_class_code);
161530    --
161531    -- set accounting class
161532    --
161533    xla_ae_lines_pkg.SetAcctClass(
161534            p_accounting_class_code  => 'ASSET'
161535          , p_ae_header_id           => l_ae_header_id
161536          );
161537 
161538    --
161539    -- set rounding class
161540    --
161541    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
161542                       'ASSET';
161543 
161544    --
161545    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
161546    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
161547    --
161548    -- bulk performance
161549    --
161550    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
161551 
161552    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
161553       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
161554 
161555    -- 4955764
161556    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
161557       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
161558 
161559    -- 4458381 Public Sector Enh
161560    
161561    --
161562    -- set accounting attributes for the line type
161563    --
161564    l_entered_amt_idx := 4;
161565    l_accted_amt_idx  := 6;
161566    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
161567    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
161568    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
161569    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
161570    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
161574    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
161571    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
161572    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
161573    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
161575    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
161576    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
161577    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
161578    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
161579 
161580    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
161581    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
161582 
161583    ---------------------------------------------------------------------------------------------------------------
161584    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
161585    ---------------------------------------------------------------------------------------------------------------
161586    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
161587 
161588    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
161589    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
161590 
161591    IF xla_accounting_cache_pkg.GetValueChar
161592          (p_source_code         => 'LEDGER_CATEGORY_CODE'
161593          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
161594    AND l_bflow_method_code = 'PRIOR_ENTRY'
161595 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
161596    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
161597          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
161598        )
161599    THEN
161600          xla_ae_lines_pkg.BflowUpgEntry
161601            (p_business_method_code    => l_bflow_method_code
161602            ,p_business_class_code     => l_bflow_class_code
161603            ,p_balance_type            => l_balance_type_code);
161604    ELSE
161605       NULL;
161606 -- No business flow processing for business flow method of NONE.
161607    END IF;
161608 
161609    --
161610    -- call analytical criteria
161611    --
161612    
161613    --
161614    -- call description
161615    --
161616    
161617 xla_ae_lines_pkg.SetLineDescription(
161618    p_ae_header_id => l_ae_header_id
161619   ,p_description  => Description_126 (
161620      p_application_id         => p_application_id
161621    , p_ae_header_id           => l_ae_header_id 
161622 , p_source_1 => p_source_1
161623    )
161624 );
161625 
161626 
161627    --
161628    -- call ADRs
161629    -- Bug 4922099
161630    --
161631    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
161632         (NVL(l_actual_upg_option, 'N') = 'O') OR
161633         (NVL(l_enc_upg_option, 'N') = 'O')
161634       )
161635    THEN
161636    NULL;
161637    --
161638    --
161639    
161640   l_ccid := AcctDerRule_173(
161641            p_application_id           => p_application_id
161642          , p_ae_header_id             => l_ae_header_id 
161643 , p_source_3 => p_source_3
161644 , p_source_30 => p_source_30
161645          , x_transaction_coa_id       => l_adr_transaction_coa_id
161646          , x_accounting_coa_id        => l_adr_accounting_coa_id
161647          , x_value_type_code          => l_adr_value_type_code
161648          , p_side                     => 'NA'
161649    );
161650 
161651    xla_ae_lines_pkg.set_ccid(
161652     p_code_combination_id          => l_ccid
161653   , p_value_type_code              => l_adr_value_type_code
161654   , p_transaction_coa_id           => l_adr_transaction_coa_id
161655   , p_accounting_coa_id            => l_adr_accounting_coa_id
161656   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
161657   , p_adr_type_code                => 'S'
161658   , p_component_type               => l_component_type
161659   , p_component_code               => l_component_code
161660   , p_component_type_code          => l_component_type_code
161661   , p_component_appl_id            => l_component_appl_id
161662   , p_amb_context_code             => l_amb_context_code
161663   , p_side                         => 'NA'
161664   );
161665 
161666 
161667    l_segment := AcctDerRule_148(
161668            p_application_id           => p_application_id
161669          , p_ae_header_id             => l_ae_header_id 
161670 , p_source_3 => p_source_3
161671 , p_source_9 => p_source_9
161672          , x_transaction_coa_id       => l_adr_transaction_coa_id
161673          , x_accounting_coa_id        => l_adr_accounting_coa_id
161674          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
161675          , x_flex_value_set_id        => l_adr_flex_value_set_id
161676          , x_value_type_code          => l_adr_value_type_code
161677          , x_value_combination_id     => l_adr_value_combination_id
161678          , x_value_segment_code       => l_adr_value_segment_code
161679          , p_side                     => 'NA'
161680          , p_override_seg_flag        => 'Y'
161681    );
161682 
161683    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
161684 
161685       xla_ae_lines_pkg.set_segment(
161686           p_to_segment_code         => 'GL_ACCOUNT'
161687         , p_segment_value           => l_segment
161688         , p_from_segment_code       => l_adr_value_segment_code
161689         , p_from_combination_id     => l_adr_value_combination_id
161690         , p_value_type_code         => l_adr_value_type_code
161691         , p_transaction_coa_id      => l_adr_transaction_coa_id
161692         , p_accounting_coa_id       => l_adr_accounting_coa_id
161693         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
161694         , p_flex_value_set_id       => l_adr_flex_value_set_id
161698         , p_component_code          => l_component_code
161695         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
161696         , p_adr_type_code           => 'S'
161697         , p_component_type          => l_component_type
161699         , p_component_type_code     => l_component_type_code
161700         , p_component_appl_id       => l_component_appl_id
161701         , p_amb_context_code        => l_amb_context_code
161702         , p_entity_code             => 'TRANSACTIONS'
161703         , p_event_class_code        => 'TRANSFERS'
161704         , p_side                    => 'NA'
161705         );
161706 
161707   END IF;
161708 
161709    l_segment := AcctDerRule_168(
161710            p_application_id           => p_application_id
161711          , p_ae_header_id             => l_ae_header_id 
161712 , p_source_3 => p_source_3
161713 , p_source_29 => p_source_29
161714          , x_transaction_coa_id       => l_adr_transaction_coa_id
161715          , x_accounting_coa_id        => l_adr_accounting_coa_id
161716          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
161717          , x_flex_value_set_id        => l_adr_flex_value_set_id
161718          , x_value_type_code          => l_adr_value_type_code
161719          , x_value_combination_id     => l_adr_value_combination_id
161720          , x_value_segment_code       => l_adr_value_segment_code
161721          , p_side                     => 'NA'
161722          , p_override_seg_flag        => 'Y'
161723    );
161724 
161725    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
161726 
161727       xla_ae_lines_pkg.set_segment(
161728           p_to_segment_code         => 'GL_BALANCING'
161729         , p_segment_value           => l_segment
161730         , p_from_segment_code       => l_adr_value_segment_code
161731         , p_from_combination_id     => l_adr_value_combination_id
161732         , p_value_type_code         => l_adr_value_type_code
161733         , p_transaction_coa_id      => l_adr_transaction_coa_id
161734         , p_accounting_coa_id       => l_adr_accounting_coa_id
161735         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
161736         , p_flex_value_set_id       => l_adr_flex_value_set_id
161737         , p_adr_code                => 'FA_EXPENSE_ACCT'
161738         , p_adr_type_code           => 'S'
161739         , p_component_type          => l_component_type
161740         , p_component_code          => l_component_code
161741         , p_component_type_code     => l_component_type_code
161742         , p_component_appl_id       => l_component_appl_id
161743         , p_amb_context_code        => l_amb_context_code
161744         , p_entity_code             => 'TRANSACTIONS'
161745         , p_event_class_code        => 'TRANSFERS'
161746         , p_side                    => 'NA'
161747         );
161748 
161749   END IF;
161750 
161751    --
161752    --
161753    END IF;
161754    --
161755    -- Bug 4922099
161756    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
161757           (NVL(l_enc_upg_option, 'N') = 'O')
161758         ) AND
161759         (l_bflow_method_code = 'PRIOR_ENTRY')
161760       )
161761    THEN
161762       IF
161763       --
161764       1 = 2
161765       --
161766       THEN
161767       xla_accounting_err_pkg.build_message
161768                                     (p_appli_s_name            => 'XLA'
161769                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
161770                                     ,p_token_1                 => 'LINE_NUMBER'
161771                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
161772                                     ,p_token_2                 => 'LINE_TYPE_NAME'
161773                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
161774                                                                              l_component_type
161775                                                                             ,l_component_code
161776                                                                             ,l_component_type_code
161777                                                                             ,l_component_appl_id
161778                                                                             ,l_amb_context_code
161779                                                                             ,l_entity_code
161780                                                                             ,l_event_class_code
161781                                                                            )
161782                                     ,p_token_3                 => 'OWNER'
161783                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
161784                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
161785                                                                           ,p_lookup_code    => l_component_type_code
161786                                                                          )
161787                                     ,p_token_4                 => 'PRODUCT_NAME'
161788                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
161789                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
161790                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
161791                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
161792                                     ,p_ae_header_id            =>  NULL
161793                                        );
161794 
161795         IF (C_LEVEL_ERROR>= g_log_level) THEN
161796                  trace
161797                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
161798                       ,p_level    => C_LEVEL_ERROR
161799                       ,p_module   => l_log_module);
161800         END IF;
161801       END IF;
161805    ------------------------------------------------------------------------------------------------
161802    END IF;
161803    --
161804    --
161806    -- 4219869 Business Flow
161807    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
161808    -- Prior Entry.  Currently, the following code is always generated.
161809    ------------------------------------------------------------------------------------------------
161810    XLA_AE_LINES_PKG.ValidateCurrentLine;
161811 
161812    ------------------------------------------------------------------------------------
161813    -- 4219869 Business Flow
161814    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
161815    ------------------------------------------------------------------------------------
161816    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
161817 
161818    ----------------------------------------------------------------------------------
161819    -- 4219869 Business Flow
161820    -- Update journal entry status -- Need to generate this within IF <condition>
161821    ----------------------------------------------------------------------------------
161822    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
161823          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
161824          ,p_balance_type_code => l_balance_type_code
161825          );
161826 
161827    -------------------------------------------------------------------------------------------
161828    -- 4262811 - Generate the Accrual Reversal lines
161829    -------------------------------------------------------------------------------------------
161830    BEGIN
161831       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
161832                               (g_array_event(p_event_id).array_value_num('header_index'));
161833       IF l_acc_rev_flag IS NULL THEN
161834          l_acc_rev_flag := 'N';
161835       END IF;
161836    EXCEPTION
161837       WHEN OTHERS THEN
161838          l_acc_rev_flag := 'N';
161839    END;
161840    --
161841    IF (l_acc_rev_flag = 'Y') THEN
161842 
161843        -- 4645092  ------------------------------------------------------------------------------
161844        -- To allow MPA report to determine if it should generate report process
161845        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
161846        ------------------------------------------------------------------------------------------
161847 
161848        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
161849        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
161850    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
161851    -- call ADRs
161852    -- Bug 4922099
161853    --
161854    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
161855         (NVL(l_actual_upg_option, 'N') = 'O') OR
161856         (NVL(l_enc_upg_option, 'N') = 'O')
161857       )
161858    THEN
161859    NULL;
161860    --
161861    --
161862    
161863   l_ccid := AcctDerRule_173(
161864            p_application_id           => p_application_id
161865          , p_ae_header_id             => l_ae_header_id 
161866 , p_source_3 => p_source_3
161867 , p_source_30 => p_source_30
161868          , x_transaction_coa_id       => l_adr_transaction_coa_id
161869          , x_accounting_coa_id        => l_adr_accounting_coa_id
161870          , x_value_type_code          => l_adr_value_type_code
161871          , p_side                     => 'NA'
161872    );
161873 
161874    xla_ae_lines_pkg.set_ccid(
161875     p_code_combination_id          => l_ccid
161876   , p_value_type_code              => l_adr_value_type_code
161877   , p_transaction_coa_id           => l_adr_transaction_coa_id
161878   , p_accounting_coa_id            => l_adr_accounting_coa_id
161879   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
161880   , p_adr_type_code                => 'S'
161881   , p_component_type               => l_component_type
161882   , p_component_code               => l_component_code
161883   , p_component_type_code          => l_component_type_code
161884   , p_component_appl_id            => l_component_appl_id
161885   , p_amb_context_code             => l_amb_context_code
161886   , p_side                         => 'NA'
161887   );
161888 
161889 
161890    l_segment := AcctDerRule_148(
161891            p_application_id           => p_application_id
161892          , p_ae_header_id             => l_ae_header_id 
161893 , p_source_3 => p_source_3
161894 , p_source_9 => p_source_9
161895          , x_transaction_coa_id       => l_adr_transaction_coa_id
161896          , x_accounting_coa_id        => l_adr_accounting_coa_id
161897          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
161898          , x_flex_value_set_id        => l_adr_flex_value_set_id
161899          , x_value_type_code          => l_adr_value_type_code
161900          , x_value_combination_id     => l_adr_value_combination_id
161901          , x_value_segment_code       => l_adr_value_segment_code
161902          , p_side                     => 'NA'
161903          , p_override_seg_flag        => 'Y'
161904    );
161905 
161906    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
161907 
161908       xla_ae_lines_pkg.set_segment(
161909           p_to_segment_code         => 'GL_ACCOUNT'
161910         , p_segment_value           => l_segment
161911         , p_from_segment_code       => l_adr_value_segment_code
161912         , p_from_combination_id     => l_adr_value_combination_id
161913         , p_value_type_code         => l_adr_value_type_code
161914         , p_transaction_coa_id      => l_adr_transaction_coa_id
161915         , p_accounting_coa_id       => l_adr_accounting_coa_id
161916         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
161917         , p_flex_value_set_id       => l_adr_flex_value_set_id
161918         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
161919         , p_adr_type_code           => 'S'
161923         , p_component_appl_id       => l_component_appl_id
161920         , p_component_type          => l_component_type
161921         , p_component_code          => l_component_code
161922         , p_component_type_code     => l_component_type_code
161924         , p_amb_context_code        => l_amb_context_code
161925         , p_entity_code             => 'TRANSACTIONS'
161926         , p_event_class_code        => 'TRANSFERS'
161927         , p_side                    => 'NA'
161928         );
161929 
161930   END IF;
161931 
161932    l_segment := AcctDerRule_168(
161933            p_application_id           => p_application_id
161934          , p_ae_header_id             => l_ae_header_id 
161935 , p_source_3 => p_source_3
161936 , p_source_29 => p_source_29
161937          , x_transaction_coa_id       => l_adr_transaction_coa_id
161938          , x_accounting_coa_id        => l_adr_accounting_coa_id
161939          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
161940          , x_flex_value_set_id        => l_adr_flex_value_set_id
161941          , x_value_type_code          => l_adr_value_type_code
161942          , x_value_combination_id     => l_adr_value_combination_id
161943          , x_value_segment_code       => l_adr_value_segment_code
161944          , p_side                     => 'NA'
161945          , p_override_seg_flag        => 'Y'
161946    );
161947 
161948    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
161949 
161950       xla_ae_lines_pkg.set_segment(
161951           p_to_segment_code         => 'GL_BALANCING'
161952         , p_segment_value           => l_segment
161953         , p_from_segment_code       => l_adr_value_segment_code
161954         , p_from_combination_id     => l_adr_value_combination_id
161955         , p_value_type_code         => l_adr_value_type_code
161956         , p_transaction_coa_id      => l_adr_transaction_coa_id
161957         , p_accounting_coa_id       => l_adr_accounting_coa_id
161958         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
161959         , p_flex_value_set_id       => l_adr_flex_value_set_id
161960         , p_adr_code                => 'FA_EXPENSE_ACCT'
161961         , p_adr_type_code           => 'S'
161962         , p_component_type          => l_component_type
161963         , p_component_code          => l_component_code
161964         , p_component_type_code     => l_component_type_code
161965         , p_component_appl_id       => l_component_appl_id
161966         , p_amb_context_code        => l_amb_context_code
161967         , p_entity_code             => 'TRANSACTIONS'
161968         , p_event_class_code        => 'TRANSFERS'
161969         , p_side                    => 'NA'
161970         );
161971 
161972   END IF;
161973 
161974    --
161975    --
161976    END IF;
161977 
161978        --
161979        -- Update the line information that should be overwritten
161980        --
161981        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
161982                                          p_header_num   => 1);
161983        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
161984 
161985        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
161986 
161987        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
161988           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
161989        END IF;
161990 
161991       --
161992       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
161993       --
161994       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
161995           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
161996       ELSE
161997           ---------------------------------------------------------------------------------------------------
161998           -- 4262811a Switch Sign
161999           ---------------------------------------------------------------------------------------------------
162000           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
162001           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
162002                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
162003           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
162004                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
162005           -- 5132302
162006           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
162007                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
162008 
162009       END IF;
162010 
162011       -- 4955764
162012       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
162013       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
162014 
162015 
162016       XLA_AE_LINES_PKG.ValidateCurrentLine;
162017       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
162018 
162019       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
162020                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
162021                ,p_balance_type_code => l_balance_type_code);
162022 
162023    END IF;
162024 
162025    -----------------------------------------------------------------------------------------
162026    -- 4262811 Multiperiod Accounting
162027    -----------------------------------------------------------------------------------------
162028      -- No MPA option is assigned.
162029 
162030 
162031 END IF;
162032 END IF;
162033 --
162034 
162035 --
162036 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
162037    trace
162041 END IF;
162038       (p_msg      => 'END of AcctLineType_381'
162039       ,p_level    => C_LEVEL_PROCEDURE
162040       ,p_module   => l_log_module);
162042 --
162043 EXCEPTION
162044   WHEN xla_exceptions_pkg.application_exception THEN
162045       RAISE;
162046   WHEN OTHERS THEN
162047        xla_exceptions_pkg.raise_message
162048            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_381');
162049 END AcctLineType_381;
162050 --
162051 
162052 ---------------------------------------
162053 --
162054 -- PRIVATE FUNCTION
162055 --         AcctLineType_382
162056 --
162057 ---------------------------------------
162058 PROCEDURE AcctLineType_382 (
162059   p_application_id        IN NUMBER
162060  ,p_event_id              IN NUMBER
162061  ,p_calculate_acctd_flag  IN VARCHAR2
162062  ,p_calculate_g_l_flag    IN VARCHAR2
162063  ,p_actual_flag           IN OUT VARCHAR2
162064  ,p_balance_type_code     OUT VARCHAR2
162065  ,p_gain_or_loss_ref      OUT VARCHAR2
162066  
162067 --Period Close Date
162068  , p_source_1            IN DATE
162069 --Generated Code Combination Identifier
162070  , p_source_3            IN NUMBER
162071 --Expense Account Code Combination Identifier
162072  , p_source_29            IN NUMBER
162073 --Adjustment Type
162074  , p_source_35            IN VARCHAR2
162075 --Transaction Header Identifier
162076  , p_source_36            IN NUMBER
162077 --Adjustment Line Identifier
162078  , p_source_37            IN NUMBER
162079 --Distribution Type Code
162080  , p_source_38            IN VARCHAR2
162081 --Entered Amount
162082  , p_source_39            IN NUMBER
162083 --Currency Code
162084  , p_source_40            IN VARCHAR2
162085 --Source Destination Code
162086  , p_source_42            IN VARCHAR2
162087 )
162088 IS
162089 
162090 l_component_type              VARCHAR2(80);
162091 l_component_code              VARCHAR2(30);
162092 l_component_type_code         VARCHAR2(1);
162093 l_component_appl_id           INTEGER;
162094 l_amb_context_code            VARCHAR2(30);
162095 l_entity_code                 VARCHAR2(30);
162096 l_event_class_code            VARCHAR2(30);
162097 l_ae_header_id                NUMBER;
162098 l_event_type_code             VARCHAR2(30);
162099 l_line_definition_code        VARCHAR2(30);
162100 l_line_definition_owner_code  VARCHAR2(1);
162101 --
162102 -- adr variables
162103 l_segment                     VARCHAR2(30);
162104 l_ccid                        NUMBER;
162105 l_adr_transaction_coa_id      NUMBER;
162106 l_adr_accounting_coa_id       NUMBER;
162107 l_adr_flexfield_segment_code  VARCHAR2(30);
162108 l_adr_flex_value_set_id       NUMBER;
162109 l_adr_value_type_code         VARCHAR2(30);
162110 l_adr_value_combination_id    NUMBER;
162111 l_adr_value_segment_code      VARCHAR2(30);
162112 
162113 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
162114 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
162115 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
162116 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
162117 
162118 -- 4262811 Variables ------------------------------------------------------------------------------------------
162119 l_entered_amt_idx             NUMBER;
162120 l_accted_amt_idx              NUMBER;
162121 l_acc_rev_flag                VARCHAR2(1);
162122 l_accrual_line_num            NUMBER;
162123 l_tmp_amt                     NUMBER;
162124 l_acc_rev_natural_side_code   VARCHAR2(1);
162125 
162126 l_num_entries                 NUMBER;
162127 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
162128 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
162129 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
162130 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
162131 l_recog_line_1                NUMBER;
162132 l_recog_line_2                NUMBER;
162133 
162134 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
162135 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
162136 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
162137 
162138 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
162139 
162140 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
162141 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
162142 
162143 ---------------------------------------------------------------------------------------------------------------
162144 
162145 
162146 --
162147 -- bulk performance
162148 --
162149 l_balance_type_code           VARCHAR2(1);
162150 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
162151 l_log_module                  VARCHAR2(240);
162152 
162153 --
162154 -- Upgrade strategy
162155 --
162156 l_actual_upg_option           VARCHAR2(1);
162157 l_enc_upg_option           VARCHAR2(1);
162158 
162159 --
162160 BEGIN
162161 --
162162 IF g_log_enabled THEN
162163       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_382';
162164 END IF;
162165 --
162166 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
162167 
162168       trace
162169          (p_msg      => 'BEGIN of AcctLineType_382'
162170          ,p_level    => C_LEVEL_PROCEDURE
162171          ,p_module   => l_log_module);
162172 
162173 END IF;
162174 --
162175 l_component_type             := 'AMB_JLT';
162176 l_component_code             := 'FA_TRANSFER_SOURCE_DEPRN_EXP';
162177 l_component_type_code        := 'S';
162178 l_component_appl_id          :=  140;
162179 l_amb_context_code           := 'DEFAULT';
162180 l_entity_code                := 'TRANSACTIONS';
162181 l_event_class_code           := 'TRANSFERS';
162182 l_event_type_code            := 'TRANSFERS_ALL';
162183 l_line_definition_owner_code := 'S';
162187 l_segment                     := NULL;
162184 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
162185 --
162186 l_balance_type_code          := 'A';
162188 l_ccid                        := NULL;
162189 l_adr_transaction_coa_id      := NULL;
162190 l_adr_accounting_coa_id       := NULL;
162191 l_adr_flexfield_segment_code  := NULL;
162192 l_adr_flex_value_set_id       := NULL;
162193 l_adr_value_type_code         := NULL;
162194 l_adr_value_combination_id    := NULL;
162195 l_adr_value_segment_code      := NULL;
162196 
162197 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
162198 l_bflow_class_code           := '';    -- 4219869 Business Flow
162199 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
162200 l_budgetary_control_flag     := 'N';
162201 
162202 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
162203 l_bflow_applied_to_amt       := NULL; -- 5132302
162204 l_entered_amt_idx            := NULL;          -- 4262811
162205 l_accted_amt_idx             := NULL;          -- 4262811
162206 l_acc_rev_flag               := NULL;          -- 4262811
162207 l_accrual_line_num           := NULL;          -- 4262811
162208 l_tmp_amt                    := NULL;          -- 4262811
162209 --
162210  
162211 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
162212     l_balance_type_code <> 'B' THEN
162213 IF NVL(p_source_35,'
162214 ') =  'EXPENSE' AND 
162215 NVL(p_source_42,'
162216 ') =  'SOURCE'
162217  THEN 
162218 
162219    --
162220    XLA_AE_LINES_PKG.SetNewLine;
162221 
162222    p_balance_type_code          := l_balance_type_code;
162223    -- set the flag so later we will know whether the gain loss line needs to be created
162224    
162225    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
162226      p_actual_flag :='A';
162227    END IF;
162228 
162229    --
162230    -- bulk performance
162231    --
162232    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
162233                                       p_header_num   => 0); -- 4262811
162234    --
162235    -- set accounting line options
162236    --
162237    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
162238            p_natural_side_code          => 'C'
162239          , p_gain_or_loss_flag          => 'N'
162240          , p_gl_transfer_mode_code      => 'S'
162241          , p_acct_entry_type_code       => 'A'
162242          , p_switch_side_flag           => 'Y'
162243          , p_merge_duplicate_code       => 'N'
162244          );
162245    --
162246    l_acc_rev_natural_side_code := 'D';  -- 4262811
162247    -- 
162248    --
162249    -- set accounting line type info
162250    --
162251    xla_ae_lines_pkg.SetAcctLineType
162252       (p_component_type             => l_component_type
162253       ,p_event_type_code            => l_event_type_code
162254       ,p_line_definition_owner_code => l_line_definition_owner_code
162255       ,p_line_definition_code       => l_line_definition_code
162256       ,p_accounting_line_code       => l_component_code
162257       ,p_accounting_line_type_code  => l_component_type_code
162258       ,p_accounting_line_appl_id    => l_component_appl_id
162259       ,p_amb_context_code           => l_amb_context_code
162260       ,p_entity_code                => l_entity_code
162261       ,p_event_class_code           => l_event_class_code);
162262    --
162263    -- set accounting class
162264    --
162265    xla_ae_lines_pkg.SetAcctClass(
162266            p_accounting_class_code  => 'EXPENSE'
162267          , p_ae_header_id           => l_ae_header_id
162268          );
162269 
162270    --
162271    -- set rounding class
162272    --
162273    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
162274                       'EXPENSE';
162275 
162276    --
162277    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
162278    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
162279    --
162280    -- bulk performance
162281    --
162282    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
162283 
162284    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
162285       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
162286 
162287    -- 4955764
162288    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
162289       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
162290 
162291    -- 4458381 Public Sector Enh
162292    
162293    --
162294    -- set accounting attributes for the line type
162295    --
162296    l_entered_amt_idx := 4;
162297    l_accted_amt_idx  := 6;
162298    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
162299    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
162300    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
162301    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
162302    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
162303    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
162304    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
162305    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
162306    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
162307    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
162308    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
162309    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
162310    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
162311 
162312    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
162313    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
162314 
162318    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
162315    ---------------------------------------------------------------------------------------------------------------
162316    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
162317    ---------------------------------------------------------------------------------------------------------------
162319 
162320    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
162321    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
162322 
162323    IF xla_accounting_cache_pkg.GetValueChar
162324          (p_source_code         => 'LEDGER_CATEGORY_CODE'
162325          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
162326    AND l_bflow_method_code = 'PRIOR_ENTRY'
162327 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
162328    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
162329          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
162330        )
162331    THEN
162332          xla_ae_lines_pkg.BflowUpgEntry
162333            (p_business_method_code    => l_bflow_method_code
162334            ,p_business_class_code     => l_bflow_class_code
162335            ,p_balance_type            => l_balance_type_code);
162336    ELSE
162337       NULL;
162338 -- No business flow processing for business flow method of NONE.
162339    END IF;
162340 
162341    --
162342    -- call analytical criteria
162343    --
162344    
162345    --
162346    -- call description
162347    --
162348    
162349 xla_ae_lines_pkg.SetLineDescription(
162350    p_ae_header_id => l_ae_header_id
162351   ,p_description  => Description_127 (
162352      p_application_id         => p_application_id
162353    , p_ae_header_id           => l_ae_header_id 
162354 , p_source_1 => p_source_1
162355    )
162356 );
162357 
162358 
162359    --
162360    -- call ADRs
162361    -- Bug 4922099
162362    --
162363    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
162364         (NVL(l_actual_upg_option, 'N') = 'O') OR
162365         (NVL(l_enc_upg_option, 'N') = 'O')
162366       )
162367    THEN
162368    NULL;
162369    --
162370    --
162371    
162372   l_ccid := AcctDerRule_175(
162373            p_application_id           => p_application_id
162374          , p_ae_header_id             => l_ae_header_id 
162375 , p_source_3 => p_source_3
162376 , p_source_29 => p_source_29
162377          , x_transaction_coa_id       => l_adr_transaction_coa_id
162378          , x_accounting_coa_id        => l_adr_accounting_coa_id
162379          , x_value_type_code          => l_adr_value_type_code
162380          , p_side                     => 'NA'
162381    );
162382 
162383    xla_ae_lines_pkg.set_ccid(
162384     p_code_combination_id          => l_ccid
162385   , p_value_type_code              => l_adr_value_type_code
162386   , p_transaction_coa_id           => l_adr_transaction_coa_id
162387   , p_accounting_coa_id            => l_adr_accounting_coa_id
162388   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
162389   , p_adr_type_code                => 'S'
162390   , p_component_type               => l_component_type
162391   , p_component_code               => l_component_code
162392   , p_component_type_code          => l_component_type_code
162393   , p_component_appl_id            => l_component_appl_id
162394   , p_amb_context_code             => l_amb_context_code
162395   , p_side                         => 'NA'
162396   );
162397 
162398 
162399    --
162400    --
162401    END IF;
162402    --
162403    -- Bug 4922099
162404    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
162405           (NVL(l_enc_upg_option, 'N') = 'O')
162406         ) AND
162407         (l_bflow_method_code = 'PRIOR_ENTRY')
162408       )
162409    THEN
162410       IF
162411       --
162412       1 = 2
162413       --
162414       THEN
162415       xla_accounting_err_pkg.build_message
162416                                     (p_appli_s_name            => 'XLA'
162417                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
162418                                     ,p_token_1                 => 'LINE_NUMBER'
162419                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
162420                                     ,p_token_2                 => 'LINE_TYPE_NAME'
162421                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
162422                                                                              l_component_type
162423                                                                             ,l_component_code
162424                                                                             ,l_component_type_code
162425                                                                             ,l_component_appl_id
162426                                                                             ,l_amb_context_code
162427                                                                             ,l_entity_code
162428                                                                             ,l_event_class_code
162429                                                                            )
162430                                     ,p_token_3                 => 'OWNER'
162431                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
162432                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
162433                                                                           ,p_lookup_code    => l_component_type_code
162434                                                                          )
162435                                     ,p_token_4                 => 'PRODUCT_NAME'
162439                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
162436                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
162437                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
162438                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
162440                                     ,p_ae_header_id            =>  NULL
162441                                        );
162442 
162443         IF (C_LEVEL_ERROR>= g_log_level) THEN
162444                  trace
162445                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
162446                       ,p_level    => C_LEVEL_ERROR
162447                       ,p_module   => l_log_module);
162448         END IF;
162449       END IF;
162450    END IF;
162451    --
162452    --
162453    ------------------------------------------------------------------------------------------------
162454    -- 4219869 Business Flow
162455    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
162456    -- Prior Entry.  Currently, the following code is always generated.
162457    ------------------------------------------------------------------------------------------------
162458    XLA_AE_LINES_PKG.ValidateCurrentLine;
162459 
162460    ------------------------------------------------------------------------------------
162461    -- 4219869 Business Flow
162462    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
162463    ------------------------------------------------------------------------------------
162464    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
162465 
162466    ----------------------------------------------------------------------------------
162467    -- 4219869 Business Flow
162468    -- Update journal entry status -- Need to generate this within IF <condition>
162469    ----------------------------------------------------------------------------------
162470    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
162471          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
162472          ,p_balance_type_code => l_balance_type_code
162473          );
162474 
162475    -------------------------------------------------------------------------------------------
162476    -- 4262811 - Generate the Accrual Reversal lines
162477    -------------------------------------------------------------------------------------------
162478    BEGIN
162479       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
162480                               (g_array_event(p_event_id).array_value_num('header_index'));
162481       IF l_acc_rev_flag IS NULL THEN
162482          l_acc_rev_flag := 'N';
162483       END IF;
162484    EXCEPTION
162485       WHEN OTHERS THEN
162486          l_acc_rev_flag := 'N';
162487    END;
162488    --
162489    IF (l_acc_rev_flag = 'Y') THEN
162490 
162491        -- 4645092  ------------------------------------------------------------------------------
162492        -- To allow MPA report to determine if it should generate report process
162493        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
162494        ------------------------------------------------------------------------------------------
162495 
162496        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
162497        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
162498    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
162499    -- call ADRs
162500    -- Bug 4922099
162501    --
162502    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
162503         (NVL(l_actual_upg_option, 'N') = 'O') OR
162504         (NVL(l_enc_upg_option, 'N') = 'O')
162505       )
162506    THEN
162507    NULL;
162508    --
162509    --
162510    
162511   l_ccid := AcctDerRule_175(
162512            p_application_id           => p_application_id
162513          , p_ae_header_id             => l_ae_header_id 
162514 , p_source_3 => p_source_3
162515 , p_source_29 => p_source_29
162516          , x_transaction_coa_id       => l_adr_transaction_coa_id
162517          , x_accounting_coa_id        => l_adr_accounting_coa_id
162518          , x_value_type_code          => l_adr_value_type_code
162519          , p_side                     => 'NA'
162520    );
162521 
162522    xla_ae_lines_pkg.set_ccid(
162523     p_code_combination_id          => l_ccid
162524   , p_value_type_code              => l_adr_value_type_code
162525   , p_transaction_coa_id           => l_adr_transaction_coa_id
162526   , p_accounting_coa_id            => l_adr_accounting_coa_id
162527   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
162528   , p_adr_type_code                => 'S'
162529   , p_component_type               => l_component_type
162530   , p_component_code               => l_component_code
162531   , p_component_type_code          => l_component_type_code
162532   , p_component_appl_id            => l_component_appl_id
162533   , p_amb_context_code             => l_amb_context_code
162534   , p_side                         => 'NA'
162535   );
162536 
162537 
162538    --
162539    --
162540    END IF;
162541 
162542        --
162543        -- Update the line information that should be overwritten
162544        --
162545        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
162546                                          p_header_num   => 1);
162547        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
162548 
162549        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
162550 
162551        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
162552           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
162553        END IF;
162554 
162555       --
162559           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
162556       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
162557       --
162558       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
162560       ELSE
162561           ---------------------------------------------------------------------------------------------------
162562           -- 4262811a Switch Sign
162563           ---------------------------------------------------------------------------------------------------
162564           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
162565           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
162566                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
162567           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
162568                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
162569           -- 5132302
162570           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
162571                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
162572 
162573       END IF;
162574 
162575       -- 4955764
162576       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
162577       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
162578 
162579 
162580       XLA_AE_LINES_PKG.ValidateCurrentLine;
162581       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
162582 
162583       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
162584                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
162585                ,p_balance_type_code => l_balance_type_code);
162586 
162587    END IF;
162588 
162589    -----------------------------------------------------------------------------------------
162590    -- 4262811 Multiperiod Accounting
162591    -----------------------------------------------------------------------------------------
162592      -- No MPA option is assigned.
162593 
162594 
162595 END IF;
162596 END IF;
162597 --
162598 
162599 --
162600 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
162601    trace
162602       (p_msg      => 'END of AcctLineType_382'
162603       ,p_level    => C_LEVEL_PROCEDURE
162604       ,p_module   => l_log_module);
162605 END IF;
162606 --
162607 EXCEPTION
162608   WHEN xla_exceptions_pkg.application_exception THEN
162609       RAISE;
162610   WHEN OTHERS THEN
162611        xla_exceptions_pkg.raise_message
162612            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_382');
162613 END AcctLineType_382;
162614 --
162615 
162616 ---------------------------------------
162617 --
162618 -- PRIVATE FUNCTION
162619 --         AcctLineType_383
162620 --
162621 ---------------------------------------
162622 PROCEDURE AcctLineType_383 (
162623   p_application_id        IN NUMBER
162624  ,p_event_id              IN NUMBER
162625  ,p_calculate_acctd_flag  IN VARCHAR2
162626  ,p_calculate_g_l_flag    IN VARCHAR2
162627  ,p_actual_flag           IN OUT VARCHAR2
162628  ,p_balance_type_code     OUT VARCHAR2
162629  ,p_gain_or_loss_ref      OUT VARCHAR2
162630  
162631 --Period Close Date
162632  , p_source_1            IN DATE
162633 --Generated Code Combination Identifier
162634  , p_source_3            IN NUMBER
162635 --Depreciation Reserve Account
162636  , p_source_10            IN VARCHAR2
162637 --Generated Offset Code Combination Identifier
162638  , p_source_17            IN NUMBER
162639 --Expense Account Code Combination Identifier
162640  , p_source_29            IN NUMBER
162641 --Default Code Combination Identifier
162642  , p_source_30            IN NUMBER
162643 --Adjustment Type
162644  , p_source_35            IN VARCHAR2
162645 --Transaction Header Identifier
162646  , p_source_36            IN NUMBER
162647 --Adjustment Line Identifier
162648  , p_source_37            IN NUMBER
162649 --Distribution Type Code
162650  , p_source_38            IN VARCHAR2
162651 --Entered Amount
162652  , p_source_39            IN NUMBER
162653 --Currency Code
162654  , p_source_40            IN VARCHAR2
162655 --Source Destination Code
162656  , p_source_42            IN VARCHAR2
162657 )
162658 IS
162659 
162660 l_component_type              VARCHAR2(80);
162661 l_component_code              VARCHAR2(30);
162662 l_component_type_code         VARCHAR2(1);
162663 l_component_appl_id           INTEGER;
162664 l_amb_context_code            VARCHAR2(30);
162665 l_entity_code                 VARCHAR2(30);
162666 l_event_class_code            VARCHAR2(30);
162667 l_ae_header_id                NUMBER;
162668 l_event_type_code             VARCHAR2(30);
162669 l_line_definition_code        VARCHAR2(30);
162670 l_line_definition_owner_code  VARCHAR2(1);
162671 --
162672 -- adr variables
162673 l_segment                     VARCHAR2(30);
162674 l_ccid                        NUMBER;
162675 l_adr_transaction_coa_id      NUMBER;
162676 l_adr_accounting_coa_id       NUMBER;
162677 l_adr_flexfield_segment_code  VARCHAR2(30);
162678 l_adr_flex_value_set_id       NUMBER;
162679 l_adr_value_type_code         VARCHAR2(30);
162680 l_adr_value_combination_id    NUMBER;
162681 l_adr_value_segment_code      VARCHAR2(30);
162682 
162683 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
162684 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
162685 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
162686 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
162687 
162691 l_acc_rev_flag                VARCHAR2(1);
162688 -- 4262811 Variables ------------------------------------------------------------------------------------------
162689 l_entered_amt_idx             NUMBER;
162690 l_accted_amt_idx              NUMBER;
162692 l_accrual_line_num            NUMBER;
162693 l_tmp_amt                     NUMBER;
162694 l_acc_rev_natural_side_code   VARCHAR2(1);
162695 
162696 l_num_entries                 NUMBER;
162697 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
162698 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
162699 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
162700 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
162701 l_recog_line_1                NUMBER;
162702 l_recog_line_2                NUMBER;
162703 
162704 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
162705 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
162706 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
162707 
162708 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
162709 
162710 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
162711 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
162712 
162713 ---------------------------------------------------------------------------------------------------------------
162714 
162715 
162716 --
162717 -- bulk performance
162718 --
162719 l_balance_type_code           VARCHAR2(1);
162720 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
162721 l_log_module                  VARCHAR2(240);
162722 
162723 --
162724 -- Upgrade strategy
162725 --
162726 l_actual_upg_option           VARCHAR2(1);
162727 l_enc_upg_option           VARCHAR2(1);
162728 
162729 --
162730 BEGIN
162731 --
162732 IF g_log_enabled THEN
162733       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_383';
162734 END IF;
162735 --
162736 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
162737 
162738       trace
162739          (p_msg      => 'BEGIN of AcctLineType_383'
162740          ,p_level    => C_LEVEL_PROCEDURE
162741          ,p_module   => l_log_module);
162742 
162743 END IF;
162744 --
162745 l_component_type             := 'AMB_JLT';
162746 l_component_code             := 'FA_TRANSFER_SOURCE_DEPRN_RES';
162747 l_component_type_code        := 'S';
162748 l_component_appl_id          :=  140;
162749 l_amb_context_code           := 'DEFAULT';
162750 l_entity_code                := 'TRANSACTIONS';
162751 l_event_class_code           := 'TRANSFERS';
162752 l_event_type_code            := 'TRANSFERS_ALL';
162753 l_line_definition_owner_code := 'S';
162754 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
162755 --
162756 l_balance_type_code          := 'A';
162757 l_segment                     := NULL;
162758 l_ccid                        := NULL;
162759 l_adr_transaction_coa_id      := NULL;
162760 l_adr_accounting_coa_id       := NULL;
162761 l_adr_flexfield_segment_code  := NULL;
162762 l_adr_flex_value_set_id       := NULL;
162763 l_adr_value_type_code         := NULL;
162764 l_adr_value_combination_id    := NULL;
162765 l_adr_value_segment_code      := NULL;
162766 
162767 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
162768 l_bflow_class_code           := '';    -- 4219869 Business Flow
162769 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
162770 l_budgetary_control_flag     := 'N';
162771 
162772 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
162773 l_bflow_applied_to_amt       := NULL; -- 5132302
162774 l_entered_amt_idx            := NULL;          -- 4262811
162775 l_accted_amt_idx             := NULL;          -- 4262811
162776 l_acc_rev_flag               := NULL;          -- 4262811
162777 l_accrual_line_num           := NULL;          -- 4262811
162778 l_tmp_amt                    := NULL;          -- 4262811
162779 --
162780  
162781 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
162782     l_balance_type_code <> 'B' THEN
162783 IF (NVL(p_source_35,'
162784 ') =  'RESERVE' OR 
162785 NVL(p_source_35,'
162786 ') =  'EXPENSE') AND 
162787 NVL(p_source_42,'
162788 ') =  'SOURCE'
162789  THEN 
162790 
162791    --
162792    XLA_AE_LINES_PKG.SetNewLine;
162793 
162794    p_balance_type_code          := l_balance_type_code;
162795    -- set the flag so later we will know whether the gain loss line needs to be created
162796    
162797    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
162798      p_actual_flag :='A';
162799    END IF;
162800 
162801    --
162802    -- bulk performance
162803    --
162804    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
162805                                       p_header_num   => 0); -- 4262811
162806    --
162807    -- set accounting line options
162808    --
162809    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
162810            p_natural_side_code          => 'D'
162811          , p_gain_or_loss_flag          => 'N'
162812          , p_gl_transfer_mode_code      => 'S'
162813          , p_acct_entry_type_code       => 'A'
162814          , p_switch_side_flag           => 'Y'
162815          , p_merge_duplicate_code       => 'N'
162816          );
162817    --
162818    l_acc_rev_natural_side_code := 'C';  -- 4262811
162819    -- 
162820    --
162821    -- set accounting line type info
162822    --
162823    xla_ae_lines_pkg.SetAcctLineType
162824       (p_component_type             => l_component_type
162825       ,p_event_type_code            => l_event_type_code
162826       ,p_line_definition_owner_code => l_line_definition_owner_code
162827       ,p_line_definition_code       => l_line_definition_code
162828       ,p_accounting_line_code       => l_component_code
162832       ,p_entity_code                => l_entity_code
162829       ,p_accounting_line_type_code  => l_component_type_code
162830       ,p_accounting_line_appl_id    => l_component_appl_id
162831       ,p_amb_context_code           => l_amb_context_code
162833       ,p_event_class_code           => l_event_class_code);
162834    --
162835    -- set accounting class
162836    --
162837    xla_ae_lines_pkg.SetAcctClass(
162838            p_accounting_class_code  => 'ASSET'
162839          , p_ae_header_id           => l_ae_header_id
162840          );
162841 
162842    --
162843    -- set rounding class
162844    --
162845    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
162846                       'ASSET';
162847 
162848    --
162849    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
162850    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
162851    --
162852    -- bulk performance
162853    --
162854    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
162855 
162856    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
162857       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
162858 
162859    -- 4955764
162860    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
162861       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
162862 
162863    -- 4458381 Public Sector Enh
162864    
162865    --
162866    -- set accounting attributes for the line type
162867    --
162868    l_entered_amt_idx := 4;
162869    l_accted_amt_idx  := 6;
162870    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
162871    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
162872    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
162873    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
162874    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
162875    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
162876    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
162877    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
162878    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
162879    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
162880    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
162881    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
162882    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
162883 
162884    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
162885    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
162886 
162887    ---------------------------------------------------------------------------------------------------------------
162888    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
162889    ---------------------------------------------------------------------------------------------------------------
162890    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
162891 
162892    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
162893    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
162894 
162895    IF xla_accounting_cache_pkg.GetValueChar
162896          (p_source_code         => 'LEDGER_CATEGORY_CODE'
162897          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
162898    AND l_bflow_method_code = 'PRIOR_ENTRY'
162899 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
162900    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
162901          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
162902        )
162903    THEN
162904          xla_ae_lines_pkg.BflowUpgEntry
162905            (p_business_method_code    => l_bflow_method_code
162906            ,p_business_class_code     => l_bflow_class_code
162907            ,p_balance_type            => l_balance_type_code);
162908    ELSE
162909       NULL;
162910 -- No business flow processing for business flow method of NONE.
162911    END IF;
162912 
162913    --
162914    -- call analytical criteria
162915    --
162916    
162917    --
162918    -- call description
162919    --
162920    
162921 xla_ae_lines_pkg.SetLineDescription(
162922    p_ae_header_id => l_ae_header_id
162923   ,p_description  => Description_130 (
162924      p_application_id         => p_application_id
162925    , p_ae_header_id           => l_ae_header_id 
162926 , p_source_1 => p_source_1
162927    )
162928 );
162929 
162930 
162931    --
162932    -- call ADRs
162933    -- Bug 4922099
162934    --
162935    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
162936         (NVL(l_actual_upg_option, 'N') = 'O') OR
162937         (NVL(l_enc_upg_option, 'N') = 'O')
162938       )
162939    THEN
162940    NULL;
162941    --
162942    --
162943    
162944   l_ccid := AcctDerRule_174(
162945            p_application_id           => p_application_id
162946          , p_ae_header_id             => l_ae_header_id 
162947 , p_source_3 => p_source_3
162948 , p_source_17 => p_source_17
162949 , p_source_30 => p_source_30
162950          , x_transaction_coa_id       => l_adr_transaction_coa_id
162951          , x_accounting_coa_id        => l_adr_accounting_coa_id
162952          , x_value_type_code          => l_adr_value_type_code
162953          , p_side                     => 'NA'
162954    );
162955 
162956    xla_ae_lines_pkg.set_ccid(
162957     p_code_combination_id          => l_ccid
162958   , p_value_type_code              => l_adr_value_type_code
162962   , p_adr_type_code                => 'S'
162959   , p_transaction_coa_id           => l_adr_transaction_coa_id
162960   , p_accounting_coa_id            => l_adr_accounting_coa_id
162961   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
162963   , p_component_type               => l_component_type
162964   , p_component_code               => l_component_code
162965   , p_component_type_code          => l_component_type_code
162966   , p_component_appl_id            => l_component_appl_id
162967   , p_amb_context_code             => l_amb_context_code
162968   , p_side                         => 'NA'
162969   );
162970 
162971 
162972    l_segment := AcctDerRule_149(
162973            p_application_id           => p_application_id
162974          , p_ae_header_id             => l_ae_header_id 
162975 , p_source_3 => p_source_3
162976 , p_source_10 => p_source_10
162977          , x_transaction_coa_id       => l_adr_transaction_coa_id
162978          , x_accounting_coa_id        => l_adr_accounting_coa_id
162979          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
162980          , x_flex_value_set_id        => l_adr_flex_value_set_id
162981          , x_value_type_code          => l_adr_value_type_code
162982          , x_value_combination_id     => l_adr_value_combination_id
162983          , x_value_segment_code       => l_adr_value_segment_code
162984          , p_side                     => 'NA'
162985          , p_override_seg_flag        => 'Y'
162986    );
162987 
162988    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
162989 
162990       xla_ae_lines_pkg.set_segment(
162991           p_to_segment_code         => 'GL_ACCOUNT'
162992         , p_segment_value           => l_segment
162993         , p_from_segment_code       => l_adr_value_segment_code
162994         , p_from_combination_id     => l_adr_value_combination_id
162995         , p_value_type_code         => l_adr_value_type_code
162996         , p_transaction_coa_id      => l_adr_transaction_coa_id
162997         , p_accounting_coa_id       => l_adr_accounting_coa_id
162998         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
162999         , p_flex_value_set_id       => l_adr_flex_value_set_id
163000         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
163001         , p_adr_type_code           => 'S'
163002         , p_component_type          => l_component_type
163003         , p_component_code          => l_component_code
163004         , p_component_type_code     => l_component_type_code
163005         , p_component_appl_id       => l_component_appl_id
163006         , p_amb_context_code        => l_amb_context_code
163007         , p_entity_code             => 'TRANSACTIONS'
163008         , p_event_class_code        => 'TRANSFERS'
163009         , p_side                    => 'NA'
163010         );
163011 
163012   END IF;
163013 
163014    l_segment := AcctDerRule_168(
163015            p_application_id           => p_application_id
163016          , p_ae_header_id             => l_ae_header_id 
163017 , p_source_3 => p_source_3
163018 , p_source_29 => p_source_29
163019          , x_transaction_coa_id       => l_adr_transaction_coa_id
163020          , x_accounting_coa_id        => l_adr_accounting_coa_id
163021          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
163022          , x_flex_value_set_id        => l_adr_flex_value_set_id
163023          , x_value_type_code          => l_adr_value_type_code
163024          , x_value_combination_id     => l_adr_value_combination_id
163025          , x_value_segment_code       => l_adr_value_segment_code
163026          , p_side                     => 'NA'
163027          , p_override_seg_flag        => 'Y'
163028    );
163029 
163030    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
163031 
163032       xla_ae_lines_pkg.set_segment(
163033           p_to_segment_code         => 'GL_BALANCING'
163034         , p_segment_value           => l_segment
163035         , p_from_segment_code       => l_adr_value_segment_code
163036         , p_from_combination_id     => l_adr_value_combination_id
163037         , p_value_type_code         => l_adr_value_type_code
163038         , p_transaction_coa_id      => l_adr_transaction_coa_id
163039         , p_accounting_coa_id       => l_adr_accounting_coa_id
163040         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
163041         , p_flex_value_set_id       => l_adr_flex_value_set_id
163042         , p_adr_code                => 'FA_EXPENSE_ACCT'
163043         , p_adr_type_code           => 'S'
163044         , p_component_type          => l_component_type
163045         , p_component_code          => l_component_code
163046         , p_component_type_code     => l_component_type_code
163047         , p_component_appl_id       => l_component_appl_id
163048         , p_amb_context_code        => l_amb_context_code
163049         , p_entity_code             => 'TRANSACTIONS'
163050         , p_event_class_code        => 'TRANSFERS'
163051         , p_side                    => 'NA'
163052         );
163053 
163054   END IF;
163055 
163056    --
163057    --
163058    END IF;
163059    --
163060    -- Bug 4922099
163061    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
163062           (NVL(l_enc_upg_option, 'N') = 'O')
163063         ) AND
163064         (l_bflow_method_code = 'PRIOR_ENTRY')
163065       )
163066    THEN
163067       IF
163068       --
163069       1 = 2
163070       --
163071       THEN
163072       xla_accounting_err_pkg.build_message
163073                                     (p_appli_s_name            => 'XLA'
163074                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
163075                                     ,p_token_1                 => 'LINE_NUMBER'
163076                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
163077                                     ,p_token_2                 => 'LINE_TYPE_NAME'
163081                                                                             ,l_component_type_code
163078                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
163079                                                                              l_component_type
163080                                                                             ,l_component_code
163082                                                                             ,l_component_appl_id
163083                                                                             ,l_amb_context_code
163084                                                                             ,l_entity_code
163085                                                                             ,l_event_class_code
163086                                                                            )
163087                                     ,p_token_3                 => 'OWNER'
163088                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
163089                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
163090                                                                           ,p_lookup_code    => l_component_type_code
163091                                                                          )
163092                                     ,p_token_4                 => 'PRODUCT_NAME'
163093                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
163094                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
163095                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
163096                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
163097                                     ,p_ae_header_id            =>  NULL
163098                                        );
163099 
163100         IF (C_LEVEL_ERROR>= g_log_level) THEN
163101                  trace
163102                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
163103                       ,p_level    => C_LEVEL_ERROR
163104                       ,p_module   => l_log_module);
163105         END IF;
163106       END IF;
163107    END IF;
163108    --
163109    --
163110    ------------------------------------------------------------------------------------------------
163111    -- 4219869 Business Flow
163112    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
163113    -- Prior Entry.  Currently, the following code is always generated.
163114    ------------------------------------------------------------------------------------------------
163115    XLA_AE_LINES_PKG.ValidateCurrentLine;
163116 
163117    ------------------------------------------------------------------------------------
163118    -- 4219869 Business Flow
163119    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
163120    ------------------------------------------------------------------------------------
163121    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
163122 
163123    ----------------------------------------------------------------------------------
163124    -- 4219869 Business Flow
163125    -- Update journal entry status -- Need to generate this within IF <condition>
163126    ----------------------------------------------------------------------------------
163127    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
163128          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
163129          ,p_balance_type_code => l_balance_type_code
163130          );
163131 
163132    -------------------------------------------------------------------------------------------
163133    -- 4262811 - Generate the Accrual Reversal lines
163134    -------------------------------------------------------------------------------------------
163135    BEGIN
163136       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
163137                               (g_array_event(p_event_id).array_value_num('header_index'));
163138       IF l_acc_rev_flag IS NULL THEN
163139          l_acc_rev_flag := 'N';
163140       END IF;
163141    EXCEPTION
163142       WHEN OTHERS THEN
163143          l_acc_rev_flag := 'N';
163144    END;
163145    --
163146    IF (l_acc_rev_flag = 'Y') THEN
163147 
163148        -- 4645092  ------------------------------------------------------------------------------
163149        -- To allow MPA report to determine if it should generate report process
163150        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
163151        ------------------------------------------------------------------------------------------
163152 
163153        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
163154        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
163155    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
163156    -- call ADRs
163157    -- Bug 4922099
163158    --
163159    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
163160         (NVL(l_actual_upg_option, 'N') = 'O') OR
163161         (NVL(l_enc_upg_option, 'N') = 'O')
163162       )
163163    THEN
163164    NULL;
163165    --
163166    --
163167    
163168   l_ccid := AcctDerRule_174(
163169            p_application_id           => p_application_id
163170          , p_ae_header_id             => l_ae_header_id 
163171 , p_source_3 => p_source_3
163172 , p_source_17 => p_source_17
163173 , p_source_30 => p_source_30
163174          , x_transaction_coa_id       => l_adr_transaction_coa_id
163175          , x_accounting_coa_id        => l_adr_accounting_coa_id
163176          , x_value_type_code          => l_adr_value_type_code
163177          , p_side                     => 'NA'
163178    );
163179 
163180    xla_ae_lines_pkg.set_ccid(
163181     p_code_combination_id          => l_ccid
163182   , p_value_type_code              => l_adr_value_type_code
163186   , p_adr_type_code                => 'S'
163183   , p_transaction_coa_id           => l_adr_transaction_coa_id
163184   , p_accounting_coa_id            => l_adr_accounting_coa_id
163185   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
163187   , p_component_type               => l_component_type
163188   , p_component_code               => l_component_code
163189   , p_component_type_code          => l_component_type_code
163190   , p_component_appl_id            => l_component_appl_id
163191   , p_amb_context_code             => l_amb_context_code
163192   , p_side                         => 'NA'
163193   );
163194 
163195 
163196    l_segment := AcctDerRule_149(
163197            p_application_id           => p_application_id
163198          , p_ae_header_id             => l_ae_header_id 
163199 , p_source_3 => p_source_3
163200 , p_source_10 => p_source_10
163201          , x_transaction_coa_id       => l_adr_transaction_coa_id
163202          , x_accounting_coa_id        => l_adr_accounting_coa_id
163203          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
163204          , x_flex_value_set_id        => l_adr_flex_value_set_id
163205          , x_value_type_code          => l_adr_value_type_code
163206          , x_value_combination_id     => l_adr_value_combination_id
163207          , x_value_segment_code       => l_adr_value_segment_code
163208          , p_side                     => 'NA'
163209          , p_override_seg_flag        => 'Y'
163210    );
163211 
163212    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
163213 
163214       xla_ae_lines_pkg.set_segment(
163215           p_to_segment_code         => 'GL_ACCOUNT'
163216         , p_segment_value           => l_segment
163217         , p_from_segment_code       => l_adr_value_segment_code
163218         , p_from_combination_id     => l_adr_value_combination_id
163219         , p_value_type_code         => l_adr_value_type_code
163220         , p_transaction_coa_id      => l_adr_transaction_coa_id
163221         , p_accounting_coa_id       => l_adr_accounting_coa_id
163222         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
163223         , p_flex_value_set_id       => l_adr_flex_value_set_id
163224         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
163225         , p_adr_type_code           => 'S'
163226         , p_component_type          => l_component_type
163227         , p_component_code          => l_component_code
163228         , p_component_type_code     => l_component_type_code
163229         , p_component_appl_id       => l_component_appl_id
163230         , p_amb_context_code        => l_amb_context_code
163231         , p_entity_code             => 'TRANSACTIONS'
163232         , p_event_class_code        => 'TRANSFERS'
163233         , p_side                    => 'NA'
163234         );
163235 
163236   END IF;
163237 
163238    l_segment := AcctDerRule_168(
163239            p_application_id           => p_application_id
163240          , p_ae_header_id             => l_ae_header_id 
163241 , p_source_3 => p_source_3
163242 , p_source_29 => p_source_29
163243          , x_transaction_coa_id       => l_adr_transaction_coa_id
163244          , x_accounting_coa_id        => l_adr_accounting_coa_id
163245          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
163246          , x_flex_value_set_id        => l_adr_flex_value_set_id
163247          , x_value_type_code          => l_adr_value_type_code
163248          , x_value_combination_id     => l_adr_value_combination_id
163249          , x_value_segment_code       => l_adr_value_segment_code
163250          , p_side                     => 'NA'
163251          , p_override_seg_flag        => 'Y'
163252    );
163253 
163254    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
163255 
163256       xla_ae_lines_pkg.set_segment(
163257           p_to_segment_code         => 'GL_BALANCING'
163258         , p_segment_value           => l_segment
163259         , p_from_segment_code       => l_adr_value_segment_code
163260         , p_from_combination_id     => l_adr_value_combination_id
163261         , p_value_type_code         => l_adr_value_type_code
163262         , p_transaction_coa_id      => l_adr_transaction_coa_id
163263         , p_accounting_coa_id       => l_adr_accounting_coa_id
163264         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
163265         , p_flex_value_set_id       => l_adr_flex_value_set_id
163266         , p_adr_code                => 'FA_EXPENSE_ACCT'
163267         , p_adr_type_code           => 'S'
163268         , p_component_type          => l_component_type
163269         , p_component_code          => l_component_code
163270         , p_component_type_code     => l_component_type_code
163271         , p_component_appl_id       => l_component_appl_id
163272         , p_amb_context_code        => l_amb_context_code
163273         , p_entity_code             => 'TRANSACTIONS'
163274         , p_event_class_code        => 'TRANSFERS'
163275         , p_side                    => 'NA'
163276         );
163277 
163278   END IF;
163279 
163280    --
163281    --
163282    END IF;
163283 
163284        --
163285        -- Update the line information that should be overwritten
163286        --
163287        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
163288                                          p_header_num   => 1);
163289        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
163290 
163291        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
163292 
163293        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
163294           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
163295        END IF;
163296 
163297       --
163298       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
163299       --
163300       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
163304           -- 4262811a Switch Sign
163301           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
163302       ELSE
163303           ---------------------------------------------------------------------------------------------------
163305           ---------------------------------------------------------------------------------------------------
163306           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
163307           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
163308                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
163309           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
163310                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
163311           -- 5132302
163312           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
163313                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
163314 
163315       END IF;
163316 
163317       -- 4955764
163318       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
163319       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
163320 
163321 
163322       XLA_AE_LINES_PKG.ValidateCurrentLine;
163323       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
163324 
163325       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
163326                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
163327                ,p_balance_type_code => l_balance_type_code);
163328 
163329    END IF;
163330 
163331    -----------------------------------------------------------------------------------------
163332    -- 4262811 Multiperiod Accounting
163333    -----------------------------------------------------------------------------------------
163334      -- No MPA option is assigned.
163335 
163336 
163337 END IF;
163338 END IF;
163339 --
163340 
163341 --
163342 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
163343    trace
163344       (p_msg      => 'END of AcctLineType_383'
163345       ,p_level    => C_LEVEL_PROCEDURE
163346       ,p_module   => l_log_module);
163347 END IF;
163348 --
163349 EXCEPTION
163350   WHEN xla_exceptions_pkg.application_exception THEN
163351       RAISE;
163352   WHEN OTHERS THEN
163353        xla_exceptions_pkg.raise_message
163354            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_383');
163355 END AcctLineType_383;
163356 --
163357 
163358 ---------------------------------------
163359 --
163360 -- PRIVATE FUNCTION
163361 --         AcctLineType_384
163362 --
163363 ---------------------------------------
163364 PROCEDURE AcctLineType_384 (
163365   p_application_id        IN NUMBER
163366  ,p_event_id              IN NUMBER
163367  ,p_calculate_acctd_flag  IN VARCHAR2
163368  ,p_calculate_g_l_flag    IN VARCHAR2
163369  ,p_actual_flag           IN OUT VARCHAR2
163370  ,p_balance_type_code     OUT VARCHAR2
163371  ,p_gain_or_loss_ref      OUT VARCHAR2
163372  
163373 --Period Close Date
163374  , p_source_1            IN DATE
163375 --Generated Code Combination Identifier
163376  , p_source_3            IN NUMBER
163377 --Expense Account Code Combination Identifier
163378  , p_source_29            IN NUMBER
163379 --Adjustment Type
163380  , p_source_35            IN VARCHAR2
163381 --Transaction Header Identifier
163382  , p_source_36            IN NUMBER
163383 --Adjustment Line Identifier
163384  , p_source_37            IN NUMBER
163385 --Distribution Type Code
163386  , p_source_38            IN VARCHAR2
163387 --Entered Amount
163388  , p_source_39            IN NUMBER
163389 --Currency Code
163390  , p_source_40            IN VARCHAR2
163391 --Source Destination Code
163392  , p_source_42            IN VARCHAR2
163393 )
163394 IS
163395 
163396 l_component_type              VARCHAR2(80);
163397 l_component_code              VARCHAR2(30);
163398 l_component_type_code         VARCHAR2(1);
163399 l_component_appl_id           INTEGER;
163400 l_amb_context_code            VARCHAR2(30);
163401 l_entity_code                 VARCHAR2(30);
163402 l_event_class_code            VARCHAR2(30);
163403 l_ae_header_id                NUMBER;
163404 l_event_type_code             VARCHAR2(30);
163405 l_line_definition_code        VARCHAR2(30);
163406 l_line_definition_owner_code  VARCHAR2(1);
163407 --
163408 -- adr variables
163409 l_segment                     VARCHAR2(30);
163410 l_ccid                        NUMBER;
163411 l_adr_transaction_coa_id      NUMBER;
163412 l_adr_accounting_coa_id       NUMBER;
163413 l_adr_flexfield_segment_code  VARCHAR2(30);
163414 l_adr_flex_value_set_id       NUMBER;
163415 l_adr_value_type_code         VARCHAR2(30);
163416 l_adr_value_combination_id    NUMBER;
163417 l_adr_value_segment_code      VARCHAR2(30);
163418 
163419 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
163420 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
163421 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
163422 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
163423 
163424 -- 4262811 Variables ------------------------------------------------------------------------------------------
163425 l_entered_amt_idx             NUMBER;
163426 l_accted_amt_idx              NUMBER;
163427 l_acc_rev_flag                VARCHAR2(1);
163428 l_accrual_line_num            NUMBER;
163429 l_tmp_amt                     NUMBER;
163430 l_acc_rev_natural_side_code   VARCHAR2(1);
163431 
163432 l_num_entries                 NUMBER;
163433 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
163437 l_recog_line_1                NUMBER;
163434 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
163435 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
163436 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
163438 l_recog_line_2                NUMBER;
163439 
163440 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
163441 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
163442 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
163443 
163444 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
163445 
163446 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
163447 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
163448 
163449 ---------------------------------------------------------------------------------------------------------------
163450 
163451 
163452 --
163453 -- bulk performance
163454 --
163455 l_balance_type_code           VARCHAR2(1);
163456 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
163457 l_log_module                  VARCHAR2(240);
163458 
163459 --
163460 -- Upgrade strategy
163461 --
163462 l_actual_upg_option           VARCHAR2(1);
163463 l_enc_upg_option           VARCHAR2(1);
163464 
163465 --
163466 BEGIN
163467 --
163468 IF g_log_enabled THEN
163469       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_384';
163470 END IF;
163471 --
163472 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
163473 
163474       trace
163475          (p_msg      => 'BEGIN of AcctLineType_384'
163476          ,p_level    => C_LEVEL_PROCEDURE
163477          ,p_module   => l_log_module);
163478 
163479 END IF;
163480 --
163481 l_component_type             := 'AMB_JLT';
163482 l_component_code             := 'FA_TRANSFER_SOURCE_EXP_BAL';
163483 l_component_type_code        := 'S';
163484 l_component_appl_id          :=  140;
163485 l_amb_context_code           := 'DEFAULT';
163486 l_entity_code                := 'TRANSACTIONS';
163487 l_event_class_code           := 'TRANSFERS';
163488 l_event_type_code            := 'TRANSFERS_ALL';
163489 l_line_definition_owner_code := 'S';
163490 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
163491 --
163492 l_balance_type_code          := 'A';
163493 l_segment                     := NULL;
163494 l_ccid                        := NULL;
163495 l_adr_transaction_coa_id      := NULL;
163496 l_adr_accounting_coa_id       := NULL;
163497 l_adr_flexfield_segment_code  := NULL;
163498 l_adr_flex_value_set_id       := NULL;
163499 l_adr_value_type_code         := NULL;
163500 l_adr_value_combination_id    := NULL;
163501 l_adr_value_segment_code      := NULL;
163502 
163503 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
163504 l_bflow_class_code           := '';    -- 4219869 Business Flow
163505 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
163506 l_budgetary_control_flag     := 'N';
163507 
163508 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
163509 l_bflow_applied_to_amt       := NULL; -- 5132302
163510 l_entered_amt_idx            := NULL;          -- 4262811
163511 l_accted_amt_idx             := NULL;          -- 4262811
163512 l_acc_rev_flag               := NULL;          -- 4262811
163513 l_accrual_line_num           := NULL;          -- 4262811
163514 l_tmp_amt                    := NULL;          -- 4262811
163515 --
163516  
163517 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
163518     l_balance_type_code <> 'B' THEN
163519 IF NVL(p_source_35,'
163520 ') =  'BONUS EXPENSE' AND 
163521 NVL(p_source_42,'
163522 ') =  'SOURCE'
163523  THEN 
163524 
163525    --
163526    XLA_AE_LINES_PKG.SetNewLine;
163527 
163528    p_balance_type_code          := l_balance_type_code;
163529    -- set the flag so later we will know whether the gain loss line needs to be created
163530    
163531    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
163532      p_actual_flag :='A';
163533    END IF;
163534 
163535    --
163536    -- bulk performance
163537    --
163538    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
163539                                       p_header_num   => 0); -- 4262811
163540    --
163541    -- set accounting line options
163542    --
163543    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
163544            p_natural_side_code          => 'D'
163545          , p_gain_or_loss_flag          => 'N'
163546          , p_gl_transfer_mode_code      => 'S'
163547          , p_acct_entry_type_code       => 'A'
163548          , p_switch_side_flag           => 'Y'
163549          , p_merge_duplicate_code       => 'N'
163550          );
163551    --
163552    l_acc_rev_natural_side_code := 'C';  -- 4262811
163553    -- 
163554    --
163555    -- set accounting line type info
163556    --
163557    xla_ae_lines_pkg.SetAcctLineType
163558       (p_component_type             => l_component_type
163559       ,p_event_type_code            => l_event_type_code
163560       ,p_line_definition_owner_code => l_line_definition_owner_code
163561       ,p_line_definition_code       => l_line_definition_code
163562       ,p_accounting_line_code       => l_component_code
163563       ,p_accounting_line_type_code  => l_component_type_code
163564       ,p_accounting_line_appl_id    => l_component_appl_id
163565       ,p_amb_context_code           => l_amb_context_code
163566       ,p_entity_code                => l_entity_code
163567       ,p_event_class_code           => l_event_class_code);
163568    --
163569    -- set accounting class
163570    --
163571    xla_ae_lines_pkg.SetAcctClass(
163572            p_accounting_class_code  => 'EXPENSE'
163573          , p_ae_header_id           => l_ae_header_id
163574          );
163578    --
163575 
163576    --
163577    -- set rounding class
163579    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
163580                       'EXPENSE';
163581 
163582    --
163583    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
163584    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
163585    --
163586    -- bulk performance
163587    --
163588    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
163589 
163590    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
163591       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
163592 
163593    -- 4955764
163594    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
163595       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
163596 
163597    -- 4458381 Public Sector Enh
163598    
163599    --
163600    -- set accounting attributes for the line type
163601    --
163602    l_entered_amt_idx := 4;
163603    l_accted_amt_idx  := 6;
163604    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
163605    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
163606    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
163607    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
163608    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
163609    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
163610    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
163611    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
163612    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
163613    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
163614    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
163615    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
163616    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
163617 
163618    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
163619    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
163620 
163621    ---------------------------------------------------------------------------------------------------------------
163622    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
163623    ---------------------------------------------------------------------------------------------------------------
163624    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
163625 
163626    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
163627    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
163628 
163629    IF xla_accounting_cache_pkg.GetValueChar
163630          (p_source_code         => 'LEDGER_CATEGORY_CODE'
163631          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
163632    AND l_bflow_method_code = 'PRIOR_ENTRY'
163633 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
163634    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
163635          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
163636        )
163637    THEN
163638          xla_ae_lines_pkg.BflowUpgEntry
163639            (p_business_method_code    => l_bflow_method_code
163640            ,p_business_class_code     => l_bflow_class_code
163641            ,p_balance_type            => l_balance_type_code);
163642    ELSE
163643       NULL;
163644 -- No business flow processing for business flow method of NONE.
163645    END IF;
163646 
163647    --
163648    -- call analytical criteria
163649    --
163650    
163651    --
163652    -- call description
163653    --
163654    
163655 xla_ae_lines_pkg.SetLineDescription(
163656    p_ae_header_id => l_ae_header_id
163657   ,p_description  => Description_127 (
163658      p_application_id         => p_application_id
163659    , p_ae_header_id           => l_ae_header_id 
163660 , p_source_1 => p_source_1
163661    )
163662 );
163663 
163664 
163665    --
163666    -- call ADRs
163667    -- Bug 4922099
163668    --
163669    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
163670         (NVL(l_actual_upg_option, 'N') = 'O') OR
163671         (NVL(l_enc_upg_option, 'N') = 'O')
163672       )
163673    THEN
163674    NULL;
163675    --
163676    --
163677    
163678   l_ccid := AcctDerRule_175(
163679            p_application_id           => p_application_id
163680          , p_ae_header_id             => l_ae_header_id 
163681 , p_source_3 => p_source_3
163682 , p_source_29 => p_source_29
163683          , x_transaction_coa_id       => l_adr_transaction_coa_id
163684          , x_accounting_coa_id        => l_adr_accounting_coa_id
163685          , x_value_type_code          => l_adr_value_type_code
163686          , p_side                     => 'NA'
163687    );
163688 
163689    xla_ae_lines_pkg.set_ccid(
163690     p_code_combination_id          => l_ccid
163691   , p_value_type_code              => l_adr_value_type_code
163692   , p_transaction_coa_id           => l_adr_transaction_coa_id
163693   , p_accounting_coa_id            => l_adr_accounting_coa_id
163694   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
163695   , p_adr_type_code                => 'S'
163696   , p_component_type               => l_component_type
163697   , p_component_code               => l_component_code
163698   , p_component_type_code          => l_component_type_code
163699   , p_component_appl_id            => l_component_appl_id
163700   , p_amb_context_code             => l_amb_context_code
163701   , p_side                         => 'NA'
163702   );
163703 
163704 
163708    --
163705    --
163706    --
163707    END IF;
163709    -- Bug 4922099
163710    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
163711           (NVL(l_enc_upg_option, 'N') = 'O')
163712         ) AND
163713         (l_bflow_method_code = 'PRIOR_ENTRY')
163714       )
163715    THEN
163716       IF
163717       --
163718       1 = 2
163719       --
163720       THEN
163721       xla_accounting_err_pkg.build_message
163722                                     (p_appli_s_name            => 'XLA'
163723                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
163724                                     ,p_token_1                 => 'LINE_NUMBER'
163725                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
163726                                     ,p_token_2                 => 'LINE_TYPE_NAME'
163727                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
163728                                                                              l_component_type
163729                                                                             ,l_component_code
163730                                                                             ,l_component_type_code
163731                                                                             ,l_component_appl_id
163732                                                                             ,l_amb_context_code
163733                                                                             ,l_entity_code
163734                                                                             ,l_event_class_code
163735                                                                            )
163736                                     ,p_token_3                 => 'OWNER'
163737                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
163738                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
163739                                                                           ,p_lookup_code    => l_component_type_code
163740                                                                          )
163741                                     ,p_token_4                 => 'PRODUCT_NAME'
163742                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
163743                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
163744                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
163745                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
163746                                     ,p_ae_header_id            =>  NULL
163747                                        );
163748 
163749         IF (C_LEVEL_ERROR>= g_log_level) THEN
163750                  trace
163751                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
163752                       ,p_level    => C_LEVEL_ERROR
163753                       ,p_module   => l_log_module);
163754         END IF;
163755       END IF;
163756    END IF;
163757    --
163758    --
163759    ------------------------------------------------------------------------------------------------
163760    -- 4219869 Business Flow
163761    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
163762    -- Prior Entry.  Currently, the following code is always generated.
163763    ------------------------------------------------------------------------------------------------
163764    XLA_AE_LINES_PKG.ValidateCurrentLine;
163765 
163766    ------------------------------------------------------------------------------------
163767    -- 4219869 Business Flow
163768    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
163769    ------------------------------------------------------------------------------------
163770    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
163771 
163772    ----------------------------------------------------------------------------------
163773    -- 4219869 Business Flow
163774    -- Update journal entry status -- Need to generate this within IF <condition>
163775    ----------------------------------------------------------------------------------
163776    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
163777          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
163778          ,p_balance_type_code => l_balance_type_code
163779          );
163780 
163781    -------------------------------------------------------------------------------------------
163782    -- 4262811 - Generate the Accrual Reversal lines
163783    -------------------------------------------------------------------------------------------
163784    BEGIN
163785       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
163786                               (g_array_event(p_event_id).array_value_num('header_index'));
163787       IF l_acc_rev_flag IS NULL THEN
163788          l_acc_rev_flag := 'N';
163789       END IF;
163790    EXCEPTION
163791       WHEN OTHERS THEN
163792          l_acc_rev_flag := 'N';
163793    END;
163794    --
163795    IF (l_acc_rev_flag = 'Y') THEN
163796 
163797        -- 4645092  ------------------------------------------------------------------------------
163798        -- To allow MPA report to determine if it should generate report process
163799        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
163800        ------------------------------------------------------------------------------------------
163801 
163802        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
163803        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
163804    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
163805    -- call ADRs
163806    -- Bug 4922099
163807    --
163808    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
163809         (NVL(l_actual_upg_option, 'N') = 'O') OR
163813    NULL;
163810         (NVL(l_enc_upg_option, 'N') = 'O')
163811       )
163812    THEN
163814    --
163815    --
163816    
163817   l_ccid := AcctDerRule_175(
163818            p_application_id           => p_application_id
163819          , p_ae_header_id             => l_ae_header_id 
163820 , p_source_3 => p_source_3
163821 , p_source_29 => p_source_29
163822          , x_transaction_coa_id       => l_adr_transaction_coa_id
163823          , x_accounting_coa_id        => l_adr_accounting_coa_id
163824          , x_value_type_code          => l_adr_value_type_code
163825          , p_side                     => 'NA'
163826    );
163827 
163828    xla_ae_lines_pkg.set_ccid(
163829     p_code_combination_id          => l_ccid
163830   , p_value_type_code              => l_adr_value_type_code
163831   , p_transaction_coa_id           => l_adr_transaction_coa_id
163832   , p_accounting_coa_id            => l_adr_accounting_coa_id
163833   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
163834   , p_adr_type_code                => 'S'
163835   , p_component_type               => l_component_type
163836   , p_component_code               => l_component_code
163837   , p_component_type_code          => l_component_type_code
163838   , p_component_appl_id            => l_component_appl_id
163839   , p_amb_context_code             => l_amb_context_code
163840   , p_side                         => 'NA'
163841   );
163842 
163843 
163844    --
163845    --
163846    END IF;
163847 
163848        --
163849        -- Update the line information that should be overwritten
163850        --
163851        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
163852                                          p_header_num   => 1);
163853        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
163854 
163855        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
163856 
163857        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
163858           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
163859        END IF;
163860 
163861       --
163862       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
163863       --
163864       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
163865           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
163866       ELSE
163867           ---------------------------------------------------------------------------------------------------
163868           -- 4262811a Switch Sign
163869           ---------------------------------------------------------------------------------------------------
163870           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
163871           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
163872                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
163873           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
163874                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
163875           -- 5132302
163876           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
163877                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
163878 
163879       END IF;
163880 
163881       -- 4955764
163882       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
163883       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
163884 
163885 
163886       XLA_AE_LINES_PKG.ValidateCurrentLine;
163887       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
163888 
163889       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
163890                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
163891                ,p_balance_type_code => l_balance_type_code);
163892 
163893    END IF;
163894 
163895    -----------------------------------------------------------------------------------------
163896    -- 4262811 Multiperiod Accounting
163897    -----------------------------------------------------------------------------------------
163898      -- No MPA option is assigned.
163899 
163900 
163901 END IF;
163902 END IF;
163903 --
163904 
163905 --
163906 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
163907    trace
163908       (p_msg      => 'END of AcctLineType_384'
163909       ,p_level    => C_LEVEL_PROCEDURE
163910       ,p_module   => l_log_module);
163911 END IF;
163912 --
163913 EXCEPTION
163914   WHEN xla_exceptions_pkg.application_exception THEN
163915       RAISE;
163916   WHEN OTHERS THEN
163917        xla_exceptions_pkg.raise_message
163918            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_384');
163919 END AcctLineType_384;
163920 --
163921 
163922 ---------------------------------------
163923 --
163924 -- PRIVATE FUNCTION
163925 --         AcctLineType_385
163926 --
163927 ---------------------------------------
163928 PROCEDURE AcctLineType_385 (
163929   p_application_id        IN NUMBER
163930  ,p_event_id              IN NUMBER
163931  ,p_calculate_acctd_flag  IN VARCHAR2
163932  ,p_calculate_g_l_flag    IN VARCHAR2
163933  ,p_actual_flag           IN OUT VARCHAR2
163934  ,p_balance_type_code     OUT VARCHAR2
163935  ,p_gain_or_loss_ref      OUT VARCHAR2
163936  
163937 --Period Close Date
163938  , p_source_1            IN DATE
163939 --Generated Code Combination Identifier
163940  , p_source_3            IN NUMBER
163941 --Depreciation Reserve Account
163942  , p_source_10            IN VARCHAR2
163946  , p_source_29            IN NUMBER
163943 --Generated Offset Code Combination Identifier
163944  , p_source_17            IN NUMBER
163945 --Expense Account Code Combination Identifier
163947 --Default Code Combination Identifier
163948  , p_source_30            IN NUMBER
163949 --Adjustment Type
163950  , p_source_35            IN VARCHAR2
163951 --Transaction Header Identifier
163952  , p_source_36            IN NUMBER
163953 --Adjustment Line Identifier
163954  , p_source_37            IN NUMBER
163955 --Distribution Type Code
163956  , p_source_38            IN VARCHAR2
163957 --Entered Amount
163958  , p_source_39            IN NUMBER
163959 --Currency Code
163960  , p_source_40            IN VARCHAR2
163961 --Source Destination Code
163962  , p_source_42            IN VARCHAR2
163963 )
163964 IS
163965 
163966 l_component_type              VARCHAR2(80);
163967 l_component_code              VARCHAR2(30);
163968 l_component_type_code         VARCHAR2(1);
163969 l_component_appl_id           INTEGER;
163970 l_amb_context_code            VARCHAR2(30);
163971 l_entity_code                 VARCHAR2(30);
163972 l_event_class_code            VARCHAR2(30);
163973 l_ae_header_id                NUMBER;
163974 l_event_type_code             VARCHAR2(30);
163975 l_line_definition_code        VARCHAR2(30);
163976 l_line_definition_owner_code  VARCHAR2(1);
163977 --
163978 -- adr variables
163979 l_segment                     VARCHAR2(30);
163980 l_ccid                        NUMBER;
163981 l_adr_transaction_coa_id      NUMBER;
163982 l_adr_accounting_coa_id       NUMBER;
163983 l_adr_flexfield_segment_code  VARCHAR2(30);
163984 l_adr_flex_value_set_id       NUMBER;
163985 l_adr_value_type_code         VARCHAR2(30);
163986 l_adr_value_combination_id    NUMBER;
163987 l_adr_value_segment_code      VARCHAR2(30);
163988 
163989 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
163990 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
163991 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
163992 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
163993 
163994 -- 4262811 Variables ------------------------------------------------------------------------------------------
163995 l_entered_amt_idx             NUMBER;
163996 l_accted_amt_idx              NUMBER;
163997 l_acc_rev_flag                VARCHAR2(1);
163998 l_accrual_line_num            NUMBER;
163999 l_tmp_amt                     NUMBER;
164000 l_acc_rev_natural_side_code   VARCHAR2(1);
164001 
164002 l_num_entries                 NUMBER;
164003 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
164004 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
164005 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
164006 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
164007 l_recog_line_1                NUMBER;
164008 l_recog_line_2                NUMBER;
164009 
164010 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
164011 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
164012 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
164013 
164014 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
164015 
164016 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
164017 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
164018 
164019 ---------------------------------------------------------------------------------------------------------------
164020 
164021 
164022 --
164023 -- bulk performance
164024 --
164025 l_balance_type_code           VARCHAR2(1);
164026 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
164027 l_log_module                  VARCHAR2(240);
164028 
164029 --
164030 -- Upgrade strategy
164031 --
164032 l_actual_upg_option           VARCHAR2(1);
164033 l_enc_upg_option           VARCHAR2(1);
164034 
164035 --
164036 BEGIN
164037 --
164038 IF g_log_enabled THEN
164039       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_385';
164040 END IF;
164041 --
164042 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
164043 
164044       trace
164045          (p_msg      => 'BEGIN of AcctLineType_385'
164046          ,p_level    => C_LEVEL_PROCEDURE
164047          ,p_module   => l_log_module);
164048 
164049 END IF;
164050 --
164051 l_component_type             := 'AMB_JLT';
164052 l_component_code             := 'FA_TRANSFER_SOURCE_RESERVE_BAL';
164053 l_component_type_code        := 'S';
164054 l_component_appl_id          :=  140;
164055 l_amb_context_code           := 'DEFAULT';
164056 l_entity_code                := 'TRANSACTIONS';
164057 l_event_class_code           := 'TRANSFERS';
164058 l_event_type_code            := 'TRANSFERS_ALL';
164059 l_line_definition_owner_code := 'S';
164060 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
164061 --
164062 l_balance_type_code          := 'A';
164063 l_segment                     := NULL;
164064 l_ccid                        := NULL;
164065 l_adr_transaction_coa_id      := NULL;
164066 l_adr_accounting_coa_id       := NULL;
164067 l_adr_flexfield_segment_code  := NULL;
164068 l_adr_flex_value_set_id       := NULL;
164069 l_adr_value_type_code         := NULL;
164070 l_adr_value_combination_id    := NULL;
164071 l_adr_value_segment_code      := NULL;
164072 
164073 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
164074 l_bflow_class_code           := '';    -- 4219869 Business Flow
164075 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
164076 l_budgetary_control_flag     := 'N';
164077 
164078 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
164079 l_bflow_applied_to_amt       := NULL; -- 5132302
164080 l_entered_amt_idx            := NULL;          -- 4262811
164084 l_tmp_amt                    := NULL;          -- 4262811
164081 l_accted_amt_idx             := NULL;          -- 4262811
164082 l_acc_rev_flag               := NULL;          -- 4262811
164083 l_accrual_line_num           := NULL;          -- 4262811
164085 --
164086  
164087 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
164088     l_balance_type_code <> 'B' THEN
164089 IF (NVL(p_source_35,'
164090 ') =  'BONUS RESERVE' OR 
164091 NVL(p_source_35,'
164092 ') =  'BONUS EXPENSE') AND 
164093 NVL(p_source_42,'
164094 ') =  'SOURCE'
164095  THEN 
164096 
164097    --
164098    XLA_AE_LINES_PKG.SetNewLine;
164099 
164100    p_balance_type_code          := l_balance_type_code;
164101    -- set the flag so later we will know whether the gain loss line needs to be created
164102    
164103    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
164104      p_actual_flag :='A';
164105    END IF;
164106 
164107    --
164108    -- bulk performance
164109    --
164110    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
164111                                       p_header_num   => 0); -- 4262811
164112    --
164113    -- set accounting line options
164114    --
164115    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
164116            p_natural_side_code          => 'C'
164117          , p_gain_or_loss_flag          => 'N'
164118          , p_gl_transfer_mode_code      => 'S'
164119          , p_acct_entry_type_code       => 'A'
164120          , p_switch_side_flag           => 'Y'
164121          , p_merge_duplicate_code       => 'N'
164122          );
164123    --
164124    l_acc_rev_natural_side_code := 'D';  -- 4262811
164125    -- 
164126    --
164127    -- set accounting line type info
164128    --
164129    xla_ae_lines_pkg.SetAcctLineType
164130       (p_component_type             => l_component_type
164131       ,p_event_type_code            => l_event_type_code
164132       ,p_line_definition_owner_code => l_line_definition_owner_code
164133       ,p_line_definition_code       => l_line_definition_code
164134       ,p_accounting_line_code       => l_component_code
164135       ,p_accounting_line_type_code  => l_component_type_code
164136       ,p_accounting_line_appl_id    => l_component_appl_id
164137       ,p_amb_context_code           => l_amb_context_code
164138       ,p_entity_code                => l_entity_code
164139       ,p_event_class_code           => l_event_class_code);
164140    --
164141    -- set accounting class
164142    --
164143    xla_ae_lines_pkg.SetAcctClass(
164144            p_accounting_class_code  => 'ASSET'
164145          , p_ae_header_id           => l_ae_header_id
164146          );
164147 
164148    --
164149    -- set rounding class
164150    --
164151    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
164152                       'ASSET';
164153 
164154    --
164155    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
164156    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
164157    --
164158    -- bulk performance
164159    --
164160    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
164161 
164162    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
164163       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
164164 
164165    -- 4955764
164166    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
164167       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
164168 
164169    -- 4458381 Public Sector Enh
164170    
164171    --
164172    -- set accounting attributes for the line type
164173    --
164174    l_entered_amt_idx := 4;
164175    l_accted_amt_idx  := 6;
164176    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
164177    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
164178    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
164179    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
164180    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
164181    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
164182    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
164183    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
164184    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
164185    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
164186    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
164187    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
164188    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
164189 
164190    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
164191    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
164192 
164193    ---------------------------------------------------------------------------------------------------------------
164194    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
164195    ---------------------------------------------------------------------------------------------------------------
164196    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
164197 
164198    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
164199    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
164200 
164201    IF xla_accounting_cache_pkg.GetValueChar
164202          (p_source_code         => 'LEDGER_CATEGORY_CODE'
164203          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
164204    AND l_bflow_method_code = 'PRIOR_ENTRY'
164208        )
164205 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
164206    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
164207          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
164209    THEN
164210          xla_ae_lines_pkg.BflowUpgEntry
164211            (p_business_method_code    => l_bflow_method_code
164212            ,p_business_class_code     => l_bflow_class_code
164213            ,p_balance_type            => l_balance_type_code);
164214    ELSE
164215       NULL;
164216 -- No business flow processing for business flow method of NONE.
164217    END IF;
164218 
164219    --
164220    -- call analytical criteria
164221    --
164222    
164223    --
164224    -- call description
164225    --
164226    
164227 xla_ae_lines_pkg.SetLineDescription(
164228    p_ae_header_id => l_ae_header_id
164229   ,p_description  => Description_130 (
164230      p_application_id         => p_application_id
164231    , p_ae_header_id           => l_ae_header_id 
164232 , p_source_1 => p_source_1
164233    )
164234 );
164235 
164236 
164237    --
164238    -- call ADRs
164239    -- Bug 4922099
164240    --
164241    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
164242         (NVL(l_actual_upg_option, 'N') = 'O') OR
164243         (NVL(l_enc_upg_option, 'N') = 'O')
164244       )
164245    THEN
164246    NULL;
164247    --
164248    --
164249    
164250   l_ccid := AcctDerRule_174(
164251            p_application_id           => p_application_id
164252          , p_ae_header_id             => l_ae_header_id 
164253 , p_source_3 => p_source_3
164254 , p_source_17 => p_source_17
164255 , p_source_30 => p_source_30
164256          , x_transaction_coa_id       => l_adr_transaction_coa_id
164257          , x_accounting_coa_id        => l_adr_accounting_coa_id
164258          , x_value_type_code          => l_adr_value_type_code
164259          , p_side                     => 'NA'
164260    );
164261 
164262    xla_ae_lines_pkg.set_ccid(
164263     p_code_combination_id          => l_ccid
164264   , p_value_type_code              => l_adr_value_type_code
164265   , p_transaction_coa_id           => l_adr_transaction_coa_id
164266   , p_accounting_coa_id            => l_adr_accounting_coa_id
164267   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
164268   , p_adr_type_code                => 'S'
164269   , p_component_type               => l_component_type
164270   , p_component_code               => l_component_code
164271   , p_component_type_code          => l_component_type_code
164272   , p_component_appl_id            => l_component_appl_id
164273   , p_amb_context_code             => l_amb_context_code
164274   , p_side                         => 'NA'
164275   );
164276 
164277 
164278    l_segment := AcctDerRule_149(
164279            p_application_id           => p_application_id
164280          , p_ae_header_id             => l_ae_header_id 
164281 , p_source_3 => p_source_3
164282 , p_source_10 => p_source_10
164283          , x_transaction_coa_id       => l_adr_transaction_coa_id
164284          , x_accounting_coa_id        => l_adr_accounting_coa_id
164285          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
164286          , x_flex_value_set_id        => l_adr_flex_value_set_id
164287          , x_value_type_code          => l_adr_value_type_code
164288          , x_value_combination_id     => l_adr_value_combination_id
164289          , x_value_segment_code       => l_adr_value_segment_code
164290          , p_side                     => 'NA'
164291          , p_override_seg_flag        => 'Y'
164292    );
164293 
164294    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
164295 
164296       xla_ae_lines_pkg.set_segment(
164297           p_to_segment_code         => 'GL_ACCOUNT'
164298         , p_segment_value           => l_segment
164299         , p_from_segment_code       => l_adr_value_segment_code
164300         , p_from_combination_id     => l_adr_value_combination_id
164301         , p_value_type_code         => l_adr_value_type_code
164302         , p_transaction_coa_id      => l_adr_transaction_coa_id
164303         , p_accounting_coa_id       => l_adr_accounting_coa_id
164304         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
164305         , p_flex_value_set_id       => l_adr_flex_value_set_id
164306         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
164307         , p_adr_type_code           => 'S'
164308         , p_component_type          => l_component_type
164309         , p_component_code          => l_component_code
164310         , p_component_type_code     => l_component_type_code
164311         , p_component_appl_id       => l_component_appl_id
164312         , p_amb_context_code        => l_amb_context_code
164313         , p_entity_code             => 'TRANSACTIONS'
164314         , p_event_class_code        => 'TRANSFERS'
164315         , p_side                    => 'NA'
164316         );
164317 
164318   END IF;
164319 
164320    l_segment := AcctDerRule_168(
164321            p_application_id           => p_application_id
164322          , p_ae_header_id             => l_ae_header_id 
164323 , p_source_3 => p_source_3
164324 , p_source_29 => p_source_29
164325          , x_transaction_coa_id       => l_adr_transaction_coa_id
164326          , x_accounting_coa_id        => l_adr_accounting_coa_id
164327          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
164328          , x_flex_value_set_id        => l_adr_flex_value_set_id
164329          , x_value_type_code          => l_adr_value_type_code
164330          , x_value_combination_id     => l_adr_value_combination_id
164331          , x_value_segment_code       => l_adr_value_segment_code
164332          , p_side                     => 'NA'
164333          , p_override_seg_flag        => 'Y'
164334    );
164335 
164336    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
164337 
164338       xla_ae_lines_pkg.set_segment(
164342         , p_from_combination_id     => l_adr_value_combination_id
164339           p_to_segment_code         => 'GL_BALANCING'
164340         , p_segment_value           => l_segment
164341         , p_from_segment_code       => l_adr_value_segment_code
164343         , p_value_type_code         => l_adr_value_type_code
164344         , p_transaction_coa_id      => l_adr_transaction_coa_id
164345         , p_accounting_coa_id       => l_adr_accounting_coa_id
164346         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
164347         , p_flex_value_set_id       => l_adr_flex_value_set_id
164348         , p_adr_code                => 'FA_EXPENSE_ACCT'
164349         , p_adr_type_code           => 'S'
164350         , p_component_type          => l_component_type
164351         , p_component_code          => l_component_code
164352         , p_component_type_code     => l_component_type_code
164353         , p_component_appl_id       => l_component_appl_id
164354         , p_amb_context_code        => l_amb_context_code
164355         , p_entity_code             => 'TRANSACTIONS'
164356         , p_event_class_code        => 'TRANSFERS'
164357         , p_side                    => 'NA'
164358         );
164359 
164360   END IF;
164361 
164362    --
164363    --
164364    END IF;
164365    --
164366    -- Bug 4922099
164367    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
164368           (NVL(l_enc_upg_option, 'N') = 'O')
164369         ) AND
164370         (l_bflow_method_code = 'PRIOR_ENTRY')
164371       )
164372    THEN
164373       IF
164374       --
164375       1 = 2
164376       --
164377       THEN
164378       xla_accounting_err_pkg.build_message
164379                                     (p_appli_s_name            => 'XLA'
164380                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
164381                                     ,p_token_1                 => 'LINE_NUMBER'
164382                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
164383                                     ,p_token_2                 => 'LINE_TYPE_NAME'
164384                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
164385                                                                              l_component_type
164386                                                                             ,l_component_code
164387                                                                             ,l_component_type_code
164388                                                                             ,l_component_appl_id
164389                                                                             ,l_amb_context_code
164390                                                                             ,l_entity_code
164391                                                                             ,l_event_class_code
164392                                                                            )
164393                                     ,p_token_3                 => 'OWNER'
164394                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
164395                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
164396                                                                           ,p_lookup_code    => l_component_type_code
164397                                                                          )
164398                                     ,p_token_4                 => 'PRODUCT_NAME'
164399                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
164400                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
164401                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
164402                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
164403                                     ,p_ae_header_id            =>  NULL
164404                                        );
164405 
164406         IF (C_LEVEL_ERROR>= g_log_level) THEN
164407                  trace
164408                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
164409                       ,p_level    => C_LEVEL_ERROR
164410                       ,p_module   => l_log_module);
164411         END IF;
164412       END IF;
164413    END IF;
164414    --
164415    --
164416    ------------------------------------------------------------------------------------------------
164417    -- 4219869 Business Flow
164418    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
164419    -- Prior Entry.  Currently, the following code is always generated.
164420    ------------------------------------------------------------------------------------------------
164421    XLA_AE_LINES_PKG.ValidateCurrentLine;
164422 
164423    ------------------------------------------------------------------------------------
164424    -- 4219869 Business Flow
164425    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
164426    ------------------------------------------------------------------------------------
164427    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
164428 
164429    ----------------------------------------------------------------------------------
164430    -- 4219869 Business Flow
164431    -- Update journal entry status -- Need to generate this within IF <condition>
164432    ----------------------------------------------------------------------------------
164433    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
164434          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
164435          ,p_balance_type_code => l_balance_type_code
164436          );
164437 
164438    -------------------------------------------------------------------------------------------
164439    -- 4262811 - Generate the Accrual Reversal lines
164440    -------------------------------------------------------------------------------------------
164444       IF l_acc_rev_flag IS NULL THEN
164441    BEGIN
164442       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
164443                               (g_array_event(p_event_id).array_value_num('header_index'));
164445          l_acc_rev_flag := 'N';
164446       END IF;
164447    EXCEPTION
164448       WHEN OTHERS THEN
164449          l_acc_rev_flag := 'N';
164450    END;
164451    --
164452    IF (l_acc_rev_flag = 'Y') THEN
164453 
164454        -- 4645092  ------------------------------------------------------------------------------
164455        -- To allow MPA report to determine if it should generate report process
164456        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
164457        ------------------------------------------------------------------------------------------
164458 
164459        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
164460        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
164461    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
164462    -- call ADRs
164463    -- Bug 4922099
164464    --
164465    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
164466         (NVL(l_actual_upg_option, 'N') = 'O') OR
164467         (NVL(l_enc_upg_option, 'N') = 'O')
164468       )
164469    THEN
164470    NULL;
164471    --
164472    --
164473    
164474   l_ccid := AcctDerRule_174(
164475            p_application_id           => p_application_id
164476          , p_ae_header_id             => l_ae_header_id 
164477 , p_source_3 => p_source_3
164478 , p_source_17 => p_source_17
164479 , p_source_30 => p_source_30
164480          , x_transaction_coa_id       => l_adr_transaction_coa_id
164481          , x_accounting_coa_id        => l_adr_accounting_coa_id
164482          , x_value_type_code          => l_adr_value_type_code
164483          , p_side                     => 'NA'
164484    );
164485 
164486    xla_ae_lines_pkg.set_ccid(
164487     p_code_combination_id          => l_ccid
164488   , p_value_type_code              => l_adr_value_type_code
164489   , p_transaction_coa_id           => l_adr_transaction_coa_id
164490   , p_accounting_coa_id            => l_adr_accounting_coa_id
164491   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
164492   , p_adr_type_code                => 'S'
164493   , p_component_type               => l_component_type
164494   , p_component_code               => l_component_code
164495   , p_component_type_code          => l_component_type_code
164496   , p_component_appl_id            => l_component_appl_id
164497   , p_amb_context_code             => l_amb_context_code
164498   , p_side                         => 'NA'
164499   );
164500 
164501 
164502    l_segment := AcctDerRule_149(
164503            p_application_id           => p_application_id
164504          , p_ae_header_id             => l_ae_header_id 
164505 , p_source_3 => p_source_3
164506 , p_source_10 => p_source_10
164507          , x_transaction_coa_id       => l_adr_transaction_coa_id
164508          , x_accounting_coa_id        => l_adr_accounting_coa_id
164509          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
164510          , x_flex_value_set_id        => l_adr_flex_value_set_id
164511          , x_value_type_code          => l_adr_value_type_code
164512          , x_value_combination_id     => l_adr_value_combination_id
164513          , x_value_segment_code       => l_adr_value_segment_code
164514          , p_side                     => 'NA'
164515          , p_override_seg_flag        => 'Y'
164516    );
164517 
164518    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
164519 
164520       xla_ae_lines_pkg.set_segment(
164521           p_to_segment_code         => 'GL_ACCOUNT'
164522         , p_segment_value           => l_segment
164523         , p_from_segment_code       => l_adr_value_segment_code
164524         , p_from_combination_id     => l_adr_value_combination_id
164525         , p_value_type_code         => l_adr_value_type_code
164526         , p_transaction_coa_id      => l_adr_transaction_coa_id
164527         , p_accounting_coa_id       => l_adr_accounting_coa_id
164528         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
164529         , p_flex_value_set_id       => l_adr_flex_value_set_id
164530         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
164531         , p_adr_type_code           => 'S'
164532         , p_component_type          => l_component_type
164533         , p_component_code          => l_component_code
164534         , p_component_type_code     => l_component_type_code
164535         , p_component_appl_id       => l_component_appl_id
164536         , p_amb_context_code        => l_amb_context_code
164537         , p_entity_code             => 'TRANSACTIONS'
164538         , p_event_class_code        => 'TRANSFERS'
164539         , p_side                    => 'NA'
164540         );
164541 
164542   END IF;
164543 
164544    l_segment := AcctDerRule_168(
164545            p_application_id           => p_application_id
164546          , p_ae_header_id             => l_ae_header_id 
164547 , p_source_3 => p_source_3
164548 , p_source_29 => p_source_29
164549          , x_transaction_coa_id       => l_adr_transaction_coa_id
164550          , x_accounting_coa_id        => l_adr_accounting_coa_id
164551          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
164552          , x_flex_value_set_id        => l_adr_flex_value_set_id
164553          , x_value_type_code          => l_adr_value_type_code
164554          , x_value_combination_id     => l_adr_value_combination_id
164555          , x_value_segment_code       => l_adr_value_segment_code
164556          , p_side                     => 'NA'
164557          , p_override_seg_flag        => 'Y'
164558    );
164559 
164560    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
164561 
164562       xla_ae_lines_pkg.set_segment(
164563           p_to_segment_code         => 'GL_BALANCING'
164564         , p_segment_value           => l_segment
164568         , p_transaction_coa_id      => l_adr_transaction_coa_id
164565         , p_from_segment_code       => l_adr_value_segment_code
164566         , p_from_combination_id     => l_adr_value_combination_id
164567         , p_value_type_code         => l_adr_value_type_code
164569         , p_accounting_coa_id       => l_adr_accounting_coa_id
164570         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
164571         , p_flex_value_set_id       => l_adr_flex_value_set_id
164572         , p_adr_code                => 'FA_EXPENSE_ACCT'
164573         , p_adr_type_code           => 'S'
164574         , p_component_type          => l_component_type
164575         , p_component_code          => l_component_code
164576         , p_component_type_code     => l_component_type_code
164577         , p_component_appl_id       => l_component_appl_id
164578         , p_amb_context_code        => l_amb_context_code
164579         , p_entity_code             => 'TRANSACTIONS'
164580         , p_event_class_code        => 'TRANSFERS'
164581         , p_side                    => 'NA'
164582         );
164583 
164584   END IF;
164585 
164586    --
164587    --
164588    END IF;
164589 
164590        --
164591        -- Update the line information that should be overwritten
164592        --
164593        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
164594                                          p_header_num   => 1);
164595        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
164596 
164597        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
164598 
164599        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
164600           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
164601        END IF;
164602 
164603       --
164604       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
164605       --
164606       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
164607           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
164608       ELSE
164609           ---------------------------------------------------------------------------------------------------
164610           -- 4262811a Switch Sign
164611           ---------------------------------------------------------------------------------------------------
164612           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
164613           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
164614                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
164615           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
164616                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
164617           -- 5132302
164618           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
164619                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
164620 
164621       END IF;
164622 
164623       -- 4955764
164624       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
164625       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
164626 
164627 
164628       XLA_AE_LINES_PKG.ValidateCurrentLine;
164629       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
164630 
164631       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
164632                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
164633                ,p_balance_type_code => l_balance_type_code);
164634 
164635    END IF;
164636 
164637    -----------------------------------------------------------------------------------------
164638    -- 4262811 Multiperiod Accounting
164639    -----------------------------------------------------------------------------------------
164640      -- No MPA option is assigned.
164641 
164642 
164643 END IF;
164644 END IF;
164645 --
164646 
164647 --
164648 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
164649    trace
164650       (p_msg      => 'END of AcctLineType_385'
164651       ,p_level    => C_LEVEL_PROCEDURE
164652       ,p_module   => l_log_module);
164653 END IF;
164654 --
164655 EXCEPTION
164656   WHEN xla_exceptions_pkg.application_exception THEN
164657       RAISE;
164658   WHEN OTHERS THEN
164659        xla_exceptions_pkg.raise_message
164660            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_385');
164661 END AcctLineType_385;
164662 --
164663 
164664 ---------------------------------------
164665 --
164666 -- PRIVATE FUNCTION
164667 --         AcctLineType_386
164668 --
164669 ---------------------------------------
164670 PROCEDURE AcctLineType_386 (
164671   p_application_id        IN NUMBER
164672  ,p_event_id              IN NUMBER
164673  ,p_calculate_acctd_flag  IN VARCHAR2
164674  ,p_calculate_g_l_flag    IN VARCHAR2
164675  ,p_actual_flag           IN OUT VARCHAR2
164676  ,p_balance_type_code     OUT VARCHAR2
164677  ,p_gain_or_loss_ref      OUT VARCHAR2
164678  
164679 --Period Close Date
164680  , p_source_1            IN DATE
164681 --Generated Code Combination Identifier
164682  , p_source_3            IN NUMBER
164683 --Revaluation Reserve Account
164684  , p_source_11            IN VARCHAR2
164685 --Generated Offset Code Combination Identifier
164686  , p_source_17            IN NUMBER
164687 --Expense Account Code Combination Identifier
164688  , p_source_29            IN NUMBER
164689 --Default Code Combination Identifier
164690  , p_source_30            IN NUMBER
164691 --Adjustment Type
164692  , p_source_35            IN VARCHAR2
164696  , p_source_37            IN NUMBER
164693 --Transaction Header Identifier
164694  , p_source_36            IN NUMBER
164695 --Adjustment Line Identifier
164697 --Distribution Type Code
164698  , p_source_38            IN VARCHAR2
164699 --Entered Amount
164700  , p_source_39            IN NUMBER
164701 --Currency Code
164702  , p_source_40            IN VARCHAR2
164703 --Source Destination Code
164704  , p_source_42            IN VARCHAR2
164705 )
164706 IS
164707 
164708 l_component_type              VARCHAR2(80);
164709 l_component_code              VARCHAR2(30);
164710 l_component_type_code         VARCHAR2(1);
164711 l_component_appl_id           INTEGER;
164712 l_amb_context_code            VARCHAR2(30);
164713 l_entity_code                 VARCHAR2(30);
164714 l_event_class_code            VARCHAR2(30);
164715 l_ae_header_id                NUMBER;
164716 l_event_type_code             VARCHAR2(30);
164717 l_line_definition_code        VARCHAR2(30);
164718 l_line_definition_owner_code  VARCHAR2(1);
164719 --
164720 -- adr variables
164721 l_segment                     VARCHAR2(30);
164722 l_ccid                        NUMBER;
164723 l_adr_transaction_coa_id      NUMBER;
164724 l_adr_accounting_coa_id       NUMBER;
164725 l_adr_flexfield_segment_code  VARCHAR2(30);
164726 l_adr_flex_value_set_id       NUMBER;
164727 l_adr_value_type_code         VARCHAR2(30);
164728 l_adr_value_combination_id    NUMBER;
164729 l_adr_value_segment_code      VARCHAR2(30);
164730 
164731 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
164732 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
164733 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
164734 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
164735 
164736 -- 4262811 Variables ------------------------------------------------------------------------------------------
164737 l_entered_amt_idx             NUMBER;
164738 l_accted_amt_idx              NUMBER;
164739 l_acc_rev_flag                VARCHAR2(1);
164740 l_accrual_line_num            NUMBER;
164741 l_tmp_amt                     NUMBER;
164742 l_acc_rev_natural_side_code   VARCHAR2(1);
164743 
164744 l_num_entries                 NUMBER;
164745 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
164746 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
164747 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
164748 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
164749 l_recog_line_1                NUMBER;
164750 l_recog_line_2                NUMBER;
164751 
164752 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
164753 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
164754 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
164755 
164756 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
164757 
164758 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
164759 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
164760 
164761 ---------------------------------------------------------------------------------------------------------------
164762 
164763 
164764 --
164765 -- bulk performance
164766 --
164767 l_balance_type_code           VARCHAR2(1);
164768 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
164769 l_log_module                  VARCHAR2(240);
164770 
164771 --
164772 -- Upgrade strategy
164773 --
164774 l_actual_upg_option           VARCHAR2(1);
164775 l_enc_upg_option           VARCHAR2(1);
164776 
164777 --
164778 BEGIN
164779 --
164780 IF g_log_enabled THEN
164781       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_386';
164782 END IF;
164783 --
164784 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
164785 
164786       trace
164787          (p_msg      => 'BEGIN of AcctLineType_386'
164788          ,p_level    => C_LEVEL_PROCEDURE
164789          ,p_module   => l_log_module);
164790 
164791 END IF;
164792 --
164793 l_component_type             := 'AMB_JLT';
164794 l_component_code             := 'FA_TRANSFER_SOURCE_REVAL_RES';
164795 l_component_type_code        := 'S';
164796 l_component_appl_id          :=  140;
164797 l_amb_context_code           := 'DEFAULT';
164798 l_entity_code                := 'TRANSACTIONS';
164799 l_event_class_code           := 'TRANSFERS';
164800 l_event_type_code            := 'TRANSFERS_ALL';
164801 l_line_definition_owner_code := 'S';
164802 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_TRANS25';
164803 --
164804 l_balance_type_code          := 'A';
164805 l_segment                     := NULL;
164806 l_ccid                        := NULL;
164807 l_adr_transaction_coa_id      := NULL;
164808 l_adr_accounting_coa_id       := NULL;
164809 l_adr_flexfield_segment_code  := NULL;
164810 l_adr_flex_value_set_id       := NULL;
164811 l_adr_value_type_code         := NULL;
164812 l_adr_value_combination_id    := NULL;
164813 l_adr_value_segment_code      := NULL;
164814 
164815 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
164816 l_bflow_class_code           := '';    -- 4219869 Business Flow
164817 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
164818 l_budgetary_control_flag     := 'N';
164819 
164820 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
164821 l_bflow_applied_to_amt       := NULL; -- 5132302
164822 l_entered_amt_idx            := NULL;          -- 4262811
164823 l_accted_amt_idx             := NULL;          -- 4262811
164824 l_acc_rev_flag               := NULL;          -- 4262811
164825 l_accrual_line_num           := NULL;          -- 4262811
164826 l_tmp_amt                    := NULL;          -- 4262811
164827 --
164828  
164829 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
164833 NVL(p_source_42,'
164830     l_balance_type_code <> 'B' THEN
164831 IF NVL(p_source_35,'
164832 ') =  'REVAL RESERVE' AND 
164834 ') =  'SOURCE'
164835  THEN 
164836 
164837    --
164838    XLA_AE_LINES_PKG.SetNewLine;
164839 
164840    p_balance_type_code          := l_balance_type_code;
164841    -- set the flag so later we will know whether the gain loss line needs to be created
164842    
164843    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
164844      p_actual_flag :='A';
164845    END IF;
164846 
164847    --
164848    -- bulk performance
164849    --
164850    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
164851                                       p_header_num   => 0); -- 4262811
164852    --
164853    -- set accounting line options
164854    --
164855    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
164856            p_natural_side_code          => 'D'
164857          , p_gain_or_loss_flag          => 'N'
164858          , p_gl_transfer_mode_code      => 'S'
164859          , p_acct_entry_type_code       => 'A'
164860          , p_switch_side_flag           => 'Y'
164861          , p_merge_duplicate_code       => 'N'
164862          );
164863    --
164864    l_acc_rev_natural_side_code := 'C';  -- 4262811
164865    -- 
164866    --
164867    -- set accounting line type info
164868    --
164869    xla_ae_lines_pkg.SetAcctLineType
164870       (p_component_type             => l_component_type
164871       ,p_event_type_code            => l_event_type_code
164872       ,p_line_definition_owner_code => l_line_definition_owner_code
164873       ,p_line_definition_code       => l_line_definition_code
164874       ,p_accounting_line_code       => l_component_code
164875       ,p_accounting_line_type_code  => l_component_type_code
164876       ,p_accounting_line_appl_id    => l_component_appl_id
164877       ,p_amb_context_code           => l_amb_context_code
164878       ,p_entity_code                => l_entity_code
164879       ,p_event_class_code           => l_event_class_code);
164880    --
164881    -- set accounting class
164882    --
164883    xla_ae_lines_pkg.SetAcctClass(
164884            p_accounting_class_code  => 'ASSET'
164885          , p_ae_header_id           => l_ae_header_id
164886          );
164887 
164888    --
164889    -- set rounding class
164890    --
164891    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
164892                       'ASSET';
164893 
164894    --
164895    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
164896    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
164897    --
164898    -- bulk performance
164899    --
164900    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
164901 
164902    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
164903       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
164904 
164905    -- 4955764
164906    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
164907       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
164908 
164909    -- 4458381 Public Sector Enh
164910    
164911    --
164912    -- set accounting attributes for the line type
164913    --
164914    l_entered_amt_idx := 4;
164915    l_accted_amt_idx  := 6;
164916    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
164917    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
164918    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
164919    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
164920    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
164921    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
164922    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
164923    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
164924    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
164925    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
164926    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
164927    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
164928    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
164929 
164930    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
164931    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
164932 
164933    ---------------------------------------------------------------------------------------------------------------
164934    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
164935    ---------------------------------------------------------------------------------------------------------------
164936    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
164937 
164938    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
164939    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
164940 
164941    IF xla_accounting_cache_pkg.GetValueChar
164942          (p_source_code         => 'LEDGER_CATEGORY_CODE'
164943          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
164944    AND l_bflow_method_code = 'PRIOR_ENTRY'
164945 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
164946    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
164947          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
164948        )
164949    THEN
164950          xla_ae_lines_pkg.BflowUpgEntry
164951            (p_business_method_code    => l_bflow_method_code
164952            ,p_business_class_code     => l_bflow_class_code
164956 -- No business flow processing for business flow method of NONE.
164953            ,p_balance_type            => l_balance_type_code);
164954    ELSE
164955       NULL;
164957    END IF;
164958 
164959    --
164960    -- call analytical criteria
164961    --
164962    
164963    --
164964    -- call description
164965    --
164966    
164967 xla_ae_lines_pkg.SetLineDescription(
164968    p_ae_header_id => l_ae_header_id
164969   ,p_description  => Description_131 (
164970      p_application_id         => p_application_id
164971    , p_ae_header_id           => l_ae_header_id 
164972 , p_source_1 => p_source_1
164973    )
164974 );
164975 
164976 
164977    --
164978    -- call ADRs
164979    -- Bug 4922099
164980    --
164981    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
164982         (NVL(l_actual_upg_option, 'N') = 'O') OR
164983         (NVL(l_enc_upg_option, 'N') = 'O')
164984       )
164985    THEN
164986    NULL;
164987    --
164988    --
164989    
164990   l_ccid := AcctDerRule_174(
164991            p_application_id           => p_application_id
164992          , p_ae_header_id             => l_ae_header_id 
164993 , p_source_3 => p_source_3
164994 , p_source_17 => p_source_17
164995 , p_source_30 => p_source_30
164996          , x_transaction_coa_id       => l_adr_transaction_coa_id
164997          , x_accounting_coa_id        => l_adr_accounting_coa_id
164998          , x_value_type_code          => l_adr_value_type_code
164999          , p_side                     => 'NA'
165000    );
165001 
165002    xla_ae_lines_pkg.set_ccid(
165003     p_code_combination_id          => l_ccid
165004   , p_value_type_code              => l_adr_value_type_code
165005   , p_transaction_coa_id           => l_adr_transaction_coa_id
165006   , p_accounting_coa_id            => l_adr_accounting_coa_id
165007   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
165008   , p_adr_type_code                => 'S'
165009   , p_component_type               => l_component_type
165010   , p_component_code               => l_component_code
165011   , p_component_type_code          => l_component_type_code
165012   , p_component_appl_id            => l_component_appl_id
165013   , p_amb_context_code             => l_amb_context_code
165014   , p_side                         => 'NA'
165015   );
165016 
165017 
165018    l_segment := AcctDerRule_150(
165019            p_application_id           => p_application_id
165020          , p_ae_header_id             => l_ae_header_id 
165021 , p_source_3 => p_source_3
165022 , p_source_11 => p_source_11
165023          , x_transaction_coa_id       => l_adr_transaction_coa_id
165024          , x_accounting_coa_id        => l_adr_accounting_coa_id
165025          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
165026          , x_flex_value_set_id        => l_adr_flex_value_set_id
165027          , x_value_type_code          => l_adr_value_type_code
165028          , x_value_combination_id     => l_adr_value_combination_id
165029          , x_value_segment_code       => l_adr_value_segment_code
165030          , p_side                     => 'NA'
165031          , p_override_seg_flag        => 'Y'
165032    );
165033 
165034    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
165035 
165036       xla_ae_lines_pkg.set_segment(
165037           p_to_segment_code         => 'GL_ACCOUNT'
165038         , p_segment_value           => l_segment
165039         , p_from_segment_code       => l_adr_value_segment_code
165040         , p_from_combination_id     => l_adr_value_combination_id
165041         , p_value_type_code         => l_adr_value_type_code
165042         , p_transaction_coa_id      => l_adr_transaction_coa_id
165043         , p_accounting_coa_id       => l_adr_accounting_coa_id
165044         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
165045         , p_flex_value_set_id       => l_adr_flex_value_set_id
165046         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
165047         , p_adr_type_code           => 'S'
165048         , p_component_type          => l_component_type
165049         , p_component_code          => l_component_code
165050         , p_component_type_code     => l_component_type_code
165051         , p_component_appl_id       => l_component_appl_id
165052         , p_amb_context_code        => l_amb_context_code
165053         , p_entity_code             => 'TRANSACTIONS'
165054         , p_event_class_code        => 'TRANSFERS'
165055         , p_side                    => 'NA'
165056         );
165057 
165058   END IF;
165059 
165060    l_segment := AcctDerRule_168(
165061            p_application_id           => p_application_id
165062          , p_ae_header_id             => l_ae_header_id 
165063 , p_source_3 => p_source_3
165064 , p_source_29 => p_source_29
165065          , x_transaction_coa_id       => l_adr_transaction_coa_id
165066          , x_accounting_coa_id        => l_adr_accounting_coa_id
165067          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
165068          , x_flex_value_set_id        => l_adr_flex_value_set_id
165069          , x_value_type_code          => l_adr_value_type_code
165070          , x_value_combination_id     => l_adr_value_combination_id
165071          , x_value_segment_code       => l_adr_value_segment_code
165072          , p_side                     => 'NA'
165073          , p_override_seg_flag        => 'Y'
165074    );
165075 
165076    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
165077 
165078       xla_ae_lines_pkg.set_segment(
165079           p_to_segment_code         => 'GL_BALANCING'
165080         , p_segment_value           => l_segment
165081         , p_from_segment_code       => l_adr_value_segment_code
165082         , p_from_combination_id     => l_adr_value_combination_id
165083         , p_value_type_code         => l_adr_value_type_code
165084         , p_transaction_coa_id      => l_adr_transaction_coa_id
165088         , p_adr_code                => 'FA_EXPENSE_ACCT'
165085         , p_accounting_coa_id       => l_adr_accounting_coa_id
165086         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
165087         , p_flex_value_set_id       => l_adr_flex_value_set_id
165089         , p_adr_type_code           => 'S'
165090         , p_component_type          => l_component_type
165091         , p_component_code          => l_component_code
165092         , p_component_type_code     => l_component_type_code
165093         , p_component_appl_id       => l_component_appl_id
165094         , p_amb_context_code        => l_amb_context_code
165095         , p_entity_code             => 'TRANSACTIONS'
165096         , p_event_class_code        => 'TRANSFERS'
165097         , p_side                    => 'NA'
165098         );
165099 
165100   END IF;
165101 
165102    --
165103    --
165104    END IF;
165105    --
165106    -- Bug 4922099
165107    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
165108           (NVL(l_enc_upg_option, 'N') = 'O')
165109         ) AND
165110         (l_bflow_method_code = 'PRIOR_ENTRY')
165111       )
165112    THEN
165113       IF
165114       --
165115       1 = 2
165116       --
165117       THEN
165118       xla_accounting_err_pkg.build_message
165119                                     (p_appli_s_name            => 'XLA'
165120                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
165121                                     ,p_token_1                 => 'LINE_NUMBER'
165122                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
165123                                     ,p_token_2                 => 'LINE_TYPE_NAME'
165124                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
165125                                                                              l_component_type
165126                                                                             ,l_component_code
165127                                                                             ,l_component_type_code
165128                                                                             ,l_component_appl_id
165129                                                                             ,l_amb_context_code
165130                                                                             ,l_entity_code
165131                                                                             ,l_event_class_code
165132                                                                            )
165133                                     ,p_token_3                 => 'OWNER'
165134                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
165135                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
165136                                                                           ,p_lookup_code    => l_component_type_code
165137                                                                          )
165138                                     ,p_token_4                 => 'PRODUCT_NAME'
165139                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
165140                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
165141                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
165142                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
165143                                     ,p_ae_header_id            =>  NULL
165144                                        );
165145 
165146         IF (C_LEVEL_ERROR>= g_log_level) THEN
165147                  trace
165148                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
165149                       ,p_level    => C_LEVEL_ERROR
165150                       ,p_module   => l_log_module);
165151         END IF;
165152       END IF;
165153    END IF;
165154    --
165155    --
165156    ------------------------------------------------------------------------------------------------
165157    -- 4219869 Business Flow
165158    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
165159    -- Prior Entry.  Currently, the following code is always generated.
165160    ------------------------------------------------------------------------------------------------
165161    XLA_AE_LINES_PKG.ValidateCurrentLine;
165162 
165163    ------------------------------------------------------------------------------------
165164    -- 4219869 Business Flow
165165    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
165166    ------------------------------------------------------------------------------------
165167    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
165168 
165169    ----------------------------------------------------------------------------------
165170    -- 4219869 Business Flow
165171    -- Update journal entry status -- Need to generate this within IF <condition>
165172    ----------------------------------------------------------------------------------
165173    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
165174          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
165175          ,p_balance_type_code => l_balance_type_code
165176          );
165177 
165178    -------------------------------------------------------------------------------------------
165179    -- 4262811 - Generate the Accrual Reversal lines
165180    -------------------------------------------------------------------------------------------
165181    BEGIN
165182       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
165183                               (g_array_event(p_event_id).array_value_num('header_index'));
165184       IF l_acc_rev_flag IS NULL THEN
165185          l_acc_rev_flag := 'N';
165186       END IF;
165187    EXCEPTION
165188       WHEN OTHERS THEN
165192    IF (l_acc_rev_flag = 'Y') THEN
165189          l_acc_rev_flag := 'N';
165190    END;
165191    --
165193 
165194        -- 4645092  ------------------------------------------------------------------------------
165195        -- To allow MPA report to determine if it should generate report process
165196        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
165197        ------------------------------------------------------------------------------------------
165198 
165199        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
165200        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
165201    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
165202    -- call ADRs
165203    -- Bug 4922099
165204    --
165205    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
165206         (NVL(l_actual_upg_option, 'N') = 'O') OR
165207         (NVL(l_enc_upg_option, 'N') = 'O')
165208       )
165209    THEN
165210    NULL;
165211    --
165212    --
165213    
165214   l_ccid := AcctDerRule_174(
165215            p_application_id           => p_application_id
165216          , p_ae_header_id             => l_ae_header_id 
165217 , p_source_3 => p_source_3
165218 , p_source_17 => p_source_17
165219 , p_source_30 => p_source_30
165220          , x_transaction_coa_id       => l_adr_transaction_coa_id
165221          , x_accounting_coa_id        => l_adr_accounting_coa_id
165222          , x_value_type_code          => l_adr_value_type_code
165223          , p_side                     => 'NA'
165224    );
165225 
165226    xla_ae_lines_pkg.set_ccid(
165227     p_code_combination_id          => l_ccid
165228   , p_value_type_code              => l_adr_value_type_code
165229   , p_transaction_coa_id           => l_adr_transaction_coa_id
165230   , p_accounting_coa_id            => l_adr_accounting_coa_id
165231   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
165232   , p_adr_type_code                => 'S'
165233   , p_component_type               => l_component_type
165234   , p_component_code               => l_component_code
165235   , p_component_type_code          => l_component_type_code
165236   , p_component_appl_id            => l_component_appl_id
165237   , p_amb_context_code             => l_amb_context_code
165238   , p_side                         => 'NA'
165239   );
165240 
165241 
165242    l_segment := AcctDerRule_150(
165243            p_application_id           => p_application_id
165244          , p_ae_header_id             => l_ae_header_id 
165245 , p_source_3 => p_source_3
165246 , p_source_11 => p_source_11
165247          , x_transaction_coa_id       => l_adr_transaction_coa_id
165248          , x_accounting_coa_id        => l_adr_accounting_coa_id
165249          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
165250          , x_flex_value_set_id        => l_adr_flex_value_set_id
165251          , x_value_type_code          => l_adr_value_type_code
165252          , x_value_combination_id     => l_adr_value_combination_id
165253          , x_value_segment_code       => l_adr_value_segment_code
165254          , p_side                     => 'NA'
165255          , p_override_seg_flag        => 'Y'
165256    );
165257 
165258    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
165259 
165260       xla_ae_lines_pkg.set_segment(
165261           p_to_segment_code         => 'GL_ACCOUNT'
165262         , p_segment_value           => l_segment
165263         , p_from_segment_code       => l_adr_value_segment_code
165264         , p_from_combination_id     => l_adr_value_combination_id
165265         , p_value_type_code         => l_adr_value_type_code
165266         , p_transaction_coa_id      => l_adr_transaction_coa_id
165267         , p_accounting_coa_id       => l_adr_accounting_coa_id
165268         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
165269         , p_flex_value_set_id       => l_adr_flex_value_set_id
165270         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
165271         , p_adr_type_code           => 'S'
165272         , p_component_type          => l_component_type
165273         , p_component_code          => l_component_code
165274         , p_component_type_code     => l_component_type_code
165275         , p_component_appl_id       => l_component_appl_id
165276         , p_amb_context_code        => l_amb_context_code
165277         , p_entity_code             => 'TRANSACTIONS'
165278         , p_event_class_code        => 'TRANSFERS'
165279         , p_side                    => 'NA'
165280         );
165281 
165282   END IF;
165283 
165284    l_segment := AcctDerRule_168(
165285            p_application_id           => p_application_id
165286          , p_ae_header_id             => l_ae_header_id 
165287 , p_source_3 => p_source_3
165288 , p_source_29 => p_source_29
165289          , x_transaction_coa_id       => l_adr_transaction_coa_id
165290          , x_accounting_coa_id        => l_adr_accounting_coa_id
165291          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
165292          , x_flex_value_set_id        => l_adr_flex_value_set_id
165293          , x_value_type_code          => l_adr_value_type_code
165294          , x_value_combination_id     => l_adr_value_combination_id
165295          , x_value_segment_code       => l_adr_value_segment_code
165296          , p_side                     => 'NA'
165297          , p_override_seg_flag        => 'Y'
165298    );
165299 
165300    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
165301 
165302       xla_ae_lines_pkg.set_segment(
165303           p_to_segment_code         => 'GL_BALANCING'
165304         , p_segment_value           => l_segment
165305         , p_from_segment_code       => l_adr_value_segment_code
165306         , p_from_combination_id     => l_adr_value_combination_id
165307         , p_value_type_code         => l_adr_value_type_code
165308         , p_transaction_coa_id      => l_adr_transaction_coa_id
165309         , p_accounting_coa_id       => l_adr_accounting_coa_id
165313         , p_adr_type_code           => 'S'
165310         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
165311         , p_flex_value_set_id       => l_adr_flex_value_set_id
165312         , p_adr_code                => 'FA_EXPENSE_ACCT'
165314         , p_component_type          => l_component_type
165315         , p_component_code          => l_component_code
165316         , p_component_type_code     => l_component_type_code
165317         , p_component_appl_id       => l_component_appl_id
165318         , p_amb_context_code        => l_amb_context_code
165319         , p_entity_code             => 'TRANSACTIONS'
165320         , p_event_class_code        => 'TRANSFERS'
165321         , p_side                    => 'NA'
165322         );
165323 
165324   END IF;
165325 
165326    --
165327    --
165328    END IF;
165329 
165330        --
165331        -- Update the line information that should be overwritten
165332        --
165333        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
165334                                          p_header_num   => 1);
165335        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
165336 
165337        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
165338 
165339        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
165340           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
165341        END IF;
165342 
165343       --
165344       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
165345       --
165346       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
165347           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
165348       ELSE
165349           ---------------------------------------------------------------------------------------------------
165350           -- 4262811a Switch Sign
165351           ---------------------------------------------------------------------------------------------------
165352           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
165353           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
165354                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
165355           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
165356                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
165357           -- 5132302
165358           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
165359                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
165360 
165361       END IF;
165362 
165363       -- 4955764
165364       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
165365       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
165366 
165367 
165368       XLA_AE_LINES_PKG.ValidateCurrentLine;
165369       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
165370 
165371       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
165372                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
165373                ,p_balance_type_code => l_balance_type_code);
165374 
165375    END IF;
165376 
165377    -----------------------------------------------------------------------------------------
165378    -- 4262811 Multiperiod Accounting
165379    -----------------------------------------------------------------------------------------
165380      -- No MPA option is assigned.
165381 
165382 
165383 END IF;
165384 END IF;
165385 --
165386 
165387 --
165388 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
165389    trace
165390       (p_msg      => 'END of AcctLineType_386'
165391       ,p_level    => C_LEVEL_PROCEDURE
165392       ,p_module   => l_log_module);
165393 END IF;
165394 --
165395 EXCEPTION
165396   WHEN xla_exceptions_pkg.application_exception THEN
165397       RAISE;
165398   WHEN OTHERS THEN
165399        xla_exceptions_pkg.raise_message
165400            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_386');
165401 END AcctLineType_386;
165402 --
165403 
165404 ---------------------------------------
165405 --
165406 -- PRIVATE FUNCTION
165407 --         AcctLineType_387
165408 --
165409 ---------------------------------------
165410 PROCEDURE AcctLineType_387 (
165411   p_application_id        IN NUMBER
165412  ,p_event_id              IN NUMBER
165413  ,p_calculate_acctd_flag  IN VARCHAR2
165414  ,p_calculate_g_l_flag    IN VARCHAR2
165415  ,p_actual_flag           IN OUT VARCHAR2
165416  ,p_balance_type_code     OUT VARCHAR2
165417  ,p_gain_or_loss_ref      OUT VARCHAR2
165418  
165419 --Period Close Date
165420  , p_source_1            IN DATE
165421 --Generated Code Combination Identifier
165422  , p_source_3            IN NUMBER
165423 --Asset Cost Account
165424  , p_source_9            IN VARCHAR2
165425 --Expense Account Code Combination Identifier
165426  , p_source_29            IN NUMBER
165427 --Default Code Combination Identifier
165428  , p_source_30            IN NUMBER
165429 --Adjustment Type
165430  , p_source_35            IN VARCHAR2
165431 --Transaction Header Identifier
165432  , p_source_36            IN NUMBER
165433 --Adjustment Line Identifier
165434  , p_source_37            IN NUMBER
165435 --Distribution Type Code
165436  , p_source_38            IN VARCHAR2
165437 --Entered Amount
165438  , p_source_39            IN NUMBER
165439 --Currency Code
165440  , p_source_40            IN VARCHAR2
165441 --Source Destination Code
165445 
165442  , p_source_42            IN VARCHAR2
165443 )
165444 IS
165446 l_component_type              VARCHAR2(80);
165447 l_component_code              VARCHAR2(30);
165448 l_component_type_code         VARCHAR2(1);
165449 l_component_appl_id           INTEGER;
165450 l_amb_context_code            VARCHAR2(30);
165451 l_entity_code                 VARCHAR2(30);
165452 l_event_class_code            VARCHAR2(30);
165453 l_ae_header_id                NUMBER;
165454 l_event_type_code             VARCHAR2(30);
165455 l_line_definition_code        VARCHAR2(30);
165456 l_line_definition_owner_code  VARCHAR2(1);
165457 --
165458 -- adr variables
165459 l_segment                     VARCHAR2(30);
165460 l_ccid                        NUMBER;
165461 l_adr_transaction_coa_id      NUMBER;
165462 l_adr_accounting_coa_id       NUMBER;
165463 l_adr_flexfield_segment_code  VARCHAR2(30);
165464 l_adr_flex_value_set_id       NUMBER;
165465 l_adr_value_type_code         VARCHAR2(30);
165466 l_adr_value_combination_id    NUMBER;
165467 l_adr_value_segment_code      VARCHAR2(30);
165468 
165469 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
165470 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
165471 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
165472 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
165473 
165474 -- 4262811 Variables ------------------------------------------------------------------------------------------
165475 l_entered_amt_idx             NUMBER;
165476 l_accted_amt_idx              NUMBER;
165477 l_acc_rev_flag                VARCHAR2(1);
165478 l_accrual_line_num            NUMBER;
165479 l_tmp_amt                     NUMBER;
165480 l_acc_rev_natural_side_code   VARCHAR2(1);
165481 
165482 l_num_entries                 NUMBER;
165483 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
165484 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
165485 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
165486 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
165487 l_recog_line_1                NUMBER;
165488 l_recog_line_2                NUMBER;
165489 
165490 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
165491 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
165492 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
165493 
165494 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
165495 
165496 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
165497 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
165498 
165499 ---------------------------------------------------------------------------------------------------------------
165500 
165501 
165502 --
165503 -- bulk performance
165504 --
165505 l_balance_type_code           VARCHAR2(1);
165506 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
165507 l_log_module                  VARCHAR2(240);
165508 
165509 --
165510 -- Upgrade strategy
165511 --
165512 l_actual_upg_option           VARCHAR2(1);
165513 l_enc_upg_option           VARCHAR2(1);
165514 
165515 --
165516 BEGIN
165517 --
165518 IF g_log_enabled THEN
165519       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_387';
165520 END IF;
165521 --
165522 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
165523 
165524       trace
165525          (p_msg      => 'BEGIN of AcctLineType_387'
165526          ,p_level    => C_LEVEL_PROCEDURE
165527          ,p_module   => l_log_module);
165528 
165529 END IF;
165530 --
165531 l_component_type             := 'AMB_JLT';
165532 l_component_code             := 'FA_UNITADJ _DEST_COST';
165533 l_component_type_code        := 'S';
165534 l_component_appl_id          :=  140;
165535 l_amb_context_code           := 'DEFAULT';
165536 l_entity_code                := 'TRANSACTIONS';
165537 l_event_class_code           := 'UNIT_ADJUSTMENTS';
165538 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
165539 l_line_definition_owner_code := 'S';
165540 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
165541 --
165542 l_balance_type_code          := 'A';
165543 l_segment                     := NULL;
165544 l_ccid                        := NULL;
165545 l_adr_transaction_coa_id      := NULL;
165546 l_adr_accounting_coa_id       := NULL;
165547 l_adr_flexfield_segment_code  := NULL;
165548 l_adr_flex_value_set_id       := NULL;
165549 l_adr_value_type_code         := NULL;
165550 l_adr_value_combination_id    := NULL;
165551 l_adr_value_segment_code      := NULL;
165552 
165553 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
165554 l_bflow_class_code           := '';    -- 4219869 Business Flow
165555 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
165556 l_budgetary_control_flag     := 'N';
165557 
165558 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
165559 l_bflow_applied_to_amt       := NULL; -- 5132302
165560 l_entered_amt_idx            := NULL;          -- 4262811
165561 l_accted_amt_idx             := NULL;          -- 4262811
165562 l_acc_rev_flag               := NULL;          -- 4262811
165563 l_accrual_line_num           := NULL;          -- 4262811
165564 l_tmp_amt                    := NULL;          -- 4262811
165565 --
165566  
165567 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
165568     l_balance_type_code <> 'B' THEN
165569 IF NVL(p_source_35,'
165570 ') =  'COST' AND 
165571 NVL(p_source_42,'
165572 ') =  'DEST'
165573  THEN 
165574 
165575    --
165576    XLA_AE_LINES_PKG.SetNewLine;
165577 
165578    p_balance_type_code          := l_balance_type_code;
165579    -- set the flag so later we will know whether the gain loss line needs to be created
165580    
165584 
165581    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
165582      p_actual_flag :='A';
165583    END IF;
165585    --
165586    -- bulk performance
165587    --
165588    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
165589                                       p_header_num   => 0); -- 4262811
165590    --
165591    -- set accounting line options
165592    --
165593    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
165594            p_natural_side_code          => 'D'
165595          , p_gain_or_loss_flag          => 'N'
165596          , p_gl_transfer_mode_code      => 'S'
165597          , p_acct_entry_type_code       => 'A'
165598          , p_switch_side_flag           => 'Y'
165599          , p_merge_duplicate_code       => 'N'
165600          );
165601    --
165602    l_acc_rev_natural_side_code := 'C';  -- 4262811
165603    -- 
165604    --
165605    -- set accounting line type info
165606    --
165607    xla_ae_lines_pkg.SetAcctLineType
165608       (p_component_type             => l_component_type
165609       ,p_event_type_code            => l_event_type_code
165610       ,p_line_definition_owner_code => l_line_definition_owner_code
165611       ,p_line_definition_code       => l_line_definition_code
165612       ,p_accounting_line_code       => l_component_code
165613       ,p_accounting_line_type_code  => l_component_type_code
165614       ,p_accounting_line_appl_id    => l_component_appl_id
165615       ,p_amb_context_code           => l_amb_context_code
165616       ,p_entity_code                => l_entity_code
165617       ,p_event_class_code           => l_event_class_code);
165618    --
165619    -- set accounting class
165620    --
165621    xla_ae_lines_pkg.SetAcctClass(
165622            p_accounting_class_code  => 'ASSET'
165623          , p_ae_header_id           => l_ae_header_id
165624          );
165625 
165626    --
165627    -- set rounding class
165628    --
165629    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
165630                       'ASSET';
165631 
165632    --
165633    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
165634    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
165635    --
165636    -- bulk performance
165637    --
165638    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
165639 
165640    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
165641       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
165642 
165643    -- 4955764
165644    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
165645       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
165646 
165647    -- 4458381 Public Sector Enh
165648    
165649    --
165650    -- set accounting attributes for the line type
165651    --
165652    l_entered_amt_idx := 4;
165653    l_accted_amt_idx  := 6;
165654    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
165655    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
165656    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
165657    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
165658    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
165659    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
165660    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
165661    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
165662    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
165663    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
165664    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
165665    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
165666    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
165667 
165668    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
165669    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
165670 
165671    ---------------------------------------------------------------------------------------------------------------
165672    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
165673    ---------------------------------------------------------------------------------------------------------------
165674    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
165675 
165676    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
165677    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
165678 
165679    IF xla_accounting_cache_pkg.GetValueChar
165680          (p_source_code         => 'LEDGER_CATEGORY_CODE'
165681          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
165682    AND l_bflow_method_code = 'PRIOR_ENTRY'
165683 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
165684    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
165685          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
165686        )
165687    THEN
165688          xla_ae_lines_pkg.BflowUpgEntry
165689            (p_business_method_code    => l_bflow_method_code
165690            ,p_business_class_code     => l_bflow_class_code
165691            ,p_balance_type            => l_balance_type_code);
165692    ELSE
165693       NULL;
165694 -- No business flow processing for business flow method of NONE.
165695    END IF;
165696 
165697    --
165698    -- call analytical criteria
165699    --
165700    
165701    --
165702    -- call description
165703    --
165704    
165705 xla_ae_lines_pkg.SetLineDescription(
165706    p_ae_header_id => l_ae_header_id
165710 , p_source_1 => p_source_1
165707   ,p_description  => Description_133 (
165708      p_application_id         => p_application_id
165709    , p_ae_header_id           => l_ae_header_id 
165711    )
165712 );
165713 
165714 
165715    --
165716    -- call ADRs
165717    -- Bug 4922099
165718    --
165719    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
165720         (NVL(l_actual_upg_option, 'N') = 'O') OR
165721         (NVL(l_enc_upg_option, 'N') = 'O')
165722       )
165723    THEN
165724    NULL;
165725    --
165726    --
165727    
165728   l_ccid := AcctDerRule_173(
165729            p_application_id           => p_application_id
165730          , p_ae_header_id             => l_ae_header_id 
165731 , p_source_3 => p_source_3
165732 , p_source_30 => p_source_30
165733          , x_transaction_coa_id       => l_adr_transaction_coa_id
165734          , x_accounting_coa_id        => l_adr_accounting_coa_id
165735          , x_value_type_code          => l_adr_value_type_code
165736          , p_side                     => 'NA'
165737    );
165738 
165739    xla_ae_lines_pkg.set_ccid(
165740     p_code_combination_id          => l_ccid
165741   , p_value_type_code              => l_adr_value_type_code
165742   , p_transaction_coa_id           => l_adr_transaction_coa_id
165743   , p_accounting_coa_id            => l_adr_accounting_coa_id
165744   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
165745   , p_adr_type_code                => 'S'
165746   , p_component_type               => l_component_type
165747   , p_component_code               => l_component_code
165748   , p_component_type_code          => l_component_type_code
165749   , p_component_appl_id            => l_component_appl_id
165750   , p_amb_context_code             => l_amb_context_code
165751   , p_side                         => 'NA'
165752   );
165753 
165754 
165755    l_segment := AcctDerRule_148(
165756            p_application_id           => p_application_id
165757          , p_ae_header_id             => l_ae_header_id 
165758 , p_source_3 => p_source_3
165759 , p_source_9 => p_source_9
165760          , x_transaction_coa_id       => l_adr_transaction_coa_id
165761          , x_accounting_coa_id        => l_adr_accounting_coa_id
165762          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
165763          , x_flex_value_set_id        => l_adr_flex_value_set_id
165764          , x_value_type_code          => l_adr_value_type_code
165765          , x_value_combination_id     => l_adr_value_combination_id
165766          , x_value_segment_code       => l_adr_value_segment_code
165767          , p_side                     => 'NA'
165768          , p_override_seg_flag        => 'Y'
165769    );
165770 
165771    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
165772 
165773       xla_ae_lines_pkg.set_segment(
165774           p_to_segment_code         => 'GL_ACCOUNT'
165775         , p_segment_value           => l_segment
165776         , p_from_segment_code       => l_adr_value_segment_code
165777         , p_from_combination_id     => l_adr_value_combination_id
165778         , p_value_type_code         => l_adr_value_type_code
165779         , p_transaction_coa_id      => l_adr_transaction_coa_id
165780         , p_accounting_coa_id       => l_adr_accounting_coa_id
165781         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
165782         , p_flex_value_set_id       => l_adr_flex_value_set_id
165783         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
165784         , p_adr_type_code           => 'S'
165785         , p_component_type          => l_component_type
165786         , p_component_code          => l_component_code
165787         , p_component_type_code     => l_component_type_code
165788         , p_component_appl_id       => l_component_appl_id
165789         , p_amb_context_code        => l_amb_context_code
165790         , p_entity_code             => 'TRANSACTIONS'
165791         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
165792         , p_side                    => 'NA'
165793         );
165794 
165795   END IF;
165796 
165797    l_segment := AcctDerRule_168(
165798            p_application_id           => p_application_id
165799          , p_ae_header_id             => l_ae_header_id 
165800 , p_source_3 => p_source_3
165801 , p_source_29 => p_source_29
165802          , x_transaction_coa_id       => l_adr_transaction_coa_id
165803          , x_accounting_coa_id        => l_adr_accounting_coa_id
165804          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
165805          , x_flex_value_set_id        => l_adr_flex_value_set_id
165806          , x_value_type_code          => l_adr_value_type_code
165807          , x_value_combination_id     => l_adr_value_combination_id
165808          , x_value_segment_code       => l_adr_value_segment_code
165809          , p_side                     => 'NA'
165810          , p_override_seg_flag        => 'Y'
165811    );
165812 
165813    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
165814 
165815       xla_ae_lines_pkg.set_segment(
165816           p_to_segment_code         => 'GL_BALANCING'
165817         , p_segment_value           => l_segment
165818         , p_from_segment_code       => l_adr_value_segment_code
165819         , p_from_combination_id     => l_adr_value_combination_id
165820         , p_value_type_code         => l_adr_value_type_code
165821         , p_transaction_coa_id      => l_adr_transaction_coa_id
165822         , p_accounting_coa_id       => l_adr_accounting_coa_id
165823         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
165824         , p_flex_value_set_id       => l_adr_flex_value_set_id
165825         , p_adr_code                => 'FA_EXPENSE_ACCT'
165826         , p_adr_type_code           => 'S'
165827         , p_component_type          => l_component_type
165828         , p_component_code          => l_component_code
165829         , p_component_type_code     => l_component_type_code
165830         , p_component_appl_id       => l_component_appl_id
165834         , p_side                    => 'NA'
165831         , p_amb_context_code        => l_amb_context_code
165832         , p_entity_code             => 'TRANSACTIONS'
165833         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
165835         );
165836 
165837   END IF;
165838 
165839    --
165840    --
165841    END IF;
165842    --
165843    -- Bug 4922099
165844    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
165845           (NVL(l_enc_upg_option, 'N') = 'O')
165846         ) AND
165847         (l_bflow_method_code = 'PRIOR_ENTRY')
165848       )
165849    THEN
165850       IF
165851       --
165852       1 = 2
165853       --
165854       THEN
165855       xla_accounting_err_pkg.build_message
165856                                     (p_appli_s_name            => 'XLA'
165857                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
165858                                     ,p_token_1                 => 'LINE_NUMBER'
165859                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
165860                                     ,p_token_2                 => 'LINE_TYPE_NAME'
165861                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
165862                                                                              l_component_type
165863                                                                             ,l_component_code
165864                                                                             ,l_component_type_code
165865                                                                             ,l_component_appl_id
165866                                                                             ,l_amb_context_code
165867                                                                             ,l_entity_code
165868                                                                             ,l_event_class_code
165869                                                                            )
165870                                     ,p_token_3                 => 'OWNER'
165871                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
165872                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
165873                                                                           ,p_lookup_code    => l_component_type_code
165874                                                                          )
165875                                     ,p_token_4                 => 'PRODUCT_NAME'
165876                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
165877                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
165878                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
165879                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
165880                                     ,p_ae_header_id            =>  NULL
165881                                        );
165882 
165883         IF (C_LEVEL_ERROR>= g_log_level) THEN
165884                  trace
165885                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
165886                       ,p_level    => C_LEVEL_ERROR
165887                       ,p_module   => l_log_module);
165888         END IF;
165889       END IF;
165890    END IF;
165891    --
165892    --
165893    ------------------------------------------------------------------------------------------------
165894    -- 4219869 Business Flow
165895    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
165896    -- Prior Entry.  Currently, the following code is always generated.
165897    ------------------------------------------------------------------------------------------------
165898    XLA_AE_LINES_PKG.ValidateCurrentLine;
165899 
165900    ------------------------------------------------------------------------------------
165901    -- 4219869 Business Flow
165902    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
165903    ------------------------------------------------------------------------------------
165904    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
165905 
165906    ----------------------------------------------------------------------------------
165907    -- 4219869 Business Flow
165908    -- Update journal entry status -- Need to generate this within IF <condition>
165909    ----------------------------------------------------------------------------------
165910    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
165911          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
165912          ,p_balance_type_code => l_balance_type_code
165913          );
165914 
165915    -------------------------------------------------------------------------------------------
165916    -- 4262811 - Generate the Accrual Reversal lines
165917    -------------------------------------------------------------------------------------------
165918    BEGIN
165919       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
165920                               (g_array_event(p_event_id).array_value_num('header_index'));
165921       IF l_acc_rev_flag IS NULL THEN
165922          l_acc_rev_flag := 'N';
165923       END IF;
165924    EXCEPTION
165925       WHEN OTHERS THEN
165926          l_acc_rev_flag := 'N';
165927    END;
165928    --
165929    IF (l_acc_rev_flag = 'Y') THEN
165930 
165931        -- 4645092  ------------------------------------------------------------------------------
165932        -- To allow MPA report to determine if it should generate report process
165933        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
165934        ------------------------------------------------------------------------------------------
165935 
165936        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
165940    -- Bug 4922099
165937        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
165938    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
165939    -- call ADRs
165941    --
165942    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
165943         (NVL(l_actual_upg_option, 'N') = 'O') OR
165944         (NVL(l_enc_upg_option, 'N') = 'O')
165945       )
165946    THEN
165947    NULL;
165948    --
165949    --
165950    
165951   l_ccid := AcctDerRule_173(
165952            p_application_id           => p_application_id
165953          , p_ae_header_id             => l_ae_header_id 
165954 , p_source_3 => p_source_3
165955 , p_source_30 => p_source_30
165956          , x_transaction_coa_id       => l_adr_transaction_coa_id
165957          , x_accounting_coa_id        => l_adr_accounting_coa_id
165958          , x_value_type_code          => l_adr_value_type_code
165959          , p_side                     => 'NA'
165960    );
165961 
165962    xla_ae_lines_pkg.set_ccid(
165963     p_code_combination_id          => l_ccid
165964   , p_value_type_code              => l_adr_value_type_code
165965   , p_transaction_coa_id           => l_adr_transaction_coa_id
165966   , p_accounting_coa_id            => l_adr_accounting_coa_id
165967   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
165968   , p_adr_type_code                => 'S'
165969   , p_component_type               => l_component_type
165970   , p_component_code               => l_component_code
165971   , p_component_type_code          => l_component_type_code
165972   , p_component_appl_id            => l_component_appl_id
165973   , p_amb_context_code             => l_amb_context_code
165974   , p_side                         => 'NA'
165975   );
165976 
165977 
165978    l_segment := AcctDerRule_148(
165979            p_application_id           => p_application_id
165980          , p_ae_header_id             => l_ae_header_id 
165981 , p_source_3 => p_source_3
165982 , p_source_9 => p_source_9
165983          , x_transaction_coa_id       => l_adr_transaction_coa_id
165984          , x_accounting_coa_id        => l_adr_accounting_coa_id
165985          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
165986          , x_flex_value_set_id        => l_adr_flex_value_set_id
165987          , x_value_type_code          => l_adr_value_type_code
165988          , x_value_combination_id     => l_adr_value_combination_id
165989          , x_value_segment_code       => l_adr_value_segment_code
165990          , p_side                     => 'NA'
165991          , p_override_seg_flag        => 'Y'
165992    );
165993 
165994    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
165995 
165996       xla_ae_lines_pkg.set_segment(
165997           p_to_segment_code         => 'GL_ACCOUNT'
165998         , p_segment_value           => l_segment
165999         , p_from_segment_code       => l_adr_value_segment_code
166000         , p_from_combination_id     => l_adr_value_combination_id
166001         , p_value_type_code         => l_adr_value_type_code
166002         , p_transaction_coa_id      => l_adr_transaction_coa_id
166003         , p_accounting_coa_id       => l_adr_accounting_coa_id
166004         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
166005         , p_flex_value_set_id       => l_adr_flex_value_set_id
166006         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
166007         , p_adr_type_code           => 'S'
166008         , p_component_type          => l_component_type
166009         , p_component_code          => l_component_code
166010         , p_component_type_code     => l_component_type_code
166011         , p_component_appl_id       => l_component_appl_id
166012         , p_amb_context_code        => l_amb_context_code
166013         , p_entity_code             => 'TRANSACTIONS'
166014         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
166015         , p_side                    => 'NA'
166016         );
166017 
166018   END IF;
166019 
166020    l_segment := AcctDerRule_168(
166021            p_application_id           => p_application_id
166022          , p_ae_header_id             => l_ae_header_id 
166023 , p_source_3 => p_source_3
166024 , p_source_29 => p_source_29
166025          , x_transaction_coa_id       => l_adr_transaction_coa_id
166026          , x_accounting_coa_id        => l_adr_accounting_coa_id
166027          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
166028          , x_flex_value_set_id        => l_adr_flex_value_set_id
166029          , x_value_type_code          => l_adr_value_type_code
166030          , x_value_combination_id     => l_adr_value_combination_id
166031          , x_value_segment_code       => l_adr_value_segment_code
166032          , p_side                     => 'NA'
166033          , p_override_seg_flag        => 'Y'
166034    );
166035 
166036    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
166037 
166038       xla_ae_lines_pkg.set_segment(
166039           p_to_segment_code         => 'GL_BALANCING'
166040         , p_segment_value           => l_segment
166041         , p_from_segment_code       => l_adr_value_segment_code
166042         , p_from_combination_id     => l_adr_value_combination_id
166043         , p_value_type_code         => l_adr_value_type_code
166044         , p_transaction_coa_id      => l_adr_transaction_coa_id
166045         , p_accounting_coa_id       => l_adr_accounting_coa_id
166046         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
166047         , p_flex_value_set_id       => l_adr_flex_value_set_id
166048         , p_adr_code                => 'FA_EXPENSE_ACCT'
166049         , p_adr_type_code           => 'S'
166050         , p_component_type          => l_component_type
166051         , p_component_code          => l_component_code
166052         , p_component_type_code     => l_component_type_code
166053         , p_component_appl_id       => l_component_appl_id
166054         , p_amb_context_code        => l_amb_context_code
166055         , p_entity_code             => 'TRANSACTIONS'
166059 
166056         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
166057         , p_side                    => 'NA'
166058         );
166060   END IF;
166061 
166062    --
166063    --
166064    END IF;
166065 
166066        --
166067        -- Update the line information that should be overwritten
166068        --
166069        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
166070                                          p_header_num   => 1);
166071        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
166072 
166073        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
166074 
166075        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
166076           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
166077        END IF;
166078 
166079       --
166080       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
166081       --
166082       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
166083           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
166084       ELSE
166085           ---------------------------------------------------------------------------------------------------
166086           -- 4262811a Switch Sign
166087           ---------------------------------------------------------------------------------------------------
166088           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
166089           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
166090                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
166091           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
166092                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
166093           -- 5132302
166094           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
166095                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
166096 
166097       END IF;
166098 
166099       -- 4955764
166100       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
166101       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
166102 
166103 
166104       XLA_AE_LINES_PKG.ValidateCurrentLine;
166105       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
166106 
166107       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
166108                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
166109                ,p_balance_type_code => l_balance_type_code);
166110 
166111    END IF;
166112 
166113    -----------------------------------------------------------------------------------------
166114    -- 4262811 Multiperiod Accounting
166115    -----------------------------------------------------------------------------------------
166116      -- No MPA option is assigned.
166117 
166118 
166119 END IF;
166120 END IF;
166121 --
166122 
166123 --
166124 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
166125    trace
166126       (p_msg      => 'END of AcctLineType_387'
166127       ,p_level    => C_LEVEL_PROCEDURE
166128       ,p_module   => l_log_module);
166129 END IF;
166130 --
166131 EXCEPTION
166132   WHEN xla_exceptions_pkg.application_exception THEN
166133       RAISE;
166134   WHEN OTHERS THEN
166135        xla_exceptions_pkg.raise_message
166136            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_387');
166137 END AcctLineType_387;
166138 --
166139 
166140 ---------------------------------------
166141 --
166142 -- PRIVATE FUNCTION
166143 --         AcctLineType_388
166144 --
166145 ---------------------------------------
166146 PROCEDURE AcctLineType_388 (
166147   p_application_id        IN NUMBER
166148  ,p_event_id              IN NUMBER
166149  ,p_calculate_acctd_flag  IN VARCHAR2
166150  ,p_calculate_g_l_flag    IN VARCHAR2
166151  ,p_actual_flag           IN OUT VARCHAR2
166152  ,p_balance_type_code     OUT VARCHAR2
166153  ,p_gain_or_loss_ref      OUT VARCHAR2
166154  
166155 --Period Close Date
166156  , p_source_1            IN DATE
166157 --Bonus Depreciation Expense Account
166158  , p_source_2            IN VARCHAR2
166159 --Generated Code Combination Identifier
166160  , p_source_3            IN NUMBER
166161 --Expense Account Code Combination Identifier
166162  , p_source_29            IN NUMBER
166163 --Adjustment Type
166164  , p_source_35            IN VARCHAR2
166165 --Transaction Header Identifier
166166  , p_source_36            IN NUMBER
166167 --Adjustment Line Identifier
166168  , p_source_37            IN NUMBER
166169 --Distribution Type Code
166170  , p_source_38            IN VARCHAR2
166171 --Entered Amount
166172  , p_source_39            IN NUMBER
166173 --Currency Code
166174  , p_source_40            IN VARCHAR2
166175 --Source Destination Code
166176  , p_source_42            IN VARCHAR2
166177 )
166178 IS
166179 
166180 l_component_type              VARCHAR2(80);
166181 l_component_code              VARCHAR2(30);
166182 l_component_type_code         VARCHAR2(1);
166183 l_component_appl_id           INTEGER;
166184 l_amb_context_code            VARCHAR2(30);
166185 l_entity_code                 VARCHAR2(30);
166186 l_event_class_code            VARCHAR2(30);
166187 l_ae_header_id                NUMBER;
166188 l_event_type_code             VARCHAR2(30);
166189 l_line_definition_code        VARCHAR2(30);
166190 l_line_definition_owner_code  VARCHAR2(1);
166191 --
166192 -- adr variables
166193 l_segment                     VARCHAR2(30);
166197 l_adr_flexfield_segment_code  VARCHAR2(30);
166194 l_ccid                        NUMBER;
166195 l_adr_transaction_coa_id      NUMBER;
166196 l_adr_accounting_coa_id       NUMBER;
166198 l_adr_flex_value_set_id       NUMBER;
166199 l_adr_value_type_code         VARCHAR2(30);
166200 l_adr_value_combination_id    NUMBER;
166201 l_adr_value_segment_code      VARCHAR2(30);
166202 
166203 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
166204 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
166205 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
166206 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
166207 
166208 -- 4262811 Variables ------------------------------------------------------------------------------------------
166209 l_entered_amt_idx             NUMBER;
166210 l_accted_amt_idx              NUMBER;
166211 l_acc_rev_flag                VARCHAR2(1);
166212 l_accrual_line_num            NUMBER;
166213 l_tmp_amt                     NUMBER;
166214 l_acc_rev_natural_side_code   VARCHAR2(1);
166215 
166216 l_num_entries                 NUMBER;
166217 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
166218 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
166219 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
166220 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
166221 l_recog_line_1                NUMBER;
166222 l_recog_line_2                NUMBER;
166223 
166224 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
166225 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
166226 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
166227 
166228 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
166229 
166230 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
166231 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
166232 
166233 ---------------------------------------------------------------------------------------------------------------
166234 
166235 
166236 --
166237 -- bulk performance
166238 --
166239 l_balance_type_code           VARCHAR2(1);
166240 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
166241 l_log_module                  VARCHAR2(240);
166242 
166243 --
166244 -- Upgrade strategy
166245 --
166246 l_actual_upg_option           VARCHAR2(1);
166247 l_enc_upg_option           VARCHAR2(1);
166248 
166249 --
166250 BEGIN
166251 --
166252 IF g_log_enabled THEN
166253       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_388';
166254 END IF;
166255 --
166256 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
166257 
166258       trace
166259          (p_msg      => 'BEGIN of AcctLineType_388'
166260          ,p_level    => C_LEVEL_PROCEDURE
166261          ,p_module   => l_log_module);
166262 
166263 END IF;
166264 --
166265 l_component_type             := 'AMB_JLT';
166266 l_component_code             := 'FA_UNITADJ_DEST_BONUS_EXP';
166267 l_component_type_code        := 'S';
166268 l_component_appl_id          :=  140;
166269 l_amb_context_code           := 'DEFAULT';
166270 l_entity_code                := 'TRANSACTIONS';
166271 l_event_class_code           := 'UNIT_ADJUSTMENTS';
166272 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
166273 l_line_definition_owner_code := 'S';
166274 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
166275 --
166276 l_balance_type_code          := 'A';
166277 l_segment                     := NULL;
166278 l_ccid                        := NULL;
166279 l_adr_transaction_coa_id      := NULL;
166280 l_adr_accounting_coa_id       := NULL;
166281 l_adr_flexfield_segment_code  := NULL;
166282 l_adr_flex_value_set_id       := NULL;
166283 l_adr_value_type_code         := NULL;
166284 l_adr_value_combination_id    := NULL;
166285 l_adr_value_segment_code      := NULL;
166286 
166287 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
166288 l_bflow_class_code           := '';    -- 4219869 Business Flow
166289 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
166290 l_budgetary_control_flag     := 'N';
166291 
166292 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
166293 l_bflow_applied_to_amt       := NULL; -- 5132302
166294 l_entered_amt_idx            := NULL;          -- 4262811
166295 l_accted_amt_idx             := NULL;          -- 4262811
166296 l_acc_rev_flag               := NULL;          -- 4262811
166297 l_accrual_line_num           := NULL;          -- 4262811
166298 l_tmp_amt                    := NULL;          -- 4262811
166299 --
166300  
166301 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
166302     l_balance_type_code <> 'B' THEN
166303 IF NVL(p_source_35,'
166304 ') =  'BONUS EXPENSE' AND 
166305 NVL(p_source_42,'
166306 ') =  'DEST'
166307  THEN 
166308 
166309    --
166310    XLA_AE_LINES_PKG.SetNewLine;
166311 
166312    p_balance_type_code          := l_balance_type_code;
166313    -- set the flag so later we will know whether the gain loss line needs to be created
166314    
166315    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
166316      p_actual_flag :='A';
166317    END IF;
166318 
166319    --
166320    -- bulk performance
166321    --
166322    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
166323                                       p_header_num   => 0); -- 4262811
166324    --
166325    -- set accounting line options
166326    --
166327    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
166328            p_natural_side_code          => 'D'
166329          , p_gain_or_loss_flag          => 'N'
166330          , p_gl_transfer_mode_code      => 'S'
166331          , p_acct_entry_type_code       => 'A'
166335    --
166332          , p_switch_side_flag           => 'Y'
166333          , p_merge_duplicate_code       => 'N'
166334          );
166336    l_acc_rev_natural_side_code := 'C';  -- 4262811
166337    -- 
166338    --
166339    -- set accounting line type info
166340    --
166341    xla_ae_lines_pkg.SetAcctLineType
166342       (p_component_type             => l_component_type
166343       ,p_event_type_code            => l_event_type_code
166344       ,p_line_definition_owner_code => l_line_definition_owner_code
166345       ,p_line_definition_code       => l_line_definition_code
166346       ,p_accounting_line_code       => l_component_code
166347       ,p_accounting_line_type_code  => l_component_type_code
166348       ,p_accounting_line_appl_id    => l_component_appl_id
166349       ,p_amb_context_code           => l_amb_context_code
166350       ,p_entity_code                => l_entity_code
166351       ,p_event_class_code           => l_event_class_code);
166352    --
166353    -- set accounting class
166354    --
166355    xla_ae_lines_pkg.SetAcctClass(
166356            p_accounting_class_code  => 'EXPENSE'
166357          , p_ae_header_id           => l_ae_header_id
166358          );
166359 
166360    --
166361    -- set rounding class
166362    --
166363    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
166364                       'EXPENSE';
166365 
166366    --
166367    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
166368    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
166369    --
166370    -- bulk performance
166371    --
166372    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
166373 
166374    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
166375       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
166376 
166377    -- 4955764
166378    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
166379       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
166380 
166381    -- 4458381 Public Sector Enh
166382    
166383    --
166384    -- set accounting attributes for the line type
166385    --
166386    l_entered_amt_idx := 4;
166387    l_accted_amt_idx  := 6;
166388    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
166389    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
166390    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
166391    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
166392    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
166393    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
166394    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
166395    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
166396    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
166397    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
166398    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
166399    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
166400    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
166401 
166402    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
166403    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
166404 
166405    ---------------------------------------------------------------------------------------------------------------
166406    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
166407    ---------------------------------------------------------------------------------------------------------------
166408    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
166409 
166410    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
166411    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
166412 
166413    IF xla_accounting_cache_pkg.GetValueChar
166414          (p_source_code         => 'LEDGER_CATEGORY_CODE'
166415          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
166416    AND l_bflow_method_code = 'PRIOR_ENTRY'
166417 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
166418    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
166419          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
166420        )
166421    THEN
166422          xla_ae_lines_pkg.BflowUpgEntry
166423            (p_business_method_code    => l_bflow_method_code
166424            ,p_business_class_code     => l_bflow_class_code
166425            ,p_balance_type            => l_balance_type_code);
166426    ELSE
166427       NULL;
166428 -- No business flow processing for business flow method of NONE.
166429    END IF;
166430 
166431    --
166432    -- call analytical criteria
166433    --
166434    
166435    --
166436    -- call description
166437    --
166438    
166439 xla_ae_lines_pkg.SetLineDescription(
166440    p_ae_header_id => l_ae_header_id
166441   ,p_description  => Description_139 (
166442      p_application_id         => p_application_id
166443    , p_ae_header_id           => l_ae_header_id 
166444 , p_source_1 => p_source_1
166445    )
166446 );
166447 
166448 
166449    --
166450    -- call ADRs
166451    -- Bug 4922099
166452    --
166453    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
166454         (NVL(l_actual_upg_option, 'N') = 'O') OR
166455         (NVL(l_enc_upg_option, 'N') = 'O')
166456       )
166457    THEN
166458    NULL;
166459    --
166460    --
166461    
166462   l_ccid := AcctDerRule_175(
166466 , p_source_29 => p_source_29
166463            p_application_id           => p_application_id
166464          , p_ae_header_id             => l_ae_header_id 
166465 , p_source_3 => p_source_3
166467          , x_transaction_coa_id       => l_adr_transaction_coa_id
166468          , x_accounting_coa_id        => l_adr_accounting_coa_id
166469          , x_value_type_code          => l_adr_value_type_code
166470          , p_side                     => 'NA'
166471    );
166472 
166473    xla_ae_lines_pkg.set_ccid(
166474     p_code_combination_id          => l_ccid
166475   , p_value_type_code              => l_adr_value_type_code
166476   , p_transaction_coa_id           => l_adr_transaction_coa_id
166477   , p_accounting_coa_id            => l_adr_accounting_coa_id
166478   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
166479   , p_adr_type_code                => 'S'
166480   , p_component_type               => l_component_type
166481   , p_component_code               => l_component_code
166482   , p_component_type_code          => l_component_type_code
166483   , p_component_appl_id            => l_component_appl_id
166484   , p_amb_context_code             => l_amb_context_code
166485   , p_side                         => 'NA'
166486   );
166487 
166488 
166489    l_segment := AcctDerRule_143(
166490            p_application_id           => p_application_id
166491          , p_ae_header_id             => l_ae_header_id 
166492 , p_source_2 => p_source_2
166493 , p_source_3 => p_source_3
166494          , x_transaction_coa_id       => l_adr_transaction_coa_id
166495          , x_accounting_coa_id        => l_adr_accounting_coa_id
166496          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
166497          , x_flex_value_set_id        => l_adr_flex_value_set_id
166498          , x_value_type_code          => l_adr_value_type_code
166499          , x_value_combination_id     => l_adr_value_combination_id
166500          , x_value_segment_code       => l_adr_value_segment_code
166501          , p_side                     => 'NA'
166502          , p_override_seg_flag        => 'Y'
166503    );
166504 
166505    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
166506 
166507       xla_ae_lines_pkg.set_segment(
166508           p_to_segment_code         => 'GL_ACCOUNT'
166509         , p_segment_value           => l_segment
166510         , p_from_segment_code       => l_adr_value_segment_code
166511         , p_from_combination_id     => l_adr_value_combination_id
166512         , p_value_type_code         => l_adr_value_type_code
166513         , p_transaction_coa_id      => l_adr_transaction_coa_id
166514         , p_accounting_coa_id       => l_adr_accounting_coa_id
166515         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
166516         , p_flex_value_set_id       => l_adr_flex_value_set_id
166517         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
166518         , p_adr_type_code           => 'S'
166519         , p_component_type          => l_component_type
166520         , p_component_code          => l_component_code
166521         , p_component_type_code     => l_component_type_code
166522         , p_component_appl_id       => l_component_appl_id
166523         , p_amb_context_code        => l_amb_context_code
166524         , p_entity_code             => 'TRANSACTIONS'
166525         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
166526         , p_side                    => 'NA'
166527         );
166528 
166529   END IF;
166530 
166531    --
166532    --
166533    END IF;
166534    --
166535    -- Bug 4922099
166536    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
166537           (NVL(l_enc_upg_option, 'N') = 'O')
166538         ) AND
166539         (l_bflow_method_code = 'PRIOR_ENTRY')
166540       )
166541    THEN
166542       IF
166543       --
166544       1 = 2
166545       --
166546       THEN
166547       xla_accounting_err_pkg.build_message
166548                                     (p_appli_s_name            => 'XLA'
166549                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
166550                                     ,p_token_1                 => 'LINE_NUMBER'
166551                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
166552                                     ,p_token_2                 => 'LINE_TYPE_NAME'
166553                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
166554                                                                              l_component_type
166555                                                                             ,l_component_code
166556                                                                             ,l_component_type_code
166557                                                                             ,l_component_appl_id
166558                                                                             ,l_amb_context_code
166559                                                                             ,l_entity_code
166560                                                                             ,l_event_class_code
166561                                                                            )
166562                                     ,p_token_3                 => 'OWNER'
166563                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
166564                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
166565                                                                           ,p_lookup_code    => l_component_type_code
166566                                                                          )
166567                                     ,p_token_4                 => 'PRODUCT_NAME'
166568                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
166569                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
166573                                        );
166570                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
166571                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
166572                                     ,p_ae_header_id            =>  NULL
166574 
166575         IF (C_LEVEL_ERROR>= g_log_level) THEN
166576                  trace
166577                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
166578                       ,p_level    => C_LEVEL_ERROR
166579                       ,p_module   => l_log_module);
166580         END IF;
166581       END IF;
166582    END IF;
166583    --
166584    --
166585    ------------------------------------------------------------------------------------------------
166586    -- 4219869 Business Flow
166587    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
166588    -- Prior Entry.  Currently, the following code is always generated.
166589    ------------------------------------------------------------------------------------------------
166590    XLA_AE_LINES_PKG.ValidateCurrentLine;
166591 
166592    ------------------------------------------------------------------------------------
166593    -- 4219869 Business Flow
166594    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
166595    ------------------------------------------------------------------------------------
166596    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
166597 
166598    ----------------------------------------------------------------------------------
166599    -- 4219869 Business Flow
166600    -- Update journal entry status -- Need to generate this within IF <condition>
166601    ----------------------------------------------------------------------------------
166602    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
166603          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
166604          ,p_balance_type_code => l_balance_type_code
166605          );
166606 
166607    -------------------------------------------------------------------------------------------
166608    -- 4262811 - Generate the Accrual Reversal lines
166609    -------------------------------------------------------------------------------------------
166610    BEGIN
166611       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
166612                               (g_array_event(p_event_id).array_value_num('header_index'));
166613       IF l_acc_rev_flag IS NULL THEN
166614          l_acc_rev_flag := 'N';
166615       END IF;
166616    EXCEPTION
166617       WHEN OTHERS THEN
166618          l_acc_rev_flag := 'N';
166619    END;
166620    --
166621    IF (l_acc_rev_flag = 'Y') THEN
166622 
166623        -- 4645092  ------------------------------------------------------------------------------
166624        -- To allow MPA report to determine if it should generate report process
166625        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
166626        ------------------------------------------------------------------------------------------
166627 
166628        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
166629        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
166630    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
166631    -- call ADRs
166632    -- Bug 4922099
166633    --
166634    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
166635         (NVL(l_actual_upg_option, 'N') = 'O') OR
166636         (NVL(l_enc_upg_option, 'N') = 'O')
166637       )
166638    THEN
166639    NULL;
166640    --
166641    --
166642    
166643   l_ccid := AcctDerRule_175(
166644            p_application_id           => p_application_id
166645          , p_ae_header_id             => l_ae_header_id 
166646 , p_source_3 => p_source_3
166647 , p_source_29 => p_source_29
166648          , x_transaction_coa_id       => l_adr_transaction_coa_id
166649          , x_accounting_coa_id        => l_adr_accounting_coa_id
166650          , x_value_type_code          => l_adr_value_type_code
166651          , p_side                     => 'NA'
166652    );
166653 
166654    xla_ae_lines_pkg.set_ccid(
166655     p_code_combination_id          => l_ccid
166656   , p_value_type_code              => l_adr_value_type_code
166657   , p_transaction_coa_id           => l_adr_transaction_coa_id
166658   , p_accounting_coa_id            => l_adr_accounting_coa_id
166659   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
166660   , p_adr_type_code                => 'S'
166661   , p_component_type               => l_component_type
166662   , p_component_code               => l_component_code
166663   , p_component_type_code          => l_component_type_code
166664   , p_component_appl_id            => l_component_appl_id
166665   , p_amb_context_code             => l_amb_context_code
166666   , p_side                         => 'NA'
166667   );
166668 
166669 
166670    l_segment := AcctDerRule_143(
166671            p_application_id           => p_application_id
166672          , p_ae_header_id             => l_ae_header_id 
166673 , p_source_2 => p_source_2
166674 , p_source_3 => p_source_3
166675          , x_transaction_coa_id       => l_adr_transaction_coa_id
166676          , x_accounting_coa_id        => l_adr_accounting_coa_id
166677          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
166678          , x_flex_value_set_id        => l_adr_flex_value_set_id
166679          , x_value_type_code          => l_adr_value_type_code
166680          , x_value_combination_id     => l_adr_value_combination_id
166681          , x_value_segment_code       => l_adr_value_segment_code
166682          , p_side                     => 'NA'
166683          , p_override_seg_flag        => 'Y'
166684    );
166685 
166686    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
166687 
166688       xla_ae_lines_pkg.set_segment(
166692         , p_from_combination_id     => l_adr_value_combination_id
166689           p_to_segment_code         => 'GL_ACCOUNT'
166690         , p_segment_value           => l_segment
166691         , p_from_segment_code       => l_adr_value_segment_code
166693         , p_value_type_code         => l_adr_value_type_code
166694         , p_transaction_coa_id      => l_adr_transaction_coa_id
166695         , p_accounting_coa_id       => l_adr_accounting_coa_id
166696         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
166697         , p_flex_value_set_id       => l_adr_flex_value_set_id
166698         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
166699         , p_adr_type_code           => 'S'
166700         , p_component_type          => l_component_type
166701         , p_component_code          => l_component_code
166702         , p_component_type_code     => l_component_type_code
166703         , p_component_appl_id       => l_component_appl_id
166704         , p_amb_context_code        => l_amb_context_code
166705         , p_entity_code             => 'TRANSACTIONS'
166706         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
166707         , p_side                    => 'NA'
166708         );
166709 
166710   END IF;
166711 
166712    --
166713    --
166714    END IF;
166715 
166716        --
166717        -- Update the line information that should be overwritten
166718        --
166719        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
166720                                          p_header_num   => 1);
166721        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
166722 
166723        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
166724 
166725        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
166726           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
166727        END IF;
166728 
166729       --
166730       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
166731       --
166732       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
166733           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
166734       ELSE
166735           ---------------------------------------------------------------------------------------------------
166736           -- 4262811a Switch Sign
166737           ---------------------------------------------------------------------------------------------------
166738           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
166739           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
166740                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
166741           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
166742                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
166743           -- 5132302
166744           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
166745                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
166746 
166747       END IF;
166748 
166749       -- 4955764
166750       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
166751       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
166752 
166753 
166754       XLA_AE_LINES_PKG.ValidateCurrentLine;
166755       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
166756 
166757       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
166758                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
166759                ,p_balance_type_code => l_balance_type_code);
166760 
166761    END IF;
166762 
166763    -----------------------------------------------------------------------------------------
166764    -- 4262811 Multiperiod Accounting
166765    -----------------------------------------------------------------------------------------
166766      -- No MPA option is assigned.
166767 
166768 
166769 END IF;
166770 END IF;
166771 --
166772 
166773 --
166774 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
166775    trace
166776       (p_msg      => 'END of AcctLineType_388'
166777       ,p_level    => C_LEVEL_PROCEDURE
166778       ,p_module   => l_log_module);
166779 END IF;
166780 --
166781 EXCEPTION
166782   WHEN xla_exceptions_pkg.application_exception THEN
166783       RAISE;
166784   WHEN OTHERS THEN
166785        xla_exceptions_pkg.raise_message
166786            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_388');
166787 END AcctLineType_388;
166788 --
166789 
166790 ---------------------------------------
166791 --
166792 -- PRIVATE FUNCTION
166793 --         AcctLineType_389
166794 --
166795 ---------------------------------------
166796 PROCEDURE AcctLineType_389 (
166797   p_application_id        IN NUMBER
166798  ,p_event_id              IN NUMBER
166799  ,p_calculate_acctd_flag  IN VARCHAR2
166800  ,p_calculate_g_l_flag    IN VARCHAR2
166801  ,p_actual_flag           IN OUT VARCHAR2
166802  ,p_balance_type_code     OUT VARCHAR2
166803  ,p_gain_or_loss_ref      OUT VARCHAR2
166804  
166805 --Period Close Date
166806  , p_source_1            IN DATE
166807 --Generated Code Combination Identifier
166808  , p_source_3            IN NUMBER
166809 --Bonus Reserve Account
166810  , p_source_4            IN VARCHAR2
166811 --Generated Offset Code Combination Identifier
166812  , p_source_17            IN NUMBER
166813 --Expense Account Code Combination Identifier
166814  , p_source_29            IN NUMBER
166815 --Default Code Combination Identifier
166819 --Transaction Header Identifier
166816  , p_source_30            IN NUMBER
166817 --Adjustment Type
166818  , p_source_35            IN VARCHAR2
166820  , p_source_36            IN NUMBER
166821 --Adjustment Line Identifier
166822  , p_source_37            IN NUMBER
166823 --Distribution Type Code
166824  , p_source_38            IN VARCHAR2
166825 --Entered Amount
166826  , p_source_39            IN NUMBER
166827 --Currency Code
166828  , p_source_40            IN VARCHAR2
166829 --Source Destination Code
166830  , p_source_42            IN VARCHAR2
166831 )
166832 IS
166833 
166834 l_component_type              VARCHAR2(80);
166835 l_component_code              VARCHAR2(30);
166836 l_component_type_code         VARCHAR2(1);
166837 l_component_appl_id           INTEGER;
166838 l_amb_context_code            VARCHAR2(30);
166839 l_entity_code                 VARCHAR2(30);
166840 l_event_class_code            VARCHAR2(30);
166841 l_ae_header_id                NUMBER;
166842 l_event_type_code             VARCHAR2(30);
166843 l_line_definition_code        VARCHAR2(30);
166844 l_line_definition_owner_code  VARCHAR2(1);
166845 --
166846 -- adr variables
166847 l_segment                     VARCHAR2(30);
166848 l_ccid                        NUMBER;
166849 l_adr_transaction_coa_id      NUMBER;
166850 l_adr_accounting_coa_id       NUMBER;
166851 l_adr_flexfield_segment_code  VARCHAR2(30);
166852 l_adr_flex_value_set_id       NUMBER;
166853 l_adr_value_type_code         VARCHAR2(30);
166854 l_adr_value_combination_id    NUMBER;
166855 l_adr_value_segment_code      VARCHAR2(30);
166856 
166857 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
166858 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
166859 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
166860 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
166861 
166862 -- 4262811 Variables ------------------------------------------------------------------------------------------
166863 l_entered_amt_idx             NUMBER;
166864 l_accted_amt_idx              NUMBER;
166865 l_acc_rev_flag                VARCHAR2(1);
166866 l_accrual_line_num            NUMBER;
166867 l_tmp_amt                     NUMBER;
166868 l_acc_rev_natural_side_code   VARCHAR2(1);
166869 
166870 l_num_entries                 NUMBER;
166871 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
166872 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
166873 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
166874 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
166875 l_recog_line_1                NUMBER;
166876 l_recog_line_2                NUMBER;
166877 
166878 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
166879 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
166880 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
166881 
166882 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
166883 
166884 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
166885 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
166886 
166887 ---------------------------------------------------------------------------------------------------------------
166888 
166889 
166890 --
166891 -- bulk performance
166892 --
166893 l_balance_type_code           VARCHAR2(1);
166894 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
166895 l_log_module                  VARCHAR2(240);
166896 
166897 --
166898 -- Upgrade strategy
166899 --
166900 l_actual_upg_option           VARCHAR2(1);
166901 l_enc_upg_option           VARCHAR2(1);
166902 
166903 --
166904 BEGIN
166905 --
166906 IF g_log_enabled THEN
166907       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_389';
166908 END IF;
166909 --
166910 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
166911 
166912       trace
166913          (p_msg      => 'BEGIN of AcctLineType_389'
166914          ,p_level    => C_LEVEL_PROCEDURE
166915          ,p_module   => l_log_module);
166916 
166917 END IF;
166918 --
166919 l_component_type             := 'AMB_JLT';
166920 l_component_code             := 'FA_UNITADJ_DEST_BONUS_RES';
166921 l_component_type_code        := 'S';
166922 l_component_appl_id          :=  140;
166923 l_amb_context_code           := 'DEFAULT';
166924 l_entity_code                := 'TRANSACTIONS';
166925 l_event_class_code           := 'UNIT_ADJUSTMENTS';
166926 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
166927 l_line_definition_owner_code := 'S';
166928 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
166929 --
166930 l_balance_type_code          := 'A';
166931 l_segment                     := NULL;
166932 l_ccid                        := NULL;
166933 l_adr_transaction_coa_id      := NULL;
166934 l_adr_accounting_coa_id       := NULL;
166935 l_adr_flexfield_segment_code  := NULL;
166936 l_adr_flex_value_set_id       := NULL;
166937 l_adr_value_type_code         := NULL;
166938 l_adr_value_combination_id    := NULL;
166939 l_adr_value_segment_code      := NULL;
166940 
166941 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
166942 l_bflow_class_code           := '';    -- 4219869 Business Flow
166943 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
166944 l_budgetary_control_flag     := 'N';
166945 
166946 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
166947 l_bflow_applied_to_amt       := NULL; -- 5132302
166948 l_entered_amt_idx            := NULL;          -- 4262811
166949 l_accted_amt_idx             := NULL;          -- 4262811
166950 l_acc_rev_flag               := NULL;          -- 4262811
166951 l_accrual_line_num           := NULL;          -- 4262811
166952 l_tmp_amt                    := NULL;          -- 4262811
166953 --
166957 IF (NVL(p_source_35,'
166954  
166955 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
166956     l_balance_type_code <> 'B' THEN
166958 ') =  'BONUS EXPENSE' OR 
166959 NVL(p_source_35,'
166960 ') =  'BONUS RESERVE') AND 
166961 NVL(p_source_42,'
166962 ') =  'DEST'
166963  THEN 
166964 
166965    --
166966    XLA_AE_LINES_PKG.SetNewLine;
166967 
166968    p_balance_type_code          := l_balance_type_code;
166969    -- set the flag so later we will know whether the gain loss line needs to be created
166970    
166971    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
166972      p_actual_flag :='A';
166973    END IF;
166974 
166975    --
166976    -- bulk performance
166977    --
166978    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
166979                                       p_header_num   => 0); -- 4262811
166980    --
166981    -- set accounting line options
166982    --
166983    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
166984            p_natural_side_code          => 'C'
166985          , p_gain_or_loss_flag          => 'N'
166986          , p_gl_transfer_mode_code      => 'S'
166987          , p_acct_entry_type_code       => 'A'
166988          , p_switch_side_flag           => 'Y'
166989          , p_merge_duplicate_code       => 'N'
166990          );
166991    --
166992    l_acc_rev_natural_side_code := 'D';  -- 4262811
166993    -- 
166994    --
166995    -- set accounting line type info
166996    --
166997    xla_ae_lines_pkg.SetAcctLineType
166998       (p_component_type             => l_component_type
166999       ,p_event_type_code            => l_event_type_code
167000       ,p_line_definition_owner_code => l_line_definition_owner_code
167001       ,p_line_definition_code       => l_line_definition_code
167002       ,p_accounting_line_code       => l_component_code
167003       ,p_accounting_line_type_code  => l_component_type_code
167004       ,p_accounting_line_appl_id    => l_component_appl_id
167005       ,p_amb_context_code           => l_amb_context_code
167006       ,p_entity_code                => l_entity_code
167007       ,p_event_class_code           => l_event_class_code);
167008    --
167009    -- set accounting class
167010    --
167011    xla_ae_lines_pkg.SetAcctClass(
167012            p_accounting_class_code  => 'ASSET'
167013          , p_ae_header_id           => l_ae_header_id
167014          );
167015 
167016    --
167017    -- set rounding class
167018    --
167019    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
167020                       'ASSET';
167021 
167022    --
167023    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
167024    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
167025    --
167026    -- bulk performance
167027    --
167028    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
167029 
167030    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
167031       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
167032 
167033    -- 4955764
167034    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
167035       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
167036 
167037    -- 4458381 Public Sector Enh
167038    
167039    --
167040    -- set accounting attributes for the line type
167041    --
167042    l_entered_amt_idx := 4;
167043    l_accted_amt_idx  := 6;
167044    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
167045    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
167046    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
167047    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
167048    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
167049    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
167050    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
167051    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
167052    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
167053    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
167054    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
167055    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
167056    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
167057 
167058    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
167059    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
167060 
167061    ---------------------------------------------------------------------------------------------------------------
167062    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
167063    ---------------------------------------------------------------------------------------------------------------
167064    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
167065 
167066    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
167067    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
167068 
167069    IF xla_accounting_cache_pkg.GetValueChar
167070          (p_source_code         => 'LEDGER_CATEGORY_CODE'
167071          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
167072    AND l_bflow_method_code = 'PRIOR_ENTRY'
167073 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
167074    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
167075          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
167076        )
167077    THEN
167078          xla_ae_lines_pkg.BflowUpgEntry
167082    ELSE
167079            (p_business_method_code    => l_bflow_method_code
167080            ,p_business_class_code     => l_bflow_class_code
167081            ,p_balance_type            => l_balance_type_code);
167083       NULL;
167084 -- No business flow processing for business flow method of NONE.
167085    END IF;
167086 
167087    --
167088    -- call analytical criteria
167089    --
167090    
167091    --
167092    -- call description
167093    --
167094    
167095 xla_ae_lines_pkg.SetLineDescription(
167096    p_ae_header_id => l_ae_header_id
167097   ,p_description  => Description_132 (
167098      p_application_id         => p_application_id
167099    , p_ae_header_id           => l_ae_header_id 
167100 , p_source_1 => p_source_1
167101    )
167102 );
167103 
167104 
167105    --
167106    -- call ADRs
167107    -- Bug 4922099
167108    --
167109    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
167110         (NVL(l_actual_upg_option, 'N') = 'O') OR
167111         (NVL(l_enc_upg_option, 'N') = 'O')
167112       )
167113    THEN
167114    NULL;
167115    --
167116    --
167117    
167118   l_ccid := AcctDerRule_174(
167119            p_application_id           => p_application_id
167120          , p_ae_header_id             => l_ae_header_id 
167121 , p_source_3 => p_source_3
167122 , p_source_17 => p_source_17
167123 , p_source_30 => p_source_30
167124          , x_transaction_coa_id       => l_adr_transaction_coa_id
167125          , x_accounting_coa_id        => l_adr_accounting_coa_id
167126          , x_value_type_code          => l_adr_value_type_code
167127          , p_side                     => 'NA'
167128    );
167129 
167130    xla_ae_lines_pkg.set_ccid(
167131     p_code_combination_id          => l_ccid
167132   , p_value_type_code              => l_adr_value_type_code
167133   , p_transaction_coa_id           => l_adr_transaction_coa_id
167134   , p_accounting_coa_id            => l_adr_accounting_coa_id
167135   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
167136   , p_adr_type_code                => 'S'
167137   , p_component_type               => l_component_type
167138   , p_component_code               => l_component_code
167139   , p_component_type_code          => l_component_type_code
167140   , p_component_appl_id            => l_component_appl_id
167141   , p_amb_context_code             => l_amb_context_code
167142   , p_side                         => 'NA'
167143   );
167144 
167145 
167146    l_segment := AcctDerRule_144(
167147            p_application_id           => p_application_id
167148          , p_ae_header_id             => l_ae_header_id 
167149 , p_source_3 => p_source_3
167150 , p_source_4 => p_source_4
167151          , x_transaction_coa_id       => l_adr_transaction_coa_id
167152          , x_accounting_coa_id        => l_adr_accounting_coa_id
167153          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
167154          , x_flex_value_set_id        => l_adr_flex_value_set_id
167155          , x_value_type_code          => l_adr_value_type_code
167156          , x_value_combination_id     => l_adr_value_combination_id
167157          , x_value_segment_code       => l_adr_value_segment_code
167158          , p_side                     => 'NA'
167159          , p_override_seg_flag        => 'Y'
167160    );
167161 
167162    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
167163 
167164       xla_ae_lines_pkg.set_segment(
167165           p_to_segment_code         => 'GL_ACCOUNT'
167166         , p_segment_value           => l_segment
167167         , p_from_segment_code       => l_adr_value_segment_code
167168         , p_from_combination_id     => l_adr_value_combination_id
167169         , p_value_type_code         => l_adr_value_type_code
167170         , p_transaction_coa_id      => l_adr_transaction_coa_id
167171         , p_accounting_coa_id       => l_adr_accounting_coa_id
167172         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
167173         , p_flex_value_set_id       => l_adr_flex_value_set_id
167174         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
167175         , p_adr_type_code           => 'S'
167176         , p_component_type          => l_component_type
167177         , p_component_code          => l_component_code
167178         , p_component_type_code     => l_component_type_code
167179         , p_component_appl_id       => l_component_appl_id
167180         , p_amb_context_code        => l_amb_context_code
167181         , p_entity_code             => 'TRANSACTIONS'
167182         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
167183         , p_side                    => 'NA'
167184         );
167185 
167186   END IF;
167187 
167188    l_segment := AcctDerRule_168(
167189            p_application_id           => p_application_id
167190          , p_ae_header_id             => l_ae_header_id 
167191 , p_source_3 => p_source_3
167192 , p_source_29 => p_source_29
167193          , x_transaction_coa_id       => l_adr_transaction_coa_id
167194          , x_accounting_coa_id        => l_adr_accounting_coa_id
167195          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
167196          , x_flex_value_set_id        => l_adr_flex_value_set_id
167197          , x_value_type_code          => l_adr_value_type_code
167198          , x_value_combination_id     => l_adr_value_combination_id
167199          , x_value_segment_code       => l_adr_value_segment_code
167200          , p_side                     => 'NA'
167201          , p_override_seg_flag        => 'Y'
167202    );
167203 
167204    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
167205 
167206       xla_ae_lines_pkg.set_segment(
167207           p_to_segment_code         => 'GL_BALANCING'
167208         , p_segment_value           => l_segment
167209         , p_from_segment_code       => l_adr_value_segment_code
167210         , p_from_combination_id     => l_adr_value_combination_id
167214         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
167211         , p_value_type_code         => l_adr_value_type_code
167212         , p_transaction_coa_id      => l_adr_transaction_coa_id
167213         , p_accounting_coa_id       => l_adr_accounting_coa_id
167215         , p_flex_value_set_id       => l_adr_flex_value_set_id
167216         , p_adr_code                => 'FA_EXPENSE_ACCT'
167217         , p_adr_type_code           => 'S'
167218         , p_component_type          => l_component_type
167219         , p_component_code          => l_component_code
167220         , p_component_type_code     => l_component_type_code
167221         , p_component_appl_id       => l_component_appl_id
167222         , p_amb_context_code        => l_amb_context_code
167223         , p_entity_code             => 'TRANSACTIONS'
167224         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
167225         , p_side                    => 'NA'
167226         );
167227 
167228   END IF;
167229 
167230    --
167231    --
167232    END IF;
167233    --
167234    -- Bug 4922099
167235    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
167236           (NVL(l_enc_upg_option, 'N') = 'O')
167237         ) AND
167238         (l_bflow_method_code = 'PRIOR_ENTRY')
167239       )
167240    THEN
167241       IF
167242       --
167243       1 = 2
167244       --
167245       THEN
167246       xla_accounting_err_pkg.build_message
167247                                     (p_appli_s_name            => 'XLA'
167248                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
167249                                     ,p_token_1                 => 'LINE_NUMBER'
167250                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
167251                                     ,p_token_2                 => 'LINE_TYPE_NAME'
167252                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
167253                                                                              l_component_type
167254                                                                             ,l_component_code
167255                                                                             ,l_component_type_code
167256                                                                             ,l_component_appl_id
167257                                                                             ,l_amb_context_code
167258                                                                             ,l_entity_code
167259                                                                             ,l_event_class_code
167260                                                                            )
167261                                     ,p_token_3                 => 'OWNER'
167262                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
167263                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
167264                                                                           ,p_lookup_code    => l_component_type_code
167265                                                                          )
167266                                     ,p_token_4                 => 'PRODUCT_NAME'
167267                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
167268                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
167269                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
167270                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
167271                                     ,p_ae_header_id            =>  NULL
167272                                        );
167273 
167274         IF (C_LEVEL_ERROR>= g_log_level) THEN
167275                  trace
167276                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
167277                       ,p_level    => C_LEVEL_ERROR
167278                       ,p_module   => l_log_module);
167279         END IF;
167280       END IF;
167281    END IF;
167282    --
167283    --
167284    ------------------------------------------------------------------------------------------------
167285    -- 4219869 Business Flow
167286    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
167287    -- Prior Entry.  Currently, the following code is always generated.
167288    ------------------------------------------------------------------------------------------------
167289    XLA_AE_LINES_PKG.ValidateCurrentLine;
167290 
167291    ------------------------------------------------------------------------------------
167292    -- 4219869 Business Flow
167293    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
167294    ------------------------------------------------------------------------------------
167295    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
167296 
167297    ----------------------------------------------------------------------------------
167298    -- 4219869 Business Flow
167299    -- Update journal entry status -- Need to generate this within IF <condition>
167300    ----------------------------------------------------------------------------------
167301    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
167302          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
167303          ,p_balance_type_code => l_balance_type_code
167304          );
167305 
167306    -------------------------------------------------------------------------------------------
167307    -- 4262811 - Generate the Accrual Reversal lines
167308    -------------------------------------------------------------------------------------------
167309    BEGIN
167310       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
167311                               (g_array_event(p_event_id).array_value_num('header_index'));
167312       IF l_acc_rev_flag IS NULL THEN
167316       WHEN OTHERS THEN
167313          l_acc_rev_flag := 'N';
167314       END IF;
167315    EXCEPTION
167317          l_acc_rev_flag := 'N';
167318    END;
167319    --
167320    IF (l_acc_rev_flag = 'Y') THEN
167321 
167322        -- 4645092  ------------------------------------------------------------------------------
167323        -- To allow MPA report to determine if it should generate report process
167324        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
167325        ------------------------------------------------------------------------------------------
167326 
167327        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
167328        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
167329    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
167330    -- call ADRs
167331    -- Bug 4922099
167332    --
167333    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
167334         (NVL(l_actual_upg_option, 'N') = 'O') OR
167335         (NVL(l_enc_upg_option, 'N') = 'O')
167336       )
167337    THEN
167338    NULL;
167339    --
167340    --
167341    
167342   l_ccid := AcctDerRule_174(
167343            p_application_id           => p_application_id
167344          , p_ae_header_id             => l_ae_header_id 
167345 , p_source_3 => p_source_3
167346 , p_source_17 => p_source_17
167347 , p_source_30 => p_source_30
167348          , x_transaction_coa_id       => l_adr_transaction_coa_id
167349          , x_accounting_coa_id        => l_adr_accounting_coa_id
167350          , x_value_type_code          => l_adr_value_type_code
167351          , p_side                     => 'NA'
167352    );
167353 
167354    xla_ae_lines_pkg.set_ccid(
167355     p_code_combination_id          => l_ccid
167356   , p_value_type_code              => l_adr_value_type_code
167357   , p_transaction_coa_id           => l_adr_transaction_coa_id
167358   , p_accounting_coa_id            => l_adr_accounting_coa_id
167359   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
167360   , p_adr_type_code                => 'S'
167361   , p_component_type               => l_component_type
167362   , p_component_code               => l_component_code
167363   , p_component_type_code          => l_component_type_code
167364   , p_component_appl_id            => l_component_appl_id
167365   , p_amb_context_code             => l_amb_context_code
167366   , p_side                         => 'NA'
167367   );
167368 
167369 
167370    l_segment := AcctDerRule_144(
167371            p_application_id           => p_application_id
167372          , p_ae_header_id             => l_ae_header_id 
167373 , p_source_3 => p_source_3
167374 , p_source_4 => p_source_4
167375          , x_transaction_coa_id       => l_adr_transaction_coa_id
167376          , x_accounting_coa_id        => l_adr_accounting_coa_id
167377          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
167378          , x_flex_value_set_id        => l_adr_flex_value_set_id
167379          , x_value_type_code          => l_adr_value_type_code
167380          , x_value_combination_id     => l_adr_value_combination_id
167381          , x_value_segment_code       => l_adr_value_segment_code
167382          , p_side                     => 'NA'
167383          , p_override_seg_flag        => 'Y'
167384    );
167385 
167386    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
167387 
167388       xla_ae_lines_pkg.set_segment(
167389           p_to_segment_code         => 'GL_ACCOUNT'
167390         , p_segment_value           => l_segment
167391         , p_from_segment_code       => l_adr_value_segment_code
167392         , p_from_combination_id     => l_adr_value_combination_id
167393         , p_value_type_code         => l_adr_value_type_code
167394         , p_transaction_coa_id      => l_adr_transaction_coa_id
167395         , p_accounting_coa_id       => l_adr_accounting_coa_id
167396         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
167397         , p_flex_value_set_id       => l_adr_flex_value_set_id
167398         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
167399         , p_adr_type_code           => 'S'
167400         , p_component_type          => l_component_type
167401         , p_component_code          => l_component_code
167402         , p_component_type_code     => l_component_type_code
167403         , p_component_appl_id       => l_component_appl_id
167404         , p_amb_context_code        => l_amb_context_code
167405         , p_entity_code             => 'TRANSACTIONS'
167406         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
167407         , p_side                    => 'NA'
167408         );
167409 
167410   END IF;
167411 
167412    l_segment := AcctDerRule_168(
167413            p_application_id           => p_application_id
167414          , p_ae_header_id             => l_ae_header_id 
167415 , p_source_3 => p_source_3
167416 , p_source_29 => p_source_29
167417          , x_transaction_coa_id       => l_adr_transaction_coa_id
167418          , x_accounting_coa_id        => l_adr_accounting_coa_id
167419          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
167420          , x_flex_value_set_id        => l_adr_flex_value_set_id
167421          , x_value_type_code          => l_adr_value_type_code
167422          , x_value_combination_id     => l_adr_value_combination_id
167423          , x_value_segment_code       => l_adr_value_segment_code
167424          , p_side                     => 'NA'
167425          , p_override_seg_flag        => 'Y'
167426    );
167427 
167428    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
167429 
167430       xla_ae_lines_pkg.set_segment(
167431           p_to_segment_code         => 'GL_BALANCING'
167432         , p_segment_value           => l_segment
167433         , p_from_segment_code       => l_adr_value_segment_code
167434         , p_from_combination_id     => l_adr_value_combination_id
167435         , p_value_type_code         => l_adr_value_type_code
167439         , p_flex_value_set_id       => l_adr_flex_value_set_id
167436         , p_transaction_coa_id      => l_adr_transaction_coa_id
167437         , p_accounting_coa_id       => l_adr_accounting_coa_id
167438         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
167440         , p_adr_code                => 'FA_EXPENSE_ACCT'
167441         , p_adr_type_code           => 'S'
167442         , p_component_type          => l_component_type
167443         , p_component_code          => l_component_code
167444         , p_component_type_code     => l_component_type_code
167445         , p_component_appl_id       => l_component_appl_id
167446         , p_amb_context_code        => l_amb_context_code
167447         , p_entity_code             => 'TRANSACTIONS'
167448         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
167449         , p_side                    => 'NA'
167450         );
167451 
167452   END IF;
167453 
167454    --
167455    --
167456    END IF;
167457 
167458        --
167459        -- Update the line information that should be overwritten
167460        --
167461        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
167462                                          p_header_num   => 1);
167463        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
167464 
167465        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
167466 
167467        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
167468           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
167469        END IF;
167470 
167471       --
167472       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
167473       --
167474       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
167475           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
167476       ELSE
167477           ---------------------------------------------------------------------------------------------------
167478           -- 4262811a Switch Sign
167479           ---------------------------------------------------------------------------------------------------
167480           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
167481           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
167482                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
167483           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
167484                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
167485           -- 5132302
167486           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
167487                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
167488 
167489       END IF;
167490 
167491       -- 4955764
167492       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
167493       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
167494 
167495 
167496       XLA_AE_LINES_PKG.ValidateCurrentLine;
167497       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
167498 
167499       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
167500                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
167501                ,p_balance_type_code => l_balance_type_code);
167502 
167503    END IF;
167504 
167505    -----------------------------------------------------------------------------------------
167506    -- 4262811 Multiperiod Accounting
167507    -----------------------------------------------------------------------------------------
167508      -- No MPA option is assigned.
167509 
167510 
167511 END IF;
167512 END IF;
167513 --
167514 
167515 --
167516 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
167517    trace
167518       (p_msg      => 'END of AcctLineType_389'
167519       ,p_level    => C_LEVEL_PROCEDURE
167520       ,p_module   => l_log_module);
167521 END IF;
167522 --
167523 EXCEPTION
167524   WHEN xla_exceptions_pkg.application_exception THEN
167525       RAISE;
167526   WHEN OTHERS THEN
167527        xla_exceptions_pkg.raise_message
167528            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_389');
167529 END AcctLineType_389;
167530 --
167531 
167532 ---------------------------------------
167533 --
167534 -- PRIVATE FUNCTION
167535 --         AcctLineType_390
167536 --
167537 ---------------------------------------
167538 PROCEDURE AcctLineType_390 (
167539   p_application_id        IN NUMBER
167540  ,p_event_id              IN NUMBER
167541  ,p_calculate_acctd_flag  IN VARCHAR2
167542  ,p_calculate_g_l_flag    IN VARCHAR2
167543  ,p_actual_flag           IN OUT VARCHAR2
167544  ,p_balance_type_code     OUT VARCHAR2
167545  ,p_gain_or_loss_ref      OUT VARCHAR2
167546  
167547 --Period Close Date
167548  , p_source_1            IN DATE
167549 --Generated Code Combination Identifier
167550  , p_source_3            IN NUMBER
167551 --Expense Account Code Combination Identifier
167552  , p_source_29            IN NUMBER
167553 --Adjustment Type
167554  , p_source_35            IN VARCHAR2
167555 --Transaction Header Identifier
167556  , p_source_36            IN NUMBER
167557 --Adjustment Line Identifier
167558  , p_source_37            IN NUMBER
167559 --Distribution Type Code
167560  , p_source_38            IN VARCHAR2
167561 --Entered Amount
167562  , p_source_39            IN NUMBER
167563 --Currency Code
167564  , p_source_40            IN VARCHAR2
167565 --Source Destination Code
167566  , p_source_42            IN VARCHAR2
167567 )
167571 l_component_code              VARCHAR2(30);
167568 IS
167569 
167570 l_component_type              VARCHAR2(80);
167572 l_component_type_code         VARCHAR2(1);
167573 l_component_appl_id           INTEGER;
167574 l_amb_context_code            VARCHAR2(30);
167575 l_entity_code                 VARCHAR2(30);
167576 l_event_class_code            VARCHAR2(30);
167577 l_ae_header_id                NUMBER;
167578 l_event_type_code             VARCHAR2(30);
167579 l_line_definition_code        VARCHAR2(30);
167580 l_line_definition_owner_code  VARCHAR2(1);
167581 --
167582 -- adr variables
167583 l_segment                     VARCHAR2(30);
167584 l_ccid                        NUMBER;
167585 l_adr_transaction_coa_id      NUMBER;
167586 l_adr_accounting_coa_id       NUMBER;
167587 l_adr_flexfield_segment_code  VARCHAR2(30);
167588 l_adr_flex_value_set_id       NUMBER;
167589 l_adr_value_type_code         VARCHAR2(30);
167590 l_adr_value_combination_id    NUMBER;
167591 l_adr_value_segment_code      VARCHAR2(30);
167592 
167593 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
167594 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
167595 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
167596 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
167597 
167598 -- 4262811 Variables ------------------------------------------------------------------------------------------
167599 l_entered_amt_idx             NUMBER;
167600 l_accted_amt_idx              NUMBER;
167601 l_acc_rev_flag                VARCHAR2(1);
167602 l_accrual_line_num            NUMBER;
167603 l_tmp_amt                     NUMBER;
167604 l_acc_rev_natural_side_code   VARCHAR2(1);
167605 
167606 l_num_entries                 NUMBER;
167607 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
167608 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
167609 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
167610 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
167611 l_recog_line_1                NUMBER;
167612 l_recog_line_2                NUMBER;
167613 
167614 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
167615 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
167616 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
167617 
167618 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
167619 
167620 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
167621 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
167622 
167623 ---------------------------------------------------------------------------------------------------------------
167624 
167625 
167626 --
167627 -- bulk performance
167628 --
167629 l_balance_type_code           VARCHAR2(1);
167630 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
167631 l_log_module                  VARCHAR2(240);
167632 
167633 --
167634 -- Upgrade strategy
167635 --
167636 l_actual_upg_option           VARCHAR2(1);
167637 l_enc_upg_option           VARCHAR2(1);
167638 
167639 --
167640 BEGIN
167641 --
167642 IF g_log_enabled THEN
167643       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_390';
167644 END IF;
167645 --
167646 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
167647 
167648       trace
167649          (p_msg      => 'BEGIN of AcctLineType_390'
167650          ,p_level    => C_LEVEL_PROCEDURE
167651          ,p_module   => l_log_module);
167652 
167653 END IF;
167654 --
167655 l_component_type             := 'AMB_JLT';
167656 l_component_code             := 'FA_UNITADJ_DEST_DEPRN_EXP';
167657 l_component_type_code        := 'S';
167658 l_component_appl_id          :=  140;
167659 l_amb_context_code           := 'DEFAULT';
167660 l_entity_code                := 'TRANSACTIONS';
167661 l_event_class_code           := 'UNIT_ADJUSTMENTS';
167662 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
167663 l_line_definition_owner_code := 'S';
167664 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
167665 --
167666 l_balance_type_code          := 'A';
167667 l_segment                     := NULL;
167668 l_ccid                        := NULL;
167669 l_adr_transaction_coa_id      := NULL;
167670 l_adr_accounting_coa_id       := NULL;
167671 l_adr_flexfield_segment_code  := NULL;
167672 l_adr_flex_value_set_id       := NULL;
167673 l_adr_value_type_code         := NULL;
167674 l_adr_value_combination_id    := NULL;
167675 l_adr_value_segment_code      := NULL;
167676 
167677 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
167678 l_bflow_class_code           := '';    -- 4219869 Business Flow
167679 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
167680 l_budgetary_control_flag     := 'N';
167681 
167682 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
167683 l_bflow_applied_to_amt       := NULL; -- 5132302
167684 l_entered_amt_idx            := NULL;          -- 4262811
167685 l_accted_amt_idx             := NULL;          -- 4262811
167686 l_acc_rev_flag               := NULL;          -- 4262811
167687 l_accrual_line_num           := NULL;          -- 4262811
167688 l_tmp_amt                    := NULL;          -- 4262811
167689 --
167690  
167691 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
167692     l_balance_type_code <> 'B' THEN
167693 IF NVL(p_source_35,'
167694 ') =  'EXPENSE' AND 
167695 NVL(p_source_42,'
167696 ') =  'DEST'
167697  THEN 
167698 
167699    --
167700    XLA_AE_LINES_PKG.SetNewLine;
167701 
167702    p_balance_type_code          := l_balance_type_code;
167703    -- set the flag so later we will know whether the gain loss line needs to be created
167704    
167708 
167705    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
167706      p_actual_flag :='A';
167707    END IF;
167709    --
167710    -- bulk performance
167711    --
167712    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
167713                                       p_header_num   => 0); -- 4262811
167714    --
167715    -- set accounting line options
167716    --
167717    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
167718            p_natural_side_code          => 'D'
167719          , p_gain_or_loss_flag          => 'N'
167720          , p_gl_transfer_mode_code      => 'S'
167721          , p_acct_entry_type_code       => 'A'
167722          , p_switch_side_flag           => 'Y'
167723          , p_merge_duplicate_code       => 'N'
167724          );
167725    --
167726    l_acc_rev_natural_side_code := 'C';  -- 4262811
167727    -- 
167728    --
167729    -- set accounting line type info
167730    --
167731    xla_ae_lines_pkg.SetAcctLineType
167732       (p_component_type             => l_component_type
167733       ,p_event_type_code            => l_event_type_code
167734       ,p_line_definition_owner_code => l_line_definition_owner_code
167735       ,p_line_definition_code       => l_line_definition_code
167736       ,p_accounting_line_code       => l_component_code
167737       ,p_accounting_line_type_code  => l_component_type_code
167738       ,p_accounting_line_appl_id    => l_component_appl_id
167739       ,p_amb_context_code           => l_amb_context_code
167740       ,p_entity_code                => l_entity_code
167741       ,p_event_class_code           => l_event_class_code);
167742    --
167743    -- set accounting class
167744    --
167745    xla_ae_lines_pkg.SetAcctClass(
167746            p_accounting_class_code  => 'EXPENSE'
167747          , p_ae_header_id           => l_ae_header_id
167748          );
167749 
167750    --
167751    -- set rounding class
167752    --
167753    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
167754                       'EXPENSE';
167755 
167756    --
167757    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
167758    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
167759    --
167760    -- bulk performance
167761    --
167762    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
167763 
167764    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
167765       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
167766 
167767    -- 4955764
167768    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
167769       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
167770 
167771    -- 4458381 Public Sector Enh
167772    
167773    --
167774    -- set accounting attributes for the line type
167775    --
167776    l_entered_amt_idx := 4;
167777    l_accted_amt_idx  := 6;
167778    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
167779    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
167780    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
167781    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
167782    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
167783    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
167784    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
167785    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
167786    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
167787    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
167788    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
167789    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
167790    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
167791 
167792    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
167793    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
167794 
167795    ---------------------------------------------------------------------------------------------------------------
167796    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
167797    ---------------------------------------------------------------------------------------------------------------
167798    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
167799 
167800    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
167801    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
167802 
167803    IF xla_accounting_cache_pkg.GetValueChar
167804          (p_source_code         => 'LEDGER_CATEGORY_CODE'
167805          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
167806    AND l_bflow_method_code = 'PRIOR_ENTRY'
167807 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
167808    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
167809          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
167810        )
167811    THEN
167812          xla_ae_lines_pkg.BflowUpgEntry
167813            (p_business_method_code    => l_bflow_method_code
167814            ,p_business_class_code     => l_bflow_class_code
167815            ,p_balance_type            => l_balance_type_code);
167816    ELSE
167817       NULL;
167818 -- No business flow processing for business flow method of NONE.
167819    END IF;
167820 
167821    --
167822    -- call analytical criteria
167823    --
167824    
167825    --
167826    -- call description
167827    --
167828    
167829 xla_ae_lines_pkg.SetLineDescription(
167830    p_ae_header_id => l_ae_header_id
167834 , p_source_1 => p_source_1
167831   ,p_description  => Description_134 (
167832      p_application_id         => p_application_id
167833    , p_ae_header_id           => l_ae_header_id 
167835    )
167836 );
167837 
167838 
167839    --
167840    -- call ADRs
167841    -- Bug 4922099
167842    --
167843    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
167844         (NVL(l_actual_upg_option, 'N') = 'O') OR
167845         (NVL(l_enc_upg_option, 'N') = 'O')
167846       )
167847    THEN
167848    NULL;
167849    --
167850    --
167851    
167852   l_ccid := AcctDerRule_175(
167853            p_application_id           => p_application_id
167854          , p_ae_header_id             => l_ae_header_id 
167855 , p_source_3 => p_source_3
167856 , p_source_29 => p_source_29
167857          , x_transaction_coa_id       => l_adr_transaction_coa_id
167858          , x_accounting_coa_id        => l_adr_accounting_coa_id
167859          , x_value_type_code          => l_adr_value_type_code
167860          , p_side                     => 'NA'
167861    );
167862 
167863    xla_ae_lines_pkg.set_ccid(
167864     p_code_combination_id          => l_ccid
167865   , p_value_type_code              => l_adr_value_type_code
167866   , p_transaction_coa_id           => l_adr_transaction_coa_id
167867   , p_accounting_coa_id            => l_adr_accounting_coa_id
167868   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
167869   , p_adr_type_code                => 'S'
167870   , p_component_type               => l_component_type
167871   , p_component_code               => l_component_code
167872   , p_component_type_code          => l_component_type_code
167873   , p_component_appl_id            => l_component_appl_id
167874   , p_amb_context_code             => l_amb_context_code
167875   , p_side                         => 'NA'
167876   );
167877 
167878 
167879    --
167880    --
167881    END IF;
167882    --
167883    -- Bug 4922099
167884    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
167885           (NVL(l_enc_upg_option, 'N') = 'O')
167886         ) AND
167887         (l_bflow_method_code = 'PRIOR_ENTRY')
167888       )
167889    THEN
167890       IF
167891       --
167892       1 = 2
167893       --
167894       THEN
167895       xla_accounting_err_pkg.build_message
167896                                     (p_appli_s_name            => 'XLA'
167897                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
167898                                     ,p_token_1                 => 'LINE_NUMBER'
167899                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
167900                                     ,p_token_2                 => 'LINE_TYPE_NAME'
167901                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
167902                                                                              l_component_type
167903                                                                             ,l_component_code
167904                                                                             ,l_component_type_code
167905                                                                             ,l_component_appl_id
167906                                                                             ,l_amb_context_code
167907                                                                             ,l_entity_code
167908                                                                             ,l_event_class_code
167909                                                                            )
167910                                     ,p_token_3                 => 'OWNER'
167911                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
167912                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
167913                                                                           ,p_lookup_code    => l_component_type_code
167914                                                                          )
167915                                     ,p_token_4                 => 'PRODUCT_NAME'
167916                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
167917                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
167918                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
167919                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
167920                                     ,p_ae_header_id            =>  NULL
167921                                        );
167922 
167923         IF (C_LEVEL_ERROR>= g_log_level) THEN
167924                  trace
167925                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
167926                       ,p_level    => C_LEVEL_ERROR
167927                       ,p_module   => l_log_module);
167928         END IF;
167929       END IF;
167930    END IF;
167931    --
167932    --
167933    ------------------------------------------------------------------------------------------------
167934    -- 4219869 Business Flow
167935    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
167936    -- Prior Entry.  Currently, the following code is always generated.
167937    ------------------------------------------------------------------------------------------------
167938    XLA_AE_LINES_PKG.ValidateCurrentLine;
167939 
167940    ------------------------------------------------------------------------------------
167941    -- 4219869 Business Flow
167942    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
167943    ------------------------------------------------------------------------------------
167944    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
167945 
167949    ----------------------------------------------------------------------------------
167946    ----------------------------------------------------------------------------------
167947    -- 4219869 Business Flow
167948    -- Update journal entry status -- Need to generate this within IF <condition>
167950    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
167951          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
167952          ,p_balance_type_code => l_balance_type_code
167953          );
167954 
167955    -------------------------------------------------------------------------------------------
167956    -- 4262811 - Generate the Accrual Reversal lines
167957    -------------------------------------------------------------------------------------------
167958    BEGIN
167959       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
167960                               (g_array_event(p_event_id).array_value_num('header_index'));
167961       IF l_acc_rev_flag IS NULL THEN
167962          l_acc_rev_flag := 'N';
167963       END IF;
167964    EXCEPTION
167965       WHEN OTHERS THEN
167966          l_acc_rev_flag := 'N';
167967    END;
167968    --
167969    IF (l_acc_rev_flag = 'Y') THEN
167970 
167971        -- 4645092  ------------------------------------------------------------------------------
167972        -- To allow MPA report to determine if it should generate report process
167973        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
167974        ------------------------------------------------------------------------------------------
167975 
167976        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
167977        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
167978    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
167979    -- call ADRs
167980    -- Bug 4922099
167981    --
167982    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
167983         (NVL(l_actual_upg_option, 'N') = 'O') OR
167984         (NVL(l_enc_upg_option, 'N') = 'O')
167985       )
167986    THEN
167987    NULL;
167988    --
167989    --
167990    
167991   l_ccid := AcctDerRule_175(
167992            p_application_id           => p_application_id
167993          , p_ae_header_id             => l_ae_header_id 
167994 , p_source_3 => p_source_3
167995 , p_source_29 => p_source_29
167996          , x_transaction_coa_id       => l_adr_transaction_coa_id
167997          , x_accounting_coa_id        => l_adr_accounting_coa_id
167998          , x_value_type_code          => l_adr_value_type_code
167999          , p_side                     => 'NA'
168000    );
168001 
168002    xla_ae_lines_pkg.set_ccid(
168003     p_code_combination_id          => l_ccid
168004   , p_value_type_code              => l_adr_value_type_code
168005   , p_transaction_coa_id           => l_adr_transaction_coa_id
168006   , p_accounting_coa_id            => l_adr_accounting_coa_id
168007   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
168008   , p_adr_type_code                => 'S'
168009   , p_component_type               => l_component_type
168010   , p_component_code               => l_component_code
168011   , p_component_type_code          => l_component_type_code
168012   , p_component_appl_id            => l_component_appl_id
168013   , p_amb_context_code             => l_amb_context_code
168014   , p_side                         => 'NA'
168015   );
168016 
168017 
168018    --
168019    --
168020    END IF;
168021 
168022        --
168023        -- Update the line information that should be overwritten
168024        --
168025        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
168026                                          p_header_num   => 1);
168027        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
168028 
168029        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
168030 
168031        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
168032           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
168033        END IF;
168034 
168035       --
168036       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
168037       --
168038       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
168039           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
168040       ELSE
168041           ---------------------------------------------------------------------------------------------------
168042           -- 4262811a Switch Sign
168043           ---------------------------------------------------------------------------------------------------
168044           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
168045           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
168046                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
168047           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
168048                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
168049           -- 5132302
168050           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
168051                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
168052 
168053       END IF;
168054 
168055       -- 4955764
168056       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
168057       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
168058 
168059 
168060       XLA_AE_LINES_PKG.ValidateCurrentLine;
168061       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
168062 
168066 
168063       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
168064                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
168065                ,p_balance_type_code => l_balance_type_code);
168067    END IF;
168068 
168069    -----------------------------------------------------------------------------------------
168070    -- 4262811 Multiperiod Accounting
168071    -----------------------------------------------------------------------------------------
168072      -- No MPA option is assigned.
168073 
168074 
168075 END IF;
168076 END IF;
168077 --
168078 
168079 --
168080 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
168081    trace
168082       (p_msg      => 'END of AcctLineType_390'
168083       ,p_level    => C_LEVEL_PROCEDURE
168084       ,p_module   => l_log_module);
168085 END IF;
168086 --
168087 EXCEPTION
168088   WHEN xla_exceptions_pkg.application_exception THEN
168089       RAISE;
168090   WHEN OTHERS THEN
168091        xla_exceptions_pkg.raise_message
168092            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_390');
168093 END AcctLineType_390;
168094 --
168095 
168096 ---------------------------------------
168097 --
168098 -- PRIVATE FUNCTION
168099 --         AcctLineType_391
168100 --
168101 ---------------------------------------
168102 PROCEDURE AcctLineType_391 (
168103   p_application_id        IN NUMBER
168104  ,p_event_id              IN NUMBER
168105  ,p_calculate_acctd_flag  IN VARCHAR2
168106  ,p_calculate_g_l_flag    IN VARCHAR2
168107  ,p_actual_flag           IN OUT VARCHAR2
168108  ,p_balance_type_code     OUT VARCHAR2
168109  ,p_gain_or_loss_ref      OUT VARCHAR2
168110  
168111 --Period Close Date
168112  , p_source_1            IN DATE
168113 --Generated Code Combination Identifier
168114  , p_source_3            IN NUMBER
168115 --Depreciation Reserve Account
168116  , p_source_10            IN VARCHAR2
168117 --Generated Offset Code Combination Identifier
168118  , p_source_17            IN NUMBER
168119 --Expense Account Code Combination Identifier
168120  , p_source_29            IN NUMBER
168121 --Default Code Combination Identifier
168122  , p_source_30            IN NUMBER
168123 --Adjustment Type
168124  , p_source_35            IN VARCHAR2
168125 --Transaction Header Identifier
168126  , p_source_36            IN NUMBER
168127 --Adjustment Line Identifier
168128  , p_source_37            IN NUMBER
168129 --Distribution Type Code
168130  , p_source_38            IN VARCHAR2
168131 --Entered Amount
168132  , p_source_39            IN NUMBER
168133 --Currency Code
168134  , p_source_40            IN VARCHAR2
168135 --Source Destination Code
168136  , p_source_42            IN VARCHAR2
168137 )
168138 IS
168139 
168140 l_component_type              VARCHAR2(80);
168141 l_component_code              VARCHAR2(30);
168142 l_component_type_code         VARCHAR2(1);
168143 l_component_appl_id           INTEGER;
168144 l_amb_context_code            VARCHAR2(30);
168145 l_entity_code                 VARCHAR2(30);
168146 l_event_class_code            VARCHAR2(30);
168147 l_ae_header_id                NUMBER;
168148 l_event_type_code             VARCHAR2(30);
168149 l_line_definition_code        VARCHAR2(30);
168150 l_line_definition_owner_code  VARCHAR2(1);
168151 --
168152 -- adr variables
168153 l_segment                     VARCHAR2(30);
168154 l_ccid                        NUMBER;
168155 l_adr_transaction_coa_id      NUMBER;
168156 l_adr_accounting_coa_id       NUMBER;
168157 l_adr_flexfield_segment_code  VARCHAR2(30);
168158 l_adr_flex_value_set_id       NUMBER;
168159 l_adr_value_type_code         VARCHAR2(30);
168160 l_adr_value_combination_id    NUMBER;
168161 l_adr_value_segment_code      VARCHAR2(30);
168162 
168163 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
168164 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
168165 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
168166 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
168167 
168168 -- 4262811 Variables ------------------------------------------------------------------------------------------
168169 l_entered_amt_idx             NUMBER;
168170 l_accted_amt_idx              NUMBER;
168171 l_acc_rev_flag                VARCHAR2(1);
168172 l_accrual_line_num            NUMBER;
168173 l_tmp_amt                     NUMBER;
168174 l_acc_rev_natural_side_code   VARCHAR2(1);
168175 
168176 l_num_entries                 NUMBER;
168177 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
168178 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
168179 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
168180 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
168181 l_recog_line_1                NUMBER;
168182 l_recog_line_2                NUMBER;
168183 
168184 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
168185 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
168186 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
168187 
168188 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
168189 
168190 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
168191 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
168192 
168193 ---------------------------------------------------------------------------------------------------------------
168194 
168195 
168196 --
168197 -- bulk performance
168198 --
168199 l_balance_type_code           VARCHAR2(1);
168200 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
168201 l_log_module                  VARCHAR2(240);
168202 
168203 --
168204 -- Upgrade strategy
168205 --
168209 --
168206 l_actual_upg_option           VARCHAR2(1);
168207 l_enc_upg_option           VARCHAR2(1);
168208 
168210 BEGIN
168211 --
168212 IF g_log_enabled THEN
168213       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_391';
168214 END IF;
168215 --
168216 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
168217 
168218       trace
168219          (p_msg      => 'BEGIN of AcctLineType_391'
168220          ,p_level    => C_LEVEL_PROCEDURE
168221          ,p_module   => l_log_module);
168222 
168223 END IF;
168224 --
168225 l_component_type             := 'AMB_JLT';
168226 l_component_code             := 'FA_UNITADJ_DEST_DEPRN_RESERVE';
168227 l_component_type_code        := 'S';
168228 l_component_appl_id          :=  140;
168229 l_amb_context_code           := 'DEFAULT';
168230 l_entity_code                := 'TRANSACTIONS';
168231 l_event_class_code           := 'UNIT_ADJUSTMENTS';
168232 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
168233 l_line_definition_owner_code := 'S';
168234 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
168235 --
168236 l_balance_type_code          := 'A';
168237 l_segment                     := NULL;
168238 l_ccid                        := NULL;
168239 l_adr_transaction_coa_id      := NULL;
168240 l_adr_accounting_coa_id       := NULL;
168241 l_adr_flexfield_segment_code  := NULL;
168242 l_adr_flex_value_set_id       := NULL;
168243 l_adr_value_type_code         := NULL;
168244 l_adr_value_combination_id    := NULL;
168245 l_adr_value_segment_code      := NULL;
168246 
168247 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
168248 l_bflow_class_code           := '';    -- 4219869 Business Flow
168249 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
168250 l_budgetary_control_flag     := 'N';
168251 
168252 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
168253 l_bflow_applied_to_amt       := NULL; -- 5132302
168254 l_entered_amt_idx            := NULL;          -- 4262811
168255 l_accted_amt_idx             := NULL;          -- 4262811
168256 l_acc_rev_flag               := NULL;          -- 4262811
168257 l_accrual_line_num           := NULL;          -- 4262811
168258 l_tmp_amt                    := NULL;          -- 4262811
168259 --
168260  
168261 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
168262     l_balance_type_code <> 'B' THEN
168263 IF (NVL(p_source_35,'
168264 ') =  'RESERVE' OR 
168265 NVL(p_source_35,'
168266 ') =  'EXPENSE') AND 
168267 NVL(p_source_42,'
168268 ') =  'DEST'
168269  THEN 
168270 
168271    --
168272    XLA_AE_LINES_PKG.SetNewLine;
168273 
168274    p_balance_type_code          := l_balance_type_code;
168275    -- set the flag so later we will know whether the gain loss line needs to be created
168276    
168277    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
168278      p_actual_flag :='A';
168279    END IF;
168280 
168281    --
168282    -- bulk performance
168283    --
168284    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
168285                                       p_header_num   => 0); -- 4262811
168286    --
168287    -- set accounting line options
168288    --
168289    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
168290            p_natural_side_code          => 'C'
168291          , p_gain_or_loss_flag          => 'N'
168292          , p_gl_transfer_mode_code      => 'S'
168293          , p_acct_entry_type_code       => 'A'
168294          , p_switch_side_flag           => 'Y'
168295          , p_merge_duplicate_code       => 'N'
168296          );
168297    --
168298    l_acc_rev_natural_side_code := 'D';  -- 4262811
168299    -- 
168300    --
168301    -- set accounting line type info
168302    --
168303    xla_ae_lines_pkg.SetAcctLineType
168304       (p_component_type             => l_component_type
168305       ,p_event_type_code            => l_event_type_code
168306       ,p_line_definition_owner_code => l_line_definition_owner_code
168307       ,p_line_definition_code       => l_line_definition_code
168308       ,p_accounting_line_code       => l_component_code
168309       ,p_accounting_line_type_code  => l_component_type_code
168310       ,p_accounting_line_appl_id    => l_component_appl_id
168311       ,p_amb_context_code           => l_amb_context_code
168312       ,p_entity_code                => l_entity_code
168313       ,p_event_class_code           => l_event_class_code);
168314    --
168315    -- set accounting class
168316    --
168317    xla_ae_lines_pkg.SetAcctClass(
168318            p_accounting_class_code  => 'ASSET'
168319          , p_ae_header_id           => l_ae_header_id
168320          );
168321 
168322    --
168323    -- set rounding class
168324    --
168325    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
168326                       'ASSET';
168327 
168328    --
168329    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
168330    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
168331    --
168332    -- bulk performance
168333    --
168334    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
168335 
168336    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
168337       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
168338 
168339    -- 4955764
168340    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
168341       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
168342 
168343    -- 4458381 Public Sector Enh
168344    
168345    --
168346    -- set accounting attributes for the line type
168347    --
168348    l_entered_amt_idx := 4;
168352    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
168349    l_accted_amt_idx  := 6;
168350    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
168351    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
168353    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
168354    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
168355    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
168356    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
168357    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
168358    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
168359    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
168360    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
168361    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
168362    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
168363 
168364    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
168365    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
168366 
168367    ---------------------------------------------------------------------------------------------------------------
168368    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
168369    ---------------------------------------------------------------------------------------------------------------
168370    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
168371 
168372    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
168373    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
168374 
168375    IF xla_accounting_cache_pkg.GetValueChar
168376          (p_source_code         => 'LEDGER_CATEGORY_CODE'
168377          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
168378    AND l_bflow_method_code = 'PRIOR_ENTRY'
168379 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
168380    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
168381          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
168382        )
168383    THEN
168384          xla_ae_lines_pkg.BflowUpgEntry
168385            (p_business_method_code    => l_bflow_method_code
168386            ,p_business_class_code     => l_bflow_class_code
168387            ,p_balance_type            => l_balance_type_code);
168388    ELSE
168389       NULL;
168390 -- No business flow processing for business flow method of NONE.
168391    END IF;
168392 
168393    --
168394    -- call analytical criteria
168395    --
168396    
168397    --
168398    -- call description
168399    --
168400    
168401 xla_ae_lines_pkg.SetLineDescription(
168402    p_ae_header_id => l_ae_header_id
168403   ,p_description  => Description_137 (
168404      p_application_id         => p_application_id
168405    , p_ae_header_id           => l_ae_header_id 
168406 , p_source_1 => p_source_1
168407    )
168408 );
168409 
168410 
168411    --
168412    -- call ADRs
168413    -- Bug 4922099
168414    --
168415    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
168416         (NVL(l_actual_upg_option, 'N') = 'O') OR
168417         (NVL(l_enc_upg_option, 'N') = 'O')
168418       )
168419    THEN
168420    NULL;
168421    --
168422    --
168423    
168424   l_ccid := AcctDerRule_174(
168425            p_application_id           => p_application_id
168426          , p_ae_header_id             => l_ae_header_id 
168427 , p_source_3 => p_source_3
168428 , p_source_17 => p_source_17
168429 , p_source_30 => p_source_30
168430          , x_transaction_coa_id       => l_adr_transaction_coa_id
168431          , x_accounting_coa_id        => l_adr_accounting_coa_id
168432          , x_value_type_code          => l_adr_value_type_code
168433          , p_side                     => 'NA'
168434    );
168435 
168436    xla_ae_lines_pkg.set_ccid(
168437     p_code_combination_id          => l_ccid
168438   , p_value_type_code              => l_adr_value_type_code
168439   , p_transaction_coa_id           => l_adr_transaction_coa_id
168440   , p_accounting_coa_id            => l_adr_accounting_coa_id
168441   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
168442   , p_adr_type_code                => 'S'
168443   , p_component_type               => l_component_type
168444   , p_component_code               => l_component_code
168445   , p_component_type_code          => l_component_type_code
168446   , p_component_appl_id            => l_component_appl_id
168447   , p_amb_context_code             => l_amb_context_code
168448   , p_side                         => 'NA'
168449   );
168450 
168451 
168452    l_segment := AcctDerRule_149(
168453            p_application_id           => p_application_id
168454          , p_ae_header_id             => l_ae_header_id 
168455 , p_source_3 => p_source_3
168456 , p_source_10 => p_source_10
168457          , x_transaction_coa_id       => l_adr_transaction_coa_id
168458          , x_accounting_coa_id        => l_adr_accounting_coa_id
168459          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
168460          , x_flex_value_set_id        => l_adr_flex_value_set_id
168461          , x_value_type_code          => l_adr_value_type_code
168462          , x_value_combination_id     => l_adr_value_combination_id
168463          , x_value_segment_code       => l_adr_value_segment_code
168464          , p_side                     => 'NA'
168465          , p_override_seg_flag        => 'Y'
168466    );
168467 
168468    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
168469 
168470       xla_ae_lines_pkg.set_segment(
168471           p_to_segment_code         => 'GL_ACCOUNT'
168472         , p_segment_value           => l_segment
168473         , p_from_segment_code       => l_adr_value_segment_code
168477         , p_accounting_coa_id       => l_adr_accounting_coa_id
168474         , p_from_combination_id     => l_adr_value_combination_id
168475         , p_value_type_code         => l_adr_value_type_code
168476         , p_transaction_coa_id      => l_adr_transaction_coa_id
168478         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
168479         , p_flex_value_set_id       => l_adr_flex_value_set_id
168480         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
168481         , p_adr_type_code           => 'S'
168482         , p_component_type          => l_component_type
168483         , p_component_code          => l_component_code
168484         , p_component_type_code     => l_component_type_code
168485         , p_component_appl_id       => l_component_appl_id
168486         , p_amb_context_code        => l_amb_context_code
168487         , p_entity_code             => 'TRANSACTIONS'
168488         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
168489         , p_side                    => 'NA'
168490         );
168491 
168492   END IF;
168493 
168494    l_segment := AcctDerRule_168(
168495            p_application_id           => p_application_id
168496          , p_ae_header_id             => l_ae_header_id 
168497 , p_source_3 => p_source_3
168498 , p_source_29 => p_source_29
168499          , x_transaction_coa_id       => l_adr_transaction_coa_id
168500          , x_accounting_coa_id        => l_adr_accounting_coa_id
168501          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
168502          , x_flex_value_set_id        => l_adr_flex_value_set_id
168503          , x_value_type_code          => l_adr_value_type_code
168504          , x_value_combination_id     => l_adr_value_combination_id
168505          , x_value_segment_code       => l_adr_value_segment_code
168506          , p_side                     => 'NA'
168507          , p_override_seg_flag        => 'Y'
168508    );
168509 
168510    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
168511 
168512       xla_ae_lines_pkg.set_segment(
168513           p_to_segment_code         => 'GL_BALANCING'
168514         , p_segment_value           => l_segment
168515         , p_from_segment_code       => l_adr_value_segment_code
168516         , p_from_combination_id     => l_adr_value_combination_id
168517         , p_value_type_code         => l_adr_value_type_code
168518         , p_transaction_coa_id      => l_adr_transaction_coa_id
168519         , p_accounting_coa_id       => l_adr_accounting_coa_id
168520         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
168521         , p_flex_value_set_id       => l_adr_flex_value_set_id
168522         , p_adr_code                => 'FA_EXPENSE_ACCT'
168523         , p_adr_type_code           => 'S'
168524         , p_component_type          => l_component_type
168525         , p_component_code          => l_component_code
168526         , p_component_type_code     => l_component_type_code
168527         , p_component_appl_id       => l_component_appl_id
168528         , p_amb_context_code        => l_amb_context_code
168529         , p_entity_code             => 'TRANSACTIONS'
168530         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
168531         , p_side                    => 'NA'
168532         );
168533 
168534   END IF;
168535 
168536    --
168537    --
168538    END IF;
168539    --
168540    -- Bug 4922099
168541    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
168542           (NVL(l_enc_upg_option, 'N') = 'O')
168543         ) AND
168544         (l_bflow_method_code = 'PRIOR_ENTRY')
168545       )
168546    THEN
168547       IF
168548       --
168549       1 = 2
168550       --
168551       THEN
168552       xla_accounting_err_pkg.build_message
168553                                     (p_appli_s_name            => 'XLA'
168554                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
168555                                     ,p_token_1                 => 'LINE_NUMBER'
168556                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
168557                                     ,p_token_2                 => 'LINE_TYPE_NAME'
168558                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
168559                                                                              l_component_type
168560                                                                             ,l_component_code
168561                                                                             ,l_component_type_code
168562                                                                             ,l_component_appl_id
168563                                                                             ,l_amb_context_code
168564                                                                             ,l_entity_code
168565                                                                             ,l_event_class_code
168566                                                                            )
168567                                     ,p_token_3                 => 'OWNER'
168568                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
168569                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
168570                                                                           ,p_lookup_code    => l_component_type_code
168571                                                                          )
168572                                     ,p_token_4                 => 'PRODUCT_NAME'
168573                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
168574                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
168575                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
168576                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
168580         IF (C_LEVEL_ERROR>= g_log_level) THEN
168577                                     ,p_ae_header_id            =>  NULL
168578                                        );
168579 
168581                  trace
168582                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
168583                       ,p_level    => C_LEVEL_ERROR
168584                       ,p_module   => l_log_module);
168585         END IF;
168586       END IF;
168587    END IF;
168588    --
168589    --
168590    ------------------------------------------------------------------------------------------------
168591    -- 4219869 Business Flow
168592    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
168593    -- Prior Entry.  Currently, the following code is always generated.
168594    ------------------------------------------------------------------------------------------------
168595    XLA_AE_LINES_PKG.ValidateCurrentLine;
168596 
168597    ------------------------------------------------------------------------------------
168598    -- 4219869 Business Flow
168599    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
168600    ------------------------------------------------------------------------------------
168601    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
168602 
168603    ----------------------------------------------------------------------------------
168604    -- 4219869 Business Flow
168605    -- Update journal entry status -- Need to generate this within IF <condition>
168606    ----------------------------------------------------------------------------------
168607    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
168608          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
168609          ,p_balance_type_code => l_balance_type_code
168610          );
168611 
168612    -------------------------------------------------------------------------------------------
168613    -- 4262811 - Generate the Accrual Reversal lines
168614    -------------------------------------------------------------------------------------------
168615    BEGIN
168616       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
168617                               (g_array_event(p_event_id).array_value_num('header_index'));
168618       IF l_acc_rev_flag IS NULL THEN
168619          l_acc_rev_flag := 'N';
168620       END IF;
168621    EXCEPTION
168622       WHEN OTHERS THEN
168623          l_acc_rev_flag := 'N';
168624    END;
168625    --
168626    IF (l_acc_rev_flag = 'Y') THEN
168627 
168628        -- 4645092  ------------------------------------------------------------------------------
168629        -- To allow MPA report to determine if it should generate report process
168630        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
168631        ------------------------------------------------------------------------------------------
168632 
168633        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
168634        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
168635    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
168636    -- call ADRs
168637    -- Bug 4922099
168638    --
168639    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
168640         (NVL(l_actual_upg_option, 'N') = 'O') OR
168641         (NVL(l_enc_upg_option, 'N') = 'O')
168642       )
168643    THEN
168644    NULL;
168645    --
168646    --
168647    
168648   l_ccid := AcctDerRule_174(
168649            p_application_id           => p_application_id
168650          , p_ae_header_id             => l_ae_header_id 
168651 , p_source_3 => p_source_3
168652 , p_source_17 => p_source_17
168653 , p_source_30 => p_source_30
168654          , x_transaction_coa_id       => l_adr_transaction_coa_id
168655          , x_accounting_coa_id        => l_adr_accounting_coa_id
168656          , x_value_type_code          => l_adr_value_type_code
168657          , p_side                     => 'NA'
168658    );
168659 
168660    xla_ae_lines_pkg.set_ccid(
168661     p_code_combination_id          => l_ccid
168662   , p_value_type_code              => l_adr_value_type_code
168663   , p_transaction_coa_id           => l_adr_transaction_coa_id
168664   , p_accounting_coa_id            => l_adr_accounting_coa_id
168665   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
168666   , p_adr_type_code                => 'S'
168667   , p_component_type               => l_component_type
168668   , p_component_code               => l_component_code
168669   , p_component_type_code          => l_component_type_code
168670   , p_component_appl_id            => l_component_appl_id
168671   , p_amb_context_code             => l_amb_context_code
168672   , p_side                         => 'NA'
168673   );
168674 
168675 
168676    l_segment := AcctDerRule_149(
168677            p_application_id           => p_application_id
168678          , p_ae_header_id             => l_ae_header_id 
168679 , p_source_3 => p_source_3
168680 , p_source_10 => p_source_10
168681          , x_transaction_coa_id       => l_adr_transaction_coa_id
168682          , x_accounting_coa_id        => l_adr_accounting_coa_id
168683          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
168684          , x_flex_value_set_id        => l_adr_flex_value_set_id
168685          , x_value_type_code          => l_adr_value_type_code
168686          , x_value_combination_id     => l_adr_value_combination_id
168687          , x_value_segment_code       => l_adr_value_segment_code
168688          , p_side                     => 'NA'
168689          , p_override_seg_flag        => 'Y'
168690    );
168691 
168692    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
168693 
168694       xla_ae_lines_pkg.set_segment(
168695           p_to_segment_code         => 'GL_ACCOUNT'
168696         , p_segment_value           => l_segment
168697         , p_from_segment_code       => l_adr_value_segment_code
168701         , p_accounting_coa_id       => l_adr_accounting_coa_id
168698         , p_from_combination_id     => l_adr_value_combination_id
168699         , p_value_type_code         => l_adr_value_type_code
168700         , p_transaction_coa_id      => l_adr_transaction_coa_id
168702         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
168703         , p_flex_value_set_id       => l_adr_flex_value_set_id
168704         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
168705         , p_adr_type_code           => 'S'
168706         , p_component_type          => l_component_type
168707         , p_component_code          => l_component_code
168708         , p_component_type_code     => l_component_type_code
168709         , p_component_appl_id       => l_component_appl_id
168710         , p_amb_context_code        => l_amb_context_code
168711         , p_entity_code             => 'TRANSACTIONS'
168712         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
168713         , p_side                    => 'NA'
168714         );
168715 
168716   END IF;
168717 
168718    l_segment := AcctDerRule_168(
168719            p_application_id           => p_application_id
168720          , p_ae_header_id             => l_ae_header_id 
168721 , p_source_3 => p_source_3
168722 , p_source_29 => p_source_29
168723          , x_transaction_coa_id       => l_adr_transaction_coa_id
168724          , x_accounting_coa_id        => l_adr_accounting_coa_id
168725          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
168726          , x_flex_value_set_id        => l_adr_flex_value_set_id
168727          , x_value_type_code          => l_adr_value_type_code
168728          , x_value_combination_id     => l_adr_value_combination_id
168729          , x_value_segment_code       => l_adr_value_segment_code
168730          , p_side                     => 'NA'
168731          , p_override_seg_flag        => 'Y'
168732    );
168733 
168734    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
168735 
168736       xla_ae_lines_pkg.set_segment(
168737           p_to_segment_code         => 'GL_BALANCING'
168738         , p_segment_value           => l_segment
168739         , p_from_segment_code       => l_adr_value_segment_code
168740         , p_from_combination_id     => l_adr_value_combination_id
168741         , p_value_type_code         => l_adr_value_type_code
168742         , p_transaction_coa_id      => l_adr_transaction_coa_id
168743         , p_accounting_coa_id       => l_adr_accounting_coa_id
168744         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
168745         , p_flex_value_set_id       => l_adr_flex_value_set_id
168746         , p_adr_code                => 'FA_EXPENSE_ACCT'
168747         , p_adr_type_code           => 'S'
168748         , p_component_type          => l_component_type
168749         , p_component_code          => l_component_code
168750         , p_component_type_code     => l_component_type_code
168751         , p_component_appl_id       => l_component_appl_id
168752         , p_amb_context_code        => l_amb_context_code
168753         , p_entity_code             => 'TRANSACTIONS'
168754         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
168755         , p_side                    => 'NA'
168756         );
168757 
168758   END IF;
168759 
168760    --
168761    --
168762    END IF;
168763 
168764        --
168765        -- Update the line information that should be overwritten
168766        --
168767        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
168768                                          p_header_num   => 1);
168769        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
168770 
168771        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
168772 
168773        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
168774           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
168775        END IF;
168776 
168777       --
168778       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
168779       --
168780       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
168781           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
168782       ELSE
168783           ---------------------------------------------------------------------------------------------------
168784           -- 4262811a Switch Sign
168785           ---------------------------------------------------------------------------------------------------
168786           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
168787           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
168788                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
168789           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
168790                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
168791           -- 5132302
168792           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
168793                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
168794 
168795       END IF;
168796 
168797       -- 4955764
168798       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
168799       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
168800 
168801 
168802       XLA_AE_LINES_PKG.ValidateCurrentLine;
168803       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
168804 
168805       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
168806                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
168807                ,p_balance_type_code => l_balance_type_code);
168808 
168812    -- 4262811 Multiperiod Accounting
168809    END IF;
168810 
168811    -----------------------------------------------------------------------------------------
168813    -----------------------------------------------------------------------------------------
168814      -- No MPA option is assigned.
168815 
168816 
168817 END IF;
168818 END IF;
168819 --
168820 
168821 --
168822 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
168823    trace
168824       (p_msg      => 'END of AcctLineType_391'
168825       ,p_level    => C_LEVEL_PROCEDURE
168826       ,p_module   => l_log_module);
168827 END IF;
168828 --
168829 EXCEPTION
168830   WHEN xla_exceptions_pkg.application_exception THEN
168831       RAISE;
168832   WHEN OTHERS THEN
168833        xla_exceptions_pkg.raise_message
168834            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_391');
168835 END AcctLineType_391;
168836 --
168837 
168838 ---------------------------------------
168839 --
168840 -- PRIVATE FUNCTION
168841 --         AcctLineType_392
168842 --
168843 ---------------------------------------
168844 PROCEDURE AcctLineType_392 (
168845   p_application_id        IN NUMBER
168846  ,p_event_id              IN NUMBER
168847  ,p_calculate_acctd_flag  IN VARCHAR2
168848  ,p_calculate_g_l_flag    IN VARCHAR2
168849  ,p_actual_flag           IN OUT VARCHAR2
168850  ,p_balance_type_code     OUT VARCHAR2
168851  ,p_gain_or_loss_ref      OUT VARCHAR2
168852  
168853 --Period Close Date
168854  , p_source_1            IN DATE
168855 --Generated Code Combination Identifier
168856  , p_source_3            IN NUMBER
168857 --Expense Account Code Combination Identifier
168858  , p_source_29            IN NUMBER
168859 --Adjustment Type
168860  , p_source_35            IN VARCHAR2
168861 --Transaction Header Identifier
168862  , p_source_36            IN NUMBER
168863 --Adjustment Line Identifier
168864  , p_source_37            IN NUMBER
168865 --Distribution Type Code
168866  , p_source_38            IN VARCHAR2
168867 --Entered Amount
168868  , p_source_39            IN NUMBER
168869 --Currency Code
168870  , p_source_40            IN VARCHAR2
168871 --Source Destination Code
168872  , p_source_42            IN VARCHAR2
168873 )
168874 IS
168875 
168876 l_component_type              VARCHAR2(80);
168877 l_component_code              VARCHAR2(30);
168878 l_component_type_code         VARCHAR2(1);
168879 l_component_appl_id           INTEGER;
168880 l_amb_context_code            VARCHAR2(30);
168881 l_entity_code                 VARCHAR2(30);
168882 l_event_class_code            VARCHAR2(30);
168883 l_ae_header_id                NUMBER;
168884 l_event_type_code             VARCHAR2(30);
168885 l_line_definition_code        VARCHAR2(30);
168886 l_line_definition_owner_code  VARCHAR2(1);
168887 --
168888 -- adr variables
168889 l_segment                     VARCHAR2(30);
168890 l_ccid                        NUMBER;
168891 l_adr_transaction_coa_id      NUMBER;
168892 l_adr_accounting_coa_id       NUMBER;
168893 l_adr_flexfield_segment_code  VARCHAR2(30);
168894 l_adr_flex_value_set_id       NUMBER;
168895 l_adr_value_type_code         VARCHAR2(30);
168896 l_adr_value_combination_id    NUMBER;
168897 l_adr_value_segment_code      VARCHAR2(30);
168898 
168899 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
168900 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
168901 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
168902 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
168903 
168904 -- 4262811 Variables ------------------------------------------------------------------------------------------
168905 l_entered_amt_idx             NUMBER;
168906 l_accted_amt_idx              NUMBER;
168907 l_acc_rev_flag                VARCHAR2(1);
168908 l_accrual_line_num            NUMBER;
168909 l_tmp_amt                     NUMBER;
168910 l_acc_rev_natural_side_code   VARCHAR2(1);
168911 
168912 l_num_entries                 NUMBER;
168913 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
168914 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
168915 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
168916 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
168917 l_recog_line_1                NUMBER;
168918 l_recog_line_2                NUMBER;
168919 
168920 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
168921 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
168922 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
168923 
168924 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
168925 
168926 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
168927 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
168928 
168929 ---------------------------------------------------------------------------------------------------------------
168930 
168931 
168932 --
168933 -- bulk performance
168934 --
168935 l_balance_type_code           VARCHAR2(1);
168936 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
168937 l_log_module                  VARCHAR2(240);
168938 
168939 --
168940 -- Upgrade strategy
168941 --
168942 l_actual_upg_option           VARCHAR2(1);
168943 l_enc_upg_option           VARCHAR2(1);
168944 
168945 --
168946 BEGIN
168947 --
168948 IF g_log_enabled THEN
168949       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_392';
168950 END IF;
168951 --
168952 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
168953 
168954       trace
168955          (p_msg      => 'BEGIN of AcctLineType_392'
168956          ,p_level    => C_LEVEL_PROCEDURE
168957          ,p_module   => l_log_module);
168958 
168962 l_component_code             := 'FA_UNITADJ_DEST_EXP_BAL';
168959 END IF;
168960 --
168961 l_component_type             := 'AMB_JLT';
168963 l_component_type_code        := 'S';
168964 l_component_appl_id          :=  140;
168965 l_amb_context_code           := 'DEFAULT';
168966 l_entity_code                := 'TRANSACTIONS';
168967 l_event_class_code           := 'UNIT_ADJUSTMENTS';
168968 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
168969 l_line_definition_owner_code := 'S';
168970 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
168971 --
168972 l_balance_type_code          := 'A';
168973 l_segment                     := NULL;
168974 l_ccid                        := NULL;
168975 l_adr_transaction_coa_id      := NULL;
168976 l_adr_accounting_coa_id       := NULL;
168977 l_adr_flexfield_segment_code  := NULL;
168978 l_adr_flex_value_set_id       := NULL;
168979 l_adr_value_type_code         := NULL;
168980 l_adr_value_combination_id    := NULL;
168981 l_adr_value_segment_code      := NULL;
168982 
168983 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
168984 l_bflow_class_code           := '';    -- 4219869 Business Flow
168985 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
168986 l_budgetary_control_flag     := 'N';
168987 
168988 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
168989 l_bflow_applied_to_amt       := NULL; -- 5132302
168990 l_entered_amt_idx            := NULL;          -- 4262811
168991 l_accted_amt_idx             := NULL;          -- 4262811
168992 l_acc_rev_flag               := NULL;          -- 4262811
168993 l_accrual_line_num           := NULL;          -- 4262811
168994 l_tmp_amt                    := NULL;          -- 4262811
168995 --
168996  
168997 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
168998     l_balance_type_code <> 'B' THEN
168999 IF NVL(p_source_35,'
169000 ') =  'BONUS EXPENSE' AND 
169001 NVL(p_source_42,'
169002 ') =  'DEST'
169003  THEN 
169004 
169005    --
169006    XLA_AE_LINES_PKG.SetNewLine;
169007 
169008    p_balance_type_code          := l_balance_type_code;
169009    -- set the flag so later we will know whether the gain loss line needs to be created
169010    
169011    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
169012      p_actual_flag :='A';
169013    END IF;
169014 
169015    --
169016    -- bulk performance
169017    --
169018    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
169019                                       p_header_num   => 0); -- 4262811
169020    --
169021    -- set accounting line options
169022    --
169023    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
169024            p_natural_side_code          => 'C'
169025          , p_gain_or_loss_flag          => 'N'
169026          , p_gl_transfer_mode_code      => 'S'
169027          , p_acct_entry_type_code       => 'A'
169028          , p_switch_side_flag           => 'Y'
169029          , p_merge_duplicate_code       => 'N'
169030          );
169031    --
169032    l_acc_rev_natural_side_code := 'D';  -- 4262811
169033    -- 
169034    --
169035    -- set accounting line type info
169036    --
169037    xla_ae_lines_pkg.SetAcctLineType
169038       (p_component_type             => l_component_type
169039       ,p_event_type_code            => l_event_type_code
169040       ,p_line_definition_owner_code => l_line_definition_owner_code
169041       ,p_line_definition_code       => l_line_definition_code
169042       ,p_accounting_line_code       => l_component_code
169043       ,p_accounting_line_type_code  => l_component_type_code
169044       ,p_accounting_line_appl_id    => l_component_appl_id
169045       ,p_amb_context_code           => l_amb_context_code
169046       ,p_entity_code                => l_entity_code
169047       ,p_event_class_code           => l_event_class_code);
169048    --
169049    -- set accounting class
169050    --
169051    xla_ae_lines_pkg.SetAcctClass(
169052            p_accounting_class_code  => 'EXPENSE'
169053          , p_ae_header_id           => l_ae_header_id
169054          );
169055 
169056    --
169057    -- set rounding class
169058    --
169059    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
169060                       'EXPENSE';
169061 
169062    --
169063    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
169064    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
169065    --
169066    -- bulk performance
169067    --
169068    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
169069 
169070    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
169071       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
169072 
169073    -- 4955764
169074    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
169075       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
169076 
169077    -- 4458381 Public Sector Enh
169078    
169079    --
169080    -- set accounting attributes for the line type
169081    --
169082    l_entered_amt_idx := 4;
169083    l_accted_amt_idx  := 6;
169084    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
169085    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
169086    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
169087    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
169088    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
169089    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
169090    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
169091    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
169095    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
169092    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
169093    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
169094    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
169096    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
169097 
169098    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
169099    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
169100 
169101    ---------------------------------------------------------------------------------------------------------------
169102    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
169103    ---------------------------------------------------------------------------------------------------------------
169104    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
169105 
169106    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
169107    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
169108 
169109    IF xla_accounting_cache_pkg.GetValueChar
169110          (p_source_code         => 'LEDGER_CATEGORY_CODE'
169111          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
169112    AND l_bflow_method_code = 'PRIOR_ENTRY'
169113 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
169114    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
169115          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
169116        )
169117    THEN
169118          xla_ae_lines_pkg.BflowUpgEntry
169119            (p_business_method_code    => l_bflow_method_code
169120            ,p_business_class_code     => l_bflow_class_code
169121            ,p_balance_type            => l_balance_type_code);
169122    ELSE
169123       NULL;
169124 -- No business flow processing for business flow method of NONE.
169125    END IF;
169126 
169127    --
169128    -- call analytical criteria
169129    --
169130    
169131    --
169132    -- call description
169133    --
169134    
169135 xla_ae_lines_pkg.SetLineDescription(
169136    p_ae_header_id => l_ae_header_id
169137   ,p_description  => Description_134 (
169138      p_application_id         => p_application_id
169139    , p_ae_header_id           => l_ae_header_id 
169140 , p_source_1 => p_source_1
169141    )
169142 );
169143 
169144 
169145    --
169146    -- call ADRs
169147    -- Bug 4922099
169148    --
169149    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
169150         (NVL(l_actual_upg_option, 'N') = 'O') OR
169151         (NVL(l_enc_upg_option, 'N') = 'O')
169152       )
169153    THEN
169154    NULL;
169155    --
169156    --
169157    
169158   l_ccid := AcctDerRule_175(
169159            p_application_id           => p_application_id
169160          , p_ae_header_id             => l_ae_header_id 
169161 , p_source_3 => p_source_3
169162 , p_source_29 => p_source_29
169163          , x_transaction_coa_id       => l_adr_transaction_coa_id
169164          , x_accounting_coa_id        => l_adr_accounting_coa_id
169165          , x_value_type_code          => l_adr_value_type_code
169166          , p_side                     => 'NA'
169167    );
169168 
169169    xla_ae_lines_pkg.set_ccid(
169170     p_code_combination_id          => l_ccid
169171   , p_value_type_code              => l_adr_value_type_code
169172   , p_transaction_coa_id           => l_adr_transaction_coa_id
169173   , p_accounting_coa_id            => l_adr_accounting_coa_id
169174   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
169175   , p_adr_type_code                => 'S'
169176   , p_component_type               => l_component_type
169177   , p_component_code               => l_component_code
169178   , p_component_type_code          => l_component_type_code
169179   , p_component_appl_id            => l_component_appl_id
169180   , p_amb_context_code             => l_amb_context_code
169181   , p_side                         => 'NA'
169182   );
169183 
169184 
169185    --
169186    --
169187    END IF;
169188    --
169189    -- Bug 4922099
169190    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
169191           (NVL(l_enc_upg_option, 'N') = 'O')
169192         ) AND
169193         (l_bflow_method_code = 'PRIOR_ENTRY')
169194       )
169195    THEN
169196       IF
169197       --
169198       1 = 2
169199       --
169200       THEN
169201       xla_accounting_err_pkg.build_message
169202                                     (p_appli_s_name            => 'XLA'
169203                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
169204                                     ,p_token_1                 => 'LINE_NUMBER'
169205                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
169206                                     ,p_token_2                 => 'LINE_TYPE_NAME'
169207                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
169208                                                                              l_component_type
169209                                                                             ,l_component_code
169210                                                                             ,l_component_type_code
169211                                                                             ,l_component_appl_id
169212                                                                             ,l_amb_context_code
169213                                                                             ,l_entity_code
169214                                                                             ,l_event_class_code
169215                                                                            )
169216                                     ,p_token_3                 => 'OWNER'
169220                                                                          )
169217                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
169218                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
169219                                                                           ,p_lookup_code    => l_component_type_code
169221                                     ,p_token_4                 => 'PRODUCT_NAME'
169222                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
169223                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
169224                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
169225                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
169226                                     ,p_ae_header_id            =>  NULL
169227                                        );
169228 
169229         IF (C_LEVEL_ERROR>= g_log_level) THEN
169230                  trace
169231                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
169232                       ,p_level    => C_LEVEL_ERROR
169233                       ,p_module   => l_log_module);
169234         END IF;
169235       END IF;
169236    END IF;
169237    --
169238    --
169239    ------------------------------------------------------------------------------------------------
169240    -- 4219869 Business Flow
169241    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
169242    -- Prior Entry.  Currently, the following code is always generated.
169243    ------------------------------------------------------------------------------------------------
169244    XLA_AE_LINES_PKG.ValidateCurrentLine;
169245 
169246    ------------------------------------------------------------------------------------
169247    -- 4219869 Business Flow
169248    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
169249    ------------------------------------------------------------------------------------
169250    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
169251 
169252    ----------------------------------------------------------------------------------
169253    -- 4219869 Business Flow
169254    -- Update journal entry status -- Need to generate this within IF <condition>
169255    ----------------------------------------------------------------------------------
169256    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
169257          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
169258          ,p_balance_type_code => l_balance_type_code
169259          );
169260 
169261    -------------------------------------------------------------------------------------------
169262    -- 4262811 - Generate the Accrual Reversal lines
169263    -------------------------------------------------------------------------------------------
169264    BEGIN
169265       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
169266                               (g_array_event(p_event_id).array_value_num('header_index'));
169267       IF l_acc_rev_flag IS NULL THEN
169268          l_acc_rev_flag := 'N';
169269       END IF;
169270    EXCEPTION
169271       WHEN OTHERS THEN
169272          l_acc_rev_flag := 'N';
169273    END;
169274    --
169275    IF (l_acc_rev_flag = 'Y') THEN
169276 
169277        -- 4645092  ------------------------------------------------------------------------------
169278        -- To allow MPA report to determine if it should generate report process
169279        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
169280        ------------------------------------------------------------------------------------------
169281 
169282        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
169283        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
169284    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
169285    -- call ADRs
169286    -- Bug 4922099
169287    --
169288    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
169289         (NVL(l_actual_upg_option, 'N') = 'O') OR
169290         (NVL(l_enc_upg_option, 'N') = 'O')
169291       )
169292    THEN
169293    NULL;
169294    --
169295    --
169296    
169297   l_ccid := AcctDerRule_175(
169298            p_application_id           => p_application_id
169299          , p_ae_header_id             => l_ae_header_id 
169300 , p_source_3 => p_source_3
169301 , p_source_29 => p_source_29
169302          , x_transaction_coa_id       => l_adr_transaction_coa_id
169303          , x_accounting_coa_id        => l_adr_accounting_coa_id
169304          , x_value_type_code          => l_adr_value_type_code
169305          , p_side                     => 'NA'
169306    );
169307 
169308    xla_ae_lines_pkg.set_ccid(
169309     p_code_combination_id          => l_ccid
169310   , p_value_type_code              => l_adr_value_type_code
169311   , p_transaction_coa_id           => l_adr_transaction_coa_id
169312   , p_accounting_coa_id            => l_adr_accounting_coa_id
169313   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
169314   , p_adr_type_code                => 'S'
169315   , p_component_type               => l_component_type
169316   , p_component_code               => l_component_code
169317   , p_component_type_code          => l_component_type_code
169318   , p_component_appl_id            => l_component_appl_id
169319   , p_amb_context_code             => l_amb_context_code
169320   , p_side                         => 'NA'
169321   );
169322 
169323 
169324    --
169325    --
169326    END IF;
169327 
169328        --
169329        -- Update the line information that should be overwritten
169330        --
169331        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
169332                                          p_header_num   => 1);
169336 
169333        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
169334 
169335        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
169337        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
169338           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
169339        END IF;
169340 
169341       --
169342       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
169343       --
169344       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
169345           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
169346       ELSE
169347           ---------------------------------------------------------------------------------------------------
169348           -- 4262811a Switch Sign
169349           ---------------------------------------------------------------------------------------------------
169350           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
169351           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
169352                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
169353           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
169354                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
169355           -- 5132302
169356           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
169357                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
169358 
169359       END IF;
169360 
169361       -- 4955764
169362       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
169363       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
169364 
169365 
169366       XLA_AE_LINES_PKG.ValidateCurrentLine;
169367       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
169368 
169369       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
169370                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
169371                ,p_balance_type_code => l_balance_type_code);
169372 
169373    END IF;
169374 
169375    -----------------------------------------------------------------------------------------
169376    -- 4262811 Multiperiod Accounting
169377    -----------------------------------------------------------------------------------------
169378      -- No MPA option is assigned.
169379 
169380 
169381 END IF;
169382 END IF;
169383 --
169384 
169385 --
169386 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
169387    trace
169388       (p_msg      => 'END of AcctLineType_392'
169389       ,p_level    => C_LEVEL_PROCEDURE
169390       ,p_module   => l_log_module);
169391 END IF;
169392 --
169393 EXCEPTION
169394   WHEN xla_exceptions_pkg.application_exception THEN
169395       RAISE;
169396   WHEN OTHERS THEN
169397        xla_exceptions_pkg.raise_message
169398            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_392');
169399 END AcctLineType_392;
169400 --
169401 
169402 ---------------------------------------
169403 --
169404 -- PRIVATE FUNCTION
169405 --         AcctLineType_393
169406 --
169407 ---------------------------------------
169408 PROCEDURE AcctLineType_393 (
169409   p_application_id        IN NUMBER
169410  ,p_event_id              IN NUMBER
169411  ,p_calculate_acctd_flag  IN VARCHAR2
169412  ,p_calculate_g_l_flag    IN VARCHAR2
169413  ,p_actual_flag           IN OUT VARCHAR2
169414  ,p_balance_type_code     OUT VARCHAR2
169415  ,p_gain_or_loss_ref      OUT VARCHAR2
169416  
169417 --Period Close Date
169418  , p_source_1            IN DATE
169419 --Generated Code Combination Identifier
169420  , p_source_3            IN NUMBER
169421 --Depreciation Reserve Account
169422  , p_source_10            IN VARCHAR2
169423 --Generated Offset Code Combination Identifier
169424  , p_source_17            IN NUMBER
169425 --Expense Account Code Combination Identifier
169426  , p_source_29            IN NUMBER
169427 --Default Code Combination Identifier
169428  , p_source_30            IN NUMBER
169429 --Adjustment Type
169430  , p_source_35            IN VARCHAR2
169431 --Transaction Header Identifier
169432  , p_source_36            IN NUMBER
169433 --Adjustment Line Identifier
169434  , p_source_37            IN NUMBER
169435 --Distribution Type Code
169436  , p_source_38            IN VARCHAR2
169437 --Entered Amount
169438  , p_source_39            IN NUMBER
169439 --Currency Code
169440  , p_source_40            IN VARCHAR2
169441 --Source Destination Code
169442  , p_source_42            IN VARCHAR2
169443 )
169444 IS
169445 
169446 l_component_type              VARCHAR2(80);
169447 l_component_code              VARCHAR2(30);
169448 l_component_type_code         VARCHAR2(1);
169449 l_component_appl_id           INTEGER;
169450 l_amb_context_code            VARCHAR2(30);
169451 l_entity_code                 VARCHAR2(30);
169452 l_event_class_code            VARCHAR2(30);
169453 l_ae_header_id                NUMBER;
169454 l_event_type_code             VARCHAR2(30);
169455 l_line_definition_code        VARCHAR2(30);
169456 l_line_definition_owner_code  VARCHAR2(1);
169457 --
169458 -- adr variables
169459 l_segment                     VARCHAR2(30);
169460 l_ccid                        NUMBER;
169461 l_adr_transaction_coa_id      NUMBER;
169462 l_adr_accounting_coa_id       NUMBER;
169463 l_adr_flexfield_segment_code  VARCHAR2(30);
169464 l_adr_flex_value_set_id       NUMBER;
169465 l_adr_value_type_code         VARCHAR2(30);
169466 l_adr_value_combination_id    NUMBER;
169470 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
169467 l_adr_value_segment_code      VARCHAR2(30);
169468 
169469 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
169471 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
169472 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
169473 
169474 -- 4262811 Variables ------------------------------------------------------------------------------------------
169475 l_entered_amt_idx             NUMBER;
169476 l_accted_amt_idx              NUMBER;
169477 l_acc_rev_flag                VARCHAR2(1);
169478 l_accrual_line_num            NUMBER;
169479 l_tmp_amt                     NUMBER;
169480 l_acc_rev_natural_side_code   VARCHAR2(1);
169481 
169482 l_num_entries                 NUMBER;
169483 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
169484 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
169485 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
169486 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
169487 l_recog_line_1                NUMBER;
169488 l_recog_line_2                NUMBER;
169489 
169490 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
169491 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
169492 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
169493 
169494 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
169495 
169496 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
169497 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
169498 
169499 ---------------------------------------------------------------------------------------------------------------
169500 
169501 
169502 --
169503 -- bulk performance
169504 --
169505 l_balance_type_code           VARCHAR2(1);
169506 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
169507 l_log_module                  VARCHAR2(240);
169508 
169509 --
169510 -- Upgrade strategy
169511 --
169512 l_actual_upg_option           VARCHAR2(1);
169513 l_enc_upg_option           VARCHAR2(1);
169514 
169515 --
169516 BEGIN
169517 --
169518 IF g_log_enabled THEN
169519       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_393';
169520 END IF;
169521 --
169522 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
169523 
169524       trace
169525          (p_msg      => 'BEGIN of AcctLineType_393'
169526          ,p_level    => C_LEVEL_PROCEDURE
169527          ,p_module   => l_log_module);
169528 
169529 END IF;
169530 --
169531 l_component_type             := 'AMB_JLT';
169532 l_component_code             := 'FA_UNITADJ_DEST_RESERVE_BAL';
169533 l_component_type_code        := 'S';
169534 l_component_appl_id          :=  140;
169535 l_amb_context_code           := 'DEFAULT';
169536 l_entity_code                := 'TRANSACTIONS';
169537 l_event_class_code           := 'UNIT_ADJUSTMENTS';
169538 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
169539 l_line_definition_owner_code := 'S';
169540 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
169541 --
169542 l_balance_type_code          := 'A';
169543 l_segment                     := NULL;
169544 l_ccid                        := NULL;
169545 l_adr_transaction_coa_id      := NULL;
169546 l_adr_accounting_coa_id       := NULL;
169547 l_adr_flexfield_segment_code  := NULL;
169548 l_adr_flex_value_set_id       := NULL;
169549 l_adr_value_type_code         := NULL;
169550 l_adr_value_combination_id    := NULL;
169551 l_adr_value_segment_code      := NULL;
169552 
169553 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
169554 l_bflow_class_code           := '';    -- 4219869 Business Flow
169555 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
169556 l_budgetary_control_flag     := 'N';
169557 
169558 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
169559 l_bflow_applied_to_amt       := NULL; -- 5132302
169560 l_entered_amt_idx            := NULL;          -- 4262811
169561 l_accted_amt_idx             := NULL;          -- 4262811
169562 l_acc_rev_flag               := NULL;          -- 4262811
169563 l_accrual_line_num           := NULL;          -- 4262811
169564 l_tmp_amt                    := NULL;          -- 4262811
169565 --
169566  
169567 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
169568     l_balance_type_code <> 'B' THEN
169569 IF (NVL(p_source_35,'
169570 ') =  'BONUS EXPENSE' OR 
169571 NVL(p_source_35,'
169572 ') =  'BONUS RESERVE') AND 
169573 NVL(p_source_42,'
169574 ') =  'DEST'
169575  THEN 
169576 
169577    --
169578    XLA_AE_LINES_PKG.SetNewLine;
169579 
169580    p_balance_type_code          := l_balance_type_code;
169581    -- set the flag so later we will know whether the gain loss line needs to be created
169582    
169583    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
169584      p_actual_flag :='A';
169585    END IF;
169586 
169587    --
169588    -- bulk performance
169589    --
169590    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
169591                                       p_header_num   => 0); -- 4262811
169592    --
169593    -- set accounting line options
169594    --
169595    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
169596            p_natural_side_code          => 'D'
169597          , p_gain_or_loss_flag          => 'N'
169598          , p_gl_transfer_mode_code      => 'S'
169599          , p_acct_entry_type_code       => 'A'
169600          , p_switch_side_flag           => 'Y'
169601          , p_merge_duplicate_code       => 'N'
169602          );
169603    --
169604    l_acc_rev_natural_side_code := 'C';  -- 4262811
169605    -- 
169606    --
169610       (p_component_type             => l_component_type
169607    -- set accounting line type info
169608    --
169609    xla_ae_lines_pkg.SetAcctLineType
169611       ,p_event_type_code            => l_event_type_code
169612       ,p_line_definition_owner_code => l_line_definition_owner_code
169613       ,p_line_definition_code       => l_line_definition_code
169614       ,p_accounting_line_code       => l_component_code
169615       ,p_accounting_line_type_code  => l_component_type_code
169616       ,p_accounting_line_appl_id    => l_component_appl_id
169617       ,p_amb_context_code           => l_amb_context_code
169618       ,p_entity_code                => l_entity_code
169619       ,p_event_class_code           => l_event_class_code);
169620    --
169621    -- set accounting class
169622    --
169623    xla_ae_lines_pkg.SetAcctClass(
169624            p_accounting_class_code  => 'ASSET'
169625          , p_ae_header_id           => l_ae_header_id
169626          );
169627 
169628    --
169629    -- set rounding class
169630    --
169631    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
169632                       'ASSET';
169633 
169634    --
169635    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
169636    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
169637    --
169638    -- bulk performance
169639    --
169640    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
169641 
169642    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
169643       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
169644 
169645    -- 4955764
169646    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
169647       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
169648 
169649    -- 4458381 Public Sector Enh
169650    
169651    --
169652    -- set accounting attributes for the line type
169653    --
169654    l_entered_amt_idx := 4;
169655    l_accted_amt_idx  := 6;
169656    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
169657    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
169658    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
169659    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
169660    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
169661    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
169662    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
169663    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
169664    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
169665    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
169666    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
169667    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
169668    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
169669 
169670    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
169671    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
169672 
169673    ---------------------------------------------------------------------------------------------------------------
169674    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
169675    ---------------------------------------------------------------------------------------------------------------
169676    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
169677 
169678    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
169679    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
169680 
169681    IF xla_accounting_cache_pkg.GetValueChar
169682          (p_source_code         => 'LEDGER_CATEGORY_CODE'
169683          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
169684    AND l_bflow_method_code = 'PRIOR_ENTRY'
169685 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
169686    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
169687          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
169688        )
169689    THEN
169690          xla_ae_lines_pkg.BflowUpgEntry
169691            (p_business_method_code    => l_bflow_method_code
169692            ,p_business_class_code     => l_bflow_class_code
169693            ,p_balance_type            => l_balance_type_code);
169694    ELSE
169695       NULL;
169696 -- No business flow processing for business flow method of NONE.
169697    END IF;
169698 
169699    --
169700    -- call analytical criteria
169701    --
169702    
169703    --
169704    -- call description
169705    --
169706    
169707 xla_ae_lines_pkg.SetLineDescription(
169708    p_ae_header_id => l_ae_header_id
169709   ,p_description  => Description_137 (
169710      p_application_id         => p_application_id
169711    , p_ae_header_id           => l_ae_header_id 
169712 , p_source_1 => p_source_1
169713    )
169714 );
169715 
169716 
169717    --
169718    -- call ADRs
169719    -- Bug 4922099
169720    --
169721    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
169722         (NVL(l_actual_upg_option, 'N') = 'O') OR
169723         (NVL(l_enc_upg_option, 'N') = 'O')
169724       )
169725    THEN
169726    NULL;
169727    --
169728    --
169729    
169730   l_ccid := AcctDerRule_174(
169731            p_application_id           => p_application_id
169732          , p_ae_header_id             => l_ae_header_id 
169733 , p_source_3 => p_source_3
169734 , p_source_17 => p_source_17
169735 , p_source_30 => p_source_30
169739          , p_side                     => 'NA'
169736          , x_transaction_coa_id       => l_adr_transaction_coa_id
169737          , x_accounting_coa_id        => l_adr_accounting_coa_id
169738          , x_value_type_code          => l_adr_value_type_code
169740    );
169741 
169742    xla_ae_lines_pkg.set_ccid(
169743     p_code_combination_id          => l_ccid
169744   , p_value_type_code              => l_adr_value_type_code
169745   , p_transaction_coa_id           => l_adr_transaction_coa_id
169746   , p_accounting_coa_id            => l_adr_accounting_coa_id
169747   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
169748   , p_adr_type_code                => 'S'
169749   , p_component_type               => l_component_type
169750   , p_component_code               => l_component_code
169751   , p_component_type_code          => l_component_type_code
169752   , p_component_appl_id            => l_component_appl_id
169753   , p_amb_context_code             => l_amb_context_code
169754   , p_side                         => 'NA'
169755   );
169756 
169757 
169758    l_segment := AcctDerRule_149(
169759            p_application_id           => p_application_id
169760          , p_ae_header_id             => l_ae_header_id 
169761 , p_source_3 => p_source_3
169762 , p_source_10 => p_source_10
169763          , x_transaction_coa_id       => l_adr_transaction_coa_id
169764          , x_accounting_coa_id        => l_adr_accounting_coa_id
169765          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
169766          , x_flex_value_set_id        => l_adr_flex_value_set_id
169767          , x_value_type_code          => l_adr_value_type_code
169768          , x_value_combination_id     => l_adr_value_combination_id
169769          , x_value_segment_code       => l_adr_value_segment_code
169770          , p_side                     => 'NA'
169771          , p_override_seg_flag        => 'Y'
169772    );
169773 
169774    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
169775 
169776       xla_ae_lines_pkg.set_segment(
169777           p_to_segment_code         => 'GL_ACCOUNT'
169778         , p_segment_value           => l_segment
169779         , p_from_segment_code       => l_adr_value_segment_code
169780         , p_from_combination_id     => l_adr_value_combination_id
169781         , p_value_type_code         => l_adr_value_type_code
169782         , p_transaction_coa_id      => l_adr_transaction_coa_id
169783         , p_accounting_coa_id       => l_adr_accounting_coa_id
169784         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
169785         , p_flex_value_set_id       => l_adr_flex_value_set_id
169786         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
169787         , p_adr_type_code           => 'S'
169788         , p_component_type          => l_component_type
169789         , p_component_code          => l_component_code
169790         , p_component_type_code     => l_component_type_code
169791         , p_component_appl_id       => l_component_appl_id
169792         , p_amb_context_code        => l_amb_context_code
169793         , p_entity_code             => 'TRANSACTIONS'
169794         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
169795         , p_side                    => 'NA'
169796         );
169797 
169798   END IF;
169799 
169800    l_segment := AcctDerRule_168(
169801            p_application_id           => p_application_id
169802          , p_ae_header_id             => l_ae_header_id 
169803 , p_source_3 => p_source_3
169804 , p_source_29 => p_source_29
169805          , x_transaction_coa_id       => l_adr_transaction_coa_id
169806          , x_accounting_coa_id        => l_adr_accounting_coa_id
169807          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
169808          , x_flex_value_set_id        => l_adr_flex_value_set_id
169809          , x_value_type_code          => l_adr_value_type_code
169810          , x_value_combination_id     => l_adr_value_combination_id
169811          , x_value_segment_code       => l_adr_value_segment_code
169812          , p_side                     => 'NA'
169813          , p_override_seg_flag        => 'Y'
169814    );
169815 
169816    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
169817 
169818       xla_ae_lines_pkg.set_segment(
169819           p_to_segment_code         => 'GL_BALANCING'
169820         , p_segment_value           => l_segment
169821         , p_from_segment_code       => l_adr_value_segment_code
169822         , p_from_combination_id     => l_adr_value_combination_id
169823         , p_value_type_code         => l_adr_value_type_code
169824         , p_transaction_coa_id      => l_adr_transaction_coa_id
169825         , p_accounting_coa_id       => l_adr_accounting_coa_id
169826         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
169827         , p_flex_value_set_id       => l_adr_flex_value_set_id
169828         , p_adr_code                => 'FA_EXPENSE_ACCT'
169829         , p_adr_type_code           => 'S'
169830         , p_component_type          => l_component_type
169831         , p_component_code          => l_component_code
169832         , p_component_type_code     => l_component_type_code
169833         , p_component_appl_id       => l_component_appl_id
169834         , p_amb_context_code        => l_amb_context_code
169835         , p_entity_code             => 'TRANSACTIONS'
169836         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
169837         , p_side                    => 'NA'
169838         );
169839 
169840   END IF;
169841 
169842    --
169843    --
169844    END IF;
169845    --
169846    -- Bug 4922099
169847    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
169848           (NVL(l_enc_upg_option, 'N') = 'O')
169849         ) AND
169850         (l_bflow_method_code = 'PRIOR_ENTRY')
169851       )
169852    THEN
169853       IF
169854       --
169855       1 = 2
169856       --
169857       THEN
169858       xla_accounting_err_pkg.build_message
169862                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
169859                                     (p_appli_s_name            => 'XLA'
169860                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
169861                                     ,p_token_1                 => 'LINE_NUMBER'
169863                                     ,p_token_2                 => 'LINE_TYPE_NAME'
169864                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
169865                                                                              l_component_type
169866                                                                             ,l_component_code
169867                                                                             ,l_component_type_code
169868                                                                             ,l_component_appl_id
169869                                                                             ,l_amb_context_code
169870                                                                             ,l_entity_code
169871                                                                             ,l_event_class_code
169872                                                                            )
169873                                     ,p_token_3                 => 'OWNER'
169874                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
169875                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
169876                                                                           ,p_lookup_code    => l_component_type_code
169877                                                                          )
169878                                     ,p_token_4                 => 'PRODUCT_NAME'
169879                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
169880                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
169881                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
169882                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
169883                                     ,p_ae_header_id            =>  NULL
169884                                        );
169885 
169886         IF (C_LEVEL_ERROR>= g_log_level) THEN
169887                  trace
169888                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
169889                       ,p_level    => C_LEVEL_ERROR
169890                       ,p_module   => l_log_module);
169891         END IF;
169892       END IF;
169893    END IF;
169894    --
169895    --
169896    ------------------------------------------------------------------------------------------------
169897    -- 4219869 Business Flow
169898    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
169899    -- Prior Entry.  Currently, the following code is always generated.
169900    ------------------------------------------------------------------------------------------------
169901    XLA_AE_LINES_PKG.ValidateCurrentLine;
169902 
169903    ------------------------------------------------------------------------------------
169904    -- 4219869 Business Flow
169905    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
169906    ------------------------------------------------------------------------------------
169907    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
169908 
169909    ----------------------------------------------------------------------------------
169910    -- 4219869 Business Flow
169911    -- Update journal entry status -- Need to generate this within IF <condition>
169912    ----------------------------------------------------------------------------------
169913    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
169914          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
169915          ,p_balance_type_code => l_balance_type_code
169916          );
169917 
169918    -------------------------------------------------------------------------------------------
169919    -- 4262811 - Generate the Accrual Reversal lines
169920    -------------------------------------------------------------------------------------------
169921    BEGIN
169922       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
169923                               (g_array_event(p_event_id).array_value_num('header_index'));
169924       IF l_acc_rev_flag IS NULL THEN
169925          l_acc_rev_flag := 'N';
169926       END IF;
169927    EXCEPTION
169928       WHEN OTHERS THEN
169929          l_acc_rev_flag := 'N';
169930    END;
169931    --
169932    IF (l_acc_rev_flag = 'Y') THEN
169933 
169934        -- 4645092  ------------------------------------------------------------------------------
169935        -- To allow MPA report to determine if it should generate report process
169936        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
169937        ------------------------------------------------------------------------------------------
169938 
169939        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
169940        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
169941    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
169942    -- call ADRs
169943    -- Bug 4922099
169944    --
169945    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
169946         (NVL(l_actual_upg_option, 'N') = 'O') OR
169947         (NVL(l_enc_upg_option, 'N') = 'O')
169948       )
169949    THEN
169950    NULL;
169951    --
169952    --
169953    
169954   l_ccid := AcctDerRule_174(
169955            p_application_id           => p_application_id
169956          , p_ae_header_id             => l_ae_header_id 
169957 , p_source_3 => p_source_3
169958 , p_source_17 => p_source_17
169959 , p_source_30 => p_source_30
169963          , p_side                     => 'NA'
169960          , x_transaction_coa_id       => l_adr_transaction_coa_id
169961          , x_accounting_coa_id        => l_adr_accounting_coa_id
169962          , x_value_type_code          => l_adr_value_type_code
169964    );
169965 
169966    xla_ae_lines_pkg.set_ccid(
169967     p_code_combination_id          => l_ccid
169968   , p_value_type_code              => l_adr_value_type_code
169969   , p_transaction_coa_id           => l_adr_transaction_coa_id
169970   , p_accounting_coa_id            => l_adr_accounting_coa_id
169971   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
169972   , p_adr_type_code                => 'S'
169973   , p_component_type               => l_component_type
169974   , p_component_code               => l_component_code
169975   , p_component_type_code          => l_component_type_code
169976   , p_component_appl_id            => l_component_appl_id
169977   , p_amb_context_code             => l_amb_context_code
169978   , p_side                         => 'NA'
169979   );
169980 
169981 
169982    l_segment := AcctDerRule_149(
169983            p_application_id           => p_application_id
169984          , p_ae_header_id             => l_ae_header_id 
169985 , p_source_3 => p_source_3
169986 , p_source_10 => p_source_10
169987          , x_transaction_coa_id       => l_adr_transaction_coa_id
169988          , x_accounting_coa_id        => l_adr_accounting_coa_id
169989          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
169990          , x_flex_value_set_id        => l_adr_flex_value_set_id
169991          , x_value_type_code          => l_adr_value_type_code
169992          , x_value_combination_id     => l_adr_value_combination_id
169993          , x_value_segment_code       => l_adr_value_segment_code
169994          , p_side                     => 'NA'
169995          , p_override_seg_flag        => 'Y'
169996    );
169997 
169998    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
169999 
170000       xla_ae_lines_pkg.set_segment(
170001           p_to_segment_code         => 'GL_ACCOUNT'
170002         , p_segment_value           => l_segment
170003         , p_from_segment_code       => l_adr_value_segment_code
170004         , p_from_combination_id     => l_adr_value_combination_id
170005         , p_value_type_code         => l_adr_value_type_code
170006         , p_transaction_coa_id      => l_adr_transaction_coa_id
170007         , p_accounting_coa_id       => l_adr_accounting_coa_id
170008         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
170009         , p_flex_value_set_id       => l_adr_flex_value_set_id
170010         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
170011         , p_adr_type_code           => 'S'
170012         , p_component_type          => l_component_type
170013         , p_component_code          => l_component_code
170014         , p_component_type_code     => l_component_type_code
170015         , p_component_appl_id       => l_component_appl_id
170016         , p_amb_context_code        => l_amb_context_code
170017         , p_entity_code             => 'TRANSACTIONS'
170018         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
170019         , p_side                    => 'NA'
170020         );
170021 
170022   END IF;
170023 
170024    l_segment := AcctDerRule_168(
170025            p_application_id           => p_application_id
170026          , p_ae_header_id             => l_ae_header_id 
170027 , p_source_3 => p_source_3
170028 , p_source_29 => p_source_29
170029          , x_transaction_coa_id       => l_adr_transaction_coa_id
170030          , x_accounting_coa_id        => l_adr_accounting_coa_id
170031          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
170032          , x_flex_value_set_id        => l_adr_flex_value_set_id
170033          , x_value_type_code          => l_adr_value_type_code
170034          , x_value_combination_id     => l_adr_value_combination_id
170035          , x_value_segment_code       => l_adr_value_segment_code
170036          , p_side                     => 'NA'
170037          , p_override_seg_flag        => 'Y'
170038    );
170039 
170040    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
170041 
170042       xla_ae_lines_pkg.set_segment(
170043           p_to_segment_code         => 'GL_BALANCING'
170044         , p_segment_value           => l_segment
170045         , p_from_segment_code       => l_adr_value_segment_code
170046         , p_from_combination_id     => l_adr_value_combination_id
170047         , p_value_type_code         => l_adr_value_type_code
170048         , p_transaction_coa_id      => l_adr_transaction_coa_id
170049         , p_accounting_coa_id       => l_adr_accounting_coa_id
170050         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
170051         , p_flex_value_set_id       => l_adr_flex_value_set_id
170052         , p_adr_code                => 'FA_EXPENSE_ACCT'
170053         , p_adr_type_code           => 'S'
170054         , p_component_type          => l_component_type
170055         , p_component_code          => l_component_code
170056         , p_component_type_code     => l_component_type_code
170057         , p_component_appl_id       => l_component_appl_id
170058         , p_amb_context_code        => l_amb_context_code
170059         , p_entity_code             => 'TRANSACTIONS'
170060         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
170061         , p_side                    => 'NA'
170062         );
170063 
170064   END IF;
170065 
170066    --
170067    --
170068    END IF;
170069 
170070        --
170071        -- Update the line information that should be overwritten
170072        --
170073        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
170074                                          p_header_num   => 1);
170075        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
170076 
170077        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
170078 
170082 
170079        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
170080           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
170081        END IF;
170083       --
170084       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
170085       --
170086       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
170087           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
170088       ELSE
170089           ---------------------------------------------------------------------------------------------------
170090           -- 4262811a Switch Sign
170091           ---------------------------------------------------------------------------------------------------
170092           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
170093           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
170094                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
170095           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
170096                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
170097           -- 5132302
170098           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
170099                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
170100 
170101       END IF;
170102 
170103       -- 4955764
170104       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
170105       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
170106 
170107 
170108       XLA_AE_LINES_PKG.ValidateCurrentLine;
170109       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
170110 
170111       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
170112                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
170113                ,p_balance_type_code => l_balance_type_code);
170114 
170115    END IF;
170116 
170117    -----------------------------------------------------------------------------------------
170118    -- 4262811 Multiperiod Accounting
170119    -----------------------------------------------------------------------------------------
170120      -- No MPA option is assigned.
170121 
170122 
170123 END IF;
170124 END IF;
170125 --
170126 
170127 --
170128 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
170129    trace
170130       (p_msg      => 'END of AcctLineType_393'
170131       ,p_level    => C_LEVEL_PROCEDURE
170132       ,p_module   => l_log_module);
170133 END IF;
170134 --
170135 EXCEPTION
170136   WHEN xla_exceptions_pkg.application_exception THEN
170137       RAISE;
170138   WHEN OTHERS THEN
170139        xla_exceptions_pkg.raise_message
170140            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_393');
170141 END AcctLineType_393;
170142 --
170143 
170144 ---------------------------------------
170145 --
170146 -- PRIVATE FUNCTION
170147 --         AcctLineType_394
170148 --
170149 ---------------------------------------
170150 PROCEDURE AcctLineType_394 (
170151   p_application_id        IN NUMBER
170152  ,p_event_id              IN NUMBER
170153  ,p_calculate_acctd_flag  IN VARCHAR2
170154  ,p_calculate_g_l_flag    IN VARCHAR2
170155  ,p_actual_flag           IN OUT VARCHAR2
170156  ,p_balance_type_code     OUT VARCHAR2
170157  ,p_gain_or_loss_ref      OUT VARCHAR2
170158  
170159 --Period Close Date
170160  , p_source_1            IN DATE
170161 --Generated Code Combination Identifier
170162  , p_source_3            IN NUMBER
170163 --Revaluation Reserve Account
170164  , p_source_11            IN VARCHAR2
170165 --Generated Offset Code Combination Identifier
170166  , p_source_17            IN NUMBER
170167 --Expense Account Code Combination Identifier
170168  , p_source_29            IN NUMBER
170169 --Default Code Combination Identifier
170170  , p_source_30            IN NUMBER
170171 --Adjustment Type
170172  , p_source_35            IN VARCHAR2
170173 --Transaction Header Identifier
170174  , p_source_36            IN NUMBER
170175 --Adjustment Line Identifier
170176  , p_source_37            IN NUMBER
170177 --Distribution Type Code
170178  , p_source_38            IN VARCHAR2
170179 --Entered Amount
170180  , p_source_39            IN NUMBER
170181 --Currency Code
170182  , p_source_40            IN VARCHAR2
170183 --Source Destination Code
170184  , p_source_42            IN VARCHAR2
170185 )
170186 IS
170187 
170188 l_component_type              VARCHAR2(80);
170189 l_component_code              VARCHAR2(30);
170190 l_component_type_code         VARCHAR2(1);
170191 l_component_appl_id           INTEGER;
170192 l_amb_context_code            VARCHAR2(30);
170193 l_entity_code                 VARCHAR2(30);
170194 l_event_class_code            VARCHAR2(30);
170195 l_ae_header_id                NUMBER;
170196 l_event_type_code             VARCHAR2(30);
170197 l_line_definition_code        VARCHAR2(30);
170198 l_line_definition_owner_code  VARCHAR2(1);
170199 --
170200 -- adr variables
170201 l_segment                     VARCHAR2(30);
170202 l_ccid                        NUMBER;
170203 l_adr_transaction_coa_id      NUMBER;
170204 l_adr_accounting_coa_id       NUMBER;
170205 l_adr_flexfield_segment_code  VARCHAR2(30);
170206 l_adr_flex_value_set_id       NUMBER;
170207 l_adr_value_type_code         VARCHAR2(30);
170208 l_adr_value_combination_id    NUMBER;
170209 l_adr_value_segment_code      VARCHAR2(30);
170210 
170211 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
170212 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
170216 -- 4262811 Variables ------------------------------------------------------------------------------------------
170213 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
170214 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
170215 
170217 l_entered_amt_idx             NUMBER;
170218 l_accted_amt_idx              NUMBER;
170219 l_acc_rev_flag                VARCHAR2(1);
170220 l_accrual_line_num            NUMBER;
170221 l_tmp_amt                     NUMBER;
170222 l_acc_rev_natural_side_code   VARCHAR2(1);
170223 
170224 l_num_entries                 NUMBER;
170225 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
170226 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
170227 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
170228 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
170229 l_recog_line_1                NUMBER;
170230 l_recog_line_2                NUMBER;
170231 
170232 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
170233 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
170234 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
170235 
170236 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
170237 
170238 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
170239 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
170240 
170241 ---------------------------------------------------------------------------------------------------------------
170242 
170243 
170244 --
170245 -- bulk performance
170246 --
170247 l_balance_type_code           VARCHAR2(1);
170248 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
170249 l_log_module                  VARCHAR2(240);
170250 
170251 --
170252 -- Upgrade strategy
170253 --
170254 l_actual_upg_option           VARCHAR2(1);
170255 l_enc_upg_option           VARCHAR2(1);
170256 
170257 --
170258 BEGIN
170259 --
170260 IF g_log_enabled THEN
170261       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_394';
170262 END IF;
170263 --
170264 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
170265 
170266       trace
170267          (p_msg      => 'BEGIN of AcctLineType_394'
170268          ,p_level    => C_LEVEL_PROCEDURE
170269          ,p_module   => l_log_module);
170270 
170271 END IF;
170272 --
170273 l_component_type             := 'AMB_JLT';
170274 l_component_code             := 'FA_UNITADJ_DEST_REVAL_RESERV';
170275 l_component_type_code        := 'S';
170276 l_component_appl_id          :=  140;
170277 l_amb_context_code           := 'DEFAULT';
170278 l_entity_code                := 'TRANSACTIONS';
170279 l_event_class_code           := 'UNIT_ADJUSTMENTS';
170280 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
170281 l_line_definition_owner_code := 'S';
170282 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
170283 --
170284 l_balance_type_code          := 'A';
170285 l_segment                     := NULL;
170286 l_ccid                        := NULL;
170287 l_adr_transaction_coa_id      := NULL;
170288 l_adr_accounting_coa_id       := NULL;
170289 l_adr_flexfield_segment_code  := NULL;
170290 l_adr_flex_value_set_id       := NULL;
170291 l_adr_value_type_code         := NULL;
170292 l_adr_value_combination_id    := NULL;
170293 l_adr_value_segment_code      := NULL;
170294 
170295 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
170296 l_bflow_class_code           := '';    -- 4219869 Business Flow
170297 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
170298 l_budgetary_control_flag     := 'N';
170299 
170300 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
170301 l_bflow_applied_to_amt       := NULL; -- 5132302
170302 l_entered_amt_idx            := NULL;          -- 4262811
170303 l_accted_amt_idx             := NULL;          -- 4262811
170304 l_acc_rev_flag               := NULL;          -- 4262811
170305 l_accrual_line_num           := NULL;          -- 4262811
170306 l_tmp_amt                    := NULL;          -- 4262811
170307 --
170308  
170309 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
170310     l_balance_type_code <> 'B' THEN
170311 IF NVL(p_source_35,'
170312 ') =  'REVAL RESERVE' AND 
170313 NVL(p_source_42,'
170314 ') =  'DEST'
170315  THEN 
170316 
170317    --
170318    XLA_AE_LINES_PKG.SetNewLine;
170319 
170320    p_balance_type_code          := l_balance_type_code;
170321    -- set the flag so later we will know whether the gain loss line needs to be created
170322    
170323    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
170324      p_actual_flag :='A';
170325    END IF;
170326 
170327    --
170328    -- bulk performance
170329    --
170330    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
170331                                       p_header_num   => 0); -- 4262811
170332    --
170333    -- set accounting line options
170334    --
170335    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
170336            p_natural_side_code          => 'C'
170337          , p_gain_or_loss_flag          => 'N'
170338          , p_gl_transfer_mode_code      => 'S'
170339          , p_acct_entry_type_code       => 'A'
170340          , p_switch_side_flag           => 'Y'
170341          , p_merge_duplicate_code       => 'N'
170342          );
170343    --
170344    l_acc_rev_natural_side_code := 'D';  -- 4262811
170345    -- 
170346    --
170347    -- set accounting line type info
170348    --
170349    xla_ae_lines_pkg.SetAcctLineType
170350       (p_component_type             => l_component_type
170351       ,p_event_type_code            => l_event_type_code
170352       ,p_line_definition_owner_code => l_line_definition_owner_code
170356       ,p_accounting_line_appl_id    => l_component_appl_id
170353       ,p_line_definition_code       => l_line_definition_code
170354       ,p_accounting_line_code       => l_component_code
170355       ,p_accounting_line_type_code  => l_component_type_code
170357       ,p_amb_context_code           => l_amb_context_code
170358       ,p_entity_code                => l_entity_code
170359       ,p_event_class_code           => l_event_class_code);
170360    --
170361    -- set accounting class
170362    --
170363    xla_ae_lines_pkg.SetAcctClass(
170364            p_accounting_class_code  => 'ASSET'
170365          , p_ae_header_id           => l_ae_header_id
170366          );
170367 
170368    --
170369    -- set rounding class
170370    --
170371    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
170372                       'ASSET';
170373 
170374    --
170375    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
170376    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
170377    --
170378    -- bulk performance
170379    --
170380    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
170381 
170382    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
170383       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
170384 
170385    -- 4955764
170386    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
170387       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
170388 
170389    -- 4458381 Public Sector Enh
170390    
170391    --
170392    -- set accounting attributes for the line type
170393    --
170394    l_entered_amt_idx := 4;
170395    l_accted_amt_idx  := 6;
170396    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
170397    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
170398    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
170399    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
170400    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
170401    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
170402    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
170403    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
170404    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
170405    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
170406    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
170407    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
170408    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
170409 
170410    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
170411    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
170412 
170413    ---------------------------------------------------------------------------------------------------------------
170414    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
170415    ---------------------------------------------------------------------------------------------------------------
170416    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
170417 
170418    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
170419    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
170420 
170421    IF xla_accounting_cache_pkg.GetValueChar
170422          (p_source_code         => 'LEDGER_CATEGORY_CODE'
170423          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
170424    AND l_bflow_method_code = 'PRIOR_ENTRY'
170425 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
170426    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
170427          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
170428        )
170429    THEN
170430          xla_ae_lines_pkg.BflowUpgEntry
170431            (p_business_method_code    => l_bflow_method_code
170432            ,p_business_class_code     => l_bflow_class_code
170433            ,p_balance_type            => l_balance_type_code);
170434    ELSE
170435       NULL;
170436 -- No business flow processing for business flow method of NONE.
170437    END IF;
170438 
170439    --
170440    -- call analytical criteria
170441    --
170442    
170443    --
170444    -- call description
170445    --
170446    
170447 xla_ae_lines_pkg.SetLineDescription(
170448    p_ae_header_id => l_ae_header_id
170449   ,p_description  => Description_138 (
170450      p_application_id         => p_application_id
170451    , p_ae_header_id           => l_ae_header_id 
170452 , p_source_1 => p_source_1
170453    )
170454 );
170455 
170456 
170457    --
170458    -- call ADRs
170459    -- Bug 4922099
170460    --
170461    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
170462         (NVL(l_actual_upg_option, 'N') = 'O') OR
170463         (NVL(l_enc_upg_option, 'N') = 'O')
170464       )
170465    THEN
170466    NULL;
170467    --
170468    --
170469    
170470   l_ccid := AcctDerRule_174(
170471            p_application_id           => p_application_id
170472          , p_ae_header_id             => l_ae_header_id 
170473 , p_source_3 => p_source_3
170474 , p_source_17 => p_source_17
170475 , p_source_30 => p_source_30
170476          , x_transaction_coa_id       => l_adr_transaction_coa_id
170477          , x_accounting_coa_id        => l_adr_accounting_coa_id
170478          , x_value_type_code          => l_adr_value_type_code
170479          , p_side                     => 'NA'
170480    );
170481 
170482    xla_ae_lines_pkg.set_ccid(
170486   , p_accounting_coa_id            => l_adr_accounting_coa_id
170483     p_code_combination_id          => l_ccid
170484   , p_value_type_code              => l_adr_value_type_code
170485   , p_transaction_coa_id           => l_adr_transaction_coa_id
170487   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
170488   , p_adr_type_code                => 'S'
170489   , p_component_type               => l_component_type
170490   , p_component_code               => l_component_code
170491   , p_component_type_code          => l_component_type_code
170492   , p_component_appl_id            => l_component_appl_id
170493   , p_amb_context_code             => l_amb_context_code
170494   , p_side                         => 'NA'
170495   );
170496 
170497 
170498    l_segment := AcctDerRule_150(
170499            p_application_id           => p_application_id
170500          , p_ae_header_id             => l_ae_header_id 
170501 , p_source_3 => p_source_3
170502 , p_source_11 => p_source_11
170503          , x_transaction_coa_id       => l_adr_transaction_coa_id
170504          , x_accounting_coa_id        => l_adr_accounting_coa_id
170505          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
170506          , x_flex_value_set_id        => l_adr_flex_value_set_id
170507          , x_value_type_code          => l_adr_value_type_code
170508          , x_value_combination_id     => l_adr_value_combination_id
170509          , x_value_segment_code       => l_adr_value_segment_code
170510          , p_side                     => 'NA'
170511          , p_override_seg_flag        => 'Y'
170512    );
170513 
170514    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
170515 
170516       xla_ae_lines_pkg.set_segment(
170517           p_to_segment_code         => 'GL_ACCOUNT'
170518         , p_segment_value           => l_segment
170519         , p_from_segment_code       => l_adr_value_segment_code
170520         , p_from_combination_id     => l_adr_value_combination_id
170521         , p_value_type_code         => l_adr_value_type_code
170522         , p_transaction_coa_id      => l_adr_transaction_coa_id
170523         , p_accounting_coa_id       => l_adr_accounting_coa_id
170524         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
170525         , p_flex_value_set_id       => l_adr_flex_value_set_id
170526         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
170527         , p_adr_type_code           => 'S'
170528         , p_component_type          => l_component_type
170529         , p_component_code          => l_component_code
170530         , p_component_type_code     => l_component_type_code
170531         , p_component_appl_id       => l_component_appl_id
170532         , p_amb_context_code        => l_amb_context_code
170533         , p_entity_code             => 'TRANSACTIONS'
170534         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
170535         , p_side                    => 'NA'
170536         );
170537 
170538   END IF;
170539 
170540    l_segment := AcctDerRule_168(
170541            p_application_id           => p_application_id
170542          , p_ae_header_id             => l_ae_header_id 
170543 , p_source_3 => p_source_3
170544 , p_source_29 => p_source_29
170545          , x_transaction_coa_id       => l_adr_transaction_coa_id
170546          , x_accounting_coa_id        => l_adr_accounting_coa_id
170547          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
170548          , x_flex_value_set_id        => l_adr_flex_value_set_id
170549          , x_value_type_code          => l_adr_value_type_code
170550          , x_value_combination_id     => l_adr_value_combination_id
170551          , x_value_segment_code       => l_adr_value_segment_code
170552          , p_side                     => 'NA'
170553          , p_override_seg_flag        => 'Y'
170554    );
170555 
170556    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
170557 
170558       xla_ae_lines_pkg.set_segment(
170559           p_to_segment_code         => 'GL_BALANCING'
170560         , p_segment_value           => l_segment
170561         , p_from_segment_code       => l_adr_value_segment_code
170562         , p_from_combination_id     => l_adr_value_combination_id
170563         , p_value_type_code         => l_adr_value_type_code
170564         , p_transaction_coa_id      => l_adr_transaction_coa_id
170565         , p_accounting_coa_id       => l_adr_accounting_coa_id
170566         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
170567         , p_flex_value_set_id       => l_adr_flex_value_set_id
170568         , p_adr_code                => 'FA_EXPENSE_ACCT'
170569         , p_adr_type_code           => 'S'
170570         , p_component_type          => l_component_type
170571         , p_component_code          => l_component_code
170572         , p_component_type_code     => l_component_type_code
170573         , p_component_appl_id       => l_component_appl_id
170574         , p_amb_context_code        => l_amb_context_code
170575         , p_entity_code             => 'TRANSACTIONS'
170576         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
170577         , p_side                    => 'NA'
170578         );
170579 
170580   END IF;
170581 
170582    --
170583    --
170584    END IF;
170585    --
170586    -- Bug 4922099
170587    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
170588           (NVL(l_enc_upg_option, 'N') = 'O')
170589         ) AND
170590         (l_bflow_method_code = 'PRIOR_ENTRY')
170591       )
170592    THEN
170593       IF
170594       --
170595       1 = 2
170596       --
170597       THEN
170598       xla_accounting_err_pkg.build_message
170599                                     (p_appli_s_name            => 'XLA'
170600                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
170601                                     ,p_token_1                 => 'LINE_NUMBER'
170602                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
170606                                                                             ,l_component_code
170603                                     ,p_token_2                 => 'LINE_TYPE_NAME'
170604                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
170605                                                                              l_component_type
170607                                                                             ,l_component_type_code
170608                                                                             ,l_component_appl_id
170609                                                                             ,l_amb_context_code
170610                                                                             ,l_entity_code
170611                                                                             ,l_event_class_code
170612                                                                            )
170613                                     ,p_token_3                 => 'OWNER'
170614                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
170615                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
170616                                                                           ,p_lookup_code    => l_component_type_code
170617                                                                          )
170618                                     ,p_token_4                 => 'PRODUCT_NAME'
170619                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
170620                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
170621                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
170622                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
170623                                     ,p_ae_header_id            =>  NULL
170624                                        );
170625 
170626         IF (C_LEVEL_ERROR>= g_log_level) THEN
170627                  trace
170628                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
170629                       ,p_level    => C_LEVEL_ERROR
170630                       ,p_module   => l_log_module);
170631         END IF;
170632       END IF;
170633    END IF;
170634    --
170635    --
170636    ------------------------------------------------------------------------------------------------
170637    -- 4219869 Business Flow
170638    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
170639    -- Prior Entry.  Currently, the following code is always generated.
170640    ------------------------------------------------------------------------------------------------
170641    XLA_AE_LINES_PKG.ValidateCurrentLine;
170642 
170643    ------------------------------------------------------------------------------------
170644    -- 4219869 Business Flow
170645    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
170646    ------------------------------------------------------------------------------------
170647    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
170648 
170649    ----------------------------------------------------------------------------------
170650    -- 4219869 Business Flow
170651    -- Update journal entry status -- Need to generate this within IF <condition>
170652    ----------------------------------------------------------------------------------
170653    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
170654          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
170655          ,p_balance_type_code => l_balance_type_code
170656          );
170657 
170658    -------------------------------------------------------------------------------------------
170659    -- 4262811 - Generate the Accrual Reversal lines
170660    -------------------------------------------------------------------------------------------
170661    BEGIN
170662       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
170663                               (g_array_event(p_event_id).array_value_num('header_index'));
170664       IF l_acc_rev_flag IS NULL THEN
170665          l_acc_rev_flag := 'N';
170666       END IF;
170667    EXCEPTION
170668       WHEN OTHERS THEN
170669          l_acc_rev_flag := 'N';
170670    END;
170671    --
170672    IF (l_acc_rev_flag = 'Y') THEN
170673 
170674        -- 4645092  ------------------------------------------------------------------------------
170675        -- To allow MPA report to determine if it should generate report process
170676        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
170677        ------------------------------------------------------------------------------------------
170678 
170679        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
170680        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
170681    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
170682    -- call ADRs
170683    -- Bug 4922099
170684    --
170685    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
170686         (NVL(l_actual_upg_option, 'N') = 'O') OR
170687         (NVL(l_enc_upg_option, 'N') = 'O')
170688       )
170689    THEN
170690    NULL;
170691    --
170692    --
170693    
170694   l_ccid := AcctDerRule_174(
170695            p_application_id           => p_application_id
170696          , p_ae_header_id             => l_ae_header_id 
170697 , p_source_3 => p_source_3
170698 , p_source_17 => p_source_17
170699 , p_source_30 => p_source_30
170700          , x_transaction_coa_id       => l_adr_transaction_coa_id
170701          , x_accounting_coa_id        => l_adr_accounting_coa_id
170702          , x_value_type_code          => l_adr_value_type_code
170703          , p_side                     => 'NA'
170704    );
170705 
170706    xla_ae_lines_pkg.set_ccid(
170707     p_code_combination_id          => l_ccid
170711   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
170708   , p_value_type_code              => l_adr_value_type_code
170709   , p_transaction_coa_id           => l_adr_transaction_coa_id
170710   , p_accounting_coa_id            => l_adr_accounting_coa_id
170712   , p_adr_type_code                => 'S'
170713   , p_component_type               => l_component_type
170714   , p_component_code               => l_component_code
170715   , p_component_type_code          => l_component_type_code
170716   , p_component_appl_id            => l_component_appl_id
170717   , p_amb_context_code             => l_amb_context_code
170718   , p_side                         => 'NA'
170719   );
170720 
170721 
170722    l_segment := AcctDerRule_150(
170723            p_application_id           => p_application_id
170724          , p_ae_header_id             => l_ae_header_id 
170725 , p_source_3 => p_source_3
170726 , p_source_11 => p_source_11
170727          , x_transaction_coa_id       => l_adr_transaction_coa_id
170728          , x_accounting_coa_id        => l_adr_accounting_coa_id
170729          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
170730          , x_flex_value_set_id        => l_adr_flex_value_set_id
170731          , x_value_type_code          => l_adr_value_type_code
170732          , x_value_combination_id     => l_adr_value_combination_id
170733          , x_value_segment_code       => l_adr_value_segment_code
170734          , p_side                     => 'NA'
170735          , p_override_seg_flag        => 'Y'
170736    );
170737 
170738    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
170739 
170740       xla_ae_lines_pkg.set_segment(
170741           p_to_segment_code         => 'GL_ACCOUNT'
170742         , p_segment_value           => l_segment
170743         , p_from_segment_code       => l_adr_value_segment_code
170744         , p_from_combination_id     => l_adr_value_combination_id
170745         , p_value_type_code         => l_adr_value_type_code
170746         , p_transaction_coa_id      => l_adr_transaction_coa_id
170747         , p_accounting_coa_id       => l_adr_accounting_coa_id
170748         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
170749         , p_flex_value_set_id       => l_adr_flex_value_set_id
170750         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
170751         , p_adr_type_code           => 'S'
170752         , p_component_type          => l_component_type
170753         , p_component_code          => l_component_code
170754         , p_component_type_code     => l_component_type_code
170755         , p_component_appl_id       => l_component_appl_id
170756         , p_amb_context_code        => l_amb_context_code
170757         , p_entity_code             => 'TRANSACTIONS'
170758         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
170759         , p_side                    => 'NA'
170760         );
170761 
170762   END IF;
170763 
170764    l_segment := AcctDerRule_168(
170765            p_application_id           => p_application_id
170766          , p_ae_header_id             => l_ae_header_id 
170767 , p_source_3 => p_source_3
170768 , p_source_29 => p_source_29
170769          , x_transaction_coa_id       => l_adr_transaction_coa_id
170770          , x_accounting_coa_id        => l_adr_accounting_coa_id
170771          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
170772          , x_flex_value_set_id        => l_adr_flex_value_set_id
170773          , x_value_type_code          => l_adr_value_type_code
170774          , x_value_combination_id     => l_adr_value_combination_id
170775          , x_value_segment_code       => l_adr_value_segment_code
170776          , p_side                     => 'NA'
170777          , p_override_seg_flag        => 'Y'
170778    );
170779 
170780    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
170781 
170782       xla_ae_lines_pkg.set_segment(
170783           p_to_segment_code         => 'GL_BALANCING'
170784         , p_segment_value           => l_segment
170785         , p_from_segment_code       => l_adr_value_segment_code
170786         , p_from_combination_id     => l_adr_value_combination_id
170787         , p_value_type_code         => l_adr_value_type_code
170788         , p_transaction_coa_id      => l_adr_transaction_coa_id
170789         , p_accounting_coa_id       => l_adr_accounting_coa_id
170790         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
170791         , p_flex_value_set_id       => l_adr_flex_value_set_id
170792         , p_adr_code                => 'FA_EXPENSE_ACCT'
170793         , p_adr_type_code           => 'S'
170794         , p_component_type          => l_component_type
170795         , p_component_code          => l_component_code
170796         , p_component_type_code     => l_component_type_code
170797         , p_component_appl_id       => l_component_appl_id
170798         , p_amb_context_code        => l_amb_context_code
170799         , p_entity_code             => 'TRANSACTIONS'
170800         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
170801         , p_side                    => 'NA'
170802         );
170803 
170804   END IF;
170805 
170806    --
170807    --
170808    END IF;
170809 
170810        --
170811        -- Update the line information that should be overwritten
170812        --
170813        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
170814                                          p_header_num   => 1);
170815        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
170816 
170817        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
170818 
170819        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
170820           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
170821        END IF;
170822 
170823       --
170824       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
170825       --
170829           ---------------------------------------------------------------------------------------------------
170826       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
170827           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
170828       ELSE
170830           -- 4262811a Switch Sign
170831           ---------------------------------------------------------------------------------------------------
170832           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
170833           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
170834                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
170835           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
170836                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
170837           -- 5132302
170838           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
170839                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
170840 
170841       END IF;
170842 
170843       -- 4955764
170844       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
170845       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
170846 
170847 
170848       XLA_AE_LINES_PKG.ValidateCurrentLine;
170849       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
170850 
170851       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
170852                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
170853                ,p_balance_type_code => l_balance_type_code);
170854 
170855    END IF;
170856 
170857    -----------------------------------------------------------------------------------------
170858    -- 4262811 Multiperiod Accounting
170859    -----------------------------------------------------------------------------------------
170860      -- No MPA option is assigned.
170861 
170862 
170863 END IF;
170864 END IF;
170865 --
170866 
170867 --
170868 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
170869    trace
170870       (p_msg      => 'END of AcctLineType_394'
170871       ,p_level    => C_LEVEL_PROCEDURE
170872       ,p_module   => l_log_module);
170873 END IF;
170874 --
170875 EXCEPTION
170876   WHEN xla_exceptions_pkg.application_exception THEN
170877       RAISE;
170878   WHEN OTHERS THEN
170879        xla_exceptions_pkg.raise_message
170880            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_394');
170881 END AcctLineType_394;
170882 --
170883 
170884 ---------------------------------------
170885 --
170886 -- PRIVATE FUNCTION
170887 --         AcctLineType_395
170888 --
170889 ---------------------------------------
170890 PROCEDURE AcctLineType_395 (
170891   p_application_id        IN NUMBER
170892  ,p_event_id              IN NUMBER
170893  ,p_calculate_acctd_flag  IN VARCHAR2
170894  ,p_calculate_g_l_flag    IN VARCHAR2
170895  ,p_actual_flag           IN OUT VARCHAR2
170896  ,p_balance_type_code     OUT VARCHAR2
170897  ,p_gain_or_loss_ref      OUT VARCHAR2
170898  
170899 --Period Close Date
170900  , p_source_1            IN DATE
170901 --Generated Code Combination Identifier
170902  , p_source_3            IN NUMBER
170903 --Intercompany Payables Account
170904  , p_source_19            IN VARCHAR2
170905 --Expense Account Code Combination Identifier
170906  , p_source_29            IN NUMBER
170907 --Default Code Combination Identifier
170908  , p_source_30            IN NUMBER
170909 --Adjustment Type
170910  , p_source_35            IN VARCHAR2
170911 --Transaction Header Identifier
170912  , p_source_36            IN NUMBER
170913 --Adjustment Line Identifier
170914  , p_source_37            IN NUMBER
170915 --Distribution Type Code
170916  , p_source_38            IN VARCHAR2
170917 --Entered Amount
170918  , p_source_39            IN NUMBER
170919 --Currency Code
170920  , p_source_40            IN VARCHAR2
170921 )
170922 IS
170923 
170924 l_component_type              VARCHAR2(80);
170925 l_component_code              VARCHAR2(30);
170926 l_component_type_code         VARCHAR2(1);
170927 l_component_appl_id           INTEGER;
170928 l_amb_context_code            VARCHAR2(30);
170929 l_entity_code                 VARCHAR2(30);
170930 l_event_class_code            VARCHAR2(30);
170931 l_ae_header_id                NUMBER;
170932 l_event_type_code             VARCHAR2(30);
170933 l_line_definition_code        VARCHAR2(30);
170934 l_line_definition_owner_code  VARCHAR2(1);
170935 --
170936 -- adr variables
170937 l_segment                     VARCHAR2(30);
170938 l_ccid                        NUMBER;
170939 l_adr_transaction_coa_id      NUMBER;
170940 l_adr_accounting_coa_id       NUMBER;
170941 l_adr_flexfield_segment_code  VARCHAR2(30);
170942 l_adr_flex_value_set_id       NUMBER;
170943 l_adr_value_type_code         VARCHAR2(30);
170944 l_adr_value_combination_id    NUMBER;
170945 l_adr_value_segment_code      VARCHAR2(30);
170946 
170947 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
170948 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
170949 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
170950 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
170951 
170952 -- 4262811 Variables ------------------------------------------------------------------------------------------
170953 l_entered_amt_idx             NUMBER;
170954 l_accted_amt_idx              NUMBER;
170955 l_acc_rev_flag                VARCHAR2(1);
170956 l_accrual_line_num            NUMBER;
170957 l_tmp_amt                     NUMBER;
170958 l_acc_rev_natural_side_code   VARCHAR2(1);
170962 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
170959 
170960 l_num_entries                 NUMBER;
170961 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
170963 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
170964 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
170965 l_recog_line_1                NUMBER;
170966 l_recog_line_2                NUMBER;
170967 
170968 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
170969 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
170970 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
170971 
170972 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
170973 
170974 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
170975 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
170976 
170977 ---------------------------------------------------------------------------------------------------------------
170978 
170979 
170980 --
170981 -- bulk performance
170982 --
170983 l_balance_type_code           VARCHAR2(1);
170984 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
170985 l_log_module                  VARCHAR2(240);
170986 
170987 --
170988 -- Upgrade strategy
170989 --
170990 l_actual_upg_option           VARCHAR2(1);
170991 l_enc_upg_option           VARCHAR2(1);
170992 
170993 --
170994 BEGIN
170995 --
170996 IF g_log_enabled THEN
170997       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_395';
170998 END IF;
170999 --
171000 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
171001 
171002       trace
171003          (p_msg      => 'BEGIN of AcctLineType_395'
171004          ,p_level    => C_LEVEL_PROCEDURE
171005          ,p_module   => l_log_module);
171006 
171007 END IF;
171008 --
171009 l_component_type             := 'AMB_JLT';
171010 l_component_code             := 'FA_UNITADJ_IC_PAY';
171011 l_component_type_code        := 'S';
171012 l_component_appl_id          :=  140;
171013 l_amb_context_code           := 'DEFAULT';
171014 l_entity_code                := 'TRANSACTIONS';
171015 l_event_class_code           := 'UNIT_ADJUSTMENTS';
171016 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
171017 l_line_definition_owner_code := 'S';
171018 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
171019 --
171020 l_balance_type_code          := 'A';
171021 l_segment                     := NULL;
171022 l_ccid                        := NULL;
171023 l_adr_transaction_coa_id      := NULL;
171024 l_adr_accounting_coa_id       := NULL;
171025 l_adr_flexfield_segment_code  := NULL;
171026 l_adr_flex_value_set_id       := NULL;
171027 l_adr_value_type_code         := NULL;
171028 l_adr_value_combination_id    := NULL;
171029 l_adr_value_segment_code      := NULL;
171030 
171031 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
171032 l_bflow_class_code           := '';    -- 4219869 Business Flow
171033 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
171034 l_budgetary_control_flag     := 'N';
171035 
171036 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
171037 l_bflow_applied_to_amt       := NULL; -- 5132302
171038 l_entered_amt_idx            := NULL;          -- 4262811
171039 l_accted_amt_idx             := NULL;          -- 4262811
171040 l_acc_rev_flag               := NULL;          -- 4262811
171041 l_accrual_line_num           := NULL;          -- 4262811
171042 l_tmp_amt                    := NULL;          -- 4262811
171043 --
171044  
171045 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
171046     l_balance_type_code <> 'B' THEN
171047 IF NVL(p_source_35,'
171048 ') =  'INTERCO AP'
171049  THEN 
171050 
171051    --
171052    XLA_AE_LINES_PKG.SetNewLine;
171053 
171054    p_balance_type_code          := l_balance_type_code;
171055    -- set the flag so later we will know whether the gain loss line needs to be created
171056    
171057    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
171058      p_actual_flag :='A';
171059    END IF;
171060 
171061    --
171062    -- bulk performance
171063    --
171064    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
171065                                       p_header_num   => 0); -- 4262811
171066    --
171067    -- set accounting line options
171068    --
171069    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
171070            p_natural_side_code          => 'C'
171071          , p_gain_or_loss_flag          => 'N'
171072          , p_gl_transfer_mode_code      => 'S'
171073          , p_acct_entry_type_code       => 'A'
171074          , p_switch_side_flag           => 'Y'
171075          , p_merge_duplicate_code       => 'N'
171076          );
171077    --
171078    l_acc_rev_natural_side_code := 'D';  -- 4262811
171079    -- 
171080    --
171081    -- set accounting line type info
171082    --
171083    xla_ae_lines_pkg.SetAcctLineType
171084       (p_component_type             => l_component_type
171085       ,p_event_type_code            => l_event_type_code
171086       ,p_line_definition_owner_code => l_line_definition_owner_code
171087       ,p_line_definition_code       => l_line_definition_code
171088       ,p_accounting_line_code       => l_component_code
171089       ,p_accounting_line_type_code  => l_component_type_code
171090       ,p_accounting_line_appl_id    => l_component_appl_id
171091       ,p_amb_context_code           => l_amb_context_code
171092       ,p_entity_code                => l_entity_code
171093       ,p_event_class_code           => l_event_class_code);
171094    --
171095    -- set accounting class
171096    --
171097    xla_ae_lines_pkg.SetAcctClass(
171098            p_accounting_class_code  => 'LIABILITY'
171102    --
171099          , p_ae_header_id           => l_ae_header_id
171100          );
171101 
171103    -- set rounding class
171104    --
171105    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
171106                       'LIABILITY';
171107 
171108    --
171109    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
171110    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
171111    --
171112    -- bulk performance
171113    --
171114    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
171115 
171116    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
171117       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
171118 
171119    -- 4955764
171120    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
171121       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
171122 
171123    -- 4458381 Public Sector Enh
171124    
171125    --
171126    -- set accounting attributes for the line type
171127    --
171128    l_entered_amt_idx := 4;
171129    l_accted_amt_idx  := 6;
171130    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
171131    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
171132    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
171133    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
171134    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
171135    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
171136    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
171137    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
171138    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
171139    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
171140    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
171141    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
171142    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
171143 
171144    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
171145    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
171146 
171147    ---------------------------------------------------------------------------------------------------------------
171148    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
171149    ---------------------------------------------------------------------------------------------------------------
171150    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
171151 
171152    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
171153    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
171154 
171155    IF xla_accounting_cache_pkg.GetValueChar
171156          (p_source_code         => 'LEDGER_CATEGORY_CODE'
171157          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
171158    AND l_bflow_method_code = 'PRIOR_ENTRY'
171159 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
171160    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
171161          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
171162        )
171163    THEN
171164          xla_ae_lines_pkg.BflowUpgEntry
171165            (p_business_method_code    => l_bflow_method_code
171166            ,p_business_class_code     => l_bflow_class_code
171167            ,p_balance_type            => l_balance_type_code);
171168    ELSE
171169       NULL;
171170 -- No business flow processing for business flow method of NONE.
171171    END IF;
171172 
171173    --
171174    -- call analytical criteria
171175    --
171176    
171177    --
171178    -- call description
171179    --
171180    
171181 xla_ae_lines_pkg.SetLineDescription(
171182    p_ae_header_id => l_ae_header_id
171183   ,p_description  => Description_135 (
171184      p_application_id         => p_application_id
171185    , p_ae_header_id           => l_ae_header_id 
171186 , p_source_1 => p_source_1
171187    )
171188 );
171189 
171190 
171191    --
171192    -- call ADRs
171193    -- Bug 4922099
171194    --
171195    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
171196         (NVL(l_actual_upg_option, 'N') = 'O') OR
171197         (NVL(l_enc_upg_option, 'N') = 'O')
171198       )
171199    THEN
171200    NULL;
171201    --
171202    --
171203    
171204   l_ccid := AcctDerRule_173(
171205            p_application_id           => p_application_id
171206          , p_ae_header_id             => l_ae_header_id 
171207 , p_source_3 => p_source_3
171208 , p_source_30 => p_source_30
171209          , x_transaction_coa_id       => l_adr_transaction_coa_id
171210          , x_accounting_coa_id        => l_adr_accounting_coa_id
171211          , x_value_type_code          => l_adr_value_type_code
171212          , p_side                     => 'NA'
171213    );
171214 
171215    xla_ae_lines_pkg.set_ccid(
171216     p_code_combination_id          => l_ccid
171217   , p_value_type_code              => l_adr_value_type_code
171218   , p_transaction_coa_id           => l_adr_transaction_coa_id
171219   , p_accounting_coa_id            => l_adr_accounting_coa_id
171220   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
171221   , p_adr_type_code                => 'S'
171222   , p_component_type               => l_component_type
171223   , p_component_code               => l_component_code
171224   , p_component_type_code          => l_component_type_code
171225   , p_component_appl_id            => l_component_appl_id
171226   , p_amb_context_code             => l_amb_context_code
171230 
171227   , p_side                         => 'NA'
171228   );
171229 
171231    l_segment := AcctDerRule_168(
171232            p_application_id           => p_application_id
171233          , p_ae_header_id             => l_ae_header_id 
171234 , p_source_3 => p_source_3
171235 , p_source_29 => p_source_29
171236          , x_transaction_coa_id       => l_adr_transaction_coa_id
171237          , x_accounting_coa_id        => l_adr_accounting_coa_id
171238          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
171239          , x_flex_value_set_id        => l_adr_flex_value_set_id
171240          , x_value_type_code          => l_adr_value_type_code
171241          , x_value_combination_id     => l_adr_value_combination_id
171242          , x_value_segment_code       => l_adr_value_segment_code
171243          , p_side                     => 'NA'
171244          , p_override_seg_flag        => 'Y'
171245    );
171246 
171247    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
171248 
171249       xla_ae_lines_pkg.set_segment(
171250           p_to_segment_code         => 'GL_BALANCING'
171251         , p_segment_value           => l_segment
171252         , p_from_segment_code       => l_adr_value_segment_code
171253         , p_from_combination_id     => l_adr_value_combination_id
171254         , p_value_type_code         => l_adr_value_type_code
171255         , p_transaction_coa_id      => l_adr_transaction_coa_id
171256         , p_accounting_coa_id       => l_adr_accounting_coa_id
171257         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
171258         , p_flex_value_set_id       => l_adr_flex_value_set_id
171259         , p_adr_code                => 'FA_EXPENSE_ACCT'
171260         , p_adr_type_code           => 'S'
171261         , p_component_type          => l_component_type
171262         , p_component_code          => l_component_code
171263         , p_component_type_code     => l_component_type_code
171264         , p_component_appl_id       => l_component_appl_id
171265         , p_amb_context_code        => l_amb_context_code
171266         , p_entity_code             => 'TRANSACTIONS'
171267         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
171268         , p_side                    => 'NA'
171269         );
171270 
171271   END IF;
171272 
171273    l_segment := AcctDerRule_157(
171274            p_application_id           => p_application_id
171275          , p_ae_header_id             => l_ae_header_id 
171276 , p_source_3 => p_source_3
171277 , p_source_19 => p_source_19
171278          , x_transaction_coa_id       => l_adr_transaction_coa_id
171279          , x_accounting_coa_id        => l_adr_accounting_coa_id
171280          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
171281          , x_flex_value_set_id        => l_adr_flex_value_set_id
171282          , x_value_type_code          => l_adr_value_type_code
171283          , x_value_combination_id     => l_adr_value_combination_id
171284          , x_value_segment_code       => l_adr_value_segment_code
171285          , p_side                     => 'NA'
171286          , p_override_seg_flag        => 'Y'
171287    );
171288 
171289    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
171290 
171291       xla_ae_lines_pkg.set_segment(
171292           p_to_segment_code         => 'GL_ACCOUNT'
171293         , p_segment_value           => l_segment
171294         , p_from_segment_code       => l_adr_value_segment_code
171295         , p_from_combination_id     => l_adr_value_combination_id
171296         , p_value_type_code         => l_adr_value_type_code
171297         , p_transaction_coa_id      => l_adr_transaction_coa_id
171298         , p_accounting_coa_id       => l_adr_accounting_coa_id
171299         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
171300         , p_flex_value_set_id       => l_adr_flex_value_set_id
171301         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
171302         , p_adr_type_code           => 'S'
171303         , p_component_type          => l_component_type
171304         , p_component_code          => l_component_code
171305         , p_component_type_code     => l_component_type_code
171306         , p_component_appl_id       => l_component_appl_id
171307         , p_amb_context_code        => l_amb_context_code
171308         , p_entity_code             => 'TRANSACTIONS'
171309         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
171310         , p_side                    => 'NA'
171311         );
171312 
171313   END IF;
171314 
171315    --
171316    --
171317    END IF;
171318    --
171319    -- Bug 4922099
171320    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
171321           (NVL(l_enc_upg_option, 'N') = 'O')
171322         ) AND
171323         (l_bflow_method_code = 'PRIOR_ENTRY')
171324       )
171325    THEN
171326       IF
171327       --
171328       1 = 2
171329       --
171330       THEN
171331       xla_accounting_err_pkg.build_message
171332                                     (p_appli_s_name            => 'XLA'
171333                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
171334                                     ,p_token_1                 => 'LINE_NUMBER'
171335                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
171336                                     ,p_token_2                 => 'LINE_TYPE_NAME'
171337                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
171338                                                                              l_component_type
171339                                                                             ,l_component_code
171340                                                                             ,l_component_type_code
171341                                                                             ,l_component_appl_id
171342                                                                             ,l_amb_context_code
171346                                     ,p_token_3                 => 'OWNER'
171343                                                                             ,l_entity_code
171344                                                                             ,l_event_class_code
171345                                                                            )
171347                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
171348                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
171349                                                                           ,p_lookup_code    => l_component_type_code
171350                                                                          )
171351                                     ,p_token_4                 => 'PRODUCT_NAME'
171352                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
171353                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
171354                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
171355                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
171356                                     ,p_ae_header_id            =>  NULL
171357                                        );
171358 
171359         IF (C_LEVEL_ERROR>= g_log_level) THEN
171360                  trace
171361                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
171362                       ,p_level    => C_LEVEL_ERROR
171363                       ,p_module   => l_log_module);
171364         END IF;
171365       END IF;
171366    END IF;
171367    --
171368    --
171369    ------------------------------------------------------------------------------------------------
171370    -- 4219869 Business Flow
171371    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
171372    -- Prior Entry.  Currently, the following code is always generated.
171373    ------------------------------------------------------------------------------------------------
171374    XLA_AE_LINES_PKG.ValidateCurrentLine;
171375 
171376    ------------------------------------------------------------------------------------
171377    -- 4219869 Business Flow
171378    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
171379    ------------------------------------------------------------------------------------
171380    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
171381 
171382    ----------------------------------------------------------------------------------
171383    -- 4219869 Business Flow
171384    -- Update journal entry status -- Need to generate this within IF <condition>
171385    ----------------------------------------------------------------------------------
171386    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
171387          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
171388          ,p_balance_type_code => l_balance_type_code
171389          );
171390 
171391    -------------------------------------------------------------------------------------------
171392    -- 4262811 - Generate the Accrual Reversal lines
171393    -------------------------------------------------------------------------------------------
171394    BEGIN
171395       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
171396                               (g_array_event(p_event_id).array_value_num('header_index'));
171397       IF l_acc_rev_flag IS NULL THEN
171398          l_acc_rev_flag := 'N';
171399       END IF;
171400    EXCEPTION
171401       WHEN OTHERS THEN
171402          l_acc_rev_flag := 'N';
171403    END;
171404    --
171405    IF (l_acc_rev_flag = 'Y') THEN
171406 
171407        -- 4645092  ------------------------------------------------------------------------------
171408        -- To allow MPA report to determine if it should generate report process
171409        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
171410        ------------------------------------------------------------------------------------------
171411 
171412        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
171413        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
171414    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
171415    -- call ADRs
171416    -- Bug 4922099
171417    --
171418    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
171419         (NVL(l_actual_upg_option, 'N') = 'O') OR
171420         (NVL(l_enc_upg_option, 'N') = 'O')
171421       )
171422    THEN
171423    NULL;
171424    --
171425    --
171426    
171427   l_ccid := AcctDerRule_173(
171428            p_application_id           => p_application_id
171429          , p_ae_header_id             => l_ae_header_id 
171430 , p_source_3 => p_source_3
171431 , p_source_30 => p_source_30
171432          , x_transaction_coa_id       => l_adr_transaction_coa_id
171433          , x_accounting_coa_id        => l_adr_accounting_coa_id
171434          , x_value_type_code          => l_adr_value_type_code
171435          , p_side                     => 'NA'
171436    );
171437 
171438    xla_ae_lines_pkg.set_ccid(
171439     p_code_combination_id          => l_ccid
171440   , p_value_type_code              => l_adr_value_type_code
171441   , p_transaction_coa_id           => l_adr_transaction_coa_id
171442   , p_accounting_coa_id            => l_adr_accounting_coa_id
171443   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
171444   , p_adr_type_code                => 'S'
171445   , p_component_type               => l_component_type
171446   , p_component_code               => l_component_code
171447   , p_component_type_code          => l_component_type_code
171448   , p_component_appl_id            => l_component_appl_id
171449   , p_amb_context_code             => l_amb_context_code
171450   , p_side                         => 'NA'
171451   );
171452 
171453 
171457 , p_source_3 => p_source_3
171454    l_segment := AcctDerRule_168(
171455            p_application_id           => p_application_id
171456          , p_ae_header_id             => l_ae_header_id 
171458 , p_source_29 => p_source_29
171459          , x_transaction_coa_id       => l_adr_transaction_coa_id
171460          , x_accounting_coa_id        => l_adr_accounting_coa_id
171461          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
171462          , x_flex_value_set_id        => l_adr_flex_value_set_id
171463          , x_value_type_code          => l_adr_value_type_code
171464          , x_value_combination_id     => l_adr_value_combination_id
171465          , x_value_segment_code       => l_adr_value_segment_code
171466          , p_side                     => 'NA'
171467          , p_override_seg_flag        => 'Y'
171468    );
171469 
171470    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
171471 
171472       xla_ae_lines_pkg.set_segment(
171473           p_to_segment_code         => 'GL_BALANCING'
171474         , p_segment_value           => l_segment
171475         , p_from_segment_code       => l_adr_value_segment_code
171476         , p_from_combination_id     => l_adr_value_combination_id
171477         , p_value_type_code         => l_adr_value_type_code
171478         , p_transaction_coa_id      => l_adr_transaction_coa_id
171479         , p_accounting_coa_id       => l_adr_accounting_coa_id
171480         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
171481         , p_flex_value_set_id       => l_adr_flex_value_set_id
171482         , p_adr_code                => 'FA_EXPENSE_ACCT'
171483         , p_adr_type_code           => 'S'
171484         , p_component_type          => l_component_type
171485         , p_component_code          => l_component_code
171486         , p_component_type_code     => l_component_type_code
171487         , p_component_appl_id       => l_component_appl_id
171488         , p_amb_context_code        => l_amb_context_code
171489         , p_entity_code             => 'TRANSACTIONS'
171490         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
171491         , p_side                    => 'NA'
171492         );
171493 
171494   END IF;
171495 
171496    l_segment := AcctDerRule_157(
171497            p_application_id           => p_application_id
171498          , p_ae_header_id             => l_ae_header_id 
171499 , p_source_3 => p_source_3
171500 , p_source_19 => p_source_19
171501          , x_transaction_coa_id       => l_adr_transaction_coa_id
171502          , x_accounting_coa_id        => l_adr_accounting_coa_id
171503          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
171504          , x_flex_value_set_id        => l_adr_flex_value_set_id
171505          , x_value_type_code          => l_adr_value_type_code
171506          , x_value_combination_id     => l_adr_value_combination_id
171507          , x_value_segment_code       => l_adr_value_segment_code
171508          , p_side                     => 'NA'
171509          , p_override_seg_flag        => 'Y'
171510    );
171511 
171512    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
171513 
171514       xla_ae_lines_pkg.set_segment(
171515           p_to_segment_code         => 'GL_ACCOUNT'
171516         , p_segment_value           => l_segment
171517         , p_from_segment_code       => l_adr_value_segment_code
171518         , p_from_combination_id     => l_adr_value_combination_id
171519         , p_value_type_code         => l_adr_value_type_code
171520         , p_transaction_coa_id      => l_adr_transaction_coa_id
171521         , p_accounting_coa_id       => l_adr_accounting_coa_id
171522         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
171523         , p_flex_value_set_id       => l_adr_flex_value_set_id
171524         , p_adr_code                => 'FA_IC_PAYABLE_ACCOUNT'
171525         , p_adr_type_code           => 'S'
171526         , p_component_type          => l_component_type
171527         , p_component_code          => l_component_code
171528         , p_component_type_code     => l_component_type_code
171529         , p_component_appl_id       => l_component_appl_id
171530         , p_amb_context_code        => l_amb_context_code
171531         , p_entity_code             => 'TRANSACTIONS'
171532         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
171533         , p_side                    => 'NA'
171534         );
171535 
171536   END IF;
171537 
171538    --
171539    --
171540    END IF;
171541 
171542        --
171543        -- Update the line information that should be overwritten
171544        --
171545        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
171546                                          p_header_num   => 1);
171547        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
171548 
171549        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
171550 
171551        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
171552           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
171553        END IF;
171554 
171555       --
171556       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
171557       --
171558       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
171559           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
171560       ELSE
171561           ---------------------------------------------------------------------------------------------------
171562           -- 4262811a Switch Sign
171563           ---------------------------------------------------------------------------------------------------
171564           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
171565           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
171569           -- 5132302
171566                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
171567           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
171568                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
171570           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
171571                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
171572 
171573       END IF;
171574 
171575       -- 4955764
171576       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
171577       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
171578 
171579 
171580       XLA_AE_LINES_PKG.ValidateCurrentLine;
171581       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
171582 
171583       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
171584                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
171585                ,p_balance_type_code => l_balance_type_code);
171586 
171587    END IF;
171588 
171589    -----------------------------------------------------------------------------------------
171590    -- 4262811 Multiperiod Accounting
171591    -----------------------------------------------------------------------------------------
171592      -- No MPA option is assigned.
171593 
171594 
171595 END IF;
171596 END IF;
171597 --
171598 
171599 --
171600 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
171601    trace
171602       (p_msg      => 'END of AcctLineType_395'
171603       ,p_level    => C_LEVEL_PROCEDURE
171604       ,p_module   => l_log_module);
171605 END IF;
171606 --
171607 EXCEPTION
171608   WHEN xla_exceptions_pkg.application_exception THEN
171609       RAISE;
171610   WHEN OTHERS THEN
171611        xla_exceptions_pkg.raise_message
171612            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_395');
171613 END AcctLineType_395;
171614 --
171615 
171616 ---------------------------------------
171617 --
171618 -- PRIVATE FUNCTION
171619 --         AcctLineType_396
171620 --
171621 ---------------------------------------
171622 PROCEDURE AcctLineType_396 (
171623   p_application_id        IN NUMBER
171624  ,p_event_id              IN NUMBER
171625  ,p_calculate_acctd_flag  IN VARCHAR2
171626  ,p_calculate_g_l_flag    IN VARCHAR2
171627  ,p_actual_flag           IN OUT VARCHAR2
171628  ,p_balance_type_code     OUT VARCHAR2
171629  ,p_gain_or_loss_ref      OUT VARCHAR2
171630  
171631 --Period Close Date
171632  , p_source_1            IN DATE
171633 --Generated Code Combination Identifier
171634  , p_source_3            IN NUMBER
171635 --Intercompany Receivables Account
171636  , p_source_20            IN VARCHAR2
171637 --Expense Account Code Combination Identifier
171638  , p_source_29            IN NUMBER
171639 --Default Code Combination Identifier
171640  , p_source_30            IN NUMBER
171641 --Adjustment Type
171642  , p_source_35            IN VARCHAR2
171643 --Transaction Header Identifier
171644  , p_source_36            IN NUMBER
171645 --Adjustment Line Identifier
171646  , p_source_37            IN NUMBER
171647 --Distribution Type Code
171648  , p_source_38            IN VARCHAR2
171649 --Entered Amount
171650  , p_source_39            IN NUMBER
171651 --Currency Code
171652  , p_source_40            IN VARCHAR2
171653 )
171654 IS
171655 
171656 l_component_type              VARCHAR2(80);
171657 l_component_code              VARCHAR2(30);
171658 l_component_type_code         VARCHAR2(1);
171659 l_component_appl_id           INTEGER;
171660 l_amb_context_code            VARCHAR2(30);
171661 l_entity_code                 VARCHAR2(30);
171662 l_event_class_code            VARCHAR2(30);
171663 l_ae_header_id                NUMBER;
171664 l_event_type_code             VARCHAR2(30);
171665 l_line_definition_code        VARCHAR2(30);
171666 l_line_definition_owner_code  VARCHAR2(1);
171667 --
171668 -- adr variables
171669 l_segment                     VARCHAR2(30);
171670 l_ccid                        NUMBER;
171671 l_adr_transaction_coa_id      NUMBER;
171672 l_adr_accounting_coa_id       NUMBER;
171673 l_adr_flexfield_segment_code  VARCHAR2(30);
171674 l_adr_flex_value_set_id       NUMBER;
171675 l_adr_value_type_code         VARCHAR2(30);
171676 l_adr_value_combination_id    NUMBER;
171677 l_adr_value_segment_code      VARCHAR2(30);
171678 
171679 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
171680 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
171681 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
171682 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
171683 
171684 -- 4262811 Variables ------------------------------------------------------------------------------------------
171685 l_entered_amt_idx             NUMBER;
171686 l_accted_amt_idx              NUMBER;
171687 l_acc_rev_flag                VARCHAR2(1);
171688 l_accrual_line_num            NUMBER;
171689 l_tmp_amt                     NUMBER;
171690 l_acc_rev_natural_side_code   VARCHAR2(1);
171691 
171692 l_num_entries                 NUMBER;
171693 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
171694 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
171695 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
171696 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
171697 l_recog_line_1                NUMBER;
171698 l_recog_line_2                NUMBER;
171699 
171700 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
171701 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
171702 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
171706 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
171703 
171704 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
171705 
171707 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
171708 
171709 ---------------------------------------------------------------------------------------------------------------
171710 
171711 
171712 --
171713 -- bulk performance
171714 --
171715 l_balance_type_code           VARCHAR2(1);
171716 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
171717 l_log_module                  VARCHAR2(240);
171718 
171719 --
171720 -- Upgrade strategy
171721 --
171722 l_actual_upg_option           VARCHAR2(1);
171723 l_enc_upg_option           VARCHAR2(1);
171724 
171725 --
171726 BEGIN
171727 --
171728 IF g_log_enabled THEN
171729       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_396';
171730 END IF;
171731 --
171732 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
171733 
171734       trace
171735          (p_msg      => 'BEGIN of AcctLineType_396'
171736          ,p_level    => C_LEVEL_PROCEDURE
171737          ,p_module   => l_log_module);
171738 
171739 END IF;
171740 --
171741 l_component_type             := 'AMB_JLT';
171742 l_component_code             := 'FA_UNITADJ_IC_REC';
171743 l_component_type_code        := 'S';
171744 l_component_appl_id          :=  140;
171745 l_amb_context_code           := 'DEFAULT';
171746 l_entity_code                := 'TRANSACTIONS';
171747 l_event_class_code           := 'UNIT_ADJUSTMENTS';
171748 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
171749 l_line_definition_owner_code := 'S';
171750 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
171751 --
171752 l_balance_type_code          := 'A';
171753 l_segment                     := NULL;
171754 l_ccid                        := NULL;
171755 l_adr_transaction_coa_id      := NULL;
171756 l_adr_accounting_coa_id       := NULL;
171757 l_adr_flexfield_segment_code  := NULL;
171758 l_adr_flex_value_set_id       := NULL;
171759 l_adr_value_type_code         := NULL;
171760 l_adr_value_combination_id    := NULL;
171761 l_adr_value_segment_code      := NULL;
171762 
171763 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
171764 l_bflow_class_code           := '';    -- 4219869 Business Flow
171765 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
171766 l_budgetary_control_flag     := 'N';
171767 
171768 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
171769 l_bflow_applied_to_amt       := NULL; -- 5132302
171770 l_entered_amt_idx            := NULL;          -- 4262811
171771 l_accted_amt_idx             := NULL;          -- 4262811
171772 l_acc_rev_flag               := NULL;          -- 4262811
171773 l_accrual_line_num           := NULL;          -- 4262811
171774 l_tmp_amt                    := NULL;          -- 4262811
171775 --
171776  
171777 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
171778     l_balance_type_code <> 'B' THEN
171779 IF NVL(p_source_35,'
171780 ') =  'INTERCO AR'
171781  THEN 
171782 
171783    --
171784    XLA_AE_LINES_PKG.SetNewLine;
171785 
171786    p_balance_type_code          := l_balance_type_code;
171787    -- set the flag so later we will know whether the gain loss line needs to be created
171788    
171789    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
171790      p_actual_flag :='A';
171791    END IF;
171792 
171793    --
171794    -- bulk performance
171795    --
171796    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
171797                                       p_header_num   => 0); -- 4262811
171798    --
171799    -- set accounting line options
171800    --
171801    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
171802            p_natural_side_code          => 'D'
171803          , p_gain_or_loss_flag          => 'N'
171804          , p_gl_transfer_mode_code      => 'S'
171805          , p_acct_entry_type_code       => 'A'
171806          , p_switch_side_flag           => 'Y'
171807          , p_merge_duplicate_code       => 'N'
171808          );
171809    --
171810    l_acc_rev_natural_side_code := 'C';  -- 4262811
171811    -- 
171812    --
171813    -- set accounting line type info
171814    --
171815    xla_ae_lines_pkg.SetAcctLineType
171816       (p_component_type             => l_component_type
171817       ,p_event_type_code            => l_event_type_code
171818       ,p_line_definition_owner_code => l_line_definition_owner_code
171819       ,p_line_definition_code       => l_line_definition_code
171820       ,p_accounting_line_code       => l_component_code
171821       ,p_accounting_line_type_code  => l_component_type_code
171822       ,p_accounting_line_appl_id    => l_component_appl_id
171823       ,p_amb_context_code           => l_amb_context_code
171824       ,p_entity_code                => l_entity_code
171825       ,p_event_class_code           => l_event_class_code);
171826    --
171827    -- set accounting class
171828    --
171829    xla_ae_lines_pkg.SetAcctClass(
171830            p_accounting_class_code  => 'ASSET'
171831          , p_ae_header_id           => l_ae_header_id
171832          );
171833 
171834    --
171835    -- set rounding class
171836    --
171837    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
171838                       'ASSET';
171839 
171840    --
171841    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
171842    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
171843    --
171844    -- bulk performance
171845    --
171849       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
171846    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
171847 
171848    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
171850 
171851    -- 4955764
171852    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
171853       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
171854 
171855    -- 4458381 Public Sector Enh
171856    
171857    --
171858    -- set accounting attributes for the line type
171859    --
171860    l_entered_amt_idx := 4;
171861    l_accted_amt_idx  := 6;
171862    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
171863    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
171864    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
171865    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
171866    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
171867    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
171868    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
171869    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
171870    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
171871    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
171872    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
171873    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
171874    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
171875 
171876    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
171877    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
171878 
171879    ---------------------------------------------------------------------------------------------------------------
171880    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
171881    ---------------------------------------------------------------------------------------------------------------
171882    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
171883 
171884    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
171885    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
171886 
171887    IF xla_accounting_cache_pkg.GetValueChar
171888          (p_source_code         => 'LEDGER_CATEGORY_CODE'
171889          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
171890    AND l_bflow_method_code = 'PRIOR_ENTRY'
171891 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
171892    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
171893          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
171894        )
171895    THEN
171896          xla_ae_lines_pkg.BflowUpgEntry
171897            (p_business_method_code    => l_bflow_method_code
171898            ,p_business_class_code     => l_bflow_class_code
171899            ,p_balance_type            => l_balance_type_code);
171900    ELSE
171901       NULL;
171902 -- No business flow processing for business flow method of NONE.
171903    END IF;
171904 
171905    --
171906    -- call analytical criteria
171907    --
171908    
171909    --
171910    -- call description
171911    --
171912    
171913 xla_ae_lines_pkg.SetLineDescription(
171914    p_ae_header_id => l_ae_header_id
171915   ,p_description  => Description_136 (
171916      p_application_id         => p_application_id
171917    , p_ae_header_id           => l_ae_header_id 
171918 , p_source_1 => p_source_1
171919    )
171920 );
171921 
171922 
171923    --
171924    -- call ADRs
171925    -- Bug 4922099
171926    --
171927    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
171928         (NVL(l_actual_upg_option, 'N') = 'O') OR
171929         (NVL(l_enc_upg_option, 'N') = 'O')
171930       )
171931    THEN
171932    NULL;
171933    --
171934    --
171935    
171936   l_ccid := AcctDerRule_173(
171937            p_application_id           => p_application_id
171938          , p_ae_header_id             => l_ae_header_id 
171939 , p_source_3 => p_source_3
171940 , p_source_30 => p_source_30
171941          , x_transaction_coa_id       => l_adr_transaction_coa_id
171942          , x_accounting_coa_id        => l_adr_accounting_coa_id
171943          , x_value_type_code          => l_adr_value_type_code
171944          , p_side                     => 'NA'
171945    );
171946 
171947    xla_ae_lines_pkg.set_ccid(
171948     p_code_combination_id          => l_ccid
171949   , p_value_type_code              => l_adr_value_type_code
171950   , p_transaction_coa_id           => l_adr_transaction_coa_id
171951   , p_accounting_coa_id            => l_adr_accounting_coa_id
171952   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
171953   , p_adr_type_code                => 'S'
171954   , p_component_type               => l_component_type
171955   , p_component_code               => l_component_code
171956   , p_component_type_code          => l_component_type_code
171957   , p_component_appl_id            => l_component_appl_id
171958   , p_amb_context_code             => l_amb_context_code
171959   , p_side                         => 'NA'
171960   );
171961 
171962 
171963    l_segment := AcctDerRule_168(
171964            p_application_id           => p_application_id
171965          , p_ae_header_id             => l_ae_header_id 
171966 , p_source_3 => p_source_3
171967 , p_source_29 => p_source_29
171968          , x_transaction_coa_id       => l_adr_transaction_coa_id
171969          , x_accounting_coa_id        => l_adr_accounting_coa_id
171970          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
171971          , x_flex_value_set_id        => l_adr_flex_value_set_id
171975          , p_side                     => 'NA'
171972          , x_value_type_code          => l_adr_value_type_code
171973          , x_value_combination_id     => l_adr_value_combination_id
171974          , x_value_segment_code       => l_adr_value_segment_code
171976          , p_override_seg_flag        => 'Y'
171977    );
171978 
171979    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
171980 
171981       xla_ae_lines_pkg.set_segment(
171982           p_to_segment_code         => 'GL_BALANCING'
171983         , p_segment_value           => l_segment
171984         , p_from_segment_code       => l_adr_value_segment_code
171985         , p_from_combination_id     => l_adr_value_combination_id
171986         , p_value_type_code         => l_adr_value_type_code
171987         , p_transaction_coa_id      => l_adr_transaction_coa_id
171988         , p_accounting_coa_id       => l_adr_accounting_coa_id
171989         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
171990         , p_flex_value_set_id       => l_adr_flex_value_set_id
171991         , p_adr_code                => 'FA_EXPENSE_ACCT'
171992         , p_adr_type_code           => 'S'
171993         , p_component_type          => l_component_type
171994         , p_component_code          => l_component_code
171995         , p_component_type_code     => l_component_type_code
171996         , p_component_appl_id       => l_component_appl_id
171997         , p_amb_context_code        => l_amb_context_code
171998         , p_entity_code             => 'TRANSACTIONS'
171999         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
172000         , p_side                    => 'NA'
172001         );
172002 
172003   END IF;
172004 
172005    l_segment := AcctDerRule_158(
172006            p_application_id           => p_application_id
172007          , p_ae_header_id             => l_ae_header_id 
172008 , p_source_3 => p_source_3
172009 , p_source_20 => p_source_20
172010          , x_transaction_coa_id       => l_adr_transaction_coa_id
172011          , x_accounting_coa_id        => l_adr_accounting_coa_id
172012          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
172013          , x_flex_value_set_id        => l_adr_flex_value_set_id
172014          , x_value_type_code          => l_adr_value_type_code
172015          , x_value_combination_id     => l_adr_value_combination_id
172016          , x_value_segment_code       => l_adr_value_segment_code
172017          , p_side                     => 'NA'
172018          , p_override_seg_flag        => 'Y'
172019    );
172020 
172021    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
172022 
172023       xla_ae_lines_pkg.set_segment(
172024           p_to_segment_code         => 'GL_ACCOUNT'
172025         , p_segment_value           => l_segment
172026         , p_from_segment_code       => l_adr_value_segment_code
172027         , p_from_combination_id     => l_adr_value_combination_id
172028         , p_value_type_code         => l_adr_value_type_code
172029         , p_transaction_coa_id      => l_adr_transaction_coa_id
172030         , p_accounting_coa_id       => l_adr_accounting_coa_id
172031         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
172032         , p_flex_value_set_id       => l_adr_flex_value_set_id
172033         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
172034         , p_adr_type_code           => 'S'
172035         , p_component_type          => l_component_type
172036         , p_component_code          => l_component_code
172037         , p_component_type_code     => l_component_type_code
172038         , p_component_appl_id       => l_component_appl_id
172039         , p_amb_context_code        => l_amb_context_code
172040         , p_entity_code             => 'TRANSACTIONS'
172041         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
172042         , p_side                    => 'NA'
172043         );
172044 
172045   END IF;
172046 
172047    --
172048    --
172049    END IF;
172050    --
172051    -- Bug 4922099
172052    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
172053           (NVL(l_enc_upg_option, 'N') = 'O')
172054         ) AND
172055         (l_bflow_method_code = 'PRIOR_ENTRY')
172056       )
172057    THEN
172058       IF
172059       --
172060       1 = 2
172061       --
172062       THEN
172063       xla_accounting_err_pkg.build_message
172064                                     (p_appli_s_name            => 'XLA'
172065                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
172066                                     ,p_token_1                 => 'LINE_NUMBER'
172067                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
172068                                     ,p_token_2                 => 'LINE_TYPE_NAME'
172069                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
172070                                                                              l_component_type
172071                                                                             ,l_component_code
172072                                                                             ,l_component_type_code
172073                                                                             ,l_component_appl_id
172074                                                                             ,l_amb_context_code
172075                                                                             ,l_entity_code
172076                                                                             ,l_event_class_code
172077                                                                            )
172078                                     ,p_token_3                 => 'OWNER'
172079                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
172080                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
172081                                                                           ,p_lookup_code    => l_component_type_code
172085                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
172082                                                                          )
172083                                     ,p_token_4                 => 'PRODUCT_NAME'
172084                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
172086                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
172087                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
172088                                     ,p_ae_header_id            =>  NULL
172089                                        );
172090 
172091         IF (C_LEVEL_ERROR>= g_log_level) THEN
172092                  trace
172093                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
172094                       ,p_level    => C_LEVEL_ERROR
172095                       ,p_module   => l_log_module);
172096         END IF;
172097       END IF;
172098    END IF;
172099    --
172100    --
172101    ------------------------------------------------------------------------------------------------
172102    -- 4219869 Business Flow
172103    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
172104    -- Prior Entry.  Currently, the following code is always generated.
172105    ------------------------------------------------------------------------------------------------
172106    XLA_AE_LINES_PKG.ValidateCurrentLine;
172107 
172108    ------------------------------------------------------------------------------------
172109    -- 4219869 Business Flow
172110    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
172111    ------------------------------------------------------------------------------------
172112    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
172113 
172114    ----------------------------------------------------------------------------------
172115    -- 4219869 Business Flow
172116    -- Update journal entry status -- Need to generate this within IF <condition>
172117    ----------------------------------------------------------------------------------
172118    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
172119          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
172120          ,p_balance_type_code => l_balance_type_code
172121          );
172122 
172123    -------------------------------------------------------------------------------------------
172124    -- 4262811 - Generate the Accrual Reversal lines
172125    -------------------------------------------------------------------------------------------
172126    BEGIN
172127       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
172128                               (g_array_event(p_event_id).array_value_num('header_index'));
172129       IF l_acc_rev_flag IS NULL THEN
172130          l_acc_rev_flag := 'N';
172131       END IF;
172132    EXCEPTION
172133       WHEN OTHERS THEN
172134          l_acc_rev_flag := 'N';
172135    END;
172136    --
172137    IF (l_acc_rev_flag = 'Y') THEN
172138 
172139        -- 4645092  ------------------------------------------------------------------------------
172140        -- To allow MPA report to determine if it should generate report process
172141        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
172142        ------------------------------------------------------------------------------------------
172143 
172144        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
172145        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
172146    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
172147    -- call ADRs
172148    -- Bug 4922099
172149    --
172150    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
172151         (NVL(l_actual_upg_option, 'N') = 'O') OR
172152         (NVL(l_enc_upg_option, 'N') = 'O')
172153       )
172154    THEN
172155    NULL;
172156    --
172157    --
172158    
172159   l_ccid := AcctDerRule_173(
172160            p_application_id           => p_application_id
172161          , p_ae_header_id             => l_ae_header_id 
172162 , p_source_3 => p_source_3
172163 , p_source_30 => p_source_30
172164          , x_transaction_coa_id       => l_adr_transaction_coa_id
172165          , x_accounting_coa_id        => l_adr_accounting_coa_id
172166          , x_value_type_code          => l_adr_value_type_code
172167          , p_side                     => 'NA'
172168    );
172169 
172170    xla_ae_lines_pkg.set_ccid(
172171     p_code_combination_id          => l_ccid
172172   , p_value_type_code              => l_adr_value_type_code
172173   , p_transaction_coa_id           => l_adr_transaction_coa_id
172174   , p_accounting_coa_id            => l_adr_accounting_coa_id
172175   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
172176   , p_adr_type_code                => 'S'
172177   , p_component_type               => l_component_type
172178   , p_component_code               => l_component_code
172179   , p_component_type_code          => l_component_type_code
172180   , p_component_appl_id            => l_component_appl_id
172181   , p_amb_context_code             => l_amb_context_code
172182   , p_side                         => 'NA'
172183   );
172184 
172185 
172186    l_segment := AcctDerRule_168(
172187            p_application_id           => p_application_id
172188          , p_ae_header_id             => l_ae_header_id 
172189 , p_source_3 => p_source_3
172190 , p_source_29 => p_source_29
172191          , x_transaction_coa_id       => l_adr_transaction_coa_id
172192          , x_accounting_coa_id        => l_adr_accounting_coa_id
172193          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
172194          , x_flex_value_set_id        => l_adr_flex_value_set_id
172195          , x_value_type_code          => l_adr_value_type_code
172196          , x_value_combination_id     => l_adr_value_combination_id
172200    );
172197          , x_value_segment_code       => l_adr_value_segment_code
172198          , p_side                     => 'NA'
172199          , p_override_seg_flag        => 'Y'
172201 
172202    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
172203 
172204       xla_ae_lines_pkg.set_segment(
172205           p_to_segment_code         => 'GL_BALANCING'
172206         , p_segment_value           => l_segment
172207         , p_from_segment_code       => l_adr_value_segment_code
172208         , p_from_combination_id     => l_adr_value_combination_id
172209         , p_value_type_code         => l_adr_value_type_code
172210         , p_transaction_coa_id      => l_adr_transaction_coa_id
172211         , p_accounting_coa_id       => l_adr_accounting_coa_id
172212         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
172213         , p_flex_value_set_id       => l_adr_flex_value_set_id
172214         , p_adr_code                => 'FA_EXPENSE_ACCT'
172215         , p_adr_type_code           => 'S'
172216         , p_component_type          => l_component_type
172217         , p_component_code          => l_component_code
172218         , p_component_type_code     => l_component_type_code
172219         , p_component_appl_id       => l_component_appl_id
172220         , p_amb_context_code        => l_amb_context_code
172221         , p_entity_code             => 'TRANSACTIONS'
172222         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
172223         , p_side                    => 'NA'
172224         );
172225 
172226   END IF;
172227 
172228    l_segment := AcctDerRule_158(
172229            p_application_id           => p_application_id
172230          , p_ae_header_id             => l_ae_header_id 
172231 , p_source_3 => p_source_3
172232 , p_source_20 => p_source_20
172233          , x_transaction_coa_id       => l_adr_transaction_coa_id
172234          , x_accounting_coa_id        => l_adr_accounting_coa_id
172235          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
172236          , x_flex_value_set_id        => l_adr_flex_value_set_id
172237          , x_value_type_code          => l_adr_value_type_code
172238          , x_value_combination_id     => l_adr_value_combination_id
172239          , x_value_segment_code       => l_adr_value_segment_code
172240          , p_side                     => 'NA'
172241          , p_override_seg_flag        => 'Y'
172242    );
172243 
172244    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
172245 
172246       xla_ae_lines_pkg.set_segment(
172247           p_to_segment_code         => 'GL_ACCOUNT'
172248         , p_segment_value           => l_segment
172249         , p_from_segment_code       => l_adr_value_segment_code
172250         , p_from_combination_id     => l_adr_value_combination_id
172251         , p_value_type_code         => l_adr_value_type_code
172252         , p_transaction_coa_id      => l_adr_transaction_coa_id
172253         , p_accounting_coa_id       => l_adr_accounting_coa_id
172254         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
172255         , p_flex_value_set_id       => l_adr_flex_value_set_id
172256         , p_adr_code                => 'FA_IC_RECEIVABLE_ACCOUNT'
172257         , p_adr_type_code           => 'S'
172258         , p_component_type          => l_component_type
172259         , p_component_code          => l_component_code
172260         , p_component_type_code     => l_component_type_code
172261         , p_component_appl_id       => l_component_appl_id
172262         , p_amb_context_code        => l_amb_context_code
172263         , p_entity_code             => 'TRANSACTIONS'
172264         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
172265         , p_side                    => 'NA'
172266         );
172267 
172268   END IF;
172269 
172270    --
172271    --
172272    END IF;
172273 
172274        --
172275        -- Update the line information that should be overwritten
172276        --
172277        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
172278                                          p_header_num   => 1);
172279        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
172280 
172281        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
172282 
172283        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
172284           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
172285        END IF;
172286 
172287       --
172288       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
172289       --
172290       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
172291           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
172292       ELSE
172293           ---------------------------------------------------------------------------------------------------
172294           -- 4262811a Switch Sign
172295           ---------------------------------------------------------------------------------------------------
172296           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
172297           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
172298                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
172299           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
172300                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
172301           -- 5132302
172302           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
172303                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
172304 
172305       END IF;
172306 
172307       -- 4955764
172311 
172308       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
172309       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
172310 
172312       XLA_AE_LINES_PKG.ValidateCurrentLine;
172313       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
172314 
172315       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
172316                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
172317                ,p_balance_type_code => l_balance_type_code);
172318 
172319    END IF;
172320 
172321    -----------------------------------------------------------------------------------------
172322    -- 4262811 Multiperiod Accounting
172323    -----------------------------------------------------------------------------------------
172324      -- No MPA option is assigned.
172325 
172326 
172327 END IF;
172328 END IF;
172329 --
172330 
172331 --
172332 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
172333    trace
172334       (p_msg      => 'END of AcctLineType_396'
172335       ,p_level    => C_LEVEL_PROCEDURE
172336       ,p_module   => l_log_module);
172337 END IF;
172338 --
172339 EXCEPTION
172340   WHEN xla_exceptions_pkg.application_exception THEN
172341       RAISE;
172342   WHEN OTHERS THEN
172343        xla_exceptions_pkg.raise_message
172344            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_396');
172345 END AcctLineType_396;
172346 --
172347 
172348 ---------------------------------------
172349 --
172350 -- PRIVATE FUNCTION
172351 --         AcctLineType_397
172352 --
172353 ---------------------------------------
172354 PROCEDURE AcctLineType_397 (
172355   p_application_id        IN NUMBER
172356  ,p_event_id              IN NUMBER
172357  ,p_calculate_acctd_flag  IN VARCHAR2
172358  ,p_calculate_g_l_flag    IN VARCHAR2
172359  ,p_actual_flag           IN OUT VARCHAR2
172360  ,p_balance_type_code     OUT VARCHAR2
172361  ,p_gain_or_loss_ref      OUT VARCHAR2
172362  
172363 --Period Close Date
172364  , p_source_1            IN DATE
172365 --Bonus Depreciation Expense Account
172366  , p_source_2            IN VARCHAR2
172367 --Generated Code Combination Identifier
172368  , p_source_3            IN NUMBER
172369 --Expense Account Code Combination Identifier
172370  , p_source_29            IN NUMBER
172371 --Adjustment Type
172372  , p_source_35            IN VARCHAR2
172373 --Transaction Header Identifier
172374  , p_source_36            IN NUMBER
172375 --Adjustment Line Identifier
172376  , p_source_37            IN NUMBER
172377 --Distribution Type Code
172378  , p_source_38            IN VARCHAR2
172379 --Entered Amount
172380  , p_source_39            IN NUMBER
172381 --Currency Code
172382  , p_source_40            IN VARCHAR2
172383 --Source Destination Code
172384  , p_source_42            IN VARCHAR2
172385 )
172386 IS
172387 
172388 l_component_type              VARCHAR2(80);
172389 l_component_code              VARCHAR2(30);
172390 l_component_type_code         VARCHAR2(1);
172391 l_component_appl_id           INTEGER;
172392 l_amb_context_code            VARCHAR2(30);
172393 l_entity_code                 VARCHAR2(30);
172394 l_event_class_code            VARCHAR2(30);
172395 l_ae_header_id                NUMBER;
172396 l_event_type_code             VARCHAR2(30);
172397 l_line_definition_code        VARCHAR2(30);
172398 l_line_definition_owner_code  VARCHAR2(1);
172399 --
172400 -- adr variables
172401 l_segment                     VARCHAR2(30);
172402 l_ccid                        NUMBER;
172403 l_adr_transaction_coa_id      NUMBER;
172404 l_adr_accounting_coa_id       NUMBER;
172405 l_adr_flexfield_segment_code  VARCHAR2(30);
172406 l_adr_flex_value_set_id       NUMBER;
172407 l_adr_value_type_code         VARCHAR2(30);
172408 l_adr_value_combination_id    NUMBER;
172409 l_adr_value_segment_code      VARCHAR2(30);
172410 
172411 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
172412 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
172413 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
172414 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
172415 
172416 -- 4262811 Variables ------------------------------------------------------------------------------------------
172417 l_entered_amt_idx             NUMBER;
172418 l_accted_amt_idx              NUMBER;
172419 l_acc_rev_flag                VARCHAR2(1);
172420 l_accrual_line_num            NUMBER;
172421 l_tmp_amt                     NUMBER;
172422 l_acc_rev_natural_side_code   VARCHAR2(1);
172423 
172424 l_num_entries                 NUMBER;
172425 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
172426 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
172427 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
172428 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
172429 l_recog_line_1                NUMBER;
172430 l_recog_line_2                NUMBER;
172431 
172432 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
172433 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
172434 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
172435 
172436 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
172437 
172438 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
172439 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
172440 
172441 ---------------------------------------------------------------------------------------------------------------
172442 
172443 
172444 --
172445 -- bulk performance
172446 --
172447 l_balance_type_code           VARCHAR2(1);
172448 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
172452 -- Upgrade strategy
172449 l_log_module                  VARCHAR2(240);
172450 
172451 --
172453 --
172454 l_actual_upg_option           VARCHAR2(1);
172455 l_enc_upg_option           VARCHAR2(1);
172456 
172457 --
172458 BEGIN
172459 --
172460 IF g_log_enabled THEN
172461       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_397';
172462 END IF;
172463 --
172464 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
172465 
172466       trace
172467          (p_msg      => 'BEGIN of AcctLineType_397'
172468          ,p_level    => C_LEVEL_PROCEDURE
172469          ,p_module   => l_log_module);
172470 
172471 END IF;
172472 --
172473 l_component_type             := 'AMB_JLT';
172474 l_component_code             := 'FA_UNITADJ_SOURCE_BONUS_EXP';
172475 l_component_type_code        := 'S';
172476 l_component_appl_id          :=  140;
172477 l_amb_context_code           := 'DEFAULT';
172478 l_entity_code                := 'TRANSACTIONS';
172479 l_event_class_code           := 'UNIT_ADJUSTMENTS';
172480 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
172481 l_line_definition_owner_code := 'S';
172482 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
172483 --
172484 l_balance_type_code          := 'A';
172485 l_segment                     := NULL;
172486 l_ccid                        := NULL;
172487 l_adr_transaction_coa_id      := NULL;
172488 l_adr_accounting_coa_id       := NULL;
172489 l_adr_flexfield_segment_code  := NULL;
172490 l_adr_flex_value_set_id       := NULL;
172491 l_adr_value_type_code         := NULL;
172492 l_adr_value_combination_id    := NULL;
172493 l_adr_value_segment_code      := NULL;
172494 
172495 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
172496 l_bflow_class_code           := '';    -- 4219869 Business Flow
172497 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
172498 l_budgetary_control_flag     := 'N';
172499 
172500 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
172501 l_bflow_applied_to_amt       := NULL; -- 5132302
172502 l_entered_amt_idx            := NULL;          -- 4262811
172503 l_accted_amt_idx             := NULL;          -- 4262811
172504 l_acc_rev_flag               := NULL;          -- 4262811
172505 l_accrual_line_num           := NULL;          -- 4262811
172506 l_tmp_amt                    := NULL;          -- 4262811
172507 --
172508  
172509 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
172510     l_balance_type_code <> 'B' THEN
172511 IF NVL(p_source_35,'
172512 ') =  'BONUS EXPENSE' AND 
172513 NVL(p_source_42,'
172514 ') =  'SOURCE'
172515  THEN 
172516 
172517    --
172518    XLA_AE_LINES_PKG.SetNewLine;
172519 
172520    p_balance_type_code          := l_balance_type_code;
172521    -- set the flag so later we will know whether the gain loss line needs to be created
172522    
172523    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
172524      p_actual_flag :='A';
172525    END IF;
172526 
172527    --
172528    -- bulk performance
172529    --
172530    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
172531                                       p_header_num   => 0); -- 4262811
172532    --
172533    -- set accounting line options
172534    --
172535    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
172536            p_natural_side_code          => 'C'
172537          , p_gain_or_loss_flag          => 'N'
172538          , p_gl_transfer_mode_code      => 'S'
172539          , p_acct_entry_type_code       => 'A'
172540          , p_switch_side_flag           => 'Y'
172541          , p_merge_duplicate_code       => 'N'
172542          );
172543    --
172544    l_acc_rev_natural_side_code := 'D';  -- 4262811
172545    -- 
172546    --
172547    -- set accounting line type info
172548    --
172549    xla_ae_lines_pkg.SetAcctLineType
172550       (p_component_type             => l_component_type
172551       ,p_event_type_code            => l_event_type_code
172552       ,p_line_definition_owner_code => l_line_definition_owner_code
172553       ,p_line_definition_code       => l_line_definition_code
172554       ,p_accounting_line_code       => l_component_code
172555       ,p_accounting_line_type_code  => l_component_type_code
172556       ,p_accounting_line_appl_id    => l_component_appl_id
172557       ,p_amb_context_code           => l_amb_context_code
172558       ,p_entity_code                => l_entity_code
172559       ,p_event_class_code           => l_event_class_code);
172560    --
172561    -- set accounting class
172562    --
172563    xla_ae_lines_pkg.SetAcctClass(
172564            p_accounting_class_code  => 'EXPENSE'
172565          , p_ae_header_id           => l_ae_header_id
172566          );
172567 
172568    --
172569    -- set rounding class
172570    --
172571    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
172572                       'EXPENSE';
172573 
172574    --
172575    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
172576    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
172577    --
172578    -- bulk performance
172579    --
172580    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
172581 
172582    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
172583       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
172584 
172585    -- 4955764
172586    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
172587       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
172588 
172589    -- 4458381 Public Sector Enh
172590    
172591    --
172592    -- set accounting attributes for the line type
172596    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
172593    --
172594    l_entered_amt_idx := 4;
172595    l_accted_amt_idx  := 6;
172597    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
172598    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
172599    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
172600    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
172601    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
172602    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
172603    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
172604    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
172605    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
172606    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
172607    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
172608    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
172609 
172610    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
172611    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
172612 
172613    ---------------------------------------------------------------------------------------------------------------
172614    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
172615    ---------------------------------------------------------------------------------------------------------------
172616    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
172617 
172618    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
172619    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
172620 
172621    IF xla_accounting_cache_pkg.GetValueChar
172622          (p_source_code         => 'LEDGER_CATEGORY_CODE'
172623          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
172624    AND l_bflow_method_code = 'PRIOR_ENTRY'
172625 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
172626    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
172627          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
172628        )
172629    THEN
172630          xla_ae_lines_pkg.BflowUpgEntry
172631            (p_business_method_code    => l_bflow_method_code
172632            ,p_business_class_code     => l_bflow_class_code
172633            ,p_balance_type            => l_balance_type_code);
172634    ELSE
172635       NULL;
172636 -- No business flow processing for business flow method of NONE.
172637    END IF;
172638 
172639    --
172640    -- call analytical criteria
172641    --
172642    
172643    --
172644    -- call description
172645    --
172646    
172647 xla_ae_lines_pkg.SetLineDescription(
172648    p_ae_header_id => l_ae_header_id
172649   ,p_description  => Description_139 (
172650      p_application_id         => p_application_id
172651    , p_ae_header_id           => l_ae_header_id 
172652 , p_source_1 => p_source_1
172653    )
172654 );
172655 
172656 
172657    --
172658    -- call ADRs
172659    -- Bug 4922099
172660    --
172661    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
172662         (NVL(l_actual_upg_option, 'N') = 'O') OR
172663         (NVL(l_enc_upg_option, 'N') = 'O')
172664       )
172665    THEN
172666    NULL;
172667    --
172668    --
172669    
172670   l_ccid := AcctDerRule_175(
172671            p_application_id           => p_application_id
172672          , p_ae_header_id             => l_ae_header_id 
172673 , p_source_3 => p_source_3
172674 , p_source_29 => p_source_29
172675          , x_transaction_coa_id       => l_adr_transaction_coa_id
172676          , x_accounting_coa_id        => l_adr_accounting_coa_id
172677          , x_value_type_code          => l_adr_value_type_code
172678          , p_side                     => 'NA'
172679    );
172680 
172681    xla_ae_lines_pkg.set_ccid(
172682     p_code_combination_id          => l_ccid
172683   , p_value_type_code              => l_adr_value_type_code
172684   , p_transaction_coa_id           => l_adr_transaction_coa_id
172685   , p_accounting_coa_id            => l_adr_accounting_coa_id
172686   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
172687   , p_adr_type_code                => 'S'
172688   , p_component_type               => l_component_type
172689   , p_component_code               => l_component_code
172690   , p_component_type_code          => l_component_type_code
172691   , p_component_appl_id            => l_component_appl_id
172692   , p_amb_context_code             => l_amb_context_code
172693   , p_side                         => 'NA'
172694   );
172695 
172696 
172697    l_segment := AcctDerRule_143(
172698            p_application_id           => p_application_id
172699          , p_ae_header_id             => l_ae_header_id 
172700 , p_source_2 => p_source_2
172701 , p_source_3 => p_source_3
172702          , x_transaction_coa_id       => l_adr_transaction_coa_id
172703          , x_accounting_coa_id        => l_adr_accounting_coa_id
172704          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
172705          , x_flex_value_set_id        => l_adr_flex_value_set_id
172706          , x_value_type_code          => l_adr_value_type_code
172707          , x_value_combination_id     => l_adr_value_combination_id
172708          , x_value_segment_code       => l_adr_value_segment_code
172709          , p_side                     => 'NA'
172710          , p_override_seg_flag        => 'Y'
172711    );
172712 
172713    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
172714 
172715       xla_ae_lines_pkg.set_segment(
172716           p_to_segment_code         => 'GL_ACCOUNT'
172717         , p_segment_value           => l_segment
172718         , p_from_segment_code       => l_adr_value_segment_code
172722         , p_accounting_coa_id       => l_adr_accounting_coa_id
172719         , p_from_combination_id     => l_adr_value_combination_id
172720         , p_value_type_code         => l_adr_value_type_code
172721         , p_transaction_coa_id      => l_adr_transaction_coa_id
172723         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
172724         , p_flex_value_set_id       => l_adr_flex_value_set_id
172725         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
172726         , p_adr_type_code           => 'S'
172727         , p_component_type          => l_component_type
172728         , p_component_code          => l_component_code
172729         , p_component_type_code     => l_component_type_code
172730         , p_component_appl_id       => l_component_appl_id
172731         , p_amb_context_code        => l_amb_context_code
172732         , p_entity_code             => 'TRANSACTIONS'
172733         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
172734         , p_side                    => 'NA'
172735         );
172736 
172737   END IF;
172738 
172739    --
172740    --
172741    END IF;
172742    --
172743    -- Bug 4922099
172744    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
172745           (NVL(l_enc_upg_option, 'N') = 'O')
172746         ) AND
172747         (l_bflow_method_code = 'PRIOR_ENTRY')
172748       )
172749    THEN
172750       IF
172751       --
172752       1 = 2
172753       --
172754       THEN
172755       xla_accounting_err_pkg.build_message
172756                                     (p_appli_s_name            => 'XLA'
172757                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
172758                                     ,p_token_1                 => 'LINE_NUMBER'
172759                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
172760                                     ,p_token_2                 => 'LINE_TYPE_NAME'
172761                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
172762                                                                              l_component_type
172763                                                                             ,l_component_code
172764                                                                             ,l_component_type_code
172765                                                                             ,l_component_appl_id
172766                                                                             ,l_amb_context_code
172767                                                                             ,l_entity_code
172768                                                                             ,l_event_class_code
172769                                                                            )
172770                                     ,p_token_3                 => 'OWNER'
172771                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
172772                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
172773                                                                           ,p_lookup_code    => l_component_type_code
172774                                                                          )
172775                                     ,p_token_4                 => 'PRODUCT_NAME'
172776                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
172777                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
172778                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
172779                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
172780                                     ,p_ae_header_id            =>  NULL
172781                                        );
172782 
172783         IF (C_LEVEL_ERROR>= g_log_level) THEN
172784                  trace
172785                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
172786                       ,p_level    => C_LEVEL_ERROR
172787                       ,p_module   => l_log_module);
172788         END IF;
172789       END IF;
172790    END IF;
172791    --
172792    --
172793    ------------------------------------------------------------------------------------------------
172794    -- 4219869 Business Flow
172795    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
172796    -- Prior Entry.  Currently, the following code is always generated.
172797    ------------------------------------------------------------------------------------------------
172798    XLA_AE_LINES_PKG.ValidateCurrentLine;
172799 
172800    ------------------------------------------------------------------------------------
172801    -- 4219869 Business Flow
172802    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
172803    ------------------------------------------------------------------------------------
172804    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
172805 
172806    ----------------------------------------------------------------------------------
172807    -- 4219869 Business Flow
172808    -- Update journal entry status -- Need to generate this within IF <condition>
172809    ----------------------------------------------------------------------------------
172810    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
172811          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
172812          ,p_balance_type_code => l_balance_type_code
172813          );
172814 
172815    -------------------------------------------------------------------------------------------
172816    -- 4262811 - Generate the Accrual Reversal lines
172817    -------------------------------------------------------------------------------------------
172818    BEGIN
172819       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
172823       END IF;
172820                               (g_array_event(p_event_id).array_value_num('header_index'));
172821       IF l_acc_rev_flag IS NULL THEN
172822          l_acc_rev_flag := 'N';
172824    EXCEPTION
172825       WHEN OTHERS THEN
172826          l_acc_rev_flag := 'N';
172827    END;
172828    --
172829    IF (l_acc_rev_flag = 'Y') THEN
172830 
172831        -- 4645092  ------------------------------------------------------------------------------
172832        -- To allow MPA report to determine if it should generate report process
172833        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
172834        ------------------------------------------------------------------------------------------
172835 
172836        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
172837        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
172838    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
172839    -- call ADRs
172840    -- Bug 4922099
172841    --
172842    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
172843         (NVL(l_actual_upg_option, 'N') = 'O') OR
172844         (NVL(l_enc_upg_option, 'N') = 'O')
172845       )
172846    THEN
172847    NULL;
172848    --
172849    --
172850    
172851   l_ccid := AcctDerRule_175(
172852            p_application_id           => p_application_id
172853          , p_ae_header_id             => l_ae_header_id 
172854 , p_source_3 => p_source_3
172855 , p_source_29 => p_source_29
172856          , x_transaction_coa_id       => l_adr_transaction_coa_id
172857          , x_accounting_coa_id        => l_adr_accounting_coa_id
172858          , x_value_type_code          => l_adr_value_type_code
172859          , p_side                     => 'NA'
172860    );
172861 
172862    xla_ae_lines_pkg.set_ccid(
172863     p_code_combination_id          => l_ccid
172864   , p_value_type_code              => l_adr_value_type_code
172865   , p_transaction_coa_id           => l_adr_transaction_coa_id
172866   , p_accounting_coa_id            => l_adr_accounting_coa_id
172867   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
172868   , p_adr_type_code                => 'S'
172869   , p_component_type               => l_component_type
172870   , p_component_code               => l_component_code
172871   , p_component_type_code          => l_component_type_code
172872   , p_component_appl_id            => l_component_appl_id
172873   , p_amb_context_code             => l_amb_context_code
172874   , p_side                         => 'NA'
172875   );
172876 
172877 
172878    l_segment := AcctDerRule_143(
172879            p_application_id           => p_application_id
172880          , p_ae_header_id             => l_ae_header_id 
172881 , p_source_2 => p_source_2
172882 , p_source_3 => p_source_3
172883          , x_transaction_coa_id       => l_adr_transaction_coa_id
172884          , x_accounting_coa_id        => l_adr_accounting_coa_id
172885          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
172886          , x_flex_value_set_id        => l_adr_flex_value_set_id
172887          , x_value_type_code          => l_adr_value_type_code
172888          , x_value_combination_id     => l_adr_value_combination_id
172889          , x_value_segment_code       => l_adr_value_segment_code
172890          , p_side                     => 'NA'
172891          , p_override_seg_flag        => 'Y'
172892    );
172893 
172894    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
172895 
172896       xla_ae_lines_pkg.set_segment(
172897           p_to_segment_code         => 'GL_ACCOUNT'
172898         , p_segment_value           => l_segment
172899         , p_from_segment_code       => l_adr_value_segment_code
172900         , p_from_combination_id     => l_adr_value_combination_id
172901         , p_value_type_code         => l_adr_value_type_code
172902         , p_transaction_coa_id      => l_adr_transaction_coa_id
172903         , p_accounting_coa_id       => l_adr_accounting_coa_id
172904         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
172905         , p_flex_value_set_id       => l_adr_flex_value_set_id
172906         , p_adr_code                => 'FA_BONUS_DEPRN_EXPENSE_SEGMENT'
172907         , p_adr_type_code           => 'S'
172908         , p_component_type          => l_component_type
172909         , p_component_code          => l_component_code
172910         , p_component_type_code     => l_component_type_code
172911         , p_component_appl_id       => l_component_appl_id
172912         , p_amb_context_code        => l_amb_context_code
172913         , p_entity_code             => 'TRANSACTIONS'
172914         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
172915         , p_side                    => 'NA'
172916         );
172917 
172918   END IF;
172919 
172920    --
172921    --
172922    END IF;
172923 
172924        --
172925        -- Update the line information that should be overwritten
172926        --
172927        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
172928                                          p_header_num   => 1);
172929        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
172930 
172931        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
172932 
172933        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
172934           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
172935        END IF;
172936 
172937       --
172938       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
172939       --
172940       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
172941           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
172942       ELSE
172946           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
172943           ---------------------------------------------------------------------------------------------------
172944           -- 4262811a Switch Sign
172945           ---------------------------------------------------------------------------------------------------
172947           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
172948                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
172949           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
172950                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
172951           -- 5132302
172952           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
172953                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
172954 
172955       END IF;
172956 
172957       -- 4955764
172958       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
172959       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
172960 
172961 
172962       XLA_AE_LINES_PKG.ValidateCurrentLine;
172963       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
172964 
172965       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
172966                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
172967                ,p_balance_type_code => l_balance_type_code);
172968 
172969    END IF;
172970 
172971    -----------------------------------------------------------------------------------------
172972    -- 4262811 Multiperiod Accounting
172973    -----------------------------------------------------------------------------------------
172974      -- No MPA option is assigned.
172975 
172976 
172977 END IF;
172978 END IF;
172979 --
172980 
172981 --
172982 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
172983    trace
172984       (p_msg      => 'END of AcctLineType_397'
172985       ,p_level    => C_LEVEL_PROCEDURE
172986       ,p_module   => l_log_module);
172987 END IF;
172988 --
172989 EXCEPTION
172990   WHEN xla_exceptions_pkg.application_exception THEN
172991       RAISE;
172992   WHEN OTHERS THEN
172993        xla_exceptions_pkg.raise_message
172994            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_397');
172995 END AcctLineType_397;
172996 --
172997 
172998 ---------------------------------------
172999 --
173000 -- PRIVATE FUNCTION
173001 --         AcctLineType_398
173002 --
173003 ---------------------------------------
173004 PROCEDURE AcctLineType_398 (
173005   p_application_id        IN NUMBER
173006  ,p_event_id              IN NUMBER
173007  ,p_calculate_acctd_flag  IN VARCHAR2
173008  ,p_calculate_g_l_flag    IN VARCHAR2
173009  ,p_actual_flag           IN OUT VARCHAR2
173010  ,p_balance_type_code     OUT VARCHAR2
173011  ,p_gain_or_loss_ref      OUT VARCHAR2
173012  
173013 --Period Close Date
173014  , p_source_1            IN DATE
173015 --Generated Code Combination Identifier
173016  , p_source_3            IN NUMBER
173017 --Bonus Reserve Account
173018  , p_source_4            IN VARCHAR2
173019 --Generated Offset Code Combination Identifier
173020  , p_source_17            IN NUMBER
173021 --Expense Account Code Combination Identifier
173022  , p_source_29            IN NUMBER
173023 --Default Code Combination Identifier
173024  , p_source_30            IN NUMBER
173025 --Adjustment Type
173026  , p_source_35            IN VARCHAR2
173027 --Transaction Header Identifier
173028  , p_source_36            IN NUMBER
173029 --Adjustment Line Identifier
173030  , p_source_37            IN NUMBER
173031 --Distribution Type Code
173032  , p_source_38            IN VARCHAR2
173033 --Entered Amount
173034  , p_source_39            IN NUMBER
173035 --Currency Code
173036  , p_source_40            IN VARCHAR2
173037 --Source Destination Code
173038  , p_source_42            IN VARCHAR2
173039 )
173040 IS
173041 
173042 l_component_type              VARCHAR2(80);
173043 l_component_code              VARCHAR2(30);
173044 l_component_type_code         VARCHAR2(1);
173045 l_component_appl_id           INTEGER;
173046 l_amb_context_code            VARCHAR2(30);
173047 l_entity_code                 VARCHAR2(30);
173048 l_event_class_code            VARCHAR2(30);
173049 l_ae_header_id                NUMBER;
173050 l_event_type_code             VARCHAR2(30);
173051 l_line_definition_code        VARCHAR2(30);
173052 l_line_definition_owner_code  VARCHAR2(1);
173053 --
173054 -- adr variables
173055 l_segment                     VARCHAR2(30);
173056 l_ccid                        NUMBER;
173057 l_adr_transaction_coa_id      NUMBER;
173058 l_adr_accounting_coa_id       NUMBER;
173059 l_adr_flexfield_segment_code  VARCHAR2(30);
173060 l_adr_flex_value_set_id       NUMBER;
173061 l_adr_value_type_code         VARCHAR2(30);
173062 l_adr_value_combination_id    NUMBER;
173063 l_adr_value_segment_code      VARCHAR2(30);
173064 
173065 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
173066 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
173067 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
173068 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
173069 
173070 -- 4262811 Variables ------------------------------------------------------------------------------------------
173071 l_entered_amt_idx             NUMBER;
173072 l_accted_amt_idx              NUMBER;
173073 l_acc_rev_flag                VARCHAR2(1);
173074 l_accrual_line_num            NUMBER;
173075 l_tmp_amt                     NUMBER;
173076 l_acc_rev_natural_side_code   VARCHAR2(1);
173077 
173078 l_num_entries                 NUMBER;
173082 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
173079 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
173080 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
173081 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
173083 l_recog_line_1                NUMBER;
173084 l_recog_line_2                NUMBER;
173085 
173086 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
173087 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
173088 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
173089 
173090 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
173091 
173092 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
173093 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
173094 
173095 ---------------------------------------------------------------------------------------------------------------
173096 
173097 
173098 --
173099 -- bulk performance
173100 --
173101 l_balance_type_code           VARCHAR2(1);
173102 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
173103 l_log_module                  VARCHAR2(240);
173104 
173105 --
173106 -- Upgrade strategy
173107 --
173108 l_actual_upg_option           VARCHAR2(1);
173109 l_enc_upg_option           VARCHAR2(1);
173110 
173111 --
173112 BEGIN
173113 --
173114 IF g_log_enabled THEN
173115       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_398';
173116 END IF;
173117 --
173118 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
173119 
173120       trace
173121          (p_msg      => 'BEGIN of AcctLineType_398'
173122          ,p_level    => C_LEVEL_PROCEDURE
173123          ,p_module   => l_log_module);
173124 
173125 END IF;
173126 --
173127 l_component_type             := 'AMB_JLT';
173128 l_component_code             := 'FA_UNITADJ_SOURCE_BONUS_RES';
173129 l_component_type_code        := 'S';
173130 l_component_appl_id          :=  140;
173131 l_amb_context_code           := 'DEFAULT';
173132 l_entity_code                := 'TRANSACTIONS';
173133 l_event_class_code           := 'UNIT_ADJUSTMENTS';
173134 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
173135 l_line_definition_owner_code := 'S';
173136 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
173137 --
173138 l_balance_type_code          := 'A';
173139 l_segment                     := NULL;
173140 l_ccid                        := NULL;
173141 l_adr_transaction_coa_id      := NULL;
173142 l_adr_accounting_coa_id       := NULL;
173143 l_adr_flexfield_segment_code  := NULL;
173144 l_adr_flex_value_set_id       := NULL;
173145 l_adr_value_type_code         := NULL;
173146 l_adr_value_combination_id    := NULL;
173147 l_adr_value_segment_code      := NULL;
173148 
173149 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
173150 l_bflow_class_code           := '';    -- 4219869 Business Flow
173151 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
173152 l_budgetary_control_flag     := 'N';
173153 
173154 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
173155 l_bflow_applied_to_amt       := NULL; -- 5132302
173156 l_entered_amt_idx            := NULL;          -- 4262811
173157 l_accted_amt_idx             := NULL;          -- 4262811
173158 l_acc_rev_flag               := NULL;          -- 4262811
173159 l_accrual_line_num           := NULL;          -- 4262811
173160 l_tmp_amt                    := NULL;          -- 4262811
173161 --
173162  
173163 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
173164     l_balance_type_code <> 'B' THEN
173165 IF (NVL(p_source_35,'
173166 ') =  'BONUS EXPENSE' OR 
173167 NVL(p_source_35,'
173168 ') =  'BONUS RESERVE') AND 
173169 NVL(p_source_42,'
173170 ') =  'SOURCE'
173171  THEN 
173172 
173173    --
173174    XLA_AE_LINES_PKG.SetNewLine;
173175 
173176    p_balance_type_code          := l_balance_type_code;
173177    -- set the flag so later we will know whether the gain loss line needs to be created
173178    
173179    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
173180      p_actual_flag :='A';
173181    END IF;
173182 
173183    --
173184    -- bulk performance
173185    --
173186    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
173187                                       p_header_num   => 0); -- 4262811
173188    --
173189    -- set accounting line options
173190    --
173191    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
173192            p_natural_side_code          => 'D'
173193          , p_gain_or_loss_flag          => 'N'
173194          , p_gl_transfer_mode_code      => 'S'
173195          , p_acct_entry_type_code       => 'A'
173196          , p_switch_side_flag           => 'Y'
173197          , p_merge_duplicate_code       => 'N'
173198          );
173199    --
173200    l_acc_rev_natural_side_code := 'C';  -- 4262811
173201    -- 
173202    --
173203    -- set accounting line type info
173204    --
173205    xla_ae_lines_pkg.SetAcctLineType
173206       (p_component_type             => l_component_type
173207       ,p_event_type_code            => l_event_type_code
173208       ,p_line_definition_owner_code => l_line_definition_owner_code
173209       ,p_line_definition_code       => l_line_definition_code
173210       ,p_accounting_line_code       => l_component_code
173211       ,p_accounting_line_type_code  => l_component_type_code
173212       ,p_accounting_line_appl_id    => l_component_appl_id
173213       ,p_amb_context_code           => l_amb_context_code
173214       ,p_entity_code                => l_entity_code
173215       ,p_event_class_code           => l_event_class_code);
173216    --
173217    -- set accounting class
173218    --
173219    xla_ae_lines_pkg.SetAcctClass(
173223 
173220            p_accounting_class_code  => 'ASSET'
173221          , p_ae_header_id           => l_ae_header_id
173222          );
173224    --
173225    -- set rounding class
173226    --
173227    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
173228                       'ASSET';
173229 
173230    --
173231    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
173232    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
173233    --
173234    -- bulk performance
173235    --
173236    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
173237 
173238    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
173239       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
173240 
173241    -- 4955764
173242    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
173243       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
173244 
173245    -- 4458381 Public Sector Enh
173246    
173247    --
173248    -- set accounting attributes for the line type
173249    --
173250    l_entered_amt_idx := 4;
173251    l_accted_amt_idx  := 6;
173252    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
173253    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
173254    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
173255    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
173256    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
173257    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
173258    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
173259    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
173260    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
173261    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
173262    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
173263    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
173264    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
173265 
173266    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
173267    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
173268 
173269    ---------------------------------------------------------------------------------------------------------------
173270    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
173271    ---------------------------------------------------------------------------------------------------------------
173272    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
173273 
173274    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
173275    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
173276 
173277    IF xla_accounting_cache_pkg.GetValueChar
173278          (p_source_code         => 'LEDGER_CATEGORY_CODE'
173279          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
173280    AND l_bflow_method_code = 'PRIOR_ENTRY'
173281 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
173282    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
173283          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
173284        )
173285    THEN
173286          xla_ae_lines_pkg.BflowUpgEntry
173287            (p_business_method_code    => l_bflow_method_code
173288            ,p_business_class_code     => l_bflow_class_code
173289            ,p_balance_type            => l_balance_type_code);
173290    ELSE
173291       NULL;
173292 -- No business flow processing for business flow method of NONE.
173293    END IF;
173294 
173295    --
173296    -- call analytical criteria
173297    --
173298    
173299    --
173300    -- call description
173301    --
173302    
173303 xla_ae_lines_pkg.SetLineDescription(
173304    p_ae_header_id => l_ae_header_id
173305   ,p_description  => Description_132 (
173306      p_application_id         => p_application_id
173307    , p_ae_header_id           => l_ae_header_id 
173308 , p_source_1 => p_source_1
173309    )
173310 );
173311 
173312 
173313    --
173314    -- call ADRs
173315    -- Bug 4922099
173316    --
173317    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
173318         (NVL(l_actual_upg_option, 'N') = 'O') OR
173319         (NVL(l_enc_upg_option, 'N') = 'O')
173320       )
173321    THEN
173322    NULL;
173323    --
173324    --
173325    
173326   l_ccid := AcctDerRule_174(
173327            p_application_id           => p_application_id
173328          , p_ae_header_id             => l_ae_header_id 
173329 , p_source_3 => p_source_3
173330 , p_source_17 => p_source_17
173331 , p_source_30 => p_source_30
173332          , x_transaction_coa_id       => l_adr_transaction_coa_id
173333          , x_accounting_coa_id        => l_adr_accounting_coa_id
173334          , x_value_type_code          => l_adr_value_type_code
173335          , p_side                     => 'NA'
173336    );
173337 
173338    xla_ae_lines_pkg.set_ccid(
173339     p_code_combination_id          => l_ccid
173340   , p_value_type_code              => l_adr_value_type_code
173341   , p_transaction_coa_id           => l_adr_transaction_coa_id
173342   , p_accounting_coa_id            => l_adr_accounting_coa_id
173343   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
173344   , p_adr_type_code                => 'S'
173345   , p_component_type               => l_component_type
173346   , p_component_code               => l_component_code
173347   , p_component_type_code          => l_component_type_code
173351   );
173348   , p_component_appl_id            => l_component_appl_id
173349   , p_amb_context_code             => l_amb_context_code
173350   , p_side                         => 'NA'
173352 
173353 
173354    l_segment := AcctDerRule_144(
173355            p_application_id           => p_application_id
173356          , p_ae_header_id             => l_ae_header_id 
173357 , p_source_3 => p_source_3
173358 , p_source_4 => p_source_4
173359          , x_transaction_coa_id       => l_adr_transaction_coa_id
173360          , x_accounting_coa_id        => l_adr_accounting_coa_id
173361          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
173362          , x_flex_value_set_id        => l_adr_flex_value_set_id
173363          , x_value_type_code          => l_adr_value_type_code
173364          , x_value_combination_id     => l_adr_value_combination_id
173365          , x_value_segment_code       => l_adr_value_segment_code
173366          , p_side                     => 'NA'
173367          , p_override_seg_flag        => 'Y'
173368    );
173369 
173370    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
173371 
173372       xla_ae_lines_pkg.set_segment(
173373           p_to_segment_code         => 'GL_ACCOUNT'
173374         , p_segment_value           => l_segment
173375         , p_from_segment_code       => l_adr_value_segment_code
173376         , p_from_combination_id     => l_adr_value_combination_id
173377         , p_value_type_code         => l_adr_value_type_code
173378         , p_transaction_coa_id      => l_adr_transaction_coa_id
173379         , p_accounting_coa_id       => l_adr_accounting_coa_id
173380         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
173381         , p_flex_value_set_id       => l_adr_flex_value_set_id
173382         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
173383         , p_adr_type_code           => 'S'
173384         , p_component_type          => l_component_type
173385         , p_component_code          => l_component_code
173386         , p_component_type_code     => l_component_type_code
173387         , p_component_appl_id       => l_component_appl_id
173388         , p_amb_context_code        => l_amb_context_code
173389         , p_entity_code             => 'TRANSACTIONS'
173390         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
173391         , p_side                    => 'NA'
173392         );
173393 
173394   END IF;
173395 
173396    l_segment := AcctDerRule_168(
173397            p_application_id           => p_application_id
173398          , p_ae_header_id             => l_ae_header_id 
173399 , p_source_3 => p_source_3
173400 , p_source_29 => p_source_29
173401          , x_transaction_coa_id       => l_adr_transaction_coa_id
173402          , x_accounting_coa_id        => l_adr_accounting_coa_id
173403          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
173404          , x_flex_value_set_id        => l_adr_flex_value_set_id
173405          , x_value_type_code          => l_adr_value_type_code
173406          , x_value_combination_id     => l_adr_value_combination_id
173407          , x_value_segment_code       => l_adr_value_segment_code
173408          , p_side                     => 'NA'
173409          , p_override_seg_flag        => 'Y'
173410    );
173411 
173412    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
173413 
173414       xla_ae_lines_pkg.set_segment(
173415           p_to_segment_code         => 'GL_BALANCING'
173416         , p_segment_value           => l_segment
173417         , p_from_segment_code       => l_adr_value_segment_code
173418         , p_from_combination_id     => l_adr_value_combination_id
173419         , p_value_type_code         => l_adr_value_type_code
173420         , p_transaction_coa_id      => l_adr_transaction_coa_id
173421         , p_accounting_coa_id       => l_adr_accounting_coa_id
173422         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
173423         , p_flex_value_set_id       => l_adr_flex_value_set_id
173424         , p_adr_code                => 'FA_EXPENSE_ACCT'
173425         , p_adr_type_code           => 'S'
173426         , p_component_type          => l_component_type
173427         , p_component_code          => l_component_code
173428         , p_component_type_code     => l_component_type_code
173429         , p_component_appl_id       => l_component_appl_id
173430         , p_amb_context_code        => l_amb_context_code
173431         , p_entity_code             => 'TRANSACTIONS'
173432         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
173433         , p_side                    => 'NA'
173434         );
173435 
173436   END IF;
173437 
173438    --
173439    --
173440    END IF;
173441    --
173442    -- Bug 4922099
173443    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
173444           (NVL(l_enc_upg_option, 'N') = 'O')
173445         ) AND
173446         (l_bflow_method_code = 'PRIOR_ENTRY')
173447       )
173448    THEN
173449       IF
173450       --
173451       1 = 2
173452       --
173453       THEN
173454       xla_accounting_err_pkg.build_message
173455                                     (p_appli_s_name            => 'XLA'
173456                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
173457                                     ,p_token_1                 => 'LINE_NUMBER'
173458                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
173459                                     ,p_token_2                 => 'LINE_TYPE_NAME'
173460                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
173461                                                                              l_component_type
173462                                                                             ,l_component_code
173463                                                                             ,l_component_type_code
173464                                                                             ,l_component_appl_id
173468                                                                            )
173465                                                                             ,l_amb_context_code
173466                                                                             ,l_entity_code
173467                                                                             ,l_event_class_code
173469                                     ,p_token_3                 => 'OWNER'
173470                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
173471                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
173472                                                                           ,p_lookup_code    => l_component_type_code
173473                                                                          )
173474                                     ,p_token_4                 => 'PRODUCT_NAME'
173475                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
173476                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
173477                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
173478                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
173479                                     ,p_ae_header_id            =>  NULL
173480                                        );
173481 
173482         IF (C_LEVEL_ERROR>= g_log_level) THEN
173483                  trace
173484                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
173485                       ,p_level    => C_LEVEL_ERROR
173486                       ,p_module   => l_log_module);
173487         END IF;
173488       END IF;
173489    END IF;
173490    --
173491    --
173492    ------------------------------------------------------------------------------------------------
173493    -- 4219869 Business Flow
173494    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
173495    -- Prior Entry.  Currently, the following code is always generated.
173496    ------------------------------------------------------------------------------------------------
173497    XLA_AE_LINES_PKG.ValidateCurrentLine;
173498 
173499    ------------------------------------------------------------------------------------
173500    -- 4219869 Business Flow
173501    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
173502    ------------------------------------------------------------------------------------
173503    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
173504 
173505    ----------------------------------------------------------------------------------
173506    -- 4219869 Business Flow
173507    -- Update journal entry status -- Need to generate this within IF <condition>
173508    ----------------------------------------------------------------------------------
173509    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
173510          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
173511          ,p_balance_type_code => l_balance_type_code
173512          );
173513 
173514    -------------------------------------------------------------------------------------------
173515    -- 4262811 - Generate the Accrual Reversal lines
173516    -------------------------------------------------------------------------------------------
173517    BEGIN
173518       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
173519                               (g_array_event(p_event_id).array_value_num('header_index'));
173520       IF l_acc_rev_flag IS NULL THEN
173521          l_acc_rev_flag := 'N';
173522       END IF;
173523    EXCEPTION
173524       WHEN OTHERS THEN
173525          l_acc_rev_flag := 'N';
173526    END;
173527    --
173528    IF (l_acc_rev_flag = 'Y') THEN
173529 
173530        -- 4645092  ------------------------------------------------------------------------------
173531        -- To allow MPA report to determine if it should generate report process
173532        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
173533        ------------------------------------------------------------------------------------------
173534 
173535        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
173536        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
173537    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
173538    -- call ADRs
173539    -- Bug 4922099
173540    --
173541    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
173542         (NVL(l_actual_upg_option, 'N') = 'O') OR
173543         (NVL(l_enc_upg_option, 'N') = 'O')
173544       )
173545    THEN
173546    NULL;
173547    --
173548    --
173549    
173550   l_ccid := AcctDerRule_174(
173551            p_application_id           => p_application_id
173552          , p_ae_header_id             => l_ae_header_id 
173553 , p_source_3 => p_source_3
173554 , p_source_17 => p_source_17
173555 , p_source_30 => p_source_30
173556          , x_transaction_coa_id       => l_adr_transaction_coa_id
173557          , x_accounting_coa_id        => l_adr_accounting_coa_id
173558          , x_value_type_code          => l_adr_value_type_code
173559          , p_side                     => 'NA'
173560    );
173561 
173562    xla_ae_lines_pkg.set_ccid(
173563     p_code_combination_id          => l_ccid
173564   , p_value_type_code              => l_adr_value_type_code
173565   , p_transaction_coa_id           => l_adr_transaction_coa_id
173566   , p_accounting_coa_id            => l_adr_accounting_coa_id
173567   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
173568   , p_adr_type_code                => 'S'
173569   , p_component_type               => l_component_type
173570   , p_component_code               => l_component_code
173571   , p_component_type_code          => l_component_type_code
173572   , p_component_appl_id            => l_component_appl_id
173576 
173573   , p_amb_context_code             => l_amb_context_code
173574   , p_side                         => 'NA'
173575   );
173577 
173578    l_segment := AcctDerRule_144(
173579            p_application_id           => p_application_id
173580          , p_ae_header_id             => l_ae_header_id 
173581 , p_source_3 => p_source_3
173582 , p_source_4 => p_source_4
173583          , x_transaction_coa_id       => l_adr_transaction_coa_id
173584          , x_accounting_coa_id        => l_adr_accounting_coa_id
173585          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
173586          , x_flex_value_set_id        => l_adr_flex_value_set_id
173587          , x_value_type_code          => l_adr_value_type_code
173588          , x_value_combination_id     => l_adr_value_combination_id
173589          , x_value_segment_code       => l_adr_value_segment_code
173590          , p_side                     => 'NA'
173591          , p_override_seg_flag        => 'Y'
173592    );
173593 
173594    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
173595 
173596       xla_ae_lines_pkg.set_segment(
173597           p_to_segment_code         => 'GL_ACCOUNT'
173598         , p_segment_value           => l_segment
173599         , p_from_segment_code       => l_adr_value_segment_code
173600         , p_from_combination_id     => l_adr_value_combination_id
173601         , p_value_type_code         => l_adr_value_type_code
173602         , p_transaction_coa_id      => l_adr_transaction_coa_id
173603         , p_accounting_coa_id       => l_adr_accounting_coa_id
173604         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
173605         , p_flex_value_set_id       => l_adr_flex_value_set_id
173606         , p_adr_code                => 'FA_BONUS_RES_ACCOUNT_SEGMENT'
173607         , p_adr_type_code           => 'S'
173608         , p_component_type          => l_component_type
173609         , p_component_code          => l_component_code
173610         , p_component_type_code     => l_component_type_code
173611         , p_component_appl_id       => l_component_appl_id
173612         , p_amb_context_code        => l_amb_context_code
173613         , p_entity_code             => 'TRANSACTIONS'
173614         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
173615         , p_side                    => 'NA'
173616         );
173617 
173618   END IF;
173619 
173620    l_segment := AcctDerRule_168(
173621            p_application_id           => p_application_id
173622          , p_ae_header_id             => l_ae_header_id 
173623 , p_source_3 => p_source_3
173624 , p_source_29 => p_source_29
173625          , x_transaction_coa_id       => l_adr_transaction_coa_id
173626          , x_accounting_coa_id        => l_adr_accounting_coa_id
173627          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
173628          , x_flex_value_set_id        => l_adr_flex_value_set_id
173629          , x_value_type_code          => l_adr_value_type_code
173630          , x_value_combination_id     => l_adr_value_combination_id
173631          , x_value_segment_code       => l_adr_value_segment_code
173632          , p_side                     => 'NA'
173633          , p_override_seg_flag        => 'Y'
173634    );
173635 
173636    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
173637 
173638       xla_ae_lines_pkg.set_segment(
173639           p_to_segment_code         => 'GL_BALANCING'
173640         , p_segment_value           => l_segment
173641         , p_from_segment_code       => l_adr_value_segment_code
173642         , p_from_combination_id     => l_adr_value_combination_id
173643         , p_value_type_code         => l_adr_value_type_code
173644         , p_transaction_coa_id      => l_adr_transaction_coa_id
173645         , p_accounting_coa_id       => l_adr_accounting_coa_id
173646         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
173647         , p_flex_value_set_id       => l_adr_flex_value_set_id
173648         , p_adr_code                => 'FA_EXPENSE_ACCT'
173649         , p_adr_type_code           => 'S'
173650         , p_component_type          => l_component_type
173651         , p_component_code          => l_component_code
173652         , p_component_type_code     => l_component_type_code
173653         , p_component_appl_id       => l_component_appl_id
173654         , p_amb_context_code        => l_amb_context_code
173655         , p_entity_code             => 'TRANSACTIONS'
173656         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
173657         , p_side                    => 'NA'
173658         );
173659 
173660   END IF;
173661 
173662    --
173663    --
173664    END IF;
173665 
173666        --
173667        -- Update the line information that should be overwritten
173668        --
173669        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
173670                                          p_header_num   => 1);
173671        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
173672 
173673        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
173674 
173675        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
173676           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
173677        END IF;
173678 
173679       --
173680       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
173681       --
173682       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
173683           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
173684       ELSE
173685           ---------------------------------------------------------------------------------------------------
173686           -- 4262811a Switch Sign
173687           ---------------------------------------------------------------------------------------------------
173691           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
173688           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
173689           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
173690                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
173692                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
173693           -- 5132302
173694           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
173695                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
173696 
173697       END IF;
173698 
173699       -- 4955764
173700       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
173701       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
173702 
173703 
173704       XLA_AE_LINES_PKG.ValidateCurrentLine;
173705       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
173706 
173707       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
173708                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
173709                ,p_balance_type_code => l_balance_type_code);
173710 
173711    END IF;
173712 
173713    -----------------------------------------------------------------------------------------
173714    -- 4262811 Multiperiod Accounting
173715    -----------------------------------------------------------------------------------------
173716      -- No MPA option is assigned.
173717 
173718 
173719 END IF;
173720 END IF;
173721 --
173722 
173723 --
173724 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
173725    trace
173726       (p_msg      => 'END of AcctLineType_398'
173727       ,p_level    => C_LEVEL_PROCEDURE
173728       ,p_module   => l_log_module);
173729 END IF;
173730 --
173731 EXCEPTION
173732   WHEN xla_exceptions_pkg.application_exception THEN
173733       RAISE;
173734   WHEN OTHERS THEN
173735        xla_exceptions_pkg.raise_message
173736            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_398');
173737 END AcctLineType_398;
173738 --
173739 
173740 ---------------------------------------
173741 --
173742 -- PRIVATE FUNCTION
173743 --         AcctLineType_399
173744 --
173745 ---------------------------------------
173746 PROCEDURE AcctLineType_399 (
173747   p_application_id        IN NUMBER
173748  ,p_event_id              IN NUMBER
173749  ,p_calculate_acctd_flag  IN VARCHAR2
173750  ,p_calculate_g_l_flag    IN VARCHAR2
173751  ,p_actual_flag           IN OUT VARCHAR2
173752  ,p_balance_type_code     OUT VARCHAR2
173753  ,p_gain_or_loss_ref      OUT VARCHAR2
173754  
173755 --Period Close Date
173756  , p_source_1            IN DATE
173757 --Generated Code Combination Identifier
173758  , p_source_3            IN NUMBER
173759 --Asset Cost Account
173760  , p_source_9            IN VARCHAR2
173761 --Expense Account Code Combination Identifier
173762  , p_source_29            IN NUMBER
173763 --Default Code Combination Identifier
173764  , p_source_30            IN NUMBER
173765 --Adjustment Type
173766  , p_source_35            IN VARCHAR2
173767 --Transaction Header Identifier
173768  , p_source_36            IN NUMBER
173769 --Adjustment Line Identifier
173770  , p_source_37            IN NUMBER
173771 --Distribution Type Code
173772  , p_source_38            IN VARCHAR2
173773 --Entered Amount
173774  , p_source_39            IN NUMBER
173775 --Currency Code
173776  , p_source_40            IN VARCHAR2
173777 --Source Destination Code
173778  , p_source_42            IN VARCHAR2
173779 )
173780 IS
173781 
173782 l_component_type              VARCHAR2(80);
173783 l_component_code              VARCHAR2(30);
173784 l_component_type_code         VARCHAR2(1);
173785 l_component_appl_id           INTEGER;
173786 l_amb_context_code            VARCHAR2(30);
173787 l_entity_code                 VARCHAR2(30);
173788 l_event_class_code            VARCHAR2(30);
173789 l_ae_header_id                NUMBER;
173790 l_event_type_code             VARCHAR2(30);
173791 l_line_definition_code        VARCHAR2(30);
173792 l_line_definition_owner_code  VARCHAR2(1);
173793 --
173794 -- adr variables
173795 l_segment                     VARCHAR2(30);
173796 l_ccid                        NUMBER;
173797 l_adr_transaction_coa_id      NUMBER;
173798 l_adr_accounting_coa_id       NUMBER;
173799 l_adr_flexfield_segment_code  VARCHAR2(30);
173800 l_adr_flex_value_set_id       NUMBER;
173801 l_adr_value_type_code         VARCHAR2(30);
173802 l_adr_value_combination_id    NUMBER;
173803 l_adr_value_segment_code      VARCHAR2(30);
173804 
173805 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
173806 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
173807 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
173808 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
173809 
173810 -- 4262811 Variables ------------------------------------------------------------------------------------------
173811 l_entered_amt_idx             NUMBER;
173812 l_accted_amt_idx              NUMBER;
173813 l_acc_rev_flag                VARCHAR2(1);
173814 l_accrual_line_num            NUMBER;
173815 l_tmp_amt                     NUMBER;
173816 l_acc_rev_natural_side_code   VARCHAR2(1);
173817 
173818 l_num_entries                 NUMBER;
173819 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
173820 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
173821 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
173822 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
173823 l_recog_line_1                NUMBER;
173827 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
173824 l_recog_line_2                NUMBER;
173825 
173826 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
173828 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
173829 
173830 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
173831 
173832 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
173833 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
173834 
173835 ---------------------------------------------------------------------------------------------------------------
173836 
173837 
173838 --
173839 -- bulk performance
173840 --
173841 l_balance_type_code           VARCHAR2(1);
173842 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
173843 l_log_module                  VARCHAR2(240);
173844 
173845 --
173846 -- Upgrade strategy
173847 --
173848 l_actual_upg_option           VARCHAR2(1);
173849 l_enc_upg_option           VARCHAR2(1);
173850 
173851 --
173852 BEGIN
173853 --
173854 IF g_log_enabled THEN
173855       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_399';
173856 END IF;
173857 --
173858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
173859 
173860       trace
173861          (p_msg      => 'BEGIN of AcctLineType_399'
173862          ,p_level    => C_LEVEL_PROCEDURE
173863          ,p_module   => l_log_module);
173864 
173865 END IF;
173866 --
173867 l_component_type             := 'AMB_JLT';
173868 l_component_code             := 'FA_UNITADJ_SOURCE_COST';
173869 l_component_type_code        := 'S';
173870 l_component_appl_id          :=  140;
173871 l_amb_context_code           := 'DEFAULT';
173872 l_entity_code                := 'TRANSACTIONS';
173873 l_event_class_code           := 'UNIT_ADJUSTMENTS';
173874 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
173875 l_line_definition_owner_code := 'S';
173876 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
173877 --
173878 l_balance_type_code          := 'A';
173879 l_segment                     := NULL;
173880 l_ccid                        := NULL;
173881 l_adr_transaction_coa_id      := NULL;
173882 l_adr_accounting_coa_id       := NULL;
173883 l_adr_flexfield_segment_code  := NULL;
173884 l_adr_flex_value_set_id       := NULL;
173885 l_adr_value_type_code         := NULL;
173886 l_adr_value_combination_id    := NULL;
173887 l_adr_value_segment_code      := NULL;
173888 
173889 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
173890 l_bflow_class_code           := '';    -- 4219869 Business Flow
173891 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
173892 l_budgetary_control_flag     := 'N';
173893 
173894 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
173895 l_bflow_applied_to_amt       := NULL; -- 5132302
173896 l_entered_amt_idx            := NULL;          -- 4262811
173897 l_accted_amt_idx             := NULL;          -- 4262811
173898 l_acc_rev_flag               := NULL;          -- 4262811
173899 l_accrual_line_num           := NULL;          -- 4262811
173900 l_tmp_amt                    := NULL;          -- 4262811
173901 --
173902  
173903 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
173904     l_balance_type_code <> 'B' THEN
173905 IF NVL(p_source_35,'
173906 ') =  'COST' AND 
173907 NVL(p_source_42,'
173908 ') =  'SOURCE'
173909  THEN 
173910 
173911    --
173912    XLA_AE_LINES_PKG.SetNewLine;
173913 
173914    p_balance_type_code          := l_balance_type_code;
173915    -- set the flag so later we will know whether the gain loss line needs to be created
173916    
173917    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
173918      p_actual_flag :='A';
173919    END IF;
173920 
173921    --
173922    -- bulk performance
173923    --
173924    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
173925                                       p_header_num   => 0); -- 4262811
173926    --
173927    -- set accounting line options
173928    --
173929    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
173930            p_natural_side_code          => 'C'
173931          , p_gain_or_loss_flag          => 'N'
173932          , p_gl_transfer_mode_code      => 'S'
173933          , p_acct_entry_type_code       => 'A'
173934          , p_switch_side_flag           => 'Y'
173935          , p_merge_duplicate_code       => 'N'
173936          );
173937    --
173938    l_acc_rev_natural_side_code := 'D';  -- 4262811
173939    -- 
173940    --
173941    -- set accounting line type info
173942    --
173943    xla_ae_lines_pkg.SetAcctLineType
173944       (p_component_type             => l_component_type
173945       ,p_event_type_code            => l_event_type_code
173946       ,p_line_definition_owner_code => l_line_definition_owner_code
173947       ,p_line_definition_code       => l_line_definition_code
173948       ,p_accounting_line_code       => l_component_code
173949       ,p_accounting_line_type_code  => l_component_type_code
173950       ,p_accounting_line_appl_id    => l_component_appl_id
173951       ,p_amb_context_code           => l_amb_context_code
173952       ,p_entity_code                => l_entity_code
173953       ,p_event_class_code           => l_event_class_code);
173954    --
173955    -- set accounting class
173956    --
173957    xla_ae_lines_pkg.SetAcctClass(
173958            p_accounting_class_code  => 'ASSET'
173959          , p_ae_header_id           => l_ae_header_id
173960          );
173961 
173962    --
173963    -- set rounding class
173964    --
173965    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
173966                       'ASSET';
173967 
173968    --
173972    -- bulk performance
173969    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
173970    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
173971    --
173973    --
173974    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
173975 
173976    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
173977       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
173978 
173979    -- 4955764
173980    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
173981       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
173982 
173983    -- 4458381 Public Sector Enh
173984    
173985    --
173986    -- set accounting attributes for the line type
173987    --
173988    l_entered_amt_idx := 4;
173989    l_accted_amt_idx  := 6;
173990    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
173991    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
173992    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
173993    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
173994    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
173995    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
173996    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
173997    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
173998    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
173999    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
174000    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
174001    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
174002    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
174003 
174004    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
174005    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
174006 
174007    ---------------------------------------------------------------------------------------------------------------
174008    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
174009    ---------------------------------------------------------------------------------------------------------------
174010    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
174011 
174012    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
174013    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
174014 
174015    IF xla_accounting_cache_pkg.GetValueChar
174016          (p_source_code         => 'LEDGER_CATEGORY_CODE'
174017          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
174018    AND l_bflow_method_code = 'PRIOR_ENTRY'
174019 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
174020    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
174021          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
174022        )
174023    THEN
174024          xla_ae_lines_pkg.BflowUpgEntry
174025            (p_business_method_code    => l_bflow_method_code
174026            ,p_business_class_code     => l_bflow_class_code
174027            ,p_balance_type            => l_balance_type_code);
174028    ELSE
174029       NULL;
174030 -- No business flow processing for business flow method of NONE.
174031    END IF;
174032 
174033    --
174034    -- call analytical criteria
174035    --
174036    
174037    --
174038    -- call description
174039    --
174040    
174041 xla_ae_lines_pkg.SetLineDescription(
174042    p_ae_header_id => l_ae_header_id
174043   ,p_description  => Description_133 (
174044      p_application_id         => p_application_id
174045    , p_ae_header_id           => l_ae_header_id 
174046 , p_source_1 => p_source_1
174047    )
174048 );
174049 
174050 
174051    --
174052    -- call ADRs
174053    -- Bug 4922099
174054    --
174055    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
174056         (NVL(l_actual_upg_option, 'N') = 'O') OR
174057         (NVL(l_enc_upg_option, 'N') = 'O')
174058       )
174059    THEN
174060    NULL;
174061    --
174062    --
174063    
174064   l_ccid := AcctDerRule_173(
174065            p_application_id           => p_application_id
174066          , p_ae_header_id             => l_ae_header_id 
174067 , p_source_3 => p_source_3
174068 , p_source_30 => p_source_30
174069          , x_transaction_coa_id       => l_adr_transaction_coa_id
174070          , x_accounting_coa_id        => l_adr_accounting_coa_id
174071          , x_value_type_code          => l_adr_value_type_code
174072          , p_side                     => 'NA'
174073    );
174074 
174075    xla_ae_lines_pkg.set_ccid(
174076     p_code_combination_id          => l_ccid
174077   , p_value_type_code              => l_adr_value_type_code
174078   , p_transaction_coa_id           => l_adr_transaction_coa_id
174079   , p_accounting_coa_id            => l_adr_accounting_coa_id
174080   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
174081   , p_adr_type_code                => 'S'
174082   , p_component_type               => l_component_type
174083   , p_component_code               => l_component_code
174084   , p_component_type_code          => l_component_type_code
174085   , p_component_appl_id            => l_component_appl_id
174086   , p_amb_context_code             => l_amb_context_code
174087   , p_side                         => 'NA'
174088   );
174089 
174090 
174091    l_segment := AcctDerRule_148(
174092            p_application_id           => p_application_id
174093          , p_ae_header_id             => l_ae_header_id 
174094 , p_source_3 => p_source_3
174095 , p_source_9 => p_source_9
174099          , x_flex_value_set_id        => l_adr_flex_value_set_id
174096          , x_transaction_coa_id       => l_adr_transaction_coa_id
174097          , x_accounting_coa_id        => l_adr_accounting_coa_id
174098          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
174100          , x_value_type_code          => l_adr_value_type_code
174101          , x_value_combination_id     => l_adr_value_combination_id
174102          , x_value_segment_code       => l_adr_value_segment_code
174103          , p_side                     => 'NA'
174104          , p_override_seg_flag        => 'Y'
174105    );
174106 
174107    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
174108 
174109       xla_ae_lines_pkg.set_segment(
174110           p_to_segment_code         => 'GL_ACCOUNT'
174111         , p_segment_value           => l_segment
174112         , p_from_segment_code       => l_adr_value_segment_code
174113         , p_from_combination_id     => l_adr_value_combination_id
174114         , p_value_type_code         => l_adr_value_type_code
174115         , p_transaction_coa_id      => l_adr_transaction_coa_id
174116         , p_accounting_coa_id       => l_adr_accounting_coa_id
174117         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
174118         , p_flex_value_set_id       => l_adr_flex_value_set_id
174119         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
174120         , p_adr_type_code           => 'S'
174121         , p_component_type          => l_component_type
174122         , p_component_code          => l_component_code
174123         , p_component_type_code     => l_component_type_code
174124         , p_component_appl_id       => l_component_appl_id
174125         , p_amb_context_code        => l_amb_context_code
174126         , p_entity_code             => 'TRANSACTIONS'
174127         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
174128         , p_side                    => 'NA'
174129         );
174130 
174131   END IF;
174132 
174133    l_segment := AcctDerRule_168(
174134            p_application_id           => p_application_id
174135          , p_ae_header_id             => l_ae_header_id 
174136 , p_source_3 => p_source_3
174137 , p_source_29 => p_source_29
174138          , x_transaction_coa_id       => l_adr_transaction_coa_id
174139          , x_accounting_coa_id        => l_adr_accounting_coa_id
174140          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
174141          , x_flex_value_set_id        => l_adr_flex_value_set_id
174142          , x_value_type_code          => l_adr_value_type_code
174143          , x_value_combination_id     => l_adr_value_combination_id
174144          , x_value_segment_code       => l_adr_value_segment_code
174145          , p_side                     => 'NA'
174146          , p_override_seg_flag        => 'Y'
174147    );
174148 
174149    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
174150 
174151       xla_ae_lines_pkg.set_segment(
174152           p_to_segment_code         => 'GL_BALANCING'
174153         , p_segment_value           => l_segment
174154         , p_from_segment_code       => l_adr_value_segment_code
174155         , p_from_combination_id     => l_adr_value_combination_id
174156         , p_value_type_code         => l_adr_value_type_code
174157         , p_transaction_coa_id      => l_adr_transaction_coa_id
174158         , p_accounting_coa_id       => l_adr_accounting_coa_id
174159         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
174160         , p_flex_value_set_id       => l_adr_flex_value_set_id
174161         , p_adr_code                => 'FA_EXPENSE_ACCT'
174162         , p_adr_type_code           => 'S'
174163         , p_component_type          => l_component_type
174164         , p_component_code          => l_component_code
174165         , p_component_type_code     => l_component_type_code
174166         , p_component_appl_id       => l_component_appl_id
174167         , p_amb_context_code        => l_amb_context_code
174168         , p_entity_code             => 'TRANSACTIONS'
174169         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
174170         , p_side                    => 'NA'
174171         );
174172 
174173   END IF;
174174 
174175    --
174176    --
174177    END IF;
174178    --
174179    -- Bug 4922099
174180    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
174181           (NVL(l_enc_upg_option, 'N') = 'O')
174182         ) AND
174183         (l_bflow_method_code = 'PRIOR_ENTRY')
174184       )
174185    THEN
174186       IF
174187       --
174188       1 = 2
174189       --
174190       THEN
174191       xla_accounting_err_pkg.build_message
174192                                     (p_appli_s_name            => 'XLA'
174193                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
174194                                     ,p_token_1                 => 'LINE_NUMBER'
174195                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
174196                                     ,p_token_2                 => 'LINE_TYPE_NAME'
174197                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
174198                                                                              l_component_type
174199                                                                             ,l_component_code
174200                                                                             ,l_component_type_code
174201                                                                             ,l_component_appl_id
174202                                                                             ,l_amb_context_code
174203                                                                             ,l_entity_code
174204                                                                             ,l_event_class_code
174205                                                                            )
174206                                     ,p_token_3                 => 'OWNER'
174210                                                                          )
174207                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
174208                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
174209                                                                           ,p_lookup_code    => l_component_type_code
174211                                     ,p_token_4                 => 'PRODUCT_NAME'
174212                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
174213                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
174214                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
174215                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
174216                                     ,p_ae_header_id            =>  NULL
174217                                        );
174218 
174219         IF (C_LEVEL_ERROR>= g_log_level) THEN
174220                  trace
174221                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
174222                       ,p_level    => C_LEVEL_ERROR
174223                       ,p_module   => l_log_module);
174224         END IF;
174225       END IF;
174226    END IF;
174227    --
174228    --
174229    ------------------------------------------------------------------------------------------------
174230    -- 4219869 Business Flow
174231    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
174232    -- Prior Entry.  Currently, the following code is always generated.
174233    ------------------------------------------------------------------------------------------------
174234    XLA_AE_LINES_PKG.ValidateCurrentLine;
174235 
174236    ------------------------------------------------------------------------------------
174237    -- 4219869 Business Flow
174238    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
174239    ------------------------------------------------------------------------------------
174240    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
174241 
174242    ----------------------------------------------------------------------------------
174243    -- 4219869 Business Flow
174244    -- Update journal entry status -- Need to generate this within IF <condition>
174245    ----------------------------------------------------------------------------------
174246    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
174247          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
174248          ,p_balance_type_code => l_balance_type_code
174249          );
174250 
174251    -------------------------------------------------------------------------------------------
174252    -- 4262811 - Generate the Accrual Reversal lines
174253    -------------------------------------------------------------------------------------------
174254    BEGIN
174255       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
174256                               (g_array_event(p_event_id).array_value_num('header_index'));
174257       IF l_acc_rev_flag IS NULL THEN
174258          l_acc_rev_flag := 'N';
174259       END IF;
174260    EXCEPTION
174261       WHEN OTHERS THEN
174262          l_acc_rev_flag := 'N';
174263    END;
174264    --
174265    IF (l_acc_rev_flag = 'Y') THEN
174266 
174267        -- 4645092  ------------------------------------------------------------------------------
174268        -- To allow MPA report to determine if it should generate report process
174269        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
174270        ------------------------------------------------------------------------------------------
174271 
174272        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
174273        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
174274    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
174275    -- call ADRs
174276    -- Bug 4922099
174277    --
174278    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
174279         (NVL(l_actual_upg_option, 'N') = 'O') OR
174280         (NVL(l_enc_upg_option, 'N') = 'O')
174281       )
174282    THEN
174283    NULL;
174284    --
174285    --
174286    
174287   l_ccid := AcctDerRule_173(
174288            p_application_id           => p_application_id
174289          , p_ae_header_id             => l_ae_header_id 
174290 , p_source_3 => p_source_3
174291 , p_source_30 => p_source_30
174292          , x_transaction_coa_id       => l_adr_transaction_coa_id
174293          , x_accounting_coa_id        => l_adr_accounting_coa_id
174294          , x_value_type_code          => l_adr_value_type_code
174295          , p_side                     => 'NA'
174296    );
174297 
174298    xla_ae_lines_pkg.set_ccid(
174299     p_code_combination_id          => l_ccid
174300   , p_value_type_code              => l_adr_value_type_code
174301   , p_transaction_coa_id           => l_adr_transaction_coa_id
174302   , p_accounting_coa_id            => l_adr_accounting_coa_id
174303   , p_adr_code                     => 'FA_DEFAULT_ACCOUNT'
174304   , p_adr_type_code                => 'S'
174305   , p_component_type               => l_component_type
174306   , p_component_code               => l_component_code
174307   , p_component_type_code          => l_component_type_code
174308   , p_component_appl_id            => l_component_appl_id
174309   , p_amb_context_code             => l_amb_context_code
174310   , p_side                         => 'NA'
174311   );
174312 
174313 
174314    l_segment := AcctDerRule_148(
174315            p_application_id           => p_application_id
174316          , p_ae_header_id             => l_ae_header_id 
174317 , p_source_3 => p_source_3
174318 , p_source_9 => p_source_9
174319          , x_transaction_coa_id       => l_adr_transaction_coa_id
174323          , x_value_type_code          => l_adr_value_type_code
174320          , x_accounting_coa_id        => l_adr_accounting_coa_id
174321          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
174322          , x_flex_value_set_id        => l_adr_flex_value_set_id
174324          , x_value_combination_id     => l_adr_value_combination_id
174325          , x_value_segment_code       => l_adr_value_segment_code
174326          , p_side                     => 'NA'
174327          , p_override_seg_flag        => 'Y'
174328    );
174329 
174330    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
174331 
174332       xla_ae_lines_pkg.set_segment(
174333           p_to_segment_code         => 'GL_ACCOUNT'
174334         , p_segment_value           => l_segment
174335         , p_from_segment_code       => l_adr_value_segment_code
174336         , p_from_combination_id     => l_adr_value_combination_id
174337         , p_value_type_code         => l_adr_value_type_code
174338         , p_transaction_coa_id      => l_adr_transaction_coa_id
174339         , p_accounting_coa_id       => l_adr_accounting_coa_id
174340         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
174341         , p_flex_value_set_id       => l_adr_flex_value_set_id
174342         , p_adr_code                => 'FA_CAT_COST_ACCOUNT_SEGMENT'
174343         , p_adr_type_code           => 'S'
174344         , p_component_type          => l_component_type
174345         , p_component_code          => l_component_code
174346         , p_component_type_code     => l_component_type_code
174347         , p_component_appl_id       => l_component_appl_id
174348         , p_amb_context_code        => l_amb_context_code
174349         , p_entity_code             => 'TRANSACTIONS'
174350         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
174351         , p_side                    => 'NA'
174352         );
174353 
174354   END IF;
174355 
174356    l_segment := AcctDerRule_168(
174357            p_application_id           => p_application_id
174358          , p_ae_header_id             => l_ae_header_id 
174359 , p_source_3 => p_source_3
174360 , p_source_29 => p_source_29
174361          , x_transaction_coa_id       => l_adr_transaction_coa_id
174362          , x_accounting_coa_id        => l_adr_accounting_coa_id
174363          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
174364          , x_flex_value_set_id        => l_adr_flex_value_set_id
174365          , x_value_type_code          => l_adr_value_type_code
174366          , x_value_combination_id     => l_adr_value_combination_id
174367          , x_value_segment_code       => l_adr_value_segment_code
174368          , p_side                     => 'NA'
174369          , p_override_seg_flag        => 'Y'
174370    );
174371 
174372    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
174373 
174374       xla_ae_lines_pkg.set_segment(
174375           p_to_segment_code         => 'GL_BALANCING'
174376         , p_segment_value           => l_segment
174377         , p_from_segment_code       => l_adr_value_segment_code
174378         , p_from_combination_id     => l_adr_value_combination_id
174379         , p_value_type_code         => l_adr_value_type_code
174380         , p_transaction_coa_id      => l_adr_transaction_coa_id
174381         , p_accounting_coa_id       => l_adr_accounting_coa_id
174382         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
174383         , p_flex_value_set_id       => l_adr_flex_value_set_id
174384         , p_adr_code                => 'FA_EXPENSE_ACCT'
174385         , p_adr_type_code           => 'S'
174386         , p_component_type          => l_component_type
174387         , p_component_code          => l_component_code
174388         , p_component_type_code     => l_component_type_code
174389         , p_component_appl_id       => l_component_appl_id
174390         , p_amb_context_code        => l_amb_context_code
174391         , p_entity_code             => 'TRANSACTIONS'
174392         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
174393         , p_side                    => 'NA'
174394         );
174395 
174396   END IF;
174397 
174398    --
174399    --
174400    END IF;
174401 
174402        --
174403        -- Update the line information that should be overwritten
174404        --
174405        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
174406                                          p_header_num   => 1);
174407        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
174408 
174409        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
174410 
174411        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
174412           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
174413        END IF;
174414 
174415       --
174416       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
174417       --
174418       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
174419           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
174420       ELSE
174421           ---------------------------------------------------------------------------------------------------
174422           -- 4262811a Switch Sign
174423           ---------------------------------------------------------------------------------------------------
174424           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
174425           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
174426                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
174427           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
174428                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
174429           -- 5132302
174433       END IF;
174430           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
174431                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
174432 
174434 
174435       -- 4955764
174436       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
174437       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
174438 
174439 
174440       XLA_AE_LINES_PKG.ValidateCurrentLine;
174441       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
174442 
174443       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
174444                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
174445                ,p_balance_type_code => l_balance_type_code);
174446 
174447    END IF;
174448 
174449    -----------------------------------------------------------------------------------------
174450    -- 4262811 Multiperiod Accounting
174451    -----------------------------------------------------------------------------------------
174452      -- No MPA option is assigned.
174453 
174454 
174455 END IF;
174456 END IF;
174457 --
174458 
174459 --
174460 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
174461    trace
174462       (p_msg      => 'END of AcctLineType_399'
174463       ,p_level    => C_LEVEL_PROCEDURE
174464       ,p_module   => l_log_module);
174465 END IF;
174466 --
174467 EXCEPTION
174468   WHEN xla_exceptions_pkg.application_exception THEN
174469       RAISE;
174470   WHEN OTHERS THEN
174471        xla_exceptions_pkg.raise_message
174472            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_399');
174473 END AcctLineType_399;
174474 --
174475 
174476 ---------------------------------------
174477 --
174478 -- PRIVATE FUNCTION
174479 --         AcctLineType_400
174480 --
174481 ---------------------------------------
174482 PROCEDURE AcctLineType_400 (
174483   p_application_id        IN NUMBER
174484  ,p_event_id              IN NUMBER
174485  ,p_calculate_acctd_flag  IN VARCHAR2
174486  ,p_calculate_g_l_flag    IN VARCHAR2
174487  ,p_actual_flag           IN OUT VARCHAR2
174488  ,p_balance_type_code     OUT VARCHAR2
174489  ,p_gain_or_loss_ref      OUT VARCHAR2
174490  
174491 --Period Close Date
174492  , p_source_1            IN DATE
174493 --Generated Code Combination Identifier
174494  , p_source_3            IN NUMBER
174495 --Expense Account Code Combination Identifier
174496  , p_source_29            IN NUMBER
174497 --Adjustment Type
174498  , p_source_35            IN VARCHAR2
174499 --Transaction Header Identifier
174500  , p_source_36            IN NUMBER
174501 --Adjustment Line Identifier
174502  , p_source_37            IN NUMBER
174503 --Distribution Type Code
174504  , p_source_38            IN VARCHAR2
174505 --Entered Amount
174506  , p_source_39            IN NUMBER
174507 --Currency Code
174508  , p_source_40            IN VARCHAR2
174509 --Source Destination Code
174510  , p_source_42            IN VARCHAR2
174511 )
174512 IS
174513 
174514 l_component_type              VARCHAR2(80);
174515 l_component_code              VARCHAR2(30);
174516 l_component_type_code         VARCHAR2(1);
174517 l_component_appl_id           INTEGER;
174518 l_amb_context_code            VARCHAR2(30);
174519 l_entity_code                 VARCHAR2(30);
174520 l_event_class_code            VARCHAR2(30);
174521 l_ae_header_id                NUMBER;
174522 l_event_type_code             VARCHAR2(30);
174523 l_line_definition_code        VARCHAR2(30);
174524 l_line_definition_owner_code  VARCHAR2(1);
174525 --
174526 -- adr variables
174527 l_segment                     VARCHAR2(30);
174528 l_ccid                        NUMBER;
174529 l_adr_transaction_coa_id      NUMBER;
174530 l_adr_accounting_coa_id       NUMBER;
174531 l_adr_flexfield_segment_code  VARCHAR2(30);
174532 l_adr_flex_value_set_id       NUMBER;
174533 l_adr_value_type_code         VARCHAR2(30);
174534 l_adr_value_combination_id    NUMBER;
174535 l_adr_value_segment_code      VARCHAR2(30);
174536 
174537 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
174538 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
174539 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
174540 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
174541 
174542 -- 4262811 Variables ------------------------------------------------------------------------------------------
174543 l_entered_amt_idx             NUMBER;
174544 l_accted_amt_idx              NUMBER;
174545 l_acc_rev_flag                VARCHAR2(1);
174546 l_accrual_line_num            NUMBER;
174547 l_tmp_amt                     NUMBER;
174548 l_acc_rev_natural_side_code   VARCHAR2(1);
174549 
174550 l_num_entries                 NUMBER;
174551 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
174552 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
174553 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
174554 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
174555 l_recog_line_1                NUMBER;
174556 l_recog_line_2                NUMBER;
174557 
174558 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
174559 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
174560 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
174561 
174562 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
174563 
174564 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
174565 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
174566 
174567 ---------------------------------------------------------------------------------------------------------------
174571 -- bulk performance
174568 
174569 
174570 --
174572 --
174573 l_balance_type_code           VARCHAR2(1);
174574 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
174575 l_log_module                  VARCHAR2(240);
174576 
174577 --
174578 -- Upgrade strategy
174579 --
174580 l_actual_upg_option           VARCHAR2(1);
174581 l_enc_upg_option           VARCHAR2(1);
174582 
174583 --
174584 BEGIN
174585 --
174586 IF g_log_enabled THEN
174587       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_400';
174588 END IF;
174589 --
174590 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
174591 
174592       trace
174593          (p_msg      => 'BEGIN of AcctLineType_400'
174594          ,p_level    => C_LEVEL_PROCEDURE
174595          ,p_module   => l_log_module);
174596 
174597 END IF;
174598 --
174599 l_component_type             := 'AMB_JLT';
174600 l_component_code             := 'FA_UNITADJ_SOURCE_DEPRN_EXP';
174601 l_component_type_code        := 'S';
174602 l_component_appl_id          :=  140;
174603 l_amb_context_code           := 'DEFAULT';
174604 l_entity_code                := 'TRANSACTIONS';
174605 l_event_class_code           := 'UNIT_ADJUSTMENTS';
174606 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
174607 l_line_definition_owner_code := 'S';
174608 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
174609 --
174610 l_balance_type_code          := 'A';
174611 l_segment                     := NULL;
174612 l_ccid                        := NULL;
174613 l_adr_transaction_coa_id      := NULL;
174614 l_adr_accounting_coa_id       := NULL;
174615 l_adr_flexfield_segment_code  := NULL;
174616 l_adr_flex_value_set_id       := NULL;
174617 l_adr_value_type_code         := NULL;
174618 l_adr_value_combination_id    := NULL;
174619 l_adr_value_segment_code      := NULL;
174620 
174621 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
174622 l_bflow_class_code           := '';    -- 4219869 Business Flow
174623 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
174624 l_budgetary_control_flag     := 'N';
174625 
174626 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
174627 l_bflow_applied_to_amt       := NULL; -- 5132302
174628 l_entered_amt_idx            := NULL;          -- 4262811
174629 l_accted_amt_idx             := NULL;          -- 4262811
174630 l_acc_rev_flag               := NULL;          -- 4262811
174631 l_accrual_line_num           := NULL;          -- 4262811
174632 l_tmp_amt                    := NULL;          -- 4262811
174633 --
174634  
174635 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
174636     l_balance_type_code <> 'B' THEN
174637 IF NVL(p_source_35,'
174638 ') =  'EXPENSE' AND 
174639 NVL(p_source_42,'
174640 ') =  'SOURCE'
174641  THEN 
174642 
174643    --
174644    XLA_AE_LINES_PKG.SetNewLine;
174645 
174646    p_balance_type_code          := l_balance_type_code;
174647    -- set the flag so later we will know whether the gain loss line needs to be created
174648    
174649    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
174650      p_actual_flag :='A';
174651    END IF;
174652 
174653    --
174654    -- bulk performance
174655    --
174656    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
174657                                       p_header_num   => 0); -- 4262811
174658    --
174659    -- set accounting line options
174660    --
174661    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
174662            p_natural_side_code          => 'C'
174663          , p_gain_or_loss_flag          => 'N'
174664          , p_gl_transfer_mode_code      => 'S'
174665          , p_acct_entry_type_code       => 'A'
174666          , p_switch_side_flag           => 'Y'
174667          , p_merge_duplicate_code       => 'N'
174668          );
174669    --
174670    l_acc_rev_natural_side_code := 'D';  -- 4262811
174671    -- 
174672    --
174673    -- set accounting line type info
174674    --
174675    xla_ae_lines_pkg.SetAcctLineType
174676       (p_component_type             => l_component_type
174677       ,p_event_type_code            => l_event_type_code
174678       ,p_line_definition_owner_code => l_line_definition_owner_code
174679       ,p_line_definition_code       => l_line_definition_code
174680       ,p_accounting_line_code       => l_component_code
174681       ,p_accounting_line_type_code  => l_component_type_code
174682       ,p_accounting_line_appl_id    => l_component_appl_id
174683       ,p_amb_context_code           => l_amb_context_code
174684       ,p_entity_code                => l_entity_code
174685       ,p_event_class_code           => l_event_class_code);
174686    --
174687    -- set accounting class
174688    --
174689    xla_ae_lines_pkg.SetAcctClass(
174690            p_accounting_class_code  => 'EXPENSE'
174691          , p_ae_header_id           => l_ae_header_id
174692          );
174693 
174694    --
174695    -- set rounding class
174696    --
174697    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
174698                       'EXPENSE';
174699 
174700    --
174701    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
174702    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
174703    --
174704    -- bulk performance
174705    --
174706    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
174707 
174708    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
174709       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
174710 
174711    -- 4955764
174712    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
174716    
174713       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
174714 
174715    -- 4458381 Public Sector Enh
174717    --
174718    -- set accounting attributes for the line type
174719    --
174720    l_entered_amt_idx := 4;
174721    l_accted_amt_idx  := 6;
174722    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
174723    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
174724    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
174725    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
174726    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
174727    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
174728    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
174729    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
174730    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
174731    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
174732    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
174733    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
174734    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
174735 
174736    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
174737    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
174738 
174739    ---------------------------------------------------------------------------------------------------------------
174740    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
174741    ---------------------------------------------------------------------------------------------------------------
174742    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
174743 
174744    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
174745    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
174746 
174747    IF xla_accounting_cache_pkg.GetValueChar
174748          (p_source_code         => 'LEDGER_CATEGORY_CODE'
174749          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
174750    AND l_bflow_method_code = 'PRIOR_ENTRY'
174751 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
174752    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
174753          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
174754        )
174755    THEN
174756          xla_ae_lines_pkg.BflowUpgEntry
174757            (p_business_method_code    => l_bflow_method_code
174758            ,p_business_class_code     => l_bflow_class_code
174759            ,p_balance_type            => l_balance_type_code);
174760    ELSE
174761       NULL;
174762 -- No business flow processing for business flow method of NONE.
174763    END IF;
174764 
174765    --
174766    -- call analytical criteria
174767    --
174768    
174769    --
174770    -- call description
174771    --
174772    
174773 xla_ae_lines_pkg.SetLineDescription(
174774    p_ae_header_id => l_ae_header_id
174775   ,p_description  => Description_134 (
174776      p_application_id         => p_application_id
174777    , p_ae_header_id           => l_ae_header_id 
174778 , p_source_1 => p_source_1
174779    )
174780 );
174781 
174782 
174783    --
174784    -- call ADRs
174785    -- Bug 4922099
174786    --
174787    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
174788         (NVL(l_actual_upg_option, 'N') = 'O') OR
174789         (NVL(l_enc_upg_option, 'N') = 'O')
174790       )
174791    THEN
174792    NULL;
174793    --
174794    --
174795    
174796   l_ccid := AcctDerRule_175(
174797            p_application_id           => p_application_id
174798          , p_ae_header_id             => l_ae_header_id 
174799 , p_source_3 => p_source_3
174800 , p_source_29 => p_source_29
174801          , x_transaction_coa_id       => l_adr_transaction_coa_id
174802          , x_accounting_coa_id        => l_adr_accounting_coa_id
174803          , x_value_type_code          => l_adr_value_type_code
174804          , p_side                     => 'NA'
174805    );
174806 
174807    xla_ae_lines_pkg.set_ccid(
174808     p_code_combination_id          => l_ccid
174809   , p_value_type_code              => l_adr_value_type_code
174810   , p_transaction_coa_id           => l_adr_transaction_coa_id
174811   , p_accounting_coa_id            => l_adr_accounting_coa_id
174812   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
174813   , p_adr_type_code                => 'S'
174814   , p_component_type               => l_component_type
174815   , p_component_code               => l_component_code
174816   , p_component_type_code          => l_component_type_code
174817   , p_component_appl_id            => l_component_appl_id
174818   , p_amb_context_code             => l_amb_context_code
174819   , p_side                         => 'NA'
174820   );
174821 
174822 
174823    --
174824    --
174825    END IF;
174826    --
174827    -- Bug 4922099
174828    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
174829           (NVL(l_enc_upg_option, 'N') = 'O')
174830         ) AND
174831         (l_bflow_method_code = 'PRIOR_ENTRY')
174832       )
174833    THEN
174834       IF
174835       --
174836       1 = 2
174837       --
174838       THEN
174839       xla_accounting_err_pkg.build_message
174840                                     (p_appli_s_name            => 'XLA'
174841                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
174842                                     ,p_token_1                 => 'LINE_NUMBER'
174843                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
174844                                     ,p_token_2                 => 'LINE_TYPE_NAME'
174848                                                                             ,l_component_type_code
174845                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
174846                                                                              l_component_type
174847                                                                             ,l_component_code
174849                                                                             ,l_component_appl_id
174850                                                                             ,l_amb_context_code
174851                                                                             ,l_entity_code
174852                                                                             ,l_event_class_code
174853                                                                            )
174854                                     ,p_token_3                 => 'OWNER'
174855                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
174856                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
174857                                                                           ,p_lookup_code    => l_component_type_code
174858                                                                          )
174859                                     ,p_token_4                 => 'PRODUCT_NAME'
174860                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
174861                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
174862                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
174863                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
174864                                     ,p_ae_header_id            =>  NULL
174865                                        );
174866 
174867         IF (C_LEVEL_ERROR>= g_log_level) THEN
174868                  trace
174869                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
174870                       ,p_level    => C_LEVEL_ERROR
174871                       ,p_module   => l_log_module);
174872         END IF;
174873       END IF;
174874    END IF;
174875    --
174876    --
174877    ------------------------------------------------------------------------------------------------
174878    -- 4219869 Business Flow
174879    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
174880    -- Prior Entry.  Currently, the following code is always generated.
174881    ------------------------------------------------------------------------------------------------
174882    XLA_AE_LINES_PKG.ValidateCurrentLine;
174883 
174884    ------------------------------------------------------------------------------------
174885    -- 4219869 Business Flow
174886    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
174887    ------------------------------------------------------------------------------------
174888    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
174889 
174890    ----------------------------------------------------------------------------------
174891    -- 4219869 Business Flow
174892    -- Update journal entry status -- Need to generate this within IF <condition>
174893    ----------------------------------------------------------------------------------
174894    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
174895          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
174896          ,p_balance_type_code => l_balance_type_code
174897          );
174898 
174899    -------------------------------------------------------------------------------------------
174900    -- 4262811 - Generate the Accrual Reversal lines
174901    -------------------------------------------------------------------------------------------
174902    BEGIN
174903       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
174904                               (g_array_event(p_event_id).array_value_num('header_index'));
174905       IF l_acc_rev_flag IS NULL THEN
174906          l_acc_rev_flag := 'N';
174907       END IF;
174908    EXCEPTION
174909       WHEN OTHERS THEN
174910          l_acc_rev_flag := 'N';
174911    END;
174912    --
174913    IF (l_acc_rev_flag = 'Y') THEN
174914 
174915        -- 4645092  ------------------------------------------------------------------------------
174916        -- To allow MPA report to determine if it should generate report process
174917        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
174918        ------------------------------------------------------------------------------------------
174919 
174920        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
174921        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
174922    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
174923    -- call ADRs
174924    -- Bug 4922099
174925    --
174926    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
174927         (NVL(l_actual_upg_option, 'N') = 'O') OR
174928         (NVL(l_enc_upg_option, 'N') = 'O')
174929       )
174930    THEN
174931    NULL;
174932    --
174933    --
174934    
174935   l_ccid := AcctDerRule_175(
174936            p_application_id           => p_application_id
174937          , p_ae_header_id             => l_ae_header_id 
174938 , p_source_3 => p_source_3
174939 , p_source_29 => p_source_29
174940          , x_transaction_coa_id       => l_adr_transaction_coa_id
174941          , x_accounting_coa_id        => l_adr_accounting_coa_id
174942          , x_value_type_code          => l_adr_value_type_code
174943          , p_side                     => 'NA'
174944    );
174945 
174946    xla_ae_lines_pkg.set_ccid(
174947     p_code_combination_id          => l_ccid
174948   , p_value_type_code              => l_adr_value_type_code
174949   , p_transaction_coa_id           => l_adr_transaction_coa_id
174953   , p_component_type               => l_component_type
174950   , p_accounting_coa_id            => l_adr_accounting_coa_id
174951   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
174952   , p_adr_type_code                => 'S'
174954   , p_component_code               => l_component_code
174955   , p_component_type_code          => l_component_type_code
174956   , p_component_appl_id            => l_component_appl_id
174957   , p_amb_context_code             => l_amb_context_code
174958   , p_side                         => 'NA'
174959   );
174960 
174961 
174962    --
174963    --
174964    END IF;
174965 
174966        --
174967        -- Update the line information that should be overwritten
174968        --
174969        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
174970                                          p_header_num   => 1);
174971        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
174972 
174973        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
174974 
174975        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
174976           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
174977        END IF;
174978 
174979       --
174980       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
174981       --
174982       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
174983           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
174984       ELSE
174985           ---------------------------------------------------------------------------------------------------
174986           -- 4262811a Switch Sign
174987           ---------------------------------------------------------------------------------------------------
174988           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
174989           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
174990                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
174991           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
174992                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
174993           -- 5132302
174994           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
174995                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
174996 
174997       END IF;
174998 
174999       -- 4955764
175000       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
175001       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
175002 
175003 
175004       XLA_AE_LINES_PKG.ValidateCurrentLine;
175005       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
175006 
175007       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
175008                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
175009                ,p_balance_type_code => l_balance_type_code);
175010 
175011    END IF;
175012 
175013    -----------------------------------------------------------------------------------------
175014    -- 4262811 Multiperiod Accounting
175015    -----------------------------------------------------------------------------------------
175016      -- No MPA option is assigned.
175017 
175018 
175019 END IF;
175020 END IF;
175021 --
175022 
175023 --
175024 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
175025    trace
175026       (p_msg      => 'END of AcctLineType_400'
175027       ,p_level    => C_LEVEL_PROCEDURE
175028       ,p_module   => l_log_module);
175029 END IF;
175030 --
175031 EXCEPTION
175032   WHEN xla_exceptions_pkg.application_exception THEN
175033       RAISE;
175034   WHEN OTHERS THEN
175035        xla_exceptions_pkg.raise_message
175036            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_400');
175037 END AcctLineType_400;
175038 --
175039 
175040 ---------------------------------------
175041 --
175042 -- PRIVATE FUNCTION
175043 --         AcctLineType_401
175044 --
175045 ---------------------------------------
175046 PROCEDURE AcctLineType_401 (
175047   p_application_id        IN NUMBER
175048  ,p_event_id              IN NUMBER
175049  ,p_calculate_acctd_flag  IN VARCHAR2
175050  ,p_calculate_g_l_flag    IN VARCHAR2
175051  ,p_actual_flag           IN OUT VARCHAR2
175052  ,p_balance_type_code     OUT VARCHAR2
175053  ,p_gain_or_loss_ref      OUT VARCHAR2
175054  
175055 --Period Close Date
175056  , p_source_1            IN DATE
175057 --Generated Code Combination Identifier
175058  , p_source_3            IN NUMBER
175059 --Depreciation Reserve Account
175060  , p_source_10            IN VARCHAR2
175061 --Generated Offset Code Combination Identifier
175062  , p_source_17            IN NUMBER
175063 --Expense Account Code Combination Identifier
175064  , p_source_29            IN NUMBER
175065 --Default Code Combination Identifier
175066  , p_source_30            IN NUMBER
175067 --Adjustment Type
175071 --Adjustment Line Identifier
175068  , p_source_35            IN VARCHAR2
175069 --Transaction Header Identifier
175070  , p_source_36            IN NUMBER
175072  , p_source_37            IN NUMBER
175073 --Distribution Type Code
175074  , p_source_38            IN VARCHAR2
175075 --Entered Amount
175076  , p_source_39            IN NUMBER
175077 --Currency Code
175078  , p_source_40            IN VARCHAR2
175079 --Source Destination Code
175080  , p_source_42            IN VARCHAR2
175081 )
175082 IS
175083 
175084 l_component_type              VARCHAR2(80);
175085 l_component_code              VARCHAR2(30);
175086 l_component_type_code         VARCHAR2(1);
175087 l_component_appl_id           INTEGER;
175088 l_amb_context_code            VARCHAR2(30);
175089 l_entity_code                 VARCHAR2(30);
175090 l_event_class_code            VARCHAR2(30);
175091 l_ae_header_id                NUMBER;
175092 l_event_type_code             VARCHAR2(30);
175093 l_line_definition_code        VARCHAR2(30);
175094 l_line_definition_owner_code  VARCHAR2(1);
175095 --
175096 -- adr variables
175097 l_segment                     VARCHAR2(30);
175098 l_ccid                        NUMBER;
175099 l_adr_transaction_coa_id      NUMBER;
175100 l_adr_accounting_coa_id       NUMBER;
175101 l_adr_flexfield_segment_code  VARCHAR2(30);
175102 l_adr_flex_value_set_id       NUMBER;
175103 l_adr_value_type_code         VARCHAR2(30);
175104 l_adr_value_combination_id    NUMBER;
175105 l_adr_value_segment_code      VARCHAR2(30);
175106 
175107 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
175108 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
175109 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
175110 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
175111 
175112 -- 4262811 Variables ------------------------------------------------------------------------------------------
175113 l_entered_amt_idx             NUMBER;
175114 l_accted_amt_idx              NUMBER;
175115 l_acc_rev_flag                VARCHAR2(1);
175116 l_accrual_line_num            NUMBER;
175117 l_tmp_amt                     NUMBER;
175118 l_acc_rev_natural_side_code   VARCHAR2(1);
175119 
175120 l_num_entries                 NUMBER;
175121 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
175122 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
175123 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
175124 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
175125 l_recog_line_1                NUMBER;
175126 l_recog_line_2                NUMBER;
175127 
175128 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
175129 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
175130 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
175131 
175132 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
175133 
175134 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
175135 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
175136 
175137 ---------------------------------------------------------------------------------------------------------------
175138 
175139 
175140 --
175141 -- bulk performance
175142 --
175143 l_balance_type_code           VARCHAR2(1);
175144 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
175145 l_log_module                  VARCHAR2(240);
175146 
175147 --
175148 -- Upgrade strategy
175149 --
175150 l_actual_upg_option           VARCHAR2(1);
175151 l_enc_upg_option           VARCHAR2(1);
175152 
175153 --
175154 BEGIN
175155 --
175156 IF g_log_enabled THEN
175157       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_401';
175158 END IF;
175159 --
175160 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
175161 
175162       trace
175163          (p_msg      => 'BEGIN of AcctLineType_401'
175164          ,p_level    => C_LEVEL_PROCEDURE
175165          ,p_module   => l_log_module);
175166 
175167 END IF;
175168 --
175169 l_component_type             := 'AMB_JLT';
175170 l_component_code             := 'FA_UNITADJ_SOURCE_DEPRN_RES';
175171 l_component_type_code        := 'S';
175172 l_component_appl_id          :=  140;
175173 l_amb_context_code           := 'DEFAULT';
175174 l_entity_code                := 'TRANSACTIONS';
175175 l_event_class_code           := 'UNIT_ADJUSTMENTS';
175176 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
175177 l_line_definition_owner_code := 'S';
175178 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
175179 --
175180 l_balance_type_code          := 'A';
175181 l_segment                     := NULL;
175182 l_ccid                        := NULL;
175183 l_adr_transaction_coa_id      := NULL;
175184 l_adr_accounting_coa_id       := NULL;
175185 l_adr_flexfield_segment_code  := NULL;
175186 l_adr_flex_value_set_id       := NULL;
175187 l_adr_value_type_code         := NULL;
175188 l_adr_value_combination_id    := NULL;
175189 l_adr_value_segment_code      := NULL;
175190 
175191 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
175192 l_bflow_class_code           := '';    -- 4219869 Business Flow
175193 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
175194 l_budgetary_control_flag     := 'N';
175195 
175196 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
175197 l_bflow_applied_to_amt       := NULL; -- 5132302
175198 l_entered_amt_idx            := NULL;          -- 4262811
175199 l_accted_amt_idx             := NULL;          -- 4262811
175200 l_acc_rev_flag               := NULL;          -- 4262811
175201 l_accrual_line_num           := NULL;          -- 4262811
175202 l_tmp_amt                    := NULL;          -- 4262811
175203 --
175204  
175208 ') =  'RESERVE' OR 
175205 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
175206     l_balance_type_code <> 'B' THEN
175207 IF (NVL(p_source_35,'
175209 NVL(p_source_35,'
175210 ') =  'EXPENSE') AND 
175211 NVL(p_source_42,'
175212 ') =  'SOURCE'
175213  THEN 
175214 
175215    --
175216    XLA_AE_LINES_PKG.SetNewLine;
175217 
175218    p_balance_type_code          := l_balance_type_code;
175219    -- set the flag so later we will know whether the gain loss line needs to be created
175220    
175221    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
175222      p_actual_flag :='A';
175223    END IF;
175224 
175225    --
175226    -- bulk performance
175227    --
175228    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
175229                                       p_header_num   => 0); -- 4262811
175230    --
175231    -- set accounting line options
175232    --
175233    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
175234            p_natural_side_code          => 'D'
175235          , p_gain_or_loss_flag          => 'N'
175236          , p_gl_transfer_mode_code      => 'S'
175237          , p_acct_entry_type_code       => 'A'
175238          , p_switch_side_flag           => 'Y'
175239          , p_merge_duplicate_code       => 'N'
175240          );
175241    --
175242    l_acc_rev_natural_side_code := 'C';  -- 4262811
175243    -- 
175244    --
175245    -- set accounting line type info
175246    --
175247    xla_ae_lines_pkg.SetAcctLineType
175248       (p_component_type             => l_component_type
175249       ,p_event_type_code            => l_event_type_code
175250       ,p_line_definition_owner_code => l_line_definition_owner_code
175251       ,p_line_definition_code       => l_line_definition_code
175252       ,p_accounting_line_code       => l_component_code
175253       ,p_accounting_line_type_code  => l_component_type_code
175254       ,p_accounting_line_appl_id    => l_component_appl_id
175255       ,p_amb_context_code           => l_amb_context_code
175256       ,p_entity_code                => l_entity_code
175257       ,p_event_class_code           => l_event_class_code);
175258    --
175259    -- set accounting class
175260    --
175261    xla_ae_lines_pkg.SetAcctClass(
175262            p_accounting_class_code  => 'ASSET'
175263          , p_ae_header_id           => l_ae_header_id
175264          );
175265 
175266    --
175267    -- set rounding class
175268    --
175269    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
175270                       'ASSET';
175271 
175272    --
175273    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
175274    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
175275    --
175276    -- bulk performance
175277    --
175278    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
175279 
175280    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
175281       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
175282 
175283    -- 4955764
175284    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
175285       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
175286 
175287    -- 4458381 Public Sector Enh
175288    
175289    --
175290    -- set accounting attributes for the line type
175291    --
175292    l_entered_amt_idx := 4;
175293    l_accted_amt_idx  := 6;
175294    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
175295    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
175296    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
175297    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
175298    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
175299    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
175300    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
175301    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
175302    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
175303    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
175304    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
175305    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
175306    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
175307 
175308    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
175309    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
175310 
175311    ---------------------------------------------------------------------------------------------------------------
175312    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
175313    ---------------------------------------------------------------------------------------------------------------
175314    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
175315 
175316    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
175317    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
175318 
175319    IF xla_accounting_cache_pkg.GetValueChar
175320          (p_source_code         => 'LEDGER_CATEGORY_CODE'
175321          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
175322    AND l_bflow_method_code = 'PRIOR_ENTRY'
175323 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
175324    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
175325          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
175326        )
175327    THEN
175328          xla_ae_lines_pkg.BflowUpgEntry
175332    ELSE
175329            (p_business_method_code    => l_bflow_method_code
175330            ,p_business_class_code     => l_bflow_class_code
175331            ,p_balance_type            => l_balance_type_code);
175333       NULL;
175334 -- No business flow processing for business flow method of NONE.
175335    END IF;
175336 
175337    --
175338    -- call analytical criteria
175339    --
175340    
175341    --
175342    -- call description
175343    --
175344    
175345 xla_ae_lines_pkg.SetLineDescription(
175346    p_ae_header_id => l_ae_header_id
175347   ,p_description  => Description_137 (
175348      p_application_id         => p_application_id
175349    , p_ae_header_id           => l_ae_header_id 
175350 , p_source_1 => p_source_1
175351    )
175352 );
175353 
175354 
175355    --
175356    -- call ADRs
175357    -- Bug 4922099
175358    --
175359    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
175360         (NVL(l_actual_upg_option, 'N') = 'O') OR
175361         (NVL(l_enc_upg_option, 'N') = 'O')
175362       )
175363    THEN
175364    NULL;
175365    --
175366    --
175367    
175368   l_ccid := AcctDerRule_174(
175369            p_application_id           => p_application_id
175370          , p_ae_header_id             => l_ae_header_id 
175371 , p_source_3 => p_source_3
175372 , p_source_17 => p_source_17
175373 , p_source_30 => p_source_30
175374          , x_transaction_coa_id       => l_adr_transaction_coa_id
175375          , x_accounting_coa_id        => l_adr_accounting_coa_id
175376          , x_value_type_code          => l_adr_value_type_code
175377          , p_side                     => 'NA'
175378    );
175379 
175380    xla_ae_lines_pkg.set_ccid(
175381     p_code_combination_id          => l_ccid
175382   , p_value_type_code              => l_adr_value_type_code
175383   , p_transaction_coa_id           => l_adr_transaction_coa_id
175384   , p_accounting_coa_id            => l_adr_accounting_coa_id
175385   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
175386   , p_adr_type_code                => 'S'
175387   , p_component_type               => l_component_type
175388   , p_component_code               => l_component_code
175389   , p_component_type_code          => l_component_type_code
175390   , p_component_appl_id            => l_component_appl_id
175391   , p_amb_context_code             => l_amb_context_code
175392   , p_side                         => 'NA'
175393   );
175394 
175395 
175396    l_segment := AcctDerRule_149(
175397            p_application_id           => p_application_id
175398          , p_ae_header_id             => l_ae_header_id 
175399 , p_source_3 => p_source_3
175400 , p_source_10 => p_source_10
175401          , x_transaction_coa_id       => l_adr_transaction_coa_id
175402          , x_accounting_coa_id        => l_adr_accounting_coa_id
175403          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
175404          , x_flex_value_set_id        => l_adr_flex_value_set_id
175405          , x_value_type_code          => l_adr_value_type_code
175406          , x_value_combination_id     => l_adr_value_combination_id
175407          , x_value_segment_code       => l_adr_value_segment_code
175408          , p_side                     => 'NA'
175409          , p_override_seg_flag        => 'Y'
175410    );
175411 
175412    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
175413 
175414       xla_ae_lines_pkg.set_segment(
175415           p_to_segment_code         => 'GL_ACCOUNT'
175416         , p_segment_value           => l_segment
175417         , p_from_segment_code       => l_adr_value_segment_code
175418         , p_from_combination_id     => l_adr_value_combination_id
175419         , p_value_type_code         => l_adr_value_type_code
175420         , p_transaction_coa_id      => l_adr_transaction_coa_id
175421         , p_accounting_coa_id       => l_adr_accounting_coa_id
175422         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
175423         , p_flex_value_set_id       => l_adr_flex_value_set_id
175424         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
175425         , p_adr_type_code           => 'S'
175426         , p_component_type          => l_component_type
175427         , p_component_code          => l_component_code
175428         , p_component_type_code     => l_component_type_code
175429         , p_component_appl_id       => l_component_appl_id
175430         , p_amb_context_code        => l_amb_context_code
175431         , p_entity_code             => 'TRANSACTIONS'
175432         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
175433         , p_side                    => 'NA'
175434         );
175435 
175436   END IF;
175437 
175438    l_segment := AcctDerRule_168(
175439            p_application_id           => p_application_id
175440          , p_ae_header_id             => l_ae_header_id 
175441 , p_source_3 => p_source_3
175442 , p_source_29 => p_source_29
175443          , x_transaction_coa_id       => l_adr_transaction_coa_id
175444          , x_accounting_coa_id        => l_adr_accounting_coa_id
175445          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
175446          , x_flex_value_set_id        => l_adr_flex_value_set_id
175447          , x_value_type_code          => l_adr_value_type_code
175448          , x_value_combination_id     => l_adr_value_combination_id
175449          , x_value_segment_code       => l_adr_value_segment_code
175450          , p_side                     => 'NA'
175451          , p_override_seg_flag        => 'Y'
175452    );
175453 
175454    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
175455 
175456       xla_ae_lines_pkg.set_segment(
175457           p_to_segment_code         => 'GL_BALANCING'
175458         , p_segment_value           => l_segment
175459         , p_from_segment_code       => l_adr_value_segment_code
175460         , p_from_combination_id     => l_adr_value_combination_id
175464         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
175461         , p_value_type_code         => l_adr_value_type_code
175462         , p_transaction_coa_id      => l_adr_transaction_coa_id
175463         , p_accounting_coa_id       => l_adr_accounting_coa_id
175465         , p_flex_value_set_id       => l_adr_flex_value_set_id
175466         , p_adr_code                => 'FA_EXPENSE_ACCT'
175467         , p_adr_type_code           => 'S'
175468         , p_component_type          => l_component_type
175469         , p_component_code          => l_component_code
175470         , p_component_type_code     => l_component_type_code
175471         , p_component_appl_id       => l_component_appl_id
175472         , p_amb_context_code        => l_amb_context_code
175473         , p_entity_code             => 'TRANSACTIONS'
175474         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
175475         , p_side                    => 'NA'
175476         );
175477 
175478   END IF;
175479 
175480    --
175481    --
175482    END IF;
175483    --
175484    -- Bug 4922099
175485    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
175486           (NVL(l_enc_upg_option, 'N') = 'O')
175487         ) AND
175488         (l_bflow_method_code = 'PRIOR_ENTRY')
175489       )
175490    THEN
175491       IF
175492       --
175493       1 = 2
175494       --
175495       THEN
175496       xla_accounting_err_pkg.build_message
175497                                     (p_appli_s_name            => 'XLA'
175498                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
175499                                     ,p_token_1                 => 'LINE_NUMBER'
175500                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
175501                                     ,p_token_2                 => 'LINE_TYPE_NAME'
175502                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
175503                                                                              l_component_type
175504                                                                             ,l_component_code
175505                                                                             ,l_component_type_code
175506                                                                             ,l_component_appl_id
175507                                                                             ,l_amb_context_code
175508                                                                             ,l_entity_code
175509                                                                             ,l_event_class_code
175510                                                                            )
175511                                     ,p_token_3                 => 'OWNER'
175512                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
175513                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
175514                                                                           ,p_lookup_code    => l_component_type_code
175515                                                                          )
175516                                     ,p_token_4                 => 'PRODUCT_NAME'
175517                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
175518                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
175519                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
175520                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
175521                                     ,p_ae_header_id            =>  NULL
175522                                        );
175523 
175524         IF (C_LEVEL_ERROR>= g_log_level) THEN
175525                  trace
175526                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
175527                       ,p_level    => C_LEVEL_ERROR
175528                       ,p_module   => l_log_module);
175529         END IF;
175530       END IF;
175531    END IF;
175532    --
175533    --
175534    ------------------------------------------------------------------------------------------------
175535    -- 4219869 Business Flow
175536    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
175537    -- Prior Entry.  Currently, the following code is always generated.
175538    ------------------------------------------------------------------------------------------------
175539    XLA_AE_LINES_PKG.ValidateCurrentLine;
175540 
175541    ------------------------------------------------------------------------------------
175542    -- 4219869 Business Flow
175543    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
175544    ------------------------------------------------------------------------------------
175545    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
175546 
175547    ----------------------------------------------------------------------------------
175548    -- 4219869 Business Flow
175549    -- Update journal entry status -- Need to generate this within IF <condition>
175550    ----------------------------------------------------------------------------------
175551    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
175552          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
175553          ,p_balance_type_code => l_balance_type_code
175554          );
175555 
175556    -------------------------------------------------------------------------------------------
175557    -- 4262811 - Generate the Accrual Reversal lines
175558    -------------------------------------------------------------------------------------------
175559    BEGIN
175560       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
175561                               (g_array_event(p_event_id).array_value_num('header_index'));
175562       IF l_acc_rev_flag IS NULL THEN
175566       WHEN OTHERS THEN
175563          l_acc_rev_flag := 'N';
175564       END IF;
175565    EXCEPTION
175567          l_acc_rev_flag := 'N';
175568    END;
175569    --
175570    IF (l_acc_rev_flag = 'Y') THEN
175571 
175572        -- 4645092  ------------------------------------------------------------------------------
175573        -- To allow MPA report to determine if it should generate report process
175574        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
175575        ------------------------------------------------------------------------------------------
175576 
175577        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
175578        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
175579    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
175580    -- call ADRs
175581    -- Bug 4922099
175582    --
175583    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
175584         (NVL(l_actual_upg_option, 'N') = 'O') OR
175585         (NVL(l_enc_upg_option, 'N') = 'O')
175586       )
175587    THEN
175588    NULL;
175589    --
175590    --
175591    
175592   l_ccid := AcctDerRule_174(
175593            p_application_id           => p_application_id
175594          , p_ae_header_id             => l_ae_header_id 
175595 , p_source_3 => p_source_3
175596 , p_source_17 => p_source_17
175597 , p_source_30 => p_source_30
175598          , x_transaction_coa_id       => l_adr_transaction_coa_id
175599          , x_accounting_coa_id        => l_adr_accounting_coa_id
175600          , x_value_type_code          => l_adr_value_type_code
175601          , p_side                     => 'NA'
175602    );
175603 
175604    xla_ae_lines_pkg.set_ccid(
175605     p_code_combination_id          => l_ccid
175606   , p_value_type_code              => l_adr_value_type_code
175607   , p_transaction_coa_id           => l_adr_transaction_coa_id
175608   , p_accounting_coa_id            => l_adr_accounting_coa_id
175609   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
175610   , p_adr_type_code                => 'S'
175611   , p_component_type               => l_component_type
175612   , p_component_code               => l_component_code
175613   , p_component_type_code          => l_component_type_code
175614   , p_component_appl_id            => l_component_appl_id
175615   , p_amb_context_code             => l_amb_context_code
175616   , p_side                         => 'NA'
175617   );
175618 
175619 
175620    l_segment := AcctDerRule_149(
175621            p_application_id           => p_application_id
175622          , p_ae_header_id             => l_ae_header_id 
175623 , p_source_3 => p_source_3
175624 , p_source_10 => p_source_10
175625          , x_transaction_coa_id       => l_adr_transaction_coa_id
175626          , x_accounting_coa_id        => l_adr_accounting_coa_id
175627          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
175628          , x_flex_value_set_id        => l_adr_flex_value_set_id
175629          , x_value_type_code          => l_adr_value_type_code
175630          , x_value_combination_id     => l_adr_value_combination_id
175631          , x_value_segment_code       => l_adr_value_segment_code
175632          , p_side                     => 'NA'
175633          , p_override_seg_flag        => 'Y'
175634    );
175635 
175636    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
175637 
175638       xla_ae_lines_pkg.set_segment(
175639           p_to_segment_code         => 'GL_ACCOUNT'
175640         , p_segment_value           => l_segment
175641         , p_from_segment_code       => l_adr_value_segment_code
175642         , p_from_combination_id     => l_adr_value_combination_id
175643         , p_value_type_code         => l_adr_value_type_code
175644         , p_transaction_coa_id      => l_adr_transaction_coa_id
175645         , p_accounting_coa_id       => l_adr_accounting_coa_id
175646         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
175647         , p_flex_value_set_id       => l_adr_flex_value_set_id
175648         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
175649         , p_adr_type_code           => 'S'
175650         , p_component_type          => l_component_type
175651         , p_component_code          => l_component_code
175652         , p_component_type_code     => l_component_type_code
175653         , p_component_appl_id       => l_component_appl_id
175654         , p_amb_context_code        => l_amb_context_code
175655         , p_entity_code             => 'TRANSACTIONS'
175656         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
175657         , p_side                    => 'NA'
175658         );
175659 
175660   END IF;
175661 
175662    l_segment := AcctDerRule_168(
175663            p_application_id           => p_application_id
175664          , p_ae_header_id             => l_ae_header_id 
175665 , p_source_3 => p_source_3
175666 , p_source_29 => p_source_29
175667          , x_transaction_coa_id       => l_adr_transaction_coa_id
175668          , x_accounting_coa_id        => l_adr_accounting_coa_id
175669          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
175670          , x_flex_value_set_id        => l_adr_flex_value_set_id
175671          , x_value_type_code          => l_adr_value_type_code
175672          , x_value_combination_id     => l_adr_value_combination_id
175676    );
175673          , x_value_segment_code       => l_adr_value_segment_code
175674          , p_side                     => 'NA'
175675          , p_override_seg_flag        => 'Y'
175677 
175678    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
175679 
175680       xla_ae_lines_pkg.set_segment(
175681           p_to_segment_code         => 'GL_BALANCING'
175682         , p_segment_value           => l_segment
175683         , p_from_segment_code       => l_adr_value_segment_code
175684         , p_from_combination_id     => l_adr_value_combination_id
175685         , p_value_type_code         => l_adr_value_type_code
175686         , p_transaction_coa_id      => l_adr_transaction_coa_id
175687         , p_accounting_coa_id       => l_adr_accounting_coa_id
175688         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
175689         , p_flex_value_set_id       => l_adr_flex_value_set_id
175690         , p_adr_code                => 'FA_EXPENSE_ACCT'
175691         , p_adr_type_code           => 'S'
175692         , p_component_type          => l_component_type
175693         , p_component_code          => l_component_code
175694         , p_component_type_code     => l_component_type_code
175695         , p_component_appl_id       => l_component_appl_id
175696         , p_amb_context_code        => l_amb_context_code
175697         , p_entity_code             => 'TRANSACTIONS'
175698         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
175699         , p_side                    => 'NA'
175700         );
175701 
175702   END IF;
175703 
175704    --
175705    --
175706    END IF;
175707 
175708        --
175709        -- Update the line information that should be overwritten
175710        --
175711        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
175712                                          p_header_num   => 1);
175713        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
175714 
175715        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
175716 
175717        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
175718           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
175719        END IF;
175720 
175721       --
175722       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
175723       --
175724       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
175725           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
175726       ELSE
175727           ---------------------------------------------------------------------------------------------------
175728           -- 4262811a Switch Sign
175729           ---------------------------------------------------------------------------------------------------
175730           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
175731           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
175732                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
175733           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
175734                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
175735           -- 5132302
175736           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
175737                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
175738 
175739       END IF;
175740 
175741       -- 4955764
175742       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
175743       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
175744 
175745 
175746       XLA_AE_LINES_PKG.ValidateCurrentLine;
175747       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
175748 
175749       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
175750                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
175751                ,p_balance_type_code => l_balance_type_code);
175752 
175753    END IF;
175754 
175755    -----------------------------------------------------------------------------------------
175756    -- 4262811 Multiperiod Accounting
175757    -----------------------------------------------------------------------------------------
175758      -- No MPA option is assigned.
175759 
175760 
175761 END IF;
175762 END IF;
175763 --
175764 
175765 --
175766 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
175767    trace
175768       (p_msg      => 'END of AcctLineType_401'
175769       ,p_level    => C_LEVEL_PROCEDURE
175770       ,p_module   => l_log_module);
175771 END IF;
175772 --
175773 EXCEPTION
175774   WHEN xla_exceptions_pkg.application_exception THEN
175775       RAISE;
175776   WHEN OTHERS THEN
175777        xla_exceptions_pkg.raise_message
175778            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_401');
175779 END AcctLineType_401;
175780 --
175781 
175782 ---------------------------------------
175783 --
175784 -- PRIVATE FUNCTION
175785 --         AcctLineType_402
175786 --
175787 ---------------------------------------
175788 PROCEDURE AcctLineType_402 (
175789   p_application_id        IN NUMBER
175793  ,p_actual_flag           IN OUT VARCHAR2
175790  ,p_event_id              IN NUMBER
175791  ,p_calculate_acctd_flag  IN VARCHAR2
175792  ,p_calculate_g_l_flag    IN VARCHAR2
175794  ,p_balance_type_code     OUT VARCHAR2
175795  ,p_gain_or_loss_ref      OUT VARCHAR2
175796  
175797 --Period Close Date
175798  , p_source_1            IN DATE
175799 --Generated Code Combination Identifier
175800  , p_source_3            IN NUMBER
175801 --Expense Account Code Combination Identifier
175802  , p_source_29            IN NUMBER
175803 --Adjustment Type
175804  , p_source_35            IN VARCHAR2
175805 --Transaction Header Identifier
175806  , p_source_36            IN NUMBER
175807 --Adjustment Line Identifier
175808  , p_source_37            IN NUMBER
175809 --Distribution Type Code
175810  , p_source_38            IN VARCHAR2
175811 --Entered Amount
175812  , p_source_39            IN NUMBER
175813 --Currency Code
175814  , p_source_40            IN VARCHAR2
175815 --Source Destination Code
175816  , p_source_42            IN VARCHAR2
175817 )
175818 IS
175819 
175820 l_component_type              VARCHAR2(80);
175821 l_component_code              VARCHAR2(30);
175822 l_component_type_code         VARCHAR2(1);
175823 l_component_appl_id           INTEGER;
175824 l_amb_context_code            VARCHAR2(30);
175825 l_entity_code                 VARCHAR2(30);
175829 l_line_definition_code        VARCHAR2(30);
175826 l_event_class_code            VARCHAR2(30);
175827 l_ae_header_id                NUMBER;
175828 l_event_type_code             VARCHAR2(30);
175830 l_line_definition_owner_code  VARCHAR2(1);
175831 --
175832 -- adr variables
175833 l_segment                     VARCHAR2(30);
175834 l_ccid                        NUMBER;
175835 l_adr_transaction_coa_id      NUMBER;
175836 l_adr_accounting_coa_id       NUMBER;
175837 l_adr_flexfield_segment_code  VARCHAR2(30);
175838 l_adr_flex_value_set_id       NUMBER;
175839 l_adr_value_type_code         VARCHAR2(30);
175840 l_adr_value_combination_id    NUMBER;
175841 l_adr_value_segment_code      VARCHAR2(30);
175842 
175843 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
175844 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
175845 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
175846 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
175847 
175848 -- 4262811 Variables ------------------------------------------------------------------------------------------
175849 l_entered_amt_idx             NUMBER;
175850 l_accted_amt_idx              NUMBER;
175851 l_acc_rev_flag                VARCHAR2(1);
175852 l_accrual_line_num            NUMBER;
175853 l_tmp_amt                     NUMBER;
175854 l_acc_rev_natural_side_code   VARCHAR2(1);
175855 
175856 l_num_entries                 NUMBER;
175857 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
175858 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
175859 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
175860 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
175861 l_recog_line_1                NUMBER;
175862 l_recog_line_2                NUMBER;
175863 
175864 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
175865 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
175866 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
175867 
175868 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
175869 
175870 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
175871 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
175872 
175873 ---------------------------------------------------------------------------------------------------------------
175874 
175875 
175876 --
175877 -- bulk performance
175878 --
175879 l_balance_type_code           VARCHAR2(1);
175880 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
175881 l_log_module                  VARCHAR2(240);
175882 
175883 --
175884 -- Upgrade strategy
175885 --
175886 l_actual_upg_option           VARCHAR2(1);
175887 l_enc_upg_option           VARCHAR2(1);
175888 
175889 --
175890 BEGIN
175891 --
175892 IF g_log_enabled THEN
175893       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_402';
175894 END IF;
175895 --
175896 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
175897 
175898       trace
175899          (p_msg      => 'BEGIN of AcctLineType_402'
175900          ,p_level    => C_LEVEL_PROCEDURE
175901          ,p_module   => l_log_module);
175902 
175903 END IF;
175904 --
175905 l_component_type             := 'AMB_JLT';
175906 l_component_code             := 'FA_UNITADJ_SOURCE_EXP_BAL';
175907 l_component_type_code        := 'S';
175908 l_component_appl_id          :=  140;
175909 l_amb_context_code           := 'DEFAULT';
175910 l_entity_code                := 'TRANSACTIONS';
175911 l_event_class_code           := 'UNIT_ADJUSTMENTS';
175912 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
175913 l_line_definition_owner_code := 'S';
175914 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
175915 --
175916 l_balance_type_code          := 'A';
175917 l_segment                     := NULL;
175918 l_ccid                        := NULL;
175919 l_adr_transaction_coa_id      := NULL;
175920 l_adr_accounting_coa_id       := NULL;
175921 l_adr_flexfield_segment_code  := NULL;
175922 l_adr_flex_value_set_id       := NULL;
175923 l_adr_value_type_code         := NULL;
175924 l_adr_value_combination_id    := NULL;
175925 l_adr_value_segment_code      := NULL;
175926 
175927 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
175928 l_bflow_class_code           := '';    -- 4219869 Business Flow
175929 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
175930 l_budgetary_control_flag     := 'N';
175931 
175932 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
175933 l_bflow_applied_to_amt       := NULL; -- 5132302
175934 l_entered_amt_idx            := NULL;          -- 4262811
175935 l_accted_amt_idx             := NULL;          -- 4262811
175936 l_acc_rev_flag               := NULL;          -- 4262811
175937 l_accrual_line_num           := NULL;          -- 4262811
175938 l_tmp_amt                    := NULL;          -- 4262811
175939 --
175940  
175941 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
175942     l_balance_type_code <> 'B' THEN
175943 IF NVL(p_source_35,'
175944 ') =  'BONUS EXPENSE' AND 
175945 NVL(p_source_42,'
175946 ') =  'SOURCE'
175947  THEN 
175948 
175949    --
175953    -- set the flag so later we will know whether the gain loss line needs to be created
175950    XLA_AE_LINES_PKG.SetNewLine;
175951 
175952    p_balance_type_code          := l_balance_type_code;
175954    
175955    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
175956      p_actual_flag :='A';
175957    END IF;
175958 
175959    --
175960    -- bulk performance
175961    --
175962    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
175963                                       p_header_num   => 0); -- 4262811
175964    --
175965    -- set accounting line options
175966    --
175967    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
175968            p_natural_side_code          => 'D'
175969          , p_gain_or_loss_flag          => 'N'
175970          , p_gl_transfer_mode_code      => 'S'
175971          , p_acct_entry_type_code       => 'A'
175972          , p_switch_side_flag           => 'Y'
175973          , p_merge_duplicate_code       => 'N'
175974          );
175975    --
175976    l_acc_rev_natural_side_code := 'C';  -- 4262811
175977    -- 
175978    --
175979    -- set accounting line type info
175980    --
175981    xla_ae_lines_pkg.SetAcctLineType
175982       (p_component_type             => l_component_type
175983       ,p_event_type_code            => l_event_type_code
175984       ,p_line_definition_owner_code => l_line_definition_owner_code
175985       ,p_line_definition_code       => l_line_definition_code
175986       ,p_accounting_line_code       => l_component_code
175987       ,p_accounting_line_type_code  => l_component_type_code
175988       ,p_accounting_line_appl_id    => l_component_appl_id
175989       ,p_amb_context_code           => l_amb_context_code
175990       ,p_entity_code                => l_entity_code
175991       ,p_event_class_code           => l_event_class_code);
175992    --
175993    -- set accounting class
175994    --
175995    xla_ae_lines_pkg.SetAcctClass(
175996            p_accounting_class_code  => 'EXPENSE'
175997          , p_ae_header_id           => l_ae_header_id
175998          );
175999 
176000    --
176001    -- set rounding class
176002    --
176003    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
176004                       'EXPENSE';
176005 
176006    --
176007    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
176008    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
176009    --
176010    -- bulk performance
176011    --
176012    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
176013 
176014    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
176015       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
176016 
176017    -- 4955764
176018    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
176019       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
176020 
176021    -- 4458381 Public Sector Enh
176022    
176023    --
176024    -- set accounting attributes for the line type
176025    --
176026    l_entered_amt_idx := 4;
176027    l_accted_amt_idx  := 6;
176028    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
176029    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
176030    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
176031    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
176032    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
176033    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
176034    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
176035    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
176036    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
176037    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
176038    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
176039    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
176040    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
176041 
176042    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
176043    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
176044 
176045    ---------------------------------------------------------------------------------------------------------------
176046    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
176047    ---------------------------------------------------------------------------------------------------------------
176048    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
176049 
176050    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
176051    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
176052 
176053    IF xla_accounting_cache_pkg.GetValueChar
176054          (p_source_code         => 'LEDGER_CATEGORY_CODE'
176055          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
176056    AND l_bflow_method_code = 'PRIOR_ENTRY'
176057 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
176058    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
176059          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
176060        )
176061    THEN
176062          xla_ae_lines_pkg.BflowUpgEntry
176063            (p_business_method_code    => l_bflow_method_code
176064            ,p_business_class_code     => l_bflow_class_code
176065            ,p_balance_type            => l_balance_type_code);
176066    ELSE
176067       NULL;
176068 -- No business flow processing for business flow method of NONE.
176069    END IF;
176070 
176071    --
176072    -- call analytical criteria
176076    -- call description
176073    --
176074    
176075    --
176077    --
176078    
176079 xla_ae_lines_pkg.SetLineDescription(
176080    p_ae_header_id => l_ae_header_id
176081   ,p_description  => Description_134 (
176082      p_application_id         => p_application_id
176083    , p_ae_header_id           => l_ae_header_id 
176084 , p_source_1 => p_source_1
176085    )
176086 );
176087 
176088 
176089    --
176090    -- call ADRs
176091    -- Bug 4922099
176092    --
176093    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
176094         (NVL(l_actual_upg_option, 'N') = 'O') OR
176095         (NVL(l_enc_upg_option, 'N') = 'O')
176096       )
176097    THEN
176098    NULL;
176099    --
176100    --
176101    
176102   l_ccid := AcctDerRule_175(
176103            p_application_id           => p_application_id
176104          , p_ae_header_id             => l_ae_header_id 
176105 , p_source_3 => p_source_3
176106 , p_source_29 => p_source_29
176107          , x_transaction_coa_id       => l_adr_transaction_coa_id
176108          , x_accounting_coa_id        => l_adr_accounting_coa_id
176109          , x_value_type_code          => l_adr_value_type_code
176110          , p_side                     => 'NA'
176111    );
176112 
176113    xla_ae_lines_pkg.set_ccid(
176114     p_code_combination_id          => l_ccid
176115   , p_value_type_code              => l_adr_value_type_code
176116   , p_transaction_coa_id           => l_adr_transaction_coa_id
176117   , p_accounting_coa_id            => l_adr_accounting_coa_id
176118   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
176119   , p_adr_type_code                => 'S'
176120   , p_component_type               => l_component_type
176121   , p_component_code               => l_component_code
176122   , p_component_type_code          => l_component_type_code
176123   , p_component_appl_id            => l_component_appl_id
176124   , p_amb_context_code             => l_amb_context_code
176125   , p_side                         => 'NA'
176126   );
176127 
176128 
176129    --
176130    --
176131    END IF;
176132    --
176133    -- Bug 4922099
176134    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
176135           (NVL(l_enc_upg_option, 'N') = 'O')
176136         ) AND
176137         (l_bflow_method_code = 'PRIOR_ENTRY')
176138       )
176139    THEN
176140       IF
176141       --
176142       1 = 2
176143       --
176144       THEN
176145       xla_accounting_err_pkg.build_message
176146                                     (p_appli_s_name            => 'XLA'
176147                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
176148                                     ,p_token_1                 => 'LINE_NUMBER'
176149                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
176150                                     ,p_token_2                 => 'LINE_TYPE_NAME'
176151                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
176152                                                                              l_component_type
176153                                                                             ,l_component_code
176154                                                                             ,l_component_type_code
176155                                                                             ,l_component_appl_id
176156                                                                             ,l_amb_context_code
176157                                                                             ,l_entity_code
176158                                                                             ,l_event_class_code
176159                                                                            )
176160                                     ,p_token_3                 => 'OWNER'
176161                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
176162                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
176163                                                                           ,p_lookup_code    => l_component_type_code
176164                                                                          )
176165                                     ,p_token_4                 => 'PRODUCT_NAME'
176166                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
176167                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
176168                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
176169                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
176170                                     ,p_ae_header_id            =>  NULL
176171                                        );
176172 
176173         IF (C_LEVEL_ERROR>= g_log_level) THEN
176174                  trace
176175                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
176176                       ,p_level    => C_LEVEL_ERROR
176177                       ,p_module   => l_log_module);
176178         END IF;
176179       END IF;
176180    END IF;
176181    --
176182    --
176183    ------------------------------------------------------------------------------------------------
176184    -- 4219869 Business Flow
176185    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
176186    -- Prior Entry.  Currently, the following code is always generated.
176187    ------------------------------------------------------------------------------------------------
176188    XLA_AE_LINES_PKG.ValidateCurrentLine;
176189 
176190    ------------------------------------------------------------------------------------
176191    -- 4219869 Business Flow
176192    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
176196    ----------------------------------------------------------------------------------
176193    ------------------------------------------------------------------------------------
176194    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
176195 
176197    -- 4219869 Business Flow
176198    -- Update journal entry status -- Need to generate this within IF <condition>
176199    ----------------------------------------------------------------------------------
176200    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
176201          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
176202          ,p_balance_type_code => l_balance_type_code
176203          );
176204 
176205    -------------------------------------------------------------------------------------------
176206    -- 4262811 - Generate the Accrual Reversal lines
176207    -------------------------------------------------------------------------------------------
176208    BEGIN
176209       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
176210                               (g_array_event(p_event_id).array_value_num('header_index'));
176211       IF l_acc_rev_flag IS NULL THEN
176212          l_acc_rev_flag := 'N';
176213       END IF;
176214    EXCEPTION
176215       WHEN OTHERS THEN
176216          l_acc_rev_flag := 'N';
176217    END;
176218    --
176219    IF (l_acc_rev_flag = 'Y') THEN
176220 
176221        -- 4645092  ------------------------------------------------------------------------------
176222        -- To allow MPA report to determine if it should generate report process
176223        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
176224        ------------------------------------------------------------------------------------------
176225 
176226        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
176227        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
176228    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
176229    -- call ADRs
176230    -- Bug 4922099
176231    --
176232    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
176233         (NVL(l_actual_upg_option, 'N') = 'O') OR
176234         (NVL(l_enc_upg_option, 'N') = 'O')
176235       )
176236    THEN
176237    NULL;
176238    --
176239    --
176240    
176241   l_ccid := AcctDerRule_175(
176242            p_application_id           => p_application_id
176243          , p_ae_header_id             => l_ae_header_id 
176244 , p_source_3 => p_source_3
176245 , p_source_29 => p_source_29
176246          , x_transaction_coa_id       => l_adr_transaction_coa_id
176247          , x_accounting_coa_id        => l_adr_accounting_coa_id
176248          , x_value_type_code          => l_adr_value_type_code
176249          , p_side                     => 'NA'
176250    );
176251 
176252    xla_ae_lines_pkg.set_ccid(
176253     p_code_combination_id          => l_ccid
176254   , p_value_type_code              => l_adr_value_type_code
176255   , p_transaction_coa_id           => l_adr_transaction_coa_id
176256   , p_accounting_coa_id            => l_adr_accounting_coa_id
176257   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
176258   , p_adr_type_code                => 'S'
176259   , p_component_type               => l_component_type
176260   , p_component_code               => l_component_code
176261   , p_component_type_code          => l_component_type_code
176262   , p_component_appl_id            => l_component_appl_id
176263   , p_amb_context_code             => l_amb_context_code
176264   , p_side                         => 'NA'
176265   );
176266 
176267 
176268    --
176269    --
176270    END IF;
176271 
176272        --
176273        -- Update the line information that should be overwritten
176274        --
176275        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
176276                                          p_header_num   => 1);
176277        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
176278 
176279        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
176280 
176281        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
176282           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
176283        END IF;
176284 
176285       --
176286       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
176287       --
176288       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
176289           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
176290       ELSE
176291           ---------------------------------------------------------------------------------------------------
176292           -- 4262811a Switch Sign
176293           ---------------------------------------------------------------------------------------------------
176294           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
176295           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
176296                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
176297           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
176298                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
176299           -- 5132302
176300           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
176301                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
176302 
176303       END IF;
176304 
176305       -- 4955764
176306       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
176307       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
176308 
176309 
176313       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
176310       XLA_AE_LINES_PKG.ValidateCurrentLine;
176311       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
176312 
176314                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
176315                ,p_balance_type_code => l_balance_type_code);
176316 
176317    END IF;
176318 
176319    -----------------------------------------------------------------------------------------
176320    -- 4262811 Multiperiod Accounting
176321    -----------------------------------------------------------------------------------------
176322      -- No MPA option is assigned.
176323 
176324 
176325 END IF;
176326 END IF;
176327 --
176328 
176329 --
176330 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
176331    trace
176332       (p_msg      => 'END of AcctLineType_402'
176333       ,p_level    => C_LEVEL_PROCEDURE
176334       ,p_module   => l_log_module);
176335 END IF;
176336 --
176337 EXCEPTION
176338   WHEN xla_exceptions_pkg.application_exception THEN
176339       RAISE;
176340   WHEN OTHERS THEN
176341        xla_exceptions_pkg.raise_message
176342            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_402');
176343 END AcctLineType_402;
176344 --
176345 
176346 ---------------------------------------
176347 --
176348 -- PRIVATE FUNCTION
176349 --         AcctLineType_403
176350 --
176351 ---------------------------------------
176352 PROCEDURE AcctLineType_403 (
176353   p_application_id        IN NUMBER
176354  ,p_event_id              IN NUMBER
176355  ,p_calculate_acctd_flag  IN VARCHAR2
176356  ,p_calculate_g_l_flag    IN VARCHAR2
176357  ,p_actual_flag           IN OUT VARCHAR2
176358  ,p_balance_type_code     OUT VARCHAR2
176359  ,p_gain_or_loss_ref      OUT VARCHAR2
176360  
176361 --Period Close Date
176362  , p_source_1            IN DATE
176363 --Generated Code Combination Identifier
176364  , p_source_3            IN NUMBER
176365 --Depreciation Reserve Account
176366  , p_source_10            IN VARCHAR2
176367 --Generated Offset Code Combination Identifier
176368  , p_source_17            IN NUMBER
176369 --Expense Account Code Combination Identifier
176370  , p_source_29            IN NUMBER
176371 --Default Code Combination Identifier
176372  , p_source_30            IN NUMBER
176373 --Adjustment Type
176374  , p_source_35            IN VARCHAR2
176375 --Transaction Header Identifier
176376  , p_source_36            IN NUMBER
176377 --Adjustment Line Identifier
176378  , p_source_37            IN NUMBER
176379 --Distribution Type Code
176380  , p_source_38            IN VARCHAR2
176381 --Entered Amount
176382  , p_source_39            IN NUMBER
176383 --Currency Code
176384  , p_source_40            IN VARCHAR2
176385 --Source Destination Code
176386  , p_source_42            IN VARCHAR2
176387 )
176388 IS
176389 
176390 l_component_type              VARCHAR2(80);
176391 l_component_code              VARCHAR2(30);
176392 l_component_type_code         VARCHAR2(1);
176393 l_component_appl_id           INTEGER;
176394 l_amb_context_code            VARCHAR2(30);
176395 l_entity_code                 VARCHAR2(30);
176396 l_event_class_code            VARCHAR2(30);
176397 l_ae_header_id                NUMBER;
176398 l_event_type_code             VARCHAR2(30);
176399 l_line_definition_code        VARCHAR2(30);
176400 l_line_definition_owner_code  VARCHAR2(1);
176401 --
176402 -- adr variables
176403 l_segment                     VARCHAR2(30);
176404 l_ccid                        NUMBER;
176405 l_adr_transaction_coa_id      NUMBER;
176406 l_adr_accounting_coa_id       NUMBER;
176407 l_adr_flexfield_segment_code  VARCHAR2(30);
176408 l_adr_flex_value_set_id       NUMBER;
176409 l_adr_value_type_code         VARCHAR2(30);
176410 l_adr_value_combination_id    NUMBER;
176411 l_adr_value_segment_code      VARCHAR2(30);
176412 
176413 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
176414 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
176415 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
176416 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
176417 
176418 -- 4262811 Variables ------------------------------------------------------------------------------------------
176419 l_entered_amt_idx             NUMBER;
176420 l_accted_amt_idx              NUMBER;
176421 l_acc_rev_flag                VARCHAR2(1);
176422 l_accrual_line_num            NUMBER;
176423 l_tmp_amt                     NUMBER;
176424 l_acc_rev_natural_side_code   VARCHAR2(1);
176425 
176426 l_num_entries                 NUMBER;
176427 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
176428 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
176429 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
176430 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
176431 l_recog_line_1                NUMBER;
176432 l_recog_line_2                NUMBER;
176433 
176434 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
176435 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
176436 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
176437 
176438 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
176439 
176440 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
176441 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
176442 
176443 ---------------------------------------------------------------------------------------------------------------
176444 
176445 
176446 --
176447 -- bulk performance
176448 --
176449 l_balance_type_code           VARCHAR2(1);
176450 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
176454 -- Upgrade strategy
176451 l_log_module                  VARCHAR2(240);
176452 
176453 --
176455 --
176456 l_actual_upg_option           VARCHAR2(1);
176457 l_enc_upg_option           VARCHAR2(1);
176458 
176459 --
176460 BEGIN
176461 --
176462 IF g_log_enabled THEN
176463       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_403';
176464 END IF;
176465 --
176466 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
176467 
176468       trace
176469          (p_msg      => 'BEGIN of AcctLineType_403'
176470          ,p_level    => C_LEVEL_PROCEDURE
176471          ,p_module   => l_log_module);
176472 
176473 END IF;
176474 --
176475 l_component_type             := 'AMB_JLT';
176476 l_component_code             := 'FA_UNITADJ_SOURCE_RESERVE_BAL';
176477 l_component_type_code        := 'S';
176478 l_component_appl_id          :=  140;
176479 l_amb_context_code           := 'DEFAULT';
176480 l_entity_code                := 'TRANSACTIONS';
176481 l_event_class_code           := 'UNIT_ADJUSTMENTS';
176482 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
176483 l_line_definition_owner_code := 'S';
176484 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
176485 --
176486 l_balance_type_code          := 'A';
176487 l_segment                     := NULL;
176488 l_ccid                        := NULL;
176489 l_adr_transaction_coa_id      := NULL;
176490 l_adr_accounting_coa_id       := NULL;
176491 l_adr_flexfield_segment_code  := NULL;
176492 l_adr_flex_value_set_id       := NULL;
176493 l_adr_value_type_code         := NULL;
176494 l_adr_value_combination_id    := NULL;
176495 l_adr_value_segment_code      := NULL;
176496 
176497 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
176498 l_bflow_class_code           := '';    -- 4219869 Business Flow
176499 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
176500 l_budgetary_control_flag     := 'N';
176501 
176502 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
176503 l_bflow_applied_to_amt       := NULL; -- 5132302
176504 l_entered_amt_idx            := NULL;          -- 4262811
176505 l_accted_amt_idx             := NULL;          -- 4262811
176506 l_acc_rev_flag               := NULL;          -- 4262811
176507 l_accrual_line_num           := NULL;          -- 4262811
176508 l_tmp_amt                    := NULL;          -- 4262811
176509 --
176510  
176511 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
176512     l_balance_type_code <> 'B' THEN
176513 IF (NVL(p_source_35,'
176514 ') =  'BONUS EXPENSE' OR 
176515 NVL(p_source_35,'
176516 ') =  'BONUS RESERVE') AND 
176517 NVL(p_source_42,'
176518 ') =  'SOURCE'
176519  THEN 
176520 
176521    --
176522    XLA_AE_LINES_PKG.SetNewLine;
176523 
176524    p_balance_type_code          := l_balance_type_code;
176525    -- set the flag so later we will know whether the gain loss line needs to be created
176526    
176527    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
176528      p_actual_flag :='A';
176529    END IF;
176530 
176531    --
176532    -- bulk performance
176533    --
176534    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
176535                                       p_header_num   => 0); -- 4262811
176536    --
176537    -- set accounting line options
176538    --
176539    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
176540            p_natural_side_code          => 'C'
176541          , p_gain_or_loss_flag          => 'N'
176542          , p_gl_transfer_mode_code      => 'S'
176543          , p_acct_entry_type_code       => 'A'
176544          , p_switch_side_flag           => 'Y'
176545          , p_merge_duplicate_code       => 'N'
176546          );
176547    --
176548    l_acc_rev_natural_side_code := 'D';  -- 4262811
176549    -- 
176550    --
176551    -- set accounting line type info
176552    --
176553    xla_ae_lines_pkg.SetAcctLineType
176554       (p_component_type             => l_component_type
176555       ,p_event_type_code            => l_event_type_code
176556       ,p_line_definition_owner_code => l_line_definition_owner_code
176557       ,p_line_definition_code       => l_line_definition_code
176558       ,p_accounting_line_code       => l_component_code
176559       ,p_accounting_line_type_code  => l_component_type_code
176560       ,p_accounting_line_appl_id    => l_component_appl_id
176561       ,p_amb_context_code           => l_amb_context_code
176562       ,p_entity_code                => l_entity_code
176563       ,p_event_class_code           => l_event_class_code);
176564    --
176565    -- set accounting class
176566    --
176567    xla_ae_lines_pkg.SetAcctClass(
176568            p_accounting_class_code  => 'ASSET'
176569          , p_ae_header_id           => l_ae_header_id
176570          );
176571 
176572    --
176573    -- set rounding class
176574    --
176575    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
176576                       'ASSET';
176577 
176578    --
176579    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
176580    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
176581    --
176582    -- bulk performance
176583    --
176584    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
176585 
176586    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
176587       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
176588 
176589    -- 4955764
176590    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
176591       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
176592 
176593    -- 4458381 Public Sector Enh
176594    
176595    --
176599    l_accted_amt_idx  := 6;
176596    -- set accounting attributes for the line type
176597    --
176598    l_entered_amt_idx := 4;
176600    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
176601    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
176602    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
176603    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
176604    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
176605    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
176606    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
176607    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
176608    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
176609    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
176610    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
176611    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
176612    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
176613 
176614    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
176615    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
176616 
176617    ---------------------------------------------------------------------------------------------------------------
176618    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
176619    ---------------------------------------------------------------------------------------------------------------
176620    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
176621 
176622    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
176623    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
176624 
176625    IF xla_accounting_cache_pkg.GetValueChar
176626          (p_source_code         => 'LEDGER_CATEGORY_CODE'
176627          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
176628    AND l_bflow_method_code = 'PRIOR_ENTRY'
176629 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
176630    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
176631          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
176632        )
176633    THEN
176634          xla_ae_lines_pkg.BflowUpgEntry
176635            (p_business_method_code    => l_bflow_method_code
176636            ,p_business_class_code     => l_bflow_class_code
176637            ,p_balance_type            => l_balance_type_code);
176638    ELSE
176639       NULL;
176640 -- No business flow processing for business flow method of NONE.
176641    END IF;
176642 
176643    --
176644    -- call analytical criteria
176645    --
176646    
176647    --
176648    -- call description
176649    --
176650    
176651 xla_ae_lines_pkg.SetLineDescription(
176652    p_ae_header_id => l_ae_header_id
176653   ,p_description  => Description_137 (
176654      p_application_id         => p_application_id
176655    , p_ae_header_id           => l_ae_header_id 
176656 , p_source_1 => p_source_1
176657    )
176658 );
176659 
176660 
176661    --
176662    -- call ADRs
176663    -- Bug 4922099
176664    --
176665    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
176666         (NVL(l_actual_upg_option, 'N') = 'O') OR
176667         (NVL(l_enc_upg_option, 'N') = 'O')
176668       )
176669    THEN
176670    NULL;
176671    --
176672    --
176673    
176674   l_ccid := AcctDerRule_174(
176675            p_application_id           => p_application_id
176676          , p_ae_header_id             => l_ae_header_id 
176677 , p_source_3 => p_source_3
176678 , p_source_17 => p_source_17
176679 , p_source_30 => p_source_30
176680          , x_transaction_coa_id       => l_adr_transaction_coa_id
176681          , x_accounting_coa_id        => l_adr_accounting_coa_id
176682          , x_value_type_code          => l_adr_value_type_code
176683          , p_side                     => 'NA'
176684    );
176685 
176686    xla_ae_lines_pkg.set_ccid(
176687     p_code_combination_id          => l_ccid
176688   , p_value_type_code              => l_adr_value_type_code
176689   , p_transaction_coa_id           => l_adr_transaction_coa_id
176690   , p_accounting_coa_id            => l_adr_accounting_coa_id
176691   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
176692   , p_adr_type_code                => 'S'
176693   , p_component_type               => l_component_type
176694   , p_component_code               => l_component_code
176695   , p_component_type_code          => l_component_type_code
176696   , p_component_appl_id            => l_component_appl_id
176697   , p_amb_context_code             => l_amb_context_code
176698   , p_side                         => 'NA'
176699   );
176700 
176701 
176702    l_segment := AcctDerRule_149(
176703            p_application_id           => p_application_id
176704          , p_ae_header_id             => l_ae_header_id 
176705 , p_source_3 => p_source_3
176706 , p_source_10 => p_source_10
176707          , x_transaction_coa_id       => l_adr_transaction_coa_id
176708          , x_accounting_coa_id        => l_adr_accounting_coa_id
176709          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
176710          , x_flex_value_set_id        => l_adr_flex_value_set_id
176711          , x_value_type_code          => l_adr_value_type_code
176712          , x_value_combination_id     => l_adr_value_combination_id
176713          , x_value_segment_code       => l_adr_value_segment_code
176714          , p_side                     => 'NA'
176715          , p_override_seg_flag        => 'Y'
176716    );
176717 
176718    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
176719 
176720       xla_ae_lines_pkg.set_segment(
176721           p_to_segment_code         => 'GL_ACCOUNT'
176725         , p_value_type_code         => l_adr_value_type_code
176722         , p_segment_value           => l_segment
176723         , p_from_segment_code       => l_adr_value_segment_code
176724         , p_from_combination_id     => l_adr_value_combination_id
176726         , p_transaction_coa_id      => l_adr_transaction_coa_id
176727         , p_accounting_coa_id       => l_adr_accounting_coa_id
176728         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
176729         , p_flex_value_set_id       => l_adr_flex_value_set_id
176730         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
176731         , p_adr_type_code           => 'S'
176732         , p_component_type          => l_component_type
176733         , p_component_code          => l_component_code
176734         , p_component_type_code     => l_component_type_code
176735         , p_component_appl_id       => l_component_appl_id
176736         , p_amb_context_code        => l_amb_context_code
176737         , p_entity_code             => 'TRANSACTIONS'
176738         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
176739         , p_side                    => 'NA'
176740         );
176741 
176742   END IF;
176743 
176744    l_segment := AcctDerRule_168(
176745            p_application_id           => p_application_id
176746          , p_ae_header_id             => l_ae_header_id 
176747 , p_source_3 => p_source_3
176748 , p_source_29 => p_source_29
176749          , x_transaction_coa_id       => l_adr_transaction_coa_id
176750          , x_accounting_coa_id        => l_adr_accounting_coa_id
176751          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
176752          , x_flex_value_set_id        => l_adr_flex_value_set_id
176753          , x_value_type_code          => l_adr_value_type_code
176754          , x_value_combination_id     => l_adr_value_combination_id
176755          , x_value_segment_code       => l_adr_value_segment_code
176756          , p_side                     => 'NA'
176757          , p_override_seg_flag        => 'Y'
176758    );
176759 
176760    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
176761 
176762       xla_ae_lines_pkg.set_segment(
176763           p_to_segment_code         => 'GL_BALANCING'
176764         , p_segment_value           => l_segment
176765         , p_from_segment_code       => l_adr_value_segment_code
176766         , p_from_combination_id     => l_adr_value_combination_id
176767         , p_value_type_code         => l_adr_value_type_code
176768         , p_transaction_coa_id      => l_adr_transaction_coa_id
176769         , p_accounting_coa_id       => l_adr_accounting_coa_id
176770         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
176771         , p_flex_value_set_id       => l_adr_flex_value_set_id
176772         , p_adr_code                => 'FA_EXPENSE_ACCT'
176773         , p_adr_type_code           => 'S'
176774         , p_component_type          => l_component_type
176775         , p_component_code          => l_component_code
176776         , p_component_type_code     => l_component_type_code
176777         , p_component_appl_id       => l_component_appl_id
176778         , p_amb_context_code        => l_amb_context_code
176779         , p_entity_code             => 'TRANSACTIONS'
176780         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
176781         , p_side                    => 'NA'
176782         );
176783 
176784   END IF;
176785 
176786    --
176787    --
176788    END IF;
176789    --
176790    -- Bug 4922099
176791    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
176792           (NVL(l_enc_upg_option, 'N') = 'O')
176793         ) AND
176794         (l_bflow_method_code = 'PRIOR_ENTRY')
176795       )
176796    THEN
176797       IF
176798       --
176799       1 = 2
176800       --
176801       THEN
176802       xla_accounting_err_pkg.build_message
176803                                     (p_appli_s_name            => 'XLA'
176804                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
176805                                     ,p_token_1                 => 'LINE_NUMBER'
176806                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
176807                                     ,p_token_2                 => 'LINE_TYPE_NAME'
176808                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
176809                                                                              l_component_type
176810                                                                             ,l_component_code
176811                                                                             ,l_component_type_code
176812                                                                             ,l_component_appl_id
176813                                                                             ,l_amb_context_code
176814                                                                             ,l_entity_code
176815                                                                             ,l_event_class_code
176816                                                                            )
176817                                     ,p_token_3                 => 'OWNER'
176818                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
176819                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
176820                                                                           ,p_lookup_code    => l_component_type_code
176821                                                                          )
176822                                     ,p_token_4                 => 'PRODUCT_NAME'
176823                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
176824                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
176825                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
176829 
176826                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
176827                                     ,p_ae_header_id            =>  NULL
176828                                        );
176830         IF (C_LEVEL_ERROR>= g_log_level) THEN
176831                  trace
176832                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
176833                       ,p_level    => C_LEVEL_ERROR
176834                       ,p_module   => l_log_module);
176835         END IF;
176836       END IF;
176837    END IF;
176838    --
176839    --
176840    ------------------------------------------------------------------------------------------------
176841    -- 4219869 Business Flow
176842    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
176843    -- Prior Entry.  Currently, the following code is always generated.
176844    ------------------------------------------------------------------------------------------------
176845    XLA_AE_LINES_PKG.ValidateCurrentLine;
176846 
176847    ------------------------------------------------------------------------------------
176848    -- 4219869 Business Flow
176849    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
176850    ------------------------------------------------------------------------------------
176851    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
176852 
176853    ----------------------------------------------------------------------------------
176854    -- 4219869 Business Flow
176855    -- Update journal entry status -- Need to generate this within IF <condition>
176856    ----------------------------------------------------------------------------------
176857    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
176858          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
176859          ,p_balance_type_code => l_balance_type_code
176860          );
176861 
176862    -------------------------------------------------------------------------------------------
176863    -- 4262811 - Generate the Accrual Reversal lines
176864    -------------------------------------------------------------------------------------------
176865    BEGIN
176866       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
176867                               (g_array_event(p_event_id).array_value_num('header_index'));
176868       IF l_acc_rev_flag IS NULL THEN
176869          l_acc_rev_flag := 'N';
176870       END IF;
176871    EXCEPTION
176872       WHEN OTHERS THEN
176873          l_acc_rev_flag := 'N';
176874    END;
176875    --
176876    IF (l_acc_rev_flag = 'Y') THEN
176877 
176878        -- 4645092  ------------------------------------------------------------------------------
176879        -- To allow MPA report to determine if it should generate report process
176880        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
176881        ------------------------------------------------------------------------------------------
176882 
176883        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
176884        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
176885    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
176886    -- call ADRs
176887    -- Bug 4922099
176888    --
176889    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
176890         (NVL(l_actual_upg_option, 'N') = 'O') OR
176891         (NVL(l_enc_upg_option, 'N') = 'O')
176892       )
176893    THEN
176894    NULL;
176895    --
176896    --
176897    
176898   l_ccid := AcctDerRule_174(
176899            p_application_id           => p_application_id
176900          , p_ae_header_id             => l_ae_header_id 
176901 , p_source_3 => p_source_3
176902 , p_source_17 => p_source_17
176903 , p_source_30 => p_source_30
176904          , x_transaction_coa_id       => l_adr_transaction_coa_id
176905          , x_accounting_coa_id        => l_adr_accounting_coa_id
176906          , x_value_type_code          => l_adr_value_type_code
176907          , p_side                     => 'NA'
176908    );
176909 
176910    xla_ae_lines_pkg.set_ccid(
176911     p_code_combination_id          => l_ccid
176912   , p_value_type_code              => l_adr_value_type_code
176913   , p_transaction_coa_id           => l_adr_transaction_coa_id
176914   , p_accounting_coa_id            => l_adr_accounting_coa_id
176915   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
176916   , p_adr_type_code                => 'S'
176917   , p_component_type               => l_component_type
176918   , p_component_code               => l_component_code
176919   , p_component_type_code          => l_component_type_code
176920   , p_component_appl_id            => l_component_appl_id
176921   , p_amb_context_code             => l_amb_context_code
176922   , p_side                         => 'NA'
176923   );
176924 
176925 
176926    l_segment := AcctDerRule_149(
176927            p_application_id           => p_application_id
176928          , p_ae_header_id             => l_ae_header_id 
176929 , p_source_3 => p_source_3
176930 , p_source_10 => p_source_10
176931          , x_transaction_coa_id       => l_adr_transaction_coa_id
176932          , x_accounting_coa_id        => l_adr_accounting_coa_id
176933          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
176934          , x_flex_value_set_id        => l_adr_flex_value_set_id
176935          , x_value_type_code          => l_adr_value_type_code
176936          , x_value_combination_id     => l_adr_value_combination_id
176937          , x_value_segment_code       => l_adr_value_segment_code
176938          , p_side                     => 'NA'
176939          , p_override_seg_flag        => 'Y'
176940    );
176941 
176942    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
176943 
176944       xla_ae_lines_pkg.set_segment(
176945           p_to_segment_code         => 'GL_ACCOUNT'
176946         , p_segment_value           => l_segment
176950         , p_transaction_coa_id      => l_adr_transaction_coa_id
176947         , p_from_segment_code       => l_adr_value_segment_code
176948         , p_from_combination_id     => l_adr_value_combination_id
176949         , p_value_type_code         => l_adr_value_type_code
176951         , p_accounting_coa_id       => l_adr_accounting_coa_id
176952         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
176953         , p_flex_value_set_id       => l_adr_flex_value_set_id
176954         , p_adr_code                => 'FA_CAT_RES_ACCOUNT_SEGMENT'
176955         , p_adr_type_code           => 'S'
176956         , p_component_type          => l_component_type
176957         , p_component_code          => l_component_code
176958         , p_component_type_code     => l_component_type_code
176959         , p_component_appl_id       => l_component_appl_id
176960         , p_amb_context_code        => l_amb_context_code
176961         , p_entity_code             => 'TRANSACTIONS'
176962         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
176963         , p_side                    => 'NA'
176964         );
176965 
176966   END IF;
176967 
176968    l_segment := AcctDerRule_168(
176969            p_application_id           => p_application_id
176970          , p_ae_header_id             => l_ae_header_id 
176971 , p_source_3 => p_source_3
176972 , p_source_29 => p_source_29
176973          , x_transaction_coa_id       => l_adr_transaction_coa_id
176974          , x_accounting_coa_id        => l_adr_accounting_coa_id
176975          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
176976          , x_flex_value_set_id        => l_adr_flex_value_set_id
176977          , x_value_type_code          => l_adr_value_type_code
176978          , x_value_combination_id     => l_adr_value_combination_id
176979          , x_value_segment_code       => l_adr_value_segment_code
176980          , p_side                     => 'NA'
176981          , p_override_seg_flag        => 'Y'
176982    );
176983 
176984    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
176985 
176986       xla_ae_lines_pkg.set_segment(
176987           p_to_segment_code         => 'GL_BALANCING'
176988         , p_segment_value           => l_segment
176989         , p_from_segment_code       => l_adr_value_segment_code
176990         , p_from_combination_id     => l_adr_value_combination_id
176991         , p_value_type_code         => l_adr_value_type_code
176992         , p_transaction_coa_id      => l_adr_transaction_coa_id
176993         , p_accounting_coa_id       => l_adr_accounting_coa_id
176994         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
176995         , p_flex_value_set_id       => l_adr_flex_value_set_id
176996         , p_adr_code                => 'FA_EXPENSE_ACCT'
176997         , p_adr_type_code           => 'S'
176998         , p_component_type          => l_component_type
176999         , p_component_code          => l_component_code
177000         , p_component_type_code     => l_component_type_code
177001         , p_component_appl_id       => l_component_appl_id
177002         , p_amb_context_code        => l_amb_context_code
177003         , p_entity_code             => 'TRANSACTIONS'
177004         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
177005         , p_side                    => 'NA'
177006         );
177007 
177008   END IF;
177009 
177010    --
177011    --
177012    END IF;
177013 
177014        --
177015        -- Update the line information that should be overwritten
177016        --
177017        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
177018                                          p_header_num   => 1);
177019        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
177020 
177021        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
177022 
177023        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
177024           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
177025        END IF;
177026 
177027       --
177028       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
177029       --
177030       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
177031           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
177032       ELSE
177033           ---------------------------------------------------------------------------------------------------
177034           -- 4262811a Switch Sign
177035           ---------------------------------------------------------------------------------------------------
177036           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
177037           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
177038                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
177039           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
177040                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
177041           -- 5132302
177042           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
177043                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
177044 
177045       END IF;
177046 
177047       -- 4955764
177048       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
177049       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
177050 
177051 
177052       XLA_AE_LINES_PKG.ValidateCurrentLine;
177053       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
177054 
177055       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
177056                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
177060 
177057                ,p_balance_type_code => l_balance_type_code);
177058 
177059    END IF;
177061    -----------------------------------------------------------------------------------------
177062    -- 4262811 Multiperiod Accounting
177063    -----------------------------------------------------------------------------------------
177064      -- No MPA option is assigned.
177065 
177066 
177067 END IF;
177068 END IF;
177069 --
177070 
177071 --
177072 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
177073    trace
177074       (p_msg      => 'END of AcctLineType_403'
177075       ,p_level    => C_LEVEL_PROCEDURE
177076       ,p_module   => l_log_module);
177077 END IF;
177078 --
177079 EXCEPTION
177080   WHEN xla_exceptions_pkg.application_exception THEN
177081       RAISE;
177082   WHEN OTHERS THEN
177083        xla_exceptions_pkg.raise_message
177084            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_403');
177085 END AcctLineType_403;
177086 --
177087 
177088 ---------------------------------------
177089 --
177090 -- PRIVATE FUNCTION
177091 --         AcctLineType_404
177092 --
177093 ---------------------------------------
177094 PROCEDURE AcctLineType_404 (
177095   p_application_id        IN NUMBER
177096  ,p_event_id              IN NUMBER
177097  ,p_calculate_acctd_flag  IN VARCHAR2
177098  ,p_calculate_g_l_flag    IN VARCHAR2
177099  ,p_actual_flag           IN OUT VARCHAR2
177100  ,p_balance_type_code     OUT VARCHAR2
177101  ,p_gain_or_loss_ref      OUT VARCHAR2
177102  
177103 --Period Close Date
177104  , p_source_1            IN DATE
177105 --Generated Code Combination Identifier
177106  , p_source_3            IN NUMBER
177107 --Revaluation Reserve Account
177108  , p_source_11            IN VARCHAR2
177109 --Generated Offset Code Combination Identifier
177110  , p_source_17            IN NUMBER
177111 --Expense Account Code Combination Identifier
177112  , p_source_29            IN NUMBER
177113 --Default Code Combination Identifier
177114  , p_source_30            IN NUMBER
177115 --Adjustment Type
177116  , p_source_35            IN VARCHAR2
177117 --Transaction Header Identifier
177118  , p_source_36            IN NUMBER
177119 --Adjustment Line Identifier
177120  , p_source_37            IN NUMBER
177121 --Distribution Type Code
177122  , p_source_38            IN VARCHAR2
177123 --Entered Amount
177124  , p_source_39            IN NUMBER
177125 --Currency Code
177126  , p_source_40            IN VARCHAR2
177127 --Source Destination Code
177128  , p_source_42            IN VARCHAR2
177129 )
177130 IS
177131 
177132 l_component_type              VARCHAR2(80);
177133 l_component_code              VARCHAR2(30);
177134 l_component_type_code         VARCHAR2(1);
177135 l_component_appl_id           INTEGER;
177136 l_amb_context_code            VARCHAR2(30);
177137 l_entity_code                 VARCHAR2(30);
177138 l_event_class_code            VARCHAR2(30);
177139 l_ae_header_id                NUMBER;
177140 l_event_type_code             VARCHAR2(30);
177141 l_line_definition_code        VARCHAR2(30);
177142 l_line_definition_owner_code  VARCHAR2(1);
177143 --
177144 -- adr variables
177145 l_segment                     VARCHAR2(30);
177146 l_ccid                        NUMBER;
177147 l_adr_transaction_coa_id      NUMBER;
177148 l_adr_accounting_coa_id       NUMBER;
177149 l_adr_flexfield_segment_code  VARCHAR2(30);
177150 l_adr_flex_value_set_id       NUMBER;
177151 l_adr_value_type_code         VARCHAR2(30);
177152 l_adr_value_combination_id    NUMBER;
177153 l_adr_value_segment_code      VARCHAR2(30);
177154 
177155 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
177156 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
177157 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
177158 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
177159 
177160 -- 4262811 Variables ------------------------------------------------------------------------------------------
177161 l_entered_amt_idx             NUMBER;
177162 l_accted_amt_idx              NUMBER;
177163 l_acc_rev_flag                VARCHAR2(1);
177164 l_accrual_line_num            NUMBER;
177165 l_tmp_amt                     NUMBER;
177166 l_acc_rev_natural_side_code   VARCHAR2(1);
177167 
177168 l_num_entries                 NUMBER;
177169 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
177170 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
177171 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
177172 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
177173 l_recog_line_1                NUMBER;
177174 l_recog_line_2                NUMBER;
177175 
177176 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
177177 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
177178 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
177179 
177180 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
177181 
177182 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
177183 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
177184 
177185 ---------------------------------------------------------------------------------------------------------------
177186 
177187 
177188 --
177189 -- bulk performance
177190 --
177191 l_balance_type_code           VARCHAR2(1);
177192 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
177193 l_log_module                  VARCHAR2(240);
177194 
177195 --
177196 -- Upgrade strategy
177197 --
177198 l_actual_upg_option           VARCHAR2(1);
177199 l_enc_upg_option           VARCHAR2(1);
177200 
177201 --
177202 BEGIN
177203 --
177204 IF g_log_enabled THEN
177208 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
177205       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_404';
177206 END IF;
177207 --
177209 
177210       trace
177211          (p_msg      => 'BEGIN of AcctLineType_404'
177212          ,p_level    => C_LEVEL_PROCEDURE
177213          ,p_module   => l_log_module);
177214 
177215 END IF;
177216 --
177217 l_component_type             := 'AMB_JLT';
177218 l_component_code             := 'FA_UNITADJ_SOURCE_REVAL_RESERV';
177219 l_component_type_code        := 'S';
177220 l_component_appl_id          :=  140;
177221 l_amb_context_code           := 'DEFAULT';
177222 l_entity_code                := 'TRANSACTIONS';
177223 l_event_class_code           := 'UNIT_ADJUSTMENTS';
177224 l_event_type_code            := 'UNIT_ADJUSTMENTS_ALL';
177225 l_line_definition_owner_code := 'S';
177226 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNIT_26';
177227 --
177228 l_balance_type_code          := 'A';
177229 l_segment                     := NULL;
177230 l_ccid                        := NULL;
177231 l_adr_transaction_coa_id      := NULL;
177232 l_adr_accounting_coa_id       := NULL;
177233 l_adr_flexfield_segment_code  := NULL;
177234 l_adr_flex_value_set_id       := NULL;
177235 l_adr_value_type_code         := NULL;
177236 l_adr_value_combination_id    := NULL;
177237 l_adr_value_segment_code      := NULL;
177238 
177239 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
177240 l_bflow_class_code           := '';    -- 4219869 Business Flow
177241 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
177242 l_budgetary_control_flag     := 'N';
177243 
177244 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
177245 l_bflow_applied_to_amt       := NULL; -- 5132302
177246 l_entered_amt_idx            := NULL;          -- 4262811
177247 l_accted_amt_idx             := NULL;          -- 4262811
177248 l_acc_rev_flag               := NULL;          -- 4262811
177249 l_accrual_line_num           := NULL;          -- 4262811
177250 l_tmp_amt                    := NULL;          -- 4262811
177251 --
177252  
177253 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
177254     l_balance_type_code <> 'B' THEN
177255 IF NVL(p_source_35,'
177256 ') =  'REVAL RESERVE' AND 
177257 NVL(p_source_42,'
177258 ') =  'SOURCE'
177259  THEN 
177260 
177261    --
177262    XLA_AE_LINES_PKG.SetNewLine;
177263 
177264    p_balance_type_code          := l_balance_type_code;
177265    -- set the flag so later we will know whether the gain loss line needs to be created
177266    
177267    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
177268      p_actual_flag :='A';
177269    END IF;
177270 
177271    --
177272    -- bulk performance
177273    --
177274    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
177275                                       p_header_num   => 0); -- 4262811
177276    --
177277    -- set accounting line options
177278    --
177279    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
177280            p_natural_side_code          => 'D'
177281          , p_gain_or_loss_flag          => 'N'
177282          , p_gl_transfer_mode_code      => 'S'
177283          , p_acct_entry_type_code       => 'A'
177284          , p_switch_side_flag           => 'Y'
177285          , p_merge_duplicate_code       => 'N'
177286          );
177287    --
177288    l_acc_rev_natural_side_code := 'C';  -- 4262811
177289    -- 
177290    --
177291    -- set accounting line type info
177292    --
177293    xla_ae_lines_pkg.SetAcctLineType
177294       (p_component_type             => l_component_type
177295       ,p_event_type_code            => l_event_type_code
177296       ,p_line_definition_owner_code => l_line_definition_owner_code
177297       ,p_line_definition_code       => l_line_definition_code
177298       ,p_accounting_line_code       => l_component_code
177299       ,p_accounting_line_type_code  => l_component_type_code
177300       ,p_accounting_line_appl_id    => l_component_appl_id
177301       ,p_amb_context_code           => l_amb_context_code
177302       ,p_entity_code                => l_entity_code
177303       ,p_event_class_code           => l_event_class_code);
177304    --
177305    -- set accounting class
177306    --
177307    xla_ae_lines_pkg.SetAcctClass(
177308            p_accounting_class_code  => 'ASSET'
177309          , p_ae_header_id           => l_ae_header_id
177310          );
177311 
177312    --
177313    -- set rounding class
177314    --
177315    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
177316                       'ASSET';
177317 
177318    --
177319    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
177320    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
177321    --
177322    -- bulk performance
177323    --
177324    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
177325 
177326    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
177327       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
177328 
177329    -- 4955764
177330    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
177331       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
177332 
177333    -- 4458381 Public Sector Enh
177334    
177335    --
177336    -- set accounting attributes for the line type
177337    --
177338    l_entered_amt_idx := 4;
177339    l_accted_amt_idx  := 6;
177340    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
177341    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
177342    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
177346    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
177343    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
177344    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
177345    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
177347    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
177348    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
177349    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
177350    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
177351    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
177352    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
177353 
177354    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
177355    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
177356 
177357    ---------------------------------------------------------------------------------------------------------------
177358    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
177359    ---------------------------------------------------------------------------------------------------------------
177360    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
177361 
177362    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
177363    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
177364 
177365    IF xla_accounting_cache_pkg.GetValueChar
177366          (p_source_code         => 'LEDGER_CATEGORY_CODE'
177367          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
177368    AND l_bflow_method_code = 'PRIOR_ENTRY'
177369 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
177370    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
177371          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
177372        )
177373    THEN
177374          xla_ae_lines_pkg.BflowUpgEntry
177375            (p_business_method_code    => l_bflow_method_code
177376            ,p_business_class_code     => l_bflow_class_code
177377            ,p_balance_type            => l_balance_type_code);
177378    ELSE
177379       NULL;
177380 -- No business flow processing for business flow method of NONE.
177381    END IF;
177382 
177383    --
177384    -- call analytical criteria
177385    --
177386    
177387    --
177388    -- call description
177389    --
177390    
177391 xla_ae_lines_pkg.SetLineDescription(
177392    p_ae_header_id => l_ae_header_id
177393   ,p_description  => Description_138 (
177394      p_application_id         => p_application_id
177395    , p_ae_header_id           => l_ae_header_id 
177396 , p_source_1 => p_source_1
177397    )
177398 );
177399 
177400 
177401    --
177402    -- call ADRs
177403    -- Bug 4922099
177404    --
177405    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
177406         (NVL(l_actual_upg_option, 'N') = 'O') OR
177407         (NVL(l_enc_upg_option, 'N') = 'O')
177408       )
177409    THEN
177410    NULL;
177411    --
177412    --
177413    
177414   l_ccid := AcctDerRule_174(
177415            p_application_id           => p_application_id
177416          , p_ae_header_id             => l_ae_header_id 
177417 , p_source_3 => p_source_3
177418 , p_source_17 => p_source_17
177419 , p_source_30 => p_source_30
177420          , x_transaction_coa_id       => l_adr_transaction_coa_id
177421          , x_accounting_coa_id        => l_adr_accounting_coa_id
177422          , x_value_type_code          => l_adr_value_type_code
177423          , p_side                     => 'NA'
177424    );
177425 
177426    xla_ae_lines_pkg.set_ccid(
177427     p_code_combination_id          => l_ccid
177428   , p_value_type_code              => l_adr_value_type_code
177429   , p_transaction_coa_id           => l_adr_transaction_coa_id
177430   , p_accounting_coa_id            => l_adr_accounting_coa_id
177431   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
177432   , p_adr_type_code                => 'S'
177433   , p_component_type               => l_component_type
177434   , p_component_code               => l_component_code
177435   , p_component_type_code          => l_component_type_code
177436   , p_component_appl_id            => l_component_appl_id
177437   , p_amb_context_code             => l_amb_context_code
177438   , p_side                         => 'NA'
177439   );
177440 
177441 
177442    l_segment := AcctDerRule_150(
177443            p_application_id           => p_application_id
177444          , p_ae_header_id             => l_ae_header_id 
177445 , p_source_3 => p_source_3
177446 , p_source_11 => p_source_11
177447          , x_transaction_coa_id       => l_adr_transaction_coa_id
177448          , x_accounting_coa_id        => l_adr_accounting_coa_id
177449          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
177450          , x_flex_value_set_id        => l_adr_flex_value_set_id
177451          , x_value_type_code          => l_adr_value_type_code
177452          , x_value_combination_id     => l_adr_value_combination_id
177453          , x_value_segment_code       => l_adr_value_segment_code
177454          , p_side                     => 'NA'
177455          , p_override_seg_flag        => 'Y'
177456    );
177457 
177458    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
177459 
177460       xla_ae_lines_pkg.set_segment(
177461           p_to_segment_code         => 'GL_ACCOUNT'
177462         , p_segment_value           => l_segment
177463         , p_from_segment_code       => l_adr_value_segment_code
177464         , p_from_combination_id     => l_adr_value_combination_id
177465         , p_value_type_code         => l_adr_value_type_code
177466         , p_transaction_coa_id      => l_adr_transaction_coa_id
177467         , p_accounting_coa_id       => l_adr_accounting_coa_id
177471         , p_adr_type_code           => 'S'
177468         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
177469         , p_flex_value_set_id       => l_adr_flex_value_set_id
177470         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
177472         , p_component_type          => l_component_type
177473         , p_component_code          => l_component_code
177474         , p_component_type_code     => l_component_type_code
177475         , p_component_appl_id       => l_component_appl_id
177476         , p_amb_context_code        => l_amb_context_code
177477         , p_entity_code             => 'TRANSACTIONS'
177478         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
177479         , p_side                    => 'NA'
177480         );
177481 
177482   END IF;
177483 
177484    l_segment := AcctDerRule_168(
177485            p_application_id           => p_application_id
177486          , p_ae_header_id             => l_ae_header_id 
177487 , p_source_3 => p_source_3
177488 , p_source_29 => p_source_29
177489          , x_transaction_coa_id       => l_adr_transaction_coa_id
177490          , x_accounting_coa_id        => l_adr_accounting_coa_id
177491          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
177492          , x_flex_value_set_id        => l_adr_flex_value_set_id
177493          , x_value_type_code          => l_adr_value_type_code
177494          , x_value_combination_id     => l_adr_value_combination_id
177495          , x_value_segment_code       => l_adr_value_segment_code
177496          , p_side                     => 'NA'
177497          , p_override_seg_flag        => 'Y'
177498    );
177499 
177500    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
177501 
177502       xla_ae_lines_pkg.set_segment(
177503           p_to_segment_code         => 'GL_BALANCING'
177504         , p_segment_value           => l_segment
177505         , p_from_segment_code       => l_adr_value_segment_code
177506         , p_from_combination_id     => l_adr_value_combination_id
177507         , p_value_type_code         => l_adr_value_type_code
177508         , p_transaction_coa_id      => l_adr_transaction_coa_id
177509         , p_accounting_coa_id       => l_adr_accounting_coa_id
177510         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
177511         , p_flex_value_set_id       => l_adr_flex_value_set_id
177512         , p_adr_code                => 'FA_EXPENSE_ACCT'
177513         , p_adr_type_code           => 'S'
177514         , p_component_type          => l_component_type
177515         , p_component_code          => l_component_code
177516         , p_component_type_code     => l_component_type_code
177517         , p_component_appl_id       => l_component_appl_id
177518         , p_amb_context_code        => l_amb_context_code
177519         , p_entity_code             => 'TRANSACTIONS'
177520         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
177521         , p_side                    => 'NA'
177522         );
177523 
177524   END IF;
177525 
177526    --
177527    --
177528    END IF;
177529    --
177530    -- Bug 4922099
177531    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
177532           (NVL(l_enc_upg_option, 'N') = 'O')
177533         ) AND
177534         (l_bflow_method_code = 'PRIOR_ENTRY')
177535       )
177536    THEN
177537       IF
177538       --
177539       1 = 2
177540       --
177541       THEN
177542       xla_accounting_err_pkg.build_message
177543                                     (p_appli_s_name            => 'XLA'
177544                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
177545                                     ,p_token_1                 => 'LINE_NUMBER'
177546                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
177547                                     ,p_token_2                 => 'LINE_TYPE_NAME'
177548                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
177549                                                                              l_component_type
177550                                                                             ,l_component_code
177551                                                                             ,l_component_type_code
177552                                                                             ,l_component_appl_id
177553                                                                             ,l_amb_context_code
177554                                                                             ,l_entity_code
177555                                                                             ,l_event_class_code
177556                                                                            )
177557                                     ,p_token_3                 => 'OWNER'
177558                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
177559                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
177560                                                                           ,p_lookup_code    => l_component_type_code
177561                                                                          )
177562                                     ,p_token_4                 => 'PRODUCT_NAME'
177563                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
177564                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
177565                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
177566                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
177567                                     ,p_ae_header_id            =>  NULL
177568                                        );
177569 
177570         IF (C_LEVEL_ERROR>= g_log_level) THEN
177571                  trace
177572                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
177576       END IF;
177573                       ,p_level    => C_LEVEL_ERROR
177574                       ,p_module   => l_log_module);
177575         END IF;
177577    END IF;
177578    --
177579    --
177580    ------------------------------------------------------------------------------------------------
177581    -- 4219869 Business Flow
177582    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
177583    -- Prior Entry.  Currently, the following code is always generated.
177584    ------------------------------------------------------------------------------------------------
177585    XLA_AE_LINES_PKG.ValidateCurrentLine;
177586 
177587    ------------------------------------------------------------------------------------
177588    -- 4219869 Business Flow
177589    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
177590    ------------------------------------------------------------------------------------
177591    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
177592 
177593    ----------------------------------------------------------------------------------
177594    -- 4219869 Business Flow
177595    -- Update journal entry status -- Need to generate this within IF <condition>
177596    ----------------------------------------------------------------------------------
177597    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
177598          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
177599          ,p_balance_type_code => l_balance_type_code
177600          );
177601 
177602    -------------------------------------------------------------------------------------------
177603    -- 4262811 - Generate the Accrual Reversal lines
177604    -------------------------------------------------------------------------------------------
177605    BEGIN
177606       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
177607                               (g_array_event(p_event_id).array_value_num('header_index'));
177608       IF l_acc_rev_flag IS NULL THEN
177609          l_acc_rev_flag := 'N';
177610       END IF;
177611    EXCEPTION
177612       WHEN OTHERS THEN
177613          l_acc_rev_flag := 'N';
177614    END;
177615    --
177616    IF (l_acc_rev_flag = 'Y') THEN
177617 
177618        -- 4645092  ------------------------------------------------------------------------------
177619        -- To allow MPA report to determine if it should generate report process
177620        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
177621        ------------------------------------------------------------------------------------------
177622 
177623        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
177624        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
177625    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
177626    -- call ADRs
177627    -- Bug 4922099
177628    --
177629    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
177630         (NVL(l_actual_upg_option, 'N') = 'O') OR
177631         (NVL(l_enc_upg_option, 'N') = 'O')
177632       )
177633    THEN
177634    NULL;
177635    --
177636    --
177637    
177638   l_ccid := AcctDerRule_174(
177639            p_application_id           => p_application_id
177640          , p_ae_header_id             => l_ae_header_id 
177641 , p_source_3 => p_source_3
177642 , p_source_17 => p_source_17
177643 , p_source_30 => p_source_30
177644          , x_transaction_coa_id       => l_adr_transaction_coa_id
177645          , x_accounting_coa_id        => l_adr_accounting_coa_id
177646          , x_value_type_code          => l_adr_value_type_code
177647          , p_side                     => 'NA'
177648    );
177649 
177650    xla_ae_lines_pkg.set_ccid(
177651     p_code_combination_id          => l_ccid
177652   , p_value_type_code              => l_adr_value_type_code
177653   , p_transaction_coa_id           => l_adr_transaction_coa_id
177654   , p_accounting_coa_id            => l_adr_accounting_coa_id
177655   , p_adr_code                     => 'FA_DEFAULT_OFFSET_ACCOUNT'
177656   , p_adr_type_code                => 'S'
177657   , p_component_type               => l_component_type
177658   , p_component_code               => l_component_code
177659   , p_component_type_code          => l_component_type_code
177660   , p_component_appl_id            => l_component_appl_id
177661   , p_amb_context_code             => l_amb_context_code
177662   , p_side                         => 'NA'
177663   );
177664 
177665 
177666    l_segment := AcctDerRule_150(
177667            p_application_id           => p_application_id
177668          , p_ae_header_id             => l_ae_header_id 
177669 , p_source_3 => p_source_3
177670 , p_source_11 => p_source_11
177671          , x_transaction_coa_id       => l_adr_transaction_coa_id
177672          , x_accounting_coa_id        => l_adr_accounting_coa_id
177673          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
177674          , x_flex_value_set_id        => l_adr_flex_value_set_id
177675          , x_value_type_code          => l_adr_value_type_code
177676          , x_value_combination_id     => l_adr_value_combination_id
177677          , x_value_segment_code       => l_adr_value_segment_code
177678          , p_side                     => 'NA'
177679          , p_override_seg_flag        => 'Y'
177680    );
177681 
177682    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
177683 
177684       xla_ae_lines_pkg.set_segment(
177685           p_to_segment_code         => 'GL_ACCOUNT'
177686         , p_segment_value           => l_segment
177687         , p_from_segment_code       => l_adr_value_segment_code
177688         , p_from_combination_id     => l_adr_value_combination_id
177689         , p_value_type_code         => l_adr_value_type_code
177690         , p_transaction_coa_id      => l_adr_transaction_coa_id
177691         , p_accounting_coa_id       => l_adr_accounting_coa_id
177692         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
177696         , p_component_type          => l_component_type
177693         , p_flex_value_set_id       => l_adr_flex_value_set_id
177694         , p_adr_code                => 'FA_CAT_REVAL_RES_SEGMENT'
177695         , p_adr_type_code           => 'S'
177697         , p_component_code          => l_component_code
177698         , p_component_type_code     => l_component_type_code
177699         , p_component_appl_id       => l_component_appl_id
177700         , p_amb_context_code        => l_amb_context_code
177701         , p_entity_code             => 'TRANSACTIONS'
177702         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
177703         , p_side                    => 'NA'
177704         );
177705 
177706   END IF;
177707 
177708    l_segment := AcctDerRule_168(
177709            p_application_id           => p_application_id
177710          , p_ae_header_id             => l_ae_header_id 
177711 , p_source_3 => p_source_3
177712 , p_source_29 => p_source_29
177713          , x_transaction_coa_id       => l_adr_transaction_coa_id
177714          , x_accounting_coa_id        => l_adr_accounting_coa_id
177715          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
177716          , x_flex_value_set_id        => l_adr_flex_value_set_id
177717          , x_value_type_code          => l_adr_value_type_code
177718          , x_value_combination_id     => l_adr_value_combination_id
177719          , x_value_segment_code       => l_adr_value_segment_code
177720          , p_side                     => 'NA'
177721          , p_override_seg_flag        => 'Y'
177722    );
177723 
177724    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
177725 
177726       xla_ae_lines_pkg.set_segment(
177727           p_to_segment_code         => 'GL_BALANCING'
177728         , p_segment_value           => l_segment
177729         , p_from_segment_code       => l_adr_value_segment_code
177730         , p_from_combination_id     => l_adr_value_combination_id
177731         , p_value_type_code         => l_adr_value_type_code
177732         , p_transaction_coa_id      => l_adr_transaction_coa_id
177733         , p_accounting_coa_id       => l_adr_accounting_coa_id
177734         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
177735         , p_flex_value_set_id       => l_adr_flex_value_set_id
177736         , p_adr_code                => 'FA_EXPENSE_ACCT'
177737         , p_adr_type_code           => 'S'
177738         , p_component_type          => l_component_type
177739         , p_component_code          => l_component_code
177740         , p_component_type_code     => l_component_type_code
177741         , p_component_appl_id       => l_component_appl_id
177742         , p_amb_context_code        => l_amb_context_code
177743         , p_entity_code             => 'TRANSACTIONS'
177744         , p_event_class_code        => 'UNIT_ADJUSTMENTS'
177745         , p_side                    => 'NA'
177746         );
177747 
177748   END IF;
177749 
177750    --
177751    --
177752    END IF;
177753 
177754        --
177755        -- Update the line information that should be overwritten
177756        --
177757        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
177758                                          p_header_num   => 1);
177759        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
177760 
177761        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
177762 
177763        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
177764           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
177765        END IF;
177766 
177767       --
177768       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
177769       --
177770       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
177771           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
177772       ELSE
177773           ---------------------------------------------------------------------------------------------------
177774           -- 4262811a Switch Sign
177775           ---------------------------------------------------------------------------------------------------
177776           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
177777           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
177778                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
177779           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
177780                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
177781           -- 5132302
177782           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
177783                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
177784 
177785       END IF;
177786 
177787       -- 4955764
177788       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
177789       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
177790 
177791 
177792       XLA_AE_LINES_PKG.ValidateCurrentLine;
177793       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
177794 
177795       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
177796                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
177797                ,p_balance_type_code => l_balance_type_code);
177798 
177799    END IF;
177800 
177801    -----------------------------------------------------------------------------------------
177802    -- 4262811 Multiperiod Accounting
177803    -----------------------------------------------------------------------------------------
177804      -- No MPA option is assigned.
177805 
177806 
177810 
177807 END IF;
177808 END IF;
177809 --
177811 --
177812 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
177813    trace
177814       (p_msg      => 'END of AcctLineType_404'
177815       ,p_level    => C_LEVEL_PROCEDURE
177816       ,p_module   => l_log_module);
177817 END IF;
177818 --
177819 EXCEPTION
177820   WHEN xla_exceptions_pkg.application_exception THEN
177821       RAISE;
177822   WHEN OTHERS THEN
177823        xla_exceptions_pkg.raise_message
177824            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_404');
177825 END AcctLineType_404;
177826 --
177827 
177828 ---------------------------------------
177829 --
177830 -- PRIVATE FUNCTION
177831 --         AcctLineType_405
177832 --
177833 ---------------------------------------
177834 PROCEDURE AcctLineType_405 (
177835   p_application_id        IN NUMBER
177836  ,p_event_id              IN NUMBER
177837  ,p_calculate_acctd_flag  IN VARCHAR2
177838  ,p_calculate_g_l_flag    IN VARCHAR2
177839  ,p_actual_flag           IN OUT VARCHAR2
177840  ,p_balance_type_code     OUT VARCHAR2
177841  ,p_gain_or_loss_ref      OUT VARCHAR2
177842  
177843 --Period Close Date
177844  , p_source_1            IN DATE
177845 --Generated Code Combination Identifier
177846  , p_source_3            IN NUMBER
177847 --Expense Account Code Combination Identifier
177848  , p_source_29            IN NUMBER
177849 --Adjustment Type
177850  , p_source_35            IN VARCHAR2
177851 --Transaction Header Identifier
177852  , p_source_36            IN NUMBER
177853 --Adjustment Line Identifier
177854  , p_source_37            IN NUMBER
177855 --Distribution Type Code
177856  , p_source_38            IN VARCHAR2
177857 --Entered Amount
177858  , p_source_39            IN NUMBER
177859 --Currency Code
177860  , p_source_40            IN VARCHAR2
177861 )
177862 IS
177863 
177864 l_component_type              VARCHAR2(80);
177865 l_component_code              VARCHAR2(30);
177866 l_component_type_code         VARCHAR2(1);
177867 l_component_appl_id           INTEGER;
177868 l_amb_context_code            VARCHAR2(30);
177869 l_entity_code                 VARCHAR2(30);
177870 l_event_class_code            VARCHAR2(30);
177871 l_ae_header_id                NUMBER;
177872 l_event_type_code             VARCHAR2(30);
177873 l_line_definition_code        VARCHAR2(30);
177874 l_line_definition_owner_code  VARCHAR2(1);
177875 --
177876 -- adr variables
177877 l_segment                     VARCHAR2(30);
177878 l_ccid                        NUMBER;
177879 l_adr_transaction_coa_id      NUMBER;
177880 l_adr_accounting_coa_id       NUMBER;
177881 l_adr_flexfield_segment_code  VARCHAR2(30);
177882 l_adr_flex_value_set_id       NUMBER;
177883 l_adr_value_type_code         VARCHAR2(30);
177884 l_adr_value_combination_id    NUMBER;
177885 l_adr_value_segment_code      VARCHAR2(30);
177886 
177887 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
177888 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
177889 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
177890 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
177891 
177892 -- 4262811 Variables ------------------------------------------------------------------------------------------
177893 l_entered_amt_idx             NUMBER;
177894 l_accted_amt_idx              NUMBER;
177895 l_acc_rev_flag                VARCHAR2(1);
177896 l_accrual_line_num            NUMBER;
177897 l_tmp_amt                     NUMBER;
177898 l_acc_rev_natural_side_code   VARCHAR2(1);
177899 
177900 l_num_entries                 NUMBER;
177901 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
177902 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
177903 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
177904 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
177905 l_recog_line_1                NUMBER;
177906 l_recog_line_2                NUMBER;
177907 
177908 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
177909 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
177910 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
177911 
177912 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
177913 
177914 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
177915 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
177916 
177917 ---------------------------------------------------------------------------------------------------------------
177918 
177919 
177920 --
177921 -- bulk performance
177922 --
177923 l_balance_type_code           VARCHAR2(1);
177924 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
177925 l_log_module                  VARCHAR2(240);
177926 
177927 --
177928 -- Upgrade strategy
177929 --
177930 l_actual_upg_option           VARCHAR2(1);
177931 l_enc_upg_option           VARCHAR2(1);
177932 
177933 --
177934 BEGIN
177935 --
177936 IF g_log_enabled THEN
177937       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_405';
177938 END IF;
177939 --
177940 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
177941 
177942       trace
177943          (p_msg      => 'BEGIN of AcctLineType_405'
177944          ,p_level    => C_LEVEL_PROCEDURE
177945          ,p_module   => l_log_module);
177946 
177947 END IF;
177948 --
177949 l_component_type             := 'AMB_JLT';
177950 l_component_code             := 'FA_UNPL_EXP';
177951 l_component_type_code        := 'S';
177952 l_component_appl_id          :=  140;
177953 l_amb_context_code           := 'DEFAULT';
177954 l_entity_code                := 'TRANSACTIONS';
177955 l_event_class_code           := 'UNPLANNED_DEPRECIATION';
177959 --
177956 l_event_type_code            := 'UNPLANNED_DEPRECIATION_ALL';
177957 l_line_definition_owner_code := 'S';
177958 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNPLA27';
177960 l_balance_type_code          := 'A';
177961 l_segment                     := NULL;
177962 l_ccid                        := NULL;
177963 l_adr_transaction_coa_id      := NULL;
177964 l_adr_accounting_coa_id       := NULL;
177965 l_adr_flexfield_segment_code  := NULL;
177966 l_adr_flex_value_set_id       := NULL;
177967 l_adr_value_type_code         := NULL;
177968 l_adr_value_combination_id    := NULL;
177969 l_adr_value_segment_code      := NULL;
177970 
177971 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
177972 l_bflow_class_code           := '';    -- 4219869 Business Flow
177973 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
177974 l_budgetary_control_flag     := 'N';
177975 
177976 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
177977 l_bflow_applied_to_amt       := NULL; -- 5132302
177978 l_entered_amt_idx            := NULL;          -- 4262811
177979 l_accted_amt_idx             := NULL;          -- 4262811
177980 l_acc_rev_flag               := NULL;          -- 4262811
177981 l_accrual_line_num           := NULL;          -- 4262811
177982 l_tmp_amt                    := NULL;          -- 4262811
177983 --
177984  
177985 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
177986     l_balance_type_code <> 'B' THEN
177987 IF NVL(p_source_35,'
177988 ') =  'EXPENSE'
177989  THEN 
177990 
177991    --
177992    XLA_AE_LINES_PKG.SetNewLine;
177993 
177994    p_balance_type_code          := l_balance_type_code;
177995    -- set the flag so later we will know whether the gain loss line needs to be created
177996    
177997    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
177998      p_actual_flag :='A';
177999    END IF;
178000 
178001    --
178002    -- bulk performance
178003    --
178004    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
178005                                       p_header_num   => 0); -- 4262811
178006    --
178007    -- set accounting line options
178008    --
178009    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
178010            p_natural_side_code          => 'D'
178011          , p_gain_or_loss_flag          => 'N'
178012          , p_gl_transfer_mode_code      => 'S'
178013          , p_acct_entry_type_code       => 'A'
178014          , p_switch_side_flag           => 'Y'
178015          , p_merge_duplicate_code       => 'N'
178016          );
178017    --
178018    l_acc_rev_natural_side_code := 'C';  -- 4262811
178019    -- 
178020    --
178021    -- set accounting line type info
178022    --
178023    xla_ae_lines_pkg.SetAcctLineType
178024       (p_component_type             => l_component_type
178025       ,p_event_type_code            => l_event_type_code
178026       ,p_line_definition_owner_code => l_line_definition_owner_code
178027       ,p_line_definition_code       => l_line_definition_code
178028       ,p_accounting_line_code       => l_component_code
178029       ,p_accounting_line_type_code  => l_component_type_code
178030       ,p_accounting_line_appl_id    => l_component_appl_id
178031       ,p_amb_context_code           => l_amb_context_code
178032       ,p_entity_code                => l_entity_code
178033       ,p_event_class_code           => l_event_class_code);
178034    --
178035    -- set accounting class
178036    --
178037    xla_ae_lines_pkg.SetAcctClass(
178038            p_accounting_class_code  => 'EXPENSE'
178039          , p_ae_header_id           => l_ae_header_id
178040          );
178041 
178042    --
178043    -- set rounding class
178044    --
178045    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
178046                       'EXPENSE';
178047 
178048    --
178049    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
178050    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
178051    --
178052    -- bulk performance
178053    --
178054    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
178055 
178056    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
178057       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
178058 
178059    -- 4955764
178060    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
178061       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
178062 
178063    -- 4458381 Public Sector Enh
178064    
178065    --
178066    -- set accounting attributes for the line type
178067    --
178068    l_entered_amt_idx := 4;
178069    l_accted_amt_idx  := 6;
178070    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
178071    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
178072    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
178073    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
178074    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
178075    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
178076    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
178077    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
178078    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
178079    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
178080    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
178081    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
178082    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
178083 
178084    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
178088    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
178085    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
178086 
178087    ---------------------------------------------------------------------------------------------------------------
178089    ---------------------------------------------------------------------------------------------------------------
178090    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
178091 
178092    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
178093    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
178094 
178095    IF xla_accounting_cache_pkg.GetValueChar
178096          (p_source_code         => 'LEDGER_CATEGORY_CODE'
178097          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
178098    AND l_bflow_method_code = 'PRIOR_ENTRY'
178099 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
178100    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
178101          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
178102        )
178103    THEN
178104          xla_ae_lines_pkg.BflowUpgEntry
178105            (p_business_method_code    => l_bflow_method_code
178106            ,p_business_class_code     => l_bflow_class_code
178107            ,p_balance_type            => l_balance_type_code);
178108    ELSE
178109       NULL;
178110 -- No business flow processing for business flow method of NONE.
178111    END IF;
178112 
178113    --
178114    -- call analytical criteria
178115    --
178116    
178117    --
178118    -- call description
178119    --
178120    
178121 xla_ae_lines_pkg.SetLineDescription(
178122    p_ae_header_id => l_ae_header_id
178123   ,p_description  => Description_141 (
178124      p_application_id         => p_application_id
178125    , p_ae_header_id           => l_ae_header_id 
178126 , p_source_1 => p_source_1
178127    )
178128 );
178129 
178130 
178131    --
178132    -- call ADRs
178133    -- Bug 4922099
178134    --
178135    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
178136         (NVL(l_actual_upg_option, 'N') = 'O') OR
178137         (NVL(l_enc_upg_option, 'N') = 'O')
178138       )
178139    THEN
178140    NULL;
178141    --
178142    --
178143    
178144   l_ccid := AcctDerRule_175(
178145            p_application_id           => p_application_id
178146          , p_ae_header_id             => l_ae_header_id 
178147 , p_source_3 => p_source_3
178148 , p_source_29 => p_source_29
178149          , x_transaction_coa_id       => l_adr_transaction_coa_id
178150          , x_accounting_coa_id        => l_adr_accounting_coa_id
178151          , x_value_type_code          => l_adr_value_type_code
178152          , p_side                     => 'NA'
178153    );
178154 
178155    xla_ae_lines_pkg.set_ccid(
178156     p_code_combination_id          => l_ccid
178157   , p_value_type_code              => l_adr_value_type_code
178158   , p_transaction_coa_id           => l_adr_transaction_coa_id
178159   , p_accounting_coa_id            => l_adr_accounting_coa_id
178160   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
178161   , p_adr_type_code                => 'S'
178162   , p_component_type               => l_component_type
178163   , p_component_code               => l_component_code
178164   , p_component_type_code          => l_component_type_code
178165   , p_component_appl_id            => l_component_appl_id
178166   , p_amb_context_code             => l_amb_context_code
178167   , p_side                         => 'NA'
178168   );
178169 
178170 
178171    --
178172    --
178173    END IF;
178174    --
178175    -- Bug 4922099
178176    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
178177           (NVL(l_enc_upg_option, 'N') = 'O')
178178         ) AND
178179         (l_bflow_method_code = 'PRIOR_ENTRY')
178180       )
178181    THEN
178182       IF
178183       --
178184       1 = 2
178185       --
178186       THEN
178187       xla_accounting_err_pkg.build_message
178188                                     (p_appli_s_name            => 'XLA'
178189                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
178190                                     ,p_token_1                 => 'LINE_NUMBER'
178191                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
178192                                     ,p_token_2                 => 'LINE_TYPE_NAME'
178193                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
178194                                                                              l_component_type
178195                                                                             ,l_component_code
178196                                                                             ,l_component_type_code
178197                                                                             ,l_component_appl_id
178198                                                                             ,l_amb_context_code
178199                                                                             ,l_entity_code
178200                                                                             ,l_event_class_code
178201                                                                            )
178202                                     ,p_token_3                 => 'OWNER'
178203                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
178204                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
178205                                                                           ,p_lookup_code    => l_component_type_code
178206                                                                          )
178210                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
178207                                     ,p_token_4                 => 'PRODUCT_NAME'
178208                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
178209                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
178211                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
178212                                     ,p_ae_header_id            =>  NULL
178213                                        );
178214 
178215         IF (C_LEVEL_ERROR>= g_log_level) THEN
178216                  trace
178217                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
178218                       ,p_level    => C_LEVEL_ERROR
178219                       ,p_module   => l_log_module);
178220         END IF;
178221       END IF;
178222    END IF;
178223    --
178224    --
178225    ------------------------------------------------------------------------------------------------
178226    -- 4219869 Business Flow
178227    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
178228    -- Prior Entry.  Currently, the following code is always generated.
178229    ------------------------------------------------------------------------------------------------
178230    XLA_AE_LINES_PKG.ValidateCurrentLine;
178231 
178232    ------------------------------------------------------------------------------------
178233    -- 4219869 Business Flow
178234    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
178235    ------------------------------------------------------------------------------------
178236    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
178237 
178238    ----------------------------------------------------------------------------------
178239    -- 4219869 Business Flow
178240    -- Update journal entry status -- Need to generate this within IF <condition>
178241    ----------------------------------------------------------------------------------
178242    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
178243          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
178244          ,p_balance_type_code => l_balance_type_code
178245          );
178246 
178247    -------------------------------------------------------------------------------------------
178248    -- 4262811 - Generate the Accrual Reversal lines
178249    -------------------------------------------------------------------------------------------
178250    BEGIN
178251       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
178252                               (g_array_event(p_event_id).array_value_num('header_index'));
178253       IF l_acc_rev_flag IS NULL THEN
178254          l_acc_rev_flag := 'N';
178255       END IF;
178256    EXCEPTION
178257       WHEN OTHERS THEN
178258          l_acc_rev_flag := 'N';
178259    END;
178260    --
178261    IF (l_acc_rev_flag = 'Y') THEN
178262 
178263        -- 4645092  ------------------------------------------------------------------------------
178264        -- To allow MPA report to determine if it should generate report process
178265        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
178266        ------------------------------------------------------------------------------------------
178267 
178268        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
178269        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
178270    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
178271    -- call ADRs
178272    -- Bug 4922099
178273    --
178274    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
178275         (NVL(l_actual_upg_option, 'N') = 'O') OR
178276         (NVL(l_enc_upg_option, 'N') = 'O')
178277       )
178278    THEN
178279    NULL;
178280    --
178281    --
178282    
178283   l_ccid := AcctDerRule_175(
178284            p_application_id           => p_application_id
178285          , p_ae_header_id             => l_ae_header_id 
178286 , p_source_3 => p_source_3
178287 , p_source_29 => p_source_29
178288          , x_transaction_coa_id       => l_adr_transaction_coa_id
178289          , x_accounting_coa_id        => l_adr_accounting_coa_id
178290          , x_value_type_code          => l_adr_value_type_code
178291          , p_side                     => 'NA'
178292    );
178293 
178294    xla_ae_lines_pkg.set_ccid(
178295     p_code_combination_id          => l_ccid
178296   , p_value_type_code              => l_adr_value_type_code
178297   , p_transaction_coa_id           => l_adr_transaction_coa_id
178298   , p_accounting_coa_id            => l_adr_accounting_coa_id
178299   , p_adr_code                     => 'FA_EXPENSE_ACCOUNT'
178300   , p_adr_type_code                => 'S'
178301   , p_component_type               => l_component_type
178302   , p_component_code               => l_component_code
178303   , p_component_type_code          => l_component_type_code
178304   , p_component_appl_id            => l_component_appl_id
178305   , p_amb_context_code             => l_amb_context_code
178306   , p_side                         => 'NA'
178307   );
178308 
178309 
178310    --
178311    --
178312    END IF;
178313 
178314        --
178315        -- Update the line information that should be overwritten
178316        --
178317        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
178318                                          p_header_num   => 1);
178319        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
178320 
178321        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
178322 
178323        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
178327       --
178324           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
178325        END IF;
178326 
178328       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
178329       --
178330       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
178331           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
178332       ELSE
178333           ---------------------------------------------------------------------------------------------------
178334           -- 4262811a Switch Sign
178335           ---------------------------------------------------------------------------------------------------
178336           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
178337           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
178338                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
178339           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
178340                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
178341           -- 5132302
178342           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
178343                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
178344 
178345       END IF;
178346 
178347       -- 4955764
178348       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
178349       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
178350 
178351 
178352       XLA_AE_LINES_PKG.ValidateCurrentLine;
178353       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
178354 
178355       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
178356                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
178357                ,p_balance_type_code => l_balance_type_code);
178358 
178359    END IF;
178360 
178361    -----------------------------------------------------------------------------------------
178362    -- 4262811 Multiperiod Accounting
178363    -----------------------------------------------------------------------------------------
178364      -- No MPA option is assigned.
178365 
178366 
178367 END IF;
178368 END IF;
178369 --
178370 
178371 --
178372 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
178373    trace
178374       (p_msg      => 'END of AcctLineType_405'
178375       ,p_level    => C_LEVEL_PROCEDURE
178376       ,p_module   => l_log_module);
178377 END IF;
178378 --
178379 EXCEPTION
178380   WHEN xla_exceptions_pkg.application_exception THEN
178381       RAISE;
178382   WHEN OTHERS THEN
178383        xla_exceptions_pkg.raise_message
178384            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_405');
178385 END AcctLineType_405;
178386 --
178387 
178388 ---------------------------------------
178389 --
178390 -- PRIVATE FUNCTION
178391 --         AcctLineType_406
178392 --
178393 ---------------------------------------
178394 PROCEDURE AcctLineType_406 (
178395   p_application_id        IN NUMBER
178396  ,p_event_id              IN NUMBER
178397  ,p_calculate_acctd_flag  IN VARCHAR2
178398  ,p_calculate_g_l_flag    IN VARCHAR2
178399  ,p_actual_flag           IN OUT VARCHAR2
178400  ,p_balance_type_code     OUT VARCHAR2
178401  ,p_gain_or_loss_ref      OUT VARCHAR2
178402  
178403 --Period Close Date
178404  , p_source_1            IN DATE
178405 --Depreciation Reserve Account
178406  , p_source_10            IN VARCHAR2
178407 --Generated Offset Code Combination Identifier
178408  , p_source_17            IN NUMBER
178409 --Expense Account Code Combination Identifier
178410  , p_source_29            IN NUMBER
178411 --Default Code Combination Identifier
178412  , p_source_30            IN NUMBER
178413 --Adjustment Type
178414  , p_source_35            IN VARCHAR2
178415 --Transaction Header Identifier
178416  , p_source_36            IN NUMBER
178417 --Adjustment Line Identifier
178418  , p_source_37            IN NUMBER
178419 --Distribution Type Code
178420  , p_source_38            IN VARCHAR2
178421 --Entered Amount
178422  , p_source_39            IN NUMBER
178423 --Currency Code
178424  , p_source_40            IN VARCHAR2
178425 )
178426 IS
178427 
178428 l_component_type              VARCHAR2(80);
178429 l_component_code              VARCHAR2(30);
178430 l_component_type_code         VARCHAR2(1);
178431 l_component_appl_id           INTEGER;
178432 l_amb_context_code            VARCHAR2(30);
178433 l_entity_code                 VARCHAR2(30);
178434 l_event_class_code            VARCHAR2(30);
178435 l_ae_header_id                NUMBER;
178436 l_event_type_code             VARCHAR2(30);
178437 l_line_definition_code        VARCHAR2(30);
178438 l_line_definition_owner_code  VARCHAR2(1);
178439 --
178440 -- adr variables
178441 l_segment                     VARCHAR2(30);
178442 l_ccid                        NUMBER;
178443 l_adr_transaction_coa_id      NUMBER;
178444 l_adr_accounting_coa_id       NUMBER;
178445 l_adr_flexfield_segment_code  VARCHAR2(30);
178446 l_adr_flex_value_set_id       NUMBER;
178447 l_adr_value_type_code         VARCHAR2(30);
178448 l_adr_value_combination_id    NUMBER;
178449 l_adr_value_segment_code      VARCHAR2(30);
178450 
178451 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
178452 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
178453 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
178454 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
178455 
178459 l_acc_rev_flag                VARCHAR2(1);
178456 -- 4262811 Variables ------------------------------------------------------------------------------------------
178457 l_entered_amt_idx             NUMBER;
178458 l_accted_amt_idx              NUMBER;
178460 l_accrual_line_num            NUMBER;
178461 l_tmp_amt                     NUMBER;
178462 l_acc_rev_natural_side_code   VARCHAR2(1);
178463 
178464 l_num_entries                 NUMBER;
178465 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
178466 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
178467 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
178468 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
178469 l_recog_line_1                NUMBER;
178470 l_recog_line_2                NUMBER;
178471 
178472 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
178473 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
178474 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
178475 
178476 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
178477 
178478 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
178479 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
178480 
178481 ---------------------------------------------------------------------------------------------------------------
178482 
178483 
178484 --
178485 -- bulk performance
178486 --
178487 l_balance_type_code           VARCHAR2(1);
178488 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
178489 l_log_module                  VARCHAR2(240);
178490 
178491 --
178492 -- Upgrade strategy
178493 --
178494 l_actual_upg_option           VARCHAR2(1);
178495 l_enc_upg_option           VARCHAR2(1);
178496 
178497 --
178498 BEGIN
178499 --
178500 IF g_log_enabled THEN
178501       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_406';
178502 END IF;
178503 --
178504 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
178505 
178506       trace
178507          (p_msg      => 'BEGIN of AcctLineType_406'
178508          ,p_level    => C_LEVEL_PROCEDURE
178509          ,p_module   => l_log_module);
178510 
178511 END IF;
178512 --
178513 l_component_type             := 'AMB_JLT';
178514 l_component_code             := 'FA_UNPL_RESERVE';
178515 l_component_type_code        := 'S';
178516 l_component_appl_id          :=  140;
178517 l_amb_context_code           := 'DEFAULT';
178518 l_entity_code                := 'TRANSACTIONS';
178519 l_event_class_code           := 'UNPLANNED_DEPRECIATION';
178520 l_event_type_code            := 'UNPLANNED_DEPRECIATION_ALL';
178521 l_line_definition_owner_code := 'S';
178522 l_line_definition_code       := 'FA_STANDARD_ACCOUNTING_UNPLA27';
178523 --
178524 l_balance_type_code          := 'A';
178525 l_segment                     := NULL;
178526 l_ccid                        := NULL;
178527 l_adr_transaction_coa_id      := NULL;
178528 l_adr_accounting_coa_id       := NULL;
178529 l_adr_flexfield_segment_code  := NULL;
178530 l_adr_flex_value_set_id       := NULL;
178531 l_adr_value_type_code         := NULL;
178532 l_adr_value_combination_id    := NULL;
178533 l_adr_value_segment_code      := NULL;
178534 
178535 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
178536 l_bflow_class_code           := '';    -- 4219869 Business Flow
178537 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
178538 l_budgetary_control_flag     := 'N';
178539 
178540 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
178541 l_bflow_applied_to_amt       := NULL; -- 5132302
178542 l_entered_amt_idx            := NULL;          -- 4262811
178543 l_accted_amt_idx             := NULL;          -- 4262811
178544 l_acc_rev_flag               := NULL;          -- 4262811
178545 l_accrual_line_num           := NULL;          -- 4262811
178546 l_tmp_amt                    := NULL;          -- 4262811
178547 --
178548  
178549 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
178550     l_balance_type_code <> 'B' THEN
178551 IF NVL(p_source_35,'
178552 ') =  'EXPENSE'
178553  THEN 
178554 
178555    --
178556    XLA_AE_LINES_PKG.SetNewLine;
178557 
178558    p_balance_type_code          := l_balance_type_code;
178559    -- set the flag so later we will know whether the gain loss line needs to be created
178560    
178561    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
178562      p_actual_flag :='A';
178563    END IF;
178564 
178565    --
178566    -- bulk performance
178567    --
178568    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
178569                                       p_header_num   => 0); -- 4262811
178570    --
178571    -- set accounting line options
178572    --
178573    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
178574            p_natural_side_code          => 'C'
178575          , p_gain_or_loss_flag          => 'N'
178576          , p_gl_transfer_mode_code      => 'S'
178577          , p_acct_entry_type_code       => 'A'
178578          , p_switch_side_flag           => 'Y'
178579          , p_merge_duplicate_code       => 'N'
178580          );
178581    --
178582    l_acc_rev_natural_side_code := 'D';  -- 4262811
178583    -- 
178584    --
178585    -- set accounting line type info
178586    --
178587    xla_ae_lines_pkg.SetAcctLineType
178588       (p_component_type             => l_component_type
178589       ,p_event_type_code            => l_event_type_code
178590       ,p_line_definition_owner_code => l_line_definition_owner_code
178591       ,p_line_definition_code       => l_line_definition_code
178592       ,p_accounting_line_code       => l_component_code
178593       ,p_accounting_line_type_code  => l_component_type_code
178597       ,p_event_class_code           => l_event_class_code);
178594       ,p_accounting_line_appl_id    => l_component_appl_id
178595       ,p_amb_context_code           => l_amb_context_code
178596       ,p_entity_code                => l_entity_code
178598    --
178599    -- set accounting class
178600    --
178601    xla_ae_lines_pkg.SetAcctClass(
178602            p_accounting_class_code  => 'ASSET'
178603          , p_ae_header_id           => l_ae_header_id
178604          );
178605 
178606    --
178607    -- set rounding class
178608    --
178609    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
178610                       'ASSET';
178611 
178612    --
178613    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
178614    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
178615    --
178616    -- bulk performance
178617    --
178618    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
178619 
178620    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
178621       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
178622 
178623    -- 4955764
178624    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
178625       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
178626 
178627    -- 4458381 Public Sector Enh
178628    
178629    --
178630    -- set accounting attributes for the line type
178631    --
178632    l_entered_amt_idx := 4;
178633    l_accted_amt_idx  := 6;
178634    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
178635    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
178636    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_36);
178637    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_IDENTIFIER_2';
178638    l_rec_acct_attrs.array_num_value(2)  :=  to_char(p_source_37);
178639    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
178640    l_rec_acct_attrs.array_char_value(3)  := p_source_38;
178641    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
178642    l_rec_acct_attrs.array_num_value(4)  := p_source_39;
178643    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
178644    l_rec_acct_attrs.array_char_value(5)  := p_source_40;
178645    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
178646    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
178647 
178648    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
178649    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
178650 
178651    ---------------------------------------------------------------------------------------------------------------
178652    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
178653    ---------------------------------------------------------------------------------------------------------------
178654    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
178655 
178656    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
178657    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
178658 
178659    IF xla_accounting_cache_pkg.GetValueChar
178660          (p_source_code         => 'LEDGER_CATEGORY_CODE'
178661          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
178662    AND l_bflow_method_code = 'PRIOR_ENTRY'
178663 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
178664    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
178665          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
178666        )
178667    THEN
178668          xla_ae_lines_pkg.BflowUpgEntry
178669            (p_business_method_code    => l_bflow_method_code
178670            ,p_business_class_code     => l_bflow_class_code
178671            ,p_balance_type            => l_balance_type_code);
178672    ELSE
178673       NULL;
178674 -- No business flow processing for business flow method of NONE.
178675    END IF;
178676 
178677    --
178678    -- call analytical criteria
178679    --
178680    
178681    --
178682    -- call description
178683    --
178684    
178685 xla_ae_lines_pkg.SetLineDescription(
178686    p_ae_header_id => l_ae_header_id
178687   ,p_description  => Description_142 (
178688      p_application_id         => p_application_id
178689    , p_ae_header_id           => l_ae_header_id 
178690 , p_source_1 => p_source_1
178691    )
178692 );
178693 
178694 
178695    --
178696    -- call ADRs
178697    -- Bug 4922099
178698    --
178699    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
178700         (NVL(l_actual_upg_option, 'N') = 'O') OR
178701         (NVL(l_enc_upg_option, 'N') = 'O')
178702       )
178703    THEN
178704    NULL;
178705    --
178706    --
178707    
178708   l_ccid := AcctDerRule_180(
178709            p_application_id           => p_application_id
178710          , p_ae_header_id             => l_ae_header_id 
178711 , p_source_17 => p_source_17
178712 , p_source_30 => p_source_30
178713          , x_transaction_coa_id       => l_adr_transaction_coa_id
178714          , x_accounting_coa_id        => l_adr_accounting_coa_id
178715          , x_value_type_code          => l_adr_value_type_code
178716          , p_side                     => 'NA'
178717    );
178718 
178719    xla_ae_lines_pkg.set_ccid(
178720     p_code_combination_id          => l_ccid
178721   , p_value_type_code              => l_adr_value_type_code
178722   , p_transaction_coa_id           => l_adr_transaction_coa_id
178723   , p_accounting_coa_id            => l_adr_accounting_coa_id
178727   , p_component_code               => l_component_code
178724   , p_adr_code                     => 'FA_UPL_RESERVE'
178725   , p_adr_type_code                => 'S'
178726   , p_component_type               => l_component_type
178728   , p_component_type_code          => l_component_type_code
178729   , p_component_appl_id            => l_component_appl_id
178730   , p_amb_context_code             => l_amb_context_code
178731   , p_side                         => 'NA'
178732   );
178733 
178734 
178735    l_segment := AcctDerRule_167(
178736            p_application_id           => p_application_id
178737          , p_ae_header_id             => l_ae_header_id 
178738 , p_source_10 => p_source_10
178739 , p_source_17 => p_source_17
178740          , x_transaction_coa_id       => l_adr_transaction_coa_id
178741          , x_accounting_coa_id        => l_adr_accounting_coa_id
178742          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
178743          , x_flex_value_set_id        => l_adr_flex_value_set_id
178744          , x_value_type_code          => l_adr_value_type_code
178745          , x_value_combination_id     => l_adr_value_combination_id
178746          , x_value_segment_code       => l_adr_value_segment_code
178747          , p_side                     => 'NA'
178748          , p_override_seg_flag        => 'Y'
178749    );
178750 
178751    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
178752 
178753       xla_ae_lines_pkg.set_segment(
178754           p_to_segment_code         => 'GL_ACCOUNT'
178755         , p_segment_value           => l_segment
178756         , p_from_segment_code       => l_adr_value_segment_code
178757         , p_from_combination_id     => l_adr_value_combination_id
178758         , p_value_type_code         => l_adr_value_type_code
178759         , p_transaction_coa_id      => l_adr_transaction_coa_id
178760         , p_accounting_coa_id       => l_adr_accounting_coa_id
178761         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
178762         , p_flex_value_set_id       => l_adr_flex_value_set_id
178763         , p_adr_code                => 'FA_UPL_CAT_RES_ACCOUNT_SEGMENT'
178764         , p_adr_type_code           => 'S'
178765         , p_component_type          => l_component_type
178766         , p_component_code          => l_component_code
178767         , p_component_type_code     => l_component_type_code
178768         , p_component_appl_id       => l_component_appl_id
178769         , p_amb_context_code        => l_amb_context_code
178770         , p_entity_code             => 'TRANSACTIONS'
178771         , p_event_class_code        => 'UNPLANNED_DEPRECIATION'
178772         , p_side                    => 'NA'
178773         );
178774 
178775   END IF;
178776 
178777    l_segment := AcctDerRule_170(
178778            p_application_id           => p_application_id
178779          , p_ae_header_id             => l_ae_header_id 
178780 , p_source_17 => p_source_17
178781 , p_source_29 => p_source_29
178782          , x_transaction_coa_id       => l_adr_transaction_coa_id
178783          , x_accounting_coa_id        => l_adr_accounting_coa_id
178784          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
178785          , x_flex_value_set_id        => l_adr_flex_value_set_id
178786          , x_value_type_code          => l_adr_value_type_code
178787          , x_value_combination_id     => l_adr_value_combination_id
178788          , x_value_segment_code       => l_adr_value_segment_code
178789          , p_side                     => 'NA'
178790          , p_override_seg_flag        => 'Y'
178791    );
178792 
178793    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
178794 
178795       xla_ae_lines_pkg.set_segment(
178796           p_to_segment_code         => 'GL_BALANCING'
178797         , p_segment_value           => l_segment
178798         , p_from_segment_code       => l_adr_value_segment_code
178799         , p_from_combination_id     => l_adr_value_combination_id
178800         , p_value_type_code         => l_adr_value_type_code
178801         , p_transaction_coa_id      => l_adr_transaction_coa_id
178802         , p_accounting_coa_id       => l_adr_accounting_coa_id
178803         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
178804         , p_flex_value_set_id       => l_adr_flex_value_set_id
178805         , p_adr_code                => 'FA_UPL_EXP_ACCOUNT'
178806         , p_adr_type_code           => 'S'
178807         , p_component_type          => l_component_type
178808         , p_component_code          => l_component_code
178809         , p_component_type_code     => l_component_type_code
178810         , p_component_appl_id       => l_component_appl_id
178811         , p_amb_context_code        => l_amb_context_code
178812         , p_entity_code             => 'TRANSACTIONS'
178813         , p_event_class_code        => 'UNPLANNED_DEPRECIATION'
178814         , p_side                    => 'NA'
178815         );
178816 
178817   END IF;
178818 
178819    --
178820    --
178821    END IF;
178822    --
178823    -- Bug 4922099
178824    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
178825           (NVL(l_enc_upg_option, 'N') = 'O')
178826         ) AND
178827         (l_bflow_method_code = 'PRIOR_ENTRY')
178828       )
178829    THEN
178830       IF
178831       --
178832       1 = 2
178833       --
178834       THEN
178835       xla_accounting_err_pkg.build_message
178836                                     (p_appli_s_name            => 'XLA'
178837                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
178838                                     ,p_token_1                 => 'LINE_NUMBER'
178839                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
178840                                     ,p_token_2                 => 'LINE_TYPE_NAME'
178841                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
178842                                                                              l_component_type
178846                                                                             ,l_amb_context_code
178843                                                                             ,l_component_code
178844                                                                             ,l_component_type_code
178845                                                                             ,l_component_appl_id
178847                                                                             ,l_entity_code
178848                                                                             ,l_event_class_code
178849                                                                            )
178850                                     ,p_token_3                 => 'OWNER'
178851                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
178852                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
178853                                                                           ,p_lookup_code    => l_component_type_code
178854                                                                          )
178855                                     ,p_token_4                 => 'PRODUCT_NAME'
178856                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
178857                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
178858                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
178859                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
178860                                     ,p_ae_header_id            =>  NULL
178861                                        );
178862 
178863         IF (C_LEVEL_ERROR>= g_log_level) THEN
178864                  trace
178865                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
178866                       ,p_level    => C_LEVEL_ERROR
178867                       ,p_module   => l_log_module);
178868         END IF;
178869       END IF;
178870    END IF;
178871    --
178872    --
178873    ------------------------------------------------------------------------------------------------
178874    -- 4219869 Business Flow
178875    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
178876    -- Prior Entry.  Currently, the following code is always generated.
178877    ------------------------------------------------------------------------------------------------
178878    XLA_AE_LINES_PKG.ValidateCurrentLine;
178879 
178880    ------------------------------------------------------------------------------------
178881    -- 4219869 Business Flow
178882    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
178883    ------------------------------------------------------------------------------------
178884    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
178885 
178886    ----------------------------------------------------------------------------------
178887    -- 4219869 Business Flow
178888    -- Update journal entry status -- Need to generate this within IF <condition>
178889    ----------------------------------------------------------------------------------
178890    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
178891          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
178892          ,p_balance_type_code => l_balance_type_code
178893          );
178894 
178895    -------------------------------------------------------------------------------------------
178896    -- 4262811 - Generate the Accrual Reversal lines
178897    -------------------------------------------------------------------------------------------
178898    BEGIN
178899       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
178900                               (g_array_event(p_event_id).array_value_num('header_index'));
178901       IF l_acc_rev_flag IS NULL THEN
178902          l_acc_rev_flag := 'N';
178903       END IF;
178904    EXCEPTION
178905       WHEN OTHERS THEN
178906          l_acc_rev_flag := 'N';
178907    END;
178908    --
178909    IF (l_acc_rev_flag = 'Y') THEN
178910 
178911        -- 4645092  ------------------------------------------------------------------------------
178912        -- To allow MPA report to determine if it should generate report process
178913        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
178914        ------------------------------------------------------------------------------------------
178915 
178916        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
178917        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
178918    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
178919    -- call ADRs
178920    -- Bug 4922099
178921    --
178922    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
178923         (NVL(l_actual_upg_option, 'N') = 'O') OR
178924         (NVL(l_enc_upg_option, 'N') = 'O')
178925       )
178926    THEN
178927    NULL;
178928    --
178929    --
178930    
178931   l_ccid := AcctDerRule_180(
178932            p_application_id           => p_application_id
178933          , p_ae_header_id             => l_ae_header_id 
178934 , p_source_17 => p_source_17
178935 , p_source_30 => p_source_30
178936          , x_transaction_coa_id       => l_adr_transaction_coa_id
178937          , x_accounting_coa_id        => l_adr_accounting_coa_id
178938          , x_value_type_code          => l_adr_value_type_code
178939          , p_side                     => 'NA'
178940    );
178941 
178942    xla_ae_lines_pkg.set_ccid(
178943     p_code_combination_id          => l_ccid
178944   , p_value_type_code              => l_adr_value_type_code
178945   , p_transaction_coa_id           => l_adr_transaction_coa_id
178946   , p_accounting_coa_id            => l_adr_accounting_coa_id
178947   , p_adr_code                     => 'FA_UPL_RESERVE'
178948   , p_adr_type_code                => 'S'
178952   , p_component_appl_id            => l_component_appl_id
178949   , p_component_type               => l_component_type
178950   , p_component_code               => l_component_code
178951   , p_component_type_code          => l_component_type_code
178953   , p_amb_context_code             => l_amb_context_code
178954   , p_side                         => 'NA'
178955   );
178956 
178957 
178958    l_segment := AcctDerRule_167(
178959            p_application_id           => p_application_id
178960          , p_ae_header_id             => l_ae_header_id 
178961 , p_source_10 => p_source_10
178962 , p_source_17 => p_source_17
178963          , x_transaction_coa_id       => l_adr_transaction_coa_id
178964          , x_accounting_coa_id        => l_adr_accounting_coa_id
178965          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
178966          , x_flex_value_set_id        => l_adr_flex_value_set_id
178967          , x_value_type_code          => l_adr_value_type_code
178968          , x_value_combination_id     => l_adr_value_combination_id
178969          , x_value_segment_code       => l_adr_value_segment_code
178970          , p_side                     => 'NA'
178971          , p_override_seg_flag        => 'Y'
178972    );
178973 
178974    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
178975 
178976       xla_ae_lines_pkg.set_segment(
178977           p_to_segment_code         => 'GL_ACCOUNT'
178978         , p_segment_value           => l_segment
178979         , p_from_segment_code       => l_adr_value_segment_code
178980         , p_from_combination_id     => l_adr_value_combination_id
178981         , p_value_type_code         => l_adr_value_type_code
178982         , p_transaction_coa_id      => l_adr_transaction_coa_id
178983         , p_accounting_coa_id       => l_adr_accounting_coa_id
178984         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
178985         , p_flex_value_set_id       => l_adr_flex_value_set_id
178986         , p_adr_code                => 'FA_UPL_CAT_RES_ACCOUNT_SEGMENT'
178987         , p_adr_type_code           => 'S'
178988         , p_component_type          => l_component_type
178989         , p_component_code          => l_component_code
178990         , p_component_type_code     => l_component_type_code
178991         , p_component_appl_id       => l_component_appl_id
178992         , p_amb_context_code        => l_amb_context_code
178993         , p_entity_code             => 'TRANSACTIONS'
178994         , p_event_class_code        => 'UNPLANNED_DEPRECIATION'
178995         , p_side                    => 'NA'
178996         );
178997 
178998   END IF;
178999 
179000    l_segment := AcctDerRule_170(
179001            p_application_id           => p_application_id
179002          , p_ae_header_id             => l_ae_header_id 
179003 , p_source_17 => p_source_17
179004 , p_source_29 => p_source_29
179005          , x_transaction_coa_id       => l_adr_transaction_coa_id
179006          , x_accounting_coa_id        => l_adr_accounting_coa_id
179007          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
179008          , x_flex_value_set_id        => l_adr_flex_value_set_id
179009          , x_value_type_code          => l_adr_value_type_code
179010          , x_value_combination_id     => l_adr_value_combination_id
179011          , x_value_segment_code       => l_adr_value_segment_code
179012          , p_side                     => 'NA'
179013          , p_override_seg_flag        => 'Y'
179014    );
179015 
179016    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
179017 
179018       xla_ae_lines_pkg.set_segment(
179019           p_to_segment_code         => 'GL_BALANCING'
179020         , p_segment_value           => l_segment
179021         , p_from_segment_code       => l_adr_value_segment_code
179022         , p_from_combination_id     => l_adr_value_combination_id
179023         , p_value_type_code         => l_adr_value_type_code
179024         , p_transaction_coa_id      => l_adr_transaction_coa_id
179025         , p_accounting_coa_id       => l_adr_accounting_coa_id
179026         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
179027         , p_flex_value_set_id       => l_adr_flex_value_set_id
179028         , p_adr_code                => 'FA_UPL_EXP_ACCOUNT'
179029         , p_adr_type_code           => 'S'
179030         , p_component_type          => l_component_type
179031         , p_component_code          => l_component_code
179032         , p_component_type_code     => l_component_type_code
179033         , p_component_appl_id       => l_component_appl_id
179034         , p_amb_context_code        => l_amb_context_code
179035         , p_entity_code             => 'TRANSACTIONS'
179036         , p_event_class_code        => 'UNPLANNED_DEPRECIATION'
179037         , p_side                    => 'NA'
179038         );
179039 
179040   END IF;
179041 
179042    --
179043    --
179044    END IF;
179045 
179046        --
179047        -- Update the line information that should be overwritten
179048        --
179049        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
179050                                          p_header_num   => 1);
179051        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
179052 
179053        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
179054 
179055        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
179056           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
179057        END IF;
179058 
179059       --
179060       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
179061       --
179062       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
179063           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
179064       ELSE
179068           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
179065           ---------------------------------------------------------------------------------------------------
179066           -- 4262811a Switch Sign
179067           ---------------------------------------------------------------------------------------------------
179069           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
179070                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
179071           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
179072                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
179073           -- 5132302
179074           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
179075                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
179076 
179077       END IF;
179078 
179079       -- 4955764
179080       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
179081       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
179082 
179083 
179084       XLA_AE_LINES_PKG.ValidateCurrentLine;
179085       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
179086 
179087       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
179088                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
179089                ,p_balance_type_code => l_balance_type_code);
179090 
179091    END IF;
179092 
179093    -----------------------------------------------------------------------------------------
179094    -- 4262811 Multiperiod Accounting
179095    -----------------------------------------------------------------------------------------
179096      -- No MPA option is assigned.
179097 
179098 
179099 END IF;
179100 END IF;
179101 --
179102 
179103 --
179104 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
179105    trace
179106       (p_msg      => 'END of AcctLineType_406'
179107       ,p_level    => C_LEVEL_PROCEDURE
179108       ,p_module   => l_log_module);
179109 END IF;
179110 --
179111 EXCEPTION
179112   WHEN xla_exceptions_pkg.application_exception THEN
179113       RAISE;
179114   WHEN OTHERS THEN
179115        xla_exceptions_pkg.raise_message
179116            (p_location => 'XLA_00140_AAD_S_000002_PKG.AcctLineType_406');
179117 END AcctLineType_406;
179118 --
179119 
179120 ---------------------------------------
179121 --
179122 -- PRIVATE PROCEDURE
179123 --         insert_sources_407
179124 --
179125 ----------------------------------------
179126 --
179127 PROCEDURE insert_sources_407(
179128                                 p_target_ledger_id       IN NUMBER
179129                               , p_language               IN VARCHAR2
179130                               , p_sla_ledger_id          IN NUMBER
179131                               , p_pad_start_date         IN DATE
179132                               , p_pad_end_date           IN DATE
179133                          )
179134 IS
179135 
179136 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'ADDITIONS_ALL';
179137 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'ADDITIONS';
179138 p_apps_owner                   VARCHAR2(30);
179139 l_log_module                   VARCHAR2(240);
179140 BEGIN
179141 IF g_log_enabled THEN
179142       l_log_module := C_DEFAULT_MODULE||'.insert_sources_407';
179143 END IF;
179144 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
179145 
179146       trace
179147          (p_msg      => 'BEGIN of insert_sources_407'
179148          ,p_level    => C_LEVEL_PROCEDURE
179149          ,p_module   => l_log_module);
179150 
179151 END IF;
179152 
179153 -- select APPS owner
179154 SELECT oracle_username
179155   INTO p_apps_owner
179156   FROM fnd_oracle_userid
179157  WHERE read_only_flag = 'U'
179158 ;
179159 
179160 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
179161       trace
179162          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
179163                         ' - p_language = '||p_language||
179164                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
179165                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
179166                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
179167                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
179168          ,p_level    => C_LEVEL_STATEMENT
179169          ,p_module   => l_log_module);
179170 END IF;
179171 
179172 
179173 --
179174 INSERT INTO xla_diag_sources --hdr2
179175 (
179176         event_id
179177       , ledger_id
179178       , sla_ledger_id
179179       , description_language
179180       , object_name
179181       , object_type_code
179182       , line_number
179183       , source_application_id
179184       , source_type_code
179185       , source_code
179186       , source_value
179187       , source_meaning
179188       , created_by
179189       , creation_date
179190       , last_update_date
179191       , last_updated_by
179192       , last_update_login
179193       , program_update_date
179194       , program_application_id
179195       , program_id
179196       , request_id
179197 )
179198 SELECT
179199         event_id
179200       , p_target_ledger_id
179201       , p_sla_ledger_id
179202       , p_language
179203       , object_name
179204       , object_type_code
179205       , line_number
179206       , source_application_id
179207       , source_type_code
179208       , source_code
179209       , SUBSTR(source_value ,1,1996)
179210       , SUBSTR(source_meaning ,1,200)
179211       , xla_environment_pkg.g_Usr_Id
179212       , TRUNC(SYSDATE)
179216       , TRUNC(SYSDATE)
179213       , TRUNC(SYSDATE)
179214       , xla_environment_pkg.g_Usr_Id
179215       , xla_environment_pkg.g_Login_Id
179217       , xla_environment_pkg.g_Prog_Appl_Id
179218       , xla_environment_pkg.g_Prog_Id
179219       , xla_environment_pkg.g_Req_Id
179220   FROM (
179221        SELECT xet.event_id                  event_id
179222             , 0                          line_number
179223             , CASE r
179224                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
179225                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
179226                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
179227                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
179228                 
179229                ELSE null
179230               END                           object_name
179231             , CASE r
179232                 WHEN 1 THEN 'HEADER' 
179233                 WHEN 2 THEN 'HEADER' 
179234                 WHEN 3 THEN 'HEADER' 
179235                 WHEN 4 THEN 'HEADER' 
179236                 
179237                 ELSE null
179238               END                           object_type_code
179239             , CASE r
179240                 WHEN 1 THEN '140' 
179241                 WHEN 2 THEN '140' 
179242                 WHEN 3 THEN '140' 
179243                 WHEN 4 THEN '140' 
179244                 
179245                 ELSE null
179246               END                           source_application_id
179247             , 'S'             source_type_code
179248             , CASE r
179249                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
179250                 WHEN 2 THEN 'DEFAULT_CCID' 
179251                 WHEN 3 THEN 'ACCOUNTING_DATE' 
179252                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
179253                 
179254                 ELSE null
179255               END                           source_code
179256             , CASE r
179257                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
179258                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
179259                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
179260                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
179261                 
179262                 ELSE null
179263               END                           source_value
179264             , null              source_meaning
179265          FROM xla_events_gt     xet  
179266       , FA_XLA_EXT_HEADERS_B_GT  h1
179267              ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
179268          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
179269            AND xet.event_class_code = C_EVENT_CLASS_CODE
179270               AND h1.event_id = xet.event_id
179271 
179272 )
179273 ;
179274 --
179275 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
179276 
179277       trace
179278          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
179279          ,p_level    => C_LEVEL_STATEMENT
179280          ,p_module   => l_log_module);
179281 
179282 END IF;
179283 --
179284 
179285 
179286 
179287 --
179288 INSERT INTO xla_diag_sources  --line2
179289 (
179290         event_id
179291       , ledger_id
179292       , sla_ledger_id
179293       , description_language
179294       , object_name
179295       , object_type_code
179296       , line_number
179297       , source_application_id
179298       , source_type_code
179299       , source_code
179300       , source_value
179301       , source_meaning
179302       , created_by
179303       , creation_date
179304       , last_update_date
179305       , last_updated_by
179306       , last_update_login
179307       , program_update_date
179308       , program_application_id
179309       , program_id
179310       , request_id
179311 )
179312 SELECT  event_id
179313       , p_target_ledger_id
179314       , p_sla_ledger_id
179315       , p_language
179316       , object_name
179317       , object_type_code
179318       , line_number
179319       , source_application_id
179320       , source_type_code
179321       , source_code
179322       , SUBSTR(source_value,1,1996)
179323       , SUBSTR(source_meaning ,1,200)
179324       , xla_environment_pkg.g_Usr_Id
179325       , TRUNC(SYSDATE)
179326       , TRUNC(SYSDATE)
179327       , xla_environment_pkg.g_Usr_Id
179328       , xla_environment_pkg.g_Login_Id
179329       , TRUNC(SYSDATE)
179330       , xla_environment_pkg.g_Prog_Appl_Id
179331       , xla_environment_pkg.g_Prog_Id
179332       , xla_environment_pkg.g_Req_Id
179333   FROM (
179334        SELECT xet.event_id                  event_id
179335             , l2.line_number                 line_number
179336             , CASE r
179337                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
179338                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
179339                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
179340                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
179341                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
179342                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
179343                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
179344                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
179345                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
179346                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
179347                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
179348                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
179349                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
179350                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
179351                 WHEN 15 THEN 'FA_XLA_EXT_LINES_B_GT' 
179352                 
179353                ELSE null
179354               END                           object_name
179355             , CASE r
179356                 WHEN 1 THEN 'LINE' 
179357                 WHEN 2 THEN 'LINE' 
179358                 WHEN 3 THEN 'LINE' 
179359                 WHEN 4 THEN 'LINE' 
179363                 WHEN 8 THEN 'LINE' 
179360                 WHEN 5 THEN 'LINE' 
179361                 WHEN 6 THEN 'LINE' 
179362                 WHEN 7 THEN 'LINE' 
179364                 WHEN 9 THEN 'LINE' 
179365                 WHEN 10 THEN 'LINE' 
179366                 WHEN 11 THEN 'LINE' 
179367                 WHEN 12 THEN 'LINE' 
179368                 WHEN 13 THEN 'LINE' 
179369                 WHEN 14 THEN 'LINE' 
179370                 WHEN 15 THEN 'LINE' 
179371                 
179372                 ELSE null
179373               END                           object_type_code
179374             , CASE r
179375                 WHEN 1 THEN '140' 
179376                 WHEN 2 THEN '140' 
179377                 WHEN 3 THEN '140' 
179378                 WHEN 4 THEN '140' 
179379                 WHEN 5 THEN '140' 
179380                 WHEN 6 THEN '140' 
179381                 WHEN 7 THEN '140' 
179382                 WHEN 8 THEN '140' 
179383                 WHEN 9 THEN '140' 
179384                 WHEN 10 THEN '140' 
179385                 WHEN 11 THEN '140' 
179386                 WHEN 12 THEN '140' 
179387                 WHEN 13 THEN '140' 
179388                 WHEN 14 THEN '140' 
179389                 WHEN 15 THEN '140' 
179390                 
179391                 ELSE null
179392               END                           source_application_id
179393             , 'S'             source_type_code
179394             , CASE r
179395                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
179396                 WHEN 2 THEN 'GENERATED_CCID' 
179397                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
179398                 WHEN 4 THEN 'PAYABLES_CCID' 
179399                 WHEN 5 THEN 'ASSET_CLEARING_ACCT' 
179400                 WHEN 6 THEN 'ASSET_COST_ACCT' 
179401                 WHEN 7 THEN 'DEPRN_RESERVE_ACCT' 
179402                 WHEN 8 THEN 'GENERATED_OFFSET_CCID' 
179403                 WHEN 9 THEN 'EXPENSE_ACCOUNT_CCID' 
179404                 WHEN 10 THEN 'ADJUSTMENT_TYPE' 
179405                 WHEN 11 THEN 'TRANSACTION_HEADER_ID' 
179406                 WHEN 12 THEN 'ADJUSTMENT_LINE_ID' 
179407                 WHEN 13 THEN 'DISTRIBUTION_TYPE_CODE' 
179408                 WHEN 14 THEN 'ENTERED_AMOUNT' 
179409                 WHEN 15 THEN 'CURRENCY_CODE' 
179410                 
179411                 ELSE null
179412               END                           source_code
179413             , CASE r
179414                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
179415                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
179416                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
179417                 WHEN 4 THEN TO_CHAR(l2.PAYABLES_CCID)
179418                 WHEN 5 THEN TO_CHAR(l2.ASSET_CLEARING_ACCT)
179419                 WHEN 6 THEN TO_CHAR(l2.ASSET_COST_ACCT)
179420                 WHEN 7 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
179421                 WHEN 8 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
179422                 WHEN 9 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
179423                 WHEN 10 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
179424                 WHEN 11 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
179425                 WHEN 12 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
179426                 WHEN 13 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
179427                 WHEN 14 THEN TO_CHAR(l2.ENTERED_AMOUNT)
179428                 WHEN 15 THEN TO_CHAR(l2.CURRENCY_CODE)
179429                 
179430                 ELSE null
179431               END                           source_value
179432             , null              source_meaning
179433          FROM  xla_events_gt     xet  
179434         , FA_XLA_EXT_LINES_B_GT  l2
179435             , (select rownum r from all_objects where rownum <= 15 and owner = p_apps_owner)
179436         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
179437           AND xet.event_class_code = C_EVENT_CLASS_CODE
179438             AND l2.event_id          = xet.event_id
179439   AND l2.ledger_id (+)  = p_sla_ledger_id
179440 
179441 )
179442 ;
179443 --
179444 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
179445 
179446       trace
179447          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
179448          ,p_level    => C_LEVEL_STATEMENT
179449          ,p_module   => l_log_module);
179450 
179451 END IF;
179452 
179453 
179454 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
179455       trace
179456          (p_msg      => 'END of insert_sources_407'
179457          ,p_level    => C_LEVEL_PROCEDURE
179458          ,p_module   => l_log_module);
179459 END IF;
179460 EXCEPTION
179461   WHEN xla_exceptions_pkg.application_exception THEN
179462       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
179463             trace
179464                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
179465                ,p_level    => C_LEVEL_EXCEPTION
179466                ,p_module   => l_log_module);
179467       END IF;
179468       RAISE;
179469   WHEN OTHERS THEN
179470       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
179471             trace
179472                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
179473                ,p_level    => C_LEVEL_EXCEPTION
179474                ,p_module   => l_log_module);
179475        END IF;
179476        xla_exceptions_pkg.raise_message
179477            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_407');
179478 END insert_sources_407;
179479 --
179480 
179481 ---------------------------------------
179482 --
179483 -- PRIVATE FUNCTION
179484 --         EventClass_407
179485 --
179486 ----------------------------------------
179487 --
179488 FUNCTION EventClass_407
179489        (p_application_id         IN NUMBER
179490        ,p_base_ledger_id         IN NUMBER
179491        ,p_target_ledger_id       IN NUMBER
179492        ,p_language               IN VARCHAR2
179493        ,p_currency_code          IN VARCHAR2
179494        ,p_sla_ledger_id          IN NUMBER
179498 RETURN BOOLEAN IS
179495        ,p_pad_start_date         IN DATE
179496        ,p_pad_end_date           IN DATE
179497        ,p_primary_ledger_id      IN NUMBER)
179499 --
179500 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'ADDITIONS_ALL';
179501 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'ADDITIONS';
179502 
179503 l_calculate_acctd_flag   VARCHAR2(1) :='N';
179504 l_calculate_g_l_flag     VARCHAR2(1) :='N';
179505 --
179506 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
179507 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
179508 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
179509 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
179510 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
179511 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
179512 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
179513 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
179514 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
179515 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
179516 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
179517 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
179518 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
179519 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
179520 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
179521 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
179522 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
179523 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
179524 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
179525 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
179526 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
179527 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
179528 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
179529 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
179530 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
179531 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
179532 
179533 l_event_id                             NUMBER;
179534 l_previous_event_id                    NUMBER;
179535 l_first_event_id                       NUMBER;
179536 l_last_event_id                        NUMBER;
179537 
179538 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
179539 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
179540 --
179541 --
179542 l_result                    BOOLEAN := TRUE;
179543 l_rows                      NUMBER  := 1000;
179544 l_event_type_name           VARCHAR2(80) := 'All';
179545 l_event_class_name          VARCHAR2(80) := 'Additions';
179546 l_description               VARCHAR2(4000);
179547 l_transaction_reversal      NUMBER;
179548 l_ae_header_id              NUMBER;
179549 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
179550 l_log_module                VARCHAR2(240);
179551 --
179552 l_acct_reversal_source      VARCHAR2(30);
179553 l_trx_reversal_source       VARCHAR2(30);
179554 
179555 l_continue_with_lines       BOOLEAN := TRUE;
179556 --
179557 l_acc_rev_gl_date_source    DATE;                      -- 4262811
179558 --
179559 type t_array_event_id is table of number index by binary_integer;
179560 
179561 l_rec_array_event                    t_rec_array_event;
179562 l_null_rec_array_event               t_rec_array_event;
179563 l_array_ae_header_id                 xla_number_array_type;
179564 l_actual_flag                        VARCHAR2(1) := NULL;
179565 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
179566 l_balance_type_code                  VARCHAR2(1) :=NULL;
179567 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
179568 
179569 --
179570 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
179571 --
179572 
179573 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
179574 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
179575 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
179576 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
179577 
179578 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
179579 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
179580 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
179581 TYPE t_array_source_6 IS TABLE OF FA_XLA_EXT_LINES_B_GT.PAYABLES_CCID%TYPE INDEX BY BINARY_INTEGER;
179582 TYPE t_array_source_8 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
179583 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
179584 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
179585 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
179586 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
179587 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
179588 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
179589 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
179590 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
179594 l_array_source_1              t_array_source_1;
179591 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
179592 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
179593 
179595 l_array_source_30              t_array_source_30;
179596 l_array_source_51              t_array_source_51;
179597 l_array_source_52              t_array_source_52;
179598 
179599 l_array_source_2      t_array_source_2;
179600 l_array_source_3      t_array_source_3;
179601 l_array_source_4      t_array_source_4;
179602 l_array_source_6      t_array_source_6;
179603 l_array_source_8      t_array_source_8;
179604 l_array_source_9      t_array_source_9;
179605 l_array_source_10      t_array_source_10;
179606 l_array_source_17      t_array_source_17;
179607 l_array_source_29      t_array_source_29;
179608 l_array_source_35      t_array_source_35;
179609 l_array_source_36      t_array_source_36;
179610 l_array_source_37      t_array_source_37;
179611 l_array_source_38      t_array_source_38;
179612 l_array_source_39      t_array_source_39;
179613 l_array_source_40      t_array_source_40;
179614 
179615 --
179616 CURSOR header_cur
179617 IS
179618 SELECT /*+ leading(xet) cardinality(xet,1) */
179619 -- Event Class Code: ADDITIONS
179620     xet.entity_id
179621    ,xet.legal_entity_id
179622    ,xet.entity_code
179623    ,xet.transaction_number
179624    ,xet.event_id
179625    ,xet.event_class_code
179626    ,xet.event_type_code
179627    ,xet.event_number
179628    ,xet.event_date
179629    ,xet.transaction_date
179630    ,xet.reference_num_1
179631    ,xet.reference_num_2
179632    ,xet.reference_num_3
179633    ,xet.reference_num_4
179634    ,xet.reference_char_1
179635    ,xet.reference_char_2
179636    ,xet.reference_char_3
179637    ,xet.reference_char_4
179638    ,xet.reference_date_1
179639    ,xet.reference_date_2
179640    ,xet.reference_date_3
179641    ,xet.reference_date_4
179642    ,xet.event_created_by
179643    ,xet.budgetary_control_flag 
179644   , h1.PERIOD_CLOSE_DATE    source_1
179645   , h1.DEFAULT_CCID    source_30
179646   , h1.ACCOUNTING_DATE    source_51
179647   , h1.TRANSFER_TO_GL_FLAG    source_52
179648   FROM xla_events_gt     xet 
179649   , FA_XLA_EXT_HEADERS_B_GT  h1
179650  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
179651    and xet.event_class_code = C_EVENT_CLASS_CODE
179652    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
179653 
179654  ORDER BY event_id
179655 ;
179656 
179657 
179658 --
179659 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
179660 IS
179661 SELECT  /*+ leading(xet) cardinality(xet,1) */
179662 -- Event Class Code: ADDITIONS
179663     xet.entity_id
179664    ,xet.legal_entity_id
179665    ,xet.entity_code
179666    ,xet.transaction_number
179667    ,xet.event_id
179668    ,xet.event_class_code
179669    ,xet.event_type_code
179670    ,xet.event_number
179671    ,xet.event_date
179672    ,xet.transaction_date
179673    ,xet.reference_num_1
179674    ,xet.reference_num_2
179675    ,xet.reference_num_3
179676    ,xet.reference_num_4
179677    ,xet.reference_char_1
179678    ,xet.reference_char_2
179679    ,xet.reference_char_3
179680    ,xet.reference_char_4
179681    ,xet.reference_date_1
179682    ,xet.reference_date_2
179683    ,xet.reference_date_3
179684    ,xet.reference_date_4
179685    ,xet.event_created_by
179686    ,xet.budgetary_control_flag
179687  , l2.LINE_NUMBER  
179688   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
179689   , l2.GENERATED_CCID    source_3
179690   , l2.BONUS_RESERVE_ACCT    source_4
179691   , l2.PAYABLES_CCID    source_6
179692   , l2.ASSET_CLEARING_ACCT    source_8
179693   , l2.ASSET_COST_ACCT    source_9
179694   , l2.DEPRN_RESERVE_ACCT    source_10
179695   , l2.GENERATED_OFFSET_CCID    source_17
179696   , l2.EXPENSE_ACCOUNT_CCID    source_29
179697   , l2.ADJUSTMENT_TYPE    source_35
179698   , l2.TRANSACTION_HEADER_ID    source_36
179699   , l2.ADJUSTMENT_LINE_ID    source_37
179700   , l2.DISTRIBUTION_TYPE_CODE    source_38
179701   , l2.ENTERED_AMOUNT    source_39
179702   , l2.CURRENCY_CODE    source_40
179703   FROM xla_events_gt     xet 
179704   , FA_XLA_EXT_LINES_B_GT  l2
179705  WHERE xet.event_id between x_first_event_id and x_last_event_id
179706    and xet.event_date between p_pad_start_date and p_pad_end_date
179707    and xet.event_class_code = C_EVENT_CLASS_CODE
179708    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
179709   AND l2.ledger_id = p_sla_ledger_id
179710 ;
179711 
179712 --
179713 BEGIN
179714 IF g_log_enabled THEN
179715    l_log_module := C_DEFAULT_MODULE||'.EventClass_407';
179716 END IF;
179717 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
179718    trace
179719       (p_msg      => 'BEGIN of EventClass_407'
179720       ,p_level    => C_LEVEL_PROCEDURE
179721       ,p_module   => l_log_module);
179722 END IF;
179723 
179724 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
179725    trace
179726       (p_msg      => 'p_application_id = '||p_application_id||
179727                      ' - p_base_ledger_id = '||p_base_ledger_id||
179728                      ' - p_target_ledger_id  = '||p_target_ledger_id||
179729                      ' - p_language = '||p_language||
179730                      ' - p_currency_code = '||p_currency_code||
179731                      ' - p_sla_ledger_id = '||p_sla_ledger_id
179732       ,p_level    => C_LEVEL_STATEMENT
179733       ,p_module   => l_log_module);
179734 END IF;
179735 --
179736 -- initialze arrays
179737 --
179738 g_array_event.DELETE;
179739 l_rec_array_event := l_null_rec_array_event;
179740 --
179741 --------------------------------------
179742 -- 4262811 Initialze MPA Line Number
179743 --------------------------------------
179747 
179744 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
179745 
179746 --
179748 --
179749 OPEN header_cur;
179750 --
179751 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
179752    trace
179753    (p_msg      => 'SQL - FETCH header_cur'
179754    ,p_level    => C_LEVEL_STATEMENT
179755    ,p_module   => l_log_module);
179756 END IF;
179757 --
179758 LOOP
179759 FETCH header_cur BULK COLLECT INTO
179760         l_array_entity_id
179761       , l_array_legal_entity_id
179762       , l_array_entity_code
179763       , l_array_transaction_num
179764       , l_array_event_id
179765       , l_array_class_code
179766       , l_array_event_type
179767       , l_array_event_number
179768       , l_array_event_date
179769       , l_array_transaction_date
179770       , l_array_reference_num_1
179771       , l_array_reference_num_2
179772       , l_array_reference_num_3
179773       , l_array_reference_num_4
179774       , l_array_reference_char_1
179775       , l_array_reference_char_2
179776       , l_array_reference_char_3
179777       , l_array_reference_char_4
179778       , l_array_reference_date_1
179779       , l_array_reference_date_2
179780       , l_array_reference_date_3
179781       , l_array_reference_date_4
179782       , l_array_event_created_by
179783       , l_array_budgetary_control_flag 
179784       , l_array_source_1
179785       , l_array_source_30
179786       , l_array_source_51
179787       , l_array_source_52
179788       LIMIT l_rows;
179789 --
179790 IF (C_LEVEL_EVENT >= g_log_level) THEN
179791    trace
179792    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
179793    ,p_level    => C_LEVEL_EVENT
179794    ,p_module   => l_log_module);
179795 END IF;
179796 --
179797 EXIT WHEN l_array_entity_id.COUNT = 0;
179798 
179799 -- initialize arrays
179800 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
179801 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
179802 
179803 --
179804 -- Bug 4458708
179805 --
179806 XLA_AE_LINES_PKG.g_LineNumber := 0;
179807 
179808 
179809 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
179810 g_last_hdr_idx := l_array_event_id.LAST;
179811 --
179812 -- loop for the headers. Each iteration is for each header extract row
179813 -- fetched in header cursor
179814 --
179815 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
179816 
179817 --
179818 -- set event info as cache for other routines to refer event attributes
179819 --
179820 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
179821    (p_application_id           => p_application_id
179822    ,p_primary_ledger_id        => p_primary_ledger_id
179823    ,p_base_ledger_id           => p_base_ledger_id
179824    ,p_target_ledger_id         => p_target_ledger_id
179825    ,p_entity_id                => l_array_entity_id(hdr_idx)
179826    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
179827    ,p_entity_code              => l_array_entity_code(hdr_idx)
179828    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
179829    ,p_event_id                 => l_array_event_id(hdr_idx)
179830    ,p_event_class_code         => l_array_class_code(hdr_idx)
179831    ,p_event_type_code          => l_array_event_type(hdr_idx)
179832    ,p_event_number             => l_array_event_number(hdr_idx)
179833    ,p_event_date               => l_array_event_date(hdr_idx)
179834    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
179835    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
179836    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
179837    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
179838    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
179839    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
179840    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
179841    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
179842    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
179843    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
179844    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
179845    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
179846    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
179847    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
179848    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
179849 
179850 --
179851 -- set the status of entry to C_VALID (0)
179852 --
179853 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
179854 
179855 --
179856 -- initialize a row for ae header
179857 --
179858 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
179859 
179860 l_event_id := l_array_event_id(hdr_idx);
179861 
179862 --
179863 -- storing the hdr_idx for event. May be used by line cursor.
179864 --
179865 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
179866 
179867 --
179868 -- store sources from header extract. This can be improved to
179869 -- store only those sources from header extract that may be used in lines
179870 --
179871 
179872 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
179873 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
179874 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
179875 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
179876 
179877 --
179878 -- initilaize the status of ae headers for diffrent balance types
179879 -- the status is initialised to C_NOT_CREATED (2)
179880 --
179881 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
179882 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
179886 -- call api to validate and store accounting attributes for header
179883 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
179884 
179885 --
179887 --
179888 
179889 ------------------------------------------------------------
179890 -- Accrual Reversal : to get date for Standard Source (NONE)
179891 ------------------------------------------------------------
179892 l_acc_rev_gl_date_source := NULL;
179893 
179894      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
179895       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
179896      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
179897       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
179898 
179899 
179900 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
179901 
179902 XLA_AE_HEADER_PKG.SetJeCategoryName;
179903 
179904 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
179905 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
179906 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
179907 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
179908 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
179909 
179910 
179911 --
179912 xla_ae_header_pkg.SetHdrDescription(
179913    p_description => Description_1 (
179914    p_application_id => p_application_id 
179915  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
179916    )
179917 );
179918 --
179919 
179920 -- No header level analytical criteria
179921 
179922 --
179923 --accounting attribute enhancement, bug 3612931
179924 --
179925 l_trx_reversal_source := SUBSTR(NULL, 1,30);
179926 
179927 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
179928    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
179929 
179930    xla_accounting_err_pkg.build_message
179931       (p_appli_s_name            => 'XLA'
179932       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
179933       ,p_token_1                 => 'ACCT_ATTR_NAME'
179934       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
179935       ,p_token_2                 => 'PRODUCT_NAME'
179936       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
179937       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
179938       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
179939       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
179940 
179941 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
179942    --
179943    -- following sets the accounting attributes needed to reverse
179944    -- accounting for a distributeion
179945    --
179946    xla_ae_lines_pkg.SetTrxReversalAttrs
179947       (p_event_id              => l_event_id
179948       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
179949       ,p_trx_reversal_source   => l_trx_reversal_source);
179950 
179951 END IF;
179952 
179953 
179954 ----------------------------------------------------------------
179955 -- 4262811 -  update the header statuses to invalid in need be
179956 ----------------------------------------------------------------
179957 --
179958 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
179959 
179960 
179961   -----------------------------------------------
179962   -- No accrual reversal for the event class/type
179963   -----------------------------------------------
179964 ----------------------------------------------------------------
179965 
179966 --
179967 -- this ends the header loop iteration for one bulk fetch
179968 --
179969 END LOOP;
179970 
179971 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
179972 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
179973 
179974 --
179975 -- insert dummy rows into lines gt table that were created due to
179976 -- transaction reversals
179977 --
179978 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
179979    l_result := XLA_AE_LINES_PKG.InsertLines;
179980 END IF;
179981 
179982 --
179983 -- reset the temp_line_num for each set of events fetched from header
179984 -- cursor rather than doing it for each new event in line cursor
179985 -- Bug 3939231
179986 --
179987 xla_ae_lines_pkg.g_temp_line_num := 0;
179988 
179989 
179990 
179991 --
179992 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
179993 --
179994 --
179995 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
179996 
179997       trace
179998          (p_msg      => 'SQL - FETCH line_cur'
179999          ,p_level    => C_LEVEL_STATEMENT
180000          ,p_module   => l_log_module);
180001 
180002 END IF;
180003 --
180004 --
180005 LOOP
180006   --
180007   FETCH line_cur BULK COLLECT INTO
180008         l_array_entity_id
180009       , l_array_legal_entity_id
180010       , l_array_entity_code
180011       , l_array_transaction_num
180012       , l_array_event_id
180013       , l_array_class_code
180014       , l_array_event_type
180015       , l_array_event_number
180016       , l_array_event_date
180017       , l_array_transaction_date
180018       , l_array_reference_num_1
180019       , l_array_reference_num_2
180020       , l_array_reference_num_3
180021       , l_array_reference_num_4
180022       , l_array_reference_char_1
180023       , l_array_reference_char_2
180024       , l_array_reference_char_3
180025       , l_array_reference_char_4
180026       , l_array_reference_date_1
180030       , l_array_event_created_by
180027       , l_array_reference_date_2
180028       , l_array_reference_date_3
180029       , l_array_reference_date_4
180031       , l_array_budgetary_control_flag
180032       , l_array_extract_line_num 
180033       , l_array_source_2
180034       , l_array_source_3
180035       , l_array_source_4
180036       , l_array_source_6
180037       , l_array_source_8
180038       , l_array_source_9
180039       , l_array_source_10
180040       , l_array_source_17
180041       , l_array_source_29
180042       , l_array_source_35
180043       , l_array_source_36
180044       , l_array_source_37
180045       , l_array_source_38
180046       , l_array_source_39
180047       , l_array_source_40
180048       LIMIT l_rows;
180049 
180050   --
180051   IF (C_LEVEL_EVENT >= g_log_level) THEN
180052             trace
180053                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
180054                ,p_level    => C_LEVEL_EVENT
180055                ,p_module   => l_log_module);
180056   END IF;
180057   --
180058   EXIT WHEN l_array_entity_id.count = 0;
180059 
180060   XLA_AE_LINES_PKG.g_rec_lines := null;
180061 
180062 --
180063 -- Bug 4458708
180064 --
180065 XLA_AE_LINES_PKG.g_LineNumber := 0;
180066 --
180067 --
180068 
180069 FOR Idx IN 1..l_array_event_id.count LOOP
180070    --
180071    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
180072    --
180073    l_event_id := l_array_event_id(idx);  -- 5648433
180074 
180075    --
180076    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
180077    --
180078 
180079    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
180080              (g_array_event(l_event_id).array_value_num('header_index'))
180081          ,'N'
180082          ) <> 'Y'
180083    THEN
180084       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
180085          trace
180086             (p_msg      => 'Trancaction revesal option is not Y '
180087             ,p_level    => C_LEVEL_STATEMENT
180088             ,p_module   => l_log_module);
180089       END IF;
180090 
180091 --
180092 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
180093 --
180094 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
180095 --
180096 -- set event info as cache for other routines to refer event attributes
180097 --
180098 
180099 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
180100    l_previous_event_id := l_event_id;
180101 
180102    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
180103       (p_application_id           => p_application_id
180104       ,p_primary_ledger_id        => p_primary_ledger_id
180105       ,p_base_ledger_id           => p_base_ledger_id
180106       ,p_target_ledger_id         => p_target_ledger_id
180107       ,p_entity_id                => l_array_entity_id(Idx)
180108       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
180109       ,p_entity_code              => l_array_entity_code(Idx)
180110       ,p_transaction_num          => l_array_transaction_num(Idx)
180111       ,p_event_id                 => l_array_event_id(Idx)
180112       ,p_event_class_code         => l_array_class_code(Idx)
180113       ,p_event_type_code          => l_array_event_type(Idx)
180114       ,p_event_number             => l_array_event_number(Idx)
180115       ,p_event_date               => l_array_event_date(Idx)
180116       ,p_transaction_date         => l_array_transaction_date(Idx)
180117       ,p_reference_num_1          => l_array_reference_num_1(Idx)
180118       ,p_reference_num_2          => l_array_reference_num_2(Idx)
180119       ,p_reference_num_3          => l_array_reference_num_3(Idx)
180120       ,p_reference_num_4          => l_array_reference_num_4(Idx)
180121       ,p_reference_char_1         => l_array_reference_char_1(Idx)
180122       ,p_reference_char_2         => l_array_reference_char_2(Idx)
180123       ,p_reference_char_3         => l_array_reference_char_3(Idx)
180124       ,p_reference_char_4         => l_array_reference_char_4(Idx)
180125       ,p_reference_date_1         => l_array_reference_date_1(Idx)
180126       ,p_reference_date_2         => l_array_reference_date_2(Idx)
180127       ,p_reference_date_3         => l_array_reference_date_3(Idx)
180128       ,p_reference_date_4         => l_array_reference_date_4(Idx)
180129       ,p_event_created_by         => l_array_event_created_by(Idx)
180130       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
180131        --
180132 END IF;
180133 
180134 
180135 
180136 --
180137 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
180138 
180139 l_acct_reversal_source := SUBSTR(NULL, 1,30);
180140 
180141 IF l_continue_with_lines THEN
180142    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
180143       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
180144 
180145       xla_accounting_err_pkg.build_message
180146          (p_appli_s_name            => 'XLA'
180147          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
180148          ,p_token_1                 => 'LINE_NUMBER'
180149          ,p_value_1                 => l_array_extract_line_num(Idx)
180150          ,p_token_2                 => 'PRODUCT_NAME'
180151          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
180152          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
180153          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
180154          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
180155 
180156    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
180157       --
180158       -- following sets the accounting attributes needed to reverse
180159       -- accounting for a distributeion
180160       --
180164       --
180161 
180162       --
180163       -- 5217187
180165       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
180166       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
180167                                        g_array_event(l_event_id).array_value_num('header_index'));
180168       --
180169       --
180170 
180171       -- No reversal code generated
180172 
180173       xla_ae_lines_pkg.SetAcctReversalAttrs
180174          (p_event_id             => l_event_id
180175          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
180176          ,p_calculate_acctd_flag => l_calculate_acctd_flag
180177          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
180178    END IF;
180179 
180180    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
180181        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
180182 
180183 --
180184 AcctLineType_181 (
180185  p_application_id  => p_application_id
180186  ,p_event_id     => l_event_id
180187  ,p_calculate_acctd_flag => l_calculate_acctd_flag
180188  ,p_calculate_g_l_flag => l_calculate_g_l_flag
180189  ,p_actual_flag => l_actual_flag
180190  ,p_balance_type_code => l_balance_type_code
180191  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
180192  
180193  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
180194  , p_source_2 => l_array_source_2(Idx)
180195  , p_source_3 => l_array_source_3(Idx)
180196  , p_source_29 => l_array_source_29(Idx)
180197  , p_source_35 => l_array_source_35(Idx)
180198  , p_source_36 => l_array_source_36(Idx)
180199  , p_source_37 => l_array_source_37(Idx)
180200  , p_source_38 => l_array_source_38(Idx)
180201  , p_source_39 => l_array_source_39(Idx)
180202  , p_source_40 => l_array_source_40(Idx)
180203  );
180204 If(l_balance_type_code = 'A') THEN
180205   l_actual_gain_loss_ref := l_gain_or_loss_ref;
180206 END IF;
180207 
180208 --
180209 
180210 
180211 --
180212 AcctLineType_182 (
180213  p_application_id  => p_application_id
180214  ,p_event_id     => l_event_id
180215  ,p_calculate_acctd_flag => l_calculate_acctd_flag
180216  ,p_calculate_g_l_flag => l_calculate_g_l_flag
180217  ,p_actual_flag => l_actual_flag
180218  ,p_balance_type_code => l_balance_type_code
180219  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
180220  
180221  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
180222  , p_source_3 => l_array_source_3(Idx)
180223  , p_source_4 => l_array_source_4(Idx)
180224  , p_source_17 => l_array_source_17(Idx)
180225  , p_source_29 => l_array_source_29(Idx)
180226  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
180227  , p_source_35 => l_array_source_35(Idx)
180228  , p_source_36 => l_array_source_36(Idx)
180229  , p_source_37 => l_array_source_37(Idx)
180230  , p_source_38 => l_array_source_38(Idx)
180231  , p_source_39 => l_array_source_39(Idx)
180232  , p_source_40 => l_array_source_40(Idx)
180233  );
180234 If(l_balance_type_code = 'A') THEN
180235   l_actual_gain_loss_ref := l_gain_or_loss_ref;
180236 END IF;
180237 
180238 --
180239 
180240 
180241 --
180242 AcctLineType_183 (
180243  p_application_id  => p_application_id
180244  ,p_event_id     => l_event_id
180245  ,p_calculate_acctd_flag => l_calculate_acctd_flag
180246  ,p_calculate_g_l_flag => l_calculate_g_l_flag
180247  ,p_actual_flag => l_actual_flag
180248  ,p_balance_type_code => l_balance_type_code
180249  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
180250  
180251  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
180252  , p_source_3 => l_array_source_3(Idx)
180253  , p_source_9 => l_array_source_9(Idx)
180254  , p_source_29 => l_array_source_29(Idx)
180255  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
180256  , p_source_35 => l_array_source_35(Idx)
180257  , p_source_36 => l_array_source_36(Idx)
180258  , p_source_37 => l_array_source_37(Idx)
180259  , p_source_38 => l_array_source_38(Idx)
180260  , p_source_39 => l_array_source_39(Idx)
180261  , p_source_40 => l_array_source_40(Idx)
180262  );
180263 If(l_balance_type_code = 'A') THEN
180264   l_actual_gain_loss_ref := l_gain_or_loss_ref;
180265 END IF;
180266 
180267 --
180268 
180269 
180270 --
180271 AcctLineType_184 (
180272  p_application_id  => p_application_id
180273  ,p_event_id     => l_event_id
180274  ,p_calculate_acctd_flag => l_calculate_acctd_flag
180275  ,p_calculate_g_l_flag => l_calculate_g_l_flag
180276  ,p_actual_flag => l_actual_flag
180277  ,p_balance_type_code => l_balance_type_code
180278  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
180279  
180280  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
180281  , p_source_3 => l_array_source_3(Idx)
180282  , p_source_6 => l_array_source_6(Idx)
180283  , p_source_8 => l_array_source_8(Idx)
180284  , p_source_29 => l_array_source_29(Idx)
180285  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
180286  , p_source_35 => l_array_source_35(Idx)
180287  , p_source_36 => l_array_source_36(Idx)
180288  , p_source_37 => l_array_source_37(Idx)
180289  , p_source_38 => l_array_source_38(Idx)
180290  , p_source_39 => l_array_source_39(Idx)
180291  , p_source_40 => l_array_source_40(Idx)
180292  );
180293 If(l_balance_type_code = 'A') THEN
180294   l_actual_gain_loss_ref := l_gain_or_loss_ref;
180295 END IF;
180296 
180297 --
180298 
180299 
180300 --
180301 AcctLineType_185 (
180302  p_application_id  => p_application_id
180303  ,p_event_id     => l_event_id
180304  ,p_calculate_acctd_flag => l_calculate_acctd_flag
180305  ,p_calculate_g_l_flag => l_calculate_g_l_flag
180306  ,p_actual_flag => l_actual_flag
180307  ,p_balance_type_code => l_balance_type_code
180308  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
180309  
180310  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
180314  , p_source_36 => l_array_source_36(Idx)
180311  , p_source_3 => l_array_source_3(Idx)
180312  , p_source_29 => l_array_source_29(Idx)
180313  , p_source_35 => l_array_source_35(Idx)
180315  , p_source_37 => l_array_source_37(Idx)
180316  , p_source_38 => l_array_source_38(Idx)
180317  , p_source_39 => l_array_source_39(Idx)
180318  , p_source_40 => l_array_source_40(Idx)
180319  );
180320 If(l_balance_type_code = 'A') THEN
180321   l_actual_gain_loss_ref := l_gain_or_loss_ref;
180322 END IF;
180323 
180324 --
180325 
180326 
180327 --
180328 AcctLineType_186 (
180329  p_application_id  => p_application_id
180330  ,p_event_id     => l_event_id
180331  ,p_calculate_acctd_flag => l_calculate_acctd_flag
180332  ,p_calculate_g_l_flag => l_calculate_g_l_flag
180333  ,p_actual_flag => l_actual_flag
180334  ,p_balance_type_code => l_balance_type_code
180335  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
180336  
180337  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
180338  , p_source_3 => l_array_source_3(Idx)
180339  , p_source_29 => l_array_source_29(Idx)
180340  , p_source_35 => l_array_source_35(Idx)
180341  , p_source_36 => l_array_source_36(Idx)
180342  , p_source_37 => l_array_source_37(Idx)
180343  , p_source_38 => l_array_source_38(Idx)
180344  , p_source_39 => l_array_source_39(Idx)
180345  , p_source_40 => l_array_source_40(Idx)
180346  );
180347 If(l_balance_type_code = 'A') THEN
180348   l_actual_gain_loss_ref := l_gain_or_loss_ref;
180349 END IF;
180350 
180351 --
180352 
180353 
180354 --
180355 AcctLineType_187 (
180356  p_application_id  => p_application_id
180357  ,p_event_id     => l_event_id
180358  ,p_calculate_acctd_flag => l_calculate_acctd_flag
180359  ,p_calculate_g_l_flag => l_calculate_g_l_flag
180360  ,p_actual_flag => l_actual_flag
180361  ,p_balance_type_code => l_balance_type_code
180362  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
180363  
180364  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
180365  , p_source_3 => l_array_source_3(Idx)
180366  , p_source_10 => l_array_source_10(Idx)
180367  , p_source_17 => l_array_source_17(Idx)
180368  , p_source_29 => l_array_source_29(Idx)
180369  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
180370  , p_source_35 => l_array_source_35(Idx)
180371  , p_source_36 => l_array_source_36(Idx)
180372  , p_source_37 => l_array_source_37(Idx)
180373  , p_source_38 => l_array_source_38(Idx)
180374  , p_source_39 => l_array_source_39(Idx)
180375  , p_source_40 => l_array_source_40(Idx)
180376  );
180377 If(l_balance_type_code = 'A') THEN
180378   l_actual_gain_loss_ref := l_gain_or_loss_ref;
180379 END IF;
180380 
180381 --
180382 
180383 
180384 --
180385 AcctLineType_188 (
180386  p_application_id  => p_application_id
180387  ,p_event_id     => l_event_id
180388  ,p_calculate_acctd_flag => l_calculate_acctd_flag
180389  ,p_calculate_g_l_flag => l_calculate_g_l_flag
180390  ,p_actual_flag => l_actual_flag
180391  ,p_balance_type_code => l_balance_type_code
180392  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
180393  
180394  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
180395  , p_source_3 => l_array_source_3(Idx)
180396  , p_source_10 => l_array_source_10(Idx)
180397  , p_source_17 => l_array_source_17(Idx)
180398  , p_source_29 => l_array_source_29(Idx)
180399  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
180400  , p_source_35 => l_array_source_35(Idx)
180401  , p_source_36 => l_array_source_36(Idx)
180402  , p_source_37 => l_array_source_37(Idx)
180403  , p_source_38 => l_array_source_38(Idx)
180404  , p_source_39 => l_array_source_39(Idx)
180405  , p_source_40 => l_array_source_40(Idx)
180406  );
180407 If(l_balance_type_code = 'A') THEN
180408   l_actual_gain_loss_ref := l_gain_or_loss_ref;
180409 END IF;
180410 
180411 --
180412 
180413       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
180414       -- or secondary ledger that has different currency with primary
180415       -- or alc that is calculated by sla
180416       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
180417             (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'))
180418 
180419 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
180420 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
180421           AND (l_actual_flag = 'A')) THEN
180422         XLA_AE_LINES_PKG.CreateGainOrLossLines(
180423           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
180424          ,p_application_id   => p_application_id
180425          ,p_amb_context_code => 'DEFAULT'
180426          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
180427          ,p_event_class_code => C_EVENT_CLASS_CODE
180428          ,p_event_type_code  => C_EVENT_TYPE_CODE
180429          
180430          ,p_gain_ccid        => -1
180431          ,p_loss_ccid        => -1
180432 
180433          ,p_actual_flag      => l_actual_flag
180434          ,p_enc_flag         => null
180435          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
180436          ,p_enc_g_l_ref      => null
180437          );
180438       END IF;
180439    END IF;
180440 END IF;
180441 
180442    ELSE
180443       --
180444       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
180445       --
180446       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
180447          trace
180448             (p_msg      => 'Trancaction revesal option is Y'
180449             ,p_level    => C_LEVEL_STATEMENT
180450             ,p_module   => l_log_module);
180451       END IF;
180452    END IF;
180453 
180454 END LOOP;
180458 
180455 l_result := XLA_AE_LINES_PKG.InsertLines ;
180456 end loop;
180457 close line_cur;
180459 
180460 --
180461 -- insert headers into xla_ae_headers_gt table
180462 --
180463 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
180464 
180465 -- insert into errors table here.
180466 
180467 END LOOP;
180468 
180469 --
180470 -- 4865292
180471 --
180472 -- Compare g_hdr_extract_count with event count in
180473 -- CreateHeadersAndLines.
180474 --
180475 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
180476 
180477 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
180478    trace (p_msg     => '# rows extracted from header extract objects '
180479                     || ' (running total): '
180480                     || g_hdr_extract_count
180481          ,p_level   => C_LEVEL_STATEMENT
180482          ,p_module  => l_log_module);
180483 END IF;
180484 
180485 CLOSE header_cur;
180486 --
180487 
180488 --
180489 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
180490    trace
180491       (p_msg      => 'END of EventClass_407'
180492       ,p_level    => C_LEVEL_PROCEDURE
180493       ,p_module   => l_log_module);
180494 END IF;
180495 --
180496 RETURN l_result;
180497 EXCEPTION
180498 WHEN xla_exceptions_pkg.application_exception THEN
180499    
180500 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
180501 
180502    
180503 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
180504 
180505    RAISE;
180506 
180507 WHEN NO_DATA_FOUND THEN
180508 
180509 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
180510 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
180511 
180512 FOR header_record IN header_cur
180513 LOOP
180514     l_array_header_events(header_record.event_id) := header_record.event_id;
180515 END LOOP;
180516 
180517 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
180518 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
180519 
180520 fnd_file.put_line(fnd_file.LOG, '                    ');
180521 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
180522 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
180523 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
180524 
180525 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
180526 LOOP
180527 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
180528 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
180529         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
180530 	END IF;
180531 END LOOP;
180532 
180533 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
180534 fnd_file.put_line(fnd_file.LOG, '                    ');
180535 
180536 
180537 xla_exceptions_pkg.raise_message
180538       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_407');
180539 
180540 
180541 WHEN OTHERS THEN
180542    xla_exceptions_pkg.raise_message
180543       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_407');
180544 END EventClass_407;
180545 --
180546 
180547 ---------------------------------------
180548 --
180549 -- PRIVATE PROCEDURE
180550 --         insert_sources_408
180551 --
180552 ----------------------------------------
180553 --
180554 PROCEDURE insert_sources_408(
180555                                 p_target_ledger_id       IN NUMBER
180556                               , p_language               IN VARCHAR2
180557                               , p_sla_ledger_id          IN NUMBER
180558                               , p_pad_start_date         IN DATE
180559                               , p_pad_end_date           IN DATE
180560                          )
180561 IS
180562 
180563 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'ADJUSTMENTS_ALL';
180564 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'ADJUSTMENTS';
180565 p_apps_owner                   VARCHAR2(30);
180566 l_log_module                   VARCHAR2(240);
180567 BEGIN
180568 IF g_log_enabled THEN
180569       l_log_module := C_DEFAULT_MODULE||'.insert_sources_408';
180570 END IF;
180571 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
180572 
180573       trace
180574          (p_msg      => 'BEGIN of insert_sources_408'
180575          ,p_level    => C_LEVEL_PROCEDURE
180576          ,p_module   => l_log_module);
180577 
180578 END IF;
180579 
180580 -- select APPS owner
180581 SELECT oracle_username
180582   INTO p_apps_owner
180583   FROM fnd_oracle_userid
180584  WHERE read_only_flag = 'U'
180585 ;
180586 
180587 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
180588       trace
180589          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
180590                         ' - p_language = '||p_language||
180591                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
180592                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
180593                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
180594                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
180595          ,p_level    => C_LEVEL_STATEMENT
180596          ,p_module   => l_log_module);
180597 END IF;
180598 
180599 
180600 --
180601 INSERT INTO xla_diag_sources --hdr2
180602 (
180603         event_id
180604       , ledger_id
180605       , sla_ledger_id
180606       , description_language
180607       , object_name
180608       , object_type_code
180609       , line_number
180610       , source_application_id
180611       , source_type_code
180612       , source_code
180613       , source_value
180614       , source_meaning
180615       , created_by
180619       , last_update_login
180616       , creation_date
180617       , last_update_date
180618       , last_updated_by
180620       , program_update_date
180621       , program_application_id
180622       , program_id
180623       , request_id
180624 )
180625 SELECT
180626         event_id
180627       , p_target_ledger_id
180628       , p_sla_ledger_id
180629       , p_language
180630       , object_name
180631       , object_type_code
180632       , line_number
180633       , source_application_id
180634       , source_type_code
180635       , source_code
180636       , SUBSTR(source_value ,1,1996)
180637       , SUBSTR(source_meaning ,1,200)
180638       , xla_environment_pkg.g_Usr_Id
180639       , TRUNC(SYSDATE)
180640       , TRUNC(SYSDATE)
180641       , xla_environment_pkg.g_Usr_Id
180642       , xla_environment_pkg.g_Login_Id
180643       , TRUNC(SYSDATE)
180644       , xla_environment_pkg.g_Prog_Appl_Id
180645       , xla_environment_pkg.g_Prog_Id
180646       , xla_environment_pkg.g_Req_Id
180647   FROM (
180648        SELECT xet.event_id                  event_id
180649             , 0                          line_number
180650             , CASE r
180651                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
180652                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
180653                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
180654                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
180655                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
180656                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
180657                 
180658                ELSE null
180659               END                           object_name
180660             , CASE r
180661                 WHEN 1 THEN 'HEADER' 
180662                 WHEN 2 THEN 'HEADER' 
180663                 WHEN 3 THEN 'HEADER' 
180664                 WHEN 4 THEN 'HEADER' 
180665                 WHEN 5 THEN 'HEADER' 
180666                 WHEN 6 THEN 'HEADER' 
180667                 
180668                 ELSE null
180669               END                           object_type_code
180670             , CASE r
180671                 WHEN 1 THEN '140' 
180672                 WHEN 2 THEN '140' 
180673                 WHEN 3 THEN '140' 
180674                 WHEN 4 THEN '140' 
180675                 WHEN 5 THEN '140' 
180676                 WHEN 6 THEN '140' 
180677                 
180678                 ELSE null
180679               END                           source_application_id
180680             , 'S'             source_type_code
180681             , CASE r
180682                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
180683                 WHEN 2 THEN 'AP_INTERCOMPANY_ACCT' 
180684                 WHEN 3 THEN 'AR_INTERCOMPANY_ACCT' 
180685                 WHEN 4 THEN 'DEFAULT_CCID' 
180686                 WHEN 5 THEN 'ACCOUNTING_DATE' 
180687                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
180688                 
180689                 ELSE null
180690               END                           source_code
180691             , CASE r
180692                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
180693                 WHEN 2 THEN TO_CHAR(h1.AP_INTERCOMPANY_ACCT)
180694                 WHEN 3 THEN TO_CHAR(h1.AR_INTERCOMPANY_ACCT)
180695                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
180696                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
180697                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
180698                 
180699                 ELSE null
180700               END                           source_value
180701             , null              source_meaning
180702          FROM xla_events_gt     xet  
180703       , FA_XLA_EXT_HEADERS_B_GT  h1
180704              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
180705          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
180706            AND xet.event_class_code = C_EVENT_CLASS_CODE
180707               AND h1.event_id = xet.event_id
180708 
180709 )
180710 ;
180711 --
180712 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
180713 
180714       trace
180715          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
180716          ,p_level    => C_LEVEL_STATEMENT
180717          ,p_module   => l_log_module);
180718 
180719 END IF;
180720 --
180721 
180722 
180723 
180724 --
180725 INSERT INTO xla_diag_sources  --line2
180726 (
180727         event_id
180728       , ledger_id
180729       , sla_ledger_id
180730       , description_language
180731       , object_name
180732       , object_type_code
180733       , line_number
180734       , source_application_id
180735       , source_type_code
180736       , source_code
180737       , source_value
180738       , source_meaning
180739       , created_by
180740       , creation_date
180741       , last_update_date
180742       , last_updated_by
180743       , last_update_login
180744       , program_update_date
180745       , program_application_id
180746       , program_id
180747       , request_id
180748 )
180749 SELECT  event_id
180750       , p_target_ledger_id
180751       , p_sla_ledger_id
180752       , p_language
180753       , object_name
180754       , object_type_code
180755       , line_number
180756       , source_application_id
180757       , source_type_code
180758       , source_code
180759       , SUBSTR(source_value,1,1996)
180760       , SUBSTR(source_meaning ,1,200)
180761       , xla_environment_pkg.g_Usr_Id
180762       , TRUNC(SYSDATE)
180763       , TRUNC(SYSDATE)
180764       , xla_environment_pkg.g_Usr_Id
180765       , xla_environment_pkg.g_Login_Id
180766       , TRUNC(SYSDATE)
180767       , xla_environment_pkg.g_Prog_Appl_Id
180768       , xla_environment_pkg.g_Prog_Id
180769       , xla_environment_pkg.g_Req_Id
180770   FROM (
180774                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
180771        SELECT xet.event_id                  event_id
180772             , l2.line_number                 line_number
180773             , CASE r
180775                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
180776                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
180777                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
180778                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
180779                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
180780                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
180781                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
180782                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
180783                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
180784                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
180785                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
180786                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
180787                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
180788                 WHEN 15 THEN 'FA_XLA_EXT_LINES_B_GT' 
180789                 
180790                ELSE null
180791               END                           object_name
180792             , CASE r
180793                 WHEN 1 THEN 'LINE' 
180794                 WHEN 2 THEN 'LINE' 
180795                 WHEN 3 THEN 'LINE' 
180796                 WHEN 4 THEN 'LINE' 
180797                 WHEN 5 THEN 'LINE' 
180798                 WHEN 6 THEN 'LINE' 
180799                 WHEN 7 THEN 'LINE' 
180800                 WHEN 8 THEN 'LINE' 
180801                 WHEN 9 THEN 'LINE' 
180802                 WHEN 10 THEN 'LINE' 
180803                 WHEN 11 THEN 'LINE' 
180804                 WHEN 12 THEN 'LINE' 
180805                 WHEN 13 THEN 'LINE' 
180806                 WHEN 14 THEN 'LINE' 
180807                 WHEN 15 THEN 'LINE' 
180808                 
180809                 ELSE null
180810               END                           object_type_code
180811             , CASE r
180812                 WHEN 1 THEN '140' 
180813                 WHEN 2 THEN '140' 
180814                 WHEN 3 THEN '140' 
180815                 WHEN 4 THEN '140' 
180816                 WHEN 5 THEN '140' 
180817                 WHEN 6 THEN '140' 
180818                 WHEN 7 THEN '140' 
180819                 WHEN 8 THEN '140' 
180820                 WHEN 9 THEN '140' 
180821                 WHEN 10 THEN '140' 
180822                 WHEN 11 THEN '140' 
180823                 WHEN 12 THEN '140' 
180824                 WHEN 13 THEN '140' 
180825                 WHEN 14 THEN '140' 
180826                 WHEN 15 THEN '140' 
180827                 
180828                 ELSE null
180829               END                           source_application_id
180830             , 'S'             source_type_code
180831             , CASE r
180832                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
180833                 WHEN 2 THEN 'GENERATED_CCID' 
180834                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
180835                 WHEN 4 THEN 'PAYABLES_CCID' 
180836                 WHEN 5 THEN 'ASSET_CLEARING_ACCT' 
180837                 WHEN 6 THEN 'ASSET_COST_ACCT' 
180838                 WHEN 7 THEN 'DEPRN_RESERVE_ACCT' 
180839                 WHEN 8 THEN 'GENERATED_OFFSET_CCID' 
180840                 WHEN 9 THEN 'EXPENSE_ACCOUNT_CCID' 
180841                 WHEN 10 THEN 'ADJUSTMENT_TYPE' 
180842                 WHEN 11 THEN 'TRANSACTION_HEADER_ID' 
180843                 WHEN 12 THEN 'ADJUSTMENT_LINE_ID' 
180844                 WHEN 13 THEN 'DISTRIBUTION_TYPE_CODE' 
180845                 WHEN 14 THEN 'ENTERED_AMOUNT' 
180846                 WHEN 15 THEN 'CURRENCY_CODE' 
180847                 
180848                 ELSE null
180849               END                           source_code
180850             , CASE r
180851                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
180852                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
180853                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
180854                 WHEN 4 THEN TO_CHAR(l2.PAYABLES_CCID)
180855                 WHEN 5 THEN TO_CHAR(l2.ASSET_CLEARING_ACCT)
180856                 WHEN 6 THEN TO_CHAR(l2.ASSET_COST_ACCT)
180857                 WHEN 7 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
180858                 WHEN 8 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
180859                 WHEN 9 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
180860                 WHEN 10 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
180861                 WHEN 11 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
180862                 WHEN 12 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
180863                 WHEN 13 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
180864                 WHEN 14 THEN TO_CHAR(l2.ENTERED_AMOUNT)
180865                 WHEN 15 THEN TO_CHAR(l2.CURRENCY_CODE)
180866                 
180867                 ELSE null
180868               END                           source_value
180869             , null              source_meaning
180870          FROM  xla_events_gt     xet  
180871         , FA_XLA_EXT_LINES_B_GT  l2
180872             , (select rownum r from all_objects where rownum <= 15 and owner = p_apps_owner)
180873         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
180874           AND xet.event_class_code = C_EVENT_CLASS_CODE
180875             AND l2.event_id          = xet.event_id
180876   AND l2.ledger_id (+)  = p_sla_ledger_id
180877 
180878 )
180879 ;
180880 --
180881 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
180882 
180883       trace
180884          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
180885          ,p_level    => C_LEVEL_STATEMENT
180886          ,p_module   => l_log_module);
180887 
180888 END IF;
180889 
180890 
180891 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
180892       trace
180893          (p_msg      => 'END of insert_sources_408'
180894          ,p_level    => C_LEVEL_PROCEDURE
180895          ,p_module   => l_log_module);
180896 END IF;
180897 EXCEPTION
180898   WHEN xla_exceptions_pkg.application_exception THEN
180902                ,p_level    => C_LEVEL_EXCEPTION
180899       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
180900             trace
180901                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
180903                ,p_module   => l_log_module);
180904       END IF;
180905       RAISE;
180906   WHEN OTHERS THEN
180907       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
180908             trace
180909                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
180910                ,p_level    => C_LEVEL_EXCEPTION
180911                ,p_module   => l_log_module);
180912        END IF;
180913        xla_exceptions_pkg.raise_message
180914            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_408');
180915 END insert_sources_408;
180916 --
180917 
180918 ---------------------------------------
180919 --
180920 -- PRIVATE FUNCTION
180921 --         EventClass_408
180922 --
180923 ----------------------------------------
180924 --
180925 FUNCTION EventClass_408
180926        (p_application_id         IN NUMBER
180927        ,p_base_ledger_id         IN NUMBER
180928        ,p_target_ledger_id       IN NUMBER
180929        ,p_language               IN VARCHAR2
180930        ,p_currency_code          IN VARCHAR2
180931        ,p_sla_ledger_id          IN NUMBER
180932        ,p_pad_start_date         IN DATE
180933        ,p_pad_end_date           IN DATE
180934        ,p_primary_ledger_id      IN NUMBER)
180935 RETURN BOOLEAN IS
180936 --
180937 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'ADJUSTMENTS_ALL';
180938 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'ADJUSTMENTS';
180939 
180940 l_calculate_acctd_flag   VARCHAR2(1) :='N';
180941 l_calculate_g_l_flag     VARCHAR2(1) :='N';
180942 --
180943 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
180944 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
180945 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
180946 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
180947 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
180948 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
180949 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
180950 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
180951 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
180952 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
180953 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
180954 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
180955 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
180956 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
180957 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
180958 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
180959 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
180960 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
180961 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
180962 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
180963 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
180964 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
180965 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
180966 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
180967 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
180968 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
180969 
180970 l_event_id                             NUMBER;
180971 l_previous_event_id                    NUMBER;
180972 l_first_event_id                       NUMBER;
180973 l_last_event_id                        NUMBER;
180974 
180975 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
180976 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
180977 --
180978 --
180979 l_result                    BOOLEAN := TRUE;
180980 l_rows                      NUMBER  := 1000;
180981 l_event_type_name           VARCHAR2(80) := 'All';
180982 l_event_class_name          VARCHAR2(80) := 'Adjustments';
180983 l_description               VARCHAR2(4000);
180984 l_transaction_reversal      NUMBER;
180985 l_ae_header_id              NUMBER;
180986 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
180987 l_log_module                VARCHAR2(240);
180988 --
180989 l_acct_reversal_source      VARCHAR2(30);
180990 l_trx_reversal_source       VARCHAR2(30);
180991 
180992 l_continue_with_lines       BOOLEAN := TRUE;
180993 --
180994 l_acc_rev_gl_date_source    DATE;                      -- 4262811
180995 --
180996 type t_array_event_id is table of number index by binary_integer;
180997 
180998 l_rec_array_event                    t_rec_array_event;
180999 l_null_rec_array_event               t_rec_array_event;
181000 l_array_ae_header_id                 xla_number_array_type;
181001 l_actual_flag                        VARCHAR2(1) := NULL;
181002 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
181003 l_balance_type_code                  VARCHAR2(1) :=NULL;
181004 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
181005 
181006 --
181007 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
181008 --
181009 
181010 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
181011 TYPE t_array_source_19 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AP_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
181012 TYPE t_array_source_20 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AR_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
181016 
181013 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
181014 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
181015 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
181017 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
181018 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
181019 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
181020 TYPE t_array_source_6 IS TABLE OF FA_XLA_EXT_LINES_B_GT.PAYABLES_CCID%TYPE INDEX BY BINARY_INTEGER;
181021 TYPE t_array_source_8 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
181022 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
181023 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
181024 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
181025 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
181026 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
181027 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
181028 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
181029 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
181030 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
181031 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
181032 
181033 l_array_source_1              t_array_source_1;
181034 l_array_source_19              t_array_source_19;
181035 l_array_source_20              t_array_source_20;
181036 l_array_source_30              t_array_source_30;
181037 l_array_source_51              t_array_source_51;
181038 l_array_source_52              t_array_source_52;
181039 
181040 l_array_source_2      t_array_source_2;
181041 l_array_source_3      t_array_source_3;
181042 l_array_source_4      t_array_source_4;
181043 l_array_source_6      t_array_source_6;
181044 l_array_source_8      t_array_source_8;
181045 l_array_source_9      t_array_source_9;
181046 l_array_source_10      t_array_source_10;
181047 l_array_source_17      t_array_source_17;
181048 l_array_source_29      t_array_source_29;
181049 l_array_source_35      t_array_source_35;
181050 l_array_source_36      t_array_source_36;
181051 l_array_source_37      t_array_source_37;
181052 l_array_source_38      t_array_source_38;
181053 l_array_source_39      t_array_source_39;
181054 l_array_source_40      t_array_source_40;
181055 
181056 --
181057 CURSOR header_cur
181058 IS
181059 SELECT /*+ leading(xet) cardinality(xet,1) */
181060 -- Event Class Code: ADJUSTMENTS
181061     xet.entity_id
181062    ,xet.legal_entity_id
181063    ,xet.entity_code
181064    ,xet.transaction_number
181065    ,xet.event_id
181066    ,xet.event_class_code
181067    ,xet.event_type_code
181068    ,xet.event_number
181069    ,xet.event_date
181070    ,xet.transaction_date
181071    ,xet.reference_num_1
181072    ,xet.reference_num_2
181073    ,xet.reference_num_3
181074    ,xet.reference_num_4
181075    ,xet.reference_char_1
181076    ,xet.reference_char_2
181077    ,xet.reference_char_3
181078    ,xet.reference_char_4
181079    ,xet.reference_date_1
181080    ,xet.reference_date_2
181081    ,xet.reference_date_3
181082    ,xet.reference_date_4
181083    ,xet.event_created_by
181084    ,xet.budgetary_control_flag 
181085   , h1.PERIOD_CLOSE_DATE    source_1
181086   , h1.AP_INTERCOMPANY_ACCT    source_19
181087   , h1.AR_INTERCOMPANY_ACCT    source_20
181088   , h1.DEFAULT_CCID    source_30
181089   , h1.ACCOUNTING_DATE    source_51
181090   , h1.TRANSFER_TO_GL_FLAG    source_52
181091   FROM xla_events_gt     xet 
181092   , FA_XLA_EXT_HEADERS_B_GT  h1
181093  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
181094    and xet.event_class_code = C_EVENT_CLASS_CODE
181095    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
181096 
181097  ORDER BY event_id
181098 ;
181099 
181100 
181101 --
181102 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
181103 IS
181104 SELECT  /*+ leading(xet) cardinality(xet,1) */
181105 -- Event Class Code: ADJUSTMENTS
181106     xet.entity_id
181107    ,xet.legal_entity_id
181108    ,xet.entity_code
181109    ,xet.transaction_number
181110    ,xet.event_id
181111    ,xet.event_class_code
181112    ,xet.event_type_code
181113    ,xet.event_number
181114    ,xet.event_date
181115    ,xet.transaction_date
181116    ,xet.reference_num_1
181117    ,xet.reference_num_2
181118    ,xet.reference_num_3
181119    ,xet.reference_num_4
181120    ,xet.reference_char_1
181121    ,xet.reference_char_2
181122    ,xet.reference_char_3
181123    ,xet.reference_char_4
181124    ,xet.reference_date_1
181125    ,xet.reference_date_2
181126    ,xet.reference_date_3
181127    ,xet.reference_date_4
181128    ,xet.event_created_by
181129    ,xet.budgetary_control_flag
181130  , l2.LINE_NUMBER  
181131   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
181132   , l2.GENERATED_CCID    source_3
181133   , l2.BONUS_RESERVE_ACCT    source_4
181134   , l2.PAYABLES_CCID    source_6
181135   , l2.ASSET_CLEARING_ACCT    source_8
181136   , l2.ASSET_COST_ACCT    source_9
181137   , l2.DEPRN_RESERVE_ACCT    source_10
181138   , l2.GENERATED_OFFSET_CCID    source_17
181139   , l2.EXPENSE_ACCOUNT_CCID    source_29
181140   , l2.ADJUSTMENT_TYPE    source_35
181141   , l2.TRANSACTION_HEADER_ID    source_36
181142   , l2.ADJUSTMENT_LINE_ID    source_37
181146   FROM xla_events_gt     xet 
181143   , l2.DISTRIBUTION_TYPE_CODE    source_38
181144   , l2.ENTERED_AMOUNT    source_39
181145   , l2.CURRENCY_CODE    source_40
181147   , FA_XLA_EXT_LINES_B_GT  l2
181148  WHERE xet.event_id between x_first_event_id and x_last_event_id
181149    and xet.event_date between p_pad_start_date and p_pad_end_date
181150    and xet.event_class_code = C_EVENT_CLASS_CODE
181151    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
181152   AND l2.ledger_id = p_sla_ledger_id
181153 ;
181154 
181155 --
181156 BEGIN
181157 IF g_log_enabled THEN
181158    l_log_module := C_DEFAULT_MODULE||'.EventClass_408';
181159 END IF;
181160 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
181161    trace
181162       (p_msg      => 'BEGIN of EventClass_408'
181163       ,p_level    => C_LEVEL_PROCEDURE
181164       ,p_module   => l_log_module);
181165 END IF;
181166 
181167 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
181168    trace
181169       (p_msg      => 'p_application_id = '||p_application_id||
181170                      ' - p_base_ledger_id = '||p_base_ledger_id||
181171                      ' - p_target_ledger_id  = '||p_target_ledger_id||
181172                      ' - p_language = '||p_language||
181173                      ' - p_currency_code = '||p_currency_code||
181174                      ' - p_sla_ledger_id = '||p_sla_ledger_id
181175       ,p_level    => C_LEVEL_STATEMENT
181176       ,p_module   => l_log_module);
181177 END IF;
181178 --
181179 -- initialze arrays
181180 --
181181 g_array_event.DELETE;
181182 l_rec_array_event := l_null_rec_array_event;
181183 --
181184 --------------------------------------
181185 -- 4262811 Initialze MPA Line Number
181186 --------------------------------------
181187 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
181188 
181189 --
181190 
181191 --
181192 OPEN header_cur;
181193 --
181194 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
181195    trace
181196    (p_msg      => 'SQL - FETCH header_cur'
181197    ,p_level    => C_LEVEL_STATEMENT
181198    ,p_module   => l_log_module);
181199 END IF;
181200 --
181201 LOOP
181202 FETCH header_cur BULK COLLECT INTO
181203         l_array_entity_id
181204       , l_array_legal_entity_id
181205       , l_array_entity_code
181206       , l_array_transaction_num
181207       , l_array_event_id
181208       , l_array_class_code
181209       , l_array_event_type
181210       , l_array_event_number
181211       , l_array_event_date
181212       , l_array_transaction_date
181213       , l_array_reference_num_1
181214       , l_array_reference_num_2
181215       , l_array_reference_num_3
181216       , l_array_reference_num_4
181217       , l_array_reference_char_1
181218       , l_array_reference_char_2
181219       , l_array_reference_char_3
181220       , l_array_reference_char_4
181221       , l_array_reference_date_1
181222       , l_array_reference_date_2
181223       , l_array_reference_date_3
181224       , l_array_reference_date_4
181225       , l_array_event_created_by
181226       , l_array_budgetary_control_flag 
181227       , l_array_source_1
181228       , l_array_source_19
181229       , l_array_source_20
181230       , l_array_source_30
181231       , l_array_source_51
181232       , l_array_source_52
181233       LIMIT l_rows;
181234 --
181235 IF (C_LEVEL_EVENT >= g_log_level) THEN
181236    trace
181237    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
181238    ,p_level    => C_LEVEL_EVENT
181239    ,p_module   => l_log_module);
181240 END IF;
181241 --
181242 EXIT WHEN l_array_entity_id.COUNT = 0;
181243 
181244 -- initialize arrays
181245 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
181246 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
181247 
181248 --
181249 -- Bug 4458708
181250 --
181251 XLA_AE_LINES_PKG.g_LineNumber := 0;
181252 
181253 
181254 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
181255 g_last_hdr_idx := l_array_event_id.LAST;
181256 --
181257 -- loop for the headers. Each iteration is for each header extract row
181258 -- fetched in header cursor
181259 --
181260 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
181261 
181262 --
181263 -- set event info as cache for other routines to refer event attributes
181264 --
181265 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
181266    (p_application_id           => p_application_id
181267    ,p_primary_ledger_id        => p_primary_ledger_id
181268    ,p_base_ledger_id           => p_base_ledger_id
181269    ,p_target_ledger_id         => p_target_ledger_id
181270    ,p_entity_id                => l_array_entity_id(hdr_idx)
181271    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
181272    ,p_entity_code              => l_array_entity_code(hdr_idx)
181273    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
181274    ,p_event_id                 => l_array_event_id(hdr_idx)
181275    ,p_event_class_code         => l_array_class_code(hdr_idx)
181276    ,p_event_type_code          => l_array_event_type(hdr_idx)
181277    ,p_event_number             => l_array_event_number(hdr_idx)
181278    ,p_event_date               => l_array_event_date(hdr_idx)
181279    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
181280    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
181281    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
181282    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
181283    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
181284    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
181285    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
181286    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
181287    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
181291    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
181288    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
181289    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
181290    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
181292    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
181293    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
181294 
181295 --
181296 -- set the status of entry to C_VALID (0)
181297 --
181298 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
181299 
181300 --
181301 -- initialize a row for ae header
181302 --
181303 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
181304 
181305 l_event_id := l_array_event_id(hdr_idx);
181306 
181307 --
181308 -- storing the hdr_idx for event. May be used by line cursor.
181309 --
181310 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
181311 
181312 --
181313 -- store sources from header extract. This can be improved to
181314 -- store only those sources from header extract that may be used in lines
181315 --
181316 
181317 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
181318 g_array_event(l_event_id).array_value_char('source_19') := l_array_source_19(hdr_idx);
181319 g_array_event(l_event_id).array_value_char('source_20') := l_array_source_20(hdr_idx);
181320 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
181321 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
181322 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
181323 
181324 --
181325 -- initilaize the status of ae headers for diffrent balance types
181326 -- the status is initialised to C_NOT_CREATED (2)
181327 --
181328 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
181329 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
181330 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
181331 
181332 --
181333 -- call api to validate and store accounting attributes for header
181334 --
181335 
181336 ------------------------------------------------------------
181337 -- Accrual Reversal : to get date for Standard Source (NONE)
181338 ------------------------------------------------------------
181339 l_acc_rev_gl_date_source := NULL;
181340 
181341      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
181342       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
181343      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
181344       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
181345 
181346 
181347 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
181348 
181349 XLA_AE_HEADER_PKG.SetJeCategoryName;
181350 
181351 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
181352 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
181353 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
181354 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
181355 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
181356 
181357 
181358 -- No header level analytical criteria
181359 
181360 --
181361 --accounting attribute enhancement, bug 3612931
181362 --
181363 l_trx_reversal_source := SUBSTR(NULL, 1,30);
181364 
181365 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
181366    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
181367 
181368    xla_accounting_err_pkg.build_message
181369       (p_appli_s_name            => 'XLA'
181370       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
181371       ,p_token_1                 => 'ACCT_ATTR_NAME'
181372       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
181373       ,p_token_2                 => 'PRODUCT_NAME'
181374       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
181375       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
181376       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
181377       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
181378 
181379 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
181380    --
181381    -- following sets the accounting attributes needed to reverse
181382    -- accounting for a distributeion
181383    --
181384    xla_ae_lines_pkg.SetTrxReversalAttrs
181385       (p_event_id              => l_event_id
181386       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
181387       ,p_trx_reversal_source   => l_trx_reversal_source);
181388 
181389 END IF;
181390 
181391 
181392 ----------------------------------------------------------------
181393 -- 4262811 -  update the header statuses to invalid in need be
181394 ----------------------------------------------------------------
181395 --
181396 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
181397 
181398 
181399   -----------------------------------------------
181400   -- No accrual reversal for the event class/type
181401   -----------------------------------------------
181402 ----------------------------------------------------------------
181403 
181404 --
181405 -- this ends the header loop iteration for one bulk fetch
181406 --
181407 END LOOP;
181408 
181409 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
181410 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
181411 
181412 --
181416 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
181413 -- insert dummy rows into lines gt table that were created due to
181414 -- transaction reversals
181415 --
181417    l_result := XLA_AE_LINES_PKG.InsertLines;
181418 END IF;
181419 
181420 --
181421 -- reset the temp_line_num for each set of events fetched from header
181422 -- cursor rather than doing it for each new event in line cursor
181423 -- Bug 3939231
181424 --
181425 xla_ae_lines_pkg.g_temp_line_num := 0;
181426 
181427 
181428 
181429 --
181430 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
181431 --
181432 --
181433 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
181434 
181435       trace
181436          (p_msg      => 'SQL - FETCH line_cur'
181437          ,p_level    => C_LEVEL_STATEMENT
181438          ,p_module   => l_log_module);
181439 
181440 END IF;
181441 --
181442 --
181443 LOOP
181444   --
181445   FETCH line_cur BULK COLLECT INTO
181446         l_array_entity_id
181447       , l_array_legal_entity_id
181448       , l_array_entity_code
181449       , l_array_transaction_num
181450       , l_array_event_id
181451       , l_array_class_code
181452       , l_array_event_type
181453       , l_array_event_number
181454       , l_array_event_date
181455       , l_array_transaction_date
181456       , l_array_reference_num_1
181457       , l_array_reference_num_2
181458       , l_array_reference_num_3
181459       , l_array_reference_num_4
181460       , l_array_reference_char_1
181461       , l_array_reference_char_2
181462       , l_array_reference_char_3
181463       , l_array_reference_char_4
181464       , l_array_reference_date_1
181465       , l_array_reference_date_2
181466       , l_array_reference_date_3
181467       , l_array_reference_date_4
181468       , l_array_event_created_by
181469       , l_array_budgetary_control_flag
181470       , l_array_extract_line_num 
181471       , l_array_source_2
181472       , l_array_source_3
181473       , l_array_source_4
181474       , l_array_source_6
181475       , l_array_source_8
181476       , l_array_source_9
181477       , l_array_source_10
181478       , l_array_source_17
181479       , l_array_source_29
181480       , l_array_source_35
181481       , l_array_source_36
181482       , l_array_source_37
181483       , l_array_source_38
181484       , l_array_source_39
181485       , l_array_source_40
181486       LIMIT l_rows;
181487 
181488   --
181489   IF (C_LEVEL_EVENT >= g_log_level) THEN
181490             trace
181491                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
181492                ,p_level    => C_LEVEL_EVENT
181493                ,p_module   => l_log_module);
181494   END IF;
181495   --
181496   EXIT WHEN l_array_entity_id.count = 0;
181497 
181498   XLA_AE_LINES_PKG.g_rec_lines := null;
181499 
181500 --
181501 -- Bug 4458708
181502 --
181503 XLA_AE_LINES_PKG.g_LineNumber := 0;
181504 --
181505 --
181506 
181507 FOR Idx IN 1..l_array_event_id.count LOOP
181508    --
181509    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
181510    --
181511    l_event_id := l_array_event_id(idx);  -- 5648433
181512 
181513    --
181514    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
181515    --
181516 
181517    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
181518              (g_array_event(l_event_id).array_value_num('header_index'))
181519          ,'N'
181520          ) <> 'Y'
181521    THEN
181522       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
181523          trace
181524             (p_msg      => 'Trancaction revesal option is not Y '
181525             ,p_level    => C_LEVEL_STATEMENT
181526             ,p_module   => l_log_module);
181527       END IF;
181528 
181529 --
181530 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
181531 --
181532 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
181533 --
181534 -- set event info as cache for other routines to refer event attributes
181535 --
181536 
181537 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
181538    l_previous_event_id := l_event_id;
181539 
181540    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
181541       (p_application_id           => p_application_id
181542       ,p_primary_ledger_id        => p_primary_ledger_id
181543       ,p_base_ledger_id           => p_base_ledger_id
181544       ,p_target_ledger_id         => p_target_ledger_id
181545       ,p_entity_id                => l_array_entity_id(Idx)
181546       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
181547       ,p_entity_code              => l_array_entity_code(Idx)
181548       ,p_transaction_num          => l_array_transaction_num(Idx)
181549       ,p_event_id                 => l_array_event_id(Idx)
181550       ,p_event_class_code         => l_array_class_code(Idx)
181551       ,p_event_type_code          => l_array_event_type(Idx)
181552       ,p_event_number             => l_array_event_number(Idx)
181553       ,p_event_date               => l_array_event_date(Idx)
181554       ,p_transaction_date         => l_array_transaction_date(Idx)
181555       ,p_reference_num_1          => l_array_reference_num_1(Idx)
181556       ,p_reference_num_2          => l_array_reference_num_2(Idx)
181557       ,p_reference_num_3          => l_array_reference_num_3(Idx)
181558       ,p_reference_num_4          => l_array_reference_num_4(Idx)
181559       ,p_reference_char_1         => l_array_reference_char_1(Idx)
181560       ,p_reference_char_2         => l_array_reference_char_2(Idx)
181561       ,p_reference_char_3         => l_array_reference_char_3(Idx)
181562       ,p_reference_char_4         => l_array_reference_char_4(Idx)
181566       ,p_reference_date_4         => l_array_reference_date_4(Idx)
181563       ,p_reference_date_1         => l_array_reference_date_1(Idx)
181564       ,p_reference_date_2         => l_array_reference_date_2(Idx)
181565       ,p_reference_date_3         => l_array_reference_date_3(Idx)
181567       ,p_event_created_by         => l_array_event_created_by(Idx)
181568       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
181569        --
181570 END IF;
181571 
181572 
181573 
181574 --
181575 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
181576 
181577 l_acct_reversal_source := SUBSTR(NULL, 1,30);
181578 
181579 IF l_continue_with_lines THEN
181580    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
181581       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
181582 
181583       xla_accounting_err_pkg.build_message
181584          (p_appli_s_name            => 'XLA'
181585          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
181586          ,p_token_1                 => 'LINE_NUMBER'
181587          ,p_value_1                 => l_array_extract_line_num(Idx)
181588          ,p_token_2                 => 'PRODUCT_NAME'
181589          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
181590          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
181591          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
181592          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
181593 
181594    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
181595       --
181596       -- following sets the accounting attributes needed to reverse
181597       -- accounting for a distributeion
181598       --
181599 
181600       --
181601       -- 5217187
181602       --
181603       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
181604       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
181605                                        g_array_event(l_event_id).array_value_num('header_index'));
181606       --
181607       --
181608 
181609       -- No reversal code generated
181610 
181611       xla_ae_lines_pkg.SetAcctReversalAttrs
181612          (p_event_id             => l_event_id
181613          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
181614          ,p_calculate_acctd_flag => l_calculate_acctd_flag
181615          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
181616    END IF;
181617 
181618    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
181619        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
181620 
181621 --
181622 AcctLineType_189 (
181623  p_application_id  => p_application_id
181624  ,p_event_id     => l_event_id
181625  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181626  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181627  ,p_actual_flag => l_actual_flag
181628  ,p_balance_type_code => l_balance_type_code
181629  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181630  
181631  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181632  , p_source_2 => l_array_source_2(Idx)
181633  , p_source_3 => l_array_source_3(Idx)
181634  , p_source_29 => l_array_source_29(Idx)
181635  , p_source_35 => l_array_source_35(Idx)
181636  , p_source_36 => l_array_source_36(Idx)
181637  , p_source_37 => l_array_source_37(Idx)
181638  , p_source_38 => l_array_source_38(Idx)
181639  , p_source_39 => l_array_source_39(Idx)
181640  , p_source_40 => l_array_source_40(Idx)
181641  );
181642 If(l_balance_type_code = 'A') THEN
181643   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181644 END IF;
181645 
181646 --
181647 
181648 
181649 --
181650 AcctLineType_190 (
181651  p_application_id  => p_application_id
181652  ,p_event_id     => l_event_id
181653  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181654  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181655  ,p_actual_flag => l_actual_flag
181656  ,p_balance_type_code => l_balance_type_code
181657  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181658  
181659  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181660  , p_source_3 => l_array_source_3(Idx)
181661  , p_source_4 => l_array_source_4(Idx)
181662  , p_source_17 => l_array_source_17(Idx)
181663  , p_source_29 => l_array_source_29(Idx)
181664  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
181665  , p_source_35 => l_array_source_35(Idx)
181666  , p_source_36 => l_array_source_36(Idx)
181667  , p_source_37 => l_array_source_37(Idx)
181668  , p_source_38 => l_array_source_38(Idx)
181669  , p_source_39 => l_array_source_39(Idx)
181670  , p_source_40 => l_array_source_40(Idx)
181671  );
181672 If(l_balance_type_code = 'A') THEN
181673   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181674 END IF;
181675 
181676 --
181677 
181678 
181679 --
181680 AcctLineType_191 (
181681  p_application_id  => p_application_id
181682  ,p_event_id     => l_event_id
181683  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181684  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181685  ,p_actual_flag => l_actual_flag
181686  ,p_balance_type_code => l_balance_type_code
181687  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181688  
181689  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181690  , p_source_3 => l_array_source_3(Idx)
181691  , p_source_9 => l_array_source_9(Idx)
181692  , p_source_29 => l_array_source_29(Idx)
181693  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
181694  , p_source_35 => l_array_source_35(Idx)
181695  , p_source_36 => l_array_source_36(Idx)
181696  , p_source_37 => l_array_source_37(Idx)
181697  , p_source_38 => l_array_source_38(Idx)
181698  , p_source_39 => l_array_source_39(Idx)
181699  , p_source_40 => l_array_source_40(Idx)
181700  );
181704 
181701 If(l_balance_type_code = 'A') THEN
181702   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181703 END IF;
181705 --
181706 
181707 
181708 --
181709 AcctLineType_192 (
181710  p_application_id  => p_application_id
181711  ,p_event_id     => l_event_id
181712  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181713  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181714  ,p_actual_flag => l_actual_flag
181715  ,p_balance_type_code => l_balance_type_code
181716  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181717  
181718  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181719  , p_source_3 => l_array_source_3(Idx)
181720  , p_source_6 => l_array_source_6(Idx)
181721  , p_source_8 => l_array_source_8(Idx)
181722  , p_source_29 => l_array_source_29(Idx)
181723  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
181724  , p_source_35 => l_array_source_35(Idx)
181725  , p_source_36 => l_array_source_36(Idx)
181726  , p_source_37 => l_array_source_37(Idx)
181727  , p_source_38 => l_array_source_38(Idx)
181728  , p_source_39 => l_array_source_39(Idx)
181729  , p_source_40 => l_array_source_40(Idx)
181730  );
181731 If(l_balance_type_code = 'A') THEN
181732   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181733 END IF;
181734 
181735 --
181736 
181737 
181738 --
181739 AcctLineType_193 (
181740  p_application_id  => p_application_id
181741  ,p_event_id     => l_event_id
181742  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181743  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181744  ,p_actual_flag => l_actual_flag
181745  ,p_balance_type_code => l_balance_type_code
181746  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181747  
181748  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181749  , p_source_3 => l_array_source_3(Idx)
181750  , p_source_29 => l_array_source_29(Idx)
181751  , p_source_35 => l_array_source_35(Idx)
181752  , p_source_36 => l_array_source_36(Idx)
181753  , p_source_37 => l_array_source_37(Idx)
181754  , p_source_38 => l_array_source_38(Idx)
181755  , p_source_39 => l_array_source_39(Idx)
181756  , p_source_40 => l_array_source_40(Idx)
181757  );
181758 If(l_balance_type_code = 'A') THEN
181759   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181760 END IF;
181761 
181762 --
181763 
181764 
181765 --
181766 AcctLineType_194 (
181767  p_application_id  => p_application_id
181768  ,p_event_id     => l_event_id
181769  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181770  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181771  ,p_actual_flag => l_actual_flag
181772  ,p_balance_type_code => l_balance_type_code
181773  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181774  
181775  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181776  , p_source_3 => l_array_source_3(Idx)
181777  , p_source_29 => l_array_source_29(Idx)
181778  , p_source_35 => l_array_source_35(Idx)
181779  , p_source_36 => l_array_source_36(Idx)
181780  , p_source_37 => l_array_source_37(Idx)
181781  , p_source_38 => l_array_source_38(Idx)
181782  , p_source_39 => l_array_source_39(Idx)
181783  , p_source_40 => l_array_source_40(Idx)
181784  );
181785 If(l_balance_type_code = 'A') THEN
181786   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181787 END IF;
181788 
181789 --
181790 
181791 
181792 --
181793 AcctLineType_195 (
181794  p_application_id  => p_application_id
181795  ,p_event_id     => l_event_id
181796  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181797  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181798  ,p_actual_flag => l_actual_flag
181799  ,p_balance_type_code => l_balance_type_code
181800  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181801  
181802  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181803  , p_source_3 => l_array_source_3(Idx)
181804  , p_source_19 => g_array_event(l_event_id).array_value_char('source_19')
181805  , p_source_29 => l_array_source_29(Idx)
181806  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
181807  , p_source_35 => l_array_source_35(Idx)
181808  , p_source_36 => l_array_source_36(Idx)
181809  , p_source_37 => l_array_source_37(Idx)
181810  , p_source_38 => l_array_source_38(Idx)
181811  , p_source_39 => l_array_source_39(Idx)
181812  , p_source_40 => l_array_source_40(Idx)
181813  );
181814 If(l_balance_type_code = 'A') THEN
181815   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181816 END IF;
181817 
181818 --
181819 
181820 
181821 --
181822 AcctLineType_196 (
181823  p_application_id  => p_application_id
181824  ,p_event_id     => l_event_id
181825  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181826  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181827  ,p_actual_flag => l_actual_flag
181828  ,p_balance_type_code => l_balance_type_code
181829  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181830  
181831  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181832  , p_source_3 => l_array_source_3(Idx)
181833  , p_source_20 => g_array_event(l_event_id).array_value_char('source_20')
181834  , p_source_29 => l_array_source_29(Idx)
181835  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
181836  , p_source_35 => l_array_source_35(Idx)
181837  , p_source_36 => l_array_source_36(Idx)
181838  , p_source_37 => l_array_source_37(Idx)
181839  , p_source_38 => l_array_source_38(Idx)
181840  , p_source_39 => l_array_source_39(Idx)
181841  , p_source_40 => l_array_source_40(Idx)
181842  );
181843 If(l_balance_type_code = 'A') THEN
181844   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181845 END IF;
181846 
181847 --
181848 
181849 
181850 --
181851 AcctLineType_197 (
181852  p_application_id  => p_application_id
181853  ,p_event_id     => l_event_id
181854  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181855  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181859  
181856  ,p_actual_flag => l_actual_flag
181857  ,p_balance_type_code => l_balance_type_code
181858  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181860  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181861  , p_source_3 => l_array_source_3(Idx)
181862  , p_source_10 => l_array_source_10(Idx)
181863  , p_source_17 => l_array_source_17(Idx)
181864  , p_source_29 => l_array_source_29(Idx)
181865  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
181866  , p_source_35 => l_array_source_35(Idx)
181867  , p_source_36 => l_array_source_36(Idx)
181868  , p_source_37 => l_array_source_37(Idx)
181869  , p_source_38 => l_array_source_38(Idx)
181870  , p_source_39 => l_array_source_39(Idx)
181871  , p_source_40 => l_array_source_40(Idx)
181872  );
181873 If(l_balance_type_code = 'A') THEN
181874   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181875 END IF;
181876 
181877 --
181878 
181879 
181880 --
181881 AcctLineType_198 (
181882  p_application_id  => p_application_id
181883  ,p_event_id     => l_event_id
181884  ,p_calculate_acctd_flag => l_calculate_acctd_flag
181885  ,p_calculate_g_l_flag => l_calculate_g_l_flag
181886  ,p_actual_flag => l_actual_flag
181887  ,p_balance_type_code => l_balance_type_code
181888  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
181889  
181890  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
181891  , p_source_3 => l_array_source_3(Idx)
181892  , p_source_10 => l_array_source_10(Idx)
181893  , p_source_17 => l_array_source_17(Idx)
181894  , p_source_29 => l_array_source_29(Idx)
181895  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
181896  , p_source_35 => l_array_source_35(Idx)
181897  , p_source_36 => l_array_source_36(Idx)
181898  , p_source_37 => l_array_source_37(Idx)
181899  , p_source_38 => l_array_source_38(Idx)
181900  , p_source_39 => l_array_source_39(Idx)
181901  , p_source_40 => l_array_source_40(Idx)
181902  );
181903 If(l_balance_type_code = 'A') THEN
181904   l_actual_gain_loss_ref := l_gain_or_loss_ref;
181905 END IF;
181906 
181907 --
181908 
181909       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
181910       -- or secondary ledger that has different currency with primary
181911       -- or alc that is calculated by sla
181912       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
181913             (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'))
181914 
181915 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
181916 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
181917           AND (l_actual_flag = 'A')) THEN
181918         XLA_AE_LINES_PKG.CreateGainOrLossLines(
181919           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
181920          ,p_application_id   => p_application_id
181921          ,p_amb_context_code => 'DEFAULT'
181922          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
181923          ,p_event_class_code => C_EVENT_CLASS_CODE
181924          ,p_event_type_code  => C_EVENT_TYPE_CODE
181925          
181926          ,p_gain_ccid        => -1
181927          ,p_loss_ccid        => -1
181928 
181929          ,p_actual_flag      => l_actual_flag
181930          ,p_enc_flag         => null
181931          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
181932          ,p_enc_g_l_ref      => null
181933          );
181934       END IF;
181935    END IF;
181936 END IF;
181937 
181938    ELSE
181939       --
181940       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
181941       --
181942       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
181943          trace
181944             (p_msg      => 'Trancaction revesal option is Y'
181945             ,p_level    => C_LEVEL_STATEMENT
181946             ,p_module   => l_log_module);
181947       END IF;
181948    END IF;
181949 
181950 END LOOP;
181951 l_result := XLA_AE_LINES_PKG.InsertLines ;
181952 end loop;
181953 close line_cur;
181954 
181955 
181956 --
181957 -- insert headers into xla_ae_headers_gt table
181958 --
181959 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
181960 
181961 -- insert into errors table here.
181962 
181963 END LOOP;
181964 
181965 --
181966 -- 4865292
181967 --
181968 -- Compare g_hdr_extract_count with event count in
181969 -- CreateHeadersAndLines.
181970 --
181971 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
181972 
181973 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
181974    trace (p_msg     => '# rows extracted from header extract objects '
181975                     || ' (running total): '
181976                     || g_hdr_extract_count
181977          ,p_level   => C_LEVEL_STATEMENT
181978          ,p_module  => l_log_module);
181979 END IF;
181980 
181981 CLOSE header_cur;
181982 --
181983 
181984 --
181985 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
181986    trace
181987       (p_msg      => 'END of EventClass_408'
181988       ,p_level    => C_LEVEL_PROCEDURE
181989       ,p_module   => l_log_module);
181990 END IF;
181991 --
181992 RETURN l_result;
181993 EXCEPTION
181994 WHEN xla_exceptions_pkg.application_exception THEN
181995    
181996 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
181997 
181998    
181999 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
182000 
182001    RAISE;
182002 
182003 WHEN NO_DATA_FOUND THEN
182004 
182005 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
182006 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
182007 
182008 FOR header_record IN header_cur
182009 LOOP
182013 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
182010     l_array_header_events(header_record.event_id) := header_record.event_id;
182011 END LOOP;
182012 
182014 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
182015 
182016 fnd_file.put_line(fnd_file.LOG, '                    ');
182017 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
182018 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
182019 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
182020 
182021 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
182022 LOOP
182023 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
182024 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
182025         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
182026 	END IF;
182027 END LOOP;
182028 
182029 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
182030 fnd_file.put_line(fnd_file.LOG, '                    ');
182031 
182032 
182033 xla_exceptions_pkg.raise_message
182034       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_408');
182035 
182036 
182037 WHEN OTHERS THEN
182038    xla_exceptions_pkg.raise_message
182039       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_408');
182040 END EventClass_408;
182041 --
182042 
182043 ---------------------------------------
182044 --
182045 -- PRIVATE PROCEDURE
182046 --         insert_sources_409
182047 --
182048 ----------------------------------------
182049 --
182050 PROCEDURE insert_sources_409(
182051                                 p_target_ledger_id       IN NUMBER
182052                               , p_language               IN VARCHAR2
182053                               , p_sla_ledger_id          IN NUMBER
182054                               , p_pad_start_date         IN DATE
182055                               , p_pad_end_date           IN DATE
182056                          )
182057 IS
182058 
182059 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CAPITALIZATION';
182060 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CAPITALIZATION';
182061 p_apps_owner                   VARCHAR2(30);
182062 l_log_module                   VARCHAR2(240);
182063 BEGIN
182064 IF g_log_enabled THEN
182065       l_log_module := C_DEFAULT_MODULE||'.insert_sources_409';
182066 END IF;
182067 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
182068 
182069       trace
182070          (p_msg      => 'BEGIN of insert_sources_409'
182071          ,p_level    => C_LEVEL_PROCEDURE
182072          ,p_module   => l_log_module);
182073 
182074 END IF;
182075 
182076 -- select APPS owner
182077 SELECT oracle_username
182078   INTO p_apps_owner
182079   FROM fnd_oracle_userid
182080  WHERE read_only_flag = 'U'
182081 ;
182082 
182083 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
182084       trace
182085          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
182086                         ' - p_language = '||p_language||
182087                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
182088                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
182089                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
182090                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
182091          ,p_level    => C_LEVEL_STATEMENT
182092          ,p_module   => l_log_module);
182093 END IF;
182094 
182095 
182096 --
182097 INSERT INTO xla_diag_sources --hdr1
182098 (
182099         event_id
182100       , ledger_id
182101       , sla_ledger_id
182102       , description_language
182103       , object_name
182104       , object_type_code
182105       , line_number
182106       , source_application_id
182107       , source_type_code
182108       , source_code
182109       , source_value
182110       , source_meaning
182111       , created_by
182112       , creation_date
182113       , last_update_date
182114       , last_updated_by
182115       , last_update_login
182116       , program_update_date
182117       , program_application_id
182118       , program_id
182119       , request_id
182120 )
182121 SELECT
182122         event_id
182123       , p_target_ledger_id
182124       , p_sla_ledger_id
182125       , p_language
182126       , object_name
182127       , object_type_code
182128       , line_number
182129       , source_application_id
182130       , source_type_code
182131       , source_code
182132       , SUBSTR(source_value ,1,1996)
182133       , SUBSTR(source_meaning,1,200)
182134       , xla_environment_pkg.g_Usr_Id
182135       , TRUNC(SYSDATE)
182136       , TRUNC(SYSDATE)
182137       , xla_environment_pkg.g_Usr_Id
182138       , xla_environment_pkg.g_Login_Id
182139       , TRUNC(SYSDATE)
182140       , xla_environment_pkg.g_Prog_Appl_Id
182141       , xla_environment_pkg.g_Prog_Id
182142       , xla_environment_pkg.g_Req_Id
182143   FROM (
182144        SELECT xet.event_id                  event_id
182145             , 0                             line_number
182146             , CASE r
182147                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
182148                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
182149                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
182150                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
182151                 
182152                ELSE null
182153               END                           object_name
182154             , CASE r
182155                 WHEN 1 THEN 'HEADER' 
182156                 WHEN 2 THEN 'HEADER' 
182157                 WHEN 3 THEN 'HEADER' 
182158                 WHEN 4 THEN 'HEADER' 
182162             , CASE r
182159                 
182160                 ELSE null
182161               END                           object_type_code
182163                 WHEN 1 THEN '140' 
182164                 WHEN 2 THEN '140' 
182165                 WHEN 3 THEN '140' 
182166                 WHEN 4 THEN '140' 
182167                 
182168                 ELSE null
182169               END                           source_application_id
182170             , 'S'             source_type_code
182171             , CASE r
182172                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
182173                 WHEN 2 THEN 'DEFAULT_CCID' 
182174                 WHEN 3 THEN 'ACCOUNTING_DATE' 
182175                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
182176                 
182177                 ELSE null
182178               END                           source_code
182179             , CASE r
182180                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
182181                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
182182                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
182183                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
182184                 
182185                 ELSE null
182186               END                           source_value
182187             , null              source_meaning
182188         FROM xla_events_gt     xet  
182189       , FA_XLA_EXT_HEADERS_B_GT  h1
182190             ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
182191        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
182192          AND xet.event_type_code = C_EVENT_TYPE_CODE
182193             AND h1.event_id = xet.event_id
182194 
182195 )
182196 ;
182197 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
182198 
182199       trace
182200          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
182201          ,p_level    => C_LEVEL_STATEMENT
182202          ,p_module   => l_log_module);
182203 
182204 END IF;
182205 --
182206 
182207 
182208 
182209 --
182210 INSERT INTO xla_diag_sources --line1
182211 (
182212         event_id
182213       , ledger_id
182214       , sla_ledger_id
182215       , description_language
182216       , object_name
182217       , object_type_code
182218       , line_number
182219       , source_application_id
182220       , source_type_code
182221       , source_code
182222       , source_value
182223       , source_meaning
182224       , created_by
182225       , creation_date
182226       , last_update_date
182227       , last_updated_by
182228       , last_update_login
182229       , program_update_date
182230       , program_application_id
182231       , program_id
182232       , request_id
182233 )
182234 SELECT  event_id
182235       , p_target_ledger_id
182236       , p_sla_ledger_id
182237       , p_language
182238       , object_name
182239       , object_type_code
182240       , line_number
182241       , source_application_id
182242       , source_type_code
182243       , source_code
182244       , SUBSTR(source_value,1,1996)
182245       , SUBSTR(source_meaning,1,200)
182246       , xla_environment_pkg.g_Usr_Id
182247       , TRUNC(SYSDATE)
182248       , TRUNC(SYSDATE)
182249       , xla_environment_pkg.g_Usr_Id
182250       , xla_environment_pkg.g_Login_Id
182251       , TRUNC(SYSDATE)
182252       , xla_environment_pkg.g_Prog_Appl_Id
182253       , xla_environment_pkg.g_Prog_Id
182254       , xla_environment_pkg.g_Req_Id
182255   FROM (
182256        SELECT xet.event_id                  event_id
182257             , l2.line_number                 line_number
182258             , CASE r
182259                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
182260                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
182261                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
182262                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
182263                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
182264                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
182265                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
182266                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
182267                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
182268                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
182269                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
182270                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
182271                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
182272                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
182273                 
182274                ELSE null
182275               END                           object_name
182276             , CASE r
182277                 WHEN 1 THEN 'LINE' 
182278                 WHEN 2 THEN 'LINE' 
182279                 WHEN 3 THEN 'LINE' 
182280                 WHEN 4 THEN 'LINE' 
182281                 WHEN 5 THEN 'LINE' 
182282                 WHEN 6 THEN 'LINE' 
182283                 WHEN 7 THEN 'LINE' 
182284                 WHEN 8 THEN 'LINE' 
182285                 WHEN 9 THEN 'LINE' 
182286                 WHEN 10 THEN 'LINE' 
182287                 WHEN 11 THEN 'LINE' 
182288                 WHEN 12 THEN 'LINE' 
182289                 WHEN 13 THEN 'LINE' 
182290                 WHEN 14 THEN 'LINE' 
182291                 
182292                 ELSE null
182293               END                           object_type_code
182294             , CASE r
182295                 WHEN 1 THEN '140' 
182296                 WHEN 2 THEN '140' 
182297                 WHEN 3 THEN '140' 
182298                 WHEN 4 THEN '140' 
182299                 WHEN 5 THEN '140' 
182300                 WHEN 6 THEN '140' 
182301                 WHEN 7 THEN '140' 
182302                 WHEN 8 THEN '140' 
182303                 WHEN 9 THEN '140' 
182304                 WHEN 10 THEN '140' 
182305                 WHEN 11 THEN '140' 
182306                 WHEN 12 THEN '140' 
182310                 ELSE null
182307                 WHEN 13 THEN '140' 
182308                 WHEN 14 THEN '140' 
182309                 
182311               END                           source_application_id
182312             , 'S'             source_type_code
182313             , CASE r
182314                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
182315                 WHEN 2 THEN 'GENERATED_CCID' 
182316                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
182317                 WHEN 4 THEN 'CIP_COST_ACCT' 
182318                 WHEN 5 THEN 'ASSET_COST_ACCT' 
182319                 WHEN 6 THEN 'DEPRN_RESERVE_ACCT' 
182320                 WHEN 7 THEN 'GENERATED_OFFSET_CCID' 
182321                 WHEN 8 THEN 'EXPENSE_ACCOUNT_CCID' 
182322                 WHEN 9 THEN 'ADJUSTMENT_TYPE' 
182323                 WHEN 10 THEN 'TRANSACTION_HEADER_ID' 
182324                 WHEN 11 THEN 'ADJUSTMENT_LINE_ID' 
182325                 WHEN 12 THEN 'DISTRIBUTION_TYPE_CODE' 
182326                 WHEN 13 THEN 'ENTERED_AMOUNT' 
182327                 WHEN 14 THEN 'CURRENCY_CODE' 
182328                 
182329                 ELSE null
182330               END                           source_code
182331             , CASE r
182332                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
182333                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
182334                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
182335                 WHEN 4 THEN TO_CHAR(l2.CIP_COST_ACCT)
182336                 WHEN 5 THEN TO_CHAR(l2.ASSET_COST_ACCT)
182337                 WHEN 6 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
182338                 WHEN 7 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
182339                 WHEN 8 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
182340                 WHEN 9 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
182341                 WHEN 10 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
182342                 WHEN 11 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
182343                 WHEN 12 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
182344                 WHEN 13 THEN TO_CHAR(l2.ENTERED_AMOUNT)
182345                 WHEN 14 THEN TO_CHAR(l2.CURRENCY_CODE)
182346                 
182347                 ELSE null
182348               END                           source_value
182349             , null              source_meaning
182350          FROM  xla_events_gt     xet  
182351         , FA_XLA_EXT_LINES_B_GT  l2
182352             ,(select rownum r from all_objects where rownum <= 14 and owner = p_apps_owner)
182353         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
182354           AND xet.event_type_code = C_EVENT_TYPE_CODE
182355             AND l2.event_id          = xet.event_id
182356   AND l2.ledger_id (+)  = p_sla_ledger_id
182357 
182358 )
182359 ;
182360 --
182361 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
182362 
182363       trace
182364          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
182365          ,p_level    => C_LEVEL_STATEMENT
182366          ,p_module   => l_log_module);
182367 
182368 END IF;
182369 
182370 
182371 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
182372       trace
182373          (p_msg      => 'END of insert_sources_409'
182374          ,p_level    => C_LEVEL_PROCEDURE
182375          ,p_module   => l_log_module);
182376 END IF;
182377 EXCEPTION
182378   WHEN xla_exceptions_pkg.application_exception THEN
182379       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
182380             trace
182381                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
182382                ,p_level    => C_LEVEL_EXCEPTION
182383                ,p_module   => l_log_module);
182384       END IF;
182385       RAISE;
182386   WHEN OTHERS THEN
182387       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
182388             trace
182389                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
182390                ,p_level    => C_LEVEL_EXCEPTION
182391                ,p_module   => l_log_module);
182392        END IF;
182393        xla_exceptions_pkg.raise_message
182394            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_409');
182395 END insert_sources_409;
182396 --
182397 
182398 ---------------------------------------
182399 --
182400 -- PRIVATE FUNCTION
182401 --         EventType_409
182402 --
182403 ----------------------------------------
182404 --
182405 FUNCTION EventType_409
182406        (p_application_id         IN NUMBER
182407        ,p_base_ledger_id         IN NUMBER
182408        ,p_target_ledger_id       IN NUMBER
182409        ,p_language               IN VARCHAR2
182410        ,p_currency_code          IN VARCHAR2
182411        ,p_sla_ledger_id          IN NUMBER
182412        ,p_pad_start_date         IN DATE
182413        ,p_pad_end_date           IN DATE
182414        ,p_primary_ledger_id      IN NUMBER)
182415 RETURN BOOLEAN IS
182416 --
182417 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CAPITALIZATION';
182418 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CAPITALIZATION';
182419 
182420 l_calculate_acctd_flag   VARCHAR2(1) :='N';
182421 l_calculate_g_l_flag     VARCHAR2(1) :='N';
182422 --
182423 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
182424 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
182425 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
182426 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
182427 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
182428 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
182429 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
182430 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
182431 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
182432 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
182433 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
182437 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
182434 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
182435 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
182436 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
182438 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
182439 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
182440 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
182441 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
182442 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
182443 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
182444 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
182445 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
182446 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
182447 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
182448 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
182449 
182450 l_event_id                             NUMBER;
182451 l_previous_event_id                    NUMBER;
182452 l_first_event_id                       NUMBER;
182453 l_last_event_id                        NUMBER;
182454 
182455 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
182456 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
182457 --
182458 --
182459 l_result                    BOOLEAN := TRUE;
182460 l_rows                      NUMBER  := 1000;
182461 l_event_type_name           VARCHAR2(80) := 'Capitalization';
182462 l_event_class_name          VARCHAR2(80) := 'Capitalization';
182463 l_description               VARCHAR2(4000);
182464 l_transaction_reversal      NUMBER;
182465 l_ae_header_id              NUMBER;
182466 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
182467 l_log_module                VARCHAR2(240);
182468 --
182469 l_acct_reversal_source      VARCHAR2(30);
182470 l_trx_reversal_source       VARCHAR2(30);
182471 
182472 l_continue_with_lines       BOOLEAN := TRUE;
182473 --
182474 l_acc_rev_gl_date_source    DATE;                      -- 4262811
182475 --
182476 type t_array_event_id is table of number index by binary_integer;
182477 
182478 l_rec_array_event                    t_rec_array_event;
182479 l_null_rec_array_event               t_rec_array_event;
182480 l_array_ae_header_id                 xla_number_array_type;
182481 l_actual_flag                        VARCHAR2(1) := NULL;
182482 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
182483 l_balance_type_code                  VARCHAR2(1) :=NULL;
182484 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
182485 
182486 --
182487 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
182488 --
182489 
182490 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
182491 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
182492 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
182493 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
182494 
182495 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
182496 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
182497 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
182498 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
182499 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
182500 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
182501 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
182502 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
182503 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
182504 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
182505 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
182506 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
182507 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
182508 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
182509 
182510 l_array_source_1              t_array_source_1;
182511 l_array_source_30              t_array_source_30;
182512 l_array_source_51              t_array_source_51;
182513 l_array_source_52              t_array_source_52;
182514 
182515 l_array_source_2      t_array_source_2;
182516 l_array_source_3      t_array_source_3;
182517 l_array_source_4      t_array_source_4;
182518 l_array_source_7      t_array_source_7;
182519 l_array_source_9      t_array_source_9;
182520 l_array_source_10      t_array_source_10;
182521 l_array_source_17      t_array_source_17;
182522 l_array_source_29      t_array_source_29;
182523 l_array_source_35      t_array_source_35;
182524 l_array_source_36      t_array_source_36;
182525 l_array_source_37      t_array_source_37;
182526 l_array_source_38      t_array_source_38;
182527 l_array_source_39      t_array_source_39;
182528 l_array_source_40      t_array_source_40;
182529 
182530 --
182531 CURSOR header_cur
182532 IS
182533 SELECT /*+ leading(xet) cardinality(xet,1) */
182534 -- Event Type Code: CAPITALIZATION
182535 -- Event Class Code: CAPITALIZATION
182536     xet.entity_id
182537   , xet.legal_entity_id
182541   , xet.event_class_code
182538   , xet.entity_code
182539   , xet.transaction_number
182540   , xet.event_id
182542   , xet.event_type_code
182543   , xet.event_number
182544   , xet.event_date
182545   , xet.transaction_date
182546   , xet.reference_num_1
182547   , xet.reference_num_2
182548   , xet.reference_num_3
182549   , xet.reference_num_4
182550   , xet.reference_char_1
182551   , xet.reference_char_2
182552   , xet.reference_char_3
182553   , xet.reference_char_4
182554   , xet.reference_date_1
182555   , xet.reference_date_2
182556   , xet.reference_date_3
182557   , xet.reference_date_4
182558   , xet.event_created_by
182559   , xet.budgetary_control_flag 
182560   , h1.PERIOD_CLOSE_DATE    source_1
182561   , h1.DEFAULT_CCID    source_30
182562   , h1.ACCOUNTING_DATE    source_51
182563   , h1.TRANSFER_TO_GL_FLAG    source_52
182564   FROM xla_events_gt     xet 
182565   , FA_XLA_EXT_HEADERS_B_GT  h1
182566  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
182567    and xet.event_type_code = C_EVENT_TYPE_CODE
182568    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
182569 
182570  ORDER BY event_id
182571 ;
182572 
182573 
182574 --
182575 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
182576 IS
182577 SELECT /*+ leading(xet) cardinality(xet,1) */
182578 -- Event Type Code: CAPITALIZATION
182579 -- Event Class Code: CAPITALIZATION
182580     xet.entity_id
182581    ,xet.legal_entity_id
182582    ,xet.entity_code
182583    ,xet.transaction_number
182584    ,xet.event_id
182585    ,xet.event_class_code
182586    ,xet.event_type_code
182587    ,xet.event_number
182588    ,xet.event_date
182589    ,xet.transaction_date
182590    ,xet.reference_num_1
182591    ,xet.reference_num_2
182592    ,xet.reference_num_3
182593    ,xet.reference_num_4
182594    ,xet.reference_char_1
182595    ,xet.reference_char_2
182596    ,xet.reference_char_3
182597    ,xet.reference_char_4
182598    ,xet.reference_date_1
182599    ,xet.reference_date_2
182600    ,xet.reference_date_3
182601    ,xet.reference_date_4
182602    ,xet.event_created_by
182603    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
182604   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
182605   , l2.GENERATED_CCID    source_3
182606   , l2.BONUS_RESERVE_ACCT    source_4
182607   , l2.CIP_COST_ACCT    source_7
182608   , l2.ASSET_COST_ACCT    source_9
182609   , l2.DEPRN_RESERVE_ACCT    source_10
182610   , l2.GENERATED_OFFSET_CCID    source_17
182611   , l2.EXPENSE_ACCOUNT_CCID    source_29
182612   , l2.ADJUSTMENT_TYPE    source_35
182613   , l2.TRANSACTION_HEADER_ID    source_36
182614   , l2.ADJUSTMENT_LINE_ID    source_37
182615   , l2.DISTRIBUTION_TYPE_CODE    source_38
182616   , l2.ENTERED_AMOUNT    source_39
182617   , l2.CURRENCY_CODE    source_40
182618   FROM xla_events_gt     xet 
182619   , FA_XLA_EXT_LINES_B_GT  l2
182620  WHERE xet.event_id between x_first_event_id and x_last_event_id
182621    and xet.event_date between p_pad_start_date and p_pad_end_date
182622    and xet.event_type_code = C_EVENT_TYPE_CODE
182623    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
182624   AND l2.ledger_id = p_sla_ledger_id
182625 ;
182626 
182627 --
182628 BEGIN
182629 IF g_log_enabled THEN
182630    l_log_module := C_DEFAULT_MODULE||'.EventType_409';
182631 END IF;
182632 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
182633    trace
182634       (p_msg      => 'BEGIN of EventType_409'
182635       ,p_level    => C_LEVEL_PROCEDURE
182636       ,p_module   => l_log_module);
182637 END IF;
182638 
182639 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
182640    trace
182641       (p_msg      => 'p_application_id = '||p_application_id||
182642                      ' - p_base_ledger_id = '||p_base_ledger_id||
182643                      ' - p_target_ledger_id  = '||p_target_ledger_id||
182644                      ' - p_language = '||p_language||
182645                      ' - p_currency_code = '||p_currency_code||
182646                      ' - p_sla_ledger_id = '||p_sla_ledger_id
182647       ,p_level    => C_LEVEL_STATEMENT
182648       ,p_module   => l_log_module);
182649 END IF;
182650 --
182651 -- initialze arrays
182652 --
182653 g_array_event.DELETE;
182654 l_rec_array_event := l_null_rec_array_event;
182655 --
182656 --------------------------------------
182657 -- 4262811 Initialze MPA Line Number
182658 --------------------------------------
182659 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
182660 
182661 --
182662 
182663 --
182664 OPEN header_cur;
182665 --
182666 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
182667    trace
182668    (p_msg      => 'SQL - FETCH header_cur'
182669    ,p_level    => C_LEVEL_STATEMENT
182670    ,p_module   => l_log_module);
182671 END IF;
182672 --
182673 LOOP
182674 FETCH header_cur BULK COLLECT INTO
182675         l_array_entity_id
182676       , l_array_legal_entity_id
182677       , l_array_entity_code
182678       , l_array_transaction_num
182679       , l_array_event_id
182680       , l_array_class_code
182681       , l_array_event_type
182682       , l_array_event_number
182683       , l_array_event_date
182684       , l_array_transaction_date
182685       , l_array_reference_num_1
182686       , l_array_reference_num_2
182687       , l_array_reference_num_3
182688       , l_array_reference_num_4
182689       , l_array_reference_char_1
182690       , l_array_reference_char_2
182691       , l_array_reference_char_3
182692       , l_array_reference_char_4
182693       , l_array_reference_date_1
182694       , l_array_reference_date_2
182695       , l_array_reference_date_3
182696       , l_array_reference_date_4
182697       , l_array_event_created_by
182698       , l_array_budgetary_control_flag 
182699       , l_array_source_1
182703       LIMIT l_rows;
182700       , l_array_source_30
182701       , l_array_source_51
182702       , l_array_source_52
182704 --
182705 IF (C_LEVEL_EVENT >= g_log_level) THEN
182706    trace
182707    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
182708    ,p_level    => C_LEVEL_EVENT
182709    ,p_module   => l_log_module);
182710 END IF;
182711 --
182712 EXIT WHEN l_array_entity_id.COUNT = 0;
182713 
182714 -- initialize arrays
182715 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
182716 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
182717 
182718 --
182719 -- Bug 4458708
182720 --
182721 XLA_AE_LINES_PKG.g_LineNumber := 0;
182722 
182723 
182724 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
182725 g_last_hdr_idx := l_array_event_id.LAST;
182726 --
182727 -- loop for the headers. Each iteration is for each header extract row
182728 -- fetched in header cursor
182729 --
182730 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
182731 
182732 --
182733 -- set event info as cache for other routines to refer event attributes
182734 --
182735 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
182736    (p_application_id           => p_application_id
182737    ,p_primary_ledger_id        => p_primary_ledger_id
182738    ,p_base_ledger_id           => p_base_ledger_id
182739    ,p_target_ledger_id         => p_target_ledger_id
182740    ,p_entity_id                => l_array_entity_id(hdr_idx)
182741    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
182742    ,p_entity_code              => l_array_entity_code(hdr_idx)
182743    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
182744    ,p_event_id                 => l_array_event_id(hdr_idx)
182745    ,p_event_class_code         => l_array_class_code(hdr_idx)
182746    ,p_event_type_code          => l_array_event_type(hdr_idx)
182747    ,p_event_number             => l_array_event_number(hdr_idx)
182748    ,p_event_date               => l_array_event_date(hdr_idx)
182749    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
182750    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
182751    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
182752    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
182753    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
182754    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
182755    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
182756    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
182757    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
182758    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
182759    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
182760    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
182761    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
182762    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
182763    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
182764 
182765 --
182766 -- set the status of entry to C_VALID (0)
182767 --
182768 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
182769 
182770 --
182771 -- initialize a row for ae header
182772 --
182773 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
182774 
182775 l_event_id := l_array_event_id(hdr_idx);
182776 
182777 --
182778 -- storing the hdr_idx for event. May be used by line cursor.
182779 --
182780 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
182781 
182782 --
182783 -- store sources from header extract. This can be improved to
182784 -- store only those sources from header extract that may be used in lines
182785 --
182786 
182787 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
182788 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
182789 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
182790 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
182791 
182792 --
182793 -- initilaize the status of ae headers for diffrent balance types
182794 -- the status is initialised to C_NOT_CREATED (2)
182795 --
182796 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
182797 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
182798 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
182799 
182800 --
182801 -- call api to validate and store accounting attributes for header
182802 --
182803 
182804 ------------------------------------------------------------
182805 -- Accrual Reversal : to get date for Standard Source (NONE)
182806 ------------------------------------------------------------
182807 l_acc_rev_gl_date_source := NULL;
182808 
182809      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
182810       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
182811      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
182812       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
182813 
182814 
182815 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
182816 
182817 XLA_AE_HEADER_PKG.SetJeCategoryName;
182818 
182819 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
182820 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
182821 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
182822 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
182826 --
182823 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
182824 
182825 
182827 xla_ae_header_pkg.SetHdrDescription(
182828    p_description => Description_16 (
182829    p_application_id => p_application_id 
182830  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
182831    )
182832 );
182833 --
182834 
182835 -- No header level analytical criteria
182836 
182837 --
182838 --accounting attribute enhancement, bug 3612931
182839 --
182840 l_trx_reversal_source := SUBSTR(NULL, 1,30);
182841 
182842 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
182843    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
182844 
182845    xla_accounting_err_pkg.build_message
182846       (p_appli_s_name            => 'XLA'
182847       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
182848       ,p_token_1                 => 'ACCT_ATTR_NAME'
182849       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
182850       ,p_token_2                 => 'PRODUCT_NAME'
182851       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
182852       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
182853       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
182854       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
182855 
182856 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
182857    --
182858    -- following sets the accounting attributes needed to reverse
182859    -- accounting for a distributeion
182860    --
182861    xla_ae_lines_pkg.SetTrxReversalAttrs
182862       (p_event_id              => l_event_id
182863       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
182864       ,p_trx_reversal_source   => l_trx_reversal_source);
182865 
182866 END IF;
182867 
182868 
182869 ----------------------------------------------------------------
182870 -- 4262811 -  update the header statuses to invalid in need be
182871 ----------------------------------------------------------------
182872 --
182873 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
182874 
182875 
182876   -----------------------------------------------
182877   -- No accrual reversal for the event class/type
182878   -----------------------------------------------
182879 ----------------------------------------------------------------
182880 
182881 --
182882 -- this ends the header loop iteration for one bulk fetch
182883 --
182884 END LOOP;
182885 
182886 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
182887 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
182888 
182889 --
182890 -- insert dummy rows into lines gt table that were created due to
182891 -- transaction reversals
182892 --
182893 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
182894    l_result := XLA_AE_LINES_PKG.InsertLines;
182895 END IF;
182896 
182897 --
182898 -- reset the temp_line_num for each set of events fetched from header
182899 -- cursor rather than doing it for each new event in line cursor
182900 -- Bug 3939231
182901 --
182902 xla_ae_lines_pkg.g_temp_line_num := 0;
182903 
182904 
182905 
182906 --
182907 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
182908 --
182909 --
182910 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
182911 
182912       trace
182913          (p_msg      => 'SQL - FETCH line_cur'
182914          ,p_level    => C_LEVEL_STATEMENT
182915          ,p_module   => l_log_module);
182916 
182917 END IF;
182918 --
182919 --
182920 LOOP
182921   --
182922   FETCH line_cur BULK COLLECT INTO
182923         l_array_entity_id
182924       , l_array_legal_entity_id
182925       , l_array_entity_code
182926       , l_array_transaction_num
182927       , l_array_event_id
182928       , l_array_class_code
182929       , l_array_event_type
182930       , l_array_event_number
182931       , l_array_event_date
182932       , l_array_transaction_date
182933       , l_array_reference_num_1
182934       , l_array_reference_num_2
182935       , l_array_reference_num_3
182936       , l_array_reference_num_4
182937       , l_array_reference_char_1
182938       , l_array_reference_char_2
182939       , l_array_reference_char_3
182940       , l_array_reference_char_4
182941       , l_array_reference_date_1
182942       , l_array_reference_date_2
182943       , l_array_reference_date_3
182944       , l_array_reference_date_4
182945       , l_array_event_created_by
182946       , l_array_budgetary_control_flag
182947       , l_array_extract_line_num 
182948       , l_array_source_2
182949       , l_array_source_3
182950       , l_array_source_4
182951       , l_array_source_7
182952       , l_array_source_9
182953       , l_array_source_10
182954       , l_array_source_17
182955       , l_array_source_29
182956       , l_array_source_35
182957       , l_array_source_36
182958       , l_array_source_37
182959       , l_array_source_38
182960       , l_array_source_39
182961       , l_array_source_40
182962       LIMIT l_rows;
182963 
182964   --
182965   IF (C_LEVEL_EVENT >= g_log_level) THEN
182966             trace
182967                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
182968                ,p_level    => C_LEVEL_EVENT
182969                ,p_module   => l_log_module);
182970   END IF;
182971   --
182972   EXIT WHEN l_array_entity_id.count = 0;
182973 
182974   XLA_AE_LINES_PKG.g_rec_lines := null;
182975 
182976 --
182977 -- Bug 4458708
182978 --
182979 XLA_AE_LINES_PKG.g_LineNumber := 0;
182980 --
182981 --
182985    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
182982 
182983 FOR Idx IN 1..l_array_event_id.count LOOP
182984    --
182986    --
182987    l_event_id := l_array_event_id(idx);  -- 5648433
182988 
182989    --
182990    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
182991    --
182992 
182993    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
182994              (g_array_event(l_event_id).array_value_num('header_index'))
182995          ,'N'
182996          ) <> 'Y'
182997    THEN
182998       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
182999          trace
183000             (p_msg      => 'Trancaction revesal option is not Y '
183001             ,p_level    => C_LEVEL_STATEMENT
183002             ,p_module   => l_log_module);
183003       END IF;
183004 
183005 --
183006 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
183007 --
183008 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
183009 --
183010 -- set event info as cache for other routines to refer event attributes
183011 --
183012 
183013 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
183014    l_previous_event_id := l_event_id;
183015 
183016    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
183017       (p_application_id           => p_application_id
183018       ,p_primary_ledger_id        => p_primary_ledger_id
183019       ,p_base_ledger_id           => p_base_ledger_id
183020       ,p_target_ledger_id         => p_target_ledger_id
183021       ,p_entity_id                => l_array_entity_id(Idx)
183022       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
183023       ,p_entity_code              => l_array_entity_code(Idx)
183024       ,p_transaction_num          => l_array_transaction_num(Idx)
183025       ,p_event_id                 => l_array_event_id(Idx)
183026       ,p_event_class_code         => l_array_class_code(Idx)
183027       ,p_event_type_code          => l_array_event_type(Idx)
183028       ,p_event_number             => l_array_event_number(Idx)
183029       ,p_event_date               => l_array_event_date(Idx)
183030       ,p_transaction_date         => l_array_transaction_date(Idx)
183031       ,p_reference_num_1          => l_array_reference_num_1(Idx)
183032       ,p_reference_num_2          => l_array_reference_num_2(Idx)
183033       ,p_reference_num_3          => l_array_reference_num_3(Idx)
183034       ,p_reference_num_4          => l_array_reference_num_4(Idx)
183035       ,p_reference_char_1         => l_array_reference_char_1(Idx)
183036       ,p_reference_char_2         => l_array_reference_char_2(Idx)
183037       ,p_reference_char_3         => l_array_reference_char_3(Idx)
183038       ,p_reference_char_4         => l_array_reference_char_4(Idx)
183039       ,p_reference_date_1         => l_array_reference_date_1(Idx)
183040       ,p_reference_date_2         => l_array_reference_date_2(Idx)
183041       ,p_reference_date_3         => l_array_reference_date_3(Idx)
183042       ,p_reference_date_4         => l_array_reference_date_4(Idx)
183043       ,p_event_created_by         => l_array_event_created_by(Idx)
183044       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
183045        --
183046 END IF;
183047 
183048 
183049 
183050 --
183051 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
183052 
183053 l_acct_reversal_source := SUBSTR(NULL, 1,30);
183054 
183055 IF l_continue_with_lines THEN
183056    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
183057       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
183058 
183059       xla_accounting_err_pkg.build_message
183060          (p_appli_s_name            => 'XLA'
183061          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
183062          ,p_token_1                 => 'LINE_NUMBER'
183063          ,p_value_1                 => l_array_extract_line_num(Idx)
183064          ,p_token_2                 => 'PRODUCT_NAME'
183065          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
183066          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
183067          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
183068          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
183069 
183070    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
183071       --
183072       -- following sets the accounting attributes needed to reverse
183073       -- accounting for a distributeion
183074       --
183075 
183076       --
183077       -- 5217187
183078       --
183079       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
183080       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
183081                                        g_array_event(l_event_id).array_value_num('header_index'));
183082       --
183083       --
183084 
183085       -- No reversal code generated
183086 
183087       xla_ae_lines_pkg.SetAcctReversalAttrs
183088          (p_event_id             => l_event_id
183089          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
183090          ,p_calculate_acctd_flag => l_calculate_acctd_flag
183091          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
183092    END IF;
183093 
183094    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
183095        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
183096 
183097 --
183098 AcctLineType_199 (
183099  p_application_id  => p_application_id
183100  ,p_event_id     => l_event_id
183101  ,p_calculate_acctd_flag => l_calculate_acctd_flag
183102  ,p_calculate_g_l_flag => l_calculate_g_l_flag
183103  ,p_actual_flag => l_actual_flag
183104  ,p_balance_type_code => l_balance_type_code
183105  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
183106  
183107  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
183111  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
183108  , p_source_3 => l_array_source_3(Idx)
183109  , p_source_7 => l_array_source_7(Idx)
183110  , p_source_29 => l_array_source_29(Idx)
183112  , p_source_35 => l_array_source_35(Idx)
183113  , p_source_36 => l_array_source_36(Idx)
183114  , p_source_37 => l_array_source_37(Idx)
183115  , p_source_38 => l_array_source_38(Idx)
183116  , p_source_39 => l_array_source_39(Idx)
183117  , p_source_40 => l_array_source_40(Idx)
183118  );
183119 If(l_balance_type_code = 'A') THEN
183120   l_actual_gain_loss_ref := l_gain_or_loss_ref;
183121 END IF;
183122 
183123 --
183124 
183125 
183126 --
183127 AcctLineType_200 (
183128  p_application_id  => p_application_id
183129  ,p_event_id     => l_event_id
183130  ,p_calculate_acctd_flag => l_calculate_acctd_flag
183131  ,p_calculate_g_l_flag => l_calculate_g_l_flag
183132  ,p_actual_flag => l_actual_flag
183133  ,p_balance_type_code => l_balance_type_code
183134  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
183135  
183136  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
183137  , p_source_3 => l_array_source_3(Idx)
183138  , p_source_9 => l_array_source_9(Idx)
183139  , p_source_29 => l_array_source_29(Idx)
183140  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
183141  , p_source_35 => l_array_source_35(Idx)
183142  , p_source_36 => l_array_source_36(Idx)
183143  , p_source_37 => l_array_source_37(Idx)
183144  , p_source_38 => l_array_source_38(Idx)
183145  , p_source_39 => l_array_source_39(Idx)
183146  , p_source_40 => l_array_source_40(Idx)
183147  );
183148 If(l_balance_type_code = 'A') THEN
183149   l_actual_gain_loss_ref := l_gain_or_loss_ref;
183150 END IF;
183151 
183152 --
183153 
183154 
183155 --
183156 AcctLineType_201 (
183157  p_application_id  => p_application_id
183158  ,p_event_id     => l_event_id
183159  ,p_calculate_acctd_flag => l_calculate_acctd_flag
183160  ,p_calculate_g_l_flag => l_calculate_g_l_flag
183161  ,p_actual_flag => l_actual_flag
183162  ,p_balance_type_code => l_balance_type_code
183163  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
183164  
183165  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
183166  , p_source_3 => l_array_source_3(Idx)
183167  , p_source_29 => l_array_source_29(Idx)
183168  , p_source_35 => l_array_source_35(Idx)
183169  , p_source_36 => l_array_source_36(Idx)
183170  , p_source_37 => l_array_source_37(Idx)
183171  , p_source_38 => l_array_source_38(Idx)
183172  , p_source_39 => l_array_source_39(Idx)
183173  , p_source_40 => l_array_source_40(Idx)
183174  );
183175 If(l_balance_type_code = 'A') THEN
183176   l_actual_gain_loss_ref := l_gain_or_loss_ref;
183177 END IF;
183178 
183179 --
183180 
183181 
183182 --
183183 AcctLineType_202 (
183184  p_application_id  => p_application_id
183185  ,p_event_id     => l_event_id
183186  ,p_calculate_acctd_flag => l_calculate_acctd_flag
183187  ,p_calculate_g_l_flag => l_calculate_g_l_flag
183188  ,p_actual_flag => l_actual_flag
183189  ,p_balance_type_code => l_balance_type_code
183190  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
183191  
183192  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
183193  , p_source_2 => l_array_source_2(Idx)
183194  , p_source_3 => l_array_source_3(Idx)
183195  , p_source_29 => l_array_source_29(Idx)
183196  , p_source_35 => l_array_source_35(Idx)
183197  , p_source_36 => l_array_source_36(Idx)
183198  , p_source_37 => l_array_source_37(Idx)
183199  , p_source_38 => l_array_source_38(Idx)
183200  , p_source_39 => l_array_source_39(Idx)
183201  , p_source_40 => l_array_source_40(Idx)
183202  );
183203 If(l_balance_type_code = 'A') THEN
183204   l_actual_gain_loss_ref := l_gain_or_loss_ref;
183205 END IF;
183206 
183207 --
183208 
183209 
183210 --
183211 AcctLineType_203 (
183212  p_application_id  => p_application_id
183213  ,p_event_id     => l_event_id
183214  ,p_calculate_acctd_flag => l_calculate_acctd_flag
183215  ,p_calculate_g_l_flag => l_calculate_g_l_flag
183216  ,p_actual_flag => l_actual_flag
183217  ,p_balance_type_code => l_balance_type_code
183218  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
183219  
183220  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
183221  , p_source_3 => l_array_source_3(Idx)
183222  , p_source_4 => l_array_source_4(Idx)
183223  , p_source_17 => l_array_source_17(Idx)
183224  , p_source_29 => l_array_source_29(Idx)
183225  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
183226  , p_source_35 => l_array_source_35(Idx)
183227  , p_source_36 => l_array_source_36(Idx)
183228  , p_source_37 => l_array_source_37(Idx)
183229  , p_source_38 => l_array_source_38(Idx)
183230  , p_source_39 => l_array_source_39(Idx)
183231  , p_source_40 => l_array_source_40(Idx)
183232  );
183233 If(l_balance_type_code = 'A') THEN
183234   l_actual_gain_loss_ref := l_gain_or_loss_ref;
183235 END IF;
183236 
183237 --
183238 
183239 
183240 --
183241 AcctLineType_204 (
183242  p_application_id  => p_application_id
183243  ,p_event_id     => l_event_id
183244  ,p_calculate_acctd_flag => l_calculate_acctd_flag
183245  ,p_calculate_g_l_flag => l_calculate_g_l_flag
183246  ,p_actual_flag => l_actual_flag
183247  ,p_balance_type_code => l_balance_type_code
183248  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
183249  
183250  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
183251  , p_source_3 => l_array_source_3(Idx)
183252  , p_source_29 => l_array_source_29(Idx)
183253  , p_source_35 => l_array_source_35(Idx)
183254  , p_source_36 => l_array_source_36(Idx)
183255  , p_source_37 => l_array_source_37(Idx)
183256  , p_source_38 => l_array_source_38(Idx)
183257  , p_source_39 => l_array_source_39(Idx)
183258  , p_source_40 => l_array_source_40(Idx)
183259  );
183260 If(l_balance_type_code = 'A') THEN
183264 --
183261   l_actual_gain_loss_ref := l_gain_or_loss_ref;
183262 END IF;
183263 
183265 
183266 
183267 --
183268 AcctLineType_205 (
183269  p_application_id  => p_application_id
183270  ,p_event_id     => l_event_id
183271  ,p_calculate_acctd_flag => l_calculate_acctd_flag
183272  ,p_calculate_g_l_flag => l_calculate_g_l_flag
183273  ,p_actual_flag => l_actual_flag
183274  ,p_balance_type_code => l_balance_type_code
183275  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
183276  
183277  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
183278  , p_source_3 => l_array_source_3(Idx)
183279  , p_source_10 => l_array_source_10(Idx)
183280  , p_source_17 => l_array_source_17(Idx)
183281  , p_source_29 => l_array_source_29(Idx)
183282  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
183283  , p_source_35 => l_array_source_35(Idx)
183284  , p_source_36 => l_array_source_36(Idx)
183285  , p_source_37 => l_array_source_37(Idx)
183286  , p_source_38 => l_array_source_38(Idx)
183287  , p_source_39 => l_array_source_39(Idx)
183288  , p_source_40 => l_array_source_40(Idx)
183289  );
183290 If(l_balance_type_code = 'A') THEN
183291   l_actual_gain_loss_ref := l_gain_or_loss_ref;
183292 END IF;
183293 
183294 --
183295 
183296 
183297 --
183298 AcctLineType_206 (
183299  p_application_id  => p_application_id
183300  ,p_event_id     => l_event_id
183301  ,p_calculate_acctd_flag => l_calculate_acctd_flag
183302  ,p_calculate_g_l_flag => l_calculate_g_l_flag
183303  ,p_actual_flag => l_actual_flag
183304  ,p_balance_type_code => l_balance_type_code
183305  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
183306  
183307  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
183308  , p_source_3 => l_array_source_3(Idx)
183309  , p_source_10 => l_array_source_10(Idx)
183310  , p_source_17 => l_array_source_17(Idx)
183311  , p_source_29 => l_array_source_29(Idx)
183312  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
183313  , p_source_35 => l_array_source_35(Idx)
183314  , p_source_36 => l_array_source_36(Idx)
183315  , p_source_37 => l_array_source_37(Idx)
183316  , p_source_38 => l_array_source_38(Idx)
183317  , p_source_39 => l_array_source_39(Idx)
183318  , p_source_40 => l_array_source_40(Idx)
183319  );
183320 If(l_balance_type_code = 'A') THEN
183321   l_actual_gain_loss_ref := l_gain_or_loss_ref;
183322 END IF;
183323 
183324 --
183325 
183326       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
183327       -- or secondary ledger that has different currency with primary
183328       -- or alc that is calculated by sla
183329       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
183330             (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'))
183331 
183332 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
183333 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
183334           AND (l_actual_flag = 'A')) THEN
183335         XLA_AE_LINES_PKG.CreateGainOrLossLines(
183336           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
183337          ,p_application_id   => p_application_id
183338          ,p_amb_context_code => 'DEFAULT'
183339          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
183340          ,p_event_class_code => C_EVENT_CLASS_CODE
183341          ,p_event_type_code  => C_EVENT_TYPE_CODE
183342          
183343          ,p_gain_ccid        => -1
183344          ,p_loss_ccid        => -1
183345 
183346          ,p_actual_flag      => l_actual_flag
183347          ,p_enc_flag         => null
183348          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
183349          ,p_enc_g_l_ref      => null
183350          );
183351       END IF;
183352    END IF;
183353 END IF;
183354 
183355    ELSE
183356       --
183357       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
183358       --
183359       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
183360          trace
183361             (p_msg      => 'Trancaction revesal option is Y'
183362             ,p_level    => C_LEVEL_STATEMENT
183363             ,p_module   => l_log_module);
183364       END IF;
183365    END IF;
183366 
183367 END LOOP;
183368 l_result := XLA_AE_LINES_PKG.InsertLines ;
183369 end loop;
183370 close line_cur;
183371 
183372 
183373 --
183374 -- insert headers into xla_ae_headers_gt table
183375 --
183376 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
183377 
183378 -- insert into errors table here.
183379 
183380 END LOOP;
183381 
183382 --
183383 -- 4865292
183384 --
183385 -- Compare g_hdr_extract_count with event count in
183386 -- CreateHeadersAndLines.
183387 --
183388 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
183389 
183390 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
183391    trace (p_msg     => '# rows extracted from header extract objects '
183392                     || ' (running total): '
183393                     || g_hdr_extract_count
183394          ,p_level   => C_LEVEL_STATEMENT
183395          ,p_module  => l_log_module);
183396 END IF;
183397 
183398 CLOSE header_cur;
183399 --
183400 
183401 --
183402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
183403    trace
183404       (p_msg      => 'END of EventType_409'
183405       ,p_level    => C_LEVEL_PROCEDURE
183406       ,p_module   => l_log_module);
183407 END IF;
183408 --
183409 RETURN l_result;
183410 EXCEPTION
183411 WHEN xla_exceptions_pkg.application_exception THEN
183412    
183413 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
183414 
183415    
183419 
183416 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
183417 
183418    RAISE;
183420 WHEN NO_DATA_FOUND THEN
183421 
183422 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
183423 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
183424 
183425 FOR header_record IN header_cur
183426 LOOP
183427     l_array_header_events(header_record.event_id) := header_record.event_id;
183428 END LOOP;
183429 
183430 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
183431 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
183432 
183433 fnd_file.put_line(fnd_file.LOG, '                    ');
183434 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
183435 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
183436 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
183437 
183438 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
183439 LOOP
183440 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
183441 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
183442         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
183443 	END IF;
183444 END LOOP;
183445 
183446 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
183447 fnd_file.put_line(fnd_file.LOG, '                    ');
183448 
183449 
183450 xla_exceptions_pkg.raise_message
183451       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_409');
183452 
183453 
183454 WHEN OTHERS THEN
183455    xla_exceptions_pkg.raise_message
183456       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_409');
183457 END EventType_409;
183458 --
183459 
183460 ---------------------------------------
183461 --
183462 -- PRIVATE PROCEDURE
183463 --         insert_sources_410
183464 --
183465 ----------------------------------------
183466 --
183467 PROCEDURE insert_sources_410(
183468                                 p_target_ledger_id       IN NUMBER
183469                               , p_language               IN VARCHAR2
183470                               , p_sla_ledger_id          IN NUMBER
183471                               , p_pad_start_date         IN DATE
183472                               , p_pad_end_date           IN DATE
183473                          )
183474 IS
183475 
183476 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CATEGORY_RECLASS_ALL';
183477 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CATEGORY_RECLASS';
183478 p_apps_owner                   VARCHAR2(30);
183479 l_log_module                   VARCHAR2(240);
183480 BEGIN
183481 IF g_log_enabled THEN
183482       l_log_module := C_DEFAULT_MODULE||'.insert_sources_410';
183483 END IF;
183484 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
183485 
183486       trace
183487          (p_msg      => 'BEGIN of insert_sources_410'
183488          ,p_level    => C_LEVEL_PROCEDURE
183489          ,p_module   => l_log_module);
183490 
183491 END IF;
183492 
183493 -- select APPS owner
183494 SELECT oracle_username
183495   INTO p_apps_owner
183496   FROM fnd_oracle_userid
183497  WHERE read_only_flag = 'U'
183498 ;
183499 
183500 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
183501       trace
183502          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
183503                         ' - p_language = '||p_language||
183504                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
183505                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
183506                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
183507                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
183508          ,p_level    => C_LEVEL_STATEMENT
183509          ,p_module   => l_log_module);
183510 END IF;
183511 
183512 
183513 --
183514 INSERT INTO xla_diag_sources --hdr2
183515 (
183516         event_id
183517       , ledger_id
183518       , sla_ledger_id
183519       , description_language
183520       , object_name
183521       , object_type_code
183522       , line_number
183523       , source_application_id
183524       , source_type_code
183525       , source_code
183526       , source_value
183527       , source_meaning
183528       , created_by
183529       , creation_date
183530       , last_update_date
183531       , last_updated_by
183532       , last_update_login
183533       , program_update_date
183534       , program_application_id
183535       , program_id
183536       , request_id
183537 )
183538 SELECT
183539         event_id
183540       , p_target_ledger_id
183541       , p_sla_ledger_id
183542       , p_language
183543       , object_name
183544       , object_type_code
183545       , line_number
183546       , source_application_id
183547       , source_type_code
183548       , source_code
183549       , SUBSTR(source_value ,1,1996)
183550       , SUBSTR(source_meaning ,1,200)
183551       , xla_environment_pkg.g_Usr_Id
183552       , TRUNC(SYSDATE)
183553       , TRUNC(SYSDATE)
183554       , xla_environment_pkg.g_Usr_Id
183555       , xla_environment_pkg.g_Login_Id
183556       , TRUNC(SYSDATE)
183557       , xla_environment_pkg.g_Prog_Appl_Id
183558       , xla_environment_pkg.g_Prog_Id
183559       , xla_environment_pkg.g_Req_Id
183560   FROM (
183561        SELECT xet.event_id                  event_id
183562             , 0                          line_number
183563             , CASE r
183564                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
183565                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
183566                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
183567                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
183571             , CASE r
183568                 
183569                ELSE null
183570               END                           object_name
183572                 WHEN 1 THEN 'HEADER' 
183573                 WHEN 2 THEN 'HEADER' 
183574                 WHEN 3 THEN 'HEADER' 
183575                 WHEN 4 THEN 'HEADER' 
183576                 
183577                 ELSE null
183578               END                           object_type_code
183579             , CASE r
183580                 WHEN 1 THEN '140' 
183581                 WHEN 2 THEN '140' 
183582                 WHEN 3 THEN '140' 
183583                 WHEN 4 THEN '140' 
183584                 
183585                 ELSE null
183586               END                           source_application_id
183587             , 'S'             source_type_code
183588             , CASE r
183589                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
183590                 WHEN 2 THEN 'DEFAULT_CCID' 
183591                 WHEN 3 THEN 'ACCOUNTING_DATE' 
183592                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
183593                 
183594                 ELSE null
183595               END                           source_code
183596             , CASE r
183597                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
183598                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
183599                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
183600                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
183601                 
183602                 ELSE null
183603               END                           source_value
183604             , null              source_meaning
183605          FROM xla_events_gt     xet  
183606       , FA_XLA_EXT_HEADERS_B_GT  h1
183607              ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
183608          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
183609            AND xet.event_class_code = C_EVENT_CLASS_CODE
183610               AND h1.event_id = xet.event_id
183611 
183612 )
183613 ;
183614 --
183615 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
183616 
183617       trace
183618          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
183619          ,p_level    => C_LEVEL_STATEMENT
183620          ,p_module   => l_log_module);
183621 
183622 END IF;
183623 --
183624 
183625 
183626 
183627 --
183628 INSERT INTO xla_diag_sources  --line2
183629 (
183630         event_id
183631       , ledger_id
183632       , sla_ledger_id
183633       , description_language
183634       , object_name
183635       , object_type_code
183636       , line_number
183637       , source_application_id
183638       , source_type_code
183639       , source_code
183640       , source_value
183641       , source_meaning
183642       , created_by
183643       , creation_date
183644       , last_update_date
183645       , last_updated_by
183646       , last_update_login
183647       , program_update_date
183648       , program_application_id
183649       , program_id
183650       , request_id
183651 )
183652 SELECT  event_id
183653       , p_target_ledger_id
183654       , p_sla_ledger_id
183655       , p_language
183656       , object_name
183657       , object_type_code
183658       , line_number
183659       , source_application_id
183660       , source_type_code
183661       , source_code
183662       , SUBSTR(source_value,1,1996)
183663       , SUBSTR(source_meaning ,1,200)
183664       , xla_environment_pkg.g_Usr_Id
183665       , TRUNC(SYSDATE)
183666       , TRUNC(SYSDATE)
183667       , xla_environment_pkg.g_Usr_Id
183668       , xla_environment_pkg.g_Login_Id
183669       , TRUNC(SYSDATE)
183670       , xla_environment_pkg.g_Prog_Appl_Id
183671       , xla_environment_pkg.g_Prog_Id
183672       , xla_environment_pkg.g_Req_Id
183673   FROM (
183674        SELECT xet.event_id                  event_id
183675             , l2.line_number                 line_number
183676             , CASE r
183677                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
183678                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
183679                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
183680                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
183681                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
183682                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
183683                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
183684                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
183685                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
183686                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
183687                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
183688                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
183689                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
183690                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
183691                 WHEN 15 THEN 'FA_XLA_EXT_LINES_B_GT' 
183692                 
183693                ELSE null
183694               END                           object_name
183695             , CASE r
183696                 WHEN 1 THEN 'LINE' 
183697                 WHEN 2 THEN 'LINE' 
183698                 WHEN 3 THEN 'LINE' 
183699                 WHEN 4 THEN 'LINE' 
183700                 WHEN 5 THEN 'LINE' 
183701                 WHEN 6 THEN 'LINE' 
183702                 WHEN 7 THEN 'LINE' 
183703                 WHEN 8 THEN 'LINE' 
183704                 WHEN 9 THEN 'LINE' 
183705                 WHEN 10 THEN 'LINE' 
183706                 WHEN 11 THEN 'LINE' 
183707                 WHEN 12 THEN 'LINE' 
183708                 WHEN 13 THEN 'LINE' 
183709                 WHEN 14 THEN 'LINE' 
183710                 WHEN 15 THEN 'LINE' 
183711                 
183712                 ELSE null
183713               END                           object_type_code
183714             , CASE r
183715                 WHEN 1 THEN '140' 
183716                 WHEN 2 THEN '140' 
183720                 WHEN 6 THEN '140' 
183717                 WHEN 3 THEN '140' 
183718                 WHEN 4 THEN '140' 
183719                 WHEN 5 THEN '140' 
183721                 WHEN 7 THEN '140' 
183722                 WHEN 8 THEN '140' 
183723                 WHEN 9 THEN '140' 
183724                 WHEN 10 THEN '140' 
183725                 WHEN 11 THEN '140' 
183726                 WHEN 12 THEN '140' 
183727                 WHEN 13 THEN '140' 
183728                 WHEN 14 THEN '140' 
183729                 WHEN 15 THEN '140' 
183730                 
183731                 ELSE null
183732               END                           source_application_id
183733             , 'S'             source_type_code
183734             , CASE r
183735                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
183736                 WHEN 2 THEN 'GENERATED_CCID' 
183737                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
183738                 WHEN 4 THEN 'ASSET_COST_ACCT' 
183739                 WHEN 5 THEN 'DEPRN_RESERVE_ACCT' 
183740                 WHEN 6 THEN 'REVAL_RESERVE_ACCT' 
183741                 WHEN 7 THEN 'GENERATED_OFFSET_CCID' 
183742                 WHEN 8 THEN 'EXPENSE_ACCOUNT_CCID' 
183743                 WHEN 9 THEN 'ADJUSTMENT_TYPE' 
183744                 WHEN 10 THEN 'TRANSACTION_HEADER_ID' 
183745                 WHEN 11 THEN 'ADJUSTMENT_LINE_ID' 
183746                 WHEN 12 THEN 'DISTRIBUTION_TYPE_CODE' 
183747                 WHEN 13 THEN 'ENTERED_AMOUNT' 
183748                 WHEN 14 THEN 'CURRENCY_CODE' 
183749                 WHEN 15 THEN 'SOURCE_DEST_CODE' 
183750                 
183751                 ELSE null
183752               END                           source_code
183753             , CASE r
183754                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
183755                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
183756                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
183757                 WHEN 4 THEN TO_CHAR(l2.ASSET_COST_ACCT)
183758                 WHEN 5 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
183759                 WHEN 6 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
183760                 WHEN 7 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
183761                 WHEN 8 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
183762                 WHEN 9 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
183763                 WHEN 10 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
183764                 WHEN 11 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
183765                 WHEN 12 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
183766                 WHEN 13 THEN TO_CHAR(l2.ENTERED_AMOUNT)
183767                 WHEN 14 THEN TO_CHAR(l2.CURRENCY_CODE)
183768                 WHEN 15 THEN TO_CHAR(l2.SOURCE_DEST_CODE)
183769                 
183770                 ELSE null
183771               END                           source_value
183772             , null              source_meaning
183773          FROM  xla_events_gt     xet  
183774         , FA_XLA_EXT_LINES_B_GT  l2
183775             , (select rownum r from all_objects where rownum <= 15 and owner = p_apps_owner)
183776         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
183777           AND xet.event_class_code = C_EVENT_CLASS_CODE
183778             AND l2.event_id          = xet.event_id
183779   AND l2.ledger_id (+)  = p_sla_ledger_id
183780 
183781 )
183782 ;
183783 --
183784 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
183785 
183786       trace
183787          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
183788          ,p_level    => C_LEVEL_STATEMENT
183789          ,p_module   => l_log_module);
183790 
183791 END IF;
183792 
183793 
183794 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
183795       trace
183796          (p_msg      => 'END of insert_sources_410'
183797          ,p_level    => C_LEVEL_PROCEDURE
183798          ,p_module   => l_log_module);
183799 END IF;
183800 EXCEPTION
183801   WHEN xla_exceptions_pkg.application_exception THEN
183802       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
183803             trace
183804                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
183805                ,p_level    => C_LEVEL_EXCEPTION
183806                ,p_module   => l_log_module);
183807       END IF;
183808       RAISE;
183809   WHEN OTHERS THEN
183810       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
183811             trace
183812                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
183813                ,p_level    => C_LEVEL_EXCEPTION
183814                ,p_module   => l_log_module);
183815        END IF;
183816        xla_exceptions_pkg.raise_message
183817            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_410');
183818 END insert_sources_410;
183819 --
183820 
183821 ---------------------------------------
183822 --
183823 -- PRIVATE FUNCTION
183824 --         EventClass_410
183825 --
183826 ----------------------------------------
183827 --
183828 FUNCTION EventClass_410
183829        (p_application_id         IN NUMBER
183830        ,p_base_ledger_id         IN NUMBER
183831        ,p_target_ledger_id       IN NUMBER
183832        ,p_language               IN VARCHAR2
183833        ,p_currency_code          IN VARCHAR2
183834        ,p_sla_ledger_id          IN NUMBER
183835        ,p_pad_start_date         IN DATE
183836        ,p_pad_end_date           IN DATE
183837        ,p_primary_ledger_id      IN NUMBER)
183838 RETURN BOOLEAN IS
183839 --
183840 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CATEGORY_RECLASS_ALL';
183841 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CATEGORY_RECLASS';
183842 
183843 l_calculate_acctd_flag   VARCHAR2(1) :='N';
183844 l_calculate_g_l_flag     VARCHAR2(1) :='N';
183845 --
183846 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
183847 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
183848 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
183852 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
183849 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
183850 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
183851 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
183853 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
183854 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
183855 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
183856 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
183857 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
183858 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
183859 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
183860 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
183861 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
183862 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
183863 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
183864 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
183865 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
183866 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
183867 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
183868 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
183869 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
183870 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
183871 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
183872 
183873 l_event_id                             NUMBER;
183874 l_previous_event_id                    NUMBER;
183875 l_first_event_id                       NUMBER;
183876 l_last_event_id                        NUMBER;
183877 
183878 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
183879 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
183880 --
183881 --
183882 l_result                    BOOLEAN := TRUE;
183883 l_rows                      NUMBER  := 1000;
183884 l_event_type_name           VARCHAR2(80) := 'All';
183885 l_event_class_name          VARCHAR2(80) := 'Category Reclass';
183886 l_description               VARCHAR2(4000);
183887 l_transaction_reversal      NUMBER;
183888 l_ae_header_id              NUMBER;
183889 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
183890 l_log_module                VARCHAR2(240);
183891 --
183892 l_acct_reversal_source      VARCHAR2(30);
183893 l_trx_reversal_source       VARCHAR2(30);
183894 
183895 l_continue_with_lines       BOOLEAN := TRUE;
183896 --
183897 l_acc_rev_gl_date_source    DATE;                      -- 4262811
183898 --
183899 type t_array_event_id is table of number index by binary_integer;
183900 
183901 l_rec_array_event                    t_rec_array_event;
183902 l_null_rec_array_event               t_rec_array_event;
183903 l_array_ae_header_id                 xla_number_array_type;
183904 l_actual_flag                        VARCHAR2(1) := NULL;
183905 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
183906 l_balance_type_code                  VARCHAR2(1) :=NULL;
183907 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
183908 
183909 --
183910 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
183911 --
183912 
183913 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
183914 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
183915 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
183916 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
183917 
183918 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
183919 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
183920 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
183921 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
183922 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
183923 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
183924 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
183925 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
183926 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
183927 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
183928 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
183929 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
183930 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
183931 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
183932 TYPE t_array_source_42 IS TABLE OF FA_XLA_EXT_LINES_B_GT.SOURCE_DEST_CODE%TYPE INDEX BY BINARY_INTEGER;
183933 
183934 l_array_source_1              t_array_source_1;
183935 l_array_source_30              t_array_source_30;
183936 l_array_source_51              t_array_source_51;
183937 l_array_source_52              t_array_source_52;
183938 
183939 l_array_source_2      t_array_source_2;
183940 l_array_source_3      t_array_source_3;
183941 l_array_source_4      t_array_source_4;
183942 l_array_source_9      t_array_source_9;
183946 l_array_source_29      t_array_source_29;
183943 l_array_source_10      t_array_source_10;
183944 l_array_source_11      t_array_source_11;
183945 l_array_source_17      t_array_source_17;
183947 l_array_source_35      t_array_source_35;
183948 l_array_source_36      t_array_source_36;
183949 l_array_source_37      t_array_source_37;
183950 l_array_source_38      t_array_source_38;
183951 l_array_source_39      t_array_source_39;
183952 l_array_source_40      t_array_source_40;
183953 l_array_source_42      t_array_source_42;
183954 
183955 --
183956 CURSOR header_cur
183957 IS
183958 SELECT /*+ leading(xet) cardinality(xet,1) */
183959 -- Event Class Code: CATEGORY_RECLASS
183960     xet.entity_id
183961    ,xet.legal_entity_id
183962    ,xet.entity_code
183963    ,xet.transaction_number
183964    ,xet.event_id
183965    ,xet.event_class_code
183966    ,xet.event_type_code
183967    ,xet.event_number
183968    ,xet.event_date
183969    ,xet.transaction_date
183970    ,xet.reference_num_1
183971    ,xet.reference_num_2
183972    ,xet.reference_num_3
183973    ,xet.reference_num_4
183974    ,xet.reference_char_1
183975    ,xet.reference_char_2
183976    ,xet.reference_char_3
183977    ,xet.reference_char_4
183978    ,xet.reference_date_1
183979    ,xet.reference_date_2
183980    ,xet.reference_date_3
183981    ,xet.reference_date_4
183982    ,xet.event_created_by
183983    ,xet.budgetary_control_flag 
183984   , h1.PERIOD_CLOSE_DATE    source_1
183985   , h1.DEFAULT_CCID    source_30
183986   , h1.ACCOUNTING_DATE    source_51
183987   , h1.TRANSFER_TO_GL_FLAG    source_52
183988   FROM xla_events_gt     xet 
183989   , FA_XLA_EXT_HEADERS_B_GT  h1
183990  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
183991    and xet.event_class_code = C_EVENT_CLASS_CODE
183992    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
183993 
183994  ORDER BY event_id
183995 ;
183996 
183997 
183998 --
183999 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
184000 IS
184001 SELECT  /*+ leading(xet) cardinality(xet,1) */
184002 -- Event Class Code: CATEGORY_RECLASS
184003     xet.entity_id
184004    ,xet.legal_entity_id
184005    ,xet.entity_code
184006    ,xet.transaction_number
184007    ,xet.event_id
184008    ,xet.event_class_code
184009    ,xet.event_type_code
184010    ,xet.event_number
184011    ,xet.event_date
184012    ,xet.transaction_date
184013    ,xet.reference_num_1
184014    ,xet.reference_num_2
184015    ,xet.reference_num_3
184016    ,xet.reference_num_4
184017    ,xet.reference_char_1
184018    ,xet.reference_char_2
184019    ,xet.reference_char_3
184020    ,xet.reference_char_4
184021    ,xet.reference_date_1
184022    ,xet.reference_date_2
184023    ,xet.reference_date_3
184024    ,xet.reference_date_4
184025    ,xet.event_created_by
184026    ,xet.budgetary_control_flag
184027  , l2.LINE_NUMBER  
184028   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
184029   , l2.GENERATED_CCID    source_3
184030   , l2.BONUS_RESERVE_ACCT    source_4
184031   , l2.ASSET_COST_ACCT    source_9
184032   , l2.DEPRN_RESERVE_ACCT    source_10
184033   , l2.REVAL_RESERVE_ACCT    source_11
184034   , l2.GENERATED_OFFSET_CCID    source_17
184035   , l2.EXPENSE_ACCOUNT_CCID    source_29
184036   , l2.ADJUSTMENT_TYPE    source_35
184037   , l2.TRANSACTION_HEADER_ID    source_36
184038   , l2.ADJUSTMENT_LINE_ID    source_37
184039   , l2.DISTRIBUTION_TYPE_CODE    source_38
184040   , l2.ENTERED_AMOUNT    source_39
184041   , l2.CURRENCY_CODE    source_40
184042   , l2.SOURCE_DEST_CODE    source_42
184043   FROM xla_events_gt     xet 
184044   , FA_XLA_EXT_LINES_B_GT  l2
184045  WHERE xet.event_id between x_first_event_id and x_last_event_id
184046    and xet.event_date between p_pad_start_date and p_pad_end_date
184047    and xet.event_class_code = C_EVENT_CLASS_CODE
184048    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
184049   AND l2.ledger_id = p_sla_ledger_id
184050 ;
184051 
184052 --
184053 BEGIN
184054 IF g_log_enabled THEN
184055    l_log_module := C_DEFAULT_MODULE||'.EventClass_410';
184056 END IF;
184057 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
184058    trace
184059       (p_msg      => 'BEGIN of EventClass_410'
184060       ,p_level    => C_LEVEL_PROCEDURE
184061       ,p_module   => l_log_module);
184062 END IF;
184063 
184064 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
184065    trace
184066       (p_msg      => 'p_application_id = '||p_application_id||
184067                      ' - p_base_ledger_id = '||p_base_ledger_id||
184068                      ' - p_target_ledger_id  = '||p_target_ledger_id||
184069                      ' - p_language = '||p_language||
184070                      ' - p_currency_code = '||p_currency_code||
184071                      ' - p_sla_ledger_id = '||p_sla_ledger_id
184072       ,p_level    => C_LEVEL_STATEMENT
184073       ,p_module   => l_log_module);
184074 END IF;
184075 --
184076 -- initialze arrays
184077 --
184078 g_array_event.DELETE;
184079 l_rec_array_event := l_null_rec_array_event;
184080 --
184081 --------------------------------------
184082 -- 4262811 Initialze MPA Line Number
184083 --------------------------------------
184084 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
184085 
184086 --
184087 
184088 --
184089 OPEN header_cur;
184090 --
184091 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
184092    trace
184093    (p_msg      => 'SQL - FETCH header_cur'
184094    ,p_level    => C_LEVEL_STATEMENT
184095    ,p_module   => l_log_module);
184096 END IF;
184097 --
184098 LOOP
184099 FETCH header_cur BULK COLLECT INTO
184100         l_array_entity_id
184101       , l_array_legal_entity_id
184102       , l_array_entity_code
184103       , l_array_transaction_num
184104       , l_array_event_id
184108       , l_array_event_date
184105       , l_array_class_code
184106       , l_array_event_type
184107       , l_array_event_number
184109       , l_array_transaction_date
184110       , l_array_reference_num_1
184111       , l_array_reference_num_2
184112       , l_array_reference_num_3
184113       , l_array_reference_num_4
184114       , l_array_reference_char_1
184115       , l_array_reference_char_2
184116       , l_array_reference_char_3
184117       , l_array_reference_char_4
184118       , l_array_reference_date_1
184119       , l_array_reference_date_2
184120       , l_array_reference_date_3
184121       , l_array_reference_date_4
184122       , l_array_event_created_by
184123       , l_array_budgetary_control_flag 
184124       , l_array_source_1
184125       , l_array_source_30
184126       , l_array_source_51
184127       , l_array_source_52
184128       LIMIT l_rows;
184129 --
184130 IF (C_LEVEL_EVENT >= g_log_level) THEN
184131    trace
184132    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
184133    ,p_level    => C_LEVEL_EVENT
184134    ,p_module   => l_log_module);
184135 END IF;
184136 --
184137 EXIT WHEN l_array_entity_id.COUNT = 0;
184138 
184139 -- initialize arrays
184140 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
184141 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
184142 
184143 --
184144 -- Bug 4458708
184145 --
184146 XLA_AE_LINES_PKG.g_LineNumber := 0;
184147 
184148 
184149 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
184150 g_last_hdr_idx := l_array_event_id.LAST;
184151 --
184152 -- loop for the headers. Each iteration is for each header extract row
184153 -- fetched in header cursor
184154 --
184155 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
184156 
184157 --
184158 -- set event info as cache for other routines to refer event attributes
184159 --
184160 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
184161    (p_application_id           => p_application_id
184162    ,p_primary_ledger_id        => p_primary_ledger_id
184163    ,p_base_ledger_id           => p_base_ledger_id
184164    ,p_target_ledger_id         => p_target_ledger_id
184165    ,p_entity_id                => l_array_entity_id(hdr_idx)
184166    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
184167    ,p_entity_code              => l_array_entity_code(hdr_idx)
184168    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
184169    ,p_event_id                 => l_array_event_id(hdr_idx)
184170    ,p_event_class_code         => l_array_class_code(hdr_idx)
184171    ,p_event_type_code          => l_array_event_type(hdr_idx)
184172    ,p_event_number             => l_array_event_number(hdr_idx)
184173    ,p_event_date               => l_array_event_date(hdr_idx)
184174    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
184175    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
184176    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
184177    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
184178    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
184179    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
184180    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
184181    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
184182    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
184183    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
184184    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
184185    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
184186    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
184187    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
184188    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
184189 
184190 --
184191 -- set the status of entry to C_VALID (0)
184192 --
184193 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
184194 
184195 --
184196 -- initialize a row for ae header
184197 --
184198 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
184199 
184200 l_event_id := l_array_event_id(hdr_idx);
184201 
184202 --
184203 -- storing the hdr_idx for event. May be used by line cursor.
184204 --
184205 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
184206 
184207 --
184208 -- store sources from header extract. This can be improved to
184209 -- store only those sources from header extract that may be used in lines
184210 --
184211 
184212 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
184213 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
184214 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
184215 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
184216 
184217 --
184218 -- initilaize the status of ae headers for diffrent balance types
184219 -- the status is initialised to C_NOT_CREATED (2)
184220 --
184221 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
184222 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
184223 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
184224 
184225 --
184226 -- call api to validate and store accounting attributes for header
184227 --
184228 
184229 ------------------------------------------------------------
184230 -- Accrual Reversal : to get date for Standard Source (NONE)
184231 ------------------------------------------------------------
184232 l_acc_rev_gl_date_source := NULL;
184233 
184234      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
184238 
184235       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
184236      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
184237       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
184239 
184240 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
184241 
184242 XLA_AE_HEADER_PKG.SetJeCategoryName;
184243 
184244 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
184245 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
184246 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
184247 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
184248 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
184249 
184250 
184251 --
184252 xla_ae_header_pkg.SetHdrDescription(
184253    p_description => Description_62 (
184254    p_application_id => p_application_id 
184255  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184256    )
184257 );
184258 --
184259 
184260 -- No header level analytical criteria
184261 
184262 --
184263 --accounting attribute enhancement, bug 3612931
184264 --
184265 l_trx_reversal_source := SUBSTR(NULL, 1,30);
184266 
184267 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
184268    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
184269 
184270    xla_accounting_err_pkg.build_message
184271       (p_appli_s_name            => 'XLA'
184272       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
184273       ,p_token_1                 => 'ACCT_ATTR_NAME'
184274       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
184275       ,p_token_2                 => 'PRODUCT_NAME'
184276       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
184277       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
184278       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
184279       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
184280 
184281 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
184282    --
184283    -- following sets the accounting attributes needed to reverse
184284    -- accounting for a distributeion
184285    --
184286    xla_ae_lines_pkg.SetTrxReversalAttrs
184287       (p_event_id              => l_event_id
184288       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
184289       ,p_trx_reversal_source   => l_trx_reversal_source);
184290 
184291 END IF;
184292 
184293 
184294 ----------------------------------------------------------------
184295 -- 4262811 -  update the header statuses to invalid in need be
184296 ----------------------------------------------------------------
184297 --
184298 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
184299 
184300 
184301   -----------------------------------------------
184302   -- No accrual reversal for the event class/type
184303   -----------------------------------------------
184304 ----------------------------------------------------------------
184305 
184306 --
184307 -- this ends the header loop iteration for one bulk fetch
184308 --
184309 END LOOP;
184310 
184311 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
184312 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
184313 
184314 --
184315 -- insert dummy rows into lines gt table that were created due to
184316 -- transaction reversals
184317 --
184318 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
184319    l_result := XLA_AE_LINES_PKG.InsertLines;
184320 END IF;
184321 
184322 --
184323 -- reset the temp_line_num for each set of events fetched from header
184324 -- cursor rather than doing it for each new event in line cursor
184325 -- Bug 3939231
184326 --
184327 xla_ae_lines_pkg.g_temp_line_num := 0;
184328 
184329 
184330 
184331 --
184332 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
184333 --
184334 --
184335 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
184336 
184337       trace
184338          (p_msg      => 'SQL - FETCH line_cur'
184339          ,p_level    => C_LEVEL_STATEMENT
184340          ,p_module   => l_log_module);
184341 
184342 END IF;
184343 --
184344 --
184345 LOOP
184346   --
184347   FETCH line_cur BULK COLLECT INTO
184348         l_array_entity_id
184349       , l_array_legal_entity_id
184350       , l_array_entity_code
184351       , l_array_transaction_num
184352       , l_array_event_id
184353       , l_array_class_code
184354       , l_array_event_type
184355       , l_array_event_number
184356       , l_array_event_date
184357       , l_array_transaction_date
184358       , l_array_reference_num_1
184359       , l_array_reference_num_2
184360       , l_array_reference_num_3
184361       , l_array_reference_num_4
184362       , l_array_reference_char_1
184363       , l_array_reference_char_2
184364       , l_array_reference_char_3
184365       , l_array_reference_char_4
184366       , l_array_reference_date_1
184367       , l_array_reference_date_2
184368       , l_array_reference_date_3
184369       , l_array_reference_date_4
184370       , l_array_event_created_by
184371       , l_array_budgetary_control_flag
184372       , l_array_extract_line_num 
184373       , l_array_source_2
184374       , l_array_source_3
184375       , l_array_source_4
184376       , l_array_source_9
184377       , l_array_source_10
184378       , l_array_source_11
184379       , l_array_source_17
184380       , l_array_source_29
184381       , l_array_source_35
184385       , l_array_source_39
184382       , l_array_source_36
184383       , l_array_source_37
184384       , l_array_source_38
184386       , l_array_source_40
184387       , l_array_source_42
184388       LIMIT l_rows;
184389 
184390   --
184391   IF (C_LEVEL_EVENT >= g_log_level) THEN
184392             trace
184393                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
184394                ,p_level    => C_LEVEL_EVENT
184395                ,p_module   => l_log_module);
184396   END IF;
184397   --
184398   EXIT WHEN l_array_entity_id.count = 0;
184399 
184400   XLA_AE_LINES_PKG.g_rec_lines := null;
184401 
184402 --
184403 -- Bug 4458708
184404 --
184405 XLA_AE_LINES_PKG.g_LineNumber := 0;
184406 --
184407 --
184408 
184409 FOR Idx IN 1..l_array_event_id.count LOOP
184410    --
184411    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
184412    --
184413    l_event_id := l_array_event_id(idx);  -- 5648433
184414 
184415    --
184416    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
184417    --
184418 
184419    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
184420              (g_array_event(l_event_id).array_value_num('header_index'))
184421          ,'N'
184422          ) <> 'Y'
184423    THEN
184424       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
184425          trace
184426             (p_msg      => 'Trancaction revesal option is not Y '
184427             ,p_level    => C_LEVEL_STATEMENT
184428             ,p_module   => l_log_module);
184429       END IF;
184430 
184431 --
184432 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
184433 --
184434 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
184435 --
184436 -- set event info as cache for other routines to refer event attributes
184437 --
184438 
184439 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
184440    l_previous_event_id := l_event_id;
184441 
184442    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
184443       (p_application_id           => p_application_id
184444       ,p_primary_ledger_id        => p_primary_ledger_id
184445       ,p_base_ledger_id           => p_base_ledger_id
184446       ,p_target_ledger_id         => p_target_ledger_id
184447       ,p_entity_id                => l_array_entity_id(Idx)
184448       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
184449       ,p_entity_code              => l_array_entity_code(Idx)
184450       ,p_transaction_num          => l_array_transaction_num(Idx)
184451       ,p_event_id                 => l_array_event_id(Idx)
184452       ,p_event_class_code         => l_array_class_code(Idx)
184453       ,p_event_type_code          => l_array_event_type(Idx)
184454       ,p_event_number             => l_array_event_number(Idx)
184455       ,p_event_date               => l_array_event_date(Idx)
184456       ,p_transaction_date         => l_array_transaction_date(Idx)
184457       ,p_reference_num_1          => l_array_reference_num_1(Idx)
184458       ,p_reference_num_2          => l_array_reference_num_2(Idx)
184459       ,p_reference_num_3          => l_array_reference_num_3(Idx)
184460       ,p_reference_num_4          => l_array_reference_num_4(Idx)
184461       ,p_reference_char_1         => l_array_reference_char_1(Idx)
184462       ,p_reference_char_2         => l_array_reference_char_2(Idx)
184463       ,p_reference_char_3         => l_array_reference_char_3(Idx)
184464       ,p_reference_char_4         => l_array_reference_char_4(Idx)
184465       ,p_reference_date_1         => l_array_reference_date_1(Idx)
184466       ,p_reference_date_2         => l_array_reference_date_2(Idx)
184467       ,p_reference_date_3         => l_array_reference_date_3(Idx)
184468       ,p_reference_date_4         => l_array_reference_date_4(Idx)
184469       ,p_event_created_by         => l_array_event_created_by(Idx)
184470       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
184471        --
184472 END IF;
184473 
184474 
184475 
184476 --
184477 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
184478 
184479 l_acct_reversal_source := SUBSTR(NULL, 1,30);
184480 
184481 IF l_continue_with_lines THEN
184482    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
184483       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
184484 
184485       xla_accounting_err_pkg.build_message
184486          (p_appli_s_name            => 'XLA'
184487          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
184488          ,p_token_1                 => 'LINE_NUMBER'
184489          ,p_value_1                 => l_array_extract_line_num(Idx)
184490          ,p_token_2                 => 'PRODUCT_NAME'
184491          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
184492          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
184493          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
184494          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
184495 
184496    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
184497       --
184498       -- following sets the accounting attributes needed to reverse
184499       -- accounting for a distributeion
184500       --
184501 
184502       --
184503       -- 5217187
184504       --
184505       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
184506       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
184507                                        g_array_event(l_event_id).array_value_num('header_index'));
184508       --
184509       --
184510 
184511       -- No reversal code generated
184512 
184513       xla_ae_lines_pkg.SetAcctReversalAttrs
184514          (p_event_id             => l_event_id
184518    END IF;
184515          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
184516          ,p_calculate_acctd_flag => l_calculate_acctd_flag
184517          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
184519 
184520    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
184521        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
184522 
184523 --
184524 AcctLineType_279 (
184525  p_application_id  => p_application_id
184526  ,p_event_id     => l_event_id
184527  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184528  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184529  ,p_actual_flag => l_actual_flag
184530  ,p_balance_type_code => l_balance_type_code
184531  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184532  
184533  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184534  , p_source_2 => l_array_source_2(Idx)
184535  , p_source_3 => l_array_source_3(Idx)
184536  , p_source_29 => l_array_source_29(Idx)
184537  , p_source_35 => l_array_source_35(Idx)
184538  , p_source_36 => l_array_source_36(Idx)
184539  , p_source_37 => l_array_source_37(Idx)
184540  , p_source_38 => l_array_source_38(Idx)
184541  , p_source_39 => l_array_source_39(Idx)
184542  , p_source_40 => l_array_source_40(Idx)
184543  , p_source_42 => l_array_source_42(Idx)
184544  );
184545 If(l_balance_type_code = 'A') THEN
184546   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184547 END IF;
184548 
184549 --
184550 
184551 
184552 --
184553 AcctLineType_280 (
184554  p_application_id  => p_application_id
184555  ,p_event_id     => l_event_id
184556  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184557  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184558  ,p_actual_flag => l_actual_flag
184559  ,p_balance_type_code => l_balance_type_code
184560  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184561  
184562  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184563  , p_source_3 => l_array_source_3(Idx)
184564  , p_source_4 => l_array_source_4(Idx)
184565  , p_source_17 => l_array_source_17(Idx)
184566  , p_source_29 => l_array_source_29(Idx)
184567  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
184568  , p_source_35 => l_array_source_35(Idx)
184569  , p_source_36 => l_array_source_36(Idx)
184570  , p_source_37 => l_array_source_37(Idx)
184571  , p_source_38 => l_array_source_38(Idx)
184572  , p_source_39 => l_array_source_39(Idx)
184573  , p_source_40 => l_array_source_40(Idx)
184574  , p_source_42 => l_array_source_42(Idx)
184575  );
184576 If(l_balance_type_code = 'A') THEN
184577   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184578 END IF;
184579 
184580 --
184581 
184582 
184583 --
184584 AcctLineType_281 (
184585  p_application_id  => p_application_id
184586  ,p_event_id     => l_event_id
184587  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184588  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184589  ,p_actual_flag => l_actual_flag
184590  ,p_balance_type_code => l_balance_type_code
184591  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184592  
184593  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184594  , p_source_3 => l_array_source_3(Idx)
184595  , p_source_9 => l_array_source_9(Idx)
184596  , p_source_29 => l_array_source_29(Idx)
184597  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
184598  , p_source_35 => l_array_source_35(Idx)
184599  , p_source_36 => l_array_source_36(Idx)
184600  , p_source_37 => l_array_source_37(Idx)
184601  , p_source_38 => l_array_source_38(Idx)
184602  , p_source_39 => l_array_source_39(Idx)
184603  , p_source_40 => l_array_source_40(Idx)
184604  , p_source_42 => l_array_source_42(Idx)
184605  );
184606 If(l_balance_type_code = 'A') THEN
184607   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184608 END IF;
184609 
184610 --
184611 
184612 
184613 --
184614 AcctLineType_282 (
184615  p_application_id  => p_application_id
184616  ,p_event_id     => l_event_id
184617  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184618  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184619  ,p_actual_flag => l_actual_flag
184620  ,p_balance_type_code => l_balance_type_code
184621  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184622  
184623  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184624  , p_source_3 => l_array_source_3(Idx)
184625  , p_source_29 => l_array_source_29(Idx)
184626  , p_source_35 => l_array_source_35(Idx)
184627  , p_source_36 => l_array_source_36(Idx)
184628  , p_source_37 => l_array_source_37(Idx)
184629  , p_source_38 => l_array_source_38(Idx)
184630  , p_source_39 => l_array_source_39(Idx)
184631  , p_source_40 => l_array_source_40(Idx)
184632  , p_source_42 => l_array_source_42(Idx)
184633  );
184634 If(l_balance_type_code = 'A') THEN
184635   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184636 END IF;
184637 
184638 --
184639 
184640 
184641 --
184642 AcctLineType_283 (
184643  p_application_id  => p_application_id
184644  ,p_event_id     => l_event_id
184645  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184646  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184647  ,p_actual_flag => l_actual_flag
184648  ,p_balance_type_code => l_balance_type_code
184649  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184650  
184651  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184652  , p_source_3 => l_array_source_3(Idx)
184653  , p_source_10 => l_array_source_10(Idx)
184654  , p_source_29 => l_array_source_29(Idx)
184655  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
184656  , p_source_35 => l_array_source_35(Idx)
184657  , p_source_36 => l_array_source_36(Idx)
184658  , p_source_37 => l_array_source_37(Idx)
184659  , p_source_38 => l_array_source_38(Idx)
184660  , p_source_39 => l_array_source_39(Idx)
184661  , p_source_40 => l_array_source_40(Idx)
184662  , p_source_42 => l_array_source_42(Idx)
184663  );
184667 
184664 If(l_balance_type_code = 'A') THEN
184665   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184666 END IF;
184668 --
184669 
184670 
184671 --
184672 AcctLineType_284 (
184673  p_application_id  => p_application_id
184674  ,p_event_id     => l_event_id
184675  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184676  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184677  ,p_actual_flag => l_actual_flag
184678  ,p_balance_type_code => l_balance_type_code
184679  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184680  
184681  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184682  , p_source_3 => l_array_source_3(Idx)
184683  , p_source_11 => l_array_source_11(Idx)
184684  , p_source_29 => l_array_source_29(Idx)
184685  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
184686  , p_source_35 => l_array_source_35(Idx)
184687  , p_source_36 => l_array_source_36(Idx)
184688  , p_source_37 => l_array_source_37(Idx)
184689  , p_source_38 => l_array_source_38(Idx)
184690  , p_source_39 => l_array_source_39(Idx)
184691  , p_source_40 => l_array_source_40(Idx)
184692  , p_source_42 => l_array_source_42(Idx)
184693  );
184694 If(l_balance_type_code = 'A') THEN
184695   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184696 END IF;
184697 
184698 --
184699 
184700 
184701 --
184702 AcctLineType_285 (
184703  p_application_id  => p_application_id
184704  ,p_event_id     => l_event_id
184705  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184706  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184707  ,p_actual_flag => l_actual_flag
184708  ,p_balance_type_code => l_balance_type_code
184709  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184710  
184711  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184712  , p_source_2 => l_array_source_2(Idx)
184713  , p_source_3 => l_array_source_3(Idx)
184714  , p_source_29 => l_array_source_29(Idx)
184715  , p_source_35 => l_array_source_35(Idx)
184716  , p_source_36 => l_array_source_36(Idx)
184717  , p_source_37 => l_array_source_37(Idx)
184718  , p_source_38 => l_array_source_38(Idx)
184719  , p_source_39 => l_array_source_39(Idx)
184720  , p_source_40 => l_array_source_40(Idx)
184721  , p_source_42 => l_array_source_42(Idx)
184722  );
184723 If(l_balance_type_code = 'A') THEN
184724   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184725 END IF;
184726 
184727 --
184728 
184729 
184730 --
184731 AcctLineType_286 (
184732  p_application_id  => p_application_id
184733  ,p_event_id     => l_event_id
184734  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184735  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184736  ,p_actual_flag => l_actual_flag
184737  ,p_balance_type_code => l_balance_type_code
184738  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184739  
184740  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184741  , p_source_3 => l_array_source_3(Idx)
184742  , p_source_4 => l_array_source_4(Idx)
184743  , p_source_17 => l_array_source_17(Idx)
184744  , p_source_29 => l_array_source_29(Idx)
184745  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
184746  , p_source_35 => l_array_source_35(Idx)
184747  , p_source_36 => l_array_source_36(Idx)
184748  , p_source_37 => l_array_source_37(Idx)
184749  , p_source_38 => l_array_source_38(Idx)
184750  , p_source_39 => l_array_source_39(Idx)
184751  , p_source_40 => l_array_source_40(Idx)
184752  , p_source_42 => l_array_source_42(Idx)
184753  );
184754 If(l_balance_type_code = 'A') THEN
184755   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184756 END IF;
184757 
184758 --
184759 
184760 
184761 --
184762 AcctLineType_287 (
184763  p_application_id  => p_application_id
184764  ,p_event_id     => l_event_id
184765  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184766  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184767  ,p_actual_flag => l_actual_flag
184768  ,p_balance_type_code => l_balance_type_code
184769  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184770  
184771  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184772  , p_source_3 => l_array_source_3(Idx)
184773  , p_source_9 => l_array_source_9(Idx)
184774  , p_source_29 => l_array_source_29(Idx)
184775  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
184776  , p_source_35 => l_array_source_35(Idx)
184777  , p_source_36 => l_array_source_36(Idx)
184778  , p_source_37 => l_array_source_37(Idx)
184779  , p_source_38 => l_array_source_38(Idx)
184780  , p_source_39 => l_array_source_39(Idx)
184781  , p_source_40 => l_array_source_40(Idx)
184782  , p_source_42 => l_array_source_42(Idx)
184783  );
184784 If(l_balance_type_code = 'A') THEN
184785   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184786 END IF;
184787 
184788 --
184789 
184790 
184791 --
184792 AcctLineType_288 (
184793  p_application_id  => p_application_id
184794  ,p_event_id     => l_event_id
184795  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184796  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184797  ,p_actual_flag => l_actual_flag
184798  ,p_balance_type_code => l_balance_type_code
184799  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184800  
184801  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184802  , p_source_3 => l_array_source_3(Idx)
184803  , p_source_29 => l_array_source_29(Idx)
184804  , p_source_35 => l_array_source_35(Idx)
184805  , p_source_36 => l_array_source_36(Idx)
184806  , p_source_37 => l_array_source_37(Idx)
184807  , p_source_38 => l_array_source_38(Idx)
184808  , p_source_39 => l_array_source_39(Idx)
184809  , p_source_40 => l_array_source_40(Idx)
184810  , p_source_42 => l_array_source_42(Idx)
184811  );
184812 If(l_balance_type_code = 'A') THEN
184813   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184814 END IF;
184815 
184816 --
184817 
184818 
184819 --
184823  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184820 AcctLineType_289 (
184821  p_application_id  => p_application_id
184822  ,p_event_id     => l_event_id
184824  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184825  ,p_actual_flag => l_actual_flag
184826  ,p_balance_type_code => l_balance_type_code
184827  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184828  
184829  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184830  , p_source_3 => l_array_source_3(Idx)
184831  , p_source_10 => l_array_source_10(Idx)
184832  , p_source_17 => l_array_source_17(Idx)
184833  , p_source_29 => l_array_source_29(Idx)
184834  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
184835  , p_source_35 => l_array_source_35(Idx)
184836  , p_source_36 => l_array_source_36(Idx)
184837  , p_source_37 => l_array_source_37(Idx)
184838  , p_source_38 => l_array_source_38(Idx)
184839  , p_source_39 => l_array_source_39(Idx)
184840  , p_source_40 => l_array_source_40(Idx)
184841  , p_source_42 => l_array_source_42(Idx)
184842  );
184843 If(l_balance_type_code = 'A') THEN
184844   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184845 END IF;
184846 
184847 --
184848 
184849 
184850 --
184851 AcctLineType_290 (
184852  p_application_id  => p_application_id
184853  ,p_event_id     => l_event_id
184854  ,p_calculate_acctd_flag => l_calculate_acctd_flag
184855  ,p_calculate_g_l_flag => l_calculate_g_l_flag
184856  ,p_actual_flag => l_actual_flag
184857  ,p_balance_type_code => l_balance_type_code
184858  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
184859  
184860  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
184861  , p_source_3 => l_array_source_3(Idx)
184862  , p_source_11 => l_array_source_11(Idx)
184863  , p_source_17 => l_array_source_17(Idx)
184864  , p_source_29 => l_array_source_29(Idx)
184865  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
184866  , p_source_35 => l_array_source_35(Idx)
184867  , p_source_36 => l_array_source_36(Idx)
184868  , p_source_37 => l_array_source_37(Idx)
184869  , p_source_38 => l_array_source_38(Idx)
184870  , p_source_39 => l_array_source_39(Idx)
184871  , p_source_40 => l_array_source_40(Idx)
184872  , p_source_42 => l_array_source_42(Idx)
184873  );
184874 If(l_balance_type_code = 'A') THEN
184875   l_actual_gain_loss_ref := l_gain_or_loss_ref;
184876 END IF;
184877 
184878 --
184879 
184880       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
184881       -- or secondary ledger that has different currency with primary
184882       -- or alc that is calculated by sla
184883       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
184884             (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'))
184885 
184886 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
184887 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
184888           AND (l_actual_flag = 'A')) THEN
184889         XLA_AE_LINES_PKG.CreateGainOrLossLines(
184890           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
184891          ,p_application_id   => p_application_id
184892          ,p_amb_context_code => 'DEFAULT'
184893          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
184894          ,p_event_class_code => C_EVENT_CLASS_CODE
184895          ,p_event_type_code  => C_EVENT_TYPE_CODE
184896          
184897          ,p_gain_ccid        => -1
184898          ,p_loss_ccid        => -1
184899 
184900          ,p_actual_flag      => l_actual_flag
184901          ,p_enc_flag         => null
184902          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
184903          ,p_enc_g_l_ref      => null
184904          );
184905       END IF;
184906    END IF;
184907 END IF;
184908 
184909    ELSE
184910       --
184911       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
184912       --
184913       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
184914          trace
184915             (p_msg      => 'Trancaction revesal option is Y'
184916             ,p_level    => C_LEVEL_STATEMENT
184917             ,p_module   => l_log_module);
184918       END IF;
184919    END IF;
184920 
184921 END LOOP;
184922 l_result := XLA_AE_LINES_PKG.InsertLines ;
184923 end loop;
184924 close line_cur;
184925 
184926 
184927 --
184928 -- insert headers into xla_ae_headers_gt table
184929 --
184930 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
184931 
184932 -- insert into errors table here.
184933 
184934 END LOOP;
184935 
184936 --
184937 -- 4865292
184938 --
184939 -- Compare g_hdr_extract_count with event count in
184940 -- CreateHeadersAndLines.
184941 --
184942 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
184943 
184944 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
184945    trace (p_msg     => '# rows extracted from header extract objects '
184946                     || ' (running total): '
184947                     || g_hdr_extract_count
184948          ,p_level   => C_LEVEL_STATEMENT
184949          ,p_module  => l_log_module);
184950 END IF;
184951 
184952 CLOSE header_cur;
184953 --
184954 
184955 --
184956 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
184957    trace
184958       (p_msg      => 'END of EventClass_410'
184959       ,p_level    => C_LEVEL_PROCEDURE
184960       ,p_module   => l_log_module);
184961 END IF;
184962 --
184963 RETURN l_result;
184964 EXCEPTION
184965 WHEN xla_exceptions_pkg.application_exception THEN
184966    
184967 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
184968 
184969    
184970 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
184971 
184975 
184972    RAISE;
184973 
184974 WHEN NO_DATA_FOUND THEN
184976 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
184977 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
184978 
184979 FOR header_record IN header_cur
184980 LOOP
184981     l_array_header_events(header_record.event_id) := header_record.event_id;
184982 END LOOP;
184983 
184984 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
184985 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
184986 
184987 fnd_file.put_line(fnd_file.LOG, '                    ');
184988 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
184989 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
184990 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
184991 
184992 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
184993 LOOP
184994 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
184995 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
184996         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
184997 	END IF;
184998 END LOOP;
184999 
185000 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
185001 fnd_file.put_line(fnd_file.LOG, '                    ');
185002 
185003 
185004 xla_exceptions_pkg.raise_message
185005       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_410');
185006 
185007 
185008 WHEN OTHERS THEN
185009    xla_exceptions_pkg.raise_message
185010       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_410');
185011 END EventClass_410;
185012 --
185013 
185014 ---------------------------------------
185015 --
185016 -- PRIVATE PROCEDURE
185017 --         insert_sources_411
185018 --
185019 ----------------------------------------
185020 --
185021 PROCEDURE insert_sources_411(
185022                                 p_target_ledger_id       IN NUMBER
185023                               , p_language               IN VARCHAR2
185024                               , p_sla_ledger_id          IN NUMBER
185025                               , p_pad_start_date         IN DATE
185026                               , p_pad_end_date           IN DATE
185027                          )
185028 IS
185029 
185030 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_ADDITIONS_ALL';
185031 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CIP_ADDITIONS';
185032 p_apps_owner                   VARCHAR2(30);
185033 l_log_module                   VARCHAR2(240);
185034 BEGIN
185035 IF g_log_enabled THEN
185036       l_log_module := C_DEFAULT_MODULE||'.insert_sources_411';
185037 END IF;
185038 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
185039 
185040       trace
185041          (p_msg      => 'BEGIN of insert_sources_411'
185042          ,p_level    => C_LEVEL_PROCEDURE
185043          ,p_module   => l_log_module);
185044 
185045 END IF;
185046 
185047 -- select APPS owner
185048 SELECT oracle_username
185049   INTO p_apps_owner
185050   FROM fnd_oracle_userid
185051  WHERE read_only_flag = 'U'
185052 ;
185053 
185054 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
185055       trace
185056          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
185057                         ' - p_language = '||p_language||
185058                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
185059                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
185060                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
185061                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
185062          ,p_level    => C_LEVEL_STATEMENT
185063          ,p_module   => l_log_module);
185064 END IF;
185065 
185066 
185067 --
185068 INSERT INTO xla_diag_sources --hdr2
185069 (
185070         event_id
185071       , ledger_id
185072       , sla_ledger_id
185073       , description_language
185074       , object_name
185075       , object_type_code
185076       , line_number
185077       , source_application_id
185078       , source_type_code
185079       , source_code
185080       , source_value
185081       , source_meaning
185082       , created_by
185083       , creation_date
185084       , last_update_date
185085       , last_updated_by
185086       , last_update_login
185087       , program_update_date
185088       , program_application_id
185089       , program_id
185090       , request_id
185091 )
185092 SELECT
185093         event_id
185094       , p_target_ledger_id
185095       , p_sla_ledger_id
185096       , p_language
185097       , object_name
185098       , object_type_code
185099       , line_number
185100       , source_application_id
185101       , source_type_code
185102       , source_code
185103       , SUBSTR(source_value ,1,1996)
185104       , SUBSTR(source_meaning ,1,200)
185105       , xla_environment_pkg.g_Usr_Id
185106       , TRUNC(SYSDATE)
185107       , TRUNC(SYSDATE)
185108       , xla_environment_pkg.g_Usr_Id
185109       , xla_environment_pkg.g_Login_Id
185110       , TRUNC(SYSDATE)
185111       , xla_environment_pkg.g_Prog_Appl_Id
185112       , xla_environment_pkg.g_Prog_Id
185113       , xla_environment_pkg.g_Req_Id
185114   FROM (
185115        SELECT xet.event_id                  event_id
185116             , 0                          line_number
185117             , CASE r
185118                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
185119                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
185120                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
185121                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
185122                 
185123                ELSE null
185127                 WHEN 2 THEN 'HEADER' 
185124               END                           object_name
185125             , CASE r
185126                 WHEN 1 THEN 'HEADER' 
185128                 WHEN 3 THEN 'HEADER' 
185129                 WHEN 4 THEN 'HEADER' 
185130                 
185131                 ELSE null
185132               END                           object_type_code
185133             , CASE r
185134                 WHEN 1 THEN '140' 
185135                 WHEN 2 THEN '140' 
185136                 WHEN 3 THEN '140' 
185137                 WHEN 4 THEN '140' 
185138                 
185139                 ELSE null
185140               END                           source_application_id
185141             , 'S'             source_type_code
185142             , CASE r
185143                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
185144                 WHEN 2 THEN 'DEFAULT_CCID' 
185145                 WHEN 3 THEN 'ACCOUNTING_DATE' 
185146                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
185147                 
185148                 ELSE null
185149               END                           source_code
185150             , CASE r
185151                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
185152                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
185153                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
185154                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
185155                 
185156                 ELSE null
185157               END                           source_value
185158             , null              source_meaning
185159          FROM xla_events_gt     xet  
185160       , FA_XLA_EXT_HEADERS_B_GT  h1
185161              ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
185162          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
185163            AND xet.event_class_code = C_EVENT_CLASS_CODE
185164               AND h1.event_id = xet.event_id
185165 
185166 )
185167 ;
185168 --
185169 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
185170 
185171       trace
185172          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
185173          ,p_level    => C_LEVEL_STATEMENT
185174          ,p_module   => l_log_module);
185175 
185176 END IF;
185177 --
185178 
185179 
185180 
185181 --
185182 INSERT INTO xla_diag_sources  --line2
185183 (
185184         event_id
185185       , ledger_id
185186       , sla_ledger_id
185187       , description_language
185188       , object_name
185189       , object_type_code
185190       , line_number
185191       , source_application_id
185192       , source_type_code
185193       , source_code
185194       , source_value
185195       , source_meaning
185196       , created_by
185197       , creation_date
185198       , last_update_date
185199       , last_updated_by
185200       , last_update_login
185201       , program_update_date
185202       , program_application_id
185203       , program_id
185204       , request_id
185205 )
185206 SELECT  event_id
185207       , p_target_ledger_id
185208       , p_sla_ledger_id
185209       , p_language
185210       , object_name
185211       , object_type_code
185212       , line_number
185213       , source_application_id
185214       , source_type_code
185215       , source_code
185216       , SUBSTR(source_value,1,1996)
185217       , SUBSTR(source_meaning ,1,200)
185218       , xla_environment_pkg.g_Usr_Id
185219       , TRUNC(SYSDATE)
185220       , TRUNC(SYSDATE)
185221       , xla_environment_pkg.g_Usr_Id
185222       , xla_environment_pkg.g_Login_Id
185223       , TRUNC(SYSDATE)
185224       , xla_environment_pkg.g_Prog_Appl_Id
185225       , xla_environment_pkg.g_Prog_Id
185226       , xla_environment_pkg.g_Req_Id
185227   FROM (
185228        SELECT xet.event_id                  event_id
185229             , l2.line_number                 line_number
185230             , CASE r
185231                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
185232                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
185233                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
185234                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
185235                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
185236                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
185237                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
185238                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
185239                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
185240                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
185241                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
185242                 
185243                ELSE null
185244               END                           object_name
185245             , CASE r
185246                 WHEN 1 THEN 'LINE' 
185247                 WHEN 2 THEN 'LINE' 
185248                 WHEN 3 THEN 'LINE' 
185249                 WHEN 4 THEN 'LINE' 
185250                 WHEN 5 THEN 'LINE' 
185251                 WHEN 6 THEN 'LINE' 
185252                 WHEN 7 THEN 'LINE' 
185253                 WHEN 8 THEN 'LINE' 
185254                 WHEN 9 THEN 'LINE' 
185255                 WHEN 10 THEN 'LINE' 
185256                 WHEN 11 THEN 'LINE' 
185257                 
185258                 ELSE null
185259               END                           object_type_code
185260             , CASE r
185261                 WHEN 1 THEN '140' 
185262                 WHEN 2 THEN '140' 
185263                 WHEN 3 THEN '140' 
185264                 WHEN 4 THEN '140' 
185265                 WHEN 5 THEN '140' 
185266                 WHEN 6 THEN '140' 
185267                 WHEN 7 THEN '140' 
185268                 WHEN 8 THEN '140' 
185269                 WHEN 9 THEN '140' 
185270                 WHEN 10 THEN '140' 
185271                 WHEN 11 THEN '140' 
185272                 
185273                 ELSE null
185277                 WHEN 1 THEN 'GENERATED_CCID' 
185274               END                           source_application_id
185275             , 'S'             source_type_code
185276             , CASE r
185278                 WHEN 2 THEN 'CIP_CLEARING_ACCT' 
185279                 WHEN 3 THEN 'PAYABLES_CCID' 
185280                 WHEN 4 THEN 'CIP_COST_ACCT' 
185281                 WHEN 5 THEN 'EXPENSE_ACCOUNT_CCID' 
185282                 WHEN 6 THEN 'ADJUSTMENT_TYPE' 
185283                 WHEN 7 THEN 'TRANSACTION_HEADER_ID' 
185284                 WHEN 8 THEN 'ADJUSTMENT_LINE_ID' 
185285                 WHEN 9 THEN 'DISTRIBUTION_TYPE_CODE' 
185286                 WHEN 10 THEN 'ENTERED_AMOUNT' 
185287                 WHEN 11 THEN 'CURRENCY_CODE' 
185288                 
185289                 ELSE null
185290               END                           source_code
185291             , CASE r
185292                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
185293                 WHEN 2 THEN TO_CHAR(l2.CIP_CLEARING_ACCT)
185294                 WHEN 3 THEN TO_CHAR(l2.PAYABLES_CCID)
185295                 WHEN 4 THEN TO_CHAR(l2.CIP_COST_ACCT)
185296                 WHEN 5 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
185297                 WHEN 6 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
185298                 WHEN 7 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
185299                 WHEN 8 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
185300                 WHEN 9 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
185301                 WHEN 10 THEN TO_CHAR(l2.ENTERED_AMOUNT)
185302                 WHEN 11 THEN TO_CHAR(l2.CURRENCY_CODE)
185303                 
185304                 ELSE null
185305               END                           source_value
185306             , null              source_meaning
185307          FROM  xla_events_gt     xet  
185308         , FA_XLA_EXT_LINES_B_GT  l2
185309             , (select rownum r from all_objects where rownum <= 11 and owner = p_apps_owner)
185310         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
185311           AND xet.event_class_code = C_EVENT_CLASS_CODE
185312             AND l2.event_id          = xet.event_id
185313   AND l2.ledger_id (+)  = p_sla_ledger_id
185314 
185315 )
185316 ;
185317 --
185318 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
185319 
185320       trace
185321          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
185322          ,p_level    => C_LEVEL_STATEMENT
185323          ,p_module   => l_log_module);
185324 
185325 END IF;
185326 
185327 
185328 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
185329       trace
185330          (p_msg      => 'END of insert_sources_411'
185331          ,p_level    => C_LEVEL_PROCEDURE
185332          ,p_module   => l_log_module);
185333 END IF;
185334 EXCEPTION
185335   WHEN xla_exceptions_pkg.application_exception THEN
185336       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
185337             trace
185338                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
185339                ,p_level    => C_LEVEL_EXCEPTION
185340                ,p_module   => l_log_module);
185341       END IF;
185342       RAISE;
185343   WHEN OTHERS THEN
185344       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
185345             trace
185346                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
185347                ,p_level    => C_LEVEL_EXCEPTION
185348                ,p_module   => l_log_module);
185349        END IF;
185350        xla_exceptions_pkg.raise_message
185351            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_411');
185352 END insert_sources_411;
185353 --
185354 
185355 ---------------------------------------
185356 --
185357 -- PRIVATE FUNCTION
185358 --         EventClass_411
185359 --
185360 ----------------------------------------
185361 --
185362 FUNCTION EventClass_411
185363        (p_application_id         IN NUMBER
185364        ,p_base_ledger_id         IN NUMBER
185365        ,p_target_ledger_id       IN NUMBER
185366        ,p_language               IN VARCHAR2
185367        ,p_currency_code          IN VARCHAR2
185368        ,p_sla_ledger_id          IN NUMBER
185369        ,p_pad_start_date         IN DATE
185370        ,p_pad_end_date           IN DATE
185371        ,p_primary_ledger_id      IN NUMBER)
185372 RETURN BOOLEAN IS
185373 --
185374 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_ADDITIONS_ALL';
185375 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CIP_ADDITIONS';
185376 
185377 l_calculate_acctd_flag   VARCHAR2(1) :='N';
185378 l_calculate_g_l_flag     VARCHAR2(1) :='N';
185379 --
185380 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
185381 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
185382 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
185383 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
185384 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
185385 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
185386 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
185387 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
185388 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
185389 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
185390 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
185391 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
185392 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
185393 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
185394 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
185395 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
185396 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
185400 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
185397 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
185398 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
185399 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
185401 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
185402 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
185403 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
185404 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
185405 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
185406 
185407 l_event_id                             NUMBER;
185408 l_previous_event_id                    NUMBER;
185409 l_first_event_id                       NUMBER;
185410 l_last_event_id                        NUMBER;
185411 
185412 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
185413 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
185414 --
185415 --
185416 l_result                    BOOLEAN := TRUE;
185417 l_rows                      NUMBER  := 1000;
185418 l_event_type_name           VARCHAR2(80) := 'All';
185419 l_event_class_name          VARCHAR2(80) := 'CIP Additions';
185420 l_description               VARCHAR2(4000);
185421 l_transaction_reversal      NUMBER;
185422 l_ae_header_id              NUMBER;
185423 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
185424 l_log_module                VARCHAR2(240);
185425 --
185426 l_acct_reversal_source      VARCHAR2(30);
185427 l_trx_reversal_source       VARCHAR2(30);
185428 
185429 l_continue_with_lines       BOOLEAN := TRUE;
185430 --
185431 l_acc_rev_gl_date_source    DATE;                      -- 4262811
185432 --
185433 type t_array_event_id is table of number index by binary_integer;
185434 
185435 l_rec_array_event                    t_rec_array_event;
185436 l_null_rec_array_event               t_rec_array_event;
185437 l_array_ae_header_id                 xla_number_array_type;
185438 l_actual_flag                        VARCHAR2(1) := NULL;
185439 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
185440 l_balance_type_code                  VARCHAR2(1) :=NULL;
185441 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
185442 
185443 --
185444 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
185445 --
185446 
185447 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
185448 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
185449 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
185450 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
185451 
185452 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
185453 TYPE t_array_source_5 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
185454 TYPE t_array_source_6 IS TABLE OF FA_XLA_EXT_LINES_B_GT.PAYABLES_CCID%TYPE INDEX BY BINARY_INTEGER;
185455 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
185456 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
185457 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
185458 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
185459 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
185460 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
185461 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
185462 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
185463 
185464 l_array_source_1              t_array_source_1;
185465 l_array_source_30              t_array_source_30;
185466 l_array_source_51              t_array_source_51;
185467 l_array_source_52              t_array_source_52;
185468 
185469 l_array_source_3      t_array_source_3;
185470 l_array_source_5      t_array_source_5;
185471 l_array_source_6      t_array_source_6;
185472 l_array_source_7      t_array_source_7;
185473 l_array_source_29      t_array_source_29;
185474 l_array_source_35      t_array_source_35;
185475 l_array_source_36      t_array_source_36;
185476 l_array_source_37      t_array_source_37;
185477 l_array_source_38      t_array_source_38;
185478 l_array_source_39      t_array_source_39;
185479 l_array_source_40      t_array_source_40;
185480 
185481 --
185482 CURSOR header_cur
185483 IS
185484 SELECT /*+ leading(xet) cardinality(xet,1) */
185485 -- Event Class Code: CIP_ADDITIONS
185486     xet.entity_id
185487    ,xet.legal_entity_id
185488    ,xet.entity_code
185489    ,xet.transaction_number
185490    ,xet.event_id
185491    ,xet.event_class_code
185492    ,xet.event_type_code
185493    ,xet.event_number
185494    ,xet.event_date
185495    ,xet.transaction_date
185496    ,xet.reference_num_1
185497    ,xet.reference_num_2
185498    ,xet.reference_num_3
185499    ,xet.reference_num_4
185500    ,xet.reference_char_1
185501    ,xet.reference_char_2
185502    ,xet.reference_char_3
185503    ,xet.reference_char_4
185504    ,xet.reference_date_1
185505    ,xet.reference_date_2
185506    ,xet.reference_date_3
185507    ,xet.reference_date_4
185508    ,xet.event_created_by
185509    ,xet.budgetary_control_flag 
185510   , h1.PERIOD_CLOSE_DATE    source_1
185511   , h1.DEFAULT_CCID    source_30
185512   , h1.ACCOUNTING_DATE    source_51
185513   , h1.TRANSFER_TO_GL_FLAG    source_52
185514   FROM xla_events_gt     xet 
185515   , FA_XLA_EXT_HEADERS_B_GT  h1
185519 
185516  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
185517    and xet.event_class_code = C_EVENT_CLASS_CODE
185518    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
185520  ORDER BY event_id
185521 ;
185522 
185523 
185524 --
185525 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
185526 IS
185527 SELECT  /*+ leading(xet) cardinality(xet,1) */
185528 -- Event Class Code: CIP_ADDITIONS
185529     xet.entity_id
185530    ,xet.legal_entity_id
185531    ,xet.entity_code
185532    ,xet.transaction_number
185533    ,xet.event_id
185534    ,xet.event_class_code
185535    ,xet.event_type_code
185536    ,xet.event_number
185537    ,xet.event_date
185538    ,xet.transaction_date
185539    ,xet.reference_num_1
185540    ,xet.reference_num_2
185541    ,xet.reference_num_3
185542    ,xet.reference_num_4
185543    ,xet.reference_char_1
185544    ,xet.reference_char_2
185545    ,xet.reference_char_3
185546    ,xet.reference_char_4
185547    ,xet.reference_date_1
185548    ,xet.reference_date_2
185549    ,xet.reference_date_3
185550    ,xet.reference_date_4
185551    ,xet.event_created_by
185552    ,xet.budgetary_control_flag
185553  , l2.LINE_NUMBER  
185554   , l2.GENERATED_CCID    source_3
185555   , l2.CIP_CLEARING_ACCT    source_5
185556   , l2.PAYABLES_CCID    source_6
185557   , l2.CIP_COST_ACCT    source_7
185558   , l2.EXPENSE_ACCOUNT_CCID    source_29
185559   , l2.ADJUSTMENT_TYPE    source_35
185560   , l2.TRANSACTION_HEADER_ID    source_36
185561   , l2.ADJUSTMENT_LINE_ID    source_37
185562   , l2.DISTRIBUTION_TYPE_CODE    source_38
185563   , l2.ENTERED_AMOUNT    source_39
185564   , l2.CURRENCY_CODE    source_40
185565   FROM xla_events_gt     xet 
185566   , FA_XLA_EXT_LINES_B_GT  l2
185567  WHERE xet.event_id between x_first_event_id and x_last_event_id
185568    and xet.event_date between p_pad_start_date and p_pad_end_date
185569    and xet.event_class_code = C_EVENT_CLASS_CODE
185570    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
185571   AND l2.ledger_id = p_sla_ledger_id
185572 ;
185573 
185574 --
185575 BEGIN
185576 IF g_log_enabled THEN
185577    l_log_module := C_DEFAULT_MODULE||'.EventClass_411';
185578 END IF;
185579 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
185580    trace
185581       (p_msg      => 'BEGIN of EventClass_411'
185582       ,p_level    => C_LEVEL_PROCEDURE
185583       ,p_module   => l_log_module);
185584 END IF;
185585 
185586 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
185587    trace
185588       (p_msg      => 'p_application_id = '||p_application_id||
185589                      ' - p_base_ledger_id = '||p_base_ledger_id||
185590                      ' - p_target_ledger_id  = '||p_target_ledger_id||
185591                      ' - p_language = '||p_language||
185592                      ' - p_currency_code = '||p_currency_code||
185593                      ' - p_sla_ledger_id = '||p_sla_ledger_id
185594       ,p_level    => C_LEVEL_STATEMENT
185595       ,p_module   => l_log_module);
185596 END IF;
185597 --
185598 -- initialze arrays
185599 --
185600 g_array_event.DELETE;
185601 l_rec_array_event := l_null_rec_array_event;
185602 --
185603 --------------------------------------
185604 -- 4262811 Initialze MPA Line Number
185605 --------------------------------------
185606 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
185607 
185608 --
185609 
185610 --
185611 OPEN header_cur;
185612 --
185613 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
185614    trace
185615    (p_msg      => 'SQL - FETCH header_cur'
185616    ,p_level    => C_LEVEL_STATEMENT
185617    ,p_module   => l_log_module);
185618 END IF;
185619 --
185620 LOOP
185621 FETCH header_cur BULK COLLECT INTO
185622         l_array_entity_id
185623       , l_array_legal_entity_id
185624       , l_array_entity_code
185625       , l_array_transaction_num
185626       , l_array_event_id
185627       , l_array_class_code
185628       , l_array_event_type
185629       , l_array_event_number
185630       , l_array_event_date
185631       , l_array_transaction_date
185632       , l_array_reference_num_1
185633       , l_array_reference_num_2
185634       , l_array_reference_num_3
185635       , l_array_reference_num_4
185636       , l_array_reference_char_1
185637       , l_array_reference_char_2
185638       , l_array_reference_char_3
185639       , l_array_reference_char_4
185640       , l_array_reference_date_1
185641       , l_array_reference_date_2
185642       , l_array_reference_date_3
185643       , l_array_reference_date_4
185644       , l_array_event_created_by
185645       , l_array_budgetary_control_flag 
185646       , l_array_source_1
185647       , l_array_source_30
185648       , l_array_source_51
185649       , l_array_source_52
185650       LIMIT l_rows;
185651 --
185652 IF (C_LEVEL_EVENT >= g_log_level) THEN
185653    trace
185654    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
185655    ,p_level    => C_LEVEL_EVENT
185656    ,p_module   => l_log_module);
185657 END IF;
185658 --
185659 EXIT WHEN l_array_entity_id.COUNT = 0;
185660 
185661 -- initialize arrays
185662 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
185663 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
185664 
185665 --
185666 -- Bug 4458708
185667 --
185668 XLA_AE_LINES_PKG.g_LineNumber := 0;
185669 
185670 
185671 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
185672 g_last_hdr_idx := l_array_event_id.LAST;
185673 --
185674 -- loop for the headers. Each iteration is for each header extract row
185675 -- fetched in header cursor
185676 --
185677 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
185678 
185679 --
185683    (p_application_id           => p_application_id
185680 -- set event info as cache for other routines to refer event attributes
185681 --
185682 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
185684    ,p_primary_ledger_id        => p_primary_ledger_id
185685    ,p_base_ledger_id           => p_base_ledger_id
185686    ,p_target_ledger_id         => p_target_ledger_id
185687    ,p_entity_id                => l_array_entity_id(hdr_idx)
185688    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
185689    ,p_entity_code              => l_array_entity_code(hdr_idx)
185690    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
185691    ,p_event_id                 => l_array_event_id(hdr_idx)
185692    ,p_event_class_code         => l_array_class_code(hdr_idx)
185693    ,p_event_type_code          => l_array_event_type(hdr_idx)
185694    ,p_event_number             => l_array_event_number(hdr_idx)
185695    ,p_event_date               => l_array_event_date(hdr_idx)
185696    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
185697    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
185698    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
185699    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
185700    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
185701    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
185702    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
185703    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
185704    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
185705    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
185706    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
185707    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
185708    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
185709    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
185710    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
185711 
185712 --
185713 -- set the status of entry to C_VALID (0)
185714 --
185715 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
185716 
185717 --
185718 -- initialize a row for ae header
185719 --
185720 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
185721 
185722 l_event_id := l_array_event_id(hdr_idx);
185723 
185724 --
185725 -- storing the hdr_idx for event. May be used by line cursor.
185726 --
185727 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
185728 
185729 --
185730 -- store sources from header extract. This can be improved to
185731 -- store only those sources from header extract that may be used in lines
185732 --
185733 
185734 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
185735 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
185736 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
185737 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
185738 
185739 --
185740 -- initilaize the status of ae headers for diffrent balance types
185741 -- the status is initialised to C_NOT_CREATED (2)
185742 --
185743 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
185744 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
185745 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
185746 
185747 --
185748 -- call api to validate and store accounting attributes for header
185749 --
185750 
185751 ------------------------------------------------------------
185752 -- Accrual Reversal : to get date for Standard Source (NONE)
185753 ------------------------------------------------------------
185754 l_acc_rev_gl_date_source := NULL;
185755 
185756      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
185757       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
185758      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
185759       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
185760 
185761 
185762 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
185763 
185764 XLA_AE_HEADER_PKG.SetJeCategoryName;
185765 
185766 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
185767 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
185768 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
185769 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
185770 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
185771 
185772 
185773 --
185774 xla_ae_header_pkg.SetHdrDescription(
185775    p_description => Description_23 (
185776    p_application_id => p_application_id 
185777  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
185778    )
185779 );
185780 --
185781 
185782 -- No header level analytical criteria
185783 
185784 --
185785 --accounting attribute enhancement, bug 3612931
185786 --
185787 l_trx_reversal_source := SUBSTR(NULL, 1,30);
185788 
185789 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
185790    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
185791 
185792    xla_accounting_err_pkg.build_message
185793       (p_appli_s_name            => 'XLA'
185794       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
185795       ,p_token_1                 => 'ACCT_ATTR_NAME'
185796       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
185797       ,p_token_2                 => 'PRODUCT_NAME'
185801       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
185798       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
185799       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
185800       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
185802 
185803 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
185804    --
185805    -- following sets the accounting attributes needed to reverse
185806    -- accounting for a distributeion
185807    --
185808    xla_ae_lines_pkg.SetTrxReversalAttrs
185809       (p_event_id              => l_event_id
185810       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
185811       ,p_trx_reversal_source   => l_trx_reversal_source);
185812 
185813 END IF;
185814 
185815 
185816 ----------------------------------------------------------------
185817 -- 4262811 -  update the header statuses to invalid in need be
185818 ----------------------------------------------------------------
185819 --
185820 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
185821 
185822 
185823   -----------------------------------------------
185824   -- No accrual reversal for the event class/type
185825   -----------------------------------------------
185826 ----------------------------------------------------------------
185827 
185828 --
185829 -- this ends the header loop iteration for one bulk fetch
185830 --
185831 END LOOP;
185832 
185833 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
185834 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
185835 
185836 --
185837 -- insert dummy rows into lines gt table that were created due to
185838 -- transaction reversals
185839 --
185840 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
185841    l_result := XLA_AE_LINES_PKG.InsertLines;
185842 END IF;
185843 
185844 --
185845 -- reset the temp_line_num for each set of events fetched from header
185846 -- cursor rather than doing it for each new event in line cursor
185847 -- Bug 3939231
185848 --
185849 xla_ae_lines_pkg.g_temp_line_num := 0;
185850 
185851 
185852 
185853 --
185854 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
185855 --
185856 --
185857 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
185858 
185859       trace
185860          (p_msg      => 'SQL - FETCH line_cur'
185861          ,p_level    => C_LEVEL_STATEMENT
185862          ,p_module   => l_log_module);
185863 
185864 END IF;
185865 --
185866 --
185867 LOOP
185868   --
185869   FETCH line_cur BULK COLLECT INTO
185870         l_array_entity_id
185871       , l_array_legal_entity_id
185872       , l_array_entity_code
185873       , l_array_transaction_num
185874       , l_array_event_id
185875       , l_array_class_code
185876       , l_array_event_type
185877       , l_array_event_number
185878       , l_array_event_date
185879       , l_array_transaction_date
185880       , l_array_reference_num_1
185881       , l_array_reference_num_2
185882       , l_array_reference_num_3
185883       , l_array_reference_num_4
185884       , l_array_reference_char_1
185885       , l_array_reference_char_2
185886       , l_array_reference_char_3
185887       , l_array_reference_char_4
185888       , l_array_reference_date_1
185889       , l_array_reference_date_2
185890       , l_array_reference_date_3
185891       , l_array_reference_date_4
185892       , l_array_event_created_by
185893       , l_array_budgetary_control_flag
185894       , l_array_extract_line_num 
185895       , l_array_source_3
185896       , l_array_source_5
185897       , l_array_source_6
185898       , l_array_source_7
185899       , l_array_source_29
185900       , l_array_source_35
185901       , l_array_source_36
185902       , l_array_source_37
185903       , l_array_source_38
185904       , l_array_source_39
185905       , l_array_source_40
185906       LIMIT l_rows;
185907 
185908   --
185909   IF (C_LEVEL_EVENT >= g_log_level) THEN
185910             trace
185911                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
185912                ,p_level    => C_LEVEL_EVENT
185913                ,p_module   => l_log_module);
185914   END IF;
185915   --
185916   EXIT WHEN l_array_entity_id.count = 0;
185917 
185918   XLA_AE_LINES_PKG.g_rec_lines := null;
185919 
185920 --
185921 -- Bug 4458708
185922 --
185923 XLA_AE_LINES_PKG.g_LineNumber := 0;
185924 --
185925 --
185926 
185927 FOR Idx IN 1..l_array_event_id.count LOOP
185928    --
185929    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
185930    --
185931    l_event_id := l_array_event_id(idx);  -- 5648433
185932 
185933    --
185934    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
185935    --
185936 
185937    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
185938              (g_array_event(l_event_id).array_value_num('header_index'))
185939          ,'N'
185940          ) <> 'Y'
185941    THEN
185942       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
185943          trace
185944             (p_msg      => 'Trancaction revesal option is not Y '
185945             ,p_level    => C_LEVEL_STATEMENT
185946             ,p_module   => l_log_module);
185947       END IF;
185948 
185949 --
185950 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
185951 --
185952 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
185953 --
185954 -- set event info as cache for other routines to refer event attributes
185955 --
185956 
185957 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
185961       (p_application_id           => p_application_id
185958    l_previous_event_id := l_event_id;
185959 
185960    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
185962       ,p_primary_ledger_id        => p_primary_ledger_id
185963       ,p_base_ledger_id           => p_base_ledger_id
185964       ,p_target_ledger_id         => p_target_ledger_id
185965       ,p_entity_id                => l_array_entity_id(Idx)
185966       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
185967       ,p_entity_code              => l_array_entity_code(Idx)
185968       ,p_transaction_num          => l_array_transaction_num(Idx)
185969       ,p_event_id                 => l_array_event_id(Idx)
185970       ,p_event_class_code         => l_array_class_code(Idx)
185971       ,p_event_type_code          => l_array_event_type(Idx)
185972       ,p_event_number             => l_array_event_number(Idx)
185973       ,p_event_date               => l_array_event_date(Idx)
185974       ,p_transaction_date         => l_array_transaction_date(Idx)
185975       ,p_reference_num_1          => l_array_reference_num_1(Idx)
185976       ,p_reference_num_2          => l_array_reference_num_2(Idx)
185977       ,p_reference_num_3          => l_array_reference_num_3(Idx)
185978       ,p_reference_num_4          => l_array_reference_num_4(Idx)
185979       ,p_reference_char_1         => l_array_reference_char_1(Idx)
185980       ,p_reference_char_2         => l_array_reference_char_2(Idx)
185981       ,p_reference_char_3         => l_array_reference_char_3(Idx)
185982       ,p_reference_char_4         => l_array_reference_char_4(Idx)
185983       ,p_reference_date_1         => l_array_reference_date_1(Idx)
185984       ,p_reference_date_2         => l_array_reference_date_2(Idx)
185985       ,p_reference_date_3         => l_array_reference_date_3(Idx)
185986       ,p_reference_date_4         => l_array_reference_date_4(Idx)
185987       ,p_event_created_by         => l_array_event_created_by(Idx)
185988       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
185989        --
185990 END IF;
185991 
185992 
185993 
185994 --
185995 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
185996 
185997 l_acct_reversal_source := SUBSTR(NULL, 1,30);
185998 
185999 IF l_continue_with_lines THEN
186000    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
186001       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
186002 
186003       xla_accounting_err_pkg.build_message
186004          (p_appli_s_name            => 'XLA'
186005          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
186006          ,p_token_1                 => 'LINE_NUMBER'
186007          ,p_value_1                 => l_array_extract_line_num(Idx)
186008          ,p_token_2                 => 'PRODUCT_NAME'
186009          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
186010          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
186011          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
186012          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
186013 
186014    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
186015       --
186016       -- following sets the accounting attributes needed to reverse
186017       -- accounting for a distributeion
186018       --
186019 
186020       --
186021       -- 5217187
186022       --
186023       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
186024       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
186025                                        g_array_event(l_event_id).array_value_num('header_index'));
186026       --
186027       --
186028 
186029       -- No reversal code generated
186030 
186031       xla_ae_lines_pkg.SetAcctReversalAttrs
186032          (p_event_id             => l_event_id
186033          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
186034          ,p_calculate_acctd_flag => l_calculate_acctd_flag
186035          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
186036    END IF;
186037 
186038    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
186039        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
186040 
186041 --
186042 AcctLineType_207 (
186043  p_application_id  => p_application_id
186044  ,p_event_id     => l_event_id
186045  ,p_calculate_acctd_flag => l_calculate_acctd_flag
186046  ,p_calculate_g_l_flag => l_calculate_g_l_flag
186047  ,p_actual_flag => l_actual_flag
186048  ,p_balance_type_code => l_balance_type_code
186049  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
186050  
186051  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
186052  , p_source_3 => l_array_source_3(Idx)
186053  , p_source_7 => l_array_source_7(Idx)
186054  , p_source_29 => l_array_source_29(Idx)
186055  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
186056  , p_source_35 => l_array_source_35(Idx)
186057  , p_source_36 => l_array_source_36(Idx)
186058  , p_source_37 => l_array_source_37(Idx)
186059  , p_source_38 => l_array_source_38(Idx)
186060  , p_source_39 => l_array_source_39(Idx)
186061  , p_source_40 => l_array_source_40(Idx)
186062  );
186063 If(l_balance_type_code = 'A') THEN
186064   l_actual_gain_loss_ref := l_gain_or_loss_ref;
186065 END IF;
186066 
186067 --
186068 
186069 
186070 --
186071 AcctLineType_208 (
186072  p_application_id  => p_application_id
186073  ,p_event_id     => l_event_id
186074  ,p_calculate_acctd_flag => l_calculate_acctd_flag
186075  ,p_calculate_g_l_flag => l_calculate_g_l_flag
186076  ,p_actual_flag => l_actual_flag
186077  ,p_balance_type_code => l_balance_type_code
186078  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
186079  
186080  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
186081  , p_source_3 => l_array_source_3(Idx)
186082  , p_source_5 => l_array_source_5(Idx)
186086  , p_source_35 => l_array_source_35(Idx)
186083  , p_source_6 => l_array_source_6(Idx)
186084  , p_source_29 => l_array_source_29(Idx)
186085  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
186087  , p_source_36 => l_array_source_36(Idx)
186088  , p_source_37 => l_array_source_37(Idx)
186089  , p_source_38 => l_array_source_38(Idx)
186090  , p_source_39 => l_array_source_39(Idx)
186091  , p_source_40 => l_array_source_40(Idx)
186092  );
186093 If(l_balance_type_code = 'A') THEN
186094   l_actual_gain_loss_ref := l_gain_or_loss_ref;
186095 END IF;
186096 
186097 --
186098 
186099       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
186100       -- or secondary ledger that has different currency with primary
186101       -- or alc that is calculated by sla
186102       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
186103             (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'))
186104 
186105 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
186106 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
186107           AND (l_actual_flag = 'A')) THEN
186108         XLA_AE_LINES_PKG.CreateGainOrLossLines(
186109           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
186110          ,p_application_id   => p_application_id
186111          ,p_amb_context_code => 'DEFAULT'
186112          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
186113          ,p_event_class_code => C_EVENT_CLASS_CODE
186114          ,p_event_type_code  => C_EVENT_TYPE_CODE
186115          
186116          ,p_gain_ccid        => -1
186117          ,p_loss_ccid        => -1
186118 
186119          ,p_actual_flag      => l_actual_flag
186120          ,p_enc_flag         => null
186121          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
186122          ,p_enc_g_l_ref      => null
186123          );
186124       END IF;
186125    END IF;
186126 END IF;
186127 
186128    ELSE
186129       --
186130       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
186131       --
186132       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
186133          trace
186134             (p_msg      => 'Trancaction revesal option is Y'
186135             ,p_level    => C_LEVEL_STATEMENT
186136             ,p_module   => l_log_module);
186137       END IF;
186138    END IF;
186139 
186140 END LOOP;
186141 l_result := XLA_AE_LINES_PKG.InsertLines ;
186142 end loop;
186143 close line_cur;
186144 
186145 
186146 --
186147 -- insert headers into xla_ae_headers_gt table
186148 --
186149 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
186150 
186151 -- insert into errors table here.
186152 
186153 END LOOP;
186154 
186155 --
186156 -- 4865292
186157 --
186158 -- Compare g_hdr_extract_count with event count in
186159 -- CreateHeadersAndLines.
186160 --
186161 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
186162 
186163 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
186164    trace (p_msg     => '# rows extracted from header extract objects '
186165                     || ' (running total): '
186166                     || g_hdr_extract_count
186167          ,p_level   => C_LEVEL_STATEMENT
186168          ,p_module  => l_log_module);
186169 END IF;
186170 
186171 CLOSE header_cur;
186172 --
186173 
186174 --
186175 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
186176    trace
186177       (p_msg      => 'END of EventClass_411'
186178       ,p_level    => C_LEVEL_PROCEDURE
186179       ,p_module   => l_log_module);
186180 END IF;
186181 --
186182 RETURN l_result;
186183 EXCEPTION
186184 WHEN xla_exceptions_pkg.application_exception THEN
186185    
186186 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
186187 
186188    
186189 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
186190 
186191    RAISE;
186192 
186193 WHEN NO_DATA_FOUND THEN
186194 
186195 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
186196 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
186197 
186198 FOR header_record IN header_cur
186199 LOOP
186200     l_array_header_events(header_record.event_id) := header_record.event_id;
186201 END LOOP;
186202 
186203 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
186204 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
186205 
186206 fnd_file.put_line(fnd_file.LOG, '                    ');
186207 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
186208 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
186209 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
186210 
186211 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
186212 LOOP
186213 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
186214 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
186215         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
186216 	END IF;
186217 END LOOP;
186218 
186219 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
186220 fnd_file.put_line(fnd_file.LOG, '                    ');
186221 
186222 
186223 xla_exceptions_pkg.raise_message
186224       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_411');
186225 
186226 
186227 WHEN OTHERS THEN
186228    xla_exceptions_pkg.raise_message
186229       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_411');
186230 END EventClass_411;
186234 --
186231 --
186232 
186233 ---------------------------------------
186235 -- PRIVATE PROCEDURE
186236 --         insert_sources_412
186237 --
186238 ----------------------------------------
186239 --
186240 PROCEDURE insert_sources_412(
186241                                 p_target_ledger_id       IN NUMBER
186242                               , p_language               IN VARCHAR2
186243                               , p_sla_ledger_id          IN NUMBER
186244                               , p_pad_start_date         IN DATE
186245                               , p_pad_end_date           IN DATE
186246                          )
186247 IS
186248 
186249 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_ADJUSTMENTS_ALL';
186250 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CIP_ADJUSTMENTS';
186251 p_apps_owner                   VARCHAR2(30);
186252 l_log_module                   VARCHAR2(240);
186253 BEGIN
186254 IF g_log_enabled THEN
186255       l_log_module := C_DEFAULT_MODULE||'.insert_sources_412';
186256 END IF;
186257 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
186258 
186259       trace
186260          (p_msg      => 'BEGIN of insert_sources_412'
186261          ,p_level    => C_LEVEL_PROCEDURE
186262          ,p_module   => l_log_module);
186263 
186264 END IF;
186265 
186266 -- select APPS owner
186267 SELECT oracle_username
186268   INTO p_apps_owner
186269   FROM fnd_oracle_userid
186270  WHERE read_only_flag = 'U'
186271 ;
186272 
186273 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
186274       trace
186275          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
186276                         ' - p_language = '||p_language||
186277                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
186278                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
186279                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
186280                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
186281          ,p_level    => C_LEVEL_STATEMENT
186282          ,p_module   => l_log_module);
186283 END IF;
186284 
186285 
186286 --
186287 INSERT INTO xla_diag_sources --hdr2
186288 (
186289         event_id
186290       , ledger_id
186291       , sla_ledger_id
186292       , description_language
186293       , object_name
186294       , object_type_code
186295       , line_number
186296       , source_application_id
186297       , source_type_code
186298       , source_code
186299       , source_value
186300       , source_meaning
186301       , created_by
186302       , creation_date
186303       , last_update_date
186304       , last_updated_by
186305       , last_update_login
186306       , program_update_date
186307       , program_application_id
186308       , program_id
186309       , request_id
186310 )
186311 SELECT
186312         event_id
186313       , p_target_ledger_id
186314       , p_sla_ledger_id
186315       , p_language
186316       , object_name
186317       , object_type_code
186318       , line_number
186319       , source_application_id
186320       , source_type_code
186321       , source_code
186322       , SUBSTR(source_value ,1,1996)
186323       , SUBSTR(source_meaning ,1,200)
186324       , xla_environment_pkg.g_Usr_Id
186325       , TRUNC(SYSDATE)
186326       , TRUNC(SYSDATE)
186327       , xla_environment_pkg.g_Usr_Id
186328       , xla_environment_pkg.g_Login_Id
186329       , TRUNC(SYSDATE)
186330       , xla_environment_pkg.g_Prog_Appl_Id
186331       , xla_environment_pkg.g_Prog_Id
186332       , xla_environment_pkg.g_Req_Id
186333   FROM (
186334        SELECT xet.event_id                  event_id
186335             , 0                          line_number
186336             , CASE r
186337                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
186338                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
186339                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
186340                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
186341                 
186342                ELSE null
186343               END                           object_name
186344             , CASE r
186345                 WHEN 1 THEN 'HEADER' 
186346                 WHEN 2 THEN 'HEADER' 
186347                 WHEN 3 THEN 'HEADER' 
186348                 WHEN 4 THEN 'HEADER' 
186349                 
186350                 ELSE null
186351               END                           object_type_code
186352             , CASE r
186353                 WHEN 1 THEN '140' 
186354                 WHEN 2 THEN '140' 
186355                 WHEN 3 THEN '140' 
186356                 WHEN 4 THEN '140' 
186357                 
186358                 ELSE null
186359               END                           source_application_id
186360             , 'S'             source_type_code
186361             , CASE r
186362                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
186363                 WHEN 2 THEN 'DEFAULT_CCID' 
186364                 WHEN 3 THEN 'ACCOUNTING_DATE' 
186365                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
186366                 
186367                 ELSE null
186368               END                           source_code
186369             , CASE r
186370                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
186371                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
186372                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
186373                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
186374                 
186375                 ELSE null
186376               END                           source_value
186377             , null              source_meaning
186378          FROM xla_events_gt     xet  
186379       , FA_XLA_EXT_HEADERS_B_GT  h1
186380              ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
186381          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
186385 )
186382            AND xet.event_class_code = C_EVENT_CLASS_CODE
186383               AND h1.event_id = xet.event_id
186384 
186386 ;
186387 --
186388 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
186389 
186390       trace
186391          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
186392          ,p_level    => C_LEVEL_STATEMENT
186393          ,p_module   => l_log_module);
186394 
186395 END IF;
186396 --
186397 
186398 
186399 
186400 --
186401 INSERT INTO xla_diag_sources  --line2
186402 (
186403         event_id
186404       , ledger_id
186405       , sla_ledger_id
186406       , description_language
186407       , object_name
186408       , object_type_code
186409       , line_number
186410       , source_application_id
186411       , source_type_code
186412       , source_code
186413       , source_value
186414       , source_meaning
186415       , created_by
186416       , creation_date
186417       , last_update_date
186418       , last_updated_by
186419       , last_update_login
186420       , program_update_date
186421       , program_application_id
186422       , program_id
186423       , request_id
186424 )
186425 SELECT  event_id
186426       , p_target_ledger_id
186427       , p_sla_ledger_id
186428       , p_language
186429       , object_name
186430       , object_type_code
186431       , line_number
186432       , source_application_id
186433       , source_type_code
186434       , source_code
186435       , SUBSTR(source_value,1,1996)
186436       , SUBSTR(source_meaning ,1,200)
186437       , xla_environment_pkg.g_Usr_Id
186438       , TRUNC(SYSDATE)
186439       , TRUNC(SYSDATE)
186440       , xla_environment_pkg.g_Usr_Id
186441       , xla_environment_pkg.g_Login_Id
186442       , TRUNC(SYSDATE)
186443       , xla_environment_pkg.g_Prog_Appl_Id
186444       , xla_environment_pkg.g_Prog_Id
186445       , xla_environment_pkg.g_Req_Id
186446   FROM (
186447        SELECT xet.event_id                  event_id
186448             , l2.line_number                 line_number
186449             , CASE r
186450                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
186451                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
186452                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
186453                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
186454                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
186455                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
186456                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
186457                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
186458                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
186459                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
186460                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
186461                 
186462                ELSE null
186463               END                           object_name
186464             , CASE r
186465                 WHEN 1 THEN 'LINE' 
186466                 WHEN 2 THEN 'LINE' 
186467                 WHEN 3 THEN 'LINE' 
186468                 WHEN 4 THEN 'LINE' 
186469                 WHEN 5 THEN 'LINE' 
186470                 WHEN 6 THEN 'LINE' 
186471                 WHEN 7 THEN 'LINE' 
186472                 WHEN 8 THEN 'LINE' 
186473                 WHEN 9 THEN 'LINE' 
186474                 WHEN 10 THEN 'LINE' 
186475                 WHEN 11 THEN 'LINE' 
186476                 
186477                 ELSE null
186478               END                           object_type_code
186479             , CASE r
186480                 WHEN 1 THEN '140' 
186481                 WHEN 2 THEN '140' 
186482                 WHEN 3 THEN '140' 
186483                 WHEN 4 THEN '140' 
186484                 WHEN 5 THEN '140' 
186485                 WHEN 6 THEN '140' 
186486                 WHEN 7 THEN '140' 
186487                 WHEN 8 THEN '140' 
186488                 WHEN 9 THEN '140' 
186489                 WHEN 10 THEN '140' 
186490                 WHEN 11 THEN '140' 
186491                 
186492                 ELSE null
186493               END                           source_application_id
186494             , 'S'             source_type_code
186495             , CASE r
186496                 WHEN 1 THEN 'GENERATED_CCID' 
186497                 WHEN 2 THEN 'CIP_CLEARING_ACCT' 
186498                 WHEN 3 THEN 'PAYABLES_CCID' 
186499                 WHEN 4 THEN 'CIP_COST_ACCT' 
186500                 WHEN 5 THEN 'EXPENSE_ACCOUNT_CCID' 
186501                 WHEN 6 THEN 'ADJUSTMENT_TYPE' 
186502                 WHEN 7 THEN 'TRANSACTION_HEADER_ID' 
186503                 WHEN 8 THEN 'ADJUSTMENT_LINE_ID' 
186504                 WHEN 9 THEN 'DISTRIBUTION_TYPE_CODE' 
186505                 WHEN 10 THEN 'ENTERED_AMOUNT' 
186506                 WHEN 11 THEN 'CURRENCY_CODE' 
186507                 
186508                 ELSE null
186509               END                           source_code
186510             , CASE r
186511                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
186512                 WHEN 2 THEN TO_CHAR(l2.CIP_CLEARING_ACCT)
186513                 WHEN 3 THEN TO_CHAR(l2.PAYABLES_CCID)
186514                 WHEN 4 THEN TO_CHAR(l2.CIP_COST_ACCT)
186515                 WHEN 5 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
186516                 WHEN 6 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
186517                 WHEN 7 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
186518                 WHEN 8 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
186519                 WHEN 9 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
186520                 WHEN 10 THEN TO_CHAR(l2.ENTERED_AMOUNT)
186521                 WHEN 11 THEN TO_CHAR(l2.CURRENCY_CODE)
186522                 
186523                 ELSE null
186524               END                           source_value
186525             , null              source_meaning
186526          FROM  xla_events_gt     xet  
186527         , FA_XLA_EXT_LINES_B_GT  l2
186531             AND l2.event_id          = xet.event_id
186528             , (select rownum r from all_objects where rownum <= 11 and owner = p_apps_owner)
186529         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
186530           AND xet.event_class_code = C_EVENT_CLASS_CODE
186532   AND l2.ledger_id (+)  = p_sla_ledger_id
186533 
186534 )
186535 ;
186536 --
186537 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
186538 
186539       trace
186540          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
186541          ,p_level    => C_LEVEL_STATEMENT
186542          ,p_module   => l_log_module);
186543 
186544 END IF;
186545 
186546 
186547 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
186548       trace
186549          (p_msg      => 'END of insert_sources_412'
186550          ,p_level    => C_LEVEL_PROCEDURE
186551          ,p_module   => l_log_module);
186552 END IF;
186553 EXCEPTION
186554   WHEN xla_exceptions_pkg.application_exception THEN
186555       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
186556             trace
186557                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
186558                ,p_level    => C_LEVEL_EXCEPTION
186559                ,p_module   => l_log_module);
186560       END IF;
186561       RAISE;
186562   WHEN OTHERS THEN
186563       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
186564             trace
186565                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
186566                ,p_level    => C_LEVEL_EXCEPTION
186567                ,p_module   => l_log_module);
186568        END IF;
186569        xla_exceptions_pkg.raise_message
186570            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_412');
186571 END insert_sources_412;
186572 --
186573 
186574 ---------------------------------------
186575 --
186576 -- PRIVATE FUNCTION
186577 --         EventClass_412
186578 --
186579 ----------------------------------------
186580 --
186581 FUNCTION EventClass_412
186582        (p_application_id         IN NUMBER
186583        ,p_base_ledger_id         IN NUMBER
186584        ,p_target_ledger_id       IN NUMBER
186585        ,p_language               IN VARCHAR2
186586        ,p_currency_code          IN VARCHAR2
186587        ,p_sla_ledger_id          IN NUMBER
186588        ,p_pad_start_date         IN DATE
186589        ,p_pad_end_date           IN DATE
186590        ,p_primary_ledger_id      IN NUMBER)
186591 RETURN BOOLEAN IS
186592 --
186593 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_ADJUSTMENTS_ALL';
186594 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CIP_ADJUSTMENTS';
186595 
186596 l_calculate_acctd_flag   VARCHAR2(1) :='N';
186597 l_calculate_g_l_flag     VARCHAR2(1) :='N';
186598 --
186599 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
186600 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
186601 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
186602 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
186603 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
186604 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
186605 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
186606 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
186607 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
186608 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
186609 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
186610 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
186611 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
186612 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
186613 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
186614 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
186615 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
186616 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
186617 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
186618 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
186619 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
186620 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
186621 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
186622 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
186623 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
186624 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
186625 
186626 l_event_id                             NUMBER;
186627 l_previous_event_id                    NUMBER;
186628 l_first_event_id                       NUMBER;
186629 l_last_event_id                        NUMBER;
186630 
186631 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
186632 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
186633 --
186634 --
186635 l_result                    BOOLEAN := TRUE;
186636 l_rows                      NUMBER  := 1000;
186637 l_event_type_name           VARCHAR2(80) := 'All';
186638 l_event_class_name          VARCHAR2(80) := 'CIP Adjustments';
186639 l_description               VARCHAR2(4000);
186640 l_transaction_reversal      NUMBER;
186641 l_ae_header_id              NUMBER;
186642 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
186643 l_log_module                VARCHAR2(240);
186644 --
186645 l_acct_reversal_source      VARCHAR2(30);
186646 l_trx_reversal_source       VARCHAR2(30);
186647 
186648 l_continue_with_lines       BOOLEAN := TRUE;
186649 --
186650 l_acc_rev_gl_date_source    DATE;                      -- 4262811
186651 --
186655 l_null_rec_array_event               t_rec_array_event;
186652 type t_array_event_id is table of number index by binary_integer;
186653 
186654 l_rec_array_event                    t_rec_array_event;
186656 l_array_ae_header_id                 xla_number_array_type;
186657 l_actual_flag                        VARCHAR2(1) := NULL;
186658 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
186659 l_balance_type_code                  VARCHAR2(1) :=NULL;
186660 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
186661 
186662 --
186663 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
186664 --
186665 
186666 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
186667 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
186668 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
186669 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
186670 
186671 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
186672 TYPE t_array_source_5 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
186673 TYPE t_array_source_6 IS TABLE OF FA_XLA_EXT_LINES_B_GT.PAYABLES_CCID%TYPE INDEX BY BINARY_INTEGER;
186674 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
186675 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
186676 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
186677 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
186678 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
186679 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
186680 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
186681 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
186682 
186683 l_array_source_1              t_array_source_1;
186684 l_array_source_30              t_array_source_30;
186685 l_array_source_51              t_array_source_51;
186686 l_array_source_52              t_array_source_52;
186687 
186688 l_array_source_3      t_array_source_3;
186689 l_array_source_5      t_array_source_5;
186690 l_array_source_6      t_array_source_6;
186691 l_array_source_7      t_array_source_7;
186692 l_array_source_29      t_array_source_29;
186693 l_array_source_35      t_array_source_35;
186694 l_array_source_36      t_array_source_36;
186695 l_array_source_37      t_array_source_37;
186696 l_array_source_38      t_array_source_38;
186697 l_array_source_39      t_array_source_39;
186698 l_array_source_40      t_array_source_40;
186699 
186700 --
186701 CURSOR header_cur
186702 IS
186703 SELECT /*+ leading(xet) cardinality(xet,1) */
186704 -- Event Class Code: CIP_ADJUSTMENTS
186705     xet.entity_id
186706    ,xet.legal_entity_id
186707    ,xet.entity_code
186708    ,xet.transaction_number
186709    ,xet.event_id
186710    ,xet.event_class_code
186711    ,xet.event_type_code
186712    ,xet.event_number
186713    ,xet.event_date
186714    ,xet.transaction_date
186715    ,xet.reference_num_1
186716    ,xet.reference_num_2
186717    ,xet.reference_num_3
186718    ,xet.reference_num_4
186719    ,xet.reference_char_1
186720    ,xet.reference_char_2
186721    ,xet.reference_char_3
186722    ,xet.reference_char_4
186723    ,xet.reference_date_1
186724    ,xet.reference_date_2
186725    ,xet.reference_date_3
186726    ,xet.reference_date_4
186727    ,xet.event_created_by
186728    ,xet.budgetary_control_flag 
186729   , h1.PERIOD_CLOSE_DATE    source_1
186730   , h1.DEFAULT_CCID    source_30
186731   , h1.ACCOUNTING_DATE    source_51
186732   , h1.TRANSFER_TO_GL_FLAG    source_52
186733   FROM xla_events_gt     xet 
186734   , FA_XLA_EXT_HEADERS_B_GT  h1
186735  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
186736    and xet.event_class_code = C_EVENT_CLASS_CODE
186737    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
186738 
186739  ORDER BY event_id
186740 ;
186741 
186742 
186743 --
186744 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
186745 IS
186746 SELECT  /*+ leading(xet) cardinality(xet,1) */
186747 -- Event Class Code: CIP_ADJUSTMENTS
186748     xet.entity_id
186749    ,xet.legal_entity_id
186750    ,xet.entity_code
186751    ,xet.transaction_number
186752    ,xet.event_id
186753    ,xet.event_class_code
186754    ,xet.event_type_code
186755    ,xet.event_number
186756    ,xet.event_date
186757    ,xet.transaction_date
186758    ,xet.reference_num_1
186759    ,xet.reference_num_2
186760    ,xet.reference_num_3
186761    ,xet.reference_num_4
186762    ,xet.reference_char_1
186763    ,xet.reference_char_2
186764    ,xet.reference_char_3
186765    ,xet.reference_char_4
186766    ,xet.reference_date_1
186767    ,xet.reference_date_2
186768    ,xet.reference_date_3
186769    ,xet.reference_date_4
186770    ,xet.event_created_by
186771    ,xet.budgetary_control_flag
186772  , l2.LINE_NUMBER  
186773   , l2.GENERATED_CCID    source_3
186774   , l2.CIP_CLEARING_ACCT    source_5
186775   , l2.PAYABLES_CCID    source_6
186776   , l2.CIP_COST_ACCT    source_7
186777   , l2.EXPENSE_ACCOUNT_CCID    source_29
186778   , l2.ADJUSTMENT_TYPE    source_35
186779   , l2.TRANSACTION_HEADER_ID    source_36
186780   , l2.ADJUSTMENT_LINE_ID    source_37
186781   , l2.DISTRIBUTION_TYPE_CODE    source_38
186782   , l2.ENTERED_AMOUNT    source_39
186783   , l2.CURRENCY_CODE    source_40
186784   FROM xla_events_gt     xet 
186785   , FA_XLA_EXT_LINES_B_GT  l2
186789    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
186786  WHERE xet.event_id between x_first_event_id and x_last_event_id
186787    and xet.event_date between p_pad_start_date and p_pad_end_date
186788    and xet.event_class_code = C_EVENT_CLASS_CODE
186790   AND l2.ledger_id = p_sla_ledger_id
186791 ;
186792 
186793 --
186794 BEGIN
186795 IF g_log_enabled THEN
186796    l_log_module := C_DEFAULT_MODULE||'.EventClass_412';
186797 END IF;
186798 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
186799    trace
186800       (p_msg      => 'BEGIN of EventClass_412'
186801       ,p_level    => C_LEVEL_PROCEDURE
186802       ,p_module   => l_log_module);
186803 END IF;
186804 
186805 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
186806    trace
186807       (p_msg      => 'p_application_id = '||p_application_id||
186808                      ' - p_base_ledger_id = '||p_base_ledger_id||
186809                      ' - p_target_ledger_id  = '||p_target_ledger_id||
186810                      ' - p_language = '||p_language||
186811                      ' - p_currency_code = '||p_currency_code||
186812                      ' - p_sla_ledger_id = '||p_sla_ledger_id
186813       ,p_level    => C_LEVEL_STATEMENT
186814       ,p_module   => l_log_module);
186815 END IF;
186816 --
186817 -- initialze arrays
186818 --
186819 g_array_event.DELETE;
186820 l_rec_array_event := l_null_rec_array_event;
186821 --
186822 --------------------------------------
186823 -- 4262811 Initialze MPA Line Number
186824 --------------------------------------
186825 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
186826 
186827 --
186828 
186829 --
186830 OPEN header_cur;
186831 --
186832 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
186833    trace
186834    (p_msg      => 'SQL - FETCH header_cur'
186835    ,p_level    => C_LEVEL_STATEMENT
186836    ,p_module   => l_log_module);
186837 END IF;
186838 --
186839 LOOP
186840 FETCH header_cur BULK COLLECT INTO
186841         l_array_entity_id
186842       , l_array_legal_entity_id
186843       , l_array_entity_code
186844       , l_array_transaction_num
186845       , l_array_event_id
186846       , l_array_class_code
186847       , l_array_event_type
186848       , l_array_event_number
186849       , l_array_event_date
186850       , l_array_transaction_date
186851       , l_array_reference_num_1
186852       , l_array_reference_num_2
186853       , l_array_reference_num_3
186854       , l_array_reference_num_4
186855       , l_array_reference_char_1
186856       , l_array_reference_char_2
186857       , l_array_reference_char_3
186858       , l_array_reference_char_4
186859       , l_array_reference_date_1
186860       , l_array_reference_date_2
186861       , l_array_reference_date_3
186862       , l_array_reference_date_4
186863       , l_array_event_created_by
186864       , l_array_budgetary_control_flag 
186865       , l_array_source_1
186866       , l_array_source_30
186867       , l_array_source_51
186868       , l_array_source_52
186869       LIMIT l_rows;
186870 --
186871 IF (C_LEVEL_EVENT >= g_log_level) THEN
186872    trace
186873    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
186874    ,p_level    => C_LEVEL_EVENT
186875    ,p_module   => l_log_module);
186876 END IF;
186877 --
186878 EXIT WHEN l_array_entity_id.COUNT = 0;
186879 
186880 -- initialize arrays
186881 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
186885 -- Bug 4458708
186882 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
186883 
186884 --
186886 --
186887 XLA_AE_LINES_PKG.g_LineNumber := 0;
186888 
186889 
186890 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
186891 g_last_hdr_idx := l_array_event_id.LAST;
186892 --
186893 -- loop for the headers. Each iteration is for each header extract row
186894 -- fetched in header cursor
186895 --
186896 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
186897 
186901 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
186898 --
186899 -- set event info as cache for other routines to refer event attributes
186900 --
186902    (p_application_id           => p_application_id
186903    ,p_primary_ledger_id        => p_primary_ledger_id
186904    ,p_base_ledger_id           => p_base_ledger_id
186905    ,p_target_ledger_id         => p_target_ledger_id
186906    ,p_entity_id                => l_array_entity_id(hdr_idx)
186907    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
186908    ,p_entity_code              => l_array_entity_code(hdr_idx)
186909    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
186910    ,p_event_id                 => l_array_event_id(hdr_idx)
186911    ,p_event_class_code         => l_array_class_code(hdr_idx)
186912    ,p_event_type_code          => l_array_event_type(hdr_idx)
186913    ,p_event_number             => l_array_event_number(hdr_idx)
186914    ,p_event_date               => l_array_event_date(hdr_idx)
186915    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
186916    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
186917    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
186918    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
186919    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
186920    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
186921    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
186922    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
186923    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
186924    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
186925    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
186926    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
186927    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
186928    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
186929    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
186930 
186931 --
186932 -- set the status of entry to C_VALID (0)
186933 --
186934 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
186935 
186936 --
186937 -- initialize a row for ae header
186938 --
186939 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
186940 
186941 l_event_id := l_array_event_id(hdr_idx);
186942 
186943 --
186944 -- storing the hdr_idx for event. May be used by line cursor.
186945 --
186946 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
186947 
186948 --
186949 -- store sources from header extract. This can be improved to
186950 -- store only those sources from header extract that may be used in lines
186951 --
186952 
186953 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
186954 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
186955 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
186956 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
186957 
186958 --
186959 -- initilaize the status of ae headers for diffrent balance types
186960 -- the status is initialised to C_NOT_CREATED (2)
186961 --
186962 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
186963 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
186964 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
186965 
186966 --
186967 -- call api to validate and store accounting attributes for header
186968 --
186969 
186970 ------------------------------------------------------------
186971 -- Accrual Reversal : to get date for Standard Source (NONE)
186972 ------------------------------------------------------------
186973 l_acc_rev_gl_date_source := NULL;
186974 
186975      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
186976       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
186977      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
186978       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
186979 
186980 
186981 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
186982 
186983 XLA_AE_HEADER_PKG.SetJeCategoryName;
186984 
186985 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
186986 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
186987 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
186988 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
186989 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
186990 
186991 
186992 --
186993 xla_ae_header_pkg.SetHdrDescription(
186994    p_description => Description_26 (
186995    p_application_id => p_application_id 
186996  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
186997    )
186998 );
186999 --
187000 
187001 -- No header level analytical criteria
187002 
187003 --
187004 --accounting attribute enhancement, bug 3612931
187005 --
187006 l_trx_reversal_source := SUBSTR(NULL, 1,30);
187007 
187008 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
187009    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
187010 
187011    xla_accounting_err_pkg.build_message
187012       (p_appli_s_name            => 'XLA'
187013       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
187014       ,p_token_1                 => 'ACCT_ATTR_NAME'
187015       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
187016       ,p_token_2                 => 'PRODUCT_NAME'
187020       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
187017       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
187018       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
187019       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
187021 
187022 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
187023    --
187024    -- following sets the accounting attributes needed to reverse
187025    -- accounting for a distributeion
187026    --
187027    xla_ae_lines_pkg.SetTrxReversalAttrs
187028       (p_event_id              => l_event_id
187029       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
187030       ,p_trx_reversal_source   => l_trx_reversal_source);
187031 
187032 END IF;
187033 
187034 
187035 ----------------------------------------------------------------
187036 -- 4262811 -  update the header statuses to invalid in need be
187037 ----------------------------------------------------------------
187038 --
187039 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
187040 
187041 
187042   -----------------------------------------------
187043   -- No accrual reversal for the event class/type
187044   -----------------------------------------------
187045 ----------------------------------------------------------------
187046 
187047 --
187048 -- this ends the header loop iteration for one bulk fetch
187049 --
187050 END LOOP;
187051 
187052 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
187053 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
187054 
187055 --
187056 -- insert dummy rows into lines gt table that were created due to
187057 -- transaction reversals
187058 --
187059 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
187060    l_result := XLA_AE_LINES_PKG.InsertLines;
187061 END IF;
187062 
187063 --
187064 -- reset the temp_line_num for each set of events fetched from header
187065 -- cursor rather than doing it for each new event in line cursor
187066 -- Bug 3939231
187067 --
187068 xla_ae_lines_pkg.g_temp_line_num := 0;
187069 
187070 
187071 
187072 --
187073 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
187074 --
187075 --
187076 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
187077 
187078       trace
187079          (p_msg      => 'SQL - FETCH line_cur'
187080          ,p_level    => C_LEVEL_STATEMENT
187081          ,p_module   => l_log_module);
187082 
187083 END IF;
187084 --
187085 --
187086 LOOP
187087   --
187088   FETCH line_cur BULK COLLECT INTO
187089         l_array_entity_id
187090       , l_array_legal_entity_id
187091       , l_array_entity_code
187092       , l_array_transaction_num
187093       , l_array_event_id
187094       , l_array_class_code
187095       , l_array_event_type
187096       , l_array_event_number
187097       , l_array_event_date
187098       , l_array_transaction_date
187099       , l_array_reference_num_1
187100       , l_array_reference_num_2
187101       , l_array_reference_num_3
187102       , l_array_reference_num_4
187103       , l_array_reference_char_1
187104       , l_array_reference_char_2
187105       , l_array_reference_char_3
187106       , l_array_reference_char_4
187107       , l_array_reference_date_1
187108       , l_array_reference_date_2
187109       , l_array_reference_date_3
187110       , l_array_reference_date_4
187111       , l_array_event_created_by
187112       , l_array_budgetary_control_flag
187113       , l_array_extract_line_num 
187114       , l_array_source_3
187115       , l_array_source_5
187116       , l_array_source_6
187117       , l_array_source_7
187118       , l_array_source_29
187119       , l_array_source_35
187120       , l_array_source_36
187121       , l_array_source_37
187122       , l_array_source_38
187123       , l_array_source_39
187124       , l_array_source_40
187125       LIMIT l_rows;
187126 
187127   --
187128   IF (C_LEVEL_EVENT >= g_log_level) THEN
187129             trace
187130                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
187131                ,p_level    => C_LEVEL_EVENT
187132                ,p_module   => l_log_module);
187133   END IF;
187134   --
187135   EXIT WHEN l_array_entity_id.count = 0;
187136 
187137   XLA_AE_LINES_PKG.g_rec_lines := null;
187138 
187139 --
187140 -- Bug 4458708
187141 --
187142 XLA_AE_LINES_PKG.g_LineNumber := 0;
187143 --
187144 --
187145 
187146 FOR Idx IN 1..l_array_event_id.count LOOP
187147    --
187148    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
187149    --
187150    l_event_id := l_array_event_id(idx);  -- 5648433
187151 
187152    --
187153    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
187154    --
187155 
187156    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
187157              (g_array_event(l_event_id).array_value_num('header_index'))
187158          ,'N'
187159          ) <> 'Y'
187160    THEN
187161       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
187162          trace
187163             (p_msg      => 'Trancaction revesal option is not Y '
187164             ,p_level    => C_LEVEL_STATEMENT
187165             ,p_module   => l_log_module);
187166       END IF;
187167 
187168 --
187169 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
187170 --
187171 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
187172 --
187173 -- set event info as cache for other routines to refer event attributes
187174 --
187175 
187176 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
187180       (p_application_id           => p_application_id
187177    l_previous_event_id := l_event_id;
187178 
187179    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
187181       ,p_primary_ledger_id        => p_primary_ledger_id
187182       ,p_base_ledger_id           => p_base_ledger_id
187183       ,p_target_ledger_id         => p_target_ledger_id
187184       ,p_entity_id                => l_array_entity_id(Idx)
187185       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
187186       ,p_entity_code              => l_array_entity_code(Idx)
187187       ,p_transaction_num          => l_array_transaction_num(Idx)
187188       ,p_event_id                 => l_array_event_id(Idx)
187189       ,p_event_class_code         => l_array_class_code(Idx)
187190       ,p_event_type_code          => l_array_event_type(Idx)
187191       ,p_event_number             => l_array_event_number(Idx)
187192       ,p_event_date               => l_array_event_date(Idx)
187193       ,p_transaction_date         => l_array_transaction_date(Idx)
187194       ,p_reference_num_1          => l_array_reference_num_1(Idx)
187195       ,p_reference_num_2          => l_array_reference_num_2(Idx)
187196       ,p_reference_num_3          => l_array_reference_num_3(Idx)
187197       ,p_reference_num_4          => l_array_reference_num_4(Idx)
187198       ,p_reference_char_1         => l_array_reference_char_1(Idx)
187199       ,p_reference_char_2         => l_array_reference_char_2(Idx)
187203       ,p_reference_date_2         => l_array_reference_date_2(Idx)
187200       ,p_reference_char_3         => l_array_reference_char_3(Idx)
187201       ,p_reference_char_4         => l_array_reference_char_4(Idx)
187202       ,p_reference_date_1         => l_array_reference_date_1(Idx)
187204       ,p_reference_date_3         => l_array_reference_date_3(Idx)
187205       ,p_reference_date_4         => l_array_reference_date_4(Idx)
187206       ,p_event_created_by         => l_array_event_created_by(Idx)
187207       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
187208        --
187209 END IF;
187210 
187211 
187212 
187213 --
187214 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
187215 
187216 l_acct_reversal_source := SUBSTR(NULL, 1,30);
187217 
187218 IF l_continue_with_lines THEN
187219    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
187220       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
187221 
187222       xla_accounting_err_pkg.build_message
187223          (p_appli_s_name            => 'XLA'
187224          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
187225          ,p_token_1                 => 'LINE_NUMBER'
187226          ,p_value_1                 => l_array_extract_line_num(Idx)
187227          ,p_token_2                 => 'PRODUCT_NAME'
187228          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
187229          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
187230          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
187231          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
187232 
187233    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
187234       --
187235       -- following sets the accounting attributes needed to reverse
187236       -- accounting for a distributeion
187237       --
187238 
187239       --
187240       -- 5217187
187241       --
187242       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
187243       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
187244                                        g_array_event(l_event_id).array_value_num('header_index'));
187245       --
187246       --
187247 
187248       -- No reversal code generated
187249 
187250       xla_ae_lines_pkg.SetAcctReversalAttrs
187251          (p_event_id             => l_event_id
187252          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
187253          ,p_calculate_acctd_flag => l_calculate_acctd_flag
187254          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
187255    END IF;
187256 
187257    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
187258        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
187259 
187260 --
187261 AcctLineType_209 (
187262  p_application_id  => p_application_id
187263  ,p_event_id     => l_event_id
187264  ,p_calculate_acctd_flag => l_calculate_acctd_flag
187265  ,p_calculate_g_l_flag => l_calculate_g_l_flag
187266  ,p_actual_flag => l_actual_flag
187267  ,p_balance_type_code => l_balance_type_code
187268  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
187269  
187270  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
187271  , p_source_3 => l_array_source_3(Idx)
187272  , p_source_7 => l_array_source_7(Idx)
187273  , p_source_29 => l_array_source_29(Idx)
187274  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
187275  , p_source_35 => l_array_source_35(Idx)
187276  , p_source_36 => l_array_source_36(Idx)
187277  , p_source_37 => l_array_source_37(Idx)
187278  , p_source_38 => l_array_source_38(Idx)
187279  , p_source_39 => l_array_source_39(Idx)
187280  , p_source_40 => l_array_source_40(Idx)
187281  );
187282 If(l_balance_type_code = 'A') THEN
187283   l_actual_gain_loss_ref := l_gain_or_loss_ref;
187284 END IF;
187285 
187286 --
187287 
187288 
187289 --
187290 AcctLineType_210 (
187291  p_application_id  => p_application_id
187292  ,p_event_id     => l_event_id
187293  ,p_calculate_acctd_flag => l_calculate_acctd_flag
187294  ,p_calculate_g_l_flag => l_calculate_g_l_flag
187295  ,p_actual_flag => l_actual_flag
187296  ,p_balance_type_code => l_balance_type_code
187297  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
187298  
187299  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
187300  , p_source_3 => l_array_source_3(Idx)
187301  , p_source_5 => l_array_source_5(Idx)
187302  , p_source_6 => l_array_source_6(Idx)
187303  , p_source_29 => l_array_source_29(Idx)
187304  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
187305  , p_source_35 => l_array_source_35(Idx)
187306  , p_source_36 => l_array_source_36(Idx)
187307  , p_source_37 => l_array_source_37(Idx)
187308  , p_source_38 => l_array_source_38(Idx)
187309  , p_source_39 => l_array_source_39(Idx)
187310  , p_source_40 => l_array_source_40(Idx)
187311  );
187312 If(l_balance_type_code = 'A') THEN
187313   l_actual_gain_loss_ref := l_gain_or_loss_ref;
187314 END IF;
187315 
187316 --
187317 
187318       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
187319       -- or secondary ledger that has different currency with primary
187320       -- or alc that is calculated by sla
187321       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
187322             (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'))
187323 
187324 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
187325 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
187326           AND (l_actual_flag = 'A')) THEN
187327         XLA_AE_LINES_PKG.CreateGainOrLossLines(
187331          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
187328           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
187329          ,p_application_id   => p_application_id
187330          ,p_amb_context_code => 'DEFAULT'
187332          ,p_event_class_code => C_EVENT_CLASS_CODE
187333          ,p_event_type_code  => C_EVENT_TYPE_CODE
187334          
187335          ,p_gain_ccid        => -1
187336          ,p_loss_ccid        => -1
187337 
187338          ,p_actual_flag      => l_actual_flag
187339          ,p_enc_flag         => null
187340          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
187341          ,p_enc_g_l_ref      => null
187342          );
187343       END IF;
187344    END IF;
187345 END IF;
187346 
187347    ELSE
187348       --
187349       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
187350       --
187351       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
187352          trace
187353             (p_msg      => 'Trancaction revesal option is Y'
187354             ,p_level    => C_LEVEL_STATEMENT
187355             ,p_module   => l_log_module);
187356       END IF;
187357    END IF;
187358 
187359 END LOOP;
187360 l_result := XLA_AE_LINES_PKG.InsertLines ;
187361 end loop;
187362 close line_cur;
187363 
187364 
187365 --
187366 -- insert headers into xla_ae_headers_gt table
187367 --
187368 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
187369 
187370 -- insert into errors table here.
187371 
187372 END LOOP;
187373 
187374 --
187375 -- 4865292
187376 --
187377 -- Compare g_hdr_extract_count with event count in
187378 -- CreateHeadersAndLines.
187379 --
187380 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
187381 
187382 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
187383    trace (p_msg     => '# rows extracted from header extract objects '
187384                     || ' (running total): '
187385                     || g_hdr_extract_count
187386          ,p_level   => C_LEVEL_STATEMENT
187387          ,p_module  => l_log_module);
187388 END IF;
187389 
187390 CLOSE header_cur;
187391 --
187392 
187393 --
187394 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
187395    trace
187396       (p_msg      => 'END of EventClass_412'
187397       ,p_level    => C_LEVEL_PROCEDURE
187398       ,p_module   => l_log_module);
187399 END IF;
187400 --
187401 RETURN l_result;
187402 EXCEPTION
187403 WHEN xla_exceptions_pkg.application_exception THEN
187404    
187405 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
187406 
187407    
187408 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
187409 
187410    RAISE;
187411 
187412 WHEN NO_DATA_FOUND THEN
187413 
187414 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
187415 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
187416 
187417 FOR header_record IN header_cur
187418 LOOP
187419     l_array_header_events(header_record.event_id) := header_record.event_id;
187420 END LOOP;
187421 
187422 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
187423 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
187424 
187425 fnd_file.put_line(fnd_file.LOG, '                    ');
187426 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
187430 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
187427 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
187428 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
187429 
187431 LOOP
187432 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
187433 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
187434         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
187435 	END IF;
187436 END LOOP;
187437 
187438 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
187439 fnd_file.put_line(fnd_file.LOG, '                    ');
187440 
187441 
187442 xla_exceptions_pkg.raise_message
187443       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_412');
187444 
187445 
187446 WHEN OTHERS THEN
187447    xla_exceptions_pkg.raise_message
187448       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_412');
187449 END EventClass_412;
187450 --
187451 
187452 ---------------------------------------
187453 --
187454 -- PRIVATE PROCEDURE
187455 --         insert_sources_413
187456 --
187457 ----------------------------------------
187458 --
187459 PROCEDURE insert_sources_413(
187460                                 p_target_ledger_id       IN NUMBER
187461                               , p_language               IN VARCHAR2
187462                               , p_sla_ledger_id          IN NUMBER
187463                               , p_pad_start_date         IN DATE
187464                               , p_pad_end_date           IN DATE
187465                          )
187466 IS
187467 
187468 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_CATEGORY_RECLASS_ALL';
187469 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CIP_CATEGORY_RECLASS';
187470 p_apps_owner                   VARCHAR2(30);
187471 l_log_module                   VARCHAR2(240);
187472 BEGIN
187473 IF g_log_enabled THEN
187474       l_log_module := C_DEFAULT_MODULE||'.insert_sources_413';
187475 END IF;
187476 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
187477 
187478       trace
187479          (p_msg      => 'BEGIN of insert_sources_413'
187480          ,p_level    => C_LEVEL_PROCEDURE
187481          ,p_module   => l_log_module);
187482 
187483 END IF;
187484 
187485 -- select APPS owner
187486 SELECT oracle_username
187487   INTO p_apps_owner
187488   FROM fnd_oracle_userid
187489  WHERE read_only_flag = 'U'
187490 ;
187491 
187492 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
187493       trace
187494          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
187495                         ' - p_language = '||p_language||
187496                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
187497                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
187498                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
187499                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
187500          ,p_level    => C_LEVEL_STATEMENT
187501          ,p_module   => l_log_module);
187502 END IF;
187503 
187504 
187505 --
187506 INSERT INTO xla_diag_sources --hdr2
187507 (
187508         event_id
187509       , ledger_id
187510       , sla_ledger_id
187511       , description_language
187512       , object_name
187513       , object_type_code
187514       , line_number
187515       , source_application_id
187516       , source_type_code
187517       , source_code
187518       , source_value
187519       , source_meaning
187520       , created_by
187521       , creation_date
187522       , last_update_date
187523       , last_updated_by
187524       , last_update_login
187525       , program_update_date
187526       , program_application_id
187527       , program_id
187528       , request_id
187529 )
187530 SELECT
187531         event_id
187532       , p_target_ledger_id
187533       , p_sla_ledger_id
187534       , p_language
187535       , object_name
187536       , object_type_code
187537       , line_number
187538       , source_application_id
187539       , source_type_code
187540       , source_code
187541       , SUBSTR(source_value ,1,1996)
187542       , SUBSTR(source_meaning ,1,200)
187543       , xla_environment_pkg.g_Usr_Id
187544       , TRUNC(SYSDATE)
187548       , TRUNC(SYSDATE)
187545       , TRUNC(SYSDATE)
187546       , xla_environment_pkg.g_Usr_Id
187547       , xla_environment_pkg.g_Login_Id
187549       , xla_environment_pkg.g_Prog_Appl_Id
187550       , xla_environment_pkg.g_Prog_Id
187551       , xla_environment_pkg.g_Req_Id
187552   FROM (
187553        SELECT xet.event_id                  event_id
187554             , 0                          line_number
187555             , CASE r
187556                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
187557                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
187558                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
187559                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
187560                 
187561                ELSE null
187562               END                           object_name
187563             , CASE r
187564                 WHEN 1 THEN 'HEADER' 
187565                 WHEN 2 THEN 'HEADER' 
187566                 WHEN 3 THEN 'HEADER' 
187567                 WHEN 4 THEN 'HEADER' 
187568                 
187569                 ELSE null
187570               END                           object_type_code
187571             , CASE r
187572                 WHEN 1 THEN '140' 
187573                 WHEN 2 THEN '140' 
187574                 WHEN 3 THEN '140' 
187575                 WHEN 4 THEN '140' 
187576                 
187577                 ELSE null
187578               END                           source_application_id
187579             , 'S'             source_type_code
187580             , CASE r
187581                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
187582                 WHEN 2 THEN 'DEFAULT_CCID' 
187583                 WHEN 3 THEN 'ACCOUNTING_DATE' 
187584                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
187585                 
187586                 ELSE null
187587               END                           source_code
187588             , CASE r
187589                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
187590                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
187591                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
187592                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
187593                 
187594                 ELSE null
187595               END                           source_value
187596             , null              source_meaning
187597          FROM xla_events_gt     xet  
187598       , FA_XLA_EXT_HEADERS_B_GT  h1
187599              ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
187600          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
187601            AND xet.event_class_code = C_EVENT_CLASS_CODE
187602               AND h1.event_id = xet.event_id
187603 
187604 )
187605 ;
187606 --
187607 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
187608 
187609       trace
187610          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
187611          ,p_level    => C_LEVEL_STATEMENT
187612          ,p_module   => l_log_module);
187613 
187614 END IF;
187615 --
187616 
187617 
187618 
187619 --
187620 INSERT INTO xla_diag_sources  --line2
187621 (
187622         event_id
187623       , ledger_id
187624       , sla_ledger_id
187625       , description_language
187626       , object_name
187627       , object_type_code
187628       , line_number
187629       , source_application_id
187630       , source_type_code
187631       , source_code
187632       , source_value
187633       , source_meaning
187634       , created_by
187635       , creation_date
187636       , last_update_date
187637       , last_updated_by
187638       , last_update_login
187639       , program_update_date
187640       , program_application_id
187641       , program_id
187642       , request_id
187643 )
187644 SELECT  event_id
187645       , p_target_ledger_id
187646       , p_sla_ledger_id
187647       , p_language
187648       , object_name
187649       , object_type_code
187650       , line_number
187651       , source_application_id
187652       , source_type_code
187653       , source_code
187654       , SUBSTR(source_value,1,1996)
187655       , SUBSTR(source_meaning ,1,200)
187656       , xla_environment_pkg.g_Usr_Id
187657       , TRUNC(SYSDATE)
187658       , TRUNC(SYSDATE)
187659       , xla_environment_pkg.g_Usr_Id
187660       , xla_environment_pkg.g_Login_Id
187661       , TRUNC(SYSDATE)
187662       , xla_environment_pkg.g_Prog_Appl_Id
187663       , xla_environment_pkg.g_Prog_Id
187664       , xla_environment_pkg.g_Req_Id
187665   FROM (
187666        SELECT xet.event_id                  event_id
187667             , l2.line_number                 line_number
187668             , CASE r
187669                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
187670                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
187671                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
187672                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
187673                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
187674                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
187675                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
187676                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
187677                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
187678                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
187679                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
187680                 
187681                ELSE null
187682               END                           object_name
187683             , CASE r
187684                 WHEN 1 THEN 'LINE' 
187685                 WHEN 2 THEN 'LINE' 
187686                 WHEN 3 THEN 'LINE' 
187687                 WHEN 4 THEN 'LINE' 
187688                 WHEN 5 THEN 'LINE' 
187689                 WHEN 6 THEN 'LINE' 
187693                 WHEN 10 THEN 'LINE' 
187690                 WHEN 7 THEN 'LINE' 
187691                 WHEN 8 THEN 'LINE' 
187692                 WHEN 9 THEN 'LINE' 
187694                 WHEN 11 THEN 'LINE' 
187695                 
187696                 ELSE null
187697               END                           object_type_code
187698             , CASE r
187699                 WHEN 1 THEN '140' 
187700                 WHEN 2 THEN '140' 
187701                 WHEN 3 THEN '140' 
187702                 WHEN 4 THEN '140' 
187703                 WHEN 5 THEN '140' 
187704                 WHEN 6 THEN '140' 
187705                 WHEN 7 THEN '140' 
187706                 WHEN 8 THEN '140' 
187707                 WHEN 9 THEN '140' 
187708                 WHEN 10 THEN '140' 
187709                 WHEN 11 THEN '140' 
187710                 
187711                 ELSE null
187712               END                           source_application_id
187713             , 'S'             source_type_code
187714             , CASE r
187715                 WHEN 1 THEN 'GENERATED_CCID' 
187716                 WHEN 2 THEN 'CIP_COST_ACCT' 
187717                 WHEN 3 THEN 'REVAL_RESERVE_ACCT' 
187718                 WHEN 4 THEN 'EXPENSE_ACCOUNT_CCID' 
187719                 WHEN 5 THEN 'ADJUSTMENT_TYPE' 
187720                 WHEN 6 THEN 'TRANSACTION_HEADER_ID' 
187721                 WHEN 7 THEN 'ADJUSTMENT_LINE_ID' 
187722                 WHEN 8 THEN 'DISTRIBUTION_TYPE_CODE' 
187723                 WHEN 9 THEN 'ENTERED_AMOUNT' 
187724                 WHEN 10 THEN 'CURRENCY_CODE' 
187725                 WHEN 11 THEN 'SOURCE_DEST_CODE' 
187726                 
187727                 ELSE null
187728               END                           source_code
187729             , CASE r
187730                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
187731                 WHEN 2 THEN TO_CHAR(l2.CIP_COST_ACCT)
187732                 WHEN 3 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
187733                 WHEN 4 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
187734                 WHEN 5 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
187735                 WHEN 6 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
187736                 WHEN 7 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
187737                 WHEN 8 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
187738                 WHEN 9 THEN TO_CHAR(l2.ENTERED_AMOUNT)
187739                 WHEN 10 THEN TO_CHAR(l2.CURRENCY_CODE)
187740                 WHEN 11 THEN TO_CHAR(l2.SOURCE_DEST_CODE)
187741                 
187742                 ELSE null
187743               END                           source_value
187744             , null              source_meaning
187745          FROM  xla_events_gt     xet  
187746         , FA_XLA_EXT_LINES_B_GT  l2
187747             , (select rownum r from all_objects where rownum <= 11 and owner = p_apps_owner)
187748         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
187749           AND xet.event_class_code = C_EVENT_CLASS_CODE
187750             AND l2.event_id          = xet.event_id
187751   AND l2.ledger_id (+)  = p_sla_ledger_id
187752 
187753 )
187754 ;
187755 --
187756 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
187757 
187758       trace
187759          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
187760          ,p_level    => C_LEVEL_STATEMENT
187761          ,p_module   => l_log_module);
187762 
187763 END IF;
187764 
187765 
187766 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
187767       trace
187768          (p_msg      => 'END of insert_sources_413'
187769          ,p_level    => C_LEVEL_PROCEDURE
187770          ,p_module   => l_log_module);
187771 END IF;
187772 EXCEPTION
187773   WHEN xla_exceptions_pkg.application_exception THEN
187774       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
187775             trace
187776                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
187777                ,p_level    => C_LEVEL_EXCEPTION
187778                ,p_module   => l_log_module);
187779       END IF;
187780       RAISE;
187781   WHEN OTHERS THEN
187782       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
187783             trace
187784                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
187785                ,p_level    => C_LEVEL_EXCEPTION
187786                ,p_module   => l_log_module);
187787        END IF;
187788        xla_exceptions_pkg.raise_message
187789            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_413');
187790 END insert_sources_413;
187791 --
187792 
187793 ---------------------------------------
187794 --
187795 -- PRIVATE FUNCTION
187796 --         EventClass_413
187797 --
187798 ----------------------------------------
187799 --
187800 FUNCTION EventClass_413
187801        (p_application_id         IN NUMBER
187802        ,p_base_ledger_id         IN NUMBER
187803        ,p_target_ledger_id       IN NUMBER
187804        ,p_language               IN VARCHAR2
187805        ,p_currency_code          IN VARCHAR2
187806        ,p_sla_ledger_id          IN NUMBER
187807        ,p_pad_start_date         IN DATE
187808        ,p_pad_end_date           IN DATE
187809        ,p_primary_ledger_id      IN NUMBER)
187810 RETURN BOOLEAN IS
187811 --
187812 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_CATEGORY_RECLASS_ALL';
187813 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CIP_CATEGORY_RECLASS';
187814 
187815 l_calculate_acctd_flag   VARCHAR2(1) :='N';
187816 l_calculate_g_l_flag     VARCHAR2(1) :='N';
187817 --
187818 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
187819 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
187820 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
187821 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
187822 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
187823 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
187827 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
187824 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
187825 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
187826 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
187828 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
187829 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
187830 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
187831 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
187832 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
187833 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
187834 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
187835 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
187836 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
187837 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
187838 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
187839 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
187840 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
187841 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
187842 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
187843 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
187844 
187845 l_event_id                             NUMBER;
187846 l_previous_event_id                    NUMBER;
187847 l_first_event_id                       NUMBER;
187848 l_last_event_id                        NUMBER;
187849 
187850 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
187851 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
187852 --
187853 --
187854 l_result                    BOOLEAN := TRUE;
187855 l_rows                      NUMBER  := 1000;
187856 l_event_type_name           VARCHAR2(80) := 'All';
187857 l_event_class_name          VARCHAR2(80) := 'CIP Category Reclass';
187858 l_description               VARCHAR2(4000);
187859 l_transaction_reversal      NUMBER;
187860 l_ae_header_id              NUMBER;
187861 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
187862 l_log_module                VARCHAR2(240);
187863 --
187864 l_acct_reversal_source      VARCHAR2(30);
187865 l_trx_reversal_source       VARCHAR2(30);
187866 
187867 l_continue_with_lines       BOOLEAN := TRUE;
187868 --
187869 l_acc_rev_gl_date_source    DATE;                      -- 4262811
187870 --
187871 type t_array_event_id is table of number index by binary_integer;
187872 
187873 l_rec_array_event                    t_rec_array_event;
187874 l_null_rec_array_event               t_rec_array_event;
187875 l_array_ae_header_id                 xla_number_array_type;
187876 l_actual_flag                        VARCHAR2(1) := NULL;
187877 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
187878 l_balance_type_code                  VARCHAR2(1) :=NULL;
187879 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
187880 
187881 --
187882 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
187883 --
187884 
187885 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
187886 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
187887 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
187888 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
187889 
187890 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
187891 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
187892 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
187893 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
187894 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
187895 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
187896 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
187897 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
187898 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
187899 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
187900 TYPE t_array_source_42 IS TABLE OF FA_XLA_EXT_LINES_B_GT.SOURCE_DEST_CODE%TYPE INDEX BY BINARY_INTEGER;
187901 
187902 l_array_source_1              t_array_source_1;
187903 l_array_source_30              t_array_source_30;
187904 l_array_source_51              t_array_source_51;
187905 l_array_source_52              t_array_source_52;
187906 
187907 l_array_source_3      t_array_source_3;
187908 l_array_source_7      t_array_source_7;
187909 l_array_source_11      t_array_source_11;
187910 l_array_source_29      t_array_source_29;
187911 l_array_source_35      t_array_source_35;
187912 l_array_source_36      t_array_source_36;
187913 l_array_source_37      t_array_source_37;
187914 l_array_source_38      t_array_source_38;
187915 l_array_source_39      t_array_source_39;
187916 l_array_source_40      t_array_source_40;
187917 l_array_source_42      t_array_source_42;
187918 
187919 --
187920 CURSOR header_cur
187921 IS
187922 SELECT /*+ leading(xet) cardinality(xet,1) */
187923 -- Event Class Code: CIP_CATEGORY_RECLASS
187924     xet.entity_id
187925    ,xet.legal_entity_id
187926    ,xet.entity_code
187927    ,xet.transaction_number
187928    ,xet.event_id
187932    ,xet.event_date
187929    ,xet.event_class_code
187930    ,xet.event_type_code
187931    ,xet.event_number
187933    ,xet.transaction_date
187934    ,xet.reference_num_1
187935    ,xet.reference_num_2
187936    ,xet.reference_num_3
187937    ,xet.reference_num_4
187938    ,xet.reference_char_1
187939    ,xet.reference_char_2
187940    ,xet.reference_char_3
187941    ,xet.reference_char_4
187942    ,xet.reference_date_1
187943    ,xet.reference_date_2
187944    ,xet.reference_date_3
187945    ,xet.reference_date_4
187946    ,xet.event_created_by
187947    ,xet.budgetary_control_flag 
187948   , h1.PERIOD_CLOSE_DATE    source_1
187949   , h1.DEFAULT_CCID    source_30
187950   , h1.ACCOUNTING_DATE    source_51
187951   , h1.TRANSFER_TO_GL_FLAG    source_52
187952   FROM xla_events_gt     xet 
187953   , FA_XLA_EXT_HEADERS_B_GT  h1
187954  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
187955    and xet.event_class_code = C_EVENT_CLASS_CODE
187956    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
187957 
187958  ORDER BY event_id
187959 ;
187960 
187961 
187962 --
187963 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
187964 IS
187965 SELECT  /*+ leading(xet) cardinality(xet,1) */
187966 -- Event Class Code: CIP_CATEGORY_RECLASS
187967     xet.entity_id
187968    ,xet.legal_entity_id
187969    ,xet.entity_code
187970    ,xet.transaction_number
187971    ,xet.event_id
187972    ,xet.event_class_code
187973    ,xet.event_type_code
187974    ,xet.event_number
187975    ,xet.event_date
187976    ,xet.transaction_date
187977    ,xet.reference_num_1
187978    ,xet.reference_num_2
187979    ,xet.reference_num_3
187980    ,xet.reference_num_4
187981    ,xet.reference_char_1
187982    ,xet.reference_char_2
187983    ,xet.reference_char_3
187984    ,xet.reference_char_4
187985    ,xet.reference_date_1
187986    ,xet.reference_date_2
187987    ,xet.reference_date_3
187988    ,xet.reference_date_4
187989    ,xet.event_created_by
187990    ,xet.budgetary_control_flag
187991  , l2.LINE_NUMBER  
187992   , l2.GENERATED_CCID    source_3
187993   , l2.CIP_COST_ACCT    source_7
187994   , l2.REVAL_RESERVE_ACCT    source_11
187995   , l2.EXPENSE_ACCOUNT_CCID    source_29
187996   , l2.ADJUSTMENT_TYPE    source_35
187997   , l2.TRANSACTION_HEADER_ID    source_36
187998   , l2.ADJUSTMENT_LINE_ID    source_37
187999   , l2.DISTRIBUTION_TYPE_CODE    source_38
188000   , l2.ENTERED_AMOUNT    source_39
188001   , l2.CURRENCY_CODE    source_40
188002   , l2.SOURCE_DEST_CODE    source_42
188003   FROM xla_events_gt     xet 
188004   , FA_XLA_EXT_LINES_B_GT  l2
188005  WHERE xet.event_id between x_first_event_id and x_last_event_id
188006    and xet.event_date between p_pad_start_date and p_pad_end_date
188007    and xet.event_class_code = C_EVENT_CLASS_CODE
188008    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
188009   AND l2.ledger_id = p_sla_ledger_id
188010 ;
188011 
188012 --
188013 BEGIN
188014 IF g_log_enabled THEN
188015    l_log_module := C_DEFAULT_MODULE||'.EventClass_413';
188016 END IF;
188017 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
188018    trace
188019       (p_msg      => 'BEGIN of EventClass_413'
188020       ,p_level    => C_LEVEL_PROCEDURE
188021       ,p_module   => l_log_module);
188022 END IF;
188023 
188024 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
188025    trace
188026       (p_msg      => 'p_application_id = '||p_application_id||
188027                      ' - p_base_ledger_id = '||p_base_ledger_id||
188028                      ' - p_target_ledger_id  = '||p_target_ledger_id||
188029                      ' - p_language = '||p_language||
188030                      ' - p_currency_code = '||p_currency_code||
188031                      ' - p_sla_ledger_id = '||p_sla_ledger_id
188032       ,p_level    => C_LEVEL_STATEMENT
188033       ,p_module   => l_log_module);
188034 END IF;
188035 --
188036 -- initialze arrays
188037 --
188038 g_array_event.DELETE;
188039 l_rec_array_event := l_null_rec_array_event;
188040 --
188041 --------------------------------------
188042 -- 4262811 Initialze MPA Line Number
188043 --------------------------------------
188044 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
188045 
188046 --
188047 
188048 --
188049 OPEN header_cur;
188050 --
188051 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
188052    trace
188053    (p_msg      => 'SQL - FETCH header_cur'
188054    ,p_level    => C_LEVEL_STATEMENT
188055    ,p_module   => l_log_module);
188056 END IF;
188057 --
188058 LOOP
188059 FETCH header_cur BULK COLLECT INTO
188060         l_array_entity_id
188061       , l_array_legal_entity_id
188062       , l_array_entity_code
188063       , l_array_transaction_num
188064       , l_array_event_id
188065       , l_array_class_code
188066       , l_array_event_type
188067       , l_array_event_number
188068       , l_array_event_date
188069       , l_array_transaction_date
188070       , l_array_reference_num_1
188071       , l_array_reference_num_2
188072       , l_array_reference_num_3
188073       , l_array_reference_num_4
188074       , l_array_reference_char_1
188075       , l_array_reference_char_2
188076       , l_array_reference_char_3
188077       , l_array_reference_char_4
188078       , l_array_reference_date_1
188079       , l_array_reference_date_2
188080       , l_array_reference_date_3
188081       , l_array_reference_date_4
188082       , l_array_event_created_by
188083       , l_array_budgetary_control_flag 
188084       , l_array_source_1
188085       , l_array_source_30
188086       , l_array_source_51
188087       , l_array_source_52
188088       LIMIT l_rows;
188089 --
188090 IF (C_LEVEL_EVENT >= g_log_level) THEN
188091    trace
188095 END IF;
188092    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
188093    ,p_level    => C_LEVEL_EVENT
188094    ,p_module   => l_log_module);
188096 --
188097 EXIT WHEN l_array_entity_id.COUNT = 0;
188098 
188099 -- initialize arrays
188100 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
188101 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
188102 
188103 --
188104 -- Bug 4458708
188105 --
188106 XLA_AE_LINES_PKG.g_LineNumber := 0;
188107 
188108 
188109 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
188110 g_last_hdr_idx := l_array_event_id.LAST;
188111 --
188112 -- loop for the headers. Each iteration is for each header extract row
188113 -- fetched in header cursor
188114 --
188115 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
188116 
188117 --
188118 -- set event info as cache for other routines to refer event attributes
188119 --
188120 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
188121    (p_application_id           => p_application_id
188122    ,p_primary_ledger_id        => p_primary_ledger_id
188123    ,p_base_ledger_id           => p_base_ledger_id
188124    ,p_target_ledger_id         => p_target_ledger_id
188125    ,p_entity_id                => l_array_entity_id(hdr_idx)
188126    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
188127    ,p_entity_code              => l_array_entity_code(hdr_idx)
188128    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
188129    ,p_event_id                 => l_array_event_id(hdr_idx)
188130    ,p_event_class_code         => l_array_class_code(hdr_idx)
188131    ,p_event_type_code          => l_array_event_type(hdr_idx)
188132    ,p_event_number             => l_array_event_number(hdr_idx)
188133    ,p_event_date               => l_array_event_date(hdr_idx)
188134    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
188135    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
188136    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
188137    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
188138    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
188139    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
188140    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
188141    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
188142    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
188143    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
188144    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
188145    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
188146    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
188147    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
188148    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
188149 
188150 --
188151 -- set the status of entry to C_VALID (0)
188152 --
188153 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
188154 
188155 --
188156 -- initialize a row for ae header
188157 --
188158 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
188159 
188160 l_event_id := l_array_event_id(hdr_idx);
188161 
188162 --
188163 -- storing the hdr_idx for event. May be used by line cursor.
188164 --
188165 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
188166 
188167 --
188168 -- store sources from header extract. This can be improved to
188169 -- store only those sources from header extract that may be used in lines
188170 --
188171 
188172 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
188173 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
188174 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
188175 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
188176 
188177 --
188178 -- initilaize the status of ae headers for diffrent balance types
188179 -- the status is initialised to C_NOT_CREATED (2)
188180 --
188181 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
188182 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
188183 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
188184 
188185 --
188186 -- call api to validate and store accounting attributes for header
188187 --
188188 
188189 ------------------------------------------------------------
188190 -- Accrual Reversal : to get date for Standard Source (NONE)
188191 ------------------------------------------------------------
188192 l_acc_rev_gl_date_source := NULL;
188193 
188194      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
188195       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
188196      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
188197       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
188198 
188199 
188200 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
188201 
188202 XLA_AE_HEADER_PKG.SetJeCategoryName;
188203 
188204 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
188205 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
188206 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
188207 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
188208 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
188209 
188210 
188211 --
188212 xla_ae_header_pkg.SetHdrDescription(
188213    p_description => Description_28 (
188214    p_application_id => p_application_id 
188218 --
188215  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
188216    )
188217 );
188219 
188220 -- No header level analytical criteria
188221 
188222 --
188223 --accounting attribute enhancement, bug 3612931
188224 --
188225 l_trx_reversal_source := SUBSTR(NULL, 1,30);
188226 
188227 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
188228    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
188229 
188230    xla_accounting_err_pkg.build_message
188231       (p_appli_s_name            => 'XLA'
188232       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
188233       ,p_token_1                 => 'ACCT_ATTR_NAME'
188234       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
188235       ,p_token_2                 => 'PRODUCT_NAME'
188236       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
188237       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
188238       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
188239       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
188240 
188241 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
188242    --
188243    -- following sets the accounting attributes needed to reverse
188244    -- accounting for a distributeion
188245    --
188246    xla_ae_lines_pkg.SetTrxReversalAttrs
188247       (p_event_id              => l_event_id
188248       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
188249       ,p_trx_reversal_source   => l_trx_reversal_source);
188250 
188251 END IF;
188252 
188253 
188254 ----------------------------------------------------------------
188255 -- 4262811 -  update the header statuses to invalid in need be
188256 ----------------------------------------------------------------
188257 --
188258 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
188259 
188260 
188261   -----------------------------------------------
188262   -- No accrual reversal for the event class/type
188263   -----------------------------------------------
188264 ----------------------------------------------------------------
188265 
188266 --
188267 -- this ends the header loop iteration for one bulk fetch
188268 --
188269 END LOOP;
188270 
188271 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
188272 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
188273 
188274 --
188275 -- insert dummy rows into lines gt table that were created due to
188276 -- transaction reversals
188277 --
188278 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
188279    l_result := XLA_AE_LINES_PKG.InsertLines;
188280 END IF;
188281 
188282 --
188283 -- reset the temp_line_num for each set of events fetched from header
188284 -- cursor rather than doing it for each new event in line cursor
188285 -- Bug 3939231
188286 --
188287 xla_ae_lines_pkg.g_temp_line_num := 0;
188288 
188289 
188290 
188291 --
188292 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
188293 --
188294 --
188295 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
188296 
188297       trace
188298          (p_msg      => 'SQL - FETCH line_cur'
188299          ,p_level    => C_LEVEL_STATEMENT
188300          ,p_module   => l_log_module);
188301 
188302 END IF;
188303 --
188304 --
188305 LOOP
188306   --
188307   FETCH line_cur BULK COLLECT INTO
188308         l_array_entity_id
188309       , l_array_legal_entity_id
188310       , l_array_entity_code
188311       , l_array_transaction_num
188312       , l_array_event_id
188313       , l_array_class_code
188314       , l_array_event_type
188315       , l_array_event_number
188316       , l_array_event_date
188317       , l_array_transaction_date
188318       , l_array_reference_num_1
188319       , l_array_reference_num_2
188320       , l_array_reference_num_3
188321       , l_array_reference_num_4
188322       , l_array_reference_char_1
188323       , l_array_reference_char_2
188324       , l_array_reference_char_3
188325       , l_array_reference_char_4
188326       , l_array_reference_date_1
188327       , l_array_reference_date_2
188328       , l_array_reference_date_3
188329       , l_array_reference_date_4
188330       , l_array_event_created_by
188331       , l_array_budgetary_control_flag
188332       , l_array_extract_line_num 
188333       , l_array_source_3
188334       , l_array_source_7
188335       , l_array_source_11
188336       , l_array_source_29
188337       , l_array_source_35
188338       , l_array_source_36
188339       , l_array_source_37
188340       , l_array_source_38
188341       , l_array_source_39
188342       , l_array_source_40
188343       , l_array_source_42
188344       LIMIT l_rows;
188345 
188346   --
188347   IF (C_LEVEL_EVENT >= g_log_level) THEN
188348             trace
188349                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
188350                ,p_level    => C_LEVEL_EVENT
188351                ,p_module   => l_log_module);
188352   END IF;
188353   --
188354   EXIT WHEN l_array_entity_id.count = 0;
188355 
188356   XLA_AE_LINES_PKG.g_rec_lines := null;
188357 
188358 --
188359 -- Bug 4458708
188360 --
188361 XLA_AE_LINES_PKG.g_LineNumber := 0;
188362 --
188363 --
188364 
188365 FOR Idx IN 1..l_array_event_id.count LOOP
188366    --
188367    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
188368    --
188369    l_event_id := l_array_event_id(idx);  -- 5648433
188370 
188371    --
188372    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
188373    --
188377          ,'N'
188374 
188375    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
188376              (g_array_event(l_event_id).array_value_num('header_index'))
188378          ) <> 'Y'
188379    THEN
188380       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
188381          trace
188382             (p_msg      => 'Trancaction revesal option is not Y '
188383             ,p_level    => C_LEVEL_STATEMENT
188384             ,p_module   => l_log_module);
188385       END IF;
188386 
188387 --
188388 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
188389 --
188390 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
188391 --
188392 -- set event info as cache for other routines to refer event attributes
188393 --
188394 
188395 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
188396    l_previous_event_id := l_event_id;
188397 
188398    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
188399       (p_application_id           => p_application_id
188400       ,p_primary_ledger_id        => p_primary_ledger_id
188401       ,p_base_ledger_id           => p_base_ledger_id
188402       ,p_target_ledger_id         => p_target_ledger_id
188403       ,p_entity_id                => l_array_entity_id(Idx)
188404       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
188405       ,p_entity_code              => l_array_entity_code(Idx)
188406       ,p_transaction_num          => l_array_transaction_num(Idx)
188407       ,p_event_id                 => l_array_event_id(Idx)
188408       ,p_event_class_code         => l_array_class_code(Idx)
188409       ,p_event_type_code          => l_array_event_type(Idx)
188410       ,p_event_number             => l_array_event_number(Idx)
188411       ,p_event_date               => l_array_event_date(Idx)
188412       ,p_transaction_date         => l_array_transaction_date(Idx)
188413       ,p_reference_num_1          => l_array_reference_num_1(Idx)
188414       ,p_reference_num_2          => l_array_reference_num_2(Idx)
188415       ,p_reference_num_3          => l_array_reference_num_3(Idx)
188416       ,p_reference_num_4          => l_array_reference_num_4(Idx)
188417       ,p_reference_char_1         => l_array_reference_char_1(Idx)
188418       ,p_reference_char_2         => l_array_reference_char_2(Idx)
188419       ,p_reference_char_3         => l_array_reference_char_3(Idx)
188420       ,p_reference_char_4         => l_array_reference_char_4(Idx)
188421       ,p_reference_date_1         => l_array_reference_date_1(Idx)
188422       ,p_reference_date_2         => l_array_reference_date_2(Idx)
188423       ,p_reference_date_3         => l_array_reference_date_3(Idx)
188424       ,p_reference_date_4         => l_array_reference_date_4(Idx)
188425       ,p_event_created_by         => l_array_event_created_by(Idx)
188426       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
188427        --
188428 END IF;
188429 
188430 
188431 
188432 --
188433 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
188434 
188435 l_acct_reversal_source := SUBSTR(NULL, 1,30);
188436 
188437 IF l_continue_with_lines THEN
188438    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
188439       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
188440 
188441       xla_accounting_err_pkg.build_message
188442          (p_appli_s_name            => 'XLA'
188443          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
188444          ,p_token_1                 => 'LINE_NUMBER'
188445          ,p_value_1                 => l_array_extract_line_num(Idx)
188446          ,p_token_2                 => 'PRODUCT_NAME'
188447          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
188448          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
188449          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
188450          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
188451 
188452    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
188453       --
188454       -- following sets the accounting attributes needed to reverse
188455       -- accounting for a distributeion
188456       --
188457 
188458       --
188459       -- 5217187
188460       --
188461       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
188462       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
188463                                        g_array_event(l_event_id).array_value_num('header_index'));
188464       --
188465       --
188466 
188467       -- No reversal code generated
188468 
188469       xla_ae_lines_pkg.SetAcctReversalAttrs
188470          (p_event_id             => l_event_id
188471          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
188472          ,p_calculate_acctd_flag => l_calculate_acctd_flag
188473          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
188474    END IF;
188475 
188476    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
188477        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
188478 
188479 --
188480 AcctLineType_227 (
188481  p_application_id  => p_application_id
188482  ,p_event_id     => l_event_id
188483  ,p_calculate_acctd_flag => l_calculate_acctd_flag
188484  ,p_calculate_g_l_flag => l_calculate_g_l_flag
188485  ,p_actual_flag => l_actual_flag
188486  ,p_balance_type_code => l_balance_type_code
188487  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
188488  
188489  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
188490  , p_source_3 => l_array_source_3(Idx)
188491  , p_source_7 => l_array_source_7(Idx)
188492  , p_source_29 => l_array_source_29(Idx)
188493  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
188494  , p_source_35 => l_array_source_35(Idx)
188495  , p_source_36 => l_array_source_36(Idx)
188496  , p_source_37 => l_array_source_37(Idx)
188497  , p_source_38 => l_array_source_38(Idx)
188503   l_actual_gain_loss_ref := l_gain_or_loss_ref;
188498  , p_source_39 => l_array_source_39(Idx)
188499  , p_source_40 => l_array_source_40(Idx)
188500  , p_source_42 => l_array_source_42(Idx)
188501  );
188502 If(l_balance_type_code = 'A') THEN
188504 END IF;
188505 
188506 --
188507 
188508 
188509 --
188510 AcctLineType_228 (
188511  p_application_id  => p_application_id
188512  ,p_event_id     => l_event_id
188513  ,p_calculate_acctd_flag => l_calculate_acctd_flag
188514  ,p_calculate_g_l_flag => l_calculate_g_l_flag
188515  ,p_actual_flag => l_actual_flag
188516  ,p_balance_type_code => l_balance_type_code
188517  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
188518  
188519  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
188520  , p_source_3 => l_array_source_3(Idx)
188521  , p_source_11 => l_array_source_11(Idx)
188522  , p_source_29 => l_array_source_29(Idx)
188523  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
188524  , p_source_35 => l_array_source_35(Idx)
188525  , p_source_36 => l_array_source_36(Idx)
188526  , p_source_37 => l_array_source_37(Idx)
188527  , p_source_38 => l_array_source_38(Idx)
188528  , p_source_39 => l_array_source_39(Idx)
188529  , p_source_40 => l_array_source_40(Idx)
188530  , p_source_42 => l_array_source_42(Idx)
188531  );
188532 If(l_balance_type_code = 'A') THEN
188533   l_actual_gain_loss_ref := l_gain_or_loss_ref;
188534 END IF;
188535 
188536 --
188537 
188538 
188539 --
188540 AcctLineType_229 (
188541  p_application_id  => p_application_id
188542  ,p_event_id     => l_event_id
188543  ,p_calculate_acctd_flag => l_calculate_acctd_flag
188544  ,p_calculate_g_l_flag => l_calculate_g_l_flag
188545  ,p_actual_flag => l_actual_flag
188546  ,p_balance_type_code => l_balance_type_code
188547  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
188548  
188549  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
188550  , p_source_3 => l_array_source_3(Idx)
188551  , p_source_7 => l_array_source_7(Idx)
188552  , p_source_29 => l_array_source_29(Idx)
188553  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
188554  , p_source_35 => l_array_source_35(Idx)
188555  , p_source_36 => l_array_source_36(Idx)
188556  , p_source_37 => l_array_source_37(Idx)
188557  , p_source_38 => l_array_source_38(Idx)
188558  , p_source_39 => l_array_source_39(Idx)
188559  , p_source_40 => l_array_source_40(Idx)
188560  , p_source_42 => l_array_source_42(Idx)
188561  );
188562 If(l_balance_type_code = 'A') THEN
188563   l_actual_gain_loss_ref := l_gain_or_loss_ref;
188564 END IF;
188565 
188566 --
188567 
188568 
188569 --
188570 AcctLineType_230 (
188571  p_application_id  => p_application_id
188572  ,p_event_id     => l_event_id
188573  ,p_calculate_acctd_flag => l_calculate_acctd_flag
188574  ,p_calculate_g_l_flag => l_calculate_g_l_flag
188575  ,p_actual_flag => l_actual_flag
188576  ,p_balance_type_code => l_balance_type_code
188577  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
188578  
188579  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
188580  , p_source_3 => l_array_source_3(Idx)
188581  , p_source_11 => l_array_source_11(Idx)
188582  , p_source_29 => l_array_source_29(Idx)
188583  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
188584  , p_source_35 => l_array_source_35(Idx)
188585  , p_source_36 => l_array_source_36(Idx)
188586  , p_source_37 => l_array_source_37(Idx)
188587  , p_source_38 => l_array_source_38(Idx)
188588  , p_source_39 => l_array_source_39(Idx)
188589  , p_source_40 => l_array_source_40(Idx)
188590  , p_source_42 => l_array_source_42(Idx)
188591  );
188592 If(l_balance_type_code = 'A') THEN
188593   l_actual_gain_loss_ref := l_gain_or_loss_ref;
188594 END IF;
188595 
188596 --
188597 
188598       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
188599       -- or secondary ledger that has different currency with primary
188600       -- or alc that is calculated by sla
188601       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
188602             (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'))
188603 
188604 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
188605 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
188606           AND (l_actual_flag = 'A')) THEN
188607         XLA_AE_LINES_PKG.CreateGainOrLossLines(
188608           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
188609          ,p_application_id   => p_application_id
188610          ,p_amb_context_code => 'DEFAULT'
188611          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
188612          ,p_event_class_code => C_EVENT_CLASS_CODE
188613          ,p_event_type_code  => C_EVENT_TYPE_CODE
188614          
188618          ,p_actual_flag      => l_actual_flag
188615          ,p_gain_ccid        => -1
188616          ,p_loss_ccid        => -1
188617 
188619          ,p_enc_flag         => null
188620          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
188621          ,p_enc_g_l_ref      => null
188622          );
188623       END IF;
188624    END IF;
188625 END IF;
188626 
188627    ELSE
188628       --
188629       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
188630       --
188631       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
188632          trace
188633             (p_msg      => 'Trancaction revesal option is Y'
188634             ,p_level    => C_LEVEL_STATEMENT
188635             ,p_module   => l_log_module);
188636       END IF;
188637    END IF;
188638 
188639 END LOOP;
188640 l_result := XLA_AE_LINES_PKG.InsertLines ;
188641 end loop;
188642 close line_cur;
188643 
188644 
188645 --
188646 -- insert headers into xla_ae_headers_gt table
188647 --
188648 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
188649 
188650 -- insert into errors table here.
188651 
188652 END LOOP;
188653 
188654 --
188655 -- 4865292
188656 --
188657 -- Compare g_hdr_extract_count with event count in
188658 -- CreateHeadersAndLines.
188659 --
188660 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
188661 
188662 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
188663    trace (p_msg     => '# rows extracted from header extract objects '
188664                     || ' (running total): '
188665                     || g_hdr_extract_count
188666          ,p_level   => C_LEVEL_STATEMENT
188667          ,p_module  => l_log_module);
188668 END IF;
188669 
188670 CLOSE header_cur;
188671 --
188672 
188673 --
188674 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
188675    trace
188676       (p_msg      => 'END of EventClass_413'
188677       ,p_level    => C_LEVEL_PROCEDURE
188678       ,p_module   => l_log_module);
188679 END IF;
188680 --
188681 RETURN l_result;
188682 EXCEPTION
188683 WHEN xla_exceptions_pkg.application_exception THEN
188684    
188685 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
188686 
188687    
188688 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
188689 
188690    RAISE;
188691 
188692 WHEN NO_DATA_FOUND THEN
188693 
188694 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
188695 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
188696 
188697 FOR header_record IN header_cur
188698 LOOP
188699     l_array_header_events(header_record.event_id) := header_record.event_id;
188700 END LOOP;
188701 
188702 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
188703 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
188704 
188705 fnd_file.put_line(fnd_file.LOG, '                    ');
188706 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
188707 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
188708 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
188709 
188710 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
188711 LOOP
188712 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
188713 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
188714         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
188715 	END IF;
188716 END LOOP;
188717 
188718 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
188719 fnd_file.put_line(fnd_file.LOG, '                    ');
188720 
188721 
188722 xla_exceptions_pkg.raise_message
188723       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_413');
188724 
188725 
188726 WHEN OTHERS THEN
188727    xla_exceptions_pkg.raise_message
188728       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_413');
188729 END EventClass_413;
188730 --
188731 
188732 ---------------------------------------
188733 --
188734 -- PRIVATE PROCEDURE
188735 --         insert_sources_414
188736 --
188737 ----------------------------------------
188738 --
188739 PROCEDURE insert_sources_414(
188740                                 p_target_ledger_id       IN NUMBER
188741                               , p_language               IN VARCHAR2
188742                               , p_sla_ledger_id          IN NUMBER
188743                               , p_pad_start_date         IN DATE
188744                               , p_pad_end_date           IN DATE
188745                          )
188746 IS
188747 
188748 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_REINSTATEMENTS';
188749 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CIP_RETIREMENTS';
188750 p_apps_owner                   VARCHAR2(30);
188751 l_log_module                   VARCHAR2(240);
188752 BEGIN
188753 IF g_log_enabled THEN
188754       l_log_module := C_DEFAULT_MODULE||'.insert_sources_414';
188755 END IF;
188756 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
188757 
188758       trace
188759          (p_msg      => 'BEGIN of insert_sources_414'
188760          ,p_level    => C_LEVEL_PROCEDURE
188761          ,p_module   => l_log_module);
188762 
188763 END IF;
188764 
188765 -- select APPS owner
188766 SELECT oracle_username
188767   INTO p_apps_owner
188768   FROM fnd_oracle_userid
188769  WHERE read_only_flag = 'U'
188770 ;
188771 
188772 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
188773       trace
188774          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
188775                         ' - p_language = '||p_language||
188779                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
188776                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
188777                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
188778                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
188780          ,p_level    => C_LEVEL_STATEMENT
188781          ,p_module   => l_log_module);
188782 END IF;
188783 
188784 
188785 --
188786 INSERT INTO xla_diag_sources --hdr1
188787 (
188788         event_id
188789       , ledger_id
188790       , sla_ledger_id
188791       , description_language
188792       , object_name
188793       , object_type_code
188794       , line_number
188795       , source_application_id
188796       , source_type_code
188797       , source_code
188798       , source_value
188799       , source_meaning
188800       , created_by
188801       , creation_date
188802       , last_update_date
188803       , last_updated_by
188804       , last_update_login
188805       , program_update_date
188806       , program_application_id
188807       , program_id
188808       , request_id
188809 )
188810 SELECT
188811         event_id
188812       , p_target_ledger_id
188813       , p_sla_ledger_id
188814       , p_language
188815       , object_name
188816       , object_type_code
188817       , line_number
188818       , source_application_id
188819       , source_type_code
188820       , source_code
188821       , SUBSTR(source_value ,1,1996)
188822       , SUBSTR(source_meaning,1,200)
188823       , xla_environment_pkg.g_Usr_Id
188824       , TRUNC(SYSDATE)
188825       , TRUNC(SYSDATE)
188826       , xla_environment_pkg.g_Usr_Id
188827       , xla_environment_pkg.g_Login_Id
188828       , TRUNC(SYSDATE)
188829       , xla_environment_pkg.g_Prog_Appl_Id
188830       , xla_environment_pkg.g_Prog_Id
188831       , xla_environment_pkg.g_Req_Id
188832   FROM (
188833        SELECT xet.event_id                  event_id
188834             , 0                             line_number
188835             , CASE r
188836                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188837                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188838                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188839                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188840                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188841                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188842                 WHEN 7 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188843                 WHEN 8 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188844                 WHEN 9 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188845                 WHEN 10 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188846                 WHEN 11 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188847                 WHEN 12 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188848                 WHEN 13 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
188849                 
188850                ELSE null
188851               END                           object_name
188852             , CASE r
188853                 WHEN 1 THEN 'HEADER' 
188854                 WHEN 2 THEN 'HEADER' 
188855                 WHEN 3 THEN 'HEADER' 
188856                 WHEN 4 THEN 'HEADER' 
188857                 WHEN 5 THEN 'HEADER' 
188858                 WHEN 6 THEN 'HEADER' 
188859                 WHEN 7 THEN 'HEADER' 
188860                 WHEN 8 THEN 'HEADER' 
188861                 WHEN 9 THEN 'HEADER' 
188862                 WHEN 10 THEN 'HEADER' 
188863                 WHEN 11 THEN 'HEADER' 
188864                 WHEN 12 THEN 'HEADER' 
188865                 WHEN 13 THEN 'HEADER' 
188866                 
188867                 ELSE null
188868               END                           object_type_code
188869             , CASE r
188870                 WHEN 1 THEN '140' 
188871                 WHEN 2 THEN '140' 
188872                 WHEN 3 THEN '140' 
188873                 WHEN 4 THEN '140' 
188874                 WHEN 5 THEN '140' 
188875                 WHEN 6 THEN '140' 
188876                 WHEN 7 THEN '140' 
188877                 WHEN 8 THEN '140' 
188878                 WHEN 9 THEN '140' 
188879                 WHEN 10 THEN '140' 
188880                 WHEN 11 THEN '140' 
188881                 WHEN 12 THEN '140' 
188882                 WHEN 13 THEN '140' 
188883                 
188884                 ELSE null
188885               END                           source_application_id
188886             , 'S'             source_type_code
188887             , CASE r
188888                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
188889                 WHEN 2 THEN 'COST_OF_REMOVAL_CLEARING_ACCT' 
188890                 WHEN 3 THEN 'COST_OF_REMOVAL_GAIN_ACCT' 
188891                 WHEN 4 THEN 'COST_OF_REMOVAL_LOSS_ACCT' 
188892                 WHEN 5 THEN 'NBV_RETIRED_GAIN_ACCT' 
188893                 WHEN 6 THEN 'NBV_RETIRED_LOSS_ACCT' 
188894                 WHEN 7 THEN 'PROCEEDS_OF_SALE_CLEARING_ACCT' 
188895                 WHEN 8 THEN 'PROCEEDS_OF_SALE_GAIN_ACCT' 
188896                 WHEN 9 THEN 'PROCEEDS_OF_SALE_LOSS_ACCT' 
188897                 WHEN 10 THEN 'REVAL_RSV_RETIRED_LOSS_ACCT' 
188898                 WHEN 11 THEN 'DEFAULT_CCID' 
188899                 WHEN 12 THEN 'ACCOUNTING_DATE' 
188900                 WHEN 13 THEN 'TRANSFER_TO_GL_FLAG' 
188901                 
188902                 ELSE null
188903               END                           source_code
188904             , CASE r
188905                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
188906                 WHEN 2 THEN TO_CHAR(h1.COST_OF_REMOVAL_CLEARING_ACCT)
188907                 WHEN 3 THEN TO_CHAR(h1.COST_OF_REMOVAL_GAIN_ACCT)
188908                 WHEN 4 THEN TO_CHAR(h1.COST_OF_REMOVAL_LOSS_ACCT)
188909                 WHEN 5 THEN TO_CHAR(h1.NBV_RETIRED_GAIN_ACCT)
188910                 WHEN 6 THEN TO_CHAR(h1.NBV_RETIRED_LOSS_ACCT)
188911                 WHEN 7 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_CLEARING_ACCT)
188915                 WHEN 11 THEN TO_CHAR(h1.DEFAULT_CCID)
188912                 WHEN 8 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_GAIN_ACCT)
188913                 WHEN 9 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_LOSS_ACCT)
188914                 WHEN 10 THEN TO_CHAR(h1.REVAL_RSV_RETIRED_LOSS_ACCT)
188916                 WHEN 12 THEN TO_CHAR(h1.ACCOUNTING_DATE)
188917                 WHEN 13 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
188918                 
188919                 ELSE null
188920               END                           source_value
188921             , null              source_meaning
188922         FROM xla_events_gt     xet  
188923       , FA_XLA_EXT_HEADERS_B_GT  h1
188924             ,(select rownum r from all_objects where rownum <= 13 and owner = p_apps_owner)
188925        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
188926          AND xet.event_type_code = C_EVENT_TYPE_CODE
188927             AND h1.event_id = xet.event_id
188928 
188929 )
188930 ;
188931 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
188932 
188933       trace
188934          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
188935          ,p_level    => C_LEVEL_STATEMENT
188936          ,p_module   => l_log_module);
188937 
188938 END IF;
188939 --
188940 
188941 
188942 
188943 --
188944 INSERT INTO xla_diag_sources --line1
188945 (
188946         event_id
188947       , ledger_id
188948       , sla_ledger_id
188949       , description_language
188950       , object_name
188951       , object_type_code
188952       , line_number
188953       , source_application_id
188954       , source_type_code
188955       , source_code
188956       , source_value
188957       , source_meaning
188958       , created_by
188959       , creation_date
188960       , last_update_date
188961       , last_updated_by
188962       , last_update_login
188963       , program_update_date
188964       , program_application_id
188965       , program_id
188966       , request_id
188967 )
188968 SELECT  event_id
188969       , p_target_ledger_id
188970       , p_sla_ledger_id
188971       , p_language
188972       , object_name
188973       , object_type_code
188974       , line_number
188975       , source_application_id
188976       , source_type_code
188977       , source_code
188978       , SUBSTR(source_value,1,1996)
188979       , SUBSTR(source_meaning,1,200)
188980       , xla_environment_pkg.g_Usr_Id
188981       , TRUNC(SYSDATE)
188982       , TRUNC(SYSDATE)
188983       , xla_environment_pkg.g_Usr_Id
188984       , xla_environment_pkg.g_Login_Id
188985       , TRUNC(SYSDATE)
188986       , xla_environment_pkg.g_Prog_Appl_Id
188987       , xla_environment_pkg.g_Prog_Id
188988       , xla_environment_pkg.g_Req_Id
188989   FROM (
188990        SELECT xet.event_id                  event_id
188991             , l2.line_number                 line_number
188992             , CASE r
188993                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
188994                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
188995                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
188996                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
188997                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
188998                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
188999                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
189000                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
189001                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
189002                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
189003                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
189004                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
189005                 
189006                ELSE null
189007               END                           object_name
189008             , CASE r
189009                 WHEN 1 THEN 'LINE' 
189010                 WHEN 2 THEN 'LINE' 
189011                 WHEN 3 THEN 'LINE' 
189012                 WHEN 4 THEN 'LINE' 
189013                 WHEN 5 THEN 'LINE' 
189014                 WHEN 6 THEN 'LINE' 
189015                 WHEN 7 THEN 'LINE' 
189016                 WHEN 8 THEN 'LINE' 
189017                 WHEN 9 THEN 'LINE' 
189018                 WHEN 10 THEN 'LINE' 
189019                 WHEN 11 THEN 'LINE' 
189020                 WHEN 12 THEN 'LINE' 
189021                 
189022                 ELSE null
189023               END                           object_type_code
189024             , CASE r
189025                 WHEN 1 THEN '140' 
189026                 WHEN 2 THEN '140' 
189027                 WHEN 3 THEN '140' 
189028                 WHEN 4 THEN '140' 
189029                 WHEN 5 THEN '140' 
189030                 WHEN 6 THEN '140' 
189031                 WHEN 7 THEN '140' 
189032                 WHEN 8 THEN '140' 
189033                 WHEN 9 THEN '140' 
189034                 WHEN 10 THEN '140' 
189035                 WHEN 11 THEN '140' 
189036                 WHEN 12 THEN '140' 
189037                 
189038                 ELSE null
189039               END                           source_application_id
189040             , 'S'             source_type_code
189041             , CASE r
189042                 WHEN 1 THEN 'GENERATED_CCID' 
189043                 WHEN 2 THEN 'CIP_COST_ACCT' 
189044                 WHEN 3 THEN 'REVAL_RESERVE_ACCT' 
189045                 WHEN 4 THEN 'GENERATED_OFFSET_CCID' 
189046                 WHEN 5 THEN 'EXPENSE_ACCOUNT_CCID' 
189047                 WHEN 6 THEN 'ADJUSTMENT_TYPE' 
189048                 WHEN 7 THEN 'TRANSACTION_HEADER_ID' 
189049                 WHEN 8 THEN 'ADJUSTMENT_LINE_ID' 
189050                 WHEN 9 THEN 'DISTRIBUTION_TYPE_CODE' 
189051                 WHEN 10 THEN 'ENTERED_AMOUNT' 
189052                 WHEN 11 THEN 'CURRENCY_CODE' 
189053                 WHEN 12 THEN 'GAIN_LOSS_AMOUNT' 
189054                 
189055                 ELSE null
189056               END                           source_code
189060                 WHEN 3 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
189057             , CASE r
189058                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
189059                 WHEN 2 THEN TO_CHAR(l2.CIP_COST_ACCT)
189061                 WHEN 4 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
189062                 WHEN 5 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
189063                 WHEN 6 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
189064                 WHEN 7 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
189065                 WHEN 8 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
189066                 WHEN 9 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
189067                 WHEN 10 THEN TO_CHAR(l2.ENTERED_AMOUNT)
189068                 WHEN 11 THEN TO_CHAR(l2.CURRENCY_CODE)
189069                 WHEN 12 THEN TO_CHAR(l2.GAIN_LOSS_AMOUNT)
189070                 
189071                 ELSE null
189072               END                           source_value
189073             , null              source_meaning
189074          FROM  xla_events_gt     xet  
189075         , FA_XLA_EXT_LINES_B_GT  l2
189076             ,(select rownum r from all_objects where rownum <= 12 and owner = p_apps_owner)
189077         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
189078           AND xet.event_type_code = C_EVENT_TYPE_CODE
189079             AND l2.event_id          = xet.event_id
189080   AND l2.ledger_id (+)  = p_sla_ledger_id
189081 
189082 )
189083 ;
189084 --
189085 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
189086 
189087       trace
189088          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
189089          ,p_level    => C_LEVEL_STATEMENT
189090          ,p_module   => l_log_module);
189091 
189092 END IF;
189093 
189094 
189095 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
189096       trace
189097          (p_msg      => 'END of insert_sources_414'
189098          ,p_level    => C_LEVEL_PROCEDURE
189099          ,p_module   => l_log_module);
189100 END IF;
189101 EXCEPTION
189102   WHEN xla_exceptions_pkg.application_exception THEN
189103       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
189104             trace
189105                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
189106                ,p_level    => C_LEVEL_EXCEPTION
189107                ,p_module   => l_log_module);
189108       END IF;
189109       RAISE;
189110   WHEN OTHERS THEN
189111       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
189112             trace
189113                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
189114                ,p_level    => C_LEVEL_EXCEPTION
189115                ,p_module   => l_log_module);
189116        END IF;
189117        xla_exceptions_pkg.raise_message
189118            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_414');
189119 END insert_sources_414;
189120 --
189121 
189122 ---------------------------------------
189123 --
189124 -- PRIVATE FUNCTION
189125 --         EventType_414
189126 --
189127 ----------------------------------------
189128 --
189129 FUNCTION EventType_414
189130        (p_application_id         IN NUMBER
189131        ,p_base_ledger_id         IN NUMBER
189132        ,p_target_ledger_id       IN NUMBER
189133        ,p_language               IN VARCHAR2
189134        ,p_currency_code          IN VARCHAR2
189135        ,p_sla_ledger_id          IN NUMBER
189136        ,p_pad_start_date         IN DATE
189137        ,p_pad_end_date           IN DATE
189138        ,p_primary_ledger_id      IN NUMBER)
189139 RETURN BOOLEAN IS
189140 --
189141 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_REINSTATEMENTS';
189142 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CIP_RETIREMENTS';
189143 
189144 l_calculate_acctd_flag   VARCHAR2(1) :='N';
189145 l_calculate_g_l_flag     VARCHAR2(1) :='N';
189146 --
189147 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
189148 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
189149 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
189150 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
189151 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
189152 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
189153 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
189154 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
189155 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
189156 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
189157 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
189158 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
189159 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
189160 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
189161 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
189162 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
189163 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
189164 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
189165 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
189166 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
189167 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
189168 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
189169 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
189170 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
189171 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
189172 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
189173 
189174 l_event_id                             NUMBER;
189175 l_previous_event_id                    NUMBER;
189179 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
189176 l_first_event_id                       NUMBER;
189177 l_last_event_id                        NUMBER;
189178 
189180 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
189181 --
189182 --
189183 l_result                    BOOLEAN := TRUE;
189184 l_rows                      NUMBER  := 1000;
189185 l_event_type_name           VARCHAR2(80) := 'CIP Reinstatements';
189186 l_event_class_name          VARCHAR2(80) := 'CIP Retirements';
189187 l_description               VARCHAR2(4000);
189188 l_transaction_reversal      NUMBER;
189189 l_ae_header_id              NUMBER;
189190 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
189191 l_log_module                VARCHAR2(240);
189192 --
189193 l_acct_reversal_source      VARCHAR2(30);
189194 l_trx_reversal_source       VARCHAR2(30);
189195 
189196 l_continue_with_lines       BOOLEAN := TRUE;
189197 --
189198 l_acc_rev_gl_date_source    DATE;                      -- 4262811
189199 --
189200 type t_array_event_id is table of number index by binary_integer;
189201 
189202 l_rec_array_event                    t_rec_array_event;
189203 l_null_rec_array_event               t_rec_array_event;
189204 l_array_ae_header_id                 xla_number_array_type;
189205 l_actual_flag                        VARCHAR2(1) := NULL;
189206 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
189207 l_balance_type_code                  VARCHAR2(1) :=NULL;
189208 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
189209 
189210 --
189211 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
189212 --
189213 
189214 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
189215 TYPE t_array_source_12 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
189216 TYPE t_array_source_13 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
189217 TYPE t_array_source_14 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
189218 TYPE t_array_source_21 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
189219 TYPE t_array_source_22 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
189220 TYPE t_array_source_23 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
189221 TYPE t_array_source_24 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
189222 TYPE t_array_source_25 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
189223 TYPE t_array_source_28 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.REVAL_RSV_RETIRED_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
189224 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
189225 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
189226 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
189227 
189228 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
189229 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
189230 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
189231 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
189232 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
189233 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
189234 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
189235 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
189236 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
189237 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
189238 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
189239 TYPE t_array_source_41 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GAIN_LOSS_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
189240 
189241 l_array_source_1              t_array_source_1;
189242 l_array_source_12              t_array_source_12;
189243 l_array_source_13              t_array_source_13;
189244 l_array_source_14              t_array_source_14;
189245 l_array_source_21              t_array_source_21;
189246 l_array_source_22              t_array_source_22;
189247 l_array_source_23              t_array_source_23;
189248 l_array_source_24              t_array_source_24;
189249 l_array_source_25              t_array_source_25;
189250 l_array_source_28              t_array_source_28;
189251 l_array_source_30              t_array_source_30;
189252 l_array_source_51              t_array_source_51;
189253 l_array_source_52              t_array_source_52;
189254 
189255 l_array_source_3      t_array_source_3;
189256 l_array_source_7      t_array_source_7;
189257 l_array_source_11      t_array_source_11;
189258 l_array_source_17      t_array_source_17;
189259 l_array_source_29      t_array_source_29;
189260 l_array_source_35      t_array_source_35;
189261 l_array_source_36      t_array_source_36;
189262 l_array_source_37      t_array_source_37;
189263 l_array_source_38      t_array_source_38;
189264 l_array_source_39      t_array_source_39;
189265 l_array_source_40      t_array_source_40;
189266 l_array_source_41      t_array_source_41;
189267 
189268 --
189269 CURSOR header_cur
189270 IS
189271 SELECT /*+ leading(xet) cardinality(xet,1) */
189272 -- Event Type Code: CIP_REINSTATEMENTS
189273 -- Event Class Code: CIP_RETIREMENTS
189274     xet.entity_id
189275   , xet.legal_entity_id
189276   , xet.entity_code
189277   , xet.transaction_number
189278   , xet.event_id
189279   , xet.event_class_code
189283   , xet.transaction_date
189280   , xet.event_type_code
189281   , xet.event_number
189282   , xet.event_date
189284   , xet.reference_num_1
189285   , xet.reference_num_2
189286   , xet.reference_num_3
189287   , xet.reference_num_4
189288   , xet.reference_char_1
189289   , xet.reference_char_2
189290   , xet.reference_char_3
189291   , xet.reference_char_4
189292   , xet.reference_date_1
189293   , xet.reference_date_2
189294   , xet.reference_date_3
189295   , xet.reference_date_4
189296   , xet.event_created_by
189297   , xet.budgetary_control_flag 
189298   , h1.PERIOD_CLOSE_DATE    source_1
189299   , h1.COST_OF_REMOVAL_CLEARING_ACCT    source_12
189300   , h1.COST_OF_REMOVAL_GAIN_ACCT    source_13
189301   , h1.COST_OF_REMOVAL_LOSS_ACCT    source_14
189302   , h1.NBV_RETIRED_GAIN_ACCT    source_21
189303   , h1.NBV_RETIRED_LOSS_ACCT    source_22
189304   , h1.PROCEEDS_OF_SALE_CLEARING_ACCT    source_23
189305   , h1.PROCEEDS_OF_SALE_GAIN_ACCT    source_24
189306   , h1.PROCEEDS_OF_SALE_LOSS_ACCT    source_25
189307   , h1.REVAL_RSV_RETIRED_LOSS_ACCT    source_28
189308   , h1.DEFAULT_CCID    source_30
189309   , h1.ACCOUNTING_DATE    source_51
189310   , h1.TRANSFER_TO_GL_FLAG    source_52
189311   FROM xla_events_gt     xet 
189312   , FA_XLA_EXT_HEADERS_B_GT  h1
189313  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
189314    and xet.event_type_code = C_EVENT_TYPE_CODE
189315    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
189316 
189317  ORDER BY event_id
189318 ;
189319 
189320 
189321 --
189322 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
189323 IS
189324 SELECT /*+ leading(xet) cardinality(xet,1) */
189325 -- Event Type Code: CIP_REINSTATEMENTS
189326 -- Event Class Code: CIP_RETIREMENTS
189327     xet.entity_id
189328    ,xet.legal_entity_id
189329    ,xet.entity_code
189330    ,xet.transaction_number
189331    ,xet.event_id
189332    ,xet.event_class_code
189333    ,xet.event_type_code
189334    ,xet.event_number
189335    ,xet.event_date
189336    ,xet.transaction_date
189337    ,xet.reference_num_1
189338    ,xet.reference_num_2
189339    ,xet.reference_num_3
189340    ,xet.reference_num_4
189341    ,xet.reference_char_1
189342    ,xet.reference_char_2
189343    ,xet.reference_char_3
189344    ,xet.reference_char_4
189345    ,xet.reference_date_1
189346    ,xet.reference_date_2
189347    ,xet.reference_date_3
189348    ,xet.reference_date_4
189349    ,xet.event_created_by
189350    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
189351   , l2.GENERATED_CCID    source_3
189352   , l2.CIP_COST_ACCT    source_7
189353   , l2.REVAL_RESERVE_ACCT    source_11
189354   , l2.GENERATED_OFFSET_CCID    source_17
189355   , l2.EXPENSE_ACCOUNT_CCID    source_29
189356   , l2.ADJUSTMENT_TYPE    source_35
189357   , l2.TRANSACTION_HEADER_ID    source_36
189358   , l2.ADJUSTMENT_LINE_ID    source_37
189359   , l2.DISTRIBUTION_TYPE_CODE    source_38
189360   , l2.ENTERED_AMOUNT    source_39
189361   , l2.CURRENCY_CODE    source_40
189362   , l2.GAIN_LOSS_AMOUNT    source_41
189363   FROM xla_events_gt     xet 
189364   , FA_XLA_EXT_LINES_B_GT  l2
189365  WHERE xet.event_id between x_first_event_id and x_last_event_id
189366    and xet.event_date between p_pad_start_date and p_pad_end_date
189367    and xet.event_type_code = C_EVENT_TYPE_CODE
189368    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
189369   AND l2.ledger_id = p_sla_ledger_id
189370 ;
189371 
189372 --
189373 BEGIN
189374 IF g_log_enabled THEN
189375    l_log_module := C_DEFAULT_MODULE||'.EventType_414';
189376 END IF;
189377 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
189378    trace
189379       (p_msg      => 'BEGIN of EventType_414'
189380       ,p_level    => C_LEVEL_PROCEDURE
189381       ,p_module   => l_log_module);
189382 END IF;
189383 
189384 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
189385    trace
189386       (p_msg      => 'p_application_id = '||p_application_id||
189387                      ' - p_base_ledger_id = '||p_base_ledger_id||
189388                      ' - p_target_ledger_id  = '||p_target_ledger_id||
189389                      ' - p_language = '||p_language||
189390                      ' - p_currency_code = '||p_currency_code||
189391                      ' - p_sla_ledger_id = '||p_sla_ledger_id
189392       ,p_level    => C_LEVEL_STATEMENT
189393       ,p_module   => l_log_module);
189394 END IF;
189395 --
189396 -- initialze arrays
189397 --
189398 g_array_event.DELETE;
189399 l_rec_array_event := l_null_rec_array_event;
189400 --
189401 --------------------------------------
189402 -- 4262811 Initialze MPA Line Number
189403 --------------------------------------
189404 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
189405 
189406 --
189407 
189408 --
189409 OPEN header_cur;
189410 --
189411 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
189412    trace
189413    (p_msg      => 'SQL - FETCH header_cur'
189414    ,p_level    => C_LEVEL_STATEMENT
189415    ,p_module   => l_log_module);
189416 END IF;
189417 --
189418 LOOP
189419 FETCH header_cur BULK COLLECT INTO
189420         l_array_entity_id
189421       , l_array_legal_entity_id
189422       , l_array_entity_code
189423       , l_array_transaction_num
189424       , l_array_event_id
189425       , l_array_class_code
189426       , l_array_event_type
189427       , l_array_event_number
189428       , l_array_event_date
189429       , l_array_transaction_date
189430       , l_array_reference_num_1
189431       , l_array_reference_num_2
189432       , l_array_reference_num_3
189433       , l_array_reference_num_4
189434       , l_array_reference_char_1
189435       , l_array_reference_char_2
189436       , l_array_reference_char_3
189437       , l_array_reference_char_4
189438       , l_array_reference_date_1
189442       , l_array_event_created_by
189439       , l_array_reference_date_2
189440       , l_array_reference_date_3
189441       , l_array_reference_date_4
189443       , l_array_budgetary_control_flag 
189444       , l_array_source_1
189445       , l_array_source_12
189446       , l_array_source_13
189447       , l_array_source_14
189448       , l_array_source_21
189449       , l_array_source_22
189450       , l_array_source_23
189451       , l_array_source_24
189452       , l_array_source_25
189453       , l_array_source_28
189454       , l_array_source_30
189455       , l_array_source_51
189456       , l_array_source_52
189457       LIMIT l_rows;
189458 --
189459 IF (C_LEVEL_EVENT >= g_log_level) THEN
189460    trace
189461    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
189462    ,p_level    => C_LEVEL_EVENT
189463    ,p_module   => l_log_module);
189464 END IF;
189465 --
189466 EXIT WHEN l_array_entity_id.COUNT = 0;
189467 
189468 -- initialize arrays
189469 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
189470 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
189471 
189472 --
189473 -- Bug 4458708
189474 --
189475 XLA_AE_LINES_PKG.g_LineNumber := 0;
189476 
189477 
189478 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
189479 g_last_hdr_idx := l_array_event_id.LAST;
189480 --
189481 -- loop for the headers. Each iteration is for each header extract row
189482 -- fetched in header cursor
189483 --
189484 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
189485 
189486 --
189487 -- set event info as cache for other routines to refer event attributes
189488 --
189489 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
189490    (p_application_id           => p_application_id
189491    ,p_primary_ledger_id        => p_primary_ledger_id
189492    ,p_base_ledger_id           => p_base_ledger_id
189493    ,p_target_ledger_id         => p_target_ledger_id
189494    ,p_entity_id                => l_array_entity_id(hdr_idx)
189495    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
189496    ,p_entity_code              => l_array_entity_code(hdr_idx)
189497    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
189498    ,p_event_id                 => l_array_event_id(hdr_idx)
189499    ,p_event_class_code         => l_array_class_code(hdr_idx)
189500    ,p_event_type_code          => l_array_event_type(hdr_idx)
189501    ,p_event_number             => l_array_event_number(hdr_idx)
189502    ,p_event_date               => l_array_event_date(hdr_idx)
189503    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
189504    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
189505    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
189506    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
189507    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
189508    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
189509    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
189510    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
189511    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
189512    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
189513    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
189514    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
189515    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
189516    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
189517    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
189518 
189519 --
189520 -- set the status of entry to C_VALID (0)
189521 --
189522 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
189523 
189524 --
189525 -- initialize a row for ae header
189526 --
189527 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
189528 
189529 l_event_id := l_array_event_id(hdr_idx);
189530 
189531 --
189532 -- storing the hdr_idx for event. May be used by line cursor.
189533 --
189534 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
189535 
189536 --
189537 -- store sources from header extract. This can be improved to
189538 -- store only those sources from header extract that may be used in lines
189539 --
189540 
189541 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
189542 g_array_event(l_event_id).array_value_char('source_12') := l_array_source_12(hdr_idx);
189543 g_array_event(l_event_id).array_value_char('source_13') := l_array_source_13(hdr_idx);
189544 g_array_event(l_event_id).array_value_char('source_14') := l_array_source_14(hdr_idx);
189545 g_array_event(l_event_id).array_value_char('source_21') := l_array_source_21(hdr_idx);
189546 g_array_event(l_event_id).array_value_char('source_22') := l_array_source_22(hdr_idx);
189547 g_array_event(l_event_id).array_value_char('source_23') := l_array_source_23(hdr_idx);
189548 g_array_event(l_event_id).array_value_char('source_24') := l_array_source_24(hdr_idx);
189549 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
189550 g_array_event(l_event_id).array_value_char('source_28') := l_array_source_28(hdr_idx);
189551 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
189552 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
189553 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
189554 
189555 --
189556 -- initilaize the status of ae headers for diffrent balance types
189557 -- the status is initialised to C_NOT_CREATED (2)
189558 --
189559 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
189560 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
189564 -- call api to validate and store accounting attributes for header
189561 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
189562 
189563 --
189565 --
189566 
189567 ------------------------------------------------------------
189568 -- Accrual Reversal : to get date for Standard Source (NONE)
189569 ------------------------------------------------------------
189570 l_acc_rev_gl_date_source := NULL;
189571 
189572      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
189573       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
189574      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
189575       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
189576 
189577 
189578 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
189579 
189580 XLA_AE_HEADER_PKG.SetJeCategoryName;
189581 
189582 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
189583 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
189584 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
189585 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
189586 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
189587 
189588 
189589 --
189590 xla_ae_header_pkg.SetHdrDescription(
189591    p_description => Description_31 (
189592    p_application_id => p_application_id 
189593  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
189594    )
189595 );
189596 --
189597 
189598 -- No header level analytical criteria
189599 
189600 --
189601 --accounting attribute enhancement, bug 3612931
189602 --
189603 l_trx_reversal_source := SUBSTR(NULL, 1,30);
189604 
189605 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
189606    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
189607 
189608    xla_accounting_err_pkg.build_message
189609       (p_appli_s_name            => 'XLA'
189610       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
189611       ,p_token_1                 => 'ACCT_ATTR_NAME'
189612       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
189613       ,p_token_2                 => 'PRODUCT_NAME'
189614       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
189615       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
189616       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
189617       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
189618 
189619 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
189620    --
189621    -- following sets the accounting attributes needed to reverse
189622    -- accounting for a distributeion
189623    --
189624    xla_ae_lines_pkg.SetTrxReversalAttrs
189625       (p_event_id              => l_event_id
189626       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
189627       ,p_trx_reversal_source   => l_trx_reversal_source);
189628 
189629 END IF;
189630 
189631 
189632 ----------------------------------------------------------------
189633 -- 4262811 -  update the header statuses to invalid in need be
189634 ----------------------------------------------------------------
189635 --
189636 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
189637 
189638 
189639   -----------------------------------------------
189640   -- No accrual reversal for the event class/type
189641   -----------------------------------------------
189642 ----------------------------------------------------------------
189643 
189644 --
189645 -- this ends the header loop iteration for one bulk fetch
189646 --
189647 END LOOP;
189648 
189649 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
189650 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
189651 
189652 --
189653 -- insert dummy rows into lines gt table that were created due to
189654 -- transaction reversals
189655 --
189656 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
189657    l_result := XLA_AE_LINES_PKG.InsertLines;
189658 END IF;
189659 
189660 --
189661 -- reset the temp_line_num for each set of events fetched from header
189662 -- cursor rather than doing it for each new event in line cursor
189663 -- Bug 3939231
189664 --
189665 xla_ae_lines_pkg.g_temp_line_num := 0;
189666 
189667 
189668 
189669 --
189670 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
189671 --
189672 --
189673 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
189674 
189675       trace
189676          (p_msg      => 'SQL - FETCH line_cur'
189677          ,p_level    => C_LEVEL_STATEMENT
189678          ,p_module   => l_log_module);
189679 
189680 END IF;
189681 --
189682 --
189683 LOOP
189684   --
189685   FETCH line_cur BULK COLLECT INTO
189686         l_array_entity_id
189687       , l_array_legal_entity_id
189688       , l_array_entity_code
189689       , l_array_transaction_num
189690       , l_array_event_id
189691       , l_array_class_code
189692       , l_array_event_type
189693       , l_array_event_number
189694       , l_array_event_date
189695       , l_array_transaction_date
189696       , l_array_reference_num_1
189697       , l_array_reference_num_2
189698       , l_array_reference_num_3
189699       , l_array_reference_num_4
189700       , l_array_reference_char_1
189701       , l_array_reference_char_2
189702       , l_array_reference_char_3
189703       , l_array_reference_char_4
189704       , l_array_reference_date_1
189708       , l_array_event_created_by
189705       , l_array_reference_date_2
189706       , l_array_reference_date_3
189707       , l_array_reference_date_4
189709       , l_array_budgetary_control_flag
189710       , l_array_extract_line_num 
189711       , l_array_source_3
189712       , l_array_source_7
189713       , l_array_source_11
189714       , l_array_source_17
189715       , l_array_source_29
189716       , l_array_source_35
189717       , l_array_source_36
189718       , l_array_source_37
189719       , l_array_source_38
189720       , l_array_source_39
189721       , l_array_source_40
189722       , l_array_source_41
189723       LIMIT l_rows;
189724 
189725   --
189726   IF (C_LEVEL_EVENT >= g_log_level) THEN
189727             trace
189728                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
189729                ,p_level    => C_LEVEL_EVENT
189730                ,p_module   => l_log_module);
189731   END IF;
189732   --
189733   EXIT WHEN l_array_entity_id.count = 0;
189734 
189735   XLA_AE_LINES_PKG.g_rec_lines := null;
189736 
189737 --
189738 -- Bug 4458708
189739 --
189740 XLA_AE_LINES_PKG.g_LineNumber := 0;
189741 --
189742 --
189743 
189744 FOR Idx IN 1..l_array_event_id.count LOOP
189745    --
189746    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
189747    --
189748    l_event_id := l_array_event_id(idx);  -- 5648433
189749 
189750    --
189751    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
189752    --
189753 
189754    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
189755              (g_array_event(l_event_id).array_value_num('header_index'))
189756          ,'N'
189757          ) <> 'Y'
189758    THEN
189759       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
189760          trace
189761             (p_msg      => 'Trancaction revesal option is not Y '
189762             ,p_level    => C_LEVEL_STATEMENT
189763             ,p_module   => l_log_module);
189764       END IF;
189765 
189766 --
189767 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
189768 --
189769 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
189770 --
189771 -- set event info as cache for other routines to refer event attributes
189772 --
189773 
189774 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
189775    l_previous_event_id := l_event_id;
189776 
189777    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
189778       (p_application_id           => p_application_id
189779       ,p_primary_ledger_id        => p_primary_ledger_id
189780       ,p_base_ledger_id           => p_base_ledger_id
189781       ,p_target_ledger_id         => p_target_ledger_id
189782       ,p_entity_id                => l_array_entity_id(Idx)
189783       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
189784       ,p_entity_code              => l_array_entity_code(Idx)
189785       ,p_transaction_num          => l_array_transaction_num(Idx)
189786       ,p_event_id                 => l_array_event_id(Idx)
189787       ,p_event_class_code         => l_array_class_code(Idx)
189788       ,p_event_type_code          => l_array_event_type(Idx)
189789       ,p_event_number             => l_array_event_number(Idx)
189790       ,p_event_date               => l_array_event_date(Idx)
189791       ,p_transaction_date         => l_array_transaction_date(Idx)
189792       ,p_reference_num_1          => l_array_reference_num_1(Idx)
189793       ,p_reference_num_2          => l_array_reference_num_2(Idx)
189794       ,p_reference_num_3          => l_array_reference_num_3(Idx)
189795       ,p_reference_num_4          => l_array_reference_num_4(Idx)
189796       ,p_reference_char_1         => l_array_reference_char_1(Idx)
189797       ,p_reference_char_2         => l_array_reference_char_2(Idx)
189798       ,p_reference_char_3         => l_array_reference_char_3(Idx)
189799       ,p_reference_char_4         => l_array_reference_char_4(Idx)
189800       ,p_reference_date_1         => l_array_reference_date_1(Idx)
189801       ,p_reference_date_2         => l_array_reference_date_2(Idx)
189802       ,p_reference_date_3         => l_array_reference_date_3(Idx)
189803       ,p_reference_date_4         => l_array_reference_date_4(Idx)
189804       ,p_event_created_by         => l_array_event_created_by(Idx)
189805       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
189806        --
189807 END IF;
189808 
189809 
189810 
189811 --
189812 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
189813 
189814 l_acct_reversal_source := SUBSTR(NULL, 1,30);
189815 
189816 IF l_continue_with_lines THEN
189817    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
189818       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
189819 
189820       xla_accounting_err_pkg.build_message
189821          (p_appli_s_name            => 'XLA'
189822          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
189823          ,p_token_1                 => 'LINE_NUMBER'
189824          ,p_value_1                 => l_array_extract_line_num(Idx)
189825          ,p_token_2                 => 'PRODUCT_NAME'
189826          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
189827          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
189828          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
189829          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
189830 
189831    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
189832       --
189833       -- following sets the accounting attributes needed to reverse
189834       -- accounting for a distributeion
189835       --
189836 
189837       --
189838       -- 5217187
189839       --
189843       --
189840       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
189841       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
189842                                        g_array_event(l_event_id).array_value_num('header_index'));
189844       --
189845 
189846       -- No reversal code generated
189847 
189848       xla_ae_lines_pkg.SetAcctReversalAttrs
189849          (p_event_id             => l_event_id
189850          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
189851          ,p_calculate_acctd_flag => l_calculate_acctd_flag
189852          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
189853    END IF;
189854 
189855    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
189856        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
189857 
189858 --
189859 AcctLineType_211 (
189860  p_application_id  => p_application_id
189861  ,p_event_id     => l_event_id
189862  ,p_calculate_acctd_flag => l_calculate_acctd_flag
189863  ,p_calculate_g_l_flag => l_calculate_g_l_flag
189864  ,p_actual_flag => l_actual_flag
189865  ,p_balance_type_code => l_balance_type_code
189866  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
189867  
189868  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
189869  , p_source_3 => l_array_source_3(Idx)
189870  , p_source_12 => g_array_event(l_event_id).array_value_char('source_12')
189871  , p_source_29 => l_array_source_29(Idx)
189872  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
189873  , p_source_35 => l_array_source_35(Idx)
189874  , p_source_36 => l_array_source_36(Idx)
189875  , p_source_37 => l_array_source_37(Idx)
189876  , p_source_38 => l_array_source_38(Idx)
189877  , p_source_39 => l_array_source_39(Idx)
189878  , p_source_40 => l_array_source_40(Idx)
189879  );
189880 If(l_balance_type_code = 'A') THEN
189881   l_actual_gain_loss_ref := l_gain_or_loss_ref;
189882 END IF;
189883 
189884 --
189885 
189886 
189887 --
189888 AcctLineType_214 (
189889  p_application_id  => p_application_id
189890  ,p_event_id     => l_event_id
189891  ,p_calculate_acctd_flag => l_calculate_acctd_flag
189892  ,p_calculate_g_l_flag => l_calculate_g_l_flag
189893  ,p_actual_flag => l_actual_flag
189894  ,p_balance_type_code => l_balance_type_code
189895  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
189896  
189897  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
189898  , p_source_3 => l_array_source_3(Idx)
189899  , p_source_13 => g_array_event(l_event_id).array_value_char('source_13')
189900  , p_source_29 => l_array_source_29(Idx)
189901  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
189902  , p_source_35 => l_array_source_35(Idx)
189903  , p_source_36 => l_array_source_36(Idx)
189904  , p_source_37 => l_array_source_37(Idx)
189905  , p_source_38 => l_array_source_38(Idx)
189906  , p_source_39 => l_array_source_39(Idx)
189907  , p_source_40 => l_array_source_40(Idx)
189908  , p_source_41 => l_array_source_41(Idx)
189909  );
189910 If(l_balance_type_code = 'A') THEN
189911   l_actual_gain_loss_ref := l_gain_or_loss_ref;
189912 END IF;
189913 
189914 --
189915 
189916 
189917 --
189918 AcctLineType_216 (
189919  p_application_id  => p_application_id
189920  ,p_event_id     => l_event_id
189921  ,p_calculate_acctd_flag => l_calculate_acctd_flag
189922  ,p_calculate_g_l_flag => l_calculate_g_l_flag
189923  ,p_actual_flag => l_actual_flag
189924  ,p_balance_type_code => l_balance_type_code
189925  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
189926  
189927  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
189928  , p_source_3 => l_array_source_3(Idx)
189929  , p_source_14 => g_array_event(l_event_id).array_value_char('source_14')
189930  , p_source_29 => l_array_source_29(Idx)
189931  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
189932  , p_source_35 => l_array_source_35(Idx)
189933  , p_source_36 => l_array_source_36(Idx)
189934  , p_source_37 => l_array_source_37(Idx)
189935  , p_source_38 => l_array_source_38(Idx)
189936  , p_source_39 => l_array_source_39(Idx)
189937  , p_source_40 => l_array_source_40(Idx)
189938  , p_source_41 => l_array_source_41(Idx)
189939  );
189940 If(l_balance_type_code = 'A') THEN
189941   l_actual_gain_loss_ref := l_gain_or_loss_ref;
189942 END IF;
189943 
189944 --
189945 
189946 
189947 --
189948 AcctLineType_218 (
189949  p_application_id  => p_application_id
189950  ,p_event_id     => l_event_id
189951  ,p_calculate_acctd_flag => l_calculate_acctd_flag
189952  ,p_calculate_g_l_flag => l_calculate_g_l_flag
189953  ,p_actual_flag => l_actual_flag
189954  ,p_balance_type_code => l_balance_type_code
189955  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
189956  
189957  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
189958  , p_source_3 => l_array_source_3(Idx)
189959  , p_source_21 => g_array_event(l_event_id).array_value_char('source_21')
189960  , p_source_29 => l_array_source_29(Idx)
189961  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
189962  , p_source_35 => l_array_source_35(Idx)
189963  , p_source_36 => l_array_source_36(Idx)
189964  , p_source_37 => l_array_source_37(Idx)
189965  , p_source_38 => l_array_source_38(Idx)
189966  , p_source_39 => l_array_source_39(Idx)
189967  , p_source_40 => l_array_source_40(Idx)
189968  , p_source_41 => l_array_source_41(Idx)
189969  );
189970 If(l_balance_type_code = 'A') THEN
189971   l_actual_gain_loss_ref := l_gain_or_loss_ref;
189972 END IF;
189973 
189974 --
189975 
189976 
189977 --
189978 AcctLineType_219 (
189979  p_application_id  => p_application_id
189980  ,p_event_id     => l_event_id
189981  ,p_calculate_acctd_flag => l_calculate_acctd_flag
189982  ,p_calculate_g_l_flag => l_calculate_g_l_flag
189983  ,p_actual_flag => l_actual_flag
189984  ,p_balance_type_code => l_balance_type_code
189988  , p_source_3 => l_array_source_3(Idx)
189985  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
189986  
189987  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
189989  , p_source_22 => g_array_event(l_event_id).array_value_char('source_22')
189990  , p_source_29 => l_array_source_29(Idx)
189991  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
189992  , p_source_35 => l_array_source_35(Idx)
189993  , p_source_36 => l_array_source_36(Idx)
189994  , p_source_37 => l_array_source_37(Idx)
189995  , p_source_38 => l_array_source_38(Idx)
189996  , p_source_39 => l_array_source_39(Idx)
189997  , p_source_40 => l_array_source_40(Idx)
189998  , p_source_41 => l_array_source_41(Idx)
189999  );
190000 If(l_balance_type_code = 'A') THEN
190001   l_actual_gain_loss_ref := l_gain_or_loss_ref;
190002 END IF;
190003 
190004 --
190005 
190006 
190007 --
190008 AcctLineType_221 (
190009  p_application_id  => p_application_id
190010  ,p_event_id     => l_event_id
190011  ,p_calculate_acctd_flag => l_calculate_acctd_flag
190012  ,p_calculate_g_l_flag => l_calculate_g_l_flag
190013  ,p_actual_flag => l_actual_flag
190014  ,p_balance_type_code => l_balance_type_code
190015  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
190016  
190017  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
190018  , p_source_3 => l_array_source_3(Idx)
190019  , p_source_23 => g_array_event(l_event_id).array_value_char('source_23')
190020  , p_source_29 => l_array_source_29(Idx)
190021  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
190022  , p_source_35 => l_array_source_35(Idx)
190023  , p_source_36 => l_array_source_36(Idx)
190024  , p_source_37 => l_array_source_37(Idx)
190025  , p_source_38 => l_array_source_38(Idx)
190026  , p_source_39 => l_array_source_39(Idx)
190027  , p_source_40 => l_array_source_40(Idx)
190028  );
190029 If(l_balance_type_code = 'A') THEN
190030   l_actual_gain_loss_ref := l_gain_or_loss_ref;
190031 END IF;
190032 
190033 --
190034 
190035 
190036 --
190037 AcctLineType_224 (
190038  p_application_id  => p_application_id
190039  ,p_event_id     => l_event_id
190040  ,p_calculate_acctd_flag => l_calculate_acctd_flag
190041  ,p_calculate_g_l_flag => l_calculate_g_l_flag
190042  ,p_actual_flag => l_actual_flag
190043  ,p_balance_type_code => l_balance_type_code
190044  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
190045  
190046  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
190047  , p_source_3 => l_array_source_3(Idx)
190048  , p_source_24 => g_array_event(l_event_id).array_value_char('source_24')
190049  , p_source_29 => l_array_source_29(Idx)
190050  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
190051  , p_source_35 => l_array_source_35(Idx)
190052  , p_source_36 => l_array_source_36(Idx)
190053  , p_source_37 => l_array_source_37(Idx)
190054  , p_source_38 => l_array_source_38(Idx)
190055  , p_source_39 => l_array_source_39(Idx)
190056  , p_source_40 => l_array_source_40(Idx)
190057  , p_source_41 => l_array_source_41(Idx)
190058  );
190059 If(l_balance_type_code = 'A') THEN
190060   l_actual_gain_loss_ref := l_gain_or_loss_ref;
190061 END IF;
190062 
190063 --
190064 
190065 
190066 --
190067 AcctLineType_226 (
190068  p_application_id  => p_application_id
190069  ,p_event_id     => l_event_id
190070  ,p_calculate_acctd_flag => l_calculate_acctd_flag
190071  ,p_calculate_g_l_flag => l_calculate_g_l_flag
190072  ,p_actual_flag => l_actual_flag
190073  ,p_balance_type_code => l_balance_type_code
190074  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
190075  
190076  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
190077  , p_source_3 => l_array_source_3(Idx)
190078  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
190079  , p_source_29 => l_array_source_29(Idx)
190080  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
190081  , p_source_35 => l_array_source_35(Idx)
190082  , p_source_36 => l_array_source_36(Idx)
190083  , p_source_37 => l_array_source_37(Idx)
190084  , p_source_38 => l_array_source_38(Idx)
190085  , p_source_39 => l_array_source_39(Idx)
190086  , p_source_40 => l_array_source_40(Idx)
190087  , p_source_41 => l_array_source_41(Idx)
190088  );
190089 If(l_balance_type_code = 'A') THEN
190090   l_actual_gain_loss_ref := l_gain_or_loss_ref;
190091 END IF;
190092 
190093 --
190094 
190095 
190096 --
190097 AcctLineType_231 (
190098  p_application_id  => p_application_id
190099  ,p_event_id     => l_event_id
190100  ,p_calculate_acctd_flag => l_calculate_acctd_flag
190101  ,p_calculate_g_l_flag => l_calculate_g_l_flag
190102  ,p_actual_flag => l_actual_flag
190103  ,p_balance_type_code => l_balance_type_code
190104  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
190105  
190106  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
190107  , p_source_3 => l_array_source_3(Idx)
190108  , p_source_7 => l_array_source_7(Idx)
190109  , p_source_29 => l_array_source_29(Idx)
190110  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
190111  , p_source_35 => l_array_source_35(Idx)
190112  , p_source_36 => l_array_source_36(Idx)
190113  , p_source_37 => l_array_source_37(Idx)
190114  , p_source_38 => l_array_source_38(Idx)
190115  , p_source_39 => l_array_source_39(Idx)
190116  , p_source_40 => l_array_source_40(Idx)
190117  );
190118 If(l_balance_type_code = 'A') THEN
190119   l_actual_gain_loss_ref := l_gain_or_loss_ref;
190120 END IF;
190121 
190122 --
190123 
190124 
190125 --
190126 AcctLineType_234 (
190127  p_application_id  => p_application_id
190128  ,p_event_id     => l_event_id
190129  ,p_calculate_acctd_flag => l_calculate_acctd_flag
190130  ,p_calculate_g_l_flag => l_calculate_g_l_flag
190131  ,p_actual_flag => l_actual_flag
190132  ,p_balance_type_code => l_balance_type_code
190136  , p_source_3 => l_array_source_3(Idx)
190133  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
190134  
190135  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
190137  , p_source_11 => l_array_source_11(Idx)
190138  , p_source_17 => l_array_source_17(Idx)
190139  , p_source_29 => l_array_source_29(Idx)
190140  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
190141  , p_source_35 => l_array_source_35(Idx)
190142  , p_source_36 => l_array_source_36(Idx)
190143  , p_source_37 => l_array_source_37(Idx)
190144  , p_source_38 => l_array_source_38(Idx)
190145  , p_source_39 => l_array_source_39(Idx)
190146  , p_source_40 => l_array_source_40(Idx)
190147  );
190148 If(l_balance_type_code = 'A') THEN
190149   l_actual_gain_loss_ref := l_gain_or_loss_ref;
190150 END IF;
190151 
190152 --
190153 
190154 
190155 --
190156 AcctLineType_236 (
190157  p_application_id  => p_application_id
190158  ,p_event_id     => l_event_id
190159  ,p_calculate_acctd_flag => l_calculate_acctd_flag
190160  ,p_calculate_g_l_flag => l_calculate_g_l_flag
190161  ,p_actual_flag => l_actual_flag
190162  ,p_balance_type_code => l_balance_type_code
190163  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
190164  
190165  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
190166  , p_source_3 => l_array_source_3(Idx)
190167  , p_source_28 => g_array_event(l_event_id).array_value_char('source_28')
190168  , p_source_29 => l_array_source_29(Idx)
190169  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
190170  , p_source_35 => l_array_source_35(Idx)
190171  , p_source_36 => l_array_source_36(Idx)
190172  , p_source_37 => l_array_source_37(Idx)
190173  , p_source_38 => l_array_source_38(Idx)
190174  , p_source_39 => l_array_source_39(Idx)
190175  , p_source_40 => l_array_source_40(Idx)
190176  , p_source_41 => l_array_source_41(Idx)
190177  );
190178 If(l_balance_type_code = 'A') THEN
190179   l_actual_gain_loss_ref := l_gain_or_loss_ref;
190180 END IF;
190181 
190182 --
190183 
190184 
190185 --
190186 AcctLineType_237 (
190187  p_application_id  => p_application_id
190188  ,p_event_id     => l_event_id
190189  ,p_calculate_acctd_flag => l_calculate_acctd_flag
190190  ,p_calculate_g_l_flag => l_calculate_g_l_flag
190191  ,p_actual_flag => l_actual_flag
190192  ,p_balance_type_code => l_balance_type_code
190193  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
190194  
190195  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
190196  , p_source_3 => l_array_source_3(Idx)
190197  , p_source_28 => g_array_event(l_event_id).array_value_char('source_28')
190198  , p_source_29 => l_array_source_29(Idx)
190199  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
190200  , p_source_35 => l_array_source_35(Idx)
190201  , p_source_36 => l_array_source_36(Idx)
190202  , p_source_37 => l_array_source_37(Idx)
190203  , p_source_38 => l_array_source_38(Idx)
190204  , p_source_39 => l_array_source_39(Idx)
190205  , p_source_40 => l_array_source_40(Idx)
190206  , p_source_41 => l_array_source_41(Idx)
190207  );
190208 If(l_balance_type_code = 'A') THEN
190209   l_actual_gain_loss_ref := l_gain_or_loss_ref;
190210 END IF;
190211 
190212 --
190213 
190214       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
190215       -- or secondary ledger that has different currency with primary
190216       -- or alc that is calculated by sla
190217       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
190218             (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'))
190219 
190220 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
190221 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
190222           AND (l_actual_flag = 'A')) THEN
190223         XLA_AE_LINES_PKG.CreateGainOrLossLines(
190224           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
190225          ,p_application_id   => p_application_id
190226          ,p_amb_context_code => 'DEFAULT'
190227          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
190228          ,p_event_class_code => C_EVENT_CLASS_CODE
190229          ,p_event_type_code  => C_EVENT_TYPE_CODE
190230          
190231          ,p_gain_ccid        => -1
190232          ,p_loss_ccid        => -1
190233 
190234          ,p_actual_flag      => l_actual_flag
190235          ,p_enc_flag         => null
190236          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
190237          ,p_enc_g_l_ref      => null
190238          );
190239       END IF;
190240    END IF;
190241 END IF;
190242 
190243    ELSE
190244       --
190245       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
190246       --
190247       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
190248          trace
190249             (p_msg      => 'Trancaction revesal option is Y'
190250             ,p_level    => C_LEVEL_STATEMENT
190251             ,p_module   => l_log_module);
190252       END IF;
190253    END IF;
190254 
190255 END LOOP;
190256 l_result := XLA_AE_LINES_PKG.InsertLines ;
190257 end loop;
190258 close line_cur;
190259 
190260 
190261 --
190262 -- insert headers into xla_ae_headers_gt table
190263 --
190264 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
190265 
190266 -- insert into errors table here.
190267 
190268 END LOOP;
190269 
190270 --
190271 -- 4865292
190272 --
190273 -- Compare g_hdr_extract_count with event count in
190274 -- CreateHeadersAndLines.
190275 --
190276 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
190277 
190278 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
190282          ,p_level   => C_LEVEL_STATEMENT
190279    trace (p_msg     => '# rows extracted from header extract objects '
190280                     || ' (running total): '
190281                     || g_hdr_extract_count
190283          ,p_module  => l_log_module);
190284 END IF;
190285 
190286 CLOSE header_cur;
190287 --
190288 
190289 --
190290 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
190291    trace
190292       (p_msg      => 'END of EventType_414'
190293       ,p_level    => C_LEVEL_PROCEDURE
190294       ,p_module   => l_log_module);
190295 END IF;
190296 --
190297 RETURN l_result;
190298 EXCEPTION
190299 WHEN xla_exceptions_pkg.application_exception THEN
190300    
190301 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
190302 
190303    
190304 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
190305 
190306    RAISE;
190307 
190308 WHEN NO_DATA_FOUND THEN
190309 
190310 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
190311 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
190312 
190313 FOR header_record IN header_cur
190314 LOOP
190315     l_array_header_events(header_record.event_id) := header_record.event_id;
190316 END LOOP;
190317 
190318 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
190319 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
190320 
190321 fnd_file.put_line(fnd_file.LOG, '                    ');
190322 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
190323 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
190324 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
190325 
190326 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
190327 LOOP
190328 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
190329 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
190330         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
190331 	END IF;
190332 END LOOP;
190333 
190334 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
190335 fnd_file.put_line(fnd_file.LOG, '                    ');
190336 
190337 
190338 xla_exceptions_pkg.raise_message
190339       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_414');
190340 
190341 
190342 WHEN OTHERS THEN
190343    xla_exceptions_pkg.raise_message
190344       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_414');
190345 END EventType_414;
190346 --
190347 
190348 ---------------------------------------
190349 --
190350 -- PRIVATE PROCEDURE
190351 --         insert_sources_415
190352 --
190353 ----------------------------------------
190354 --
190355 PROCEDURE insert_sources_415(
190356                                 p_target_ledger_id       IN NUMBER
190357                               , p_language               IN VARCHAR2
190358                               , p_sla_ledger_id          IN NUMBER
190359                               , p_pad_start_date         IN DATE
190360                               , p_pad_end_date           IN DATE
190361                          )
190362 IS
190363 
190364 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_RETIREMENTS';
190365 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CIP_RETIREMENTS';
190366 p_apps_owner                   VARCHAR2(30);
190367 l_log_module                   VARCHAR2(240);
190368 BEGIN
190369 IF g_log_enabled THEN
190370       l_log_module := C_DEFAULT_MODULE||'.insert_sources_415';
190371 END IF;
190372 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
190373 
190374       trace
190375          (p_msg      => 'BEGIN of insert_sources_415'
190376          ,p_level    => C_LEVEL_PROCEDURE
190377          ,p_module   => l_log_module);
190378 
190379 END IF;
190380 
190381 -- select APPS owner
190382 SELECT oracle_username
190383   INTO p_apps_owner
190384   FROM fnd_oracle_userid
190385  WHERE read_only_flag = 'U'
190386 ;
190387 
190388 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
190389       trace
190390          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
190391                         ' - p_language = '||p_language||
190392                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
190393                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
190394                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
190395                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
190396          ,p_level    => C_LEVEL_STATEMENT
190397          ,p_module   => l_log_module);
190398 END IF;
190399 
190400 
190401 --
190402 INSERT INTO xla_diag_sources --hdr1
190403 (
190404         event_id
190405       , ledger_id
190406       , sla_ledger_id
190407       , description_language
190408       , object_name
190409       , object_type_code
190410       , line_number
190411       , source_application_id
190412       , source_type_code
190413       , source_code
190414       , source_value
190415       , source_meaning
190416       , created_by
190417       , creation_date
190418       , last_update_date
190419       , last_updated_by
190420       , last_update_login
190421       , program_update_date
190422       , program_application_id
190423       , program_id
190424       , request_id
190425 )
190426 SELECT
190427         event_id
190428       , p_target_ledger_id
190429       , p_sla_ledger_id
190430       , p_language
190431       , object_name
190432       , object_type_code
190433       , line_number
190434       , source_application_id
190435       , source_type_code
190436       , source_code
190440       , TRUNC(SYSDATE)
190437       , SUBSTR(source_value ,1,1996)
190438       , SUBSTR(source_meaning,1,200)
190439       , xla_environment_pkg.g_Usr_Id
190441       , TRUNC(SYSDATE)
190442       , xla_environment_pkg.g_Usr_Id
190443       , xla_environment_pkg.g_Login_Id
190444       , TRUNC(SYSDATE)
190445       , xla_environment_pkg.g_Prog_Appl_Id
190446       , xla_environment_pkg.g_Prog_Id
190447       , xla_environment_pkg.g_Req_Id
190448   FROM (
190449        SELECT xet.event_id                  event_id
190450             , 0                             line_number
190451             , CASE r
190452                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190453                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190454                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190455                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190456                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190457                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190458                 WHEN 7 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190459                 WHEN 8 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190460                 WHEN 9 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190461                 WHEN 10 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190462                 WHEN 11 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190463                 WHEN 12 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190464                 WHEN 13 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190465                 WHEN 14 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
190466                 
190467                ELSE null
190468               END                           object_name
190469             , CASE r
190470                 WHEN 1 THEN 'HEADER' 
190471                 WHEN 2 THEN 'HEADER' 
190472                 WHEN 3 THEN 'HEADER' 
190473                 WHEN 4 THEN 'HEADER' 
190474                 WHEN 5 THEN 'HEADER' 
190475                 WHEN 6 THEN 'HEADER' 
190476                 WHEN 7 THEN 'HEADER' 
190477                 WHEN 8 THEN 'HEADER' 
190478                 WHEN 9 THEN 'HEADER' 
190479                 WHEN 10 THEN 'HEADER' 
190480                 WHEN 11 THEN 'HEADER' 
190481                 WHEN 12 THEN 'HEADER' 
190482                 WHEN 13 THEN 'HEADER' 
190483                 WHEN 14 THEN 'HEADER' 
190484                 
190485                 ELSE null
190486               END                           object_type_code
190487             , CASE r
190488                 WHEN 1 THEN '140' 
190489                 WHEN 2 THEN '140' 
190490                 WHEN 3 THEN '140' 
190491                 WHEN 4 THEN '140' 
190492                 WHEN 5 THEN '140' 
190493                 WHEN 6 THEN '140' 
190494                 WHEN 7 THEN '140' 
190495                 WHEN 8 THEN '140' 
190496                 WHEN 9 THEN '140' 
190497                 WHEN 10 THEN '140' 
190498                 WHEN 11 THEN '140' 
190499                 WHEN 12 THEN '140' 
190500                 WHEN 13 THEN '140' 
190501                 WHEN 14 THEN '140' 
190502                 
190503                 ELSE null
190504               END                           source_application_id
190505             , 'S'             source_type_code
190506             , CASE r
190507                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
190508                 WHEN 2 THEN 'COST_OF_REMOVAL_CLEARING_ACCT' 
190509                 WHEN 3 THEN 'COST_OF_REMOVAL_GAIN_ACCT' 
190510                 WHEN 4 THEN 'COST_OF_REMOVAL_LOSS_ACCT' 
190511                 WHEN 5 THEN 'NBV_RETIRED_GAIN_ACCT' 
190512                 WHEN 6 THEN 'NBV_RETIRED_LOSS_ACCT' 
190513                 WHEN 7 THEN 'PROCEEDS_OF_SALE_CLEARING_ACCT' 
190514                 WHEN 8 THEN 'PROCEEDS_OF_SALE_GAIN_ACCT' 
190515                 WHEN 9 THEN 'PROCEEDS_OF_SALE_LOSS_ACCT' 
190516                 WHEN 10 THEN 'REVAL_RSV_RETIRED_GAIN_ACCT' 
190517                 WHEN 11 THEN 'REVAL_RSV_RETIRED_LOSS_ACCT' 
190518                 WHEN 12 THEN 'DEFAULT_CCID' 
190519                 WHEN 13 THEN 'ACCOUNTING_DATE' 
190520                 WHEN 14 THEN 'TRANSFER_TO_GL_FLAG' 
190521                 
190522                 ELSE null
190523               END                           source_code
190524             , CASE r
190525                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
190526                 WHEN 2 THEN TO_CHAR(h1.COST_OF_REMOVAL_CLEARING_ACCT)
190527                 WHEN 3 THEN TO_CHAR(h1.COST_OF_REMOVAL_GAIN_ACCT)
190528                 WHEN 4 THEN TO_CHAR(h1.COST_OF_REMOVAL_LOSS_ACCT)
190529                 WHEN 5 THEN TO_CHAR(h1.NBV_RETIRED_GAIN_ACCT)
190530                 WHEN 6 THEN TO_CHAR(h1.NBV_RETIRED_LOSS_ACCT)
190531                 WHEN 7 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_CLEARING_ACCT)
190532                 WHEN 8 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_GAIN_ACCT)
190533                 WHEN 9 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_LOSS_ACCT)
190534                 WHEN 10 THEN TO_CHAR(h1.REVAL_RSV_RETIRED_GAIN_ACCT)
190535                 WHEN 11 THEN TO_CHAR(h1.REVAL_RSV_RETIRED_LOSS_ACCT)
190536                 WHEN 12 THEN TO_CHAR(h1.DEFAULT_CCID)
190537                 WHEN 13 THEN TO_CHAR(h1.ACCOUNTING_DATE)
190538                 WHEN 14 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
190539                 
190540                 ELSE null
190541               END                           source_value
190542             , null              source_meaning
190543         FROM xla_events_gt     xet  
190544       , FA_XLA_EXT_HEADERS_B_GT  h1
190545             ,(select rownum r from all_objects where rownum <= 14 and owner = p_apps_owner)
190546        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
190547          AND xet.event_type_code = C_EVENT_TYPE_CODE
190548             AND h1.event_id = xet.event_id
190549 
190550 )
190551 ;
190552 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
190553 
190554       trace
190555          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
190556          ,p_level    => C_LEVEL_STATEMENT
190557          ,p_module   => l_log_module);
190558 
190559 END IF;
190560 --
190561 
190562 
190563 
190567         event_id
190564 --
190565 INSERT INTO xla_diag_sources --line1
190566 (
190568       , ledger_id
190569       , sla_ledger_id
190570       , description_language
190571       , object_name
190572       , object_type_code
190573       , line_number
190574       , source_application_id
190575       , source_type_code
190576       , source_code
190577       , source_value
190578       , source_meaning
190579       , created_by
190580       , creation_date
190581       , last_update_date
190582       , last_updated_by
190583       , last_update_login
190584       , program_update_date
190585       , program_application_id
190586       , program_id
190587       , request_id
190588 )
190589 SELECT  event_id
190590       , p_target_ledger_id
190591       , p_sla_ledger_id
190592       , p_language
190593       , object_name
190594       , object_type_code
190595       , line_number
190596       , source_application_id
190597       , source_type_code
190598       , source_code
190599       , SUBSTR(source_value,1,1996)
190600       , SUBSTR(source_meaning,1,200)
190601       , xla_environment_pkg.g_Usr_Id
190602       , TRUNC(SYSDATE)
190603       , TRUNC(SYSDATE)
190604       , xla_environment_pkg.g_Usr_Id
190605       , xla_environment_pkg.g_Login_Id
190606       , TRUNC(SYSDATE)
190607       , xla_environment_pkg.g_Prog_Appl_Id
190608       , xla_environment_pkg.g_Prog_Id
190609       , xla_environment_pkg.g_Req_Id
190610   FROM (
190611        SELECT xet.event_id                  event_id
190612             , l2.line_number                 line_number
190613             , CASE r
190614                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
190615                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
190616                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
190617                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
190618                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
190619                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
190620                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
190621                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
190622                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
190623                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
190624                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
190625                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
190626                 
190627                ELSE null
190628               END                           object_name
190629             , CASE r
190630                 WHEN 1 THEN 'LINE' 
190631                 WHEN 2 THEN 'LINE' 
190632                 WHEN 3 THEN 'LINE' 
190633                 WHEN 4 THEN 'LINE' 
190634                 WHEN 5 THEN 'LINE' 
190635                 WHEN 6 THEN 'LINE' 
190636                 WHEN 7 THEN 'LINE' 
190637                 WHEN 8 THEN 'LINE' 
190638                 WHEN 9 THEN 'LINE' 
190639                 WHEN 10 THEN 'LINE' 
190640                 WHEN 11 THEN 'LINE' 
190641                 WHEN 12 THEN 'LINE' 
190642                 
190643                 ELSE null
190644               END                           object_type_code
190645             , CASE r
190646                 WHEN 1 THEN '140' 
190647                 WHEN 2 THEN '140' 
190648                 WHEN 3 THEN '140' 
190649                 WHEN 4 THEN '140' 
190650                 WHEN 5 THEN '140' 
190651                 WHEN 6 THEN '140' 
190652                 WHEN 7 THEN '140' 
190653                 WHEN 8 THEN '140' 
190654                 WHEN 9 THEN '140' 
190655                 WHEN 10 THEN '140' 
190656                 WHEN 11 THEN '140' 
190657                 WHEN 12 THEN '140' 
190658                 
190659                 ELSE null
190660               END                           source_application_id
190661             , 'S'             source_type_code
190662             , CASE r
190663                 WHEN 1 THEN 'GENERATED_CCID' 
190664                 WHEN 2 THEN 'CIP_COST_ACCT' 
190665                 WHEN 3 THEN 'REVAL_RESERVE_ACCT' 
190666                 WHEN 4 THEN 'GENERATED_OFFSET_CCID' 
190667                 WHEN 5 THEN 'EXPENSE_ACCOUNT_CCID' 
190668                 WHEN 6 THEN 'ADJUSTMENT_TYPE' 
190669                 WHEN 7 THEN 'TRANSACTION_HEADER_ID' 
190670                 WHEN 8 THEN 'ADJUSTMENT_LINE_ID' 
190671                 WHEN 9 THEN 'DISTRIBUTION_TYPE_CODE' 
190672                 WHEN 10 THEN 'ENTERED_AMOUNT' 
190673                 WHEN 11 THEN 'CURRENCY_CODE' 
190674                 WHEN 12 THEN 'GAIN_LOSS_AMOUNT' 
190675                 
190676                 ELSE null
190677               END                           source_code
190678             , CASE r
190679                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
190680                 WHEN 2 THEN TO_CHAR(l2.CIP_COST_ACCT)
190681                 WHEN 3 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
190682                 WHEN 4 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
190683                 WHEN 5 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
190684                 WHEN 6 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
190685                 WHEN 7 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
190686                 WHEN 8 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
190687                 WHEN 9 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
190688                 WHEN 10 THEN TO_CHAR(l2.ENTERED_AMOUNT)
190689                 WHEN 11 THEN TO_CHAR(l2.CURRENCY_CODE)
190690                 WHEN 12 THEN TO_CHAR(l2.GAIN_LOSS_AMOUNT)
190691                 
190692                 ELSE null
190693               END                           source_value
190694             , null              source_meaning
190695          FROM  xla_events_gt     xet  
190696         , FA_XLA_EXT_LINES_B_GT  l2
190697             ,(select rownum r from all_objects where rownum <= 12 and owner = p_apps_owner)
190698         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
190699           AND xet.event_type_code = C_EVENT_TYPE_CODE
190700             AND l2.event_id          = xet.event_id
190704 ;
190701   AND l2.ledger_id (+)  = p_sla_ledger_id
190702 
190703 )
190705 --
190706 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
190707 
190708       trace
190709          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
190710          ,p_level    => C_LEVEL_STATEMENT
190711          ,p_module   => l_log_module);
190712 
190713 END IF;
190714 
190715 
190716 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
190717       trace
190718          (p_msg      => 'END of insert_sources_415'
190719          ,p_level    => C_LEVEL_PROCEDURE
190720          ,p_module   => l_log_module);
190721 END IF;
190722 EXCEPTION
190723   WHEN xla_exceptions_pkg.application_exception THEN
190724       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
190725             trace
190726                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
190727                ,p_level    => C_LEVEL_EXCEPTION
190728                ,p_module   => l_log_module);
190729       END IF;
190730       RAISE;
190731   WHEN OTHERS THEN
190732       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
190733             trace
190734                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
190735                ,p_level    => C_LEVEL_EXCEPTION
190736                ,p_module   => l_log_module);
190737        END IF;
190738        xla_exceptions_pkg.raise_message
190739            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_415');
190740 END insert_sources_415;
190741 --
190742 
190743 ---------------------------------------
190744 --
190745 -- PRIVATE FUNCTION
190746 --         EventType_415
190747 --
190748 ----------------------------------------
190749 --
190750 FUNCTION EventType_415
190751        (p_application_id         IN NUMBER
190752        ,p_base_ledger_id         IN NUMBER
190753        ,p_target_ledger_id       IN NUMBER
190754        ,p_language               IN VARCHAR2
190755        ,p_currency_code          IN VARCHAR2
190756        ,p_sla_ledger_id          IN NUMBER
190757        ,p_pad_start_date         IN DATE
190758        ,p_pad_end_date           IN DATE
190759        ,p_primary_ledger_id      IN NUMBER)
190760 RETURN BOOLEAN IS
190761 --
190762 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_RETIREMENTS';
190763 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CIP_RETIREMENTS';
190764 
190765 l_calculate_acctd_flag   VARCHAR2(1) :='N';
190766 l_calculate_g_l_flag     VARCHAR2(1) :='N';
190767 --
190768 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
190769 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
190770 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
190771 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
190772 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
190773 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
190774 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
190775 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
190776 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
190777 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
190778 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
190779 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
190780 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
190781 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
190782 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
190783 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
190784 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
190785 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
190786 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
190787 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
190788 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
190789 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
190790 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
190791 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
190792 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
190793 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
190794 
190795 l_event_id                             NUMBER;
190796 l_previous_event_id                    NUMBER;
190797 l_first_event_id                       NUMBER;
190798 l_last_event_id                        NUMBER;
190799 
190800 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
190801 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
190802 --
190803 --
190804 l_result                    BOOLEAN := TRUE;
190805 l_rows                      NUMBER  := 1000;
190806 l_event_type_name           VARCHAR2(80) := 'CIP Retirements';
190807 l_event_class_name          VARCHAR2(80) := 'CIP Retirements';
190808 l_description               VARCHAR2(4000);
190809 l_transaction_reversal      NUMBER;
190810 l_ae_header_id              NUMBER;
190811 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
190812 l_log_module                VARCHAR2(240);
190813 --
190814 l_acct_reversal_source      VARCHAR2(30);
190815 l_trx_reversal_source       VARCHAR2(30);
190816 
190817 l_continue_with_lines       BOOLEAN := TRUE;
190818 --
190819 l_acc_rev_gl_date_source    DATE;                      -- 4262811
190820 --
190821 type t_array_event_id is table of number index by binary_integer;
190822 
190823 l_rec_array_event                    t_rec_array_event;
190824 l_null_rec_array_event               t_rec_array_event;
190825 l_array_ae_header_id                 xla_number_array_type;
190829 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
190826 l_actual_flag                        VARCHAR2(1) := NULL;
190827 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
190828 l_balance_type_code                  VARCHAR2(1) :=NULL;
190830 
190831 --
190832 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
190833 --
190834 
190835 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
190836 TYPE t_array_source_12 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
190837 TYPE t_array_source_13 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
190838 TYPE t_array_source_14 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
190839 TYPE t_array_source_21 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
190840 TYPE t_array_source_22 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
190841 TYPE t_array_source_23 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
190842 TYPE t_array_source_24 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
190843 TYPE t_array_source_25 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
190844 TYPE t_array_source_27 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.REVAL_RSV_RETIRED_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
190845 TYPE t_array_source_28 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.REVAL_RSV_RETIRED_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
190846 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
190847 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
190848 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
190849 
190850 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
190851 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
190852 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
190853 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
190854 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
190855 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
190856 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
190857 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
190858 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
190859 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
190860 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
190861 TYPE t_array_source_41 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GAIN_LOSS_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
190862 
190863 l_array_source_1              t_array_source_1;
190864 l_array_source_12              t_array_source_12;
190865 l_array_source_13              t_array_source_13;
190866 l_array_source_14              t_array_source_14;
190867 l_array_source_21              t_array_source_21;
190868 l_array_source_22              t_array_source_22;
190869 l_array_source_23              t_array_source_23;
190870 l_array_source_24              t_array_source_24;
190871 l_array_source_25              t_array_source_25;
190872 l_array_source_27              t_array_source_27;
190873 l_array_source_28              t_array_source_28;
190874 l_array_source_30              t_array_source_30;
190875 l_array_source_51              t_array_source_51;
190876 l_array_source_52              t_array_source_52;
190877 
190878 l_array_source_3      t_array_source_3;
190879 l_array_source_7      t_array_source_7;
190880 l_array_source_11      t_array_source_11;
190881 l_array_source_17      t_array_source_17;
190882 l_array_source_29      t_array_source_29;
190883 l_array_source_35      t_array_source_35;
190884 l_array_source_36      t_array_source_36;
190885 l_array_source_37      t_array_source_37;
190886 l_array_source_38      t_array_source_38;
190887 l_array_source_39      t_array_source_39;
190888 l_array_source_40      t_array_source_40;
190889 l_array_source_41      t_array_source_41;
190890 
190891 --
190892 CURSOR header_cur
190893 IS
190894 SELECT /*+ leading(xet) cardinality(xet,1) */
190895 -- Event Type Code: CIP_RETIREMENTS
190896 -- Event Class Code: CIP_RETIREMENTS
190897     xet.entity_id
190898   , xet.legal_entity_id
190899   , xet.entity_code
190900   , xet.transaction_number
190901   , xet.event_id
190902   , xet.event_class_code
190903   , xet.event_type_code
190904   , xet.event_number
190905   , xet.event_date
190906   , xet.transaction_date
190907   , xet.reference_num_1
190908   , xet.reference_num_2
190909   , xet.reference_num_3
190910   , xet.reference_num_4
190911   , xet.reference_char_1
190912   , xet.reference_char_2
190913   , xet.reference_char_3
190914   , xet.reference_char_4
190915   , xet.reference_date_1
190916   , xet.reference_date_2
190917   , xet.reference_date_3
190918   , xet.reference_date_4
190919   , xet.event_created_by
190920   , xet.budgetary_control_flag 
190921   , h1.PERIOD_CLOSE_DATE    source_1
190922   , h1.COST_OF_REMOVAL_CLEARING_ACCT    source_12
190923   , h1.COST_OF_REMOVAL_GAIN_ACCT    source_13
190924   , h1.COST_OF_REMOVAL_LOSS_ACCT    source_14
190925   , h1.NBV_RETIRED_GAIN_ACCT    source_21
190926   , h1.NBV_RETIRED_LOSS_ACCT    source_22
190927   , h1.PROCEEDS_OF_SALE_CLEARING_ACCT    source_23
190928   , h1.PROCEEDS_OF_SALE_GAIN_ACCT    source_24
190929   , h1.PROCEEDS_OF_SALE_LOSS_ACCT    source_25
190930   , h1.REVAL_RSV_RETIRED_GAIN_ACCT    source_27
190934   , h1.TRANSFER_TO_GL_FLAG    source_52
190931   , h1.REVAL_RSV_RETIRED_LOSS_ACCT    source_28
190932   , h1.DEFAULT_CCID    source_30
190933   , h1.ACCOUNTING_DATE    source_51
190935   FROM xla_events_gt     xet 
190936   , FA_XLA_EXT_HEADERS_B_GT  h1
190937  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
190938    and xet.event_type_code = C_EVENT_TYPE_CODE
190939    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
190940 
190941  ORDER BY event_id
190942 ;
190943 
190944 
190945 --
190946 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
190947 IS
190948 SELECT /*+ leading(xet) cardinality(xet,1) */
190949 -- Event Type Code: CIP_RETIREMENTS
190950 -- Event Class Code: CIP_RETIREMENTS
190951     xet.entity_id
190952    ,xet.legal_entity_id
190953    ,xet.entity_code
190954    ,xet.transaction_number
190955    ,xet.event_id
190956    ,xet.event_class_code
190957    ,xet.event_type_code
190958    ,xet.event_number
190959    ,xet.event_date
190960    ,xet.transaction_date
190961    ,xet.reference_num_1
190962    ,xet.reference_num_2
190963    ,xet.reference_num_3
190964    ,xet.reference_num_4
190965    ,xet.reference_char_1
190966    ,xet.reference_char_2
190967    ,xet.reference_char_3
190968    ,xet.reference_char_4
190969    ,xet.reference_date_1
190970    ,xet.reference_date_2
190971    ,xet.reference_date_3
190972    ,xet.reference_date_4
190973    ,xet.event_created_by
190974    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
190975   , l2.GENERATED_CCID    source_3
190976   , l2.CIP_COST_ACCT    source_7
190977   , l2.REVAL_RESERVE_ACCT    source_11
190978   , l2.GENERATED_OFFSET_CCID    source_17
190979   , l2.EXPENSE_ACCOUNT_CCID    source_29
190980   , l2.ADJUSTMENT_TYPE    source_35
190981   , l2.TRANSACTION_HEADER_ID    source_36
190982   , l2.ADJUSTMENT_LINE_ID    source_37
190983   , l2.DISTRIBUTION_TYPE_CODE    source_38
190984   , l2.ENTERED_AMOUNT    source_39
190985   , l2.CURRENCY_CODE    source_40
190986   , l2.GAIN_LOSS_AMOUNT    source_41
190987   FROM xla_events_gt     xet 
190988   , FA_XLA_EXT_LINES_B_GT  l2
190989  WHERE xet.event_id between x_first_event_id and x_last_event_id
190990    and xet.event_date between p_pad_start_date and p_pad_end_date
190991    and xet.event_type_code = C_EVENT_TYPE_CODE
190992    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
190993   AND l2.ledger_id = p_sla_ledger_id
190994 ;
190995 
190996 --
190997 BEGIN
190998 IF g_log_enabled THEN
190999    l_log_module := C_DEFAULT_MODULE||'.EventType_415';
191000 END IF;
191001 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
191002    trace
191003       (p_msg      => 'BEGIN of EventType_415'
191004       ,p_level    => C_LEVEL_PROCEDURE
191005       ,p_module   => l_log_module);
191006 END IF;
191007 
191008 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
191009    trace
191010       (p_msg      => 'p_application_id = '||p_application_id||
191011                      ' - p_base_ledger_id = '||p_base_ledger_id||
191012                      ' - p_target_ledger_id  = '||p_target_ledger_id||
191013                      ' - p_language = '||p_language||
191014                      ' - p_currency_code = '||p_currency_code||
191015                      ' - p_sla_ledger_id = '||p_sla_ledger_id
191016       ,p_level    => C_LEVEL_STATEMENT
191017       ,p_module   => l_log_module);
191018 END IF;
191019 --
191020 -- initialze arrays
191021 --
191022 g_array_event.DELETE;
191023 l_rec_array_event := l_null_rec_array_event;
191024 --
191025 --------------------------------------
191026 -- 4262811 Initialze MPA Line Number
191027 --------------------------------------
191028 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
191029 
191030 --
191031 
191032 --
191033 OPEN header_cur;
191034 --
191035 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
191036    trace
191037    (p_msg      => 'SQL - FETCH header_cur'
191038    ,p_level    => C_LEVEL_STATEMENT
191039    ,p_module   => l_log_module);
191040 END IF;
191041 --
191042 LOOP
191043 FETCH header_cur BULK COLLECT INTO
191044         l_array_entity_id
191045       , l_array_legal_entity_id
191046       , l_array_entity_code
191047       , l_array_transaction_num
191048       , l_array_event_id
191049       , l_array_class_code
191050       , l_array_event_type
191051       , l_array_event_number
191052       , l_array_event_date
191053       , l_array_transaction_date
191054       , l_array_reference_num_1
191055       , l_array_reference_num_2
191056       , l_array_reference_num_3
191057       , l_array_reference_num_4
191058       , l_array_reference_char_1
191059       , l_array_reference_char_2
191060       , l_array_reference_char_3
191061       , l_array_reference_char_4
191062       , l_array_reference_date_1
191063       , l_array_reference_date_2
191064       , l_array_reference_date_3
191065       , l_array_reference_date_4
191066       , l_array_event_created_by
191067       , l_array_budgetary_control_flag 
191068       , l_array_source_1
191069       , l_array_source_12
191070       , l_array_source_13
191071       , l_array_source_14
191072       , l_array_source_21
191073       , l_array_source_22
191074       , l_array_source_23
191075       , l_array_source_24
191076       , l_array_source_25
191077       , l_array_source_27
191078       , l_array_source_28
191079       , l_array_source_30
191080       , l_array_source_51
191081       , l_array_source_52
191082       LIMIT l_rows;
191083 --
191084 IF (C_LEVEL_EVENT >= g_log_level) THEN
191085    trace
191086    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
191087    ,p_level    => C_LEVEL_EVENT
191088    ,p_module   => l_log_module);
191089 END IF;
191090 --
191091 EXIT WHEN l_array_entity_id.COUNT = 0;
191095 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
191092 
191093 -- initialize arrays
191094 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
191096 
191097 --
191098 -- Bug 4458708
191099 --
191100 XLA_AE_LINES_PKG.g_LineNumber := 0;
191101 
191102 
191103 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
191104 g_last_hdr_idx := l_array_event_id.LAST;
191105 --
191106 -- loop for the headers. Each iteration is for each header extract row
191107 -- fetched in header cursor
191108 --
191109 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
191110 
191111 --
191112 -- set event info as cache for other routines to refer event attributes
191113 --
191114 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
191115    (p_application_id           => p_application_id
191116    ,p_primary_ledger_id        => p_primary_ledger_id
191117    ,p_base_ledger_id           => p_base_ledger_id
191118    ,p_target_ledger_id         => p_target_ledger_id
191119    ,p_entity_id                => l_array_entity_id(hdr_idx)
191120    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
191121    ,p_entity_code              => l_array_entity_code(hdr_idx)
191122    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
191123    ,p_event_id                 => l_array_event_id(hdr_idx)
191124    ,p_event_class_code         => l_array_class_code(hdr_idx)
191125    ,p_event_type_code          => l_array_event_type(hdr_idx)
191126    ,p_event_number             => l_array_event_number(hdr_idx)
191127    ,p_event_date               => l_array_event_date(hdr_idx)
191128    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
191129    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
191130    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
191131    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
191132    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
191133    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
191134    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
191135    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
191136    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
191137    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
191138    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
191139    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
191140    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
191141    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
191142    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
191143 
191144 --
191145 -- set the status of entry to C_VALID (0)
191146 --
191147 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
191148 
191149 --
191150 -- initialize a row for ae header
191151 --
191152 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
191153 
191154 l_event_id := l_array_event_id(hdr_idx);
191155 
191156 --
191157 -- storing the hdr_idx for event. May be used by line cursor.
191158 --
191159 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
191160 
191161 --
191162 -- store sources from header extract. This can be improved to
191163 -- store only those sources from header extract that may be used in lines
191164 --
191165 
191166 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
191167 g_array_event(l_event_id).array_value_char('source_12') := l_array_source_12(hdr_idx);
191168 g_array_event(l_event_id).array_value_char('source_13') := l_array_source_13(hdr_idx);
191169 g_array_event(l_event_id).array_value_char('source_14') := l_array_source_14(hdr_idx);
191170 g_array_event(l_event_id).array_value_char('source_21') := l_array_source_21(hdr_idx);
191171 g_array_event(l_event_id).array_value_char('source_22') := l_array_source_22(hdr_idx);
191172 g_array_event(l_event_id).array_value_char('source_23') := l_array_source_23(hdr_idx);
191173 g_array_event(l_event_id).array_value_char('source_24') := l_array_source_24(hdr_idx);
191174 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
191175 g_array_event(l_event_id).array_value_char('source_27') := l_array_source_27(hdr_idx);
191176 g_array_event(l_event_id).array_value_char('source_28') := l_array_source_28(hdr_idx);
191177 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
191178 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
191179 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
191180 
191181 --
191182 -- initilaize the status of ae headers for diffrent balance types
191183 -- the status is initialised to C_NOT_CREATED (2)
191184 --
191185 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
191186 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
191187 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
191188 
191189 --
191190 -- call api to validate and store accounting attributes for header
191191 --
191192 
191193 ------------------------------------------------------------
191194 -- Accrual Reversal : to get date for Standard Source (NONE)
191195 ------------------------------------------------------------
191196 l_acc_rev_gl_date_source := NULL;
191197 
191198      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
191199       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
191200      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
191201       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
191202 
191203 
191204 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
191205 
191206 XLA_AE_HEADER_PKG.SetJeCategoryName;
191207 
191211 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
191208 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
191209 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
191210 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
191212 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
191213 
191214 
191215 --
191216 xla_ae_header_pkg.SetHdrDescription(
191217    p_description => Description_32 (
191218    p_application_id => p_application_id 
191219  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191220    )
191221 );
191222 --
191223 
191224 -- No header level analytical criteria
191225 
191226 --
191227 --accounting attribute enhancement, bug 3612931
191228 --
191229 l_trx_reversal_source := SUBSTR(NULL, 1,30);
191230 
191231 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
191232    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
191233 
191234    xla_accounting_err_pkg.build_message
191235       (p_appli_s_name            => 'XLA'
191236       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
191237       ,p_token_1                 => 'ACCT_ATTR_NAME'
191238       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
191239       ,p_token_2                 => 'PRODUCT_NAME'
191240       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
191241       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
191242       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
191243       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
191244 
191245 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
191246    --
191247    -- following sets the accounting attributes needed to reverse
191248    -- accounting for a distributeion
191249    --
191250    xla_ae_lines_pkg.SetTrxReversalAttrs
191251       (p_event_id              => l_event_id
191252       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
191253       ,p_trx_reversal_source   => l_trx_reversal_source);
191254 
191255 END IF;
191256 
191257 
191258 ----------------------------------------------------------------
191259 -- 4262811 -  update the header statuses to invalid in need be
191260 ----------------------------------------------------------------
191261 --
191262 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
191263 
191264 
191265   -----------------------------------------------
191266   -- No accrual reversal for the event class/type
191267   -----------------------------------------------
191268 ----------------------------------------------------------------
191269 
191270 --
191271 -- this ends the header loop iteration for one bulk fetch
191272 --
191273 END LOOP;
191274 
191275 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
191276 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
191277 
191278 --
191279 -- insert dummy rows into lines gt table that were created due to
191280 -- transaction reversals
191281 --
191282 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
191283    l_result := XLA_AE_LINES_PKG.InsertLines;
191284 END IF;
191285 
191286 --
191287 -- reset the temp_line_num for each set of events fetched from header
191288 -- cursor rather than doing it for each new event in line cursor
191289 -- Bug 3939231
191290 --
191291 xla_ae_lines_pkg.g_temp_line_num := 0;
191292 
191293 
191294 
191295 --
191296 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
191297 --
191298 --
191299 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
191300 
191301       trace
191302          (p_msg      => 'SQL - FETCH line_cur'
191303          ,p_level    => C_LEVEL_STATEMENT
191304          ,p_module   => l_log_module);
191305 
191306 END IF;
191307 --
191308 --
191309 LOOP
191310   --
191311   FETCH line_cur BULK COLLECT INTO
191312         l_array_entity_id
191313       , l_array_legal_entity_id
191314       , l_array_entity_code
191315       , l_array_transaction_num
191316       , l_array_event_id
191317       , l_array_class_code
191318       , l_array_event_type
191319       , l_array_event_number
191320       , l_array_event_date
191321       , l_array_transaction_date
191322       , l_array_reference_num_1
191323       , l_array_reference_num_2
191324       , l_array_reference_num_3
191325       , l_array_reference_num_4
191326       , l_array_reference_char_1
191327       , l_array_reference_char_2
191328       , l_array_reference_char_3
191329       , l_array_reference_char_4
191330       , l_array_reference_date_1
191331       , l_array_reference_date_2
191332       , l_array_reference_date_3
191333       , l_array_reference_date_4
191334       , l_array_event_created_by
191335       , l_array_budgetary_control_flag
191336       , l_array_extract_line_num 
191337       , l_array_source_3
191338       , l_array_source_7
191339       , l_array_source_11
191340       , l_array_source_17
191341       , l_array_source_29
191342       , l_array_source_35
191343       , l_array_source_36
191344       , l_array_source_37
191345       , l_array_source_38
191346       , l_array_source_39
191347       , l_array_source_40
191348       , l_array_source_41
191349       LIMIT l_rows;
191350 
191351   --
191352   IF (C_LEVEL_EVENT >= g_log_level) THEN
191353             trace
191354                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
191355                ,p_level    => C_LEVEL_EVENT
191359   EXIT WHEN l_array_entity_id.count = 0;
191356                ,p_module   => l_log_module);
191357   END IF;
191358   --
191360 
191361   XLA_AE_LINES_PKG.g_rec_lines := null;
191362 
191363 --
191364 -- Bug 4458708
191365 --
191366 XLA_AE_LINES_PKG.g_LineNumber := 0;
191367 --
191368 --
191369 
191370 FOR Idx IN 1..l_array_event_id.count LOOP
191371    --
191372    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
191373    --
191374    l_event_id := l_array_event_id(idx);  -- 5648433
191375 
191376    --
191377    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
191378    --
191379 
191380    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
191381              (g_array_event(l_event_id).array_value_num('header_index'))
191382          ,'N'
191383          ) <> 'Y'
191384    THEN
191385       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
191386          trace
191387             (p_msg      => 'Trancaction revesal option is not Y '
191388             ,p_level    => C_LEVEL_STATEMENT
191389             ,p_module   => l_log_module);
191390       END IF;
191391 
191392 --
191393 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
191394 --
191395 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
191396 --
191397 -- set event info as cache for other routines to refer event attributes
191398 --
191399 
191400 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
191401    l_previous_event_id := l_event_id;
191402 
191403    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
191404       (p_application_id           => p_application_id
191405       ,p_primary_ledger_id        => p_primary_ledger_id
191406       ,p_base_ledger_id           => p_base_ledger_id
191407       ,p_target_ledger_id         => p_target_ledger_id
191408       ,p_entity_id                => l_array_entity_id(Idx)
191409       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
191410       ,p_entity_code              => l_array_entity_code(Idx)
191411       ,p_transaction_num          => l_array_transaction_num(Idx)
191412       ,p_event_id                 => l_array_event_id(Idx)
191413       ,p_event_class_code         => l_array_class_code(Idx)
191414       ,p_event_type_code          => l_array_event_type(Idx)
191415       ,p_event_number             => l_array_event_number(Idx)
191416       ,p_event_date               => l_array_event_date(Idx)
191417       ,p_transaction_date         => l_array_transaction_date(Idx)
191418       ,p_reference_num_1          => l_array_reference_num_1(Idx)
191419       ,p_reference_num_2          => l_array_reference_num_2(Idx)
191420       ,p_reference_num_3          => l_array_reference_num_3(Idx)
191421       ,p_reference_num_4          => l_array_reference_num_4(Idx)
191422       ,p_reference_char_1         => l_array_reference_char_1(Idx)
191423       ,p_reference_char_2         => l_array_reference_char_2(Idx)
191424       ,p_reference_char_3         => l_array_reference_char_3(Idx)
191425       ,p_reference_char_4         => l_array_reference_char_4(Idx)
191426       ,p_reference_date_1         => l_array_reference_date_1(Idx)
191427       ,p_reference_date_2         => l_array_reference_date_2(Idx)
191428       ,p_reference_date_3         => l_array_reference_date_3(Idx)
191429       ,p_reference_date_4         => l_array_reference_date_4(Idx)
191430       ,p_event_created_by         => l_array_event_created_by(Idx)
191431       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
191432        --
191433 END IF;
191434 
191435 
191436 
191437 --
191438 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
191439 
191440 l_acct_reversal_source := SUBSTR(NULL, 1,30);
191441 
191442 IF l_continue_with_lines THEN
191443    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
191444       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
191445 
191446       xla_accounting_err_pkg.build_message
191447          (p_appli_s_name            => 'XLA'
191448          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
191449          ,p_token_1                 => 'LINE_NUMBER'
191450          ,p_value_1                 => l_array_extract_line_num(Idx)
191451          ,p_token_2                 => 'PRODUCT_NAME'
191452          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
191453          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
191454          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
191455          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
191456 
191457    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
191458       --
191459       -- following sets the accounting attributes needed to reverse
191460       -- accounting for a distributeion
191461       --
191462 
191463       --
191464       -- 5217187
191465       --
191466       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
191467       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
191468                                        g_array_event(l_event_id).array_value_num('header_index'));
191469       --
191470       --
191471 
191472       -- No reversal code generated
191473 
191474       xla_ae_lines_pkg.SetAcctReversalAttrs
191475          (p_event_id             => l_event_id
191476          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
191477          ,p_calculate_acctd_flag => l_calculate_acctd_flag
191478          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
191479    END IF;
191480 
191481    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
191482        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
191483 
191484 --
191485 AcctLineType_212 (
191486  p_application_id  => p_application_id
191487  ,p_event_id     => l_event_id
191491  ,p_balance_type_code => l_balance_type_code
191488  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191489  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191490  ,p_actual_flag => l_actual_flag
191492  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191493  
191494  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191495  , p_source_3 => l_array_source_3(Idx)
191496  , p_source_12 => g_array_event(l_event_id).array_value_char('source_12')
191497  , p_source_29 => l_array_source_29(Idx)
191498  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191499  , p_source_35 => l_array_source_35(Idx)
191500  , p_source_36 => l_array_source_36(Idx)
191501  , p_source_37 => l_array_source_37(Idx)
191502  , p_source_38 => l_array_source_38(Idx)
191503  , p_source_39 => l_array_source_39(Idx)
191504  , p_source_40 => l_array_source_40(Idx)
191505  );
191506 If(l_balance_type_code = 'A') THEN
191507   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191508 END IF;
191509 
191510 --
191511 
191512 
191513 --
191514 AcctLineType_213 (
191515  p_application_id  => p_application_id
191516  ,p_event_id     => l_event_id
191517  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191518  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191519  ,p_actual_flag => l_actual_flag
191520  ,p_balance_type_code => l_balance_type_code
191521  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191522  
191523  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191524  , p_source_3 => l_array_source_3(Idx)
191525  , p_source_13 => g_array_event(l_event_id).array_value_char('source_13')
191526  , p_source_29 => l_array_source_29(Idx)
191527  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191528  , p_source_35 => l_array_source_35(Idx)
191529  , p_source_36 => l_array_source_36(Idx)
191530  , p_source_37 => l_array_source_37(Idx)
191531  , p_source_38 => l_array_source_38(Idx)
191532  , p_source_39 => l_array_source_39(Idx)
191533  , p_source_40 => l_array_source_40(Idx)
191534  , p_source_41 => l_array_source_41(Idx)
191535  );
191536 If(l_balance_type_code = 'A') THEN
191537   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191538 END IF;
191539 
191540 --
191541 
191542 
191543 --
191544 AcctLineType_215 (
191545  p_application_id  => p_application_id
191546  ,p_event_id     => l_event_id
191547  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191548  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191549  ,p_actual_flag => l_actual_flag
191550  ,p_balance_type_code => l_balance_type_code
191551  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191552  
191553  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191554  , p_source_3 => l_array_source_3(Idx)
191555  , p_source_14 => g_array_event(l_event_id).array_value_char('source_14')
191556  , p_source_29 => l_array_source_29(Idx)
191557  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191558  , p_source_35 => l_array_source_35(Idx)
191559  , p_source_36 => l_array_source_36(Idx)
191560  , p_source_37 => l_array_source_37(Idx)
191561  , p_source_38 => l_array_source_38(Idx)
191562  , p_source_39 => l_array_source_39(Idx)
191563  , p_source_40 => l_array_source_40(Idx)
191564  , p_source_41 => l_array_source_41(Idx)
191565  );
191566 If(l_balance_type_code = 'A') THEN
191567   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191568 END IF;
191569 
191570 --
191571 
191572 
191573 --
191574 AcctLineType_217 (
191575  p_application_id  => p_application_id
191576  ,p_event_id     => l_event_id
191577  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191578  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191579  ,p_actual_flag => l_actual_flag
191580  ,p_balance_type_code => l_balance_type_code
191581  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191582  
191583  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191584  , p_source_3 => l_array_source_3(Idx)
191585  , p_source_21 => g_array_event(l_event_id).array_value_char('source_21')
191586  , p_source_29 => l_array_source_29(Idx)
191587  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191588  , p_source_35 => l_array_source_35(Idx)
191589  , p_source_36 => l_array_source_36(Idx)
191590  , p_source_37 => l_array_source_37(Idx)
191591  , p_source_38 => l_array_source_38(Idx)
191592  , p_source_39 => l_array_source_39(Idx)
191593  , p_source_40 => l_array_source_40(Idx)
191594  , p_source_41 => l_array_source_41(Idx)
191595  );
191596 If(l_balance_type_code = 'A') THEN
191597   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191598 END IF;
191599 
191600 --
191601 
191602 
191603 --
191604 AcctLineType_220 (
191605  p_application_id  => p_application_id
191606  ,p_event_id     => l_event_id
191607  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191608  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191609  ,p_actual_flag => l_actual_flag
191610  ,p_balance_type_code => l_balance_type_code
191611  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191612  
191613  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191614  , p_source_3 => l_array_source_3(Idx)
191615  , p_source_22 => g_array_event(l_event_id).array_value_char('source_22')
191616  , p_source_29 => l_array_source_29(Idx)
191617  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191618  , p_source_35 => l_array_source_35(Idx)
191619  , p_source_36 => l_array_source_36(Idx)
191620  , p_source_37 => l_array_source_37(Idx)
191621  , p_source_38 => l_array_source_38(Idx)
191622  , p_source_39 => l_array_source_39(Idx)
191623  , p_source_40 => l_array_source_40(Idx)
191624  , p_source_41 => l_array_source_41(Idx)
191625  );
191626 If(l_balance_type_code = 'A') THEN
191627   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191628 END IF;
191629 
191630 --
191631 
191632 
191633 --
191634 AcctLineType_222 (
191635  p_application_id  => p_application_id
191639  ,p_actual_flag => l_actual_flag
191636  ,p_event_id     => l_event_id
191637  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191638  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191640  ,p_balance_type_code => l_balance_type_code
191641  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191642  
191643  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191644  , p_source_3 => l_array_source_3(Idx)
191645  , p_source_23 => g_array_event(l_event_id).array_value_char('source_23')
191646  , p_source_29 => l_array_source_29(Idx)
191647  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191648  , p_source_35 => l_array_source_35(Idx)
191649  , p_source_36 => l_array_source_36(Idx)
191650  , p_source_37 => l_array_source_37(Idx)
191651  , p_source_38 => l_array_source_38(Idx)
191652  , p_source_39 => l_array_source_39(Idx)
191653  , p_source_40 => l_array_source_40(Idx)
191654  );
191655 If(l_balance_type_code = 'A') THEN
191656   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191657 END IF;
191658 
191659 --
191660 
191661 
191662 --
191663 AcctLineType_223 (
191664  p_application_id  => p_application_id
191665  ,p_event_id     => l_event_id
191666  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191667  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191668  ,p_actual_flag => l_actual_flag
191669  ,p_balance_type_code => l_balance_type_code
191670  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191671  
191672  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191673  , p_source_3 => l_array_source_3(Idx)
191674  , p_source_24 => g_array_event(l_event_id).array_value_char('source_24')
191675  , p_source_29 => l_array_source_29(Idx)
191676  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191677  , p_source_35 => l_array_source_35(Idx)
191678  , p_source_36 => l_array_source_36(Idx)
191679  , p_source_37 => l_array_source_37(Idx)
191680  , p_source_38 => l_array_source_38(Idx)
191681  , p_source_39 => l_array_source_39(Idx)
191682  , p_source_40 => l_array_source_40(Idx)
191683  , p_source_41 => l_array_source_41(Idx)
191684  );
191685 If(l_balance_type_code = 'A') THEN
191686   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191687 END IF;
191688 
191689 --
191690 
191691 
191692 --
191693 AcctLineType_225 (
191694  p_application_id  => p_application_id
191695  ,p_event_id     => l_event_id
191696  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191697  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191698  ,p_actual_flag => l_actual_flag
191699  ,p_balance_type_code => l_balance_type_code
191700  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191701  
191702  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191703  , p_source_3 => l_array_source_3(Idx)
191704  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
191705  , p_source_29 => l_array_source_29(Idx)
191706  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191707  , p_source_35 => l_array_source_35(Idx)
191708  , p_source_36 => l_array_source_36(Idx)
191709  , p_source_37 => l_array_source_37(Idx)
191710  , p_source_38 => l_array_source_38(Idx)
191711  , p_source_39 => l_array_source_39(Idx)
191712  , p_source_40 => l_array_source_40(Idx)
191713  , p_source_41 => l_array_source_41(Idx)
191714  );
191715 If(l_balance_type_code = 'A') THEN
191716   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191717 END IF;
191718 
191719 --
191720 
191721 
191722 --
191723 AcctLineType_232 (
191724  p_application_id  => p_application_id
191725  ,p_event_id     => l_event_id
191726  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191727  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191728  ,p_actual_flag => l_actual_flag
191729  ,p_balance_type_code => l_balance_type_code
191730  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191731  
191732  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191733  , p_source_3 => l_array_source_3(Idx)
191734  , p_source_7 => l_array_source_7(Idx)
191735  , p_source_29 => l_array_source_29(Idx)
191736  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191737  , p_source_35 => l_array_source_35(Idx)
191738  , p_source_36 => l_array_source_36(Idx)
191739  , p_source_37 => l_array_source_37(Idx)
191740  , p_source_38 => l_array_source_38(Idx)
191741  , p_source_39 => l_array_source_39(Idx)
191742  , p_source_40 => l_array_source_40(Idx)
191743  );
191744 If(l_balance_type_code = 'A') THEN
191745   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191746 END IF;
191747 
191748 --
191749 
191750 
191751 --
191752 AcctLineType_233 (
191753  p_application_id  => p_application_id
191754  ,p_event_id     => l_event_id
191755  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191756  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191757  ,p_actual_flag => l_actual_flag
191758  ,p_balance_type_code => l_balance_type_code
191759  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191760  
191761  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191762  , p_source_3 => l_array_source_3(Idx)
191763  , p_source_11 => l_array_source_11(Idx)
191764  , p_source_17 => l_array_source_17(Idx)
191765  , p_source_29 => l_array_source_29(Idx)
191766  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191767  , p_source_35 => l_array_source_35(Idx)
191768  , p_source_36 => l_array_source_36(Idx)
191769  , p_source_37 => l_array_source_37(Idx)
191770  , p_source_38 => l_array_source_38(Idx)
191771  , p_source_39 => l_array_source_39(Idx)
191772  , p_source_40 => l_array_source_40(Idx)
191773  );
191774 If(l_balance_type_code = 'A') THEN
191775   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191776 END IF;
191777 
191778 --
191779 
191780 
191781 --
191782 AcctLineType_235 (
191783  p_application_id  => p_application_id
191784  ,p_event_id     => l_event_id
191788  ,p_balance_type_code => l_balance_type_code
191785  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191786  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191787  ,p_actual_flag => l_actual_flag
191789  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191790  
191791  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191792  , p_source_3 => l_array_source_3(Idx)
191793  , p_source_27 => g_array_event(l_event_id).array_value_char('source_27')
191794  , p_source_29 => l_array_source_29(Idx)
191795  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191796  , p_source_35 => l_array_source_35(Idx)
191797  , p_source_36 => l_array_source_36(Idx)
191798  , p_source_37 => l_array_source_37(Idx)
191799  , p_source_38 => l_array_source_38(Idx)
191800  , p_source_39 => l_array_source_39(Idx)
191801  , p_source_40 => l_array_source_40(Idx)
191802  , p_source_41 => l_array_source_41(Idx)
191803  );
191804 If(l_balance_type_code = 'A') THEN
191805   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191806 END IF;
191807 
191808 --
191809 
191810 
191811 --
191812 AcctLineType_238 (
191813  p_application_id  => p_application_id
191814  ,p_event_id     => l_event_id
191815  ,p_calculate_acctd_flag => l_calculate_acctd_flag
191816  ,p_calculate_g_l_flag => l_calculate_g_l_flag
191817  ,p_actual_flag => l_actual_flag
191818  ,p_balance_type_code => l_balance_type_code
191819  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
191820  
191821  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
191822  , p_source_3 => l_array_source_3(Idx)
191823  , p_source_28 => g_array_event(l_event_id).array_value_char('source_28')
191824  , p_source_29 => l_array_source_29(Idx)
191825  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
191826  , p_source_35 => l_array_source_35(Idx)
191827  , p_source_36 => l_array_source_36(Idx)
191828  , p_source_37 => l_array_source_37(Idx)
191829  , p_source_38 => l_array_source_38(Idx)
191830  , p_source_39 => l_array_source_39(Idx)
191831  , p_source_40 => l_array_source_40(Idx)
191832  , p_source_41 => l_array_source_41(Idx)
191833  );
191834 If(l_balance_type_code = 'A') THEN
191835   l_actual_gain_loss_ref := l_gain_or_loss_ref;
191836 END IF;
191837 
191838 --
191839 
191840       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
191841       -- or secondary ledger that has different currency with primary
191842       -- or alc that is calculated by sla
191843       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
191844             (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'))
191845 
191846 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
191847 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
191848           AND (l_actual_flag = 'A')) THEN
191849         XLA_AE_LINES_PKG.CreateGainOrLossLines(
191850           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
191851          ,p_application_id   => p_application_id
191852          ,p_amb_context_code => 'DEFAULT'
191853          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
191854          ,p_event_class_code => C_EVENT_CLASS_CODE
191855          ,p_event_type_code  => C_EVENT_TYPE_CODE
191856          
191857          ,p_gain_ccid        => -1
191858          ,p_loss_ccid        => -1
191859 
191860          ,p_actual_flag      => l_actual_flag
191861          ,p_enc_flag         => null
191862          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
191863          ,p_enc_g_l_ref      => null
191864          );
191865       END IF;
191866    END IF;
191867 END IF;
191868 
191869    ELSE
191870       --
191871       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
191872       --
191873       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
191874          trace
191875             (p_msg      => 'Trancaction revesal option is Y'
191876             ,p_level    => C_LEVEL_STATEMENT
191877             ,p_module   => l_log_module);
191878       END IF;
191879    END IF;
191880 
191881 END LOOP;
191882 l_result := XLA_AE_LINES_PKG.InsertLines ;
191883 end loop;
191884 close line_cur;
191885 
191886 
191887 --
191888 -- insert headers into xla_ae_headers_gt table
191889 --
191890 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
191891 
191892 -- insert into errors table here.
191893 
191894 END LOOP;
191895 
191896 --
191897 -- 4865292
191898 --
191899 -- Compare g_hdr_extract_count with event count in
191900 -- CreateHeadersAndLines.
191901 --
191902 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
191903 
191904 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
191905    trace (p_msg     => '# rows extracted from header extract objects '
191906                     || ' (running total): '
191907                     || g_hdr_extract_count
191908          ,p_level   => C_LEVEL_STATEMENT
191909          ,p_module  => l_log_module);
191910 END IF;
191911 
191912 CLOSE header_cur;
191913 --
191914 
191915 --
191916 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
191917    trace
191918       (p_msg      => 'END of EventType_415'
191919       ,p_level    => C_LEVEL_PROCEDURE
191920       ,p_module   => l_log_module);
191921 END IF;
191922 --
191923 RETURN l_result;
191924 EXCEPTION
191925 WHEN xla_exceptions_pkg.application_exception THEN
191926    
191927 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
191928 
191929    
191930 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
191931 
191932    RAISE;
191933 
191934 WHEN NO_DATA_FOUND THEN
191935 
191936 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
191940 LOOP
191937 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
191938 
191939 FOR header_record IN header_cur
191941     l_array_header_events(header_record.event_id) := header_record.event_id;
191942 END LOOP;
191943 
191944 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
191945 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
191946 
191947 fnd_file.put_line(fnd_file.LOG, '                    ');
191948 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
191949 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
191950 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
191951 
191952 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
191953 LOOP
191954 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
191955 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
191956         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
191957 	END IF;
191958 END LOOP;
191959 
191960 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
191961 fnd_file.put_line(fnd_file.LOG, '                    ');
191962 
191963 
191964 xla_exceptions_pkg.raise_message
191965       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_415');
191966 
191967 
191968 WHEN OTHERS THEN
191969    xla_exceptions_pkg.raise_message
191970       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_415');
191971 END EventType_415;
191972 --
191973 
191974 ---------------------------------------
191975 --
191976 -- PRIVATE PROCEDURE
191977 --         insert_sources_416
191978 --
191979 ----------------------------------------
191980 --
191981 PROCEDURE insert_sources_416(
191982                                 p_target_ledger_id       IN NUMBER
191983                               , p_language               IN VARCHAR2
191984                               , p_sla_ledger_id          IN NUMBER
191985                               , p_pad_start_date         IN DATE
191986                               , p_pad_end_date           IN DATE
191987                          )
191988 IS
191989 
191990 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_REVALUATION_ALL';
191991 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CIP_REVALUATION';
191992 p_apps_owner                   VARCHAR2(30);
191993 l_log_module                   VARCHAR2(240);
191994 BEGIN
191995 IF g_log_enabled THEN
191996       l_log_module := C_DEFAULT_MODULE||'.insert_sources_416';
191997 END IF;
191998 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
191999 
192000       trace
192001          (p_msg      => 'BEGIN of insert_sources_416'
192002          ,p_level    => C_LEVEL_PROCEDURE
192003          ,p_module   => l_log_module);
192004 
192005 END IF;
192006 
192007 -- select APPS owner
192008 SELECT oracle_username
192009   INTO p_apps_owner
192010   FROM fnd_oracle_userid
192011  WHERE read_only_flag = 'U'
192012 ;
192013 
192014 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
192015       trace
192016          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
192017                         ' - p_language = '||p_language||
192018                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
192019                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
192020                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
192021                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
192022          ,p_level    => C_LEVEL_STATEMENT
192023          ,p_module   => l_log_module);
192024 END IF;
192025 
192026 
192027 --
192028 INSERT INTO xla_diag_sources --hdr2
192029 (
192030         event_id
192031       , ledger_id
192032       , sla_ledger_id
192033       , description_language
192034       , object_name
192035       , object_type_code
192036       , line_number
192037       , source_application_id
192038       , source_type_code
192039       , source_code
192040       , source_value
192041       , source_meaning
192042       , created_by
192043       , creation_date
192044       , last_update_date
192045       , last_updated_by
192046       , last_update_login
192047       , program_update_date
192048       , program_application_id
192049       , program_id
192050       , request_id
192051 )
192052 SELECT
192053         event_id
192054       , p_target_ledger_id
192055       , p_sla_ledger_id
192056       , p_language
192057       , object_name
192058       , object_type_code
192059       , line_number
192060       , source_application_id
192061       , source_type_code
192062       , source_code
192063       , SUBSTR(source_value ,1,1996)
192064       , SUBSTR(source_meaning ,1,200)
192065       , xla_environment_pkg.g_Usr_Id
192066       , TRUNC(SYSDATE)
192067       , TRUNC(SYSDATE)
192068       , xla_environment_pkg.g_Usr_Id
192069       , xla_environment_pkg.g_Login_Id
192070       , TRUNC(SYSDATE)
192071       , xla_environment_pkg.g_Prog_Appl_Id
192072       , xla_environment_pkg.g_Prog_Id
192073       , xla_environment_pkg.g_Req_Id
192074   FROM (
192075        SELECT xet.event_id                  event_id
192076             , 0                          line_number
192077             , CASE r
192078                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
192079                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
192080                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
192081                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
192082                 
192083                ELSE null
192084               END                           object_name
192085             , CASE r
192086                 WHEN 1 THEN 'HEADER' 
192090                 
192087                 WHEN 2 THEN 'HEADER' 
192088                 WHEN 3 THEN 'HEADER' 
192089                 WHEN 4 THEN 'HEADER' 
192091                 ELSE null
192092               END                           object_type_code
192093             , CASE r
192094                 WHEN 1 THEN '140' 
192095                 WHEN 2 THEN '140' 
192096                 WHEN 3 THEN '140' 
192097                 WHEN 4 THEN '140' 
192098                 
192099                 ELSE null
192100               END                           source_application_id
192101             , 'S'             source_type_code
192102             , CASE r
192103                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
192104                 WHEN 2 THEN 'DEFAULT_CCID' 
192105                 WHEN 3 THEN 'ACCOUNTING_DATE' 
192106                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
192107                 
192108                 ELSE null
192109               END                           source_code
192110             , CASE r
192111                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
192112                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
192113                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
192114                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
192115                 
192116                 ELSE null
192117               END                           source_value
192118             , null              source_meaning
192119          FROM xla_events_gt     xet  
192120       , FA_XLA_EXT_HEADERS_B_GT  h1
192121              ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
192122          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
192123            AND xet.event_class_code = C_EVENT_CLASS_CODE
192124               AND h1.event_id = xet.event_id
192125 
192126 )
192127 ;
192128 --
192129 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
192130 
192131       trace
192132          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
192133          ,p_level    => C_LEVEL_STATEMENT
192134          ,p_module   => l_log_module);
192135 
192136 END IF;
192137 --
192138 
192139 
192140 
192141 --
192142 INSERT INTO xla_diag_sources  --line2
192143 (
192144         event_id
192145       , ledger_id
192146       , sla_ledger_id
192147       , description_language
192148       , object_name
192149       , object_type_code
192150       , line_number
192151       , source_application_id
192152       , source_type_code
192153       , source_code
192154       , source_value
192155       , source_meaning
192156       , created_by
192157       , creation_date
192158       , last_update_date
192159       , last_updated_by
192160       , last_update_login
192161       , program_update_date
192162       , program_application_id
192163       , program_id
192164       , request_id
192165 )
192166 SELECT  event_id
192167       , p_target_ledger_id
192168       , p_sla_ledger_id
192169       , p_language
192170       , object_name
192171       , object_type_code
192172       , line_number
192173       , source_application_id
192174       , source_type_code
192175       , source_code
192176       , SUBSTR(source_value,1,1996)
192177       , SUBSTR(source_meaning ,1,200)
192178       , xla_environment_pkg.g_Usr_Id
192179       , TRUNC(SYSDATE)
192180       , TRUNC(SYSDATE)
192181       , xla_environment_pkg.g_Usr_Id
192182       , xla_environment_pkg.g_Login_Id
192183       , TRUNC(SYSDATE)
192184       , xla_environment_pkg.g_Prog_Appl_Id
192185       , xla_environment_pkg.g_Prog_Id
192186       , xla_environment_pkg.g_Req_Id
192187   FROM (
192188        SELECT xet.event_id                  event_id
192189             , l2.line_number                 line_number
192190             , CASE r
192191                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
192192                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
192193                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
192194                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
192195                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
192196                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
192197                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
192198                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
192199                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
192200                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
192201                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
192202                 
192203                ELSE null
192204               END                           object_name
192205             , CASE r
192206                 WHEN 1 THEN 'LINE' 
192207                 WHEN 2 THEN 'LINE' 
192208                 WHEN 3 THEN 'LINE' 
192209                 WHEN 4 THEN 'LINE' 
192210                 WHEN 5 THEN 'LINE' 
192211                 WHEN 6 THEN 'LINE' 
192212                 WHEN 7 THEN 'LINE' 
192213                 WHEN 8 THEN 'LINE' 
192214                 WHEN 9 THEN 'LINE' 
192215                 WHEN 10 THEN 'LINE' 
192216                 WHEN 11 THEN 'LINE' 
192217                 
192218                 ELSE null
192219               END                           object_type_code
192220             , CASE r
192221                 WHEN 1 THEN '140' 
192222                 WHEN 2 THEN '140' 
192223                 WHEN 3 THEN '140' 
192224                 WHEN 4 THEN '140' 
192225                 WHEN 5 THEN '140' 
192226                 WHEN 6 THEN '140' 
192227                 WHEN 7 THEN '140' 
192228                 WHEN 8 THEN '140' 
192229                 WHEN 9 THEN '140' 
192230                 WHEN 10 THEN '140' 
192231                 WHEN 11 THEN '140' 
192232                 
192233                 ELSE null
192234               END                           source_application_id
192235             , 'S'             source_type_code
192236             , CASE r
192240                 WHEN 4 THEN 'GENERATED_OFFSET_CCID' 
192237                 WHEN 1 THEN 'GENERATED_CCID' 
192238                 WHEN 2 THEN 'CIP_COST_ACCT' 
192239                 WHEN 3 THEN 'REVAL_RESERVE_ACCT' 
192241                 WHEN 5 THEN 'EXPENSE_ACCOUNT_CCID' 
192242                 WHEN 6 THEN 'ADJUSTMENT_TYPE' 
192243                 WHEN 7 THEN 'TRANSACTION_HEADER_ID' 
192244                 WHEN 8 THEN 'ADJUSTMENT_LINE_ID' 
192245                 WHEN 9 THEN 'DISTRIBUTION_TYPE_CODE' 
192246                 WHEN 10 THEN 'ENTERED_AMOUNT' 
192247                 WHEN 11 THEN 'CURRENCY_CODE' 
192248                 
192249                 ELSE null
192250               END                           source_code
192251             , CASE r
192252                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
192253                 WHEN 2 THEN TO_CHAR(l2.CIP_COST_ACCT)
192254                 WHEN 3 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
192255                 WHEN 4 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
192256                 WHEN 5 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
192257                 WHEN 6 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
192258                 WHEN 7 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
192259                 WHEN 8 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
192260                 WHEN 9 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
192261                 WHEN 10 THEN TO_CHAR(l2.ENTERED_AMOUNT)
192262                 WHEN 11 THEN TO_CHAR(l2.CURRENCY_CODE)
192263                 
192264                 ELSE null
192265               END                           source_value
192266             , null              source_meaning
192267          FROM  xla_events_gt     xet  
192268         , FA_XLA_EXT_LINES_B_GT  l2
192269             , (select rownum r from all_objects where rownum <= 11 and owner = p_apps_owner)
192270         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
192271           AND xet.event_class_code = C_EVENT_CLASS_CODE
192272             AND l2.event_id          = xet.event_id
192273   AND l2.ledger_id (+)  = p_sla_ledger_id
192274 
192275 )
192276 ;
192277 --
192278 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
192279 
192280       trace
192281          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
192282          ,p_level    => C_LEVEL_STATEMENT
192283          ,p_module   => l_log_module);
192284 
192285 END IF;
192286 
192287 
192288 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
192289       trace
192290          (p_msg      => 'END of insert_sources_416'
192291          ,p_level    => C_LEVEL_PROCEDURE
192292          ,p_module   => l_log_module);
192293 END IF;
192294 EXCEPTION
192295   WHEN xla_exceptions_pkg.application_exception THEN
192296       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
192297             trace
192298                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
192299                ,p_level    => C_LEVEL_EXCEPTION
192300                ,p_module   => l_log_module);
192301       END IF;
192302       RAISE;
192303   WHEN OTHERS THEN
192304       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
192305             trace
192306                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
192307                ,p_level    => C_LEVEL_EXCEPTION
192308                ,p_module   => l_log_module);
192309        END IF;
192310        xla_exceptions_pkg.raise_message
192311            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_416');
192312 END insert_sources_416;
192313 --
192314 
192315 ---------------------------------------
192316 --
192317 -- PRIVATE FUNCTION
192318 --         EventClass_416
192319 --
192320 ----------------------------------------
192321 --
192322 FUNCTION EventClass_416
192323        (p_application_id         IN NUMBER
192324        ,p_base_ledger_id         IN NUMBER
192325        ,p_target_ledger_id       IN NUMBER
192326        ,p_language               IN VARCHAR2
192327        ,p_currency_code          IN VARCHAR2
192328        ,p_sla_ledger_id          IN NUMBER
192329        ,p_pad_start_date         IN DATE
192330        ,p_pad_end_date           IN DATE
192331        ,p_primary_ledger_id      IN NUMBER)
192332 RETURN BOOLEAN IS
192333 --
192334 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_REVALUATION_ALL';
192335 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CIP_REVALUATION';
192336 
192337 l_calculate_acctd_flag   VARCHAR2(1) :='N';
192338 l_calculate_g_l_flag     VARCHAR2(1) :='N';
192339 --
192340 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
192341 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
192342 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
192343 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
192344 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
192345 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
192346 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
192347 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
192348 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
192349 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
192350 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
192351 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
192352 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
192353 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
192354 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
192355 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
192356 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
192357 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
192358 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
192362 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
192359 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
192360 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
192361 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
192363 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
192364 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
192365 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
192366 
192367 l_event_id                             NUMBER;
192368 l_previous_event_id                    NUMBER;
192369 l_first_event_id                       NUMBER;
192370 l_last_event_id                        NUMBER;
192371 
192372 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
192373 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
192374 --
192375 --
192376 l_result                    BOOLEAN := TRUE;
192377 l_rows                      NUMBER  := 1000;
192378 l_event_type_name           VARCHAR2(80) := 'All';
192379 l_event_class_name          VARCHAR2(80) := 'CIP Revaluation';
192380 l_description               VARCHAR2(4000);
192381 l_transaction_reversal      NUMBER;
192382 l_ae_header_id              NUMBER;
192383 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
192384 l_log_module                VARCHAR2(240);
192385 --
192386 l_acct_reversal_source      VARCHAR2(30);
192387 l_trx_reversal_source       VARCHAR2(30);
192388 
192389 l_continue_with_lines       BOOLEAN := TRUE;
192390 --
192391 l_acc_rev_gl_date_source    DATE;                      -- 4262811
192392 --
192393 type t_array_event_id is table of number index by binary_integer;
192394 
192395 l_rec_array_event                    t_rec_array_event;
192396 l_null_rec_array_event               t_rec_array_event;
192397 l_array_ae_header_id                 xla_number_array_type;
192398 l_actual_flag                        VARCHAR2(1) := NULL;
192399 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
192400 l_balance_type_code                  VARCHAR2(1) :=NULL;
192401 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
192402 
192403 --
192404 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
192405 --
192406 
192407 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
192408 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
192409 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
192410 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
192411 
192412 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
192413 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
192414 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
192415 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
192416 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
192417 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
192418 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
192419 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
192420 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
192421 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
192422 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
192423 
192424 l_array_source_1              t_array_source_1;
192425 l_array_source_30              t_array_source_30;
192426 l_array_source_51              t_array_source_51;
192427 l_array_source_52              t_array_source_52;
192428 
192429 l_array_source_3      t_array_source_3;
192430 l_array_source_7      t_array_source_7;
192431 l_array_source_11      t_array_source_11;
192432 l_array_source_17      t_array_source_17;
192433 l_array_source_29      t_array_source_29;
192434 l_array_source_35      t_array_source_35;
192435 l_array_source_36      t_array_source_36;
192436 l_array_source_37      t_array_source_37;
192437 l_array_source_38      t_array_source_38;
192438 l_array_source_39      t_array_source_39;
192439 l_array_source_40      t_array_source_40;
192440 
192441 --
192442 CURSOR header_cur
192443 IS
192444 SELECT /*+ leading(xet) cardinality(xet,1) */
192445 -- Event Class Code: CIP_REVALUATION
192446     xet.entity_id
192447    ,xet.legal_entity_id
192448    ,xet.entity_code
192449    ,xet.transaction_number
192450    ,xet.event_id
192451    ,xet.event_class_code
192452    ,xet.event_type_code
192453    ,xet.event_number
192454    ,xet.event_date
192455    ,xet.transaction_date
192456    ,xet.reference_num_1
192457    ,xet.reference_num_2
192458    ,xet.reference_num_3
192459    ,xet.reference_num_4
192460    ,xet.reference_char_1
192461    ,xet.reference_char_2
192462    ,xet.reference_char_3
192463    ,xet.reference_char_4
192464    ,xet.reference_date_1
192465    ,xet.reference_date_2
192466    ,xet.reference_date_3
192467    ,xet.reference_date_4
192468    ,xet.event_created_by
192469    ,xet.budgetary_control_flag 
192470   , h1.PERIOD_CLOSE_DATE    source_1
192471   , h1.DEFAULT_CCID    source_30
192472   , h1.ACCOUNTING_DATE    source_51
192473   , h1.TRANSFER_TO_GL_FLAG    source_52
192474   FROM xla_events_gt     xet 
192475   , FA_XLA_EXT_HEADERS_B_GT  h1
192476  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
192477    and xet.event_class_code = C_EVENT_CLASS_CODE
192481 ;
192478    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
192479 
192480  ORDER BY event_id
192482 
192483 
192484 --
192485 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
192486 IS
192487 SELECT  /*+ leading(xet) cardinality(xet,1) */
192488 -- Event Class Code: CIP_REVALUATION
192489     xet.entity_id
192490    ,xet.legal_entity_id
192491    ,xet.entity_code
192492    ,xet.transaction_number
192493    ,xet.event_id
192494    ,xet.event_class_code
192495    ,xet.event_type_code
192496    ,xet.event_number
192497    ,xet.event_date
192498    ,xet.transaction_date
192499    ,xet.reference_num_1
192500    ,xet.reference_num_2
192501    ,xet.reference_num_3
192502    ,xet.reference_num_4
192503    ,xet.reference_char_1
192504    ,xet.reference_char_2
192505    ,xet.reference_char_3
192506    ,xet.reference_char_4
192507    ,xet.reference_date_1
192508    ,xet.reference_date_2
192509    ,xet.reference_date_3
192510    ,xet.reference_date_4
192511    ,xet.event_created_by
192512    ,xet.budgetary_control_flag
192513  , l2.LINE_NUMBER  
192514   , l2.GENERATED_CCID    source_3
192515   , l2.CIP_COST_ACCT    source_7
192516   , l2.REVAL_RESERVE_ACCT    source_11
192517   , l2.GENERATED_OFFSET_CCID    source_17
192518   , l2.EXPENSE_ACCOUNT_CCID    source_29
192519   , l2.ADJUSTMENT_TYPE    source_35
192520   , l2.TRANSACTION_HEADER_ID    source_36
192521   , l2.ADJUSTMENT_LINE_ID    source_37
192522   , l2.DISTRIBUTION_TYPE_CODE    source_38
192523   , l2.ENTERED_AMOUNT    source_39
192524   , l2.CURRENCY_CODE    source_40
192525   FROM xla_events_gt     xet 
192526   , FA_XLA_EXT_LINES_B_GT  l2
192527  WHERE xet.event_id between x_first_event_id and x_last_event_id
192528    and xet.event_date between p_pad_start_date and p_pad_end_date
192529    and xet.event_class_code = C_EVENT_CLASS_CODE
192530    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
192531   AND l2.ledger_id = p_sla_ledger_id
192532 ;
192533 
192534 --
192535 BEGIN
192536 IF g_log_enabled THEN
192537    l_log_module := C_DEFAULT_MODULE||'.EventClass_416';
192538 END IF;
192539 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
192540    trace
192541       (p_msg      => 'BEGIN of EventClass_416'
192542       ,p_level    => C_LEVEL_PROCEDURE
192543       ,p_module   => l_log_module);
192544 END IF;
192545 
192546 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
192547    trace
192548       (p_msg      => 'p_application_id = '||p_application_id||
192549                      ' - p_base_ledger_id = '||p_base_ledger_id||
192550                      ' - p_target_ledger_id  = '||p_target_ledger_id||
192551                      ' - p_language = '||p_language||
192552                      ' - p_currency_code = '||p_currency_code||
192553                      ' - p_sla_ledger_id = '||p_sla_ledger_id
192554       ,p_level    => C_LEVEL_STATEMENT
192555       ,p_module   => l_log_module);
192556 END IF;
192557 --
192558 -- initialze arrays
192559 --
192560 g_array_event.DELETE;
192561 l_rec_array_event := l_null_rec_array_event;
192562 --
192563 --------------------------------------
192564 -- 4262811 Initialze MPA Line Number
192565 --------------------------------------
192566 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
192567 
192568 --
192569 
192570 --
192571 OPEN header_cur;
192572 --
192573 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
192574    trace
192575    (p_msg      => 'SQL - FETCH header_cur'
192576    ,p_level    => C_LEVEL_STATEMENT
192577    ,p_module   => l_log_module);
192578 END IF;
192579 --
192580 LOOP
192581 FETCH header_cur BULK COLLECT INTO
192582         l_array_entity_id
192583       , l_array_legal_entity_id
192584       , l_array_entity_code
192585       , l_array_transaction_num
192586       , l_array_event_id
192587       , l_array_class_code
192588       , l_array_event_type
192589       , l_array_event_number
192590       , l_array_event_date
192591       , l_array_transaction_date
192592       , l_array_reference_num_1
192593       , l_array_reference_num_2
192594       , l_array_reference_num_3
192595       , l_array_reference_num_4
192596       , l_array_reference_char_1
192597       , l_array_reference_char_2
192598       , l_array_reference_char_3
192599       , l_array_reference_char_4
192600       , l_array_reference_date_1
192601       , l_array_reference_date_2
192602       , l_array_reference_date_3
192603       , l_array_reference_date_4
192604       , l_array_event_created_by
192605       , l_array_budgetary_control_flag 
192606       , l_array_source_1
192607       , l_array_source_30
192608       , l_array_source_51
192609       , l_array_source_52
192610       LIMIT l_rows;
192611 --
192612 IF (C_LEVEL_EVENT >= g_log_level) THEN
192613    trace
192614    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
192615    ,p_level    => C_LEVEL_EVENT
192616    ,p_module   => l_log_module);
192617 END IF;
192618 --
192619 EXIT WHEN l_array_entity_id.COUNT = 0;
192620 
192621 -- initialize arrays
192622 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
192623 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
192624 
192625 --
192626 -- Bug 4458708
192627 --
192628 XLA_AE_LINES_PKG.g_LineNumber := 0;
192629 
192630 
192631 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
192632 g_last_hdr_idx := l_array_event_id.LAST;
192633 --
192634 -- loop for the headers. Each iteration is for each header extract row
192635 -- fetched in header cursor
192636 --
192637 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
192638 
192639 --
192640 -- set event info as cache for other routines to refer event attributes
192641 --
192645    ,p_base_ledger_id           => p_base_ledger_id
192642 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
192643    (p_application_id           => p_application_id
192644    ,p_primary_ledger_id        => p_primary_ledger_id
192646    ,p_target_ledger_id         => p_target_ledger_id
192647    ,p_entity_id                => l_array_entity_id(hdr_idx)
192648    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
192649    ,p_entity_code              => l_array_entity_code(hdr_idx)
192650    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
192651    ,p_event_id                 => l_array_event_id(hdr_idx)
192652    ,p_event_class_code         => l_array_class_code(hdr_idx)
192653    ,p_event_type_code          => l_array_event_type(hdr_idx)
192654    ,p_event_number             => l_array_event_number(hdr_idx)
192655    ,p_event_date               => l_array_event_date(hdr_idx)
192656    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
192657    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
192658    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
192659    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
192660    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
192661    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
192662    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
192663    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
192664    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
192665    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
192666    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
192667    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
192668    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
192669    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
192670    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
192671 
192672 --
192673 -- set the status of entry to C_VALID (0)
192674 --
192675 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
192676 
192677 --
192678 -- initialize a row for ae header
192679 --
192680 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
192681 
192682 l_event_id := l_array_event_id(hdr_idx);
192683 
192684 --
192685 -- storing the hdr_idx for event. May be used by line cursor.
192686 --
192687 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
192688 
192689 --
192690 -- store sources from header extract. This can be improved to
192691 -- store only those sources from header extract that may be used in lines
192692 --
192693 
192694 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
192695 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
192696 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
192697 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
192698 
192699 --
192700 -- initilaize the status of ae headers for diffrent balance types
192701 -- the status is initialised to C_NOT_CREATED (2)
192702 --
192703 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
192704 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
192705 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
192706 
192707 --
192708 -- call api to validate and store accounting attributes for header
192709 --
192710 
192711 ------------------------------------------------------------
192712 -- Accrual Reversal : to get date for Standard Source (NONE)
192713 ------------------------------------------------------------
192714 l_acc_rev_gl_date_source := NULL;
192715 
192716      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
192717       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
192718      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
192719       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
192720 
192721 
192722 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
192723 
192724 XLA_AE_HEADER_PKG.SetJeCategoryName;
192725 
192726 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
192727 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
192728 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
192729 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
192730 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
192731 
192732 
192733 --
192734 xla_ae_header_pkg.SetHdrDescription(
192735    p_description => Description_41 (
192736    p_application_id => p_application_id 
192737  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
192738    )
192739 );
192740 --
192741 
192742 -- No header level analytical criteria
192743 
192744 --
192745 --accounting attribute enhancement, bug 3612931
192746 --
192747 l_trx_reversal_source := SUBSTR(NULL, 1,30);
192748 
192749 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
192750    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
192751 
192752    xla_accounting_err_pkg.build_message
192753       (p_appli_s_name            => 'XLA'
192754       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
192755       ,p_token_1                 => 'ACCT_ATTR_NAME'
192756       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
192757       ,p_token_2                 => 'PRODUCT_NAME'
192758       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
192759       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
192763 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
192760       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
192761       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
192762 
192764    --
192765    -- following sets the accounting attributes needed to reverse
192766    -- accounting for a distributeion
192767    --
192768    xla_ae_lines_pkg.SetTrxReversalAttrs
192769       (p_event_id              => l_event_id
192770       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
192771       ,p_trx_reversal_source   => l_trx_reversal_source);
192772 
192773 END IF;
192774 
192775 
192776 ----------------------------------------------------------------
192777 -- 4262811 -  update the header statuses to invalid in need be
192778 ----------------------------------------------------------------
192779 --
192780 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
192781 
192782 
192783   -----------------------------------------------
192784   -- No accrual reversal for the event class/type
192785   -----------------------------------------------
192786 ----------------------------------------------------------------
192787 
192788 --
192789 -- this ends the header loop iteration for one bulk fetch
192790 --
192791 END LOOP;
192792 
192793 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
192794 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
192795 
192796 --
192797 -- insert dummy rows into lines gt table that were created due to
192798 -- transaction reversals
192799 --
192800 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
192801    l_result := XLA_AE_LINES_PKG.InsertLines;
192802 END IF;
192803 
192804 --
192805 -- reset the temp_line_num for each set of events fetched from header
192806 -- cursor rather than doing it for each new event in line cursor
192807 -- Bug 3939231
192808 --
192809 xla_ae_lines_pkg.g_temp_line_num := 0;
192810 
192811 
192812 
192813 --
192814 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
192815 --
192816 --
192817 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
192818 
192819       trace
192820          (p_msg      => 'SQL - FETCH line_cur'
192821          ,p_level    => C_LEVEL_STATEMENT
192822          ,p_module   => l_log_module);
192823 
192824 END IF;
192825 --
192826 --
192827 LOOP
192828   --
192829   FETCH line_cur BULK COLLECT INTO
192830         l_array_entity_id
192831       , l_array_legal_entity_id
192832       , l_array_entity_code
192833       , l_array_transaction_num
192834       , l_array_event_id
192835       , l_array_class_code
192836       , l_array_event_type
192837       , l_array_event_number
192838       , l_array_event_date
192839       , l_array_transaction_date
192840       , l_array_reference_num_1
192841       , l_array_reference_num_2
192842       , l_array_reference_num_3
192843       , l_array_reference_num_4
192844       , l_array_reference_char_1
192845       , l_array_reference_char_2
192846       , l_array_reference_char_3
192847       , l_array_reference_char_4
192848       , l_array_reference_date_1
192849       , l_array_reference_date_2
192850       , l_array_reference_date_3
192851       , l_array_reference_date_4
192852       , l_array_event_created_by
192853       , l_array_budgetary_control_flag
192854       , l_array_extract_line_num 
192855       , l_array_source_3
192856       , l_array_source_7
192857       , l_array_source_11
192858       , l_array_source_17
192859       , l_array_source_29
192860       , l_array_source_35
192861       , l_array_source_36
192862       , l_array_source_37
192863       , l_array_source_38
192864       , l_array_source_39
192865       , l_array_source_40
192866       LIMIT l_rows;
192867 
192868   --
192869   IF (C_LEVEL_EVENT >= g_log_level) THEN
192870             trace
192871                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
192872                ,p_level    => C_LEVEL_EVENT
192873                ,p_module   => l_log_module);
192874   END IF;
192875   --
192876   EXIT WHEN l_array_entity_id.count = 0;
192877 
192878   XLA_AE_LINES_PKG.g_rec_lines := null;
192879 
192880 --
192881 -- Bug 4458708
192882 --
192883 XLA_AE_LINES_PKG.g_LineNumber := 0;
192884 --
192885 --
192886 
192887 FOR Idx IN 1..l_array_event_id.count LOOP
192888    --
192889    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
192890    --
192891    l_event_id := l_array_event_id(idx);  -- 5648433
192892 
192893    --
192894    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
192895    --
192896 
192897    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
192898              (g_array_event(l_event_id).array_value_num('header_index'))
192899          ,'N'
192900          ) <> 'Y'
192901    THEN
192902       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
192903          trace
192904             (p_msg      => 'Trancaction revesal option is not Y '
192905             ,p_level    => C_LEVEL_STATEMENT
192906             ,p_module   => l_log_module);
192907       END IF;
192908 
192909 --
192910 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
192911 --
192912 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
192913 --
192914 -- set event info as cache for other routines to refer event attributes
192915 --
192916 
192917 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
192918    l_previous_event_id := l_event_id;
192919 
192920    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
192921       (p_application_id           => p_application_id
192925       ,p_entity_id                => l_array_entity_id(Idx)
192922       ,p_primary_ledger_id        => p_primary_ledger_id
192923       ,p_base_ledger_id           => p_base_ledger_id
192924       ,p_target_ledger_id         => p_target_ledger_id
192926       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
192927       ,p_entity_code              => l_array_entity_code(Idx)
192928       ,p_transaction_num          => l_array_transaction_num(Idx)
192929       ,p_event_id                 => l_array_event_id(Idx)
192930       ,p_event_class_code         => l_array_class_code(Idx)
192931       ,p_event_type_code          => l_array_event_type(Idx)
192932       ,p_event_number             => l_array_event_number(Idx)
192933       ,p_event_date               => l_array_event_date(Idx)
192934       ,p_transaction_date         => l_array_transaction_date(Idx)
192935       ,p_reference_num_1          => l_array_reference_num_1(Idx)
192936       ,p_reference_num_2          => l_array_reference_num_2(Idx)
192937       ,p_reference_num_3          => l_array_reference_num_3(Idx)
192938       ,p_reference_num_4          => l_array_reference_num_4(Idx)
192939       ,p_reference_char_1         => l_array_reference_char_1(Idx)
192940       ,p_reference_char_2         => l_array_reference_char_2(Idx)
192941       ,p_reference_char_3         => l_array_reference_char_3(Idx)
192942       ,p_reference_char_4         => l_array_reference_char_4(Idx)
192943       ,p_reference_date_1         => l_array_reference_date_1(Idx)
192944       ,p_reference_date_2         => l_array_reference_date_2(Idx)
192945       ,p_reference_date_3         => l_array_reference_date_3(Idx)
192946       ,p_reference_date_4         => l_array_reference_date_4(Idx)
192947       ,p_event_created_by         => l_array_event_created_by(Idx)
192948       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
192949        --
192950 END IF;
192951 
192952 
192953 
192954 --
192955 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
192956 
192957 l_acct_reversal_source := SUBSTR(NULL, 1,30);
192958 
192959 IF l_continue_with_lines THEN
192960    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
192961       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
192962 
192963       xla_accounting_err_pkg.build_message
192964          (p_appli_s_name            => 'XLA'
192965          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
192966          ,p_token_1                 => 'LINE_NUMBER'
192967          ,p_value_1                 => l_array_extract_line_num(Idx)
192968          ,p_token_2                 => 'PRODUCT_NAME'
192969          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
192970          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
192971          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
192972          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
192973 
192974    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
192975       --
192976       -- following sets the accounting attributes needed to reverse
192977       -- accounting for a distributeion
192978       --
192979 
192980       --
192981       -- 5217187
192982       --
192983       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
192984       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
192985                                        g_array_event(l_event_id).array_value_num('header_index'));
192986       --
192987       --
192988 
192989       -- No reversal code generated
192990 
192991       xla_ae_lines_pkg.SetAcctReversalAttrs
192992          (p_event_id             => l_event_id
192993          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
192994          ,p_calculate_acctd_flag => l_calculate_acctd_flag
192995          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
192996    END IF;
192997 
192998    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
192999        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
193000 
193001 --
193002 AcctLineType_239 (
193003  p_application_id  => p_application_id
193004  ,p_event_id     => l_event_id
193005  ,p_calculate_acctd_flag => l_calculate_acctd_flag
193006  ,p_calculate_g_l_flag => l_calculate_g_l_flag
193007  ,p_actual_flag => l_actual_flag
193008  ,p_balance_type_code => l_balance_type_code
193009  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
193010  
193011  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
193012  , p_source_3 => l_array_source_3(Idx)
193013  , p_source_7 => l_array_source_7(Idx)
193014  , p_source_29 => l_array_source_29(Idx)
193015  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
193016  , p_source_35 => l_array_source_35(Idx)
193017  , p_source_36 => l_array_source_36(Idx)
193018  , p_source_37 => l_array_source_37(Idx)
193019  , p_source_38 => l_array_source_38(Idx)
193020  , p_source_39 => l_array_source_39(Idx)
193021  , p_source_40 => l_array_source_40(Idx)
193022  );
193023 If(l_balance_type_code = 'A') THEN
193024   l_actual_gain_loss_ref := l_gain_or_loss_ref;
193025 END IF;
193026 
193027 --
193028 
193029 
193030 --
193031 AcctLineType_240 (
193032  p_application_id  => p_application_id
193033  ,p_event_id     => l_event_id
193034  ,p_calculate_acctd_flag => l_calculate_acctd_flag
193035  ,p_calculate_g_l_flag => l_calculate_g_l_flag
193036  ,p_actual_flag => l_actual_flag
193037  ,p_balance_type_code => l_balance_type_code
193038  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
193039  
193040  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
193041  , p_source_3 => l_array_source_3(Idx)
193042  , p_source_11 => l_array_source_11(Idx)
193043  , p_source_17 => l_array_source_17(Idx)
193044  , p_source_29 => l_array_source_29(Idx)
193045  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
193049  , p_source_38 => l_array_source_38(Idx)
193046  , p_source_35 => l_array_source_35(Idx)
193047  , p_source_36 => l_array_source_36(Idx)
193048  , p_source_37 => l_array_source_37(Idx)
193050  , p_source_39 => l_array_source_39(Idx)
193051  , p_source_40 => l_array_source_40(Idx)
193052  );
193053 If(l_balance_type_code = 'A') THEN
193054   l_actual_gain_loss_ref := l_gain_or_loss_ref;
193055 END IF;
193056 
193057 --
193058 
193059       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
193060       -- or secondary ledger that has different currency with primary
193061       -- or alc that is calculated by sla
193062       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
193063             (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'))
193064 
193065 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
193066 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
193067           AND (l_actual_flag = 'A')) THEN
193068         XLA_AE_LINES_PKG.CreateGainOrLossLines(
193069           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
193070          ,p_application_id   => p_application_id
193071          ,p_amb_context_code => 'DEFAULT'
193072          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
193073          ,p_event_class_code => C_EVENT_CLASS_CODE
193074          ,p_event_type_code  => C_EVENT_TYPE_CODE
193075          
193076          ,p_gain_ccid        => -1
193077          ,p_loss_ccid        => -1
193078 
193079          ,p_actual_flag      => l_actual_flag
193080          ,p_enc_flag         => null
193081          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
193082          ,p_enc_g_l_ref      => null
193083          );
193084       END IF;
193085    END IF;
193086 END IF;
193087 
193088    ELSE
193089       --
193090       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
193091       --
193092       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
193093          trace
193094             (p_msg      => 'Trancaction revesal option is Y'
193095             ,p_level    => C_LEVEL_STATEMENT
193096             ,p_module   => l_log_module);
193097       END IF;
193098    END IF;
193099 
193100 END LOOP;
193101 l_result := XLA_AE_LINES_PKG.InsertLines ;
193102 end loop;
193103 close line_cur;
193104 
193105 
193106 --
193107 -- insert headers into xla_ae_headers_gt table
193108 --
193109 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
193110 
193111 -- insert into errors table here.
193112 
193113 END LOOP;
193114 
193115 --
193116 -- 4865292
193117 --
193118 -- Compare g_hdr_extract_count with event count in
193119 -- CreateHeadersAndLines.
193120 --
193121 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
193122 
193123 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
193124    trace (p_msg     => '# rows extracted from header extract objects '
193125                     || ' (running total): '
193126                     || g_hdr_extract_count
193127          ,p_level   => C_LEVEL_STATEMENT
193128          ,p_module  => l_log_module);
193129 END IF;
193130 
193131 CLOSE header_cur;
193132 --
193133 
193134 --
193135 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
193136    trace
193137       (p_msg      => 'END of EventClass_416'
193138       ,p_level    => C_LEVEL_PROCEDURE
193139       ,p_module   => l_log_module);
193140 END IF;
193141 --
193142 RETURN l_result;
193143 EXCEPTION
193144 WHEN xla_exceptions_pkg.application_exception THEN
193145    
193146 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
193147 
193148    
193149 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
193150 
193151    RAISE;
193152 
193153 WHEN NO_DATA_FOUND THEN
193154 
193155 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
193156 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
193157 
193158 FOR header_record IN header_cur
193159 LOOP
193160     l_array_header_events(header_record.event_id) := header_record.event_id;
193161 END LOOP;
193162 
193163 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
193164 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
193165 
193166 fnd_file.put_line(fnd_file.LOG, '                    ');
193167 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
193168 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
193169 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
193170 
193171 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
193172 LOOP
193173 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
193174 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
193175         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
193176 	END IF;
193177 END LOOP;
193178 
193179 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
193180 fnd_file.put_line(fnd_file.LOG, '                    ');
193181 
193182 
193183 xla_exceptions_pkg.raise_message
193184       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_416');
193185 
193186 
193187 WHEN OTHERS THEN
193188    xla_exceptions_pkg.raise_message
193189       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_416');
193190 END EventClass_416;
193191 --
193192 
193193 ---------------------------------------
193194 --
193195 -- PRIVATE PROCEDURE
193196 --         insert_sources_417
193200 PROCEDURE insert_sources_417(
193197 --
193198 ----------------------------------------
193199 --
193201                                 p_target_ledger_id       IN NUMBER
193202                               , p_language               IN VARCHAR2
193203                               , p_sla_ledger_id          IN NUMBER
193204                               , p_pad_start_date         IN DATE
193205                               , p_pad_end_date           IN DATE
193206                          )
193207 IS
193208 
193209 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
193210 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CIP_SOURCE_LINE_TRANSFERS';
193211 p_apps_owner                   VARCHAR2(30);
193212 l_log_module                   VARCHAR2(240);
193213 BEGIN
193214 IF g_log_enabled THEN
193215       l_log_module := C_DEFAULT_MODULE||'.insert_sources_417';
193216 END IF;
193217 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
193218 
193219       trace
193220          (p_msg      => 'BEGIN of insert_sources_417'
193221          ,p_level    => C_LEVEL_PROCEDURE
193222          ,p_module   => l_log_module);
193223 
193224 END IF;
193225 
193226 -- select APPS owner
193227 SELECT oracle_username
193228   INTO p_apps_owner
193229   FROM fnd_oracle_userid
193230  WHERE read_only_flag = 'U'
193231 ;
193232 
193233 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
193234       trace
193235          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
193236                         ' - p_language = '||p_language||
193237                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
193238                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
193239                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
193240                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
193241          ,p_level    => C_LEVEL_STATEMENT
193242          ,p_module   => l_log_module);
193243 END IF;
193244 
193245 
193246 --
193247 INSERT INTO xla_diag_sources --hdr2
193248 (
193249         event_id
193250       , ledger_id
193251       , sla_ledger_id
193252       , description_language
193253       , object_name
193254       , object_type_code
193255       , line_number
193256       , source_application_id
193257       , source_type_code
193258       , source_code
193259       , source_value
193260       , source_meaning
193261       , created_by
193262       , creation_date
193263       , last_update_date
193264       , last_updated_by
193265       , last_update_login
193266       , program_update_date
193267       , program_application_id
193268       , program_id
193269       , request_id
193270 )
193271 SELECT
193272         event_id
193273       , p_target_ledger_id
193274       , p_sla_ledger_id
193275       , p_language
193276       , object_name
193277       , object_type_code
193278       , line_number
193279       , source_application_id
193280       , source_type_code
193281       , source_code
193282       , SUBSTR(source_value ,1,1996)
193283       , SUBSTR(source_meaning ,1,200)
193284       , xla_environment_pkg.g_Usr_Id
193285       , TRUNC(SYSDATE)
193286       , TRUNC(SYSDATE)
193287       , xla_environment_pkg.g_Usr_Id
193288       , xla_environment_pkg.g_Login_Id
193289       , TRUNC(SYSDATE)
193290       , xla_environment_pkg.g_Prog_Appl_Id
193291       , xla_environment_pkg.g_Prog_Id
193292       , xla_environment_pkg.g_Req_Id
193293   FROM (
193294        SELECT xet.event_id                  event_id
193295             , 0                          line_number
193296             , CASE r
193297                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
193298                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
193299                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
193300                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
193301                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
193302                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
193303                 
193304                ELSE null
193305               END                           object_name
193306             , CASE r
193307                 WHEN 1 THEN 'HEADER' 
193308                 WHEN 2 THEN 'HEADER' 
193309                 WHEN 3 THEN 'HEADER' 
193310                 WHEN 4 THEN 'HEADER' 
193311                 WHEN 5 THEN 'HEADER' 
193312                 WHEN 6 THEN 'HEADER' 
193313                 
193314                 ELSE null
193315               END                           object_type_code
193316             , CASE r
193317                 WHEN 1 THEN '140' 
193318                 WHEN 2 THEN '140' 
193319                 WHEN 3 THEN '140' 
193320                 WHEN 4 THEN '140' 
193321                 WHEN 5 THEN '140' 
193322                 WHEN 6 THEN '140' 
193323                 
193324                 ELSE null
193325               END                           source_application_id
193326             , 'S'             source_type_code
193327             , CASE r
193328                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
193329                 WHEN 2 THEN 'AP_INTERCOMPANY_ACCT' 
193330                 WHEN 3 THEN 'AR_INTERCOMPANY_ACCT' 
193331                 WHEN 4 THEN 'DEFAULT_CCID' 
193332                 WHEN 5 THEN 'ACCOUNTING_DATE' 
193333                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
193334                 
193335                 ELSE null
193336               END                           source_code
193337             , CASE r
193338                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
193339                 WHEN 2 THEN TO_CHAR(h1.AP_INTERCOMPANY_ACCT)
193340                 WHEN 3 THEN TO_CHAR(h1.AR_INTERCOMPANY_ACCT)
193341                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
193342                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
193343                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
193344                 
193348          FROM xla_events_gt     xet  
193345                 ELSE null
193346               END                           source_value
193347             , null              source_meaning
193349       , FA_XLA_EXT_HEADERS_B_GT  h1
193350              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
193351          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
193352            AND xet.event_class_code = C_EVENT_CLASS_CODE
193353               AND h1.event_id = xet.event_id
193354 
193355 )
193356 ;
193357 --
193358 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
193359 
193360       trace
193361          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
193362          ,p_level    => C_LEVEL_STATEMENT
193363          ,p_module   => l_log_module);
193364 
193365 END IF;
193366 --
193367 
193368 
193369 
193370 --
193371 INSERT INTO xla_diag_sources  --line2
193372 (
193373         event_id
193374       , ledger_id
193375       , sla_ledger_id
193376       , description_language
193377       , object_name
193378       , object_type_code
193379       , line_number
193380       , source_application_id
193381       , source_type_code
193382       , source_code
193383       , source_value
193384       , source_meaning
193385       , created_by
193386       , creation_date
193387       , last_update_date
193388       , last_updated_by
193389       , last_update_login
193390       , program_update_date
193391       , program_application_id
193392       , program_id
193393       , request_id
193394 )
193395 SELECT  event_id
193396       , p_target_ledger_id
193397       , p_sla_ledger_id
193398       , p_language
193399       , object_name
193400       , object_type_code
193401       , line_number
193402       , source_application_id
193403       , source_type_code
193404       , source_code
193405       , SUBSTR(source_value,1,1996)
193406       , SUBSTR(source_meaning ,1,200)
193407       , xla_environment_pkg.g_Usr_Id
193408       , TRUNC(SYSDATE)
193409       , TRUNC(SYSDATE)
193410       , xla_environment_pkg.g_Usr_Id
193411       , xla_environment_pkg.g_Login_Id
193412       , TRUNC(SYSDATE)
193413       , xla_environment_pkg.g_Prog_Appl_Id
193414       , xla_environment_pkg.g_Prog_Id
193415       , xla_environment_pkg.g_Req_Id
193416   FROM (
193417        SELECT xet.event_id                  event_id
193418             , l2.line_number                 line_number
193419             , CASE r
193420                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
193421                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
193422                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
193423                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
193424                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
193425                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
193426                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
193427                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
193428                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
193429                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
193430                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
193431                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
193432                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
193433                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
193434                 
193435                ELSE null
193436               END                           object_name
193437             , CASE r
193438                 WHEN 1 THEN 'LINE' 
193439                 WHEN 2 THEN 'LINE' 
193440                 WHEN 3 THEN 'LINE' 
193441                 WHEN 4 THEN 'LINE' 
193442                 WHEN 5 THEN 'LINE' 
193443                 WHEN 6 THEN 'LINE' 
193444                 WHEN 7 THEN 'LINE' 
193445                 WHEN 8 THEN 'LINE' 
193446                 WHEN 9 THEN 'LINE' 
193447                 WHEN 10 THEN 'LINE' 
193448                 WHEN 11 THEN 'LINE' 
193449                 WHEN 12 THEN 'LINE' 
193450                 WHEN 13 THEN 'LINE' 
193451                 WHEN 14 THEN 'LINE' 
193452                 
193453                 ELSE null
193454               END                           object_type_code
193455             , CASE r
193456                 WHEN 1 THEN '140' 
193457                 WHEN 2 THEN '140' 
193458                 WHEN 3 THEN '140' 
193459                 WHEN 4 THEN '140' 
193460                 WHEN 5 THEN '140' 
193461                 WHEN 6 THEN '140' 
193462                 WHEN 7 THEN '140' 
193463                 WHEN 8 THEN '140' 
193464                 WHEN 9 THEN '140' 
193465                 WHEN 10 THEN '140' 
193466                 WHEN 11 THEN '140' 
193467                 WHEN 12 THEN '140' 
193468                 WHEN 13 THEN '140' 
193469                 WHEN 14 THEN '140' 
193470                 
193471                 ELSE null
193472               END                           source_application_id
193473             , 'S'             source_type_code
193474             , CASE r
193475                 WHEN 1 THEN 'GENERATED_CCID' 
193476                 WHEN 2 THEN 'CIP_CLEARING_ACCT' 
193477                 WHEN 3 THEN 'PAYABLES_CCID' 
193478                 WHEN 4 THEN 'CIP_COST_ACCT' 
193479                 WHEN 5 THEN 'REVAL_RESERVE_ACCT' 
193480                 WHEN 6 THEN 'GENERATED_OFFSET_CCID' 
193481                 WHEN 7 THEN 'EXPENSE_ACCOUNT_CCID' 
193482                 WHEN 8 THEN 'ADJUSTMENT_TYPE' 
193483                 WHEN 9 THEN 'TRANSACTION_HEADER_ID' 
193484                 WHEN 10 THEN 'ADJUSTMENT_LINE_ID' 
193485                 WHEN 11 THEN 'DISTRIBUTION_TYPE_CODE' 
193486                 WHEN 12 THEN 'ENTERED_AMOUNT' 
193487                 WHEN 13 THEN 'CURRENCY_CODE' 
193488                 WHEN 14 THEN 'SOURCE_DEST_CODE' 
193489                 
193490                 ELSE null
193491               END                           source_code
193495                 WHEN 3 THEN TO_CHAR(l2.PAYABLES_CCID)
193492             , CASE r
193493                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
193494                 WHEN 2 THEN TO_CHAR(l2.CIP_CLEARING_ACCT)
193496                 WHEN 4 THEN TO_CHAR(l2.CIP_COST_ACCT)
193497                 WHEN 5 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
193498                 WHEN 6 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
193499                 WHEN 7 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
193500                 WHEN 8 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
193501                 WHEN 9 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
193502                 WHEN 10 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
193503                 WHEN 11 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
193504                 WHEN 12 THEN TO_CHAR(l2.ENTERED_AMOUNT)
193505                 WHEN 13 THEN TO_CHAR(l2.CURRENCY_CODE)
193506                 WHEN 14 THEN TO_CHAR(l2.SOURCE_DEST_CODE)
193507                 
193508                 ELSE null
193509               END                           source_value
193510             , null              source_meaning
193511          FROM  xla_events_gt     xet  
193512         , FA_XLA_EXT_LINES_B_GT  l2
193513             , (select rownum r from all_objects where rownum <= 14 and owner = p_apps_owner)
193514         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
193515           AND xet.event_class_code = C_EVENT_CLASS_CODE
193516             AND l2.event_id          = xet.event_id
193517   AND l2.ledger_id (+)  = p_sla_ledger_id
193518 
193519 )
193520 ;
193521 --
193522 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
193523 
193524       trace
193525          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
193526          ,p_level    => C_LEVEL_STATEMENT
193527          ,p_module   => l_log_module);
193528 
193529 END IF;
193530 
193531 
193532 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
193533       trace
193534          (p_msg      => 'END of insert_sources_417'
193535          ,p_level    => C_LEVEL_PROCEDURE
193536          ,p_module   => l_log_module);
193537 END IF;
193538 EXCEPTION
193539   WHEN xla_exceptions_pkg.application_exception THEN
193540       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
193541             trace
193542                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
193543                ,p_level    => C_LEVEL_EXCEPTION
193544                ,p_module   => l_log_module);
193545       END IF;
193546       RAISE;
193547   WHEN OTHERS THEN
193548       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
193549             trace
193550                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
193551                ,p_level    => C_LEVEL_EXCEPTION
193552                ,p_module   => l_log_module);
193553        END IF;
193554        xla_exceptions_pkg.raise_message
193555            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_417');
193556 END insert_sources_417;
193557 --
193558 
193559 ---------------------------------------
193560 --
193561 -- PRIVATE FUNCTION
193562 --         EventClass_417
193563 --
193564 ----------------------------------------
193565 --
193566 FUNCTION EventClass_417
193567        (p_application_id         IN NUMBER
193568        ,p_base_ledger_id         IN NUMBER
193569        ,p_target_ledger_id       IN NUMBER
193570        ,p_language               IN VARCHAR2
193571        ,p_currency_code          IN VARCHAR2
193572        ,p_sla_ledger_id          IN NUMBER
193573        ,p_pad_start_date         IN DATE
193574        ,p_pad_end_date           IN DATE
193575        ,p_primary_ledger_id      IN NUMBER)
193576 RETURN BOOLEAN IS
193577 --
193578 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_SOURCE_LINE_TRANSFERS_ALL';
193579 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CIP_SOURCE_LINE_TRANSFERS';
193580 
193581 l_calculate_acctd_flag   VARCHAR2(1) :='N';
193582 l_calculate_g_l_flag     VARCHAR2(1) :='N';
193583 --
193584 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
193585 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
193586 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
193587 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
193588 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
193589 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
193590 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
193591 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
193592 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
193593 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
193594 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
193595 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
193596 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
193597 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
193598 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
193599 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
193600 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
193601 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
193602 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
193603 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
193604 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
193605 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
193606 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
193607 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
193608 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
193609 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
193613 l_first_event_id                       NUMBER;
193610 
193611 l_event_id                             NUMBER;
193612 l_previous_event_id                    NUMBER;
193614 l_last_event_id                        NUMBER;
193615 
193616 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
193617 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
193618 --
193619 --
193620 l_result                    BOOLEAN := TRUE;
193621 l_rows                      NUMBER  := 1000;
193622 l_event_type_name           VARCHAR2(80) := 'All';
193623 l_event_class_name          VARCHAR2(80) := 'CIP Source Line Transfers';
193624 l_description               VARCHAR2(4000);
193625 l_transaction_reversal      NUMBER;
193626 l_ae_header_id              NUMBER;
193627 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
193628 l_log_module                VARCHAR2(240);
193629 --
193630 l_acct_reversal_source      VARCHAR2(30);
193631 l_trx_reversal_source       VARCHAR2(30);
193632 
193633 l_continue_with_lines       BOOLEAN := TRUE;
193634 --
193635 l_acc_rev_gl_date_source    DATE;                      -- 4262811
193636 --
193637 type t_array_event_id is table of number index by binary_integer;
193638 
193639 l_rec_array_event                    t_rec_array_event;
193640 l_null_rec_array_event               t_rec_array_event;
193641 l_array_ae_header_id                 xla_number_array_type;
193642 l_actual_flag                        VARCHAR2(1) := NULL;
193643 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
193644 l_balance_type_code                  VARCHAR2(1) :=NULL;
193645 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
193646 
193647 --
193648 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
193649 --
193650 
193651 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
193652 TYPE t_array_source_19 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AP_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
193653 TYPE t_array_source_20 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AR_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
193654 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
193655 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
193656 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
193657 
193658 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
193659 TYPE t_array_source_5 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
193660 TYPE t_array_source_6 IS TABLE OF FA_XLA_EXT_LINES_B_GT.PAYABLES_CCID%TYPE INDEX BY BINARY_INTEGER;
193661 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
193662 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
193663 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
193664 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
193665 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
193666 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
193667 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
193668 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
193669 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
193670 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
193671 TYPE t_array_source_42 IS TABLE OF FA_XLA_EXT_LINES_B_GT.SOURCE_DEST_CODE%TYPE INDEX BY BINARY_INTEGER;
193672 
193673 l_array_source_1              t_array_source_1;
193674 l_array_source_19              t_array_source_19;
193675 l_array_source_20              t_array_source_20;
193676 l_array_source_30              t_array_source_30;
193677 l_array_source_51              t_array_source_51;
193678 l_array_source_52              t_array_source_52;
193679 
193680 l_array_source_3      t_array_source_3;
193681 l_array_source_5      t_array_source_5;
193682 l_array_source_6      t_array_source_6;
193683 l_array_source_7      t_array_source_7;
193684 l_array_source_11      t_array_source_11;
193685 l_array_source_17      t_array_source_17;
193686 l_array_source_29      t_array_source_29;
193687 l_array_source_35      t_array_source_35;
193688 l_array_source_36      t_array_source_36;
193689 l_array_source_37      t_array_source_37;
193690 l_array_source_38      t_array_source_38;
193691 l_array_source_39      t_array_source_39;
193692 l_array_source_40      t_array_source_40;
193693 l_array_source_42      t_array_source_42;
193694 
193695 --
193696 CURSOR header_cur
193697 IS
193698 SELECT /*+ leading(xet) cardinality(xet,1) */
193699 -- Event Class Code: CIP_SOURCE_LINE_TRANSFERS
193700     xet.entity_id
193701    ,xet.legal_entity_id
193702    ,xet.entity_code
193703    ,xet.transaction_number
193704    ,xet.event_id
193705    ,xet.event_class_code
193706    ,xet.event_type_code
193707    ,xet.event_number
193708    ,xet.event_date
193709    ,xet.transaction_date
193710    ,xet.reference_num_1
193711    ,xet.reference_num_2
193712    ,xet.reference_num_3
193713    ,xet.reference_num_4
193714    ,xet.reference_char_1
193715    ,xet.reference_char_2
193716    ,xet.reference_char_3
193717    ,xet.reference_char_4
193718    ,xet.reference_date_1
193719    ,xet.reference_date_2
193720    ,xet.reference_date_3
193721    ,xet.reference_date_4
193722    ,xet.event_created_by
193723    ,xet.budgetary_control_flag 
193724   , h1.PERIOD_CLOSE_DATE    source_1
193725   , h1.AP_INTERCOMPANY_ACCT    source_19
193726   , h1.AR_INTERCOMPANY_ACCT    source_20
193727   , h1.DEFAULT_CCID    source_30
193731   , FA_XLA_EXT_HEADERS_B_GT  h1
193728   , h1.ACCOUNTING_DATE    source_51
193729   , h1.TRANSFER_TO_GL_FLAG    source_52
193730   FROM xla_events_gt     xet 
193732  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
193733    and xet.event_class_code = C_EVENT_CLASS_CODE
193734    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
193735 
193736  ORDER BY event_id
193737 ;
193738 
193739 
193740 --
193741 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
193742 IS
193743 SELECT  /*+ leading(xet) cardinality(xet,1) */
193744 -- Event Class Code: CIP_SOURCE_LINE_TRANSFERS
193745     xet.entity_id
193746    ,xet.legal_entity_id
193747    ,xet.entity_code
193748    ,xet.transaction_number
193749    ,xet.event_id
193750    ,xet.event_class_code
193751    ,xet.event_type_code
193752    ,xet.event_number
193753    ,xet.event_date
193754    ,xet.transaction_date
193755    ,xet.reference_num_1
193756    ,xet.reference_num_2
193757    ,xet.reference_num_3
193758    ,xet.reference_num_4
193759    ,xet.reference_char_1
193760    ,xet.reference_char_2
193761    ,xet.reference_char_3
193762    ,xet.reference_char_4
193763    ,xet.reference_date_1
193764    ,xet.reference_date_2
193765    ,xet.reference_date_3
193766    ,xet.reference_date_4
193767    ,xet.event_created_by
193768    ,xet.budgetary_control_flag
193769  , l2.LINE_NUMBER  
193770   , l2.GENERATED_CCID    source_3
193771   , l2.CIP_CLEARING_ACCT    source_5
193772   , l2.PAYABLES_CCID    source_6
193773   , l2.CIP_COST_ACCT    source_7
193774   , l2.REVAL_RESERVE_ACCT    source_11
193775   , l2.GENERATED_OFFSET_CCID    source_17
193776   , l2.EXPENSE_ACCOUNT_CCID    source_29
193777   , l2.ADJUSTMENT_TYPE    source_35
193778   , l2.TRANSACTION_HEADER_ID    source_36
193779   , l2.ADJUSTMENT_LINE_ID    source_37
193780   , l2.DISTRIBUTION_TYPE_CODE    source_38
193781   , l2.ENTERED_AMOUNT    source_39
193782   , l2.CURRENCY_CODE    source_40
193783   , l2.SOURCE_DEST_CODE    source_42
193784   FROM xla_events_gt     xet 
193785   , FA_XLA_EXT_LINES_B_GT  l2
193786  WHERE xet.event_id between x_first_event_id and x_last_event_id
193787    and xet.event_date between p_pad_start_date and p_pad_end_date
193788    and xet.event_class_code = C_EVENT_CLASS_CODE
193789    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
193790   AND l2.ledger_id = p_sla_ledger_id
193791 ;
193792 
193793 --
193794 BEGIN
193795 IF g_log_enabled THEN
193796    l_log_module := C_DEFAULT_MODULE||'.EventClass_417';
193797 END IF;
193798 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
193799    trace
193800       (p_msg      => 'BEGIN of EventClass_417'
193801       ,p_level    => C_LEVEL_PROCEDURE
193802       ,p_module   => l_log_module);
193803 END IF;
193804 
193805 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
193806    trace
193807       (p_msg      => 'p_application_id = '||p_application_id||
193808                      ' - p_base_ledger_id = '||p_base_ledger_id||
193809                      ' - p_target_ledger_id  = '||p_target_ledger_id||
193810                      ' - p_language = '||p_language||
193811                      ' - p_currency_code = '||p_currency_code||
193812                      ' - p_sla_ledger_id = '||p_sla_ledger_id
193813       ,p_level    => C_LEVEL_STATEMENT
193814       ,p_module   => l_log_module);
193815 END IF;
193816 --
193817 -- initialze arrays
193818 --
193819 g_array_event.DELETE;
193820 l_rec_array_event := l_null_rec_array_event;
193821 --
193822 --------------------------------------
193823 -- 4262811 Initialze MPA Line Number
193824 --------------------------------------
193825 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
193826 
193827 --
193828 
193829 --
193830 OPEN header_cur;
193831 --
193832 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
193833    trace
193834    (p_msg      => 'SQL - FETCH header_cur'
193835    ,p_level    => C_LEVEL_STATEMENT
193836    ,p_module   => l_log_module);
193837 END IF;
193838 --
193839 LOOP
193840 FETCH header_cur BULK COLLECT INTO
193841         l_array_entity_id
193842       , l_array_legal_entity_id
193843       , l_array_entity_code
193844       , l_array_transaction_num
193845       , l_array_event_id
193846       , l_array_class_code
193847       , l_array_event_type
193848       , l_array_event_number
193849       , l_array_event_date
193850       , l_array_transaction_date
193851       , l_array_reference_num_1
193852       , l_array_reference_num_2
193853       , l_array_reference_num_3
193854       , l_array_reference_num_4
193855       , l_array_reference_char_1
193856       , l_array_reference_char_2
193857       , l_array_reference_char_3
193858       , l_array_reference_char_4
193859       , l_array_reference_date_1
193860       , l_array_reference_date_2
193861       , l_array_reference_date_3
193862       , l_array_reference_date_4
193863       , l_array_event_created_by
193864       , l_array_budgetary_control_flag 
193865       , l_array_source_1
193866       , l_array_source_19
193867       , l_array_source_20
193868       , l_array_source_30
193869       , l_array_source_51
193870       , l_array_source_52
193871       LIMIT l_rows;
193872 --
193873 IF (C_LEVEL_EVENT >= g_log_level) THEN
193874    trace
193875    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
193876    ,p_level    => C_LEVEL_EVENT
193877    ,p_module   => l_log_module);
193878 END IF;
193879 --
193880 EXIT WHEN l_array_entity_id.COUNT = 0;
193881 
193882 -- initialize arrays
193883 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
193884 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
193885 
193886 --
193887 -- Bug 4458708
193888 --
193889 XLA_AE_LINES_PKG.g_LineNumber := 0;
193890 
193891 
193895 -- loop for the headers. Each iteration is for each header extract row
193892 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
193893 g_last_hdr_idx := l_array_event_id.LAST;
193894 --
193896 -- fetched in header cursor
193897 --
193898 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
193899 
193900 --
193901 -- set event info as cache for other routines to refer event attributes
193902 --
193903 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
193904    (p_application_id           => p_application_id
193905    ,p_primary_ledger_id        => p_primary_ledger_id
193906    ,p_base_ledger_id           => p_base_ledger_id
193907    ,p_target_ledger_id         => p_target_ledger_id
193908    ,p_entity_id                => l_array_entity_id(hdr_idx)
193909    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
193910    ,p_entity_code              => l_array_entity_code(hdr_idx)
193911    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
193912    ,p_event_id                 => l_array_event_id(hdr_idx)
193913    ,p_event_class_code         => l_array_class_code(hdr_idx)
193914    ,p_event_type_code          => l_array_event_type(hdr_idx)
193915    ,p_event_number             => l_array_event_number(hdr_idx)
193916    ,p_event_date               => l_array_event_date(hdr_idx)
193917    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
193918    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
193919    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
193920    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
193921    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
193922    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
193923    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
193924    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
193925    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
193926    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
193927    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
193928    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
193929    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
193930    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
193931    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
193932 
193933 --
193934 -- set the status of entry to C_VALID (0)
193935 --
193936 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
193937 
193938 --
193939 -- initialize a row for ae header
193940 --
193941 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
193942 
193943 l_event_id := l_array_event_id(hdr_idx);
193944 
193945 --
193946 -- storing the hdr_idx for event. May be used by line cursor.
193947 --
193948 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
193949 
193950 --
193951 -- store sources from header extract. This can be improved to
193952 -- store only those sources from header extract that may be used in lines
193953 --
193954 
193955 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
193956 g_array_event(l_event_id).array_value_char('source_19') := l_array_source_19(hdr_idx);
193957 g_array_event(l_event_id).array_value_char('source_20') := l_array_source_20(hdr_idx);
193958 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
193959 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
193960 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
193961 
193962 --
193963 -- initilaize the status of ae headers for diffrent balance types
193964 -- the status is initialised to C_NOT_CREATED (2)
193965 --
193966 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
193967 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
193968 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
193969 
193970 --
193971 -- call api to validate and store accounting attributes for header
193972 --
193973 
193974 ------------------------------------------------------------
193975 -- Accrual Reversal : to get date for Standard Source (NONE)
193976 ------------------------------------------------------------
193977 l_acc_rev_gl_date_source := NULL;
193978 
193979      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
193980       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
193981      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
193982       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
193983 
193984 
193985 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
193986 
193987 XLA_AE_HEADER_PKG.SetJeCategoryName;
193988 
193989 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
193990 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
193991 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
193992 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
193993 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
193994 
193995 
193996 --
193997 xla_ae_header_pkg.SetHdrDescription(
193998    p_description => Description_44 (
193999    p_application_id => p_application_id 
194000  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
194001    )
194002 );
194003 --
194004 
194005 -- No header level analytical criteria
194006 
194007 --
194008 --accounting attribute enhancement, bug 3612931
194009 --
194010 l_trx_reversal_source := SUBSTR(NULL, 1,30);
194011 
194012 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
194016       (p_appli_s_name            => 'XLA'
194013    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
194014 
194015    xla_accounting_err_pkg.build_message
194017       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
194018       ,p_token_1                 => 'ACCT_ATTR_NAME'
194019       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
194020       ,p_token_2                 => 'PRODUCT_NAME'
194021       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
194022       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
194023       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
194024       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
194025 
194026 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
194027    --
194028    -- following sets the accounting attributes needed to reverse
194029    -- accounting for a distributeion
194030    --
194031    xla_ae_lines_pkg.SetTrxReversalAttrs
194032       (p_event_id              => l_event_id
194033       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
194034       ,p_trx_reversal_source   => l_trx_reversal_source);
194035 
194036 END IF;
194037 
194038 
194039 ----------------------------------------------------------------
194040 -- 4262811 -  update the header statuses to invalid in need be
194041 ----------------------------------------------------------------
194042 --
194043 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
194044 
194045 
194046   -----------------------------------------------
194047   -- No accrual reversal for the event class/type
194048   -----------------------------------------------
194049 ----------------------------------------------------------------
194050 
194051 --
194052 -- this ends the header loop iteration for one bulk fetch
194053 --
194054 END LOOP;
194055 
194056 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
194057 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
194058 
194059 --
194060 -- insert dummy rows into lines gt table that were created due to
194061 -- transaction reversals
194062 --
194063 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
194064    l_result := XLA_AE_LINES_PKG.InsertLines;
194065 END IF;
194066 
194067 --
194068 -- reset the temp_line_num for each set of events fetched from header
194069 -- cursor rather than doing it for each new event in line cursor
194070 -- Bug 3939231
194071 --
194072 xla_ae_lines_pkg.g_temp_line_num := 0;
194073 
194074 
194075 
194076 --
194077 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
194078 --
194079 --
194080 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
194081 
194082       trace
194083          (p_msg      => 'SQL - FETCH line_cur'
194084          ,p_level    => C_LEVEL_STATEMENT
194085          ,p_module   => l_log_module);
194086 
194087 END IF;
194088 --
194089 --
194090 LOOP
194091   --
194092   FETCH line_cur BULK COLLECT INTO
194093         l_array_entity_id
194094       , l_array_legal_entity_id
194095       , l_array_entity_code
194096       , l_array_transaction_num
194097       , l_array_event_id
194098       , l_array_class_code
194099       , l_array_event_type
194100       , l_array_event_number
194101       , l_array_event_date
194102       , l_array_transaction_date
194103       , l_array_reference_num_1
194104       , l_array_reference_num_2
194105       , l_array_reference_num_3
194106       , l_array_reference_num_4
194107       , l_array_reference_char_1
194108       , l_array_reference_char_2
194109       , l_array_reference_char_3
194110       , l_array_reference_char_4
194111       , l_array_reference_date_1
194112       , l_array_reference_date_2
194113       , l_array_reference_date_3
194114       , l_array_reference_date_4
194115       , l_array_event_created_by
194116       , l_array_budgetary_control_flag
194117       , l_array_extract_line_num 
194118       , l_array_source_3
194119       , l_array_source_5
194120       , l_array_source_6
194121       , l_array_source_7
194122       , l_array_source_11
194123       , l_array_source_17
194124       , l_array_source_29
194125       , l_array_source_35
194126       , l_array_source_36
194127       , l_array_source_37
194128       , l_array_source_38
194129       , l_array_source_39
194130       , l_array_source_40
194131       , l_array_source_42
194132       LIMIT l_rows;
194133 
194134   --
194135   IF (C_LEVEL_EVENT >= g_log_level) THEN
194136             trace
194137                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
194138                ,p_level    => C_LEVEL_EVENT
194139                ,p_module   => l_log_module);
194140   END IF;
194141   --
194142   EXIT WHEN l_array_entity_id.count = 0;
194143 
194144   XLA_AE_LINES_PKG.g_rec_lines := null;
194145 
194146 --
194147 -- Bug 4458708
194148 --
194149 XLA_AE_LINES_PKG.g_LineNumber := 0;
194150 --
194151 --
194152 
194153 FOR Idx IN 1..l_array_event_id.count LOOP
194154    --
194155    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
194156    --
194157    l_event_id := l_array_event_id(idx);  -- 5648433
194158 
194159    --
194160    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
194161    --
194162 
194163    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
194164              (g_array_event(l_event_id).array_value_num('header_index'))
194165          ,'N'
194166          ) <> 'Y'
194167    THEN
194168       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
194172             ,p_module   => l_log_module);
194169          trace
194170             (p_msg      => 'Trancaction revesal option is not Y '
194171             ,p_level    => C_LEVEL_STATEMENT
194173       END IF;
194174 
194175 --
194176 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
194177 --
194178 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
194179 --
194180 -- set event info as cache for other routines to refer event attributes
194181 --
194182 
194183 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
194184    l_previous_event_id := l_event_id;
194185 
194186    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
194187       (p_application_id           => p_application_id
194188       ,p_primary_ledger_id        => p_primary_ledger_id
194189       ,p_base_ledger_id           => p_base_ledger_id
194190       ,p_target_ledger_id         => p_target_ledger_id
194191       ,p_entity_id                => l_array_entity_id(Idx)
194192       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
194193       ,p_entity_code              => l_array_entity_code(Idx)
194194       ,p_transaction_num          => l_array_transaction_num(Idx)
194195       ,p_event_id                 => l_array_event_id(Idx)
194196       ,p_event_class_code         => l_array_class_code(Idx)
194197       ,p_event_type_code          => l_array_event_type(Idx)
194198       ,p_event_number             => l_array_event_number(Idx)
194199       ,p_event_date               => l_array_event_date(Idx)
194200       ,p_transaction_date         => l_array_transaction_date(Idx)
194201       ,p_reference_num_1          => l_array_reference_num_1(Idx)
194202       ,p_reference_num_2          => l_array_reference_num_2(Idx)
194203       ,p_reference_num_3          => l_array_reference_num_3(Idx)
194204       ,p_reference_num_4          => l_array_reference_num_4(Idx)
194205       ,p_reference_char_1         => l_array_reference_char_1(Idx)
194206       ,p_reference_char_2         => l_array_reference_char_2(Idx)
194207       ,p_reference_char_3         => l_array_reference_char_3(Idx)
194208       ,p_reference_char_4         => l_array_reference_char_4(Idx)
194209       ,p_reference_date_1         => l_array_reference_date_1(Idx)
194210       ,p_reference_date_2         => l_array_reference_date_2(Idx)
194211       ,p_reference_date_3         => l_array_reference_date_3(Idx)
194212       ,p_reference_date_4         => l_array_reference_date_4(Idx)
194213       ,p_event_created_by         => l_array_event_created_by(Idx)
194214       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
194215        --
194216 END IF;
194217 
194218 
194219 
194220 --
194221 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
194222 
194223 l_acct_reversal_source := SUBSTR(NULL, 1,30);
194224 
194225 IF l_continue_with_lines THEN
194226    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
194227       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
194228 
194229       xla_accounting_err_pkg.build_message
194230          (p_appli_s_name            => 'XLA'
194231          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
194232          ,p_token_1                 => 'LINE_NUMBER'
194233          ,p_value_1                 => l_array_extract_line_num(Idx)
194234          ,p_token_2                 => 'PRODUCT_NAME'
194235          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
194236          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
194237          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
194238          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
194239 
194240    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
194241       --
194242       -- following sets the accounting attributes needed to reverse
194243       -- accounting for a distributeion
194244       --
194245 
194246       --
194247       -- 5217187
194248       --
194249       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
194250       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
194251                                        g_array_event(l_event_id).array_value_num('header_index'));
194252       --
194253       --
194254 
194255       -- No reversal code generated
194256 
194257       xla_ae_lines_pkg.SetAcctReversalAttrs
194258          (p_event_id             => l_event_id
194259          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
194260          ,p_calculate_acctd_flag => l_calculate_acctd_flag
194261          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
194262    END IF;
194263 
194264    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
194265        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
194266 
194267 --
194268 AcctLineType_334 (
194269  p_application_id  => p_application_id
194270  ,p_event_id     => l_event_id
194271  ,p_calculate_acctd_flag => l_calculate_acctd_flag
194272  ,p_calculate_g_l_flag => l_calculate_g_l_flag
194273  ,p_actual_flag => l_actual_flag
194274  ,p_balance_type_code => l_balance_type_code
194275  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
194276  
194277  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
194278  , p_source_3 => l_array_source_3(Idx)
194279  , p_source_19 => g_array_event(l_event_id).array_value_char('source_19')
194280  , p_source_29 => l_array_source_29(Idx)
194281  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
194282  , p_source_35 => l_array_source_35(Idx)
194283  , p_source_36 => l_array_source_36(Idx)
194284  , p_source_37 => l_array_source_37(Idx)
194285  , p_source_38 => l_array_source_38(Idx)
194286  , p_source_39 => l_array_source_39(Idx)
194287  , p_source_40 => l_array_source_40(Idx)
194288  );
194289 If(l_balance_type_code = 'A') THEN
194290   l_actual_gain_loss_ref := l_gain_or_loss_ref;
194291 END IF;
194292 
194293 --
194297 AcctLineType_335 (
194294 
194295 
194296 --
194298  p_application_id  => p_application_id
194299  ,p_event_id     => l_event_id
194300  ,p_calculate_acctd_flag => l_calculate_acctd_flag
194301  ,p_calculate_g_l_flag => l_calculate_g_l_flag
194302  ,p_actual_flag => l_actual_flag
194303  ,p_balance_type_code => l_balance_type_code
194304  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
194305  
194306  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
194307  , p_source_3 => l_array_source_3(Idx)
194308  , p_source_20 => g_array_event(l_event_id).array_value_char('source_20')
194309  , p_source_29 => l_array_source_29(Idx)
194310  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
194311  , p_source_35 => l_array_source_35(Idx)
194312  , p_source_36 => l_array_source_36(Idx)
194313  , p_source_37 => l_array_source_37(Idx)
194314  , p_source_38 => l_array_source_38(Idx)
194315  , p_source_39 => l_array_source_39(Idx)
194316  , p_source_40 => l_array_source_40(Idx)
194317  );
194318 If(l_balance_type_code = 'A') THEN
194319   l_actual_gain_loss_ref := l_gain_or_loss_ref;
194320 END IF;
194321 
194322 --
194323 
194324 
194325 --
194326 AcctLineType_338 (
194327  p_application_id  => p_application_id
194328  ,p_event_id     => l_event_id
194329  ,p_calculate_acctd_flag => l_calculate_acctd_flag
194330  ,p_calculate_g_l_flag => l_calculate_g_l_flag
194331  ,p_actual_flag => l_actual_flag
194332  ,p_balance_type_code => l_balance_type_code
194333  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
194334  
194335  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
194336  , p_source_3 => l_array_source_3(Idx)
194337  , p_source_7 => l_array_source_7(Idx)
194338  , p_source_29 => l_array_source_29(Idx)
194339  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
194340  , p_source_35 => l_array_source_35(Idx)
194341  , p_source_36 => l_array_source_36(Idx)
194342  , p_source_37 => l_array_source_37(Idx)
194343  , p_source_38 => l_array_source_38(Idx)
194344  , p_source_39 => l_array_source_39(Idx)
194345  , p_source_40 => l_array_source_40(Idx)
194346  , p_source_42 => l_array_source_42(Idx)
194347  );
194348 If(l_balance_type_code = 'A') THEN
194349   l_actual_gain_loss_ref := l_gain_or_loss_ref;
194350 END IF;
194351 
194352 --
194353 
194354 
194355 --
194356 AcctLineType_340 (
194357  p_application_id  => p_application_id
194358  ,p_event_id     => l_event_id
194359  ,p_calculate_acctd_flag => l_calculate_acctd_flag
194360  ,p_calculate_g_l_flag => l_calculate_g_l_flag
194361  ,p_actual_flag => l_actual_flag
194362  ,p_balance_type_code => l_balance_type_code
194363  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
194364  
194365  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
194366  , p_source_3 => l_array_source_3(Idx)
194367  , p_source_5 => l_array_source_5(Idx)
194368  , p_source_6 => l_array_source_6(Idx)
194369  , p_source_29 => l_array_source_29(Idx)
194370  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
194371  , p_source_35 => l_array_source_35(Idx)
194372  , p_source_36 => l_array_source_36(Idx)
194373  , p_source_37 => l_array_source_37(Idx)
194374  , p_source_38 => l_array_source_38(Idx)
194375  , p_source_39 => l_array_source_39(Idx)
194376  , p_source_40 => l_array_source_40(Idx)
194377  , p_source_42 => l_array_source_42(Idx)
194378  );
194379 If(l_balance_type_code = 'A') THEN
194380   l_actual_gain_loss_ref := l_gain_or_loss_ref;
194381 END IF;
194382 
194383 --
194384 
194385 
194386 --
194387 AcctLineType_341 (
194388  p_application_id  => p_application_id
194389  ,p_event_id     => l_event_id
194390  ,p_calculate_acctd_flag => l_calculate_acctd_flag
194391  ,p_calculate_g_l_flag => l_calculate_g_l_flag
194392  ,p_actual_flag => l_actual_flag
194393  ,p_balance_type_code => l_balance_type_code
194394  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
194395  
194396  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
194397  , p_source_3 => l_array_source_3(Idx)
194398  , p_source_11 => l_array_source_11(Idx)
194399  , p_source_17 => l_array_source_17(Idx)
194400  , p_source_29 => l_array_source_29(Idx)
194401  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
194402  , p_source_35 => l_array_source_35(Idx)
194403  , p_source_36 => l_array_source_36(Idx)
194404  , p_source_37 => l_array_source_37(Idx)
194405  , p_source_38 => l_array_source_38(Idx)
194406  , p_source_39 => l_array_source_39(Idx)
194407  , p_source_40 => l_array_source_40(Idx)
194408  , p_source_42 => l_array_source_42(Idx)
194409  );
194410 If(l_balance_type_code = 'A') THEN
194411   l_actual_gain_loss_ref := l_gain_or_loss_ref;
194412 END IF;
194413 
194414 --
194415 
194416 
194417 --
194418 AcctLineType_353 (
194419  p_application_id  => p_application_id
194420  ,p_event_id     => l_event_id
194421  ,p_calculate_acctd_flag => l_calculate_acctd_flag
194422  ,p_calculate_g_l_flag => l_calculate_g_l_flag
194423  ,p_actual_flag => l_actual_flag
194424  ,p_balance_type_code => l_balance_type_code
194425  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
194426  
194427  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
194428  , p_source_3 => l_array_source_3(Idx)
194429  , p_source_7 => l_array_source_7(Idx)
194430  , p_source_29 => l_array_source_29(Idx)
194431  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
194432  , p_source_35 => l_array_source_35(Idx)
194433  , p_source_36 => l_array_source_36(Idx)
194434  , p_source_37 => l_array_source_37(Idx)
194435  , p_source_38 => l_array_source_38(Idx)
194436  , p_source_39 => l_array_source_39(Idx)
194437  , p_source_40 => l_array_source_40(Idx)
194438  , p_source_42 => l_array_source_42(Idx)
194439  );
194440 If(l_balance_type_code = 'A') THEN
194441   l_actual_gain_loss_ref := l_gain_or_loss_ref;
194442 END IF;
194443 
194447 --
194444 --
194445 
194446 
194448 AcctLineType_355 (
194449  p_application_id  => p_application_id
194450  ,p_event_id     => l_event_id
194451  ,p_calculate_acctd_flag => l_calculate_acctd_flag
194452  ,p_calculate_g_l_flag => l_calculate_g_l_flag
194453  ,p_actual_flag => l_actual_flag
194454  ,p_balance_type_code => l_balance_type_code
194455  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
194456  
194457  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
194458  , p_source_3 => l_array_source_3(Idx)
194459  , p_source_5 => l_array_source_5(Idx)
194460  , p_source_6 => l_array_source_6(Idx)
194461  , p_source_29 => l_array_source_29(Idx)
194462  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
194463  , p_source_35 => l_array_source_35(Idx)
194464  , p_source_36 => l_array_source_36(Idx)
194465  , p_source_37 => l_array_source_37(Idx)
194466  , p_source_38 => l_array_source_38(Idx)
194467  , p_source_39 => l_array_source_39(Idx)
194468  , p_source_40 => l_array_source_40(Idx)
194469  , p_source_42 => l_array_source_42(Idx)
194470  );
194471 If(l_balance_type_code = 'A') THEN
194472   l_actual_gain_loss_ref := l_gain_or_loss_ref;
194473 END IF;
194474 
194475 --
194476 
194477 
194478 --
194479 AcctLineType_356 (
194480  p_application_id  => p_application_id
194481  ,p_event_id     => l_event_id
194482  ,p_calculate_acctd_flag => l_calculate_acctd_flag
194483  ,p_calculate_g_l_flag => l_calculate_g_l_flag
194484  ,p_actual_flag => l_actual_flag
194485  ,p_balance_type_code => l_balance_type_code
194486  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
194487  
194488  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
194489  , p_source_3 => l_array_source_3(Idx)
194490  , p_source_11 => l_array_source_11(Idx)
194491  , p_source_17 => l_array_source_17(Idx)
194492  , p_source_29 => l_array_source_29(Idx)
194493  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
194494  , p_source_35 => l_array_source_35(Idx)
194495  , p_source_36 => l_array_source_36(Idx)
194496  , p_source_37 => l_array_source_37(Idx)
194497  , p_source_38 => l_array_source_38(Idx)
194498  , p_source_39 => l_array_source_39(Idx)
194499  , p_source_40 => l_array_source_40(Idx)
194500  , p_source_42 => l_array_source_42(Idx)
194501  );
194502 If(l_balance_type_code = 'A') THEN
194503   l_actual_gain_loss_ref := l_gain_or_loss_ref;
194504 END IF;
194505 
194506 --
194507 
194508       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
194509       -- or secondary ledger that has different currency with primary
194510       -- or alc that is calculated by sla
194511       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
194512             (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'))
194513 
194514 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
194515 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
194516           AND (l_actual_flag = 'A')) THEN
194517         XLA_AE_LINES_PKG.CreateGainOrLossLines(
194518           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
194519          ,p_application_id   => p_application_id
194520          ,p_amb_context_code => 'DEFAULT'
194521          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
194522          ,p_event_class_code => C_EVENT_CLASS_CODE
194523          ,p_event_type_code  => C_EVENT_TYPE_CODE
194524          
194525          ,p_gain_ccid        => -1
194526          ,p_loss_ccid        => -1
194527 
194528          ,p_actual_flag      => l_actual_flag
194529          ,p_enc_flag         => null
194530          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
194531          ,p_enc_g_l_ref      => null
194532          );
194533       END IF;
194534    END IF;
194535 END IF;
194536 
194537    ELSE
194538       --
194539       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
194540       --
194541       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
194542          trace
194543             (p_msg      => 'Trancaction revesal option is Y'
194544             ,p_level    => C_LEVEL_STATEMENT
194545             ,p_module   => l_log_module);
194546       END IF;
194547    END IF;
194548 
194549 END LOOP;
194550 l_result := XLA_AE_LINES_PKG.InsertLines ;
194551 end loop;
194552 close line_cur;
194553 
194554 
194555 --
194556 -- insert headers into xla_ae_headers_gt table
194557 --
194558 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
194559 
194560 -- insert into errors table here.
194561 
194562 END LOOP;
194563 
194564 --
194565 -- 4865292
194566 --
194567 -- Compare g_hdr_extract_count with event count in
194568 -- CreateHeadersAndLines.
194569 --
194570 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
194571 
194572 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
194573    trace (p_msg     => '# rows extracted from header extract objects '
194574                     || ' (running total): '
194575                     || g_hdr_extract_count
194576          ,p_level   => C_LEVEL_STATEMENT
194577          ,p_module  => l_log_module);
194578 END IF;
194579 
194580 CLOSE header_cur;
194581 --
194582 
194583 --
194584 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
194585    trace
194586       (p_msg      => 'END of EventClass_417'
194587       ,p_level    => C_LEVEL_PROCEDURE
194588       ,p_module   => l_log_module);
194589 END IF;
194590 --
194591 RETURN l_result;
194592 EXCEPTION
194593 WHEN xla_exceptions_pkg.application_exception THEN
194594    
194595 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
194596 
194597    
194601 
194598 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
194599 
194600    RAISE;
194602 WHEN NO_DATA_FOUND THEN
194603 
194604 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
194605 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
194606 
194607 FOR header_record IN header_cur
194608 LOOP
194609     l_array_header_events(header_record.event_id) := header_record.event_id;
194610 END LOOP;
194611 
194612 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
194613 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
194614 
194615 fnd_file.put_line(fnd_file.LOG, '                    ');
194616 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
194617 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
194618 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
194619 
194620 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
194621 LOOP
194622 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
194623 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
194624         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
194625 	END IF;
194626 END LOOP;
194627 
194628 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
194629 fnd_file.put_line(fnd_file.LOG, '                    ');
194630 
194631 
194632 xla_exceptions_pkg.raise_message
194633       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_417');
194634 
194635 
194636 WHEN OTHERS THEN
194637    xla_exceptions_pkg.raise_message
194638       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_417');
194639 END EventClass_417;
194640 --
194641 
194642 ---------------------------------------
194643 --
194644 -- PRIVATE PROCEDURE
194645 --         insert_sources_418
194646 --
194647 ----------------------------------------
194648 --
194649 PROCEDURE insert_sources_418(
194650                                 p_target_ledger_id       IN NUMBER
194651                               , p_language               IN VARCHAR2
194652                               , p_sla_ledger_id          IN NUMBER
194653                               , p_pad_start_date         IN DATE
194654                               , p_pad_end_date           IN DATE
194655                          )
194656 IS
194657 
194658 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_TRANSFERS_ALL';
194659 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CIP_TRANSFERS';
194660 p_apps_owner                   VARCHAR2(30);
194661 l_log_module                   VARCHAR2(240);
194662 BEGIN
194663 IF g_log_enabled THEN
194664       l_log_module := C_DEFAULT_MODULE||'.insert_sources_418';
194665 END IF;
194666 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
194667 
194668       trace
194669          (p_msg      => 'BEGIN of insert_sources_418'
194670          ,p_level    => C_LEVEL_PROCEDURE
194671          ,p_module   => l_log_module);
194672 
194673 END IF;
194674 
194675 -- select APPS owner
194676 SELECT oracle_username
194677   INTO p_apps_owner
194678   FROM fnd_oracle_userid
194679  WHERE read_only_flag = 'U'
194680 ;
194681 
194682 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
194683       trace
194684          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
194685                         ' - p_language = '||p_language||
194686                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
194687                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
194688                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
194689                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
194690          ,p_level    => C_LEVEL_STATEMENT
194691          ,p_module   => l_log_module);
194692 END IF;
194693 
194694 
194695 --
194696 INSERT INTO xla_diag_sources --hdr2
194697 (
194698         event_id
194699       , ledger_id
194700       , sla_ledger_id
194701       , description_language
194702       , object_name
194703       , object_type_code
194704       , line_number
194705       , source_application_id
194706       , source_type_code
194707       , source_code
194708       , source_value
194709       , source_meaning
194710       , created_by
194711       , creation_date
194712       , last_update_date
194713       , last_updated_by
194714       , last_update_login
194715       , program_update_date
194716       , program_application_id
194717       , program_id
194718       , request_id
194719 )
194720 SELECT
194721         event_id
194722       , p_target_ledger_id
194723       , p_sla_ledger_id
194724       , p_language
194725       , object_name
194726       , object_type_code
194727       , line_number
194728       , source_application_id
194729       , source_type_code
194730       , source_code
194731       , SUBSTR(source_value ,1,1996)
194732       , SUBSTR(source_meaning ,1,200)
194733       , xla_environment_pkg.g_Usr_Id
194734       , TRUNC(SYSDATE)
194735       , TRUNC(SYSDATE)
194736       , xla_environment_pkg.g_Usr_Id
194737       , xla_environment_pkg.g_Login_Id
194738       , TRUNC(SYSDATE)
194739       , xla_environment_pkg.g_Prog_Appl_Id
194740       , xla_environment_pkg.g_Prog_Id
194741       , xla_environment_pkg.g_Req_Id
194742   FROM (
194743        SELECT xet.event_id                  event_id
194744             , 0                          line_number
194745             , CASE r
194746                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
194747                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
194748                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
194749                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
194753                ELSE null
194750                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
194751                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
194752                 
194754               END                           object_name
194755             , CASE r
194756                 WHEN 1 THEN 'HEADER' 
194757                 WHEN 2 THEN 'HEADER' 
194758                 WHEN 3 THEN 'HEADER' 
194759                 WHEN 4 THEN 'HEADER' 
194760                 WHEN 5 THEN 'HEADER' 
194761                 WHEN 6 THEN 'HEADER' 
194762                 
194763                 ELSE null
194764               END                           object_type_code
194765             , CASE r
194766                 WHEN 1 THEN '140' 
194767                 WHEN 2 THEN '140' 
194768                 WHEN 3 THEN '140' 
194769                 WHEN 4 THEN '140' 
194770                 WHEN 5 THEN '140' 
194771                 WHEN 6 THEN '140' 
194772                 
194773                 ELSE null
194774               END                           source_application_id
194775             , 'S'             source_type_code
194776             , CASE r
194777                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
194778                 WHEN 2 THEN 'AP_INTERCOMPANY_ACCT' 
194779                 WHEN 3 THEN 'AR_INTERCOMPANY_ACCT' 
194780                 WHEN 4 THEN 'DEFAULT_CCID' 
194781                 WHEN 5 THEN 'ACCOUNTING_DATE' 
194782                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
194783                 
194784                 ELSE null
194785               END                           source_code
194786             , CASE r
194787                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
194788                 WHEN 2 THEN TO_CHAR(h1.AP_INTERCOMPANY_ACCT)
194789                 WHEN 3 THEN TO_CHAR(h1.AR_INTERCOMPANY_ACCT)
194790                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
194791                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
194792                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
194793                 
194794                 ELSE null
194795               END                           source_value
194796             , null              source_meaning
194797          FROM xla_events_gt     xet  
194798       , FA_XLA_EXT_HEADERS_B_GT  h1
194799              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
194800          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
194801            AND xet.event_class_code = C_EVENT_CLASS_CODE
194802               AND h1.event_id = xet.event_id
194803 
194804 )
194805 ;
194806 --
194807 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
194808 
194809       trace
194810          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
194811          ,p_level    => C_LEVEL_STATEMENT
194812          ,p_module   => l_log_module);
194813 
194814 END IF;
194815 --
194816 
194817 
194818 
194819 --
194820 INSERT INTO xla_diag_sources  --line2
194821 (
194822         event_id
194823       , ledger_id
194824       , sla_ledger_id
194825       , description_language
194826       , object_name
194827       , object_type_code
194828       , line_number
194829       , source_application_id
194830       , source_type_code
194831       , source_code
194832       , source_value
194833       , source_meaning
194834       , created_by
194835       , creation_date
194836       , last_update_date
194837       , last_updated_by
194838       , last_update_login
194839       , program_update_date
194840       , program_application_id
194841       , program_id
194842       , request_id
194843 )
194844 SELECT  event_id
194845       , p_target_ledger_id
194846       , p_sla_ledger_id
194847       , p_language
194848       , object_name
194849       , object_type_code
194850       , line_number
194851       , source_application_id
194852       , source_type_code
194853       , source_code
194854       , SUBSTR(source_value,1,1996)
194855       , SUBSTR(source_meaning ,1,200)
194856       , xla_environment_pkg.g_Usr_Id
194857       , TRUNC(SYSDATE)
194858       , TRUNC(SYSDATE)
194859       , xla_environment_pkg.g_Usr_Id
194860       , xla_environment_pkg.g_Login_Id
194861       , TRUNC(SYSDATE)
194862       , xla_environment_pkg.g_Prog_Appl_Id
194863       , xla_environment_pkg.g_Prog_Id
194864       , xla_environment_pkg.g_Req_Id
194865   FROM (
194866        SELECT xet.event_id                  event_id
194867             , l2.line_number                 line_number
194868             , CASE r
194869                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
194870                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
194871                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
194872                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
194873                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
194874                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
194875                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
194876                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
194877                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
194878                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
194879                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
194880                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
194881                 
194882                ELSE null
194883               END                           object_name
194884             , CASE r
194885                 WHEN 1 THEN 'LINE' 
194886                 WHEN 2 THEN 'LINE' 
194887                 WHEN 3 THEN 'LINE' 
194888                 WHEN 4 THEN 'LINE' 
194889                 WHEN 5 THEN 'LINE' 
194890                 WHEN 6 THEN 'LINE' 
194891                 WHEN 7 THEN 'LINE' 
194892                 WHEN 8 THEN 'LINE' 
194893                 WHEN 9 THEN 'LINE' 
194894                 WHEN 10 THEN 'LINE' 
194895                 WHEN 11 THEN 'LINE' 
194896                 WHEN 12 THEN 'LINE' 
194900             , CASE r
194897                 
194898                 ELSE null
194899               END                           object_type_code
194901                 WHEN 1 THEN '140' 
194902                 WHEN 2 THEN '140' 
194903                 WHEN 3 THEN '140' 
194904                 WHEN 4 THEN '140' 
194905                 WHEN 5 THEN '140' 
194906                 WHEN 6 THEN '140' 
194907                 WHEN 7 THEN '140' 
194908                 WHEN 8 THEN '140' 
194909                 WHEN 9 THEN '140' 
194910                 WHEN 10 THEN '140' 
194911                 WHEN 11 THEN '140' 
194912                 WHEN 12 THEN '140' 
194913                 
194914                 ELSE null
194915               END                           source_application_id
194916             , 'S'             source_type_code
194917             , CASE r
194918                 WHEN 1 THEN 'GENERATED_CCID' 
194919                 WHEN 2 THEN 'CIP_COST_ACCT' 
194920                 WHEN 3 THEN 'REVAL_RESERVE_ACCT' 
194921                 WHEN 4 THEN 'GENERATED_OFFSET_CCID' 
194922                 WHEN 5 THEN 'EXPENSE_ACCOUNT_CCID' 
194923                 WHEN 6 THEN 'ADJUSTMENT_TYPE' 
194924                 WHEN 7 THEN 'TRANSACTION_HEADER_ID' 
194925                 WHEN 8 THEN 'ADJUSTMENT_LINE_ID' 
194926                 WHEN 9 THEN 'DISTRIBUTION_TYPE_CODE' 
194927                 WHEN 10 THEN 'ENTERED_AMOUNT' 
194928                 WHEN 11 THEN 'CURRENCY_CODE' 
194929                 WHEN 12 THEN 'SOURCE_DEST_CODE' 
194930                 
194931                 ELSE null
194932               END                           source_code
194933             , CASE r
194934                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
194935                 WHEN 2 THEN TO_CHAR(l2.CIP_COST_ACCT)
194936                 WHEN 3 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
194937                 WHEN 4 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
194938                 WHEN 5 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
194939                 WHEN 6 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
194940                 WHEN 7 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
194941                 WHEN 8 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
194942                 WHEN 9 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
194943                 WHEN 10 THEN TO_CHAR(l2.ENTERED_AMOUNT)
194944                 WHEN 11 THEN TO_CHAR(l2.CURRENCY_CODE)
194945                 WHEN 12 THEN TO_CHAR(l2.SOURCE_DEST_CODE)
194946                 
194947                 ELSE null
194948               END                           source_value
194949             , null              source_meaning
194950          FROM  xla_events_gt     xet  
194951         , FA_XLA_EXT_LINES_B_GT  l2
194952             , (select rownum r from all_objects where rownum <= 12 and owner = p_apps_owner)
194953         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
194954           AND xet.event_class_code = C_EVENT_CLASS_CODE
194955             AND l2.event_id          = xet.event_id
194956   AND l2.ledger_id (+)  = p_sla_ledger_id
194957 
194958 )
194959 ;
194960 --
194961 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
194962 
194963       trace
194964          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
194965          ,p_level    => C_LEVEL_STATEMENT
194966          ,p_module   => l_log_module);
194967 
194968 END IF;
194969 
194970 
194971 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
194972       trace
194973          (p_msg      => 'END of insert_sources_418'
194974          ,p_level    => C_LEVEL_PROCEDURE
194975          ,p_module   => l_log_module);
194976 END IF;
194977 EXCEPTION
194978   WHEN xla_exceptions_pkg.application_exception THEN
194979       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
194980             trace
194981                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
194982                ,p_level    => C_LEVEL_EXCEPTION
194983                ,p_module   => l_log_module);
194984       END IF;
194985       RAISE;
194986   WHEN OTHERS THEN
194987       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
194988             trace
194989                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
194990                ,p_level    => C_LEVEL_EXCEPTION
194991                ,p_module   => l_log_module);
194992        END IF;
194993        xla_exceptions_pkg.raise_message
194994            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_418');
194995 END insert_sources_418;
194996 --
194997 
194998 ---------------------------------------
194999 --
195000 -- PRIVATE FUNCTION
195001 --         EventClass_418
195002 --
195003 ----------------------------------------
195004 --
195005 FUNCTION EventClass_418
195006        (p_application_id         IN NUMBER
195007        ,p_base_ledger_id         IN NUMBER
195008        ,p_target_ledger_id       IN NUMBER
195009        ,p_language               IN VARCHAR2
195010        ,p_currency_code          IN VARCHAR2
195011        ,p_sla_ledger_id          IN NUMBER
195012        ,p_pad_start_date         IN DATE
195013        ,p_pad_end_date           IN DATE
195014        ,p_primary_ledger_id      IN NUMBER)
195015 RETURN BOOLEAN IS
195016 --
195017 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_TRANSFERS_ALL';
195018 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CIP_TRANSFERS';
195019 
195020 l_calculate_acctd_flag   VARCHAR2(1) :='N';
195021 l_calculate_g_l_flag     VARCHAR2(1) :='N';
195022 --
195023 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
195024 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
195025 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
195026 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
195027 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
195028 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
195032 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
195029 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
195030 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
195031 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
195033 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
195034 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
195035 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
195036 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
195037 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
195038 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
195039 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
195040 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
195041 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
195042 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
195043 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
195044 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
195045 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
195046 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
195047 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
195048 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
195049 
195050 l_event_id                             NUMBER;
195051 l_previous_event_id                    NUMBER;
195052 l_first_event_id                       NUMBER;
195053 l_last_event_id                        NUMBER;
195054 
195055 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
195056 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
195057 --
195058 --
195059 l_result                    BOOLEAN := TRUE;
195060 l_rows                      NUMBER  := 1000;
195061 l_event_type_name           VARCHAR2(80) := 'All';
195062 l_event_class_name          VARCHAR2(80) := 'CIP Transfers';
195063 l_description               VARCHAR2(4000);
195064 l_transaction_reversal      NUMBER;
195065 l_ae_header_id              NUMBER;
195066 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
195067 l_log_module                VARCHAR2(240);
195068 --
195069 l_acct_reversal_source      VARCHAR2(30);
195070 l_trx_reversal_source       VARCHAR2(30);
195071 
195072 l_continue_with_lines       BOOLEAN := TRUE;
195073 --
195074 l_acc_rev_gl_date_source    DATE;                      -- 4262811
195075 --
195076 type t_array_event_id is table of number index by binary_integer;
195077 
195078 l_rec_array_event                    t_rec_array_event;
195079 l_null_rec_array_event               t_rec_array_event;
195080 l_array_ae_header_id                 xla_number_array_type;
195081 l_actual_flag                        VARCHAR2(1) := NULL;
195082 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
195083 l_balance_type_code                  VARCHAR2(1) :=NULL;
195084 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
195085 
195086 --
195087 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
195088 --
195089 
195090 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
195091 TYPE t_array_source_19 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AP_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
195092 TYPE t_array_source_20 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AR_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
195093 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
195094 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
195095 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
195096 
195097 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
195098 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
195099 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
195100 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
195101 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
195102 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
195103 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
195104 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
195105 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
195106 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
195107 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
195108 TYPE t_array_source_42 IS TABLE OF FA_XLA_EXT_LINES_B_GT.SOURCE_DEST_CODE%TYPE INDEX BY BINARY_INTEGER;
195109 
195110 l_array_source_1              t_array_source_1;
195111 l_array_source_19              t_array_source_19;
195112 l_array_source_20              t_array_source_20;
195113 l_array_source_30              t_array_source_30;
195114 l_array_source_51              t_array_source_51;
195115 l_array_source_52              t_array_source_52;
195116 
195117 l_array_source_3      t_array_source_3;
195118 l_array_source_7      t_array_source_7;
195119 l_array_source_11      t_array_source_11;
195120 l_array_source_17      t_array_source_17;
195121 l_array_source_29      t_array_source_29;
195122 l_array_source_35      t_array_source_35;
195123 l_array_source_36      t_array_source_36;
195124 l_array_source_37      t_array_source_37;
195125 l_array_source_38      t_array_source_38;
195129 
195126 l_array_source_39      t_array_source_39;
195127 l_array_source_40      t_array_source_40;
195128 l_array_source_42      t_array_source_42;
195130 --
195131 CURSOR header_cur
195132 IS
195133 SELECT /*+ leading(xet) cardinality(xet,1) */
195134 -- Event Class Code: CIP_TRANSFERS
195135     xet.entity_id
195136    ,xet.legal_entity_id
195137    ,xet.entity_code
195138    ,xet.transaction_number
195139    ,xet.event_id
195140    ,xet.event_class_code
195141    ,xet.event_type_code
195142    ,xet.event_number
195143    ,xet.event_date
195144    ,xet.transaction_date
195145    ,xet.reference_num_1
195146    ,xet.reference_num_2
195147    ,xet.reference_num_3
195148    ,xet.reference_num_4
195149    ,xet.reference_char_1
195150    ,xet.reference_char_2
195151    ,xet.reference_char_3
195152    ,xet.reference_char_4
195153    ,xet.reference_date_1
195154    ,xet.reference_date_2
195155    ,xet.reference_date_3
195156    ,xet.reference_date_4
195157    ,xet.event_created_by
195158    ,xet.budgetary_control_flag 
195159   , h1.PERIOD_CLOSE_DATE    source_1
195160   , h1.AP_INTERCOMPANY_ACCT    source_19
195161   , h1.AR_INTERCOMPANY_ACCT    source_20
195162   , h1.DEFAULT_CCID    source_30
195163   , h1.ACCOUNTING_DATE    source_51
195164   , h1.TRANSFER_TO_GL_FLAG    source_52
195165   FROM xla_events_gt     xet 
195166   , FA_XLA_EXT_HEADERS_B_GT  h1
195167  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
195168    and xet.event_class_code = C_EVENT_CLASS_CODE
195169    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
195170 
195171  ORDER BY event_id
195172 ;
195173 
195174 
195175 --
195176 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
195177 IS
195178 SELECT  /*+ leading(xet) cardinality(xet,1) */
195179 -- Event Class Code: CIP_TRANSFERS
195180     xet.entity_id
195181    ,xet.legal_entity_id
195182    ,xet.entity_code
195183    ,xet.transaction_number
195184    ,xet.event_id
195185    ,xet.event_class_code
195186    ,xet.event_type_code
195187    ,xet.event_number
195188    ,xet.event_date
195189    ,xet.transaction_date
195190    ,xet.reference_num_1
195191    ,xet.reference_num_2
195192    ,xet.reference_num_3
195193    ,xet.reference_num_4
195194    ,xet.reference_char_1
195195    ,xet.reference_char_2
195196    ,xet.reference_char_3
195197    ,xet.reference_char_4
195198    ,xet.reference_date_1
195199    ,xet.reference_date_2
195200    ,xet.reference_date_3
195201    ,xet.reference_date_4
195202    ,xet.event_created_by
195203    ,xet.budgetary_control_flag
195204  , l2.LINE_NUMBER  
195205   , l2.GENERATED_CCID    source_3
195206   , l2.CIP_COST_ACCT    source_7
195207   , l2.REVAL_RESERVE_ACCT    source_11
195208   , l2.GENERATED_OFFSET_CCID    source_17
195209   , l2.EXPENSE_ACCOUNT_CCID    source_29
195210   , l2.ADJUSTMENT_TYPE    source_35
195211   , l2.TRANSACTION_HEADER_ID    source_36
195212   , l2.ADJUSTMENT_LINE_ID    source_37
195213   , l2.DISTRIBUTION_TYPE_CODE    source_38
195214   , l2.ENTERED_AMOUNT    source_39
195215   , l2.CURRENCY_CODE    source_40
195216   , l2.SOURCE_DEST_CODE    source_42
195217   FROM xla_events_gt     xet 
195218   , FA_XLA_EXT_LINES_B_GT  l2
195219  WHERE xet.event_id between x_first_event_id and x_last_event_id
195220    and xet.event_date between p_pad_start_date and p_pad_end_date
195221    and xet.event_class_code = C_EVENT_CLASS_CODE
195222    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
195223   AND l2.ledger_id = p_sla_ledger_id
195224 ;
195225 
195226 --
195227 BEGIN
195228 IF g_log_enabled THEN
195229    l_log_module := C_DEFAULT_MODULE||'.EventClass_418';
195230 END IF;
195231 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
195232    trace
195233       (p_msg      => 'BEGIN of EventClass_418'
195234       ,p_level    => C_LEVEL_PROCEDURE
195235       ,p_module   => l_log_module);
195236 END IF;
195237 
195238 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
195239    trace
195240       (p_msg      => 'p_application_id = '||p_application_id||
195241                      ' - p_base_ledger_id = '||p_base_ledger_id||
195242                      ' - p_target_ledger_id  = '||p_target_ledger_id||
195243                      ' - p_language = '||p_language||
195244                      ' - p_currency_code = '||p_currency_code||
195245                      ' - p_sla_ledger_id = '||p_sla_ledger_id
195246       ,p_level    => C_LEVEL_STATEMENT
195247       ,p_module   => l_log_module);
195248 END IF;
195249 --
195250 -- initialze arrays
195251 --
195252 g_array_event.DELETE;
195253 l_rec_array_event := l_null_rec_array_event;
195254 --
195255 --------------------------------------
195256 -- 4262811 Initialze MPA Line Number
195257 --------------------------------------
195258 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
195259 
195260 --
195261 
195262 --
195263 OPEN header_cur;
195264 --
195265 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
195266    trace
195267    (p_msg      => 'SQL - FETCH header_cur'
195268    ,p_level    => C_LEVEL_STATEMENT
195269    ,p_module   => l_log_module);
195270 END IF;
195271 --
195272 LOOP
195273 FETCH header_cur BULK COLLECT INTO
195274         l_array_entity_id
195275       , l_array_legal_entity_id
195276       , l_array_entity_code
195277       , l_array_transaction_num
195278       , l_array_event_id
195279       , l_array_class_code
195280       , l_array_event_type
195281       , l_array_event_number
195282       , l_array_event_date
195283       , l_array_transaction_date
195284       , l_array_reference_num_1
195285       , l_array_reference_num_2
195286       , l_array_reference_num_3
195287       , l_array_reference_num_4
195288       , l_array_reference_char_1
195289       , l_array_reference_char_2
195293       , l_array_reference_date_2
195290       , l_array_reference_char_3
195291       , l_array_reference_char_4
195292       , l_array_reference_date_1
195294       , l_array_reference_date_3
195295       , l_array_reference_date_4
195296       , l_array_event_created_by
195297       , l_array_budgetary_control_flag 
195298       , l_array_source_1
195299       , l_array_source_19
195300       , l_array_source_20
195301       , l_array_source_30
195302       , l_array_source_51
195303       , l_array_source_52
195304       LIMIT l_rows;
195305 --
195306 IF (C_LEVEL_EVENT >= g_log_level) THEN
195307    trace
195308    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
195309    ,p_level    => C_LEVEL_EVENT
195310    ,p_module   => l_log_module);
195311 END IF;
195312 --
195313 EXIT WHEN l_array_entity_id.COUNT = 0;
195314 
195315 -- initialize arrays
195316 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
195317 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
195318 
195319 --
195320 -- Bug 4458708
195321 --
195322 XLA_AE_LINES_PKG.g_LineNumber := 0;
195323 
195324 
195325 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
195326 g_last_hdr_idx := l_array_event_id.LAST;
195327 --
195328 -- loop for the headers. Each iteration is for each header extract row
195329 -- fetched in header cursor
195330 --
195331 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
195332 
195333 --
195334 -- set event info as cache for other routines to refer event attributes
195335 --
195336 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
195337    (p_application_id           => p_application_id
195338    ,p_primary_ledger_id        => p_primary_ledger_id
195339    ,p_base_ledger_id           => p_base_ledger_id
195340    ,p_target_ledger_id         => p_target_ledger_id
195341    ,p_entity_id                => l_array_entity_id(hdr_idx)
195342    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
195343    ,p_entity_code              => l_array_entity_code(hdr_idx)
195344    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
195345    ,p_event_id                 => l_array_event_id(hdr_idx)
195346    ,p_event_class_code         => l_array_class_code(hdr_idx)
195347    ,p_event_type_code          => l_array_event_type(hdr_idx)
195348    ,p_event_number             => l_array_event_number(hdr_idx)
195349    ,p_event_date               => l_array_event_date(hdr_idx)
195350    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
195351    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
195352    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
195353    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
195354    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
195355    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
195356    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
195357    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
195358    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
195359    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
195360    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
195361    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
195362    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
195363    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
195364    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
195365 
195366 --
195367 -- set the status of entry to C_VALID (0)
195368 --
195369 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
195370 
195371 --
195372 -- initialize a row for ae header
195373 --
195374 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
195375 
195376 l_event_id := l_array_event_id(hdr_idx);
195377 
195378 --
195379 -- storing the hdr_idx for event. May be used by line cursor.
195380 --
195381 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
195382 
195383 --
195384 -- store sources from header extract. This can be improved to
195385 -- store only those sources from header extract that may be used in lines
195386 --
195387 
195388 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
195389 g_array_event(l_event_id).array_value_char('source_19') := l_array_source_19(hdr_idx);
195390 g_array_event(l_event_id).array_value_char('source_20') := l_array_source_20(hdr_idx);
195391 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
195392 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
195393 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
195394 
195395 --
195396 -- initilaize the status of ae headers for diffrent balance types
195397 -- the status is initialised to C_NOT_CREATED (2)
195398 --
195399 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
195400 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
195401 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
195402 
195403 --
195404 -- call api to validate and store accounting attributes for header
195405 --
195406 
195407 ------------------------------------------------------------
195408 -- Accrual Reversal : to get date for Standard Source (NONE)
195409 ------------------------------------------------------------
195410 l_acc_rev_gl_date_source := NULL;
195411 
195412      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
195413       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
195414      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
195415       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
195419 
195416 
195417 
195418 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
195420 XLA_AE_HEADER_PKG.SetJeCategoryName;
195421 
195422 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
195423 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
195424 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
195425 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
195426 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
195427 
195428 
195429 --
195430 xla_ae_header_pkg.SetHdrDescription(
195431    p_description => Description_1 (
195432    p_application_id => p_application_id 
195433  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
195434    )
195435 );
195436 --
195437 
195438 -- No header level analytical criteria
195439 
195440 --
195441 --accounting attribute enhancement, bug 3612931
195442 --
195443 l_trx_reversal_source := SUBSTR(NULL, 1,30);
195444 
195445 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
195446    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
195447 
195448    xla_accounting_err_pkg.build_message
195449       (p_appli_s_name            => 'XLA'
195450       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
195451       ,p_token_1                 => 'ACCT_ATTR_NAME'
195452       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
195453       ,p_token_2                 => 'PRODUCT_NAME'
195454       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
195455       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
195456       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
195457       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
195458 
195459 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
195460    --
195461    -- following sets the accounting attributes needed to reverse
195462    -- accounting for a distributeion
195463    --
195464    xla_ae_lines_pkg.SetTrxReversalAttrs
195465       (p_event_id              => l_event_id
195466       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
195467       ,p_trx_reversal_source   => l_trx_reversal_source);
195468 
195469 END IF;
195470 
195471 
195472 ----------------------------------------------------------------
195473 -- 4262811 -  update the header statuses to invalid in need be
195474 ----------------------------------------------------------------
195475 --
195476 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
195477 
195478 
195479   -----------------------------------------------
195480   -- No accrual reversal for the event class/type
195481   -----------------------------------------------
195482 ----------------------------------------------------------------
195483 
195484 --
195485 -- this ends the header loop iteration for one bulk fetch
195486 --
195487 END LOOP;
195488 
195489 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
195490 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
195491 
195492 --
195493 -- insert dummy rows into lines gt table that were created due to
195494 -- transaction reversals
195495 --
195496 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
195497    l_result := XLA_AE_LINES_PKG.InsertLines;
195498 END IF;
195499 
195500 --
195501 -- reset the temp_line_num for each set of events fetched from header
195502 -- cursor rather than doing it for each new event in line cursor
195503 -- Bug 3939231
195504 --
195505 xla_ae_lines_pkg.g_temp_line_num := 0;
195506 
195507 
195508 
195509 --
195510 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
195511 --
195512 --
195513 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
195514 
195515       trace
195516          (p_msg      => 'SQL - FETCH line_cur'
195517          ,p_level    => C_LEVEL_STATEMENT
195518          ,p_module   => l_log_module);
195519 
195520 END IF;
195521 --
195522 --
195523 LOOP
195524   --
195525   FETCH line_cur BULK COLLECT INTO
195526         l_array_entity_id
195527       , l_array_legal_entity_id
195528       , l_array_entity_code
195529       , l_array_transaction_num
195530       , l_array_event_id
195531       , l_array_class_code
195532       , l_array_event_type
195533       , l_array_event_number
195534       , l_array_event_date
195535       , l_array_transaction_date
195536       , l_array_reference_num_1
195537       , l_array_reference_num_2
195538       , l_array_reference_num_3
195539       , l_array_reference_num_4
195540       , l_array_reference_char_1
195541       , l_array_reference_char_2
195542       , l_array_reference_char_3
195543       , l_array_reference_char_4
195544       , l_array_reference_date_1
195545       , l_array_reference_date_2
195546       , l_array_reference_date_3
195547       , l_array_reference_date_4
195548       , l_array_event_created_by
195549       , l_array_budgetary_control_flag
195550       , l_array_extract_line_num 
195551       , l_array_source_3
195552       , l_array_source_7
195553       , l_array_source_11
195554       , l_array_source_17
195555       , l_array_source_29
195556       , l_array_source_35
195557       , l_array_source_36
195558       , l_array_source_37
195559       , l_array_source_38
195560       , l_array_source_39
195561       , l_array_source_40
195562       , l_array_source_42
195563       LIMIT l_rows;
195564 
195565   --
195566   IF (C_LEVEL_EVENT >= g_log_level) THEN
195567             trace
195571   END IF;
195568                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
195569                ,p_level    => C_LEVEL_EVENT
195570                ,p_module   => l_log_module);
195572   --
195573   EXIT WHEN l_array_entity_id.count = 0;
195574 
195575   XLA_AE_LINES_PKG.g_rec_lines := null;
195576 
195577 --
195578 -- Bug 4458708
195579 --
195580 XLA_AE_LINES_PKG.g_LineNumber := 0;
195581 --
195582 --
195583 
195584 FOR Idx IN 1..l_array_event_id.count LOOP
195585    --
195586    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
195587    --
195588    l_event_id := l_array_event_id(idx);  -- 5648433
195589 
195590    --
195591    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
195592    --
195593 
195594    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
195595              (g_array_event(l_event_id).array_value_num('header_index'))
195596          ,'N'
195597          ) <> 'Y'
195598    THEN
195599       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
195600          trace
195601             (p_msg      => 'Trancaction revesal option is not Y '
195602             ,p_level    => C_LEVEL_STATEMENT
195603             ,p_module   => l_log_module);
195604       END IF;
195605 
195606 --
195607 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
195608 --
195609 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
195610 --
195611 -- set event info as cache for other routines to refer event attributes
195612 --
195613 
195614 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
195615    l_previous_event_id := l_event_id;
195616 
195617    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
195618       (p_application_id           => p_application_id
195619       ,p_primary_ledger_id        => p_primary_ledger_id
195620       ,p_base_ledger_id           => p_base_ledger_id
195621       ,p_target_ledger_id         => p_target_ledger_id
195622       ,p_entity_id                => l_array_entity_id(Idx)
195623       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
195624       ,p_entity_code              => l_array_entity_code(Idx)
195625       ,p_transaction_num          => l_array_transaction_num(Idx)
195626       ,p_event_id                 => l_array_event_id(Idx)
195627       ,p_event_class_code         => l_array_class_code(Idx)
195628       ,p_event_type_code          => l_array_event_type(Idx)
195629       ,p_event_number             => l_array_event_number(Idx)
195630       ,p_event_date               => l_array_event_date(Idx)
195631       ,p_transaction_date         => l_array_transaction_date(Idx)
195632       ,p_reference_num_1          => l_array_reference_num_1(Idx)
195633       ,p_reference_num_2          => l_array_reference_num_2(Idx)
195634       ,p_reference_num_3          => l_array_reference_num_3(Idx)
195635       ,p_reference_num_4          => l_array_reference_num_4(Idx)
195636       ,p_reference_char_1         => l_array_reference_char_1(Idx)
195637       ,p_reference_char_2         => l_array_reference_char_2(Idx)
195638       ,p_reference_char_3         => l_array_reference_char_3(Idx)
195639       ,p_reference_char_4         => l_array_reference_char_4(Idx)
195640       ,p_reference_date_1         => l_array_reference_date_1(Idx)
195641       ,p_reference_date_2         => l_array_reference_date_2(Idx)
195642       ,p_reference_date_3         => l_array_reference_date_3(Idx)
195643       ,p_reference_date_4         => l_array_reference_date_4(Idx)
195644       ,p_event_created_by         => l_array_event_created_by(Idx)
195645       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
195646        --
195647 END IF;
195648 
195649 
195650 
195651 --
195652 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
195653 
195654 l_acct_reversal_source := SUBSTR(NULL, 1,30);
195655 
195656 IF l_continue_with_lines THEN
195657    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
195658       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
195659 
195660       xla_accounting_err_pkg.build_message
195661          (p_appli_s_name            => 'XLA'
195662          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
195663          ,p_token_1                 => 'LINE_NUMBER'
195664          ,p_value_1                 => l_array_extract_line_num(Idx)
195665          ,p_token_2                 => 'PRODUCT_NAME'
195666          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
195667          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
195668          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
195669          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
195670 
195671    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
195672       --
195673       -- following sets the accounting attributes needed to reverse
195674       -- accounting for a distributeion
195675       --
195676 
195677       --
195678       -- 5217187
195679       --
195680       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
195681       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
195682                                        g_array_event(l_event_id).array_value_num('header_index'));
195683       --
195684       --
195685 
195686       -- No reversal code generated
195687 
195688       xla_ae_lines_pkg.SetAcctReversalAttrs
195689          (p_event_id             => l_event_id
195690          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
195691          ,p_calculate_acctd_flag => l_calculate_acctd_flag
195692          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
195693    END IF;
195694 
195695    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
195696        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
195700  p_application_id  => p_application_id
195697 
195698 --
195699 AcctLineType_241 (
195701  ,p_event_id     => l_event_id
195702  ,p_calculate_acctd_flag => l_calculate_acctd_flag
195703  ,p_calculate_g_l_flag => l_calculate_g_l_flag
195704  ,p_actual_flag => l_actual_flag
195705  ,p_balance_type_code => l_balance_type_code
195706  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
195707  
195708  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
195709  , p_source_3 => l_array_source_3(Idx)
195710  , p_source_7 => l_array_source_7(Idx)
195711  , p_source_29 => l_array_source_29(Idx)
195712  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
195713  , p_source_35 => l_array_source_35(Idx)
195714  , p_source_36 => l_array_source_36(Idx)
195715  , p_source_37 => l_array_source_37(Idx)
195716  , p_source_38 => l_array_source_38(Idx)
195717  , p_source_39 => l_array_source_39(Idx)
195718  , p_source_40 => l_array_source_40(Idx)
195719  , p_source_42 => l_array_source_42(Idx)
195720  );
195721 If(l_balance_type_code = 'A') THEN
195722   l_actual_gain_loss_ref := l_gain_or_loss_ref;
195723 END IF;
195724 
195725 --
195726 
195727 
195728 --
195729 AcctLineType_242 (
195730  p_application_id  => p_application_id
195731  ,p_event_id     => l_event_id
195732  ,p_calculate_acctd_flag => l_calculate_acctd_flag
195733  ,p_calculate_g_l_flag => l_calculate_g_l_flag
195734  ,p_actual_flag => l_actual_flag
195735  ,p_balance_type_code => l_balance_type_code
195736  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
195737  
195738  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
195739  , p_source_3 => l_array_source_3(Idx)
195740  , p_source_11 => l_array_source_11(Idx)
195741  , p_source_17 => l_array_source_17(Idx)
195742  , p_source_29 => l_array_source_29(Idx)
195743  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
195744  , p_source_35 => l_array_source_35(Idx)
195745  , p_source_36 => l_array_source_36(Idx)
195746  , p_source_37 => l_array_source_37(Idx)
195747  , p_source_38 => l_array_source_38(Idx)
195748  , p_source_39 => l_array_source_39(Idx)
195749  , p_source_40 => l_array_source_40(Idx)
195750  , p_source_42 => l_array_source_42(Idx)
195751  );
195752 If(l_balance_type_code = 'A') THEN
195753   l_actual_gain_loss_ref := l_gain_or_loss_ref;
195754 END IF;
195755 
195756 --
195757 
195758 
195759 --
195760 AcctLineType_243 (
195761  p_application_id  => p_application_id
195762  ,p_event_id     => l_event_id
195763  ,p_calculate_acctd_flag => l_calculate_acctd_flag
195764  ,p_calculate_g_l_flag => l_calculate_g_l_flag
195765  ,p_actual_flag => l_actual_flag
195766  ,p_balance_type_code => l_balance_type_code
195767  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
195768  
195769  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
195770  , p_source_3 => l_array_source_3(Idx)
195771  , p_source_19 => g_array_event(l_event_id).array_value_char('source_19')
195772  , p_source_29 => l_array_source_29(Idx)
195773  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
195774  , p_source_35 => l_array_source_35(Idx)
195775  , p_source_36 => l_array_source_36(Idx)
195776  , p_source_37 => l_array_source_37(Idx)
195780  );
195777  , p_source_38 => l_array_source_38(Idx)
195778  , p_source_39 => l_array_source_39(Idx)
195779  , p_source_40 => l_array_source_40(Idx)
195781 If(l_balance_type_code = 'A') THEN
195782   l_actual_gain_loss_ref := l_gain_or_loss_ref;
195783 END IF;
195784 
195785 --
195786 
195787 
195788 --
195789 AcctLineType_244 (
195790  p_application_id  => p_application_id
195791  ,p_event_id     => l_event_id
195792  ,p_calculate_acctd_flag => l_calculate_acctd_flag
195793  ,p_calculate_g_l_flag => l_calculate_g_l_flag
195794  ,p_actual_flag => l_actual_flag
195795  ,p_balance_type_code => l_balance_type_code
195796  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
195797  
195798  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
195799  , p_source_3 => l_array_source_3(Idx)
195800  , p_source_20 => g_array_event(l_event_id).array_value_char('source_20')
195801  , p_source_29 => l_array_source_29(Idx)
195802  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
195803  , p_source_35 => l_array_source_35(Idx)
195804  , p_source_36 => l_array_source_36(Idx)
195805  , p_source_37 => l_array_source_37(Idx)
195806  , p_source_38 => l_array_source_38(Idx)
195807  , p_source_39 => l_array_source_39(Idx)
195808  , p_source_40 => l_array_source_40(Idx)
195809  );
195810 If(l_balance_type_code = 'A') THEN
195811   l_actual_gain_loss_ref := l_gain_or_loss_ref;
195812 END IF;
195813 
195814 --
195815 
195816 
195817 --
195818 AcctLineType_245 (
195819  p_application_id  => p_application_id
195823  ,p_actual_flag => l_actual_flag
195820  ,p_event_id     => l_event_id
195821  ,p_calculate_acctd_flag => l_calculate_acctd_flag
195822  ,p_calculate_g_l_flag => l_calculate_g_l_flag
195824  ,p_balance_type_code => l_balance_type_code
195825  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
195826  
195827  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
195828  , p_source_3 => l_array_source_3(Idx)
195829  , p_source_7 => l_array_source_7(Idx)
195830  , p_source_29 => l_array_source_29(Idx)
195831  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
195832  , p_source_35 => l_array_source_35(Idx)
195833  , p_source_36 => l_array_source_36(Idx)
195834  , p_source_37 => l_array_source_37(Idx)
195835  , p_source_38 => l_array_source_38(Idx)
195836  , p_source_39 => l_array_source_39(Idx)
195837  , p_source_40 => l_array_source_40(Idx)
195838  , p_source_42 => l_array_source_42(Idx)
195839  );
195840 If(l_balance_type_code = 'A') THEN
195841   l_actual_gain_loss_ref := l_gain_or_loss_ref;
195842 END IF;
195843 
195844 --
195845 
195846 
195847 --
195848 AcctLineType_246 (
195849  p_application_id  => p_application_id
195850  ,p_event_id     => l_event_id
195851  ,p_calculate_acctd_flag => l_calculate_acctd_flag
195852  ,p_calculate_g_l_flag => l_calculate_g_l_flag
195853  ,p_actual_flag => l_actual_flag
195854  ,p_balance_type_code => l_balance_type_code
195855  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
195856  
195857  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
195858  , p_source_3 => l_array_source_3(Idx)
195859  , p_source_11 => l_array_source_11(Idx)
195860  , p_source_17 => l_array_source_17(Idx)
195861  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
195862  , p_source_35 => l_array_source_35(Idx)
195863  , p_source_36 => l_array_source_36(Idx)
195864  , p_source_37 => l_array_source_37(Idx)
195865  , p_source_38 => l_array_source_38(Idx)
195866  , p_source_39 => l_array_source_39(Idx)
195867  , p_source_40 => l_array_source_40(Idx)
195868  , p_source_42 => l_array_source_42(Idx)
195869  );
195870 If(l_balance_type_code = 'A') THEN
195871   l_actual_gain_loss_ref := l_gain_or_loss_ref;
195872 END IF;
195873 
195874 --
195875 
195876       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
195877       -- or secondary ledger that has different currency with primary
195878       -- or alc that is calculated by sla
195879       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
195880             (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'))
195881 
195882 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
195883 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
195884           AND (l_actual_flag = 'A')) THEN
195885         XLA_AE_LINES_PKG.CreateGainOrLossLines(
195886           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
195887          ,p_application_id   => p_application_id
195888          ,p_amb_context_code => 'DEFAULT'
195889          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
195890          ,p_event_class_code => C_EVENT_CLASS_CODE
195891          ,p_event_type_code  => C_EVENT_TYPE_CODE
195892          
195893          ,p_gain_ccid        => -1
195894          ,p_loss_ccid        => -1
195895 
195896          ,p_actual_flag      => l_actual_flag
195897          ,p_enc_flag         => null
195898          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
195899          ,p_enc_g_l_ref      => null
195900          );
195901       END IF;
195902    END IF;
195903 END IF;
195904 
195905    ELSE
195906       --
195907       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
195908       --
195909       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
195910          trace
195911             (p_msg      => 'Trancaction revesal option is Y'
195912             ,p_level    => C_LEVEL_STATEMENT
195913             ,p_module   => l_log_module);
195914       END IF;
195915    END IF;
195916 
195917 END LOOP;
195918 l_result := XLA_AE_LINES_PKG.InsertLines ;
195919 end loop;
195920 close line_cur;
195921 
195922 
195923 --
195924 -- insert headers into xla_ae_headers_gt table
195925 --
195926 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
195927 
195928 -- insert into errors table here.
195929 
195930 END LOOP;
195931 
195932 --
195933 -- 4865292
195934 --
195935 -- Compare g_hdr_extract_count with event count in
195936 -- CreateHeadersAndLines.
195937 --
195938 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
195939 
195940 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
195941    trace (p_msg     => '# rows extracted from header extract objects '
195942                     || ' (running total): '
195943                     || g_hdr_extract_count
195944          ,p_level   => C_LEVEL_STATEMENT
195945          ,p_module  => l_log_module);
195946 END IF;
195947 
195948 CLOSE header_cur;
195949 --
195950 
195951 --
195952 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
195953    trace
195957 END IF;
195954       (p_msg      => 'END of EventClass_418'
195955       ,p_level    => C_LEVEL_PROCEDURE
195956       ,p_module   => l_log_module);
195958 --
195959 RETURN l_result;
195960 EXCEPTION
195961 WHEN xla_exceptions_pkg.application_exception THEN
195962    
195963 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
195964 
195965    
195966 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
195967 
195968    RAISE;
195969 
195970 WHEN NO_DATA_FOUND THEN
195971 
195972 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
195973 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
195974 
195975 FOR header_record IN header_cur
195976 LOOP
195977     l_array_header_events(header_record.event_id) := header_record.event_id;
195978 END LOOP;
195979 
195980 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
195981 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
195982 
195983 fnd_file.put_line(fnd_file.LOG, '                    ');
195984 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
195985 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
195986 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
195987 
195988 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
195989 LOOP
195990 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
195991 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
195992         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
195993 	END IF;
195994 END LOOP;
195995 
195996 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
195997 fnd_file.put_line(fnd_file.LOG, '                    ');
195998 
195999 
196000 xla_exceptions_pkg.raise_message
196001       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_418');
196002 
196003 
196004 WHEN OTHERS THEN
196005    xla_exceptions_pkg.raise_message
196006       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_418');
196007 END EventClass_418;
196008 --
196009 
196010 ---------------------------------------
196011 --
196012 -- PRIVATE PROCEDURE
196013 --         insert_sources_419
196014 --
196015 ----------------------------------------
196016 --
196017 PROCEDURE insert_sources_419(
196018                                 p_target_ledger_id       IN NUMBER
196019                               , p_language               IN VARCHAR2
196020                               , p_sla_ledger_id          IN NUMBER
196021                               , p_pad_start_date         IN DATE
196022                               , p_pad_end_date           IN DATE
196023                          )
196024 IS
196025 
196026 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_UNIT_ADJUSTMENTS_ALL';
196027 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CIP_UNIT_ADJUSTMENTS';
196028 p_apps_owner                   VARCHAR2(30);
196029 l_log_module                   VARCHAR2(240);
196030 BEGIN
196031 IF g_log_enabled THEN
196032       l_log_module := C_DEFAULT_MODULE||'.insert_sources_419';
196033 END IF;
196034 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
196035 
196036       trace
196037          (p_msg      => 'BEGIN of insert_sources_419'
196038          ,p_level    => C_LEVEL_PROCEDURE
196039          ,p_module   => l_log_module);
196040 
196041 END IF;
196042 
196043 -- select APPS owner
196047  WHERE read_only_flag = 'U'
196044 SELECT oracle_username
196045   INTO p_apps_owner
196046   FROM fnd_oracle_userid
196048 ;
196049 
196050 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
196051       trace
196052          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
196053                         ' - p_language = '||p_language||
196054                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
196055                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
196056                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
196057                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
196058          ,p_level    => C_LEVEL_STATEMENT
196059          ,p_module   => l_log_module);
196060 END IF;
196061 
196062 
196063 --
196064 INSERT INTO xla_diag_sources --hdr2
196065 (
196066         event_id
196067       , ledger_id
196068       , sla_ledger_id
196069       , description_language
196070       , object_name
196071       , object_type_code
196072       , line_number
196073       , source_application_id
196074       , source_type_code
196075       , source_code
196076       , source_value
196077       , source_meaning
196078       , created_by
196079       , creation_date
196080       , last_update_date
196081       , last_updated_by
196082       , last_update_login
196083       , program_update_date
196084       , program_application_id
196085       , program_id
196086       , request_id
196087 )
196088 SELECT
196089         event_id
196090       , p_target_ledger_id
196091       , p_sla_ledger_id
196092       , p_language
196093       , object_name
196094       , object_type_code
196095       , line_number
196096       , source_application_id
196097       , source_type_code
196098       , source_code
196099       , SUBSTR(source_value ,1,1996)
196100       , SUBSTR(source_meaning ,1,200)
196101       , xla_environment_pkg.g_Usr_Id
196102       , TRUNC(SYSDATE)
196103       , TRUNC(SYSDATE)
196104       , xla_environment_pkg.g_Usr_Id
196105       , xla_environment_pkg.g_Login_Id
196106       , TRUNC(SYSDATE)
196107       , xla_environment_pkg.g_Prog_Appl_Id
196108       , xla_environment_pkg.g_Prog_Id
196109       , xla_environment_pkg.g_Req_Id
196110   FROM (
196111        SELECT xet.event_id                  event_id
196112             , 0                          line_number
196113             , CASE r
196114                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
196115                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
196116                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
196117                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
196118                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
196119                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
196120                 
196121                ELSE null
196122               END                           object_name
196123             , CASE r
196124                 WHEN 1 THEN 'HEADER' 
196125                 WHEN 2 THEN 'HEADER' 
196126                 WHEN 3 THEN 'HEADER' 
196127                 WHEN 4 THEN 'HEADER' 
196128                 WHEN 5 THEN 'HEADER' 
196129                 WHEN 6 THEN 'HEADER' 
196130                 
196131                 ELSE null
196132               END                           object_type_code
196133             , CASE r
196134                 WHEN 1 THEN '140' 
196135                 WHEN 2 THEN '140' 
196136                 WHEN 3 THEN '140' 
196137                 WHEN 4 THEN '140' 
196138                 WHEN 5 THEN '140' 
196139                 WHEN 6 THEN '140' 
196140                 
196141                 ELSE null
196142               END                           source_application_id
196143             , 'S'             source_type_code
196144             , CASE r
196145                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
196146                 WHEN 2 THEN 'AP_INTERCOMPANY_ACCT' 
196147                 WHEN 3 THEN 'AR_INTERCOMPANY_ACCT' 
196148                 WHEN 4 THEN 'DEFAULT_CCID' 
196149                 WHEN 5 THEN 'ACCOUNTING_DATE' 
196150                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
196151                 
196152                 ELSE null
196153               END                           source_code
196154             , CASE r
196155                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
196156                 WHEN 2 THEN TO_CHAR(h1.AP_INTERCOMPANY_ACCT)
196157                 WHEN 3 THEN TO_CHAR(h1.AR_INTERCOMPANY_ACCT)
196158                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
196159                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
196160                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
196161                 
196162                 ELSE null
196163               END                           source_value
196164             , null              source_meaning
196165          FROM xla_events_gt     xet  
196166       , FA_XLA_EXT_HEADERS_B_GT  h1
196167              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
196168          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
196169            AND xet.event_class_code = C_EVENT_CLASS_CODE
196170               AND h1.event_id = xet.event_id
196171 
196172 )
196173 ;
196174 --
196175 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
196176 
196177       trace
196178          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
196179          ,p_level    => C_LEVEL_STATEMENT
196180          ,p_module   => l_log_module);
196181 
196182 END IF;
196183 --
196184 
196185 
196186 
196187 --
196188 INSERT INTO xla_diag_sources  --line2
196189 (
196190         event_id
196191       , ledger_id
196192       , sla_ledger_id
196193       , description_language
196194       , object_name
196195       , object_type_code
196196       , line_number
196200       , source_value
196197       , source_application_id
196198       , source_type_code
196199       , source_code
196201       , source_meaning
196202       , created_by
196203       , creation_date
196204       , last_update_date
196205       , last_updated_by
196206       , last_update_login
196207       , program_update_date
196208       , program_application_id
196209       , program_id
196210       , request_id
196211 )
196212 SELECT  event_id
196213       , p_target_ledger_id
196214       , p_sla_ledger_id
196215       , p_language
196216       , object_name
196217       , object_type_code
196218       , line_number
196219       , source_application_id
196220       , source_type_code
196221       , source_code
196222       , SUBSTR(source_value,1,1996)
196223       , SUBSTR(source_meaning ,1,200)
196224       , xla_environment_pkg.g_Usr_Id
196225       , TRUNC(SYSDATE)
196226       , TRUNC(SYSDATE)
196227       , xla_environment_pkg.g_Usr_Id
196228       , xla_environment_pkg.g_Login_Id
196229       , TRUNC(SYSDATE)
196230       , xla_environment_pkg.g_Prog_Appl_Id
196231       , xla_environment_pkg.g_Prog_Id
196232       , xla_environment_pkg.g_Req_Id
196233   FROM (
196234        SELECT xet.event_id                  event_id
196235             , l2.line_number                 line_number
196236             , CASE r
196237                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
196238                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
196239                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
196240                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
196241                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
196242                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
196243                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
196244                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
196245                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
196246                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
196247                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
196248                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
196249                 
196250                ELSE null
196251               END                           object_name
196252             , CASE r
196253                 WHEN 1 THEN 'LINE' 
196254                 WHEN 2 THEN 'LINE' 
196255                 WHEN 3 THEN 'LINE' 
196256                 WHEN 4 THEN 'LINE' 
196257                 WHEN 5 THEN 'LINE' 
196258                 WHEN 6 THEN 'LINE' 
196259                 WHEN 7 THEN 'LINE' 
196260                 WHEN 8 THEN 'LINE' 
196261                 WHEN 9 THEN 'LINE' 
196262                 WHEN 10 THEN 'LINE' 
196263                 WHEN 11 THEN 'LINE' 
196264                 WHEN 12 THEN 'LINE' 
196265                 
196266                 ELSE null
196267               END                           object_type_code
196268             , CASE r
196269                 WHEN 1 THEN '140' 
196270                 WHEN 2 THEN '140' 
196271                 WHEN 3 THEN '140' 
196272                 WHEN 4 THEN '140' 
196273                 WHEN 5 THEN '140' 
196274                 WHEN 6 THEN '140' 
196275                 WHEN 7 THEN '140' 
196276                 WHEN 8 THEN '140' 
196277                 WHEN 9 THEN '140' 
196278                 WHEN 10 THEN '140' 
196279                 WHEN 11 THEN '140' 
196280                 WHEN 12 THEN '140' 
196281                 
196282                 ELSE null
196283               END                           source_application_id
196284             , 'S'             source_type_code
196285             , CASE r
196286                 WHEN 1 THEN 'GENERATED_CCID' 
196287                 WHEN 2 THEN 'CIP_COST_ACCT' 
196288                 WHEN 3 THEN 'REVAL_RESERVE_ACCT' 
196289                 WHEN 4 THEN 'GENERATED_OFFSET_CCID' 
196290                 WHEN 5 THEN 'EXPENSE_ACCOUNT_CCID' 
196291                 WHEN 6 THEN 'ADJUSTMENT_TYPE' 
196292                 WHEN 7 THEN 'TRANSACTION_HEADER_ID' 
196293                 WHEN 8 THEN 'ADJUSTMENT_LINE_ID' 
196294                 WHEN 9 THEN 'DISTRIBUTION_TYPE_CODE' 
196295                 WHEN 10 THEN 'ENTERED_AMOUNT' 
196296                 WHEN 11 THEN 'CURRENCY_CODE' 
196297                 WHEN 12 THEN 'SOURCE_DEST_CODE' 
196298                 
196299                 ELSE null
196300               END                           source_code
196301             , CASE r
196302                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
196303                 WHEN 2 THEN TO_CHAR(l2.CIP_COST_ACCT)
196304                 WHEN 3 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
196305                 WHEN 4 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
196306                 WHEN 5 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
196307                 WHEN 6 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
196308                 WHEN 7 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
196309                 WHEN 8 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
196310                 WHEN 9 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
196311                 WHEN 10 THEN TO_CHAR(l2.ENTERED_AMOUNT)
196312                 WHEN 11 THEN TO_CHAR(l2.CURRENCY_CODE)
196313                 WHEN 12 THEN TO_CHAR(l2.SOURCE_DEST_CODE)
196314                 
196315                 ELSE null
196316               END                           source_value
196317             , null              source_meaning
196318          FROM  xla_events_gt     xet  
196319         , FA_XLA_EXT_LINES_B_GT  l2
196320             , (select rownum r from all_objects where rownum <= 12 and owner = p_apps_owner)
196321         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
196322           AND xet.event_class_code = C_EVENT_CLASS_CODE
196323             AND l2.event_id          = xet.event_id
196324   AND l2.ledger_id (+)  = p_sla_ledger_id
196325 
196326 )
196327 ;
196328 --
196329 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
196330 
196331       trace
196332          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
196336 END IF;
196333          ,p_level    => C_LEVEL_STATEMENT
196334          ,p_module   => l_log_module);
196335 
196337 
196338 
196339 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
196340       trace
196341          (p_msg      => 'END of insert_sources_419'
196342          ,p_level    => C_LEVEL_PROCEDURE
196343          ,p_module   => l_log_module);
196344 END IF;
196345 EXCEPTION
196346   WHEN xla_exceptions_pkg.application_exception THEN
196347       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
196348             trace
196349                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
196350                ,p_level    => C_LEVEL_EXCEPTION
196351                ,p_module   => l_log_module);
196352       END IF;
196353       RAISE;
196354   WHEN OTHERS THEN
196355       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
196356             trace
196357                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
196358                ,p_level    => C_LEVEL_EXCEPTION
196359                ,p_module   => l_log_module);
196360        END IF;
196361        xla_exceptions_pkg.raise_message
196362            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_419');
196363 END insert_sources_419;
196364 --
196365 
196366 ---------------------------------------
196367 --
196368 -- PRIVATE FUNCTION
196369 --         EventClass_419
196370 --
196371 ----------------------------------------
196372 --
196373 FUNCTION EventClass_419
196374        (p_application_id         IN NUMBER
196375        ,p_base_ledger_id         IN NUMBER
196376        ,p_target_ledger_id       IN NUMBER
196377        ,p_language               IN VARCHAR2
196378        ,p_currency_code          IN VARCHAR2
196379        ,p_sla_ledger_id          IN NUMBER
196380        ,p_pad_start_date         IN DATE
196381        ,p_pad_end_date           IN DATE
196382        ,p_primary_ledger_id      IN NUMBER)
196383 RETURN BOOLEAN IS
196384 --
196385 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CIP_UNIT_ADJUSTMENTS_ALL';
196386 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CIP_UNIT_ADJUSTMENTS';
196387 
196388 l_calculate_acctd_flag   VARCHAR2(1) :='N';
196389 l_calculate_g_l_flag     VARCHAR2(1) :='N';
196390 --
196391 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
196392 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
196393 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
196394 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
196395 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
196396 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
196397 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
196398 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
196399 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
196400 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
196401 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
196402 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
196403 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
196404 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
196405 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
196406 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
196407 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
196408 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
196409 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
196410 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
196411 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
196412 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
196413 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
196414 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
196415 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
196416 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
196417 
196418 l_event_id                             NUMBER;
196419 l_previous_event_id                    NUMBER;
196420 l_first_event_id                       NUMBER;
196421 l_last_event_id                        NUMBER;
196422 
196423 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
196424 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
196425 --
196426 --
196427 l_result                    BOOLEAN := TRUE;
196428 l_rows                      NUMBER  := 1000;
196429 l_event_type_name           VARCHAR2(80) := 'All';
196430 l_event_class_name          VARCHAR2(80) := 'CIP Unit Adjustments';
196431 l_description               VARCHAR2(4000);
196432 l_transaction_reversal      NUMBER;
196433 l_ae_header_id              NUMBER;
196434 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
196435 l_log_module                VARCHAR2(240);
196436 --
196437 l_acct_reversal_source      VARCHAR2(30);
196438 l_trx_reversal_source       VARCHAR2(30);
196439 
196440 l_continue_with_lines       BOOLEAN := TRUE;
196441 --
196442 l_acc_rev_gl_date_source    DATE;                      -- 4262811
196443 --
196444 type t_array_event_id is table of number index by binary_integer;
196445 
196446 l_rec_array_event                    t_rec_array_event;
196447 l_null_rec_array_event               t_rec_array_event;
196448 l_array_ae_header_id                 xla_number_array_type;
196449 l_actual_flag                        VARCHAR2(1) := NULL;
196450 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
196451 l_balance_type_code                  VARCHAR2(1) :=NULL;
196452 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
196453 
196454 --
196458 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
196455 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
196456 --
196457 
196459 TYPE t_array_source_19 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AP_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
196460 TYPE t_array_source_20 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AR_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
196461 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
196462 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
196463 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
196464 
196465 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
196466 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
196467 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
196468 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
196469 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
196470 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
196471 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
196472 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
196473 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
196474 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
196475 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
196476 TYPE t_array_source_42 IS TABLE OF FA_XLA_EXT_LINES_B_GT.SOURCE_DEST_CODE%TYPE INDEX BY BINARY_INTEGER;
196477 
196478 l_array_source_1              t_array_source_1;
196479 l_array_source_19              t_array_source_19;
196480 l_array_source_20              t_array_source_20;
196481 l_array_source_30              t_array_source_30;
196482 l_array_source_51              t_array_source_51;
196483 l_array_source_52              t_array_source_52;
196484 
196485 l_array_source_3      t_array_source_3;
196486 l_array_source_7      t_array_source_7;
196487 l_array_source_11      t_array_source_11;
196488 l_array_source_17      t_array_source_17;
196489 l_array_source_29      t_array_source_29;
196490 l_array_source_35      t_array_source_35;
196491 l_array_source_36      t_array_source_36;
196492 l_array_source_37      t_array_source_37;
196493 l_array_source_38      t_array_source_38;
196494 l_array_source_39      t_array_source_39;
196495 l_array_source_40      t_array_source_40;
196496 l_array_source_42      t_array_source_42;
196497 
196498 --
196499 CURSOR header_cur
196500 IS
196501 SELECT /*+ leading(xet) cardinality(xet,1) */
196502 -- Event Class Code: CIP_UNIT_ADJUSTMENTS
196503     xet.entity_id
196504    ,xet.legal_entity_id
196505    ,xet.entity_code
196506    ,xet.transaction_number
196507    ,xet.event_id
196508    ,xet.event_class_code
196509    ,xet.event_type_code
196510    ,xet.event_number
196511    ,xet.event_date
196512    ,xet.transaction_date
196513    ,xet.reference_num_1
196514    ,xet.reference_num_2
196515    ,xet.reference_num_3
196516    ,xet.reference_num_4
196517    ,xet.reference_char_1
196518    ,xet.reference_char_2
196519    ,xet.reference_char_3
196520    ,xet.reference_char_4
196521    ,xet.reference_date_1
196522    ,xet.reference_date_2
196523    ,xet.reference_date_3
196524    ,xet.reference_date_4
196525    ,xet.event_created_by
196526    ,xet.budgetary_control_flag 
196527   , h1.PERIOD_CLOSE_DATE    source_1
196528   , h1.AP_INTERCOMPANY_ACCT    source_19
196529   , h1.AR_INTERCOMPANY_ACCT    source_20
196530   , h1.DEFAULT_CCID    source_30
196531   , h1.ACCOUNTING_DATE    source_51
196532   , h1.TRANSFER_TO_GL_FLAG    source_52
196533   FROM xla_events_gt     xet 
196534   , FA_XLA_EXT_HEADERS_B_GT  h1
196535  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
196536    and xet.event_class_code = C_EVENT_CLASS_CODE
196537    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
196538 
196539  ORDER BY event_id
196540 ;
196541 
196542 
196543 --
196544 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
196545 IS
196546 SELECT  /*+ leading(xet) cardinality(xet,1) */
196547 -- Event Class Code: CIP_UNIT_ADJUSTMENTS
196548     xet.entity_id
196549    ,xet.legal_entity_id
196550    ,xet.entity_code
196551    ,xet.transaction_number
196552    ,xet.event_id
196553    ,xet.event_class_code
196554    ,xet.event_type_code
196555    ,xet.event_number
196556    ,xet.event_date
196557    ,xet.transaction_date
196558    ,xet.reference_num_1
196559    ,xet.reference_num_2
196560    ,xet.reference_num_3
196561    ,xet.reference_num_4
196562    ,xet.reference_char_1
196563    ,xet.reference_char_2
196564    ,xet.reference_char_3
196565    ,xet.reference_char_4
196566    ,xet.reference_date_1
196567    ,xet.reference_date_2
196568    ,xet.reference_date_3
196569    ,xet.reference_date_4
196570    ,xet.event_created_by
196571    ,xet.budgetary_control_flag
196572  , l2.LINE_NUMBER  
196573   , l2.GENERATED_CCID    source_3
196574   , l2.CIP_COST_ACCT    source_7
196575   , l2.REVAL_RESERVE_ACCT    source_11
196576   , l2.GENERATED_OFFSET_CCID    source_17
196577   , l2.EXPENSE_ACCOUNT_CCID    source_29
196578   , l2.ADJUSTMENT_TYPE    source_35
196579   , l2.TRANSACTION_HEADER_ID    source_36
196580   , l2.ADJUSTMENT_LINE_ID    source_37
196581   , l2.DISTRIBUTION_TYPE_CODE    source_38
196582   , l2.ENTERED_AMOUNT    source_39
196583   , l2.CURRENCY_CODE    source_40
196584   , l2.SOURCE_DEST_CODE    source_42
196588    and xet.event_date between p_pad_start_date and p_pad_end_date
196585   FROM xla_events_gt     xet 
196586   , FA_XLA_EXT_LINES_B_GT  l2
196587  WHERE xet.event_id between x_first_event_id and x_last_event_id
196589    and xet.event_class_code = C_EVENT_CLASS_CODE
196590    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
196591   AND l2.ledger_id = p_sla_ledger_id
196592 ;
196593 
196594 --
196595 BEGIN
196596 IF g_log_enabled THEN
196597    l_log_module := C_DEFAULT_MODULE||'.EventClass_419';
196598 END IF;
196599 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
196600    trace
196601       (p_msg      => 'BEGIN of EventClass_419'
196602       ,p_level    => C_LEVEL_PROCEDURE
196603       ,p_module   => l_log_module);
196604 END IF;
196605 
196606 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
196607    trace
196608       (p_msg      => 'p_application_id = '||p_application_id||
196609                      ' - p_base_ledger_id = '||p_base_ledger_id||
196610                      ' - p_target_ledger_id  = '||p_target_ledger_id||
196611                      ' - p_language = '||p_language||
196612                      ' - p_currency_code = '||p_currency_code||
196613                      ' - p_sla_ledger_id = '||p_sla_ledger_id
196614       ,p_level    => C_LEVEL_STATEMENT
196615       ,p_module   => l_log_module);
196616 END IF;
196617 --
196618 -- initialze arrays
196619 --
196620 g_array_event.DELETE;
196621 l_rec_array_event := l_null_rec_array_event;
196622 --
196623 --------------------------------------
196624 -- 4262811 Initialze MPA Line Number
196625 --------------------------------------
196626 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
196627 
196628 --
196629 
196630 --
196631 OPEN header_cur;
196632 --
196633 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
196634    trace
196635    (p_msg      => 'SQL - FETCH header_cur'
196636    ,p_level    => C_LEVEL_STATEMENT
196637    ,p_module   => l_log_module);
196638 END IF;
196639 --
196640 LOOP
196641 FETCH header_cur BULK COLLECT INTO
196642         l_array_entity_id
196643       , l_array_legal_entity_id
196644       , l_array_entity_code
196645       , l_array_transaction_num
196646       , l_array_event_id
196647       , l_array_class_code
196648       , l_array_event_type
196649       , l_array_event_number
196650       , l_array_event_date
196651       , l_array_transaction_date
196652       , l_array_reference_num_1
196653       , l_array_reference_num_2
196654       , l_array_reference_num_3
196655       , l_array_reference_num_4
196656       , l_array_reference_char_1
196657       , l_array_reference_char_2
196658       , l_array_reference_char_3
196659       , l_array_reference_char_4
196660       , l_array_reference_date_1
196661       , l_array_reference_date_2
196662       , l_array_reference_date_3
196663       , l_array_reference_date_4
196664       , l_array_event_created_by
196665       , l_array_budgetary_control_flag 
196666       , l_array_source_1
196667       , l_array_source_19
196668       , l_array_source_20
196669       , l_array_source_30
196670       , l_array_source_51
196671       , l_array_source_52
196672       LIMIT l_rows;
196673 --
196674 IF (C_LEVEL_EVENT >= g_log_level) THEN
196675    trace
196676    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
196677    ,p_level    => C_LEVEL_EVENT
196678    ,p_module   => l_log_module);
196679 END IF;
196680 --
196681 EXIT WHEN l_array_entity_id.COUNT = 0;
196682 
196683 -- initialize arrays
196684 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
196685 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
196686 
196687 --
196688 -- Bug 4458708
196689 --
196690 XLA_AE_LINES_PKG.g_LineNumber := 0;
196691 
196692 
196693 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
196694 g_last_hdr_idx := l_array_event_id.LAST;
196695 --
196696 -- loop for the headers. Each iteration is for each header extract row
196697 -- fetched in header cursor
196698 --
196699 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
196700 
196701 --
196702 -- set event info as cache for other routines to refer event attributes
196703 --
196704 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
196705    (p_application_id           => p_application_id
196706    ,p_primary_ledger_id        => p_primary_ledger_id
196707    ,p_base_ledger_id           => p_base_ledger_id
196708    ,p_target_ledger_id         => p_target_ledger_id
196709    ,p_entity_id                => l_array_entity_id(hdr_idx)
196710    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
196711    ,p_entity_code              => l_array_entity_code(hdr_idx)
196712    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
196713    ,p_event_id                 => l_array_event_id(hdr_idx)
196714    ,p_event_class_code         => l_array_class_code(hdr_idx)
196715    ,p_event_type_code          => l_array_event_type(hdr_idx)
196716    ,p_event_number             => l_array_event_number(hdr_idx)
196717    ,p_event_date               => l_array_event_date(hdr_idx)
196718    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
196719    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
196720    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
196721    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
196722    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
196723    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
196724    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
196725    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
196726    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
196727    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
196728    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
196732    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
196729    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
196730    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
196731    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
196733 
196734 --
196735 -- set the status of entry to C_VALID (0)
196736 --
196737 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
196738 
196739 --
196740 -- initialize a row for ae header
196741 --
196742 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
196743 
196744 l_event_id := l_array_event_id(hdr_idx);
196745 
196746 --
196747 -- storing the hdr_idx for event. May be used by line cursor.
196748 --
196749 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
196750 
196751 --
196752 -- store sources from header extract. This can be improved to
196753 -- store only those sources from header extract that may be used in lines
196754 --
196755 
196756 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
196757 g_array_event(l_event_id).array_value_char('source_19') := l_array_source_19(hdr_idx);
196758 g_array_event(l_event_id).array_value_char('source_20') := l_array_source_20(hdr_idx);
196759 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
196760 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
196761 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
196762 
196763 --
196764 -- initilaize the status of ae headers for diffrent balance types
196765 -- the status is initialised to C_NOT_CREATED (2)
196766 --
196767 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
196768 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
196769 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
196770 
196771 --
196772 -- call api to validate and store accounting attributes for header
196773 --
196774 
196775 ------------------------------------------------------------
196776 -- Accrual Reversal : to get date for Standard Source (NONE)
196777 ------------------------------------------------------------
196778 l_acc_rev_gl_date_source := NULL;
196779 
196780      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
196781       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
196782      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
196783       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
196784 
196785 
196786 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
196787 
196788 XLA_AE_HEADER_PKG.SetJeCategoryName;
196789 
196790 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
196791 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
196792 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
196793 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
196794 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
196795 
196796 
196797 --
196798 xla_ae_header_pkg.SetHdrDescription(
196799    p_description => Description_53 (
196800    p_application_id => p_application_id 
196801  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
196802    )
196803 );
196804 --
196805 
196806 -- No header level analytical criteria
196807 
196808 --
196809 --accounting attribute enhancement, bug 3612931
196810 --
196811 l_trx_reversal_source := SUBSTR(NULL, 1,30);
196812 
196813 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
196814    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
196815 
196816    xla_accounting_err_pkg.build_message
196817       (p_appli_s_name            => 'XLA'
196818       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
196819       ,p_token_1                 => 'ACCT_ATTR_NAME'
196820       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
196821       ,p_token_2                 => 'PRODUCT_NAME'
196822       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
196823       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
196824       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
196825       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
196826 
196827 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
196828    --
196829    -- following sets the accounting attributes needed to reverse
196830    -- accounting for a distributeion
196831    --
196832    xla_ae_lines_pkg.SetTrxReversalAttrs
196833       (p_event_id              => l_event_id
196834       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
196835       ,p_trx_reversal_source   => l_trx_reversal_source);
196836 
196837 END IF;
196838 
196839 
196840 ----------------------------------------------------------------
196841 -- 4262811 -  update the header statuses to invalid in need be
196842 ----------------------------------------------------------------
196843 --
196844 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
196845 
196846 
196847   -----------------------------------------------
196848   -- No accrual reversal for the event class/type
196849   -----------------------------------------------
196850 ----------------------------------------------------------------
196851 
196852 --
196853 -- this ends the header loop iteration for one bulk fetch
196854 --
196855 END LOOP;
196856 
196860 --
196857 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
196858 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
196859 
196861 -- insert dummy rows into lines gt table that were created due to
196862 -- transaction reversals
196863 --
196864 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
196865    l_result := XLA_AE_LINES_PKG.InsertLines;
196866 END IF;
196867 
196868 --
196869 -- reset the temp_line_num for each set of events fetched from header
196870 -- cursor rather than doing it for each new event in line cursor
196871 -- Bug 3939231
196872 --
196873 xla_ae_lines_pkg.g_temp_line_num := 0;
196874 
196875 
196876 
196877 --
196878 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
196879 --
196880 --
196881 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
196882 
196883       trace
196884          (p_msg      => 'SQL - FETCH line_cur'
196885          ,p_level    => C_LEVEL_STATEMENT
196886          ,p_module   => l_log_module);
196887 
196888 END IF;
196889 --
196890 --
196891 LOOP
196892   --
196893   FETCH line_cur BULK COLLECT INTO
196894         l_array_entity_id
196895       , l_array_legal_entity_id
196896       , l_array_entity_code
196897       , l_array_transaction_num
196898       , l_array_event_id
196899       , l_array_class_code
196900       , l_array_event_type
196901       , l_array_event_number
196902       , l_array_event_date
196903       , l_array_transaction_date
196904       , l_array_reference_num_1
196905       , l_array_reference_num_2
196906       , l_array_reference_num_3
196907       , l_array_reference_num_4
196908       , l_array_reference_char_1
196909       , l_array_reference_char_2
196910       , l_array_reference_char_3
196911       , l_array_reference_char_4
196912       , l_array_reference_date_1
196913       , l_array_reference_date_2
196914       , l_array_reference_date_3
196915       , l_array_reference_date_4
196916       , l_array_event_created_by
196917       , l_array_budgetary_control_flag
196918       , l_array_extract_line_num 
196919       , l_array_source_3
196920       , l_array_source_7
196921       , l_array_source_11
196922       , l_array_source_17
196923       , l_array_source_29
196924       , l_array_source_35
196925       , l_array_source_36
196926       , l_array_source_37
196927       , l_array_source_38
196928       , l_array_source_39
196929       , l_array_source_40
196930       , l_array_source_42
196931       LIMIT l_rows;
196932 
196933   --
196934   IF (C_LEVEL_EVENT >= g_log_level) THEN
196935             trace
196936                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
196937                ,p_level    => C_LEVEL_EVENT
196938                ,p_module   => l_log_module);
196939   END IF;
196940   --
196941   EXIT WHEN l_array_entity_id.count = 0;
196942 
196943   XLA_AE_LINES_PKG.g_rec_lines := null;
196944 
196945 --
196946 -- Bug 4458708
196947 --
196948 XLA_AE_LINES_PKG.g_LineNumber := 0;
196949 --
196950 --
196951 
196952 FOR Idx IN 1..l_array_event_id.count LOOP
196953    --
196954    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
196955    --
196956    l_event_id := l_array_event_id(idx);  -- 5648433
196957 
196958    --
196959    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
196960    --
196961 
196962    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
196963              (g_array_event(l_event_id).array_value_num('header_index'))
196964          ,'N'
196965          ) <> 'Y'
196966    THEN
196967       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
196968          trace
196969             (p_msg      => 'Trancaction revesal option is not Y '
196970             ,p_level    => C_LEVEL_STATEMENT
196971             ,p_module   => l_log_module);
196972       END IF;
196973 
196974 --
196975 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
196976 --
196977 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
196978 --
196979 -- set event info as cache for other routines to refer event attributes
196980 --
196981 
196982 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
196983    l_previous_event_id := l_event_id;
196984 
196985    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
196986       (p_application_id           => p_application_id
196987       ,p_primary_ledger_id        => p_primary_ledger_id
196988       ,p_base_ledger_id           => p_base_ledger_id
196989       ,p_target_ledger_id         => p_target_ledger_id
196990       ,p_entity_id                => l_array_entity_id(Idx)
196991       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
196992       ,p_entity_code              => l_array_entity_code(Idx)
196993       ,p_transaction_num          => l_array_transaction_num(Idx)
196994       ,p_event_id                 => l_array_event_id(Idx)
196995       ,p_event_class_code         => l_array_class_code(Idx)
196996       ,p_event_type_code          => l_array_event_type(Idx)
196997       ,p_event_number             => l_array_event_number(Idx)
196998       ,p_event_date               => l_array_event_date(Idx)
196999       ,p_transaction_date         => l_array_transaction_date(Idx)
197000       ,p_reference_num_1          => l_array_reference_num_1(Idx)
197001       ,p_reference_num_2          => l_array_reference_num_2(Idx)
197002       ,p_reference_num_3          => l_array_reference_num_3(Idx)
197003       ,p_reference_num_4          => l_array_reference_num_4(Idx)
197004       ,p_reference_char_1         => l_array_reference_char_1(Idx)
197005       ,p_reference_char_2         => l_array_reference_char_2(Idx)
197006       ,p_reference_char_3         => l_array_reference_char_3(Idx)
197010       ,p_reference_date_3         => l_array_reference_date_3(Idx)
197007       ,p_reference_char_4         => l_array_reference_char_4(Idx)
197008       ,p_reference_date_1         => l_array_reference_date_1(Idx)
197009       ,p_reference_date_2         => l_array_reference_date_2(Idx)
197011       ,p_reference_date_4         => l_array_reference_date_4(Idx)
197012       ,p_event_created_by         => l_array_event_created_by(Idx)
197013       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
197014        --
197015 END IF;
197016 
197017 
197018 
197019 --
197020 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
197021 
197022 l_acct_reversal_source := SUBSTR(NULL, 1,30);
197023 
197024 IF l_continue_with_lines THEN
197025    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
197026       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
197027 
197028       xla_accounting_err_pkg.build_message
197029          (p_appli_s_name            => 'XLA'
197030          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
197031          ,p_token_1                 => 'LINE_NUMBER'
197032          ,p_value_1                 => l_array_extract_line_num(Idx)
197033          ,p_token_2                 => 'PRODUCT_NAME'
197034          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
197035          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
197036          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
197037          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
197038 
197039    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
197040       --
197041       -- following sets the accounting attributes needed to reverse
197042       -- accounting for a distributeion
197043       --
197044 
197045       --
197046       -- 5217187
197047       --
197048       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
197049       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
197050                                        g_array_event(l_event_id).array_value_num('header_index'));
197051       --
197052       --
197053 
197054       -- No reversal code generated
197055 
197056       xla_ae_lines_pkg.SetAcctReversalAttrs
197057          (p_event_id             => l_event_id
197058          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
197059          ,p_calculate_acctd_flag => l_calculate_acctd_flag
197060          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
197061    END IF;
197062 
197063    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
197064        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
197065 
197066 --
197067 AcctLineType_247 (
197068  p_application_id  => p_application_id
197069  ,p_event_id     => l_event_id
197070  ,p_calculate_acctd_flag => l_calculate_acctd_flag
197071  ,p_calculate_g_l_flag => l_calculate_g_l_flag
197072  ,p_actual_flag => l_actual_flag
197073  ,p_balance_type_code => l_balance_type_code
197074  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
197075  
197076  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
197077  , p_source_3 => l_array_source_3(Idx)
197078  , p_source_7 => l_array_source_7(Idx)
197079  , p_source_29 => l_array_source_29(Idx)
197080  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
197081  , p_source_35 => l_array_source_35(Idx)
197082  , p_source_36 => l_array_source_36(Idx)
197083  , p_source_37 => l_array_source_37(Idx)
197084  , p_source_38 => l_array_source_38(Idx)
197085  , p_source_39 => l_array_source_39(Idx)
197086  , p_source_40 => l_array_source_40(Idx)
197087  , p_source_42 => l_array_source_42(Idx)
197088  );
197089 If(l_balance_type_code = 'A') THEN
197090   l_actual_gain_loss_ref := l_gain_or_loss_ref;
197091 END IF;
197092 
197093 --
197094 
197095 
197096 --
197097 AcctLineType_248 (
197098  p_application_id  => p_application_id
197099  ,p_event_id     => l_event_id
197100  ,p_calculate_acctd_flag => l_calculate_acctd_flag
197101  ,p_calculate_g_l_flag => l_calculate_g_l_flag
197102  ,p_actual_flag => l_actual_flag
197103  ,p_balance_type_code => l_balance_type_code
197104  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
197105  
197106  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
197107  , p_source_3 => l_array_source_3(Idx)
197108  , p_source_11 => l_array_source_11(Idx)
197109  , p_source_17 => l_array_source_17(Idx)
197110  , p_source_29 => l_array_source_29(Idx)
197111  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
197112  , p_source_35 => l_array_source_35(Idx)
197113  , p_source_36 => l_array_source_36(Idx)
197114  , p_source_37 => l_array_source_37(Idx)
197115  , p_source_38 => l_array_source_38(Idx)
197116  , p_source_39 => l_array_source_39(Idx)
197117  , p_source_40 => l_array_source_40(Idx)
197118  , p_source_42 => l_array_source_42(Idx)
197119  );
197120 If(l_balance_type_code = 'A') THEN
197121   l_actual_gain_loss_ref := l_gain_or_loss_ref;
197122 END IF;
197123 
197124 --
197125 
197126 
197127 --
197128 AcctLineType_249 (
197129  p_application_id  => p_application_id
197130  ,p_event_id     => l_event_id
197131  ,p_calculate_acctd_flag => l_calculate_acctd_flag
197132  ,p_calculate_g_l_flag => l_calculate_g_l_flag
197133  ,p_actual_flag => l_actual_flag
197134  ,p_balance_type_code => l_balance_type_code
197135  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
197136  
197137  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
197138  , p_source_3 => l_array_source_3(Idx)
197139  , p_source_19 => g_array_event(l_event_id).array_value_char('source_19')
197140  , p_source_29 => l_array_source_29(Idx)
197141  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
197142  , p_source_35 => l_array_source_35(Idx)
197146  , p_source_39 => l_array_source_39(Idx)
197143  , p_source_36 => l_array_source_36(Idx)
197144  , p_source_37 => l_array_source_37(Idx)
197145  , p_source_38 => l_array_source_38(Idx)
197147  , p_source_40 => l_array_source_40(Idx)
197148  );
197149 If(l_balance_type_code = 'A') THEN
197150   l_actual_gain_loss_ref := l_gain_or_loss_ref;
197151 END IF;
197152 
197153 --
197154 
197155 
197156 --
197157 AcctLineType_250 (
197158  p_application_id  => p_application_id
197159  ,p_event_id     => l_event_id
197160  ,p_calculate_acctd_flag => l_calculate_acctd_flag
197161  ,p_calculate_g_l_flag => l_calculate_g_l_flag
197162  ,p_actual_flag => l_actual_flag
197163  ,p_balance_type_code => l_balance_type_code
197164  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
197165  
197166  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
197167  , p_source_3 => l_array_source_3(Idx)
197168  , p_source_20 => g_array_event(l_event_id).array_value_char('source_20')
197169  , p_source_29 => l_array_source_29(Idx)
197170  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
197171  , p_source_35 => l_array_source_35(Idx)
197172  , p_source_36 => l_array_source_36(Idx)
197173  , p_source_37 => l_array_source_37(Idx)
197174  , p_source_38 => l_array_source_38(Idx)
197175  , p_source_39 => l_array_source_39(Idx)
197176  , p_source_40 => l_array_source_40(Idx)
197177  );
197178 If(l_balance_type_code = 'A') THEN
197179   l_actual_gain_loss_ref := l_gain_or_loss_ref;
197180 END IF;
197181 
197182 --
197183 
197184 
197185 --
197186 AcctLineType_251 (
197187  p_application_id  => p_application_id
197188  ,p_event_id     => l_event_id
197189  ,p_calculate_acctd_flag => l_calculate_acctd_flag
197190  ,p_calculate_g_l_flag => l_calculate_g_l_flag
197191  ,p_actual_flag => l_actual_flag
197192  ,p_balance_type_code => l_balance_type_code
197193  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
197194  
197195  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
197196  , p_source_3 => l_array_source_3(Idx)
197197  , p_source_7 => l_array_source_7(Idx)
197198  , p_source_29 => l_array_source_29(Idx)
197199  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
197200  , p_source_35 => l_array_source_35(Idx)
197201  , p_source_36 => l_array_source_36(Idx)
197202  , p_source_37 => l_array_source_37(Idx)
197203  , p_source_38 => l_array_source_38(Idx)
197204  , p_source_39 => l_array_source_39(Idx)
197205  , p_source_40 => l_array_source_40(Idx)
197206  , p_source_42 => l_array_source_42(Idx)
197207  );
197208 If(l_balance_type_code = 'A') THEN
197209   l_actual_gain_loss_ref := l_gain_or_loss_ref;
197210 END IF;
197211 
197212 --
197213 
197214 
197215 --
197216 AcctLineType_252 (
197217  p_application_id  => p_application_id
197218  ,p_event_id     => l_event_id
197219  ,p_calculate_acctd_flag => l_calculate_acctd_flag
197220  ,p_calculate_g_l_flag => l_calculate_g_l_flag
197221  ,p_actual_flag => l_actual_flag
197222  ,p_balance_type_code => l_balance_type_code
197223  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
197224  
197225  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
197226  , p_source_3 => l_array_source_3(Idx)
197227  , p_source_11 => l_array_source_11(Idx)
197228  , p_source_17 => l_array_source_17(Idx)
197229  , p_source_29 => l_array_source_29(Idx)
197230  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
197231  , p_source_35 => l_array_source_35(Idx)
197232  , p_source_36 => l_array_source_36(Idx)
197233  , p_source_37 => l_array_source_37(Idx)
197234  , p_source_38 => l_array_source_38(Idx)
197235  , p_source_39 => l_array_source_39(Idx)
197236  , p_source_40 => l_array_source_40(Idx)
197237  , p_source_42 => l_array_source_42(Idx)
197238  );
197239 If(l_balance_type_code = 'A') THEN
197240   l_actual_gain_loss_ref := l_gain_or_loss_ref;
197241 END IF;
197242 
197243 --
197244 
197245       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
197246       -- or secondary ledger that has different currency with primary
197247       -- or alc that is calculated by sla
197248       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
197249             (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'))
197250 
197251 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
197252 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
197253           AND (l_actual_flag = 'A')) THEN
197254         XLA_AE_LINES_PKG.CreateGainOrLossLines(
197255           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
197256          ,p_application_id   => p_application_id
197257          ,p_amb_context_code => 'DEFAULT'
197258          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
197259          ,p_event_class_code => C_EVENT_CLASS_CODE
197260          ,p_event_type_code  => C_EVENT_TYPE_CODE
197261          
197262          ,p_gain_ccid        => -1
197263          ,p_loss_ccid        => -1
197264 
197265          ,p_actual_flag      => l_actual_flag
197266          ,p_enc_flag         => null
197267          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
197268          ,p_enc_g_l_ref      => null
197269          );
197270       END IF;
197271    END IF;
197272 END IF;
197273 
197274    ELSE
197275       --
197276       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
197277       --
197278       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
197279          trace
197280             (p_msg      => 'Trancaction revesal option is Y'
197281             ,p_level    => C_LEVEL_STATEMENT
197282             ,p_module   => l_log_module);
197283       END IF;
197284    END IF;
197285 
197289 close line_cur;
197286 END LOOP;
197287 l_result := XLA_AE_LINES_PKG.InsertLines ;
197288 end loop;
197290 
197291 
197292 --
197293 -- insert headers into xla_ae_headers_gt table
197294 --
197295 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
197296 
197297 -- insert into errors table here.
197298 
197299 END LOOP;
197300 
197301 --
197302 -- 4865292
197303 --
197304 -- Compare g_hdr_extract_count with event count in
197305 -- CreateHeadersAndLines.
197306 --
197307 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
197308 
197309 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
197310    trace (p_msg     => '# rows extracted from header extract objects '
197311                     || ' (running total): '
197312                     || g_hdr_extract_count
197313          ,p_level   => C_LEVEL_STATEMENT
197314          ,p_module  => l_log_module);
197315 END IF;
197316 
197317 CLOSE header_cur;
197318 --
197319 
197320 --
197321 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
197322    trace
197323       (p_msg      => 'END of EventClass_419'
197324       ,p_level    => C_LEVEL_PROCEDURE
197325       ,p_module   => l_log_module);
197326 END IF;
197327 --
197328 RETURN l_result;
197329 EXCEPTION
197330 WHEN xla_exceptions_pkg.application_exception THEN
197331    
197332 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
197333 
197334    
197335 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
197336 
197337    RAISE;
197338 
197339 WHEN NO_DATA_FOUND THEN
197340 
197341 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
197342 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
197343 
197344 FOR header_record IN header_cur
197345 LOOP
197346     l_array_header_events(header_record.event_id) := header_record.event_id;
197347 END LOOP;
197348 
197349 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
197350 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
197351 
197352 fnd_file.put_line(fnd_file.LOG, '                    ');
197353 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
197354 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
197355 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
197356 
197357 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
197358 LOOP
197359 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
197360 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
197361         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
197362 	END IF;
197363 END LOOP;
197364 
197365 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
197366 fnd_file.put_line(fnd_file.LOG, '                    ');
197367 
197368 
197369 xla_exceptions_pkg.raise_message
197370       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_419');
197371 
197372 
197373 WHEN OTHERS THEN
197374    xla_exceptions_pkg.raise_message
197375       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_419');
197376 END EventClass_419;
197377 --
197378 
197379 ---------------------------------------
197380 --
197381 -- PRIVATE PROCEDURE
197382 --         insert_sources_420
197383 --
197384 ----------------------------------------
197385 --
197386 PROCEDURE insert_sources_420(
197387                                 p_target_ledger_id       IN NUMBER
197388                               , p_language               IN VARCHAR2
197389                               , p_sla_ledger_id          IN NUMBER
197390                               , p_pad_start_date         IN DATE
197391                               , p_pad_end_date           IN DATE
197392                          )
197393 IS
197394 
197395 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEFERRED_DEPRECIATION_ALL';
197396 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'DEFERRED_DEPRECIATION';
197397 p_apps_owner                   VARCHAR2(30);
197398 l_log_module                   VARCHAR2(240);
197399 BEGIN
197400 IF g_log_enabled THEN
197401       l_log_module := C_DEFAULT_MODULE||'.insert_sources_420';
197402 END IF;
197403 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
197404 
197405       trace
197406          (p_msg      => 'BEGIN of insert_sources_420'
197407          ,p_level    => C_LEVEL_PROCEDURE
197408          ,p_module   => l_log_module);
197409 
197410 END IF;
197411 
197412 -- select APPS owner
197413 SELECT oracle_username
197414   INTO p_apps_owner
197415   FROM fnd_oracle_userid
197416  WHERE read_only_flag = 'U'
197417 ;
197418 
197419 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
197420       trace
197421          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
197422                         ' - p_language = '||p_language||
197423                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
197424                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
197425                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
197426                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
197427          ,p_level    => C_LEVEL_STATEMENT
197428          ,p_module   => l_log_module);
197429 END IF;
197430 
197431 
197432 --
197433 INSERT INTO xla_diag_sources --hdr2
197434 (
197435         event_id
197436       , ledger_id
197437       , sla_ledger_id
197438       , description_language
197439       , object_name
197440       , object_type_code
197441       , line_number
197442       , source_application_id
197443       , source_type_code
197444       , source_code
197445       , source_value
197449       , last_update_date
197446       , source_meaning
197447       , created_by
197448       , creation_date
197450       , last_updated_by
197451       , last_update_login
197452       , program_update_date
197453       , program_application_id
197454       , program_id
197455       , request_id
197456 )
197457 SELECT
197458         event_id
197459       , p_target_ledger_id
197460       , p_sla_ledger_id
197461       , p_language
197462       , object_name
197463       , object_type_code
197464       , line_number
197465       , source_application_id
197466       , source_type_code
197467       , source_code
197468       , SUBSTR(source_value ,1,1996)
197469       , SUBSTR(source_meaning ,1,200)
197470       , xla_environment_pkg.g_Usr_Id
197471       , TRUNC(SYSDATE)
197472       , TRUNC(SYSDATE)
197473       , xla_environment_pkg.g_Usr_Id
197474       , xla_environment_pkg.g_Login_Id
197475       , TRUNC(SYSDATE)
197476       , xla_environment_pkg.g_Prog_Appl_Id
197477       , xla_environment_pkg.g_Prog_Id
197478       , xla_environment_pkg.g_Req_Id
197479   FROM (
197480        SELECT xet.event_id                  event_id
197481             , 0                          line_number
197482             , CASE r
197483                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
197484                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
197485                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
197486                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
197487                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
197488                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
197489                 WHEN 7 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
197490                 
197491                ELSE null
197492               END                           object_name
197493             , CASE r
197494                 WHEN 1 THEN 'HEADER' 
197495                 WHEN 2 THEN 'HEADER' 
197496                 WHEN 3 THEN 'HEADER' 
197497                 WHEN 4 THEN 'HEADER' 
197498                 WHEN 5 THEN 'HEADER' 
197499                 WHEN 6 THEN 'HEADER' 
197500                 WHEN 7 THEN 'HEADER' 
197501                 
197502                 ELSE null
197503               END                           object_type_code
197504             , CASE r
197505                 WHEN 1 THEN '140' 
197506                 WHEN 2 THEN '140' 
197507                 WHEN 3 THEN '140' 
197508                 WHEN 4 THEN '140' 
197509                 WHEN 5 THEN '140' 
197510                 WHEN 6 THEN '140' 
197511                 WHEN 7 THEN '140' 
197512                 
197513                 ELSE null
197514               END                           source_application_id
197515             , 'S'             source_type_code
197516             , CASE r
197517                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
197518                 WHEN 2 THEN 'DEFERRED_DEPRN_EXPENSE_ACCT' 
197519                 WHEN 3 THEN 'DEFERRED_DEPRN_RESERVE_ACCT' 
197520                 WHEN 4 THEN 'DEFAULT_CCID' 
197521                 WHEN 5 THEN 'PERIOD_COUNTER' 
197522                 WHEN 6 THEN 'BOOK_TYPE_CODE' 
197523                 WHEN 7 THEN 'ACCOUNTING_DATE' 
197524                 
197525                 ELSE null
197526               END                           source_code
197527             , CASE r
197528                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
197529                 WHEN 2 THEN TO_CHAR(h1.DEFERRED_DEPRN_EXPENSE_ACCT)
197530                 WHEN 3 THEN TO_CHAR(h1.DEFERRED_DEPRN_RESERVE_ACCT)
197531                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
197532                 WHEN 5 THEN TO_CHAR(h1.PERIOD_COUNTER)
197533                 WHEN 6 THEN TO_CHAR(h1.BOOK_TYPE_CODE)
197534                 WHEN 7 THEN TO_CHAR(h1.ACCOUNTING_DATE)
197535                 
197536                 ELSE null
197537               END                           source_value
197538             , null              source_meaning
197539          FROM xla_events_gt     xet  
197540       , FA_XLA_EXT_HEADERS_B_GT  h1
197541              ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
197542          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
197543            AND xet.event_class_code = C_EVENT_CLASS_CODE
197544               AND h1.event_id = xet.event_id
197545 
197546 )
197547 ;
197548 --
197549 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
197550 
197551       trace
197552          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
197553          ,p_level    => C_LEVEL_STATEMENT
197554          ,p_module   => l_log_module);
197555 
197556 END IF;
197557 --
197558 
197559 
197560 
197561 --
197562 INSERT INTO xla_diag_sources  --line2
197563 (
197564         event_id
197565       , ledger_id
197566       , sla_ledger_id
197567       , description_language
197568       , object_name
197569       , object_type_code
197570       , line_number
197571       , source_application_id
197572       , source_type_code
197573       , source_code
197574       , source_value
197575       , source_meaning
197576       , created_by
197577       , creation_date
197578       , last_update_date
197579       , last_updated_by
197580       , last_update_login
197581       , program_update_date
197582       , program_application_id
197583       , program_id
197584       , request_id
197585 )
197586 SELECT  event_id
197587       , p_target_ledger_id
197588       , p_sla_ledger_id
197589       , p_language
197590       , object_name
197591       , object_type_code
197592       , line_number
197593       , source_application_id
197594       , source_type_code
197595       , source_code
197596       , SUBSTR(source_value,1,1996)
197597       , SUBSTR(source_meaning ,1,200)
197598       , xla_environment_pkg.g_Usr_Id
197599       , TRUNC(SYSDATE)
197603       , TRUNC(SYSDATE)
197600       , TRUNC(SYSDATE)
197601       , xla_environment_pkg.g_Usr_Id
197602       , xla_environment_pkg.g_Login_Id
197604       , xla_environment_pkg.g_Prog_Appl_Id
197605       , xla_environment_pkg.g_Prog_Id
197606       , xla_environment_pkg.g_Req_Id
197607   FROM (
197608        SELECT xet.event_id                  event_id
197609             , l2.line_number                 line_number
197610             , CASE r
197611                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
197612                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
197613                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
197614                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
197615                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
197616                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
197617                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
197618                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
197619                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
197620                 
197621                ELSE null
197622               END                           object_name
197623             , CASE r
197624                 WHEN 1 THEN 'LINE' 
197625                 WHEN 2 THEN 'LINE' 
197626                 WHEN 3 THEN 'LINE' 
197627                 WHEN 4 THEN 'LINE' 
197628                 WHEN 5 THEN 'LINE' 
197629                 WHEN 6 THEN 'LINE' 
197630                 WHEN 7 THEN 'LINE' 
197631                 WHEN 8 THEN 'LINE' 
197632                 WHEN 9 THEN 'LINE' 
197633                 
197634                 ELSE null
197635               END                           object_type_code
197636             , CASE r
197637                 WHEN 1 THEN '140' 
197638                 WHEN 2 THEN '140' 
197639                 WHEN 3 THEN '140' 
197640                 WHEN 4 THEN '140' 
197641                 WHEN 5 THEN '140' 
197642                 WHEN 6 THEN '140' 
197643                 WHEN 7 THEN '140' 
197644                 WHEN 8 THEN '140' 
197645                 WHEN 9 THEN '140' 
197646                 
197647                 ELSE null
197648               END                           source_application_id
197649             , 'S'             source_type_code
197650             , CASE r
197651                 WHEN 1 THEN 'GENERATED_CCID' 
197652                 WHEN 2 THEN 'GENERATED_OFFSET_CCID' 
197653                 WHEN 3 THEN 'EXPENSE_ACCOUNT_CCID' 
197654                 WHEN 4 THEN 'DISTRIBUTION_TYPE_CODE' 
197655                 WHEN 5 THEN 'ENTERED_AMOUNT' 
197656                 WHEN 6 THEN 'CURRENCY_CODE' 
197657                 WHEN 7 THEN 'ASSET_ID' 
197658                 WHEN 8 THEN 'DISTRIBUTION_ID' 
197659                 WHEN 9 THEN 'TAX_BOOK_TYPE_CODE' 
197660                 
197661                 ELSE null
197662               END                           source_code
197663             , CASE r
197664                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
197665                 WHEN 2 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
197666                 WHEN 3 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
197667                 WHEN 4 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
197668                 WHEN 5 THEN TO_CHAR(l2.ENTERED_AMOUNT)
197669                 WHEN 6 THEN TO_CHAR(l2.CURRENCY_CODE)
197670                 WHEN 7 THEN TO_CHAR(l2.ASSET_ID)
197671                 WHEN 8 THEN TO_CHAR(l2.DISTRIBUTION_ID)
197672                 WHEN 9 THEN TO_CHAR(l2.TAX_BOOK_TYPE_CODE)
197673                 
197674                 ELSE null
197675               END                           source_value
197676             , null              source_meaning
197677          FROM  xla_events_gt     xet  
197678         , FA_XLA_EXT_LINES_B_GT  l2
197679             , (select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
197680         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
197681           AND xet.event_class_code = C_EVENT_CLASS_CODE
197682             AND l2.event_id          = xet.event_id
197683   AND l2.ledger_id (+)  = p_sla_ledger_id
197684 
197685 )
197686 ;
197687 --
197688 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
197689 
197690       trace
197691          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
197692          ,p_level    => C_LEVEL_STATEMENT
197693          ,p_module   => l_log_module);
197694 
197695 END IF;
197696 
197697 
197698 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
197699       trace
197700          (p_msg      => 'END of insert_sources_420'
197701          ,p_level    => C_LEVEL_PROCEDURE
197702          ,p_module   => l_log_module);
197703 END IF;
197704 EXCEPTION
197705   WHEN xla_exceptions_pkg.application_exception THEN
197706       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
197707             trace
197708                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
197709                ,p_level    => C_LEVEL_EXCEPTION
197710                ,p_module   => l_log_module);
197711       END IF;
197712       RAISE;
197713   WHEN OTHERS THEN
197714       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
197715             trace
197716                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
197717                ,p_level    => C_LEVEL_EXCEPTION
197718                ,p_module   => l_log_module);
197719        END IF;
197720        xla_exceptions_pkg.raise_message
197721            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_420');
197722 END insert_sources_420;
197723 --
197724 
197725 ---------------------------------------
197726 --
197727 -- PRIVATE FUNCTION
197728 --         EventClass_420
197729 --
197730 ----------------------------------------
197731 --
197732 FUNCTION EventClass_420
197733        (p_application_id         IN NUMBER
197734        ,p_base_ledger_id         IN NUMBER
197735        ,p_target_ledger_id       IN NUMBER
197736        ,p_language               IN VARCHAR2
197737        ,p_currency_code          IN VARCHAR2
197741        ,p_primary_ledger_id      IN NUMBER)
197738        ,p_sla_ledger_id          IN NUMBER
197739        ,p_pad_start_date         IN DATE
197740        ,p_pad_end_date           IN DATE
197742 RETURN BOOLEAN IS
197743 --
197744 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEFERRED_DEPRECIATION_ALL';
197745 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'DEFERRED_DEPRECIATION';
197746 
197747 l_calculate_acctd_flag   VARCHAR2(1) :='N';
197748 l_calculate_g_l_flag     VARCHAR2(1) :='N';
197749 --
197750 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
197751 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
197752 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
197753 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
197754 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
197755 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
197756 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
197757 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
197758 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
197759 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
197760 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
197761 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
197762 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
197763 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
197764 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
197765 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
197766 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
197767 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
197768 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
197769 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
197770 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
197771 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
197772 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
197773 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
197774 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
197775 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
197776 
197777 l_event_id                             NUMBER;
197778 l_previous_event_id                    NUMBER;
197779 l_first_event_id                       NUMBER;
197780 l_last_event_id                        NUMBER;
197781 
197782 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
197783 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
197784 --
197785 --
197786 l_result                    BOOLEAN := TRUE;
197787 l_rows                      NUMBER  := 1000;
197788 l_event_type_name           VARCHAR2(80) := 'All';
197789 l_event_class_name          VARCHAR2(80) := 'Deferred Depreciation';
197790 l_description               VARCHAR2(4000);
197791 l_transaction_reversal      NUMBER;
197792 l_ae_header_id              NUMBER;
197793 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
197794 l_log_module                VARCHAR2(240);
197795 --
197796 l_acct_reversal_source      VARCHAR2(30);
197797 l_trx_reversal_source       VARCHAR2(30);
197798 
197799 l_continue_with_lines       BOOLEAN := TRUE;
197800 --
197801 l_acc_rev_gl_date_source    DATE;                      -- 4262811
197802 --
197803 type t_array_event_id is table of number index by binary_integer;
197804 
197805 l_rec_array_event                    t_rec_array_event;
197806 l_null_rec_array_event               t_rec_array_event;
197807 l_array_ae_header_id                 xla_number_array_type;
197808 l_actual_flag                        VARCHAR2(1) := NULL;
197809 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
197810 l_balance_type_code                  VARCHAR2(1) :=NULL;
197811 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
197812 
197813 --
197814 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
197815 --
197816 
197817 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
197818 TYPE t_array_source_15 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFERRED_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
197819 TYPE t_array_source_16 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFERRED_DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
197820 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
197821 TYPE t_array_source_44 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_COUNTER%TYPE INDEX BY BINARY_INTEGER;
197822 TYPE t_array_source_46 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.BOOK_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
197823 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
197824 
197825 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
197826 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
197827 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
197828 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
197829 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
197830 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
197831 TYPE t_array_source_43 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_ID%TYPE INDEX BY BINARY_INTEGER;
197832 TYPE t_array_source_45 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_ID%TYPE INDEX BY BINARY_INTEGER;
197833 TYPE t_array_source_47 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TAX_BOOK_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
197834 
197838 l_array_source_30              t_array_source_30;
197835 l_array_source_1              t_array_source_1;
197836 l_array_source_15              t_array_source_15;
197837 l_array_source_16              t_array_source_16;
197839 l_array_source_44              t_array_source_44;
197840 l_array_source_46              t_array_source_46;
197841 l_array_source_51              t_array_source_51;
197842 
197843 l_array_source_3      t_array_source_3;
197844 l_array_source_17      t_array_source_17;
197845 l_array_source_29      t_array_source_29;
197846 l_array_source_38      t_array_source_38;
197847 l_array_source_39      t_array_source_39;
197848 l_array_source_40      t_array_source_40;
197849 l_array_source_43      t_array_source_43;
197850 l_array_source_45      t_array_source_45;
197851 l_array_source_47      t_array_source_47;
197852 
197853 --
197854 CURSOR header_cur
197855 IS
197856 SELECT /*+ leading(xet) cardinality(xet,1) */
197857 -- Event Class Code: DEFERRED_DEPRECIATION
197858     xet.entity_id
197859    ,xet.legal_entity_id
197860    ,xet.entity_code
197861    ,xet.transaction_number
197862    ,xet.event_id
197863    ,xet.event_class_code
197864    ,xet.event_type_code
197865    ,xet.event_number
197866    ,xet.event_date
197867    ,xet.transaction_date
197868    ,xet.reference_num_1
197869    ,xet.reference_num_2
197870    ,xet.reference_num_3
197871    ,xet.reference_num_4
197872    ,xet.reference_char_1
197873    ,xet.reference_char_2
197874    ,xet.reference_char_3
197875    ,xet.reference_char_4
197876    ,xet.reference_date_1
197877    ,xet.reference_date_2
197878    ,xet.reference_date_3
197879    ,xet.reference_date_4
197880    ,xet.event_created_by
197881    ,xet.budgetary_control_flag 
197882   , h1.PERIOD_CLOSE_DATE    source_1
197883   , h1.DEFERRED_DEPRN_EXPENSE_ACCT    source_15
197884   , h1.DEFERRED_DEPRN_RESERVE_ACCT    source_16
197885   , h1.DEFAULT_CCID    source_30
197886   , h1.PERIOD_COUNTER    source_44
197887   , h1.BOOK_TYPE_CODE    source_46
197888   , h1.ACCOUNTING_DATE    source_51
197889   FROM xla_events_gt     xet 
197890   , FA_XLA_EXT_HEADERS_B_GT  h1
197891  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
197892    and xet.event_class_code = C_EVENT_CLASS_CODE
197893    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
197894 
197895  ORDER BY event_id
197896 ;
197897 
197898 
197899 --
197900 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
197901 IS
197902 SELECT  /*+ leading(xet) cardinality(xet,1) */
197903 -- Event Class Code: DEFERRED_DEPRECIATION
197904     xet.entity_id
197905    ,xet.legal_entity_id
197906    ,xet.entity_code
197907    ,xet.transaction_number
197908    ,xet.event_id
197909    ,xet.event_class_code
197910    ,xet.event_type_code
197911    ,xet.event_number
197912    ,xet.event_date
197913    ,xet.transaction_date
197914    ,xet.reference_num_1
197915    ,xet.reference_num_2
197916    ,xet.reference_num_3
197917    ,xet.reference_num_4
197918    ,xet.reference_char_1
197919    ,xet.reference_char_2
197920    ,xet.reference_char_3
197921    ,xet.reference_char_4
197922    ,xet.reference_date_1
197923    ,xet.reference_date_2
197924    ,xet.reference_date_3
197925    ,xet.reference_date_4
197926    ,xet.event_created_by
197927    ,xet.budgetary_control_flag
197928  , l2.LINE_NUMBER  
197929   , l2.GENERATED_CCID    source_3
197930   , l2.GENERATED_OFFSET_CCID    source_17
197931   , l2.EXPENSE_ACCOUNT_CCID    source_29
197932   , l2.DISTRIBUTION_TYPE_CODE    source_38
197933   , l2.ENTERED_AMOUNT    source_39
197934   , l2.CURRENCY_CODE    source_40
197935   , l2.ASSET_ID    source_43
197936   , l2.DISTRIBUTION_ID    source_45
197937   , l2.TAX_BOOK_TYPE_CODE    source_47
197938   FROM xla_events_gt     xet 
197939   , FA_XLA_EXT_LINES_B_GT  l2
197940  WHERE xet.event_id between x_first_event_id and x_last_event_id
197941    and xet.event_date between p_pad_start_date and p_pad_end_date
197942    and xet.event_class_code = C_EVENT_CLASS_CODE
197943    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
197944   AND l2.ledger_id = p_sla_ledger_id
197945 ;
197946 
197947 --
197948 BEGIN
197949 IF g_log_enabled THEN
197950    l_log_module := C_DEFAULT_MODULE||'.EventClass_420';
197951 END IF;
197952 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
197953    trace
197954       (p_msg      => 'BEGIN of EventClass_420'
197955       ,p_level    => C_LEVEL_PROCEDURE
197956       ,p_module   => l_log_module);
197957 END IF;
197958 
197959 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
197960    trace
197961       (p_msg      => 'p_application_id = '||p_application_id||
197962                      ' - p_base_ledger_id = '||p_base_ledger_id||
197963                      ' - p_target_ledger_id  = '||p_target_ledger_id||
197964                      ' - p_language = '||p_language||
197965                      ' - p_currency_code = '||p_currency_code||
197966                      ' - p_sla_ledger_id = '||p_sla_ledger_id
197967       ,p_level    => C_LEVEL_STATEMENT
197968       ,p_module   => l_log_module);
197969 END IF;
197970 --
197971 -- initialze arrays
197972 --
197973 g_array_event.DELETE;
197974 l_rec_array_event := l_null_rec_array_event;
197975 --
197976 --------------------------------------
197977 -- 4262811 Initialze MPA Line Number
197978 --------------------------------------
197979 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
197980 
197981 --
197982 
197983 --
197984 OPEN header_cur;
197985 --
197986 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
197987    trace
197988    (p_msg      => 'SQL - FETCH header_cur'
197989    ,p_level    => C_LEVEL_STATEMENT
197990    ,p_module   => l_log_module);
197991 END IF;
197992 --
197993 LOOP
197994 FETCH header_cur BULK COLLECT INTO
197998       , l_array_transaction_num
197995         l_array_entity_id
197996       , l_array_legal_entity_id
197997       , l_array_entity_code
197999       , l_array_event_id
198000       , l_array_class_code
198001       , l_array_event_type
198002       , l_array_event_number
198003       , l_array_event_date
198004       , l_array_transaction_date
198005       , l_array_reference_num_1
198006       , l_array_reference_num_2
198007       , l_array_reference_num_3
198008       , l_array_reference_num_4
198009       , l_array_reference_char_1
198010       , l_array_reference_char_2
198011       , l_array_reference_char_3
198012       , l_array_reference_char_4
198013       , l_array_reference_date_1
198014       , l_array_reference_date_2
198015       , l_array_reference_date_3
198016       , l_array_reference_date_4
198017       , l_array_event_created_by
198018       , l_array_budgetary_control_flag 
198019       , l_array_source_1
198020       , l_array_source_15
198021       , l_array_source_16
198022       , l_array_source_30
198023       , l_array_source_44
198024       , l_array_source_46
198025       , l_array_source_51
198026       LIMIT l_rows;
198027 --
198028 IF (C_LEVEL_EVENT >= g_log_level) THEN
198029    trace
198030    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
198031    ,p_level    => C_LEVEL_EVENT
198032    ,p_module   => l_log_module);
198033 END IF;
198034 --
198035 EXIT WHEN l_array_entity_id.COUNT = 0;
198036 
198037 -- initialize arrays
198038 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
198039 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
198040 
198041 --
198042 -- Bug 4458708
198043 --
198044 XLA_AE_LINES_PKG.g_LineNumber := 0;
198045 
198046 
198047 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
198048 g_last_hdr_idx := l_array_event_id.LAST;
198049 --
198050 -- loop for the headers. Each iteration is for each header extract row
198051 -- fetched in header cursor
198052 --
198053 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
198054 
198055 --
198056 -- set event info as cache for other routines to refer event attributes
198057 --
198058 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
198059    (p_application_id           => p_application_id
198060    ,p_primary_ledger_id        => p_primary_ledger_id
198061    ,p_base_ledger_id           => p_base_ledger_id
198062    ,p_target_ledger_id         => p_target_ledger_id
198063    ,p_entity_id                => l_array_entity_id(hdr_idx)
198064    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
198065    ,p_entity_code              => l_array_entity_code(hdr_idx)
198066    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
198067    ,p_event_id                 => l_array_event_id(hdr_idx)
198068    ,p_event_class_code         => l_array_class_code(hdr_idx)
198069    ,p_event_type_code          => l_array_event_type(hdr_idx)
198070    ,p_event_number             => l_array_event_number(hdr_idx)
198071    ,p_event_date               => l_array_event_date(hdr_idx)
198072    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
198073    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
198074    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
198075    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
198076    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
198077    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
198078    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
198079    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
198080    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
198081    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
198082    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
198083    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
198084    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
198085    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
198086    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
198087 
198088 --
198089 -- set the status of entry to C_VALID (0)
198090 --
198091 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
198092 
198093 --
198094 -- initialize a row for ae header
198095 --
198096 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
198097 
198098 l_event_id := l_array_event_id(hdr_idx);
198099 
198100 --
198101 -- storing the hdr_idx for event. May be used by line cursor.
198102 --
198103 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
198104 
198105 --
198106 -- store sources from header extract. This can be improved to
198107 -- store only those sources from header extract that may be used in lines
198108 --
198109 
198110 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
198111 g_array_event(l_event_id).array_value_char('source_15') := l_array_source_15(hdr_idx);
198112 g_array_event(l_event_id).array_value_char('source_16') := l_array_source_16(hdr_idx);
198113 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
198114 g_array_event(l_event_id).array_value_num('source_44') := l_array_source_44(hdr_idx);
198115 g_array_event(l_event_id).array_value_char('source_46') := l_array_source_46(hdr_idx);
198116 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
198117 
198118 --
198119 -- initilaize the status of ae headers for diffrent balance types
198120 -- the status is initialised to C_NOT_CREATED (2)
198121 --
198122 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
198123 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
198127 -- call api to validate and store accounting attributes for header
198124 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
198125 
198126 --
198128 --
198129 
198130 ------------------------------------------------------------
198131 -- Accrual Reversal : to get date for Standard Source (NONE)
198132 ------------------------------------------------------------
198133 l_acc_rev_gl_date_source := NULL;
198134 
198135      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
198136       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
198137 
198138 
198139 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
198140 
198141 XLA_AE_HEADER_PKG.SetJeCategoryName;
198142 
198143 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
198144 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
198145 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
198146 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
198147 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
198148 
198149 
198150 --
198151 xla_ae_header_pkg.SetHdrDescription(
198152    p_description => Description_54 (
198153    p_application_id => p_application_id 
198154  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
198155    )
198156 );
198157 --
198158 
198159 -- No header level analytical criteria
198160 
198161 --
198162 --accounting attribute enhancement, bug 3612931
198163 --
198164 l_trx_reversal_source := SUBSTR(NULL, 1,30);
198165 
198166 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
198167    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
198168 
198169    xla_accounting_err_pkg.build_message
198170       (p_appli_s_name            => 'XLA'
198171       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
198172       ,p_token_1                 => 'ACCT_ATTR_NAME'
198173       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
198174       ,p_token_2                 => 'PRODUCT_NAME'
198175       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
198176       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
198177       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
198178       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
198179 
198180 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
198181    --
198182    -- following sets the accounting attributes needed to reverse
198183    -- accounting for a distributeion
198184    --
198185    xla_ae_lines_pkg.SetTrxReversalAttrs
198186       (p_event_id              => l_event_id
198187       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
198188       ,p_trx_reversal_source   => l_trx_reversal_source);
198189 
198190 END IF;
198191 
198192 
198193 ----------------------------------------------------------------
198194 -- 4262811 -  update the header statuses to invalid in need be
198195 ----------------------------------------------------------------
198196 --
198197 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
198198 
198199 
198200   -----------------------------------------------
198201   -- No accrual reversal for the event class/type
198202   -----------------------------------------------
198203 ----------------------------------------------------------------
198204 
198205 --
198206 -- this ends the header loop iteration for one bulk fetch
198207 --
198208 END LOOP;
198209 
198210 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
198211 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
198212 
198213 --
198214 -- insert dummy rows into lines gt table that were created due to
198215 -- transaction reversals
198216 --
198217 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
198218    l_result := XLA_AE_LINES_PKG.InsertLines;
198219 END IF;
198220 
198221 --
198222 -- reset the temp_line_num for each set of events fetched from header
198223 -- cursor rather than doing it for each new event in line cursor
198224 -- Bug 3939231
198225 --
198226 xla_ae_lines_pkg.g_temp_line_num := 0;
198227 
198228 
198229 
198230 --
198231 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
198232 --
198233 --
198234 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
198235 
198236       trace
198237          (p_msg      => 'SQL - FETCH line_cur'
198238          ,p_level    => C_LEVEL_STATEMENT
198239          ,p_module   => l_log_module);
198240 
198241 END IF;
198242 --
198243 --
198244 LOOP
198245   --
198246   FETCH line_cur BULK COLLECT INTO
198247         l_array_entity_id
198248       , l_array_legal_entity_id
198249       , l_array_entity_code
198250       , l_array_transaction_num
198251       , l_array_event_id
198252       , l_array_class_code
198253       , l_array_event_type
198254       , l_array_event_number
198255       , l_array_event_date
198256       , l_array_transaction_date
198257       , l_array_reference_num_1
198258       , l_array_reference_num_2
198259       , l_array_reference_num_3
198260       , l_array_reference_num_4
198261       , l_array_reference_char_1
198262       , l_array_reference_char_2
198263       , l_array_reference_char_3
198264       , l_array_reference_char_4
198265       , l_array_reference_date_1
198266       , l_array_reference_date_2
198267       , l_array_reference_date_3
198268       , l_array_reference_date_4
198269       , l_array_event_created_by
198273       , l_array_source_17
198270       , l_array_budgetary_control_flag
198271       , l_array_extract_line_num 
198272       , l_array_source_3
198274       , l_array_source_29
198275       , l_array_source_38
198276       , l_array_source_39
198277       , l_array_source_40
198278       , l_array_source_43
198279       , l_array_source_45
198280       , l_array_source_47
198281       LIMIT l_rows;
198282 
198283   --
198284   IF (C_LEVEL_EVENT >= g_log_level) THEN
198285             trace
198286                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
198287                ,p_level    => C_LEVEL_EVENT
198288                ,p_module   => l_log_module);
198289   END IF;
198290   --
198291   EXIT WHEN l_array_entity_id.count = 0;
198292 
198293   XLA_AE_LINES_PKG.g_rec_lines := null;
198294 
198295 --
198296 -- Bug 4458708
198297 --
198298 XLA_AE_LINES_PKG.g_LineNumber := 0;
198299 --
198300 --
198301 
198302 FOR Idx IN 1..l_array_event_id.count LOOP
198303    --
198304    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
198305    --
198306    l_event_id := l_array_event_id(idx);  -- 5648433
198307 
198308    --
198309    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
198310    --
198311 
198312    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
198313              (g_array_event(l_event_id).array_value_num('header_index'))
198314          ,'N'
198315          ) <> 'Y'
198316    THEN
198317       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
198318          trace
198319             (p_msg      => 'Trancaction revesal option is not Y '
198320             ,p_level    => C_LEVEL_STATEMENT
198321             ,p_module   => l_log_module);
198322       END IF;
198323 
198324 --
198325 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
198326 --
198327 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
198328 --
198329 -- set event info as cache for other routines to refer event attributes
198330 --
198331 
198332 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
198333    l_previous_event_id := l_event_id;
198334 
198335    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
198336       (p_application_id           => p_application_id
198337       ,p_primary_ledger_id        => p_primary_ledger_id
198338       ,p_base_ledger_id           => p_base_ledger_id
198339       ,p_target_ledger_id         => p_target_ledger_id
198340       ,p_entity_id                => l_array_entity_id(Idx)
198341       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
198342       ,p_entity_code              => l_array_entity_code(Idx)
198343       ,p_transaction_num          => l_array_transaction_num(Idx)
198344       ,p_event_id                 => l_array_event_id(Idx)
198345       ,p_event_class_code         => l_array_class_code(Idx)
198346       ,p_event_type_code          => l_array_event_type(Idx)
198347       ,p_event_number             => l_array_event_number(Idx)
198348       ,p_event_date               => l_array_event_date(Idx)
198349       ,p_transaction_date         => l_array_transaction_date(Idx)
198350       ,p_reference_num_1          => l_array_reference_num_1(Idx)
198351       ,p_reference_num_2          => l_array_reference_num_2(Idx)
198352       ,p_reference_num_3          => l_array_reference_num_3(Idx)
198353       ,p_reference_num_4          => l_array_reference_num_4(Idx)
198354       ,p_reference_char_1         => l_array_reference_char_1(Idx)
198355       ,p_reference_char_2         => l_array_reference_char_2(Idx)
198356       ,p_reference_char_3         => l_array_reference_char_3(Idx)
198357       ,p_reference_char_4         => l_array_reference_char_4(Idx)
198358       ,p_reference_date_1         => l_array_reference_date_1(Idx)
198359       ,p_reference_date_2         => l_array_reference_date_2(Idx)
198360       ,p_reference_date_3         => l_array_reference_date_3(Idx)
198361       ,p_reference_date_4         => l_array_reference_date_4(Idx)
198362       ,p_event_created_by         => l_array_event_created_by(Idx)
198363       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
198364        --
198365 END IF;
198366 
198367 
198368 
198369 --
198370 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
198371 
198372 l_acct_reversal_source := SUBSTR(NULL, 1,30);
198373 
198374 IF l_continue_with_lines THEN
198375    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
198376       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
198377 
198378       xla_accounting_err_pkg.build_message
198379          (p_appli_s_name            => 'XLA'
198380          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
198381          ,p_token_1                 => 'LINE_NUMBER'
198382          ,p_value_1                 => l_array_extract_line_num(Idx)
198383          ,p_token_2                 => 'PRODUCT_NAME'
198384          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
198385          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
198386          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
198387          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
198388 
198389    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
198390       --
198391       -- following sets the accounting attributes needed to reverse
198392       -- accounting for a distributeion
198393       --
198394 
198395       --
198396       -- 5217187
198397       --
198398       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
198399       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
198400                                        g_array_event(l_event_id).array_value_num('header_index'));
198401       --
198405 
198402       --
198403 
198404       -- No reversal code generated
198406       xla_ae_lines_pkg.SetAcctReversalAttrs
198407          (p_event_id             => l_event_id
198408          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
198409          ,p_calculate_acctd_flag => l_calculate_acctd_flag
198410          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
198411    END IF;
198412 
198413    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
198414        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
198415 
198416 --
198417 AcctLineType_259 (
198418  p_application_id  => p_application_id
198419  ,p_event_id     => l_event_id
198420  ,p_calculate_acctd_flag => l_calculate_acctd_flag
198421  ,p_calculate_g_l_flag => l_calculate_g_l_flag
198422  ,p_actual_flag => l_actual_flag
198423  ,p_balance_type_code => l_balance_type_code
198424  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
198425  
198426  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
198427  , p_source_3 => l_array_source_3(Idx)
198428  , p_source_15 => g_array_event(l_event_id).array_value_char('source_15')
198429  , p_source_29 => l_array_source_29(Idx)
198430  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
198431  , p_source_38 => l_array_source_38(Idx)
198432  , p_source_39 => l_array_source_39(Idx)
198433  , p_source_40 => l_array_source_40(Idx)
198434  , p_source_43 => l_array_source_43(Idx)
198435  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
198436  , p_source_45 => l_array_source_45(Idx)
198437  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
198438  , p_source_47 => l_array_source_47(Idx)
198439  );
198440 If(l_balance_type_code = 'A') THEN
198441   l_actual_gain_loss_ref := l_gain_or_loss_ref;
198442 END IF;
198443 
198444 --
198445 
198446 
198447 --
198448 AcctLineType_260 (
198449  p_application_id  => p_application_id
198450  ,p_event_id     => l_event_id
198451  ,p_calculate_acctd_flag => l_calculate_acctd_flag
198452  ,p_calculate_g_l_flag => l_calculate_g_l_flag
198453  ,p_actual_flag => l_actual_flag
198454  ,p_balance_type_code => l_balance_type_code
198455  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
198456  
198457  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
198458  , p_source_3 => l_array_source_3(Idx)
198459  , p_source_16 => g_array_event(l_event_id).array_value_char('source_16')
198460  , p_source_17 => l_array_source_17(Idx)
198461  , p_source_29 => l_array_source_29(Idx)
198462  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
198463  , p_source_38 => l_array_source_38(Idx)
198464  , p_source_39 => l_array_source_39(Idx)
198465  , p_source_40 => l_array_source_40(Idx)
198466  , p_source_43 => l_array_source_43(Idx)
198467  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
198468  , p_source_45 => l_array_source_45(Idx)
198469  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
198470  , p_source_47 => l_array_source_47(Idx)
198471  );
198472 If(l_balance_type_code = 'A') THEN
198473   l_actual_gain_loss_ref := l_gain_or_loss_ref;
198474 END IF;
198475 
198476 --
198477 
198478       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
198479       -- or secondary ledger that has different currency with primary
198480       -- or alc that is calculated by sla
198481       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
198482             (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'))
198483 
198484 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
198485 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
198486           AND (l_actual_flag = 'A')) THEN
198487         XLA_AE_LINES_PKG.CreateGainOrLossLines(
198488           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
198489          ,p_application_id   => p_application_id
198490          ,p_amb_context_code => 'DEFAULT'
198491          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
198492          ,p_event_class_code => C_EVENT_CLASS_CODE
198493          ,p_event_type_code  => C_EVENT_TYPE_CODE
198494          
198495          ,p_gain_ccid        => -1
198496          ,p_loss_ccid        => -1
198497 
198498          ,p_actual_flag      => l_actual_flag
198499          ,p_enc_flag         => null
198500          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
198501          ,p_enc_g_l_ref      => null
198502          );
198503       END IF;
198504    END IF;
198505 END IF;
198506 
198507    ELSE
198508       --
198509       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
198510       --
198511       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
198512          trace
198513             (p_msg      => 'Trancaction revesal option is Y'
198514             ,p_level    => C_LEVEL_STATEMENT
198515             ,p_module   => l_log_module);
198516       END IF;
198517    END IF;
198518 
198519 END LOOP;
198520 l_result := XLA_AE_LINES_PKG.InsertLines ;
198521 end loop;
198522 close line_cur;
198523 
198524 
198525 --
198526 -- insert headers into xla_ae_headers_gt table
198527 --
198528 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
198529 
198530 -- insert into errors table here.
198531 
198532 END LOOP;
198533 
198534 --
198535 -- 4865292
198536 --
198537 -- Compare g_hdr_extract_count with event count in
198538 -- CreateHeadersAndLines.
198539 --
198540 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
198541 
198542 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
198543    trace (p_msg     => '# rows extracted from header extract objects '
198547          ,p_module  => l_log_module);
198544                     || ' (running total): '
198545                     || g_hdr_extract_count
198546          ,p_level   => C_LEVEL_STATEMENT
198548 END IF;
198549 
198550 CLOSE header_cur;
198551 --
198552 
198553 --
198554 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
198555    trace
198556       (p_msg      => 'END of EventClass_420'
198557       ,p_level    => C_LEVEL_PROCEDURE
198558       ,p_module   => l_log_module);
198559 END IF;
198560 --
198561 RETURN l_result;
198562 EXCEPTION
198563 WHEN xla_exceptions_pkg.application_exception THEN
198564    
198565 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
198566 
198567    
198568 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
198569 
198570    RAISE;
198571 
198572 WHEN NO_DATA_FOUND THEN
198573 
198574 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
198575 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
198576 
198577 FOR header_record IN header_cur
198578 LOOP
198579     l_array_header_events(header_record.event_id) := header_record.event_id;
198580 END LOOP;
198581 
198582 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
198583 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
198584 
198585 fnd_file.put_line(fnd_file.LOG, '                    ');
198586 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
198587 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
198588 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
198589 
198590 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
198591 LOOP
198592 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
198593 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
198594         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
198595 	END IF;
198596 END LOOP;
198597 
198598 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
198599 fnd_file.put_line(fnd_file.LOG, '                    ');
198600 
198601 
198602 xla_exceptions_pkg.raise_message
198603       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_420');
198604 
198605 
198606 WHEN OTHERS THEN
198607    xla_exceptions_pkg.raise_message
198608       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_420');
198609 END EventClass_420;
198610 --
198611 
198612 ---------------------------------------
198613 --
198614 -- PRIVATE PROCEDURE
198615 --         insert_sources_421
198616 --
198617 ----------------------------------------
198618 --
198619 PROCEDURE insert_sources_421(
198620                                 p_target_ledger_id       IN NUMBER
198621                               , p_language               IN VARCHAR2
198622                               , p_sla_ledger_id          IN NUMBER
198623                               , p_pad_start_date         IN DATE
198624                               , p_pad_end_date           IN DATE
198625                          )
198626 IS
198627 
198628 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEPRECIATION_ADJUSTMENTS_ALL';
198629 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'DEPRECIATION_ADJUSTMENTS';
198630 p_apps_owner                   VARCHAR2(30);
198631 l_log_module                   VARCHAR2(240);
198632 BEGIN
198633 IF g_log_enabled THEN
198634       l_log_module := C_DEFAULT_MODULE||'.insert_sources_421';
198635 END IF;
198636 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
198637 
198638       trace
198639          (p_msg      => 'BEGIN of insert_sources_421'
198640          ,p_level    => C_LEVEL_PROCEDURE
198641          ,p_module   => l_log_module);
198642 
198643 END IF;
198644 
198645 -- select APPS owner
198646 SELECT oracle_username
198647   INTO p_apps_owner
198648   FROM fnd_oracle_userid
198649  WHERE read_only_flag = 'U'
198650 ;
198651 
198652 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
198653       trace
198654          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
198655                         ' - p_language = '||p_language||
198656                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
198657                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
198658                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
198659                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
198660          ,p_level    => C_LEVEL_STATEMENT
198661          ,p_module   => l_log_module);
198662 END IF;
198663 
198664 
198665 --
198666 INSERT INTO xla_diag_sources --hdr2
198667 (
198668         event_id
198669       , ledger_id
198670       , sla_ledger_id
198671       , description_language
198672       , object_name
198673       , object_type_code
198674       , line_number
198675       , source_application_id
198676       , source_type_code
198677       , source_code
198678       , source_value
198679       , source_meaning
198680       , created_by
198681       , creation_date
198682       , last_update_date
198683       , last_updated_by
198684       , last_update_login
198685       , program_update_date
198686       , program_application_id
198687       , program_id
198688       , request_id
198689 )
198690 SELECT
198691         event_id
198692       , p_target_ledger_id
198693       , p_sla_ledger_id
198694       , p_language
198695       , object_name
198696       , object_type_code
198697       , line_number
198698       , source_application_id
198699       , source_type_code
198700       , source_code
198701       , SUBSTR(source_value ,1,1996)
198702       , SUBSTR(source_meaning ,1,200)
198706       , xla_environment_pkg.g_Usr_Id
198703       , xla_environment_pkg.g_Usr_Id
198704       , TRUNC(SYSDATE)
198705       , TRUNC(SYSDATE)
198707       , xla_environment_pkg.g_Login_Id
198708       , TRUNC(SYSDATE)
198709       , xla_environment_pkg.g_Prog_Appl_Id
198710       , xla_environment_pkg.g_Prog_Id
198711       , xla_environment_pkg.g_Req_Id
198712   FROM (
198713        SELECT xet.event_id                  event_id
198714             , 0                          line_number
198715             , CASE r
198716                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
198717                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
198718                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
198719                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
198720                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
198721                 
198722                ELSE null
198723               END                           object_name
198724             , CASE r
198725                 WHEN 1 THEN 'HEADER' 
198726                 WHEN 2 THEN 'HEADER' 
198727                 WHEN 3 THEN 'HEADER' 
198728                 WHEN 4 THEN 'HEADER' 
198729                 WHEN 5 THEN 'HEADER' 
198730                 
198731                 ELSE null
198732               END                           object_type_code
198733             , CASE r
198734                 WHEN 1 THEN '140' 
198735                 WHEN 2 THEN '140' 
198736                 WHEN 3 THEN '140' 
198737                 WHEN 4 THEN '140' 
198738                 WHEN 5 THEN '140' 
198739                 
198740                 ELSE null
198741               END                           source_application_id
198742             , 'S'             source_type_code
198743             , CASE r
198744                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
198745                 WHEN 2 THEN 'DEPRN_ADJUSTMENT_ACCT' 
198746                 WHEN 3 THEN 'DEFAULT_CCID' 
198747                 WHEN 4 THEN 'ACCOUNTING_DATE' 
198748                 WHEN 5 THEN 'TRANSFER_TO_GL_FLAG' 
198749                 
198750                 ELSE null
198751               END                           source_code
198752             , CASE r
198753                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
198754                 WHEN 2 THEN TO_CHAR(h1.DEPRN_ADJUSTMENT_ACCT)
198755                 WHEN 3 THEN TO_CHAR(h1.DEFAULT_CCID)
198756                 WHEN 4 THEN TO_CHAR(h1.ACCOUNTING_DATE)
198757                 WHEN 5 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
198758                 
198759                 ELSE null
198760               END                           source_value
198761             , null              source_meaning
198762          FROM xla_events_gt     xet  
198763       , FA_XLA_EXT_HEADERS_B_GT  h1
198764              ,(select rownum r from all_objects where rownum <= 5 and owner = p_apps_owner)
198765          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
198766            AND xet.event_class_code = C_EVENT_CLASS_CODE
198767               AND h1.event_id = xet.event_id
198768 
198769 )
198770 ;
198771 --
198772 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
198773 
198774       trace
198775          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
198776          ,p_level    => C_LEVEL_STATEMENT
198777          ,p_module   => l_log_module);
198778 
198779 END IF;
198780 --
198781 
198782 
198783 
198784 --
198785 INSERT INTO xla_diag_sources  --line2
198786 (
198787         event_id
198788       , ledger_id
198789       , sla_ledger_id
198790       , description_language
198791       , object_name
198792       , object_type_code
198793       , line_number
198794       , source_application_id
198795       , source_type_code
198796       , source_code
198797       , source_value
198798       , source_meaning
198799       , created_by
198800       , creation_date
198801       , last_update_date
198802       , last_updated_by
198803       , last_update_login
198804       , program_update_date
198805       , program_application_id
198806       , program_id
198807       , request_id
198808 )
198809 SELECT  event_id
198810       , p_target_ledger_id
198811       , p_sla_ledger_id
198812       , p_language
198813       , object_name
198814       , object_type_code
198815       , line_number
198816       , source_application_id
198817       , source_type_code
198818       , source_code
198819       , SUBSTR(source_value,1,1996)
198820       , SUBSTR(source_meaning ,1,200)
198821       , xla_environment_pkg.g_Usr_Id
198822       , TRUNC(SYSDATE)
198823       , TRUNC(SYSDATE)
198824       , xla_environment_pkg.g_Usr_Id
198825       , xla_environment_pkg.g_Login_Id
198826       , TRUNC(SYSDATE)
198827       , xla_environment_pkg.g_Prog_Appl_Id
198828       , xla_environment_pkg.g_Prog_Id
198829       , xla_environment_pkg.g_Req_Id
198830   FROM (
198831        SELECT xet.event_id                  event_id
198832             , l2.line_number                 line_number
198833             , CASE r
198834                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
198835                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
198836                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
198837                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
198838                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
198839                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
198840                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
198841                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
198842                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
198843                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
198844                 
198845                ELSE null
198846               END                           object_name
198847             , CASE r
198848                 WHEN 1 THEN 'LINE' 
198849                 WHEN 2 THEN 'LINE' 
198850                 WHEN 3 THEN 'LINE' 
198854                 WHEN 7 THEN 'LINE' 
198851                 WHEN 4 THEN 'LINE' 
198852                 WHEN 5 THEN 'LINE' 
198853                 WHEN 6 THEN 'LINE' 
198855                 WHEN 8 THEN 'LINE' 
198856                 WHEN 9 THEN 'LINE' 
198857                 WHEN 10 THEN 'LINE' 
198858                 
198859                 ELSE null
198860               END                           object_type_code
198861             , CASE r
198862                 WHEN 1 THEN '140' 
198863                 WHEN 2 THEN '140' 
198864                 WHEN 3 THEN '140' 
198865                 WHEN 4 THEN '140' 
198866                 WHEN 5 THEN '140' 
198867                 WHEN 6 THEN '140' 
198868                 WHEN 7 THEN '140' 
198869                 WHEN 8 THEN '140' 
198870                 WHEN 9 THEN '140' 
198871                 WHEN 10 THEN '140' 
198872                 
198873                 ELSE null
198874               END                           source_application_id
198875             , 'S'             source_type_code
198876             , CASE r
198877                 WHEN 1 THEN 'GENERATED_CCID' 
198878                 WHEN 2 THEN 'DEPRN_RESERVE_ACCT' 
198879                 WHEN 3 THEN 'GENERATED_OFFSET_CCID' 
198880                 WHEN 4 THEN 'EXPENSE_ACCOUNT_CCID' 
198881                 WHEN 5 THEN 'ADJUSTMENT_TYPE' 
198882                 WHEN 6 THEN 'TRANSACTION_HEADER_ID' 
198883                 WHEN 7 THEN 'ADJUSTMENT_LINE_ID' 
198884                 WHEN 8 THEN 'DISTRIBUTION_TYPE_CODE' 
198885                 WHEN 9 THEN 'ENTERED_AMOUNT' 
198886                 WHEN 10 THEN 'CURRENCY_CODE' 
198887                 
198888                 ELSE null
198889               END                           source_code
198890             , CASE r
198891                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
198892                 WHEN 2 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
198893                 WHEN 3 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
198894                 WHEN 4 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
198895                 WHEN 5 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
198896                 WHEN 6 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
198897                 WHEN 7 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
198898                 WHEN 8 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
198899                 WHEN 9 THEN TO_CHAR(l2.ENTERED_AMOUNT)
198900                 WHEN 10 THEN TO_CHAR(l2.CURRENCY_CODE)
198901                 
198902                 ELSE null
198903               END                           source_value
198904             , null              source_meaning
198905          FROM  xla_events_gt     xet  
198906         , FA_XLA_EXT_LINES_B_GT  l2
198907             , (select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
198908         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
198909           AND xet.event_class_code = C_EVENT_CLASS_CODE
198910             AND l2.event_id          = xet.event_id
198911   AND l2.ledger_id (+)  = p_sla_ledger_id
198912 
198913 )
198914 ;
198915 --
198916 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
198917 
198918       trace
198919          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
198920          ,p_level    => C_LEVEL_STATEMENT
198921          ,p_module   => l_log_module);
198922 
198923 END IF;
198924 
198925 
198926 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
198927       trace
198928          (p_msg      => 'END of insert_sources_421'
198929          ,p_level    => C_LEVEL_PROCEDURE
198930          ,p_module   => l_log_module);
198931 END IF;
198932 EXCEPTION
198933   WHEN xla_exceptions_pkg.application_exception THEN
198934       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
198935             trace
198936                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
198937                ,p_level    => C_LEVEL_EXCEPTION
198938                ,p_module   => l_log_module);
198939       END IF;
198940       RAISE;
198941   WHEN OTHERS THEN
198942       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
198943             trace
198944                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
198945                ,p_level    => C_LEVEL_EXCEPTION
198946                ,p_module   => l_log_module);
198947        END IF;
198948        xla_exceptions_pkg.raise_message
198949            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_421');
198950 END insert_sources_421;
198951 --
198952 
198953 ---------------------------------------
198954 --
198955 -- PRIVATE FUNCTION
198956 --         EventClass_421
198957 --
198958 ----------------------------------------
198959 --
198960 FUNCTION EventClass_421
198961        (p_application_id         IN NUMBER
198962        ,p_base_ledger_id         IN NUMBER
198963        ,p_target_ledger_id       IN NUMBER
198964        ,p_language               IN VARCHAR2
198965        ,p_currency_code          IN VARCHAR2
198966        ,p_sla_ledger_id          IN NUMBER
198967        ,p_pad_start_date         IN DATE
198968        ,p_pad_end_date           IN DATE
198969        ,p_primary_ledger_id      IN NUMBER)
198970 RETURN BOOLEAN IS
198971 --
198972 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEPRECIATION_ADJUSTMENTS_ALL';
198973 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'DEPRECIATION_ADJUSTMENTS';
198974 
198975 l_calculate_acctd_flag   VARCHAR2(1) :='N';
198976 l_calculate_g_l_flag     VARCHAR2(1) :='N';
198977 --
198978 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
198979 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
198980 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
198981 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
198982 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
198983 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
198987 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
198984 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
198985 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
198986 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
198988 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
198989 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
198990 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
198991 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
198992 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
198993 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
198994 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
198995 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
198996 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
198997 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
198998 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
198999 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
199000 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
199001 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
199002 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
199003 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
199004 
199005 l_event_id                             NUMBER;
199006 l_previous_event_id                    NUMBER;
199007 l_first_event_id                       NUMBER;
199008 l_last_event_id                        NUMBER;
199009 
199010 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
199011 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
199012 --
199013 --
199014 l_result                    BOOLEAN := TRUE;
199015 l_rows                      NUMBER  := 1000;
199016 l_event_type_name           VARCHAR2(80) := 'All';
199017 l_event_class_name          VARCHAR2(80) := 'Depreciation Adjustments';
199018 l_description               VARCHAR2(4000);
199019 l_transaction_reversal      NUMBER;
199020 l_ae_header_id              NUMBER;
199021 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
199022 l_log_module                VARCHAR2(240);
199023 --
199024 l_acct_reversal_source      VARCHAR2(30);
199025 l_trx_reversal_source       VARCHAR2(30);
199026 
199027 l_continue_with_lines       BOOLEAN := TRUE;
199028 --
199029 l_acc_rev_gl_date_source    DATE;                      -- 4262811
199030 --
199031 type t_array_event_id is table of number index by binary_integer;
199032 
199033 l_rec_array_event                    t_rec_array_event;
199034 l_null_rec_array_event               t_rec_array_event;
199035 l_array_ae_header_id                 xla_number_array_type;
199036 l_actual_flag                        VARCHAR2(1) := NULL;
199037 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
199038 l_balance_type_code                  VARCHAR2(1) :=NULL;
199039 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
199040 
199041 --
199042 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
199043 --
199044 
199045 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
199046 TYPE t_array_source_18 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEPRN_ADJUSTMENT_ACCT%TYPE INDEX BY BINARY_INTEGER;
199047 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
199048 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
199049 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
199050 
199051 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
199052 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
199053 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
199054 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
199055 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
199056 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
199057 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
199058 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
199059 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
199060 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
199061 
199062 l_array_source_1              t_array_source_1;
199063 l_array_source_18              t_array_source_18;
199064 l_array_source_30              t_array_source_30;
199065 l_array_source_51              t_array_source_51;
199066 l_array_source_52              t_array_source_52;
199067 
199068 l_array_source_3      t_array_source_3;
199069 l_array_source_10      t_array_source_10;
199070 l_array_source_17      t_array_source_17;
199071 l_array_source_29      t_array_source_29;
199072 l_array_source_35      t_array_source_35;
199073 l_array_source_36      t_array_source_36;
199074 l_array_source_37      t_array_source_37;
199075 l_array_source_38      t_array_source_38;
199076 l_array_source_39      t_array_source_39;
199077 l_array_source_40      t_array_source_40;
199078 
199079 --
199080 CURSOR header_cur
199081 IS
199082 SELECT /*+ leading(xet) cardinality(xet,1) */
199083 -- Event Class Code: DEPRECIATION_ADJUSTMENTS
199084     xet.entity_id
199085    ,xet.legal_entity_id
199086    ,xet.entity_code
199087    ,xet.transaction_number
199091    ,xet.event_number
199088    ,xet.event_id
199089    ,xet.event_class_code
199090    ,xet.event_type_code
199092    ,xet.event_date
199093    ,xet.transaction_date
199094    ,xet.reference_num_1
199095    ,xet.reference_num_2
199096    ,xet.reference_num_3
199097    ,xet.reference_num_4
199098    ,xet.reference_char_1
199099    ,xet.reference_char_2
199100    ,xet.reference_char_3
199101    ,xet.reference_char_4
199102    ,xet.reference_date_1
199103    ,xet.reference_date_2
199104    ,xet.reference_date_3
199105    ,xet.reference_date_4
199106    ,xet.event_created_by
199107    ,xet.budgetary_control_flag 
199108   , h1.PERIOD_CLOSE_DATE    source_1
199109   , h1.DEPRN_ADJUSTMENT_ACCT    source_18
199110   , h1.DEFAULT_CCID    source_30
199111   , h1.ACCOUNTING_DATE    source_51
199112   , h1.TRANSFER_TO_GL_FLAG    source_52
199113   FROM xla_events_gt     xet 
199114   , FA_XLA_EXT_HEADERS_B_GT  h1
199115  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
199116    and xet.event_class_code = C_EVENT_CLASS_CODE
199117    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
199118 
199119  ORDER BY event_id
199120 ;
199121 
199122 
199123 --
199124 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
199125 IS
199126 SELECT  /*+ leading(xet) cardinality(xet,1) */
199127 -- Event Class Code: DEPRECIATION_ADJUSTMENTS
199128     xet.entity_id
199129    ,xet.legal_entity_id
199130    ,xet.entity_code
199131    ,xet.transaction_number
199132    ,xet.event_id
199133    ,xet.event_class_code
199134    ,xet.event_type_code
199135    ,xet.event_number
199136    ,xet.event_date
199137    ,xet.transaction_date
199138    ,xet.reference_num_1
199139    ,xet.reference_num_2
199140    ,xet.reference_num_3
199141    ,xet.reference_num_4
199142    ,xet.reference_char_1
199143    ,xet.reference_char_2
199144    ,xet.reference_char_3
199145    ,xet.reference_char_4
199146    ,xet.reference_date_1
199147    ,xet.reference_date_2
199148    ,xet.reference_date_3
199149    ,xet.reference_date_4
199150    ,xet.event_created_by
199151    ,xet.budgetary_control_flag
199152  , l2.LINE_NUMBER  
199153   , l2.GENERATED_CCID    source_3
199154   , l2.DEPRN_RESERVE_ACCT    source_10
199155   , l2.GENERATED_OFFSET_CCID    source_17
199156   , l2.EXPENSE_ACCOUNT_CCID    source_29
199157   , l2.ADJUSTMENT_TYPE    source_35
199158   , l2.TRANSACTION_HEADER_ID    source_36
199159   , l2.ADJUSTMENT_LINE_ID    source_37
199160   , l2.DISTRIBUTION_TYPE_CODE    source_38
199161   , l2.ENTERED_AMOUNT    source_39
199162   , l2.CURRENCY_CODE    source_40
199163   FROM xla_events_gt     xet 
199164   , FA_XLA_EXT_LINES_B_GT  l2
199165  WHERE xet.event_id between x_first_event_id and x_last_event_id
199166    and xet.event_date between p_pad_start_date and p_pad_end_date
199167    and xet.event_class_code = C_EVENT_CLASS_CODE
199168    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
199169   AND l2.ledger_id = p_sla_ledger_id
199170 ;
199171 
199172 --
199173 BEGIN
199174 IF g_log_enabled THEN
199175    l_log_module := C_DEFAULT_MODULE||'.EventClass_421';
199176 END IF;
199177 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
199178    trace
199179       (p_msg      => 'BEGIN of EventClass_421'
199180       ,p_level    => C_LEVEL_PROCEDURE
199181       ,p_module   => l_log_module);
199182 END IF;
199183 
199184 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
199185    trace
199186       (p_msg      => 'p_application_id = '||p_application_id||
199187                      ' - p_base_ledger_id = '||p_base_ledger_id||
199188                      ' - p_target_ledger_id  = '||p_target_ledger_id||
199189                      ' - p_language = '||p_language||
199190                      ' - p_currency_code = '||p_currency_code||
199191                      ' - p_sla_ledger_id = '||p_sla_ledger_id
199192       ,p_level    => C_LEVEL_STATEMENT
199193       ,p_module   => l_log_module);
199194 END IF;
199195 --
199196 -- initialze arrays
199197 --
199198 g_array_event.DELETE;
199199 l_rec_array_event := l_null_rec_array_event;
199200 --
199201 --------------------------------------
199202 -- 4262811 Initialze MPA Line Number
199203 --------------------------------------
199204 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
199205 
199206 --
199207 
199208 --
199209 OPEN header_cur;
199210 --
199211 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
199212    trace
199213    (p_msg      => 'SQL - FETCH header_cur'
199214    ,p_level    => C_LEVEL_STATEMENT
199215    ,p_module   => l_log_module);
199216 END IF;
199217 --
199218 LOOP
199219 FETCH header_cur BULK COLLECT INTO
199220         l_array_entity_id
199221       , l_array_legal_entity_id
199222       , l_array_entity_code
199223       , l_array_transaction_num
199224       , l_array_event_id
199225       , l_array_class_code
199226       , l_array_event_type
199227       , l_array_event_number
199228       , l_array_event_date
199229       , l_array_transaction_date
199230       , l_array_reference_num_1
199231       , l_array_reference_num_2
199232       , l_array_reference_num_3
199233       , l_array_reference_num_4
199234       , l_array_reference_char_1
199235       , l_array_reference_char_2
199236       , l_array_reference_char_3
199237       , l_array_reference_char_4
199238       , l_array_reference_date_1
199239       , l_array_reference_date_2
199240       , l_array_reference_date_3
199241       , l_array_reference_date_4
199242       , l_array_event_created_by
199243       , l_array_budgetary_control_flag 
199244       , l_array_source_1
199245       , l_array_source_18
199246       , l_array_source_30
199247       , l_array_source_51
199248       , l_array_source_52
199249       LIMIT l_rows;
199250 --
199254    ,p_level    => C_LEVEL_EVENT
199251 IF (C_LEVEL_EVENT >= g_log_level) THEN
199252    trace
199253    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
199255    ,p_module   => l_log_module);
199256 END IF;
199257 --
199258 EXIT WHEN l_array_entity_id.COUNT = 0;
199259 
199260 -- initialize arrays
199261 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
199262 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
199263 
199264 --
199265 -- Bug 4458708
199266 --
199267 XLA_AE_LINES_PKG.g_LineNumber := 0;
199268 
199269 
199270 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
199271 g_last_hdr_idx := l_array_event_id.LAST;
199272 --
199273 -- loop for the headers. Each iteration is for each header extract row
199274 -- fetched in header cursor
199275 --
199276 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
199277 
199278 --
199279 -- set event info as cache for other routines to refer event attributes
199280 --
199281 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
199282    (p_application_id           => p_application_id
199283    ,p_primary_ledger_id        => p_primary_ledger_id
199284    ,p_base_ledger_id           => p_base_ledger_id
199285    ,p_target_ledger_id         => p_target_ledger_id
199286    ,p_entity_id                => l_array_entity_id(hdr_idx)
199287    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
199288    ,p_entity_code              => l_array_entity_code(hdr_idx)
199289    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
199290    ,p_event_id                 => l_array_event_id(hdr_idx)
199291    ,p_event_class_code         => l_array_class_code(hdr_idx)
199292    ,p_event_type_code          => l_array_event_type(hdr_idx)
199293    ,p_event_number             => l_array_event_number(hdr_idx)
199294    ,p_event_date               => l_array_event_date(hdr_idx)
199295    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
199296    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
199297    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
199298    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
199299    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
199300    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
199301    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
199302    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
199303    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
199304    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
199305    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
199306    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
199307    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
199308    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
199309    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
199310 
199311 --
199312 -- set the status of entry to C_VALID (0)
199313 --
199314 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
199315 
199316 --
199317 -- initialize a row for ae header
199318 --
199319 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
199320 
199321 l_event_id := l_array_event_id(hdr_idx);
199322 
199323 --
199324 -- storing the hdr_idx for event. May be used by line cursor.
199325 --
199326 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
199327 
199328 --
199329 -- store sources from header extract. This can be improved to
199330 -- store only those sources from header extract that may be used in lines
199331 --
199332 
199333 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
199334 g_array_event(l_event_id).array_value_char('source_18') := l_array_source_18(hdr_idx);
199335 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
199336 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
199337 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
199338 
199339 --
199340 -- initilaize the status of ae headers for diffrent balance types
199341 -- the status is initialised to C_NOT_CREATED (2)
199342 --
199343 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
199344 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
199345 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
199346 
199347 --
199348 -- call api to validate and store accounting attributes for header
199349 --
199350 
199351 ------------------------------------------------------------
199352 -- Accrual Reversal : to get date for Standard Source (NONE)
199353 ------------------------------------------------------------
199354 l_acc_rev_gl_date_source := NULL;
199355 
199356      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
199357       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
199358      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
199359       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
199360 
199361 
199362 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
199363 
199364 XLA_AE_HEADER_PKG.SetJeCategoryName;
199365 
199366 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
199367 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
199368 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
199369 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
199370 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
199371 
199372 
199373 --
199377  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
199374 xla_ae_header_pkg.SetHdrDescription(
199375    p_description => Description_58 (
199376    p_application_id => p_application_id 
199378    )
199379 );
199380 --
199381 
199382 -- No header level analytical criteria
199383 
199384 --
199385 --accounting attribute enhancement, bug 3612931
199386 --
199387 l_trx_reversal_source := SUBSTR(NULL, 1,30);
199388 
199389 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
199390    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
199391 
199392    xla_accounting_err_pkg.build_message
199393       (p_appli_s_name            => 'XLA'
199394       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
199395       ,p_token_1                 => 'ACCT_ATTR_NAME'
199396       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
199397       ,p_token_2                 => 'PRODUCT_NAME'
199398       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
199399       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
199400       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
199401       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
199402 
199403 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
199404    --
199405    -- following sets the accounting attributes needed to reverse
199406    -- accounting for a distributeion
199407    --
199408    xla_ae_lines_pkg.SetTrxReversalAttrs
199409       (p_event_id              => l_event_id
199410       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
199411       ,p_trx_reversal_source   => l_trx_reversal_source);
199412 
199413 END IF;
199414 
199415 
199416 ----------------------------------------------------------------
199417 -- 4262811 -  update the header statuses to invalid in need be
199418 ----------------------------------------------------------------
199419 --
199420 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
199421 
199422 
199423   -----------------------------------------------
199424   -- No accrual reversal for the event class/type
199425   -----------------------------------------------
199426 ----------------------------------------------------------------
199427 
199428 --
199429 -- this ends the header loop iteration for one bulk fetch
199430 --
199431 END LOOP;
199432 
199433 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
199434 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
199435 
199436 --
199437 -- insert dummy rows into lines gt table that were created due to
199438 -- transaction reversals
199439 --
199440 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
199441    l_result := XLA_AE_LINES_PKG.InsertLines;
199442 END IF;
199443 
199444 --
199445 -- reset the temp_line_num for each set of events fetched from header
199446 -- cursor rather than doing it for each new event in line cursor
199447 -- Bug 3939231
199448 --
199449 xla_ae_lines_pkg.g_temp_line_num := 0;
199450 
199451 
199452 
199453 --
199454 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
199455 --
199456 --
199457 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
199458 
199459       trace
199460          (p_msg      => 'SQL - FETCH line_cur'
199461          ,p_level    => C_LEVEL_STATEMENT
199462          ,p_module   => l_log_module);
199463 
199464 END IF;
199465 --
199466 --
199467 LOOP
199468   --
199469   FETCH line_cur BULK COLLECT INTO
199470         l_array_entity_id
199471       , l_array_legal_entity_id
199472       , l_array_entity_code
199473       , l_array_transaction_num
199474       , l_array_event_id
199475       , l_array_class_code
199476       , l_array_event_type
199477       , l_array_event_number
199478       , l_array_event_date
199479       , l_array_transaction_date
199480       , l_array_reference_num_1
199481       , l_array_reference_num_2
199482       , l_array_reference_num_3
199483       , l_array_reference_num_4
199484       , l_array_reference_char_1
199485       , l_array_reference_char_2
199486       , l_array_reference_char_3
199487       , l_array_reference_char_4
199488       , l_array_reference_date_1
199489       , l_array_reference_date_2
199490       , l_array_reference_date_3
199491       , l_array_reference_date_4
199492       , l_array_event_created_by
199493       , l_array_budgetary_control_flag
199494       , l_array_extract_line_num 
199495       , l_array_source_3
199496       , l_array_source_10
199497       , l_array_source_17
199498       , l_array_source_29
199499       , l_array_source_35
199500       , l_array_source_36
199501       , l_array_source_37
199502       , l_array_source_38
199503       , l_array_source_39
199504       , l_array_source_40
199505       LIMIT l_rows;
199506 
199507   --
199508   IF (C_LEVEL_EVENT >= g_log_level) THEN
199509             trace
199510                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
199511                ,p_level    => C_LEVEL_EVENT
199512                ,p_module   => l_log_module);
199513   END IF;
199514   --
199515   EXIT WHEN l_array_entity_id.count = 0;
199516 
199517   XLA_AE_LINES_PKG.g_rec_lines := null;
199518 
199519 --
199520 -- Bug 4458708
199521 --
199522 XLA_AE_LINES_PKG.g_LineNumber := 0;
199523 --
199524 --
199525 
199526 FOR Idx IN 1..l_array_event_id.count LOOP
199527    --
199528    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
199529    --
199530    l_event_id := l_array_event_id(idx);  -- 5648433
199531 
199535 
199532    --
199533    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
199534    --
199536    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
199537              (g_array_event(l_event_id).array_value_num('header_index'))
199538          ,'N'
199539          ) <> 'Y'
199540    THEN
199541       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
199542          trace
199543             (p_msg      => 'Trancaction revesal option is not Y '
199544             ,p_level    => C_LEVEL_STATEMENT
199545             ,p_module   => l_log_module);
199546       END IF;
199547 
199548 --
199549 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
199550 --
199551 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
199552 --
199553 -- set event info as cache for other routines to refer event attributes
199554 --
199555 
199556 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
199557    l_previous_event_id := l_event_id;
199558 
199559    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
199560       (p_application_id           => p_application_id
199561       ,p_primary_ledger_id        => p_primary_ledger_id
199562       ,p_base_ledger_id           => p_base_ledger_id
199563       ,p_target_ledger_id         => p_target_ledger_id
199564       ,p_entity_id                => l_array_entity_id(Idx)
199565       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
199566       ,p_entity_code              => l_array_entity_code(Idx)
199567       ,p_transaction_num          => l_array_transaction_num(Idx)
199568       ,p_event_id                 => l_array_event_id(Idx)
199569       ,p_event_class_code         => l_array_class_code(Idx)
199570       ,p_event_type_code          => l_array_event_type(Idx)
199571       ,p_event_number             => l_array_event_number(Idx)
199572       ,p_event_date               => l_array_event_date(Idx)
199573       ,p_transaction_date         => l_array_transaction_date(Idx)
199574       ,p_reference_num_1          => l_array_reference_num_1(Idx)
199575       ,p_reference_num_2          => l_array_reference_num_2(Idx)
199576       ,p_reference_num_3          => l_array_reference_num_3(Idx)
199577       ,p_reference_num_4          => l_array_reference_num_4(Idx)
199578       ,p_reference_char_1         => l_array_reference_char_1(Idx)
199579       ,p_reference_char_2         => l_array_reference_char_2(Idx)
199580       ,p_reference_char_3         => l_array_reference_char_3(Idx)
199581       ,p_reference_char_4         => l_array_reference_char_4(Idx)
199582       ,p_reference_date_1         => l_array_reference_date_1(Idx)
199583       ,p_reference_date_2         => l_array_reference_date_2(Idx)
199584       ,p_reference_date_3         => l_array_reference_date_3(Idx)
199585       ,p_reference_date_4         => l_array_reference_date_4(Idx)
199586       ,p_event_created_by         => l_array_event_created_by(Idx)
199587       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
199588        --
199589 END IF;
199590 
199591 
199592 
199593 --
199594 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
199595 
199596 l_acct_reversal_source := SUBSTR(NULL, 1,30);
199597 
199598 IF l_continue_with_lines THEN
199599    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
199600       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
199601 
199602       xla_accounting_err_pkg.build_message
199603          (p_appli_s_name            => 'XLA'
199604          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
199605          ,p_token_1                 => 'LINE_NUMBER'
199606          ,p_value_1                 => l_array_extract_line_num(Idx)
199607          ,p_token_2                 => 'PRODUCT_NAME'
199608          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
199609          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
199610          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
199611          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
199612 
199613    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
199614       --
199615       -- following sets the accounting attributes needed to reverse
199616       -- accounting for a distributeion
199617       --
199618 
199619       --
199620       -- 5217187
199621       --
199622       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
199623       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
199624                                        g_array_event(l_event_id).array_value_num('header_index'));
199625       --
199626       --
199627 
199628       -- No reversal code generated
199629 
199630       xla_ae_lines_pkg.SetAcctReversalAttrs
199631          (p_event_id             => l_event_id
199632          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
199633          ,p_calculate_acctd_flag => l_calculate_acctd_flag
199634          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
199635    END IF;
199636 
199637    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
199638        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
199639 
199640 --
199641 AcctLineType_364 (
199642  p_application_id  => p_application_id
199643  ,p_event_id     => l_event_id
199644  ,p_calculate_acctd_flag => l_calculate_acctd_flag
199645  ,p_calculate_g_l_flag => l_calculate_g_l_flag
199646  ,p_actual_flag => l_actual_flag
199647  ,p_balance_type_code => l_balance_type_code
199648  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
199649  
199650  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
199651  , p_source_3 => l_array_source_3(Idx)
199652  , p_source_18 => g_array_event(l_event_id).array_value_char('source_18')
199653  , p_source_29 => l_array_source_29(Idx)
199654  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
199655  , p_source_35 => l_array_source_35(Idx)
199659  , p_source_39 => l_array_source_39(Idx)
199656  , p_source_36 => l_array_source_36(Idx)
199657  , p_source_37 => l_array_source_37(Idx)
199658  , p_source_38 => l_array_source_38(Idx)
199660  , p_source_40 => l_array_source_40(Idx)
199661  );
199662 If(l_balance_type_code = 'A') THEN
199663   l_actual_gain_loss_ref := l_gain_or_loss_ref;
199664 END IF;
199665 
199666 --
199667 
199668 
199669 --
199670 AcctLineType_365 (
199671  p_application_id  => p_application_id
199672  ,p_event_id     => l_event_id
199673  ,p_calculate_acctd_flag => l_calculate_acctd_flag
199674  ,p_calculate_g_l_flag => l_calculate_g_l_flag
199675  ,p_actual_flag => l_actual_flag
199676  ,p_balance_type_code => l_balance_type_code
199677  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
199678  
199679  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
199680  , p_source_3 => l_array_source_3(Idx)
199681  , p_source_10 => l_array_source_10(Idx)
199682  , p_source_17 => l_array_source_17(Idx)
199683  , p_source_29 => l_array_source_29(Idx)
199684  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
199685  , p_source_35 => l_array_source_35(Idx)
199686  , p_source_36 => l_array_source_36(Idx)
199687  , p_source_37 => l_array_source_37(Idx)
199688  , p_source_38 => l_array_source_38(Idx)
199689  , p_source_39 => l_array_source_39(Idx)
199690  , p_source_40 => l_array_source_40(Idx)
199691  );
199692 If(l_balance_type_code = 'A') THEN
199693   l_actual_gain_loss_ref := l_gain_or_loss_ref;
199694 END IF;
199695 
199696 --
199697 
199698       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
199699       -- or secondary ledger that has different currency with primary
199700       -- or alc that is calculated by sla
199701       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
199702             (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'))
199703 
199704 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
199705 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
199706           AND (l_actual_flag = 'A')) THEN
199707         XLA_AE_LINES_PKG.CreateGainOrLossLines(
199708           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
199709          ,p_application_id   => p_application_id
199710          ,p_amb_context_code => 'DEFAULT'
199711          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
199712          ,p_event_class_code => C_EVENT_CLASS_CODE
199713          ,p_event_type_code  => C_EVENT_TYPE_CODE
199714          
199715          ,p_gain_ccid        => -1
199716          ,p_loss_ccid        => -1
199717 
199718          ,p_actual_flag      => l_actual_flag
199719          ,p_enc_flag         => null
199720          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
199721          ,p_enc_g_l_ref      => null
199722          );
199723       END IF;
199724    END IF;
199725 END IF;
199726 
199727    ELSE
199728       --
199729       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
199730       --
199731       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
199732          trace
199733             (p_msg      => 'Trancaction revesal option is Y'
199734             ,p_level    => C_LEVEL_STATEMENT
199735             ,p_module   => l_log_module);
199736       END IF;
199737    END IF;
199738 
199739 END LOOP;
199740 l_result := XLA_AE_LINES_PKG.InsertLines ;
199741 end loop;
199742 close line_cur;
199743 
199744 
199745 --
199746 -- insert headers into xla_ae_headers_gt table
199747 --
199748 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
199749 
199750 -- insert into errors table here.
199751 
199752 END LOOP;
199753 
199754 --
199755 -- 4865292
199756 --
199757 -- Compare g_hdr_extract_count with event count in
199758 -- CreateHeadersAndLines.
199759 --
199760 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
199761 
199762 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
199763    trace (p_msg     => '# rows extracted from header extract objects '
199764                     || ' (running total): '
199765                     || g_hdr_extract_count
199766          ,p_level   => C_LEVEL_STATEMENT
199767          ,p_module  => l_log_module);
199768 END IF;
199769 
199770 CLOSE header_cur;
199771 --
199772 
199773 --
199774 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
199775    trace
199776       (p_msg      => 'END of EventClass_421'
199777       ,p_level    => C_LEVEL_PROCEDURE
199778       ,p_module   => l_log_module);
199779 END IF;
199780 --
199781 RETURN l_result;
199782 EXCEPTION
199783 WHEN xla_exceptions_pkg.application_exception THEN
199784    
199785 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
199786 
199787    
199788 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
199789 
199790    RAISE;
199791 
199792 WHEN NO_DATA_FOUND THEN
199793 
199794 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
199795 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
199796 
199797 FOR header_record IN header_cur
199798 LOOP
199799     l_array_header_events(header_record.event_id) := header_record.event_id;
199800 END LOOP;
199801 
199802 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
199803 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
199804 
199805 fnd_file.put_line(fnd_file.LOG, '                    ');
199806 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
199807 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
199811 LOOP
199808 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
199809 
199810 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
199812 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
199813 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
199814         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
199815 	END IF;
199816 END LOOP;
199817 
199818 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
199819 fnd_file.put_line(fnd_file.LOG, '                    ');
199820 
199821 
199822 xla_exceptions_pkg.raise_message
199823       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_421');
199824 
199825 
199826 WHEN OTHERS THEN
199827    xla_exceptions_pkg.raise_message
199828       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_421');
199829 END EventClass_421;
199830 --
199831 
199832 ---------------------------------------
199833 --
199834 -- PRIVATE PROCEDURE
199835 --         insert_sources_422
199836 --
199837 ----------------------------------------
199838 --
199839 PROCEDURE insert_sources_422(
199840                                 p_target_ledger_id       IN NUMBER
199841                               , p_language               IN VARCHAR2
199842                               , p_sla_ledger_id          IN NUMBER
199843                               , p_pad_start_date         IN DATE
199844                               , p_pad_end_date           IN DATE
199845                          )
199846 IS
199847 
199848 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEPRECIATION_ALL';
199849 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'DEPRECIATION';
199850 p_apps_owner                   VARCHAR2(30);
199851 l_log_module                   VARCHAR2(240);
199852 BEGIN
199853 IF g_log_enabled THEN
199854       l_log_module := C_DEFAULT_MODULE||'.insert_sources_422';
199855 END IF;
199856 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
199857 
199858       trace
199859          (p_msg      => 'BEGIN of insert_sources_422'
199860          ,p_level    => C_LEVEL_PROCEDURE
199861          ,p_module   => l_log_module);
199862 
199863 END IF;
199864 
199865 -- select APPS owner
199866 SELECT oracle_username
199867   INTO p_apps_owner
199868   FROM fnd_oracle_userid
199869  WHERE read_only_flag = 'U'
199870 ;
199871 
199872 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
199873       trace
199874          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
199875                         ' - p_language = '||p_language||
199876                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
199877                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
199878                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
199879                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
199880          ,p_level    => C_LEVEL_STATEMENT
199881          ,p_module   => l_log_module);
199882 END IF;
199883 
199884 
199885 --
199886 INSERT INTO xla_diag_sources --hdr2
199887 (
199888         event_id
199889       , ledger_id
199890       , sla_ledger_id
199891       , description_language
199892       , object_name
199893       , object_type_code
199894       , line_number
199895       , source_application_id
199896       , source_type_code
199897       , source_code
199898       , source_value
199899       , source_meaning
199900       , created_by
199901       , creation_date
199902       , last_update_date
199903       , last_updated_by
199904       , last_update_login
199905       , program_update_date
199906       , program_application_id
199907       , program_id
199908       , request_id
199909 )
199910 SELECT
199911         event_id
199912       , p_target_ledger_id
199913       , p_sla_ledger_id
199914       , p_language
199915       , object_name
199916       , object_type_code
199917       , line_number
199918       , source_application_id
199919       , source_type_code
199920       , source_code
199921       , SUBSTR(source_value ,1,1996)
199922       , SUBSTR(source_meaning ,1,200)
199923       , xla_environment_pkg.g_Usr_Id
199924       , TRUNC(SYSDATE)
199925       , TRUNC(SYSDATE)
199926       , xla_environment_pkg.g_Usr_Id
199927       , xla_environment_pkg.g_Login_Id
199928       , TRUNC(SYSDATE)
199929       , xla_environment_pkg.g_Prog_Appl_Id
199930       , xla_environment_pkg.g_Prog_Id
199931       , xla_environment_pkg.g_Req_Id
199932   FROM (
199933        SELECT xet.event_id                  event_id
199934             , 0                          line_number
199935             , CASE r
199936                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
199937                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
199938                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
199939                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
199940                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
199941                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
199942                 WHEN 7 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
199943                 
199944                ELSE null
199945               END                           object_name
199946             , CASE r
199947                 WHEN 1 THEN 'HEADER' 
199948                 WHEN 2 THEN 'HEADER' 
199949                 WHEN 3 THEN 'HEADER' 
199950                 WHEN 4 THEN 'HEADER' 
199951                 WHEN 5 THEN 'HEADER' 
199952                 WHEN 6 THEN 'HEADER' 
199953                 WHEN 7 THEN 'HEADER' 
199954                 
199955                 ELSE null
199956               END                           object_type_code
199957             , CASE r
199958                 WHEN 1 THEN '140' 
199962                 WHEN 5 THEN '140' 
199959                 WHEN 2 THEN '140' 
199960                 WHEN 3 THEN '140' 
199961                 WHEN 4 THEN '140' 
199963                 WHEN 6 THEN '140' 
199964                 WHEN 7 THEN '140' 
199965                 
199966                 ELSE null
199967               END                           source_application_id
199968             , 'S'             source_type_code
199969             , CASE r
199970                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
199971                 WHEN 2 THEN 'DEFAULT_CCID' 
199972                 WHEN 3 THEN 'PERIOD_COUNTER' 
199973                 WHEN 4 THEN 'BOOK_TYPE_CODE' 
199974                 WHEN 5 THEN 'ACCOUNTING_DATE' 
199975                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
199976                 WHEN 7 THEN 'REVERSAL_FLAG' 
199977                 
199978                 ELSE null
199979               END                           source_code
199980             , CASE r
199981                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
199982                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
199983                 WHEN 3 THEN TO_CHAR(h1.PERIOD_COUNTER)
199984                 WHEN 4 THEN TO_CHAR(h1.BOOK_TYPE_CODE)
199985                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
199986                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
199987                 WHEN 7 THEN TO_CHAR(h1.REVERSAL_FLAG)
199988                 
199989                 ELSE null
199990               END                           source_value
199991             , null              source_meaning
199992          FROM xla_events_gt     xet  
199993       , FA_XLA_EXT_HEADERS_B_GT  h1
199994              ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
199995          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
199996            AND xet.event_class_code = C_EVENT_CLASS_CODE
199997               AND h1.event_id = xet.event_id
199998 
199999 )
200000 ;
200001 --
200002 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
200003 
200004       trace
200005          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
200006          ,p_level    => C_LEVEL_STATEMENT
200007          ,p_module   => l_log_module);
200008 
200009 END IF;
200010 --
200011 
200012 
200013 
200014 --
200015 INSERT INTO xla_diag_sources  --line2
200016 (
200017         event_id
200018       , ledger_id
200019       , sla_ledger_id
200020       , description_language
200021       , object_name
200022       , object_type_code
200023       , line_number
200024       , source_application_id
200025       , source_type_code
200026       , source_code
200027       , source_value
200028       , source_meaning
200029       , created_by
200030       , creation_date
200031       , last_update_date
200032       , last_updated_by
200033       , last_update_login
200034       , program_update_date
200035       , program_application_id
200036       , program_id
200037       , request_id
200038 )
200039 SELECT  event_id
200040       , p_target_ledger_id
200041       , p_sla_ledger_id
200042       , p_language
200043       , object_name
200044       , object_type_code
200045       , line_number
200046       , source_application_id
200047       , source_type_code
200048       , source_code
200049       , SUBSTR(source_value,1,1996)
200050       , SUBSTR(source_meaning ,1,200)
200051       , xla_environment_pkg.g_Usr_Id
200052       , TRUNC(SYSDATE)
200053       , TRUNC(SYSDATE)
200054       , xla_environment_pkg.g_Usr_Id
200055       , xla_environment_pkg.g_Login_Id
200056       , TRUNC(SYSDATE)
200057       , xla_environment_pkg.g_Prog_Appl_Id
200058       , xla_environment_pkg.g_Prog_Id
200059       , xla_environment_pkg.g_Req_Id
200060   FROM (
200061        SELECT xet.event_id                  event_id
200062             , l2.line_number                 line_number
200063             , CASE r
200064                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
200065                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
200066                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
200067                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
200068                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
200069                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
200070                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
200071                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
200072                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
200073                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
200074                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
200075                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
200076                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
200077                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
200078                 WHEN 15 THEN 'FA_XLA_EXT_LINES_B_GT' 
200079                 WHEN 16 THEN 'FA_XLA_EXT_LINES_B_GT' 
200080                 WHEN 17 THEN 'FA_XLA_EXT_LINES_B_GT' 
200081                 WHEN 18 THEN 'FA_XLA_EXT_LINES_B_GT' 
200082                 WHEN 19 THEN 'FA_XLA_EXT_LINES_B_GT' 
200083                 WHEN 20 THEN 'FA_XLA_EXT_LINES_B_GT' 
200084                 
200085                ELSE null
200086               END                           object_name
200087             , CASE r
200088                 WHEN 1 THEN 'LINE' 
200089                 WHEN 2 THEN 'LINE' 
200090                 WHEN 3 THEN 'LINE' 
200091                 WHEN 4 THEN 'LINE' 
200092                 WHEN 5 THEN 'LINE' 
200093                 WHEN 6 THEN 'LINE' 
200094                 WHEN 7 THEN 'LINE' 
200095                 WHEN 8 THEN 'LINE' 
200096                 WHEN 9 THEN 'LINE' 
200097                 WHEN 10 THEN 'LINE' 
200098                 WHEN 11 THEN 'LINE' 
200099                 WHEN 12 THEN 'LINE' 
200100                 WHEN 13 THEN 'LINE' 
200101                 WHEN 14 THEN 'LINE' 
200102                 WHEN 15 THEN 'LINE' 
200106                 WHEN 19 THEN 'LINE' 
200103                 WHEN 16 THEN 'LINE' 
200104                 WHEN 17 THEN 'LINE' 
200105                 WHEN 18 THEN 'LINE' 
200107                 WHEN 20 THEN 'LINE' 
200108                 
200109                 ELSE null
200110               END                           object_type_code
200111             , CASE r
200112                 WHEN 1 THEN '140' 
200113                 WHEN 2 THEN '140' 
200114                 WHEN 3 THEN '140' 
200115                 WHEN 4 THEN '140' 
200116                 WHEN 5 THEN '140' 
200117                 WHEN 6 THEN '140' 
200118                 WHEN 7 THEN '140' 
200119                 WHEN 8 THEN '140' 
200120                 WHEN 9 THEN '140' 
200121                 WHEN 10 THEN '140' 
200122                 WHEN 11 THEN '140' 
200123                 WHEN 12 THEN '140' 
200124                 WHEN 13 THEN '140' 
200125                 WHEN 14 THEN '140' 
200126                 WHEN 15 THEN '140' 
200127                 WHEN 16 THEN '140' 
200128                 WHEN 17 THEN '140' 
200129                 WHEN 18 THEN '140' 
200130                 WHEN 19 THEN '140' 
200131                 WHEN 20 THEN '140' 
200132                 
200133                 ELSE null
200134               END                           source_application_id
200135             , 'S'             source_type_code
200136             , CASE r
200137                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
200138                 WHEN 2 THEN 'GENERATED_CCID' 
200139                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
200140                 WHEN 4 THEN 'DEPRN_RESERVE_ACCT' 
200141                 WHEN 5 THEN 'REVAL_RESERVE_ACCT' 
200142                 WHEN 6 THEN 'GENERATED_OFFSET_CCID' 
200143                 WHEN 7 THEN 'REVAL_AMORT_ACCT' 
200144                 WHEN 8 THEN 'EXPENSE_ACCOUNT_CCID' 
200145                 WHEN 9 THEN 'BONUS_GENERATED_CCID' 
200146                 WHEN 10 THEN 'BONUS_GENERATED_OFFSET_CCID' 
200147                 WHEN 11 THEN 'REVAL_GENERATED_CCID' 
200148                 WHEN 12 THEN 'REVAL_GENERATED_OFFSET_CCID' 
200149                 WHEN 13 THEN 'DISTRIBUTION_TYPE_CODE' 
200150                 WHEN 14 THEN 'ENTERED_AMOUNT' 
200151                 WHEN 15 THEN 'CURRENCY_CODE' 
200152                 WHEN 16 THEN 'ASSET_ID' 
200153                 WHEN 17 THEN 'DISTRIBUTION_ID' 
200154                 WHEN 18 THEN 'BONUS_ENTERED_AMOUNT' 
200155                 WHEN 19 THEN 'DEPRN_RUN_ID' 
200156                 WHEN 20 THEN 'REVAL_ENTERED_AMOUNT' 
200157                 
200158                 ELSE null
200159               END                           source_code
200160             , CASE r
200161                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
200162                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
200163                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
200164                 WHEN 4 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
200165                 WHEN 5 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
200166                 WHEN 6 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
200167                 WHEN 7 THEN TO_CHAR(l2.REVAL_AMORT_ACCT)
200168                 WHEN 8 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
200169                 WHEN 9 THEN TO_CHAR(l2.BONUS_GENERATED_CCID)
200170                 WHEN 10 THEN TO_CHAR(l2.BONUS_GENERATED_OFFSET_CCID)
200171                 WHEN 11 THEN TO_CHAR(l2.REVAL_GENERATED_CCID)
200172                 WHEN 12 THEN TO_CHAR(l2.REVAL_GENERATED_OFFSET_CCID)
200173                 WHEN 13 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
200174                 WHEN 14 THEN TO_CHAR(l2.ENTERED_AMOUNT)
200175                 WHEN 15 THEN TO_CHAR(l2.CURRENCY_CODE)
200176                 WHEN 16 THEN TO_CHAR(l2.ASSET_ID)
200177                 WHEN 17 THEN TO_CHAR(l2.DISTRIBUTION_ID)
200178                 WHEN 18 THEN TO_CHAR(l2.BONUS_ENTERED_AMOUNT)
200179                 WHEN 19 THEN TO_CHAR(l2.DEPRN_RUN_ID)
200180                 WHEN 20 THEN TO_CHAR(l2.REVAL_ENTERED_AMOUNT)
200181                 
200182                 ELSE null
200183               END                           source_value
200184             , null              source_meaning
200185          FROM  xla_events_gt     xet  
200186         , FA_XLA_EXT_LINES_B_GT  l2
200187             , (select rownum r from all_objects where rownum <= 20 and owner = p_apps_owner)
200188         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
200189           AND xet.event_class_code = C_EVENT_CLASS_CODE
200190             AND l2.event_id          = xet.event_id
200191   AND l2.ledger_id (+)  = p_sla_ledger_id
200192 
200193 )
200194 ;
200195 --
200196 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
200197 
200198       trace
200199          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
200200          ,p_level    => C_LEVEL_STATEMENT
200201          ,p_module   => l_log_module);
200202 
200203 END IF;
200204 
200205 
200206 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
200207       trace
200208          (p_msg      => 'END of insert_sources_422'
200209          ,p_level    => C_LEVEL_PROCEDURE
200210          ,p_module   => l_log_module);
200211 END IF;
200212 EXCEPTION
200213   WHEN xla_exceptions_pkg.application_exception THEN
200214       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
200215             trace
200216                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
200217                ,p_level    => C_LEVEL_EXCEPTION
200218                ,p_module   => l_log_module);
200219       END IF;
200220       RAISE;
200221   WHEN OTHERS THEN
200222       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
200223             trace
200224                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
200225                ,p_level    => C_LEVEL_EXCEPTION
200226                ,p_module   => l_log_module);
200227        END IF;
200228        xla_exceptions_pkg.raise_message
200229            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_422');
200230 END insert_sources_422;
200234 --
200231 --
200232 
200233 ---------------------------------------
200235 -- PRIVATE FUNCTION
200236 --         EventClass_422
200237 --
200238 ----------------------------------------
200239 --
200240 FUNCTION EventClass_422
200241        (p_application_id         IN NUMBER
200242        ,p_base_ledger_id         IN NUMBER
200243        ,p_target_ledger_id       IN NUMBER
200244        ,p_language               IN VARCHAR2
200245        ,p_currency_code          IN VARCHAR2
200246        ,p_sla_ledger_id          IN NUMBER
200247        ,p_pad_start_date         IN DATE
200248        ,p_pad_end_date           IN DATE
200249        ,p_primary_ledger_id      IN NUMBER)
200250 RETURN BOOLEAN IS
200251 --
200252 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEPRECIATION_ALL';
200253 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'DEPRECIATION';
200254 
200255 l_calculate_acctd_flag   VARCHAR2(1) :='N';
200256 l_calculate_g_l_flag     VARCHAR2(1) :='N';
200257 --
200258 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
200259 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
200260 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
200261 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
200262 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
200263 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
200264 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
200265 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
200266 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
200267 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
200268 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
200269 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
200270 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
200271 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
200272 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
200273 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
200274 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
200275 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
200276 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
200277 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
200278 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
200279 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
200280 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
200281 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
200282 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
200283 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
200284 
200285 l_event_id                             NUMBER;
200286 l_previous_event_id                    NUMBER;
200287 l_first_event_id                       NUMBER;
200288 l_last_event_id                        NUMBER;
200289 
200290 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
200291 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
200292 --
200293 --
200294 l_result                    BOOLEAN := TRUE;
200295 l_rows                      NUMBER  := 1000;
200296 l_event_type_name           VARCHAR2(80) := 'All';
200297 l_event_class_name          VARCHAR2(80) := 'Depreciation';
200298 l_description               VARCHAR2(4000);
200299 l_transaction_reversal      NUMBER;
200300 l_ae_header_id              NUMBER;
200301 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
200302 l_log_module                VARCHAR2(240);
200303 --
200304 l_acct_reversal_source      VARCHAR2(30);
200305 l_trx_reversal_source       VARCHAR2(30);
200306 
200307 l_continue_with_lines       BOOLEAN := TRUE;
200308 --
200309 l_acc_rev_gl_date_source    DATE;                      -- 4262811
200310 --
200311 type t_array_event_id is table of number index by binary_integer;
200312 
200313 l_rec_array_event                    t_rec_array_event;
200314 l_null_rec_array_event               t_rec_array_event;
200315 l_array_ae_header_id                 xla_number_array_type;
200316 l_actual_flag                        VARCHAR2(1) := NULL;
200317 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
200318 l_balance_type_code                  VARCHAR2(1) :=NULL;
200319 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
200320 
200321 --
200322 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
200323 --
200324 
200325 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
200326 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
200327 TYPE t_array_source_44 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_COUNTER%TYPE INDEX BY BINARY_INTEGER;
200328 TYPE t_array_source_46 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.BOOK_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
200329 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
200330 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
200331 TYPE t_array_source_53 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.REVERSAL_FLAG%TYPE INDEX BY BINARY_INTEGER;
200332 
200333 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
200334 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
200335 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
200336 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
200340 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
200337 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
200338 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
200339 TYPE t_array_source_26 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_AMORT_ACCT%TYPE INDEX BY BINARY_INTEGER;
200341 TYPE t_array_source_31 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
200342 TYPE t_array_source_32 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
200343 TYPE t_array_source_33 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
200344 TYPE t_array_source_34 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
200345 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
200346 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
200347 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
200348 TYPE t_array_source_43 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_ID%TYPE INDEX BY BINARY_INTEGER;
200349 TYPE t_array_source_45 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_ID%TYPE INDEX BY BINARY_INTEGER;
200350 TYPE t_array_source_48 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
200351 TYPE t_array_source_49 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RUN_ID%TYPE INDEX BY BINARY_INTEGER;
200352 TYPE t_array_source_50 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
200353 
200354 l_array_source_1              t_array_source_1;
200355 l_array_source_30              t_array_source_30;
200356 l_array_source_44              t_array_source_44;
200357 l_array_source_46              t_array_source_46;
200358 l_array_source_51              t_array_source_51;
200359 l_array_source_52              t_array_source_52;
200360 l_array_source_53              t_array_source_53;
200361 
200362 l_array_source_2      t_array_source_2;
200363 l_array_source_3      t_array_source_3;
200364 l_array_source_4      t_array_source_4;
200365 l_array_source_10      t_array_source_10;
200366 l_array_source_11      t_array_source_11;
200367 l_array_source_17      t_array_source_17;
200368 l_array_source_26      t_array_source_26;
200369 l_array_source_29      t_array_source_29;
200370 l_array_source_31      t_array_source_31;
200371 l_array_source_32      t_array_source_32;
200372 l_array_source_33      t_array_source_33;
200373 l_array_source_34      t_array_source_34;
200374 l_array_source_38      t_array_source_38;
200375 l_array_source_39      t_array_source_39;
200376 l_array_source_40      t_array_source_40;
200377 l_array_source_43      t_array_source_43;
200378 l_array_source_45      t_array_source_45;
200379 l_array_source_48      t_array_source_48;
200380 l_array_source_49      t_array_source_49;
200381 l_array_source_50      t_array_source_50;
200382 
200383 --
200384 CURSOR header_cur
200385 IS
200386 SELECT /*+ leading(xet) cardinality(xet,1) */
200387 -- Event Class Code: DEPRECIATION
200388     xet.entity_id
200389    ,xet.legal_entity_id
200390    ,xet.entity_code
200391    ,xet.transaction_number
200392    ,xet.event_id
200393    ,xet.event_class_code
200394    ,xet.event_type_code
200395    ,xet.event_number
200396    ,xet.event_date
200397    ,xet.transaction_date
200398    ,xet.reference_num_1
200399    ,xet.reference_num_2
200400    ,xet.reference_num_3
200401    ,xet.reference_num_4
200402    ,xet.reference_char_1
200403    ,xet.reference_char_2
200404    ,xet.reference_char_3
200405    ,xet.reference_char_4
200406    ,xet.reference_date_1
200407    ,xet.reference_date_2
200408    ,xet.reference_date_3
200409    ,xet.reference_date_4
200410    ,xet.event_created_by
200411    ,xet.budgetary_control_flag 
200412   , h1.PERIOD_CLOSE_DATE    source_1
200413   , h1.DEFAULT_CCID    source_30
200414   , h1.PERIOD_COUNTER    source_44
200415   , h1.BOOK_TYPE_CODE    source_46
200416   , h1.ACCOUNTING_DATE    source_51
200417   , h1.TRANSFER_TO_GL_FLAG    source_52
200418   , h1.REVERSAL_FLAG    source_53
200419   FROM xla_events_gt     xet 
200420   , FA_XLA_EXT_HEADERS_B_GT  h1
200421  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
200422    and xet.event_class_code = C_EVENT_CLASS_CODE
200423    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
200424 
200425  ORDER BY event_id
200426 ;
200427 
200428 
200429 --
200430 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
200431 IS
200432 SELECT  /*+ leading(xet) cardinality(xet,1) */
200433 -- Event Class Code: DEPRECIATION
200434     xet.entity_id
200435    ,xet.legal_entity_id
200436    ,xet.entity_code
200437    ,xet.transaction_number
200438    ,xet.event_id
200439    ,xet.event_class_code
200440    ,xet.event_type_code
200441    ,xet.event_number
200442    ,xet.event_date
200443    ,xet.transaction_date
200444    ,xet.reference_num_1
200445    ,xet.reference_num_2
200446    ,xet.reference_num_3
200447    ,xet.reference_num_4
200448    ,xet.reference_char_1
200449    ,xet.reference_char_2
200450    ,xet.reference_char_3
200451    ,xet.reference_char_4
200452    ,xet.reference_date_1
200453    ,xet.reference_date_2
200454    ,xet.reference_date_3
200455    ,xet.reference_date_4
200456    ,xet.event_created_by
200457    ,xet.budgetary_control_flag
200458  , l2.LINE_NUMBER  
200459   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
200460   , l2.GENERATED_CCID    source_3
200461   , l2.BONUS_RESERVE_ACCT    source_4
200462   , l2.DEPRN_RESERVE_ACCT    source_10
200463   , l2.REVAL_RESERVE_ACCT    source_11
200464   , l2.GENERATED_OFFSET_CCID    source_17
200465   , l2.REVAL_AMORT_ACCT    source_26
200466   , l2.EXPENSE_ACCOUNT_CCID    source_29
200467   , l2.BONUS_GENERATED_CCID    source_31
200471   , l2.DISTRIBUTION_TYPE_CODE    source_38
200468   , l2.BONUS_GENERATED_OFFSET_CCID    source_32
200469   , l2.REVAL_GENERATED_CCID    source_33
200470   , l2.REVAL_GENERATED_OFFSET_CCID    source_34
200472   , l2.ENTERED_AMOUNT    source_39
200473   , l2.CURRENCY_CODE    source_40
200474   , l2.ASSET_ID    source_43
200475   , l2.DISTRIBUTION_ID    source_45
200476   , l2.BONUS_ENTERED_AMOUNT    source_48
200477   , l2.DEPRN_RUN_ID    source_49
200478   , l2.REVAL_ENTERED_AMOUNT    source_50
200479   FROM xla_events_gt     xet 
200480   , FA_XLA_EXT_LINES_B_GT  l2
200481  WHERE xet.event_id between x_first_event_id and x_last_event_id
200482    and xet.event_date between p_pad_start_date and p_pad_end_date
200483    and xet.event_class_code = C_EVENT_CLASS_CODE
200484    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
200485   AND l2.ledger_id = p_sla_ledger_id
200486 ;
200487 
200488 --
200489 BEGIN
200490 IF g_log_enabled THEN
200491    l_log_module := C_DEFAULT_MODULE||'.EventClass_422';
200492 END IF;
200493 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
200494    trace
200495       (p_msg      => 'BEGIN of EventClass_422'
200496       ,p_level    => C_LEVEL_PROCEDURE
200497       ,p_module   => l_log_module);
200498 END IF;
200499 
200500 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
200501    trace
200502       (p_msg      => 'p_application_id = '||p_application_id||
200503                      ' - p_base_ledger_id = '||p_base_ledger_id||
200504                      ' - p_target_ledger_id  = '||p_target_ledger_id||
200505                      ' - p_language = '||p_language||
200506                      ' - p_currency_code = '||p_currency_code||
200507                      ' - p_sla_ledger_id = '||p_sla_ledger_id
200508       ,p_level    => C_LEVEL_STATEMENT
200509       ,p_module   => l_log_module);
200510 END IF;
200511 --
200512 -- initialze arrays
200513 --
200514 g_array_event.DELETE;
200515 l_rec_array_event := l_null_rec_array_event;
200516 --
200517 --------------------------------------
200518 -- 4262811 Initialze MPA Line Number
200519 --------------------------------------
200520 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
200521 
200522 --
200523 
200524 --
200525 OPEN header_cur;
200526 --
200527 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
200528    trace
200529    (p_msg      => 'SQL - FETCH header_cur'
200530    ,p_level    => C_LEVEL_STATEMENT
200531    ,p_module   => l_log_module);
200532 END IF;
200533 --
200534 LOOP
200535 FETCH header_cur BULK COLLECT INTO
200536         l_array_entity_id
200537       , l_array_legal_entity_id
200538       , l_array_entity_code
200539       , l_array_transaction_num
200540       , l_array_event_id
200541       , l_array_class_code
200542       , l_array_event_type
200543       , l_array_event_number
200544       , l_array_event_date
200545       , l_array_transaction_date
200546       , l_array_reference_num_1
200547       , l_array_reference_num_2
200548       , l_array_reference_num_3
200549       , l_array_reference_num_4
200550       , l_array_reference_char_1
200551       , l_array_reference_char_2
200552       , l_array_reference_char_3
200553       , l_array_reference_char_4
200554       , l_array_reference_date_1
200555       , l_array_reference_date_2
200556       , l_array_reference_date_3
200557       , l_array_reference_date_4
200558       , l_array_event_created_by
200559       , l_array_budgetary_control_flag 
200560       , l_array_source_1
200561       , l_array_source_30
200562       , l_array_source_44
200563       , l_array_source_46
200564       , l_array_source_51
200565       , l_array_source_52
200566       , l_array_source_53
200567       LIMIT l_rows;
200568 --
200569 IF (C_LEVEL_EVENT >= g_log_level) THEN
200570    trace
200571    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
200572    ,p_level    => C_LEVEL_EVENT
200573    ,p_module   => l_log_module);
200574 END IF;
200575 --
200576 EXIT WHEN l_array_entity_id.COUNT = 0;
200577 
200578 -- initialize arrays
200579 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
200580 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
200581 
200582 --
200583 -- Bug 4458708
200584 --
200585 XLA_AE_LINES_PKG.g_LineNumber := 0;
200586 
200587 
200588 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
200589 g_last_hdr_idx := l_array_event_id.LAST;
200590 --
200591 -- loop for the headers. Each iteration is for each header extract row
200592 -- fetched in header cursor
200593 --
200594 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
200595 
200596 --
200597 -- set event info as cache for other routines to refer event attributes
200598 --
200599 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
200600    (p_application_id           => p_application_id
200601    ,p_primary_ledger_id        => p_primary_ledger_id
200602    ,p_base_ledger_id           => p_base_ledger_id
200603    ,p_target_ledger_id         => p_target_ledger_id
200604    ,p_entity_id                => l_array_entity_id(hdr_idx)
200605    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
200606    ,p_entity_code              => l_array_entity_code(hdr_idx)
200607    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
200608    ,p_event_id                 => l_array_event_id(hdr_idx)
200609    ,p_event_class_code         => l_array_class_code(hdr_idx)
200610    ,p_event_type_code          => l_array_event_type(hdr_idx)
200611    ,p_event_number             => l_array_event_number(hdr_idx)
200612    ,p_event_date               => l_array_event_date(hdr_idx)
200613    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
200614    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
200615    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
200619    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
200616    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
200617    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
200618    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
200620    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
200621    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
200622    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
200623    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
200624    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
200625    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
200626    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
200627    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
200628 
200629 --
200630 -- set the status of entry to C_VALID (0)
200631 --
200632 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
200633 
200634 --
200635 -- initialize a row for ae header
200636 --
200637 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
200638 
200639 l_event_id := l_array_event_id(hdr_idx);
200640 
200641 --
200642 -- storing the hdr_idx for event. May be used by line cursor.
200643 --
200644 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
200645 
200646 --
200647 -- store sources from header extract. This can be improved to
200648 -- store only those sources from header extract that may be used in lines
200649 --
200650 
200651 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
200652 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
200653 g_array_event(l_event_id).array_value_num('source_44') := l_array_source_44(hdr_idx);
200654 g_array_event(l_event_id).array_value_char('source_46') := l_array_source_46(hdr_idx);
200655 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
200656 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
200657 g_array_event(l_event_id).array_value_char('source_53') := l_array_source_53(hdr_idx);
200658 
200659 --
200660 -- initilaize the status of ae headers for diffrent balance types
200661 -- the status is initialised to C_NOT_CREATED (2)
200662 --
200663 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
200664 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
200665 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
200666 
200667 --
200668 -- call api to validate and store accounting attributes for header
200669 --
200670 
200671 ------------------------------------------------------------
200672 -- Accrual Reversal : to get date for Standard Source (NONE)
200673 ------------------------------------------------------------
200674 l_acc_rev_gl_date_source := NULL;
200675 
200676      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
200677       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
200678      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
200679       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
200680      l_rec_acct_attrs.array_acct_attr_code(3)   := 'TRX_ACCT_REVERSAL_OPTION';
200681       l_rec_acct_attrs.array_char_value(3) := g_array_event(l_event_id).array_value_char('source_53');
200682 
200683 
200684 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
200685 
200686 XLA_AE_HEADER_PKG.SetJeCategoryName;
200687 
200688 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
200689 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
200690 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
200691 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
200692 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
200693 
200694 
200695 --
200696 xla_ae_header_pkg.SetHdrDescription(
200697    p_description => Description_57 (
200698    p_application_id => p_application_id 
200699  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
200700    )
200701 );
200702 --
200703 
200704 -- No header level analytical criteria
200705 
200706 --
200707 --accounting attribute enhancement, bug 3612931
200708 --
200709 l_trx_reversal_source := SUBSTR(g_array_event(l_event_id).array_value_char('source_53'), 1,30);
200710 
200711 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
200712    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
200713 
200714    xla_accounting_err_pkg.build_message
200715       (p_appli_s_name            => 'XLA'
200716       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
200717       ,p_token_1                 => 'ACCT_ATTR_NAME'
200718       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
200719       ,p_token_2                 => 'PRODUCT_NAME'
200720       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
200721       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
200722       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
200723       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
200724 
200725 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
200726    --
200727    -- following sets the accounting attributes needed to reverse
200728    -- accounting for a distributeion
200729    --
200730    xla_ae_lines_pkg.SetTrxReversalAttrs
200731       (p_event_id              => l_event_id
200732       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
200736 
200733       ,p_trx_reversal_source   => l_trx_reversal_source);
200734 
200735 END IF;
200737 
200738 ----------------------------------------------------------------
200739 -- 4262811 -  update the header statuses to invalid in need be
200740 ----------------------------------------------------------------
200741 --
200742 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
200743 
200744 
200745   -----------------------------------------------
200746   -- No accrual reversal for the event class/type
200747   -----------------------------------------------
200748 ----------------------------------------------------------------
200749 
200750 --
200751 -- this ends the header loop iteration for one bulk fetch
200752 --
200753 END LOOP;
200754 
200755 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
200756 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
200757 
200758 --
200759 -- insert dummy rows into lines gt table that were created due to
200760 -- transaction reversals
200761 --
200762 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
200763    l_result := XLA_AE_LINES_PKG.InsertLines;
200764 END IF;
200765 
200766 --
200767 -- reset the temp_line_num for each set of events fetched from header
200768 -- cursor rather than doing it for each new event in line cursor
200769 -- Bug 3939231
200770 --
200771 xla_ae_lines_pkg.g_temp_line_num := 0;
200772 
200773 
200774 
200775 --
200776 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
200777 --
200778 --
200779 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
200780 
200781       trace
200782          (p_msg      => 'SQL - FETCH line_cur'
200783          ,p_level    => C_LEVEL_STATEMENT
200784          ,p_module   => l_log_module);
200785 
200786 END IF;
200787 --
200788 --
200789 LOOP
200790   --
200791   FETCH line_cur BULK COLLECT INTO
200792         l_array_entity_id
200793       , l_array_legal_entity_id
200794       , l_array_entity_code
200795       , l_array_transaction_num
200796       , l_array_event_id
200797       , l_array_class_code
200798       , l_array_event_type
200799       , l_array_event_number
200800       , l_array_event_date
200801       , l_array_transaction_date
200802       , l_array_reference_num_1
200803       , l_array_reference_num_2
200804       , l_array_reference_num_3
200805       , l_array_reference_num_4
200806       , l_array_reference_char_1
200807       , l_array_reference_char_2
200808       , l_array_reference_char_3
200809       , l_array_reference_char_4
200810       , l_array_reference_date_1
200811       , l_array_reference_date_2
200812       , l_array_reference_date_3
200813       , l_array_reference_date_4
200814       , l_array_event_created_by
200815       , l_array_budgetary_control_flag
200816       , l_array_extract_line_num 
200817       , l_array_source_2
200818       , l_array_source_3
200819       , l_array_source_4
200820       , l_array_source_10
200821       , l_array_source_11
200822       , l_array_source_17
200823       , l_array_source_26
200824       , l_array_source_29
200825       , l_array_source_31
200826       , l_array_source_32
200827       , l_array_source_33
200828       , l_array_source_34
200829       , l_array_source_38
200830       , l_array_source_39
200831       , l_array_source_40
200832       , l_array_source_43
200833       , l_array_source_45
200834       , l_array_source_48
200835       , l_array_source_49
200836       , l_array_source_50
200837       LIMIT l_rows;
200838 
200839   --
200840   IF (C_LEVEL_EVENT >= g_log_level) THEN
200841             trace
200842                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
200843                ,p_level    => C_LEVEL_EVENT
200844                ,p_module   => l_log_module);
200845   END IF;
200846   --
200847   EXIT WHEN l_array_entity_id.count = 0;
200848 
200849   XLA_AE_LINES_PKG.g_rec_lines := null;
200850 
200851 --
200852 -- Bug 4458708
200853 --
200854 XLA_AE_LINES_PKG.g_LineNumber := 0;
200855 --
200856 --
200857 
200858 FOR Idx IN 1..l_array_event_id.count LOOP
200859    --
200860    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
200861    --
200862    l_event_id := l_array_event_id(idx);  -- 5648433
200863 
200864    --
200865    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
200866    --
200867 
200868    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
200869              (g_array_event(l_event_id).array_value_num('header_index'))
200870          ,'N'
200871          ) <> 'Y'
200872    THEN
200873       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
200874          trace
200875             (p_msg      => 'Trancaction revesal option is not Y '
200876             ,p_level    => C_LEVEL_STATEMENT
200877             ,p_module   => l_log_module);
200878       END IF;
200879 
200880 --
200881 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
200882 --
200883 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
200884 --
200885 -- set event info as cache for other routines to refer event attributes
200886 --
200887 
200888 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
200889    l_previous_event_id := l_event_id;
200890 
200891    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
200892       (p_application_id           => p_application_id
200893       ,p_primary_ledger_id        => p_primary_ledger_id
200894       ,p_base_ledger_id           => p_base_ledger_id
200895       ,p_target_ledger_id         => p_target_ledger_id
200896       ,p_entity_id                => l_array_entity_id(Idx)
200900       ,p_event_id                 => l_array_event_id(Idx)
200897       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
200898       ,p_entity_code              => l_array_entity_code(Idx)
200899       ,p_transaction_num          => l_array_transaction_num(Idx)
200901       ,p_event_class_code         => l_array_class_code(Idx)
200902       ,p_event_type_code          => l_array_event_type(Idx)
200903       ,p_event_number             => l_array_event_number(Idx)
200904       ,p_event_date               => l_array_event_date(Idx)
200905       ,p_transaction_date         => l_array_transaction_date(Idx)
200906       ,p_reference_num_1          => l_array_reference_num_1(Idx)
200907       ,p_reference_num_2          => l_array_reference_num_2(Idx)
200908       ,p_reference_num_3          => l_array_reference_num_3(Idx)
200909       ,p_reference_num_4          => l_array_reference_num_4(Idx)
200910       ,p_reference_char_1         => l_array_reference_char_1(Idx)
200911       ,p_reference_char_2         => l_array_reference_char_2(Idx)
200912       ,p_reference_char_3         => l_array_reference_char_3(Idx)
200913       ,p_reference_char_4         => l_array_reference_char_4(Idx)
200914       ,p_reference_date_1         => l_array_reference_date_1(Idx)
200915       ,p_reference_date_2         => l_array_reference_date_2(Idx)
200916       ,p_reference_date_3         => l_array_reference_date_3(Idx)
200917       ,p_reference_date_4         => l_array_reference_date_4(Idx)
200918       ,p_event_created_by         => l_array_event_created_by(Idx)
200919       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
200920        --
200921 END IF;
200922 
200923 
200924 
200925 --
200926 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
200927 
200928 l_acct_reversal_source := SUBSTR(NULL, 1,30);
200929 
200930 IF l_continue_with_lines THEN
200931    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
200932       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
200933 
200934       xla_accounting_err_pkg.build_message
200935          (p_appli_s_name            => 'XLA'
200936          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
200937          ,p_token_1                 => 'LINE_NUMBER'
200938          ,p_value_1                 => l_array_extract_line_num(Idx)
200939          ,p_token_2                 => 'PRODUCT_NAME'
200940          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
200941          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
200942          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
200943          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
200944 
200945    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
200946       --
200947       -- following sets the accounting attributes needed to reverse
200948       -- accounting for a distributeion
200949       --
200950 
200951       --
200952       -- 5217187
200953       --
200954       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
200955       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
200956                                        g_array_event(l_event_id).array_value_num('header_index'));
200957       --
200958       --
200959 
200960       -- No reversal code generated
200961 
200962       xla_ae_lines_pkg.SetAcctReversalAttrs
200963          (p_event_id             => l_event_id
200964          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
200965          ,p_calculate_acctd_flag => l_calculate_acctd_flag
200966          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
200967    END IF;
200968 
200969    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
200970        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
200971 
200972 --
200973 AcctLineType_265 (
200974  p_application_id  => p_application_id
200975  ,p_event_id     => l_event_id
200976  ,p_calculate_acctd_flag => l_calculate_acctd_flag
200977  ,p_calculate_g_l_flag => l_calculate_g_l_flag
200978  ,p_actual_flag => l_actual_flag
200979  ,p_balance_type_code => l_balance_type_code
200980  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
200981  
200982  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
200983  , p_source_2 => l_array_source_2(Idx)
200984  , p_source_3 => l_array_source_3(Idx)
200985  , p_source_29 => l_array_source_29(Idx)
200986  , p_source_31 => l_array_source_31(Idx)
200987  , p_source_38 => l_array_source_38(Idx)
200988  , p_source_40 => l_array_source_40(Idx)
200989  , p_source_43 => l_array_source_43(Idx)
200990  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
200991  , p_source_45 => l_array_source_45(Idx)
200992  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
200993  , p_source_48 => l_array_source_48(Idx)
200994  , p_source_49 => l_array_source_49(Idx)
200995  );
200996 If(l_balance_type_code = 'A') THEN
200997   l_actual_gain_loss_ref := l_gain_or_loss_ref;
200998 END IF;
200999 
201000 --
201001 
201002 
201003 --
201004 AcctLineType_266 (
201005  p_application_id  => p_application_id
201006  ,p_event_id     => l_event_id
201007  ,p_calculate_acctd_flag => l_calculate_acctd_flag
201008  ,p_calculate_g_l_flag => l_calculate_g_l_flag
201009  ,p_actual_flag => l_actual_flag
201010  ,p_balance_type_code => l_balance_type_code
201011  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
201012  
201013  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
201014  , p_source_3 => l_array_source_3(Idx)
201015  , p_source_4 => l_array_source_4(Idx)
201016  , p_source_29 => l_array_source_29(Idx)
201017  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
201018  , p_source_32 => l_array_source_32(Idx)
201019  , p_source_38 => l_array_source_38(Idx)
201020  , p_source_40 => l_array_source_40(Idx)
201021  , p_source_43 => l_array_source_43(Idx)
201025  , p_source_48 => l_array_source_48(Idx)
201022  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
201023  , p_source_45 => l_array_source_45(Idx)
201024  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
201026  , p_source_49 => l_array_source_49(Idx)
201027  );
201028 If(l_balance_type_code = 'A') THEN
201029   l_actual_gain_loss_ref := l_gain_or_loss_ref;
201030 END IF;
201031 
201032 --
201033 
201034 
201035 --
201036 AcctLineType_267 (
201037  p_application_id  => p_application_id
201038  ,p_event_id     => l_event_id
201039  ,p_calculate_acctd_flag => l_calculate_acctd_flag
201040  ,p_calculate_g_l_flag => l_calculate_g_l_flag
201041  ,p_actual_flag => l_actual_flag
201042  ,p_balance_type_code => l_balance_type_code
201043  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
201044  
201045  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
201046  , p_source_3 => l_array_source_3(Idx)
201047  , p_source_29 => l_array_source_29(Idx)
201048  , p_source_38 => l_array_source_38(Idx)
201049  , p_source_39 => l_array_source_39(Idx)
201050  , p_source_40 => l_array_source_40(Idx)
201051  , p_source_43 => l_array_source_43(Idx)
201052  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
201053  , p_source_45 => l_array_source_45(Idx)
201054  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
201055  , p_source_49 => l_array_source_49(Idx)
201056  );
201057 If(l_balance_type_code = 'A') THEN
201058   l_actual_gain_loss_ref := l_gain_or_loss_ref;
201059 END IF;
201060 
201061 --
201062 
201063 
201064 --
201065 AcctLineType_268 (
201066  p_application_id  => p_application_id
201067  ,p_event_id     => l_event_id
201068  ,p_calculate_acctd_flag => l_calculate_acctd_flag
201069  ,p_calculate_g_l_flag => l_calculate_g_l_flag
201070  ,p_actual_flag => l_actual_flag
201071  ,p_balance_type_code => l_balance_type_code
201072  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
201073  
201074  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
201075  , p_source_3 => l_array_source_3(Idx)
201076  , p_source_10 => l_array_source_10(Idx)
201077  , p_source_17 => l_array_source_17(Idx)
201078  , p_source_29 => l_array_source_29(Idx)
201079  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
201080  , p_source_38 => l_array_source_38(Idx)
201081  , p_source_39 => l_array_source_39(Idx)
201082  , p_source_40 => l_array_source_40(Idx)
201083  , p_source_43 => l_array_source_43(Idx)
201084  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
201085  , p_source_45 => l_array_source_45(Idx)
201086  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
201087  , p_source_49 => l_array_source_49(Idx)
201088  );
201089 If(l_balance_type_code = 'A') THEN
201090   l_actual_gain_loss_ref := l_gain_or_loss_ref;
201091 END IF;
201092 
201093 --
201094 
201095 
201096 --
201097 AcctLineType_269 (
201098  p_application_id  => p_application_id
201099  ,p_event_id     => l_event_id
201100  ,p_calculate_acctd_flag => l_calculate_acctd_flag
201101  ,p_calculate_g_l_flag => l_calculate_g_l_flag
201102  ,p_actual_flag => l_actual_flag
201103  ,p_balance_type_code => l_balance_type_code
201104  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
201105  
201106  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
201107  , p_source_3 => l_array_source_3(Idx)
201108  , p_source_26 => l_array_source_26(Idx)
201109  , p_source_29 => l_array_source_29(Idx)
201110  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
201111  , p_source_33 => l_array_source_33(Idx)
201112  , p_source_38 => l_array_source_38(Idx)
201113  , p_source_40 => l_array_source_40(Idx)
201114  , p_source_43 => l_array_source_43(Idx)
201115  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
201116  , p_source_45 => l_array_source_45(Idx)
201117  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
201118  , p_source_49 => l_array_source_49(Idx)
201119  , p_source_50 => l_array_source_50(Idx)
201120  );
201121 If(l_balance_type_code = 'A') THEN
201122   l_actual_gain_loss_ref := l_gain_or_loss_ref;
201123 END IF;
201124 
201125 --
201126 
201127 
201128 --
201129 AcctLineType_270 (
201130  p_application_id  => p_application_id
201131  ,p_event_id     => l_event_id
201132  ,p_calculate_acctd_flag => l_calculate_acctd_flag
201133  ,p_calculate_g_l_flag => l_calculate_g_l_flag
201134  ,p_actual_flag => l_actual_flag
201135  ,p_balance_type_code => l_balance_type_code
201136  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
201137  
201138  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
201139  , p_source_3 => l_array_source_3(Idx)
201140  , p_source_11 => l_array_source_11(Idx)
201141  , p_source_29 => l_array_source_29(Idx)
201142  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
201143  , p_source_34 => l_array_source_34(Idx)
201144  , p_source_38 => l_array_source_38(Idx)
201145  , p_source_40 => l_array_source_40(Idx)
201146  , p_source_43 => l_array_source_43(Idx)
201147  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
201148  , p_source_45 => l_array_source_45(Idx)
201149  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
201150  , p_source_49 => l_array_source_49(Idx)
201151  , p_source_50 => l_array_source_50(Idx)
201152  );
201153 If(l_balance_type_code = 'A') THEN
201154   l_actual_gain_loss_ref := l_gain_or_loss_ref;
201155 END IF;
201156 
201157 --
201158 
201159 
201160 --
201161 AcctLineType_271 (
201162  p_application_id  => p_application_id
201163  ,p_event_id     => l_event_id
201164  ,p_calculate_acctd_flag => l_calculate_acctd_flag
201165  ,p_calculate_g_l_flag => l_calculate_g_l_flag
201166  ,p_actual_flag => l_actual_flag
201167  ,p_balance_type_code => l_balance_type_code
201171  , p_source_3 => l_array_source_3(Idx)
201168  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
201169  
201170  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
201172  , p_source_29 => l_array_source_29(Idx)
201173  , p_source_38 => l_array_source_38(Idx)
201174  , p_source_40 => l_array_source_40(Idx)
201175  , p_source_43 => l_array_source_43(Idx)
201176  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
201177  , p_source_45 => l_array_source_45(Idx)
201178  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
201179  , p_source_48 => l_array_source_48(Idx)
201180  , p_source_49 => l_array_source_49(Idx)
201181  );
201182 If(l_balance_type_code = 'A') THEN
201183   l_actual_gain_loss_ref := l_gain_or_loss_ref;
201184 END IF;
201185 
201186 --
201187 
201188 
201189 --
201190 AcctLineType_272 (
201191  p_application_id  => p_application_id
201192  ,p_event_id     => l_event_id
201193  ,p_calculate_acctd_flag => l_calculate_acctd_flag
201194  ,p_calculate_g_l_flag => l_calculate_g_l_flag
201195  ,p_actual_flag => l_actual_flag
201196  ,p_balance_type_code => l_balance_type_code
201197  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
201198  
201199  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
201200  , p_source_3 => l_array_source_3(Idx)
201201  , p_source_10 => l_array_source_10(Idx)
201202  , p_source_17 => l_array_source_17(Idx)
201203  , p_source_29 => l_array_source_29(Idx)
201204  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
201205  , p_source_38 => l_array_source_38(Idx)
201206  , p_source_40 => l_array_source_40(Idx)
201207  , p_source_43 => l_array_source_43(Idx)
201208  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
201209  , p_source_45 => l_array_source_45(Idx)
201210  , p_source_46 => g_array_event(l_event_id).array_value_char('source_46')
201211  , p_source_48 => l_array_source_48(Idx)
201212  , p_source_49 => l_array_source_49(Idx)
201213  );
201214 If(l_balance_type_code = 'A') THEN
201215   l_actual_gain_loss_ref := l_gain_or_loss_ref;
201216 END IF;
201217 
201218 --
201219 
201220       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
201221       -- or secondary ledger that has different currency with primary
201222       -- or alc that is calculated by sla
201223       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
201224             (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'))
201225 
201226 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
201227 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
201228           AND (l_actual_flag = 'A')) THEN
201229         XLA_AE_LINES_PKG.CreateGainOrLossLines(
201230           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
201231          ,p_application_id   => p_application_id
201232          ,p_amb_context_code => 'DEFAULT'
201233          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
201234          ,p_event_class_code => C_EVENT_CLASS_CODE
201235          ,p_event_type_code  => C_EVENT_TYPE_CODE
201236          
201237          ,p_gain_ccid        => -1
201238          ,p_loss_ccid        => -1
201239 
201240          ,p_actual_flag      => l_actual_flag
201241          ,p_enc_flag         => null
201242          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
201243          ,p_enc_g_l_ref      => null
201244          );
201245       END IF;
201246    END IF;
201247 END IF;
201248 
201249    ELSE
201250       --
201251       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
201252       --
201253       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
201254          trace
201255             (p_msg      => 'Trancaction revesal option is Y'
201256             ,p_level    => C_LEVEL_STATEMENT
201257             ,p_module   => l_log_module);
201258       END IF;
201259    END IF;
201260 
201261 END LOOP;
201262 l_result := XLA_AE_LINES_PKG.InsertLines ;
201263 end loop;
201264 close line_cur;
201265 
201266 
201267 --
201268 -- insert headers into xla_ae_headers_gt table
201269 --
201270 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
201271 
201272 -- insert into errors table here.
201273 
201274 END LOOP;
201275 
201276 --
201277 -- 4865292
201278 --
201279 -- Compare g_hdr_extract_count with event count in
201280 -- CreateHeadersAndLines.
201281 --
201282 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
201283 
201284 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
201285    trace (p_msg     => '# rows extracted from header extract objects '
201286                     || ' (running total): '
201287                     || g_hdr_extract_count
201288          ,p_level   => C_LEVEL_STATEMENT
201289          ,p_module  => l_log_module);
201290 END IF;
201291 
201292 CLOSE header_cur;
201293 --
201294 
201295 --
201296 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
201297    trace
201298       (p_msg      => 'END of EventClass_422'
201299       ,p_level    => C_LEVEL_PROCEDURE
201300       ,p_module   => l_log_module);
201301 END IF;
201302 --
201303 RETURN l_result;
201304 EXCEPTION
201305 WHEN xla_exceptions_pkg.application_exception THEN
201306    
201307 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
201308 
201309    
201310 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
201311 
201312    RAISE;
201313 
201314 WHEN NO_DATA_FOUND THEN
201315 
201316 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
201317 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
201318 
201319 FOR header_record IN header_cur
201320 LOOP
201324 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
201321     l_array_header_events(header_record.event_id) := header_record.event_id;
201322 END LOOP;
201323 
201325 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
201326 
201327 fnd_file.put_line(fnd_file.LOG, '                    ');
201328 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
201329 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
201330 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
201331 
201332 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
201333 LOOP
201334 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
201335 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
201336         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
201337 	END IF;
201338 END LOOP;
201339 
201340 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
201341 fnd_file.put_line(fnd_file.LOG, '                    ');
201342 
201343 
201344 xla_exceptions_pkg.raise_message
201345       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_422');
201346 
201347 
201348 WHEN OTHERS THEN
201349    xla_exceptions_pkg.raise_message
201350       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_422');
201351 END EventClass_422;
201352 --
201353 
201354 ---------------------------------------
201355 --
201356 -- PRIVATE PROCEDURE
201357 --         insert_sources_423
201358 --
201359 ----------------------------------------
201360 --
201361 PROCEDURE insert_sources_423(
201362                                 p_target_ledger_id       IN NUMBER
201363                               , p_language               IN VARCHAR2
201364                               , p_sla_ledger_id          IN NUMBER
201365                               , p_pad_start_date         IN DATE
201366                               , p_pad_end_date           IN DATE
201367                          )
201368 IS
201369 
201370 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'REINSTATEMENTS';
201371 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'RETIREMENTS';
201372 p_apps_owner                   VARCHAR2(30);
201373 l_log_module                   VARCHAR2(240);
201374 BEGIN
201375 IF g_log_enabled THEN
201376       l_log_module := C_DEFAULT_MODULE||'.insert_sources_423';
201377 END IF;
201378 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
201379 
201380       trace
201381          (p_msg      => 'BEGIN of insert_sources_423'
201382          ,p_level    => C_LEVEL_PROCEDURE
201383          ,p_module   => l_log_module);
201384 
201385 END IF;
201386 
201387 -- select APPS owner
201388 SELECT oracle_username
201389   INTO p_apps_owner
201390   FROM fnd_oracle_userid
201391  WHERE read_only_flag = 'U'
201392 ;
201393 
201394 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
201395       trace
201396          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
201397                         ' - p_language = '||p_language||
201398                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
201399                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
201400                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
201401                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
201402          ,p_level    => C_LEVEL_STATEMENT
201403          ,p_module   => l_log_module);
201404 END IF;
201405 
201406 
201407 --
201408 INSERT INTO xla_diag_sources --hdr1
201409 (
201410         event_id
201411       , ledger_id
201412       , sla_ledger_id
201413       , description_language
201414       , object_name
201415       , object_type_code
201416       , line_number
201417       , source_application_id
201418       , source_type_code
201419       , source_code
201420       , source_value
201421       , source_meaning
201422       , created_by
201423       , creation_date
201424       , last_update_date
201425       , last_updated_by
201426       , last_update_login
201427       , program_update_date
201428       , program_application_id
201429       , program_id
201430       , request_id
201431 )
201432 SELECT
201433         event_id
201434       , p_target_ledger_id
201435       , p_sla_ledger_id
201436       , p_language
201437       , object_name
201438       , object_type_code
201439       , line_number
201440       , source_application_id
201441       , source_type_code
201442       , source_code
201443       , SUBSTR(source_value ,1,1996)
201444       , SUBSTR(source_meaning,1,200)
201445       , xla_environment_pkg.g_Usr_Id
201446       , TRUNC(SYSDATE)
201447       , TRUNC(SYSDATE)
201448       , xla_environment_pkg.g_Usr_Id
201449       , xla_environment_pkg.g_Login_Id
201450       , TRUNC(SYSDATE)
201451       , xla_environment_pkg.g_Prog_Appl_Id
201452       , xla_environment_pkg.g_Prog_Id
201453       , xla_environment_pkg.g_Req_Id
201454   FROM (
201455        SELECT xet.event_id                  event_id
201456             , 0                             line_number
201457             , CASE r
201458                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201459                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201460                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201461                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201462                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201463                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201464                 WHEN 7 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201465                 WHEN 8 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201466                 WHEN 9 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201470                 WHEN 13 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201467                 WHEN 10 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201468                 WHEN 11 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201469                 WHEN 12 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201471                 WHEN 14 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
201472                 
201473                ELSE null
201474               END                           object_name
201475             , CASE r
201476                 WHEN 1 THEN 'HEADER' 
201477                 WHEN 2 THEN 'HEADER' 
201478                 WHEN 3 THEN 'HEADER' 
201479                 WHEN 4 THEN 'HEADER' 
201480                 WHEN 5 THEN 'HEADER' 
201481                 WHEN 6 THEN 'HEADER' 
201482                 WHEN 7 THEN 'HEADER' 
201483                 WHEN 8 THEN 'HEADER' 
201484                 WHEN 9 THEN 'HEADER' 
201485                 WHEN 10 THEN 'HEADER' 
201486                 WHEN 11 THEN 'HEADER' 
201487                 WHEN 12 THEN 'HEADER' 
201488                 WHEN 13 THEN 'HEADER' 
201489                 WHEN 14 THEN 'HEADER' 
201490                 
201491                 ELSE null
201492               END                           object_type_code
201493             , CASE r
201494                 WHEN 1 THEN '140' 
201495                 WHEN 2 THEN '140' 
201496                 WHEN 3 THEN '140' 
201497                 WHEN 4 THEN '140' 
201498                 WHEN 5 THEN '140' 
201499                 WHEN 6 THEN '140' 
201500                 WHEN 7 THEN '140' 
201501                 WHEN 8 THEN '140' 
201502                 WHEN 9 THEN '140' 
201503                 WHEN 10 THEN '140' 
201504                 WHEN 11 THEN '140' 
201505                 WHEN 12 THEN '140' 
201506                 WHEN 13 THEN '140' 
201507                 WHEN 14 THEN '140' 
201508                 
201509                 ELSE null
201510               END                           source_application_id
201511             , 'S'             source_type_code
201512             , CASE r
201513                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
201514                 WHEN 2 THEN 'COST_OF_REMOVAL_CLEARING_ACCT' 
201515                 WHEN 3 THEN 'COST_OF_REMOVAL_GAIN_ACCT' 
201516                 WHEN 4 THEN 'COST_OF_REMOVAL_LOSS_ACCT' 
201517                 WHEN 5 THEN 'NBV_RETIRED_GAIN_ACCT' 
201518                 WHEN 6 THEN 'NBV_RETIRED_LOSS_ACCT' 
201519                 WHEN 7 THEN 'PROCEEDS_OF_SALE_CLEARING_ACCT' 
201520                 WHEN 8 THEN 'PROCEEDS_OF_SALE_GAIN_ACCT' 
201521                 WHEN 9 THEN 'PROCEEDS_OF_SALE_LOSS_ACCT' 
201522                 WHEN 10 THEN 'REVAL_RSV_RETIRED_GAIN_ACCT' 
201523                 WHEN 11 THEN 'REVAL_RSV_RETIRED_LOSS_ACCT' 
201524                 WHEN 12 THEN 'DEFAULT_CCID' 
201525                 WHEN 13 THEN 'ACCOUNTING_DATE' 
201526                 WHEN 14 THEN 'TRANSFER_TO_GL_FLAG' 
201527                 
201528                 ELSE null
201529               END                           source_code
201530             , CASE r
201531                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
201532                 WHEN 2 THEN TO_CHAR(h1.COST_OF_REMOVAL_CLEARING_ACCT)
201533                 WHEN 3 THEN TO_CHAR(h1.COST_OF_REMOVAL_GAIN_ACCT)
201534                 WHEN 4 THEN TO_CHAR(h1.COST_OF_REMOVAL_LOSS_ACCT)
201535                 WHEN 5 THEN TO_CHAR(h1.NBV_RETIRED_GAIN_ACCT)
201536                 WHEN 6 THEN TO_CHAR(h1.NBV_RETIRED_LOSS_ACCT)
201537                 WHEN 7 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_CLEARING_ACCT)
201538                 WHEN 8 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_GAIN_ACCT)
201539                 WHEN 9 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_LOSS_ACCT)
201540                 WHEN 10 THEN TO_CHAR(h1.REVAL_RSV_RETIRED_GAIN_ACCT)
201541                 WHEN 11 THEN TO_CHAR(h1.REVAL_RSV_RETIRED_LOSS_ACCT)
201542                 WHEN 12 THEN TO_CHAR(h1.DEFAULT_CCID)
201543                 WHEN 13 THEN TO_CHAR(h1.ACCOUNTING_DATE)
201544                 WHEN 14 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
201545                 
201546                 ELSE null
201547               END                           source_value
201548             , null              source_meaning
201549         FROM xla_events_gt     xet  
201550       , FA_XLA_EXT_HEADERS_B_GT  h1
201551             ,(select rownum r from all_objects where rownum <= 14 and owner = p_apps_owner)
201552        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
201553          AND xet.event_type_code = C_EVENT_TYPE_CODE
201554             AND h1.event_id = xet.event_id
201555 
201556 )
201557 ;
201558 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
201559 
201560       trace
201561          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
201562          ,p_level    => C_LEVEL_STATEMENT
201563          ,p_module   => l_log_module);
201564 
201565 END IF;
201566 --
201567 
201568 
201569 
201570 --
201571 INSERT INTO xla_diag_sources --line1
201572 (
201573         event_id
201574       , ledger_id
201575       , sla_ledger_id
201576       , description_language
201577       , object_name
201578       , object_type_code
201579       , line_number
201580       , source_application_id
201581       , source_type_code
201582       , source_code
201583       , source_value
201584       , source_meaning
201585       , created_by
201586       , creation_date
201587       , last_update_date
201588       , last_updated_by
201589       , last_update_login
201590       , program_update_date
201591       , program_application_id
201592       , program_id
201593       , request_id
201594 )
201595 SELECT  event_id
201596       , p_target_ledger_id
201597       , p_sla_ledger_id
201598       , p_language
201599       , object_name
201600       , object_type_code
201601       , line_number
201602       , source_application_id
201603       , source_type_code
201604       , source_code
201605       , SUBSTR(source_value,1,1996)
201609       , TRUNC(SYSDATE)
201606       , SUBSTR(source_meaning,1,200)
201607       , xla_environment_pkg.g_Usr_Id
201608       , TRUNC(SYSDATE)
201610       , xla_environment_pkg.g_Usr_Id
201611       , xla_environment_pkg.g_Login_Id
201612       , TRUNC(SYSDATE)
201613       , xla_environment_pkg.g_Prog_Appl_Id
201614       , xla_environment_pkg.g_Prog_Id
201615       , xla_environment_pkg.g_Req_Id
201616   FROM (
201617        SELECT xet.event_id                  event_id
201618             , l2.line_number                 line_number
201619             , CASE r
201620                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
201621                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
201622                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
201623                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
201624                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
201625                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
201626                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
201627                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
201628                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
201629                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
201630                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
201631                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
201632                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
201633                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
201634                 WHEN 15 THEN 'FA_XLA_EXT_LINES_B_GT' 
201635                 
201636                ELSE null
201637               END                           object_name
201638             , CASE r
201639                 WHEN 1 THEN 'LINE' 
201640                 WHEN 2 THEN 'LINE' 
201641                 WHEN 3 THEN 'LINE' 
201642                 WHEN 4 THEN 'LINE' 
201643                 WHEN 5 THEN 'LINE' 
201644                 WHEN 6 THEN 'LINE' 
201645                 WHEN 7 THEN 'LINE' 
201646                 WHEN 8 THEN 'LINE' 
201647                 WHEN 9 THEN 'LINE' 
201648                 WHEN 10 THEN 'LINE' 
201649                 WHEN 11 THEN 'LINE' 
201650                 WHEN 12 THEN 'LINE' 
201651                 WHEN 13 THEN 'LINE' 
201652                 WHEN 14 THEN 'LINE' 
201653                 WHEN 15 THEN 'LINE' 
201654                 
201655                 ELSE null
201656               END                           object_type_code
201657             , CASE r
201658                 WHEN 1 THEN '140' 
201659                 WHEN 2 THEN '140' 
201660                 WHEN 3 THEN '140' 
201661                 WHEN 4 THEN '140' 
201662                 WHEN 5 THEN '140' 
201663                 WHEN 6 THEN '140' 
201664                 WHEN 7 THEN '140' 
201665                 WHEN 8 THEN '140' 
201666                 WHEN 9 THEN '140' 
201667                 WHEN 10 THEN '140' 
201668                 WHEN 11 THEN '140' 
201669                 WHEN 12 THEN '140' 
201670                 WHEN 13 THEN '140' 
201671                 WHEN 14 THEN '140' 
201672                 WHEN 15 THEN '140' 
201673                 
201674                 ELSE null
201675               END                           source_application_id
201676             , 'S'             source_type_code
201677             , CASE r
201678                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
201679                 WHEN 2 THEN 'GENERATED_CCID' 
201680                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
201681                 WHEN 4 THEN 'ASSET_COST_ACCT' 
201682                 WHEN 5 THEN 'DEPRN_RESERVE_ACCT' 
201683                 WHEN 6 THEN 'REVAL_RESERVE_ACCT' 
201684                 WHEN 7 THEN 'GENERATED_OFFSET_CCID' 
201685                 WHEN 8 THEN 'EXPENSE_ACCOUNT_CCID' 
201686                 WHEN 9 THEN 'ADJUSTMENT_TYPE' 
201687                 WHEN 10 THEN 'TRANSACTION_HEADER_ID' 
201688                 WHEN 11 THEN 'ADJUSTMENT_LINE_ID' 
201689                 WHEN 12 THEN 'DISTRIBUTION_TYPE_CODE' 
201690                 WHEN 13 THEN 'ENTERED_AMOUNT' 
201691                 WHEN 14 THEN 'CURRENCY_CODE' 
201692                 WHEN 15 THEN 'GAIN_LOSS_AMOUNT' 
201693                 
201694                 ELSE null
201695               END                           source_code
201696             , CASE r
201697                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
201698                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
201699                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
201700                 WHEN 4 THEN TO_CHAR(l2.ASSET_COST_ACCT)
201701                 WHEN 5 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
201702                 WHEN 6 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
201703                 WHEN 7 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
201704                 WHEN 8 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
201705                 WHEN 9 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
201706                 WHEN 10 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
201707                 WHEN 11 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
201708                 WHEN 12 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
201709                 WHEN 13 THEN TO_CHAR(l2.ENTERED_AMOUNT)
201710                 WHEN 14 THEN TO_CHAR(l2.CURRENCY_CODE)
201711                 WHEN 15 THEN TO_CHAR(l2.GAIN_LOSS_AMOUNT)
201712                 
201713                 ELSE null
201714               END                           source_value
201715             , null              source_meaning
201716          FROM  xla_events_gt     xet  
201717         , FA_XLA_EXT_LINES_B_GT  l2
201718             ,(select rownum r from all_objects where rownum <= 15 and owner = p_apps_owner)
201719         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
201720           AND xet.event_type_code = C_EVENT_TYPE_CODE
201721             AND l2.event_id          = xet.event_id
201722   AND l2.ledger_id (+)  = p_sla_ledger_id
201723 
201724 )
201725 ;
201726 --
201727 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
201728 
201729       trace
201730          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
201731          ,p_level    => C_LEVEL_STATEMENT
201735 
201732          ,p_module   => l_log_module);
201733 
201734 END IF;
201736 
201737 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
201738       trace
201739          (p_msg      => 'END of insert_sources_423'
201740          ,p_level    => C_LEVEL_PROCEDURE
201741          ,p_module   => l_log_module);
201742 END IF;
201743 EXCEPTION
201744   WHEN xla_exceptions_pkg.application_exception THEN
201745       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
201746             trace
201747                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
201748                ,p_level    => C_LEVEL_EXCEPTION
201749                ,p_module   => l_log_module);
201750       END IF;
201751       RAISE;
201752   WHEN OTHERS THEN
201753       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
201754             trace
201755                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
201756                ,p_level    => C_LEVEL_EXCEPTION
201757                ,p_module   => l_log_module);
201758        END IF;
201759        xla_exceptions_pkg.raise_message
201760            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_423');
201761 END insert_sources_423;
201762 --
201763 
201764 ---------------------------------------
201765 --
201766 -- PRIVATE FUNCTION
201767 --         EventType_423
201768 --
201769 ----------------------------------------
201770 --
201771 FUNCTION EventType_423
201772        (p_application_id         IN NUMBER
201773        ,p_base_ledger_id         IN NUMBER
201774        ,p_target_ledger_id       IN NUMBER
201775        ,p_language               IN VARCHAR2
201776        ,p_currency_code          IN VARCHAR2
201777        ,p_sla_ledger_id          IN NUMBER
201778        ,p_pad_start_date         IN DATE
201779        ,p_pad_end_date           IN DATE
201780        ,p_primary_ledger_id      IN NUMBER)
201781 RETURN BOOLEAN IS
201782 --
201783 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'REINSTATEMENTS';
201784 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'RETIREMENTS';
201785 
201786 l_calculate_acctd_flag   VARCHAR2(1) :='N';
201787 l_calculate_g_l_flag     VARCHAR2(1) :='N';
201788 --
201789 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
201790 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
201791 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
201792 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
201793 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
201794 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
201795 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
201796 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
201797 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
201798 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
201799 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
201800 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
201801 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
201802 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
201803 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
201804 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
201805 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
201806 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
201807 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
201808 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
201809 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
201810 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
201811 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
201812 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
201813 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
201814 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
201815 
201816 l_event_id                             NUMBER;
201817 l_previous_event_id                    NUMBER;
201818 l_first_event_id                       NUMBER;
201819 l_last_event_id                        NUMBER;
201820 
201821 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
201822 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
201823 --
201824 --
201825 l_result                    BOOLEAN := TRUE;
201826 l_rows                      NUMBER  := 1000;
201827 l_event_type_name           VARCHAR2(80) := 'Reinstatements';
201828 l_event_class_name          VARCHAR2(80) := 'Retirements';
201829 l_description               VARCHAR2(4000);
201830 l_transaction_reversal      NUMBER;
201831 l_ae_header_id              NUMBER;
201832 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
201833 l_log_module                VARCHAR2(240);
201834 --
201835 l_acct_reversal_source      VARCHAR2(30);
201836 l_trx_reversal_source       VARCHAR2(30);
201837 
201838 l_continue_with_lines       BOOLEAN := TRUE;
201839 --
201840 l_acc_rev_gl_date_source    DATE;                      -- 4262811
201841 --
201842 type t_array_event_id is table of number index by binary_integer;
201843 
201844 l_rec_array_event                    t_rec_array_event;
201845 l_null_rec_array_event               t_rec_array_event;
201846 l_array_ae_header_id                 xla_number_array_type;
201847 l_actual_flag                        VARCHAR2(1) := NULL;
201848 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
201849 l_balance_type_code                  VARCHAR2(1) :=NULL;
201850 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
201851 
201852 --
201856 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
201853 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
201854 --
201855 
201857 TYPE t_array_source_12 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
201858 TYPE t_array_source_13 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
201859 TYPE t_array_source_14 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
201860 TYPE t_array_source_21 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
201861 TYPE t_array_source_22 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
201862 TYPE t_array_source_23 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
201863 TYPE t_array_source_24 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
201864 TYPE t_array_source_25 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
201865 TYPE t_array_source_27 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.REVAL_RSV_RETIRED_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
201866 TYPE t_array_source_28 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.REVAL_RSV_RETIRED_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
201867 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
201868 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
201869 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
201870 
201871 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
201872 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
201873 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
201874 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
201875 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
201876 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
201877 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
201878 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
201879 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
201880 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
201881 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
201882 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
201883 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
201884 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
201885 TYPE t_array_source_41 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GAIN_LOSS_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
201886 
201887 l_array_source_1              t_array_source_1;
201888 l_array_source_12              t_array_source_12;
201889 l_array_source_13              t_array_source_13;
201890 l_array_source_14              t_array_source_14;
201891 l_array_source_21              t_array_source_21;
201892 l_array_source_22              t_array_source_22;
201893 l_array_source_23              t_array_source_23;
201894 l_array_source_24              t_array_source_24;
201895 l_array_source_25              t_array_source_25;
201896 l_array_source_27              t_array_source_27;
201897 l_array_source_28              t_array_source_28;
201898 l_array_source_30              t_array_source_30;
201899 l_array_source_51              t_array_source_51;
201900 l_array_source_52              t_array_source_52;
201901 
201902 l_array_source_2      t_array_source_2;
201903 l_array_source_3      t_array_source_3;
201904 l_array_source_4      t_array_source_4;
201905 l_array_source_9      t_array_source_9;
201906 l_array_source_10      t_array_source_10;
201907 l_array_source_11      t_array_source_11;
201908 l_array_source_17      t_array_source_17;
201909 l_array_source_29      t_array_source_29;
201910 l_array_source_35      t_array_source_35;
201911 l_array_source_36      t_array_source_36;
201912 l_array_source_37      t_array_source_37;
201913 l_array_source_38      t_array_source_38;
201914 l_array_source_39      t_array_source_39;
201915 l_array_source_40      t_array_source_40;
201916 l_array_source_41      t_array_source_41;
201917 
201918 --
201919 CURSOR header_cur
201920 IS
201921 SELECT /*+ leading(xet) cardinality(xet,1) */
201922 -- Event Type Code: REINSTATEMENTS
201923 -- Event Class Code: RETIREMENTS
201924     xet.entity_id
201925   , xet.legal_entity_id
201926   , xet.entity_code
201927   , xet.transaction_number
201928   , xet.event_id
201929   , xet.event_class_code
201930   , xet.event_type_code
201931   , xet.event_number
201932   , xet.event_date
201933   , xet.transaction_date
201934   , xet.reference_num_1
201935   , xet.reference_num_2
201936   , xet.reference_num_3
201937   , xet.reference_num_4
201938   , xet.reference_char_1
201939   , xet.reference_char_2
201940   , xet.reference_char_3
201941   , xet.reference_char_4
201942   , xet.reference_date_1
201943   , xet.reference_date_2
201944   , xet.reference_date_3
201945   , xet.reference_date_4
201946   , xet.event_created_by
201947   , xet.budgetary_control_flag 
201948   , h1.PERIOD_CLOSE_DATE    source_1
201949   , h1.COST_OF_REMOVAL_CLEARING_ACCT    source_12
201950   , h1.COST_OF_REMOVAL_GAIN_ACCT    source_13
201951   , h1.COST_OF_REMOVAL_LOSS_ACCT    source_14
201952   , h1.NBV_RETIRED_GAIN_ACCT    source_21
201953   , h1.NBV_RETIRED_LOSS_ACCT    source_22
201954   , h1.PROCEEDS_OF_SALE_CLEARING_ACCT    source_23
201958   , h1.REVAL_RSV_RETIRED_LOSS_ACCT    source_28
201955   , h1.PROCEEDS_OF_SALE_GAIN_ACCT    source_24
201956   , h1.PROCEEDS_OF_SALE_LOSS_ACCT    source_25
201957   , h1.REVAL_RSV_RETIRED_GAIN_ACCT    source_27
201959   , h1.DEFAULT_CCID    source_30
201960   , h1.ACCOUNTING_DATE    source_51
201961   , h1.TRANSFER_TO_GL_FLAG    source_52
201962   FROM xla_events_gt     xet 
201963   , FA_XLA_EXT_HEADERS_B_GT  h1
201964  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
201965    and xet.event_type_code = C_EVENT_TYPE_CODE
201966    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
201967 
201968  ORDER BY event_id
201969 ;
201970 
201971 
201972 --
201973 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
201974 IS
201975 SELECT /*+ leading(xet) cardinality(xet,1) */
201976 -- Event Type Code: REINSTATEMENTS
201977 -- Event Class Code: RETIREMENTS
201978     xet.entity_id
201979    ,xet.legal_entity_id
201980    ,xet.entity_code
201981    ,xet.transaction_number
201982    ,xet.event_id
201983    ,xet.event_class_code
201984    ,xet.event_type_code
201985    ,xet.event_number
201986    ,xet.event_date
201987    ,xet.transaction_date
201988    ,xet.reference_num_1
201989    ,xet.reference_num_2
201990    ,xet.reference_num_3
201991    ,xet.reference_num_4
201992    ,xet.reference_char_1
201993    ,xet.reference_char_2
201994    ,xet.reference_char_3
201995    ,xet.reference_char_4
201996    ,xet.reference_date_1
201997    ,xet.reference_date_2
201998    ,xet.reference_date_3
201999    ,xet.reference_date_4
202000    ,xet.event_created_by
202001    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
202002   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
202003   , l2.GENERATED_CCID    source_3
202004   , l2.BONUS_RESERVE_ACCT    source_4
202005   , l2.ASSET_COST_ACCT    source_9
202006   , l2.DEPRN_RESERVE_ACCT    source_10
202007   , l2.REVAL_RESERVE_ACCT    source_11
202008   , l2.GENERATED_OFFSET_CCID    source_17
202009   , l2.EXPENSE_ACCOUNT_CCID    source_29
202010   , l2.ADJUSTMENT_TYPE    source_35
202011   , l2.TRANSACTION_HEADER_ID    source_36
202012   , l2.ADJUSTMENT_LINE_ID    source_37
202013   , l2.DISTRIBUTION_TYPE_CODE    source_38
202014   , l2.ENTERED_AMOUNT    source_39
202015   , l2.CURRENCY_CODE    source_40
202016   , l2.GAIN_LOSS_AMOUNT    source_41
202017   FROM xla_events_gt     xet 
202018   , FA_XLA_EXT_LINES_B_GT  l2
202019  WHERE xet.event_id between x_first_event_id and x_last_event_id
202020    and xet.event_date between p_pad_start_date and p_pad_end_date
202021    and xet.event_type_code = C_EVENT_TYPE_CODE
202022    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
202023   AND l2.ledger_id = p_sla_ledger_id
202024 ;
202025 
202026 --
202027 BEGIN
202028 IF g_log_enabled THEN
202029    l_log_module := C_DEFAULT_MODULE||'.EventType_423';
202030 END IF;
202031 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
202032    trace
202033       (p_msg      => 'BEGIN of EventType_423'
202034       ,p_level    => C_LEVEL_PROCEDURE
202035       ,p_module   => l_log_module);
202036 END IF;
202037 
202038 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
202039    trace
202040       (p_msg      => 'p_application_id = '||p_application_id||
202041                      ' - p_base_ledger_id = '||p_base_ledger_id||
202042                      ' - p_target_ledger_id  = '||p_target_ledger_id||
202043                      ' - p_language = '||p_language||
202044                      ' - p_currency_code = '||p_currency_code||
202045                      ' - p_sla_ledger_id = '||p_sla_ledger_id
202046       ,p_level    => C_LEVEL_STATEMENT
202047       ,p_module   => l_log_module);
202048 END IF;
202049 --
202050 -- initialze arrays
202051 --
202052 g_array_event.DELETE;
202053 l_rec_array_event := l_null_rec_array_event;
202054 --
202055 --------------------------------------
202056 -- 4262811 Initialze MPA Line Number
202057 --------------------------------------
202058 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
202059 
202060 --
202061 
202062 --
202063 OPEN header_cur;
202064 --
202065 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
202066    trace
202067    (p_msg      => 'SQL - FETCH header_cur'
202068    ,p_level    => C_LEVEL_STATEMENT
202069    ,p_module   => l_log_module);
202070 END IF;
202071 --
202072 LOOP
202073 FETCH header_cur BULK COLLECT INTO
202074         l_array_entity_id
202075       , l_array_legal_entity_id
202076       , l_array_entity_code
202077       , l_array_transaction_num
202078       , l_array_event_id
202079       , l_array_class_code
202080       , l_array_event_type
202081       , l_array_event_number
202082       , l_array_event_date
202083       , l_array_transaction_date
202084       , l_array_reference_num_1
202085       , l_array_reference_num_2
202086       , l_array_reference_num_3
202087       , l_array_reference_num_4
202088       , l_array_reference_char_1
202089       , l_array_reference_char_2
202090       , l_array_reference_char_3
202091       , l_array_reference_char_4
202092       , l_array_reference_date_1
202093       , l_array_reference_date_2
202094       , l_array_reference_date_3
202095       , l_array_reference_date_4
202096       , l_array_event_created_by
202097       , l_array_budgetary_control_flag 
202098       , l_array_source_1
202099       , l_array_source_12
202100       , l_array_source_13
202101       , l_array_source_14
202102       , l_array_source_21
202103       , l_array_source_22
202104       , l_array_source_23
202105       , l_array_source_24
202106       , l_array_source_25
202107       , l_array_source_27
202108       , l_array_source_28
202109       , l_array_source_30
202110       , l_array_source_51
202111       , l_array_source_52
202112       LIMIT l_rows;
202113 --
202117    ,p_level    => C_LEVEL_EVENT
202114 IF (C_LEVEL_EVENT >= g_log_level) THEN
202115    trace
202116    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
202118    ,p_module   => l_log_module);
202119 END IF;
202120 --
202121 EXIT WHEN l_array_entity_id.COUNT = 0;
202122 
202123 -- initialize arrays
202124 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
202125 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
202126 
202127 --
202128 -- Bug 4458708
202129 --
202130 XLA_AE_LINES_PKG.g_LineNumber := 0;
202131 
202132 
202133 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
202134 g_last_hdr_idx := l_array_event_id.LAST;
202135 --
202136 -- loop for the headers. Each iteration is for each header extract row
202137 -- fetched in header cursor
202138 --
202139 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
202140 
202141 --
202142 -- set event info as cache for other routines to refer event attributes
202143 --
202144 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
202145    (p_application_id           => p_application_id
202146    ,p_primary_ledger_id        => p_primary_ledger_id
202147    ,p_base_ledger_id           => p_base_ledger_id
202148    ,p_target_ledger_id         => p_target_ledger_id
202149    ,p_entity_id                => l_array_entity_id(hdr_idx)
202150    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
202151    ,p_entity_code              => l_array_entity_code(hdr_idx)
202152    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
202153    ,p_event_id                 => l_array_event_id(hdr_idx)
202154    ,p_event_class_code         => l_array_class_code(hdr_idx)
202155    ,p_event_type_code          => l_array_event_type(hdr_idx)
202156    ,p_event_number             => l_array_event_number(hdr_idx)
202157    ,p_event_date               => l_array_event_date(hdr_idx)
202158    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
202159    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
202160    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
202161    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
202162    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
202163    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
202164    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
202165    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
202166    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
202167    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
202168    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
202169    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
202170    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
202171    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
202172    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
202173 
202174 --
202175 -- set the status of entry to C_VALID (0)
202176 --
202177 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
202178 
202179 --
202180 -- initialize a row for ae header
202181 --
202182 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
202183 
202184 l_event_id := l_array_event_id(hdr_idx);
202185 
202186 --
202187 -- storing the hdr_idx for event. May be used by line cursor.
202188 --
202189 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
202190 
202191 --
202192 -- store sources from header extract. This can be improved to
202193 -- store only those sources from header extract that may be used in lines
202194 --
202195 
202196 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
202197 g_array_event(l_event_id).array_value_char('source_12') := l_array_source_12(hdr_idx);
202198 g_array_event(l_event_id).array_value_char('source_13') := l_array_source_13(hdr_idx);
202199 g_array_event(l_event_id).array_value_char('source_14') := l_array_source_14(hdr_idx);
202200 g_array_event(l_event_id).array_value_char('source_21') := l_array_source_21(hdr_idx);
202201 g_array_event(l_event_id).array_value_char('source_22') := l_array_source_22(hdr_idx);
202202 g_array_event(l_event_id).array_value_char('source_23') := l_array_source_23(hdr_idx);
202203 g_array_event(l_event_id).array_value_char('source_24') := l_array_source_24(hdr_idx);
202204 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
202205 g_array_event(l_event_id).array_value_char('source_27') := l_array_source_27(hdr_idx);
202206 g_array_event(l_event_id).array_value_char('source_28') := l_array_source_28(hdr_idx);
202207 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
202208 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
202209 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
202210 
202211 --
202212 -- initilaize the status of ae headers for diffrent balance types
202213 -- the status is initialised to C_NOT_CREATED (2)
202214 --
202215 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
202216 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
202217 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
202218 
202219 --
202220 -- call api to validate and store accounting attributes for header
202221 --
202222 
202223 ------------------------------------------------------------
202224 -- Accrual Reversal : to get date for Standard Source (NONE)
202225 ------------------------------------------------------------
202226 l_acc_rev_gl_date_source := NULL;
202227 
202228      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
202229       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
202230      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
202234 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
202231       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
202232 
202233 
202235 
202236 XLA_AE_HEADER_PKG.SetJeCategoryName;
202237 
202238 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
202239 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
202240 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
202241 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
202242 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
202243 
202244 
202245 --
202246 xla_ae_header_pkg.SetHdrDescription(
202247    p_description => Description_69 (
202248    p_application_id => p_application_id 
202249  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202250    )
202251 );
202252 --
202253 
202254 -- No header level analytical criteria
202255 
202256 --
202257 --accounting attribute enhancement, bug 3612931
202258 --
202259 l_trx_reversal_source := SUBSTR(NULL, 1,30);
202260 
202261 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
202262    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
202263 
202264    xla_accounting_err_pkg.build_message
202265       (p_appli_s_name            => 'XLA'
202266       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
202267       ,p_token_1                 => 'ACCT_ATTR_NAME'
202268       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
202269       ,p_token_2                 => 'PRODUCT_NAME'
202270       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
202271       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
202272       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
202273       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
202274 
202275 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
202276    --
202277    -- following sets the accounting attributes needed to reverse
202278    -- accounting for a distributeion
202279    --
202280    xla_ae_lines_pkg.SetTrxReversalAttrs
202281       (p_event_id              => l_event_id
202282       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
202283       ,p_trx_reversal_source   => l_trx_reversal_source);
202284 
202285 END IF;
202286 
202287 
202288 ----------------------------------------------------------------
202289 -- 4262811 -  update the header statuses to invalid in need be
202290 ----------------------------------------------------------------
202291 --
202292 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
202293 
202294 
202295   -----------------------------------------------
202296   -- No accrual reversal for the event class/type
202297   -----------------------------------------------
202298 ----------------------------------------------------------------
202299 
202300 --
202301 -- this ends the header loop iteration for one bulk fetch
202302 --
202303 END LOOP;
202304 
202305 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
202306 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
202307 
202308 --
202309 -- insert dummy rows into lines gt table that were created due to
202310 -- transaction reversals
202311 --
202312 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
202313    l_result := XLA_AE_LINES_PKG.InsertLines;
202314 END IF;
202315 
202316 --
202317 -- reset the temp_line_num for each set of events fetched from header
202318 -- cursor rather than doing it for each new event in line cursor
202319 -- Bug 3939231
202320 --
202321 xla_ae_lines_pkg.g_temp_line_num := 0;
202322 
202323 
202324 
202325 --
202326 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
202327 --
202328 --
202329 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
202330 
202331       trace
202332          (p_msg      => 'SQL - FETCH line_cur'
202333          ,p_level    => C_LEVEL_STATEMENT
202334          ,p_module   => l_log_module);
202335 
202336 END IF;
202337 --
202338 --
202339 LOOP
202340   --
202341   FETCH line_cur BULK COLLECT INTO
202342         l_array_entity_id
202343       , l_array_legal_entity_id
202344       , l_array_entity_code
202345       , l_array_transaction_num
202346       , l_array_event_id
202347       , l_array_class_code
202348       , l_array_event_type
202349       , l_array_event_number
202350       , l_array_event_date
202351       , l_array_transaction_date
202352       , l_array_reference_num_1
202353       , l_array_reference_num_2
202354       , l_array_reference_num_3
202355       , l_array_reference_num_4
202356       , l_array_reference_char_1
202357       , l_array_reference_char_2
202358       , l_array_reference_char_3
202359       , l_array_reference_char_4
202360       , l_array_reference_date_1
202361       , l_array_reference_date_2
202362       , l_array_reference_date_3
202363       , l_array_reference_date_4
202364       , l_array_event_created_by
202365       , l_array_budgetary_control_flag
202366       , l_array_extract_line_num 
202367       , l_array_source_2
202368       , l_array_source_3
202369       , l_array_source_4
202370       , l_array_source_9
202371       , l_array_source_10
202372       , l_array_source_11
202373       , l_array_source_17
202374       , l_array_source_29
202375       , l_array_source_35
202376       , l_array_source_36
202377       , l_array_source_37
202378       , l_array_source_38
202379       , l_array_source_39
202380       , l_array_source_40
202384   --
202381       , l_array_source_41
202382       LIMIT l_rows;
202383 
202385   IF (C_LEVEL_EVENT >= g_log_level) THEN
202386             trace
202387                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
202388                ,p_level    => C_LEVEL_EVENT
202389                ,p_module   => l_log_module);
202390   END IF;
202391   --
202392   EXIT WHEN l_array_entity_id.count = 0;
202393 
202394   XLA_AE_LINES_PKG.g_rec_lines := null;
202395 
202396 --
202397 -- Bug 4458708
202398 --
202399 XLA_AE_LINES_PKG.g_LineNumber := 0;
202400 --
202401 --
202402 
202403 FOR Idx IN 1..l_array_event_id.count LOOP
202404    --
202405    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
202406    --
202407    l_event_id := l_array_event_id(idx);  -- 5648433
202408 
202409    --
202410    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
202411    --
202412 
202413    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
202414              (g_array_event(l_event_id).array_value_num('header_index'))
202415          ,'N'
202416          ) <> 'Y'
202417    THEN
202418       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
202419          trace
202420             (p_msg      => 'Trancaction revesal option is not Y '
202421             ,p_level    => C_LEVEL_STATEMENT
202422             ,p_module   => l_log_module);
202423       END IF;
202424 
202425 --
202426 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
202427 --
202428 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
202429 --
202430 -- set event info as cache for other routines to refer event attributes
202431 --
202432 
202433 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
202434    l_previous_event_id := l_event_id;
202435 
202436    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
202437       (p_application_id           => p_application_id
202438       ,p_primary_ledger_id        => p_primary_ledger_id
202439       ,p_base_ledger_id           => p_base_ledger_id
202440       ,p_target_ledger_id         => p_target_ledger_id
202441       ,p_entity_id                => l_array_entity_id(Idx)
202442       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
202443       ,p_entity_code              => l_array_entity_code(Idx)
202444       ,p_transaction_num          => l_array_transaction_num(Idx)
202445       ,p_event_id                 => l_array_event_id(Idx)
202446       ,p_event_class_code         => l_array_class_code(Idx)
202447       ,p_event_type_code          => l_array_event_type(Idx)
202448       ,p_event_number             => l_array_event_number(Idx)
202449       ,p_event_date               => l_array_event_date(Idx)
202450       ,p_transaction_date         => l_array_transaction_date(Idx)
202451       ,p_reference_num_1          => l_array_reference_num_1(Idx)
202452       ,p_reference_num_2          => l_array_reference_num_2(Idx)
202453       ,p_reference_num_3          => l_array_reference_num_3(Idx)
202454       ,p_reference_num_4          => l_array_reference_num_4(Idx)
202455       ,p_reference_char_1         => l_array_reference_char_1(Idx)
202456       ,p_reference_char_2         => l_array_reference_char_2(Idx)
202457       ,p_reference_char_3         => l_array_reference_char_3(Idx)
202458       ,p_reference_char_4         => l_array_reference_char_4(Idx)
202459       ,p_reference_date_1         => l_array_reference_date_1(Idx)
202460       ,p_reference_date_2         => l_array_reference_date_2(Idx)
202461       ,p_reference_date_3         => l_array_reference_date_3(Idx)
202462       ,p_reference_date_4         => l_array_reference_date_4(Idx)
202463       ,p_event_created_by         => l_array_event_created_by(Idx)
202464       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
202465        --
202466 END IF;
202467 
202468 
202469 
202470 --
202471 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
202472 
202473 l_acct_reversal_source := SUBSTR(NULL, 1,30);
202474 
202475 IF l_continue_with_lines THEN
202476    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
202477       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
202478 
202479       xla_accounting_err_pkg.build_message
202480          (p_appli_s_name            => 'XLA'
202481          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
202482          ,p_token_1                 => 'LINE_NUMBER'
202483          ,p_value_1                 => l_array_extract_line_num(Idx)
202484          ,p_token_2                 => 'PRODUCT_NAME'
202485          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
202486          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
202487          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
202488          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
202489 
202490    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
202491       --
202492       -- following sets the accounting attributes needed to reverse
202493       -- accounting for a distributeion
202494       --
202495 
202496       --
202497       -- 5217187
202498       --
202499       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
202500       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
202501                                        g_array_event(l_event_id).array_value_num('header_index'));
202502       --
202503       --
202504 
202505       -- No reversal code generated
202506 
202507       xla_ae_lines_pkg.SetAcctReversalAttrs
202508          (p_event_id             => l_event_id
202509          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
202510          ,p_calculate_acctd_flag => l_calculate_acctd_flag
202511          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
202515        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
202512    END IF;
202513 
202514    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
202516 
202517 --
202518 AcctLineType_254 (
202519  p_application_id  => p_application_id
202520  ,p_event_id     => l_event_id
202521  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202522  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202523  ,p_actual_flag => l_actual_flag
202524  ,p_balance_type_code => l_balance_type_code
202525  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202526  
202527  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202528  , p_source_3 => l_array_source_3(Idx)
202529  , p_source_12 => g_array_event(l_event_id).array_value_char('source_12')
202530  , p_source_29 => l_array_source_29(Idx)
202531  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202532  , p_source_35 => l_array_source_35(Idx)
202533  , p_source_36 => l_array_source_36(Idx)
202534  , p_source_37 => l_array_source_37(Idx)
202535  , p_source_38 => l_array_source_38(Idx)
202536  , p_source_39 => l_array_source_39(Idx)
202537  , p_source_40 => l_array_source_40(Idx)
202538  );
202539 If(l_balance_type_code = 'A') THEN
202540   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202541 END IF;
202542 
202543 --
202544 
202545 
202546 --
202547 AcctLineType_256 (
202548  p_application_id  => p_application_id
202549  ,p_event_id     => l_event_id
202550  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202551  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202552  ,p_actual_flag => l_actual_flag
202553  ,p_balance_type_code => l_balance_type_code
202554  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202555  
202556  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202557  , p_source_3 => l_array_source_3(Idx)
202558  , p_source_13 => g_array_event(l_event_id).array_value_char('source_13')
202559  , p_source_29 => l_array_source_29(Idx)
202560  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202561  , p_source_35 => l_array_source_35(Idx)
202562  , p_source_36 => l_array_source_36(Idx)
202563  , p_source_37 => l_array_source_37(Idx)
202564  , p_source_38 => l_array_source_38(Idx)
202565  , p_source_39 => l_array_source_39(Idx)
202566  , p_source_40 => l_array_source_40(Idx)
202567  , p_source_41 => l_array_source_41(Idx)
202568  );
202569 If(l_balance_type_code = 'A') THEN
202570   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202571 END IF;
202572 
202573 --
202574 
202575 
202576 --
202577 AcctLineType_257 (
202578  p_application_id  => p_application_id
202579  ,p_event_id     => l_event_id
202580  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202581  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202582  ,p_actual_flag => l_actual_flag
202583  ,p_balance_type_code => l_balance_type_code
202584  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202585  
202586  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202587  , p_source_3 => l_array_source_3(Idx)
202588  , p_source_14 => g_array_event(l_event_id).array_value_char('source_14')
202589  , p_source_29 => l_array_source_29(Idx)
202590  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202591  , p_source_35 => l_array_source_35(Idx)
202592  , p_source_36 => l_array_source_36(Idx)
202593  , p_source_37 => l_array_source_37(Idx)
202594  , p_source_38 => l_array_source_38(Idx)
202595  , p_source_39 => l_array_source_39(Idx)
202596  , p_source_40 => l_array_source_40(Idx)
202597  , p_source_41 => l_array_source_41(Idx)
202598  );
202599 If(l_balance_type_code = 'A') THEN
202600   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202601 END IF;
202602 
202603 --
202604 
202605 
202606 --
202607 AcctLineType_262 (
202608  p_application_id  => p_application_id
202609  ,p_event_id     => l_event_id
202610  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202611  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202612  ,p_actual_flag => l_actual_flag
202613  ,p_balance_type_code => l_balance_type_code
202614  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202615  
202616  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202617  , p_source_3 => l_array_source_3(Idx)
202618  , p_source_21 => g_array_event(l_event_id).array_value_char('source_21')
202619  , p_source_29 => l_array_source_29(Idx)
202620  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202621  , p_source_35 => l_array_source_35(Idx)
202622  , p_source_36 => l_array_source_36(Idx)
202623  , p_source_37 => l_array_source_37(Idx)
202624  , p_source_38 => l_array_source_38(Idx)
202625  , p_source_39 => l_array_source_39(Idx)
202626  , p_source_40 => l_array_source_40(Idx)
202627  , p_source_41 => l_array_source_41(Idx)
202628  );
202629 If(l_balance_type_code = 'A') THEN
202630   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202631 END IF;
202632 
202633 --
202634 
202635 
202636 --
202637 AcctLineType_264 (
202638  p_application_id  => p_application_id
202639  ,p_event_id     => l_event_id
202640  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202641  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202642  ,p_actual_flag => l_actual_flag
202643  ,p_balance_type_code => l_balance_type_code
202644  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202645  
202646  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202647  , p_source_3 => l_array_source_3(Idx)
202648  , p_source_22 => g_array_event(l_event_id).array_value_char('source_22')
202649  , p_source_29 => l_array_source_29(Idx)
202650  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202651  , p_source_35 => l_array_source_35(Idx)
202652  , p_source_36 => l_array_source_36(Idx)
202653  , p_source_37 => l_array_source_37(Idx)
202654  , p_source_38 => l_array_source_38(Idx)
202655  , p_source_39 => l_array_source_39(Idx)
202656  , p_source_40 => l_array_source_40(Idx)
202660   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202657  , p_source_41 => l_array_source_41(Idx)
202658  );
202659 If(l_balance_type_code = 'A') THEN
202661 END IF;
202662 
202663 --
202664 
202665 
202666 --
202667 AcctLineType_274 (
202668  p_application_id  => p_application_id
202669  ,p_event_id     => l_event_id
202670  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202671  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202672  ,p_actual_flag => l_actual_flag
202673  ,p_balance_type_code => l_balance_type_code
202674  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202675  
202676  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202677  , p_source_3 => l_array_source_3(Idx)
202678  , p_source_23 => g_array_event(l_event_id).array_value_char('source_23')
202679  , p_source_29 => l_array_source_29(Idx)
202680  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202681  , p_source_35 => l_array_source_35(Idx)
202682  , p_source_36 => l_array_source_36(Idx)
202683  , p_source_37 => l_array_source_37(Idx)
202684  , p_source_38 => l_array_source_38(Idx)
202685  , p_source_39 => l_array_source_39(Idx)
202686  , p_source_40 => l_array_source_40(Idx)
202687  );
202688 If(l_balance_type_code = 'A') THEN
202689   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202690 END IF;
202691 
202692 --
202693 
202694 
202695 --
202696 AcctLineType_276 (
202697  p_application_id  => p_application_id
202698  ,p_event_id     => l_event_id
202699  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202700  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202701  ,p_actual_flag => l_actual_flag
202702  ,p_balance_type_code => l_balance_type_code
202703  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202704  
202705  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202706  , p_source_3 => l_array_source_3(Idx)
202707  , p_source_24 => g_array_event(l_event_id).array_value_char('source_24')
202708  , p_source_29 => l_array_source_29(Idx)
202709  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202710  , p_source_35 => l_array_source_35(Idx)
202711  , p_source_36 => l_array_source_36(Idx)
202712  , p_source_37 => l_array_source_37(Idx)
202713  , p_source_38 => l_array_source_38(Idx)
202714  , p_source_39 => l_array_source_39(Idx)
202715  , p_source_40 => l_array_source_40(Idx)
202716  , p_source_41 => l_array_source_41(Idx)
202717  );
202718 If(l_balance_type_code = 'A') THEN
202719   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202720 END IF;
202721 
202722 --
202723 
202724 
202725 --
202726 AcctLineType_278 (
202727  p_application_id  => p_application_id
202728  ,p_event_id     => l_event_id
202729  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202730  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202731  ,p_actual_flag => l_actual_flag
202732  ,p_balance_type_code => l_balance_type_code
202733  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202734  
202735  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202736  , p_source_3 => l_array_source_3(Idx)
202737  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
202738  , p_source_29 => l_array_source_29(Idx)
202739  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202740  , p_source_35 => l_array_source_35(Idx)
202741  , p_source_36 => l_array_source_36(Idx)
202742  , p_source_37 => l_array_source_37(Idx)
202743  , p_source_38 => l_array_source_38(Idx)
202744  , p_source_39 => l_array_source_39(Idx)
202745  , p_source_40 => l_array_source_40(Idx)
202746  , p_source_41 => l_array_source_41(Idx)
202747  );
202748 If(l_balance_type_code = 'A') THEN
202749   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202750 END IF;
202751 
202752 --
202753 
202754 
202755 --
202756 AcctLineType_296 (
202757  p_application_id  => p_application_id
202758  ,p_event_id     => l_event_id
202759  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202760  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202761  ,p_actual_flag => l_actual_flag
202762  ,p_balance_type_code => l_balance_type_code
202763  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202764  
202765  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202766  , p_source_2 => l_array_source_2(Idx)
202767  , p_source_3 => l_array_source_3(Idx)
202768  , p_source_29 => l_array_source_29(Idx)
202769  , p_source_35 => l_array_source_35(Idx)
202770  , p_source_36 => l_array_source_36(Idx)
202771  , p_source_37 => l_array_source_37(Idx)
202772  , p_source_38 => l_array_source_38(Idx)
202773  , p_source_39 => l_array_source_39(Idx)
202774  , p_source_40 => l_array_source_40(Idx)
202775  );
202776 If(l_balance_type_code = 'A') THEN
202777   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202778 END IF;
202779 
202780 --
202781 
202782 
202783 --
202784 AcctLineType_297 (
202785  p_application_id  => p_application_id
202786  ,p_event_id     => l_event_id
202787  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202788  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202789  ,p_actual_flag => l_actual_flag
202790  ,p_balance_type_code => l_balance_type_code
202791  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202792  
202793  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202794  , p_source_3 => l_array_source_3(Idx)
202795  , p_source_4 => l_array_source_4(Idx)
202796  , p_source_17 => l_array_source_17(Idx)
202797  , p_source_29 => l_array_source_29(Idx)
202798  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202799  , p_source_35 => l_array_source_35(Idx)
202800  , p_source_36 => l_array_source_36(Idx)
202801  , p_source_37 => l_array_source_37(Idx)
202802  , p_source_38 => l_array_source_38(Idx)
202803  , p_source_39 => l_array_source_39(Idx)
202804  , p_source_40 => l_array_source_40(Idx)
202805  );
202806 If(l_balance_type_code = 'A') THEN
202810 --
202807   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202808 END IF;
202809 
202811 
202812 
202813 --
202814 AcctLineType_300 (
202815  p_application_id  => p_application_id
202816  ,p_event_id     => l_event_id
202817  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202818  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202819  ,p_actual_flag => l_actual_flag
202820  ,p_balance_type_code => l_balance_type_code
202821  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202822  
202823  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202824  , p_source_3 => l_array_source_3(Idx)
202825  , p_source_9 => l_array_source_9(Idx)
202826  , p_source_29 => l_array_source_29(Idx)
202827  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202828  , p_source_35 => l_array_source_35(Idx)
202829  , p_source_36 => l_array_source_36(Idx)
202830  , p_source_37 => l_array_source_37(Idx)
202831  , p_source_38 => l_array_source_38(Idx)
202832  , p_source_39 => l_array_source_39(Idx)
202833  , p_source_40 => l_array_source_40(Idx)
202834  );
202835 If(l_balance_type_code = 'A') THEN
202836   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202837 END IF;
202838 
202839 --
202840 
202841 
202842 --
202843 AcctLineType_301 (
202844  p_application_id  => p_application_id
202845  ,p_event_id     => l_event_id
202846  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202847  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202848  ,p_actual_flag => l_actual_flag
202849  ,p_balance_type_code => l_balance_type_code
202850  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202851  
202852  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202853  , p_source_3 => l_array_source_3(Idx)
202854  , p_source_29 => l_array_source_29(Idx)
202855  , p_source_35 => l_array_source_35(Idx)
202856  , p_source_36 => l_array_source_36(Idx)
202857  , p_source_37 => l_array_source_37(Idx)
202858  , p_source_38 => l_array_source_38(Idx)
202859  , p_source_39 => l_array_source_39(Idx)
202860  , p_source_40 => l_array_source_40(Idx)
202861  );
202862 If(l_balance_type_code = 'A') THEN
202863   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202864 END IF;
202865 
202866 --
202867 
202868 
202869 --
202870 AcctLineType_304 (
202871  p_application_id  => p_application_id
202872  ,p_event_id     => l_event_id
202873  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202874  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202875  ,p_actual_flag => l_actual_flag
202876  ,p_balance_type_code => l_balance_type_code
202877  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202878  
202879  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202880  , p_source_3 => l_array_source_3(Idx)
202881  , p_source_10 => l_array_source_10(Idx)
202882  , p_source_17 => l_array_source_17(Idx)
202883  , p_source_29 => l_array_source_29(Idx)
202884  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202885  , p_source_35 => l_array_source_35(Idx)
202886  , p_source_36 => l_array_source_36(Idx)
202887  , p_source_37 => l_array_source_37(Idx)
202888  , p_source_38 => l_array_source_38(Idx)
202889  , p_source_39 => l_array_source_39(Idx)
202890  , p_source_40 => l_array_source_40(Idx)
202891  );
202892 If(l_balance_type_code = 'A') THEN
202893   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202894 END IF;
202895 
202896 --
202897 
202898 
202899 --
202900 AcctLineType_305 (
202901  p_application_id  => p_application_id
202902  ,p_event_id     => l_event_id
202903  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202904  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202905  ,p_actual_flag => l_actual_flag
202906  ,p_balance_type_code => l_balance_type_code
202907  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202908  
202909  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202910  , p_source_3 => l_array_source_3(Idx)
202911  , p_source_29 => l_array_source_29(Idx)
202912  , p_source_35 => l_array_source_35(Idx)
202913  , p_source_36 => l_array_source_36(Idx)
202914  , p_source_37 => l_array_source_37(Idx)
202915  , p_source_38 => l_array_source_38(Idx)
202916  , p_source_39 => l_array_source_39(Idx)
202917  , p_source_40 => l_array_source_40(Idx)
202918  );
202919 If(l_balance_type_code = 'A') THEN
202920   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202921 END IF;
202922 
202923 --
202924 
202925 
202926 --
202927 AcctLineType_307 (
202928  p_application_id  => p_application_id
202929  ,p_event_id     => l_event_id
202930  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202931  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202932  ,p_actual_flag => l_actual_flag
202933  ,p_balance_type_code => l_balance_type_code
202934  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202935  
202936  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202937  , p_source_3 => l_array_source_3(Idx)
202938  , p_source_10 => l_array_source_10(Idx)
202939  , p_source_17 => l_array_source_17(Idx)
202940  , p_source_29 => l_array_source_29(Idx)
202941  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202942  , p_source_35 => l_array_source_35(Idx)
202943  , p_source_36 => l_array_source_36(Idx)
202944  , p_source_37 => l_array_source_37(Idx)
202945  , p_source_38 => l_array_source_38(Idx)
202946  , p_source_39 => l_array_source_39(Idx)
202947  , p_source_40 => l_array_source_40(Idx)
202948  );
202949 If(l_balance_type_code = 'A') THEN
202950   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202951 END IF;
202952 
202953 --
202954 
202955 
202956 --
202957 AcctLineType_308 (
202958  p_application_id  => p_application_id
202959  ,p_event_id     => l_event_id
202960  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202961  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202962  ,p_actual_flag => l_actual_flag
202966  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202963  ,p_balance_type_code => l_balance_type_code
202964  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202965  
202967  , p_source_3 => l_array_source_3(Idx)
202968  , p_source_10 => l_array_source_10(Idx)
202969  , p_source_17 => l_array_source_17(Idx)
202970  , p_source_29 => l_array_source_29(Idx)
202971  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
202972  , p_source_35 => l_array_source_35(Idx)
202973  , p_source_36 => l_array_source_36(Idx)
202974  , p_source_37 => l_array_source_37(Idx)
202975  , p_source_38 => l_array_source_38(Idx)
202976  , p_source_39 => l_array_source_39(Idx)
202977  , p_source_40 => l_array_source_40(Idx)
202978  );
202979 If(l_balance_type_code = 'A') THEN
202980   l_actual_gain_loss_ref := l_gain_or_loss_ref;
202981 END IF;
202982 
202983 --
202984 
202985 
202986 --
202987 AcctLineType_313 (
202988  p_application_id  => p_application_id
202989  ,p_event_id     => l_event_id
202990  ,p_calculate_acctd_flag => l_calculate_acctd_flag
202991  ,p_calculate_g_l_flag => l_calculate_g_l_flag
202992  ,p_actual_flag => l_actual_flag
202993  ,p_balance_type_code => l_balance_type_code
202994  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
202995  
202996  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
202997  , p_source_3 => l_array_source_3(Idx)
202998  , p_source_11 => l_array_source_11(Idx)
202999  , p_source_17 => l_array_source_17(Idx)
203000  , p_source_29 => l_array_source_29(Idx)
203001  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
203002  , p_source_35 => l_array_source_35(Idx)
203003  , p_source_36 => l_array_source_36(Idx)
203004  , p_source_37 => l_array_source_37(Idx)
203005  , p_source_38 => l_array_source_38(Idx)
203006  , p_source_39 => l_array_source_39(Idx)
203007  , p_source_40 => l_array_source_40(Idx)
203008  );
203009 If(l_balance_type_code = 'A') THEN
203010   l_actual_gain_loss_ref := l_gain_or_loss_ref;
203011 END IF;
203012 
203013 --
203014 
203015 
203016 --
203017 AcctLineType_314 (
203018  p_application_id  => p_application_id
203019  ,p_event_id     => l_event_id
203020  ,p_calculate_acctd_flag => l_calculate_acctd_flag
203021  ,p_calculate_g_l_flag => l_calculate_g_l_flag
203022  ,p_actual_flag => l_actual_flag
203023  ,p_balance_type_code => l_balance_type_code
203024  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
203025  
203026  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
203027  , p_source_3 => l_array_source_3(Idx)
203028  , p_source_27 => g_array_event(l_event_id).array_value_char('source_27')
203029  , p_source_29 => l_array_source_29(Idx)
203030  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
203031  , p_source_35 => l_array_source_35(Idx)
203032  , p_source_36 => l_array_source_36(Idx)
203033  , p_source_37 => l_array_source_37(Idx)
203034  , p_source_38 => l_array_source_38(Idx)
203035  , p_source_39 => l_array_source_39(Idx)
203036  , p_source_40 => l_array_source_40(Idx)
203037  , p_source_41 => l_array_source_41(Idx)
203038  );
203039 If(l_balance_type_code = 'A') THEN
203040   l_actual_gain_loss_ref := l_gain_or_loss_ref;
203041 END IF;
203042 
203043 --
203044 
203045 
203046 --
203047 AcctLineType_317 (
203048  p_application_id  => p_application_id
203049  ,p_event_id     => l_event_id
203050  ,p_calculate_acctd_flag => l_calculate_acctd_flag
203051  ,p_calculate_g_l_flag => l_calculate_g_l_flag
203052  ,p_actual_flag => l_actual_flag
203053  ,p_balance_type_code => l_balance_type_code
203054  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
203055  
203056  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
203057  , p_source_3 => l_array_source_3(Idx)
203058  , p_source_28 => g_array_event(l_event_id).array_value_char('source_28')
203059  , p_source_29 => l_array_source_29(Idx)
203060  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
203061  , p_source_35 => l_array_source_35(Idx)
203062  , p_source_36 => l_array_source_36(Idx)
203063  , p_source_37 => l_array_source_37(Idx)
203064  , p_source_38 => l_array_source_38(Idx)
203065  , p_source_39 => l_array_source_39(Idx)
203066  , p_source_40 => l_array_source_40(Idx)
203067  , p_source_41 => l_array_source_41(Idx)
203068  );
203069 If(l_balance_type_code = 'A') THEN
203070   l_actual_gain_loss_ref := l_gain_or_loss_ref;
203071 END IF;
203072 
203073 --
203074 
203075       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
203076       -- or secondary ledger that has different currency with primary
203077       -- or alc that is calculated by sla
203078       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
203079             (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'))
203080 
203081 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
203082 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
203083           AND (l_actual_flag = 'A')) THEN
203084         XLA_AE_LINES_PKG.CreateGainOrLossLines(
203085           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
203086          ,p_application_id   => p_application_id
203087          ,p_amb_context_code => 'DEFAULT'
203088          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
203089          ,p_event_class_code => C_EVENT_CLASS_CODE
203090          ,p_event_type_code  => C_EVENT_TYPE_CODE
203091          
203092          ,p_gain_ccid        => -1
203093          ,p_loss_ccid        => -1
203094 
203095          ,p_actual_flag      => l_actual_flag
203096          ,p_enc_flag         => null
203097          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
203098          ,p_enc_g_l_ref      => null
203099          );
203103 
203100       END IF;
203101    END IF;
203102 END IF;
203104    ELSE
203105       --
203106       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
203107       --
203108       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
203109          trace
203110             (p_msg      => 'Trancaction revesal option is Y'
203111             ,p_level    => C_LEVEL_STATEMENT
203112             ,p_module   => l_log_module);
203113       END IF;
203114    END IF;
203115 
203116 END LOOP;
203117 l_result := XLA_AE_LINES_PKG.InsertLines ;
203118 end loop;
203119 close line_cur;
203120 
203121 
203122 --
203123 -- insert headers into xla_ae_headers_gt table
203124 --
203125 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
203126 
203127 -- insert into errors table here.
203128 
203129 END LOOP;
203130 
203131 --
203132 -- 4865292
203133 --
203134 -- Compare g_hdr_extract_count with event count in
203135 -- CreateHeadersAndLines.
203136 --
203137 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
203138 
203139 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
203140    trace (p_msg     => '# rows extracted from header extract objects '
203141                     || ' (running total): '
203142                     || g_hdr_extract_count
203143          ,p_level   => C_LEVEL_STATEMENT
203144          ,p_module  => l_log_module);
203145 END IF;
203146 
203147 CLOSE header_cur;
203148 --
203149 
203150 --
203151 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
203152    trace
203153       (p_msg      => 'END of EventType_423'
203154       ,p_level    => C_LEVEL_PROCEDURE
203155       ,p_module   => l_log_module);
203156 END IF;
203157 --
203158 RETURN l_result;
203159 EXCEPTION
203160 WHEN xla_exceptions_pkg.application_exception THEN
203161    
203162 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
203163 
203164    
203165 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
203166 
203167    RAISE;
203168 
203169 WHEN NO_DATA_FOUND THEN
203170 
203171 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
203172 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
203173 
203174 FOR header_record IN header_cur
203175 LOOP
203176     l_array_header_events(header_record.event_id) := header_record.event_id;
203177 END LOOP;
203178 
203179 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
203180 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
203181 
203182 fnd_file.put_line(fnd_file.LOG, '                    ');
203183 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
203184 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
203185 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
203186 
203187 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
203188 LOOP
203189 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
203190 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
203191         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
203192 	END IF;
203193 END LOOP;
203194 
203195 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
203196 fnd_file.put_line(fnd_file.LOG, '                    ');
203197 
203198 
203199 xla_exceptions_pkg.raise_message
203200       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_423');
203201 
203202 
203203 WHEN OTHERS THEN
203204    xla_exceptions_pkg.raise_message
203205       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_423');
203206 END EventType_423;
203207 --
203208 
203209 ---------------------------------------
203210 --
203211 -- PRIVATE PROCEDURE
203212 --         insert_sources_424
203213 --
203214 ----------------------------------------
203215 --
203216 PROCEDURE insert_sources_424(
203217                                 p_target_ledger_id       IN NUMBER
203218                               , p_language               IN VARCHAR2
203219                               , p_sla_ledger_id          IN NUMBER
203220                               , p_pad_start_date         IN DATE
203221                               , p_pad_end_date           IN DATE
203222                          )
203223 IS
203224 
203225 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RESERVE_TRANSFERS_ALL';
203226 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'RESERVE_TRANSFERS';
203227 p_apps_owner                   VARCHAR2(30);
203228 l_log_module                   VARCHAR2(240);
203229 BEGIN
203230 IF g_log_enabled THEN
203231       l_log_module := C_DEFAULT_MODULE||'.insert_sources_424';
203232 END IF;
203233 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
203234 
203235       trace
203236          (p_msg      => 'BEGIN of insert_sources_424'
203237          ,p_level    => C_LEVEL_PROCEDURE
203238          ,p_module   => l_log_module);
203239 
203240 END IF;
203241 
203242 -- select APPS owner
203243 SELECT oracle_username
203244   INTO p_apps_owner
203245   FROM fnd_oracle_userid
203246  WHERE read_only_flag = 'U'
203247 ;
203248 
203249 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
203250       trace
203251          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
203252                         ' - p_language = '||p_language||
203253                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
203254                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
203255                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
203256                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
203257          ,p_level    => C_LEVEL_STATEMENT
203261 
203258          ,p_module   => l_log_module);
203259 END IF;
203260 
203262 --
203263 INSERT INTO xla_diag_sources --hdr2
203264 (
203265         event_id
203266       , ledger_id
203267       , sla_ledger_id
203268       , description_language
203269       , object_name
203270       , object_type_code
203271       , line_number
203272       , source_application_id
203273       , source_type_code
203274       , source_code
203275       , source_value
203276       , source_meaning
203277       , created_by
203278       , creation_date
203279       , last_update_date
203280       , last_updated_by
203281       , last_update_login
203282       , program_update_date
203283       , program_application_id
203284       , program_id
203285       , request_id
203286 )
203287 SELECT
203288         event_id
203289       , p_target_ledger_id
203290       , p_sla_ledger_id
203291       , p_language
203292       , object_name
203293       , object_type_code
203294       , line_number
203295       , source_application_id
203296       , source_type_code
203297       , source_code
203298       , SUBSTR(source_value ,1,1996)
203299       , SUBSTR(source_meaning ,1,200)
203300       , xla_environment_pkg.g_Usr_Id
203301       , TRUNC(SYSDATE)
203302       , TRUNC(SYSDATE)
203303       , xla_environment_pkg.g_Usr_Id
203304       , xla_environment_pkg.g_Login_Id
203305       , TRUNC(SYSDATE)
203306       , xla_environment_pkg.g_Prog_Appl_Id
203307       , xla_environment_pkg.g_Prog_Id
203308       , xla_environment_pkg.g_Req_Id
203309   FROM (
203310        SELECT xet.event_id                  event_id
203311             , 0                          line_number
203312             , CASE r
203313                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
203314                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
203315                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
203316                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
203317                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
203318                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
203319                 
203320                ELSE null
203321               END                           object_name
203322             , CASE r
203323                 WHEN 1 THEN 'HEADER' 
203324                 WHEN 2 THEN 'HEADER' 
203325                 WHEN 3 THEN 'HEADER' 
203326                 WHEN 4 THEN 'HEADER' 
203327                 WHEN 5 THEN 'HEADER' 
203328                 WHEN 6 THEN 'HEADER' 
203329                 
203330                 ELSE null
203331               END                           object_type_code
203332             , CASE r
203333                 WHEN 1 THEN '140' 
203334                 WHEN 2 THEN '140' 
203335                 WHEN 3 THEN '140' 
203336                 WHEN 4 THEN '140' 
203337                 WHEN 5 THEN '140' 
203338                 WHEN 6 THEN '140' 
203339                 
203340                 ELSE null
203341               END                           source_application_id
203342             , 'S'             source_type_code
203343             , CASE r
203344                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
203345                 WHEN 2 THEN 'AP_INTERCOMPANY_ACCT' 
203346                 WHEN 3 THEN 'AR_INTERCOMPANY_ACCT' 
203347                 WHEN 4 THEN 'DEFAULT_CCID' 
203348                 WHEN 5 THEN 'ACCOUNTING_DATE' 
203349                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
203350                 
203351                 ELSE null
203352               END                           source_code
203353             , CASE r
203354                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
203355                 WHEN 2 THEN TO_CHAR(h1.AP_INTERCOMPANY_ACCT)
203356                 WHEN 3 THEN TO_CHAR(h1.AR_INTERCOMPANY_ACCT)
203357                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
203358                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
203359                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
203360                 
203361                 ELSE null
203362               END                           source_value
203363             , null              source_meaning
203364          FROM xla_events_gt     xet  
203365       , FA_XLA_EXT_HEADERS_B_GT  h1
203366              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
203367          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
203368            AND xet.event_class_code = C_EVENT_CLASS_CODE
203369               AND h1.event_id = xet.event_id
203370 
203371 )
203372 ;
203373 --
203374 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
203375 
203376       trace
203377          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
203378          ,p_level    => C_LEVEL_STATEMENT
203379          ,p_module   => l_log_module);
203380 
203381 END IF;
203382 --
203383 
203384 
203385 
203386 --
203387 INSERT INTO xla_diag_sources  --line2
203388 (
203389         event_id
203390       , ledger_id
203391       , sla_ledger_id
203392       , description_language
203393       , object_name
203394       , object_type_code
203395       , line_number
203396       , source_application_id
203397       , source_type_code
203398       , source_code
203399       , source_value
203400       , source_meaning
203401       , created_by
203402       , creation_date
203403       , last_update_date
203404       , last_updated_by
203405       , last_update_login
203406       , program_update_date
203407       , program_application_id
203408       , program_id
203409       , request_id
203410 )
203411 SELECT  event_id
203412       , p_target_ledger_id
203413       , p_sla_ledger_id
203414       , p_language
203415       , object_name
203416       , object_type_code
203417       , line_number
203418       , source_application_id
203422       , SUBSTR(source_meaning ,1,200)
203419       , source_type_code
203420       , source_code
203421       , SUBSTR(source_value,1,1996)
203423       , xla_environment_pkg.g_Usr_Id
203424       , TRUNC(SYSDATE)
203425       , TRUNC(SYSDATE)
203426       , xla_environment_pkg.g_Usr_Id
203427       , xla_environment_pkg.g_Login_Id
203428       , TRUNC(SYSDATE)
203429       , xla_environment_pkg.g_Prog_Appl_Id
203430       , xla_environment_pkg.g_Prog_Id
203431       , xla_environment_pkg.g_Req_Id
203432   FROM (
203433        SELECT xet.event_id                  event_id
203434             , l2.line_number                 line_number
203435             , CASE r
203436                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
203437                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
203438                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
203439                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
203440                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
203441                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
203442                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
203443                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
203444                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
203445                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
203446                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
203447                 
203448                ELSE null
203449               END                           object_name
203450             , CASE r
203451                 WHEN 1 THEN 'LINE' 
203452                 WHEN 2 THEN 'LINE' 
203453                 WHEN 3 THEN 'LINE' 
203454                 WHEN 4 THEN 'LINE' 
203455                 WHEN 5 THEN 'LINE' 
203456                 WHEN 6 THEN 'LINE' 
203457                 WHEN 7 THEN 'LINE' 
203458                 WHEN 8 THEN 'LINE' 
203459                 WHEN 9 THEN 'LINE' 
203460                 WHEN 10 THEN 'LINE' 
203461                 WHEN 11 THEN 'LINE' 
203462                 
203463                 ELSE null
203464               END                           object_type_code
203465             , CASE r
203466                 WHEN 1 THEN '140' 
203467                 WHEN 2 THEN '140' 
203468                 WHEN 3 THEN '140' 
203469                 WHEN 4 THEN '140' 
203470                 WHEN 5 THEN '140' 
203471                 WHEN 6 THEN '140' 
203472                 WHEN 7 THEN '140' 
203473                 WHEN 8 THEN '140' 
203474                 WHEN 9 THEN '140' 
203475                 WHEN 10 THEN '140' 
203476                 WHEN 11 THEN '140' 
203477                 
203478                 ELSE null
203479               END                           source_application_id
203480             , 'S'             source_type_code
203481             , CASE r
203482                 WHEN 1 THEN 'GENERATED_CCID' 
203483                 WHEN 2 THEN 'DEPRN_RESERVE_ACCT' 
203484                 WHEN 3 THEN 'GENERATED_OFFSET_CCID' 
203485                 WHEN 4 THEN 'EXPENSE_ACCOUNT_CCID' 
203486                 WHEN 5 THEN 'ADJUSTMENT_TYPE' 
203487                 WHEN 6 THEN 'TRANSACTION_HEADER_ID' 
203488                 WHEN 7 THEN 'ADJUSTMENT_LINE_ID' 
203489                 WHEN 8 THEN 'DISTRIBUTION_TYPE_CODE' 
203490                 WHEN 9 THEN 'ENTERED_AMOUNT' 
203491                 WHEN 10 THEN 'CURRENCY_CODE' 
203492                 WHEN 11 THEN 'SOURCE_DEST_CODE' 
203493                 
203494                 ELSE null
203495               END                           source_code
203496             , CASE r
203497                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
203498                 WHEN 2 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
203499                 WHEN 3 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
203500                 WHEN 4 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
203501                 WHEN 5 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
203502                 WHEN 6 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
203503                 WHEN 7 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
203504                 WHEN 8 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
203505                 WHEN 9 THEN TO_CHAR(l2.ENTERED_AMOUNT)
203506                 WHEN 10 THEN TO_CHAR(l2.CURRENCY_CODE)
203507                 WHEN 11 THEN TO_CHAR(l2.SOURCE_DEST_CODE)
203508                 
203509                 ELSE null
203510               END                           source_value
203511             , null              source_meaning
203512          FROM  xla_events_gt     xet  
203513         , FA_XLA_EXT_LINES_B_GT  l2
203514             , (select rownum r from all_objects where rownum <= 11 and owner = p_apps_owner)
203515         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
203516           AND xet.event_class_code = C_EVENT_CLASS_CODE
203517             AND l2.event_id          = xet.event_id
203518   AND l2.ledger_id (+)  = p_sla_ledger_id
203519 
203520 )
203521 ;
203522 --
203523 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
203524 
203525       trace
203526          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
203527          ,p_level    => C_LEVEL_STATEMENT
203528          ,p_module   => l_log_module);
203529 
203530 END IF;
203531 
203532 
203533 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
203534       trace
203535          (p_msg      => 'END of insert_sources_424'
203536          ,p_level    => C_LEVEL_PROCEDURE
203537          ,p_module   => l_log_module);
203538 END IF;
203539 EXCEPTION
203540   WHEN xla_exceptions_pkg.application_exception THEN
203541       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
203542             trace
203543                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
203544                ,p_level    => C_LEVEL_EXCEPTION
203545                ,p_module   => l_log_module);
203546       END IF;
203547       RAISE;
203548   WHEN OTHERS THEN
203549       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
203550             trace
203551                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
203555        xla_exceptions_pkg.raise_message
203552                ,p_level    => C_LEVEL_EXCEPTION
203553                ,p_module   => l_log_module);
203554        END IF;
203556            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_424');
203557 END insert_sources_424;
203558 --
203559 
203560 ---------------------------------------
203561 --
203562 -- PRIVATE FUNCTION
203563 --         EventClass_424
203564 --
203565 ----------------------------------------
203566 --
203567 FUNCTION EventClass_424
203568        (p_application_id         IN NUMBER
203569        ,p_base_ledger_id         IN NUMBER
203570        ,p_target_ledger_id       IN NUMBER
203571        ,p_language               IN VARCHAR2
203572        ,p_currency_code          IN VARCHAR2
203573        ,p_sla_ledger_id          IN NUMBER
203574        ,p_pad_start_date         IN DATE
203575        ,p_pad_end_date           IN DATE
203576        ,p_primary_ledger_id      IN NUMBER)
203577 RETURN BOOLEAN IS
203578 --
203579 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RESERVE_TRANSFERS_ALL';
203580 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'RESERVE_TRANSFERS';
203581 
203582 l_calculate_acctd_flag   VARCHAR2(1) :='N';
203583 l_calculate_g_l_flag     VARCHAR2(1) :='N';
203584 --
203585 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
203586 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
203587 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
203588 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
203589 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
203590 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
203591 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
203592 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
203593 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
203594 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
203595 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
203596 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
203597 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
203598 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
203599 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
203600 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
203601 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
203602 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
203603 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
203604 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
203605 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
203606 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
203607 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
203608 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
203609 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
203610 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
203611 
203612 l_event_id                             NUMBER;
203613 l_previous_event_id                    NUMBER;
203614 l_first_event_id                       NUMBER;
203615 l_last_event_id                        NUMBER;
203616 
203617 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
203618 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
203619 --
203620 --
203621 l_result                    BOOLEAN := TRUE;
203622 l_rows                      NUMBER  := 1000;
203623 l_event_type_name           VARCHAR2(80) := 'All';
203624 l_event_class_name          VARCHAR2(80) := 'Reserve Transfers';
203625 l_description               VARCHAR2(4000);
203626 l_transaction_reversal      NUMBER;
203627 l_ae_header_id              NUMBER;
203628 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
203629 l_log_module                VARCHAR2(240);
203630 --
203631 l_acct_reversal_source      VARCHAR2(30);
203632 l_trx_reversal_source       VARCHAR2(30);
203633 
203634 l_continue_with_lines       BOOLEAN := TRUE;
203635 --
203636 l_acc_rev_gl_date_source    DATE;                      -- 4262811
203637 --
203638 type t_array_event_id is table of number index by binary_integer;
203639 
203640 l_rec_array_event                    t_rec_array_event;
203641 l_null_rec_array_event               t_rec_array_event;
203642 l_array_ae_header_id                 xla_number_array_type;
203643 l_actual_flag                        VARCHAR2(1) := NULL;
203644 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
203645 l_balance_type_code                  VARCHAR2(1) :=NULL;
203646 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
203647 
203648 --
203649 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
203650 --
203651 
203652 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
203653 TYPE t_array_source_19 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AP_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
203654 TYPE t_array_source_20 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AR_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
203655 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
203656 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
203657 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
203658 
203659 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
203660 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
203664 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
203661 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
203662 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
203663 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
203665 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
203666 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
203667 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
203668 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
203669 TYPE t_array_source_42 IS TABLE OF FA_XLA_EXT_LINES_B_GT.SOURCE_DEST_CODE%TYPE INDEX BY BINARY_INTEGER;
203670 
203671 l_array_source_1              t_array_source_1;
203672 l_array_source_19              t_array_source_19;
203673 l_array_source_20              t_array_source_20;
203674 l_array_source_30              t_array_source_30;
203675 l_array_source_51              t_array_source_51;
203676 l_array_source_52              t_array_source_52;
203677 
203678 l_array_source_3      t_array_source_3;
203679 l_array_source_10      t_array_source_10;
203680 l_array_source_17      t_array_source_17;
203681 l_array_source_29      t_array_source_29;
203682 l_array_source_35      t_array_source_35;
203683 l_array_source_36      t_array_source_36;
203684 l_array_source_37      t_array_source_37;
203685 l_array_source_38      t_array_source_38;
203686 l_array_source_39      t_array_source_39;
203687 l_array_source_40      t_array_source_40;
203688 l_array_source_42      t_array_source_42;
203689 
203690 --
203691 CURSOR header_cur
203692 IS
203693 SELECT /*+ leading(xet) cardinality(xet,1) */
203694 -- Event Class Code: RESERVE_TRANSFERS
203695     xet.entity_id
203696    ,xet.legal_entity_id
203697    ,xet.entity_code
203698    ,xet.transaction_number
203699    ,xet.event_id
203700    ,xet.event_class_code
203701    ,xet.event_type_code
203702    ,xet.event_number
203703    ,xet.event_date
203704    ,xet.transaction_date
203705    ,xet.reference_num_1
203706    ,xet.reference_num_2
203707    ,xet.reference_num_3
203708    ,xet.reference_num_4
203709    ,xet.reference_char_1
203710    ,xet.reference_char_2
203711    ,xet.reference_char_3
203712    ,xet.reference_char_4
203713    ,xet.reference_date_1
203714    ,xet.reference_date_2
203715    ,xet.reference_date_3
203716    ,xet.reference_date_4
203717    ,xet.event_created_by
203718    ,xet.budgetary_control_flag 
203719   , h1.PERIOD_CLOSE_DATE    source_1
203720   , h1.AP_INTERCOMPANY_ACCT    source_19
203721   , h1.AR_INTERCOMPANY_ACCT    source_20
203722   , h1.DEFAULT_CCID    source_30
203723   , h1.ACCOUNTING_DATE    source_51
203724   , h1.TRANSFER_TO_GL_FLAG    source_52
203725   FROM xla_events_gt     xet 
203726   , FA_XLA_EXT_HEADERS_B_GT  h1
203727  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
203728    and xet.event_class_code = C_EVENT_CLASS_CODE
203729    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
203730 
203731  ORDER BY event_id
203732 ;
203733 
203734 
203735 --
203736 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
203737 IS
203738 SELECT  /*+ leading(xet) cardinality(xet,1) */
203739 -- Event Class Code: RESERVE_TRANSFERS
203740     xet.entity_id
203741    ,xet.legal_entity_id
203742    ,xet.entity_code
203743    ,xet.transaction_number
203744    ,xet.event_id
203745    ,xet.event_class_code
203746    ,xet.event_type_code
203747    ,xet.event_number
203748    ,xet.event_date
203749    ,xet.transaction_date
203750    ,xet.reference_num_1
203751    ,xet.reference_num_2
203752    ,xet.reference_num_3
203753    ,xet.reference_num_4
203754    ,xet.reference_char_1
203755    ,xet.reference_char_2
203756    ,xet.reference_char_3
203757    ,xet.reference_char_4
203758    ,xet.reference_date_1
203759    ,xet.reference_date_2
203760    ,xet.reference_date_3
203761    ,xet.reference_date_4
203762    ,xet.event_created_by
203763    ,xet.budgetary_control_flag
203764  , l2.LINE_NUMBER  
203765   , l2.GENERATED_CCID    source_3
203766   , l2.DEPRN_RESERVE_ACCT    source_10
203767   , l2.GENERATED_OFFSET_CCID    source_17
203768   , l2.EXPENSE_ACCOUNT_CCID    source_29
203769   , l2.ADJUSTMENT_TYPE    source_35
203770   , l2.TRANSACTION_HEADER_ID    source_36
203771   , l2.ADJUSTMENT_LINE_ID    source_37
203772   , l2.DISTRIBUTION_TYPE_CODE    source_38
203773   , l2.ENTERED_AMOUNT    source_39
203774   , l2.CURRENCY_CODE    source_40
203775   , l2.SOURCE_DEST_CODE    source_42
203776   FROM xla_events_gt     xet 
203777   , FA_XLA_EXT_LINES_B_GT  l2
203778  WHERE xet.event_id between x_first_event_id and x_last_event_id
203779    and xet.event_date between p_pad_start_date and p_pad_end_date
203780    and xet.event_class_code = C_EVENT_CLASS_CODE
203781    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
203782   AND l2.ledger_id = p_sla_ledger_id
203783 ;
203784 
203785 --
203786 BEGIN
203787 IF g_log_enabled THEN
203788    l_log_module := C_DEFAULT_MODULE||'.EventClass_424';
203789 END IF;
203790 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
203791    trace
203792       (p_msg      => 'BEGIN of EventClass_424'
203793       ,p_level    => C_LEVEL_PROCEDURE
203794       ,p_module   => l_log_module);
203795 END IF;
203796 
203797 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
203798    trace
203799       (p_msg      => 'p_application_id = '||p_application_id||
203800                      ' - p_base_ledger_id = '||p_base_ledger_id||
203801                      ' - p_target_ledger_id  = '||p_target_ledger_id||
203802                      ' - p_language = '||p_language||
203806       ,p_module   => l_log_module);
203803                      ' - p_currency_code = '||p_currency_code||
203804                      ' - p_sla_ledger_id = '||p_sla_ledger_id
203805       ,p_level    => C_LEVEL_STATEMENT
203807 END IF;
203808 --
203809 -- initialze arrays
203810 --
203811 g_array_event.DELETE;
203812 l_rec_array_event := l_null_rec_array_event;
203813 --
203814 --------------------------------------
203815 -- 4262811 Initialze MPA Line Number
203816 --------------------------------------
203817 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
203818 
203819 --
203820 
203821 --
203822 OPEN header_cur;
203823 --
203824 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
203825    trace
203826    (p_msg      => 'SQL - FETCH header_cur'
203827    ,p_level    => C_LEVEL_STATEMENT
203828    ,p_module   => l_log_module);
203829 END IF;
203830 --
203831 LOOP
203832 FETCH header_cur BULK COLLECT INTO
203833         l_array_entity_id
203834       , l_array_legal_entity_id
203835       , l_array_entity_code
203836       , l_array_transaction_num
203837       , l_array_event_id
203838       , l_array_class_code
203839       , l_array_event_type
203840       , l_array_event_number
203841       , l_array_event_date
203842       , l_array_transaction_date
203843       , l_array_reference_num_1
203844       , l_array_reference_num_2
203845       , l_array_reference_num_3
203846       , l_array_reference_num_4
203847       , l_array_reference_char_1
203848       , l_array_reference_char_2
203849       , l_array_reference_char_3
203850       , l_array_reference_char_4
203851       , l_array_reference_date_1
203852       , l_array_reference_date_2
203853       , l_array_reference_date_3
203854       , l_array_reference_date_4
203855       , l_array_event_created_by
203856       , l_array_budgetary_control_flag 
203857       , l_array_source_1
203858       , l_array_source_19
203859       , l_array_source_20
203860       , l_array_source_30
203861       , l_array_source_51
203862       , l_array_source_52
203863       LIMIT l_rows;
203864 --
203865 IF (C_LEVEL_EVENT >= g_log_level) THEN
203866    trace
203867    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
203868    ,p_level    => C_LEVEL_EVENT
203869    ,p_module   => l_log_module);
203870 END IF;
203871 --
203872 EXIT WHEN l_array_entity_id.COUNT = 0;
203873 
203874 -- initialize arrays
203875 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
203876 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
203877 
203878 --
203879 -- Bug 4458708
203880 --
203881 XLA_AE_LINES_PKG.g_LineNumber := 0;
203882 
203883 
203884 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
203885 g_last_hdr_idx := l_array_event_id.LAST;
203886 --
203887 -- loop for the headers. Each iteration is for each header extract row
203888 -- fetched in header cursor
203889 --
203890 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
203891 
203892 --
203893 -- set event info as cache for other routines to refer event attributes
203894 --
203895 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
203896    (p_application_id           => p_application_id
203897    ,p_primary_ledger_id        => p_primary_ledger_id
203898    ,p_base_ledger_id           => p_base_ledger_id
203899    ,p_target_ledger_id         => p_target_ledger_id
203900    ,p_entity_id                => l_array_entity_id(hdr_idx)
203901    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
203902    ,p_entity_code              => l_array_entity_code(hdr_idx)
203903    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
203904    ,p_event_id                 => l_array_event_id(hdr_idx)
203905    ,p_event_class_code         => l_array_class_code(hdr_idx)
203906    ,p_event_type_code          => l_array_event_type(hdr_idx)
203907    ,p_event_number             => l_array_event_number(hdr_idx)
203908    ,p_event_date               => l_array_event_date(hdr_idx)
203909    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
203910    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
203911    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
203912    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
203913    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
203914    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
203915    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
203916    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
203917    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
203918    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
203919    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
203920    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
203921    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
203922    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
203923    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
203924 
203925 --
203926 -- set the status of entry to C_VALID (0)
203927 --
203928 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
203929 
203930 --
203931 -- initialize a row for ae header
203932 --
203933 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
203934 
203935 l_event_id := l_array_event_id(hdr_idx);
203936 
203937 --
203938 -- storing the hdr_idx for event. May be used by line cursor.
203939 --
203940 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
203941 
203942 --
203943 -- store sources from header extract. This can be improved to
203944 -- store only those sources from header extract that may be used in lines
203945 --
203946 
203947 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
203951 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
203948 g_array_event(l_event_id).array_value_char('source_19') := l_array_source_19(hdr_idx);
203949 g_array_event(l_event_id).array_value_char('source_20') := l_array_source_20(hdr_idx);
203950 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
203952 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
203953 
203954 --
203955 -- initilaize the status of ae headers for diffrent balance types
203956 -- the status is initialised to C_NOT_CREATED (2)
203957 --
203958 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
203959 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
203960 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
203961 
203962 --
203963 -- call api to validate and store accounting attributes for header
203964 --
203965 
203966 ------------------------------------------------------------
203967 -- Accrual Reversal : to get date for Standard Source (NONE)
203968 ------------------------------------------------------------
203969 l_acc_rev_gl_date_source := NULL;
203970 
203971      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
203972       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
203973      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
203974       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
203975 
203976 
203977 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
203978 
203979 XLA_AE_HEADER_PKG.SetJeCategoryName;
203980 
203981 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
203982 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
203983 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
203984 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
203985 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
203986 
203987 
203988 --
203989 xla_ae_header_pkg.SetHdrDescription(
203990    p_description => Description_70 (
203991    p_application_id => p_application_id 
203992  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
203993    )
203994 );
203995 --
203996 
203997 -- No header level analytical criteria
203998 
203999 --
204000 --accounting attribute enhancement, bug 3612931
204001 --
204002 l_trx_reversal_source := SUBSTR(NULL, 1,30);
204003 
204004 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
204005    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
204006 
204007    xla_accounting_err_pkg.build_message
204008       (p_appli_s_name            => 'XLA'
204009       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
204010       ,p_token_1                 => 'ACCT_ATTR_NAME'
204011       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
204012       ,p_token_2                 => 'PRODUCT_NAME'
204013       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
204014       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
204015       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
204016       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
204017 
204018 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
204019    --
204020    -- following sets the accounting attributes needed to reverse
204021    -- accounting for a distributeion
204022    --
204023    xla_ae_lines_pkg.SetTrxReversalAttrs
204024       (p_event_id              => l_event_id
204025       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
204026       ,p_trx_reversal_source   => l_trx_reversal_source);
204027 
204028 END IF;
204029 
204030 
204031 ----------------------------------------------------------------
204032 -- 4262811 -  update the header statuses to invalid in need be
204033 ----------------------------------------------------------------
204034 --
204035 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
204036 
204037 
204038   -----------------------------------------------
204039   -- No accrual reversal for the event class/type
204040   -----------------------------------------------
204041 ----------------------------------------------------------------
204042 
204043 --
204044 -- this ends the header loop iteration for one bulk fetch
204045 --
204046 END LOOP;
204047 
204048 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
204049 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
204050 
204051 --
204052 -- insert dummy rows into lines gt table that were created due to
204053 -- transaction reversals
204054 --
204055 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
204056    l_result := XLA_AE_LINES_PKG.InsertLines;
204057 END IF;
204058 
204059 --
204060 -- reset the temp_line_num for each set of events fetched from header
204061 -- cursor rather than doing it for each new event in line cursor
204062 -- Bug 3939231
204063 --
204064 xla_ae_lines_pkg.g_temp_line_num := 0;
204065 
204066 
204067 
204068 --
204069 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
204070 --
204071 --
204072 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
204073 
204074       trace
204075          (p_msg      => 'SQL - FETCH line_cur'
204076          ,p_level    => C_LEVEL_STATEMENT
204077          ,p_module   => l_log_module);
204078 
204079 END IF;
204080 --
204081 --
204082 LOOP
204086       , l_array_legal_entity_id
204083   --
204084   FETCH line_cur BULK COLLECT INTO
204085         l_array_entity_id
204087       , l_array_entity_code
204088       , l_array_transaction_num
204089       , l_array_event_id
204090       , l_array_class_code
204091       , l_array_event_type
204092       , l_array_event_number
204093       , l_array_event_date
204094       , l_array_transaction_date
204095       , l_array_reference_num_1
204096       , l_array_reference_num_2
204097       , l_array_reference_num_3
204098       , l_array_reference_num_4
204099       , l_array_reference_char_1
204100       , l_array_reference_char_2
204101       , l_array_reference_char_3
204102       , l_array_reference_char_4
204103       , l_array_reference_date_1
204104       , l_array_reference_date_2
204105       , l_array_reference_date_3
204106       , l_array_reference_date_4
204107       , l_array_event_created_by
204108       , l_array_budgetary_control_flag
204109       , l_array_extract_line_num 
204110       , l_array_source_3
204111       , l_array_source_10
204112       , l_array_source_17
204113       , l_array_source_29
204114       , l_array_source_35
204115       , l_array_source_36
204116       , l_array_source_37
204117       , l_array_source_38
204118       , l_array_source_39
204119       , l_array_source_40
204120       , l_array_source_42
204121       LIMIT l_rows;
204122 
204123   --
204124   IF (C_LEVEL_EVENT >= g_log_level) THEN
204125             trace
204126                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
204127                ,p_level    => C_LEVEL_EVENT
204128                ,p_module   => l_log_module);
204129   END IF;
204130   --
204131   EXIT WHEN l_array_entity_id.count = 0;
204132 
204133   XLA_AE_LINES_PKG.g_rec_lines := null;
204134 
204135 --
204136 -- Bug 4458708
204137 --
204138 XLA_AE_LINES_PKG.g_LineNumber := 0;
204139 --
204140 --
204141 
204142 FOR Idx IN 1..l_array_event_id.count LOOP
204143    --
204144    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
204145    --
204146    l_event_id := l_array_event_id(idx);  -- 5648433
204147 
204148    --
204149    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
204150    --
204151 
204152    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
204153              (g_array_event(l_event_id).array_value_num('header_index'))
204154          ,'N'
204155          ) <> 'Y'
204156    THEN
204157       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
204158          trace
204159             (p_msg      => 'Trancaction revesal option is not Y '
204160             ,p_level    => C_LEVEL_STATEMENT
204161             ,p_module   => l_log_module);
204162       END IF;
204163 
204164 --
204165 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
204166 --
204167 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
204168 --
204169 -- set event info as cache for other routines to refer event attributes
204170 --
204171 
204172 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
204173    l_previous_event_id := l_event_id;
204174 
204175    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
204176       (p_application_id           => p_application_id
204177       ,p_primary_ledger_id        => p_primary_ledger_id
204178       ,p_base_ledger_id           => p_base_ledger_id
204179       ,p_target_ledger_id         => p_target_ledger_id
204180       ,p_entity_id                => l_array_entity_id(Idx)
204181       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
204182       ,p_entity_code              => l_array_entity_code(Idx)
204183       ,p_transaction_num          => l_array_transaction_num(Idx)
204184       ,p_event_id                 => l_array_event_id(Idx)
204185       ,p_event_class_code         => l_array_class_code(Idx)
204186       ,p_event_type_code          => l_array_event_type(Idx)
204187       ,p_event_number             => l_array_event_number(Idx)
204188       ,p_event_date               => l_array_event_date(Idx)
204189       ,p_transaction_date         => l_array_transaction_date(Idx)
204190       ,p_reference_num_1          => l_array_reference_num_1(Idx)
204191       ,p_reference_num_2          => l_array_reference_num_2(Idx)
204192       ,p_reference_num_3          => l_array_reference_num_3(Idx)
204193       ,p_reference_num_4          => l_array_reference_num_4(Idx)
204194       ,p_reference_char_1         => l_array_reference_char_1(Idx)
204195       ,p_reference_char_2         => l_array_reference_char_2(Idx)
204196       ,p_reference_char_3         => l_array_reference_char_3(Idx)
204197       ,p_reference_char_4         => l_array_reference_char_4(Idx)
204198       ,p_reference_date_1         => l_array_reference_date_1(Idx)
204199       ,p_reference_date_2         => l_array_reference_date_2(Idx)
204200       ,p_reference_date_3         => l_array_reference_date_3(Idx)
204201       ,p_reference_date_4         => l_array_reference_date_4(Idx)
204202       ,p_event_created_by         => l_array_event_created_by(Idx)
204203       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
204204        --
204205 END IF;
204206 
204207 
204208 
204209 --
204210 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
204211 
204212 l_acct_reversal_source := SUBSTR(NULL, 1,30);
204213 
204214 IF l_continue_with_lines THEN
204215    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
204216       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
204217 
204218       xla_accounting_err_pkg.build_message
204219          (p_appli_s_name            => 'XLA'
204220          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
204221          ,p_token_1                 => 'LINE_NUMBER'
204222          ,p_value_1                 => l_array_extract_line_num(Idx)
204226          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
204223          ,p_token_2                 => 'PRODUCT_NAME'
204224          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
204225          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
204227          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
204228 
204229    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
204230       --
204231       -- following sets the accounting attributes needed to reverse
204232       -- accounting for a distributeion
204233       --
204234 
204235       --
204236       -- 5217187
204237       --
204238       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
204239       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
204240                                        g_array_event(l_event_id).array_value_num('header_index'));
204241       --
204242       --
204243 
204244       -- No reversal code generated
204245 
204246       xla_ae_lines_pkg.SetAcctReversalAttrs
204247          (p_event_id             => l_event_id
204248          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
204249          ,p_calculate_acctd_flag => l_calculate_acctd_flag
204250          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
204251    END IF;
204252 
204253    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
204254        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
204255 
204256 --
204257 AcctLineType_291 (
204258  p_application_id  => p_application_id
204259  ,p_event_id     => l_event_id
204260  ,p_calculate_acctd_flag => l_calculate_acctd_flag
204261  ,p_calculate_g_l_flag => l_calculate_g_l_flag
204262  ,p_actual_flag => l_actual_flag
204263  ,p_balance_type_code => l_balance_type_code
204264  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
204265  
204266  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
204267  , p_source_3 => l_array_source_3(Idx)
204268  , p_source_19 => g_array_event(l_event_id).array_value_char('source_19')
204269  , p_source_29 => l_array_source_29(Idx)
204270  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
204271  , p_source_35 => l_array_source_35(Idx)
204272  , p_source_36 => l_array_source_36(Idx)
204273  , p_source_37 => l_array_source_37(Idx)
204274  , p_source_38 => l_array_source_38(Idx)
204275  , p_source_39 => l_array_source_39(Idx)
204276  , p_source_40 => l_array_source_40(Idx)
204277  );
204278 If(l_balance_type_code = 'A') THEN
204279   l_actual_gain_loss_ref := l_gain_or_loss_ref;
204280 END IF;
204281 
204282 --
204283 
204284 
204285 --
204286 AcctLineType_292 (
204287  p_application_id  => p_application_id
204288  ,p_event_id     => l_event_id
204289  ,p_calculate_acctd_flag => l_calculate_acctd_flag
204290  ,p_calculate_g_l_flag => l_calculate_g_l_flag
204291  ,p_actual_flag => l_actual_flag
204292  ,p_balance_type_code => l_balance_type_code
204293  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
204294  
204295  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
204296  , p_source_3 => l_array_source_3(Idx)
204297  , p_source_20 => g_array_event(l_event_id).array_value_char('source_20')
204298  , p_source_29 => l_array_source_29(Idx)
204299  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
204300  , p_source_35 => l_array_source_35(Idx)
204301  , p_source_36 => l_array_source_36(Idx)
204302  , p_source_37 => l_array_source_37(Idx)
204303  , p_source_38 => l_array_source_38(Idx)
204304  , p_source_39 => l_array_source_39(Idx)
204305  , p_source_40 => l_array_source_40(Idx)
204306  );
204307 If(l_balance_type_code = 'A') THEN
204308   l_actual_gain_loss_ref := l_gain_or_loss_ref;
204309 END IF;
204310 
204311 --
204312 
204313 
204314 --
204315 AcctLineType_293 (
204316  p_application_id  => p_application_id
204317  ,p_event_id     => l_event_id
204318  ,p_calculate_acctd_flag => l_calculate_acctd_flag
204319  ,p_calculate_g_l_flag => l_calculate_g_l_flag
204320  ,p_actual_flag => l_actual_flag
204321  ,p_balance_type_code => l_balance_type_code
204322  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
204323  
204324  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
204325  , p_source_3 => l_array_source_3(Idx)
204326  , p_source_10 => l_array_source_10(Idx)
204327  , p_source_17 => l_array_source_17(Idx)
204328  , p_source_29 => l_array_source_29(Idx)
204329  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
204330  , p_source_35 => l_array_source_35(Idx)
204331  , p_source_36 => l_array_source_36(Idx)
204332  , p_source_37 => l_array_source_37(Idx)
204333  , p_source_38 => l_array_source_38(Idx)
204334  , p_source_39 => l_array_source_39(Idx)
204335  , p_source_40 => l_array_source_40(Idx)
204336  , p_source_42 => l_array_source_42(Idx)
204337  );
204338 If(l_balance_type_code = 'A') THEN
204339   l_actual_gain_loss_ref := l_gain_or_loss_ref;
204340 END IF;
204341 
204342 --
204343 
204344 
204345 --
204346 AcctLineType_294 (
204347  p_application_id  => p_application_id
204348  ,p_event_id     => l_event_id
204349  ,p_calculate_acctd_flag => l_calculate_acctd_flag
204350  ,p_calculate_g_l_flag => l_calculate_g_l_flag
204351  ,p_actual_flag => l_actual_flag
204352  ,p_balance_type_code => l_balance_type_code
204353  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
204354  
204355  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
204356  , p_source_3 => l_array_source_3(Idx)
204357  , p_source_10 => l_array_source_10(Idx)
204358  , p_source_17 => l_array_source_17(Idx)
204359  , p_source_29 => l_array_source_29(Idx)
204360  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
204361  , p_source_35 => l_array_source_35(Idx)
204362  , p_source_36 => l_array_source_36(Idx)
204363  , p_source_37 => l_array_source_37(Idx)
204367  , p_source_42 => l_array_source_42(Idx)
204364  , p_source_38 => l_array_source_38(Idx)
204365  , p_source_39 => l_array_source_39(Idx)
204366  , p_source_40 => l_array_source_40(Idx)
204368  );
204369 If(l_balance_type_code = 'A') THEN
204370   l_actual_gain_loss_ref := l_gain_or_loss_ref;
204371 END IF;
204372 
204373 --
204374 
204375       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
204376       -- or secondary ledger that has different currency with primary
204377       -- or alc that is calculated by sla
204378       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
204379             (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'))
204380 
204381 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
204382 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
204383           AND (l_actual_flag = 'A')) THEN
204384         XLA_AE_LINES_PKG.CreateGainOrLossLines(
204385           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
204386          ,p_application_id   => p_application_id
204387          ,p_amb_context_code => 'DEFAULT'
204388          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
204389          ,p_event_class_code => C_EVENT_CLASS_CODE
204390          ,p_event_type_code  => C_EVENT_TYPE_CODE
204391          
204392          ,p_gain_ccid        => -1
204393          ,p_loss_ccid        => -1
204394 
204395          ,p_actual_flag      => l_actual_flag
204396          ,p_enc_flag         => null
204397          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
204398          ,p_enc_g_l_ref      => null
204399          );
204400       END IF;
204401    END IF;
204402 END IF;
204403 
204404    ELSE
204405       --
204406       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
204407       --
204408       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
204409          trace
204410             (p_msg      => 'Trancaction revesal option is Y'
204411             ,p_level    => C_LEVEL_STATEMENT
204412             ,p_module   => l_log_module);
204413       END IF;
204414    END IF;
204415 
204416 END LOOP;
204417 l_result := XLA_AE_LINES_PKG.InsertLines ;
204418 end loop;
204419 close line_cur;
204420 
204421 
204422 --
204423 -- insert headers into xla_ae_headers_gt table
204424 --
204425 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
204426 
204427 -- insert into errors table here.
204428 
204429 END LOOP;
204430 
204431 --
204432 -- 4865292
204433 --
204434 -- Compare g_hdr_extract_count with event count in
204435 -- CreateHeadersAndLines.
204436 --
204437 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
204438 
204439 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
204440    trace (p_msg     => '# rows extracted from header extract objects '
204441                     || ' (running total): '
204442                     || g_hdr_extract_count
204443          ,p_level   => C_LEVEL_STATEMENT
204444          ,p_module  => l_log_module);
204445 END IF;
204446 
204447 CLOSE header_cur;
204448 --
204449 
204450 --
204451 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
204452    trace
204453       (p_msg      => 'END of EventClass_424'
204454       ,p_level    => C_LEVEL_PROCEDURE
204455       ,p_module   => l_log_module);
204456 END IF;
204457 --
204458 RETURN l_result;
204459 EXCEPTION
204460 WHEN xla_exceptions_pkg.application_exception THEN
204461    
204462 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
204463 
204464    
204465 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
204466 
204467    RAISE;
204468 
204469 WHEN NO_DATA_FOUND THEN
204470 
204471 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
204472 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
204473 
204474 FOR header_record IN header_cur
204475 LOOP
204476     l_array_header_events(header_record.event_id) := header_record.event_id;
204477 END LOOP;
204478 
204479 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
204480 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
204481 
204482 fnd_file.put_line(fnd_file.LOG, '                    ');
204483 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
204484 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
204485 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
204486 
204487 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
204488 LOOP
204489 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
204490 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
204491         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
204492 	END IF;
204493 END LOOP;
204494 
204495 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
204496 fnd_file.put_line(fnd_file.LOG, '                    ');
204497 
204498 
204499 xla_exceptions_pkg.raise_message
204500       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_424');
204501 
204502 
204503 WHEN OTHERS THEN
204504    xla_exceptions_pkg.raise_message
204505       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_424');
204506 END EventClass_424;
204507 --
204508 
204509 ---------------------------------------
204510 --
204511 -- PRIVATE PROCEDURE
204512 --         insert_sources_425
204513 --
204514 ----------------------------------------
204515 --
204519                               , p_sla_ledger_id          IN NUMBER
204516 PROCEDURE insert_sources_425(
204517                                 p_target_ledger_id       IN NUMBER
204518                               , p_language               IN VARCHAR2
204520                               , p_pad_start_date         IN DATE
204521                               , p_pad_end_date           IN DATE
204522                          )
204523 IS
204524 
204525 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RETIREMENTS';
204526 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'RETIREMENTS';
204527 p_apps_owner                   VARCHAR2(30);
204528 l_log_module                   VARCHAR2(240);
204529 BEGIN
204530 IF g_log_enabled THEN
204531       l_log_module := C_DEFAULT_MODULE||'.insert_sources_425';
204532 END IF;
204533 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
204534 
204535       trace
204536          (p_msg      => 'BEGIN of insert_sources_425'
204537          ,p_level    => C_LEVEL_PROCEDURE
204538          ,p_module   => l_log_module);
204539 
204540 END IF;
204541 
204542 -- select APPS owner
204543 SELECT oracle_username
204544   INTO p_apps_owner
204545   FROM fnd_oracle_userid
204546  WHERE read_only_flag = 'U'
204547 ;
204548 
204549 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
204550       trace
204551          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
204552                         ' - p_language = '||p_language||
204553                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
204554                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
204555                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
204556                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
204557          ,p_level    => C_LEVEL_STATEMENT
204558          ,p_module   => l_log_module);
204559 END IF;
204560 
204561 
204562 --
204563 INSERT INTO xla_diag_sources --hdr1
204564 (
204565         event_id
204566       , ledger_id
204567       , sla_ledger_id
204568       , description_language
204569       , object_name
204570       , object_type_code
204571       , line_number
204572       , source_application_id
204573       , source_type_code
204574       , source_code
204575       , source_value
204576       , source_meaning
204577       , created_by
204578       , creation_date
204579       , last_update_date
204580       , last_updated_by
204581       , last_update_login
204582       , program_update_date
204583       , program_application_id
204584       , program_id
204585       , request_id
204586 )
204587 SELECT
204588         event_id
204589       , p_target_ledger_id
204590       , p_sla_ledger_id
204591       , p_language
204592       , object_name
204593       , object_type_code
204594       , line_number
204595       , source_application_id
204596       , source_type_code
204597       , source_code
204598       , SUBSTR(source_value ,1,1996)
204599       , SUBSTR(source_meaning,1,200)
204600       , xla_environment_pkg.g_Usr_Id
204601       , TRUNC(SYSDATE)
204602       , TRUNC(SYSDATE)
204603       , xla_environment_pkg.g_Usr_Id
204604       , xla_environment_pkg.g_Login_Id
204605       , TRUNC(SYSDATE)
204606       , xla_environment_pkg.g_Prog_Appl_Id
204607       , xla_environment_pkg.g_Prog_Id
204608       , xla_environment_pkg.g_Req_Id
204609   FROM (
204610        SELECT xet.event_id                  event_id
204611             , 0                             line_number
204612             , CASE r
204613                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204614                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204615                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204616                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204617                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204618                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204619                 WHEN 7 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204620                 WHEN 8 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204621                 WHEN 9 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204622                 WHEN 10 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204623                 WHEN 11 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204624                 WHEN 12 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204625                 WHEN 13 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204626                 WHEN 14 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
204627                 
204628                ELSE null
204629               END                           object_name
204630             , CASE r
204631                 WHEN 1 THEN 'HEADER' 
204632                 WHEN 2 THEN 'HEADER' 
204633                 WHEN 3 THEN 'HEADER' 
204634                 WHEN 4 THEN 'HEADER' 
204635                 WHEN 5 THEN 'HEADER' 
204636                 WHEN 6 THEN 'HEADER' 
204637                 WHEN 7 THEN 'HEADER' 
204638                 WHEN 8 THEN 'HEADER' 
204639                 WHEN 9 THEN 'HEADER' 
204640                 WHEN 10 THEN 'HEADER' 
204641                 WHEN 11 THEN 'HEADER' 
204642                 WHEN 12 THEN 'HEADER' 
204643                 WHEN 13 THEN 'HEADER' 
204644                 WHEN 14 THEN 'HEADER' 
204645                 
204646                 ELSE null
204647               END                           object_type_code
204648             , CASE r
204649                 WHEN 1 THEN '140' 
204650                 WHEN 2 THEN '140' 
204651                 WHEN 3 THEN '140' 
204652                 WHEN 4 THEN '140' 
204653                 WHEN 5 THEN '140' 
204654                 WHEN 6 THEN '140' 
204655                 WHEN 7 THEN '140' 
204656                 WHEN 8 THEN '140' 
204657                 WHEN 9 THEN '140' 
204658                 WHEN 10 THEN '140' 
204659                 WHEN 11 THEN '140' 
204660                 WHEN 12 THEN '140' 
204661                 WHEN 13 THEN '140' 
204662                 WHEN 14 THEN '140' 
204666             , 'S'             source_type_code
204663                 
204664                 ELSE null
204665               END                           source_application_id
204667             , CASE r
204668                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
204669                 WHEN 2 THEN 'COST_OF_REMOVAL_CLEARING_ACCT' 
204670                 WHEN 3 THEN 'COST_OF_REMOVAL_GAIN_ACCT' 
204671                 WHEN 4 THEN 'COST_OF_REMOVAL_LOSS_ACCT' 
204672                 WHEN 5 THEN 'NBV_RETIRED_GAIN_ACCT' 
204673                 WHEN 6 THEN 'NBV_RETIRED_LOSS_ACCT' 
204674                 WHEN 7 THEN 'PROCEEDS_OF_SALE_CLEARING_ACCT' 
204675                 WHEN 8 THEN 'PROCEEDS_OF_SALE_GAIN_ACCT' 
204676                 WHEN 9 THEN 'PROCEEDS_OF_SALE_LOSS_ACCT' 
204677                 WHEN 10 THEN 'REVAL_RSV_RETIRED_GAIN_ACCT' 
204678                 WHEN 11 THEN 'REVAL_RSV_RETIRED_LOSS_ACCT' 
204679                 WHEN 12 THEN 'DEFAULT_CCID' 
204680                 WHEN 13 THEN 'ACCOUNTING_DATE' 
204681                 WHEN 14 THEN 'TRANSFER_TO_GL_FLAG' 
204682                 
204683                 ELSE null
204684               END                           source_code
204685             , CASE r
204686                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
204687                 WHEN 2 THEN TO_CHAR(h1.COST_OF_REMOVAL_CLEARING_ACCT)
204688                 WHEN 3 THEN TO_CHAR(h1.COST_OF_REMOVAL_GAIN_ACCT)
204689                 WHEN 4 THEN TO_CHAR(h1.COST_OF_REMOVAL_LOSS_ACCT)
204690                 WHEN 5 THEN TO_CHAR(h1.NBV_RETIRED_GAIN_ACCT)
204691                 WHEN 6 THEN TO_CHAR(h1.NBV_RETIRED_LOSS_ACCT)
204692                 WHEN 7 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_CLEARING_ACCT)
204693                 WHEN 8 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_GAIN_ACCT)
204694                 WHEN 9 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_LOSS_ACCT)
204695                 WHEN 10 THEN TO_CHAR(h1.REVAL_RSV_RETIRED_GAIN_ACCT)
204696                 WHEN 11 THEN TO_CHAR(h1.REVAL_RSV_RETIRED_LOSS_ACCT)
204697                 WHEN 12 THEN TO_CHAR(h1.DEFAULT_CCID)
204698                 WHEN 13 THEN TO_CHAR(h1.ACCOUNTING_DATE)
204699                 WHEN 14 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
204700                 
204701                 ELSE null
204702               END                           source_value
204703             , null              source_meaning
204704         FROM xla_events_gt     xet  
204705       , FA_XLA_EXT_HEADERS_B_GT  h1
204706             ,(select rownum r from all_objects where rownum <= 14 and owner = p_apps_owner)
204707        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
204708          AND xet.event_type_code = C_EVENT_TYPE_CODE
204709             AND h1.event_id = xet.event_id
204710 
204711 )
204712 ;
204713 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
204714 
204715       trace
204716          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
204717          ,p_level    => C_LEVEL_STATEMENT
204718          ,p_module   => l_log_module);
204719 
204720 END IF;
204721 --
204722 
204723 
204724 
204725 --
204726 INSERT INTO xla_diag_sources --line1
204727 (
204728         event_id
204729       , ledger_id
204730       , sla_ledger_id
204731       , description_language
204732       , object_name
204733       , object_type_code
204734       , line_number
204735       , source_application_id
204736       , source_type_code
204737       , source_code
204738       , source_value
204739       , source_meaning
204740       , created_by
204741       , creation_date
204742       , last_update_date
204743       , last_updated_by
204744       , last_update_login
204745       , program_update_date
204746       , program_application_id
204747       , program_id
204748       , request_id
204749 )
204750 SELECT  event_id
204751       , p_target_ledger_id
204752       , p_sla_ledger_id
204753       , p_language
204754       , object_name
204755       , object_type_code
204756       , line_number
204757       , source_application_id
204758       , source_type_code
204759       , source_code
204760       , SUBSTR(source_value,1,1996)
204761       , SUBSTR(source_meaning,1,200)
204762       , xla_environment_pkg.g_Usr_Id
204763       , TRUNC(SYSDATE)
204764       , TRUNC(SYSDATE)
204765       , xla_environment_pkg.g_Usr_Id
204766       , xla_environment_pkg.g_Login_Id
204767       , TRUNC(SYSDATE)
204768       , xla_environment_pkg.g_Prog_Appl_Id
204769       , xla_environment_pkg.g_Prog_Id
204770       , xla_environment_pkg.g_Req_Id
204771   FROM (
204772        SELECT xet.event_id                  event_id
204773             , l2.line_number                 line_number
204774             , CASE r
204775                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
204776                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
204777                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
204778                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
204779                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
204780                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
204781                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
204782                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
204783                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
204784                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
204785                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
204786                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
204787                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
204788                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
204789                 WHEN 15 THEN 'FA_XLA_EXT_LINES_B_GT' 
204790                 
204791                ELSE null
204792               END                           object_name
204793             , CASE r
204794                 WHEN 1 THEN 'LINE' 
204795                 WHEN 2 THEN 'LINE' 
204796                 WHEN 3 THEN 'LINE' 
204797                 WHEN 4 THEN 'LINE' 
204798                 WHEN 5 THEN 'LINE' 
204799                 WHEN 6 THEN 'LINE' 
204803                 WHEN 10 THEN 'LINE' 
204800                 WHEN 7 THEN 'LINE' 
204801                 WHEN 8 THEN 'LINE' 
204802                 WHEN 9 THEN 'LINE' 
204804                 WHEN 11 THEN 'LINE' 
204805                 WHEN 12 THEN 'LINE' 
204806                 WHEN 13 THEN 'LINE' 
204807                 WHEN 14 THEN 'LINE' 
204808                 WHEN 15 THEN 'LINE' 
204809                 
204810                 ELSE null
204811               END                           object_type_code
204812             , CASE r
204813                 WHEN 1 THEN '140' 
204814                 WHEN 2 THEN '140' 
204815                 WHEN 3 THEN '140' 
204816                 WHEN 4 THEN '140' 
204817                 WHEN 5 THEN '140' 
204818                 WHEN 6 THEN '140' 
204819                 WHEN 7 THEN '140' 
204820                 WHEN 8 THEN '140' 
204821                 WHEN 9 THEN '140' 
204822                 WHEN 10 THEN '140' 
204823                 WHEN 11 THEN '140' 
204824                 WHEN 12 THEN '140' 
204825                 WHEN 13 THEN '140' 
204826                 WHEN 14 THEN '140' 
204827                 WHEN 15 THEN '140' 
204828                 
204829                 ELSE null
204830               END                           source_application_id
204831             , 'S'             source_type_code
204832             , CASE r
204833                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
204834                 WHEN 2 THEN 'GENERATED_CCID' 
204835                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
204836                 WHEN 4 THEN 'ASSET_COST_ACCT' 
204837                 WHEN 5 THEN 'DEPRN_RESERVE_ACCT' 
204838                 WHEN 6 THEN 'REVAL_RESERVE_ACCT' 
204839                 WHEN 7 THEN 'GENERATED_OFFSET_CCID' 
204840                 WHEN 8 THEN 'EXPENSE_ACCOUNT_CCID' 
204841                 WHEN 9 THEN 'ADJUSTMENT_TYPE' 
204842                 WHEN 10 THEN 'TRANSACTION_HEADER_ID' 
204843                 WHEN 11 THEN 'ADJUSTMENT_LINE_ID' 
204844                 WHEN 12 THEN 'DISTRIBUTION_TYPE_CODE' 
204845                 WHEN 13 THEN 'ENTERED_AMOUNT' 
204846                 WHEN 14 THEN 'CURRENCY_CODE' 
204847                 WHEN 15 THEN 'GAIN_LOSS_AMOUNT' 
204848                 
204849                 ELSE null
204850               END                           source_code
204851             , CASE r
204852                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
204853                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
204854                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
204855                 WHEN 4 THEN TO_CHAR(l2.ASSET_COST_ACCT)
204856                 WHEN 5 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
204857                 WHEN 6 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
204858                 WHEN 7 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
204859                 WHEN 8 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
204860                 WHEN 9 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
204861                 WHEN 10 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
204862                 WHEN 11 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
204863                 WHEN 12 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
204864                 WHEN 13 THEN TO_CHAR(l2.ENTERED_AMOUNT)
204865                 WHEN 14 THEN TO_CHAR(l2.CURRENCY_CODE)
204866                 WHEN 15 THEN TO_CHAR(l2.GAIN_LOSS_AMOUNT)
204867                 
204868                 ELSE null
204869               END                           source_value
204870             , null              source_meaning
204871          FROM  xla_events_gt     xet  
204872         , FA_XLA_EXT_LINES_B_GT  l2
204873             ,(select rownum r from all_objects where rownum <= 15 and owner = p_apps_owner)
204874         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
204875           AND xet.event_type_code = C_EVENT_TYPE_CODE
204876             AND l2.event_id          = xet.event_id
204877   AND l2.ledger_id (+)  = p_sla_ledger_id
204878 
204879 )
204880 ;
204881 --
204882 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
204883 
204884       trace
204885          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
204886          ,p_level    => C_LEVEL_STATEMENT
204887          ,p_module   => l_log_module);
204888 
204889 END IF;
204890 
204891 
204892 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
204893       trace
204894          (p_msg      => 'END of insert_sources_425'
204895          ,p_level    => C_LEVEL_PROCEDURE
204896          ,p_module   => l_log_module);
204897 END IF;
204898 EXCEPTION
204899   WHEN xla_exceptions_pkg.application_exception THEN
204900       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
204901             trace
204902                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
204903                ,p_level    => C_LEVEL_EXCEPTION
204904                ,p_module   => l_log_module);
204905       END IF;
204906       RAISE;
204907   WHEN OTHERS THEN
204908       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
204909             trace
204910                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
204911                ,p_level    => C_LEVEL_EXCEPTION
204912                ,p_module   => l_log_module);
204913        END IF;
204914        xla_exceptions_pkg.raise_message
204915            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_425');
204916 END insert_sources_425;
204917 --
204918 
204919 ---------------------------------------
204920 --
204921 -- PRIVATE FUNCTION
204922 --         EventType_425
204923 --
204924 ----------------------------------------
204925 --
204926 FUNCTION EventType_425
204927        (p_application_id         IN NUMBER
204928        ,p_base_ledger_id         IN NUMBER
204929        ,p_target_ledger_id       IN NUMBER
204930        ,p_language               IN VARCHAR2
204931        ,p_currency_code          IN VARCHAR2
204932        ,p_sla_ledger_id          IN NUMBER
204933        ,p_pad_start_date         IN DATE
204934        ,p_pad_end_date           IN DATE
204938 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RETIREMENTS';
204935        ,p_primary_ledger_id      IN NUMBER)
204936 RETURN BOOLEAN IS
204937 --
204939 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'RETIREMENTS';
204940 
204941 l_calculate_acctd_flag   VARCHAR2(1) :='N';
204942 l_calculate_g_l_flag     VARCHAR2(1) :='N';
204943 --
204944 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
204945 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
204946 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
204947 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
204948 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
204949 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
204950 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
204951 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
204952 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
204953 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
204954 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
204955 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
204956 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
204957 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
204958 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
204959 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
204960 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
204961 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
204962 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
204963 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
204964 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
204965 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
204966 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
204967 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
204968 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
204969 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
204970 
204971 l_event_id                             NUMBER;
204972 l_previous_event_id                    NUMBER;
204973 l_first_event_id                       NUMBER;
204974 l_last_event_id                        NUMBER;
204975 
204976 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
204977 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
204978 --
204979 --
204980 l_result                    BOOLEAN := TRUE;
204981 l_rows                      NUMBER  := 1000;
204982 l_event_type_name           VARCHAR2(80) := 'Retirements';
204983 l_event_class_name          VARCHAR2(80) := 'Retirements';
204984 l_description               VARCHAR2(4000);
204985 l_transaction_reversal      NUMBER;
204986 l_ae_header_id              NUMBER;
204987 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
204988 l_log_module                VARCHAR2(240);
204989 --
204990 l_acct_reversal_source      VARCHAR2(30);
204991 l_trx_reversal_source       VARCHAR2(30);
204992 
204993 l_continue_with_lines       BOOLEAN := TRUE;
204994 --
204995 l_acc_rev_gl_date_source    DATE;                      -- 4262811
204996 --
204997 type t_array_event_id is table of number index by binary_integer;
204998 
204999 l_rec_array_event                    t_rec_array_event;
205000 l_null_rec_array_event               t_rec_array_event;
205001 l_array_ae_header_id                 xla_number_array_type;
205002 l_actual_flag                        VARCHAR2(1) := NULL;
205003 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
205004 l_balance_type_code                  VARCHAR2(1) :=NULL;
205005 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
205006 
205007 --
205008 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
205009 --
205010 
205011 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
205012 TYPE t_array_source_12 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
205013 TYPE t_array_source_13 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
205014 TYPE t_array_source_14 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
205015 TYPE t_array_source_21 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
205016 TYPE t_array_source_22 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
205017 TYPE t_array_source_23 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
205018 TYPE t_array_source_24 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
205019 TYPE t_array_source_25 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
205020 TYPE t_array_source_27 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.REVAL_RSV_RETIRED_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
205021 TYPE t_array_source_28 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.REVAL_RSV_RETIRED_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
205022 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
205023 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
205024 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
205025 
205026 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
205027 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
205028 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
205032 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
205029 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
205030 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
205031 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
205033 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
205034 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
205035 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
205036 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
205037 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
205038 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
205039 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
205040 TYPE t_array_source_41 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GAIN_LOSS_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
205041 
205042 l_array_source_1              t_array_source_1;
205043 l_array_source_12              t_array_source_12;
205044 l_array_source_13              t_array_source_13;
205045 l_array_source_14              t_array_source_14;
205046 l_array_source_21              t_array_source_21;
205047 l_array_source_22              t_array_source_22;
205048 l_array_source_23              t_array_source_23;
205049 l_array_source_24              t_array_source_24;
205050 l_array_source_25              t_array_source_25;
205051 l_array_source_27              t_array_source_27;
205052 l_array_source_28              t_array_source_28;
205053 l_array_source_30              t_array_source_30;
205054 l_array_source_51              t_array_source_51;
205055 l_array_source_52              t_array_source_52;
205056 
205057 l_array_source_2      t_array_source_2;
205058 l_array_source_3      t_array_source_3;
205059 l_array_source_4      t_array_source_4;
205060 l_array_source_9      t_array_source_9;
205061 l_array_source_10      t_array_source_10;
205062 l_array_source_11      t_array_source_11;
205063 l_array_source_17      t_array_source_17;
205064 l_array_source_29      t_array_source_29;
205065 l_array_source_35      t_array_source_35;
205066 l_array_source_36      t_array_source_36;
205067 l_array_source_37      t_array_source_37;
205068 l_array_source_38      t_array_source_38;
205069 l_array_source_39      t_array_source_39;
205070 l_array_source_40      t_array_source_40;
205071 l_array_source_41      t_array_source_41;
205072 
205073 --
205074 CURSOR header_cur
205075 IS
205076 SELECT /*+ leading(xet) cardinality(xet,1) */
205077 -- Event Type Code: RETIREMENTS
205078 -- Event Class Code: RETIREMENTS
205079     xet.entity_id
205080   , xet.legal_entity_id
205081   , xet.entity_code
205082   , xet.transaction_number
205083   , xet.event_id
205084   , xet.event_class_code
205085   , xet.event_type_code
205086   , xet.event_number
205087   , xet.event_date
205088   , xet.transaction_date
205089   , xet.reference_num_1
205090   , xet.reference_num_2
205091   , xet.reference_num_3
205092   , xet.reference_num_4
205093   , xet.reference_char_1
205094   , xet.reference_char_2
205095   , xet.reference_char_3
205096   , xet.reference_char_4
205097   , xet.reference_date_1
205098   , xet.reference_date_2
205099   , xet.reference_date_3
205100   , xet.reference_date_4
205101   , xet.event_created_by
205102   , xet.budgetary_control_flag 
205103   , h1.PERIOD_CLOSE_DATE    source_1
205104   , h1.COST_OF_REMOVAL_CLEARING_ACCT    source_12
205105   , h1.COST_OF_REMOVAL_GAIN_ACCT    source_13
205106   , h1.COST_OF_REMOVAL_LOSS_ACCT    source_14
205107   , h1.NBV_RETIRED_GAIN_ACCT    source_21
205108   , h1.NBV_RETIRED_LOSS_ACCT    source_22
205109   , h1.PROCEEDS_OF_SALE_CLEARING_ACCT    source_23
205110   , h1.PROCEEDS_OF_SALE_GAIN_ACCT    source_24
205111   , h1.PROCEEDS_OF_SALE_LOSS_ACCT    source_25
205112   , h1.REVAL_RSV_RETIRED_GAIN_ACCT    source_27
205113   , h1.REVAL_RSV_RETIRED_LOSS_ACCT    source_28
205114   , h1.DEFAULT_CCID    source_30
205115   , h1.ACCOUNTING_DATE    source_51
205116   , h1.TRANSFER_TO_GL_FLAG    source_52
205117   FROM xla_events_gt     xet 
205118   , FA_XLA_EXT_HEADERS_B_GT  h1
205119  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
205120    and xet.event_type_code = C_EVENT_TYPE_CODE
205121    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
205122 
205123  ORDER BY event_id
205124 ;
205125 
205126 
205127 --
205128 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
205129 IS
205130 SELECT /*+ leading(xet) cardinality(xet,1) */
205131 -- Event Type Code: RETIREMENTS
205132 -- Event Class Code: RETIREMENTS
205133     xet.entity_id
205134    ,xet.legal_entity_id
205135    ,xet.entity_code
205136    ,xet.transaction_number
205137    ,xet.event_id
205138    ,xet.event_class_code
205139    ,xet.event_type_code
205140    ,xet.event_number
205141    ,xet.event_date
205142    ,xet.transaction_date
205143    ,xet.reference_num_1
205144    ,xet.reference_num_2
205145    ,xet.reference_num_3
205146    ,xet.reference_num_4
205147    ,xet.reference_char_1
205148    ,xet.reference_char_2
205149    ,xet.reference_char_3
205150    ,xet.reference_char_4
205151    ,xet.reference_date_1
205152    ,xet.reference_date_2
205153    ,xet.reference_date_3
205154    ,xet.reference_date_4
205155    ,xet.event_created_by
205156    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
205157   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
205158   , l2.GENERATED_CCID    source_3
205159   , l2.BONUS_RESERVE_ACCT    source_4
205160   , l2.ASSET_COST_ACCT    source_9
205161   , l2.DEPRN_RESERVE_ACCT    source_10
205165   , l2.ADJUSTMENT_TYPE    source_35
205162   , l2.REVAL_RESERVE_ACCT    source_11
205163   , l2.GENERATED_OFFSET_CCID    source_17
205164   , l2.EXPENSE_ACCOUNT_CCID    source_29
205166   , l2.TRANSACTION_HEADER_ID    source_36
205167   , l2.ADJUSTMENT_LINE_ID    source_37
205168   , l2.DISTRIBUTION_TYPE_CODE    source_38
205169   , l2.ENTERED_AMOUNT    source_39
205170   , l2.CURRENCY_CODE    source_40
205171   , l2.GAIN_LOSS_AMOUNT    source_41
205172   FROM xla_events_gt     xet 
205173   , FA_XLA_EXT_LINES_B_GT  l2
205174  WHERE xet.event_id between x_first_event_id and x_last_event_id
205175    and xet.event_date between p_pad_start_date and p_pad_end_date
205176    and xet.event_type_code = C_EVENT_TYPE_CODE
205177    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
205178   AND l2.ledger_id = p_sla_ledger_id
205179 ;
205180 
205181 --
205182 BEGIN
205183 IF g_log_enabled THEN
205184    l_log_module := C_DEFAULT_MODULE||'.EventType_425';
205185 END IF;
205186 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
205187    trace
205188       (p_msg      => 'BEGIN of EventType_425'
205189       ,p_level    => C_LEVEL_PROCEDURE
205190       ,p_module   => l_log_module);
205191 END IF;
205192 
205193 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
205194    trace
205195       (p_msg      => 'p_application_id = '||p_application_id||
205196                      ' - p_base_ledger_id = '||p_base_ledger_id||
205197                      ' - p_target_ledger_id  = '||p_target_ledger_id||
205198                      ' - p_language = '||p_language||
205199                      ' - p_currency_code = '||p_currency_code||
205200                      ' - p_sla_ledger_id = '||p_sla_ledger_id
205201       ,p_level    => C_LEVEL_STATEMENT
205202       ,p_module   => l_log_module);
205203 END IF;
205204 --
205205 -- initialze arrays
205206 --
205207 g_array_event.DELETE;
205208 l_rec_array_event := l_null_rec_array_event;
205209 --
205210 --------------------------------------
205211 -- 4262811 Initialze MPA Line Number
205212 --------------------------------------
205213 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
205214 
205215 --
205216 
205217 --
205218 OPEN header_cur;
205219 --
205220 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
205221    trace
205222    (p_msg      => 'SQL - FETCH header_cur'
205223    ,p_level    => C_LEVEL_STATEMENT
205224    ,p_module   => l_log_module);
205225 END IF;
205226 --
205227 LOOP
205228 FETCH header_cur BULK COLLECT INTO
205229         l_array_entity_id
205230       , l_array_legal_entity_id
205231       , l_array_entity_code
205232       , l_array_transaction_num
205233       , l_array_event_id
205234       , l_array_class_code
205235       , l_array_event_type
205236       , l_array_event_number
205237       , l_array_event_date
205238       , l_array_transaction_date
205239       , l_array_reference_num_1
205240       , l_array_reference_num_2
205241       , l_array_reference_num_3
205242       , l_array_reference_num_4
205243       , l_array_reference_char_1
205244       , l_array_reference_char_2
205245       , l_array_reference_char_3
205246       , l_array_reference_char_4
205247       , l_array_reference_date_1
205248       , l_array_reference_date_2
205249       , l_array_reference_date_3
205250       , l_array_reference_date_4
205251       , l_array_event_created_by
205252       , l_array_budgetary_control_flag 
205253       , l_array_source_1
205254       , l_array_source_12
205255       , l_array_source_13
205256       , l_array_source_14
205257       , l_array_source_21
205258       , l_array_source_22
205259       , l_array_source_23
205260       , l_array_source_24
205261       , l_array_source_25
205262       , l_array_source_27
205263       , l_array_source_28
205264       , l_array_source_30
205265       , l_array_source_51
205266       , l_array_source_52
205267       LIMIT l_rows;
205268 --
205269 IF (C_LEVEL_EVENT >= g_log_level) THEN
205270    trace
205271    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
205272    ,p_level    => C_LEVEL_EVENT
205273    ,p_module   => l_log_module);
205274 END IF;
205275 --
205276 EXIT WHEN l_array_entity_id.COUNT = 0;
205277 
205278 -- initialize arrays
205279 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
205280 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
205281 
205282 --
205283 -- Bug 4458708
205284 --
205285 XLA_AE_LINES_PKG.g_LineNumber := 0;
205286 
205287 
205288 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
205289 g_last_hdr_idx := l_array_event_id.LAST;
205290 --
205291 -- loop for the headers. Each iteration is for each header extract row
205292 -- fetched in header cursor
205293 --
205294 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
205295 
205296 --
205297 -- set event info as cache for other routines to refer event attributes
205298 --
205299 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
205300    (p_application_id           => p_application_id
205301    ,p_primary_ledger_id        => p_primary_ledger_id
205302    ,p_base_ledger_id           => p_base_ledger_id
205303    ,p_target_ledger_id         => p_target_ledger_id
205304    ,p_entity_id                => l_array_entity_id(hdr_idx)
205305    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
205306    ,p_entity_code              => l_array_entity_code(hdr_idx)
205307    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
205308    ,p_event_id                 => l_array_event_id(hdr_idx)
205309    ,p_event_class_code         => l_array_class_code(hdr_idx)
205310    ,p_event_type_code          => l_array_event_type(hdr_idx)
205311    ,p_event_number             => l_array_event_number(hdr_idx)
205312    ,p_event_date               => l_array_event_date(hdr_idx)
205316    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
205313    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
205314    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
205315    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
205317    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
205318    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
205319    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
205320    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
205321    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
205322    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
205323    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
205324    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
205325    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
205326    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
205327    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
205328 
205329 --
205330 -- set the status of entry to C_VALID (0)
205331 --
205332 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
205333 
205334 --
205335 -- initialize a row for ae header
205336 --
205337 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
205338 
205339 l_event_id := l_array_event_id(hdr_idx);
205340 
205341 --
205342 -- storing the hdr_idx for event. May be used by line cursor.
205343 --
205344 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
205345 
205346 --
205347 -- store sources from header extract. This can be improved to
205348 -- store only those sources from header extract that may be used in lines
205349 --
205350 
205351 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
205352 g_array_event(l_event_id).array_value_char('source_12') := l_array_source_12(hdr_idx);
205353 g_array_event(l_event_id).array_value_char('source_13') := l_array_source_13(hdr_idx);
205354 g_array_event(l_event_id).array_value_char('source_14') := l_array_source_14(hdr_idx);
205355 g_array_event(l_event_id).array_value_char('source_21') := l_array_source_21(hdr_idx);
205356 g_array_event(l_event_id).array_value_char('source_22') := l_array_source_22(hdr_idx);
205357 g_array_event(l_event_id).array_value_char('source_23') := l_array_source_23(hdr_idx);
205358 g_array_event(l_event_id).array_value_char('source_24') := l_array_source_24(hdr_idx);
205359 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
205360 g_array_event(l_event_id).array_value_char('source_27') := l_array_source_27(hdr_idx);
205361 g_array_event(l_event_id).array_value_char('source_28') := l_array_source_28(hdr_idx);
205362 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
205363 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
205364 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
205365 
205366 --
205367 -- initilaize the status of ae headers for diffrent balance types
205368 -- the status is initialised to C_NOT_CREATED (2)
205369 --
205370 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
205371 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
205372 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
205373 
205374 --
205375 -- call api to validate and store accounting attributes for header
205376 --
205377 
205378 ------------------------------------------------------------
205379 -- Accrual Reversal : to get date for Standard Source (NONE)
205380 ------------------------------------------------------------
205381 l_acc_rev_gl_date_source := NULL;
205382 
205383      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
205384       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
205385      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
205386       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
205387 
205388 
205389 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
205390 
205391 XLA_AE_HEADER_PKG.SetJeCategoryName;
205392 
205393 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
205394 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
205395 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
205396 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
205397 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
205398 
205399 
205400 --
205401 xla_ae_header_pkg.SetHdrDescription(
205402    p_description => Description_74 (
205403    p_application_id => p_application_id 
205404  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205405    )
205406 );
205407 --
205408 
205409 -- No header level analytical criteria
205410 
205411 --
205412 --accounting attribute enhancement, bug 3612931
205413 --
205414 l_trx_reversal_source := SUBSTR(NULL, 1,30);
205415 
205416 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
205417    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
205418 
205419    xla_accounting_err_pkg.build_message
205420       (p_appli_s_name            => 'XLA'
205421       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
205422       ,p_token_1                 => 'ACCT_ATTR_NAME'
205423       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
205424       ,p_token_2                 => 'PRODUCT_NAME'
205425       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
205426       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
205430 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
205427       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
205428       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
205429 
205431    --
205432    -- following sets the accounting attributes needed to reverse
205433    -- accounting for a distributeion
205434    --
205435    xla_ae_lines_pkg.SetTrxReversalAttrs
205436       (p_event_id              => l_event_id
205437       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
205438       ,p_trx_reversal_source   => l_trx_reversal_source);
205439 
205440 END IF;
205441 
205442 
205443 ----------------------------------------------------------------
205444 -- 4262811 -  update the header statuses to invalid in need be
205445 ----------------------------------------------------------------
205446 --
205447 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
205448 
205449 
205450   -----------------------------------------------
205451   -- No accrual reversal for the event class/type
205452   -----------------------------------------------
205453 ----------------------------------------------------------------
205454 
205455 --
205456 -- this ends the header loop iteration for one bulk fetch
205457 --
205458 END LOOP;
205459 
205460 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
205461 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
205462 
205463 --
205464 -- insert dummy rows into lines gt table that were created due to
205465 -- transaction reversals
205466 --
205467 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
205468    l_result := XLA_AE_LINES_PKG.InsertLines;
205469 END IF;
205470 
205471 --
205472 -- reset the temp_line_num for each set of events fetched from header
205473 -- cursor rather than doing it for each new event in line cursor
205474 -- Bug 3939231
205475 --
205476 xla_ae_lines_pkg.g_temp_line_num := 0;
205477 
205478 
205479 
205480 --
205481 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
205482 --
205483 --
205484 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
205485 
205486       trace
205487          (p_msg      => 'SQL - FETCH line_cur'
205488          ,p_level    => C_LEVEL_STATEMENT
205489          ,p_module   => l_log_module);
205490 
205491 END IF;
205492 --
205493 --
205494 LOOP
205495   --
205496   FETCH line_cur BULK COLLECT INTO
205497         l_array_entity_id
205498       , l_array_legal_entity_id
205499       , l_array_entity_code
205500       , l_array_transaction_num
205501       , l_array_event_id
205502       , l_array_class_code
205503       , l_array_event_type
205504       , l_array_event_number
205505       , l_array_event_date
205506       , l_array_transaction_date
205507       , l_array_reference_num_1
205508       , l_array_reference_num_2
205509       , l_array_reference_num_3
205510       , l_array_reference_num_4
205511       , l_array_reference_char_1
205512       , l_array_reference_char_2
205513       , l_array_reference_char_3
205514       , l_array_reference_char_4
205515       , l_array_reference_date_1
205516       , l_array_reference_date_2
205517       , l_array_reference_date_3
205518       , l_array_reference_date_4
205519       , l_array_event_created_by
205520       , l_array_budgetary_control_flag
205521       , l_array_extract_line_num 
205522       , l_array_source_2
205523       , l_array_source_3
205524       , l_array_source_4
205525       , l_array_source_9
205526       , l_array_source_10
205527       , l_array_source_11
205528       , l_array_source_17
205529       , l_array_source_29
205530       , l_array_source_35
205531       , l_array_source_36
205532       , l_array_source_37
205533       , l_array_source_38
205534       , l_array_source_39
205535       , l_array_source_40
205536       , l_array_source_41
205537       LIMIT l_rows;
205538 
205539   --
205540   IF (C_LEVEL_EVENT >= g_log_level) THEN
205541             trace
205542                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
205543                ,p_level    => C_LEVEL_EVENT
205544                ,p_module   => l_log_module);
205545   END IF;
205546   --
205547   EXIT WHEN l_array_entity_id.count = 0;
205548 
205549   XLA_AE_LINES_PKG.g_rec_lines := null;
205550 
205551 --
205552 -- Bug 4458708
205553 --
205554 XLA_AE_LINES_PKG.g_LineNumber := 0;
205555 --
205556 --
205557 
205558 FOR Idx IN 1..l_array_event_id.count LOOP
205559    --
205560    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
205561    --
205562    l_event_id := l_array_event_id(idx);  -- 5648433
205563 
205564    --
205565    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
205566    --
205567 
205568    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
205569              (g_array_event(l_event_id).array_value_num('header_index'))
205570          ,'N'
205571          ) <> 'Y'
205572    THEN
205573       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
205574          trace
205575             (p_msg      => 'Trancaction revesal option is not Y '
205576             ,p_level    => C_LEVEL_STATEMENT
205577             ,p_module   => l_log_module);
205578       END IF;
205579 
205580 --
205581 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
205582 --
205583 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
205584 --
205585 -- set event info as cache for other routines to refer event attributes
205586 --
205587 
205588 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
205592       (p_application_id           => p_application_id
205589    l_previous_event_id := l_event_id;
205590 
205591    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
205593       ,p_primary_ledger_id        => p_primary_ledger_id
205594       ,p_base_ledger_id           => p_base_ledger_id
205595       ,p_target_ledger_id         => p_target_ledger_id
205596       ,p_entity_id                => l_array_entity_id(Idx)
205597       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
205598       ,p_entity_code              => l_array_entity_code(Idx)
205599       ,p_transaction_num          => l_array_transaction_num(Idx)
205600       ,p_event_id                 => l_array_event_id(Idx)
205601       ,p_event_class_code         => l_array_class_code(Idx)
205602       ,p_event_type_code          => l_array_event_type(Idx)
205603       ,p_event_number             => l_array_event_number(Idx)
205604       ,p_event_date               => l_array_event_date(Idx)
205605       ,p_transaction_date         => l_array_transaction_date(Idx)
205606       ,p_reference_num_1          => l_array_reference_num_1(Idx)
205607       ,p_reference_num_2          => l_array_reference_num_2(Idx)
205608       ,p_reference_num_3          => l_array_reference_num_3(Idx)
205609       ,p_reference_num_4          => l_array_reference_num_4(Idx)
205610       ,p_reference_char_1         => l_array_reference_char_1(Idx)
205611       ,p_reference_char_2         => l_array_reference_char_2(Idx)
205612       ,p_reference_char_3         => l_array_reference_char_3(Idx)
205613       ,p_reference_char_4         => l_array_reference_char_4(Idx)
205614       ,p_reference_date_1         => l_array_reference_date_1(Idx)
205615       ,p_reference_date_2         => l_array_reference_date_2(Idx)
205616       ,p_reference_date_3         => l_array_reference_date_3(Idx)
205617       ,p_reference_date_4         => l_array_reference_date_4(Idx)
205618       ,p_event_created_by         => l_array_event_created_by(Idx)
205619       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
205620        --
205621 END IF;
205622 
205623 
205624 
205625 --
205626 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
205627 
205628 l_acct_reversal_source := SUBSTR(NULL, 1,30);
205629 
205630 IF l_continue_with_lines THEN
205631    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
205632       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
205633 
205634       xla_accounting_err_pkg.build_message
205635          (p_appli_s_name            => 'XLA'
205636          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
205637          ,p_token_1                 => 'LINE_NUMBER'
205638          ,p_value_1                 => l_array_extract_line_num(Idx)
205639          ,p_token_2                 => 'PRODUCT_NAME'
205640          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
205641          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
205642          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
205643          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
205644 
205645    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
205646       --
205647       -- following sets the accounting attributes needed to reverse
205648       -- accounting for a distributeion
205649       --
205650 
205651       --
205652       -- 5217187
205653       --
205654       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
205655       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
205656                                        g_array_event(l_event_id).array_value_num('header_index'));
205657       --
205658       --
205659 
205660       -- No reversal code generated
205661 
205662       xla_ae_lines_pkg.SetAcctReversalAttrs
205663          (p_event_id             => l_event_id
205664          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
205665          ,p_calculate_acctd_flag => l_calculate_acctd_flag
205666          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
205667    END IF;
205668 
205669    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
205670        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
205671 
205672 --
205673 AcctLineType_253 (
205674  p_application_id  => p_application_id
205675  ,p_event_id     => l_event_id
205676  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205677  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205678  ,p_actual_flag => l_actual_flag
205679  ,p_balance_type_code => l_balance_type_code
205680  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205681  
205682  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205683  , p_source_3 => l_array_source_3(Idx)
205684  , p_source_12 => g_array_event(l_event_id).array_value_char('source_12')
205685  , p_source_29 => l_array_source_29(Idx)
205686  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205687  , p_source_35 => l_array_source_35(Idx)
205688  , p_source_36 => l_array_source_36(Idx)
205689  , p_source_37 => l_array_source_37(Idx)
205690  , p_source_38 => l_array_source_38(Idx)
205691  , p_source_39 => l_array_source_39(Idx)
205692  , p_source_40 => l_array_source_40(Idx)
205693  );
205694 If(l_balance_type_code = 'A') THEN
205695   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205696 END IF;
205697 
205698 --
205699 
205700 
205701 --
205702 AcctLineType_255 (
205703  p_application_id  => p_application_id
205704  ,p_event_id     => l_event_id
205705  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205706  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205707  ,p_actual_flag => l_actual_flag
205708  ,p_balance_type_code => l_balance_type_code
205709  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205710  
205711  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205712  , p_source_3 => l_array_source_3(Idx)
205716  , p_source_35 => l_array_source_35(Idx)
205713  , p_source_13 => g_array_event(l_event_id).array_value_char('source_13')
205714  , p_source_29 => l_array_source_29(Idx)
205715  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205717  , p_source_36 => l_array_source_36(Idx)
205718  , p_source_37 => l_array_source_37(Idx)
205719  , p_source_38 => l_array_source_38(Idx)
205720  , p_source_39 => l_array_source_39(Idx)
205721  , p_source_40 => l_array_source_40(Idx)
205722  , p_source_41 => l_array_source_41(Idx)
205723  );
205724 If(l_balance_type_code = 'A') THEN
205725   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205726 END IF;
205727 
205728 --
205729 
205730 
205731 --
205732 AcctLineType_258 (
205733  p_application_id  => p_application_id
205734  ,p_event_id     => l_event_id
205735  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205736  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205737  ,p_actual_flag => l_actual_flag
205738  ,p_balance_type_code => l_balance_type_code
205739  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205740  
205741  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205742  , p_source_3 => l_array_source_3(Idx)
205743  , p_source_14 => g_array_event(l_event_id).array_value_char('source_14')
205744  , p_source_29 => l_array_source_29(Idx)
205745  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205746  , p_source_35 => l_array_source_35(Idx)
205747  , p_source_36 => l_array_source_36(Idx)
205748  , p_source_37 => l_array_source_37(Idx)
205749  , p_source_38 => l_array_source_38(Idx)
205750  , p_source_39 => l_array_source_39(Idx)
205751  , p_source_40 => l_array_source_40(Idx)
205752  , p_source_41 => l_array_source_41(Idx)
205753  );
205754 If(l_balance_type_code = 'A') THEN
205755   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205756 END IF;
205757 
205758 --
205759 
205760 
205761 --
205762 AcctLineType_261 (
205763  p_application_id  => p_application_id
205764  ,p_event_id     => l_event_id
205765  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205766  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205767  ,p_actual_flag => l_actual_flag
205768  ,p_balance_type_code => l_balance_type_code
205769  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205770  
205771  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205772  , p_source_3 => l_array_source_3(Idx)
205773  , p_source_21 => g_array_event(l_event_id).array_value_char('source_21')
205774  , p_source_29 => l_array_source_29(Idx)
205775  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205776  , p_source_35 => l_array_source_35(Idx)
205777  , p_source_36 => l_array_source_36(Idx)
205778  , p_source_37 => l_array_source_37(Idx)
205779  , p_source_38 => l_array_source_38(Idx)
205780  , p_source_39 => l_array_source_39(Idx)
205781  , p_source_40 => l_array_source_40(Idx)
205782  , p_source_41 => l_array_source_41(Idx)
205783  );
205784 If(l_balance_type_code = 'A') THEN
205785   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205786 END IF;
205787 
205788 --
205789 
205790 
205791 --
205792 AcctLineType_263 (
205793  p_application_id  => p_application_id
205794  ,p_event_id     => l_event_id
205795  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205796  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205797  ,p_actual_flag => l_actual_flag
205798  ,p_balance_type_code => l_balance_type_code
205799  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205800  
205801  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205802  , p_source_3 => l_array_source_3(Idx)
205803  , p_source_22 => g_array_event(l_event_id).array_value_char('source_22')
205804  , p_source_29 => l_array_source_29(Idx)
205805  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205806  , p_source_35 => l_array_source_35(Idx)
205807  , p_source_36 => l_array_source_36(Idx)
205808  , p_source_37 => l_array_source_37(Idx)
205809  , p_source_38 => l_array_source_38(Idx)
205810  , p_source_39 => l_array_source_39(Idx)
205811  , p_source_40 => l_array_source_40(Idx)
205812  , p_source_41 => l_array_source_41(Idx)
205813  );
205814 If(l_balance_type_code = 'A') THEN
205815   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205816 END IF;
205817 
205818 --
205819 
205820 
205821 --
205822 AcctLineType_273 (
205823  p_application_id  => p_application_id
205824  ,p_event_id     => l_event_id
205825  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205826  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205827  ,p_actual_flag => l_actual_flag
205828  ,p_balance_type_code => l_balance_type_code
205829  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205830  
205831  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205832  , p_source_3 => l_array_source_3(Idx)
205833  , p_source_23 => g_array_event(l_event_id).array_value_char('source_23')
205834  , p_source_29 => l_array_source_29(Idx)
205835  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205836  , p_source_35 => l_array_source_35(Idx)
205837  , p_source_36 => l_array_source_36(Idx)
205838  , p_source_37 => l_array_source_37(Idx)
205839  , p_source_38 => l_array_source_38(Idx)
205840  , p_source_39 => l_array_source_39(Idx)
205841  , p_source_40 => l_array_source_40(Idx)
205842  );
205843 If(l_balance_type_code = 'A') THEN
205844   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205845 END IF;
205846 
205847 --
205848 
205849 
205850 --
205851 AcctLineType_275 (
205852  p_application_id  => p_application_id
205853  ,p_event_id     => l_event_id
205854  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205855  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205856  ,p_actual_flag => l_actual_flag
205857  ,p_balance_type_code => l_balance_type_code
205858  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205859  
205860  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205864  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205861  , p_source_3 => l_array_source_3(Idx)
205862  , p_source_24 => g_array_event(l_event_id).array_value_char('source_24')
205863  , p_source_29 => l_array_source_29(Idx)
205865  , p_source_35 => l_array_source_35(Idx)
205866  , p_source_36 => l_array_source_36(Idx)
205867  , p_source_37 => l_array_source_37(Idx)
205868  , p_source_38 => l_array_source_38(Idx)
205869  , p_source_39 => l_array_source_39(Idx)
205870  , p_source_40 => l_array_source_40(Idx)
205871  , p_source_41 => l_array_source_41(Idx)
205872  );
205873 If(l_balance_type_code = 'A') THEN
205874   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205875 END IF;
205876 
205877 --
205878 
205879 
205880 --
205881 AcctLineType_277 (
205882  p_application_id  => p_application_id
205883  ,p_event_id     => l_event_id
205884  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205885  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205886  ,p_actual_flag => l_actual_flag
205887  ,p_balance_type_code => l_balance_type_code
205888  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205889  
205890  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205891  , p_source_3 => l_array_source_3(Idx)
205892  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
205893  , p_source_29 => l_array_source_29(Idx)
205894  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205895  , p_source_35 => l_array_source_35(Idx)
205896  , p_source_36 => l_array_source_36(Idx)
205897  , p_source_37 => l_array_source_37(Idx)
205898  , p_source_38 => l_array_source_38(Idx)
205899  , p_source_39 => l_array_source_39(Idx)
205900  , p_source_40 => l_array_source_40(Idx)
205901  , p_source_41 => l_array_source_41(Idx)
205902  );
205903 If(l_balance_type_code = 'A') THEN
205904   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205905 END IF;
205906 
205907 --
205908 
205909 
205910 --
205911 AcctLineType_295 (
205912  p_application_id  => p_application_id
205913  ,p_event_id     => l_event_id
205914  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205915  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205916  ,p_actual_flag => l_actual_flag
205917  ,p_balance_type_code => l_balance_type_code
205918  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205919  
205920  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205921  , p_source_2 => l_array_source_2(Idx)
205922  , p_source_3 => l_array_source_3(Idx)
205923  , p_source_29 => l_array_source_29(Idx)
205924  , p_source_35 => l_array_source_35(Idx)
205925  , p_source_36 => l_array_source_36(Idx)
205926  , p_source_37 => l_array_source_37(Idx)
205927  , p_source_38 => l_array_source_38(Idx)
205928  , p_source_39 => l_array_source_39(Idx)
205929  , p_source_40 => l_array_source_40(Idx)
205930  );
205931 If(l_balance_type_code = 'A') THEN
205932   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205933 END IF;
205934 
205935 --
205936 
205937 
205938 --
205939 AcctLineType_298 (
205940  p_application_id  => p_application_id
205941  ,p_event_id     => l_event_id
205942  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205943  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205944  ,p_actual_flag => l_actual_flag
205945  ,p_balance_type_code => l_balance_type_code
205946  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205947  
205948  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205949  , p_source_3 => l_array_source_3(Idx)
205950  , p_source_4 => l_array_source_4(Idx)
205951  , p_source_17 => l_array_source_17(Idx)
205952  , p_source_29 => l_array_source_29(Idx)
205953  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205954  , p_source_35 => l_array_source_35(Idx)
205955  , p_source_36 => l_array_source_36(Idx)
205956  , p_source_37 => l_array_source_37(Idx)
205957  , p_source_38 => l_array_source_38(Idx)
205958  , p_source_39 => l_array_source_39(Idx)
205959  , p_source_40 => l_array_source_40(Idx)
205960  );
205961 If(l_balance_type_code = 'A') THEN
205962   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205963 END IF;
205964 
205965 --
205966 
205967 
205968 --
205969 AcctLineType_299 (
205970  p_application_id  => p_application_id
205971  ,p_event_id     => l_event_id
205972  ,p_calculate_acctd_flag => l_calculate_acctd_flag
205973  ,p_calculate_g_l_flag => l_calculate_g_l_flag
205974  ,p_actual_flag => l_actual_flag
205975  ,p_balance_type_code => l_balance_type_code
205976  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
205977  
205978  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
205979  , p_source_3 => l_array_source_3(Idx)
205980  , p_source_9 => l_array_source_9(Idx)
205981  , p_source_29 => l_array_source_29(Idx)
205982  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
205983  , p_source_35 => l_array_source_35(Idx)
205984  , p_source_36 => l_array_source_36(Idx)
205985  , p_source_37 => l_array_source_37(Idx)
205986  , p_source_38 => l_array_source_38(Idx)
205987  , p_source_39 => l_array_source_39(Idx)
205988  , p_source_40 => l_array_source_40(Idx)
205989  );
205990 If(l_balance_type_code = 'A') THEN
205991   l_actual_gain_loss_ref := l_gain_or_loss_ref;
205992 END IF;
205993 
205994 --
205995 
205996 
205997 --
205998 AcctLineType_302 (
205999  p_application_id  => p_application_id
206000  ,p_event_id     => l_event_id
206001  ,p_calculate_acctd_flag => l_calculate_acctd_flag
206002  ,p_calculate_g_l_flag => l_calculate_g_l_flag
206003  ,p_actual_flag => l_actual_flag
206004  ,p_balance_type_code => l_balance_type_code
206005  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
206006  
206007  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
206008  , p_source_3 => l_array_source_3(Idx)
206009  , p_source_29 => l_array_source_29(Idx)
206010  , p_source_35 => l_array_source_35(Idx)
206014  , p_source_39 => l_array_source_39(Idx)
206011  , p_source_36 => l_array_source_36(Idx)
206012  , p_source_37 => l_array_source_37(Idx)
206013  , p_source_38 => l_array_source_38(Idx)
206015  , p_source_40 => l_array_source_40(Idx)
206016  );
206017 If(l_balance_type_code = 'A') THEN
206018   l_actual_gain_loss_ref := l_gain_or_loss_ref;
206019 END IF;
206020 
206021 --
206022 
206023 
206024 --
206025 AcctLineType_303 (
206026  p_application_id  => p_application_id
206027  ,p_event_id     => l_event_id
206028  ,p_calculate_acctd_flag => l_calculate_acctd_flag
206029  ,p_calculate_g_l_flag => l_calculate_g_l_flag
206030  ,p_actual_flag => l_actual_flag
206031  ,p_balance_type_code => l_balance_type_code
206032  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
206033  
206034  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
206035  , p_source_3 => l_array_source_3(Idx)
206036  , p_source_10 => l_array_source_10(Idx)
206037  , p_source_17 => l_array_source_17(Idx)
206038  , p_source_29 => l_array_source_29(Idx)
206039  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
206040  , p_source_35 => l_array_source_35(Idx)
206041  , p_source_36 => l_array_source_36(Idx)
206042  , p_source_37 => l_array_source_37(Idx)
206043  , p_source_38 => l_array_source_38(Idx)
206044  , p_source_39 => l_array_source_39(Idx)
206045  , p_source_40 => l_array_source_40(Idx)
206046  );
206047 If(l_balance_type_code = 'A') THEN
206048   l_actual_gain_loss_ref := l_gain_or_loss_ref;
206049 END IF;
206050 
206051 --
206052 
206053 
206054 --
206055 AcctLineType_306 (
206056  p_application_id  => p_application_id
206057  ,p_event_id     => l_event_id
206058  ,p_calculate_acctd_flag => l_calculate_acctd_flag
206059  ,p_calculate_g_l_flag => l_calculate_g_l_flag
206060  ,p_actual_flag => l_actual_flag
206061  ,p_balance_type_code => l_balance_type_code
206062  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
206063  
206064  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
206065  , p_source_3 => l_array_source_3(Idx)
206066  , p_source_10 => l_array_source_10(Idx)
206067  , p_source_17 => l_array_source_17(Idx)
206068  , p_source_29 => l_array_source_29(Idx)
206069  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
206070  , p_source_35 => l_array_source_35(Idx)
206071  , p_source_36 => l_array_source_36(Idx)
206072  , p_source_37 => l_array_source_37(Idx)
206073  , p_source_38 => l_array_source_38(Idx)
206074  , p_source_39 => l_array_source_39(Idx)
206075  , p_source_40 => l_array_source_40(Idx)
206076  );
206077 If(l_balance_type_code = 'A') THEN
206078   l_actual_gain_loss_ref := l_gain_or_loss_ref;
206079 END IF;
206080 
206081 --
206082 
206083 
206084 --
206085 AcctLineType_312 (
206086  p_application_id  => p_application_id
206087  ,p_event_id     => l_event_id
206088  ,p_calculate_acctd_flag => l_calculate_acctd_flag
206089  ,p_calculate_g_l_flag => l_calculate_g_l_flag
206090  ,p_actual_flag => l_actual_flag
206091  ,p_balance_type_code => l_balance_type_code
206092  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
206093  
206094  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
206095  , p_source_3 => l_array_source_3(Idx)
206096  , p_source_11 => l_array_source_11(Idx)
206097  , p_source_17 => l_array_source_17(Idx)
206098  , p_source_29 => l_array_source_29(Idx)
206099  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
206100  , p_source_35 => l_array_source_35(Idx)
206101  , p_source_36 => l_array_source_36(Idx)
206102  , p_source_37 => l_array_source_37(Idx)
206103  , p_source_38 => l_array_source_38(Idx)
206104  , p_source_39 => l_array_source_39(Idx)
206105  , p_source_40 => l_array_source_40(Idx)
206106  );
206107 If(l_balance_type_code = 'A') THEN
206108   l_actual_gain_loss_ref := l_gain_or_loss_ref;
206109 END IF;
206110 
206111 --
206112 
206113 
206114 --
206115 AcctLineType_315 (
206116  p_application_id  => p_application_id
206117  ,p_event_id     => l_event_id
206118  ,p_calculate_acctd_flag => l_calculate_acctd_flag
206119  ,p_calculate_g_l_flag => l_calculate_g_l_flag
206120  ,p_actual_flag => l_actual_flag
206121  ,p_balance_type_code => l_balance_type_code
206122  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
206123  
206124  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
206125  , p_source_3 => l_array_source_3(Idx)
206126  , p_source_27 => g_array_event(l_event_id).array_value_char('source_27')
206127  , p_source_29 => l_array_source_29(Idx)
206128  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
206129  , p_source_35 => l_array_source_35(Idx)
206130  , p_source_36 => l_array_source_36(Idx)
206131  , p_source_37 => l_array_source_37(Idx)
206132  , p_source_38 => l_array_source_38(Idx)
206133  , p_source_39 => l_array_source_39(Idx)
206134  , p_source_40 => l_array_source_40(Idx)
206135  , p_source_41 => l_array_source_41(Idx)
206136  );
206137 If(l_balance_type_code = 'A') THEN
206138   l_actual_gain_loss_ref := l_gain_or_loss_ref;
206139 END IF;
206140 
206141 --
206142 
206143 
206144 --
206145 AcctLineType_316 (
206146  p_application_id  => p_application_id
206147  ,p_event_id     => l_event_id
206148  ,p_calculate_acctd_flag => l_calculate_acctd_flag
206149  ,p_calculate_g_l_flag => l_calculate_g_l_flag
206150  ,p_actual_flag => l_actual_flag
206151  ,p_balance_type_code => l_balance_type_code
206152  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
206153  
206154  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
206155  , p_source_3 => l_array_source_3(Idx)
206156  , p_source_28 => g_array_event(l_event_id).array_value_char('source_28')
206157  , p_source_29 => l_array_source_29(Idx)
206158  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
206159  , p_source_35 => l_array_source_35(Idx)
206163  , p_source_39 => l_array_source_39(Idx)
206160  , p_source_36 => l_array_source_36(Idx)
206161  , p_source_37 => l_array_source_37(Idx)
206162  , p_source_38 => l_array_source_38(Idx)
206164  , p_source_40 => l_array_source_40(Idx)
206165  , p_source_41 => l_array_source_41(Idx)
206166  );
206167 If(l_balance_type_code = 'A') THEN
206168   l_actual_gain_loss_ref := l_gain_or_loss_ref;
206169 END IF;
206170 
206171 --
206172 
206173       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
206174       -- or secondary ledger that has different currency with primary
206175       -- or alc that is calculated by sla
206176       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
206177             (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'))
206178 
206179 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
206180 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
206181           AND (l_actual_flag = 'A')) THEN
206182         XLA_AE_LINES_PKG.CreateGainOrLossLines(
206183           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
206184          ,p_application_id   => p_application_id
206185          ,p_amb_context_code => 'DEFAULT'
206186          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
206187          ,p_event_class_code => C_EVENT_CLASS_CODE
206188          ,p_event_type_code  => C_EVENT_TYPE_CODE
206189          
206190          ,p_gain_ccid        => -1
206191          ,p_loss_ccid        => -1
206192 
206193          ,p_actual_flag      => l_actual_flag
206194          ,p_enc_flag         => null
206195          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
206196          ,p_enc_g_l_ref      => null
206197          );
206198       END IF;
206199    END IF;
206200 END IF;
206201 
206202    ELSE
206203       --
206204       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
206205       --
206206       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
206207          trace
206208             (p_msg      => 'Trancaction revesal option is Y'
206209             ,p_level    => C_LEVEL_STATEMENT
206210             ,p_module   => l_log_module);
206211       END IF;
206212    END IF;
206213 
206214 END LOOP;
206215 l_result := XLA_AE_LINES_PKG.InsertLines ;
206216 end loop;
206217 close line_cur;
206218 
206219 
206220 --
206221 -- insert headers into xla_ae_headers_gt table
206222 --
206223 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
206224 
206225 -- insert into errors table here.
206226 
206227 END LOOP;
206228 
206229 --
206230 -- 4865292
206231 --
206232 -- Compare g_hdr_extract_count with event count in
206233 -- CreateHeadersAndLines.
206234 --
206235 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
206236 
206237 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
206238    trace (p_msg     => '# rows extracted from header extract objects '
206239                     || ' (running total): '
206240                     || g_hdr_extract_count
206241          ,p_level   => C_LEVEL_STATEMENT
206242          ,p_module  => l_log_module);
206243 END IF;
206244 
206245 CLOSE header_cur;
206246 --
206247 
206248 --
206249 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
206250    trace
206251       (p_msg      => 'END of EventType_425'
206252       ,p_level    => C_LEVEL_PROCEDURE
206253       ,p_module   => l_log_module);
206254 END IF;
206255 --
206256 RETURN l_result;
206257 EXCEPTION
206258 WHEN xla_exceptions_pkg.application_exception THEN
206259    
206260 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
206261 
206262    
206263 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
206264 
206265    RAISE;
206266 
206267 WHEN NO_DATA_FOUND THEN
206268 
206269 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
206270 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
206271 
206272 FOR header_record IN header_cur
206273 LOOP
206274     l_array_header_events(header_record.event_id) := header_record.event_id;
206275 END LOOP;
206276 
206277 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
206278 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
206279 
206280 fnd_file.put_line(fnd_file.LOG, '                    ');
206281 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
206282 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
206283 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
206284 
206285 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
206286 LOOP
206287 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
206288 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
206289         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
206290 	END IF;
206291 END LOOP;
206292 
206293 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
206294 fnd_file.put_line(fnd_file.LOG, '                    ');
206295 
206296 
206297 xla_exceptions_pkg.raise_message
206298       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_425');
206299 
206300 
206301 WHEN OTHERS THEN
206302    xla_exceptions_pkg.raise_message
206303       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_425');
206304 END EventType_425;
206305 --
206306 
206307 ---------------------------------------
206308 --
206309 -- PRIVATE PROCEDURE
206310 --         insert_sources_426
206311 --
206315                                 p_target_ledger_id       IN NUMBER
206312 ----------------------------------------
206313 --
206314 PROCEDURE insert_sources_426(
206316                               , p_language               IN VARCHAR2
206317                               , p_sla_ledger_id          IN NUMBER
206318                               , p_pad_start_date         IN DATE
206319                               , p_pad_end_date           IN DATE
206320                          )
206321 IS
206322 
206323 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RETIREMENT_ADJUSTMENTS_ALL';
206324 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'RETIREMENT_ADJUSTMENTS';
206325 p_apps_owner                   VARCHAR2(30);
206326 l_log_module                   VARCHAR2(240);
206327 BEGIN
206328 IF g_log_enabled THEN
206329       l_log_module := C_DEFAULT_MODULE||'.insert_sources_426';
206330 END IF;
206331 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
206332 
206333       trace
206334          (p_msg      => 'BEGIN of insert_sources_426'
206335          ,p_level    => C_LEVEL_PROCEDURE
206336          ,p_module   => l_log_module);
206337 
206338 END IF;
206339 
206340 -- select APPS owner
206341 SELECT oracle_username
206342   INTO p_apps_owner
206343   FROM fnd_oracle_userid
206344  WHERE read_only_flag = 'U'
206345 ;
206346 
206347 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
206348       trace
206349          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
206350                         ' - p_language = '||p_language||
206351                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
206352                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
206353                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
206354                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
206355          ,p_level    => C_LEVEL_STATEMENT
206356          ,p_module   => l_log_module);
206357 END IF;
206358 
206359 
206360 --
206361 INSERT INTO xla_diag_sources --hdr2
206362 (
206363         event_id
206364       , ledger_id
206365       , sla_ledger_id
206366       , description_language
206367       , object_name
206368       , object_type_code
206369       , line_number
206370       , source_application_id
206371       , source_type_code
206372       , source_code
206373       , source_value
206374       , source_meaning
206375       , created_by
206376       , creation_date
206377       , last_update_date
206378       , last_updated_by
206379       , last_update_login
206380       , program_update_date
206381       , program_application_id
206382       , program_id
206383       , request_id
206384 )
206385 SELECT
206386         event_id
206387       , p_target_ledger_id
206388       , p_sla_ledger_id
206389       , p_language
206390       , object_name
206391       , object_type_code
206392       , line_number
206393       , source_application_id
206394       , source_type_code
206395       , source_code
206396       , SUBSTR(source_value ,1,1996)
206397       , SUBSTR(source_meaning ,1,200)
206398       , xla_environment_pkg.g_Usr_Id
206399       , TRUNC(SYSDATE)
206400       , TRUNC(SYSDATE)
206401       , xla_environment_pkg.g_Usr_Id
206402       , xla_environment_pkg.g_Login_Id
206403       , TRUNC(SYSDATE)
206404       , xla_environment_pkg.g_Prog_Appl_Id
206405       , xla_environment_pkg.g_Prog_Id
206406       , xla_environment_pkg.g_Req_Id
206407   FROM (
206408        SELECT xet.event_id                  event_id
206409             , 0                          line_number
206410             , CASE r
206411                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
206412                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
206413                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
206414                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
206415                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
206416                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
206417                 
206418                ELSE null
206419               END                           object_name
206420             , CASE r
206421                 WHEN 1 THEN 'HEADER' 
206422                 WHEN 2 THEN 'HEADER' 
206423                 WHEN 3 THEN 'HEADER' 
206424                 WHEN 4 THEN 'HEADER' 
206425                 WHEN 5 THEN 'HEADER' 
206426                 WHEN 6 THEN 'HEADER' 
206427                 
206428                 ELSE null
206429               END                           object_type_code
206430             , CASE r
206431                 WHEN 1 THEN '140' 
206432                 WHEN 2 THEN '140' 
206433                 WHEN 3 THEN '140' 
206434                 WHEN 4 THEN '140' 
206435                 WHEN 5 THEN '140' 
206436                 WHEN 6 THEN '140' 
206437                 
206438                 ELSE null
206439               END                           source_application_id
206440             , 'S'             source_type_code
206441             , CASE r
206442                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
206443                 WHEN 2 THEN 'COST_OF_REMOVAL_CLEARING_ACCT' 
206444                 WHEN 3 THEN 'PROCEEDS_OF_SALE_CLEARING_ACCT' 
206445                 WHEN 4 THEN 'DEFAULT_CCID' 
206446                 WHEN 5 THEN 'ACCOUNTING_DATE' 
206447                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
206448                 
206449                 ELSE null
206450               END                           source_code
206451             , CASE r
206452                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
206453                 WHEN 2 THEN TO_CHAR(h1.COST_OF_REMOVAL_CLEARING_ACCT)
206454                 WHEN 3 THEN TO_CHAR(h1.PROCEEDS_OF_SALE_CLEARING_ACCT)
206455                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
206456                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
206457                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
206458                 
206462          FROM xla_events_gt     xet  
206459                 ELSE null
206460               END                           source_value
206461             , null              source_meaning
206463       , FA_XLA_EXT_HEADERS_B_GT  h1
206464              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
206465          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
206466            AND xet.event_class_code = C_EVENT_CLASS_CODE
206467               AND h1.event_id = xet.event_id
206468 
206469 )
206470 ;
206471 --
206472 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
206473 
206474       trace
206475          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
206476          ,p_level    => C_LEVEL_STATEMENT
206477          ,p_module   => l_log_module);
206478 
206479 END IF;
206480 --
206481 
206482 
206483 
206484 --
206485 INSERT INTO xla_diag_sources  --line2
206486 (
206487         event_id
206488       , ledger_id
206489       , sla_ledger_id
206490       , description_language
206491       , object_name
206492       , object_type_code
206493       , line_number
206494       , source_application_id
206495       , source_type_code
206496       , source_code
206497       , source_value
206498       , source_meaning
206499       , created_by
206500       , creation_date
206501       , last_update_date
206502       , last_updated_by
206503       , last_update_login
206504       , program_update_date
206505       , program_application_id
206506       , program_id
206507       , request_id
206508 )
206509 SELECT  event_id
206510       , p_target_ledger_id
206511       , p_sla_ledger_id
206512       , p_language
206513       , object_name
206514       , object_type_code
206515       , line_number
206516       , source_application_id
206517       , source_type_code
206518       , source_code
206519       , SUBSTR(source_value,1,1996)
206520       , SUBSTR(source_meaning ,1,200)
206521       , xla_environment_pkg.g_Usr_Id
206522       , TRUNC(SYSDATE)
206523       , TRUNC(SYSDATE)
206524       , xla_environment_pkg.g_Usr_Id
206525       , xla_environment_pkg.g_Login_Id
206526       , TRUNC(SYSDATE)
206527       , xla_environment_pkg.g_Prog_Appl_Id
206528       , xla_environment_pkg.g_Prog_Id
206529       , xla_environment_pkg.g_Req_Id
206530   FROM (
206531        SELECT xet.event_id                  event_id
206532             , l2.line_number                 line_number
206533             , CASE r
206534                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
206535                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
206536                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
206537                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
206538                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
206539                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
206540                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
206541                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
206542                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
206543                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
206544                 
206545                ELSE null
206546               END                           object_name
206547             , CASE r
206548                 WHEN 1 THEN 'LINE' 
206549                 WHEN 2 THEN 'LINE' 
206550                 WHEN 3 THEN 'LINE' 
206551                 WHEN 4 THEN 'LINE' 
206552                 WHEN 5 THEN 'LINE' 
206553                 WHEN 6 THEN 'LINE' 
206554                 WHEN 7 THEN 'LINE' 
206555                 WHEN 8 THEN 'LINE' 
206556                 WHEN 9 THEN 'LINE' 
206557                 WHEN 10 THEN 'LINE' 
206558                 
206559                 ELSE null
206560               END                           object_type_code
206561             , CASE r
206562                 WHEN 1 THEN '140' 
206563                 WHEN 2 THEN '140' 
206564                 WHEN 3 THEN '140' 
206565                 WHEN 4 THEN '140' 
206566                 WHEN 5 THEN '140' 
206567                 WHEN 6 THEN '140' 
206568                 WHEN 7 THEN '140' 
206569                 WHEN 8 THEN '140' 
206570                 WHEN 9 THEN '140' 
206571                 WHEN 10 THEN '140' 
206572                 
206573                 ELSE null
206574               END                           source_application_id
206575             , 'S'             source_type_code
206576             , CASE r
206577                 WHEN 1 THEN 'GENERATED_CCID' 
206578                 WHEN 2 THEN 'DEPRN_RESERVE_ACCT' 
206579                 WHEN 3 THEN 'GENERATED_OFFSET_CCID' 
206580                 WHEN 4 THEN 'EXPENSE_ACCOUNT_CCID' 
206581                 WHEN 5 THEN 'ADJUSTMENT_TYPE' 
206582                 WHEN 6 THEN 'TRANSACTION_HEADER_ID' 
206583                 WHEN 7 THEN 'ADJUSTMENT_LINE_ID' 
206584                 WHEN 8 THEN 'DISTRIBUTION_TYPE_CODE' 
206585                 WHEN 9 THEN 'ENTERED_AMOUNT' 
206586                 WHEN 10 THEN 'CURRENCY_CODE' 
206587                 
206588                 ELSE null
206589               END                           source_code
206590             , CASE r
206591                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
206592                 WHEN 2 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
206593                 WHEN 3 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
206594                 WHEN 4 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
206595                 WHEN 5 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
206596                 WHEN 6 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
206597                 WHEN 7 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
206598                 WHEN 8 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
206599                 WHEN 9 THEN TO_CHAR(l2.ENTERED_AMOUNT)
206600                 WHEN 10 THEN TO_CHAR(l2.CURRENCY_CODE)
206601                 
206602                 ELSE null
206603               END                           source_value
206607             , (select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
206604             , null              source_meaning
206605          FROM  xla_events_gt     xet  
206606         , FA_XLA_EXT_LINES_B_GT  l2
206608         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
206609           AND xet.event_class_code = C_EVENT_CLASS_CODE
206610             AND l2.event_id          = xet.event_id
206611   AND l2.ledger_id (+)  = p_sla_ledger_id
206612 
206613 )
206614 ;
206615 --
206616 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
206617 
206618       trace
206619          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
206620          ,p_level    => C_LEVEL_STATEMENT
206621          ,p_module   => l_log_module);
206622 
206623 END IF;
206624 
206625 
206626 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
206627       trace
206628          (p_msg      => 'END of insert_sources_426'
206629          ,p_level    => C_LEVEL_PROCEDURE
206630          ,p_module   => l_log_module);
206631 END IF;
206632 EXCEPTION
206633   WHEN xla_exceptions_pkg.application_exception THEN
206634       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
206635             trace
206636                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
206637                ,p_level    => C_LEVEL_EXCEPTION
206638                ,p_module   => l_log_module);
206639       END IF;
206640       RAISE;
206641   WHEN OTHERS THEN
206642       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
206643             trace
206644                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
206645                ,p_level    => C_LEVEL_EXCEPTION
206646                ,p_module   => l_log_module);
206647        END IF;
206648        xla_exceptions_pkg.raise_message
206649            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_426');
206650 END insert_sources_426;
206651 --
206652 
206653 ---------------------------------------
206654 --
206655 -- PRIVATE FUNCTION
206656 --         EventClass_426
206657 --
206658 ----------------------------------------
206659 --
206660 FUNCTION EventClass_426
206661        (p_application_id         IN NUMBER
206662        ,p_base_ledger_id         IN NUMBER
206663        ,p_target_ledger_id       IN NUMBER
206664        ,p_language               IN VARCHAR2
206665        ,p_currency_code          IN VARCHAR2
206666        ,p_sla_ledger_id          IN NUMBER
206667        ,p_pad_start_date         IN DATE
206668        ,p_pad_end_date           IN DATE
206669        ,p_primary_ledger_id      IN NUMBER)
206670 RETURN BOOLEAN IS
206671 --
206672 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RETIREMENT_ADJUSTMENTS_ALL';
206673 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'RETIREMENT_ADJUSTMENTS';
206674 
206675 l_calculate_acctd_flag   VARCHAR2(1) :='N';
206676 l_calculate_g_l_flag     VARCHAR2(1) :='N';
206677 --
206678 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
206679 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
206680 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
206681 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
206682 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
206683 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
206684 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
206685 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
206686 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
206687 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
206688 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
206689 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
206690 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
206691 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
206692 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
206693 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
206694 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
206695 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
206696 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
206697 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
206698 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
206699 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
206700 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
206701 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
206702 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
206703 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
206704 
206705 l_event_id                             NUMBER;
206706 l_previous_event_id                    NUMBER;
206707 l_first_event_id                       NUMBER;
206708 l_last_event_id                        NUMBER;
206709 
206710 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
206711 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
206712 --
206713 --
206714 l_result                    BOOLEAN := TRUE;
206715 l_rows                      NUMBER  := 1000;
206716 l_event_type_name           VARCHAR2(80) := 'All';
206717 l_event_class_name          VARCHAR2(80) := 'Retirement Adjustments';
206718 l_description               VARCHAR2(4000);
206719 l_transaction_reversal      NUMBER;
206720 l_ae_header_id              NUMBER;
206721 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
206722 l_log_module                VARCHAR2(240);
206723 --
206724 l_acct_reversal_source      VARCHAR2(30);
206725 l_trx_reversal_source       VARCHAR2(30);
206726 
206730 --
206727 l_continue_with_lines       BOOLEAN := TRUE;
206728 --
206729 l_acc_rev_gl_date_source    DATE;                      -- 4262811
206731 type t_array_event_id is table of number index by binary_integer;
206732 
206733 l_rec_array_event                    t_rec_array_event;
206734 l_null_rec_array_event               t_rec_array_event;
206735 l_array_ae_header_id                 xla_number_array_type;
206736 l_actual_flag                        VARCHAR2(1) := NULL;
206737 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
206738 l_balance_type_code                  VARCHAR2(1) :=NULL;
206739 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
206740 
206741 --
206742 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
206743 --
206744 
206745 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
206746 TYPE t_array_source_12 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.COST_OF_REMOVAL_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
206747 TYPE t_array_source_23 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PROCEEDS_OF_SALE_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
206748 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
206749 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
206750 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
206751 
206752 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
206753 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
206754 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
206755 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
206756 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
206757 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
206758 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
206759 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
206760 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
206761 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
206762 
206763 l_array_source_1              t_array_source_1;
206764 l_array_source_12              t_array_source_12;
206765 l_array_source_23              t_array_source_23;
206766 l_array_source_30              t_array_source_30;
206767 l_array_source_51              t_array_source_51;
206768 l_array_source_52              t_array_source_52;
206769 
206770 l_array_source_3      t_array_source_3;
206771 l_array_source_10      t_array_source_10;
206772 l_array_source_17      t_array_source_17;
206773 l_array_source_29      t_array_source_29;
206774 l_array_source_35      t_array_source_35;
206775 l_array_source_36      t_array_source_36;
206776 l_array_source_37      t_array_source_37;
206777 l_array_source_38      t_array_source_38;
206778 l_array_source_39      t_array_source_39;
206779 l_array_source_40      t_array_source_40;
206780 
206781 --
206782 CURSOR header_cur
206783 IS
206784 SELECT /*+ leading(xet) cardinality(xet,1) */
206785 -- Event Class Code: RETIREMENT_ADJUSTMENTS
206786     xet.entity_id
206787    ,xet.legal_entity_id
206788    ,xet.entity_code
206789    ,xet.transaction_number
206790    ,xet.event_id
206791    ,xet.event_class_code
206792    ,xet.event_type_code
206793    ,xet.event_number
206794    ,xet.event_date
206795    ,xet.transaction_date
206796    ,xet.reference_num_1
206797    ,xet.reference_num_2
206798    ,xet.reference_num_3
206799    ,xet.reference_num_4
206800    ,xet.reference_char_1
206801    ,xet.reference_char_2
206802    ,xet.reference_char_3
206803    ,xet.reference_char_4
206804    ,xet.reference_date_1
206805    ,xet.reference_date_2
206806    ,xet.reference_date_3
206807    ,xet.reference_date_4
206808    ,xet.event_created_by
206809    ,xet.budgetary_control_flag 
206810   , h1.PERIOD_CLOSE_DATE    source_1
206811   , h1.COST_OF_REMOVAL_CLEARING_ACCT    source_12
206812   , h1.PROCEEDS_OF_SALE_CLEARING_ACCT    source_23
206813   , h1.DEFAULT_CCID    source_30
206814   , h1.ACCOUNTING_DATE    source_51
206815   , h1.TRANSFER_TO_GL_FLAG    source_52
206816   FROM xla_events_gt     xet 
206817   , FA_XLA_EXT_HEADERS_B_GT  h1
206818  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
206819    and xet.event_class_code = C_EVENT_CLASS_CODE
206820    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
206821 
206822  ORDER BY event_id
206823 ;
206824 
206825 
206826 --
206827 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
206828 IS
206829 SELECT  /*+ leading(xet) cardinality(xet,1) */
206830 -- Event Class Code: RETIREMENT_ADJUSTMENTS
206831     xet.entity_id
206832    ,xet.legal_entity_id
206833    ,xet.entity_code
206834    ,xet.transaction_number
206835    ,xet.event_id
206836    ,xet.event_class_code
206837    ,xet.event_type_code
206838    ,xet.event_number
206839    ,xet.event_date
206840    ,xet.transaction_date
206841    ,xet.reference_num_1
206842    ,xet.reference_num_2
206843    ,xet.reference_num_3
206844    ,xet.reference_num_4
206845    ,xet.reference_char_1
206846    ,xet.reference_char_2
206847    ,xet.reference_char_3
206848    ,xet.reference_char_4
206849    ,xet.reference_date_1
206850    ,xet.reference_date_2
206851    ,xet.reference_date_3
206852    ,xet.reference_date_4
206853    ,xet.event_created_by
206854    ,xet.budgetary_control_flag
206855  , l2.LINE_NUMBER  
206856   , l2.GENERATED_CCID    source_3
206857   , l2.DEPRN_RESERVE_ACCT    source_10
206861   , l2.TRANSACTION_HEADER_ID    source_36
206858   , l2.GENERATED_OFFSET_CCID    source_17
206859   , l2.EXPENSE_ACCOUNT_CCID    source_29
206860   , l2.ADJUSTMENT_TYPE    source_35
206862   , l2.ADJUSTMENT_LINE_ID    source_37
206863   , l2.DISTRIBUTION_TYPE_CODE    source_38
206864   , l2.ENTERED_AMOUNT    source_39
206865   , l2.CURRENCY_CODE    source_40
206866   FROM xla_events_gt     xet 
206867   , FA_XLA_EXT_LINES_B_GT  l2
206868  WHERE xet.event_id between x_first_event_id and x_last_event_id
206869    and xet.event_date between p_pad_start_date and p_pad_end_date
206870    and xet.event_class_code = C_EVENT_CLASS_CODE
206871    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
206872   AND l2.ledger_id = p_sla_ledger_id
206873 ;
206874 
206875 --
206876 BEGIN
206877 IF g_log_enabled THEN
206878    l_log_module := C_DEFAULT_MODULE||'.EventClass_426';
206879 END IF;
206880 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
206881    trace
206882       (p_msg      => 'BEGIN of EventClass_426'
206883       ,p_level    => C_LEVEL_PROCEDURE
206884       ,p_module   => l_log_module);
206885 END IF;
206886 
206887 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
206888    trace
206889       (p_msg      => 'p_application_id = '||p_application_id||
206890                      ' - p_base_ledger_id = '||p_base_ledger_id||
206891                      ' - p_target_ledger_id  = '||p_target_ledger_id||
206892                      ' - p_language = '||p_language||
206893                      ' - p_currency_code = '||p_currency_code||
206894                      ' - p_sla_ledger_id = '||p_sla_ledger_id
206895       ,p_level    => C_LEVEL_STATEMENT
206896       ,p_module   => l_log_module);
206897 END IF;
206898 --
206899 -- initialze arrays
206900 --
206901 g_array_event.DELETE;
206902 l_rec_array_event := l_null_rec_array_event;
206903 --
206904 --------------------------------------
206905 -- 4262811 Initialze MPA Line Number
206906 --------------------------------------
206907 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
206908 
206909 --
206910 
206911 --
206912 OPEN header_cur;
206913 --
206914 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
206915    trace
206916    (p_msg      => 'SQL - FETCH header_cur'
206917    ,p_level    => C_LEVEL_STATEMENT
206918    ,p_module   => l_log_module);
206919 END IF;
206920 --
206921 LOOP
206922 FETCH header_cur BULK COLLECT INTO
206923         l_array_entity_id
206924       , l_array_legal_entity_id
206925       , l_array_entity_code
206926       , l_array_transaction_num
206927       , l_array_event_id
206928       , l_array_class_code
206929       , l_array_event_type
206930       , l_array_event_number
206931       , l_array_event_date
206932       , l_array_transaction_date
206933       , l_array_reference_num_1
206934       , l_array_reference_num_2
206935       , l_array_reference_num_3
206936       , l_array_reference_num_4
206937       , l_array_reference_char_1
206938       , l_array_reference_char_2
206939       , l_array_reference_char_3
206940       , l_array_reference_char_4
206941       , l_array_reference_date_1
206942       , l_array_reference_date_2
206943       , l_array_reference_date_3
206944       , l_array_reference_date_4
206945       , l_array_event_created_by
206946       , l_array_budgetary_control_flag 
206947       , l_array_source_1
206948       , l_array_source_12
206949       , l_array_source_23
206950       , l_array_source_30
206951       , l_array_source_51
206952       , l_array_source_52
206953       LIMIT l_rows;
206954 --
206955 IF (C_LEVEL_EVENT >= g_log_level) THEN
206956    trace
206957    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
206958    ,p_level    => C_LEVEL_EVENT
206959    ,p_module   => l_log_module);
206960 END IF;
206961 --
206962 EXIT WHEN l_array_entity_id.COUNT = 0;
206963 
206964 -- initialize arrays
206965 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
206966 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
206967 
206968 --
206969 -- Bug 4458708
206970 --
206971 XLA_AE_LINES_PKG.g_LineNumber := 0;
206972 
206973 
206974 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
206975 g_last_hdr_idx := l_array_event_id.LAST;
206976 --
206977 -- loop for the headers. Each iteration is for each header extract row
206978 -- fetched in header cursor
206979 --
206980 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
206981 
206982 --
206983 -- set event info as cache for other routines to refer event attributes
206984 --
206985 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
206986    (p_application_id           => p_application_id
206987    ,p_primary_ledger_id        => p_primary_ledger_id
206988    ,p_base_ledger_id           => p_base_ledger_id
206989    ,p_target_ledger_id         => p_target_ledger_id
206990    ,p_entity_id                => l_array_entity_id(hdr_idx)
206991    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
206992    ,p_entity_code              => l_array_entity_code(hdr_idx)
206993    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
206994    ,p_event_id                 => l_array_event_id(hdr_idx)
206995    ,p_event_class_code         => l_array_class_code(hdr_idx)
206996    ,p_event_type_code          => l_array_event_type(hdr_idx)
206997    ,p_event_number             => l_array_event_number(hdr_idx)
206998    ,p_event_date               => l_array_event_date(hdr_idx)
206999    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
207000    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
207001    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
207002    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
207003    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
207007    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
207004    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
207005    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
207006    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
207008    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
207009    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
207010    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
207011    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
207012    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
207013    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
207014 
207015 --
207016 -- set the status of entry to C_VALID (0)
207017 --
207018 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
207019 
207020 --
207021 -- initialize a row for ae header
207022 --
207023 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
207024 
207025 l_event_id := l_array_event_id(hdr_idx);
207026 
207027 --
207028 -- storing the hdr_idx for event. May be used by line cursor.
207029 --
207030 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
207031 
207032 --
207033 -- store sources from header extract. This can be improved to
207034 -- store only those sources from header extract that may be used in lines
207035 --
207036 
207037 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
207038 g_array_event(l_event_id).array_value_char('source_12') := l_array_source_12(hdr_idx);
207039 g_array_event(l_event_id).array_value_char('source_23') := l_array_source_23(hdr_idx);
207040 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
207041 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
207042 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
207043 
207044 --
207045 -- initilaize the status of ae headers for diffrent balance types
207046 -- the status is initialised to C_NOT_CREATED (2)
207047 --
207048 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
207049 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
207050 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
207051 
207052 --
207053 -- call api to validate and store accounting attributes for header
207054 --
207055 
207056 ------------------------------------------------------------
207057 -- Accrual Reversal : to get date for Standard Source (NONE)
207058 ------------------------------------------------------------
207059 l_acc_rev_gl_date_source := NULL;
207060 
207061      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
207062       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
207063      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
207064       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
207065 
207066 
207067 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
207068 
207069 XLA_AE_HEADER_PKG.SetJeCategoryName;
207070 
207071 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
207072 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
207073 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
207074 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
207075 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
207076 
207077 
207078 --
207079 xla_ae_header_pkg.SetHdrDescription(
207080    p_description => Description_84 (
207081    p_application_id => p_application_id 
207082  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
207083    )
207084 );
207085 --
207086 
207087 -- No header level analytical criteria
207088 
207089 --
207090 --accounting attribute enhancement, bug 3612931
207091 --
207092 l_trx_reversal_source := SUBSTR(NULL, 1,30);
207093 
207094 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
207095    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
207096 
207097    xla_accounting_err_pkg.build_message
207098       (p_appli_s_name            => 'XLA'
207099       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
207100       ,p_token_1                 => 'ACCT_ATTR_NAME'
207101       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
207102       ,p_token_2                 => 'PRODUCT_NAME'
207103       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
207104       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
207105       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
207106       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
207107 
207108 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
207109    --
207110    -- following sets the accounting attributes needed to reverse
207111    -- accounting for a distributeion
207112    --
207113    xla_ae_lines_pkg.SetTrxReversalAttrs
207114       (p_event_id              => l_event_id
207115       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
207116       ,p_trx_reversal_source   => l_trx_reversal_source);
207117 
207118 END IF;
207119 
207120 
207121 ----------------------------------------------------------------
207122 -- 4262811 -  update the header statuses to invalid in need be
207123 ----------------------------------------------------------------
207124 --
207125 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
207126 
207127 
207131 ----------------------------------------------------------------
207128   -----------------------------------------------
207129   -- No accrual reversal for the event class/type
207130   -----------------------------------------------
207132 
207133 --
207134 -- this ends the header loop iteration for one bulk fetch
207135 --
207136 END LOOP;
207137 
207138 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
207139 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
207140 
207141 --
207142 -- insert dummy rows into lines gt table that were created due to
207143 -- transaction reversals
207144 --
207145 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
207146    l_result := XLA_AE_LINES_PKG.InsertLines;
207147 END IF;
207148 
207149 --
207150 -- reset the temp_line_num for each set of events fetched from header
207151 -- cursor rather than doing it for each new event in line cursor
207152 -- Bug 3939231
207153 --
207154 xla_ae_lines_pkg.g_temp_line_num := 0;
207155 
207156 
207157 
207158 --
207159 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
207160 --
207161 --
207162 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
207163 
207164       trace
207165          (p_msg      => 'SQL - FETCH line_cur'
207166          ,p_level    => C_LEVEL_STATEMENT
207167          ,p_module   => l_log_module);
207168 
207169 END IF;
207170 --
207171 --
207172 LOOP
207173   --
207174   FETCH line_cur BULK COLLECT INTO
207175         l_array_entity_id
207176       , l_array_legal_entity_id
207177       , l_array_entity_code
207178       , l_array_transaction_num
207179       , l_array_event_id
207180       , l_array_class_code
207181       , l_array_event_type
207182       , l_array_event_number
207183       , l_array_event_date
207184       , l_array_transaction_date
207185       , l_array_reference_num_1
207186       , l_array_reference_num_2
207187       , l_array_reference_num_3
207188       , l_array_reference_num_4
207189       , l_array_reference_char_1
207190       , l_array_reference_char_2
207191       , l_array_reference_char_3
207192       , l_array_reference_char_4
207193       , l_array_reference_date_1
207194       , l_array_reference_date_2
207195       , l_array_reference_date_3
207196       , l_array_reference_date_4
207197       , l_array_event_created_by
207198       , l_array_budgetary_control_flag
207199       , l_array_extract_line_num 
207200       , l_array_source_3
207201       , l_array_source_10
207202       , l_array_source_17
207203       , l_array_source_29
207204       , l_array_source_35
207205       , l_array_source_36
207206       , l_array_source_37
207207       , l_array_source_38
207208       , l_array_source_39
207209       , l_array_source_40
207210       LIMIT l_rows;
207211 
207212   --
207213   IF (C_LEVEL_EVENT >= g_log_level) THEN
207214             trace
207215                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
207216                ,p_level    => C_LEVEL_EVENT
207217                ,p_module   => l_log_module);
207218   END IF;
207219   --
207220   EXIT WHEN l_array_entity_id.count = 0;
207221 
207222   XLA_AE_LINES_PKG.g_rec_lines := null;
207223 
207224 --
207225 -- Bug 4458708
207226 --
207227 XLA_AE_LINES_PKG.g_LineNumber := 0;
207228 --
207229 --
207230 
207231 FOR Idx IN 1..l_array_event_id.count LOOP
207232    --
207233    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
207234    --
207235    l_event_id := l_array_event_id(idx);  -- 5648433
207236 
207237    --
207238    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
207239    --
207240 
207241    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
207242              (g_array_event(l_event_id).array_value_num('header_index'))
207243          ,'N'
207244          ) <> 'Y'
207245    THEN
207246       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
207247          trace
207248             (p_msg      => 'Trancaction revesal option is not Y '
207249             ,p_level    => C_LEVEL_STATEMENT
207250             ,p_module   => l_log_module);
207251       END IF;
207252 
207253 --
207254 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
207255 --
207256 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
207257 --
207258 -- set event info as cache for other routines to refer event attributes
207259 --
207260 
207261 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
207262    l_previous_event_id := l_event_id;
207263 
207264    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
207265       (p_application_id           => p_application_id
207266       ,p_primary_ledger_id        => p_primary_ledger_id
207267       ,p_base_ledger_id           => p_base_ledger_id
207268       ,p_target_ledger_id         => p_target_ledger_id
207269       ,p_entity_id                => l_array_entity_id(Idx)
207270       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
207271       ,p_entity_code              => l_array_entity_code(Idx)
207272       ,p_transaction_num          => l_array_transaction_num(Idx)
207273       ,p_event_id                 => l_array_event_id(Idx)
207274       ,p_event_class_code         => l_array_class_code(Idx)
207275       ,p_event_type_code          => l_array_event_type(Idx)
207276       ,p_event_number             => l_array_event_number(Idx)
207277       ,p_event_date               => l_array_event_date(Idx)
207278       ,p_transaction_date         => l_array_transaction_date(Idx)
207279       ,p_reference_num_1          => l_array_reference_num_1(Idx)
207280       ,p_reference_num_2          => l_array_reference_num_2(Idx)
207281       ,p_reference_num_3          => l_array_reference_num_3(Idx)
207285       ,p_reference_char_3         => l_array_reference_char_3(Idx)
207282       ,p_reference_num_4          => l_array_reference_num_4(Idx)
207283       ,p_reference_char_1         => l_array_reference_char_1(Idx)
207284       ,p_reference_char_2         => l_array_reference_char_2(Idx)
207286       ,p_reference_char_4         => l_array_reference_char_4(Idx)
207287       ,p_reference_date_1         => l_array_reference_date_1(Idx)
207288       ,p_reference_date_2         => l_array_reference_date_2(Idx)
207289       ,p_reference_date_3         => l_array_reference_date_3(Idx)
207290       ,p_reference_date_4         => l_array_reference_date_4(Idx)
207291       ,p_event_created_by         => l_array_event_created_by(Idx)
207292       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
207293        --
207294 END IF;
207295 
207296 
207297 
207298 --
207299 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
207300 
207301 l_acct_reversal_source := SUBSTR(NULL, 1,30);
207302 
207303 IF l_continue_with_lines THEN
207304    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
207305       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
207306 
207307       xla_accounting_err_pkg.build_message
207308          (p_appli_s_name            => 'XLA'
207309          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
207310          ,p_token_1                 => 'LINE_NUMBER'
207311          ,p_value_1                 => l_array_extract_line_num(Idx)
207312          ,p_token_2                 => 'PRODUCT_NAME'
207313          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
207314          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
207315          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
207316          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
207317 
207318    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
207319       --
207320       -- following sets the accounting attributes needed to reverse
207321       -- accounting for a distributeion
207322       --
207323 
207324       --
207325       -- 5217187
207326       --
207327       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
207328       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
207329                                        g_array_event(l_event_id).array_value_num('header_index'));
207330       --
207331       --
207332 
207333       -- No reversal code generated
207334 
207335       xla_ae_lines_pkg.SetAcctReversalAttrs
207336          (p_event_id             => l_event_id
207337          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
207338          ,p_calculate_acctd_flag => l_calculate_acctd_flag
207339          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
207340    END IF;
207341 
207342    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
207343        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
207344 
207345 --
207346 AcctLineType_309 (
207347  p_application_id  => p_application_id
207348  ,p_event_id     => l_event_id
207349  ,p_calculate_acctd_flag => l_calculate_acctd_flag
207350  ,p_calculate_g_l_flag => l_calculate_g_l_flag
207351  ,p_actual_flag => l_actual_flag
207352  ,p_balance_type_code => l_balance_type_code
207353  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
207354  
207355  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
207356  , p_source_3 => l_array_source_3(Idx)
207357  , p_source_12 => g_array_event(l_event_id).array_value_char('source_12')
207358  , p_source_29 => l_array_source_29(Idx)
207359  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
207360  , p_source_35 => l_array_source_35(Idx)
207361  , p_source_36 => l_array_source_36(Idx)
207362  , p_source_37 => l_array_source_37(Idx)
207363  , p_source_38 => l_array_source_38(Idx)
207364  , p_source_39 => l_array_source_39(Idx)
207365  , p_source_40 => l_array_source_40(Idx)
207366  );
207367 If(l_balance_type_code = 'A') THEN
207368   l_actual_gain_loss_ref := l_gain_or_loss_ref;
207369 END IF;
207370 
207371 --
207372 
207373 
207374 --
207375 AcctLineType_310 (
207376  p_application_id  => p_application_id
207377  ,p_event_id     => l_event_id
207378  ,p_calculate_acctd_flag => l_calculate_acctd_flag
207379  ,p_calculate_g_l_flag => l_calculate_g_l_flag
207380  ,p_actual_flag => l_actual_flag
207381  ,p_balance_type_code => l_balance_type_code
207382  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
207383  
207384  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
207385  , p_source_3 => l_array_source_3(Idx)
207386  , p_source_23 => g_array_event(l_event_id).array_value_char('source_23')
207387  , p_source_29 => l_array_source_29(Idx)
207388  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
207389  , p_source_35 => l_array_source_35(Idx)
207390  , p_source_36 => l_array_source_36(Idx)
207391  , p_source_37 => l_array_source_37(Idx)
207392  , p_source_38 => l_array_source_38(Idx)
207393  , p_source_39 => l_array_source_39(Idx)
207394  , p_source_40 => l_array_source_40(Idx)
207395  );
207396 If(l_balance_type_code = 'A') THEN
207397   l_actual_gain_loss_ref := l_gain_or_loss_ref;
207398 END IF;
207399 
207400 --
207401 
207402 
207403 --
207404 AcctLineType_311 (
207405  p_application_id  => p_application_id
207406  ,p_event_id     => l_event_id
207407  ,p_calculate_acctd_flag => l_calculate_acctd_flag
207408  ,p_calculate_g_l_flag => l_calculate_g_l_flag
207409  ,p_actual_flag => l_actual_flag
207410  ,p_balance_type_code => l_balance_type_code
207411  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
207412  
207413  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
207414  , p_source_3 => l_array_source_3(Idx)
207415  , p_source_10 => l_array_source_10(Idx)
207419  , p_source_35 => l_array_source_35(Idx)
207416  , p_source_17 => l_array_source_17(Idx)
207417  , p_source_29 => l_array_source_29(Idx)
207418  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
207420  , p_source_36 => l_array_source_36(Idx)
207421  , p_source_37 => l_array_source_37(Idx)
207422  , p_source_38 => l_array_source_38(Idx)
207423  , p_source_39 => l_array_source_39(Idx)
207424  , p_source_40 => l_array_source_40(Idx)
207425  );
207426 If(l_balance_type_code = 'A') THEN
207427   l_actual_gain_loss_ref := l_gain_or_loss_ref;
207428 END IF;
207429 
207430 --
207431 
207432       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
207433       -- or secondary ledger that has different currency with primary
207434       -- or alc that is calculated by sla
207435       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
207436             (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'))
207437 
207438 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
207439 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
207440           AND (l_actual_flag = 'A')) THEN
207441         XLA_AE_LINES_PKG.CreateGainOrLossLines(
207442           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
207443          ,p_application_id   => p_application_id
207444          ,p_amb_context_code => 'DEFAULT'
207445          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
207446          ,p_event_class_code => C_EVENT_CLASS_CODE
207447          ,p_event_type_code  => C_EVENT_TYPE_CODE
207448          
207449          ,p_gain_ccid        => -1
207450          ,p_loss_ccid        => -1
207451 
207452          ,p_actual_flag      => l_actual_flag
207453          ,p_enc_flag         => null
207454          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
207455          ,p_enc_g_l_ref      => null
207456          );
207457       END IF;
207458    END IF;
207459 END IF;
207460 
207461    ELSE
207462       --
207463       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
207464       --
207465       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
207466          trace
207467             (p_msg      => 'Trancaction revesal option is Y'
207468             ,p_level    => C_LEVEL_STATEMENT
207469             ,p_module   => l_log_module);
207470       END IF;
207471    END IF;
207472 
207473 END LOOP;
207474 l_result := XLA_AE_LINES_PKG.InsertLines ;
207475 end loop;
207476 close line_cur;
207477 
207478 
207479 --
207480 -- insert headers into xla_ae_headers_gt table
207481 --
207482 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
207483 
207484 -- insert into errors table here.
207485 
207486 END LOOP;
207487 
207488 --
207489 -- 4865292
207490 --
207491 -- Compare g_hdr_extract_count with event count in
207492 -- CreateHeadersAndLines.
207493 --
207494 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
207495 
207496 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
207497    trace (p_msg     => '# rows extracted from header extract objects '
207498                     || ' (running total): '
207499                     || g_hdr_extract_count
207500          ,p_level   => C_LEVEL_STATEMENT
207501          ,p_module  => l_log_module);
207502 END IF;
207503 
207504 CLOSE header_cur;
207505 --
207506 
207507 --
207508 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
207509    trace
207510       (p_msg      => 'END of EventClass_426'
207511       ,p_level    => C_LEVEL_PROCEDURE
207512       ,p_module   => l_log_module);
207513 END IF;
207514 --
207515 RETURN l_result;
207516 EXCEPTION
207517 WHEN xla_exceptions_pkg.application_exception THEN
207518    
207519 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
207520 
207521    
207522 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
207523 
207524    RAISE;
207525 
207526 WHEN NO_DATA_FOUND THEN
207527 
207528 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
207529 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
207530 
207531 FOR header_record IN header_cur
207532 LOOP
207533     l_array_header_events(header_record.event_id) := header_record.event_id;
207534 END LOOP;
207535 
207536 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
207537 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
207538 
207539 fnd_file.put_line(fnd_file.LOG, '                    ');
207540 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
207541 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
207542 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
207543 
207544 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
207545 LOOP
207546 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
207547 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
207548         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
207549 	END IF;
207550 END LOOP;
207551 
207552 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
207553 fnd_file.put_line(fnd_file.LOG, '                    ');
207554 
207555 
207556 xla_exceptions_pkg.raise_message
207557       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_426');
207558 
207559 
207560 WHEN OTHERS THEN
207561    xla_exceptions_pkg.raise_message
207562       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_426');
207563 END EventClass_426;
207567 --
207564 --
207565 
207566 ---------------------------------------
207568 -- PRIVATE PROCEDURE
207569 --         insert_sources_427
207570 --
207571 ----------------------------------------
207572 --
207573 PROCEDURE insert_sources_427(
207574                                 p_target_ledger_id       IN NUMBER
207575                               , p_language               IN VARCHAR2
207576                               , p_sla_ledger_id          IN NUMBER
207577                               , p_pad_start_date         IN DATE
207578                               , p_pad_end_date           IN DATE
207579                          )
207580 IS
207581 
207582 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'REVALUATION_ALL';
207583 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'REVALUATION';
207584 p_apps_owner                   VARCHAR2(30);
207585 l_log_module                   VARCHAR2(240);
207586 BEGIN
207587 IF g_log_enabled THEN
207588       l_log_module := C_DEFAULT_MODULE||'.insert_sources_427';
207589 END IF;
207590 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
207591 
207592       trace
207593          (p_msg      => 'BEGIN of insert_sources_427'
207594          ,p_level    => C_LEVEL_PROCEDURE
207595          ,p_module   => l_log_module);
207596 
207597 END IF;
207598 
207599 -- select APPS owner
207600 SELECT oracle_username
207601   INTO p_apps_owner
207602   FROM fnd_oracle_userid
207603  WHERE read_only_flag = 'U'
207604 ;
207605 
207606 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
207607       trace
207608          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
207609                         ' - p_language = '||p_language||
207610                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
207611                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
207612                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
207613                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
207614          ,p_level    => C_LEVEL_STATEMENT
207615          ,p_module   => l_log_module);
207616 END IF;
207617 
207618 
207619 --
207620 INSERT INTO xla_diag_sources --hdr2
207621 (
207622         event_id
207623       , ledger_id
207624       , sla_ledger_id
207625       , description_language
207626       , object_name
207627       , object_type_code
207628       , line_number
207629       , source_application_id
207630       , source_type_code
207631       , source_code
207632       , source_value
207633       , source_meaning
207634       , created_by
207635       , creation_date
207636       , last_update_date
207637       , last_updated_by
207638       , last_update_login
207639       , program_update_date
207640       , program_application_id
207641       , program_id
207642       , request_id
207643 )
207644 SELECT
207645         event_id
207646       , p_target_ledger_id
207647       , p_sla_ledger_id
207648       , p_language
207649       , object_name
207650       , object_type_code
207651       , line_number
207652       , source_application_id
207653       , source_type_code
207654       , source_code
207655       , SUBSTR(source_value ,1,1996)
207656       , SUBSTR(source_meaning ,1,200)
207657       , xla_environment_pkg.g_Usr_Id
207658       , TRUNC(SYSDATE)
207659       , TRUNC(SYSDATE)
207660       , xla_environment_pkg.g_Usr_Id
207661       , xla_environment_pkg.g_Login_Id
207662       , TRUNC(SYSDATE)
207663       , xla_environment_pkg.g_Prog_Appl_Id
207664       , xla_environment_pkg.g_Prog_Id
207665       , xla_environment_pkg.g_Req_Id
207666   FROM (
207667        SELECT xet.event_id                  event_id
207668             , 0                          line_number
207669             , CASE r
207670                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
207671                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
207672                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
207673                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
207674                 
207675                ELSE null
207676               END                           object_name
207677             , CASE r
207678                 WHEN 1 THEN 'HEADER' 
207679                 WHEN 2 THEN 'HEADER' 
207680                 WHEN 3 THEN 'HEADER' 
207681                 WHEN 4 THEN 'HEADER' 
207682                 
207683                 ELSE null
207684               END                           object_type_code
207685             , CASE r
207686                 WHEN 1 THEN '140' 
207687                 WHEN 2 THEN '140' 
207688                 WHEN 3 THEN '140' 
207689                 WHEN 4 THEN '140' 
207690                 
207691                 ELSE null
207692               END                           source_application_id
207693             , 'S'             source_type_code
207694             , CASE r
207695                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
207696                 WHEN 2 THEN 'DEFAULT_CCID' 
207697                 WHEN 3 THEN 'ACCOUNTING_DATE' 
207698                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
207699                 
207700                 ELSE null
207701               END                           source_code
207702             , CASE r
207703                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
207704                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
207705                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
207706                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
207707                 
207708                 ELSE null
207709               END                           source_value
207710             , null              source_meaning
207711          FROM xla_events_gt     xet  
207712       , FA_XLA_EXT_HEADERS_B_GT  h1
207713              ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
207714          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
207718 )
207715            AND xet.event_class_code = C_EVENT_CLASS_CODE
207716               AND h1.event_id = xet.event_id
207717 
207719 ;
207720 --
207721 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
207722 
207723       trace
207724          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
207725          ,p_level    => C_LEVEL_STATEMENT
207726          ,p_module   => l_log_module);
207727 
207728 END IF;
207729 --
207730 
207731 
207732 
207733 --
207734 INSERT INTO xla_diag_sources  --line2
207735 (
207736         event_id
207737       , ledger_id
207738       , sla_ledger_id
207739       , description_language
207740       , object_name
207741       , object_type_code
207742       , line_number
207743       , source_application_id
207744       , source_type_code
207745       , source_code
207746       , source_value
207747       , source_meaning
207748       , created_by
207749       , creation_date
207750       , last_update_date
207751       , last_updated_by
207752       , last_update_login
207753       , program_update_date
207754       , program_application_id
207755       , program_id
207756       , request_id
207757 )
207758 SELECT  event_id
207759       , p_target_ledger_id
207760       , p_sla_ledger_id
207761       , p_language
207762       , object_name
207763       , object_type_code
207764       , line_number
207765       , source_application_id
207766       , source_type_code
207767       , source_code
207768       , SUBSTR(source_value,1,1996)
207769       , SUBSTR(source_meaning ,1,200)
207770       , xla_environment_pkg.g_Usr_Id
207771       , TRUNC(SYSDATE)
207772       , TRUNC(SYSDATE)
207773       , xla_environment_pkg.g_Usr_Id
207774       , xla_environment_pkg.g_Login_Id
207775       , TRUNC(SYSDATE)
207776       , xla_environment_pkg.g_Prog_Appl_Id
207777       , xla_environment_pkg.g_Prog_Id
207778       , xla_environment_pkg.g_Req_Id
207779   FROM (
207780        SELECT xet.event_id                  event_id
207781             , l2.line_number                 line_number
207782             , CASE r
207783                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
207784                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
207785                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
207786                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
207787                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
207788                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
207789                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
207790                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
207791                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
207792                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
207793                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
207794                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
207795                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
207796                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
207797                 
207798                ELSE null
207799               END                           object_name
207800             , CASE r
207801                 WHEN 1 THEN 'LINE' 
207802                 WHEN 2 THEN 'LINE' 
207803                 WHEN 3 THEN 'LINE' 
207804                 WHEN 4 THEN 'LINE' 
207805                 WHEN 5 THEN 'LINE' 
207806                 WHEN 6 THEN 'LINE' 
207807                 WHEN 7 THEN 'LINE' 
207808                 WHEN 8 THEN 'LINE' 
207809                 WHEN 9 THEN 'LINE' 
207810                 WHEN 10 THEN 'LINE' 
207811                 WHEN 11 THEN 'LINE' 
207812                 WHEN 12 THEN 'LINE' 
207813                 WHEN 13 THEN 'LINE' 
207814                 WHEN 14 THEN 'LINE' 
207815                 
207816                 ELSE null
207817               END                           object_type_code
207818             , CASE r
207819                 WHEN 1 THEN '140' 
207820                 WHEN 2 THEN '140' 
207821                 WHEN 3 THEN '140' 
207822                 WHEN 4 THEN '140' 
207823                 WHEN 5 THEN '140' 
207824                 WHEN 6 THEN '140' 
207825                 WHEN 7 THEN '140' 
207826                 WHEN 8 THEN '140' 
207827                 WHEN 9 THEN '140' 
207828                 WHEN 10 THEN '140' 
207829                 WHEN 11 THEN '140' 
207830                 WHEN 12 THEN '140' 
207831                 WHEN 13 THEN '140' 
207832                 WHEN 14 THEN '140' 
207833                 
207834                 ELSE null
207835               END                           source_application_id
207836             , 'S'             source_type_code
207837             , CASE r
207838                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
207839                 WHEN 2 THEN 'GENERATED_CCID' 
207840                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
207841                 WHEN 4 THEN 'ASSET_COST_ACCT' 
207842                 WHEN 5 THEN 'DEPRN_RESERVE_ACCT' 
207843                 WHEN 6 THEN 'REVAL_RESERVE_ACCT' 
207844                 WHEN 7 THEN 'GENERATED_OFFSET_CCID' 
207845                 WHEN 8 THEN 'EXPENSE_ACCOUNT_CCID' 
207846                 WHEN 9 THEN 'ADJUSTMENT_TYPE' 
207847                 WHEN 10 THEN 'TRANSACTION_HEADER_ID' 
207848                 WHEN 11 THEN 'ADJUSTMENT_LINE_ID' 
207849                 WHEN 12 THEN 'DISTRIBUTION_TYPE_CODE' 
207850                 WHEN 13 THEN 'ENTERED_AMOUNT' 
207851                 WHEN 14 THEN 'CURRENCY_CODE' 
207852                 
207853                 ELSE null
207854               END                           source_code
207855             , CASE r
207856                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
207857                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
207858                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
207859                 WHEN 4 THEN TO_CHAR(l2.ASSET_COST_ACCT)
207860                 WHEN 5 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
207864                 WHEN 9 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
207861                 WHEN 6 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
207862                 WHEN 7 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
207863                 WHEN 8 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
207865                 WHEN 10 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
207866                 WHEN 11 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
207867                 WHEN 12 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
207868                 WHEN 13 THEN TO_CHAR(l2.ENTERED_AMOUNT)
207869                 WHEN 14 THEN TO_CHAR(l2.CURRENCY_CODE)
207870                 
207871                 ELSE null
207872               END                           source_value
207873             , null              source_meaning
207874          FROM  xla_events_gt     xet  
207875         , FA_XLA_EXT_LINES_B_GT  l2
207876             , (select rownum r from all_objects where rownum <= 14 and owner = p_apps_owner)
207877         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
207878           AND xet.event_class_code = C_EVENT_CLASS_CODE
207879             AND l2.event_id          = xet.event_id
207880   AND l2.ledger_id (+)  = p_sla_ledger_id
207881 
207882 )
207883 ;
207884 --
207885 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
207886 
207887       trace
207888          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
207889          ,p_level    => C_LEVEL_STATEMENT
207890          ,p_module   => l_log_module);
207891 
207892 END IF;
207893 
207894 
207895 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
207896       trace
207897          (p_msg      => 'END of insert_sources_427'
207898          ,p_level    => C_LEVEL_PROCEDURE
207899          ,p_module   => l_log_module);
207900 END IF;
207901 EXCEPTION
207902   WHEN xla_exceptions_pkg.application_exception THEN
207903       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
207904             trace
207905                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
207906                ,p_level    => C_LEVEL_EXCEPTION
207907                ,p_module   => l_log_module);
207908       END IF;
207909       RAISE;
207910   WHEN OTHERS THEN
207911       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
207912             trace
207913                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
207914                ,p_level    => C_LEVEL_EXCEPTION
207915                ,p_module   => l_log_module);
207916        END IF;
207917        xla_exceptions_pkg.raise_message
207918            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_427');
207919 END insert_sources_427;
207920 --
207921 
207922 ---------------------------------------
207923 --
207924 -- PRIVATE FUNCTION
207925 --         EventClass_427
207926 --
207927 ----------------------------------------
207928 --
207929 FUNCTION EventClass_427
207930        (p_application_id         IN NUMBER
207931        ,p_base_ledger_id         IN NUMBER
207932        ,p_target_ledger_id       IN NUMBER
207933        ,p_language               IN VARCHAR2
207934        ,p_currency_code          IN VARCHAR2
207935        ,p_sla_ledger_id          IN NUMBER
207936        ,p_pad_start_date         IN DATE
207937        ,p_pad_end_date           IN DATE
207938        ,p_primary_ledger_id      IN NUMBER)
207939 RETURN BOOLEAN IS
207940 --
207941 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'REVALUATION_ALL';
207942 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'REVALUATION';
207943 
207944 l_calculate_acctd_flag   VARCHAR2(1) :='N';
207945 l_calculate_g_l_flag     VARCHAR2(1) :='N';
207946 --
207947 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
207948 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
207949 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
207950 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
207951 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
207952 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
207953 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
207954 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
207955 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
207956 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
207957 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
207958 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
207959 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
207960 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
207961 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
207962 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
207963 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
207964 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
207965 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
207966 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
207967 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
207968 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
207969 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
207970 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
207971 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
207972 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
207973 
207974 l_event_id                             NUMBER;
207975 l_previous_event_id                    NUMBER;
207976 l_first_event_id                       NUMBER;
207977 l_last_event_id                        NUMBER;
207978 
207979 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
207983 l_result                    BOOLEAN := TRUE;
207980 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
207981 --
207982 --
207984 l_rows                      NUMBER  := 1000;
207985 l_event_type_name           VARCHAR2(80) := 'All';
207986 l_event_class_name          VARCHAR2(80) := 'Revaluation';
207987 l_description               VARCHAR2(4000);
207988 l_transaction_reversal      NUMBER;
207989 l_ae_header_id              NUMBER;
207990 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
207991 l_log_module                VARCHAR2(240);
207992 --
207993 l_acct_reversal_source      VARCHAR2(30);
207994 l_trx_reversal_source       VARCHAR2(30);
207995 
207996 l_continue_with_lines       BOOLEAN := TRUE;
207997 --
207998 l_acc_rev_gl_date_source    DATE;                      -- 4262811
207999 --
208000 type t_array_event_id is table of number index by binary_integer;
208001 
208002 l_rec_array_event                    t_rec_array_event;
208003 l_null_rec_array_event               t_rec_array_event;
208004 l_array_ae_header_id                 xla_number_array_type;
208005 l_actual_flag                        VARCHAR2(1) := NULL;
208006 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
208007 l_balance_type_code                  VARCHAR2(1) :=NULL;
208008 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
208009 
208010 --
208011 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
208012 --
208013 
208014 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
208015 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
208016 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
208017 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
208018 
208019 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
208020 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
208021 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
208022 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
208023 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
208024 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
208025 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
208026 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
208027 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
208028 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
208029 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
208030 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
208031 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
208032 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
208033 
208034 l_array_source_1              t_array_source_1;
208035 l_array_source_30              t_array_source_30;
208036 l_array_source_51              t_array_source_51;
208037 l_array_source_52              t_array_source_52;
208038 
208039 l_array_source_2      t_array_source_2;
208040 l_array_source_3      t_array_source_3;
208041 l_array_source_4      t_array_source_4;
208042 l_array_source_9      t_array_source_9;
208043 l_array_source_10      t_array_source_10;
208044 l_array_source_11      t_array_source_11;
208045 l_array_source_17      t_array_source_17;
208046 l_array_source_29      t_array_source_29;
208047 l_array_source_35      t_array_source_35;
208048 l_array_source_36      t_array_source_36;
208049 l_array_source_37      t_array_source_37;
208050 l_array_source_38      t_array_source_38;
208051 l_array_source_39      t_array_source_39;
208052 l_array_source_40      t_array_source_40;
208053 
208054 --
208055 CURSOR header_cur
208056 IS
208057 SELECT /*+ leading(xet) cardinality(xet,1) */
208058 -- Event Class Code: REVALUATION
208059     xet.entity_id
208060    ,xet.legal_entity_id
208061    ,xet.entity_code
208062    ,xet.transaction_number
208063    ,xet.event_id
208064    ,xet.event_class_code
208065    ,xet.event_type_code
208066    ,xet.event_number
208067    ,xet.event_date
208068    ,xet.transaction_date
208069    ,xet.reference_num_1
208070    ,xet.reference_num_2
208071    ,xet.reference_num_3
208072    ,xet.reference_num_4
208073    ,xet.reference_char_1
208074    ,xet.reference_char_2
208075    ,xet.reference_char_3
208076    ,xet.reference_char_4
208077    ,xet.reference_date_1
208078    ,xet.reference_date_2
208079    ,xet.reference_date_3
208080    ,xet.reference_date_4
208081    ,xet.event_created_by
208082    ,xet.budgetary_control_flag 
208083   , h1.PERIOD_CLOSE_DATE    source_1
208084   , h1.DEFAULT_CCID    source_30
208085   , h1.ACCOUNTING_DATE    source_51
208086   , h1.TRANSFER_TO_GL_FLAG    source_52
208087   FROM xla_events_gt     xet 
208088   , FA_XLA_EXT_HEADERS_B_GT  h1
208089  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
208090    and xet.event_class_code = C_EVENT_CLASS_CODE
208091    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
208092 
208093  ORDER BY event_id
208094 ;
208095 
208096 
208097 --
208098 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
208099 IS
208100 SELECT  /*+ leading(xet) cardinality(xet,1) */
208101 -- Event Class Code: REVALUATION
208102     xet.entity_id
208103    ,xet.legal_entity_id
208104    ,xet.entity_code
208108    ,xet.event_type_code
208105    ,xet.transaction_number
208106    ,xet.event_id
208107    ,xet.event_class_code
208109    ,xet.event_number
208110    ,xet.event_date
208111    ,xet.transaction_date
208112    ,xet.reference_num_1
208113    ,xet.reference_num_2
208114    ,xet.reference_num_3
208115    ,xet.reference_num_4
208116    ,xet.reference_char_1
208117    ,xet.reference_char_2
208118    ,xet.reference_char_3
208119    ,xet.reference_char_4
208120    ,xet.reference_date_1
208121    ,xet.reference_date_2
208122    ,xet.reference_date_3
208123    ,xet.reference_date_4
208124    ,xet.event_created_by
208125    ,xet.budgetary_control_flag
208126  , l2.LINE_NUMBER  
208127   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
208128   , l2.GENERATED_CCID    source_3
208129   , l2.BONUS_RESERVE_ACCT    source_4
208130   , l2.ASSET_COST_ACCT    source_9
208131   , l2.DEPRN_RESERVE_ACCT    source_10
208132   , l2.REVAL_RESERVE_ACCT    source_11
208133   , l2.GENERATED_OFFSET_CCID    source_17
208134   , l2.EXPENSE_ACCOUNT_CCID    source_29
208135   , l2.ADJUSTMENT_TYPE    source_35
208136   , l2.TRANSACTION_HEADER_ID    source_36
208137   , l2.ADJUSTMENT_LINE_ID    source_37
208138   , l2.DISTRIBUTION_TYPE_CODE    source_38
208139   , l2.ENTERED_AMOUNT    source_39
208140   , l2.CURRENCY_CODE    source_40
208141   FROM xla_events_gt     xet 
208142   , FA_XLA_EXT_LINES_B_GT  l2
208143  WHERE xet.event_id between x_first_event_id and x_last_event_id
208144    and xet.event_date between p_pad_start_date and p_pad_end_date
208145    and xet.event_class_code = C_EVENT_CLASS_CODE
208146    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
208147   AND l2.ledger_id = p_sla_ledger_id
208148 ;
208149 
208150 --
208151 BEGIN
208152 IF g_log_enabled THEN
208153    l_log_module := C_DEFAULT_MODULE||'.EventClass_427';
208154 END IF;
208155 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
208156    trace
208157       (p_msg      => 'BEGIN of EventClass_427'
208158       ,p_level    => C_LEVEL_PROCEDURE
208159       ,p_module   => l_log_module);
208160 END IF;
208161 
208162 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
208163    trace
208164       (p_msg      => 'p_application_id = '||p_application_id||
208165                      ' - p_base_ledger_id = '||p_base_ledger_id||
208166                      ' - p_target_ledger_id  = '||p_target_ledger_id||
208167                      ' - p_language = '||p_language||
208168                      ' - p_currency_code = '||p_currency_code||
208169                      ' - p_sla_ledger_id = '||p_sla_ledger_id
208170       ,p_level    => C_LEVEL_STATEMENT
208171       ,p_module   => l_log_module);
208172 END IF;
208173 --
208174 -- initialze arrays
208175 --
208176 g_array_event.DELETE;
208177 l_rec_array_event := l_null_rec_array_event;
208178 --
208179 --------------------------------------
208180 -- 4262811 Initialze MPA Line Number
208181 --------------------------------------
208182 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
208183 
208184 --
208185 
208186 --
208187 OPEN header_cur;
208188 --
208189 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
208190    trace
208191    (p_msg      => 'SQL - FETCH header_cur'
208192    ,p_level    => C_LEVEL_STATEMENT
208193    ,p_module   => l_log_module);
208194 END IF;
208195 --
208196 LOOP
208197 FETCH header_cur BULK COLLECT INTO
208198         l_array_entity_id
208199       , l_array_legal_entity_id
208200       , l_array_entity_code
208201       , l_array_transaction_num
208202       , l_array_event_id
208203       , l_array_class_code
208204       , l_array_event_type
208205       , l_array_event_number
208206       , l_array_event_date
208207       , l_array_transaction_date
208208       , l_array_reference_num_1
208209       , l_array_reference_num_2
208210       , l_array_reference_num_3
208211       , l_array_reference_num_4
208212       , l_array_reference_char_1
208213       , l_array_reference_char_2
208214       , l_array_reference_char_3
208215       , l_array_reference_char_4
208216       , l_array_reference_date_1
208217       , l_array_reference_date_2
208218       , l_array_reference_date_3
208219       , l_array_reference_date_4
208220       , l_array_event_created_by
208221       , l_array_budgetary_control_flag 
208222       , l_array_source_1
208223       , l_array_source_30
208224       , l_array_source_51
208225       , l_array_source_52
208226       LIMIT l_rows;
208227 --
208228 IF (C_LEVEL_EVENT >= g_log_level) THEN
208229    trace
208230    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
208231    ,p_level    => C_LEVEL_EVENT
208232    ,p_module   => l_log_module);
208233 END IF;
208234 --
208235 EXIT WHEN l_array_entity_id.COUNT = 0;
208236 
208237 -- initialize arrays
208238 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
208239 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
208240 
208241 --
208242 -- Bug 4458708
208243 --
208244 XLA_AE_LINES_PKG.g_LineNumber := 0;
208245 
208246 
208247 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
208248 g_last_hdr_idx := l_array_event_id.LAST;
208249 --
208250 -- loop for the headers. Each iteration is for each header extract row
208251 -- fetched in header cursor
208252 --
208253 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
208254 
208255 --
208256 -- set event info as cache for other routines to refer event attributes
208257 --
208258 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
208259    (p_application_id           => p_application_id
208260    ,p_primary_ledger_id        => p_primary_ledger_id
208261    ,p_base_ledger_id           => p_base_ledger_id
208262    ,p_target_ledger_id         => p_target_ledger_id
208263    ,p_entity_id                => l_array_entity_id(hdr_idx)
208267    ,p_event_id                 => l_array_event_id(hdr_idx)
208264    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
208265    ,p_entity_code              => l_array_entity_code(hdr_idx)
208266    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
208268    ,p_event_class_code         => l_array_class_code(hdr_idx)
208269    ,p_event_type_code          => l_array_event_type(hdr_idx)
208270    ,p_event_number             => l_array_event_number(hdr_idx)
208271    ,p_event_date               => l_array_event_date(hdr_idx)
208272    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
208273    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
208274    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
208275    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
208276    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
208277    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
208278    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
208279    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
208280    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
208281    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
208282    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
208283    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
208284    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
208285    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
208286    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
208287 
208288 --
208289 -- set the status of entry to C_VALID (0)
208290 --
208291 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
208292 
208293 --
208294 -- initialize a row for ae header
208295 --
208296 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
208297 
208298 l_event_id := l_array_event_id(hdr_idx);
208299 
208300 --
208301 -- storing the hdr_idx for event. May be used by line cursor.
208302 --
208303 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
208304 
208305 --
208306 -- store sources from header extract. This can be improved to
208307 -- store only those sources from header extract that may be used in lines
208308 --
208309 
208310 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
208311 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
208312 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
208313 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
208314 
208315 --
208316 -- initilaize the status of ae headers for diffrent balance types
208317 -- the status is initialised to C_NOT_CREATED (2)
208318 --
208319 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
208320 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
208321 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
208322 
208323 --
208324 -- call api to validate and store accounting attributes for header
208325 --
208326 
208327 ------------------------------------------------------------
208328 -- Accrual Reversal : to get date for Standard Source (NONE)
208329 ------------------------------------------------------------
208330 l_acc_rev_gl_date_source := NULL;
208331 
208332      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
208333       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
208334      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
208335       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
208336 
208337 
208338 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
208339 
208340 XLA_AE_HEADER_PKG.SetJeCategoryName;
208341 
208342 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
208343 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
208344 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
208345 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
208346 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
208347 
208348 
208349 --
208350 xla_ae_header_pkg.SetHdrDescription(
208351    p_description => Description_90 (
208352    p_application_id => p_application_id 
208353  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
208354    )
208355 );
208356 --
208357 
208358 -- No header level analytical criteria
208359 
208360 --
208361 --accounting attribute enhancement, bug 3612931
208362 --
208363 l_trx_reversal_source := SUBSTR(NULL, 1,30);
208364 
208365 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
208366    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
208367 
208368    xla_accounting_err_pkg.build_message
208369       (p_appli_s_name            => 'XLA'
208370       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
208371       ,p_token_1                 => 'ACCT_ATTR_NAME'
208372       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
208373       ,p_token_2                 => 'PRODUCT_NAME'
208374       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
208375       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
208376       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
208377       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
208378 
208379 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
208380    --
208381    -- following sets the accounting attributes needed to reverse
208385       (p_event_id              => l_event_id
208382    -- accounting for a distributeion
208383    --
208384    xla_ae_lines_pkg.SetTrxReversalAttrs
208386       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
208387       ,p_trx_reversal_source   => l_trx_reversal_source);
208388 
208389 END IF;
208390 
208391 
208392 ----------------------------------------------------------------
208393 -- 4262811 -  update the header statuses to invalid in need be
208394 ----------------------------------------------------------------
208395 --
208396 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
208397 
208398 
208399   -----------------------------------------------
208400   -- No accrual reversal for the event class/type
208401   -----------------------------------------------
208402 ----------------------------------------------------------------
208403 
208404 --
208405 -- this ends the header loop iteration for one bulk fetch
208406 --
208407 END LOOP;
208408 
208409 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
208410 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
208411 
208412 --
208413 -- insert dummy rows into lines gt table that were created due to
208414 -- transaction reversals
208415 --
208416 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
208417    l_result := XLA_AE_LINES_PKG.InsertLines;
208418 END IF;
208419 
208420 --
208421 -- reset the temp_line_num for each set of events fetched from header
208422 -- cursor rather than doing it for each new event in line cursor
208423 -- Bug 3939231
208424 --
208425 xla_ae_lines_pkg.g_temp_line_num := 0;
208426 
208427 
208428 
208429 --
208430 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
208431 --
208432 --
208433 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
208434 
208435       trace
208436          (p_msg      => 'SQL - FETCH line_cur'
208437          ,p_level    => C_LEVEL_STATEMENT
208438          ,p_module   => l_log_module);
208439 
208440 END IF;
208441 --
208442 --
208443 LOOP
208444   --
208445   FETCH line_cur BULK COLLECT INTO
208446         l_array_entity_id
208447       , l_array_legal_entity_id
208448       , l_array_entity_code
208449       , l_array_transaction_num
208450       , l_array_event_id
208451       , l_array_class_code
208452       , l_array_event_type
208453       , l_array_event_number
208454       , l_array_event_date
208455       , l_array_transaction_date
208456       , l_array_reference_num_1
208457       , l_array_reference_num_2
208458       , l_array_reference_num_3
208459       , l_array_reference_num_4
208460       , l_array_reference_char_1
208461       , l_array_reference_char_2
208462       , l_array_reference_char_3
208463       , l_array_reference_char_4
208464       , l_array_reference_date_1
208465       , l_array_reference_date_2
208466       , l_array_reference_date_3
208467       , l_array_reference_date_4
208468       , l_array_event_created_by
208469       , l_array_budgetary_control_flag
208470       , l_array_extract_line_num 
208471       , l_array_source_2
208472       , l_array_source_3
208473       , l_array_source_4
208474       , l_array_source_9
208475       , l_array_source_10
208476       , l_array_source_11
208477       , l_array_source_17
208478       , l_array_source_29
208479       , l_array_source_35
208480       , l_array_source_36
208481       , l_array_source_37
208482       , l_array_source_38
208483       , l_array_source_39
208484       , l_array_source_40
208485       LIMIT l_rows;
208486 
208487   --
208488   IF (C_LEVEL_EVENT >= g_log_level) THEN
208489             trace
208490                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
208491                ,p_level    => C_LEVEL_EVENT
208492                ,p_module   => l_log_module);
208493   END IF;
208494   --
208495   EXIT WHEN l_array_entity_id.count = 0;
208496 
208497   XLA_AE_LINES_PKG.g_rec_lines := null;
208498 
208499 --
208500 -- Bug 4458708
208501 --
208502 XLA_AE_LINES_PKG.g_LineNumber := 0;
208503 --
208504 --
208505 
208506 FOR Idx IN 1..l_array_event_id.count LOOP
208507    --
208508    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
208509    --
208510    l_event_id := l_array_event_id(idx);  -- 5648433
208511 
208512    --
208513    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
208514    --
208515 
208516    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
208517              (g_array_event(l_event_id).array_value_num('header_index'))
208518          ,'N'
208519          ) <> 'Y'
208520    THEN
208521       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
208522          trace
208523             (p_msg      => 'Trancaction revesal option is not Y '
208524             ,p_level    => C_LEVEL_STATEMENT
208525             ,p_module   => l_log_module);
208526       END IF;
208527 
208528 --
208529 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
208530 --
208531 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
208532 --
208533 -- set event info as cache for other routines to refer event attributes
208534 --
208535 
208536 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
208537    l_previous_event_id := l_event_id;
208538 
208539    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
208540       (p_application_id           => p_application_id
208541       ,p_primary_ledger_id        => p_primary_ledger_id
208542       ,p_base_ledger_id           => p_base_ledger_id
208543       ,p_target_ledger_id         => p_target_ledger_id
208547       ,p_transaction_num          => l_array_transaction_num(Idx)
208544       ,p_entity_id                => l_array_entity_id(Idx)
208545       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
208546       ,p_entity_code              => l_array_entity_code(Idx)
208548       ,p_event_id                 => l_array_event_id(Idx)
208549       ,p_event_class_code         => l_array_class_code(Idx)
208550       ,p_event_type_code          => l_array_event_type(Idx)
208551       ,p_event_number             => l_array_event_number(Idx)
208552       ,p_event_date               => l_array_event_date(Idx)
208553       ,p_transaction_date         => l_array_transaction_date(Idx)
208554       ,p_reference_num_1          => l_array_reference_num_1(Idx)
208555       ,p_reference_num_2          => l_array_reference_num_2(Idx)
208556       ,p_reference_num_3          => l_array_reference_num_3(Idx)
208557       ,p_reference_num_4          => l_array_reference_num_4(Idx)
208558       ,p_reference_char_1         => l_array_reference_char_1(Idx)
208559       ,p_reference_char_2         => l_array_reference_char_2(Idx)
208560       ,p_reference_char_3         => l_array_reference_char_3(Idx)
208561       ,p_reference_char_4         => l_array_reference_char_4(Idx)
208562       ,p_reference_date_1         => l_array_reference_date_1(Idx)
208563       ,p_reference_date_2         => l_array_reference_date_2(Idx)
208564       ,p_reference_date_3         => l_array_reference_date_3(Idx)
208565       ,p_reference_date_4         => l_array_reference_date_4(Idx)
208566       ,p_event_created_by         => l_array_event_created_by(Idx)
208567       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
208568        --
208569 END IF;
208570 
208571 
208572 
208573 --
208574 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
208575 
208576 l_acct_reversal_source := SUBSTR(NULL, 1,30);
208577 
208578 IF l_continue_with_lines THEN
208579    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
208580       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
208581 
208582       xla_accounting_err_pkg.build_message
208583          (p_appli_s_name            => 'XLA'
208584          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
208585          ,p_token_1                 => 'LINE_NUMBER'
208586          ,p_value_1                 => l_array_extract_line_num(Idx)
208587          ,p_token_2                 => 'PRODUCT_NAME'
208588          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
208589          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
208590          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
208591          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
208592 
208593    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
208594       --
208595       -- following sets the accounting attributes needed to reverse
208596       -- accounting for a distributeion
208597       --
208598 
208599       --
208600       -- 5217187
208601       --
208602       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
208603       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
208604                                        g_array_event(l_event_id).array_value_num('header_index'));
208605       --
208606       --
208607 
208608       -- No reversal code generated
208609 
208610       xla_ae_lines_pkg.SetAcctReversalAttrs
208611          (p_event_id             => l_event_id
208612          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
208613          ,p_calculate_acctd_flag => l_calculate_acctd_flag
208614          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
208615    END IF;
208616 
208617    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
208618        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
208619 
208620 --
208621 AcctLineType_318 (
208622  p_application_id  => p_application_id
208623  ,p_event_id     => l_event_id
208624  ,p_calculate_acctd_flag => l_calculate_acctd_flag
208625  ,p_calculate_g_l_flag => l_calculate_g_l_flag
208626  ,p_actual_flag => l_actual_flag
208627  ,p_balance_type_code => l_balance_type_code
208628  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
208629  
208630  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
208631  , p_source_3 => l_array_source_3(Idx)
208632  , p_source_4 => l_array_source_4(Idx)
208633  , p_source_17 => l_array_source_17(Idx)
208634  , p_source_29 => l_array_source_29(Idx)
208635  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
208636  , p_source_35 => l_array_source_35(Idx)
208637  , p_source_36 => l_array_source_36(Idx)
208638  , p_source_37 => l_array_source_37(Idx)
208639  , p_source_38 => l_array_source_38(Idx)
208640  , p_source_39 => l_array_source_39(Idx)
208641  , p_source_40 => l_array_source_40(Idx)
208642  );
208643 If(l_balance_type_code = 'A') THEN
208644   l_actual_gain_loss_ref := l_gain_or_loss_ref;
208645 END IF;
208646 
208647 --
208648 
208649 
208650 --
208651 AcctLineType_319 (
208652  p_application_id  => p_application_id
208653  ,p_event_id     => l_event_id
208654  ,p_calculate_acctd_flag => l_calculate_acctd_flag
208655  ,p_calculate_g_l_flag => l_calculate_g_l_flag
208656  ,p_actual_flag => l_actual_flag
208657  ,p_balance_type_code => l_balance_type_code
208658  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
208659  
208660  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
208661  , p_source_2 => l_array_source_2(Idx)
208662  , p_source_3 => l_array_source_3(Idx)
208663  , p_source_29 => l_array_source_29(Idx)
208664  , p_source_35 => l_array_source_35(Idx)
208665  , p_source_36 => l_array_source_36(Idx)
208666  , p_source_37 => l_array_source_37(Idx)
208667  , p_source_38 => l_array_source_38(Idx)
208668  , p_source_39 => l_array_source_39(Idx)
208669  , p_source_40 => l_array_source_40(Idx)
208673 END IF;
208670  );
208671 If(l_balance_type_code = 'A') THEN
208672   l_actual_gain_loss_ref := l_gain_or_loss_ref;
208674 
208675 --
208676 
208677 
208678 --
208679 AcctLineType_320 (
208680  p_application_id  => p_application_id
208681  ,p_event_id     => l_event_id
208682  ,p_calculate_acctd_flag => l_calculate_acctd_flag
208683  ,p_calculate_g_l_flag => l_calculate_g_l_flag
208684  ,p_actual_flag => l_actual_flag
208685  ,p_balance_type_code => l_balance_type_code
208686  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
208687  
208688  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
208689  , p_source_3 => l_array_source_3(Idx)
208690  , p_source_9 => l_array_source_9(Idx)
208691  , p_source_29 => l_array_source_29(Idx)
208692  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
208693  , p_source_35 => l_array_source_35(Idx)
208694  , p_source_36 => l_array_source_36(Idx)
208695  , p_source_37 => l_array_source_37(Idx)
208696  , p_source_38 => l_array_source_38(Idx)
208697  , p_source_39 => l_array_source_39(Idx)
208698  , p_source_40 => l_array_source_40(Idx)
208699  );
208700 If(l_balance_type_code = 'A') THEN
208701   l_actual_gain_loss_ref := l_gain_or_loss_ref;
208702 END IF;
208703 
208704 --
208705 
208706 
208707 --
208708 AcctLineType_321 (
208709  p_application_id  => p_application_id
208710  ,p_event_id     => l_event_id
208711  ,p_calculate_acctd_flag => l_calculate_acctd_flag
208712  ,p_calculate_g_l_flag => l_calculate_g_l_flag
208713  ,p_actual_flag => l_actual_flag
208714  ,p_balance_type_code => l_balance_type_code
208715  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
208716  
208717  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
208718  , p_source_3 => l_array_source_3(Idx)
208719  , p_source_10 => l_array_source_10(Idx)
208720  , p_source_17 => l_array_source_17(Idx)
208721  , p_source_29 => l_array_source_29(Idx)
208722  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
208723  , p_source_35 => l_array_source_35(Idx)
208724  , p_source_36 => l_array_source_36(Idx)
208725  , p_source_37 => l_array_source_37(Idx)
208726  , p_source_38 => l_array_source_38(Idx)
208727  , p_source_39 => l_array_source_39(Idx)
208728  , p_source_40 => l_array_source_40(Idx)
208729  );
208730 If(l_balance_type_code = 'A') THEN
208731   l_actual_gain_loss_ref := l_gain_or_loss_ref;
208732 END IF;
208733 
208734 --
208735 
208736 
208737 --
208738 AcctLineType_322 (
208739  p_application_id  => p_application_id
208740  ,p_event_id     => l_event_id
208741  ,p_calculate_acctd_flag => l_calculate_acctd_flag
208742  ,p_calculate_g_l_flag => l_calculate_g_l_flag
208743  ,p_actual_flag => l_actual_flag
208744  ,p_balance_type_code => l_balance_type_code
208745  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
208746  
208747  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
208748  , p_source_3 => l_array_source_3(Idx)
208749  , p_source_29 => l_array_source_29(Idx)
208750  , p_source_35 => l_array_source_35(Idx)
208751  , p_source_36 => l_array_source_36(Idx)
208752  , p_source_37 => l_array_source_37(Idx)
208753  , p_source_38 => l_array_source_38(Idx)
208754  , p_source_39 => l_array_source_39(Idx)
208755  , p_source_40 => l_array_source_40(Idx)
208756  );
208757 If(l_balance_type_code = 'A') THEN
208758   l_actual_gain_loss_ref := l_gain_or_loss_ref;
208759 END IF;
208760 
208761 --
208762 
208763 
208764 --
208765 AcctLineType_323 (
208766  p_application_id  => p_application_id
208767  ,p_event_id     => l_event_id
208768  ,p_calculate_acctd_flag => l_calculate_acctd_flag
208769  ,p_calculate_g_l_flag => l_calculate_g_l_flag
208770  ,p_actual_flag => l_actual_flag
208771  ,p_balance_type_code => l_balance_type_code
208772  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
208773  
208774  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
208775  , p_source_3 => l_array_source_3(Idx)
208776  , p_source_29 => l_array_source_29(Idx)
208777  , p_source_35 => l_array_source_35(Idx)
208778  , p_source_36 => l_array_source_36(Idx)
208779  , p_source_37 => l_array_source_37(Idx)
208780  , p_source_38 => l_array_source_38(Idx)
208781  , p_source_39 => l_array_source_39(Idx)
208782  , p_source_40 => l_array_source_40(Idx)
208783  );
208784 If(l_balance_type_code = 'A') THEN
208785   l_actual_gain_loss_ref := l_gain_or_loss_ref;
208786 END IF;
208787 
208788 --
208789 
208790 
208791 --
208792 AcctLineType_324 (
208793  p_application_id  => p_application_id
208794  ,p_event_id     => l_event_id
208795  ,p_calculate_acctd_flag => l_calculate_acctd_flag
208796  ,p_calculate_g_l_flag => l_calculate_g_l_flag
208797  ,p_actual_flag => l_actual_flag
208798  ,p_balance_type_code => l_balance_type_code
208799  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
208800  
208801  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
208802  , p_source_3 => l_array_source_3(Idx)
208803  , p_source_11 => l_array_source_11(Idx)
208804  , p_source_17 => l_array_source_17(Idx)
208805  , p_source_29 => l_array_source_29(Idx)
208806  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
208807  , p_source_35 => l_array_source_35(Idx)
208808  , p_source_36 => l_array_source_36(Idx)
208809  , p_source_37 => l_array_source_37(Idx)
208810  , p_source_38 => l_array_source_38(Idx)
208811  , p_source_39 => l_array_source_39(Idx)
208812  , p_source_40 => l_array_source_40(Idx)
208813  );
208814 If(l_balance_type_code = 'A') THEN
208815   l_actual_gain_loss_ref := l_gain_or_loss_ref;
208816 END IF;
208817 
208818 --
208819 
208820 
208821 --
208822 AcctLineType_325 (
208823  p_application_id  => p_application_id
208824  ,p_event_id     => l_event_id
208825  ,p_calculate_acctd_flag => l_calculate_acctd_flag
208826  ,p_calculate_g_l_flag => l_calculate_g_l_flag
208830  
208827  ,p_actual_flag => l_actual_flag
208828  ,p_balance_type_code => l_balance_type_code
208829  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
208831  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
208832  , p_source_3 => l_array_source_3(Idx)
208833  , p_source_10 => l_array_source_10(Idx)
208834  , p_source_17 => l_array_source_17(Idx)
208835  , p_source_29 => l_array_source_29(Idx)
208836  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
208837  , p_source_35 => l_array_source_35(Idx)
208838  , p_source_36 => l_array_source_36(Idx)
208839  , p_source_37 => l_array_source_37(Idx)
208840  , p_source_38 => l_array_source_38(Idx)
208841  , p_source_39 => l_array_source_39(Idx)
208842  , p_source_40 => l_array_source_40(Idx)
208843  );
208844 If(l_balance_type_code = 'A') THEN
208845   l_actual_gain_loss_ref := l_gain_or_loss_ref;
208846 END IF;
208847 
208848 --
208849 
208850       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
208851       -- or secondary ledger that has different currency with primary
208852       -- or alc that is calculated by sla
208853       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
208854             (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'))
208855 
208856 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
208857 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
208858           AND (l_actual_flag = 'A')) THEN
208859         XLA_AE_LINES_PKG.CreateGainOrLossLines(
208860           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
208861          ,p_application_id   => p_application_id
208862          ,p_amb_context_code => 'DEFAULT'
208863          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
208864          ,p_event_class_code => C_EVENT_CLASS_CODE
208865          ,p_event_type_code  => C_EVENT_TYPE_CODE
208866          
208867          ,p_gain_ccid        => -1
208868          ,p_loss_ccid        => -1
208869 
208870          ,p_actual_flag      => l_actual_flag
208871          ,p_enc_flag         => null
208872          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
208873          ,p_enc_g_l_ref      => null
208874          );
208875       END IF;
208876    END IF;
208877 END IF;
208878 
208879    ELSE
208880       --
208881       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
208882       --
208883       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
208884          trace
208885             (p_msg      => 'Trancaction revesal option is Y'
208886             ,p_level    => C_LEVEL_STATEMENT
208887             ,p_module   => l_log_module);
208888       END IF;
208889    END IF;
208890 
208891 END LOOP;
208892 l_result := XLA_AE_LINES_PKG.InsertLines ;
208893 end loop;
208894 close line_cur;
208895 
208896 
208897 --
208898 -- insert headers into xla_ae_headers_gt table
208899 --
208900 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
208901 
208902 -- insert into errors table here.
208903 
208904 END LOOP;
208905 
208906 --
208907 -- 4865292
208908 --
208909 -- Compare g_hdr_extract_count with event count in
208910 -- CreateHeadersAndLines.
208911 --
208912 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
208913 
208914 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
208915    trace (p_msg     => '# rows extracted from header extract objects '
208916                     || ' (running total): '
208917                     || g_hdr_extract_count
208918          ,p_level   => C_LEVEL_STATEMENT
208919          ,p_module  => l_log_module);
208920 END IF;
208921 
208922 CLOSE header_cur;
208923 --
208924 
208925 --
208926 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
208927    trace
208928       (p_msg      => 'END of EventClass_427'
208929       ,p_level    => C_LEVEL_PROCEDURE
208930       ,p_module   => l_log_module);
208931 END IF;
208932 --
208933 RETURN l_result;
208934 EXCEPTION
208935 WHEN xla_exceptions_pkg.application_exception THEN
208936    
208937 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
208938 
208939    
208940 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
208941 
208942    RAISE;
208943 
208944 WHEN NO_DATA_FOUND THEN
208945 
208946 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
208947 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
208948 
208949 FOR header_record IN header_cur
208950 LOOP
208951     l_array_header_events(header_record.event_id) := header_record.event_id;
208952 END LOOP;
208953 
208954 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
208955 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
208956 
208957 fnd_file.put_line(fnd_file.LOG, '                    ');
208958 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
208959 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
208960 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
208961 
208962 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
208963 LOOP
208964 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
208965 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
208966         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
208967 	END IF;
208968 END LOOP;
208969 
208970 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
208971 fnd_file.put_line(fnd_file.LOG, '                    ');
208972 
208976 
208973 
208974 xla_exceptions_pkg.raise_message
208975       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_427');
208977 
208978 WHEN OTHERS THEN
208979    xla_exceptions_pkg.raise_message
208980       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_427');
208981 END EventClass_427;
208982 --
208983 
208984 ---------------------------------------
208985 --
208986 -- PRIVATE PROCEDURE
208987 --         insert_sources_428
208988 --
208989 ----------------------------------------
208990 --
208991 PROCEDURE insert_sources_428(
208992                                 p_target_ledger_id       IN NUMBER
208993                               , p_language               IN VARCHAR2
208994                               , p_sla_ledger_id          IN NUMBER
208995                               , p_pad_start_date         IN DATE
208996                               , p_pad_end_date           IN DATE
208997                          )
208998 IS
208999 
209000 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'REVERSE_CAPITALIZATION';
209001 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CAPITALIZATION';
209002 p_apps_owner                   VARCHAR2(30);
209003 l_log_module                   VARCHAR2(240);
209004 BEGIN
209005 IF g_log_enabled THEN
209006       l_log_module := C_DEFAULT_MODULE||'.insert_sources_428';
209007 END IF;
209008 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
209009 
209010       trace
209011          (p_msg      => 'BEGIN of insert_sources_428'
209012          ,p_level    => C_LEVEL_PROCEDURE
209013          ,p_module   => l_log_module);
209014 
209015 END IF;
209016 
209017 -- select APPS owner
209018 SELECT oracle_username
209019   INTO p_apps_owner
209020   FROM fnd_oracle_userid
209021  WHERE read_only_flag = 'U'
209022 ;
209023 
209024 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
209025       trace
209026          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
209027                         ' - p_language = '||p_language||
209028                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
209029                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
209030                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
209031                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
209032          ,p_level    => C_LEVEL_STATEMENT
209033          ,p_module   => l_log_module);
209034 END IF;
209035 
209036 
209037 --
209038 INSERT INTO xla_diag_sources --hdr1
209039 (
209040         event_id
209041       , ledger_id
209042       , sla_ledger_id
209043       , description_language
209044       , object_name
209045       , object_type_code
209046       , line_number
209047       , source_application_id
209048       , source_type_code
209049       , source_code
209050       , source_value
209051       , source_meaning
209052       , created_by
209053       , creation_date
209054       , last_update_date
209055       , last_updated_by
209056       , last_update_login
209057       , program_update_date
209058       , program_application_id
209059       , program_id
209060       , request_id
209061 )
209062 SELECT
209063         event_id
209064       , p_target_ledger_id
209065       , p_sla_ledger_id
209066       , p_language
209067       , object_name
209068       , object_type_code
209069       , line_number
209070       , source_application_id
209071       , source_type_code
209072       , source_code
209073       , SUBSTR(source_value ,1,1996)
209074       , SUBSTR(source_meaning,1,200)
209075       , xla_environment_pkg.g_Usr_Id
209076       , TRUNC(SYSDATE)
209077       , TRUNC(SYSDATE)
209078       , xla_environment_pkg.g_Usr_Id
209079       , xla_environment_pkg.g_Login_Id
209080       , TRUNC(SYSDATE)
209081       , xla_environment_pkg.g_Prog_Appl_Id
209082       , xla_environment_pkg.g_Prog_Id
209083       , xla_environment_pkg.g_Req_Id
209084   FROM (
209085        SELECT xet.event_id                  event_id
209086             , 0                             line_number
209087             , CASE r
209088                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
209089                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
209090                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
209091                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
209092                 
209093                ELSE null
209094               END                           object_name
209095             , CASE r
209096                 WHEN 1 THEN 'HEADER' 
209097                 WHEN 2 THEN 'HEADER' 
209098                 WHEN 3 THEN 'HEADER' 
209099                 WHEN 4 THEN 'HEADER' 
209100                 
209101                 ELSE null
209102               END                           object_type_code
209103             , CASE r
209104                 WHEN 1 THEN '140' 
209105                 WHEN 2 THEN '140' 
209106                 WHEN 3 THEN '140' 
209107                 WHEN 4 THEN '140' 
209108                 
209109                 ELSE null
209110               END                           source_application_id
209111             , 'S'             source_type_code
209112             , CASE r
209113                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
209114                 WHEN 2 THEN 'DEFAULT_CCID' 
209115                 WHEN 3 THEN 'ACCOUNTING_DATE' 
209116                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
209117                 
209118                 ELSE null
209119               END                           source_code
209120             , CASE r
209121                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
209122                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
209123                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
209124                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
209125                 
209126                 ELSE null
209130       , FA_XLA_EXT_HEADERS_B_GT  h1
209127               END                           source_value
209128             , null              source_meaning
209129         FROM xla_events_gt     xet  
209131             ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
209132        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
209133          AND xet.event_type_code = C_EVENT_TYPE_CODE
209134             AND h1.event_id = xet.event_id
209135 
209136 )
209137 ;
209138 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
209139 
209140       trace
209141          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
209142          ,p_level    => C_LEVEL_STATEMENT
209143          ,p_module   => l_log_module);
209144 
209145 END IF;
209146 --
209147 
209148 
209149 
209150 --
209151 INSERT INTO xla_diag_sources --line1
209152 (
209153         event_id
209154       , ledger_id
209155       , sla_ledger_id
209156       , description_language
209157       , object_name
209158       , object_type_code
209159       , line_number
209160       , source_application_id
209161       , source_type_code
209162       , source_code
209163       , source_value
209164       , source_meaning
209165       , created_by
209166       , creation_date
209167       , last_update_date
209168       , last_updated_by
209169       , last_update_login
209170       , program_update_date
209171       , program_application_id
209172       , program_id
209173       , request_id
209174 )
209175 SELECT  event_id
209176       , p_target_ledger_id
209177       , p_sla_ledger_id
209178       , p_language
209179       , object_name
209180       , object_type_code
209181       , line_number
209182       , source_application_id
209183       , source_type_code
209184       , source_code
209185       , SUBSTR(source_value,1,1996)
209186       , SUBSTR(source_meaning,1,200)
209187       , xla_environment_pkg.g_Usr_Id
209188       , TRUNC(SYSDATE)
209189       , TRUNC(SYSDATE)
209190       , xla_environment_pkg.g_Usr_Id
209191       , xla_environment_pkg.g_Login_Id
209192       , TRUNC(SYSDATE)
209193       , xla_environment_pkg.g_Prog_Appl_Id
209194       , xla_environment_pkg.g_Prog_Id
209195       , xla_environment_pkg.g_Req_Id
209196   FROM (
209197        SELECT xet.event_id                  event_id
209198             , l2.line_number                 line_number
209199             , CASE r
209200                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
209201                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
209202                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
209203                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
209204                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
209205                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
209206                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
209207                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
209208                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
209209                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
209210                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
209211                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
209212                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
209213                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
209214                 
209215                ELSE null
209216               END                           object_name
209217             , CASE r
209218                 WHEN 1 THEN 'LINE' 
209219                 WHEN 2 THEN 'LINE' 
209220                 WHEN 3 THEN 'LINE' 
209221                 WHEN 4 THEN 'LINE' 
209222                 WHEN 5 THEN 'LINE' 
209223                 WHEN 6 THEN 'LINE' 
209224                 WHEN 7 THEN 'LINE' 
209225                 WHEN 8 THEN 'LINE' 
209226                 WHEN 9 THEN 'LINE' 
209227                 WHEN 10 THEN 'LINE' 
209228                 WHEN 11 THEN 'LINE' 
209229                 WHEN 12 THEN 'LINE' 
209230                 WHEN 13 THEN 'LINE' 
209231                 WHEN 14 THEN 'LINE' 
209232                 
209233                 ELSE null
209234               END                           object_type_code
209235             , CASE r
209236                 WHEN 1 THEN '140' 
209237                 WHEN 2 THEN '140' 
209238                 WHEN 3 THEN '140' 
209239                 WHEN 4 THEN '140' 
209240                 WHEN 5 THEN '140' 
209241                 WHEN 6 THEN '140' 
209242                 WHEN 7 THEN '140' 
209243                 WHEN 8 THEN '140' 
209244                 WHEN 9 THEN '140' 
209245                 WHEN 10 THEN '140' 
209246                 WHEN 11 THEN '140' 
209247                 WHEN 12 THEN '140' 
209248                 WHEN 13 THEN '140' 
209249                 WHEN 14 THEN '140' 
209250                 
209251                 ELSE null
209252               END                           source_application_id
209253             , 'S'             source_type_code
209254             , CASE r
209255                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
209256                 WHEN 2 THEN 'GENERATED_CCID' 
209257                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
209258                 WHEN 4 THEN 'CIP_COST_ACCT' 
209259                 WHEN 5 THEN 'ASSET_COST_ACCT' 
209260                 WHEN 6 THEN 'DEPRN_RESERVE_ACCT' 
209261                 WHEN 7 THEN 'GENERATED_OFFSET_CCID' 
209262                 WHEN 8 THEN 'EXPENSE_ACCOUNT_CCID' 
209263                 WHEN 9 THEN 'ADJUSTMENT_TYPE' 
209264                 WHEN 10 THEN 'TRANSACTION_HEADER_ID' 
209265                 WHEN 11 THEN 'ADJUSTMENT_LINE_ID' 
209266                 WHEN 12 THEN 'DISTRIBUTION_TYPE_CODE' 
209267                 WHEN 13 THEN 'ENTERED_AMOUNT' 
209268                 WHEN 14 THEN 'CURRENCY_CODE' 
209269                 
209270                 ELSE null
209271               END                           source_code
209272             , CASE r
209276                 WHEN 4 THEN TO_CHAR(l2.CIP_COST_ACCT)
209273                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
209274                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
209275                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
209277                 WHEN 5 THEN TO_CHAR(l2.ASSET_COST_ACCT)
209278                 WHEN 6 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
209279                 WHEN 7 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
209280                 WHEN 8 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
209281                 WHEN 9 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
209282                 WHEN 10 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
209283                 WHEN 11 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
209284                 WHEN 12 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
209285                 WHEN 13 THEN TO_CHAR(l2.ENTERED_AMOUNT)
209286                 WHEN 14 THEN TO_CHAR(l2.CURRENCY_CODE)
209287                 
209288                 ELSE null
209289               END                           source_value
209290             , null              source_meaning
209291          FROM  xla_events_gt     xet  
209292         , FA_XLA_EXT_LINES_B_GT  l2
209293             ,(select rownum r from all_objects where rownum <= 14 and owner = p_apps_owner)
209294         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
209295           AND xet.event_type_code = C_EVENT_TYPE_CODE
209296             AND l2.event_id          = xet.event_id
209297   AND l2.ledger_id (+)  = p_sla_ledger_id
209298 
209299 )
209300 ;
209301 --
209302 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
209303 
209304       trace
209305          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
209306          ,p_level    => C_LEVEL_STATEMENT
209307          ,p_module   => l_log_module);
209308 
209309 END IF;
209310 
209311 
209312 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
209313       trace
209314          (p_msg      => 'END of insert_sources_428'
209315          ,p_level    => C_LEVEL_PROCEDURE
209316          ,p_module   => l_log_module);
209317 END IF;
209318 EXCEPTION
209319   WHEN xla_exceptions_pkg.application_exception THEN
209320       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
209321             trace
209322                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
209323                ,p_level    => C_LEVEL_EXCEPTION
209324                ,p_module   => l_log_module);
209325       END IF;
209326       RAISE;
209327   WHEN OTHERS THEN
209328       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
209329             trace
209330                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
209331                ,p_level    => C_LEVEL_EXCEPTION
209332                ,p_module   => l_log_module);
209333        END IF;
209334        xla_exceptions_pkg.raise_message
209335            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_428');
209336 END insert_sources_428;
209337 --
209338 
209339 ---------------------------------------
209340 --
209341 -- PRIVATE FUNCTION
209342 --         EventType_428
209343 --
209344 ----------------------------------------
209345 --
209346 FUNCTION EventType_428
209347        (p_application_id         IN NUMBER
209348        ,p_base_ledger_id         IN NUMBER
209349        ,p_target_ledger_id       IN NUMBER
209350        ,p_language               IN VARCHAR2
209351        ,p_currency_code          IN VARCHAR2
209352        ,p_sla_ledger_id          IN NUMBER
209353        ,p_pad_start_date         IN DATE
209354        ,p_pad_end_date           IN DATE
209355        ,p_primary_ledger_id      IN NUMBER)
209356 RETURN BOOLEAN IS
209357 --
209358 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'REVERSE_CAPITALIZATION';
209359 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CAPITALIZATION';
209360 
209361 l_calculate_acctd_flag   VARCHAR2(1) :='N';
209362 l_calculate_g_l_flag     VARCHAR2(1) :='N';
209363 --
209364 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
209365 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
209366 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
209367 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
209368 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
209369 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
209370 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
209371 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
209372 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
209373 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
209374 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
209375 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
209376 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
209377 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
209378 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
209379 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
209380 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
209381 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
209382 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
209383 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
209384 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
209385 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
209386 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
209387 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
209388 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
209389 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
209390 
209394 l_last_event_id                        NUMBER;
209391 l_event_id                             NUMBER;
209392 l_previous_event_id                    NUMBER;
209393 l_first_event_id                       NUMBER;
209395 
209396 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
209397 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
209398 --
209399 --
209400 l_result                    BOOLEAN := TRUE;
209401 l_rows                      NUMBER  := 1000;
209402 l_event_type_name           VARCHAR2(80) := 'Reverse Capitalization';
209403 l_event_class_name          VARCHAR2(80) := 'Capitalization';
209404 l_description               VARCHAR2(4000);
209405 l_transaction_reversal      NUMBER;
209406 l_ae_header_id              NUMBER;
209407 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
209408 l_log_module                VARCHAR2(240);
209409 --
209410 l_acct_reversal_source      VARCHAR2(30);
209411 l_trx_reversal_source       VARCHAR2(30);
209412 
209413 l_continue_with_lines       BOOLEAN := TRUE;
209414 --
209415 l_acc_rev_gl_date_source    DATE;                      -- 4262811
209416 --
209417 type t_array_event_id is table of number index by binary_integer;
209418 
209419 l_rec_array_event                    t_rec_array_event;
209420 l_null_rec_array_event               t_rec_array_event;
209421 l_array_ae_header_id                 xla_number_array_type;
209422 l_actual_flag                        VARCHAR2(1) := NULL;
209423 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
209424 l_balance_type_code                  VARCHAR2(1) :=NULL;
209425 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
209426 
209427 --
209428 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
209429 --
209430 
209431 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
209432 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
209433 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
209434 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
209435 
209436 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
209437 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
209438 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
209439 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
209440 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
209441 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
209442 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
209443 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
209444 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
209445 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
209446 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
209447 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
209448 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
209449 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
209450 
209451 l_array_source_1              t_array_source_1;
209452 l_array_source_30              t_array_source_30;
209453 l_array_source_51              t_array_source_51;
209454 l_array_source_52              t_array_source_52;
209455 
209456 l_array_source_2      t_array_source_2;
209457 l_array_source_3      t_array_source_3;
209458 l_array_source_4      t_array_source_4;
209459 l_array_source_7      t_array_source_7;
209460 l_array_source_9      t_array_source_9;
209461 l_array_source_10      t_array_source_10;
209462 l_array_source_17      t_array_source_17;
209463 l_array_source_29      t_array_source_29;
209464 l_array_source_35      t_array_source_35;
209465 l_array_source_36      t_array_source_36;
209466 l_array_source_37      t_array_source_37;
209467 l_array_source_38      t_array_source_38;
209468 l_array_source_39      t_array_source_39;
209469 l_array_source_40      t_array_source_40;
209470 
209471 --
209472 CURSOR header_cur
209473 IS
209474 SELECT /*+ leading(xet) cardinality(xet,1) */
209475 -- Event Type Code: REVERSE_CAPITALIZATION
209476 -- Event Class Code: CAPITALIZATION
209477     xet.entity_id
209478   , xet.legal_entity_id
209479   , xet.entity_code
209480   , xet.transaction_number
209481   , xet.event_id
209482   , xet.event_class_code
209483   , xet.event_type_code
209484   , xet.event_number
209485   , xet.event_date
209486   , xet.transaction_date
209487   , xet.reference_num_1
209488   , xet.reference_num_2
209489   , xet.reference_num_3
209490   , xet.reference_num_4
209491   , xet.reference_char_1
209492   , xet.reference_char_2
209493   , xet.reference_char_3
209494   , xet.reference_char_4
209495   , xet.reference_date_1
209496   , xet.reference_date_2
209497   , xet.reference_date_3
209498   , xet.reference_date_4
209499   , xet.event_created_by
209500   , xet.budgetary_control_flag 
209501   , h1.PERIOD_CLOSE_DATE    source_1
209502   , h1.DEFAULT_CCID    source_30
209503   , h1.ACCOUNTING_DATE    source_51
209504   , h1.TRANSFER_TO_GL_FLAG    source_52
209505   FROM xla_events_gt     xet 
209506   , FA_XLA_EXT_HEADERS_B_GT  h1
209507  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
209508    and xet.event_type_code = C_EVENT_TYPE_CODE
209509    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
209510 
209514 
209511  ORDER BY event_id
209512 ;
209513 
209515 --
209516 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
209517 IS
209518 SELECT /*+ leading(xet) cardinality(xet,1) */
209519 -- Event Type Code: REVERSE_CAPITALIZATION
209520 -- Event Class Code: CAPITALIZATION
209521     xet.entity_id
209522    ,xet.legal_entity_id
209523    ,xet.entity_code
209524    ,xet.transaction_number
209525    ,xet.event_id
209526    ,xet.event_class_code
209527    ,xet.event_type_code
209528    ,xet.event_number
209529    ,xet.event_date
209530    ,xet.transaction_date
209531    ,xet.reference_num_1
209532    ,xet.reference_num_2
209533    ,xet.reference_num_3
209534    ,xet.reference_num_4
209535    ,xet.reference_char_1
209536    ,xet.reference_char_2
209537    ,xet.reference_char_3
209538    ,xet.reference_char_4
209539    ,xet.reference_date_1
209540    ,xet.reference_date_2
209541    ,xet.reference_date_3
209542    ,xet.reference_date_4
209543    ,xet.event_created_by
209544    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
209545   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
209546   , l2.GENERATED_CCID    source_3
209547   , l2.BONUS_RESERVE_ACCT    source_4
209548   , l2.CIP_COST_ACCT    source_7
209549   , l2.ASSET_COST_ACCT    source_9
209550   , l2.DEPRN_RESERVE_ACCT    source_10
209551   , l2.GENERATED_OFFSET_CCID    source_17
209552   , l2.EXPENSE_ACCOUNT_CCID    source_29
209553   , l2.ADJUSTMENT_TYPE    source_35
209554   , l2.TRANSACTION_HEADER_ID    source_36
209555   , l2.ADJUSTMENT_LINE_ID    source_37
209556   , l2.DISTRIBUTION_TYPE_CODE    source_38
209557   , l2.ENTERED_AMOUNT    source_39
209558   , l2.CURRENCY_CODE    source_40
209559   FROM xla_events_gt     xet 
209560   , FA_XLA_EXT_LINES_B_GT  l2
209561  WHERE xet.event_id between x_first_event_id and x_last_event_id
209562    and xet.event_date between p_pad_start_date and p_pad_end_date
209563    and xet.event_type_code = C_EVENT_TYPE_CODE
209564    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
209565   AND l2.ledger_id = p_sla_ledger_id
209566 ;
209567 
209568 --
209569 BEGIN
209570 IF g_log_enabled THEN
209571    l_log_module := C_DEFAULT_MODULE||'.EventType_428';
209572 END IF;
209573 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
209574    trace
209575       (p_msg      => 'BEGIN of EventType_428'
209576       ,p_level    => C_LEVEL_PROCEDURE
209577       ,p_module   => l_log_module);
209578 END IF;
209579 
209580 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
209581    trace
209582       (p_msg      => 'p_application_id = '||p_application_id||
209583                      ' - p_base_ledger_id = '||p_base_ledger_id||
209584                      ' - p_target_ledger_id  = '||p_target_ledger_id||
209585                      ' - p_language = '||p_language||
209586                      ' - p_currency_code = '||p_currency_code||
209587                      ' - p_sla_ledger_id = '||p_sla_ledger_id
209588       ,p_level    => C_LEVEL_STATEMENT
209589       ,p_module   => l_log_module);
209590 END IF;
209591 --
209592 -- initialze arrays
209593 --
209594 g_array_event.DELETE;
209595 l_rec_array_event := l_null_rec_array_event;
209596 --
209597 --------------------------------------
209598 -- 4262811 Initialze MPA Line Number
209599 --------------------------------------
209600 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
209601 
209602 --
209603 
209604 --
209605 OPEN header_cur;
209606 --
209607 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
209608    trace
209609    (p_msg      => 'SQL - FETCH header_cur'
209610    ,p_level    => C_LEVEL_STATEMENT
209611    ,p_module   => l_log_module);
209612 END IF;
209613 --
209614 LOOP
209615 FETCH header_cur BULK COLLECT INTO
209616         l_array_entity_id
209617       , l_array_legal_entity_id
209618       , l_array_entity_code
209619       , l_array_transaction_num
209620       , l_array_event_id
209621       , l_array_class_code
209622       , l_array_event_type
209623       , l_array_event_number
209624       , l_array_event_date
209625       , l_array_transaction_date
209626       , l_array_reference_num_1
209627       , l_array_reference_num_2
209628       , l_array_reference_num_3
209629       , l_array_reference_num_4
209630       , l_array_reference_char_1
209631       , l_array_reference_char_2
209632       , l_array_reference_char_3
209633       , l_array_reference_char_4
209634       , l_array_reference_date_1
209635       , l_array_reference_date_2
209636       , l_array_reference_date_3
209637       , l_array_reference_date_4
209638       , l_array_event_created_by
209639       , l_array_budgetary_control_flag 
209640       , l_array_source_1
209641       , l_array_source_30
209642       , l_array_source_51
209643       , l_array_source_52
209644       LIMIT l_rows;
209645 --
209646 IF (C_LEVEL_EVENT >= g_log_level) THEN
209647    trace
209648    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
209649    ,p_level    => C_LEVEL_EVENT
209650    ,p_module   => l_log_module);
209651 END IF;
209652 --
209653 EXIT WHEN l_array_entity_id.COUNT = 0;
209654 
209655 -- initialize arrays
209656 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
209657 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
209658 
209659 --
209660 -- Bug 4458708
209661 --
209662 XLA_AE_LINES_PKG.g_LineNumber := 0;
209663 
209664 
209665 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
209666 g_last_hdr_idx := l_array_event_id.LAST;
209667 --
209668 -- loop for the headers. Each iteration is for each header extract row
209669 -- fetched in header cursor
209670 --
209671 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
209672 
209673 --
209677    (p_application_id           => p_application_id
209674 -- set event info as cache for other routines to refer event attributes
209675 --
209676 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
209678    ,p_primary_ledger_id        => p_primary_ledger_id
209679    ,p_base_ledger_id           => p_base_ledger_id
209680    ,p_target_ledger_id         => p_target_ledger_id
209681    ,p_entity_id                => l_array_entity_id(hdr_idx)
209682    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
209683    ,p_entity_code              => l_array_entity_code(hdr_idx)
209684    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
209685    ,p_event_id                 => l_array_event_id(hdr_idx)
209686    ,p_event_class_code         => l_array_class_code(hdr_idx)
209687    ,p_event_type_code          => l_array_event_type(hdr_idx)
209688    ,p_event_number             => l_array_event_number(hdr_idx)
209689    ,p_event_date               => l_array_event_date(hdr_idx)
209690    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
209691    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
209692    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
209693    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
209694    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
209695    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
209696    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
209697    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
209698    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
209699    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
209700    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
209701    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
209702    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
209703    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
209704    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
209705 
209706 --
209707 -- set the status of entry to C_VALID (0)
209708 --
209709 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
209710 
209711 --
209712 -- initialize a row for ae header
209713 --
209714 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
209715 
209716 l_event_id := l_array_event_id(hdr_idx);
209717 
209718 --
209719 -- storing the hdr_idx for event. May be used by line cursor.
209720 --
209721 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
209722 
209723 --
209724 -- store sources from header extract. This can be improved to
209725 -- store only those sources from header extract that may be used in lines
209726 --
209727 
209728 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
209729 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
209730 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
209731 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
209732 
209733 --
209734 -- initilaize the status of ae headers for diffrent balance types
209735 -- the status is initialised to C_NOT_CREATED (2)
209736 --
209737 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
209738 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
209739 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
209740 
209741 --
209742 -- call api to validate and store accounting attributes for header
209743 --
209744 
209745 ------------------------------------------------------------
209746 -- Accrual Reversal : to get date for Standard Source (NONE)
209747 ------------------------------------------------------------
209748 l_acc_rev_gl_date_source := NULL;
209749 
209750      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
209751       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
209752      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
209753       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
209754 
209755 
209756 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
209757 
209758 XLA_AE_HEADER_PKG.SetJeCategoryName;
209759 
209760 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
209761 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
209762 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
209763 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
209764 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
209765 
209766 
209767 --
209768 xla_ae_header_pkg.SetHdrDescription(
209769    p_description => Description_16 (
209770    p_application_id => p_application_id 
209771  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
209772    )
209773 );
209774 --
209775 
209776 -- No header level analytical criteria
209777 
209778 --
209779 --accounting attribute enhancement, bug 3612931
209780 --
209781 l_trx_reversal_source := SUBSTR(NULL, 1,30);
209782 
209783 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
209784    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
209785 
209786    xla_accounting_err_pkg.build_message
209787       (p_appli_s_name            => 'XLA'
209788       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
209789       ,p_token_1                 => 'ACCT_ATTR_NAME'
209790       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
209791       ,p_token_2                 => 'PRODUCT_NAME'
209795       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
209792       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
209793       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
209794       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
209796 
209797 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
209798    --
209799    -- following sets the accounting attributes needed to reverse
209800    -- accounting for a distributeion
209801    --
209802    xla_ae_lines_pkg.SetTrxReversalAttrs
209803       (p_event_id              => l_event_id
209804       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
209805       ,p_trx_reversal_source   => l_trx_reversal_source);
209806 
209807 END IF;
209808 
209809 
209810 ----------------------------------------------------------------
209811 -- 4262811 -  update the header statuses to invalid in need be
209812 ----------------------------------------------------------------
209813 --
209814 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
209815 
209816 
209817   -----------------------------------------------
209818   -- No accrual reversal for the event class/type
209819   -----------------------------------------------
209820 ----------------------------------------------------------------
209821 
209822 --
209823 -- this ends the header loop iteration for one bulk fetch
209824 --
209825 END LOOP;
209826 
209827 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
209828 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
209829 
209830 --
209831 -- insert dummy rows into lines gt table that were created due to
209832 -- transaction reversals
209833 --
209834 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
209835    l_result := XLA_AE_LINES_PKG.InsertLines;
209836 END IF;
209837 
209838 --
209839 -- reset the temp_line_num for each set of events fetched from header
209840 -- cursor rather than doing it for each new event in line cursor
209841 -- Bug 3939231
209842 --
209843 xla_ae_lines_pkg.g_temp_line_num := 0;
209844 
209845 
209846 
209847 --
209848 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
209849 --
209850 --
209851 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
209852 
209853       trace
209854          (p_msg      => 'SQL - FETCH line_cur'
209855          ,p_level    => C_LEVEL_STATEMENT
209856          ,p_module   => l_log_module);
209857 
209858 END IF;
209859 --
209860 --
209861 LOOP
209862   --
209863   FETCH line_cur BULK COLLECT INTO
209864         l_array_entity_id
209865       , l_array_legal_entity_id
209866       , l_array_entity_code
209867       , l_array_transaction_num
209868       , l_array_event_id
209869       , l_array_class_code
209870       , l_array_event_type
209871       , l_array_event_number
209872       , l_array_event_date
209873       , l_array_transaction_date
209874       , l_array_reference_num_1
209875       , l_array_reference_num_2
209876       , l_array_reference_num_3
209877       , l_array_reference_num_4
209878       , l_array_reference_char_1
209879       , l_array_reference_char_2
209880       , l_array_reference_char_3
209881       , l_array_reference_char_4
209882       , l_array_reference_date_1
209883       , l_array_reference_date_2
209884       , l_array_reference_date_3
209885       , l_array_reference_date_4
209886       , l_array_event_created_by
209887       , l_array_budgetary_control_flag
209888       , l_array_extract_line_num 
209889       , l_array_source_2
209890       , l_array_source_3
209891       , l_array_source_4
209892       , l_array_source_7
209893       , l_array_source_9
209894       , l_array_source_10
209895       , l_array_source_17
209896       , l_array_source_29
209897       , l_array_source_35
209898       , l_array_source_36
209899       , l_array_source_37
209900       , l_array_source_38
209901       , l_array_source_39
209902       , l_array_source_40
209903       LIMIT l_rows;
209904 
209905   --
209906   IF (C_LEVEL_EVENT >= g_log_level) THEN
209907             trace
209908                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
209909                ,p_level    => C_LEVEL_EVENT
209910                ,p_module   => l_log_module);
209911   END IF;
209912   --
209913   EXIT WHEN l_array_entity_id.count = 0;
209914 
209915   XLA_AE_LINES_PKG.g_rec_lines := null;
209916 
209917 --
209918 -- Bug 4458708
209919 --
209920 XLA_AE_LINES_PKG.g_LineNumber := 0;
209921 --
209922 --
209923 
209924 FOR Idx IN 1..l_array_event_id.count LOOP
209925    --
209926    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
209927    --
209928    l_event_id := l_array_event_id(idx);  -- 5648433
209929 
209930    --
209931    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
209932    --
209933 
209934    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
209935              (g_array_event(l_event_id).array_value_num('header_index'))
209936          ,'N'
209937          ) <> 'Y'
209938    THEN
209939       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
209940          trace
209941             (p_msg      => 'Trancaction revesal option is not Y '
209942             ,p_level    => C_LEVEL_STATEMENT
209943             ,p_module   => l_log_module);
209944       END IF;
209945 
209946 --
209947 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
209948 --
209949 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
209950 --
209954 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
209951 -- set event info as cache for other routines to refer event attributes
209952 --
209953 
209955    l_previous_event_id := l_event_id;
209956 
209957    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
209958       (p_application_id           => p_application_id
209959       ,p_primary_ledger_id        => p_primary_ledger_id
209960       ,p_base_ledger_id           => p_base_ledger_id
209961       ,p_target_ledger_id         => p_target_ledger_id
209962       ,p_entity_id                => l_array_entity_id(Idx)
209963       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
209964       ,p_entity_code              => l_array_entity_code(Idx)
209965       ,p_transaction_num          => l_array_transaction_num(Idx)
209966       ,p_event_id                 => l_array_event_id(Idx)
209967       ,p_event_class_code         => l_array_class_code(Idx)
209968       ,p_event_type_code          => l_array_event_type(Idx)
209969       ,p_event_number             => l_array_event_number(Idx)
209970       ,p_event_date               => l_array_event_date(Idx)
209971       ,p_transaction_date         => l_array_transaction_date(Idx)
209972       ,p_reference_num_1          => l_array_reference_num_1(Idx)
209973       ,p_reference_num_2          => l_array_reference_num_2(Idx)
209974       ,p_reference_num_3          => l_array_reference_num_3(Idx)
209975       ,p_reference_num_4          => l_array_reference_num_4(Idx)
209976       ,p_reference_char_1         => l_array_reference_char_1(Idx)
209977       ,p_reference_char_2         => l_array_reference_char_2(Idx)
209978       ,p_reference_char_3         => l_array_reference_char_3(Idx)
209979       ,p_reference_char_4         => l_array_reference_char_4(Idx)
209980       ,p_reference_date_1         => l_array_reference_date_1(Idx)
209981       ,p_reference_date_2         => l_array_reference_date_2(Idx)
209982       ,p_reference_date_3         => l_array_reference_date_3(Idx)
209983       ,p_reference_date_4         => l_array_reference_date_4(Idx)
209984       ,p_event_created_by         => l_array_event_created_by(Idx)
209985       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
209986        --
209987 END IF;
209988 
209989 
209990 
209991 --
209992 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
209993 
209994 l_acct_reversal_source := SUBSTR(NULL, 1,30);
209995 
209996 IF l_continue_with_lines THEN
209997    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
209998       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
209999 
210000       xla_accounting_err_pkg.build_message
210001          (p_appli_s_name            => 'XLA'
210002          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
210003          ,p_token_1                 => 'LINE_NUMBER'
210004          ,p_value_1                 => l_array_extract_line_num(Idx)
210005          ,p_token_2                 => 'PRODUCT_NAME'
210006          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
210007          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
210008          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
210009          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
210010 
210011    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
210012       --
210013       -- following sets the accounting attributes needed to reverse
210014       -- accounting for a distributeion
210015       --
210016 
210017       --
210018       -- 5217187
210019       --
210020       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
210021       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
210022                                        g_array_event(l_event_id).array_value_num('header_index'));
210023       --
210024       --
210025 
210026       -- No reversal code generated
210027 
210028       xla_ae_lines_pkg.SetAcctReversalAttrs
210029          (p_event_id             => l_event_id
210030          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
210031          ,p_calculate_acctd_flag => l_calculate_acctd_flag
210032          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
210033    END IF;
210034 
210035    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
210036        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
210037 
210038 --
210039 AcctLineType_326 (
210040  p_application_id  => p_application_id
210041  ,p_event_id     => l_event_id
210042  ,p_calculate_acctd_flag => l_calculate_acctd_flag
210043  ,p_calculate_g_l_flag => l_calculate_g_l_flag
210044  ,p_actual_flag => l_actual_flag
210045  ,p_balance_type_code => l_balance_type_code
210046  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
210047  
210048  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
210049  , p_source_3 => l_array_source_3(Idx)
210050  , p_source_7 => l_array_source_7(Idx)
210051  , p_source_29 => l_array_source_29(Idx)
210052  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
210053  , p_source_35 => l_array_source_35(Idx)
210054  , p_source_36 => l_array_source_36(Idx)
210055  , p_source_37 => l_array_source_37(Idx)
210056  , p_source_38 => l_array_source_38(Idx)
210057  , p_source_39 => l_array_source_39(Idx)
210058  , p_source_40 => l_array_source_40(Idx)
210059  );
210060 If(l_balance_type_code = 'A') THEN
210061   l_actual_gain_loss_ref := l_gain_or_loss_ref;
210062 END IF;
210063 
210064 --
210065 
210066 
210067 --
210068 AcctLineType_327 (
210069  p_application_id  => p_application_id
210070  ,p_event_id     => l_event_id
210071  ,p_calculate_acctd_flag => l_calculate_acctd_flag
210072  ,p_calculate_g_l_flag => l_calculate_g_l_flag
210073  ,p_actual_flag => l_actual_flag
210074  ,p_balance_type_code => l_balance_type_code
210075  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
210076  
210080  , p_source_29 => l_array_source_29(Idx)
210077  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
210078  , p_source_3 => l_array_source_3(Idx)
210079  , p_source_9 => l_array_source_9(Idx)
210081  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
210082  , p_source_35 => l_array_source_35(Idx)
210083  , p_source_36 => l_array_source_36(Idx)
210084  , p_source_37 => l_array_source_37(Idx)
210085  , p_source_38 => l_array_source_38(Idx)
210086  , p_source_39 => l_array_source_39(Idx)
210087  , p_source_40 => l_array_source_40(Idx)
210088  );
210089 If(l_balance_type_code = 'A') THEN
210090   l_actual_gain_loss_ref := l_gain_or_loss_ref;
210091 END IF;
210092 
210093 --
210094 
210095 
210096 --
210097 AcctLineType_328 (
210098  p_application_id  => p_application_id
210099  ,p_event_id     => l_event_id
210100  ,p_calculate_acctd_flag => l_calculate_acctd_flag
210101  ,p_calculate_g_l_flag => l_calculate_g_l_flag
210102  ,p_actual_flag => l_actual_flag
210103  ,p_balance_type_code => l_balance_type_code
210104  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
210105  
210106  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
210107  , p_source_3 => l_array_source_3(Idx)
210108  , p_source_29 => l_array_source_29(Idx)
210109  , p_source_35 => l_array_source_35(Idx)
210110  , p_source_36 => l_array_source_36(Idx)
210111  , p_source_37 => l_array_source_37(Idx)
210112  , p_source_38 => l_array_source_38(Idx)
210113  , p_source_39 => l_array_source_39(Idx)
210114  , p_source_40 => l_array_source_40(Idx)
210115  );
210116 If(l_balance_type_code = 'A') THEN
210117   l_actual_gain_loss_ref := l_gain_or_loss_ref;
210118 END IF;
210119 
210120 --
210121 
210122 
210123 --
210124 AcctLineType_329 (
210125  p_application_id  => p_application_id
210126  ,p_event_id     => l_event_id
210127  ,p_calculate_acctd_flag => l_calculate_acctd_flag
210128  ,p_calculate_g_l_flag => l_calculate_g_l_flag
210129  ,p_actual_flag => l_actual_flag
210130  ,p_balance_type_code => l_balance_type_code
210131  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
210132  
210133  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
210134  , p_source_2 => l_array_source_2(Idx)
210135  , p_source_3 => l_array_source_3(Idx)
210136  , p_source_29 => l_array_source_29(Idx)
210137  , p_source_35 => l_array_source_35(Idx)
210138  , p_source_36 => l_array_source_36(Idx)
210139  , p_source_37 => l_array_source_37(Idx)
210140  , p_source_38 => l_array_source_38(Idx)
210141  , p_source_39 => l_array_source_39(Idx)
210142  , p_source_40 => l_array_source_40(Idx)
210143  );
210144 If(l_balance_type_code = 'A') THEN
210145   l_actual_gain_loss_ref := l_gain_or_loss_ref;
210146 END IF;
210147 
210148 --
210149 
210150 
210151 --
210152 AcctLineType_330 (
210153  p_application_id  => p_application_id
210154  ,p_event_id     => l_event_id
210155  ,p_calculate_acctd_flag => l_calculate_acctd_flag
210156  ,p_calculate_g_l_flag => l_calculate_g_l_flag
210157  ,p_actual_flag => l_actual_flag
210158  ,p_balance_type_code => l_balance_type_code
210159  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
210160  
210161  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
210162  , p_source_3 => l_array_source_3(Idx)
210163  , p_source_4 => l_array_source_4(Idx)
210164  , p_source_17 => l_array_source_17(Idx)
210165  , p_source_29 => l_array_source_29(Idx)
210166  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
210167  , p_source_35 => l_array_source_35(Idx)
210168  , p_source_36 => l_array_source_36(Idx)
210169  , p_source_37 => l_array_source_37(Idx)
210170  , p_source_38 => l_array_source_38(Idx)
210171  , p_source_39 => l_array_source_39(Idx)
210172  , p_source_40 => l_array_source_40(Idx)
210173  );
210174 If(l_balance_type_code = 'A') THEN
210175   l_actual_gain_loss_ref := l_gain_or_loss_ref;
210176 END IF;
210177 
210178 --
210179 
210180 
210181 --
210182 AcctLineType_331 (
210183  p_application_id  => p_application_id
210184  ,p_event_id     => l_event_id
210185  ,p_calculate_acctd_flag => l_calculate_acctd_flag
210186  ,p_calculate_g_l_flag => l_calculate_g_l_flag
210187  ,p_actual_flag => l_actual_flag
210188  ,p_balance_type_code => l_balance_type_code
210189  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
210190  
210191  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
210192  , p_source_3 => l_array_source_3(Idx)
210193  , p_source_29 => l_array_source_29(Idx)
210194  , p_source_35 => l_array_source_35(Idx)
210195  , p_source_36 => l_array_source_36(Idx)
210196  , p_source_37 => l_array_source_37(Idx)
210197  , p_source_38 => l_array_source_38(Idx)
210198  , p_source_39 => l_array_source_39(Idx)
210199  , p_source_40 => l_array_source_40(Idx)
210200  );
210201 If(l_balance_type_code = 'A') THEN
210202   l_actual_gain_loss_ref := l_gain_or_loss_ref;
210203 END IF;
210204 
210205 --
210206 
210207 
210208 --
210209 AcctLineType_332 (
210210  p_application_id  => p_application_id
210211  ,p_event_id     => l_event_id
210212  ,p_calculate_acctd_flag => l_calculate_acctd_flag
210213  ,p_calculate_g_l_flag => l_calculate_g_l_flag
210214  ,p_actual_flag => l_actual_flag
210215  ,p_balance_type_code => l_balance_type_code
210216  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
210217  
210218  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
210219  , p_source_3 => l_array_source_3(Idx)
210220  , p_source_10 => l_array_source_10(Idx)
210221  , p_source_17 => l_array_source_17(Idx)
210222  , p_source_29 => l_array_source_29(Idx)
210223  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
210224  , p_source_35 => l_array_source_35(Idx)
210225  , p_source_36 => l_array_source_36(Idx)
210226  , p_source_37 => l_array_source_37(Idx)
210227  , p_source_38 => l_array_source_38(Idx)
210231 If(l_balance_type_code = 'A') THEN
210228  , p_source_39 => l_array_source_39(Idx)
210229  , p_source_40 => l_array_source_40(Idx)
210230  );
210232   l_actual_gain_loss_ref := l_gain_or_loss_ref;
210233 END IF;
210234 
210235 --
210236 
210237 
210238 --
210239 AcctLineType_333 (
210240  p_application_id  => p_application_id
210241  ,p_event_id     => l_event_id
210242  ,p_calculate_acctd_flag => l_calculate_acctd_flag
210243  ,p_calculate_g_l_flag => l_calculate_g_l_flag
210244  ,p_actual_flag => l_actual_flag
210245  ,p_balance_type_code => l_balance_type_code
210246  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
210247  
210248  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
210249  , p_source_3 => l_array_source_3(Idx)
210250  , p_source_10 => l_array_source_10(Idx)
210251  , p_source_17 => l_array_source_17(Idx)
210252  , p_source_29 => l_array_source_29(Idx)
210253  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
210254  , p_source_35 => l_array_source_35(Idx)
210255  , p_source_36 => l_array_source_36(Idx)
210256  , p_source_37 => l_array_source_37(Idx)
210257  , p_source_38 => l_array_source_38(Idx)
210258  , p_source_39 => l_array_source_39(Idx)
210259  , p_source_40 => l_array_source_40(Idx)
210260  );
210261 If(l_balance_type_code = 'A') THEN
210262   l_actual_gain_loss_ref := l_gain_or_loss_ref;
210263 END IF;
210264 
210265 --
210266 
210267       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
210268       -- or secondary ledger that has different currency with primary
210269       -- or alc that is calculated by sla
210270       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
210271             (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'))
210272 
210273 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
210274 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
210275           AND (l_actual_flag = 'A')) THEN
210276         XLA_AE_LINES_PKG.CreateGainOrLossLines(
210277           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
210278          ,p_application_id   => p_application_id
210279          ,p_amb_context_code => 'DEFAULT'
210280          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
210281          ,p_event_class_code => C_EVENT_CLASS_CODE
210282          ,p_event_type_code  => C_EVENT_TYPE_CODE
210283          
210284          ,p_gain_ccid        => -1
210285          ,p_loss_ccid        => -1
210286 
210287          ,p_actual_flag      => l_actual_flag
210288          ,p_enc_flag         => null
210289          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
210290          ,p_enc_g_l_ref      => null
210291          );
210292       END IF;
210293    END IF;
210294 END IF;
210295 
210296    ELSE
210297       --
210298       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
210299       --
210300       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
210301          trace
210302             (p_msg      => 'Trancaction revesal option is Y'
210303             ,p_level    => C_LEVEL_STATEMENT
210304             ,p_module   => l_log_module);
210305       END IF;
210306    END IF;
210307 
210308 END LOOP;
210309 l_result := XLA_AE_LINES_PKG.InsertLines ;
210310 end loop;
210311 close line_cur;
210312 
210313 
210314 --
210315 -- insert headers into xla_ae_headers_gt table
210316 --
210317 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
210318 
210319 -- insert into errors table here.
210320 
210321 END LOOP;
210322 
210323 --
210324 -- 4865292
210325 --
210326 -- Compare g_hdr_extract_count with event count in
210327 -- CreateHeadersAndLines.
210328 --
210329 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
210330 
210331 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
210332    trace (p_msg     => '# rows extracted from header extract objects '
210333                     || ' (running total): '
210334                     || g_hdr_extract_count
210335          ,p_level   => C_LEVEL_STATEMENT
210336          ,p_module  => l_log_module);
210337 END IF;
210338 
210339 CLOSE header_cur;
210340 --
210341 
210342 --
210343 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
210344    trace
210345       (p_msg      => 'END of EventType_428'
210346       ,p_level    => C_LEVEL_PROCEDURE
210347       ,p_module   => l_log_module);
210348 END IF;
210349 --
210350 RETURN l_result;
210351 EXCEPTION
210352 WHEN xla_exceptions_pkg.application_exception THEN
210353    
210354 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
210355 
210356    
210357 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
210358 
210359    RAISE;
210360 
210361 WHEN NO_DATA_FOUND THEN
210362 
210363 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
210364 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
210365 
210366 FOR header_record IN header_cur
210367 LOOP
210368     l_array_header_events(header_record.event_id) := header_record.event_id;
210369 END LOOP;
210370 
210371 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
210372 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
210373 
210374 fnd_file.put_line(fnd_file.LOG, '                    ');
210375 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
210376 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
210377 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
210378 
210379 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
210380 LOOP
210384 	END IF;
210381 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
210382 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
210383         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
210385 END LOOP;
210386 
210387 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
210388 fnd_file.put_line(fnd_file.LOG, '                    ');
210389 
210390 
210391 xla_exceptions_pkg.raise_message
210392       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_428');
210393 
210394 
210395 WHEN OTHERS THEN
210396    xla_exceptions_pkg.raise_message
210397       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventType_428');
210398 END EventType_428;
210399 --
210400 
210401 ---------------------------------------
210402 --
210403 -- PRIVATE PROCEDURE
210404 --         insert_sources_429
210405 --
210406 ----------------------------------------
210407 --
210408 PROCEDURE insert_sources_429(
210409                                 p_target_ledger_id       IN NUMBER
210410                               , p_language               IN VARCHAR2
210411                               , p_sla_ledger_id          IN NUMBER
210412                               , p_pad_start_date         IN DATE
210413                               , p_pad_end_date           IN DATE
210414                          )
210415 IS
210416 
210417 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'SOURCE_LINE_TRANSFERS_ALL';
210418 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'SOURCE_LINE_TRANSFERS';
210419 p_apps_owner                   VARCHAR2(30);
210420 l_log_module                   VARCHAR2(240);
210421 BEGIN
210422 IF g_log_enabled THEN
210423       l_log_module := C_DEFAULT_MODULE||'.insert_sources_429';
210424 END IF;
210425 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
210426 
210427       trace
210428          (p_msg      => 'BEGIN of insert_sources_429'
210429          ,p_level    => C_LEVEL_PROCEDURE
210430          ,p_module   => l_log_module);
210431 
210432 END IF;
210433 
210434 -- select APPS owner
210435 SELECT oracle_username
210436   INTO p_apps_owner
210437   FROM fnd_oracle_userid
210438  WHERE read_only_flag = 'U'
210439 ;
210440 
210441 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
210442       trace
210443          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
210444                         ' - p_language = '||p_language||
210445                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
210446                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
210447                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
210448                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
210449          ,p_level    => C_LEVEL_STATEMENT
210450          ,p_module   => l_log_module);
210451 END IF;
210452 
210453 
210454 --
210455 INSERT INTO xla_diag_sources --hdr2
210456 (
210457         event_id
210458       , ledger_id
210459       , sla_ledger_id
210460       , description_language
210461       , object_name
210462       , object_type_code
210463       , line_number
210464       , source_application_id
210465       , source_type_code
210466       , source_code
210467       , source_value
210468       , source_meaning
210469       , created_by
210470       , creation_date
210471       , last_update_date
210472       , last_updated_by
210473       , last_update_login
210474       , program_update_date
210475       , program_application_id
210476       , program_id
210477       , request_id
210478 )
210479 SELECT
210480         event_id
210481       , p_target_ledger_id
210482       , p_sla_ledger_id
210483       , p_language
210484       , object_name
210485       , object_type_code
210486       , line_number
210487       , source_application_id
210488       , source_type_code
210489       , source_code
210490       , SUBSTR(source_value ,1,1996)
210491       , SUBSTR(source_meaning ,1,200)
210492       , xla_environment_pkg.g_Usr_Id
210493       , TRUNC(SYSDATE)
210494       , TRUNC(SYSDATE)
210495       , xla_environment_pkg.g_Usr_Id
210496       , xla_environment_pkg.g_Login_Id
210497       , TRUNC(SYSDATE)
210498       , xla_environment_pkg.g_Prog_Appl_Id
210499       , xla_environment_pkg.g_Prog_Id
210500       , xla_environment_pkg.g_Req_Id
210501   FROM (
210502        SELECT xet.event_id                  event_id
210503             , 0                          line_number
210504             , CASE r
210505                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
210506                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
210507                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
210508                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
210509                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
210510                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
210511                 
210512                ELSE null
210513               END                           object_name
210514             , CASE r
210515                 WHEN 1 THEN 'HEADER' 
210516                 WHEN 2 THEN 'HEADER' 
210517                 WHEN 3 THEN 'HEADER' 
210518                 WHEN 4 THEN 'HEADER' 
210519                 WHEN 5 THEN 'HEADER' 
210520                 WHEN 6 THEN 'HEADER' 
210521                 
210522                 ELSE null
210523               END                           object_type_code
210524             , CASE r
210525                 WHEN 1 THEN '140' 
210526                 WHEN 2 THEN '140' 
210527                 WHEN 3 THEN '140' 
210528                 WHEN 4 THEN '140' 
210529                 WHEN 5 THEN '140' 
210530                 WHEN 6 THEN '140' 
210531                 
210532                 ELSE null
210536                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
210533               END                           source_application_id
210534             , 'S'             source_type_code
210535             , CASE r
210537                 WHEN 2 THEN 'AP_INTERCOMPANY_ACCT' 
210538                 WHEN 3 THEN 'AR_INTERCOMPANY_ACCT' 
210539                 WHEN 4 THEN 'DEFAULT_CCID' 
210540                 WHEN 5 THEN 'ACCOUNTING_DATE' 
210541                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
210542                 
210543                 ELSE null
210544               END                           source_code
210545             , CASE r
210546                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
210547                 WHEN 2 THEN TO_CHAR(h1.AP_INTERCOMPANY_ACCT)
210548                 WHEN 3 THEN TO_CHAR(h1.AR_INTERCOMPANY_ACCT)
210549                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
210550                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
210551                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
210552                 
210553                 ELSE null
210554               END                           source_value
210555             , null              source_meaning
210556          FROM xla_events_gt     xet  
210557       , FA_XLA_EXT_HEADERS_B_GT  h1
210558              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
210559          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
210560            AND xet.event_class_code = C_EVENT_CLASS_CODE
210561               AND h1.event_id = xet.event_id
210562 
210563 )
210564 ;
210565 --
210566 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
210567 
210568       trace
210569          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
210570          ,p_level    => C_LEVEL_STATEMENT
210571          ,p_module   => l_log_module);
210572 
210573 END IF;
210574 --
210575 
210576 
210577 
210578 --
210579 INSERT INTO xla_diag_sources  --line2
210580 (
210581         event_id
210582       , ledger_id
210583       , sla_ledger_id
210584       , description_language
210585       , object_name
210586       , object_type_code
210587       , line_number
210588       , source_application_id
210589       , source_type_code
210590       , source_code
210591       , source_value
210592       , source_meaning
210593       , created_by
210594       , creation_date
210595       , last_update_date
210596       , last_updated_by
210597       , last_update_login
210598       , program_update_date
210599       , program_application_id
210600       , program_id
210601       , request_id
210602 )
210603 SELECT  event_id
210604       , p_target_ledger_id
210605       , p_sla_ledger_id
210606       , p_language
210607       , object_name
210608       , object_type_code
210609       , line_number
210610       , source_application_id
210611       , source_type_code
210612       , source_code
210613       , SUBSTR(source_value,1,1996)
210614       , SUBSTR(source_meaning ,1,200)
210615       , xla_environment_pkg.g_Usr_Id
210616       , TRUNC(SYSDATE)
210617       , TRUNC(SYSDATE)
210618       , xla_environment_pkg.g_Usr_Id
210619       , xla_environment_pkg.g_Login_Id
210620       , TRUNC(SYSDATE)
210621       , xla_environment_pkg.g_Prog_Appl_Id
210622       , xla_environment_pkg.g_Prog_Id
210623       , xla_environment_pkg.g_Req_Id
210624   FROM (
210625        SELECT xet.event_id                  event_id
210626             , l2.line_number                 line_number
210627             , CASE r
210628                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
210629                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
210630                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
210631                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
210632                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
210633                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
210634                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
210635                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
210636                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
210637                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
210638                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
210639                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
210640                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
210641                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
210642                 WHEN 15 THEN 'FA_XLA_EXT_LINES_B_GT' 
210643                 WHEN 16 THEN 'FA_XLA_EXT_LINES_B_GT' 
210644                 WHEN 17 THEN 'FA_XLA_EXT_LINES_B_GT' 
210645                 WHEN 18 THEN 'FA_XLA_EXT_LINES_B_GT' 
210646                 
210647                ELSE null
210648               END                           object_name
210649             , CASE r
210650                 WHEN 1 THEN 'LINE' 
210651                 WHEN 2 THEN 'LINE' 
210652                 WHEN 3 THEN 'LINE' 
210653                 WHEN 4 THEN 'LINE' 
210654                 WHEN 5 THEN 'LINE' 
210655                 WHEN 6 THEN 'LINE' 
210656                 WHEN 7 THEN 'LINE' 
210657                 WHEN 8 THEN 'LINE' 
210658                 WHEN 9 THEN 'LINE' 
210659                 WHEN 10 THEN 'LINE' 
210660                 WHEN 11 THEN 'LINE' 
210661                 WHEN 12 THEN 'LINE' 
210662                 WHEN 13 THEN 'LINE' 
210663                 WHEN 14 THEN 'LINE' 
210664                 WHEN 15 THEN 'LINE' 
210665                 WHEN 16 THEN 'LINE' 
210666                 WHEN 17 THEN 'LINE' 
210667                 WHEN 18 THEN 'LINE' 
210668                 
210669                 ELSE null
210670               END                           object_type_code
210671             , CASE r
210672                 WHEN 1 THEN '140' 
210673                 WHEN 2 THEN '140' 
210674                 WHEN 3 THEN '140' 
210675                 WHEN 4 THEN '140' 
210676                 WHEN 5 THEN '140' 
210677                 WHEN 6 THEN '140' 
210681                 WHEN 10 THEN '140' 
210678                 WHEN 7 THEN '140' 
210679                 WHEN 8 THEN '140' 
210680                 WHEN 9 THEN '140' 
210682                 WHEN 11 THEN '140' 
210683                 WHEN 12 THEN '140' 
210684                 WHEN 13 THEN '140' 
210685                 WHEN 14 THEN '140' 
210686                 WHEN 15 THEN '140' 
210687                 WHEN 16 THEN '140' 
210688                 WHEN 17 THEN '140' 
210689                 WHEN 18 THEN '140' 
210690                 
210691                 ELSE null
210692               END                           source_application_id
210693             , 'S'             source_type_code
210694             , CASE r
210695                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
210696                 WHEN 2 THEN 'GENERATED_CCID' 
210697                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
210698                 WHEN 4 THEN 'PAYABLES_CCID' 
210699                 WHEN 5 THEN 'CIP_COST_ACCT' 
210700                 WHEN 6 THEN 'ASSET_CLEARING_ACCT' 
210701                 WHEN 7 THEN 'ASSET_COST_ACCT' 
210702                 WHEN 8 THEN 'DEPRN_RESERVE_ACCT' 
210703                 WHEN 9 THEN 'REVAL_RESERVE_ACCT' 
210704                 WHEN 10 THEN 'GENERATED_OFFSET_CCID' 
210705                 WHEN 11 THEN 'EXPENSE_ACCOUNT_CCID' 
210706                 WHEN 12 THEN 'ADJUSTMENT_TYPE' 
210707                 WHEN 13 THEN 'TRANSACTION_HEADER_ID' 
210708                 WHEN 14 THEN 'ADJUSTMENT_LINE_ID' 
210709                 WHEN 15 THEN 'DISTRIBUTION_TYPE_CODE' 
210710                 WHEN 16 THEN 'ENTERED_AMOUNT' 
210711                 WHEN 17 THEN 'CURRENCY_CODE' 
210712                 WHEN 18 THEN 'SOURCE_DEST_CODE' 
210713                 
210714                 ELSE null
210715               END                           source_code
210716             , CASE r
210717                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
210718                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
210719                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
210720                 WHEN 4 THEN TO_CHAR(l2.PAYABLES_CCID)
210721                 WHEN 5 THEN TO_CHAR(l2.CIP_COST_ACCT)
210722                 WHEN 6 THEN TO_CHAR(l2.ASSET_CLEARING_ACCT)
210723                 WHEN 7 THEN TO_CHAR(l2.ASSET_COST_ACCT)
210724                 WHEN 8 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
210725                 WHEN 9 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
210726                 WHEN 10 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
210727                 WHEN 11 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
210728                 WHEN 12 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
210729                 WHEN 13 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
210730                 WHEN 14 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
210731                 WHEN 15 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
210732                 WHEN 16 THEN TO_CHAR(l2.ENTERED_AMOUNT)
210733                 WHEN 17 THEN TO_CHAR(l2.CURRENCY_CODE)
210734                 WHEN 18 THEN TO_CHAR(l2.SOURCE_DEST_CODE)
210735                 
210736                 ELSE null
210737               END                           source_value
210738             , null              source_meaning
210739          FROM  xla_events_gt     xet  
210740         , FA_XLA_EXT_LINES_B_GT  l2
210741             , (select rownum r from all_objects where rownum <= 18 and owner = p_apps_owner)
210742         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
210743           AND xet.event_class_code = C_EVENT_CLASS_CODE
210744             AND l2.event_id          = xet.event_id
210745   AND l2.ledger_id (+)  = p_sla_ledger_id
210746 
210747 )
210748 ;
210749 --
210750 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
210751 
210752       trace
210753          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
210754          ,p_level    => C_LEVEL_STATEMENT
210755          ,p_module   => l_log_module);
210756 
210757 END IF;
210758 
210759 
210760 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
210761       trace
210762          (p_msg      => 'END of insert_sources_429'
210763          ,p_level    => C_LEVEL_PROCEDURE
210764          ,p_module   => l_log_module);
210765 END IF;
210766 EXCEPTION
210767   WHEN xla_exceptions_pkg.application_exception THEN
210768       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
210769             trace
210770                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
210771                ,p_level    => C_LEVEL_EXCEPTION
210772                ,p_module   => l_log_module);
210773       END IF;
210774       RAISE;
210775   WHEN OTHERS THEN
210776       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
210777             trace
210778                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
210779                ,p_level    => C_LEVEL_EXCEPTION
210780                ,p_module   => l_log_module);
210781        END IF;
210782        xla_exceptions_pkg.raise_message
210783            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_429');
210784 END insert_sources_429;
210785 --
210786 
210787 ---------------------------------------
210788 --
210789 -- PRIVATE FUNCTION
210790 --         EventClass_429
210791 --
210792 ----------------------------------------
210793 --
210794 FUNCTION EventClass_429
210795        (p_application_id         IN NUMBER
210796        ,p_base_ledger_id         IN NUMBER
210797        ,p_target_ledger_id       IN NUMBER
210798        ,p_language               IN VARCHAR2
210799        ,p_currency_code          IN VARCHAR2
210800        ,p_sla_ledger_id          IN NUMBER
210801        ,p_pad_start_date         IN DATE
210802        ,p_pad_end_date           IN DATE
210803        ,p_primary_ledger_id      IN NUMBER)
210804 RETURN BOOLEAN IS
210805 --
210806 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'SOURCE_LINE_TRANSFERS_ALL';
210807 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'SOURCE_LINE_TRANSFERS';
210808 
210809 l_calculate_acctd_flag   VARCHAR2(1) :='N';
210813 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
210810 l_calculate_g_l_flag     VARCHAR2(1) :='N';
210811 --
210812 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
210814 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
210815 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
210816 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
210817 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
210818 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
210819 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
210820 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
210821 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
210822 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
210823 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
210824 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
210825 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
210826 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
210827 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
210828 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
210829 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
210830 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
210831 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
210832 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
210833 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
210834 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
210835 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
210836 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
210837 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
210838 
210839 l_event_id                             NUMBER;
210840 l_previous_event_id                    NUMBER;
210841 l_first_event_id                       NUMBER;
210842 l_last_event_id                        NUMBER;
210843 
210844 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
210845 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
210846 --
210847 --
210848 l_result                    BOOLEAN := TRUE;
210849 l_rows                      NUMBER  := 1000;
210850 l_event_type_name           VARCHAR2(80) := 'All';
210851 l_event_class_name          VARCHAR2(80) := 'Source Line Transfers';
210852 l_description               VARCHAR2(4000);
210853 l_transaction_reversal      NUMBER;
210854 l_ae_header_id              NUMBER;
210855 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
210856 l_log_module                VARCHAR2(240);
210857 --
210858 l_acct_reversal_source      VARCHAR2(30);
210859 l_trx_reversal_source       VARCHAR2(30);
210860 
210861 l_continue_with_lines       BOOLEAN := TRUE;
210862 --
210863 l_acc_rev_gl_date_source    DATE;                      -- 4262811
210864 --
210865 type t_array_event_id is table of number index by binary_integer;
210866 
210867 l_rec_array_event                    t_rec_array_event;
210868 l_null_rec_array_event               t_rec_array_event;
210869 l_array_ae_header_id                 xla_number_array_type;
210870 l_actual_flag                        VARCHAR2(1) := NULL;
210871 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
210872 l_balance_type_code                  VARCHAR2(1) :=NULL;
210873 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
210874 
210875 --
210876 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
210877 --
210878 
210879 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
210880 TYPE t_array_source_19 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AP_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
210881 TYPE t_array_source_20 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AR_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
210882 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
210883 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
210884 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
210885 
210886 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
210887 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
210888 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
210889 TYPE t_array_source_6 IS TABLE OF FA_XLA_EXT_LINES_B_GT.PAYABLES_CCID%TYPE INDEX BY BINARY_INTEGER;
210890 TYPE t_array_source_7 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CIP_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
210891 TYPE t_array_source_8 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_CLEARING_ACCT%TYPE INDEX BY BINARY_INTEGER;
210892 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
210893 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
210894 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
210895 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
210896 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
210897 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
210898 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
210899 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
210903 TYPE t_array_source_42 IS TABLE OF FA_XLA_EXT_LINES_B_GT.SOURCE_DEST_CODE%TYPE INDEX BY BINARY_INTEGER;
210900 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
210901 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
210902 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
210904 
210905 l_array_source_1              t_array_source_1;
210906 l_array_source_19              t_array_source_19;
210907 l_array_source_20              t_array_source_20;
210908 l_array_source_30              t_array_source_30;
210909 l_array_source_51              t_array_source_51;
210910 l_array_source_52              t_array_source_52;
210911 
210912 l_array_source_2      t_array_source_2;
210913 l_array_source_3      t_array_source_3;
210914 l_array_source_4      t_array_source_4;
210915 l_array_source_6      t_array_source_6;
210916 l_array_source_7      t_array_source_7;
210917 l_array_source_8      t_array_source_8;
210918 l_array_source_9      t_array_source_9;
210919 l_array_source_10      t_array_source_10;
210920 l_array_source_11      t_array_source_11;
210921 l_array_source_17      t_array_source_17;
210922 l_array_source_29      t_array_source_29;
210923 l_array_source_35      t_array_source_35;
210924 l_array_source_36      t_array_source_36;
210925 l_array_source_37      t_array_source_37;
210926 l_array_source_38      t_array_source_38;
210927 l_array_source_39      t_array_source_39;
210928 l_array_source_40      t_array_source_40;
210929 l_array_source_42      t_array_source_42;
210930 
210931 --
210932 CURSOR header_cur
210933 IS
210934 SELECT /*+ leading(xet) cardinality(xet,1) */
210935 -- Event Class Code: SOURCE_LINE_TRANSFERS
210936     xet.entity_id
210937    ,xet.legal_entity_id
210938    ,xet.entity_code
210939    ,xet.transaction_number
210940    ,xet.event_id
210941    ,xet.event_class_code
210942    ,xet.event_type_code
210943    ,xet.event_number
210944    ,xet.event_date
210945    ,xet.transaction_date
210946    ,xet.reference_num_1
210947    ,xet.reference_num_2
210948    ,xet.reference_num_3
210949    ,xet.reference_num_4
210950    ,xet.reference_char_1
210951    ,xet.reference_char_2
210952    ,xet.reference_char_3
210953    ,xet.reference_char_4
210954    ,xet.reference_date_1
210955    ,xet.reference_date_2
210956    ,xet.reference_date_3
210957    ,xet.reference_date_4
210958    ,xet.event_created_by
210959    ,xet.budgetary_control_flag 
210960   , h1.PERIOD_CLOSE_DATE    source_1
210961   , h1.AP_INTERCOMPANY_ACCT    source_19
210962   , h1.AR_INTERCOMPANY_ACCT    source_20
210963   , h1.DEFAULT_CCID    source_30
210964   , h1.ACCOUNTING_DATE    source_51
210965   , h1.TRANSFER_TO_GL_FLAG    source_52
210966   FROM xla_events_gt     xet 
210967   , FA_XLA_EXT_HEADERS_B_GT  h1
210968  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
210969    and xet.event_class_code = C_EVENT_CLASS_CODE
210970    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
210971 
210972  ORDER BY event_id
210973 ;
210974 
210975 
210976 --
210977 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
210978 IS
210979 SELECT  /*+ leading(xet) cardinality(xet,1) */
210980 -- Event Class Code: SOURCE_LINE_TRANSFERS
210981     xet.entity_id
210982    ,xet.legal_entity_id
210983    ,xet.entity_code
210984    ,xet.transaction_number
210985    ,xet.event_id
210986    ,xet.event_class_code
210987    ,xet.event_type_code
210988    ,xet.event_number
210989    ,xet.event_date
210990    ,xet.transaction_date
210991    ,xet.reference_num_1
210992    ,xet.reference_num_2
210993    ,xet.reference_num_3
210994    ,xet.reference_num_4
210995    ,xet.reference_char_1
210996    ,xet.reference_char_2
210997    ,xet.reference_char_3
210998    ,xet.reference_char_4
210999    ,xet.reference_date_1
211000    ,xet.reference_date_2
211001    ,xet.reference_date_3
211002    ,xet.reference_date_4
211003    ,xet.event_created_by
211004    ,xet.budgetary_control_flag
211005  , l2.LINE_NUMBER  
211006   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
211007   , l2.GENERATED_CCID    source_3
211008   , l2.BONUS_RESERVE_ACCT    source_4
211009   , l2.PAYABLES_CCID    source_6
211010   , l2.CIP_COST_ACCT    source_7
211011   , l2.ASSET_CLEARING_ACCT    source_8
211012   , l2.ASSET_COST_ACCT    source_9
211013   , l2.DEPRN_RESERVE_ACCT    source_10
211014   , l2.REVAL_RESERVE_ACCT    source_11
211015   , l2.GENERATED_OFFSET_CCID    source_17
211016   , l2.EXPENSE_ACCOUNT_CCID    source_29
211017   , l2.ADJUSTMENT_TYPE    source_35
211018   , l2.TRANSACTION_HEADER_ID    source_36
211019   , l2.ADJUSTMENT_LINE_ID    source_37
211020   , l2.DISTRIBUTION_TYPE_CODE    source_38
211021   , l2.ENTERED_AMOUNT    source_39
211022   , l2.CURRENCY_CODE    source_40
211023   , l2.SOURCE_DEST_CODE    source_42
211024   FROM xla_events_gt     xet 
211025   , FA_XLA_EXT_LINES_B_GT  l2
211026  WHERE xet.event_id between x_first_event_id and x_last_event_id
211027    and xet.event_date between p_pad_start_date and p_pad_end_date
211028    and xet.event_class_code = C_EVENT_CLASS_CODE
211029    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
211030   AND l2.ledger_id = p_sla_ledger_id
211031 ;
211032 
211033 --
211034 BEGIN
211035 IF g_log_enabled THEN
211036    l_log_module := C_DEFAULT_MODULE||'.EventClass_429';
211037 END IF;
211038 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
211039    trace
211040       (p_msg      => 'BEGIN of EventClass_429'
211041       ,p_level    => C_LEVEL_PROCEDURE
211042       ,p_module   => l_log_module);
211043 END IF;
211044 
211045 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
211046    trace
211047       (p_msg      => 'p_application_id = '||p_application_id||
211048                      ' - p_base_ledger_id = '||p_base_ledger_id||
211052                      ' - p_sla_ledger_id = '||p_sla_ledger_id
211049                      ' - p_target_ledger_id  = '||p_target_ledger_id||
211050                      ' - p_language = '||p_language||
211051                      ' - p_currency_code = '||p_currency_code||
211053       ,p_level    => C_LEVEL_STATEMENT
211054       ,p_module   => l_log_module);
211055 END IF;
211056 --
211057 -- initialze arrays
211058 --
211059 g_array_event.DELETE;
211060 l_rec_array_event := l_null_rec_array_event;
211061 --
211062 --------------------------------------
211063 -- 4262811 Initialze MPA Line Number
211064 --------------------------------------
211065 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
211066 
211067 --
211068 
211069 --
211070 OPEN header_cur;
211071 --
211072 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
211073    trace
211074    (p_msg      => 'SQL - FETCH header_cur'
211075    ,p_level    => C_LEVEL_STATEMENT
211076    ,p_module   => l_log_module);
211077 END IF;
211078 --
211079 LOOP
211080 FETCH header_cur BULK COLLECT INTO
211081         l_array_entity_id
211082       , l_array_legal_entity_id
211083       , l_array_entity_code
211084       , l_array_transaction_num
211085       , l_array_event_id
211086       , l_array_class_code
211087       , l_array_event_type
211088       , l_array_event_number
211089       , l_array_event_date
211090       , l_array_transaction_date
211091       , l_array_reference_num_1
211092       , l_array_reference_num_2
211093       , l_array_reference_num_3
211094       , l_array_reference_num_4
211095       , l_array_reference_char_1
211096       , l_array_reference_char_2
211097       , l_array_reference_char_3
211098       , l_array_reference_char_4
211099       , l_array_reference_date_1
211100       , l_array_reference_date_2
211101       , l_array_reference_date_3
211102       , l_array_reference_date_4
211103       , l_array_event_created_by
211104       , l_array_budgetary_control_flag 
211105       , l_array_source_1
211106       , l_array_source_19
211107       , l_array_source_20
211108       , l_array_source_30
211109       , l_array_source_51
211110       , l_array_source_52
211111       LIMIT l_rows;
211112 --
211113 IF (C_LEVEL_EVENT >= g_log_level) THEN
211114    trace
211115    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
211116    ,p_level    => C_LEVEL_EVENT
211117    ,p_module   => l_log_module);
211118 END IF;
211119 --
211120 EXIT WHEN l_array_entity_id.COUNT = 0;
211121 
211122 -- initialize arrays
211123 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
211124 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
211125 
211126 --
211127 -- Bug 4458708
211128 --
211129 XLA_AE_LINES_PKG.g_LineNumber := 0;
211130 
211131 
211132 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
211133 g_last_hdr_idx := l_array_event_id.LAST;
211134 --
211135 -- loop for the headers. Each iteration is for each header extract row
211136 -- fetched in header cursor
211137 --
211138 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
211139 
211140 --
211141 -- set event info as cache for other routines to refer event attributes
211142 --
211143 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
211144    (p_application_id           => p_application_id
211145    ,p_primary_ledger_id        => p_primary_ledger_id
211146    ,p_base_ledger_id           => p_base_ledger_id
211147    ,p_target_ledger_id         => p_target_ledger_id
211148    ,p_entity_id                => l_array_entity_id(hdr_idx)
211149    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
211150    ,p_entity_code              => l_array_entity_code(hdr_idx)
211151    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
211152    ,p_event_id                 => l_array_event_id(hdr_idx)
211153    ,p_event_class_code         => l_array_class_code(hdr_idx)
211154    ,p_event_type_code          => l_array_event_type(hdr_idx)
211155    ,p_event_number             => l_array_event_number(hdr_idx)
211156    ,p_event_date               => l_array_event_date(hdr_idx)
211157    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
211158    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
211159    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
211160    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
211161    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
211162    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
211163    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
211164    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
211165    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
211166    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
211167    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
211168    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
211169    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
211170    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
211171    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
211172 
211173 --
211174 -- set the status of entry to C_VALID (0)
211175 --
211176 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
211177 
211178 --
211179 -- initialize a row for ae header
211180 --
211181 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
211182 
211183 l_event_id := l_array_event_id(hdr_idx);
211184 
211185 --
211186 -- storing the hdr_idx for event. May be used by line cursor.
211187 --
211188 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
211189 
211190 --
211191 -- store sources from header extract. This can be improved to
211192 -- store only those sources from header extract that may be used in lines
211193 --
211197 g_array_event(l_event_id).array_value_char('source_20') := l_array_source_20(hdr_idx);
211194 
211195 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
211196 g_array_event(l_event_id).array_value_char('source_19') := l_array_source_19(hdr_idx);
211198 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
211199 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
211200 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
211201 
211202 --
211203 -- initilaize the status of ae headers for diffrent balance types
211204 -- the status is initialised to C_NOT_CREATED (2)
211205 --
211206 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
211207 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
211208 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
211209 
211210 --
211211 -- call api to validate and store accounting attributes for header
211212 --
211213 
211214 ------------------------------------------------------------
211215 -- Accrual Reversal : to get date for Standard Source (NONE)
211216 ------------------------------------------------------------
211217 l_acc_rev_gl_date_source := NULL;
211218 
211219      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
211220       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
211221      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
211222       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
211223 
211224 
211225 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
211226 
211227 XLA_AE_HEADER_PKG.SetJeCategoryName;
211228 
211229 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
211230 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
211231 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
211232 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
211233 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
211234 
211235 
211236 --
211237 xla_ae_header_pkg.SetHdrDescription(
211238    p_description => Description_117 (
211239    p_application_id => p_application_id 
211240  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211241    )
211242 );
211243 --
211244 
211245 -- No header level analytical criteria
211246 
211247 --
211248 --accounting attribute enhancement, bug 3612931
211249 --
211250 l_trx_reversal_source := SUBSTR(NULL, 1,30);
211251 
211252 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
211253    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
211254 
211255    xla_accounting_err_pkg.build_message
211256       (p_appli_s_name            => 'XLA'
211257       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
211258       ,p_token_1                 => 'ACCT_ATTR_NAME'
211259       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
211260       ,p_token_2                 => 'PRODUCT_NAME'
211261       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
211262       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
211263       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
211264       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
211265 
211266 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
211267    --
211268    -- following sets the accounting attributes needed to reverse
211269    -- accounting for a distributeion
211270    --
211271    xla_ae_lines_pkg.SetTrxReversalAttrs
211272       (p_event_id              => l_event_id
211273       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
211274       ,p_trx_reversal_source   => l_trx_reversal_source);
211275 
211276 END IF;
211277 
211278 
211279 ----------------------------------------------------------------
211280 -- 4262811 -  update the header statuses to invalid in need be
211281 ----------------------------------------------------------------
211282 --
211283 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
211284 
211285 
211286   -----------------------------------------------
211287   -- No accrual reversal for the event class/type
211288   -----------------------------------------------
211289 ----------------------------------------------------------------
211290 
211291 --
211292 -- this ends the header loop iteration for one bulk fetch
211293 --
211294 END LOOP;
211295 
211296 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
211297 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
211298 
211299 --
211300 -- insert dummy rows into lines gt table that were created due to
211301 -- transaction reversals
211302 --
211303 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
211304    l_result := XLA_AE_LINES_PKG.InsertLines;
211305 END IF;
211306 
211307 --
211308 -- reset the temp_line_num for each set of events fetched from header
211309 -- cursor rather than doing it for each new event in line cursor
211310 -- Bug 3939231
211311 --
211312 xla_ae_lines_pkg.g_temp_line_num := 0;
211313 
211314 
211315 
211316 --
211317 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
211318 --
211319 --
211320 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
211321 
211322       trace
211323          (p_msg      => 'SQL - FETCH line_cur'
211324          ,p_level    => C_LEVEL_STATEMENT
211325          ,p_module   => l_log_module);
211329 --
211326 
211327 END IF;
211328 --
211330 LOOP
211331   --
211332   FETCH line_cur BULK COLLECT INTO
211333         l_array_entity_id
211334       , l_array_legal_entity_id
211335       , l_array_entity_code
211336       , l_array_transaction_num
211337       , l_array_event_id
211338       , l_array_class_code
211339       , l_array_event_type
211340       , l_array_event_number
211341       , l_array_event_date
211342       , l_array_transaction_date
211343       , l_array_reference_num_1
211344       , l_array_reference_num_2
211345       , l_array_reference_num_3
211346       , l_array_reference_num_4
211347       , l_array_reference_char_1
211348       , l_array_reference_char_2
211349       , l_array_reference_char_3
211350       , l_array_reference_char_4
211351       , l_array_reference_date_1
211352       , l_array_reference_date_2
211353       , l_array_reference_date_3
211354       , l_array_reference_date_4
211355       , l_array_event_created_by
211356       , l_array_budgetary_control_flag
211357       , l_array_extract_line_num 
211358       , l_array_source_2
211359       , l_array_source_3
211360       , l_array_source_4
211361       , l_array_source_6
211362       , l_array_source_7
211363       , l_array_source_8
211364       , l_array_source_9
211365       , l_array_source_10
211366       , l_array_source_11
211367       , l_array_source_17
211368       , l_array_source_29
211369       , l_array_source_35
211370       , l_array_source_36
211371       , l_array_source_37
211372       , l_array_source_38
211373       , l_array_source_39
211374       , l_array_source_40
211375       , l_array_source_42
211376       LIMIT l_rows;
211377 
211378   --
211379   IF (C_LEVEL_EVENT >= g_log_level) THEN
211380             trace
211381                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
211382                ,p_level    => C_LEVEL_EVENT
211383                ,p_module   => l_log_module);
211384   END IF;
211385   --
211386   EXIT WHEN l_array_entity_id.count = 0;
211387 
211388   XLA_AE_LINES_PKG.g_rec_lines := null;
211389 
211390 --
211391 -- Bug 4458708
211392 --
211393 XLA_AE_LINES_PKG.g_LineNumber := 0;
211394 --
211395 --
211396 
211397 FOR Idx IN 1..l_array_event_id.count LOOP
211398    --
211399    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
211400    --
211401    l_event_id := l_array_event_id(idx);  -- 5648433
211402 
211403    --
211404    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
211405    --
211406 
211407    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
211408              (g_array_event(l_event_id).array_value_num('header_index'))
211409          ,'N'
211410          ) <> 'Y'
211411    THEN
211412       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
211413          trace
211414             (p_msg      => 'Trancaction revesal option is not Y '
211415             ,p_level    => C_LEVEL_STATEMENT
211416             ,p_module   => l_log_module);
211417       END IF;
211418 
211419 --
211420 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
211421 --
211422 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
211423 --
211424 -- set event info as cache for other routines to refer event attributes
211425 --
211426 
211427 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
211428    l_previous_event_id := l_event_id;
211429 
211430    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
211431       (p_application_id           => p_application_id
211432       ,p_primary_ledger_id        => p_primary_ledger_id
211433       ,p_base_ledger_id           => p_base_ledger_id
211434       ,p_target_ledger_id         => p_target_ledger_id
211435       ,p_entity_id                => l_array_entity_id(Idx)
211436       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
211437       ,p_entity_code              => l_array_entity_code(Idx)
211438       ,p_transaction_num          => l_array_transaction_num(Idx)
211439       ,p_event_id                 => l_array_event_id(Idx)
211440       ,p_event_class_code         => l_array_class_code(Idx)
211441       ,p_event_type_code          => l_array_event_type(Idx)
211442       ,p_event_number             => l_array_event_number(Idx)
211443       ,p_event_date               => l_array_event_date(Idx)
211444       ,p_transaction_date         => l_array_transaction_date(Idx)
211445       ,p_reference_num_1          => l_array_reference_num_1(Idx)
211446       ,p_reference_num_2          => l_array_reference_num_2(Idx)
211447       ,p_reference_num_3          => l_array_reference_num_3(Idx)
211448       ,p_reference_num_4          => l_array_reference_num_4(Idx)
211449       ,p_reference_char_1         => l_array_reference_char_1(Idx)
211450       ,p_reference_char_2         => l_array_reference_char_2(Idx)
211451       ,p_reference_char_3         => l_array_reference_char_3(Idx)
211452       ,p_reference_char_4         => l_array_reference_char_4(Idx)
211453       ,p_reference_date_1         => l_array_reference_date_1(Idx)
211454       ,p_reference_date_2         => l_array_reference_date_2(Idx)
211455       ,p_reference_date_3         => l_array_reference_date_3(Idx)
211456       ,p_reference_date_4         => l_array_reference_date_4(Idx)
211457       ,p_event_created_by         => l_array_event_created_by(Idx)
211458       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
211459        --
211460 END IF;
211461 
211462 
211463 
211464 --
211465 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
211466 
211467 l_acct_reversal_source := SUBSTR(NULL, 1,30);
211468 
211469 IF l_continue_with_lines THEN
211470    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
211474          (p_appli_s_name            => 'XLA'
211471       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
211472 
211473       xla_accounting_err_pkg.build_message
211475          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
211476          ,p_token_1                 => 'LINE_NUMBER'
211477          ,p_value_1                 => l_array_extract_line_num(Idx)
211478          ,p_token_2                 => 'PRODUCT_NAME'
211479          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
211480          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
211481          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
211482          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
211483 
211484    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
211485       --
211486       -- following sets the accounting attributes needed to reverse
211487       -- accounting for a distributeion
211488       --
211489 
211490       --
211491       -- 5217187
211492       --
211493       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
211494       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
211495                                        g_array_event(l_event_id).array_value_num('header_index'));
211496       --
211497       --
211498 
211499       -- No reversal code generated
211500 
211501       xla_ae_lines_pkg.SetAcctReversalAttrs
211502          (p_event_id             => l_event_id
211503          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
211504          ,p_calculate_acctd_flag => l_calculate_acctd_flag
211505          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
211506    END IF;
211507 
211508    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
211509        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
211510 
211511 --
211512 AcctLineType_336 (
211513  p_application_id  => p_application_id
211514  ,p_event_id     => l_event_id
211515  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211516  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211517  ,p_actual_flag => l_actual_flag
211518  ,p_balance_type_code => l_balance_type_code
211519  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211520  
211521  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211522  , p_source_2 => l_array_source_2(Idx)
211523  , p_source_3 => l_array_source_3(Idx)
211524  , p_source_29 => l_array_source_29(Idx)
211525  , p_source_35 => l_array_source_35(Idx)
211526  , p_source_36 => l_array_source_36(Idx)
211527  , p_source_37 => l_array_source_37(Idx)
211528  , p_source_38 => l_array_source_38(Idx)
211529  , p_source_39 => l_array_source_39(Idx)
211530  , p_source_40 => l_array_source_40(Idx)
211531  , p_source_42 => l_array_source_42(Idx)
211532  );
211533 If(l_balance_type_code = 'A') THEN
211534   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211535 END IF;
211536 
211537 --
211538 
211539 
211540 --
211541 AcctLineType_337 (
211542  p_application_id  => p_application_id
211543  ,p_event_id     => l_event_id
211544  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211545  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211546  ,p_actual_flag => l_actual_flag
211547  ,p_balance_type_code => l_balance_type_code
211548  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211549  
211550  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211551  , p_source_3 => l_array_source_3(Idx)
211552  , p_source_4 => l_array_source_4(Idx)
211553  , p_source_17 => l_array_source_17(Idx)
211554  , p_source_29 => l_array_source_29(Idx)
211555  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211556  , p_source_35 => l_array_source_35(Idx)
211557  , p_source_36 => l_array_source_36(Idx)
211558  , p_source_37 => l_array_source_37(Idx)
211559  , p_source_38 => l_array_source_38(Idx)
211560  , p_source_39 => l_array_source_39(Idx)
211561  , p_source_40 => l_array_source_40(Idx)
211562  , p_source_42 => l_array_source_42(Idx)
211563  );
211564 If(l_balance_type_code = 'A') THEN
211565   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211566 END IF;
211567 
211568 --
211569 
211570 
211571 --
211572 AcctLineType_339 (
211573  p_application_id  => p_application_id
211574  ,p_event_id     => l_event_id
211575  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211576  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211577  ,p_actual_flag => l_actual_flag
211578  ,p_balance_type_code => l_balance_type_code
211579  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211580  
211581  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211582  , p_source_3 => l_array_source_3(Idx)
211583  , p_source_7 => l_array_source_7(Idx)
211584  , p_source_29 => l_array_source_29(Idx)
211585  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211586  , p_source_35 => l_array_source_35(Idx)
211587  , p_source_36 => l_array_source_36(Idx)
211588  , p_source_37 => l_array_source_37(Idx)
211589  , p_source_38 => l_array_source_38(Idx)
211590  , p_source_39 => l_array_source_39(Idx)
211591  , p_source_40 => l_array_source_40(Idx)
211592  , p_source_42 => l_array_source_42(Idx)
211593  );
211594 If(l_balance_type_code = 'A') THEN
211595   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211596 END IF;
211597 
211598 --
211599 
211600 
211601 --
211602 AcctLineType_342 (
211603  p_application_id  => p_application_id
211604  ,p_event_id     => l_event_id
211605  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211606  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211607  ,p_actual_flag => l_actual_flag
211608  ,p_balance_type_code => l_balance_type_code
211609  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211610  
211611  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211615  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211612  , p_source_3 => l_array_source_3(Idx)
211613  , p_source_9 => l_array_source_9(Idx)
211614  , p_source_29 => l_array_source_29(Idx)
211616  , p_source_35 => l_array_source_35(Idx)
211617  , p_source_36 => l_array_source_36(Idx)
211618  , p_source_37 => l_array_source_37(Idx)
211619  , p_source_38 => l_array_source_38(Idx)
211620  , p_source_39 => l_array_source_39(Idx)
211621  , p_source_40 => l_array_source_40(Idx)
211622  , p_source_42 => l_array_source_42(Idx)
211623  );
211624 If(l_balance_type_code = 'A') THEN
211625   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211626 END IF;
211627 
211628 --
211629 
211630 
211631 --
211632 AcctLineType_343 (
211633  p_application_id  => p_application_id
211634  ,p_event_id     => l_event_id
211635  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211636  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211637  ,p_actual_flag => l_actual_flag
211638  ,p_balance_type_code => l_balance_type_code
211639  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211640  
211641  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211642  , p_source_3 => l_array_source_3(Idx)
211643  , p_source_6 => l_array_source_6(Idx)
211644  , p_source_8 => l_array_source_8(Idx)
211645  , p_source_29 => l_array_source_29(Idx)
211646  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211647  , p_source_35 => l_array_source_35(Idx)
211648  , p_source_36 => l_array_source_36(Idx)
211649  , p_source_37 => l_array_source_37(Idx)
211650  , p_source_38 => l_array_source_38(Idx)
211651  , p_source_39 => l_array_source_39(Idx)
211652  , p_source_40 => l_array_source_40(Idx)
211653  , p_source_42 => l_array_source_42(Idx)
211654  );
211655 If(l_balance_type_code = 'A') THEN
211656   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211657 END IF;
211658 
211659 --
211660 
211661 
211662 --
211663 AcctLineType_344 (
211664  p_application_id  => p_application_id
211665  ,p_event_id     => l_event_id
211666  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211667  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211668  ,p_actual_flag => l_actual_flag
211669  ,p_balance_type_code => l_balance_type_code
211670  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211671  
211672  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211673  , p_source_3 => l_array_source_3(Idx)
211674  , p_source_29 => l_array_source_29(Idx)
211675  , p_source_35 => l_array_source_35(Idx)
211676  , p_source_36 => l_array_source_36(Idx)
211677  , p_source_37 => l_array_source_37(Idx)
211678  , p_source_38 => l_array_source_38(Idx)
211679  , p_source_39 => l_array_source_39(Idx)
211680  , p_source_40 => l_array_source_40(Idx)
211681  , p_source_42 => l_array_source_42(Idx)
211682  );
211683 If(l_balance_type_code = 'A') THEN
211684   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211685 END IF;
211686 
211687 --
211688 
211689 
211690 --
211691 AcctLineType_345 (
211692  p_application_id  => p_application_id
211693  ,p_event_id     => l_event_id
211694  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211695  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211696  ,p_actual_flag => l_actual_flag
211697  ,p_balance_type_code => l_balance_type_code
211698  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211699  
211700  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211701  , p_source_3 => l_array_source_3(Idx)
211702  , p_source_10 => l_array_source_10(Idx)
211703  , p_source_17 => l_array_source_17(Idx)
211704  , p_source_29 => l_array_source_29(Idx)
211705  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211706  , p_source_35 => l_array_source_35(Idx)
211707  , p_source_36 => l_array_source_36(Idx)
211708  , p_source_37 => l_array_source_37(Idx)
211709  , p_source_38 => l_array_source_38(Idx)
211710  , p_source_39 => l_array_source_39(Idx)
211711  , p_source_40 => l_array_source_40(Idx)
211712  , p_source_42 => l_array_source_42(Idx)
211713  );
211714 If(l_balance_type_code = 'A') THEN
211715   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211716 END IF;
211717 
211718 --
211719 
211720 
211721 --
211722 AcctLineType_346 (
211723  p_application_id  => p_application_id
211724  ,p_event_id     => l_event_id
211725  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211726  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211727  ,p_actual_flag => l_actual_flag
211728  ,p_balance_type_code => l_balance_type_code
211729  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211730  
211731  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211732  , p_source_3 => l_array_source_3(Idx)
211733  , p_source_29 => l_array_source_29(Idx)
211734  , p_source_35 => l_array_source_35(Idx)
211735  , p_source_36 => l_array_source_36(Idx)
211736  , p_source_37 => l_array_source_37(Idx)
211737  , p_source_38 => l_array_source_38(Idx)
211738  , p_source_39 => l_array_source_39(Idx)
211739  , p_source_40 => l_array_source_40(Idx)
211740  , p_source_42 => l_array_source_42(Idx)
211741  );
211742 If(l_balance_type_code = 'A') THEN
211743   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211744 END IF;
211745 
211746 --
211747 
211748 
211749 --
211750 AcctLineType_347 (
211751  p_application_id  => p_application_id
211752  ,p_event_id     => l_event_id
211753  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211754  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211755  ,p_actual_flag => l_actual_flag
211756  ,p_balance_type_code => l_balance_type_code
211757  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211758  
211759  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211760  , p_source_3 => l_array_source_3(Idx)
211761  , p_source_10 => l_array_source_10(Idx)
211762  , p_source_17 => l_array_source_17(Idx)
211763  , p_source_29 => l_array_source_29(Idx)
211767  , p_source_37 => l_array_source_37(Idx)
211764  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211765  , p_source_35 => l_array_source_35(Idx)
211766  , p_source_36 => l_array_source_36(Idx)
211768  , p_source_38 => l_array_source_38(Idx)
211769  , p_source_39 => l_array_source_39(Idx)
211770  , p_source_40 => l_array_source_40(Idx)
211771  , p_source_42 => l_array_source_42(Idx)
211772  );
211773 If(l_balance_type_code = 'A') THEN
211774   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211775 END IF;
211776 
211777 --
211778 
211779 
211780 --
211781 AcctLineType_348 (
211782  p_application_id  => p_application_id
211783  ,p_event_id     => l_event_id
211784  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211785  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211786  ,p_actual_flag => l_actual_flag
211787  ,p_balance_type_code => l_balance_type_code
211788  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211789  
211790  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211791  , p_source_3 => l_array_source_3(Idx)
211792  , p_source_11 => l_array_source_11(Idx)
211793  , p_source_17 => l_array_source_17(Idx)
211794  , p_source_29 => l_array_source_29(Idx)
211795  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211796  , p_source_35 => l_array_source_35(Idx)
211797  , p_source_36 => l_array_source_36(Idx)
211798  , p_source_37 => l_array_source_37(Idx)
211799  , p_source_38 => l_array_source_38(Idx)
211800  , p_source_39 => l_array_source_39(Idx)
211801  , p_source_40 => l_array_source_40(Idx)
211802  , p_source_42 => l_array_source_42(Idx)
211803  );
211804 If(l_balance_type_code = 'A') THEN
211805   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211806 END IF;
211807 
211808 --
211809 
211810 
211811 --
211812 AcctLineType_349 (
211813  p_application_id  => p_application_id
211814  ,p_event_id     => l_event_id
211815  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211816  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211817  ,p_actual_flag => l_actual_flag
211818  ,p_balance_type_code => l_balance_type_code
211819  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211820  
211821  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211822  , p_source_3 => l_array_source_3(Idx)
211823  , p_source_19 => g_array_event(l_event_id).array_value_char('source_19')
211824  , p_source_29 => l_array_source_29(Idx)
211825  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211826  , p_source_35 => l_array_source_35(Idx)
211827  , p_source_36 => l_array_source_36(Idx)
211828  , p_source_37 => l_array_source_37(Idx)
211829  , p_source_38 => l_array_source_38(Idx)
211830  , p_source_39 => l_array_source_39(Idx)
211831  , p_source_40 => l_array_source_40(Idx)
211832  );
211833 If(l_balance_type_code = 'A') THEN
211834   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211835 END IF;
211836 
211837 --
211838 
211839 
211840 --
211841 AcctLineType_350 (
211842  p_application_id  => p_application_id
211843  ,p_event_id     => l_event_id
211844  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211845  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211846  ,p_actual_flag => l_actual_flag
211847  ,p_balance_type_code => l_balance_type_code
211848  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211849  
211850  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211851  , p_source_3 => l_array_source_3(Idx)
211852  , p_source_20 => g_array_event(l_event_id).array_value_char('source_20')
211853  , p_source_29 => l_array_source_29(Idx)
211854  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211855  , p_source_35 => l_array_source_35(Idx)
211856  , p_source_36 => l_array_source_36(Idx)
211857  , p_source_37 => l_array_source_37(Idx)
211858  , p_source_38 => l_array_source_38(Idx)
211859  , p_source_39 => l_array_source_39(Idx)
211860  , p_source_40 => l_array_source_40(Idx)
211861  );
211862 If(l_balance_type_code = 'A') THEN
211863   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211864 END IF;
211865 
211866 --
211867 
211868 
211869 --
211870 AcctLineType_351 (
211871  p_application_id  => p_application_id
211872  ,p_event_id     => l_event_id
211873  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211874  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211875  ,p_actual_flag => l_actual_flag
211876  ,p_balance_type_code => l_balance_type_code
211877  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211878  
211879  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211880  , p_source_2 => l_array_source_2(Idx)
211881  , p_source_3 => l_array_source_3(Idx)
211882  , p_source_29 => l_array_source_29(Idx)
211883  , p_source_35 => l_array_source_35(Idx)
211884  , p_source_36 => l_array_source_36(Idx)
211885  , p_source_37 => l_array_source_37(Idx)
211886  , p_source_38 => l_array_source_38(Idx)
211887  , p_source_39 => l_array_source_39(Idx)
211888  , p_source_40 => l_array_source_40(Idx)
211889  , p_source_42 => l_array_source_42(Idx)
211890  );
211891 If(l_balance_type_code = 'A') THEN
211892   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211893 END IF;
211894 
211895 --
211896 
211897 
211898 --
211899 AcctLineType_352 (
211900  p_application_id  => p_application_id
211901  ,p_event_id     => l_event_id
211902  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211903  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211904  ,p_actual_flag => l_actual_flag
211905  ,p_balance_type_code => l_balance_type_code
211906  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211907  
211908  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211909  , p_source_3 => l_array_source_3(Idx)
211910  , p_source_4 => l_array_source_4(Idx)
211911  , p_source_17 => l_array_source_17(Idx)
211912  , p_source_29 => l_array_source_29(Idx)
211913  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211917  , p_source_38 => l_array_source_38(Idx)
211914  , p_source_35 => l_array_source_35(Idx)
211915  , p_source_36 => l_array_source_36(Idx)
211916  , p_source_37 => l_array_source_37(Idx)
211918  , p_source_39 => l_array_source_39(Idx)
211919  , p_source_40 => l_array_source_40(Idx)
211920  , p_source_42 => l_array_source_42(Idx)
211921  );
211922 If(l_balance_type_code = 'A') THEN
211923   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211924 END IF;
211925 
211926 --
211927 
211928 
211929 --
211930 AcctLineType_354 (
211931  p_application_id  => p_application_id
211932  ,p_event_id     => l_event_id
211933  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211934  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211935  ,p_actual_flag => l_actual_flag
211936  ,p_balance_type_code => l_balance_type_code
211937  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211938  
211939  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211940  , p_source_3 => l_array_source_3(Idx)
211941  , p_source_7 => l_array_source_7(Idx)
211942  , p_source_29 => l_array_source_29(Idx)
211943  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211944  , p_source_35 => l_array_source_35(Idx)
211945  , p_source_36 => l_array_source_36(Idx)
211946  , p_source_37 => l_array_source_37(Idx)
211947  , p_source_38 => l_array_source_38(Idx)
211948  , p_source_39 => l_array_source_39(Idx)
211949  , p_source_40 => l_array_source_40(Idx)
211950  , p_source_42 => l_array_source_42(Idx)
211951  );
211952 If(l_balance_type_code = 'A') THEN
211953   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211954 END IF;
211955 
211956 --
211957 
211958 
211959 --
211960 AcctLineType_357 (
211961  p_application_id  => p_application_id
211962  ,p_event_id     => l_event_id
211963  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211964  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211965  ,p_actual_flag => l_actual_flag
211966  ,p_balance_type_code => l_balance_type_code
211967  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211968  
211969  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
211970  , p_source_3 => l_array_source_3(Idx)
211971  , p_source_9 => l_array_source_9(Idx)
211972  , p_source_29 => l_array_source_29(Idx)
211973  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
211974  , p_source_35 => l_array_source_35(Idx)
211975  , p_source_36 => l_array_source_36(Idx)
211976  , p_source_37 => l_array_source_37(Idx)
211977  , p_source_38 => l_array_source_38(Idx)
211978  , p_source_39 => l_array_source_39(Idx)
211979  , p_source_40 => l_array_source_40(Idx)
211980  , p_source_42 => l_array_source_42(Idx)
211981  );
211982 If(l_balance_type_code = 'A') THEN
211983   l_actual_gain_loss_ref := l_gain_or_loss_ref;
211984 END IF;
211985 
211986 --
211987 
211988 
211989 --
211990 AcctLineType_358 (
211991  p_application_id  => p_application_id
211992  ,p_event_id     => l_event_id
211993  ,p_calculate_acctd_flag => l_calculate_acctd_flag
211994  ,p_calculate_g_l_flag => l_calculate_g_l_flag
211995  ,p_actual_flag => l_actual_flag
211996  ,p_balance_type_code => l_balance_type_code
211997  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
211998  
211999  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
212000  , p_source_3 => l_array_source_3(Idx)
212001  , p_source_6 => l_array_source_6(Idx)
212002  , p_source_8 => l_array_source_8(Idx)
212003  , p_source_29 => l_array_source_29(Idx)
212004  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
212005  , p_source_35 => l_array_source_35(Idx)
212006  , p_source_36 => l_array_source_36(Idx)
212007  , p_source_37 => l_array_source_37(Idx)
212008  , p_source_38 => l_array_source_38(Idx)
212009  , p_source_39 => l_array_source_39(Idx)
212010  , p_source_40 => l_array_source_40(Idx)
212011  , p_source_42 => l_array_source_42(Idx)
212012  );
212013 If(l_balance_type_code = 'A') THEN
212014   l_actual_gain_loss_ref := l_gain_or_loss_ref;
212015 END IF;
212016 
212017 --
212018 
212019 
212020 --
212021 AcctLineType_359 (
212022  p_application_id  => p_application_id
212023  ,p_event_id     => l_event_id
212024  ,p_calculate_acctd_flag => l_calculate_acctd_flag
212025  ,p_calculate_g_l_flag => l_calculate_g_l_flag
212026  ,p_actual_flag => l_actual_flag
212027  ,p_balance_type_code => l_balance_type_code
212028  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
212029  
212030  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
212031  , p_source_3 => l_array_source_3(Idx)
212032  , p_source_29 => l_array_source_29(Idx)
212033  , p_source_35 => l_array_source_35(Idx)
212034  , p_source_36 => l_array_source_36(Idx)
212035  , p_source_37 => l_array_source_37(Idx)
212036  , p_source_38 => l_array_source_38(Idx)
212037  , p_source_39 => l_array_source_39(Idx)
212038  , p_source_40 => l_array_source_40(Idx)
212039  , p_source_42 => l_array_source_42(Idx)
212040  );
212041 If(l_balance_type_code = 'A') THEN
212042   l_actual_gain_loss_ref := l_gain_or_loss_ref;
212043 END IF;
212044 
212045 --
212046 
212047 
212048 --
212049 AcctLineType_360 (
212050  p_application_id  => p_application_id
212051  ,p_event_id     => l_event_id
212052  ,p_calculate_acctd_flag => l_calculate_acctd_flag
212053  ,p_calculate_g_l_flag => l_calculate_g_l_flag
212054  ,p_actual_flag => l_actual_flag
212055  ,p_balance_type_code => l_balance_type_code
212056  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
212057  
212058  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
212059  , p_source_3 => l_array_source_3(Idx)
212060  , p_source_10 => l_array_source_10(Idx)
212061  , p_source_17 => l_array_source_17(Idx)
212062  , p_source_29 => l_array_source_29(Idx)
212063  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
212064  , p_source_35 => l_array_source_35(Idx)
212068  , p_source_39 => l_array_source_39(Idx)
212065  , p_source_36 => l_array_source_36(Idx)
212066  , p_source_37 => l_array_source_37(Idx)
212067  , p_source_38 => l_array_source_38(Idx)
212069  , p_source_40 => l_array_source_40(Idx)
212070  , p_source_42 => l_array_source_42(Idx)
212071  );
212072 If(l_balance_type_code = 'A') THEN
212073   l_actual_gain_loss_ref := l_gain_or_loss_ref;
212074 END IF;
212075 
212076 --
212077 
212078 
212079 --
212080 AcctLineType_361 (
212081  p_application_id  => p_application_id
212082  ,p_event_id     => l_event_id
212083  ,p_calculate_acctd_flag => l_calculate_acctd_flag
212084  ,p_calculate_g_l_flag => l_calculate_g_l_flag
212085  ,p_actual_flag => l_actual_flag
212086  ,p_balance_type_code => l_balance_type_code
212087  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
212088  
212089  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
212090  , p_source_3 => l_array_source_3(Idx)
212091  , p_source_29 => l_array_source_29(Idx)
212092  , p_source_35 => l_array_source_35(Idx)
212093  , p_source_36 => l_array_source_36(Idx)
212094  , p_source_37 => l_array_source_37(Idx)
212095  , p_source_38 => l_array_source_38(Idx)
212096  , p_source_39 => l_array_source_39(Idx)
212097  , p_source_40 => l_array_source_40(Idx)
212098  , p_source_42 => l_array_source_42(Idx)
212099  );
212100 If(l_balance_type_code = 'A') THEN
212101   l_actual_gain_loss_ref := l_gain_or_loss_ref;
212102 END IF;
212103 
212104 --
212105 
212106 
212107 --
212108 AcctLineType_362 (
212109  p_application_id  => p_application_id
212110  ,p_event_id     => l_event_id
212111  ,p_calculate_acctd_flag => l_calculate_acctd_flag
212112  ,p_calculate_g_l_flag => l_calculate_g_l_flag
212113  ,p_actual_flag => l_actual_flag
212114  ,p_balance_type_code => l_balance_type_code
212115  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
212116  
212117  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
212118  , p_source_3 => l_array_source_3(Idx)
212119  , p_source_10 => l_array_source_10(Idx)
212120  , p_source_17 => l_array_source_17(Idx)
212121  , p_source_29 => l_array_source_29(Idx)
212122  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
212123  , p_source_35 => l_array_source_35(Idx)
212124  , p_source_36 => l_array_source_36(Idx)
212125  , p_source_37 => l_array_source_37(Idx)
212126  , p_source_38 => l_array_source_38(Idx)
212127  , p_source_39 => l_array_source_39(Idx)
212128  , p_source_40 => l_array_source_40(Idx)
212129  , p_source_42 => l_array_source_42(Idx)
212130  );
212131 If(l_balance_type_code = 'A') THEN
212132   l_actual_gain_loss_ref := l_gain_or_loss_ref;
212133 END IF;
212134 
212135 --
212136 
212137 
212138 --
212139 AcctLineType_363 (
212140  p_application_id  => p_application_id
212141  ,p_event_id     => l_event_id
212142  ,p_calculate_acctd_flag => l_calculate_acctd_flag
212143  ,p_calculate_g_l_flag => l_calculate_g_l_flag
212144  ,p_actual_flag => l_actual_flag
212145  ,p_balance_type_code => l_balance_type_code
212146  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
212147  
212148  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
212149  , p_source_3 => l_array_source_3(Idx)
212150  , p_source_11 => l_array_source_11(Idx)
212151  , p_source_17 => l_array_source_17(Idx)
212152  , p_source_29 => l_array_source_29(Idx)
212153  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
212154  , p_source_35 => l_array_source_35(Idx)
212155  , p_source_36 => l_array_source_36(Idx)
212156  , p_source_37 => l_array_source_37(Idx)
212157  , p_source_38 => l_array_source_38(Idx)
212158  , p_source_39 => l_array_source_39(Idx)
212159  , p_source_40 => l_array_source_40(Idx)
212160  , p_source_42 => l_array_source_42(Idx)
212161  );
212162 If(l_balance_type_code = 'A') THEN
212163   l_actual_gain_loss_ref := l_gain_or_loss_ref;
212164 END IF;
212165 
212166 --
212167 
212168       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
212169       -- or secondary ledger that has different currency with primary
212170       -- or alc that is calculated by sla
212171       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
212172             (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'))
212173 
212174 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
212175 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
212176           AND (l_actual_flag = 'A')) THEN
212177         XLA_AE_LINES_PKG.CreateGainOrLossLines(
212178           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
212179          ,p_application_id   => p_application_id
212180          ,p_amb_context_code => 'DEFAULT'
212181          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
212182          ,p_event_class_code => C_EVENT_CLASS_CODE
212183          ,p_event_type_code  => C_EVENT_TYPE_CODE
212184          
212185          ,p_gain_ccid        => -1
212186          ,p_loss_ccid        => -1
212187 
212188          ,p_actual_flag      => l_actual_flag
212189          ,p_enc_flag         => null
212190          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
212191          ,p_enc_g_l_ref      => null
212192          );
212193       END IF;
212194    END IF;
212195 END IF;
212196 
212197    ELSE
212198       --
212199       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
212200       --
212201       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
212202          trace
212203             (p_msg      => 'Trancaction revesal option is Y'
212204             ,p_level    => C_LEVEL_STATEMENT
212205             ,p_module   => l_log_module);
212206       END IF;
212207    END IF;
212208 
212212 close line_cur;
212209 END LOOP;
212210 l_result := XLA_AE_LINES_PKG.InsertLines ;
212211 end loop;
212213 
212214 
212215 --
212216 -- insert headers into xla_ae_headers_gt table
212217 --
212218 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
212219 
212220 -- insert into errors table here.
212221 
212222 END LOOP;
212223 
212224 --
212225 -- 4865292
212226 --
212227 -- Compare g_hdr_extract_count with event count in
212228 -- CreateHeadersAndLines.
212229 --
212230 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
212231 
212232 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
212233    trace (p_msg     => '# rows extracted from header extract objects '
212234                     || ' (running total): '
212235                     || g_hdr_extract_count
212236          ,p_level   => C_LEVEL_STATEMENT
212237          ,p_module  => l_log_module);
212238 END IF;
212239 
212240 CLOSE header_cur;
212241 --
212242 
212243 --
212244 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
212245    trace
212246       (p_msg      => 'END of EventClass_429'
212247       ,p_level    => C_LEVEL_PROCEDURE
212248       ,p_module   => l_log_module);
212249 END IF;
212250 --
212251 RETURN l_result;
212252 EXCEPTION
212253 WHEN xla_exceptions_pkg.application_exception THEN
212254    
212255 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
212256 
212257    
212258 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
212259 
212260    RAISE;
212261 
212262 WHEN NO_DATA_FOUND THEN
212263 
212264 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
212265 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
212266 
212267 FOR header_record IN header_cur
212268 LOOP
212269     l_array_header_events(header_record.event_id) := header_record.event_id;
212270 END LOOP;
212271 
212272 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
212273 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
212274 
212275 fnd_file.put_line(fnd_file.LOG, '                    ');
212276 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
212277 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
212278 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
212279 
212280 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
212281 LOOP
212282 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
212283 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
212284         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
212285 	END IF;
212286 END LOOP;
212287 
212288 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
212289 fnd_file.put_line(fnd_file.LOG, '                    ');
212290 
212291 
212292 xla_exceptions_pkg.raise_message
212293       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_429');
212294 
212295 
212296 WHEN OTHERS THEN
212297    xla_exceptions_pkg.raise_message
212298       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_429');
212299 END EventClass_429;
212300 --
212301 
212302 ---------------------------------------
212303 --
212304 -- PRIVATE PROCEDURE
212305 --         insert_sources_430
212306 --
212307 ----------------------------------------
212308 --
212309 PROCEDURE insert_sources_430(
212310                                 p_target_ledger_id       IN NUMBER
212311                               , p_language               IN VARCHAR2
212312                               , p_sla_ledger_id          IN NUMBER
212313                               , p_pad_start_date         IN DATE
212314                               , p_pad_end_date           IN DATE
212315                          )
212316 IS
212317 
212318 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'TERMINAL_GAIN_LOSS_ALL';
212319 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'TERMINAL_GAIN_LOSS';
212320 p_apps_owner                   VARCHAR2(30);
212321 l_log_module                   VARCHAR2(240);
212322 BEGIN
212323 IF g_log_enabled THEN
212324       l_log_module := C_DEFAULT_MODULE||'.insert_sources_430';
212325 END IF;
212326 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
212327 
212328       trace
212329          (p_msg      => 'BEGIN of insert_sources_430'
212330          ,p_level    => C_LEVEL_PROCEDURE
212331          ,p_module   => l_log_module);
212332 
212333 END IF;
212334 
212335 -- select APPS owner
212336 SELECT oracle_username
212337   INTO p_apps_owner
212338   FROM fnd_oracle_userid
212339  WHERE read_only_flag = 'U'
212340 ;
212341 
212342 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
212343       trace
212344          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
212345                         ' - p_language = '||p_language||
212346                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
212347                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
212348                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
212349                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
212350          ,p_level    => C_LEVEL_STATEMENT
212351          ,p_module   => l_log_module);
212352 END IF;
212353 
212354 
212355 --
212356 INSERT INTO xla_diag_sources --hdr2
212357 (
212358         event_id
212359       , ledger_id
212360       , sla_ledger_id
212361       , description_language
212362       , object_name
212363       , object_type_code
212364       , line_number
212365       , source_application_id
212366       , source_type_code
212367       , source_code
212368       , source_value
212369       , source_meaning
212373       , last_updated_by
212370       , created_by
212371       , creation_date
212372       , last_update_date
212374       , last_update_login
212375       , program_update_date
212376       , program_application_id
212377       , program_id
212378       , request_id
212379 )
212380 SELECT
212381         event_id
212382       , p_target_ledger_id
212383       , p_sla_ledger_id
212384       , p_language
212385       , object_name
212386       , object_type_code
212387       , line_number
212388       , source_application_id
212389       , source_type_code
212390       , source_code
212391       , SUBSTR(source_value ,1,1996)
212392       , SUBSTR(source_meaning ,1,200)
212393       , xla_environment_pkg.g_Usr_Id
212394       , TRUNC(SYSDATE)
212395       , TRUNC(SYSDATE)
212396       , xla_environment_pkg.g_Usr_Id
212397       , xla_environment_pkg.g_Login_Id
212398       , TRUNC(SYSDATE)
212399       , xla_environment_pkg.g_Prog_Appl_Id
212400       , xla_environment_pkg.g_Prog_Id
212401       , xla_environment_pkg.g_Req_Id
212402   FROM (
212403        SELECT xet.event_id                  event_id
212404             , 0                          line_number
212405             , CASE r
212406                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
212407                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
212408                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
212409                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
212410                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
212411                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
212412                 
212413                ELSE null
212414               END                           object_name
212415             , CASE r
212416                 WHEN 1 THEN 'HEADER' 
212417                 WHEN 2 THEN 'HEADER' 
212418                 WHEN 3 THEN 'HEADER' 
212419                 WHEN 4 THEN 'HEADER' 
212420                 WHEN 5 THEN 'HEADER' 
212421                 WHEN 6 THEN 'HEADER' 
212422                 
212423                 ELSE null
212424               END                           object_type_code
212425             , CASE r
212426                 WHEN 1 THEN '140' 
212427                 WHEN 2 THEN '140' 
212428                 WHEN 3 THEN '140' 
212429                 WHEN 4 THEN '140' 
212430                 WHEN 5 THEN '140' 
212431                 WHEN 6 THEN '140' 
212432                 
212433                 ELSE null
212434               END                           source_application_id
212435             , 'S'             source_type_code
212436             , CASE r
212437                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
212438                 WHEN 2 THEN 'NBV_RETIRED_GAIN_ACCT' 
212439                 WHEN 3 THEN 'NBV_RETIRED_LOSS_ACCT' 
212440                 WHEN 4 THEN 'DEFAULT_CCID' 
212441                 WHEN 5 THEN 'ACCOUNTING_DATE' 
212442                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
212443                 
212444                 ELSE null
212445               END                           source_code
212446             , CASE r
212447                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
212448                 WHEN 2 THEN TO_CHAR(h1.NBV_RETIRED_GAIN_ACCT)
212449                 WHEN 3 THEN TO_CHAR(h1.NBV_RETIRED_LOSS_ACCT)
212450                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
212451                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
212452                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
212453                 
212454                 ELSE null
212455               END                           source_value
212456             , null              source_meaning
212457          FROM xla_events_gt     xet  
212458       , FA_XLA_EXT_HEADERS_B_GT  h1
212459              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
212460          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
212461            AND xet.event_class_code = C_EVENT_CLASS_CODE
212462               AND h1.event_id = xet.event_id
212463 
212464 )
212465 ;
212466 --
212467 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
212468 
212469       trace
212470          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
212471          ,p_level    => C_LEVEL_STATEMENT
212472          ,p_module   => l_log_module);
212473 
212474 END IF;
212475 --
212476 
212477 
212478 
212479 --
212480 INSERT INTO xla_diag_sources  --line2
212481 (
212482         event_id
212483       , ledger_id
212484       , sla_ledger_id
212485       , description_language
212486       , object_name
212487       , object_type_code
212488       , line_number
212489       , source_application_id
212490       , source_type_code
212491       , source_code
212492       , source_value
212493       , source_meaning
212494       , created_by
212495       , creation_date
212496       , last_update_date
212497       , last_updated_by
212498       , last_update_login
212499       , program_update_date
212500       , program_application_id
212501       , program_id
212502       , request_id
212503 )
212504 SELECT  event_id
212505       , p_target_ledger_id
212506       , p_sla_ledger_id
212507       , p_language
212508       , object_name
212509       , object_type_code
212510       , line_number
212511       , source_application_id
212512       , source_type_code
212513       , source_code
212514       , SUBSTR(source_value,1,1996)
212515       , SUBSTR(source_meaning ,1,200)
212516       , xla_environment_pkg.g_Usr_Id
212517       , TRUNC(SYSDATE)
212518       , TRUNC(SYSDATE)
212519       , xla_environment_pkg.g_Usr_Id
212520       , xla_environment_pkg.g_Login_Id
212521       , TRUNC(SYSDATE)
212522       , xla_environment_pkg.g_Prog_Appl_Id
212523       , xla_environment_pkg.g_Prog_Id
212524       , xla_environment_pkg.g_Req_Id
212525   FROM (
212529                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
212526        SELECT xet.event_id                  event_id
212527             , l2.line_number                 line_number
212528             , CASE r
212530                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
212531                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
212532                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
212533                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
212534                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
212535                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
212536                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
212537                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
212538                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
212539                 
212540                ELSE null
212541               END                           object_name
212542             , CASE r
212543                 WHEN 1 THEN 'LINE' 
212544                 WHEN 2 THEN 'LINE' 
212545                 WHEN 3 THEN 'LINE' 
212546                 WHEN 4 THEN 'LINE' 
212547                 WHEN 5 THEN 'LINE' 
212548                 WHEN 6 THEN 'LINE' 
212549                 WHEN 7 THEN 'LINE' 
212550                 WHEN 8 THEN 'LINE' 
212551                 WHEN 9 THEN 'LINE' 
212552                 WHEN 10 THEN 'LINE' 
212553                 
212554                 ELSE null
212555               END                           object_type_code
212556             , CASE r
212557                 WHEN 1 THEN '140' 
212558                 WHEN 2 THEN '140' 
212559                 WHEN 3 THEN '140' 
212560                 WHEN 4 THEN '140' 
212561                 WHEN 5 THEN '140' 
212562                 WHEN 6 THEN '140' 
212563                 WHEN 7 THEN '140' 
212564                 WHEN 8 THEN '140' 
212565                 WHEN 9 THEN '140' 
212566                 WHEN 10 THEN '140' 
212567                 
212568                 ELSE null
212569               END                           source_application_id
212570             , 'S'             source_type_code
212571             , CASE r
212572                 WHEN 1 THEN 'GENERATED_CCID' 
212573                 WHEN 2 THEN 'DEPRN_RESERVE_ACCT' 
212574                 WHEN 3 THEN 'GENERATED_OFFSET_CCID' 
212575                 WHEN 4 THEN 'EXPENSE_ACCOUNT_CCID' 
212576                 WHEN 5 THEN 'ADJUSTMENT_TYPE' 
212577                 WHEN 6 THEN 'TRANSACTION_HEADER_ID' 
212578                 WHEN 7 THEN 'ADJUSTMENT_LINE_ID' 
212579                 WHEN 8 THEN 'DISTRIBUTION_TYPE_CODE' 
212580                 WHEN 9 THEN 'ENTERED_AMOUNT' 
212581                 WHEN 10 THEN 'CURRENCY_CODE' 
212582                 
212583                 ELSE null
212584               END                           source_code
212585             , CASE r
212586                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
212587                 WHEN 2 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
212588                 WHEN 3 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
212589                 WHEN 4 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
212590                 WHEN 5 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
212591                 WHEN 6 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
212592                 WHEN 7 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
212593                 WHEN 8 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
212594                 WHEN 9 THEN TO_CHAR(l2.ENTERED_AMOUNT)
212595                 WHEN 10 THEN TO_CHAR(l2.CURRENCY_CODE)
212596                 
212597                 ELSE null
212598               END                           source_value
212599             , null              source_meaning
212600          FROM  xla_events_gt     xet  
212601         , FA_XLA_EXT_LINES_B_GT  l2
212602             , (select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
212603         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
212604           AND xet.event_class_code = C_EVENT_CLASS_CODE
212605             AND l2.event_id          = xet.event_id
212606   AND l2.ledger_id (+)  = p_sla_ledger_id
212607 
212608 )
212609 ;
212610 --
212611 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
212612 
212613       trace
212614          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
212615          ,p_level    => C_LEVEL_STATEMENT
212616          ,p_module   => l_log_module);
212617 
212618 END IF;
212619 
212620 
212621 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
212622       trace
212623          (p_msg      => 'END of insert_sources_430'
212624          ,p_level    => C_LEVEL_PROCEDURE
212625          ,p_module   => l_log_module);
212626 END IF;
212627 EXCEPTION
212628   WHEN xla_exceptions_pkg.application_exception THEN
212629       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
212630             trace
212631                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
212632                ,p_level    => C_LEVEL_EXCEPTION
212633                ,p_module   => l_log_module);
212634       END IF;
212635       RAISE;
212636   WHEN OTHERS THEN
212637       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
212638             trace
212639                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
212640                ,p_level    => C_LEVEL_EXCEPTION
212641                ,p_module   => l_log_module);
212642        END IF;
212643        xla_exceptions_pkg.raise_message
212644            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_430');
212645 END insert_sources_430;
212646 --
212647 
212648 ---------------------------------------
212649 --
212650 -- PRIVATE FUNCTION
212651 --         EventClass_430
212652 --
212653 ----------------------------------------
212654 --
212655 FUNCTION EventClass_430
212656        (p_application_id         IN NUMBER
212657        ,p_base_ledger_id         IN NUMBER
212658        ,p_target_ledger_id       IN NUMBER
212659        ,p_language               IN VARCHAR2
212660        ,p_currency_code          IN VARCHAR2
212664        ,p_primary_ledger_id      IN NUMBER)
212661        ,p_sla_ledger_id          IN NUMBER
212662        ,p_pad_start_date         IN DATE
212663        ,p_pad_end_date           IN DATE
212665 RETURN BOOLEAN IS
212666 --
212667 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'TERMINAL_GAIN_LOSS_ALL';
212668 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'TERMINAL_GAIN_LOSS';
212669 
212670 l_calculate_acctd_flag   VARCHAR2(1) :='N';
212671 l_calculate_g_l_flag     VARCHAR2(1) :='N';
212672 --
212673 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
212674 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
212675 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
212676 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
212677 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
212678 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
212679 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
212680 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
212681 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
212682 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
212683 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
212684 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
212685 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
212686 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
212687 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
212688 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
212689 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
212690 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
212691 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
212692 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
212693 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
212694 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
212695 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
212696 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
212697 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
212698 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
212699 
212700 l_event_id                             NUMBER;
212701 l_previous_event_id                    NUMBER;
212702 l_first_event_id                       NUMBER;
212703 l_last_event_id                        NUMBER;
212704 
212705 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
212706 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
212707 --
212708 --
212709 l_result                    BOOLEAN := TRUE;
212710 l_rows                      NUMBER  := 1000;
212711 l_event_type_name           VARCHAR2(80) := 'All';
212712 l_event_class_name          VARCHAR2(80) := 'Terminal Gain and Loss';
212713 l_description               VARCHAR2(4000);
212714 l_transaction_reversal      NUMBER;
212715 l_ae_header_id              NUMBER;
212716 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
212717 l_log_module                VARCHAR2(240);
212718 --
212719 l_acct_reversal_source      VARCHAR2(30);
212720 l_trx_reversal_source       VARCHAR2(30);
212721 
212722 l_continue_with_lines       BOOLEAN := TRUE;
212723 --
212724 l_acc_rev_gl_date_source    DATE;                      -- 4262811
212725 --
212726 type t_array_event_id is table of number index by binary_integer;
212727 
212728 l_rec_array_event                    t_rec_array_event;
212729 l_null_rec_array_event               t_rec_array_event;
212730 l_array_ae_header_id                 xla_number_array_type;
212731 l_actual_flag                        VARCHAR2(1) := NULL;
212732 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
212733 l_balance_type_code                  VARCHAR2(1) :=NULL;
212734 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
212735 
212736 --
212737 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
212738 --
212739 
212740 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
212741 TYPE t_array_source_21 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_GAIN_ACCT%TYPE INDEX BY BINARY_INTEGER;
212742 TYPE t_array_source_22 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.NBV_RETIRED_LOSS_ACCT%TYPE INDEX BY BINARY_INTEGER;
212743 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
212744 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
212745 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
212746 
212747 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
212748 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
212749 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
212750 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
212751 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
212752 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
212753 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
212754 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
212755 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
212756 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
212757 
212761 l_array_source_30              t_array_source_30;
212758 l_array_source_1              t_array_source_1;
212759 l_array_source_21              t_array_source_21;
212760 l_array_source_22              t_array_source_22;
212762 l_array_source_51              t_array_source_51;
212763 l_array_source_52              t_array_source_52;
212764 
212765 l_array_source_3      t_array_source_3;
212766 l_array_source_10      t_array_source_10;
212767 l_array_source_17      t_array_source_17;
212768 l_array_source_29      t_array_source_29;
212769 l_array_source_35      t_array_source_35;
212770 l_array_source_36      t_array_source_36;
212771 l_array_source_37      t_array_source_37;
212772 l_array_source_38      t_array_source_38;
212773 l_array_source_39      t_array_source_39;
212774 l_array_source_40      t_array_source_40;
212775 
212776 --
212777 CURSOR header_cur
212778 IS
212779 SELECT /*+ leading(xet) cardinality(xet,1) */
212780 -- Event Class Code: TERMINAL_GAIN_LOSS
212781     xet.entity_id
212782    ,xet.legal_entity_id
212783    ,xet.entity_code
212784    ,xet.transaction_number
212785    ,xet.event_id
212786    ,xet.event_class_code
212787    ,xet.event_type_code
212788    ,xet.event_number
212789    ,xet.event_date
212790    ,xet.transaction_date
212791    ,xet.reference_num_1
212792    ,xet.reference_num_2
212793    ,xet.reference_num_3
212794    ,xet.reference_num_4
212795    ,xet.reference_char_1
212796    ,xet.reference_char_2
212797    ,xet.reference_char_3
212798    ,xet.reference_char_4
212799    ,xet.reference_date_1
212800    ,xet.reference_date_2
212801    ,xet.reference_date_3
212802    ,xet.reference_date_4
212803    ,xet.event_created_by
212804    ,xet.budgetary_control_flag 
212805   , h1.PERIOD_CLOSE_DATE    source_1
212806   , h1.NBV_RETIRED_GAIN_ACCT    source_21
212807   , h1.NBV_RETIRED_LOSS_ACCT    source_22
212808   , h1.DEFAULT_CCID    source_30
212809   , h1.ACCOUNTING_DATE    source_51
212810   , h1.TRANSFER_TO_GL_FLAG    source_52
212811   FROM xla_events_gt     xet 
212812   , FA_XLA_EXT_HEADERS_B_GT  h1
212813  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
212814    and xet.event_class_code = C_EVENT_CLASS_CODE
212815    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
212816 
212817  ORDER BY event_id
212818 ;
212819 
212820 
212821 --
212822 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
212823 IS
212824 SELECT  /*+ leading(xet) cardinality(xet,1) */
212825 -- Event Class Code: TERMINAL_GAIN_LOSS
212826     xet.entity_id
212827    ,xet.legal_entity_id
212828    ,xet.entity_code
212829    ,xet.transaction_number
212830    ,xet.event_id
212831    ,xet.event_class_code
212832    ,xet.event_type_code
212833    ,xet.event_number
212834    ,xet.event_date
212835    ,xet.transaction_date
212836    ,xet.reference_num_1
212837    ,xet.reference_num_2
212838    ,xet.reference_num_3
212839    ,xet.reference_num_4
212840    ,xet.reference_char_1
212841    ,xet.reference_char_2
212842    ,xet.reference_char_3
212843    ,xet.reference_char_4
212844    ,xet.reference_date_1
212845    ,xet.reference_date_2
212846    ,xet.reference_date_3
212847    ,xet.reference_date_4
212848    ,xet.event_created_by
212849    ,xet.budgetary_control_flag
212850  , l2.LINE_NUMBER  
212851   , l2.GENERATED_CCID    source_3
212852   , l2.DEPRN_RESERVE_ACCT    source_10
212853   , l2.GENERATED_OFFSET_CCID    source_17
212854   , l2.EXPENSE_ACCOUNT_CCID    source_29
212855   , l2.ADJUSTMENT_TYPE    source_35
212856   , l2.TRANSACTION_HEADER_ID    source_36
212857   , l2.ADJUSTMENT_LINE_ID    source_37
212858   , l2.DISTRIBUTION_TYPE_CODE    source_38
212859   , l2.ENTERED_AMOUNT    source_39
212860   , l2.CURRENCY_CODE    source_40
212861   FROM xla_events_gt     xet 
212862   , FA_XLA_EXT_LINES_B_GT  l2
212863  WHERE xet.event_id between x_first_event_id and x_last_event_id
212864    and xet.event_date between p_pad_start_date and p_pad_end_date
212865    and xet.event_class_code = C_EVENT_CLASS_CODE
212866    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
212867   AND l2.ledger_id = p_sla_ledger_id
212868 ;
212869 
212870 --
212871 BEGIN
212872 IF g_log_enabled THEN
212873    l_log_module := C_DEFAULT_MODULE||'.EventClass_430';
212874 END IF;
212875 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
212876    trace
212877       (p_msg      => 'BEGIN of EventClass_430'
212878       ,p_level    => C_LEVEL_PROCEDURE
212879       ,p_module   => l_log_module);
212880 END IF;
212881 
212882 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
212883    trace
212884       (p_msg      => 'p_application_id = '||p_application_id||
212885                      ' - p_base_ledger_id = '||p_base_ledger_id||
212886                      ' - p_target_ledger_id  = '||p_target_ledger_id||
212887                      ' - p_language = '||p_language||
212888                      ' - p_currency_code = '||p_currency_code||
212889                      ' - p_sla_ledger_id = '||p_sla_ledger_id
212890       ,p_level    => C_LEVEL_STATEMENT
212891       ,p_module   => l_log_module);
212892 END IF;
212893 --
212894 -- initialze arrays
212895 --
212896 g_array_event.DELETE;
212897 l_rec_array_event := l_null_rec_array_event;
212898 --
212899 --------------------------------------
212900 -- 4262811 Initialze MPA Line Number
212901 --------------------------------------
212902 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
212903 
212904 --
212905 
212906 --
212907 OPEN header_cur;
212908 --
212909 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
212910    trace
212911    (p_msg      => 'SQL - FETCH header_cur'
212912    ,p_level    => C_LEVEL_STATEMENT
212913    ,p_module   => l_log_module);
212914 END IF;
212915 --
212916 LOOP
212917 FETCH header_cur BULK COLLECT INTO
212918         l_array_entity_id
212922       , l_array_event_id
212919       , l_array_legal_entity_id
212920       , l_array_entity_code
212921       , l_array_transaction_num
212923       , l_array_class_code
212924       , l_array_event_type
212925       , l_array_event_number
212926       , l_array_event_date
212927       , l_array_transaction_date
212928       , l_array_reference_num_1
212929       , l_array_reference_num_2
212930       , l_array_reference_num_3
212931       , l_array_reference_num_4
212932       , l_array_reference_char_1
212933       , l_array_reference_char_2
212934       , l_array_reference_char_3
212935       , l_array_reference_char_4
212936       , l_array_reference_date_1
212937       , l_array_reference_date_2
212938       , l_array_reference_date_3
212939       , l_array_reference_date_4
212940       , l_array_event_created_by
212941       , l_array_budgetary_control_flag 
212942       , l_array_source_1
212943       , l_array_source_21
212944       , l_array_source_22
212945       , l_array_source_30
212946       , l_array_source_51
212947       , l_array_source_52
212948       LIMIT l_rows;
212949 --
212950 IF (C_LEVEL_EVENT >= g_log_level) THEN
212951    trace
212952    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
212953    ,p_level    => C_LEVEL_EVENT
212954    ,p_module   => l_log_module);
212955 END IF;
212956 --
212957 EXIT WHEN l_array_entity_id.COUNT = 0;
212958 
212959 -- initialize arrays
212960 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
212961 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
212962 
212963 --
212964 -- Bug 4458708
212965 --
212966 XLA_AE_LINES_PKG.g_LineNumber := 0;
212967 
212968 
212969 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
212970 g_last_hdr_idx := l_array_event_id.LAST;
212971 --
212972 -- loop for the headers. Each iteration is for each header extract row
212973 -- fetched in header cursor
212974 --
212975 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
212976 
212977 --
212978 -- set event info as cache for other routines to refer event attributes
212979 --
212980 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
212981    (p_application_id           => p_application_id
212982    ,p_primary_ledger_id        => p_primary_ledger_id
212983    ,p_base_ledger_id           => p_base_ledger_id
212984    ,p_target_ledger_id         => p_target_ledger_id
212985    ,p_entity_id                => l_array_entity_id(hdr_idx)
212986    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
212987    ,p_entity_code              => l_array_entity_code(hdr_idx)
212988    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
212989    ,p_event_id                 => l_array_event_id(hdr_idx)
212990    ,p_event_class_code         => l_array_class_code(hdr_idx)
212991    ,p_event_type_code          => l_array_event_type(hdr_idx)
212992    ,p_event_number             => l_array_event_number(hdr_idx)
212993    ,p_event_date               => l_array_event_date(hdr_idx)
212994    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
212995    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
212996    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
212997    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
212998    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
212999    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
213000    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
213001    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
213002    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
213003    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
213004    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
213005    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
213006    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
213007    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
213008    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
213009 
213010 --
213011 -- set the status of entry to C_VALID (0)
213012 --
213013 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
213014 
213015 --
213016 -- initialize a row for ae header
213017 --
213018 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
213019 
213020 l_event_id := l_array_event_id(hdr_idx);
213021 
213022 --
213023 -- storing the hdr_idx for event. May be used by line cursor.
213024 --
213025 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
213026 
213027 --
213028 -- store sources from header extract. This can be improved to
213029 -- store only those sources from header extract that may be used in lines
213030 --
213031 
213032 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
213033 g_array_event(l_event_id).array_value_char('source_21') := l_array_source_21(hdr_idx);
213034 g_array_event(l_event_id).array_value_char('source_22') := l_array_source_22(hdr_idx);
213035 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
213036 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
213037 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
213038 
213039 --
213040 -- initilaize the status of ae headers for diffrent balance types
213041 -- the status is initialised to C_NOT_CREATED (2)
213042 --
213043 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
213044 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
213045 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
213046 
213047 --
213048 -- call api to validate and store accounting attributes for header
213049 --
213050 
213054 l_acc_rev_gl_date_source := NULL;
213051 ------------------------------------------------------------
213052 -- Accrual Reversal : to get date for Standard Source (NONE)
213053 ------------------------------------------------------------
213055 
213056      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
213057       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
213058      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
213059       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
213060 
213061 
213062 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
213063 
213064 XLA_AE_HEADER_PKG.SetJeCategoryName;
213065 
213066 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
213067 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
213068 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
213069 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
213070 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
213071 
213072 
213073 --
213074 xla_ae_header_pkg.SetHdrDescription(
213075    p_description => Description_119 (
213076    p_application_id => p_application_id 
213077  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
213078    )
213079 );
213080 --
213081 
213082 -- No header level analytical criteria
213083 
213084 --
213085 --accounting attribute enhancement, bug 3612931
213086 --
213087 l_trx_reversal_source := SUBSTR(NULL, 1,30);
213088 
213089 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
213090    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
213091 
213092    xla_accounting_err_pkg.build_message
213093       (p_appli_s_name            => 'XLA'
213094       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
213095       ,p_token_1                 => 'ACCT_ATTR_NAME'
213096       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
213097       ,p_token_2                 => 'PRODUCT_NAME'
213098       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
213099       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
213100       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
213101       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
213102 
213103 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
213104    --
213105    -- following sets the accounting attributes needed to reverse
213106    -- accounting for a distributeion
213107    --
213108    xla_ae_lines_pkg.SetTrxReversalAttrs
213109       (p_event_id              => l_event_id
213110       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
213111       ,p_trx_reversal_source   => l_trx_reversal_source);
213112 
213113 END IF;
213114 
213115 
213116 ----------------------------------------------------------------
213117 -- 4262811 -  update the header statuses to invalid in need be
213118 ----------------------------------------------------------------
213119 --
213120 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
213121 
213122 
213123   -----------------------------------------------
213124   -- No accrual reversal for the event class/type
213125   -----------------------------------------------
213126 ----------------------------------------------------------------
213127 
213128 --
213129 -- this ends the header loop iteration for one bulk fetch
213130 --
213131 END LOOP;
213132 
213133 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
213134 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
213135 
213136 --
213137 -- insert dummy rows into lines gt table that were created due to
213138 -- transaction reversals
213139 --
213140 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
213141    l_result := XLA_AE_LINES_PKG.InsertLines;
213142 END IF;
213143 
213144 --
213145 -- reset the temp_line_num for each set of events fetched from header
213146 -- cursor rather than doing it for each new event in line cursor
213147 -- Bug 3939231
213148 --
213149 xla_ae_lines_pkg.g_temp_line_num := 0;
213150 
213151 
213152 
213153 --
213154 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
213155 --
213156 --
213157 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
213158 
213159       trace
213160          (p_msg      => 'SQL - FETCH line_cur'
213161          ,p_level    => C_LEVEL_STATEMENT
213162          ,p_module   => l_log_module);
213163 
213164 END IF;
213165 --
213166 --
213167 LOOP
213168   --
213169   FETCH line_cur BULK COLLECT INTO
213170         l_array_entity_id
213171       , l_array_legal_entity_id
213172       , l_array_entity_code
213173       , l_array_transaction_num
213174       , l_array_event_id
213175       , l_array_class_code
213176       , l_array_event_type
213177       , l_array_event_number
213178       , l_array_event_date
213179       , l_array_transaction_date
213180       , l_array_reference_num_1
213181       , l_array_reference_num_2
213182       , l_array_reference_num_3
213183       , l_array_reference_num_4
213184       , l_array_reference_char_1
213185       , l_array_reference_char_2
213186       , l_array_reference_char_3
213187       , l_array_reference_char_4
213188       , l_array_reference_date_1
213189       , l_array_reference_date_2
213190       , l_array_reference_date_3
213191       , l_array_reference_date_4
213192       , l_array_event_created_by
213193       , l_array_budgetary_control_flag
213194       , l_array_extract_line_num 
213198       , l_array_source_29
213195       , l_array_source_3
213196       , l_array_source_10
213197       , l_array_source_17
213199       , l_array_source_35
213200       , l_array_source_36
213201       , l_array_source_37
213202       , l_array_source_38
213203       , l_array_source_39
213204       , l_array_source_40
213205       LIMIT l_rows;
213206 
213207   --
213208   IF (C_LEVEL_EVENT >= g_log_level) THEN
213209             trace
213210                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
213211                ,p_level    => C_LEVEL_EVENT
213212                ,p_module   => l_log_module);
213213   END IF;
213214   --
213215   EXIT WHEN l_array_entity_id.count = 0;
213216 
213217   XLA_AE_LINES_PKG.g_rec_lines := null;
213218 
213219 --
213220 -- Bug 4458708
213221 --
213222 XLA_AE_LINES_PKG.g_LineNumber := 0;
213223 --
213224 --
213225 
213226 FOR Idx IN 1..l_array_event_id.count LOOP
213227    --
213228    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
213229    --
213230    l_event_id := l_array_event_id(idx);  -- 5648433
213231 
213232    --
213233    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
213234    --
213235 
213236    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
213237              (g_array_event(l_event_id).array_value_num('header_index'))
213238          ,'N'
213239          ) <> 'Y'
213240    THEN
213241       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
213242          trace
213243             (p_msg      => 'Trancaction revesal option is not Y '
213244             ,p_level    => C_LEVEL_STATEMENT
213245             ,p_module   => l_log_module);
213246       END IF;
213247 
213248 --
213249 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
213250 --
213251 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
213252 --
213253 -- set event info as cache for other routines to refer event attributes
213254 --
213255 
213256 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
213257    l_previous_event_id := l_event_id;
213258 
213259    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
213260       (p_application_id           => p_application_id
213261       ,p_primary_ledger_id        => p_primary_ledger_id
213262       ,p_base_ledger_id           => p_base_ledger_id
213263       ,p_target_ledger_id         => p_target_ledger_id
213264       ,p_entity_id                => l_array_entity_id(Idx)
213265       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
213266       ,p_entity_code              => l_array_entity_code(Idx)
213267       ,p_transaction_num          => l_array_transaction_num(Idx)
213268       ,p_event_id                 => l_array_event_id(Idx)
213269       ,p_event_class_code         => l_array_class_code(Idx)
213270       ,p_event_type_code          => l_array_event_type(Idx)
213271       ,p_event_number             => l_array_event_number(Idx)
213272       ,p_event_date               => l_array_event_date(Idx)
213273       ,p_transaction_date         => l_array_transaction_date(Idx)
213274       ,p_reference_num_1          => l_array_reference_num_1(Idx)
213275       ,p_reference_num_2          => l_array_reference_num_2(Idx)
213276       ,p_reference_num_3          => l_array_reference_num_3(Idx)
213277       ,p_reference_num_4          => l_array_reference_num_4(Idx)
213278       ,p_reference_char_1         => l_array_reference_char_1(Idx)
213279       ,p_reference_char_2         => l_array_reference_char_2(Idx)
213280       ,p_reference_char_3         => l_array_reference_char_3(Idx)
213281       ,p_reference_char_4         => l_array_reference_char_4(Idx)
213282       ,p_reference_date_1         => l_array_reference_date_1(Idx)
213283       ,p_reference_date_2         => l_array_reference_date_2(Idx)
213284       ,p_reference_date_3         => l_array_reference_date_3(Idx)
213285       ,p_reference_date_4         => l_array_reference_date_4(Idx)
213286       ,p_event_created_by         => l_array_event_created_by(Idx)
213287       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
213288        --
213289 END IF;
213290 
213291 
213292 
213293 --
213294 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
213295 
213296 l_acct_reversal_source := SUBSTR(NULL, 1,30);
213297 
213298 IF l_continue_with_lines THEN
213299    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
213300       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
213301 
213302       xla_accounting_err_pkg.build_message
213303          (p_appli_s_name            => 'XLA'
213304          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
213305          ,p_token_1                 => 'LINE_NUMBER'
213306          ,p_value_1                 => l_array_extract_line_num(Idx)
213307          ,p_token_2                 => 'PRODUCT_NAME'
213308          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
213309          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
213310          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
213311          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
213312 
213313    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
213314       --
213315       -- following sets the accounting attributes needed to reverse
213316       -- accounting for a distributeion
213317       --
213318 
213319       --
213320       -- 5217187
213321       --
213322       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
213323       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
213324                                        g_array_event(l_event_id).array_value_num('header_index'));
213325       --
213326       --
213327 
213331          (p_event_id             => l_event_id
213328       -- No reversal code generated
213329 
213330       xla_ae_lines_pkg.SetAcctReversalAttrs
213332          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
213333          ,p_calculate_acctd_flag => l_calculate_acctd_flag
213334          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
213335    END IF;
213336 
213337    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
213338        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
213339 
213340 --
213341 AcctLineType_366 (
213342  p_application_id  => p_application_id
213343  ,p_event_id     => l_event_id
213344  ,p_calculate_acctd_flag => l_calculate_acctd_flag
213345  ,p_calculate_g_l_flag => l_calculate_g_l_flag
213346  ,p_actual_flag => l_actual_flag
213347  ,p_balance_type_code => l_balance_type_code
213348  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
213349  
213350  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
213351  , p_source_3 => l_array_source_3(Idx)
213352  , p_source_21 => g_array_event(l_event_id).array_value_char('source_21')
213353  , p_source_29 => l_array_source_29(Idx)
213354  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
213355  , p_source_35 => l_array_source_35(Idx)
213356  , p_source_36 => l_array_source_36(Idx)
213357  , p_source_37 => l_array_source_37(Idx)
213358  , p_source_38 => l_array_source_38(Idx)
213359  , p_source_39 => l_array_source_39(Idx)
213360  , p_source_40 => l_array_source_40(Idx)
213361  );
213362 If(l_balance_type_code = 'A') THEN
213363   l_actual_gain_loss_ref := l_gain_or_loss_ref;
213364 END IF;
213365 
213366 --
213367 
213368 
213369 --
213370 AcctLineType_367 (
213371  p_application_id  => p_application_id
213372  ,p_event_id     => l_event_id
213373  ,p_calculate_acctd_flag => l_calculate_acctd_flag
213374  ,p_calculate_g_l_flag => l_calculate_g_l_flag
213375  ,p_actual_flag => l_actual_flag
213376  ,p_balance_type_code => l_balance_type_code
213377  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
213378  
213379  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
213380  , p_source_3 => l_array_source_3(Idx)
213381  , p_source_22 => g_array_event(l_event_id).array_value_char('source_22')
213382  , p_source_29 => l_array_source_29(Idx)
213383  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
213384  , p_source_35 => l_array_source_35(Idx)
213385  , p_source_36 => l_array_source_36(Idx)
213386  , p_source_37 => l_array_source_37(Idx)
213387  , p_source_38 => l_array_source_38(Idx)
213388  , p_source_39 => l_array_source_39(Idx)
213389  , p_source_40 => l_array_source_40(Idx)
213390  );
213391 If(l_balance_type_code = 'A') THEN
213392   l_actual_gain_loss_ref := l_gain_or_loss_ref;
213393 END IF;
213394 
213395 --
213396 
213397 
213398 --
213399 AcctLineType_368 (
213400  p_application_id  => p_application_id
213401  ,p_event_id     => l_event_id
213402  ,p_calculate_acctd_flag => l_calculate_acctd_flag
213403  ,p_calculate_g_l_flag => l_calculate_g_l_flag
213404  ,p_actual_flag => l_actual_flag
213405  ,p_balance_type_code => l_balance_type_code
213406  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
213407  
213408  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
213409  , p_source_3 => l_array_source_3(Idx)
213410  , p_source_10 => l_array_source_10(Idx)
213411  , p_source_17 => l_array_source_17(Idx)
213412  , p_source_29 => l_array_source_29(Idx)
213413  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
213414  , p_source_35 => l_array_source_35(Idx)
213415  , p_source_36 => l_array_source_36(Idx)
213416  , p_source_37 => l_array_source_37(Idx)
213417  , p_source_38 => l_array_source_38(Idx)
213418  , p_source_39 => l_array_source_39(Idx)
213419  , p_source_40 => l_array_source_40(Idx)
213420  );
213421 If(l_balance_type_code = 'A') THEN
213422   l_actual_gain_loss_ref := l_gain_or_loss_ref;
213423 END IF;
213424 
213425 --
213426 
213427       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
213428       -- or secondary ledger that has different currency with primary
213429       -- or alc that is calculated by sla
213430       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
213431             (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'))
213432 
213433 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
213434 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
213435           AND (l_actual_flag = 'A')) THEN
213436         XLA_AE_LINES_PKG.CreateGainOrLossLines(
213437           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
213438          ,p_application_id   => p_application_id
213439          ,p_amb_context_code => 'DEFAULT'
213440          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
213441          ,p_event_class_code => C_EVENT_CLASS_CODE
213442          ,p_event_type_code  => C_EVENT_TYPE_CODE
213443          
213444          ,p_gain_ccid        => -1
213445          ,p_loss_ccid        => -1
213446 
213447          ,p_actual_flag      => l_actual_flag
213448          ,p_enc_flag         => null
213449          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
213450          ,p_enc_g_l_ref      => null
213451          );
213452       END IF;
213453    END IF;
213454 END IF;
213455 
213456    ELSE
213457       --
213458       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
213459       --
213460       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
213461          trace
213462             (p_msg      => 'Trancaction revesal option is Y'
213463             ,p_level    => C_LEVEL_STATEMENT
213464             ,p_module   => l_log_module);
213465       END IF;
213469 l_result := XLA_AE_LINES_PKG.InsertLines ;
213466    END IF;
213467 
213468 END LOOP;
213470 end loop;
213471 close line_cur;
213472 
213473 
213474 --
213475 -- insert headers into xla_ae_headers_gt table
213476 --
213477 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
213478 
213479 -- insert into errors table here.
213480 
213481 END LOOP;
213482 
213483 --
213484 -- 4865292
213485 --
213486 -- Compare g_hdr_extract_count with event count in
213487 -- CreateHeadersAndLines.
213488 --
213489 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
213490 
213491 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
213492    trace (p_msg     => '# rows extracted from header extract objects '
213493                     || ' (running total): '
213494                     || g_hdr_extract_count
213495          ,p_level   => C_LEVEL_STATEMENT
213496          ,p_module  => l_log_module);
213497 END IF;
213498 
213499 CLOSE header_cur;
213500 --
213501 
213502 --
213503 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
213504    trace
213505       (p_msg      => 'END of EventClass_430'
213506       ,p_level    => C_LEVEL_PROCEDURE
213507       ,p_module   => l_log_module);
213508 END IF;
213509 --
213510 RETURN l_result;
213511 EXCEPTION
213512 WHEN xla_exceptions_pkg.application_exception THEN
213513    
213514 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
213515 
213516    
213517 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
213518 
213519    RAISE;
213520 
213521 WHEN NO_DATA_FOUND THEN
213522 
213523 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
213524 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
213525 
213526 FOR header_record IN header_cur
213527 LOOP
213528     l_array_header_events(header_record.event_id) := header_record.event_id;
213529 END LOOP;
213530 
213531 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
213532 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
213533 
213534 fnd_file.put_line(fnd_file.LOG, '                    ');
213535 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
213536 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
213537 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
213538 
213539 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
213540 LOOP
213541 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
213542 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
213543         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
213544 	END IF;
213545 END LOOP;
213546 
213547 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
213548 fnd_file.put_line(fnd_file.LOG, '                    ');
213549 
213550 
213551 xla_exceptions_pkg.raise_message
213552       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_430');
213553 
213554 
213555 WHEN OTHERS THEN
213556    xla_exceptions_pkg.raise_message
213557       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_430');
213558 END EventClass_430;
213559 --
213560 
213561 ---------------------------------------
213562 --
213563 -- PRIVATE PROCEDURE
213564 --         insert_sources_431
213565 --
213566 ----------------------------------------
213567 --
213568 PROCEDURE insert_sources_431(
213569                                 p_target_ledger_id       IN NUMBER
213570                               , p_language               IN VARCHAR2
213571                               , p_sla_ledger_id          IN NUMBER
213572                               , p_pad_start_date         IN DATE
213573                               , p_pad_end_date           IN DATE
213574                          )
213575 IS
213576 
213577 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'TRANSFERS_ALL';
213578 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'TRANSFERS';
213579 p_apps_owner                   VARCHAR2(30);
213580 l_log_module                   VARCHAR2(240);
213581 BEGIN
213582 IF g_log_enabled THEN
213583       l_log_module := C_DEFAULT_MODULE||'.insert_sources_431';
213584 END IF;
213585 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
213586 
213587       trace
213588          (p_msg      => 'BEGIN of insert_sources_431'
213589          ,p_level    => C_LEVEL_PROCEDURE
213590          ,p_module   => l_log_module);
213591 
213592 END IF;
213593 
213594 -- select APPS owner
213595 SELECT oracle_username
213596   INTO p_apps_owner
213597   FROM fnd_oracle_userid
213598  WHERE read_only_flag = 'U'
213599 ;
213600 
213601 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
213602       trace
213603          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
213604                         ' - p_language = '||p_language||
213605                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
213606                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
213607                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
213608                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
213609          ,p_level    => C_LEVEL_STATEMENT
213610          ,p_module   => l_log_module);
213611 END IF;
213612 
213613 
213614 --
213615 INSERT INTO xla_diag_sources --hdr2
213616 (
213617         event_id
213618       , ledger_id
213619       , sla_ledger_id
213620       , description_language
213621       , object_name
213622       , object_type_code
213623       , line_number
213624       , source_application_id
213625       , source_type_code
213626       , source_code
213627       , source_value
213631       , last_update_date
213628       , source_meaning
213629       , created_by
213630       , creation_date
213632       , last_updated_by
213633       , last_update_login
213634       , program_update_date
213635       , program_application_id
213636       , program_id
213637       , request_id
213638 )
213639 SELECT
213640         event_id
213641       , p_target_ledger_id
213642       , p_sla_ledger_id
213643       , p_language
213644       , object_name
213645       , object_type_code
213646       , line_number
213647       , source_application_id
213648       , source_type_code
213649       , source_code
213650       , SUBSTR(source_value ,1,1996)
213651       , SUBSTR(source_meaning ,1,200)
213652       , xla_environment_pkg.g_Usr_Id
213653       , TRUNC(SYSDATE)
213654       , TRUNC(SYSDATE)
213655       , xla_environment_pkg.g_Usr_Id
213656       , xla_environment_pkg.g_Login_Id
213657       , TRUNC(SYSDATE)
213658       , xla_environment_pkg.g_Prog_Appl_Id
213659       , xla_environment_pkg.g_Prog_Id
213660       , xla_environment_pkg.g_Req_Id
213661   FROM (
213662        SELECT xet.event_id                  event_id
213663             , 0                          line_number
213664             , CASE r
213665                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
213666                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
213667                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
213668                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
213669                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
213670                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
213671                 
213672                ELSE null
213673               END                           object_name
213674             , CASE r
213675                 WHEN 1 THEN 'HEADER' 
213676                 WHEN 2 THEN 'HEADER' 
213677                 WHEN 3 THEN 'HEADER' 
213678                 WHEN 4 THEN 'HEADER' 
213679                 WHEN 5 THEN 'HEADER' 
213680                 WHEN 6 THEN 'HEADER' 
213681                 
213682                 ELSE null
213683               END                           object_type_code
213684             , CASE r
213685                 WHEN 1 THEN '140' 
213686                 WHEN 2 THEN '140' 
213687                 WHEN 3 THEN '140' 
213688                 WHEN 4 THEN '140' 
213689                 WHEN 5 THEN '140' 
213690                 WHEN 6 THEN '140' 
213691                 
213692                 ELSE null
213693               END                           source_application_id
213694             , 'S'             source_type_code
213695             , CASE r
213696                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
213697                 WHEN 2 THEN 'AP_INTERCOMPANY_ACCT' 
213698                 WHEN 3 THEN 'AR_INTERCOMPANY_ACCT' 
213699                 WHEN 4 THEN 'DEFAULT_CCID' 
213700                 WHEN 5 THEN 'ACCOUNTING_DATE' 
213701                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
213702                 
213703                 ELSE null
213704               END                           source_code
213705             , CASE r
213706                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
213707                 WHEN 2 THEN TO_CHAR(h1.AP_INTERCOMPANY_ACCT)
213708                 WHEN 3 THEN TO_CHAR(h1.AR_INTERCOMPANY_ACCT)
213709                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
213710                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
213711                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
213712                 
213713                 ELSE null
213714               END                           source_value
213715             , null              source_meaning
213716          FROM xla_events_gt     xet  
213717       , FA_XLA_EXT_HEADERS_B_GT  h1
213718              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
213719          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
213720            AND xet.event_class_code = C_EVENT_CLASS_CODE
213721               AND h1.event_id = xet.event_id
213722 
213723 )
213724 ;
213725 --
213726 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
213727 
213728       trace
213729          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
213730          ,p_level    => C_LEVEL_STATEMENT
213731          ,p_module   => l_log_module);
213732 
213733 END IF;
213734 --
213735 
213736 
213737 
213738 --
213739 INSERT INTO xla_diag_sources  --line2
213740 (
213741         event_id
213742       , ledger_id
213743       , sla_ledger_id
213744       , description_language
213745       , object_name
213746       , object_type_code
213747       , line_number
213748       , source_application_id
213749       , source_type_code
213750       , source_code
213751       , source_value
213752       , source_meaning
213753       , created_by
213754       , creation_date
213755       , last_update_date
213756       , last_updated_by
213757       , last_update_login
213758       , program_update_date
213759       , program_application_id
213760       , program_id
213761       , request_id
213762 )
213763 SELECT  event_id
213764       , p_target_ledger_id
213765       , p_sla_ledger_id
213766       , p_language
213767       , object_name
213768       , object_type_code
213769       , line_number
213770       , source_application_id
213771       , source_type_code
213772       , source_code
213773       , SUBSTR(source_value,1,1996)
213774       , SUBSTR(source_meaning ,1,200)
213775       , xla_environment_pkg.g_Usr_Id
213776       , TRUNC(SYSDATE)
213777       , TRUNC(SYSDATE)
213778       , xla_environment_pkg.g_Usr_Id
213779       , xla_environment_pkg.g_Login_Id
213780       , TRUNC(SYSDATE)
213781       , xla_environment_pkg.g_Prog_Appl_Id
213782       , xla_environment_pkg.g_Prog_Id
213783       , xla_environment_pkg.g_Req_Id
213787             , CASE r
213784   FROM (
213785        SELECT xet.event_id                  event_id
213786             , l2.line_number                 line_number
213788                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
213789                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
213790                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
213791                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
213792                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
213793                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
213794                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
213795                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
213796                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
213797                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
213798                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
213799                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
213800                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
213801                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
213802                 WHEN 15 THEN 'FA_XLA_EXT_LINES_B_GT' 
213803                 
213804                ELSE null
213805               END                           object_name
213806             , CASE r
213807                 WHEN 1 THEN 'LINE' 
213808                 WHEN 2 THEN 'LINE' 
213809                 WHEN 3 THEN 'LINE' 
213810                 WHEN 4 THEN 'LINE' 
213811                 WHEN 5 THEN 'LINE' 
213812                 WHEN 6 THEN 'LINE' 
213813                 WHEN 7 THEN 'LINE' 
213814                 WHEN 8 THEN 'LINE' 
213815                 WHEN 9 THEN 'LINE' 
213816                 WHEN 10 THEN 'LINE' 
213817                 WHEN 11 THEN 'LINE' 
213818                 WHEN 12 THEN 'LINE' 
213819                 WHEN 13 THEN 'LINE' 
213820                 WHEN 14 THEN 'LINE' 
213821                 WHEN 15 THEN 'LINE' 
213822                 
213823                 ELSE null
213824               END                           object_type_code
213825             , CASE r
213826                 WHEN 1 THEN '140' 
213827                 WHEN 2 THEN '140' 
213828                 WHEN 3 THEN '140' 
213829                 WHEN 4 THEN '140' 
213830                 WHEN 5 THEN '140' 
213831                 WHEN 6 THEN '140' 
213832                 WHEN 7 THEN '140' 
213833                 WHEN 8 THEN '140' 
213834                 WHEN 9 THEN '140' 
213835                 WHEN 10 THEN '140' 
213836                 WHEN 11 THEN '140' 
213837                 WHEN 12 THEN '140' 
213838                 WHEN 13 THEN '140' 
213839                 WHEN 14 THEN '140' 
213840                 WHEN 15 THEN '140' 
213841                 
213842                 ELSE null
213843               END                           source_application_id
213844             , 'S'             source_type_code
213845             , CASE r
213846                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
213847                 WHEN 2 THEN 'GENERATED_CCID' 
213848                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
213849                 WHEN 4 THEN 'ASSET_COST_ACCT' 
213850                 WHEN 5 THEN 'DEPRN_RESERVE_ACCT' 
213851                 WHEN 6 THEN 'REVAL_RESERVE_ACCT' 
213852                 WHEN 7 THEN 'GENERATED_OFFSET_CCID' 
213853                 WHEN 8 THEN 'EXPENSE_ACCOUNT_CCID' 
213854                 WHEN 9 THEN 'ADJUSTMENT_TYPE' 
213855                 WHEN 10 THEN 'TRANSACTION_HEADER_ID' 
213856                 WHEN 11 THEN 'ADJUSTMENT_LINE_ID' 
213857                 WHEN 12 THEN 'DISTRIBUTION_TYPE_CODE' 
213858                 WHEN 13 THEN 'ENTERED_AMOUNT' 
213859                 WHEN 14 THEN 'CURRENCY_CODE' 
213860                 WHEN 15 THEN 'SOURCE_DEST_CODE' 
213861                 
213862                 ELSE null
213863               END                           source_code
213864             , CASE r
213865                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
213866                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
213867                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
213868                 WHEN 4 THEN TO_CHAR(l2.ASSET_COST_ACCT)
213869                 WHEN 5 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
213870                 WHEN 6 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
213871                 WHEN 7 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
213872                 WHEN 8 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
213873                 WHEN 9 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
213874                 WHEN 10 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
213875                 WHEN 11 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
213876                 WHEN 12 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
213877                 WHEN 13 THEN TO_CHAR(l2.ENTERED_AMOUNT)
213878                 WHEN 14 THEN TO_CHAR(l2.CURRENCY_CODE)
213879                 WHEN 15 THEN TO_CHAR(l2.SOURCE_DEST_CODE)
213880                 
213881                 ELSE null
213882               END                           source_value
213883             , null              source_meaning
213884          FROM  xla_events_gt     xet  
213885         , FA_XLA_EXT_LINES_B_GT  l2
213886             , (select rownum r from all_objects where rownum <= 15 and owner = p_apps_owner)
213887         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
213888           AND xet.event_class_code = C_EVENT_CLASS_CODE
213889             AND l2.event_id          = xet.event_id
213890   AND l2.ledger_id (+)  = p_sla_ledger_id
213891 
213892 )
213893 ;
213894 --
213895 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
213896 
213897       trace
213898          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
213899          ,p_level    => C_LEVEL_STATEMENT
213900          ,p_module   => l_log_module);
213901 
213902 END IF;
213903 
213904 
213905 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
213906       trace
213907          (p_msg      => 'END of insert_sources_431'
213908          ,p_level    => C_LEVEL_PROCEDURE
213909          ,p_module   => l_log_module);
213910 END IF;
213911 EXCEPTION
213912   WHEN xla_exceptions_pkg.application_exception THEN
213916                ,p_level    => C_LEVEL_EXCEPTION
213913       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
213914             trace
213915                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
213917                ,p_module   => l_log_module);
213918       END IF;
213919       RAISE;
213920   WHEN OTHERS THEN
213921       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
213922             trace
213923                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
213924                ,p_level    => C_LEVEL_EXCEPTION
213925                ,p_module   => l_log_module);
213926        END IF;
213927        xla_exceptions_pkg.raise_message
213928            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_431');
213929 END insert_sources_431;
213930 --
213931 
213932 ---------------------------------------
213933 --
213934 -- PRIVATE FUNCTION
213935 --         EventClass_431
213936 --
213937 ----------------------------------------
213938 --
213939 FUNCTION EventClass_431
213940        (p_application_id         IN NUMBER
213941        ,p_base_ledger_id         IN NUMBER
213942        ,p_target_ledger_id       IN NUMBER
213943        ,p_language               IN VARCHAR2
213944        ,p_currency_code          IN VARCHAR2
213945        ,p_sla_ledger_id          IN NUMBER
213946        ,p_pad_start_date         IN DATE
213947        ,p_pad_end_date           IN DATE
213948        ,p_primary_ledger_id      IN NUMBER)
213949 RETURN BOOLEAN IS
213950 --
213951 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'TRANSFERS_ALL';
213952 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'TRANSFERS';
213953 
213954 l_calculate_acctd_flag   VARCHAR2(1) :='N';
213955 l_calculate_g_l_flag     VARCHAR2(1) :='N';
213956 --
213957 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
213958 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
213959 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
213960 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
213961 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
213962 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
213963 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
213964 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
213965 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
213966 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
213967 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
213968 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
213969 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
213970 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
213971 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
213972 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
213973 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
213974 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
213975 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
213976 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
213977 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
213978 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
213979 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
213980 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
213981 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
213982 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
213983 
213984 l_event_id                             NUMBER;
213985 l_previous_event_id                    NUMBER;
213986 l_first_event_id                       NUMBER;
213987 l_last_event_id                        NUMBER;
213988 
213989 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
213990 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
213991 --
213992 --
213993 l_result                    BOOLEAN := TRUE;
213994 l_rows                      NUMBER  := 1000;
213995 l_event_type_name           VARCHAR2(80) := 'All';
213996 l_event_class_name          VARCHAR2(80) := 'Transfers';
213997 l_description               VARCHAR2(4000);
213998 l_transaction_reversal      NUMBER;
213999 l_ae_header_id              NUMBER;
214000 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
214001 l_log_module                VARCHAR2(240);
214002 --
214003 l_acct_reversal_source      VARCHAR2(30);
214004 l_trx_reversal_source       VARCHAR2(30);
214005 
214006 l_continue_with_lines       BOOLEAN := TRUE;
214007 --
214008 l_acc_rev_gl_date_source    DATE;                      -- 4262811
214009 --
214010 type t_array_event_id is table of number index by binary_integer;
214011 
214012 l_rec_array_event                    t_rec_array_event;
214013 l_null_rec_array_event               t_rec_array_event;
214014 l_array_ae_header_id                 xla_number_array_type;
214015 l_actual_flag                        VARCHAR2(1) := NULL;
214016 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
214017 l_balance_type_code                  VARCHAR2(1) :=NULL;
214018 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
214019 
214020 --
214021 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
214022 --
214023 
214024 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
214025 TYPE t_array_source_19 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AP_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
214026 TYPE t_array_source_20 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AR_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
214030 
214027 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
214028 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
214029 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
214031 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
214032 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
214033 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
214034 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
214035 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
214036 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
214037 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
214038 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
214039 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
214040 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
214041 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
214042 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
214043 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
214044 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
214045 TYPE t_array_source_42 IS TABLE OF FA_XLA_EXT_LINES_B_GT.SOURCE_DEST_CODE%TYPE INDEX BY BINARY_INTEGER;
214046 
214047 l_array_source_1              t_array_source_1;
214048 l_array_source_19              t_array_source_19;
214049 l_array_source_20              t_array_source_20;
214050 l_array_source_30              t_array_source_30;
214051 l_array_source_51              t_array_source_51;
214052 l_array_source_52              t_array_source_52;
214053 
214054 l_array_source_2      t_array_source_2;
214055 l_array_source_3      t_array_source_3;
214056 l_array_source_4      t_array_source_4;
214057 l_array_source_9      t_array_source_9;
214058 l_array_source_10      t_array_source_10;
214059 l_array_source_11      t_array_source_11;
214060 l_array_source_17      t_array_source_17;
214061 l_array_source_29      t_array_source_29;
214062 l_array_source_35      t_array_source_35;
214063 l_array_source_36      t_array_source_36;
214064 l_array_source_37      t_array_source_37;
214065 l_array_source_38      t_array_source_38;
214066 l_array_source_39      t_array_source_39;
214067 l_array_source_40      t_array_source_40;
214068 l_array_source_42      t_array_source_42;
214069 
214070 --
214071 CURSOR header_cur
214072 IS
214073 SELECT /*+ leading(xet) cardinality(xet,1) */
214074 -- Event Class Code: TRANSFERS
214075     xet.entity_id
214076    ,xet.legal_entity_id
214077    ,xet.entity_code
214078    ,xet.transaction_number
214079    ,xet.event_id
214080    ,xet.event_class_code
214081    ,xet.event_type_code
214082    ,xet.event_number
214083    ,xet.event_date
214084    ,xet.transaction_date
214085    ,xet.reference_num_1
214086    ,xet.reference_num_2
214087    ,xet.reference_num_3
214088    ,xet.reference_num_4
214089    ,xet.reference_char_1
214090    ,xet.reference_char_2
214091    ,xet.reference_char_3
214092    ,xet.reference_char_4
214093    ,xet.reference_date_1
214094    ,xet.reference_date_2
214095    ,xet.reference_date_3
214096    ,xet.reference_date_4
214097    ,xet.event_created_by
214098    ,xet.budgetary_control_flag 
214099   , h1.PERIOD_CLOSE_DATE    source_1
214100   , h1.AP_INTERCOMPANY_ACCT    source_19
214101   , h1.AR_INTERCOMPANY_ACCT    source_20
214102   , h1.DEFAULT_CCID    source_30
214103   , h1.ACCOUNTING_DATE    source_51
214104   , h1.TRANSFER_TO_GL_FLAG    source_52
214105   FROM xla_events_gt     xet 
214106   , FA_XLA_EXT_HEADERS_B_GT  h1
214107  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
214108    and xet.event_class_code = C_EVENT_CLASS_CODE
214109    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
214110 
214111  ORDER BY event_id
214112 ;
214113 
214114 
214115 --
214116 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
214117 IS
214118 SELECT  /*+ leading(xet) cardinality(xet,1) */
214119 -- Event Class Code: TRANSFERS
214120     xet.entity_id
214121    ,xet.legal_entity_id
214122    ,xet.entity_code
214123    ,xet.transaction_number
214124    ,xet.event_id
214125    ,xet.event_class_code
214126    ,xet.event_type_code
214127    ,xet.event_number
214128    ,xet.event_date
214129    ,xet.transaction_date
214130    ,xet.reference_num_1
214131    ,xet.reference_num_2
214132    ,xet.reference_num_3
214133    ,xet.reference_num_4
214134    ,xet.reference_char_1
214135    ,xet.reference_char_2
214136    ,xet.reference_char_3
214137    ,xet.reference_char_4
214138    ,xet.reference_date_1
214139    ,xet.reference_date_2
214140    ,xet.reference_date_3
214141    ,xet.reference_date_4
214142    ,xet.event_created_by
214143    ,xet.budgetary_control_flag
214144  , l2.LINE_NUMBER  
214145   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
214146   , l2.GENERATED_CCID    source_3
214147   , l2.BONUS_RESERVE_ACCT    source_4
214148   , l2.ASSET_COST_ACCT    source_9
214149   , l2.DEPRN_RESERVE_ACCT    source_10
214150   , l2.REVAL_RESERVE_ACCT    source_11
214151   , l2.GENERATED_OFFSET_CCID    source_17
214152   , l2.EXPENSE_ACCOUNT_CCID    source_29
214153   , l2.ADJUSTMENT_TYPE    source_35
214154   , l2.TRANSACTION_HEADER_ID    source_36
214155   , l2.ADJUSTMENT_LINE_ID    source_37
214159   , l2.SOURCE_DEST_CODE    source_42
214156   , l2.DISTRIBUTION_TYPE_CODE    source_38
214157   , l2.ENTERED_AMOUNT    source_39
214158   , l2.CURRENCY_CODE    source_40
214160   FROM xla_events_gt     xet 
214161   , FA_XLA_EXT_LINES_B_GT  l2
214162  WHERE xet.event_id between x_first_event_id and x_last_event_id
214163    and xet.event_date between p_pad_start_date and p_pad_end_date
214164    and xet.event_class_code = C_EVENT_CLASS_CODE
214165    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
214166   AND l2.ledger_id = p_sla_ledger_id
214167 ;
214168 
214169 --
214170 BEGIN
214171 IF g_log_enabled THEN
214172    l_log_module := C_DEFAULT_MODULE||'.EventClass_431';
214173 END IF;
214174 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
214175    trace
214176       (p_msg      => 'BEGIN of EventClass_431'
214177       ,p_level    => C_LEVEL_PROCEDURE
214178       ,p_module   => l_log_module);
214179 END IF;
214180 
214181 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
214182    trace
214183       (p_msg      => 'p_application_id = '||p_application_id||
214184                      ' - p_base_ledger_id = '||p_base_ledger_id||
214185                      ' - p_target_ledger_id  = '||p_target_ledger_id||
214186                      ' - p_language = '||p_language||
214187                      ' - p_currency_code = '||p_currency_code||
214188                      ' - p_sla_ledger_id = '||p_sla_ledger_id
214189       ,p_level    => C_LEVEL_STATEMENT
214190       ,p_module   => l_log_module);
214191 END IF;
214192 --
214193 -- initialze arrays
214194 --
214195 g_array_event.DELETE;
214196 l_rec_array_event := l_null_rec_array_event;
214197 --
214198 --------------------------------------
214199 -- 4262811 Initialze MPA Line Number
214200 --------------------------------------
214201 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
214202 
214203 --
214204 
214205 --
214206 OPEN header_cur;
214207 --
214208 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
214209    trace
214210    (p_msg      => 'SQL - FETCH header_cur'
214211    ,p_level    => C_LEVEL_STATEMENT
214212    ,p_module   => l_log_module);
214213 END IF;
214214 --
214215 LOOP
214216 FETCH header_cur BULK COLLECT INTO
214217         l_array_entity_id
214218       , l_array_legal_entity_id
214219       , l_array_entity_code
214220       , l_array_transaction_num
214221       , l_array_event_id
214222       , l_array_class_code
214223       , l_array_event_type
214224       , l_array_event_number
214225       , l_array_event_date
214226       , l_array_transaction_date
214227       , l_array_reference_num_1
214228       , l_array_reference_num_2
214229       , l_array_reference_num_3
214230       , l_array_reference_num_4
214231       , l_array_reference_char_1
214232       , l_array_reference_char_2
214233       , l_array_reference_char_3
214234       , l_array_reference_char_4
214235       , l_array_reference_date_1
214236       , l_array_reference_date_2
214237       , l_array_reference_date_3
214238       , l_array_reference_date_4
214239       , l_array_event_created_by
214240       , l_array_budgetary_control_flag 
214241       , l_array_source_1
214242       , l_array_source_19
214243       , l_array_source_20
214244       , l_array_source_30
214245       , l_array_source_51
214246       , l_array_source_52
214247       LIMIT l_rows;
214248 --
214249 IF (C_LEVEL_EVENT >= g_log_level) THEN
214250    trace
214251    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
214252    ,p_level    => C_LEVEL_EVENT
214253    ,p_module   => l_log_module);
214254 END IF;
214255 --
214256 EXIT WHEN l_array_entity_id.COUNT = 0;
214257 
214258 -- initialize arrays
214259 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
214260 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
214261 
214262 --
214263 -- Bug 4458708
214264 --
214265 XLA_AE_LINES_PKG.g_LineNumber := 0;
214266 
214267 
214268 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
214269 g_last_hdr_idx := l_array_event_id.LAST;
214270 --
214271 -- loop for the headers. Each iteration is for each header extract row
214272 -- fetched in header cursor
214273 --
214274 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
214275 
214276 --
214277 -- set event info as cache for other routines to refer event attributes
214278 --
214279 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
214280    (p_application_id           => p_application_id
214281    ,p_primary_ledger_id        => p_primary_ledger_id
214282    ,p_base_ledger_id           => p_base_ledger_id
214283    ,p_target_ledger_id         => p_target_ledger_id
214284    ,p_entity_id                => l_array_entity_id(hdr_idx)
214285    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
214286    ,p_entity_code              => l_array_entity_code(hdr_idx)
214287    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
214288    ,p_event_id                 => l_array_event_id(hdr_idx)
214289    ,p_event_class_code         => l_array_class_code(hdr_idx)
214290    ,p_event_type_code          => l_array_event_type(hdr_idx)
214291    ,p_event_number             => l_array_event_number(hdr_idx)
214292    ,p_event_date               => l_array_event_date(hdr_idx)
214293    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
214294    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
214295    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
214296    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
214297    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
214298    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
214299    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
214300    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
214304    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
214301    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
214302    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
214303    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
214305    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
214306    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
214307    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
214308 
214309 --
214310 -- set the status of entry to C_VALID (0)
214311 --
214312 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
214313 
214314 --
214315 -- initialize a row for ae header
214316 --
214317 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
214318 
214319 l_event_id := l_array_event_id(hdr_idx);
214320 
214321 --
214322 -- storing the hdr_idx for event. May be used by line cursor.
214323 --
214324 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
214325 
214326 --
214327 -- store sources from header extract. This can be improved to
214328 -- store only those sources from header extract that may be used in lines
214329 --
214330 
214331 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
214332 g_array_event(l_event_id).array_value_char('source_19') := l_array_source_19(hdr_idx);
214333 g_array_event(l_event_id).array_value_char('source_20') := l_array_source_20(hdr_idx);
214334 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
214335 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
214336 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
214337 
214338 --
214339 -- initilaize the status of ae headers for diffrent balance types
214340 -- the status is initialised to C_NOT_CREATED (2)
214341 --
214342 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
214343 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
214344 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
214345 
214346 --
214347 -- call api to validate and store accounting attributes for header
214348 --
214349 
214350 ------------------------------------------------------------
214351 -- Accrual Reversal : to get date for Standard Source (NONE)
214352 ------------------------------------------------------------
214353 l_acc_rev_gl_date_source := NULL;
214354 
214355      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
214356       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
214357      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
214358       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
214359 
214360 
214361 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
214362 
214363 XLA_AE_HEADER_PKG.SetJeCategoryName;
214364 
214365 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
214366 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
214367 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
214368 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
214369 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
214370 
214371 
214372 --
214373 xla_ae_header_pkg.SetHdrDescription(
214374    p_description => Description_123 (
214375    p_application_id => p_application_id 
214376  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214377    )
214378 );
214379 --
214380 
214381 -- No header level analytical criteria
214382 
214383 --
214384 --accounting attribute enhancement, bug 3612931
214385 --
214386 l_trx_reversal_source := SUBSTR(NULL, 1,30);
214387 
214388 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
214389    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
214390 
214391    xla_accounting_err_pkg.build_message
214392       (p_appli_s_name            => 'XLA'
214393       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
214394       ,p_token_1                 => 'ACCT_ATTR_NAME'
214395       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
214396       ,p_token_2                 => 'PRODUCT_NAME'
214397       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
214398       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
214399       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
214400       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
214401 
214402 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
214403    --
214404    -- following sets the accounting attributes needed to reverse
214405    -- accounting for a distributeion
214406    --
214407    xla_ae_lines_pkg.SetTrxReversalAttrs
214408       (p_event_id              => l_event_id
214409       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
214410       ,p_trx_reversal_source   => l_trx_reversal_source);
214411 
214412 END IF;
214413 
214414 
214415 ----------------------------------------------------------------
214416 -- 4262811 -  update the header statuses to invalid in need be
214417 ----------------------------------------------------------------
214418 --
214419 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
214420 
214421 
214422   -----------------------------------------------
214423   -- No accrual reversal for the event class/type
214424   -----------------------------------------------
214428 -- this ends the header loop iteration for one bulk fetch
214425 ----------------------------------------------------------------
214426 
214427 --
214429 --
214430 END LOOP;
214431 
214432 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
214433 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
214434 
214435 --
214436 -- insert dummy rows into lines gt table that were created due to
214437 -- transaction reversals
214438 --
214439 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
214440    l_result := XLA_AE_LINES_PKG.InsertLines;
214441 END IF;
214442 
214443 --
214444 -- reset the temp_line_num for each set of events fetched from header
214445 -- cursor rather than doing it for each new event in line cursor
214446 -- Bug 3939231
214447 --
214448 xla_ae_lines_pkg.g_temp_line_num := 0;
214449 
214450 
214451 
214452 --
214453 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
214454 --
214455 --
214456 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
214457 
214458       trace
214459          (p_msg      => 'SQL - FETCH line_cur'
214460          ,p_level    => C_LEVEL_STATEMENT
214461          ,p_module   => l_log_module);
214462 
214463 END IF;
214464 --
214465 --
214466 LOOP
214467   --
214468   FETCH line_cur BULK COLLECT INTO
214469         l_array_entity_id
214470       , l_array_legal_entity_id
214471       , l_array_entity_code
214472       , l_array_transaction_num
214473       , l_array_event_id
214474       , l_array_class_code
214475       , l_array_event_type
214476       , l_array_event_number
214477       , l_array_event_date
214478       , l_array_transaction_date
214479       , l_array_reference_num_1
214480       , l_array_reference_num_2
214481       , l_array_reference_num_3
214482       , l_array_reference_num_4
214483       , l_array_reference_char_1
214484       , l_array_reference_char_2
214485       , l_array_reference_char_3
214486       , l_array_reference_char_4
214487       , l_array_reference_date_1
214488       , l_array_reference_date_2
214489       , l_array_reference_date_3
214490       , l_array_reference_date_4
214491       , l_array_event_created_by
214492       , l_array_budgetary_control_flag
214493       , l_array_extract_line_num 
214494       , l_array_source_2
214495       , l_array_source_3
214496       , l_array_source_4
214497       , l_array_source_9
214498       , l_array_source_10
214499       , l_array_source_11
214500       , l_array_source_17
214501       , l_array_source_29
214502       , l_array_source_35
214503       , l_array_source_36
214504       , l_array_source_37
214505       , l_array_source_38
214506       , l_array_source_39
214507       , l_array_source_40
214508       , l_array_source_42
214509       LIMIT l_rows;
214510 
214511   --
214512   IF (C_LEVEL_EVENT >= g_log_level) THEN
214513             trace
214514                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
214515                ,p_level    => C_LEVEL_EVENT
214516                ,p_module   => l_log_module);
214517   END IF;
214518   --
214519   EXIT WHEN l_array_entity_id.count = 0;
214520 
214521   XLA_AE_LINES_PKG.g_rec_lines := null;
214522 
214523 --
214524 -- Bug 4458708
214525 --
214526 XLA_AE_LINES_PKG.g_LineNumber := 0;
214527 --
214528 --
214529 
214530 FOR Idx IN 1..l_array_event_id.count LOOP
214531    --
214532    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
214533    --
214534    l_event_id := l_array_event_id(idx);  -- 5648433
214535 
214536    --
214537    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
214538    --
214539 
214540    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
214541              (g_array_event(l_event_id).array_value_num('header_index'))
214542          ,'N'
214543          ) <> 'Y'
214544    THEN
214545       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
214546          trace
214547             (p_msg      => 'Trancaction revesal option is not Y '
214548             ,p_level    => C_LEVEL_STATEMENT
214549             ,p_module   => l_log_module);
214550       END IF;
214551 
214552 --
214553 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
214554 --
214555 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
214556 --
214557 -- set event info as cache for other routines to refer event attributes
214558 --
214559 
214560 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
214561    l_previous_event_id := l_event_id;
214562 
214563    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
214564       (p_application_id           => p_application_id
214565       ,p_primary_ledger_id        => p_primary_ledger_id
214566       ,p_base_ledger_id           => p_base_ledger_id
214567       ,p_target_ledger_id         => p_target_ledger_id
214568       ,p_entity_id                => l_array_entity_id(Idx)
214569       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
214570       ,p_entity_code              => l_array_entity_code(Idx)
214571       ,p_transaction_num          => l_array_transaction_num(Idx)
214572       ,p_event_id                 => l_array_event_id(Idx)
214573       ,p_event_class_code         => l_array_class_code(Idx)
214574       ,p_event_type_code          => l_array_event_type(Idx)
214575       ,p_event_number             => l_array_event_number(Idx)
214576       ,p_event_date               => l_array_event_date(Idx)
214577       ,p_transaction_date         => l_array_transaction_date(Idx)
214578       ,p_reference_num_1          => l_array_reference_num_1(Idx)
214579       ,p_reference_num_2          => l_array_reference_num_2(Idx)
214580       ,p_reference_num_3          => l_array_reference_num_3(Idx)
214584       ,p_reference_char_3         => l_array_reference_char_3(Idx)
214581       ,p_reference_num_4          => l_array_reference_num_4(Idx)
214582       ,p_reference_char_1         => l_array_reference_char_1(Idx)
214583       ,p_reference_char_2         => l_array_reference_char_2(Idx)
214585       ,p_reference_char_4         => l_array_reference_char_4(Idx)
214586       ,p_reference_date_1         => l_array_reference_date_1(Idx)
214587       ,p_reference_date_2         => l_array_reference_date_2(Idx)
214588       ,p_reference_date_3         => l_array_reference_date_3(Idx)
214589       ,p_reference_date_4         => l_array_reference_date_4(Idx)
214590       ,p_event_created_by         => l_array_event_created_by(Idx)
214591       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
214592        --
214593 END IF;
214594 
214595 
214596 
214597 --
214598 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
214599 
214600 l_acct_reversal_source := SUBSTR(NULL, 1,30);
214601 
214602 IF l_continue_with_lines THEN
214603    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
214604       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
214605 
214606       xla_accounting_err_pkg.build_message
214607          (p_appli_s_name            => 'XLA'
214608          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
214609          ,p_token_1                 => 'LINE_NUMBER'
214610          ,p_value_1                 => l_array_extract_line_num(Idx)
214611          ,p_token_2                 => 'PRODUCT_NAME'
214612          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
214613          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
214614          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
214615          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
214616 
214617    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
214618       --
214619       -- following sets the accounting attributes needed to reverse
214620       -- accounting for a distributeion
214621       --
214622 
214623       --
214624       -- 5217187
214625       --
214626       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
214627       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
214628                                        g_array_event(l_event_id).array_value_num('header_index'));
214629       --
214630       --
214631 
214632       -- No reversal code generated
214633 
214634       xla_ae_lines_pkg.SetAcctReversalAttrs
214635          (p_event_id             => l_event_id
214636          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
214637          ,p_calculate_acctd_flag => l_calculate_acctd_flag
214638          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
214639    END IF;
214640 
214641    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
214642        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
214643 
214644 --
214645 AcctLineType_369 (
214646  p_application_id  => p_application_id
214647  ,p_event_id     => l_event_id
214648  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214649  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214650  ,p_actual_flag => l_actual_flag
214651  ,p_balance_type_code => l_balance_type_code
214652  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214653  
214654  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214655  , p_source_2 => l_array_source_2(Idx)
214656  , p_source_3 => l_array_source_3(Idx)
214657  , p_source_29 => l_array_source_29(Idx)
214658  , p_source_35 => l_array_source_35(Idx)
214659  , p_source_36 => l_array_source_36(Idx)
214660  , p_source_37 => l_array_source_37(Idx)
214661  , p_source_38 => l_array_source_38(Idx)
214662  , p_source_39 => l_array_source_39(Idx)
214663  , p_source_40 => l_array_source_40(Idx)
214664  , p_source_42 => l_array_source_42(Idx)
214665  );
214666 If(l_balance_type_code = 'A') THEN
214667   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214668 END IF;
214669 
214670 --
214671 
214672 
214673 --
214674 AcctLineType_370 (
214675  p_application_id  => p_application_id
214676  ,p_event_id     => l_event_id
214677  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214678  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214679  ,p_actual_flag => l_actual_flag
214680  ,p_balance_type_code => l_balance_type_code
214681  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214682  
214683  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214684  , p_source_3 => l_array_source_3(Idx)
214685  , p_source_4 => l_array_source_4(Idx)
214686  , p_source_17 => l_array_source_17(Idx)
214687  , p_source_29 => l_array_source_29(Idx)
214688  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
214689  , p_source_35 => l_array_source_35(Idx)
214690  , p_source_36 => l_array_source_36(Idx)
214691  , p_source_37 => l_array_source_37(Idx)
214692  , p_source_38 => l_array_source_38(Idx)
214693  , p_source_39 => l_array_source_39(Idx)
214694  , p_source_40 => l_array_source_40(Idx)
214695  , p_source_42 => l_array_source_42(Idx)
214696  );
214697 If(l_balance_type_code = 'A') THEN
214698   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214699 END IF;
214700 
214701 --
214702 
214703 
214704 --
214705 AcctLineType_371 (
214706  p_application_id  => p_application_id
214707  ,p_event_id     => l_event_id
214708  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214709  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214710  ,p_actual_flag => l_actual_flag
214711  ,p_balance_type_code => l_balance_type_code
214712  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214713  
214714  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214715  , p_source_3 => l_array_source_3(Idx)
214716  , p_source_9 => l_array_source_9(Idx)
214720  , p_source_36 => l_array_source_36(Idx)
214717  , p_source_29 => l_array_source_29(Idx)
214718  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
214719  , p_source_35 => l_array_source_35(Idx)
214721  , p_source_37 => l_array_source_37(Idx)
214722  , p_source_38 => l_array_source_38(Idx)
214723  , p_source_39 => l_array_source_39(Idx)
214724  , p_source_40 => l_array_source_40(Idx)
214725  , p_source_42 => l_array_source_42(Idx)
214726  );
214727 If(l_balance_type_code = 'A') THEN
214728   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214729 END IF;
214730 
214731 --
214732 
214733 
214734 --
214735 AcctLineType_372 (
214736  p_application_id  => p_application_id
214737  ,p_event_id     => l_event_id
214738  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214739  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214740  ,p_actual_flag => l_actual_flag
214741  ,p_balance_type_code => l_balance_type_code
214742  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214743  
214744  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214745  , p_source_3 => l_array_source_3(Idx)
214746  , p_source_29 => l_array_source_29(Idx)
214747  , p_source_35 => l_array_source_35(Idx)
214748  , p_source_36 => l_array_source_36(Idx)
214749  , p_source_37 => l_array_source_37(Idx)
214750  , p_source_38 => l_array_source_38(Idx)
214751  , p_source_39 => l_array_source_39(Idx)
214752  , p_source_40 => l_array_source_40(Idx)
214753  , p_source_42 => l_array_source_42(Idx)
214754  );
214755 If(l_balance_type_code = 'A') THEN
214756   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214757 END IF;
214758 
214759 --
214760 
214761 
214762 --
214763 AcctLineType_373 (
214764  p_application_id  => p_application_id
214765  ,p_event_id     => l_event_id
214766  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214767  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214768  ,p_actual_flag => l_actual_flag
214769  ,p_balance_type_code => l_balance_type_code
214770  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214771  
214772  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214773  , p_source_3 => l_array_source_3(Idx)
214774  , p_source_10 => l_array_source_10(Idx)
214775  , p_source_17 => l_array_source_17(Idx)
214776  , p_source_29 => l_array_source_29(Idx)
214777  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
214778  , p_source_35 => l_array_source_35(Idx)
214779  , p_source_36 => l_array_source_36(Idx)
214780  , p_source_37 => l_array_source_37(Idx)
214781  , p_source_38 => l_array_source_38(Idx)
214782  , p_source_39 => l_array_source_39(Idx)
214783  , p_source_40 => l_array_source_40(Idx)
214784  , p_source_42 => l_array_source_42(Idx)
214785  );
214786 If(l_balance_type_code = 'A') THEN
214787   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214788 END IF;
214789 
214790 --
214791 
214792 
214793 --
214794 AcctLineType_374 (
214795  p_application_id  => p_application_id
214796  ,p_event_id     => l_event_id
214797  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214798  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214799  ,p_actual_flag => l_actual_flag
214800  ,p_balance_type_code => l_balance_type_code
214801  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214802  
214803  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214804  , p_source_3 => l_array_source_3(Idx)
214805  , p_source_29 => l_array_source_29(Idx)
214806  , p_source_35 => l_array_source_35(Idx)
214807  , p_source_36 => l_array_source_36(Idx)
214808  , p_source_37 => l_array_source_37(Idx)
214809  , p_source_38 => l_array_source_38(Idx)
214810  , p_source_39 => l_array_source_39(Idx)
214811  , p_source_40 => l_array_source_40(Idx)
214812  , p_source_42 => l_array_source_42(Idx)
214813  );
214814 If(l_balance_type_code = 'A') THEN
214815   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214816 END IF;
214817 
214818 --
214819 
214820 
214821 --
214822 AcctLineType_375 (
214823  p_application_id  => p_application_id
214824  ,p_event_id     => l_event_id
214825  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214826  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214827  ,p_actual_flag => l_actual_flag
214828  ,p_balance_type_code => l_balance_type_code
214829  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214830  
214831  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214832  , p_source_3 => l_array_source_3(Idx)
214833  , p_source_10 => l_array_source_10(Idx)
214834  , p_source_17 => l_array_source_17(Idx)
214835  , p_source_29 => l_array_source_29(Idx)
214836  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
214837  , p_source_35 => l_array_source_35(Idx)
214838  , p_source_36 => l_array_source_36(Idx)
214839  , p_source_37 => l_array_source_37(Idx)
214840  , p_source_38 => l_array_source_38(Idx)
214841  , p_source_39 => l_array_source_39(Idx)
214842  , p_source_40 => l_array_source_40(Idx)
214843  , p_source_42 => l_array_source_42(Idx)
214844  );
214845 If(l_balance_type_code = 'A') THEN
214846   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214847 END IF;
214848 
214849 --
214850 
214851 
214852 --
214853 AcctLineType_376 (
214854  p_application_id  => p_application_id
214855  ,p_event_id     => l_event_id
214856  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214857  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214858  ,p_actual_flag => l_actual_flag
214859  ,p_balance_type_code => l_balance_type_code
214860  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214861  
214862  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214863  , p_source_3 => l_array_source_3(Idx)
214864  , p_source_11 => l_array_source_11(Idx)
214865  , p_source_17 => l_array_source_17(Idx)
214866  , p_source_29 => l_array_source_29(Idx)
214867  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
214871  , p_source_38 => l_array_source_38(Idx)
214868  , p_source_35 => l_array_source_35(Idx)
214869  , p_source_36 => l_array_source_36(Idx)
214870  , p_source_37 => l_array_source_37(Idx)
214872  , p_source_39 => l_array_source_39(Idx)
214873  , p_source_40 => l_array_source_40(Idx)
214874  , p_source_42 => l_array_source_42(Idx)
214875  );
214876 If(l_balance_type_code = 'A') THEN
214877   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214878 END IF;
214879 
214880 --
214881 
214882 
214883 --
214884 AcctLineType_377 (
214885  p_application_id  => p_application_id
214886  ,p_event_id     => l_event_id
214887  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214888  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214889  ,p_actual_flag => l_actual_flag
214890  ,p_balance_type_code => l_balance_type_code
214891  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214892  
214893  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214894  , p_source_3 => l_array_source_3(Idx)
214895  , p_source_19 => g_array_event(l_event_id).array_value_char('source_19')
214896  , p_source_29 => l_array_source_29(Idx)
214897  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
214898  , p_source_35 => l_array_source_35(Idx)
214899  , p_source_36 => l_array_source_36(Idx)
214900  , p_source_37 => l_array_source_37(Idx)
214901  , p_source_38 => l_array_source_38(Idx)
214902  , p_source_39 => l_array_source_39(Idx)
214903  , p_source_40 => l_array_source_40(Idx)
214904  );
214905 If(l_balance_type_code = 'A') THEN
214906   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214907 END IF;
214908 
214909 --
214910 
214911 
214912 --
214913 AcctLineType_378 (
214914  p_application_id  => p_application_id
214915  ,p_event_id     => l_event_id
214916  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214917  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214918  ,p_actual_flag => l_actual_flag
214919  ,p_balance_type_code => l_balance_type_code
214920  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214921  
214922  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214923  , p_source_3 => l_array_source_3(Idx)
214924  , p_source_20 => g_array_event(l_event_id).array_value_char('source_20')
214925  , p_source_29 => l_array_source_29(Idx)
214926  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
214927  , p_source_35 => l_array_source_35(Idx)
214928  , p_source_36 => l_array_source_36(Idx)
214929  , p_source_37 => l_array_source_37(Idx)
214930  , p_source_38 => l_array_source_38(Idx)
214931  , p_source_39 => l_array_source_39(Idx)
214932  , p_source_40 => l_array_source_40(Idx)
214933  );
214934 If(l_balance_type_code = 'A') THEN
214935   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214936 END IF;
214937 
214938 --
214939 
214940 
214941 --
214942 AcctLineType_379 (
214943  p_application_id  => p_application_id
214944  ,p_event_id     => l_event_id
214945  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214946  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214947  ,p_actual_flag => l_actual_flag
214948  ,p_balance_type_code => l_balance_type_code
214949  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214950  
214951  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214952  , p_source_2 => l_array_source_2(Idx)
214953  , p_source_3 => l_array_source_3(Idx)
214954  , p_source_29 => l_array_source_29(Idx)
214955  , p_source_35 => l_array_source_35(Idx)
214956  , p_source_36 => l_array_source_36(Idx)
214957  , p_source_37 => l_array_source_37(Idx)
214958  , p_source_38 => l_array_source_38(Idx)
214959  , p_source_39 => l_array_source_39(Idx)
214960  , p_source_40 => l_array_source_40(Idx)
214961  , p_source_42 => l_array_source_42(Idx)
214962  );
214963 If(l_balance_type_code = 'A') THEN
214964   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214965 END IF;
214966 
214967 --
214968 
214969 
214970 --
214971 AcctLineType_380 (
214972  p_application_id  => p_application_id
214973  ,p_event_id     => l_event_id
214974  ,p_calculate_acctd_flag => l_calculate_acctd_flag
214975  ,p_calculate_g_l_flag => l_calculate_g_l_flag
214976  ,p_actual_flag => l_actual_flag
214977  ,p_balance_type_code => l_balance_type_code
214978  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
214979  
214980  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
214981  , p_source_3 => l_array_source_3(Idx)
214982  , p_source_4 => l_array_source_4(Idx)
214983  , p_source_17 => l_array_source_17(Idx)
214984  , p_source_29 => l_array_source_29(Idx)
214985  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
214986  , p_source_35 => l_array_source_35(Idx)
214987  , p_source_36 => l_array_source_36(Idx)
214988  , p_source_37 => l_array_source_37(Idx)
214989  , p_source_38 => l_array_source_38(Idx)
214990  , p_source_39 => l_array_source_39(Idx)
214991  , p_source_40 => l_array_source_40(Idx)
214992  , p_source_42 => l_array_source_42(Idx)
214993  );
214994 If(l_balance_type_code = 'A') THEN
214995   l_actual_gain_loss_ref := l_gain_or_loss_ref;
214996 END IF;
214997 
214998 --
214999 
215000 
215001 --
215002 AcctLineType_381 (
215003  p_application_id  => p_application_id
215004  ,p_event_id     => l_event_id
215005  ,p_calculate_acctd_flag => l_calculate_acctd_flag
215006  ,p_calculate_g_l_flag => l_calculate_g_l_flag
215007  ,p_actual_flag => l_actual_flag
215008  ,p_balance_type_code => l_balance_type_code
215009  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
215010  
215011  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
215012  , p_source_3 => l_array_source_3(Idx)
215013  , p_source_9 => l_array_source_9(Idx)
215014  , p_source_29 => l_array_source_29(Idx)
215015  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
215016  , p_source_35 => l_array_source_35(Idx)
215017  , p_source_36 => l_array_source_36(Idx)
215021  , p_source_40 => l_array_source_40(Idx)
215018  , p_source_37 => l_array_source_37(Idx)
215019  , p_source_38 => l_array_source_38(Idx)
215020  , p_source_39 => l_array_source_39(Idx)
215022  , p_source_42 => l_array_source_42(Idx)
215023  );
215024 If(l_balance_type_code = 'A') THEN
215025   l_actual_gain_loss_ref := l_gain_or_loss_ref;
215026 END IF;
215027 
215028 --
215029 
215030 
215031 --
215032 AcctLineType_382 (
215033  p_application_id  => p_application_id
215034  ,p_event_id     => l_event_id
215035  ,p_calculate_acctd_flag => l_calculate_acctd_flag
215036  ,p_calculate_g_l_flag => l_calculate_g_l_flag
215037  ,p_actual_flag => l_actual_flag
215038  ,p_balance_type_code => l_balance_type_code
215039  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
215040  
215041  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
215042  , p_source_3 => l_array_source_3(Idx)
215043  , p_source_29 => l_array_source_29(Idx)
215044  , p_source_35 => l_array_source_35(Idx)
215045  , p_source_36 => l_array_source_36(Idx)
215046  , p_source_37 => l_array_source_37(Idx)
215047  , p_source_38 => l_array_source_38(Idx)
215048  , p_source_39 => l_array_source_39(Idx)
215049  , p_source_40 => l_array_source_40(Idx)
215050  , p_source_42 => l_array_source_42(Idx)
215051  );
215052 If(l_balance_type_code = 'A') THEN
215053   l_actual_gain_loss_ref := l_gain_or_loss_ref;
215054 END IF;
215055 
215056 --
215057 
215058 
215059 --
215060 AcctLineType_383 (
215061  p_application_id  => p_application_id
215062  ,p_event_id     => l_event_id
215063  ,p_calculate_acctd_flag => l_calculate_acctd_flag
215064  ,p_calculate_g_l_flag => l_calculate_g_l_flag
215065  ,p_actual_flag => l_actual_flag
215066  ,p_balance_type_code => l_balance_type_code
215067  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
215068  
215069  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
215070  , p_source_3 => l_array_source_3(Idx)
215071  , p_source_10 => l_array_source_10(Idx)
215072  , p_source_17 => l_array_source_17(Idx)
215073  , p_source_29 => l_array_source_29(Idx)
215074  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
215075  , p_source_35 => l_array_source_35(Idx)
215076  , p_source_36 => l_array_source_36(Idx)
215077  , p_source_37 => l_array_source_37(Idx)
215078  , p_source_38 => l_array_source_38(Idx)
215079  , p_source_39 => l_array_source_39(Idx)
215080  , p_source_40 => l_array_source_40(Idx)
215081  , p_source_42 => l_array_source_42(Idx)
215082  );
215083 If(l_balance_type_code = 'A') THEN
215084   l_actual_gain_loss_ref := l_gain_or_loss_ref;
215085 END IF;
215086 
215087 --
215088 
215089 
215090 --
215091 AcctLineType_384 (
215092  p_application_id  => p_application_id
215093  ,p_event_id     => l_event_id
215094  ,p_calculate_acctd_flag => l_calculate_acctd_flag
215095  ,p_calculate_g_l_flag => l_calculate_g_l_flag
215096  ,p_actual_flag => l_actual_flag
215097  ,p_balance_type_code => l_balance_type_code
215098  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
215099  
215100  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
215101  , p_source_3 => l_array_source_3(Idx)
215102  , p_source_29 => l_array_source_29(Idx)
215103  , p_source_35 => l_array_source_35(Idx)
215104  , p_source_36 => l_array_source_36(Idx)
215105  , p_source_37 => l_array_source_37(Idx)
215106  , p_source_38 => l_array_source_38(Idx)
215107  , p_source_39 => l_array_source_39(Idx)
215108  , p_source_40 => l_array_source_40(Idx)
215109  , p_source_42 => l_array_source_42(Idx)
215110  );
215111 If(l_balance_type_code = 'A') THEN
215112   l_actual_gain_loss_ref := l_gain_or_loss_ref;
215113 END IF;
215114 
215115 --
215116 
215117 
215118 --
215119 AcctLineType_385 (
215120  p_application_id  => p_application_id
215121  ,p_event_id     => l_event_id
215122  ,p_calculate_acctd_flag => l_calculate_acctd_flag
215123  ,p_calculate_g_l_flag => l_calculate_g_l_flag
215124  ,p_actual_flag => l_actual_flag
215125  ,p_balance_type_code => l_balance_type_code
215126  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
215127  
215128  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
215129  , p_source_3 => l_array_source_3(Idx)
215130  , p_source_10 => l_array_source_10(Idx)
215131  , p_source_17 => l_array_source_17(Idx)
215132  , p_source_29 => l_array_source_29(Idx)
215133  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
215134  , p_source_35 => l_array_source_35(Idx)
215135  , p_source_36 => l_array_source_36(Idx)
215136  , p_source_37 => l_array_source_37(Idx)
215137  , p_source_38 => l_array_source_38(Idx)
215138  , p_source_39 => l_array_source_39(Idx)
215139  , p_source_40 => l_array_source_40(Idx)
215140  , p_source_42 => l_array_source_42(Idx)
215141  );
215142 If(l_balance_type_code = 'A') THEN
215143   l_actual_gain_loss_ref := l_gain_or_loss_ref;
215144 END IF;
215145 
215146 --
215147 
215148 
215149 --
215150 AcctLineType_386 (
215151  p_application_id  => p_application_id
215152  ,p_event_id     => l_event_id
215153  ,p_calculate_acctd_flag => l_calculate_acctd_flag
215154  ,p_calculate_g_l_flag => l_calculate_g_l_flag
215155  ,p_actual_flag => l_actual_flag
215156  ,p_balance_type_code => l_balance_type_code
215157  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
215158  
215159  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
215160  , p_source_3 => l_array_source_3(Idx)
215161  , p_source_11 => l_array_source_11(Idx)
215162  , p_source_17 => l_array_source_17(Idx)
215163  , p_source_29 => l_array_source_29(Idx)
215164  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
215165  , p_source_35 => l_array_source_35(Idx)
215166  , p_source_36 => l_array_source_36(Idx)
215167  , p_source_37 => l_array_source_37(Idx)
215168  , p_source_38 => l_array_source_38(Idx)
215169  , p_source_39 => l_array_source_39(Idx)
215173 If(l_balance_type_code = 'A') THEN
215170  , p_source_40 => l_array_source_40(Idx)
215171  , p_source_42 => l_array_source_42(Idx)
215172  );
215174   l_actual_gain_loss_ref := l_gain_or_loss_ref;
215175 END IF;
215176 
215177 --
215178 
215179       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
215180       -- or secondary ledger that has different currency with primary
215181       -- or alc that is calculated by sla
215182       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
215183             (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'))
215184 
215185 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
215186 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
215187           AND (l_actual_flag = 'A')) THEN
215188         XLA_AE_LINES_PKG.CreateGainOrLossLines(
215189           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
215190          ,p_application_id   => p_application_id
215191          ,p_amb_context_code => 'DEFAULT'
215192          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
215193          ,p_event_class_code => C_EVENT_CLASS_CODE
215194          ,p_event_type_code  => C_EVENT_TYPE_CODE
215195          
215196          ,p_gain_ccid        => -1
215197          ,p_loss_ccid        => -1
215198 
215199          ,p_actual_flag      => l_actual_flag
215200          ,p_enc_flag         => null
215201          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
215202          ,p_enc_g_l_ref      => null
215203          );
215204       END IF;
215205    END IF;
215206 END IF;
215207 
215208    ELSE
215209       --
215210       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
215211       --
215212       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
215213          trace
215214             (p_msg      => 'Trancaction revesal option is Y'
215215             ,p_level    => C_LEVEL_STATEMENT
215216             ,p_module   => l_log_module);
215217       END IF;
215218    END IF;
215219 
215220 END LOOP;
215221 l_result := XLA_AE_LINES_PKG.InsertLines ;
215222 end loop;
215223 close line_cur;
215224 
215225 
215226 --
215227 -- insert headers into xla_ae_headers_gt table
215228 --
215229 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
215230 
215231 -- insert into errors table here.
215232 
215233 END LOOP;
215234 
215235 --
215236 -- 4865292
215237 --
215238 -- Compare g_hdr_extract_count with event count in
215239 -- CreateHeadersAndLines.
215240 --
215241 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
215242 
215243 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
215244    trace (p_msg     => '# rows extracted from header extract objects '
215245                     || ' (running total): '
215246                     || g_hdr_extract_count
215247          ,p_level   => C_LEVEL_STATEMENT
215248          ,p_module  => l_log_module);
215249 END IF;
215250 
215251 CLOSE header_cur;
215252 --
215253 
215254 --
215255 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
215256    trace
215257       (p_msg      => 'END of EventClass_431'
215258       ,p_level    => C_LEVEL_PROCEDURE
215259       ,p_module   => l_log_module);
215260 END IF;
215261 --
215262 RETURN l_result;
215263 EXCEPTION
215264 WHEN xla_exceptions_pkg.application_exception THEN
215265    
215266 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
215267 
215268    
215269 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
215270 
215271    RAISE;
215272 
215273 WHEN NO_DATA_FOUND THEN
215274 
215275 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
215276 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
215277 
215278 FOR header_record IN header_cur
215279 LOOP
215280     l_array_header_events(header_record.event_id) := header_record.event_id;
215281 END LOOP;
215282 
215283 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
215284 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
215285 
215286 fnd_file.put_line(fnd_file.LOG, '                    ');
215287 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
215288 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
215289 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
215290 
215291 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
215292 LOOP
215293 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
215294 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
215295         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
215296 	END IF;
215297 END LOOP;
215298 
215299 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
215300 fnd_file.put_line(fnd_file.LOG, '                    ');
215301 
215302 
215303 xla_exceptions_pkg.raise_message
215304       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_431');
215305 
215306 
215307 WHEN OTHERS THEN
215308    xla_exceptions_pkg.raise_message
215309       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_431');
215310 END EventClass_431;
215311 --
215312 
215313 ---------------------------------------
215314 --
215315 -- PRIVATE PROCEDURE
215316 --         insert_sources_432
215317 --
215318 ----------------------------------------
215319 --
215320 PROCEDURE insert_sources_432(
215321                                 p_target_ledger_id       IN NUMBER
215325                               , p_pad_end_date           IN DATE
215322                               , p_language               IN VARCHAR2
215323                               , p_sla_ledger_id          IN NUMBER
215324                               , p_pad_start_date         IN DATE
215326                          )
215327 IS
215328 
215329 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'UNIT_ADJUSTMENTS_ALL';
215330 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'UNIT_ADJUSTMENTS';
215331 p_apps_owner                   VARCHAR2(30);
215332 l_log_module                   VARCHAR2(240);
215333 BEGIN
215334 IF g_log_enabled THEN
215335       l_log_module := C_DEFAULT_MODULE||'.insert_sources_432';
215336 END IF;
215337 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
215338 
215339       trace
215340          (p_msg      => 'BEGIN of insert_sources_432'
215341          ,p_level    => C_LEVEL_PROCEDURE
215342          ,p_module   => l_log_module);
215343 
215344 END IF;
215345 
215346 -- select APPS owner
215347 SELECT oracle_username
215348   INTO p_apps_owner
215349   FROM fnd_oracle_userid
215350  WHERE read_only_flag = 'U'
215351 ;
215352 
215353 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
215354       trace
215355          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
215356                         ' - p_language = '||p_language||
215357                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
215358                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
215359                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
215360                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
215361          ,p_level    => C_LEVEL_STATEMENT
215362          ,p_module   => l_log_module);
215363 END IF;
215364 
215365 
215366 --
215367 INSERT INTO xla_diag_sources --hdr2
215368 (
215369         event_id
215370       , ledger_id
215371       , sla_ledger_id
215372       , description_language
215373       , object_name
215374       , object_type_code
215375       , line_number
215376       , source_application_id
215377       , source_type_code
215378       , source_code
215379       , source_value
215380       , source_meaning
215381       , created_by
215382       , creation_date
215383       , last_update_date
215384       , last_updated_by
215385       , last_update_login
215386       , program_update_date
215387       , program_application_id
215388       , program_id
215389       , request_id
215390 )
215391 SELECT
215392         event_id
215393       , p_target_ledger_id
215394       , p_sla_ledger_id
215395       , p_language
215396       , object_name
215397       , object_type_code
215398       , line_number
215399       , source_application_id
215400       , source_type_code
215401       , source_code
215402       , SUBSTR(source_value ,1,1996)
215403       , SUBSTR(source_meaning ,1,200)
215404       , xla_environment_pkg.g_Usr_Id
215405       , TRUNC(SYSDATE)
215406       , TRUNC(SYSDATE)
215407       , xla_environment_pkg.g_Usr_Id
215408       , xla_environment_pkg.g_Login_Id
215409       , TRUNC(SYSDATE)
215410       , xla_environment_pkg.g_Prog_Appl_Id
215411       , xla_environment_pkg.g_Prog_Id
215412       , xla_environment_pkg.g_Req_Id
215413   FROM (
215414        SELECT xet.event_id                  event_id
215415             , 0                          line_number
215416             , CASE r
215417                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
215418                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
215419                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
215420                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
215421                 WHEN 5 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
215422                 WHEN 6 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
215423                 
215424                ELSE null
215425               END                           object_name
215426             , CASE r
215427                 WHEN 1 THEN 'HEADER' 
215428                 WHEN 2 THEN 'HEADER' 
215429                 WHEN 3 THEN 'HEADER' 
215430                 WHEN 4 THEN 'HEADER' 
215431                 WHEN 5 THEN 'HEADER' 
215432                 WHEN 6 THEN 'HEADER' 
215433                 
215434                 ELSE null
215435               END                           object_type_code
215436             , CASE r
215437                 WHEN 1 THEN '140' 
215438                 WHEN 2 THEN '140' 
215439                 WHEN 3 THEN '140' 
215440                 WHEN 4 THEN '140' 
215441                 WHEN 5 THEN '140' 
215442                 WHEN 6 THEN '140' 
215443                 
215444                 ELSE null
215445               END                           source_application_id
215446             , 'S'             source_type_code
215447             , CASE r
215448                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
215449                 WHEN 2 THEN 'AP_INTERCOMPANY_ACCT' 
215450                 WHEN 3 THEN 'AR_INTERCOMPANY_ACCT' 
215451                 WHEN 4 THEN 'DEFAULT_CCID' 
215452                 WHEN 5 THEN 'ACCOUNTING_DATE' 
215453                 WHEN 6 THEN 'TRANSFER_TO_GL_FLAG' 
215454                 
215455                 ELSE null
215456               END                           source_code
215457             , CASE r
215458                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
215459                 WHEN 2 THEN TO_CHAR(h1.AP_INTERCOMPANY_ACCT)
215460                 WHEN 3 THEN TO_CHAR(h1.AR_INTERCOMPANY_ACCT)
215461                 WHEN 4 THEN TO_CHAR(h1.DEFAULT_CCID)
215462                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
215463                 WHEN 6 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
215464                 
215465                 ELSE null
215466               END                           source_value
215467             , null              source_meaning
215468          FROM xla_events_gt     xet  
215472            AND xet.event_class_code = C_EVENT_CLASS_CODE
215469       , FA_XLA_EXT_HEADERS_B_GT  h1
215470              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
215471          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
215473               AND h1.event_id = xet.event_id
215474 
215475 )
215476 ;
215477 --
215478 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
215479 
215480       trace
215481          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
215482          ,p_level    => C_LEVEL_STATEMENT
215483          ,p_module   => l_log_module);
215484 
215485 END IF;
215486 --
215487 
215488 
215489 
215490 --
215491 INSERT INTO xla_diag_sources  --line2
215492 (
215493         event_id
215494       , ledger_id
215495       , sla_ledger_id
215496       , description_language
215497       , object_name
215498       , object_type_code
215499       , line_number
215500       , source_application_id
215501       , source_type_code
215502       , source_code
215503       , source_value
215504       , source_meaning
215505       , created_by
215506       , creation_date
215507       , last_update_date
215508       , last_updated_by
215509       , last_update_login
215510       , program_update_date
215511       , program_application_id
215512       , program_id
215513       , request_id
215514 )
215515 SELECT  event_id
215516       , p_target_ledger_id
215517       , p_sla_ledger_id
215518       , p_language
215519       , object_name
215520       , object_type_code
215521       , line_number
215522       , source_application_id
215523       , source_type_code
215524       , source_code
215525       , SUBSTR(source_value,1,1996)
215526       , SUBSTR(source_meaning ,1,200)
215527       , xla_environment_pkg.g_Usr_Id
215528       , TRUNC(SYSDATE)
215529       , TRUNC(SYSDATE)
215530       , xla_environment_pkg.g_Usr_Id
215531       , xla_environment_pkg.g_Login_Id
215532       , TRUNC(SYSDATE)
215533       , xla_environment_pkg.g_Prog_Appl_Id
215534       , xla_environment_pkg.g_Prog_Id
215535       , xla_environment_pkg.g_Req_Id
215536   FROM (
215537        SELECT xet.event_id                  event_id
215538             , l2.line_number                 line_number
215539             , CASE r
215540                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
215541                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
215542                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
215543                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
215544                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
215545                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
215546                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
215547                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
215548                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
215549                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
215550                 WHEN 11 THEN 'FA_XLA_EXT_LINES_B_GT' 
215551                 WHEN 12 THEN 'FA_XLA_EXT_LINES_B_GT' 
215552                 WHEN 13 THEN 'FA_XLA_EXT_LINES_B_GT' 
215553                 WHEN 14 THEN 'FA_XLA_EXT_LINES_B_GT' 
215554                 WHEN 15 THEN 'FA_XLA_EXT_LINES_B_GT' 
215555                 
215556                ELSE null
215557               END                           object_name
215558             , CASE r
215559                 WHEN 1 THEN 'LINE' 
215560                 WHEN 2 THEN 'LINE' 
215561                 WHEN 3 THEN 'LINE' 
215562                 WHEN 4 THEN 'LINE' 
215563                 WHEN 5 THEN 'LINE' 
215564                 WHEN 6 THEN 'LINE' 
215565                 WHEN 7 THEN 'LINE' 
215566                 WHEN 8 THEN 'LINE' 
215567                 WHEN 9 THEN 'LINE' 
215568                 WHEN 10 THEN 'LINE' 
215569                 WHEN 11 THEN 'LINE' 
215570                 WHEN 12 THEN 'LINE' 
215571                 WHEN 13 THEN 'LINE' 
215572                 WHEN 14 THEN 'LINE' 
215573                 WHEN 15 THEN 'LINE' 
215574                 
215575                 ELSE null
215576               END                           object_type_code
215577             , CASE r
215578                 WHEN 1 THEN '140' 
215579                 WHEN 2 THEN '140' 
215580                 WHEN 3 THEN '140' 
215581                 WHEN 4 THEN '140' 
215582                 WHEN 5 THEN '140' 
215583                 WHEN 6 THEN '140' 
215584                 WHEN 7 THEN '140' 
215585                 WHEN 8 THEN '140' 
215586                 WHEN 9 THEN '140' 
215587                 WHEN 10 THEN '140' 
215588                 WHEN 11 THEN '140' 
215589                 WHEN 12 THEN '140' 
215590                 WHEN 13 THEN '140' 
215591                 WHEN 14 THEN '140' 
215592                 WHEN 15 THEN '140' 
215593                 
215594                 ELSE null
215595               END                           source_application_id
215596             , 'S'             source_type_code
215597             , CASE r
215598                 WHEN 1 THEN 'BONUS_DEPRN_EXPENSE_ACCT' 
215599                 WHEN 2 THEN 'GENERATED_CCID' 
215600                 WHEN 3 THEN 'BONUS_RESERVE_ACCT' 
215601                 WHEN 4 THEN 'ASSET_COST_ACCT' 
215602                 WHEN 5 THEN 'DEPRN_RESERVE_ACCT' 
215603                 WHEN 6 THEN 'REVAL_RESERVE_ACCT' 
215604                 WHEN 7 THEN 'GENERATED_OFFSET_CCID' 
215605                 WHEN 8 THEN 'EXPENSE_ACCOUNT_CCID' 
215606                 WHEN 9 THEN 'ADJUSTMENT_TYPE' 
215607                 WHEN 10 THEN 'TRANSACTION_HEADER_ID' 
215608                 WHEN 11 THEN 'ADJUSTMENT_LINE_ID' 
215609                 WHEN 12 THEN 'DISTRIBUTION_TYPE_CODE' 
215610                 WHEN 13 THEN 'ENTERED_AMOUNT' 
215611                 WHEN 14 THEN 'CURRENCY_CODE' 
215612                 WHEN 15 THEN 'SOURCE_DEST_CODE' 
215613                 
215614                 ELSE null
215618                 WHEN 2 THEN TO_CHAR(l2.GENERATED_CCID)
215615               END                           source_code
215616             , CASE r
215617                 WHEN 1 THEN TO_CHAR(l2.BONUS_DEPRN_EXPENSE_ACCT)
215619                 WHEN 3 THEN TO_CHAR(l2.BONUS_RESERVE_ACCT)
215620                 WHEN 4 THEN TO_CHAR(l2.ASSET_COST_ACCT)
215621                 WHEN 5 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
215622                 WHEN 6 THEN TO_CHAR(l2.REVAL_RESERVE_ACCT)
215623                 WHEN 7 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
215624                 WHEN 8 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
215625                 WHEN 9 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
215626                 WHEN 10 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
215627                 WHEN 11 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
215628                 WHEN 12 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
215629                 WHEN 13 THEN TO_CHAR(l2.ENTERED_AMOUNT)
215630                 WHEN 14 THEN TO_CHAR(l2.CURRENCY_CODE)
215631                 WHEN 15 THEN TO_CHAR(l2.SOURCE_DEST_CODE)
215632                 
215633                 ELSE null
215634               END                           source_value
215635             , null              source_meaning
215636          FROM  xla_events_gt     xet  
215637         , FA_XLA_EXT_LINES_B_GT  l2
215638             , (select rownum r from all_objects where rownum <= 15 and owner = p_apps_owner)
215639         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
215640           AND xet.event_class_code = C_EVENT_CLASS_CODE
215641             AND l2.event_id          = xet.event_id
215642   AND l2.ledger_id (+)  = p_sla_ledger_id
215643 
215644 )
215645 ;
215646 --
215647 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
215648 
215649       trace
215650          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
215651          ,p_level    => C_LEVEL_STATEMENT
215652          ,p_module   => l_log_module);
215653 
215654 END IF;
215655 
215656 
215657 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
215658       trace
215659          (p_msg      => 'END of insert_sources_432'
215660          ,p_level    => C_LEVEL_PROCEDURE
215661          ,p_module   => l_log_module);
215662 END IF;
215663 EXCEPTION
215664   WHEN xla_exceptions_pkg.application_exception THEN
215665       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
215666             trace
215667                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
215668                ,p_level    => C_LEVEL_EXCEPTION
215669                ,p_module   => l_log_module);
215670       END IF;
215671       RAISE;
215672   WHEN OTHERS THEN
215673       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
215674             trace
215675                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
215676                ,p_level    => C_LEVEL_EXCEPTION
215677                ,p_module   => l_log_module);
215678        END IF;
215679        xla_exceptions_pkg.raise_message
215680            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_432');
215681 END insert_sources_432;
215682 --
215683 
215684 ---------------------------------------
215685 --
215686 -- PRIVATE FUNCTION
215687 --         EventClass_432
215688 --
215689 ----------------------------------------
215690 --
215691 FUNCTION EventClass_432
215692        (p_application_id         IN NUMBER
215693        ,p_base_ledger_id         IN NUMBER
215694        ,p_target_ledger_id       IN NUMBER
215695        ,p_language               IN VARCHAR2
215696        ,p_currency_code          IN VARCHAR2
215697        ,p_sla_ledger_id          IN NUMBER
215698        ,p_pad_start_date         IN DATE
215699        ,p_pad_end_date           IN DATE
215700        ,p_primary_ledger_id      IN NUMBER)
215701 RETURN BOOLEAN IS
215702 --
215703 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'UNIT_ADJUSTMENTS_ALL';
215704 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'UNIT_ADJUSTMENTS';
215705 
215706 l_calculate_acctd_flag   VARCHAR2(1) :='N';
215707 l_calculate_g_l_flag     VARCHAR2(1) :='N';
215708 --
215709 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
215710 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
215711 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
215712 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
215713 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
215714 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
215715 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
215716 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
215717 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
215718 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
215719 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
215720 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
215721 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
215722 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
215723 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
215724 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
215725 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
215726 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
215727 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
215728 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
215729 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
215730 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
215731 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
215732 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
215736 l_event_id                             NUMBER;
215733 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
215734 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
215735 
215737 l_previous_event_id                    NUMBER;
215738 l_first_event_id                       NUMBER;
215739 l_last_event_id                        NUMBER;
215740 
215741 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
215742 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
215743 --
215744 --
215745 l_result                    BOOLEAN := TRUE;
215746 l_rows                      NUMBER  := 1000;
215747 l_event_type_name           VARCHAR2(80) := 'All';
215748 l_event_class_name          VARCHAR2(80) := 'Unit Adjustments';
215749 l_description               VARCHAR2(4000);
215750 l_transaction_reversal      NUMBER;
215751 l_ae_header_id              NUMBER;
215752 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
215753 l_log_module                VARCHAR2(240);
215754 --
215755 l_acct_reversal_source      VARCHAR2(30);
215756 l_trx_reversal_source       VARCHAR2(30);
215757 
215758 l_continue_with_lines       BOOLEAN := TRUE;
215759 --
215760 l_acc_rev_gl_date_source    DATE;                      -- 4262811
215761 --
215762 type t_array_event_id is table of number index by binary_integer;
215763 
215764 l_rec_array_event                    t_rec_array_event;
215765 l_null_rec_array_event               t_rec_array_event;
215766 l_array_ae_header_id                 xla_number_array_type;
215767 l_actual_flag                        VARCHAR2(1) := NULL;
215768 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
215769 l_balance_type_code                  VARCHAR2(1) :=NULL;
215770 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
215771 
215772 --
215773 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
215774 --
215775 
215776 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
215777 TYPE t_array_source_19 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AP_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
215778 TYPE t_array_source_20 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.AR_INTERCOMPANY_ACCT%TYPE INDEX BY BINARY_INTEGER;
215779 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
215780 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
215781 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
215782 
215783 TYPE t_array_source_2 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_DEPRN_EXPENSE_ACCT%TYPE INDEX BY BINARY_INTEGER;
215784 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
215785 TYPE t_array_source_4 IS TABLE OF FA_XLA_EXT_LINES_B_GT.BONUS_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
215786 TYPE t_array_source_9 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ASSET_COST_ACCT%TYPE INDEX BY BINARY_INTEGER;
215787 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
215788 TYPE t_array_source_11 IS TABLE OF FA_XLA_EXT_LINES_B_GT.REVAL_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
215789 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
215790 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
215791 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
215792 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
215793 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
215794 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
215795 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
215796 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
215797 TYPE t_array_source_42 IS TABLE OF FA_XLA_EXT_LINES_B_GT.SOURCE_DEST_CODE%TYPE INDEX BY BINARY_INTEGER;
215798 
215799 l_array_source_1              t_array_source_1;
215800 l_array_source_19              t_array_source_19;
215801 l_array_source_20              t_array_source_20;
215802 l_array_source_30              t_array_source_30;
215803 l_array_source_51              t_array_source_51;
215804 l_array_source_52              t_array_source_52;
215805 
215806 l_array_source_2      t_array_source_2;
215807 l_array_source_3      t_array_source_3;
215808 l_array_source_4      t_array_source_4;
215809 l_array_source_9      t_array_source_9;
215810 l_array_source_10      t_array_source_10;
215811 l_array_source_11      t_array_source_11;
215812 l_array_source_17      t_array_source_17;
215813 l_array_source_29      t_array_source_29;
215814 l_array_source_35      t_array_source_35;
215815 l_array_source_36      t_array_source_36;
215816 l_array_source_37      t_array_source_37;
215817 l_array_source_38      t_array_source_38;
215818 l_array_source_39      t_array_source_39;
215819 l_array_source_40      t_array_source_40;
215820 l_array_source_42      t_array_source_42;
215821 
215822 --
215823 CURSOR header_cur
215824 IS
215825 SELECT /*+ leading(xet) cardinality(xet,1) */
215826 -- Event Class Code: UNIT_ADJUSTMENTS
215827     xet.entity_id
215828    ,xet.legal_entity_id
215829    ,xet.entity_code
215830    ,xet.transaction_number
215831    ,xet.event_id
215832    ,xet.event_class_code
215833    ,xet.event_type_code
215834    ,xet.event_number
215835    ,xet.event_date
215836    ,xet.transaction_date
215837    ,xet.reference_num_1
215838    ,xet.reference_num_2
215839    ,xet.reference_num_3
215840    ,xet.reference_num_4
215841    ,xet.reference_char_1
215842    ,xet.reference_char_2
215843    ,xet.reference_char_3
215844    ,xet.reference_char_4
215845    ,xet.reference_date_1
215846    ,xet.reference_date_2
215850    ,xet.budgetary_control_flag 
215847    ,xet.reference_date_3
215848    ,xet.reference_date_4
215849    ,xet.event_created_by
215851   , h1.PERIOD_CLOSE_DATE    source_1
215852   , h1.AP_INTERCOMPANY_ACCT    source_19
215853   , h1.AR_INTERCOMPANY_ACCT    source_20
215854   , h1.DEFAULT_CCID    source_30
215855   , h1.ACCOUNTING_DATE    source_51
215856   , h1.TRANSFER_TO_GL_FLAG    source_52
215857   FROM xla_events_gt     xet 
215858   , FA_XLA_EXT_HEADERS_B_GT  h1
215859  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
215860    and xet.event_class_code = C_EVENT_CLASS_CODE
215861    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
215862 
215863  ORDER BY event_id
215864 ;
215865 
215866 
215867 --
215868 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
215869 IS
215870 SELECT  /*+ leading(xet) cardinality(xet,1) */
215871 -- Event Class Code: UNIT_ADJUSTMENTS
215872     xet.entity_id
215873    ,xet.legal_entity_id
215874    ,xet.entity_code
215875    ,xet.transaction_number
215876    ,xet.event_id
215877    ,xet.event_class_code
215878    ,xet.event_type_code
215879    ,xet.event_number
215880    ,xet.event_date
215881    ,xet.transaction_date
215882    ,xet.reference_num_1
215883    ,xet.reference_num_2
215884    ,xet.reference_num_3
215885    ,xet.reference_num_4
215886    ,xet.reference_char_1
215887    ,xet.reference_char_2
215888    ,xet.reference_char_3
215889    ,xet.reference_char_4
215890    ,xet.reference_date_1
215891    ,xet.reference_date_2
215892    ,xet.reference_date_3
215893    ,xet.reference_date_4
215894    ,xet.event_created_by
215895    ,xet.budgetary_control_flag
215896  , l2.LINE_NUMBER  
215897   , l2.BONUS_DEPRN_EXPENSE_ACCT    source_2
215898   , l2.GENERATED_CCID    source_3
215899   , l2.BONUS_RESERVE_ACCT    source_4
215900   , l2.ASSET_COST_ACCT    source_9
215901   , l2.DEPRN_RESERVE_ACCT    source_10
215902   , l2.REVAL_RESERVE_ACCT    source_11
215903   , l2.GENERATED_OFFSET_CCID    source_17
215904   , l2.EXPENSE_ACCOUNT_CCID    source_29
215905   , l2.ADJUSTMENT_TYPE    source_35
215906   , l2.TRANSACTION_HEADER_ID    source_36
215907   , l2.ADJUSTMENT_LINE_ID    source_37
215908   , l2.DISTRIBUTION_TYPE_CODE    source_38
215909   , l2.ENTERED_AMOUNT    source_39
215910   , l2.CURRENCY_CODE    source_40
215911   , l2.SOURCE_DEST_CODE    source_42
215912   FROM xla_events_gt     xet 
215913   , FA_XLA_EXT_LINES_B_GT  l2
215914  WHERE xet.event_id between x_first_event_id and x_last_event_id
215915    and xet.event_date between p_pad_start_date and p_pad_end_date
215916    and xet.event_class_code = C_EVENT_CLASS_CODE
215917    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
215918   AND l2.ledger_id = p_sla_ledger_id
215919 ;
215920 
215921 --
215922 BEGIN
215923 IF g_log_enabled THEN
215924    l_log_module := C_DEFAULT_MODULE||'.EventClass_432';
215925 END IF;
215926 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
215927    trace
215928       (p_msg      => 'BEGIN of EventClass_432'
215929       ,p_level    => C_LEVEL_PROCEDURE
215930       ,p_module   => l_log_module);
215931 END IF;
215932 
215933 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
215934    trace
215935       (p_msg      => 'p_application_id = '||p_application_id||
215936                      ' - p_base_ledger_id = '||p_base_ledger_id||
215937                      ' - p_target_ledger_id  = '||p_target_ledger_id||
215938                      ' - p_language = '||p_language||
215939                      ' - p_currency_code = '||p_currency_code||
215940                      ' - p_sla_ledger_id = '||p_sla_ledger_id
215941       ,p_level    => C_LEVEL_STATEMENT
215942       ,p_module   => l_log_module);
215943 END IF;
215944 --
215945 -- initialze arrays
215946 --
215947 g_array_event.DELETE;
215948 l_rec_array_event := l_null_rec_array_event;
215949 --
215950 --------------------------------------
215951 -- 4262811 Initialze MPA Line Number
215952 --------------------------------------
215953 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
215954 
215955 --
215956 
215957 --
215958 OPEN header_cur;
215959 --
215960 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
215961    trace
215962    (p_msg      => 'SQL - FETCH header_cur'
215963    ,p_level    => C_LEVEL_STATEMENT
215964    ,p_module   => l_log_module);
215965 END IF;
215966 --
215967 LOOP
215968 FETCH header_cur BULK COLLECT INTO
215969         l_array_entity_id
215970       , l_array_legal_entity_id
215971       , l_array_entity_code
215972       , l_array_transaction_num
215973       , l_array_event_id
215974       , l_array_class_code
215975       , l_array_event_type
215976       , l_array_event_number
215977       , l_array_event_date
215978       , l_array_transaction_date
215979       , l_array_reference_num_1
215980       , l_array_reference_num_2
215981       , l_array_reference_num_3
215982       , l_array_reference_num_4
215983       , l_array_reference_char_1
215984       , l_array_reference_char_2
215985       , l_array_reference_char_3
215986       , l_array_reference_char_4
215987       , l_array_reference_date_1
215988       , l_array_reference_date_2
215989       , l_array_reference_date_3
215990       , l_array_reference_date_4
215991       , l_array_event_created_by
215992       , l_array_budgetary_control_flag 
215993       , l_array_source_1
215994       , l_array_source_19
215995       , l_array_source_20
215996       , l_array_source_30
215997       , l_array_source_51
215998       , l_array_source_52
215999       LIMIT l_rows;
216000 --
216001 IF (C_LEVEL_EVENT >= g_log_level) THEN
216002    trace
216003    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
216004    ,p_level    => C_LEVEL_EVENT
216005    ,p_module   => l_log_module);
216006 END IF;
216010 -- initialize arrays
216007 --
216008 EXIT WHEN l_array_entity_id.COUNT = 0;
216009 
216011 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
216012 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
216013 
216014 --
216015 -- Bug 4458708
216016 --
216017 XLA_AE_LINES_PKG.g_LineNumber := 0;
216018 
216019 
216020 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
216021 g_last_hdr_idx := l_array_event_id.LAST;
216022 --
216023 -- loop for the headers. Each iteration is for each header extract row
216024 -- fetched in header cursor
216025 --
216026 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
216027 
216028 --
216029 -- set event info as cache for other routines to refer event attributes
216030 --
216031 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
216032    (p_application_id           => p_application_id
216033    ,p_primary_ledger_id        => p_primary_ledger_id
216034    ,p_base_ledger_id           => p_base_ledger_id
216035    ,p_target_ledger_id         => p_target_ledger_id
216036    ,p_entity_id                => l_array_entity_id(hdr_idx)
216037    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
216038    ,p_entity_code              => l_array_entity_code(hdr_idx)
216039    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
216040    ,p_event_id                 => l_array_event_id(hdr_idx)
216041    ,p_event_class_code         => l_array_class_code(hdr_idx)
216042    ,p_event_type_code          => l_array_event_type(hdr_idx)
216043    ,p_event_number             => l_array_event_number(hdr_idx)
216044    ,p_event_date               => l_array_event_date(hdr_idx)
216045    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
216046    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
216047    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
216048    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
216049    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
216050    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
216051    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
216052    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
216053    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
216054    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
216055    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
216056    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
216057    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
216058    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
216059    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
216060 
216061 --
216062 -- set the status of entry to C_VALID (0)
216063 --
216064 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
216065 
216066 --
216067 -- initialize a row for ae header
216068 --
216069 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
216070 
216071 l_event_id := l_array_event_id(hdr_idx);
216072 
216073 --
216074 -- storing the hdr_idx for event. May be used by line cursor.
216075 --
216076 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
216077 
216078 --
216079 -- store sources from header extract. This can be improved to
216080 -- store only those sources from header extract that may be used in lines
216081 --
216082 
216083 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
216084 g_array_event(l_event_id).array_value_char('source_19') := l_array_source_19(hdr_idx);
216085 g_array_event(l_event_id).array_value_char('source_20') := l_array_source_20(hdr_idx);
216086 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
216087 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
216088 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
216089 
216090 --
216091 -- initilaize the status of ae headers for diffrent balance types
216092 -- the status is initialised to C_NOT_CREATED (2)
216093 --
216094 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
216095 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
216096 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
216097 
216098 --
216099 -- call api to validate and store accounting attributes for header
216100 --
216101 
216102 ------------------------------------------------------------
216103 -- Accrual Reversal : to get date for Standard Source (NONE)
216104 ------------------------------------------------------------
216105 l_acc_rev_gl_date_source := NULL;
216106 
216107      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
216108       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
216109      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
216110       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
216111 
216112 
216113 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
216114 
216115 XLA_AE_HEADER_PKG.SetJeCategoryName;
216116 
216117 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
216118 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
216119 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
216120 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
216121 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
216122 
216123 
216124 --
216125 xla_ae_header_pkg.SetHdrDescription(
216126    p_description => Description_139 (
216127    p_application_id => p_application_id 
216131 --
216128  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216129    )
216130 );
216132 
216133 -- No header level analytical criteria
216134 
216135 --
216136 --accounting attribute enhancement, bug 3612931
216137 --
216138 l_trx_reversal_source := SUBSTR(NULL, 1,30);
216139 
216140 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
216141    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
216142 
216143    xla_accounting_err_pkg.build_message
216144       (p_appli_s_name            => 'XLA'
216145       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
216146       ,p_token_1                 => 'ACCT_ATTR_NAME'
216147       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
216148       ,p_token_2                 => 'PRODUCT_NAME'
216149       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
216150       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
216151       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
216152       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
216153 
216154 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
216155    --
216156    -- following sets the accounting attributes needed to reverse
216157    -- accounting for a distributeion
216158    --
216159    xla_ae_lines_pkg.SetTrxReversalAttrs
216160       (p_event_id              => l_event_id
216161       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
216162       ,p_trx_reversal_source   => l_trx_reversal_source);
216163 
216164 END IF;
216165 
216166 
216167 ----------------------------------------------------------------
216168 -- 4262811 -  update the header statuses to invalid in need be
216169 ----------------------------------------------------------------
216170 --
216171 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
216172 
216173 
216174   -----------------------------------------------
216175   -- No accrual reversal for the event class/type
216176   -----------------------------------------------
216177 ----------------------------------------------------------------
216178 
216179 --
216180 -- this ends the header loop iteration for one bulk fetch
216181 --
216182 END LOOP;
216183 
216184 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
216185 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
216186 
216187 --
216188 -- insert dummy rows into lines gt table that were created due to
216189 -- transaction reversals
216190 --
216191 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
216192    l_result := XLA_AE_LINES_PKG.InsertLines;
216193 END IF;
216194 
216195 --
216196 -- reset the temp_line_num for each set of events fetched from header
216197 -- cursor rather than doing it for each new event in line cursor
216198 -- Bug 3939231
216199 --
216200 xla_ae_lines_pkg.g_temp_line_num := 0;
216201 
216202 
216203 
216204 --
216205 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
216206 --
216207 --
216208 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
216209 
216210       trace
216211          (p_msg      => 'SQL - FETCH line_cur'
216212          ,p_level    => C_LEVEL_STATEMENT
216213          ,p_module   => l_log_module);
216214 
216215 END IF;
216216 --
216217 --
216218 LOOP
216219   --
216220   FETCH line_cur BULK COLLECT INTO
216221         l_array_entity_id
216222       , l_array_legal_entity_id
216223       , l_array_entity_code
216224       , l_array_transaction_num
216225       , l_array_event_id
216226       , l_array_class_code
216227       , l_array_event_type
216228       , l_array_event_number
216229       , l_array_event_date
216230       , l_array_transaction_date
216231       , l_array_reference_num_1
216232       , l_array_reference_num_2
216233       , l_array_reference_num_3
216234       , l_array_reference_num_4
216235       , l_array_reference_char_1
216236       , l_array_reference_char_2
216237       , l_array_reference_char_3
216238       , l_array_reference_char_4
216239       , l_array_reference_date_1
216240       , l_array_reference_date_2
216241       , l_array_reference_date_3
216242       , l_array_reference_date_4
216243       , l_array_event_created_by
216244       , l_array_budgetary_control_flag
216245       , l_array_extract_line_num 
216246       , l_array_source_2
216247       , l_array_source_3
216248       , l_array_source_4
216249       , l_array_source_9
216250       , l_array_source_10
216251       , l_array_source_11
216252       , l_array_source_17
216253       , l_array_source_29
216254       , l_array_source_35
216255       , l_array_source_36
216256       , l_array_source_37
216257       , l_array_source_38
216258       , l_array_source_39
216259       , l_array_source_40
216260       , l_array_source_42
216261       LIMIT l_rows;
216262 
216263   --
216264   IF (C_LEVEL_EVENT >= g_log_level) THEN
216265             trace
216266                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
216267                ,p_level    => C_LEVEL_EVENT
216268                ,p_module   => l_log_module);
216269   END IF;
216270   --
216271   EXIT WHEN l_array_entity_id.count = 0;
216272 
216273   XLA_AE_LINES_PKG.g_rec_lines := null;
216274 
216275 --
216276 -- Bug 4458708
216277 --
216278 XLA_AE_LINES_PKG.g_LineNumber := 0;
216279 --
216280 --
216281 
216282 FOR Idx IN 1..l_array_event_id.count LOOP
216283    --
216284    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
216285    --
216289    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
216286    l_event_id := l_array_event_id(idx);  -- 5648433
216287 
216288    --
216290    --
216291 
216292    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
216293              (g_array_event(l_event_id).array_value_num('header_index'))
216294          ,'N'
216295          ) <> 'Y'
216296    THEN
216297       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
216298          trace
216299             (p_msg      => 'Trancaction revesal option is not Y '
216300             ,p_level    => C_LEVEL_STATEMENT
216301             ,p_module   => l_log_module);
216302       END IF;
216303 
216304 --
216305 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
216306 --
216307 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
216308 --
216309 -- set event info as cache for other routines to refer event attributes
216310 --
216311 
216312 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
216313    l_previous_event_id := l_event_id;
216314 
216315    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
216316       (p_application_id           => p_application_id
216317       ,p_primary_ledger_id        => p_primary_ledger_id
216318       ,p_base_ledger_id           => p_base_ledger_id
216319       ,p_target_ledger_id         => p_target_ledger_id
216320       ,p_entity_id                => l_array_entity_id(Idx)
216321       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
216322       ,p_entity_code              => l_array_entity_code(Idx)
216323       ,p_transaction_num          => l_array_transaction_num(Idx)
216324       ,p_event_id                 => l_array_event_id(Idx)
216325       ,p_event_class_code         => l_array_class_code(Idx)
216326       ,p_event_type_code          => l_array_event_type(Idx)
216327       ,p_event_number             => l_array_event_number(Idx)
216328       ,p_event_date               => l_array_event_date(Idx)
216329       ,p_transaction_date         => l_array_transaction_date(Idx)
216330       ,p_reference_num_1          => l_array_reference_num_1(Idx)
216331       ,p_reference_num_2          => l_array_reference_num_2(Idx)
216332       ,p_reference_num_3          => l_array_reference_num_3(Idx)
216333       ,p_reference_num_4          => l_array_reference_num_4(Idx)
216334       ,p_reference_char_1         => l_array_reference_char_1(Idx)
216335       ,p_reference_char_2         => l_array_reference_char_2(Idx)
216336       ,p_reference_char_3         => l_array_reference_char_3(Idx)
216337       ,p_reference_char_4         => l_array_reference_char_4(Idx)
216338       ,p_reference_date_1         => l_array_reference_date_1(Idx)
216339       ,p_reference_date_2         => l_array_reference_date_2(Idx)
216340       ,p_reference_date_3         => l_array_reference_date_3(Idx)
216341       ,p_reference_date_4         => l_array_reference_date_4(Idx)
216342       ,p_event_created_by         => l_array_event_created_by(Idx)
216343       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
216344        --
216345 END IF;
216346 
216347 
216348 
216349 --
216350 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
216351 
216352 l_acct_reversal_source := SUBSTR(NULL, 1,30);
216353 
216354 IF l_continue_with_lines THEN
216355    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
216356       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
216357 
216358       xla_accounting_err_pkg.build_message
216359          (p_appli_s_name            => 'XLA'
216360          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
216361          ,p_token_1                 => 'LINE_NUMBER'
216362          ,p_value_1                 => l_array_extract_line_num(Idx)
216363          ,p_token_2                 => 'PRODUCT_NAME'
216364          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
216365          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
216366          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
216367          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
216368 
216369    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
216370       --
216371       -- following sets the accounting attributes needed to reverse
216372       -- accounting for a distributeion
216373       --
216374 
216375       --
216376       -- 5217187
216377       --
216378       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
216379       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
216380                                        g_array_event(l_event_id).array_value_num('header_index'));
216381       --
216382       --
216383 
216384       -- No reversal code generated
216385 
216386       xla_ae_lines_pkg.SetAcctReversalAttrs
216387          (p_event_id             => l_event_id
216388          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
216389          ,p_calculate_acctd_flag => l_calculate_acctd_flag
216390          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
216391    END IF;
216392 
216393    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
216394        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
216395 
216396 --
216397 AcctLineType_387 (
216398  p_application_id  => p_application_id
216399  ,p_event_id     => l_event_id
216400  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216401  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216402  ,p_actual_flag => l_actual_flag
216403  ,p_balance_type_code => l_balance_type_code
216404  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216405  
216406  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216407  , p_source_3 => l_array_source_3(Idx)
216408  , p_source_9 => l_array_source_9(Idx)
216409  , p_source_29 => l_array_source_29(Idx)
216410  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216414  , p_source_38 => l_array_source_38(Idx)
216411  , p_source_35 => l_array_source_35(Idx)
216412  , p_source_36 => l_array_source_36(Idx)
216413  , p_source_37 => l_array_source_37(Idx)
216415  , p_source_39 => l_array_source_39(Idx)
216416  , p_source_40 => l_array_source_40(Idx)
216417  , p_source_42 => l_array_source_42(Idx)
216418  );
216419 If(l_balance_type_code = 'A') THEN
216420   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216421 END IF;
216422 
216423 --
216424 
216425 
216426 --
216427 AcctLineType_388 (
216428  p_application_id  => p_application_id
216429  ,p_event_id     => l_event_id
216430  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216431  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216432  ,p_actual_flag => l_actual_flag
216433  ,p_balance_type_code => l_balance_type_code
216434  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216435  
216436  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216437  , p_source_2 => l_array_source_2(Idx)
216438  , p_source_3 => l_array_source_3(Idx)
216439  , p_source_29 => l_array_source_29(Idx)
216440  , p_source_35 => l_array_source_35(Idx)
216441  , p_source_36 => l_array_source_36(Idx)
216442  , p_source_37 => l_array_source_37(Idx)
216443  , p_source_38 => l_array_source_38(Idx)
216444  , p_source_39 => l_array_source_39(Idx)
216445  , p_source_40 => l_array_source_40(Idx)
216446  , p_source_42 => l_array_source_42(Idx)
216447  );
216448 If(l_balance_type_code = 'A') THEN
216449   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216450 END IF;
216451 
216452 --
216453 
216454 
216455 --
216456 AcctLineType_389 (
216457  p_application_id  => p_application_id
216458  ,p_event_id     => l_event_id
216459  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216460  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216461  ,p_actual_flag => l_actual_flag
216462  ,p_balance_type_code => l_balance_type_code
216463  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216464  
216465  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216466  , p_source_3 => l_array_source_3(Idx)
216467  , p_source_4 => l_array_source_4(Idx)
216468  , p_source_17 => l_array_source_17(Idx)
216469  , p_source_29 => l_array_source_29(Idx)
216470  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216471  , p_source_35 => l_array_source_35(Idx)
216472  , p_source_36 => l_array_source_36(Idx)
216473  , p_source_37 => l_array_source_37(Idx)
216474  , p_source_38 => l_array_source_38(Idx)
216475  , p_source_39 => l_array_source_39(Idx)
216476  , p_source_40 => l_array_source_40(Idx)
216477  , p_source_42 => l_array_source_42(Idx)
216478  );
216479 If(l_balance_type_code = 'A') THEN
216480   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216481 END IF;
216482 
216483 --
216484 
216485 
216486 --
216487 AcctLineType_390 (
216488  p_application_id  => p_application_id
216489  ,p_event_id     => l_event_id
216490  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216491  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216492  ,p_actual_flag => l_actual_flag
216493  ,p_balance_type_code => l_balance_type_code
216494  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216495  
216496  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216497  , p_source_3 => l_array_source_3(Idx)
216498  , p_source_29 => l_array_source_29(Idx)
216499  , p_source_35 => l_array_source_35(Idx)
216500  , p_source_36 => l_array_source_36(Idx)
216501  , p_source_37 => l_array_source_37(Idx)
216502  , p_source_38 => l_array_source_38(Idx)
216503  , p_source_39 => l_array_source_39(Idx)
216504  , p_source_40 => l_array_source_40(Idx)
216505  , p_source_42 => l_array_source_42(Idx)
216506  );
216507 If(l_balance_type_code = 'A') THEN
216508   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216509 END IF;
216510 
216511 --
216512 
216513 
216514 --
216515 AcctLineType_391 (
216516  p_application_id  => p_application_id
216517  ,p_event_id     => l_event_id
216518  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216519  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216520  ,p_actual_flag => l_actual_flag
216521  ,p_balance_type_code => l_balance_type_code
216522  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216523  
216524  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216525  , p_source_3 => l_array_source_3(Idx)
216526  , p_source_10 => l_array_source_10(Idx)
216527  , p_source_17 => l_array_source_17(Idx)
216528  , p_source_29 => l_array_source_29(Idx)
216529  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216530  , p_source_35 => l_array_source_35(Idx)
216531  , p_source_36 => l_array_source_36(Idx)
216532  , p_source_37 => l_array_source_37(Idx)
216533  , p_source_38 => l_array_source_38(Idx)
216534  , p_source_39 => l_array_source_39(Idx)
216535  , p_source_40 => l_array_source_40(Idx)
216536  , p_source_42 => l_array_source_42(Idx)
216537  );
216538 If(l_balance_type_code = 'A') THEN
216539   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216540 END IF;
216541 
216542 --
216543 
216544 
216545 --
216546 AcctLineType_392 (
216547  p_application_id  => p_application_id
216548  ,p_event_id     => l_event_id
216549  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216550  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216551  ,p_actual_flag => l_actual_flag
216552  ,p_balance_type_code => l_balance_type_code
216553  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216554  
216555  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216556  , p_source_3 => l_array_source_3(Idx)
216557  , p_source_29 => l_array_source_29(Idx)
216558  , p_source_35 => l_array_source_35(Idx)
216559  , p_source_36 => l_array_source_36(Idx)
216560  , p_source_37 => l_array_source_37(Idx)
216561  , p_source_38 => l_array_source_38(Idx)
216562  , p_source_39 => l_array_source_39(Idx)
216566 If(l_balance_type_code = 'A') THEN
216563  , p_source_40 => l_array_source_40(Idx)
216564  , p_source_42 => l_array_source_42(Idx)
216565  );
216567   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216568 END IF;
216569 
216570 --
216571 
216572 
216573 --
216574 AcctLineType_393 (
216575  p_application_id  => p_application_id
216576  ,p_event_id     => l_event_id
216577  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216578  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216579  ,p_actual_flag => l_actual_flag
216580  ,p_balance_type_code => l_balance_type_code
216581  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216582  
216583  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216584  , p_source_3 => l_array_source_3(Idx)
216585  , p_source_10 => l_array_source_10(Idx)
216586  , p_source_17 => l_array_source_17(Idx)
216587  , p_source_29 => l_array_source_29(Idx)
216588  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216589  , p_source_35 => l_array_source_35(Idx)
216590  , p_source_36 => l_array_source_36(Idx)
216591  , p_source_37 => l_array_source_37(Idx)
216592  , p_source_38 => l_array_source_38(Idx)
216593  , p_source_39 => l_array_source_39(Idx)
216594  , p_source_40 => l_array_source_40(Idx)
216595  , p_source_42 => l_array_source_42(Idx)
216596  );
216597 If(l_balance_type_code = 'A') THEN
216598   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216599 END IF;
216600 
216601 --
216602 
216603 
216604 --
216605 AcctLineType_394 (
216606  p_application_id  => p_application_id
216607  ,p_event_id     => l_event_id
216608  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216609  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216610  ,p_actual_flag => l_actual_flag
216611  ,p_balance_type_code => l_balance_type_code
216612  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216613  
216614  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216615  , p_source_3 => l_array_source_3(Idx)
216616  , p_source_11 => l_array_source_11(Idx)
216617  , p_source_17 => l_array_source_17(Idx)
216618  , p_source_29 => l_array_source_29(Idx)
216619  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216620  , p_source_35 => l_array_source_35(Idx)
216621  , p_source_36 => l_array_source_36(Idx)
216622  , p_source_37 => l_array_source_37(Idx)
216623  , p_source_38 => l_array_source_38(Idx)
216624  , p_source_39 => l_array_source_39(Idx)
216625  , p_source_40 => l_array_source_40(Idx)
216626  , p_source_42 => l_array_source_42(Idx)
216627  );
216628 If(l_balance_type_code = 'A') THEN
216629   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216630 END IF;
216631 
216632 --
216633 
216634 
216635 --
216636 AcctLineType_395 (
216637  p_application_id  => p_application_id
216638  ,p_event_id     => l_event_id
216639  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216640  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216641  ,p_actual_flag => l_actual_flag
216642  ,p_balance_type_code => l_balance_type_code
216643  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216644  
216645  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216646  , p_source_3 => l_array_source_3(Idx)
216647  , p_source_19 => g_array_event(l_event_id).array_value_char('source_19')
216648  , p_source_29 => l_array_source_29(Idx)
216649  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216650  , p_source_35 => l_array_source_35(Idx)
216651  , p_source_36 => l_array_source_36(Idx)
216652  , p_source_37 => l_array_source_37(Idx)
216653  , p_source_38 => l_array_source_38(Idx)
216654  , p_source_39 => l_array_source_39(Idx)
216655  , p_source_40 => l_array_source_40(Idx)
216656  );
216657 If(l_balance_type_code = 'A') THEN
216658   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216659 END IF;
216660 
216661 --
216662 
216663 
216664 --
216665 AcctLineType_396 (
216666  p_application_id  => p_application_id
216667  ,p_event_id     => l_event_id
216668  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216669  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216670  ,p_actual_flag => l_actual_flag
216671  ,p_balance_type_code => l_balance_type_code
216672  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216673  
216674  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216675  , p_source_3 => l_array_source_3(Idx)
216676  , p_source_20 => g_array_event(l_event_id).array_value_char('source_20')
216677  , p_source_29 => l_array_source_29(Idx)
216678  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216679  , p_source_35 => l_array_source_35(Idx)
216680  , p_source_36 => l_array_source_36(Idx)
216681  , p_source_37 => l_array_source_37(Idx)
216682  , p_source_38 => l_array_source_38(Idx)
216683  , p_source_39 => l_array_source_39(Idx)
216684  , p_source_40 => l_array_source_40(Idx)
216685  );
216686 If(l_balance_type_code = 'A') THEN
216687   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216688 END IF;
216689 
216690 --
216691 
216692 
216693 --
216694 AcctLineType_397 (
216695  p_application_id  => p_application_id
216696  ,p_event_id     => l_event_id
216697  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216698  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216699  ,p_actual_flag => l_actual_flag
216700  ,p_balance_type_code => l_balance_type_code
216701  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216702  
216703  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216704  , p_source_2 => l_array_source_2(Idx)
216705  , p_source_3 => l_array_source_3(Idx)
216706  , p_source_29 => l_array_source_29(Idx)
216707  , p_source_35 => l_array_source_35(Idx)
216708  , p_source_36 => l_array_source_36(Idx)
216709  , p_source_37 => l_array_source_37(Idx)
216710  , p_source_38 => l_array_source_38(Idx)
216711  , p_source_39 => l_array_source_39(Idx)
216712  , p_source_40 => l_array_source_40(Idx)
216716   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216713  , p_source_42 => l_array_source_42(Idx)
216714  );
216715 If(l_balance_type_code = 'A') THEN
216717 END IF;
216718 
216719 --
216720 
216721 
216722 --
216723 AcctLineType_398 (
216724  p_application_id  => p_application_id
216725  ,p_event_id     => l_event_id
216726  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216727  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216728  ,p_actual_flag => l_actual_flag
216729  ,p_balance_type_code => l_balance_type_code
216730  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216731  
216732  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216733  , p_source_3 => l_array_source_3(Idx)
216734  , p_source_4 => l_array_source_4(Idx)
216735  , p_source_17 => l_array_source_17(Idx)
216736  , p_source_29 => l_array_source_29(Idx)
216737  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216738  , p_source_35 => l_array_source_35(Idx)
216739  , p_source_36 => l_array_source_36(Idx)
216740  , p_source_37 => l_array_source_37(Idx)
216741  , p_source_38 => l_array_source_38(Idx)
216742  , p_source_39 => l_array_source_39(Idx)
216743  , p_source_40 => l_array_source_40(Idx)
216744  , p_source_42 => l_array_source_42(Idx)
216745  );
216746 If(l_balance_type_code = 'A') THEN
216747   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216748 END IF;
216749 
216750 --
216751 
216752 
216753 --
216754 AcctLineType_399 (
216755  p_application_id  => p_application_id
216756  ,p_event_id     => l_event_id
216757  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216758  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216759  ,p_actual_flag => l_actual_flag
216760  ,p_balance_type_code => l_balance_type_code
216761  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216762  
216763  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216764  , p_source_3 => l_array_source_3(Idx)
216765  , p_source_9 => l_array_source_9(Idx)
216766  , p_source_29 => l_array_source_29(Idx)
216767  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216768  , p_source_35 => l_array_source_35(Idx)
216769  , p_source_36 => l_array_source_36(Idx)
216770  , p_source_37 => l_array_source_37(Idx)
216771  , p_source_38 => l_array_source_38(Idx)
216772  , p_source_39 => l_array_source_39(Idx)
216773  , p_source_40 => l_array_source_40(Idx)
216774  , p_source_42 => l_array_source_42(Idx)
216775  );
216776 If(l_balance_type_code = 'A') THEN
216777   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216778 END IF;
216779 
216780 --
216781 
216782 
216783 --
216784 AcctLineType_400 (
216785  p_application_id  => p_application_id
216786  ,p_event_id     => l_event_id
216787  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216788  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216789  ,p_actual_flag => l_actual_flag
216790  ,p_balance_type_code => l_balance_type_code
216791  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216792  
216793  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216794  , p_source_3 => l_array_source_3(Idx)
216795  , p_source_29 => l_array_source_29(Idx)
216796  , p_source_35 => l_array_source_35(Idx)
216797  , p_source_36 => l_array_source_36(Idx)
216798  , p_source_37 => l_array_source_37(Idx)
216799  , p_source_38 => l_array_source_38(Idx)
216800  , p_source_39 => l_array_source_39(Idx)
216801  , p_source_40 => l_array_source_40(Idx)
216802  , p_source_42 => l_array_source_42(Idx)
216803  );
216804 If(l_balance_type_code = 'A') THEN
216805   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216806 END IF;
216807 
216808 --
216809 
216810 
216811 --
216812 AcctLineType_401 (
216813  p_application_id  => p_application_id
216814  ,p_event_id     => l_event_id
216815  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216816  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216817  ,p_actual_flag => l_actual_flag
216818  ,p_balance_type_code => l_balance_type_code
216819  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216820  
216821  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216822  , p_source_3 => l_array_source_3(Idx)
216823  , p_source_10 => l_array_source_10(Idx)
216824  , p_source_17 => l_array_source_17(Idx)
216825  , p_source_29 => l_array_source_29(Idx)
216826  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216827  , p_source_35 => l_array_source_35(Idx)
216828  , p_source_36 => l_array_source_36(Idx)
216829  , p_source_37 => l_array_source_37(Idx)
216830  , p_source_38 => l_array_source_38(Idx)
216831  , p_source_39 => l_array_source_39(Idx)
216832  , p_source_40 => l_array_source_40(Idx)
216833  , p_source_42 => l_array_source_42(Idx)
216834  );
216835 If(l_balance_type_code = 'A') THEN
216836   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216837 END IF;
216838 
216839 --
216840 
216841 
216842 --
216843 AcctLineType_402 (
216844  p_application_id  => p_application_id
216845  ,p_event_id     => l_event_id
216846  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216847  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216848  ,p_actual_flag => l_actual_flag
216849  ,p_balance_type_code => l_balance_type_code
216850  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216851  
216852  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216853  , p_source_3 => l_array_source_3(Idx)
216854  , p_source_29 => l_array_source_29(Idx)
216855  , p_source_35 => l_array_source_35(Idx)
216856  , p_source_36 => l_array_source_36(Idx)
216857  , p_source_37 => l_array_source_37(Idx)
216858  , p_source_38 => l_array_source_38(Idx)
216859  , p_source_39 => l_array_source_39(Idx)
216860  , p_source_40 => l_array_source_40(Idx)
216861  , p_source_42 => l_array_source_42(Idx)
216862  );
216863 If(l_balance_type_code = 'A') THEN
216864   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216865 END IF;
216866 
216870 --
216867 --
216868 
216869 
216871 AcctLineType_403 (
216872  p_application_id  => p_application_id
216873  ,p_event_id     => l_event_id
216874  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216875  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216876  ,p_actual_flag => l_actual_flag
216877  ,p_balance_type_code => l_balance_type_code
216878  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216879  
216880  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216881  , p_source_3 => l_array_source_3(Idx)
216882  , p_source_10 => l_array_source_10(Idx)
216883  , p_source_17 => l_array_source_17(Idx)
216884  , p_source_29 => l_array_source_29(Idx)
216885  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216886  , p_source_35 => l_array_source_35(Idx)
216887  , p_source_36 => l_array_source_36(Idx)
216888  , p_source_37 => l_array_source_37(Idx)
216889  , p_source_38 => l_array_source_38(Idx)
216890  , p_source_39 => l_array_source_39(Idx)
216891  , p_source_40 => l_array_source_40(Idx)
216892  , p_source_42 => l_array_source_42(Idx)
216893  );
216894 If(l_balance_type_code = 'A') THEN
216895   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216896 END IF;
216897 
216898 --
216899 
216900 
216901 --
216902 AcctLineType_404 (
216903  p_application_id  => p_application_id
216904  ,p_event_id     => l_event_id
216905  ,p_calculate_acctd_flag => l_calculate_acctd_flag
216906  ,p_calculate_g_l_flag => l_calculate_g_l_flag
216907  ,p_actual_flag => l_actual_flag
216908  ,p_balance_type_code => l_balance_type_code
216909  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
216910  
216911  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
216912  , p_source_3 => l_array_source_3(Idx)
216913  , p_source_11 => l_array_source_11(Idx)
216914  , p_source_17 => l_array_source_17(Idx)
216915  , p_source_29 => l_array_source_29(Idx)
216916  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
216917  , p_source_35 => l_array_source_35(Idx)
216918  , p_source_36 => l_array_source_36(Idx)
216919  , p_source_37 => l_array_source_37(Idx)
216920  , p_source_38 => l_array_source_38(Idx)
216921  , p_source_39 => l_array_source_39(Idx)
216922  , p_source_40 => l_array_source_40(Idx)
216923  , p_source_42 => l_array_source_42(Idx)
216924  );
216925 If(l_balance_type_code = 'A') THEN
216926   l_actual_gain_loss_ref := l_gain_or_loss_ref;
216927 END IF;
216928 
216929 --
216930 
216931       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
216932       -- or secondary ledger that has different currency with primary
216933       -- or alc that is calculated by sla
216934       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
216935             (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'))
216936 
216937 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
216938 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
216939           AND (l_actual_flag = 'A')) THEN
216940         XLA_AE_LINES_PKG.CreateGainOrLossLines(
216941           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
216942          ,p_application_id   => p_application_id
216943          ,p_amb_context_code => 'DEFAULT'
216944          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
216945          ,p_event_class_code => C_EVENT_CLASS_CODE
216946          ,p_event_type_code  => C_EVENT_TYPE_CODE
216947          
216948          ,p_gain_ccid        => -1
216949          ,p_loss_ccid        => -1
216950 
216951          ,p_actual_flag      => l_actual_flag
216952          ,p_enc_flag         => null
216953          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
216954          ,p_enc_g_l_ref      => null
216955          );
216956       END IF;
216957    END IF;
216958 END IF;
216959 
216960    ELSE
216961       --
216962       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
216963       --
216964       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
216965          trace
216966             (p_msg      => 'Trancaction revesal option is Y'
216967             ,p_level    => C_LEVEL_STATEMENT
216968             ,p_module   => l_log_module);
216969       END IF;
216970    END IF;
216971 
216972 END LOOP;
216973 l_result := XLA_AE_LINES_PKG.InsertLines ;
216974 end loop;
216975 close line_cur;
216976 
216977 
216978 --
216979 -- insert headers into xla_ae_headers_gt table
216980 --
216981 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
216982 
216983 -- insert into errors table here.
216984 
216985 END LOOP;
216986 
216987 --
216988 -- 4865292
216989 --
216990 -- Compare g_hdr_extract_count with event count in
216991 -- CreateHeadersAndLines.
216992 --
216993 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
216994 
216995 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
216996    trace (p_msg     => '# rows extracted from header extract objects '
216997                     || ' (running total): '
216998                     || g_hdr_extract_count
216999          ,p_level   => C_LEVEL_STATEMENT
217000          ,p_module  => l_log_module);
217001 END IF;
217002 
217003 CLOSE header_cur;
217004 --
217005 
217006 --
217007 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
217008    trace
217009       (p_msg      => 'END of EventClass_432'
217010       ,p_level    => C_LEVEL_PROCEDURE
217011       ,p_module   => l_log_module);
217012 END IF;
217013 --
217014 RETURN l_result;
217015 EXCEPTION
217016 WHEN xla_exceptions_pkg.application_exception THEN
217017    
217018 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
217019 
217020    
217024 
217021 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
217022 
217023    RAISE;
217025 WHEN NO_DATA_FOUND THEN
217026 
217027 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
217028 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
217029 
217030 FOR header_record IN header_cur
217031 LOOP
217032     l_array_header_events(header_record.event_id) := header_record.event_id;
217033 END LOOP;
217034 
217035 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
217036 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
217037 
217038 fnd_file.put_line(fnd_file.LOG, '                    ');
217039 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
217040 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
217041 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
217042 
217043 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
217044 LOOP
217045 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
217046 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
217047         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
217048 	END IF;
217049 END LOOP;
217050 
217051 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
217052 fnd_file.put_line(fnd_file.LOG, '                    ');
217053 
217054 
217055 xla_exceptions_pkg.raise_message
217056       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_432');
217057 
217058 
217059 WHEN OTHERS THEN
217060    xla_exceptions_pkg.raise_message
217061       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_432');
217062 END EventClass_432;
217063 --
217064 
217065 ---------------------------------------
217066 --
217067 -- PRIVATE PROCEDURE
217068 --         insert_sources_433
217069 --
217070 ----------------------------------------
217071 --
217072 PROCEDURE insert_sources_433(
217073                                 p_target_ledger_id       IN NUMBER
217074                               , p_language               IN VARCHAR2
217075                               , p_sla_ledger_id          IN NUMBER
217076                               , p_pad_start_date         IN DATE
217077                               , p_pad_end_date           IN DATE
217078                          )
217079 IS
217080 
217081 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'UNPLANNED_DEPRECIATION_ALL';
217082 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'UNPLANNED_DEPRECIATION';
217083 p_apps_owner                   VARCHAR2(30);
217084 l_log_module                   VARCHAR2(240);
217085 BEGIN
217086 IF g_log_enabled THEN
217087       l_log_module := C_DEFAULT_MODULE||'.insert_sources_433';
217088 END IF;
217089 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
217090 
217091       trace
217092          (p_msg      => 'BEGIN of insert_sources_433'
217093          ,p_level    => C_LEVEL_PROCEDURE
217094          ,p_module   => l_log_module);
217095 
217096 END IF;
217097 
217098 -- select APPS owner
217099 SELECT oracle_username
217100   INTO p_apps_owner
217101   FROM fnd_oracle_userid
217102  WHERE read_only_flag = 'U'
217103 ;
217104 
217105 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
217106       trace
217107          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
217108                         ' - p_language = '||p_language||
217109                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
217110                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
217111                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
217112                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
217113          ,p_level    => C_LEVEL_STATEMENT
217114          ,p_module   => l_log_module);
217115 END IF;
217116 
217117 
217118 --
217119 INSERT INTO xla_diag_sources --hdr2
217120 (
217121         event_id
217122       , ledger_id
217123       , sla_ledger_id
217124       , description_language
217125       , object_name
217126       , object_type_code
217127       , line_number
217128       , source_application_id
217129       , source_type_code
217130       , source_code
217131       , source_value
217132       , source_meaning
217133       , created_by
217134       , creation_date
217135       , last_update_date
217136       , last_updated_by
217137       , last_update_login
217138       , program_update_date
217139       , program_application_id
217140       , program_id
217141       , request_id
217142 )
217143 SELECT
217144         event_id
217145       , p_target_ledger_id
217146       , p_sla_ledger_id
217147       , p_language
217148       , object_name
217149       , object_type_code
217150       , line_number
217151       , source_application_id
217152       , source_type_code
217153       , source_code
217154       , SUBSTR(source_value ,1,1996)
217155       , SUBSTR(source_meaning ,1,200)
217156       , xla_environment_pkg.g_Usr_Id
217157       , TRUNC(SYSDATE)
217158       , TRUNC(SYSDATE)
217159       , xla_environment_pkg.g_Usr_Id
217160       , xla_environment_pkg.g_Login_Id
217161       , TRUNC(SYSDATE)
217162       , xla_environment_pkg.g_Prog_Appl_Id
217163       , xla_environment_pkg.g_Prog_Id
217164       , xla_environment_pkg.g_Req_Id
217165   FROM (
217166        SELECT xet.event_id                  event_id
217167             , 0                          line_number
217168             , CASE r
217169                WHEN 1 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
217170                 WHEN 2 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
217171                 WHEN 3 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
217175               END                           object_name
217172                 WHEN 4 THEN 'FA_XLA_EXT_HEADERS_B_GT' 
217173                 
217174                ELSE null
217176             , CASE r
217177                 WHEN 1 THEN 'HEADER' 
217178                 WHEN 2 THEN 'HEADER' 
217179                 WHEN 3 THEN 'HEADER' 
217180                 WHEN 4 THEN 'HEADER' 
217181                 
217182                 ELSE null
217183               END                           object_type_code
217184             , CASE r
217185                 WHEN 1 THEN '140' 
217186                 WHEN 2 THEN '140' 
217187                 WHEN 3 THEN '140' 
217188                 WHEN 4 THEN '140' 
217189                 
217190                 ELSE null
217191               END                           source_application_id
217192             , 'S'             source_type_code
217193             , CASE r
217194                 WHEN 1 THEN 'PERIOD_CLOSE_DATE' 
217195                 WHEN 2 THEN 'DEFAULT_CCID' 
217196                 WHEN 3 THEN 'ACCOUNTING_DATE' 
217197                 WHEN 4 THEN 'TRANSFER_TO_GL_FLAG' 
217198                 
217199                 ELSE null
217200               END                           source_code
217201             , CASE r
217202                 WHEN 1 THEN TO_CHAR(h1.PERIOD_CLOSE_DATE)
217203                 WHEN 2 THEN TO_CHAR(h1.DEFAULT_CCID)
217204                 WHEN 3 THEN TO_CHAR(h1.ACCOUNTING_DATE)
217205                 WHEN 4 THEN TO_CHAR(h1.TRANSFER_TO_GL_FLAG)
217206                 
217207                 ELSE null
217208               END                           source_value
217209             , null              source_meaning
217210          FROM xla_events_gt     xet  
217211       , FA_XLA_EXT_HEADERS_B_GT  h1
217212              ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
217213          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
217214            AND xet.event_class_code = C_EVENT_CLASS_CODE
217215               AND h1.event_id = xet.event_id
217216 
217217 )
217218 ;
217219 --
217220 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
217221 
217222       trace
217223          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
217224          ,p_level    => C_LEVEL_STATEMENT
217225          ,p_module   => l_log_module);
217226 
217227 END IF;
217228 --
217229 
217230 
217231 
217232 --
217233 INSERT INTO xla_diag_sources  --line2
217234 (
217235         event_id
217236       , ledger_id
217237       , sla_ledger_id
217238       , description_language
217239       , object_name
217240       , object_type_code
217241       , line_number
217242       , source_application_id
217243       , source_type_code
217244       , source_code
217245       , source_value
217246       , source_meaning
217247       , created_by
217248       , creation_date
217249       , last_update_date
217250       , last_updated_by
217251       , last_update_login
217252       , program_update_date
217253       , program_application_id
217254       , program_id
217255       , request_id
217256 )
217257 SELECT  event_id
217258       , p_target_ledger_id
217259       , p_sla_ledger_id
217260       , p_language
217261       , object_name
217262       , object_type_code
217263       , line_number
217264       , source_application_id
217265       , source_type_code
217266       , source_code
217267       , SUBSTR(source_value,1,1996)
217268       , SUBSTR(source_meaning ,1,200)
217269       , xla_environment_pkg.g_Usr_Id
217270       , TRUNC(SYSDATE)
217271       , TRUNC(SYSDATE)
217272       , xla_environment_pkg.g_Usr_Id
217273       , xla_environment_pkg.g_Login_Id
217274       , TRUNC(SYSDATE)
217275       , xla_environment_pkg.g_Prog_Appl_Id
217276       , xla_environment_pkg.g_Prog_Id
217277       , xla_environment_pkg.g_Req_Id
217278   FROM (
217279        SELECT xet.event_id                  event_id
217280             , l2.line_number                 line_number
217281             , CASE r
217282                WHEN 1 THEN 'FA_XLA_EXT_LINES_B_GT' 
217283                 WHEN 2 THEN 'FA_XLA_EXT_LINES_B_GT' 
217284                 WHEN 3 THEN 'FA_XLA_EXT_LINES_B_GT' 
217285                 WHEN 4 THEN 'FA_XLA_EXT_LINES_B_GT' 
217286                 WHEN 5 THEN 'FA_XLA_EXT_LINES_B_GT' 
217287                 WHEN 6 THEN 'FA_XLA_EXT_LINES_B_GT' 
217288                 WHEN 7 THEN 'FA_XLA_EXT_LINES_B_GT' 
217289                 WHEN 8 THEN 'FA_XLA_EXT_LINES_B_GT' 
217290                 WHEN 9 THEN 'FA_XLA_EXT_LINES_B_GT' 
217291                 WHEN 10 THEN 'FA_XLA_EXT_LINES_B_GT' 
217292                 
217293                ELSE null
217294               END                           object_name
217295             , CASE r
217296                 WHEN 1 THEN 'LINE' 
217297                 WHEN 2 THEN 'LINE' 
217298                 WHEN 3 THEN 'LINE' 
217299                 WHEN 4 THEN 'LINE' 
217300                 WHEN 5 THEN 'LINE' 
217301                 WHEN 6 THEN 'LINE' 
217302                 WHEN 7 THEN 'LINE' 
217303                 WHEN 8 THEN 'LINE' 
217304                 WHEN 9 THEN 'LINE' 
217305                 WHEN 10 THEN 'LINE' 
217306                 
217307                 ELSE null
217308               END                           object_type_code
217309             , CASE r
217310                 WHEN 1 THEN '140' 
217311                 WHEN 2 THEN '140' 
217312                 WHEN 3 THEN '140' 
217313                 WHEN 4 THEN '140' 
217314                 WHEN 5 THEN '140' 
217315                 WHEN 6 THEN '140' 
217316                 WHEN 7 THEN '140' 
217317                 WHEN 8 THEN '140' 
217318                 WHEN 9 THEN '140' 
217319                 WHEN 10 THEN '140' 
217320                 
217321                 ELSE null
217325                 WHEN 1 THEN 'GENERATED_CCID' 
217322               END                           source_application_id
217323             , 'S'             source_type_code
217324             , CASE r
217326                 WHEN 2 THEN 'DEPRN_RESERVE_ACCT' 
217327                 WHEN 3 THEN 'GENERATED_OFFSET_CCID' 
217328                 WHEN 4 THEN 'EXPENSE_ACCOUNT_CCID' 
217329                 WHEN 5 THEN 'ADJUSTMENT_TYPE' 
217330                 WHEN 6 THEN 'TRANSACTION_HEADER_ID' 
217331                 WHEN 7 THEN 'ADJUSTMENT_LINE_ID' 
217332                 WHEN 8 THEN 'DISTRIBUTION_TYPE_CODE' 
217333                 WHEN 9 THEN 'ENTERED_AMOUNT' 
217334                 WHEN 10 THEN 'CURRENCY_CODE' 
217335                 
217336                 ELSE null
217337               END                           source_code
217338             , CASE r
217339                 WHEN 1 THEN TO_CHAR(l2.GENERATED_CCID)
217340                 WHEN 2 THEN TO_CHAR(l2.DEPRN_RESERVE_ACCT)
217341                 WHEN 3 THEN TO_CHAR(l2.GENERATED_OFFSET_CCID)
217342                 WHEN 4 THEN TO_CHAR(l2.EXPENSE_ACCOUNT_CCID)
217343                 WHEN 5 THEN TO_CHAR(l2.ADJUSTMENT_TYPE)
217344                 WHEN 6 THEN TO_CHAR(l2.TRANSACTION_HEADER_ID)
217345                 WHEN 7 THEN TO_CHAR(l2.ADJUSTMENT_LINE_ID)
217346                 WHEN 8 THEN TO_CHAR(l2.DISTRIBUTION_TYPE_CODE)
217347                 WHEN 9 THEN TO_CHAR(l2.ENTERED_AMOUNT)
217348                 WHEN 10 THEN TO_CHAR(l2.CURRENCY_CODE)
217349                 
217350                 ELSE null
217351               END                           source_value
217352             , null              source_meaning
217353          FROM  xla_events_gt     xet  
217354         , FA_XLA_EXT_LINES_B_GT  l2
217355             , (select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
217356         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
217357           AND xet.event_class_code = C_EVENT_CLASS_CODE
217358             AND l2.event_id          = xet.event_id
217359   AND l2.ledger_id (+)  = p_sla_ledger_id
217360 
217361 )
217362 ;
217363 --
217364 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
217365 
217366       trace
217367          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
217368          ,p_level    => C_LEVEL_STATEMENT
217369          ,p_module   => l_log_module);
217370 
217371 END IF;
217372 
217373 
217374 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
217375       trace
217376          (p_msg      => 'END of insert_sources_433'
217377          ,p_level    => C_LEVEL_PROCEDURE
217378          ,p_module   => l_log_module);
217379 END IF;
217380 EXCEPTION
217381   WHEN xla_exceptions_pkg.application_exception THEN
217382       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
217383             trace
217384                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
217385                ,p_level    => C_LEVEL_EXCEPTION
217386                ,p_module   => l_log_module);
217387       END IF;
217388       RAISE;
217389   WHEN OTHERS THEN
217390       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
217391             trace
217392                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
217393                ,p_level    => C_LEVEL_EXCEPTION
217394                ,p_module   => l_log_module);
217395        END IF;
217396        xla_exceptions_pkg.raise_message
217397            (p_location => 'XLA_00140_AAD_S_000002_PKG.insert_sources_433');
217398 END insert_sources_433;
217399 --
217400 
217401 ---------------------------------------
217402 --
217403 -- PRIVATE FUNCTION
217404 --         EventClass_433
217405 --
217406 ----------------------------------------
217407 --
217408 FUNCTION EventClass_433
217409        (p_application_id         IN NUMBER
217410        ,p_base_ledger_id         IN NUMBER
217411        ,p_target_ledger_id       IN NUMBER
217412        ,p_language               IN VARCHAR2
217413        ,p_currency_code          IN VARCHAR2
217414        ,p_sla_ledger_id          IN NUMBER
217415        ,p_pad_start_date         IN DATE
217416        ,p_pad_end_date           IN DATE
217417        ,p_primary_ledger_id      IN NUMBER)
217418 RETURN BOOLEAN IS
217419 --
217420 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'UNPLANNED_DEPRECIATION_ALL';
217421 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'UNPLANNED_DEPRECIATION';
217422 
217423 l_calculate_acctd_flag   VARCHAR2(1) :='N';
217424 l_calculate_g_l_flag     VARCHAR2(1) :='N';
217425 --
217426 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
217427 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
217428 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
217429 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
217430 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
217431 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
217432 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
217433 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
217434 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
217435 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
217436 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
217437 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
217438 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
217439 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
217440 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
217441 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
217442 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
217443 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
217447 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
217444 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
217445 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
217446 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
217448 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
217449 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
217450 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
217451 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
217452 
217453 l_event_id                             NUMBER;
217454 l_previous_event_id                    NUMBER;
217455 l_first_event_id                       NUMBER;
217456 l_last_event_id                        NUMBER;
217457 
217458 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
217459 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
217460 --
217461 --
217462 l_result                    BOOLEAN := TRUE;
217463 l_rows                      NUMBER  := 1000;
217464 l_event_type_name           VARCHAR2(80) := 'All';
217465 l_event_class_name          VARCHAR2(80) := 'Unplanned Depreciation';
217466 l_description               VARCHAR2(4000);
217467 l_transaction_reversal      NUMBER;
217468 l_ae_header_id              NUMBER;
217469 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
217470 l_log_module                VARCHAR2(240);
217471 --
217472 l_acct_reversal_source      VARCHAR2(30);
217473 l_trx_reversal_source       VARCHAR2(30);
217474 
217475 l_continue_with_lines       BOOLEAN := TRUE;
217476 --
217477 l_acc_rev_gl_date_source    DATE;                      -- 4262811
217478 --
217479 type t_array_event_id is table of number index by binary_integer;
217480 
217481 l_rec_array_event                    t_rec_array_event;
217482 l_null_rec_array_event               t_rec_array_event;
217483 l_array_ae_header_id                 xla_number_array_type;
217484 l_actual_flag                        VARCHAR2(1) := NULL;
217485 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
217486 l_balance_type_code                  VARCHAR2(1) :=NULL;
217487 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
217488 
217489 --
217490 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
217491 --
217492 
217493 TYPE t_array_source_1 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.PERIOD_CLOSE_DATE%TYPE INDEX BY BINARY_INTEGER;
217494 TYPE t_array_source_30 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.DEFAULT_CCID%TYPE INDEX BY BINARY_INTEGER;
217495 TYPE t_array_source_51 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
217496 TYPE t_array_source_52 IS TABLE OF FA_XLA_EXT_HEADERS_B_GT.TRANSFER_TO_GL_FLAG%TYPE INDEX BY BINARY_INTEGER;
217497 
217498 TYPE t_array_source_3 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_CCID%TYPE INDEX BY BINARY_INTEGER;
217499 TYPE t_array_source_10 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DEPRN_RESERVE_ACCT%TYPE INDEX BY BINARY_INTEGER;
217500 TYPE t_array_source_17 IS TABLE OF FA_XLA_EXT_LINES_B_GT.GENERATED_OFFSET_CCID%TYPE INDEX BY BINARY_INTEGER;
217501 TYPE t_array_source_29 IS TABLE OF FA_XLA_EXT_LINES_B_GT.EXPENSE_ACCOUNT_CCID%TYPE INDEX BY BINARY_INTEGER;
217502 TYPE t_array_source_35 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
217503 TYPE t_array_source_36 IS TABLE OF FA_XLA_EXT_LINES_B_GT.TRANSACTION_HEADER_ID%TYPE INDEX BY BINARY_INTEGER;
217504 TYPE t_array_source_37 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ADJUSTMENT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
217505 TYPE t_array_source_38 IS TABLE OF FA_XLA_EXT_LINES_B_GT.DISTRIBUTION_TYPE_CODE%TYPE INDEX BY BINARY_INTEGER;
217506 TYPE t_array_source_39 IS TABLE OF FA_XLA_EXT_LINES_B_GT.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
217507 TYPE t_array_source_40 IS TABLE OF FA_XLA_EXT_LINES_B_GT.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
217508 
217509 l_array_source_1              t_array_source_1;
217510 l_array_source_30              t_array_source_30;
217511 l_array_source_51              t_array_source_51;
217512 l_array_source_52              t_array_source_52;
217513 
217514 l_array_source_3      t_array_source_3;
217515 l_array_source_10      t_array_source_10;
217516 l_array_source_17      t_array_source_17;
217517 l_array_source_29      t_array_source_29;
217518 l_array_source_35      t_array_source_35;
217519 l_array_source_36      t_array_source_36;
217520 l_array_source_37      t_array_source_37;
217521 l_array_source_38      t_array_source_38;
217522 l_array_source_39      t_array_source_39;
217523 l_array_source_40      t_array_source_40;
217524 
217525 --
217526 CURSOR header_cur
217527 IS
217528 SELECT /*+ leading(xet) cardinality(xet,1) */
217529 -- Event Class Code: UNPLANNED_DEPRECIATION
217530     xet.entity_id
217531    ,xet.legal_entity_id
217532    ,xet.entity_code
217533    ,xet.transaction_number
217534    ,xet.event_id
217535    ,xet.event_class_code
217536    ,xet.event_type_code
217537    ,xet.event_number
217538    ,xet.event_date
217539    ,xet.transaction_date
217540    ,xet.reference_num_1
217541    ,xet.reference_num_2
217542    ,xet.reference_num_3
217543    ,xet.reference_num_4
217544    ,xet.reference_char_1
217545    ,xet.reference_char_2
217546    ,xet.reference_char_3
217547    ,xet.reference_char_4
217548    ,xet.reference_date_1
217549    ,xet.reference_date_2
217550    ,xet.reference_date_3
217551    ,xet.reference_date_4
217552    ,xet.event_created_by
217553    ,xet.budgetary_control_flag 
217554   , h1.PERIOD_CLOSE_DATE    source_1
217555   , h1.DEFAULT_CCID    source_30
217556   , h1.ACCOUNTING_DATE    source_51
217557   , h1.TRANSFER_TO_GL_FLAG    source_52
217558   FROM xla_events_gt     xet 
217559   , FA_XLA_EXT_HEADERS_B_GT  h1
217560  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
217561    and xet.event_class_code = C_EVENT_CLASS_CODE
217562    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
217566 
217563 
217564  ORDER BY event_id
217565 ;
217567 
217568 --
217569 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
217570 IS
217571 SELECT  /*+ leading(xet) cardinality(xet,1) */
217572 -- Event Class Code: UNPLANNED_DEPRECIATION
217573     xet.entity_id
217574    ,xet.legal_entity_id
217575    ,xet.entity_code
217576    ,xet.transaction_number
217577    ,xet.event_id
217578    ,xet.event_class_code
217579    ,xet.event_type_code
217580    ,xet.event_number
217581    ,xet.event_date
217582    ,xet.transaction_date
217583    ,xet.reference_num_1
217584    ,xet.reference_num_2
217585    ,xet.reference_num_3
217586    ,xet.reference_num_4
217587    ,xet.reference_char_1
217588    ,xet.reference_char_2
217589    ,xet.reference_char_3
217590    ,xet.reference_char_4
217591    ,xet.reference_date_1
217592    ,xet.reference_date_2
217593    ,xet.reference_date_3
217594    ,xet.reference_date_4
217595    ,xet.event_created_by
217596    ,xet.budgetary_control_flag
217597  , l2.LINE_NUMBER  
217598   , l2.GENERATED_CCID    source_3
217599   , l2.DEPRN_RESERVE_ACCT    source_10
217600   , l2.GENERATED_OFFSET_CCID    source_17
217601   , l2.EXPENSE_ACCOUNT_CCID    source_29
217602   , l2.ADJUSTMENT_TYPE    source_35
217603   , l2.TRANSACTION_HEADER_ID    source_36
217604   , l2.ADJUSTMENT_LINE_ID    source_37
217605   , l2.DISTRIBUTION_TYPE_CODE    source_38
217606   , l2.ENTERED_AMOUNT    source_39
217607   , l2.CURRENCY_CODE    source_40
217608   FROM xla_events_gt     xet 
217609   , FA_XLA_EXT_LINES_B_GT  l2
217610  WHERE xet.event_id between x_first_event_id and x_last_event_id
217611    and xet.event_date between p_pad_start_date and p_pad_end_date
217612    and xet.event_class_code = C_EVENT_CLASS_CODE
217613    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
217614   AND l2.ledger_id = p_sla_ledger_id
217615 ;
217616 
217617 --
217618 BEGIN
217619 IF g_log_enabled THEN
217620    l_log_module := C_DEFAULT_MODULE||'.EventClass_433';
217621 END IF;
217622 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
217623    trace
217624       (p_msg      => 'BEGIN of EventClass_433'
217625       ,p_level    => C_LEVEL_PROCEDURE
217626       ,p_module   => l_log_module);
217627 END IF;
217628 
217629 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
217630    trace
217631       (p_msg      => 'p_application_id = '||p_application_id||
217632                      ' - p_base_ledger_id = '||p_base_ledger_id||
217633                      ' - p_target_ledger_id  = '||p_target_ledger_id||
217634                      ' - p_language = '||p_language||
217635                      ' - p_currency_code = '||p_currency_code||
217636                      ' - p_sla_ledger_id = '||p_sla_ledger_id
217637       ,p_level    => C_LEVEL_STATEMENT
217638       ,p_module   => l_log_module);
217639 END IF;
217640 --
217641 -- initialze arrays
217642 --
217643 g_array_event.DELETE;
217644 l_rec_array_event := l_null_rec_array_event;
217645 --
217646 --------------------------------------
217647 -- 4262811 Initialze MPA Line Number
217648 --------------------------------------
217649 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
217650 
217651 --
217652 
217653 --
217654 OPEN header_cur;
217655 --
217656 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
217657    trace
217658    (p_msg      => 'SQL - FETCH header_cur'
217659    ,p_level    => C_LEVEL_STATEMENT
217660    ,p_module   => l_log_module);
217661 END IF;
217662 --
217663 LOOP
217664 FETCH header_cur BULK COLLECT INTO
217665         l_array_entity_id
217666       , l_array_legal_entity_id
217667       , l_array_entity_code
217668       , l_array_transaction_num
217669       , l_array_event_id
217670       , l_array_class_code
217671       , l_array_event_type
217672       , l_array_event_number
217673       , l_array_event_date
217674       , l_array_transaction_date
217675       , l_array_reference_num_1
217676       , l_array_reference_num_2
217677       , l_array_reference_num_3
217678       , l_array_reference_num_4
217679       , l_array_reference_char_1
217680       , l_array_reference_char_2
217681       , l_array_reference_char_3
217682       , l_array_reference_char_4
217683       , l_array_reference_date_1
217684       , l_array_reference_date_2
217685       , l_array_reference_date_3
217686       , l_array_reference_date_4
217687       , l_array_event_created_by
217688       , l_array_budgetary_control_flag 
217689       , l_array_source_1
217690       , l_array_source_30
217691       , l_array_source_51
217692       , l_array_source_52
217693       LIMIT l_rows;
217694 --
217695 IF (C_LEVEL_EVENT >= g_log_level) THEN
217696    trace
217697    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
217698    ,p_level    => C_LEVEL_EVENT
217699    ,p_module   => l_log_module);
217700 END IF;
217701 --
217702 EXIT WHEN l_array_entity_id.COUNT = 0;
217703 
217704 -- initialize arrays
217705 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
217706 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
217707 
217708 --
217709 -- Bug 4458708
217710 --
217711 XLA_AE_LINES_PKG.g_LineNumber := 0;
217712 
217713 
217714 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
217715 g_last_hdr_idx := l_array_event_id.LAST;
217716 --
217717 -- loop for the headers. Each iteration is for each header extract row
217718 -- fetched in header cursor
217719 --
217720 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
217721 
217722 --
217723 -- set event info as cache for other routines to refer event attributes
217724 --
217725 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
217726    (p_application_id           => p_application_id
217730    ,p_entity_id                => l_array_entity_id(hdr_idx)
217727    ,p_primary_ledger_id        => p_primary_ledger_id
217728    ,p_base_ledger_id           => p_base_ledger_id
217729    ,p_target_ledger_id         => p_target_ledger_id
217731    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
217732    ,p_entity_code              => l_array_entity_code(hdr_idx)
217733    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
217734    ,p_event_id                 => l_array_event_id(hdr_idx)
217735    ,p_event_class_code         => l_array_class_code(hdr_idx)
217736    ,p_event_type_code          => l_array_event_type(hdr_idx)
217737    ,p_event_number             => l_array_event_number(hdr_idx)
217738    ,p_event_date               => l_array_event_date(hdr_idx)
217739    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
217740    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
217741    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
217742    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
217743    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
217744    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
217745    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
217746    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
217747    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
217748    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
217749    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
217750    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
217751    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
217752    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
217753    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
217754 
217755 --
217756 -- set the status of entry to C_VALID (0)
217757 --
217758 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
217759 
217760 --
217761 -- initialize a row for ae header
217762 --
217763 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
217764 
217765 l_event_id := l_array_event_id(hdr_idx);
217766 
217767 --
217768 -- storing the hdr_idx for event. May be used by line cursor.
217769 --
217770 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
217771 
217772 --
217773 -- store sources from header extract. This can be improved to
217774 -- store only those sources from header extract that may be used in lines
217775 --
217776 
217777 g_array_event(l_event_id).array_value_date('source_1') := l_array_source_1(hdr_idx);
217778 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
217779 g_array_event(l_event_id).array_value_date('source_51') := l_array_source_51(hdr_idx);
217780 g_array_event(l_event_id).array_value_char('source_52') := l_array_source_52(hdr_idx);
217781 
217782 --
217783 -- initilaize the status of ae headers for diffrent balance types
217784 -- the status is initialised to C_NOT_CREATED (2)
217785 --
217786 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
217787 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
217788 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
217789 
217790 --
217791 -- call api to validate and store accounting attributes for header
217792 --
217793 
217794 ------------------------------------------------------------
217795 -- Accrual Reversal : to get date for Standard Source (NONE)
217796 ------------------------------------------------------------
217797 l_acc_rev_gl_date_source := NULL;
217798 
217799      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
217800       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_51');
217801      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
217802       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_52');
217803 
217804 
217805 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
217806 
217807 XLA_AE_HEADER_PKG.SetJeCategoryName;
217808 
217809 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
217810 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
217811 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
217812 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
217813 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
217814 
217815 
217816 --
217817 xla_ae_header_pkg.SetHdrDescription(
217818    p_description => Description_140 (
217819    p_application_id => p_application_id 
217820  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
217821    )
217822 );
217823 --
217824 
217825 -- No header level analytical criteria
217826 
217827 --
217828 --accounting attribute enhancement, bug 3612931
217829 --
217830 l_trx_reversal_source := SUBSTR(NULL, 1,30);
217831 
217832 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
217833    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
217834 
217835    xla_accounting_err_pkg.build_message
217836       (p_appli_s_name            => 'XLA'
217837       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
217838       ,p_token_1                 => 'ACCT_ATTR_NAME'
217839       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
217840       ,p_token_2                 => 'PRODUCT_NAME'
217841       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
217842       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
217843       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
217847    --
217844       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
217845 
217846 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
217848    -- following sets the accounting attributes needed to reverse
217849    -- accounting for a distributeion
217850    --
217851    xla_ae_lines_pkg.SetTrxReversalAttrs
217852       (p_event_id              => l_event_id
217853       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
217854       ,p_trx_reversal_source   => l_trx_reversal_source);
217855 
217856 END IF;
217857 
217858 
217859 ----------------------------------------------------------------
217860 -- 4262811 -  update the header statuses to invalid in need be
217861 ----------------------------------------------------------------
217862 --
217863 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
217864 
217865 
217866   -----------------------------------------------
217867   -- No accrual reversal for the event class/type
217868   -----------------------------------------------
217869 ----------------------------------------------------------------
217870 
217871 --
217872 -- this ends the header loop iteration for one bulk fetch
217873 --
217874 END LOOP;
217875 
217876 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
217877 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
217878 
217879 --
217880 -- insert dummy rows into lines gt table that were created due to
217881 -- transaction reversals
217882 --
217883 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
217884    l_result := XLA_AE_LINES_PKG.InsertLines;
217885 END IF;
217886 
217887 --
217888 -- reset the temp_line_num for each set of events fetched from header
217889 -- cursor rather than doing it for each new event in line cursor
217890 -- Bug 3939231
217891 --
217892 xla_ae_lines_pkg.g_temp_line_num := 0;
217893 
217894 
217895 
217896 --
217897 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
217898 --
217899 --
217900 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
217901 
217902       trace
217903          (p_msg      => 'SQL - FETCH line_cur'
217904          ,p_level    => C_LEVEL_STATEMENT
217905          ,p_module   => l_log_module);
217906 
217907 END IF;
217908 --
217909 --
217910 LOOP
217911   --
217912   FETCH line_cur BULK COLLECT INTO
217913         l_array_entity_id
217914       , l_array_legal_entity_id
217915       , l_array_entity_code
217916       , l_array_transaction_num
217917       , l_array_event_id
217918       , l_array_class_code
217919       , l_array_event_type
217920       , l_array_event_number
217921       , l_array_event_date
217922       , l_array_transaction_date
217923       , l_array_reference_num_1
217924       , l_array_reference_num_2
217925       , l_array_reference_num_3
217926       , l_array_reference_num_4
217927       , l_array_reference_char_1
217928       , l_array_reference_char_2
217929       , l_array_reference_char_3
217930       , l_array_reference_char_4
217931       , l_array_reference_date_1
217932       , l_array_reference_date_2
217933       , l_array_reference_date_3
217934       , l_array_reference_date_4
217935       , l_array_event_created_by
217936       , l_array_budgetary_control_flag
217937       , l_array_extract_line_num 
217938       , l_array_source_3
217939       , l_array_source_10
217940       , l_array_source_17
217941       , l_array_source_29
217942       , l_array_source_35
217943       , l_array_source_36
217944       , l_array_source_37
217945       , l_array_source_38
217946       , l_array_source_39
217947       , l_array_source_40
217948       LIMIT l_rows;
217949 
217950   --
217951   IF (C_LEVEL_EVENT >= g_log_level) THEN
217952             trace
217953                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
217954                ,p_level    => C_LEVEL_EVENT
217955                ,p_module   => l_log_module);
217956   END IF;
217957   --
217958   EXIT WHEN l_array_entity_id.count = 0;
217959 
217960   XLA_AE_LINES_PKG.g_rec_lines := null;
217961 
217962 --
217963 -- Bug 4458708
217964 --
217965 XLA_AE_LINES_PKG.g_LineNumber := 0;
217966 --
217967 --
217968 
217969 FOR Idx IN 1..l_array_event_id.count LOOP
217970    --
217971    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
217972    --
217973    l_event_id := l_array_event_id(idx);  -- 5648433
217974 
217975    --
217976    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
217977    --
217978 
217979    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
217980              (g_array_event(l_event_id).array_value_num('header_index'))
217981          ,'N'
217982          ) <> 'Y'
217983    THEN
217984       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
217985          trace
217986             (p_msg      => 'Trancaction revesal option is not Y '
217987             ,p_level    => C_LEVEL_STATEMENT
217988             ,p_module   => l_log_module);
217989       END IF;
217990 
217991 --
217992 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
217993 --
217994 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
217995 --
217996 -- set event info as cache for other routines to refer event attributes
217997 --
217998 
217999 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
218000    l_previous_event_id := l_event_id;
218001 
218002    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
218003       (p_application_id           => p_application_id
218004       ,p_primary_ledger_id        => p_primary_ledger_id
218005       ,p_base_ledger_id           => p_base_ledger_id
218009       ,p_entity_code              => l_array_entity_code(Idx)
218006       ,p_target_ledger_id         => p_target_ledger_id
218007       ,p_entity_id                => l_array_entity_id(Idx)
218008       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
218010       ,p_transaction_num          => l_array_transaction_num(Idx)
218011       ,p_event_id                 => l_array_event_id(Idx)
218012       ,p_event_class_code         => l_array_class_code(Idx)
218013       ,p_event_type_code          => l_array_event_type(Idx)
218014       ,p_event_number             => l_array_event_number(Idx)
218015       ,p_event_date               => l_array_event_date(Idx)
218016       ,p_transaction_date         => l_array_transaction_date(Idx)
218017       ,p_reference_num_1          => l_array_reference_num_1(Idx)
218018       ,p_reference_num_2          => l_array_reference_num_2(Idx)
218019       ,p_reference_num_3          => l_array_reference_num_3(Idx)
218020       ,p_reference_num_4          => l_array_reference_num_4(Idx)
218021       ,p_reference_char_1         => l_array_reference_char_1(Idx)
218022       ,p_reference_char_2         => l_array_reference_char_2(Idx)
218023       ,p_reference_char_3         => l_array_reference_char_3(Idx)
218024       ,p_reference_char_4         => l_array_reference_char_4(Idx)
218025       ,p_reference_date_1         => l_array_reference_date_1(Idx)
218026       ,p_reference_date_2         => l_array_reference_date_2(Idx)
218027       ,p_reference_date_3         => l_array_reference_date_3(Idx)
218028       ,p_reference_date_4         => l_array_reference_date_4(Idx)
218029       ,p_event_created_by         => l_array_event_created_by(Idx)
218030       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
218031        --
218032 END IF;
218033 
218034 
218035 
218036 --
218037 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
218038 
218039 l_acct_reversal_source := SUBSTR(NULL, 1,30);
218040 
218041 IF l_continue_with_lines THEN
218042    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
218043       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
218044 
218045       xla_accounting_err_pkg.build_message
218046          (p_appli_s_name            => 'XLA'
218047          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
218048          ,p_token_1                 => 'LINE_NUMBER'
218049          ,p_value_1                 => l_array_extract_line_num(Idx)
218050          ,p_token_2                 => 'PRODUCT_NAME'
218051          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
218052          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
218053          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
218054          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
218055 
218056    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
218057       --
218058       -- following sets the accounting attributes needed to reverse
218059       -- accounting for a distributeion
218060       --
218061 
218062       --
218063       -- 5217187
218064       --
218065       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
218066       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
218067                                        g_array_event(l_event_id).array_value_num('header_index'));
218068       --
218069       --
218070 
218071       -- No reversal code generated
218072 
218073       xla_ae_lines_pkg.SetAcctReversalAttrs
218074          (p_event_id             => l_event_id
218075          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
218076          ,p_calculate_acctd_flag => l_calculate_acctd_flag
218077          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
218078    END IF;
218079 
218080    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
218081        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
218082 
218083 --
218084 AcctLineType_405 (
218085  p_application_id  => p_application_id
218086  ,p_event_id     => l_event_id
218087  ,p_calculate_acctd_flag => l_calculate_acctd_flag
218088  ,p_calculate_g_l_flag => l_calculate_g_l_flag
218089  ,p_actual_flag => l_actual_flag
218090  ,p_balance_type_code => l_balance_type_code
218091  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
218092  
218093  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
218094  , p_source_3 => l_array_source_3(Idx)
218095  , p_source_29 => l_array_source_29(Idx)
218096  , p_source_35 => l_array_source_35(Idx)
218097  , p_source_36 => l_array_source_36(Idx)
218098  , p_source_37 => l_array_source_37(Idx)
218099  , p_source_38 => l_array_source_38(Idx)
218100  , p_source_39 => l_array_source_39(Idx)
218101  , p_source_40 => l_array_source_40(Idx)
218102  );
218103 If(l_balance_type_code = 'A') THEN
218104   l_actual_gain_loss_ref := l_gain_or_loss_ref;
218105 END IF;
218106 
218107 --
218108 
218109 
218110 --
218111 AcctLineType_406 (
218112  p_application_id  => p_application_id
218113  ,p_event_id     => l_event_id
218114  ,p_calculate_acctd_flag => l_calculate_acctd_flag
218115  ,p_calculate_g_l_flag => l_calculate_g_l_flag
218116  ,p_actual_flag => l_actual_flag
218117  ,p_balance_type_code => l_balance_type_code
218118  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
218119  
218120  , p_source_1 => g_array_event(l_event_id).array_value_date('source_1')
218121  , p_source_10 => l_array_source_10(Idx)
218122  , p_source_17 => l_array_source_17(Idx)
218123  , p_source_29 => l_array_source_29(Idx)
218124  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
218125  , p_source_35 => l_array_source_35(Idx)
218126  , p_source_36 => l_array_source_36(Idx)
218127  , p_source_37 => l_array_source_37(Idx)
218128  , p_source_38 => l_array_source_38(Idx)
218129  , p_source_39 => l_array_source_39(Idx)
218130  , p_source_40 => l_array_source_40(Idx)
218131  );
218135 
218132 If(l_balance_type_code = 'A') THEN
218133   l_actual_gain_loss_ref := l_gain_or_loss_ref;
218134 END IF;
218136 --
218137 
218138       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
218139       -- or secondary ledger that has different currency with primary
218140       -- or alc that is calculated by sla
218141       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
218142             (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'))
218143 
218144 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
218145 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
218146           AND (l_actual_flag = 'A')) THEN
218147         XLA_AE_LINES_PKG.CreateGainOrLossLines(
218148           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
218149          ,p_application_id   => p_application_id
218150          ,p_amb_context_code => 'DEFAULT'
218151          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
218152          ,p_event_class_code => C_EVENT_CLASS_CODE
218153          ,p_event_type_code  => C_EVENT_TYPE_CODE
218154          
218155          ,p_gain_ccid        => -1
218156          ,p_loss_ccid        => -1
218157 
218158          ,p_actual_flag      => l_actual_flag
218159          ,p_enc_flag         => null
218160          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
218161          ,p_enc_g_l_ref      => null
218162          );
218163       END IF;
218164    END IF;
218165 END IF;
218166 
218167    ELSE
218168       --
218169       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
218170       --
218171       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218172          trace
218173             (p_msg      => 'Trancaction revesal option is Y'
218174             ,p_level    => C_LEVEL_STATEMENT
218175             ,p_module   => l_log_module);
218176       END IF;
218177    END IF;
218178 
218179 END LOOP;
218180 l_result := XLA_AE_LINES_PKG.InsertLines ;
218181 end loop;
218182 close line_cur;
218183 
218184 
218185 --
218186 -- insert headers into xla_ae_headers_gt table
218187 --
218188 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
218189 
218190 -- insert into errors table here.
218191 
218192 END LOOP;
218193 
218194 --
218195 -- 4865292
218196 --
218197 -- Compare g_hdr_extract_count with event count in
218198 -- CreateHeadersAndLines.
218199 --
218200 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
218201 
218202 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218203    trace (p_msg     => '# rows extracted from header extract objects '
218204                     || ' (running total): '
218205                     || g_hdr_extract_count
218206          ,p_level   => C_LEVEL_STATEMENT
218207          ,p_module  => l_log_module);
218208 END IF;
218209 
218210 CLOSE header_cur;
218211 --
218212 
218213 --
218214 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
218215    trace
218216       (p_msg      => 'END of EventClass_433'
218217       ,p_level    => C_LEVEL_PROCEDURE
218218       ,p_module   => l_log_module);
218219 END IF;
218220 --
218221 RETURN l_result;
218222 EXCEPTION
218223 WHEN xla_exceptions_pkg.application_exception THEN
218224    
218225 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
218226 
218227    
218228 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
218229 
218230    RAISE;
218231 
218232 WHEN NO_DATA_FOUND THEN
218233 
218234 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
218235 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
218236 
218237 FOR header_record IN header_cur
218238 LOOP
218239     l_array_header_events(header_record.event_id) := header_record.event_id;
218240 END LOOP;
218241 
218242 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
218243 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
218244 
218245 fnd_file.put_line(fnd_file.LOG, '                    ');
218246 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
218247 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
218248 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
218249 
218250 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
218251 LOOP
218252 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
218253 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
218254         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
218255 	END IF;
218256 END LOOP;
218257 
218258 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
218259 fnd_file.put_line(fnd_file.LOG, '                    ');
218260 
218261 
218262 xla_exceptions_pkg.raise_message
218263       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_433');
218264 
218265 
218266 WHEN OTHERS THEN
218267    xla_exceptions_pkg.raise_message
218268       (p_location => 'XLA_00140_AAD_S_000002_PKG.EventClass_433');
218269 END EventClass_433;
218270 --
218271 
218272 --
218273 --+============================================+
218274 --|                                            |
218275 --|  PRIVATE FUNCTION                          |
218276 --|                                            |
218277 --+============================================+
218278 --
218279 FUNCTION CreateHeadersAndLines
218280        (p_application_id         IN NUMBER
218281        ,p_base_ledger_id         IN NUMBER
218285        ,p_primary_ledger_id      IN NUMBER)
218282        ,p_target_ledger_id       IN NUMBER
218283        ,p_pad_start_date         IN DATE
218284        ,p_pad_end_date           IN DATE
218286 RETURN BOOLEAN IS
218287 l_created                   BOOLEAN:=FALSE;
218288 l_event_id                  NUMBER;
218289 l_event_date                DATE;
218290 l_language                  VARCHAR2(30);
218291 l_currency_code             VARCHAR2(30);
218292 l_sla_ledger_id             NUMBER;
218293 l_log_module                VARCHAR2(240);
218294 
218295 BEGIN
218296 --
218297 IF g_log_enabled THEN
218298    l_log_module := C_DEFAULT_MODULE||'.CreateHeadersAndLines';
218299 END IF;
218300 --
218301 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
218302    trace
218303       (p_msg      => 'BEGIN of CreateHeadersAndLines'
218304       ,p_level    => C_LEVEL_PROCEDURE
218305       ,p_module   => l_log_module);
218306 END IF;
218307 
218308 l_language         := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
218309 l_currency_code    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.currency_code;
218310 l_sla_ledger_id    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.sla_ledger_id;
218311 
218312 --
218313 -- initialize array of lines with NULL
218314 --
218315 xla_ae_lines_pkg.SetNullLine;
218316 
218317 --
218318 -- initialize header extract count -- Bug 4865292
218319 --
218320 g_hdr_extract_count:= 0;
218321 
218322 
218323 l_created := EventClass_407(
218324    p_application_id         => p_application_id
218325  , p_base_ledger_id         => p_base_ledger_id
218326  , p_target_ledger_id       => p_target_ledger_id
218327  , p_language               => l_language
218328  , p_currency_code          => l_currency_code
218329  , p_sla_ledger_id          => l_sla_ledger_id
218330  , p_pad_start_date         => p_pad_start_date
218331  , p_pad_end_date           => p_pad_end_date
218332  , p_primary_ledger_id      => p_primary_ledger_id
218333 );
218334 
218335 
218336 
218337      IF ( g_diagnostics_mode ='Y' ) THEN
218338 
218339          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218340           trace
218341               (p_msg      => 'CALL Transaction Objects Diagnostics'
218342               ,p_level    => C_LEVEL_STATEMENT
218343               ,p_module   => l_log_module);
218344 
218345          END IF;
218346 
218347          insert_sources_407(
218348                           p_target_ledger_id => p_target_ledger_id
218349                         , p_language         => l_language
218350                         , p_sla_ledger_id    => l_sla_ledger_id
218351                         , p_pad_start_date   => p_pad_start_date
218352                         , p_pad_end_date     => p_pad_end_date
218353                           );
218354 
218355      END IF;
218356 
218357 l_created := EventClass_408(
218358    p_application_id         => p_application_id
218359  , p_base_ledger_id         => p_base_ledger_id
218360  , p_target_ledger_id       => p_target_ledger_id
218361  , p_language               => l_language
218362  , p_currency_code          => l_currency_code
218363  , p_sla_ledger_id          => l_sla_ledger_id
218364  , p_pad_start_date         => p_pad_start_date
218365  , p_pad_end_date           => p_pad_end_date
218366  , p_primary_ledger_id      => p_primary_ledger_id
218367 );
218368 
218369 
218370 
218371      IF ( g_diagnostics_mode ='Y' ) THEN
218372 
218373          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218374           trace
218375               (p_msg      => 'CALL Transaction Objects Diagnostics'
218376               ,p_level    => C_LEVEL_STATEMENT
218377               ,p_module   => l_log_module);
218378 
218379          END IF;
218380 
218381          insert_sources_408(
218382                           p_target_ledger_id => p_target_ledger_id
218383                         , p_language         => l_language
218384                         , p_sla_ledger_id    => l_sla_ledger_id
218385                         , p_pad_start_date   => p_pad_start_date
218386                         , p_pad_end_date     => p_pad_end_date
218387                           );
218388 
218389      END IF;
218390 
218391  l_created :=  EventType_409(
218392    p_application_id         => p_application_id
218393  , p_base_ledger_id         => p_base_ledger_id
218394  , p_target_ledger_id       => p_target_ledger_id
218395  , p_language               => l_language
218396  , p_currency_code          => l_currency_code
218397  , p_sla_ledger_id          => l_sla_ledger_id
218398  , p_pad_start_date         => p_pad_start_date
218399  , p_pad_end_date           => p_pad_end_date
218400  , p_primary_ledger_id      => p_primary_ledger_id
218401 );
218402 
218403 
218404 
218405      IF ( g_diagnostics_mode ='Y' ) THEN
218406 
218407          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218408           trace
218409               (p_msg      => 'CALL Transaction Objects Diagnostics'
218410               ,p_level    => C_LEVEL_STATEMENT
218411               ,p_module   => l_log_module);
218412 
218413          END IF;
218414 
218415          insert_sources_409(
218416                           p_target_ledger_id => p_target_ledger_id
218417                         , p_language         => l_language
218418                         , p_sla_ledger_id    => l_sla_ledger_id
218419                         , p_pad_start_date   => p_pad_start_date
218420                         , p_pad_end_date     => p_pad_end_date
218421                           );
218422 
218423      END IF;
218424 
218425 l_created := EventClass_410(
218426    p_application_id         => p_application_id
218427  , p_base_ledger_id         => p_base_ledger_id
218428  , p_target_ledger_id       => p_target_ledger_id
218429  , p_language               => l_language
218430  , p_currency_code          => l_currency_code
218434  , p_primary_ledger_id      => p_primary_ledger_id
218431  , p_sla_ledger_id          => l_sla_ledger_id
218432  , p_pad_start_date         => p_pad_start_date
218433  , p_pad_end_date           => p_pad_end_date
218435 );
218436 
218437 
218438 
218439      IF ( g_diagnostics_mode ='Y' ) THEN
218440 
218441          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218442           trace
218443               (p_msg      => 'CALL Transaction Objects Diagnostics'
218444               ,p_level    => C_LEVEL_STATEMENT
218445               ,p_module   => l_log_module);
218446 
218447          END IF;
218448 
218449          insert_sources_410(
218450                           p_target_ledger_id => p_target_ledger_id
218451                         , p_language         => l_language
218452                         , p_sla_ledger_id    => l_sla_ledger_id
218453                         , p_pad_start_date   => p_pad_start_date
218454                         , p_pad_end_date     => p_pad_end_date
218455                           );
218456 
218457      END IF;
218458 
218459 l_created := EventClass_411(
218460    p_application_id         => p_application_id
218461  , p_base_ledger_id         => p_base_ledger_id
218462  , p_target_ledger_id       => p_target_ledger_id
218463  , p_language               => l_language
218464  , p_currency_code          => l_currency_code
218465  , p_sla_ledger_id          => l_sla_ledger_id
218466  , p_pad_start_date         => p_pad_start_date
218467  , p_pad_end_date           => p_pad_end_date
218468  , p_primary_ledger_id      => p_primary_ledger_id
218469 );
218470 
218471 
218472 
218473      IF ( g_diagnostics_mode ='Y' ) THEN
218474 
218475          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218476           trace
218477               (p_msg      => 'CALL Transaction Objects Diagnostics'
218478               ,p_level    => C_LEVEL_STATEMENT
218479               ,p_module   => l_log_module);
218480 
218481          END IF;
218482 
218483          insert_sources_411(
218484                           p_target_ledger_id => p_target_ledger_id
218485                         , p_language         => l_language
218486                         , p_sla_ledger_id    => l_sla_ledger_id
218487                         , p_pad_start_date   => p_pad_start_date
218488                         , p_pad_end_date     => p_pad_end_date
218489                           );
218490 
218491      END IF;
218492 
218493 l_created := EventClass_412(
218494    p_application_id         => p_application_id
218495  , p_base_ledger_id         => p_base_ledger_id
218496  , p_target_ledger_id       => p_target_ledger_id
218497  , p_language               => l_language
218498  , p_currency_code          => l_currency_code
218499  , p_sla_ledger_id          => l_sla_ledger_id
218500  , p_pad_start_date         => p_pad_start_date
218501  , p_pad_end_date           => p_pad_end_date
218502  , p_primary_ledger_id      => p_primary_ledger_id
218503 );
218504 
218505 
218506 
218507      IF ( g_diagnostics_mode ='Y' ) THEN
218508 
218509          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218510           trace
218511               (p_msg      => 'CALL Transaction Objects Diagnostics'
218512               ,p_level    => C_LEVEL_STATEMENT
218513               ,p_module   => l_log_module);
218514 
218515          END IF;
218516 
218517          insert_sources_412(
218518                           p_target_ledger_id => p_target_ledger_id
218519                         , p_language         => l_language
218520                         , p_sla_ledger_id    => l_sla_ledger_id
218521                         , p_pad_start_date   => p_pad_start_date
218522                         , p_pad_end_date     => p_pad_end_date
218523                           );
218524 
218525      END IF;
218526 
218527 l_created := EventClass_413(
218528    p_application_id         => p_application_id
218529  , p_base_ledger_id         => p_base_ledger_id
218530  , p_target_ledger_id       => p_target_ledger_id
218531  , p_language               => l_language
218532  , p_currency_code          => l_currency_code
218533  , p_sla_ledger_id          => l_sla_ledger_id
218534  , p_pad_start_date         => p_pad_start_date
218535  , p_pad_end_date           => p_pad_end_date
218536  , p_primary_ledger_id      => p_primary_ledger_id
218537 );
218538 
218539 
218540 
218541      IF ( g_diagnostics_mode ='Y' ) THEN
218542 
218543          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218544           trace
218545               (p_msg      => 'CALL Transaction Objects Diagnostics'
218546               ,p_level    => C_LEVEL_STATEMENT
218547               ,p_module   => l_log_module);
218548 
218549          END IF;
218550 
218551          insert_sources_413(
218552                           p_target_ledger_id => p_target_ledger_id
218553                         , p_language         => l_language
218554                         , p_sla_ledger_id    => l_sla_ledger_id
218555                         , p_pad_start_date   => p_pad_start_date
218556                         , p_pad_end_date     => p_pad_end_date
218557                           );
218558 
218559      END IF;
218560 
218561  l_created :=  EventType_414(
218562    p_application_id         => p_application_id
218563  , p_base_ledger_id         => p_base_ledger_id
218564  , p_target_ledger_id       => p_target_ledger_id
218565  , p_language               => l_language
218566  , p_currency_code          => l_currency_code
218567  , p_sla_ledger_id          => l_sla_ledger_id
218568  , p_pad_start_date         => p_pad_start_date
218569  , p_pad_end_date           => p_pad_end_date
218570  , p_primary_ledger_id      => p_primary_ledger_id
218571 );
218572 
218573 
218574 
218575      IF ( g_diagnostics_mode ='Y' ) THEN
218576 
218577          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218578           trace
218582 
218579               (p_msg      => 'CALL Transaction Objects Diagnostics'
218580               ,p_level    => C_LEVEL_STATEMENT
218581               ,p_module   => l_log_module);
218583          END IF;
218584 
218585          insert_sources_414(
218586                           p_target_ledger_id => p_target_ledger_id
218587                         , p_language         => l_language
218588                         , p_sla_ledger_id    => l_sla_ledger_id
218589                         , p_pad_start_date   => p_pad_start_date
218590                         , p_pad_end_date     => p_pad_end_date
218591                           );
218592 
218593      END IF;
218594 
218595  l_created :=  EventType_415(
218596    p_application_id         => p_application_id
218597  , p_base_ledger_id         => p_base_ledger_id
218598  , p_target_ledger_id       => p_target_ledger_id
218599  , p_language               => l_language
218600  , p_currency_code          => l_currency_code
218601  , p_sla_ledger_id          => l_sla_ledger_id
218602  , p_pad_start_date         => p_pad_start_date
218603  , p_pad_end_date           => p_pad_end_date
218604  , p_primary_ledger_id      => p_primary_ledger_id
218605 );
218606 
218607 
218608 
218609      IF ( g_diagnostics_mode ='Y' ) THEN
218610 
218611          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218612           trace
218613               (p_msg      => 'CALL Transaction Objects Diagnostics'
218614               ,p_level    => C_LEVEL_STATEMENT
218615               ,p_module   => l_log_module);
218616 
218617          END IF;
218618 
218619          insert_sources_415(
218620                           p_target_ledger_id => p_target_ledger_id
218621                         , p_language         => l_language
218622                         , p_sla_ledger_id    => l_sla_ledger_id
218623                         , p_pad_start_date   => p_pad_start_date
218624                         , p_pad_end_date     => p_pad_end_date
218625                           );
218626 
218627      END IF;
218628 
218629 l_created := EventClass_416(
218630    p_application_id         => p_application_id
218631  , p_base_ledger_id         => p_base_ledger_id
218632  , p_target_ledger_id       => p_target_ledger_id
218633  , p_language               => l_language
218634  , p_currency_code          => l_currency_code
218635  , p_sla_ledger_id          => l_sla_ledger_id
218636  , p_pad_start_date         => p_pad_start_date
218637  , p_pad_end_date           => p_pad_end_date
218638  , p_primary_ledger_id      => p_primary_ledger_id
218639 );
218640 
218641 
218642 
218643      IF ( g_diagnostics_mode ='Y' ) THEN
218644 
218645          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218646           trace
218647               (p_msg      => 'CALL Transaction Objects Diagnostics'
218648               ,p_level    => C_LEVEL_STATEMENT
218649               ,p_module   => l_log_module);
218650 
218651          END IF;
218652 
218653          insert_sources_416(
218654                           p_target_ledger_id => p_target_ledger_id
218655                         , p_language         => l_language
218656                         , p_sla_ledger_id    => l_sla_ledger_id
218657                         , p_pad_start_date   => p_pad_start_date
218658                         , p_pad_end_date     => p_pad_end_date
218659                           );
218660 
218661      END IF;
218662 
218663 l_created := EventClass_417(
218664    p_application_id         => p_application_id
218665  , p_base_ledger_id         => p_base_ledger_id
218666  , p_target_ledger_id       => p_target_ledger_id
218667  , p_language               => l_language
218668  , p_currency_code          => l_currency_code
218669  , p_sla_ledger_id          => l_sla_ledger_id
218670  , p_pad_start_date         => p_pad_start_date
218671  , p_pad_end_date           => p_pad_end_date
218672  , p_primary_ledger_id      => p_primary_ledger_id
218673 );
218674 
218675 
218676 
218677      IF ( g_diagnostics_mode ='Y' ) THEN
218678 
218679          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218680           trace
218681               (p_msg      => 'CALL Transaction Objects Diagnostics'
218682               ,p_level    => C_LEVEL_STATEMENT
218683               ,p_module   => l_log_module);
218684 
218685          END IF;
218686 
218687          insert_sources_417(
218688                           p_target_ledger_id => p_target_ledger_id
218689                         , p_language         => l_language
218690                         , p_sla_ledger_id    => l_sla_ledger_id
218691                         , p_pad_start_date   => p_pad_start_date
218692                         , p_pad_end_date     => p_pad_end_date
218693                           );
218694 
218695      END IF;
218696 
218697 l_created := EventClass_418(
218698    p_application_id         => p_application_id
218699  , p_base_ledger_id         => p_base_ledger_id
218700  , p_target_ledger_id       => p_target_ledger_id
218701  , p_language               => l_language
218702  , p_currency_code          => l_currency_code
218703  , p_sla_ledger_id          => l_sla_ledger_id
218704  , p_pad_start_date         => p_pad_start_date
218705  , p_pad_end_date           => p_pad_end_date
218706  , p_primary_ledger_id      => p_primary_ledger_id
218707 );
218708 
218709 
218710 
218711      IF ( g_diagnostics_mode ='Y' ) THEN
218712 
218713          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218714           trace
218715               (p_msg      => 'CALL Transaction Objects Diagnostics'
218716               ,p_level    => C_LEVEL_STATEMENT
218717               ,p_module   => l_log_module);
218718 
218719          END IF;
218720 
218721          insert_sources_418(
218722                           p_target_ledger_id => p_target_ledger_id
218723                         , p_language         => l_language
218727                           );
218724                         , p_sla_ledger_id    => l_sla_ledger_id
218725                         , p_pad_start_date   => p_pad_start_date
218726                         , p_pad_end_date     => p_pad_end_date
218728 
218729      END IF;
218730 
218731 l_created := EventClass_419(
218732    p_application_id         => p_application_id
218733  , p_base_ledger_id         => p_base_ledger_id
218734  , p_target_ledger_id       => p_target_ledger_id
218735  , p_language               => l_language
218736  , p_currency_code          => l_currency_code
218737  , p_sla_ledger_id          => l_sla_ledger_id
218738  , p_pad_start_date         => p_pad_start_date
218739  , p_pad_end_date           => p_pad_end_date
218740  , p_primary_ledger_id      => p_primary_ledger_id
218741 );
218742 
218743 
218744 
218745      IF ( g_diagnostics_mode ='Y' ) THEN
218746 
218747          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218748           trace
218749               (p_msg      => 'CALL Transaction Objects Diagnostics'
218750               ,p_level    => C_LEVEL_STATEMENT
218751               ,p_module   => l_log_module);
218752 
218753          END IF;
218754 
218755          insert_sources_419(
218756                           p_target_ledger_id => p_target_ledger_id
218757                         , p_language         => l_language
218758                         , p_sla_ledger_id    => l_sla_ledger_id
218759                         , p_pad_start_date   => p_pad_start_date
218760                         , p_pad_end_date     => p_pad_end_date
218761                           );
218762 
218763      END IF;
218764 
218765 l_created := EventClass_420(
218766    p_application_id         => p_application_id
218767  , p_base_ledger_id         => p_base_ledger_id
218768  , p_target_ledger_id       => p_target_ledger_id
218769  , p_language               => l_language
218770  , p_currency_code          => l_currency_code
218771  , p_sla_ledger_id          => l_sla_ledger_id
218772  , p_pad_start_date         => p_pad_start_date
218773  , p_pad_end_date           => p_pad_end_date
218774  , p_primary_ledger_id      => p_primary_ledger_id
218775 );
218776 
218777 
218778 
218779      IF ( g_diagnostics_mode ='Y' ) THEN
218780 
218781          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218782           trace
218783               (p_msg      => 'CALL Transaction Objects Diagnostics'
218784               ,p_level    => C_LEVEL_STATEMENT
218785               ,p_module   => l_log_module);
218786 
218787          END IF;
218788 
218789          insert_sources_420(
218790                           p_target_ledger_id => p_target_ledger_id
218791                         , p_language         => l_language
218792                         , p_sla_ledger_id    => l_sla_ledger_id
218793                         , p_pad_start_date   => p_pad_start_date
218794                         , p_pad_end_date     => p_pad_end_date
218795                           );
218796 
218797      END IF;
218798 
218799 l_created := EventClass_421(
218800    p_application_id         => p_application_id
218801  , p_base_ledger_id         => p_base_ledger_id
218802  , p_target_ledger_id       => p_target_ledger_id
218803  , p_language               => l_language
218804  , p_currency_code          => l_currency_code
218805  , p_sla_ledger_id          => l_sla_ledger_id
218806  , p_pad_start_date         => p_pad_start_date
218807  , p_pad_end_date           => p_pad_end_date
218808  , p_primary_ledger_id      => p_primary_ledger_id
218809 );
218810 
218811 
218812 
218813      IF ( g_diagnostics_mode ='Y' ) THEN
218814 
218815          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218816           trace
218817               (p_msg      => 'CALL Transaction Objects Diagnostics'
218818               ,p_level    => C_LEVEL_STATEMENT
218819               ,p_module   => l_log_module);
218820 
218821          END IF;
218822 
218823          insert_sources_421(
218824                           p_target_ledger_id => p_target_ledger_id
218825                         , p_language         => l_language
218826                         , p_sla_ledger_id    => l_sla_ledger_id
218827                         , p_pad_start_date   => p_pad_start_date
218828                         , p_pad_end_date     => p_pad_end_date
218829                           );
218830 
218831      END IF;
218832 
218833 l_created := EventClass_422(
218834    p_application_id         => p_application_id
218835  , p_base_ledger_id         => p_base_ledger_id
218836  , p_target_ledger_id       => p_target_ledger_id
218837  , p_language               => l_language
218838  , p_currency_code          => l_currency_code
218839  , p_sla_ledger_id          => l_sla_ledger_id
218840  , p_pad_start_date         => p_pad_start_date
218841  , p_pad_end_date           => p_pad_end_date
218842  , p_primary_ledger_id      => p_primary_ledger_id
218843 );
218844 
218845 
218846 
218847      IF ( g_diagnostics_mode ='Y' ) THEN
218848 
218849          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218850           trace
218851               (p_msg      => 'CALL Transaction Objects Diagnostics'
218852               ,p_level    => C_LEVEL_STATEMENT
218853               ,p_module   => l_log_module);
218854 
218855          END IF;
218856 
218857          insert_sources_422(
218858                           p_target_ledger_id => p_target_ledger_id
218859                         , p_language         => l_language
218860                         , p_sla_ledger_id    => l_sla_ledger_id
218861                         , p_pad_start_date   => p_pad_start_date
218862                         , p_pad_end_date     => p_pad_end_date
218863                           );
218864 
218865      END IF;
218866 
218867  l_created :=  EventType_423(
218868    p_application_id         => p_application_id
218869  , p_base_ledger_id         => p_base_ledger_id
218873  , p_sla_ledger_id          => l_sla_ledger_id
218870  , p_target_ledger_id       => p_target_ledger_id
218871  , p_language               => l_language
218872  , p_currency_code          => l_currency_code
218874  , p_pad_start_date         => p_pad_start_date
218875  , p_pad_end_date           => p_pad_end_date
218876  , p_primary_ledger_id      => p_primary_ledger_id
218877 );
218878 
218879 
218880 
218881      IF ( g_diagnostics_mode ='Y' ) THEN
218882 
218883          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218884           trace
218885               (p_msg      => 'CALL Transaction Objects Diagnostics'
218886               ,p_level    => C_LEVEL_STATEMENT
218887               ,p_module   => l_log_module);
218888 
218889          END IF;
218890 
218891          insert_sources_423(
218892                           p_target_ledger_id => p_target_ledger_id
218893                         , p_language         => l_language
218894                         , p_sla_ledger_id    => l_sla_ledger_id
218895                         , p_pad_start_date   => p_pad_start_date
218896                         , p_pad_end_date     => p_pad_end_date
218897                           );
218898 
218899      END IF;
218900 
218901 l_created := EventClass_424(
218902    p_application_id         => p_application_id
218903  , p_base_ledger_id         => p_base_ledger_id
218904  , p_target_ledger_id       => p_target_ledger_id
218905  , p_language               => l_language
218906  , p_currency_code          => l_currency_code
218907  , p_sla_ledger_id          => l_sla_ledger_id
218908  , p_pad_start_date         => p_pad_start_date
218909  , p_pad_end_date           => p_pad_end_date
218910  , p_primary_ledger_id      => p_primary_ledger_id
218911 );
218912 
218913 
218914 
218915      IF ( g_diagnostics_mode ='Y' ) THEN
218916 
218917          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218918           trace
218919               (p_msg      => 'CALL Transaction Objects Diagnostics'
218920               ,p_level    => C_LEVEL_STATEMENT
218921               ,p_module   => l_log_module);
218922 
218923          END IF;
218924 
218925          insert_sources_424(
218926                           p_target_ledger_id => p_target_ledger_id
218927                         , p_language         => l_language
218928                         , p_sla_ledger_id    => l_sla_ledger_id
218929                         , p_pad_start_date   => p_pad_start_date
218930                         , p_pad_end_date     => p_pad_end_date
218931                           );
218932 
218933      END IF;
218934 
218935  l_created :=  EventType_425(
218936    p_application_id         => p_application_id
218937  , p_base_ledger_id         => p_base_ledger_id
218938  , p_target_ledger_id       => p_target_ledger_id
218939  , p_language               => l_language
218940  , p_currency_code          => l_currency_code
218941  , p_sla_ledger_id          => l_sla_ledger_id
218942  , p_pad_start_date         => p_pad_start_date
218943  , p_pad_end_date           => p_pad_end_date
218944  , p_primary_ledger_id      => p_primary_ledger_id
218945 );
218946 
218947 
218948 
218949      IF ( g_diagnostics_mode ='Y' ) THEN
218950 
218951          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218952           trace
218953               (p_msg      => 'CALL Transaction Objects Diagnostics'
218954               ,p_level    => C_LEVEL_STATEMENT
218955               ,p_module   => l_log_module);
218956 
218957          END IF;
218958 
218959          insert_sources_425(
218960                           p_target_ledger_id => p_target_ledger_id
218961                         , p_language         => l_language
218962                         , p_sla_ledger_id    => l_sla_ledger_id
218963                         , p_pad_start_date   => p_pad_start_date
218964                         , p_pad_end_date     => p_pad_end_date
218965                           );
218966 
218967      END IF;
218968 
218969 l_created := EventClass_426(
218970    p_application_id         => p_application_id
218971  , p_base_ledger_id         => p_base_ledger_id
218972  , p_target_ledger_id       => p_target_ledger_id
218973  , p_language               => l_language
218974  , p_currency_code          => l_currency_code
218975  , p_sla_ledger_id          => l_sla_ledger_id
218976  , p_pad_start_date         => p_pad_start_date
218977  , p_pad_end_date           => p_pad_end_date
218978  , p_primary_ledger_id      => p_primary_ledger_id
218979 );
218980 
218981 
218982 
218983      IF ( g_diagnostics_mode ='Y' ) THEN
218984 
218985          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
218986           trace
218987               (p_msg      => 'CALL Transaction Objects Diagnostics'
218988               ,p_level    => C_LEVEL_STATEMENT
218989               ,p_module   => l_log_module);
218990 
218991          END IF;
218992 
218993          insert_sources_426(
218994                           p_target_ledger_id => p_target_ledger_id
218995                         , p_language         => l_language
218996                         , p_sla_ledger_id    => l_sla_ledger_id
218997                         , p_pad_start_date   => p_pad_start_date
218998                         , p_pad_end_date     => p_pad_end_date
218999                           );
219000 
219001      END IF;
219002 
219003 l_created := EventClass_427(
219004    p_application_id         => p_application_id
219005  , p_base_ledger_id         => p_base_ledger_id
219006  , p_target_ledger_id       => p_target_ledger_id
219007  , p_language               => l_language
219008  , p_currency_code          => l_currency_code
219009  , p_sla_ledger_id          => l_sla_ledger_id
219010  , p_pad_start_date         => p_pad_start_date
219011  , p_pad_end_date           => p_pad_end_date
219012  , p_primary_ledger_id      => p_primary_ledger_id
219013 );
219014 
219015 
219016 
219020           trace
219017      IF ( g_diagnostics_mode ='Y' ) THEN
219018 
219019          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219021               (p_msg      => 'CALL Transaction Objects Diagnostics'
219022               ,p_level    => C_LEVEL_STATEMENT
219023               ,p_module   => l_log_module);
219024 
219025          END IF;
219026 
219027          insert_sources_427(
219028                           p_target_ledger_id => p_target_ledger_id
219029                         , p_language         => l_language
219030                         , p_sla_ledger_id    => l_sla_ledger_id
219031                         , p_pad_start_date   => p_pad_start_date
219032                         , p_pad_end_date     => p_pad_end_date
219033                           );
219034 
219035      END IF;
219036 
219037  l_created :=  EventType_428(
219038    p_application_id         => p_application_id
219039  , p_base_ledger_id         => p_base_ledger_id
219040  , p_target_ledger_id       => p_target_ledger_id
219041  , p_language               => l_language
219042  , p_currency_code          => l_currency_code
219043  , p_sla_ledger_id          => l_sla_ledger_id
219044  , p_pad_start_date         => p_pad_start_date
219045  , p_pad_end_date           => p_pad_end_date
219046  , p_primary_ledger_id      => p_primary_ledger_id
219047 );
219048 
219049 
219050 
219051      IF ( g_diagnostics_mode ='Y' ) THEN
219052 
219053          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219054           trace
219055               (p_msg      => 'CALL Transaction Objects Diagnostics'
219056               ,p_level    => C_LEVEL_STATEMENT
219057               ,p_module   => l_log_module);
219058 
219059          END IF;
219060 
219061          insert_sources_428(
219062                           p_target_ledger_id => p_target_ledger_id
219063                         , p_language         => l_language
219064                         , p_sla_ledger_id    => l_sla_ledger_id
219065                         , p_pad_start_date   => p_pad_start_date
219066                         , p_pad_end_date     => p_pad_end_date
219067                           );
219068 
219069      END IF;
219070 
219071 l_created := EventClass_429(
219072    p_application_id         => p_application_id
219073  , p_base_ledger_id         => p_base_ledger_id
219074  , p_target_ledger_id       => p_target_ledger_id
219075  , p_language               => l_language
219076  , p_currency_code          => l_currency_code
219077  , p_sla_ledger_id          => l_sla_ledger_id
219078  , p_pad_start_date         => p_pad_start_date
219079  , p_pad_end_date           => p_pad_end_date
219080  , p_primary_ledger_id      => p_primary_ledger_id
219081 );
219082 
219083 
219084 
219085      IF ( g_diagnostics_mode ='Y' ) THEN
219086 
219087          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219088           trace
219089               (p_msg      => 'CALL Transaction Objects Diagnostics'
219090               ,p_level    => C_LEVEL_STATEMENT
219091               ,p_module   => l_log_module);
219092 
219093          END IF;
219094 
219095          insert_sources_429(
219096                           p_target_ledger_id => p_target_ledger_id
219097                         , p_language         => l_language
219098                         , p_sla_ledger_id    => l_sla_ledger_id
219099                         , p_pad_start_date   => p_pad_start_date
219100                         , p_pad_end_date     => p_pad_end_date
219101                           );
219102 
219103      END IF;
219104 
219105 l_created := EventClass_430(
219106    p_application_id         => p_application_id
219107  , p_base_ledger_id         => p_base_ledger_id
219108  , p_target_ledger_id       => p_target_ledger_id
219109  , p_language               => l_language
219110  , p_currency_code          => l_currency_code
219111  , p_sla_ledger_id          => l_sla_ledger_id
219112  , p_pad_start_date         => p_pad_start_date
219113  , p_pad_end_date           => p_pad_end_date
219114  , p_primary_ledger_id      => p_primary_ledger_id
219115 );
219116 
219117 
219118 
219119      IF ( g_diagnostics_mode ='Y' ) THEN
219120 
219121          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219122           trace
219123               (p_msg      => 'CALL Transaction Objects Diagnostics'
219124               ,p_level    => C_LEVEL_STATEMENT
219125               ,p_module   => l_log_module);
219126 
219127          END IF;
219128 
219129          insert_sources_430(
219130                           p_target_ledger_id => p_target_ledger_id
219131                         , p_language         => l_language
219132                         , p_sla_ledger_id    => l_sla_ledger_id
219133                         , p_pad_start_date   => p_pad_start_date
219134                         , p_pad_end_date     => p_pad_end_date
219135                           );
219136 
219137      END IF;
219138 
219139 l_created := EventClass_431(
219140    p_application_id         => p_application_id
219141  , p_base_ledger_id         => p_base_ledger_id
219142  , p_target_ledger_id       => p_target_ledger_id
219143  , p_language               => l_language
219144  , p_currency_code          => l_currency_code
219145  , p_sla_ledger_id          => l_sla_ledger_id
219146  , p_pad_start_date         => p_pad_start_date
219147  , p_pad_end_date           => p_pad_end_date
219148  , p_primary_ledger_id      => p_primary_ledger_id
219149 );
219150 
219151 
219152 
219153      IF ( g_diagnostics_mode ='Y' ) THEN
219154 
219155          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219156           trace
219157               (p_msg      => 'CALL Transaction Objects Diagnostics'
219158               ,p_level    => C_LEVEL_STATEMENT
219159               ,p_module   => l_log_module);
219160 
219161          END IF;
219162 
219163          insert_sources_431(
219167                         , p_pad_start_date   => p_pad_start_date
219164                           p_target_ledger_id => p_target_ledger_id
219165                         , p_language         => l_language
219166                         , p_sla_ledger_id    => l_sla_ledger_id
219168                         , p_pad_end_date     => p_pad_end_date
219169                           );
219170 
219171      END IF;
219172 
219173 l_created := EventClass_432(
219174    p_application_id         => p_application_id
219175  , p_base_ledger_id         => p_base_ledger_id
219176  , p_target_ledger_id       => p_target_ledger_id
219177  , p_language               => l_language
219178  , p_currency_code          => l_currency_code
219179  , p_sla_ledger_id          => l_sla_ledger_id
219180  , p_pad_start_date         => p_pad_start_date
219181  , p_pad_end_date           => p_pad_end_date
219182  , p_primary_ledger_id      => p_primary_ledger_id
219183 );
219184 
219185 
219186 
219187      IF ( g_diagnostics_mode ='Y' ) THEN
219188 
219189          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219190           trace
219191               (p_msg      => 'CALL Transaction Objects Diagnostics'
219192               ,p_level    => C_LEVEL_STATEMENT
219193               ,p_module   => l_log_module);
219194 
219195          END IF;
219196 
219197          insert_sources_432(
219198                           p_target_ledger_id => p_target_ledger_id
219199                         , p_language         => l_language
219200                         , p_sla_ledger_id    => l_sla_ledger_id
219201                         , p_pad_start_date   => p_pad_start_date
219202                         , p_pad_end_date     => p_pad_end_date
219203                           );
219204 
219205      END IF;
219206 
219207 l_created := EventClass_433(
219208    p_application_id         => p_application_id
219209  , p_base_ledger_id         => p_base_ledger_id
219210  , p_target_ledger_id       => p_target_ledger_id
219211  , p_language               => l_language
219212  , p_currency_code          => l_currency_code
219213  , p_sla_ledger_id          => l_sla_ledger_id
219214  , p_pad_start_date         => p_pad_start_date
219215  , p_pad_end_date           => p_pad_end_date
219216  , p_primary_ledger_id      => p_primary_ledger_id
219217 );
219218 
219219 
219220 
219221      IF ( g_diagnostics_mode ='Y' ) THEN
219222 
219223          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219224           trace
219225               (p_msg      => 'CALL Transaction Objects Diagnostics'
219226               ,p_level    => C_LEVEL_STATEMENT
219227               ,p_module   => l_log_module);
219228 
219229          END IF;
219230 
219231          insert_sources_433(
219232                           p_target_ledger_id => p_target_ledger_id
219233                         , p_language         => l_language
219234                         , p_sla_ledger_id    => l_sla_ledger_id
219235                         , p_pad_start_date   => p_pad_start_date
219236                         , p_pad_end_date     => p_pad_end_date
219237                           );
219238 
219239      END IF;
219240 
219241 
219242  --
219243  -- Bug 4865292
219244  -- When the number of events and that of header extract do not match,
219245  -- set the no header extract flag to indicate there are some issues
219246  -- in header extract.
219247  --
219248  -- Event count context is set in xla_accounting_pkg.unit_processor.
219249  -- Build_Message for this error is called in xla_accounting_pkg.post_accounting
219250  -- to report it as a general error.
219251  --
219252  IF  xla_context_pkg.get_event_count_context <> g_hdr_extract_count
219253  AND xla_context_pkg.get_event_nohdr_context <> 'Y' THEN
219254 
219255      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219256         trace
219257           (p_msg      => '# of extracted headers and events does not match'
219258           ,p_level    => C_LEVEL_STATEMENT
219259           ,p_module   => l_log_module);
219260 
219261         trace
219262           (p_msg      => '# of extracted headers: '
219263                          ||g_hdr_extract_count
219264           ,p_level    => C_LEVEL_STATEMENT
219265           ,p_module   => l_log_module);
219266 
219267         trace
219268           (p_msg      => '# of events in xla_events_gt: '
219269                          ||xla_context_pkg.get_event_count_context
219270           ,p_level    => C_LEVEL_STATEMENT
219271           ,p_module   => l_log_module);
219272 
219273         trace
219274           (p_msg      => 'Event No Header Extract Context: '
219275                          ||xla_context_pkg.get_event_nohdr_context
219276           ,p_level    => C_LEVEL_STATEMENT
219277           ,p_module   => l_log_module);
219278 
219279      END IF;
219280 
219281 
219282      xla_context_pkg.set_event_nohdr_context
219283        (p_nohdr_extract_flag => 'Y'
219284        ,p_client_id => sys_context('USERENV','CLIENT_IDENTIFIER'));
219285 
219286      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219287         trace
219288           (p_msg      => 'No Header Extract Flag is set to Y'
219289           ,p_level    => C_LEVEL_STATEMENT
219290           ,p_module   => l_log_module);
219291      END IF;
219292 
219293  END IF;
219294 
219295 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
219296    trace
219297       (p_msg      => 'END of CreateHeadersAndLines'
219298       ,p_level    => C_LEVEL_PROCEDURE
219299       ,p_module   => l_log_module);
219300 END IF;
219301 
219302 RETURN l_created;
219303 EXCEPTION
219304 WHEN xla_exceptions_pkg.application_exception THEN
219305    RAISE;
219306 WHEN OTHERS THEN
219307    xla_exceptions_pkg.raise_message
219308       (p_location => 'XLA_00140_AAD_S_000002_PKG.CreateHeadersAndLines');
219309 END CreateHeadersAndLines;
219310 --
219311 --
219312 
219313 --
219317 --|                                            |
219314 --+============================================+
219315 --|                                            |
219316 --|  PUBLIC FUNCTION                           |
219318 --+============================================+
219319 --
219320 FUNCTION CreateJournalEntries
219321        (p_application_id         IN NUMBER
219322        ,p_base_ledger_id         IN NUMBER
219323        ,p_pad_start_date         IN DATE
219324        ,p_pad_end_date           IN DATE
219325        ,p_primary_ledger_id      IN NUMBER)
219326 RETURN NUMBER IS
219327 l_log_module                   VARCHAR2(240);
219328 l_array_ledgers                xla_accounting_cache_pkg.t_array_ledger_id;
219329 l_temp_result                  BOOLEAN;
219330 l_result                       NUMBER;
219331 BEGIN
219332 --
219333 IF g_log_enabled THEN
219334    l_log_module := C_DEFAULT_MODULE||'.CreateJournalEntries';
219335 END IF;
219336 --
219337 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
219338    trace
219339       (p_msg      => 'BEGIN of CreateJournalEntries'||
219340                      ' - p_base_ledger_id = '||TO_CHAR(p_base_ledger_id)
219341       ,p_level    => C_LEVEL_PROCEDURE
219342       ,p_module   => l_log_module);
219343 
219344 END IF;
219345 
219346 --
219347 g_diagnostics_mode:= xla_accounting_engine_pkg.g_diagnostics_mode;
219348 
219349 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
219350    trace
219351       (p_msg      => 'g_diagnostics_mode = '||g_diagnostics_mode
219352       ,p_level    => C_LEVEL_STATEMENT
219353       ,p_module   => l_log_module);
219354 END IF;
219355 --
219356 xla_ae_journal_entry_pkg.SetProductAcctDefinition
219357    (p_product_rule_code      => 'FA_STANDARD_ACCOUNTING'
219358    ,p_product_rule_type_code => 'S'
219359    ,p_product_rule_version   => ''
219360    ,p_product_rule_name      => 'Assets Standard Accounting'
219361    ,p_amb_context_code       => 'DEFAULT'
219362    );
219363 
219364 l_array_ledgers :=
219365    xla_ae_journal_entry_pkg.GetAlternateCurrencyLedger
219366       (p_base_ledger_id  => p_base_ledger_id);
219367 
219368 FOR Idx IN 1 .. l_array_ledgers.COUNT LOOP
219369    l_temp_result :=
219370       XLA_AE_JOURNAL_ENTRY_PKG.GetLedgersInfo
219371          (p_application_id           => p_application_id
219372          ,p_base_ledger_id           => p_base_ledger_id
219373          ,p_target_ledger_id         => l_array_ledgers(Idx)
219374          ,p_primary_ledger_id        => p_primary_ledger_id
219375          ,p_pad_start_date           => p_pad_start_date
219376          ,p_pad_end_date             => p_pad_end_date);
219377 
219378    l_temp_result :=
219379       l_temp_result AND
219380       CreateHeadersAndLines
219381          (p_application_id             => p_application_id
219382          ,p_base_ledger_id             => p_base_ledger_id
219383          ,p_target_ledger_id           => l_array_ledgers(Idx)
219384          ,p_pad_start_date             => p_pad_start_date
219385          ,p_pad_end_date               => p_pad_end_date
219386          ,p_primary_ledger_id          => p_primary_ledger_id
219387          );
219388 END LOOP;
219389 
219390 
219391 IF (g_diagnostics_mode = 'Y' AND
219392     C_LEVEL_UNEXPECTED >= g_log_level AND
219393     xla_environment_pkg.g_Req_Id IS NOT NULL ) THEN
219394 
219395    xla_accounting_dump_pkg.acctg_event_extract_log(
219396     p_application_id  => p_application_id
219397     ,p_request_id     => xla_environment_pkg.g_Req_Id
219398    );
219399 
219400 END IF;
219401 
219402 CASE l_temp_result
219403   WHEN TRUE THEN l_result := 0;
219404   ELSE l_result := 2;
219405 END CASE;
219406 
219407 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
219408    trace
219409       (p_msg      => 'return value. = '||TO_CHAR(l_result)
219410       ,p_level    => C_LEVEL_PROCEDURE
219411       ,p_module   => l_log_module);
219412    trace
219413       (p_msg      => 'END of CreateJournalEntries '
219414       ,p_level    => C_LEVEL_PROCEDURE
219415       ,p_module   => l_log_module);
219416 END IF;
219417 
219418 RETURN l_result;
219419 EXCEPTION
219420 WHEN xla_exceptions_pkg.application_exception THEN
219421    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
219422    trace
219423       (p_msg      => 'ERROR. = '||sqlerrm
219424       ,p_level    => C_LEVEL_PROCEDURE
219425       ,p_module   => l_log_module);
219426    END IF;
219427    RAISE;
219428 WHEN OTHERS THEN
219429    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
219430    trace
219431       (p_msg      => 'ERROR. = '||sqlerrm
219432       ,p_level    => C_LEVEL_PROCEDURE
219433       ,p_module   => l_log_module);
219434    END IF;
219435    xla_exceptions_pkg.raise_message
219436       (p_location => 'XLA_00140_AAD_S_000002_PKG.CreateJournalEntries');
219437 END CreateJournalEntries;
219438 --
219439 --=============================================================================
219440 --
219441 --
219442 --
219443 --
219444 --
219445 --
219446 --
219447 --
219448 --
219449 --
219450 --
219451 --
219452 --
219453 --
219454 --
219455 --
219456 --
219457 --
219458 --
219459 --
219460 --
219461 --
219462 --=============================================================================
219463 --=============================================================================
219464 --          *********** Initialization routine **********
219465 --=============================================================================
219466 
219467 BEGIN
219468    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
219469    g_log_enabled    := fnd_log.test
219470                           (log_level  => g_log_level
219471                           ,module     => C_DEFAULT_MODULE);
219472 
219473    IF NOT g_log_enabled  THEN
219477 END XLA_00140_AAD_S_000002_PKG;
219474       g_log_level := C_LEVEL_LOG_DISABLED;
219475    END IF;
219476 --
219478 --